@leafer-draw/miniapp 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) { }
@@ -5740,9 +5717,12 @@ function useCanvas(_canvasType, app) {
5740
5717
  canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
5741
5718
  canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, { quality }),
5742
5719
  canvasSaveAs: (canvas, filePath, quality) => {
5720
+ let data = canvas.toDataURL(mineType(fileType(filePath)), quality);
5721
+ data = data.substring(data.indexOf('64,') + 3);
5722
+ return Platform.origin.download(data, filePath);
5723
+ },
5724
+ download(data, filePath) {
5743
5725
  return new Promise((resolve, reject) => {
5744
- let data = canvas.toDataURL(mineType(fileType(filePath)), quality);
5745
- data = data.substring(data.indexOf('64,') + 3);
5746
5726
  let toAlbum;
5747
5727
  if (!filePath.includes('/')) {
5748
5728
  filePath = `${app.env.USER_DATA_PATH}/` + filePath;
@@ -6024,7 +6004,7 @@ class LayoutBlockData {
6024
6004
  }
6025
6005
 
6026
6006
  const { updateAllMatrix, updateAllChange } = LeafHelper;
6027
- const debug$3 = Debug.get('Layouter');
6007
+ const debug$4 = Debug.get('Layouter');
6028
6008
  class Layouter {
6029
6009
  constructor(target, userConfig) {
6030
6010
  this.totalTimes = 0;
@@ -6059,7 +6039,7 @@ class Layouter {
6059
6039
  target.emitEvent(new LayoutEvent(LayoutEvent.END, this.layoutedBlocks, this.times));
6060
6040
  }
6061
6041
  catch (e) {
6062
- debug$3.error(e);
6042
+ debug$4.error(e);
6063
6043
  }
6064
6044
  this.layoutedBlocks = null;
6065
6045
  }
@@ -6073,9 +6053,9 @@ class Layouter {
6073
6053
  }
6074
6054
  layoutOnce() {
6075
6055
  if (this.layouting)
6076
- return debug$3.warn('layouting');
6056
+ return debug$4.warn('layouting');
6077
6057
  if (this.times > 3)
6078
- return debug$3.warn('layout max times');
6058
+ return debug$4.warn('layout max times');
6079
6059
  this.times++;
6080
6060
  this.totalTimes++;
6081
6061
  this.layouting = true;
@@ -6179,7 +6159,7 @@ class Layouter {
6179
6159
  }
6180
6160
  }
6181
6161
 
6182
- const debug$2 = Debug.get('Renderer');
6162
+ const debug$3 = Debug.get('Renderer');
6183
6163
  class Renderer {
6184
6164
  get needFill() { return !!(!this.canvas.allowBackgroundColor && this.config.fill); }
6185
6165
  constructor(target, canvas, userConfig) {
@@ -6217,7 +6197,7 @@ class Renderer {
6217
6197
  const { target } = this;
6218
6198
  this.times = 0;
6219
6199
  this.totalBounds = new Bounds();
6220
- debug$2.log(target.innerName, '--->');
6200
+ debug$3.log(target.innerName, '--->');
6221
6201
  try {
6222
6202
  this.emitRender(RenderEvent.START);
6223
6203
  this.renderOnce(callback);
@@ -6226,9 +6206,9 @@ class Renderer {
6226
6206
  }
6227
6207
  catch (e) {
6228
6208
  this.rendering = false;
6229
- debug$2.error(e);
6209
+ debug$3.error(e);
6230
6210
  }
6231
- debug$2.log('-------------|');
6211
+ debug$3.log('-------------|');
6232
6212
  }
6233
6213
  renderAgain() {
6234
6214
  if (this.rendering) {
@@ -6240,9 +6220,9 @@ class Renderer {
6240
6220
  }
6241
6221
  renderOnce(callback) {
6242
6222
  if (this.rendering)
6243
- return debug$2.warn('rendering');
6223
+ return debug$3.warn('rendering');
6244
6224
  if (this.times > 3)
6245
- return debug$2.warn('render max times');
6225
+ return debug$3.warn('render max times');
6246
6226
  this.times++;
6247
6227
  this.totalTimes++;
6248
6228
  this.rendering = true;
@@ -6279,7 +6259,7 @@ class Renderer {
6279
6259
  partRender() {
6280
6260
  const { canvas, updateBlocks: list } = this;
6281
6261
  if (!list)
6282
- return debug$2.warn('PartRender: need update attr');
6262
+ return debug$3.warn('PartRender: need update attr');
6283
6263
  this.mergeBlocks();
6284
6264
  list.forEach(block => { if (canvas.bounds.hit(block) && !block.isEmpty())
6285
6265
  this.clipRender(block); });
@@ -6379,7 +6359,7 @@ class Renderer {
6379
6359
  empty = (!leaf.__world.width || !leaf.__world.height);
6380
6360
  if (empty) {
6381
6361
  if (!leaf.isLeafer)
6382
- debug$2.tip(leaf.innerName, ': empty');
6362
+ debug$3.tip(leaf.innerName, ': empty');
6383
6363
  empty = (!leaf.isBranch || leaf.isBranchLeaf);
6384
6364
  }
6385
6365
  return empty;
@@ -6431,51 +6411,42 @@ const Export = {};
6431
6411
  const State = {};
6432
6412
 
6433
6413
  function stateType(defaultValue) {
6434
- return (target, key) => {
6435
- const stateType = key + 'Style';
6436
- defineLeafAttr(target, key, defaultValue, {
6437
- set(value) {
6438
- this.__setAttr(key, value);
6439
- this.waitLeafer(() => { if (State.setStyle)
6440
- State.setStyle(this, stateType, value); });
6441
- }
6442
- });
6443
- };
6414
+ return decorateLeafAttr(defaultValue, (key) => attr({
6415
+ set(value) {
6416
+ this.__setAttr(key, value);
6417
+ this.waitLeafer(() => { if (State.setStyle)
6418
+ State.setStyle(this, key + 'Style', value); });
6419
+ }
6420
+ }));
6444
6421
  }
6445
6422
  function arrowType(defaultValue) {
6446
- return (target, key) => {
6447
- defineLeafAttr(target, key, defaultValue, {
6448
- set(value) {
6449
- this.__setAttr(key, value);
6450
- const data = this.__;
6451
- data.__useArrow = data.startArrow !== 'none' || data.endArrow !== 'none';
6452
- doStrokeType(this);
6453
- }
6454
- });
6455
- };
6423
+ return decorateLeafAttr(defaultValue, (key) => attr({
6424
+ set(value) {
6425
+ this.__setAttr(key, value);
6426
+ const data = this.__;
6427
+ data.__useArrow = data.startArrow !== 'none' || data.endArrow !== 'none';
6428
+ doStrokeType(this);
6429
+ }
6430
+ }));
6456
6431
  }
6457
6432
  function effectType(defaultValue) {
6458
- return (target, key) => {
6459
- defineLeafAttr(target, key, defaultValue, {
6460
- set(value) {
6461
- this.__setAttr(key, value);
6462
- if (value)
6463
- this.__.__useEffect = true;
6464
- this.__layout.renderChanged || this.__layout.renderChange();
6465
- }
6466
- });
6467
- };
6433
+ return decorateLeafAttr(defaultValue, (key) => attr({
6434
+ set(value) {
6435
+ this.__setAttr(key, value);
6436
+ if (value)
6437
+ this.__.__useEffect = true;
6438
+ this.__layout.renderChanged || this.__layout.renderChange();
6439
+ }
6440
+ }));
6468
6441
  }
6469
6442
  function resizeType(defaultValue) {
6470
- return (target, key) => {
6471
- defineLeafAttr(target, key, defaultValue, {
6472
- set(value) {
6473
- this.__setAttr(key, value);
6474
- this.__layout.boxChanged || this.__layout.boxChange();
6475
- this.__updateSize();
6476
- }
6477
- });
6478
- };
6443
+ return decorateLeafAttr(defaultValue, (key) => attr({
6444
+ set(value) {
6445
+ this.__setAttr(key, value);
6446
+ this.__layout.boxChanged || this.__layout.boxChange();
6447
+ this.__updateSize();
6448
+ }
6449
+ }));
6479
6450
  }
6480
6451
  function zoomLayerType() {
6481
6452
  return (target, key) => {
@@ -6490,12 +6461,13 @@ function zoomLayerType() {
6490
6461
 
6491
6462
  const { parse } = PathConvert;
6492
6463
  const emptyPaint = {};
6493
- const debug$1 = Debug.get('UIData');
6464
+ const debug$2 = Debug.get('UIData');
6494
6465
  class UIData extends LeafData {
6495
6466
  get __strokeWidth() {
6496
6467
  const { strokeWidth, strokeWidthFixed } = this;
6497
6468
  if (strokeWidthFixed) {
6498
- let { scaleX } = this.__leaf.__nowWorld;
6469
+ const ui = this.__leaf;
6470
+ let { scaleX } = ui.__nowWorld || ui.__world;
6499
6471
  if (scaleX < 0)
6500
6472
  scaleX = -scaleX;
6501
6473
  return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
@@ -6517,7 +6489,7 @@ class UIData extends LeafData {
6517
6489
  if (value < 0) {
6518
6490
  this._width = -value;
6519
6491
  this.__leaf.scaleX *= -1;
6520
- debug$1.warn('width < 0, instead -scaleX ', this);
6492
+ debug$2.warn('width < 0, instead -scaleX ', this);
6521
6493
  }
6522
6494
  else {
6523
6495
  this._width = value;
@@ -6527,7 +6499,7 @@ class UIData extends LeafData {
6527
6499
  if (value < 0) {
6528
6500
  this._height = -value;
6529
6501
  this.__leaf.scaleY *= -1;
6530
- debug$1.warn('height < 0, instead -scaleY', this);
6502
+ debug$2.warn('height < 0, instead -scaleY', this);
6531
6503
  }
6532
6504
  else {
6533
6505
  this._height = value;
@@ -6814,14 +6786,14 @@ const UIRender = {
6814
6786
  }
6815
6787
  }
6816
6788
  },
6817
- __renderShape(canvas, options) {
6789
+ __renderShape(canvas, options, ignoreFill, ignoreStroke) {
6818
6790
  if (this.__worldOpacity) {
6819
6791
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
6820
6792
  const { fill, stroke } = this.__;
6821
6793
  this.__drawRenderPath(canvas);
6822
- if (fill)
6794
+ if (fill && !ignoreFill)
6823
6795
  this.__.__pixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
6824
- if (stroke)
6796
+ if (stroke && !ignoreStroke)
6825
6797
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
6826
6798
  }
6827
6799
  }
@@ -6919,10 +6891,7 @@ let UI = UI_1 = class UI extends Leaf {
6919
6891
  __onUpdateSize() {
6920
6892
  if (this.__.__input) {
6921
6893
  const data = this.__;
6922
- data.__needComputePaint = true;
6923
- if (data.lazy && this.leafer && !this.leafer.canvas.bounds.hit(this.__world))
6924
- return;
6925
- data.__computePaint();
6894
+ (data.lazy && this.leafer && this.leafer.created && !this.leafer.lazyBounds.hit(this.__world)) ? data.__needComputePaint = true : data.__computePaint();
6926
6895
  }
6927
6896
  }
6928
6897
  __updateRenderPath() {
@@ -7024,31 +6993,31 @@ __decorate([
7024
6993
  eraserType(false)
7025
6994
  ], UI.prototype, "eraser", void 0);
7026
6995
  __decorate([
7027
- positionType(0)
6996
+ positionType(0, true)
7028
6997
  ], UI.prototype, "x", void 0);
7029
6998
  __decorate([
7030
- positionType(0)
6999
+ positionType(0, true)
7031
7000
  ], UI.prototype, "y", void 0);
7032
7001
  __decorate([
7033
- boundsType(100)
7002
+ boundsType(100, true)
7034
7003
  ], UI.prototype, "width", void 0);
7035
7004
  __decorate([
7036
- boundsType(100)
7005
+ boundsType(100, true)
7037
7006
  ], UI.prototype, "height", void 0);
7038
7007
  __decorate([
7039
- scaleType(1)
7008
+ scaleType(1, true)
7040
7009
  ], UI.prototype, "scaleX", void 0);
7041
7010
  __decorate([
7042
- scaleType(1)
7011
+ scaleType(1, true)
7043
7012
  ], UI.prototype, "scaleY", void 0);
7044
7013
  __decorate([
7045
- rotationType(0)
7014
+ rotationType(0, true)
7046
7015
  ], UI.prototype, "rotation", void 0);
7047
7016
  __decorate([
7048
- rotationType(0)
7017
+ rotationType(0, true)
7049
7018
  ], UI.prototype, "skewX", void 0);
7050
7019
  __decorate([
7051
- rotationType(0)
7020
+ rotationType(0, true)
7052
7021
  ], UI.prototype, "skewY", void 0);
7053
7022
  __decorate([
7054
7023
  autoLayoutType()
@@ -7062,6 +7031,9 @@ __decorate([
7062
7031
  __decorate([
7063
7032
  dataType('size')
7064
7033
  ], UI.prototype, "editSize", void 0);
7034
+ __decorate([
7035
+ dataType()
7036
+ ], UI.prototype, "editorStyle", void 0);
7065
7037
  __decorate([
7066
7038
  hitType(true)
7067
7039
  ], UI.prototype, "hittable", void 0);
@@ -7128,6 +7100,9 @@ __decorate([
7128
7100
  __decorate([
7129
7101
  pathType()
7130
7102
  ], UI.prototype, "windingRule", void 0);
7103
+ __decorate([
7104
+ pathType(true)
7105
+ ], UI.prototype, "closed", void 0);
7131
7106
  __decorate([
7132
7107
  arrowType('none')
7133
7108
  ], UI.prototype, "startArrow", void 0);
@@ -7247,14 +7222,17 @@ Group = __decorate([
7247
7222
  registerUI()
7248
7223
  ], Group);
7249
7224
 
7250
- const debug = Debug.get('Leafer');
7251
- let Leafer = class Leafer extends Group {
7225
+ var Leafer_1;
7226
+ const debug$1 = Debug.get('Leafer');
7227
+ let Leafer = Leafer_1 = class Leafer extends Group {
7228
+ static get version() { return '1.0.0-rc.21'; }
7252
7229
  get __tag() { return 'Leafer'; }
7253
7230
  get isApp() { return false; }
7254
7231
  get app() { return this.parent || this; }
7255
7232
  get isLeafer() { return true; }
7256
7233
  get imageReady() { return this.viewReady && ImageManager.isComplete; }
7257
7234
  get layoutLocked() { return !this.layouter.running; }
7235
+ get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7258
7236
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
7259
7237
  constructor(userConfig, data) {
7260
7238
  super(data);
@@ -7263,6 +7241,7 @@ let Leafer = class Leafer extends Group {
7263
7241
  start: true,
7264
7242
  hittable: true,
7265
7243
  smooth: true,
7244
+ lazySpeard: 100,
7266
7245
  zoom: {
7267
7246
  min: 0.01,
7268
7247
  max: 256
@@ -7283,6 +7262,7 @@ let Leafer = class Leafer extends Group {
7283
7262
  this.userConfig = userConfig;
7284
7263
  if (userConfig && (userConfig.view || userConfig.width))
7285
7264
  this.init(userConfig);
7265
+ Leafer_1.list.add(this);
7286
7266
  }
7287
7267
  init(userConfig, parentApp) {
7288
7268
  if (this.canvas)
@@ -7293,19 +7273,20 @@ let Leafer = class Leafer extends Group {
7293
7273
  let start;
7294
7274
  const { config } = this;
7295
7275
  this.initType(config.type);
7296
- this.canvas = Creator.canvas(config);
7297
- this.__controllers.push(this.renderer = Creator.renderer(this, this.canvas, config), this.watcher = Creator.watcher(this, config), this.layouter = Creator.layouter(this, config));
7276
+ const canvas = this.canvas = Creator.canvas(config);
7277
+ this.__controllers.push(this.renderer = Creator.renderer(this, canvas, config), this.watcher = Creator.watcher(this, config), this.layouter = Creator.layouter(this, config));
7298
7278
  if (this.isApp)
7299
7279
  this.__setApp();
7300
7280
  this.__checkAutoLayout(config);
7301
- this.view = this.canvas.view;
7281
+ this.updateLazyBounds();
7282
+ this.view = canvas.view;
7302
7283
  if (parentApp) {
7303
7284
  this.__bindApp(parentApp);
7304
7285
  start = parentApp.running;
7305
7286
  }
7306
7287
  else {
7307
7288
  this.selector = Creator.selector(this);
7308
- this.interaction = Creator.interaction(this, this.canvas, this.selector, config);
7289
+ this.interaction = Creator.interaction(this, canvas, this.selector, config);
7309
7290
  if (this.interaction) {
7310
7291
  this.__controllers.unshift(this.interaction);
7311
7292
  this.hitCanvasManager = Creator.hitCanvasManager();
@@ -7315,23 +7296,17 @@ let Leafer = class Leafer extends Group {
7315
7296
  }
7316
7297
  this.hittable = config.hittable;
7317
7298
  this.fill = config.fill;
7318
- this.canvasManager.add(this.canvas);
7299
+ this.canvasManager.add(canvas);
7319
7300
  this.__listenEvents();
7320
7301
  if (start)
7321
7302
  this.__startTimer = setTimeout(this.start.bind(this));
7303
+ WaitHelper.run(this.__initWait);
7322
7304
  this.onInit();
7323
7305
  }
7324
7306
  onInit() { }
7325
7307
  initType(_type) { }
7326
7308
  set(data) {
7327
- if (!this.children) {
7328
- setTimeout(() => {
7329
- super.set(data);
7330
- });
7331
- }
7332
- else {
7333
- super.set(data);
7334
- }
7309
+ this.waitInit(() => { super.set(data); });
7335
7310
  }
7336
7311
  start() {
7337
7312
  clearTimeout(this.__startTimer);
@@ -7376,11 +7351,16 @@ let Leafer = class Leafer extends Group {
7376
7351
  if (i)
7377
7352
  cursor ? i.setCursor(cursor) : i.updateCursor();
7378
7353
  }
7354
+ updateLazyBounds() {
7355
+ this.lazyBounds = this.canvas.bounds.clone().spread(this.config.lazySpeard);
7356
+ }
7379
7357
  __doResize(size) {
7380
- if (!this.canvas || this.canvas.isSameSize(size))
7358
+ const { canvas } = this;
7359
+ if (!canvas || canvas.isSameSize(size))
7381
7360
  return;
7382
7361
  const old = DataHelper.copyAttrs({}, this.canvas, canvasSizeAttrs);
7383
- this.canvas.resize(size);
7362
+ canvas.resize(size);
7363
+ this.updateLazyBounds();
7384
7364
  this.__onResize(new ResizeEvent(size, old));
7385
7365
  }
7386
7366
  __onResize(event) {
@@ -7418,7 +7398,7 @@ let Leafer = class Leafer extends Group {
7418
7398
  this.canvas.hittable = newValue;
7419
7399
  }
7420
7400
  }
7421
- super.__setAttr(attrName, newValue);
7401
+ return super.__setAttr(attrName, newValue);
7422
7402
  }
7423
7403
  __getAttr(attrName) {
7424
7404
  if (this.canvas && canvasSizeAttrs.includes(attrName))
@@ -7485,6 +7465,13 @@ let Leafer = class Leafer extends Group {
7485
7465
  this.nextRender(() => this.interaction.updateCursor());
7486
7466
  }
7487
7467
  }
7468
+ waitInit(item, bind) {
7469
+ if (bind)
7470
+ item = item.bind(bind);
7471
+ if (!this.__initWait)
7472
+ this.__initWait = [];
7473
+ this.canvas ? item() : this.__initWait.push(item);
7474
+ }
7488
7475
  waitReady(item, bind) {
7489
7476
  if (bind)
7490
7477
  item = item.bind(bind);
@@ -7524,14 +7511,8 @@ let Leafer = class Leafer extends Group {
7524
7511
  }
7525
7512
  }
7526
7513
  zoom(_zoomType, _padding, _fixedScale) { return undefined; }
7527
- validScale(changeScale) {
7528
- const { scaleX } = this.zoomLayer.__, { min, max } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale);
7529
- if (absScale < min)
7530
- changeScale = min / scaleX;
7531
- else if (absScale > max)
7532
- changeScale = max / scaleX;
7533
- return changeScale;
7534
- }
7514
+ getValidMove(moveX, moveY) { return { x: moveX, y: moveY }; }
7515
+ getValidScale(changeScale) { return changeScale; }
7535
7516
  __checkUpdateLayout() {
7536
7517
  this.__layout.update();
7537
7518
  }
@@ -7550,9 +7531,10 @@ let Leafer = class Leafer extends Group {
7550
7531
  this.off_(this.__eventIds);
7551
7532
  this.__eventIds.length = 0;
7552
7533
  }
7553
- destroy() {
7554
- setTimeout(() => {
7534
+ destroy(sync) {
7535
+ const doDestory = () => {
7555
7536
  if (!this.destroyed) {
7537
+ Leafer_1.list.remove(this);
7556
7538
  try {
7557
7539
  this.stop();
7558
7540
  this.emitEvent(new LeaferEvent(LeaferEvent.END, this));
@@ -7577,19 +7559,21 @@ let Leafer = class Leafer extends Group {
7577
7559
  setTimeout(() => { ImageManager.clearRecycled(); }, 100);
7578
7560
  }
7579
7561
  catch (e) {
7580
- debug.error(e);
7562
+ debug$1.error(e);
7581
7563
  }
7582
7564
  }
7583
- });
7565
+ };
7566
+ sync ? doDestory() : setTimeout(doDestory);
7584
7567
  }
7585
7568
  };
7569
+ Leafer.list = new LeafList();
7586
7570
  __decorate([
7587
7571
  dataProcessor(LeaferData)
7588
7572
  ], Leafer.prototype, "__", void 0);
7589
7573
  __decorate([
7590
7574
  boundsType()
7591
7575
  ], Leafer.prototype, "pixelRatio", void 0);
7592
- Leafer = __decorate([
7576
+ Leafer = Leafer_1 = __decorate([
7593
7577
  registerUI()
7594
7578
  ], Leafer);
7595
7579
 
@@ -7622,11 +7606,9 @@ let Box = class Box extends Group {
7622
7606
  __updateStrokeSpread() { return 0; }
7623
7607
  __updateRectRenderSpread() { return 0; }
7624
7608
  __updateRenderSpread() {
7625
- let width = this.__updateRectRenderSpread() || super.__updateRenderSpread();
7626
- this.__.__drawAfterFill = this.__.overflow === 'hide';
7627
- if (!width)
7628
- width = this.__.__drawAfterFill ? 0 : 1;
7629
- return width;
7609
+ const width = this.__updateRectRenderSpread();
7610
+ const hide = this.__.__drawAfterFill = this.__.overflow === 'hide';
7611
+ return (width || hide) ? width : -1;
7630
7612
  }
7631
7613
  __updateRectBoxBounds() { }
7632
7614
  __updateBoxBounds() {
@@ -7820,7 +7802,7 @@ let Line = class Line extends UI {
7820
7802
  __updatePath() {
7821
7803
  const path = this.__.path = [];
7822
7804
  if (this.__.points) {
7823
- drawPoints$1(path, this.__.points, false);
7805
+ drawPoints$1(path, this.__.points, this.__.closed);
7824
7806
  }
7825
7807
  else {
7826
7808
  moveTo$2(path, 0, 0);
@@ -7830,7 +7812,7 @@ let Line = class Line extends UI {
7830
7812
  __updateRenderPath() {
7831
7813
  const data = this.__;
7832
7814
  if (!this.pathInputed && data.points && data.curve) {
7833
- drawPoints$1(data.__pathForRender = [], data.points, data.curve, this.pathClosed);
7815
+ drawPoints$1(data.__pathForRender = [], data.points, data.curve, data.closed);
7834
7816
  if (data.__useArrow)
7835
7817
  PathArrow.addArrows(this, false);
7836
7818
  }
@@ -7862,6 +7844,9 @@ __decorate([
7862
7844
  __decorate([
7863
7845
  pathType(0)
7864
7846
  ], Line.prototype, "curve", void 0);
7847
+ __decorate([
7848
+ pathType(false)
7849
+ ], Line.prototype, "closed", void 0);
7865
7850
  Line = __decorate([
7866
7851
  registerUI()
7867
7852
  ], Line);
@@ -7873,7 +7858,6 @@ let Polygon = class Polygon extends UI {
7873
7858
  get __tag() { return 'Polygon'; }
7874
7859
  constructor(data) {
7875
7860
  super(data);
7876
- this.pathClosed = true;
7877
7861
  }
7878
7862
  __updatePath() {
7879
7863
  const path = this.__.path = [];
@@ -8043,6 +8027,9 @@ __decorate([
8043
8027
  __decorate([
8044
8028
  resizeType(true)
8045
8029
  ], Canvas.prototype, "smooth", void 0);
8030
+ __decorate([
8031
+ resizeType()
8032
+ ], Canvas.prototype, "contextSettings", void 0);
8046
8033
  __decorate([
8047
8034
  hitType('all')
8048
8035
  ], Canvas.prototype, "hitFill", void 0);
@@ -8119,6 +8106,8 @@ let Text = class Text extends UI {
8119
8106
  else {
8120
8107
  super.__updateBoxBounds();
8121
8108
  }
8109
+ if (italic)
8110
+ b.width += fontSize * 0.16;
8122
8111
  const contentBounds = includes(b, bounds) ? b : bounds;
8123
8112
  if (contentBounds !== layout.contentBounds) {
8124
8113
  layout.contentBounds = contentBounds;
@@ -8256,6 +8245,7 @@ let Pen = class Pen extends Group {
8256
8245
  drawEllipse(_x, _y, _radiusX, _radiusY, _rotation, _startAngle, _endAngle, _anticlockwise) { return this; }
8257
8246
  drawArc(_x, _y, _radius, _startAngle, _endAngle, _anticlockwise) { return this; }
8258
8247
  drawPoints(_points, _curve, _close) { return this; }
8248
+ clearPath() { return this; }
8259
8249
  paint() {
8260
8250
  this.pathElement.forceUpdate('path');
8261
8251
  }
@@ -8267,7 +8257,7 @@ __decorate([
8267
8257
  penPathType()
8268
8258
  ], Pen.prototype, "path", void 0);
8269
8259
  Pen = __decorate([
8270
- useModule(PathCreator, ['beginPath', 'path']),
8260
+ useModule(PathCreator, ['set', 'beginPath', 'path']),
8271
8261
  registerUI()
8272
8262
  ], Pen);
8273
8263
  function penPathType() {
@@ -8278,6 +8268,8 @@ function penPathType() {
8278
8268
  };
8279
8269
  }
8280
8270
 
8271
+ const version = "1.0.0-rc.21";
8272
+
8281
8273
  function fillText(ui, canvas) {
8282
8274
  let row;
8283
8275
  const { rows, decorationY, decorationHeight } = ui.__.__textDrawData;
@@ -8639,8 +8631,11 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation) {
8639
8631
  }
8640
8632
 
8641
8633
  const { get: get$3, translate } = MatrixHelper;
8634
+ const tempBox = new Bounds();
8642
8635
  function createData(leafPaint, image, paint, box) {
8643
8636
  let { width, height } = image;
8637
+ if (paint.padding)
8638
+ box = tempBox.set(box).shrink(paint.padding);
8644
8639
  const { opacity, mode, offset, scale, size, rotation, blendMode, repeat } = paint;
8645
8640
  const sameBox = box.width === width && box.height === height;
8646
8641
  if (blendMode)
@@ -8724,8 +8719,11 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
8724
8719
  leafPaint.loadId = image.load(() => {
8725
8720
  ignoreRender(ui, false);
8726
8721
  if (!ui.destroyed) {
8727
- if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds))
8722
+ if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
8723
+ if (image.hasOpacityPixel)
8724
+ ui.__layout.hitCanvasChanged = true;
8728
8725
  ui.forceUpdate('surface');
8726
+ }
8729
8727
  onLoadSuccess(ui, event);
8730
8728
  }
8731
8729
  leafPaint.loadId = null;
@@ -8779,7 +8777,7 @@ function ignoreRender(ui, value) {
8779
8777
  const { get: get$2, scale, copy: copy$1 } = MatrixHelper;
8780
8778
  const { ceil, abs: abs$1 } = Math;
8781
8779
  function createPattern(ui, paint, pixelRatio) {
8782
- let { scaleX, scaleY } = ui.__nowWorld;
8780
+ let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
8783
8781
  const id = scaleX + '-' + scaleY;
8784
8782
  if (paint.patternId !== id && !ui.destroyed) {
8785
8783
  scaleX = abs$1(scaleX);
@@ -8841,7 +8839,7 @@ function createPattern(ui, paint, pixelRatio) {
8841
8839
 
8842
8840
  const { abs } = Math;
8843
8841
  function checkImage(ui, canvas, paint, allowPaint) {
8844
- const { scaleX, scaleY } = ui.__nowWorld;
8842
+ const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
8845
8843
  if (!paint.data || paint.patternId === scaleX + '-' + scaleY) {
8846
8844
  return false;
8847
8845
  }
@@ -9746,7 +9744,7 @@ const ExportModule = {
9746
9744
  const scale = options.scale || 1;
9747
9745
  const pixelRatio = options.pixelRatio || 1;
9748
9746
  const screenshot = options.screenshot || leaf.isApp;
9749
- const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : undefined) : options.fill;
9747
+ const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
9750
9748
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
9751
9749
  if (screenshot) {
9752
9750
  renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
@@ -9757,10 +9755,10 @@ const ExportModule = {
9757
9755
  scaleY = worldTransform.scaleY;
9758
9756
  switch (relative) {
9759
9757
  case 'inner':
9760
- matrix.set(worldTransform).invert();
9758
+ matrix.set(worldTransform);
9761
9759
  break;
9762
9760
  case 'local':
9763
- matrix.set(worldTransform).divide(leaf.localTransform).invert();
9761
+ matrix.set(worldTransform).divide(leaf.localTransform);
9764
9762
  scaleX /= leaf.scaleX;
9765
9763
  scaleY /= leaf.scaleY;
9766
9764
  break;
@@ -9771,7 +9769,7 @@ const ExportModule = {
9771
9769
  case 'page':
9772
9770
  relative = leaf.leafer;
9773
9771
  default:
9774
- matrix.set(worldTransform).divide(leaf.getTransform(relative)).invert();
9772
+ matrix.set(worldTransform).divide(leaf.getTransform(relative));
9775
9773
  const l = relative.worldTransform;
9776
9774
  scaleX /= scaleX / l.scaleX;
9777
9775
  scaleY /= scaleY / l.scaleY;
@@ -9780,7 +9778,7 @@ const ExportModule = {
9780
9778
  }
9781
9779
  const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
9782
9780
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio });
9783
- const renderOptions = { matrix: matrix.scale(scale).translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
9781
+ const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
9784
9782
  if (slice) {
9785
9783
  leaf = leafer;
9786
9784
  renderOptions.bounds = canvas.bounds;
@@ -9826,6 +9824,44 @@ function addTask(task) {
9826
9824
  });
9827
9825
  }
9828
9826
 
9827
+ const canvas = LeaferCanvasBase.prototype;
9828
+ const debug = Debug.get('@leafer-ui/export');
9829
+ canvas.export = function (filename, options) {
9830
+ const { quality, blob } = FileHelper.getExportOptions(options);
9831
+ if (filename.includes('.')) {
9832
+ return this.saveAs(filename, quality);
9833
+ }
9834
+ else if (blob) {
9835
+ return this.toBlob(filename, quality);
9836
+ }
9837
+ else {
9838
+ return this.toDataURL(filename, quality);
9839
+ }
9840
+ };
9841
+ canvas.toBlob = function (type, quality) {
9842
+ return new Promise((resolve) => {
9843
+ Platform.origin.canvasToBolb(this.view, type, quality).then((blob) => {
9844
+ resolve(blob);
9845
+ }).catch((e) => {
9846
+ debug.error(e);
9847
+ resolve(null);
9848
+ });
9849
+ });
9850
+ };
9851
+ canvas.toDataURL = function (type, quality) {
9852
+ return Platform.origin.canvasToDataURL(this.view, type, quality);
9853
+ };
9854
+ canvas.saveAs = function (filename, quality) {
9855
+ return new Promise((resolve) => {
9856
+ Platform.origin.canvasSaveAs(this.view, filename, quality).then(() => {
9857
+ resolve(true);
9858
+ }).catch((e) => {
9859
+ debug.error(e);
9860
+ resolve(false);
9861
+ });
9862
+ });
9863
+ };
9864
+
9829
9865
  Object.assign(TextConvert, TextConvertModule);
9830
9866
  Object.assign(ColorConvert, ColorConvertModule);
9831
9867
  Object.assign(Paint, PaintModule);
@@ -9839,4 +9875,4 @@ try {
9839
9875
  }
9840
9876
  catch (_a) { }
9841
9877
 
9842
- 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 };
9878
+ 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 };