leafer-draw 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{Debug as t,LeaferCanvasBase as e,Platform as i,DataHelper as n,canvasSizeAttrs as s,ResizeEvent as o,canvasPatch as a,Creator as r,LeaferImage as d,defineKey as l,FileHelper as c,LeafList as h,RenderEvent as u,ChildEvent as p,WatchEvent as f,PropertyEvent as g,LeafHelper as _,BranchHelper as w,Bounds as y,LeafBoundsHelper as m,LeafLevelList as v,LayoutEvent as x,Run as b,ImageManager as B,BoundsHelper as R,MatrixHelper as k,MathHelper as S,AlignHelper as E,ImageEvent as L,AroundHelper as A,PointHelper as O,Direction4 as W,TwoPointBoundsHelper as C,TaskProcessor as T,Matrix as M}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as D,ColorConvert as P,PaintGradient as I,Export as z,Group as F,TextConvert as V,Paint as Y,Effect as U}from"@leafer-ui/draw";export*from"@leafer-ui/draw";const X=t.get("LeaferCanvas");class G extends e{set zIndex(t){const{style:e}=this.view;e.zIndex=t,this.setAbsolute(this.view)}set childIndex(t){const{view:e,parentView:i}=this;if(e&&i){const n=i.children[t];n?(this.setAbsolute(n),i.insertBefore(e,n)):i.appendChild(n)}}init(){const{config:t}=this,e=t.view||t.canvas;e?this.__createViewFrom(e):this.__createView();const{style:n}=this.view;if(n.display||(n.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none"}i.syncDomFont&&!this.parentView&&(n.display="none",document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(t)}set backgroundColor(t){this.view.style.backgroundColor=t}get backgroundColor(){return this.view.style.backgroundColor}set hittable(t){this.view.style.pointerEvents=t?"auto":"none"}get hittable(){return"none"!==this.view.style.pointerEvents}__createView(){this.view=document.createElement("canvas")}__createViewFrom(t){let e="string"==typeof t?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:i}=e;i.position="absolute",i.top=i.bottom=i.left=i.right="0px",document.body.appendChild(e),t=e}this.__createView();const i=this.view;t.hasChildNodes()&&(this.setAbsolute(i),t.style.position||(t.style.position="relative")),t.appendChild(i)}else X.error(`no id: ${t}`),this.__createView()}setAbsolute(t){const{style:e}=t;e.position="absolute",e.top=e.left="0px"}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:n}=this.view;n.width=t+"px",n.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.view.parentElement&&(this.clientBounds=this.view.getBoundingClientRect())}startAutoLayout(t,e){if(this.resizeListener=e,t){this.autoBounds=t;try{this.resizeObserver=new ResizeObserver((t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)}));const t=this.parentView;t?(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect())):(this.checkAutoBounds(this.view),X.warn("no parent"))}catch(t){this.imitateResizeObserver()}}else window.addEventListener("resize",(()=>{const t=i.devicePixelRatio;if(this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}}))}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}checkAutoBounds(t){const e=this.view,{x:n,y:s,width:o,height:a}=this.autoBounds.getBoundsFrom(t),r={width:o,height:a,pixelRatio:i.devicePixelRatio};if(!this.isSameSize(r)){const{style:t}=e;t.marginLeft=n+"px",t.marginTop=s+"px",this.emitResize(r)}}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}emitResize(t){const e={};n.copyAttrs(e,this,s),this.resize(t),this.resizeListener&&void 0!==this.width&&this.resizeListener(new o(t,e))}unrealCanvas(){if(!this.unreal&&this.parentView){const t=this.view;t&&t.remove(),this.view=this.parentView,this.unreal=!0}}destroy(){if(this.view){if(this.stopAutoLayout(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}a(CanvasRenderingContext2D.prototype),a(Path2D.prototype);const{mineType:N,fileType:j}=c;function q(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>t.toDataURL(N(e),i),canvasToBolb:(t,e,i)=>new Promise((n=>t.toBlob(n,N(e),i))),canvasSaveAs:(t,e,n)=>{const s=t.toDataURL(N(j(e)),n);return i.origin.download(s,e)},download:(t,e)=>new Promise((i=>{let n=document.createElement("a");n.href=t,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),i()})),loadImage:t=>new Promise(((e,n)=>{const s=new Image,{crossOrigin:o}=i.image;o&&(s.setAttribute("crossOrigin",o),s.crossOrigin=o),s.onload=()=>{e(s)},s.onerror=t=>{n(t)},s.src=i.image.getRealURL(t)}))},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=r.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(r,{canvas:(t,e)=>new G(t,e),image:t=>new d(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},l(i,"devicePixelRatio",{get:()=>Math.max(1,devicePixelRatio)});const{userAgent:H}=navigator;H.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):H.indexOf("Safari")>-1&&-1===H.indexOf("Chrome")&&(i.fullImageShadow=!0),H.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):H.indexOf("Mac")>-1?i.os="Mac":H.indexOf("Linux")>-1&&(i.os="Linux");class Q{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new h;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 h,this.target=t,e&&(this.config=n.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(u.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===p.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 f(f.DATA,{updatedList:this.updatedList})),this.__updatedList=new h,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(g.CHANGE,this.__onAttrChange,this),t.on_([p.ADD,p.REMOVE],this.__onChildEvent,this),t.on_(f.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:J,updateBounds:Z,updateAllWorldOpacity:$}=_,{pushAllChildBranch:K,pushAllParent:tt}=w;const{worldBounds:et}=m,it={x:0,y:0,width:1e5,height:1e5};class nt{constructor(t){this.updatedBounds=new y,this.beforeBounds=new y,this.afterBounds=new y,t instanceof Array&&(t=new h(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,et)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(it):this.afterBounds.setListWithFn(t,et),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:st,updateAllChange:ot}=_,at=t.get("Layouter");class rt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new v,this.target=t,e&&(this.config=n.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(x.START),this.layoutOnce(),t.emitEvent(new x(x.END,this.layoutedBlocks,this.times))}catch(t){at.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?at.warn("layouting"):this.times>3?at.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(f.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=b.start("PartLayout"),{target:i,__updatedList:n}=this,{BEFORE:s,LAYOUT:o,AFTER:a}=x,r=this.getBlocks(n);r.forEach((t=>t.setBefore())),i.emitEvent(new x(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?(J(t,!0),e.add(t),t.isBranch&&K(t,e),tt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),tt(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||Z(n[t])}Z(i)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&$(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 x(o,r,this.times)),i.emitEvent(new x(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,b.end(e)}fullLayout(){const t=b.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:n,AFTER:s}=x,o=this.getBlocks(new h(e));e.emitEvent(new x(i,o,this.times)),rt.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new x(n,o,this.times)),e.emitEvent(new x(s,o,this.times)),this.addBlocks(o),b.end(t)}static fullLayout(t){st(t,!0),t.isBranch?w.updateBounds(t):_.updateBounds(t),ot(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new nt([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new nt(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_(x.REQUEST,this.layout,this),t.on_(x.AGAIN,this.layoutAgain,this),t.on_(f.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const dt=t.get("Renderer");class lt{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=n.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(x.REQUEST)}render(t){if(!this.running||!this.canvas.view)return this.update();const{target:e}=this;this.times=0,this.totalBounds=new y,dt.log(e.innerName,"---\x3e");try{e.isApp||e.app.emit(u.CHILD_START,e),this.emitRender(u.START),this.renderOnce(t),this.emitRender(u.END,this.totalBounds),B.clearRecycled()}catch(t){this.rendering=!1,dt.error(t)}dt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return dt.warn("rendering");if(this.times>3)return dt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new y,this.renderOptions={},t)this.emitRender(u.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(u.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(u.RENDER,this.renderBounds,this.renderOptions),this.emitRender(u.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;if(!e)return dt.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const i=b.start("PartRender"),{canvas:n}=this,s=e.getIntersect(n.bounds),o=e.includes(this.target.__world),a=new y(s);n.save(),o&&!t.showRepaint?n.clear():(s.spread(10+1/this.canvas.pixelRatio).ceil(),n.clearWorld(s,!0),n.clipWorld(s,!0)),this.__render(s,o,a),n.restore(),b.end(i)}fullRender(){const t=b.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),b.end(t)}__render(e,i,n){const s=e.includes(this.target.__world)?{includes:i}:{bounds:e,includes:i};this.needFill&&this.canvas.fillWorld(e,this.config.fill),t.showRepaint&&this.canvas.strokeWorld(e,"red"),this.target.__render(this.canvas,s),this.renderBounds=n=n||e,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=n:this.totalBounds.add(n),t.showHitView&&this.renderHitView(s),t.showBoundsView&&this.renderBoundsView(s),this.canvas.updateRender(n)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new y;e.setList(t),t.length=0,t.push(e)}}__requestRender(){if(this.requestTime)return;const t=this.requestTime=Date.now();i.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(u.NEXT))}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new y(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 y(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||dt.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 u(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.REQUEST,this.update,this),t.on_(x.END,this.__onLayoutEnd,this),t.on_(u.AGAIN,this.renderAgain,this),t.on_(o.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 ct(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 ht(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?ft(t,!0,e,i):pt(e,i);break;case"inside":ut("inside",t,s,e,i);break;case"outside":ut("outside",t,s,e,i)}}function ut(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?ft(e,!0,n,r):pt(n,r),r.blendMode="outside"===t?"destination-out":"destination-in",ct(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 pt(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 ft(t,e,i,n){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&D.checkImage(i,n,s,!1)||s.style&&(n.strokeStyle=s.style,s.blendMode?(n.saveBlendMode(s.blendMode),e?pt(i,n):n.stroke(),n.restoreBlendMode()):e?pt(i,n):n.stroke())}function gt(t,e){t.__.dashPattern&&(e.beginPath(),t.__drawPathByData(e,t.__.__pathForArrow),e.dashPattern=null,e.stroke())}Object.assign(r,{watcher:(t,e)=>new Q(t,e),layouter:(t,e)=>new rt(t,e),renderer:(t,e,i)=>new lt(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,n)=>{}}),i.layout=rt.fullLayout;const{getSpread:_t,getOuterOf:wt,getByMove:yt,getIntersectData:mt}=R;let vt;function xt(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:P.string(a,r)};case"image":return D.image(i,t,e,n,!vt||!vt[e.url]);case"linear":return I.linearGradient(e,n);case"radial":return I.radialGradient(e,n);case"angular":return I.conicGradient(e,n);default:return void 0!==e.r?{type:"solid",style:P.string(e)}:void 0}}const bt={compute:function(t,e){const i=e.__,n=[];let s,o=i.__input[t];o instanceof Array||(o=[o]),vt=D.recycleImage(t,i);for(let i,s=0,a=o.length;s<a;s++)i=xt(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?ct(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&&D.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?ct(e,i):s?i.fill(s):i.fill(),i.restore()):n.blendMode?(i.saveBlendMode(n.blendMode),o?ct(e,i):s?i.fill(s):i.fill(),i.restoreBlendMode()):o?ct(e,i):s?i.fill(s):i.fill())},fillText:ct,stroke:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)ht(t,e,i);else switch(o){case"center":i.setStroke(t,s,n),i.stroke(),n.__useArrow&&gt(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)ht(t,e,i);else switch(o){case"center":i.setStroke(void 0,s,n),ft(t,!1,e,i),n.__useArrow&&gt(e,i);break;case"inside":i.save(),i.setStroke(void 0,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),ft(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),ft(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:ht,drawTextStroke:pt,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=mt(n?_t(e.bounds,l===c?n*l:[n*c,n*l]):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:p}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,c*=p),r=wt(s,a),o=yt(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,p*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,p)})}return t.__renderShape(n,i),{canvas:n,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:c}}};let Bt={};const{get:Rt,rotateOfOuter:kt,translate:St,scaleOfOuter:Et,scale:Lt,rotate:At}=k;function Ot(t,e,i,n,s,o,a){const r=Rt();St(r,e.x+i,e.y+n),Lt(r,s,o),a&&kt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Wt(t,e,i,n,s,o,a){const r=Rt();St(r,e.x+i,e.y+n),s&&Lt(r,s,o),a&&At(r,a),t.transform=r}function Ct(t,e,i,n,s,o,a,r,d,l){const c=Rt();if(d)if("center"===l)kt(c,{x:i/2,y:n/2},d);else switch(At(c,d),d){case 90:St(c,n,0);break;case 180:St(c,i,n);break;case 270:St(c,0,i)}Bt.x=e.x+s,Bt.y=e.y+o,St(c,Bt.x,Bt.y),a&&Et(c,Bt,a,r),t.transform=c}const{get:Tt,translate:Mt}=k,Dt=new y,Pt={},It={};function zt(t,e,i,n){const{blendMode:s,sync:o}=i;s&&(t.blendMode=s),o&&(t.sync=o),t.data=Ft(i,n,e)}function Ft(t,e,i){let{width:n,height:s}=i;t.padding&&(e=Dt.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}=t,p=e.width===n&&e.height===s,f={mode:a},g="center"!==r&&(h||0)%180==90,_=g?s:n,w=g?n:s;let y,m,v=0,x=0;if(a&&"cover"!==a&&"fit"!==a)(l||c)&&(S.getScaleData(l,c,i,It),y=It.scaleX,m=It.scaleY);else if(!p||h){const t=e.width/_,i=e.height/w;y=m="fit"===a?Math.min(t,i):Math.max(t,i),v+=(e.width-n*y)/2,x+=(e.height-s*m)/2}if(r){const t={x:v,y:x,width:_,height:w};y&&(t.width*=y,t.height*=m),E.toPoint(r,t,e,Pt,!0),v+=Pt.x,x+=Pt.y}switch(d&&(v+=d.x,x+=d.y),a){case"stretch":p||(n=e.width,s=e.height);break;case"normal":case"clip":(v||x||y||h)&&Wt(f,e,v,x,y,m,h);break;case"repeat":(!p||y||h)&&Ct(f,e,n,s,v,x,y,m,h,r),u||(f.repeat="repeat");break;default:y&&Ot(f,e,v,x,y,m,h)}return f.transform||(e.x||e.y)&&(f.transform=Tt(),Mt(f.transform,e.x,e.y)),y&&"stretch"!==a&&(f.scaleX=y,f.scaleY=m),f.width=n,f.height=s,o&&(f.opacity=o),u&&(f.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),f}let Vt,Yt=new y;const{isSame:Ut}=R;function Xt(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||zt(s,n,i,o),!0}function Gt(t,e){qt(t,L.LOAD,e)}function Nt(t,e){qt(t,L.LOADED,e)}function jt(t,e,i){e.error=i,t.forceUpdate("surface"),qt(t,L.ERROR,e)}function qt(t,e,i){t.hasEvent(e)&&t.emitEvent(new L(e,i))}function Ht(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:Qt,scale:Jt,copy:Zt}=k,{ceil:$t,abs:Kt}=Math;function te(t,e,n){let{scaleX:s,scaleY:o}=B.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o+"-"+n;if(e.patternId===a||t.destroyed)return!1;{s=Kt(s),o=Kt(o);const{image:t,data:r}=e;let d,l,{width:c,height:h,scaleX:u,scaleY:p,opacity:f,transform:g,repeat:_}=r;u&&(l=Qt(),Zt(l,g),Jt(l,1/u,1/p),s*=u,o*=p),s*=n,o*=n,c*=s,h*=o;const w=c*h;if(!_&&w>i.image.maxCacheSize)return!1;let y=i.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(s/=d,o/=d,c/=d,h/=d),u&&(s/=u,o/=p),(g||1!==s||1!==o)&&(l||(l=Qt(),g&&Zt(l,g)),Jt(l,1/s,1/o));const m=t.getCanvas($t(c)||1,$t(h)||1,f),v=t.getPattern(m,_||i.origin.noRepeat||"no-repeat",l,e);return e.style=v,e.patternId=a,!0}}function ee(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;const{abs:ie}=Math;const ne={image:function(t,e,i,n,s){let o,a;const r=B.get(i);return Vt&&i===Vt.paint&&Ut(n,Vt.boxBounds)?o=Vt.leafPaint:(o={type:i.type,image:r},Vt=r.use>1?{leafPaint:o,paint:i,boxBounds:Yt.set(n)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(Xt(t,e,i,r,o,n),s&&(Gt(t,a),Nt(t,a))):r.error?s&&jt(t,a,r.error):(s&&(Ht(t,!0),Gt(t,a)),o.loadId=r.load((()=>{Ht(t,!1),t.destroyed||(Xt(t,e,i,r,o,n)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Nt(t,a)),o.loadId=null}),(e=>{Ht(t,!1),jt(t,a,e),o.loadId=null}))),o},checkImage:function(t,e,n,s){const{scaleX:o,scaleY:a}=B.patternLocked?t.__world:t.__nowWorld,{pixelRatio:r}=e;if(!n.data||n.patternId===o+"-"+a+"-"+r&&!z.running)return!1;{const{data:d}=n;if(s)if(d.repeat)s=!1;else{let{width:t,height:e}=d;t*=ie(o)*r,e*=ie(a)*r,d.scaleX&&(t*=d.scaleX,e*=d.scaleY),s=t*e>i.image.maxCacheSize||z.running}return s?(e.save(),t.windingRule?e.clip(t.windingRule):e.clip(),n.blendMode&&(e.blendMode=n.blendMode),d.opacity&&(e.opacity*=d.opacity),d.transform&&e.transform(d.transform),e.drawImage(n.image.view,0,0,d.width,d.height),e.restore(),!0):(!n.style||n.sync||z.running?te(t,n,r):n.patternTask||(n.patternTask=B.patternTasker.add((()=>ee(this,void 0,void 0,(function*(){n.patternTask=null,e.bounds.hit(t.__nowWorld)&&te(t,n,r),t.forceUpdate("surface")}))),300)),!1)}},createPattern:te,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,B.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:zt,getPatternData:Ft,fillOrFitMode:Ot,clipMode:Wt,repeatMode:Ct},{toPoint:se}=A,oe={},ae={};function re(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),P.string(n,i)):t.addColorStop(n.offset,P.string(n.color,i))}}const{getAngle:de,getDistance:le}=O,{get:ce,rotateOfOuter:he,scaleOfOuter:ue}=k,{toPoint:pe}=A,fe={},ge={};function _e(t,e,i,n,s){let o;const{width:a,height:r}=t;if(a!==r||n){const t=de(e,i);o=ce(),s?(ue(o,e,a/r*(n||1),1),he(o,e,t+90)):(ue(o,e,1,a/r*(n||1)),he(o,e,t))}return o}const{getDistance:we}=O,{toPoint:ye}=A,me={},ve={};const xe={linearGradient:function(t,e){let{from:n,to:s,type:o,blendMode:a,opacity:r}=t;se(n||"top",e,oe),se(s||"bottom",e,ae);const d=i.canvas.createLinearGradient(oe.x,oe.y,ae.x,ae.y);re(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,e){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;pe(n||"center",e,fe),pe(s||"bottom",e,ge);const l=i.canvas.createRadialGradient(fe.x,fe.y,0,fe.x,fe.y,le(fe,ge));re(l,t.stops,a);const c={type:o,style:l},h=_e(e,fe,ge,d,!0);return h&&(c.transform=h),r&&(c.blendMode=r),c},conicGradient:function(t,e){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;ye(n||"center",e,me),ye(s||"bottom",e,ve);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,me.x,me.y):i.canvas.createRadialGradient(me.x,me.y,0,me.x,me.y,we(me,ve));re(l,t.stops,a);const c={type:o,style:l},h=_e(e,me,ve,d||1,i.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:_e},{copy:be,toOffsetOutBounds:Be}=R,Re={},ke={};function Se(t,e,n,s){const{bounds:o,shapeBounds:a}=s;if(i.fullImageShadow){if(be(Re,t.bounds),Re.x+=e.x-a.x,Re.y+=e.y-a.y,n){const{matrix:t}=s;Re.x-=(o.x+(t?t.e:0)+o.width/2)*(n-1),Re.y-=(o.y+(t?t.f:0)+o.height/2)*(n-1),Re.width*=n,Re.height*=n}t.copyWorld(s.canvas,t.bounds,Re)}else n&&(be(Re,e),Re.x-=e.width/2*(n-1),Re.y-=e.height/2*(n-1),Re.width*=n,Re.height*=n),t.copyWorld(s.canvas,a,n?Re:e)}const{toOffsetOutBounds:Ee}=R,Le={};const Ae={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,p=e.getSameCanvas(),f=r.length-1;Be(l,ke),r.forEach(((r,g)=>{p.setWorldShadow(ke.offsetX+r.x*h,ke.offsetY+r.y*u,r.blur*h,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Se(p,ke,s,i),n=l,r.box&&(p.restore(),p.save(),d&&(p.copyWorld(p,l,o,"copy"),n=o),d?p.copyWorld(d,o,o,"destination-out"):p.copyWorld(i.canvas,c,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(p,n,o,r.blendMode):e.copyWorldToInner(p,n,a.renderBounds,r.blendMode),f&&g<f&&p.clearWorld(n,!0)})),p.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,p=e.getSameCanvas(),f=r.length-1;Ee(l,Le),r.forEach(((r,g)=>{p.save(),p.setWorldShadow(Le.offsetX+r.x*h,Le.offsetY+r.y*u,r.blur*h),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Se(p,Le,s,i),p.restore(),d?(p.copyWorld(p,l,o,"copy"),p.copyWorld(d,o,o,"source-out"),n=o):(p.copyWorld(i.canvas,c,l,"source-out"),n=l),p.fillWorld(n,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(p,n,o,r.blendMode):e.copyWorldToInner(p,n,a.renderBounds,r.blendMode),f&&g<f&&p.clearWorld(n,!0)})),p.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:Oe}=m;function We(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),Te(t,e,i,1)}(t,i,n,s);break;case"opacity-path":Te(t,i,n,o);break;case"path":i.restore()}}function Ce(t){return t.getSameCanvas(!1,!0)}function Te(t,e,i,n){const s=t.__nowWorld;e.resetTransform(),e.opacity=n,e.copyWorld(i,s),i.recycle(s)}F.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&&(We(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=Ce(t))):(a="path",t.save()),i.__clip(s||t,e)):(a="grayscale"===r?"grayscale":"alpha",n||(n=Ce(t)),s||(s=Ce(t)),i.__render(n,e)),"clipping"!==r&&"clipping-path"!==r)||Oe(i,e)||i.__render(s||t,e);We(this,a,t,s,n,o)};const Me=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",De=Me+"_#~&*+\\=|≮≯≈≠=…",Pe=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 Ie(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const ze=Ie("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Fe=Ie("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Ve=Ie(Me),Ye=Ie(De),Ue=Ie("- —/~|┆·");var Xe;!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"}(Xe||(Xe={}));const{Letter:Ge,Single:Ne,Before:je,After:qe,Symbol:He,Break:Qe}=Xe;function Je(t){return ze[t]?Ge:Ue[t]?Qe:Fe[t]?je:Ve[t]?qe:Ye[t]?He:Pe.test(t)?Ne:Ge}const Ze={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 $e(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:Ke}=Ze,{Letter:ti,Single:ei,Before:ii,After:ni,Symbol:si,Break:oi}=Xe;let ai,ri,di,li,ci,hi,ui,pi,fi,gi,_i,wi,yi,mi,vi,xi,bi,Bi=[];function Ri(t,e){fi&&!pi&&(pi=fi),ai.data.push({char:t,width:e}),di+=e}function ki(){li+=di,ai.width=di,ri.words.push(ai),ai={data:[]},di=0}function Si(){mi&&(vi.paraNumber++,ri.paraStart=!0,mi=!1),fi&&(ri.startCharSize=pi,ri.endCharSize=fi,pi=0),ri.width=li,xi.width?Ke(ri):bi&&Ei(),Bi.push(ri),ri={words:[]},li=0}function Ei(){li>(vi.maxWidth||0)&&(vi.maxWidth=li)}const Li=0,Ai=1,Oi=2;const{top:Wi,right:Ci,bottom:Ti,left:Mi}=W;function Di(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 Pi={getDrawData:function(t,e){"string"!=typeof t&&(t=String(t));let n=0,s=0,o=e.__getInput("width")||0,a=e.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=e;l&&(o?(n=l[Mi],o-=l[Ci]+l[Mi]):e.autoSizeAlign||(n=l[Mi]),a?(s=l[Wi],a-=l[Wi]+l[Ti]):e.autoSizeAlign||(s=l[Wi]));const c={bounds:{x:n,y:s,width:o,height:a},rows:[],paraNumber:0,font:i.canvas.font=d};return function(t,e,n){vi=t,Bi=t.rows,xi=t.bounds,bi=!xi.width&&!n.autoSizeAlign;const{__letterSpacing:s,paraIndent:o,textCase:a}=n,{canvas:r}=i,{width:d,height:l}=xi;if(d||l||s||"none"!==a){const t="none"!==n.textWrap,i="break"===n.textWrap;mi=!0,_i=null,pi=ui=fi=di=li=0,ai={data:[]},ri={words:[]};for(let n=0,l=e.length;n<l;n++)hi=e[n],"\n"===hi?(di&&ki(),ri.paraEnd=!0,Si(),mi=!0):(gi=Je(hi),gi===ti&&"none"!==a&&(hi=$e(hi,a,!di)),ui=r.measureText(hi).width,s&&(s<0&&(fi=ui),ui+=s),wi=gi===ei&&(_i===ei||_i===ti)||_i===ei&&gi!==ni,yi=!(gi!==ii&&gi!==ei||_i!==si&&_i!==ni),ci=mi&&o?d-o:d,t&&d&&li+di+ui>ci&&(i?(di&&ki(),li&&Si()):(yi||(yi=gi===ti&&_i==ni),wi||yi||gi===oi||gi===ii||gi===ei||di+ui>ci?(di&&ki(),li&&Si()):li&&Si()))," "===hi&&!0!==mi&&li+di===0||(gi===oi?(" "===hi&&di&&ki(),Ri(hi,ui),ki()):wi||yi?(di&&ki(),Ri(hi,ui)):Ri(hi,ui)),_i=gi);di&&ki(),li&&Si(),Bi.length>0&&(Bi[Bi.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{vi.paraNumber++,li=r.measureText(t).width,Bi.push({x:o||0,text:t,width:li,paraStart:!0}),bi&&Ei()}))}(c,t,e),l&&function(t,e,i,n,s){if(!n&&i.autoSizeAlign)switch(i.textAlign){case"left":Di(e,"x",t[Mi]);break;case"right":Di(e,"x",-t[Ci])}if(!s&&i.autoSizeAlign)switch(i.verticalAlign){case"top":Di(e,"y",t[Wi]);break;case"bottom":Di(e,"y",-t[Ti])}}(l,c,e,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:p,width:f,height:g}=n,_=s*i.length+(c?c*(t.paraNumber-1):0),w=o;if(r&&_>g)_=Math.max(g,s),t.overflow=i.length;else if(g||h)switch(l){case"middle":p+=(g-_)/2;break;case"bottom":p+=g-_}w+=p;let y,m,v,x=f||h?f:t.maxWidth;for(let o=0,l=i.length;o<l;o++){if(y=i[o],y.x=u,y.width<f||y.width>f&&!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>_&&(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&&f&&f<v&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}n.y=p,n.height=_}(c,e),function(t,e,i,n){const{rows:s}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,l,c,h,u;s.forEach((t=>{t.words&&(c=a&&t.paraStart?a:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-c)/(t.words.length-1):0,h=r||t.isOverflow?Li:l>.01?Ai:Oi,t.isOverflow&&!r&&(t.textMode=!0),h===Oi?(t.x+=c,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=c,d=t.x,t.data=[],t.words.forEach((e=>{h===Ai?(u={char:"",x:d},d=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,d,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,i,n){return t.forEach((t=>{(n||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(c,e,o),c.overflow&&function(t,e,n,s){if(!s)return;const{rows:o,overflow:a}=t;let{textOverflow:r}=e;if(o.splice(a),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const l=r?i.canvas.measureText(r).width:0,c=n+s-l;("none"===e.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,e,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,e),c}};const Ii={string:function(t,e){const i="number"==typeof e&&1!==e;if("string"==typeof t){if(!i||!P.object)return t;t=P.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+")"}},{setPoint:zi,addPoint:Fi,toBounds:Vi}=C;const Yi={export(t,e,n){this.running=!0;const s=c.fileType(e),o=e.includes(".");return n=c.getExportOptions(n),function(t){Ui||(Ui=new T);return new Promise((e=>{Ui.add((()=>ee(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((a=>new Promise((d=>{const l=t=>{a(t),d(),this.running=!1},{toURL:h}=i,{download:u}=i.origin;if("json"===s)return o&&u(h(JSON.stringify(t.toJSON(n.json)),"text"),e),l({data:!!o||t.toJSON(n.json)});if("svg"===s)return o&&u(h(t.toSVG(),"svg"),e),l({data:!!o||t.toSVG()});const{leafer:p}=t;p?(Xi(t),p.waitViewCompleted((()=>ee(this,void 0,void 0,(function*(){let i,s,o=1,a=1;const{worldTransform:d,isLeafer:h,isFrame:u}=t,{slice:f,trim:g,onCanvas:_}=n,w=void 0===n.smooth?p.config.smooth:n.smooth,m=n.contextSettings||p.config.contextSettings,v=n.screenshot||t.isApp,x=h&&v&&void 0===n.fill?t.fill:n.fill,b=c.isOpaqueImage(e)||x,B=new M;if(v)i=!0===v?h?p.canvas.bounds:t.worldRenderBounds:v;else{let e=n.relative||(h?"inner":"local");switch(o=d.scaleX,a=d.scaleY,e){case"inner":B.set(d);break;case"local":B.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:B.set(d).divide(t.getTransform(e));const i=e.worldTransform;o/=o/i.scaleX,a/=a/i.scaleY}i=t.getBounds("render",e)}const R={scaleX:1,scaleY:1};S.getScaleData(n.scale,n.size,i,R);let k=n.pixelRatio||1;t.isApp&&(R.scaleX*=k,R.scaleY*=k,k=t.app.pixelRatio);const{x:E,y:L,width:A,height:O}=new y(i).scale(R.scaleX,R.scaleY),W={matrix:B.scale(1/R.scaleX,1/R.scaleY).invert().translate(-E,-L).withScale(1/o*R.scaleX,1/a*R.scaleY)};let C,T=r.canvas({width:Math.round(A),height:Math.round(O),pixelRatio:k,smooth:w,contextSettings:m});if(f&&(C=t,C.__worldOpacity=0,t=p,W.bounds=T.bounds),T.save(),u&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(T,W),t.fill=e}else t.__render(T,W);if(T.restore(),C&&C.__updateWorldOpacity(),g){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?Fi(a,s,o):zi(a={},s,o)),r++;const d=new y;return Vi(a,d),d.scale(1/t.pixelRatio).ceil()}(T);const t=T,{width:e,height:i}=s,n={x:0,y:0,width:e,height:i,pixelRatio:k};T=r.canvas(n),T.copyWorld(t,s,n)}b&&T.fillWorld(T.bounds,x||"#FFFFFF","destination-over"),_&&_(T);const D="canvas"===e?T:yield T.export(e,n);l({data:D,width:T.pixelWidth,height:T.pixelHeight,renderBounds:i,trimBounds:s})}))))):l({data:!1})}))))}};let Ui;function Xi(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Xi(t)))}const Gi=e.prototype,Ni=t.get("@leafer-ui/export");Gi.export=function(t,e){const{quality:i,blob:n}=c.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):n?this.toBlob(t,i):this.toDataURL(t,i)},Gi.toBlob=function(t,e){return new Promise((n=>{i.origin.canvasToBolb(this.view,t,e).then((t=>{n(t)})).catch((t=>{Ni.error(t),n(null)}))}))},Gi.toDataURL=function(t,e){return i.origin.canvasToDataURL(this.view,t,e)},Gi.saveAs=function(t,e){return new Promise((n=>{i.origin.canvasSaveAs(this.view,t,e).then((()=>{n(!0)})).catch((t=>{Ni.error(t),n(!1)}))}))},Object.assign(V,Pi),Object.assign(P,Ii),Object.assign(Y,bt),Object.assign(D,ne),Object.assign(I,xe),Object.assign(U,Ae),Object.assign(z,Yi),q();export{rt as Layouter,G as LeaferCanvas,lt as Renderer,Q as Watcher,q as useCanvas};
1
+ import{Debug as t,LeaferCanvasBase as e,Platform as i,DataHelper as s,canvasSizeAttrs as n,ResizeEvent as o,canvasPatch as a,Creator as r,LeaferImage as d,defineKey as l,FileHelper as h,LeafList as c,RenderEvent as u,ChildEvent as p,WatchEvent as f,PropertyEvent as _,LeafHelper as g,BranchHelper as w,Bounds as y,LeafBoundsHelper as m,LeafLevelList as v,LayoutEvent as x,Run as b,ImageManager as B,BoundsHelper as R,MatrixHelper as k,MathHelper as E,AlignHelper as S,ImageEvent as L,AroundHelper as A,PointHelper as O,Direction4 as W}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as C,ColorConvert as T,PaintGradient as M,Export as D,Group as I,TextConvert as P,Paint as z,Effect as F}from"@leafer-ui/draw";export*from"@leafer-ui/draw";const V=t.get("LeaferCanvas");class Y extends e{set zIndex(t){const{style:e}=this.view;e.zIndex=t,this.setAbsolute(this.view)}set childIndex(t){const{view:e,parentView:i}=this;if(e&&i){const s=i.children[t];s?(this.setAbsolute(s),i.insertBefore(e,s)):i.appendChild(s)}}init(){const{config:t}=this,e=t.view||t.canvas;e?this.__createViewFrom(e):this.__createView();const{style:s}=this.view;if(s.display||(s.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none"}i.syncDomFont&&!this.parentView&&(s.display="none",document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(t)}set backgroundColor(t){this.view.style.backgroundColor=t}get backgroundColor(){return this.view.style.backgroundColor}set hittable(t){this.view.style.pointerEvents=t?"auto":"none"}get hittable(){return"none"!==this.view.style.pointerEvents}__createView(){this.view=document.createElement("canvas")}__createViewFrom(t){let e="string"==typeof t?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:i}=e;i.position="absolute",i.top=i.bottom=i.left=i.right="0px",document.body.appendChild(e),t=e}this.__createView();const i=this.view;t.hasChildNodes()&&(this.setAbsolute(i),t.style.position||(t.style.position="relative")),t.appendChild(i)}else V.error(`no id: ${t}`),this.__createView()}setAbsolute(t){const{style:e}=t;e.position="absolute",e.top=e.left="0px"}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;s.width=t+"px",s.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.view.parentElement&&(this.clientBounds=this.view.getBoundingClientRect())}startAutoLayout(t,e){if(this.resizeListener=e,t){this.autoBounds=t;try{this.resizeObserver=new ResizeObserver((t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)}));const t=this.parentView;t?(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect())):(this.checkAutoBounds(this.view),V.warn("no parent"))}catch(t){this.imitateResizeObserver()}}else window.addEventListener("resize",(()=>{const t=i.devicePixelRatio;if(this.pixelRatio!==t){const{width:e,height:i}=this;this.emitResize({width:e,height:i,pixelRatio:t})}}))}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}checkAutoBounds(t){const e=this.view,{x:s,y:n,width:o,height:a}=this.autoBounds.getBoundsFrom(t),r={width:o,height:a,pixelRatio:i.devicePixelRatio};if(!this.isSameSize(r)){const{style:t}=e;t.marginLeft=s+"px",t.marginTop=n+"px",this.emitResize(r)}}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}emitResize(t){const e={};s.copyAttrs(e,this,n),this.resize(t),this.resizeListener&&void 0!==this.width&&this.resizeListener(new o(t,e))}unrealCanvas(){if(!this.unreal&&this.parentView){const t=this.view;t&&t.remove(),this.view=this.parentView,this.unreal=!0}}destroy(){if(this.view){if(this.stopAutoLayout(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}a(CanvasRenderingContext2D.prototype),a(Path2D.prototype);const{mineType:G,fileType:U}=h;function N(t,e){i.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>t.toDataURL(G(e),i),canvasToBolb:(t,e,i)=>new Promise((s=>t.toBlob(s,G(e),i))),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL(G(U(e)),s);return i.origin.download(n,e)},download:(t,e)=>new Promise((i=>{let s=document.createElement("a");s.href=t,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),i()})),loadImage:t=>new Promise(((e,s)=>{const n=new Image,{crossOrigin:o}=i.image;o&&(n.setAttribute("crossOrigin",o),n.crossOrigin=o),n.onload=()=>{e(n)},n.onerror=t=>{s(t)},n.src=i.image.getRealURL(t)}))},i.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},i.canvas=r.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(r,{canvas:(t,e)=>new Y(t,e),image:t=>new d(t)}),i.name="web",i.isMobile="ontouchstart"in window,i.requestRender=function(t){window.requestAnimationFrame(t)},l(i,"devicePixelRatio",{get:()=>Math.max(1,devicePixelRatio)});const{userAgent:j}=navigator;j.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):j.indexOf("Safari")>-1&&-1===j.indexOf("Chrome")&&(i.fullImageShadow=!0),j.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):j.indexOf("Mac")>-1?i.os="Mac":j.indexOf("Linux")>-1&&(i.os="Linux");class X{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new c;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 c,this.target=t,e&&(this.config=s.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(u.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===p.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 f(f.DATA,{updatedList:this.updatedList})),this.__updatedList=new c,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(_.CHANGE,this.__onAttrChange,this),t.on_([p.ADD,p.REMOVE],this.__onChildEvent,this),t.on_(f.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:q,updateBounds:H,updateAllWorldOpacity:Q}=g,{pushAllChildBranch:Z,pushAllParent:$}=w;const{worldBounds:J}=m,K={x:0,y:0,width:1e5,height:1e5};class tt{constructor(t){this.updatedBounds=new y,this.beforeBounds=new y,this.afterBounds=new y,t instanceof Array&&(t=new c(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,J)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(K):this.afterBounds.setListWithFn(t,J),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:et,updateAllChange:it}=g,st=t.get("Layouter");class nt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new v,this.target=t,e&&(this.config=s.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(x.START),this.layoutOnce(),t.emitEvent(new x(x.END,this.layoutedBlocks,this.times))}catch(t){st.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?st.warn("layouting"):this.times>3?st.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(f.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=b.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:o,AFTER:a}=x,r=this.getBlocks(s);r.forEach((t=>t.setBefore())),i.emitEvent(new x(n,r,this.times)),this.extraBlock=null,s.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(q(t,!0),e.add(t),t.isBranch&&Z(t,e),$(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),$(t,e)))}))}(s,this.__levelList),function(t){let e,i,s;t.sort(!0),t.levels.forEach((n=>{e=t.levelMap[n];for(let t=0,n=e.length;t<n;t++){if(i=e[t],i.isBranch&&i.__tempNumber){s=i.children;for(let t=0,e=s.length;t<e;t++)s[t].isBranch||H(s[t])}H(i)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&Q(t),e.stateStyleChanged&&setTimeout((()=>e.stateStyleChanged&&t.updateState())),t.__updateChange()}))}(s),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new x(o,r,this.times)),i.emitEvent(new x(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,b.end(e)}fullLayout(){const t=b.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=x,o=this.getBlocks(new c(e));e.emitEvent(new x(i,o,this.times)),nt.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new x(s,o,this.times)),e.emitEvent(new x(n,o,this.times)),this.addBlocks(o),b.end(t)}static fullLayout(t){et(t,!0),t.isBranch?w.updateBounds(t):g.updateBounds(t),it(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new tt([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new tt(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_(x.REQUEST,this.layout,this),t.on_(x.AGAIN,this.layoutAgain,this),t.on_(f.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const ot=t.get("Renderer");class at{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=s.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(x.REQUEST)}render(t){if(!this.running||!this.canvas.view)return this.update();const{target:e}=this;this.times=0,this.totalBounds=new y,ot.log(e.innerName,"---\x3e");try{e.isApp||e.app.emit(u.CHILD_START,e),this.emitRender(u.START),this.renderOnce(t),this.emitRender(u.END,this.totalBounds),B.clearRecycled()}catch(t){this.rendering=!1,ot.error(t)}ot.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return ot.warn("rendering");if(this.times>3)return ot.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new y,this.renderOptions={},t)this.emitRender(u.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(u.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(u.RENDER,this.renderBounds,this.renderOptions),this.emitRender(u.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;if(!e)return ot.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const i=b.start("PartRender"),{canvas:s}=this,n=e.getIntersect(s.bounds),o=e.includes(this.target.__world),a=new y(n);s.save(),o&&!t.showRepaint?s.clear():(n.spread(10+1/this.canvas.pixelRatio).ceil(),s.clearWorld(n,!0),s.clipWorld(n,!0)),this.__render(n,o,a),s.restore(),b.end(i)}fullRender(){const t=b.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),b.end(t)}__render(e,i,s){const n=e.includes(this.target.__world)?{includes:i}:{bounds:e,includes:i};this.needFill&&this.canvas.fillWorld(e,this.config.fill),t.showRepaint&&this.canvas.strokeWorld(e,"red"),this.target.__render(this.canvas,n),this.renderBounds=s=s||e,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=s:this.totalBounds.add(s),t.showHitView&&this.renderHitView(n),t.showBoundsView&&this.renderBoundsView(n),this.canvas.updateRender(s)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new y;e.setList(t),t.length=0,t.push(e)}}__requestRender(){if(this.requestTime)return;const t=this.requestTime=Date.now();i.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(u.NEXT))}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new y(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 y(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||ot.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 u(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.REQUEST,this.update,this),t.on_(x.END,this.__onLayoutEnd,this),t.on_(u.AGAIN,this.renderAgain,this),t.on_(o.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 rt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;t++)i=s[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)})),n&&e.fillRect(i.x,i.y+n,i.width,o)}function dt(t,e,i){const{strokeAlign:s}=e.__,n="string"!=typeof t;switch(s){case"center":i.setStroke(n?void 0:t,e.__.strokeWidth,e.__),n?ct(t,!0,e,i):ht(e,i);break;case"inside":lt("inside",t,n,e,i);break;case"outside":lt("outside",t,n,e,i)}}function lt(t,e,i,s,n){const{__strokeWidth:o,__font:a}=s.__,r=n.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,s.__),r.font=a,i?ct(e,!0,s,r):ht(s,r),r.blendMode="outside"===t?"destination-out":"destination-in",rt(s,r),r.blendMode="normal",s.__worldFlipped?n.copyWorldByReset(r,s.__nowWorld):n.copyWorldToInner(r,s.__nowWorld,s.__layout.renderBounds),r.recycle(s.__nowWorld)}function ht(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;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)})),n&&e.strokeRect(i.x,i.y+n,i.width,o)}function ct(t,e,i,s){let n;for(let o=0,a=t.length;o<a;o++)n=t[o],n.image&&C.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?ht(i,s):s.stroke(),s.restoreBlendMode()):e?ht(i,s):s.stroke())}function ut(t,e){t.__.dashPattern&&(e.beginPath(),t.__drawPathByData(e,t.__.__pathForArrow),e.dashPattern=null,e.stroke())}Object.assign(r,{watcher:(t,e)=>new X(t,e),layouter:(t,e)=>new nt(t,e),renderer:(t,e,i)=>new at(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,s)=>{}}),i.layout=nt.fullLayout;const{getSpread:pt,getOuterOf:ft,getByMove:_t,getIntersectData:gt}=R;let wt;function yt(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:s}=i.__layout;switch(e.type){case"solid":let{type:n,blendMode:o,color:a,opacity:r}=e;return{type:n,blendMode:o,style:T.string(a,r)};case"image":return C.image(i,t,e,s,!wt||!wt[e.url]);case"linear":return M.linearGradient(e,s);case"radial":return M.radialGradient(e,s);case"angular":return M.conicGradient(e,s);default:return void 0!==e.r?{type:"solid",style:T.string(e)}:void 0}}const mt={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),wt=C.recycleImage(t,i);for(let i,n=0,a=o.length;n<a;n++)i=yt(t,o[n],e),i&&s.push(i);i["_"+t]=s.length?s:void 0,s.length&&s[0].image&&(n=s[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=n:i.__pixelStroke=n},fill:function(t,e,i){i.fillStyle=t,e.__.__font?rt(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let s;const{windingRule:n,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)s=t[a],s.image&&C.checkImage(e,i,s,!o)||s.style&&(i.fillStyle=s.style,s.transform?(i.save(),i.transform(s.transform),s.blendMode&&(i.blendMode=s.blendMode),o?rt(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?rt(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?rt(e,i):n?i.fill(n):i.fill())},fillText:rt,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:a}=s;if(n)if(a)dt(t,e,i);else switch(o){case"center":i.setStroke(t,n,s),i.stroke(),s.__useArrow&&ut(e,i);break;case"inside":i.save(),i.setStroke(t,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*n,s),e.__drawRenderPath(o),o.stroke(),s.windingRule?o.clip(s.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 s=e.__,{__strokeWidth:n,strokeAlign:o,__font:a}=s;if(n)if(a)dt(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),ct(t,!1,e,i),s.__useArrow&&ut(e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),ct(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*n,s),ct(t,!1,e,a),s.windingRule?a.clip(s.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:dt,drawTextStroke:ht,shape:function(t,e,i){const s=e.getSameCanvas(),n=t.__nowWorld;let o,a,r,d,{scaleX:l,scaleY:h}=n;if(l<0&&(l=-l),h<0&&(h=-h),e.bounds.includes(n))d=s,o=r=n;else{const{renderShapeSpread:s}=t.__layout,c=gt(s?pt(e.bounds,l===h?s*l:[s*h,s*l]):e.bounds,n);a=e.bounds.getFitMatrix(c);let{a:u,d:p}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,h*=p),r=ft(n,a),o=_t(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,p*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,p)})}return t.__renderShape(s,i),{canvas:s,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:h}}};let vt={};const{get:xt,rotateOfOuter:bt,translate:Bt,scaleOfOuter:Rt,scale:kt,rotate:Et}=k;function St(t,e,i,s,n,o,a){const r=xt();Bt(r,e.x+i,e.y+s),kt(r,n,o),a&&bt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Lt(t,e,i,s,n,o,a){const r=xt();Bt(r,e.x+i,e.y+s),n&&kt(r,n,o),a&&Et(r,a),t.transform=r}function At(t,e,i,s,n,o,a,r,d,l){const h=xt();if(d)if("center"===l)bt(h,{x:i/2,y:s/2},d);else switch(Et(h,d),d){case 90:Bt(h,s,0);break;case 180:Bt(h,i,s);break;case 270:Bt(h,0,i)}vt.x=e.x+n,vt.y=e.y+o,Bt(h,vt.x,vt.y),a&&Rt(h,vt,a,r),t.transform=h}const{get:Ot,translate:Wt}=k,Ct=new y,Tt={},Mt={};function Dt(t,e,i,s){const{blendMode:n,sync:o}=i;n&&(t.blendMode=n),o&&(t.sync=o),t.data=It(i,s,e)}function It(t,e,i){let{width:s,height:n}=i;t.padding&&(e=Ct.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{opacity:o,mode:a,align:r,offset:d,scale:l,size:h,rotation:c,repeat:u}=t,p=e.width===s&&e.height===n,f={mode:a},_="center"!==r&&(c||0)%180==90,g=_?n:s,w=_?s:n;let y,m,v=0,x=0;if(a&&"cover"!==a&&"fit"!==a)(l||h)&&(E.getScaleData(l,h,i,Mt),y=Mt.scaleX,m=Mt.scaleY);else if(!p||c){const t=e.width/g,i=e.height/w;y=m="fit"===a?Math.min(t,i):Math.max(t,i),v+=(e.width-s*y)/2,x+=(e.height-n*m)/2}if(r){const t={x:v,y:x,width:g,height:w};y&&(t.width*=y,t.height*=m),S.toPoint(r,t,e,Tt,!0),v+=Tt.x,x+=Tt.y}switch(d&&(v+=d.x,x+=d.y),a){case"stretch":p||(s=e.width,n=e.height);break;case"normal":case"clip":(v||x||y||c)&&Lt(f,e,v,x,y,m,c);break;case"repeat":(!p||y||c)&&At(f,e,s,n,v,x,y,m,c,r),u||(f.repeat="repeat");break;default:y&&St(f,e,v,x,y,m,c)}return f.transform||(e.x||e.y)&&(f.transform=Ot(),Wt(f.transform,e.x,e.y)),y&&"stretch"!==a&&(f.scaleX=y,f.scaleY=m),f.width=s,f.height=n,o&&(f.opacity=o),u&&(f.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),f}let Pt,zt=new y;const{isSame:Ft}=R;function Vt(t,e,i,s,n,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=s.width/e.pixelRatio,e.__naturalHeight=s.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return n.data||Dt(n,s,i,o),!0}function Yt(t,e){Nt(t,L.LOAD,e)}function Gt(t,e){Nt(t,L.LOADED,e)}function Ut(t,e,i){e.error=i,t.forceUpdate("surface"),Nt(t,L.ERROR,e)}function Nt(t,e,i){t.hasEvent(e)&&t.emitEvent(new L(e,i))}function jt(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:Xt,scale:qt,copy:Ht}=k,{ceil:Qt,abs:Zt}=Math;function $t(t,e,s){let{scaleX:n,scaleY:o}=B.patternLocked?t.__world:t.__nowWorld;const a=n+"-"+o+"-"+s;if(e.patternId===a||t.destroyed)return!1;{n=Zt(n),o=Zt(o);const{image:t,data:r}=e;let d,l,{width:h,height:c,scaleX:u,scaleY:p,opacity:f,transform:_,repeat:g}=r;u&&(l=Xt(),Ht(l,_),qt(l,1/u,1/p),n*=u,o*=p),n*=s,o*=s,h*=n,c*=o;const w=h*c;if(!g&&w>i.image.maxCacheSize)return!1;let y=i.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(n/=d,o/=d,h/=d,c/=d),u&&(n/=u,o/=p),(_||1!==n||1!==o)&&(l||(l=Xt(),_&&Ht(l,_)),qt(l,1/n,1/o));const m=t.getCanvas(Qt(h)||1,Qt(c)||1,f),v=t.getPattern(m,g||i.origin.noRepeat||"no-repeat",l,e);return e.style=v,e.patternId=a,!0}}function Jt(t,e,i,s){return new(i||(i=Promise))((function(n,o){function a(t){try{d(s.next(t))}catch(t){o(t)}}function r(t){try{d(s.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}d((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:Kt}=Math;const te={image:function(t,e,i,s,n){let o,a;const r=B.get(i);return Pt&&i===Pt.paint&&Ft(s,Pt.boxBounds)?o=Pt.leafPaint:(o={type:i.type,image:r},Pt=r.use>1?{leafPaint:o,paint:i,boxBounds:zt.set(s)}:null),(n||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(Vt(t,e,i,r,o,s),n&&(Yt(t,a),Gt(t,a))):r.error?n&&Ut(t,a,r.error):(n&&(jt(t,!0),Yt(t,a)),o.loadId=r.load((()=>{jt(t,!1),t.destroyed||(Vt(t,e,i,r,o,s)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Gt(t,a)),o.loadId=null}),(e=>{jt(t,!1),Ut(t,a,e),o.loadId=null}))),o},checkImage:function(t,e,s,n){const{scaleX:o,scaleY:a}=B.patternLocked?t.__world:t.__nowWorld,{pixelRatio:r}=e;if(!s.data||s.patternId===o+"-"+a+"-"+r&&!D.running)return!1;{const{data:d}=s;if(n)if(d.repeat)n=!1;else{let{width:t,height:e}=d;t*=Kt(o)*r,e*=Kt(a)*r,d.scaleX&&(t*=d.scaleX,e*=d.scaleY),n=t*e>i.image.maxCacheSize||D.running}return n?(e.save(),t.windingRule?e.clip(t.windingRule):e.clip(),s.blendMode&&(e.blendMode=s.blendMode),d.opacity&&(e.opacity*=d.opacity),d.transform&&e.transform(d.transform),e.drawImage(s.image.view,0,0,d.width,d.height),e.restore(),!0):(!s.style||s.sync||D.running?$t(t,s,r):s.patternTask||(s.patternTask=B.patternTasker.add((()=>Jt(this,void 0,void 0,(function*(){s.patternTask=null,e.bounds.hit(t.__nowWorld)&&$t(t,s,r),t.forceUpdate("surface")}))),300)),!1)}},createPattern:$t,recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let s,n,o,a;for(let r=0,d=i.length;r<d;r++)s=i[r].image,a=s&&s.url,a&&(n||(n={}),n[a]=!0,B.recycle(s),s.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),s.unload(i[r].loadId,!o.some((t=>t.url===a)))));return n}return null},createData:Dt,getPatternData:It,fillOrFitMode:St,clipMode:Lt,repeatMode:At},{toPoint:ee}=A,ie={},se={};function ne(t,e,i){if(e){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],"string"==typeof s?t.addColorStop(n/(o-1),T.string(s,i)):t.addColorStop(s.offset,T.string(s.color,i))}}const{getAngle:oe,getDistance:ae}=O,{get:re,rotateOfOuter:de,scaleOfOuter:le}=k,{toPoint:he}=A,ce={},ue={};function pe(t,e,i,s,n){let o;const{width:a,height:r}=t;if(a!==r||s){const t=oe(e,i);o=re(),n?(le(o,e,a/r*(s||1),1),de(o,e,t+90)):(le(o,e,1,a/r*(s||1)),de(o,e,t))}return o}const{getDistance:fe}=O,{toPoint:_e}=A,ge={},we={};const ye={linearGradient:function(t,e){let{from:s,to:n,type:o,blendMode:a,opacity:r}=t;ee(s||"top",e,ie),ee(n||"bottom",e,se);const d=i.canvas.createLinearGradient(ie.x,ie.y,se.x,se.y);ne(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,e){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:d}=t;he(s||"center",e,ce),he(n||"bottom",e,ue);const l=i.canvas.createRadialGradient(ce.x,ce.y,0,ce.x,ce.y,ae(ce,ue));ne(l,t.stops,a);const h={type:o,style:l},c=pe(e,ce,ue,d,!0);return c&&(h.transform=c),r&&(h.blendMode=r),h},conicGradient:function(t,e){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:d}=t;_e(s||"center",e,ge),_e(n||"bottom",e,we);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,ge.x,ge.y):i.canvas.createRadialGradient(ge.x,ge.y,0,ge.x,ge.y,fe(ge,we));ne(l,t.stops,a);const h={type:o,style:l},c=pe(e,ge,we,d||1,i.conicGradientRotate90);return c&&(h.transform=c),r&&(h.blendMode=r),h},getTransform:pe},{copy:me,toOffsetOutBounds:ve}=R,xe={},be={};function Be(t,e,s,n){const{bounds:o,shapeBounds:a}=n;if(i.fullImageShadow){if(me(xe,t.bounds),xe.x+=e.x-a.x,xe.y+=e.y-a.y,s){const{matrix:t}=n;xe.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),xe.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),xe.width*=s,xe.height*=s}t.copyWorld(n.canvas,t.bounds,xe)}else s&&(me(xe,e),xe.x-=e.width/2*(s-1),xe.y-=e.height/2*(s-1),xe.width*=s,xe.height*=s),t.copyWorld(n.canvas,a,s?xe:e)}const{toOffsetOutBounds:Re}=R,ke={};const Ee={shadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,p=e.getSameCanvas(),f=r.length-1;ve(l,be),r.forEach(((r,_)=>{p.setWorldShadow(be.offsetX+r.x*c,be.offsetY+r.y*u,r.blur*c,r.color),n=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Be(p,be,n,i),s=l,r.box&&(p.restore(),p.save(),d&&(p.copyWorld(p,l,o,"copy"),s=o),d?p.copyWorld(d,o,o,"destination-out"):p.copyWorld(i.canvas,h,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(p,s,o,r.blendMode):e.copyWorldToInner(p,s,a.renderBounds,r.blendMode),f&&_<f&&p.clearWorld(s,!0)})),p.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,p=e.getSameCanvas(),f=r.length-1;Re(l,ke),r.forEach(((r,_)=>{p.save(),p.setWorldShadow(ke.offsetX+r.x*c,ke.offsetY+r.y*u,r.blur*c),n=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Be(p,ke,n,i),p.restore(),d?(p.copyWorld(p,l,o,"copy"),p.copyWorld(d,o,o,"source-out"),s=o):(p.copyWorld(i.canvas,h,l,"source-out"),s=l),p.fillWorld(s,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(p,s,o,r.blendMode):e.copyWorldToInner(p,s,a.renderBounds,r.blendMode),f&&_<f&&p.clearWorld(s,!0)})),p.recycle(s)},blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Se}=m;function Le(t,e,i,s,n,o){switch(e){case"grayscale":n.useGrayscaleAlpha(t.__nowWorld);case"alpha":!function(t,e,i,s){const n=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,n),s.recycle(n),Oe(t,e,i,1)}(t,i,s,n);break;case"opacity-path":Oe(t,i,s,o);break;case"path":i.restore()}}function Ae(t){return t.getSameCanvas(!1,!0)}function Oe(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}I.prototype.__renderMask=function(t,e){let i,s,n,o,a,r;const{children:d}=this;for(let l=0,h=d.length;l<h;l++)i=d[l],r=i.__.mask,r&&(a&&(Le(this,a,t,n,s,o),s=n=null),"path"===r||"clipping-path"===r?(i.opacity<1?(a="opacity-path",o=i.opacity,n||(n=Ae(t))):(a="path",t.save()),i.__clip(n||t,e)):(a="grayscale"===r?"grayscale":"alpha",s||(s=Ae(t)),n||(n=Ae(t)),i.__render(s,e)),"clipping"!==r&&"clipping-path"!==r)||Se(i,e)||i.__render(n||t,e);Le(this,a,t,n,s,o)};const We=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Ce=We+"_#~&*+\\=|≮≯≈≠=…",Te=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map((([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`)).join("|"));function Me(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const De=Me("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ie=Me("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Pe=Me(We),ze=Me(Ce),Fe=Me("- —/~|┆·");var Ve;!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"}(Ve||(Ve={}));const{Letter:Ye,Single:Ge,Before:Ue,After:Ne,Symbol:je,Break:Xe}=Ve;function qe(t){return De[t]?Ye:Fe[t]?Xe:Ie[t]?Ue:Pe[t]?Ne:ze[t]?je:Te.test(t)?Ge:Ye}const He={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let o=n-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function Qe(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:Ze}=He,{Letter:$e,Single:Je,Before:Ke,After:ti,Symbol:ei,Break:ii}=Ve;let si,ni,oi,ai,ri,di,li,hi,ci,ui,pi,fi,_i,gi,wi,yi,mi,vi=[];function xi(t,e){ci&&!hi&&(hi=ci),si.data.push({char:t,width:e}),oi+=e}function bi(){ai+=oi,si.width=oi,ni.words.push(si),si={data:[]},oi=0}function Bi(){gi&&(wi.paraNumber++,ni.paraStart=!0,gi=!1),ci&&(ni.startCharSize=hi,ni.endCharSize=ci,hi=0),ni.width=ai,yi.width?Ze(ni):mi&&Ri(),vi.push(ni),ni={words:[]},ai=0}function Ri(){ai>(wi.maxWidth||0)&&(wi.maxWidth=ai)}const ki=0,Ei=1,Si=2;const{top:Li,right:Ai,bottom:Oi,left:Wi}=W;function Ci(t,e,i){const{bounds:s,rows:n}=t;s[e]+=i;for(let t=0;t<n.length;t++)n[t][e]+=i}const Ti={getDrawData:function(t,e){"string"!=typeof t&&(t=String(t));let s=0,n=0,o=e.__getInput("width")||0,a=e.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=e;l&&(o?(s=l[Wi],o-=l[Ai]+l[Wi]):e.autoSizeAlign||(s=l[Wi]),a?(n=l[Li],a-=l[Li]+l[Oi]):e.autoSizeAlign||(n=l[Li]));const h={bounds:{x:s,y:n,width:o,height:a},rows:[],paraNumber:0,font:i.canvas.font=d};return function(t,e,s){wi=t,vi=t.rows,yi=t.bounds,mi=!yi.width&&!s.autoSizeAlign;const{__letterSpacing:n,paraIndent:o,textCase:a}=s,{canvas:r}=i,{width:d,height:l}=yi;if(d||l||n||"none"!==a){const t="none"!==s.textWrap,i="break"===s.textWrap;gi=!0,pi=null,hi=li=ci=oi=ai=0,si={data:[]},ni={words:[]};for(let s=0,l=e.length;s<l;s++)di=e[s],"\n"===di?(oi&&bi(),ni.paraEnd=!0,Bi(),gi=!0):(ui=qe(di),ui===$e&&"none"!==a&&(di=Qe(di,a,!oi)),li=r.measureText(di).width,n&&(n<0&&(ci=li),li+=n),fi=ui===Je&&(pi===Je||pi===$e)||pi===Je&&ui!==ti,_i=!(ui!==Ke&&ui!==Je||pi!==ei&&pi!==ti),ri=gi&&o?d-o:d,t&&d&&ai+oi+li>ri&&(i?(oi&&bi(),ai&&Bi()):(_i||(_i=ui===$e&&pi==ti),fi||_i||ui===ii||ui===Ke||ui===Je||oi+li>ri?(oi&&bi(),ai&&Bi()):ai&&Bi()))," "===di&&!0!==gi&&ai+oi===0||(ui===ii?(" "===di&&oi&&bi(),xi(di,li),bi()):fi||_i?(oi&&bi(),xi(di,li)):xi(di,li)),pi=ui);oi&&bi(),ai&&Bi(),vi.length>0&&(vi[vi.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{wi.paraNumber++,ai=r.measureText(t).width,vi.push({x:o||0,text:t,width:ai,paraStart:!0}),mi&&Ri()}))}(h,t,e),l&&function(t,e,i,s,n){if(!s&&i.autoSizeAlign)switch(i.textAlign){case"left":Ci(e,"x",t[Wi]);break;case"right":Ci(e,"x",-t[Ai])}if(!n&&i.autoSizeAlign)switch(i.verticalAlign){case"top":Ci(e,"y",t[Li]);break;case"bottom":Ci(e,"y",-t[Oi])}}(l,h,e,o,a),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:h,autoSizeAlign:c}=e;let{x:u,y:p,width:f,height:_}=s,g=n*i.length+(h?h*(t.paraNumber-1):0),w=o;if(r&&g>_)g=Math.max(_,n),t.overflow=i.length;else if(_||c)switch(l){case"middle":p+=(_-g)/2;break;case"bottom":p+=_-g}w+=p;let y,m,v,x=f||c?f:t.maxWidth;for(let o=0,l=i.length;o<l;o++){if(y=i[o],y.x=u,y.width<f||y.width>f&&!r)switch(d){case"center":y.x+=(x-y.width)/2;break;case"right":y.x+=x-y.width}y.paraStart&&h&&o>0&&(w+=h),y.y=w,w+=n,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<s.x&&(s.x=m),v>s.width&&(s.width=v),r&&f&&f<v&&(y.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=p,s.height=g}(h,e),function(t,e,i,s){const{rows:n}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,l,h,c,u;n.forEach((t=>{t.words&&(h=a&&t.paraStart?a:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-h)/(t.words.length-1):0,c=r||t.isOverflow?ki:l>.01?Ei:Si,t.isOverflow&&!r&&(t.textMode=!0),c===Si?(t.x+=h,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=h,d=t.x,t.data=[],t.words.forEach((e=>{c===Ei?(u={char:"",x:d},d=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,d,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,i,s){return t.forEach((t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(h,e,o),h.overflow&&function(t,e,s,n){if(!n)return;const{rows:o,overflow:a}=t;let{textOverflow:r}=e;if(o.splice(a),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const l=r?i.canvas.measureText(r).width:0,h=s+n-l;("none"===e.textWrap?o:[o[a-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],d=t.x+t.width,!(s===i&&d<h));s--){if(d<h&&" "!==t.char){e.data.splice(s+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)}}))}}(h,e,s,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}}(h,e),h}};const Mi={string:function(t,e){const i="number"==typeof e&&1!==e;if("string"==typeof t){if(!i||!T.object)return t;t=T.object(t)}let s=void 0===t.a?1:t.a;i&&(s*=e);const n=t.r+","+t.g+","+t.b;return 1===s?"rgb("+n+")":"rgba("+n+","+s+")"}};Object.assign(P,Ti),Object.assign(T,Mi),Object.assign(z,mt),Object.assign(C,te),Object.assign(M,ye),Object.assign(F,Ee),N();export{nt as Layouter,Y as LeaferCanvas,at as Renderer,X as Watcher,N as useCanvas};