@leafer-draw/node 1.4.2 → 1.5.1

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.
@@ -1,2 +1,2 @@
1
- import{LeaferCanvasBase as t,Platform as e,canvasPatch as i,FileHelper as n,Creator as s,LeaferImage as o,defineKey as a,LeafList as r,DataHelper as d,RenderEvent as l,ChildEvent as c,WatchEvent as h,PropertyEvent as u,LeafHelper as f,BranchHelper as p,LeafBoundsHelper as _,Bounds as g,Debug as w,LeafLevelList as y,LayoutEvent as m,Run as v,ImageManager as x,ResizeEvent as b,BoundsHelper as B,MatrixHelper as R,MathHelper as k,AlignHelper as S,ImageEvent as E,AroundHelper as L,PointHelper as A,Direction4 as W}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{writeFileSync as T}from"fs";import{PaintImage as O,ColorConvert as C,PaintGradient as M,Export as D,Group as I,TextConvert as P,Paint as F,Effect as Y,TwoPointBoundsHelper as U,Bounds as X,FileHelper as N,TaskProcessor as z,Platform as G,Matrix as j,MathHelper as q,Creator as V,LeaferCanvasBase as H,Debug as Q,Plugin as J,UI as Z}from"@leafer-ui/draw";export*from"@leafer-ui/draw";function $(t,e,i,n){return new(i||(i=Promise))((function(s,o){function a(t){try{d(n.next(t))}catch(t){o(t)}}function r(t){try{d(n.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}d((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class K extends t{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config),e.roundRectPatch&&(this.context.__proto__.roundRect=null,i(this.context.__proto__))}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this;this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i),this.clientBounds=this.bounds}}const{mineType:tt,fileType:et}=n;function it(t,i){if(e.canvasType=t,!e.origin){if("skia"===t){const{Canvas:t,loadImage:n}=i;e.origin={createCanvas:(e,i,n)=>new t(e,i,n),canvasToDataURL:(t,e,i)=>t.toDataURLSync(e,{quality:i}),canvasToBolb:(t,e,i)=>t.toBuffer(e,{quality:i}),canvasSaveAs:(t,e,i)=>t.saveAs(e,{quality:i}),download(t,e){},loadImage:t=>n(e.image.getRealURL(t))},e.roundRectPatch=!0}else if("napi"===t){const{Canvas:t,loadImage:n}=i;e.origin={createCanvas:(e,i,n)=>new t(e,i,n),canvasToDataURL:(t,e,i)=>t.toDataURL(tt(e),i),canvasToBolb:(t,e,i)=>$(this,void 0,void 0,(function*(){return t.toBuffer(tt(e),i)})),canvasSaveAs:(t,e,i)=>$(this,void 0,void 0,(function*(){return T(e,t.toBuffer(tt(et(e)),i))})),download(t,e){},loadImage:t=>n(e.image.getRealURL(t))}}e.ellipseToCurve=!0,e.event={stopDefault(t){},stopNow(t){},stop(t){}},e.canvas=s.canvas()}}Object.assign(s,{canvas:(t,e)=>new K(t,e),image:t=>new o(t)}),e.name="node",e.backgrounder=!0,e.requestRender=function(t){setTimeout(t,16)},a(e,"devicePixelRatio",{get:()=>1}),e.conicGradientSupport=!0;class nt{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new r;return this.__updatedList.list.forEach((e=>{e.leafer&&t.add(e)})),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new r,this.target=t,e&&(this.config=d.default(e,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(l.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===c.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new h(h.DATA,{updatedList:this.updatedList})),this.__updatedList=new r,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.CHANGE,this.__onAttrChange,this),t.on_([c.ADD,c.REMOVE],this.__onChildEvent,this),t.on_(h.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:st,updateBounds:ot,updateAllWorldOpacity:at}=f,{pushAllChildBranch:rt,pushAllParent:dt}=p;const{worldBounds:lt}=_,ct={x:0,y:0,width:1e5,height:1e5};class ht{constructor(t){this.updatedBounds=new g,this.beforeBounds=new g,this.afterBounds=new g,t instanceof Array&&(t=new r(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,lt)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(ct):this.afterBounds.setListWithFn(t,lt),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:ut,updateAllChange:ft}=f,pt=w.get("Layouter");class _t{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new y,this.target=t,e&&(this.config=d.default(e,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.running)return;const{target:t}=this;this.times=0;try{t.emit(m.START),this.layoutOnce(),t.emitEvent(new m(m.END,this.layoutedBlocks,this.times))}catch(t){pt.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?pt.warn("layouting"):this.times>3?pt.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(h.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=v.start("PartLayout"),{target:i,__updatedList:n}=this,{BEFORE:s,LAYOUT:o,AFTER:a}=m,r=this.getBlocks(n);r.forEach((t=>t.setBefore())),i.emitEvent(new m(s,r,this.times)),this.extraBlock=null,n.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(st(t,!0),e.add(t),t.isBranch&&rt(t,e),dt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),dt(t,e)))}))}(n,this.__levelList),function(t){let e,i,n;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(i=e[t],i.isBranch&&i.__tempNumber){n=i.children;for(let t=0,e=n.length;t<e;t++)n[t].isBranch||ot(n[t])}ot(i)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&at(t),e.stateStyleChanged&&setTimeout((()=>e.stateStyleChanged&&t.updateState())),t.__updateChange()}))}(n),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new m(o,r,this.times)),i.emitEvent(new m(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,v.end(e)}fullLayout(){const t=v.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:n,AFTER:s}=m,o=this.getBlocks(new r(e));e.emitEvent(new m(i,o,this.times)),_t.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new m(n,o,this.times)),e.emitEvent(new m(s,o,this.times)),this.addBlocks(o),v.end(t)}static fullLayout(t){ut(t,!0),t.isBranch?p.updateBounds(t):f.updateBounds(t),ft(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new ht([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new ht(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(){const{target:t}=this;this.__eventIds=[t.on_(m.REQUEST,this.layout,this),t.on_(m.AGAIN,this.layoutAgain,this),t.on_(h.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const gt=w.get("Renderer");class wt{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,i&&(this.config=d.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(m.REQUEST)}render(t){if(!this.running||!this.canvas.view)return this.update();const{target:e}=this;this.times=0,this.totalBounds=new g,gt.log(e.innerName,"---\x3e");try{e.isApp||e.app.emit(l.CHILD_START,e),this.emitRender(l.START),this.renderOnce(t),this.emitRender(l.END,this.totalBounds),x.clearRecycled()}catch(t){this.rendering=!1,gt.error(t)}gt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return gt.warn("rendering");if(this.times>3)return gt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new g,this.renderOptions={},t)this.emitRender(l.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(l.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(l.RENDER,this.renderBounds,this.renderOptions),this.emitRender(l.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(t){const e=v.start("PartRender"),{canvas:i}=this,n=t.getIntersect(i.bounds),s=t.includes(this.target.__world),o=new g(n);i.save(),s&&!w.showRepaint?i.clear():(n.spread(10+1/this.canvas.pixelRatio).ceil(),i.clearWorld(n,!0),i.clipWorld(n,!0)),this.__render(n,s,o),i.restore(),v.end(e)}fullRender(){const t=v.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),v.end(t)}__render(t,e,i){const n=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),w.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,n),this.renderBounds=i=i||t,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=i:this.totalBounds.add(i),w.showHitView&&this.renderHitView(n),w.showBoundsView&&this.renderBoundsView(n),this.canvas.updateRender(i)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new g;e.setList(t),t.length=0,t.push(e)}}__requestRender(){if(this.requestTime)return;const t=this.requestTime=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.requestTime=0,this.running&&(this.changed&&this.canvas.view&&this.render(),this.target.emit(l.NEXT))}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new g(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new g(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||gt.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,i){this.target.emitEvent(new l(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(l.REQUEST,this.update,this),t.on_(m.END,this.__onLayoutEnd,this),t.on_(l.AGAIN,this.renderAgain,this),t.on_(b.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 yt(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),s&&e.fillRect(i.x,i.y+s,i.width,o)}function mt(t,e,i){const{strokeAlign:n}=e.__,s="string"!=typeof t;switch(n){case"center":i.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?bt(t,!0,e,i):xt(e,i);break;case"inside":vt("inside",t,s,e,i);break;case"outside":vt("outside",t,s,e,i)}}function vt(t,e,i,n,s){const{__strokeWidth:o,__font:a}=n.__,r=s.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,n.__),r.font=a,i?bt(e,!0,n,r):xt(n,r),r.blendMode="outside"===t?"destination-out":"destination-in",yt(n,r),r.blendMode="normal",n.__worldFlipped?s.copyWorldByReset(r,n.__nowWorld):s.copyWorldToInner(r,n.__nowWorld,n.__layout.renderBounds),r.recycle(n.__nowWorld)}function xt(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),s&&e.strokeRect(i.x,i.y+s,i.width,o)}function bt(t,e,i,n){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&O.checkImage(i,n,s,!1)||s.style&&(n.strokeStyle=s.style,s.blendMode?(n.saveBlendMode(s.blendMode),e?xt(i,n):n.stroke(),n.restoreBlendMode()):e?xt(i,n):n.stroke())}function Bt(t,e){t.__.dashPattern&&(e.beginPath(),t.__drawPathByData(e,t.__.__pathForArrow),e.dashPattern=null,e.stroke())}Object.assign(s,{watcher:(t,e)=>new nt(t,e),layouter:(t,e)=>new _t(t,e),renderer:(t,e,i)=>new wt(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,n)=>{}}),e.layout=_t.fullLayout;const{getSpread:Rt,getOuterOf:kt,getByMove:St,getIntersectData:Et}=B;let Lt;function At(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:n}=i.__layout;switch(e.type){case"solid":let{type:s,blendMode:o,color:a,opacity:r}=e;return{type:s,blendMode:o,style:C.string(a,r)};case"image":return O.image(i,t,e,n,!Lt||!Lt[e.url]);case"linear":return M.linearGradient(e,n);case"radial":return M.radialGradient(e,n);case"angular":return M.conicGradient(e,n);default:return void 0!==e.r?{type:"solid",style:C.string(e)}:void 0}}const Wt={compute:function(t,e){const i=e.__,n=[];let s,o=i.__input[t];o instanceof Array||(o=[o]),Lt=O.recycleImage(t,i);for(let i,s=0,a=o.length;s<a;s++)i=At(t,o[s],e),i&&n.push(i);i["_"+t]=n.length?n:void 0,n.length&&n[0].image&&(s=n[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=s:i.__pixelStroke=s},fill:function(t,e,i){i.fillStyle=t,e.__.__font?yt(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let n;const{windingRule:s,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)n=t[a],n.image&&O.checkImage(e,i,n,!o)||n.style&&(i.fillStyle=n.style,n.transform?(i.save(),i.transform(n.transform),n.blendMode&&(i.blendMode=n.blendMode),o?yt(e,i):s?i.fill(s):i.fill(),i.restore()):n.blendMode?(i.saveBlendMode(n.blendMode),o?yt(e,i):s?i.fill(s):i.fill(),i.restoreBlendMode()):o?yt(e,i):s?i.fill(s):i.fill())},fillText:yt,stroke:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)mt(t,e,i);else switch(o){case"center":i.setStroke(t,s,n),i.stroke(),n.__useArrow&&Bt(e,i);break;case"inside":i.save(),i.setStroke(t,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*s,n),e.__drawRenderPath(o),o.stroke(),n.windingRule?o.clip(n.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?i.copyWorldByReset(o,e.__nowWorld):i.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)mt(t,e,i);else switch(o){case"center":i.setStroke(void 0,s,n),bt(t,!1,e,i),n.__useArrow&&Bt(e,i);break;case"inside":i.save(),i.setStroke(void 0,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),bt(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*s,n),bt(t,!1,e,a),n.windingRule?a.clip(n.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:mt,drawTextStroke:xt,shape:function(t,e,i){const n=e.getSameCanvas(),s=t.__nowWorld;let o,a,r,d,{scaleX:l,scaleY:c}=s;if(l<0&&(l=-l),c<0&&(c=-c),e.bounds.includes(s))d=n,o=r=s;else{const{renderShapeSpread:n}=t.__layout,h=Et(n?Rt(e.bounds,l===c?n*l:[n*c,n*l]):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,c*=f),r=kt(s,a),o=St(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,f)})}return t.__renderShape(n,i),{canvas:n,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:c}}};let Tt={};const{get:Ot,rotateOfOuter:Ct,translate:Mt,scaleOfOuter:Dt,scale:It,rotate:Pt}=R;function Ft(t,e,i,n,s,o,a){const r=Ot();Mt(r,e.x+i,e.y+n),It(r,s,o),a&&Ct(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Yt(t,e,i,n,s,o,a){const r=Ot();Mt(r,e.x+i,e.y+n),s&&It(r,s,o),a&&Pt(r,a),t.transform=r}function Ut(t,e,i,n,s,o,a,r,d,l){const c=Ot();if(d)if("center"===l)Ct(c,{x:i/2,y:n/2},d);else switch(Pt(c,d),d){case 90:Mt(c,n,0);break;case 180:Mt(c,i,n);break;case 270:Mt(c,0,i)}Tt.x=e.x+s,Tt.y=e.y+o,Mt(c,Tt.x,Tt.y),a&&Dt(c,Tt,a,r),t.transform=c}const{get:Xt,translate:Nt}=R,zt=new g,Gt={},jt={};function qt(t,e,i,n){const{blendMode:s,sync:o}=i;s&&(t.blendMode=s),o&&(t.sync=o),t.data=Vt(i,n,e)}function Vt(t,e,i){let{width:n,height:s}=i;t.padding&&(e=zt.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{opacity:o,mode:a,align:r,offset:d,scale:l,size:c,rotation:h,repeat:u,filters:f}=t,p=e.width===n&&e.height===s,_={mode:a},g="center"!==r&&(h||0)%180==90,w=g?s:n,y=g?n:s;let m,v,x=0,b=0;if(a&&"cover"!==a&&"fit"!==a)(l||c)&&(k.getScaleData(l,c,i,jt),m=jt.scaleX,v=jt.scaleY);else if(!p||h){const t=e.width/w,i=e.height/y;m=v="fit"===a?Math.min(t,i):Math.max(t,i),x+=(e.width-n*m)/2,b+=(e.height-s*v)/2}if(r){const t={x:x,y:b,width:w,height:y};m&&(t.width*=m,t.height*=v),S.toPoint(r,t,e,Gt,!0),x+=Gt.x,b+=Gt.y}switch(d&&(x+=d.x,b+=d.y),a){case"stretch":p||(n=e.width,s=e.height);break;case"normal":case"clip":(x||b||m||h)&&Yt(_,e,x,b,m,v,h);break;case"repeat":(!p||m||h)&&Ut(_,e,n,s,x,b,m,v,h,r),u||(_.repeat="repeat");break;default:m&&Ft(_,e,x,b,m,v,h)}return _.transform||(e.x||e.y)&&(_.transform=Xt(),Nt(_.transform,e.x,e.y)),m&&"stretch"!==a&&(_.scaleX=m,_.scaleY=v),_.width=n,_.height=s,o&&(_.opacity=o),f&&(_.filters=f),u&&(_.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),_}let Ht,Qt=new g;const{isSame:Jt}=B;function Zt(t,e,i,n,s,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=n.width/e.pixelRatio,e.__naturalHeight=n.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return s.data||qt(s,n,i,o),!0}function $t(t,e){ee(t,E.LOAD,e)}function Kt(t,e){ee(t,E.LOADED,e)}function te(t,e,i){e.error=i,t.forceUpdate("surface"),ee(t,E.ERROR,e)}function ee(t,e,i){t.hasEvent(e)&&t.emitEvent(new E(e,i))}function ie(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:ne,scale:se,copy:oe}=R,{ceil:ae,abs:re}=Math;function de(t,i,n){let{scaleX:s,scaleY:o}=x.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o+"-"+n;if(i.patternId===a||t.destroyed)return!1;{s=re(s),o=re(o);const{image:t,data:r}=i;let d,l,{width:c,height:h,scaleX:u,scaleY:f,transform:p,repeat:_}=r;u&&(l=ne(),oe(l,p),se(l,1/u,1/f),s*=u,o*=f),s*=n,o*=n,c*=s,h*=o;const g=c*h;if(!_&&g>e.image.maxCacheSize)return!1;let w=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;w>e&&(w=e)}g>w&&(d=Math.sqrt(g/w)),d&&(s/=d,o/=d,c/=d,h/=d),u&&(s/=u,o/=f),(p||1!==s||1!==o)&&(l||(l=ne(),p&&oe(l,p)),se(l,1/s,1/o));const y=t.getCanvas(ae(c)||1,ae(h)||1,r.opacity,r.filters),m=t.getPattern(y,_||e.origin.noRepeat||"no-repeat",l,i);return i.style=m,i.patternId=a,!0}}const{abs:le}=Math;const ce={image:function(t,e,i,n,s){let o,a;const r=x.get(i);return Ht&&i===Ht.paint&&Jt(n,Ht.boxBounds)?o=Ht.leafPaint:(o={type:i.type,image:r},Ht=r.use>1?{leafPaint:o,paint:i,boxBounds:Qt.set(n)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(Zt(t,e,i,r,o,n),s&&($t(t,a),Kt(t,a))):r.error?s&&te(t,a,r.error):(s&&(ie(t,!0),$t(t,a)),o.loadId=r.load((()=>{ie(t,!1),t.destroyed||(Zt(t,e,i,r,o,n)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Kt(t,a)),o.loadId=null}),(e=>{ie(t,!1),te(t,a,e),o.loadId=null}))),o},checkImage:function(t,i,n,s){const{scaleX:o,scaleY:a}=x.patternLocked?t.__world:t.__nowWorld,{pixelRatio:r}=i;if(!n.data||n.patternId===o+"-"+a+"-"+r&&!D.running)return!1;{const{data:d}=n;if(s)if(d.repeat)s=!1;else{let{width:t,height:i}=d;t*=le(o)*r,i*=le(a)*r,d.scaleX&&(t*=d.scaleX,i*=d.scaleY),s=t*i>e.image.maxCacheSize||D.running}return s?(i.save(),t.windingRule?i.clip(t.windingRule):i.clip(),n.blendMode&&(i.blendMode=n.blendMode),d.opacity&&(i.opacity*=d.opacity),d.transform&&i.transform(d.transform),i.drawImage(n.image.getFull(d.filters),0,0,d.width,d.height),i.restore(),!0):(!n.style||n.sync||D.running?de(t,n,r):n.patternTask||(n.patternTask=x.patternTasker.add((()=>$(this,void 0,void 0,(function*(){n.patternTask=null,i.bounds.hit(t.__nowWorld)&&de(t,n,r),t.forceUpdate("surface")}))),300)),!1)}},createPattern:de,recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let n,s,o,a;for(let r=0,d=i.length;r<d;r++)n=i[r].image,a=n&&n.url,a&&(s||(s={}),s[a]=!0,x.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),n.unload(i[r].loadId,!o.some((t=>t.url===a)))));return s}return null},createData:qt,getPatternData:Vt,fillOrFitMode:Ft,clipMode:Yt,repeatMode:Ut},{toPoint:he}=L,ue={},fe={};function pe(t,e,i){if(e){let n;for(let s=0,o=e.length;s<o;s++)n=e[s],"string"==typeof n?t.addColorStop(s/(o-1),C.string(n,i)):t.addColorStop(n.offset,C.string(n.color,i))}}const{getAngle:_e,getDistance:ge}=A,{get:we,rotateOfOuter:ye,scaleOfOuter:me}=R,{toPoint:ve}=L,xe={},be={};function Be(t,e,i,n,s){let o;const{width:a,height:r}=t;if(a!==r||n){const t=_e(e,i);o=we(),s?(me(o,e,a/r*(n||1),1),ye(o,e,t+90)):(me(o,e,1,a/r*(n||1)),ye(o,e,t))}return o}const{getDistance:Re}=A,{toPoint:ke}=L,Se={},Ee={};const Le={linearGradient:function(t,i){let{from:n,to:s,type:o,blendMode:a,opacity:r}=t;he(n||"top",i,ue),he(s||"bottom",i,fe);const d=e.canvas.createLinearGradient(ue.x,ue.y,fe.x,fe.y);pe(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,i){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;ve(n||"center",i,xe),ve(s||"bottom",i,be);const l=e.canvas.createRadialGradient(xe.x,xe.y,0,xe.x,xe.y,ge(xe,be));pe(l,t.stops,a);const c={type:o,style:l},h=Be(i,xe,be,d,!0);return h&&(c.transform=h),r&&(c.blendMode=r),c},conicGradient:function(t,i){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;ke(n||"center",i,Se),ke(s||"bottom",i,Ee);const l=e.conicGradientSupport?e.canvas.createConicGradient(0,Se.x,Se.y):e.canvas.createRadialGradient(Se.x,Se.y,0,Se.x,Se.y,Re(Se,Ee));pe(l,t.stops,a);const c={type:o,style:l},h=Be(i,Se,Ee,d||1,e.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:Be},{copy:Ae,toOffsetOutBounds:We}=B,Te={},Oe={};function Ce(t,i,n,s){const{bounds:o,shapeBounds:a}=s;if(e.fullImageShadow){if(Ae(Te,t.bounds),Te.x+=i.x-a.x,Te.y+=i.y-a.y,n){const{matrix:t}=s;Te.x-=(o.x+(t?t.e:0)+o.width/2)*(n-1),Te.y-=(o.y+(t?t.f:0)+o.height/2)*(n-1),Te.width*=n,Te.height*=n}t.copyWorld(s.canvas,t.bounds,Te)}else n&&(Ae(Te,i),Te.x-=i.width/2*(n-1),Te.y-=i.height/2*(n-1),Te.width*=n,Te.height*=n),t.copyWorld(s.canvas,a,n?Te:i)}const{toOffsetOutBounds:Me}=B,De={};const Ie={shadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;We(l,Oe),r.forEach(((r,_)=>{f.setWorldShadow(Oe.offsetX+r.x*h,Oe.offsetY+r.y*u,r.blur*h,C.string(r.color)),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Ce(f,Oe,s,i),n=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,o,"copy"),n=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(i.canvas,c,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(n,!0)})),f.recycle(n)},innerShadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;Me(l,De),r.forEach(((r,_)=>{f.save(),f.setWorldShadow(De.offsetX+r.x*h,De.offsetY+r.y*u,r.blur*h),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Ce(f,De,s,i),f.restore(),d?(f.copyWorld(f,l,o,"copy"),f.copyWorld(d,o,o,"source-out"),n=o):(f.copyWorld(i.canvas,c,l,"source-out"),n=l),f.fillWorld(n,C.string(r.color),"source-in"),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(n,!0)})),f.recycle(n)},blur:function(t,e,i){const{blur:n}=t.__;i.setWorldBlur(n*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Pe}=_;function Fe(t,e,i,n,s,o){switch(e){case"grayscale":s.useGrayscaleAlpha(t.__nowWorld);case"alpha":!function(t,e,i,n){const s=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(n,s),n.recycle(s),Ue(t,e,i,1)}(t,i,n,s);break;case"opacity-path":Ue(t,i,n,o);break;case"path":i.restore()}}function Ye(t){return t.getSameCanvas(!1,!0)}function Ue(t,e,i,n){const s=t.__nowWorld;e.resetTransform(),e.opacity=n,e.copyWorld(i,s),i.recycle(s)}I.prototype.__renderMask=function(t,e){let i,n,s,o,a,r;const{children:d}=this;for(let l=0,c=d.length;l<c;l++)i=d[l],r=i.__.mask,r&&(a&&(Fe(this,a,t,s,n,o),n=s=null),"path"===r||"clipping-path"===r?(i.opacity<1?(a="opacity-path",o=i.opacity,s||(s=Ye(t))):(a="path",t.save()),i.__clip(s||t,e)):(a="grayscale"===r?"grayscale":"alpha",n||(n=Ye(t)),s||(s=Ye(t)),i.__render(n,e)),"clipping"!==r&&"clipping-path"!==r)||Pe(i,e)||i.__render(s||t,e);Fe(this,a,t,s,n,o)};const Xe=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Ne=Xe+"_#~&*+\\=|≮≯≈≠=…",ze=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 Ge(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const je=Ge("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),qe=Ge("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Ve=Ge(Xe),He=Ge(Ne),Qe=Ge("- —/~|┆·");var Je;!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"}(Je||(Je={}));const{Letter:Ze,Single:$e,Before:Ke,After:ti,Symbol:ei,Break:ii}=Je;function ni(t){return je[t]?Ze:Qe[t]?ii:qe[t]?Ke:Ve[t]?ti:He[t]?ei:ze.test(t)?$e:Ze}const si={trimRight(t){const{words:e}=t;let i,n=0,s=e.length;for(let o=s-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)n++,t.width-=i.width;n&&e.splice(s-n,n)}};function oi(t,e,i){switch(e){case"title":return i?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:ai}=si,{Letter:ri,Single:di,Before:li,After:ci,Symbol:hi,Break:ui}=Je;let fi,pi,_i,gi,wi,yi,mi,vi,xi,bi,Bi,Ri,ki,Si,Ei,Li,Ai,Wi=[];function Ti(t,e){xi&&!vi&&(vi=xi),fi.data.push({char:t,width:e}),_i+=e}function Oi(){gi+=_i,fi.width=_i,pi.words.push(fi),fi={data:[]},_i=0}function Ci(){Si&&(Ei.paraNumber++,pi.paraStart=!0,Si=!1),xi&&(pi.startCharSize=vi,pi.endCharSize=xi,vi=0),pi.width=gi,Li.width?ai(pi):Ai&&Mi(),Wi.push(pi),pi={words:[]},gi=0}function Mi(){gi>(Ei.maxWidth||0)&&(Ei.maxWidth=gi)}const{top:Di,right:Ii,bottom:Pi,left:Fi}=W;function Yi(t,e,i){const{bounds:n,rows:s}=t;n[e]+=i;for(let t=0;t<s.length;t++)s[t][e]+=i}const Ui={getDrawData:function(t,i){"string"!=typeof t&&(t=String(t));let n=0,s=0,o=i.__getInput("width")||0,a=i.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=i;l&&(o?(n=l[Fi],o-=l[Ii]+l[Fi]):i.autoSizeAlign||(n=l[Fi]),a?(s=l[Di],a-=l[Di]+l[Pi]):i.autoSizeAlign||(s=l[Di]));const c={bounds:{x:n,y:s,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,i,n){Ei=t,Wi=t.rows,Li=t.bounds,Ai=!Li.width&&!n.autoSizeAlign;const{__letterSpacing:s,paraIndent:o,textCase:a}=n,{canvas:r}=e,{width:d,height:l}=Li;if(d||l||s||"none"!==a){const t="none"!==n.textWrap,e="break"===n.textWrap;Si=!0,Bi=null,vi=mi=xi=_i=gi=0,fi={data:[]},pi={words:[]};for(let n=0,l=i.length;n<l;n++)yi=i[n],"\n"===yi?(_i&&Oi(),pi.paraEnd=!0,Ci(),Si=!0):(bi=ni(yi),bi===ri&&"none"!==a&&(yi=oi(yi,a,!_i)),mi=r.measureText(yi).width,s&&(s<0&&(xi=mi),mi+=s),Ri=bi===di&&(Bi===di||Bi===ri)||Bi===di&&bi!==ci,ki=!(bi!==li&&bi!==di||Bi!==hi&&Bi!==ci),wi=Si&&o?d-o:d,t&&d&&gi+_i+mi>wi&&(e?(_i&&Oi(),gi&&Ci()):(ki||(ki=bi===ri&&Bi==ci),Ri||ki||bi===ui||bi===li||bi===di||_i+mi>wi?(_i&&Oi(),gi&&Ci()):gi&&Ci()))," "===yi&&!0!==Si&&gi+_i===0||(bi===ui?(" "===yi&&_i&&Oi(),Ti(yi,mi),Oi()):Ri||ki?(_i&&Oi(),Ti(yi,mi)):Ti(yi,mi)),Bi=bi);_i&&Oi(),gi&&Ci(),Wi.length>0&&(Wi[Wi.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{Ei.paraNumber++,gi=r.measureText(t).width,Wi.push({x:o||0,text:t,width:gi,paraStart:!0}),Ai&&Mi()}))}(c,t,i),l&&function(t,e,i,n,s){if(!n&&i.autoSizeAlign)switch(i.textAlign){case"left":Yi(e,"x",t[Fi]);break;case"right":Yi(e,"x",-t[Ii])}if(!s&&i.autoSizeAlign)switch(i.verticalAlign){case"top":Yi(e,"y",t[Di]);break;case"bottom":Yi(e,"y",-t[Pi])}}(l,c,i,o,a),function(t,e){const{rows:i,bounds:n}=t,{__lineHeight:s,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:c,autoSizeAlign:h}=e;let{x:u,y:f,width:p,height:_}=n,g=s*i.length+(c?c*(t.paraNumber-1):0),w=o;if(r&&g>_)g=Math.max(_,s),t.overflow=i.length;else if(_||h)switch(l){case"middle":f+=(_-g)/2;break;case"bottom":f+=_-g}w+=f;let y,m,v,x=p||h?p:t.maxWidth;for(let o=0,l=i.length;o<l;o++){if(y=i[o],y.x=u,y.width<p||y.width>p&&!r)switch(d){case"center":y.x+=(x-y.width)/2;break;case"right":y.x+=x-y.width}y.paraStart&&c&&o>0&&(w+=c),y.y=w,w+=s,t.overflow>o&&w>g&&(y.isOverflow=!0,t.overflow=o+1),m=y.x,v=y.width,a<0&&(y.width<0?(v=-y.width+e.fontSize+a,m-=v,v+=e.fontSize):v-=a),m<n.x&&(n.x=m),v>n.width&&(n.width=v),r&&p&&p<v&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}n.y=f,n.height=g}(c,i),function(t,e,i){const{rows:n}=t,{textAlign:s,paraIndent:o,letterSpacing:a}=e;let r,d,l,c,h,u;n.forEach((t=>{t.words&&(l=o&&t.paraStart?o:0,u=t.words.length,d=i&&("justify"===s||"both"===s)&&u>1?(i-t.width-l)/(u-1):0,c=a||t.isOverflow?0:d>.01?1:2,t.isOverflow&&!a&&(t.textMode=!0),2===c?(t.x+=l,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=l,r=t.x,t.data=[],t.words.forEach(((e,i)=>{1===c?(h={char:"",x:r},r=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,r,h),(t.isOverflow||" "!==h.char)&&t.data.push(h)):r=function(t,e,i,n){return t.forEach((t=>{(n||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,r,t.data,t.isOverflow),!d||t.paraEnd&&"both"!==s||i===u-1||(r+=d,t.width+=d)}))),t.words=null)}))}(c,i,o),c.overflow&&function(t,i,n,s){if(!s)return;const{rows:o,overflow:a}=t;let{textOverflow:r}=i;if(o.splice(a),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const l=r?e.canvas.measureText(r).width:0,c=n+s-l;("none"===i.textWrap?o:[o[a-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let n=i;n>-1&&(t=e.data[n],d=t.x+t.width,!(n===i&&d<c));n--){if(d<c&&" "!==t.char){e.data.splice(n+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:r,x:d}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(c,i,n,o),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(c,i),c}};const Xi={string:function(t,e){const i="number"==typeof e&&1!==e;if("string"==typeof t){if(!i||!C.object)return t;t=C.object(t)}let n=void 0===t.a?1:t.a;i&&(n*=e);const s=t.r+","+t.g+","+t.b;return 1===n?"rgb("+s+")":"rgba("+s+","+n+")"}};Object.assign(P,Ui),Object.assign(C,Xi),Object.assign(F,Wt),Object.assign(O,ce),Object.assign(M,Le),Object.assign(Y,Ie);const{setPoint:Ni,addPoint:zi,toBounds:Gi}=U;const ji={export(t,e,i){this.running=!0;const n=N.fileType(e),s=e.includes(".");return i=N.getExportOptions(i),function(t){qi||(qi=new z);return new Promise((e=>{qi.add((()=>$(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((o=>new Promise((a=>{const r=t=>{o(t),a(),this.running=!1},{toURL:d}=G,{download:l}=G.origin;if("json"===n)return s&&l(d(JSON.stringify(t.toJSON(i.json)),"text"),e),r({data:!!s||t.toJSON(i.json)});if("svg"===n)return s&&l(d(t.toSVG(),"svg"),e),r({data:!!s||t.toSVG()});const{leafer:c}=t;c?(Vi(t),c.waitViewCompleted((()=>$(this,void 0,void 0,(function*(){let n,s,o=1,a=1;const{worldTransform:d,isLeafer:l,isFrame:h}=t,{slice:u,trim:f,padding:p,onCanvas:_}=i,g=void 0===i.smooth?c.config.smooth:i.smooth,w=i.contextSettings||c.config.contextSettings,y=i.screenshot||t.isApp,m=l&&y&&void 0===i.fill?t.fill:i.fill,v=N.isOpaqueImage(e)||m,x=new j;if(y)n=!0===y?l?c.canvas.bounds:t.worldRenderBounds:y;else{let e=i.relative||(l?"inner":"local");switch(o=d.scaleX,a=d.scaleY,e){case"inner":x.set(d);break;case"local":x.set(d).divide(t.localTransform),o/=t.scaleX,a/=t.scaleY;break;case"world":o=1,a=1;break;case"page":e=t.leafer;default:x.set(d).divide(t.getTransform(e));const i=e.worldTransform;o/=o/i.scaleX,a/=a/i.scaleY}n=t.getBounds("render",e)}const b={scaleX:1,scaleY:1};q.getScaleData(i.scale,i.size,n,b);let B=i.pixelRatio||1;t.isApp&&(b.scaleX*=B,b.scaleY*=B,B=t.app.pixelRatio);const{x:R,y:k,width:S,height:E}=new X(n).scale(b.scaleX,b.scaleY),L={matrix:x.scale(1/b.scaleX,1/b.scaleY).invert().translate(-R,-k).withScale(1/o*b.scaleX,1/a*b.scaleY)};let A,W=V.canvas({width:Math.round(S),height:Math.round(E),pixelRatio:B,smooth:g,contextSettings:w});if(u&&(A=t,A.__worldOpacity=0,t=c,L.bounds=W.bounds),W.save(),h&&void 0!==m){const e=t.get("fill");t.fill="",t.__render(W,L),t.fill=e}else t.__render(W,L);if(W.restore(),A&&A.__updateWorldOpacity(),f){s=function(t){const{width:e,height:i}=t.view,{data:n}=t.context.getImageData(0,0,e,i);let s,o,a,r=0;for(let t=0;t<n.length;t+=4)0!==n[t+3]&&(s=r%e,o=(r-s)/e,a?zi(a,s,o):Ni(a={},s,o)),r++;const d=new X;return Gi(a,d),d.scale(1/t.pixelRatio).ceil()}(W);const t=W,{width:e,height:i}=s,n={x:0,y:0,width:e,height:i,pixelRatio:B};W=V.canvas(n),W.copyWorld(t,s,n)}if(p){const[t,e,i,n]=q.fourNumber(p),s=W,{width:o,height:a}=s;W=V.canvas({width:o+n+e,height:a+t+i,pixelRatio:B}),W.copyWorld(s,s.bounds,{x:n,y:t,width:o,height:a})}v&&W.fillWorld(W.bounds,m||"#FFFFFF","destination-over"),_&&_(W);const T="canvas"===e?W:yield W.export(e,i);r({data:T,width:W.pixelWidth,height:W.pixelHeight,renderBounds:n,trimBounds:s})}))))):r({data:!1})}))))}};let qi;function Vi(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Vi(t)))}const Hi=H.prototype,Qi=Q.get("@leafer-in/export");Hi.export=function(t,e){const{quality:i,blob:n}=N.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):n?this.toBlob(t,i):this.toDataURL(t,i)},Hi.toBlob=function(t,e){return new Promise((i=>{G.origin.canvasToBolb(this.view,t,e).then((t=>{i(t)})).catch((t=>{Qi.error(t),i(null)}))}))},Hi.toDataURL=function(t,e){return G.origin.canvasToDataURL(this.view,t,e)},Hi.saveAs=function(t,e){return new Promise((i=>{G.origin.canvasSaveAs(this.view,t,e).then((()=>{i(!0)})).catch((t=>{Qi.error(t),i(!1)}))}))},J.add("export"),Object.assign(D,ji),Z.prototype.export=function(t,e){return D.export(this,t,e)};export{_t as Layouter,K as LeaferCanvas,wt as Renderer,nt as Watcher,it as useCanvas};
1
+ import{LeaferCanvasBase as t,Platform as e,canvasPatch as i,FileHelper as n,Creator as s,LeaferImage as o,defineKey as a,LeafList as r,DataHelper as d,RenderEvent as l,ChildEvent as c,WatchEvent as h,PropertyEvent as u,LeafHelper as f,BranchHelper as p,LeafBoundsHelper as _,Bounds as g,Debug as w,LeafLevelList as y,LayoutEvent as m,Run as v,ImageManager as x,ResizeEvent as b,BoundsHelper as B,MatrixHelper as R,MathHelper as k,AlignHelper as S,ImageEvent as E,AroundHelper as L,PointHelper as A,Direction4 as W}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{writeFileSync as T}from"fs";import{PaintImage as O,ColorConvert as C,PaintGradient as M,Export as D,Group as P,TextConvert as I,Paint as F,Effect as Y,TwoPointBoundsHelper as U,Bounds as X,FileHelper as N,Platform as z,Matrix as G,MathHelper as j,Creator as q,TaskProcessor as V,Resource as H,LeaferCanvasBase as Q,Debug as J,Plugin as Z,UI as $}from"@leafer-ui/draw";export*from"@leafer-ui/draw";function K(t,e,i,n){return new(i||(i=Promise))((function(s,o){function a(t){try{d(n.next(t))}catch(t){o(t)}}function r(t){try{d(n.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}d((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class tt extends t{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config),e.roundRectPatch&&(this.context.__proto__.roundRect=null,i(this.context.__proto__))}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this;this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i),this.clientBounds=this.bounds}}const{mineType:et,fileType:it}=n;function nt(t,i){if(e.canvasType=t,!e.origin){if("skia"===t){const{Canvas:t,loadImage:n}=i;e.origin={createCanvas:(e,i,n)=>new t(e,i,n),canvasToDataURL:(t,e,i)=>t.toDataURLSync(e,{quality:i}),canvasToBolb:(t,e,i)=>t.toBuffer(e,{quality:i}),canvasSaveAs:(t,e,i)=>t.saveAs(e,{quality:i}),download(t,e){},loadImage:t=>n(e.image.getRealURL(t))},e.roundRectPatch=!0}else if("napi"===t){const{Canvas:t,loadImage:n}=i;e.origin={createCanvas:(e,i,n)=>new t(e,i,n),canvasToDataURL:(t,e,i)=>t.toDataURL(et(e),i),canvasToBolb:(t,e,i)=>K(this,void 0,void 0,(function*(){return t.toBuffer(et(e),i)})),canvasSaveAs:(t,e,i)=>K(this,void 0,void 0,(function*(){return T(e,t.toBuffer(et(it(e)),i))})),download(t,e){},loadImage:t=>n(e.image.getRealURL(t))}}e.ellipseToCurve=!0,e.event={stopDefault(t){},stopNow(t){},stop(t){}},e.canvas=s.canvas()}}Object.assign(s,{canvas:(t,e)=>new tt(t,e),image:t=>new o(t)}),e.name="node",e.backgrounder=!0,e.requestRender=function(t){setTimeout(t,16)},a(e,"devicePixelRatio",{get:()=>1}),e.conicGradientSupport=!0;class st{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new r;return this.__updatedList.list.forEach((e=>{e.leafer&&t.add(e)})),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new r,this.target=t,e&&(this.config=d.default(e,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(l.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===c.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.add(t.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,i=e.length;t<i;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new h(h.DATA,{updatedList:this.updatedList})),this.__updatedList=new r,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.CHANGE,this.__onAttrChange,this),t.on_([c.ADD,c.REMOVE],this.__onChildEvent,this),t.on_(h.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:ot,updateBounds:at,updateAllWorldOpacity:rt}=f,{pushAllChildBranch:dt,pushAllParent:lt}=p;const{worldBounds:ct}=_,ht={x:0,y:0,width:1e5,height:1e5};class ut{constructor(t){this.updatedBounds=new g,this.beforeBounds=new g,this.afterBounds=new g,t instanceof Array&&(t=new r(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,ct)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(ht):this.afterBounds.setListWithFn(t,ct),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:ft,updateAllChange:pt}=f,_t=w.get("Layouter");class gt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new y,this.target=t,e&&(this.config=d.default(e,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.running)return;const{target:t}=this;this.times=0;try{t.emit(m.START),this.layoutOnce(),t.emitEvent(new m(m.END,this.layoutedBlocks,this.times))}catch(t){_t.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?_t.warn("layouting"):this.times>3?_t.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(h.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=v.start("PartLayout"),{target:i,__updatedList:n}=this,{BEFORE:s,LAYOUT:o,AFTER:a}=m,r=this.getBlocks(n);r.forEach((t=>t.setBefore())),i.emitEvent(new m(s,r,this.times)),this.extraBlock=null,n.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(ot(t,!0),e.add(t),t.isBranch&&dt(t,e),lt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),lt(t,e)))}))}(n,this.__levelList),function(t){let e,i,n;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(i=e[t],i.isBranch&&i.__tempNumber){n=i.children;for(let t=0,e=n.length;t<e;t++)n[t].isBranch||at(n[t])}at(i)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&rt(t),e.stateStyleChanged&&setTimeout((()=>e.stateStyleChanged&&t.updateState())),t.__updateChange()}))}(n),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new m(o,r,this.times)),i.emitEvent(new m(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,v.end(e)}fullLayout(){const t=v.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:n,AFTER:s}=m,o=this.getBlocks(new r(e));e.emitEvent(new m(i,o,this.times)),gt.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new m(n,o,this.times)),e.emitEvent(new m(s,o,this.times)),this.addBlocks(o),v.end(t)}static fullLayout(t){ft(t,!0),t.isBranch?p.updateBounds(t):f.updateBounds(t),pt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new ut([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new ut(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(){const{target:t}=this;this.__eventIds=[t.on_(m.REQUEST,this.layout,this),t.on_(m.AGAIN,this.layoutAgain,this),t.on_(h.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const wt=w.get("Renderer");class yt{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,i&&(this.config=d.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(m.REQUEST)}render(t){if(!this.running||!this.canvas.view)return this.update();const{target:e}=this;this.times=0,this.totalBounds=new g,wt.log(e.innerName,"---\x3e");try{e.isApp||e.app.emit(l.CHILD_START,e),this.emitRender(l.START),this.renderOnce(t),this.emitRender(l.END,this.totalBounds),x.clearRecycled()}catch(t){this.rendering=!1,wt.error(t)}wt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return wt.warn("rendering");if(this.times>3)return wt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new g,this.renderOptions={},t)this.emitRender(l.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(l.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(l.RENDER,this.renderBounds,this.renderOptions),this.emitRender(l.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(t){const e=v.start("PartRender"),{canvas:i}=this,n=t.getIntersect(i.bounds),s=t.includes(this.target.__world),o=new g(n);i.save(),s&&!w.showRepaint?i.clear():(n.spread(10+1/this.canvas.pixelRatio).ceil(),i.clearWorld(n,!0),i.clipWorld(n,!0)),this.__render(n,s,o),i.restore(),v.end(e)}fullRender(){const t=v.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),v.end(t)}__render(t,e,i){const n=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),w.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,n),this.renderBounds=i=i||t,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=i:this.totalBounds.add(i),w.showHitView&&this.renderHitView(n),w.showBoundsView&&this.renderBoundsView(n),this.canvas.updateRender(i)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new g;e.setList(t),t.length=0,t.push(e)}}__requestRender(){if(this.requestTime)return;const t=this.requestTime=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.requestTime=0,this.running&&(this.changed&&this.canvas.view&&this.render(),this.target.emit(l.NEXT))}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new g(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new g(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||wt.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,i){this.target.emitEvent(new l(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(l.REQUEST,this.update,this),t.on_(m.END,this.__onLayoutEnd,this),t.on_(l.AGAIN,this.renderAgain,this),t.on_(b.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 mt(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),s&&e.fillRect(i.x,i.y+s,i.width,o)}function vt(t,e,i){const{strokeAlign:n}=e.__,s="string"!=typeof t;switch(n){case"center":i.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?Bt(t,!0,e,i):bt(e,i);break;case"inside":xt("inside",t,s,e,i);break;case"outside":xt("outside",t,s,e,i)}}function xt(t,e,i,n,s){const{__strokeWidth:o,__font:a}=n.__,r=s.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,n.__),r.font=a,i?Bt(e,!0,n,r):bt(n,r),r.blendMode="outside"===t?"destination-out":"destination-in",mt(n,r),r.blendMode="normal",n.__worldFlipped?s.copyWorldByReset(r,n.__nowWorld):s.copyWorldToInner(r,n.__nowWorld,n.__layout.renderBounds),r.recycle(n.__nowWorld)}function bt(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),s&&e.strokeRect(i.x,i.y+s,i.width,o)}function Bt(t,e,i,n){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&O.checkImage(i,n,s,!1)||s.style&&(n.strokeStyle=s.style,s.blendMode?(n.saveBlendMode(s.blendMode),e?bt(i,n):n.stroke(),n.restoreBlendMode()):e?bt(i,n):n.stroke())}function Rt(t,e){t.__.dashPattern&&(e.beginPath(),t.__drawPathByData(e,t.__.__pathForArrow),e.dashPattern=null,e.stroke())}Object.assign(s,{watcher:(t,e)=>new st(t,e),layouter:(t,e)=>new gt(t,e),renderer:(t,e,i)=>new yt(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,n)=>{}}),e.layout=gt.fullLayout;const{getSpread:kt,getOuterOf:St,getByMove:Et,getIntersectData:Lt}=B;let At;function Wt(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:n}=i.__layout;switch(e.type){case"solid":let{type:s,blendMode:o,color:a,opacity:r}=e;return{type:s,blendMode:o,style:C.string(a,r)};case"image":return O.image(i,t,e,n,!At||!At[e.url]);case"linear":return M.linearGradient(e,n);case"radial":return M.radialGradient(e,n);case"angular":return M.conicGradient(e,n);default:return void 0!==e.r?{type:"solid",style:C.string(e)}:void 0}}const Tt={compute:function(t,e){const i=e.__,n=[];let s,o=i.__input[t];o instanceof Array||(o=[o]),At=O.recycleImage(t,i);for(let i,s=0,a=o.length;s<a;s++)i=Wt(t,o[s],e),i&&n.push(i);i["_"+t]=n.length?n:void 0,n.length&&n[0].image&&(s=n[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=s:i.__pixelStroke=s},fill:function(t,e,i){i.fillStyle=t,e.__.__font?mt(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let n;const{windingRule:s,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)n=t[a],n.image&&O.checkImage(e,i,n,!o)||n.style&&(i.fillStyle=n.style,n.transform?(i.save(),i.transform(n.transform),n.blendMode&&(i.blendMode=n.blendMode),o?mt(e,i):s?i.fill(s):i.fill(),i.restore()):n.blendMode?(i.saveBlendMode(n.blendMode),o?mt(e,i):s?i.fill(s):i.fill(),i.restoreBlendMode()):o?mt(e,i):s?i.fill(s):i.fill())},fillText:mt,stroke:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)vt(t,e,i);else switch(o){case"center":i.setStroke(t,s,n),i.stroke(),n.__useArrow&&Rt(e,i);break;case"inside":i.save(),i.setStroke(t,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*s,n),e.__drawRenderPath(o),o.stroke(),n.windingRule?o.clip(n.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?i.copyWorldByReset(o,e.__nowWorld):i.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)vt(t,e,i);else switch(o){case"center":i.setStroke(void 0,s,n),Bt(t,!1,e,i),n.__useArrow&&Rt(e,i);break;case"inside":i.save(),i.setStroke(void 0,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),Bt(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*s,n),Bt(t,!1,e,a),n.windingRule?a.clip(n.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:vt,drawTextStroke:bt,shape:function(t,e,i){const n=e.getSameCanvas(),s=t.__nowWorld;let o,a,r,d,{scaleX:l,scaleY:c}=s;if(l<0&&(l=-l),c<0&&(c=-c),e.bounds.includes(s))d=n,o=r=s;else{const{renderShapeSpread:n}=t.__layout,h=Lt(n?kt(e.bounds,l===c?n*l:[n*c,n*l]):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,c*=f),r=St(s,a),o=Et(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,f)})}return t.__renderShape(n,i),{canvas:n,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:c}}};let Ot={};const{get:Ct,rotateOfOuter:Mt,translate:Dt,scaleOfOuter:Pt,scale:It,rotate:Ft}=R;function Yt(t,e,i,n,s,o,a){const r=Ct();Dt(r,e.x+i,e.y+n),It(r,s,o),a&&Mt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Ut(t,e,i,n,s,o,a){const r=Ct();Dt(r,e.x+i,e.y+n),s&&It(r,s,o),a&&Ft(r,a),t.transform=r}function Xt(t,e,i,n,s,o,a,r,d,l){const c=Ct();if(d)if("center"===l)Mt(c,{x:i/2,y:n/2},d);else switch(Ft(c,d),d){case 90:Dt(c,n,0);break;case 180:Dt(c,i,n);break;case 270:Dt(c,0,i)}Ot.x=e.x+s,Ot.y=e.y+o,Dt(c,Ot.x,Ot.y),a&&Pt(c,Ot,a,r),t.transform=c}const{get:Nt,translate:zt}=R,Gt=new g,jt={},qt={};function Vt(t,e,i,n){const{blendMode:s,sync:o}=i;s&&(t.blendMode=s),o&&(t.sync=o),t.data=Ht(i,n,e)}function Ht(t,e,i){let{width:n,height:s}=i;t.padding&&(e=Gt.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{opacity:o,mode:a,align:r,offset:d,scale:l,size:c,rotation:h,repeat:u,filters:f}=t,p=e.width===n&&e.height===s,_={mode:a},g="center"!==r&&(h||0)%180==90,w=g?s:n,y=g?n:s;let m,v,x=0,b=0;if(a&&"cover"!==a&&"fit"!==a)(l||c)&&(k.getScaleData(l,c,i,qt),m=qt.scaleX,v=qt.scaleY);else if(!p||h){const t=e.width/w,i=e.height/y;m=v="fit"===a?Math.min(t,i):Math.max(t,i),x+=(e.width-n*m)/2,b+=(e.height-s*v)/2}if(r){const t={x:x,y:b,width:w,height:y};m&&(t.width*=m,t.height*=v),S.toPoint(r,t,e,jt,!0),x+=jt.x,b+=jt.y}switch(d&&(x+=d.x,b+=d.y),a){case"stretch":p||(n=e.width,s=e.height);break;case"normal":case"clip":(x||b||m||h)&&Ut(_,e,x,b,m,v,h);break;case"repeat":(!p||m||h)&&Xt(_,e,n,s,x,b,m,v,h,r),u||(_.repeat="repeat");break;default:m&&Yt(_,e,x,b,m,v,h)}return _.transform||(e.x||e.y)&&(_.transform=Nt(),zt(_.transform,e.x,e.y)),m&&"stretch"!==a&&(_.scaleX=m,_.scaleY=v),_.width=n,_.height=s,o&&(_.opacity=o),f&&(_.filters=f),u&&(_.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),_}let Qt,Jt=new g;const{isSame:Zt}=B;function $t(t,e,i,n,s,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=n.width/e.pixelRatio,e.__naturalHeight=n.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return s.data||Vt(s,n,i,o),!0}function Kt(t,e){ie(t,E.LOAD,e)}function te(t,e){ie(t,E.LOADED,e)}function ee(t,e,i){e.error=i,t.forceUpdate("surface"),ie(t,E.ERROR,e)}function ie(t,e,i){t.hasEvent(e)&&t.emitEvent(new E(e,i))}function ne(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:se,scale:oe,copy:ae}=R,{ceil:re,abs:de}=Math;function le(t,i,n){let{scaleX:s,scaleY:o}=x.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o+"-"+n;if(i.patternId===a||t.destroyed)return!1;{s=de(s),o=de(o);const{image:t,data:r}=i;let d,l,{width:c,height:h,scaleX:u,scaleY:f,transform:p,repeat:_}=r;u&&(l=se(),ae(l,p),oe(l,1/u,1/f),s*=u,o*=f),s*=n,o*=n,c*=s,h*=o;const g=c*h;if(!_&&g>e.image.maxCacheSize)return!1;let w=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;w>e&&(w=e)}g>w&&(d=Math.sqrt(g/w)),d&&(s/=d,o/=d,c/=d,h/=d),u&&(s/=u,o/=f),(p||1!==s||1!==o)&&(l||(l=se(),p&&ae(l,p)),oe(l,1/s,1/o));const y=t.getCanvas(re(c)||1,re(h)||1,r.opacity,r.filters),m=t.getPattern(y,_||e.origin.noRepeat||"no-repeat",l,i);return i.style=m,i.patternId=a,!0}}const{abs:ce}=Math;const he={image:function(t,e,i,n,s){let o,a;const r=x.get(i);return Qt&&i===Qt.paint&&Zt(n,Qt.boxBounds)?o=Qt.leafPaint:(o={type:i.type,image:r},Qt=r.use>1?{leafPaint:o,paint:i,boxBounds:Jt.set(n)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?($t(t,e,i,r,o,n),s&&(Kt(t,a),te(t,a))):r.error?s&&ee(t,a,r.error):(s&&(ne(t,!0),Kt(t,a)),o.loadId=r.load((()=>{ne(t,!1),t.destroyed||($t(t,e,i,r,o,n)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),te(t,a)),o.loadId=null}),(e=>{ne(t,!1),ee(t,a,e),o.loadId=null}))),o},checkImage:function(t,i,n,s){const{scaleX:o,scaleY:a}=x.patternLocked?t.__world:t.__nowWorld,{pixelRatio:r}=i;if(!n.data||n.patternId===o+"-"+a+"-"+r&&!D.running)return!1;{const{data:d}=n;if(s)if(d.repeat)s=!1;else{let{width:t,height:i}=d;t*=ce(o)*r,i*=ce(a)*r,d.scaleX&&(t*=d.scaleX,i*=d.scaleY),s=t*i>e.image.maxCacheSize||D.running}return s?(i.save(),t.windingRule?i.clip(t.windingRule):i.clip(),n.blendMode&&(i.blendMode=n.blendMode),d.opacity&&(i.opacity*=d.opacity),d.transform&&i.transform(d.transform),i.drawImage(n.image.getFull(d.filters),0,0,d.width,d.height),i.restore(),!0):(!n.style||n.sync||D.running?le(t,n,r):n.patternTask||(n.patternTask=x.patternTasker.add((()=>K(this,void 0,void 0,(function*(){n.patternTask=null,i.bounds.hit(t.__nowWorld)&&le(t,n,r),t.forceUpdate("surface")}))),300)),!1)}},createPattern:le,recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let n,s,o,a;for(let r=0,d=i.length;r<d;r++)n=i[r].image,a=n&&n.url,a&&(s||(s={}),s[a]=!0,x.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),n.unload(i[r].loadId,!o.some((t=>t.url===a)))));return s}return null},createData:Vt,getPatternData:Ht,fillOrFitMode:Yt,clipMode:Ut,repeatMode:Xt},{toPoint:ue}=L,fe={},pe={};function _e(t,e,i){if(e){let n;for(let s=0,o=e.length;s<o;s++)n=e[s],"string"==typeof n?t.addColorStop(s/(o-1),C.string(n,i)):t.addColorStop(n.offset,C.string(n.color,i))}}const{getAngle:ge,getDistance:we}=A,{get:ye,rotateOfOuter:me,scaleOfOuter:ve}=R,{toPoint:xe}=L,be={},Be={};function Re(t,e,i,n,s){let o;const{width:a,height:r}=t;if(a!==r||n){const t=ge(e,i);o=ye(),s?(ve(o,e,a/r*(n||1),1),me(o,e,t+90)):(ve(o,e,1,a/r*(n||1)),me(o,e,t))}return o}const{getDistance:ke}=A,{toPoint:Se}=L,Ee={},Le={};const Ae={linearGradient:function(t,i){let{from:n,to:s,type:o,blendMode:a,opacity:r}=t;ue(n||"top",i,fe),ue(s||"bottom",i,pe);const d=e.canvas.createLinearGradient(fe.x,fe.y,pe.x,pe.y);_e(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,i){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;xe(n||"center",i,be),xe(s||"bottom",i,Be);const l=e.canvas.createRadialGradient(be.x,be.y,0,be.x,be.y,we(be,Be));_e(l,t.stops,a);const c={type:o,style:l},h=Re(i,be,Be,d,!0);return h&&(c.transform=h),r&&(c.blendMode=r),c},conicGradient:function(t,i){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;Se(n||"center",i,Ee),Se(s||"bottom",i,Le);const l=e.conicGradientSupport?e.canvas.createConicGradient(0,Ee.x,Ee.y):e.canvas.createRadialGradient(Ee.x,Ee.y,0,Ee.x,Ee.y,ke(Ee,Le));_e(l,t.stops,a);const c={type:o,style:l},h=Re(i,Ee,Le,d||1,e.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:Re},{copy:We,toOffsetOutBounds:Te}=B,Oe={},Ce={};function Me(t,i,n,s){const{bounds:o,shapeBounds:a}=s;if(e.fullImageShadow){if(We(Oe,t.bounds),Oe.x+=i.x-a.x,Oe.y+=i.y-a.y,n){const{matrix:t}=s;Oe.x-=(o.x+(t?t.e:0)+o.width/2)*(n-1),Oe.y-=(o.y+(t?t.f:0)+o.height/2)*(n-1),Oe.width*=n,Oe.height*=n}t.copyWorld(s.canvas,t.bounds,Oe)}else n&&(We(Oe,i),Oe.x-=i.width/2*(n-1),Oe.y-=i.height/2*(n-1),Oe.width*=n,Oe.height*=n),t.copyWorld(s.canvas,a,n?Oe:i)}const{toOffsetOutBounds:De}=B,Pe={};const Ie={shadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;Te(l,Ce),r.forEach(((r,_)=>{f.setWorldShadow(Ce.offsetX+r.x*h,Ce.offsetY+r.y*u,r.blur*h,C.string(r.color)),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Me(f,Ce,s,i),n=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,o,"copy"),n=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(i.canvas,c,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(n,!0)})),f.recycle(n)},innerShadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;De(l,Pe),r.forEach(((r,_)=>{f.save(),f.setWorldShadow(Pe.offsetX+r.x*h,Pe.offsetY+r.y*u,r.blur*h),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Me(f,Pe,s,i),f.restore(),d?(f.copyWorld(f,l,o,"copy"),f.copyWorld(d,o,o,"source-out"),n=o):(f.copyWorld(i.canvas,c,l,"source-out"),n=l),f.fillWorld(n,C.string(r.color),"source-in"),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(n,!0)})),f.recycle(n)},blur:function(t,e,i){const{blur:n}=t.__;i.setWorldBlur(n*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Fe}=_;function Ye(t,e,i,n,s,o){switch(e){case"grayscale":s.useGrayscaleAlpha(t.__nowWorld);case"alpha":!function(t,e,i,n){const s=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(n,s),n.recycle(s),Xe(t,e,i,1)}(t,i,n,s);break;case"opacity-path":Xe(t,i,n,o);break;case"path":i.restore()}}function Ue(t){return t.getSameCanvas(!1,!0)}function Xe(t,e,i,n){const s=t.__nowWorld;e.resetTransform(),e.opacity=n,e.copyWorld(i,s),i.recycle(s)}P.prototype.__renderMask=function(t,e){let i,n,s,o,a,r;const{children:d}=this;for(let l=0,c=d.length;l<c;l++)i=d[l],r=i.__.mask,r&&(a&&(Ye(this,a,t,s,n,o),n=s=null),"path"===r||"clipping-path"===r?(i.opacity<1?(a="opacity-path",o=i.opacity,s||(s=Ue(t))):(a="path",t.save()),i.__clip(s||t,e)):(a="grayscale"===r?"grayscale":"alpha",n||(n=Ue(t)),s||(s=Ue(t)),i.__render(n,e)),"clipping"!==r&&"clipping-path"!==r)||Fe(i,e)||i.__render(s||t,e);Ye(this,a,t,s,n,o)};const Ne=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",ze=Ne+"_#~&*+\\=|≮≯≈≠=…",Ge=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 je(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const qe=je("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ve=je("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),He=je(Ne),Qe=je(ze),Je=je("- —/~|┆·");var Ze;!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"}(Ze||(Ze={}));const{Letter:$e,Single:Ke,Before:ti,After:ei,Symbol:ii,Break:ni}=Ze;function si(t){return qe[t]?$e:Je[t]?ni:Ve[t]?ti:He[t]?ei:Qe[t]?ii:Ge.test(t)?Ke:$e}const oi={trimRight(t){const{words:e}=t;let i,n=0,s=e.length;for(let o=s-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)n++,t.width-=i.width;n&&e.splice(s-n,n)}};function ai(t,e,i){switch(e){case"title":return i?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:ri}=oi,{Letter:di,Single:li,Before:ci,After:hi,Symbol:ui,Break:fi}=Ze;let pi,_i,gi,wi,yi,mi,vi,xi,bi,Bi,Ri,ki,Si,Ei,Li,Ai,Wi,Ti=[];function Oi(t,e){bi&&!xi&&(xi=bi),pi.data.push({char:t,width:e}),gi+=e}function Ci(){wi+=gi,pi.width=gi,_i.words.push(pi),pi={data:[]},gi=0}function Mi(){Ei&&(Li.paraNumber++,_i.paraStart=!0,Ei=!1),bi&&(_i.startCharSize=xi,_i.endCharSize=bi,xi=0),_i.width=wi,Ai.width?ri(_i):Wi&&Di(),Ti.push(_i),_i={words:[]},wi=0}function Di(){wi>(Li.maxWidth||0)&&(Li.maxWidth=wi)}const{top:Pi,right:Ii,bottom:Fi,left:Yi}=W;function Ui(t,e,i){const{bounds:n,rows:s}=t;n[e]+=i;for(let t=0;t<s.length;t++)s[t][e]+=i}const Xi={getDrawData:function(t,i){"string"!=typeof t&&(t=String(t));let n=0,s=0,o=i.__getInput("width")||0,a=i.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=i;l&&(o?(n=l[Yi],o-=l[Ii]+l[Yi]):i.autoSizeAlign||(n=l[Yi]),a?(s=l[Pi],a-=l[Pi]+l[Fi]):i.autoSizeAlign||(s=l[Pi]));const c={bounds:{x:n,y:s,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,i,n){Li=t,Ti=t.rows,Ai=t.bounds,Wi=!Ai.width&&!n.autoSizeAlign;const{__letterSpacing:s,paraIndent:o,textCase:a}=n,{canvas:r}=e,{width:d,height:l}=Ai;if(d||l||s||"none"!==a){const t="none"!==n.textWrap,e="break"===n.textWrap;Ei=!0,Ri=null,xi=vi=bi=gi=wi=0,pi={data:[]},_i={words:[]};for(let n=0,l=i.length;n<l;n++)mi=i[n],"\n"===mi?(gi&&Ci(),_i.paraEnd=!0,Mi(),Ei=!0):(Bi=si(mi),Bi===di&&"none"!==a&&(mi=ai(mi,a,!gi)),vi=r.measureText(mi).width,s&&(s<0&&(bi=vi),vi+=s),ki=Bi===li&&(Ri===li||Ri===di)||Ri===li&&Bi!==hi,Si=!(Bi!==ci&&Bi!==li||Ri!==ui&&Ri!==hi),yi=Ei&&o?d-o:d,t&&d&&wi+gi+vi>yi&&(e?(gi&&Ci(),wi&&Mi()):(Si||(Si=Bi===di&&Ri==hi),ki||Si||Bi===fi||Bi===ci||Bi===li||gi+vi>yi?(gi&&Ci(),wi&&Mi()):wi&&Mi()))," "===mi&&!0!==Ei&&wi+gi===0||(Bi===fi?(" "===mi&&gi&&Ci(),Oi(mi,vi),Ci()):ki||Si?(gi&&Ci(),Oi(mi,vi)):Oi(mi,vi)),Ri=Bi);gi&&Ci(),wi&&Mi(),Ti.length>0&&(Ti[Ti.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{Li.paraNumber++,wi=r.measureText(t).width,Ti.push({x:o||0,text:t,width:wi,paraStart:!0}),Wi&&Di()}))}(c,t,i),l&&function(t,e,i,n,s){if(!n&&i.autoSizeAlign)switch(i.textAlign){case"left":Ui(e,"x",t[Yi]);break;case"right":Ui(e,"x",-t[Ii])}if(!s&&i.autoSizeAlign)switch(i.verticalAlign){case"top":Ui(e,"y",t[Pi]);break;case"bottom":Ui(e,"y",-t[Fi])}}(l,c,i,o,a),function(t,e){const{rows:i,bounds:n}=t,s=i.length,{__lineHeight:o,__baseLine:a,__letterSpacing:r,__clipText:d,textAlign:l,verticalAlign:c,paraSpacing:h,autoSizeAlign:u}=e;let{x:f,y:p,width:_,height:g}=n,w=o*s+(h?h*(t.paraNumber-1):0),y=a;if(d&&w>g)w=Math.max(g,o),s>1&&(t.overflow=s);else if(g||u)switch(c){case"middle":p+=(g-w)/2;break;case"bottom":p+=g-w}y+=p;let m,v,x,b=_||u?_:t.maxWidth;for(let a=0,c=s;a<c;a++){if(m=i[a],m.x=f,m.width<_||m.width>_&&!d)switch(l){case"center":m.x+=(b-m.width)/2;break;case"right":m.x+=b-m.width}m.paraStart&&h&&a>0&&(y+=h),m.y=y,y+=o,t.overflow>a&&y>w&&(m.isOverflow=!0,t.overflow=a+1),v=m.x,x=m.width,r<0&&(m.width<0?(x=-m.width+e.fontSize+r,v-=x,x+=e.fontSize):x-=r),v<n.x&&(n.x=v),x>n.width&&(n.width=x),d&&_&&_<x&&(m.isOverflow=!0,t.overflow||(t.overflow=i.length))}n.y=p,n.height=w}(c,i),function(t,e,i){const{rows:n}=t,{textAlign:s,paraIndent:o,letterSpacing:a}=e;let r,d,l,c,h,u;n.forEach((t=>{t.words&&(l=o&&t.paraStart?o:0,u=t.words.length,d=i&&("justify"===s||"both"===s)&&u>1?(i-t.width-l)/(u-1):0,c=a||t.isOverflow?0:d>.01?1:2,t.isOverflow&&!a&&(t.textMode=!0),2===c?(t.x+=l,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=l,r=t.x,t.data=[],t.words.forEach(((e,i)=>{1===c?(h={char:"",x:r},r=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,r,h),(t.isOverflow||" "!==h.char)&&t.data.push(h)):r=function(t,e,i,n){return t.forEach((t=>{(n||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,r,t.data,t.isOverflow),!d||t.paraEnd&&"both"!==s||i===u-1||(r+=d,t.width+=d)}))),t.words=null)}))}(c,i,o),c.overflow&&function(t,i,n,s){if(!s)return;const{rows:o,overflow:a}=t;let{textOverflow:r}=i;if(o.splice(a),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const l=r?e.canvas.measureText(r).width:0,c=n+s-l;("none"===i.textWrap?o:[o[a-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let n=i;n>-1&&(t=e.data[n],d=t.x+t.width,!(n===i&&d<c));n--){if(d<c&&" "!==t.char||!n){e.data.splice(n+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:r,x:d}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(c,i,n,o),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(c,i),c}};const Ni={string:function(t,e){const i="number"==typeof e&&1!==e;if("string"==typeof t){if(!i||!C.object)return t;t=C.object(t)}let n=void 0===t.a?1:t.a;i&&(n*=e);const s=t.r+","+t.g+","+t.b;return 1===n?"rgb("+s+")":"rgba("+s+","+n+")"}};Object.assign(I,Xi),Object.assign(C,Ni),Object.assign(F,Tt),Object.assign(O,he),Object.assign(M,Ae),Object.assign(Y,Ie);const{setPoint:zi,addPoint:Gi,toBounds:ji}=U;const qi={syncExport(t,e,i){let n;this.running=!0;const s=N.fileType(e),o=e.includes(".");i=N.getExportOptions(i);const{toURL:a}=z,{download:r}=z.origin;if("json"===s)o&&r(a(JSON.stringify(t.toJSON(i.json)),"text"),e),n={data:!!o||t.toJSON(i.json)};else if("svg"===s)o&&r(a(t.toSVG(),"svg"),e),n={data:!!o||t.toSVG()};else{let s,o,a=1,r=1;const{worldTransform:d,isLeafer:l,leafer:c,isFrame:h}=t,{slice:u,trim:f,padding:p,onCanvas:_}=i,g=void 0===i.smooth?!c||c.config.smooth:i.smooth,w=i.contextSettings||(c?c.config.contextSettings:void 0),y=i.screenshot||t.isApp,m=l&&y&&void 0===i.fill?t.fill:i.fill,v=N.isOpaqueImage(e)||m,x=new G;if(y)s=!0===y?l?c.canvas.bounds:t.worldRenderBounds:y;else{let e=i.relative||(l?"inner":"local");switch(a=d.scaleX,r=d.scaleY,e){case"inner":x.set(d);break;case"local":x.set(d).divide(t.localTransform),a/=t.scaleX,r/=t.scaleY;break;case"world":a=1,r=1;break;case"page":e=c||t;default:x.set(d).divide(t.getTransform(e));const i=e.worldTransform;a/=a/i.scaleX,r/=r/i.scaleY}s=t.getBounds("render",e)}const b={scaleX:1,scaleY:1};j.getScaleData(i.scale,i.size,s,b);let B=i.pixelRatio||1;t.isApp&&(b.scaleX*=B,b.scaleY*=B,B=t.app.pixelRatio);const{x:R,y:k,width:S,height:E}=new X(s).scale(b.scaleX,b.scaleY),L={matrix:x.scale(1/b.scaleX,1/b.scaleY).invert().translate(-R,-k).withScale(1/a*b.scaleX,1/r*b.scaleY)};let A,W=q.canvas({width:Math.floor(S),height:Math.floor(E),pixelRatio:B,smooth:g,contextSettings:w});if(u&&(A=t,A.__worldOpacity=0,t=c||t,L.bounds=W.bounds),W.save(),h&&void 0!==m){const e=t.get("fill");t.fill="",t.__render(W,L),t.fill=e}else t.__render(W,L);if(W.restore(),A&&A.__updateWorldOpacity(),f){o=function(t){const{width:e,height:i}=t.view,{data:n}=t.context.getImageData(0,0,e,i);let s,o,a,r=0;for(let t=0;t<n.length;t+=4)0!==n[t+3]&&(s=r%e,o=(r-s)/e,a?Gi(a,s,o):zi(a={},s,o)),r++;const d=new X;return ji(a,d),d.scale(1/t.pixelRatio).ceil()}(W);const t=W,{width:e,height:i}=o,n={x:0,y:0,width:e,height:i,pixelRatio:B};W=q.canvas(n),W.copyWorld(t,o,n)}if(p){const[t,e,i,n]=j.fourNumber(p),s=W,{width:o,height:a}=s;W=q.canvas({width:o+n+e,height:a+t+i,pixelRatio:B}),W.copyWorld(s,s.bounds,{x:n,y:t,width:o,height:a})}v&&W.fillWorld(W.bounds,m||"#FFFFFF","destination-over"),_&&_(W);n={data:"canvas"===e?W:W.export(e,i),width:W.pixelWidth,height:W.pixelHeight,renderBounds:s,trimBounds:o}}return this.running=!1,n},export(t,e,i){return this.running=!0,function(t){Vi||(Vi=new V);return new Promise((e=>{Vi.add((()=>K(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((n=>new Promise((s=>{const o=()=>K(this,void 0,void 0,(function*(){if(!H.isComplete)return z.requestRender(o);const a=qi.syncExport(t,e,i);a.data instanceof Promise&&(a.data=yield a.data),n(a),s()}));t.updateLayout(),Hi(t);const{leafer:a}=t;a?a.waitViewCompleted(o):o()}))))}};let Vi;function Hi(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Hi(t)))}const Qi=Q.prototype,Ji=J.get("@leafer-in/export");Qi.export=function(t,e){const{quality:i,blob:n}=N.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):n?this.toBlob(t,i):this.toDataURL(t,i)},Qi.toBlob=function(t,e){return new Promise((i=>{z.origin.canvasToBolb(this.view,t,e).then((t=>{i(t)})).catch((t=>{Ji.error(t),i(null)}))}))},Qi.toDataURL=function(t,e){return z.origin.canvasToDataURL(this.view,t,e)},Qi.saveAs=function(t,e){return new Promise((i=>{z.origin.canvasSaveAs(this.view,t,e).then((()=>{i(!0)})).catch((t=>{Ji.error(t),i(!1)}))}))},Z.add("export"),Object.assign(D,qi),$.prototype.export=function(t,e){return D.export(this,t,e)},$.prototype.syncExport=function(t,e){return D.syncExport(this,t,e)};export{gt as Layouter,tt as LeaferCanvas,yt as Renderer,st as Watcher,nt as useCanvas};
2
2
  //# sourceMappingURL=node.esm.min.js.map