leafer-ui 1.0.0-rc.12 → 1.0.0-rc.16

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
@@ -4,7 +4,7 @@ Leafer UI 是基于 [Leafer](https://github.com/leaferjs/leafer) 开发的一套
4
4
 
5
5
  提供了常用的 UI 绘图组件,和开箱即用的功能,方便与 Figma、Sketch 等产品进行数据交换,并为跨平台开发提供了统一、丰富的交互事件,如拖拽、旋转、缩放手势等。
6
6
 
7
- 1.0.0-rc.12 已发布 🎉🎉🎉,查看 [更新日志](https://leaferjs.com/ui/update/)。
7
+ 1.0.0-rc.16 已发布 🎉🎉🎉,查看 [更新日志](https://leaferjs.com/ui/update/)。
8
8
 
9
9
  目前产品已经逐步稳定,正式版即将到来,感谢所有参与的朋友们~
10
10
 
package/dist/web.esm.js CHANGED
@@ -1,7 +1,7 @@
1
- import { Debug, LeaferCanvasBase, Platform, DataHelper, canvasSizeAttrs, ResizeEvent, canvasPatch, Creator, LeaferImage, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, BoundsHelper, Answer, MatrixHelper, ImageEvent, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
1
+ import { Debug, LeaferCanvasBase, Platform, DataHelper, canvasSizeAttrs, ResizeEvent, canvasPatch, Creator, LeaferImage, FileHelper, LeafList, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, BoundsHelper, Answer, MathHelper, MatrixHelper, ImageEvent, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
2
2
  export * from '@leafer/core';
3
3
  export { LeaferImage } from '@leafer/core';
4
- import { InteractionHelper, Platform as Platform$1, MathHelper, InteractionBase, Cursor, HitCanvasManager } from '@leafer-ui/core';
4
+ import { InteractionHelper, InteractionBase, MathHelper as MathHelper$1, Cursor, HitCanvasManager } from '@leafer-ui/core';
5
5
  export * from '@leafer-ui/core';
6
6
  import { PaintImage, ColorConvert, PaintGradient, Export, Group, TextConvert, Paint, Effect } from '@leafer-ui/draw';
7
7
 
@@ -520,9 +520,11 @@ class Layouter {
520
520
  updateAllChange(target);
521
521
  }
522
522
  addExtra(leaf) {
523
- const block = this.extraBlock || (this.extraBlock = new LayoutBlockData([]));
524
- block.updatedList.add(leaf);
525
- block.beforeBounds.add(leaf.__world);
523
+ if (!this.__updatedList.has(leaf)) {
524
+ const { updatedList, beforeBounds } = this.extraBlock || (this.extraBlock = new LayoutBlockData([]));
525
+ updatedList.length ? beforeBounds.add(leaf.__world) : beforeBounds.set(leaf.__world);
526
+ updatedList.add(leaf);
527
+ }
526
528
  }
527
529
  createBlock(data) {
528
530
  return new LayoutBlockData(data);
@@ -1084,7 +1086,7 @@ const WheelEventHelper = {
1084
1086
  let { zoomMode, zoomSpeed } = config;
1085
1087
  const delta = e.deltaY || e.deltaX;
1086
1088
  if (zoomMode) {
1087
- zoom = (zoomMode === 'mouse') ? true : (!e.deltaX && (Platform$1.intWheelDeltaY ? Math.abs(delta) > 17 : Math.ceil(delta) !== delta));
1089
+ zoom = (zoomMode === 'mouse') ? true : (!e.deltaX && (Platform.intWheelDeltaY ? Math.abs(delta) > 17 : Math.ceil(delta) !== delta));
1088
1090
  if (e.shiftKey || e.metaKey || e.ctrlKey)
1089
1091
  zoom = true;
1090
1092
  }
@@ -1343,7 +1345,7 @@ class Interaction extends InteractionBase {
1343
1345
  const changeScale = e.scale / this.lastGestureScale;
1344
1346
  const changeAngle = e.rotation - this.lastGestureRotation;
1345
1347
  let { rotateSpeed } = this.config.wheel;
1346
- rotateSpeed = MathHelper.within(rotateSpeed, 0, 1);
1348
+ rotateSpeed = MathHelper$1.within(rotateSpeed, 0, 1);
1347
1349
  this.zoom(getZoomEventData(local, changeScale * changeScale, eventBase));
1348
1350
  this.rotate(getRotateEventData(local, changeAngle / Math.PI * 180 * (rotateSpeed / 4 + 0.1), eventBase));
1349
1351
  this.lastGestureScale = e.scale;
@@ -1843,9 +1845,9 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
1843
1845
  function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
1844
1846
  if (attrName === 'fill' && !ui.__.__naturalWidth) {
1845
1847
  const data = ui.__;
1846
- data.__naturalWidth = image.width;
1847
- data.__naturalHeight = image.height;
1848
- if (data.__autoWidth || data.__autoHeight) {
1848
+ data.__naturalWidth = image.width / data.pixelRatio;
1849
+ data.__naturalHeight = image.height / data.pixelRatio;
1850
+ if (data.__autoSide) {
1849
1851
  ui.forceUpdate('width');
1850
1852
  if (ui.__proxyData) {
1851
1853
  ui.setProxyAttr('width', data.width);
@@ -1875,7 +1877,7 @@ function emit(ui, type, data) {
1875
1877
  }
1876
1878
 
1877
1879
  const { get: get$2, scale, copy: copy$1 } = MatrixHelper;
1878
- const { round, abs: abs$1 } = Math;
1880
+ const { ceil, abs: abs$1 } = Math;
1879
1881
  function createPattern(ui, paint, pixelRatio) {
1880
1882
  let { scaleX, scaleY } = ui.__world;
1881
1883
  const id = scaleX + '-' + scaleY;
@@ -1926,7 +1928,7 @@ function createPattern(ui, paint, pixelRatio) {
1926
1928
  }
1927
1929
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1928
1930
  }
1929
- const canvas = image.getCanvas(width < 1 ? 1 : round(width), height < 1 ? 1 : round(height), opacity);
1931
+ const canvas = image.getCanvas(ceil(width) || 1, ceil(height) || 1, opacity);
1930
1932
  const pattern = image.getPattern(canvas, repeat || (Platform.origin.noRepeat || 'no-repeat'), imageMatrix, paint);
1931
1933
  paint.style = pattern;
1932
1934
  paint.patternId = id;
@@ -2869,37 +2871,55 @@ const ExportModule = {
2869
2871
  const { leafer } = leaf;
2870
2872
  if (leafer) {
2871
2873
  leafer.waitViewCompleted(() => __awaiter(this, void 0, void 0, function* () {
2872
- let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
2873
2874
  options = FileHelper.getExportOptions(options);
2874
- const { scale, slice, trim } = options;
2875
+ let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
2876
+ const { worldTransform, isLeafer, isFrame } = leaf;
2877
+ const { slice, trim, onCanvas } = options;
2878
+ const scale = options.scale || 1;
2875
2879
  const pixelRatio = options.pixelRatio || 1;
2876
2880
  const screenshot = options.screenshot || leaf.isApp;
2877
- const fill = options.fill === undefined ? ((leaf.isLeafer && screenshot) ? leaf.fill : '') : options.fill;
2881
+ const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : undefined) : options.fill;
2878
2882
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
2879
2883
  if (screenshot) {
2880
- renderBounds = screenshot === true ? (leaf.isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
2884
+ renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
2881
2885
  }
2882
2886
  else {
2883
- const { localTransform, __world: world } = leaf;
2884
- matrix.set(world).divide(localTransform).invert();
2885
- scaleX = 1 / (world.scaleX / leaf.scaleX);
2886
- scaleY = 1 / (world.scaleY / leaf.scaleY);
2887
- renderBounds = leaf.getBounds('render', 'local');
2888
- }
2889
- let { x, y, width, height } = renderBounds;
2890
- if (scale) {
2891
- matrix.scale(scale);
2892
- width *= scale, height *= scale;
2893
- scaleX *= scale, scaleY *= scale;
2887
+ const location = options.location || ((isLeafer || isFrame) ? 'inner' : 'local');
2888
+ scaleX = worldTransform.scaleX;
2889
+ scaleY = worldTransform.scaleY;
2890
+ switch (location) {
2891
+ case 'inner':
2892
+ matrix.set(worldTransform).invert();
2893
+ break;
2894
+ case 'local':
2895
+ matrix.set(worldTransform).divide(leaf.localTransform).invert();
2896
+ scaleX /= leaf.scaleX;
2897
+ scaleY /= leaf.scaleY;
2898
+ break;
2899
+ case 'world':
2900
+ scaleX = 1;
2901
+ scaleY = 1;
2902
+ break;
2903
+ }
2904
+ renderBounds = leaf.getBounds('render', location);
2894
2905
  }
2895
- let canvas = Creator.canvas({ width: Math.ceil(width), height: Math.ceil(height), pixelRatio });
2896
- const renderOptions = { matrix: matrix.translate(-x, -y).withScale(scaleX, scaleY) };
2906
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scale).ceil();
2907
+ let canvas = Creator.canvas({ width, height, pixelRatio });
2908
+ const renderOptions = { matrix: matrix.scale(scale).translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
2897
2909
  if (slice) {
2898
2910
  leaf = leafer;
2899
2911
  renderOptions.bounds = canvas.bounds;
2900
2912
  }
2901
2913
  canvas.save();
2902
- leaf.__render(canvas, renderOptions);
2914
+ if (isFrame && fill !== undefined) {
2915
+ const oldFill = leaf.get('fill');
2916
+ leaf.fill = '';
2917
+ leaf.__render(canvas, renderOptions);
2918
+ leaf.fill = oldFill;
2919
+ }
2920
+ else {
2921
+ leaf.__render(canvas, renderOptions);
2922
+ }
2903
2923
  canvas.restore();
2904
2924
  if (trim) {
2905
2925
  trimBounds = getTrimBounds(canvas);
@@ -2910,6 +2930,8 @@ const ExportModule = {
2910
2930
  }
2911
2931
  if (needFill)
2912
2932
  canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
2933
+ if (onCanvas)
2934
+ onCanvas(canvas);
2913
2935
  const data = filename === 'canvas' ? canvas : yield canvas.export(filename, options);
2914
2936
  over({ data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds });
2915
2937
  }));
@@ -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,FileHelper as l,LeafList as d,RenderEvent as c,ChildEvent as u,WatchEvent as p,PropertyEvent as g,LeafHelper as f,BranchHelper as _,Bounds as w,LeafBoundsHelper as y,LeafLevelList as v,LayoutEvent as m,Run as x,ImageManager as b,AnimateEvent as B,BoundsHelper as E,Answer as L,MatrixHelper as M,ImageEvent as R,PointHelper as k,Direction4 as T,TwoPointBoundsHelper as S,TaskProcessor as C,Matrix as O}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionHelper as W,Platform as P,MathHelper as A,InteractionBase as D,Cursor as I,HitCanvasManager as F}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as Y,ColorConvert as G,PaintGradient as z,Export as V,Group as U,TextConvert as N,Paint as j,Effect as X}from"@leafer-ui/draw";const H=t.get("LeaferCanvas");class K extends e{init(){const{view:t}=this.config;t?this.__createViewFrom(t):this.__createView();const{style:e}=this.view;e.display||(e.display="block"),this.parentView=this.view.parentElement,this.parentView&&(this.parentView.style.userSelect="none"),i.syncDomFont&&!this.parentView&&(this.view.style.display="none",document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(this.config)}set backgroundColor(t){this.view.style.backgroundColor=t}get backgroundColor(){return this.view.style.backgroundColor}set hittable(t){this.view.style.pointerEvents=t?"auto":"none"}get hittable(){return"none"!==this.view.style.pointerEvents}__createView(){this.view=document.createElement("canvas")}__createViewFrom(t){let e="string"==typeof t?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:i}=e;i.position="absolute",i.top=i.bottom=i.left=i.right="0px",document.body.appendChild(e),t=e}this.__createView();const i=this.view;if(t.hasChildNodes()){const{style:e}=i;e.position="absolute",e.top=e.left="0px",t.style.position||(t.style.position="relative")}t.appendChild(i)}else H.error(`no id: ${t}`),this.__createView()}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;s.width=t+"px",s.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.clientBounds=this.view.getBoundingClientRect()}startAutoLayout(t,e){this.autoBounds=t,this.resizeListener=e;try{this.resizeObserver=new ResizeObserver((t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)}));const t=this.parentView;t&&(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect()))}catch(t){this.imitateResizeObserver()}}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}checkAutoBounds(t){const e=this.view,{x:i,y:r,width:a,height:h}=this.autoBounds.getBoundsFrom(t);if(a!==this.width||h!==this.height){const{style:t}=e,{pixelRatio:l}=this;t.marginLeft=i+"px",t.marginTop=r+"px";const d={width:a,height:h,pixelRatio:l},c={};s.copyAttrs(c,this,n),this.resize(d),void 0!==this.width&&this.resizeListener(new o(d,c))}}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}unrealCanvas(){if(!this.unreal&&this.parentView){const t=this.view;t&&t.remove(),this.view=this.parentView,this.unreal=!0}}destroy(){if(this.view){if(this.stopAutoLayout(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}r(CanvasRenderingContext2D.prototype),r(Path2D.prototype);const{mineType:q,fileType:Q}=l;function $(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,i)=>new Promise((s=>{let n=document.createElement("a");n.href=t.toDataURL(q(Q(e)),i),n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),s()})),loadImage:t=>new Promise(((e,s)=>{const n=new Image,{suffix:o,crossOrigin:r}=i.image;r&&(n.setAttribute("crossOrigin",r),n.crossOrigin=r),n.onload=()=>{e(n)},n.onerror=t=>{s(t)},t.startsWith("data:")||t.startsWith("blob:")||!o||(t+=(t.includes("?")?"&":"?")+o),n.src=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)},i.devicePixelRatio=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 J{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new d;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 d,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(c.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===u.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 p(p.DATA,{updatedList:this.updatedList})),this.__updatedList=new d,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(g.CHANGE,this.__onAttrChange,this),t.on_([u.ADD,u.REMOVE],this.__onChildEvent,this),t.on_(p.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:tt,updateBounds:et,updateAllWorldOpacity:it}=f,{pushAllChildBranch:st,pushAllParent:nt}=_;const{worldBounds:ot}=y,rt={x:0,y:0,width:1e5,height:1e5};class at{constructor(t){this.updatedBounds=new w,this.beforeBounds=new w,this.afterBounds=new w,t instanceof Array&&(t=new d(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,ot)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(rt):this.afterBounds.setListWithFn(t,ot),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:ht,updateAllChange:lt}=f,dt=t.get("Layouter");class ct{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new v,this.target=t,e&&(this.config=s.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(m.START),this.layoutOnce(),t.emitEvent(new m(m.END,this.layoutedBlocks,this.times))}catch(t){dt.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?dt.warn("layouting"):this.times>3?dt.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(p.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=x.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:o,AFTER:r}=m,a=this.getBlocks(s);a.forEach((t=>t.setBefore())),i.emitEvent(new m(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?(tt(t,!0),e.add(t),t.isBranch&&st(t,e),nt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),nt(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||et(s[t])}et(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&it(t),t.__updateChange()}))}(s),this.extraBlock&&a.push(this.extraBlock),a.forEach((t=>t.setAfter())),i.emitEvent(new m(o,a,this.times)),i.emitEvent(new m(r,a,this.times)),this.addBlocks(a),this.__levelList.reset(),this.__updatedList=null,x.end(e)}fullLayout(){const t=x.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=m,o=this.getBlocks(new d(e));e.emitEvent(new m(i,o,this.times)),ct.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new m(s,o,this.times)),e.emitEvent(new m(n,o,this.times)),this.addBlocks(o),x.end(t)}static fullLayout(t){ht(t,!0),t.isBranch?_.updateBounds(t):f.updateBounds(t),lt(t)}addExtra(t){const e=this.extraBlock||(this.extraBlock=new at([]));e.updatedList.add(t),e.beforeBounds.add(t.__world)}createBlock(t){return new at(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_(p.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const ut=t.get("Renderer");class pt{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(),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 w,ut.log(e.innerName,"---\x3e");try{this.emitRender(c.START),this.renderOnce(t),this.emitRender(c.END,this.totalBounds),b.clearRecycled()}catch(t){this.rendering=!1,ut.error(t)}ut.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){return this.rendering?ut.warn("rendering"):this.times>3?ut.warn("render max times"):(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new w,this.renderOptions={},t?(this.emitRender(c.BEFORE),t()):(this.requestLayout(),this.emitRender(c.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()),this.emitRender(c.RENDER,this.renderBounds,this.renderOptions),this.emitRender(c.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,void(this.waitAgain&&(this.waitAgain=!1,this.renderOnce())))}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return ut.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const i=x.start("PartRender"),{canvas:s}=this,n=e.getIntersect(s.bounds),o=e.includes(this.target.__world),r=new w(n);s.save(),o&&!t.showRepaint?s.clear():(n.spread(1+1/this.canvas.pixelRatio).ceil(),s.clearWorld(n,!0),s.clipWorld(n,!0)),this.__render(n,o,r),s.restore(),x.end(i)}fullRender(){const t=x.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),x.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||e,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),t.showHitView&&this.renderHitView(n),t.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 w;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();i.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(c.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal&&(t.bigger||!t.samePixelRatio)){const{width:e,height:i}=t.old;new w(0,0,e,i).includes(this.target.__world)&&!this.needFill&&t.samePixelRatio||(this.addBlock(this.canvas.bounds),this.target.forceUpdate("surface"))}}__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||ut.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 c(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(c.REQUEST,this.update,this),t.on_(m.END,this.__onLayoutEnd,this),t.on_(c.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=null,this.canvas=null,this.config=null)}}const{hitRadiusPoint:gt}=E;class ft{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=i.findList||[],i.findList||this.eachFind(o.children,o.__onlyHitMask);const r=this.findList,a=this.getBestMatchLeaf(),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(){const{findList:t}=this;if(t.length>1){let e;this.findList=[];const{x:i,y:s}=this.point,n={x:i,y:s,radiusX:0,radiusY:0};for(let i=0,s=t.length;i<s;i++)if(e=t[i],f.worldHittable(e)&&(this.hitChild(e,n),this.findList.length))return this.findList[0]}return t[0]}getPath(t){const e=new d;for(;t;)e.add(t),t=t.parent;return e.add(this.target),e}getHitablePath(t){const e=this.getPath(t);let i,s=new d;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 d,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}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||gt(i.__world,n),i.isBranch?(s||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&!this.findList.length&&this.hitChild(i,n)):s&&this.hitChild(i,n))}hitChild(t,e){this.exclude&&this.exclude.has(t)||t.__hitWorld(e)&&this.findList.push(t)}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}const{Yes:_t,NoAndSkip:wt,YesAndSkip:yt}=L;class vt{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},this.target=t,e&&(this.config=s.default(e,this.config)),this.picker=new ft(t,this),this.__listenEvents()}getBy(t,e,i,s){switch(typeof t){case"number":const n=this.getByInnerId(t,e);return i?n:n?[n]:[];case"string":switch(t[0]){case"#":const s=this.getById(t.substring(1),e);return i?s:s?[s]:[];case".":return this.getByMethod(this.methods.className,e,i,t.substring(1));default:return this.getByMethod(this.methods.tag,e,i,t)}case"function":return this.getByMethod(t,e,i,s)}}getByPoint(t,e,s){return"node"===i.name&&this.target.emit(m.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&&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,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===_t||o===yt){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&o<wt&&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_(u.REMOVE,this.__onRemoveChild,this),this.target.on_(g.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 J(t,e),layouter:(t,e)=>new ct(t,e),renderer:(t,e,i)=>new pt(t,e,i),selector:(t,e)=>new vt(t,e)}),i.layout=ct.fullLayout;const mt={convert(t,e){const i=W.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=W.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=mt.getTouch(t),s=W.getBase(t);return Object.assign(Object.assign({},s),{x:e.x,y:e.y,width:1,height:1,pointerType:"touch",pressure:i.force})},getTouch:t=>t.targetTouches[0]||t.changedTouches[0]},xt={getMove(t,e){let{moveSpeed:i}=e,{deltaX:s,deltaY:n}=t;return t.shiftKey&&!s&&(s=n,n=0),s>50&&(s=Math.max(50,s/3)),n>50&&(n=Math.max(50,n/3)),{x:-s*i*2,y:-n*i*2}},getScale(t,e){let i,s=1,{zoomMode:n,zoomSpeed:o}=e;const r=t.deltaY||t.deltaX;if(n?(i="mouse"===n||!t.deltaX&&(P.intWheelDeltaY?Math.abs(r)>17:Math.ceil(r)!==r),(t.shiftKey||t.metaKey||t.ctrlKey)&&(i=!0)):i=!t.shiftKey&&(t.metaKey||t.ctrlKey),i){o=A.within(o,0,1);s=1-r/(4*(t.deltaY?e.delta.y:e.delta.x))*o,s<.5&&(s=.5),s>=1.5&&(s=1.5)}return s}},bt={convert(t){const e=W.getBase(t);return Object.assign(Object.assign({},e),{code:t.code,key:t.key})}},{getMoveEventData:Bt,getZoomEventData:Et,getRotateEventData:Lt}=W;class Mt extends D{__listenEvents(){super.__listenEvents();const t=this.view=this.canvas.view;this.viewEvents={pointerdown:this.onPointerDown,mousedown:this.onMouseDown,touchstart:this.onTouchStart,contextmenu:this.onContextMenu,wheel:this.onWheel,gesturestart:this.onGesturestart,gesturechange:this.onGesturechange,gestureend:this.onGestureend},this.windowEvents={pointermove:this.onPointerMove,pointerup:this.onPointerUp,pointercancel:this.onPointerCancel,mousemove:this.onMouseMove,mouseup:this.onMouseUp,touchmove:this.onTouchMove,touchend:this.onTouchEnd,touchcancel:this.onTouchCancel,keydown:this.onKeyDown,keyup:this.onKeyUp,scroll:this.onScroll};const{viewEvents:e,windowEvents:i}=this;for(let i in e)e[i]=e[i].bind(this),t.addEventListener(i,e[i]);for(let t in i)i[t]=i[t].bind(this),window.addEventListener(t,i[t])}__removeListenEvents(){super.__removeListenEvents();const{viewEvents:t,windowEvents:e}=this;for(let e in t)this.view.removeEventListener(e,t[e]),this.viewEvents={};for(let t in e)window.removeEventListener(t,e[t]),this.windowEvents={}}getLocal(t,e){e&&this.canvas.updateClientBounds();const{clientBounds:i}=this.canvas;return{x:t.clientX-i.x,y:t.clientY-i.y}}getTouches(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push(t[i]);return e}preventDefaultPointer(t){const{pointer:e}=this.config;e.preventDefault&&t.preventDefault()}preventDefaultWheel(t){const{wheel:e}=this.config;e.preventDefault&&t.preventDefault()}preventWindowPointer(t){return!this.downData&&t.target!==this.view}onKeyDown(t){this.keyDown(bt.convert(t))}onKeyUp(t){this.keyUp(bt.convert(t))}onContextMenu(t){this.config.pointer.preventDefaultMenu&&t.preventDefault(),this.menu(mt.convert(t,this.getLocal(t)))}onScroll(){this.canvas.updateClientBounds()}onPointerDown(t){this.preventDefaultPointer(t),this.usePointer||(this.usePointer=!0),this.useMultiTouch||this.pointerDown(mt.convert(t,this.getLocal(t)))}onPointerMove(t){this.usePointer||(this.usePointer=!0),this.useMultiTouch||this.preventWindowPointer(t)||this.pointerMove(mt.convert(t,this.getLocal(t,!0)))}onPointerUp(t){this.downData&&this.preventDefaultPointer(t),this.useMultiTouch||this.preventWindowPointer(t)||this.pointerUp(mt.convert(t,this.getLocal(t)))}onPointerCancel(){this.useMultiTouch||this.pointerCancel()}onMouseDown(t){this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.pointerDown(mt.convertMouse(t,this.getLocal(t)))}onMouseMove(t){this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerMove(mt.convertMouse(t,this.getLocal(t,!0)))}onMouseUp(t){this.downData&&this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerUp(mt.convertMouse(t,this.getLocal(t)))}onMouseCancel(){this.useTouch||this.usePointer||this.pointerCancel()}onTouchStart(t){if(t.preventDefault(),this.multiTouchStart(t),this.usePointer)return;this.touchTimer&&(window.clearTimeout(this.touchTimer),this.touchTimer=0),this.useTouch=!0;const e=mt.getTouch(t);this.pointerDown(mt.convertTouch(t,this.getLocal(e,!0)))}onTouchMove(t){if(this.multiTouchMove(t),this.usePointer||this.preventWindowPointer(t))return;const e=mt.getTouch(t);this.pointerMove(mt.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=mt.getTouch(t);this.pointerUp(mt.convertTouch(t,this.getLocal(e)))}onTouchCancel(){this.usePointer||this.pointerCancel()}multiTouchStart(t){this.useMultiTouch=t.touches.length>=2,this.touches=this.useMultiTouch?this.getTouches(t.touches):void 0,this.useMultiTouch&&this.pointerCancel()}multiTouchMove(t){if(this.useMultiTouch&&t.touches.length>1){const e=this.getTouches(t.touches),i=this.getKeepTouchList(this.touches,e);i.length>1&&(this.multiTouch(W.getBase(t),i),this.touches=e)}}multiTouchEnd(){this.touches=null,this.useMultiTouch=!1,this.transformEnd()}getKeepTouchList(t,e){let i;const s=[];return t.forEach((t=>{i=e.find((e=>e.identifier===t.identifier)),i&&s.push({from:this.getLocal(t),to:this.getLocal(i)})})),s}getLocalTouchs(t){return t.map((t=>this.getLocal(t)))}onWheel(t){this.preventDefaultWheel(t);const{wheel:e}=this.config,i=e.getScale?e.getScale(t,e):xt.getScale(t,e),s=this.getLocal(t),n=W.getBase(t);1!==i?this.zoom(Et(s,i,n)):this.move(Bt(s,e.getMove?e.getMove(t,e):xt.getMove(t,e),n))}onGesturestart(t){this.preventDefaultWheel(t),this.lastGestureScale=1,this.lastGestureRotation=0}onGesturechange(t){this.preventDefaultWheel(t);const e=this.getLocal(t),i=W.getBase(t),s=t.scale/this.lastGestureScale,n=t.rotation-this.lastGestureRotation;let{rotateSpeed:o}=this.config.wheel;o=A.within(o,0,1),this.zoom(Et(e,s*s,i)),this.rotate(Lt(e,n/Math.PI*180*(o/4+.1),i)),this.lastGestureScale=t.scale,this.lastGestureRotation=t.rotation}onGestureend(t){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&&I.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 Rt(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 kt(t,e,i){const{strokeAlign:s}=e.__,n="string"!=typeof t;switch(s){case"center":i.setStroke(n?void 0:t,e.__.strokeWidth,e.__),n?Ct(t,!0,e,i):St(e,i);break;case"inside":Tt("inside",t,n,e,i);break;case"outside":Tt("outside",t,n,e,i)}}function Tt(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?Ct(e,!0,s,a):St(s,a),a.blendMode="outside"===t?"destination-out":"destination-in",Rt(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 St(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 Ct(t,e,i,s){let n;for(let o=0,r=t.length;o<r;o++)n=t[o],n.image&&Y.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?St(i,s):s.stroke(),s.restoreBlendMode()):e?St(i,s):s.stroke())}const{getSpread:Ot,getOuterOf:Wt,getByMove:Pt,getIntersectData:At}=E;let Dt;function It(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:G.string(r,a)};case"image":return Y.image(i,t,e,s,!Dt||!Dt[e.url]);case"linear":return z.linearGradient(e,s);case"radial":return z.radialGradient(e,s);case"angular":return z.conicGradient(e,s);default:return e.r?{type:"solid",style:G.string(e)}:void 0}}const Ft={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),Dt=Y.recycleImage(t,i);for(let i,n=0,r=o.length;n<r;n++)i=It(t,o[n],e),i&&s.push(i);i["_"+t]=s.length?s:void 0,s.length&&s[0].image&&(n=s[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=n:i.__pixelStroke=n},fill:function(t,e,i){i.fillStyle=t,e.__.__font?Rt(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let s;const{windingRule:n,__font:o}=e.__;for(let r=0,a=t.length;r<a;r++)s=t[r],s.image&&Y.checkImage(e,i,s,!o)||s.style&&(i.fillStyle=s.style,s.transform?(i.save(),i.transform(s.transform),s.blendMode&&(i.blendMode=s.blendMode),o?Rt(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?Rt(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?Rt(e,i):n?i.fill(n):i.fill())},fillText:Rt,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:r}=s;if(n)if(r)kt(t,e,i);else switch(o){case"center":i.setStroke(t,n,s),i.stroke();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)kt(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),Ct(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),Ct(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,r=i.getSameCanvas(!0,!0);e.__drawRenderPath(r),r.setStroke(void 0,2*n,s),Ct(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:kt,drawTextStroke:St,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=At(s?Ot(e.bounds,s*l,s*d):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=Pt(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:zt,translate:Vt,scaleOfOuter:Ut,scale:Nt,rotate:jt}=M;function Xt(t,e,i,s,n,o){const r=Gt(),a=o&&180!==o,h=i.width/(a?n:s),l=i.height/(a?s:n),d="fit"===e?Math.min(h,l):Math.max(h,l),c=i.x+(i.width-s*d)/2,u=i.y+(i.height-n*d)/2;Vt(r,c,u),Nt(r,d),o&&zt(r,{x:i.x+i.width/2,y:i.y+i.height/2},o),t.scaleX=t.scaleY=d,t.transform=r}function Ht(t,e,i,s,n,o,r){const a=Gt();Vt(a,e.x,e.y),(i||s)&&Vt(a,i,s),n&&(Nt(a,n,o),t.scaleX=a.a,t.scaleY=a.d),r&&jt(a,r),t.transform=a}function Kt(t,e,i,s,n,o,r,a,h){const l=Gt();if(h)switch(jt(l,h),h){case 90:Vt(l,s,0);break;case 180:Vt(l,i,s);break;case 270:Vt(l,0,i)}Yt.x=e.x,Yt.y=e.y,(n||o)&&(Yt.x+=n,Yt.y+=o),Vt(l,Yt.x,Yt.y),r&&(Ut(l,Yt,r,a),t.scaleX=r,t.scaleY=a),t.transform=l}const{get:qt,translate:Qt}=M;function $t(t,e,i,s){let{width:n,height:o}=e;const{opacity:r,mode:a,offset:h,scale:l,size:d,rotation:c,blendMode:u,repeat:p}=i,g=s.width===n&&s.height===o;u&&(t.blendMode=u);const f=t.data={mode:a};let _,w,y,v;switch(h&&(_=h.x,w=h.y),d?(y=("number"==typeof d?d:d.width)/n,v=("number"==typeof d?d:d.height)/o):l&&(y="number"==typeof l?l:l.x,v="number"==typeof l?l:l.y),a){case"strench":g||(n=s.width,o=s.height),(s.x||s.y)&&(f.transform=qt(),Qt(f.transform,s.x,s.y));break;case"clip":(h||y||c)&&Ht(f,s,_,w,y,v,c);break;case"repeat":(!g||y||c)&&Kt(f,s,n,o,_,w,y,v,c),p||(f.repeat="repeat");break;default:g&&!c||Xt(f,a,s,n,o,c)}f.width=n,f.height=o,r&&(f.opacity=r),p&&(f.repeat="string"==typeof p?"x"===p?"repeat-x":"repeat-y":"repeat")}let Zt,Jt=new w;const{isSame:te}=E;function ee(t,e,i,s,n,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=s.width,e.__naturalHeight=s.height,e.__autoWidth||e.__autoHeight)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return n.data||$t(n,s,i,o),!0}function ie(t,e){oe(t,R.LOAD,e)}function se(t,e){oe(t,R.LOADED,e)}function ne(t,e,i){e.error=i,t.forceUpdate("surface"),oe(t,R.ERROR,e)}function oe(t,e,i){t.hasEvent(e)&&t.emitEvent(new R(e,i))}const{get:re,scale:ae,copy:he}=M,{round:le,abs:de}=Math;function ce(t,e,s){let{scaleX:n,scaleY:o}=t.__world;const r=n+"-"+o;if(e.patternId===r||t.destroyed)return!1;{n=de(n),o=de(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=re(),he(l,f),ae(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 y=i.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(h=Math.sqrt(w/y)),h&&(n/=h,o/=h,d/=h,c/=h),u&&(n/=u,o/=p),(f||1!==n||1!==o)&&(l||(l=re(),f&&he(l,f)),ae(l,1/n,1/o));const v=t.getCanvas(d<1?1:le(d),c<1?1:le(c),g),m=t.getPattern(v,_||i.origin.noRepeat||"no-repeat",l,e);return e.style=m,e.patternId=r,!0}}function ue(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:pe}=Math;const ge={image:function(t,e,i,s,n){let o,r;const a=b.get(i);return Zt&&i===Zt.paint&&te(s,Zt.boxBounds)?o=Zt.leafPaint:(o={type:i.type},o.image=a,Zt=a.use>1?{leafPaint:o,paint:i,boxBounds:Jt.set(s)}:null),(n||a.loading)&&(r={image:a,attrName:e,attrValue:i}),a.ready?(ee(t,e,i,a,o,s),n&&(ie(t,r),se(t,r))):a.error?n&&ne(t,r,a.error):(n&&ie(t,r),o.loadId=a.load((()=>{t.destroyed||(ee(t,e,i,a,o,s)&&t.forceUpdate("surface"),se(t,r)),o.loadId=null}),(e=>{ne(t,r,e),o.loadId=null}))),o},createData:$t,fillOrFitMode:Xt,clipMode:Ht,repeatMode:Kt,createPattern:ce,checkImage:function(t,e,s,n){const{scaleX:o,scaleY:r}=t.__world;if(s.data&&s.patternId!==o+"-"+r){const{data:a}=s;if(n)if(a.repeat)n=!1;else{let{width:t,height:s}=a;t*=pe(o)*e.pixelRatio,s*=pe(r)*e.pixelRatio,a.scaleX&&(t*=a.scaleX,s*=a.scaleY),n=t*s>i.image.maxCacheSize}return n?(e.save(),e.clip(),s.blendMode&&(e.blendMode=s.blendMode),a.opacity&&(e.opacity*=a.opacity),a.transform&&e.transform(a.transform),e.drawImage(s.image.view,0,0,a.width,a.height),e.restore(),!0):(!s.style||V.running?ce(t,s,e.pixelRatio):s.patternTask||(s.patternTask=b.patternTasker.add((()=>ue(this,void 0,void 0,(function*(){s.patternTask=null,e.bounds.hit(t.__world)&&ce(t,s,e.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},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}},fe={x:.5,y:0},_e={x:.5,y:1};function we(t,e,i){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],t.addColorStop(s.offset,G.string(s.color,i))}const{set:ye,getAngle:ve,getDistance:me}=k,{get:xe,rotateOfOuter:be,scaleOfOuter:Be}=M,Ee={x:.5,y:.5},Le={x:.5,y:1},Me={},Re={};const{set:ke,getAngle:Te,getDistance:Se}=k,{get:Ce,rotateOfOuter:Oe,scaleOfOuter:We}=M,Pe={x:.5,y:.5},Ae={x:.5,y:1},De={},Ie={};const Fe={linearGradient:function(t,e){let{from:s,to:n,type:o,blendMode:r,opacity:a}=t;s||(s=fe),n||(n=_e);const h=i.canvas.createLinearGradient(e.x+s.x*e.width,e.y+s.y*e.height,e.x+n.x*e.width,e.y+n.y*e.height);we(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;s||(s=Ee),n||(n=Le);const{x:l,y:d,width:c,height:u}=e;let p;ye(Me,l+s.x*c,d+s.y*u),ye(Re,l+n.x*c,d+n.y*u),(c!==u||h)&&(p=xe(),Be(p,Me,c/u*(h||1),1),be(p,Me,ve(Me,Re)+90));const g=i.canvas.createRadialGradient(Me.x,Me.y,0,Me.x,Me.y,me(Me,Re));we(g,t.stops,r);const f={type:o,style:g,transform:p};return a&&(f.blendMode=a),f},conicGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;s||(s=Pe),n||(n=Ae);const{x:l,y:d,width:c,height:u}=e;ke(De,l+s.x*c,d+s.y*u),ke(Ie,l+n.x*c,d+n.y*u);const p=Ce(),g=Te(De,Ie);i.conicGradientRotate90?(We(p,De,c/u*(h||1),1),Oe(p,De,g+90)):(We(p,De,1,c/u*(h||1)),Oe(p,De,g));const f=i.conicGradientSupport?i.canvas.createConicGradient(0,De.x,De.y):i.canvas.createRadialGradient(De.x,De.y,0,De.x,De.y,Se(De,Ie));we(f,t.stops,r);const _={type:o,style:f,transform:p};return a&&(_.blendMode=a),_}},{copy:Ye,toOffsetOutBounds:Ge}=E,ze={},Ve={};function Ue(t,e,s,n){const{bounds:o,shapeBounds:r}=n;if(i.fullImageShadow){if(Ye(ze,t.bounds),ze.x+=e.x-r.x,ze.y+=e.y-r.y,s){const{matrix:t}=n;ze.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),ze.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),ze.width*=s,ze.height*=s}t.copyWorld(n.canvas,t.bounds,ze)}else s&&(Ye(ze,e),ze.x-=e.width/2*(s-1),ze.y-=e.height/2*(s-1),ze.width*=s,ze.height*=s),t.copyWorld(n.canvas,r,s?ze:e)}const{toOffsetOutBounds:Ne}=E,je={};const Xe={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;Ge(l,Ve),a.forEach(((a,f)=>{p.setWorldShadow(Ve.offsetX+a.x*c,Ve.offsetY+a.y*u,a.blur*c,a.color),n=a.spread?1+2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,Ue(p,Ve,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,je),a.forEach(((a,f)=>{p.save(),p.setWorldShadow(je.offsetX+a.x*c,je.offsetY+a.y*u,a.blur*c),n=a.spread?1-2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,Ue(p,je,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.__world.a),i.copyWorldToInner(e,t.__world,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:He}=y;function Ke(t,e,i,s,n,o){switch(e){case"alpha":!function(t,e,i,s){const n=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,n),s.recycle(n),Qe(t,e,i,1)}(t,i,s,n);break;case"opacity-path":Qe(t,i,s,o);break;case"path":i.restore()}}function qe(t){return t.getSameCanvas(!1,!0)}function Qe(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}U.prototype.__renderMask=function(t,e){let i,s,n,o,r;const{children:a}=this;for(let h=0,l=a.length;h<l;h++)i=a[h],i.__.mask&&(r&&(Ke(this,r,t,n,s,o),s=n=null),"path"===i.__.maskType?(i.opacity<1?(r="opacity-path",o=i.opacity,n||(n=qe(t))):(r="path",t.save()),i.__clip(n||t,e)):(r="alpha",s||(s=qe(t)),n||(n=qe(t)),i.__render(s,e)),"clipping"!==i.__.maskType)||He(i,e)||i.__render(n||t,e);Ke(this,r,t,n,s,o)};const $e=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Ze=$e+"_#~&*+\\=|≮≯≈≠=…",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 ti(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const ei=ti("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ii=ti("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),si=ti($e),ni=ti(Ze),oi=ti("- —/~|┆·");var ri;!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"}(ri||(ri={}));const{Letter:ai,Single:hi,Before:li,After:di,Symbol:ci,Break:ui}=ri;function pi(t){return ei[t]?ai:oi[t]?ui:ii[t]?li:si[t]?di:ni[t]?ci:Je.test(t)?hi:ai}const gi={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 fi(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:_i}=gi,{Letter:wi,Single:yi,Before:vi,After:mi,Symbol:xi,Break:bi}=ri;let Bi,Ei,Li,Mi,Ri,ki,Ti,Si,Ci,Oi,Wi,Pi,Ai,Di,Ii,Fi,Yi=[];function Gi(t,e){Ci&&!Si&&(Si=Ci),Bi.data.push({char:t,width:e}),Li+=e}function zi(){Mi+=Li,Bi.width=Li,Ei.words.push(Bi),Bi={data:[]},Li=0}function Vi(){Di&&(Ii.paraNumber++,Ei.paraStart=!0,Di=!1),Ci&&(Ei.startCharSize=Si,Ei.endCharSize=Ci,Si=0),Ei.width=Mi,Fi.width&&_i(Ei),Yi.push(Ei),Ei={words:[]},Mi=0}const Ui=0,Ni=1,ji=2;const{top:Xi,right:Hi,bottom:Ki,left:qi}=T;function Qi(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 $i={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[qi],o-=l[Hi]+l[qi]),r&&(n=l[Xi],r-=l[Xi]+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){Ii=t,Yi=t.rows,Fi=t.bounds;const{__letterSpacing:n,paraIndent:o,textCase:r}=s,{canvas:a}=i,{width:h,height:l}=Fi;if(h||l||n||"none"!==r){const t="none"!==s.textWrap,i="break"===s.textWrap;Di=!0,Wi=null,Si=Ti=Ci=Li=Mi=0,Bi={data:[]},Ei={words:[]};for(let s=0,l=e.length;s<l;s++)ki=e[s],"\n"===ki?(Li&&zi(),Ei.paraEnd=!0,Vi(),Di=!0):(Oi=pi(ki),Oi===wi&&"none"!==r&&(ki=fi(ki,r,!Li)),Ti=a.measureText(ki).width,n&&(n<0&&(Ci=Ti),Ti+=n),Pi=Oi===yi&&(Wi===yi||Wi===wi)||Wi===yi&&Oi!==mi,Ai=!(Oi!==vi&&Oi!==yi||Wi!==xi&&Wi!==mi),Ri=Di&&o?h-o:h,t&&h&&Mi+Li+Ti>Ri&&(i?(Li&&zi(),Vi()):(Ai||(Ai=Oi===wi&&Wi==mi),Pi||Ai||Oi===bi||Oi===vi||Oi===yi||Li+Ti>Ri?(Li&&zi(),Vi()):Vi()))," "===ki&&!0!==Di&&Mi+Li===0||(Oi===bi?(" "===ki&&Li&&zi(),Gi(ki,Ti),zi()):Pi||Ai?(Li&&zi(),Gi(ki,Ti)):Gi(ki,Ti)),Wi=Oi);Li&&zi(),Mi&&Vi(),Yi.length>0&&(Yi[Yi.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{Ii.paraNumber++,Yi.push({x:o||0,text:t,width:a.measureText(t).width,paraStart:!0})}))}(d,t,e),l&&function(t,e,i,s,n){if(!s)switch(i.textAlign){case"left":Qi(e,"x",t[qi]);break;case"right":Qi(e,"x",-t[Hi])}if(!n)switch(i.verticalAlign){case"top":Qi(e,"y",t[Xi]);break;case"bottom":Qi(e,"y",-t[Ki])}}(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}=e;let c,u,p,{x:g,y:f,width:_,height:w}=s,y=n*i.length+(d?d*(t.paraNumber-1):0),v=o;if(a&&y>w)y=Math.max(w,n),t.overflow=i.length;else switch(l){case"middle":f+=(w-y)/2;break;case"bottom":f+=w-y}v+=f;for(let o=0,l=i.length;o<l;o++){switch(c=i[o],c.x=g,h){case"center":c.x+=(_-c.width)/2;break;case"right":c.x+=_-c.width}c.paraStart&&d&&o>0&&(v+=d),c.y=v,v+=n,t.overflow>o&&v>y&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,p=c.width,r<0&&(c.width<0?(p=-c.width+e.fontSize+r,u-=p,p+=e.fontSize):p-=r),u<s.x&&(s.x=u),p>s.width&&(s.width=p),a&&_&&_<p&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=f,s.height=y}(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?Ui:l>.01?Ni:ji,t.isOverflow&&!a&&(t.textMode=!0),c===ji?(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===Ni?(u={char:"",x:h},h=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,h,u)," "!==u.char&&t.data.push(u)):h=function(t,e,i){return t.forEach((t=>{" "!==t.char&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,h,t.data),!t.paraEnd&&l&&(h+=l,t.width+=l)}))),t.words=null)}))}(d,e,o),d.overflow&&function(t,e){const{rows:s,overflow:n}=t;let{textOverflow:o}=e;if(s.splice(n),"hide"!==o){let t,r;"ellipsis"===o&&(o="...");const a=i.canvas.measureText(o).width,h=e.x+e.width-a;("none"===e.textWrap?s:[s[n-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],r=t.x+t.width,!(s===i&&r<h));s--){if(r<h&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=a,e.data.push({char:o,x:r}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(d,e),"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 Zi={string:function(t,e){if("string"==typeof t)return t;let i=void 0===t.a?1:t.a;e&&(i*=e);const s=t.r+","+t.g+","+t.b;return 1===i?"rgb("+s+")":"rgba("+s+","+i+")"}},{setPoint:Ji,addPoint:ts,toBounds:es}=S;const is={export(t,e,i){return this.running=!0,function(t){ss||(ss=new C);return new Promise((e=>{ss.add((()=>ue(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((s=>new Promise((n=>{const o=t=>{s(t),n(),this.running=!1},{leafer:r}=t;r?r.waitViewCompleted((()=>ue(this,void 0,void 0,(function*(){let s,n,h=1,d=1;i=l.getExportOptions(i);const{scale:c,slice:u,trim:p}=i,g=i.pixelRatio||1,f=i.screenshot||t.isApp,_=void 0===i.fill?t.isLeafer&&f?t.fill:"":i.fill,y=l.isOpaqueImage(e)||_,v=new O;if(f)s=!0===f?t.isLeafer?r.canvas.bounds:t.worldRenderBounds:f;else{const{localTransform:e,__world:i}=t;v.set(i).divide(e).invert(),h=1/(i.scaleX/t.scaleX),d=1/(i.scaleY/t.scaleY),s=t.getBounds("render","local")}let{x:m,y:x,width:b,height:B}=s;c&&(v.scale(c),b*=c,B*=c,h*=c,d*=c);let E=a.canvas({width:Math.ceil(b),height:Math.ceil(B),pixelRatio:g});const L={matrix:v.translate(-m,-x).withScale(h,d)};if(u&&(t=r,L.bounds=E.bounds),E.save(),t.__render(E,L),E.restore(),p){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?ts(r,n,o):Ji(r={},n,o)),a++;const h=new w;return es(r,h),h.scale(1/t.pixelRatio).ceil()}(E);const t=E,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:g};E=a.canvas(s),E.copyWorld(t,n,s)}y&&E.fillWorld(E.bounds,_||"#FFFFFF","destination-over");const M="canvas"===e?E:yield E.export(e,i);o({data:M,width:E.pixelWidth,height:E.pixelHeight,renderBounds:s,trimBounds:n})})))):o({data:!1})}))))}};let ss;Object.assign(N,$i),Object.assign(G,Zi),Object.assign(j,Ft),Object.assign(Y,ge),Object.assign(z,Fe),Object.assign(X,Xe),Object.assign(V,is),Object.assign(a,{interaction:(t,e,i,s)=>new Mt(t,e,i,s),hitCanvas:(t,e)=>new K(t,e),hitCanvasManager:()=>new F}),$();export{Mt as Interaction,ct as Layouter,K as LeaferCanvas,pt as Renderer,vt as Selector,J as Watcher,$ 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,FileHelper as l,LeafList as d,RenderEvent as c,ChildEvent as u,WatchEvent as p,PropertyEvent as g,LeafHelper as f,BranchHelper as _,Bounds as w,LeafBoundsHelper as y,LeafLevelList as v,LayoutEvent as m,Run as x,ImageManager as b,AnimateEvent as B,BoundsHelper as E,Answer as L,MathHelper as M,MatrixHelper as R,ImageEvent as k,PointHelper as T,Direction4 as S,TwoPointBoundsHelper as C,TaskProcessor as O,Matrix as W}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{InteractionHelper as A,InteractionBase as P,MathHelper as D,Cursor as I,HitCanvasManager as F}from"@leafer-ui/core";export*from"@leafer-ui/core";import{PaintImage as Y,ColorConvert as G,PaintGradient as z,Export as V,Group as U,TextConvert as N,Paint as j,Effect as X}from"@leafer-ui/draw";const H=t.get("LeaferCanvas");class K extends e{init(){const{view:t}=this.config;t?this.__createViewFrom(t):this.__createView();const{style:e}=this.view;e.display||(e.display="block"),this.parentView=this.view.parentElement,this.parentView&&(this.parentView.style.userSelect="none"),i.syncDomFont&&!this.parentView&&(this.view.style.display="none",document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(this.config)}set backgroundColor(t){this.view.style.backgroundColor=t}get backgroundColor(){return this.view.style.backgroundColor}set hittable(t){this.view.style.pointerEvents=t?"auto":"none"}get hittable(){return"none"!==this.view.style.pointerEvents}__createView(){this.view=document.createElement("canvas")}__createViewFrom(t){let e="string"==typeof t?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:i}=e;i.position="absolute",i.top=i.bottom=i.left=i.right="0px",document.body.appendChild(e),t=e}this.__createView();const i=this.view;if(t.hasChildNodes()){const{style:e}=i;e.position="absolute",e.top=e.left="0px",t.style.position||(t.style.position="relative")}t.appendChild(i)}else H.error(`no id: ${t}`),this.__createView()}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this,{style:s}=this.view;s.width=t+"px",s.height=e+"px",this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(){this.clientBounds=this.view.getBoundingClientRect()}startAutoLayout(t,e){this.autoBounds=t,this.resizeListener=e;try{this.resizeObserver=new ResizeObserver((t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)}));const t=this.parentView;t&&(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect()))}catch(t){this.imitateResizeObserver()}}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),i.requestRender(this.imitateResizeObserver.bind(this)))}checkAutoBounds(t){const e=this.view,{x:i,y:r,width:a,height:h}=this.autoBounds.getBoundsFrom(t);if(a!==this.width||h!==this.height){const{style:t}=e,{pixelRatio:l}=this;t.marginLeft=i+"px",t.marginTop=r+"px";const d={width:a,height:h,pixelRatio:l},c={};s.copyAttrs(c,this,n),this.resize(d),void 0!==this.width&&this.resizeListener(new o(d,c))}}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}unrealCanvas(){if(!this.unreal&&this.parentView){const t=this.view;t&&t.remove(),this.view=this.parentView,this.unreal=!0}}destroy(){if(this.view){if(this.stopAutoLayout(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}r(CanvasRenderingContext2D.prototype),r(Path2D.prototype);const{mineType:q,fileType:Q}=l;function $(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,i)=>new Promise((s=>{let n=document.createElement("a");n.href=t.toDataURL(q(Q(e)),i),n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),s()})),loadImage:t=>new Promise(((e,s)=>{const n=new Image,{suffix:o,crossOrigin:r}=i.image;r&&(n.setAttribute("crossOrigin",r),n.crossOrigin=r),n.onload=()=>{e(n)},n.onerror=t=>{s(t)},t.startsWith("data:")||t.startsWith("blob:")||!o||(t+=(t.includes("?")?"&":"?")+o),n.src=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)},i.devicePixelRatio=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 J{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new d;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 d,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(c.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===u.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 p(p.DATA,{updatedList:this.updatedList})),this.__updatedList=new d,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(g.CHANGE,this.__onAttrChange,this),t.on_([u.ADD,u.REMOVE],this.__onChildEvent,this),t.on_(p.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:tt,updateBounds:et,updateAllWorldOpacity:it}=f,{pushAllChildBranch:st,pushAllParent:nt}=_;const{worldBounds:ot}=y,rt={x:0,y:0,width:1e5,height:1e5};class at{constructor(t){this.updatedBounds=new w,this.beforeBounds=new w,this.afterBounds=new w,t instanceof Array&&(t=new d(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,ot)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(rt):this.afterBounds.setListWithFn(t,ot),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:ht,updateAllChange:lt}=f,dt=t.get("Layouter");class ct{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new v,this.target=t,e&&(this.config=s.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(m.START),this.layoutOnce(),t.emitEvent(new m(m.END,this.layoutedBlocks,this.times))}catch(t){dt.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?dt.warn("layouting"):this.times>3?dt.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(p.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=x.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:n,LAYOUT:o,AFTER:r}=m,a=this.getBlocks(s);a.forEach((t=>t.setBefore())),i.emitEvent(new m(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?(tt(t,!0),e.add(t),t.isBranch&&st(t,e),nt(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),nt(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||et(s[t])}et(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&it(t),t.__updateChange()}))}(s),this.extraBlock&&a.push(this.extraBlock),a.forEach((t=>t.setAfter())),i.emitEvent(new m(o,a,this.times)),i.emitEvent(new m(r,a,this.times)),this.addBlocks(a),this.__levelList.reset(),this.__updatedList=null,x.end(e)}fullLayout(){const t=x.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=m,o=this.getBlocks(new d(e));e.emitEvent(new m(i,o,this.times)),ct.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new m(s,o,this.times)),e.emitEvent(new m(n,o,this.times)),this.addBlocks(o),x.end(t)}static fullLayout(t){ht(t,!0),t.isBranch?_.updateBounds(t):f.updateBounds(t),lt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new at([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new at(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_(p.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const ut=t.get("Renderer");class pt{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(),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 w,ut.log(e.innerName,"---\x3e");try{this.emitRender(c.START),this.renderOnce(t),this.emitRender(c.END,this.totalBounds),b.clearRecycled()}catch(t){this.rendering=!1,ut.error(t)}ut.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){return this.rendering?ut.warn("rendering"):this.times>3?ut.warn("render max times"):(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new w,this.renderOptions={},t?(this.emitRender(c.BEFORE),t()):(this.requestLayout(),this.emitRender(c.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()),this.emitRender(c.RENDER,this.renderBounds,this.renderOptions),this.emitRender(c.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,void(this.waitAgain&&(this.waitAgain=!1,this.renderOnce())))}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return ut.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const i=x.start("PartRender"),{canvas:s}=this,n=e.getIntersect(s.bounds),o=e.includes(this.target.__world),r=new w(n);s.save(),o&&!t.showRepaint?s.clear():(n.spread(1+1/this.canvas.pixelRatio).ceil(),s.clearWorld(n,!0),s.clipWorld(n,!0)),this.__render(n,o,r),s.restore(),x.end(i)}fullRender(){const t=x.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),x.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||e,this.renderOptions=n,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),t.showHitView&&this.renderHitView(n),t.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 w;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();i.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(c.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal&&(t.bigger||!t.samePixelRatio)){const{width:e,height:i}=t.old;new w(0,0,e,i).includes(this.target.__world)&&!this.needFill&&t.samePixelRatio||(this.addBlock(this.canvas.bounds),this.target.forceUpdate("surface"))}}__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||ut.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 c(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(c.REQUEST,this.update,this),t.on_(m.END,this.__onLayoutEnd,this),t.on_(c.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=null,this.canvas=null,this.config=null)}}const{hitRadiusPoint:gt}=E;class ft{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=i.findList||[],i.findList||this.eachFind(o.children,o.__onlyHitMask);const r=this.findList,a=this.getBestMatchLeaf(),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(){const{findList:t}=this;if(t.length>1){let e;this.findList=[];const{x:i,y:s}=this.point,n={x:i,y:s,radiusX:0,radiusY:0};for(let i=0,s=t.length;i<s;i++)if(e=t[i],f.worldHittable(e)&&(this.hitChild(e,n),this.findList.length))return this.findList[0]}return t[0]}getPath(t){const e=new d;for(;t;)e.add(t),t=t.parent;return e.add(this.target),e}getHitablePath(t){const e=this.getPath(t);let i,s=new d;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 d,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}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||gt(i.__world,n),i.isBranch?(s||i.__ignoreHitWorld)&&(this.eachFind(i.children,i.__onlyHitMask),i.isBranchLeaf&&!this.findList.length&&this.hitChild(i,n)):s&&this.hitChild(i,n))}hitChild(t,e){this.exclude&&this.exclude.has(t)||t.__hitWorld(e)&&this.findList.push(t)}clear(){this.point=null,this.findList=null,this.exclude=null}destroy(){this.clear()}}const{Yes:_t,NoAndSkip:wt,YesAndSkip:yt}=L;class vt{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},this.target=t,e&&(this.config=s.default(e,this.config)),this.picker=new ft(t,this),this.__listenEvents()}getBy(t,e,i,s){switch(typeof t){case"number":const n=this.getByInnerId(t,e);return i?n:n?[n]:[];case"string":switch(t[0]){case"#":const s=this.getById(t.substring(1),e);return i?s:s?[s]:[];case".":return this.getByMethod(this.methods.className,e,i,t.substring(1));default:return this.getByMethod(this.methods.tag,e,i,t)}case"function":return this.getByMethod(t,e,i,s)}}getByPoint(t,e,s){return"node"===i.name&&this.target.emit(m.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&&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,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===_t||o===yt){if(!i)return void(this.findLeaf=n);i.push(n)}n.isBranch&&o<wt&&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_(u.REMOVE,this.__onRemoveChild,this),this.target.on_(g.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 J(t,e),layouter:(t,e)=>new ct(t,e),renderer:(t,e,i)=>new pt(t,e,i),selector:(t,e)=>new vt(t,e)}),i.layout=ct.fullLayout;const mt={convert(t,e){const i=A.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=A.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=mt.getTouch(t),s=A.getBase(t);return Object.assign(Object.assign({},s),{x:e.x,y:e.y,width:1,height:1,pointerType:"touch",pressure:i.force})},getTouch:t=>t.targetTouches[0]||t.changedTouches[0]},xt={getMove(t,e){let{moveSpeed:i}=e,{deltaX:s,deltaY:n}=t;return t.shiftKey&&!s&&(s=n,n=0),s>50&&(s=Math.max(50,s/3)),n>50&&(n=Math.max(50,n/3)),{x:-s*i*2,y:-n*i*2}},getScale(t,e){let s,n=1,{zoomMode:o,zoomSpeed:r}=e;const a=t.deltaY||t.deltaX;if(o?(s="mouse"===o||!t.deltaX&&(i.intWheelDeltaY?Math.abs(a)>17:Math.ceil(a)!==a),(t.shiftKey||t.metaKey||t.ctrlKey)&&(s=!0)):s=!t.shiftKey&&(t.metaKey||t.ctrlKey),s){r=M.within(r,0,1);n=1-a/(4*(t.deltaY?e.delta.y:e.delta.x))*r,n<.5&&(n=.5),n>=1.5&&(n=1.5)}return n}},bt={convert(t){const e=A.getBase(t);return Object.assign(Object.assign({},e),{code:t.code,key:t.key})}},{getMoveEventData:Bt,getZoomEventData:Et,getRotateEventData:Lt}=A;class Mt extends P{__listenEvents(){super.__listenEvents();const t=this.view=this.canvas.view;this.viewEvents={pointerdown:this.onPointerDown,mousedown:this.onMouseDown,touchstart:this.onTouchStart,contextmenu:this.onContextMenu,wheel:this.onWheel,gesturestart:this.onGesturestart,gesturechange:this.onGesturechange,gestureend:this.onGestureend},this.windowEvents={pointermove:this.onPointerMove,pointerup:this.onPointerUp,pointercancel:this.onPointerCancel,mousemove:this.onMouseMove,mouseup:this.onMouseUp,touchmove:this.onTouchMove,touchend:this.onTouchEnd,touchcancel:this.onTouchCancel,keydown:this.onKeyDown,keyup:this.onKeyUp,scroll:this.onScroll};const{viewEvents:e,windowEvents:i}=this;for(let i in e)e[i]=e[i].bind(this),t.addEventListener(i,e[i]);for(let t in i)i[t]=i[t].bind(this),window.addEventListener(t,i[t])}__removeListenEvents(){super.__removeListenEvents();const{viewEvents:t,windowEvents:e}=this;for(let e in t)this.view.removeEventListener(e,t[e]),this.viewEvents={};for(let t in e)window.removeEventListener(t,e[t]),this.windowEvents={}}getLocal(t,e){e&&this.canvas.updateClientBounds();const{clientBounds:i}=this.canvas;return{x:t.clientX-i.x,y:t.clientY-i.y}}getTouches(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push(t[i]);return e}preventDefaultPointer(t){const{pointer:e}=this.config;e.preventDefault&&t.preventDefault()}preventDefaultWheel(t){const{wheel:e}=this.config;e.preventDefault&&t.preventDefault()}preventWindowPointer(t){return!this.downData&&t.target!==this.view}onKeyDown(t){this.keyDown(bt.convert(t))}onKeyUp(t){this.keyUp(bt.convert(t))}onContextMenu(t){this.config.pointer.preventDefaultMenu&&t.preventDefault(),this.menu(mt.convert(t,this.getLocal(t)))}onScroll(){this.canvas.updateClientBounds()}onPointerDown(t){this.preventDefaultPointer(t),this.usePointer||(this.usePointer=!0),this.useMultiTouch||this.pointerDown(mt.convert(t,this.getLocal(t)))}onPointerMove(t){this.usePointer||(this.usePointer=!0),this.useMultiTouch||this.preventWindowPointer(t)||this.pointerMove(mt.convert(t,this.getLocal(t,!0)))}onPointerUp(t){this.downData&&this.preventDefaultPointer(t),this.useMultiTouch||this.preventWindowPointer(t)||this.pointerUp(mt.convert(t,this.getLocal(t)))}onPointerCancel(){this.useMultiTouch||this.pointerCancel()}onMouseDown(t){this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.pointerDown(mt.convertMouse(t,this.getLocal(t)))}onMouseMove(t){this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerMove(mt.convertMouse(t,this.getLocal(t,!0)))}onMouseUp(t){this.downData&&this.preventDefaultPointer(t),this.useTouch||this.usePointer||this.preventWindowPointer(t)||this.pointerUp(mt.convertMouse(t,this.getLocal(t)))}onMouseCancel(){this.useTouch||this.usePointer||this.pointerCancel()}onTouchStart(t){if(t.preventDefault(),this.multiTouchStart(t),this.usePointer)return;this.touchTimer&&(window.clearTimeout(this.touchTimer),this.touchTimer=0),this.useTouch=!0;const e=mt.getTouch(t);this.pointerDown(mt.convertTouch(t,this.getLocal(e,!0)))}onTouchMove(t){if(this.multiTouchMove(t),this.usePointer||this.preventWindowPointer(t))return;const e=mt.getTouch(t);this.pointerMove(mt.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=mt.getTouch(t);this.pointerUp(mt.convertTouch(t,this.getLocal(e)))}onTouchCancel(){this.usePointer||this.pointerCancel()}multiTouchStart(t){this.useMultiTouch=t.touches.length>=2,this.touches=this.useMultiTouch?this.getTouches(t.touches):void 0,this.useMultiTouch&&this.pointerCancel()}multiTouchMove(t){if(this.useMultiTouch&&t.touches.length>1){const e=this.getTouches(t.touches),i=this.getKeepTouchList(this.touches,e);i.length>1&&(this.multiTouch(A.getBase(t),i),this.touches=e)}}multiTouchEnd(){this.touches=null,this.useMultiTouch=!1,this.transformEnd()}getKeepTouchList(t,e){let i;const s=[];return t.forEach((t=>{i=e.find((e=>e.identifier===t.identifier)),i&&s.push({from:this.getLocal(t),to:this.getLocal(i)})})),s}getLocalTouchs(t){return t.map((t=>this.getLocal(t)))}onWheel(t){this.preventDefaultWheel(t);const{wheel:e}=this.config,i=e.getScale?e.getScale(t,e):xt.getScale(t,e),s=this.getLocal(t),n=A.getBase(t);1!==i?this.zoom(Et(s,i,n)):this.move(Bt(s,e.getMove?e.getMove(t,e):xt.getMove(t,e),n))}onGesturestart(t){this.preventDefaultWheel(t),this.lastGestureScale=1,this.lastGestureRotation=0}onGesturechange(t){this.preventDefaultWheel(t);const e=this.getLocal(t),i=A.getBase(t),s=t.scale/this.lastGestureScale,n=t.rotation-this.lastGestureRotation;let{rotateSpeed:o}=this.config.wheel;o=D.within(o,0,1),this.zoom(Et(e,s*s,i)),this.rotate(Lt(e,n/Math.PI*180*(o/4+.1),i)),this.lastGestureScale=t.scale,this.lastGestureRotation=t.rotation}onGestureend(t){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&&I.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 Rt(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 kt(t,e,i){const{strokeAlign:s}=e.__,n="string"!=typeof t;switch(s){case"center":i.setStroke(n?void 0:t,e.__.strokeWidth,e.__),n?Ct(t,!0,e,i):St(e,i);break;case"inside":Tt("inside",t,n,e,i);break;case"outside":Tt("outside",t,n,e,i)}}function Tt(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?Ct(e,!0,s,a):St(s,a),a.blendMode="outside"===t?"destination-out":"destination-in",Rt(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 St(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 Ct(t,e,i,s){let n;for(let o=0,r=t.length;o<r;o++)n=t[o],n.image&&Y.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?St(i,s):s.stroke(),s.restoreBlendMode()):e?St(i,s):s.stroke())}const{getSpread:Ot,getOuterOf:Wt,getByMove:At,getIntersectData:Pt}=E;let Dt;function It(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:G.string(r,a)};case"image":return Y.image(i,t,e,s,!Dt||!Dt[e.url]);case"linear":return z.linearGradient(e,s);case"radial":return z.radialGradient(e,s);case"angular":return z.conicGradient(e,s);default:return e.r?{type:"solid",style:G.string(e)}:void 0}}const Ft={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),Dt=Y.recycleImage(t,i);for(let i,n=0,r=o.length;n<r;n++)i=It(t,o[n],e),i&&s.push(i);i["_"+t]=s.length?s:void 0,s.length&&s[0].image&&(n=s[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=n:i.__pixelStroke=n},fill:function(t,e,i){i.fillStyle=t,e.__.__font?Rt(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let s;const{windingRule:n,__font:o}=e.__;for(let r=0,a=t.length;r<a;r++)s=t[r],s.image&&Y.checkImage(e,i,s,!o)||s.style&&(i.fillStyle=s.style,s.transform?(i.save(),i.transform(s.transform),s.blendMode&&(i.blendMode=s.blendMode),o?Rt(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?Rt(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?Rt(e,i):n?i.fill(n):i.fill())},fillText:Rt,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:r}=s;if(n)if(r)kt(t,e,i);else switch(o){case"center":i.setStroke(t,n,s),i.stroke();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)kt(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),Ct(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),Ct(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,r=i.getSameCanvas(!0,!0);e.__drawRenderPath(r),r.setStroke(void 0,2*n,s),Ct(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:kt,drawTextStroke:St,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=Pt(s?Ot(e.bounds,s*l,s*d):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=At(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:zt,translate:Vt,scaleOfOuter:Ut,scale:Nt,rotate:jt}=R;function Xt(t,e,i,s,n,o){const r=Gt(),a=o&&180!==o,h=i.width/(a?n:s),l=i.height/(a?s:n),d="fit"===e?Math.min(h,l):Math.max(h,l),c=i.x+(i.width-s*d)/2,u=i.y+(i.height-n*d)/2;Vt(r,c,u),Nt(r,d),o&&zt(r,{x:i.x+i.width/2,y:i.y+i.height/2},o),t.scaleX=t.scaleY=d,t.transform=r}function Ht(t,e,i,s,n,o,r){const a=Gt();Vt(a,e.x,e.y),(i||s)&&Vt(a,i,s),n&&(Nt(a,n,o),t.scaleX=a.a,t.scaleY=a.d),r&&jt(a,r),t.transform=a}function Kt(t,e,i,s,n,o,r,a,h){const l=Gt();if(h)switch(jt(l,h),h){case 90:Vt(l,s,0);break;case 180:Vt(l,i,s);break;case 270:Vt(l,0,i)}Yt.x=e.x,Yt.y=e.y,(n||o)&&(Yt.x+=n,Yt.y+=o),Vt(l,Yt.x,Yt.y),r&&(Ut(l,Yt,r,a),t.scaleX=r,t.scaleY=a),t.transform=l}const{get:qt,translate:Qt}=R;function $t(t,e,i,s){let{width:n,height:o}=e;const{opacity:r,mode:a,offset:h,scale:l,size:d,rotation:c,blendMode:u,repeat:p}=i,g=s.width===n&&s.height===o;u&&(t.blendMode=u);const f=t.data={mode:a};let _,w,y,v;switch(h&&(_=h.x,w=h.y),d?(y=("number"==typeof d?d:d.width)/n,v=("number"==typeof d?d:d.height)/o):l&&(y="number"==typeof l?l:l.x,v="number"==typeof l?l:l.y),a){case"strench":g||(n=s.width,o=s.height),(s.x||s.y)&&(f.transform=qt(),Qt(f.transform,s.x,s.y));break;case"clip":(h||y||c)&&Ht(f,s,_,w,y,v,c);break;case"repeat":(!g||y||c)&&Kt(f,s,n,o,_,w,y,v,c),p||(f.repeat="repeat");break;default:g&&!c||Xt(f,a,s,n,o,c)}f.width=n,f.height=o,r&&(f.opacity=r),p&&(f.repeat="string"==typeof p?"x"===p?"repeat-x":"repeat-y":"repeat")}let Zt,Jt=new w;const{isSame:te}=E;function ee(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||$t(n,s,i,o),!0}function ie(t,e){oe(t,k.LOAD,e)}function se(t,e){oe(t,k.LOADED,e)}function ne(t,e,i){e.error=i,t.forceUpdate("surface"),oe(t,k.ERROR,e)}function oe(t,e,i){t.hasEvent(e)&&t.emitEvent(new k(e,i))}const{get:re,scale:ae,copy:he}=R,{ceil:le,abs:de}=Math;function ce(t,e,s){let{scaleX:n,scaleY:o}=t.__world;const r=n+"-"+o;if(e.patternId===r||t.destroyed)return!1;{n=de(n),o=de(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=re(),he(l,f),ae(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 y=i.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(h=Math.sqrt(w/y)),h&&(n/=h,o/=h,d/=h,c/=h),u&&(n/=u,o/=p),(f||1!==n||1!==o)&&(l||(l=re(),f&&he(l,f)),ae(l,1/n,1/o));const v=t.getCanvas(le(d)||1,le(c)||1,g),m=t.getPattern(v,_||i.origin.noRepeat||"no-repeat",l,e);return e.style=m,e.patternId=r,!0}}function ue(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:pe}=Math;const ge={image:function(t,e,i,s,n){let o,r;const a=b.get(i);return Zt&&i===Zt.paint&&te(s,Zt.boxBounds)?o=Zt.leafPaint:(o={type:i.type},o.image=a,Zt=a.use>1?{leafPaint:o,paint:i,boxBounds:Jt.set(s)}:null),(n||a.loading)&&(r={image:a,attrName:e,attrValue:i}),a.ready?(ee(t,e,i,a,o,s),n&&(ie(t,r),se(t,r))):a.error?n&&ne(t,r,a.error):(n&&ie(t,r),o.loadId=a.load((()=>{t.destroyed||(ee(t,e,i,a,o,s)&&t.forceUpdate("surface"),se(t,r)),o.loadId=null}),(e=>{ne(t,r,e),o.loadId=null}))),o},createData:$t,fillOrFitMode:Xt,clipMode:Ht,repeatMode:Kt,createPattern:ce,checkImage:function(t,e,s,n){const{scaleX:o,scaleY:r}=t.__world;if(s.data&&s.patternId!==o+"-"+r){const{data:a}=s;if(n)if(a.repeat)n=!1;else{let{width:t,height:s}=a;t*=pe(o)*e.pixelRatio,s*=pe(r)*e.pixelRatio,a.scaleX&&(t*=a.scaleX,s*=a.scaleY),n=t*s>i.image.maxCacheSize}return n?(e.save(),e.clip(),s.blendMode&&(e.blendMode=s.blendMode),a.opacity&&(e.opacity*=a.opacity),a.transform&&e.transform(a.transform),e.drawImage(s.image.view,0,0,a.width,a.height),e.restore(),!0):(!s.style||V.running?ce(t,s,e.pixelRatio):s.patternTask||(s.patternTask=b.patternTasker.add((()=>ue(this,void 0,void 0,(function*(){s.patternTask=null,e.bounds.hit(t.__world)&&ce(t,s,e.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},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}},fe={x:.5,y:0},_e={x:.5,y:1};function we(t,e,i){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],t.addColorStop(s.offset,G.string(s.color,i))}const{set:ye,getAngle:ve,getDistance:me}=T,{get:xe,rotateOfOuter:be,scaleOfOuter:Be}=R,Ee={x:.5,y:.5},Le={x:.5,y:1},Me={},Re={};const{set:ke,getAngle:Te,getDistance:Se}=T,{get:Ce,rotateOfOuter:Oe,scaleOfOuter:We}=R,Ae={x:.5,y:.5},Pe={x:.5,y:1},De={},Ie={};const Fe={linearGradient:function(t,e){let{from:s,to:n,type:o,blendMode:r,opacity:a}=t;s||(s=fe),n||(n=_e);const h=i.canvas.createLinearGradient(e.x+s.x*e.width,e.y+s.y*e.height,e.x+n.x*e.width,e.y+n.y*e.height);we(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;s||(s=Ee),n||(n=Le);const{x:l,y:d,width:c,height:u}=e;let p;ye(Me,l+s.x*c,d+s.y*u),ye(Re,l+n.x*c,d+n.y*u),(c!==u||h)&&(p=xe(),Be(p,Me,c/u*(h||1),1),be(p,Me,ve(Me,Re)+90));const g=i.canvas.createRadialGradient(Me.x,Me.y,0,Me.x,Me.y,me(Me,Re));we(g,t.stops,r);const f={type:o,style:g,transform:p};return a&&(f.blendMode=a),f},conicGradient:function(t,e){let{from:s,to:n,type:o,opacity:r,blendMode:a,stretch:h}=t;s||(s=Ae),n||(n=Pe);const{x:l,y:d,width:c,height:u}=e;ke(De,l+s.x*c,d+s.y*u),ke(Ie,l+n.x*c,d+n.y*u);const p=Ce(),g=Te(De,Ie);i.conicGradientRotate90?(We(p,De,c/u*(h||1),1),Oe(p,De,g+90)):(We(p,De,1,c/u*(h||1)),Oe(p,De,g));const f=i.conicGradientSupport?i.canvas.createConicGradient(0,De.x,De.y):i.canvas.createRadialGradient(De.x,De.y,0,De.x,De.y,Se(De,Ie));we(f,t.stops,r);const _={type:o,style:f,transform:p};return a&&(_.blendMode=a),_}},{copy:Ye,toOffsetOutBounds:Ge}=E,ze={},Ve={};function Ue(t,e,s,n){const{bounds:o,shapeBounds:r}=n;if(i.fullImageShadow){if(Ye(ze,t.bounds),ze.x+=e.x-r.x,ze.y+=e.y-r.y,s){const{matrix:t}=n;ze.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),ze.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),ze.width*=s,ze.height*=s}t.copyWorld(n.canvas,t.bounds,ze)}else s&&(Ye(ze,e),ze.x-=e.width/2*(s-1),ze.y-=e.height/2*(s-1),ze.width*=s,ze.height*=s),t.copyWorld(n.canvas,r,s?ze:e)}const{toOffsetOutBounds:Ne}=E,je={};const Xe={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;Ge(l,Ve),a.forEach(((a,f)=>{p.setWorldShadow(Ve.offsetX+a.x*c,Ve.offsetY+a.y*u,a.blur*c,a.color),n=a.spread?1+2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,Ue(p,Ve,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,je),a.forEach(((a,f)=>{p.save(),p.setWorldShadow(je.offsetX+a.x*c,je.offsetY+a.y*u,a.blur*c),n=a.spread?1-2*a.spread/(r.boxBounds.width+2*(r.strokeBoxSpread||0)):0,Ue(p,je,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.__world.a),i.copyWorldToInner(e,t.__world,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:He}=y;function Ke(t,e,i,s,n,o){switch(e){case"alpha":!function(t,e,i,s){const n=t.__nowWorld;i.resetTransform(),i.opacity=1,i.useMask(s,n),s.recycle(n),Qe(t,e,i,1)}(t,i,s,n);break;case"opacity-path":Qe(t,i,s,o);break;case"path":i.restore()}}function qe(t){return t.getSameCanvas(!1,!0)}function Qe(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}U.prototype.__renderMask=function(t,e){let i,s,n,o,r;const{children:a}=this;for(let h=0,l=a.length;h<l;h++)i=a[h],i.__.mask&&(r&&(Ke(this,r,t,n,s,o),s=n=null),"path"===i.__.maskType?(i.opacity<1?(r="opacity-path",o=i.opacity,n||(n=qe(t))):(r="path",t.save()),i.__clip(n||t,e)):(r="alpha",s||(s=qe(t)),n||(n=qe(t)),i.__render(s,e)),"clipping"!==i.__.maskType)||He(i,e)||i.__render(n||t,e);Ke(this,r,t,n,s,o)};const $e=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Ze=$e+"_#~&*+\\=|≮≯≈≠=…",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 ti(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const ei=ti("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),ii=ti("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),si=ti($e),ni=ti(Ze),oi=ti("- —/~|┆·");var ri;!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"}(ri||(ri={}));const{Letter:ai,Single:hi,Before:li,After:di,Symbol:ci,Break:ui}=ri;function pi(t){return ei[t]?ai:oi[t]?ui:ii[t]?li:si[t]?di:ni[t]?ci:Je.test(t)?hi:ai}const gi={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 fi(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:_i}=gi,{Letter:wi,Single:yi,Before:vi,After:mi,Symbol:xi,Break:bi}=ri;let Bi,Ei,Li,Mi,Ri,ki,Ti,Si,Ci,Oi,Wi,Ai,Pi,Di,Ii,Fi,Yi=[];function Gi(t,e){Ci&&!Si&&(Si=Ci),Bi.data.push({char:t,width:e}),Li+=e}function zi(){Mi+=Li,Bi.width=Li,Ei.words.push(Bi),Bi={data:[]},Li=0}function Vi(){Di&&(Ii.paraNumber++,Ei.paraStart=!0,Di=!1),Ci&&(Ei.startCharSize=Si,Ei.endCharSize=Ci,Si=0),Ei.width=Mi,Fi.width&&_i(Ei),Yi.push(Ei),Ei={words:[]},Mi=0}const Ui=0,Ni=1,ji=2;const{top:Xi,right:Hi,bottom:Ki,left:qi}=S;function Qi(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 $i={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[qi],o-=l[Hi]+l[qi]),r&&(n=l[Xi],r-=l[Xi]+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){Ii=t,Yi=t.rows,Fi=t.bounds;const{__letterSpacing:n,paraIndent:o,textCase:r}=s,{canvas:a}=i,{width:h,height:l}=Fi;if(h||l||n||"none"!==r){const t="none"!==s.textWrap,i="break"===s.textWrap;Di=!0,Wi=null,Si=Ti=Ci=Li=Mi=0,Bi={data:[]},Ei={words:[]};for(let s=0,l=e.length;s<l;s++)ki=e[s],"\n"===ki?(Li&&zi(),Ei.paraEnd=!0,Vi(),Di=!0):(Oi=pi(ki),Oi===wi&&"none"!==r&&(ki=fi(ki,r,!Li)),Ti=a.measureText(ki).width,n&&(n<0&&(Ci=Ti),Ti+=n),Ai=Oi===yi&&(Wi===yi||Wi===wi)||Wi===yi&&Oi!==mi,Pi=!(Oi!==vi&&Oi!==yi||Wi!==xi&&Wi!==mi),Ri=Di&&o?h-o:h,t&&h&&Mi+Li+Ti>Ri&&(i?(Li&&zi(),Vi()):(Pi||(Pi=Oi===wi&&Wi==mi),Ai||Pi||Oi===bi||Oi===vi||Oi===yi||Li+Ti>Ri?(Li&&zi(),Vi()):Vi()))," "===ki&&!0!==Di&&Mi+Li===0||(Oi===bi?(" "===ki&&Li&&zi(),Gi(ki,Ti),zi()):Ai||Pi?(Li&&zi(),Gi(ki,Ti)):Gi(ki,Ti)),Wi=Oi);Li&&zi(),Mi&&Vi(),Yi.length>0&&(Yi[Yi.length-1].paraEnd=!0)}else e.split("\n").forEach((t=>{Ii.paraNumber++,Yi.push({x:o||0,text:t,width:a.measureText(t).width,paraStart:!0})}))}(d,t,e),l&&function(t,e,i,s,n){if(!s)switch(i.textAlign){case"left":Qi(e,"x",t[qi]);break;case"right":Qi(e,"x",-t[Hi])}if(!n)switch(i.verticalAlign){case"top":Qi(e,"y",t[Xi]);break;case"bottom":Qi(e,"y",-t[Ki])}}(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}=e;let c,u,p,{x:g,y:f,width:_,height:w}=s,y=n*i.length+(d?d*(t.paraNumber-1):0),v=o;if(a&&y>w)y=Math.max(w,n),t.overflow=i.length;else switch(l){case"middle":f+=(w-y)/2;break;case"bottom":f+=w-y}v+=f;for(let o=0,l=i.length;o<l;o++){switch(c=i[o],c.x=g,h){case"center":c.x+=(_-c.width)/2;break;case"right":c.x+=_-c.width}c.paraStart&&d&&o>0&&(v+=d),c.y=v,v+=n,t.overflow>o&&v>y&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,p=c.width,r<0&&(c.width<0?(p=-c.width+e.fontSize+r,u-=p,p+=e.fontSize):p-=r),u<s.x&&(s.x=u),p>s.width&&(s.width=p),a&&_&&_<p&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=f,s.height=y}(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?Ui:l>.01?Ni:ji,t.isOverflow&&!a&&(t.textMode=!0),c===ji?(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===Ni?(u={char:"",x:h},h=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,h,u)," "!==u.char&&t.data.push(u)):h=function(t,e,i){return t.forEach((t=>{" "!==t.char&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,h,t.data),!t.paraEnd&&l&&(h+=l,t.width+=l)}))),t.words=null)}))}(d,e,o),d.overflow&&function(t,e){const{rows:s,overflow:n}=t;let{textOverflow:o}=e;if(s.splice(n),"hide"!==o){let t,r;"ellipsis"===o&&(o="...");const a=i.canvas.measureText(o).width,h=e.x+e.width-a;("none"===e.textWrap?s:[s[n-1]]).forEach((e=>{if(e.isOverflow&&e.data){let i=e.data.length-1;for(let s=i;s>-1&&(t=e.data[s],r=t.x+t.width,!(s===i&&r<h));s--){if(r<h&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=a,e.data.push({char:o,x:r}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(d,e),"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 Zi={string:function(t,e){if("string"==typeof t)return t;let i=void 0===t.a?1:t.a;e&&(i*=e);const s=t.r+","+t.g+","+t.b;return 1===i?"rgb("+s+")":"rgba("+s+","+i+")"}},{setPoint:Ji,addPoint:ts,toBounds:es}=C;const is={export(t,e,i){return this.running=!0,function(t){ss||(ss=new O);return new Promise((e=>{ss.add((()=>ue(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((s=>new Promise((n=>{const o=t=>{s(t),n(),this.running=!1},{leafer:r}=t;r?r.waitViewCompleted((()=>ue(this,void 0,void 0,(function*(){i=l.getExportOptions(i);let s,n,h=1,d=1;const{worldTransform:c,isLeafer:u,isFrame:p}=t,{slice:g,trim:f,onCanvas:_}=i,y=i.scale||1,v=i.pixelRatio||1,m=i.screenshot||t.isApp,x=u&&m?void 0===i.fill?t.fill:void 0:i.fill,b=l.isOpaqueImage(e)||x,B=new W;if(m)s=!0===m?u?r.canvas.bounds:t.worldRenderBounds:m;else{const e=i.location||(u||p?"inner":"local");switch(h=c.scaleX,d=c.scaleY,e){case"inner":B.set(c).invert();break;case"local":B.set(c).divide(t.localTransform).invert(),h/=t.scaleX,d/=t.scaleY;break;case"world":h=1,d=1}s=t.getBounds("render",e)}const{x:E,y:L,width:M,height:R}=new w(s).scale(y).ceil();let k=a.canvas({width:M,height:R,pixelRatio:v});const T={matrix:B.scale(y).translate(-E,-L).withScale(1/h*y,1/d*y)};if(g&&(t=r,T.bounds=k.bounds),k.save(),p&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(k,T),t.fill=e}else t.__render(k,T);if(k.restore(),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?ts(r,n,o):Ji(r={},n,o)),a++;const h=new w;return es(r,h),h.scale(1/t.pixelRatio).ceil()}(k);const t=k,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:v};k=a.canvas(s),k.copyWorld(t,n,s)}b&&k.fillWorld(k.bounds,x||"#FFFFFF","destination-over"),_&&_(k);const S="canvas"===e?k:yield k.export(e,i);o({data:S,width:k.pixelWidth,height:k.pixelHeight,renderBounds:s,trimBounds:n})})))):o({data:!1})}))))}};let ss;Object.assign(N,$i),Object.assign(G,Zi),Object.assign(j,Ft),Object.assign(Y,ge),Object.assign(z,Fe),Object.assign(X,Xe),Object.assign(V,is),Object.assign(a,{interaction:(t,e,i,s)=>new Mt(t,e,i,s),hitCanvas:(t,e)=>new K(t,e),hitCanvasManager:()=>new F}),$();export{Mt as Interaction,ct as Layouter,K as LeaferCanvas,pt as Renderer,vt as Selector,J as Watcher,$ as useCanvas};