@leafer-draw/worker 1.0.0-rc.19 → 1.0.0-rc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  const Platform = {
2
2
  image: {
3
+ hitCanvasSize: 100,
3
4
  maxCacheSize: 2560 * 1600,
4
5
  maxPatternSize: 4096 * 2160,
5
6
  suffix: 'leaf',
@@ -41,7 +42,7 @@ const MathHelper = {
41
42
  minus(value, isFourNumber) {
42
43
  if (value instanceof Array) {
43
44
  if (isFourNumber)
44
- value = MathHelper.fourNumber(value);
45
+ value = MathHelper.fourNumber(value, 0);
45
46
  for (let i = 0; i < value.length; i++)
46
47
  value[i] = -value[i];
47
48
  }
@@ -55,7 +56,7 @@ const MathHelper = {
55
56
  if (num instanceof Array) {
56
57
  switch (num.length) {
57
58
  case 4:
58
- data = num;
59
+ data = maxValue === undefined ? num : [...num];
59
60
  break;
60
61
  case 2:
61
62
  data = [num[0], num[1], num[0], num[1]];
@@ -116,7 +117,7 @@ function getMatrixData() { return { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }; }
116
117
 
117
118
  const { sin: sin$5, cos: cos$5, acos, sqrt: sqrt$3 } = Math;
118
119
  const { float: float$1 } = MathHelper;
119
- const tempPoint$2 = {};
120
+ const tempPoint$3 = {};
120
121
  function getWorld() {
121
122
  return Object.assign(Object.assign(Object.assign({}, getMatrixData()), getBoundsData()), { scaleX: 1, scaleY: 1, rotation: 0, skewX: 0, skewY: 0 });
122
123
  }
@@ -157,8 +158,8 @@ const MatrixHelper = {
157
158
  t.d *= scaleY;
158
159
  },
159
160
  scaleOfOuter(t, origin, scaleX, scaleY) {
160
- M$6.toInnerPoint(t, origin, tempPoint$2);
161
- M$6.scaleOfInner(t, tempPoint$2, scaleX, scaleY);
161
+ M$6.toInnerPoint(t, origin, tempPoint$3);
162
+ M$6.scaleOfInner(t, tempPoint$3, scaleX, scaleY);
162
163
  },
163
164
  scaleOfInner(t, origin, scaleX, scaleY = scaleX) {
164
165
  M$6.translateInner(t, origin.x, origin.y);
@@ -176,8 +177,8 @@ const MatrixHelper = {
176
177
  t.d = c * sinR + d * cosR;
177
178
  },
178
179
  rotateOfOuter(t, origin, rotation) {
179
- M$6.toInnerPoint(t, origin, tempPoint$2);
180
- M$6.rotateOfInner(t, tempPoint$2, rotation);
180
+ M$6.toInnerPoint(t, origin, tempPoint$3);
181
+ M$6.rotateOfInner(t, tempPoint$3, rotation);
181
182
  },
182
183
  rotateOfInner(t, origin, rotation) {
183
184
  M$6.translateInner(t, origin.x, origin.y);
@@ -198,8 +199,8 @@ const MatrixHelper = {
198
199
  }
199
200
  },
200
201
  skewOfOuter(t, origin, skewX, skewY) {
201
- M$6.toInnerPoint(t, origin, tempPoint$2);
202
- M$6.skewOfInner(t, tempPoint$2, skewX, skewY);
202
+ M$6.toInnerPoint(t, origin, tempPoint$3);
203
+ M$6.skewOfInner(t, tempPoint$3, skewX, skewY);
203
204
  },
204
205
  skewOfInner(t, origin, skewX, skewY = 0) {
205
206
  M$6.translateInner(t, origin.x, origin.y);
@@ -446,19 +447,19 @@ const PointHelper = {
446
447
  },
447
448
  tempToInnerOf(t, matrix) {
448
449
  const { tempPoint: temp } = P$5;
449
- copy$9(temp, t);
450
+ copy$a(temp, t);
450
451
  toInnerPoint$2(matrix, temp, temp);
451
452
  return temp;
452
453
  },
453
454
  tempToOuterOf(t, matrix) {
454
455
  const { tempPoint: temp } = P$5;
455
- copy$9(temp, t);
456
+ copy$a(temp, t);
456
457
  toOuterPoint$2(matrix, temp, temp);
457
458
  return temp;
458
459
  },
459
460
  tempToInnerRadiusPointOf(t, matrix) {
460
461
  const { tempRadiusPoint: temp } = P$5;
461
- copy$9(temp, t);
462
+ copy$a(temp, t);
462
463
  P$5.toInnerRadiusPointOf(t, matrix, temp);
463
464
  return temp;
464
465
  },
@@ -525,7 +526,7 @@ const PointHelper = {
525
526
  }
526
527
  };
527
528
  const P$5 = PointHelper;
528
- const { getDistanceFrom, copy: copy$9, getAtan2 } = P$5;
529
+ const { getDistanceFrom, copy: copy$a, getAtan2 } = P$5;
529
530
 
530
531
  class Point {
531
532
  constructor(x, y) {
@@ -593,6 +594,7 @@ class Point {
593
594
  return this;
594
595
  }
595
596
  }
597
+ const tempPoint$2 = new Point();
596
598
 
597
599
  class Matrix {
598
600
  constructor(a, b, c, d, e, f) {
@@ -602,6 +604,12 @@ class Matrix {
602
604
  typeof a === 'object' ? MatrixHelper.copy(this, a) : MatrixHelper.set(this, a, b, c, d, e, f);
603
605
  return this;
604
606
  }
607
+ setWith(dataWithScale) {
608
+ MatrixHelper.copy(this, dataWithScale);
609
+ this.scaleX = dataWithScale.scaleX;
610
+ this.scaleY = dataWithScale.scaleY;
611
+ return this;
612
+ }
605
613
  get() {
606
614
  const { a, b, c, d, e, f } = this;
607
615
  return { a, b, c, d, e, f };
@@ -621,6 +629,12 @@ class Matrix {
621
629
  MatrixHelper.scale(this, x, y);
622
630
  return this;
623
631
  }
632
+ scaleWith(x, y) {
633
+ MatrixHelper.scale(this, x, y);
634
+ this.scaleX *= x;
635
+ this.scaleY *= y || x;
636
+ return this;
637
+ }
624
638
  scaleOfOuter(origin, x, y) {
625
639
  MatrixHelper.scaleOfOuter(this, origin, x, y);
626
640
  return this;
@@ -673,6 +687,12 @@ class Matrix {
673
687
  MatrixHelper.invert(this);
674
688
  return this;
675
689
  }
690
+ invertWith() {
691
+ MatrixHelper.invert(this);
692
+ this.scaleX = 1 / this.scaleX;
693
+ this.scaleY = 1 / this.scaleY;
694
+ return this;
695
+ }
676
696
  toOuterPoint(inner, to, distance) {
677
697
  MatrixHelper.toOuterPoint(this, inner, to, distance);
678
698
  }
@@ -693,6 +713,7 @@ class Matrix {
693
713
  MatrixHelper.reset(this);
694
714
  }
695
715
  }
716
+ const tempMatrix = new Matrix();
696
717
 
697
718
  const TwoPointBoundsHelper = {
698
719
  tempPointBounds: {},
@@ -781,7 +802,7 @@ const BoundsHelper = {
781
802
  to = t;
782
803
  }
783
804
  else {
784
- copy$8(to, t);
805
+ copy$9(to, t);
785
806
  }
786
807
  if (parent) {
787
808
  to.offsetX = -(B.maxX(parent) - t.x);
@@ -856,8 +877,8 @@ const BoundsHelper = {
856
877
  B.move(to, -matrix.e, -matrix.f);
857
878
  B.scale(to, 1 / matrix.a, 1 / matrix.d);
858
879
  },
859
- getFitMatrix(t, put) {
860
- const scale = Math.min(1, Math.min(t.width / put.width, t.height / put.height));
880
+ getFitMatrix(t, put, baseScale = 1) {
881
+ const scale = Math.min(baseScale, Math.min(t.width / put.width, t.height / put.height));
861
882
  return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
862
883
  },
863
884
  getSpread(t, spreadX, spreadY) {
@@ -891,11 +912,15 @@ const BoundsHelper = {
891
912
  t.width = float(t.width, maxLength);
892
913
  t.height = float(t.height, maxLength);
893
914
  },
894
- add(t, bounds) {
915
+ add(t, bounds, isPoint) {
895
916
  right$1 = t.x + t.width;
896
917
  bottom$1 = t.y + t.height;
897
- boundsRight = bounds.x + bounds.width;
898
- boundsBottom = bounds.y + bounds.height;
918
+ boundsRight = bounds.x;
919
+ boundsBottom = bounds.y;
920
+ if (!isPoint) {
921
+ boundsRight += bounds.width;
922
+ boundsBottom += bounds.height;
923
+ }
899
924
  right$1 = right$1 > boundsRight ? right$1 : boundsRight;
900
925
  bottom$1 = bottom$1 > boundsBottom ? bottom$1 : boundsBottom;
901
926
  t.x = t.x < bounds.x ? t.x : bounds.x;
@@ -920,7 +945,7 @@ const BoundsHelper = {
920
945
  if (first) {
921
946
  first = false;
922
947
  if (!addMode)
923
- copy$8(t, bounds);
948
+ copy$9(t, bounds);
924
949
  }
925
950
  else {
926
951
  add$1(t, bounds);
@@ -934,6 +959,9 @@ const BoundsHelper = {
934
959
  points.forEach((point, index) => index === 0 ? setPoint$3(tempPointBounds$1, point.x, point.y) : addPoint$3(tempPointBounds$1, point.x, point.y));
935
960
  toBounds$4(tempPointBounds$1, t);
936
961
  },
962
+ addPoint(t, point) {
963
+ add$1(t, point, true);
964
+ },
937
965
  getPoints(t) {
938
966
  const { x, y, width, height } = t;
939
967
  return [
@@ -995,7 +1023,7 @@ const BoundsHelper = {
995
1023
  }
996
1024
  };
997
1025
  const B = BoundsHelper;
998
- const { add: add$1, copy: copy$8 } = B;
1026
+ const { add: add$1, copy: copy$9 } = B;
999
1027
 
1000
1028
  class Bounds {
1001
1029
  get minX() { return BoundsHelper.minX(this); }
@@ -1036,8 +1064,8 @@ class Bounds {
1036
1064
  BoundsHelper.toInnerOf(this, matrix, to);
1037
1065
  return this;
1038
1066
  }
1039
- getFitMatrix(put) {
1040
- return BoundsHelper.getFitMatrix(this, put);
1067
+ getFitMatrix(put, baseScale) {
1068
+ return BoundsHelper.getFitMatrix(this, put, baseScale);
1041
1069
  }
1042
1070
  spread(fourNumber, spreadY) {
1043
1071
  BoundsHelper.spread(this, fourNumber, spreadY);
@@ -1083,6 +1111,10 @@ class Bounds {
1083
1111
  BoundsHelper.setPoints(this, points);
1084
1112
  return this;
1085
1113
  }
1114
+ addPoint(point) {
1115
+ BoundsHelper.addPoint(this, point);
1116
+ return this;
1117
+ }
1086
1118
  getPoints() {
1087
1119
  return BoundsHelper.getPoints(this);
1088
1120
  }
@@ -1115,6 +1147,7 @@ class Bounds {
1115
1147
  BoundsHelper.reset(this);
1116
1148
  }
1117
1149
  }
1150
+ const tempBounds$1 = new Bounds();
1118
1151
 
1119
1152
  class AutoBounds {
1120
1153
  constructor(top, right, bottom, left, width, height) {
@@ -1232,7 +1265,8 @@ class Debug {
1232
1265
  this.warn(...messages);
1233
1266
  }
1234
1267
  warn(...messages) {
1235
- console.warn(this.name, ...messages);
1268
+ if (D$4.showWarn)
1269
+ console.warn(this.name, ...messages);
1236
1270
  }
1237
1271
  repeat(name, ...messages) {
1238
1272
  if (!this.repeatMap[name]) {
@@ -1251,6 +1285,7 @@ class Debug {
1251
1285
  }
1252
1286
  Debug.filterList = [];
1253
1287
  Debug.excludeList = [];
1288
+ Debug.showWarn = true;
1254
1289
  function getNameList(name) {
1255
1290
  if (!name)
1256
1291
  name = [];
@@ -1260,7 +1295,7 @@ function getNameList(name) {
1260
1295
  }
1261
1296
  const D$4 = Debug;
1262
1297
 
1263
- const debug$c = Debug.get('RunTime');
1298
+ const debug$d = Debug.get('RunTime');
1264
1299
  const Run = {
1265
1300
  currentId: 0,
1266
1301
  currentName: '',
@@ -1278,7 +1313,7 @@ const Run = {
1278
1313
  const time = R.idMap[id], name = R.nameMap[id];
1279
1314
  const duration = microsecond ? (performance.now() - time) / 1000 : Date.now() - time;
1280
1315
  R.idMap[id] = R.nameMap[id] = R.nameToIdMap[name] = undefined;
1281
- debug$c.log(name, duration, 'ms');
1316
+ debug$d.log(name, duration, 'ms');
1282
1317
  },
1283
1318
  endOfName(name, microsecond) {
1284
1319
  const id = R.nameToIdMap[name];
@@ -1288,13 +1323,13 @@ const Run = {
1288
1323
  };
1289
1324
  const R = Run;
1290
1325
 
1291
- const debug$b = Debug.get('UICreator');
1326
+ const debug$c = Debug.get('UICreator');
1292
1327
  const UICreator = {
1293
1328
  list: {},
1294
1329
  register(UI) {
1295
1330
  const { __tag: tag } = UI.prototype;
1296
1331
  if (list$1[tag]) {
1297
- debug$b.repeat(tag);
1332
+ debug$c.repeat(tag);
1298
1333
  }
1299
1334
  else {
1300
1335
  list$1[tag] = UI;
@@ -1316,7 +1351,7 @@ const UICreator = {
1316
1351
  };
1317
1352
  const { list: list$1 } = UICreator;
1318
1353
 
1319
- const debug$a = Debug.get('EventCreator');
1354
+ const debug$b = Debug.get('EventCreator');
1320
1355
  const EventCreator = {
1321
1356
  nameList: {},
1322
1357
  register(Event) {
@@ -1324,7 +1359,7 @@ const EventCreator = {
1324
1359
  Object.keys(Event).forEach(key => {
1325
1360
  name = Event[key];
1326
1361
  if (typeof name === 'string')
1327
- nameList[name] ? debug$a.repeat(name) : nameList[name] = Event;
1362
+ nameList[name] ? debug$b.repeat(name) : nameList[name] = Event;
1328
1363
  });
1329
1364
  },
1330
1365
  changeName(oldName, newName) {
@@ -1535,36 +1570,7 @@ var Answer;
1535
1570
  Answer[Answer["NoAndSkip"] = 2] = "NoAndSkip";
1536
1571
  Answer[Answer["YesAndSkip"] = 3] = "YesAndSkip";
1537
1572
  })(Answer || (Answer = {}));
1538
-
1539
- const FileHelper = {
1540
- opacityTypes: ['png', 'webp', 'svg'],
1541
- upperCaseTypeMap: {},
1542
- mineType(type) {
1543
- if (!type || type.startsWith('image'))
1544
- return type;
1545
- if (type === 'jpg')
1546
- type = 'jpeg';
1547
- return 'image/' + type;
1548
- },
1549
- fileType(filename) {
1550
- const l = filename.split('.');
1551
- return l[l.length - 1];
1552
- },
1553
- isOpaqueImage(filename) {
1554
- const type = F$4.fileType(filename);
1555
- return ['jpg', 'jpeg'].some(item => item === type);
1556
- },
1557
- getExportOptions(options) {
1558
- switch (typeof options) {
1559
- case 'object': return options;
1560
- case 'number': return { quality: options };
1561
- case 'boolean': return { blob: options };
1562
- default: return {};
1563
- }
1564
- }
1565
- };
1566
- const F$4 = FileHelper;
1567
- F$4.opacityTypes.forEach(type => F$4.upperCaseTypeMap[type] = type.toUpperCase());
1573
+ const emptyData = {};
1568
1574
 
1569
1575
  /******************************************************************************
1570
1576
  Copyright (c) Microsoft Corporation.
@@ -1888,10 +1894,8 @@ __decorate([
1888
1894
  contextMethod()
1889
1895
  ], Canvas$1.prototype, "strokeText", null);
1890
1896
 
1891
- const { copy: copy$7 } = MatrixHelper;
1892
- const temp = new Bounds();
1897
+ const { copy: copy$8 } = MatrixHelper;
1893
1898
  const minSize = { width: 1, height: 1, pixelRatio: 1 };
1894
- const debug$9 = Debug.get('LeaferCanvasBase');
1895
1899
  const canvasSizeAttrs = ['width', 'height', 'pixelRatio'];
1896
1900
  class LeaferCanvasBase extends Canvas$1 {
1897
1901
  get width() { return this.size.width; }
@@ -1918,44 +1922,15 @@ class LeaferCanvasBase extends Canvas$1 {
1918
1922
  }
1919
1923
  init() { }
1920
1924
  __createContext() {
1921
- this.context = this.view.getContext('2d');
1925
+ const { view } = this;
1926
+ const { contextSettings } = this.config;
1927
+ this.context = contextSettings ? view.getContext('2d', contextSettings) : view.getContext('2d');
1922
1928
  this.__bindContext();
1923
1929
  }
1924
- export(filename, options) {
1925
- const { quality, blob } = FileHelper.getExportOptions(options);
1926
- if (filename.includes('.')) {
1927
- return this.saveAs(filename, quality);
1928
- }
1929
- else if (blob) {
1930
- return this.toBlob(filename, quality);
1931
- }
1932
- else {
1933
- return this.toDataURL(filename, quality);
1934
- }
1935
- }
1936
- toBlob(type, quality) {
1937
- return new Promise((resolve) => {
1938
- Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
1939
- resolve(blob);
1940
- }).catch((e) => {
1941
- debug$9.error(e);
1942
- resolve(null);
1943
- });
1944
- });
1945
- }
1946
- toDataURL(type, quality) {
1947
- return Platform.origin.canvasToDataURL(this.view, type, quality);
1948
- }
1949
- saveAs(filename, quality) {
1950
- return new Promise((resolve) => {
1951
- Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
1952
- resolve(true);
1953
- }).catch((e) => {
1954
- debug$9.error(e);
1955
- resolve(false);
1956
- });
1957
- });
1958
- }
1930
+ export(_filename, _options) { return undefined; }
1931
+ toBlob(_type, _quality) { return undefined; }
1932
+ toDataURL(_type, _quality) { return undefined; }
1933
+ saveAs(_filename, _quality) { return undefined; }
1959
1934
  resize(size) {
1960
1935
  if (this.isSameSize(size))
1961
1936
  return;
@@ -2023,13 +1998,9 @@ class LeaferCanvasBase extends Canvas$1 {
2023
1998
  restoreBlendMode() {
2024
1999
  this.blendMode = this.savedBlendMode;
2025
2000
  }
2026
- hitFill(point, fillRule) {
2027
- return fillRule ? this.context.isPointInPath(point.x, point.y, fillRule) : this.context.isPointInPath(point.x, point.y);
2028
- }
2029
- hitStroke(point, strokeWidth) {
2030
- this.strokeWidth = strokeWidth;
2031
- return this.context.isPointInStroke(point.x, point.y);
2032
- }
2001
+ hitFill(_point, _fillRule) { return true; }
2002
+ hitStroke(_point, _strokeWidth) { return true; }
2003
+ hitPixel(_radiusPoint, _offset, _scale = 1) { return true; }
2033
2004
  setWorldShadow(x, y, blur, color) {
2034
2005
  const { pixelRatio } = this;
2035
2006
  this.shadowOffsetX = x * pixelRatio;
@@ -2088,8 +2059,8 @@ class LeaferCanvasBase extends Canvas$1 {
2088
2059
  if (blendMode)
2089
2060
  this.blendMode = blendMode;
2090
2061
  this.fillStyle = color;
2091
- temp.set(bounds).scale(this.pixelRatio);
2092
- this.fillRect(temp.x, temp.y, temp.width, temp.height);
2062
+ tempBounds$1.set(bounds).scale(this.pixelRatio);
2063
+ this.fillRect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
2093
2064
  if (blendMode)
2094
2065
  this.blendMode = 'source-over';
2095
2066
  }
@@ -2097,23 +2068,23 @@ class LeaferCanvasBase extends Canvas$1 {
2097
2068
  if (blendMode)
2098
2069
  this.blendMode = blendMode;
2099
2070
  this.strokeStyle = color;
2100
- temp.set(bounds).scale(this.pixelRatio);
2101
- this.strokeRect(temp.x, temp.y, temp.width, temp.height);
2071
+ tempBounds$1.set(bounds).scale(this.pixelRatio);
2072
+ this.strokeRect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
2102
2073
  if (blendMode)
2103
2074
  this.blendMode = 'source-over';
2104
2075
  }
2105
2076
  clearWorld(bounds, ceilPixel) {
2106
- temp.set(bounds).scale(this.pixelRatio);
2077
+ tempBounds$1.set(bounds).scale(this.pixelRatio);
2107
2078
  if (ceilPixel)
2108
- temp.ceil();
2109
- this.clearRect(temp.x, temp.y, temp.width, temp.height);
2079
+ tempBounds$1.ceil();
2080
+ this.clearRect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
2110
2081
  }
2111
2082
  clipWorld(bounds, ceilPixel) {
2112
2083
  this.beginPath();
2113
- temp.set(bounds).scale(this.pixelRatio);
2084
+ tempBounds$1.set(bounds).scale(this.pixelRatio);
2114
2085
  if (ceilPixel)
2115
- temp.ceil();
2116
- this.rect(temp.x, temp.y, temp.width, temp.height);
2086
+ tempBounds$1.ceil();
2087
+ this.rect(tempBounds$1.x, tempBounds$1.y, tempBounds$1.width, tempBounds$1.height);
2117
2088
  this.clip();
2118
2089
  }
2119
2090
  clear() {
@@ -2127,7 +2098,7 @@ class LeaferCanvasBase extends Canvas$1 {
2127
2098
  const canvas = this.manager ? this.manager.get(this.size) : Creator.canvas(Object.assign({}, this.size));
2128
2099
  canvas.save();
2129
2100
  if (useSameWorldTransform)
2130
- copy$7(canvas.worldTransform, this.worldTransform), canvas.useWorldTransform();
2101
+ copy$8(canvas.worldTransform, this.worldTransform), canvas.useWorldTransform();
2131
2102
  if (useSameSmooth)
2132
2103
  canvas.smooth = this.smooth;
2133
2104
  return canvas;
@@ -2497,10 +2468,10 @@ const EllipseHelper = {
2497
2468
  }
2498
2469
  };
2499
2470
 
2500
- const { M: M$4, m, L: L$5, l, H, h, V, v, C: C$4, c, S, s, Q: Q$3, q, T, t, A, a, Z: Z$4, z, N: N$3, D: D$3, X: X$3, G: G$3, F: F$3, O: O$3, P: P$3, U: U$3 } = PathCommandMap;
2471
+ const { M: M$4, m, L: L$5, l, H, h, V, v, C: C$4, c, S, s, Q: Q$3, q, T, t, A, a, Z: Z$4, z, N: N$3, D: D$3, X: X$3, G: G$3, F: F$4, O: O$3, P: P$3, U: U$3 } = PathCommandMap;
2501
2472
  const { rect: rect$2, roundRect: roundRect$2, arcTo: arcTo$3, arc: arc$3, ellipse: ellipse$4, quadraticCurveTo: quadraticCurveTo$1 } = BezierHelper;
2502
2473
  const { ellipticalArc } = EllipseHelper;
2503
- const debug$8 = Debug.get('PathConvert');
2474
+ const debug$a = Debug.get('PathConvert');
2504
2475
  const setEndPoint$1 = {};
2505
2476
  const PathConvert = {
2506
2477
  current: { dot: 0 },
@@ -2712,7 +2683,7 @@ const PathConvert = {
2712
2683
  y = setEndPoint$1.y;
2713
2684
  i += 9;
2714
2685
  break;
2715
- case F$3:
2686
+ case F$4:
2716
2687
  curveMode ? ellipse$4(data, old[i + 1], old[i + 2], old[i + 3], old[i + 4], 0, 0, 360, false) : copyData(data, old, i, 5);
2717
2688
  x = old[i + 1] + old[i + 3];
2718
2689
  y = old[i + 2];
@@ -2737,7 +2708,7 @@ const PathConvert = {
2737
2708
  i += 6;
2738
2709
  break;
2739
2710
  default:
2740
- debug$8.error(`command: ${command} [index:${i}]`, old);
2711
+ debug$a.error(`command: ${command} [index:${i}]`, old);
2741
2712
  return data;
2742
2713
  }
2743
2714
  lastCommand = command;
@@ -2761,7 +2732,7 @@ const PathConvert = {
2761
2732
  };
2762
2733
  const { current, pushData, copyData } = PathConvert;
2763
2734
 
2764
- const { M: M$3, L: L$4, C: C$3, Q: Q$2, Z: Z$3, N: N$2, D: D$2, X: X$2, G: G$2, F: F$2, O: O$2, P: P$2, U: U$2 } = PathCommandMap;
2735
+ const { M: M$3, L: L$4, C: C$3, Q: Q$2, Z: Z$3, N: N$2, D: D$2, X: X$2, G: G$2, F: F$3, O: O$2, P: P$2, U: U$2 } = PathCommandMap;
2765
2736
  const { getMinDistanceFrom, getRadianFrom } = PointHelper;
2766
2737
  const { tan, min, abs: abs$2 } = Math;
2767
2738
  const startPoint = {};
@@ -2803,7 +2774,7 @@ const PathCommandDataHelper = {
2803
2774
  },
2804
2775
  ellipse(data, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise) {
2805
2776
  if (rotation === undefined) {
2806
- data.push(F$2, x, y, radiusX, radiusY);
2777
+ data.push(F$3, x, y, radiusX, radiusY);
2807
2778
  }
2808
2779
  else {
2809
2780
  if (startAngle === undefined)
@@ -2853,6 +2824,7 @@ class PathCreator {
2853
2824
  set path(value) { this.__path = value; }
2854
2825
  get path() { return this.__path; }
2855
2826
  constructor(path) {
2827
+ this.clearPath = this.beginPath;
2856
2828
  this.set(path);
2857
2829
  }
2858
2830
  set(path) {
@@ -2922,8 +2894,8 @@ class PathCreator {
2922
2894
  }
2923
2895
  }
2924
2896
 
2925
- const { M: M$2, L: L$3, C: C$2, Q: Q$1, Z: Z$2, N: N$1, D: D$1, X: X$1, G: G$1, F: F$1, O: O$1, P: P$1, U: U$1 } = PathCommandMap;
2926
- const debug$7 = Debug.get('PathDrawer');
2897
+ const { M: M$2, L: L$3, C: C$2, Q: Q$1, Z: Z$2, N: N$1, D: D$1, X: X$1, G: G$1, F: F$2, O: O$1, P: P$1, U: U$1 } = PathCommandMap;
2898
+ const debug$9 = Debug.get('PathDrawer');
2927
2899
  const PathDrawer = {
2928
2900
  drawPathByData(drawer, data) {
2929
2901
  if (!data)
@@ -2969,7 +2941,7 @@ const PathDrawer = {
2969
2941
  drawer.ellipse(data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5] * OneRadian, data[i + 6] * OneRadian, data[i + 7] * OneRadian, data[i + 8]);
2970
2942
  i += 9;
2971
2943
  break;
2972
- case F$1:
2944
+ case F$2:
2973
2945
  drawer.ellipse(data[i + 1], data[i + 2], data[i + 3], data[i + 4], 0, 0, PI2, false);
2974
2946
  i += 5;
2975
2947
  break;
@@ -2986,17 +2958,17 @@ const PathDrawer = {
2986
2958
  i += 6;
2987
2959
  break;
2988
2960
  default:
2989
- debug$7.error(`command: ${command} [index:${i}]`, data);
2961
+ debug$9.error(`command: ${command} [index:${i}]`, data);
2990
2962
  return;
2991
2963
  }
2992
2964
  }
2993
2965
  }
2994
2966
  };
2995
2967
 
2996
- const { M: M$1, L: L$2, C: C$1, Q, Z: Z$1, N, D, X, G, F, O, P, U } = PathCommandMap;
2968
+ const { M: M$1, L: L$2, C: C$1, Q, Z: Z$1, N, D, X, G, F: F$1, O, P, U } = PathCommandMap;
2997
2969
  const { toTwoPointBounds, toTwoPointBoundsByQuadraticCurve, arcTo: arcTo$1, arc, ellipse: ellipse$1 } = BezierHelper;
2998
- const { addPointBounds, copy: copy$6, addPoint: addPoint$1, setPoint: setPoint$1, addBounds, toBounds: toBounds$3 } = TwoPointBoundsHelper;
2999
- const debug$6 = Debug.get('PathBounds');
2970
+ const { addPointBounds, copy: copy$7, addPoint: addPoint$1, setPoint: setPoint$1, addBounds, toBounds: toBounds$3 } = TwoPointBoundsHelper;
2971
+ const debug$8 = Debug.get('PathBounds');
3000
2972
  let radius, radiusX, radiusY;
3001
2973
  const tempPointBounds = {};
3002
2974
  const setPointBounds = {};
@@ -3068,12 +3040,12 @@ const PathBounds = {
3068
3040
  break;
3069
3041
  case G:
3070
3042
  ellipse$1(null, data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6], data[i + 7], data[i + 8], tempPointBounds, setEndPoint);
3071
- i === 0 ? copy$6(setPointBounds, tempPointBounds) : addPointBounds(setPointBounds, tempPointBounds);
3043
+ i === 0 ? copy$7(setPointBounds, tempPointBounds) : addPointBounds(setPointBounds, tempPointBounds);
3072
3044
  x = setEndPoint.x;
3073
3045
  y = setEndPoint.y;
3074
3046
  i += 9;
3075
3047
  break;
3076
- case F:
3048
+ case F$1:
3077
3049
  x = data[i + 1];
3078
3050
  y = data[i + 2];
3079
3051
  radiusX = data[i + 3];
@@ -3084,7 +3056,7 @@ const PathBounds = {
3084
3056
  break;
3085
3057
  case O:
3086
3058
  arc(null, data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6], tempPointBounds, setEndPoint);
3087
- i === 0 ? copy$6(setPointBounds, tempPointBounds) : addPointBounds(setPointBounds, tempPointBounds);
3059
+ i === 0 ? copy$7(setPointBounds, tempPointBounds) : addPointBounds(setPointBounds, tempPointBounds);
3088
3060
  x = setEndPoint.x;
3089
3061
  y = setEndPoint.y;
3090
3062
  i += 7;
@@ -3099,13 +3071,13 @@ const PathBounds = {
3099
3071
  break;
3100
3072
  case U:
3101
3073
  arcTo$1(null, x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], tempPointBounds, setEndPoint);
3102
- i === 0 ? copy$6(setPointBounds, tempPointBounds) : addPointBounds(setPointBounds, tempPointBounds);
3074
+ i === 0 ? copy$7(setPointBounds, tempPointBounds) : addPointBounds(setPointBounds, tempPointBounds);
3103
3075
  x = setEndPoint.x;
3104
3076
  y = setEndPoint.y;
3105
3077
  i += 6;
3106
3078
  break;
3107
3079
  default:
3108
- debug$6.error(`command: ${command} [index:${i}]`, data);
3080
+ debug$8.error(`command: ${command} [index:${i}]`, data);
3109
3081
  return;
3110
3082
  }
3111
3083
  }
@@ -3191,7 +3163,37 @@ function canvasPatch(drawer) {
3191
3163
  roundRect(drawer);
3192
3164
  }
3193
3165
 
3194
- const debug$5 = Debug.get('TaskProcessor');
3166
+ const FileHelper = {
3167
+ opacityTypes: ['png', 'webp', 'svg'],
3168
+ upperCaseTypeMap: {},
3169
+ mineType(type) {
3170
+ if (!type || type.startsWith('image'))
3171
+ return type;
3172
+ if (type === 'jpg')
3173
+ type = 'jpeg';
3174
+ return 'image/' + type;
3175
+ },
3176
+ fileType(filename) {
3177
+ const l = filename.split('.');
3178
+ return l[l.length - 1];
3179
+ },
3180
+ isOpaqueImage(filename) {
3181
+ const type = F.fileType(filename);
3182
+ return ['jpg', 'jpeg'].some(item => item === type);
3183
+ },
3184
+ getExportOptions(options) {
3185
+ switch (typeof options) {
3186
+ case 'object': return options;
3187
+ case 'number': return { quality: options };
3188
+ case 'boolean': return { blob: options };
3189
+ default: return {};
3190
+ }
3191
+ }
3192
+ };
3193
+ const F = FileHelper;
3194
+ F.opacityTypes.forEach(type => F.upperCaseTypeMap[type] = type.toUpperCase());
3195
+
3196
+ const debug$7 = Debug.get('TaskProcessor');
3195
3197
  class TaskItem {
3196
3198
  constructor(task) {
3197
3199
  this.parallel = true;
@@ -3206,7 +3208,7 @@ class TaskItem {
3206
3208
  yield this.task();
3207
3209
  }
3208
3210
  catch (error) {
3209
- debug$5.error(error);
3211
+ debug$7.error(error);
3210
3212
  }
3211
3213
  });
3212
3214
  }
@@ -3490,6 +3492,7 @@ const ImageManager = {
3490
3492
  },
3491
3493
  destroy() {
3492
3494
  I.map = {};
3495
+ I.recycledList = [];
3493
3496
  }
3494
3497
  };
3495
3498
  const I = ImageManager;
@@ -3604,84 +3607,75 @@ function getNames(object) {
3604
3607
  return Object.getOwnPropertyNames(object);
3605
3608
  }
3606
3609
 
3607
- function defineLeafAttr(target, key, defaultValue, mergeDescriptor) {
3610
+ function decorateLeafAttr(defaultValue, descriptorFn) {
3611
+ return (target, key) => defineLeafAttr(target, key, defaultValue, descriptorFn && descriptorFn(key));
3612
+ }
3613
+ function attr(partDescriptor) {
3614
+ return partDescriptor;
3615
+ }
3616
+ function defineLeafAttr(target, key, defaultValue, partDescriptor) {
3608
3617
  const defaultDescriptor = {
3609
3618
  get() { return this.__getAttr(key); },
3610
3619
  set(value) { this.__setAttr(key, value); },
3611
3620
  configurable: true,
3612
3621
  enumerable: true
3613
3622
  };
3614
- defineKey(target, key, Object.assign(defaultDescriptor, mergeDescriptor || {}));
3623
+ defineKey(target, key, Object.assign(defaultDescriptor, partDescriptor || {}));
3615
3624
  defineDataProcessor(target, key, defaultValue);
3616
3625
  }
3617
3626
  function dataType(defaultValue) {
3618
- return (target, key) => {
3619
- defineLeafAttr(target, key, defaultValue);
3620
- };
3627
+ return decorateLeafAttr(defaultValue);
3621
3628
  }
3622
- function positionType(defaultValue) {
3623
- return (target, key) => {
3624
- defineLeafAttr(target, key, defaultValue, {
3625
- set(value) {
3626
- this.__setAttr(key, value);
3627
- this.__layout.matrixChanged || this.__layout.matrixChange();
3628
- }
3629
- });
3630
- };
3629
+ function positionType(defaultValue, checkFiniteNumber) {
3630
+ return decorateLeafAttr(defaultValue, (key) => attr({
3631
+ set(value) {
3632
+ this.__setAttr(key, value, checkFiniteNumber);
3633
+ this.__layout.matrixChanged || this.__layout.matrixChange();
3634
+ }
3635
+ }));
3631
3636
  }
3632
3637
  function autoLayoutType(defaultValue) {
3633
- return (target, key) => {
3634
- defineLeafAttr(target, key, defaultValue, {
3635
- set(value) {
3636
- this.__setAttr(key, value);
3637
- this.__layout.matrixChanged || this.__layout.matrixChange();
3638
- this.__hasAutoLayout = !!value;
3639
- if (!this.__local)
3640
- this.__layout.createLocal();
3641
- }
3642
- });
3643
- };
3638
+ return decorateLeafAttr(defaultValue, (key) => attr({
3639
+ set(value) {
3640
+ this.__setAttr(key, value);
3641
+ this.__layout.matrixChanged || this.__layout.matrixChange();
3642
+ this.__hasAutoLayout = !!value;
3643
+ if (!this.__local)
3644
+ this.__layout.createLocal();
3645
+ }
3646
+ }));
3644
3647
  }
3645
- function scaleType(defaultValue) {
3646
- return (target, key) => {
3647
- defineLeafAttr(target, key, defaultValue, {
3648
- set(value) {
3649
- this.__setAttr(key, value);
3650
- this.__layout.scaleChanged || this.__layout.scaleChange();
3651
- }
3652
- });
3653
- };
3648
+ function scaleType(defaultValue, checkFiniteNumber) {
3649
+ return decorateLeafAttr(defaultValue, (key) => attr({
3650
+ set(value) {
3651
+ this.__setAttr(key, value, checkFiniteNumber);
3652
+ this.__layout.scaleChanged || this.__layout.scaleChange();
3653
+ }
3654
+ }));
3654
3655
  }
3655
- function rotationType(defaultValue) {
3656
- return (target, key) => {
3657
- defineLeafAttr(target, key, defaultValue, {
3658
- set(value) {
3659
- this.__setAttr(key, value);
3660
- this.__layout.rotationChanged || this.__layout.rotationChange();
3661
- }
3662
- });
3663
- };
3656
+ function rotationType(defaultValue, checkFiniteNumber) {
3657
+ return decorateLeafAttr(defaultValue, (key) => attr({
3658
+ set(value) {
3659
+ this.__setAttr(key, value, checkFiniteNumber);
3660
+ this.__layout.rotationChanged || this.__layout.rotationChange();
3661
+ }
3662
+ }));
3664
3663
  }
3665
- function boundsType(defaultValue) {
3666
- return (target, key) => {
3667
- defineLeafAttr(target, key, defaultValue, {
3668
- set(value) {
3669
- this.__setAttr(key, value);
3670
- doBoundsType(this);
3671
- }
3672
- });
3673
- };
3664
+ function boundsType(defaultValue, checkFiniteNumber) {
3665
+ return decorateLeafAttr(defaultValue, (key) => attr({
3666
+ set(value) {
3667
+ this.__setAttr(key, value, checkFiniteNumber) && doBoundsType(this);
3668
+ }
3669
+ }));
3674
3670
  }
3675
3671
  function naturalBoundsType(defaultValue) {
3676
- return (target, key) => {
3677
- defineLeafAttr(target, key, defaultValue, {
3678
- set(value) {
3679
- this.__setAttr(key, value);
3680
- doBoundsType(this);
3681
- this.__.__removeNaturalSize();
3682
- }
3683
- });
3684
- };
3672
+ return decorateLeafAttr(defaultValue, (key) => attr({
3673
+ set(value) {
3674
+ this.__setAttr(key, value);
3675
+ doBoundsType(this);
3676
+ this.__.__removeNaturalSize();
3677
+ }
3678
+ }));
3685
3679
  }
3686
3680
  function doBoundsType(leaf) {
3687
3681
  leaf.__layout.boxChanged || leaf.__layout.boxChange();
@@ -3689,27 +3683,22 @@ function doBoundsType(leaf) {
3689
3683
  leaf.__layout.matrixChanged || leaf.__layout.matrixChange();
3690
3684
  }
3691
3685
  function pathInputType(defaultValue) {
3692
- return (target, key) => {
3693
- defineLeafAttr(target, key, defaultValue, {
3694
- set(value) {
3695
- if (this.__.__pathInputed !== 2)
3696
- this.__.__pathInputed = value ? 1 : 0;
3697
- this.__setAttr(key, value);
3698
- doBoundsType(this);
3699
- }
3700
- });
3701
- };
3686
+ return decorateLeafAttr(defaultValue, (key) => attr({
3687
+ set(value) {
3688
+ if (this.__.__pathInputed !== 2)
3689
+ this.__.__pathInputed = value ? 1 : 0;
3690
+ this.__setAttr(key, value);
3691
+ doBoundsType(this);
3692
+ }
3693
+ }));
3702
3694
  }
3703
3695
  const pathType = boundsType;
3704
3696
  function affectStrokeBoundsType(defaultValue) {
3705
- return (target, key) => {
3706
- defineLeafAttr(target, key, defaultValue, {
3707
- set(value) {
3708
- this.__setAttr(key, value);
3709
- doStrokeType(this);
3710
- }
3711
- });
3712
- };
3697
+ return decorateLeafAttr(defaultValue, (key) => attr({
3698
+ set(value) {
3699
+ this.__setAttr(key, value) && doStrokeType(this);
3700
+ }
3701
+ }));
3713
3702
  }
3714
3703
  function doStrokeType(leaf) {
3715
3704
  leaf.__layout.strokeChanged || leaf.__layout.strokeChange();
@@ -3718,91 +3707,75 @@ function doStrokeType(leaf) {
3718
3707
  }
3719
3708
  const strokeType = affectStrokeBoundsType;
3720
3709
  function affectRenderBoundsType(defaultValue) {
3721
- return (target, key) => {
3722
- defineLeafAttr(target, key, defaultValue, {
3723
- set(value) {
3724
- this.__setAttr(key, value);
3725
- this.__layout.renderChanged || this.__layout.renderChange();
3726
- }
3727
- });
3728
- };
3710
+ return decorateLeafAttr(defaultValue, (key) => attr({
3711
+ set(value) {
3712
+ this.__setAttr(key, value);
3713
+ this.__layout.renderChanged || this.__layout.renderChange();
3714
+ }
3715
+ }));
3729
3716
  }
3730
3717
  function surfaceType(defaultValue) {
3731
- return (target, key) => {
3732
- defineLeafAttr(target, key, defaultValue, {
3733
- set(value) {
3734
- this.__setAttr(key, value);
3735
- this.__layout.surfaceChanged || this.__layout.surfaceChange();
3736
- }
3737
- });
3738
- };
3718
+ return decorateLeafAttr(defaultValue, (key) => attr({
3719
+ set(value) {
3720
+ this.__setAttr(key, value);
3721
+ this.__layout.surfaceChanged || this.__layout.surfaceChange();
3722
+ }
3723
+ }));
3739
3724
  }
3740
3725
  function opacityType(defaultValue) {
3741
- return (target, key) => {
3742
- defineLeafAttr(target, key, defaultValue, {
3743
- set(value) {
3744
- this.__setAttr(key, value);
3745
- this.__layout.opacityChanged || this.__layout.opacityChange();
3746
- }
3747
- });
3748
- };
3726
+ return decorateLeafAttr(defaultValue, (key) => attr({
3727
+ set(value) {
3728
+ this.__setAttr(key, value);
3729
+ this.__layout.opacityChanged || this.__layout.opacityChange();
3730
+ }
3731
+ }));
3749
3732
  }
3750
3733
  function sortType(defaultValue) {
3751
- return (target, key) => {
3752
- defineLeafAttr(target, key, defaultValue, {
3753
- set(value) {
3754
- this.__setAttr(key, value);
3755
- this.__layout.surfaceChanged || this.__layout.surfaceChange();
3756
- this.waitParent(() => { this.parent.__layout.childrenSortChange(); });
3757
- }
3758
- });
3759
- };
3734
+ return decorateLeafAttr(defaultValue, (key) => attr({
3735
+ set(value) {
3736
+ this.__setAttr(key, value);
3737
+ this.__layout.surfaceChanged || this.__layout.surfaceChange();
3738
+ this.waitParent(() => { this.parent.__layout.childrenSortChange(); });
3739
+ }
3740
+ }));
3760
3741
  }
3761
3742
  function maskType(defaultValue) {
3762
- return (target, key) => {
3763
- defineLeafAttr(target, key, defaultValue, {
3764
- set(value) {
3765
- this.__setAttr(key, value);
3766
- this.__layout.boxChanged || this.__layout.boxChange();
3767
- this.waitParent(() => { this.parent.__updateMask(value); });
3768
- }
3769
- });
3770
- };
3743
+ return decorateLeafAttr(defaultValue, (key) => attr({
3744
+ set(value) {
3745
+ this.__setAttr(key, value);
3746
+ this.__layout.boxChanged || this.__layout.boxChange();
3747
+ this.waitParent(() => { this.parent.__updateMask(value); });
3748
+ }
3749
+ }));
3771
3750
  }
3772
3751
  function eraserType(defaultValue) {
3773
- return (target, key) => {
3774
- defineLeafAttr(target, key, defaultValue, {
3775
- set(value) {
3776
- this.__setAttr(key, value);
3777
- this.waitParent(() => { this.parent.__updateEraser(value); });
3778
- }
3779
- });
3780
- };
3752
+ return decorateLeafAttr(defaultValue, (key) => attr({
3753
+ set(value) {
3754
+ this.__setAttr(key, value);
3755
+ this.waitParent(() => { this.parent.__updateEraser(value); });
3756
+ }
3757
+ }));
3781
3758
  }
3782
3759
  function hitType(defaultValue) {
3783
- return (target, key) => {
3784
- defineLeafAttr(target, key, defaultValue, {
3785
- set(value) {
3786
- this.__setAttr(key, value);
3787
- if (Debug.showHitView) {
3788
- this.__layout.surfaceChanged || this.__layout.surfaceChange();
3789
- }
3790
- if (this.leafer)
3791
- this.leafer.updateCursor();
3760
+ return decorateLeafAttr(defaultValue, (key) => attr({
3761
+ set(value) {
3762
+ this.__setAttr(key, value);
3763
+ if (Debug.showHitView) {
3764
+ this.__layout.surfaceChanged || this.__layout.surfaceChange();
3792
3765
  }
3793
- });
3794
- };
3766
+ if (this.leafer)
3767
+ this.leafer.updateCursor();
3768
+ }
3769
+ }));
3795
3770
  }
3796
3771
  function cursorType(defaultValue) {
3797
- return (target, key) => {
3798
- defineLeafAttr(target, key, defaultValue, {
3799
- set(value) {
3800
- this.__setAttr(key, value);
3801
- if (this.leafer)
3802
- this.leafer.updateCursor();
3803
- }
3804
- });
3805
- };
3772
+ return decorateLeafAttr(defaultValue, (key) => attr({
3773
+ set(value) {
3774
+ this.__setAttr(key, value);
3775
+ if (this.leafer)
3776
+ this.leafer.updateCursor();
3777
+ }
3778
+ }));
3806
3779
  }
3807
3780
  function dataProcessor(processor) {
3808
3781
  return (target, _key) => {
@@ -3865,7 +3838,7 @@ function defineDataProcessor(target, key, defaultValue) {
3865
3838
  Object.defineProperty(data, key, property);
3866
3839
  }
3867
3840
 
3868
- const debug$4 = new Debug('rewrite');
3841
+ const debug$6 = new Debug('rewrite');
3869
3842
  const list = [];
3870
3843
  const excludeNames = ['destroy', 'constructor'];
3871
3844
  function rewrite(method) {
@@ -3882,7 +3855,7 @@ function doRewrite(error) {
3882
3855
  if (list.length) {
3883
3856
  list.forEach(item => {
3884
3857
  if (error)
3885
- debug$4.error(item.name, '需在Class上装饰@rewriteAble()');
3858
+ debug$6.error(item.name, '需在Class上装饰@rewriteAble()');
3886
3859
  item.run();
3887
3860
  });
3888
3861
  list.length = 0;
@@ -3918,7 +3891,7 @@ function registerUIEvent() {
3918
3891
  };
3919
3892
  }
3920
3893
 
3921
- const { copy: copy$5, toInnerPoint: toInnerPoint$1, scaleOfOuter: scaleOfOuter$3, rotateOfOuter: rotateOfOuter$3, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3894
+ const { copy: copy$6, toInnerPoint: toInnerPoint$1, scaleOfOuter: scaleOfOuter$3, rotateOfOuter: rotateOfOuter$3, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3922
3895
  const matrix = {};
3923
3896
  const LeafHelper = {
3924
3897
  updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
@@ -3997,7 +3970,7 @@ const LeafHelper = {
3997
3970
  L.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize);
3998
3971
  },
3999
3972
  zoomOfLocal(t, origin, scaleX, scaleY = scaleX, resize) {
4000
- copy$5(matrix, t.__localMatrix);
3973
+ copy$6(matrix, t.__localMatrix);
4001
3974
  scaleOfOuter$3(matrix, origin, scaleX, scaleY);
4002
3975
  moveByMatrix(t, matrix);
4003
3976
  t.scaleResize(scaleX, scaleY, resize !== true);
@@ -4006,7 +3979,7 @@ const LeafHelper = {
4006
3979
  L.rotateOfLocal(t, getTempLocal(t, origin), angle);
4007
3980
  },
4008
3981
  rotateOfLocal(t, origin, angle) {
4009
- copy$5(matrix, t.__localMatrix);
3982
+ copy$6(matrix, t.__localMatrix);
4010
3983
  rotateOfOuter$3(matrix, origin, angle);
4011
3984
  moveByMatrix(t, matrix);
4012
3985
  t.rotation = MathHelper.formatRotation(t.rotation + angle);
@@ -4015,19 +3988,19 @@ const LeafHelper = {
4015
3988
  L.skewOfLocal(t, getTempLocal(t, origin), skewX, skewY, resize);
4016
3989
  },
4017
3990
  skewOfLocal(t, origin, skewX, skewY = 0, resize) {
4018
- copy$5(matrix, t.__localMatrix);
3991
+ copy$6(matrix, t.__localMatrix);
4019
3992
  skewOfOuter(matrix, origin, skewX, skewY);
4020
3993
  L.setTransform(t, matrix, resize);
4021
3994
  },
4022
3995
  transformWorld(t, transform, resize) {
4023
- copy$5(matrix, t.worldTransform);
3996
+ copy$6(matrix, t.worldTransform);
4024
3997
  multiplyParent$2(matrix, transform);
4025
3998
  if (t.parent)
4026
3999
  divideParent(matrix, t.parent.worldTransform);
4027
4000
  L.setTransform(t, matrix, resize);
4028
4001
  },
4029
4002
  transform(t, transform, resize) {
4030
- copy$5(matrix, t.localTransform);
4003
+ copy$6(matrix, t.localTransform);
4031
4004
  multiplyParent$2(matrix, transform);
4032
4005
  L.setTransform(t, matrix, resize);
4033
4006
  },
@@ -4041,7 +4014,7 @@ const LeafHelper = {
4041
4014
  t.set(layout);
4042
4015
  },
4043
4016
  getRelativeWorld(t, relative, temp) {
4044
- copy$5(matrix, t.worldTransform);
4017
+ copy$6(matrix, t.worldTransform);
4045
4018
  divideParent(matrix, relative.worldTransform);
4046
4019
  return temp ? matrix : Object.assign({}, matrix);
4047
4020
  },
@@ -4183,7 +4156,7 @@ const { pushAllChildBranch: pushAllChildBranch$1, pushAllBranchStack, updateBoun
4183
4156
 
4184
4157
  const WaitHelper = {
4185
4158
  run(wait) {
4186
- if (wait.length) {
4159
+ if (wait && wait.length) {
4187
4160
  const len = wait.length;
4188
4161
  for (let i = 0; i < len; i++) {
4189
4162
  wait[i]();
@@ -4194,7 +4167,7 @@ const WaitHelper = {
4194
4167
  };
4195
4168
 
4196
4169
  const { getRelativeWorld: getRelativeWorld$1 } = LeafHelper;
4197
- const { toOuterOf: toOuterOf$2, getPoints, copy: copy$4 } = BoundsHelper;
4170
+ const { toOuterOf: toOuterOf$2, getPoints, copy: copy$5 } = BoundsHelper;
4198
4171
  class LeafLayout {
4199
4172
  get strokeBounds() { return this._strokeBounds || this.boxBounds; }
4200
4173
  get renderBounds() { return this._renderBounds || this.boxBounds; }
@@ -4339,7 +4312,7 @@ class LeafLayout {
4339
4312
  matrix = getRelativeWorld$1(leaf, relative, true);
4340
4313
  }
4341
4314
  const layoutBounds = MatrixHelper.getLayout(matrix);
4342
- copy$4(layoutBounds, bounds);
4315
+ copy$5(layoutBounds, bounds);
4343
4316
  PointHelper.copy(layoutBounds, point);
4344
4317
  if (unscale) {
4345
4318
  const { scaleX, scaleY } = layoutBounds;
@@ -4733,10 +4706,16 @@ LeaferEvent.STOP = 'leafer.stop';
4733
4706
  LeaferEvent.RESTART = 'leafer.restart';
4734
4707
  LeaferEvent.END = 'leafer.end';
4735
4708
 
4709
+ const { isFinite } = Number;
4710
+ const debug$5 = Debug.get('setAttr');
4736
4711
  const LeafDataProxy = {
4737
- __setAttr(name, newValue) {
4712
+ __setAttr(name, newValue, checkFiniteNumber) {
4738
4713
  if (this.leafer && this.leafer.created) {
4739
4714
  const oldValue = this.__.__getInput(name);
4715
+ if (checkFiniteNumber && !isFinite(newValue) && newValue !== undefined) {
4716
+ debug$5.warn(this.innerName, name, newValue);
4717
+ newValue = undefined;
4718
+ }
4740
4719
  if (typeof newValue === 'object' || oldValue !== newValue) {
4741
4720
  this.__[name] = newValue;
4742
4721
  if (this.__proxyData)
@@ -4751,12 +4730,17 @@ const LeafDataProxy = {
4751
4730
  this.emitEvent(event);
4752
4731
  }
4753
4732
  this.leafer.emitEvent(event);
4733
+ return true;
4734
+ }
4735
+ else {
4736
+ return false;
4754
4737
  }
4755
4738
  }
4756
4739
  else {
4757
4740
  this.__[name] = newValue;
4758
4741
  if (this.__proxyData)
4759
4742
  this.setProxyAttr(name, newValue);
4743
+ return true;
4760
4744
  }
4761
4745
  },
4762
4746
  __getAttr(name) {
@@ -4794,7 +4778,7 @@ const LeafMatrix = {
4794
4778
 
4795
4779
  const { updateMatrix: updateMatrix$1, updateAllMatrix: updateAllMatrix$2, hasParentAutoLayout } = LeafHelper;
4796
4780
  const { updateBounds: updateBounds$1 } = BranchHelper;
4797
- const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
4781
+ const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$1, copy: copy$4 } = BoundsHelper;
4798
4782
  const { toBounds: toBounds$2 } = PathBounds;
4799
4783
  const LeafBounds = {
4800
4784
  __updateWorldBounds() {
@@ -4912,7 +4896,8 @@ const LeafBounds = {
4912
4896
  copyAndSpread$1(this.__layout.strokeBounds, this.__layout.boxBounds, this.__layout.strokeSpread);
4913
4897
  },
4914
4898
  __updateRenderBounds() {
4915
- copyAndSpread$1(this.__layout.renderBounds, this.__layout.strokeBounds, this.__layout.renderSpread);
4899
+ const { renderSpread, strokeBounds, renderBounds } = this.__layout;
4900
+ renderSpread > 0 ? copyAndSpread$1(renderBounds, strokeBounds, renderSpread) : copy$4(renderBounds, strokeBounds);
4916
4901
  },
4917
4902
  };
4918
4903
 
@@ -5098,7 +5083,7 @@ let Leaf = class Leaf {
5098
5083
  toString() {
5099
5084
  return JSON.stringify(this.toJSON());
5100
5085
  }
5101
- __setAttr(_attrName, _newValue) { }
5086
+ __setAttr(_attrName, _newValue) { return true; }
5102
5087
  __getAttr(_attrName) { return undefined; }
5103
5088
  setProxyAttr(_attrName, _newValue) { }
5104
5089
  getProxyAttr(_attrName) { return undefined; }
@@ -5282,24 +5267,16 @@ let Leaf = class Leaf {
5282
5267
  __scaleResize(_scaleX, _scaleY) { }
5283
5268
  __hitWorld(_point) { return true; }
5284
5269
  __hit(_local) { return true; }
5285
- __hitFill(inner, windingRule) {
5286
- var _a;
5287
- return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitFill(inner, windingRule);
5288
- }
5289
- __hitStroke(inner, strokeWidth) {
5290
- var _a;
5291
- return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitStroke(inner, strokeWidth);
5292
- }
5293
- __drawHitPath(canvas) {
5294
- if (canvas)
5295
- this.__drawRenderPath(canvas);
5296
- }
5270
+ __hitFill(_inner) { return true; }
5271
+ __hitStroke(_inner, _strokeWidth) { return true; }
5272
+ __hitPixel(_inner) { return true; }
5273
+ __drawHitPath(_canvas) { }
5297
5274
  __updateHitCanvas() { }
5298
5275
  __render(_canvas, _options) { }
5299
5276
  __drawFast(_canvas, _options) { }
5300
5277
  __draw(_canvas, _options) { }
5301
5278
  __clip(_canvas, _options) { }
5302
- __renderShape(_canvas, _options) { }
5279
+ __renderShape(_canvas, _options, _ignoreFill, _ignoreStroke) { }
5303
5280
  __updateWorldOpacity() { }
5304
5281
  __updateChange() { }
5305
5282
  __drawPath(_canvas) { }
@@ -5681,6 +5658,7 @@ function useCanvas(_canvasType, _power) {
5681
5658
  },
5682
5659
  canvasToBolb: (canvas, type, quality) => canvas.convertToBlob({ type: mineType(type), quality }),
5683
5660
  canvasSaveAs: (_canvas, _filename, _quality) => new Promise((resolve) => resolve()),
5661
+ download(_url, _filename) { return undefined; },
5684
5662
  loadImage(src) {
5685
5663
  return new Promise((resolve, reject) => {
5686
5664
  if (!src.startsWith('data:') && Platform.image.suffix)
@@ -5907,7 +5885,7 @@ class LayoutBlockData {
5907
5885
  }
5908
5886
 
5909
5887
  const { updateAllMatrix, updateAllChange } = LeafHelper;
5910
- const debug$3 = Debug.get('Layouter');
5888
+ const debug$4 = Debug.get('Layouter');
5911
5889
  class Layouter {
5912
5890
  constructor(target, userConfig) {
5913
5891
  this.totalTimes = 0;
@@ -5942,7 +5920,7 @@ class Layouter {
5942
5920
  target.emitEvent(new LayoutEvent(LayoutEvent.END, this.layoutedBlocks, this.times));
5943
5921
  }
5944
5922
  catch (e) {
5945
- debug$3.error(e);
5923
+ debug$4.error(e);
5946
5924
  }
5947
5925
  this.layoutedBlocks = null;
5948
5926
  }
@@ -5956,9 +5934,9 @@ class Layouter {
5956
5934
  }
5957
5935
  layoutOnce() {
5958
5936
  if (this.layouting)
5959
- return debug$3.warn('layouting');
5937
+ return debug$4.warn('layouting');
5960
5938
  if (this.times > 3)
5961
- return debug$3.warn('layout max times');
5939
+ return debug$4.warn('layout max times');
5962
5940
  this.times++;
5963
5941
  this.totalTimes++;
5964
5942
  this.layouting = true;
@@ -6062,7 +6040,7 @@ class Layouter {
6062
6040
  }
6063
6041
  }
6064
6042
 
6065
- const debug$2 = Debug.get('Renderer');
6043
+ const debug$3 = Debug.get('Renderer');
6066
6044
  class Renderer {
6067
6045
  get needFill() { return !!(!this.canvas.allowBackgroundColor && this.config.fill); }
6068
6046
  constructor(target, canvas, userConfig) {
@@ -6100,7 +6078,7 @@ class Renderer {
6100
6078
  const { target } = this;
6101
6079
  this.times = 0;
6102
6080
  this.totalBounds = new Bounds();
6103
- debug$2.log(target.innerName, '--->');
6081
+ debug$3.log(target.innerName, '--->');
6104
6082
  try {
6105
6083
  this.emitRender(RenderEvent.START);
6106
6084
  this.renderOnce(callback);
@@ -6109,9 +6087,9 @@ class Renderer {
6109
6087
  }
6110
6088
  catch (e) {
6111
6089
  this.rendering = false;
6112
- debug$2.error(e);
6090
+ debug$3.error(e);
6113
6091
  }
6114
- debug$2.log('-------------|');
6092
+ debug$3.log('-------------|');
6115
6093
  }
6116
6094
  renderAgain() {
6117
6095
  if (this.rendering) {
@@ -6123,9 +6101,9 @@ class Renderer {
6123
6101
  }
6124
6102
  renderOnce(callback) {
6125
6103
  if (this.rendering)
6126
- return debug$2.warn('rendering');
6104
+ return debug$3.warn('rendering');
6127
6105
  if (this.times > 3)
6128
- return debug$2.warn('render max times');
6106
+ return debug$3.warn('render max times');
6129
6107
  this.times++;
6130
6108
  this.totalTimes++;
6131
6109
  this.rendering = true;
@@ -6162,7 +6140,7 @@ class Renderer {
6162
6140
  partRender() {
6163
6141
  const { canvas, updateBlocks: list } = this;
6164
6142
  if (!list)
6165
- return debug$2.warn('PartRender: need update attr');
6143
+ return debug$3.warn('PartRender: need update attr');
6166
6144
  this.mergeBlocks();
6167
6145
  list.forEach(block => { if (canvas.bounds.hit(block) && !block.isEmpty())
6168
6146
  this.clipRender(block); });
@@ -6262,7 +6240,7 @@ class Renderer {
6262
6240
  empty = (!leaf.__world.width || !leaf.__world.height);
6263
6241
  if (empty) {
6264
6242
  if (!leaf.isLeafer)
6265
- debug$2.tip(leaf.innerName, ': empty');
6243
+ debug$3.tip(leaf.innerName, ': empty');
6266
6244
  empty = (!leaf.isBranch || leaf.isBranchLeaf);
6267
6245
  }
6268
6246
  return empty;
@@ -6314,51 +6292,42 @@ const Export = {};
6314
6292
  const State = {};
6315
6293
 
6316
6294
  function stateType(defaultValue) {
6317
- return (target, key) => {
6318
- const stateType = key + 'Style';
6319
- defineLeafAttr(target, key, defaultValue, {
6320
- set(value) {
6321
- this.__setAttr(key, value);
6322
- this.waitLeafer(() => { if (State.setStyle)
6323
- State.setStyle(this, stateType, value); });
6324
- }
6325
- });
6326
- };
6295
+ return decorateLeafAttr(defaultValue, (key) => attr({
6296
+ set(value) {
6297
+ this.__setAttr(key, value);
6298
+ this.waitLeafer(() => { if (State.setStyle)
6299
+ State.setStyle(this, key + 'Style', value); });
6300
+ }
6301
+ }));
6327
6302
  }
6328
6303
  function arrowType(defaultValue) {
6329
- return (target, key) => {
6330
- defineLeafAttr(target, key, defaultValue, {
6331
- set(value) {
6332
- this.__setAttr(key, value);
6333
- const data = this.__;
6334
- data.__useArrow = data.startArrow !== 'none' || data.endArrow !== 'none';
6335
- doStrokeType(this);
6336
- }
6337
- });
6338
- };
6304
+ return decorateLeafAttr(defaultValue, (key) => attr({
6305
+ set(value) {
6306
+ this.__setAttr(key, value);
6307
+ const data = this.__;
6308
+ data.__useArrow = data.startArrow !== 'none' || data.endArrow !== 'none';
6309
+ doStrokeType(this);
6310
+ }
6311
+ }));
6339
6312
  }
6340
6313
  function effectType(defaultValue) {
6341
- return (target, key) => {
6342
- defineLeafAttr(target, key, defaultValue, {
6343
- set(value) {
6344
- this.__setAttr(key, value);
6345
- if (value)
6346
- this.__.__useEffect = true;
6347
- this.__layout.renderChanged || this.__layout.renderChange();
6348
- }
6349
- });
6350
- };
6314
+ return decorateLeafAttr(defaultValue, (key) => attr({
6315
+ set(value) {
6316
+ this.__setAttr(key, value);
6317
+ if (value)
6318
+ this.__.__useEffect = true;
6319
+ this.__layout.renderChanged || this.__layout.renderChange();
6320
+ }
6321
+ }));
6351
6322
  }
6352
6323
  function resizeType(defaultValue) {
6353
- return (target, key) => {
6354
- defineLeafAttr(target, key, defaultValue, {
6355
- set(value) {
6356
- this.__setAttr(key, value);
6357
- this.__layout.boxChanged || this.__layout.boxChange();
6358
- this.__updateSize();
6359
- }
6360
- });
6361
- };
6324
+ return decorateLeafAttr(defaultValue, (key) => attr({
6325
+ set(value) {
6326
+ this.__setAttr(key, value);
6327
+ this.__layout.boxChanged || this.__layout.boxChange();
6328
+ this.__updateSize();
6329
+ }
6330
+ }));
6362
6331
  }
6363
6332
  function zoomLayerType() {
6364
6333
  return (target, key) => {
@@ -6373,12 +6342,13 @@ function zoomLayerType() {
6373
6342
 
6374
6343
  const { parse } = PathConvert;
6375
6344
  const emptyPaint = {};
6376
- const debug$1 = Debug.get('UIData');
6345
+ const debug$2 = Debug.get('UIData');
6377
6346
  class UIData extends LeafData {
6378
6347
  get __strokeWidth() {
6379
6348
  const { strokeWidth, strokeWidthFixed } = this;
6380
6349
  if (strokeWidthFixed) {
6381
- let { scaleX } = this.__leaf.__nowWorld;
6350
+ const ui = this.__leaf;
6351
+ let { scaleX } = ui.__nowWorld || ui.__world;
6382
6352
  if (scaleX < 0)
6383
6353
  scaleX = -scaleX;
6384
6354
  return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
@@ -6400,7 +6370,7 @@ class UIData extends LeafData {
6400
6370
  if (value < 0) {
6401
6371
  this._width = -value;
6402
6372
  this.__leaf.scaleX *= -1;
6403
- debug$1.warn('width < 0, instead -scaleX ', this);
6373
+ debug$2.warn('width < 0, instead -scaleX ', this);
6404
6374
  }
6405
6375
  else {
6406
6376
  this._width = value;
@@ -6410,7 +6380,7 @@ class UIData extends LeafData {
6410
6380
  if (value < 0) {
6411
6381
  this._height = -value;
6412
6382
  this.__leaf.scaleY *= -1;
6413
- debug$1.warn('height < 0, instead -scaleY', this);
6383
+ debug$2.warn('height < 0, instead -scaleY', this);
6414
6384
  }
6415
6385
  else {
6416
6386
  this._height = value;
@@ -6697,14 +6667,14 @@ const UIRender = {
6697
6667
  }
6698
6668
  }
6699
6669
  },
6700
- __renderShape(canvas, options) {
6670
+ __renderShape(canvas, options, ignoreFill, ignoreStroke) {
6701
6671
  if (this.__worldOpacity) {
6702
6672
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
6703
6673
  const { fill, stroke } = this.__;
6704
6674
  this.__drawRenderPath(canvas);
6705
- if (fill)
6675
+ if (fill && !ignoreFill)
6706
6676
  this.__.__pixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
6707
- if (stroke)
6677
+ if (stroke && !ignoreStroke)
6708
6678
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
6709
6679
  }
6710
6680
  }
@@ -6802,10 +6772,7 @@ let UI = UI_1 = class UI extends Leaf {
6802
6772
  __onUpdateSize() {
6803
6773
  if (this.__.__input) {
6804
6774
  const data = this.__;
6805
- data.__needComputePaint = true;
6806
- if (data.lazy && this.leafer && !this.leafer.canvas.bounds.hit(this.__world))
6807
- return;
6808
- data.__computePaint();
6775
+ (data.lazy && this.leafer && this.leafer.created && !this.leafer.lazyBounds.hit(this.__world)) ? data.__needComputePaint = true : data.__computePaint();
6809
6776
  }
6810
6777
  }
6811
6778
  __updateRenderPath() {
@@ -6907,31 +6874,31 @@ __decorate([
6907
6874
  eraserType(false)
6908
6875
  ], UI.prototype, "eraser", void 0);
6909
6876
  __decorate([
6910
- positionType(0)
6877
+ positionType(0, true)
6911
6878
  ], UI.prototype, "x", void 0);
6912
6879
  __decorate([
6913
- positionType(0)
6880
+ positionType(0, true)
6914
6881
  ], UI.prototype, "y", void 0);
6915
6882
  __decorate([
6916
- boundsType(100)
6883
+ boundsType(100, true)
6917
6884
  ], UI.prototype, "width", void 0);
6918
6885
  __decorate([
6919
- boundsType(100)
6886
+ boundsType(100, true)
6920
6887
  ], UI.prototype, "height", void 0);
6921
6888
  __decorate([
6922
- scaleType(1)
6889
+ scaleType(1, true)
6923
6890
  ], UI.prototype, "scaleX", void 0);
6924
6891
  __decorate([
6925
- scaleType(1)
6892
+ scaleType(1, true)
6926
6893
  ], UI.prototype, "scaleY", void 0);
6927
6894
  __decorate([
6928
- rotationType(0)
6895
+ rotationType(0, true)
6929
6896
  ], UI.prototype, "rotation", void 0);
6930
6897
  __decorate([
6931
- rotationType(0)
6898
+ rotationType(0, true)
6932
6899
  ], UI.prototype, "skewX", void 0);
6933
6900
  __decorate([
6934
- rotationType(0)
6901
+ rotationType(0, true)
6935
6902
  ], UI.prototype, "skewY", void 0);
6936
6903
  __decorate([
6937
6904
  autoLayoutType()
@@ -6945,6 +6912,9 @@ __decorate([
6945
6912
  __decorate([
6946
6913
  dataType('size')
6947
6914
  ], UI.prototype, "editSize", void 0);
6915
+ __decorate([
6916
+ dataType()
6917
+ ], UI.prototype, "editorStyle", void 0);
6948
6918
  __decorate([
6949
6919
  hitType(true)
6950
6920
  ], UI.prototype, "hittable", void 0);
@@ -7011,6 +6981,9 @@ __decorate([
7011
6981
  __decorate([
7012
6982
  pathType()
7013
6983
  ], UI.prototype, "windingRule", void 0);
6984
+ __decorate([
6985
+ pathType(true)
6986
+ ], UI.prototype, "closed", void 0);
7014
6987
  __decorate([
7015
6988
  arrowType('none')
7016
6989
  ], UI.prototype, "startArrow", void 0);
@@ -7130,14 +7103,17 @@ Group = __decorate([
7130
7103
  registerUI()
7131
7104
  ], Group);
7132
7105
 
7133
- const debug = Debug.get('Leafer');
7134
- let Leafer = class Leafer extends Group {
7106
+ var Leafer_1;
7107
+ const debug$1 = Debug.get('Leafer');
7108
+ let Leafer = Leafer_1 = class Leafer extends Group {
7109
+ static get version() { return '1.0.0-rc.21'; }
7135
7110
  get __tag() { return 'Leafer'; }
7136
7111
  get isApp() { return false; }
7137
7112
  get app() { return this.parent || this; }
7138
7113
  get isLeafer() { return true; }
7139
7114
  get imageReady() { return this.viewReady && ImageManager.isComplete; }
7140
7115
  get layoutLocked() { return !this.layouter.running; }
7116
+ get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7141
7117
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
7142
7118
  constructor(userConfig, data) {
7143
7119
  super(data);
@@ -7146,6 +7122,7 @@ let Leafer = class Leafer extends Group {
7146
7122
  start: true,
7147
7123
  hittable: true,
7148
7124
  smooth: true,
7125
+ lazySpeard: 100,
7149
7126
  zoom: {
7150
7127
  min: 0.01,
7151
7128
  max: 256
@@ -7166,6 +7143,7 @@ let Leafer = class Leafer extends Group {
7166
7143
  this.userConfig = userConfig;
7167
7144
  if (userConfig && (userConfig.view || userConfig.width))
7168
7145
  this.init(userConfig);
7146
+ Leafer_1.list.add(this);
7169
7147
  }
7170
7148
  init(userConfig, parentApp) {
7171
7149
  if (this.canvas)
@@ -7176,19 +7154,20 @@ let Leafer = class Leafer extends Group {
7176
7154
  let start;
7177
7155
  const { config } = this;
7178
7156
  this.initType(config.type);
7179
- this.canvas = Creator.canvas(config);
7180
- this.__controllers.push(this.renderer = Creator.renderer(this, this.canvas, config), this.watcher = Creator.watcher(this, config), this.layouter = Creator.layouter(this, config));
7157
+ const canvas = this.canvas = Creator.canvas(config);
7158
+ this.__controllers.push(this.renderer = Creator.renderer(this, canvas, config), this.watcher = Creator.watcher(this, config), this.layouter = Creator.layouter(this, config));
7181
7159
  if (this.isApp)
7182
7160
  this.__setApp();
7183
7161
  this.__checkAutoLayout(config);
7184
- this.view = this.canvas.view;
7162
+ this.updateLazyBounds();
7163
+ this.view = canvas.view;
7185
7164
  if (parentApp) {
7186
7165
  this.__bindApp(parentApp);
7187
7166
  start = parentApp.running;
7188
7167
  }
7189
7168
  else {
7190
7169
  this.selector = Creator.selector(this);
7191
- this.interaction = Creator.interaction(this, this.canvas, this.selector, config);
7170
+ this.interaction = Creator.interaction(this, canvas, this.selector, config);
7192
7171
  if (this.interaction) {
7193
7172
  this.__controllers.unshift(this.interaction);
7194
7173
  this.hitCanvasManager = Creator.hitCanvasManager();
@@ -7198,23 +7177,17 @@ let Leafer = class Leafer extends Group {
7198
7177
  }
7199
7178
  this.hittable = config.hittable;
7200
7179
  this.fill = config.fill;
7201
- this.canvasManager.add(this.canvas);
7180
+ this.canvasManager.add(canvas);
7202
7181
  this.__listenEvents();
7203
7182
  if (start)
7204
7183
  this.__startTimer = setTimeout(this.start.bind(this));
7184
+ WaitHelper.run(this.__initWait);
7205
7185
  this.onInit();
7206
7186
  }
7207
7187
  onInit() { }
7208
7188
  initType(_type) { }
7209
7189
  set(data) {
7210
- if (!this.children) {
7211
- setTimeout(() => {
7212
- super.set(data);
7213
- });
7214
- }
7215
- else {
7216
- super.set(data);
7217
- }
7190
+ this.waitInit(() => { super.set(data); });
7218
7191
  }
7219
7192
  start() {
7220
7193
  clearTimeout(this.__startTimer);
@@ -7259,11 +7232,16 @@ let Leafer = class Leafer extends Group {
7259
7232
  if (i)
7260
7233
  cursor ? i.setCursor(cursor) : i.updateCursor();
7261
7234
  }
7235
+ updateLazyBounds() {
7236
+ this.lazyBounds = this.canvas.bounds.clone().spread(this.config.lazySpeard);
7237
+ }
7262
7238
  __doResize(size) {
7263
- if (!this.canvas || this.canvas.isSameSize(size))
7239
+ const { canvas } = this;
7240
+ if (!canvas || canvas.isSameSize(size))
7264
7241
  return;
7265
7242
  const old = DataHelper.copyAttrs({}, this.canvas, canvasSizeAttrs);
7266
- this.canvas.resize(size);
7243
+ canvas.resize(size);
7244
+ this.updateLazyBounds();
7267
7245
  this.__onResize(new ResizeEvent(size, old));
7268
7246
  }
7269
7247
  __onResize(event) {
@@ -7301,7 +7279,7 @@ let Leafer = class Leafer extends Group {
7301
7279
  this.canvas.hittable = newValue;
7302
7280
  }
7303
7281
  }
7304
- super.__setAttr(attrName, newValue);
7282
+ return super.__setAttr(attrName, newValue);
7305
7283
  }
7306
7284
  __getAttr(attrName) {
7307
7285
  if (this.canvas && canvasSizeAttrs.includes(attrName))
@@ -7368,6 +7346,13 @@ let Leafer = class Leafer extends Group {
7368
7346
  this.nextRender(() => this.interaction.updateCursor());
7369
7347
  }
7370
7348
  }
7349
+ waitInit(item, bind) {
7350
+ if (bind)
7351
+ item = item.bind(bind);
7352
+ if (!this.__initWait)
7353
+ this.__initWait = [];
7354
+ this.canvas ? item() : this.__initWait.push(item);
7355
+ }
7371
7356
  waitReady(item, bind) {
7372
7357
  if (bind)
7373
7358
  item = item.bind(bind);
@@ -7407,14 +7392,8 @@ let Leafer = class Leafer extends Group {
7407
7392
  }
7408
7393
  }
7409
7394
  zoom(_zoomType, _padding, _fixedScale) { return undefined; }
7410
- validScale(changeScale) {
7411
- const { scaleX } = this.zoomLayer.__, { min, max } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale);
7412
- if (absScale < min)
7413
- changeScale = min / scaleX;
7414
- else if (absScale > max)
7415
- changeScale = max / scaleX;
7416
- return changeScale;
7417
- }
7395
+ getValidMove(moveX, moveY) { return { x: moveX, y: moveY }; }
7396
+ getValidScale(changeScale) { return changeScale; }
7418
7397
  __checkUpdateLayout() {
7419
7398
  this.__layout.update();
7420
7399
  }
@@ -7433,9 +7412,10 @@ let Leafer = class Leafer extends Group {
7433
7412
  this.off_(this.__eventIds);
7434
7413
  this.__eventIds.length = 0;
7435
7414
  }
7436
- destroy() {
7437
- setTimeout(() => {
7415
+ destroy(sync) {
7416
+ const doDestory = () => {
7438
7417
  if (!this.destroyed) {
7418
+ Leafer_1.list.remove(this);
7439
7419
  try {
7440
7420
  this.stop();
7441
7421
  this.emitEvent(new LeaferEvent(LeaferEvent.END, this));
@@ -7460,19 +7440,21 @@ let Leafer = class Leafer extends Group {
7460
7440
  setTimeout(() => { ImageManager.clearRecycled(); }, 100);
7461
7441
  }
7462
7442
  catch (e) {
7463
- debug.error(e);
7443
+ debug$1.error(e);
7464
7444
  }
7465
7445
  }
7466
- });
7446
+ };
7447
+ sync ? doDestory() : setTimeout(doDestory);
7467
7448
  }
7468
7449
  };
7450
+ Leafer.list = new LeafList();
7469
7451
  __decorate([
7470
7452
  dataProcessor(LeaferData)
7471
7453
  ], Leafer.prototype, "__", void 0);
7472
7454
  __decorate([
7473
7455
  boundsType()
7474
7456
  ], Leafer.prototype, "pixelRatio", void 0);
7475
- Leafer = __decorate([
7457
+ Leafer = Leafer_1 = __decorate([
7476
7458
  registerUI()
7477
7459
  ], Leafer);
7478
7460
 
@@ -7505,11 +7487,9 @@ let Box = class Box extends Group {
7505
7487
  __updateStrokeSpread() { return 0; }
7506
7488
  __updateRectRenderSpread() { return 0; }
7507
7489
  __updateRenderSpread() {
7508
- let width = this.__updateRectRenderSpread() || super.__updateRenderSpread();
7509
- this.__.__drawAfterFill = this.__.overflow === 'hide';
7510
- if (!width)
7511
- width = this.__.__drawAfterFill ? 0 : 1;
7512
- return width;
7490
+ const width = this.__updateRectRenderSpread();
7491
+ const hide = this.__.__drawAfterFill = this.__.overflow === 'hide';
7492
+ return (width || hide) ? width : -1;
7513
7493
  }
7514
7494
  __updateRectBoxBounds() { }
7515
7495
  __updateBoxBounds() {
@@ -7703,7 +7683,7 @@ let Line = class Line extends UI {
7703
7683
  __updatePath() {
7704
7684
  const path = this.__.path = [];
7705
7685
  if (this.__.points) {
7706
- drawPoints$1(path, this.__.points, false);
7686
+ drawPoints$1(path, this.__.points, this.__.closed);
7707
7687
  }
7708
7688
  else {
7709
7689
  moveTo$2(path, 0, 0);
@@ -7713,7 +7693,7 @@ let Line = class Line extends UI {
7713
7693
  __updateRenderPath() {
7714
7694
  const data = this.__;
7715
7695
  if (!this.pathInputed && data.points && data.curve) {
7716
- drawPoints$1(data.__pathForRender = [], data.points, data.curve, this.pathClosed);
7696
+ drawPoints$1(data.__pathForRender = [], data.points, data.curve, data.closed);
7717
7697
  if (data.__useArrow)
7718
7698
  PathArrow.addArrows(this, false);
7719
7699
  }
@@ -7745,6 +7725,9 @@ __decorate([
7745
7725
  __decorate([
7746
7726
  pathType(0)
7747
7727
  ], Line.prototype, "curve", void 0);
7728
+ __decorate([
7729
+ pathType(false)
7730
+ ], Line.prototype, "closed", void 0);
7748
7731
  Line = __decorate([
7749
7732
  registerUI()
7750
7733
  ], Line);
@@ -7756,7 +7739,6 @@ let Polygon = class Polygon extends UI {
7756
7739
  get __tag() { return 'Polygon'; }
7757
7740
  constructor(data) {
7758
7741
  super(data);
7759
- this.pathClosed = true;
7760
7742
  }
7761
7743
  __updatePath() {
7762
7744
  const path = this.__.path = [];
@@ -7926,6 +7908,9 @@ __decorate([
7926
7908
  __decorate([
7927
7909
  resizeType(true)
7928
7910
  ], Canvas.prototype, "smooth", void 0);
7911
+ __decorate([
7912
+ resizeType()
7913
+ ], Canvas.prototype, "contextSettings", void 0);
7929
7914
  __decorate([
7930
7915
  hitType('all')
7931
7916
  ], Canvas.prototype, "hitFill", void 0);
@@ -8002,6 +7987,8 @@ let Text = class Text extends UI {
8002
7987
  else {
8003
7988
  super.__updateBoxBounds();
8004
7989
  }
7990
+ if (italic)
7991
+ b.width += fontSize * 0.16;
8005
7992
  const contentBounds = includes(b, bounds) ? b : bounds;
8006
7993
  if (contentBounds !== layout.contentBounds) {
8007
7994
  layout.contentBounds = contentBounds;
@@ -8139,6 +8126,7 @@ let Pen = class Pen extends Group {
8139
8126
  drawEllipse(_x, _y, _radiusX, _radiusY, _rotation, _startAngle, _endAngle, _anticlockwise) { return this; }
8140
8127
  drawArc(_x, _y, _radius, _startAngle, _endAngle, _anticlockwise) { return this; }
8141
8128
  drawPoints(_points, _curve, _close) { return this; }
8129
+ clearPath() { return this; }
8142
8130
  paint() {
8143
8131
  this.pathElement.forceUpdate('path');
8144
8132
  }
@@ -8150,7 +8138,7 @@ __decorate([
8150
8138
  penPathType()
8151
8139
  ], Pen.prototype, "path", void 0);
8152
8140
  Pen = __decorate([
8153
- useModule(PathCreator, ['beginPath', 'path']),
8141
+ useModule(PathCreator, ['set', 'beginPath', 'path']),
8154
8142
  registerUI()
8155
8143
  ], Pen);
8156
8144
  function penPathType() {
@@ -8161,6 +8149,8 @@ function penPathType() {
8161
8149
  };
8162
8150
  }
8163
8151
 
8152
+ const version = "1.0.0-rc.21";
8153
+
8164
8154
  function fillText(ui, canvas) {
8165
8155
  let row;
8166
8156
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
@@ -8522,8 +8512,11 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation) {
8522
8512
  }
8523
8513
 
8524
8514
  const { get: get$3, translate } = MatrixHelper;
8515
+ const tempBox = new Bounds();
8525
8516
  function createData(leafPaint, image, paint, box) {
8526
8517
  let { width, height } = image;
8518
+ if (paint.padding)
8519
+ box = tempBox.set(box).shrink(paint.padding);
8527
8520
  const { opacity, mode, offset, scale, size, rotation, blendMode, repeat } = paint;
8528
8521
  const sameBox = box.width === width && box.height === height;
8529
8522
  if (blendMode)
@@ -8607,8 +8600,11 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
8607
8600
  leafPaint.loadId = image.load(() => {
8608
8601
  ignoreRender(ui, false);
8609
8602
  if (!ui.destroyed) {
8610
- if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds))
8603
+ if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
8604
+ if (image.hasOpacityPixel)
8605
+ ui.__layout.hitCanvasChanged = true;
8611
8606
  ui.forceUpdate('surface');
8607
+ }
8612
8608
  onLoadSuccess(ui, event);
8613
8609
  }
8614
8610
  leafPaint.loadId = null;
@@ -8662,7 +8658,7 @@ function ignoreRender(ui, value) {
8662
8658
  const { get: get$2, scale, copy: copy$1 } = MatrixHelper;
8663
8659
  const { ceil, abs: abs$1 } = Math;
8664
8660
  function createPattern(ui, paint, pixelRatio) {
8665
- let { scaleX, scaleY } = ui.__nowWorld;
8661
+ let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
8666
8662
  const id = scaleX + '-' + scaleY;
8667
8663
  if (paint.patternId !== id && !ui.destroyed) {
8668
8664
  scaleX = abs$1(scaleX);
@@ -8724,7 +8720,7 @@ function createPattern(ui, paint, pixelRatio) {
8724
8720
 
8725
8721
  const { abs } = Math;
8726
8722
  function checkImage(ui, canvas, paint, allowPaint) {
8727
- const { scaleX, scaleY } = ui.__nowWorld;
8723
+ const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
8728
8724
  if (!paint.data || paint.patternId === scaleX + '-' + scaleY) {
8729
8725
  return false;
8730
8726
  }
@@ -9629,7 +9625,7 @@ const ExportModule = {
9629
9625
  const scale = options.scale || 1;
9630
9626
  const pixelRatio = options.pixelRatio || 1;
9631
9627
  const screenshot = options.screenshot || leaf.isApp;
9632
- const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : undefined) : options.fill;
9628
+ const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
9633
9629
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
9634
9630
  if (screenshot) {
9635
9631
  renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
@@ -9640,10 +9636,10 @@ const ExportModule = {
9640
9636
  scaleY = worldTransform.scaleY;
9641
9637
  switch (relative) {
9642
9638
  case 'inner':
9643
- matrix.set(worldTransform).invert();
9639
+ matrix.set(worldTransform);
9644
9640
  break;
9645
9641
  case 'local':
9646
- matrix.set(worldTransform).divide(leaf.localTransform).invert();
9642
+ matrix.set(worldTransform).divide(leaf.localTransform);
9647
9643
  scaleX /= leaf.scaleX;
9648
9644
  scaleY /= leaf.scaleY;
9649
9645
  break;
@@ -9654,7 +9650,7 @@ const ExportModule = {
9654
9650
  case 'page':
9655
9651
  relative = leaf.leafer;
9656
9652
  default:
9657
- matrix.set(worldTransform).divide(leaf.getTransform(relative)).invert();
9653
+ matrix.set(worldTransform).divide(leaf.getTransform(relative));
9658
9654
  const l = relative.worldTransform;
9659
9655
  scaleX /= scaleX / l.scaleX;
9660
9656
  scaleY /= scaleY / l.scaleY;
@@ -9663,7 +9659,7 @@ const ExportModule = {
9663
9659
  }
9664
9660
  const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
9665
9661
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio });
9666
- const renderOptions = { matrix: matrix.scale(scale).translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
9662
+ const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
9667
9663
  if (slice) {
9668
9664
  leaf = leafer;
9669
9665
  renderOptions.bounds = canvas.bounds;
@@ -9709,6 +9705,44 @@ function addTask(task) {
9709
9705
  });
9710
9706
  }
9711
9707
 
9708
+ const canvas = LeaferCanvasBase.prototype;
9709
+ const debug = Debug.get('@leafer-ui/export');
9710
+ canvas.export = function (filename, options) {
9711
+ const { quality, blob } = FileHelper.getExportOptions(options);
9712
+ if (filename.includes('.')) {
9713
+ return this.saveAs(filename, quality);
9714
+ }
9715
+ else if (blob) {
9716
+ return this.toBlob(filename, quality);
9717
+ }
9718
+ else {
9719
+ return this.toDataURL(filename, quality);
9720
+ }
9721
+ };
9722
+ canvas.toBlob = function (type, quality) {
9723
+ return new Promise((resolve) => {
9724
+ Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
9725
+ resolve(blob);
9726
+ }).catch((e) => {
9727
+ debug.error(e);
9728
+ resolve(null);
9729
+ });
9730
+ });
9731
+ };
9732
+ canvas.toDataURL = function (type, quality) {
9733
+ return Platform.origin.canvasToDataURL(this.view, type, quality);
9734
+ };
9735
+ canvas.saveAs = function (filename, quality) {
9736
+ return new Promise((resolve) => {
9737
+ Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
9738
+ resolve(true);
9739
+ }).catch((e) => {
9740
+ debug.error(e);
9741
+ resolve(false);
9742
+ });
9743
+ });
9744
+ };
9745
+
9712
9746
  Object.assign(TextConvert, TextConvertModule);
9713
9747
  Object.assign(ColorConvert, ColorConvertModule);
9714
9748
  Object.assign(Paint, PaintModule);
@@ -9719,4 +9753,4 @@ Object.assign(Export, ExportModule);
9719
9753
 
9720
9754
  useCanvas();
9721
9755
 
9722
- export { AnimateEvent, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, DataHelper, Debug, Direction4, Direction9, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export, FileHelper, Frame, FrameData, Group, GroupData, Image, ImageData, ImageEvent, ImageManager, IncrementId, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, Line, LineData, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Platform, Point, PointHelper, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Run, Star, StarData, State, StringNumberMap, TaskItem, TaskProcessor, Text, TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, affectRenderBoundsType, affectStrokeBoundsType, arrowType, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, stateType, strokeType, surfaceType, useCanvas, useModule, zoomLayerType };
9756
+ export { AnimateEvent, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, DataHelper, Debug, Direction4, Direction9, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export, FileHelper, Frame, FrameData, Group, GroupData, Image, ImageData, ImageEvent, ImageManager, IncrementId, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, Line, LineData, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Platform, Point, PointHelper, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Run, Star, StarData, State, StringNumberMap, TaskItem, TaskProcessor, Text, TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, affectRenderBoundsType, affectStrokeBoundsType, arrowType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, stateType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$2 as tempPoint, useCanvas, useModule, version, zoomLayerType };