leafer-ui 1.0.0-rc.5 → 1.0.0-rc.6

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{LeafList as t,DataHelper as e,RenderEvent as i,ChildEvent as s,WatchEvent as n,PropertyEvent as o,LeafHelper as r,BranchHelper as a,Bounds as h,LeafBoundsHelper as l,BoundsHelper as d,Debug as c,LeafLevelList as u,LayoutEvent as g,Run as p,ImageManager as f,Platform as _,AnimateEvent as w,ResizeEvent as v,Creator as y,LeaferCanvasBase as m,Cursor as x,canvasSizeAttrs as b,canvasPatch as B,InteractionHelper as L,MathHelper as E,InteractionBase as R,LeaferImage as T,FileHelper as M,MatrixHelper as k,ImageEvent as S,PointHelper as C,TaskProcessor as O}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{ColorConvert as A,ImageManager as D,Paint as P,Effect as W,TextConvert as I,Export as F}from"@leafer-ui/core";export*from"@leafer-ui/core";class U{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const e=new t;return this.__updatedList.list.forEach((t=>{t.leafer&&e.push(t)})),e}return this.__updatedList}constructor(i,s){this.totalTimes=0,this.config={},this.__updatedList=new t,this.target=i,s&&(this.config=e.default(s,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(i.REQUEST)}__onAttrChange(t){this.__updatedList.push(t.target),this.update()}__onChildEvent(t){t.type===s.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.push(t.parent)),this.update()}__pushChild(t){this.__updatedList.push(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 n(n.DATA,{updatedList:this.updatedList})),this.__updatedList=new t,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(o.CHANGE,this.__onAttrChange,this),t.on_([s.ADD,s.REMOVE],this.__onChildEvent,this),t.on_(n.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllWorldMatrix:V,updateAllWorldOpacity:Y}=r,{pushAllChildBranch:z,pushAllParent:N}=a;const{worldBounds:G}=l,{setByListWithHandle:j}=d;class X{constructor(e){this.updatedBounds=new h,this.beforeBounds=new h,this.afterBounds=new h,e instanceof Array&&(e=new t(e)),this.updatedList=e}setBefore(){j(this.beforeBounds,this.updatedList.list,G)}setAfter(){j(this.afterBounds,this.updatedList.list,G),this.updatedBounds.setByList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.pushList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllWorldMatrix:H,updateAllChange:K}=r,{pushAllBranchStack:q,updateWorldBoundsByBranchStack:Q}=a,$=c.get("Layouter");class Z{constructor(t,i){this.totalTimes=0,this.config={},this.__levelList=new u,this.target=t,i&&(this.config=e.default(i,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(g.START),this.layoutOnce(),t.emitEvent(new g(g.END,this.layoutedBlocks,this.times))}catch(t){$.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?$.warn("layouting"):this.times>3?$.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(n.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=p.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:o,AFTER:r}=g,a=this.getBlocks(s);a.forEach((t=>{t.setBefore()})),i.emitEvent(new g(n,a,this.times)),s.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(V(t),e.push(t),t.isBranch&&z(t,e),N(t,e)):i.boundsChanged&&(e.push(t),t.isBranch&&(t.__tempNumber=0),N(t,e)))}))}(s,this.__levelList),function(t){let e,i;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)for(let t=0,e=i.children.length;t<e;t++)i.children[t].isBranch||i.children[t].__updateWorldBounds();i.__updateWorldBounds()}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&Y(t),t.__updateChange()}))}(s),a.forEach((t=>t.setAfter())),i.emitEvent(new g(o,a,this.times)),i.emitEvent(new g(r,a,this.times)),this.addBlocks(a),this.__levelList.reset(),this.__updatedList=null,p.end(e)}fullLayout(){const e=p.start("FullLayout"),{target:i}=this,{BEFORE:s,LAYOUT:n,AFTER:o}=g,r=this.getBlocks(new t(i));i.emitEvent(new g(s,r,this.times)),Z.fullLayout(i),r.forEach((t=>{t.setAfter()})),i.emitEvent(new g(n,r,this.times)),i.emitEvent(new g(o,r,this.times)),this.addBlocks(r),p.end(e)}static fullLayout(t){if(H(t),t.isBranch){const e=[t];q(t,e),Q(e)}else t.__updateWorldBounds();K(t)}createBlock(t){return new X(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_(g.REQUEST,this.layout,this),t.on_(g.AGAIN,this.layoutAgain,this),t.on_(n.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.config=null)}}const J=c.get("Renderer");class tt{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,i,s){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=i,s&&(this.config=e.default(s,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(g.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new h,J.log(e.innerName,"---\x3e");try{this.emitRender(i.START),this.renderOnce(t),this.emitRender(i.END,this.totalBounds),f.clearRecycled()}catch(t){this.rendering=!1,J.error(t)}J.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){return this.rendering?J.warn("rendering"):this.times>3?J.warn("render max times"):(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new h,this.renderOptions={},t?(this.emitRender(i.BEFORE),t()):(this.requestLayout(),this.emitRender(i.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()),this.emitRender(i.RENDER,this.renderBounds,this.renderOptions),this.emitRender(i.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,void(this.waitAgain&&(this.waitAgain=!1,this.renderOnce())))}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return J.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=p.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=t.includes(this.target.__world),o=(new h).copy(s);i.save(),n&&!c.showRepaint?i.clear():(s.spread(1+1/this.canvas.pixelRatio).ceil(),i.clearWorld(s,!0),i.clipWorld(s,!0)),this.__render(s,n,o),i.restore(),p.end(e)}fullRender(){const t=p.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),p.end(t)}__render(t,e,i){const s=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),c.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,s),this.renderBounds=i||t,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),c.showHitView&&this.renderHitView(s),c.showBoundsView&&this.renderBoundsView(s),this.canvas.updateRender()}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new h;e.setByList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();_.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.changed&&this.running&&this.canvas.view&&this.render(),this.running&&this.target.emit(w.FRAME),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal&&(t.bigger||!t.samePixelRatio)){const{width:e,height:i}=t.old;new h(0,0,e,i).includes(this.target.__world)&&!this.needFill&&t.samePixelRatio||(this.addBlock(this.canvas.bounds),this.target.forceUpdate("blendMode"))}}__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||J.warn(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,s){this.target.emitEvent(new i(t,this.times,e,s))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(i.REQUEST,this.update,this),t.on_(g.END,this.__onLayoutEnd,this),t.on_(i.AGAIN,this.renderAgain,this),t.on_(v.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.canvas=null,this.config=null)}}const{hitRadiusPoint:et}=d;class it{constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,i){e||(e=0),i||(i={});const s=i.through||!1,n=i.ignoreHittable||!1;this.exclude=i.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=[],this.eachFind(this.target.children,this.target.__onlyHitMask);const o=this.findList,r=this.getBestMatchLeaf(),a=n?this.getPath(r):this.getHitablePath(r);return this.clear(),s?{path:a,leaf:r,throughPath:o.length?this.getThroughPath(o):a}:{path:a,leaf:r}}getBestMatchLeaf(){const{findList:t}=this;if(t.length>1){let e;this.findList=[];const{x:i,y:s}=this.point,n={x:i,y:s,radiusX:0,radiusY:0};for(let i=0,s=t.length;i<s;i++)if(e=t[i],r.worldHittable(e)&&(this.hitChild(e,n),this.findList.length))return this.findList[0]}return t[0]}getPath(e){const i=new t;for(;e;)i.push(e),e=e.parent;return i.push(this.target),i}getHitablePath(e){const i=this.getPath(e);let s,n=new t;for(let t=i.list.length-1;t>-1&&(s=i.list[t],s.__.hittable)&&(n.unshift(s),s.__.hitChildren);t--);return n}getThroughPath(e){const i=new t,s=[];for(let t=e.length-1;t>-1;t--)s.push(this.getPath(e[t]));let n,o,r;for(let t=0,e=s.length;t<e;t++){n=s[t],o=s[t+1];for(let t=0,e=n.length;t<e&&(r=n.list[t],!o||!o.has(r));t++)i.push(r)}return i}eachFind(t,e){let i,s;const{point:n}=this;for(let o=t.length-1;o>-1;o--)i=t[o],!i.__.visible||e&&!i.__.isMask||(s=!!i.__.hitRadius||et(i.__world,n),i.isBranch?(s||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&!this.findList.length&&this.hitChild(i,n)):s&&this.hitChild(i,n))}hitChild(t,e){this.exclude&&this.exclude.has(t)||t.__hitWorld(e)&&this.findList.push(t)}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}class st{constructor(t,i){this.config={},this.innerIdList={},this.idList={},this.classNameList={},this.tagNameList={},this.target=t,i&&(this.config=e.default(i,this.config)),this.findPath=new it(t,this),this.__listenEvents()}getByPoint(t,e,i){return"node"===_.name&&this.target.emit(g.CHECK_UPDATE),this.findPath.getByPoint(t,e,i)}find(t,e){return"number"==typeof t?this.getByInnerId(t,e):t.startsWith("#")?this.getById(t.substring(1),e):t.startsWith(".")?this.getByClassName(t.substring(1),e):this.getByTagName(t,e)}getByInnerId(t,e){let i,s=this.innerIdList[t];return s||(e||(e=this.target),this.loopFind(e,(e=>e.innerId===t&&(i=e,this.innerIdList[t]=i,!0))),i)}getById(t,e){let i,s=this.idList[t];return s||(e||(e=this.target),this.loopFind(e,(e=>e.id===t&&(i=e,this.idList[t]=i,!0))),i)}getByClassName(t,e){e||(e=this.target);let i=[];return this.loopFind(e,(e=>(e.className===t&&i.push(e),!1))),i}getByTagName(t,e){e||(e=this.target);let i=[];return this.loopFind(e,(e=>(e.__tag===t&&i.push(e),!1))),i}loopFind(t,e){if(e(t))return;const{children:i}=t;for(let s=0,n=i.length;s<n;s++){if(e(t=i[s]))return;t.isBranch&&this.loopFind(t,e)}}__onRemoveChild(t){const e=t.target;this.idList[e.id]&&(this.idList[e.id]=null),this.innerIdList[e.id]&&(this.innerIdList[e.innerId]=null)}__listenEvents(){this.__eventIds=[this.target.on_(s.REMOVE,this.__onRemoveChild,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.__eventIds.length&&(this.__removeListenEvents(),this.findPath.destroy(),this.innerIdList={},this.idList={},this.classNameList={},this.tagNameList={})}}Object.assign(y,{watcher:(t,e)=>new U(t,e),layouter:(t,e)=>new Z(t,e),renderer:(t,e,i)=>new tt(t,e,i),selector:(t,e)=>new st(t,e)}),_.layout=Z.fullLayout;const nt=c.get("LeaferCanvas");class ot extends m{init(){const{view:t}=this.config;t?this.__createViewFrom(t):this.__createView();const{style:e}=this.view;e.display||(e.display="block"),this.parentView=this.view.parentElement,_.syncDomFont&&!this.parentView&&(this.view.style.display="none",document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(this.config)}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")}setCursor(t){const e=[];this.eachCursor(t,e),"object"==typeof e[e.length-1]&&e.push("default"),this.view.style.cursor=e.map((t=>"object"==typeof t?`url(${t.url}) ${t.x||0} ${t.y||0}`:t)).join(",")}eachCursor(t,e,i=0){if(i++,t instanceof Array)t.forEach((t=>this.eachCursor(t,e,i)));else{const s="string"==typeof t&&x.get(t);s&&i<2?this.eachCursor(s,e,i):e.push(t)}}__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;if(t.hasChildNodes()){const{style:e}=i;e.position="absolute",e.top=e.left="0px",t.style.position||(t.style.position="relative")}t.appendChild(i)}else nt.error(`no id: ${t}`),this.__createView()}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;s.width=t+"px",s.height=e+"px",this.view.width=t*i,this.view.height=e*i}updateClientBounds(){this.clientBounds=this.view.getBoundingClientRect()}startAutoLayout(t,e){this.autoBounds=t,this.resizeListener=e;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()))}catch(t){this.imitateResizeObserver()}}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),_.requestRender(this.imitateResizeObserver.bind(this)))}checkAutoBounds(t){const i=this.view,{x:s,y:n,width:o,height:r}=this.autoBounds.getBoundsFrom(t);if(o!==this.width||r!==this.height){const{style:t}=i,{pixelRatio:a}=this;t.marginLeft=s+"px",t.marginTop=n+"px";const h={width:o,height:r,pixelRatio:a},l={};e.copyAttrs(l,this,b),this.resize(h),void 0!==this.width&&this.resizeListener(new v(h,l))}}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}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()}}}B(CanvasRenderingContext2D.prototype),B(Path2D.prototype);const rt={convert(t,e){const i=L.getBase(t),s=Object.assign(Object.assign({},i),{x:e.x,y:e.y,width:t.width,height:t.height,pointerType:t.pointerType,pressure:t.pressure});return"pen"===s.pointerType&&(s.tangentialPressure=t.tangentialPressure,s.tiltX=t.tiltX,s.tiltY=t.tiltY,s.twist=t.twist),s},convertMouse(t,e){const i=L.getBase(t);return Object.assign(Object.assign({},i),{x:e.x,y:e.y,width:1,height:1,pointerType:"mouse",pressure:.5})},convertTouch(t,e){const i=rt.getTouch(t),s=L.getBase(t);return Object.assign(Object.assign({},s),{x:e.x,y:e.y,width:1,height:1,pointerType:"touch",pressure:i.force})},getTouch:t=>t.targetTouches[0]||t.changedTouches[0]},at={getMove(t,e){let{moveSpeed:i}=e,{deltaX:s,deltaY:n}=t;return t.shiftKey&&!s&&(s=n,n=0),s>50&&(s=Math.max(50,s/3)),n>50&&(n=Math.max(50,n/3)),{x:-s*i*2,y:-n*i*2}},getScale(t,e){let i,s=1,{zoomMode:n,zoomSpeed:o}=e;const r=t.deltaY||t.deltaX;if(n?(i=!t.deltaX&&(_.intWheelDeltaY?Math.abs(r)>17:Math.ceil(r)!==r),(t.shiftKey||t.metaKey||t.ctrlKey)&&(i=!0)):i=!t.shiftKey&&(t.metaKey||t.ctrlKey),i){o=E.within(o,0,1);s=1-r/(25*(t.deltaY?e.delta.y:e.delta.x)*(1-o)+10),s<.5&&(s=.5),s>=1.5&&(s=1.5)}return s}},ht={convert(t){const e=L.getBase(t);return Object.assign(Object.assign({},e),{code:t.code,key:t.key})}},{getMoveEventData:lt,getZoomEventData:dt,getRotateEventData:ct}=L;class ut extends R{__listenEvents(){super.__listenEvents();const t=this.view=this.canvas.view;this.viewEvents={pointerdown:this.onPointerDown,mousedown:this.onMouseDown,touchstart:this.onTouchStart,contextmenu:this.onContextMenu,wheel:this.onWheel,gesturestart:this.onGesturestart,gesturechange:this.onGesturechange,gestureend:this.onGestureend},this.windowEvents={pointermove:this.onPointerMove,pointerup:this.onPointerUp,pointercancel:this.onPointerCancel,mousemove:this.onMouseMove,mouseup:this.onMouseUp,touchmove:this.onTouchMove,touchend:this.onTouchEnd,touchcancel:this.onTouchCancel,keydown:this.onKeyDown,keyup:this.onKeyUp,scroll:this.onScroll};const{viewEvents:e,windowEvents:i}=this;for(let i in e)e[i]=e[i].bind(this),t.addEventListener(i,e[i]);for(let t in i)i[t]=i[t].bind(this),window.addEventListener(t,i[t])}__removeListenEvents(){super.__removeListenEvents();const{viewEvents:t,windowEvents:e}=this;for(let e in t)this.view.removeEventListener(e,t[e]),this.viewEvents={};for(let t in e)window.removeEventListener(t,e[t]),this.windowEvents={}}getLocal(t,e){e&&this.canvas.updateClientBounds();const{clientBounds:i}=this.canvas;return{x:t.clientX-i.x,y:t.clientY-i.y}}getTouches(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push(t[i]);return e}preventDefaultPointer(t){const{pointer:e}=this.config;e.preventDefault&&t.preventDefault()}preventDefaultWheel(t){const{wheel:e}=this.config;e.preventDefault&&t.preventDefault()}preventWindowPointer(t){return!this.downData&&t.target!==this.view}onKeyDown(t){this.keyDown(ht.convert(t))}onKeyUp(t){this.keyUp(ht.convert(t))}onContextMenu(t){this.menu(rt.convert(t,this.getLocal(t)))}onScroll(){this.canvas.updateClientBounds()}onPointerDown(t){this.preventDefaultPointer(t),this.usePointer||(this.usePointer=!0),this.useMultiTouch||this.pointerDown(rt.convert(t,this.getLocal(t)))}onPointerMove(t){this.usePointer||(this.usePointer=!0),this.useMultiTouch||this.preventWindowPointer(t)||this.pointerMove(rt.convert(t,this.getLocal(t,!0)))}onPointerUp(t){this.downData&&this.preventDefaultPointer(t),this.useMultiTouch||this.preventWindowPointer(t)||this.pointerUp(rt.convert(t,this.getLocal(t)))}onPointerCancel(){this.useMultiTouch||this.pointerCancel()}onMouseDown(t){this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.pointerDown(rt.convertMouse(t,this.getLocal(t)))}onMouseMove(t){this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerMove(rt.convertMouse(t,this.getLocal(t,!0)))}onMouseUp(t){this.downData&&this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerUp(rt.convertMouse(t,this.getLocal(t)))}onMouseCancel(){this.useTouch||this.usePointer||this.pointerCancel()}onTouchStart(t){if(t.preventDefault(),this.multiTouchStart(t),this.usePointer)return;this.touchTimer&&(window.clearTimeout(this.touchTimer),this.touchTimer=0),this.useTouch=!0;const e=rt.getTouch(t);this.pointerDown(rt.convertTouch(t,this.getLocal(e,!0)))}onTouchMove(t){if(this.multiTouchMove(t),this.usePointer||this.preventWindowPointer(t))return;const e=rt.getTouch(t);this.pointerMove(rt.convertTouch(t,this.getLocal(e)))}onTouchEnd(t){if(this.multiTouchEnd(),this.usePointer||this.preventWindowPointer(t))return;this.touchTimer&&clearTimeout(this.touchTimer),this.touchTimer=setTimeout((()=>{this.useTouch=!1}),500);const e=rt.getTouch(t);this.pointerUp(rt.convertTouch(t,this.getLocal(e)))}onTouchCancel(){this.usePointer||this.pointerCancel()}multiTouchStart(t){this.useMultiTouch=t.touches.length>=2,this.touches=this.useMultiTouch?this.getTouches(t.touches):void 0,this.useMultiTouch&&this.pointerCancel()}multiTouchMove(t){if(this.useMultiTouch&&t.touches.length>1){const e=this.getTouches(t.touches),i=this.getKeepTouchList(this.touches,e);i.length>1&&(this.multiTouch(L.getBase(t),i),this.touches=e)}}multiTouchEnd(){this.touches=null,this.useMultiTouch=!1,this.transformEnd()}getKeepTouchList(t,e){let i;const s=[];return t.forEach((t=>{i=e.find((e=>e.identifier===t.identifier)),i&&s.push({from:this.getLocal(t),to:this.getLocal(i)})})),s}getLocalTouchs(t){return t.map((t=>this.getLocal(t)))}onWheel(t){this.preventDefaultWheel(t);const{wheel:e}=this.config,i=e.getScale?e.getScale(t,e):at.getScale(t,e),s=this.getLocal(t),n=L.getBase(t);1!==i?this.zoom(dt(s,i,n)):this.move(lt(s,e.getMove?e.getMove(t,e):at.getMove(t,e),n))}onGesturestart(t){this.preventDefaultWheel(t),this.lastGestureScale=1,this.lastGestureRotation=0}onGesturechange(t){this.preventDefaultWheel(t);const e=this.getLocal(t),i=L.getBase(t),s=t.scale/this.lastGestureScale,n=t.rotation-this.lastGestureRotation;let{rotateSpeed:o}=this.config.wheel;o=E.within(o,0,1),this.zoom(dt(e,s*s,i)),this.rotate(ct(e,n/Math.PI*180*(o/4+.1),i)),this.lastGestureScale=t.scale,this.lastGestureRotation=t.rotation}onGestureend(t){this.preventDefaultWheel(t),this.transformEnd()}destroy(){this.view&&(super.destroy(),this.view=null,this.touches=null)}}const{mineType:gt,fileType:pt}=M;function ft(t,e){_.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>t.toDataURL(gt(e),i),canvasToBolb:(t,e,i)=>new Promise((s=>t.toBlob(s,gt(e),i))),canvasSaveAs:(t,e,i)=>new Promise((s=>{let n=document.createElement("a");n.href=t.toDataURL(gt(pt(e)),i),n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),s()})),loadImage:t=>new Promise(((e,i)=>{const s=new Image;s.setAttribute("crossOrigin","anonymous"),s.crossOrigin="anonymous",s.onload=()=>{e(s)},s.onerror=t=>{i(t)},!t.startsWith("data:")&&_.imageSuffix&&(t+=(t.includes("?")?"&":"?")+_.imageSuffix),s.src=t}))},_.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},_.canvas=y.canvas(),_.conicGradientSupport=!!_.canvas.context.createConicGradient}Object.assign(y,{canvas:(t,e)=>new ot(t,e),image:t=>new T(t),hitCanvas:(t,e)=>new ot(t,e),interaction:(t,e,i,s)=>new ut(t,e,i,s)}),_.name="web",_.isMobile="ontouchstart"in window,_.requestRender=function(t){window.requestAnimationFrame(t)},_.devicePixelRatio=devicePixelRatio,_.realtimeLayout=!0;const{userAgent:_t}=navigator;_t.indexOf("Firefox")>-1?(_.conicGradientRotate90=!0,_.intWheelDeltaY=!0,_.syncDomFont=!0):_t.indexOf("Safari")>-1&&-1===_t.indexOf("Chrome")&&(_.fullImageShadow=!0),_t.indexOf("Windows")>-1?(_.os="Windows",_.intWheelDeltaY=!0):_t.indexOf("Mac")>-1?_.os="Mac":_t.indexOf("Linux")>-1&&(_.os="Linux");const{get:wt,rotateOfOuter:vt,translate:yt,scaleOfOuter:mt,scale:xt,rotate:bt}=k;const{get:Bt,translate:Lt}=k;function Et(t,e,i,s){let{width:n,height:o}=e;const{opacity:r,mode:a,offset:h,scale:l,rotation:d,blendMode:c}=i,u=s.width===n&&s.height===o;c&&(t.blendMode=c);const g=t.data={mode:a};switch(a){case"strench":u||(n=s.width,o=s.height),(s.x||s.y)&&(g.transform=Bt(),Lt(g.transform,s.x,s.y));break;case"clip":(h||l||d)&&function(t,e,i,s,n){const o=wt();yt(o,e.x,e.y),i&&yt(o,i.x,i.y),s&&("number"==typeof s?xt(o,s):xt(o,s.x,s.y),t.scaleX=o.a,t.scaleY=o.d),n&&bt(o,n),t.transform=o}(g,s,h,l,d);break;case"repeat":(!u||l||d)&&function(t,e,i,s,n,o){const r=wt();if(o)switch(bt(r,o),o){case 90:yt(r,s,0);break;case 180:yt(r,i,s);break;case 270:yt(r,0,i)}yt(r,e.x,e.y),n&&(mt(r,e,n),t.scaleX=t.scaleY=n),t.transform=r}(g,s,n,o,l,d);break;default:u&&!d||function(t,e,i,s,n,o){const r=wt(),a=o&&180!==o,h=i.width/(a?n:s),l=i.height/(a?s:n),d="fit"===e?Math.min(h,l):Math.max(h,l),c=i.x+(i.width-s*d)/2,u=i.y+(i.height-n*d)/2;yt(r,c,u),xt(r,d),o&&vt(r,{x:i.x+i.width/2,y:i.y+i.height/2},o),t.scaleX=t.scaleY=d,t.transform=r}(g,a,s,n,o,d)}g.width=n,g.height=o,r&&(g.opacity=r)}function Rt(t,e,i){if("fill"===e&&!t.__.__naturalWidth){const{__:e}=t;if(e.__naturalWidth=i.width,e.__naturalHeight=i.height,!e.__getInput("width")||!e.__getInput("height"))return t.forceUpdate("width"),!1}return!0}function Tt(t,e){e.target.hasEvent(t)&&e.target.emitEvent(new S(t,e))}function Mt(t,e,i,s){return new(i||(i=Promise))((function(n,o){function r(t){try{h(s.next(t))}catch(t){o(t)}}function a(t){try{h(s.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{get:kt,scale:St,copy:Ct}=k;function Ot(t,e,i){let{scaleX:s,scaleY:n}=t.__world;const o=s+"-"+n;if(e.patternId===o||t.destroyed)return!1;{e.patternId=o,s=Math.abs(s),n=Math.abs(n);const{image:t,data:r}=e,a=t.isSVG?4096:Math.min(t.width,4096),h=t.isSVG?4096:Math.min(t.height,4096);let l,d,{width:c,height:u,scaleX:g,scaleY:p,opacity:f,transform:w,mode:v}=r;g&&(d=kt(),Ct(d,w),St(d,1/g,1/p),s*=g,n*=p),s*=i,n*=i,c*=s,u*=n,(c>a||u>h)&&(l=Math.max(c/a,u/h)),l&&(s/=l,n/=l,c/=l,u/=l),g&&(s/=g,n/=p),(w||1!==s||1!==n)&&(d||(d=kt(),w&&Ct(d,w)),St(d,1/s,1/n));const y=_.canvas.createPattern(t.getCanvas(c<1?1:c,u<1?1:u,f),"repeat"===v?"repeat":_.origin.noRepeat||"no-repeat");try{e.transform&&(e.transform=null),d&&(y.setTransform?y.setTransform(d):e.transform=d)}catch(t){e.transform=d}return e.style=y,!0}}function At(t,e,i,s){const{scaleX:n,scaleY:o}=t.__world;if(i.data&&i.patternId!==n+"-"+o){if(s)if(i.image.isSVG&&"repeat"!==i.data.mode){let{width:t,height:r}=i.data;t*=n*e.pixelRatio,r*=o*e.pixelRatio,s=t>4096||r>4096}else s=!1;if(s){e.save(),e.clip();const{data:t}=i;return i.blendMode&&(e.blendMode=i.blendMode),t.opacity&&(e.opacity*=t.opacity),t.transform&&e.transform(t.transform),e.drawImage(i.image.view,0,0,t.width,t.height),e.restore(),!0}return i.style?i.patternTask||(i.patternTask=f.patternTasker.add((()=>Mt(this,void 0,void 0,(function*(){i.patternTask=null,e.bounds.hit(t.__world)&&Ot(t,i,e.pixelRatio)&&t.forceUpdate("surface")}))),300)):Ot(t,i,e.pixelRatio),!1}return!1}function Dt(t,e){const i="fill"===t?e._fill:e._stroke;if(i instanceof Array){let s,n,o,r;for(let a=0,h=i.length;a<h;a++)s=i[a].image,r=s&&s.url,r&&(n||(n={}),n[r]=!0,f.recycle(s),s.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),s.unload(i[a].loadId,!o.some((t=>t.url===r)))));return n}return null}function Pt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,r=s.length;t<r;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 Wt(t,e,i,s){const{strokeAlign:n}=e.__,o="string"!=typeof t;switch(n){case"center":i.setStroke(o?void 0:t,e.__.strokeWidth,e.__),o?Ut(t,!0,e,i):Ft(e,i);break;case"inside":It("inside",t,o,e,i,s);break;case"outside":It("outside",t,o,e,i,s)}}function It(t,e,i,s,n,o){const{strokeWidth:r,__font:a}=s.__,h=n.getSameCanvas(!0);h.setStroke(i?void 0:e,2*r,s.__),h.font=a,i?Ut(e,!0,s,h):Ft(s,h),h.blendMode="outside"===t?"destination-out":"destination-in",Pt(s,h),h.blendMode="normal",s.__hasMirror||o.matrix?n.copyWorldByReset(h):n.copyWorldToInner(h,s.__world,s.__layout.renderBounds),h.recycle()}function Ft(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,r=s.length;t<r;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 Ut(t,e,i,s){let n;for(let o=0,r=t.length;o<r;o++)n=t[o],n.image&&At(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?Ft(i,s):s.stroke(),s.restoreBlendMode()):e?Ft(i,s):s.stroke())}const{getSpread:Vt,getOuterOf:Yt,getByMove:zt,getIntersectData:Nt}=d;const Gt={x:.5,y:0},jt={x:.5,y:1};function Xt(t,e,i){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],t.addColorStop(s.offset,A.string(s.color,i))}const{set:Ht,getAngle:Kt,getDistance:qt}=C,{get:Qt,rotateOfOuter:$t,scaleOfOuter:Zt}=k,Jt={x:.5,y:.5},te={x:.5,y:1},ee={},ie={};const{set:se,getAngle:ne,getDistance:oe}=C,{get:re,rotateOfOuter:ae,scaleOfOuter:he}=k,le={x:.5,y:.5},de={x:.5,y:1},ce={},ue={};let ge;function pe(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:r,opacity:a}=e;return{type:n,blendMode:o,style:A.string(r,a)};case"image":return function(t,e,i,s,n){const o={type:i.type},r=o.image=f.get(i),a=(n||r.loading)&&{target:t,image:r,attrName:e,attrValue:i};return r.ready?(Rt(t,e,r)&&Et(o,r,i,s),n&&(Tt(S.LOAD,a),Tt(S.LOADED,a))):r.error?n&&(t.forceUpdate("surface"),a.error=r.error,Tt(S.ERROR,a)):(n&&Tt(S.LOAD,a),o.loadId=r.load((()=>{t.destroyed||(Rt(t,e,r)&&(Et(o,r,i,s),t.forceUpdate("surface")),Tt(S.LOADED,a))}),(e=>{t.forceUpdate("surface"),a.error=e,Tt(S.ERROR,a)}))),o}(i,t,e,s,!ge||!ge[e.url]);case"linear":return function(t,e){let{from:i,to:s,type:n,blendMode:o,opacity:r}=t;i||(i=Gt),s||(s=jt);const a=_.canvas.createLinearGradient(e.x+i.x*e.width,e.y+i.y*e.height,e.x+s.x*e.width,e.y+s.y*e.height);Xt(a,t.stops,r);const h={type:n,style:a};return o&&(h.blendMode=o),h}(e,s);case"radial":return function(t,e){let{from:i,to:s,type:n,opacity:o,blendMode:r,stretch:a}=t;i||(i=Jt),s||(s=te);const{x:h,y:l,width:d,height:c}=e;let u;Ht(ee,h+i.x*d,l+i.y*c),Ht(ie,h+s.x*d,l+s.y*c),(d!==c||a)&&(u=Qt(),Zt(u,ee,d/c*(a||1),1),$t(u,ee,Kt(ee,ie)+90));const g=_.canvas.createRadialGradient(ee.x,ee.y,0,ee.x,ee.y,qt(ee,ie));Xt(g,t.stops,o);const p={type:n,style:g,transform:u};return r&&(p.blendMode=r),p}(e,s);case"angular":return function(t,e){let{from:i,to:s,type:n,opacity:o,blendMode:r,stretch:a}=t;i||(i=le),s||(s=de);const{x:h,y:l,width:d,height:c}=e;se(ce,h+i.x*d,l+i.y*c),se(ue,h+s.x*d,l+s.y*c);const u=re(),g=ne(ce,ue);_.conicGradientRotate90?(he(u,ce,d/c*(a||1),1),ae(u,ce,g+90)):(he(u,ce,1,d/c*(a||1)),ae(u,ce,g));const p=_.conicGradientSupport?_.canvas.createConicGradient(0,ce.x,ce.y):_.canvas.createRadialGradient(ce.x,ce.y,0,ce.x,ce.y,oe(ce,ue));Xt(p,t.stops,o);const f={type:n,style:p,transform:u};return r&&(f.blendMode=r),f}(e,s);default:return e.r?{type:"solid",style:A.string(e)}:void 0}}var fe=Object.freeze({__proto__:null,compute:function(t,e){const i=[],s=e.__;let n,o,r=s.__input[t];r instanceof Array||(r=[r]),ge=Dt(t,s);for(let s=0,o=r.length;s<o;s++)n=pe(t,r[s],e),n&&i.push(n);if(s["_"+t]=i.length?i:void 0,1===r.length){const t=r[0];"image"===t.type&&(o=D.isPixel(t))}"fill"===t?s.__pixelFill=o:s.__pixelStroke=o},drawTextStroke:Ft,fill:function(t,e,i){i.fillStyle=t,e.__.__font?Pt(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fillText:Pt,fills:function(t,e,i){let s;const{windingRule:n,__font:o}=e.__;for(let r=0,a=t.length;r<a;r++)s=t[r],s.image&&At(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?Pt(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?Pt(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?Pt(e,i):n?i.fill(n):i.fill())},recycleImage:Dt,shape:function(t,e,i){const s=e.getSameCanvas();let n,o,r,a;const{__world:h}=t;let{scaleX:l,scaleY:d}=h;if(l<0&&(l=-l),d<0&&(d=-d),e.bounds.includes(h,i.matrix))i.matrix?(l*=i.matrix.a,d*=i.matrix.d,n=r=Yt(h,i.matrix)):n=r=h,a=s;else{const{renderShapeSpread:s}=t.__layout,c=Nt(s?Vt(e.bounds,s*l,s*d):e.bounds,h,i.matrix);o=e.bounds.getFitMatrix(c),o.a<1&&(a=e.getSameCanvas(),t.__renderShape(a,i),l*=o.a,d*=o.d),r=Yt(h,o),n=zt(r,-o.e,-o.f),i.matrix&&o.multiply(i.matrix),i=Object.assign(Object.assign({},i),{matrix:o})}return t.__renderShape(s,i),{canvas:s,matrix:o,bounds:n,worldCanvas:a,shapeBounds:r,scaleX:l,scaleY:d}},stroke:function(t,e,i,s){const n=e.__,{strokeWidth:o,strokeAlign:r,__font:a}=n;if(o)if(a)Wt(t,e,i,s);else switch(r){case"center":i.setStroke(t,o,n),i.stroke();break;case"inside":i.save(),i.setStroke(t,2*o,n),n.windingRule?i.clip(n.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const r=i.getSameCanvas(!0);r.setStroke(t,2*o,e.__),e.__drawRenderPath(r),r.stroke(),n.windingRule?r.clip(n.windingRule):r.clip(),r.clearWorld(e.__layout.renderBounds),e.__hasMirror||s.matrix?i.copyWorldByReset(r):i.copyWorldToInner(r,e.__world,e.__layout.renderBounds),r.recycle()}},strokeText:Wt,strokes:function(t,e,i,s){const n=e.__,{strokeWidth:o,strokeAlign:r,__font:a}=n;if(o)if(a)Wt(t,e,i,s);else switch(r){case"center":i.setStroke(void 0,o,n),Ut(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*o,n),n.windingRule?i.clip(n.windingRule):i.clip(),Ut(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:r}=e.__layout,a=i.getSameCanvas(!0);e.__drawRenderPath(a),a.setStroke(void 0,2*o,e.__),Ut(t,!1,e,a),n.windingRule?a.clip(n.windingRule):a.clip(),a.clearWorld(r),e.__hasMirror||s.matrix?i.copyWorldByReset(a):i.copyWorldToInner(a,e.__world,r),a.recycle()}}});const{copy:_e,toOffsetOutBounds:we}=d,ve={},ye={};function me(t,e,i,s){const{bounds:n,shapeBounds:o}=s;if(_.fullImageShadow){if(_e(ve,t.bounds),ve.x+=e.x-o.x,ve.y+=e.y-o.y,i){const{matrix:t}=s;ve.x-=(n.x+(t?t.e:0)+n.width/2)*(i-1),ve.y-=(n.y+(t?t.f:0)+n.height/2)*(i-1),ve.width*=i,ve.height*=i}t.copyWorld(s.canvas,t.bounds,ve)}else i&&(_e(ve,e),ve.x-=e.width/2*(i-1),ve.y-=e.height/2*(i-1),ve.width*=i,ve.height*=i),t.copyWorld(s.canvas,o,i?ve:e)}const{toOffsetOutBounds:xe}=d,be={};var Be=Object.freeze({__proto__:null,blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__world.a),i.copyWorldToInner(e,t.__world,t.__layout.renderBounds),i.filter="none"},innerShadow:function(t,e,i,s){let n,o;const{__world:r,__layout:a}=t,{innerShadow:h}=t.__,{worldCanvas:l,bounds:d,shapeBounds:c,scaleX:u,scaleY:g}=i,p=e.getSameCanvas(),f=h.length-1;xe(d,be),h.forEach(((h,_)=>{p.save(),p.setWorldShadow(be.offsetX+h.x*u,be.offsetY+h.y*g,h.blur*u),o=h.spread?1-2*h.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,me(p,be,o,i),p.restore(),l?(p.copyWorld(p,d,r,"copy"),p.copyWorld(l,r,r,"source-out"),n=r):(p.copyWorld(i.canvas,c,d,"source-out"),n=d),p.fillWorld(n,h.color,"source-in"),t.__hasMirror||s.matrix?e.copyWorldByReset(p,n,r,h.blendMode):e.copyWorldToInner(p,n,a.renderBounds,h.blendMode),f&&_<f&&p.clear()})),p.recycle()},shadow:function(t,e,i,s){let n,o;const{__world:r,__layout:a}=t,{shadow:h}=t.__,{worldCanvas:l,bounds:d,shapeBounds:c,scaleX:u,scaleY:g}=i,p=e.getSameCanvas(),f=h.length-1;we(d,ye),h.forEach(((h,_)=>{p.setWorldShadow(ye.offsetX+h.x*u,ye.offsetY+h.y*g,h.blur*u,h.color),o=h.spread?1+2*h.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,me(p,ye,o,i),n=d,h.box&&(p.restore(),p.save(),l&&(p.copyWorld(p,d,r,"copy"),n=r),l?p.copyWorld(l,r,r,"destination-out"):p.copyWorld(i.canvas,c,d,"destination-out")),t.__hasMirror||s.matrix?e.copyWorldByReset(p,n,r,h.blendMode):e.copyWorldToInner(p,n,a.renderBounds,h.blendMode),f&&_<f&&p.clear()})),p.recycle()}});const Le=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Ee=Le+"_#~&*+\\=|≮≯≈≠=…",Re=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 Te(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Me=Te("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ke=Te("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Se=Te(Le),Ce=Te(Ee),Oe=Te("- —/~|┆·");var Ae;!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"}(Ae||(Ae={}));const{Letter:De,Single:Pe,Before:We,After:Ie,Symbol:Fe,Break:Ue}=Ae;function Ve(t){return Me[t]?De:Oe[t]?Ue:ke[t]?We:Se[t]?Ie:Ce[t]?Fe:Re.test(t)?Pe:De}const Ye={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 ze(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:Ne}=Ye,{Letter:Ge,Single:je,Before:Xe,After:He,Symbol:Ke,Break:qe}=Ae;let Qe,$e,Ze,Je,ti,ei,ii,si,ni,oi,ri,ai,hi,li,di,ci,ui=[];function gi(t,e){ni&&!si&&(si=ni),Qe.data.push({char:t,width:e}),Ze+=e}function pi(){Je+=Ze,Qe.width=Ze,$e.words.push(Qe),Qe={data:[]},Ze=0}function fi(){li&&(di.paraNumber++,$e.paraStart=!0,li=!1),ni&&($e.startCharSize=si,$e.endCharSize=ni,si=0),$e.width=Je,ci.width&&Ne($e),ui.push($e),$e={words:[]},Je=0}const _i={getDrawData(t,e){"string"!=typeof t&&(t=String(t));let i=0,s=0,n=e.__getInput("width")||0,o=e.__getInput("height")||0;const{textDecoration:r,textOverflow:a,__font:h,padding:l}=e;if(l){const[t,e,r,a]=E.fourNumber(l);n&&(i=a,n-=e+a),o&&(s=t,o-=t+r)}const d={bounds:{x:i,y:s,width:n,height:o},rows:[],paraNumber:0,font:_.canvas.font=h};return function(t,e,i){di=t,ui=t.rows,ci=t.bounds;const{__letterSpacing:s,paraIndent:n,textCase:o}=i,{canvas:r}=_,{width:a,height:h}=ci;if(a||h||s||"none"!==o){li=!0,ri=null,si=ii=ni=Ze=Je=0,Qe={data:[]},$e={words:[]};for(let t=0,i=e.length;t<i;t++)ei=e[t],"\n"===ei?(Ze&&pi(),$e.paraEnd=!0,fi(),li=!0):(oi=Ve(ei),oi===Ge&&"none"!==o&&(ei=ze(ei,o,!Ze)),ii=r.measureText(ei).width,s&&(s<0&&(ni=ii),ii+=s),ai=oi===je&&(ri===je||ri===Ge)||ri===je&&oi!==He,hi=!(oi!==Xe&&oi!==je||ri!==Ke&&ri!==He),ti=li&&n?a-n:a,a&&Je+Ze+ii>ti&&(hi||(hi=oi===Ge&&ri==He),ai||hi||oi===qe||oi===Xe||oi===je||Ze+ii>ti?(Ze&&pi(),fi()):fi())," "===ei&&!0!==li&&Je+Ze===0||(oi===qe?(" "===ei&&Ze&&pi(),gi(ei,ii),pi()):ai||hi?(Ze&&pi(),gi(ei,ii)):gi(ei,ii)),ri=oi);Ze&&pi(),Je&&fi(),ui.length>0&&(ui[ui.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{di.paraNumber++,ui.push({x:n||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(d,t,e),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:r,textAlign:a,verticalAlign:h,paraSpacing:l,textOverflow:d}=e;let c,u,g,{x:p,y:f,width:_,height:w}=s,v=n*i.length+(l?l*(t.paraNumber-1):0),y=o;if("show"!==d&&v>w)v=Math.max(w,n),t.overflow=i.length;else switch(h){case"middle":f+=(w-v)/2;break;case"bottom":f+=w-v}y+=f;for(let o=0,h=i.length;o<h;o++){switch(c=i[o],c.x=p,a){case"center":c.x+=(_-c.width)/2;break;case"right":c.x+=_-c.width}c.paraStart&&l&&o>0&&(y+=l),c.y=y,y+=n,t.overflow>o&&y>v&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,g=c.width,r<0&&(c.width<0?(g=-c.width+e.fontSize+r,u-=g,g+=e.fontSize):g-=r),u<s.x&&(s.x=u),g>s.width&&(s.width=g)}s.y=f,s.height=v}(d,e),function(t,e,i,s){const{rows:n}=t,{textAlign:o,paraIndent:r,letterSpacing:a}=e;let h,l,d,c,u;n.forEach((t=>{t.words&&(d=r&&t.paraStart?r:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-d)/(t.words.length-1):0,c=a||t.isOverflow?0:l>.01?1:2,2===c?(t.text="",t.x+=d,t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))):(t.x+=d,h=t.x,t.data=[],t.words.forEach((e=>{1===c?(u={char:"",x:h},h=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,h,u)," "!==u.char&&t.data.push(u)):h=function(t,e,i){return t.forEach((t=>{" "!==t.char&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,h,t.data),!t.paraEnd&&l&&(h+=l,t.width+=l)}))),t.words=null)}))}(d,e,n),d.overflow&&function(t,e){const{rows:i,overflow:s}=t;if(i.splice(s),"hide"!==e){"ellipsis"===e&&(e="...");const n=_.canvas.measureText(e).width,o=i[s-1];let r,a,h=o.data.length-1;const{x:l,width:d}=t.bounds,c=l+d-n;for(let t=h;t>-1&&(r=o.data[t],a=r.x+r.width,!(t===h&&a<c));t--){if(a<c&&" "!==r.char){o.data.splice(t+1),o.width-=r.width;break}o.width-=r.width}o.width+=n,o.data.push({char:e,x:a})}}(d,a),"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}}(d,e),d}},wi={string(t,e){if("string"==typeof t)return t;let i=void 0===t.a?1:t.a;e&&(i*=e);const s=t.r+","+t.g+","+t.b;return 1===i?"rgb("+s+")":"rgba("+s+","+i+")"}},vi={export(t,e,i){return function(t){yi||(yi=new O);return new Promise((e=>{yi.add((()=>Mt(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((s=>new Promise((n=>{const{leafer:o}=t;o?o.waitViewCompleted((()=>Mt(this,void 0,void 0,(function*(){let t,r,a,{canvas:h}=o,{unreal:l}=h;switch(l&&(h=h.getSameCanvas(),h.backgroundColor=o.config.fill,o.__render(h,{})),typeof i){case"object":i.quality&&(t=i.quality),i.blob&&(r=!0);break;case"number":t=i;break;case"boolean":r=i}a=e.includes(".")?yield h.saveAs(e,t):r?yield h.toBlob(e,t):yield h.toDataURL(e,t),s({data:a}),n(),l&&h.recycle()})))):(s({data:!1}),n())}))))}};let yi;Object.assign(P,fe),Object.assign(W,Be),Object.assign(I,_i),Object.assign(A,wi),Object.assign(F,vi),ft();export{ut as Interaction,Z as Layouter,ot as LeaferCanvas,tt as Renderer,st as Selector,U as Watcher,ft as useCanvas};
1
+ import{LeafList as t,DataHelper as e,RenderEvent as i,ChildEvent as s,WatchEvent as n,PropertyEvent as o,LeafHelper as r,BranchHelper as a,Bounds as h,LeafBoundsHelper as l,BoundsHelper as d,Debug as c,LeafLevelList as u,LayoutEvent as p,Run as g,ImageManager as f,Platform as _,AnimateEvent as w,ResizeEvent as v,Creator as y,LeaferCanvasBase as m,Cursor as x,canvasSizeAttrs as b,canvasPatch as B,InteractionHelper as E,MathHelper as L,InteractionBase as M,LeaferImage as R,FileHelper as T,MatrixHelper as k,ImageEvent as C,PointHelper as S,TaskProcessor as O}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{ColorConvert as A,ImageManager as D,Paint as P,Effect as W,TextConvert as I,Export as F}from"@leafer-ui/core";export*from"@leafer-ui/core";class U{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const e=new t;return this.__updatedList.list.forEach((t=>{t.leafer&&e.push(t)})),e}return this.__updatedList}constructor(i,s){this.totalTimes=0,this.config={},this.__updatedList=new t,this.target=i,s&&(this.config=e.default(s,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(i.REQUEST)}__onAttrChange(t){this.__updatedList.push(t.target),this.update()}__onChildEvent(t){t.type===s.ADD?(this.hasAdd=!0,this.__pushChild(t.child)):(this.hasRemove=!0,this.__updatedList.push(t.parent)),this.update()}__pushChild(t){this.__updatedList.push(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 n(n.DATA,{updatedList:this.updatedList})),this.__updatedList=new t,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(o.CHANGE,this.__onAttrChange,this),t.on_([s.ADD,s.REMOVE],this.__onChildEvent,this),t.on_(n.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllWorldMatrix:V,updateAllWorldOpacity:Y}=r,{pushAllChildBranch:z,pushAllParent:G}=a;const{worldBounds:j}=l,{setByListWithHandle:N}=d;class H{constructor(e){this.updatedBounds=new h,this.beforeBounds=new h,this.afterBounds=new h,e instanceof Array&&(e=new t(e)),this.updatedList=e}setBefore(){N(this.beforeBounds,this.updatedList.list,j)}setAfter(){N(this.afterBounds,this.updatedList.list,j),this.updatedBounds.setByList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.pushList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllWorldMatrix:X,updateAllChange:K}=r,{pushAllBranchStack:q,updateWorldBoundsByBranchStack:Q}=a,$=c.get("Layouter");class Z{constructor(t,i){this.totalTimes=0,this.config={},this.__levelList=new u,this.target=t,i&&(this.config=e.default(i,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(p.START),this.layoutOnce(),t.emitEvent(new p(p.END,this.layoutedBlocks,this.times))}catch(t){$.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?$.warn("layouting"):this.times>3?$.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(n.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=g.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:o,AFTER:r}=p,a=this.getBlocks(s);a.forEach((t=>{t.setBefore()})),i.emitEvent(new p(n,a,this.times)),s.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(V(t),e.push(t),t.isBranch&&z(t,e),G(t,e)):i.boundsChanged&&(e.push(t),t.isBranch&&(t.__tempNumber=0),G(t,e)))}))}(s,this.__levelList),function(t){let e,i;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)for(let t=0,e=i.children.length;t<e;t++)i.children[t].isBranch||i.children[t].__updateWorldBounds();i.__updateWorldBounds()}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&Y(t),t.__updateChange()}))}(s),a.forEach((t=>t.setAfter())),i.emitEvent(new p(o,a,this.times)),i.emitEvent(new p(r,a,this.times)),this.addBlocks(a),this.__levelList.reset(),this.__updatedList=null,g.end(e)}fullLayout(){const e=g.start("FullLayout"),{target:i}=this,{BEFORE:s,LAYOUT:n,AFTER:o}=p,r=this.getBlocks(new t(i));i.emitEvent(new p(s,r,this.times)),Z.fullLayout(i),r.forEach((t=>{t.setAfter()})),i.emitEvent(new p(n,r,this.times)),i.emitEvent(new p(o,r,this.times)),this.addBlocks(r),g.end(e)}static fullLayout(t){if(X(t),t.isBranch){const e=[t];q(t,e),Q(e)}else t.__updateWorldBounds();K(t)}createBlock(t){return new H(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_(p.REQUEST,this.layout,this),t.on_(p.AGAIN,this.layoutAgain,this),t.on_(n.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.config=null)}}const J=c.get("Renderer");class tt{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,i,s){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=i,s&&(this.config=e.default(s,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(p.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new h,J.log(e.innerName,"---\x3e");try{this.emitRender(i.START),this.renderOnce(t),this.emitRender(i.END,this.totalBounds),f.clearRecycled()}catch(t){this.rendering=!1,J.error(t)}J.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){return this.rendering?J.warn("rendering"):this.times>3?J.warn("render max times"):(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new h,this.renderOptions={},t?(this.emitRender(i.BEFORE),t()):(this.requestLayout(),this.emitRender(i.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()),this.emitRender(i.RENDER,this.renderBounds,this.renderOptions),this.emitRender(i.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,void(this.waitAgain&&(this.waitAgain=!1,this.renderOnce())))}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return J.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=g.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=t.includes(this.target.__world),o=(new h).copy(s);i.save(),n&&!c.showRepaint?i.clear():(s.spread(1+1/this.canvas.pixelRatio).ceil(),i.clearWorld(s,!0),i.clipWorld(s,!0)),this.__render(s,n,o),i.restore(),g.end(e)}fullRender(){const t=g.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),g.end(t)}__render(t,e,i){const s=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),c.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,s),this.renderBounds=i||t,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),c.showHitView&&this.renderHitView(s),c.showBoundsView&&this.renderBoundsView(s),this.canvas.updateRender()}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new h;e.setByList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();_.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.changed&&this.running&&this.canvas.view&&this.render(),this.running&&this.target.emit(w.FRAME),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal&&(t.bigger||!t.samePixelRatio)){const{width:e,height:i}=t.old;new h(0,0,e,i).includes(this.target.__world)&&!this.needFill&&t.samePixelRatio||(this.addBlock(this.canvas.bounds),this.target.forceUpdate("blendMode"))}}__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||J.warn(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,s){this.target.emitEvent(new i(t,this.times,e,s))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(i.REQUEST,this.update,this),t.on_(p.END,this.__onLayoutEnd,this),t.on_(i.AGAIN,this.renderAgain,this),t.on_(v.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.canvas=null,this.config=null)}}const{hitRadiusPoint:et}=d;class it{constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,i){e||(e=0),i||(i={});const s=i.through||!1,n=i.ignoreHittable||!1;this.exclude=i.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=[],this.eachFind(this.target.children,this.target.__onlyHitMask);const o=this.findList,r=this.getBestMatchLeaf(),a=n?this.getPath(r):this.getHitablePath(r);return this.clear(),s?{path:a,leaf:r,throughPath:o.length?this.getThroughPath(o):a}:{path:a,leaf:r}}getBestMatchLeaf(){const{findList:t}=this;if(t.length>1){let e;this.findList=[];const{x:i,y:s}=this.point,n={x:i,y:s,radiusX:0,radiusY:0};for(let i=0,s=t.length;i<s;i++)if(e=t[i],r.worldHittable(e)&&(this.hitChild(e,n),this.findList.length))return this.findList[0]}return t[0]}getPath(e){const i=new t;for(;e;)i.push(e),e=e.parent;return i.push(this.target),i}getHitablePath(e){const i=this.getPath(e);let s,n=new t;for(let t=i.list.length-1;t>-1&&(s=i.list[t],s.__.hittable)&&(n.unshift(s),s.__.hitChildren);t--);return n}getThroughPath(e){const i=new t,s=[];for(let t=e.length-1;t>-1;t--)s.push(this.getPath(e[t]));let n,o,r;for(let t=0,e=s.length;t<e;t++){n=s[t],o=s[t+1];for(let t=0,e=n.length;t<e&&(r=n.list[t],!o||!o.has(r));t++)i.push(r)}return i}eachFind(t,e){let i,s;const{point:n}=this;for(let o=t.length-1;o>-1;o--)i=t[o],!i.__.visible||e&&!i.__.isMask||(s=!!i.__.hitRadius||et(i.__world,n),i.isBranch?(s||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&!this.findList.length&&this.hitChild(i,n)):s&&this.hitChild(i,n))}hitChild(t,e){this.exclude&&this.exclude.has(t)||t.__hitWorld(e)&&this.findList.push(t)}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}class st{constructor(t,i){this.config={},this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?this.idMap[e]=t:0,innerId:(t,e)=>t.innerId===e?this.innerIdMap[e]=t:0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0},this.target=t,i&&(this.config=e.default(i,this.config)),this.pather=new it(t,this),this.__listenEvents()}getByPoint(t,e,i){return"node"===_.name&&this.target.emit(p.CHECK_UPDATE),this.pather.getByPoint(t,e,i)}getBy(t,e,i,s){switch(typeof t){case"number":const n=this.getByInnerId(t,e);return i?n:n?[n]:[];case"string":switch(t[0]){case"#":const s=this.getById(t.substring(1),e);return i?s:s?[s]:[];case".":return this.getByMethod(this.methods.className,e,i,t.substring(1));default:return this.getByMethod(this.methods.tag,e,i,t)}case"function":return this.getByMethod(t,e,i,s)}}getByInnerId(t,e){const i=this.innerIdMap[t];return i||(this.eachFind(this.toChildren(e),this.methods.innerId,null,t),this.findLeaf)}getById(t,e){const i=this.idMap[t];return i&&r.hasParent(i,e||this.target)?i:(this.eachFind(this.toChildren(e),this.methods.id,null,t),this.findLeaf)}getByClassName(t,e){return this.getByMethod(this.methods.className,e,!1,t)}getByTag(t,e){return this.getByMethod(this.methods.tag,e,!1,t)}getByMethod(t,e,i,s){const n=i?null:[];return this.eachFind(this.toChildren(e),t,n,s),n||this.findLeaf}eachFind(t,e,i,s){let n;for(let o=0,r=t.length;o<r;o++){if(n=t[o],e(n,s)){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&this.eachFind(n.children,e,i,s)}}toChildren(t){return this.findLeaf=null,[t||this.target]}__onRemoveChild(t){const{id:e,innerId:i}=t.child;this.idMap[e]&&delete this.idMap[e],this.innerIdMap[i]&&delete this.innerIdMap[i]}__checkIdChange(t){if("id"===t.attrName){const e=t.oldValue;this.idMap[e]&&delete this.idMap[e]}}__listenEvents(){this.__eventIds=[this.target.on_(s.REMOVE,this.__onRemoveChild,this),this.target.on_(o.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.__eventIds.length&&(this.__removeListenEvents(),this.pather.destroy(),this.findLeaf=null,this.innerIdMap={},this.idMap={})}}Object.assign(y,{watcher:(t,e)=>new U(t,e),layouter:(t,e)=>new Z(t,e),renderer:(t,e,i)=>new tt(t,e,i),selector:(t,e)=>new st(t,e)}),_.layout=Z.fullLayout;const nt=c.get("LeaferCanvas");class ot extends m{init(){const{view:t}=this.config;t?this.__createViewFrom(t):this.__createView();const{style:e}=this.view;e.display||(e.display="block"),this.parentView=this.view.parentElement,_.syncDomFont&&!this.parentView&&(this.view.style.display="none",document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(this.config)}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")}setCursor(t){const e=[];this.eachCursor(t,e),"object"==typeof e[e.length-1]&&e.push("default"),this.view.style.cursor=e.map((t=>"object"==typeof t?`url(${t.url}) ${t.x||0} ${t.y||0}`:t)).join(",")}eachCursor(t,e,i=0){if(i++,t instanceof Array)t.forEach((t=>this.eachCursor(t,e,i)));else{const s="string"==typeof t&&x.get(t);s&&i<2?this.eachCursor(s,e,i):e.push(t)}}__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;if(t.hasChildNodes()){const{style:e}=i;e.position="absolute",e.top=e.left="0px",t.style.position||(t.style.position="relative")}t.appendChild(i)}else nt.error(`no id: ${t}`),this.__createView()}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;s.width=t+"px",s.height=e+"px",this.view.width=t*i,this.view.height=e*i}updateClientBounds(){this.clientBounds=this.view.getBoundingClientRect()}startAutoLayout(t,e){this.autoBounds=t,this.resizeListener=e;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()))}catch(t){this.imitateResizeObserver()}}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),_.requestRender(this.imitateResizeObserver.bind(this)))}checkAutoBounds(t){const i=this.view,{x:s,y:n,width:o,height:r}=this.autoBounds.getBoundsFrom(t);if(o!==this.width||r!==this.height){const{style:t}=i,{pixelRatio:a}=this;t.marginLeft=s+"px",t.marginTop=n+"px";const h={width:o,height:r,pixelRatio:a},l={};e.copyAttrs(l,this,b),this.resize(h),void 0!==this.width&&this.resizeListener(new v(h,l))}}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}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()}}}B(CanvasRenderingContext2D.prototype),B(Path2D.prototype);const rt={convert(t,e){const i=E.getBase(t),s=Object.assign(Object.assign({},i),{x:e.x,y:e.y,width:t.width,height:t.height,pointerType:t.pointerType,pressure:t.pressure});return"pen"===s.pointerType&&(s.tangentialPressure=t.tangentialPressure,s.tiltX=t.tiltX,s.tiltY=t.tiltY,s.twist=t.twist),s},convertMouse(t,e){const i=E.getBase(t);return Object.assign(Object.assign({},i),{x:e.x,y:e.y,width:1,height:1,pointerType:"mouse",pressure:.5})},convertTouch(t,e){const i=rt.getTouch(t),s=E.getBase(t);return Object.assign(Object.assign({},s),{x:e.x,y:e.y,width:1,height:1,pointerType:"touch",pressure:i.force})},getTouch:t=>t.targetTouches[0]||t.changedTouches[0]},at={getMove(t,e){let{moveSpeed:i}=e,{deltaX:s,deltaY:n}=t;return t.shiftKey&&!s&&(s=n,n=0),s>50&&(s=Math.max(50,s/3)),n>50&&(n=Math.max(50,n/3)),{x:-s*i*2,y:-n*i*2}},getScale(t,e){let i,s=1,{zoomMode:n,zoomSpeed:o}=e;const r=t.deltaY||t.deltaX;if(n?(i="mouse"===n||!t.deltaX&&(_.intWheelDeltaY?Math.abs(r)>17:Math.ceil(r)!==r),(t.shiftKey||t.metaKey||t.ctrlKey)&&(i=!0)):i=!t.shiftKey&&(t.metaKey||t.ctrlKey),i){o=L.within(o,0,1);s=1-r/(25*(t.deltaY?e.delta.y:e.delta.x)*(1-o)+10),s<.5&&(s=.5),s>=1.5&&(s=1.5)}return s}},ht={convert(t){const e=E.getBase(t);return Object.assign(Object.assign({},e),{code:t.code,key:t.key})}},{getMoveEventData:lt,getZoomEventData:dt,getRotateEventData:ct}=E;class ut extends M{__listenEvents(){super.__listenEvents();const t=this.view=this.canvas.view;this.viewEvents={pointerdown:this.onPointerDown,mousedown:this.onMouseDown,touchstart:this.onTouchStart,contextmenu:this.onContextMenu,wheel:this.onWheel,gesturestart:this.onGesturestart,gesturechange:this.onGesturechange,gestureend:this.onGestureend},this.windowEvents={pointermove:this.onPointerMove,pointerup:this.onPointerUp,pointercancel:this.onPointerCancel,mousemove:this.onMouseMove,mouseup:this.onMouseUp,touchmove:this.onTouchMove,touchend:this.onTouchEnd,touchcancel:this.onTouchCancel,keydown:this.onKeyDown,keyup:this.onKeyUp,scroll:this.onScroll};const{viewEvents:e,windowEvents:i}=this;for(let i in e)e[i]=e[i].bind(this),t.addEventListener(i,e[i]);for(let t in i)i[t]=i[t].bind(this),window.addEventListener(t,i[t])}__removeListenEvents(){super.__removeListenEvents();const{viewEvents:t,windowEvents:e}=this;for(let e in t)this.view.removeEventListener(e,t[e]),this.viewEvents={};for(let t in e)window.removeEventListener(t,e[t]),this.windowEvents={}}getLocal(t,e){e&&this.canvas.updateClientBounds();const{clientBounds:i}=this.canvas;return{x:t.clientX-i.x,y:t.clientY-i.y}}getTouches(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push(t[i]);return e}preventDefaultPointer(t){const{pointer:e}=this.config;e.preventDefault&&t.preventDefault()}preventDefaultWheel(t){const{wheel:e}=this.config;e.preventDefault&&t.preventDefault()}preventWindowPointer(t){return!this.downData&&t.target!==this.view}onKeyDown(t){this.keyDown(ht.convert(t))}onKeyUp(t){this.keyUp(ht.convert(t))}onContextMenu(t){this.menu(rt.convert(t,this.getLocal(t)))}onScroll(){this.canvas.updateClientBounds()}onPointerDown(t){this.preventDefaultPointer(t),this.usePointer||(this.usePointer=!0),this.useMultiTouch||this.pointerDown(rt.convert(t,this.getLocal(t)))}onPointerMove(t){this.usePointer||(this.usePointer=!0),this.useMultiTouch||this.preventWindowPointer(t)||this.pointerMove(rt.convert(t,this.getLocal(t,!0)))}onPointerUp(t){this.downData&&this.preventDefaultPointer(t),this.useMultiTouch||this.preventWindowPointer(t)||this.pointerUp(rt.convert(t,this.getLocal(t)))}onPointerCancel(){this.useMultiTouch||this.pointerCancel()}onMouseDown(t){this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.pointerDown(rt.convertMouse(t,this.getLocal(t)))}onMouseMove(t){this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerMove(rt.convertMouse(t,this.getLocal(t,!0)))}onMouseUp(t){this.downData&&this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerUp(rt.convertMouse(t,this.getLocal(t)))}onMouseCancel(){this.useTouch||this.usePointer||this.pointerCancel()}onTouchStart(t){if(t.preventDefault(),this.multiTouchStart(t),this.usePointer)return;this.touchTimer&&(window.clearTimeout(this.touchTimer),this.touchTimer=0),this.useTouch=!0;const e=rt.getTouch(t);this.pointerDown(rt.convertTouch(t,this.getLocal(e,!0)))}onTouchMove(t){if(this.multiTouchMove(t),this.usePointer||this.preventWindowPointer(t))return;const e=rt.getTouch(t);this.pointerMove(rt.convertTouch(t,this.getLocal(e)))}onTouchEnd(t){if(this.multiTouchEnd(),this.usePointer||this.preventWindowPointer(t))return;this.touchTimer&&clearTimeout(this.touchTimer),this.touchTimer=setTimeout((()=>{this.useTouch=!1}),500);const e=rt.getTouch(t);this.pointerUp(rt.convertTouch(t,this.getLocal(e)))}onTouchCancel(){this.usePointer||this.pointerCancel()}multiTouchStart(t){this.useMultiTouch=t.touches.length>=2,this.touches=this.useMultiTouch?this.getTouches(t.touches):void 0,this.useMultiTouch&&this.pointerCancel()}multiTouchMove(t){if(this.useMultiTouch&&t.touches.length>1){const e=this.getTouches(t.touches),i=this.getKeepTouchList(this.touches,e);i.length>1&&(this.multiTouch(E.getBase(t),i),this.touches=e)}}multiTouchEnd(){this.touches=null,this.useMultiTouch=!1,this.transformEnd()}getKeepTouchList(t,e){let i;const s=[];return t.forEach((t=>{i=e.find((e=>e.identifier===t.identifier)),i&&s.push({from:this.getLocal(t),to:this.getLocal(i)})})),s}getLocalTouchs(t){return t.map((t=>this.getLocal(t)))}onWheel(t){this.preventDefaultWheel(t);const{wheel:e}=this.config,i=e.getScale?e.getScale(t,e):at.getScale(t,e),s=this.getLocal(t),n=E.getBase(t);1!==i?this.zoom(dt(s,i,n)):this.move(lt(s,e.getMove?e.getMove(t,e):at.getMove(t,e),n))}onGesturestart(t){this.preventDefaultWheel(t),this.lastGestureScale=1,this.lastGestureRotation=0}onGesturechange(t){this.preventDefaultWheel(t);const e=this.getLocal(t),i=E.getBase(t),s=t.scale/this.lastGestureScale,n=t.rotation-this.lastGestureRotation;let{rotateSpeed:o}=this.config.wheel;o=L.within(o,0,1),this.zoom(dt(e,s*s,i)),this.rotate(ct(e,n/Math.PI*180*(o/4+.1),i)),this.lastGestureScale=t.scale,this.lastGestureRotation=t.rotation}onGestureend(t){this.preventDefaultWheel(t),this.transformEnd()}destroy(){this.view&&(super.destroy(),this.view=null,this.touches=null)}}const{mineType:pt,fileType:gt}=T;function ft(t,e){_.origin={createCanvas(t,e){const i=document.createElement("canvas");return i.width=t,i.height=e,i},canvasToDataURL:(t,e,i)=>t.toDataURL(pt(e),i),canvasToBolb:(t,e,i)=>new Promise((s=>t.toBlob(s,pt(e),i))),canvasSaveAs:(t,e,i)=>new Promise((s=>{let n=document.createElement("a");n.href=t.toDataURL(pt(gt(e)),i),n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),s()})),loadImage:t=>new Promise(((e,i)=>{const s=new Image;s.setAttribute("crossOrigin","anonymous"),s.crossOrigin="anonymous",s.onload=()=>{e(s)},s.onerror=t=>{i(t)},!t.startsWith("data:")&&_.imageSuffix&&(t+=(t.includes("?")?"&":"?")+_.imageSuffix),s.src=t}))},_.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},_.canvas=y.canvas(),_.conicGradientSupport=!!_.canvas.context.createConicGradient}Object.assign(y,{canvas:(t,e)=>new ot(t,e),image:t=>new R(t),hitCanvas:(t,e)=>new ot(t,e),interaction:(t,e,i,s)=>new ut(t,e,i,s)}),_.name="web",_.isMobile="ontouchstart"in window,_.requestRender=function(t){window.requestAnimationFrame(t)},_.devicePixelRatio=devicePixelRatio,_.realtimeLayout=!0;const{userAgent:_t}=navigator;_t.indexOf("Firefox")>-1?(_.conicGradientRotate90=!0,_.intWheelDeltaY=!0,_.syncDomFont=!0):_t.indexOf("Safari")>-1&&-1===_t.indexOf("Chrome")&&(_.fullImageShadow=!0),_t.indexOf("Windows")>-1?(_.os="Windows",_.intWheelDeltaY=!0):_t.indexOf("Mac")>-1?_.os="Mac":_t.indexOf("Linux")>-1&&(_.os="Linux");const{get:wt,rotateOfOuter:vt,translate:yt,scaleOfOuter:mt,scale:xt,rotate:bt}=k;const{get:Bt,translate:Et}=k;function Lt(t,e,i,s){let{width:n,height:o}=e;const{opacity:r,mode:a,offset:h,scale:l,rotation:d,blendMode:c}=i,u=s.width===n&&s.height===o;c&&(t.blendMode=c);const p=t.data={mode:a};switch(a){case"strench":u||(n=s.width,o=s.height),(s.x||s.y)&&(p.transform=Bt(),Et(p.transform,s.x,s.y));break;case"clip":(h||l||d)&&function(t,e,i,s,n){const o=wt();yt(o,e.x,e.y),i&&yt(o,i.x,i.y),s&&("number"==typeof s?xt(o,s):xt(o,s.x,s.y),t.scaleX=o.a,t.scaleY=o.d),n&&bt(o,n),t.transform=o}(p,s,h,l,d);break;case"repeat":(!u||l||d)&&function(t,e,i,s,n,o){const r=wt();if(o)switch(bt(r,o),o){case 90:yt(r,s,0);break;case 180:yt(r,i,s);break;case 270:yt(r,0,i)}yt(r,e.x,e.y),n&&(mt(r,e,n),t.scaleX=t.scaleY=n),t.transform=r}(p,s,n,o,l,d);break;default:u&&!d||function(t,e,i,s,n,o){const r=wt(),a=o&&180!==o,h=i.width/(a?n:s),l=i.height/(a?s:n),d="fit"===e?Math.min(h,l):Math.max(h,l),c=i.x+(i.width-s*d)/2,u=i.y+(i.height-n*d)/2;yt(r,c,u),xt(r,d),o&&vt(r,{x:i.x+i.width/2,y:i.y+i.height/2},o),t.scaleX=t.scaleY=d,t.transform=r}(p,a,s,n,o,d)}p.width=n,p.height=o,r&&(p.opacity=r)}function Mt(t,e,i){if("fill"===e&&!t.__.__naturalWidth){const{__:e}=t;if(e.__naturalWidth=i.width,e.__naturalHeight=i.height,!e.__getInput("width")||!e.__getInput("height"))return t.forceUpdate("width"),!1}return!0}function Rt(t,e){e.target.hasEvent(t)&&e.target.emitEvent(new C(t,e))}function Tt(t,e,i,s){return new(i||(i=Promise))((function(n,o){function r(t){try{h(s.next(t))}catch(t){o(t)}}function a(t){try{h(s.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,a)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{get:kt,scale:Ct,copy:St}=k;function Ot(t,e,i){let{scaleX:s,scaleY:n}=t.__world;const o=s+"-"+n;if(e.patternId===o||t.destroyed)return!1;{e.patternId=o,s=Math.abs(s),n=Math.abs(n);const{image:t,data:r}=e,a=t.isSVG?4096:Math.min(t.width,4096),h=t.isSVG?4096:Math.min(t.height,4096);let l,d,{width:c,height:u,scaleX:p,scaleY:g,opacity:f,transform:w,mode:v}=r;p&&(d=kt(),St(d,w),Ct(d,1/p,1/g),s*=p,n*=g),s*=i,n*=i,c*=s,u*=n,(c>a||u>h)&&(l=Math.max(c/a,u/h)),l&&(s/=l,n/=l,c/=l,u/=l),p&&(s/=p,n/=g),(w||1!==s||1!==n)&&(d||(d=kt(),w&&St(d,w)),Ct(d,1/s,1/n));const y=_.canvas.createPattern(t.getCanvas(c<1?1:c,u<1?1:u,f),"repeat"===v?"repeat":_.origin.noRepeat||"no-repeat");try{e.transform&&(e.transform=null),d&&(y.setTransform?y.setTransform(d):e.transform=d)}catch(t){e.transform=d}return e.style=y,!0}}function At(t,e,i,s){const{scaleX:n,scaleY:o}=t.__world;if(i.data&&i.patternId!==n+"-"+o){if(s)if(i.image.isSVG&&"repeat"!==i.data.mode){let{width:t,height:r}=i.data;t*=n*e.pixelRatio,r*=o*e.pixelRatio,s=t>4096||r>4096}else s=!1;if(s){e.save(),e.clip();const{data:t}=i;return i.blendMode&&(e.blendMode=i.blendMode),t.opacity&&(e.opacity*=t.opacity),t.transform&&e.transform(t.transform),e.drawImage(i.image.view,0,0,t.width,t.height),e.restore(),!0}return i.style?i.patternTask||(i.patternTask=f.patternTasker.add((()=>Tt(this,void 0,void 0,(function*(){i.patternTask=null,e.bounds.hit(t.__world)&&Ot(t,i,e.pixelRatio),t.forceUpdate("surface")}))),300)):Ot(t,i,e.pixelRatio),!1}return!1}function Dt(t,e){const i="fill"===t?e._fill:e._stroke;if(i instanceof Array){let s,n,o,r;for(let a=0,h=i.length;a<h;a++)s=i[a].image,r=s&&s.url,r&&(n||(n={}),n[r]=!0,f.recycle(s),s.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),s.unload(i[a].loadId,!o.some((t=>t.url===r)))));return n}return null}function Pt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,r=s.length;t<r;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 Wt(t,e,i,s){const{strokeAlign:n}=e.__,o="string"!=typeof t;switch(n){case"center":i.setStroke(o?void 0:t,e.__.strokeWidth,e.__),o?Ut(t,!0,e,i):Ft(e,i);break;case"inside":It("inside",t,o,e,i,s);break;case"outside":It("outside",t,o,e,i,s)}}function It(t,e,i,s,n,o){const{strokeWidth:r,__font:a}=s.__,h=n.getSameCanvas(!0);h.setStroke(i?void 0:e,2*r,s.__),h.font=a,i?Ut(e,!0,s,h):Ft(s,h),h.blendMode="outside"===t?"destination-out":"destination-in",Pt(s,h),h.blendMode="normal",s.__hasMirror||o.matrix?n.copyWorldByReset(h):n.copyWorldToInner(h,s.__world,s.__layout.renderBounds),h.recycle()}function Ft(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,r=s.length;t<r;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 Ut(t,e,i,s){let n;for(let o=0,r=t.length;o<r;o++)n=t[o],n.image&&At(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?Ft(i,s):s.stroke(),s.restoreBlendMode()):e?Ft(i,s):s.stroke())}const{getSpread:Vt,getOuterOf:Yt,getByMove:zt,getIntersectData:Gt}=d;const jt={x:.5,y:0},Nt={x:.5,y:1};function Ht(t,e,i){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],t.addColorStop(s.offset,A.string(s.color,i))}const{set:Xt,getAngle:Kt,getDistance:qt}=S,{get:Qt,rotateOfOuter:$t,scaleOfOuter:Zt}=k,Jt={x:.5,y:.5},te={x:.5,y:1},ee={},ie={};const{set:se,getAngle:ne,getDistance:oe}=S,{get:re,rotateOfOuter:ae,scaleOfOuter:he}=k,le={x:.5,y:.5},de={x:.5,y:1},ce={},ue={};let pe;function ge(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:r,opacity:a}=e;return{type:n,blendMode:o,style:A.string(r,a)};case"image":return function(t,e,i,s,n){const o={type:i.type},r=o.image=f.get(i),a=(n||r.loading)&&{target:t,image:r,attrName:e,attrValue:i};return r.ready?(Mt(t,e,r)&&Lt(o,r,i,s),n&&(Rt(C.LOAD,a),Rt(C.LOADED,a))):r.error?n&&(t.forceUpdate("surface"),a.error=r.error,Rt(C.ERROR,a)):(n&&Rt(C.LOAD,a),o.loadId=r.load((()=>{t.destroyed||(Mt(t,e,r)&&(Lt(o,r,i,s),t.forceUpdate("surface")),Rt(C.LOADED,a))}),(e=>{t.forceUpdate("surface"),a.error=e,Rt(C.ERROR,a)}))),o}(i,t,e,s,!pe||!pe[e.url]);case"linear":return function(t,e){let{from:i,to:s,type:n,blendMode:o,opacity:r}=t;i||(i=jt),s||(s=Nt);const a=_.canvas.createLinearGradient(e.x+i.x*e.width,e.y+i.y*e.height,e.x+s.x*e.width,e.y+s.y*e.height);Ht(a,t.stops,r);const h={type:n,style:a};return o&&(h.blendMode=o),h}(e,s);case"radial":return function(t,e){let{from:i,to:s,type:n,opacity:o,blendMode:r,stretch:a}=t;i||(i=Jt),s||(s=te);const{x:h,y:l,width:d,height:c}=e;let u;Xt(ee,h+i.x*d,l+i.y*c),Xt(ie,h+s.x*d,l+s.y*c),(d!==c||a)&&(u=Qt(),Zt(u,ee,d/c*(a||1),1),$t(u,ee,Kt(ee,ie)+90));const p=_.canvas.createRadialGradient(ee.x,ee.y,0,ee.x,ee.y,qt(ee,ie));Ht(p,t.stops,o);const g={type:n,style:p,transform:u};return r&&(g.blendMode=r),g}(e,s);case"angular":return function(t,e){let{from:i,to:s,type:n,opacity:o,blendMode:r,stretch:a}=t;i||(i=le),s||(s=de);const{x:h,y:l,width:d,height:c}=e;se(ce,h+i.x*d,l+i.y*c),se(ue,h+s.x*d,l+s.y*c);const u=re(),p=ne(ce,ue);_.conicGradientRotate90?(he(u,ce,d/c*(a||1),1),ae(u,ce,p+90)):(he(u,ce,1,d/c*(a||1)),ae(u,ce,p));const g=_.conicGradientSupport?_.canvas.createConicGradient(0,ce.x,ce.y):_.canvas.createRadialGradient(ce.x,ce.y,0,ce.x,ce.y,oe(ce,ue));Ht(g,t.stops,o);const f={type:n,style:g,transform:u};return r&&(f.blendMode=r),f}(e,s);default:return e.r?{type:"solid",style:A.string(e)}:void 0}}var fe=Object.freeze({__proto__:null,compute:function(t,e){const i=[],s=e.__;let n,o,r=s.__input[t];r instanceof Array||(r=[r]),pe=Dt(t,s);for(let s=0,o=r.length;s<o;s++)n=ge(t,r[s],e),n&&i.push(n);if(s["_"+t]=i.length?i:void 0,1===r.length){const t=r[0];"image"===t.type&&(o=D.isPixel(t))}"fill"===t?s.__pixelFill=o:s.__pixelStroke=o},drawTextStroke:Ft,fill:function(t,e,i){i.fillStyle=t,e.__.__font?Pt(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fillText:Pt,fills:function(t,e,i){let s;const{windingRule:n,__font:o}=e.__;for(let r=0,a=t.length;r<a;r++)s=t[r],s.image&&At(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?Pt(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?Pt(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?Pt(e,i):n?i.fill(n):i.fill())},recycleImage:Dt,shape:function(t,e,i){const s=e.getSameCanvas();let n,o,r,a;const{__world:h}=t;let{scaleX:l,scaleY:d}=h;if(l<0&&(l=-l),d<0&&(d=-d),e.bounds.includes(h,i.matrix))i.matrix?(l*=i.matrix.a,d*=i.matrix.d,n=r=Yt(h,i.matrix)):n=r=h,a=s;else{const{renderShapeSpread:s}=t.__layout,c=Gt(s?Vt(e.bounds,s*l,s*d):e.bounds,h,i.matrix);o=e.bounds.getFitMatrix(c),o.a<1&&(a=e.getSameCanvas(),t.__renderShape(a,i),l*=o.a,d*=o.d),r=Yt(h,o),n=zt(r,-o.e,-o.f),i.matrix&&o.multiply(i.matrix),i=Object.assign(Object.assign({},i),{matrix:o})}return t.__renderShape(s,i),{canvas:s,matrix:o,bounds:n,worldCanvas:a,shapeBounds:r,scaleX:l,scaleY:d}},stroke:function(t,e,i,s){const n=e.__,{strokeWidth:o,strokeAlign:r,__font:a}=n;if(o)if(a)Wt(t,e,i,s);else switch(r){case"center":i.setStroke(t,o,n),i.stroke();break;case"inside":i.save(),i.setStroke(t,2*o,n),n.windingRule?i.clip(n.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const r=i.getSameCanvas(!0);r.setStroke(t,2*o,e.__),e.__drawRenderPath(r),r.stroke(),n.windingRule?r.clip(n.windingRule):r.clip(),r.clearWorld(e.__layout.renderBounds),e.__hasMirror||s.matrix?i.copyWorldByReset(r):i.copyWorldToInner(r,e.__world,e.__layout.renderBounds),r.recycle()}},strokeText:Wt,strokes:function(t,e,i,s){const n=e.__,{strokeWidth:o,strokeAlign:r,__font:a}=n;if(o)if(a)Wt(t,e,i,s);else switch(r){case"center":i.setStroke(void 0,o,n),Ut(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*o,n),n.windingRule?i.clip(n.windingRule):i.clip(),Ut(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:r}=e.__layout,a=i.getSameCanvas(!0);e.__drawRenderPath(a),a.setStroke(void 0,2*o,e.__),Ut(t,!1,e,a),n.windingRule?a.clip(n.windingRule):a.clip(),a.clearWorld(r),e.__hasMirror||s.matrix?i.copyWorldByReset(a):i.copyWorldToInner(a,e.__world,r),a.recycle()}}});const{copy:_e,toOffsetOutBounds:we}=d,ve={},ye={};function me(t,e,i,s){const{bounds:n,shapeBounds:o}=s;if(_.fullImageShadow){if(_e(ve,t.bounds),ve.x+=e.x-o.x,ve.y+=e.y-o.y,i){const{matrix:t}=s;ve.x-=(n.x+(t?t.e:0)+n.width/2)*(i-1),ve.y-=(n.y+(t?t.f:0)+n.height/2)*(i-1),ve.width*=i,ve.height*=i}t.copyWorld(s.canvas,t.bounds,ve)}else i&&(_e(ve,e),ve.x-=e.width/2*(i-1),ve.y-=e.height/2*(i-1),ve.width*=i,ve.height*=i),t.copyWorld(s.canvas,o,i?ve:e)}const{toOffsetOutBounds:xe}=d,be={};var Be=Object.freeze({__proto__:null,blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__world.a),i.copyWorldToInner(e,t.__world,t.__layout.renderBounds),i.filter="none"},innerShadow:function(t,e,i,s){let n,o;const{__world:r,__layout:a}=t,{innerShadow:h}=t.__,{worldCanvas:l,bounds:d,shapeBounds:c,scaleX:u,scaleY:p}=i,g=e.getSameCanvas(),f=h.length-1;xe(d,be),h.forEach(((h,_)=>{g.save(),g.setWorldShadow(be.offsetX+h.x*u,be.offsetY+h.y*p,h.blur*u),o=h.spread?1-2*h.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,me(g,be,o,i),g.restore(),l?(g.copyWorld(g,d,r,"copy"),g.copyWorld(l,r,r,"source-out"),n=r):(g.copyWorld(i.canvas,c,d,"source-out"),n=d),g.fillWorld(n,h.color,"source-in"),t.__hasMirror||s.matrix?e.copyWorldByReset(g,n,r,h.blendMode):e.copyWorldToInner(g,n,a.renderBounds,h.blendMode),f&&_<f&&g.clear()})),g.recycle()},shadow:function(t,e,i,s){let n,o;const{__world:r,__layout:a}=t,{shadow:h}=t.__,{worldCanvas:l,bounds:d,shapeBounds:c,scaleX:u,scaleY:p}=i,g=e.getSameCanvas(),f=h.length-1;we(d,ye),h.forEach(((h,_)=>{g.setWorldShadow(ye.offsetX+h.x*u,ye.offsetY+h.y*p,h.blur*u,h.color),o=h.spread?1+2*h.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,me(g,ye,o,i),n=d,h.box&&(g.restore(),g.save(),l&&(g.copyWorld(g,d,r,"copy"),n=r),l?g.copyWorld(l,r,r,"destination-out"):g.copyWorld(i.canvas,c,d,"destination-out")),t.__hasMirror||s.matrix?e.copyWorldByReset(g,n,r,h.blendMode):e.copyWorldToInner(g,n,a.renderBounds,h.blendMode),f&&_<f&&g.clear()})),g.recycle()}});const Ee=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Le=Ee+"_#~&*+\\=|≮≯≈≠=…",Me=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 Re(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Te=Re("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ke=Re("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Ce=Re(Ee),Se=Re(Le),Oe=Re("- —/~|┆·");var Ae;!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"}(Ae||(Ae={}));const{Letter:De,Single:Pe,Before:We,After:Ie,Symbol:Fe,Break:Ue}=Ae;function Ve(t){return Te[t]?De:Oe[t]?Ue:ke[t]?We:Ce[t]?Ie:Se[t]?Fe:Me.test(t)?Pe:De}const Ye={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 ze(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:Ge}=Ye,{Letter:je,Single:Ne,Before:He,After:Xe,Symbol:Ke,Break:qe}=Ae;let Qe,$e,Ze,Je,ti,ei,ii,si,ni,oi,ri,ai,hi,li,di,ci,ui=[];function pi(t,e){ni&&!si&&(si=ni),Qe.data.push({char:t,width:e}),Ze+=e}function gi(){Je+=Ze,Qe.width=Ze,$e.words.push(Qe),Qe={data:[]},Ze=0}function fi(){li&&(di.paraNumber++,$e.paraStart=!0,li=!1),ni&&($e.startCharSize=si,$e.endCharSize=ni,si=0),$e.width=Je,ci.width&&Ge($e),ui.push($e),$e={words:[]},Je=0}const _i={getDrawData(t,e){"string"!=typeof t&&(t=String(t));let i=0,s=0,n=e.__getInput("width")||0,o=e.__getInput("height")||0;const{textDecoration:r,__font:a,padding:h}=e;if(h){const[t,e,r,a]=L.fourNumber(h);n&&(i=a,n-=e+a),o&&(s=t,o-=t+r)}const l={bounds:{x:i,y:s,width:n,height:o},rows:[],paraNumber:0,font:_.canvas.font=a};return function(t,e,i){di=t,ui=t.rows,ci=t.bounds;const{__letterSpacing:s,paraIndent:n,textCase:o}=i,{canvas:r}=_,{width:a,height:h}=ci;if(a||h||s||"none"!==o){const t="none"!==i.textWrap,h="break"===i.textWrap;li=!0,ri=null,si=ii=ni=Ze=Je=0,Qe={data:[]},$e={words:[]};for(let i=0,l=e.length;i<l;i++)ei=e[i],"\n"===ei?(Ze&&gi(),$e.paraEnd=!0,fi(),li=!0):(oi=Ve(ei),oi===je&&"none"!==o&&(ei=ze(ei,o,!Ze)),ii=r.measureText(ei).width,s&&(s<0&&(ni=ii),ii+=s),ai=oi===Ne&&(ri===Ne||ri===je)||ri===Ne&&oi!==Xe,hi=!(oi!==He&&oi!==Ne||ri!==Ke&&ri!==Xe),ti=li&&n?a-n:a,t&&a&&Je+Ze+ii>ti&&(h?(Ze&&gi(),fi()):(hi||(hi=oi===je&&ri==Xe),ai||hi||oi===qe||oi===He||oi===Ne||Ze+ii>ti?(Ze&&gi(),fi()):fi()))," "===ei&&!0!==li&&Je+Ze===0||(oi===qe?(" "===ei&&Ze&&gi(),pi(ei,ii),gi()):ai||hi?(Ze&&gi(),pi(ei,ii)):pi(ei,ii)),ri=oi);Ze&&gi(),Je&&fi(),ui.length>0&&(ui[ui.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{di.paraNumber++,ui.push({x:n||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(l,t,e),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:r,__clipText:a,textAlign:h,verticalAlign:l,paraSpacing:d}=e;let c,u,p,{x:g,y:f,width:_,height:w}=s,v=n*i.length+(d?d*(t.paraNumber-1):0),y=o;if(a&&v>w)v=Math.max(w,n),t.overflow=i.length;else switch(l){case"middle":f+=(w-v)/2;break;case"bottom":f+=w-v}y+=f;for(let o=0,l=i.length;o<l;o++){switch(c=i[o],c.x=g,h){case"center":c.x+=(_-c.width)/2;break;case"right":c.x+=_-c.width}c.paraStart&&d&&o>0&&(y+=d),c.y=y,y+=n,t.overflow>o&&y>v&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,p=c.width,r<0&&(c.width<0?(p=-c.width+e.fontSize+r,u-=p,p+=e.fontSize):p-=r),u<s.x&&(s.x=u),p>s.width&&(s.width=p),a&&_&&_<p&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=f,s.height=v}(l,e),function(t,e,i,s){const{rows:n}=t,{textAlign:o,paraIndent:r,letterSpacing:a}=e;let h,l,d,c,u;n.forEach((t=>{t.words&&(d=r&&t.paraStart?r:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-d)/(t.words.length-1):0,c=a||t.isOverflow?0:l>.01?1:2,t.isOverflow&&!a&&(t.textMode=!0),2===c?(t.x+=d,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=d,h=t.x,t.data=[],t.words.forEach((e=>{1===c?(u={char:"",x:h},h=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,h,u)," "!==u.char&&t.data.push(u)):h=function(t,e,i){return t.forEach((t=>{" "!==t.char&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,h,t.data),!t.paraEnd&&l&&(h+=l,t.width+=l)}))),t.words=null)}))}(l,e,n),l.overflow&&function(t,e){const{rows:i,overflow:s}=t;let{textOverflow:n}=e;if(i.splice(s),"hide"!==n){let t,o;"ellipsis"===n&&(n="...");const r=_.canvas.measureText(n).width,a=e.x+e.width-r;("none"===e.textWrap?i:[i[s-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],o=t.x+t.width,!(s===i&&o<a));s--){if(o<a&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=r,e.data.push({char:n,x:o}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(l,e),"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}}(l,e),l}},wi={string(t,e){if("string"==typeof t)return t;let i=void 0===t.a?1:t.a;e&&(i*=e);const s=t.r+","+t.g+","+t.b;return 1===i?"rgb("+s+")":"rgba("+s+","+i+")"}},vi={export(t,e,i){return function(t){yi||(yi=new O);return new Promise((e=>{yi.add((()=>Tt(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((s=>new Promise((n=>{const{leafer:o}=t;o?o.waitViewCompleted((()=>Tt(this,void 0,void 0,(function*(){let t,r,a,{canvas:h}=o,{unreal:l}=h;switch(l&&(h=h.getSameCanvas(),h.backgroundColor=o.config.fill,o.__render(h,{})),typeof i){case"object":i.quality&&(t=i.quality),i.blob&&(r=!0);break;case"number":t=i;break;case"boolean":r=i}a=e.includes(".")?yield h.saveAs(e,t):r?yield h.toBlob(e,t):yield h.toDataURL(e,t),s({data:a}),n(),l&&h.recycle()})))):(s({data:!1}),n())}))))}};let yi;Object.assign(P,fe),Object.assign(W,Be),Object.assign(I,_i),Object.assign(A,wi),Object.assign(F,vi),ft();export{ut as Interaction,Z as Layouter,ot as LeaferCanvas,tt as Renderer,st as Selector,U as Watcher,ft as useCanvas};