function t(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function e(e){for(var i=1;arguments.length>i;i++){var n=null!=arguments[i]?arguments[i]:{};i%2?t(Object(n),!0).forEach((function(t){s(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){for(var i=0;e.length>i;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)}}function r(t,e,i){return e&&o(t.prototype,e),i&&o(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&u(t,e)}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}function u(t,e){return u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},u(t,e)}function h(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function l(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var i,n=c(t);if(e){var o=c(this).constructor;i=Reflect.construct(n,arguments,o)}else i=n.apply(this,arguments);return h(this,i)}}var v={}.toString,f=function(t,e){return v.call(t)==="[object "+e+"]"},d=function(t){return f(t,"String")},y=function(t){return f(t,"Number")},p=function(){function t(){n(this,t),this.__events=void 0,this.__events={}}return r(t,[{key:"on",value:function(t,e){if(t&&e){var i=this.__events[t]||[];i.push(e),this.__events[t]=i}}},{key:"emit",value:function(t,e){var n=this;if(function(t){var e=i(t);return null!==t&&"object"===e||"function"===e}(t)&&(t=(e=t)&&e.type),t){var o=this.__events[t];o&&o.length&&o.forEach((function(t){t.call(n,e)}))}}},{key:"off",value:function(t,e){var i=this.__events,n=i[t];if(n&&n.length)if(e)for(var o=0,r=n.length;r>o;o++)n[o]===e&&(n.splice(o,1),o--);else delete i[t]}},{key:"getEvents",value:function(){return this.__events}}]),t}(),g=function(t){a(i,p);var e=l(i);function i(t,o){var r;return n(this,i),(r=e.call(this)).context=void 0,r.canvas=void 0,r.attrs=void 0,r.isCanvasElement=void 0,r.context=t,r.canvas=o.canvas||t.canvas||{width:o.width||0,height:o.height||0},r.attrs=o||{},r.isCanvasElement=!0,r}return r(i,[{key:"width",get:function(){return this.canvas.width},set:function(t){this.canvas.width=t}},{key:"height",get:function(){return this.canvas.height},set:function(t){this.canvas.height=t}},{key:"getContext",value:function(){return this.context}},{key:"getBoundingClientRect",value:function(){var t=this.attrs||{},e=t.top,i=t.right,n=t.width,o=t.height,r=t.left,s=t.bottom;return{top:void 0===e?0:e,width:void 0===n?0:n,right:void 0===i?0:i,height:void 0===o?0:o,bottom:void 0===s?0:s,left:void 0===r?0:r}}},{key:"setAttribute",value:function(t,e){this.attrs[t]=e}},{key:"addEventListener",value:function(t,e){this.on(t,e)}},{key:"removeEventListener",value:function(t,e){this.off(t,e)}},{key:"dispatchEvent",value:function(t,e){this.emit(t,e)}}]),i}();var m=function(t,e){return t?function(t){if(!t)return!1;if(1!==t.nodeType||!t.nodeName||"canvas"!==t.nodeName.toLowerCase())return!1;var e=!1;try{t.addEventListener("eventTest",(function(){e=!0})),t.dispatchEvent(new Event("eventTest"))}catch(t){e=!1}return e}(t.canvas)?t.canvas:new g(t,e):null};function x(t,e){try{return t.currentStyle?t.currentStyle[e]:document.defaultView&&document.defaultView.getComputedStyle(t,null).getPropertyValue(e)}catch(t){return{width:300,height:150}[e]}}function w(t,e){var i=e.get("el");if(!i)return t;var n=i.getBoundingClientRect(),o=n.top,r=void 0===o?0:o,s=n.left,a=void 0===s?0:s,c=parseFloat(x(i,"padding-left"))||0,u=parseFloat(x(i,"padding-top"))||0;return{x:t.x-a-c,y:t.y-r-u}}function b(t,e){var i=e.get("landscape");if(!i)return t;if(f(i,"Function"))return i(t,e);var n=e.get("height");return{x:t.y,y:n-t.x}}var k=function(t,e){var i=t.touches;if(!i||!i.length)return[b(w({x:t.clientX,y:t.clientY},e),e)];i.length||(i=t.changedTouches||[]);for(var n=[],o=0,r=i.length;r>o;o++){var s=i[o],a=s.x,c=s.y,u=s.clientX,h=s.clientY,l=void 0;l=y(a)||y(c)?{x:a,y:c}:w({x:u,y:h},e),n.push(b(l,e))}return n},_=function(t,e){var i=e.x-t.x,n=e.y-t.y;return Math.abs(i)>Math.abs(n)?i>0?"right":"left":n>0?"down":"up"},E=function(t,e){var i=Math.abs(e.x-t.x),n=Math.abs(e.y-t.y);return Math.sqrt(i*i+n*n)},L=function(){function t(e){var i=this,o=e.canvas,r=e.el;n(this,t),this.processEvent=void 0,this.canvas=void 0,this.startTime=0,this.endTime=0,this.startPoints=null,this.startDistance=0,this.center=null,this.pressTimeout=void 0,this.eventType=null,this.direction=null,this.lastMoveTime=0,this.prevMovePoints=null,this.prevMoveTime=0,this.lastMovePoints=null,this.pinch=!1,this._click=function(t){var e=k(t,i.canvas);t.points=e,i.emitEvent("click",t)},this._start=function(t){var e,n,o=k(t,i.canvas);o&&(t.points=o,i.emitEvent("touchstart",t),i.reset(),i.startTime=Date.now(),i.startPoints=o,o.length>1?(i.startDistance=E(o[0],o[1]),i.center={x:(e=o[0]).x+((n=o[1]).x-e.x)/2,y:e.y+(n.y-e.y)/2}):i.pressTimeout=setTimeout((function(){var e="press",n="none";t.direction=n,i.emitStart(e,t),i.emitEvent(e,t),i.eventType=e,i.direction=n}),250))},this._move=function(t){var e=k(t,i.canvas);if(e){t.points=e,i.emitEvent("touchmove",t);var n=i.startPoints;if(n)if(e.length>1){var o=i.startDistance,r=E(e[0],e[1]);t.zoom=r/o,t.center=i.center,i.emitStart("pinch",t),i.emitEvent("pinch",t)}else{var s=e[0].x-n[0].x,a=e[0].y-n[0].y,c=i.direction||_(n[0],e[0]);i.direction=c;var u=i.getEventType(e);t.direction=c,t.deltaX=s,t.deltaY=a,i.emitStart(u,t),i.emitEvent(u,t);var h=i.lastMoveTime,l=Date.now();l-h>0&&(i.prevMoveTime=h,i.prevMovePoints=i.lastMovePoints,i.lastMoveTime=l,i.lastMovePoints=e)}}},this._end=function(t){var e=k(t,i.canvas);t.points=e,i.emitEnd(t),i.emitEvent("touchend",t);var n=i.lastMoveTime;if(100>Date.now()-n){var o=n-(i.prevMoveTime||i.startTime);if(o>0){var r=i.prevMovePoints||i.startPoints,s=i.lastMovePoints;if(!r||!s)return;var a=E(r[0],s[0])/o;a>.3&&(t.velocity=a,t.direction=_(r[0],s[0]),i.emitEvent("swipe",t))}}i.reset();var c=t.touches;c&&c.length>0&&i._start(t)},this._cancel=function(t){i.emitEvent("touchcancel",t),i.reset()},this.canvas=o,this.delegateEvent(r),this.processEvent={}}return r(t,[{key:"delegateEvent",value:function(t){t.addEventListener("click",this._click),t.addEventListener("touchstart",this._start),t.addEventListener("touchmove",this._move),t.addEventListener("touchend",this._end),t.addEventListener("touchcancel",this._cancel)}},{key:"emitEvent",value:function(t,e){this.canvas.emit(t,e)}},{key:"getEventType",value:function(t){var e,i=this.eventType,n=this.startTime,o=this.startPoints;if(i)ret
评论0