@leafer-draw/node 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.min.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var t=require("@leafer/core"),e=require("fs"),n=require("@leafer-ui/draw");function a(t,e,n,a){return new(n||(n=Promise))((function(i,o){function r(t){try{l(a.next(t))}catch(t){o(t)}}function s(t){try{l(a.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,s)}l((a=a.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class i extends t.LeaferCanvasBase{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config),t.Platform.roundRectPatch&&(this.context.__proto__.roundRect=null,t.canvasPatch(this.context.__proto__))}__createView(){this.view=t.Platform.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:n}=this;this.view.width=Math.ceil(t*n),this.view.height=Math.ceil(e*n),this.clientBounds=this.bounds}}const{mineType:o,fileType:r}=t.FileHelper;Object.assign(t.Creator,{canvas:(t,e)=>new i(t,e),image:e=>new t.LeaferImage(e)}),t.Platform.name="node",t.Platform.backgrounder=!0,t.Platform.requestRender=function(t){setTimeout(t,16)},t.defineKey(t.Platform,"devicePixelRatio",{get:()=>1}),t.Platform.conicGradientSupport=!0;class s{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const e=new t.LeafList;return this.__updatedList.list.forEach((t=>{t.leafer&&e.add(t)})),e}return this.__updatedList}constructor(e,n){this.totalTimes=0,this.config={},this.__updatedList=new t.LeafList,this.target=e,n&&(this.config=t.DataHelper.default(n,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(t.RenderEvent.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(e){e.type===t.ChildEvent.ADD?(this.hasAdd=!0,this.__pushChild(e.child)):(this.hasRemove=!0,this.__updatedList.add(e.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,n=e.length;t<n;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new t.WatchEvent(t.WatchEvent.DATA,{updatedList:this.updatedList})),this.__updatedList=new t.LeafList,this.totalTimes++,this.changed=this.hasVisible=this.hasRemove=this.hasAdd=!1}__listenEvents(){this.__eventIds=[this.target.on_([[t.PropertyEvent.CHANGE,this.__onAttrChange,this],[[t.ChildEvent.ADD,t.ChildEvent.REMOVE],this.__onChildEvent,this],[t.WatchEvent.REQUEST,this.__onRquestData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.__updatedList=null)}}const{updateAllMatrix:l,updateBounds:d,updateChange:c}=t.LeafHelper,{pushAllChildBranch:h,pushAllParent:u}=t.BranchHelper;const{worldBounds:f}=t.LeafBoundsHelper;class p{constructor(e){this.updatedBounds=new t.Bounds,this.beforeBounds=new t.Bounds,this.afterBounds=new t.Bounds,e instanceof Array&&(e=new t.LeafList(e)),this.updatedList=e}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,f)}setAfter(){this.afterBounds.setListWithFn(this.updatedList.list,f),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:g,updateAllChange:_}=t.LeafHelper,m=t.Debug.get("Layouter");class y{constructor(e,n){this.totalTimes=0,this.config={},this.__levelList=new t.LeafLevelList,this.target=e,n&&(this.config=t.DataHelper.default(n,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(this.layouting||!this.running)return;const{target:e}=this;this.times=0;try{e.emit(t.LayoutEvent.START),this.layoutOnce(),e.emitEvent(new t.LayoutEvent(t.LayoutEvent.END,this.layoutedBlocks,this.times))}catch(t){m.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?m.warn("layouting"):this.times>3?m.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(t.WatchEvent.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var e;if(!(null===(e=this.__updatedList)||void 0===e?void 0:e.length))return;const n=t.Run.start("PartLayout"),{target:a,__updatedList:i}=this,{BEFORE:o,LAYOUT:r,AFTER:s}=t.LayoutEvent,f=this.getBlocks(i);f.forEach((t=>t.setBefore())),a.emitEvent(new t.LayoutEvent(o,f,this.times)),this.extraBlock=null,i.sort(),function(t,e){let n;t.list.forEach((t=>{n=t.__layout,e.without(t)&&!n.proxyZoom&&(n.matrixChanged?(l(t,!0),e.add(t),t.isBranch&&h(t,e),u(t,e)):n.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),u(t,e)))}))}(i,this.__levelList),function(t){let e,n,a;t.sort(!0),t.levels.forEach((i=>{e=t.levelMap[i];for(let t=0,i=e.length;t<i;t++){if(n=e[t],n.isBranch&&n.__tempNumber){a=n.children;for(let t=0,e=a.length;t<e;t++)a[t].isBranch||d(a[t])}d(n)}}))}(this.__levelList),function(t){t.list.forEach(c)}(i),this.extraBlock&&f.push(this.extraBlock),f.forEach((t=>t.setAfter())),a.emitEvent(new t.LayoutEvent(r,f,this.times)),a.emitEvent(new t.LayoutEvent(s,f,this.times)),this.addBlocks(f),this.__levelList.reset(),this.__updatedList=null,t.Run.end(n)}fullLayout(){const e=t.Run.start("FullLayout"),{target:n}=this,{BEFORE:a,LAYOUT:i,AFTER:o}=t.LayoutEvent,r=this.getBlocks(new t.LeafList(n));n.emitEvent(new t.LayoutEvent(a,r,this.times)),y.fullLayout(n),r.forEach((t=>{t.setAfter()})),n.emitEvent(new t.LayoutEvent(i,r,this.times)),n.emitEvent(new t.LayoutEvent(o,r,this.times)),this.addBlocks(r),t.Run.end(e)}static fullLayout(e){g(e,!0),e.isBranch?t.BranchHelper.updateBounds(e):t.LeafHelper.updateBounds(e),_(e)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:n}=this.extraBlock||(this.extraBlock=new p([]));e.length?n.add(t.__world):n.set(t.__world),e.add(t)}}createBlock(t){return new p(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){this.__eventIds=[this.target.on_([[t.LayoutEvent.REQUEST,this.layout,this],[t.LayoutEvent.AGAIN,this.layoutAgain,this],[t.WatchEvent.DATA,this.__onReceiveWatchData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const w=t.Debug.get("Renderer");class v{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(e,n,a){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=e,this.canvas=n,a&&(this.config=t.DataHelper.default(a,this.config)),this.__listenEvents()}start(){this.running=!0,this.update(!1)}stop(){this.running=!1}update(t=!0){this.changed||(this.changed=t),this.__requestRender()}requestLayout(){this.target.emit(t.LayoutEvent.REQUEST)}checkRender(){if(this.running){const{target:e}=this;e.isApp&&(e.emit(t.RenderEvent.CHILD_START,e),e.children.forEach((t=>{t.renderer.FPS=this.FPS,t.renderer.checkRender()})),e.emit(t.RenderEvent.CHILD_END,e)),this.changed&&this.canvas.view&&this.render(),this.target.emit(t.RenderEvent.NEXT)}}render(e){if(!this.running||!this.canvas.view)return this.update();const{target:n}=this;this.times=0,this.totalBounds=new t.Bounds,w.log(n.innerName,"---\x3e");try{this.emitRender(t.RenderEvent.START),this.renderOnce(e),this.emitRender(t.RenderEvent.END,this.totalBounds),t.ImageManager.clearRecycled()}catch(t){this.rendering=!1,w.error(t)}w.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(e){if(this.rendering)return w.warn("rendering");if(this.times>3)return w.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new t.Bounds,this.renderOptions={},e)this.emitRender(t.RenderEvent.BEFORE),e();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(t.RenderEvent.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(t.RenderEvent.RENDER,this.renderBounds,this.renderOptions),this.emitRender(t.RenderEvent.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;e&&(this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)})))}clipRender(e){const n=t.Run.start("PartRender"),{canvas:a}=this,i=e.getIntersect(a.bounds),o=new t.Bounds(i);a.save(),i.spread(v.clipSpread).ceil(),a.clearWorld(i,!0),a.clipWorld(i,!0),this.__render(i,o),a.restore(),t.Run.end(n)}fullRender(){const e=t.Run.start("FullRender"),{canvas:n}=this;n.save(),n.clear(),this.__render(n.bounds),n.restore(),t.Run.end(e)}__render(e,n){const{canvas:a}=this,i=e.includes(this.target.__world),o=i?{includes:i}:{bounds:e,includes:i};this.needFill&&a.fillWorld(e,this.config.fill),t.Debug.showRepaint&&t.Debug.drawRepaint(a,e),this.target.__render(a,o),this.renderBounds=n=n||e,this.renderOptions=o,this.totalBounds.isEmpty()?this.totalBounds=n:this.totalBounds.add(n),a.updateRender(n)}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:e}=this;if(e){const n=new t.Bounds;n.setList(e),e.length=0,e.push(n)}}__requestRender(){const e=this.target;if(this.requestTime||!e)return;if(e.parentApp)return e.parentApp.requestRender(!1);const n=this.requestTime=Date.now();t.Platform.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-n))),this.requestTime=0,this.checkRender()}))}__onResize(e){if(!this.canvas.unreal){if(e.bigger||!e.samePixelRatio){const{width:n,height:a}=e.old;if(!new t.Bounds(0,0,n,a).includes(this.target.__world)||this.needFill||!e.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new t.Bounds(0,0,1,1)),this.update()}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||w.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(e,n,a){this.target.emitEvent(new t.RenderEvent(e,this.times,n,a))}__listenEvents(){this.__eventIds=[this.target.on_([[t.RenderEvent.REQUEST,this.update,this],[t.LayoutEvent.END,this.__onLayoutEnd,this],[t.RenderEvent.AGAIN,this.renderAgain,this],[t.ResizeEvent.RESIZE,this.__onResize,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}function x(t,e){const n=t.__,{rows:a,decorationY:i}=n.__textDrawData;let o;n.__isPlacehold&&n.placeholderColor&&(e.fillStyle=n.placeholderColor);for(let t=0,n=a.length;t<n;t++)o=a[t],o.text?e.fillText(o.text,o.x,o.y):o.data&&o.data.forEach((t=>{e.fillText(t.char,t.x,o.y)}));if(i){const{decorationColor:t,decorationHeight:o}=n.__textDrawData;t&&(e.fillStyle=t),a.forEach((t=>i.forEach((n=>e.fillRect(t.x,t.y+n,t.width,o)))))}}function b(t,e){t.__.__font?x(t,e):t.__.windingRule?e.fill(t.__.windingRule):e.fill()}function E(t,e,n){switch(e.__.strokeAlign){case"center":B(t,1,e,n);break;case"inside":R(t,"inside",e,n);break;case"outside":e.__.__fillAfterStroke?B(t,2,e,n):R(t,"outside",e,n)}}function B(t,e,n,a){const i=n.__;a.setStroke(!i.__isStrokes&&t,i.strokeWidth*e,i),i.__isStrokes?S(t,!0,n,a):k(n,a)}function R(t,e,n,a){const i=a.getSameCanvas(!0,!0);i.font=n.__.__font,B(t,2,n,i),i.blendMode="outside"===e?"destination-out":"destination-in",x(n,i),i.blendMode="normal",L(a,i,n),i.recycle(n.__nowWorld)}function L(e,n,a){a.__worldFlipped||t.Platform.fullImageShadow?e.copyWorldByReset(n,a.__nowWorld):e.copyWorldToInner(n,a.__nowWorld,a.__layout.renderBounds)}function k(t,e){let n,a=t.__.__textDrawData;const{rows:i,decorationY:o}=a;for(let t=0,a=i.length;t<a;t++)n=i[t],n.text?e.strokeText(n.text,n.x,n.y):n.data&&n.data.forEach((t=>{e.strokeText(t.char,t.x,n.y)}));if(o){const{decorationHeight:t}=a;i.forEach((n=>o.forEach((a=>e.strokeRect(n.x,n.y+a,n.width,t)))))}}function S(t,e,a,i){let o;for(let r=0,s=t.length;r<s;r++)o=t[r],o.image&&n.PaintImage.checkImage(a,i,o,!1)||o.style&&(i.strokeStyle=o.style,o.blendMode?(i.saveBlendMode(o.blendMode),e?k(a,i):i.stroke(),i.restoreBlendMode()):e?k(a,i):i.stroke())}function P(t,e,n){const a=e.__;if(a.__strokeWidth)if(a.__font)E(t,e,n);else switch(a.strokeAlign){case"center":C(t,1,e,n);break;case"inside":!function(t,e,n){n.save(),n.clipUI(e),C(t,2,e,n),n.restore()}(t,e,n);break;case"outside":!function(t,e,n){const a=e.__;if(a.__fillAfterStroke)C(t,2,e,n);else{const{renderBounds:i}=e.__layout,o=n.getSameCanvas(!0,!0);e.__drawRenderPath(o),C(t,2,e,o),o.clipUI(a),o.clearWorld(i),L(n,o,e),o.recycle(e.__nowWorld)}}(t,e,n)}}function C(t,e,a,i){const o=a.__;i.setStroke(!o.__isStrokes&&t,o.__strokeWidth*e,o),o.__isStrokes?S(t,!1,a,i):i.stroke(),o.__useArrow&&n.Paint.strokeArrow(t,a,i)}v.clipSpread=10,Object.assign(t.Creator,{watcher:(t,e)=>new s(t,e),layouter:(t,e)=>new y(t,e),renderer:(t,e,n)=>new v(t,e,n),selector:(t,e)=>{},interaction:(t,e,n,a)=>{}}),t.Platform.layout=y.fullLayout;const{getSpread:A,getOuterOf:T,getByMove:O,getIntersectData:W}=t.BoundsHelper;let I;const{stintSet:D}=t.DataHelper,{hasTransparent:M}=n.ColorConvert;function H(t,e,a){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;let i;const{boxBounds:o}=a.__layout;switch(e.type){case"image":i=n.PaintImage.image(a,t,e,o,!I||!I[e.url]);break;case"linear":i=n.PaintGradient.linearGradient(e,o);break;case"radial":i=n.PaintGradient.radialGradient(e,o);break;case"angular":i=n.PaintGradient.conicGradient(e,o);break;case"solid":const{type:r,color:s,opacity:l}=e;i={type:r,style:n.ColorConvert.string(s,l)};break;default:void 0!==e.r&&(i={type:"solid",style:n.ColorConvert.string(e)})}return i&&("string"==typeof i.style&&M(i.style)&&(i.isTransparent=!0),e.blendMode&&(i.blendMode=e.blendMode)),i}const F={compute:function(t,e){const a=e.__,i=[];let o,r,s=a.__input[t];s instanceof Array||(s=[s]),I=n.PaintImage.recycleImage(t,a);for(let n,a=0,o=s.length;a<o;a++)(n=H(t,s[a],e))&&i.push(n);a["_"+t]=i.length?i:void 0,i.length&&i.every((t=>t.isTransparent))&&(i.some((t=>t.image))&&(o=!0),r=!0),"fill"===t?(D(a,"__isAlphaPixelFill",o),D(a,"__isTransparentFill",r)):(D(a,"__isAlphaPixelStroke",o),D(a,"__isTransparentStroke",r))},fill:function(t,e,n){n.fillStyle=t,b(e,n)},fills:function(t,e,a){let i;for(let o=0,r=t.length;o<r;o++){if(i=t[o],i.image){if(n.PaintImage.checkImage(e,a,i,!e.__.__font))continue;if(!i.style){!o&&i.image.isPlacehold&&e.drawImagePlaceholder(a,i.image);continue}}a.fillStyle=i.style,i.transform?(a.save(),a.transform(i.transform),i.blendMode&&(a.blendMode=i.blendMode),b(e,a),a.restore()):i.blendMode?(a.saveBlendMode(i.blendMode),b(e,a),a.restoreBlendMode()):b(e,a)}},fillPathOrText:b,fillText:x,stroke:P,strokes:function(t,e,n){P(t,e,n)},strokeText:E,drawTextStroke:k,shape:function(t,e,n){const a=e.getSameCanvas(),i=t.__nowWorld;let o,r,s,l,{scaleX:d,scaleY:c}=i;if(d<0&&(d=-d),c<0&&(c=-c),e.bounds.includes(i))l=a,o=s=i;else{const{renderShapeSpread:a}=t.__layout,h=W(a?A(e.bounds,d===c?a*d:[a*c,a*d]):e.bounds,i);r=e.bounds.getFitMatrix(h);let{a:u,d:f}=r;if(r.a<1&&(l=e.getSameCanvas(),t.__renderShape(l,n),d*=u,c*=f),s=T(i,r),o=O(s,-r.e,-r.f),n.matrix){const{matrix:t}=n;r.multiply(t),u*=t.scaleX,f*=t.scaleY}n=Object.assign(Object.assign({},n),{matrix:r.withScale(u,f)})}return t.__renderShape(a,n),{canvas:a,matrix:r,bounds:o,worldCanvas:l,shapeBounds:s,scaleX:d,scaleY:c}}};let U={};const{get:j,rotateOfOuter:Y,translate:G,scaleOfOuter:z,scale:N,rotate:q,skew:X}=t.MatrixHelper;function V(t,e,n,a,i,o,r){const s=j();G(s,e.x+n,e.y+a),N(s,i,o),r&&Y(s,{x:e.x+e.width/2,y:e.y+e.height/2},r),t.transform=s}function Q(t,e,n,a,i,o,r,s){const l=j();r&&q(l,r),s&&X(l,s.x,s.y),i&&N(l,i,o),G(l,e.x+n,e.y+a),t.transform=l}function J(t,e,n,a,i,o,r,s,l,d){const c=j();if(l)if("center"===d)Y(c,{x:n/2,y:a/2},l);else switch(q(c,l),l){case 90:G(c,a,0);break;case 180:G(c,n,a);break;case 270:G(c,0,n)}U.x=e.x+i,U.y=e.y+o,G(c,U.x,U.y),r&&z(c,U,r,s),t.transform=c}const{get:Z,translate:K}=t.MatrixHelper,$=new t.Bounds,tt={},et={};function nt(t,e,n,a){const{changeful:i,sync:o,editing:r}=n;i&&(t.changeful=i),o&&(t.sync=o),r&&(t.editing=r),t.data=at(n,a,e)}function at(e,n,a){e.padding&&(n=$.set(n).shrink(e.padding)),"strench"===e.mode&&(e.mode="stretch");let{width:i,height:o}=a;const{opacity:r,mode:s,align:l,offset:d,scale:c,size:h,rotation:u,skew:f,repeat:p,filters:g}=e,_=n.width===i&&n.height===o,m={mode:s},y="center"!==l&&(u||0)%180==90;let w,v;switch(t.BoundsHelper.set(et,0,0,y?o:i,y?i:o),s&&"cover"!==s&&"fit"!==s?((c||h)&&(t.MathHelper.getScaleData(c,h,a,tt),w=tt.scaleX,v=tt.scaleY),l&&(w&&t.BoundsHelper.scale(et,w,v,!0),t.AlignHelper.toPoint(l,et,n,et,!0,!0))):_&&!u||(w=v=t.BoundsHelper.getFitScale(n,et,"fit"!==s),t.BoundsHelper.put(n,a,l,w,!1,et),t.BoundsHelper.scale(et,w,v,!0)),d&&t.PointHelper.move(et,d),s){case"stretch":_||(i=n.width,o=n.height);break;case"normal":case"clip":(et.x||et.y||w||u||f)&&Q(m,n,et.x,et.y,w,v,u,f);break;case"repeat":(!_||w||u)&&J(m,n,i,o,et.x,et.y,w,v,u,l),p||(m.repeat="repeat");break;default:w&&V(m,n,et.x,et.y,w,v,u)}return m.transform||(n.x||n.y)&&(m.transform=Z(),K(m.transform,n.x,n.y)),w&&"stretch"!==s&&(m.scaleX=w,m.scaleY=v),m.width=i,m.height=o,r&&(m.opacity=r),g&&(m.filters=g),p&&(m.repeat="string"==typeof p?"x"===p?"repeat-x":"repeat-y":"repeat"),m}let it,ot=new t.Bounds;const{isSame:rt}=t.BoundsHelper;function st(t,e,n,a,i,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=a.width/e.pixelRatio,e.__naturalHeight=a.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return i.data||nt(i,a,n,o),!0}function lt(e,n){ht(e,t.ImageEvent.LOAD,n)}function dt(e,n){ht(e,t.ImageEvent.LOADED,n)}function ct(e,n,a){n.error=a,e.forceUpdate("surface"),ht(e,t.ImageEvent.ERROR,n)}function ht(e,n,a){e.hasEvent(n)&&e.emitEvent(new t.ImageEvent(n,a))}function ut(t,e){const{leafer:n}=t;n&&n.viewReady&&(n.renderer.ignore=e)}const{get:ft,scale:pt,copy:gt}=t.MatrixHelper,{ceil:_t,abs:mt}=Math;function yt(e,n,a){let{scaleX:i,scaleY:o}=t.ImageManager.patternLocked?e.__world:e.__nowWorld;const r=i+"-"+o+"-"+a;if(n.patternId===r||e.destroyed)return!1;{i=mt(i),o=mt(o);const{image:e,data:s}=n;let l,d,{width:c,height:h,scaleX:u,scaleY:f,transform:p,repeat:g}=s;u&&(u=mt(u),f=mt(f),d=ft(),gt(d,p),pt(d,1/u,1/f),i*=u,o*=f),i*=a,o*=a,c*=i,h*=o;const _=c*h;if(!g&&_>t.Platform.image.maxCacheSize)return!1;let m=t.Platform.image.maxPatternSize;if(!e.isSVG){const t=e.width*e.height;m>t&&(m=t)}_>m&&(l=Math.sqrt(_/m)),l&&(i/=l,o/=l,c/=l,h/=l),u&&(i/=u,o/=f),(p||1!==i||1!==o)&&(d||(d=ft(),p&&gt(d,p)),pt(d,1/i,1/o));const y=e.getCanvas(_t(c)||1,_t(h)||1,s.opacity,s.filters),w=e.getPattern(y,g||t.Platform.origin.noRepeat||"no-repeat",d,n);return n.style=w,n.patternId=r,!0}}const{abs:wt}=Math;const vt={image:function(e,n,a,i,o){let r,s;const l=t.ImageManager.get(a);return it&&a===it.paint&&rt(i,it.boxBounds)?r=it.leafPaint:(r={type:a.type,image:l},l.hasAlphaPixel&&(r.isTransparent=!0),it=l.use>1?{leafPaint:r,paint:a,boxBounds:ot.set(i)}:null),(o||l.loading)&&(s={image:l,attrName:n,attrValue:a}),l.ready?(st(e,n,a,l,r,i),o&&(lt(e,s),dt(e,s))):l.error?o&&ct(e,s,l.error):(o&&(ut(e,!0),lt(e,s)),r.loadId=l.load((()=>{ut(e,!1),e.destroyed||(st(e,n,a,l,r,i)&&(l.hasAlphaPixel&&(e.__layout.hitCanvasChanged=!0),e.forceUpdate("surface")),dt(e,s)),r.loadId=void 0}),(t=>{ut(e,!1),ct(e,s,t),r.loadId=void 0})),e.placeholderColor&&(e.placeholderDelay?setTimeout((()=>{l.ready||(l.isPlacehold=!0,e.forceUpdate("surface"))}),e.placeholderDelay):l.isPlacehold=!0)),r},checkImage:function(e,i,o,r){const{scaleX:s,scaleY:l}=t.ImageManager.patternLocked?e.__world:e.__nowWorld,{pixelRatio:d}=i,{data:c}=o;if(!c||o.patternId===s+"-"+l+"-"+d&&!n.Export.running)return!1;if(r)if(c.repeat)r=!1;else if(!(o.changeful||t.ResizeEvent.isResizing(e)||n.Export.running)){let{width:e,height:n}=c;e*=wt(s)*d,n*=wt(l)*d,c.scaleX&&(e*=c.scaleX,n*=c.scaleY),r=e*n>t.Platform.image.maxCacheSize}return r?(function(t,e,n,a){e.save(),e.clipUI(t),n.blendMode&&(e.blendMode=n.blendMode);a.opacity&&(e.opacity*=a.opacity);a.transform&&e.transform(a.transform);e.drawImage(n.image.getFull(a.filters),0,0,a.width,a.height),e.restore()}(e,i,o,c),!0):(!o.style||o.sync||n.Export.running?yt(e,o,d):o.patternTask||(o.patternTask=t.ImageManager.patternTasker.add((()=>a(this,void 0,void 0,(function*(){o.patternTask=null,i.bounds.hit(e.__nowWorld)&&yt(e,o,d),e.forceUpdate("surface")}))),300)),!1)},createPattern:yt,recycleImage:function(e,n){const a=n["_"+e];if(a instanceof Array){let i,o,r,s,l;for(let d=0,c=a.length;d<c;d++)i=a[d],o=i.image,l=o&&o.url,l&&(r||(r={}),r[l]=!0,t.ImageManager.recycle(o),o.loading&&(s||(s=n.__input&&n.__input[e]||[],s instanceof Array||(s=[s])),o.unload(a[d].loadId,!s.some((t=>t.url===l)))));return r}return null},createData:nt,getPatternData:at,fillOrFitMode:V,clipMode:Q,repeatMode:J},{toPoint:xt}=t.AroundHelper,{hasTransparent:bt}=n.ColorConvert,Et={},Bt={};function Rt(t,e,a,i){if(a){let o,r,s,l;for(let t=0,d=a.length;t<d;t++)o=a[t],"string"==typeof o?(s=t/(d-1),r=n.ColorConvert.string(o,i)):(s=o.offset,r=n.ColorConvert.string(o.color,i)),e.addColorStop(s,r),!l&&bt(r)&&(l=!0);l&&(t.isTransparent=!0)}}const{getAngle:Lt,getDistance:kt}=t.PointHelper,{get:St,rotateOfOuter:Pt,scaleOfOuter:Ct}=t.MatrixHelper,{toPoint:At}=t.AroundHelper,Tt={},Ot={};function Wt(t,e,n,a,i){let o;const{width:r,height:s}=t;if(r!==s||a){const t=Lt(e,n);o=St(),i?(Ct(o,e,r/s*(a||1),1),Pt(o,e,t+90)):(Ct(o,e,1,r/s*(a||1)),Pt(o,e,t))}return o}const{getDistance:It}=t.PointHelper,{toPoint:Dt}=t.AroundHelper,Mt={},Ht={};const Ft={linearGradient:function(e,n){let{from:a,to:i,type:o,opacity:r}=e;xt(a||"top",n,Et),xt(i||"bottom",n,Bt);const s=t.Platform.canvas.createLinearGradient(Et.x,Et.y,Bt.x,Bt.y),l={type:o,style:s};return Rt(l,s,e.stops,r),l},radialGradient:function(e,n){let{from:a,to:i,type:o,opacity:r,stretch:s}=e;At(a||"center",n,Tt),At(i||"bottom",n,Ot);const l=t.Platform.canvas.createRadialGradient(Tt.x,Tt.y,0,Tt.x,Tt.y,kt(Tt,Ot)),d={type:o,style:l};Rt(d,l,e.stops,r);const c=Wt(n,Tt,Ot,s,!0);return c&&(d.transform=c),d},conicGradient:function(e,n){let{from:a,to:i,type:o,opacity:r,stretch:s}=e;Dt(a||"center",n,Mt),Dt(i||"bottom",n,Ht);const l=t.Platform.conicGradientSupport?t.Platform.canvas.createConicGradient(0,Mt.x,Mt.y):t.Platform.canvas.createRadialGradient(Mt.x,Mt.y,0,Mt.x,Mt.y,It(Mt,Ht)),d={type:o,style:l};Rt(d,l,e.stops,r);const c=Wt(n,Mt,Ht,s||1,t.Platform.conicGradientRotate90);return c&&(d.transform=c),d},getTransform:Wt},{copy:Ut,toOffsetOutBounds:jt}=t.BoundsHelper,Yt={},Gt={};function zt(e,n,a,i){const{bounds:o,shapeBounds:r}=i;if(t.Platform.fullImageShadow){if(Ut(Yt,e.bounds),Yt.x+=n.x-r.x,Yt.y+=n.y-r.y,a){const{matrix:t}=i;Yt.x-=(o.x+(t?t.e:0)+o.width/2)*(a-1),Yt.y-=(o.y+(t?t.f:0)+o.height/2)*(a-1),Yt.width*=a,Yt.height*=a}e.copyWorld(i.canvas,e.bounds,Yt)}else a&&(Ut(Yt,n),Yt.x-=n.width/2*(a-1),Yt.y-=n.height/2*(a-1),Yt.width*=a,Yt.height*=a),e.copyWorld(i.canvas,r,a?Yt:n)}const{toOffsetOutBounds:Nt}=t.BoundsHelper,qt={};const Xt={shadow:function(t,e,a){let i,o;const{__nowWorld:r,__layout:s}=t,{shadow:l}=t.__,{worldCanvas:d,bounds:c,shapeBounds:h,scaleX:u,scaleY:f}=a,p=e.getSameCanvas(),g=l.length-1;jt(c,Gt),l.forEach(((l,_)=>{p.setWorldShadow(Gt.offsetX+l.x*u,Gt.offsetY+l.y*f,l.blur*u,n.ColorConvert.string(l.color)),o=l.spread?1+2*l.spread/(s.boxBounds.width+2*(s.strokeBoxSpread||0)):0,zt(p,Gt,o,a),i=c,l.box&&(p.restore(),p.save(),d&&(p.copyWorld(p,c,r,"copy"),i=r),d?p.copyWorld(d,r,r,"destination-out"):p.copyWorld(a.canvas,h,c,"destination-out")),t.__worldFlipped?e.copyWorldByReset(p,i,r,l.blendMode):e.copyWorldToInner(p,i,s.renderBounds,l.blendMode),g&&_<g&&p.clearWorld(i,!0)})),p.recycle(i)},innerShadow:function(t,e,a){let i,o;const{__nowWorld:r,__layout:s}=t,{innerShadow:l}=t.__,{worldCanvas:d,bounds:c,shapeBounds:h,scaleX:u,scaleY:f}=a,p=e.getSameCanvas(),g=l.length-1;Nt(c,qt),l.forEach(((l,_)=>{p.save(),p.setWorldShadow(qt.offsetX+l.x*u,qt.offsetY+l.y*f,l.blur*u),o=l.spread?1-2*l.spread/(s.boxBounds.width+2*(s.strokeBoxSpread||0)):0,zt(p,qt,o,a),p.restore(),d?(p.copyWorld(p,c,r,"copy"),p.copyWorld(d,r,r,"source-out"),i=r):(p.copyWorld(a.canvas,h,c,"source-out"),i=c),p.fillWorld(i,n.ColorConvert.string(l.color),"source-in"),t.__worldFlipped?e.copyWorldByReset(p,i,r,l.blendMode):e.copyWorldToInner(p,i,s.renderBounds,l.blendMode),g&&_<g&&p.clearWorld(i,!0)})),p.recycle(i)},blur:function(t,e,n){const{blur:a}=t.__;n.setWorldBlur(a*t.__nowWorld.a),n.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),n.filter="none"},backgroundBlur:function(t,e,n){}},{excludeRenderBounds:Vt}=t.LeafBoundsHelper;function Qt(t,e,n,a,i,o){switch(e){case"grayscale":i.useGrayscaleAlpha(t.__nowWorld);case"alpha":!function(t,e,n,a){const i=t.__nowWorld;n.resetTransform(),n.opacity=1,n.useMask(a,i),a.recycle(i),Zt(t,e,n,1)}(t,n,a,i);break;case"opacity-path":Zt(t,n,a,o);break;case"path":n.restore()}}function Jt(t){return t.getSameCanvas(!1,!0)}function Zt(t,e,n,a){const i=t.__nowWorld;e.resetTransform(),e.opacity=a,e.copyWorld(n,i),n.recycle(i)}n.Group.prototype.__renderMask=function(t,e){let n,a,i,o,r,s;const{children:l}=this;for(let d=0,c=l.length;d<c;d++)n=l[d],s=n.__.mask,s&&(r&&(Qt(this,r,t,i,a,o),a=i=null),"path"===s||"clipping-path"===s?(n.opacity<1?(r="opacity-path",o=n.opacity,i||(i=Jt(t))):(r="path",t.save()),n.__clip(i||t,e)):(r="grayscale"===s?"grayscale":"alpha",a||(a=Jt(t)),i||(i=Jt(t)),n.__render(a,e)),"clipping"!==s&&"clipping-path"!==s)||Vt(n,e)||n.__render(i||t,e);Qt(this,r,t,i,a,o)};const Kt=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",$t=Kt+"_#~&*+\\=|≮≯≈≠=…",te=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map((([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`)).join("|"));function ee(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const ne=ee("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ae=ee("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),ie=ee(Kt),oe=ee($t),re=ee("- —/~|┆·");var se;!function(t){t[t.Letter=0]="Letter",t[t.Single=1]="Single",t[t.Before=2]="Before",t[t.After=3]="After",t[t.Symbol=4]="Symbol",t[t.Break=5]="Break"}(se||(se={}));const{Letter:le,Single:de,Before:ce,After:he,Symbol:ue,Break:fe}=se;function pe(t){return ne[t]?le:re[t]?fe:ae[t]?ce:ie[t]?he:oe[t]?ue:te.test(t)?de:le}const ge={trimRight(t){const{words:e}=t;let n,a=0,i=e.length;for(let o=i-1;o>-1&&(n=e[o].data[0]," "===n.char);o--)a++,t.width-=n.width;a&&e.splice(i-a,a)}};function _e(t,e,n){switch(e){case"title":return n?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:me}=ge,{Letter:ye,Single:we,Before:ve,After:xe,Symbol:be,Break:Ee}=se;let Be,Re,Le,ke,Se,Pe,Ce,Ae,Te,Oe,We,Ie,De,Me,He,Fe,Ue,je=[];function Ye(t,e){Te&&!Ae&&(Ae=Te),Be.data.push({char:t,width:e}),Le+=e}function Ge(){ke+=Le,Be.width=Le,Re.words.push(Be),Be={data:[]},Le=0}function ze(){Me&&(He.paraNumber++,Re.paraStart=!0,Me=!1),Te&&(Re.startCharSize=Ae,Re.endCharSize=Te,Ae=0),Re.width=ke,Fe.width?me(Re):Ue&&Ne(),je.push(Re),Re={words:[]},ke=0}function Ne(){ke>(He.maxWidth||0)&&(He.maxWidth=ke)}const{top:qe,right:Xe,bottom:Ve,left:Qe}=t.Direction4;function Je(t,e,n){const{bounds:a,rows:i}=t;a[e]+=n;for(let t=0;t<i.length;t++)i[t][e]+=n}const Ze={getDrawData:function(e,a){"string"!=typeof e&&(e=String(e));let i=0,o=0,r=a.__getInput("width")||0,s=a.__getInput("height")||0;const{textDecoration:l,__font:d,__padding:c}=a;c&&(r?(i=c[Qe],r-=c[Xe]+c[Qe]):a.autoSizeAlign||(i=c[Qe]),s?(o=c[qe],s-=c[qe]+c[Ve]):a.autoSizeAlign||(o=c[qe]));const h={bounds:{x:i,y:o,width:r,height:s},rows:[],paraNumber:0,font:t.Platform.canvas.font=d};return function(e,n,a){He=e,je=e.rows,Fe=e.bounds,Ue=!Fe.width&&!a.autoSizeAlign;const{__letterSpacing:i,paraIndent:o,textCase:r}=a,{canvas:s}=t.Platform,{width:l,height:d}=Fe;if(l||d||i||"none"!==r){const t="none"!==a.textWrap,e="break"===a.textWrap;Me=!0,We=null,Ae=Ce=Te=Le=ke=0,Be={data:[]},Re={words:[]},i&&(n=[...n]);for(let a=0,d=n.length;a<d;a++)Pe=n[a],"\n"===Pe?(Le&&Ge(),Re.paraEnd=!0,ze(),Me=!0):(Oe=pe(Pe),Oe===ye&&"none"!==r&&(Pe=_e(Pe,r,!Le)),Ce=s.measureText(Pe).width,i&&(i<0&&(Te=Ce),Ce+=i),Ie=Oe===we&&(We===we||We===ye)||We===we&&Oe!==xe,De=!(Oe!==ve&&Oe!==we||We!==be&&We!==xe),Se=Me&&o?l-o:l,t&&l&&ke+Le+Ce>Se&&(e?(Le&&Ge(),ke&&ze()):(De||(De=Oe===ye&&We==xe),Ie||De||Oe===Ee||Oe===ve||Oe===we||Le+Ce>Se?(Le&&Ge(),ke&&ze()):ke&&ze()))," "===Pe&&!0!==Me&&ke+Le===0||(Oe===Ee?(" "===Pe&&Le&&Ge(),Ye(Pe,Ce),Ge()):Ie||De?(Le&&Ge(),Ye(Pe,Ce)):Ye(Pe,Ce)),We=Oe);Le&&Ge(),ke&&ze(),je.length>0&&(je[je.length-1].paraEnd=!0)}else n.split("\n").forEach((t=>{He.paraNumber++,ke=s.measureText(t).width,je.push({x:o||0,text:t,width:ke,paraStart:!0}),Ue&&Ne()}))}(h,e,a),c&&function(t,e,n,a,i){if(!a&&n.autoSizeAlign)switch(n.textAlign){case"left":Je(e,"x",t[Qe]);break;case"right":Je(e,"x",-t[Xe])}if(!i&&n.autoSizeAlign)switch(n.verticalAlign){case"top":Je(e,"y",t[qe]);break;case"bottom":Je(e,"y",-t[Ve])}}(c,h,a,r,s),function(t,e){const{rows:n,bounds:a}=t,i=n.length,{__lineHeight:o,__baseLine:r,__letterSpacing:s,__clipText:l,textAlign:d,verticalAlign:c,paraSpacing:h,autoSizeAlign:u}=e;let{x:f,y:p,width:g,height:_}=a,m=o*i+(h?h*(t.paraNumber-1):0),y=r;if(l&&m>_)m=Math.max(_,o),i>1&&(t.overflow=i);else if(_||u)switch(c){case"middle":p+=(_-m)/2;break;case"bottom":p+=_-m}y+=p;let w,v,x,b=g||u?g:t.maxWidth;for(let r=0,c=i;r<c;r++){if(w=n[r],w.x=f,w.width<g||w.width>g&&!l)switch(d){case"center":w.x+=(b-w.width)/2;break;case"right":w.x+=b-w.width}w.paraStart&&h&&r>0&&(y+=h),w.y=y,y+=o,t.overflow>r&&y>m&&(w.isOverflow=!0,t.overflow=r+1),v=w.x,x=w.width,s<0&&(w.width<0?(x=-w.width+e.fontSize+s,v-=x,x+=e.fontSize):x-=s),v<a.x&&(a.x=v),x>a.width&&(a.width=x),l&&g&&g<x&&(w.isOverflow=!0,t.overflow||(t.overflow=n.length))}a.y=p,a.height=m}(h,a),function(t,e,n){const{rows:a}=t,{textAlign:i,paraIndent:o,letterSpacing:r}=e;let s,l,d,c,h,u;a.forEach((t=>{t.words&&(d=o&&t.paraStart?o:0,u=t.words.length,l=n&&("justify"===i||"both"===i)&&u>1?(n-t.width-d)/(u-1):0,c=r||t.isOverflow?0:l>.01?1:2,t.isOverflow&&!r&&(t.textMode=!0),2===c?(t.x+=d,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=d,s=t.x,t.data=[],t.words.forEach(((e,n)=>{1===c?(h={char:"",x:s},s=function(t,e,n){return t.forEach((t=>{n.char+=t.char,e+=t.width})),e}(e.data,s,h),(t.isOverflow||" "!==h.char)&&t.data.push(h)):s=function(t,e,n,a){return t.forEach((t=>{(a||" "!==t.char)&&(t.x=e,n.push(t)),e+=t.width})),e}(e.data,s,t.data,t.isOverflow),!l||t.paraEnd&&"both"!==i||n===u-1||(s+=l,t.width+=l)}))),t.words=null)}))}(h,a,r),h.overflow&&function(e,n,a,i){if(!i)return;const{rows:o,overflow:r}=e;let{textOverflow:s}=n;if(o.splice(r),s&&"show"!==s){let e,l;"hide"===s?s="":"ellipsis"===s&&(s="...");const d=s?t.Platform.canvas.measureText(s).width:0,c=a+i-d;("none"===n.textWrap?o:[o[r-1]]).forEach((t=>{if(t.isOverflow&&t.data){let n=t.data.length-1;for(let a=n;a>-1&&(e=t.data[a],l=e.x+e.width,!(a===n&&l<c));a--){if(l<c&&" "!==e.char||!a){t.data.splice(a+1),t.width-=e.width;break}t.width-=e.width}t.width+=d,t.data.push({char:s,x:l}),t.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(t)}}))}}(h,a,i,r),"none"!==l&&function(t,e){let a;const{fontSize:i,textDecoration:o}=e;switch(t.decorationHeight=i/11,"object"==typeof o?(a=o.type,o.color&&(t.decorationColor=n.ColorConvert.string(o.color))):a=o,a){case"under":t.decorationY=[.15*i];break;case"delete":t.decorationY=[.35*-i];break;case"under-delete":t.decorationY=[.15*i,.35*-i]}}(h,a),h}};const Ke={string:function(t,e){const a="number"==typeof e&&1!==e;if("string"==typeof t){if(!a||!n.ColorConvert.object)return t;t=n.ColorConvert.object(t)}let i=void 0===t.a?1:t.a;a&&(i*=e);const o=t.r+","+t.g+","+t.b;return 1===i?"rgb("+o+")":"rgba("+o+","+i+")"}};Object.assign(n.TextConvert,Ze),Object.assign(n.ColorConvert,Ke),Object.assign(n.Paint,F),Object.assign(n.PaintImage,vt),Object.assign(n.PaintGradient,Ft),Object.assign(n.Effect,Xt);const{setPoint:$e,addPoint:tn,toBounds:en}=n.TwoPointBoundsHelper;const nn={syncExport(t,e,a){let i;this.running=!0;const o=n.FileHelper.fileType(e),r=e.includes(".");a=n.FileHelper.getExportOptions(a);const{toURL:s}=n.Platform,{download:l}=n.Platform.origin;if("json"===o)r&&l(s(JSON.stringify(t.toJSON(a.json)),"text"),e),i={data:!!r||t.toJSON(a.json)};else if("svg"===o)r&&l(s(t.toSVG(),"svg"),e),i={data:!!r||t.toSVG()};else{let o,r,s=1,l=1;const{worldTransform:d,isLeafer:c,leafer:h,isFrame:u}=t,{slice:f,clip:p,trim:g,screenshot:_,padding:m,onCanvas:y}=a,w=void 0===a.smooth?!h||h.config.smooth:a.smooth,v=a.contextSettings||(h?h.config.contextSettings:void 0),x=c&&_&&void 0===a.fill?t.fill:a.fill,b=n.FileHelper.isOpaqueImage(e)||x,E=new n.Matrix;if(_)o=!0===_?c?h.canvas.bounds:t.worldRenderBounds:_;else{let e=a.relative||(c?"inner":"local");switch(s=d.scaleX,l=d.scaleY,e){case"inner":E.set(d);break;case"local":E.set(d).divide(t.localTransform),s/=t.scaleX,l/=t.scaleY;break;case"world":s=1,l=1;break;case"page":e=h||t;default:E.set(d).divide(t.getTransform(e));const n=e.worldTransform;s/=s/n.scaleX,l/=l/n.scaleY}o=t.getBounds("render",e)}const B={scaleX:1,scaleY:1};n.MathHelper.getScaleData(a.scale,a.size,o,B);let R=a.pixelRatio||1,{x:L,y:k,width:S,height:P}=new n.Bounds(o).scale(B.scaleX,B.scaleY);p&&(L+=p.x,k+=p.y,S=p.width,P=p.height);const C={exporting:!0,matrix:E.scale(1/B.scaleX,1/B.scaleY).invert().translate(-L,-k).withScale(1/s*B.scaleX,1/l*B.scaleY)};let A,T=n.Creator.canvas({width:Math.floor(S),height:Math.floor(P),pixelRatio:R,smooth:w,contextSettings:v});if(f&&(A=t,A.__worldOpacity=0,t=h||t,C.bounds=T.bounds),T.save(),u&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(T,C),t.fill=e}else t.__render(T,C);if(T.restore(),A&&A.__updateWorldOpacity(),g){r=function(t){const{width:e,height:a}=t.view,{data:i}=t.context.getImageData(0,0,e,a);let o,r,s,l=0;for(let t=0;t<i.length;t+=4)0!==i[t+3]&&(o=l%e,r=(l-o)/e,s?tn(s,o,r):$e(s={},o,r)),l++;const d=new n.Bounds;return en(s,d),d.scale(1/t.pixelRatio).ceil()}(T);const t=T,{width:e,height:a}=r,i={x:0,y:0,width:e,height:a,pixelRatio:R};T=n.Creator.canvas(i),T.copyWorld(t,r,i)}if(m){const[t,e,a,i]=n.MathHelper.fourNumber(m),o=T,{width:r,height:s}=o;T=n.Creator.canvas({width:r+i+e,height:s+t+a,pixelRatio:R}),T.copyWorld(o,o.bounds,{x:i,y:t,width:r,height:s})}b&&T.fillWorld(T.bounds,x||"#FFFFFF","destination-over"),y&&y(T);i={data:"canvas"===e?T:T.export(e,a),width:T.pixelWidth,height:T.pixelHeight,renderBounds:o,trimBounds:r}}return this.running=!1,i},export(t,e,i){return this.running=!0,function(t){an||(an=new n.TaskProcessor);return new Promise((e=>{an.add((()=>a(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((o=>new Promise((r=>{const s=()=>a(this,void 0,void 0,(function*(){if(!n.Resource.isComplete)return n.Platform.requestRender(s);const a=nn.syncExport(t,e,i);a.data instanceof Promise&&(a.data=yield a.data),o(a),r()}));t.updateLayout(),on(t);const{leafer:l}=t;l?l.waitViewCompleted(s):s()}))))}};let an;function on(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>on(t)))}const rn=n.LeaferCanvasBase.prototype,sn=n.Debug.get("@leafer-in/export");rn.export=function(t,e){const{quality:a,blob:i}=n.FileHelper.getExportOptions(e);return t.includes(".")?this.saveAs(t,a):i?this.toBlob(t,a):this.toDataURL(t,a)},rn.toBlob=function(t,e){return new Promise((a=>{n.Platform.origin.canvasToBolb(this.view,t,e).then((t=>{a(t)})).catch((t=>{sn.error(t),a(null)}))}))},rn.toDataURL=function(t,e){return n.Platform.origin.canvasToDataURL(this.view,t,e)},rn.saveAs=function(t,e){return new Promise((a=>{n.Platform.origin.canvasSaveAs(this.view,t,e).then((()=>{a(!0)})).catch((t=>{sn.error(t),a(!1)}))}))},n.Plugin.add("export"),Object.assign(n.Export,nn),n.UI.prototype.export=function(t,e){return n.Export.export(this,t,e)},n.UI.prototype.syncExport=function(t,e){return n.Export.syncExport(this,t,e)},Object.defineProperty(exports,"LeaferImage",{enumerable:!0,get:function(){return t.LeaferImage}}),exports.Layouter=y,exports.LeaferCanvas=i,exports.Renderer=v,exports.Watcher=s,exports.useCanvas=function(n,i){if(t.Platform.canvasType=n,!t.Platform.origin){if("skia"===n){const{Canvas:e,loadImage:n}=i;t.Platform.origin={createCanvas:(t,n,a)=>new e(t,n,a),canvasToDataURL:(t,e,n)=>t.toDataURLSync(e,{quality:n}),canvasToBolb:(t,e,n)=>t.toBuffer(e,{quality:n}),canvasSaveAs:(t,e,n)=>t.saveAs(e,{quality:n}),download(t,e){},loadImage:e=>n(t.Platform.image.getRealURL(e))},t.Platform.roundRectPatch=!0}else if("napi"===n){const{Canvas:n,loadImage:s}=i;t.Platform.origin={createCanvas:(t,e,a)=>new n(t,e,a),canvasToDataURL:(t,e,n)=>t.toDataURL(o(e),n),canvasToBolb:(t,e,n)=>a(this,void 0,void 0,(function*(){return t.toBuffer(o(e),n)})),canvasSaveAs:(t,n,i)=>a(this,void 0,void 0,(function*(){return e.writeFileSync(n,t.toBuffer(o(r(n)),i))})),download(t,e){},loadImage:e=>s(t.Platform.image.getRealURL(e))}}t.Platform.ellipseToCurve=!0,t.Platform.event={stopDefault(t){},stopNow(t){},stop(t){}},t.Platform.canvas=t.Creator.canvas()}},Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})})),Object.keys(n).forEach((function(t){"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return n[t]}})}));
1
+ "use strict";var t=require("@leafer/core"),e=require("fs"),n=require("@leafer-ui/draw");function i(t,e,n,i){return new(n||(n=Promise))(function(a,s){function r(t){try{l(i.next(t))}catch(t){s(t)}}function o(t){try{l(i.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(r,o)}l((i=i.apply(t,e||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class a extends t.LeaferCanvasBase{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config),t.Platform.roundRectPatch&&(this.context.__proto__.roundRect=null,t.canvasPatch(this.context.__proto__))}__createView(){this.view=t.Platform.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:n}=this;this.view.width=Math.ceil(t*n),this.view.height=Math.ceil(e*n),this.clientBounds=this.bounds}}const{mineType:s,fileType:r}=t.FileHelper;Object.assign(t.Creator,{canvas:(t,e)=>new a(t,e),image:e=>new t.LeaferImage(e)}),t.Platform.name="node",t.Platform.backgrounder=!0,t.Platform.requestRender=function(t){setTimeout(t,16)},t.defineKey(t.Platform,"devicePixelRatio",{get:()=>1}),t.Platform.conicGradientSupport=!0;class o{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const e=new t.LeafList;return this.__updatedList.list.forEach(t=>{t.leafer&&e.add(t)}),e}return this.__updatedList}constructor(e,n){this.totalTimes=0,this.config={},this.__updatedList=new t.LeafList,this.target=e,n&&(this.config=t.DataHelper.default(n,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(t.RenderEvent.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(e){e.type===t.ChildEvent.ADD?(this.hasAdd=!0,this.__pushChild(e.child)):(this.hasRemove=!0,this.__updatedList.add(e.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,n=e.length;t<n;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new t.WatchEvent(t.WatchEvent.DATA,{updatedList:this.updatedList})),this.__updatedList=new t.LeafList,this.totalTimes++,this.changed=this.hasVisible=this.hasRemove=this.hasAdd=!1}__listenEvents(){this.__eventIds=[this.target.on_([[t.PropertyEvent.CHANGE,this.__onAttrChange,this],[[t.ChildEvent.ADD,t.ChildEvent.REMOVE],this.__onChildEvent,this],[t.WatchEvent.REQUEST,this.__onRquestData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.__updatedList=null)}}const{updateAllMatrix:l,updateBounds:d,updateChange:c}=t.LeafHelper,{pushAllChildBranch:h,pushAllParent:u}=t.BranchHelper;const{worldBounds:f}=t.LeafBoundsHelper;class p{constructor(e){this.updatedBounds=new t.Bounds,this.beforeBounds=new t.Bounds,this.afterBounds=new t.Bounds,t.isArray(e)&&(e=new t.LeafList(e)),this.updatedList=e}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,f)}setAfter(){this.afterBounds.setListWithFn(this.updatedList.list,f),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:g,updateAllChange:_}=t.LeafHelper,y=t.Debug.get("Layouter");class m{constructor(e,n){this.totalTimes=0,this.config={},this.__levelList=new t.LeafLevelList,this.target=e,n&&(this.config=t.DataHelper.default(n,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(this.layouting||!this.running)return;const{target:e}=this;this.times=0;try{e.emit(t.LayoutEvent.START),this.layoutOnce(),e.emitEvent(new t.LayoutEvent(t.LayoutEvent.END,this.layoutedBlocks,this.times))}catch(t){y.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?y.warn("layouting"):this.times>3?y.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(t.WatchEvent.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var e;if(!(null===(e=this.__updatedList)||void 0===e?void 0:e.length))return;const n=t.Run.start("PartLayout"),{target:i,__updatedList:a}=this,{BEFORE:s,LAYOUT:r,AFTER:o}=t.LayoutEvent,f=this.getBlocks(a);f.forEach(t=>t.setBefore()),i.emitEvent(new t.LayoutEvent(s,f,this.times)),this.extraBlock=null,a.sort(),function(t,e){let n;t.list.forEach(t=>{n=t.__layout,e.without(t)&&!n.proxyZoom&&(n.matrixChanged?(l(t,!0),e.add(t),t.isBranch&&h(t,e),u(t,e)):n.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),u(t,e)))})}(a,this.__levelList),function(t){let e,n,i;t.sort(!0),t.levels.forEach(a=>{e=t.levelMap[a];for(let t=0,a=e.length;t<a;t++){if(n=e[t],n.isBranch&&n.__tempNumber){i=n.children;for(let t=0,e=i.length;t<e;t++)i[t].isBranch||d(i[t])}d(n)}})}(this.__levelList),function(t){t.list.forEach(c)}(a),this.extraBlock&&f.push(this.extraBlock),f.forEach(t=>t.setAfter()),i.emitEvent(new t.LayoutEvent(r,f,this.times)),i.emitEvent(new t.LayoutEvent(o,f,this.times)),this.addBlocks(f),this.__levelList.reset(),this.__updatedList=null,t.Run.end(n)}fullLayout(){const e=t.Run.start("FullLayout"),{target:n}=this,{BEFORE:i,LAYOUT:a,AFTER:s}=t.LayoutEvent,r=this.getBlocks(new t.LeafList(n));n.emitEvent(new t.LayoutEvent(i,r,this.times)),m.fullLayout(n),r.forEach(t=>{t.setAfter()}),n.emitEvent(new t.LayoutEvent(a,r,this.times)),n.emitEvent(new t.LayoutEvent(s,r,this.times)),this.addBlocks(r),t.Run.end(e)}static fullLayout(e){g(e,!0),e.isBranch?t.BranchHelper.updateBounds(e):t.LeafHelper.updateBounds(e),_(e)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:n}=this.extraBlock||(this.extraBlock=new p([]));e.length?n.add(t.__world):n.set(t.__world),e.add(t)}}createBlock(t){return new p(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){this.__eventIds=[this.target.on_([[t.LayoutEvent.REQUEST,this.layout,this],[t.LayoutEvent.AGAIN,this.layoutAgain,this],[t.WatchEvent.DATA,this.__onReceiveWatchData,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const v=t.Debug.get("Renderer");class w{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(e,n,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=e,this.canvas=n,i&&(this.config=t.DataHelper.default(i,this.config)),this.__listenEvents()}start(){this.running=!0,this.update(!1)}stop(){this.running=!1}update(t=!0){this.changed||(this.changed=t),this.__requestRender()}requestLayout(){this.target.emit(t.LayoutEvent.REQUEST)}checkRender(){if(this.running){const{target:e}=this;e.isApp&&(e.emit(t.RenderEvent.CHILD_START,e),e.children.forEach(t=>{t.renderer.FPS=this.FPS,t.renderer.checkRender()}),e.emit(t.RenderEvent.CHILD_END,e)),this.changed&&this.canvas.view&&this.render(),this.target.emit(t.RenderEvent.NEXT)}}render(e){if(!this.running||!this.canvas.view)return this.update();const{target:n}=this;this.times=0,this.totalBounds=new t.Bounds,v.log(n.innerName,"---\x3e");try{this.emitRender(t.RenderEvent.START),this.renderOnce(e),this.emitRender(t.RenderEvent.END,this.totalBounds),t.ImageManager.clearRecycled()}catch(t){this.rendering=!1,v.error(t)}v.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(e){if(this.rendering)return v.warn("rendering");if(this.times>3)return v.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new t.Bounds,this.renderOptions={},e)this.emitRender(t.RenderEvent.BEFORE),e();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(t.RenderEvent.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(t.RenderEvent.RENDER,this.renderBounds,this.renderOptions),this.emitRender(t.RenderEvent.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;e&&(this.mergeBlocks(),e.forEach(e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const n=t.Run.start("PartRender"),{canvas:i}=this,a=e.getIntersect(i.bounds),s=new t.Bounds(a);i.save(),a.spread(w.clipSpread).ceil(),i.clearWorld(a,!0),i.clipWorld(a,!0),this.__render(a,s),i.restore(),t.Run.end(n)}fullRender(){const e=t.Run.start("FullRender"),{canvas:n}=this;n.save(),n.clear(),this.__render(n.bounds),n.restore(),t.Run.end(e)}__render(e,n){const{canvas:i}=this,a=e.includes(this.target.__world),s=a?{includes:a}:{bounds:e,includes:a};this.needFill&&i.fillWorld(e,this.config.fill),t.Debug.showRepaint&&t.Debug.drawRepaint(i,e),this.target.__render(i,s),this.renderBounds=n=n||e,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=n:this.totalBounds.add(n),i.updateRender(n)}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:e}=this;if(e){const n=new t.Bounds;n.setList(e),e.length=0,e.push(n)}}__requestRender(){const e=this.target;if(this.requestTime||!e)return;if(e.parentApp)return e.parentApp.requestRender(!1);const n=this.requestTime=Date.now();t.Platform.requestRender(()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-n))),this.requestTime=0,this.checkRender()})}__onResize(e){if(!this.canvas.unreal){if(e.bigger||!e.samePixelRatio){const{width:n,height:i}=e.old;if(!new t.Bounds(0,0,n,i).includes(this.target.__world)||this.needFill||!e.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new t.Bounds(0,0,1,1)),this.update()}}__onLayoutEnd(t){t.data&&t.data.map(t=>{let e;t.updatedList&&t.updatedList.list.some(t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||v.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e)),this.addBlock(e?this.canvas.bounds:t.updatedBounds)})}emitRender(e,n,i){this.target.emitEvent(new t.RenderEvent(e,this.times,n,i))}__listenEvents(){this.__eventIds=[this.target.on_([[t.RenderEvent.REQUEST,this.update,this],[t.LayoutEvent.END,this.__onLayoutEnd,this],[t.RenderEvent.AGAIN,this.renderAgain,this],[t.ResizeEvent.RESIZE,this.__onResize,this]])]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}function x(t,e){const n=t.__,{rows:i,decorationY:a}=n.__textDrawData;let s;n.__isPlacehold&&n.placeholderColor&&(e.fillStyle=n.placeholderColor);for(let t=0,n=i.length;t<n;t++)s=i[t],s.text?e.fillText(s.text,s.x,s.y):s.data&&s.data.forEach(t=>{e.fillText(t.char,t.x,s.y)});if(a){const{decorationColor:t,decorationHeight:s}=n.__textDrawData;t&&(e.fillStyle=t),i.forEach(t=>a.forEach(n=>e.fillRect(t.x,t.y+n,t.width,s)))}}function b(t,e){t.__.__font?x(t,e):t.__.windingRule?e.fill(t.__.windingRule):e.fill()}function E(t,e,n){switch(e.__.strokeAlign){case"center":B(t,1,e,n);break;case"inside":R(t,"inside",e,n);break;case"outside":e.__.__fillAfterStroke?B(t,2,e,n):R(t,"outside",e,n)}}function B(e,n,i,a){const s=i.__;t.isObject(e)?L(e,n,!0,i,a):(a.setStroke(e,s.__strokeWidth*n,s),S(i,a))}function R(e,n,i,a){const s=a.getSameCanvas(!0,!0);s.font=i.__.__font,B(e,2,i,s),s.blendMode="outside"===n?"destination-out":"destination-in",x(i,s),s.blendMode="normal",t.LeafHelper.copyCanvasByWorld(i,a,s),s.recycle(i.__nowWorld)}function S(t,e){let n,i=t.__.__textDrawData;const{rows:a,decorationY:s}=i;for(let t=0,i=a.length;t<i;t++)n=a[t],n.text?e.strokeText(n.text,n.x,n.y):n.data&&n.data.forEach(t=>{e.strokeText(t.char,t.x,n.y)});if(s){const{decorationHeight:t}=i;a.forEach(n=>s.forEach(i=>e.strokeRect(n.x,n.y+i,n.width,t)))}}function L(t,e,i,a,s){let r;const o=a.__,{__hasMultiStrokeStyle:l}=o;l||s.setStroke(void 0,o.__strokeWidth*e,o);for(let d=0,c=t.length;d<c;d++)if(r=t[d],(!r.image||!n.PaintImage.checkImage(a,s,r,!1))&&r.style){if(l){const{strokeStyle:t}=r;t?s.setStroke(r.style,o.__getRealStrokeWidth(t)*e,o,t):s.setStroke(r.style,o.__strokeWidth*e,o)}else s.strokeStyle=r.style;r.blendMode?(s.saveBlendMode(r.blendMode),i?S(a,s):s.stroke(),s.restoreBlendMode()):i?S(a,s):s.stroke()}}function k(e,n,i){const a=n.__;if(a.__strokeWidth)if(a.__font)E(e,n,i);else switch(a.strokeAlign){case"center":P(e,1,n,i);break;case"inside":!function(t,e,n){n.save(),n.clipUI(e),P(t,2,e,n),n.restore()}(e,n,i);break;case"outside":!function(e,n,i){const a=n.__;if(a.__fillAfterStroke)P(e,2,n,i);else{const{renderBounds:s}=n.__layout,r=i.getSameCanvas(!0,!0);n.__drawRenderPath(r),P(e,2,n,r),r.clipUI(a),r.clearWorld(s),t.LeafHelper.copyCanvasByWorld(n,i,r),r.recycle(n.__nowWorld)}}(e,n,i)}}function P(e,i,a,s){const r=a.__;t.isObject(e)?L(e,i,!1,a,s):(s.setStroke(e,r.__strokeWidth*i,r),s.stroke()),r.__useArrow&&n.Paint.strokeArrow(e,a,s)}w.clipSpread=10,Object.assign(t.Creator,{watcher:(t,e)=>new o(t,e),layouter:(t,e)=>new m(t,e),renderer:(t,e,n)=>new w(t,e,n),selector:(t,e)=>{},interaction:(t,e,n,i)=>{}}),t.Platform.layout=m.fullLayout;const{getSpread:C,getOuterOf:A,getByMove:O,getIntersectData:T}=t.BoundsHelper;let W;const{stintSet:M}=t.DataHelper,{hasTransparent:D}=n.ColorConvert;function I(e,i,a){if(!t.isObject(i)||!1===i.visible||0===i.opacity)return;let s;const{boxBounds:r}=a.__layout;switch(i.type){case"image":s=n.PaintImage.image(a,e,i,r,!W||!W[i.url]);break;case"linear":s=n.PaintGradient.linearGradient(i,r);break;case"radial":s=n.PaintGradient.radialGradient(i,r);break;case"angular":s=n.PaintGradient.conicGradient(i,r);break;case"solid":const{type:o,color:l,opacity:d}=i;s={type:o,style:n.ColorConvert.string(l,d)};break;default:t.isUndefined(i.r)||(s={type:"solid",style:n.ColorConvert.string(i)})}if(s){if(t.isString(s.style)&&D(s.style)&&(s.isTransparent=!0),i.style){if(0===i.style.strokeWidth)return;s.strokeStyle=i.style}i.editing&&(s.editing=i.editing),i.blendMode&&(s.blendMode=i.blendMode)}return s}const H={compute:function(e,i){const a=i.__,s=[];let r,o,l,d=a.__input[e];t.isArray(d)||(d=[d]),W=n.PaintImage.recycleImage(e,a);for(let t,n=0,a=d.length;n<a;n++)(t=I(e,d[n],i))&&(s.push(t),t.strokeStyle&&(l||(l=1),t.strokeStyle.strokeWidth&&(l=Math.max(l,t.strokeStyle.strokeWidth))));a["_"+e]=s.length?s:void 0,s.length&&s.every(t=>t.isTransparent)&&(s.some(t=>t.image)&&(r=!0),o=!0),"fill"===e?(M(a,"__isAlphaPixelFill",r),M(a,"__isTransparentFill",o)):(M(a,"__isAlphaPixelStroke",r),M(a,"__isTransparentStroke",o),M(a,"__hasMultiStrokeStyle",l))},fill:function(t,e,n){n.fillStyle=t,b(e,n)},fills:function(t,e,i){let a;for(let s=0,r=t.length;s<r;s++){if(a=t[s],a.image){if(n.PaintImage.checkImage(e,i,a,!e.__.__font))continue;if(!a.style){!s&&a.image.isPlacehold&&e.drawImagePlaceholder(i,a.image);continue}}if(i.fillStyle=a.style,a.transform||a.scaleFixed){if(i.save(),a.transform&&i.transform(a.transform),a.scaleFixed){const{scaleX:t,scaleY:n}=e.getRenderScaleData(!0);(!0===a.scaleFixed||"zoom-in"===a.scaleFixed&&t>1&&n>1)&&i.scale(1/t,1/n)}a.blendMode&&(i.blendMode=a.blendMode),b(e,i),i.restore()}else a.blendMode?(i.saveBlendMode(a.blendMode),b(e,i),i.restoreBlendMode()):b(e,i)}},fillPathOrText:b,fillText:x,stroke:k,strokes:function(t,e,n){k(t,e,n)},strokeText:E,drawTextStroke:S,shape:function(e,n,i){const a=n.getSameCanvas(),s=e.__nowWorld;let r,o,l,d,c,{scaleX:h,scaleY:u}=s;if(h<0&&(h=-h),u<0&&(u=-u),n.bounds.includes(s))c=a,r=d=s;else{const{renderShapeSpread:a}=e.__layout,f=T(a?C(n.bounds,h===u?a*h:[a*u,a*h]):n.bounds,s);l=n.bounds.getFitMatrix(f);let{a:p,d:g}=l;l.a<1&&(c=n.getSameCanvas(),e.__renderShape(c,i),h*=p,u*=g),d=A(s,l),r=O(d,-l.e,-l.f);const _=i.matrix;_?(o=new t.Matrix(l),o.multiply(_),p*=_.scaleX,g*=_.scaleY):o=l,o.withScale(p,g),i=Object.assign(Object.assign({},i),{matrix:o})}return e.__renderShape(a,i),{canvas:a,matrix:o,fitMatrix:l,bounds:r,worldCanvas:c,shapeBounds:d,scaleX:h,scaleY:u}}};let F={},U=t.getMatrixData();const{get:j,rotateOfOuter:Y,translate:z,scaleOfOuter:G,multiplyParent:X,scale:N,rotate:q,skew:V}=t.MatrixHelper;function Q(t,e,n,i,a,s,r){const o=j();z(o,e.x+n,e.y+i),N(o,a,s),r&&Y(o,{x:e.x+e.width/2,y:e.y+e.height/2},r),t.transform=o}function J(t,e,n,i,a,s,r,o,l){const d=j();K(d,e,n,i,a,s,r,o),l&&(U.a=e.width/l.width,U.d=e.height/l.height,X(d,U)),t.transform=d}function Z(t,e,n,i,a,s,r,o,l,d,c,h){const u=j();if(h)K(u,e,a,s,r,o,l,d);else{if(l)if("center"===c)Y(u,{x:n/2,y:i/2},l);else switch(q(u,l),l){case 90:z(u,i,0);break;case 180:z(u,n,i);break;case 270:z(u,0,n)}F.x=e.x+a,F.y=e.y+s,z(u,F.x,F.y),r&&G(u,F,r,o)}t.transform=u}function K(t,e,n,i,a,s,r,o){r&&q(t,r),o&&V(t,o.x,o.y),a&&N(t,a,s),z(t,e.x+n,e.y+i)}const{get:$,translate:tt}=t.MatrixHelper,et=new t.Bounds,nt={},it={};function at(t,e,n,i){const{changeful:a,sync:s,scaleFixed:r}=n;a&&(t.changeful=a),s&&(t.sync=s),r&&(t.scaleFixed=r),t.data=st(n,i,e)}function st(e,n,i){e.padding&&(n=et.set(n).shrink(e.padding)),"strench"===e.mode&&(e.mode="stretch");let{width:a,height:s}=i;const{opacity:r,mode:o,align:l,offset:d,scale:c,size:h,rotation:u,skew:f,clipSize:p,repeat:g,gap:_,filters:y}=e,m=n.width===a&&n.height===s,v={mode:o},w="center"!==l&&(u||0)%180==90;let x,b;switch(t.BoundsHelper.set(it,0,0,w?s:a,w?a:s),o&&"cover"!==o&&"fit"!==o?((c||h)&&(t.MathHelper.getScaleData(c,h,i,nt),x=nt.scaleX,b=nt.scaleY),(l||_||g)&&(x&&t.BoundsHelper.scale(it,x,b,!0),l&&t.AlignHelper.toPoint(l,it,n,it,!0,!0))):m&&!u||(x=b=t.BoundsHelper.getFitScale(n,it,"fit"!==o),t.BoundsHelper.put(n,i,l,x,!1,it),t.BoundsHelper.scale(it,x,b,!0)),d&&t.PointHelper.move(it,d),o){case"stretch":m||(a=n.width,s=n.height);break;case"normal":case"clip":(it.x||it.y||x||p||u||f)&&J(v,n,it.x,it.y,x,b,u,f,e.clipSize);break;case"repeat":(!m||x||u||f)&&Z(v,n,a,s,it.x,it.y,x,b,u,f,l,e.freeTransform),g||(v.repeat="repeat");const i=t.isObject(g);(_||i)&&(v.gap=function(e,n,i,a,s){let r,o;t.isObject(e)?(r=e.x,o=e.y):r=o=e;return{x:rt(r,i,s.width,n&&n.x),y:rt(o,a,s.height,n&&n.y)}}(_,i&&g,it.width,it.height,n));break;default:x&&Q(v,n,it.x,it.y,x,b,u)}return v.transform||(n.x||n.y)&&(v.transform=$(),tt(v.transform,n.x,n.y)),x&&"stretch"!==o&&(v.scaleX=x,v.scaleY=b),v.width=a,v.height=s,r&&(v.opacity=r),y&&(v.filters=y),g&&(v.repeat=t.isString(g)?"x"===g?"repeat-x":"repeat-y":"repeat"),v}function rt(e,n,i,a){const s=t.isString(e)||a?(a?i-a*n:i%n)/((a||Math.floor(i/n))-1):e;return"auto"===e&&s<0?0:s}let ot,lt=new t.Bounds;const{isSame:dt}=t.BoundsHelper;function ct(t,e,n,i,a,s){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=i.width/e.pixelRatio,e.__naturalHeight=i.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return a.data||at(a,i,n,s),!0}function ht(e,n){pt(e,t.ImageEvent.LOAD,n)}function ut(e,n){pt(e,t.ImageEvent.LOADED,n)}function ft(e,n,i){n.error=i,e.forceUpdate("surface"),pt(e,t.ImageEvent.ERROR,n)}function pt(e,n,i){e.hasEvent(n)&&e.emitEvent(new t.ImageEvent(n,i))}function gt(t,e){const{leafer:n}=t;n&&n.viewReady&&(n.renderer.ignore=e)}const{get:_t,scale:yt,copy:mt}=t.MatrixHelper,{floor:vt,max:wt,abs:xt}=Math;function bt(e,n,i){let{scaleX:a,scaleY:s}=e.getRenderScaleData(!0,n.scaleFixed);const r=a+"-"+s+"-"+i;if(n.patternId===r||e.destroyed)return!1;{const{image:e,data:o}=n;let l,d,{width:c,height:h,scaleX:u,scaleY:f,transform:p,repeat:g,gap:_}=o;a*=i,s*=i;const y=_&&_.x*a,m=_&&_.y*s;u&&(u=xt(u),f=xt(f),d=_t(),mt(d,p),yt(d,1/u,1/f),a*=u,s*=f),c*=a,h*=s;const v=c*h;if(!g&&v>t.Platform.image.maxCacheSize)return!1;let w=t.Platform.image.maxPatternSize;if(!e.isSVG){const t=e.width*e.height;w>t&&(w=t)}if(v>w&&(l=Math.sqrt(v/w)),l&&(a/=l,s/=l,c/=l,h/=l),u&&(a/=u,s/=f),(p||1!==a||1!==s)&&(d||(d=_t(),p&&mt(d,p)),yt(d,1/a,1/s)),d){const t=c+(y||0),e=h+(m||0);yt(d,t/wt(vt(t),1),e/wt(vt(e),1))}const x=e.getCanvas(c,h,o.opacity,o.filters,y,m),b=e.getPattern(x,g||t.Platform.origin.noRepeat||"no-repeat",d,n);return n.style=b,n.patternId=r,!0}}const Et={image:function(e,n,i,a,s){let r,o;const l=t.ImageManager.get(i);return ot&&i===ot.paint&&dt(a,ot.boxBounds)?r=ot.leafPaint:(r={type:i.type,image:l},l.hasAlphaPixel&&(r.isTransparent=!0),ot=l.use>1?{leafPaint:r,paint:i,boxBounds:lt.set(a)}:null),(s||l.loading)&&(o={image:l,attrName:n,attrValue:i}),l.ready?(ct(e,n,i,l,r,a),s&&(ht(e,o),ut(e,o))):l.error?s&&ft(e,o,l.error):(s&&(gt(e,!0),ht(e,o)),r.loadId=l.load(()=>{gt(e,!1),e.destroyed||(ct(e,n,i,l,r,a)&&(l.hasAlphaPixel&&(e.__layout.hitCanvasChanged=!0),e.forceUpdate("surface")),ut(e,o)),r.loadId=void 0},t=>{gt(e,!1),ft(e,o,t),r.loadId=void 0}),e.placeholderColor&&(e.placeholderDelay?setTimeout(()=>{l.ready||(l.isPlacehold=!0,e.forceUpdate("surface"))},e.placeholderDelay):l.isPlacehold=!0)),r},checkImage:function(e,a,s,r){const{scaleX:o,scaleY:l}=e.getRenderScaleData(!0,s.scaleFixed),{pixelRatio:d}=a,{data:c}=s;if(!c||s.patternId===o+"-"+l+"-"+d&&!n.Export.running)return!1;if(r)if(c.repeat)r=!1;else if(!(s.changeful||"miniapp"===t.Platform.name&&t.ResizeEvent.isResizing(e)||n.Export.running)){let{width:e,height:n}=c;e*=o*d,n*=l*d,c.scaleX&&(e*=c.scaleX,n*=c.scaleY),r=e*n>t.Platform.image.maxCacheSize}return r?(e.__.__isFastShadow&&(a.fillStyle=s.style||"#000",a.fill()),function(t,e,n,i){e.save(),e.clipUI(t),n.blendMode&&(e.blendMode=n.blendMode);i.opacity&&(e.opacity*=i.opacity);i.transform&&e.transform(i.transform);e.drawImage(n.image.getFull(i.filters),0,0,i.width,i.height),e.restore()}(e,a,s,c),!0):(!s.style||s.sync||n.Export.running?bt(e,s,d):s.patternTask||(s.patternTask=t.ImageManager.patternTasker.add(()=>i(this,void 0,void 0,function*(){s.patternTask=null,a.bounds.hit(e.__nowWorld)&&bt(e,s,d),e.forceUpdate("surface")}),300)),!1)},createPattern:bt,recycleImage:function(e,n){const i=n["_"+e];if(t.isArray(i)){let a,s,r,o,l;for(let d=0,c=i.length;d<c;d++)a=i[d],s=a.image,l=s&&s.url,l&&(r||(r={}),r[l]=!0,t.ImageManager.recycle(s),s.loading&&(o||(o=n.__input&&n.__input[e]||[],t.isArray(o)||(o=[o])),s.unload(i[d].loadId,!o.some(t=>t.url===l))));return r}return null},createData:at,getPatternData:st,fillOrFitMode:Q,clipMode:J,repeatMode:Z},{toPoint:Bt}=t.AroundHelper,{hasTransparent:Rt}=n.ColorConvert,St={},Lt={};function kt(e,i,a,s){if(a){let r,o,l,d;for(let e=0,c=a.length;e<c;e++)r=a[e],t.isString(r)?(l=e/(c-1),o=n.ColorConvert.string(r,s)):(l=r.offset,o=n.ColorConvert.string(r.color,s)),i.addColorStop(l,o),!d&&Rt(o)&&(d=!0);d&&(e.isTransparent=!0)}}const{getAngle:Pt,getDistance:Ct}=t.PointHelper,{get:At,rotateOfOuter:Ot,scaleOfOuter:Tt}=t.MatrixHelper,{toPoint:Wt}=t.AroundHelper,Mt={},Dt={};function It(t,e,n,i,a){let s;const{width:r,height:o}=t;if(r!==o||i){const t=Pt(e,n);s=At(),a?(Tt(s,e,r/o*(i||1),1),Ot(s,e,t+90)):(Tt(s,e,1,r/o*(i||1)),Ot(s,e,t))}return s}const{getDistance:Ht}=t.PointHelper,{toPoint:Ft}=t.AroundHelper,Ut={},jt={};const Yt={linearGradient:function(e,n){let{from:i,to:a,type:s,opacity:r}=e;Bt(i||"top",n,St),Bt(a||"bottom",n,Lt);const o=t.Platform.canvas.createLinearGradient(St.x,St.y,Lt.x,Lt.y),l={type:s,style:o};return kt(l,o,e.stops,r),l},radialGradient:function(e,n){let{from:i,to:a,type:s,opacity:r,stretch:o}=e;Wt(i||"center",n,Mt),Wt(a||"bottom",n,Dt);const l=t.Platform.canvas.createRadialGradient(Mt.x,Mt.y,0,Mt.x,Mt.y,Ct(Mt,Dt)),d={type:s,style:l};kt(d,l,e.stops,r);const c=It(n,Mt,Dt,o,!0);return c&&(d.transform=c),d},conicGradient:function(e,n){let{from:i,to:a,type:s,opacity:r,stretch:o}=e;Ft(i||"center",n,Ut),Ft(a||"bottom",n,jt);const l=t.Platform.conicGradientSupport?t.Platform.canvas.createConicGradient(0,Ut.x,Ut.y):t.Platform.canvas.createRadialGradient(Ut.x,Ut.y,0,Ut.x,Ut.y,Ht(Ut,jt)),d={type:s,style:l};kt(d,l,e.stops,r);const c=It(n,Ut,jt,o||1,t.Platform.conicGradientRotate90);return c&&(d.transform=c),d},getTransform:It},{copy:zt,toOffsetOutBounds:Gt}=t.BoundsHelper,Xt={},Nt={};function qt(e,n,i,a){const{bounds:s,shapeBounds:r}=a;if(t.Platform.fullImageShadow){if(zt(Xt,e.bounds),Xt.x+=n.x-r.x,Xt.y+=n.y-r.y,i){const{fitMatrix:t}=a;Xt.x-=(s.x+(t?t.e:0)+s.width/2)*(i-1),Xt.y-=(s.y+(t?t.f:0)+s.height/2)*(i-1),Xt.width*=i,Xt.height*=i}e.copyWorld(a.canvas,e.bounds,Xt)}else i&&(zt(Xt,n),Xt.x-=n.width/2*(i-1),Xt.y-=n.height/2*(i-1),Xt.width*=i,Xt.height*=i),e.copyWorld(a.canvas,r,i?Xt:n)}const{toOffsetOutBounds:Vt}=t.BoundsHelper,Qt={};const Jt={shadow:function(e,i,a){let s,r;const{__nowWorld:o,__layout:l}=e,{shadow:d}=e.__,{worldCanvas:c,bounds:h,shapeBounds:u,scaleX:f,scaleY:p}=a,g=i.getSameCanvas(),_=d.length-1;Gt(h,Nt),d.forEach((d,y)=>{let m=1;if(d.scaleFixed){const t=Math.abs(o.scaleX);t>1&&(m=1/t)}g.setWorldShadow(Nt.offsetX+d.x*f*m,Nt.offsetY+d.y*p*m,d.blur*f*m,n.ColorConvert.string(d.color)),r=d.spread?1+2*d.spread/(l.boxBounds.width+2*(l.strokeBoxSpread||0))*m:0,qt(g,Nt,r,a),s=h,d.box&&(g.restore(),g.save(),c&&(g.copyWorld(g,h,o,"copy"),s=o),c?g.copyWorld(c,o,o,"destination-out"):g.copyWorld(a.canvas,u,h,"destination-out")),t.LeafHelper.copyCanvasByWorld(e,i,g,s,d.blendMode),_&&y<_&&g.clearWorld(s,!0)}),g.recycle(s)},innerShadow:function(e,i,a){let s,r;const{__nowWorld:o,__layout:l}=e,{innerShadow:d}=e.__,{worldCanvas:c,bounds:h,shapeBounds:u,scaleX:f,scaleY:p}=a,g=i.getSameCanvas(),_=d.length-1;Vt(h,Qt),d.forEach((d,y)=>{let m=1;if(d.scaleFixed){const t=Math.abs(o.scaleX);t>1&&(m=1/t)}g.save(),g.setWorldShadow(Qt.offsetX+d.x*f*m,Qt.offsetY+d.y*p*m,d.blur*f*m),r=d.spread?1-2*d.spread/(l.boxBounds.width+2*(l.strokeBoxSpread||0))*m:0,qt(g,Qt,r,a),g.restore(),c?(g.copyWorld(g,h,o,"copy"),g.copyWorld(c,o,o,"source-out"),s=o):(g.copyWorld(a.canvas,u,h,"source-out"),s=h),g.fillWorld(s,n.ColorConvert.string(d.color),"source-in"),t.LeafHelper.copyCanvasByWorld(e,i,g,s,d.blendMode),_&&y<_&&g.clearWorld(s,!0)}),g.recycle(s)},blur:function(t,e,n){const{blur:i}=t.__;n.setWorldBlur(i*t.__nowWorld.a),n.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),n.filter="none"},backgroundBlur:function(t,e,n){}},{excludeRenderBounds:Zt}=t.LeafBoundsHelper;let Kt;function $t(t,e,n,i,a,s,r,o){switch(e){case"grayscale":Kt||(Kt=!0,a.useGrayscaleAlpha(t.__nowWorld));case"alpha":!function(t,e,n,i,a,s){const r=t.__nowWorld;n.resetTransform(),n.opacity=1,n.useMask(i,r),s&&i.recycle(r);ee(t,e,n,1,a,s)}(t,n,i,a,r,o);break;case"opacity-path":ee(t,n,i,s,r,o);break;case"path":o&&n.restore()}}function te(t){return t.getSameCanvas(!1,!0)}function ee(t,e,n,i,a,s){const r=t.__nowWorld;e.resetTransform(),e.opacity=i,e.copyWorld(n,r,void 0,a),s?n.recycle(r):n.clearWorld(r,!0)}n.Group.prototype.__renderMask=function(t,e){let n,i,a,s,r,o;const{children:l}=this;for(let d=0,c=l.length;d<c;d++){if(n=l[d],o=n.__.mask,o){r&&($t(this,r,t,a,i,s,void 0,!0),i=a=null),s=n.__.opacity,Kt=!1,"path"===o||"clipping-path"===o?(s<1?(r="opacity-path",a||(a=te(t))):(r="path",t.save()),n.__clip(a||t,e)):(r="grayscale"===o?"grayscale":"alpha",i||(i=te(t)),a||(a=te(t)),n.__render(i,e)),"clipping"!==o&&"clipping-path"!==o||Zt(n,e)||n.__render(t,e);continue}const c=1===s&&n.__.__blendMode;c&&$t(this,r,t,a,i,s,void 0,!1),Zt(n,e)||n.__render(a||t,e),c&&$t(this,r,t,a,i,s,c,!1)}$t(this,r,t,a,i,s,void 0,!0)};const ne=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",ie=ne+"_#~&*+\\=|≮≯≈≠=…",ae=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map(([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`).join("|"));function se(t){const e={};return t.split("").forEach(t=>e[t]=!0),e}const re=se("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),oe=se("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),le=se(ne),de=se(ie),ce=se("- —/~|┆·");var he;!function(t){t[t.Letter=0]="Letter",t[t.Single=1]="Single",t[t.Before=2]="Before",t[t.After=3]="After",t[t.Symbol=4]="Symbol",t[t.Break=5]="Break"}(he||(he={}));const{Letter:ue,Single:fe,Before:pe,After:ge,Symbol:_e,Break:ye}=he;function me(t){return re[t]?ue:ce[t]?ye:oe[t]?pe:le[t]?ge:de[t]?_e:ae.test(t)?fe:ue}const ve={trimRight(t){const{words:e}=t;let n,i=0,a=e.length;for(let s=a-1;s>-1&&(n=e[s].data[0]," "===n.char);s--)i++,t.width-=n.width;i&&e.splice(a-i,i)}};function we(t,e,n){switch(e){case"title":return n?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:xe}=ve,{Letter:be,Single:Ee,Before:Be,After:Re,Symbol:Se,Break:Le}=he;let ke,Pe,Ce,Ae,Oe,Te,We,Me,De,Ie,He,Fe,Ue,je,Ye,ze,Ge,Xe=[];function Ne(t,e){De&&!Me&&(Me=De),ke.data.push({char:t,width:e}),Ce+=e}function qe(){Ae+=Ce,ke.width=Ce,Pe.words.push(ke),ke={data:[]},Ce=0}function Ve(){je&&(Ye.paraNumber++,Pe.paraStart=!0,je=!1),De&&(Pe.startCharSize=Me,Pe.endCharSize=De,Me=0),Pe.width=Ae,ze.width?xe(Pe):Ge&&Qe(),Xe.push(Pe),Pe={words:[]},Ae=0}function Qe(){Ae>(Ye.maxWidth||0)&&(Ye.maxWidth=Ae)}const{top:Je,right:Ze,bottom:Ke,left:$e}=t.Direction4;function tn(t,e,n){const{bounds:i,rows:a}=t;i[e]+=n;for(let t=0;t<a.length;t++)a[t][e]+=n}const en={getDrawData:function(e,i){t.isString(e)||(e=String(e));let a=0,s=0,r=i.__getInput("width")||0,o=i.__getInput("height")||0;const{textDecoration:l,__font:d,__padding:c}=i;c&&(r?(a=c[$e],r-=c[Ze]+c[$e]):i.autoSizeAlign||(a=c[$e]),o?(s=c[Je],o-=c[Je]+c[Ke]):i.autoSizeAlign||(s=c[Je]));const h={bounds:{x:a,y:s,width:r,height:o},rows:[],paraNumber:0,font:t.Platform.canvas.font=d};return function(e,n,i){Ye=e,Xe=e.rows,ze=e.bounds,Ge=!ze.width&&!i.autoSizeAlign;const{__letterSpacing:a,paraIndent:s,textCase:r}=i,{canvas:o}=t.Platform,{width:l,height:d}=ze;if(l||d||a||"none"!==r){const t="none"!==i.textWrap,e="break"===i.textWrap;je=!0,He=null,Me=We=De=Ce=Ae=0,ke={data:[]},Pe={words:[]},a&&(n=[...n]);for(let i=0,d=n.length;i<d;i++)Te=n[i],"\n"===Te?(Ce&&qe(),Pe.paraEnd=!0,Ve(),je=!0):(Ie=me(Te),Ie===be&&"none"!==r&&(Te=we(Te,r,!Ce)),We=o.measureText(Te).width,a&&(a<0&&(De=We),We+=a),Fe=Ie===Ee&&(He===Ee||He===be)||He===Ee&&Ie!==Re,Ue=!(Ie!==Be&&Ie!==Ee||He!==Se&&He!==Re),Oe=je&&s?l-s:l,t&&l&&Ae+Ce+We>Oe&&(e?(Ce&&qe(),Ae&&Ve()):(Ue||(Ue=Ie===be&&He==Re),Fe||Ue||Ie===Le||Ie===Be||Ie===Ee||Ce+We>Oe?(Ce&&qe(),Ae&&Ve()):Ae&&Ve()))," "===Te&&!0!==je&&Ae+Ce===0||(Ie===Le?(" "===Te&&Ce&&qe(),Ne(Te,We),qe()):Fe||Ue?(Ce&&qe(),Ne(Te,We)):Ne(Te,We)),He=Ie);Ce&&qe(),Ae&&Ve(),Xe.length>0&&(Xe[Xe.length-1].paraEnd=!0)}else n.split("\n").forEach(t=>{Ye.paraNumber++,Ae=o.measureText(t).width,Xe.push({x:s||0,text:t,width:Ae,paraStart:!0}),Ge&&Qe()})}(h,e,i),c&&function(t,e,n,i,a){if(!i&&n.autoSizeAlign)switch(n.textAlign){case"left":tn(e,"x",t[$e]);break;case"right":tn(e,"x",-t[Ze])}if(!a&&n.autoSizeAlign)switch(n.verticalAlign){case"top":tn(e,"y",t[Je]);break;case"bottom":tn(e,"y",-t[Ke])}}(c,h,i,r,o),function(t,e){const{rows:n,bounds:i}=t,a=n.length,{__lineHeight:s,__baseLine:r,__letterSpacing:o,__clipText:l,textAlign:d,verticalAlign:c,paraSpacing:h,autoSizeAlign:u}=e;let{x:f,y:p,width:g,height:_}=i,y=s*a+(h?h*(t.paraNumber-1):0),m=r;if(l&&y>_)y=Math.max(_,s),a>1&&(t.overflow=a);else if(_||u)switch(c){case"middle":p+=(_-y)/2;break;case"bottom":p+=_-y}m+=p;let v,w,x,b=g||u?g:t.maxWidth;for(let r=0,c=a;r<c;r++){if(v=n[r],v.x=f,v.width<g||v.width>g&&!l)switch(d){case"center":v.x+=(b-v.width)/2;break;case"right":v.x+=b-v.width}v.paraStart&&h&&r>0&&(m+=h),v.y=m,m+=s,t.overflow>r&&m>y&&(v.isOverflow=!0,t.overflow=r+1),w=v.x,x=v.width,o<0&&(v.width<0?(x=-v.width+e.fontSize+o,w-=x,x+=e.fontSize):x-=o),w<i.x&&(i.x=w),x>i.width&&(i.width=x),l&&g&&g<x&&(v.isOverflow=!0,t.overflow||(t.overflow=n.length))}i.y=p,i.height=y}(h,i),function(t,e,n){const{rows:i}=t,{textAlign:a,paraIndent:s,letterSpacing:r}=e;let o,l,d,c,h,u;i.forEach(t=>{t.words&&(d=s&&t.paraStart?s:0,u=t.words.length,l=n&&("justify"===a||"both"===a)&&u>1?(n-t.width-d)/(u-1):0,c=r||t.isOverflow?0:l>.01?1:2,t.isOverflow&&!r&&(t.textMode=!0),2===c?(t.x+=d,function(t){t.text="",t.words.forEach(e=>{e.data.forEach(e=>{t.text+=e.char})})}(t)):(t.x+=d,o=t.x,t.data=[],t.words.forEach((e,n)=>{1===c?(h={char:"",x:o},o=function(t,e,n){return t.forEach(t=>{n.char+=t.char,e+=t.width}),e}(e.data,o,h),(t.isOverflow||" "!==h.char)&&t.data.push(h)):o=function(t,e,n,i){return t.forEach(t=>{(i||" "!==t.char)&&(t.x=e,n.push(t)),e+=t.width}),e}(e.data,o,t.data,t.isOverflow),!l||t.paraEnd&&"both"!==a||n===u-1||(o+=l,t.width+=l)})),t.words=null)})}(h,i,r),h.overflow&&function(e,n,i,a){if(!a)return;const{rows:s,overflow:r}=e;let{textOverflow:o}=n;if(s.splice(r),o&&"show"!==o){let e,l;"hide"===o?o="":"ellipsis"===o&&(o="...");const d=o?t.Platform.canvas.measureText(o).width:0,c=i+a-d;("none"===n.textWrap?s:[s[r-1]]).forEach(t=>{if(t.isOverflow&&t.data){let n=t.data.length-1;for(let i=n;i>-1&&(e=t.data[i],l=e.x+e.width,!(i===n&&l<c));i--){if(l<c&&" "!==e.char||!i){t.data.splice(i+1),t.width-=e.width;break}t.width-=e.width}t.width+=d,t.data.push({char:o,x:l}),t.textMode&&function(t){t.text="",t.data.forEach(e=>{t.text+=e.char}),t.data=null}(t)}})}}(h,i,a,r),"none"!==l&&function(e,i){let a;const{fontSize:s,textDecoration:r}=i;switch(e.decorationHeight=s/11,t.isObject(r)?(a=r.type,r.color&&(e.decorationColor=n.ColorConvert.string(r.color))):a=r,a){case"under":e.decorationY=[.15*s];break;case"delete":e.decorationY=[.35*-s];break;case"under-delete":e.decorationY=[.15*s,.35*-s]}}(h,i),h}};const nn={string:function(e,i){const a=t.isNumber(i)&&i<1;if(t.isString(e)){if(!a||!n.ColorConvert.object)return e;e=n.ColorConvert.object(e)}let s=t.isUndefined(e.a)?1:e.a;a&&(s*=i);const r=e.r+","+e.g+","+e.b;return 1===s?"rgb("+r+")":"rgba("+r+","+s+")"}};Object.assign(n.TextConvert,en),Object.assign(n.ColorConvert,nn),Object.assign(n.Paint,H),Object.assign(n.PaintImage,Et),Object.assign(n.PaintGradient,Yt),Object.assign(n.Effect,Jt);const{setPoint:an,addPoint:sn,toBounds:rn}=n.TwoPointBoundsHelper;const on={syncExport(t,e,i){let a;n.Export.running=!0;try{const s=n.FileHelper.fileType(e),r=e.includes(".");i=n.FileHelper.getExportOptions(i);const{toURL:o}=n.Platform,{download:l}=n.Platform.origin;if("json"===s)r&&l(o(JSON.stringify(t.toJSON(i.json)),"text"),e),a={data:!!r||t.toJSON(i.json)};else if("svg"===s)r&&l(o(t.toSVG(),"svg"),e),a={data:!!r||t.toSVG()};else{let s,r,o=1,l=1;const{worldTransform:d,isLeafer:c,leafer:h,isFrame:u}=t,{slice:f,clip:p,trim:g,screenshot:_,padding:y,onCanvas:m}=i,v=n.isUndefined(i.smooth)?!h||h.config.smooth:i.smooth,w=i.contextSettings||(h?h.config.contextSettings:void 0),x=c&&_&&n.isUndefined(i.fill)?t.fill:i.fill,b=n.FileHelper.isOpaqueImage(e)||x,E=new n.Matrix;if(_)s=!0===_?c?h.canvas.bounds:t.worldRenderBounds:_;else{let e=i.relative||(c?"inner":"local");switch(o=d.scaleX,l=d.scaleY,e){case"inner":E.set(d);break;case"local":E.set(d).divide(t.localTransform),o/=t.scaleX,l/=t.scaleY;break;case"world":o=1,l=1;break;case"page":e=h||t;default:E.set(d).divide(t.getTransform(e));const n=e.worldTransform;o/=o/n.scaleX,l/=l/n.scaleY}s=t.getBounds("render",e)}const B={scaleX:1,scaleY:1};n.MathHelper.getScaleData(i.scale,i.size,s,B);let R=i.pixelRatio||1,{x:S,y:L,width:k,height:P}=new n.Bounds(s).scale(B.scaleX,B.scaleY);p&&(S+=p.x,L+=p.y,k=p.width,P=p.height);const C={exporting:!0,matrix:E.scale(1/B.scaleX,1/B.scaleY).invert().translate(-S,-L).withScale(1/o*B.scaleX,1/l*B.scaleY)};let A,O=n.Creator.canvas({width:Math.floor(k),height:Math.floor(P),pixelRatio:R,smooth:v,contextSettings:w});if(f&&(A=t,A.__worldOpacity=0,t=h||t,C.bounds=O.bounds),O.save(),u&&!n.isUndefined(x)){const e=t.get("fill");t.fill="",t.__render(O,C),t.fill=e}else t.__render(O,C);if(O.restore(),A&&A.__updateWorldOpacity(),g){r=function(t){const{width:e,height:i}=t.view,{data:a}=t.context.getImageData(0,0,e,i);let s,r,o,l=0;for(let t=0;t<a.length;t+=4)0!==a[t+3]&&(s=l%e,r=(l-s)/e,o?sn(o,s,r):an(o={},s,r)),l++;const d=new n.Bounds;return o&&(rn(o,d),d.scale(1/t.pixelRatio).ceil()),d}(O);const t=O,{width:e,height:i}=r,a={x:0,y:0,width:e,height:i,pixelRatio:R};O=n.Creator.canvas(a),O.copyWorld(t,r,a),t.destroy()}if(y){const[t,e,i,a]=n.MathHelper.fourNumber(y),s=O,{width:r,height:o}=s;O=n.Creator.canvas({width:r+a+e,height:o+t+i,pixelRatio:R}),O.copyWorld(s,s.bounds,{x:a,y:t,width:r,height:o}),s.destroy()}b&&O.fillWorld(O.bounds,x||"#FFFFFF","destination-over"),m&&m(O);a={data:"canvas"===e?O:O.export(e,i),width:O.pixelWidth,height:O.pixelHeight,renderBounds:s,trimBounds:r}}}catch(t){a={data:"",error:t}}return n.Export.running=!1,a},export(t,e,a){return n.Export.running=!0,function(t){ln||(ln=new n.TaskProcessor);return new Promise(e=>{ln.add(()=>i(this,void 0,void 0,function*(){return yield t(e)}),{parallel:!1})})}(s=>new Promise(r=>{const o=()=>i(this,void 0,void 0,function*(){if(!n.Resource.isComplete)return n.Platform.requestRender(o);const i=n.Export.syncExport(t,e,a);i.data instanceof Promise&&(i.data=yield i.data),s(i),r()});t.updateLayout(),dn(t);const{leafer:l}=t;l?l.waitViewCompleted(o):o()}))}};let ln;function dn(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach(t=>dn(t))}const cn=n.LeaferCanvasBase.prototype,hn=n.Debug.get("@leafer-in/export");cn.export=function(t,e){const{quality:i,blob:a}=n.FileHelper.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):a?this.toBlob(t,i):this.toDataURL(t,i)},cn.toBlob=function(t,e){return new Promise(i=>{n.Platform.origin.canvasToBolb(this.view,t,e).then(t=>{i(t)}).catch(t=>{hn.error(t),i(null)})})},cn.toDataURL=function(t,e){return n.Platform.origin.canvasToDataURL(this.view,t,e)},cn.saveAs=function(t,e){return new Promise(i=>{n.Platform.origin.canvasSaveAs(this.view,t,e).then(()=>{i(!0)}).catch(t=>{hn.error(t),i(!1)})})},n.Plugin.add("export"),Object.assign(n.Export,on),n.UI.prototype.export=function(t,e){return n.Export.export(this,t,e)},n.UI.prototype.syncExport=function(t,e){return n.Export.syncExport(this,t,e)},Object.defineProperty(exports,"LeaferImage",{enumerable:!0,get:function(){return t.LeaferImage}}),exports.Layouter=m,exports.LeaferCanvas=a,exports.Renderer=w,exports.Watcher=o,exports.useCanvas=function(n,a){if(t.Platform.canvasType=n,!t.Platform.origin){if("skia"===n){const{Canvas:e,loadImage:n}=a;t.Platform.origin={createCanvas:(t,n,i)=>new e(t,n,i),canvasToDataURL:(t,e,n)=>t.toDataURLSync(e,{quality:n}),canvasToBolb:(t,e,n)=>t.toBuffer(e,{quality:n}),canvasSaveAs:(t,e,n)=>t.saveAs(e,{quality:n}),download(t,e){},loadImage:e=>n(t.Platform.image.getRealURL(e))},t.Platform.roundRectPatch=!0}else if("napi"===n){const{Canvas:n,loadImage:o}=a;t.Platform.origin={createCanvas:(t,e,i)=>new n(t,e,i),canvasToDataURL:(t,e,n)=>t.toDataURL(s(e),n),canvasToBolb:(t,e,n)=>i(this,void 0,void 0,function*(){return t.toBuffer(s(e),n)}),canvasSaveAs:(t,n,a)=>i(this,void 0,void 0,function*(){return e.writeFileSync(n,t.toBuffer(s(r(n)),a))}),download(t,e){},loadImage:e=>o(t.Platform.image.getRealURL(e))}}t.Platform.ellipseToCurve=!0,t.Platform.event={stopDefault(t){},stopNow(t){},stop(t){}},t.Platform.canvas=t.Creator.canvas()}},Object.keys(t).forEach(function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}),Object.keys(n).forEach(function(t){"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return n[t]}})});
2
2
  //# sourceMappingURL=node.min.cjs.map