Advertisement
alexx876

Untitled

Jun 1st, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.55 KB | None | 0 0
  1. !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Hand=e()}(this,function(){"use strict";var t={classCallCheck:function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}};t.createClass=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),t.extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t};try{new Touch({identifier:0,target:document})}catch(t){!1}var e=!0;try{new MouseEvent("mousedown")}catch(t){e=!1}var i=!0;try{new Touch({identifier:0,target:document})}catch(t){i=!1}var n=!0;try{new TouchEvent("touchdown")}catch(t){n=!1}try{new PointerEvent("pointerdown")}catch(t){!1}var s=!!("MouseEvent"in window),a=!!("TouchEvent"in window),h=!!("PointerEvent"in window),r=navigator.userAgent.toLowerCase(),o=-1!==r.indexOf("webkit"),c=-1!==r.indexOf("phantom"),u=(r.search("android [23]"),-1!==r.indexOf("chrome")),d=-1!==r.indexOf("gecko")&&!o&&!window.opera&&!m,m=(c=c,m),l=(o=o,d=d,r.indexOf("android"),!(u=u)&&!c&&-1!==r.indexOf("safari")),f=1,p=function(){function n(e,i){t.classCallCheck(this,n),this._id=f++,this._mode=e||"mouse",this._hand=i.hand,this._state=t.extends({},{x:0,y:0,down:!1,pressure:.5,tiltX:0,tiltY:0,width:25,height:25,pointerType:"pen"},i),this._movements=[],this._movesUntil=performance.now(),this._movesFrom=performance.now(),this._finalState=t.extends({},this._state),"touch"===this._mode?(this._initGraphicIvansFinger(),a||console.warn("This browser cannot emulate touch events.")):"pointer"===this._mode?("touch"===this._state.pointerType?this._initGraphicIvansFinger():this._initGraphicCircle(),h||console.warn("This browser cannot emulate pointer events.")):(this._mode="mouse",this._initGraphicCircle(),s||console.warn("This browser cannot emulate mouse events.")),this._touchTargetWhenDowned=void 0,this._currentTarget=void 0}return t.createClass(n,[{key:"isIdle",value:function(){return!this._movements.length}},{key:"down",value:function(t){return this.update({down:!0,getState:this._falseFn,duration:t||0})}},{key:"up",value:function(t){return this.update({down:!1,getState:this._falseFn,duration:t||0})}},{key:"wait",value:function(t){return this._queueMove({finalState:this._finalState,getState:this._falseFn,duration:t}),this}},{key:"waitUntil",value:function(t){if(this._movements.length)return this.wait(t-this._movesUntil);var e={finalState:this._finalState,getState:this._falseFn,duration:t-performance.now(),until:t};return this._movesUntil=this._movesFrom=e.until,this._movements.push(e),this._hand.fingerIsBusy(),this}},{key:"update",value:function(t,e){return this._queueMove({finalState:t,getState:this._falseFn,duration:e||0}),this}},{key:"reset",value:function(t){return this}},{key:"moveTo",value:function(t,e,i){return this.moveBy(t-this._finalState.x,e-this._finalState.y,i)}},{key:"moveBy",value:function(t,e,i){var n,s,a,h,r=this._finalState.x,o=this._finalState.y,c={finalState:{x:r+t,y:o+e},getState:(n=r,s=o,a=t,h=e,function(t){var e=t/i;return{x:Math.round(n+a*e),y:Math.round(s+h*e)}}),duration:i};return this._queueMove(c),this}},{key:"_falseFn",value:function(){return!1}},{key:"_queueMove",value:function(e){this._movements.length||(this._movesUntil=this._movesFrom=performance.now()),e.until=this._movesUntil+e.duration,this._movements.push(e),this._finalState=e.finalState=t.extends({},this._finalState,e.finalState),this._movesUntil=e.until,1===this._movements.length&&this._hand.fingerIsBusy()}},{key:"getNextMoveEndTime",value:function(){if(this._movements.length)return this._movements[0].until}},{key:"getEvents",value:function(e,i){for(var n=e||performance.now(),s=!1,a=t.extends({},this._state);this._movements.length&&this._movements[0].until<=n&&(!s||!i);){var h=this._movements.shift();t.extends(this._state,h.finalState),this._movesFrom=h.until,s=!0}if(this._movements.length&&(!s||!i)){var r=this._movements[0].getState(n-this._movesFrom);r&&!this._statesAreEqual(r,this._state)&&(s=!0,t.extends(this._state,r))}this._movements.length||this._hand.fingerIsIdle();var o="idle";if(s&&(a.x===this._state.x&&a.y===this._state.y||(o="move",this._currentTarget=document.elementFromPoint(this._state.x,this._state.y)),a.down&&!this._state.down?(this._graphic.style.display="none",o="up"):!a.down&&this._state.down&&(this._graphic.style.display="block",this._touchTargetWhenDowned=this._currentTarget=document.elementFromPoint(this._state.x,this._state.y),o="down"),this._setGraphicPosition(this._state.x,this._state.y)),"mouse"===this._mode||"touchpad"===this._mode)return"idle"===o?[]:[{type:o,event:this._asMouseEvent(o),finger:this}];if("pointer"===this._mode)return"idle"===o?[]:[{type:o,event:this._asPointerEvent(o),finger:this}];if("touch"===this._mode){if(this._touchTargetWhenDowned){var c=[{type:o,touch:this._asTouch(o),finger:this}];return"up"===o&&(this._touchTargetWhenDowned=void 0),c}return[]}return[]}},{key:"_asTouch",value:function(){return i&&!l?new Touch({identifier:this._id,target:this._touchTargetWhenDowned,clientX:this._state.x,clientY:this._state.y,screenX:this._state.x,screenY:this._state.y,pageX:this._state.x,pageY:this._state.y,radiusX:25,radiusY:25,rotationAngle:0,force:this._state.pressure}):u?document.createTouch(window,this._touchTargetWhenDowned,this._id,this._state.x,this._state.y,this._state.x,this._state.y,25,25,0,this._state.pressure):d?document.createTouch(window,this._touchTargetWhenDowned,this._id,this._state.x,this._state.y,this._state.x,this._state.y,this._state.x,this._state.y):document.createTouch(window,this._touchTargetWhenDowned,this._id,this._state.x,this._state.y,this._state.x,this._state.y)}},{key:"_asPointerEvent",value:function(t){return new PointerEvent("pointer"+t,{bubbles:!0,button:0,clientX:this._state.x,clientY:this._state.y,screenX:this._state.x,screenY:this._state.y,pageX:this._state.x,pageY:this._state.y,pointerType:"pen",pointerId:this._id,isPrimary:1===this._id,width:this._state.width,height:this._state.height,tiltX:this._state.tiltX,tiltY:this._state.tiltY,pressure:this._state.pressure})}},{key:"_asMouseEvent",value:function(t){var i;return e?i=new MouseEvent("mouse"+t,{bubbles:!0,button:0,buttons:this._state.down?1:0,detail:"down"===t||"up"===t?1:0,clientX:this._state.x,clientY:this._state.y,screenX:this._state.x,screenY:this._state.y,pageX:this._state.x,pageY:this._state.y}):(i=document.createEvent("MouseEvent")).initMouseEvent("mouse"+t,!0,!0,window,0,this._state.x,this._state.y,this._state.x,this._state.y,!1,!1,!1,!1,0,null),i}},{key:"_initGraphicCircle",value:function(){this._graphic=document.createElementNS("http://www.w3.org/2000/svg","svg"),this._graphic.style.height="0px",this._graphic.style.width="0px",this._graphic.style.zIndex=1e6,this._graphic.style.position="absolute",this._graphic.style.top=0,this._graphic.style.left=0,this._graphic.style.marginLeft="-25px",this._graphic.style.marginTop="-25px",this._graphic.style.pointerEvents="none";var t=document.createElementNS("http://www.w3.org/2000/svg","circle");t.cx.baseVal.value=25,t.cy.baseVal.value=25,t.r.baseVal.value=20,t.style.stroke="rgba(0,0,0,0.3)",t.style.strokeWidth=2,t.style.fill="rgba(0,0,0,0.1)",this._graphic.appendChild(t),this._graphic.style.display="none",document.body.appendChild(this._graphic)}},{key:"_initGraphicIvansFinger",value:function(){this._graphic=document.createElement("img"),this._graphic.src="",this._graphic.style.height="160px",this._graphic.style.width="160px",this._graphic.style.zIndex=1e6,this._graphic.style.position="absolute",this._graphic.style.top=0,this._graphic.style.left=0,this._graphic.style.marginLeft="-20px",this._graphic.style.marginTop="-20px",this._graphic.style.pointerEvents="none",this._graphic.style.display="none",document.body.appendChild(this._graphic)}},{key:"_setGraphicPosition",value:function(t,e){this._graphic.style.transform="translate3d("+t+"px, "+e+"px, 0)"}},{key:"_statesAreEqual",value:function(t,e){for(var i in t)if(t[i]!==e[i])return!1;return!0}}]),n}(),v=1,g=2,z=3,y=4,b=5;return function(){function e(i){if(t.classCallCheck(this,e),i||(i={}),this._fingers=[],this._fingersAreIdle=!0,this._timeInterval=20,this._timingMode=v,this._framesPending=0,i.timing){var n=i.timing.toString();n.match(/^\d+ms$/)&&(this._timingMode=v,this._timeInterval=parseInt(n)),"frame"===n&&(this._timingMode=y,this._timeInterval=parseInt(n)),"minimal"===n&&(this._timingMode=g,this._timeInterval=!1),"instant"===n&&(this._timingMode=z,this._timeInterval=!1),"fastframe"===n&&(this._timingMode=b,this._timeInterval=parseInt(n))}i.onStart&&(this._onStart=i.onStart),i.onStop&&(this._onStop=i.onStop),this._nextDispatch=null}return t.createClass(e,[{key:"growFinger",value:function(e,i){i||(i={}),t.extends(i,{hand:this});var n=new p(e,i);return this._fingers.push(n),n}},{key:"fingerIsBusy",value:function(){return this._fingersAreIdle&&(document.dispatchEvent(new CustomEvent("prostheticHandStart",{target:this})),this._onStart&&this._onStart instanceof Function&&this._onStart(this),this._fingersAreIdle=!1,this._scheduleNextDispatch()),this}},{key:"fingerIsIdle",value:function(){this._fingers.every(function(t){return t.isIdle()})&&(this._fingersAreIdle||(document.dispatchEvent(new CustomEvent("prostheticHandStop",{target:this})),this._onStop&&this._onStop instanceof Function&&this._onStop(this)),this._fingersAreIdle=!0)}},{key:"sync",value:function(t){var e=performance.now();this._fingers.forEach(function(t){var i=t._movesUntil;i&&(e=Math.max(e,i))});var i=e+t;this._fingers.forEach(function(t){t.waitUntil(i)})}},{key:"_dispatchEvents",value:function(t){document.dispatchEvent(new CustomEvent("prostheticHandStart",{target:this}));var e,i,n=t||performance.now(),s=[],a=[],h=[],r=!1,o=void 0,c=!1,u=void 0,d=this._timingMode===g||this._timingMode===z||this._timingMode===b;(this._fingers.forEach(function(t){t.getEvents(n,d).forEach(function(t){"event"in t&&s.push(t.event),"touch"in t&&("down"===t.type&&(r=!0,o=t.touch.target),"up"===t.type?(c=!0,u=t.touch.target):a.push(t.touch),"idle"!==t.type&&h.push(t.touch))})}),s.forEach(function(t){document.elementFromPoint(t.clientX,t.clientY).dispatchEvent(t)}),a.length||c)&&(r?(e=this._createTouchEvent("touchstart",{cancelable:!0,bubbles:!0,touches:a,targetTouches:a.filter(function(t){return t.target===o}),changedTouches:h}),i=o):c?(u=document.elementFromPoint(h[0].clientX,h[0].clientY),e=this._createTouchEvent("touchend",{cancelable:!0,bubbles:!0,touches:a,target:u,targetTouches:a.filter(function(t){return t.target===u}),changedTouches:h}),i=u):(i=document.elementFromPoint(a[0].clientX,a[0].clientY),e=this._createTouchEvent("touchmove",{cancelable:!0,bubbles:!0,touches:a,targetTouches:a.filter(function(t){return t.target===i}),changedTouches:h})),h.length&&(i||(i=document),i.dispatchEvent(e)));return this._scheduleNextDispatch(),this}},{key:"_createTouchEvent",value:function(t,e){if(n)return new TouchEvent(t,e);var i;try{i=document.createEvent("TouchEvent")}catch(t){i=document.createEvent("UIEvent")}return i&&i.initTouchEvent&&(0!=i.initTouchEvent.length||l?12==i.initTouchEvent.length?i.initTouchEvent(t,e.bubbles,e.cancelable,window,e.detail,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,this._createTouchListFromArray(e.touches),this._createTouchListFromArray(e.targetTouches),this._createTouchListFromArray(e.changedTouches)):i.initTouchEvent(t,e.bubbles,e.cancelable,window,e.detail,0,0,0,0,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,this._createTouchListFromArray(e.touches),this._createTouchListFromArray(e.targetTouches),this._createTouchListFromArray(e.changedTouches),1,0):i.initTouchEvent(this._createTouchListFromArray(e.touches),this._createTouchListFromArray(e.targetTouches),this._createTouchListFromArray(e.changedTouches),t,window,0,0,0,0)),i}},{key:"_createTouchListFromArray",value:function(t){switch(t.length){case 0:return document.createTouchList();case 1:return document.createTouchList(t[0]);case 2:return document.createTouchList(t[0],t[1]);case 3:return document.createTouchList(t[0],t[1],t[2]);case 4:return document.createTouchList(t[0],t[1],t[2],t[3]);case 5:return document.createTouchList(t[0],t[1],t[2],t[3],t[4]);case 6:return document.createTouchList(t[0],t[1],t[2],t[3],t[4],t[5]);case 7:return document.createTouchList(t[0],t[1],t[2],t[3],t[4],t[5],t[6]);default:return document.createTouchList(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7])}}},{key:"_scheduleNextDispatch",value:function(){if(!this._fingersAreIdle){var t=1/0;if(this._fingers.forEach(function(e){if(!e.isIdle()){var i=e.getNextMoveEndTime();i<t&&(t=i)}}),this._timingMode===v)this._nextDispatch=setTimeout(this._dispatchEvents.bind(this),this._timeInterval);else if(this._timingMode===g)this._nextDispatch=setTimeout(this._dispatchEvents.bind(this),t-performance.now());else{if(this._timingMode===z)return this._dispatchEvents(t);this._timingMode===y?this._nextDispatch=requestAnimationFrame(this._dispatchEvents.bind(this)):this._timingMode===b&&(this._nextDispatch=requestAnimationFrame(function(){this._dispatchEvents(t)}.bind(this)))}}}}]),e}()});let h1=new Hand({timing:'20ms'});let f1=h1.growFinger('mouse');function getRandomInt(min,max){min=Math.ceil(min);max=Math.floor(max);return Math.floor(Math.random()*(max-min))+min} function randomTask(first = false){let x=getRandomInt(20,window.innerWidth-50),y=getRandomInt(20,window.innerHeight-50);let nextTime=getRandomInt(5,20)*100;try{if(getRandomInt(0,100)>70){f1.down()} if(getRandomInt(0,100)>50){f1.moveTo(x,y,first ? 0 : nextTime-100)}}catch(e){} setTimeout(()=>{randomTask()},nextTime)} if (getRandomInt(0,3) >= 1) randomTask(true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement