@leafer-ui/worker 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { LeaferCanvasBase, Platform, canvasPatch, Creator, LeaferImage, FileHelper, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, ResizeEvent, BoundsHelper, Answer, MatrixHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
1
+ import { LeaferCanvasBase, Platform, canvasPatch, Creator, LeaferImage, defineKey, FileHelper, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, ResizeEvent, BoundsHelper, Answer, MatrixHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
2
2
  export * from '@leafer/core';
3
3
  export { LeaferImage } from '@leafer/core';
4
4
  import { InteractionBase, HitCanvasManager } from '@leafer-ui/core';
@@ -72,7 +72,7 @@ function useCanvas(_canvasType, _power) {
72
72
  Platform.name = 'web';
73
73
  Platform.isWorker = true;
74
74
  Platform.requestRender = function (render) { requestAnimationFrame(render); };
75
- Platform.devicePixelRatio = 1;
75
+ defineKey(Platform, 'devicePixelRatio', { get() { return 1; } });
76
76
  const { userAgent } = navigator;
77
77
  if (userAgent.indexOf("Firefox") > -1) {
78
78
  Platform.conicGradientRotate90 = true;
@@ -568,14 +568,14 @@ class Renderer {
568
568
  if (Debug.showRepaint)
569
569
  this.canvas.strokeWorld(bounds, 'red');
570
570
  this.target.__render(this.canvas, options);
571
- this.renderBounds = realBounds || bounds;
571
+ this.renderBounds = realBounds = realBounds || bounds;
572
572
  this.renderOptions = options;
573
- this.totalBounds.isEmpty() ? this.totalBounds = this.renderBounds : this.totalBounds.add(this.renderBounds);
573
+ this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
574
574
  if (Debug.showHitView)
575
575
  this.renderHitView(options);
576
576
  if (Debug.showBoundsView)
577
577
  this.renderBoundsView(options);
578
- this.canvas.updateRender();
578
+ this.canvas.updateRender(realBounds);
579
579
  }
580
580
  renderHitView(_options) { }
581
581
  renderBoundsView(_options) { }
@@ -1560,7 +1560,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1560
1560
  const { abs } = Math;
1561
1561
  function checkImage(ui, canvas, paint, allowPaint) {
1562
1562
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1563
- if (!paint.data || paint.patternId === scaleX + '-' + scaleY) {
1563
+ if (!paint.data || (paint.patternId === scaleX + '-' + scaleY && !Export.running)) {
1564
1564
  return false;
1565
1565
  }
1566
1566
  else {
@@ -2538,7 +2538,10 @@ const ExportModule = {
2538
2538
  const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
2539
2539
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
2540
2540
  const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
2541
+ let sliceLeaf;
2541
2542
  if (slice) {
2543
+ sliceLeaf = leaf;
2544
+ sliceLeaf.__worldOpacity = 0;
2542
2545
  leaf = leafer;
2543
2546
  renderOptions.bounds = canvas.bounds;
2544
2547
  }
@@ -2553,6 +2556,8 @@ const ExportModule = {
2553
2556
  leaf.__render(canvas, renderOptions);
2554
2557
  }
2555
2558
  canvas.restore();
2559
+ if (sliceLeaf)
2560
+ sliceLeaf.__updateWorldOpacity();
2556
2561
  if (trim) {
2557
2562
  trimBounds = getTrimBounds(canvas);
2558
2563
  const old = canvas, { width, height } = trimBounds;
@@ -1 +1 @@
1
- import{LeaferCanvasBase as t,Platform as e,canvasPatch as i,Creator as n,LeaferImage as s,FileHelper as o,LeafList as a,DataHelper as r,RenderEvent as d,ChildEvent as h,WatchEvent as l,PropertyEvent as c,LeafHelper as u,BranchHelper as f,Bounds as g,LeafBoundsHelper as _,Debug as p,LeafLevelList as w,LayoutEvent as y,Run as m,ImageManager as v,AnimateEvent as x,ResizeEvent as b,BoundsHelper as B,Answer as R,MatrixHelper as k,AlignHelper as E,ImageEvent as L,AroundHelper as S,PointHelper as M,Direction4 as A,TwoPointBoundsHelper as W,TaskProcessor as C,Matrix as O}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionBase as T,HitCanvasManager as I}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as P,ColorConvert as D,PaintGradient as F,Export as N,Group as Y,TextConvert as G,Paint as U,Effect as j}from"@leafer-ui/draw";class H extends t{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this;this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i),this.clientBounds=this.bounds}}i(OffscreenCanvasRenderingContext2D.prototype),i(Path2D.prototype);const{mineType:X}=o;function V(t,i){e.origin={createCanvas:(t,e)=>new OffscreenCanvas(t,e),canvasToDataURL:(t,e,i)=>new Promise(((n,s)=>{t.convertToBlob({type:X(e),quality:i}).then((t=>{var e=new FileReader;e.onload=t=>n(t.target.result),e.onerror=t=>s(t),e.readAsDataURL(t)})).catch((t=>{s(t)}))})),canvasToBolb:(t,e,i)=>t.convertToBlob({type:X(e),quality:i}),canvasSaveAs:(t,e,i)=>new Promise((t=>t())),download(t,e){},loadImage:t=>new Promise(((i,n)=>{let s=new XMLHttpRequest;s.open("GET",e.image.getRealURL(t),!0),s.responseType="blob",s.onload=()=>{createImageBitmap(s.response).then((t=>{i(t)})).catch((t=>{n(t)}))},s.onerror=t=>n(t),s.send()}))},e.canvas=n.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient}Object.assign(n,{canvas:(t,e)=>new H(t,e),image:t=>new s(t)}),e.name="web",e.isWorker=!0,e.requestRender=function(t){requestAnimationFrame(t)},e.devicePixelRatio=1;const{userAgent:q}=navigator;q.indexOf("Firefox")>-1?(e.conicGradientRotate90=!0,e.intWheelDeltaY=!0):q.indexOf("Safari")>-1&&-1===q.indexOf("Chrome")&&(e.fullImageShadow=!0),q.indexOf("Windows")>-1?(e.os="Windows",e.intWheelDeltaY=!0):q.indexOf("Mac")>-1?e.os="Mac":q.indexOf("Linux")>-1&&(e.os="Linux");class z{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new a;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 a,this.target=t,e&&(this.config=r.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(d.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===h.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 l(l.DATA,{updatedList:this.updatedList})),this.__updatedList=new a,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(c.CHANGE,this.__onAttrChange,this),t.on_([h.ADD,h.REMOVE],this.__onChildEvent,this),t.on_(l.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:Q,updateBounds:J,updateAllWorldOpacity:Z}=u,{pushAllChildBranch:K,pushAllParent:$}=f;const{worldBounds:tt}=_,et={x:0,y:0,width:1e5,height:1e5};class it{constructor(t){this.updatedBounds=new g,this.beforeBounds=new g,this.afterBounds=new g,t instanceof Array&&(t=new a(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,tt)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(et):this.afterBounds.setListWithFn(t,tt),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:nt,updateAllChange:st}=u,ot=p.get("Layouter");class at{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new w,this.target=t,e&&(this.config=r.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(y.START),this.layoutOnce(),t.emitEvent(new y(y.END,this.layoutedBlocks,this.times))}catch(t){ot.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ot.warn("layouting"):this.times>3?ot.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(l.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=m.start("PartLayout"),{target:i,__updatedList:n}=this,{BEFORE:s,LAYOUT:o,AFTER:a}=y,r=this.getBlocks(n);r.forEach((t=>t.setBefore())),i.emitEvent(new y(s,r,this.times)),this.extraBlock=null,n.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(Q(t,!0),e.add(t),t.isBranch&&K(t,e),$(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),$(t,e)))}))}(n,this.__levelList),function(t){let e,i,n;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(i=e[t],i.isBranch&&i.__tempNumber){n=i.children;for(let t=0,e=n.length;t<e;t++)n[t].isBranch||J(n[t])}J(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&Z(t),t.__updateChange()}))}(n),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new y(o,r,this.times)),i.emitEvent(new y(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,m.end(e)}fullLayout(){const t=m.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:n,AFTER:s}=y,o=this.getBlocks(new a(e));e.emitEvent(new y(i,o,this.times)),at.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new y(n,o,this.times)),e.emitEvent(new y(s,o,this.times)),this.addBlocks(o),m.end(t)}static fullLayout(t){nt(t,!0),t.isBranch?f.updateBounds(t):u.updateBounds(t),st(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new it([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new it(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_(y.REQUEST,this.layout,this),t.on_(y.AGAIN,this.layoutAgain,this),t.on_(l.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const rt=p.get("Renderer");class dt{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=r.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(y.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new g,rt.log(e.innerName,"---\x3e");try{this.emitRender(d.START),this.renderOnce(t),this.emitRender(d.END,this.totalBounds),v.clearRecycled()}catch(t){this.rendering=!1,rt.error(t)}rt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return rt.warn("rendering");if(this.times>3)return rt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new g,this.renderOptions={},t)this.emitRender(d.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(d.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(d.RENDER,this.renderBounds,this.renderOptions),this.emitRender(d.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 rt.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=m.start("PartRender"),{canvas:i}=this,n=t.getIntersect(i.bounds),s=t.includes(this.target.__world),o=new g(n);i.save(),s&&!p.showRepaint?i.clear():(n.spread(10+1/this.canvas.pixelRatio).ceil(),i.clearWorld(n,!0),i.clipWorld(n,!0)),this.__render(n,s,o),i.restore(),m.end(e)}fullRender(){const t=m.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),m.end(t)}__render(t,e,i){const n=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),p.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,n),this.renderBounds=i||t,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),p.showHitView&&this.renderHitView(n),p.showBoundsView&&this.renderBoundsView(n),this.canvas.updateRender()}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new g;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.target.emit(x.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(d.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new g(0,0,e,i).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new g(0,0,1,1)),this.changed=!0}}__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||rt.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 d(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(d.REQUEST,this.update,this),t.on_(y.END,this.__onLayoutEnd,this),t.on_(d.AGAIN,this.renderAgain,this),t.on_(b.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}const{hitRadiusPoint:ht}=B;class lt{constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,i){e||(e=0),i||(i={});const n=i.through||!1,s=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 a(i.findList),i.findList||this.hitBranch(o);const{list:r}=this.findList,d=this.getBestMatchLeaf(r,i.bottomList,s),h=s?this.getPath(d):this.getHitablePath(d);return this.clear(),n?{path:h,target:d,throughPath:r.length?this.getThroughPath(r):h}:{path:h,target:d}}getBestMatchLeaf(t,e,i){if(t.length){let e;this.findList=new a;const{x:n,y:s}=this.point,o={x:n,y:s,radiusX:0,radiusY:0};for(let n=0,s=t.length;n<s;n++)if(e=t[n],(i||u.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 a;for(;t;)e.add(t),t=t.parent;return e.add(this.target),e}getHitablePath(t){const e=this.getPath(t&&t.hittable?t:null);let i,n=new a;for(let t=e.list.length-1;t>-1&&(i=e.list[t],i.__.hittable)&&(n.addAt(i,0),i.__.hitChildren);t--);return n}getThroughPath(t){const e=new a,i=[];for(let e=t.length-1;e>-1;e--)i.push(this.getPath(t[e]));let n,s,o;for(let t=0,a=i.length;t<a;t++){n=i[t],s=i[t+1];for(let t=0,i=n.length;t<i&&(o=n.list[t],!s||!s.has(o));t++)e.add(o)}return e}hitBranch(t){this.eachFind(t.children,t.__onlyHitMask)}eachFind(t,e){let i,n;const{point:s}=this;for(let o=t.length-1;o>-1;o--)i=t[o],!i.__.visible||e&&!i.__.mask||(n=!!i.__.hitRadius||ht(i.__world,s),i.isBranch?(n||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&!this.findList.length&&this.hitChild(i,s)):n&&this.hitChild(i,s))}hitChild(t,e,i){if((!this.exclude||!this.exclude.has(t))&&t.__hitWorld(e)){const{parent:n}=t;if(n&&n.__hasMask&&!t.__.mask&&!n.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:ct,NoAndSkip:ut,YesAndSkip:ft}=R,gt={},_t={},pt={};class wt{constructor(t,e){this.config={},this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.idMap[e]=t,1):0,innerId:(t,e)=>t.innerId===e?(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=r.default(e,this.config)),this.picker=new lt(t,this),this.__listenEvents()}getBy(t,e,i,n){switch(typeof t){case"number":const s=this.getByInnerId(t,e);return i?s:s?[s]:[];case"string":switch(t[0]){case"#":gt.id=t.substring(1),t=gt;break;case".":_t.className=t.substring(1),t=_t;break;default:pt.tag=t,t=pt}case"object":if(void 0!==t.id){const n=this.getById(t.id,e);return i?n:n?[n]:[]}if(t.tag){const{tag:n}=t,s=n instanceof Array;return this.getByMethod(s?this.methods.tags:this.methods.tag,e,i,s?r.toMap(n):n)}return this.getByMethod(this.methods.className,e,i,t.className);case"function":return this.getByMethod(t,e,i,n)}}getByPoint(t,i,n){return"node"===e.name&&this.target.emit(y.CHECK_UPDATE),this.picker.getByPoint(t,i,n)}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&&u.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,n){const s=i?null:[];return this.eachFind(this.toChildren(e),t,s,n),s||this.findLeaf}eachFind(t,e,i,n){let s,o;for(let a=0,r=t.length;a<r;a++){if(s=t[a],o=e(s,n),o===ct||o===ft){if(!i)return void(this.findLeaf=s);i.push(s)}s.isBranch&&o<ut&&this.eachFind(s.children,e,i,n)}}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_(h.REMOVE,this.__onRemoveChild,this),this.target.on_(c.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={})}}function yt(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),s&&e.fillRect(i.x,i.y+s,i.width,o)}function mt(t,e,i){const{strokeAlign:n}=e.__,s="string"!=typeof t;switch(n){case"center":i.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?bt(t,!0,e,i):xt(e,i);break;case"inside":vt("inside",t,s,e,i);break;case"outside":vt("outside",t,s,e,i)}}function vt(t,e,i,n,s){const{__strokeWidth:o,__font:a}=n.__,r=s.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,n.__),r.font=a,i?bt(e,!0,n,r):xt(n,r),r.blendMode="outside"===t?"destination-out":"destination-in",yt(n,r),r.blendMode="normal",n.__worldFlipped?s.copyWorldByReset(r,n.__nowWorld):s.copyWorldToInner(r,n.__nowWorld,n.__layout.renderBounds),r.recycle(n.__nowWorld)}function xt(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),s&&e.strokeRect(i.x,i.y+s,i.width,o)}function bt(t,e,i,n){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&P.checkImage(i,n,s,!1)||s.style&&(n.strokeStyle=s.style,s.blendMode?(n.saveBlendMode(s.blendMode),e?xt(i,n):n.stroke(),n.restoreBlendMode()):e?xt(i,n):n.stroke())}Object.assign(n,{watcher:(t,e)=>new z(t,e),layouter:(t,e)=>new at(t,e),renderer:(t,e,i)=>new dt(t,e,i),selector:(t,e)=>new wt(t,e)}),e.layout=at.fullLayout;const{getSpread:Bt,getOuterOf:Rt,getByMove:kt,getIntersectData:Et}=B;let Lt;function St(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:n}=i.__layout;switch(e.type){case"solid":let{type:s,blendMode:o,color:a,opacity:r}=e;return{type:s,blendMode:o,style:D.string(a,r)};case"image":return P.image(i,t,e,n,!Lt||!Lt[e.url]);case"linear":return F.linearGradient(e,n);case"radial":return F.radialGradient(e,n);case"angular":return F.conicGradient(e,n);default:return void 0!==e.r?{type:"solid",style:D.string(e)}:void 0}}const Mt={compute:function(t,e){const i=e.__,n=[];let s,o=i.__input[t];o instanceof Array||(o=[o]),Lt=P.recycleImage(t,i);for(let i,s=0,a=o.length;s<a;s++)i=St(t,o[s],e),i&&n.push(i);i["_"+t]=n.length?n:void 0,n.length&&n[0].image&&(s=n[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=s:i.__pixelStroke=s},fill:function(t,e,i){i.fillStyle=t,e.__.__font?yt(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let n;const{windingRule:s,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)n=t[a],n.image&&P.checkImage(e,i,n,!o)||n.style&&(i.fillStyle=n.style,n.transform?(i.save(),i.transform(n.transform),n.blendMode&&(i.blendMode=n.blendMode),o?yt(e,i):s?i.fill(s):i.fill(),i.restore()):n.blendMode?(i.saveBlendMode(n.blendMode),o?yt(e,i):s?i.fill(s):i.fill(),i.restoreBlendMode()):o?yt(e,i):s?i.fill(s):i.fill())},fillText:yt,stroke:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)mt(t,e,i);else switch(o){case"center":i.setStroke(t,s,n),i.stroke();break;case"inside":i.save(),i.setStroke(t,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*s,n),e.__drawRenderPath(o),o.stroke(),n.windingRule?o.clip(n.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?i.copyWorldByReset(o,e.__nowWorld):i.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)mt(t,e,i);else switch(o){case"center":i.setStroke(void 0,s,n),bt(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),bt(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*s,n),bt(t,!1,e,a),n.windingRule?a.clip(n.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:mt,drawTextStroke:xt,shape:function(t,e,i){const n=e.getSameCanvas(),s=t.__nowWorld;let o,a,r,d,{scaleX:h,scaleY:l}=s;if(h<0&&(h=-h),l<0&&(l=-l),e.bounds.includes(s))d=n,o=r=s;else{const{renderShapeSpread:n}=t.__layout,c=Et(n?Bt(e.bounds,h===l?n*h:[n*l,n*h]):e.bounds,s);a=e.bounds.getFitMatrix(c);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),h*=u,l*=f),r=Rt(s,a),o=kt(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,f)})}return t.__renderShape(n,i),{canvas:n,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:h,scaleY:l}}};let At={};const{get:Wt,rotateOfOuter:Ct,translate:Ot,scaleOfOuter:Tt,scale:It,rotate:Pt}=k;function Dt(t,e,i,n,s,o,a){const r=Wt();Ot(r,e.x+i,e.y+n),It(r,s,o),a&&Ct(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Ft(t,e,i,n,s,o,a){const r=Wt();Ot(r,e.x+i,e.y+n),s&&It(r,s,o),a&&Pt(r,a),t.transform=r}function Nt(t,e,i,n,s,o,a,r,d,h){const l=Wt();if(d)if("center"===h)Ct(l,{x:i/2,y:n/2},d);else switch(Pt(l,d),d){case 90:Ot(l,n,0);break;case 180:Ot(l,i,n);break;case 270:Ot(l,0,i)}At.x=e.x+s,At.y=e.y+o,Ot(l,At.x,At.y),a&&Tt(l,At,a,r),t.transform=l}const{get:Yt,translate:Gt}=k,Ut=new g,jt={};function Ht(t,e,i,n){const{blendMode:s}=i;s&&(t.blendMode=s),t.data=Xt(i,n,e)}function Xt(t,e,i){let{width:n,height:s}=i;t.padding&&(e=Ut.set(e).shrink(t.padding));const{opacity:o,mode:a,align:r,offset:d,scale:h,size:l,rotation:c,repeat:u}=t,f=e.width===n&&e.height===s,g={mode:a},_="center"!==r&&(c||0)%180==90,p=_?s:n,w=_?n:s;let y,m,v=0,x=0;if(a&&"cover"!==a&&"fit"!==a)l?(y=("number"==typeof l?l:l.width)/n,m=("number"==typeof l?l:l.height)/s):h&&(y="number"==typeof h?h:h.x,m="number"==typeof h?h:h.y);else if(!f||c){const t=e.width/p,i=e.height/w;y=m="fit"===a?Math.min(t,i):Math.max(t,i),v+=(e.width-n*y)/2,x+=(e.height-s*m)/2}if(r){const t={x:v,y:x,width:p,height:w};y&&(t.width*=y,t.height*=m),E.toPoint(r,t,e,jt,!0),v+=jt.x,x+=jt.y}switch(d&&(v+=d.x,x+=d.y),a){case"strench":f||(n=e.width,s=e.height);break;case"normal":case"clip":(v||x||y||c)&&Ft(g,e,v,x,y,m,c);break;case"repeat":(!f||y||c)&&Nt(g,e,n,s,v,x,y,m,c,r),u||(g.repeat="repeat");break;default:y&&Dt(g,e,v,x,y,m,c)}return g.transform||(e.x||e.y)&&(g.transform=Yt(),Gt(g.transform,e.x,e.y)),y&&"strench"!==a&&(g.scaleX=y,g.scaleY=m),g.width=n,g.height=s,o&&(g.opacity=o),u&&(g.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),g}let Vt,qt=new g;const{isSame:zt}=B;function Qt(t,e,i,n,s,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=n.width/e.pixelRatio,e.__naturalHeight=n.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return s.data||Ht(s,n,i,o),!0}function Jt(t,e){$t(t,L.LOAD,e)}function Zt(t,e){$t(t,L.LOADED,e)}function Kt(t,e,i){e.error=i,t.forceUpdate("surface"),$t(t,L.ERROR,e)}function $t(t,e,i){t.hasEvent(e)&&t.emitEvent(new L(e,i))}function te(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:ee,scale:ie,copy:ne}=k,{ceil:se,abs:oe}=Math;function ae(t,i,n){let{scaleX:s,scaleY:o}=v.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o;if(i.patternId===a||t.destroyed)return!1;{s=oe(s),o=oe(o);const{image:t,data:r}=i;let d,h,{width:l,height:c,scaleX:u,scaleY:f,opacity:g,transform:_,repeat:p}=r;u&&(h=ee(),ne(h,_),ie(h,1/u,1/f),s*=u,o*=f),s*=n,o*=n,l*=s,c*=o;const w=l*c;if(!p&&w>e.image.maxCacheSize)return!1;let y=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(s/=d,o/=d,l/=d,c/=d),u&&(s/=u,o/=f),(_||1!==s||1!==o)&&(h||(h=ee(),_&&ne(h,_)),ie(h,1/s,1/o));const m=t.getCanvas(se(l)||1,se(c)||1,g),v=t.getPattern(m,p||e.origin.noRepeat||"no-repeat",h,i);return i.style=v,i.patternId=a,!0}}function re(t,e,i,n){return new(i||(i=Promise))((function(s,o){function a(t){try{d(n.next(t))}catch(t){o(t)}}function r(t){try{d(n.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}d((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:de}=Math;const he={image:function(t,e,i,n,s){let o,a;const r=v.get(i);return Vt&&i===Vt.paint&&zt(n,Vt.boxBounds)?o=Vt.leafPaint:(o={type:i.type,image:r},Vt=r.use>1?{leafPaint:o,paint:i,boxBounds:qt.set(n)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(Qt(t,e,i,r,o,n),s&&(Jt(t,a),Zt(t,a))):r.error?s&&Kt(t,a,r.error):(te(t,!0),s&&Jt(t,a),o.loadId=r.load((()=>{te(t,!1),t.destroyed||(Qt(t,e,i,r,o,n)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Zt(t,a)),o.loadId=null}),(e=>{te(t,!1),Kt(t,a,e),o.loadId=null}))),o},checkImage:function(t,i,n,s){const{scaleX:o,scaleY:a}=v.patternLocked?t.__world:t.__nowWorld;if(n.data&&n.patternId!==o+"-"+a){const{data:r}=n;if(s)if(r.repeat)s=!1;else{let{width:t,height:n}=r;t*=de(o)*i.pixelRatio,n*=de(a)*i.pixelRatio,r.scaleX&&(t*=r.scaleX,n*=r.scaleY),s=t*n>e.image.maxCacheSize||N.running}return s?(i.save(),i.clip(),n.blendMode&&(i.blendMode=n.blendMode),r.opacity&&(i.opacity*=r.opacity),r.transform&&i.transform(r.transform),i.drawImage(n.image.view,0,0,r.width,r.height),i.restore(),!0):(!n.style||N.running?ae(t,n,i.pixelRatio):n.patternTask||(n.patternTask=v.patternTasker.add((()=>re(this,void 0,void 0,(function*(){n.patternTask=null,i.bounds.hit(t.__nowWorld)&&ae(t,n,i.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},createPattern:ae,recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let n,s,o,a;for(let r=0,d=i.length;r<d;r++)n=i[r].image,a=n&&n.url,a&&(s||(s={}),s[a]=!0,v.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),n.unload(i[r].loadId,!o.some((t=>t.url===a)))));return s}return null},createData:Ht,getPatternData:Xt,fillOrFitMode:Dt,clipMode:Ft,repeatMode:Nt},{toPoint:le}=S,ce={},ue={};function fe(t,e,i){let n;for(let s=0,o=e.length;s<o;s++)n=e[s],"string"==typeof n?t.addColorStop(s/(o-1),D.string(n,i)):t.addColorStop(n.offset,D.string(n.color,i))}const{getAngle:ge,getDistance:_e}=M,{get:pe,rotateOfOuter:we,scaleOfOuter:ye}=k,{toPoint:me}=S,ve={},xe={};function be(t,e,i,n,s){let o;const{width:a,height:r}=t;if(a!==r||n){const t=ge(e,i);o=pe(),s?(ye(o,e,a/r*(n||1),1),we(o,e,t+90)):(ye(o,e,1,a/r*(n||1)),we(o,e,t))}return o}const{getDistance:Be}=M,{toPoint:Re}=S,ke={},Ee={};const Le={linearGradient:function(t,i){let{from:n,to:s,type:o,blendMode:a,opacity:r}=t;le(n||"top",i,ce),le(s||"bottom",i,ue);const d=e.canvas.createLinearGradient(ce.x,ce.y,ue.x,ue.y);fe(d,t.stops,r);const h={type:o,style:d};return a&&(h.blendMode=a),h},radialGradient:function(t,i){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;me(n||"center",i,ve),me(s||"bottom",i,xe);const h=e.canvas.createRadialGradient(ve.x,ve.y,0,ve.x,ve.y,_e(ve,xe));fe(h,t.stops,a);const l={type:o,style:h},c=be(i,ve,xe,d,!0);return c&&(l.transform=c),r&&(l.blendMode=r),l},conicGradient:function(t,i){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;Re(n||"center",i,ke),Re(s||"bottom",i,Ee);const h=e.conicGradientSupport?e.canvas.createConicGradient(0,ke.x,ke.y):e.canvas.createRadialGradient(ke.x,ke.y,0,ke.x,ke.y,Be(ke,Ee));fe(h,t.stops,a);const l={type:o,style:h},c=be(i,ke,Ee,d||1,e.conicGradientRotate90);return c&&(l.transform=c),r&&(l.blendMode=r),l},getTransform:be},{copy:Se,toOffsetOutBounds:Me}=B,Ae={},We={};function Ce(t,i,n,s){const{bounds:o,shapeBounds:a}=s;if(e.fullImageShadow){if(Se(Ae,t.bounds),Ae.x+=i.x-a.x,Ae.y+=i.y-a.y,n){const{matrix:t}=s;Ae.x-=(o.x+(t?t.e:0)+o.width/2)*(n-1),Ae.y-=(o.y+(t?t.f:0)+o.height/2)*(n-1),Ae.width*=n,Ae.height*=n}t.copyWorld(s.canvas,t.bounds,Ae)}else n&&(Se(Ae,i),Ae.x-=i.width/2*(n-1),Ae.y-=i.height/2*(n-1),Ae.width*=n,Ae.height*=n),t.copyWorld(s.canvas,a,n?Ae:i)}const{toOffsetOutBounds:Oe}=B,Te={};const Ie={shadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:h,shapeBounds:l,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),g=r.length-1;Me(h,We),r.forEach(((r,_)=>{f.setWorldShadow(We.offsetX+r.x*c,We.offsetY+r.y*u,r.blur*c,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Ce(f,We,s,i),n=h,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,h,o,"copy"),n=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(i.canvas,l,h,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),g&&_<g&&f.clearWorld(n,!0)})),f.recycle(n)},innerShadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:h,shapeBounds:l,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),g=r.length-1;Oe(h,Te),r.forEach(((r,_)=>{f.save(),f.setWorldShadow(Te.offsetX+r.x*c,Te.offsetY+r.y*u,r.blur*c),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Ce(f,Te,s,i),f.restore(),d?(f.copyWorld(f,h,o,"copy"),f.copyWorld(d,o,o,"source-out"),n=o):(f.copyWorld(i.canvas,l,h,"source-out"),n=h),f.fillWorld(n,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),g&&_<g&&f.clearWorld(n,!0)})),f.recycle(n)},blur:function(t,e,i){const{blur:n}=t.__;i.setWorldBlur(n*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Pe}=_;function De(t,e,i,n,s,o){switch(e){case"alpha":!function(t,e,i,n){const s=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(n,s),n.recycle(s),Ne(t,e,i,1)}(t,i,n,s);break;case"opacity-path":Ne(t,i,n,o);break;case"path":i.restore()}}function Fe(t){return t.getSameCanvas(!1,!0)}function Ne(t,e,i,n){const s=t.__nowWorld;e.resetTransform(),e.opacity=n,e.copyWorld(i,s),i.recycle(s)}Y.prototype.__renderMask=function(t,e){let i,n,s,o,a;const{children:r}=this;for(let d=0,h=r.length;d<h;d++)i=r[d],i.__.mask&&(a&&(De(this,a,t,s,n,o),n=s=null),"path"===i.__.mask?(i.opacity<1?(a="opacity-path",o=i.opacity,s||(s=Fe(t))):(a="path",t.save()),i.__clip(s||t,e)):(a="alpha",n||(n=Fe(t)),s||(s=Fe(t)),i.__render(n,e)),"clipping"!==i.__.mask)||Pe(i,e)||i.__render(s||t,e);De(this,a,t,s,n,o)};const Ye=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Ge=Ye+"_#~&*+\\=|≮≯≈≠=…",Ue=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 je(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const He=je("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Xe=je("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Ve=je(Ye),qe=je(Ge),ze=je("- —/~|┆·");var Qe;!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"}(Qe||(Qe={}));const{Letter:Je,Single:Ze,Before:Ke,After:$e,Symbol:ti,Break:ei}=Qe;function ii(t){return He[t]?Je:ze[t]?ei:Xe[t]?Ke:Ve[t]?$e:qe[t]?ti:Ue.test(t)?Ze:Je}const ni={trimRight(t){const{words:e}=t;let i,n=0,s=e.length;for(let o=s-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)n++,t.width-=i.width;n&&e.splice(s-n,n)}};function si(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:oi}=ni,{Letter:ai,Single:ri,Before:di,After:hi,Symbol:li,Break:ci}=Qe;let ui,fi,gi,_i,pi,wi,yi,mi,vi,xi,bi,Bi,Ri,ki,Ei,Li,Si=[];function Mi(t,e){vi&&!mi&&(mi=vi),ui.data.push({char:t,width:e}),gi+=e}function Ai(){_i+=gi,ui.width=gi,fi.words.push(ui),ui={data:[]},gi=0}function Wi(){ki&&(Ei.paraNumber++,fi.paraStart=!0,ki=!1),vi&&(fi.startCharSize=mi,fi.endCharSize=vi,mi=0),fi.width=_i,Li.width&&oi(fi),Si.push(fi),fi={words:[]},_i=0}const Ci=0,Oi=1,Ti=2;const{top:Ii,right:Pi,bottom:Di,left:Fi}=A;function Ni(t,e,i){const{bounds:n,rows:s}=t;n[e]+=i;for(let t=0;t<s.length;t++)s[t][e]+=i}const Yi={getDrawData:function(t,i){"string"!=typeof t&&(t=String(t));let n=0,s=0,o=i.__getInput("width")||0,a=i.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:h}=i;h&&(o&&(n=h[Fi],o-=h[Pi]+h[Fi]),a&&(s=h[Ii],a-=h[Ii]+h[Di]));const l={bounds:{x:n,y:s,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,i,n){Ei=t,Si=t.rows,Li=t.bounds;const{__letterSpacing:s,paraIndent:o,textCase:a}=n,{canvas:r}=e,{width:d,height:h}=Li;if(d||h||s||"none"!==a){const t="none"!==n.textWrap,e="break"===n.textWrap;ki=!0,bi=null,mi=yi=vi=gi=_i=0,ui={data:[]},fi={words:[]};for(let n=0,h=i.length;n<h;n++)wi=i[n],"\n"===wi?(gi&&Ai(),fi.paraEnd=!0,Wi(),ki=!0):(xi=ii(wi),xi===ai&&"none"!==a&&(wi=si(wi,a,!gi)),yi=r.measureText(wi).width,s&&(s<0&&(vi=yi),yi+=s),Bi=xi===ri&&(bi===ri||bi===ai)||bi===ri&&xi!==hi,Ri=!(xi!==di&&xi!==ri||bi!==li&&bi!==hi),pi=ki&&o?d-o:d,t&&d&&_i+gi+yi>pi&&(e?(gi&&Ai(),_i&&Wi()):(Ri||(Ri=xi===ai&&bi==hi),Bi||Ri||xi===ci||xi===di||xi===ri||gi+yi>pi?(gi&&Ai(),_i&&Wi()):_i&&Wi()))," "===wi&&!0!==ki&&_i+gi===0||(xi===ci?(" "===wi&&gi&&Ai(),Mi(wi,yi),Ai()):Bi||Ri?(gi&&Ai(),Mi(wi,yi)):Mi(wi,yi)),bi=xi);gi&&Ai(),_i&&Wi(),Si.length>0&&(Si[Si.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{Ei.paraNumber++,Si.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(l,t,i),h&&function(t,e,i,n,s){if(!n)switch(i.textAlign){case"left":Ni(e,"x",t[Fi]);break;case"right":Ni(e,"x",-t[Pi])}if(!s)switch(i.verticalAlign){case"top":Ni(e,"y",t[Ii]);break;case"bottom":Ni(e,"y",-t[Di])}}(h,l,i,o,a),function(t,e){const{rows:i,bounds:n}=t,{__lineHeight:s,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:h,paraSpacing:l}=e;let c,u,f,{x:g,y:_,width:p,height:w}=n,y=s*i.length+(l?l*(t.paraNumber-1):0),m=o;if(r&&y>w)y=Math.max(w,s),t.overflow=i.length;else switch(h){case"middle":_+=(w-y)/2;break;case"bottom":_+=w-y}m+=_;for(let o=0,h=i.length;o<h;o++){if(c=i[o],c.x=g,c.width<p||c.width>p&&!r)switch(d){case"center":c.x+=(p-c.width)/2;break;case"right":c.x+=p-c.width}c.paraStart&&l&&o>0&&(m+=l),c.y=m,m+=s,t.overflow>o&&m>y&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,f=c.width,a<0&&(c.width<0?(f=-c.width+e.fontSize+a,u-=f,f+=e.fontSize):f-=a),u<n.x&&(n.x=u),f>n.width&&(n.width=f),r&&p&&p<f&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}n.y=_,n.height=y}(l,i),function(t,e,i,n){const{rows:s}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,h,l,c,u;s.forEach((t=>{t.words&&(l=a&&t.paraStart?a:0,h=i&&"justify"===o&&t.words.length>1?(i-t.width-l)/(t.words.length-1):0,c=r||t.isOverflow?Ci:h>.01?Oi:Ti,t.isOverflow&&!r&&(t.textMode=!0),c===Ti?(t.x+=l,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=l,d=t.x,t.data=[],t.words.forEach((e=>{c===Oi?(u={char:"",x:d},d=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,d,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,i,n){return t.forEach((t=>{(n||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&h&&(d+=h,t.width+=h)}))),t.words=null)}))}(l,i,o),l.overflow&&function(t,i,n,s){if(!s)return;const{rows:o,overflow:a}=t;let{textOverflow:r}=i;if(o.splice(a),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const h=r?e.canvas.measureText(r).width:0,l=n+s-h;("none"===i.textWrap?o:[o[a-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let n=i;n>-1&&(t=e.data[n],d=t.x+t.width,!(n===i&&d<l));n--){if(d<l&&" "!==t.char){e.data.splice(n+1),e.width-=t.width;break}e.width-=t.width}e.width+=h,e.data.push({char:r,x:d}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(l,i,n,o),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(l,i),l}};const Gi={string:function(t,e){if("string"==typeof t)return t;let i=void 0===t.a?1:t.a;e&&(i*=e);const n=t.r+","+t.g+","+t.b;return 1===i?"rgb("+n+")":"rgba("+n+","+i+")"}},{setPoint:Ui,addPoint:ji,toBounds:Hi}=W;const Xi={export(t,i,s){this.running=!0;const a=o.fileType(i);return s=o.getExportOptions(s),function(t){Vi||(Vi=new C);return new Promise((e=>{Vi.add((()=>re(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((r=>new Promise((d=>{const h=t=>{r(t),d(),this.running=!1},{toURL:l}=e,{download:c}=e.origin;if("json"===i)return h({data:t.toJSON(s.json)});if("json"===a)return c(l(JSON.stringify(t.toJSON(s.json)),"text"),i),h({data:!0});if("svg"===i)return h({data:t.toSVG()});if("svg"===a)return c(l(t.toSVG(),"svg"),i),h({data:!0});const{leafer:u}=t;u?(qi(t),u.waitViewCompleted((()=>re(this,void 0,void 0,(function*(){let e,a,r=1,d=1;const{worldTransform:l,isLeafer:c,isFrame:f}=t,{slice:_,trim:p,onCanvas:w}=s;let y=s.scale||1,m=s.pixelRatio||1;const v=void 0===s.smooth?u.config.smooth:s.smooth,x=s.contextSettings||u.config.contextSettings;t.isApp&&(y*=m,m=t.app.pixelRatio);const b=s.screenshot||t.isApp,B=c&&b&&void 0===s.fill?t.fill:s.fill,R=o.isOpaqueImage(i)||B,k=new O;if(b)e=!0===b?c?u.canvas.bounds:t.worldRenderBounds:b;else{let i=s.relative||(c?"inner":"local");switch(r=l.scaleX,d=l.scaleY,i){case"inner":k.set(l);break;case"local":k.set(l).divide(t.localTransform),r/=t.scaleX,d/=t.scaleY;break;case"world":r=1,d=1;break;case"page":i=t.leafer;default:k.set(l).divide(t.getTransform(i));const e=i.worldTransform;r/=r/e.scaleX,d/=d/e.scaleY}e=t.getBounds("render",i)}const{x:E,y:L,width:S,height:M}=new g(e).scale(y);let A=n.canvas({width:Math.round(S),height:Math.round(M),pixelRatio:m,smooth:v,contextSettings:x});const W={matrix:k.scale(1/y).invert().translate(-E,-L).withScale(1/r*y,1/d*y)};if(_&&(t=u,W.bounds=A.bounds),A.save(),f&&void 0!==B){const e=t.get("fill");t.fill="",t.__render(A,W),t.fill=e}else t.__render(A,W);if(A.restore(),p){a=function(t){const{width:e,height:i}=t.view,{data:n}=t.context.getImageData(0,0,e,i);let s,o,a,r=0;for(let t=0;t<n.length;t+=4)0!==n[t+3]&&(s=r%e,o=(r-s)/e,a?ji(a,s,o):Ui(a={},s,o)),r++;const d=new g;return Hi(a,d),d.scale(1/t.pixelRatio).ceil()}(A);const t=A,{width:e,height:i}=a,s={x:0,y:0,width:e,height:i,pixelRatio:m};A=n.canvas(s),A.copyWorld(t,a,s)}R&&A.fillWorld(A.bounds,B||"#FFFFFF","destination-over"),w&&w(A);const C="canvas"===i?A:yield A.export(i,s);h({data:C,width:A.pixelWidth,height:A.pixelHeight,renderBounds:e,trimBounds:a})}))))):h({data:!1})}))))}};let Vi;function qi(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>qi(t)))}const zi=t.prototype,Qi=p.get("@leafer-ui/export");zi.export=function(t,e){const{quality:i,blob:n}=o.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):n?this.toBlob(t,i):this.toDataURL(t,i)},zi.toBlob=function(t,i){return new Promise((n=>{e.origin.canvasToBolb(this.view,t,i).then((t=>{n(t)})).catch((t=>{Qi.error(t),n(null)}))}))},zi.toDataURL=function(t,i){return e.origin.canvasToDataURL(this.view,t,i)},zi.saveAs=function(t,i){return new Promise((n=>{e.origin.canvasSaveAs(this.view,t,i).then((()=>{n(!0)})).catch((t=>{Qi.error(t),n(!1)}))}))},Object.assign(G,Yi),Object.assign(D,Gi),Object.assign(U,Mt),Object.assign(P,he),Object.assign(F,Le),Object.assign(j,Ie),Object.assign(N,Xi),Object.assign(n,{interaction:(t,e,i,n)=>new T(t,e,i,n),hitCanvas:(t,e)=>new H(t,e),hitCanvasManager:()=>new I}),V();export{at as Layouter,H as LeaferCanvas,dt as Renderer,wt as Selector,z as Watcher,V as useCanvas};
1
+ import{LeaferCanvasBase as t,Platform as e,canvasPatch as i,Creator as n,LeaferImage as s,defineKey as o,FileHelper as a,LeafList as r,DataHelper as d,RenderEvent as h,ChildEvent as l,WatchEvent as c,PropertyEvent as u,LeafHelper as f,BranchHelper as g,Bounds as _,LeafBoundsHelper as p,Debug as w,LeafLevelList as y,LayoutEvent as m,Run as v,ImageManager as x,AnimateEvent as b,ResizeEvent as B,BoundsHelper as R,Answer as k,MatrixHelper as E,AlignHelper as L,ImageEvent as S,AroundHelper as M,PointHelper as A,Direction4 as O,TwoPointBoundsHelper as W,TaskProcessor as C,Matrix as T}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionBase as I,HitCanvasManager as P}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as D,ColorConvert as F,PaintGradient as N,Export as Y,Group as G,TextConvert as U,Paint as j,Effect as H}from"@leafer-ui/draw";class X extends t{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this;this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i),this.clientBounds=this.bounds}}i(OffscreenCanvasRenderingContext2D.prototype),i(Path2D.prototype);const{mineType:V}=a;function q(t,i){e.origin={createCanvas:(t,e)=>new OffscreenCanvas(t,e),canvasToDataURL:(t,e,i)=>new Promise(((n,s)=>{t.convertToBlob({type:V(e),quality:i}).then((t=>{var e=new FileReader;e.onload=t=>n(t.target.result),e.onerror=t=>s(t),e.readAsDataURL(t)})).catch((t=>{s(t)}))})),canvasToBolb:(t,e,i)=>t.convertToBlob({type:V(e),quality:i}),canvasSaveAs:(t,e,i)=>new Promise((t=>t())),download(t,e){},loadImage:t=>new Promise(((i,n)=>{let s=new XMLHttpRequest;s.open("GET",e.image.getRealURL(t),!0),s.responseType="blob",s.onload=()=>{createImageBitmap(s.response).then((t=>{i(t)})).catch((t=>{n(t)}))},s.onerror=t=>n(t),s.send()}))},e.canvas=n.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient}Object.assign(n,{canvas:(t,e)=>new X(t,e),image:t=>new s(t)}),e.name="web",e.isWorker=!0,e.requestRender=function(t){requestAnimationFrame(t)},o(e,"devicePixelRatio",{get:()=>1});const{userAgent:z}=navigator;z.indexOf("Firefox")>-1?(e.conicGradientRotate90=!0,e.intWheelDeltaY=!0):z.indexOf("Safari")>-1&&-1===z.indexOf("Chrome")&&(e.fullImageShadow=!0),z.indexOf("Windows")>-1?(e.os="Windows",e.intWheelDeltaY=!0):z.indexOf("Mac")>-1?e.os="Mac":z.indexOf("Linux")>-1&&(e.os="Linux");class Q{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new r;return this.__updatedList.list.forEach((e=>{e.leafer&&t.add(e)})),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new r,this.target=t,e&&(this.config=d.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(h.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===l.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 c(c.DATA,{updatedList:this.updatedList})),this.__updatedList=new r,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.CHANGE,this.__onAttrChange,this),t.on_([l.ADD,l.REMOVE],this.__onChildEvent,this),t.on_(c.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:J,updateBounds:Z,updateAllWorldOpacity:K}=f,{pushAllChildBranch:$,pushAllParent:tt}=g;const{worldBounds:et}=p,it={x:0,y:0,width:1e5,height:1e5};class nt{constructor(t){this.updatedBounds=new _,this.beforeBounds=new _,this.afterBounds=new _,t instanceof Array&&(t=new r(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,et)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(it):this.afterBounds.setListWithFn(t,et),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:st,updateAllChange:ot}=f,at=w.get("Layouter");class rt{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new y,this.target=t,e&&(this.config=d.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(m.START),this.layoutOnce(),t.emitEvent(new m(m.END,this.layoutedBlocks,this.times))}catch(t){at.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?at.warn("layouting"):this.times>3?at.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(c.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=v.start("PartLayout"),{target:i,__updatedList:n}=this,{BEFORE:s,LAYOUT:o,AFTER:a}=m,r=this.getBlocks(n);r.forEach((t=>t.setBefore())),i.emitEvent(new m(s,r,this.times)),this.extraBlock=null,n.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(J(t,!0),e.add(t),t.isBranch&&$(t,e),tt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),tt(t,e)))}))}(n,this.__levelList),function(t){let e,i,n;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(i=e[t],i.isBranch&&i.__tempNumber){n=i.children;for(let t=0,e=n.length;t<e;t++)n[t].isBranch||Z(n[t])}Z(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&K(t),t.__updateChange()}))}(n),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new m(o,r,this.times)),i.emitEvent(new m(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,v.end(e)}fullLayout(){const t=v.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:n,AFTER:s}=m,o=this.getBlocks(new r(e));e.emitEvent(new m(i,o,this.times)),rt.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new m(n,o,this.times)),e.emitEvent(new m(s,o,this.times)),this.addBlocks(o),v.end(t)}static fullLayout(t){st(t,!0),t.isBranch?g.updateBounds(t):f.updateBounds(t),ot(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new nt([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new nt(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(m.REQUEST,this.layout,this),t.on_(m.AGAIN,this.layoutAgain,this),t.on_(c.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const dt=w.get("Renderer");class ht{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,i&&(this.config=d.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(m.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new _,dt.log(e.innerName,"---\x3e");try{this.emitRender(h.START),this.renderOnce(t),this.emitRender(h.END,this.totalBounds),x.clearRecycled()}catch(t){this.rendering=!1,dt.error(t)}dt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return dt.warn("rendering");if(this.times>3)return dt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new _,this.renderOptions={},t)this.emitRender(h.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(h.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(h.RENDER,this.renderBounds,this.renderOptions),this.emitRender(h.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return dt.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=v.start("PartRender"),{canvas:i}=this,n=t.getIntersect(i.bounds),s=t.includes(this.target.__world),o=new _(n);i.save(),s&&!w.showRepaint?i.clear():(n.spread(10+1/this.canvas.pixelRatio).ceil(),i.clearWorld(n,!0),i.clipWorld(n,!0)),this.__render(n,s,o),i.restore(),v.end(e)}fullRender(){const t=v.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),v.end(t)}__render(t,e,i){const n=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),w.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,n),this.renderBounds=i=i||t,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=i:this.totalBounds.add(i),w.showHitView&&this.renderHitView(n),w.showBoundsView&&this.renderBoundsView(n),this.canvas.updateRender(i)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new _;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.target.emit(b.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(h.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:i}=t.old;if(!new _(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 _(0,0,1,1)),this.changed=!0}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||dt.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,i){this.target.emitEvent(new h(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(h.REQUEST,this.update,this),t.on_(m.END,this.__onLayoutEnd,this),t.on_(h.AGAIN,this.renderAgain,this),t.on_(B.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}const{hitRadiusPoint:lt}=R;class ct{constructor(t,e){this.target=t,this.selector=e}getByPoint(t,e,i){e||(e=0),i||(i={});const n=i.through||!1,s=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 r(i.findList),i.findList||this.hitBranch(o);const{list:a}=this.findList,d=this.getBestMatchLeaf(a,i.bottomList,s),h=s?this.getPath(d):this.getHitablePath(d);return this.clear(),n?{path:h,target:d,throughPath:a.length?this.getThroughPath(a):h}:{path:h,target:d}}getBestMatchLeaf(t,e,i){if(t.length){let e;this.findList=new r;const{x:n,y:s}=this.point,o={x:n,y:s,radiusX:0,radiusY:0};for(let n=0,s=t.length;n<s;n++)if(e=t[n],(i||f.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 r;for(;t;)e.add(t),t=t.parent;return e.add(this.target),e}getHitablePath(t){const e=this.getPath(t&&t.hittable?t:null);let i,n=new r;for(let t=e.list.length-1;t>-1&&(i=e.list[t],i.__.hittable)&&(n.addAt(i,0),i.__.hitChildren);t--);return n}getThroughPath(t){const e=new r,i=[];for(let e=t.length-1;e>-1;e--)i.push(this.getPath(t[e]));let n,s,o;for(let t=0,a=i.length;t<a;t++){n=i[t],s=i[t+1];for(let t=0,i=n.length;t<i&&(o=n.list[t],!s||!s.has(o));t++)e.add(o)}return e}hitBranch(t){this.eachFind(t.children,t.__onlyHitMask)}eachFind(t,e){let i,n;const{point:s}=this;for(let o=t.length-1;o>-1;o--)i=t[o],!i.__.visible||e&&!i.__.mask||(n=!!i.__.hitRadius||lt(i.__world,s),i.isBranch?(n||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&!this.findList.length&&this.hitChild(i,s)):n&&this.hitChild(i,s))}hitChild(t,e,i){if((!this.exclude||!this.exclude.has(t))&&t.__hitWorld(e)){const{parent:n}=t;if(n&&n.__hasMask&&!t.__.mask&&!n.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:ut,NoAndSkip:ft,YesAndSkip:gt}=k,_t={},pt={},wt={};class yt{constructor(t,e){this.config={},this.innerIdMap={},this.idMap={},this.methods={id:(t,e)=>t.id===e?(this.idMap[e]=t,1):0,innerId:(t,e)=>t.innerId===e?(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=d.default(e,this.config)),this.picker=new ct(t,this),this.__listenEvents()}getBy(t,e,i,n){switch(typeof t){case"number":const s=this.getByInnerId(t,e);return i?s:s?[s]:[];case"string":switch(t[0]){case"#":_t.id=t.substring(1),t=_t;break;case".":pt.className=t.substring(1),t=pt;break;default:wt.tag=t,t=wt}case"object":if(void 0!==t.id){const n=this.getById(t.id,e);return i?n:n?[n]:[]}if(t.tag){const{tag:n}=t,s=n instanceof Array;return this.getByMethod(s?this.methods.tags:this.methods.tag,e,i,s?d.toMap(n):n)}return this.getByMethod(this.methods.className,e,i,t.className);case"function":return this.getByMethod(t,e,i,n)}}getByPoint(t,i,n){return"node"===e.name&&this.target.emit(m.CHECK_UPDATE),this.picker.getByPoint(t,i,n)}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&&f.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,n){const s=i?null:[];return this.eachFind(this.toChildren(e),t,s,n),s||this.findLeaf}eachFind(t,e,i,n){let s,o;for(let a=0,r=t.length;a<r;a++){if(s=t[a],o=e(s,n),o===ut||o===gt){if(!i)return void(this.findLeaf=s);i.push(s)}s.isBranch&&o<ft&&this.eachFind(s.children,e,i,n)}}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_(l.REMOVE,this.__onRemoveChild,this),this.target.on_(u.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={})}}function mt(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),s&&e.fillRect(i.x,i.y+s,i.width,o)}function vt(t,e,i){const{strokeAlign:n}=e.__,s="string"!=typeof t;switch(n){case"center":i.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?Bt(t,!0,e,i):bt(e,i);break;case"inside":xt("inside",t,s,e,i);break;case"outside":xt("outside",t,s,e,i)}}function xt(t,e,i,n,s){const{__strokeWidth:o,__font:a}=n.__,r=s.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,n.__),r.font=a,i?Bt(e,!0,n,r):bt(n,r),r.blendMode="outside"===t?"destination-out":"destination-in",mt(n,r),r.blendMode="normal",n.__worldFlipped?s.copyWorldByReset(r,n.__nowWorld):s.copyWorldToInner(r,n.__nowWorld,n.__layout.renderBounds),r.recycle(n.__nowWorld)}function bt(t,e){let i;const{rows:n,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=n.length;t<a;t++)i=n[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),s&&e.strokeRect(i.x,i.y+s,i.width,o)}function Bt(t,e,i,n){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&D.checkImage(i,n,s,!1)||s.style&&(n.strokeStyle=s.style,s.blendMode?(n.saveBlendMode(s.blendMode),e?bt(i,n):n.stroke(),n.restoreBlendMode()):e?bt(i,n):n.stroke())}Object.assign(n,{watcher:(t,e)=>new Q(t,e),layouter:(t,e)=>new rt(t,e),renderer:(t,e,i)=>new ht(t,e,i),selector:(t,e)=>new yt(t,e)}),e.layout=rt.fullLayout;const{getSpread:Rt,getOuterOf:kt,getByMove:Et,getIntersectData:Lt}=R;let St;function Mt(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:n}=i.__layout;switch(e.type){case"solid":let{type:s,blendMode:o,color:a,opacity:r}=e;return{type:s,blendMode:o,style:F.string(a,r)};case"image":return D.image(i,t,e,n,!St||!St[e.url]);case"linear":return N.linearGradient(e,n);case"radial":return N.radialGradient(e,n);case"angular":return N.conicGradient(e,n);default:return void 0!==e.r?{type:"solid",style:F.string(e)}:void 0}}const At={compute:function(t,e){const i=e.__,n=[];let s,o=i.__input[t];o instanceof Array||(o=[o]),St=D.recycleImage(t,i);for(let i,s=0,a=o.length;s<a;s++)i=Mt(t,o[s],e),i&&n.push(i);i["_"+t]=n.length?n:void 0,n.length&&n[0].image&&(s=n[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=s:i.__pixelStroke=s},fill:function(t,e,i){i.fillStyle=t,e.__.__font?mt(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let n;const{windingRule:s,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)n=t[a],n.image&&D.checkImage(e,i,n,!o)||n.style&&(i.fillStyle=n.style,n.transform?(i.save(),i.transform(n.transform),n.blendMode&&(i.blendMode=n.blendMode),o?mt(e,i):s?i.fill(s):i.fill(),i.restore()):n.blendMode?(i.saveBlendMode(n.blendMode),o?mt(e,i):s?i.fill(s):i.fill(),i.restoreBlendMode()):o?mt(e,i):s?i.fill(s):i.fill())},fillText:mt,stroke:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)vt(t,e,i);else switch(o){case"center":i.setStroke(t,s,n),i.stroke();break;case"inside":i.save(),i.setStroke(t,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),i.stroke(),i.restore();break;case"outside":const o=i.getSameCanvas(!0,!0);o.setStroke(t,2*s,n),e.__drawRenderPath(o),o.stroke(),n.windingRule?o.clip(n.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?i.copyWorldByReset(o,e.__nowWorld):i.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,i){const n=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=n;if(s)if(a)vt(t,e,i);else switch(o){case"center":i.setStroke(void 0,s,n),Bt(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*s,n),n.windingRule?i.clip(n.windingRule):i.clip(),Bt(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*s,n),Bt(t,!1,e,a),n.windingRule?a.clip(n.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:vt,drawTextStroke:bt,shape:function(t,e,i){const n=e.getSameCanvas(),s=t.__nowWorld;let o,a,r,d,{scaleX:h,scaleY:l}=s;if(h<0&&(h=-h),l<0&&(l=-l),e.bounds.includes(s))d=n,o=r=s;else{const{renderShapeSpread:n}=t.__layout,c=Lt(n?Rt(e.bounds,h===l?n*h:[n*l,n*h]):e.bounds,s);a=e.bounds.getFitMatrix(c);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),h*=u,l*=f),r=kt(s,a),o=Et(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,f)})}return t.__renderShape(n,i),{canvas:n,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:h,scaleY:l}}};let Ot={};const{get:Wt,rotateOfOuter:Ct,translate:Tt,scaleOfOuter:It,scale:Pt,rotate:Dt}=E;function Ft(t,e,i,n,s,o,a){const r=Wt();Tt(r,e.x+i,e.y+n),Pt(r,s,o),a&&Ct(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Nt(t,e,i,n,s,o,a){const r=Wt();Tt(r,e.x+i,e.y+n),s&&Pt(r,s,o),a&&Dt(r,a),t.transform=r}function Yt(t,e,i,n,s,o,a,r,d,h){const l=Wt();if(d)if("center"===h)Ct(l,{x:i/2,y:n/2},d);else switch(Dt(l,d),d){case 90:Tt(l,n,0);break;case 180:Tt(l,i,n);break;case 270:Tt(l,0,i)}Ot.x=e.x+s,Ot.y=e.y+o,Tt(l,Ot.x,Ot.y),a&&It(l,Ot,a,r),t.transform=l}const{get:Gt,translate:Ut}=E,jt=new _,Ht={};function Xt(t,e,i,n){const{blendMode:s}=i;s&&(t.blendMode=s),t.data=Vt(i,n,e)}function Vt(t,e,i){let{width:n,height:s}=i;t.padding&&(e=jt.set(e).shrink(t.padding));const{opacity:o,mode:a,align:r,offset:d,scale:h,size:l,rotation:c,repeat:u}=t,f=e.width===n&&e.height===s,g={mode:a},_="center"!==r&&(c||0)%180==90,p=_?s:n,w=_?n:s;let y,m,v=0,x=0;if(a&&"cover"!==a&&"fit"!==a)l?(y=("number"==typeof l?l:l.width)/n,m=("number"==typeof l?l:l.height)/s):h&&(y="number"==typeof h?h:h.x,m="number"==typeof h?h:h.y);else if(!f||c){const t=e.width/p,i=e.height/w;y=m="fit"===a?Math.min(t,i):Math.max(t,i),v+=(e.width-n*y)/2,x+=(e.height-s*m)/2}if(r){const t={x:v,y:x,width:p,height:w};y&&(t.width*=y,t.height*=m),L.toPoint(r,t,e,Ht,!0),v+=Ht.x,x+=Ht.y}switch(d&&(v+=d.x,x+=d.y),a){case"strench":f||(n=e.width,s=e.height);break;case"normal":case"clip":(v||x||y||c)&&Nt(g,e,v,x,y,m,c);break;case"repeat":(!f||y||c)&&Yt(g,e,n,s,v,x,y,m,c,r),u||(g.repeat="repeat");break;default:y&&Ft(g,e,v,x,y,m,c)}return g.transform||(e.x||e.y)&&(g.transform=Gt(),Ut(g.transform,e.x,e.y)),y&&"strench"!==a&&(g.scaleX=y,g.scaleY=m),g.width=n,g.height=s,o&&(g.opacity=o),u&&(g.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),g}let qt,zt=new _;const{isSame:Qt}=R;function Jt(t,e,i,n,s,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=n.width/e.pixelRatio,e.__naturalHeight=n.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return s.data||Xt(s,n,i,o),!0}function Zt(t,e){te(t,S.LOAD,e)}function Kt(t,e){te(t,S.LOADED,e)}function $t(t,e,i){e.error=i,t.forceUpdate("surface"),te(t,S.ERROR,e)}function te(t,e,i){t.hasEvent(e)&&t.emitEvent(new S(e,i))}function ee(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:ie,scale:ne,copy:se}=E,{ceil:oe,abs:ae}=Math;function re(t,i,n){let{scaleX:s,scaleY:o}=x.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o;if(i.patternId===a||t.destroyed)return!1;{s=ae(s),o=ae(o);const{image:t,data:r}=i;let d,h,{width:l,height:c,scaleX:u,scaleY:f,opacity:g,transform:_,repeat:p}=r;u&&(h=ie(),se(h,_),ne(h,1/u,1/f),s*=u,o*=f),s*=n,o*=n,l*=s,c*=o;const w=l*c;if(!p&&w>e.image.maxCacheSize)return!1;let y=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(s/=d,o/=d,l/=d,c/=d),u&&(s/=u,o/=f),(_||1!==s||1!==o)&&(h||(h=ie(),_&&se(h,_)),ne(h,1/s,1/o));const m=t.getCanvas(oe(l)||1,oe(c)||1,g),v=t.getPattern(m,p||e.origin.noRepeat||"no-repeat",h,i);return i.style=v,i.patternId=a,!0}}function de(t,e,i,n){return new(i||(i=Promise))((function(s,o){function a(t){try{d(n.next(t))}catch(t){o(t)}}function r(t){try{d(n.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}d((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:he}=Math;const le={image:function(t,e,i,n,s){let o,a;const r=x.get(i);return qt&&i===qt.paint&&Qt(n,qt.boxBounds)?o=qt.leafPaint:(o={type:i.type,image:r},qt=r.use>1?{leafPaint:o,paint:i,boxBounds:zt.set(n)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(Jt(t,e,i,r,o,n),s&&(Zt(t,a),Kt(t,a))):r.error?s&&$t(t,a,r.error):(ee(t,!0),s&&Zt(t,a),o.loadId=r.load((()=>{ee(t,!1),t.destroyed||(Jt(t,e,i,r,o,n)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Kt(t,a)),o.loadId=null}),(e=>{ee(t,!1),$t(t,a,e),o.loadId=null}))),o},checkImage:function(t,i,n,s){const{scaleX:o,scaleY:a}=x.patternLocked?t.__world:t.__nowWorld;if(!n.data||n.patternId===o+"-"+a&&!Y.running)return!1;{const{data:r}=n;if(s)if(r.repeat)s=!1;else{let{width:t,height:n}=r;t*=he(o)*i.pixelRatio,n*=he(a)*i.pixelRatio,r.scaleX&&(t*=r.scaleX,n*=r.scaleY),s=t*n>e.image.maxCacheSize||Y.running}return s?(i.save(),i.clip(),n.blendMode&&(i.blendMode=n.blendMode),r.opacity&&(i.opacity*=r.opacity),r.transform&&i.transform(r.transform),i.drawImage(n.image.view,0,0,r.width,r.height),i.restore(),!0):(!n.style||Y.running?re(t,n,i.pixelRatio):n.patternTask||(n.patternTask=x.patternTasker.add((()=>de(this,void 0,void 0,(function*(){n.patternTask=null,i.bounds.hit(t.__nowWorld)&&re(t,n,i.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}},createPattern:re,recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let n,s,o,a;for(let r=0,d=i.length;r<d;r++)n=i[r].image,a=n&&n.url,a&&(s||(s={}),s[a]=!0,x.recycle(n),n.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),n.unload(i[r].loadId,!o.some((t=>t.url===a)))));return s}return null},createData:Xt,getPatternData:Vt,fillOrFitMode:Ft,clipMode:Nt,repeatMode:Yt},{toPoint:ce}=M,ue={},fe={};function ge(t,e,i){let n;for(let s=0,o=e.length;s<o;s++)n=e[s],"string"==typeof n?t.addColorStop(s/(o-1),F.string(n,i)):t.addColorStop(n.offset,F.string(n.color,i))}const{getAngle:_e,getDistance:pe}=A,{get:we,rotateOfOuter:ye,scaleOfOuter:me}=E,{toPoint:ve}=M,xe={},be={};function Be(t,e,i,n,s){let o;const{width:a,height:r}=t;if(a!==r||n){const t=_e(e,i);o=we(),s?(me(o,e,a/r*(n||1),1),ye(o,e,t+90)):(me(o,e,1,a/r*(n||1)),ye(o,e,t))}return o}const{getDistance:Re}=A,{toPoint:ke}=M,Ee={},Le={};const Se={linearGradient:function(t,i){let{from:n,to:s,type:o,blendMode:a,opacity:r}=t;ce(n||"top",i,ue),ce(s||"bottom",i,fe);const d=e.canvas.createLinearGradient(ue.x,ue.y,fe.x,fe.y);ge(d,t.stops,r);const h={type:o,style:d};return a&&(h.blendMode=a),h},radialGradient:function(t,i){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;ve(n||"center",i,xe),ve(s||"bottom",i,be);const h=e.canvas.createRadialGradient(xe.x,xe.y,0,xe.x,xe.y,pe(xe,be));ge(h,t.stops,a);const l={type:o,style:h},c=Be(i,xe,be,d,!0);return c&&(l.transform=c),r&&(l.blendMode=r),l},conicGradient:function(t,i){let{from:n,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;ke(n||"center",i,Ee),ke(s||"bottom",i,Le);const h=e.conicGradientSupport?e.canvas.createConicGradient(0,Ee.x,Ee.y):e.canvas.createRadialGradient(Ee.x,Ee.y,0,Ee.x,Ee.y,Re(Ee,Le));ge(h,t.stops,a);const l={type:o,style:h},c=Be(i,Ee,Le,d||1,e.conicGradientRotate90);return c&&(l.transform=c),r&&(l.blendMode=r),l},getTransform:Be},{copy:Me,toOffsetOutBounds:Ae}=R,Oe={},We={};function Ce(t,i,n,s){const{bounds:o,shapeBounds:a}=s;if(e.fullImageShadow){if(Me(Oe,t.bounds),Oe.x+=i.x-a.x,Oe.y+=i.y-a.y,n){const{matrix:t}=s;Oe.x-=(o.x+(t?t.e:0)+o.width/2)*(n-1),Oe.y-=(o.y+(t?t.f:0)+o.height/2)*(n-1),Oe.width*=n,Oe.height*=n}t.copyWorld(s.canvas,t.bounds,Oe)}else n&&(Me(Oe,i),Oe.x-=i.width/2*(n-1),Oe.y-=i.height/2*(n-1),Oe.width*=n,Oe.height*=n),t.copyWorld(s.canvas,a,n?Oe:i)}const{toOffsetOutBounds:Te}=R,Ie={};const Pe={shadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:h,shapeBounds:l,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),g=r.length-1;Ae(h,We),r.forEach(((r,_)=>{f.setWorldShadow(We.offsetX+r.x*c,We.offsetY+r.y*u,r.blur*c,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Ce(f,We,s,i),n=h,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,h,o,"copy"),n=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(i.canvas,l,h,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),g&&_<g&&f.clearWorld(n,!0)})),f.recycle(n)},innerShadow:function(t,e,i){let n,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:h,shapeBounds:l,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),g=r.length-1;Te(h,Ie),r.forEach(((r,_)=>{f.save(),f.setWorldShadow(Ie.offsetX+r.x*c,Ie.offsetY+r.y*u,r.blur*c),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Ce(f,Ie,s,i),f.restore(),d?(f.copyWorld(f,h,o,"copy"),f.copyWorld(d,o,o,"source-out"),n=o):(f.copyWorld(i.canvas,l,h,"source-out"),n=h),f.fillWorld(n,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,n,o,r.blendMode):e.copyWorldToInner(f,n,a.renderBounds,r.blendMode),g&&_<g&&f.clearWorld(n,!0)})),f.recycle(n)},blur:function(t,e,i){const{blur:n}=t.__;i.setWorldBlur(n*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:De}=p;function Fe(t,e,i,n,s,o){switch(e){case"alpha":!function(t,e,i,n){const s=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(n,s),n.recycle(s),Ye(t,e,i,1)}(t,i,n,s);break;case"opacity-path":Ye(t,i,n,o);break;case"path":i.restore()}}function Ne(t){return t.getSameCanvas(!1,!0)}function Ye(t,e,i,n){const s=t.__nowWorld;e.resetTransform(),e.opacity=n,e.copyWorld(i,s),i.recycle(s)}G.prototype.__renderMask=function(t,e){let i,n,s,o,a;const{children:r}=this;for(let d=0,h=r.length;d<h;d++)i=r[d],i.__.mask&&(a&&(Fe(this,a,t,s,n,o),n=s=null),"path"===i.__.mask?(i.opacity<1?(a="opacity-path",o=i.opacity,s||(s=Ne(t))):(a="path",t.save()),i.__clip(s||t,e)):(a="alpha",n||(n=Ne(t)),s||(s=Ne(t)),i.__render(n,e)),"clipping"!==i.__.mask)||De(i,e)||i.__render(s||t,e);Fe(this,a,t,s,n,o)};const Ge=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Ue=Ge+"_#~&*+\\=|≮≯≈≠=…",je=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map((([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`)).join("|"));function He(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Xe=He("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ve=He("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),qe=He(Ge),ze=He(Ue),Qe=He("- —/~|┆·");var Je;!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"}(Je||(Je={}));const{Letter:Ze,Single:Ke,Before:$e,After:ti,Symbol:ei,Break:ii}=Je;function ni(t){return Xe[t]?Ze:Qe[t]?ii:Ve[t]?$e:qe[t]?ti:ze[t]?ei:je.test(t)?Ke:Ze}const si={trimRight(t){const{words:e}=t;let i,n=0,s=e.length;for(let o=s-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)n++,t.width-=i.width;n&&e.splice(s-n,n)}};function oi(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:ai}=si,{Letter:ri,Single:di,Before:hi,After:li,Symbol:ci,Break:ui}=Je;let fi,gi,_i,pi,wi,yi,mi,vi,xi,bi,Bi,Ri,ki,Ei,Li,Si,Mi=[];function Ai(t,e){xi&&!vi&&(vi=xi),fi.data.push({char:t,width:e}),_i+=e}function Oi(){pi+=_i,fi.width=_i,gi.words.push(fi),fi={data:[]},_i=0}function Wi(){Ei&&(Li.paraNumber++,gi.paraStart=!0,Ei=!1),xi&&(gi.startCharSize=vi,gi.endCharSize=xi,vi=0),gi.width=pi,Si.width&&ai(gi),Mi.push(gi),gi={words:[]},pi=0}const Ci=0,Ti=1,Ii=2;const{top:Pi,right:Di,bottom:Fi,left:Ni}=O;function Yi(t,e,i){const{bounds:n,rows:s}=t;n[e]+=i;for(let t=0;t<s.length;t++)s[t][e]+=i}const Gi={getDrawData:function(t,i){"string"!=typeof t&&(t=String(t));let n=0,s=0,o=i.__getInput("width")||0,a=i.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:h}=i;h&&(o&&(n=h[Ni],o-=h[Di]+h[Ni]),a&&(s=h[Pi],a-=h[Pi]+h[Fi]));const l={bounds:{x:n,y:s,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,i,n){Li=t,Mi=t.rows,Si=t.bounds;const{__letterSpacing:s,paraIndent:o,textCase:a}=n,{canvas:r}=e,{width:d,height:h}=Si;if(d||h||s||"none"!==a){const t="none"!==n.textWrap,e="break"===n.textWrap;Ei=!0,Bi=null,vi=mi=xi=_i=pi=0,fi={data:[]},gi={words:[]};for(let n=0,h=i.length;n<h;n++)yi=i[n],"\n"===yi?(_i&&Oi(),gi.paraEnd=!0,Wi(),Ei=!0):(bi=ni(yi),bi===ri&&"none"!==a&&(yi=oi(yi,a,!_i)),mi=r.measureText(yi).width,s&&(s<0&&(xi=mi),mi+=s),Ri=bi===di&&(Bi===di||Bi===ri)||Bi===di&&bi!==li,ki=!(bi!==hi&&bi!==di||Bi!==ci&&Bi!==li),wi=Ei&&o?d-o:d,t&&d&&pi+_i+mi>wi&&(e?(_i&&Oi(),pi&&Wi()):(ki||(ki=bi===ri&&Bi==li),Ri||ki||bi===ui||bi===hi||bi===di||_i+mi>wi?(_i&&Oi(),pi&&Wi()):pi&&Wi()))," "===yi&&!0!==Ei&&pi+_i===0||(bi===ui?(" "===yi&&_i&&Oi(),Ai(yi,mi),Oi()):Ri||ki?(_i&&Oi(),Ai(yi,mi)):Ai(yi,mi)),Bi=bi);_i&&Oi(),pi&&Wi(),Mi.length>0&&(Mi[Mi.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{Li.paraNumber++,Mi.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(l,t,i),h&&function(t,e,i,n,s){if(!n)switch(i.textAlign){case"left":Yi(e,"x",t[Ni]);break;case"right":Yi(e,"x",-t[Di])}if(!s)switch(i.verticalAlign){case"top":Yi(e,"y",t[Pi]);break;case"bottom":Yi(e,"y",-t[Fi])}}(h,l,i,o,a),function(t,e){const{rows:i,bounds:n}=t,{__lineHeight:s,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:h,paraSpacing:l}=e;let c,u,f,{x:g,y:_,width:p,height:w}=n,y=s*i.length+(l?l*(t.paraNumber-1):0),m=o;if(r&&y>w)y=Math.max(w,s),t.overflow=i.length;else switch(h){case"middle":_+=(w-y)/2;break;case"bottom":_+=w-y}m+=_;for(let o=0,h=i.length;o<h;o++){if(c=i[o],c.x=g,c.width<p||c.width>p&&!r)switch(d){case"center":c.x+=(p-c.width)/2;break;case"right":c.x+=p-c.width}c.paraStart&&l&&o>0&&(m+=l),c.y=m,m+=s,t.overflow>o&&m>y&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,f=c.width,a<0&&(c.width<0?(f=-c.width+e.fontSize+a,u-=f,f+=e.fontSize):f-=a),u<n.x&&(n.x=u),f>n.width&&(n.width=f),r&&p&&p<f&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}n.y=_,n.height=y}(l,i),function(t,e,i,n){const{rows:s}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,h,l,c,u;s.forEach((t=>{t.words&&(l=a&&t.paraStart?a:0,h=i&&"justify"===o&&t.words.length>1?(i-t.width-l)/(t.words.length-1):0,c=r||t.isOverflow?Ci:h>.01?Ti:Ii,t.isOverflow&&!r&&(t.textMode=!0),c===Ii?(t.x+=l,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=l,d=t.x,t.data=[],t.words.forEach((e=>{c===Ti?(u={char:"",x:d},d=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,d,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,i,n){return t.forEach((t=>{(n||" "!==t.char)&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&h&&(d+=h,t.width+=h)}))),t.words=null)}))}(l,i,o),l.overflow&&function(t,i,n,s){if(!s)return;const{rows:o,overflow:a}=t;let{textOverflow:r}=i;if(o.splice(a),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const h=r?e.canvas.measureText(r).width:0,l=n+s-h;("none"===i.textWrap?o:[o[a-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let n=i;n>-1&&(t=e.data[n],d=t.x+t.width,!(n===i&&d<l));n--){if(d<l&&" "!==t.char){e.data.splice(n+1),e.width-=t.width;break}e.width-=t.width}e.width+=h,e.data.push({char:r,x:d}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(l,i,n,o),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(l,i),l}};const Ui={string:function(t,e){if("string"==typeof t)return t;let i=void 0===t.a?1:t.a;e&&(i*=e);const n=t.r+","+t.g+","+t.b;return 1===i?"rgb("+n+")":"rgba("+n+","+i+")"}},{setPoint:ji,addPoint:Hi,toBounds:Xi}=W;const Vi={export(t,i,s){this.running=!0;const o=a.fileType(i);return s=a.getExportOptions(s),function(t){qi||(qi=new C);return new Promise((e=>{qi.add((()=>de(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((r=>new Promise((d=>{const h=t=>{r(t),d(),this.running=!1},{toURL:l}=e,{download:c}=e.origin;if("json"===i)return h({data:t.toJSON(s.json)});if("json"===o)return c(l(JSON.stringify(t.toJSON(s.json)),"text"),i),h({data:!0});if("svg"===i)return h({data:t.toSVG()});if("svg"===o)return c(l(t.toSVG(),"svg"),i),h({data:!0});const{leafer:u}=t;u?(zi(t),u.waitViewCompleted((()=>de(this,void 0,void 0,(function*(){let e,o,r=1,d=1;const{worldTransform:l,isLeafer:c,isFrame:f}=t,{slice:g,trim:p,onCanvas:w}=s;let y=s.scale||1,m=s.pixelRatio||1;const v=void 0===s.smooth?u.config.smooth:s.smooth,x=s.contextSettings||u.config.contextSettings;t.isApp&&(y*=m,m=t.app.pixelRatio);const b=s.screenshot||t.isApp,B=c&&b&&void 0===s.fill?t.fill:s.fill,R=a.isOpaqueImage(i)||B,k=new T;if(b)e=!0===b?c?u.canvas.bounds:t.worldRenderBounds:b;else{let i=s.relative||(c?"inner":"local");switch(r=l.scaleX,d=l.scaleY,i){case"inner":k.set(l);break;case"local":k.set(l).divide(t.localTransform),r/=t.scaleX,d/=t.scaleY;break;case"world":r=1,d=1;break;case"page":i=t.leafer;default:k.set(l).divide(t.getTransform(i));const e=i.worldTransform;r/=r/e.scaleX,d/=d/e.scaleY}e=t.getBounds("render",i)}const{x:E,y:L,width:S,height:M}=new _(e).scale(y);let A=n.canvas({width:Math.round(S),height:Math.round(M),pixelRatio:m,smooth:v,contextSettings:x});const O={matrix:k.scale(1/y).invert().translate(-E,-L).withScale(1/r*y,1/d*y)};let W;if(g&&(W=t,W.__worldOpacity=0,t=u,O.bounds=A.bounds),A.save(),f&&void 0!==B){const e=t.get("fill");t.fill="",t.__render(A,O),t.fill=e}else t.__render(A,O);if(A.restore(),W&&W.__updateWorldOpacity(),p){o=function(t){const{width:e,height:i}=t.view,{data:n}=t.context.getImageData(0,0,e,i);let s,o,a,r=0;for(let t=0;t<n.length;t+=4)0!==n[t+3]&&(s=r%e,o=(r-s)/e,a?Hi(a,s,o):ji(a={},s,o)),r++;const d=new _;return Xi(a,d),d.scale(1/t.pixelRatio).ceil()}(A);const t=A,{width:e,height:i}=o,s={x:0,y:0,width:e,height:i,pixelRatio:m};A=n.canvas(s),A.copyWorld(t,o,s)}R&&A.fillWorld(A.bounds,B||"#FFFFFF","destination-over"),w&&w(A);const C="canvas"===i?A:yield A.export(i,s);h({data:C,width:A.pixelWidth,height:A.pixelHeight,renderBounds:e,trimBounds:o})}))))):h({data:!1})}))))}};let qi;function zi(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>zi(t)))}const Qi=t.prototype,Ji=w.get("@leafer-ui/export");Qi.export=function(t,e){const{quality:i,blob:n}=a.getExportOptions(e);return t.includes(".")?this.saveAs(t,i):n?this.toBlob(t,i):this.toDataURL(t,i)},Qi.toBlob=function(t,i){return new Promise((n=>{e.origin.canvasToBolb(this.view,t,i).then((t=>{n(t)})).catch((t=>{Ji.error(t),n(null)}))}))},Qi.toDataURL=function(t,i){return e.origin.canvasToDataURL(this.view,t,i)},Qi.saveAs=function(t,i){return new Promise((n=>{e.origin.canvasSaveAs(this.view,t,i).then((()=>{n(!0)})).catch((t=>{Ji.error(t),n(!1)}))}))},Object.assign(U,Gi),Object.assign(F,Ui),Object.assign(j,At),Object.assign(D,le),Object.assign(N,Se),Object.assign(H,Pe),Object.assign(Y,Vi),Object.assign(n,{interaction:(t,e,i,n)=>new I(t,e,i,n),hitCanvas:(t,e)=>new X(t,e),hitCanvasManager:()=>new P}),q();export{rt as Layouter,X as LeaferCanvas,ht as Renderer,yt as Selector,Q as Watcher,q as useCanvas};