-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathmcanvas.web.js
15 lines (13 loc) · 27.9 KB
/
mcanvas.web.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.MCanvas=e():t.MCanvas=e()}(window,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(t,e,r){"use strict";r.d(e,"g",(function(){return n.a})),r.d(e,"b",(function(){return o})),r.d(e,"c",(function(){return a})),r.d(e,"a",(function(){return c})),r.d(e,"e",(function(){return u})),r.d(e,"f",(function(){return s})),r.d(e,"k",(function(){return h})),r.d(e,"d",(function(){return f})),r.d(e,"i",(function(){return d})),r.d(e,"j",(function(){return l})),r.d(e,"h",(function(){return g}));var n=r(1);function i(t){var e={},r=e.toString,n=e.hasOwnProperty,i=n.toString,o=i.call(Object);if(!t||"[object Object]"!==r.call(t))return!1;var a=Object.getPrototypeOf(t);if(!a)return!0;var c=n.call(a,"constructor")&&a.constructor;return"function"==typeof c&&i.call(c)===o}function o(){for(var t,e,r,n,a,c,u=[],s=0;s<arguments.length;s++)u[s]=arguments[s];var h=arguments[0]||{},f=1,d=arguments.length,l=!1;for("boolean"==typeof h&&(l=h,h=arguments[f]||{},f++),"object"!=typeof h&&"function"!=typeof h&&(h={}),f===d&&(h=this,f--);f<d;f++)if(null!==(t=arguments[f]))for(e in t)if(t.hasOwnProperty(e)){if(a=h[e],h===(n=t[e]))continue;l&&n&&(i(n)||(c=Array.isArray(n)))?(c?(c=!1,r=a&&Array.isArray(a)?a:[]):r=a&&i(a)?a:{},h[e]=o(l,r,n)):void 0!==n&&(h[e]=n)}return h}function a(t,e){for(var r in t)t.hasOwnProperty(r)&&e(r,t[r])}function c(){var t=window.navigator.userAgent.toLowerCase(),e=/(iPhone|iPad|iPod|iOS)/gi.test(t),r=/(iPad)/gi.test(t);if(e){var n=r?t.match(/cpu os (\d*)/):t.match(/iphone os (\d*)/);return!!(n&&+n[1]<9)}return!1}function u(t){return"IMG"===t.tagName?{iw:t.naturalWidth,ih:t.naturalHeight}:{iw:t.width,ih:t.height}}function s(t,e){return t.indexOf&&-1!==t.indexOf(e)}function h(t,e,r,i){var o=r;if(n.a.str(r))if(s(r,":")&&"pos"===i){var a=r.split(":"),c=a[0],u=a[1];switch(c){case"left":case"top":o=+u.replace("px","");break;case"right":case"bottom":o=t-+u.replace("px","")-e}}else o=s(r,"px")?+r.replace("px",""):s(r,"%")?("crop"===i?e:t)*+r.replace("%","")/100:s(["top","left"],r)?0:s(["bottom","right"],r)?t-e:"center"===r?(t-e)/2:"origin"===r?e:+r;return Math.round(o)}function f(t,e){var r=e;return n.a.str(e)&&(r=s(e,"px")?+e.replace("px",""):s(e,"%")?t*+e.replace("%","")/100:"center"===e?t/2:+e),Math.round(r)}function d(t){throw new Error("[MCanvas ERROR]: "+t)}function l(t){throw new Error("[MCanvas WARN]: "+t)}function p(t){return!!/[\ |\s*(.*?)\s+$|\~|\`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\||\\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\,|\。|\“|\”|\‘|\’|\¥|\?|\(|\)|\;|\:|\、|\!|\<|\.|\>|\/|\?]/g.test(t)}function g(t){if(!n.a.str(t))return[];var e,r=[],i=t.length,o="";for(e=0;e<i;e++){var a=t[e];if(/^[A-Za-z]+$/g.test(a))o+=a,p(t[e+1])&&(r.push(o),o="");else r.push(a)}return r}},function(t,e,r){"use strict";r.d(e,"a",(function(){return o}));var n={};function i(t){var e=n.toString.call(t);return null===t?t+"":Number.isNaN(t)?"NaN":"object"==typeof t||"function"==typeof t?n[e]||"object":typeof t}"Boolean Number String Function Array Date RegExp Object Error Symbol".split(" ").forEach((function(t){n["[object "+t+"]"]=t.toLowerCase()}));var o={primitive:function(t){return["string","number"].includes(i(t))},array:function(t){return"array"===i(t)},str:function(t){return"string"===i(t)},obj:function(t){return"object"===i(t)},arr:function(t){return"array"===i(t)},num:function(t){return"number"===i(t)},fn:function(t){return"function"===i(t)},undef:function(t){return"undefined"===i(t)},def:function(t){return!o.undef(t)},null:function(t){return"null"===i(t)},empty:function(t){switch(i(t)){case"object":return 0===Object.keys(t).length;case"array":return 0===t.length;case"string":return!t.trim();case"undefined":case"null":case"NaN":case"boolean":return!0;default:return!1}},Nil:function(t){return["null","undefined"].includes(i(t))},NaN:function(t){return"NaN"===i(t)},promise:function(t){return!!t&&(o.obj(t)||o.fn(t))&&o.fn(t.then)}}},function(t,e,r){t.exports=r(4)},function(t,e,r){"use strict";r.r(e),r.d(e,"_Canvas",(function(){return i}));var n=r(0),i={name:"WebCanvas",create:function(t,e){void 0===t&&(t=500),void 0===e&&(e=500);var r=document.createElement("canvas"),i=r.getContext("2d");return n.g.num(t)&&(r.width=t),n.g.num(e)&&(r.height=e),[r,i]},loadImage:function(t){return new Promise((function(e,r){var n=new Image;0===t.indexOf("http")&&(n.crossOrigin="*"),n.onload=function(){return e(n)},n.onerror=function(){return r("img load error.url: "+t)},n.src=t}))}}},function(t,e,r){"use strict";r.r(e),r.d(e,"MCanvas",(function(){return u})),r.d(e,"MImage",(function(){return k}));var n=r(0),i=r(3)._Canvas,o={getImage:function(t){return"string"==typeof t?a.loadImage(t):"object"==typeof t?Promise.resolve(t):Promise.reject("getImage error, src="+t)},drawRoundRectPath:function(t,e,r,n){t.beginPath(),t.arc(e-n,r-n,n,0,Math.PI/2),t.lineTo(n,r),t.arc(n,r-n,n,Math.PI/2,Math.PI),t.lineTo(0,n),t.arc(n,n,n,Math.PI,3*Math.PI/2),t.lineTo(e-n,0),t.arc(e-n,n,n,3*Math.PI/2,2*Math.PI),t.lineTo(e,r-n),t.closePath()},drawRoundRect:function(t,e,r,n,i,a,c,u,s){void 0===a&&(a=0),void 0===c&&(c="#fff"),void 0===u&&(u=0),void 0===s&&(s="#000");var h=Math.min(n,i);2*a>h&&(a=h/2),t.save(),t.translate(e,r),o.drawRoundRectPath(t,n,i,a),t.fillStyle=c,t.fill(),t.lineWidth=u,t.strokeStyle=s,t.stroke(),t.restore()}},a=Object(n.b)(!0,i,o);function c(t,e){var r=Object(n.e)(t),i=r.iw,o=r.ih,c=Object(n.b)(!0,{x:0,y:0,width:"100%",height:"100%",radius:0},e),u=c.width,s=c.height,h=c.x,f=c.y,d=c.radius;(u=Object(n.d)(i,u))>i&&(u=i),(s=Object(n.d)(o,s))>o&&(s=o),h=Object(n.k)(i,u,h,"pos"),f=Object(n.k)(o,s,f,"pos"),d=Object(n.d)(i,d);var l=a.create(u,s),p=l[0],g=l[1];return p.width=u,p.height=s,a.drawRoundRect(g,0,0,u,s,d),g.globalCompositeOperation="source-in",g.drawImage(t,-h,-f,i,o),{cvs:p,ctx:g}}var u=function(){function t(t){void 0===t&&(t={}),this.queue=[],this.fn={success:function(){},error:function(t){}},this.data={textId:0,text:{},bgConfig:null},this._defaultFontFamily="helvetica neue,hiragino sans gb,Microsoft YaHei,arial,tahoma,sans-serif",this.ops=Object(n.b)({width:500,height:500,backgroundColor:""},t),this._init()}return t.prototype._init=function(){var t,e=this.ops,r=e.width,n=e.height,i=e.backgroundColor;t=a.create(r,n),this.cvs=t[0],this.ctx=t[1],i&&this._setBgColor(i)},t.prototype.background=function(t,e){var r=this;return void 0===e&&(e={type:"origin"}),t||this.data.bgConfig?(t?(e.image=t,this.data.bgConfig=e):this.data.bgConfig&&(e=this.data.bgConfig),this.queue.push((function(){e.color&&r._setBgColor(e.color),a.getImage(e.image).then((function(t){return r._background(t,e)})).catch(r.fn.error)})),this):(Object(n.i)("the init background must has a image."),this)},t.prototype._setBgColor=function(t){this.ctx.fillStyle=t,this.ctx.fillRect(0,0,this.cvs.width,this.cvs.height)},t.prototype._getBgAlign=function(t,e,r,i){var o;return n.g.str(t)?"50%"===t||"center"===t?o=Math.abs((e-r/i)/2):"100%"===t?o=Math.abs(e-r/i):"0%"===t&&(o=0):o=n.g.num(t)?t:0,o},t.prototype._background=function(t,e){var r,i,o,a,c,u,s,h,f,d=Object(n.e)(t),l=d.iw,p=d.ih,g=l/p,v=this.cvs.width/this.cvs.height;switch(e.type){case"crop":g>v?(o=p*v,a=p,f=this.cvs.height/p):(a=(o=l)/v,f=this.cvs.width/l),r=this._getBgAlign(e.left,l,this.cvs.width,f),i=this._getBgAlign(e.top,p,this.cvs.height,f),u=c=0,h=this.cvs.height,s=this.cvs.width;break;case"contain":i=r=0,o=l,a=p,g>v?(h=(s=this.cvs.width)/g,c=e.left||0,u=e.top||0===e.top?e.top:(this.cvs.height-h)/2):(s=(h=this.cvs.height)*g,u=e.top||0,c=e.left||0===e.left?e.left:(this.cvs.width-s)/2);break;case"origin":this.cvs.width=l,this.cvs.height=p,r=i=0,o=l,a=p,c=u=0,s=this.cvs.width,h=this.cvs.height;break;default:return void Object(n.i)("background type error!")}this.ctx.drawImage(t,r,i,o,a,c,u,s,h),this._next()},t.prototype.rect=function(t){var e=this;return void 0===t&&(t={}),this.queue.push((function(){var r=e.cvs,i=r.width,o=r.height,c=t.fillColor,u=void 0===c?"#fff":c,s=t.strokeColor,h=void 0===s?u:s,f=t.strokeWidth,d=void 0===f?0:f,l=t.radius,p=void 0===l?0:l,g=t.width,v=void 0===g?100:g,y=t.height,b=void 0===y?100:y,x=t.x,m=void 0===x?0:x,w=t.y,j=void 0===w?0:w;v=Object(n.k)(i,0,v,"pos")-2*d,b=Object(n.k)(o,0,b,"pos")-2*d,m=Object(n.k)(i,v,m,"pos")+(Object(n.f)(m,"right")?-d:d),j=Object(n.k)(o,b,j,"pos")+(Object(n.f)(j,"bottom")?-d:d),a.drawRoundRect(e.ctx,m,j,v,b,p,u,d,h),e._resetCtx()._next()})),this},t.prototype.circle=function(t){var e=this;return void 0===t&&(t={}),this.queue.push((function(){var r=t.fillColor,i=void 0===r?"#fff":r,o=t.strokeColor,a=void 0===o?i:o,c=t.strokeWidth,u=void 0===c?0:c,s=e.cvs,h=s.width,f=s.height,d=t.x,l=void 0===d?0:d,p=t.y,g=void 0===p?0:p,v=t.radius,y=void 0===v?100:v,b=Object(n.k)(h,0,y,"pos")-2*u;l=Object(n.k)(h,2*b,l,"pos")+b+(Object(n.f)(l,"right")?-u:u),g=Object(n.k)(f,2*b,g,"pos")+b+(Object(n.f)(g,"bottom")?-u:u),e.ctx.beginPath(),e.ctx.arc(l,g,b,0,2*Math.PI,!1),e.ctx.fillStyle=i,e.ctx.fill(),e.ctx.strokeStyle=a,e.ctx.lineWidth=u,e.ctx.stroke(),e.ctx.closePath(),e._resetCtx()._next()})),this},t.prototype._resetCtx=function(){return this.ctx.setTransform(1,0,0,1,0,0),this},t.prototype.watermark=function(t,e){if(void 0===e&&(e={}),!t)return Object(n.i)("there is not image of watermark."),this;var r=e.width,i=void 0===r?"40%":r,o=e.pos,a=void 0===o?"rightbottom":o,c=e.margin,u=void 0===c?20:c,s={x:0,y:0,scale:1,rotate:0};switch(a){case"leftTop":s.x="left:"+u,s.y="top:"+u;break;case"leftBottom":s.x="left:"+u,s.y="bottom:"+u;break;case"rightTop":s.x="right:"+u,s.y="top:"+u;break;case"rightBottom":s.x="right:"+u,s.y="bottom:"+u}return this.add(t,{width:i,pos:s}),this},t.prototype.add=function(t,e){var r=this,i={width:"100%",crop:{x:0,y:0,width:"100%",height:"100%",radius:0},pos:{x:0,y:0,scale:1,rotate:0}};return(n.g.arr(t)?t:[{image:t,options:e}]).map((function(t){var e=t.image,o=t.options;r.queue.push((function(){a.getImage(e).then((function(t){r._add(t,r._handleOps(t,Object(n.b)(!0,i,o)))})).catch(r.fn.error)}))})),this},t.prototype._add=function(t,e){var r,i=e.crop,o=e.pos,u=e.width;0===u&&Object(n.j)("the width of mc-element is zero");var s,h,f,d,l=Object(n.e)(t),p=l.iw,g=l.ih,v=i.width,y=i.height,b=i.radius;(v!==p||y!==g||b>0)&&(t=c(t,i).cvs);var x,m,w,j,_,O,k=v/y,I=p>g?p/g:g/p,C=1.4*I>5?5:1.4*I,M=a.create(Math.round(v*C),Math.round(y*C)),S=M[0],P=M[1],q=Object(n.a)()&&(S.width>2096||S.height>2096)?2096:4096,T=k>1?q/S.width:q/S.height;x=-Math.round(v/2),m=-Math.round(y/2),w=v,j=Math.round(v/k),(S.width>q||S.height>q)&&T&&(r=[S.width,S.height,x,m,w,j].map((function(t){return Math.round(t*T)})),S.width=r[0],S.height=r[1],x=r[2],m=r[3],w=r[4],j=r[5]),P.translate(S.width/2,S.height/2),P.rotate(o.rotate),P.drawImage(t,x,m,w,j),f=Math.round(u*C),d=Math.round(f/k),O=(_=(C-1)*u/2)/k,s=Math.round(o.x+f*(1-o.scale)/2-_),h=Math.round(o.y+d*(1-o.scale)/2-O),f*=o.scale,d*=o.scale,this.ctx.drawImage(S,s,h,f,d),this._next()},t.prototype._getRotate=function(t){return n.g.str(t)?parseFloat(t)*Math.PI/180:n.g.num(t)?t*Math.PI/180:0},t.prototype._handleOps=function(t,e){var r,i,o=this.cvs,a=o.width,c=o.height,u=Object(n.e)(t),s=u.iw,h=u.ih,f=s/h,d=Object(n.k)(a,s,e.width,"pos"),l=Object(n.k)(a,s,e.crop.width,"crop"),p=Object(n.k)(c,h,e.crop.height,"crop"),g={width:l,height:p,x:Object(n.k)(s,l,e.crop.x,"crop"),y:Object(n.k)(h,p,e.crop.y,"crop"),radius:Object(n.d)(l,e.crop.radius)};g.x>s&&(g.x=s),g.y>h&&(g.y=h),r=s-g.x,i=h-g.y,g.width>r&&(g.width=r),g.height>i&&(g.height=i);var v=e.pos,y=v.x,b=v.y,x=v.rotate,m=v.scale,w=void 0===m?1:m;return{width:d,crop:g,pos:{x:Object(n.k)(a,d,y,"pos"),y:Object(n.k)(c,d/f,b,"pos"),scale:w,rotate:this._getRotate(x)}}},t.prototype._createStyle=function(t,e){return{font:t+"px "+this._defaultFontFamily,lineHeight:e,color:"#000",type:"fill",lineWidth:1,wordBreak:!0,shadow:{color:null,blur:0,offsetX:0,offsetY:0}}},t.prototype.text=function(t,e){var r=this;void 0===e&&(e={});var i=this.cvs.width/20;return this.queue.push((function(){var o,a=Object(n.b)(!0,{width:300,align:"left",smallStyle:r._createStyle(.8*i,.9*i),normalStyle:r._createStyle(i,1.1*i),largeStyle:r._createStyle(1.3*i,1.4*i),pos:{x:0,y:0,rotate:0}},e),c=r._parse(String(t)),u=0;c.map((function(t){t.size>u&&(u=t.size,o=t.type)}));var s=parseInt(a[o+"Style"].font);s&&a.width<s&&(a.width=s),r._text(c,a),r._resetCtx()._next()})),this},t.prototype._parse=function(t){for(var e=t.split(/<s>|<b>/),r=[],n=0;n<e.length;n++){var i=e[n];if(/<\/s>|<\/b>/.test(i)){var o=/<\/s>/.test(i)?"</s>":"</b>",a=/<\/s>/.test(i)?"small":"large",c=e[n].split(o);r.push({type:a,text:c[0],size:"small"===a?0:2}),c[1]&&r.push({type:"normal",text:c[1],size:1})}else e[n]&&r.push({text:e[n],type:"normal",size:1})}return r},t.prototype._text=function(t,e){var r=this;this.data.textId++,this.data.text[this.data.textId]={};var i,o=e.width=Object(n.k)(this.cvs.width,0,e.width,"pos"),c=1,u=0,s=this._getLineHeight(t,e),h=Object(n.k)(this.cvs.width,o,0,"pos"),f=Object(n.k)(this.cvs.height,0,0,"pos")+s;this.data.text[this.data.textId][c]={data:[],lineWidth:0},t.map((function(t){i=e[t.type+"Style"],r.ctx.font=i.font;var a=r.ctx.measureText(t.text).width,d=t.text.replace(/<br>/g,"|");if(u+a>o||Object(n.f)(d,"|")){i.wordBreak||(d=Object(n.h)(d));for(var l=0,p=d.length;l<p;l++){var g=d[l];if(a=r.ctx.measureText(g).width,!(u+a>o||"|"===g)||(h=u=0,f+=s,c+=1,r.data.text[r.data.textId][c]={data:[],lineWidth:0},"|"!==g))(v=r.data.text[r.data.textId][c]).data.push({context:g,x:h,y:f,style:i,width:a}),h+=a,v.lineWidth=u+=a}}else{var v;(v=r.data.text[r.data.textId][c]).data.push({context:d,x:h,y:f,style:i,width:a}),h+=a,v.lineWidth=u+=a}}));var d=a.create(o,this._getTextRectHeight(c)),l=d[0],p=d[1],g=l.height,v=l.width,y=Object(n.k)(this.cvs.width,v,e.pos.x,"pos"),b=Object(n.k)(this.cvs.height,g,e.pos.y,"pos");Object(n.c)(this.data.text[this.data.textId],(function(t,n){var i=0;n.lineWidth<o&&("center"===e.align?i=(o-n.lineWidth)/2:"right"===e.align&&(i=o-n.lineWidth)),n.data.map((function(t){t.x+=i,r._fillText(p,t)}))})),this.ctx.translate(y+v/2,b+g/2),this.ctx.rotate(this._getRotate(e.pos.rotate)),this.ctx.drawImage(l,-v/2,-g/2,v,g)},t.prototype._getLineHeight=function(t,e){var r,n=0;return t.map((function(t){(r=e[t.type+"Style"].lineHeight)>n&&(n=r)})),n},t.prototype._fillText=function(t,e){var r=e.context,i=e.x,o=e.y,a=e.style,c=a.align,u=a.lineWidth,s=a.shadow,h=a.font,f=a.gradient,d=a.lineHeight,l=s.color,p=s.blur,g=s.offsetX,v=s.offsetY;if(t.font=h,t.textAlign=c,t.textBaseline="alphabetic",t.lineWidth=u,t.shadowColor=l,t.shadowBlur=p,t.shadowOffsetX=g,t.shadowOffsetY=v,f){var y=f.type,b=f.colorStop,x=void 0,m=void 0,w=void 0,j=void 0;1===y?(x=i,m=o,w=i+e.width,j=o):(x=i,m=o-d,w=i,j=o);var _=t.createLinearGradient(x,m,w,j),O=b.length||0;Object(n.c)(b,(function(t,e){_.addColorStop(1/O*(+t+1),e)})),t[a.type+"Style"]=_}else t[a.type+"Style"]=a.color;t[a.type+"Text"](r,i,o),this._resetCtx()},t.prototype._getTextRectHeight=function(t){var e=this.data.text[this.data.textId][t].data[0];return e.y+e.style.lineHeight},t.prototype.draw=function(t){var e=this;return void 0===t&&(t={}),new Promise((function(r,i){var o={type:"jpeg",quality:.9,exportType:"base64",success:function(t){},error:function(t){}};n.g.fn(t)?o.success=t:"jpg"===(o=Object(n.b)(!0,o,t)).type&&(o.type="jpeg"),e.fn.error=function(t){o.error(t),i(t)},e.fn.success=function(){"canvas"===o.exportType?(o.success(e.cvs),r(e.cvs)):setTimeout((function(){var t=e.cvs.toDataURL("image/"+o.type,o.quality);o.success(t),r(t)}),0)},e._next()}))},t.prototype._next=function(){if(this.queue.length>0){this.ctx.save();var t=this.queue.shift();t&&t(),this.ctx.restore()}else this.fn.success()},t.prototype.clear=function(){return this.ctx.clearRect(0,0,this.cvs.width,this.cvs.height),this},t}();
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function s(t,e,r,n){return new(r||(r=Promise))((function(i,o){function a(t){try{u(n.next(t))}catch(t){o(t)}}function c(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,c)}u((n=n.apply(t,e||[])).next())}))}function h(t,e){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}Object.create;function f(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;var n=Array(t),i=0;for(e=0;e<r;e++)for(var o=arguments[e],a=0,c=o.length;a<c;a++,i++)n[i]=o[a];return n}Object.create;var d=r(1),l=function(){function t(t){var e=this;this.isFirst=!0,this.queue=[],this._next=function(t){if(e.isFirst||(t=e.after(t)),e.queue.length>0){var r=e.queue.shift();r&&(t=e.before(t),r(e._next,t),e.isFirst=!1)}else e.end(t),e.queue=[]};var r=t||{},n=r.before,i=void 0===n?function(t){return t}:n,o=r.after,a=void 0===o?function(t){return t}:o;this.before=i,this.after=a}return t.prototype.push=function(t){d.a.fn(t)&&this.queue.push(t)},t.prototype.perform=function(t,e){this.end=t,this._next(e)},t}();!function(){function t(){this._queue=new l}t.prototype.line=function(t){var e=this;return this._queue.push((function(r,n){setTimeout((function(){return s(e,void 0,void 0,(function(){var e;return h(this,(function(i){return e=t(n),d.a.promise(e)?e.then(r):r(e),[2]}))}))}),0)})),this},t.prototype.start=function(t,e){this._queue.perform(t,e)}}();function p(t){return(p="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)}var g=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],v=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];function y(t,e,r,n,i){if("string"==typeof t&&(t=document.getElementById(t)),!t||"object"!==p(t)||!("getContext"in t))throw new TypeError("Expecting canvas with `getContext` method in processCanvasRGB(A) calls!");var o=t.getContext("2d");try{return o.getImageData(e,r,n,i)}catch(t){throw new Error("unable to access image data: "+t)}}function b(t,e,r,n,i,o){if(!(isNaN(o)||o<1)){o|=0;var a=y(t,e,r,n,i);a=function(t,e,r,n,i,o){var a,c,u,s,h,f,d,l,p,y,b,m,w,j,_,O,k,I,C,M,S,P,q,T,R,D=t.data,N=2*o+1,W=n-1,B=i-1,A=o+1,E=A*(A+1)/2,H=new x,F=H;for(u=1;u<N;u++)F=F.next=new x,u===A&&(R=F);F.next=H;var z=null,L=null;d=f=0;var G=g[o],Y=v[o];for(c=0;c<i;c++){for(O=k=I=C=l=p=y=b=0,m=A*(M=D[f]),w=A*(S=D[f+1]),j=A*(P=D[f+2]),_=A*(q=D[f+3]),l+=E*M,p+=E*S,y+=E*P,b+=E*q,F=H,u=0;u<A;u++)F.r=M,F.g=S,F.b=P,F.a=q,F=F.next;for(u=1;u<A;u++)s=f+((W<u?W:u)<<2),l+=(F.r=M=D[s])*(T=A-u),p+=(F.g=S=D[s+1])*T,y+=(F.b=P=D[s+2])*T,b+=(F.a=q=D[s+3])*T,O+=M,k+=S,I+=P,C+=q,F=F.next;for(z=H,L=R,a=0;a<n;a++)D[f+3]=q=b*G>>Y,0!==q?(q=255/q,D[f]=(l*G>>Y)*q,D[f+1]=(p*G>>Y)*q,D[f+2]=(y*G>>Y)*q):D[f]=D[f+1]=D[f+2]=0,l-=m,p-=w,y-=j,b-=_,m-=z.r,w-=z.g,j-=z.b,_-=z.a,s=d+((s=a+o+1)<W?s:W)<<2,O+=z.r=D[s],k+=z.g=D[s+1],I+=z.b=D[s+2],C+=z.a=D[s+3],l+=O,p+=k,y+=I,b+=C,z=z.next,m+=M=L.r,w+=S=L.g,j+=P=L.b,_+=q=L.a,O-=M,k-=S,I-=P,C-=q,L=L.next,f+=4;d+=n}for(a=0;a<n;a++){for(k=I=C=O=p=y=b=l=0,m=A*(M=D[f=a<<2]),w=A*(S=D[f+1]),j=A*(P=D[f+2]),_=A*(q=D[f+3]),l+=E*M,p+=E*S,y+=E*P,b+=E*q,F=H,u=0;u<A;u++)F.r=M,F.g=S,F.b=P,F.a=q,F=F.next;for(h=n,u=1;u<=o;u++)f=h+a<<2,l+=(F.r=M=D[f])*(T=A-u),p+=(F.g=S=D[f+1])*T,y+=(F.b=P=D[f+2])*T,b+=(F.a=q=D[f+3])*T,O+=M,k+=S,I+=P,C+=q,F=F.next,u<B&&(h+=n);for(f=a,z=H,L=R,c=0;c<i;c++)D[(s=f<<2)+3]=q=b*G>>Y,q>0?(q=255/q,D[s]=(l*G>>Y)*q,D[s+1]=(p*G>>Y)*q,D[s+2]=(y*G>>Y)*q):D[s]=D[s+1]=D[s+2]=0,l-=m,p-=w,y-=j,b-=_,m-=z.r,w-=z.g,j-=z.b,_-=z.a,s=a+((s=c+A)<B?s:B)*n<<2,l+=O+=z.r=D[s],p+=k+=z.g=D[s+1],y+=I+=z.b=D[s+2],b+=C+=z.a=D[s+3],z=z.next,m+=M=L.r,w+=S=L.g,j+=P=L.b,_+=q=L.a,O-=M,k-=S,I-=P,C-=q,L=L.next,f+=n}return t}(a,0,0,n,i,o),t.getContext("2d").putImageData(a,e,r)}}var x=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.r=0,this.g=0,this.b=0,this.a=0,this.next=null};function m(t,e){void 0===e&&(e=20);var r=t.width,n=t.height,i=t.getContext("2d");return b(t,0,0,r,n,e),[t,i]}function w(t,e){void 0===e&&(e="hor");var r,n,i,o,a=t.width,c=t.height,u=t.getContext("2d"),s=u.getImageData(0,0,a,c).data,h=u.createImageData(a,c),f=h.data;for(r=0;r<c;r++)for(n=0;n<a;n++)i=4*(r*a+n),f[o="hor"===e?4*(r*a+(a-n-1)):4*((c-r-1)*a+n)]=s[i],f[o+1]=s[i+1],f[o+2]=s[i+2],f[o+3]=s[i+3];return u.putImageData(h,0,0),[t,u]}function j(t){var e,r,n=t.width,i=t.height,o=t.getContext("2d"),a=o.getImageData(0,0,n,i).data,c=o.createImageData(n,i),u=c.data;for(e=0;e<a.length;e+=4)r=.3*a[e]+.59*a[e+1]+.11*a[e+2],u[e]=u[e+1]=u[e+2]=r,u[e+3]=a[e+3];return o.putImageData(c,0,0),[t,o]}function _(t,e){void 0===e&&(e=10);var r,n,i,o,a,c,u,s,h,f,d,l,p,g,v,y=t.width,b=t.height,x=t.getContext("2d"),m=x.getImageData(0,0,y,b).data,w=x.createImageData(y,b),j=w.data,_=Math.ceil(y/e),O=Math.ceil(b/e);for(r=0;r<O;r++)for((c=(a=r*e)+e)>b&&(c=b),n=0;n<_;n++){for((o=(i=n*e)+e)>y&&(o=y),l=p=g=v=0,d=(o-i)*(c-a),s=a;s<c;s+=1)for(h=s*y,u=i;u<o;u+=1)l+=m[f=h+u<<2],p+=m[f+1],g+=m[f+2],v+=m[f+3];for(l=l/d+.5|0,p=p/d+.5|0,g=g/d+.5|0,v=v/d+.5|0,s=a;s<c;s++)for(h=s*y,u=i;u<o;u++)j[f=h+u<<2]=l,j[f+1]=p,j[f+2]=g,j[f+3]=v}return x.putImageData(w,0,0),[t,x]}function O(t,e,r){void 0===e&&(e=2),void 0===r&&(r=32);var n,i,o,a,c,u,s,h,f,d,l,p,g,v,y,b,x,m,w=t.width,j=t.height,_=t.getContext("2d"),O=_.getImageData(0,0,w,j).data,k=_.createImageData(w,j),I=k.data,C=[],M=[],S=[],P=[],q=[],T=[],R=0;for(u=0;u<j;u++)for(c=0;c<w;c++){for(s=0;s<r;s++)C[s]=M[s]=S[s]=P[s]=q[s]=T[s]=0;for(h=-e;h<=e;h++)if(!((n=u+h)<0||n>=j))for(o=n*w,f=-e;f<=e;f++)(i=c+f)<0||i>=w||(d=O[a=o+i<<2],v=(l=O[a+1])*r>>8,y=(p=O[a+2])*r>>8,P[g=d*r>>8]+=d,q[v]+=l,T[y]+=p,C[g]+=1,M[v]+=1,S[y]+=1);for(b=x=m=0,s=1;s<r;s++)C[s]>C[b]&&(b=s),M[s]>M[x]&&(x=s),S[s]>S[m]&&(m=s);I[R]=P[b]/C[b]|0,I[R+1]=q[x]/M[x]|0,I[R+2]=T[m]/S[m]|0,I[R+3]=O[R+3],R+=4}return _.putImageData(k,0,0),[t,_]}var k=function(){function t(t){this._image=t,this._queue=new l,this.clear()}return t.prototype.clear=function(){return this._getImage()._drawCanvas(),this},t.prototype._drawCanvas=function(){return this._run((function(t){var e=Object(n.e)(t),r=e.iw,i=e.ih,o=a.create(r,i),c=o[0],u=o[1];return u.drawImage(t,0,0,r,i),{cvs:c,ctx:u}}))},t.prototype._getImage=function(){var t=this;return this._run((function(){return new Promise((function(e){return s(t,void 0,void 0,(function(){var t=this;return h(this,(function(r){return n.g.str(this._image)?a.getImage(this._image).then((function(r){return e(t._image=r)})).catch(this._error):e(this._image),[2]}))}))}))}))},t.prototype._run=function(t){var e=this;return this._queue.push((function(r,i){setTimeout((function(){return s(e,void 0,void 0,(function(){var e;return h(this,(function(o){return e=t(i),n.g.promise(e)?e.then(r):r(e),[2]}))}))}),0)})),this},t.prototype.draw=function(t){var e=this;return void 0===t&&(t={}),new Promise((function(r,i){var o={type:"jpeg",quality:1,exportType:"base64",success:function(t){},error:function(t){}};n.g.fn(t)?o.success=t:"jpg"===(o=Object(n.b)(!0,o,t)).type&&(o.type="jpeg");var a=o.exportType,c=o.type,u=o.quality,s=o.success,h=o.error,f=function(t){s(t),r(t),e.clear()};e._error=function(t){h(t),i(t)},e._queue.perform((function(t){var e=t.cvs,r=t.quality;"canvas"===a?f(e):setTimeout((function(){var t=e.toDataURL("image/"+c,r||u);f(t)}),0)}))}))},t.prototype.crop=function(t){return void 0===t&&(t={}),this._run((function(e){return c(e.cvs,t)}))},t.prototype.compress=function(t){return void 0===t&&(t={}),this._run((function(e){var r=e.cvs,i=e.ctx,o=t.quality,c=t.width,u=t.height,s=r.width/r.height;if(!n.g.num(c)&&!n.g.num(u))return{cvs:r,ctx:i,quality:o};n.g.num(c)||(c=u*s),n.g.num(u)||(u=c/s);var h=a.create(c,u),f=h[0],d=h[1];return d.drawImage(r,0,0,c,u),{cvs:f,ctx:d,quality:o}}))},t.prototype.filter=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return this._run((function(r){var n,i,o,a,c,u=r.cvs,s=u,h=r.ctx;switch(t){case"blur":s=(n=m.apply(void 0,f([u],e)))[0],h=n[1];break;case"flip":s=(i=w.apply(void 0,f([u],e)))[0],h=i[1];break;case"gray":s=(o=j(u))[0],h=o[1];break;case"mosaic":s=(a=_.apply(void 0,f([u],e)))[0],h=a[1];break;case"oil":s=(c=O.apply(void 0,f([u],e)))[0],h=c[1]}return{cvs:s,ctx:h}}))},t}();e.default=u}])}));