UNPKG

zan-poster

Version:

通过json在canvas上绘制图像, 基于cax画图框架开发, 本画图组件是json2canvas库的改造、优化版本 (详情查看README.md文档末说明)。

1 lines 39.2 kB
((t,e)=>{"object"==typeof exports&&typeof module<"u"?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=typeof globalThis<"u"?globalThis:t||self).ZanPosterLib=e()})(this,function(){var r,L=function t(e,i){var r=i.length;if(2<=r){for(var h=i.slice(0,r/2),r=i.slice(r/2,r),s=e,a=t(e,h),n=t(e,r),o=[],l=a.length,c=n.length;0<l&&0<c;)s(a[0],n[0])<=0?(o.push(a.shift()),l--):(o.push(n.shift()),c--);return 0<l?o.push.apply(o,a):o.push.apply(o,n),o}return i.slice()},X=function(t,e,i){for(var r=0,h=e.length;r<h&&!(0<t(e[r],i));r++);return r};function t(t){return function(){return t}}function e(t){this.config=t=t||{},this.config.childrenPropertyName=t.childrenPropertyName||"children",this.config.modelComparatorFn=t.modelComparatorFn}function a(t,e){this.config=t,this.model=e,this.children=[]}function h(t){return"function"==typeof t.config.modelComparatorFn}function i(t,e,i){var r;if(!(e instanceof a))throw new TypeError("Child must be of type Node.");if((e.parent=t).model[t.config.childrenPropertyName]instanceof Array||(t.model[t.config.childrenPropertyName]=[]),h(t))r=X(t.config.modelComparatorFn,t.model[t.config.childrenPropertyName],e.model),t.model[t.config.childrenPropertyName].splice(r,0,e.model),t.children.splice(r,0,e);else if(void 0===i)t.model[t.config.childrenPropertyName].push(e.model),t.children.push(e);else{if(i<0||i>t.children.length)throw new Error("Invalid index.");t.model[t.config.childrenPropertyName].splice(i,0,e.model),t.children.splice(i,0,e)}return e}function s(){var t={};if(1===arguments.length?"function"==typeof arguments[0]?t.fn=arguments[0]:t.options=arguments[0]:2===arguments.length?"function"==typeof arguments[0]?(t.fn=arguments[0],t.ctx=arguments[1]):(t.options=arguments[0],t.fn=arguments[1]):(t.options=arguments[0],t.fn=arguments[1],t.ctx=arguments[2]),t.options=t.options||{},t.options.strategy||(t.options.strategy="pre"),r[t.options.strategy])return t;throw new Error("Unknown tree walk strategy. Valid strategies are 'pre' [default], 'post' and 'breadth'.")}r={},e.prototype.parse=function(t){var e,i,r,h,s;if(!(t instanceof Object))throw new TypeError("Model must be of type object.");if(r=new a(this.config,t),t[this.config.childrenPropertyName]instanceof Array)for(this.config.modelComparatorFn&&(t[this.config.childrenPropertyName]=L(this.config.modelComparatorFn,t[this.config.childrenPropertyName])),e=0,i=t[this.config.childrenPropertyName].length;e<i;e++)h=r,((s=this.parse(t[this.config.childrenPropertyName][e])).parent=h).children.push(s);return r},a.prototype.isRoot=function(){return void 0===this.parent},a.prototype.hasChildren=function(){return 0<this.children.length},a.prototype.addChild=function(t){return i(this,t)},a.prototype.addChildAtIndex=function(t,e){if(h(this))throw new Error("Cannot add child at index when using a comparator function.");return i(this,t,e)},a.prototype.setIndex=function(t){if(h(this))throw new Error("Cannot set node index when using a comparator function.");if(this.isRoot()){if(0===t)return this;throw new Error("Invalid index.")}if(t<0||t>=this.parent.children.length)throw new Error("Invalid index.");var e=this.parent.children.indexOf(this);return this.parent.children.splice(t,0,this.parent.children.splice(e,1)[0]),this.parent.model[this.parent.config.childrenPropertyName].splice(t,0,this.parent.model[this.parent.config.childrenPropertyName].splice(e,1)[0]),this},a.prototype.getPath=function(){var i=[];return function t(e){i.unshift(e),e.isRoot()||t(e.parent)}(this),i},a.prototype.getIndex=function(){return this.isRoot()?0:this.parent.children.indexOf(this)},a.prototype.walk=function(){var t=s.apply(this,arguments);r[t.options.strategy].call(this,t.fn,t.ctx)},r.pre=function t(e,i){for(var r=e.call(i,this),h=0,s=this.children.length;h<s;h++){if(!1===r)return!1;r=t.call(this.children[h],e,i)}return r},r.post=function t(e,i){for(var r=0,h=this.children.length;r<h;r++)if(!1===t.call(this.children[r],e,i))return!1;return e.call(i,this)},r.breadth=function(h,s){var a=[this];!function t(){var e,i,r;if(0!==a.length){for(e=0,i=(r=a.shift()).children.length;e<i;e++)a.push(r.children[e]);!1!==h.call(s,r)&&t()}}()},a.prototype.all=function(){var e=[],i=s.apply(this,arguments);return i.fn=i.fn||t(!0),r[i.options.strategy].call(this,function(t){i.fn.call(i.ctx,t)&&e.push(t)},i.ctx),e},a.prototype.first=function(){var e,i=s.apply(this,arguments);return i.fn=i.fn||t(!0),r[i.options.strategy].call(this,function(t){if(i.fn.call(i.ctx,t))return e=t,!1},i.ctx),e},a.prototype.drop=function(){var t;return this.isRoot()||(t=this.parent.children.indexOf(this),this.parent.children.splice(t,1),this.parent.model[this.config.childrenPropertyName].splice(t,1),this.parent=void 0,delete this.parent),this};var n=(n=e)&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n;let o=null,Y=(typeof wx<"u"&&(wx.getSharedCanvas?o=wx.getSharedCanvas():wx.createCanvas&&(o=wx.createCanvas())),o),c=.017453292519943295,R=2*Math.PI;class l{constructor(t,e,i,r,h,s){return this.a=t??1,this.b=e||0,this.c=i||0,this.d=r??1,this.tx=h||0,this.ty=s||0,this}identity(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this}appendTransform(t,e,i,r,h,s,a,n,o){var l,h=h%360?(h=h*c,l=Math.cos(h),Math.sin(h)):(l=1,0);return s||a?(s*=c,a*=c,this.append(Math.cos(a),Math.sin(a),-Math.sin(s),Math.cos(s),t,e),this.append(l*i,h*i,-h*r,l*r,0,0)):this.append(l*i,h*i,-h*r,l*r,t,e),(n||o)&&(this.tx-=n*this.a+o*this.c,this.ty-=n*this.b+o*this.d),this}append(t,e,i,r,h,s){var a=this.a,n=this.b,o=this.c,l=this.d;return this.a=t*a+e*o,this.b=t*n+e*l,this.c=i*a+r*o,this.d=i*n+r*l,this.tx=h*a+s*o+this.tx,this.ty=h*n+s*l+this.ty,this}initialize(t,e,i,r,h,s){return this.a=t,this.b=e,this.c=i,this.d=r,this.tx=h,this.ty=s,this}setValues(t,e,i,r,h,s){return this.a=t??1,this.b=e||0,this.c=i||0,this.d=r??1,this.tx=h||0,this.ty=s||0,this}invert(){var t=this.a,e=this.b,i=this.c,r=this.d,h=this.tx,s=t*r-e*i;return this.a=r/s,this.b=-e/s,this.c=-i/s,this.d=t/s,this.tx=(i*this.ty-r*h)/s,this.ty=-(t*this.ty-e*h)/s,this}copy(t){return this.setValues(t.a,t.b,t.c,t.d,t.tx,t.ty)}}l.decompose=function(t,e,i,r,h,s,a){var n=-Math.atan2(-i,r),o=Math.atan2(e,t),l=Math.abs(n+o);l<1e-5||Math.abs(R-l)<1e-5?(a.rotation=o,t<0&&0<=r&&(a.rotation+=a.rotation<=0?Math.PI:-Math.PI),a.skewX=a.skewY=0):(a.rotation=0,a.skewX=n,a.skewY=o),a.scaleX=Math.sqrt(t*t+e*e),a.scaleY=Math.sqrt(i*i+r*r),a.x=h,a.y=s};let N={stagePropagationStopped:{}};var d={_nextID:0,get:function(){return d._nextID++}};class p extends class{constructor(){this._listeners=null,this._captureListeners=null}addEventListener(t,e,i){var r=i?this._captureListeners=this._captureListeners||{}:this._listeners=this._listeners||{},h=r[t];return h&&this.removeEventListener(t,e,i),(h=r[t])?h.push(e):r[t]=[e],e}removeEventListener(t,i,e){var r,e=e?this._captureListeners:this._listeners;e&&(r=e[t])&&r.every((t,e)=>t!==i||(r.splice(e,1),!1))}on(t,e,i){this.addEventListener(t,e,i)}off(t,e,i){this.removeEventListener(t,e,i)}dispatchEvent(t){N.stagePropagationStopped[t.type]=!1;for(var e=this,i=[e];e.parent;)i.push(e=e.parent);for(var r=i.length,h=r-1;0<=h&&!t.propagationStopped;h--)i[h]._dispatchEvent(t,0);for(h=0;h<r&&!t.propagationStopped;h++)i[h]._dispatchEvent(t,1)}_dispatchEvent(e,t){var i;(e.target=this)._captureListeners&&0===t&&(i=this._captureListeners[e.type])&&i.forEach(t=>{t.call(this,e)}),this._listeners&&1===t&&(i=this._listeners[e.type])&&i.forEach(t=>{t.call(this,e)})}}{constructor(){super(),this.alpha=this.complexAlpha=this.scaleX=this.scaleY=1,this.x=this.y=this.rotation=this.skewX=this.skewY=this.originX=this.originY=0,this.cursor=null,this.visible=!0,this._matrix=new l,this._hitMatrix=new l,this.id=d.get(),this.clipGraphics=null,this.clipRuleNonzero=!0,this.fixed=!1,this.shadow=null,this.compositeOperation=null,this.absClipGraphics=null,this.absClipRuleNonzero=!0,this.cacheUpdating=!1;try{Object.defineProperties(this,{stage:{get:this._getStage},scale:{get:function(){return this.scaleX},set:function(t){this.scaleX=this.scaleY=t}}})}catch{}this.hitBox=null}isVisible(){return this.visible&&0<this.alpha&&0!==this.scaleX&&0!==this.scaleY}initAABB(){if(void 0!==this.width&&void 0!==this.height||this.hitBox){let t,e,i=this.width,r=this.height,h=this._matrix,s=h.tx,a=h.ty,n=(this.hitBox&&(i=this.hitBox[2],r=this.hitBox[3],s=this.hitBox[0]*h.a+this.hitBox[1]*h.c+s,a=this.hitBox[0]*h.b+this.hitBox[1]*h.d+a),i*h.a),o=i*h.b,l=r*h.c,c=r*h.d,d=s,p=s,u=a,g=a;(t=n+s)<d?d=t:t>p&&(p=t),(t=n+l+s)<d?d=t:t>p&&(p=t),(t=l+s)<d?d=t:t>p&&(p=t),(e=o+a)<u?u=e:e>g&&(g=e),(e=o+c+a)<u?u=e:e>g&&(g=e),(e=c+a)<u?u=e:e>g&&(g=e),this.AABB=[d,u,p-d,g-u],this.rectPoints=[{x:s,y:a},{x:n+s,y:o+a},{x:n+l+s,y:o+c+a},{x:l+s,y:c+a}]}}destroy(){this.parent.remove(this)}hover(t,e,i){this.on("mouseover",t),this.on("mouseout",e),i&&this.on("mousemove",i)}clip(t,e){this.clipGraphics=t,this.clipRuleNonzero=!e}unclip(){this.clipGraphics=null}absClip(t,e){this.absClipGraphics=t,this.absClipRuleNonzero=!e}unAbsClip(){this.absClipGraphics=null}cache(t,e,i,r,h,s){this._cacheData={x:t||0,y:e||0,width:i||this.width,height:r||this.height,scale:h||1},this.cacheUpdating=s,this.cacheCanvas||(typeof wx<"u"&&wx.createCanvas?this.cacheCanvas=wx.createCanvas():this.cacheCanvas=document.createElement("canvas"),this.cacheCtx=this.cacheCanvas.getContext("2d")),this.cacheCanvas.width=this._cacheData.width*this._cacheData.scale,this.cacheCanvas.height=this._cacheData.height*this._cacheData.scale,this._readyToCache=!0}uncache(){this.cacheCanvas=null}filter(t,e){e=Object.assign({},{x:0,y:0,width:this.width,height:this.height},e),this.cache(e.x,e.y,e.width,e.height),this._readyToFilter=!0,this._filterName=t}setTransform(t,e,i,r,h,s,a,n,o){this.x=t||0,this.y=e||0,this.scaleX=i??1,this.scaleY=r??1,this.rotation=h||0,this.skewX=s||0,this.skewY=a||0,this.originX=n||0,this.originY=o||0}setMatrix(t,e,i,r,h,s){l.decompose(t,e,i,r,h,s,this)}unfilter(){this.uncache()}_getStage(){for(var t=this;t.parent;)t=t.parent;return"Stage"===t.___instanceof?t:null}}class u extends p{constructor(t){super(t),this.children=[]}add(t){var e=arguments.length;for(let t=0;t<e;t++){var i=arguments[t],r=i.parent;r&&r.removeChildAt(r.children.indexOf(i)),this.children.push(i),i.parent=this}}addChildAt(t,e){var i=t.parent;i&&i.removeChildAt(i.children.indexOf(t)),(t.parent=this).children.splice(e,0,t)}removeChildAt(t){var e=this.children[t];e&&(e.parent=null),this.children.splice(t,1)}replace(t,e){e=e.parent.children.indexOf(e);this.removeChildAt(e),this.addChildAt(t,e)}remove(e){var i=arguments.length;let r=this.children.length;for(let t=0;t<i;t++)for(let t=0;t<r;t++)e.id===this.children[t].id&&(e.parent=null,this.children.splice(t,1),t--,r--)}empty(){this.children.forEach(t=>{t.parent=null}),this.children.length=0}destroy(){this.empty(),this.parent&&super.destroy()}}let D={globalAlpha:!0,filter:!0,fillStyle:!0,strokeStyle:!0,lineWidth:!0,lineCap:!0,lineDashOffset:!0,lineJoin:!0,miterLimit:!0};class g extends p{constructor(){super(),this.cmds=[],this.currentGradient=null}globalAlpha(){return this.cmds.push(["globalAlpha",arguments]),this}filter(){return this.cmds.push(["filter",arguments]),this}filter(...t){return this.cmds.push(["filter",t]),this}clearRect(...t){return this.cmds.push(["clearRect",t]),this}rect(...t){return this.cmds.push(["rect",t]),this}clear(){return this.cmds.length=0,this}setLineDash(...t){return this.cmds.push(["setLineDash",t]),this}strokeRect(...t){return this.cmds.push(["strokeRect",t]),this}fillRect(...t){return this.cmds.push(["fillRect",t]),this}beginPath(...t){return this.cmds.push(["beginPath",t]),this}arc(...t){return this.cmds.push(["arc",t]),this}closePath(...t){return this.cmds.push(["closePath",t]),this}fillStyle(...t){return this.cmds.push(["fillStyle",t]),this}fill(...t){return this.cmds.push(["fill",t]),this}strokeStyle(...t){return this.cmds.push(["strokeStyle",t]),this}lineWidth(...t){return this.cmds.push(["lineWidth",t]),this}lineCap(...t){return this.cmds.push(["lineCap",t]),this}lineDashOffset(...t){return this.cmds.push(["lineDashOffset",t]),this}lineJoin(...t){return this.cmds.push(["lineJoin",t]),this}miterLimit(...t){return this.cmds.push(["miterLimit",t]),this}stroke(...t){return this.cmds.push(["stroke",t]),this}moveTo(...t){return this.cmds.push(["moveTo",t]),this}lineTo(...t){return this.cmds.push(["lineTo",t]),this}bezierCurveTo(...t){return this.cmds.push(["bezierCurveTo",t]),this}quadraticCurveTo(...t){return this.cmds.push(["quadraticCurveTo",t]),this}createRadialGradient(...t){return this.cmds.push(["createRadialGradient",t]),this}createLinearGradient(...t){return this.cmds.push(["createLinearGradient",t]),this}addColorStop(...t){return this.cmds.push(["addColorStop",t]),this}fillGradient(){return this.cmds.push(["fillGradient"]),this}arcTo(...t){return this.cmds.push(["arcTo",t]),this}render(i){this.cmds.forEach(t=>{var e=t[0];D[e]?i[e]=t[1][0]:"addColorStop"===e?this.currentGradient&&this.currentGradient.addColorStop(t[1][0],t[1][1]):"fillGradient"===e?i.fillStyle=this.currentGradient:(t=i[e](...t[1]),"createRadialGradient"!==e&&"createLinearGradient"!==e||(this.currentGradient=t))})}}let G="object"==typeof global&&global&&global.Math===Math&&global.Array===Array?global:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:function(){return this}(),f={getImageInWx:function(e,i){!e.includes("https://")&&!e.includes("http://")||/^https?:\/\/tmp\//.test(e)?wx.getImageInfo({src:e,success:t=>{i({img:e,width:t.width,height:t.height})}}):wx.downloadFile({url:e,success:e=>{200===e.statusCode&&wx.getImageInfo({src:e.tempFilePath,success:t=>{i({img:e.tempFilePath,width:t.width,height:t.height})}})}})},root:G,isWeapp:typeof wx<"u"&&wx.getSystemInfo&&typeof Page<"u",isWegame:typeof wx<"u"&&wx.getSystemInfo&&"u"<typeof Page};class m extends p{constructor(t,e){super(),"string"==typeof t?m.cache[t]?(f.isWeapp?(this.img=m.cache[t].img,this.rect=[0,0,m.cache[t].width,m.cache[t].height],this.width=this.rect[2],this.height=this.rect[3]):(this.img=m.cache[t],this.rect=[0,0,this.img.width,this.img.height],this.width=this.img.width,this.height=this.img.height),e&&e.call(this)):(this.img=f.isWegame?wx.createImage():new window.Image,this.img.onload=()=>{this.rect||(this.rect=[0,0,this.img.width,this.img.height]),this.width=this.img.width,this.height=this.img.height,e&&e.call(this),m.cache[t]=this.img},this.img.src=t):(this.img=t,this.rect=[0,0,t.width,t.height],this.width=t.width,this.height=t.height,m.cache[t.src]=t,e&&e.call(this))}clone(t){t=new m(t);return t.x=this.x,t.y=this.y,t.scaleX=this.scaleX,t.scaleY=this.scaleY,t.rotation=this.rotation,t.skewX=this.skewX,t.skewY=this.skewY,t.originX=this.originX,t.originY=this.originY,t.width=this.width,t.height=this.height,t.cursor=this.cursor,t}}m.cache={};let x;f.isWeapp?x=wx.createCanvasContext("measure0"):typeof document<"u"&&(x=document.createElement("canvas").getContext("2d"));class w extends p{constructor(t,e){super(null),this.text=t,this.font=(e=e||{}).font||"10px sans-serif",this.fontSize=e.fontSize||10,this.textAlign=e.textAlign||"left",this.baseline=e.baseline||"top",this.fillStyle=e.fillStyle||e.color,this.lineWidth=e.lineWidth||1,this.strokeStyle=e.strokeStyle}getWidth(){return x||f.isWegame&&(x=wx.createCanvas().getContext("2d")),this.font&&(x.font=this.font),x.measureText(this.text).width}}let y=null;function B(t,e){return y.createImageData(t,e)}function J(t,e){if((e=Math.abs(e))<=1)return t;for(var i=e/2,r=Math.ceil(e)+(1-Math.ceil(e)%2),h=new Float32Array(r),e=(.5+i)/3,s=1/Math.sqrt(2*Math.PI*(e*e)),a=-1/(2*e*e),n=0,o=Math.floor(r/2),l=0;l<r;l++){var c=l-o,c=s*Math.exp(c*c*a);n+=h[l]=c}for(l=0;l<h.length;l++)h[l]/=n;for(var e=((t,e)=>{for(var i=e.length,r=Math.floor(i/2),h=t.data,s=t.width,a=t.height,n=s,o=a,l=(t=B(n,o)).data,c=0;c<o;c++)for(var d=0;d<n;d++){for(var p=c,u=d,g=4*(c*n+d),f=0,m=0,x=0,w=0,y=0;y<i;y++){var v=4*(Math.min(a-1,Math.max(0,p+y-r))*s+u),b=e[y];f+=h[v]*b,m+=h[1+v]*b,x+=h[2+v]*b,w+=h[3+v]*b}l[g]=f,l[1+g]=m,l[2+g]=x,l[3+g]=w+0*(255-w)}return t})(t,i=h),d=i,p=d.length,u=Math.floor(p/2),g=e.data,f=e.width,m=f,x=e.height,w=(e=B(m,x)).data,y=0;y<x;y++)for(var v=0;v<m;v++){for(var b=y,C=v,_=4*(y*m+v),A=0,S=0,M=0,T=0,k=0;k<p;k++){var P=b,I=Math.min(f-1,Math.max(0,C+k-u)),P=4*(P*f+I),I=d[k];A+=g[P]*I,S+=g[1+P]*I,M+=g[2+P]*I,T+=g[3+P]*I}w[_]=A,w[1+_]=S,w[2+_]=M,w[3+_]=T+0*(255-T)}return e}function z(t,e){if("string"==typeof e){var L=e.split("(")[0],i=-1!==(k=(k=e).replace(/(invert)|(brightness)|(blur)|(contrast)|(grayscale)|(sepia)|(threshold)|(gamma)?\(/g,"").replace(")","")).indexOf("%")?Number(k.replace("%",""))/100:-1!==k.indexOf("px")?Number(k.replace("px","")):Number(k);switch(L){case"invert":var r=t,h=i,s=r.data;h=void 0===h?1:h;for(var a=0;a<s.length;a+=4)s[a]=s[a]+h*(255-2*s[a]),s[a+1]=s[a+1]+h*(255-2*s[a+1]),s[a+2]=s[a+2]+h*(255-2*s[a+2]);return r;case"brightness":var r=t,n=255*i-255,o=r.data,X=o.length;for(let t=0;t<X;t+=4)o[t]+=n,o[t+1]+=n,o[t+2]+=n;return r;case"blur":return J(t,i);case"contrast":var l=t,c=255*i-255,d=l.data,Y=d.length,p=259*(c+255)/(255*(259-c));for(let t=0;t<Y;t+=4)d[t]=p*(d[t]-128)+128,d[t+1]=p*(d[t+1]-128)+128,d[t+2]=p*(d[t+2]-128)+128;return l;case"grayscale":var c=t,u=i,g=c.data,R=g.length;for(let t=0;t<R;t+=4){var f=g[t],m=g[t+1],x=g[t+2],w=.2126*f+.7152*m+.0722*x;g[t]=f+(w-f)*u,g[t+1]=m+(w-m)*u,g[t+2]=x+(w-x)*u}return c;case"sepia":var l=t,y=i,v=l.data,N=v.length;for(let t=0;t<N;t+=4){var b=v[t],C=v[t+1],_=v[t+2],D=.349*b+.686*C+.168*_,G=.272*b+.534*C+.131*_;v[t]=b+(.393*b+.769*C+.189*_-b)*y,v[t+1]=C+(D-C)*y,v[t+2]=_+(G-_)*y}return l;case"threshold":var A=t,z=i,S=A.data,H=S.length;for(let t=0;t<H;t+=4){var j=S[t],q=S[t+1],V=S[t+2];S[t]=S[t+1]=S[t+2]=z<=.2126*j+.7152*q+.0722*V?255:0}return A;case"gamma":var A=t,M=i,T=A.data,U=T.length;for(let t=0;t<U;t+=4)T[t]=255*Math.pow(T[t]/255,M),T[t+1]=255*Math.pow(T[t+1]/255,M),T[t+2]=255*Math.pow(T[t+2]/255,M);return A}}else if("colorize"===e.type){var k=t,P=e;const I=k.data,B=I.length,O="#"===P.color.charAt(0)?P.color.substr(1):P.color,W=parseInt(O.substr(0,2),16),F=parseInt(O.substr(2,2),16),E=parseInt(O.substr(4,2),16);for(let t=0;t<B;t+=4)I[t]-=(I[t]-W)*P.amount,I[t+1]-=(I[t+1]-F)*P.amount,I[t+2]-=(I[t+2]-E)*P.amount;return k}var k}typeof document<"u"?y=document.createElement("canvas").getContext("2d"):typeof wx<"u"&&wx.createCanvas&&(y=wx.createCanvas().getContext("2d"));class v extends class{render(){}renderGraphics(){}clear(){}}{constructor(t,e,i,r){super(),this.ctx=3===arguments.length?t:t.getContext("2d",r),this.width=e,this.height=i}clear(t,e,i){t.clearRect(0,0,e,i)}render(e,i,r){var h=i._matrix;if(i.children){var s=i.children.slice(0),a=s.length;for(let t=0;t<a;t++){var n=s[t];h.initialize(1,0,0,1,0,0),h.appendTransform(i.x,i.y,i.scaleX,i.scaleY,i.rotation,i.skewX,i.skewY,i.originX,i.originY),e.save(),this._render(e,n,r?null:h,r,!0),e.restore()}}else this._render(e,i,r?null:h,r)}_render(e,t,i,r,h){if(t.isVisible()){i&&!t.fixed?t._matrix.initialize(i.a,i.b,i.c,i.d,i.tx,i.ty):r&&!t.fixed?t._matrix.initialize(r.scale,0,0,r.scale,-1*r.x,-1*r.y):t._matrix.initialize(1,0,0,1,0,0),i=t._matrix,!h&&r||i.appendTransform(t.x,t.y,t.scaleX,t.scaleY,t.rotation,t.skewX,t.skewY,t.originX,t.originY);var h=t.clipGraphics,h=(h&&(e.beginPath(),h._matrix.copy(i),h._matrix.appendTransform(h.x,h.y,h.scaleX,h.scaleY,h.rotation,h.skewX,h.skewY,h.originX,h.originY),e.setTransform(h._matrix.a,h._matrix.b,h._matrix.c,h._matrix.d,h._matrix.tx,h._matrix.ty),h.render(e),e.clip(t.clipRuleNonzero?"nonzero":"evenodd")),t.absClipGraphics);if(h&&(e.beginPath(),h._matrix.initialize(1,0,0,1,0,0),h._matrix.appendTransform(h.x,h.y,h.scaleX,h.scaleY,h.rotation,h.skewX,h.skewY,h.originX,h.originY),e.setTransform(h._matrix.a,h._matrix.b,h._matrix.c,h._matrix.d,h._matrix.tx,h._matrix.ty),h.render(e),e.clip(t.absClipRuleNonzero?"nonzero":"evenodd")),e.setTransform(i.a,i.b,i.c,i.d,i.tx,i.ty),t._readyToCache||t.cacheUpdating)this.setComplexProps(e,t),t._readyToCache=!1,t.cacheCtx.clearRect(0,0,t.cacheCanvas.width,t.cacheCanvas.height),t.cacheCtx.save(),this.render(t.cacheCtx,t,t._cacheData),t.cacheCtx.restore(),t._readyToFilter&&(t.cacheCtx.putImageData(z(t.cacheCtx.getImageData(0,0,t.cacheCanvas.width,t.cacheCanvas.height),t._filterName),0,0),this._readyToFilter=!1),t.filterStyle&&(e.filter=t.filterStyle),this.drawImage(e,t.cacheCanvas,t._cacheData.x,t._cacheData.y);else if(t.cacheCanvas&&!r)this.setComplexProps(e,t),t.filterStyle&&(e.filter=t.filterStyle),this.drawImage(e,t.cacheCanvas,t._cacheData.x,t._cacheData.y);else if(t instanceof u){var s=t.children.slice(0),a=s.length;for(let t=0;t<a;t++)e.save(),this._render(e,s[t],i),e.restore()}else t instanceof g?(this.setComplexProps(e,t),t.render(e)):t instanceof m&&t.rect?(this.setComplexProps(e,t),h=t.rect,t.filterStyle&&(e.filter=t.filterStyle),this.drawImage(e,t.img,h[0],h[1],h[2],h[3],0,0,h[2],h[3])):t instanceof w&&(this.setComplexProps(e,t),e.font=t.font,e.textAlign=t.textAlign,e.textBaseline=t.baseline,t.fillStyle?(e.fillStyle=t.fillStyle,e.fillText(t.text,0,0,t.maxWidth)):t.strokeStyle?(e.strokeStyle=t.strokeStyle,e.lineWidth=t.lineWidth,e.strokeText(t.text,0,0)):console.warn("The Text element needs to have 【fillStyle】 or 【strokeStyle】 set in order to be rendered."))}}drawImage(t,...e){t.drawImage(...e)}setComplexProps(t,e){e.complexCompositeOperation=t.globalCompositeOperation=this.getCompositeOperation(e),e.complexAlpha=t.globalAlpha=this.getAlpha(e,1),e.complexShadow=this.getShadow(e),e.complexShadow&&(t.shadowColor=e.complexShadow.color,t.shadowOffsetX=e.complexShadow.offsetX,t.shadowOffsetY=e.complexShadow.offsetY,t.shadowBlur=e.complexShadow.blur)}getCompositeOperation(t){return t.compositeOperation||(t.parent?this.getCompositeOperation(t.parent):void 0)}getAlpha(t,e){e=t.alpha*e;return t.parent?this.getAlpha(t.parent,e):e}getShadow(t){return t.shadow||(t.parent?this.getShadow(t.parent):void 0)}}class b{constructor(t,e,i){this.renderList=[],3===arguments.length?(this.renderer=new v(t,e,i),this.width=e,this.height=i):(this.renderer=new v(t),this.width=t.width,this.height=t.height),this.ctx=this.renderer.ctx}update(t){this.renderer.clear(this.ctx,this.width,this.height),this.ctx.draw&&this.ctx.draw(),this.renderer.render(this.ctx,t)}getHitRenderList(t){var e=this.renderList;return e.length=0,this.computeMatrix(t),e}computeMatrix(i){for(let t=0,e=i.children.length;t<e;t++)this._computeMatrix(i.children[t])}initComplex(t){t.complexCompositeOperation=this._getCompositeOperation(t),t.complexAlpha=this._getAlpha(t,1)}_computeMatrix(e,t){if(e.isVisible())if(t&&!e.fixed?e._matrix.initialize(t.a,t.b,t.c,t.d,t.tx,t.ty):e._matrix.initialize(1,0,0,1,0,0),e._matrix.appendTransform(e.x,e.y,e.scaleX,e.scaleY,e.rotation,e.skewX,e.skewY,e.originX,e.originY),e instanceof u){var i=e.children,r=i.length;let t=0;for(;t<r;t++)this._computeMatrix(i[t],e._matrix)}else e.initAABB(),this.renderList.push(e),this.initComplex(e)}_getCompositeOperation(t){return t.compositeOperation||(t.parent?this._getCompositeOperation(t.parent):void 0)}_getAlpha(t,e){e=t.alpha*e;return t.parent?this._getAlpha(t.parent,e):e}isInStage(t){return this.collisionBetweenAABB(t.AABB,this.stage.AABB)}collisionBetweenAABB(t,e){return!(t[0]+t[2]<e[0]||t[0]>e[0]+e[2]||t[1]+t[3]<e[1]||t[1]>e[1]+e[3])}}class H extends u{constructor(t,e,i,r){if(super(),!i)throw new Error("无效canvas元素");this.canvas=i,this.ctx=this.canvas.getContext("2d"),this.renderer=new b(this.ctx,t,e),this._overObject=null,this.hitAABB=!0,this.width=t,this.height=e}update(){this.renderer.update(this)}}class j extends u{constructor(t,e,i,r){super();var h=arguments.length;if(this.isWegame=typeof wx<"u"&&"u"<typeof Page,(this.moveDetectionInterval=0)===h)this.canvas=Y,this.disableMoveDetection=!0,this.moveDetectionInterval=500;else{if(4===h)return new H(t,e,i,r);1===h?this.canvas="string"==typeof t?document.querySelector(t):t:(this.renderTo="string"==typeof i?document.querySelector(i):i,"CANVAS"===this.renderTo.tagName?(this.canvas=this.renderTo,this.canvas.width=t,this.canvas.height=e):(this.canvas=document.createElement("canvas"),this.canvas.width=t,this.canvas.height=e,this.renderTo.appendChild(this.canvas))),this._boundingClientRect=this.canvas.getBoundingClientRect(),this.offset=this._getOffset(this.canvas)}this.renderer=new b(this.canvas,this.canvas.width,this.canvas.height,r),this.borderTopWidth=0,this.borderLeftWidth=0,this.hitAABB=!1,this._overObject=null,this._scaleX=1,this._scaleY=1,this._mouseDownX=0,this._mouseDownY=0,this._mouseUpX=0,this._mouseUpY=0,this.willDragObject=null,this.preStageX=null,this.preStageY=null,this.width=this.canvas.width,this.height=this.canvas.height,this.___instanceof="Stage",this._moveDetectionTime=Date.now()}_getOffset(t){if(this.isWegame)return[0,0];let e=0,i=0;var r;if(document.documentElement.getBoundingClientRect&&t.getBoundingClientRect)return r=t.getBoundingClientRect(),i=r.left,e=r.top,[i+Math.max(document.documentElement.scrollLeft,document.body.scrollLeft),e+Math.max(document.documentElement.scrollTop,document.body.scrollTop)];for(;t.offsetParent;)e+=t.offsetTop,i+=t.offsetLeft,t=t.offsetParent;return[i,e]}update(){this.renderer.update(this)}}class q extends g{draw(){}render(t){this.clear(),this.draw(),super.render(t)}}let C={util:{randomInt:(t,e)=>t+Math.floor(Math.random()*(e-t+1))},Stage:j,WeStage:H,Graphics:g,Bitmap:m,Text:w,Group:u,Shape:q,caxCanvasId:0},_=typeof wx<"u"&&wx.getSystemInfo&&!wx.createCanvas&&wx.createCanvasContext;function V({option:e},t){let i=null;if(e.linearGradient&&e.colors){var r=4<e.linearGradient.length?"createRadialGradient":"createLinearGradient";i=t[r](...e.linearGradient);for(let t=0;t<e.colors.length;t++)i.addColorStop(...e.colors[t])}return i||e.fillStyle}function A(t){return JSON.parse(JSON.stringify(t))}typeof wx<"u"&&wx.getSystemInfo&&wx.createCanvas;let S={shape:"shape",rect:"rect",circle:"circle",line:"line",image:"image",text:"text",group:"group",container:"container"};class M extends C.Graphics{constructor(t,e){var i;super(),(t=Object.assign({font:"10px sans-serif",color:"black",textAlign:"left",baseline:"top",orientation:"horizontal",lineHeight:0},t)).lineHeight||(i=/\d+px/i.exec(t.font))&&(t.lineHeight=Number.parseFloat(i[0])),this.option=t||{},this.text=t.text,this.ctx=(e||document.createElement("canvas")).getContext("2d")}getWidth(t){this.option.font&&(this.ctx.font=this.option.font);t=(this.ctx?.measureText(""+(t||this.text))).width;return t||0}getHeight(){return this.renderBreakLine({ctx:this.ctx,isMeasure:!0})}render(t){t.save(),t.fillStyle=V({option:this.option},this.ctx)||this.option.color,t.font=this.option.font,t.textAlign=this.option.textAlign,t.textBaseline=this.option.baseline,this.option.filter&&(t.filter=this.option.filter),"vertical"===this.option.orientation?this.renderVertical({ctx:t}):this.option.maxWidth&&this.getWidth()>this.option.maxWidth?this.renderBreakLine({ctx:t,symbol:this.option.symbol}):this.fill(t,this.text),t.restore()}fill(e,i="",r=0,h=0){var{actualBoundingBoxDescent:s,width:a}=e.measureText(""+i),n=Math.ceil(s);if(this.option.lineDecoration){var{lineSize:s,lineColor:o,lineOffset:l=0,lineOffsetTop:c=0,lineOffsetLeft:d=0,color:p,lineDecoration:u,lineLevel:g}=this.option;"bottom"!==g&&e.fillText(i,r,h);let t=0;switch(u){case"middle":t=n/2;break;case"bottom":t=n}e.strokeStyle=o||p||"#222",e.lineWidth=s||2,e.beginPath(),e.moveTo(r+d,t+h+(l||c)),e.lineTo(r+a+d,t+h+(l||c)),e.stroke(),"bottom"===g&&e.fillText(i,r,h)}else e.fillText(i,r,h)}renderVertical({ctx:r}){let t=this.text.split(""),h=t.map(t=>this.getWidth(t)),e=r.textAlign,i=r.textBaseline,s=0,a=0,n=this.text;return"left"===e?s+=Math.max.apply(null,h)/2:"right"===e&&(s-=Math.max.apply(null,h)/2),"bottom"===i||"alphabetic"===i||"ideographic"===i?a-=h[0]/2:"top"!==i&&"hanging"!==i||(a+=h[0]/2),r.textAlign="center",r.textBaseline="middle",t.forEach((t,e)=>{var i=t.charCodeAt(0),t=(i<=256?(r.translate(s,a),r.rotate(90*Math.PI/180),r.translate(-s,-a)):0<e&&n.charCodeAt(e-1)<256&&(a+=h[e-1]/2),this.fill(r,t,s,a),i<=256&&(r.translate(s,a),r.rotate(-90*Math.PI/180),r.translate(-s,-a)),h[e]);a+=t}),r.textAlign=e,r.textBaseline=i,a}renderBreakLine({ctx:i,isMeasure:r=!1,symbol:h="..."}){let s="",a=0,n=1,t=[],o=(this.option.text.replace(/\b(?![\u0020-\u002F\u003A-\u003F\u2000-\u206F\u2E00-\u2E7F\u3000-\u303F\uFF00-\uFF1F])|(?=[\u2E80-\u2FFF\u3040-\u9FFF])/g,function(){t.push(arguments[arguments.length-2]-1)}),0);for(let e=0;e<this.option.text.length;e++)if(t.includes(e)&&(o=e),s+=[this.option.text[e]],this.getWidth(s)>this.option.maxWidth||10===this.option.text[e].charCodeAt(0)){let t="";if(s=n===this.option.maxLine&&e!==this.option.text.length?(t=""+s.substring(0,s.length-1)+(h||""),""):o===e||10===this.option.text[e].charCodeAt(0)?(t=s,""):(t=s.substring(0,s.length-(e-o)),s.substring(s.length-(e-o),s.length)),10===this.option.text[e].charCodeAt(0)&&(t=t.substring(0,t.length-1)),r||this.fill(i,t,0,a,!1),n===this.option.maxLine&&e!==this.option.text.length)break;a+=this.option.lineHeight||0,n++}return s&&!r&&this.fill(i,s,0,a,!1),a+this.option.lineHeight-2}}class U extends C.Graphics{constructor(i,t){if(super(),i=Object.assign({lineWidth:1,lt:!0,rt:!0,lb:!0,rb:!0},i),this.option=i,this.ctx=(t||document.createElement("canvas")).getContext("2d"),this.beginPath(),i.type===S.shape)this.setShape();else{switch(i.type){case S.rect:0<i.r?this.setRoundedRect(i):this.rect(0,0,i.width,i.height);break;case S.circle:{let t=1,e=0;i.angle&&(t=i.angle/360),i.sAngle&&(e=i.sAngle/360),this.arc(0,0,i.r,e*Math.PI*2,t*Math.PI*2,!1);break}case S.line:this.moveTo(0,0),this.lineTo(i.long,0)}t=V({option:i},this.ctx);"fillStyle"in i||i.strokeStyle||(i.fillStyle="#FFFFFF"),i.fillStyle?(this.fillStyle(t||i.fillStyle),this.fill()):i.strokeStyle&&(this.lineWidth(i.lineWidth),this.lineCap(i.lineCap),this.strokeStyle(t||i.strokeStyle),this.stroke())}}render(t){t.setLineDash(this.option.lineDash||[]),t.lineDashOffset=this.option.lineDashOffset||0,this.option.filter&&(t.filter=this.option.filter),super.render(t)}setRoundedRect(t){var e=t.r,i=t.r,r=t.width,h=t.width,s=t.height,a=t.height;this.moveTo(i,0),t.rt?this.arcTo(r,0,h,s,e):this.lineTo(r,0),t.rb?this.arcTo(h,s,0,a,e):this.lineTo(h,s),t.lb?this.arcTo(0,a,0,0,e):this.lineTo(0,a),t.lt?this.arcTo(0,0,i,0,e):this.lineTo(0,0)}setShape(){var t,{ctx:e,option:i}=this;e.save();for(t of i.cmds){var[r,h=[]]=t;this[r](...h)}e.restore()}}let $={lfit:0,mfit:2,fill:1,pad:4,fixed:5};function T(t,e={}){if(!t||"string"!=typeof t)return"";if(!/^http/.test(t))return t;var i=((t,i=["x-oss-process=image","imageView2","imageView1","t1t"])=>{var e,r=t.match(/(.*)\?(.*)/)||[];return r.length?(e=(r[2]||"").split("&")||[],{origin:t,url:(r[1]||t).replace(/[!|#].*/,""),params:e.map(e=>(~e.indexOf("source")&&(e=e.match(/source=\d+/)[0]),i.some(t=>~e.indexOf(t))?null:e)).filter(t=>t&&~t.indexOf("=")).join("&")}):{url:t}})(t)||{},e={mode:"fill",limit:0,rate:1,quality:90,webp:!1,...e};let r=!1;var h=[],s=i.params?"&"+i.params:"";let a=[`?t1t=poster${s}&x-oss-process=image/resize`,"m_"+e.mode,"limit_"+e.limit];return"qiniu"===e.oss||/^https?:\/\/xs\.c3tech\.cn/.test(t)?(r=!0,a=[`?t1t=poster${s}&imageView2`,$[e.mode],"ignore-error",1],e.width&&a.push("w",e.width*e.rate),e.height&&a.push("h",e.height*e.rate),e.quality&&a.push("q",e.quality||100),e.webp&&a.push("format","webp")):(e.color&&a.push("color_"+e.color.replace(/^#/,"")),e.width&&a.push("w_"+e.width*e.rate),e.height&&a.push("h_"+e.height*e.rate),e.l&&a.push("l_"+e.l),e.s&&a.push("s_"+e.s),e.p&&a.push("p_"+e.p),e.quality&&h.push("quality,q_"+e.quality),e.blur&&([t=0,s=0]=e.blur||[],h.push(`blur,r_${t},s_`+(s||t))),e.webp&&h.push("format,webp")),""+i.url+a.join(r?"/":",")+"/"+h.join("/")}let k=new n,P=null,I=null,O=null,Q=new Map,W=new Map,Z=[];function K({option:t,parent:e}){var i=new U(t,I);return E(i,t,e),F(i,t),i}function tt({option:t,parent:e}){var i,r=W.get(t.url);return r?(i=r.used?r.clone(r.img):r,r.used=!0,i.scale=t.width/i.width,t.filter&&(i.filterStyle=t.filter),E(i,t,e),F(i,t),r=i.width,e=t.height?t.height/i.scale:i.height,t.isCenter&&i.width!==t.width&&i.height!==t.height&&(i.width>i.height?(i.y=0,i.x+=Math.round((i.width-t.width)/-2)):(i.x=0,i.y+=Math.round((i.height-t.height)/-2))),r=new U({...t,width:r,height:e,r:t.isCircular?t.width/i.scale/2:t.r/i.scale||0,type:"rect",fillStyle:""},I),i.clip(r),i):null}function et({option:t,parent:e}){var i=new M(t,I);return t.shadow&&(i.shadow=t.shadow),E(i,t,e),F(i,t),i}function F(i,r){if(r.rotation){let t,e=0;switch(r.type){case S.image:t=i.width,e=i.height,i.x+=t/2*i.scale,i.y+=e/2*i.scale;break;case S.text:(t=i.getWidth())>r.maxWidth&&(t=r.maxWidth),e=i.getHeight(),i.x+=t/2,i.y+=e/2;break;default:t=r.width,e=r.height,i.x+=t/2,i.y+=e/2}i.originX=t/2,i.originY=e/2,i.rotation=r.rotation}}function E(t,e,i){it({ele:t,option:e,value:"x",parent:i}),it({ele:t,option:e,value:"y",parent:i})}function it({ele:t,option:e,value:i,parent:r}){switch(e[i]){case"center":switch(e.type){case S.image:t[i]=(r.width-t.width*t.scale)/2;break;case S.text:t[i]=(r.width-t.getWidth())/2}break;case"bottom":switch(e.type){case S.image:t[i]=r.height-t.height*t.scale;break;case S.rect:case S.group:t[i]=r.height-e.height}break;default:e.type===S.circle?t[i]=e[i]+e.r:t[i]=e[i]||0}}function rt(t=[]){var e=[];for(let i of Array.isArray(t)?t:[t])Q.get(i.family)||e.push(new Promise(e=>{_?wx.loadFontFace({family:i.family,source:i.source,scopes:["webview","native"],success(){e(i)},fail(t){console.log("loadFontFace: ",i,t),e(i)}}):new FontFace(i.family,`url(${i.source})`).load().then(()=>{e(i)}).catch(t=>{console.log("loadFontFace: ",i,t),e(i)})}));return e}return{draw:async function(t,e,i=null,r,h){let s=k.parse(Object.assign({scale:1},A(t))),a=(I="string"!=typeof e&&Array.isArray(e)?e[0].node:e,t=[s.model.width*s.model.scale,s.model.height*s.model.scale,I],(P=_?new C.Stage(...t,i):new C.Stage(...t)).scale=s.model.scale,O=await(async()=>{let t=await new Promise((t,e)=>{if(!_)return t(!1);var i=_?I.createImage():new Image;i.onload=function(){t(!0)},i.onerror=function(){t(!1)},i.src="data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA"}).then();return function(){return t}})(),null),n=[],o=[];s.all().forEach((e,i)=>{if(e.model.hidden)e.drop();else{let t=e.model;var r,h,s;t.url&&(t=(h=t,s=h.ratio||1,h.height&&"auto"!==h.height?h.url=T(h.url,{width:h.width*s,height:h.height*s,webp:O?.()}):h.url=T(h.url,{mode:"mfit",width:h.width*s,webp:O?.()}),h),o.includes(t.url)||(o.push(t.url),n.push((r=t.url,new Promise(e=>{if(_){let t=I.createImage();t.onload=()=>{new C.Bitmap(t,function(){e({url:r,bitmap:this})})},t.onerror=t=>{console.log(t),e({url:r,bitmap:null})},t.crossOrigin="Anonymous",t.src=r}else{let t=new Image;t.onload=function(){new C.Bitmap(t,function(){e({url:r,bitmap:this})})},t.onerror=function(t){console.error(t),e({url:r,bitmap:null})},t.setAttribute("crossOrigin","Anonymous"),t.src=r}}))))),t.fonts&&Z.push(...rt(t.fonts)),t.type!==S.group&&0!==i||(t.url?(s={type:S.image,width:t.width,height:t.height,url:t.url,decorate:!0},e.addChildAtIndex(k.parse(s),0)):t.fillStyle&&(delete(h=A(t)).children,h.type=S.rect,h.x=0,h.y=0,h.decorate=!0,0===i&&(a=h),e.addChildAtIndex(k.parse(h),0)))}}),Promise.all([...n,...Z]).then(t=>{t.forEach(({url:t,bitmap:e,family:i,source:r})=>{t?W.set(t,e):i&&Q.set(i,r)}),_&&i&&i.data.preload||((t=s).all().reverse().forEach(e=>{let a=e.model,n=0;if(a.type===S.text&&"auto"===a.height&&(i=new M(a,I),n+=i.getHeight()-(a.uiHeight||0)),a.type===S.image&&a.maxHeight&&"auto"===a.height&&(i=W.get(a.url))&&(t=a.width/i.img.width,t=Math.min(Math.round(t*i.img.height),a.maxHeight),a.height=t,n+=t-a.maxHeight),a.type===S.container){a.x=a.x||0,a.y=a.y||0,a.paddingTop=a.paddingTop||0,a.paddingBottom=a.paddingBottom||0,a.paddingLeft=a.paddingLeft||0,a.paddingRight=a.paddingRight||0;var t,i=e.parent&&e.parent.model||{};if(!a.width&&i.width&&(a.width=i.width-2*a.x),a.height&&(n+=a.height+a.paddingTop+a.paddingBottom),a.children.every(t=>t.height)){let h={x:a.paddingLeft,y:a.paddingTop},s=[];a.children.filter(t=>"group"===t.type&&t.children?.length).forEach((t,e)=>{t.x=t.x||0,t.y=t.y||0,t.width=t.width||a.width;var i=t.x+t.width,r=t.y+t.height;0===e&&s.push(r),h.x+i<=a.width||0===e?(t.x=h.x+t.x,t.y=h.y+t.y,h.x+=i):(h.y=s.reduce((t,e)=>t+e,0),s.push(r),h.x=a.paddingLeft,t.x=h.x+t.x,t.y=h.y+t.y,h.x+=t.x+t.width)}),a.height||(a.height=s.reduce((t,e)=>t+e,0)+a.paddingTop+a.paddingBottom,n+=a.height)}a.fillStyle&&(delete(t=A(a)).children,t.type=S.rect,t.x=0,t.y=0,t.height=a.height,t.decorate=!0,a.children.unshift(t))}if(a.type===S.group&&["row","justify","column"].includes(a.display)){let h={x:0,y:0,maxHeight:0,maxWidth:0,index:0},t=null;if(a.children.forEach(e=>{e.decorate&&!t&&(t=e),e.x=e.x||0,e.y=e.y||0;var i=(t=>{var e,i;return t.type!==S.text?t.decorate?{}:{...t}:(i=new M(t,I),e=t.width||Math.round(i.getWidth()),i=Math.round(i.getHeight()),{...t,width:t.maxWidth?Math.min(t.maxWidth,e):e,height:t.height||i||0})})(e)||{};i.x=i.x||0,i.y=i.y||0,e.width=i.width,e.height=i.height;let r=!1;switch(!e.auto||(e.children||[]).filter(t=>!t.decorate).length||e.text||e.url||(r=!0,e={x:0,y:0,width:0,height:0}),a.display){case"justify":case"row":h.index||"justify"!==a.display||(e.x=0),r||(e.x+=h.x,h.x+=i.x+(i.width||0),h.maxHeight=Math.max(i.height,h.maxHeight),h.maxWidth=Math.max(i.width,h.maxWidth),t)||h.index++;break;case"column":{let t=0;r&&(t-=i.height+i.y,n-=i.height),e.y+=h.y+t,h.y+=i.y+(i.height||0)+t,h.maxWidth=Math.max(i.width,h.maxWidth),h.maxHeight=Math.max(i.height,h.maxHeight);break}}}),h.maxWidth&&!a.width&&"container"!==e.parent.model.type&&(a.width=h.maxWidth),a.height||(["row","justify"].includes(a.display)&&h.maxHeight?a.height=h.maxHeight:a.height=h.y),t&&a.height&&a.width&&(t.height=a.height,t.width=a.width),["row","justify"].includes(a.display)&&(["center","right"].includes(a.align)&&a.width&&(a.x="center"===a.align?(a.width-h.x+2*a.x)/2:a.x+a.width-h.x),["middle","bottom"].includes(a.vertical))&&a.height&&a.children?.length){let e=0;a.children.forEach(t=>{switch(a.vertical){case"middle":e=(a.height-t.height)/2;break;case"bottom":e=a.height-t.height}t.y+=e})}["column"].includes(a.display)&&["center","right"].includes(a.horizontal)&&a.width}n&&e.getPath().forEach((t,e)=>{0===e?t.model.height+=n:(e=t.parent).children.slice(t.getIndex()+1,e.children.length).forEach(t=>{t.model.pin||Number.isNaN(Number.parseInt(t.model.y))||"column"===t.parent.model.display||(t.model.y+=n)})})}),t.model.minHeight&&t.model.height<t.model.minHeight&&(t.model.height=t.model.minHeight),!_&&I&&(I.width=s.model.width,I.height=s.model.height),h&&h(s.model),a&&(a.height=s.model.height),P.add(function r({option:t,parent:e}){let h=new C.Group;return t.width&&(h.width=t.width),t.height&&(h.height=t.height),E(h,t,e),t.children&&t.children.forEach(t=>{let e=null,i={option:t,parent:h};switch(t.type){case S.group:case S.container:e=r(i);break;case S.rect:case S.circle:case S.line:case S.shape:e=K(i);break;case S.image:e=tt(i);break;case S.text:e=et(i)}e&&h.add(e)}),h}({option:s.model})),setTimeout(()=>{P.update(),r&&r(s.model)},100))})},clear:function(){W=new Map},loadFonts:rt,imageOSSResize:T}});