@leafer-draw/miniapp 1.0.0-rc.17 → 1.0.0-rc.19

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.
@@ -621,6 +621,10 @@ class Renderer {
621
621
  }
622
622
  else {
623
623
  this.requestLayout();
624
+ if (this.ignore) {
625
+ this.ignore = this.rendering = false;
626
+ return;
627
+ }
624
628
  this.emitRender(RenderEvent.BEFORE);
625
629
  if (this.config.usePartRender && this.totalTimes > 1) {
626
630
  this.partRender();
@@ -768,9 +772,7 @@ class Renderer {
768
772
  if (this.target) {
769
773
  this.stop();
770
774
  this.__removeListenEvents();
771
- this.target = null;
772
- this.canvas = null;
773
- this.config = null;
775
+ this.target = this.canvas = this.config = null;
774
776
  }
775
777
  }
776
778
  }
@@ -1167,10 +1169,6 @@ function createData(leafPaint, image, paint, box) {
1167
1169
  case 'strench':
1168
1170
  if (!sameBox)
1169
1171
  width = box.width, height = box.height;
1170
- if (box.x || box.y) {
1171
- data.transform = get$3();
1172
- translate(data.transform, box.x, box.y);
1173
- }
1174
1172
  break;
1175
1173
  case 'clip':
1176
1174
  if (offset || scaleX || rotation)
@@ -1188,6 +1186,12 @@ function createData(leafPaint, image, paint, box) {
1188
1186
  if (!sameBox || rotation)
1189
1187
  fillOrFitMode(data, mode, box, width, height, rotation);
1190
1188
  }
1189
+ if (!data.transform) {
1190
+ if (box.x || box.y) {
1191
+ data.transform = get$3();
1192
+ translate(data.transform, box.x, box.y);
1193
+ }
1194
+ }
1191
1195
  data.width = width;
1192
1196
  data.height = height;
1193
1197
  if (opacity)
@@ -1205,8 +1209,7 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
1205
1209
  leafPaint = cache.leafPaint;
1206
1210
  }
1207
1211
  else {
1208
- leafPaint = { type: paint.type };
1209
- leafPaint.image = image;
1212
+ leafPaint = { type: paint.type, image };
1210
1213
  cache = image.use > 1 ? { leafPaint, paint, boxBounds: box.set(boxBounds) } : null;
1211
1214
  }
1212
1215
  if (firstUse || image.loading)
@@ -1223,9 +1226,11 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
1223
1226
  onLoadError(ui, event, image.error);
1224
1227
  }
1225
1228
  else {
1229
+ ignoreRender(ui, true);
1226
1230
  if (firstUse)
1227
1231
  onLoad(ui, event);
1228
1232
  leafPaint.loadId = image.load(() => {
1233
+ ignoreRender(ui, false);
1229
1234
  if (!ui.destroyed) {
1230
1235
  if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds))
1231
1236
  ui.forceUpdate('surface');
@@ -1233,6 +1238,7 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
1233
1238
  }
1234
1239
  leafPaint.loadId = null;
1235
1240
  }, (error) => {
1241
+ ignoreRender(ui, false);
1236
1242
  onLoadError(ui, event, error);
1237
1243
  leafPaint.loadId = null;
1238
1244
  });
@@ -1272,11 +1278,16 @@ function emit(ui, type, data) {
1272
1278
  if (ui.hasEvent(type))
1273
1279
  ui.emitEvent(new ImageEvent(type, data));
1274
1280
  }
1281
+ function ignoreRender(ui, value) {
1282
+ const { leafer } = ui;
1283
+ if (leafer && leafer.viewReady)
1284
+ leafer.renderer.ignore = value;
1285
+ }
1275
1286
 
1276
1287
  const { get: get$2, scale, copy: copy$1 } = MatrixHelper;
1277
1288
  const { ceil, abs: abs$1 } = Math;
1278
1289
  function createPattern(ui, paint, pixelRatio) {
1279
- let { scaleX, scaleY } = ui.__world;
1290
+ let { scaleX, scaleY } = ui.__nowWorld;
1280
1291
  const id = scaleX + '-' + scaleY;
1281
1292
  if (paint.patternId !== id && !ui.destroyed) {
1282
1293
  scaleX = abs$1(scaleX);
@@ -1370,7 +1381,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1370
1381
 
1371
1382
  const { abs } = Math;
1372
1383
  function checkImage(ui, canvas, paint, allowPaint) {
1373
- const { scaleX, scaleY } = ui.__world;
1384
+ const { scaleX, scaleY } = ui.__nowWorld;
1374
1385
  if (!paint.data || paint.patternId === scaleX + '-' + scaleY) {
1375
1386
  return false;
1376
1387
  }
@@ -1412,7 +1423,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
1412
1423
  if (!paint.patternTask) {
1413
1424
  paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1414
1425
  paint.patternTask = null;
1415
- if (canvas.bounds.hit(ui.__world))
1426
+ if (canvas.bounds.hit(ui.__nowWorld))
1416
1427
  createPattern(ui, paint, canvas.pixelRatio);
1417
1428
  ui.forceUpdate('surface');
1418
1429
  }), 300);
@@ -1649,8 +1660,8 @@ function innerShadow(ui, current, shape) {
1649
1660
 
1650
1661
  function blur(ui, current, origin) {
1651
1662
  const { blur } = ui.__;
1652
- origin.setWorldBlur(blur * ui.__world.a);
1653
- origin.copyWorldToInner(current, ui.__world, ui.__layout.renderBounds);
1663
+ origin.setWorldBlur(blur * ui.__nowWorld.a);
1664
+ origin.copyWorldToInner(current, ui.__nowWorld, ui.__layout.renderBounds);
1654
1665
  origin.filter = 'none';
1655
1666
  }
1656
1667
 
@@ -2281,10 +2292,10 @@ const ExportModule = {
2281
2292
  renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
2282
2293
  }
2283
2294
  else {
2284
- const location = options.location || ((isLeafer || isFrame) ? 'inner' : 'local');
2295
+ let relative = options.relative || (isLeafer ? 'inner' : 'local');
2285
2296
  scaleX = worldTransform.scaleX;
2286
2297
  scaleY = worldTransform.scaleY;
2287
- switch (location) {
2298
+ switch (relative) {
2288
2299
  case 'inner':
2289
2300
  matrix.set(worldTransform).invert();
2290
2301
  break;
@@ -2297,11 +2308,18 @@ const ExportModule = {
2297
2308
  scaleX = 1;
2298
2309
  scaleY = 1;
2299
2310
  break;
2311
+ case 'page':
2312
+ relative = leaf.leafer;
2313
+ default:
2314
+ matrix.set(worldTransform).divide(leaf.getTransform(relative)).invert();
2315
+ const l = relative.worldTransform;
2316
+ scaleX /= scaleX / l.scaleX;
2317
+ scaleY /= scaleY / l.scaleY;
2300
2318
  }
2301
- renderBounds = leaf.getBounds('render', location);
2319
+ renderBounds = leaf.getBounds('render', relative);
2302
2320
  }
2303
- const { x, y, width, height } = new Bounds(renderBounds).scale(scale).ceil();
2304
- let canvas = Creator.canvas({ width, height, pixelRatio });
2321
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
2322
+ let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio });
2305
2323
  const renderOptions = { matrix: matrix.scale(scale).translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
2306
2324
  if (slice) {
2307
2325
  leaf = leafer;
@@ -1 +1 @@
1
- import{LeaferCanvasBase as t,Platform as e,canvasPatch as i,DataHelper as s,canvasSizeAttrs as n,ResizeEvent as o,Creator as a,LeaferImage as r,FileHelper as d,LeafList as l,RenderEvent as h,ChildEvent as c,WatchEvent as u,PropertyEvent as f,LeafHelper as p,BranchHelper as _,Bounds as g,LeafBoundsHelper as w,Debug as y,LeafLevelList as m,LayoutEvent as v,Run as x,ImageManager as b,AnimateEvent as B,BoundsHelper as R,MatrixHelper as k,ImageEvent as S,PointHelper as E,Direction4 as L,TwoPointBoundsHelper as A,TaskProcessor as W,Matrix as O}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as T,ColorConvert as M,PaintGradient as C,Export as I,Group as P,TextConvert as D,Paint as F,Effect as z}from"@leafer-ui/draw";export*from"@leafer-ui/draw";class Y extends t{get allowBackgroundColor(){return!1}init(){let{view:t}=this.config;t?("string"==typeof t?("#"!==t[0]&&(t="#"+t),this.viewSelect=e.miniapp.select(t)):t.fields?this.viewSelect=t:this.initView(t),this.viewSelect&&e.miniapp.getSizeView(this.viewSelect).then((t=>{this.initView(t)}))):this.initView()}initView(t){t?this.view=t.view||t:(t={},this.__createView()),this.__createContext();const{width:e,height:s,pixelRatio:n}=this.config,o={width:e||t.width,height:s||t.height,pixelRatio:n};this.resize(o),this.context.roundRect&&(this.roundRect=function(t,e,i,s,n){this.context.roundRect(t,e,i,s,"number"==typeof n?[n]:n)}),i(this.context.__proto__)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this;this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(t){this.viewSelect&&e.miniapp.getBounds(this.viewSelect).then((e=>{this.clientBounds=e,t&&t()}))}startAutoLayout(t,i){this.resizeListener=i,this.checkSize=this.checkSize.bind(this),e.miniapp.onWindowResize(this.checkSize)}checkSize(){this.viewSelect&&setTimeout((()=>{this.updateClientBounds((()=>{const{width:t,height:e}=this.clientBounds,{pixelRatio:i}=this,a={width:t,height:e,pixelRatio:i};if(!this.isSameSize(a)){const t={};s.copyAttrs(t,this,n),this.resize(a),void 0!==this.width&&this.resizeListener(new o(a,t))}}))}),500)}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,e.miniapp.offWindowResize(this.checkSize)}}const{mineType:V,fileType:U}=d;function G(t,i){e.origin||(e.origin={createCanvas:(t,e,s)=>i.createOffscreenCanvas({type:"2d",width:t,height:e}),canvasToDataURL:(t,e,i)=>t.toDataURL(V(e),i),canvasToBolb:(t,e,i)=>t.toBuffer(e,{quality:i}),canvasSaveAs:(t,s,n)=>new Promise(((o,a)=>{let r,d=t.toDataURL(V(U(s)),n);d=d.substring(d.indexOf("64,")+3),s.includes("/")||(s=`${i.env.USER_DATA_PATH}/`+s,r=!0);const l=i.getFileSystemManager();l.writeFile({filePath:s,data:d,encoding:"base64",success(){r&&e.miniapp.saveToAlbum(s).then((()=>{l.unlink({filePath:s})})),o()},fail(t){a(t)}})})),loadImage:t=>new Promise(((i,s)=>{const n=e.canvas.view.createImage();n.onload=()=>{i(n)},n.onerror=t=>{s(t)},n.src=t})),noRepeat:"repeat-x"},e.miniapp={select:t=>i.createSelectorQuery().select(t),getBounds:t=>new Promise((e=>{t.boundingClientRect().exec((t=>{const i=t[1];e({x:i.top,y:i.left,width:i.width,height:i.height})}))})),getSizeView:t=>new Promise((e=>{t.fields({node:!0,size:!0}).exec((t=>{const i=t[0];e({view:i.node,width:i.width,height:i.height})}))})),saveToAlbum:t=>new Promise((e=>{i.getSetting({success:s=>{s.authSetting["scope.writePhotosAlbum"]?i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}}):i.authorize({scope:"scope.writePhotosAlbum",success:()=>{i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}})},fail:()=>{}})}})})),onWindowResize(t){i.onWindowResize(t)},offWindowResize(t){i.offWindowResize(t)}},e.event={stopDefault(t){},stopNow(t){},stop(t){}},e.canvas=a.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient)}Object.assign(a,{canvas:(t,e)=>new Y(t,e),image:t=>new r(t)}),e.name="miniapp",e.requestRender=function(t){e.canvas.view.requestAnimationFrame(t)},e.devicePixelRatio=wx.getSystemInfoSync().pixelRatio;class N{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new l;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 l,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(h.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===c.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 u(u.DATA,{updatedList:this.updatedList})),this.__updatedList=new l,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(f.CHANGE,this.__onAttrChange,this),t.on_([c.ADD,c.REMOVE],this.__onChildEvent,this),t.on_(u.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:X,updateBounds:j,updateAllWorldOpacity:q}=p,{pushAllChildBranch:H,pushAllParent:Q}=_;const{worldBounds:Z}=w,$={x:0,y:0,width:1e5,height:1e5};class J{constructor(t){this.updatedBounds=new g,this.beforeBounds=new g,this.afterBounds=new g,t instanceof Array&&(t=new l(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,Z)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set($):this.afterBounds.setListWithFn(t,Z),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:K,updateAllChange:tt}=p,et=y.get("Layouter");class it{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new m,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(v.START),this.layoutOnce(),t.emitEvent(new v(v.END,this.layoutedBlocks,this.times))}catch(t){et.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?et.warn("layouting"):this.times>3?et.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(u.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:a}=v,r=this.getBlocks(s);r.forEach((t=>t.setBefore())),i.emitEvent(new v(n,r,this.times)),this.extraBlock=null,s.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(X(t,!0),e.add(t),t.isBranch&&H(t,e),Q(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),Q(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||j(s[t])}j(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&q(t),t.__updateChange()}))}(s),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new v(o,r,this.times)),i.emitEvent(new v(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,x.end(e)}fullLayout(){const t=x.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=v,o=this.getBlocks(new l(e));e.emitEvent(new v(i,o,this.times)),it.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new v(s,o,this.times)),e.emitEvent(new v(n,o,this.times)),this.addBlocks(o),x.end(t)}static fullLayout(t){K(t,!0),t.isBranch?_.updateBounds(t):p.updateBounds(t),tt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new J([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new J(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_(v.REQUEST,this.layout,this),t.on_(v.AGAIN,this.layoutAgain,this),t.on_(u.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const st=y.get("Renderer");class nt{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(v.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new g,st.log(e.innerName,"---\x3e");try{this.emitRender(h.START),this.renderOnce(t),this.emitRender(h.END,this.totalBounds),b.clearRecycled()}catch(t){this.rendering=!1,st.error(t)}st.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){return this.rendering?st.warn("rendering"):this.times>3?st.warn("render max times"):(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new g,this.renderOptions={},t?(this.emitRender(h.BEFORE),t()):(this.requestLayout(),this.emitRender(h.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()),this.emitRender(h.RENDER,this.renderBounds,this.renderOptions),this.emitRender(h.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,void(this.waitAgain&&(this.waitAgain=!1,this.renderOnce())))}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return st.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=x.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=t.includes(this.target.__world),o=new g(s);i.save(),n&&!y.showRepaint?i.clear():(s.spread(1+1/this.canvas.pixelRatio).ceil(),i.clearWorld(s,!0),i.clipWorld(s,!0)),this.__render(s,n,o),i.restore(),x.end(e)}fullRender(){const t=x.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),x.end(t)}__render(t,e,i){const s=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),y.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,s),this.renderBounds=i||t,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),y.showHitView&&this.renderHitView(s),y.showBoundsView&&this.renderBoundsView(s),this.canvas.updateRender()}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new g;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.target.emit(B.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(h.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal&&(t.bigger||!t.samePixelRatio)){const{width:e,height:i}=t.old;new g(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||st.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,i){this.target.emitEvent(new h(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(h.REQUEST,this.update,this),t.on_(v.END,this.__onLayoutEnd,this),t.on_(h.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)}}function ot(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;t++)i=s[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),n&&e.fillRect(i.x,i.y+n,i.width,o)}function at(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?lt(t,!0,e,i):dt(e,i);break;case"inside":rt("inside",t,n,e,i);break;case"outside":rt("outside",t,n,e,i)}}function rt(t,e,i,s,n){const{__strokeWidth:o,__font:a}=s.__,r=n.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,s.__),r.font=a,i?lt(e,!0,s,r):dt(s,r),r.blendMode="outside"===t?"destination-out":"destination-in",ot(s,r),r.blendMode="normal",s.__worldFlipped?n.copyWorldByReset(r,s.__nowWorld):n.copyWorldToInner(r,s.__nowWorld,s.__layout.renderBounds),r.recycle(s.__nowWorld)}function dt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;t++)i=s[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),n&&e.strokeRect(i.x,i.y+n,i.width,o)}function lt(t,e,i,s){let n;for(let o=0,a=t.length;o<a;o++)n=t[o],n.image&&T.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?dt(i,s):s.stroke(),s.restoreBlendMode()):e?dt(i,s):s.stroke())}Object.assign(a,{watcher:(t,e)=>new N(t,e),layouter:(t,e)=>new it(t,e),renderer:(t,e,i)=>new nt(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,s)=>{}}),e.layout=it.fullLayout;const{getSpread:ht,getOuterOf:ct,getByMove:ut,getIntersectData:ft}=R;let pt;function _t(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:s}=i.__layout;switch(e.type){case"solid":let{type:n,blendMode:o,color:a,opacity:r}=e;return{type:n,blendMode:o,style:M.string(a,r)};case"image":return T.image(i,t,e,s,!pt||!pt[e.url]);case"linear":return C.linearGradient(e,s);case"radial":return C.radialGradient(e,s);case"angular":return C.conicGradient(e,s);default:return e.r?{type:"solid",style:M.string(e)}:void 0}}const gt={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),pt=T.recycleImage(t,i);for(let i,n=0,a=o.length;n<a;n++)i=_t(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?ot(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let s;const{windingRule:n,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)s=t[a],s.image&&T.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?ot(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?ot(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?ot(e,i):n?i.fill(n):i.fill())},fillText:ot,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:a}=s;if(n)if(a)at(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:a}=s;if(n)if(a)at(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),lt(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),lt(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*n,s),lt(t,!1,e,a),s.windingRule?a.clip(s.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:at,drawTextStroke:dt,shape:function(t,e,i){const s=e.getSameCanvas(),n=t.__nowWorld;let o,a,r,d,{scaleX:l,scaleY:h}=n;if(l<0&&(l=-l),h<0&&(h=-h),e.bounds.includes(n))d=s,o=r=n;else{const{renderShapeSpread:s}=t.__layout,c=ft(s?ht(e.bounds,s*l,s*h):e.bounds,n);a=e.bounds.getFitMatrix(c);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,h*=f),r=ct(n,a),o=ut(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,f)})}return t.__renderShape(s,i),{canvas:s,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:h}}};let wt={};const{get:yt,rotateOfOuter:mt,translate:vt,scaleOfOuter:xt,scale:bt,rotate:Bt}=k;function Rt(t,e,i,s,n,o){const a=yt(),r=o&&180!==o,d=i.width/(r?n:s),l=i.height/(r?s:n),h="fit"===e?Math.min(d,l):Math.max(d,l),c=i.x+(i.width-s*h)/2,u=i.y+(i.height-n*h)/2;vt(a,c,u),bt(a,h),o&&mt(a,{x:i.x+i.width/2,y:i.y+i.height/2},o),t.scaleX=t.scaleY=h,t.transform=a}function kt(t,e,i,s,n,o,a){const r=yt();vt(r,e.x,e.y),(i||s)&&vt(r,i,s),n&&(bt(r,n,o),t.scaleX=r.a,t.scaleY=r.d),a&&Bt(r,a),t.transform=r}function St(t,e,i,s,n,o,a,r,d){const l=yt();if(d)switch(Bt(l,d),d){case 90:vt(l,s,0);break;case 180:vt(l,i,s);break;case 270:vt(l,0,i)}wt.x=e.x,wt.y=e.y,(n||o)&&(wt.x+=n,wt.y+=o),vt(l,wt.x,wt.y),a&&(xt(l,wt,a,r),t.scaleX=a,t.scaleY=r),t.transform=l}const{get:Et,translate:Lt}=k;function At(t,e,i,s){let{width:n,height:o}=e;const{opacity:a,mode:r,offset:d,scale:l,size:h,rotation:c,blendMode:u,repeat:f}=i,p=s.width===n&&s.height===o;u&&(t.blendMode=u);const _=t.data={mode:r};let g,w,y,m;switch(d&&(g=d.x,w=d.y),h?(y=("number"==typeof h?h:h.width)/n,m=("number"==typeof h?h:h.height)/o):l&&(y="number"==typeof l?l:l.x,m="number"==typeof l?l:l.y),r){case"strench":p||(n=s.width,o=s.height),(s.x||s.y)&&(_.transform=Et(),Lt(_.transform,s.x,s.y));break;case"clip":(d||y||c)&&kt(_,s,g,w,y,m,c);break;case"repeat":(!p||y||c)&&St(_,s,n,o,g,w,y,m,c),f||(_.repeat="repeat");break;default:p&&!c||Rt(_,r,s,n,o,c)}_.width=n,_.height=o,a&&(_.opacity=a),f&&(_.repeat="string"==typeof f?"x"===f?"repeat-x":"repeat-y":"repeat")}let Wt,Ot=new g;const{isSame:Tt}=R;function Mt(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||At(n,s,i,o),!0}function Ct(t,e){Dt(t,S.LOAD,e)}function It(t,e){Dt(t,S.LOADED,e)}function Pt(t,e,i){e.error=i,t.forceUpdate("surface"),Dt(t,S.ERROR,e)}function Dt(t,e,i){t.hasEvent(e)&&t.emitEvent(new S(e,i))}const{get:Ft,scale:zt,copy:Yt}=k,{ceil:Vt,abs:Ut}=Math;function Gt(t,i,s){let{scaleX:n,scaleY:o}=t.__world;const a=n+"-"+o;if(i.patternId===a||t.destroyed)return!1;{n=Ut(n),o=Ut(o);const{image:t,data:r}=i;let d,l,{width:h,height:c,scaleX:u,scaleY:f,opacity:p,transform:_,repeat:g}=r;u&&(l=Ft(),Yt(l,_),zt(l,1/u,1/f),n*=u,o*=f),n*=s,o*=s,h*=n,c*=o;const w=h*c;if(!g&&w>e.image.maxCacheSize)return!1;let y=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(n/=d,o/=d,h/=d,c/=d),u&&(n/=u,o/=f),(_||1!==n||1!==o)&&(l||(l=Ft(),_&&Yt(l,_)),zt(l,1/n,1/o));const m=t.getCanvas(Vt(h)||1,Vt(c)||1,p),v=t.getPattern(m,g||e.origin.noRepeat||"no-repeat",l,i);return i.style=v,i.patternId=a,!0}}function Nt(t,e,i,s){return new(i||(i=Promise))((function(n,o){function a(t){try{d(s.next(t))}catch(t){o(t)}}function r(t){try{d(s.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}d((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:Xt}=Math;const jt={image:function(t,e,i,s,n){let o,a;const r=b.get(i);return Wt&&i===Wt.paint&&Tt(s,Wt.boxBounds)?o=Wt.leafPaint:(o={type:i.type},o.image=r,Wt=r.use>1?{leafPaint:o,paint:i,boxBounds:Ot.set(s)}:null),(n||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(Mt(t,e,i,r,o,s),n&&(Ct(t,a),It(t,a))):r.error?n&&Pt(t,a,r.error):(n&&Ct(t,a),o.loadId=r.load((()=>{t.destroyed||(Mt(t,e,i,r,o,s)&&t.forceUpdate("surface"),It(t,a)),o.loadId=null}),(e=>{Pt(t,a,e),o.loadId=null}))),o},createData:At,fillOrFitMode:Rt,clipMode:kt,repeatMode:St,createPattern:Gt,checkImage:function(t,i,s,n){const{scaleX:o,scaleY:a}=t.__world;if(s.data&&s.patternId!==o+"-"+a){const{data:r}=s;if(n)if(r.repeat)n=!1;else{let{width:t,height:s}=r;t*=Xt(o)*i.pixelRatio,s*=Xt(a)*i.pixelRatio,r.scaleX&&(t*=r.scaleX,s*=r.scaleY),n=t*s>e.image.maxCacheSize}return n?(i.save(),i.clip(),s.blendMode&&(i.blendMode=s.blendMode),r.opacity&&(i.opacity*=r.opacity),r.transform&&i.transform(r.transform),i.drawImage(s.image.view,0,0,r.width,r.height),i.restore(),!0):(!s.style||I.running?Gt(t,s,i.pixelRatio):s.patternTask||(s.patternTask=b.patternTasker.add((()=>Nt(this,void 0,void 0,(function*(){s.patternTask=null,i.bounds.hit(t.__world)&&Gt(t,s,i.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let s,n,o,a;for(let r=0,d=i.length;r<d;r++)s=i[r].image,a=s&&s.url,a&&(n||(n={}),n[a]=!0,b.recycle(s),s.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),s.unload(i[r].loadId,!o.some((t=>t.url===a)))));return n}return null}},qt={x:.5,y:0},Ht={x:.5,y:1};function Qt(t,e,i){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],t.addColorStop(s.offset,M.string(s.color,i))}const{set:Zt,getAngle:$t,getDistance:Jt}=E,{get:Kt,rotateOfOuter:te,scaleOfOuter:ee}=k,ie={x:.5,y:.5},se={x:.5,y:1},ne={},oe={};const{set:ae,getAngle:re,getDistance:de}=E,{get:le,rotateOfOuter:he,scaleOfOuter:ce}=k,ue={x:.5,y:.5},fe={x:.5,y:1},pe={},_e={};const ge={linearGradient:function(t,i){let{from:s,to:n,type:o,blendMode:a,opacity:r}=t;s||(s=qt),n||(n=Ht);const d=e.canvas.createLinearGradient(i.x+s.x*i.width,i.y+s.y*i.height,i.x+n.x*i.width,i.y+n.y*i.height);Qt(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,i){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:d}=t;s||(s=ie),n||(n=se);const{x:l,y:h,width:c,height:u}=i;let f;Zt(ne,l+s.x*c,h+s.y*u),Zt(oe,l+n.x*c,h+n.y*u),(c!==u||d)&&(f=Kt(),ee(f,ne,c/u*(d||1),1),te(f,ne,$t(ne,oe)+90));const p=e.canvas.createRadialGradient(ne.x,ne.y,0,ne.x,ne.y,Jt(ne,oe));Qt(p,t.stops,a);const _={type:o,style:p,transform:f};return r&&(_.blendMode=r),_},conicGradient:function(t,i){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:d}=t;s||(s=ue),n||(n=fe);const{x:l,y:h,width:c,height:u}=i;ae(pe,l+s.x*c,h+s.y*u),ae(_e,l+n.x*c,h+n.y*u);const f=le(),p=re(pe,_e);e.conicGradientRotate90?(ce(f,pe,c/u*(d||1),1),he(f,pe,p+90)):(ce(f,pe,1,c/u*(d||1)),he(f,pe,p));const _=e.conicGradientSupport?e.canvas.createConicGradient(0,pe.x,pe.y):e.canvas.createRadialGradient(pe.x,pe.y,0,pe.x,pe.y,de(pe,_e));Qt(_,t.stops,a);const g={type:o,style:_,transform:f};return r&&(g.blendMode=r),g}},{copy:we,toOffsetOutBounds:ye}=R,me={},ve={};function xe(t,i,s,n){const{bounds:o,shapeBounds:a}=n;if(e.fullImageShadow){if(we(me,t.bounds),me.x+=i.x-a.x,me.y+=i.y-a.y,s){const{matrix:t}=n;me.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),me.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),me.width*=s,me.height*=s}t.copyWorld(n.canvas,t.bounds,me)}else s&&(we(me,i),me.x-=i.width/2*(s-1),me.y-=i.height/2*(s-1),me.width*=s,me.height*=s),t.copyWorld(n.canvas,a,s?me:i)}const{toOffsetOutBounds:be}=R,Be={};const Re={shadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;ye(l,ve),r.forEach(((r,_)=>{f.setWorldShadow(ve.offsetX+r.x*c,ve.offsetY+r.y*u,r.blur*c,r.color),n=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,xe(f,ve,n,i),s=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,o,"copy"),s=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(i.canvas,h,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,s,o,r.blendMode):e.copyWorldToInner(f,s,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(s,!0)})),f.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;be(l,Be),r.forEach(((r,_)=>{f.save(),f.setWorldShadow(Be.offsetX+r.x*c,Be.offsetY+r.y*u,r.blur*c),n=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,xe(f,Be,n,i),f.restore(),d?(f.copyWorld(f,l,o,"copy"),f.copyWorld(d,o,o,"source-out"),s=o):(f.copyWorld(i.canvas,h,l,"source-out"),s=l),f.fillWorld(s,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,s,o,r.blendMode):e.copyWorldToInner(f,s,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(s,!0)})),f.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:ke}=w;function Se(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),Le(t,e,i,1)}(t,i,s,n);break;case"opacity-path":Le(t,i,s,o);break;case"path":i.restore()}}function Ee(t){return t.getSameCanvas(!1,!0)}function Le(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}P.prototype.__renderMask=function(t,e){let i,s,n,o,a;const{children:r}=this;for(let d=0,l=r.length;d<l;d++)i=r[d],i.__.mask&&(a&&(Se(this,a,t,n,s,o),s=n=null),"path"===i.__.maskType?(i.opacity<1?(a="opacity-path",o=i.opacity,n||(n=Ee(t))):(a="path",t.save()),i.__clip(n||t,e)):(a="alpha",s||(s=Ee(t)),n||(n=Ee(t)),i.__render(s,e)),"clipping"!==i.__.maskType)||ke(i,e)||i.__render(n||t,e);Se(this,a,t,n,s,o)};const Ae=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",We=Ae+"_#~&*+\\=|≮≯≈≠=…",Oe=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map((([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`)).join("|"));function Te(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Me=Te("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ce=Te("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Ie=Te(Ae),Pe=Te(We),De=Te("- —/~|┆·");var Fe;!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"}(Fe||(Fe={}));const{Letter:ze,Single:Ye,Before:Ve,After:Ue,Symbol:Ge,Break:Ne}=Fe;function Xe(t){return Me[t]?ze:De[t]?Ne:Ce[t]?Ve:Ie[t]?Ue:Pe[t]?Ge:Oe.test(t)?Ye:ze}const je={trimRight(t){const{words:e}=t;let i,s=0,n=e.length;for(let o=n-1;o>-1&&(i=e[o].data[0]," "===i.char);o--)s++,t.width-=i.width;s&&e.splice(n-s,s)}};function qe(t,e,i){switch(e){case"title":return i?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:He}=je,{Letter:Qe,Single:Ze,Before:$e,After:Je,Symbol:Ke,Break:ti}=Fe;let ei,ii,si,ni,oi,ai,ri,di,li,hi,ci,ui,fi,pi,_i,gi,wi=[];function yi(t,e){li&&!di&&(di=li),ei.data.push({char:t,width:e}),si+=e}function mi(){ni+=si,ei.width=si,ii.words.push(ei),ei={data:[]},si=0}function vi(){pi&&(_i.paraNumber++,ii.paraStart=!0,pi=!1),li&&(ii.startCharSize=di,ii.endCharSize=li,di=0),ii.width=ni,gi.width&&He(ii),wi.push(ii),ii={words:[]},ni=0}const xi=0,bi=1,Bi=2;const{top:Ri,right:ki,bottom:Si,left:Ei}=L;function Li(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 Ai={getDrawData:function(t,i){"string"!=typeof t&&(t=String(t));let s=0,n=0,o=i.__getInput("width")||0,a=i.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=i;l&&(o&&(s=l[Ei],o-=l[ki]+l[Ei]),a&&(n=l[Ri],a-=l[Ri]+l[Si]));const h={bounds:{x:s,y:n,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,i,s){_i=t,wi=t.rows,gi=t.bounds;const{__letterSpacing:n,paraIndent:o,textCase:a}=s,{canvas:r}=e,{width:d,height:l}=gi;if(d||l||n||"none"!==a){const t="none"!==s.textWrap,e="break"===s.textWrap;pi=!0,ci=null,di=ri=li=si=ni=0,ei={data:[]},ii={words:[]};for(let s=0,l=i.length;s<l;s++)ai=i[s],"\n"===ai?(si&&mi(),ii.paraEnd=!0,vi(),pi=!0):(hi=Xe(ai),hi===Qe&&"none"!==a&&(ai=qe(ai,a,!si)),ri=r.measureText(ai).width,n&&(n<0&&(li=ri),ri+=n),ui=hi===Ze&&(ci===Ze||ci===Qe)||ci===Ze&&hi!==Je,fi=!(hi!==$e&&hi!==Ze||ci!==Ke&&ci!==Je),oi=pi&&o?d-o:d,t&&d&&ni+si+ri>oi&&(e?(si&&mi(),vi()):(fi||(fi=hi===Qe&&ci==Je),ui||fi||hi===ti||hi===$e||hi===Ze||si+ri>oi?(si&&mi(),vi()):vi()))," "===ai&&!0!==pi&&ni+si===0||(hi===ti?(" "===ai&&si&&mi(),yi(ai,ri),mi()):ui||fi?(si&&mi(),yi(ai,ri)):yi(ai,ri)),ci=hi);si&&mi(),ni&&vi(),wi.length>0&&(wi[wi.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{_i.paraNumber++,wi.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(h,t,i),l&&function(t,e,i,s,n){if(!s)switch(i.textAlign){case"left":Li(e,"x",t[Ei]);break;case"right":Li(e,"x",-t[ki])}if(!n)switch(i.verticalAlign){case"top":Li(e,"y",t[Ri]);break;case"bottom":Li(e,"y",-t[Si])}}(l,h,i,o,a),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:h}=e;let c,u,f,{x:p,y:_,width:g,height:w}=s,y=n*i.length+(h?h*(t.paraNumber-1):0),m=o;if(r&&y>w)y=Math.max(w,n),t.overflow=i.length;else switch(l){case"middle":_+=(w-y)/2;break;case"bottom":_+=w-y}m+=_;for(let o=0,l=i.length;o<l;o++){switch(c=i[o],c.x=p,d){case"center":c.x+=(g-c.width)/2;break;case"right":c.x+=g-c.width}c.paraStart&&h&&o>0&&(m+=h),c.y=m,m+=n,t.overflow>o&&m>y&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,f=c.width,a<0&&(c.width<0?(f=-c.width+e.fontSize+a,u-=f,f+=e.fontSize):f-=a),u<s.x&&(s.x=u),f>s.width&&(s.width=f),r&&g&&g<f&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=_,s.height=y}(h,i),function(t,e,i,s){const{rows:n}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,l,h,c,u;n.forEach((t=>{t.words&&(h=a&&t.paraStart?a:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-h)/(t.words.length-1):0,c=r||t.isOverflow?xi:l>.01?bi:Bi,t.isOverflow&&!r&&(t.textMode=!0),c===Bi?(t.x+=h,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=h,d=t.x,t.data=[],t.words.forEach((e=>{c===bi?(u={char:"",x:d},d=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,d,u)," "!==u.char&&t.data.push(u)):d=function(t,e,i){return t.forEach((t=>{" "!==t.char&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(h,i,o),h.overflow&&function(t,i){const{rows:s,overflow:n}=t;let{textOverflow:o}=i;if(s.splice(n),"hide"!==o){let t,a;"ellipsis"===o&&(o="...");const r=e.canvas.measureText(o).width,d=i.x+i.width-r;("none"===i.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],a=t.x+t.width,!(s===i&&a<d));s--){if(a<d&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=r,e.data.push({char:o,x:a}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(h,i),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(h,i),h}};const Wi={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:Oi,addPoint:Ti,toBounds:Mi}=A;const Ci={export(t,e,i){return this.running=!0,function(t){Ii||(Ii=new W);return new Promise((e=>{Ii.add((()=>Nt(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((()=>Nt(this,void 0,void 0,(function*(){i=d.getExportOptions(i);let s,n,l=1,h=1;const{worldTransform:c,isLeafer:u,isFrame:f}=t,{slice:p,trim:_,onCanvas:w}=i,y=i.scale||1,m=i.pixelRatio||1,v=i.screenshot||t.isApp,x=u&&v?void 0===i.fill?t.fill:void 0:i.fill,b=d.isOpaqueImage(e)||x,B=new O;if(v)s=!0===v?u?r.canvas.bounds:t.worldRenderBounds:v;else{const e=i.location||(u||f?"inner":"local");switch(l=c.scaleX,h=c.scaleY,e){case"inner":B.set(c).invert();break;case"local":B.set(c).divide(t.localTransform).invert(),l/=t.scaleX,h/=t.scaleY;break;case"world":l=1,h=1}s=t.getBounds("render",e)}const{x:R,y:k,width:S,height:E}=new g(s).scale(y).ceil();let L=a.canvas({width:S,height:E,pixelRatio:m});const A={matrix:B.scale(y).translate(-R,-k).withScale(1/l*y,1/h*y)};if(p&&(t=r,A.bounds=L.bounds),L.save(),f&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(L,A),t.fill=e}else t.__render(L,A);if(L.restore(),_){n=function(t){const{width:e,height:i}=t.view,{data:s}=t.context.getImageData(0,0,e,i);let n,o,a,r=0;for(let t=0;t<s.length;t+=4)0!==s[t+3]&&(n=r%e,o=(r-n)/e,a?Ti(a,n,o):Oi(a={},n,o)),r++;const d=new g;return Mi(a,d),d.scale(1/t.pixelRatio).ceil()}(L);const t=L,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:m};L=a.canvas(s),L.copyWorld(t,n,s)}b&&L.fillWorld(L.bounds,x||"#FFFFFF","destination-over"),w&&w(L);const W="canvas"===e?L:yield L.export(e,i);o({data:W,width:L.pixelWidth,height:L.pixelHeight,renderBounds:s,trimBounds:n})})))):o({data:!1})}))))}};let Ii;Object.assign(D,Ai),Object.assign(M,Wi),Object.assign(F,gt),Object.assign(T,jt),Object.assign(C,ge),Object.assign(z,Re),Object.assign(I,Ci);try{G(0,wx)}catch(t){}export{it as Layouter,Y as LeaferCanvas,nt as Renderer,N as Watcher,G as useCanvas};
1
+ import{LeaferCanvasBase as t,Platform as e,canvasPatch as i,DataHelper as s,canvasSizeAttrs as n,ResizeEvent as o,Creator as a,LeaferImage as r,FileHelper as d,LeafList as l,RenderEvent as h,ChildEvent as c,WatchEvent as u,PropertyEvent as f,LeafHelper as p,BranchHelper as _,Bounds as g,LeafBoundsHelper as w,Debug as y,LeafLevelList as m,LayoutEvent as v,Run as x,ImageManager as b,AnimateEvent as B,BoundsHelper as R,MatrixHelper as k,ImageEvent as S,PointHelper as E,Direction4 as L,TwoPointBoundsHelper as A,TaskProcessor as W,Matrix as T}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as O,ColorConvert as M,PaintGradient as C,Export as I,Group as P,TextConvert as D,Paint as F,Effect as z}from"@leafer-ui/draw";export*from"@leafer-ui/draw";class Y extends t{get allowBackgroundColor(){return!1}init(){let{view:t}=this.config;t?("string"==typeof t?("#"!==t[0]&&(t="#"+t),this.viewSelect=e.miniapp.select(t)):t.fields?this.viewSelect=t:this.initView(t),this.viewSelect&&e.miniapp.getSizeView(this.viewSelect).then((t=>{this.initView(t)}))):this.initView()}initView(t){t?this.view=t.view||t:(t={},this.__createView()),this.__createContext();const{width:e,height:s,pixelRatio:n}=this.config,o={width:e||t.width,height:s||t.height,pixelRatio:n};this.resize(o),this.context.roundRect&&(this.roundRect=function(t,e,i,s,n){this.context.roundRect(t,e,i,s,"number"==typeof n?[n]:n)}),i(this.context.__proto__)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:i}=this;this.view.width=Math.ceil(t*i),this.view.height=Math.ceil(e*i)}updateClientBounds(t){this.viewSelect&&e.miniapp.getBounds(this.viewSelect).then((e=>{this.clientBounds=e,t&&t()}))}startAutoLayout(t,i){this.resizeListener=i,this.checkSize=this.checkSize.bind(this),e.miniapp.onWindowResize(this.checkSize)}checkSize(){this.viewSelect&&setTimeout((()=>{this.updateClientBounds((()=>{const{width:t,height:e}=this.clientBounds,{pixelRatio:i}=this,a={width:t,height:e,pixelRatio:i};if(!this.isSameSize(a)){const t={};s.copyAttrs(t,this,n),this.resize(a),void 0!==this.width&&this.resizeListener(new o(a,t))}}))}),500)}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,e.miniapp.offWindowResize(this.checkSize)}}const{mineType:V,fileType:U}=d;function X(t,i){e.origin||(e.origin={createCanvas:(t,e,s)=>i.createOffscreenCanvas({type:"2d",width:t,height:e}),canvasToDataURL:(t,e,i)=>t.toDataURL(V(e),i),canvasToBolb:(t,e,i)=>t.toBuffer(e,{quality:i}),canvasSaveAs:(t,s,n)=>new Promise(((o,a)=>{let r,d=t.toDataURL(V(U(s)),n);d=d.substring(d.indexOf("64,")+3),s.includes("/")||(s=`${i.env.USER_DATA_PATH}/`+s,r=!0);const l=i.getFileSystemManager();l.writeFile({filePath:s,data:d,encoding:"base64",success(){r&&e.miniapp.saveToAlbum(s).then((()=>{l.unlink({filePath:s})})),o()},fail(t){a(t)}})})),loadImage:t=>new Promise(((i,s)=>{const n=e.canvas.view.createImage();n.onload=()=>{i(n)},n.onerror=t=>{s(t)},n.src=t})),noRepeat:"repeat-x"},e.miniapp={select:t=>i.createSelectorQuery().select(t),getBounds:t=>new Promise((e=>{t.boundingClientRect().exec((t=>{const i=t[1];e({x:i.top,y:i.left,width:i.width,height:i.height})}))})),getSizeView:t=>new Promise((e=>{t.fields({node:!0,size:!0}).exec((t=>{const i=t[0];e({view:i.node,width:i.width,height:i.height})}))})),saveToAlbum:t=>new Promise((e=>{i.getSetting({success:s=>{s.authSetting["scope.writePhotosAlbum"]?i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}}):i.authorize({scope:"scope.writePhotosAlbum",success:()=>{i.saveImageToPhotosAlbum({filePath:t,success(){e(!0)}})},fail:()=>{}})}})})),onWindowResize(t){i.onWindowResize(t)},offWindowResize(t){i.offWindowResize(t)}},e.event={stopDefault(t){},stopNow(t){},stop(t){}},e.canvas=a.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient)}Object.assign(a,{canvas:(t,e)=>new Y(t,e),image:t=>new r(t)}),e.name="miniapp",e.requestRender=function(t){e.canvas.view.requestAnimationFrame(t)},e.devicePixelRatio=wx.getSystemInfoSync().pixelRatio;class G{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new l;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 l,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(h.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(t){t.type===c.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 u(u.DATA,{updatedList:this.updatedList})),this.__updatedList=new l,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(f.CHANGE,this.__onAttrChange,this),t.on_([c.ADD,c.REMOVE],this.__onChildEvent,this),t.on_(u.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:N,updateBounds:j,updateAllWorldOpacity:q}=p,{pushAllChildBranch:H,pushAllParent:Q}=_;const{worldBounds:Z}=w,$={x:0,y:0,width:1e5,height:1e5};class J{constructor(t){this.updatedBounds=new g,this.beforeBounds=new g,this.afterBounds=new g,t instanceof Array&&(t=new l(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,Z)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set($):this.afterBounds.setListWithFn(t,Z),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:K,updateAllChange:tt}=p,et=y.get("Layouter");class it{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new m,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(v.START),this.layoutOnce(),t.emitEvent(new v(v.END,this.layoutedBlocks,this.times))}catch(t){et.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?et.warn("layouting"):this.times>3?et.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(u.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:a}=v,r=this.getBlocks(s);r.forEach((t=>t.setBefore())),i.emitEvent(new v(n,r,this.times)),this.extraBlock=null,s.sort(),function(t,e){let i;t.list.forEach((t=>{i=t.__layout,e.without(t)&&!i.proxyZoom&&(i.matrixChanged?(N(t,!0),e.add(t),t.isBranch&&H(t,e),Q(t,e)):i.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),Q(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||j(s[t])}j(i)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&q(t),t.__updateChange()}))}(s),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),i.emitEvent(new v(o,r,this.times)),i.emitEvent(new v(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,x.end(e)}fullLayout(){const t=x.start("FullLayout"),{target:e}=this,{BEFORE:i,LAYOUT:s,AFTER:n}=v,o=this.getBlocks(new l(e));e.emitEvent(new v(i,o,this.times)),it.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new v(s,o,this.times)),e.emitEvent(new v(n,o,this.times)),this.addBlocks(o),x.end(t)}static fullLayout(t){K(t,!0),t.isBranch?_.updateBounds(t):p.updateBounds(t),tt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:i}=this.extraBlock||(this.extraBlock=new J([]));e.length?i.add(t.__world):i.set(t.__world),e.add(t)}}createBlock(t){return new J(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_(v.REQUEST,this.layout,this),t.on_(v.AGAIN,this.layoutAgain,this),t.on_(u.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const st=y.get("Renderer");class nt{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(v.REQUEST)}render(t){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:e}=this;this.times=0,this.totalBounds=new g,st.log(e.innerName,"---\x3e");try{this.emitRender(h.START),this.renderOnce(t),this.emitRender(h.END,this.totalBounds),b.clearRecycled()}catch(t){this.rendering=!1,st.error(t)}st.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return st.warn("rendering");if(this.times>3)return st.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new g,this.renderOptions={},t)this.emitRender(h.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(h.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(h.RENDER,this.renderBounds,this.renderOptions),this.emitRender(h.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return st.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=x.start("PartRender"),{canvas:i}=this,s=t.getIntersect(i.bounds),n=t.includes(this.target.__world),o=new g(s);i.save(),n&&!y.showRepaint?i.clear():(s.spread(1+1/this.canvas.pixelRatio).ceil(),i.clearWorld(s,!0),i.clipWorld(s,!0)),this.__render(s,n,o),i.restore(),x.end(e)}fullRender(){const t=x.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),x.end(t)}__render(t,e,i){const s=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),y.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,s),this.renderBounds=i||t,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=this.renderBounds:this.totalBounds.add(this.renderBounds),y.showHitView&&this.renderHitView(s),y.showBoundsView&&this.renderBoundsView(s),this.canvas.updateRender()}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new g;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.target.emit(B.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(h.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal&&(t.bigger||!t.samePixelRatio)){const{width:e,height:i}=t.old;new g(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||st.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,i){this.target.emitEvent(new h(t,this.times,e,i))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(h.REQUEST,this.update,this),t.on_(v.END,this.__onLayoutEnd,this),t.on_(h.AGAIN,this.renderAgain,this),t.on_(o.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}function ot(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;t++)i=s[t],i.text?e.fillText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.fillText(t.char,t.x,i.y)})),n&&e.fillRect(i.x,i.y+n,i.width,o)}function at(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?lt(t,!0,e,i):dt(e,i);break;case"inside":rt("inside",t,n,e,i);break;case"outside":rt("outside",t,n,e,i)}}function rt(t,e,i,s,n){const{__strokeWidth:o,__font:a}=s.__,r=n.getSameCanvas(!0,!0);r.setStroke(i?void 0:e,2*o,s.__),r.font=a,i?lt(e,!0,s,r):dt(s,r),r.blendMode="outside"===t?"destination-out":"destination-in",ot(s,r),r.blendMode="normal",s.__worldFlipped?n.copyWorldByReset(r,s.__nowWorld):n.copyWorldToInner(r,s.__nowWorld,s.__layout.renderBounds),r.recycle(s.__nowWorld)}function dt(t,e){let i;const{rows:s,decorationY:n,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=s.length;t<a;t++)i=s[t],i.text?e.strokeText(i.text,i.x,i.y):i.data&&i.data.forEach((t=>{e.strokeText(t.char,t.x,i.y)})),n&&e.strokeRect(i.x,i.y+n,i.width,o)}function lt(t,e,i,s){let n;for(let o=0,a=t.length;o<a;o++)n=t[o],n.image&&O.checkImage(i,s,n,!1)||n.style&&(s.strokeStyle=n.style,n.blendMode?(s.saveBlendMode(n.blendMode),e?dt(i,s):s.stroke(),s.restoreBlendMode()):e?dt(i,s):s.stroke())}Object.assign(a,{watcher:(t,e)=>new G(t,e),layouter:(t,e)=>new it(t,e),renderer:(t,e,i)=>new nt(t,e,i),selector:(t,e)=>{},interaction:(t,e,i,s)=>{}}),e.layout=it.fullLayout;const{getSpread:ht,getOuterOf:ct,getByMove:ut,getIntersectData:ft}=R;let pt;function _t(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:s}=i.__layout;switch(e.type){case"solid":let{type:n,blendMode:o,color:a,opacity:r}=e;return{type:n,blendMode:o,style:M.string(a,r)};case"image":return O.image(i,t,e,s,!pt||!pt[e.url]);case"linear":return C.linearGradient(e,s);case"radial":return C.radialGradient(e,s);case"angular":return C.conicGradient(e,s);default:return e.r?{type:"solid",style:M.string(e)}:void 0}}const gt={compute:function(t,e){const i=e.__,s=[];let n,o=i.__input[t];o instanceof Array||(o=[o]),pt=O.recycleImage(t,i);for(let i,n=0,a=o.length;n<a;n++)i=_t(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?ot(e,i):e.__.windingRule?i.fill(e.__.windingRule):i.fill()},fills:function(t,e,i){let s;const{windingRule:n,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)s=t[a],s.image&&O.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?ot(e,i):n?i.fill(n):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),o?ot(e,i):n?i.fill(n):i.fill(),i.restoreBlendMode()):o?ot(e,i):n?i.fill(n):i.fill())},fillText:ot,stroke:function(t,e,i){const s=e.__,{__strokeWidth:n,strokeAlign:o,__font:a}=s;if(n)if(a)at(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:a}=s;if(n)if(a)at(t,e,i);else switch(o){case"center":i.setStroke(void 0,n,s),lt(t,!1,e,i);break;case"inside":i.save(),i.setStroke(void 0,2*n,s),s.windingRule?i.clip(s.windingRule):i.clip(),lt(t,!1,e,i),i.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=i.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*n,s),lt(t,!1,e,a),s.windingRule?a.clip(s.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?i.copyWorldByReset(a,e.__nowWorld):i.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:at,drawTextStroke:dt,shape:function(t,e,i){const s=e.getSameCanvas(),n=t.__nowWorld;let o,a,r,d,{scaleX:l,scaleY:h}=n;if(l<0&&(l=-l),h<0&&(h=-h),e.bounds.includes(n))d=s,o=r=n;else{const{renderShapeSpread:s}=t.__layout,c=ft(s?ht(e.bounds,s*l,s*h):e.bounds,n);a=e.bounds.getFitMatrix(c);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,i),l*=u,h*=f),r=ct(n,a),o=ut(r,-a.e,-a.f),i.matrix){const{matrix:t}=i;a.multiply(t),u*=t.scaleX,f*=t.scaleY}i=Object.assign(Object.assign({},i),{matrix:a.withScale(u,f)})}return t.__renderShape(s,i),{canvas:s,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:h}}};let wt={};const{get:yt,rotateOfOuter:mt,translate:vt,scaleOfOuter:xt,scale:bt,rotate:Bt}=k;function Rt(t,e,i,s,n,o){const a=yt(),r=o&&180!==o,d=i.width/(r?n:s),l=i.height/(r?s:n),h="fit"===e?Math.min(d,l):Math.max(d,l),c=i.x+(i.width-s*h)/2,u=i.y+(i.height-n*h)/2;vt(a,c,u),bt(a,h),o&&mt(a,{x:i.x+i.width/2,y:i.y+i.height/2},o),t.scaleX=t.scaleY=h,t.transform=a}function kt(t,e,i,s,n,o,a){const r=yt();vt(r,e.x,e.y),(i||s)&&vt(r,i,s),n&&(bt(r,n,o),t.scaleX=r.a,t.scaleY=r.d),a&&Bt(r,a),t.transform=r}function St(t,e,i,s,n,o,a,r,d){const l=yt();if(d)switch(Bt(l,d),d){case 90:vt(l,s,0);break;case 180:vt(l,i,s);break;case 270:vt(l,0,i)}wt.x=e.x,wt.y=e.y,(n||o)&&(wt.x+=n,wt.y+=o),vt(l,wt.x,wt.y),a&&(xt(l,wt,a,r),t.scaleX=a,t.scaleY=r),t.transform=l}const{get:Et,translate:Lt}=k;function At(t,e,i,s){let{width:n,height:o}=e;const{opacity:a,mode:r,offset:d,scale:l,size:h,rotation:c,blendMode:u,repeat:f}=i,p=s.width===n&&s.height===o;u&&(t.blendMode=u);const _=t.data={mode:r};let g,w,y,m;switch(d&&(g=d.x,w=d.y),h?(y=("number"==typeof h?h:h.width)/n,m=("number"==typeof h?h:h.height)/o):l&&(y="number"==typeof l?l:l.x,m="number"==typeof l?l:l.y),r){case"strench":p||(n=s.width,o=s.height);break;case"clip":(d||y||c)&&kt(_,s,g,w,y,m,c);break;case"repeat":(!p||y||c)&&St(_,s,n,o,g,w,y,m,c),f||(_.repeat="repeat");break;default:p&&!c||Rt(_,r,s,n,o,c)}_.transform||(s.x||s.y)&&(_.transform=Et(),Lt(_.transform,s.x,s.y)),_.width=n,_.height=o,a&&(_.opacity=a),f&&(_.repeat="string"==typeof f?"x"===f?"repeat-x":"repeat-y":"repeat")}let Wt,Tt=new g;const{isSame:Ot}=R;function Mt(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||At(n,s,i,o),!0}function Ct(t,e){Dt(t,S.LOAD,e)}function It(t,e){Dt(t,S.LOADED,e)}function Pt(t,e,i){e.error=i,t.forceUpdate("surface"),Dt(t,S.ERROR,e)}function Dt(t,e,i){t.hasEvent(e)&&t.emitEvent(new S(e,i))}function Ft(t,e){const{leafer:i}=t;i&&i.viewReady&&(i.renderer.ignore=e)}const{get:zt,scale:Yt,copy:Vt}=k,{ceil:Ut,abs:Xt}=Math;function Gt(t,i,s){let{scaleX:n,scaleY:o}=t.__nowWorld;const a=n+"-"+o;if(i.patternId===a||t.destroyed)return!1;{n=Xt(n),o=Xt(o);const{image:t,data:r}=i;let d,l,{width:h,height:c,scaleX:u,scaleY:f,opacity:p,transform:_,repeat:g}=r;u&&(l=zt(),Vt(l,_),Yt(l,1/u,1/f),n*=u,o*=f),n*=s,o*=s,h*=n,c*=o;const w=h*c;if(!g&&w>e.image.maxCacheSize)return!1;let y=e.image.maxPatternSize;if(!t.isSVG){const e=t.width*t.height;y>e&&(y=e)}w>y&&(d=Math.sqrt(w/y)),d&&(n/=d,o/=d,h/=d,c/=d),u&&(n/=u,o/=f),(_||1!==n||1!==o)&&(l||(l=zt(),_&&Vt(l,_)),Yt(l,1/n,1/o));const m=t.getCanvas(Ut(h)||1,Ut(c)||1,p),v=t.getPattern(m,g||e.origin.noRepeat||"no-repeat",l,i);return i.style=v,i.patternId=a,!0}}function Nt(t,e,i,s){return new(i||(i=Promise))((function(n,o){function a(t){try{d(s.next(t))}catch(t){o(t)}}function r(t){try{d(s.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,r)}d((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:jt}=Math;const qt={image:function(t,e,i,s,n){let o,a;const r=b.get(i);return Wt&&i===Wt.paint&&Ot(s,Wt.boxBounds)?o=Wt.leafPaint:(o={type:i.type,image:r},Wt=r.use>1?{leafPaint:o,paint:i,boxBounds:Tt.set(s)}:null),(n||r.loading)&&(a={image:r,attrName:e,attrValue:i}),r.ready?(Mt(t,e,i,r,o,s),n&&(Ct(t,a),It(t,a))):r.error?n&&Pt(t,a,r.error):(Ft(t,!0),n&&Ct(t,a),o.loadId=r.load((()=>{Ft(t,!1),t.destroyed||(Mt(t,e,i,r,o,s)&&t.forceUpdate("surface"),It(t,a)),o.loadId=null}),(e=>{Ft(t,!1),Pt(t,a,e),o.loadId=null}))),o},createData:At,fillOrFitMode:Rt,clipMode:kt,repeatMode:St,createPattern:Gt,checkImage:function(t,i,s,n){const{scaleX:o,scaleY:a}=t.__nowWorld;if(s.data&&s.patternId!==o+"-"+a){const{data:r}=s;if(n)if(r.repeat)n=!1;else{let{width:t,height:s}=r;t*=jt(o)*i.pixelRatio,s*=jt(a)*i.pixelRatio,r.scaleX&&(t*=r.scaleX,s*=r.scaleY),n=t*s>e.image.maxCacheSize}return n?(i.save(),i.clip(),s.blendMode&&(i.blendMode=s.blendMode),r.opacity&&(i.opacity*=r.opacity),r.transform&&i.transform(r.transform),i.drawImage(s.image.view,0,0,r.width,r.height),i.restore(),!0):(!s.style||I.running?Gt(t,s,i.pixelRatio):s.patternTask||(s.patternTask=b.patternTasker.add((()=>Nt(this,void 0,void 0,(function*(){s.patternTask=null,i.bounds.hit(t.__nowWorld)&&Gt(t,s,i.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}return!1},recycleImage:function(t,e){const i=e["_"+t];if(i instanceof Array){let s,n,o,a;for(let r=0,d=i.length;r<d;r++)s=i[r].image,a=s&&s.url,a&&(n||(n={}),n[a]=!0,b.recycle(s),s.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),s.unload(i[r].loadId,!o.some((t=>t.url===a)))));return n}return null}},Ht={x:.5,y:0},Qt={x:.5,y:1};function Zt(t,e,i){let s;for(let n=0,o=e.length;n<o;n++)s=e[n],t.addColorStop(s.offset,M.string(s.color,i))}const{set:$t,getAngle:Jt,getDistance:Kt}=E,{get:te,rotateOfOuter:ee,scaleOfOuter:ie}=k,se={x:.5,y:.5},ne={x:.5,y:1},oe={},ae={};const{set:re,getAngle:de,getDistance:le}=E,{get:he,rotateOfOuter:ce,scaleOfOuter:ue}=k,fe={x:.5,y:.5},pe={x:.5,y:1},_e={},ge={};const we={linearGradient:function(t,i){let{from:s,to:n,type:o,blendMode:a,opacity:r}=t;s||(s=Ht),n||(n=Qt);const d=e.canvas.createLinearGradient(i.x+s.x*i.width,i.y+s.y*i.height,i.x+n.x*i.width,i.y+n.y*i.height);Zt(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,i){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:d}=t;s||(s=se),n||(n=ne);const{x:l,y:h,width:c,height:u}=i;let f;$t(oe,l+s.x*c,h+s.y*u),$t(ae,l+n.x*c,h+n.y*u),(c!==u||d)&&(f=te(),ie(f,oe,c/u*(d||1),1),ee(f,oe,Jt(oe,ae)+90));const p=e.canvas.createRadialGradient(oe.x,oe.y,0,oe.x,oe.y,Kt(oe,ae));Zt(p,t.stops,a);const _={type:o,style:p,transform:f};return r&&(_.blendMode=r),_},conicGradient:function(t,i){let{from:s,to:n,type:o,opacity:a,blendMode:r,stretch:d}=t;s||(s=fe),n||(n=pe);const{x:l,y:h,width:c,height:u}=i;re(_e,l+s.x*c,h+s.y*u),re(ge,l+n.x*c,h+n.y*u);const f=he(),p=de(_e,ge);e.conicGradientRotate90?(ue(f,_e,c/u*(d||1),1),ce(f,_e,p+90)):(ue(f,_e,1,c/u*(d||1)),ce(f,_e,p));const _=e.conicGradientSupport?e.canvas.createConicGradient(0,_e.x,_e.y):e.canvas.createRadialGradient(_e.x,_e.y,0,_e.x,_e.y,le(_e,ge));Zt(_,t.stops,a);const g={type:o,style:_,transform:f};return r&&(g.blendMode=r),g}},{copy:ye,toOffsetOutBounds:me}=R,ve={},xe={};function be(t,i,s,n){const{bounds:o,shapeBounds:a}=n;if(e.fullImageShadow){if(ye(ve,t.bounds),ve.x+=i.x-a.x,ve.y+=i.y-a.y,s){const{matrix:t}=n;ve.x-=(o.x+(t?t.e:0)+o.width/2)*(s-1),ve.y-=(o.y+(t?t.f:0)+o.height/2)*(s-1),ve.width*=s,ve.height*=s}t.copyWorld(n.canvas,t.bounds,ve)}else s&&(ye(ve,i),ve.x-=i.width/2*(s-1),ve.y-=i.height/2*(s-1),ve.width*=s,ve.height*=s),t.copyWorld(n.canvas,a,s?ve:i)}const{toOffsetOutBounds:Be}=R,Re={};const ke={shadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;me(l,xe),r.forEach(((r,_)=>{f.setWorldShadow(xe.offsetX+r.x*c,xe.offsetY+r.y*u,r.blur*c,r.color),n=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,be(f,xe,n,i),s=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,o,"copy"),s=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(i.canvas,h,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,s,o,r.blendMode):e.copyWorldToInner(f,s,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(s,!0)})),f.recycle(s)},innerShadow:function(t,e,i){let s,n;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:h,scaleX:c,scaleY:u}=i,f=e.getSameCanvas(),p=r.length-1;Be(l,Re),r.forEach(((r,_)=>{f.save(),f.setWorldShadow(Re.offsetX+r.x*c,Re.offsetY+r.y*u,r.blur*c),n=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,be(f,Re,n,i),f.restore(),d?(f.copyWorld(f,l,o,"copy"),f.copyWorld(d,o,o,"source-out"),s=o):(f.copyWorld(i.canvas,h,l,"source-out"),s=l),f.fillWorld(s,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,s,o,r.blendMode):e.copyWorldToInner(f,s,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(s,!0)})),f.recycle(s)},blur:function(t,e,i){const{blur:s}=t.__;i.setWorldBlur(s*t.__nowWorld.a),i.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),i.filter="none"},backgroundBlur:function(t,e,i){}},{excludeRenderBounds:Se}=w;function Ee(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),Ae(t,e,i,1)}(t,i,s,n);break;case"opacity-path":Ae(t,i,s,o);break;case"path":i.restore()}}function Le(t){return t.getSameCanvas(!1,!0)}function Ae(t,e,i,s){const n=t.__nowWorld;e.resetTransform(),e.opacity=s,e.copyWorld(i,n),i.recycle(n)}P.prototype.__renderMask=function(t,e){let i,s,n,o,a;const{children:r}=this;for(let d=0,l=r.length;d<l;d++)i=r[d],i.__.mask&&(a&&(Ee(this,a,t,n,s,o),s=n=null),"path"===i.__.maskType?(i.opacity<1?(a="opacity-path",o=i.opacity,n||(n=Le(t))):(a="path",t.save()),i.__clip(n||t,e)):(a="alpha",s||(s=Le(t)),n||(n=Le(t)),i.__render(s,e)),"clipping"!==i.__.maskType)||Se(i,e)||i.__render(n||t,e);Ee(this,a,t,n,s,o)};const We=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Te=We+"_#~&*+\\=|≮≯≈≠=…",Oe=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map((([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`)).join("|"));function Me(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Ce=Me("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ie=Me("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Pe=Me(We),De=Me(Te),Fe=Me("- —/~|┆·");var ze;!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"}(ze||(ze={}));const{Letter:Ye,Single:Ve,Before:Ue,After:Xe,Symbol:Ge,Break:Ne}=ze;function je(t){return Ce[t]?Ye:Fe[t]?Ne:Ie[t]?Ue:Pe[t]?Xe:De[t]?Ge:Oe.test(t)?Ve:Ye}const qe={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 He(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:Qe}=qe,{Letter:Ze,Single:$e,Before:Je,After:Ke,Symbol:ti,Break:ei}=ze;let ii,si,ni,oi,ai,ri,di,li,hi,ci,ui,fi,pi,_i,gi,wi,yi=[];function mi(t,e){hi&&!li&&(li=hi),ii.data.push({char:t,width:e}),ni+=e}function vi(){oi+=ni,ii.width=ni,si.words.push(ii),ii={data:[]},ni=0}function xi(){_i&&(gi.paraNumber++,si.paraStart=!0,_i=!1),hi&&(si.startCharSize=li,si.endCharSize=hi,li=0),si.width=oi,wi.width&&Qe(si),yi.push(si),si={words:[]},oi=0}const bi=0,Bi=1,Ri=2;const{top:ki,right:Si,bottom:Ei,left:Li}=L;function Ai(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 Wi={getDrawData:function(t,i){"string"!=typeof t&&(t=String(t));let s=0,n=0,o=i.__getInput("width")||0,a=i.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=i;l&&(o&&(s=l[Li],o-=l[Si]+l[Li]),a&&(n=l[ki],a-=l[ki]+l[Ei]));const h={bounds:{x:s,y:n,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,i,s){gi=t,yi=t.rows,wi=t.bounds;const{__letterSpacing:n,paraIndent:o,textCase:a}=s,{canvas:r}=e,{width:d,height:l}=wi;if(d||l||n||"none"!==a){const t="none"!==s.textWrap,e="break"===s.textWrap;_i=!0,ui=null,li=di=hi=ni=oi=0,ii={data:[]},si={words:[]};for(let s=0,l=i.length;s<l;s++)ri=i[s],"\n"===ri?(ni&&vi(),si.paraEnd=!0,xi(),_i=!0):(ci=je(ri),ci===Ze&&"none"!==a&&(ri=He(ri,a,!ni)),di=r.measureText(ri).width,n&&(n<0&&(hi=di),di+=n),fi=ci===$e&&(ui===$e||ui===Ze)||ui===$e&&ci!==Ke,pi=!(ci!==Je&&ci!==$e||ui!==ti&&ui!==Ke),ai=_i&&o?d-o:d,t&&d&&oi+ni+di>ai&&(e?(ni&&vi(),xi()):(pi||(pi=ci===Ze&&ui==Ke),fi||pi||ci===ei||ci===Je||ci===$e||ni+di>ai?(ni&&vi(),xi()):xi()))," "===ri&&!0!==_i&&oi+ni===0||(ci===ei?(" "===ri&&ni&&vi(),mi(ri,di),vi()):fi||pi?(ni&&vi(),mi(ri,di)):mi(ri,di)),ui=ci);ni&&vi(),oi&&xi(),yi.length>0&&(yi[yi.length-1].paraEnd=!0)}else i.split("\n").forEach((t=>{gi.paraNumber++,yi.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(h,t,i),l&&function(t,e,i,s,n){if(!s)switch(i.textAlign){case"left":Ai(e,"x",t[Li]);break;case"right":Ai(e,"x",-t[Si])}if(!n)switch(i.verticalAlign){case"top":Ai(e,"y",t[ki]);break;case"bottom":Ai(e,"y",-t[Ei])}}(l,h,i,o,a),function(t,e){const{rows:i,bounds:s}=t,{__lineHeight:n,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:h}=e;let c,u,f,{x:p,y:_,width:g,height:w}=s,y=n*i.length+(h?h*(t.paraNumber-1):0),m=o;if(r&&y>w)y=Math.max(w,n),t.overflow=i.length;else switch(l){case"middle":_+=(w-y)/2;break;case"bottom":_+=w-y}m+=_;for(let o=0,l=i.length;o<l;o++){switch(c=i[o],c.x=p,d){case"center":c.x+=(g-c.width)/2;break;case"right":c.x+=g-c.width}c.paraStart&&h&&o>0&&(m+=h),c.y=m,m+=n,t.overflow>o&&m>y&&(c.isOverflow=!0,t.overflow=o+1),u=c.x,f=c.width,a<0&&(c.width<0?(f=-c.width+e.fontSize+a,u-=f,f+=e.fontSize):f-=a),u<s.x&&(s.x=u),f>s.width&&(s.width=f),r&&g&&g<f&&(c.isOverflow=!0,t.overflow||(t.overflow=i.length))}s.y=_,s.height=y}(h,i),function(t,e,i,s){const{rows:n}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,l,h,c,u;n.forEach((t=>{t.words&&(h=a&&t.paraStart?a:0,l=i&&"justify"===o&&t.words.length>1?(i-t.width-h)/(t.words.length-1):0,c=r||t.isOverflow?bi:l>.01?Bi:Ri,t.isOverflow&&!r&&(t.textMode=!0),c===Ri?(t.x+=h,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=h,d=t.x,t.data=[],t.words.forEach((e=>{c===Bi?(u={char:"",x:d},d=function(t,e,i){return t.forEach((t=>{i.char+=t.char,e+=t.width})),e}(e.data,d,u)," "!==u.char&&t.data.push(u)):d=function(t,e,i){return t.forEach((t=>{" "!==t.char&&(t.x=e,i.push(t)),e+=t.width})),e}(e.data,d,t.data),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(h,i,o),h.overflow&&function(t,i){const{rows:s,overflow:n}=t;let{textOverflow:o}=i;if(s.splice(n),"hide"!==o){let t,a;"ellipsis"===o&&(o="...");const r=e.canvas.measureText(o).width,d=i.x+i.width-r;("none"===i.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],a=t.x+t.width,!(s===i&&a<d));s--){if(a<d&&" "!==t.char){e.data.splice(s+1),e.width-=t.width;break}e.width-=t.width}e.width+=r,e.data.push({char:o,x:a}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(h,i),"none"!==r&&function(t,e){const{fontSize:i}=e;switch(t.decorationHeight=i/11,e.textDecoration){case"under":t.decorationY=.15*i;break;case"delete":t.decorationY=.35*-i}}(h,i),h}};const Ti={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:Oi,addPoint:Mi,toBounds:Ci}=A;const Ii={export(t,e,i){return this.running=!0,function(t){Pi||(Pi=new W);return new Promise((e=>{Pi.add((()=>Nt(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((()=>Nt(this,void 0,void 0,(function*(){i=d.getExportOptions(i);let s,n,l=1,h=1;const{worldTransform:c,isLeafer:u,isFrame:f}=t,{slice:p,trim:_,onCanvas:w}=i,y=i.scale||1,m=i.pixelRatio||1,v=i.screenshot||t.isApp,x=u&&v?void 0===i.fill?t.fill:void 0:i.fill,b=d.isOpaqueImage(e)||x,B=new T;if(v)s=!0===v?u?r.canvas.bounds:t.worldRenderBounds:v;else{let e=i.relative||(u?"inner":"local");switch(l=c.scaleX,h=c.scaleY,e){case"inner":B.set(c).invert();break;case"local":B.set(c).divide(t.localTransform).invert(),l/=t.scaleX,h/=t.scaleY;break;case"world":l=1,h=1;break;case"page":e=t.leafer;default:B.set(c).divide(t.getTransform(e)).invert();const i=e.worldTransform;l/=l/i.scaleX,h/=h/i.scaleY}s=t.getBounds("render",e)}const{x:R,y:k,width:S,height:E}=new g(s).scale(y);let L=a.canvas({width:Math.round(S),height:Math.round(E),pixelRatio:m});const A={matrix:B.scale(y).translate(-R,-k).withScale(1/l*y,1/h*y)};if(p&&(t=r,A.bounds=L.bounds),L.save(),f&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(L,A),t.fill=e}else t.__render(L,A);if(L.restore(),_){n=function(t){const{width:e,height:i}=t.view,{data:s}=t.context.getImageData(0,0,e,i);let n,o,a,r=0;for(let t=0;t<s.length;t+=4)0!==s[t+3]&&(n=r%e,o=(r-n)/e,a?Mi(a,n,o):Oi(a={},n,o)),r++;const d=new g;return Ci(a,d),d.scale(1/t.pixelRatio).ceil()}(L);const t=L,{width:e,height:i}=n,s={x:0,y:0,width:e,height:i,pixelRatio:m};L=a.canvas(s),L.copyWorld(t,n,s)}b&&L.fillWorld(L.bounds,x||"#FFFFFF","destination-over"),w&&w(L);const W="canvas"===e?L:yield L.export(e,i);o({data:W,width:L.pixelWidth,height:L.pixelHeight,renderBounds:s,trimBounds:n})})))):o({data:!1})}))))}};let Pi;Object.assign(D,Wi),Object.assign(M,Ti),Object.assign(F,gt),Object.assign(O,qt),Object.assign(C,we),Object.assign(z,ke),Object.assign(I,Ii);try{X(0,wx)}catch(t){}export{it as Layouter,Y as LeaferCanvas,nt as Renderer,G as Watcher,X as useCanvas};