コード例 #1
0
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=function(){return function(n,t){if(Array.isArray(n))return n;if(Symbol.iterator in Object(n))return function(n,t){var e=[],i=!0,r=!1,o=void 0;try{for(var a,c=n[Symbol.iterator]();!(i=(a=c.next()).done)&&(e.push(a.value),!t||e.length!==t);i=!0);}catch(n){r=!0,o=n}finally{try{!i&&c.return&&c.return()}finally{if(r)throw o}}return e}(n,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),t=function(){function n(n,t){for(var e=0;e<t.length;e++){var i=t[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(n,i.key,i)}}return function(t,e,i){return e&&n(t.prototype,e),i&&n(t,i),t}}();function e(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function i(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e(this,i),this.config=Object.assign({inService:!1,onProcess:function(){},onReady:function(){}},n),this.turnX=0,this.turnY=0,this.config.container=document.getElementById(this.config.container),this.init()}return t(i,[{key:"init",value:function(){this.addEvent()}},{key:"start",value:function(){this.config.inService=!0,this.config.onStart&&this.config.onStart()}},{key:"stop",value:function(){this.config.inService=!1,this.config.onStop&&this.config.onStop()}},{key:"addEvent",value:function(){var t=this;window.addEventListener("devicemotion",function(e){var i=e.accelerationIncludingGravity.x.toFixed(2),r=e.accelerationIncludingGravity.y.toFixed(2);if(!t.config.inService)return t.turnX=i,t.turnY=r,t.config.onReady(),!1;i-=t.turnX,r-=t.turnY;var o=/translate3d\((-?.+)px,.(-?.+)px,.0px\)/,a=t.config.container,c=a.style.transform.match(o);if(c){var u=n(c,3),f=(u[0],u[1]),s=u[2],l=10*i,v=10*r;if(Math.abs(l)>3||Math.abs(v)>3){l=l>0?l-3:l+3,v=v>0?v-3:v+3;var h=Math.abs(l)>3?+f+l:+f,y=Math.abs(v)>3?+s+v:+s,d="translate3d("+h+"px, "+y+"px, 0px)",g=a.style.transform.replace(o,d);a.style.transform=g,t.config.onProcess&&t.config.onProcess.call(t,-h,-y)}}})}},{key:"inService",get:function(){return this.config.inService}}]),i}();exports.default=i;
コード例 #2
0
var t,e,n=module.exports={};function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(e){if(t===setTimeout)return setTimeout(e,0);if((t===r||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this,e,0)}}}function u(t){if(e===clearTimeout)return clearTimeout(t);if((e===o||!e)&&clearTimeout)return e=clearTimeout,clearTimeout(t);try{return e(t)}catch(n){try{return e.call(null,t)}catch(n){return e.call(this,t)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:r}catch(e){t=r}try{e="function"==typeof clearTimeout?clearTimeout:o}catch(t){e=o}}();var c,s=[],l=!1,a=-1;function f(){l&&c&&(l=!1,c.length?s=c.concat(s):a=-1,s.length&&h())}function h(){if(!l){var t=i(f);l=!0;for(var e=s.length;e;){for(c=s,s=[];++a<e;)c&&c[a].run();a=-1,e=s.length}c=null,l=!1,u(t)}}function m(t,e){this.fun=t,this.array=e}function p(){}n.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];s.push(new m(t,e)),1!==s.length||l||i(h)},m.prototype.run=function(){this.fun.apply(null,this.array)},n.title="browser",n.browser=!0,n.env={},n.argv=[],n.version="",n.versions={},n.on=p,n.addListener=p,n.once=p,n.off=p,n.removeListener=p,n.removeAllListeners=p,n.emit=p,n.prependListener=p,n.prependOnceListener=p,n.listeners=function(t){return[]},n.binding=function(t){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(t){throw new Error("process.chdir is not supported")},n.umask=function(){return 0};