@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.cjs CHANGED
@@ -5,7 +5,7 @@ const Platform = {
5
5
  hitCanvasSize: 100,
6
6
  maxCacheSize: 2560 * 1600,
7
7
  maxPatternSize: 4096 * 2160,
8
- suffix: 'leaf',
8
+ suffix: '',
9
9
  crossOrigin: 'anonymous'
10
10
  }
11
11
  };
@@ -35,24 +35,12 @@ const I$1 = IncrementId;
35
35
  const { round, pow: pow$1, PI: PI$2 } = Math;
36
36
  const MathHelper = {
37
37
  within(value, min, max) {
38
- if (value < min)
38
+ if (min !== undefined && value < min)
39
39
  value = min;
40
- if (value > max)
40
+ if (max !== undefined && value > max)
41
41
  value = max;
42
42
  return value;
43
43
  },
44
- minus(value, isFourNumber) {
45
- if (value instanceof Array) {
46
- if (isFourNumber)
47
- value = MathHelper.fourNumber(value, 0);
48
- for (let i = 0; i < value.length; i++)
49
- value[i] = -value[i];
50
- }
51
- else {
52
- value = -value;
53
- }
54
- return value;
55
- },
56
44
  fourNumber(num, maxValue) {
57
45
  let data;
58
46
  if (num instanceof Array) {
@@ -149,9 +137,11 @@ const MatrixHelper = {
149
137
  t.e += x;
150
138
  t.f += y;
151
139
  },
152
- translateInner(t, x, y) {
140
+ translateInner(t, x, y, isMoveOrigin) {
153
141
  t.e += t.a * x + t.c * y;
154
142
  t.f += t.b * x + t.d * y;
143
+ if (isMoveOrigin)
144
+ t.e -= x, t.f -= y;
155
145
  },
156
146
  scale(t, scaleX, scaleY = scaleX) {
157
147
  t.a *= scaleX;
@@ -218,8 +208,10 @@ const MatrixHelper = {
218
208
  t.e = child.e * a + child.f * c + e;
219
209
  t.f = child.e * b + child.f * d + f;
220
210
  },
221
- multiplyParent(t, parent, to, abcdChanged, childScaleData) {
222
- const { e, f } = t;
211
+ multiplyParent(t, parent, to, abcdChanged, childScaleData, scrollData) {
212
+ let { e, f } = t;
213
+ if (scrollData)
214
+ e += scrollData.scrollX, f += scrollData.scrollY;
223
215
  to || (to = t);
224
216
  if (abcdChanged === undefined)
225
217
  abcdChanged = t.a !== 1 || t.b || t.c || t.d !== 1;
@@ -340,7 +332,7 @@ const MatrixHelper = {
340
332
  t.e = x;
341
333
  t.f = y;
342
334
  if (origin)
343
- M$6.translateInner(t, -origin.x, -origin.y);
335
+ M$6.translateInner(t, -origin.x, -origin.y, true);
344
336
  },
345
337
  getLayout(t, origin, firstSkewY) {
346
338
  const { a, b, c, d, e, f } = t;
@@ -760,7 +752,7 @@ const { float, fourNumber } = MathHelper;
760
752
  const { floor, ceil: ceil$1 } = Math;
761
753
  let right, bottom, boundsRight, boundsBottom;
762
754
  const point = {};
763
- const toPoint$1 = {};
755
+ const toPoint$2 = {};
764
756
  const BoundsHelper = {
765
757
  tempBounds: {},
766
758
  set(t, x = 0, y = 0, width = 0, height = 0) {
@@ -775,15 +767,17 @@ const BoundsHelper = {
775
767
  t.width = bounds.width;
776
768
  t.height = bounds.height;
777
769
  },
778
- copyAndSpread(t, bounds, spreadX, spreadY) {
779
- if (spreadX instanceof Array) {
780
- const four = fourNumber(spreadX);
781
- B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]);
770
+ copyAndSpread(t, bounds, spread, isShrink) {
771
+ if (spread instanceof Array) {
772
+ const four = fourNumber(spread);
773
+ isShrink
774
+ ? B.set(t, bounds.x + four[3], bounds.y + four[0], bounds.width - four[1] - four[3], bounds.height - four[2] - four[0])
775
+ : B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]);
782
776
  }
783
777
  else {
784
- if (!spreadY)
785
- spreadY = spreadX;
786
- B.set(t, bounds.x - spreadX, bounds.y - spreadY, bounds.width + spreadX * 2, bounds.height + spreadY * 2);
778
+ if (isShrink)
779
+ spread = -spread;
780
+ B.set(t, bounds.x - spread, bounds.y - spread, bounds.width + spread * 2, bounds.height + spread * 2);
787
781
  }
788
782
  },
789
783
  minX(t) { return t.width > 0 ? t.x : t.x + t.width; },
@@ -860,17 +854,17 @@ const BoundsHelper = {
860
854
  else {
861
855
  point.x = t.x;
862
856
  point.y = t.y;
863
- toOuterPoint$1(matrix, point, toPoint$1);
864
- setPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
857
+ toOuterPoint$1(matrix, point, toPoint$2);
858
+ setPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
865
859
  point.x = t.x + t.width;
866
- toOuterPoint$1(matrix, point, toPoint$1);
867
- addPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
860
+ toOuterPoint$1(matrix, point, toPoint$2);
861
+ addPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
868
862
  point.y = t.y + t.height;
869
- toOuterPoint$1(matrix, point, toPoint$1);
870
- addPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
863
+ toOuterPoint$1(matrix, point, toPoint$2);
864
+ addPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
871
865
  point.x = t.x;
872
- toOuterPoint$1(matrix, point, toPoint$1);
873
- addPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
866
+ toOuterPoint$1(matrix, point, toPoint$2);
867
+ addPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
874
868
  toBounds$2(tempPointBounds$1, to);
875
869
  }
876
870
  },
@@ -883,13 +877,16 @@ const BoundsHelper = {
883
877
  const scale = Math.min(baseScale, Math.min(t.width / put.width, t.height / put.height));
884
878
  return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
885
879
  },
886
- getSpread(t, spreadX, spreadY) {
880
+ getSpread(t, spread) {
887
881
  const n = {};
888
- B.copyAndSpread(n, t, spreadX, spreadY);
882
+ B.copyAndSpread(n, t, spread);
889
883
  return n;
890
884
  },
891
- spread(t, spreadX, spreadY = spreadX) {
892
- B.copyAndSpread(t, t, spreadX, spreadY);
885
+ spread(t, spread) {
886
+ B.copyAndSpread(t, t, spread);
887
+ },
888
+ shrink(t, shrink) {
889
+ B.copyAndSpread(t, t, shrink, true);
893
890
  },
894
891
  ceil(t) {
895
892
  const { x, y } = t;
@@ -1069,12 +1066,12 @@ class Bounds {
1069
1066
  getFitMatrix(put, baseScale) {
1070
1067
  return BoundsHelper.getFitMatrix(this, put, baseScale);
1071
1068
  }
1072
- spread(fourNumber, spreadY) {
1073
- BoundsHelper.spread(this, fourNumber, spreadY);
1069
+ spread(fourNumber) {
1070
+ BoundsHelper.spread(this, fourNumber);
1074
1071
  return this;
1075
1072
  }
1076
1073
  shrink(fourNumber) {
1077
- BoundsHelper.spread(this, MathHelper.minus(fourNumber, true));
1074
+ BoundsHelper.shrink(this, fourNumber);
1078
1075
  return this;
1079
1076
  }
1080
1077
  ceil() {
@@ -1191,6 +1188,10 @@ exports.Direction9 = void 0;
1191
1188
  Direction9[Direction9["bottomLeft"] = 6] = "bottomLeft";
1192
1189
  Direction9[Direction9["left"] = 7] = "left";
1193
1190
  Direction9[Direction9["center"] = 8] = "center";
1191
+ Direction9[Direction9["top-left"] = 0] = "top-left";
1192
+ Direction9[Direction9["top-right"] = 2] = "top-right";
1193
+ Direction9[Direction9["bottom-right"] = 4] = "bottom-right";
1194
+ Direction9[Direction9["bottom-left"] = 6] = "bottom-left";
1194
1195
  })(exports.Direction9 || (exports.Direction9 = {}));
1195
1196
 
1196
1197
  const directionData = [
@@ -1204,6 +1205,7 @@ const directionData = [
1204
1205
  { x: 0, y: 0.5 },
1205
1206
  { x: 0.5, y: 0.5 }
1206
1207
  ];
1208
+ directionData.forEach(item => item.type = 'percent');
1207
1209
  const AroundHelper = {
1208
1210
  directionData,
1209
1211
  tempPoint: {},
@@ -1211,15 +1213,19 @@ const AroundHelper = {
1211
1213
  toPoint(around, bounds, to, onlySize, pointBounds) {
1212
1214
  to || (to = {});
1213
1215
  const point = get(around);
1214
- to.x = point.x * bounds.width;
1215
- to.y = point.y * bounds.height;
1216
- if (pointBounds) {
1217
- to.x -= pointBounds.x;
1218
- to.y -= pointBounds.y;
1219
- if (point.x)
1220
- to.x -= (point.x === 1) ? pointBounds.width : (point.x === 0.5 ? point.x * pointBounds.width : 0);
1221
- if (point.y)
1222
- to.y -= (point.y === 1) ? pointBounds.height : (point.y === 0.5 ? point.y * pointBounds.height : 0);
1216
+ to.x = point.x;
1217
+ to.y = point.y;
1218
+ if (point.type === 'percent') {
1219
+ to.x *= bounds.width;
1220
+ to.y *= bounds.height;
1221
+ if (pointBounds) {
1222
+ to.x -= pointBounds.x;
1223
+ to.y -= pointBounds.y;
1224
+ if (point.x)
1225
+ to.x -= (point.x === 1) ? pointBounds.width : (point.x === 0.5 ? point.x * pointBounds.width : 0);
1226
+ if (point.y)
1227
+ to.y -= (point.y === 1) ? pointBounds.height : (point.y === 0.5 ? point.y * pointBounds.height : 0);
1228
+ }
1223
1229
  }
1224
1230
  if (!onlySize) {
1225
1231
  to.x += bounds.x;
@@ -1231,6 +1237,13 @@ function get(around) {
1231
1237
  return typeof around === 'string' ? directionData[exports.Direction9[around]] : around;
1232
1238
  }
1233
1239
 
1240
+ const { toPoint: toPoint$1 } = AroundHelper;
1241
+ const AlignHelper = {
1242
+ toPoint(align, contentBounds, bounds, to, onlySize) {
1243
+ toPoint$1(align, bounds, to, onlySize, contentBounds);
1244
+ }
1245
+ };
1246
+
1234
1247
  const StringNumberMap = {
1235
1248
  '0': 1,
1236
1249
  '1': 1,
@@ -1463,13 +1476,21 @@ const DataHelper = {
1463
1476
  },
1464
1477
  clone(data) {
1465
1478
  return JSON.parse(JSON.stringify(data));
1479
+ },
1480
+ toMap(list) {
1481
+ const map = {};
1482
+ for (let i = 0, len = list.length; i < len; i++)
1483
+ map[list[i]] = true;
1484
+ return map;
1466
1485
  }
1467
1486
  };
1468
1487
  const { assign } = DataHelper;
1469
1488
 
1470
1489
  class LeafData {
1490
+ get __useNaturalRatio() { return true; }
1491
+ get __isLinePath() { return this.path && this.path.length === 6; }
1471
1492
  get __blendMode() {
1472
- if (this.eraser)
1493
+ if (this.eraser && this.eraser !== 'path')
1473
1494
  return 'destination-out';
1474
1495
  const { blendMode } = this;
1475
1496
  return blendMode === 'pass-through' ? null : blendMode;
@@ -1965,6 +1986,11 @@ class LeaferCanvasBase extends Canvas {
1965
1986
  }
1966
1987
  updateViewSize() { }
1967
1988
  updateClientBounds() { }
1989
+ getClientBounds(update) {
1990
+ if (update)
1991
+ this.updateClientBounds();
1992
+ return this.clientBounds || this.bounds;
1993
+ }
1968
1994
  startAutoLayout(_autoBounds, _listener) { }
1969
1995
  stopAutoLayout() { }
1970
1996
  setCursor(_cursor) { }
@@ -2099,7 +2125,7 @@ class LeaferCanvasBase extends Canvas {
2099
2125
  }
2100
2126
  clear() {
2101
2127
  const { pixelRatio } = this;
2102
- this.clearRect(0, 0, this.width * pixelRatio, this.height * pixelRatio);
2128
+ this.clearRect(0, 0, this.width * pixelRatio + 2, this.height * pixelRatio + 2);
2103
2129
  }
2104
2130
  isSameSize(size) {
2105
2131
  return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
@@ -2513,11 +2539,15 @@ const PathConvert = {
2513
2539
  char = pathString[i];
2514
2540
  if (StringNumberMap[char]) {
2515
2541
  if (char === '.') {
2516
- current.dot++;
2517
- if (current.dot > 1) {
2542
+ if (current.dot) {
2518
2543
  pushData(data, num);
2519
2544
  num = '';
2520
2545
  }
2546
+ current.dot++;
2547
+ }
2548
+ if (num === '0' && char !== '.') {
2549
+ pushData(data, num);
2550
+ num = '';
2521
2551
  }
2522
2552
  num += char;
2523
2553
  }
@@ -3607,7 +3637,9 @@ class LeaferImage {
3607
3637
  }
3608
3638
  }
3609
3639
 
3610
- function defineKey(target, key, descriptor) {
3640
+ function defineKey(target, key, descriptor, noConfigurable) {
3641
+ if (!noConfigurable)
3642
+ descriptor.configurable = descriptor.enumerable = true;
3611
3643
  Object.defineProperty(target, key, descriptor);
3612
3644
  }
3613
3645
  function getDescriptor(object, name) {
@@ -3626,9 +3658,7 @@ function attr(partDescriptor) {
3626
3658
  function defineLeafAttr(target, key, defaultValue, partDescriptor) {
3627
3659
  const defaultDescriptor = {
3628
3660
  get() { return this.__getAttr(key); },
3629
- set(value) { this.__setAttr(key, value); },
3630
- configurable: true,
3631
- enumerable: true
3661
+ set(value) { this.__setAttr(key, value); }
3632
3662
  };
3633
3663
  defineKey(target, key, Object.assign(defaultDescriptor, partDescriptor || {}));
3634
3664
  defineDataProcessor(target, key, defaultValue);
@@ -3639,35 +3669,33 @@ function dataType(defaultValue) {
3639
3669
  function positionType(defaultValue, checkFiniteNumber) {
3640
3670
  return decorateLeafAttr(defaultValue, (key) => attr({
3641
3671
  set(value) {
3642
- this.__setAttr(key, value, checkFiniteNumber);
3643
- this.__layout.matrixChanged || this.__layout.matrixChange();
3672
+ this.__setAttr(key, value, checkFiniteNumber) && (this.__layout.matrixChanged || this.__layout.matrixChange());
3644
3673
  }
3645
3674
  }));
3646
3675
  }
3647
3676
  function autoLayoutType(defaultValue) {
3648
3677
  return decorateLeafAttr(defaultValue, (key) => attr({
3649
3678
  set(value) {
3650
- this.__setAttr(key, value);
3651
- this.__layout.matrixChanged || this.__layout.matrixChange();
3652
- this.__hasAutoLayout = !!value;
3653
- if (!this.__local)
3654
- this.__layout.createLocal();
3679
+ if (this.__setAttr(key, value)) {
3680
+ this.__layout.matrixChanged || this.__layout.matrixChange();
3681
+ this.__hasAutoLayout = !!value;
3682
+ if (!this.__local)
3683
+ this.__layout.createLocal();
3684
+ }
3655
3685
  }
3656
3686
  }));
3657
3687
  }
3658
3688
  function scaleType(defaultValue, checkFiniteNumber) {
3659
3689
  return decorateLeafAttr(defaultValue, (key) => attr({
3660
3690
  set(value) {
3661
- this.__setAttr(key, value, checkFiniteNumber);
3662
- this.__layout.scaleChanged || this.__layout.scaleChange();
3691
+ this.__setAttr(key, value, checkFiniteNumber) && (this.__layout.scaleChanged || this.__layout.scaleChange());
3663
3692
  }
3664
3693
  }));
3665
3694
  }
3666
3695
  function rotationType(defaultValue, checkFiniteNumber) {
3667
3696
  return decorateLeafAttr(defaultValue, (key) => attr({
3668
3697
  set(value) {
3669
- this.__setAttr(key, value, checkFiniteNumber);
3670
- this.__layout.rotationChanged || this.__layout.rotationChange();
3698
+ this.__setAttr(key, value, checkFiniteNumber) && (this.__layout.rotationChanged || this.__layout.rotationChange());
3671
3699
  }
3672
3700
  }));
3673
3701
  }
@@ -3681,9 +3709,7 @@ function boundsType(defaultValue, checkFiniteNumber) {
3681
3709
  function naturalBoundsType(defaultValue) {
3682
3710
  return decorateLeafAttr(defaultValue, (key) => attr({
3683
3711
  set(value) {
3684
- this.__setAttr(key, value);
3685
- doBoundsType(this);
3686
- this.__.__removeNaturalSize();
3712
+ this.__setAttr(key, value) && (doBoundsType(this), this.__.__removeNaturalSize());
3687
3713
  }
3688
3714
  }));
3689
3715
  }
@@ -3695,8 +3721,11 @@ function doBoundsType(leaf) {
3695
3721
  function pathInputType(defaultValue) {
3696
3722
  return decorateLeafAttr(defaultValue, (key) => attr({
3697
3723
  set(value) {
3698
- if (this.__.__pathInputed !== 2)
3699
- this.__.__pathInputed = value ? 1 : 0;
3724
+ const data = this.__;
3725
+ if (data.__pathInputed !== 2)
3726
+ data.__pathInputed = value ? 1 : 0;
3727
+ if (!value)
3728
+ data.__pathForRender = undefined;
3700
3729
  this.__setAttr(key, value);
3701
3730
  doBoundsType(this);
3702
3731
  }
@@ -3727,54 +3756,66 @@ function affectRenderBoundsType(defaultValue) {
3727
3756
  function surfaceType(defaultValue) {
3728
3757
  return decorateLeafAttr(defaultValue, (key) => attr({
3729
3758
  set(value) {
3730
- this.__setAttr(key, value);
3731
- this.__layout.surfaceChanged || this.__layout.surfaceChange();
3759
+ this.__setAttr(key, value) && (this.__layout.surfaceChanged || this.__layout.surfaceChange());
3732
3760
  }
3733
3761
  }));
3734
3762
  }
3735
3763
  function opacityType(defaultValue) {
3736
3764
  return decorateLeafAttr(defaultValue, (key) => attr({
3737
3765
  set(value) {
3738
- this.__setAttr(key, value);
3739
- this.__layout.opacityChanged || this.__layout.opacityChange();
3766
+ this.__setAttr(key, value) && (this.__layout.opacityChanged || this.__layout.opacityChange());
3767
+ }
3768
+ }));
3769
+ }
3770
+ function visibleType(defaultValue) {
3771
+ return decorateLeafAttr(defaultValue, (key) => attr({
3772
+ set(value) {
3773
+ const oldValue = this.visible;
3774
+ if (this.__setAttr(key, value)) {
3775
+ this.__layout.opacityChanged || this.__layout.opacityChange();
3776
+ if (oldValue === 0 || value === 0)
3777
+ doBoundsType(this);
3778
+ }
3740
3779
  }
3741
3780
  }));
3742
3781
  }
3743
3782
  function sortType(defaultValue) {
3744
3783
  return decorateLeafAttr(defaultValue, (key) => attr({
3745
3784
  set(value) {
3746
- this.__setAttr(key, value);
3747
- this.__layout.surfaceChanged || this.__layout.surfaceChange();
3748
- this.waitParent(() => { this.parent.__layout.childrenSortChange(); });
3785
+ if (this.__setAttr(key, value)) {
3786
+ this.__layout.surfaceChanged || this.__layout.surfaceChange();
3787
+ this.waitParent(() => { this.parent.__layout.childrenSortChange(); });
3788
+ }
3749
3789
  }
3750
3790
  }));
3751
3791
  }
3752
3792
  function maskType(defaultValue) {
3753
3793
  return decorateLeafAttr(defaultValue, (key) => attr({
3754
3794
  set(value) {
3755
- this.__setAttr(key, value);
3756
- this.__layout.boxChanged || this.__layout.boxChange();
3757
- this.waitParent(() => { this.parent.__updateMask(value); });
3795
+ if (this.__setAttr(key, value)) {
3796
+ this.__layout.boxChanged || this.__layout.boxChange();
3797
+ this.waitParent(() => { this.parent.__updateMask(value); });
3798
+ }
3758
3799
  }
3759
3800
  }));
3760
3801
  }
3761
3802
  function eraserType(defaultValue) {
3762
3803
  return decorateLeafAttr(defaultValue, (key) => attr({
3763
3804
  set(value) {
3764
- this.__setAttr(key, value);
3765
- this.waitParent(() => { this.parent.__updateEraser(value); });
3805
+ this.__setAttr(key, value) && this.waitParent(() => { this.parent.__updateEraser(value); });
3766
3806
  }
3767
3807
  }));
3768
3808
  }
3769
3809
  function hitType(defaultValue) {
3770
3810
  return decorateLeafAttr(defaultValue, (key) => attr({
3771
3811
  set(value) {
3772
- this.__setAttr(key, value);
3773
- if (Debug.showHitView) {
3774
- this.__layout.surfaceChanged || this.__layout.surfaceChange();
3812
+ if (this.__setAttr(key, value)) {
3813
+ if (Debug.showHitView) {
3814
+ this.__layout.surfaceChanged || this.__layout.surfaceChange();
3815
+ }
3816
+ if (this.leafer)
3817
+ this.leafer.updateCursor();
3775
3818
  }
3776
- if (this.leafer)
3777
- this.leafer.updateCursor();
3778
3819
  }
3779
3820
  }));
3780
3821
  }
@@ -3815,9 +3856,7 @@ function defineDataProcessor(target, key, defaultValue) {
3815
3856
  },
3816
3857
  set(value) {
3817
3858
  this[computedKey] = value;
3818
- },
3819
- configurable: true,
3820
- enumerable: true
3859
+ }
3821
3860
  };
3822
3861
  if (defaultValue === undefined) {
3823
3862
  property.get = function () { return this[computedKey]; };
@@ -3825,13 +3864,25 @@ function defineDataProcessor(target, key, defaultValue) {
3825
3864
  else if (key === 'width') {
3826
3865
  property.get = function () {
3827
3866
  const v = this[computedKey];
3828
- return v === undefined ? (this.__naturalWidth || defaultValue) : v;
3867
+ if (v === undefined) {
3868
+ const t = this;
3869
+ return t._height && t.__naturalWidth && t.__useNaturalRatio ? t._height * t.__naturalWidth / t.__naturalHeight : t.__naturalWidth || defaultValue;
3870
+ }
3871
+ else {
3872
+ return v;
3873
+ }
3829
3874
  };
3830
3875
  }
3831
3876
  else if (key === 'height') {
3832
3877
  property.get = function () {
3833
3878
  const v = this[computedKey];
3834
- return v === undefined ? (this.__naturalHeight || defaultValue) : v;
3879
+ if (v === undefined) {
3880
+ const t = this;
3881
+ return t._width && t.__naturalHeight && t.__useNaturalRatio ? t._width * t.__naturalHeight / t.__naturalWidth : t.__naturalHeight || defaultValue;
3882
+ }
3883
+ else {
3884
+ return v;
3885
+ }
3835
3886
  };
3836
3887
  }
3837
3888
  let descriptor, find = data;
@@ -3845,7 +3896,7 @@ function defineDataProcessor(target, key, defaultValue) {
3845
3896
  property.set = data[setMethodName];
3846
3897
  delete data[setMethodName];
3847
3898
  }
3848
- Object.defineProperty(data, key, property);
3899
+ defineKey(data, key, property);
3849
3900
  }
3850
3901
 
3851
3902
  const debug$1 = new Debug('rewrite');
@@ -4046,13 +4097,6 @@ const LeafHelper = {
4046
4097
  return true;
4047
4098
  p = p.parent;
4048
4099
  }
4049
- },
4050
- hasParentAutoLayout(p) {
4051
- while (p.parent) {
4052
- p = p.parent;
4053
- if (p.__hasAutoLayout)
4054
- return true;
4055
- }
4056
4100
  }
4057
4101
  };
4058
4102
  const L = LeafHelper;
@@ -4072,13 +4116,13 @@ const LeafBoundsHelper = {
4072
4116
  return target.__world;
4073
4117
  },
4074
4118
  localBoxBounds(target) {
4075
- return target.__.eraser ? null : (target.__local || target.__layout);
4119
+ return target.__.eraser || target.__.visible === 0 ? null : (target.__local || target.__layout);
4076
4120
  },
4077
4121
  localStrokeBounds(target) {
4078
- return target.__.eraser ? null : target.__layout.localStrokeBounds;
4122
+ return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localStrokeBounds;
4079
4123
  },
4080
4124
  localRenderBounds(target) {
4081
- return target.__.eraser ? null : target.__layout.localRenderBounds;
4125
+ return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localRenderBounds;
4082
4126
  },
4083
4127
  maskLocalBoxBounds(target) {
4084
4128
  return target.__.mask ? target.__localBoxBounds : null;
@@ -4184,11 +4228,19 @@ const WaitHelper = {
4184
4228
 
4185
4229
  const { getRelativeWorld: getRelativeWorld$1 } = LeafHelper;
4186
4230
  const { toOuterOf: toOuterOf$2, getPoints, copy: copy$2 } = BoundsHelper;
4231
+ const localContent = '_localContentBounds';
4232
+ const worldContent = '_worldContentBounds', worldBox = '_worldBoxBounds', worldStroke = '_worldStrokeBounds';
4187
4233
  class LeafLayout {
4234
+ get contentBounds() { return this._contentBounds || this.boxBounds; }
4235
+ set contentBounds(bounds) { this._contentBounds = bounds; }
4188
4236
  get strokeBounds() { return this._strokeBounds || this.boxBounds; }
4189
4237
  get renderBounds() { return this._renderBounds || this.boxBounds; }
4238
+ get localContentBounds() { toOuterOf$2(this.contentBounds, this.leaf.__localMatrix, this[localContent] || (this[localContent] = {})); return this[localContent]; }
4190
4239
  get localStrokeBounds() { return this._localStrokeBounds || this; }
4191
4240
  get localRenderBounds() { return this._localRenderBounds || this; }
4241
+ get worldContentBounds() { toOuterOf$2(this.contentBounds, this.leaf.__world, this[worldContent] || (this[worldContent] = {})); return this[worldContent]; }
4242
+ get worldBoxBounds() { toOuterOf$2(this.boxBounds, this.leaf.__world, this[worldBox] || (this[worldBox] = {})); return this[worldBox]; }
4243
+ get worldStrokeBounds() { toOuterOf$2(this.strokeBounds, this.leaf.__world, this[worldStroke] || (this[worldStroke] = {})); return this[worldStroke]; }
4192
4244
  get a() { return 1; }
4193
4245
  get b() { return 0; }
4194
4246
  get c() { return 0; }
@@ -4271,7 +4323,6 @@ class LeafLayout {
4271
4323
  case 'content':
4272
4324
  if (this.contentBounds)
4273
4325
  return this.contentBounds;
4274
- case 'margin':
4275
4326
  case 'box':
4276
4327
  return this.boxBounds;
4277
4328
  case 'stroke':
@@ -4284,8 +4335,9 @@ class LeafLayout {
4284
4335
  return this.localRenderBounds;
4285
4336
  case 'stroke':
4286
4337
  return this.localStrokeBounds;
4287
- case 'margin':
4288
4338
  case 'content':
4339
+ if (this.contentBounds)
4340
+ return this.localContentBounds;
4289
4341
  case 'box':
4290
4342
  return this.leaf.__localBoxBounds;
4291
4343
  }
@@ -4294,15 +4346,13 @@ class LeafLayout {
4294
4346
  switch (type) {
4295
4347
  case 'render':
4296
4348
  return this.leaf.__world;
4349
+ case 'stroke':
4350
+ return this.worldStrokeBounds;
4297
4351
  case 'content':
4298
4352
  if (this.contentBounds)
4299
- return this.getWorldContentBounds();
4300
- case 'margin':
4353
+ return this.worldContentBounds;
4301
4354
  case 'box':
4302
- return this.getWorldBoxBounds();
4303
- case 'margin':
4304
- case 'stroke':
4305
- return this.getWorldStrokeBounds();
4355
+ return this.worldBoxBounds;
4306
4356
  }
4307
4357
  }
4308
4358
  getLayoutBounds(type, relative = 'world', unscale) {
@@ -4365,20 +4415,24 @@ class LeafLayout {
4365
4415
  points.forEach(point => leaf.innerToWorld(point, null, false, relativeLeaf));
4366
4416
  return points;
4367
4417
  }
4368
- getWorldContentBounds() {
4369
- this._worldContentBounds || (this._worldContentBounds = {});
4370
- toOuterOf$2(this.contentBounds, this.leaf.__world, this._worldContentBounds);
4371
- return this._worldContentBounds;
4418
+ shrinkContent() {
4419
+ const { x, y, width, height } = this.boxBounds;
4420
+ this._contentBounds = { x, y, width, height };
4421
+ }
4422
+ spreadStroke() {
4423
+ const { x, y, width, height } = this.strokeBounds;
4424
+ this._strokeBounds = { x, y, width, height };
4425
+ this._localStrokeBounds = { x, y, width, height };
4426
+ if (!this.renderSpread)
4427
+ this.spreadRenderCancel();
4372
4428
  }
4373
- getWorldBoxBounds() {
4374
- this._worldBoxBounds || (this._worldBoxBounds = {});
4375
- toOuterOf$2(this.boxBounds, this.leaf.__world, this._worldBoxBounds);
4376
- return this._worldBoxBounds;
4429
+ spreadRender() {
4430
+ const { x, y, width, height } = this.renderBounds;
4431
+ this._renderBounds = { x, y, width, height };
4432
+ this._localRenderBounds = { x, y, width, height };
4377
4433
  }
4378
- getWorldStrokeBounds() {
4379
- this._worldStrokeBounds || (this._worldStrokeBounds = {});
4380
- toOuterOf$2(this.strokeBounds, this.leaf.__world, this._worldStrokeBounds);
4381
- return this._worldStrokeBounds;
4434
+ shrinkContentCancel() {
4435
+ this._contentBounds = undefined;
4382
4436
  }
4383
4437
  spreadStrokeCancel() {
4384
4438
  const same = this.renderBounds === this.strokeBounds;
@@ -4391,18 +4445,6 @@ class LeafLayout {
4391
4445
  this._renderBounds = this._strokeBounds;
4392
4446
  this._localRenderBounds = this._localStrokeBounds;
4393
4447
  }
4394
- spreadStroke() {
4395
- const { x, y, width, height } = this.strokeBounds;
4396
- this._strokeBounds = { x, y, width, height };
4397
- this._localStrokeBounds = { x, y, width, height };
4398
- if (!this.renderSpread)
4399
- this.spreadRenderCancel();
4400
- }
4401
- spreadRender() {
4402
- const { x, y, width, height } = this.renderBounds;
4403
- this._renderBounds = { x, y, width, height };
4404
- this._localRenderBounds = { x, y, width, height };
4405
- }
4406
4448
  boxChange() {
4407
4449
  this.boxChanged = true;
4408
4450
  this.localBoxChanged || this.localBoxChange();
@@ -4489,24 +4531,40 @@ const LeafEventer = {
4489
4531
  });
4490
4532
  },
4491
4533
  off(type, listener, options) {
4492
- let capture;
4493
- if (options)
4494
- capture = typeof options === 'boolean' ? options : options.capture;
4495
- let events, index;
4496
- const map = __getListenerMap(this, capture);
4497
- const typeList = typeof type === 'string' ? type.split(' ') : type;
4498
- typeList.forEach(type => {
4499
- if (type) {
4500
- events = map[type];
4501
- if (events) {
4502
- index = events.findIndex(item => item.listener === listener);
4503
- if (index > -1)
4504
- events.splice(index, 1);
4505
- if (!events.length)
4506
- delete map[type];
4507
- }
4534
+ if (type) {
4535
+ const typeList = typeof type === 'string' ? type.split(' ') : type;
4536
+ if (listener) {
4537
+ let capture;
4538
+ if (options)
4539
+ capture = typeof options === 'boolean' ? options : options.capture;
4540
+ let events, index;
4541
+ const map = __getListenerMap(this, capture);
4542
+ typeList.forEach(type => {
4543
+ if (type) {
4544
+ events = map[type];
4545
+ if (events) {
4546
+ index = events.findIndex(item => item.listener === listener);
4547
+ if (index > -1)
4548
+ events.splice(index, 1);
4549
+ if (!events.length)
4550
+ delete map[type];
4551
+ }
4552
+ }
4553
+ });
4508
4554
  }
4509
- });
4555
+ else {
4556
+ const { __bubbleMap: b, __captureMap: c } = this;
4557
+ typeList.forEach(type => {
4558
+ if (b)
4559
+ delete b[type];
4560
+ if (c)
4561
+ delete c[type];
4562
+ });
4563
+ }
4564
+ }
4565
+ else {
4566
+ this.__bubbleMap = this.__captureMap = undefined;
4567
+ }
4510
4568
  },
4511
4569
  on_(type, listener, bind, options) {
4512
4570
  if (bind)
@@ -4773,7 +4831,7 @@ const { setLayout, multiplyParent: multiplyParent$1, translateInner, defaultWorl
4773
4831
  const { toPoint, tempPoint } = AroundHelper;
4774
4832
  const LeafMatrix = {
4775
4833
  __updateWorldMatrix() {
4776
- multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__);
4834
+ multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__, this.parent && this.parent.__);
4777
4835
  },
4778
4836
  __updateLocalMatrix() {
4779
4837
  if (this.__local) {
@@ -4784,18 +4842,18 @@ const LeafMatrix = {
4784
4842
  layout.scaleChanged = layout.rotationChanged = false;
4785
4843
  }
4786
4844
  }
4787
- local.e = data.x;
4788
- local.f = data.y;
4789
- if (data.around) {
4790
- toPoint(data.around, layout.boxBounds, tempPoint);
4791
- translateInner(local, -tempPoint.x, -tempPoint.y);
4845
+ local.e = data.x + data.offsetX;
4846
+ local.f = data.y + data.offsetY;
4847
+ if (data.around || data.origin) {
4848
+ toPoint(data.around || data.origin, layout.boxBounds, tempPoint);
4849
+ translateInner(local, -tempPoint.x, -tempPoint.y, data.origin);
4792
4850
  }
4793
4851
  }
4794
4852
  this.__layout.matrixChanged = false;
4795
4853
  }
4796
4854
  };
4797
4855
 
4798
- const { updateMatrix, updateAllMatrix, hasParentAutoLayout } = LeafHelper;
4856
+ const { updateMatrix, updateAllMatrix } = LeafHelper;
4799
4857
  const { updateBounds } = BranchHelper;
4800
4858
  const { toOuterOf: toOuterOf$1, copyAndSpread, copy: copy$1 } = BoundsHelper;
4801
4859
  const { toBounds } = PathBounds;
@@ -4814,7 +4872,6 @@ const LeafBounds = {
4814
4872
  this.__updatePath();
4815
4873
  this.__updateRenderPath();
4816
4874
  this.__updateBoxBounds();
4817
- layout.boxChanged = false;
4818
4875
  layout.resized = true;
4819
4876
  }
4820
4877
  if (layout.localBoxChanged) {
@@ -4828,12 +4885,12 @@ const LeafBounds = {
4828
4885
  if (this.parent)
4829
4886
  this.parent.__layout.boxChange();
4830
4887
  }
4888
+ layout.boxChanged = false;
4831
4889
  if (layout.strokeChanged) {
4832
4890
  layout.strokeSpread = this.__updateStrokeSpread();
4833
4891
  if (layout.strokeSpread) {
4834
- if (layout.strokeBounds === layout.boxBounds) {
4892
+ if (layout.strokeBounds === layout.boxBounds)
4835
4893
  layout.spreadStroke();
4836
- }
4837
4894
  this.__updateStrokeBounds();
4838
4895
  this.__updateLocalStrokeBounds();
4839
4896
  }
@@ -4841,7 +4898,7 @@ const LeafBounds = {
4841
4898
  layout.spreadStrokeCancel();
4842
4899
  }
4843
4900
  layout.strokeChanged = false;
4844
- if (layout.renderSpread)
4901
+ if (layout.renderSpread || layout.strokeSpread !== layout.strokeBoxSpread)
4845
4902
  layout.renderChanged = true;
4846
4903
  if (this.parent)
4847
4904
  this.parent.__layout.strokeChange();
@@ -4850,9 +4907,8 @@ const LeafBounds = {
4850
4907
  if (layout.renderChanged) {
4851
4908
  layout.renderSpread = this.__updateRenderSpread();
4852
4909
  if (layout.renderSpread) {
4853
- if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds) {
4910
+ if (layout.renderBounds === layout.boxBounds || layout.renderBounds === layout.strokeBounds)
4854
4911
  layout.spreadRender();
4855
- }
4856
4912
  this.__updateRenderBounds();
4857
4913
  this.__updateLocalRenderBounds();
4858
4914
  }
@@ -4892,10 +4948,15 @@ const LeafBounds = {
4892
4948
  __updateAutoLayout() {
4893
4949
  this.__layout.matrixChanged = true;
4894
4950
  if (this.isBranch) {
4895
- if (this.leafer)
4951
+ if (this.leafer && this.leafer.ready)
4896
4952
  this.leafer.layouter.addExtra(this);
4897
- if (hasParentAutoLayout(this)) {
4898
- updateMatrix(this);
4953
+ if (this.__.flow) {
4954
+ if (this.__layout.boxChanged)
4955
+ this.__updateFlowLayout();
4956
+ updateAllMatrix(this);
4957
+ updateBounds(this, this);
4958
+ if (this.__.__autoSide)
4959
+ this.__updateBoxBounds();
4899
4960
  }
4900
4961
  else {
4901
4962
  updateAllMatrix(this);
@@ -4912,12 +4973,13 @@ const LeafBounds = {
4912
4973
  data.__naturalHeight = layout.boxBounds.height;
4913
4974
  },
4914
4975
  __updateStrokeBounds() {
4915
- copyAndSpread(this.__layout.strokeBounds, this.__layout.boxBounds, this.__layout.strokeSpread);
4976
+ const layout = this.__layout;
4977
+ copyAndSpread(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
4916
4978
  },
4917
4979
  __updateRenderBounds() {
4918
- const { renderSpread, strokeBounds, renderBounds } = this.__layout;
4919
- renderSpread > 0 ? copyAndSpread(renderBounds, strokeBounds, renderSpread) : copy$1(renderBounds, strokeBounds);
4920
- },
4980
+ const layout = this.__layout;
4981
+ layout.renderSpread > 0 ? copyAndSpread(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$1(layout.renderBounds, layout.strokeBounds);
4982
+ }
4921
4983
  };
4922
4984
 
4923
4985
  const LeafRender = {
@@ -4926,6 +4988,8 @@ const LeafRender = {
4926
4988
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
4927
4989
  canvas.opacity = this.__.opacity;
4928
4990
  if (this.__.__single) {
4991
+ if (this.__.eraser === 'path')
4992
+ return this.__renderEraser(canvas, options);
4929
4993
  const tempCanvas = canvas.getSameCanvas(true, true);
4930
4994
  this.__draw(tempCanvas, options);
4931
4995
  if (this.__worldFlipped) {
@@ -4968,6 +5032,8 @@ const BranchRender = {
4968
5032
  __render(canvas, options) {
4969
5033
  if (this.__worldOpacity) {
4970
5034
  if (this.__.__single) {
5035
+ if (this.__.eraser === 'path')
5036
+ return this.__renderEraser(canvas, options);
4971
5037
  const tempCanvas = canvas.getSameCanvas(false, true);
4972
5038
  this.__renderBranch(tempCanvas, options);
4973
5039
  const nowWorld = this.__getNowWorld(options);
@@ -5033,7 +5099,7 @@ exports.Leaf = class Leaf {
5033
5099
  get __worldFlipped() { return this.__world.scaleX < 0 || this.__world.scaleY < 0; }
5034
5100
  get __onlyHitMask() { return this.__hasMask && !this.__.hitChildren; }
5035
5101
  get __ignoreHitWorld() { return (this.__hasMask || this.__hasEraser) && this.__.hitChildren; }
5036
- get pathInputed() { return !!this.__.__pathInputed; }
5102
+ get pathInputed() { return this.__.__pathInputed; }
5037
5103
  constructor(data) {
5038
5104
  this.innerId = create(LEAF);
5039
5105
  this.reset(data);
@@ -5107,7 +5173,9 @@ exports.Leaf = class Leaf {
5107
5173
  setProxyAttr(_attrName, _newValue) { }
5108
5174
  getProxyAttr(_attrName) { return undefined; }
5109
5175
  find(_condition, _options) { return undefined; }
5176
+ findTag(_tag) { return undefined; }
5110
5177
  findOne(_condition, _options) { return undefined; }
5178
+ findId(_id) { return undefined; }
5111
5179
  focus(_value) { }
5112
5180
  forceUpdate(attrName) {
5113
5181
  if (attrName === undefined)
@@ -5129,9 +5197,11 @@ exports.Leaf = class Leaf {
5129
5197
  __updateLocalStrokeBounds() { }
5130
5198
  __updateLocalRenderBounds() { }
5131
5199
  __updateBoxBounds() { }
5200
+ __updateContentBounds() { }
5132
5201
  __updateStrokeBounds() { }
5133
5202
  __updateRenderBounds() { }
5134
5203
  __updateAutoLayout() { }
5204
+ __updateFlowLayout() { }
5135
5205
  __updateNaturalSize() { }
5136
5206
  __updateStrokeSpread() { return 0; }
5137
5207
  __updateRenderSpread() { return 0; }
@@ -5139,6 +5209,13 @@ exports.Leaf = class Leaf {
5139
5209
  __updateEraser(value) {
5140
5210
  this.__hasEraser = value ? true : this.children.some(item => item.__.eraser);
5141
5211
  }
5212
+ __renderEraser(canvas, options) {
5213
+ canvas.save();
5214
+ this.__clip(canvas, options);
5215
+ const { renderBounds: r } = this.__layout;
5216
+ canvas.clearRect(r.x, r.y, r.width, r.height);
5217
+ canvas.restore();
5218
+ }
5142
5219
  __updateMask(value) {
5143
5220
  this.__hasMask = value ? true : this.children.some(item => item.__.mask);
5144
5221
  }
@@ -5319,8 +5396,8 @@ exports.Leaf = class Leaf {
5319
5396
  emit(_type, _event, _capture) { }
5320
5397
  emitEvent(_event, _capture) { }
5321
5398
  hasEvent(_type, _capture) { return false; }
5322
- static changeAttr(attrName, defaultValue) {
5323
- defineDataProcessor(this.prototype, attrName, defaultValue);
5399
+ static changeAttr(attrName, defaultValue, fn) {
5400
+ fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue);
5324
5401
  }
5325
5402
  static addAttr(attrName, defaultValue, fn) {
5326
5403
  if (!fn)
@@ -5634,6 +5711,10 @@ class LeafLevelList {
5634
5711
  }
5635
5712
  }
5636
5713
 
5714
+ const version = "1.0.0-rc.24";
5715
+ const inviteCode = {};
5716
+
5717
+ exports.AlignHelper = AlignHelper;
5637
5718
  exports.AnimateEvent = AnimateEvent;
5638
5719
  exports.AroundHelper = AroundHelper;
5639
5720
  exports.AutoBounds = AutoBounds;
@@ -5724,6 +5805,7 @@ exports.getDescriptor = getDescriptor;
5724
5805
  exports.getMatrixData = getMatrixData;
5725
5806
  exports.getPointData = getPointData;
5726
5807
  exports.hitType = hitType;
5808
+ exports.inviteCode = inviteCode;
5727
5809
  exports.layoutProcessor = layoutProcessor;
5728
5810
  exports.maskType = maskType;
5729
5811
  exports.naturalBoundsType = naturalBoundsType;
@@ -5745,3 +5827,5 @@ exports.tempBounds = tempBounds;
5745
5827
  exports.tempMatrix = tempMatrix;
5746
5828
  exports.tempPoint = tempPoint$2;
5747
5829
  exports.useModule = useModule;
5830
+ exports.version = version;
5831
+ exports.visibleType = visibleType;