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