@leafer-draw/node 1.0.1 → 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/node.cjs CHANGED
@@ -241,9 +241,13 @@ function updateBounds(boundsList) {
241
241
  });
242
242
  }
243
243
  function updateChange(updateList) {
244
+ let layout;
244
245
  updateList.list.forEach(leaf => {
245
- if (leaf.__layout.opacityChanged)
246
+ layout = leaf.__layout;
247
+ if (layout.opacityChanged)
246
248
  updateAllWorldOpacity(leaf);
249
+ if (layout.stateStyleChanged)
250
+ setTimeout(() => layout.stateStyleChanged && leaf.updateState());
247
251
  leaf.__updateChange();
248
252
  });
249
253
  }
@@ -609,7 +613,6 @@ class Renderer {
609
613
  core.Platform.requestRender(() => {
610
614
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - startTime)));
611
615
  if (this.running) {
612
- this.target.emit(core.AnimateEvent.FRAME);
613
616
  if (this.changed && this.canvas.view)
614
617
  this.render();
615
618
  this.target.emit(core.RenderEvent.NEXT);
@@ -1034,16 +1037,21 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, al
1034
1037
  const { get: get$2, translate } = core.MatrixHelper;
1035
1038
  const tempBox = new core.Bounds();
1036
1039
  const tempPoint = {};
1040
+ const tempScaleData = {};
1037
1041
  function createData(leafPaint, image, paint, box) {
1038
- const { blendMode } = paint;
1042
+ const { blendMode, sync } = paint;
1039
1043
  if (blendMode)
1040
1044
  leafPaint.blendMode = blendMode;
1045
+ if (sync)
1046
+ leafPaint.sync = sync;
1041
1047
  leafPaint.data = getPatternData(paint, box, image);
1042
1048
  }
1043
1049
  function getPatternData(paint, box, image) {
1044
1050
  let { width, height } = image;
1045
1051
  if (paint.padding)
1046
1052
  box = tempBox.set(box).shrink(paint.padding);
1053
+ if (paint.mode === 'strench')
1054
+ paint.mode = 'stretch';
1047
1055
  const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint;
1048
1056
  const sameBox = box.width === width && box.height === height;
1049
1057
  const data = { mode };
@@ -1057,13 +1065,10 @@ function getPatternData(paint, box, image) {
1057
1065
  x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
1058
1066
  }
1059
1067
  }
1060
- else if (size) {
1061
- scaleX = (typeof size === 'number' ? size : size.width) / width;
1062
- scaleY = (typeof size === 'number' ? size : size.height) / height;
1063
- }
1064
- else if (scale) {
1065
- scaleX = typeof scale === 'number' ? scale : scale.x;
1066
- scaleY = typeof scale === 'number' ? scale : scale.y;
1068
+ else if (scale || size) {
1069
+ core.MathHelper.getScaleData(scale, size, image, tempScaleData);
1070
+ scaleX = tempScaleData.scaleX;
1071
+ scaleY = tempScaleData.scaleY;
1067
1072
  }
1068
1073
  if (align) {
1069
1074
  const imageBounds = { x, y, width: swapWidth, height: swapHeight };
@@ -1075,7 +1080,7 @@ function getPatternData(paint, box, image) {
1075
1080
  if (offset)
1076
1081
  x += offset.x, y += offset.y;
1077
1082
  switch (mode) {
1078
- case 'strench':
1083
+ case 'stretch':
1079
1084
  if (!sameBox)
1080
1085
  width = box.width, height = box.height;
1081
1086
  break;
@@ -1102,7 +1107,7 @@ function getPatternData(paint, box, image) {
1102
1107
  translate(data.transform, box.x, box.y);
1103
1108
  }
1104
1109
  }
1105
- if (scaleX && mode !== 'strench') {
1110
+ if (scaleX && mode !== 'stretch') {
1106
1111
  data.scaleX = scaleX;
1107
1112
  data.scaleY = scaleY;
1108
1113
  }
@@ -1206,7 +1211,7 @@ const { get: get$1, scale, copy: copy$1 } = core.MatrixHelper;
1206
1211
  const { ceil, abs: abs$1 } = Math;
1207
1212
  function createPattern(ui, paint, pixelRatio) {
1208
1213
  let { scaleX, scaleY } = core.ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1209
- const id = scaleX + '-' + scaleY;
1214
+ const id = scaleX + '-' + scaleY + '-' + pixelRatio;
1210
1215
  if (paint.patternId !== id && !ui.destroyed) {
1211
1216
  scaleX = abs$1(scaleX);
1212
1217
  scaleY = abs$1(scaleY);
@@ -1268,7 +1273,8 @@ function createPattern(ui, paint, pixelRatio) {
1268
1273
  const { abs } = Math;
1269
1274
  function checkImage(ui, canvas, paint, allowPaint) {
1270
1275
  const { scaleX, scaleY } = core.ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1271
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY && !draw.Export.running)) {
1276
+ const { pixelRatio } = canvas;
1277
+ if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !draw.Export.running)) {
1272
1278
  return false;
1273
1279
  }
1274
1280
  else {
@@ -1276,8 +1282,8 @@ function checkImage(ui, canvas, paint, allowPaint) {
1276
1282
  if (allowPaint) {
1277
1283
  if (!data.repeat) {
1278
1284
  let { width, height } = data;
1279
- width *= abs(scaleX) * canvas.pixelRatio;
1280
- height *= abs(scaleY) * canvas.pixelRatio;
1285
+ width *= abs(scaleX) * pixelRatio;
1286
+ height *= abs(scaleY) * pixelRatio;
1281
1287
  if (data.scaleX) {
1282
1288
  width *= data.scaleX;
1283
1289
  height *= data.scaleY;
@@ -1302,15 +1308,15 @@ function checkImage(ui, canvas, paint, allowPaint) {
1302
1308
  return true;
1303
1309
  }
1304
1310
  else {
1305
- if (!paint.style || draw.Export.running) {
1306
- createPattern(ui, paint, canvas.pixelRatio);
1311
+ if (!paint.style || paint.sync || draw.Export.running) {
1312
+ createPattern(ui, paint, pixelRatio);
1307
1313
  }
1308
1314
  else {
1309
1315
  if (!paint.patternTask) {
1310
1316
  paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1311
1317
  paint.patternTask = null;
1312
1318
  if (canvas.bounds.hit(ui.__nowWorld))
1313
- createPattern(ui, paint, canvas.pixelRatio);
1319
+ createPattern(ui, paint, pixelRatio);
1314
1320
  ui.forceUpdate('surface');
1315
1321
  }), 300);
1316
1322
  }
@@ -1374,14 +1380,16 @@ function linearGradient(paint, box) {
1374
1380
  return data;
1375
1381
  }
1376
1382
  function applyStops(gradient, stops, opacity) {
1377
- let stop;
1378
- for (let i = 0, len = stops.length; i < len; i++) {
1379
- stop = stops[i];
1380
- if (typeof stop === 'string') {
1381
- gradient.addColorStop(i / (len - 1), draw.ColorConvert.string(stop, opacity));
1382
- }
1383
- else {
1384
- gradient.addColorStop(stop.offset, draw.ColorConvert.string(stop.color, opacity));
1383
+ if (stops) {
1384
+ let stop;
1385
+ for (let i = 0, len = stops.length; i < len; i++) {
1386
+ stop = stops[i];
1387
+ if (typeof stop === 'string') {
1388
+ gradient.addColorStop(i / (len - 1), draw.ColorConvert.string(stop, opacity));
1389
+ }
1390
+ else {
1391
+ gradient.addColorStop(stop.offset, draw.ColorConvert.string(stop.color, opacity));
1392
+ }
1385
1393
  }
1386
1394
  }
1387
1395
  }
@@ -2137,10 +2145,15 @@ const TextConvertModule = {
2137
2145
  };
2138
2146
 
2139
2147
  function string(color, opacity) {
2140
- if (typeof color === 'string')
2141
- return color;
2148
+ const doOpacity = typeof opacity === 'number' && opacity !== 1;
2149
+ if (typeof color === 'string') {
2150
+ if (doOpacity && draw.ColorConvert.object)
2151
+ color = draw.ColorConvert.object(color);
2152
+ else
2153
+ return color;
2154
+ }
2142
2155
  let a = color.a === undefined ? 1 : color.a;
2143
- if (opacity)
2156
+ if (doOpacity)
2144
2157
  a *= opacity;
2145
2158
  const rgb = color.r + ',' + color.g + ',' + color.b;
2146
2159
  return a === 1 ? 'rgb(' + rgb + ')' : 'rgba(' + rgb + ',' + a + ')';
@@ -2172,6 +2185,7 @@ const ExportModule = {
2172
2185
  export(leaf, filename, options) {
2173
2186
  this.running = true;
2174
2187
  const fileType = core.FileHelper.fileType(filename);
2188
+ const isDownload = filename.includes('.');
2175
2189
  options = core.FileHelper.getExportOptions(options);
2176
2190
  return addTask((success) => new Promise((resolve) => {
2177
2191
  const over = (result) => {
@@ -2181,19 +2195,13 @@ const ExportModule = {
2181
2195
  };
2182
2196
  const { toURL } = core.Platform;
2183
2197
  const { download } = core.Platform.origin;
2184
- if (filename === 'json') {
2185
- return over({ data: leaf.toJSON(options.json) });
2198
+ if (fileType === 'json') {
2199
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
2200
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
2186
2201
  }
2187
- else if (fileType === 'json') {
2188
- download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
2189
- return over({ data: true });
2190
- }
2191
- if (filename === 'svg') {
2192
- return over({ data: leaf.toSVG() });
2193
- }
2194
- else if (fileType === 'svg') {
2195
- download(toURL(leaf.toSVG(), 'svg'), filename);
2196
- return over({ data: true });
2202
+ if (fileType === 'svg') {
2203
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
2204
+ return over({ data: isDownload ? true : leaf.toSVG() });
2197
2205
  }
2198
2206
  const { leafer } = leaf;
2199
2207
  if (leafer) {
@@ -2202,14 +2210,8 @@ const ExportModule = {
2202
2210
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
2203
2211
  const { worldTransform, isLeafer, isFrame } = leaf;
2204
2212
  const { slice, trim, onCanvas } = options;
2205
- let scale = options.scale || 1;
2206
- let pixelRatio = options.pixelRatio || 1;
2207
2213
  const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
2208
2214
  const contextSettings = options.contextSettings || leafer.config.contextSettings;
2209
- if (leaf.isApp) {
2210
- scale *= pixelRatio;
2211
- pixelRatio = leaf.app.pixelRatio;
2212
- }
2213
2215
  const screenshot = options.screenshot || leaf.isApp;
2214
2216
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
2215
2217
  const needFill = core.FileHelper.isOpaqueImage(filename) || fill, matrix = new core.Matrix();
@@ -2243,9 +2245,17 @@ const ExportModule = {
2243
2245
  }
2244
2246
  renderBounds = leaf.getBounds('render', relative);
2245
2247
  }
2246
- const { x, y, width, height } = new core.Bounds(renderBounds).scale(scale);
2248
+ const scaleData = { scaleX: 1, scaleY: 1 };
2249
+ core.MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
2250
+ let pixelRatio = options.pixelRatio || 1;
2251
+ if (leaf.isApp) {
2252
+ scaleData.scaleX *= pixelRatio;
2253
+ scaleData.scaleY *= pixelRatio;
2254
+ pixelRatio = leaf.app.pixelRatio;
2255
+ }
2256
+ const { x, y, width, height } = new core.Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
2257
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
2247
2258
  let canvas = core.Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
2248
- const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
2249
2259
  let sliceLeaf;
2250
2260
  if (slice) {
2251
2261
  sliceLeaf = leaf;
package/dist/node.esm.js CHANGED
@@ -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, 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 { writeFileSync } from 'fs';
@@ -242,9 +242,13 @@ function updateBounds(boundsList) {
242
242
  });
243
243
  }
244
244
  function updateChange(updateList) {
245
+ let layout;
245
246
  updateList.list.forEach(leaf => {
246
- if (leaf.__layout.opacityChanged)
247
+ layout = leaf.__layout;
248
+ if (layout.opacityChanged)
247
249
  updateAllWorldOpacity(leaf);
250
+ if (layout.stateStyleChanged)
251
+ setTimeout(() => layout.stateStyleChanged && leaf.updateState());
248
252
  leaf.__updateChange();
249
253
  });
250
254
  }
@@ -610,7 +614,6 @@ class Renderer {
610
614
  Platform.requestRender(() => {
611
615
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - startTime)));
612
616
  if (this.running) {
613
- this.target.emit(AnimateEvent.FRAME);
614
617
  if (this.changed && this.canvas.view)
615
618
  this.render();
616
619
  this.target.emit(RenderEvent.NEXT);
@@ -1035,16 +1038,21 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, al
1035
1038
  const { get: get$2, translate } = MatrixHelper;
1036
1039
  const tempBox = new Bounds();
1037
1040
  const tempPoint = {};
1041
+ const tempScaleData = {};
1038
1042
  function createData(leafPaint, image, paint, box) {
1039
- const { blendMode } = paint;
1043
+ const { blendMode, sync } = paint;
1040
1044
  if (blendMode)
1041
1045
  leafPaint.blendMode = blendMode;
1046
+ if (sync)
1047
+ leafPaint.sync = sync;
1042
1048
  leafPaint.data = getPatternData(paint, box, image);
1043
1049
  }
1044
1050
  function getPatternData(paint, box, image) {
1045
1051
  let { width, height } = image;
1046
1052
  if (paint.padding)
1047
1053
  box = tempBox.set(box).shrink(paint.padding);
1054
+ if (paint.mode === 'strench')
1055
+ paint.mode = 'stretch';
1048
1056
  const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint;
1049
1057
  const sameBox = box.width === width && box.height === height;
1050
1058
  const data = { mode };
@@ -1058,13 +1066,10 @@ function getPatternData(paint, box, image) {
1058
1066
  x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
1059
1067
  }
1060
1068
  }
1061
- else if (size) {
1062
- scaleX = (typeof size === 'number' ? size : size.width) / width;
1063
- scaleY = (typeof size === 'number' ? size : size.height) / height;
1064
- }
1065
- else if (scale) {
1066
- scaleX = typeof scale === 'number' ? scale : scale.x;
1067
- scaleY = typeof scale === 'number' ? scale : scale.y;
1069
+ else if (scale || size) {
1070
+ MathHelper.getScaleData(scale, size, image, tempScaleData);
1071
+ scaleX = tempScaleData.scaleX;
1072
+ scaleY = tempScaleData.scaleY;
1068
1073
  }
1069
1074
  if (align) {
1070
1075
  const imageBounds = { x, y, width: swapWidth, height: swapHeight };
@@ -1076,7 +1081,7 @@ function getPatternData(paint, box, image) {
1076
1081
  if (offset)
1077
1082
  x += offset.x, y += offset.y;
1078
1083
  switch (mode) {
1079
- case 'strench':
1084
+ case 'stretch':
1080
1085
  if (!sameBox)
1081
1086
  width = box.width, height = box.height;
1082
1087
  break;
@@ -1103,7 +1108,7 @@ function getPatternData(paint, box, image) {
1103
1108
  translate(data.transform, box.x, box.y);
1104
1109
  }
1105
1110
  }
1106
- if (scaleX && mode !== 'strench') {
1111
+ if (scaleX && mode !== 'stretch') {
1107
1112
  data.scaleX = scaleX;
1108
1113
  data.scaleY = scaleY;
1109
1114
  }
@@ -1207,7 +1212,7 @@ const { get: get$1, scale, copy: copy$1 } = MatrixHelper;
1207
1212
  const { ceil, abs: abs$1 } = Math;
1208
1213
  function createPattern(ui, paint, pixelRatio) {
1209
1214
  let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1210
- const id = scaleX + '-' + scaleY;
1215
+ const id = scaleX + '-' + scaleY + '-' + pixelRatio;
1211
1216
  if (paint.patternId !== id && !ui.destroyed) {
1212
1217
  scaleX = abs$1(scaleX);
1213
1218
  scaleY = abs$1(scaleY);
@@ -1269,7 +1274,8 @@ function createPattern(ui, paint, pixelRatio) {
1269
1274
  const { abs } = Math;
1270
1275
  function checkImage(ui, canvas, paint, allowPaint) {
1271
1276
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1272
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY && !Export.running)) {
1277
+ const { pixelRatio } = canvas;
1278
+ if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1273
1279
  return false;
1274
1280
  }
1275
1281
  else {
@@ -1277,8 +1283,8 @@ function checkImage(ui, canvas, paint, allowPaint) {
1277
1283
  if (allowPaint) {
1278
1284
  if (!data.repeat) {
1279
1285
  let { width, height } = data;
1280
- width *= abs(scaleX) * canvas.pixelRatio;
1281
- height *= abs(scaleY) * canvas.pixelRatio;
1286
+ width *= abs(scaleX) * pixelRatio;
1287
+ height *= abs(scaleY) * pixelRatio;
1282
1288
  if (data.scaleX) {
1283
1289
  width *= data.scaleX;
1284
1290
  height *= data.scaleY;
@@ -1303,15 +1309,15 @@ function checkImage(ui, canvas, paint, allowPaint) {
1303
1309
  return true;
1304
1310
  }
1305
1311
  else {
1306
- if (!paint.style || Export.running) {
1307
- createPattern(ui, paint, canvas.pixelRatio);
1312
+ if (!paint.style || paint.sync || Export.running) {
1313
+ createPattern(ui, paint, pixelRatio);
1308
1314
  }
1309
1315
  else {
1310
1316
  if (!paint.patternTask) {
1311
1317
  paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1312
1318
  paint.patternTask = null;
1313
1319
  if (canvas.bounds.hit(ui.__nowWorld))
1314
- createPattern(ui, paint, canvas.pixelRatio);
1320
+ createPattern(ui, paint, pixelRatio);
1315
1321
  ui.forceUpdate('surface');
1316
1322
  }), 300);
1317
1323
  }
@@ -1375,14 +1381,16 @@ function linearGradient(paint, box) {
1375
1381
  return data;
1376
1382
  }
1377
1383
  function applyStops(gradient, stops, opacity) {
1378
- let stop;
1379
- for (let i = 0, len = stops.length; i < len; i++) {
1380
- stop = stops[i];
1381
- if (typeof stop === 'string') {
1382
- gradient.addColorStop(i / (len - 1), ColorConvert.string(stop, opacity));
1383
- }
1384
- else {
1385
- gradient.addColorStop(stop.offset, ColorConvert.string(stop.color, opacity));
1384
+ if (stops) {
1385
+ let stop;
1386
+ for (let i = 0, len = stops.length; i < len; i++) {
1387
+ stop = stops[i];
1388
+ if (typeof stop === 'string') {
1389
+ gradient.addColorStop(i / (len - 1), ColorConvert.string(stop, opacity));
1390
+ }
1391
+ else {
1392
+ gradient.addColorStop(stop.offset, ColorConvert.string(stop.color, opacity));
1393
+ }
1386
1394
  }
1387
1395
  }
1388
1396
  }
@@ -2138,10 +2146,15 @@ const TextConvertModule = {
2138
2146
  };
2139
2147
 
2140
2148
  function string(color, opacity) {
2141
- if (typeof color === 'string')
2142
- return color;
2149
+ const doOpacity = typeof opacity === 'number' && opacity !== 1;
2150
+ if (typeof color === 'string') {
2151
+ if (doOpacity && ColorConvert.object)
2152
+ color = ColorConvert.object(color);
2153
+ else
2154
+ return color;
2155
+ }
2143
2156
  let a = color.a === undefined ? 1 : color.a;
2144
- if (opacity)
2157
+ if (doOpacity)
2145
2158
  a *= opacity;
2146
2159
  const rgb = color.r + ',' + color.g + ',' + color.b;
2147
2160
  return a === 1 ? 'rgb(' + rgb + ')' : 'rgba(' + rgb + ',' + a + ')';
@@ -2173,6 +2186,7 @@ const ExportModule = {
2173
2186
  export(leaf, filename, options) {
2174
2187
  this.running = true;
2175
2188
  const fileType = FileHelper.fileType(filename);
2189
+ const isDownload = filename.includes('.');
2176
2190
  options = FileHelper.getExportOptions(options);
2177
2191
  return addTask((success) => new Promise((resolve) => {
2178
2192
  const over = (result) => {
@@ -2182,19 +2196,13 @@ const ExportModule = {
2182
2196
  };
2183
2197
  const { toURL } = Platform;
2184
2198
  const { download } = Platform.origin;
2185
- if (filename === 'json') {
2186
- return over({ data: leaf.toJSON(options.json) });
2199
+ if (fileType === 'json') {
2200
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
2201
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
2187
2202
  }
2188
- else if (fileType === 'json') {
2189
- download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
2190
- return over({ data: true });
2191
- }
2192
- if (filename === 'svg') {
2193
- return over({ data: leaf.toSVG() });
2194
- }
2195
- else if (fileType === 'svg') {
2196
- download(toURL(leaf.toSVG(), 'svg'), filename);
2197
- return over({ data: true });
2203
+ if (fileType === 'svg') {
2204
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
2205
+ return over({ data: isDownload ? true : leaf.toSVG() });
2198
2206
  }
2199
2207
  const { leafer } = leaf;
2200
2208
  if (leafer) {
@@ -2203,14 +2211,8 @@ const ExportModule = {
2203
2211
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
2204
2212
  const { worldTransform, isLeafer, isFrame } = leaf;
2205
2213
  const { slice, trim, onCanvas } = options;
2206
- let scale = options.scale || 1;
2207
- let pixelRatio = options.pixelRatio || 1;
2208
2214
  const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
2209
2215
  const contextSettings = options.contextSettings || leafer.config.contextSettings;
2210
- if (leaf.isApp) {
2211
- scale *= pixelRatio;
2212
- pixelRatio = leaf.app.pixelRatio;
2213
- }
2214
2216
  const screenshot = options.screenshot || leaf.isApp;
2215
2217
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
2216
2218
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
@@ -2244,9 +2246,17 @@ const ExportModule = {
2244
2246
  }
2245
2247
  renderBounds = leaf.getBounds('render', relative);
2246
2248
  }
2247
- const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
2249
+ const scaleData = { scaleX: 1, scaleY: 1 };
2250
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
2251
+ let pixelRatio = options.pixelRatio || 1;
2252
+ if (leaf.isApp) {
2253
+ scaleData.scaleX *= pixelRatio;
2254
+ scaleData.scaleY *= pixelRatio;
2255
+ pixelRatio = leaf.app.pixelRatio;
2256
+ }
2257
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
2258
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
2248
2259
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
2249
- const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
2250
2260
  let sliceLeaf;
2251
2261
  if (slice) {
2252
2262
  sliceLeaf = leaf;
@@ -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 _,Bounds as p,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,AlignHelper as E,ImageEvent as S,AroundHelper as L,PointHelper as A,Direction4 as W,TwoPointBoundsHelper as O,TaskProcessor as T,Matrix as M}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{writeFileSync as C}from"fs";import{PaintImage as D,ColorConvert as I,PaintGradient as P,Export as F,Group as U,TextConvert as N,Paint as Y,Effect as G}from"@leafer-ui/draw";export*from"@leafer-ui/draw";function j(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;class V extends t{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config),e.roundRectPatch&&(this.context.__proto__.roundRect=null,n(this.context.__proto__))}__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}}const{mineType:X,fileType:q}=a;function z(t,n){if(e.canvasType=t,!e.origin){if("skia"===t){const{Canvas:t,loadImage:i}=n;e.origin={createCanvas:(e,n,i)=>new t(e,n,i),canvasToDataURL:(t,e,n)=>t.toDataURLSync(e,{quality:n}),canvasToBolb:(t,e,n)=>t.toBuffer(e,{quality:n}),canvasSaveAs:(t,e,n)=>t.saveAs(e,{quality:n}),download(t,e){},loadImage:t=>i(e.image.getRealURL(t))},e.roundRectPatch=!0}else if("napi"===t){const{Canvas:t,loadImage:i}=n;e.origin={createCanvas:(e,n,i)=>new t(e,n,i),canvasToDataURL:(t,e,n)=>t.toDataURL(X(e),n),canvasToBolb:(t,e,n)=>j(this,void 0,void 0,(function*(){return t.toBuffer(X(e),n)})),canvasSaveAs:(t,e,n)=>j(this,void 0,void 0,(function*(){return C(e,t.toBuffer(X(q(e)),n))})),download(t,e){},loadImage:t=>i(e.image.getRealURL(t))}}e.ellipseToCurve=!0,e.event={stopDefault(t){},stopNow(t){},stop(t){}},e.canvas=i.canvas()}}Object.assign(i,{canvas:(t,e)=>new V(t,e),image:t=>new s(t)}),e.name="node",e.requestRender=function(t){setTimeout(t)},o(e,"devicePixelRatio",{get:()=>1}),e.conicGradientSupport=!0;class H{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:Q,updateBounds:J,updateAllWorldOpacity:Z}=f,{pushAllChildBranch:$,pushAllParent:K}=_;const{worldBounds:tt}=g,et={x:0,y:0,width:1e5,height:1e5};class nt{constructor(t){this.updatedBounds=new p,this.beforeBounds=new p,this.afterBounds=new p,t instanceof Array&&(t=new r(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,tt)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(et):this.afterBounds.setListWithFn(t,tt),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:it,updateAllChange:st}=f,ot=w.get("Layouter");class at{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){ot.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ot.warn("layouting"):this.times>3?ot.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(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?(Q(t,!0),e.add(t),t.isBranch&&$(t,e),K(t,e)):n.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),K(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||J(i[t])}J(n)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&Z(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)),at.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){it(t,!0),t.isBranch?_.updateBounds(t):f.updateBounds(t),st(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:n}=this.extraBlock||(this.extraBlock=new nt([]));e.length?n.add(t.__world):n.set(t.__world),e.add(t)}}createBlock(t){return new nt(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(m.REQUEST,this.layout,this),t.on_(m.AGAIN,this.layoutAgain,this),t.on_(h.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const rt=w.get("Renderer");class dt{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 p,rt.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,rt.error(t)}rt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return rt.warn("rendering");if(this.times>3)return rt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new p,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 rt.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 p(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 p;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 p(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 p(0,0,1,1)),this.changed=!0}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||rt.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,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 lt(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 ct(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?ft(t,!0,e,n):ut(e,n);break;case"inside":ht("inside",t,s,e,n);break;case"outside":ht("outside",t,s,e,n)}}function ht(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?ft(e,!0,i,r):ut(i,r),r.blendMode="outside"===t?"destination-out":"destination-in",lt(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 ut(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 ft(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?ut(n,i):i.stroke(),i.restoreBlendMode()):e?ut(n,i):i.stroke())}Object.assign(i,{watcher:(t,e)=>new H(t,e),layouter:(t,e)=>new at(t,e),renderer:(t,e,n)=>new dt(t,e,n),selector:(t,e)=>{},interaction:(t,e,n,i)=>{}}),e.layout=at.fullLayout;const{getSpread:_t,getOuterOf:pt,getByMove:gt,getIntersectData:wt}=R;let yt;function mt(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,!yt||!yt[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 vt={compute:function(t,e){const n=e.__,i=[];let s,o=n.__input[t];o instanceof Array||(o=[o]),yt=D.recycleImage(t,n);for(let n,s=0,a=o.length;s<a;s++)n=mt(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?lt(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?lt(e,n):s?n.fill(s):n.fill(),n.restore()):i.blendMode?(n.saveBlendMode(i.blendMode),o?lt(e,n):s?n.fill(s):n.fill(),n.restoreBlendMode()):o?lt(e,n):s?n.fill(s):n.fill())},fillText:lt,stroke:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)ct(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)ct(t,e,n);else switch(o){case"center":n.setStroke(void 0,s,i),ft(t,!1,e,n);break;case"inside":n.save(),n.setStroke(void 0,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),ft(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),ft(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:ct,drawTextStroke:ut,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=wt(i?_t(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=gt(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 xt={};const{get:bt,rotateOfOuter:Bt,translate:Rt,scaleOfOuter:kt,scale:Et,rotate:St}=k;function Lt(t,e,n,i,s,o,a){const r=bt();Rt(r,e.x+n,e.y+i),Et(r,s,o),a&&Bt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function At(t,e,n,i,s,o,a){const r=bt();Rt(r,e.x+n,e.y+i),s&&Et(r,s,o),a&&St(r,a),t.transform=r}function Wt(t,e,n,i,s,o,a,r,d,l){const c=bt();if(d)if("center"===l)Bt(c,{x:n/2,y:i/2},d);else switch(St(c,d),d){case 90:Rt(c,i,0);break;case 180:Rt(c,n,i);break;case 270:Rt(c,0,n)}xt.x=e.x+s,xt.y=e.y+o,Rt(c,xt.x,xt.y),a&&kt(c,xt,a,r),t.transform=c}const{get:Ot,translate:Tt}=k,Mt=new p,Ct={};function Dt(t,e,n,i){const{blendMode:s}=n;s&&(t.blendMode=s),t.data=It(n,i,e)}function It(t,e,n){let{width:i,height:s}=n;t.padding&&(e=Mt.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,_={mode:a},p="center"!==r&&(h||0)%180==90,g=p?s:i,w=p?i:s;let y,m,v=0,x=0;if(a&&"cover"!==a&&"fit"!==a)c?(y=("number"==typeof c?c:c.width)/i,m=("number"==typeof c?c:c.height)/s):l&&(y="number"==typeof l?l:l.x,m="number"==typeof l?l:l.y);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),E.toPoint(r,t,e,Ct,!0),v+=Ct.x,x+=Ct.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)&&At(_,e,v,x,y,m,h);break;case"repeat":(!f||y||h)&&Wt(_,e,i,s,v,x,y,m,h,r),u||(_.repeat="repeat");break;default:y&&Lt(_,e,v,x,y,m,h)}return _.transform||(e.x||e.y)&&(_.transform=Ot(),Tt(_.transform,e.x,e.y)),y&&"strench"!==a&&(_.scaleX=y,_.scaleY=m),_.width=i,_.height=s,o&&(_.opacity=o),u&&(_.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),_}let Pt,Ft=new p;const{isSame:Ut}=R;function Nt(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 Yt(t,e){Vt(t,S.LOAD,e)}function Gt(t,e){Vt(t,S.LOADED,e)}function jt(t,e,n){e.error=n,t.forceUpdate("surface"),Vt(t,S.ERROR,e)}function Vt(t,e,n){t.hasEvent(e)&&t.emitEvent(new S(e,n))}function Xt(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:_,transform:p,repeat:g}=r;u&&(l=qt(),Ht(l,p),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),(p||1!==s||1!==o)&&(l||(l=qt(),p&&Ht(l,p)),zt(l,1/s,1/o));const m=t.getCanvas(Qt(c)||1,Qt(h)||1,_),v=t.getPattern(m,g||e.origin.noRepeat||"no-repeat",l,n);return n.style=v,n.patternId=a,!0}}const{abs:$t}=Math;const Kt={image:function(t,e,n,i,s){let o,a;const r=x.get(n);return Pt&&n===Pt.paint&&Ut(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?(Nt(t,e,n,r,o,i),s&&(Yt(t,a),Gt(t,a))):r.error?s&&jt(t,a,r.error):(Xt(t,!0),s&&Yt(t,a),o.loadId=r.load((()=>{Xt(t,!1),t.destroyed||(Nt(t,e,n,r,o,i)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),Gt(t,a)),o.loadId=null}),(e=>{Xt(t,!1),jt(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*=$t(o)*n.pixelRatio,i*=$t(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||F.running?Zt(t,i,n.pixelRatio):i.patternTask||(i.patternTask=x.patternTasker.add((()=>j(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:Lt,clipMode:At,repeatMode:Wt},{toPoint:te}=L,ee={},ne={};function ie(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:se,getDistance:oe}=A,{get:ae,rotateOfOuter:re,scaleOfOuter:de}=k,{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}=A,{toPoint:_e}=L,pe={},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;_e(i||"center",n,pe),_e(s||"bottom",n,ge);const l=e.conicGradientSupport?e.canvas.createConicGradient(0,pe.x,pe.y):e.canvas.createRadialGradient(pe.x,pe.y,0,pe.x,pe.y,fe(pe,ge));ie(l,t.stops,a);const c={type:o,style:l},h=ue(n,pe,ge,d||1,e.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:ue},{copy:ye,toOffsetOutBounds:me}=R,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}=R,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(),_=r.length-1;me(l,xe),r.forEach(((r,p)=>{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<_&&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(),_=r.length-1;Be(l,Re),r.forEach(((r,p)=>{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<_&&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:Ee}=g;function Se(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),Ae(t,e,n,1)}(t,n,i,s);break;case"opacity-path":Ae(t,n,i,o);break;case"path":n.restore()}}function Le(t){return t.getSameCanvas(!1,!0)}function Ae(t,e,n,i){const s=t.__nowWorld;e.resetTransform(),e.opacity=i,e.copyWorld(n,s),n.recycle(s)}U.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&&(Se(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)||Ee(n,e)||n.__render(s||t,e);Se(this,a,t,s,i,o)};const We=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Oe=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(Oe),Fe=Me("- —/~|┆·");var Ue;!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"}(Ue||(Ue={}));const{Letter:Ne,Single:Ye,Before:Ge,After:je,Symbol:Ve,Break:Xe}=Ue;function qe(t){return Ce[t]?Ne:Fe[t]?Xe:De[t]?Ge:Ie[t]?je:Pe[t]?Ve:Te.test(t)?Ye:Ne}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}=Ue;let nn,sn,on,an,rn,dn,ln,cn,hn,un,fn,_n,pn,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:En,right:Sn,bottom:Ln,left:An}=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 On={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[An],o-=l[Sn]+l[An]),a&&(s=l[En],a-=l[En]+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),_n=un===Ze&&(fn===Ze||fn===Je)||fn===Ze&&un!==Ke,pn=!(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()):(pn||(pn=un===Je&&fn==Ke),_n||pn||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()):_n||pn?(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[An]);break;case"right":Wn(e,"x",-t[Sn])}if(!s)switch(n.verticalAlign){case"top":Wn(e,"y",t[En]);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:_,y:p,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":p+=(w-y)/2;break;case"bottom":p+=w-y}m+=p;for(let o=0,l=n.length;o<l;o++){if(h=n[o],h.x=_,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=p,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){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:Mn,addPoint:Cn,toBounds:Dn}=O;const In={export(t,n,s){this.running=!0;const o=a.fileType(n);return s=a.getExportOptions(s),function(t){Pn||(Pn=new T);return new Promise((e=>{Pn.add((()=>j(this,void 0,void 0,(function*(){return yield t(e)}))),{parallel:!1})}))}((r=>new Promise((d=>{const l=t=>{r(t),d(),this.running=!1},{toURL:c}=e,{download:h}=e.origin;if("json"===n)return l({data:t.toJSON(s.json)});if("json"===o)return h(c(JSON.stringify(t.toJSON(s.json)),"text"),n),l({data:!0});if("svg"===n)return l({data:t.toSVG()});if("svg"===o)return h(c(t.toSVG(),"svg"),n),l({data:!0});const{leafer:u}=t;u?(Fn(t),u.waitViewCompleted((()=>j(this,void 0,void 0,(function*(){let e,o,r=1,d=1;const{worldTransform:c,isLeafer:h,isFrame:f}=t,{slice:_,trim:g,onCanvas:w}=s;let y=s.scale||1,m=s.pixelRatio||1;const v=void 0===s.smooth?u.config.smooth:s.smooth,x=s.contextSettings||u.config.contextSettings;t.isApp&&(y*=m,m=t.app.pixelRatio);const b=s.screenshot||t.isApp,B=h&&b&&void 0===s.fill?t.fill:s.fill,R=a.isOpaqueImage(n)||B,k=new M;if(b)e=!0===b?h?u.canvas.bounds:t.worldRenderBounds:b;else{let n=s.relative||(h?"inner":"local");switch(r=c.scaleX,d=c.scaleY,n){case"inner":k.set(c);break;case"local":k.set(c).divide(t.localTransform),r/=t.scaleX,d/=t.scaleY;break;case"world":r=1,d=1;break;case"page":n=t.leafer;default:k.set(c).divide(t.getTransform(n));const e=n.worldTransform;r/=r/e.scaleX,d/=d/e.scaleY}e=t.getBounds("render",n)}const{x:E,y:S,width:L,height:A}=new p(e).scale(y);let W=i.canvas({width:Math.round(L),height:Math.round(A),pixelRatio:m,smooth:v,contextSettings:x});const O={matrix:k.scale(1/y).invert().translate(-E,-S).withScale(1/r*y,1/d*y)};let T;if(_&&(T=t,T.__worldOpacity=0,t=u,O.bounds=W.bounds),W.save(),f&&void 0!==B){const e=t.get("fill");t.fill="",t.__render(W,O),t.fill=e}else t.__render(W,O);if(W.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 p;return Dn(a,d),d.scale(1/t.pixelRatio).ceil()}(W);const t=W,{width:e,height:n}=o,s={x:0,y:0,width:e,height:n,pixelRatio:m};W=i.canvas(s),W.copyWorld(t,o,s)}R&&W.fillWorld(W.bounds,B||"#FFFFFF","destination-over"),w&&w(W);const C="canvas"===n?W:yield W.export(n,s);l({data:C,width:W.pixelWidth,height:W.pixelHeight,renderBounds:e,trimBounds:o})}))))):l({data:!1})}))))}};let Pn;function Fn(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Fn(t)))}const Un=t.prototype,Nn=w.get("@leafer-ui/export");Un.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)},Un.toBlob=function(t,n){return new Promise((i=>{e.origin.canvasToBolb(this.view,t,n).then((t=>{i(t)})).catch((t=>{Nn.error(t),i(null)}))}))},Un.toDataURL=function(t,n){return e.origin.canvasToDataURL(this.view,t,n)},Un.saveAs=function(t,n){return new Promise((i=>{e.origin.canvasSaveAs(this.view,t,n).then((()=>{i(!0)})).catch((t=>{Nn.error(t),i(!1)}))}))},Object.assign(N,On),Object.assign(I,Tn),Object.assign(Y,vt),Object.assign(D,Kt),Object.assign(P,we),Object.assign(G,ke),Object.assign(F,In);export{at as Layouter,V as LeaferCanvas,dt as Renderer,H as Watcher,z 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 _,Bounds as p,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 A,Direction4 as W,TwoPointBoundsHelper as O,TaskProcessor as T,Matrix as C}from"@leafer/core";export*from"@leafer/core";export{LeaferImage}from"@leafer/core";import{writeFileSync as M}from"fs";import{PaintImage as D,ColorConvert as I,PaintGradient as P,Export as F,Group as Y,TextConvert as U,Paint as X,Effect as N}from"@leafer-ui/draw";export*from"@leafer-ui/draw";function j(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;class G extends t{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config),e.roundRectPatch&&(this.context.__proto__.roundRect=null,n(this.context.__proto__))}__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}}const{mineType:V,fileType:q}=a;function z(t,n){if(e.canvasType=t,!e.origin){if("skia"===t){const{Canvas:t,loadImage:i}=n;e.origin={createCanvas:(e,n,i)=>new t(e,n,i),canvasToDataURL:(t,e,n)=>t.toDataURLSync(e,{quality:n}),canvasToBolb:(t,e,n)=>t.toBuffer(e,{quality:n}),canvasSaveAs:(t,e,n)=>t.saveAs(e,{quality:n}),download(t,e){},loadImage:t=>i(e.image.getRealURL(t))},e.roundRectPatch=!0}else if("napi"===t){const{Canvas:t,loadImage:i}=n;e.origin={createCanvas:(e,n,i)=>new t(e,n,i),canvasToDataURL:(t,e,n)=>t.toDataURL(V(e),n),canvasToBolb:(t,e,n)=>j(this,void 0,void 0,(function*(){return t.toBuffer(V(e),n)})),canvasSaveAs:(t,e,n)=>j(this,void 0,void 0,(function*(){return M(e,t.toBuffer(V(q(e)),n))})),download(t,e){},loadImage:t=>i(e.image.getRealURL(t))}}e.ellipseToCurve=!0,e.event={stopDefault(t){},stopNow(t){},stop(t){}},e.canvas=i.canvas()}}Object.assign(i,{canvas:(t,e)=>new G(t,e),image:t=>new s(t)}),e.name="node",e.requestRender=function(t){setTimeout(t)},o(e,"devicePixelRatio",{get:()=>1}),e.conicGradientSupport=!0;class H{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:Q,updateBounds:J,updateAllWorldOpacity:Z}=f,{pushAllChildBranch:$,pushAllParent:K}=_;const{worldBounds:tt}=g,et={x:0,y:0,width:1e5,height:1e5};class nt{constructor(t){this.updatedBounds=new p,this.beforeBounds=new p,this.afterBounds=new p,t instanceof Array&&(t=new r(t)),this.updatedList=t}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,tt)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(et):this.afterBounds.setListWithFn(t,tt),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:it,updateAllChange:st}=f,ot=w.get("Layouter");class at{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){ot.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?ot.warn("layouting"):this.times>3?ot.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(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?(Q(t,!0),e.add(t),t.isBranch&&$(t,e),K(t,e)):n.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),K(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||J(i[t])}J(n)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&Z(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)),at.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){it(t,!0),t.isBranch?_.updateBounds(t):f.updateBounds(t),st(t)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:n}=this.extraBlock||(this.extraBlock=new nt([]));e.length?n.add(t.__world):n.set(t.__world),e.add(t)}}createBlock(t){return new nt(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:t}=this;this.__eventIds=[t.on_(m.REQUEST,this.layout,this),t.on_(m.AGAIN,this.layoutAgain,this),t.on_(h.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const rt=w.get("Renderer");class dt{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 p,rt.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,rt.error(t)}rt.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(t){if(this.rendering)return rt.warn("rendering");if(this.times>3)return rt.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new p,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 rt.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 p(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 p;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 p(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 p(0,0,1,1)),this.changed=!0}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||rt.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(t,e,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 lt(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 ct(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?ft(t,!0,e,n):ut(e,n);break;case"inside":ht("inside",t,s,e,n);break;case"outside":ht("outside",t,s,e,n)}}function ht(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?ft(e,!0,i,r):ut(i,r),r.blendMode="outside"===t?"destination-out":"destination-in",lt(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 ut(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 ft(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?ut(n,i):i.stroke(),i.restoreBlendMode()):e?ut(n,i):i.stroke())}Object.assign(i,{watcher:(t,e)=>new H(t,e),layouter:(t,e)=>new at(t,e),renderer:(t,e,n)=>new dt(t,e,n),selector:(t,e)=>{},interaction:(t,e,n,i)=>{}}),e.layout=at.fullLayout;const{getSpread:_t,getOuterOf:pt,getByMove:gt,getIntersectData:wt}=B;let yt;function mt(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,!yt||!yt[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 vt={compute:function(t,e){const n=e.__,i=[];let s,o=n.__input[t];o instanceof Array||(o=[o]),yt=D.recycleImage(t,n);for(let n,s=0,a=o.length;s<a;s++)n=mt(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?lt(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?lt(e,n):s?n.fill(s):n.fill(),n.restore()):i.blendMode?(n.saveBlendMode(i.blendMode),o?lt(e,n):s?n.fill(s):n.fill(),n.restoreBlendMode()):o?lt(e,n):s?n.fill(s):n.fill())},fillText:lt,stroke:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)ct(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)ct(t,e,n);else switch(o){case"center":n.setStroke(void 0,s,i),ft(t,!1,e,n);break;case"inside":n.save(),n.setStroke(void 0,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),ft(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),ft(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:ct,drawTextStroke:ut,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=wt(i?_t(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=gt(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 xt={};const{get:bt,rotateOfOuter:Bt,translate:Rt,scaleOfOuter:kt,scale:St,rotate:Et}=R;function Lt(t,e,n,i,s,o,a){const r=bt();Rt(r,e.x+n,e.y+i),St(r,s,o),a&&Bt(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function At(t,e,n,i,s,o,a){const r=bt();Rt(r,e.x+n,e.y+i),s&&St(r,s,o),a&&Et(r,a),t.transform=r}function Wt(t,e,n,i,s,o,a,r,d,l){const c=bt();if(d)if("center"===l)Bt(c,{x:n/2,y:i/2},d);else switch(Et(c,d),d){case 90:Rt(c,i,0);break;case 180:Rt(c,n,i);break;case 270:Rt(c,0,n)}xt.x=e.x+s,xt.y=e.y+o,Rt(c,xt.x,xt.y),a&&kt(c,xt,a,r),t.transform=c}const{get:Ot,translate:Tt}=R,Ct=new p,Mt={},Dt={};function It(t,e,n,i){const{blendMode:s,sync:o}=n;s&&(t.blendMode=s),o&&(t.sync=o),t.data=Pt(n,i,e)}function Pt(t,e,n){let{width:i,height:s}=n;t.padding&&(e=Ct.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,_={mode:a},p="center"!==r&&(h||0)%180==90,g=p?s:i,w=p?i:s;let y,m,v=0,x=0;if(a&&"cover"!==a&&"fit"!==a)(l||c)&&(k.getScaleData(l,c,n,Dt),y=Dt.scaleX,m=Dt.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"stretch":f||(i=e.width,s=e.height);break;case"normal":case"clip":(v||x||y||h)&&At(_,e,v,x,y,m,h);break;case"repeat":(!f||y||h)&&Wt(_,e,i,s,v,x,y,m,h,r),u||(_.repeat="repeat");break;default:y&&Lt(_,e,v,x,y,m,h)}return _.transform||(e.x||e.y)&&(_.transform=Ot(),Tt(_.transform,e.x,e.y)),y&&"stretch"!==a&&(_.scaleX=y,_.scaleY=m),_.width=i,_.height=s,o&&(_.opacity=o),u&&(_.repeat="string"==typeof u?"x"===u?"repeat-x":"repeat-y":"repeat"),_}let Ft,Yt=new p;const{isSame:Ut}=B;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||It(s,i,n,o),!0}function Nt(t,e){Vt(t,E.LOAD,e)}function jt(t,e){Vt(t,E.LOADED,e)}function Gt(t,e,n){e.error=n,t.forceUpdate("surface"),Vt(t,E.ERROR,e)}function Vt(t,e,n){t.hasEvent(e)&&t.emitEvent(new E(e,n))}function qt(t,e){const{leafer:n}=t;n&&n.viewReady&&(n.renderer.ignore=e)}const{get:zt,scale:Ht,copy:Qt}=R,{ceil:Jt,abs:Zt}=Math;function $t(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=Zt(s),o=Zt(o);const{image:t,data:r}=n;let d,l,{width:c,height:h,scaleX:u,scaleY:f,opacity:_,transform:p,repeat:g}=r;u&&(l=zt(),Qt(l,p),Ht(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),(p||1!==s||1!==o)&&(l||(l=zt(),p&&Qt(l,p)),Ht(l,1/s,1/o));const m=t.getCanvas(Jt(c)||1,Jt(h)||1,_),v=t.getPattern(m,g||e.origin.noRepeat||"no-repeat",l,n);return n.style=v,n.patternId=a,!0}}const{abs:Kt}=Math;const te={image:function(t,e,n,i,s){let o,a;const r=x.get(n);return Ft&&n===Ft.paint&&Ut(i,Ft.boxBounds)?o=Ft.leafPaint:(o={type:n.type,image:r},Ft=r.use>1?{leafPaint:o,paint:n,boxBounds:Yt.set(i)}:null),(s||r.loading)&&(a={image:r,attrName:e,attrValue:n}),r.ready?(Xt(t,e,n,r,o,i),s&&(Nt(t,a),jt(t,a))):r.error?s&&Gt(t,a,r.error):(qt(t,!0),s&&Nt(t,a),o.loadId=r.load((()=>{qt(t,!1),t.destroyed||(Xt(t,e,n,r,o,i)&&(r.hasOpacityPixel&&(t.__layout.hitCanvasChanged=!0),t.forceUpdate("surface")),jt(t,a)),o.loadId=null}),(e=>{qt(t,!1),Gt(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&&!F.running)return!1;{const{data:d}=i;if(s)if(d.repeat)s=!1;else{let{width:t,height:n}=d;t*=Kt(o)*r,n*=Kt(a)*r,d.scaleX&&(t*=d.scaleX,n*=d.scaleY),s=t*n>e.image.maxCacheSize||F.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||F.running?$t(t,i,r):i.patternTask||(i.patternTask=x.patternTasker.add((()=>j(this,void 0,void 0,(function*(){i.patternTask=null,n.bounds.hit(t.__nowWorld)&&$t(t,i,r),t.forceUpdate("surface")}))),300)),!1)}},createPattern:$t,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:It,getPatternData:Pt,fillOrFitMode:Lt,clipMode:At,repeatMode:Wt},{toPoint:ee}=L,ne={},ie={};function se(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),I.string(i,n)):t.addColorStop(i.offset,I.string(i.color,n))}}const{getAngle:oe,getDistance:ae}=A,{get:re,rotateOfOuter:de,scaleOfOuter:le}=R,{toPoint:ce}=L,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:_e}=A,{toPoint:pe}=L,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;pe(i||"center",n,ge),pe(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,_e(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}=B,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}=B,ke={};const Se={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(),_=r.length-1;ve(l,be),r.forEach(((r,p)=>{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<_&&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(),_=r.length-1;Re(l,ke),r.forEach(((r,p)=>{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<_&&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:Ee}=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 Ae(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=Ae(t))):(a="path",t.save()),n.__clip(s||t,e)):(a="alpha",i||(i=Ae(t)),s||(s=Ae(t)),n.__render(i,e)),"clipping"!==n.__.mask)||Ee(n,e)||n.__render(s||t,e);Le(this,a,t,s,i,o)};const Oe=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Te=Oe+"_#~&*+\\=|≮≯≈≠=…",Ce=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 De=Me("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Ie=Me("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Pe=Me(Oe),Fe=Me(Te),Ye=Me("- —/~|┆·");var Ue;!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"}(Ue||(Ue={}));const{Letter:Xe,Single:Ne,Before:je,After:Ge,Symbol:Ve,Break:qe}=Ue;function ze(t){return De[t]?Xe:Ye[t]?qe:Ie[t]?je:Pe[t]?Ge:Fe[t]?Ve:Ce.test(t)?Ne:Xe}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}=Ue;let sn,on,an,rn,dn,ln,cn,hn,un,fn,_n,pn,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,Sn=2;const{top:En,right:Ln,bottom:An,left:Wn}=W;function On(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[En],a-=l[En]+l[An]));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,_n=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),pn=fn===$e&&(_n===$e||_n===Ze)||_n===$e&&fn!==tn,gn=!(fn!==Ke&&fn!==$e||_n!==en&&_n!==tn),dn=wn&&o?d-o:d,t&&d&&rn+an+cn>dn&&(e?(an&&bn(),rn&&Bn()):(gn||(gn=fn===Ze&&_n==tn),pn||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()):pn||gn?(an&&bn(),xn(ln,cn)):xn(ln,cn)),_n=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":On(e,"x",t[Wn]);break;case"right":On(e,"x",-t[Ln])}if(!s)switch(n.verticalAlign){case"top":On(e,"y",t[En]);break;case"bottom":On(e,"y",-t[An])}}(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:_,y:p,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":p+=(w-y)/2;break;case"bottom":p+=w-y}m+=p;for(let o=0,l=n.length;o<l;o++){if(h=n[o],h.x=_,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=p,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:Sn,t.isOverflow&&!r&&(t.textMode=!0),h===Sn?(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 Cn={string:function(t,e){const n="number"==typeof e&&1!==e;if("string"==typeof t){if(!n||!I.object)return t;t=I.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:Dn,toBounds:In}=O;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 T);return new Promise((e=>{Fn.add((()=>j(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((()=>j(this,void 0,void 0,(function*(){let e,o,r=1,d=1;const{worldTransform:l,isLeafer:h,isFrame:u}=t,{slice:_,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};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:A,height:W}=new p(e).scale(R.scaleX,R.scaleY),O={matrix:B.scale(1/R.scaleX,1/R.scaleY).invert().translate(-E,-L).withScale(1/r*R.scaleX,1/d*R.scaleY)};let T,M=i.canvas({width:Math.round(A),height:Math.round(W),pixelRatio:S,smooth:y,contextSettings:m});if(_&&(T=t,T.__worldOpacity=0,t=f,O.bounds=M.bounds),M.save(),u&&void 0!==x){const e=t.get("fill");t.fill="",t.__render(M,O),t.fill=e}else t.__render(M,O);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):Mn(a={},s,o)),r++;const d=new p;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:S};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 Un=t.prototype,Xn=w.get("@leafer-ui/export");Un.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)},Un.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)}))}))},Un.toDataURL=function(t,n){return e.origin.canvasToDataURL(this.view,t,n)},Un.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(U,Tn),Object.assign(I,Cn),Object.assign(X,vt),Object.assign(D,te),Object.assign(P,ye),Object.assign(N,Se),Object.assign(F,Pn);export{at as Layouter,G as LeaferCanvas,dt as Renderer,H as Watcher,z as useCanvas};
package/dist/node.min.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("@leafer/core"),e=require("fs"),n=require("@leafer-ui/draw");function i(t,e,n,i){return new(n||(n=Promise))((function(o,a){function s(t){try{d(i.next(t))}catch(t){a(t)}}function r(t){try{d(i.throw(t))}catch(t){a(t)}}function d(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,r)}d((i=i.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class o extends t.LeaferCanvasBase{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config),t.Platform.roundRectPatch&&(this.context.__proto__.roundRect=null,t.canvasPatch(this.context.__proto__))}__createView(){this.view=t.Platform.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}}const{mineType:a,fileType:s}=t.FileHelper;Object.assign(t.Creator,{canvas:(t,e)=>new o(t,e),image:e=>new t.LeaferImage(e)}),t.Platform.name="node",t.Platform.requestRender=function(t){setTimeout(t)},t.defineKey(t.Platform,"devicePixelRatio",{get:()=>1}),t.Platform.conicGradientSupport=!0;class r{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const e=new t.LeafList;return this.__updatedList.list.forEach((t=>{t.leafer&&e.add(t)})),e}return this.__updatedList}constructor(e,n){this.totalTimes=0,this.config={},this.__updatedList=new t.LeafList,this.target=e,n&&(this.config=t.DataHelper.default(n,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(t.RenderEvent.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(e){e.type===t.ChildEvent.ADD?(this.hasAdd=!0,this.__pushChild(e.child)):(this.hasRemove=!0,this.__updatedList.add(e.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 t.WatchEvent(t.WatchEvent.DATA,{updatedList:this.updatedList})),this.__updatedList=new t.LeafList,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:e}=this;this.__eventIds=[e.on_(t.PropertyEvent.CHANGE,this.__onAttrChange,this),e.on_([t.ChildEvent.ADD,t.ChildEvent.REMOVE],this.__onChildEvent,this),e.on_(t.WatchEvent.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:d,updateBounds:l,updateAllWorldOpacity:c}=t.LeafHelper,{pushAllChildBranch:h,pushAllParent:u}=t.BranchHelper;const{worldBounds:f}=t.LeafBoundsHelper,p={x:0,y:0,width:1e5,height:1e5};class g{constructor(e){this.updatedBounds=new t.Bounds,this.beforeBounds=new t.Bounds,this.afterBounds=new t.Bounds,e instanceof Array&&(e=new t.LeafList(e)),this.updatedList=e}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,f)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(p):this.afterBounds.setListWithFn(t,f),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:_,updateAllChange:w}=t.LeafHelper,m=t.Debug.get("Layouter");class y{constructor(e,n){this.totalTimes=0,this.config={},this.__levelList=new t.LeafLevelList,this.target=e,n&&(this.config=t.DataHelper.default(n,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:e}=this;this.times=0;try{e.emit(t.LayoutEvent.START),this.layoutOnce(),e.emitEvent(new t.LayoutEvent(t.LayoutEvent.END,this.layoutedBlocks,this.times))}catch(t){m.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?m.warn("layouting"):this.times>3?m.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(t.WatchEvent.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var e;if(!(null===(e=this.__updatedList)||void 0===e?void 0:e.length))return;const n=t.Run.start("PartLayout"),{target:i,__updatedList:o}=this,{BEFORE:a,LAYOUT:s,AFTER:r}=t.LayoutEvent,f=this.getBlocks(o);f.forEach((t=>t.setBefore())),i.emitEvent(new t.LayoutEvent(a,f,this.times)),this.extraBlock=null,o.sort(),function(t,e){let n;t.list.forEach((t=>{n=t.__layout,e.without(t)&&!n.proxyZoom&&(n.matrixChanged?(d(t,!0),e.add(t),t.isBranch&&h(t,e),u(t,e)):n.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),u(t,e)))}))}(o,this.__levelList),function(t){let e,n,i;t.sort(!0),t.levels.forEach((o=>{e=t.levelMap[o];for(let t=0,o=e.length;t<o;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||l(i[t])}l(n)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&c(t),t.__updateChange()}))}(o),this.extraBlock&&f.push(this.extraBlock),f.forEach((t=>t.setAfter())),i.emitEvent(new t.LayoutEvent(s,f,this.times)),i.emitEvent(new t.LayoutEvent(r,f,this.times)),this.addBlocks(f),this.__levelList.reset(),this.__updatedList=null,t.Run.end(n)}fullLayout(){const e=t.Run.start("FullLayout"),{target:n}=this,{BEFORE:i,LAYOUT:o,AFTER:a}=t.LayoutEvent,s=this.getBlocks(new t.LeafList(n));n.emitEvent(new t.LayoutEvent(i,s,this.times)),y.fullLayout(n),s.forEach((t=>{t.setAfter()})),n.emitEvent(new t.LayoutEvent(o,s,this.times)),n.emitEvent(new t.LayoutEvent(a,s,this.times)),this.addBlocks(s),t.Run.end(e)}static fullLayout(e){_(e,!0),e.isBranch?t.BranchHelper.updateBounds(e):t.LeafHelper.updateBounds(e),w(e)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:n}=this.extraBlock||(this.extraBlock=new g([]));e.length?n.add(t.__world):n.set(t.__world),e.add(t)}}createBlock(t){return new g(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:e}=this;this.__eventIds=[e.on_(t.LayoutEvent.REQUEST,this.layout,this),e.on_(t.LayoutEvent.AGAIN,this.layoutAgain,this),e.on_(t.WatchEvent.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const v=t.Debug.get("Renderer");class x{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(e,n,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=e,this.canvas=n,i&&(this.config=t.DataHelper.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(t.LayoutEvent.REQUEST)}render(e){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:n}=this;this.times=0,this.totalBounds=new t.Bounds,v.log(n.innerName,"---\x3e");try{this.emitRender(t.RenderEvent.START),this.renderOnce(e),this.emitRender(t.RenderEvent.END,this.totalBounds),t.ImageManager.clearRecycled()}catch(t){this.rendering=!1,v.error(t)}v.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(e){if(this.rendering)return v.warn("rendering");if(this.times>3)return v.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new t.Bounds,this.renderOptions={},e)this.emitRender(t.RenderEvent.BEFORE),e();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(t.RenderEvent.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(t.RenderEvent.RENDER,this.renderBounds,this.renderOptions),this.emitRender(t.RenderEvent.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 v.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const n=t.Run.start("PartRender"),{canvas:i}=this,o=e.getIntersect(i.bounds),a=e.includes(this.target.__world),s=new t.Bounds(o);i.save(),a&&!t.Debug.showRepaint?i.clear():(o.spread(10+1/this.canvas.pixelRatio).ceil(),i.clearWorld(o,!0),i.clipWorld(o,!0)),this.__render(o,a,s),i.restore(),t.Run.end(n)}fullRender(){const e=t.Run.start("FullRender"),{canvas:n}=this;n.save(),n.clear(),this.__render(n.bounds,!0),n.restore(),t.Run.end(e)}__render(e,n,i){const o=e.includes(this.target.__world)?{includes:n}:{bounds:e,includes:n};this.needFill&&this.canvas.fillWorld(e,this.config.fill),t.Debug.showRepaint&&this.canvas.strokeWorld(e,"red"),this.target.__render(this.canvas,o),this.renderBounds=i=i||e,this.renderOptions=o,this.totalBounds.isEmpty()?this.totalBounds=i:this.totalBounds.add(i),t.Debug.showHitView&&this.renderHitView(o),t.Debug.showBoundsView&&this.renderBoundsView(o),this.canvas.updateRender(i)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:e}=this;if(e){const n=new t.Bounds;n.setList(e),e.length=0,e.push(n)}}__requestRender(){const e=Date.now();t.Platform.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-e))),this.running&&(this.target.emit(t.AnimateEvent.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(t.RenderEvent.NEXT)),this.target&&this.__requestRender()}))}__onResize(e){if(!this.canvas.unreal){if(e.bigger||!e.samePixelRatio){const{width:n,height:i}=e.old;if(!new t.Bounds(0,0,n,i).includes(this.target.__world)||this.needFill||!e.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new t.Bounds(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||v.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(e,n,i){this.target.emitEvent(new t.RenderEvent(e,this.times,n,i))}__listenEvents(){const{target:e}=this;this.__eventIds=[e.on_(t.RenderEvent.REQUEST,this.update,this),e.on_(t.LayoutEvent.END,this.__onLayoutEnd,this),e.on_(t.RenderEvent.AGAIN,this.renderAgain,this),e.on_(t.ResizeEvent.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 b(t,e){let n;const{rows:i,decorationY:o,decorationHeight:a}=t.__.__textDrawData;for(let t=0,s=i.length;t<s;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)})),o&&e.fillRect(n.x,n.y+o,n.width,a)}function B(t,e,n){const{strokeAlign:i}=e.__,o="string"!=typeof t;switch(i){case"center":n.setStroke(o?void 0:t,e.__.strokeWidth,e.__),o?L(t,!0,e,n):R(e,n);break;case"inside":E("inside",t,o,e,n);break;case"outside":E("outside",t,o,e,n)}}function E(t,e,n,i,o){const{__strokeWidth:a,__font:s}=i.__,r=o.getSameCanvas(!0,!0);r.setStroke(n?void 0:e,2*a,i.__),r.font=s,n?L(e,!0,i,r):R(i,r),r.blendMode="outside"===t?"destination-out":"destination-in",b(i,r),r.blendMode="normal",i.__worldFlipped?o.copyWorldByReset(r,i.__nowWorld):o.copyWorldToInner(r,i.__nowWorld,i.__layout.renderBounds),r.recycle(i.__nowWorld)}function R(t,e){let n;const{rows:i,decorationY:o,decorationHeight:a}=t.__.__textDrawData;for(let t=0,s=i.length;t<s;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)})),o&&e.strokeRect(n.x,n.y+o,n.width,a)}function L(t,e,i,o){let a;for(let s=0,r=t.length;s<r;s++)a=t[s],a.image&&n.PaintImage.checkImage(i,o,a,!1)||a.style&&(o.strokeStyle=a.style,a.blendMode?(o.saveBlendMode(a.blendMode),e?R(i,o):o.stroke(),o.restoreBlendMode()):e?R(i,o):o.stroke())}Object.assign(t.Creator,{watcher:(t,e)=>new r(t,e),layouter:(t,e)=>new y(t,e),renderer:(t,e,n)=>new x(t,e,n),selector:(t,e)=>{},interaction:(t,e,n,i)=>{}}),t.Platform.layout=y.fullLayout;const{getSpread:k,getOuterOf:P,getByMove:S,getIntersectData:A}=t.BoundsHelper;let C;function O(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:o}=i.__layout;switch(e.type){case"solid":let{type:a,blendMode:s,color:r,opacity:d}=e;return{type:a,blendMode:s,style:n.ColorConvert.string(r,d)};case"image":return n.PaintImage.image(i,t,e,o,!C||!C[e.url]);case"linear":return n.PaintGradient.linearGradient(e,o);case"radial":return n.PaintGradient.radialGradient(e,o);case"angular":return n.PaintGradient.conicGradient(e,o);default:return void 0!==e.r?{type:"solid",style:n.ColorConvert.string(e)}:void 0}}const W={compute:function(t,e){const i=e.__,o=[];let a,s=i.__input[t];s instanceof Array||(s=[s]),C=n.PaintImage.recycleImage(t,i);for(let n,i=0,a=s.length;i<a;i++)n=O(t,s[i],e),n&&o.push(n);i["_"+t]=o.length?o:void 0,o.length&&o[0].image&&(a=o[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=a:i.__pixelStroke=a},fill:function(t,e,n){n.fillStyle=t,e.__.__font?b(e,n):e.__.windingRule?n.fill(e.__.windingRule):n.fill()},fills:function(t,e,i){let o;const{windingRule:a,__font:s}=e.__;for(let r=0,d=t.length;r<d;r++)o=t[r],o.image&&n.PaintImage.checkImage(e,i,o,!s)||o.style&&(i.fillStyle=o.style,o.transform?(i.save(),i.transform(o.transform),o.blendMode&&(i.blendMode=o.blendMode),s?b(e,i):a?i.fill(a):i.fill(),i.restore()):o.blendMode?(i.saveBlendMode(o.blendMode),s?b(e,i):a?i.fill(a):i.fill(),i.restoreBlendMode()):s?b(e,i):a?i.fill(a):i.fill())},fillText:b,stroke:function(t,e,n){const i=e.__,{__strokeWidth:o,strokeAlign:a,__font:s}=i;if(o)if(s)B(t,e,n);else switch(a){case"center":n.setStroke(t,o,i),n.stroke();break;case"inside":n.save(),n.setStroke(t,2*o,i),i.windingRule?n.clip(i.windingRule):n.clip(),n.stroke(),n.restore();break;case"outside":const a=n.getSameCanvas(!0,!0);a.setStroke(t,2*o,i),e.__drawRenderPath(a),a.stroke(),i.windingRule?a.clip(i.windingRule):a.clip(),a.clearWorld(e.__layout.renderBounds),e.__worldFlipped?n.copyWorldByReset(a,e.__nowWorld):n.copyWorldToInner(a,e.__nowWorld,e.__layout.renderBounds),a.recycle(e.__nowWorld)}},strokes:function(t,e,n){const i=e.__,{__strokeWidth:o,strokeAlign:a,__font:s}=i;if(o)if(s)B(t,e,n);else switch(a){case"center":n.setStroke(void 0,o,i),L(t,!1,e,n);break;case"inside":n.save(),n.setStroke(void 0,2*o,i),i.windingRule?n.clip(i.windingRule):n.clip(),L(t,!1,e,n),n.restore();break;case"outside":const{renderBounds:a}=e.__layout,s=n.getSameCanvas(!0,!0);e.__drawRenderPath(s),s.setStroke(void 0,2*o,i),L(t,!1,e,s),i.windingRule?s.clip(i.windingRule):s.clip(),s.clearWorld(a),e.__worldFlipped?n.copyWorldByReset(s,e.__nowWorld):n.copyWorldToInner(s,e.__nowWorld,a),s.recycle(e.__nowWorld)}},strokeText:B,drawTextStroke:R,shape:function(t,e,n){const i=e.getSameCanvas(),o=t.__nowWorld;let a,s,r,d,{scaleX:l,scaleY:c}=o;if(l<0&&(l=-l),c<0&&(c=-c),e.bounds.includes(o))d=i,a=r=o;else{const{renderShapeSpread:i}=t.__layout,h=A(i?k(e.bounds,l===c?i*l:[i*c,i*l]):e.bounds,o);s=e.bounds.getFitMatrix(h);let{a:u,d:f}=s;if(s.a<1&&(d=e.getSameCanvas(),t.__renderShape(d,n),l*=u,c*=f),r=P(o,s),a=S(r,-s.e,-s.f),n.matrix){const{matrix:t}=n;s.multiply(t),u*=t.scaleX,f*=t.scaleY}n=Object.assign(Object.assign({},n),{matrix:s.withScale(u,f)})}return t.__renderShape(i,n),{canvas:i,matrix:s,bounds:a,worldCanvas:d,shapeBounds:r,scaleX:l,scaleY:c}}};let T={};const{get:M,rotateOfOuter:I,translate:D,scaleOfOuter:H,scale:F,rotate:j}=t.MatrixHelper;function U(t,e,n,i,o,a,s){const r=M();D(r,e.x+n,e.y+i),F(r,o,a),s&&I(r,{x:e.x+e.width/2,y:e.y+e.height/2},s),t.transform=r}function G(t,e,n,i,o,a,s){const r=M();D(r,e.x+n,e.y+i),o&&F(r,o,a),s&&j(r,s),t.transform=r}function N(t,e,n,i,o,a,s,r,d,l){const c=M();if(d)if("center"===l)I(c,{x:n/2,y:i/2},d);else switch(j(c,d),d){case 90:D(c,i,0);break;case 180:D(c,n,i);break;case 270:D(c,0,n)}T.x=e.x+o,T.y=e.y+a,D(c,T.x,T.y),s&&H(c,T,s,r),t.transform=c}const{get:Y,translate:q}=t.MatrixHelper,V=new t.Bounds,X={};function z(t,e,n,i){const{blendMode:o}=n;o&&(t.blendMode=o),t.data=Q(n,i,e)}function Q(e,n,i){let{width:o,height:a}=i;e.padding&&(n=V.set(n).shrink(e.padding));const{opacity:s,mode:r,align:d,offset:l,scale:c,size:h,rotation:u,repeat:f}=e,p=n.width===o&&n.height===a,g={mode:r},_="center"!==d&&(u||0)%180==90,w=_?a:o,m=_?o:a;let y,v,x=0,b=0;if(r&&"cover"!==r&&"fit"!==r)h?(y=("number"==typeof h?h:h.width)/o,v=("number"==typeof h?h:h.height)/a):c&&(y="number"==typeof c?c:c.x,v="number"==typeof c?c:c.y);else if(!p||u){const t=n.width/w,e=n.height/m;y=v="fit"===r?Math.min(t,e):Math.max(t,e),x+=(n.width-o*y)/2,b+=(n.height-a*v)/2}if(d){const e={x:x,y:b,width:w,height:m};y&&(e.width*=y,e.height*=v),t.AlignHelper.toPoint(d,e,n,X,!0),x+=X.x,b+=X.y}switch(l&&(x+=l.x,b+=l.y),r){case"strench":p||(o=n.width,a=n.height);break;case"normal":case"clip":(x||b||y||u)&&G(g,n,x,b,y,v,u);break;case"repeat":(!p||y||u)&&N(g,n,o,a,x,b,y,v,u,d),f||(g.repeat="repeat");break;default:y&&U(g,n,x,b,y,v,u)}return g.transform||(n.x||n.y)&&(g.transform=Y(),q(g.transform,n.x,n.y)),y&&"strench"!==r&&(g.scaleX=y,g.scaleY=v),g.width=o,g.height=a,s&&(g.opacity=s),f&&(g.repeat="string"==typeof f?"x"===f?"repeat-x":"repeat-y":"repeat"),g}let J,Z=new t.Bounds;const{isSame:K}=t.BoundsHelper;function $(t,e,n,i,o,a){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 o.data||z(o,i,n,a),!0}function tt(e,n){it(e,t.ImageEvent.LOAD,n)}function et(e,n){it(e,t.ImageEvent.LOADED,n)}function nt(e,n,i){n.error=i,e.forceUpdate("surface"),it(e,t.ImageEvent.ERROR,n)}function it(e,n,i){e.hasEvent(n)&&e.emitEvent(new t.ImageEvent(n,i))}function ot(t,e){const{leafer:n}=t;n&&n.viewReady&&(n.renderer.ignore=e)}const{get:at,scale:st,copy:rt}=t.MatrixHelper,{ceil:dt,abs:lt}=Math;function ct(e,n,i){let{scaleX:o,scaleY:a}=t.ImageManager.patternLocked?e.__world:e.__nowWorld;const s=o+"-"+a;if(n.patternId===s||e.destroyed)return!1;{o=lt(o),a=lt(a);const{image:e,data:r}=n;let d,l,{width:c,height:h,scaleX:u,scaleY:f,opacity:p,transform:g,repeat:_}=r;u&&(l=at(),rt(l,g),st(l,1/u,1/f),o*=u,a*=f),o*=i,a*=i,c*=o,h*=a;const w=c*h;if(!_&&w>t.Platform.image.maxCacheSize)return!1;let m=t.Platform.image.maxPatternSize;if(!e.isSVG){const t=e.width*e.height;m>t&&(m=t)}w>m&&(d=Math.sqrt(w/m)),d&&(o/=d,a/=d,c/=d,h/=d),u&&(o/=u,a/=f),(g||1!==o||1!==a)&&(l||(l=at(),g&&rt(l,g)),st(l,1/o,1/a));const y=e.getCanvas(dt(c)||1,dt(h)||1,p),v=e.getPattern(y,_||t.Platform.origin.noRepeat||"no-repeat",l,n);return n.style=v,n.patternId=s,!0}}const{abs:ht}=Math;const ut={image:function(e,n,i,o,a){let s,r;const d=t.ImageManager.get(i);return J&&i===J.paint&&K(o,J.boxBounds)?s=J.leafPaint:(s={type:i.type,image:d},J=d.use>1?{leafPaint:s,paint:i,boxBounds:Z.set(o)}:null),(a||d.loading)&&(r={image:d,attrName:n,attrValue:i}),d.ready?($(e,n,i,d,s,o),a&&(tt(e,r),et(e,r))):d.error?a&&nt(e,r,d.error):(ot(e,!0),a&&tt(e,r),s.loadId=d.load((()=>{ot(e,!1),e.destroyed||($(e,n,i,d,s,o)&&(d.hasOpacityPixel&&(e.__layout.hitCanvasChanged=!0),e.forceUpdate("surface")),et(e,r)),s.loadId=null}),(t=>{ot(e,!1),nt(e,r,t),s.loadId=null}))),s},checkImage:function(e,o,a,s){const{scaleX:r,scaleY:d}=t.ImageManager.patternLocked?e.__world:e.__nowWorld;if(!a.data||a.patternId===r+"-"+d&&!n.Export.running)return!1;{const{data:l}=a;if(s)if(l.repeat)s=!1;else{let{width:e,height:i}=l;e*=ht(r)*o.pixelRatio,i*=ht(d)*o.pixelRatio,l.scaleX&&(e*=l.scaleX,i*=l.scaleY),s=e*i>t.Platform.image.maxCacheSize||n.Export.running}return s?(o.save(),o.clip(),a.blendMode&&(o.blendMode=a.blendMode),l.opacity&&(o.opacity*=l.opacity),l.transform&&o.transform(l.transform),o.drawImage(a.image.view,0,0,l.width,l.height),o.restore(),!0):(!a.style||n.Export.running?ct(e,a,o.pixelRatio):a.patternTask||(a.patternTask=t.ImageManager.patternTasker.add((()=>i(this,void 0,void 0,(function*(){a.patternTask=null,o.bounds.hit(e.__nowWorld)&&ct(e,a,o.pixelRatio),e.forceUpdate("surface")}))),300)),!1)}},createPattern:ct,recycleImage:function(e,n){const i=n["_"+e];if(i instanceof Array){let o,a,s,r;for(let d=0,l=i.length;d<l;d++)o=i[d].image,r=o&&o.url,r&&(a||(a={}),a[r]=!0,t.ImageManager.recycle(o),o.loading&&(s||(s=n.__input&&n.__input[e]||[],s instanceof Array||(s=[s])),o.unload(i[d].loadId,!s.some((t=>t.url===r)))));return a}return null},createData:z,getPatternData:Q,fillOrFitMode:U,clipMode:G,repeatMode:N},{toPoint:ft}=t.AroundHelper,pt={},gt={};function _t(t,e,i){let o;for(let a=0,s=e.length;a<s;a++)o=e[a],"string"==typeof o?t.addColorStop(a/(s-1),n.ColorConvert.string(o,i)):t.addColorStop(o.offset,n.ColorConvert.string(o.color,i))}const{getAngle:wt,getDistance:mt}=t.PointHelper,{get:yt,rotateOfOuter:vt,scaleOfOuter:xt}=t.MatrixHelper,{toPoint:bt}=t.AroundHelper,Bt={},Et={};function Rt(t,e,n,i,o){let a;const{width:s,height:r}=t;if(s!==r||i){const t=wt(e,n);a=yt(),o?(xt(a,e,s/r*(i||1),1),vt(a,e,t+90)):(xt(a,e,1,s/r*(i||1)),vt(a,e,t))}return a}const{getDistance:Lt}=t.PointHelper,{toPoint:kt}=t.AroundHelper,Pt={},St={};const At={linearGradient:function(e,n){let{from:i,to:o,type:a,blendMode:s,opacity:r}=e;ft(i||"top",n,pt),ft(o||"bottom",n,gt);const d=t.Platform.canvas.createLinearGradient(pt.x,pt.y,gt.x,gt.y);_t(d,e.stops,r);const l={type:a,style:d};return s&&(l.blendMode=s),l},radialGradient:function(e,n){let{from:i,to:o,type:a,opacity:s,blendMode:r,stretch:d}=e;bt(i||"center",n,Bt),bt(o||"bottom",n,Et);const l=t.Platform.canvas.createRadialGradient(Bt.x,Bt.y,0,Bt.x,Bt.y,mt(Bt,Et));_t(l,e.stops,s);const c={type:a,style:l},h=Rt(n,Bt,Et,d,!0);return h&&(c.transform=h),r&&(c.blendMode=r),c},conicGradient:function(e,n){let{from:i,to:o,type:a,opacity:s,blendMode:r,stretch:d}=e;kt(i||"center",n,Pt),kt(o||"bottom",n,St);const l=t.Platform.conicGradientSupport?t.Platform.canvas.createConicGradient(0,Pt.x,Pt.y):t.Platform.canvas.createRadialGradient(Pt.x,Pt.y,0,Pt.x,Pt.y,Lt(Pt,St));_t(l,e.stops,s);const c={type:a,style:l},h=Rt(n,Pt,St,d||1,t.Platform.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:Rt},{copy:Ct,toOffsetOutBounds:Ot}=t.BoundsHelper,Wt={},Tt={};function Mt(e,n,i,o){const{bounds:a,shapeBounds:s}=o;if(t.Platform.fullImageShadow){if(Ct(Wt,e.bounds),Wt.x+=n.x-s.x,Wt.y+=n.y-s.y,i){const{matrix:t}=o;Wt.x-=(a.x+(t?t.e:0)+a.width/2)*(i-1),Wt.y-=(a.y+(t?t.f:0)+a.height/2)*(i-1),Wt.width*=i,Wt.height*=i}e.copyWorld(o.canvas,e.bounds,Wt)}else i&&(Ct(Wt,n),Wt.x-=n.width/2*(i-1),Wt.y-=n.height/2*(i-1),Wt.width*=i,Wt.height*=i),e.copyWorld(o.canvas,s,i?Wt:n)}const{toOffsetOutBounds:It}=t.BoundsHelper,Dt={};const Ht={shadow:function(t,e,n){let i,o;const{__nowWorld:a,__layout:s}=t,{shadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;Ot(l,Tt),r.forEach(((r,g)=>{f.setWorldShadow(Tt.offsetX+r.x*h,Tt.offsetY+r.y*u,r.blur*h,r.color),o=r.spread?1+2*r.spread/(s.boxBounds.width+2*(s.strokeBoxSpread||0)):0,Mt(f,Tt,o,n),i=l,r.box&&(f.restore(),f.save(),d&&(f.copyWorld(f,l,a,"copy"),i=a),d?f.copyWorld(d,a,a,"destination-out"):f.copyWorld(n.canvas,c,l,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,i,a,r.blendMode):e.copyWorldToInner(f,i,s.renderBounds,r.blendMode),p&&g<p&&f.clearWorld(i,!0)})),f.recycle(i)},innerShadow:function(t,e,n){let i,o;const{__nowWorld:a,__layout:s}=t,{innerShadow:r}=t.__,{worldCanvas:d,bounds:l,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;It(l,Dt),r.forEach(((r,g)=>{f.save(),f.setWorldShadow(Dt.offsetX+r.x*h,Dt.offsetY+r.y*u,r.blur*h),o=r.spread?1-2*r.spread/(s.boxBounds.width+2*(s.strokeBoxSpread||0)):0,Mt(f,Dt,o,n),f.restore(),d?(f.copyWorld(f,l,a,"copy"),f.copyWorld(d,a,a,"source-out"),i=a):(f.copyWorld(n.canvas,c,l,"source-out"),i=l),f.fillWorld(i,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,i,a,r.blendMode):e.copyWorldToInner(f,i,s.renderBounds,r.blendMode),p&&g<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:Ft}=t.LeafBoundsHelper;function jt(t,e,n,i,o,a){switch(e){case"alpha":!function(t,e,n,i){const o=t.__nowWorld;n.resetTransform(),n.opacity=1,n.useMask(i,o),i.recycle(o),Gt(t,e,n,1)}(t,n,i,o);break;case"opacity-path":Gt(t,n,i,a);break;case"path":n.restore()}}function Ut(t){return t.getSameCanvas(!1,!0)}function Gt(t,e,n,i){const o=t.__nowWorld;e.resetTransform(),e.opacity=i,e.copyWorld(n,o),n.recycle(o)}n.Group.prototype.__renderMask=function(t,e){let n,i,o,a,s;const{children:r}=this;for(let d=0,l=r.length;d<l;d++)n=r[d],n.__.mask&&(s&&(jt(this,s,t,o,i,a),i=o=null),"path"===n.__.mask?(n.opacity<1?(s="opacity-path",a=n.opacity,o||(o=Ut(t))):(s="path",t.save()),n.__clip(o||t,e)):(s="alpha",i||(i=Ut(t)),o||(o=Ut(t)),n.__render(i,e)),"clipping"!==n.__.mask)||Ft(n,e)||n.__render(o||t,e);jt(this,s,t,o,i,a)};const Nt=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Yt=Nt+"_#~&*+\\=|≮≯≈≠=…",qt=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 Vt(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Xt=Vt("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),zt=Vt("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Qt=Vt(Nt),Jt=Vt(Yt),Zt=Vt("- —/~|┆·");var Kt;!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"}(Kt||(Kt={}));const{Letter:$t,Single:te,Before:ee,After:ne,Symbol:ie,Break:oe}=Kt;function ae(t){return Xt[t]?$t:Zt[t]?oe:zt[t]?ee:Qt[t]?ne:Jt[t]?ie:qt.test(t)?te:$t}const se={trimRight(t){const{words:e}=t;let n,i=0,o=e.length;for(let a=o-1;a>-1&&(n=e[a].data[0]," "===n.char);a--)i++,t.width-=n.width;i&&e.splice(o-i,i)}};function re(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:de}=se,{Letter:le,Single:ce,Before:he,After:ue,Symbol:fe,Break:pe}=Kt;let ge,_e,we,me,ye,ve,xe,be,Be,Ee,Re,Le,ke,Pe,Se,Ae,Ce=[];function Oe(t,e){Be&&!be&&(be=Be),ge.data.push({char:t,width:e}),we+=e}function We(){me+=we,ge.width=we,_e.words.push(ge),ge={data:[]},we=0}function Te(){Pe&&(Se.paraNumber++,_e.paraStart=!0,Pe=!1),Be&&(_e.startCharSize=be,_e.endCharSize=Be,be=0),_e.width=me,Ae.width&&de(_e),Ce.push(_e),_e={words:[]},me=0}const Me=0,Ie=1,De=2;const{top:He,right:Fe,bottom:je,left:Ue}=t.Direction4;function Ge(t,e,n){const{bounds:i,rows:o}=t;i[e]+=n;for(let t=0;t<o.length;t++)o[t][e]+=n}const Ne={getDrawData:function(e,n){"string"!=typeof e&&(e=String(e));let i=0,o=0,a=n.__getInput("width")||0,s=n.__getInput("height")||0;const{textDecoration:r,__font:d,__padding:l}=n;l&&(a&&(i=l[Ue],a-=l[Fe]+l[Ue]),s&&(o=l[He],s-=l[He]+l[je]));const c={bounds:{x:i,y:o,width:a,height:s},rows:[],paraNumber:0,font:t.Platform.canvas.font=d};return function(e,n,i){Se=e,Ce=e.rows,Ae=e.bounds;const{__letterSpacing:o,paraIndent:a,textCase:s}=i,{canvas:r}=t.Platform,{width:d,height:l}=Ae;if(d||l||o||"none"!==s){const t="none"!==i.textWrap,e="break"===i.textWrap;Pe=!0,Re=null,be=xe=Be=we=me=0,ge={data:[]},_e={words:[]};for(let i=0,l=n.length;i<l;i++)ve=n[i],"\n"===ve?(we&&We(),_e.paraEnd=!0,Te(),Pe=!0):(Ee=ae(ve),Ee===le&&"none"!==s&&(ve=re(ve,s,!we)),xe=r.measureText(ve).width,o&&(o<0&&(Be=xe),xe+=o),Le=Ee===ce&&(Re===ce||Re===le)||Re===ce&&Ee!==ue,ke=!(Ee!==he&&Ee!==ce||Re!==fe&&Re!==ue),ye=Pe&&a?d-a:d,t&&d&&me+we+xe>ye&&(e?(we&&We(),me&&Te()):(ke||(ke=Ee===le&&Re==ue),Le||ke||Ee===pe||Ee===he||Ee===ce||we+xe>ye?(we&&We(),me&&Te()):me&&Te()))," "===ve&&!0!==Pe&&me+we===0||(Ee===pe?(" "===ve&&we&&We(),Oe(ve,xe),We()):Le||ke?(we&&We(),Oe(ve,xe)):Oe(ve,xe)),Re=Ee);we&&We(),me&&Te(),Ce.length>0&&(Ce[Ce.length-1].paraEnd=!0)}else n.split("\n").forEach((t=>{Se.paraNumber++,Ce.push({x:a||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(c,e,n),l&&function(t,e,n,i,o){if(!i)switch(n.textAlign){case"left":Ge(e,"x",t[Ue]);break;case"right":Ge(e,"x",-t[Fe])}if(!o)switch(n.verticalAlign){case"top":Ge(e,"y",t[He]);break;case"bottom":Ge(e,"y",-t[je])}}(l,c,n,a,s),function(t,e){const{rows:n,bounds:i}=t,{__lineHeight:o,__baseLine:a,__letterSpacing:s,__clipText:r,textAlign:d,verticalAlign:l,paraSpacing:c}=e;let h,u,f,{x:p,y:g,width:_,height:w}=i,m=o*n.length+(c?c*(t.paraNumber-1):0),y=a;if(r&&m>w)m=Math.max(w,o),t.overflow=n.length;else switch(l){case"middle":g+=(w-m)/2;break;case"bottom":g+=w-m}y+=g;for(let a=0,l=n.length;a<l;a++){if(h=n[a],h.x=p,h.width<_||h.width>_&&!r)switch(d){case"center":h.x+=(_-h.width)/2;break;case"right":h.x+=_-h.width}h.paraStart&&c&&a>0&&(y+=c),h.y=y,y+=o,t.overflow>a&&y>m&&(h.isOverflow=!0,t.overflow=a+1),u=h.x,f=h.width,s<0&&(h.width<0?(f=-h.width+e.fontSize+s,u-=f,f+=e.fontSize):f-=s),u<i.x&&(i.x=u),f>i.width&&(i.width=f),r&&_&&_<f&&(h.isOverflow=!0,t.overflow||(t.overflow=n.length))}i.y=g,i.height=m}(c,n),function(t,e,n,i){const{rows:o}=t,{textAlign:a,paraIndent:s,letterSpacing:r}=e;let d,l,c,h,u;o.forEach((t=>{t.words&&(c=s&&t.paraStart?s:0,l=n&&"justify"===a&&t.words.length>1?(n-t.width-c)/(t.words.length-1):0,h=r||t.isOverflow?Me:l>.01?Ie:De,t.isOverflow&&!r&&(t.textMode=!0),h===De?(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===Ie?(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,a),c.overflow&&function(e,n,i,o){if(!o)return;const{rows:a,overflow:s}=e;let{textOverflow:r}=n;if(a.splice(s),r&&"show"!==r){let e,d;"hide"===r?r="":"ellipsis"===r&&(r="...");const l=r?t.Platform.canvas.measureText(r).width:0,c=i+o-l;("none"===n.textWrap?a:[a[s-1]]).forEach((t=>{if(t.isOverflow&&t.data){let n=t.data.length-1;for(let i=n;i>-1&&(e=t.data[i],d=e.x+e.width,!(i===n&&d<c));i--){if(d<c&&" "!==e.char){t.data.splice(i+1),t.width-=e.width;break}t.width-=e.width}t.width+=l,t.data.push({char:r,x:d}),t.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(t)}}))}}(c,n,i,a),"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 Ye={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:qe,addPoint:Ve,toBounds:Xe}=t.TwoPointBoundsHelper;const ze={export(e,n,o){this.running=!0;const a=t.FileHelper.fileType(n);return o=t.FileHelper.getExportOptions(o),function(e){Qe||(Qe=new t.TaskProcessor);return new Promise((t=>{Qe.add((()=>i(this,void 0,void 0,(function*(){return yield e(t)}))),{parallel:!1})}))}((s=>new Promise((r=>{const d=t=>{s(t),r(),this.running=!1},{toURL:l}=t.Platform,{download:c}=t.Platform.origin;if("json"===n)return d({data:e.toJSON(o.json)});if("json"===a)return c(l(JSON.stringify(e.toJSON(o.json)),"text"),n),d({data:!0});if("svg"===n)return d({data:e.toSVG()});if("svg"===a)return c(l(e.toSVG(),"svg"),n),d({data:!0});const{leafer:h}=e;h?(Je(e),h.waitViewCompleted((()=>i(this,void 0,void 0,(function*(){let i,a,s=1,r=1;const{worldTransform:l,isLeafer:c,isFrame:u}=e,{slice:f,trim:p,onCanvas:g}=o;let _=o.scale||1,w=o.pixelRatio||1;const m=void 0===o.smooth?h.config.smooth:o.smooth,y=o.contextSettings||h.config.contextSettings;e.isApp&&(_*=w,w=e.app.pixelRatio);const v=o.screenshot||e.isApp,x=c&&v&&void 0===o.fill?e.fill:o.fill,b=t.FileHelper.isOpaqueImage(n)||x,B=new t.Matrix;if(v)i=!0===v?c?h.canvas.bounds:e.worldRenderBounds:v;else{let t=o.relative||(c?"inner":"local");switch(s=l.scaleX,r=l.scaleY,t){case"inner":B.set(l);break;case"local":B.set(l).divide(e.localTransform),s/=e.scaleX,r/=e.scaleY;break;case"world":s=1,r=1;break;case"page":t=e.leafer;default:B.set(l).divide(e.getTransform(t));const n=t.worldTransform;s/=s/n.scaleX,r/=r/n.scaleY}i=e.getBounds("render",t)}const{x:E,y:R,width:L,height:k}=new t.Bounds(i).scale(_);let P=t.Creator.canvas({width:Math.round(L),height:Math.round(k),pixelRatio:w,smooth:m,contextSettings:y});const S={matrix:B.scale(1/_).invert().translate(-E,-R).withScale(1/s*_,1/r*_)};let A;if(f&&(A=e,A.__worldOpacity=0,e=h,S.bounds=P.bounds),P.save(),u&&void 0!==x){const t=e.get("fill");e.fill="",e.__render(P,S),e.fill=t}else e.__render(P,S);if(P.restore(),A&&A.__updateWorldOpacity(),p){a=function(e){const{width:n,height:i}=e.view,{data:o}=e.context.getImageData(0,0,n,i);let a,s,r,d=0;for(let t=0;t<o.length;t+=4)0!==o[t+3]&&(a=d%n,s=(d-a)/n,r?Ve(r,a,s):qe(r={},a,s)),d++;const l=new t.Bounds;return Xe(r,l),l.scale(1/e.pixelRatio).ceil()}(P);const e=P,{width:n,height:i}=a,o={x:0,y:0,width:n,height:i,pixelRatio:w};P=t.Creator.canvas(o),P.copyWorld(e,a,o)}b&&P.fillWorld(P.bounds,x||"#FFFFFF","destination-over"),g&&g(P);const C="canvas"===n?P:yield P.export(n,o);d({data:C,width:P.pixelWidth,height:P.pixelHeight,renderBounds:i,trimBounds:a})}))))):d({data:!1})}))))}};let Qe;function Je(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Je(t)))}const Ze=t.LeaferCanvasBase.prototype,Ke=t.Debug.get("@leafer-ui/export");Ze.export=function(e,n){const{quality:i,blob:o}=t.FileHelper.getExportOptions(n);return e.includes(".")?this.saveAs(e,i):o?this.toBlob(e,i):this.toDataURL(e,i)},Ze.toBlob=function(e,n){return new Promise((i=>{t.Platform.origin.canvasToBolb(this.view,e,n).then((t=>{i(t)})).catch((t=>{Ke.error(t),i(null)}))}))},Ze.toDataURL=function(e,n){return t.Platform.origin.canvasToDataURL(this.view,e,n)},Ze.saveAs=function(e,n){return new Promise((i=>{t.Platform.origin.canvasSaveAs(this.view,e,n).then((()=>{i(!0)})).catch((t=>{Ke.error(t),i(!1)}))}))},Object.assign(n.TextConvert,Ne),Object.assign(n.ColorConvert,Ye),Object.assign(n.Paint,W),Object.assign(n.PaintImage,ut),Object.assign(n.PaintGradient,At),Object.assign(n.Effect,Ht),Object.assign(n.Export,ze),Object.defineProperty(exports,"LeaferImage",{enumerable:!0,get:function(){return t.LeaferImage}}),exports.Layouter=y,exports.LeaferCanvas=o,exports.Renderer=x,exports.Watcher=r,exports.useCanvas=function(n,o){if(t.Platform.canvasType=n,!t.Platform.origin){if("skia"===n){const{Canvas:e,loadImage:n}=o;t.Platform.origin={createCanvas:(t,n,i)=>new e(t,n,i),canvasToDataURL:(t,e,n)=>t.toDataURLSync(e,{quality:n}),canvasToBolb:(t,e,n)=>t.toBuffer(e,{quality:n}),canvasSaveAs:(t,e,n)=>t.saveAs(e,{quality:n}),download(t,e){},loadImage:e=>n(t.Platform.image.getRealURL(e))},t.Platform.roundRectPatch=!0}else if("napi"===n){const{Canvas:n,loadImage:r}=o;t.Platform.origin={createCanvas:(t,e,i)=>new n(t,e,i),canvasToDataURL:(t,e,n)=>t.toDataURL(a(e),n),canvasToBolb:(t,e,n)=>i(this,void 0,void 0,(function*(){return t.toBuffer(a(e),n)})),canvasSaveAs:(t,n,o)=>i(this,void 0,void 0,(function*(){return e.writeFileSync(n,t.toBuffer(a(s(n)),o))})),download(t,e){},loadImage:e=>r(t.Platform.image.getRealURL(e))}}t.Platform.ellipseToCurve=!0,t.Platform.event={stopDefault(t){},stopNow(t){},stop(t){}},t.Platform.canvas=t.Creator.canvas()}},Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})})),Object.keys(n).forEach((function(t){"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return n[t]}})}));
1
+ "use strict";var t=require("@leafer/core"),e=require("fs"),n=require("@leafer-ui/draw");function i(t,e,n,i){return new(n||(n=Promise))((function(a,o){function s(t){try{l(i.next(t))}catch(t){o(t)}}function r(t){try{l(i.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,r)}l((i=i.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class a extends t.LeaferCanvasBase{get allowBackgroundColor(){return!0}init(){this.__createView(),this.__createContext(),this.resize(this.config),t.Platform.roundRectPatch&&(this.context.__proto__.roundRect=null,t.canvasPatch(this.context.__proto__))}__createView(){this.view=t.Platform.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}}const{mineType:o,fileType:s}=t.FileHelper;Object.assign(t.Creator,{canvas:(t,e)=>new a(t,e),image:e=>new t.LeaferImage(e)}),t.Platform.name="node",t.Platform.requestRender=function(t){setTimeout(t)},t.defineKey(t.Platform,"devicePixelRatio",{get:()=>1}),t.Platform.conicGradientSupport=!0;class r{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const e=new t.LeafList;return this.__updatedList.list.forEach((t=>{t.leafer&&e.add(t)})),e}return this.__updatedList}constructor(e,n){this.totalTimes=0,this.config={},this.__updatedList=new t.LeafList,this.target=e,n&&(this.config=t.DataHelper.default(n,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(t.RenderEvent.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(e){e.type===t.ChildEvent.ADD?(this.hasAdd=!0,this.__pushChild(e.child)):(this.hasRemove=!0,this.__updatedList.add(e.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 t.WatchEvent(t.WatchEvent.DATA,{updatedList:this.updatedList})),this.__updatedList=new t.LeafList,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:e}=this;this.__eventIds=[e.on_(t.PropertyEvent.CHANGE,this.__onAttrChange,this),e.on_([t.ChildEvent.ADD,t.ChildEvent.REMOVE],this.__onChildEvent,this),e.on_(t.WatchEvent.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:l,updateBounds:d,updateAllWorldOpacity:c}=t.LeafHelper,{pushAllChildBranch:h,pushAllParent:u}=t.BranchHelper;const{worldBounds:f}=t.LeafBoundsHelper,p={x:0,y:0,width:1e5,height:1e5};class g{constructor(e){this.updatedBounds=new t.Bounds,this.beforeBounds=new t.Bounds,this.afterBounds=new t.Bounds,e instanceof Array&&(e=new t.LeafList(e)),this.updatedList=e}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,f)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(p):this.afterBounds.setListWithFn(t,f),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:_,updateAllChange:w}=t.LeafHelper,m=t.Debug.get("Layouter");class y{constructor(e,n){this.totalTimes=0,this.config={},this.__levelList=new t.LeafLevelList,this.target=e,n&&(this.config=t.DataHelper.default(n,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:e}=this;this.times=0;try{e.emit(t.LayoutEvent.START),this.layoutOnce(),e.emitEvent(new t.LayoutEvent(t.LayoutEvent.END,this.layoutedBlocks,this.times))}catch(t){m.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?m.warn("layouting"):this.times>3?m.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(t.WatchEvent.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var e;if(!(null===(e=this.__updatedList)||void 0===e?void 0:e.length))return;const n=t.Run.start("PartLayout"),{target:i,__updatedList:a}=this,{BEFORE:o,LAYOUT:s,AFTER:r}=t.LayoutEvent,f=this.getBlocks(a);f.forEach((t=>t.setBefore())),i.emitEvent(new t.LayoutEvent(o,f,this.times)),this.extraBlock=null,a.sort(),function(t,e){let n;t.list.forEach((t=>{n=t.__layout,e.without(t)&&!n.proxyZoom&&(n.matrixChanged?(l(t,!0),e.add(t),t.isBranch&&h(t,e),u(t,e)):n.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),u(t,e)))}))}(a,this.__levelList),function(t){let e,n,i;t.sort(!0),t.levels.forEach((a=>{e=t.levelMap[a];for(let t=0,a=e.length;t<a;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||d(i[t])}d(n)}}))}(this.__levelList),function(t){let e;t.list.forEach((t=>{e=t.__layout,e.opacityChanged&&c(t),e.stateStyleChanged&&setTimeout((()=>e.stateStyleChanged&&t.updateState())),t.__updateChange()}))}(a),this.extraBlock&&f.push(this.extraBlock),f.forEach((t=>t.setAfter())),i.emitEvent(new t.LayoutEvent(s,f,this.times)),i.emitEvent(new t.LayoutEvent(r,f,this.times)),this.addBlocks(f),this.__levelList.reset(),this.__updatedList=null,t.Run.end(n)}fullLayout(){const e=t.Run.start("FullLayout"),{target:n}=this,{BEFORE:i,LAYOUT:a,AFTER:o}=t.LayoutEvent,s=this.getBlocks(new t.LeafList(n));n.emitEvent(new t.LayoutEvent(i,s,this.times)),y.fullLayout(n),s.forEach((t=>{t.setAfter()})),n.emitEvent(new t.LayoutEvent(a,s,this.times)),n.emitEvent(new t.LayoutEvent(o,s,this.times)),this.addBlocks(s),t.Run.end(e)}static fullLayout(e){_(e,!0),e.isBranch?t.BranchHelper.updateBounds(e):t.LeafHelper.updateBounds(e),w(e)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:n}=this.extraBlock||(this.extraBlock=new g([]));e.length?n.add(t.__world):n.set(t.__world),e.add(t)}}createBlock(t){return new g(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:e}=this;this.__eventIds=[e.on_(t.LayoutEvent.REQUEST,this.layout,this),e.on_(t.LayoutEvent.AGAIN,this.layoutAgain,this),e.on_(t.WatchEvent.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const v=t.Debug.get("Renderer");class x{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(e,n,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=e,this.canvas=n,i&&(this.config=t.DataHelper.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(t.LayoutEvent.REQUEST)}render(e){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:n}=this;this.times=0,this.totalBounds=new t.Bounds,v.log(n.innerName,"---\x3e");try{this.emitRender(t.RenderEvent.START),this.renderOnce(e),this.emitRender(t.RenderEvent.END,this.totalBounds),t.ImageManager.clearRecycled()}catch(t){this.rendering=!1,v.error(t)}v.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(e){if(this.rendering)return v.warn("rendering");if(this.times>3)return v.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new t.Bounds,this.renderOptions={},e)this.emitRender(t.RenderEvent.BEFORE),e();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(t.RenderEvent.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(t.RenderEvent.RENDER,this.renderBounds,this.renderOptions),this.emitRender(t.RenderEvent.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 v.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const n=t.Run.start("PartRender"),{canvas:i}=this,a=e.getIntersect(i.bounds),o=e.includes(this.target.__world),s=new t.Bounds(a);i.save(),o&&!t.Debug.showRepaint?i.clear():(a.spread(10+1/this.canvas.pixelRatio).ceil(),i.clearWorld(a,!0),i.clipWorld(a,!0)),this.__render(a,o,s),i.restore(),t.Run.end(n)}fullRender(){const e=t.Run.start("FullRender"),{canvas:n}=this;n.save(),n.clear(),this.__render(n.bounds,!0),n.restore(),t.Run.end(e)}__render(e,n,i){const a=e.includes(this.target.__world)?{includes:n}:{bounds:e,includes:n};this.needFill&&this.canvas.fillWorld(e,this.config.fill),t.Debug.showRepaint&&this.canvas.strokeWorld(e,"red"),this.target.__render(this.canvas,a),this.renderBounds=i=i||e,this.renderOptions=a,this.totalBounds.isEmpty()?this.totalBounds=i:this.totalBounds.add(i),t.Debug.showHitView&&this.renderHitView(a),t.Debug.showBoundsView&&this.renderBoundsView(a),this.canvas.updateRender(i)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:e}=this;if(e){const n=new t.Bounds;n.setList(e),e.length=0,e.push(n)}}__requestRender(){const e=Date.now();t.Platform.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-e))),this.running&&(this.changed&&this.canvas.view&&this.render(),this.target.emit(t.RenderEvent.NEXT)),this.target&&this.__requestRender()}))}__onResize(e){if(!this.canvas.unreal){if(e.bigger||!e.samePixelRatio){const{width:n,height:i}=e.old;if(!new t.Bounds(0,0,n,i).includes(this.target.__world)||this.needFill||!e.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new t.Bounds(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||v.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(e,n,i){this.target.emitEvent(new t.RenderEvent(e,this.times,n,i))}__listenEvents(){const{target:e}=this;this.__eventIds=[e.on_(t.RenderEvent.REQUEST,this.update,this),e.on_(t.LayoutEvent.END,this.__onLayoutEnd,this),e.on_(t.RenderEvent.AGAIN,this.renderAgain,this),e.on_(t.ResizeEvent.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 b(t,e){let n;const{rows:i,decorationY:a,decorationHeight:o}=t.__.__textDrawData;for(let t=0,s=i.length;t<s;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)})),a&&e.fillRect(n.x,n.y+a,n.width,o)}function B(t,e,n){const{strokeAlign:i}=e.__,a="string"!=typeof t;switch(i){case"center":n.setStroke(a?void 0:t,e.__.strokeWidth,e.__),a?L(t,!0,e,n):R(e,n);break;case"inside":E("inside",t,a,e,n);break;case"outside":E("outside",t,a,e,n)}}function E(t,e,n,i,a){const{__strokeWidth:o,__font:s}=i.__,r=a.getSameCanvas(!0,!0);r.setStroke(n?void 0:e,2*o,i.__),r.font=s,n?L(e,!0,i,r):R(i,r),r.blendMode="outside"===t?"destination-out":"destination-in",b(i,r),r.blendMode="normal",i.__worldFlipped?a.copyWorldByReset(r,i.__nowWorld):a.copyWorldToInner(r,i.__nowWorld,i.__layout.renderBounds),r.recycle(i.__nowWorld)}function R(t,e){let n;const{rows:i,decorationY:a,decorationHeight:o}=t.__.__textDrawData;for(let t=0,s=i.length;t<s;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)})),a&&e.strokeRect(n.x,n.y+a,n.width,o)}function L(t,e,i,a){let o;for(let s=0,r=t.length;s<r;s++)o=t[s],o.image&&n.PaintImage.checkImage(i,a,o,!1)||o.style&&(a.strokeStyle=o.style,o.blendMode?(a.saveBlendMode(o.blendMode),e?R(i,a):a.stroke(),a.restoreBlendMode()):e?R(i,a):a.stroke())}Object.assign(t.Creator,{watcher:(t,e)=>new r(t,e),layouter:(t,e)=>new y(t,e),renderer:(t,e,n)=>new x(t,e,n),selector:(t,e)=>{},interaction:(t,e,n,i)=>{}}),t.Platform.layout=y.fullLayout;const{getSpread:k,getOuterOf:S,getByMove:P,getIntersectData:C}=t.BoundsHelper;let O;function A(t,e,i){if("object"!=typeof e||!1===e.visible||0===e.opacity)return;const{boxBounds:a}=i.__layout;switch(e.type){case"solid":let{type:o,blendMode:s,color:r,opacity:l}=e;return{type:o,blendMode:s,style:n.ColorConvert.string(r,l)};case"image":return n.PaintImage.image(i,t,e,a,!O||!O[e.url]);case"linear":return n.PaintGradient.linearGradient(e,a);case"radial":return n.PaintGradient.radialGradient(e,a);case"angular":return n.PaintGradient.conicGradient(e,a);default:return void 0!==e.r?{type:"solid",style:n.ColorConvert.string(e)}:void 0}}const W={compute:function(t,e){const i=e.__,a=[];let o,s=i.__input[t];s instanceof Array||(s=[s]),O=n.PaintImage.recycleImage(t,i);for(let n,i=0,o=s.length;i<o;i++)n=A(t,s[i],e),n&&a.push(n);i["_"+t]=a.length?a:void 0,a.length&&a[0].image&&(o=a[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=o:i.__pixelStroke=o},fill:function(t,e,n){n.fillStyle=t,e.__.__font?b(e,n):e.__.windingRule?n.fill(e.__.windingRule):n.fill()},fills:function(t,e,i){let a;const{windingRule:o,__font:s}=e.__;for(let r=0,l=t.length;r<l;r++)a=t[r],a.image&&n.PaintImage.checkImage(e,i,a,!s)||a.style&&(i.fillStyle=a.style,a.transform?(i.save(),i.transform(a.transform),a.blendMode&&(i.blendMode=a.blendMode),s?b(e,i):o?i.fill(o):i.fill(),i.restore()):a.blendMode?(i.saveBlendMode(a.blendMode),s?b(e,i):o?i.fill(o):i.fill(),i.restoreBlendMode()):s?b(e,i):o?i.fill(o):i.fill())},fillText:b,stroke:function(t,e,n){const i=e.__,{__strokeWidth:a,strokeAlign:o,__font:s}=i;if(a)if(s)B(t,e,n);else switch(o){case"center":n.setStroke(t,a,i),n.stroke();break;case"inside":n.save(),n.setStroke(t,2*a,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*a,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:a,strokeAlign:o,__font:s}=i;if(a)if(s)B(t,e,n);else switch(o){case"center":n.setStroke(void 0,a,i),L(t,!1,e,n);break;case"inside":n.save(),n.setStroke(void 0,2*a,i),i.windingRule?n.clip(i.windingRule):n.clip(),L(t,!1,e,n),n.restore();break;case"outside":const{renderBounds:o}=e.__layout,s=n.getSameCanvas(!0,!0);e.__drawRenderPath(s),s.setStroke(void 0,2*a,i),L(t,!1,e,s),i.windingRule?s.clip(i.windingRule):s.clip(),s.clearWorld(o),e.__worldFlipped?n.copyWorldByReset(s,e.__nowWorld):n.copyWorldToInner(s,e.__nowWorld,o),s.recycle(e.__nowWorld)}},strokeText:B,drawTextStroke:R,shape:function(t,e,n){const i=e.getSameCanvas(),a=t.__nowWorld;let o,s,r,l,{scaleX:d,scaleY:c}=a;if(d<0&&(d=-d),c<0&&(c=-c),e.bounds.includes(a))l=i,o=r=a;else{const{renderShapeSpread:i}=t.__layout,h=C(i?k(e.bounds,d===c?i*d:[i*c,i*d]):e.bounds,a);s=e.bounds.getFitMatrix(h);let{a:u,d:f}=s;if(s.a<1&&(l=e.getSameCanvas(),t.__renderShape(l,n),d*=u,c*=f),r=S(a,s),o=P(r,-s.e,-s.f),n.matrix){const{matrix:t}=n;s.multiply(t),u*=t.scaleX,f*=t.scaleY}n=Object.assign(Object.assign({},n),{matrix:s.withScale(u,f)})}return t.__renderShape(i,n),{canvas:i,matrix:s,bounds:o,worldCanvas:l,shapeBounds:r,scaleX:d,scaleY:c}}};let T={};const{get:M,rotateOfOuter:I,translate:D,scaleOfOuter:H,scale:F,rotate:Y}=t.MatrixHelper;function j(t,e,n,i,a,o,s){const r=M();D(r,e.x+n,e.y+i),F(r,a,o),s&&I(r,{x:e.x+e.width/2,y:e.y+e.height/2},s),t.transform=r}function U(t,e,n,i,a,o,s){const r=M();D(r,e.x+n,e.y+i),a&&F(r,a,o),s&&Y(r,s),t.transform=r}function G(t,e,n,i,a,o,s,r,l,d){const c=M();if(l)if("center"===d)I(c,{x:n/2,y:i/2},l);else switch(Y(c,l),l){case 90:D(c,i,0);break;case 180:D(c,n,i);break;case 270:D(c,0,n)}T.x=e.x+a,T.y=e.y+o,D(c,T.x,T.y),s&&H(c,T,s,r),t.transform=c}const{get:X,translate:N}=t.MatrixHelper,q=new t.Bounds,V={},z={};function Q(t,e,n,i){const{blendMode:a,sync:o}=n;a&&(t.blendMode=a),o&&(t.sync=o),t.data=J(n,i,e)}function J(e,n,i){let{width:a,height:o}=i;e.padding&&(n=q.set(n).shrink(e.padding)),"strench"===e.mode&&(e.mode="stretch");const{opacity:s,mode:r,align:l,offset:d,scale:c,size:h,rotation:u,repeat:f}=e,p=n.width===a&&n.height===o,g={mode:r},_="center"!==l&&(u||0)%180==90,w=_?o:a,m=_?a:o;let y,v,x=0,b=0;if(r&&"cover"!==r&&"fit"!==r)(c||h)&&(t.MathHelper.getScaleData(c,h,i,z),y=z.scaleX,v=z.scaleY);else if(!p||u){const t=n.width/w,e=n.height/m;y=v="fit"===r?Math.min(t,e):Math.max(t,e),x+=(n.width-a*y)/2,b+=(n.height-o*v)/2}if(l){const e={x:x,y:b,width:w,height:m};y&&(e.width*=y,e.height*=v),t.AlignHelper.toPoint(l,e,n,V,!0),x+=V.x,b+=V.y}switch(d&&(x+=d.x,b+=d.y),r){case"stretch":p||(a=n.width,o=n.height);break;case"normal":case"clip":(x||b||y||u)&&U(g,n,x,b,y,v,u);break;case"repeat":(!p||y||u)&&G(g,n,a,o,x,b,y,v,u,l),f||(g.repeat="repeat");break;default:y&&j(g,n,x,b,y,v,u)}return g.transform||(n.x||n.y)&&(g.transform=X(),N(g.transform,n.x,n.y)),y&&"stretch"!==r&&(g.scaleX=y,g.scaleY=v),g.width=a,g.height=o,s&&(g.opacity=s),f&&(g.repeat="string"==typeof f?"x"===f?"repeat-x":"repeat-y":"repeat"),g}let Z,K=new t.Bounds;const{isSame:$}=t.BoundsHelper;function tt(t,e,n,i,a,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 a.data||Q(a,i,n,o),!0}function et(e,n){at(e,t.ImageEvent.LOAD,n)}function nt(e,n){at(e,t.ImageEvent.LOADED,n)}function it(e,n,i){n.error=i,e.forceUpdate("surface"),at(e,t.ImageEvent.ERROR,n)}function at(e,n,i){e.hasEvent(n)&&e.emitEvent(new t.ImageEvent(n,i))}function ot(t,e){const{leafer:n}=t;n&&n.viewReady&&(n.renderer.ignore=e)}const{get:st,scale:rt,copy:lt}=t.MatrixHelper,{ceil:dt,abs:ct}=Math;function ht(e,n,i){let{scaleX:a,scaleY:o}=t.ImageManager.patternLocked?e.__world:e.__nowWorld;const s=a+"-"+o+"-"+i;if(n.patternId===s||e.destroyed)return!1;{a=ct(a),o=ct(o);const{image:e,data:r}=n;let l,d,{width:c,height:h,scaleX:u,scaleY:f,opacity:p,transform:g,repeat:_}=r;u&&(d=st(),lt(d,g),rt(d,1/u,1/f),a*=u,o*=f),a*=i,o*=i,c*=a,h*=o;const w=c*h;if(!_&&w>t.Platform.image.maxCacheSize)return!1;let m=t.Platform.image.maxPatternSize;if(!e.isSVG){const t=e.width*e.height;m>t&&(m=t)}w>m&&(l=Math.sqrt(w/m)),l&&(a/=l,o/=l,c/=l,h/=l),u&&(a/=u,o/=f),(g||1!==a||1!==o)&&(d||(d=st(),g&&lt(d,g)),rt(d,1/a,1/o));const y=e.getCanvas(dt(c)||1,dt(h)||1,p),v=e.getPattern(y,_||t.Platform.origin.noRepeat||"no-repeat",d,n);return n.style=v,n.patternId=s,!0}}const{abs:ut}=Math;const ft={image:function(e,n,i,a,o){let s,r;const l=t.ImageManager.get(i);return Z&&i===Z.paint&&$(a,Z.boxBounds)?s=Z.leafPaint:(s={type:i.type,image:l},Z=l.use>1?{leafPaint:s,paint:i,boxBounds:K.set(a)}:null),(o||l.loading)&&(r={image:l,attrName:n,attrValue:i}),l.ready?(tt(e,n,i,l,s,a),o&&(et(e,r),nt(e,r))):l.error?o&&it(e,r,l.error):(ot(e,!0),o&&et(e,r),s.loadId=l.load((()=>{ot(e,!1),e.destroyed||(tt(e,n,i,l,s,a)&&(l.hasOpacityPixel&&(e.__layout.hitCanvasChanged=!0),e.forceUpdate("surface")),nt(e,r)),s.loadId=null}),(t=>{ot(e,!1),it(e,r,t),s.loadId=null}))),s},checkImage:function(e,a,o,s){const{scaleX:r,scaleY:l}=t.ImageManager.patternLocked?e.__world:e.__nowWorld,{pixelRatio:d}=a;if(!o.data||o.patternId===r+"-"+l+"-"+d&&!n.Export.running)return!1;{const{data:c}=o;if(s)if(c.repeat)s=!1;else{let{width:e,height:i}=c;e*=ut(r)*d,i*=ut(l)*d,c.scaleX&&(e*=c.scaleX,i*=c.scaleY),s=e*i>t.Platform.image.maxCacheSize||n.Export.running}return s?(a.save(),a.clip(),o.blendMode&&(a.blendMode=o.blendMode),c.opacity&&(a.opacity*=c.opacity),c.transform&&a.transform(c.transform),a.drawImage(o.image.view,0,0,c.width,c.height),a.restore(),!0):(!o.style||o.sync||n.Export.running?ht(e,o,d):o.patternTask||(o.patternTask=t.ImageManager.patternTasker.add((()=>i(this,void 0,void 0,(function*(){o.patternTask=null,a.bounds.hit(e.__nowWorld)&&ht(e,o,d),e.forceUpdate("surface")}))),300)),!1)}},createPattern:ht,recycleImage:function(e,n){const i=n["_"+e];if(i instanceof Array){let a,o,s,r;for(let l=0,d=i.length;l<d;l++)a=i[l].image,r=a&&a.url,r&&(o||(o={}),o[r]=!0,t.ImageManager.recycle(a),a.loading&&(s||(s=n.__input&&n.__input[e]||[],s instanceof Array||(s=[s])),a.unload(i[l].loadId,!s.some((t=>t.url===r)))));return o}return null},createData:Q,getPatternData:J,fillOrFitMode:j,clipMode:U,repeatMode:G},{toPoint:pt}=t.AroundHelper,gt={},_t={};function wt(t,e,i){if(e){let a;for(let o=0,s=e.length;o<s;o++)a=e[o],"string"==typeof a?t.addColorStop(o/(s-1),n.ColorConvert.string(a,i)):t.addColorStop(a.offset,n.ColorConvert.string(a.color,i))}}const{getAngle:mt,getDistance:yt}=t.PointHelper,{get:vt,rotateOfOuter:xt,scaleOfOuter:bt}=t.MatrixHelper,{toPoint:Bt}=t.AroundHelper,Et={},Rt={};function Lt(t,e,n,i,a){let o;const{width:s,height:r}=t;if(s!==r||i){const t=mt(e,n);o=vt(),a?(bt(o,e,s/r*(i||1),1),xt(o,e,t+90)):(bt(o,e,1,s/r*(i||1)),xt(o,e,t))}return o}const{getDistance:kt}=t.PointHelper,{toPoint:St}=t.AroundHelper,Pt={},Ct={};const Ot={linearGradient:function(e,n){let{from:i,to:a,type:o,blendMode:s,opacity:r}=e;pt(i||"top",n,gt),pt(a||"bottom",n,_t);const l=t.Platform.canvas.createLinearGradient(gt.x,gt.y,_t.x,_t.y);wt(l,e.stops,r);const d={type:o,style:l};return s&&(d.blendMode=s),d},radialGradient:function(e,n){let{from:i,to:a,type:o,opacity:s,blendMode:r,stretch:l}=e;Bt(i||"center",n,Et),Bt(a||"bottom",n,Rt);const d=t.Platform.canvas.createRadialGradient(Et.x,Et.y,0,Et.x,Et.y,yt(Et,Rt));wt(d,e.stops,s);const c={type:o,style:d},h=Lt(n,Et,Rt,l,!0);return h&&(c.transform=h),r&&(c.blendMode=r),c},conicGradient:function(e,n){let{from:i,to:a,type:o,opacity:s,blendMode:r,stretch:l}=e;St(i||"center",n,Pt),St(a||"bottom",n,Ct);const d=t.Platform.conicGradientSupport?t.Platform.canvas.createConicGradient(0,Pt.x,Pt.y):t.Platform.canvas.createRadialGradient(Pt.x,Pt.y,0,Pt.x,Pt.y,kt(Pt,Ct));wt(d,e.stops,s);const c={type:o,style:d},h=Lt(n,Pt,Ct,l||1,t.Platform.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:Lt},{copy:At,toOffsetOutBounds:Wt}=t.BoundsHelper,Tt={},Mt={};function It(e,n,i,a){const{bounds:o,shapeBounds:s}=a;if(t.Platform.fullImageShadow){if(At(Tt,e.bounds),Tt.x+=n.x-s.x,Tt.y+=n.y-s.y,i){const{matrix:t}=a;Tt.x-=(o.x+(t?t.e:0)+o.width/2)*(i-1),Tt.y-=(o.y+(t?t.f:0)+o.height/2)*(i-1),Tt.width*=i,Tt.height*=i}e.copyWorld(a.canvas,e.bounds,Tt)}else i&&(At(Tt,n),Tt.x-=n.width/2*(i-1),Tt.y-=n.height/2*(i-1),Tt.width*=i,Tt.height*=i),e.copyWorld(a.canvas,s,i?Tt:n)}const{toOffsetOutBounds:Dt}=t.BoundsHelper,Ht={};const Ft={shadow:function(t,e,n){let i,a;const{__nowWorld:o,__layout:s}=t,{shadow:r}=t.__,{worldCanvas:l,bounds:d,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;Wt(d,Mt),r.forEach(((r,g)=>{f.setWorldShadow(Mt.offsetX+r.x*h,Mt.offsetY+r.y*u,r.blur*h,r.color),a=r.spread?1+2*r.spread/(s.boxBounds.width+2*(s.strokeBoxSpread||0)):0,It(f,Mt,a,n),i=d,r.box&&(f.restore(),f.save(),l&&(f.copyWorld(f,d,o,"copy"),i=o),l?f.copyWorld(l,o,o,"destination-out"):f.copyWorld(n.canvas,c,d,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,i,o,r.blendMode):e.copyWorldToInner(f,i,s.renderBounds,r.blendMode),p&&g<p&&f.clearWorld(i,!0)})),f.recycle(i)},innerShadow:function(t,e,n){let i,a;const{__nowWorld:o,__layout:s}=t,{innerShadow:r}=t.__,{worldCanvas:l,bounds:d,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;Dt(d,Ht),r.forEach(((r,g)=>{f.save(),f.setWorldShadow(Ht.offsetX+r.x*h,Ht.offsetY+r.y*u,r.blur*h),a=r.spread?1-2*r.spread/(s.boxBounds.width+2*(s.strokeBoxSpread||0)):0,It(f,Ht,a,n),f.restore(),l?(f.copyWorld(f,d,o,"copy"),f.copyWorld(l,o,o,"source-out"),i=o):(f.copyWorld(n.canvas,c,d,"source-out"),i=d),f.fillWorld(i,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,i,o,r.blendMode):e.copyWorldToInner(f,i,s.renderBounds,r.blendMode),p&&g<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:Yt}=t.LeafBoundsHelper;function jt(t,e,n,i,a,o){switch(e){case"alpha":!function(t,e,n,i){const a=t.__nowWorld;n.resetTransform(),n.opacity=1,n.useMask(i,a),i.recycle(a),Gt(t,e,n,1)}(t,n,i,a);break;case"opacity-path":Gt(t,n,i,o);break;case"path":n.restore()}}function Ut(t){return t.getSameCanvas(!1,!0)}function Gt(t,e,n,i){const a=t.__nowWorld;e.resetTransform(),e.opacity=i,e.copyWorld(n,a),n.recycle(a)}n.Group.prototype.__renderMask=function(t,e){let n,i,a,o,s;const{children:r}=this;for(let l=0,d=r.length;l<d;l++)n=r[l],n.__.mask&&(s&&(jt(this,s,t,a,i,o),i=a=null),"path"===n.__.mask?(n.opacity<1?(s="opacity-path",o=n.opacity,a||(a=Ut(t))):(s="path",t.save()),n.__clip(a||t,e)):(s="alpha",i||(i=Ut(t)),a||(a=Ut(t)),n.__render(i,e)),"clipping"!==n.__.mask)||Yt(n,e)||n.__render(a||t,e);jt(this,s,t,a,i,o)};const Xt=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Nt=Xt+"_#~&*+\\=|≮≯≈≠=…",qt=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 Vt(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const zt=Vt("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Qt=Vt("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),Jt=Vt(Xt),Zt=Vt(Nt),Kt=Vt("- —/~|┆·");var $t;!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"}($t||($t={}));const{Letter:te,Single:ee,Before:ne,After:ie,Symbol:ae,Break:oe}=$t;function se(t){return zt[t]?te:Kt[t]?oe:Qt[t]?ne:Jt[t]?ie:Zt[t]?ae:qt.test(t)?ee:te}const re={trimRight(t){const{words:e}=t;let n,i=0,a=e.length;for(let o=a-1;o>-1&&(n=e[o].data[0]," "===n.char);o--)i++,t.width-=n.width;i&&e.splice(a-i,i)}};function le(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:de}=re,{Letter:ce,Single:he,Before:ue,After:fe,Symbol:pe,Break:ge}=$t;let _e,we,me,ye,ve,xe,be,Be,Ee,Re,Le,ke,Se,Pe,Ce,Oe,Ae=[];function We(t,e){Ee&&!Be&&(Be=Ee),_e.data.push({char:t,width:e}),me+=e}function Te(){ye+=me,_e.width=me,we.words.push(_e),_e={data:[]},me=0}function Me(){Pe&&(Ce.paraNumber++,we.paraStart=!0,Pe=!1),Ee&&(we.startCharSize=Be,we.endCharSize=Ee,Be=0),we.width=ye,Oe.width&&de(we),Ae.push(we),we={words:[]},ye=0}const Ie=0,De=1,He=2;const{top:Fe,right:Ye,bottom:je,left:Ue}=t.Direction4;function Ge(t,e,n){const{bounds:i,rows:a}=t;i[e]+=n;for(let t=0;t<a.length;t++)a[t][e]+=n}const Xe={getDrawData:function(e,n){"string"!=typeof e&&(e=String(e));let i=0,a=0,o=n.__getInput("width")||0,s=n.__getInput("height")||0;const{textDecoration:r,__font:l,__padding:d}=n;d&&(o&&(i=d[Ue],o-=d[Ye]+d[Ue]),s&&(a=d[Fe],s-=d[Fe]+d[je]));const c={bounds:{x:i,y:a,width:o,height:s},rows:[],paraNumber:0,font:t.Platform.canvas.font=l};return function(e,n,i){Ce=e,Ae=e.rows,Oe=e.bounds;const{__letterSpacing:a,paraIndent:o,textCase:s}=i,{canvas:r}=t.Platform,{width:l,height:d}=Oe;if(l||d||a||"none"!==s){const t="none"!==i.textWrap,e="break"===i.textWrap;Pe=!0,Le=null,Be=be=Ee=me=ye=0,_e={data:[]},we={words:[]};for(let i=0,d=n.length;i<d;i++)xe=n[i],"\n"===xe?(me&&Te(),we.paraEnd=!0,Me(),Pe=!0):(Re=se(xe),Re===ce&&"none"!==s&&(xe=le(xe,s,!me)),be=r.measureText(xe).width,a&&(a<0&&(Ee=be),be+=a),ke=Re===he&&(Le===he||Le===ce)||Le===he&&Re!==fe,Se=!(Re!==ue&&Re!==he||Le!==pe&&Le!==fe),ve=Pe&&o?l-o:l,t&&l&&ye+me+be>ve&&(e?(me&&Te(),ye&&Me()):(Se||(Se=Re===ce&&Le==fe),ke||Se||Re===ge||Re===ue||Re===he||me+be>ve?(me&&Te(),ye&&Me()):ye&&Me()))," "===xe&&!0!==Pe&&ye+me===0||(Re===ge?(" "===xe&&me&&Te(),We(xe,be),Te()):ke||Se?(me&&Te(),We(xe,be)):We(xe,be)),Le=Re);me&&Te(),ye&&Me(),Ae.length>0&&(Ae[Ae.length-1].paraEnd=!0)}else n.split("\n").forEach((t=>{Ce.paraNumber++,Ae.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(c,e,n),d&&function(t,e,n,i,a){if(!i)switch(n.textAlign){case"left":Ge(e,"x",t[Ue]);break;case"right":Ge(e,"x",-t[Ye])}if(!a)switch(n.verticalAlign){case"top":Ge(e,"y",t[Fe]);break;case"bottom":Ge(e,"y",-t[je])}}(d,c,n,o,s),function(t,e){const{rows:n,bounds:i}=t,{__lineHeight:a,__baseLine:o,__letterSpacing:s,__clipText:r,textAlign:l,verticalAlign:d,paraSpacing:c}=e;let h,u,f,{x:p,y:g,width:_,height:w}=i,m=a*n.length+(c?c*(t.paraNumber-1):0),y=o;if(r&&m>w)m=Math.max(w,a),t.overflow=n.length;else switch(d){case"middle":g+=(w-m)/2;break;case"bottom":g+=w-m}y+=g;for(let o=0,d=n.length;o<d;o++){if(h=n[o],h.x=p,h.width<_||h.width>_&&!r)switch(l){case"center":h.x+=(_-h.width)/2;break;case"right":h.x+=_-h.width}h.paraStart&&c&&o>0&&(y+=c),h.y=y,y+=a,t.overflow>o&&y>m&&(h.isOverflow=!0,t.overflow=o+1),u=h.x,f=h.width,s<0&&(h.width<0?(f=-h.width+e.fontSize+s,u-=f,f+=e.fontSize):f-=s),u<i.x&&(i.x=u),f>i.width&&(i.width=f),r&&_&&_<f&&(h.isOverflow=!0,t.overflow||(t.overflow=n.length))}i.y=g,i.height=m}(c,n),function(t,e,n,i){const{rows:a}=t,{textAlign:o,paraIndent:s,letterSpacing:r}=e;let l,d,c,h,u;a.forEach((t=>{t.words&&(c=s&&t.paraStart?s:0,d=n&&"justify"===o&&t.words.length>1?(n-t.width-c)/(t.words.length-1):0,h=r||t.isOverflow?Ie:d>.01?De:He,t.isOverflow&&!r&&(t.textMode=!0),h===He?(t.x+=c,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=c,l=t.x,t.data=[],t.words.forEach((e=>{h===De?(u={char:"",x:l},l=function(t,e,n){return t.forEach((t=>{n.char+=t.char,e+=t.width})),e}(e.data,l,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):l=function(t,e,n,i){return t.forEach((t=>{(i||" "!==t.char)&&(t.x=e,n.push(t)),e+=t.width})),e}(e.data,l,t.data,t.isOverflow),!t.paraEnd&&d&&(l+=d,t.width+=d)}))),t.words=null)}))}(c,n,o),c.overflow&&function(e,n,i,a){if(!a)return;const{rows:o,overflow:s}=e;let{textOverflow:r}=n;if(o.splice(s),r&&"show"!==r){let e,l;"hide"===r?r="":"ellipsis"===r&&(r="...");const d=r?t.Platform.canvas.measureText(r).width:0,c=i+a-d;("none"===n.textWrap?o:[o[s-1]]).forEach((t=>{if(t.isOverflow&&t.data){let n=t.data.length-1;for(let i=n;i>-1&&(e=t.data[i],l=e.x+e.width,!(i===n&&l<c));i--){if(l<c&&" "!==e.char){t.data.splice(i+1),t.width-=e.width;break}t.width-=e.width}t.width+=d,t.data.push({char:r,x:l}),t.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(t)}}))}}(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 Ne={string:function(t,e){const i="number"==typeof e&&1!==e;if("string"==typeof t){if(!i||!n.ColorConvert.object)return t;t=n.ColorConvert.object(t)}let a=void 0===t.a?1:t.a;i&&(a*=e);const o=t.r+","+t.g+","+t.b;return 1===a?"rgb("+o+")":"rgba("+o+","+a+")"}},{setPoint:qe,addPoint:Ve,toBounds:ze}=t.TwoPointBoundsHelper;const Qe={export(e,n,a){this.running=!0;const o=t.FileHelper.fileType(n),s=n.includes(".");return a=t.FileHelper.getExportOptions(a),function(e){Je||(Je=new t.TaskProcessor);return new Promise((t=>{Je.add((()=>i(this,void 0,void 0,(function*(){return yield e(t)}))),{parallel:!1})}))}((r=>new Promise((l=>{const d=t=>{r(t),l(),this.running=!1},{toURL:c}=t.Platform,{download:h}=t.Platform.origin;if("json"===o)return s&&h(c(JSON.stringify(e.toJSON(a.json)),"text"),n),d({data:!!s||e.toJSON(a.json)});if("svg"===o)return s&&h(c(e.toSVG(),"svg"),n),d({data:!!s||e.toSVG()});const{leafer:u}=e;u?(Ze(e),u.waitViewCompleted((()=>i(this,void 0,void 0,(function*(){let i,o,s=1,r=1;const{worldTransform:l,isLeafer:c,isFrame:h}=e,{slice:f,trim:p,onCanvas:g}=a,_=void 0===a.smooth?u.config.smooth:a.smooth,w=a.contextSettings||u.config.contextSettings,m=a.screenshot||e.isApp,y=c&&m&&void 0===a.fill?e.fill:a.fill,v=t.FileHelper.isOpaqueImage(n)||y,x=new t.Matrix;if(m)i=!0===m?c?u.canvas.bounds:e.worldRenderBounds:m;else{let t=a.relative||(c?"inner":"local");switch(s=l.scaleX,r=l.scaleY,t){case"inner":x.set(l);break;case"local":x.set(l).divide(e.localTransform),s/=e.scaleX,r/=e.scaleY;break;case"world":s=1,r=1;break;case"page":t=e.leafer;default:x.set(l).divide(e.getTransform(t));const n=t.worldTransform;s/=s/n.scaleX,r/=r/n.scaleY}i=e.getBounds("render",t)}const b={scaleX:1,scaleY:1};t.MathHelper.getScaleData(a.scale,a.size,i,b);let B=a.pixelRatio||1;e.isApp&&(b.scaleX*=B,b.scaleY*=B,B=e.app.pixelRatio);const{x:E,y:R,width:L,height:k}=new t.Bounds(i).scale(b.scaleX,b.scaleY),S={matrix:x.scale(1/b.scaleX,1/b.scaleY).invert().translate(-E,-R).withScale(1/s*b.scaleX,1/r*b.scaleY)};let P,C=t.Creator.canvas({width:Math.round(L),height:Math.round(k),pixelRatio:B,smooth:_,contextSettings:w});if(f&&(P=e,P.__worldOpacity=0,e=u,S.bounds=C.bounds),C.save(),h&&void 0!==y){const t=e.get("fill");e.fill="",e.__render(C,S),e.fill=t}else e.__render(C,S);if(C.restore(),P&&P.__updateWorldOpacity(),p){o=function(e){const{width:n,height:i}=e.view,{data:a}=e.context.getImageData(0,0,n,i);let o,s,r,l=0;for(let t=0;t<a.length;t+=4)0!==a[t+3]&&(o=l%n,s=(l-o)/n,r?Ve(r,o,s):qe(r={},o,s)),l++;const d=new t.Bounds;return ze(r,d),d.scale(1/e.pixelRatio).ceil()}(C);const e=C,{width:n,height:i}=o,a={x:0,y:0,width:n,height:i,pixelRatio:B};C=t.Creator.canvas(a),C.copyWorld(e,o,a)}v&&C.fillWorld(C.bounds,y||"#FFFFFF","destination-over"),g&&g(C);const O="canvas"===n?C:yield C.export(n,a);d({data:O,width:C.pixelWidth,height:C.pixelHeight,renderBounds:i,trimBounds:o})}))))):d({data:!1})}))))}};let Je;function Ze(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Ze(t)))}const Ke=t.LeaferCanvasBase.prototype,$e=t.Debug.get("@leafer-ui/export");Ke.export=function(e,n){const{quality:i,blob:a}=t.FileHelper.getExportOptions(n);return e.includes(".")?this.saveAs(e,i):a?this.toBlob(e,i):this.toDataURL(e,i)},Ke.toBlob=function(e,n){return new Promise((i=>{t.Platform.origin.canvasToBolb(this.view,e,n).then((t=>{i(t)})).catch((t=>{$e.error(t),i(null)}))}))},Ke.toDataURL=function(e,n){return t.Platform.origin.canvasToDataURL(this.view,e,n)},Ke.saveAs=function(e,n){return new Promise((i=>{t.Platform.origin.canvasSaveAs(this.view,e,n).then((()=>{i(!0)})).catch((t=>{$e.error(t),i(!1)}))}))},Object.assign(n.TextConvert,Xe),Object.assign(n.ColorConvert,Ne),Object.assign(n.Paint,W),Object.assign(n.PaintImage,ft),Object.assign(n.PaintGradient,Ot),Object.assign(n.Effect,Ft),Object.assign(n.Export,Qe),Object.defineProperty(exports,"LeaferImage",{enumerable:!0,get:function(){return t.LeaferImage}}),exports.Layouter=y,exports.LeaferCanvas=a,exports.Renderer=x,exports.Watcher=r,exports.useCanvas=function(n,a){if(t.Platform.canvasType=n,!t.Platform.origin){if("skia"===n){const{Canvas:e,loadImage:n}=a;t.Platform.origin={createCanvas:(t,n,i)=>new e(t,n,i),canvasToDataURL:(t,e,n)=>t.toDataURLSync(e,{quality:n}),canvasToBolb:(t,e,n)=>t.toBuffer(e,{quality:n}),canvasSaveAs:(t,e,n)=>t.saveAs(e,{quality:n}),download(t,e){},loadImage:e=>n(t.Platform.image.getRealURL(e))},t.Platform.roundRectPatch=!0}else if("napi"===n){const{Canvas:n,loadImage:r}=a;t.Platform.origin={createCanvas:(t,e,i)=>new n(t,e,i),canvasToDataURL:(t,e,n)=>t.toDataURL(o(e),n),canvasToBolb:(t,e,n)=>i(this,void 0,void 0,(function*(){return t.toBuffer(o(e),n)})),canvasSaveAs:(t,n,a)=>i(this,void 0,void 0,(function*(){return e.writeFileSync(n,t.toBuffer(o(s(n)),a))})),download(t,e){},loadImage:e=>r(t.Platform.image.getRealURL(e))}}t.Platform.ellipseToCurve=!0,t.Platform.event={stopDefault(t){},stopNow(t){},stop(t){}},t.Platform.canvas=t.Creator.canvas()}},Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})})),Object.keys(n).forEach((function(t){"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return n[t]}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-draw/node",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "@leafer-draw/node",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -12,6 +12,8 @@
12
12
  "types": "./types/index.d.ts"
13
13
  },
14
14
  "types": "types/index.d.ts",
15
+ "unpkg": "dist/node.esm.js",
16
+ "jsdelivr": "dist/node.esm.js",
15
17
  "files": [
16
18
  "src",
17
19
  "types",
@@ -31,10 +33,10 @@
31
33
  "leaferjs"
32
34
  ],
33
35
  "dependencies": {
34
- "@leafer/node": "1.0.1",
35
- "@leafer-draw/partner": "1.0.1",
36
- "@leafer-ui/draw": "1.0.1",
37
- "@leafer-ui/partner": "1.0.1",
38
- "@leafer-ui/interface": "1.0.1"
36
+ "@leafer/node": "1.0.3",
37
+ "@leafer-draw/partner": "1.0.3",
38
+ "@leafer-ui/draw": "1.0.3",
39
+ "@leafer-ui/partner": "1.0.3",
40
+ "@leafer-ui/interface": "1.0.3"
39
41
  }
40
42
  }