UNPKG

@leafer-draw/node

Version:
3 lines (2 loc) 37.6 kB
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 T}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{writeFileSync as W}from"fs";import{PaintImage as O,ColorConvert as C,PaintGradient as M,Export as P,Group as D,TextConvert as I,Paint as F,Effect as Y,TwoPointBoundsHelper as U,Bounds as N,FileHelper as X,Platform as z,Matrix as j,MathHelper as G,Creator as q,TaskProcessor as H,Resource as V,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 W(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,updateChange:rt}=f,{pushAllChildBranch:dt,pushAllParent:lt}=p;const{worldBounds:ct}=_;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,ct)}setAfter(){this.afterBounds.setListWithFn(this.updatedList.list,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: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?(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){t.list.forEach(rt)}(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)}checkRender(){if(this.running){const{target:t}=this;t.isApp&&(t.emit(l.CHILD_START,t),t.children.forEach((t=>{t.renderer.FPS=this.FPS,t.renderer.checkRender()})),t.emit(l.CHILD_END,t)),this.changed&&this.canvas.view&&this.render(),this.target.emit(l.NEXT)}}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{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=new g(n);i.save(),n.spread(wt.clipSpread).ceil(),i.clearWorld(n,!0),i.clipWorld(n,!0),this.__render(n,s),i.restore(),v.end(e)}fullRender(){const t=v.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds),e.restore(),v.end(t)}__render(t,e){const{canvas:i}=this,n=t.includes(this.target.__world),s=n?{includes:n}:{bounds:t,includes:n};this.needFill&&i.fillWorld(t,this.config.fill),w.showRepaint&&w.drawRepaint(i,t),this.target.__render(i,s),this.renderBounds=e=e||t,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=e:this.totalBounds.add(e),i.updateRender(e)}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(){const t=this.target;if(this.requestTime||!t)return;if(t.parentApp)return t.parentApp.requestRender(!1);const i=this.requestTime=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-i))),this.requestTime=0,this.checkRender()}))}__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){const i=t.__,{rows:n,decorationY:s}=i.__textDrawData;let o;i.__isPlacehold&&i.placeholderColor&&(e.fillStyle=i.placeholderColor);for(let t=0,i=n.length;t<i;t++)o=n[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(s){const{decorationColor:t,decorationHeight:o}=i.__textDrawData;t&&(e.fillStyle=t),n.forEach((t=>s.forEach((i=>e.fillRect(t.x,t.y+i,t.width,o)))))}}function mt(t,e){t.__.__font?yt(t,e):t.__.windingRule?e.fill(t.__.windingRule):e.fill()}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",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 bt(t,e){let i,n=t.__.__textDrawData;const{rows:s,decorationY:o}=n;for(let t=0,n=s.length;t<n;t++)i=s[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)}));if(o){const{decorationHeight:t}=n;s.forEach((i=>o.forEach((n=>e.strokeRect(i.x,i.y+n,i.width,t)))))}}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())}wt.clipSpread=10,Object.assign(s,{watcher:(t,e)=>new st(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:kt,getOuterOf:St,getByMove:Et,getIntersectData:Lt}=B;let At;function Tt(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 Wt={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=Tt(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,mt(e,i)},fills:function(t,e,i){let n;for(let s=0,o=t.length;s<o;s++){if(n=t[s],n.image){if(O.checkImage(e,i,n,!e.__.__font))continue;if(!n.style){!s&&n.image.isPlacehold&&e.drawImagePlaceholder(i,n.image);continue}}i.fillStyle=n.style,n.transform?(i.save(),i.transform(n.transform),n.blendMode&&(i.blendMode=n.blendMode),mt(e,i),i.restore()):n.blendMode?(i.saveBlendMode(n.blendMode),mt(e,i),i.restoreBlendMode()):mt(e,i)}},fillPathOrText:mt,fillText:yt,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:Pt,scaleOfOuter:Dt,scale:It,rotate:Ft}=R;function Yt(t,e,i,n,s,o,a){const r=Ct();Pt(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();Pt(r,e.x+i,e.y+n),s&&It(r,s,o),a&&Ft(r,a),t.transform=r}function Nt(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:Pt(c,n,0);break;case 180:Pt(c,i,n);break;case 270:Pt(c,0,i)}Ot.x=e.x+s,Ot.y=e.y+o,Pt(c,Ot.x,Ot.y),a&&Dt(c,Ot,a,r),t.transform=c}const{get:Xt,translate:zt}=R,jt=new g,Gt={},qt={};function Ht(t,e,i,n){const{blendMode:s,changeful:o,sync:a}=i;s&&(t.blendMode=s),o&&(t.changeful=o),a&&(t.sync=a),t.data=Vt(i,n,e)}function Vt(t,e,i){let{width:n,height:s}=i;t.padding&&(e=jt.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,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)&&Ut(_,e,x,b,m,v,h);break;case"repeat":(!p||m||h)&&Nt(_,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=Xt(),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||Ht(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})),t.placeholderColor&&setTimeout((()=>{r.ready||r.isPlacehold||(r.isPlacehold=!0,t.forceUpdate("surface"))}),100)),o},checkImage:function(t,i,n,s){const{scaleX:o,scaleY:a}=x.patternLocked?t.__world:t.__nowWorld,{pixelRatio:r}=i,{data:d}=n;if(!d||n.patternId===o+"-"+a+"-"+r&&!P.running)return!1;if(s)if(d.repeat)s=!1;else if(!(n.changeful||b.isResizing(t)||P.running)){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}return s?(function(t,e,i,n){e.save(),t.windingRule?e.clip(t.windingRule):e.clip(),i.blendMode&&(e.blendMode=i.blendMode);n.opacity&&(e.opacity*=n.opacity);n.transform&&e.transform(n.transform);e.drawImage(i.image.getFull(n.filters),0,0,n.width,n.height),e.restore()}(t,i,n,d),!0):(!n.style||n.sync||P.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,r;for(let d=0,l=i.length;d<l;d++)n=i[d],s=n.image,r=s&&s.url,r&&(o||(o={}),o[r]=!0,x.recycle(s),s.loading&&(a||(a=e.__input&&e.__input[t]||[],a instanceof Array||(a=[a])),s.unload(i[d].loadId,!a.some((t=>t.url===r)))));return o}return null},createData:Ht,getPatternData:Vt,fillOrFitMode:Yt,clipMode:Ut,repeatMode:Nt},{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:Te,toOffsetOutBounds:We}=B,Oe={},Ce={};function Me(t,i,n,s){const{bounds:o,shapeBounds:a}=s;if(e.fullImageShadow){if(Te(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&&(Te(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:Pe}=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,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;Pe(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,Me(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: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),Ne(t,e,i,1)}(t,i,n,s);break;case"opacity-path":Ne(t,i,n,o);break;case"path":i.restore()}}function Ue(t){return t.getSameCanvas(!1,!0)}function Ne(t,e,i,n){const s=t.__nowWorld;e.resetTransform(),e.opacity=n,e.copyWorld(i,s),i.recycle(s)}D.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 Xe=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",ze=Xe+"_#~&*+\\=|≮≯≈≠=…",je=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 qe=Ge("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),He=Ge("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Ve=Ge(Xe),Qe=Ge(ze),Je=Ge("- —/~|┆·");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:He[t]?ti:Ve[t]?ei:Qe[t]?ii:je.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,Ti,Wi=[];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):Ti&&Pi(),Wi.push(_i),_i={words:[]},wi=0}function Pi(){wi>(Li.maxWidth||0)&&(Li.maxWidth=wi)}const{top:Di,right:Ii,bottom:Fi,left:Yi}=T;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 Ni={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[Di],a-=l[Di]+l[Fi]):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){Li=t,Wi=t.rows,Ai=t.bounds,Ti=!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(),Wi.length>0&&(Wi[Wi.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{Li.paraNumber++,wi=r.measureText(t).width,Wi.push({x:o||0,text:t,width:wi,paraStart:!0}),Ti&&Pi()}))}(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[Di]);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){let i;const{fontSize:n,textDecoration:s}=e;switch(t.decorationHeight=n/11,"object"==typeof s?(i=s.type,s.color&&(t.decorationColor=C.string(s.color))):i=s,i){case"under":t.decorationY=[.15*n];break;case"delete":t.decorationY=[.35*-n];break;case"under-delete":t.decorationY=[.15*n,.35*-n]}}(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(I,Ni),Object.assign(C,Xi),Object.assign(F,Wt),Object.assign(O,he),Object.assign(M,Ae),Object.assign(Y,Ie);const{setPoint:zi,addPoint:ji,toBounds:Gi}=U;const qi={syncExport(t,e,i){let n;this.running=!0;const s=X.fileType(e),o=e.includes(".");i=X.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,clip:f,trim:p,padding:_,onCanvas:g}=i,w=void 0===i.smooth?!c||c.config.smooth:i.smooth,y=i.contextSettings||(c?c.config.contextSettings:void 0),m=i.screenshot||t.isApp,v=l&&m&&void 0===i.fill?t.fill:i.fill,x=X.isOpaqueImage(e)||v,b=new j;if(m)s=!0===m?l?c.canvas.bounds:t.worldRenderBounds:m;else{let e=i.relative||(l?"inner":"local");switch(a=d.scaleX,r=d.scaleY,e){case"inner":b.set(d);break;case"local":b.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:b.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};G.getScaleData(i.scale,i.size,s,B);let R=i.pixelRatio||1;t.isApp&&(B.scaleX*=R,B.scaleY*=R,R=t.app.pixelRatio);let{x:k,y:S,width:E,height:L}=new N(s).scale(B.scaleX,B.scaleY);f&&(k+=f.x,S+=f.y,E=f.width,L=f.height);const A={matrix:b.scale(1/B.scaleX,1/B.scaleY).invert().translate(-k,-S).withScale(1/a*B.scaleX,1/r*B.scaleY)};let T,W=q.canvas({width:Math.floor(E),height:Math.floor(L),pixelRatio:R,smooth:w,contextSettings:y});if(u&&(T=t,T.__worldOpacity=0,t=c||t,A.bounds=W.bounds),W.save(),h&&void 0!==v){const e=t.get("fill");t.fill="",t.__render(W,A),t.fill=e}else t.__render(W,A);if(W.restore(),T&&T.__updateWorldOpacity(),p){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?ji(a,s,o):zi(a={},s,o)),r++;const d=new N;return Gi(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:R};W=q.canvas(n),W.copyWorld(t,o,n)}if(_){const[t,e,i,n]=G.fourNumber(_),s=W,{width:o,height:a}=s;W=q.canvas({width:o+n+e,height:a+t+i,pixelRatio:R}),W.copyWorld(s,s.bounds,{x:n,y:t,width:o,height:a})}x&&W.fillWorld(W.bounds,v||"#FFFFFF","destination-over"),g&&g(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){Hi||(Hi=new H);return new Promise((e=>{Hi.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(!V.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(),Vi(t);const{leafer:a}=t;a?a.waitViewCompleted(o):o()}))))}};let Hi;function Vi(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Vi(t)))}const Qi=Q.prototype,Ji=J.get("@leafer-in/export");Qi.export=function(t,e){const{quality:i,blob:n}=X.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(P,qi),$.prototype.export=function(t,e){return P.export(this,t,e)},$.prototype.syncExport=function(t,e){return P.syncExport(this,t,e)};export{_t as Layouter,tt as LeaferCanvas,wt as Renderer,st as Watcher,nt as useCanvas}; //# sourceMappingURL=node.esm.min.js.map