@leafer-draw/worker 1.0.2 → 1.0.3

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/dist/worker.cjs CHANGED
@@ -228,9 +228,13 @@ function updateBounds(boundsList) {
228
228
  });
229
229
  }
230
230
  function updateChange(updateList) {
231
+ let layout;
231
232
  updateList.list.forEach(leaf => {
232
- if (leaf.__layout.opacityChanged)
233
+ layout = leaf.__layout;
234
+ if (layout.opacityChanged)
233
235
  updateAllWorldOpacity(leaf);
236
+ if (layout.stateStyleChanged)
237
+ setTimeout(() => layout.stateStyleChanged && leaf.updateState());
234
238
  leaf.__updateChange();
235
239
  });
236
240
  }
@@ -596,7 +600,6 @@ class Renderer {
596
600
  core.Platform.requestRender(() => {
597
601
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - startTime)));
598
602
  if (this.running) {
599
- this.target.emit(core.AnimateEvent.FRAME);
600
603
  if (this.changed && this.canvas.view)
601
604
  this.render();
602
605
  this.target.emit(core.RenderEvent.NEXT);
@@ -1034,6 +1037,8 @@ function getPatternData(paint, box, image) {
1034
1037
  let { width, height } = image;
1035
1038
  if (paint.padding)
1036
1039
  box = tempBox.set(box).shrink(paint.padding);
1040
+ if (paint.mode === 'strench')
1041
+ paint.mode = 'stretch';
1037
1042
  const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint;
1038
1043
  const sameBox = box.width === width && box.height === height;
1039
1044
  const data = { mode };
@@ -1062,7 +1067,7 @@ function getPatternData(paint, box, image) {
1062
1067
  if (offset)
1063
1068
  x += offset.x, y += offset.y;
1064
1069
  switch (mode) {
1065
- case 'strench':
1070
+ case 'stretch':
1066
1071
  if (!sameBox)
1067
1072
  width = box.width, height = box.height;
1068
1073
  break;
@@ -1089,7 +1094,7 @@ function getPatternData(paint, box, image) {
1089
1094
  translate(data.transform, box.x, box.y);
1090
1095
  }
1091
1096
  }
1092
- if (scaleX && mode !== 'strench') {
1097
+ if (scaleX && mode !== 'stretch') {
1093
1098
  data.scaleX = scaleX;
1094
1099
  data.scaleY = scaleY;
1095
1100
  }
@@ -1193,7 +1198,7 @@ const { get: get$1, scale, copy: copy$1 } = core.MatrixHelper;
1193
1198
  const { ceil, abs: abs$1 } = Math;
1194
1199
  function createPattern(ui, paint, pixelRatio) {
1195
1200
  let { scaleX, scaleY } = core.ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1196
- const id = scaleX + '-' + scaleY;
1201
+ const id = scaleX + '-' + scaleY + '-' + pixelRatio;
1197
1202
  if (paint.patternId !== id && !ui.destroyed) {
1198
1203
  scaleX = abs$1(scaleX);
1199
1204
  scaleY = abs$1(scaleY);
@@ -1287,7 +1292,8 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1287
1292
  const { abs } = Math;
1288
1293
  function checkImage(ui, canvas, paint, allowPaint) {
1289
1294
  const { scaleX, scaleY } = core.ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1290
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY && !draw.Export.running)) {
1295
+ const { pixelRatio } = canvas;
1296
+ if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !draw.Export.running)) {
1291
1297
  return false;
1292
1298
  }
1293
1299
  else {
@@ -1295,8 +1301,8 @@ function checkImage(ui, canvas, paint, allowPaint) {
1295
1301
  if (allowPaint) {
1296
1302
  if (!data.repeat) {
1297
1303
  let { width, height } = data;
1298
- width *= abs(scaleX) * canvas.pixelRatio;
1299
- height *= abs(scaleY) * canvas.pixelRatio;
1304
+ width *= abs(scaleX) * pixelRatio;
1305
+ height *= abs(scaleY) * pixelRatio;
1300
1306
  if (data.scaleX) {
1301
1307
  width *= data.scaleX;
1302
1308
  height *= data.scaleY;
@@ -1322,14 +1328,14 @@ function checkImage(ui, canvas, paint, allowPaint) {
1322
1328
  }
1323
1329
  else {
1324
1330
  if (!paint.style || paint.sync || draw.Export.running) {
1325
- createPattern(ui, paint, canvas.pixelRatio);
1331
+ createPattern(ui, paint, pixelRatio);
1326
1332
  }
1327
1333
  else {
1328
1334
  if (!paint.patternTask) {
1329
1335
  paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1330
1336
  paint.patternTask = null;
1331
1337
  if (canvas.bounds.hit(ui.__nowWorld))
1332
- createPattern(ui, paint, canvas.pixelRatio);
1338
+ createPattern(ui, paint, pixelRatio);
1333
1339
  ui.forceUpdate('surface');
1334
1340
  }), 300);
1335
1341
  }
@@ -1393,14 +1399,16 @@ function linearGradient(paint, box) {
1393
1399
  return data;
1394
1400
  }
1395
1401
  function applyStops(gradient, stops, opacity) {
1396
- let stop;
1397
- for (let i = 0, len = stops.length; i < len; i++) {
1398
- stop = stops[i];
1399
- if (typeof stop === 'string') {
1400
- gradient.addColorStop(i / (len - 1), draw.ColorConvert.string(stop, opacity));
1401
- }
1402
- else {
1403
- gradient.addColorStop(stop.offset, draw.ColorConvert.string(stop.color, opacity));
1402
+ if (stops) {
1403
+ let stop;
1404
+ for (let i = 0, len = stops.length; i < len; i++) {
1405
+ stop = stops[i];
1406
+ if (typeof stop === 'string') {
1407
+ gradient.addColorStop(i / (len - 1), draw.ColorConvert.string(stop, opacity));
1408
+ }
1409
+ else {
1410
+ gradient.addColorStop(stop.offset, draw.ColorConvert.string(stop.color, opacity));
1411
+ }
1404
1412
  }
1405
1413
  }
1406
1414
  }
@@ -2156,10 +2164,15 @@ const TextConvertModule = {
2156
2164
  };
2157
2165
 
2158
2166
  function string(color, opacity) {
2159
- if (typeof color === 'string')
2160
- return color;
2167
+ const doOpacity = typeof opacity === 'number' && opacity !== 1;
2168
+ if (typeof color === 'string') {
2169
+ if (doOpacity && draw.ColorConvert.object)
2170
+ color = draw.ColorConvert.object(color);
2171
+ else
2172
+ return color;
2173
+ }
2161
2174
  let a = color.a === undefined ? 1 : color.a;
2162
- if (opacity)
2175
+ if (doOpacity)
2163
2176
  a *= opacity;
2164
2177
  const rgb = color.r + ',' + color.g + ',' + color.b;
2165
2178
  return a === 1 ? 'rgb(' + rgb + ')' : 'rgba(' + rgb + ',' + a + ')';
@@ -1,4 +1,4 @@
1
- import { LeaferCanvasBase, Platform, canvasPatch, Creator, LeaferImage, defineKey, FileHelper, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, AnimateEvent, ResizeEvent, BoundsHelper, MatrixHelper, MathHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
1
+ import { LeaferCanvasBase, Platform, canvasPatch, Creator, LeaferImage, defineKey, FileHelper, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, ResizeEvent, BoundsHelper, MatrixHelper, MathHelper, AlignHelper, ImageEvent, AroundHelper, PointHelper, Direction4, TwoPointBoundsHelper, TaskProcessor, Matrix } from '@leafer/core';
2
2
  export * from '@leafer/core';
3
3
  export { LeaferImage } from '@leafer/core';
4
4
  import { PaintImage, ColorConvert, PaintGradient, Export, Group, TextConvert, Paint, Effect } from '@leafer-ui/draw';
@@ -229,9 +229,13 @@ function updateBounds(boundsList) {
229
229
  });
230
230
  }
231
231
  function updateChange(updateList) {
232
+ let layout;
232
233
  updateList.list.forEach(leaf => {
233
- if (leaf.__layout.opacityChanged)
234
+ layout = leaf.__layout;
235
+ if (layout.opacityChanged)
234
236
  updateAllWorldOpacity(leaf);
237
+ if (layout.stateStyleChanged)
238
+ setTimeout(() => layout.stateStyleChanged && leaf.updateState());
235
239
  leaf.__updateChange();
236
240
  });
237
241
  }
@@ -597,7 +601,6 @@ class Renderer {
597
601
  Platform.requestRender(() => {
598
602
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - startTime)));
599
603
  if (this.running) {
600
- this.target.emit(AnimateEvent.FRAME);
601
604
  if (this.changed && this.canvas.view)
602
605
  this.render();
603
606
  this.target.emit(RenderEvent.NEXT);
@@ -1035,6 +1038,8 @@ function getPatternData(paint, box, image) {
1035
1038
  let { width, height } = image;
1036
1039
  if (paint.padding)
1037
1040
  box = tempBox.set(box).shrink(paint.padding);
1041
+ if (paint.mode === 'strench')
1042
+ paint.mode = 'stretch';
1038
1043
  const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint;
1039
1044
  const sameBox = box.width === width && box.height === height;
1040
1045
  const data = { mode };
@@ -1063,7 +1068,7 @@ function getPatternData(paint, box, image) {
1063
1068
  if (offset)
1064
1069
  x += offset.x, y += offset.y;
1065
1070
  switch (mode) {
1066
- case 'strench':
1071
+ case 'stretch':
1067
1072
  if (!sameBox)
1068
1073
  width = box.width, height = box.height;
1069
1074
  break;
@@ -1090,7 +1095,7 @@ function getPatternData(paint, box, image) {
1090
1095
  translate(data.transform, box.x, box.y);
1091
1096
  }
1092
1097
  }
1093
- if (scaleX && mode !== 'strench') {
1098
+ if (scaleX && mode !== 'stretch') {
1094
1099
  data.scaleX = scaleX;
1095
1100
  data.scaleY = scaleY;
1096
1101
  }
@@ -1194,7 +1199,7 @@ const { get: get$1, scale, copy: copy$1 } = MatrixHelper;
1194
1199
  const { ceil, abs: abs$1 } = Math;
1195
1200
  function createPattern(ui, paint, pixelRatio) {
1196
1201
  let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1197
- const id = scaleX + '-' + scaleY;
1202
+ const id = scaleX + '-' + scaleY + '-' + pixelRatio;
1198
1203
  if (paint.patternId !== id && !ui.destroyed) {
1199
1204
  scaleX = abs$1(scaleX);
1200
1205
  scaleY = abs$1(scaleY);
@@ -1288,7 +1293,8 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1288
1293
  const { abs } = Math;
1289
1294
  function checkImage(ui, canvas, paint, allowPaint) {
1290
1295
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1291
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY && !Export.running)) {
1296
+ const { pixelRatio } = canvas;
1297
+ if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1292
1298
  return false;
1293
1299
  }
1294
1300
  else {
@@ -1296,8 +1302,8 @@ function checkImage(ui, canvas, paint, allowPaint) {
1296
1302
  if (allowPaint) {
1297
1303
  if (!data.repeat) {
1298
1304
  let { width, height } = data;
1299
- width *= abs(scaleX) * canvas.pixelRatio;
1300
- height *= abs(scaleY) * canvas.pixelRatio;
1305
+ width *= abs(scaleX) * pixelRatio;
1306
+ height *= abs(scaleY) * pixelRatio;
1301
1307
  if (data.scaleX) {
1302
1308
  width *= data.scaleX;
1303
1309
  height *= data.scaleY;
@@ -1323,14 +1329,14 @@ function checkImage(ui, canvas, paint, allowPaint) {
1323
1329
  }
1324
1330
  else {
1325
1331
  if (!paint.style || paint.sync || Export.running) {
1326
- createPattern(ui, paint, canvas.pixelRatio);
1332
+ createPattern(ui, paint, pixelRatio);
1327
1333
  }
1328
1334
  else {
1329
1335
  if (!paint.patternTask) {
1330
1336
  paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1331
1337
  paint.patternTask = null;
1332
1338
  if (canvas.bounds.hit(ui.__nowWorld))
1333
- createPattern(ui, paint, canvas.pixelRatio);
1339
+ createPattern(ui, paint, pixelRatio);
1334
1340
  ui.forceUpdate('surface');
1335
1341
  }), 300);
1336
1342
  }
@@ -1394,14 +1400,16 @@ function linearGradient(paint, box) {
1394
1400
  return data;
1395
1401
  }
1396
1402
  function applyStops(gradient, stops, opacity) {
1397
- let stop;
1398
- for (let i = 0, len = stops.length; i < len; i++) {
1399
- stop = stops[i];
1400
- if (typeof stop === 'string') {
1401
- gradient.addColorStop(i / (len - 1), ColorConvert.string(stop, opacity));
1402
- }
1403
- else {
1404
- gradient.addColorStop(stop.offset, ColorConvert.string(stop.color, opacity));
1403
+ if (stops) {
1404
+ let stop;
1405
+ for (let i = 0, len = stops.length; i < len; i++) {
1406
+ stop = stops[i];
1407
+ if (typeof stop === 'string') {
1408
+ gradient.addColorStop(i / (len - 1), ColorConvert.string(stop, opacity));
1409
+ }
1410
+ else {
1411
+ gradient.addColorStop(stop.offset, ColorConvert.string(stop.color, opacity));
1412
+ }
1405
1413
  }
1406
1414
  }
1407
1415
  }
@@ -2157,10 +2165,15 @@ const TextConvertModule = {
2157
2165
  };
2158
2166
 
2159
2167
  function string(color, opacity) {
2160
- if (typeof color === 'string')
2161
- return color;
2168
+ const doOpacity = typeof opacity === 'number' && opacity !== 1;
2169
+ if (typeof color === 'string') {
2170
+ if (doOpacity && ColorConvert.object)
2171
+ color = ColorConvert.object(color);
2172
+ else
2173
+ return color;
2174
+ }
2162
2175
  let a = color.a === undefined ? 1 : color.a;
2163
- if (opacity)
2176
+ if (doOpacity)
2164
2177
  a *= opacity;
2165
2178
  const rgb = color.r + ',' + color.g + ',' + color.b;
2166
2179
  return a === 1 ? 'rgb(' + rgb + ')' : 'rgba(' + rgb + ',' + a + ')';
@@ -1 +1 @@
1
- import{LeaferCanvasBase as t,Platform as e,canvasPatch as n,Creator as i,LeaferImage as s,defineKey as o,FileHelper as a,LeafList as r,DataHelper as d,RenderEvent as l,ChildEvent as c,WatchEvent as h,PropertyEvent as u,LeafHelper as f,BranchHelper as p,Bounds as _,LeafBoundsHelper as g,Debug as w,LeafLevelList as y,LayoutEvent as m,Run as v,ImageManager as x,AnimateEvent as b,ResizeEvent as B,BoundsHelper as R,MatrixHelper as k,MathHelper as E,AlignHelper as S,ImageEvent as L,AroundHelper as O,PointHelper as W,Direction4 as A,TwoPointBoundsHelper as T,TaskProcessor as M,Matrix as C}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as D,ColorConvert as I,PaintGradient as P,Export as F,Group as Y,TextConvert as X,Paint as G,Effect as U}from"@leafer-ui/draw";export*from"@leafer-ui/draw";class N extends t{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:n}=this;this.view.width=Math.ceil(t*n),this.view.height=Math.ceil(e*n),this.clientBounds=this.bounds}}n(OffscreenCanvasRenderingContext2D.prototype),n(Path2D.prototype);const{mineType:j}=a;function V(t,n){e.origin={createCanvas:(t,e)=>new OffscreenCanvas(t,e),canvasToDataURL:(t,e,n)=>new Promise(((i,s)=>{t.convertToBlob({type:j(e),quality:n}).then((t=>{var e=new FileReader;e.onload=t=>i(t.target.result),e.onerror=t=>s(t),e.readAsDataURL(t)})).catch((t=>{s(t)}))})),canvasToBolb:(t,e,n)=>t.convertToBlob({type:j(e),quality:n}),canvasSaveAs:(t,e,n)=>new Promise((t=>t())),download(t,e){},loadImage:t=>new Promise(((n,i)=>{let s=new XMLHttpRequest;s.open("GET",e.image.getRealURL(t),!0),s.responseType="blob",s.onload=()=>{createImageBitmap(s.response).then((t=>{n(t)})).catch((t=>{i(t)}))},s.onerror=t=>i(t),s.send()}))},e.canvas=i.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient}Object.assign(i,{canvas:(t,e)=>new N(t,e),image:t=>new s(t)}),e.name="web",e.isWorker=!0,e.requestRender=function(t){requestAnimationFrame(t)},o(e,"devicePixelRatio",{get:()=>1});const{userAgent:q}=navigator;q.indexOf("Firefox")>-1?(e.conicGradientRotate90=!0,e.intWheelDeltaY=!0):q.indexOf("Safari")>-1&&-1===q.indexOf("Chrome")&&(e.fullImageShadow=!0),q.indexOf("Windows")>-1?(e.os="Windows",e.intWheelDeltaY=!0):q.indexOf("Mac")>-1?e.os="Mac":q.indexOf("Linux")>-1&&(e.os="Linux");class z{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new r;return this.__updatedList.list.forEach((e=>{e.leafer&&t.add(e)})),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new r,this.target=t,e&&(this.config=d.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(l.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,n=e.length;t<n;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new h(h.DATA,{updatedList:this.updatedList})),this.__updatedList=new r,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.CHANGE,this.__onAttrChange,this),t.on_([c.ADD,c.REMOVE],this.__onChildEvent,this),t.on_(h.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:H,updateBounds:Q,updateAllWorldOpacity:J}=f,{pushAllChildBranch:Z,pushAllParent:$}=p;const{worldBounds:K}=g,tt={x:0,y:0,width:1e5,height:1e5};class et{constructor(t){this.updatedBounds=new _,this.beforeBounds=new _,this.afterBounds=new _,t instanceof Array&&(t=new r(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,K)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(tt):this.afterBounds.setListWithFn(t,K),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:nt,updateAllChange:it}=f,st=w.get("Layouter");class ot{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new y,this.target=t,e&&(this.config=d.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(m.START),this.layoutOnce(),t.emitEvent(new m(m.END,this.layoutedBlocks,this.times))}catch(t){st.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?st.warn("layouting"):this.times>3?st.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(h.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=v.start("PartLayout"),{target:n,__updatedList:i}=this,{BEFORE:s,LAYOUT:o,AFTER:a}=m,r=this.getBlocks(i);r.forEach((t=>t.setBefore())),n.emitEvent(new m(s,r,this.times)),this.extraBlock=null,i.sort(),function(t,e){let n;t.list.forEach((t=>{n=t.__layout,e.without(t)&&!n.proxyZoom&&(n.matrixChanged?(H(t,!0),e.add(t),t.isBranch&&Z(t,e),$(t,e)):n.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),$(t,e)))}))}(i,this.__levelList),function(t){let e,n,i;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(n=e[t],n.isBranch&&n.__tempNumber){i=n.children;for(let t=0,e=i.length;t<e;t++)i[t].isBranch||Q(i[t])}Q(n)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&J(t),t.__updateChange()}))}(i),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),n.emitEvent(new m(o,r,this.times)),n.emitEvent(new m(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,v.end(e)}fullLayout(){const t=v.start("FullLayout"),{target:e}=this,{BEFORE:n,LAYOUT:i,AFTER:s}=m,o=this.getBlocks(new r(e));e.emitEvent(new m(n,o,this.times)),ot.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new m(i,o,this.times)),e.emitEvent(new m(s,o,this.times)),this.addBlocks(o),v.end(t)}static fullLayout(t){nt(t,!0),t.isBranch?p.updateBounds(t):f.updateBounds(t),it(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:n}=this.extraBlock||(this.extraBlock=new et([]));e.length?n.add(t.__world):n.set(t.__world),e.add(t)}}createBlock(t){return new et(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_(h.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const at=w.get("Renderer");class rt{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,n){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,n&&(this.config=d.default(n,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 _,at.log(e.innerName,"---\x3e");try{this.emitRender(l.START),this.renderOnce(t),this.emitRender(l.END,this.totalBounds),x.clearRecycled()}catch(t){this.rendering=!1,at.error(t)}at.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return at.warn("rendering");if(this.times>3)return at.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new _,this.renderOptions={},t)this.emitRender(l.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(l.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(l.RENDER,this.renderBounds,this.renderOptions),this.emitRender(l.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 at.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=v.start("PartRender"),{canvas:n}=this,i=t.getIntersect(n.bounds),s=t.includes(this.target.__world),o=new _(i);n.save(),s&&!w.showRepaint?n.clear():(i.spread(10+1/this.canvas.pixelRatio).ceil(),n.clearWorld(i,!0),n.clipWorld(i,!0)),this.__render(i,s,o),n.restore(),v.end(e)}fullRender(){const t=v.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),v.end(t)}__render(t,e,n){const i=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),w.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,i),this.renderBounds=n=n||t,this.renderOptions=i,this.totalBounds.isEmpty()?this.totalBounds=n:this.totalBounds.add(n),w.showHitView&&this.renderHitView(i),w.showBoundsView&&this.renderBoundsView(i),this.canvas.updateRender(n)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new _;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.target.emit(b.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(l.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:n}=t.old;if(!new _(0,0,e,n).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new _(0,0,1,1)),this.changed=!0}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||at.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,n){this.target.emitEvent(new l(t,this.times,e,n))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(l.REQUEST,this.update,this),t.on_(m.END,this.__onLayoutEnd,this),t.on_(l.AGAIN,this.renderAgain,this),t.on_(B.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}function dt(t,e){let n;const{rows:i,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=i.length;t<a;t++)n=i[t],n.text?e.fillText(n.text,n.x,n.y):n.data&&n.data.forEach((t=>{e.fillText(t.char,t.x,n.y)})),s&&e.fillRect(n.x,n.y+s,n.width,o)}function lt(t,e,n){const{strokeAlign:i}=e.__,s="string"!=typeof t;switch(i){case"center":n.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?ut(t,!0,e,n):ht(e,n);break;case"inside":ct("inside",t,s,e,n);break;case"outside":ct("outside",t,s,e,n)}}function ct(t,e,n,i,s){const{__strokeWidth:o,__font:a}=i.__,r=s.getSameCanvas(!0,!0);r.setStroke(n?void 0:e,2*o,i.__),r.font=a,n?ut(e,!0,i,r):ht(i,r),r.blendMode="outside"===t?"destination-out":"destination-in",dt(i,r),r.blendMode="normal",i.__worldFlipped?s.copyWorldByReset(r,i.__nowWorld):s.copyWorldToInner(r,i.__nowWorld,i.__layout.renderBounds),r.recycle(i.__nowWorld)}function ht(t,e){let n;const{rows:i,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=i.length;t<a;t++)n=i[t],n.text?e.strokeText(n.text,n.x,n.y):n.data&&n.data.forEach((t=>{e.strokeText(t.char,t.x,n.y)})),s&&e.strokeRect(n.x,n.y+s,n.width,o)}function ut(t,e,n,i){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&D.checkImage(n,i,s,!1)||s.style&&(i.strokeStyle=s.style,s.blendMode?(i.saveBlendMode(s.blendMode),e?ht(n,i):i.stroke(),i.restoreBlendMode()):e?ht(n,i):i.stroke())}Object.assign(i,{watcher:(t,e)=>new z(t,e),layouter:(t,e)=>new ot(t,e),renderer:(t,e,n)=>new rt(t,e,n),selector:(t,e)=>{},interaction:(t,e,n,i)=>{}}),e.layout=ot.fullLayout;const{getSpread:ft,getOuterOf:pt,getByMove:_t,getIntersectData:gt}=R;let wt;function yt(t,e,n){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:i}=n.__layout;switch(e.type){case"solid":let{type:s,blendMode:o,color:a,opacity:r}=e;return{type:s,blendMode:o,style:I.string(a,r)};case"image":return D.image(n,t,e,i,!wt||!wt[e.url]);case"linear":return P.linearGradient(e,i);case"radial":return P.radialGradient(e,i);case"angular":return P.conicGradient(e,i);default:return void 0!==e.r?{type:"solid",style:I.string(e)}:void 0}}const mt={compute:function(t,e){const n=e.__,i=[];let s,o=n.__input[t];o instanceof Array||(o=[o]),wt=D.recycleImage(t,n);for(let n,s=0,a=o.length;s<a;s++)n=yt(t,o[s],e),n&&i.push(n);n["_"+t]=i.length?i:void 0,i.length&&i[0].image&&(s=i[0].image.hasOpacityPixel),"fill"===t?n.__pixelFill=s:n.__pixelStroke=s},fill:function(t,e,n){n.fillStyle=t,e.__.__font?dt(e,n):e.__.windingRule?n.fill(e.__.windingRule):n.fill()},fills:function(t,e,n){let i;const{windingRule:s,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)i=t[a],i.image&&D.checkImage(e,n,i,!o)||i.style&&(n.fillStyle=i.style,i.transform?(n.save(),n.transform(i.transform),i.blendMode&&(n.blendMode=i.blendMode),o?dt(e,n):s?n.fill(s):n.fill(),n.restore()):i.blendMode?(n.saveBlendMode(i.blendMode),o?dt(e,n):s?n.fill(s):n.fill(),n.restoreBlendMode()):o?dt(e,n):s?n.fill(s):n.fill())},fillText:dt,stroke:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)lt(t,e,n);else switch(o){case"center":n.setStroke(t,s,i),n.stroke();break;case"inside":n.save(),n.setStroke(t,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),n.stroke(),n.restore();break;case"outside":const o=n.getSameCanvas(!0,!0);o.setStroke(t,2*s,i),e.__drawRenderPath(o),o.stroke(),i.windingRule?o.clip(i.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?n.copyWorldByReset(o,e.__nowWorld):n.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)lt(t,e,n);else switch(o){case"center":n.setStroke(void 0,s,i),ut(t,!1,e,n);break;case"inside":n.save(),n.setStroke(void 0,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),ut(t,!1,e,n),n.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=n.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*s,i),ut(t,!1,e,a),i.windingRule?a.clip(i.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?n.copyWorldByReset(a,e.__nowWorld):n.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:lt,drawTextStroke:ht,shape:function(t,e,n){const i=e.getSameCanvas(),s=t.__nowWorld;let o,a,r,d,{scaleX:l,scaleY:c}=s;if(l<0&&(l=-l),c<0&&(c=-c),e.bounds.includes(s))d=i,o=r=s;else{const{renderShapeSpread:i}=t.__layout,h=gt(i?ft(e.bounds,l===c?i*l:[i*c,i*l]):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,n),l*=u,c*=f),r=pt(s,a),o=_t(r,-a.e,-a.f),n.matrix){const{matrix:t}=n;a.multiply(t),u*=t.scaleX,f*=t.scaleY}n=Object.assign(Object.assign({},n),{matrix:a.withScale(u,f)})}return t.__renderShape(i,n),{canvas:i,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:c}}};let vt={};const{get:xt,rotateOfOuter:bt,translate:Bt,scaleOfOuter:Rt,scale:kt,rotate:Et}=k;function St(t,e,n,i,s,o,a){const r=xt();Bt(r,e.x+n,e.y+i),kt(r,s,o),a&&bt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Lt(t,e,n,i,s,o,a){const r=xt();Bt(r,e.x+n,e.y+i),s&&kt(r,s,o),a&&Et(r,a),t.transform=r}function Ot(t,e,n,i,s,o,a,r,d,l){const c=xt();if(d)if("center"===l)bt(c,{x:n/2,y:i/2},d);else switch(Et(c,d),d){case 90:Bt(c,i,0);break;case 180:Bt(c,n,i);break;case 270:Bt(c,0,n)}vt.x=e.x+s,vt.y=e.y+o,Bt(c,vt.x,vt.y),a&&Rt(c,vt,a,r),t.transform=c}const{get:Wt,translate:At}=k,Tt=new _,Mt={},Ct={};function Dt(t,e,n,i){const{blendMode:s,sync:o}=n;s&&(t.blendMode=s),o&&(t.sync=o),t.data=It(n,i,e)}function It(t,e,n){let{width:i,height:s}=n;t.padding&&(e=Tt.set(e).shrink(t.padding));const{opacity:o,mode:a,align:r,offset:d,scale:l,size:c,rotation:h,repeat:u}=t,f=e.width===i&&e.height===s,p={mode:a},_="center"!==r&&(h||0)%180==90,g=_?s:i,w=_?i:s;let y,m,v=0,x=0;if(a&&"cover"!==a&&"fit"!==a)(l||c)&&(E.getScaleData(l,c,n,Ct),y=Ct.scaleX,m=Ct.scaleY);else if(!f||h){const t=e.width/g,n=e.height/w;y=m="fit"===a?Math.min(t,n):Math.max(t,n),v+=(e.width-i*y)/2,x+=(e.height-s*m)/2}if(r){const t={x:v,y:x,width:g,height:w};y&&(t.width*=y,t.height*=m),S.toPoint(r,t,e,Mt,!0),v+=Mt.x,x+=Mt.y}switch(d&&(v+=d.x,x+=d.y),a){case"strench":f||(i=e.width,s=e.height);break;case"normal":case"clip":(v||x||y||h)&&Lt(p,e,v,x,y,m,h);break;case"repeat":(!f||y||h)&&Ot(p,e,i,s,v,x,y,m,h,r),u||(p.repeat="repeat");break;default:y&&St(p,e,v,x,y,m,h)}return p.transform||(e.x||e.y)&&(p.transform=Wt(),At(p.transform,e.x,e.y)),y&&"strench"!==a&&(p.scaleX=y,p.scaleY=m),p.width=i,p.height=s,o&&(p.opacity=o),u&&(p.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),p}let Pt,Ft=new _;const{isSame:Yt}=R;function Xt(t,e,n,i,s,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=i.width/e.pixelRatio,e.__naturalHeight=i.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return s.data||Dt(s,i,n,o),!0}function Gt(t,e){jt(t,L.LOAD,e)}function Ut(t,e){jt(t,L.LOADED,e)}function Nt(t,e,n){e.error=n,t.forceUpdate("surface"),jt(t,L.ERROR,e)}function jt(t,e,n){t.hasEvent(e)&&t.emitEvent(new L(e,n))}function Vt(t,e){const{leafer:n}=t;n&&n.viewReady&&(n.renderer.ignore=e)}const{get:qt,scale:zt,copy:Ht}=k,{ceil:Qt,abs:Jt}=Math;function Zt(t,n,i){let{scaleX:s,scaleY:o}=x.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o;if(n.patternId===a||t.destroyed)return!1;{s=Jt(s),o=Jt(o);const{image:t,data:r}=n;let d,l,{width:c,height:h,scaleX:u,scaleY:f,opacity:p,transform:_,repeat:g}=r;u&&(l=qt(),Ht(l,_),zt(l,1/u,1/f),s*=u,o*=f),s*=i,o*=i,c*=s,h*=o;const w=c*h;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&&(s/=d,o/=d,c/=d,h/=d),u&&(s/=u,o/=f),(_||1!==s||1!==o)&&(l||(l=qt(),_&&Ht(l,_)),zt(l,1/s,1/o));const m=t.getCanvas(Qt(c)||1,Qt(h)||1,p),v=t.getPattern(m,g||e.origin.noRepeat||"no-repeat",l,n);return n.style=v,n.patternId=a,!0}}function $t(t,e,n,i){return new(n||(n=Promise))((function(s,o){function a(t){try{d(i.next(t))}catch(t){o(t)}}function r(t){try{d(i.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,r)}d((i=i.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:Kt}=Math;const te={image:function(t,e,n,i,s){let o,a;const r=x.get(n);return Pt&&n===Pt.paint&&Yt(i,Pt.boxBounds)?o=Pt.leafPaint:(o={type:n.type,image:r},Pt=r.use>1?{leafPaint:o,paint:n,boxBounds:Ft.set(i)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:n}),r.ready?(Xt(t,e,n,r,o,i),s&&(Gt(t,a),Ut(t,a))):r.error?s&&Nt(t,a,r.error):(Vt(t,!0),s&&Gt(t,a),o.loadId=r.load((()=>{Vt(t,!1),t.destroyed||(Xt(t,e,n,r,o,i)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Ut(t,a)),o.loadId=null}),(e=>{Vt(t,!1),Nt(t,a,e),o.loadId=null}))),o},checkImage:function(t,n,i,s){const{scaleX:o,scaleY:a}=x.patternLocked?t.__world:t.__nowWorld;if(!i.data||i.patternId===o+"-"+a&&!F.running)return!1;{const{data:r}=i;if(s)if(r.repeat)s=!1;else{let{width:t,height:i}=r;t*=Kt(o)*n.pixelRatio,i*=Kt(a)*n.pixelRatio,r.scaleX&&(t*=r.scaleX,i*=r.scaleY),s=t*i>e.image.maxCacheSize||F.running}return s?(n.save(),n.clip(),i.blendMode&&(n.blendMode=i.blendMode),r.opacity&&(n.opacity*=r.opacity),r.transform&&n.transform(r.transform),n.drawImage(i.image.view,0,0,r.width,r.height),n.restore(),!0):(!i.style||i.sync||F.running?Zt(t,i,n.pixelRatio):i.patternTask||(i.patternTask=x.patternTasker.add((()=>$t(this,void 0,void 0,(function*(){i.patternTask=null,n.bounds.hit(t.__nowWorld)&&Zt(t,i,n.pixelRatio),t.forceUpdate("surface")}))),300)),!1)}},createPattern:Zt,recycleImage:function(t,e){const n=e["_"+t];if(n instanceof Array){let i,s,o,a;for(let r=0,d=n.length;r<d;r++)i=n[r].image,a=i&&i.url,a&&(s||(s={}),s[a]=!0,x.recycle(i),i.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),i.unload(n[r].loadId,!o.some((t=>t.url===a)))));return s}return null},createData:Dt,getPatternData:It,fillOrFitMode:St,clipMode:Lt,repeatMode:Ot},{toPoint:ee}=O,ne={},ie={};function se(t,e,n){let i;for(let s=0,o=e.length;s<o;s++)i=e[s],"string"==typeof i?t.addColorStop(s/(o-1),I.string(i,n)):t.addColorStop(i.offset,I.string(i.color,n))}const{getAngle:oe,getDistance:ae}=W,{get:re,rotateOfOuter:de,scaleOfOuter:le}=k,{toPoint:ce}=O,he={},ue={};function fe(t,e,n,i,s){let o;const{width:a,height:r}=t;if(a!==r||i){const t=oe(e,n);o=re(),s?(le(o,e,a/r*(i||1),1),de(o,e,t+90)):(le(o,e,1,a/r*(i||1)),de(o,e,t))}return o}const{getDistance:pe}=W,{toPoint:_e}=O,ge={},we={};const ye={linearGradient:function(t,n){let{from:i,to:s,type:o,blendMode:a,opacity:r}=t;ee(i||"top",n,ne),ee(s||"bottom",n,ie);const d=e.canvas.createLinearGradient(ne.x,ne.y,ie.x,ie.y);se(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,n){let{from:i,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;ce(i||"center",n,he),ce(s||"bottom",n,ue);const l=e.canvas.createRadialGradient(he.x,he.y,0,he.x,he.y,ae(he,ue));se(l,t.stops,a);const c={type:o,style:l},h=fe(n,he,ue,d,!0);return h&&(c.transform=h),r&&(c.blendMode=r),c},conicGradient:function(t,n){let{from:i,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;_e(i||"center",n,ge),_e(s||"bottom",n,we);const l=e.conicGradientSupport?e.canvas.createConicGradient(0,ge.x,ge.y):e.canvas.createRadialGradient(ge.x,ge.y,0,ge.x,ge.y,pe(ge,we));se(l,t.stops,a);const c={type:o,style:l},h=fe(n,ge,we,d||1,e.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:fe},{copy:me,toOffsetOutBounds:ve}=R,xe={},be={};function Be(t,n,i,s){const{bounds:o,shapeBounds:a}=s;if(e.fullImageShadow){if(me(xe,t.bounds),xe.x+=n.x-a.x,xe.y+=n.y-a.y,i){const{matrix:t}=s;xe.x-=(o.x+(t?t.e:0)+o.width/2)*(i-1),xe.y-=(o.y+(t?t.f:0)+o.height/2)*(i-1),xe.width*=i,xe.height*=i}t.copyWorld(s.canvas,t.bounds,xe)}else i&&(me(xe,n),xe.x-=n.width/2*(i-1),xe.y-=n.height/2*(i-1),xe.width*=i,xe.height*=i),t.copyWorld(s.canvas,a,i?xe:n)}const{toOffsetOutBounds:Re}=R,ke={};const Ee={shadow:function(t,e,n){let i,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;ve(l,be),r.forEach(((r,_)=>{f.setWorldShadow(be.offsetX+r.x*h,be.offsetY+r.y*u,r.blur*h,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Be(f,be,s,n),i=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,o,"copy"),i=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(n.canvas,c,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,i,o,r.blendMode):e.copyWorldToInner(f,i,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(i,!0)})),f.recycle(i)},innerShadow:function(t,e,n){let i,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;Re(l,ke),r.forEach(((r,_)=>{f.save(),f.setWorldShadow(ke.offsetX+r.x*h,ke.offsetY+r.y*u,r.blur*h),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Be(f,ke,s,n),f.restore(),d?(f.copyWorld(f,l,o,"copy"),f.copyWorld(d,o,o,"source-out"),i=o):(f.copyWorld(n.canvas,c,l,"source-out"),i=l),f.fillWorld(i,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,i,o,r.blendMode):e.copyWorldToInner(f,i,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(i,!0)})),f.recycle(i)},blur:function(t,e,n){const{blur:i}=t.__;n.setWorldBlur(i*t.__nowWorld.a),n.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),n.filter="none"},backgroundBlur:function(t,e,n){}},{excludeRenderBounds:Se}=g;function Le(t,e,n,i,s,o){switch(e){case"alpha":!function(t,e,n,i){const s=t.__nowWorld;n.resetTransform(),n.opacity=1,n.useMask(i,s),i.recycle(s),We(t,e,n,1)}(t,n,i,s);break;case"opacity-path":We(t,n,i,o);break;case"path":n.restore()}}function Oe(t){return t.getSameCanvas(!1,!0)}function We(t,e,n,i){const s=t.__nowWorld;e.resetTransform(),e.opacity=i,e.copyWorld(n,s),n.recycle(s)}Y.prototype.__renderMask=function(t,e){let n,i,s,o,a;const{children:r}=this;for(let d=0,l=r.length;d<l;d++)n=r[d],n.__.mask&&(a&&(Le(this,a,t,s,i,o),i=s=null),"path"===n.__.mask?(n.opacity<1?(a="opacity-path",o=n.opacity,s||(s=Oe(t))):(a="path",t.save()),n.__clip(s||t,e)):(a="alpha",i||(i=Oe(t)),s||(s=Oe(t)),n.__render(i,e)),"clipping"!==n.__.mask)||Se(n,e)||n.__render(s||t,e);Le(this,a,t,s,i,o)};const Ae=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Te=Ae+"_#~&*+\\=|≮≯≈≠=…",Me=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map((([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`)).join("|"));function Ce(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const De=Ce("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ie=Ce("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Pe=Ce(Ae),Fe=Ce(Te),Ye=Ce("- —/~|┆·");var Xe;!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"}(Xe||(Xe={}));const{Letter:Ge,Single:Ue,Before:Ne,After:je,Symbol:Ve,Break:qe}=Xe;function ze(t){return De[t]?Ge:Ye[t]?qe:Ie[t]?Ne:Pe[t]?je:Fe[t]?Ve:Me.test(t)?Ue:Ge}const He={trimRight(t){const{words:e}=t;let n,i=0,s=e.length;for(let o=s-1;o>-1&&(n=e[o].data[0]," "===n.char);o--)i++,t.width-=n.width;i&&e.splice(s-i,i)}};function Qe(t,e,n){switch(e){case"title":return n?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:Je}=He,{Letter:Ze,Single:$e,Before:Ke,After:tn,Symbol:en,Break:nn}=Xe;let sn,on,an,rn,dn,ln,cn,hn,un,fn,pn,_n,gn,wn,yn,mn,vn=[];function xn(t,e){un&&!hn&&(hn=un),sn.data.push({char:t,width:e}),an+=e}function bn(){rn+=an,sn.width=an,on.words.push(sn),sn={data:[]},an=0}function Bn(){wn&&(yn.paraNumber++,on.paraStart=!0,wn=!1),un&&(on.startCharSize=hn,on.endCharSize=un,hn=0),on.width=rn,mn.width&&Je(on),vn.push(on),on={words:[]},rn=0}const Rn=0,kn=1,En=2;const{top:Sn,right:Ln,bottom:On,left:Wn}=A;function An(t,e,n){const{bounds:i,rows:s}=t;i[e]+=n;for(let t=0;t<s.length;t++)s[t][e]+=n}const Tn={getDrawData:function(t,n){"string"!=typeof t&&(t=String(t));let i=0,s=0,o=n.__getInput("width")||0,a=n.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=n;l&&(o&&(i=l[Wn],o-=l[Ln]+l[Wn]),a&&(s=l[Sn],a-=l[Sn]+l[On]));const c={bounds:{x:i,y:s,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,n,i){yn=t,vn=t.rows,mn=t.bounds;const{__letterSpacing:s,paraIndent:o,textCase:a}=i,{canvas:r}=e,{width:d,height:l}=mn;if(d||l||s||"none"!==a){const t="none"!==i.textWrap,e="break"===i.textWrap;wn=!0,pn=null,hn=cn=un=an=rn=0,sn={data:[]},on={words:[]};for(let i=0,l=n.length;i<l;i++)ln=n[i],"\n"===ln?(an&&bn(),on.paraEnd=!0,Bn(),wn=!0):(fn=ze(ln),fn===Ze&&"none"!==a&&(ln=Qe(ln,a,!an)),cn=r.measureText(ln).width,s&&(s<0&&(un=cn),cn+=s),_n=fn===$e&&(pn===$e||pn===Ze)||pn===$e&&fn!==tn,gn=!(fn!==Ke&&fn!==$e||pn!==en&&pn!==tn),dn=wn&&o?d-o:d,t&&d&&rn+an+cn>dn&&(e?(an&&bn(),rn&&Bn()):(gn||(gn=fn===Ze&&pn==tn),_n||gn||fn===nn||fn===Ke||fn===$e||an+cn>dn?(an&&bn(),rn&&Bn()):rn&&Bn()))," "===ln&&!0!==wn&&rn+an===0||(fn===nn?(" "===ln&&an&&bn(),xn(ln,cn),bn()):_n||gn?(an&&bn(),xn(ln,cn)):xn(ln,cn)),pn=fn);an&&bn(),rn&&Bn(),vn.length>0&&(vn[vn.length-1].paraEnd=!0)}else n.split("\n").forEach((t=>{yn.paraNumber++,vn.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(c,t,n),l&&function(t,e,n,i,s){if(!i)switch(n.textAlign){case"left":An(e,"x",t[Wn]);break;case"right":An(e,"x",-t[Ln])}if(!s)switch(n.verticalAlign){case"top":An(e,"y",t[Sn]);break;case"bottom":An(e,"y",-t[On])}}(l,c,n,o,a),function(t,e){const{rows:n,bounds:i}=t,{__lineHeight:s,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:c}=e;let h,u,f,{x:p,y:_,width:g,height:w}=i,y=s*n.length+(c?c*(t.paraNumber-1):0),m=o;if(r&&y>w)y=Math.max(w,s),t.overflow=n.length;else switch(l){case"middle":_+=(w-y)/2;break;case"bottom":_+=w-y}m+=_;for(let o=0,l=n.length;o<l;o++){if(h=n[o],h.x=p,h.width<g||h.width>g&&!r)switch(d){case"center":h.x+=(g-h.width)/2;break;case"right":h.x+=g-h.width}h.paraStart&&c&&o>0&&(m+=c),h.y=m,m+=s,t.overflow>o&&m>y&&(h.isOverflow=!0,t.overflow=o+1),u=h.x,f=h.width,a<0&&(h.width<0?(f=-h.width+e.fontSize+a,u-=f,f+=e.fontSize):f-=a),u<i.x&&(i.x=u),f>i.width&&(i.width=f),r&&g&&g<f&&(h.isOverflow=!0,t.overflow||(t.overflow=n.length))}i.y=_,i.height=y}(c,n),function(t,e,n,i){const{rows:s}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,l,c,h,u;s.forEach((t=>{t.words&&(c=a&&t.paraStart?a:0,l=n&&"justify"===o&&t.words.length>1?(n-t.width-c)/(t.words.length-1):0,h=r||t.isOverflow?Rn:l>.01?kn:En,t.isOverflow&&!r&&(t.textMode=!0),h===En?(t.x+=c,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=c,d=t.x,t.data=[],t.words.forEach((e=>{h===kn?(u={char:"",x:d},d=function(t,e,n){return t.forEach((t=>{n.char+=t.char,e+=t.width})),e}(e.data,d,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,n,i){return t.forEach((t=>{(i||" "!==t.char)&&(t.x=e,n.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(c,n,o),c.overflow&&function(t,n,i,s){if(!s)return;const{rows:o,overflow:a}=t;let{textOverflow:r}=n;if(o.splice(a),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const l=r?e.canvas.measureText(r).width:0,c=i+s-l;("none"===n.textWrap?o:[o[a-1]]).forEach((e=>{if(e.isOverflow&&e.data){let n=e.data.length-1;for(let i=n;i>-1&&(t=e.data[i],d=t.x+t.width,!(i===n&&d<c));i--){if(d<c&&" "!==t.char){e.data.splice(i+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:r,x:d}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(c,n,i,o),"none"!==r&&function(t,e){const{fontSize:n}=e;switch(t.decorationHeight=n/11,e.textDecoration){case"under":t.decorationY=.15*n;break;case"delete":t.decorationY=.35*-n}}(c,n),c}};const Mn={string:function(t,e){if("string"==typeof t)return t;let n=void 0===t.a?1:t.a;e&&(n*=e);const i=t.r+","+t.g+","+t.b;return 1===n?"rgb("+i+")":"rgba("+i+","+n+")"}},{setPoint:Cn,addPoint:Dn,toBounds:In}=T;const Pn={export(t,n,s){this.running=!0;const o=a.fileType(n),r=n.includes(".");return s=a.getExportOptions(s),function(t){Fn||(Fn=new M);return new Promise((e=>{Fn.add((()=>$t(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((d=>new Promise((l=>{const c=t=>{d(t),l(),this.running=!1},{toURL:h}=e,{download:u}=e.origin;if("json"===o)return r&&u(h(JSON.stringify(t.toJSON(s.json)),"text"),n),c({data:!!r||t.toJSON(s.json)});if("svg"===o)return r&&u(h(t.toSVG(),"svg"),n),c({data:!!r||t.toSVG()});const{leafer:f}=t;f?(Yn(t),f.waitViewCompleted((()=>$t(this,void 0,void 0,(function*(){let e,o,r=1,d=1;const{worldTransform:l,isLeafer:h,isFrame:u}=t,{slice:p,trim:g,onCanvas:w}=s,y=void 0===s.smooth?f.config.smooth:s.smooth,m=s.contextSettings||f.config.contextSettings,v=s.screenshot||t.isApp,x=h&&v&&void 0===s.fill?t.fill:s.fill,b=a.isOpaqueImage(n)||x,B=new C;if(v)e=!0===v?h?f.canvas.bounds:t.worldRenderBounds:v;else{let n=s.relative||(h?"inner":"local");switch(r=l.scaleX,d=l.scaleY,n){case"inner":B.set(l);break;case"local":B.set(l).divide(t.localTransform),r/=t.scaleX,d/=t.scaleY;break;case"world":r=1,d=1;break;case"page":n=t.leafer;default:B.set(l).divide(t.getTransform(n));const e=n.worldTransform;r/=r/e.scaleX,d/=d/e.scaleY}e=t.getBounds("render",n)}const R={scaleX:1,scaleY:1};E.getScaleData(s.scale,s.size,e,R);let k=s.pixelRatio||1;t.isApp&&(R.scaleX*=k,R.scaleY*=k,k=t.app.pixelRatio);const{x:S,y:L,width:O,height:W}=new _(e).scale(R.scaleX,R.scaleY),A={matrix:B.scale(1/R.scaleX,1/R.scaleY).invert().translate(-S,-L).withScale(1/r*R.scaleX,1/d*R.scaleY)};let T,M=i.canvas({width:Math.round(O),height:Math.round(W),pixelRatio:k,smooth:y,contextSettings:m});if(p&&(T=t,T.__worldOpacity=0,t=f,A.bounds=M.bounds),M.save(),u&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(M,A),t.fill=e}else t.__render(M,A);if(M.restore(),T&&T.__updateWorldOpacity(),g){o=function(t){const{width:e,height:n}=t.view,{data:i}=t.context.getImageData(0,0,e,n);let s,o,a,r=0;for(let t=0;t<i.length;t+=4)0!==i[t+3]&&(s=r%e,o=(r-s)/e,a?Dn(a,s,o):Cn(a={},s,o)),r++;const d=new _;return In(a,d),d.scale(1/t.pixelRatio).ceil()}(M);const t=M,{width:e,height:n}=o,s={x:0,y:0,width:e,height:n,pixelRatio:k};M=i.canvas(s),M.copyWorld(t,o,s)}b&&M.fillWorld(M.bounds,x||"#FFFFFF","destination-over"),w&&w(M);const D="canvas"===n?M:yield M.export(n,s);c({data:D,width:M.pixelWidth,height:M.pixelHeight,renderBounds:e,trimBounds:o})}))))):c({data:!1})}))))}};let Fn;function Yn(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Yn(t)))}const Xn=t.prototype,Gn=w.get("@leafer-ui/export");Xn.export=function(t,e){const{quality:n,blob:i}=a.getExportOptions(e);return t.includes(".")?this.saveAs(t,n):i?this.toBlob(t,n):this.toDataURL(t,n)},Xn.toBlob=function(t,n){return new Promise((i=>{e.origin.canvasToBolb(this.view,t,n).then((t=>{i(t)})).catch((t=>{Gn.error(t),i(null)}))}))},Xn.toDataURL=function(t,n){return e.origin.canvasToDataURL(this.view,t,n)},Xn.saveAs=function(t,n){return new Promise((i=>{e.origin.canvasSaveAs(this.view,t,n).then((()=>{i(!0)})).catch((t=>{Gn.error(t),i(!1)}))}))},Object.assign(X,Tn),Object.assign(I,Mn),Object.assign(G,mt),Object.assign(D,te),Object.assign(P,ye),Object.assign(U,Ee),Object.assign(F,Pn),V();export{ot as Layouter,N as LeaferCanvas,rt as Renderer,z as Watcher,V as useCanvas};
1
+ import{LeaferCanvasBase as t,Platform as e,canvasPatch as n,Creator as i,LeaferImage as s,defineKey as o,FileHelper as a,LeafList as r,DataHelper as d,RenderEvent as l,ChildEvent as c,WatchEvent as h,PropertyEvent as u,LeafHelper as f,BranchHelper as p,Bounds as _,LeafBoundsHelper as g,Debug as w,LeafLevelList as y,LayoutEvent as m,Run as v,ImageManager as x,ResizeEvent as b,BoundsHelper as B,MatrixHelper as R,MathHelper as k,AlignHelper as S,ImageEvent as E,AroundHelper as L,PointHelper as O,Direction4 as W,TwoPointBoundsHelper as A,TaskProcessor as T,Matrix as M}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{PaintImage as C,ColorConvert as D,PaintGradient as I,Export as P,Group as F,TextConvert as Y,Paint as X,Effect as G}from"@leafer-ui/draw";export*from"@leafer-ui/draw";class U extends t{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config)}__createView(){this.view=e.origin.createCanvas(1,1)}updateViewSize(){const{width:t,height:e,pixelRatio:n}=this;this.view.width=Math.ceil(t*n),this.view.height=Math.ceil(e*n),this.clientBounds=this.bounds}}n(OffscreenCanvasRenderingContext2D.prototype),n(Path2D.prototype);const{mineType:N}=a;function j(t,n){e.origin={createCanvas:(t,e)=>new OffscreenCanvas(t,e),canvasToDataURL:(t,e,n)=>new Promise(((i,s)=>{t.convertToBlob({type:N(e),quality:n}).then((t=>{var e=new FileReader;e.onload=t=>i(t.target.result),e.onerror=t=>s(t),e.readAsDataURL(t)})).catch((t=>{s(t)}))})),canvasToBolb:(t,e,n)=>t.convertToBlob({type:N(e),quality:n}),canvasSaveAs:(t,e,n)=>new Promise((t=>t())),download(t,e){},loadImage:t=>new Promise(((n,i)=>{let s=new XMLHttpRequest;s.open("GET",e.image.getRealURL(t),!0),s.responseType="blob",s.onload=()=>{createImageBitmap(s.response).then((t=>{n(t)})).catch((t=>{i(t)}))},s.onerror=t=>i(t),s.send()}))},e.canvas=i.canvas(),e.conicGradientSupport=!!e.canvas.context.createConicGradient}Object.assign(i,{canvas:(t,e)=>new U(t,e),image:t=>new s(t)}),e.name="web",e.isWorker=!0,e.requestRender=function(t){requestAnimationFrame(t)},o(e,"devicePixelRatio",{get:()=>1});const{userAgent:V}=navigator;V.indexOf("Firefox")>-1?(e.conicGradientRotate90=!0,e.intWheelDeltaY=!0):V.indexOf("Safari")>-1&&-1===V.indexOf("Chrome")&&(e.fullImageShadow=!0),V.indexOf("Windows")>-1?(e.os="Windows",e.intWheelDeltaY=!0):V.indexOf("Mac")>-1?e.os="Mac":V.indexOf("Linux")>-1&&(e.os="Linux");class q{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const t=new r;return this.__updatedList.list.forEach((e=>{e.leafer&&t.add(e)})),t}return this.__updatedList}constructor(t,e){this.totalTimes=0,this.config={},this.__updatedList=new r,this.target=t,e&&(this.config=d.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(l.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,n=e.length;t<n;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new h(h.DATA,{updatedList:this.updatedList})),this.__updatedList=new r,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(u.CHANGE,this.__onAttrChange,this),t.on_([c.ADD,c.REMOVE],this.__onChildEvent,this),t.on_(h.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:z,updateBounds:H,updateAllWorldOpacity:Q}=f,{pushAllChildBranch:J,pushAllParent:Z}=p;const{worldBounds:$}=g,K={x:0,y:0,width:1e5,height:1e5};class tt{constructor(t){this.updatedBounds=new _,this.beforeBounds=new _,this.afterBounds=new _,t instanceof Array&&(t=new r(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,$)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(K):this.afterBounds.setListWithFn(t,$),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:et,updateAllChange:nt}=f,it=w.get("Layouter");class st{constructor(t,e){this.totalTimes=0,this.config={},this.__levelList=new y,this.target=t,e&&(this.config=d.default(e,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:t}=this;this.times=0;try{t.emit(m.START),this.layoutOnce(),t.emitEvent(new m(m.END,this.layoutedBlocks,this.times))}catch(t){it.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?it.warn("layouting"):this.times>3?it.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(h.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var t;if(!(null===(t=this.__updatedList)||void 0===t?void 0:t.length))return;const e=v.start("PartLayout"),{target:n,__updatedList:i}=this,{BEFORE:s,LAYOUT:o,AFTER:a}=m,r=this.getBlocks(i);r.forEach((t=>t.setBefore())),n.emitEvent(new m(s,r,this.times)),this.extraBlock=null,i.sort(),function(t,e){let n;t.list.forEach((t=>{n=t.__layout,e.without(t)&&!n.proxyZoom&&(n.matrixChanged?(z(t,!0),e.add(t),t.isBranch&&J(t,e),Z(t,e)):n.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),Z(t,e)))}))}(i,this.__levelList),function(t){let e,n,i;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(n=e[t],n.isBranch&&n.__tempNumber){i=n.children;for(let t=0,e=i.length;t<e;t++)i[t].isBranch||H(i[t])}H(n)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&Q(t),e.stateStyleChanged&&setTimeout((()=>e.stateStyleChanged&&t.updateState())),t.__updateChange()}))}(i),this.extraBlock&&r.push(this.extraBlock),r.forEach((t=>t.setAfter())),n.emitEvent(new m(o,r,this.times)),n.emitEvent(new m(a,r,this.times)),this.addBlocks(r),this.__levelList.reset(),this.__updatedList=null,v.end(e)}fullLayout(){const t=v.start("FullLayout"),{target:e}=this,{BEFORE:n,LAYOUT:i,AFTER:s}=m,o=this.getBlocks(new r(e));e.emitEvent(new m(n,o,this.times)),st.fullLayout(e),o.forEach((t=>{t.setAfter()})),e.emitEvent(new m(i,o,this.times)),e.emitEvent(new m(s,o,this.times)),this.addBlocks(o),v.end(t)}static fullLayout(t){et(t,!0),t.isBranch?p.updateBounds(t):f.updateBounds(t),nt(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:n}=this.extraBlock||(this.extraBlock=new tt([]));e.length?n.add(t.__world):n.set(t.__world),e.add(t)}}createBlock(t){return new tt(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_(h.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const ot=w.get("Renderer");class at{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(t,e,n){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=t,this.canvas=e,n&&(this.config=d.default(n,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 _,ot.log(e.innerName,"---\x3e");try{this.emitRender(l.START),this.renderOnce(t),this.emitRender(l.END,this.totalBounds),x.clearRecycled()}catch(t){this.rendering=!1,ot.error(t)}ot.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return ot.warn("rendering");if(this.times>3)return ot.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new _,this.renderOptions={},t)this.emitRender(l.BEFORE),t();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(l.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(l.RENDER,this.renderBounds,this.renderOptions),this.emitRender(l.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 ot.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(t){const e=v.start("PartRender"),{canvas:n}=this,i=t.getIntersect(n.bounds),s=t.includes(this.target.__world),o=new _(i);n.save(),s&&!w.showRepaint?n.clear():(i.spread(10+1/this.canvas.pixelRatio).ceil(),n.clearWorld(i,!0),n.clipWorld(i,!0)),this.__render(i,s,o),n.restore(),v.end(e)}fullRender(){const t=v.start("FullRender"),{canvas:e}=this;e.save(),e.clear(),this.__render(e.bounds,!0),e.restore(),v.end(t)}__render(t,e,n){const i=t.includes(this.target.__world)?{includes:e}:{bounds:t,includes:e};this.needFill&&this.canvas.fillWorld(t,this.config.fill),w.showRepaint&&this.canvas.strokeWorld(t,"red"),this.target.__render(this.canvas,i),this.renderBounds=n=n||t,this.renderOptions=i,this.totalBounds.isEmpty()?this.totalBounds=n:this.totalBounds.add(n),w.showHitView&&this.renderHitView(i),w.showBoundsView&&this.renderBoundsView(i),this.canvas.updateRender(n)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:t}=this;if(t){const e=new _;e.setList(t),t.length=0,t.push(e)}}__requestRender(){const t=Date.now();e.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-t))),this.running&&(this.changed&&this.canvas.view&&this.render(),this.target.emit(l.NEXT)),this.target&&this.__requestRender()}))}__onResize(t){if(!this.canvas.unreal){if(t.bigger||!t.samePixelRatio){const{width:e,height:n}=t.old;if(!new _(0,0,e,n).includes(this.target.__world)||this.needFill||!t.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new _(0,0,1,1)),this.changed=!0}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||ot.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,n){this.target.emitEvent(new l(t,this.times,e,n))}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(l.REQUEST,this.update,this),t.on_(m.END,this.__onLayoutEnd,this),t.on_(l.AGAIN,this.renderAgain,this),t.on_(b.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}function rt(t,e){let n;const{rows:i,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=i.length;t<a;t++)n=i[t],n.text?e.fillText(n.text,n.x,n.y):n.data&&n.data.forEach((t=>{e.fillText(t.char,t.x,n.y)})),s&&e.fillRect(n.x,n.y+s,n.width,o)}function dt(t,e,n){const{strokeAlign:i}=e.__,s="string"!=typeof t;switch(i){case"center":n.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?ht(t,!0,e,n):ct(e,n);break;case"inside":lt("inside",t,s,e,n);break;case"outside":lt("outside",t,s,e,n)}}function lt(t,e,n,i,s){const{__strokeWidth:o,__font:a}=i.__,r=s.getSameCanvas(!0,!0);r.setStroke(n?void 0:e,2*o,i.__),r.font=a,n?ht(e,!0,i,r):ct(i,r),r.blendMode="outside"===t?"destination-out":"destination-in",rt(i,r),r.blendMode="normal",i.__worldFlipped?s.copyWorldByReset(r,i.__nowWorld):s.copyWorldToInner(r,i.__nowWorld,i.__layout.renderBounds),r.recycle(i.__nowWorld)}function ct(t,e){let n;const{rows:i,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=i.length;t<a;t++)n=i[t],n.text?e.strokeText(n.text,n.x,n.y):n.data&&n.data.forEach((t=>{e.strokeText(t.char,t.x,n.y)})),s&&e.strokeRect(n.x,n.y+s,n.width,o)}function ht(t,e,n,i){let s;for(let o=0,a=t.length;o<a;o++)s=t[o],s.image&&C.checkImage(n,i,s,!1)||s.style&&(i.strokeStyle=s.style,s.blendMode?(i.saveBlendMode(s.blendMode),e?ct(n,i):i.stroke(),i.restoreBlendMode()):e?ct(n,i):i.stroke())}Object.assign(i,{watcher:(t,e)=>new q(t,e),layouter:(t,e)=>new st(t,e),renderer:(t,e,n)=>new at(t,e,n),selector:(t,e)=>{},interaction:(t,e,n,i)=>{}}),e.layout=st.fullLayout;const{getSpread:ut,getOuterOf:ft,getByMove:pt,getIntersectData:_t}=B;let gt;function wt(t,e,n){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:i}=n.__layout;switch(e.type){case"solid":let{type:s,blendMode:o,color:a,opacity:r}=e;return{type:s,blendMode:o,style:D.string(a,r)};case"image":return C.image(n,t,e,i,!gt||!gt[e.url]);case"linear":return I.linearGradient(e,i);case"radial":return I.radialGradient(e,i);case"angular":return I.conicGradient(e,i);default:return void 0!==e.r?{type:"solid",style:D.string(e)}:void 0}}const yt={compute:function(t,e){const n=e.__,i=[];let s,o=n.__input[t];o instanceof Array||(o=[o]),gt=C.recycleImage(t,n);for(let n,s=0,a=o.length;s<a;s++)n=wt(t,o[s],e),n&&i.push(n);n["_"+t]=i.length?i:void 0,i.length&&i[0].image&&(s=i[0].image.hasOpacityPixel),"fill"===t?n.__pixelFill=s:n.__pixelStroke=s},fill:function(t,e,n){n.fillStyle=t,e.__.__font?rt(e,n):e.__.windingRule?n.fill(e.__.windingRule):n.fill()},fills:function(t,e,n){let i;const{windingRule:s,__font:o}=e.__;for(let a=0,r=t.length;a<r;a++)i=t[a],i.image&&C.checkImage(e,n,i,!o)||i.style&&(n.fillStyle=i.style,i.transform?(n.save(),n.transform(i.transform),i.blendMode&&(n.blendMode=i.blendMode),o?rt(e,n):s?n.fill(s):n.fill(),n.restore()):i.blendMode?(n.saveBlendMode(i.blendMode),o?rt(e,n):s?n.fill(s):n.fill(),n.restoreBlendMode()):o?rt(e,n):s?n.fill(s):n.fill())},fillText:rt,stroke:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)dt(t,e,n);else switch(o){case"center":n.setStroke(t,s,i),n.stroke();break;case"inside":n.save(),n.setStroke(t,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),n.stroke(),n.restore();break;case"outside":const o=n.getSameCanvas(!0,!0);o.setStroke(t,2*s,i),e.__drawRenderPath(o),o.stroke(),i.windingRule?o.clip(i.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?n.copyWorldByReset(o,e.__nowWorld):n.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)dt(t,e,n);else switch(o){case"center":n.setStroke(void 0,s,i),ht(t,!1,e,n);break;case"inside":n.save(),n.setStroke(void 0,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),ht(t,!1,e,n),n.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=n.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*s,i),ht(t,!1,e,a),i.windingRule?a.clip(i.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?n.copyWorldByReset(a,e.__nowWorld):n.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:dt,drawTextStroke:ct,shape:function(t,e,n){const i=e.getSameCanvas(),s=t.__nowWorld;let o,a,r,d,{scaleX:l,scaleY:c}=s;if(l<0&&(l=-l),c<0&&(c=-c),e.bounds.includes(s))d=i,o=r=s;else{const{renderShapeSpread:i}=t.__layout,h=_t(i?ut(e.bounds,l===c?i*l:[i*c,i*l]):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:f}=a;if(a.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,n),l*=u,c*=f),r=ft(s,a),o=pt(r,-a.e,-a.f),n.matrix){const{matrix:t}=n;a.multiply(t),u*=t.scaleX,f*=t.scaleY}n=Object.assign(Object.assign({},n),{matrix:a.withScale(u,f)})}return t.__renderShape(i,n),{canvas:i,matrix:a,bounds:o,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:c}}};let mt={};const{get:vt,rotateOfOuter:xt,translate:bt,scaleOfOuter:Bt,scale:Rt,rotate:kt}=R;function St(t,e,n,i,s,o,a){const r=vt();bt(r,e.x+n,e.y+i),Rt(r,s,o),a&&xt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function Et(t,e,n,i,s,o,a){const r=vt();bt(r,e.x+n,e.y+i),s&&Rt(r,s,o),a&&kt(r,a),t.transform=r}function Lt(t,e,n,i,s,o,a,r,d,l){const c=vt();if(d)if("center"===l)xt(c,{x:n/2,y:i/2},d);else switch(kt(c,d),d){case 90:bt(c,i,0);break;case 180:bt(c,n,i);break;case 270:bt(c,0,n)}mt.x=e.x+s,mt.y=e.y+o,bt(c,mt.x,mt.y),a&&Bt(c,mt,a,r),t.transform=c}const{get:Ot,translate:Wt}=R,At=new _,Tt={},Mt={};function Ct(t,e,n,i){const{blendMode:s,sync:o}=n;s&&(t.blendMode=s),o&&(t.sync=o),t.data=Dt(n,i,e)}function Dt(t,e,n){let{width:i,height:s}=n;t.padding&&(e=At.set(e).shrink(t.padding)),"strench"===t.mode&&(t.mode="stretch");const{opacity:o,mode:a,align:r,offset:d,scale:l,size:c,rotation:h,repeat:u}=t,f=e.width===i&&e.height===s,p={mode:a},_="center"!==r&&(h||0)%180==90,g=_?s:i,w=_?i:s;let y,m,v=0,x=0;if(a&&"cover"!==a&&"fit"!==a)(l||c)&&(k.getScaleData(l,c,n,Mt),y=Mt.scaleX,m=Mt.scaleY);else if(!f||h){const t=e.width/g,n=e.height/w;y=m="fit"===a?Math.min(t,n):Math.max(t,n),v+=(e.width-i*y)/2,x+=(e.height-s*m)/2}if(r){const t={x:v,y:x,width:g,height:w};y&&(t.width*=y,t.height*=m),S.toPoint(r,t,e,Tt,!0),v+=Tt.x,x+=Tt.y}switch(d&&(v+=d.x,x+=d.y),a){case"stretch":f||(i=e.width,s=e.height);break;case"normal":case"clip":(v||x||y||h)&&Et(p,e,v,x,y,m,h);break;case"repeat":(!f||y||h)&&Lt(p,e,i,s,v,x,y,m,h,r),u||(p.repeat="repeat");break;default:y&&St(p,e,v,x,y,m,h)}return p.transform||(e.x||e.y)&&(p.transform=Ot(),Wt(p.transform,e.x,e.y)),y&&"stretch"!==a&&(p.scaleX=y,p.scaleY=m),p.width=i,p.height=s,o&&(p.opacity=o),u&&(p.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),p}let It,Pt=new _;const{isSame:Ft}=B;function Yt(t,e,n,i,s,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=i.width/e.pixelRatio,e.__naturalHeight=i.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return s.data||Ct(s,i,n,o),!0}function Xt(t,e){Nt(t,E.LOAD,e)}function Gt(t,e){Nt(t,E.LOADED,e)}function Ut(t,e,n){e.error=n,t.forceUpdate("surface"),Nt(t,E.ERROR,e)}function Nt(t,e,n){t.hasEvent(e)&&t.emitEvent(new E(e,n))}function jt(t,e){const{leafer:n}=t;n&&n.viewReady&&(n.renderer.ignore=e)}const{get:Vt,scale:qt,copy:zt}=R,{ceil:Ht,abs:Qt}=Math;function Jt(t,n,i){let{scaleX:s,scaleY:o}=x.patternLocked?t.__world:t.__nowWorld;const a=s+"-"+o+"-"+i;if(n.patternId===a||t.destroyed)return!1;{s=Qt(s),o=Qt(o);const{image:t,data:r}=n;let d,l,{width:c,height:h,scaleX:u,scaleY:f,opacity:p,transform:_,repeat:g}=r;u&&(l=Vt(),zt(l,_),qt(l,1/u,1/f),s*=u,o*=f),s*=i,o*=i,c*=s,h*=o;const w=c*h;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&&(s/=d,o/=d,c/=d,h/=d),u&&(s/=u,o/=f),(_||1!==s||1!==o)&&(l||(l=Vt(),_&&zt(l,_)),qt(l,1/s,1/o));const m=t.getCanvas(Ht(c)||1,Ht(h)||1,p),v=t.getPattern(m,g||e.origin.noRepeat||"no-repeat",l,n);return n.style=v,n.patternId=a,!0}}function Zt(t,e,n,i){return new(n||(n=Promise))((function(s,o){function a(t){try{d(i.next(t))}catch(t){o(t)}}function r(t){try{d(i.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,r)}d((i=i.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:$t}=Math;const Kt={image:function(t,e,n,i,s){let o,a;const r=x.get(n);return It&&n===It.paint&&Ft(i,It.boxBounds)?o=It.leafPaint:(o={type:n.type,image:r},It=r.use>1?{leafPaint:o,paint:n,boxBounds:Pt.set(i)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:n}),r.ready?(Yt(t,e,n,r,o,i),s&&(Xt(t,a),Gt(t,a))):r.error?s&&Ut(t,a,r.error):(jt(t,!0),s&&Xt(t,a),o.loadId=r.load((()=>{jt(t,!1),t.destroyed||(Yt(t,e,n,r,o,i)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Gt(t,a)),o.loadId=null}),(e=>{jt(t,!1),Ut(t,a,e),o.loadId=null}))),o},checkImage:function(t,n,i,s){const{scaleX:o,scaleY:a}=x.patternLocked?t.__world:t.__nowWorld,{pixelRatio:r}=n;if(!i.data||i.patternId===o+"-"+a+"-"+r&&!P.running)return!1;{const{data:d}=i;if(s)if(d.repeat)s=!1;else{let{width:t,height:n}=d;t*=$t(o)*r,n*=$t(a)*r,d.scaleX&&(t*=d.scaleX,n*=d.scaleY),s=t*n>e.image.maxCacheSize||P.running}return s?(n.save(),n.clip(),i.blendMode&&(n.blendMode=i.blendMode),d.opacity&&(n.opacity*=d.opacity),d.transform&&n.transform(d.transform),n.drawImage(i.image.view,0,0,d.width,d.height),n.restore(),!0):(!i.style||i.sync||P.running?Jt(t,i,r):i.patternTask||(i.patternTask=x.patternTasker.add((()=>Zt(this,void 0,void 0,(function*(){i.patternTask=null,n.bounds.hit(t.__nowWorld)&&Jt(t,i,r),t.forceUpdate("surface")}))),300)),!1)}},createPattern:Jt,recycleImage:function(t,e){const n=e["_"+t];if(n instanceof Array){let i,s,o,a;for(let r=0,d=n.length;r<d;r++)i=n[r].image,a=i&&i.url,a&&(s||(s={}),s[a]=!0,x.recycle(i),i.loading&&(o||(o=e.__input&&e.__input[t]||[],o instanceof Array||(o=[o])),i.unload(n[r].loadId,!o.some((t=>t.url===a)))));return s}return null},createData:Ct,getPatternData:Dt,fillOrFitMode:St,clipMode:Et,repeatMode:Lt},{toPoint:te}=L,ee={},ne={};function ie(t,e,n){if(e){let i;for(let s=0,o=e.length;s<o;s++)i=e[s],"string"==typeof i?t.addColorStop(s/(o-1),D.string(i,n)):t.addColorStop(i.offset,D.string(i.color,n))}}const{getAngle:se,getDistance:oe}=O,{get:ae,rotateOfOuter:re,scaleOfOuter:de}=R,{toPoint:le}=L,ce={},he={};function ue(t,e,n,i,s){let o;const{width:a,height:r}=t;if(a!==r||i){const t=se(e,n);o=ae(),s?(de(o,e,a/r*(i||1),1),re(o,e,t+90)):(de(o,e,1,a/r*(i||1)),re(o,e,t))}return o}const{getDistance:fe}=O,{toPoint:pe}=L,_e={},ge={};const we={linearGradient:function(t,n){let{from:i,to:s,type:o,blendMode:a,opacity:r}=t;te(i||"top",n,ee),te(s||"bottom",n,ne);const d=e.canvas.createLinearGradient(ee.x,ee.y,ne.x,ne.y);ie(d,t.stops,r);const l={type:o,style:d};return a&&(l.blendMode=a),l},radialGradient:function(t,n){let{from:i,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;le(i||"center",n,ce),le(s||"bottom",n,he);const l=e.canvas.createRadialGradient(ce.x,ce.y,0,ce.x,ce.y,oe(ce,he));ie(l,t.stops,a);const c={type:o,style:l},h=ue(n,ce,he,d,!0);return h&&(c.transform=h),r&&(c.blendMode=r),c},conicGradient:function(t,n){let{from:i,to:s,type:o,opacity:a,blendMode:r,stretch:d}=t;pe(i||"center",n,_e),pe(s||"bottom",n,ge);const l=e.conicGradientSupport?e.canvas.createConicGradient(0,_e.x,_e.y):e.canvas.createRadialGradient(_e.x,_e.y,0,_e.x,_e.y,fe(_e,ge));ie(l,t.stops,a);const c={type:o,style:l},h=ue(n,_e,ge,d||1,e.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:ue},{copy:ye,toOffsetOutBounds:me}=B,ve={},xe={};function be(t,n,i,s){const{bounds:o,shapeBounds:a}=s;if(e.fullImageShadow){if(ye(ve,t.bounds),ve.x+=n.x-a.x,ve.y+=n.y-a.y,i){const{matrix:t}=s;ve.x-=(o.x+(t?t.e:0)+o.width/2)*(i-1),ve.y-=(o.y+(t?t.f:0)+o.height/2)*(i-1),ve.width*=i,ve.height*=i}t.copyWorld(s.canvas,t.bounds,ve)}else i&&(ye(ve,n),ve.x-=n.width/2*(i-1),ve.y-=n.height/2*(i-1),ve.width*=i,ve.height*=i),t.copyWorld(s.canvas,a,i?ve:n)}const{toOffsetOutBounds:Be}=B,Re={};const ke={shadow:function(t,e,n){let i,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;me(l,xe),r.forEach(((r,_)=>{f.setWorldShadow(xe.offsetX+r.x*h,xe.offsetY+r.y*u,r.blur*h,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,be(f,xe,s,n),i=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,o,"copy"),i=o),d?f.copyWorld(d,o,o,"destination-out"):f.copyWorld(n.canvas,c,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,i,o,r.blendMode):e.copyWorldToInner(f,i,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(i,!0)})),f.recycle(i)},innerShadow:function(t,e,n){let i,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;Be(l,Re),r.forEach(((r,_)=>{f.save(),f.setWorldShadow(Re.offsetX+r.x*h,Re.offsetY+r.y*u,r.blur*h),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,be(f,Re,s,n),f.restore(),d?(f.copyWorld(f,l,o,"copy"),f.copyWorld(d,o,o,"source-out"),i=o):(f.copyWorld(n.canvas,c,l,"source-out"),i=l),f.fillWorld(i,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,i,o,r.blendMode):e.copyWorldToInner(f,i,a.renderBounds,r.blendMode),p&&_<p&&f.clearWorld(i,!0)})),f.recycle(i)},blur:function(t,e,n){const{blur:i}=t.__;n.setWorldBlur(i*t.__nowWorld.a),n.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),n.filter="none"},backgroundBlur:function(t,e,n){}},{excludeRenderBounds:Se}=g;function Ee(t,e,n,i,s,o){switch(e){case"alpha":!function(t,e,n,i){const s=t.__nowWorld;n.resetTransform(),n.opacity=1,n.useMask(i,s),i.recycle(s),Oe(t,e,n,1)}(t,n,i,s);break;case"opacity-path":Oe(t,n,i,o);break;case"path":n.restore()}}function Le(t){return t.getSameCanvas(!1,!0)}function Oe(t,e,n,i){const s=t.__nowWorld;e.resetTransform(),e.opacity=i,e.copyWorld(n,s),n.recycle(s)}F.prototype.__renderMask=function(t,e){let n,i,s,o,a;const{children:r}=this;for(let d=0,l=r.length;d<l;d++)n=r[d],n.__.mask&&(a&&(Ee(this,a,t,s,i,o),i=s=null),"path"===n.__.mask?(n.opacity<1?(a="opacity-path",o=n.opacity,s||(s=Le(t))):(a="path",t.save()),n.__clip(s||t,e)):(a="alpha",i||(i=Le(t)),s||(s=Le(t)),n.__render(i,e)),"clipping"!==n.__.mask)||Se(n,e)||n.__render(s||t,e);Ee(this,a,t,s,i,o)};const We=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Ae=We+"_#~&*+\\=|≮≯≈≠=…",Te=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"),De=Me("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Ie=Me(We),Pe=Me(Ae),Fe=Me("- —/~|┆·");var Ye;!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"}(Ye||(Ye={}));const{Letter:Xe,Single:Ge,Before:Ue,After:Ne,Symbol:je,Break:Ve}=Ye;function qe(t){return Ce[t]?Xe:Fe[t]?Ve:De[t]?Ue:Ie[t]?Ne:Pe[t]?je:Te.test(t)?Ge:Xe}const ze={trimRight(t){const{words:e}=t;let n,i=0,s=e.length;for(let o=s-1;o>-1&&(n=e[o].data[0]," "===n.char);o--)i++,t.width-=n.width;i&&e.splice(s-i,i)}};function He(t,e,n){switch(e){case"title":return n?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:Qe}=ze,{Letter:Je,Single:Ze,Before:$e,After:Ke,Symbol:tn,Break:en}=Ye;let nn,sn,on,an,rn,dn,ln,cn,hn,un,fn,pn,_n,gn,wn,yn,mn=[];function vn(t,e){hn&&!cn&&(cn=hn),nn.data.push({char:t,width:e}),on+=e}function xn(){an+=on,nn.width=on,sn.words.push(nn),nn={data:[]},on=0}function bn(){gn&&(wn.paraNumber++,sn.paraStart=!0,gn=!1),hn&&(sn.startCharSize=cn,sn.endCharSize=hn,cn=0),sn.width=an,yn.width&&Qe(sn),mn.push(sn),sn={words:[]},an=0}const Bn=0,Rn=1,kn=2;const{top:Sn,right:En,bottom:Ln,left:On}=W;function Wn(t,e,n){const{bounds:i,rows:s}=t;i[e]+=n;for(let t=0;t<s.length;t++)s[t][e]+=n}const An={getDrawData:function(t,n){"string"!=typeof t&&(t=String(t));let i=0,s=0,o=n.__getInput("width")||0,a=n.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=n;l&&(o&&(i=l[On],o-=l[En]+l[On]),a&&(s=l[Sn],a-=l[Sn]+l[Ln]));const c={bounds:{x:i,y:s,width:o,height:a},rows:[],paraNumber:0,font:e.canvas.font=d};return function(t,n,i){wn=t,mn=t.rows,yn=t.bounds;const{__letterSpacing:s,paraIndent:o,textCase:a}=i,{canvas:r}=e,{width:d,height:l}=yn;if(d||l||s||"none"!==a){const t="none"!==i.textWrap,e="break"===i.textWrap;gn=!0,fn=null,cn=ln=hn=on=an=0,nn={data:[]},sn={words:[]};for(let i=0,l=n.length;i<l;i++)dn=n[i],"\n"===dn?(on&&xn(),sn.paraEnd=!0,bn(),gn=!0):(un=qe(dn),un===Je&&"none"!==a&&(dn=He(dn,a,!on)),ln=r.measureText(dn).width,s&&(s<0&&(hn=ln),ln+=s),pn=un===Ze&&(fn===Ze||fn===Je)||fn===Ze&&un!==Ke,_n=!(un!==$e&&un!==Ze||fn!==tn&&fn!==Ke),rn=gn&&o?d-o:d,t&&d&&an+on+ln>rn&&(e?(on&&xn(),an&&bn()):(_n||(_n=un===Je&&fn==Ke),pn||_n||un===en||un===$e||un===Ze||on+ln>rn?(on&&xn(),an&&bn()):an&&bn()))," "===dn&&!0!==gn&&an+on===0||(un===en?(" "===dn&&on&&xn(),vn(dn,ln),xn()):pn||_n?(on&&xn(),vn(dn,ln)):vn(dn,ln)),fn=un);on&&xn(),an&&bn(),mn.length>0&&(mn[mn.length-1].paraEnd=!0)}else n.split("\n").forEach((t=>{wn.paraNumber++,mn.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(c,t,n),l&&function(t,e,n,i,s){if(!i)switch(n.textAlign){case"left":Wn(e,"x",t[On]);break;case"right":Wn(e,"x",-t[En])}if(!s)switch(n.verticalAlign){case"top":Wn(e,"y",t[Sn]);break;case"bottom":Wn(e,"y",-t[Ln])}}(l,c,n,o,a),function(t,e){const{rows:n,bounds:i}=t,{__lineHeight:s,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:c}=e;let h,u,f,{x:p,y:_,width:g,height:w}=i,y=s*n.length+(c?c*(t.paraNumber-1):0),m=o;if(r&&y>w)y=Math.max(w,s),t.overflow=n.length;else switch(l){case"middle":_+=(w-y)/2;break;case"bottom":_+=w-y}m+=_;for(let o=0,l=n.length;o<l;o++){if(h=n[o],h.x=p,h.width<g||h.width>g&&!r)switch(d){case"center":h.x+=(g-h.width)/2;break;case"right":h.x+=g-h.width}h.paraStart&&c&&o>0&&(m+=c),h.y=m,m+=s,t.overflow>o&&m>y&&(h.isOverflow=!0,t.overflow=o+1),u=h.x,f=h.width,a<0&&(h.width<0?(f=-h.width+e.fontSize+a,u-=f,f+=e.fontSize):f-=a),u<i.x&&(i.x=u),f>i.width&&(i.width=f),r&&g&&g<f&&(h.isOverflow=!0,t.overflow||(t.overflow=n.length))}i.y=_,i.height=y}(c,n),function(t,e,n,i){const{rows:s}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let d,l,c,h,u;s.forEach((t=>{t.words&&(c=a&&t.paraStart?a:0,l=n&&"justify"===o&&t.words.length>1?(n-t.width-c)/(t.words.length-1):0,h=r||t.isOverflow?Bn:l>.01?Rn:kn,t.isOverflow&&!r&&(t.textMode=!0),h===kn?(t.x+=c,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=c,d=t.x,t.data=[],t.words.forEach((e=>{h===Rn?(u={char:"",x:d},d=function(t,e,n){return t.forEach((t=>{n.char+=t.char,e+=t.width})),e}(e.data,d,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):d=function(t,e,n,i){return t.forEach((t=>{(i||" "!==t.char)&&(t.x=e,n.push(t)),e+=t.width})),e}(e.data,d,t.data,t.isOverflow),!t.paraEnd&&l&&(d+=l,t.width+=l)}))),t.words=null)}))}(c,n,o),c.overflow&&function(t,n,i,s){if(!s)return;const{rows:o,overflow:a}=t;let{textOverflow:r}=n;if(o.splice(a),r&&"show"!==r){let t,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const l=r?e.canvas.measureText(r).width:0,c=i+s-l;("none"===n.textWrap?o:[o[a-1]]).forEach((e=>{if(e.isOverflow&&e.data){let n=e.data.length-1;for(let i=n;i>-1&&(t=e.data[i],d=t.x+t.width,!(i===n&&d<c));i--){if(d<c&&" "!==t.char){e.data.splice(i+1),e.width-=t.width;break}e.width-=t.width}e.width+=l,e.data.push({char:r,x:d}),e.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(e)}}))}}(c,n,i,o),"none"!==r&&function(t,e){const{fontSize:n}=e;switch(t.decorationHeight=n/11,e.textDecoration){case"under":t.decorationY=.15*n;break;case"delete":t.decorationY=.35*-n}}(c,n),c}};const Tn={string:function(t,e){const n="number"==typeof e&&1!==e;if("string"==typeof t){if(!n||!D.object)return t;t=D.object(t)}let i=void 0===t.a?1:t.a;n&&(i*=e);const s=t.r+","+t.g+","+t.b;return 1===i?"rgb("+s+")":"rgba("+s+","+i+")"}},{setPoint:Mn,addPoint:Cn,toBounds:Dn}=A;const In={export(t,n,s){this.running=!0;const o=a.fileType(n),r=n.includes(".");return s=a.getExportOptions(s),function(t){Pn||(Pn=new T);return new Promise((e=>{Pn.add((()=>Zt(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((d=>new Promise((l=>{const c=t=>{d(t),l(),this.running=!1},{toURL:h}=e,{download:u}=e.origin;if("json"===o)return r&&u(h(JSON.stringify(t.toJSON(s.json)),"text"),n),c({data:!!r||t.toJSON(s.json)});if("svg"===o)return r&&u(h(t.toSVG(),"svg"),n),c({data:!!r||t.toSVG()});const{leafer:f}=t;f?(Fn(t),f.waitViewCompleted((()=>Zt(this,void 0,void 0,(function*(){let e,o,r=1,d=1;const{worldTransform:l,isLeafer:h,isFrame:u}=t,{slice:p,trim:g,onCanvas:w}=s,y=void 0===s.smooth?f.config.smooth:s.smooth,m=s.contextSettings||f.config.contextSettings,v=s.screenshot||t.isApp,x=h&&v&&void 0===s.fill?t.fill:s.fill,b=a.isOpaqueImage(n)||x,B=new M;if(v)e=!0===v?h?f.canvas.bounds:t.worldRenderBounds:v;else{let n=s.relative||(h?"inner":"local");switch(r=l.scaleX,d=l.scaleY,n){case"inner":B.set(l);break;case"local":B.set(l).divide(t.localTransform),r/=t.scaleX,d/=t.scaleY;break;case"world":r=1,d=1;break;case"page":n=t.leafer;default:B.set(l).divide(t.getTransform(n));const e=n.worldTransform;r/=r/e.scaleX,d/=d/e.scaleY}e=t.getBounds("render",n)}const R={scaleX:1,scaleY:1};k.getScaleData(s.scale,s.size,e,R);let S=s.pixelRatio||1;t.isApp&&(R.scaleX*=S,R.scaleY*=S,S=t.app.pixelRatio);const{x:E,y:L,width:O,height:W}=new _(e).scale(R.scaleX,R.scaleY),A={matrix:B.scale(1/R.scaleX,1/R.scaleY).invert().translate(-E,-L).withScale(1/r*R.scaleX,1/d*R.scaleY)};let T,C=i.canvas({width:Math.round(O),height:Math.round(W),pixelRatio:S,smooth:y,contextSettings:m});if(p&&(T=t,T.__worldOpacity=0,t=f,A.bounds=C.bounds),C.save(),u&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(C,A),t.fill=e}else t.__render(C,A);if(C.restore(),T&&T.__updateWorldOpacity(),g){o=function(t){const{width:e,height:n}=t.view,{data:i}=t.context.getImageData(0,0,e,n);let s,o,a,r=0;for(let t=0;t<i.length;t+=4)0!==i[t+3]&&(s=r%e,o=(r-s)/e,a?Cn(a,s,o):Mn(a={},s,o)),r++;const d=new _;return Dn(a,d),d.scale(1/t.pixelRatio).ceil()}(C);const t=C,{width:e,height:n}=o,s={x:0,y:0,width:e,height:n,pixelRatio:S};C=i.canvas(s),C.copyWorld(t,o,s)}b&&C.fillWorld(C.bounds,x||"#FFFFFF","destination-over"),w&&w(C);const D="canvas"===n?C:yield C.export(n,s);c({data:D,width:C.pixelWidth,height:C.pixelHeight,renderBounds:e,trimBounds:o})}))))):c({data:!1})}))))}};let Pn;function Fn(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Fn(t)))}const Yn=t.prototype,Xn=w.get("@leafer-ui/export");Yn.export=function(t,e){const{quality:n,blob:i}=a.getExportOptions(e);return t.includes(".")?this.saveAs(t,n):i?this.toBlob(t,n):this.toDataURL(t,n)},Yn.toBlob=function(t,n){return new Promise((i=>{e.origin.canvasToBolb(this.view,t,n).then((t=>{i(t)})).catch((t=>{Xn.error(t),i(null)}))}))},Yn.toDataURL=function(t,n){return e.origin.canvasToDataURL(this.view,t,n)},Yn.saveAs=function(t,n){return new Promise((i=>{e.origin.canvasSaveAs(this.view,t,n).then((()=>{i(!0)})).catch((t=>{Xn.error(t),i(!1)}))}))},Object.assign(Y,An),Object.assign(D,Tn),Object.assign(X,yt),Object.assign(C,Kt),Object.assign(I,we),Object.assign(G,ke),Object.assign(P,In),j();export{st as Layouter,U as LeaferCanvas,at as Renderer,q as Watcher,j as useCanvas};