text: !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Pictool",e):(t=t||self).Pictool=e()}(this,function(){"use strict";function c(n){var o=document.createElement("img");return new Promise(function(t,e){o.onload=function(){t(o)},o.onerror=function(){e(new Error("GET_IMAGE_SRC_ERROR"))},o.src=n})}function s(t){return new Promise(function(r,s){c(t).then(function(t){var e=document.createElement("canvas"),n=t.width,o=t.height;e.width=n,e.height=o;var a=e.getContext("2d");if(a){a.clearRect(0,0,e.width,e.height),a.drawImage(t,0,0,n,o);var i=a.getImageData(0,0,n,o);r(i)}else s(new Error("canvas.getContext('2d') is null"))}).catch(function(t){s(t)})})}var S,t;(t=S=S||{}).png="image/png",t.jpg="image/webp",t.jpeg="image/jpeg";function l(t,e){void 0===e&&(e={type:S.png,encoderOptions:1});var n=e.type,o=e.encoderOptions,a=t.width,i=t.height,r=a,s=i,c=a*i,l=Math.ceil(Math.sqrt(Math.ceil(c/4e6)));1<l?(r=a/l,s=i/l):l=1;var h=document.createElement("canvas"),d=document.createElement("canvas"),p=h.getContext("2d");if(!p)return null;h.width=r,h.height=s,p.fillStyle="#FFFFFF",p.fillRect(0,0,h.width,h.height);var u=Math.ceil(c/1e6);if(1<u){var g=Math.ceil(h.width/u),f=Math.ceil(h.height/u);d.width=g,d.height=f;var v=d.getContext("2d");if(!v)return null;for(var m=g*l,_=f*l,b=g,w=f,y=0;y<u;y++)for(var k=0;k<u;k++){var E=y*g*l,x=k*f*l;v.drawImage(t,E,x,m,_,0,0,b,w),p.drawImage(d,y*g,k*f,b,w)}v.clearRect(0,0,d.width,d.height),d.width=0,d.height=0,d=null}else p.drawImage(t,0,0,r,s);var D=h.toDataURL(n,o);return p.clearRect(0,0,h.width,h.height),h.width=0,h.height=0,h=null,D}var m=(e.prototype.getWidth=function(){return null!==this._width?this._width:0},e.prototype.getHeight=function(){return null!==this._height?this._height:0},e.prototype.getData=function(){return null!==this._data?this._data:this._nullData},e.prototype.setDataUnit=function(t,e){this._data instanceof Uint8ClampedArray&&(this._data[t]=e)},e.prototype.pixelAt=function(t,e){var n=this.getWidth(),o=this.getData(),a=4*(n*e+t);return{r:o[a],g:o[1+a],b:o[2+a],a:o[3+a]}},e.prototype.destory=function(){this._data=null,this._width=null,this._height=null},e);function e(t){this._nullData=new Uint8ClampedArray(0);var e=t.width,n=t.height,o=t.data,a=e*n*4;o instanceof Uint8ClampedArray&&o.length===a?this._data=new Uint8ClampedArray(o):o instanceof Array&&o.length===a?this._data=new Uint8ClampedArray(o):this._data=new Uint8ClampedArray(a),this._width=e,this._height=n}function n(t){var e=t.getData(),n=t.getWidth(),o=t.getHeight(),a=new ImageData(n,o);return e.forEach(function(t,e){a.data[e]=t}),a}function h(t){var e=t.data,n=t.width,o=t.height;return new m({width:n,height:o,data:e})}function r(t,e){void 0===e&&(e={type:"image/png",encoderOptions:1});var n=document.createElement("canvas"),o=n.getContext("2d");n.width=t.width,n.height=t.height;var a=null;return o&&(o.clearRect(0,0,n.width,n.height),o.putImageData(t,0,0),a=n.toDataURL(e.type,e.encoderOptions)),a}function g(t){for(var e=t.getWidth(),n=t.getHeight(),o=t.getData(),a=new m({width:e,height:n,data:o}),i=0;i<e;i++)for(var r=0;r<n;r++){var s=4*(e*r+i),c=a.pixelAt(i,r),l=Math.round((c.r+c.g+c.b)/3);a.setDataUnit(s,l),a.setDataUnit(1+s,l),a.setDataUnit(2+s,l),a.setDataUnit(3+s,255)}return a}function f(t,e,n){var o=t.getWidth(),a=t.getData()[4*(o*n+e)];return 0<=a&&a<255||(a=0),a}var _=255,o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function v(t){var e=t.h/360,n=t.s/100,o=t.l/100,a=0,i=0,r=0;if(0==n)r=i=a=function(t){var e=t*_;return e=Math.round(e),e=Math.max(0,e),e=Math.min(255,e)}(o);else{var s=[],c=.5<=o?o+n-o*n:o*(1+n),l=2*o-c;s[0]=e+1/3,s[1]=e,s[2]=e-1/3;for(var h=0;h<s.length;h++){var d=s[h];switch(d<0?d+=1:1<d&&(d-=1),!0){case d<1/6:d=l+6*(c-l)*d;break;case 1/6<=d&&d<.5:d=c;break;case.5<=d&&d<2/3:d=l+(c-l)*(4-6*d);break;default:d=l}s[h]=Math.round(d*_)}a=s[0],i=s[1],r=s[2]}return{r:a,g:i,b:r}}function b(t){return 100*t/_}var w=function(){return(w=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t}).apply(this,arguments)};function y(t){return-100<=t&&t<=100}function k(t,e){var n=t.r,o=t.g,a=t.b,i=b(n),r=b(o),s=b(a),c=Math.min(i,r,s),l=Math.max(i,r,s),h=l-c,d=0,p=0,u=(l+c)/2;if(l===c?p=d=0:(l===i&&s<=r?d=(r-s)/h*60+0:l===i&&r<s?d=(r-s)/h*60+360:l===r?d=(s-i)/h*60+120:l===s&&(d=(i-r)/h*60+240),0===u||l===c?p=0:0<u&&u<=127.5?p=h/(l+c):127.5<u&&(p=h/(510-(l+c)))),d=Math.round(d),p=Math.round(100*p),u=Math.round(u),e&&e.value){var g=e.value;g.h&&function(t){return 0<=t&&t<=360}(g.h)&&(d=g.h,d=Math.min(360,d),d=Math.max(0,d)),g.s&&function(t){return 0<=t&&t<=100}(g.s)&&(p=g.s,p=Math.min(100,p),p=Math.max(0,p)),g.l&&function(t){return 0<=t&&t<=100}(g.l)&&(u=g.l,u=Math.min(100,u),u=Math.max(0,u))}else if(e&&e.percent){var f=e.percent;f.h&&y(f.h)&&(d=Math.floor(d*(100+f.h)/100),d=Math.min(360,d),d=Math.max(0,d)),f.s&&y(f.s)&&(p=Math.floor(p*(100+f.s)/100),p=Math.min(100,p),p=Math.max(0,p)),f.l&&y(f.l)&&(u=Math.floor(u*(100+f.l)/100),u=Math.min(100,u),u=Math.max(0,u))}return{h:d,s:p,l:u}}function d(t,e){for(var n=t.getWidth(),o=t.getHeight(),a=t.getData(),i=new m({width:n,height:o,data:a}),r=0;r<a.length;r+=4){var s=a[r],c=a[r+1],l=a[r+2],h=a[r+3],d=k({r:s,g:c,b:l},e),p=w({},d),u=v(p);i.setDataUnit(r,u.r),i.setDataUnit(r+1,u.g),i.setDataUnit(r+2,u.b),i.setDataUnit(r+3,h)}return t.destory(),i}var a={HSL2RGB:v,RGB2HSL:k};var i={grayscale:g,sobel:function(t){for(var e=t.getWidth(),n=t.getHeight(),o=new Uint8ClampedArray(e*n*4),a=new m({width:e,height:n,data:o}),i=[[-1,0,1],[-2,0,2],[-1,0,1]],r=[[-1,-2,-1],[0,0,0],[1,2,1]],s=g(t),c=0;c<e;c++)for(var l=0;l<n;l++){var h=i[0][0]*f(s,c-1,l-1)+i[0][1]*f(s,c,l-1)+i[0][2]*f(s,c+1,l-1)+i[1][0]*f(s,c-1,l)+i[1][1]*f(s,c,l)+i[1][2]*f(s,c+1,l)+i[2][0]*f(s,c-1,l+1)+i[2][1]*f(s,c,l+1)+i[2][2]*f(s,c+1,l+1),d=r[0][0]*f(s,c-1,l-1)+r[0][1]*f(s,c,l-1)+r[0][2]*f(s,c+1,l-1)+r[1][0]*f(s,c-1,l)+r[1][1]*f(s,c,l)+r[1][2]*f(s,c+1,l)+r[2][0]*f(s,c-1,l+1)+r[2][1]*f(s,c,l+1)+r[2][2]*f(s,c+1,l+1),p=Math.round(Math.sqrt(h*h+d*d)),u=4*(e*l+c);a.setDataUnit(u,p),a.setDataUnit(1+u,p),a.setDataUnit(2+u,p),a.setDataUnit(3+u,255)}return s.destory(),s=null,a},invert:function(t){for(var e=t.getWidth(),n=t.getHeight(),o=t.getData(),a=new m({width:e,height:n,data:o}),i=0;i<e;i++)for(var r=0;r<n;r++){var s=4*(e*r+i),c=a.pixelAt(i,r);a.setDataUnit(s,_-c.r),a.setDataUnit(1+s,_-c.g),a.setDataUnit(2+s,_-c.b),a.setDataUnit(3+s,c.a)}return a},hue:function(t,e){var n=t.getWidth(),o=t.getHeight(),a=t.getData(),i=new m({width:n,height:o,data:a}),r=void 0,s=void 0;return e.value?s={h:e.value}:e.percent&&(r={h:e.percent}),i=d(i,{percent:r,value:s})},saturation:function(t,e){var n=t.getWidth(),o=t.getHeight(),a=t.getData(),i=new m({width:n,height:o,data:a}),r=void 0,s=void 0;return e.value?s={s:e.value}:e.percent&&(r={s:e.percent}),i=d(i,{percent:r,value:s})},lightness:function(t,e){var n=t.getWidth(),o=t.getHeight(),a=t.getData(),i=new m({width:n,height:o,data:a}),r=void 0,s=void 0;return e.value?s={l:e.value}:e.percent&&(r={l:e.percent}),i=d(i,{percent:r,value:s})},alpha:function(t,e){var n=t.getWidth(),o=t.getHeight(),a=t.getData(),i=new m({width:n,height:o,data:a}),r=e.percent,s=e.value;if(r&&function(t){return-100<=t&&t<=100}(r)?(r=Math.min(100,r),r=Math.max(-100,r)):s&&function(t){return 0<=t&&t<=100}(s)&&(s=Math.min(100,s),s=Math.max(0,s)),s||0===s)for(var c=0;c<a.length;c+=4){var l=a[c],h=a[c+1],d=a[c+2],p=a[c+3];p=Math.floor(s*_/100),p=Math.min(_,p),p=Math.max(0,p),i.setDataUnit(c,l),i.setDataUnit(c+1,h),i.setDataUnit(c+2,d),i.setDataUnit(c+3,p)}else if(r||0===r)for(c=0;c<a.length;c+=4){l=a[c],h=a[c+1],d=a[c+2],p=a[c+3];p=Math.floor(p*(100+r)/100),p=Math.min(_,p),p=Math.max(0,p),i.setDataUnit(c,l),i.setDataUnit(c+1,h),i.setDataUnit(c+2,d),i.setDataUnit(c+3,p)}else for(c=0;c<a.length;c+=4){l=a[c],h=a[c+1],d=a[c+2],p=a[c+3];i.setDataUnit(c,l),i.setDataUnit(c+1,h),i.setDataUnit(c+2,d),i.setDataUnit(c+3,p)}return i},sepia:function(t){for(var e=t.getWidth(),n=t.getHeight(),o=t.getData(),a=new m({width:e,height:n,data:o}),i=0;i<e;i++)for(var r=0;r<n;r++){var s=4*(e*r+i),c=a.pixelAt(i,r),l=Math.floor(.393*c.r+.769*c.g+.189*c.b),h=Math.floor(.349*c.r+.686*c.g+.168*c.b),d=Math.floor(.272*c.r+.534*c.g+.131*c.b),p=c.a;a.setDataUnit(s,l),a.setDataUnit(1+s,h),a.setDataUnit(2+s,d),a.setDataUnit(3+s,p)}return a},posterize:function(t,e){void 0===e&&(e={});var n=t.getWidth(),o=t.getHeight(),a=t.getData(),i=new m({width:n,height:o,data:a}),r=e.value||100;r&&function(t){return 0<=t&&t<=100}(r)&&(r=Math.min(100,r),r=Math.max(0,r));for(var s=_/r,c=s,l=0;l<n;l++)for(var h=0;h<o;h++){var d=4*(n*h+l),p=i.pixelAt(l,h),u=Math.floor(Math.floor(p.r/s)*c),g=Math.floor(Math.floor(p.g/s)*c),f=Math.floor(Math.floor(p.b/s)*c),v=p.a;i.setDataUnit(d,u),i.setDataUnit(1+d,g),i.setDataUnit(2+d,f),i.setDataUnit(3+d,v)}return i},gamma:function(t,e){void 0===e&&(e={});var n=t.getWidth(),o=t.getHeight(),a=t.getData(),i=new m({width:n,height:o,data:a}),r=e.value||16;r&&function(t){return 0<=t&&t<=100}(r)&&(r=Math.min(100,r),r=Math.max(0,r));for(var s=(r+100)/200*2,c=0;c<n;c++)for(var l=0;l<o;l++){var h=4*(n*l+c),d=i.pixelAt(c,l),p=Math.floor(Math.pow(d.r,s)),u=Math.floor(Math.pow(d.g,s)),g=Math.floor(Math.pow(d.b,s)),f=d.a;i.setDataUnit(h,p),i.setDataUnit(1+h,u),i.setDataUnit(2+h,g),i.setDataUnit(3+h,f)}return i}},p=(u.prototype.process=function(t,e){if(i&&"function"!=typeof i[t])throw new Error("Pictool.digit.process."+t+" is not a function ");return this._digitImageData=i[t](this._digitImageData,e),this},u.prototype.getImageData=function(){return this._digitImageData?n(this._digitImageData):null},u.prototype.getDigitImageData=function(){return this._digitImageData},u.prototype.destory=function(){this._digitImageData&&(this._digitImageData.destory(),this._digitImageData=null)},u);function u(t){this._digitImageData=null,this._digitImageData=t}var E=(x.prototype.queueProcess=function(t){var a=this,i=[];return Array.isArray(t)?t.forEach(function(t){i.push(t)}):i.push(t),new Promise(function(n,e){a._getEffectAsync().then(function(o){i.forEach(function(t){var e=t.process,n=t.options;a._digitImg=o.process(e,n).getDigitImageData()});var t=o.getImageData(),e=r(t);n(e)}).catch(function(t){e(t)})})},x.prototype._getEffectAsync=function(){var i=this;return this._effect instanceof p?Promise.resolve(this._effect):new Promise(function(o,a){i._parseDigitAsync().then(function(t){if(!0===t){var e=i._digitImg;if(e instanceof m){var n=new p(e);i._effect=n,o(i._effect)}else a(new Error("_digitImg is null"))}else a(new Error("image src parse fail"))}).catch(function(t){a(t)})})},x.prototype._parseDigitAsync=function(){var a=this;if(this._digitImg)return Promise.resolve(!0);var t=this._options,e=1;t&&(e=t.compressRatio);var i=this._imgSrc,n=Math.max(.1,e);n=Math.min(1,e);var r={type:S.jpg,encoderOptions:n};return new Promise(function(n,o){c(i).then(function(t){var e=l(t,r);"string"==typeof e?s(e).then(function(t){var e=h(t);a._digitImg=e,n(!0)}).catch(function(t){o(t)}):o(new Error("compressImage result is null"))}).catch(function(t){o(t)})})},x);function x(t,e){this._digitImg=null,this._effect=null,this._imgSrc=t,this._options=e}var D={util:{getImageBySrc:c,getImageDataBySrc:s,compressImage:l,imageData2Base64:r,digitImageData2ImageData:n,imageData2DigitImageData:h},Sandbox:E};function C(t,e){void 0===e&&(e={});var n=e.insertAt;if(t&&"undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css","top"===n&&o.firstChild?o.insertBefore(a,o.firstChild):o.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t))}}C(".pictool-component-mask{display:none;background:rgba(0,0,0,.48);position:fixed;left:0;right:0;top:0;bottom:0}.pictool-component-mask .pictool-mask-container{position:absolute;left:0;right:0;bottom:-100%;height:100%;width:100%;background:#fff;transition:.6s}.pictool-component-mask.mask-open{display:block}.pictool-component-mask.mask-open .pictool-mask-container{bottom:0}.pictool-component-mask .pictool-mask-header{position:absolute;top:0;width:100%;height:40px;background:#222}.pictool-component-mask .pictool-mask-content{position:absolute;top:40px;bottom:120px;width:100%;background:#333}.pictool-component-mask .pictool-mask-footer{position:absolute;bottom:0;width:100%;height:120px;background:#222}");var M=(I.prototype.show=function(){this._component.classList.add("mask-open")},I.prototype.hide=function(){this._component.classList.remove("mask-open")},I.prototype._render=function(){if(!0!==this._hasRendered){var t=this._options,e=t.zIndex,n=t.afterRender,o='\n    <div class="pictool-component-mask" style="z-index: '+e+'">\n      <div class="pictool-mask-container">\n        <div class="pictool-mask-header"></div>\n        <div class="pictool-mask-content"></div>\n        <div class="pictool-mask-footer"></div>\n      </div>\n    </div>\n    ',a=document.querySelector("body"),i=document.createElement("div");i.innerHTML=o;var r=i.querySelector("div.pictool-component-mask");a.appendChild(r);var s=r.querySelector("div.pictool-mask-content"),c=r.querySelector("div.pictool-mask-header"),l=r.querySelector("div.pictool-mask-footer");"function"==typeof n&&n({contentMount:s,headerMount:c,footerMount:l}),this._hasRendered=!0,this._component=r}},I);function I(t){this._hasRendered=!1,this._component=null,this._options=t,this._render()}C(".pictool-module-sketch{width:100%;height:100%;display:table}.pictool-module-sketch .pictool-sketch-container{width:100%;height:100%;display:table-row}.pictool-module-sketch .pictool-sketch-main{width:100%;height:100%;display:table-cell;vertical-align:middle;text-align:center;user-select:none;background-position:0 0,10px 10px;background-size:20px 20px;background-image:linear-gradient(45deg,#eee 25%,transparent 0,transparent 75%,#eee 0,#eee),linear-gradient(45deg,#eee 25%,#fff 0,#fff 75%,#eee 0,#eee)}.pictool-module-sketch .pictool-sketch-main .pictool-sketch-canvas{max-height:100%;max-width:100%}.pictool-module-sketch .pictool-sketch-hidden-area{width:0;height:0;display:none}");var L=function(t,e){var n=t.getContext("2d");t.width=e.width,t.height=e.height,n.clearRect(0,0,t.width,t.height),n.putImageData(e,0,0)};function A(t){return(Object.prototype.toString.call(t)||"").replace(/(\[object|\])/gi,"").trim()}var R=function(t,e){var n=A(t);return!0===e?n.toLocaleLowerCase():n},z=function(t){return"Array"===A(t)},U=function(t){return"Object"===A(t)},T=function(t){return"Function"===A(t)},O=function(t){return"Null"===A(t)},P=function(t){return"Promise"===A(t)},H=function(t){return"NodeList"===A(t)},F={fillStyle:{type:"attribute",argumentsType:"string",executeAction:function(t,e){t.fillStyle=e}},fillRect:{type:"function",argumentsType:"array",executeAction:function(t,e){t.fillRect(e[0],e[1],e[2],e[3])}},clearRect:{type:"function",argumentsType:"array",executeAction:function(t,e){t.clearRect(e[0],e[1],e[2],e[3])}},putImageData:{type:"function",argumentsType:"array",executeAction:function(t,e){t.putImageData(e[0],e[1],e[2])}}},G=(N.prototype.getLayerContext=function(){return this._context},N.prototype.clearDrawAction=function(){var t=this._options,e=t.width,n=t.height;this._context.clearRect(0,0,e,n),this._layerSchema={key:"",drawActionList:[]}},N.prototype._executeDrawAction=function(){for(var t,e,n,o,a=this._layerSchema.drawActionList,i=this._context,r=0;r<a.length;r++){var s=a[r];t=i,e=s.method,n=s.args,o=void 0,(o=F[e])&&R(n,!0)===o.argumentsType?o.executeAction(t,n):console.warn("Layer can't support execute context."+e)}},N.prototype.draw=function(t){this._layerSchema=t,this._executeDrawAction()},N.prototype.getSchema=function(){return this._layerSchema},N);function N(t,e){this._context=t,this._options=e}var q=(j.prototype._initSketch=function(){var t=this._width,e=this._height;this._tempCanvas=document.createElement("canvas"),this._tempCanvas.width=t,this._tempCanvas.height=e;for(var n=this._layerCount,o=0;o<n;o++){var a=document.createElement("canvas");a.width=t,a.height=e;var i=a.getContext("2d"),r=new G(i,{width:t,height:e});this._layerStack.push(r),this._canvasStack.push(a)}},j.prototype.getCanvasStack=function(){return this._canvasStack},j.prototype.getLayerStack=function(){return this._layerStack},j.prototype.drawLayer=function(t,e){var n=this._layerStack[t];n.clearDrawAction(),n.draw(e)},j.prototype.drawAllLayer=function(t){var n=this;t.layerList.forEach(function(t,e){n.drawLayer(e,t)})},j.prototype.getSchema=function(){var n=[];return this._layerStack.forEach(function(t){var e=t.getSchema();n.push(e)}),{layerList:n}},j.prototype.mergeLayer=function(){var t=this._tempCanvas,e=this._width,n=this._height,o=t.getContext("2d");o.clearRect(0,0,e,n),this._canvasStack.forEach(function(t){o.drawImage(t,0,0)});var a=o.getImageData(0,0,e,n);return o.clearRect(0,0,e,n),a},j.prototype.moveUpLayer=function(t){},j.prototype.moveDownLayer=function(t){},j);function j(t){this._canvasStack=[],this._layerStack=[],this._tempCanvas=null,this._width=t.width,this._height=t.height,this._layerCount=t.layerCount,this._initSketch()}function V(n){var o=[];return Object.keys(n).forEach(function(t){if("string"==typeof t){var e=n[t]||"";"string"==typeof e&&o.push(t+":"+e)}}),o.join(";")}var W,J,B,X=(o(W=Z,J=B=q),void(W.prototype=null===J?Object.create(J):(Y.prototype=J.prototype,new Y)),Z.prototype.render=function(t){this._sketchSchema=t;for(var e=this._container;e.firstChild;)e.removeChild(e.firstChild);var n=this._options,o=n.width,a=n.height,i=n.layerCount,r=V({width:o+"px",height:a+"px",position:"relative",display:"inline-block"}),s=this.getCanvasStack();e.setAttribute("style",r);for(var c=i,l=0;l<c;l++){var h=s[l];h.width=o,h.height=a,h.setAttribute("style",V({width:o+"px",height:a+"px",position:"absolute",left:"0",top:"0"})),e.appendChild(h)}this.drawAllLayer(t)},Z.prototype.renderLayer=function(t,e){this.drawLayer(t,e)},Z.prototype.downloadImage=function(t){void 0===t&&(t="download-image");var e=this._options,n=e.width,o=e.height,a=document.createElement("canvas");a.width=n,a.height=o;var i=a.getContext("2d"),r=this.mergeLayer();i.putImageData(r,0,0);var s=a.toDataURL("image/png"),c=document.createElement("a");c.href=s,c.download=t;var l=document.createEvent("MouseEvents");l.initEvent("click",!0,!1),c.dispatchEvent(l),i.clearRect(0,0,n,o),a=null},Z);function Y(){this.constructor=W}function Z(t){var e=B.call(this,{width:t.width,height:t.height,layerCount:t.layerCount})||this;return e._options=t,e._container=t.container,e}function K(){this._listeners=new Map}var Q=new(K.prototype.on=function(t,e){this._listeners.set(t,e)},K.prototype.remove=function(t){this._listeners.delete(t)},K.prototype.trigger=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var o=this._listeners.get(t);return!!T(o)&&(o.apply(void 0,e),!0)},K),$=new Map,tt=function(t,e){$.set(t,e)},et=function(t){return $.get(t)},nt=function(t){return t.layerList[0].drawActionList[0].args[0]},ot=function(t){return{layerList:[{key:"image",drawActionList:[{method:"putImageData",args:[t,0,0]}]}]}},at=(it.prototype.renderImage=function(t){var e=this._sketchpad;e.render(t);var n=e.mergeLayer(),o=this._mount.querySelector("canvas.pictool-sketch-canvas");L(o,n),tt("Sketch.sketchSchema",t)},it.prototype._render=function(){!0!==this._hasRendered&&(this._mount.innerHTML='\n      <div class="pictool-module-sketch">\n        <div class="pictool-sketch-container">\n          <div class="pictool-sketch-main">\n            <div class="pictool-sketch-entity">\n              <canvas class="pictool-sketch-canvas"></canvas>\n            </div>\n          </div>\n        </div>\n        <div class="pictool-sketch-hidden-area">\n          <div class="pictool-sketch-hidden-area-sketchpad"></div>\n        </div>\n      </div>\n    ',this._registerEvent(),this._hasRendered=!0)},it.prototype._registerEvent=function(){if(!0!==this._hasRendered){var t=this;Q.on("GlobalEvent.moduleSketch.resizeCanvas",function(){t._resizeSketch()})}},it.prototype._resizeSketch=function(){var t=this._mount.querySelector(".pictool-sketch-container"),e=t.querySelector(".pictool-sketch-canvas"),n=t.clientHeight,o=t.clientWidth,a=Math.min(n,o);e.setAttribute("style","max-height: "+a+"px; max-width: "+a+"px; ")},it);function it(t,e){this._mount=null,this._opts=null,this._hasRendered=!1,this._sketchpad=null;var n=this;this._mount=t,this._opts=e,this._render();var o=this._opts.imageData,a=this._mount.querySelector("div.pictool-sketch-hidden-area-sketchpad"),i=o.height,r=o.width,s=new X({height:i,width:r,layerCount:2,container:a});this._sketchpad=s;var c=ot(o);tt("Sketch.originSketchSchema",c),Q.on("GlobalEvent.moduleSketch.renderImage",function(t){n.renderImage(t)}),Q.on("GlobalEvent.moduleSketch.downloadImage",function(){s.downloadImage("download-pictool.png")})}C(".pictool-module-dashboard{height:100%;width:100%;position:relative;font-size:14px;color:#333}.pictool-module-dashboard .pictool-dashboard-navlist{position:absolute;height:80px;display:flex;background:#fff;width:100%;bottom:0}.pictool-module-dashboard .pictool-dashboard-nav-btn{flex:1;text-align:center;font-size:14px;padding-top:40px;position:relative}.pictool-module-dashboard .pictool-dashboard-nav-btn.dashboard-process:before{content:\"\";position:absolute;top:0;left:0;right:0;height:40px;background:url(\"data:image/svg+xml;charset=utf-8,%3Csvg class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cdefs%3E%3Cstyle/%3E%3C/defs%3E%3Cpath d='M512 472a40 40 0 1080 0 40 40 0 10-80 0z' fill='%23666'/%3E%3Cpath d='M879 824.9L696.3 352V178H768v-68H256v68h71.7v174L145 824.9c-2.8 7.4-4.3 15.2-4.3 23.1 0 35.3 28.7 64 64 64h614.6c7.9 0 15.7-1.5 23.1-4.3 33-12.7 49.4-49.8 36.6-82.8zM395.7 364.7V180h232.6v184.7L719.2 600c-20.7-5.3-42.1-8-63.9-8-61.2 0-119.2 21.5-165.3 60-33.9 28.2-76.3 43.9-121.3 43.9-32.7 0-64.1-8.3-91.8-23.7l118.8-307.5zM210.5 844l41.7-107.8c35.7 18.1 75.4 27.8 116.6 27.8 61.2 0 119.2-21.5 165.3-60 33.9-28.2 76.3-43.9 121.3-43.9 35 0 68.4 9.5 97.6 27.1L813.5 844h-603z' fill='%23666'/%3E%3C/svg%3E\");background-repeat:no-repeat;background-position:bottom;background-size:30px}.pictool-module-dashboard .pictool-dashboard-nav-btn.dashboard-effect:before{content:\"\";position:absolute;top:0;left:0;right:0;height:40px;background:url(\"data:image/svg+xml;charset=utf-8,%3Csvg class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cdefs%3E%3Cstyle/%3E%3C/defs%3E%3Cpath d='M840 192h-56v-72c0-13.3-10.7-24-24-24H168c-13.3 0-24 10.7-24 24v272c0 13.3 10.7 24 24 24h592c13.3 0 24-10.7 24-24V256h32v200H465c-22.1 0-40 17.9-40 40v136h-44c-4.4 0-8 3.6-8 8v228c0 .6.1 1.3.2 1.9-.1 2-.2 4.1-.2 6.1 0 46.4 37.6 84 84 84s84-37.6 84-84c0-2.1-.1-4.1-.2-6.1.1-.6.2-1.2.2-1.9V640c0-4.4-3.6-8-8-8h-44V520h351c22.1 0 40-17.9 40-40V232c0-22.1-17.9-40-40-40zM720 352H208V160h512v192zM477 876c0 11-9 20-20 20s-20-9-20-20V696h40v180z' fill='%23666'/%3E%3C/svg%3E\");background-repeat:no-repeat;background-position:bottom;background-size:30px}.pictool-module-dashboard .pictool-dashboard-nav-btn.dashboard-adjust:before{content:\"\";position:absolute;top:0;left:0;right:0;height:40px;background:url(\"data:image/svg+xml;charset=utf-8,%3Csvg class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cpath d='M924.8 385.6c-22.6-53.4-54.9-101.3-96-142.4-41.1-41.1-89-73.4-142.4-96C631.1 123.8 572.5 112 512 112s-119.1 11.8-174.4 35.2c-53.4 22.6-101.3 54.9-142.4 96-41.1 41.1-73.4 89-96 142.4C75.8 440.9 64 499.5 64 560c0 132.7 58.3 257.7 159.9 343.1l1.7 1.4c5.8 4.8 13.1 7.5 20.6 7.5h531.7c7.5 0 14.8-2.7 20.6-7.5l1.7-1.4C901.7 817.7 960 692.7 960 560c0-60.5-11.9-119.1-35.2-174.4zM761.4 836H262.6C184.5 765.5 140 665.6 140 560c0-99.4 38.7-192.8 109-263 70.3-70.3 163.7-109 263-109 99.4 0 192.8 38.7 263 109 70.3 70.3 109 163.7 109 263 0 105.6-44.5 205.5-122.6 276z' fill='%23666'/%3E%3Cpath d='M623.5 421.5c-3.1-3.1-8.2-3.1-11.3 0L527.7 506c-18.7-5-39.4-.2-54.1 14.5-21.9 21.9-21.9 57.3 0 79.2 21.9 21.9 57.3 21.9 79.2 0 14.7-14.7 19.5-35.4 14.5-54.1l84.5-84.5c3.1-3.1 3.1-8.2 0-11.3l-28.3-28.3zM490 320h44c4.4 0 8-3.6 8-8v-80c0-4.4-3.6-8-8-8h-44c-4.4 0-8 3.6-8 8v80c0 4.4 3.6 8 8 8zm260 218v44c0 4.4 3.6 8 8 8h80c4.4 0 8-3.6 8-8v-44c0-4.4-3.6-8-8-8h-80c-4.4 0-8 3.6-8 8zm12.7-197.2l-31.1-31.1c-3.1-3.1-8.2-3.1-11.3 0l-56.6 56.6c-3.1 3.1-3.1 8.2 0 11.3l31.1 31.1c3.1 3.1 8.2 3.1 11.3 0l56.6-56.6c3.1-3.1 3.1-8.2 0-11.3zm-458.6-31.1c-3.1-3.1-8.2-3.1-11.3 0l-31.1 31.1c-3.1 3.1-3.1 8.2 0 11.3l56.6 56.6c3.1 3.1 8.2 3.1 11.3 0l31.1-31.1c3.1-3.1 3.1-8.2 0-11.3l-56.6-56.6zM262 530h-80c-4.4 0-8 3.6-8 8v44c0 4.4 3.6 8 8 8h80c4.4 0 8-3.6 8-8v-44c0-4.4-3.6-8-8-8z' fill='%23666'/%3E%3C/svg%3E\");background-repeat:no-repeat;background-position:bottom;background-size:30px}.pictool-module-dashboard .pictool-dashboard-nav-btn.dashboard-edit:before{content:\"\";position:absolute;top:0;left:0;right:0;height:40px;background:url(\"data:image/svg+xml;charset=utf-8,%3Csvg class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cpath d='M904 512h-56c-4.4 0-8 3.6-8 8v320H184V184h320c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H144c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V520c0-4.4-3.6-8-8-8z' fill='%23666'/%3E%3Cpath d='M355.9 534.9L354 653.8c-.1 8.9 7.1 16.2 16 16.2h.4l118-2.9c2-.1 4-.9 5.4-2.3l415.9-415c3.1-3.1 3.1-8.2 0-11.3L785.4 114.3c-1.6-1.6-3.6-2.3-5.7-2.3s-4.1.8-5.7 2.3l-415.8 415c-1.4 1.5-2.3 3.5-2.3 5.6zm63.5 23.6L779.7 199l45.2 45.1-360.5 359.7-45.7 1.1.7-46.4z' fill='%23666'/%3E%3C/svg%3E\");background-repeat:no-repeat;background-position:bottom;background-size:30px}.pictool-module-dashboard .pictool-dashboard-nav-btn.dashboard-text:before{content:\"\";position:absolute;top:0;left:0;right:0;height:40px;background:url(\"data:image/svg+xml;charset=utf-8,%3Csvg class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cpath d='M904 816H120c-4.4 0-8 3.6-8 8v80c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-80c0-4.4-3.6-8-8-8zm-650.3-80h85c4.2 0 8-2.7 9.3-6.8l53.7-166h219.2l53.2 166c1.3 4 5 6.8 9.3 6.8h89.1c1.1 0 2.2-.2 3.2-.5 5.1-1.8 7.8-7.3 6-12.4L573.6 118.6c-1.4-3.9-5.1-6.6-9.2-6.6H462.1c-4.2 0-7.9 2.6-9.2 6.6L244.5 723.1c-.4 1-.5 2.1-.5 3.2-.1 5.3 4.3 9.7 9.7 9.7zm255.9-516.1h4.1l83.8 263.8H424.9l84.7-263.8z' fill='%23666'/%3E%3C/svg%3E\");background-repeat:no-repeat;background-position:bottom;background-size:30px}");C(".pictool-component-progress{width:100%;height:28px;display:block}.pictool-component-progress.progress-hidden{display:none}.pictool-component-progress .pictool-progress-outer{position:relative;height:28px;width:100%;background:#666;border-radius:14px;overflow:hidden}.pictool-component-progress .pictool-progress-inner{position:absolute;height:28px;width:100%;background:#00d4ff;border-radius:14px}");function rt(t){void 0===t&&(t={});var e=[];if(!0===U(t))for(var n in t){var o=""+n,a=""+t[n];o=o.trim(),a=a.trim(),e.push(o+":"+a)}return e.join("; ")}var st=(ct.prototype._render=function(){if(!0!==this._hasRendered){var t=this._options,e=t.mount,n=t.customStyle,o=t.percent,a='\n      <div class="pictool-component-progress" style="'+rt(n)+'">\n        <div class="pictool-progress-outer">\n          <div class="pictool-progress-inner"></div>\n        </div>\n      </div>\n    ',i=document.createElement("div");i.innerHTML=a;var r=i.querySelector("div.pictool-component-progress");e.appendChild(r),this._component=r,this._setInnerMovePercent(o),this._triggerEvent()}},ct.prototype.show=function(){this._component.classList.remove("progress-hidden")},ct.prototype.hide=function(){this._component.classList.add("progress-hidden")},ct.prototype.resetPercent=function(t){this._setInnerMovePercent(t)},ct.prototype.resetOnChange=function(t){this._options.onChange=t},ct.prototype.resetRange=function(t,e){this._rangeList=[];for(var n=(e-t)/100,o=t;o<e;o+=n)this._rangeList.push(o);this._rangeList.push(e)},ct.prototype._triggerEvent=function(){var o=this,t=(this._options,this._component),e=t.querySelector(".pictool-progress-outer");t.querySelector(".pictool-progress-inner"),e.addEventListener("touchstart",function(t){var e=t.touches[0].clientX,n=o._calculateMovePercent(e);o._setInnerMovePercent(n)}),e.addEventListener("touchmove",function(t){var e=t.touches[0].clientX,n=o._calculateMovePercent(e);o._setInnerMovePercent(n)}),e.addEventListener("touchend",function(){var t={value:o._getInnerValue()},e=o._options.onChange;T(e)&&e(t)}),e.addEventListener("mousedown",function(t){var e=t.clientX,n=o._calculateMovePercent(e);o._setInnerMovePercent(n)}),e.addEventListener("mouseup",function(){var t={value:o._getInnerValue()},e=o._options.onChange;T(e)&&e(t)})},ct.prototype._calculateMovePercent=function(t){var e=this._component.querySelector(".pictool-progress-outer"),n=this._getViewAbsoluteLeft(e),o=e.clientWidth,a=t-n;return Math.ceil(100*a/o)},ct.prototype._setInnerMovePercent=function(t){var e=this._component.querySelector(".pictool-progress-inner"),n=0<t?t:0;n=Math.min(n,100),n=Math.max(n,0);var o=rt({left:"-"+(100-n)+"%"});e.setAttribute("style",o),e.setAttribute("data-component-inner-percent",""+n)},ct.prototype._getInnerValue=function(){var t=this._component.querySelector(".pictool-progress-inner").getAttribute("data-component-inner-percent"),e=parseInt(t,10);return e=Math.min(100,e),e=Math.max(0,e),this._rangeList[e]},ct.prototype._getViewAbsoluteLeft=function(t){for(var e=t.offsetLeft,n=t.offsetParent;null!==n;)e+=n.offsetLeft,n=n.offsetParent;return e},ct);function ct(t){this._options=null,this._hasRendered=!1,this._component=null,this._options=t,this._render(),this._rangeList=[];var e=this._options,n=e.max,o=void 0===n?100:n,a=e.min,i=void 0===a?0:a;this.resetRange(o,i)}C("@keyframes loading-animate{0%{width:0}to{width:90%}}.pictool-component-loading{position:fixed;left:0;right:0;top:0;bottom:0;z-index:1000;background:rgba(0,0,0,.67);display:none}.pictool-component-loading.loading-show{display:block}.pictool-component-loading.loading-show .pictool-loading-inner{height:100%;width:90%;background:-webkit-linear-gradient(left,rgba(75,240,248,.51),#3d7bd9);background:-moz-linear-gradient(left,rgba(75,240,248,.51),#3f7dd9);background:-o-linear-gradient(left,rgba(75,240,248,.51),#3d7bd9);background:-ms-linear-gradient(left,rgba(75,240,248,.51),#3d7bd9);background:linear-gradient(left,rgba(75,240,248,.51),#3d7bd9);border-radius:10px;box-shadow:inset 0 -2px 2px rgba(0,0,0,.2);animation:loading-animate 2s linear}.pictool-component-loading.loading-show .pictool-loading-outer{position:absolute;top:50%;left:10%;right:10%;height:10px;border-radius:10px;background:-webkit-linear-gradient(left,#e4e3e4,#e4e5e4);background:-moz-linear-gradient(left,#e4e3e4,#e4e5e4);background:-o-linear-gradient(left,#e4e3e4,#e4e5e4);background:-ms-linear-gradient(left,#e4e3e4,#e4e5e4);background:linear-gradient(left,#e4e3e4,#e4e5e4)}");var lt=(ht.prototype._render=function(){if(!0!==this._hasRendered){var t=this._options,e=t.mount,n='\n      <div class="pictool-component-loading" style="z-index:'+t.zIndex+';">\n        <div class="pictool-loading-outer">\n          <div class="pictool-loading-inner"></div>\n        </div>\n      </div>\n    ',o=document.createElement("div");o.innerHTML=n;var a=o.querySelector("div.pictool-component-loading");e instanceof HTMLElement?e.appendChild(a):document.querySelector("body").appendChild(a),this._component=a}},ht.prototype.show=function(t){var e=this;this._component.classList.add("loading-show"),0<t&&setTimeout(function(){e.hide()},t)},ht.prototype.hide=function(){this._component.classList.remove("loading-show")},ht);function ht(t){this._options=null,this._hasRendered=!1,this._component=null,this._options=t,this._render()}C(".pictool-component-actionsheet{display:none;background:hsla(0,0%,100%,0);position:fixed;left:0;right:0;bottom:0;font-size:14px;color:#333}.pictool-component-actionsheet .pictool-actionsheet-container{position:absolute;left:0;right:0;bottom:0;height:100%;width:100%;background:#fff;transition:.6s}.pictool-component-actionsheet.actionsheet-open{display:block}.pictool-component-actionsheet .pictool-actionsheet-content{position:absolute;top:0;bottom:0;width:100%;background:#fff}");var dt=(pt.prototype.show=function(){var t=this._options,e=t.beforeShow,n=t.afterShow,o=this._contentMount;"function"==typeof e&&e({contentMount:o}),this._component.classList.add("actionsheet-open"),"function"==typeof n&&n({contentMount:o})},pt.prototype.hide=function(){var t=this._options,e=t.beforeHide,n=t.afterHide,o=this._contentMount;"function"==typeof e&&e({contentMount:o}),this._component.classList.remove("actionsheet-open"),"function"==typeof n&&n({contentMount:o})},pt.prototype._render=function(){if(!0!==this._hasRendered){var t=this._options,e=t.afterRender,n=t.beforeRender,o=t.mount;"function"==typeof n&&n();var a=this._options,i='\n    <div class="pictool-component-actionsheet" style="height:'+a.height+"px; z-index: "+a.zIndex+';">\n      <div class="pictool-actionsheet-container">\n        <div class="pictool-actionsheet-header"></div>\n        <div class="pictool-actionsheet-content"></div>\n        <div class="pictool-actionsheet-footer"></div>\n      </div>\n    </div>\n    ',r=document.querySelector("body"),s=document.createElement("div");s.innerHTML=i;var c=s.querySelector("div.pictool-component-actionsheet");o?o.appendChild(c):r.appendChild(c);var l=c.querySelector("div.pictool-actionsheet-content");"function"==typeof e&&e({contentMount:l}),this._hasRendered=!0,this._component=c,this._contentMount=l}},pt);function pt(t){this._hasRendered=!1,this._component=null,this._contentMount=null,this._options=t,this._render()}C(".pictool-module-panel{height:100%;width:100%;position:relative;font-size:14px;color:#333}.pictool-module-panel .pictool-panel-header{position:absolute;top:0;left:0;right:0;height:40px;box-shadow:0 0 6px 0 rgba(0,0,0,.08)}.pictool-module-panel .pictool-panel-header .pictool-panel-title{line-height:40px;text-align:center;font-size:16px}.pictool-module-panel .pictool-panel-header .pictool-panel-btn-close{position:absolute;right:0;top:0;width:60px;height:40px}.pictool-module-panel .pictool-panel-header .pictool-panel-btn-close:before{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;background:url(\"data:image/svg+xml;charset=utf-8,%3Csvg class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cpath d='M685.4 354.8c0-4.4-3.6-8-8-8l-66 .3L512 465.6l-99.3-118.4-66.1-.3c-4.4 0-8 3.5-8 8 0 1.9.7 3.7 1.9 5.2l130.1 155L340.5 670c-1.2 1.5-1.9 3.3-1.9 5.2 0 4.4 3.6 8 8 8l66.1-.3L512 564.4l99.3 118.4 66 .3c4.4 0 8-3.5 8-8 0-1.9-.7-3.7-1.9-5.2L553.5 515l130.1-155c1.2-1.4 1.8-3.3 1.8-5.2z' fill='%23666'/%3E%3Cpath d='M512 65C264.6 65 64 265.6 64 513s200.6 448 448 448 448-200.6 448-448S759.4 65 512 65zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z' fill='%23666'/%3E%3C/svg%3E\");background-repeat:no-repeat;background-position:50%;background-size:30px}.pictool-module-panel .pictool-panel-navigation{position:absolute;height:80px;width:100%;bottom:0;background:rgba(33,150,243,.05);overflow:auto;-webkit-overflow-scrolling:touch}.pictool-module-panel .pictool-panel-navlist{width:100%;height:100%;display:flex;-webkit-overflow-scrolling:touch}.pictool-module-panel .pictool-panel-navlist.panel-beyond-width{display:block}.pictool-module-panel .pictool-panel-navlist.panel-beyond-width .pictool-panel-nav-btn{width:100px;display:block;float:left}.pictool-module-panel .pictool-panel-nav-btn{flex:1;text-align:center;font-size:14px;position:relative;padding-top:40px}.pictool-module-panel .pictool-panel-nav-btn.panelnav-icon:before{content:\"\";position:absolute;top:0;left:0;right:0;height:40px;background:url(\"data:image/svg+xml;charset=utf-8,%3Csvg class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cpath d='M288 421a48 48 0 1096 0 48 48 0 10-96 0zM640 421a48 48 0 1096 0 48 48 0 10-96 0z' fill='%23666'/%3E%3Cpath d='M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm263 711c-34.2 34.2-74 61-118.3 79.8C611 874.2 562.3 884 512 884c-50.3 0-99-9.8-144.8-29.2-44.3-18.7-84.1-45.6-118.3-79.8-34.2-34.2-61-74-79.8-118.3C149.8 611 140 562.3 140 512s9.8-99 29.2-144.8c18.7-44.3 45.6-84.1 79.8-118.3 34.2-34.2 74-61 118.3-79.8C413 149.8 461.7 140 512 140c50.3 0 99 9.8 144.8 29.2 44.3 18.7 84.1 45.6 118.3 79.8 34.2 34.2 61 74 79.8 118.3C874.2 413 884 461.7 884 512s-9.8 99-29.2 144.8c-18.7 44.3-45.6 84.1-79.8 118.2z' fill='%23666'/%3E%3Cpath d='M664 533h-48.1c-4.2 0-7.8 3.2-8.1 7.4C604 589.9 562.5 629 512 629s-92.1-39.1-95.8-88.6c-.3-4.2-3.9-7.4-8.1-7.4H360c-4.6 0-8.2 3.8-8 8.4 4.4 84.3 74.5 151.6 160 151.6s155.6-67.3 160-151.6c.2-4.6-3.4-8.4-8-8.4z' fill='%23666'/%3E%3C/svg%3E\");background-repeat:no-repeat;background-position:bottom;background-size:30px}.pictool-module-panel .pictool-panel-nav-btn.panelnav-active{color:#17abe3}.pictool-module-panel .pictool-panel-nav-btn.panelnav-active.panelnav-icon:before{content:\"\";position:absolute;top:0;left:0;right:0;height:40px;background:url(\"data:image/svg+xml;charset=utf-8,%3Csvg class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cpath d='M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zM288 421c0-26.5 21.5-48 48-48s48 21.5 48 48-21.5 48-48 48-48-21.5-48-48zm224 272c-85.5 0-155.6-67.3-160-151.6-.2-4.6 3.4-8.4 8-8.4h48.1c4.2 0 7.8 3.2 8.1 7.4C420 589.9 461.5 629 512 629s92.1-39.1 95.8-88.6c.3-4.2 3.9-7.4 8.1-7.4H664c4.6 0 8.2 3.8 8 8.4-4.4 84.3-74.5 151.6-160 151.6zm176-224c-26.5 0-48-21.5-48-48s21.5-48 48-48 48 21.5 48 48-21.5 48-48 48z' fill='%2317abe3'/%3E%3C/svg%3E\");background-repeat:no-repeat;background-position:bottom;background-size:30px}");var ut=(gt.prototype.show=function(){this._actionSheet.show()},gt.prototype.hide=function(){this._actionSheet.hide()},gt.prototype._render=function(t){if(!0!==this._hasRendered){var e=this._opts,n=e.navList,o=e.title,a=4<n.length,i='\n      <div class="pictool-module-panel">\n        <div class="pictool-panel-header">\n          <div class="pictool-panel-btn-close"></div>\n          <div class="pictool-panel-title">'+(o||"")+'</div>\n        </div>\n        <div class="pictool-panel-navigation">\n          <div class="pictool-panel-navlist '+(1==a?"panel-beyond-width":"")+'" \n            style="'+(1==a?"width: "+120*(n.length+1)+"px":"")+'"\n          >\n          '+(z(n)&&n.map(function(t,e){return' \n            <div class="pictool-panel-nav-btn panelnav-icon"\n              data-panel-nav-idx="'+e+'"\n            >\n              <span>'+t.name+"</span>\n            </div>\n            "}).join(""))+"\n          </div>\n        </div>\n      </div>\n    ";t.innerHTML=i,this._registerEvent(t),this._hasRendered=!0}},gt.prototype._registerEvent=function(t){if(!0!==this._hasRendered){var e=this,o=this._opts.navList,a=t.querySelectorAll("[data-panel-nav-idx]");t.querySelector("div.pictool-panel-btn-close").addEventListener("click",function(){e.hide()}),!0===H(a)&&a.forEach(function(t){t.addEventListener("click",function(t){var e=1*this.getAttribute("data-panel-nav-idx"),n=o[e].feedback();P(n)?n.then(function(t){t&&Q.trigger("GlobalEvent.moduleSketch.renderImage",t)}).catch(function(t){console.log(t)}):!0!==O(n)&&console.warn("feedback is not a promise or null"),a.forEach(function(t){t.classList.remove("panelnav-active")}),this.classList.add("panelnav-active")})})}},gt);function gt(t){this._actionSheet=null,this._opts=null,this._hasRendered=!1,this._opts=t;var n=this,e=t.zIndex,o=t.mount,a=new dt({height:120,mount:o,zIndex:e,afterRender:function(t){var e=t.contentMount;n._render(e)},beforeHide:function(){Q.trigger("GlobalEvent.moduleDashboard.progress.hide")}});this._actionSheet=a}function ft(t,e){return new Promise(function(n,o){try{!function(t,e){var n=t.key,o=t.param,a=t.feedback;if(e&&!0===e.use){var i=e.path,r=new Worker(i);r.onmessage=function(t){"function"==typeof a&&(a(t.data.result,t.data.error),r.terminate())},r.onerror=function(t){"function"==typeof a&&(a(null,t.message),r.terminate())},r.postMessage({key:n,param:o})}else setTimeout(function(){var e=null,t=null;try{t=(0,vt[n])(o)}catch(t){e=t}"function"==typeof a&&a(t,e)},1)}({key:t.key,param:t.param,feedback:function(t,e){e?o(e):n(t)}},e)}catch(t){o(t)}})}var vt=Object.freeze({origin:function(t){var e=t.imageData;return D.util.digitImageData2ImageData(e)},grayscale:function(t){var e=t.imageData,n=new p(e),o=n.process("grayscale").getImageData();return n.destory(),n=null,o},hue:function(t){var e=t.imageData,n=t.options,o=new p(e),a=o.process("hue",n).getImageData();return o.destory(),o=null,a},lightness:function(t){var e=t.imageData,n=t.options,o=new p(e),a=o.process("lightness",n).getImageData();return o.destory(),o=null,a},saturation:function(t){var e=t.imageData,n=t.options,o=new p(e),a=o.process("saturation",n).getImageData();return o.destory(),o=null,a},invert:function(t){var e=t.imageData,n=t.options,o=new p(e),a=o.process("invert",n).getImageData();return o.destory(),o=null,a},sobel:function(t){var e=t.imageData,n=t.options,o=new p(e),a=o.process("sobel",n).getImageData();return o.destory(),o=null,a},lineDrawing:function(t){var e=t.imageData,n=t.options,o=new p(e),a=o.process("sobel",n).process("invert",n).getImageData();return o.destory(),o=null,a},oilDrawing:function(t){var e=t.imageData,n=(t.options,new p(e)),o=n.process("gamma",{value:8}).process("posterize",{value:8}).getImageData();return n.destory(),n=null,o},old:function(t){var e=t.imageData,n=(t.options,new p(e)),o=n.process("sepia").getImageData();return n.destory(),n=null,o},natural:function(t){var e=t.imageData,n=(t.options,new p(e)),o=n.process("saturation",{percent:76}).getImageData();return n.destory(),n=null,o},alpha:function(t){var e=t.imageData,n=t.options,o=new p(e),a=o.process("alpha",n).getImageData();return o.destory(),o=null,a},sepia:function(t){var e=t.imageData,n=t.options,o=new p(e),a=o.process("sepia",n).getImageData();return o.destory(),o=null,a},posterize:function(t){var e=t.imageData,n=t.options,o=new p(e),a=o.process("posterize",n).getImageData();return o.destory(),o=null,a},gamma:function(t){var e=t.imageData,n=t.options,o=new p(e),a=o.process("gamma",n).getImageData();return o.destory(),o=null,a}});var mt={PROCESS:"简单处理",EFFECT:"效果",ADJUST:"图像调节",PROCESS_ORIGIN:"原图",PROCESS_GRAYSCALE:"灰度",PROCESS_SOBEL:"边缘检测",PROCESS_INVERT:"反色",PROCESS_SEPIA:"褐色化",ADJUST_LIGHTNESS:"亮度",ADJUST_HUE:"色相",ADJUST_SATURATION:"饱和度",ADJUST_ALPHA:"透明度",ADJUST_GAMMA:"伽马",ADJUST_POSTERIZE:"色阶",EFFECT_ORIGIN:"原图",EFFECT_OLD:"怀旧",EFFECT_LINEDRAWING:"素描",EFFECT_OILDRAWING:"油画",EFFECT_NATURAL:"自然"},_t={PROCESS:"Process",EFFECT:"Effect",ADJUST:"Adjustment",PROCESS_ORIGIN:"Origin",PROCESS_GRAYSCALE:"Grayscale",PROCESS_SOBEL:"Sobel",PROCESS_INVERT:"Invert",PROCESS_SEPIA:"Sepia",ADJUST_LIGHTNESS:"Lightness",ADJUST_HUE:"Hue",ADJUST_SATURATION:"Saturation",ADJUST_ALPHA:"Alpha",ADJUST_GAMMA:"Gamma",ADJUST_POSTERIZE:"Posterize",EFFECT_ORIGIN:"Origin",EFFECT_OLD:"Old",EFFECT_LINEDRAWING:"LineDrawing",EFFECT_OILDRAWING:"OilDrawing",EFFECT_NATURAL:"Natural"};var bt=(wt.prototype._render=function(){if(!0!==this._hasRendered){var t=this._opts;if(t&&this._mount){var e=t.zIndex,n=function(t){void 0===t&&(t="en-us");var e=_t;return"zh-cn"===t&&(e=w({},_t,mt)),e}(t.language),o=function(t){return{title:t.PROCESS,menu:[{name:t.PROCESS_ORIGIN,filter:"origin"},{name:t.PROCESS_GRAYSCALE,filter:"grayscale"},{name:t.PROCESS_SOBEL,filter:"sobel"},{name:t.PROCESS_INVERT,filter:"invert"},{name:t.PROCESS_SEPIA,filter:"sepia"}]}}(n),a=function(t){return{title:t.EFFECT,menu:[{name:t.EFFECT_ORIGIN,filter:"origin"},{name:t.EFFECT_OLD,filter:"old"},{name:t.EFFECT_LINEDRAWING,filter:"lineDrawing"},{name:t.EFFECT_OILDRAWING,filter:"oilDrawing"},{name:t.EFFECT_NATURAL,filter:"natural"}]}}(n),i=function(t){return void 0===t&&(t={}),{title:t.ADJUST,menu:[{name:t.ADJUST_LIGHTNESS,percent:50,range:{min:-100,max:100},filter:"lightness",parseOptions:function(t){var e=Math.round(t.value);return console.log("lightness.percent = ",e),{percent:e}}},{name:t.ADJUST_HUE,percent:50,range:{min:0,max:360},filter:"hue",parseOptions:function(t){var e=Math.round(t.value);return console.log("hue.value = ",e),{value:e}}},{name:t.ADJUST_SATURATION,percent:50,range:{min:-100,max:100},filter:"saturation",parseOptions:function(t){var e=Math.round(t.value);return console.log("saturation.percent = ",e),{percent:e}}},{name:t.ADJUST_ALPHA,percent:50,range:{min:0,max:100},filter:"alpha",parseOptions:function(t){var e=Math.round(t.value);return console.log("alpha.value = ",e),{value:e}}},{name:t.ADJUST_GAMMA,percent:50,range:{min:0,max:100},filter:"gamma",parseOptions:function(t){var e=Math.round(t.value);return console.log("gamma.value = ",e),{value:e}}},{name:t.ADJUST_POSTERIZE,percent:50,range:{min:0,max:100},filter:"posterize",parseOptions:function(t){var e=Math.round(t.value);return console.log("posterize.value = ",e),{value:e}}}]}}(n),r='\n      <div class="pictool-module-dashboard" style="z-index:'+e+';">\n        <div class="pictool-dashboard-navlist">\n          <div class="pictool-dashboard-nav-btn dashboard-process" data-nav-action="process" >\n            <span>'+o.title+'</span>\n          </div>\n          <div class="pictool-dashboard-nav-btn dashboard-adjust" data-nav-action="adjust" >\n            <span>'+i.title+'</span>\n          </div>\n          <div class="pictool-dashboard-nav-btn dashboard-effect" data-nav-action="effect" >\n            <span>'+a.title+"</span>\n          </div>\n        </div>\n      </div>\n    ";this._mount.innerHTML=r,this._registerEvent({processMenuConfig:o,effectMenuConfig:a,adjustMenuConfig:i}),this._hasRendered=!0}}},wt.prototype._registerEvent=function(t){if(!0!==this._hasRendered){var e=this._opts;if(e&&this._mount){var n=e.zIndex,o=(e.workerConfig,this._mount.querySelector('[data-nav-action="effect"]')),a=this._mount.querySelector('[data-nav-action="adjust"]'),i=this._mount.querySelector('[data-nav-action="process"]'),r=this._initProcessPanel(t.processMenuConfig);i&&i.addEventListener("click",function(){r&&r.show()});var s=this._initEffectPanel(t.effectMenuConfig);o&&o.addEventListener("click",function(){s&&s.show()});var c=this._initAdjustPanel(t.adjustMenuConfig);a&&a.addEventListener("click",function(){c&&c.show()});var l=new st({mount:this._mount,percent:40,max:100,min:0,customStyle:{"z-index":n+1,position:"fixed",bottom:"140px",left:"5%",right:"5%",width:"auto"},onChange:function(t){console.log("data =",t)}});l.hide(),Q.on("GlobalEvent.moduleDashboard.progress.show",function(t){var e=t.percent,n=t.onChange,o=t.range;l.resetRange(o.min,o.max),l.resetOnChange(n),l.resetPercent(e),l.show()}),Q.on("GlobalEvent.moduleDashboard.progress.hide",function(){l.resetOnChange(null),l.resetPercent(50),l.resetRange(0,100),l.hide()});var h=new lt({zIndex:n+1e3});Q.on("GlobalEvent.moduleDashboard.loading.show",function(t){var e=-1;t&&0<t.timeout&&(e=t.timeout),h.show(e)}),Q.on("GlobalEvent.moduleDashboard.loading.hide",function(){h.hide()})}}},wt.prototype._initProcessPanel=function(t){var e=this._opts;if(!this._mount)return null;var n=e.zIndex,i=e.workerConfig;return new ut({title:t.title,mount:this._mount,zIndex:n+1,navList:t.menu.map(function(a){return{name:a.name,feedback:function(){var t=et("Sketch.originSketchSchema"),e=nt(t),o=D.util.imageData2DigitImageData(e);return new Promise(function(n,e){Q.trigger("GlobalEvent.moduleDashboard.loading.show"),ft({key:a.filter,param:{imageData:o,options:{}}},i).then(function(t){Q.trigger("GlobalEvent.moduleDashboard.loading.hide");var e=ot(t);n(e)}).catch(function(t){Q.trigger("GlobalEvent.moduleDashboard.loading.hide"),e(t)})})}}})})},wt.prototype._initEffectPanel=function(t){var e=this._opts;if(!this._mount)return null;var n=e.zIndex,i=e.workerConfig;return new ut({title:t.title,mount:this._mount,zIndex:n+1,navList:t.menu.map(function(a){return{name:a.name,feedback:function(){var t=et("Sketch.originSketchSchema"),e=nt(t),o=D.util.imageData2DigitImageData(e);return new Promise(function(n,e){Q.trigger("GlobalEvent.moduleDashboard.loading.show"),ft({key:a.filter,param:{imageData:o,options:{}}},i).then(function(t){Q.trigger("GlobalEvent.moduleDashboard.loading.hide");var e=ot(t);n(e)}).catch(function(t){Q.trigger("GlobalEvent.moduleDashboard.loading.hide"),e(t)})})}}})})},wt.prototype._initAdjustPanel=function(t){var e=this._opts;if(e){var n=e.zIndex,a=e.workerConfig;if(this._mount)return new ut({title:t.title,mount:this._mount,zIndex:n+1,navList:t.menu.map(function(o){return{name:o.name,feedback:function(){var t=et("Sketch.originSketchSchema"),e=nt(t),n=D.util.imageData2DigitImageData(e);return Q.trigger("GlobalEvent.moduleDashboard.progress.show",{percent:o.percent,range:{max:o.range.max,min:o.range.min},onChange:function(t){Q.trigger("GlobalEvent.moduleDashboard.loading.show"),ft({key:o.filter,param:{imageData:n,options:o.parseOptions(t)}},a).then(function(t){var e=ot(t);Q.trigger("GlobalEvent.moduleSketch.renderImage",e),Q.trigger("GlobalEvent.moduleDashboard.loading.hide")}).catch(function(t){console.log(t),Q.trigger("GlobalEvent.moduleDashboard.loading.hide")})}}),null}}})})}},wt);function wt(t,e){this._hasRendered=!1,this._mount=t,this._opts=e,this._render()}C(".pictool-module-header{position:relative;font-size:14px;color:#fff}.pictool-module-header .pictool-header-btn-close{position:absolute;left:0;top:0;width:60px;height:40px}.pictool-module-header .pictool-header-btn-close:before{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;background:url(\"data:image/svg+xml;charset=utf-8,%3Csvg class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cpath d='M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9c-4.4 5.2-.7 13.1 6.1 13.1h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z' fill='%23fff'/%3E%3C/svg%3E\");background-repeat:no-repeat;background-position:50%;background-size:30px}.pictool-module-header .pictool-header-btn-save{position:absolute;right:0;top:0;width:60px;height:40px}.pictool-module-header .pictool-header-btn-save:before{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;background:url(\"data:image/svg+xml;charset=utf-8,%3Csvg class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cpath d='M893.3 293.3L730.7 130.7c-7.5-7.5-16.7-13-26.7-16V112H144c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V338.5c0-17-6.7-33.2-18.7-45.2zM384 184h256v104H384V184zm456 656H184V184h136v136c0 17.7 14.3 32 32 32h320c17.7 0 32-14.3 32-32V205.8l136 136V840z' fill='%23fff'/%3E%3Cpath d='M512 442c-79.5 0-144 64.5-144 144s64.5 144 144 144 144-64.5 144-144-64.5-144-144-144zm0 224c-44.2 0-80-35.8-80-80s35.8-80 80-80 80 35.8 80 80-35.8 80-80 80z' fill='%23fff'/%3E%3C/svg%3E\");background-repeat:no-repeat;background-position:50%;background-size:30px}");var yt=(kt.prototype._render=function(){!0!==this._hasRendered&&(this._mount.innerHTML='\n      <div class="pictool-module-header">\n        <div class="pictool-header-btn-close"></div>\n        <div class="pictool-header-btn-save"></div>\n      </div>\n    ',this._registerEvent(),this._hasRendered=!0)},kt.prototype._registerEvent=function(){var t=this._mount.querySelector("div.pictool-header-btn-close"),e=this._mount.querySelector("div.pictool-header-btn-save"),n=this._opts;t.addEventListener("click",function(){T(n.closeFeedback)&&n.closeFeedback()}),e.addEventListener("click",function(){T(n.saveFeedback)&&n.saveFeedback()})},kt);function kt(t,e){this._mount=null,this._opts=null,this._hasRendered=!1,this._mount=t,this._opts=e,this._render()}var Et=(xt.prototype.show=function(){var t=et("Sketch.originSketchSchema");this._sketch&&this._sketch.renderImage(t),this._mask.show(),Q.trigger("GlobalEvent.moduleSketch.resizeCanvas")},xt.prototype.hide=function(){this._mask.hide()},xt);function xt(s,t){var c=this;void 0===t&&(t={uiConfig:{},workerConfig:{use:!1,path:""}}),this._imageData=null,this._sketch=null,this._dashboard=null,this._header=null,this._imageData=s;var e=(this._options=t).uiConfig,l=void 0===e?{}:e,h=t.workerConfig,d=l.zIndex;d&&0<1*d||(d=1e3);var p=new M({zIndex:d,afterRender:function(t){var e=t.contentMount,n=t.headerMount,o=t.footerMount,a=new yt(n,{closeFeedback:function(){p.hide()},saveFeedback:function(){Q.trigger("GlobalEvent.moduleSketch.downloadImage")}}),i=new at(e,{imageData:s});d&&0<1*d||(d=1e3);var r=new bt(o,{zIndex:d+1,language:l.language||"en-us",workerConfig:h});c._sketch=i,c._dashboard=r,c._header=a}});this._mask=p}var Dt={transform:a,process:i,DigitImageData:m};return{browser:D,digit:{transform:Dt.transform,process:Dt.process,DigitImageData:Dt.DigitImageData,Effect:p},UI:Et}});
  