h5-image-editor
Version:
h5 image editor
2 lines • 45.3 kB
JavaScript
/*! For license information please see index.min.js.LICENSE.txt */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ImageEditor=e():t.ImageEditor=e()}(self,(function(){return function(){var t={591:function(t,e,n){var i=n(8).default;function o(){"use strict";t.exports=o=function(){return n},t.exports.__esModule=!0,t.exports.default=t.exports;var e,n={},r=Object.prototype,a=r.hasOwnProperty,s=Object.defineProperty||function(t,e,n){t[e]=n.value},h="function"==typeof Symbol?Symbol:{},l=h.iterator||"@@iterator",u=h.asyncIterator||"@@asyncIterator",c=h.toStringTag||"@@toStringTag";function d(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{d({},"")}catch(e){d=function(t,e,n){return t[e]=n}}function f(t,e,n,i){var o=e&&e.prototype instanceof b?e:b,r=Object.create(o.prototype),a=new R(i||[]);return s(r,"_invoke",{value:P(t,n,a)}),r}function p(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}n.wrap=f;var m="suspendedStart",y="suspendedYield",v="executing",g="completed",w={};function b(){}function x(){}function E(){}var O={};d(O,l,(function(){return this}));var T=Object.getPrototypeOf,k=T&&T(T(C([])));k&&k!==r&&a.call(k,l)&&(O=k);var S=E.prototype=b.prototype=Object.create(O);function _(t){["next","throw","return"].forEach((function(e){d(t,e,(function(t){return this._invoke(e,t)}))}))}function M(t,e){function n(o,r,s,h){var l=p(t[o],t,r);if("throw"!==l.type){var u=l.arg,c=u.value;return c&&"object"==i(c)&&a.call(c,"__await")?e.resolve(c.__await).then((function(t){n("next",t,s,h)}),(function(t){n("throw",t,s,h)})):e.resolve(c).then((function(t){u.value=t,s(u)}),(function(t){return n("throw",t,s,h)}))}h(l.arg)}var o;s(this,"_invoke",{value:function(t,i){function r(){return new e((function(e,o){n(t,i,e,o)}))}return o=o?o.then(r,r):r()}})}function P(t,n,i){var o=m;return function(r,a){if(o===v)throw new Error("Generator is already running");if(o===g){if("throw"===r)throw a;return{value:e,done:!0}}for(i.method=r,i.arg=a;;){var s=i.delegate;if(s){var h=L(s,i);if(h){if(h===w)continue;return h}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if(o===m)throw o=g,i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);o=v;var l=p(t,n,i);if("normal"===l.type){if(o=i.done?g:y,l.arg===w)continue;return{value:l.arg,done:i.done}}"throw"===l.type&&(o=g,i.method="throw",i.arg=l.arg)}}}function L(t,n){var i=n.method,o=t.iterator[i];if(o===e)return n.delegate=null,"throw"===i&&t.iterator.return&&(n.method="return",n.arg=e,L(t,n),"throw"===n.method)||"return"!==i&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+i+"' method")),w;var r=p(o,t.iterator,n.arg);if("throw"===r.type)return n.method="throw",n.arg=r.arg,n.delegate=null,w;var a=r.arg;return a?a.done?(n[t.resultName]=a.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,w):a:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,w)}function D(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function R(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(D,this),this.reset(!0)}function C(t){if(t||""===t){var n=t[l];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,r=function n(){for(;++o<t.length;)if(a.call(t,o))return n.value=t[o],n.done=!1,n;return n.value=e,n.done=!0,n};return r.next=r}}throw new TypeError(i(t)+" is not iterable")}return x.prototype=E,s(S,"constructor",{value:E,configurable:!0}),s(E,"constructor",{value:x,configurable:!0}),x.displayName=d(E,c,"GeneratorFunction"),n.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===x||"GeneratorFunction"===(e.displayName||e.name))},n.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,E):(t.__proto__=E,d(t,c,"GeneratorFunction")),t.prototype=Object.create(S),t},n.awrap=function(t){return{__await:t}},_(M.prototype),d(M.prototype,u,(function(){return this})),n.AsyncIterator=M,n.async=function(t,e,i,o,r){void 0===r&&(r=Promise);var a=new M(f(t,e,i,o),r);return n.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},_(S),d(S,c,"Generator"),d(S,l,(function(){return this})),d(S,"toString",(function(){return"[object Generator]"})),n.keys=function(t){var e=Object(t),n=[];for(var i in e)n.push(i);return n.reverse(),function t(){for(;n.length;){var i=n.pop();if(i in e)return t.value=i,t.done=!1,t}return t.done=!0,t}},n.values=C,R.prototype={constructor:R,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(j),!t)for(var n in this)"t"===n.charAt(0)&&a.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function i(i,o){return s.type="throw",s.arg=t,n.next=i,o&&(n.method="next",n.arg=e),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var r=this.tryEntries[o],s=r.completion;if("root"===r.tryLoc)return i("end");if(r.tryLoc<=this.prev){var h=a.call(r,"catchLoc"),l=a.call(r,"finallyLoc");if(h&&l){if(this.prev<r.catchLoc)return i(r.catchLoc,!0);if(this.prev<r.finallyLoc)return i(r.finallyLoc)}else if(h){if(this.prev<r.catchLoc)return i(r.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<r.finallyLoc)return i(r.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&a.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var r=o?o.completion:{};return r.type=t,r.arg=e,o?(this.method="next",this.next=o.finallyLoc,w):this.complete(r)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),w},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),j(n),w}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var i=n.completion;if("throw"===i.type){var o=i.arg;j(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,i){return this.delegate={iterator:C(t),resultName:n,nextLoc:i},"next"===this.method&&(this.arg=e),w}},n}t.exports=o,t.exports.__esModule=!0,t.exports.default=t.exports},8:function(t){function e(n){return t.exports=e="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},t.exports.__esModule=!0,t.exports.default=t.exports,e(n)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports},757:function(t,e,n){var i=n(591)();t.exports=i;try{regeneratorRuntime=i}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=i:Function("r","regeneratorRuntime = r")(i)}},814:function(t){self,t.exports=function(){"use strict";var t={d:function(e,n){for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function n(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function r(t,e,n){return e&&o(t.prototype,e),n&&o(t,n),t}t.r(e),t.d(e,{Base:function(){return g},default:function(){return D}});var a,s,h="ontouchstart"in document||navigator.maxTouchPoints,l=navigator.userAgent,u=window.navigator.msPointerEnabled&&/IEMobile/i.test(l);h=h||u||!1,void 0!==document.hidden?(a="hidden",s="visibilitychange"):void 0!==document.msHidden?(a="msHidden",s="msvisibilitychange"):void 0!==document.webkitHidden&&(a="webkitHidden",s="webkitvisibilitychange");var c=u?{START:"MSPointerDown",MOVE:"MSPointerMove",END:"MSPointerUp",CANCEL:"MSPointerCancel",HIDDEN:a,VISIBILITYCHANGE:s}:{START:h?"touchstart":"mousedown",MOVE:h?"touchmove":"mousemove",END:h?"touchend":"mouseup",CANCEL:h?"touchcancel":"mouseout",HIDDEN:a,VISIBILITYCHANGE:s};function d(){}function f(t){if(t.changedTouches){var e=t.changedTouches[0];return e.touchLength=t.changedTouches.length,e}return t.touchLength=1,t}function p(t){return p=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},p(t)}function m(t,e,n){return m="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=p(t)););return t}(t,e);if(i){var o=Object.getOwnPropertyDescriptor(i,e);return o.get?o.get.call(n):o.value}},m(t,e,n||t)}function y(t,e){return y=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},y(t,e)}function v(t){return v="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},v(t)}c.RESIZE="onorientationchange"in window?"orientationchange":"resize";var g=function(){function t(){i(this,t)}return r(t,[{key:"init",value:function(){this.resize=this.resize.bind(this),this.attachEvents(),this.resize()}},{key:"resize",value:function(){var t,e,n=this.options,i=n.width,o=n.height,r=n.maxWidth,a=n.root,s=n.scaleRatio;if(t="auto"===i?a.clientWidth:i,e="auto"===o?a.clientHeight:o,s>0?(this.drawElement.width=t*s,this.drawElement.height=e*s,this.drawCtx.scale(s,s)):(this.drawElement.width=t,this.drawElement.height=e),r){var h=t;t=Math.min(t,r),e=Math.min(e,t/h*e)}this.drawElement.style.cssText="width: ".concat(t,"px; height: ").concat(e,"px; touch-action: none;"),this.tempImageData&&(this.drawCtx.putImageData(this.tempImageData,0,0),this.tempImageData=null,this._isResizing=!1)}},{key:"attachEvents",value:function(){var t,e,n,i=this,o=this.options,r=o.width,a=o.height,s=(t=this.resize.bind(this),e=this.options.resizeDebounceTime,n=null,function(){n&&clearTimeout(n),n=setTimeout(t,e)});this.resizeHandle=function(t){i._isResizing||(i.tempImageData=i.drawCtx.getImageData(0,0,i.drawElement.width,i.drawElement.height)),i._isResizing=!0,s(t)},"auto"!==r&&"auto"!==a||window.addEventListener(c.RESIZE,this.resizeHandle,!1)}},{key:"detachEvents",value:function(){window.removeEventListener(c.RESIZE,this.resizeHandle,!1)}},{key:"destroy",value:function(){this.detachEvents()}}]),t}();function w(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function b(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?w(Object(i),!0).forEach((function(e){n(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):w(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}var x=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i(this,t),this._touchTimer=null,this.options=b(b({},t.defaultOptions),e)}return r(t,[{key:"attach",value:function(t){this.element=t,this.bindEvents()}},{key:"bindEvents",value:function(){this.onTouchStart=this.onTouchStart.bind(this),this.onTouchMove=this.onTouchMove.bind(this),this.onTouchEnd=this.onTouchEnd.bind(this),this.onMouseOut=this.onMouseOut.bind(this),this.element.addEventListener(c.START,this.onTouchStart,!1),this.element.addEventListener(c.MOVE,this.onTouchMove,!1),this.element.addEventListener(c.END,this.onTouchEnd,!1),this.element.addEventListener(c.CANCEL,this.onMouseOut,!1)}},{key:"onTouchStart",value:function(t){var e=this;t=f(t),this._startTime=Date.now(),this.clearTouchTimer(),this.setMouseEventXY(t),this.options.onMouseDown(t),this._touchTimer=setTimeout((function(){e.options.onLongTap(t)}),300)}},{key:"onTouchMove",value:function(t){t.preventDefault(),t=f(t),this.clearTouchTimer(),this.setMouseEventXY(t),this.options.onMouseMove(t)}},{key:"onTouchEnd",value:function(t){t=f(t),this.clearTouchTimer(),this.setMouseEventXY(t),this.options.onMouseUp(t),Date.now()-this._startTime<100&&this.options.onClick(t)}},{key:"onMouseOut",value:function(t){this.clearTouchTimer(),this.options.onMouseOut(t)}},{key:"clearTouchTimer",value:function(){this._touchTimer&&clearTimeout(this._touchTimer)}},{key:"setMouseEventXY",value:function(t){var e=function(t,e){if(void 0!==e.offsetX)return{x:e.offsetX,y:e.offsetY};if(void 0!==e.layerX&&e.layerX!==e.offsetX)return{x:e.layerX,y:e.layerY};var n=function(t){try{return t.getBoundingClientRect()}catch(t){return{left:0,top:0}}}(t),i=n.width/t.clientWidth;return{x:(e.clientX-n.left)/i,y:(e.clientY-n.top)/i}}(this.element,t),n=e.x,i=e.y;t.stageX=n,t.stageY=i}},{key:"detach",value:function(){this.element.removeEventListener(c.START,this.onTouchStart,!1),this.element.removeEventListener(c.MOVE,this.onTouchMove,!1),this.element.removeEventListener(c.END,this.onTouchEnd,!1),this.element.removeEventListener(c.CANCEL,this.onMouseOut,!1)}}]),t}();x.defaultOptions={onMouseDown:d,onMouseMove:d,onMouseUp:d,onMouseOut:d,onClick:d,onLongTap:d};var E=x;function O(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function T(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?O(Object(i),!0).forEach((function(e){n(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):O(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}var k=function(t){!function(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}}),e&&y(t,e)}(a,t);var e,n,o=(e=a,n=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}}(),function(){var t,i=p(e);if(n){var o=p(this).constructor;t=Reflect.construct(i,arguments,o)}else t=i.apply(this,arguments);return function(t,e){if(e&&("object"===v(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)}(this,t)});function a(){var t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return i(this,a),(t=o.call(this,e)).options=e,t._isStart=!1,t._isMoved=!1,t._isEmpty=!0,t._touchCount=0,t.prePoint={},t.point={},t}return r(a,[{key:"init",value:function(){var t=this.options.root;this.drawElement=document.createElement("canvas"),this.drawCtx=this.drawElement.getContext("2d"),t.appendChild(this.drawElement),m(p(a.prototype),"init",this).call(this),this.mouseEvent=new E({onMouseDown:this.handleMouseDown.bind(this),onMouseMove:this.handleMouseMove.bind(this),onMouseUp:this.handleMouseUp.bind(this),onMouseOut:this.handleMouseUp.bind(this)}),this.mouseEvent.attach(this.drawElement)}},{key:"drawStartPoint",value:function(t){this.drawCtx.lineWidth=this.options.lineWidth,this.drawCtx.beginPath(),this.drawCtx.moveTo(t.stageX,t.stageY),this.drawCtx.lineTo(t.stageX+.1,t.stageY+.1),this.drawCtx.stroke()}},{key:"drawSmoothLine",value:function(t,e){var n=.33*(e.x-t.x),i=.33*(e.y-t.y),o=t.x+n,r=t.y+i,a=o+n,s=r+i;if(e.lastX=a,e.lastY=s,"number"==typeof t.lastX){var h=(t.lineWidth+e.lineWidth)/2;this.drawCurveLine(t.lastX,t.lastY,t.x,t.y,o,r,h)}this.drawLine(o,r,a,s,e.lineWidth)}},{key:"drawNoSmoothLine",value:function(t,e){var n=(e.x-t.x)/2,i=(e.y-t.y)/2;e.lastX=t.x+n,e.lastY=t.y+i,"number"==typeof t.lastX&&this.drawCurveLine(t.lastX,t.lastY,t.x,t.y,e.lastX,e.lastY,this.options.lineWidth)}},{key:"drawLine",value:function(t,e,n,i,o){this.drawCtx.lineWidth=o,this.drawCtx.beginPath(),this.drawCtx.moveTo(t,e),this.drawCtx.lineTo(n,i),this.drawCtx.closePath(),this.drawCtx.stroke()}},{key:"drawCurveLine",value:function(t,e,n,i,o,r,a){this.drawCtx.lineWidth=a,this.drawCtx.beginPath(),this.drawCtx.moveTo(t,e),this.drawCtx.quadraticCurveTo(n,i,o,r),this.drawCtx.stroke()}},{key:"drawByImage",value:function(t){var e=this.options.scaleRatio,n=this.drawElement,i=n.width,o=n.height;this.clear(),this.drawCtx.drawImage(t,0,0,i/e,o/e)}},{key:"handleMouseDown",value:function(t){this._touchCount++,t.touchLength>1||this._touchCount>1?this._isStart=!1:(this._isStart=!0,this.prePoint={x:t.stageX,y:t.stageY,t:Date.now(),lastX:t.stageX,lastY:t.stageY,color:this.options.color,lineWidth:this.options.lineWidth},this.drawCtx.lineJoin="round",this.drawCtx.lineCap="round",this.drawCtx.strokeStyle=this.options.color,this.options.onDrawStart(t,this.prePoint))}},{key:"handleMouseMove",value:function(t){this._isStart&&(this.point={x:t.stageX,y:t.stageY,t:Date.now(),color:this.options.color},this.point.lineWidth=this._calculateLineWidth(),this.options.openSmooth?this.drawSmoothLine(this.prePoint,this.point):this.drawNoSmoothLine(this.prePoint,this.point),this.prePoint=T({},this.point),this._isMoved=!0,this._isEmpty=!1,this.options.onDrawing(t,this.point))}},{key:"handleMouseUp",value:function(t){var e=this;if(this._touchCount=0,this._isStart){this._isMoved||this.drawStartPoint(t),this._isStart=!1,this._isEmpty=!1,this._isMoved=!1;var n=new Image;n.src=this.drawElement.toDataURL(),n.onload=function(){e.options.onDrawUp(t,n),n.onload=null}}}},{key:"setLineWidth",value:function(t){this.options.lineWidth=t}},{key:"setColor",value:function(t){this.options.color=t}},{key:"setOptions",value:function(t){this.options=T(T({},this.options),t)}},{key:"getLineWidth",value:function(t){var e=this.options.lineWidth,n=this.options.minWidth,i=(e-n)*t/(this.options.minSpeed>10?10:this.options.minSpeed<1?1:this.options.minSpeed),o=Math.max(e-i,n);return Math.min(o,e)}},{key:"isEmpy",value:function(){return this._isEmpty}},{key:"clear",value:function(){this._isEmpty=!0,this.drawElement&&this.drawCtx.clearRect(0,0,this.drawElement.width,this.drawElement.height)}},{key:"destroy",value:function(){this._isStart=null,this._isMoved=null,this._isEmpty=null,this.prePoint=null,this.point=null,this.clear(),m(p(a.prototype),"destroy",this).call(this),this.mouseEvent.detach();try{(this.drawElement.parentElement||document.body).removeChild(this.drawElement),this.drawElement=null}catch(t){}}},{key:"_calculateLineWidth",value:function(){if(this.options.openSmooth){var t=this._calculateSpeed(),e=this.getLineWidth(t),n=(e-this.prePoint.lineWidth)/this.prePoint.lineWidth,i=this.options.maxWidthDiffRate/100;if(i=i>1?1:i<.01?.01:i,Math.abs(n)>i){var o=n>0?i:-i;e=this.prePoint.lineWidth*(1+o)}return e}return this.options.lineWidth}},{key:"_calculateSpeed",value:function(){var t=this.point.t-this.prePoint.t||.1,e=this.point.x-this.prePoint.x,n=this.point.y-this.prePoint.y;return Math.sqrt(e*e,n*n)/t}}]),a}(g),S=k,_=function(){function t(e){i(this,t),this._undoStack=[],this._redoStack=[],this.maxLength=e}return r(t,[{key:"push",value:function(t,e){var n=this;this._undoStack.push((function i(){t(),n._redoStack.push((function(){e(),n._undoStack.push(i)}))})),this.maxLength>0&&this._undoStack.length>this.maxLength&&(this._undoStack=this._undoStack.slice(-this.maxLength))}},{key:"undo",value:function(){var t=this._undoStack.pop();t instanceof Function&&t()}},{key:"redo",value:function(){var t=this._redoStack.pop();t instanceof Function&&t()}},{key:"setMaxHistoryLength",value:function(t){this.maxLength=t}},{key:"canUndo",value:function(){return this._undoStack.length>0}},{key:"canRedo",value:function(){return this._redoStack.length>0}},{key:"clear",value:function(){this._redoStack=[],this._undoStack=[]}}]),t}();function M(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function P(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?M(Object(i),!0).forEach((function(e){n(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):M(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}var L=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i(this,t),this.options=P(P({},t.defaultOptions),e),this.drawStack=[],this.lastCanUndo=!1,this.lastCanRedo=!1,this._isEmpty=!0,this.painter=new S(P(P({},this.options),{},{onDrawUp:this.onDrawUp.bind(this)})),this.undoRedoManager=new _(this.options.maxHistoryLength),this.init()}return r(t,[{key:"init",value:function(){var t=this.options.root;if(!(t&&t instanceof Element))throw new Error("Invalid root element.");this.painter.init(),this.drawElement=this.painter.drawElement,this.handleUndoRedoStateChange(!0)}},{key:"onDrawUp",value:function(t,e){var n=this,i=function(){n.drawStack.push(e)};this.undoRedoManager.push((function(){n.drawStack.pop()}),i),i(),this.options.onDrawUp(t,e),this.handleUndoRedoStateChange()}},{key:"rerender",value:function(){var t=this.drawStack[this.drawStack.length-1];t?this.painter.drawByImage(t):this.painter.clear()}},{key:"clear",value:function(){this.drawStack=[],this.undoRedoManager.clear(),this.painter.clear(),this.handleUndoRedoStateChange()}},{key:"setLineWidth",value:function(t){this.painter.setLineWidth(t)}},{key:"setColor",value:function(t){this.painter.setColor(t)}},{key:"setOptions",value:function(t){this.options=P(P({},this.options),t),this.painter.setOptions(P(P({},t),{},{onDrawUp:this.onDrawUp.bind(this)})),t&&"maxHistoryLength"in t&&this.undoRedoManager.setMaxHistoryLength(t.maxHistoryLength)}},{key:"handleUndoRedoStateChange",value:function(t){var e=this.canUndo(),n=this.canRedo();t&&this.options.undoRedoStateChange(e,n),this.lastCanUndo!==e&&(this.options.undoRedoStateChange(e,n),this.lastCanUndo=e),this.lastCanRedo!==n&&(this.options.undoRedoStateChange(e,n),this.lastCanRedo=n)}},{key:"undo",value:function(){this.undoRedoManager.undo(),this.rerender(),this.handleUndoRedoStateChange()}},{key:"redo",value:function(){this.undoRedoManager.redo(),this.rerender(),this.handleUndoRedoStateChange()}},{key:"canUndo",value:function(){return this.undoRedoManager.canUndo()}},{key:"canRedo",value:function(){return this.undoRedoManager.canRedo()}},{key:"isEmpty",value:function(){return this.painter.isEmpy()}},{key:"destroy",value:function(){this.clear(),this.painter.destroy(),this.undoRedoManager.clear()}},{key:"getValidBound",value:function(t){for(var e=t.getContext("2d"),n=t.width,i=t.height,o=e.getImageData(0,0,n,i).data,r=n,a=0,s=i,h=0,l=0;l<n;l++)for(var u=0;u<i;u++)o[4*(l+n*u)+3]>0&&(h=Math.max(u,h),a=Math.max(l,a),s=Math.min(u,s),r=Math.min(l,r));return{cutWidth:++a-++r,cutHeight:++h-++s,lOffset:r,rOffset:a,tOffset:s,bOffset:h}}},{key:"getResult",value:function(t){try{var e=this.drawElement;0!==this.options.rotate&&(e=this.getRotateCanvas(this.options.rotate));var n=this.getValidBound(e),i=n.cutWidth,o=n.cutHeight,r=n.lOffset,a=n.tOffset;if(i<=0||o<=0)return;if(t)return e;var s=this.options,h=s.exportMaxWidth,l=s.exportMaxHeight,u=s.exportPadding,c=s.scaleRatio,d=document.createElement("canvas"),f=d.getContext("2d");if(d.width=i,d.height=o,f.drawImage(e,r,a,i,o,0,0,d.width,d.height),h||l||0!==u){var p=d.width,m=d.height,y=h*c,v=l*c;h&&y<p&&(m*=y/p,p=y),l&&v<m&&(p*=v/m,m=v);var g=document.createElement("canvas"),w=g.getContext("2d");return g.width=p,g.height=m,w.drawImage(d,u,u,g.width-2*u,g.height-2*u),g}return d}catch(t){console.error(t)}}},{key:"getRotateCanvas",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:90;t=t>0?t>90?180:90:t<-90?180:-90;var e=document.createElement("canvas"),n=this.drawElement.width,i=this.drawElement.height;180===t?(e.width=n,e.height=i):(e.width=i,e.height=n);var o=e.getContext("2d");return o.rotate(t*Math.PI/180),90===t?o.drawImage(this.drawElement,0,-i,n,i):-90===t?o.drawImage(this.drawElement,-n,0,n,i):180===t&&o.drawImage(this.drawElement,-n,-i,n,i),e}},{key:"base64ToBlob",value:function(t){for(var e=t.split(";base64,"),n=e[0].split(":")[1],i=window.atob(e[1]),o=i.length,r=new Uint8Array(o),a=0;a<o;++a)r[a]=i.charCodeAt(a);return new Blob([r],{type:n})}},{key:"downloadFile",value:function(){var t=Date.now(),e=document.createElement("a"),n=this.base64ToBlob(this.drawElement.toDataURL()),i=URL.createObjectURL(n);document.createEvent("HTMLEvents").initEvent("click",!0,!0),e.download=t,e.href=i,e.click(),window.URL.revokeObjectURL(i),e=null,i=null}}]),t}();L.defaultOptions={root:null,width:"auto",height:"auto",openSmooth:!0,color:"#000",lineWidth:8,rotate:0,minWidth:2,minSpeed:1.5,scaleRatio:window.devicePixelRatio||1,maxWidth:null,maxWidthDiffRate:20,resizeDebounceTime:200,maxHistoryLength:0,exportPadding:0,exportMaxWidth:null,exportMaxHeight:null,undoRedoStateChange:d,onDrawStart:d,onDrawing:d,onDrawUp:d};var D=L;return e}()}},e={};function n(i){var o=e[i];if(void 0!==o)return o.exports;var r=e[i]={exports:{}};return t[i](r,r.exports,n),r.exports}n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,{a:e}),e},n.d=function(t,e){for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return function(){"use strict";function t(t,e,n,i,o,r,a){try{var s=t[r](a),h=s.value}catch(t){return void n(t)}s.done?e(h):Promise.resolve(h).then(i,o)}function e(t){return e="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},e(t)}function o(t){var n=function(t,n){if("object"!==e(t)||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var o=i.call(t,"string");if("object"!==e(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===e(n)?n:String(n)}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,o(i.key),i)}}function s(t,e,n){return e&&a(t.prototype,e),n&&a(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}n.r(i),n.d(i,{default:function(){return j}});var h=n(757),l=n.n(h),u=n(814),c=n.n(u);function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}function f(){return f="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=d(t)););return t}(t,e);if(i){var o=Object.getOwnPropertyDescriptor(i,e);return o.get?o.get.call(arguments.length<3?t:n):o.value}},f.apply(this,arguments)}function p(t,e){return p=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},p(t,e)}function m(t){var n=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,o=d(t);if(n){var r=d(this).constructor;i=Reflect.construct(o,arguments,r)}else i=o.apply(this,arguments);return function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;if(void 0!==n)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)}(this,i)}}var y=function(t){!function(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&&p(t,e)}(n,t);var e=m(n);function n(){var t,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return r(this,n),(t=e.call(this,i)).options=i,t}return s(n,[{key:"init",value:function(){var t=this.options.root;this.drawElement=document.createElement("canvas"),this.drawCtx=this.drawElement.getContext("2d"),t.appendChild(this.drawElement),f(d(n.prototype),"init",this).call(this)}},{key:"drawImage",value:function(t){var e=this.options,n=e.width,i=e.height;this.drawCtx.drawImage(t,0,0,n,i)}},{key:"destroy",value:function(){f(d(n.prototype),"destroy",this).call(this);try{(this.drawElement.parentElement||document.body).removeChild(this.drawElement),this.drawElement=null}catch(t){}}}]),n}(u.Base),v=y;function g(t){return t}function w(t,e,n,i){t.onload=function(){n(t),t.onload=null},t.onerror=function(e){i(e),t.onerror=null},t.setAttribute("crossorigin","anonymous"),t.src=e}function b(t){var e=new Image;return new Promise((function(n,i){w(e,t,n,i)}))}function x(t){var e=new Image;return new Promise((function(n,i){w(e,URL.createObjectURL(t),n,i)}))}function E(t){return Math.sqrt(t.x*t.x+t.y*t.y)}var O=function(){function t(e,n){r(this,t),this.element=e,this.options=n,this.preV={x:null,y:null},this.pinchStartLen=null,this.scale=1,this.isDoubleTap=!1,this.delta=null,this.last=null,this.now=null,this.end=null,this.multiTouch=!1,this.tapTimeout=null,this.longTapTimeout=null,this.singleTapTimeout=null,this.swipeTimeout=null,this.x1=this.x2=this.y1=this.y2=null,this.preTapPosition={x:null,y:null},this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.element.addEventListener("touchstart",this.handleStart,!1),this.element.addEventListener("touchmove",this.handleMove,!1),this.element.addEventListener("touchend",this.handleEnd,!1),this.element.addEventListener("touchcancel",this.handleCancel,!1)}return s(t,[{key:"_emitEvent",value:function(t){if(this.options[t]){for(var e=arguments.length,n=new Array(e>1?e-1:0),i=1;i<e;i++)n[i-1]=arguments[i];this.options[t].apply(this.options.context,n)}}},{key:"handleStart",value:function(t){var e=this;if(t.touches){this.now=Date.now(),this.x1=t.touches[0].clientX,this.y1=t.touches[0].clientY,this.delta=this.now-(this.last||this.now),null!==this.preTapPosition.x&&(this.isDoubleTap=this.delta>0&&this.delta<=250&&Math.abs(this.preTapPosition.x-this.x1)<30&&Math.abs(this.preTapPosition.y-this.y1)<30),this.preTapPosition.x=this.x1,this.preTapPosition.y=this.y1,this.last=this.now;var n=this.preV;if(t.touches.length>1){this._cancelLongTap(),this._cancelSingleTap();var i={x:t.touches[1].clientX-this.x1,y:t.touches[1].clientY-this.y1};n.x=i.x,n.y=i.y,this.pinchStartLen=E(n),this._emitEvent("onMultipointStart",t)}this.longTapTimeout=setTimeout((function(){e._emitEvent("onLongTap",t)}),750)}}},{key:"handleMove",value:function(t){var e=this.preV,n=t.touches.length,i=t.touches[0].clientX,o=t.touches[0].clientY;if(this.isDoubleTap=!1,n>1){var r={x:t.touches[1].clientX-i,y:t.touches[1].clientY-o};if(null!==e.x){if(this.pinchStartLen>0){var a={x:(t.touches[1].clientX+i)/2,y:(t.touches[1].clientY+o)/2},s=E(r)/this.pinchStartLen;this._emitEvent("onPinch",t,{center:a,scale:s})}var h=function(t,e){var n=function(t,e){var n=E(t)*E(e);if(0===n)return 0;var i=function(t,e){return t.x*e.x+t.y*e.y}(t,e)/n;return i>1&&(i=1),Math.acos(i)}(t,e);return function(t,e){return t.x*e.y-e.x*t.y}(t,e)>0&&(n*=-1),180*n/Math.PI}(r,e);this._emitEvent("onRotate",t,{angle:h})}e.x=r.x,e.y=r.y,this.multiTouch=!0;var l={};null!==this.x2?(l.deltaX=i-this.x2,l.deltaY=o-this.y2):(l.deltaX=0,l.deltaY=0),this._emitEvent("onPressMove",t,l)}this._cancelLongTap(),this.x2=i,this.y2=o,n>1&&t.preventDefault()}},{key:"handleCancel",value:function(){clearInterval(this.singleTapTimeout),clearInterval(this.tapTimeout),clearInterval(this.longTapTimeout),clearInterval(this.swipeTimeout)}},{key:"handleEnd",value:function(t){var e=this;this.end=Date.now(),this._cancelLongTap(),t.touches.length<2&&this._emitEvent("onMultipointEnd",t);var n={};n.origin=[this.x1,this.y1],!1===this.multiTouch&&(this.x2&&Math.abs(this.x1-this.x2)>30||this.y2&&Math.abs(this.preV.y-this.y2)>30?(n.direction=this._swipeDirection(this.x1,this.x2,this.y1,this.y2),n.distance=Math.abs(this.x1-this.x2),this.swipeTimeout=setTimeout((function(){e._emitEvent("onSwipe",t,n)}),0)):this.tapTimeout=setTimeout((function(){e._emitEvent("onTap",t,n),e.isDoubleTap?(e._emitEvent("onDoubleTap",t,n),clearTimeout(e.singleTapTimeout),e.isDoubleTap=!1):e.singleTapTimeout=setTimeout((function(){e._emitEvent("onSingleTap",t,n)}),250)}),0)),this.preV.x=0,this.preV.y=0,this.scale=1,this.pinchStartLen=null,this.x1=this.x2=this.y1=this.y2=null,this.multiTouch=!1}},{key:"_cancelLongTap",value:function(){clearTimeout(this.longTapTimeout)}},{key:"_cancelSingleTap",value:function(){clearTimeout(this.singleTapTimeout)}},{key:"_swipeDirection",value:function(t,e,n,i){return Math.abs(t-e)>80||this.end-this.now<250?Math.abs(t-e)>=Math.abs(n-i)?t-e>0?"Left":"Right":n-i>0?"Up":"Down":"Nochange"}},{key:"destroy",value:function(){this.handleCancel(),this.element.removeEventListener("touchstart",this.handleStart),this.element.removeEventListener("touchmove",this.handleMove),this.element.removeEventListener("touchend",this.handleEnd),this.element.removeEventListener("touchcancel",this.handleCancel),this.preV.x=0,this.preV.y=0,this.scale=1,this.pinchStartLen=null,this.x1=this.x2=this.y1=this.y2=null,this.multiTouch=!1}}]),t}(),T=function(t,e,n,i,o,r,a,s,h,l,u,c,d,f,p,m){this.elements=window.Float32Array?new Float32Array(16):[];var y=this.elements;y[0]=void 0!==t?t:1,y[4]=e||0,y[8]=n||0,y[12]=i||0,y[1]=o||0,y[5]=void 0!==r?r:1,y[9]=a||0,y[13]=s||0,y[2]=h||0,y[6]=l||0,y[10]=void 0!==u?u:1,y[14]=c||0,y[3]=d||0,y[7]=f||0,y[11]=p||0,y[15]=void 0!==m?m:1};function k(t,e,n){for(var i=0,o=e.length;i<o;i++)S(t,e[i],n)}function S(t,e,n){Object.defineProperty(t,e,{get:function(){return this["__"+e]},set:function(t){t!==this["__"+e]&&(this["__"+e]=t,n())}})}T.DEG_TO_RAD=Math.PI/180,T.prototype={set:function(t,e,n,i,o,r,a,s,h,l,u,c,d,f,p,m){var y=this.elements;return y[0]=t,y[4]=e,y[8]=n,y[12]=i,y[1]=o,y[5]=r,y[9]=a,y[13]=s,y[2]=h,y[6]=l,y[10]=u,y[14]=c,y[3]=d,y[7]=f,y[11]=p,y[15]=m,this},identity:function(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this},multiplyMatrices:function(t,e){var n=t.elements,i=this.elements,o=n[0],r=n[4],a=n[8],s=n[12],h=n[1],l=n[5],u=n[9],c=n[13],d=n[2],f=n[6],p=n[10],m=n[14],y=n[3],v=n[7],g=n[11],w=n[15],b=e[0],x=e[1],E=e[2],O=e[3],T=e[4],k=e[5],S=e[6],_=e[7],M=e[8],P=e[9],L=e[10],D=e[11],j=e[12],R=e[13],C=e[14],I=e[15];return i[0]=o*b+r*T+a*M+s*j,i[4]=o*x+r*k+a*P+s*R,i[8]=o*E+r*S+a*L+s*C,i[12]=o*O+r*_+a*D+s*I,i[1]=h*b+l*T+u*M+c*j,i[5]=h*x+l*k+u*P+c*R,i[9]=h*E+l*S+u*L+c*C,i[13]=h*O+l*_+u*D+c*I,i[2]=d*b+f*T+p*M+m*j,i[6]=d*x+f*k+p*P+m*R,i[10]=d*E+f*S+p*L+m*C,i[14]=d*O+f*_+p*D+m*I,i[3]=y*b+v*T+g*M+w*j,i[7]=y*x+v*k+g*P+w*R,i[11]=y*E+v*S+g*L+w*C,i[15]=y*O+v*_+g*D+w*I,this},_rounded:function(t,e){return e=Math.pow(10,e||15),Math.round(t*e)/e},appendTransform:function(t,e,n,i,o,r,a,s,h,l,u,c,d,f){var p=a*T.DEG_TO_RAD,m=this._rounded(Math.cos(p)),y=this._rounded(Math.sin(p)),v=s*T.DEG_TO_RAD,g=this._rounded(Math.cos(v)),w=this._rounded(Math.sin(v)),b=h*T.DEG_TO_RAD,x=this._rounded(Math.cos(-1*b)),E=this._rounded(Math.sin(-1*b));return this.multiplyMatrices(this,[1,0,0,t,0,m,y,e,0,-y,m,n,0,0,0,1]),this.multiplyMatrices(this,[g,0,w,0,0,1,0,0,-w,0,g,0,0,0,0,1]),this.multiplyMatrices(this,[x*i,E*o,0,0,-E*i,x*o,0,0,0,0,1*r,0,0,0,0,1]),(l||u)&&this.multiplyMatrices(this,[this._rounded(Math.cos(l*T.DEG_TO_RAD)),this._rounded(Math.sin(l*T.DEG_TO_RAD)),0,0,-1*this._rounded(Math.sin(u*T.DEG_TO_RAD)),this._rounded(Math.cos(u*T.DEG_TO_RAD)),0,0,0,0,1,0,0,0,0,1]),(c||d||f)&&(this.elements[12]-=c*this.elements[0]+d*this.elements[4]+f*this.elements[8],this.elements[13]-=c*this.elements[1]+d*this.elements[5]+f*this.elements[9],this.elements[14]-=c*this.elements[2]+d*this.elements[6]+f*this.elements[10]),this}};var _=function(t){k(t,["translateX","translateY","translateZ","scaleX","scaleY","scaleZ","rotateX","rotateY","rotateZ","skewX","skewY","originX","originY","originZ"],(function(){var e=t.matrix3D.identity().appendTransform(t.translateX,t.translateY,t.translateZ,t.scaleX,t.scaleY,t.scaleZ,t.rotateX,t.rotateY,t.rotateZ,t.skewX,t.skewY,t.originX,t.originY,t.originZ);t.style.transform=t.style.msTransform=t.style.OTransform=t.style.MozTransform=t.style.webkitTransform="perspective("+t.perspective+"px) matrix3d("+Array.prototype.slice.call(e.elements).join(",")+")"})),k(t,["perspective"],(function(){t.style.transform=t.style.msTransform=t.style.OTransform=t.style.MozTransform=t.style.webkitTransform="perspective("+t.perspective+"px) matrix3d("+Array.prototype.slice.call(t.matrix3D.elements).join(",")+")"})),t.matrix3D=new T,t.perspective=500,t.scaleX=t.scaleY=t.scaleZ=1,t.translateX=t.translateY=t.translateZ=t.rotateX=t.rotateY=t.rotateZ=t.skewX=t.skewY=t.originX=t.originY=t.originZ=0};function M(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function P(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?M(Object(n),!0).forEach((function(e){var i,r,a;i=t,r=e,a=n[e],(r=o(r))in i?Object.defineProperty(i,r,{value:a,enumerable:!0,configurable:!0,writable:!0}):i[r]=a})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):M(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function L(){}var D=function(){function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,n),this.options=P(P({},n.defaultOptions),t),this.initScale=1,this.screenWidth=window.innerWidth||window.screen.availWidth,this.screenHeight=window.innerHeight||window.screen.availHeight,this.init()}var i,o;return s(n,[{key:"init",value:(i=l().mark((function t(){var n,i,o,r,a,s,h,u,d,f,p,m,y,w,E,T,k,S,M,P,L,D,j,R,C,I,W;return l().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=this.options,i=n.root,o=n.url,r=n.scaleable,a=n.maxScale,s=n.center,h=n.resizeRatio,u=n.lineWidth,d=n.color,f=n.openSmooth,p=n.rotate,m=n.minWidth,y=n.minSpeed,w=n.maxWidth,E=n.maxWidthDiffRate,T=n.maxHistoryLength,k=n.undoRedoStateChange,S=n.onDrawStart,M=n.onDrawing,P=n.onDrawUp,L=this.options.scaleRatio,i&&i instanceof Element){t.next=4;break}throw new Error("Invalid root element.");case 4:return this.element=document.createElement("div"),i.appendChild(this.element),t.next=8,void 0,function(t){return"string"===e(t)?b:t instanceof Image?g:x}(l=o)(l);case 8:D=t.sent,this.imgWidth=D.width*h,this.imgHeight=D.height*h,w&&(L=this.imgWidth/w),j=this.imgWidth/L,R=this.imgHeight/L,C=Math.min(j,w),I=Math.min(R,C/j*R),this.element.style.position="relative",this.element.style.width=C+"px",this.element.style.height=I+"px",this.imageBackdrop=new v({root:this.element,scaleRatio:L,width:j,height:R,maxWidth:w}),this.imageBackdrop.init(),this.imageBackdrop.drawImage(D),this.drawInstance=new(c())({root:this.element,scaleRatio:L,width:j,height:R,openSmooth:f,lineWidth:u,color:d,rotate:p,minWidth:m,minSpeed:y,maxWidth:w,maxWidthDiffRate:E,maxHistoryLength:T,undoRedoStateChange:k,onDrawStart:S,onDrawing:M,onDrawUp:P}),(W=this.drawInstance.drawElement).style.position="absolute",W.style.left="0",W.style.top="0",r&&(_(this.element),this.finger=new O(this.element,{context:this,maxScale:a,onMultipointStart:function(){this.initScale=this.element.scaleX},onPinch:function(t,e){this.element.style.webkitTransition="cubic-bezier(.25,.01,.25,1)";var n=this.element,i=n.originX,o=n.originY,r=e.center.x-this.screenWidth/2-document.body.scrollLeft,a=e.center.y-this.screenHeight/2-document.body.scrollTop;this.element.originX=r,this.element.originY=a,this.element.translateX=this.element.translateX+(r-i)*this.element.scaleX,this.element.translateY=this.element.translateY+(a-o)*this.element.scaleY,this.element.scaleX=this.element.scaleY=this.initScale*e.scale},onMultipointEnd:function(){this.element.style.webkitTransition="300ms ease";var t=this.options.maxScale;this.element.scaleX<1&&this.restore(!1),this.element.scaleX>t&&this.setScale(t)},onPressMove:function(t,e){this.endAnimation(),this.element.translateX+=e.deltaX,this.element.translateY+=e.deltaY,t.preventDefault()}})),s&&this.setCenter();case 29:case"end":return t.stop()}var l}),t,this)})),o=function(){var e=this,n=arguments;return new Promise((function(o,r){var a=i.apply(e,n);function s(e){t(a,o,r,s,h,"next",e)}function h(e){t(a,o,r,s,h,"throw",e)}s(void 0)}))},function(){return o.apply(this,arguments)})},{key:"setCenter",value:function(){var t=this.options,e=t.root;t.scaleable?(this.element.translateX=(e.clientWidth-this.element.clientWidth)/2,this.element.translateY=(e.clientHeight-this.element.clientHeight)/2):(this.element.style.marginLeft=(e.clientWidth-this.element.clientWidth)/2+"px",this.element.style.marginTop=(e.clientHeight-this.element.clientHeight)/2+"px")}},{key:"setScale",value:function(t){this.element.style.transition="300ms ease-in-out",this.element.style.webkitTransition="300ms ease-in-out",this.element.scaleX=this.element.scaleY=t}},{key:"restore",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.options.center?this.setCenter():this.element.translateX=this.element.translateY=0,t&&(this.element.rotateZ=0),this.element.scaleX=this.element.scaleY=1,this.element.originX=this.element.originY=0}},{key:"endAnimation",value:function(){this.element.style.transition="0",this.element.style.webkitTransition="0"}},{key:"clear",value:function(){var t;null===(t=this.drawInstance)||void 0===t||t.clear()}},{key:"setLineWidth",value:function(t){var e;null===(e=this.drawInstance)||void 0===e||e.setLineWidth(t)}},{key:"setColor",value:function(t){var e;null===(e=this.drawInstance)||void 0===e||e.setColor(t)}},{key:"setOptions",value:function(t){var e;null===(e=this.drawInstance)||void 0===e||e.setOptions(t)}},{key:"undo",value:function(){var t;null===(t=this.drawInstance)||void 0===t||t.undo()}},{key:"redo",value:function(){var t;null===(t=this.drawInstance)||void 0===t||t.redo()}},{key:"canUndo",value:function(){var t;return null===(t=this.drawInstance)||void 0===t?void 0:t.canUndo()}},{key:"canRedo",value:function(){var t;return null===(t=this.drawInstance)||void 0===t?void 0:t.canRedo()}},{key:"isEmpty",value:function(){var t;return null===(t=this.drawInstance)||void 0===t?void 0:t.isEmpty()}},{key:"destroy",value:function(){var t,e,n;null===(t=this.drawInstance)||void 0===t||t.destroy(),null===(e=this.imageBackdrop)||void 0===e||e.destroy(),null===(n=this.finger)||void 0===n||n.destroy();try{(this.element.parentElement||document.body).removeChild(this.element),this.element=null}catch(t){}}},{key:"getResult",value:function(){try{if(!this.drawInstance||!this.imageBackdrop)return;var t=document.createElement("canvas"),e=t.getContext("2d");return t.width=this.imgWidth,t.height=this.imgHeight,e.drawImage(this.imageBackdrop.drawElement,0,0,this.imgWidth,this.imgHeight),e.drawImage(this.drawInstance.drawElement,0,0,this.imgWidth,this.imgHeight),t}catch(t){console.error(t)}}}]),n}();D.defaultOptions={root:null,openSmooth:!1,center:!0,scaleRatio:window.devicePixelRatio||1,resizeRatio:1/(window.devicePixelRatio||1),scaleable:!0,maxScale:5,maxWidth:window.innerWidth,onDrawStart:L,onDrawing:L,onDrawUp:L};var j=D}(),i}()}));