leafer-ui 1.2.1 → 1.2.2

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.
package/README.md CHANGED
@@ -24,21 +24,17 @@
24
24
 
25
25
  跟随官网教程步骤(文档底部有下一步引导按钮)从浅到深的学习,动手调试每一段示例代码。
26
26
 
27
- [3. 开发一个画龙点睛的小游戏](https://leaferjs.com/ui/contest/guide.html)
28
-
29
- 给你一条会飞的龙,看你能做出什么好玩的小游戏分享给我们 ◠‿◠
30
-
31
27
  ## 快速安装
32
28
 
33
29
  🚀 想马上在产品中使用,请安装 [leafer-ui](https://leaferjs.com/ui/guide/install/ui/start.html),开始你的探索之旅。
34
30
 
35
31
  ## 场景包
36
32
 
37
- 高效绘图场景,推荐安装更轻量的 [leafer-draw](https://leaferjs.com/ui/guide/install/draw/start.html) (49KB min+gzip)。
33
+ 高效绘图场景,推荐直接安装更轻量的 [leafer-draw](https://leaferjs.com/ui/guide/install/draw/start.html) (51KB min+gzip)。
38
34
 
39
- 游戏开发场景,推荐安装更省心的 [leafer-game](https://leaferjs.com/ui/guide/install/game/start.html),已集成了游戏相关插件。
35
+ 游戏开发场景,推荐直接安装更省心的 [leafer-game](https://leaferjs.com/ui/guide/install/game/start.html),已集成了游戏相关插件。
40
36
 
41
- 图形编辑场景,推荐安装更省心的 [leafer-editor](https://leaferjs.com/ui/guide/install/editor/start.html),已集成了图形编辑器相关插件。
37
+ 图形编辑场景,推荐直接安装更省心的 [leafer-editor](https://leaferjs.com/ui/guide/install/editor/start.html),已集成了图形编辑器相关插件。
42
38
 
43
39
  ## 互动交流
44
40
 
package/dist/web.cjs CHANGED
@@ -94,7 +94,8 @@ class LeaferCanvas extends core.LeaferCanvasBase {
94
94
  this.view.height = Math.ceil(height * pixelRatio);
95
95
  }
96
96
  updateClientBounds() {
97
- this.clientBounds = this.view.getBoundingClientRect();
97
+ if (this.view.parentElement)
98
+ this.clientBounds = this.view.getBoundingClientRect();
98
99
  }
99
100
  startAutoLayout(autoBounds, listener) {
100
101
  this.resizeListener = listener;
package/dist/web.esm.js CHANGED
@@ -95,7 +95,8 @@ class LeaferCanvas extends LeaferCanvasBase {
95
95
  this.view.height = Math.ceil(height * pixelRatio);
96
96
  }
97
97
  updateClientBounds() {
98
- this.clientBounds = this.view.getBoundingClientRect();
98
+ if (this.view.parentElement)
99
+ this.clientBounds = this.view.getBoundingClientRect();
99
100
  }
100
101
  startAutoLayout(autoBounds, listener) {
101
102
  this.resizeListener = listener;
@@ -1 +1 @@
1
- import{Debug as t,LeaferCanvasBase as e,Platform as i,DataHelper as s,canvasSizeAttrs as n,ResizeEvent as o,canvasPatch as r,Creator as a,LeaferImage as h,defineKey as l,FileHelper as d,LeafList as c,RenderEvent as u,ChildEvent as p,WatchEvent as g,PropertyEvent as f,LeafHelper as _,BranchHelper as w,Bounds as v,LeafBoundsHelper as m,LeafLevelList as y,LayoutEvent as x,Run as b,ImageManager as B,BoundsHelper as L,Answer as E,MathHelper as R,MatrixHelper as k,AlignHelper as T,ImageEvent as M,AroundHelper as S,PointHelper as C,Direction4 as A,TwoPointBoundsHelper as O,TaskProcessor as P,Matrix as W}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionHelper as D,InteractionBase as I,Cursor as F,HitCanvasManager as z}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as j,ColorConvert as Y,PaintGradient as G,Export as U,Group as V,TextConvert as N,Paint as X,Effect as H}from"@leafer-ui/draw";const q=t.get("LeaferCanvas");class K 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 q.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.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),q.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:r}=this.autoBounds.getBoundsFrom(t),a={width:o,height:r,pixelRatio:i.devicePixelRatio};if(!this.isSameSize(a)){const{style:t}=e;t.marginLeft=s+"px",t.marginTop=n+"px",this.emitResize(a)}}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()}}}r(CanvasRenderingContext2D.prototype),r(Path2D.prototype);const{mineType:Q,fileType:$}=d;function J(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(Q(e),i),canvasToBolb:(t,e,i)=>new Promise((s=>t.toBlob(s,Q(e),i))),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL(Q($(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=a.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(a,{canvas:(t,e)=>new K(t,e),image:t=>new h(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:Z}=navigator;Z.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):Z.indexOf("Safari")>-1&&-1===Z.indexOf("Chrome")&&(i.fullImageShadow=!0),Z.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):Z.indexOf("Mac")>-1?i.os="Mac":Z.indexOf("Linux")>-1&&(i.os="Linux");class tt{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 g(g.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_(f.CHANGE,this.__onAttrChange,this),t.on_([p.ADD,p.REMOVE],this.__onChildEvent,this),t.on_(g.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:et,updateBounds:it,updateAllWorldOpacity:st}=_,{pushAllChildBranch:nt,pushAllParent:ot}=w;const{worldBounds:rt}=m,at={x:0,y:0,width:1e5,height:1e5};class ht{constructor(t){this.updatedBounds=new v,this.beforeBounds=new v,this.afterBounds=new v,t instanceof Array&&(t=new c(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,rt)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(at):this.afterBounds.setListWithFn(t,rt),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:lt,updateAllChange:dt}=_,ct=t.get("Layouter");class ut{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new y,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){ct.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ct.warn("layouting"):this.times>3?ct.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(g.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:r}=x,a=this.getBlocks(s);a.forEach((t=>t.setBefore())),i.emitEvent(new x(n,a,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?(et(t,!0),e.add(t),t.isBranch&&nt(t,e),ot(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),ot(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||it(s[t])}it(i)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&st(t),e.stateStyleChanged&&setTimeout((()=>e.stateStyleChanged&&t.updateState())),t.__updateChange()}))}(s),this.extraBlock&&a.push(this.extraBlock),a.forEach((t=>t.setAfter())),i.emitEvent(new x(o,a,this.times)),i.emitEvent(new x(r,a,this.times)),this.addBlocks(a),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)),ut.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){lt(t,!0),t.isBranch?w.updateBounds(t):_.updateBounds(t),dt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new ht([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new ht(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(x.REQUEST,this.layout,this),t.on_(x.AGAIN,this.layoutAgain,this),t.on_(g.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const pt=t.get("Renderer");class gt{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 v,pt.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,pt.error(t)}pt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return pt.warn("rendering");if(this.times>3)return pt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new v,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 pt.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),r=new v(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,r),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 v;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 v(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 v(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||pt.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)}}const{hitRadiusPoint:ft}=L;class _t{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,o=i.target||this.target;this.exclude=i.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=new c(i.findList),i.findList||this.hitBranch(o);const{list:r}=this.findList,a=this.getBestMatchLeaf(r,i.bottomList,n),h=n?this.getPath(a):this.getHitablePath(a);return this.clear(),s?{path:h,target:a,throughPath:r.length?this.getThroughPath(r):h}:{path:h,target:a}}getBestMatchLeaf(t,e,i){if(t.length){let e;this.findList=new c;const{x:s,y:n}=this.point,o={x:s,y:n,radiusX:0,radiusY:0};for(let s=0,n=t.length;s<n;s++)if(e=t[s],(i||_.worldHittable(e))&&(this.hitChild(e,o),this.findList.length))return this.findList.list[0]}if(e)for(let t=0,i=e.length;t<i;t++)if(this.hitChild(e[t].target,this.point,e[t].proxy),this.findList.length)return this.findList.list[0];return t[0]}getPath(t){const e=new c;for(;t;)e.add(t),t=t.parent;return this.target&&e.add(this.target),e}getHitablePath(t){const e=this.getPath(t&&t.hittable?t:null);let i,s=new c;for(let t=e.list.length-1;t>-1&&(i=e.list[t],i.__.hittable)&&(s.addAt(i,0),i.__.hitChildren);t--);return s}getThroughPath(t){const e=new c,i=[];for(let e=t.length-1;e>-1;e--)i.push(this.getPath(t[e]));let s,n,o;for(let t=0,r=i.length;t<r;t++){s=i[t],n=i[t+1];for(let t=0,i=s.length;t<i&&(o=s.list[t],!n||!n.has(o));t++)e.add(o)}return e}hitBranch(t){this.eachFind(t.children,t.__onlyHitMask)}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.__.mask||(s=!!i.__.hitRadius||ft(i.__world,n),i.isBranch?(s||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&this.hitChild(i,n)):s&&this.hitChild(i,n))}hitChild(t,e,i){if((!this.exclude||!this.exclude.has(t))&&t.__hitWorld(e)){const{parent:s}=t;if(s&&s.__hasMask&&!t.__.mask&&!s.children.some((t=>t.__.mask&&t.__hitWorld(e))))return;this.findList.add(i||t)}}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}const{Yes:wt,NoAndSkip:vt,YesAndSkip:mt}=E,yt={},xt={},bt={};class Bt{constructor(t,e){this.config={},this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.target&&(this.idMap[e]=t),1):0,innerId:(t,e)=>t.innerId===e?(this.target&&(this.innerIdMap[e]=t),1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},this.target=t,e&&(this.config=s.default(e,this.config)),this.picker=new _t(t,this),t&&this.__listenEvents()}getBy(t,e,i,n){switch(typeof t){case"number":const o=this.getByInnerId(t,e);return i?o:o?[o]:[];case"string":switch(t[0]){case"#":yt.id=t.substring(1),t=yt;break;case".":xt.className=t.substring(1),t=xt;break;default:bt.tag=t,t=bt}case"object":if(void 0!==t.id){const s=this.getById(t.id,e);return i?s:s?[s]:[]}if(t.tag){const{tag:n}=t,o=n instanceof Array;return this.getByMethod(o?this.methods.tags:this.methods.tag,e,i,o?s.toMap(n):n)}return this.getByMethod(this.methods.className,e,i,t.className);case"function":return this.getByMethod(t,e,i,n)}}getByPoint(t,e,s){return"node"===i.name&&this.target&&this.target.emit(x.CHECK_UPDATE),this.picker.getByPoint(t,e,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&&_.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,o;for(let r=0,a=t.length;r<a;r++){if(n=t[r],o=e(n,s),o===wt||o===mt){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&o<vt&&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_(p.REMOVE,this.__onRemoveChild,this),this.target.on_(f.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.__eventIds.length&&(this.__removeListenEvents(),this.picker.destroy(),this.findLeaf=null,this.innerIdMap={},this.idMap={})}}Object.assign(a,{watcher:(t,e)=>new tt(t,e),layouter:(t,e)=>new ut(t,e),renderer:(t,e,i)=>new gt(t,e,i),selector:(t,e)=>new Bt(t,e)}),i.layout=ut.fullLayout;const Lt={convert(t,e){const i=D.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=D.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=Lt.getTouch(t),s=D.getBase(t);return Object.assign(Object.assign({},s),{x:e.x,y:e.y,width:1,height:1,pointerType:"touch",multiTouch:t.touches.length>1,pressure:i.force})},getTouch:t=>t.targetTouches[0]||t.changedTouches[0]},Et={convert(t){const e=D.getBase(t);return Object.assign(Object.assign({},e),{code:t.code,key:t.key})}},{pathCanDrag:Rt}=D;class kt extends I{__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={}}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(Et.convert(t))}onKeyUp(t){this.keyUp(Et.convert(t))}onContextMenu(t){this.config.pointer.preventDefaultMenu&&t.preventDefault(),this.menu(Lt.convert(t,this.getLocal(t)))}onScroll(){this.canvas.updateClientBounds()}onPointerDown(t){this.preventDefaultPointer(t),this.config.pointer.touch||this.useMultiTouch||(this.usePointer||(this.usePointer=!0),this.pointerDown(Lt.convert(t,this.getLocal(t))))}onPointerMove(t){this.config.pointer.touch||this.useMultiTouch||this.preventWindowPointer(t)||(this.usePointer||(this.usePointer=!0),this.pointerMove(Lt.convert(t,this.getLocal(t,!0))))}onPointerUp(t){this.downData&&this.preventDefaultPointer(t),this.config.pointer.touch||this.useMultiTouch||this.preventWindowPointer(t)||this.pointerUp(Lt.convert(t,this.getLocal(t)))}onPointerCancel(){this.useMultiTouch||this.pointerCancel()}onMouseDown(t){this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.pointerDown(Lt.convertMouse(t,this.getLocal(t)))}onMouseMove(t){this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerMove(Lt.convertMouse(t,this.getLocal(t,!0)))}onMouseUp(t){this.downData&&this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerUp(Lt.convertMouse(t,this.getLocal(t)))}onMouseCancel(){this.useTouch||this.usePointer||this.pointerCancel()}onTouchStart(t){const e=Lt.getTouch(t),i=this.getLocal(e,!0),{preventDefault:s}=this.config.touch;(!0===s||"auto"===s&&Rt(this.findPath(i)))&&t.preventDefault(),this.multiTouchStart(t),this.usePointer||(this.touchTimer&&(window.clearTimeout(this.touchTimer),this.touchTimer=0),this.useTouch=!0,this.pointerDown(Lt.convertTouch(t,i)))}onTouchMove(t){if(this.multiTouchMove(t),this.usePointer||this.preventWindowPointer(t))return;const e=Lt.getTouch(t);this.pointerMove(Lt.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=Lt.getTouch(t);this.pointerUp(Lt.convertTouch(t,this.getLocal(e)))}onTouchCancel(){this.usePointer||this.pointerCancel()}multiTouchStart(t){this.useMultiTouch=t.touches.length>1,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(D.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),this.wheel(Object.assign(Object.assign(Object.assign({},D.getBase(t)),this.getLocal(t)),{deltaX:t.deltaX,deltaY:t.deltaY}))}onGesturestart(t){this.useMultiTouch||(this.preventDefaultWheel(t),this.lastGestureScale=1,this.lastGestureRotation=0)}onGesturechange(t){if(this.useMultiTouch)return;this.preventDefaultWheel(t);const e=D.getBase(t);Object.assign(e,this.getLocal(t));const i=t.scale/this.lastGestureScale,s=(t.rotation-this.lastGestureRotation)/Math.PI*180*(R.within(this.config.wheel.rotateSpeed,0,1)/4+.1);this.zoom(Object.assign(Object.assign({},e),{scale:i*i})),this.rotate(Object.assign(Object.assign({},e),{rotation:s})),this.lastGestureScale=t.scale,this.lastGestureRotation=t.rotation}onGestureend(t){this.useMultiTouch||(this.preventDefaultWheel(t),this.transformEnd())}setCursor(t){super.setCursor(t);const e=[];this.eachCursor(t,e),"object"==typeof e[e.length-1]&&e.push("default"),this.canvas.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&&F.get(t);s&&i<2?this.eachCursor(s,e,i):e.push(t)}}destroy(){this.view&&(super.destroy(),this.view=null,this.touches=null)}}function Tt(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 Mt(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?At(t,!0,e,i):Ct(e,i);break;case"inside":St("inside",t,n,e,i);break;case"outside":St("outside",t,n,e,i)}}function St(t,e,i,s,n){const{__strokeWidth:o,__font:r}=s.__,a=n.getSameCanvas(!0,!0);a.setStroke(i?void 0:e,2*o,s.__),a.font=r,i?At(e,!0,s,a):Ct(s,a),a.blendMode="outside"===t?"destination-out":"destination-in",Tt(s,a),a.blendMode="normal",s.__worldFlipped?n.copyWorldByReset(a,s.__nowWorld):n.copyWorldToInner(a,s.__nowWorld,s.__layout.renderBounds),a.recycle(s.__nowWorld)}function Ct(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 At(t,e,i,s){let n;for(let o=0,r=t.length;o<r;o++)n=t[o],n.image&&j.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?Ct(i,s):s.stroke(),s.restoreBlendMode()):e?Ct(i,s):s.stroke())}function Ot(t,e){t.__.dashPattern&&(e.beginPath(),t.__drawPathByData(e,t.__.__pathForArrow),e.dashPattern=null,e.stroke())}const{getSpread:Pt,getOuterOf:Wt,getByMove:Dt,getIntersectData:It}=L;let Ft;function zt(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:Y.string(r,a)};case"image":return j.image(i,t,e,s,!Ft||!Ft[e.url]);case"linear":return G.linearGradient(e,s);case"radial":return G.radialGradient(e,s);case"angular":return G.conicGradient(e,s);default:return void 0!==e.r?{type:"solid",style:Y.string(e)}:void 0}}const jt={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),Ft=j.recycleImage(t,i);for(let i,n=0,r=o.length;n<r;n++)i=zt(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?Tt(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 r=0,a=t.length;r<a;r++)s=t[r],s.image&&j.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?Tt(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?Tt(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?Tt(e,i):n?i.fill(n):i.fill())},fillText:Tt,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:r}=s;if(n)if(r)Mt(t,e,i);else switch(o){case"center":i.setStroke(t,n,s),i.stroke(),s.__useArrow&&Ot(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:r}=s;if(n)if(r)Mt(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),At(t,!1,e,i),s.__useArrow&&Ot(e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),At(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,r=i.getSameCanvas(!0,!0);e.__drawRenderPath(r),r.setStroke(void 0,2*n,s),At(t,!1,e,r),s.windingRule?r.clip(s.windingRule):r.clip(),r.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(r,e.__nowWorld):i.copyWorldToInner(r,e.__nowWorld,o),r.recycle(e.__nowWorld)}},strokeText:Mt,drawTextStroke:Ct,shape:function(t,e,i){const s=e.getSameCanvas(),n=t.__nowWorld;let o,r,a,h,{scaleX:l,scaleY:d}=n;if(l<0&&(l=-l),d<0&&(d=-d),e.bounds.includes(n))h=s,o=a=n;else{const{renderShapeSpread:s}=t.__layout,c=It(s?Pt(e.bounds,l===d?s*l:[s*d,s*l]):e.bounds,n);r=e.bounds.getFitMatrix(c);let{a:u,d:p}=r;if(r.a<1&&(h=e.getSameCanvas(),t.__renderShape(h,i),l*=u,d*=p),a=Wt(n,r),o=Dt(a,-r.e,-r.f),i.matrix){const{matrix:t}=i;r.multiply(t),u*=t.scaleX,p*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:r.withScale(u,p)})}return t.__renderShape(s,i),{canvas:s,matrix:r,bounds:o,worldCanvas:h,shapeBounds:a,scaleX:l,scaleY:d}}};let Yt={};const{get:Gt,rotateOfOuter:Ut,translate:Vt,scaleOfOuter:Nt,scale:Xt,rotate:Ht}=k;function qt(t,e,i,s,n,o,r){const a=Gt();Vt(a,e.x+i,e.y+s),Xt(a,n,o),r&&Ut(a,{x:e.x+e.width/2,y:e.y+e.height/2},r),t.transform=a}function Kt(t,e,i,s,n,o,r){const a=Gt();Vt(a,e.x+i,e.y+s),n&&Xt(a,n,o),r&&Ht(a,r),t.transform=a}function Qt(t,e,i,s,n,o,r,a,h,l){const d=Gt();if(h)if("center"===l)Ut(d,{x:i/2,y:s/2},h);else switch(Ht(d,h),h){case 90:Vt(d,s,0);break;case 180:Vt(d,i,s);break;case 270:Vt(d,0,i)}Yt.x=e.x+n,Yt.y=e.y+o,Vt(d,Yt.x,Yt.y),r&&Nt(d,Yt,r,a),t.transform=d}const{get:$t,translate:Jt}=k,Zt=new v,te={},ee={};function ie(t,e,i,s){const{blendMode:n,sync:o}=i;n&&(t.blendMode=n),o&&(t.sync=o),t.data=se(i,s,e)}function se(t,e,i){let{width:s,height:n}=i;t.padding&&(e=Zt.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{opacity:o,mode:r,align:a,offset:h,scale:l,size:d,rotation:c,repeat:u}=t,p=e.width===s&&e.height===n,g={mode:r},f="center"!==a&&(c||0)%180==90,_=f?n:s,w=f?s:n;let v,m,y=0,x=0;if(r&&"cover"!==r&&"fit"!==r)(l||d)&&(R.getScaleData(l,d,i,ee),v=ee.scaleX,m=ee.scaleY);else if(!p||c){const t=e.width/_,i=e.height/w;v=m="fit"===r?Math.min(t,i):Math.max(t,i),y+=(e.width-s*v)/2,x+=(e.height-n*m)/2}if(a){const t={x:y,y:x,width:_,height:w};v&&(t.width*=v,t.height*=m),T.toPoint(a,t,e,te,!0),y+=te.x,x+=te.y}switch(h&&(y+=h.x,x+=h.y),r){case"stretch":p||(s=e.width,n=e.height);break;case"normal":case"clip":(y||x||v||c)&&Kt(g,e,y,x,v,m,c);break;case"repeat":(!p||v||c)&&Qt(g,e,s,n,y,x,v,m,c,a),u||(g.repeat="repeat");break;default:v&&qt(g,e,y,x,v,m,c)}return g.transform||(e.x||e.y)&&(g.transform=$t(),Jt(g.transform,e.x,e.y)),v&&"stretch"!==r&&(g.scaleX=v,g.scaleY=m),g.width=s,g.height=n,o&&(g.opacity=o),u&&(g.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),g}let ne,oe=new v;const{isSame:re}=L;function ae(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||ie(n,s,i,o),!0}function he(t,e){ce(t,M.LOAD,e)}function le(t,e){ce(t,M.LOADED,e)}function de(t,e,i){e.error=i,t.forceUpdate("surface"),ce(t,M.ERROR,e)}function ce(t,e,i){t.hasEvent(e)&&t.emitEvent(new M(e,i))}function ue(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:pe,scale:ge,copy:fe}=k,{ceil:_e,abs:we}=Math;function ve(t,e,s){let{scaleX:n,scaleY:o}=B.patternLocked?t.__world:t.__nowWorld;const r=n+"-"+o+"-"+s;if(e.patternId===r||t.destroyed)return!1;{n=we(n),o=we(o);const{image:t,data:a}=e;let h,l,{width:d,height:c,scaleX:u,scaleY:p,opacity:g,transform:f,repeat:_}=a;u&&(l=pe(),fe(l,f),ge(l,1/u,1/p),n*=u,o*=p),n*=s,o*=s,d*=n,c*=o;const w=d*c;if(!_&&w>i.image.maxCacheSize)return!1;let v=i.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;v>e&&(v=e)}w>v&&(h=Math.sqrt(w/v)),h&&(n/=h,o/=h,d/=h,c/=h),u&&(n/=u,o/=p),(f||1!==n||1!==o)&&(l||(l=pe(),f&&fe(l,f)),ge(l,1/n,1/o));const m=t.getCanvas(_e(d)||1,_e(c)||1,g),y=t.getPattern(m,_||i.origin.noRepeat||"no-repeat",l,e);return e.style=y,e.patternId=r,!0}}function me(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{abs:ye}=Math;const xe={image:function(t,e,i,s,n){let o,r;const a=B.get(i);return ne&&i===ne.paint&&re(s,ne.boxBounds)?o=ne.leafPaint:(o={type:i.type,image:a},ne=a.use>1?{leafPaint:o,paint:i,boxBounds:oe.set(s)}:null),(n||a.loading)&&(r={image:a,attrName:e,attrValue:i}),a.ready?(ae(t,e,i,a,o,s),n&&(he(t,r),le(t,r))):a.error?n&&de(t,r,a.error):(n&&(ue(t,!0),he(t,r)),o.loadId=a.load((()=>{ue(t,!1),t.destroyed||(ae(t,e,i,a,o,s)&&(a.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),le(t,r)),o.loadId=null}),(e=>{ue(t,!1),de(t,r,e),o.loadId=null}))),o},checkImage:function(t,e,s,n){const{scaleX:o,scaleY:r}=B.patternLocked?t.__world:t.__nowWorld,{pixelRatio:a}=e;if(!s.data||s.patternId===o+"-"+r+"-"+a&&!U.running)return!1;{const{data:h}=s;if(n)if(h.repeat)n=!1;else{let{width:t,height:e}=h;t*=ye(o)*a,e*=ye(r)*a,h.scaleX&&(t*=h.scaleX,e*=h.scaleY),n=t*e>i.image.maxCacheSize||U.running}return n?(e.save(),t.windingRule?e.clip(t.windingRule):e.clip(),s.blendMode&&(e.blendMode=s.blendMode),h.opacity&&(e.opacity*=h.opacity),h.transform&&e.transform(h.transform),e.drawImage(s.image.view,0,0,h.width,h.height),e.restore(),!0):(!s.style||s.sync||U.running?ve(t,s,a):s.patternTask||(s.patternTask=B.patternTasker.add((()=>me(this,void 0,void 0,(function*(){s.patternTask=null,e.bounds.hit(t.__nowWorld)&&ve(t,s,a),t.forceUpdate("surface")}))),300)),!1)}},createPattern:ve,recycleImage:function(t,e){const i=e["_"+t];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,B.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},createData:ie,getPatternData:se,fillOrFitMode:qt,clipMode:Kt,repeatMode:Qt},{toPoint:be}=S,Be={},Le={};function Ee(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),Y.string(s,i)):t.addColorStop(s.offset,Y.string(s.color,i))}}const{getAngle:Re,getDistance:ke}=C,{get:Te,rotateOfOuter:Me,scaleOfOuter:Se}=k,{toPoint:Ce}=S,Ae={},Oe={};function Pe(t,e,i,s,n){let o;const{width:r,height:a}=t;if(r!==a||s){const t=Re(e,i);o=Te(),n?(Se(o,e,r/a*(s||1),1),Me(o,e,t+90)):(Se(o,e,1,r/a*(s||1)),Me(o,e,t))}return o}const{getDistance:We}=C,{toPoint:De}=S,Ie={},Fe={};const ze={linearGradient:function(t,e){let{from:s,to:n,type:o,blendMode:r,opacity:a}=t;be(s||"top",e,Be),be(n||"bottom",e,Le);const h=i.canvas.createLinearGradient(Be.x,Be.y,Le.x,Le.y);Ee(h,t.stops,a);const l={type:o,style:h};return r&&(l.blendMode=r),l},radialGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;Ce(s||"center",e,Ae),Ce(n||"bottom",e,Oe);const l=i.canvas.createRadialGradient(Ae.x,Ae.y,0,Ae.x,Ae.y,ke(Ae,Oe));Ee(l,t.stops,r);const d={type:o,style:l},c=Pe(e,Ae,Oe,h,!0);return c&&(d.transform=c),a&&(d.blendMode=a),d},conicGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;De(s||"center",e,Ie),De(n||"bottom",e,Fe);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,Ie.x,Ie.y):i.canvas.createRadialGradient(Ie.x,Ie.y,0,Ie.x,Ie.y,We(Ie,Fe));Ee(l,t.stops,r);const d={type:o,style:l},c=Pe(e,Ie,Fe,h||1,i.conicGradientRotate90);return c&&(d.transform=c),a&&(d.blendMode=a),d},getTransform:Pe},{copy:je,toOffsetOutBounds:Ye}=L,Ge={},Ue={};function Ve(t,e,s,n){const{bounds:o,shapeBounds:r}=n;if(i.fullImageShadow){if(je(Ge,t.bounds),Ge.x+=e.x-r.x,Ge.y+=e.y-r.y,s){const{matrix:t}=n;Ge.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),Ge.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),Ge.width*=s,Ge.height*=s}t.copyWorld(n.canvas,t.bounds,Ge)}else s&&(je(Ge,e),Ge.x-=e.width/2*(s-1),Ge.y-=e.height/2*(s-1),Ge.width*=s,Ge.height*=s),t.copyWorld(n.canvas,r,s?Ge:e)}const{toOffsetOutBounds:Ne}=L,Xe={};const He={shadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:r}=t,{shadow:a}=t.__,{worldCanvas:h,bounds:l,shapeBounds:d,scaleX:c,scaleY:u}=i,p=e.getSameCanvas(),g=a.length-1;Ye(l,Ue),a.forEach(((a,f)=>{p.setWorldShadow(Ue.offsetX+a.x*c,Ue.offsetY+a.y*u,a.blur*c,a.color),n=a.spread?1+2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,Ve(p,Ue,n,i),s=l,a.box&&(p.restore(),p.save(),h&&(p.copyWorld(p,l,o,"copy"),s=o),h?p.copyWorld(h,o,o,"destination-out"):p.copyWorld(i.canvas,d,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(p,s,o,a.blendMode):e.copyWorldToInner(p,s,r.renderBounds,a.blendMode),g&&f<g&&p.clearWorld(s,!0)})),p.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:r}=t,{innerShadow:a}=t.__,{worldCanvas:h,bounds:l,shapeBounds:d,scaleX:c,scaleY:u}=i,p=e.getSameCanvas(),g=a.length-1;Ne(l,Xe),a.forEach(((a,f)=>{p.save(),p.setWorldShadow(Xe.offsetX+a.x*c,Xe.offsetY+a.y*u,a.blur*c),n=a.spread?1-2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,Ve(p,Xe,n,i),p.restore(),h?(p.copyWorld(p,l,o,"copy"),p.copyWorld(h,o,o,"source-out"),s=o):(p.copyWorld(i.canvas,d,l,"source-out"),s=l),p.fillWorld(s,a.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(p,s,o,a.blendMode):e.copyWorldToInner(p,s,r.renderBounds,a.blendMode),g&&f<g&&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:qe}=m;function Ke(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),$e(t,e,i,1)}(t,i,s,n);break;case"opacity-path":$e(t,i,s,o);break;case"path":i.restore()}}function Qe(t){return t.getSameCanvas(!1,!0)}function $e(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}V.prototype.__renderMask=function(t,e){let i,s,n,o,r,a;const{children:h}=this;for(let l=0,d=h.length;l<d;l++)i=h[l],a=i.__.mask,a&&(r&&(Ke(this,r,t,n,s,o),s=n=null),"path"===a||"clipping-path"===a?(i.opacity<1?(r="opacity-path",o=i.opacity,n||(n=Qe(t))):(r="path",t.save()),i.__clip(n||t,e)):(r="grayscale"===a?"grayscale":"alpha",s||(s=Qe(t)),n||(n=Qe(t)),i.__render(s,e)),"clipping"!==a&&"clipping-path"!==a)||qe(i,e)||i.__render(n||t,e);Ke(this,r,t,n,s,o)};const Je=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Ze=Je+"_#~&*+\\=|≮≯≈≠=…",ti=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 ei(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const ii=ei("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),si=ei("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),ni=ei(Je),oi=ei(Ze),ri=ei("- —/~|┆·");var ai;!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"}(ai||(ai={}));const{Letter:hi,Single:li,Before:di,After:ci,Symbol:ui,Break:pi}=ai;function gi(t){return ii[t]?hi:ri[t]?pi:si[t]?di:ni[t]?ci:oi[t]?ui:ti.test(t)?li:hi}const fi={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 _i(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:wi}=fi,{Letter:vi,Single:mi,Before:yi,After:xi,Symbol:bi,Break:Bi}=ai;let Li,Ei,Ri,ki,Ti,Mi,Si,Ci,Ai,Oi,Pi,Wi,Di,Ii,Fi,zi,ji,Yi=[];function Gi(t,e){Ai&&!Ci&&(Ci=Ai),Li.data.push({char:t,width:e}),Ri+=e}function Ui(){ki+=Ri,Li.width=Ri,Ei.words.push(Li),Li={data:[]},Ri=0}function Vi(){Ii&&(Fi.paraNumber++,Ei.paraStart=!0,Ii=!1),Ai&&(Ei.startCharSize=Ci,Ei.endCharSize=Ai,Ci=0),Ei.width=ki,zi.width?wi(Ei):ji&&Ni(),Yi.push(Ei),Ei={words:[]},ki=0}function Ni(){ki>(Fi.maxWidth||0)&&(Fi.maxWidth=ki)}const Xi=0,Hi=1,qi=2;const{top:Ki,right:Qi,bottom:$i,left:Ji}=A;function Zi(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 ts={getDrawData:function(t,e){"string"!=typeof t&&(t=String(t));let s=0,n=0,o=e.__getInput("width")||0,r=e.__getInput("height")||0;const{textDecoration:a,__font:h,__padding:l}=e;l&&(o?(s=l[Ji],o-=l[Qi]+l[Ji]):e.autoSizeAlign||(s=l[Ji]),r?(n=l[Ki],r-=l[Ki]+l[$i]):e.autoSizeAlign||(n=l[Ki]));const d={bounds:{x:s,y:n,width:o,height:r},rows:[],paraNumber:0,font:i.canvas.font=h};return function(t,e,s){Fi=t,Yi=t.rows,zi=t.bounds,ji=!zi.width&&!s.autoSizeAlign;const{__letterSpacing:n,paraIndent:o,textCase:r}=s,{canvas:a}=i,{width:h,height:l}=zi;if(h||l||n||"none"!==r){const t="none"!==s.textWrap,i="break"===s.textWrap;Ii=!0,Pi=null,Ci=Si=Ai=Ri=ki=0,Li={data:[]},Ei={words:[]};for(let s=0,l=e.length;s<l;s++)Mi=e[s],"\n"===Mi?(Ri&&Ui(),Ei.paraEnd=!0,Vi(),Ii=!0):(Oi=gi(Mi),Oi===vi&&"none"!==r&&(Mi=_i(Mi,r,!Ri)),Si=a.measureText(Mi).width,n&&(n<0&&(Ai=Si),Si+=n),Wi=Oi===mi&&(Pi===mi||Pi===vi)||Pi===mi&&Oi!==xi,Di=!(Oi!==yi&&Oi!==mi||Pi!==bi&&Pi!==xi),Ti=Ii&&o?h-o:h,t&&h&&ki+Ri+Si>Ti&&(i?(Ri&&Ui(),ki&&Vi()):(Di||(Di=Oi===vi&&Pi==xi),Wi||Di||Oi===Bi||Oi===yi||Oi===mi||Ri+Si>Ti?(Ri&&Ui(),ki&&Vi()):ki&&Vi()))," "===Mi&&!0!==Ii&&ki+Ri===0||(Oi===Bi?(" "===Mi&&Ri&&Ui(),Gi(Mi,Si),Ui()):Wi||Di?(Ri&&Ui(),Gi(Mi,Si)):Gi(Mi,Si)),Pi=Oi);Ri&&Ui(),ki&&Vi(),Yi.length>0&&(Yi[Yi.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{Fi.paraNumber++,ki=a.measureText(t).width,Yi.push({x:o||0,text:t,width:ki,paraStart:!0}),ji&&Ni()}))}(d,t,e),l&&function(t,e,i,s,n){if(!s&&i.autoSizeAlign)switch(i.textAlign){case"left":Zi(e,"x",t[Ji]);break;case"right":Zi(e,"x",-t[Qi])}if(!n&&i.autoSizeAlign)switch(i.verticalAlign){case"top":Zi(e,"y",t[Ki]);break;case"bottom":Zi(e,"y",-t[$i])}}(l,d,e,o,r),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:r,__clipText:a,textAlign:h,verticalAlign:l,paraSpacing:d,autoSizeAlign:c}=e;let{x:u,y:p,width:g,height:f}=s,_=n*i.length+(d?d*(t.paraNumber-1):0),w=o;if(a&&_>f)_=Math.max(f,n),t.overflow=i.length;else if(f||c)switch(l){case"middle":p+=(f-_)/2;break;case"bottom":p+=f-_}w+=p;let v,m,y,x=g||c?g:t.maxWidth;for(let o=0,l=i.length;o<l;o++){if(v=i[o],v.x=u,v.width<g||v.width>g&&!a)switch(h){case"center":v.x+=(x-v.width)/2;break;case"right":v.x+=x-v.width}v.paraStart&&d&&o>0&&(w+=d),v.y=w,w+=n,t.overflow>o&&w>_&&(v.isOverflow=!0,t.overflow=o+1),m=v.x,y=v.width,r<0&&(v.width<0?(y=-v.width+e.fontSize+r,m-=y,y+=e.fontSize):y-=r),m<s.x&&(s.x=m),y>s.width&&(s.width=y),a&&g&&g<y&&(v.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=p,s.height=_}(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?Xi:l>.01?Hi:qi,t.isOverflow&&!a&&(t.textMode=!0),c===qi?(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=>{c===Hi?(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),(t.isOverflow||" "!==u.char)&&t.data.push(u)):h=function(t,e,i,s){return t.forEach((t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,h,t.data,t.isOverflow),!t.paraEnd&&l&&(h+=l,t.width+=l)}))),t.words=null)}))}(d,e,o),d.overflow&&function(t,e,s,n){if(!n)return;const{rows:o,overflow:r}=t;let{textOverflow:a}=e;if(o.splice(r),a&&"show"!==a){let t,h;"hide"===a?a="":"ellipsis"===a&&(a="...");const l=a?i.canvas.measureText(a).width:0,d=s+n-l;("none"===e.textWrap?o:[o[r-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],h=t.x+t.width,!(s===i&&h<d));s--){if(h<d&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:a,x:h}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(d,e,s,o),"none"!==a&&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}};const es={string:function(t,e){const i="number"==typeof e&&1!==e;if("string"==typeof t){if(!i||!Y.object)return t;t=Y.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+")"}},{setPoint:is,addPoint:ss,toBounds:ns}=O;const os={export(t,e,s){this.running=!0;const n=d.fileType(e),o=e.includes(".");return s=d.getExportOptions(s),function(t){rs||(rs=new P);return new Promise((e=>{rs.add((()=>me(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((r=>new Promise((h=>{const l=t=>{r(t),h(),this.running=!1},{toURL:c}=i,{download:u}=i.origin;if("json"===n)return o&&u(c(JSON.stringify(t.toJSON(s.json)),"text"),e),l({data:!!o||t.toJSON(s.json)});if("svg"===n)return o&&u(c(t.toSVG(),"svg"),e),l({data:!!o||t.toSVG()});const{leafer:p}=t;p?(as(t),p.waitViewCompleted((()=>me(this,void 0,void 0,(function*(){let i,n,o=1,r=1;const{worldTransform:h,isLeafer:c,isFrame:u}=t,{slice:g,trim:f,onCanvas:_}=s,w=void 0===s.smooth?p.config.smooth:s.smooth,m=s.contextSettings||p.config.contextSettings,y=s.screenshot||t.isApp,x=c&&y&&void 0===s.fill?t.fill:s.fill,b=d.isOpaqueImage(e)||x,B=new W;if(y)i=!0===y?c?p.canvas.bounds:t.worldRenderBounds:y;else{let e=s.relative||(c?"inner":"local");switch(o=h.scaleX,r=h.scaleY,e){case"inner":B.set(h);break;case"local":B.set(h).divide(t.localTransform),o/=t.scaleX,r/=t.scaleY;break;case"world":o=1,r=1;break;case"page":e=t.leafer;default:B.set(h).divide(t.getTransform(e));const i=e.worldTransform;o/=o/i.scaleX,r/=r/i.scaleY}i=t.getBounds("render",e)}const L={scaleX:1,scaleY:1};R.getScaleData(s.scale,s.size,i,L);let E=s.pixelRatio||1;t.isApp&&(L.scaleX*=E,L.scaleY*=E,E=t.app.pixelRatio);const{x:k,y:T,width:M,height:S}=new v(i).scale(L.scaleX,L.scaleY),C={matrix:B.scale(1/L.scaleX,1/L.scaleY).invert().translate(-k,-T).withScale(1/o*L.scaleX,1/r*L.scaleY)};let A,O=a.canvas({width:Math.round(M),height:Math.round(S),pixelRatio:E,smooth:w,contextSettings:m});if(g&&(A=t,A.__worldOpacity=0,t=p,C.bounds=O.bounds),O.save(),u&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(O,C),t.fill=e}else t.__render(O,C);if(O.restore(),A&&A.__updateWorldOpacity(),f){n=function(t){const{width:e,height:i}=t.view,{data:s}=t.context.getImageData(0,0,e,i);let n,o,r,a=0;for(let t=0;t<s.length;t+=4)0!==s[t+3]&&(n=a%e,o=(a-n)/e,r?ss(r,n,o):is(r={},n,o)),a++;const h=new v;return ns(r,h),h.scale(1/t.pixelRatio).ceil()}(O);const t=O,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:E};O=a.canvas(s),O.copyWorld(t,n,s)}b&&O.fillWorld(O.bounds,x||"#FFFFFF","destination-over"),_&&_(O);const P="canvas"===e?O:yield O.export(e,s);l({data:P,width:O.pixelWidth,height:O.pixelHeight,renderBounds:i,trimBounds:n})}))))):l({data:!1})}))))}};let rs;function as(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>as(t)))}const hs=e.prototype,ls=t.get("@leafer-ui/export");hs.export=function(t,e){const{quality:i,blob:s}=d.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):s?this.toBlob(t,i):this.toDataURL(t,i)},hs.toBlob=function(t,e){return new Promise((s=>{i.origin.canvasToBolb(this.view,t,e).then((t=>{s(t)})).catch((t=>{ls.error(t),s(null)}))}))},hs.toDataURL=function(t,e){return i.origin.canvasToDataURL(this.view,t,e)},hs.saveAs=function(t,e){return new Promise((s=>{i.origin.canvasSaveAs(this.view,t,e).then((()=>{s(!0)})).catch((t=>{ls.error(t),s(!1)}))}))},Object.assign(N,ts),Object.assign(Y,es),Object.assign(X,jt),Object.assign(j,xe),Object.assign(G,ze),Object.assign(H,He),Object.assign(U,os),Object.assign(a,{interaction:(t,e,i,s)=>new kt(t,e,i,s),hitCanvas:(t,e)=>new K(t,e),hitCanvasManager:()=>new z}),J();export{kt as Interaction,ut as Layouter,K as LeaferCanvas,gt as Renderer,Bt as Selector,tt as Watcher,J as useCanvas};
1
+ import{Debug as t,LeaferCanvasBase as e,Platform as i,DataHelper as s,canvasSizeAttrs as n,ResizeEvent as o,canvasPatch as r,Creator as a,LeaferImage as h,defineKey as l,FileHelper as d,LeafList as c,RenderEvent as u,ChildEvent as p,WatchEvent as g,PropertyEvent as f,LeafHelper as _,BranchHelper as w,Bounds as v,LeafBoundsHelper as m,LeafLevelList as y,LayoutEvent as x,Run as b,ImageManager as B,BoundsHelper as L,Answer as E,MathHelper as R,MatrixHelper as k,AlignHelper as T,ImageEvent as M,AroundHelper as S,PointHelper as C,Direction4 as A,TwoPointBoundsHelper as O,TaskProcessor as P,Matrix as W}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionHelper as D,InteractionBase as I,Cursor as F,HitCanvasManager as z}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as j,ColorConvert as Y,PaintGradient as G,Export as U,Group as V,TextConvert as N,Paint as X,Effect as H}from"@leafer-ui/draw";const q=t.get("LeaferCanvas");class K 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 q.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),q.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:r}=this.autoBounds.getBoundsFrom(t),a={width:o,height:r,pixelRatio:i.devicePixelRatio};if(!this.isSameSize(a)){const{style:t}=e;t.marginLeft=s+"px",t.marginTop=n+"px",this.emitResize(a)}}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()}}}r(CanvasRenderingContext2D.prototype),r(Path2D.prototype);const{mineType:Q,fileType:$}=d;function J(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(Q(e),i),canvasToBolb:(t,e,i)=>new Promise((s=>t.toBlob(s,Q(e),i))),canvasSaveAs:(t,e,s)=>{const n=t.toDataURL(Q($(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=a.canvas(),i.conicGradientSupport=!!i.canvas.context.createConicGradient}Object.assign(a,{canvas:(t,e)=>new K(t,e),image:t=>new h(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:Z}=navigator;Z.indexOf("Firefox")>-1?(i.conicGradientRotate90=!0,i.intWheelDeltaY=!0,i.syncDomFont=!0):Z.indexOf("Safari")>-1&&-1===Z.indexOf("Chrome")&&(i.fullImageShadow=!0),Z.indexOf("Windows")>-1?(i.os="Windows",i.intWheelDeltaY=!0):Z.indexOf("Mac")>-1?i.os="Mac":Z.indexOf("Linux")>-1&&(i.os="Linux");class tt{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 g(g.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_(f.CHANGE,this.__onAttrChange,this),t.on_([p.ADD,p.REMOVE],this.__onChildEvent,this),t.on_(g.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:et,updateBounds:it,updateAllWorldOpacity:st}=_,{pushAllChildBranch:nt,pushAllParent:ot}=w;const{worldBounds:rt}=m,at={x:0,y:0,width:1e5,height:1e5};class ht{constructor(t){this.updatedBounds=new v,this.beforeBounds=new v,this.afterBounds=new v,t instanceof Array&&(t=new c(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,rt)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(at):this.afterBounds.setListWithFn(t,rt),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:lt,updateAllChange:dt}=_,ct=t.get("Layouter");class ut{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new y,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){ct.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ct.warn("layouting"):this.times>3?ct.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(g.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:r}=x,a=this.getBlocks(s);a.forEach((t=>t.setBefore())),i.emitEvent(new x(n,a,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?(et(t,!0),e.add(t),t.isBranch&&nt(t,e),ot(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),ot(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||it(s[t])}it(i)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&st(t),e.stateStyleChanged&&setTimeout((()=>e.stateStyleChanged&&t.updateState())),t.__updateChange()}))}(s),this.extraBlock&&a.push(this.extraBlock),a.forEach((t=>t.setAfter())),i.emitEvent(new x(o,a,this.times)),i.emitEvent(new x(r,a,this.times)),this.addBlocks(a),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)),ut.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){lt(t,!0),t.isBranch?w.updateBounds(t):_.updateBounds(t),dt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new ht([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new ht(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(x.REQUEST,this.layout,this),t.on_(x.AGAIN,this.layoutAgain,this),t.on_(g.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const pt=t.get("Renderer");class gt{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 v,pt.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,pt.error(t)}pt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return pt.warn("rendering");if(this.times>3)return pt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new v,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 pt.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),r=new v(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,r),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 v;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 v(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 v(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||pt.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)}}const{hitRadiusPoint:ft}=L;class _t{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,o=i.target||this.target;this.exclude=i.exclude||null,this.point={x:t.x,y:t.y,radiusX:e,radiusY:e},this.findList=new c(i.findList),i.findList||this.hitBranch(o);const{list:r}=this.findList,a=this.getBestMatchLeaf(r,i.bottomList,n),h=n?this.getPath(a):this.getHitablePath(a);return this.clear(),s?{path:h,target:a,throughPath:r.length?this.getThroughPath(r):h}:{path:h,target:a}}getBestMatchLeaf(t,e,i){if(t.length){let e;this.findList=new c;const{x:s,y:n}=this.point,o={x:s,y:n,radiusX:0,radiusY:0};for(let s=0,n=t.length;s<n;s++)if(e=t[s],(i||_.worldHittable(e))&&(this.hitChild(e,o),this.findList.length))return this.findList.list[0]}if(e)for(let t=0,i=e.length;t<i;t++)if(this.hitChild(e[t].target,this.point,e[t].proxy),this.findList.length)return this.findList.list[0];return t[0]}getPath(t){const e=new c;for(;t;)e.add(t),t=t.parent;return this.target&&e.add(this.target),e}getHitablePath(t){const e=this.getPath(t&&t.hittable?t:null);let i,s=new c;for(let t=e.list.length-1;t>-1&&(i=e.list[t],i.__.hittable)&&(s.addAt(i,0),i.__.hitChildren);t--);return s}getThroughPath(t){const e=new c,i=[];for(let e=t.length-1;e>-1;e--)i.push(this.getPath(t[e]));let s,n,o;for(let t=0,r=i.length;t<r;t++){s=i[t],n=i[t+1];for(let t=0,i=s.length;t<i&&(o=s.list[t],!n||!n.has(o));t++)e.add(o)}return e}hitBranch(t){this.eachFind(t.children,t.__onlyHitMask)}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.__.mask||(s=!!i.__.hitRadius||ft(i.__world,n),i.isBranch?(s||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&this.hitChild(i,n)):s&&this.hitChild(i,n))}hitChild(t,e,i){if((!this.exclude||!this.exclude.has(t))&&t.__hitWorld(e)){const{parent:s}=t;if(s&&s.__hasMask&&!t.__.mask&&!s.children.some((t=>t.__.mask&&t.__hitWorld(e))))return;this.findList.add(i||t)}}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}const{Yes:wt,NoAndSkip:vt,YesAndSkip:mt}=E,yt={},xt={},bt={};class Bt{constructor(t,e){this.config={},this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.target&&(this.idMap[e]=t),1):0,innerId:(t,e)=>t.innerId===e?(this.target&&(this.innerIdMap[e]=t),1):0,className:(t,e)=>t.className===e?1:0,tag:(t,e)=>t.__tag===e?1:0,tags:(t,e)=>e[t.__tag]?1:0},this.target=t,e&&(this.config=s.default(e,this.config)),this.picker=new _t(t,this),t&&this.__listenEvents()}getBy(t,e,i,n){switch(typeof t){case"number":const o=this.getByInnerId(t,e);return i?o:o?[o]:[];case"string":switch(t[0]){case"#":yt.id=t.substring(1),t=yt;break;case".":xt.className=t.substring(1),t=xt;break;default:bt.tag=t,t=bt}case"object":if(void 0!==t.id){const s=this.getById(t.id,e);return i?s:s?[s]:[]}if(t.tag){const{tag:n}=t,o=n instanceof Array;return this.getByMethod(o?this.methods.tags:this.methods.tag,e,i,o?s.toMap(n):n)}return this.getByMethod(this.methods.className,e,i,t.className);case"function":return this.getByMethod(t,e,i,n)}}getByPoint(t,e,s){return"node"===i.name&&this.target&&this.target.emit(x.CHECK_UPDATE),this.picker.getByPoint(t,e,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&&_.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,o;for(let r=0,a=t.length;r<a;r++){if(n=t[r],o=e(n,s),o===wt||o===mt){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&o<vt&&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_(p.REMOVE,this.__onRemoveChild,this),this.target.on_(f.CHANGE,this.__checkIdChange,this)]}__removeListenEvents(){this.target.off_(this.__eventIds),this.__eventIds.length=0}destroy(){this.__eventIds.length&&(this.__removeListenEvents(),this.picker.destroy(),this.findLeaf=null,this.innerIdMap={},this.idMap={})}}Object.assign(a,{watcher:(t,e)=>new tt(t,e),layouter:(t,e)=>new ut(t,e),renderer:(t,e,i)=>new gt(t,e,i),selector:(t,e)=>new Bt(t,e)}),i.layout=ut.fullLayout;const Lt={convert(t,e){const i=D.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=D.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=Lt.getTouch(t),s=D.getBase(t);return Object.assign(Object.assign({},s),{x:e.x,y:e.y,width:1,height:1,pointerType:"touch",multiTouch:t.touches.length>1,pressure:i.force})},getTouch:t=>t.targetTouches[0]||t.changedTouches[0]},Et={convert(t){const e=D.getBase(t);return Object.assign(Object.assign({},e),{code:t.code,key:t.key})}},{pathCanDrag:Rt}=D;class kt extends I{__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={}}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(Et.convert(t))}onKeyUp(t){this.keyUp(Et.convert(t))}onContextMenu(t){this.config.pointer.preventDefaultMenu&&t.preventDefault(),this.menu(Lt.convert(t,this.getLocal(t)))}onScroll(){this.canvas.updateClientBounds()}onPointerDown(t){this.preventDefaultPointer(t),this.config.pointer.touch||this.useMultiTouch||(this.usePointer||(this.usePointer=!0),this.pointerDown(Lt.convert(t,this.getLocal(t))))}onPointerMove(t){this.config.pointer.touch||this.useMultiTouch||this.preventWindowPointer(t)||(this.usePointer||(this.usePointer=!0),this.pointerMove(Lt.convert(t,this.getLocal(t,!0))))}onPointerUp(t){this.downData&&this.preventDefaultPointer(t),this.config.pointer.touch||this.useMultiTouch||this.preventWindowPointer(t)||this.pointerUp(Lt.convert(t,this.getLocal(t)))}onPointerCancel(){this.useMultiTouch||this.pointerCancel()}onMouseDown(t){this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.pointerDown(Lt.convertMouse(t,this.getLocal(t)))}onMouseMove(t){this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerMove(Lt.convertMouse(t,this.getLocal(t,!0)))}onMouseUp(t){this.downData&&this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerUp(Lt.convertMouse(t,this.getLocal(t)))}onMouseCancel(){this.useTouch||this.usePointer||this.pointerCancel()}onTouchStart(t){const e=Lt.getTouch(t),i=this.getLocal(e,!0),{preventDefault:s}=this.config.touch;(!0===s||"auto"===s&&Rt(this.findPath(i)))&&t.preventDefault(),this.multiTouchStart(t),this.usePointer||(this.touchTimer&&(window.clearTimeout(this.touchTimer),this.touchTimer=0),this.useTouch=!0,this.pointerDown(Lt.convertTouch(t,i)))}onTouchMove(t){if(this.multiTouchMove(t),this.usePointer||this.preventWindowPointer(t))return;const e=Lt.getTouch(t);this.pointerMove(Lt.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=Lt.getTouch(t);this.pointerUp(Lt.convertTouch(t,this.getLocal(e)))}onTouchCancel(){this.usePointer||this.pointerCancel()}multiTouchStart(t){this.useMultiTouch=t.touches.length>1,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(D.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),this.wheel(Object.assign(Object.assign(Object.assign({},D.getBase(t)),this.getLocal(t)),{deltaX:t.deltaX,deltaY:t.deltaY}))}onGesturestart(t){this.useMultiTouch||(this.preventDefaultWheel(t),this.lastGestureScale=1,this.lastGestureRotation=0)}onGesturechange(t){if(this.useMultiTouch)return;this.preventDefaultWheel(t);const e=D.getBase(t);Object.assign(e,this.getLocal(t));const i=t.scale/this.lastGestureScale,s=(t.rotation-this.lastGestureRotation)/Math.PI*180*(R.within(this.config.wheel.rotateSpeed,0,1)/4+.1);this.zoom(Object.assign(Object.assign({},e),{scale:i*i})),this.rotate(Object.assign(Object.assign({},e),{rotation:s})),this.lastGestureScale=t.scale,this.lastGestureRotation=t.rotation}onGestureend(t){this.useMultiTouch||(this.preventDefaultWheel(t),this.transformEnd())}setCursor(t){super.setCursor(t);const e=[];this.eachCursor(t,e),"object"==typeof e[e.length-1]&&e.push("default"),this.canvas.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&&F.get(t);s&&i<2?this.eachCursor(s,e,i):e.push(t)}}destroy(){this.view&&(super.destroy(),this.view=null,this.touches=null)}}function Tt(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 Mt(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?At(t,!0,e,i):Ct(e,i);break;case"inside":St("inside",t,n,e,i);break;case"outside":St("outside",t,n,e,i)}}function St(t,e,i,s,n){const{__strokeWidth:o,__font:r}=s.__,a=n.getSameCanvas(!0,!0);a.setStroke(i?void 0:e,2*o,s.__),a.font=r,i?At(e,!0,s,a):Ct(s,a),a.blendMode="outside"===t?"destination-out":"destination-in",Tt(s,a),a.blendMode="normal",s.__worldFlipped?n.copyWorldByReset(a,s.__nowWorld):n.copyWorldToInner(a,s.__nowWorld,s.__layout.renderBounds),a.recycle(s.__nowWorld)}function Ct(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 At(t,e,i,s){let n;for(let o=0,r=t.length;o<r;o++)n=t[o],n.image&&j.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?Ct(i,s):s.stroke(),s.restoreBlendMode()):e?Ct(i,s):s.stroke())}function Ot(t,e){t.__.dashPattern&&(e.beginPath(),t.__drawPathByData(e,t.__.__pathForArrow),e.dashPattern=null,e.stroke())}const{getSpread:Pt,getOuterOf:Wt,getByMove:Dt,getIntersectData:It}=L;let Ft;function zt(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:Y.string(r,a)};case"image":return j.image(i,t,e,s,!Ft||!Ft[e.url]);case"linear":return G.linearGradient(e,s);case"radial":return G.radialGradient(e,s);case"angular":return G.conicGradient(e,s);default:return void 0!==e.r?{type:"solid",style:Y.string(e)}:void 0}}const jt={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),Ft=j.recycleImage(t,i);for(let i,n=0,r=o.length;n<r;n++)i=zt(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?Tt(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 r=0,a=t.length;r<a;r++)s=t[r],s.image&&j.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?Tt(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?Tt(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?Tt(e,i):n?i.fill(n):i.fill())},fillText:Tt,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:r}=s;if(n)if(r)Mt(t,e,i);else switch(o){case"center":i.setStroke(t,n,s),i.stroke(),s.__useArrow&&Ot(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:r}=s;if(n)if(r)Mt(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),At(t,!1,e,i),s.__useArrow&&Ot(e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),At(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,r=i.getSameCanvas(!0,!0);e.__drawRenderPath(r),r.setStroke(void 0,2*n,s),At(t,!1,e,r),s.windingRule?r.clip(s.windingRule):r.clip(),r.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(r,e.__nowWorld):i.copyWorldToInner(r,e.__nowWorld,o),r.recycle(e.__nowWorld)}},strokeText:Mt,drawTextStroke:Ct,shape:function(t,e,i){const s=e.getSameCanvas(),n=t.__nowWorld;let o,r,a,h,{scaleX:l,scaleY:d}=n;if(l<0&&(l=-l),d<0&&(d=-d),e.bounds.includes(n))h=s,o=a=n;else{const{renderShapeSpread:s}=t.__layout,c=It(s?Pt(e.bounds,l===d?s*l:[s*d,s*l]):e.bounds,n);r=e.bounds.getFitMatrix(c);let{a:u,d:p}=r;if(r.a<1&&(h=e.getSameCanvas(),t.__renderShape(h,i),l*=u,d*=p),a=Wt(n,r),o=Dt(a,-r.e,-r.f),i.matrix){const{matrix:t}=i;r.multiply(t),u*=t.scaleX,p*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:r.withScale(u,p)})}return t.__renderShape(s,i),{canvas:s,matrix:r,bounds:o,worldCanvas:h,shapeBounds:a,scaleX:l,scaleY:d}}};let Yt={};const{get:Gt,rotateOfOuter:Ut,translate:Vt,scaleOfOuter:Nt,scale:Xt,rotate:Ht}=k;function qt(t,e,i,s,n,o,r){const a=Gt();Vt(a,e.x+i,e.y+s),Xt(a,n,o),r&&Ut(a,{x:e.x+e.width/2,y:e.y+e.height/2},r),t.transform=a}function Kt(t,e,i,s,n,o,r){const a=Gt();Vt(a,e.x+i,e.y+s),n&&Xt(a,n,o),r&&Ht(a,r),t.transform=a}function Qt(t,e,i,s,n,o,r,a,h,l){const d=Gt();if(h)if("center"===l)Ut(d,{x:i/2,y:s/2},h);else switch(Ht(d,h),h){case 90:Vt(d,s,0);break;case 180:Vt(d,i,s);break;case 270:Vt(d,0,i)}Yt.x=e.x+n,Yt.y=e.y+o,Vt(d,Yt.x,Yt.y),r&&Nt(d,Yt,r,a),t.transform=d}const{get:$t,translate:Jt}=k,Zt=new v,te={},ee={};function ie(t,e,i,s){const{blendMode:n,sync:o}=i;n&&(t.blendMode=n),o&&(t.sync=o),t.data=se(i,s,e)}function se(t,e,i){let{width:s,height:n}=i;t.padding&&(e=Zt.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{opacity:o,mode:r,align:a,offset:h,scale:l,size:d,rotation:c,repeat:u}=t,p=e.width===s&&e.height===n,g={mode:r},f="center"!==a&&(c||0)%180==90,_=f?n:s,w=f?s:n;let v,m,y=0,x=0;if(r&&"cover"!==r&&"fit"!==r)(l||d)&&(R.getScaleData(l,d,i,ee),v=ee.scaleX,m=ee.scaleY);else if(!p||c){const t=e.width/_,i=e.height/w;v=m="fit"===r?Math.min(t,i):Math.max(t,i),y+=(e.width-s*v)/2,x+=(e.height-n*m)/2}if(a){const t={x:y,y:x,width:_,height:w};v&&(t.width*=v,t.height*=m),T.toPoint(a,t,e,te,!0),y+=te.x,x+=te.y}switch(h&&(y+=h.x,x+=h.y),r){case"stretch":p||(s=e.width,n=e.height);break;case"normal":case"clip":(y||x||v||c)&&Kt(g,e,y,x,v,m,c);break;case"repeat":(!p||v||c)&&Qt(g,e,s,n,y,x,v,m,c,a),u||(g.repeat="repeat");break;default:v&&qt(g,e,y,x,v,m,c)}return g.transform||(e.x||e.y)&&(g.transform=$t(),Jt(g.transform,e.x,e.y)),v&&"stretch"!==r&&(g.scaleX=v,g.scaleY=m),g.width=s,g.height=n,o&&(g.opacity=o),u&&(g.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),g}let ne,oe=new v;const{isSame:re}=L;function ae(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||ie(n,s,i,o),!0}function he(t,e){ce(t,M.LOAD,e)}function le(t,e){ce(t,M.LOADED,e)}function de(t,e,i){e.error=i,t.forceUpdate("surface"),ce(t,M.ERROR,e)}function ce(t,e,i){t.hasEvent(e)&&t.emitEvent(new M(e,i))}function ue(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:pe,scale:ge,copy:fe}=k,{ceil:_e,abs:we}=Math;function ve(t,e,s){let{scaleX:n,scaleY:o}=B.patternLocked?t.__world:t.__nowWorld;const r=n+"-"+o+"-"+s;if(e.patternId===r||t.destroyed)return!1;{n=we(n),o=we(o);const{image:t,data:a}=e;let h,l,{width:d,height:c,scaleX:u,scaleY:p,opacity:g,transform:f,repeat:_}=a;u&&(l=pe(),fe(l,f),ge(l,1/u,1/p),n*=u,o*=p),n*=s,o*=s,d*=n,c*=o;const w=d*c;if(!_&&w>i.image.maxCacheSize)return!1;let v=i.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;v>e&&(v=e)}w>v&&(h=Math.sqrt(w/v)),h&&(n/=h,o/=h,d/=h,c/=h),u&&(n/=u,o/=p),(f||1!==n||1!==o)&&(l||(l=pe(),f&&fe(l,f)),ge(l,1/n,1/o));const m=t.getCanvas(_e(d)||1,_e(c)||1,g),y=t.getPattern(m,_||i.origin.noRepeat||"no-repeat",l,e);return e.style=y,e.patternId=r,!0}}function me(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{abs:ye}=Math;const xe={image:function(t,e,i,s,n){let o,r;const a=B.get(i);return ne&&i===ne.paint&&re(s,ne.boxBounds)?o=ne.leafPaint:(o={type:i.type,image:a},ne=a.use>1?{leafPaint:o,paint:i,boxBounds:oe.set(s)}:null),(n||a.loading)&&(r={image:a,attrName:e,attrValue:i}),a.ready?(ae(t,e,i,a,o,s),n&&(he(t,r),le(t,r))):a.error?n&&de(t,r,a.error):(n&&(ue(t,!0),he(t,r)),o.loadId=a.load((()=>{ue(t,!1),t.destroyed||(ae(t,e,i,a,o,s)&&(a.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),le(t,r)),o.loadId=null}),(e=>{ue(t,!1),de(t,r,e),o.loadId=null}))),o},checkImage:function(t,e,s,n){const{scaleX:o,scaleY:r}=B.patternLocked?t.__world:t.__nowWorld,{pixelRatio:a}=e;if(!s.data||s.patternId===o+"-"+r+"-"+a&&!U.running)return!1;{const{data:h}=s;if(n)if(h.repeat)n=!1;else{let{width:t,height:e}=h;t*=ye(o)*a,e*=ye(r)*a,h.scaleX&&(t*=h.scaleX,e*=h.scaleY),n=t*e>i.image.maxCacheSize||U.running}return n?(e.save(),t.windingRule?e.clip(t.windingRule):e.clip(),s.blendMode&&(e.blendMode=s.blendMode),h.opacity&&(e.opacity*=h.opacity),h.transform&&e.transform(h.transform),e.drawImage(s.image.view,0,0,h.width,h.height),e.restore(),!0):(!s.style||s.sync||U.running?ve(t,s,a):s.patternTask||(s.patternTask=B.patternTasker.add((()=>me(this,void 0,void 0,(function*(){s.patternTask=null,e.bounds.hit(t.__nowWorld)&&ve(t,s,a),t.forceUpdate("surface")}))),300)),!1)}},createPattern:ve,recycleImage:function(t,e){const i=e["_"+t];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,B.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},createData:ie,getPatternData:se,fillOrFitMode:qt,clipMode:Kt,repeatMode:Qt},{toPoint:be}=S,Be={},Le={};function Ee(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),Y.string(s,i)):t.addColorStop(s.offset,Y.string(s.color,i))}}const{getAngle:Re,getDistance:ke}=C,{get:Te,rotateOfOuter:Me,scaleOfOuter:Se}=k,{toPoint:Ce}=S,Ae={},Oe={};function Pe(t,e,i,s,n){let o;const{width:r,height:a}=t;if(r!==a||s){const t=Re(e,i);o=Te(),n?(Se(o,e,r/a*(s||1),1),Me(o,e,t+90)):(Se(o,e,1,r/a*(s||1)),Me(o,e,t))}return o}const{getDistance:We}=C,{toPoint:De}=S,Ie={},Fe={};const ze={linearGradient:function(t,e){let{from:s,to:n,type:o,blendMode:r,opacity:a}=t;be(s||"top",e,Be),be(n||"bottom",e,Le);const h=i.canvas.createLinearGradient(Be.x,Be.y,Le.x,Le.y);Ee(h,t.stops,a);const l={type:o,style:h};return r&&(l.blendMode=r),l},radialGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;Ce(s||"center",e,Ae),Ce(n||"bottom",e,Oe);const l=i.canvas.createRadialGradient(Ae.x,Ae.y,0,Ae.x,Ae.y,ke(Ae,Oe));Ee(l,t.stops,r);const d={type:o,style:l},c=Pe(e,Ae,Oe,h,!0);return c&&(d.transform=c),a&&(d.blendMode=a),d},conicGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;De(s||"center",e,Ie),De(n||"bottom",e,Fe);const l=i.conicGradientSupport?i.canvas.createConicGradient(0,Ie.x,Ie.y):i.canvas.createRadialGradient(Ie.x,Ie.y,0,Ie.x,Ie.y,We(Ie,Fe));Ee(l,t.stops,r);const d={type:o,style:l},c=Pe(e,Ie,Fe,h||1,i.conicGradientRotate90);return c&&(d.transform=c),a&&(d.blendMode=a),d},getTransform:Pe},{copy:je,toOffsetOutBounds:Ye}=L,Ge={},Ue={};function Ve(t,e,s,n){const{bounds:o,shapeBounds:r}=n;if(i.fullImageShadow){if(je(Ge,t.bounds),Ge.x+=e.x-r.x,Ge.y+=e.y-r.y,s){const{matrix:t}=n;Ge.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),Ge.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),Ge.width*=s,Ge.height*=s}t.copyWorld(n.canvas,t.bounds,Ge)}else s&&(je(Ge,e),Ge.x-=e.width/2*(s-1),Ge.y-=e.height/2*(s-1),Ge.width*=s,Ge.height*=s),t.copyWorld(n.canvas,r,s?Ge:e)}const{toOffsetOutBounds:Ne}=L,Xe={};const He={shadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:r}=t,{shadow:a}=t.__,{worldCanvas:h,bounds:l,shapeBounds:d,scaleX:c,scaleY:u}=i,p=e.getSameCanvas(),g=a.length-1;Ye(l,Ue),a.forEach(((a,f)=>{p.setWorldShadow(Ue.offsetX+a.x*c,Ue.offsetY+a.y*u,a.blur*c,a.color),n=a.spread?1+2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,Ve(p,Ue,n,i),s=l,a.box&&(p.restore(),p.save(),h&&(p.copyWorld(p,l,o,"copy"),s=o),h?p.copyWorld(h,o,o,"destination-out"):p.copyWorld(i.canvas,d,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(p,s,o,a.blendMode):e.copyWorldToInner(p,s,r.renderBounds,a.blendMode),g&&f<g&&p.clearWorld(s,!0)})),p.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:r}=t,{innerShadow:a}=t.__,{worldCanvas:h,bounds:l,shapeBounds:d,scaleX:c,scaleY:u}=i,p=e.getSameCanvas(),g=a.length-1;Ne(l,Xe),a.forEach(((a,f)=>{p.save(),p.setWorldShadow(Xe.offsetX+a.x*c,Xe.offsetY+a.y*u,a.blur*c),n=a.spread?1-2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,Ve(p,Xe,n,i),p.restore(),h?(p.copyWorld(p,l,o,"copy"),p.copyWorld(h,o,o,"source-out"),s=o):(p.copyWorld(i.canvas,d,l,"source-out"),s=l),p.fillWorld(s,a.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(p,s,o,a.blendMode):e.copyWorldToInner(p,s,r.renderBounds,a.blendMode),g&&f<g&&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:qe}=m;function Ke(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),$e(t,e,i,1)}(t,i,s,n);break;case"opacity-path":$e(t,i,s,o);break;case"path":i.restore()}}function Qe(t){return t.getSameCanvas(!1,!0)}function $e(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}V.prototype.__renderMask=function(t,e){let i,s,n,o,r,a;const{children:h}=this;for(let l=0,d=h.length;l<d;l++)i=h[l],a=i.__.mask,a&&(r&&(Ke(this,r,t,n,s,o),s=n=null),"path"===a||"clipping-path"===a?(i.opacity<1?(r="opacity-path",o=i.opacity,n||(n=Qe(t))):(r="path",t.save()),i.__clip(n||t,e)):(r="grayscale"===a?"grayscale":"alpha",s||(s=Qe(t)),n||(n=Qe(t)),i.__render(s,e)),"clipping"!==a&&"clipping-path"!==a)||qe(i,e)||i.__render(n||t,e);Ke(this,r,t,n,s,o)};const Je=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Ze=Je+"_#~&*+\\=|≮≯≈≠=…",ti=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 ei(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const ii=ei("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),si=ei("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),ni=ei(Je),oi=ei(Ze),ri=ei("- —/~|┆·");var ai;!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"}(ai||(ai={}));const{Letter:hi,Single:li,Before:di,After:ci,Symbol:ui,Break:pi}=ai;function gi(t){return ii[t]?hi:ri[t]?pi:si[t]?di:ni[t]?ci:oi[t]?ui:ti.test(t)?li:hi}const fi={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 _i(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:wi}=fi,{Letter:vi,Single:mi,Before:yi,After:xi,Symbol:bi,Break:Bi}=ai;let Li,Ei,Ri,ki,Ti,Mi,Si,Ci,Ai,Oi,Pi,Wi,Di,Ii,Fi,zi,ji,Yi=[];function Gi(t,e){Ai&&!Ci&&(Ci=Ai),Li.data.push({char:t,width:e}),Ri+=e}function Ui(){ki+=Ri,Li.width=Ri,Ei.words.push(Li),Li={data:[]},Ri=0}function Vi(){Ii&&(Fi.paraNumber++,Ei.paraStart=!0,Ii=!1),Ai&&(Ei.startCharSize=Ci,Ei.endCharSize=Ai,Ci=0),Ei.width=ki,zi.width?wi(Ei):ji&&Ni(),Yi.push(Ei),Ei={words:[]},ki=0}function Ni(){ki>(Fi.maxWidth||0)&&(Fi.maxWidth=ki)}const Xi=0,Hi=1,qi=2;const{top:Ki,right:Qi,bottom:$i,left:Ji}=A;function Zi(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 ts={getDrawData:function(t,e){"string"!=typeof t&&(t=String(t));let s=0,n=0,o=e.__getInput("width")||0,r=e.__getInput("height")||0;const{textDecoration:a,__font:h,__padding:l}=e;l&&(o?(s=l[Ji],o-=l[Qi]+l[Ji]):e.autoSizeAlign||(s=l[Ji]),r?(n=l[Ki],r-=l[Ki]+l[$i]):e.autoSizeAlign||(n=l[Ki]));const d={bounds:{x:s,y:n,width:o,height:r},rows:[],paraNumber:0,font:i.canvas.font=h};return function(t,e,s){Fi=t,Yi=t.rows,zi=t.bounds,ji=!zi.width&&!s.autoSizeAlign;const{__letterSpacing:n,paraIndent:o,textCase:r}=s,{canvas:a}=i,{width:h,height:l}=zi;if(h||l||n||"none"!==r){const t="none"!==s.textWrap,i="break"===s.textWrap;Ii=!0,Pi=null,Ci=Si=Ai=Ri=ki=0,Li={data:[]},Ei={words:[]};for(let s=0,l=e.length;s<l;s++)Mi=e[s],"\n"===Mi?(Ri&&Ui(),Ei.paraEnd=!0,Vi(),Ii=!0):(Oi=gi(Mi),Oi===vi&&"none"!==r&&(Mi=_i(Mi,r,!Ri)),Si=a.measureText(Mi).width,n&&(n<0&&(Ai=Si),Si+=n),Wi=Oi===mi&&(Pi===mi||Pi===vi)||Pi===mi&&Oi!==xi,Di=!(Oi!==yi&&Oi!==mi||Pi!==bi&&Pi!==xi),Ti=Ii&&o?h-o:h,t&&h&&ki+Ri+Si>Ti&&(i?(Ri&&Ui(),ki&&Vi()):(Di||(Di=Oi===vi&&Pi==xi),Wi||Di||Oi===Bi||Oi===yi||Oi===mi||Ri+Si>Ti?(Ri&&Ui(),ki&&Vi()):ki&&Vi()))," "===Mi&&!0!==Ii&&ki+Ri===0||(Oi===Bi?(" "===Mi&&Ri&&Ui(),Gi(Mi,Si),Ui()):Wi||Di?(Ri&&Ui(),Gi(Mi,Si)):Gi(Mi,Si)),Pi=Oi);Ri&&Ui(),ki&&Vi(),Yi.length>0&&(Yi[Yi.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{Fi.paraNumber++,ki=a.measureText(t).width,Yi.push({x:o||0,text:t,width:ki,paraStart:!0}),ji&&Ni()}))}(d,t,e),l&&function(t,e,i,s,n){if(!s&&i.autoSizeAlign)switch(i.textAlign){case"left":Zi(e,"x",t[Ji]);break;case"right":Zi(e,"x",-t[Qi])}if(!n&&i.autoSizeAlign)switch(i.verticalAlign){case"top":Zi(e,"y",t[Ki]);break;case"bottom":Zi(e,"y",-t[$i])}}(l,d,e,o,r),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:r,__clipText:a,textAlign:h,verticalAlign:l,paraSpacing:d,autoSizeAlign:c}=e;let{x:u,y:p,width:g,height:f}=s,_=n*i.length+(d?d*(t.paraNumber-1):0),w=o;if(a&&_>f)_=Math.max(f,n),t.overflow=i.length;else if(f||c)switch(l){case"middle":p+=(f-_)/2;break;case"bottom":p+=f-_}w+=p;let v,m,y,x=g||c?g:t.maxWidth;for(let o=0,l=i.length;o<l;o++){if(v=i[o],v.x=u,v.width<g||v.width>g&&!a)switch(h){case"center":v.x+=(x-v.width)/2;break;case"right":v.x+=x-v.width}v.paraStart&&d&&o>0&&(w+=d),v.y=w,w+=n,t.overflow>o&&w>_&&(v.isOverflow=!0,t.overflow=o+1),m=v.x,y=v.width,r<0&&(v.width<0?(y=-v.width+e.fontSize+r,m-=y,y+=e.fontSize):y-=r),m<s.x&&(s.x=m),y>s.width&&(s.width=y),a&&g&&g<y&&(v.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=p,s.height=_}(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?Xi:l>.01?Hi:qi,t.isOverflow&&!a&&(t.textMode=!0),c===qi?(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=>{c===Hi?(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),(t.isOverflow||" "!==u.char)&&t.data.push(u)):h=function(t,e,i,s){return t.forEach((t=>{(s||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,h,t.data,t.isOverflow),!t.paraEnd&&l&&(h+=l,t.width+=l)}))),t.words=null)}))}(d,e,o),d.overflow&&function(t,e,s,n){if(!n)return;const{rows:o,overflow:r}=t;let{textOverflow:a}=e;if(o.splice(r),a&&"show"!==a){let t,h;"hide"===a?a="":"ellipsis"===a&&(a="...");const l=a?i.canvas.measureText(a).width:0,d=s+n-l;("none"===e.textWrap?o:[o[r-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],h=t.x+t.width,!(s===i&&h<d));s--){if(h<d&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:a,x:h}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(d,e,s,o),"none"!==a&&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}};const es={string:function(t,e){const i="number"==typeof e&&1!==e;if("string"==typeof t){if(!i||!Y.object)return t;t=Y.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+")"}},{setPoint:is,addPoint:ss,toBounds:ns}=O;const os={export(t,e,s){this.running=!0;const n=d.fileType(e),o=e.includes(".");return s=d.getExportOptions(s),function(t){rs||(rs=new P);return new Promise((e=>{rs.add((()=>me(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((r=>new Promise((h=>{const l=t=>{r(t),h(),this.running=!1},{toURL:c}=i,{download:u}=i.origin;if("json"===n)return o&&u(c(JSON.stringify(t.toJSON(s.json)),"text"),e),l({data:!!o||t.toJSON(s.json)});if("svg"===n)return o&&u(c(t.toSVG(),"svg"),e),l({data:!!o||t.toSVG()});const{leafer:p}=t;p?(as(t),p.waitViewCompleted((()=>me(this,void 0,void 0,(function*(){let i,n,o=1,r=1;const{worldTransform:h,isLeafer:c,isFrame:u}=t,{slice:g,trim:f,onCanvas:_}=s,w=void 0===s.smooth?p.config.smooth:s.smooth,m=s.contextSettings||p.config.contextSettings,y=s.screenshot||t.isApp,x=c&&y&&void 0===s.fill?t.fill:s.fill,b=d.isOpaqueImage(e)||x,B=new W;if(y)i=!0===y?c?p.canvas.bounds:t.worldRenderBounds:y;else{let e=s.relative||(c?"inner":"local");switch(o=h.scaleX,r=h.scaleY,e){case"inner":B.set(h);break;case"local":B.set(h).divide(t.localTransform),o/=t.scaleX,r/=t.scaleY;break;case"world":o=1,r=1;break;case"page":e=t.leafer;default:B.set(h).divide(t.getTransform(e));const i=e.worldTransform;o/=o/i.scaleX,r/=r/i.scaleY}i=t.getBounds("render",e)}const L={scaleX:1,scaleY:1};R.getScaleData(s.scale,s.size,i,L);let E=s.pixelRatio||1;t.isApp&&(L.scaleX*=E,L.scaleY*=E,E=t.app.pixelRatio);const{x:k,y:T,width:M,height:S}=new v(i).scale(L.scaleX,L.scaleY),C={matrix:B.scale(1/L.scaleX,1/L.scaleY).invert().translate(-k,-T).withScale(1/o*L.scaleX,1/r*L.scaleY)};let A,O=a.canvas({width:Math.round(M),height:Math.round(S),pixelRatio:E,smooth:w,contextSettings:m});if(g&&(A=t,A.__worldOpacity=0,t=p,C.bounds=O.bounds),O.save(),u&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(O,C),t.fill=e}else t.__render(O,C);if(O.restore(),A&&A.__updateWorldOpacity(),f){n=function(t){const{width:e,height:i}=t.view,{data:s}=t.context.getImageData(0,0,e,i);let n,o,r,a=0;for(let t=0;t<s.length;t+=4)0!==s[t+3]&&(n=a%e,o=(a-n)/e,r?ss(r,n,o):is(r={},n,o)),a++;const h=new v;return ns(r,h),h.scale(1/t.pixelRatio).ceil()}(O);const t=O,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:E};O=a.canvas(s),O.copyWorld(t,n,s)}b&&O.fillWorld(O.bounds,x||"#FFFFFF","destination-over"),_&&_(O);const P="canvas"===e?O:yield O.export(e,s);l({data:P,width:O.pixelWidth,height:O.pixelHeight,renderBounds:i,trimBounds:n})}))))):l({data:!1})}))))}};let rs;function as(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>as(t)))}const hs=e.prototype,ls=t.get("@leafer-ui/export");hs.export=function(t,e){const{quality:i,blob:s}=d.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):s?this.toBlob(t,i):this.toDataURL(t,i)},hs.toBlob=function(t,e){return new Promise((s=>{i.origin.canvasToBolb(this.view,t,e).then((t=>{s(t)})).catch((t=>{ls.error(t),s(null)}))}))},hs.toDataURL=function(t,e){return i.origin.canvasToDataURL(this.view,t,e)},hs.saveAs=function(t,e){return new Promise((s=>{i.origin.canvasSaveAs(this.view,t,e).then((()=>{s(!0)})).catch((t=>{ls.error(t),s(!1)}))}))},Object.assign(N,ts),Object.assign(Y,es),Object.assign(X,jt),Object.assign(j,xe),Object.assign(G,ze),Object.assign(H,He),Object.assign(U,os),Object.assign(a,{interaction:(t,e,i,s)=>new kt(t,e,i,s),hitCanvas:(t,e)=>new K(t,e),hitCanvasManager:()=>new z}),J();export{kt as Interaction,ut as Layouter,K as LeaferCanvas,gt as Renderer,Bt as Selector,tt as Watcher,J as useCanvas};
package/dist/web.js CHANGED
@@ -2050,11 +2050,11 @@ var LeaferUI = (function (exports) {
2050
2050
  toBlob(_type, _quality) { return undefined; }
2051
2051
  toDataURL(_type, _quality) { return undefined; }
2052
2052
  saveAs(_filename, _quality) { return undefined; }
2053
- resize(size) {
2053
+ resize(size, safeResize = true) {
2054
2054
  if (this.isSameSize(size))
2055
2055
  return;
2056
2056
  let takeCanvas;
2057
- if (this.context && !this.unreal && this.width) {
2057
+ if (this.context && !this.unreal && safeResize && this.width) {
2058
2058
  takeCanvas = this.getSameCanvas();
2059
2059
  takeCanvas.copyWorld(this);
2060
2060
  }
@@ -4256,18 +4256,21 @@ var LeaferUI = (function (exports) {
4256
4256
  L.setTransform(t, matrix$1, resize);
4257
4257
  },
4258
4258
  setTransform(t, transform, resize) {
4259
- const layout = getLayout(transform, t.origin && L.getInnerOrigin(t, t.origin), t.around && L.getInnerOrigin(t, t.around));
4259
+ const data = t.__, originPoint = data.origin && L.getInnerOrigin(t, data.origin);
4260
+ const layout = getLayout(transform, originPoint, data.around && L.getInnerOrigin(t, data.around));
4260
4261
  if (resize) {
4261
- const scaleX = layout.scaleX / t.scaleX;
4262
- const scaleY = layout.scaleY / t.scaleY;
4263
- delete layout.scaleX;
4264
- delete layout.scaleY;
4262
+ const scaleX = layout.scaleX / t.scaleX, scaleY = layout.scaleY / t.scaleY;
4263
+ delete layout.scaleX, delete layout.scaleY;
4264
+ if (originPoint) {
4265
+ BoundsHelper.scale(t.boxBounds, Math.abs(scaleX), Math.abs(scaleY));
4266
+ const changedPoint = L.getInnerOrigin(t, data.origin);
4267
+ PointHelper.move(layout, originPoint.x - changedPoint.x, originPoint.y - changedPoint.y);
4268
+ }
4265
4269
  t.set(layout);
4266
- t.scaleResize(scaleX, scaleY, resize !== true);
4270
+ t.scaleResize(scaleX, scaleY, false);
4267
4271
  }
4268
- else {
4272
+ else
4269
4273
  t.set(layout);
4270
- }
4271
4274
  },
4272
4275
  getFlipTransform(t, axis) {
4273
4276
  const m = getMatrixData();
@@ -4950,14 +4953,15 @@ var LeaferUI = (function (exports) {
4950
4953
  if (list) {
4951
4954
  let item;
4952
4955
  for (let i = 0, len = list.length; i < len; i++) {
4953
- item = list[i];
4954
- item.listener(event);
4955
- if (item.once) {
4956
- this.off(type, item.listener, capture);
4957
- i--, len--;
4956
+ if (item = list[i]) {
4957
+ item.listener(event);
4958
+ if (item.once) {
4959
+ this.off(type, item.listener, capture);
4960
+ i--, len--;
4961
+ }
4962
+ if (event && event.isStopNow)
4963
+ break;
4958
4964
  }
4959
- if (event && event.isStopNow)
4960
- break;
4961
4965
  }
4962
4966
  }
4963
4967
  this.syncEventer && this.syncEventer.emitEvent(event, capture);
@@ -6004,7 +6008,7 @@ var LeaferUI = (function (exports) {
6004
6008
  }
6005
6009
  }
6006
6010
 
6007
- const version = "1.2.1";
6011
+ const version = "1.2.2";
6008
6012
 
6009
6013
  const debug$6 = Debug.get('LeaferCanvas');
6010
6014
  class LeaferCanvas extends LeaferCanvasBase {
@@ -6096,7 +6100,8 @@ var LeaferUI = (function (exports) {
6096
6100
  this.view.height = Math.ceil(height * pixelRatio);
6097
6101
  }
6098
6102
  updateClientBounds() {
6099
- this.clientBounds = this.view.getBoundingClientRect();
6103
+ if (this.view.parentElement)
6104
+ this.clientBounds = this.view.getBoundingClientRect();
6100
6105
  }
6101
6106
  startAutoLayout(autoBounds, listener) {
6102
6107
  this.resizeListener = listener;
@@ -8199,6 +8204,8 @@ var LeaferUI = (function (exports) {
8199
8204
  this.requestRender();
8200
8205
  }
8201
8206
  }
8207
+ else
8208
+ this.requestRender();
8202
8209
  }
8203
8210
  __checkViewCompleted(emit = true) {
8204
8211
  this.nextRender(() => {
@@ -8764,10 +8771,10 @@ var LeaferUI = (function (exports) {
8764
8771
  __updateSize() {
8765
8772
  const { canvas } = this;
8766
8773
  if (canvas) {
8767
- const { smooth } = this.__;
8774
+ const { smooth, safeResize } = this.__;
8775
+ canvas.resize(this.__, safeResize);
8768
8776
  if (canvas.smooth !== smooth)
8769
8777
  canvas.smooth = smooth;
8770
- canvas.resize(this.__);
8771
8778
  }
8772
8779
  }
8773
8780
  destroy() {
@@ -8793,6 +8800,9 @@ var LeaferUI = (function (exports) {
8793
8800
  __decorate([
8794
8801
  resizeType(true)
8795
8802
  ], exports.Canvas.prototype, "smooth", void 0);
8803
+ __decorate([
8804
+ dataType(false)
8805
+ ], exports.Canvas.prototype, "safeResize", void 0);
8796
8806
  __decorate([
8797
8807
  resizeType()
8798
8808
  ], exports.Canvas.prototype, "contextSettings", void 0);