@leafer/core 1.0.0-rc.22 → 1.0.0-rc.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/core.esm.js CHANGED
@@ -3,7 +3,7 @@ const Platform = {
3
3
  hitCanvasSize: 100,
4
4
  maxCacheSize: 2560 * 1600,
5
5
  maxPatternSize: 4096 * 2160,
6
- suffix: 'leaf',
6
+ suffix: '',
7
7
  crossOrigin: 'anonymous'
8
8
  }
9
9
  };
@@ -33,24 +33,12 @@ const I$1 = IncrementId;
33
33
  const { round, pow: pow$1, PI: PI$2 } = Math;
34
34
  const MathHelper = {
35
35
  within(value, min, max) {
36
- if (value < min)
36
+ if (min !== undefined && value < min)
37
37
  value = min;
38
- if (value > max)
38
+ if (max !== undefined && value > max)
39
39
  value = max;
40
40
  return value;
41
41
  },
42
- minus(value, isFourNumber) {
43
- if (value instanceof Array) {
44
- if (isFourNumber)
45
- value = MathHelper.fourNumber(value, 0);
46
- for (let i = 0; i < value.length; i++)
47
- value[i] = -value[i];
48
- }
49
- else {
50
- value = -value;
51
- }
52
- return value;
53
- },
54
42
  fourNumber(num, maxValue) {
55
43
  let data;
56
44
  if (num instanceof Array) {
@@ -147,9 +135,11 @@ const MatrixHelper = {
147
135
  t.e += x;
148
136
  t.f += y;
149
137
  },
150
- translateInner(t, x, y) {
138
+ translateInner(t, x, y, isMoveOrigin) {
151
139
  t.e += t.a * x + t.c * y;
152
140
  t.f += t.b * x + t.d * y;
141
+ if (isMoveOrigin)
142
+ t.e -= x, t.f -= y;
153
143
  },
154
144
  scale(t, scaleX, scaleY = scaleX) {
155
145
  t.a *= scaleX;
@@ -216,8 +206,10 @@ const MatrixHelper = {
216
206
  t.e = child.e * a + child.f * c + e;
217
207
  t.f = child.e * b + child.f * d + f;
218
208
  },
219
- multiplyParent(t, parent, to, abcdChanged, childScaleData) {
220
- const { e, f } = t;
209
+ multiplyParent(t, parent, to, abcdChanged, childScaleData, scrollData) {
210
+ let { e, f } = t;
211
+ if (scrollData)
212
+ e += scrollData.scrollX, f += scrollData.scrollY;
221
213
  to || (to = t);
222
214
  if (abcdChanged === undefined)
223
215
  abcdChanged = t.a !== 1 || t.b || t.c || t.d !== 1;
@@ -338,7 +330,7 @@ const MatrixHelper = {
338
330
  t.e = x;
339
331
  t.f = y;
340
332
  if (origin)
341
- M$6.translateInner(t, -origin.x, -origin.y);
333
+ M$6.translateInner(t, -origin.x, -origin.y, true);
342
334
  },
343
335
  getLayout(t, origin, firstSkewY) {
344
336
  const { a, b, c, d, e, f } = t;
@@ -758,7 +750,7 @@ const { float, fourNumber } = MathHelper;
758
750
  const { floor, ceil: ceil$1 } = Math;
759
751
  let right, bottom, boundsRight, boundsBottom;
760
752
  const point = {};
761
- const toPoint$1 = {};
753
+ const toPoint$2 = {};
762
754
  const BoundsHelper = {
763
755
  tempBounds: {},
764
756
  set(t, x = 0, y = 0, width = 0, height = 0) {
@@ -773,15 +765,17 @@ const BoundsHelper = {
773
765
  t.width = bounds.width;
774
766
  t.height = bounds.height;
775
767
  },
776
- copyAndSpread(t, bounds, spreadX, spreadY) {
777
- if (spreadX instanceof Array) {
778
- const four = fourNumber(spreadX);
779
- B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]);
768
+ copyAndSpread(t, bounds, spread, isShrink) {
769
+ if (spread instanceof Array) {
770
+ const four = fourNumber(spread);
771
+ isShrink
772
+ ? B.set(t, bounds.x + four[3], bounds.y + four[0], bounds.width - four[1] - four[3], bounds.height - four[2] - four[0])
773
+ : B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]);
780
774
  }
781
775
  else {
782
- if (!spreadY)
783
- spreadY = spreadX;
784
- B.set(t, bounds.x - spreadX, bounds.y - spreadY, bounds.width + spreadX * 2, bounds.height + spreadY * 2);
776
+ if (isShrink)
777
+ spread = -spread;
778
+ B.set(t, bounds.x - spread, bounds.y - spread, bounds.width + spread * 2, bounds.height + spread * 2);
785
779
  }
786
780
  },
787
781
  minX(t) { return t.width > 0 ? t.x : t.x + t.width; },
@@ -858,17 +852,17 @@ const BoundsHelper = {
858
852
  else {
859
853
  point.x = t.x;
860
854
  point.y = t.y;
861
- toOuterPoint$1(matrix, point, toPoint$1);
862
- setPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
855
+ toOuterPoint$1(matrix, point, toPoint$2);
856
+ setPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
863
857
  point.x = t.x + t.width;
864
- toOuterPoint$1(matrix, point, toPoint$1);
865
- addPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
858
+ toOuterPoint$1(matrix, point, toPoint$2);
859
+ addPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
866
860
  point.y = t.y + t.height;
867
- toOuterPoint$1(matrix, point, toPoint$1);
868
- addPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
861
+ toOuterPoint$1(matrix, point, toPoint$2);
862
+ addPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
869
863
  point.x = t.x;
870
- toOuterPoint$1(matrix, point, toPoint$1);
871
- addPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
864
+ toOuterPoint$1(matrix, point, toPoint$2);
865
+ addPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
872
866
  toBounds$2(tempPointBounds$1, to);
873
867
  }
874
868
  },
@@ -881,13 +875,16 @@ const BoundsHelper = {
881
875
  const scale = Math.min(baseScale, Math.min(t.width / put.width, t.height / put.height));
882
876
  return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
883
877
  },
884
- getSpread(t, spreadX, spreadY) {
878
+ getSpread(t, spread) {
885
879
  const n = {};
886
- B.copyAndSpread(n, t, spreadX, spreadY);
880
+ B.copyAndSpread(n, t, spread);
887
881
  return n;
888
882
  },
889
- spread(t, spreadX, spreadY = spreadX) {
890
- B.copyAndSpread(t, t, spreadX, spreadY);
883
+ spread(t, spread) {
884
+ B.copyAndSpread(t, t, spread);
885
+ },
886
+ shrink(t, shrink) {
887
+ B.copyAndSpread(t, t, shrink, true);
891
888
  },
892
889
  ceil(t) {
893
890
  const { x, y } = t;
@@ -1067,12 +1064,12 @@ class Bounds {
1067
1064
  getFitMatrix(put, baseScale) {
1068
1065
  return BoundsHelper.getFitMatrix(this, put, baseScale);
1069
1066
  }
1070
- spread(fourNumber, spreadY) {
1071
- BoundsHelper.spread(this, fourNumber, spreadY);
1067
+ spread(fourNumber) {
1068
+ BoundsHelper.spread(this, fourNumber);
1072
1069
  return this;
1073
1070
  }
1074
1071
  shrink(fourNumber) {
1075
- BoundsHelper.spread(this, MathHelper.minus(fourNumber, true));
1072
+ BoundsHelper.shrink(this, fourNumber);
1076
1073
  return this;
1077
1074
  }
1078
1075
  ceil() {
@@ -1189,6 +1186,10 @@ var Direction9;
1189
1186
  Direction9[Direction9["bottomLeft"] = 6] = "bottomLeft";
1190
1187
  Direction9[Direction9["left"] = 7] = "left";
1191
1188
  Direction9[Direction9["center"] = 8] = "center";
1189
+ Direction9[Direction9["top-left"] = 0] = "top-left";
1190
+ Direction9[Direction9["top-right"] = 2] = "top-right";
1191
+ Direction9[Direction9["bottom-right"] = 4] = "bottom-right";
1192
+ Direction9[Direction9["bottom-left"] = 6] = "bottom-left";
1192
1193
  })(Direction9 || (Direction9 = {}));
1193
1194
 
1194
1195
  const directionData = [
@@ -1202,6 +1203,7 @@ const directionData = [
1202
1203
  { x: 0, y: 0.5 },
1203
1204
  { x: 0.5, y: 0.5 }
1204
1205
  ];
1206
+ directionData.forEach(item => item.type = 'percent');
1205
1207
  const AroundHelper = {
1206
1208
  directionData,
1207
1209
  tempPoint: {},
@@ -1209,15 +1211,19 @@ const AroundHelper = {
1209
1211
  toPoint(around, bounds, to, onlySize, pointBounds) {
1210
1212
  to || (to = {});
1211
1213
  const point = get(around);
1212
- to.x = point.x * bounds.width;
1213
- to.y = point.y * bounds.height;
1214
- if (pointBounds) {
1215
- to.x -= pointBounds.x;
1216
- to.y -= pointBounds.y;
1217
- if (point.x)
1218
- to.x -= (point.x === 1) ? pointBounds.width : (point.x === 0.5 ? point.x * pointBounds.width : 0);
1219
- if (point.y)
1220
- to.y -= (point.y === 1) ? pointBounds.height : (point.y === 0.5 ? point.y * pointBounds.height : 0);
1214
+ to.x = point.x;
1215
+ to.y = point.y;
1216
+ if (point.type === 'percent') {
1217
+ to.x *= bounds.width;
1218
+ to.y *= bounds.height;
1219
+ if (pointBounds) {
1220
+ to.x -= pointBounds.x;
1221
+ to.y -= pointBounds.y;
1222
+ if (point.x)
1223
+ to.x -= (point.x === 1) ? pointBounds.width : (point.x === 0.5 ? point.x * pointBounds.width : 0);
1224
+ if (point.y)
1225
+ to.y -= (point.y === 1) ? pointBounds.height : (point.y === 0.5 ? point.y * pointBounds.height : 0);
1226
+ }
1221
1227
  }
1222
1228
  if (!onlySize) {
1223
1229
  to.x += bounds.x;
@@ -1229,6 +1235,13 @@ function get(around) {
1229
1235
  return typeof around === 'string' ? directionData[Direction9[around]] : around;
1230
1236
  }
1231
1237
 
1238
+ const { toPoint: toPoint$1 } = AroundHelper;
1239
+ const AlignHelper = {
1240
+ toPoint(align, contentBounds, bounds, to, onlySize) {
1241
+ toPoint$1(align, bounds, to, onlySize, contentBounds);
1242
+ }
1243
+ };
1244
+
1232
1245
  const StringNumberMap = {
1233
1246
  '0': 1,
1234
1247
  '1': 1,
@@ -1461,13 +1474,21 @@ const DataHelper = {
1461
1474
  },
1462
1475
  clone(data) {
1463
1476
  return JSON.parse(JSON.stringify(data));
1477
+ },
1478
+ toMap(list) {
1479
+ const map = {};
1480
+ for (let i = 0, len = list.length; i < len; i++)
1481
+ map[list[i]] = true;
1482
+ return map;
1464
1483
  }
1465
1484
  };
1466
1485
  const { assign } = DataHelper;
1467
1486
 
1468
1487
  class LeafData {
1488
+ get __useNaturalRatio() { return true; }
1489
+ get __isLinePath() { return this.path && this.path.length === 6; }
1469
1490
  get __blendMode() {
1470
- if (this.eraser)
1491
+ if (this.eraser && this.eraser !== 'path')
1471
1492
  return 'destination-out';
1472
1493
  const { blendMode } = this;
1473
1494
  return blendMode === 'pass-through' ? null : blendMode;
@@ -1963,6 +1984,11 @@ class LeaferCanvasBase extends Canvas {
1963
1984
  }
1964
1985
  updateViewSize() { }
1965
1986
  updateClientBounds() { }
1987
+ getClientBounds(update) {
1988
+ if (update)
1989
+ this.updateClientBounds();
1990
+ return this.clientBounds || this.bounds;
1991
+ }
1966
1992
  startAutoLayout(_autoBounds, _listener) { }
1967
1993
  stopAutoLayout() { }
1968
1994
  setCursor(_cursor) { }
@@ -2097,7 +2123,7 @@ class LeaferCanvasBase extends Canvas {
2097
2123
  }
2098
2124
  clear() {
2099
2125
  const { pixelRatio } = this;
2100
- this.clearRect(0, 0, this.width * pixelRatio, this.height * pixelRatio);
2126
+ this.clearRect(0, 0, this.width * pixelRatio + 2, this.height * pixelRatio + 2);
2101
2127
  }
2102
2128
  isSameSize(size) {
2103
2129
  return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
@@ -2511,11 +2537,15 @@ const PathConvert = {
2511
2537
  char = pathString[i];
2512
2538
  if (StringNumberMap[char]) {
2513
2539
  if (char === '.') {
2514
- current.dot++;
2515
- if (current.dot > 1) {
2540
+ if (current.dot) {
2516
2541
  pushData(data, num);
2517
2542
  num = '';
2518
2543
  }
2544
+ current.dot++;
2545
+ }
2546
+ if (num === '0' && char !== '.') {
2547
+ pushData(data, num);
2548
+ num = '';
2519
2549
  }
2520
2550
  num += char;
2521
2551
  }
@@ -3605,7 +3635,9 @@ class LeaferImage {
3605
3635
  }
3606
3636
  }
3607
3637
 
3608
- function defineKey(target, key, descriptor) {
3638
+ function defineKey(target, key, descriptor, noConfigurable) {
3639
+ if (!noConfigurable)
3640
+ descriptor.configurable = descriptor.enumerable = true;
3609
3641
  Object.defineProperty(target, key, descriptor);
3610
3642
  }
3611
3643
  function getDescriptor(object, name) {
@@ -3624,9 +3656,7 @@ function attr(partDescriptor) {
3624
3656
  function defineLeafAttr(target, key, defaultValue, partDescriptor) {
3625
3657
  const defaultDescriptor = {
3626
3658
  get() { return this.__getAttr(key); },
3627
- set(value) { this.__setAttr(key, value); },
3628
- configurable: true,
3629
- enumerable: true
3659
+ set(value) { this.__setAttr(key, value); }
3630
3660
  };
3631
3661
  defineKey(target, key, Object.assign(defaultDescriptor, partDescriptor || {}));
3632
3662
  defineDataProcessor(target, key, defaultValue);
@@ -3637,35 +3667,33 @@ function dataType(defaultValue) {
3637
3667
  function positionType(defaultValue, checkFiniteNumber) {
3638
3668
  return decorateLeafAttr(defaultValue, (key) => attr({
3639
3669
  set(value) {
3640
- this.__setAttr(key, value, checkFiniteNumber);
3641
- this.__layout.matrixChanged || this.__layout.matrixChange();
3670
+ this.__setAttr(key, value, checkFiniteNumber) && (this.__layout.matrixChanged || this.__layout.matrixChange());
3642
3671
  }
3643
3672
  }));
3644
3673
  }
3645
3674
  function autoLayoutType(defaultValue) {
3646
3675
  return decorateLeafAttr(defaultValue, (key) => attr({
3647
3676
  set(value) {
3648
- this.__setAttr(key, value);
3649
- this.__layout.matrixChanged || this.__layout.matrixChange();
3650
- this.__hasAutoLayout = !!value;
3651
- if (!this.__local)
3652
- this.__layout.createLocal();
3677
+ if (this.__setAttr(key, value)) {
3678
+ this.__layout.matrixChanged || this.__layout.matrixChange();
3679
+ this.__hasAutoLayout = !!value;
3680
+ if (!this.__local)
3681
+ this.__layout.createLocal();
3682
+ }
3653
3683
  }
3654
3684
  }));
3655
3685
  }
3656
3686
  function scaleType(defaultValue, checkFiniteNumber) {
3657
3687
  return decorateLeafAttr(defaultValue, (key) => attr({
3658
3688
  set(value) {
3659
- this.__setAttr(key, value, checkFiniteNumber);
3660
- this.__layout.scaleChanged || this.__layout.scaleChange();
3689
+ this.__setAttr(key, value, checkFiniteNumber) && (this.__layout.scaleChanged || this.__layout.scaleChange());
3661
3690
  }
3662
3691
  }));
3663
3692
  }
3664
3693
  function rotationType(defaultValue, checkFiniteNumber) {
3665
3694
  return decorateLeafAttr(defaultValue, (key) => attr({
3666
3695
  set(value) {
3667
- this.__setAttr(key, value, checkFiniteNumber);
3668
- this.__layout.rotationChanged || this.__layout.rotationChange();
3696
+ this.__setAttr(key, value, checkFiniteNumber) && (this.__layout.rotationChanged || this.__layout.rotationChange());
3669
3697
  }
3670
3698
  }));
3671
3699
  }
@@ -3679,9 +3707,7 @@ function boundsType(defaultValue, checkFiniteNumber) {
3679
3707
  function naturalBoundsType(defaultValue) {
3680
3708
  return decorateLeafAttr(defaultValue, (key) => attr({
3681
3709
  set(value) {
3682
- this.__setAttr(key, value);
3683
- doBoundsType(this);
3684
- this.__.__removeNaturalSize();
3710
+ this.__setAttr(key, value) && (doBoundsType(this), this.__.__removeNaturalSize());
3685
3711
  }
3686
3712
  }));
3687
3713
  }
@@ -3693,8 +3719,11 @@ function doBoundsType(leaf) {
3693
3719
  function pathInputType(defaultValue) {
3694
3720
  return decorateLeafAttr(defaultValue, (key) => attr({
3695
3721
  set(value) {
3696
- if (this.__.__pathInputed !== 2)
3697
- this.__.__pathInputed = value ? 1 : 0;
3722
+ const data = this.__;
3723
+ if (data.__pathInputed !== 2)
3724
+ data.__pathInputed = value ? 1 : 0;
3725
+ if (!value)
3726
+ data.__pathForRender = undefined;
3698
3727
  this.__setAttr(key, value);
3699
3728
  doBoundsType(this);
3700
3729
  }
@@ -3725,54 +3754,66 @@ function affectRenderBoundsType(defaultValue) {
3725
3754
  function surfaceType(defaultValue) {
3726
3755
  return decorateLeafAttr(defaultValue, (key) => attr({
3727
3756
  set(value) {
3728
- this.__setAttr(key, value);
3729
- this.__layout.surfaceChanged || this.__layout.surfaceChange();
3757
+ this.__setAttr(key, value) && (this.__layout.surfaceChanged || this.__layout.surfaceChange());
3730
3758
  }
3731
3759
  }));
3732
3760
  }
3733
3761
  function opacityType(defaultValue) {
3734
3762
  return decorateLeafAttr(defaultValue, (key) => attr({
3735
3763
  set(value) {
3736
- this.__setAttr(key, value);
3737
- this.__layout.opacityChanged || this.__layout.opacityChange();
3764
+ this.__setAttr(key, value) && (this.__layout.opacityChanged || this.__layout.opacityChange());
3765
+ }
3766
+ }));
3767
+ }
3768
+ function visibleType(defaultValue) {
3769
+ return decorateLeafAttr(defaultValue, (key) => attr({
3770
+ set(value) {
3771
+ const oldValue = this.visible;
3772
+ if (this.__setAttr(key, value)) {
3773
+ this.__layout.opacityChanged || this.__layout.opacityChange();
3774
+ if (oldValue === 0 || value === 0)
3775
+ doBoundsType(this);
3776
+ }
3738
3777
  }
3739
3778
  }));
3740
3779
  }
3741
3780
  function sortType(defaultValue) {
3742
3781
  return decorateLeafAttr(defaultValue, (key) => attr({
3743
3782
  set(value) {
3744
- this.__setAttr(key, value);
3745
- this.__layout.surfaceChanged || this.__layout.surfaceChange();
3746
- this.waitParent(() => { this.parent.__layout.childrenSortChange(); });
3783
+ if (this.__setAttr(key, value)) {
3784
+ this.__layout.surfaceChanged || this.__layout.surfaceChange();
3785
+ this.waitParent(() => { this.parent.__layout.childrenSortChange(); });
3786
+ }
3747
3787
  }
3748
3788
  }));
3749
3789
  }
3750
3790
  function maskType(defaultValue) {
3751
3791
  return decorateLeafAttr(defaultValue, (key) => attr({
3752
3792
  set(value) {
3753
- this.__setAttr(key, value);
3754
- this.__layout.boxChanged || this.__layout.boxChange();
3755
- this.waitParent(() => { this.parent.__updateMask(value); });
3793
+ if (this.__setAttr(key, value)) {
3794
+ this.__layout.boxChanged || this.__layout.boxChange();
3795
+ this.waitParent(() => { this.parent.__updateMask(value); });
3796
+ }
3756
3797
  }
3757
3798
  }));
3758
3799
  }
3759
3800
  function eraserType(defaultValue) {
3760
3801
  return decorateLeafAttr(defaultValue, (key) => attr({
3761
3802
  set(value) {
3762
- this.__setAttr(key, value);
3763
- this.waitParent(() => { this.parent.__updateEraser(value); });
3803
+ this.__setAttr(key, value) && this.waitParent(() => { this.parent.__updateEraser(value); });
3764
3804
  }
3765
3805
  }));
3766
3806
  }
3767
3807
  function hitType(defaultValue) {
3768
3808
  return decorateLeafAttr(defaultValue, (key) => attr({
3769
3809
  set(value) {
3770
- this.__setAttr(key, value);
3771
- if (Debug.showHitView) {
3772
- this.__layout.surfaceChanged || this.__layout.surfaceChange();
3810
+ if (this.__setAttr(key, value)) {
3811
+ if (Debug.showHitView) {
3812
+ this.__layout.surfaceChanged || this.__layout.surfaceChange();
3813
+ }
3814
+ if (this.leafer)
3815
+ this.leafer.updateCursor();
3773
3816
  }
3774
- if (this.leafer)
3775
- this.leafer.updateCursor();
3776
3817
  }
3777
3818
  }));
3778
3819
  }
@@ -3813,9 +3854,7 @@ function defineDataProcessor(target, key, defaultValue) {
3813
3854
  },
3814
3855
  set(value) {
3815
3856
  this[computedKey] = value;
3816
- },
3817
- configurable: true,
3818
- enumerable: true
3857
+ }
3819
3858
  };
3820
3859
  if (defaultValue === undefined) {
3821
3860
  property.get = function () { return this[computedKey]; };
@@ -3823,13 +3862,25 @@ function defineDataProcessor(target, key, defaultValue) {
3823
3862
  else if (key === 'width') {
3824
3863
  property.get = function () {
3825
3864
  const v = this[computedKey];
3826
- return v === undefined ? (this.__naturalWidth || defaultValue) : v;
3865
+ if (v === undefined) {
3866
+ const t = this;
3867
+ return t._height && t.__naturalWidth && t.__useNaturalRatio ? t._height * t.__naturalWidth / t.__naturalHeight : t.__naturalWidth || defaultValue;
3868
+ }
3869
+ else {
3870
+ return v;
3871
+ }
3827
3872
  };
3828
3873
  }
3829
3874
  else if (key === 'height') {
3830
3875
  property.get = function () {
3831
3876
  const v = this[computedKey];
3832
- return v === undefined ? (this.__naturalHeight || defaultValue) : v;
3877
+ if (v === undefined) {
3878
+ const t = this;
3879
+ return t._width && t.__naturalHeight && t.__useNaturalRatio ? t._width * t.__naturalHeight / t.__naturalWidth : t.__naturalHeight || defaultValue;
3880
+ }
3881
+ else {
3882
+ return v;
3883
+ }
3833
3884
  };
3834
3885
  }
3835
3886
  let descriptor, find = data;
@@ -3843,7 +3894,7 @@ function defineDataProcessor(target, key, defaultValue) {
3843
3894
  property.set = data[setMethodName];
3844
3895
  delete data[setMethodName];
3845
3896
  }
3846
- Object.defineProperty(data, key, property);
3897
+ defineKey(data, key, property);
3847
3898
  }
3848
3899
 
3849
3900
  const debug$1 = new Debug('rewrite');
@@ -4044,13 +4095,6 @@ const LeafHelper = {
4044
4095
  return true;
4045
4096
  p = p.parent;
4046
4097
  }
4047
- },
4048
- hasParentAutoLayout(p) {
4049
- while (p.parent) {
4050
- p = p.parent;
4051
- if (p.__hasAutoLayout)
4052
- return true;
4053
- }
4054
4098
  }
4055
4099
  };
4056
4100
  const L = LeafHelper;
@@ -4070,13 +4114,13 @@ const LeafBoundsHelper = {
4070
4114
  return target.__world;
4071
4115
  },
4072
4116
  localBoxBounds(target) {
4073
- return target.__.eraser ? null : (target.__local || target.__layout);
4117
+ return target.__.eraser || target.__.visible === 0 ? null : (target.__local || target.__layout);
4074
4118
  },
4075
4119
  localStrokeBounds(target) {
4076
- return target.__.eraser ? null : target.__layout.localStrokeBounds;
4120
+ return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localStrokeBounds;
4077
4121
  },
4078
4122
  localRenderBounds(target) {
4079
- return target.__.eraser ? null : target.__layout.localRenderBounds;
4123
+ return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localRenderBounds;
4080
4124
  },
4081
4125
  maskLocalBoxBounds(target) {
4082
4126
  return target.__.mask ? target.__localBoxBounds : null;
@@ -4182,11 +4226,19 @@ const WaitHelper = {
4182
4226
 
4183
4227
  const { getRelativeWorld: getRelativeWorld$1 } = LeafHelper;
4184
4228
  const { toOuterOf: toOuterOf$2, getPoints, copy: copy$2 } = BoundsHelper;
4229
+ const localContent = '_localContentBounds';
4230
+ const worldContent = '_worldContentBounds', worldBox = '_worldBoxBounds', worldStroke = '_worldStrokeBounds';
4185
4231
  class LeafLayout {
4232
+ get contentBounds() { return this._contentBounds || this.boxBounds; }
4233
+ set contentBounds(bounds) { this._contentBounds = bounds; }
4186
4234
  get strokeBounds() { return this._strokeBounds || this.boxBounds; }
4187
4235
  get renderBounds() { return this._renderBounds || this.boxBounds; }
4236
+ get localContentBounds() { toOuterOf$2(this.contentBounds, this.leaf.__localMatrix, this[localContent] || (this[localContent] = {})); return this[localContent]; }
4188
4237
  get localStrokeBounds() { return this._localStrokeBounds || this; }
4189
4238
  get localRenderBounds() { return this._localRenderBounds || this; }
4239
+ get worldContentBounds() { toOuterOf$2(this.contentBounds, this.leaf.__world, this[worldContent] || (this[worldContent] = {})); return this[worldContent]; }
4240
+ get worldBoxBounds() { toOuterOf$2(this.boxBounds, this.leaf.__world, this[worldBox] || (this[worldBox] = {})); return this[worldBox]; }
4241
+ get worldStrokeBounds() { toOuterOf$2(this.strokeBounds, this.leaf.__world, this[worldStroke] || (this[worldStroke] = {})); return this[worldStroke]; }
4190
4242
  get a() { return 1; }
4191
4243
  get b() { return 0; }
4192
4244
  get c() { return 0; }
@@ -4269,7 +4321,6 @@ class LeafLayout {
4269
4321
  case 'content':
4270
4322
  if (this.contentBounds)
4271
4323
  return this.contentBounds;
4272
- case 'margin':
4273
4324
  case 'box':
4274
4325
  return this.boxBounds;
4275
4326
  case 'stroke':
@@ -4282,8 +4333,9 @@ class LeafLayout {
4282
4333
  return this.localRenderBounds;
4283
4334
  case 'stroke':
4284
4335
  return this.localStrokeBounds;
4285
- case 'margin':
4286
4336
  case 'content':
4337
+ if (this.contentBounds)
4338
+ return this.localContentBounds;
4287
4339
  case 'box':
4288
4340
  return this.leaf.__localBoxBounds;
4289
4341
  }
@@ -4292,15 +4344,13 @@ class LeafLayout {
4292
4344
  switch (type) {
4293
4345
  case 'render':
4294
4346
  return this.leaf.__world;
4347
+ case 'stroke':
4348
+ return this.worldStrokeBounds;
4295
4349
  case 'content':
4296
4350
  if (this.contentBounds)
4297
- return this.getWorldContentBounds();
4298
- case 'margin':
4351
+ return this.worldContentBounds;
4299
4352
  case 'box':
4300
- return this.getWorldBoxBounds();
4301
- case 'margin':
4302
- case 'stroke':
4303
- return this.getWorldStrokeBounds();
4353
+ return this.worldBoxBounds;
4304
4354
  }
4305
4355
  }
4306
4356
  getLayoutBounds(type, relative = 'world', unscale) {
@@ -4363,20 +4413,24 @@ class LeafLayout {
4363
4413
  points.forEach(point => leaf.innerToWorld(point, null, false, relativeLeaf));
4364
4414
  return points;
4365
4415
  }
4366
- getWorldContentBounds() {
4367
- this._worldContentBounds || (this._worldContentBounds = {});
4368
- toOuterOf$2(this.contentBounds, this.leaf.__world, this._worldContentBounds);
4369
- return this._worldContentBounds;
4416
+ shrinkContent() {
4417
+ const { x, y, width, height } = this.boxBounds;
4418
+ this._contentBounds = { x, y, width, height };
4419
+ }
4420
+ spreadStroke() {
4421
+ const { x, y, width, height } = this.strokeBounds;
4422
+ this._strokeBounds = { x, y, width, height };
4423
+ this._localStrokeBounds = { x, y, width, height };
4424
+ if (!this.renderSpread)
4425
+ this.spreadRenderCancel();
4370
4426
  }
4371
- getWorldBoxBounds() {
4372
- this._worldBoxBounds || (this._worldBoxBounds = {});
4373
- toOuterOf$2(this.boxBounds, this.leaf.__world, this._worldBoxBounds);
4374
- return this._worldBoxBounds;
4427
+ spreadRender() {
4428
+ const { x, y, width, height } = this.renderBounds;
4429
+ this._renderBounds = { x, y, width, height };
4430
+ this._localRenderBounds = { x, y, width, height };
4375
4431
  }
4376
- getWorldStrokeBounds() {
4377
- this._worldStrokeBounds || (this._worldStrokeBounds = {});
4378
- toOuterOf$2(this.strokeBounds, this.leaf.__world, this._worldStrokeBounds);
4379
- return this._worldStrokeBounds;
4432
+ shrinkContentCancel() {
4433
+ this._contentBounds = undefined;
4380
4434
  }
4381
4435
  spreadStrokeCancel() {
4382
4436
  const same = this.renderBounds === this.strokeBounds;
@@ -4389,18 +4443,6 @@ class LeafLayout {
4389
4443
  this._renderBounds = this._strokeBounds;
4390
4444
  this._localRenderBounds = this._localStrokeBounds;
4391
4445
  }
4392
- spreadStroke() {
4393
- const { x, y, width, height } = this.strokeBounds;
4394
- this._strokeBounds = { x, y, width, height };
4395
- this._localStrokeBounds = { x, y, width, height };
4396
- if (!this.renderSpread)
4397
- this.spreadRenderCancel();
4398
- }
4399
- spreadRender() {
4400
- const { x, y, width, height } = this.renderBounds;
4401
- this._renderBounds = { x, y, width, height };
4402
- this._localRenderBounds = { x, y, width, height };
4403
- }
4404
4446
  boxChange() {
4405
4447
  this.boxChanged = true;
4406
4448
  this.localBoxChanged || this.localBoxChange();
@@ -4487,24 +4529,40 @@ const LeafEventer = {
4487
4529
  });
4488
4530
  },
4489
4531
  off(type, listener, options) {
4490
- let capture;
4491
- if (options)
4492
- capture = typeof options === 'boolean' ? options : options.capture;
4493
- let events, index;
4494
- const map = __getListenerMap(this, capture);
4495
- const typeList = typeof type === 'string' ? type.split(' ') : type;
4496
- typeList.forEach(type => {
4497
- if (type) {
4498
- events = map[type];
4499
- if (events) {
4500
- index = events.findIndex(item => item.listener === listener);
4501
- if (index > -1)
4502
- events.splice(index, 1);
4503
- if (!events.length)
4504
- delete map[type];
4505
- }
4532
+ if (type) {
4533
+ const typeList = typeof type === 'string' ? type.split(' ') : type;
4534
+ if (listener) {
4535
+ let capture;
4536
+ if (options)
4537
+ capture = typeof options === 'boolean' ? options : options.capture;
4538
+ let events, index;
4539
+ const map = __getListenerMap(this, capture);
4540
+ typeList.forEach(type => {
4541
+ if (type) {
4542
+ events = map[type];
4543
+ if (events) {
4544
+ index = events.findIndex(item => item.listener === listener);
4545
+ if (index > -1)
4546
+ events.splice(index, 1);
4547
+ if (!events.length)
4548
+ delete map[type];
4549
+ }
4550
+ }
4551
+ });
4506
4552
  }
4507
- });
4553
+ else {
4554
+ const { __bubbleMap: b, __captureMap: c } = this;
4555
+ typeList.forEach(type => {
4556
+ if (b)
4557
+ delete b[type];
4558
+ if (c)
4559
+ delete c[type];
4560
+ });
4561
+ }
4562
+ }
4563
+ else {
4564
+ this.__bubbleMap = this.__captureMap = undefined;
4565
+ }
4508
4566
  },
4509
4567
  on_(type, listener, bind, options) {
4510
4568
  if (bind)
@@ -4771,7 +4829,7 @@ const { setLayout, multiplyParent: multiplyParent$1, translateInner, defaultWorl
4771
4829
  const { toPoint, tempPoint } = AroundHelper;
4772
4830
  const LeafMatrix = {
4773
4831
  __updateWorldMatrix() {
4774
- multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__);
4832
+ multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__, this.parent && this.parent.__);
4775
4833
  },
4776
4834
  __updateLocalMatrix() {
4777
4835
  if (this.__local) {
@@ -4782,18 +4840,18 @@ const LeafMatrix = {
4782
4840
  layout.scaleChanged = layout.rotationChanged = false;
4783
4841
  }
4784
4842
  }
4785
- local.e = data.x;
4786
- local.f = data.y;
4787
- if (data.around) {
4788
- toPoint(data.around, layout.boxBounds, tempPoint);
4789
- translateInner(local, -tempPoint.x, -tempPoint.y);
4843
+ local.e = data.x + data.offsetX;
4844
+ local.f = data.y + data.offsetY;
4845
+ if (data.around || data.origin) {
4846
+ toPoint(data.around || data.origin, layout.boxBounds, tempPoint);
4847
+ translateInner(local, -tempPoint.x, -tempPoint.y, data.origin);
4790
4848
  }
4791
4849
  }
4792
4850
  this.__layout.matrixChanged = false;
4793
4851
  }
4794
4852
  };
4795
4853
 
4796
- const { updateMatrix, updateAllMatrix, hasParentAutoLayout } = LeafHelper;
4854
+ const { updateMatrix, updateAllMatrix } = LeafHelper;
4797
4855
  const { updateBounds } = BranchHelper;
4798
4856
  const { toOuterOf: toOuterOf$1, copyAndSpread, copy: copy$1 } = BoundsHelper;
4799
4857
  const { toBounds } = PathBounds;
@@ -4812,7 +4870,6 @@ const LeafBounds = {
4812
4870
  this.__updatePath();
4813
4871
  this.__updateRenderPath();
4814
4872
  this.__updateBoxBounds();
4815
- layout.boxChanged = false;
4816
4873
  layout.resized = true;
4817
4874
  }
4818
4875
  if (layout.localBoxChanged) {
@@ -4826,12 +4883,12 @@ const LeafBounds = {
4826
4883
  if (this.parent)
4827
4884
  this.parent.__layout.boxChange();
4828
4885
  }
4886
+ layout.boxChanged = false;
4829
4887
  if (layout.strokeChanged) {
4830
4888
  layout.strokeSpread = this.__updateStrokeSpread();
4831
4889
  if (layout.strokeSpread) {
4832
- if (layout.strokeBounds === layout.boxBounds) {
4890
+ if (layout.strokeBounds === layout.boxBounds)
4833
4891
  layout.spreadStroke();
4834
- }
4835
4892
  this.__updateStrokeBounds();
4836
4893
  this.__updateLocalStrokeBounds();
4837
4894
  }
@@ -4839,7 +4896,7 @@ const LeafBounds = {
4839
4896
  layout.spreadStrokeCancel();
4840
4897
  }
4841
4898
  layout.strokeChanged = false;
4842
- if (layout.renderSpread)
4899
+ if (layout.renderSpread || layout.strokeSpread !== layout.strokeBoxSpread)
4843
4900
  layout.renderChanged = true;
4844
4901
  if (this.parent)
4845
4902
  this.parent.__layout.strokeChange();
@@ -4848,9 +4905,8 @@ const LeafBounds = {
4848
4905
  if (layout.renderChanged) {
4849
4906
  layout.renderSpread = this.__updateRenderSpread();
4850
4907
  if (layout.renderSpread) {
4851
- if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds) {
4908
+ if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds)
4852
4909
  layout.spreadRender();
4853
- }
4854
4910
  this.__updateRenderBounds();
4855
4911
  this.__updateLocalRenderBounds();
4856
4912
  }
@@ -4890,10 +4946,15 @@ const LeafBounds = {
4890
4946
  __updateAutoLayout() {
4891
4947
  this.__layout.matrixChanged = true;
4892
4948
  if (this.isBranch) {
4893
- if (this.leafer)
4949
+ if (this.leafer && this.leafer.ready)
4894
4950
  this.leafer.layouter.addExtra(this);
4895
- if (hasParentAutoLayout(this)) {
4896
- updateMatrix(this);
4951
+ if (this.__.flow) {
4952
+ if (this.__layout.boxChanged)
4953
+ this.__updateFlowLayout();
4954
+ updateAllMatrix(this);
4955
+ updateBounds(this, this);
4956
+ if (this.__.__autoSide)
4957
+ this.__updateBoxBounds();
4897
4958
  }
4898
4959
  else {
4899
4960
  updateAllMatrix(this);
@@ -4910,12 +4971,13 @@ const LeafBounds = {
4910
4971
  data.__naturalHeight = layout.boxBounds.height;
4911
4972
  },
4912
4973
  __updateStrokeBounds() {
4913
- copyAndSpread(this.__layout.strokeBounds, this.__layout.boxBounds, this.__layout.strokeSpread);
4974
+ const layout = this.__layout;
4975
+ copyAndSpread(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
4914
4976
  },
4915
4977
  __updateRenderBounds() {
4916
- const { renderSpread, strokeBounds, renderBounds } = this.__layout;
4917
- renderSpread > 0 ? copyAndSpread(renderBounds, strokeBounds, renderSpread) : copy$1(renderBounds, strokeBounds);
4918
- },
4978
+ const layout = this.__layout;
4979
+ layout.renderSpread > 0 ? copyAndSpread(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$1(layout.renderBounds, layout.strokeBounds);
4980
+ }
4919
4981
  };
4920
4982
 
4921
4983
  const LeafRender = {
@@ -4924,6 +4986,8 @@ const LeafRender = {
4924
4986
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
4925
4987
  canvas.opacity = this.__.opacity;
4926
4988
  if (this.__.__single) {
4989
+ if (this.__.eraser === 'path')
4990
+ return this.__renderEraser(canvas, options);
4927
4991
  const tempCanvas = canvas.getSameCanvas(true, true);
4928
4992
  this.__draw(tempCanvas, options);
4929
4993
  if (this.__worldFlipped) {
@@ -4966,6 +5030,8 @@ const BranchRender = {
4966
5030
  __render(canvas, options) {
4967
5031
  if (this.__worldOpacity) {
4968
5032
  if (this.__.__single) {
5033
+ if (this.__.eraser === 'path')
5034
+ return this.__renderEraser(canvas, options);
4969
5035
  const tempCanvas = canvas.getSameCanvas(false, true);
4970
5036
  this.__renderBranch(tempCanvas, options);
4971
5037
  const nowWorld = this.__getNowWorld(options);
@@ -5031,7 +5097,7 @@ let Leaf = class Leaf {
5031
5097
  get __worldFlipped() { return this.__world.scaleX < 0 || this.__world.scaleY < 0; }
5032
5098
  get __onlyHitMask() { return this.__hasMask && !this.__.hitChildren; }
5033
5099
  get __ignoreHitWorld() { return (this.__hasMask || this.__hasEraser) && this.__.hitChildren; }
5034
- get pathInputed() { return !!this.__.__pathInputed; }
5100
+ get pathInputed() { return this.__.__pathInputed; }
5035
5101
  constructor(data) {
5036
5102
  this.innerId = create(LEAF);
5037
5103
  this.reset(data);
@@ -5105,7 +5171,9 @@ let Leaf = class Leaf {
5105
5171
  setProxyAttr(_attrName, _newValue) { }
5106
5172
  getProxyAttr(_attrName) { return undefined; }
5107
5173
  find(_condition, _options) { return undefined; }
5174
+ findTag(_tag) { return undefined; }
5108
5175
  findOne(_condition, _options) { return undefined; }
5176
+ findId(_id) { return undefined; }
5109
5177
  focus(_value) { }
5110
5178
  forceUpdate(attrName) {
5111
5179
  if (attrName === undefined)
@@ -5127,9 +5195,11 @@ let Leaf = class Leaf {
5127
5195
  __updateLocalStrokeBounds() { }
5128
5196
  __updateLocalRenderBounds() { }
5129
5197
  __updateBoxBounds() { }
5198
+ __updateContentBounds() { }
5130
5199
  __updateStrokeBounds() { }
5131
5200
  __updateRenderBounds() { }
5132
5201
  __updateAutoLayout() { }
5202
+ __updateFlowLayout() { }
5133
5203
  __updateNaturalSize() { }
5134
5204
  __updateStrokeSpread() { return 0; }
5135
5205
  __updateRenderSpread() { return 0; }
@@ -5137,6 +5207,13 @@ let Leaf = class Leaf {
5137
5207
  __updateEraser(value) {
5138
5208
  this.__hasEraser = value ? true : this.children.some(item => item.__.eraser);
5139
5209
  }
5210
+ __renderEraser(canvas, options) {
5211
+ canvas.save();
5212
+ this.__clip(canvas, options);
5213
+ const { renderBounds: r } = this.__layout;
5214
+ canvas.clearRect(r.x, r.y, r.width, r.height);
5215
+ canvas.restore();
5216
+ }
5140
5217
  __updateMask(value) {
5141
5218
  this.__hasMask = value ? true : this.children.some(item => item.__.mask);
5142
5219
  }
@@ -5317,8 +5394,8 @@ let Leaf = class Leaf {
5317
5394
  emit(_type, _event, _capture) { }
5318
5395
  emitEvent(_event, _capture) { }
5319
5396
  hasEvent(_type, _capture) { return false; }
5320
- static changeAttr(attrName, defaultValue) {
5321
- defineDataProcessor(this.prototype, attrName, defaultValue);
5397
+ static changeAttr(attrName, defaultValue, fn) {
5398
+ fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue);
5322
5399
  }
5323
5400
  static addAttr(attrName, defaultValue, fn) {
5324
5401
  if (!fn)
@@ -5632,4 +5709,7 @@ class LeafLevelList {
5632
5709
  }
5633
5710
  }
5634
5711
 
5635
- export { AnimateEvent, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, FileHelper, ImageEvent, ImageManager, IncrementId, LayoutEvent, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, LeaferCanvasBase, LeaferEvent, LeaferImage, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Platform, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Run, StringNumberMap, TaskItem, TaskProcessor, TwoPointBoundsHelper, UICreator, WaitHelper, WatchEvent, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, useModule };
5712
+ const version = "1.0.0-rc.24";
5713
+ const inviteCode = {};
5714
+
5715
+ export { AlignHelper, AnimateEvent, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, FileHelper, ImageEvent, ImageManager, IncrementId, LayoutEvent, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, LeaferCanvasBase, LeaferEvent, LeaferImage, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Platform, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Run, StringNumberMap, TaskItem, TaskProcessor, TwoPointBoundsHelper, UICreator, WaitHelper, WatchEvent, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, inviteCode, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, useModule, version, visibleType };