@leafer/core 1.6.1 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/core.cjs CHANGED
@@ -25,8 +25,6 @@ const Platform = {
25
25
  }
26
26
  };
27
27
 
28
- const Creator = {};
29
-
30
28
  const IncrementId = {
31
29
  RUNTIME: 'runtime',
32
30
  LEAF: 'leaf',
@@ -466,8 +464,10 @@ const PointHelper = {
466
464
  t.y = halfPixel ? round$2(t.y - 0.5) + 0.5 : round$2(t.y);
467
465
  },
468
466
  move(t, x, y) {
469
- t.x += x;
470
- t.y += y;
467
+ if (typeof x === 'object')
468
+ t.x += x.x, t.y += x.y;
469
+ else
470
+ t.x += x, t.y += y;
471
471
  },
472
472
  scale(t, scaleX, scaleY = scaleX) {
473
473
  if (t.x)
@@ -803,15 +803,87 @@ const TwoPointBoundsHelper = {
803
803
  };
804
804
  const { addPoint: addPoint$3 } = TwoPointBoundsHelper;
805
805
 
806
+ exports.Direction4 = void 0;
807
+ (function (Direction4) {
808
+ Direction4[Direction4["top"] = 0] = "top";
809
+ Direction4[Direction4["right"] = 1] = "right";
810
+ Direction4[Direction4["bottom"] = 2] = "bottom";
811
+ Direction4[Direction4["left"] = 3] = "left";
812
+ })(exports.Direction4 || (exports.Direction4 = {}));
813
+ exports.Direction9 = void 0;
814
+ (function (Direction9) {
815
+ Direction9[Direction9["topLeft"] = 0] = "topLeft";
816
+ Direction9[Direction9["top"] = 1] = "top";
817
+ Direction9[Direction9["topRight"] = 2] = "topRight";
818
+ Direction9[Direction9["right"] = 3] = "right";
819
+ Direction9[Direction9["bottomRight"] = 4] = "bottomRight";
820
+ Direction9[Direction9["bottom"] = 5] = "bottom";
821
+ Direction9[Direction9["bottomLeft"] = 6] = "bottomLeft";
822
+ Direction9[Direction9["left"] = 7] = "left";
823
+ Direction9[Direction9["center"] = 8] = "center";
824
+ Direction9[Direction9["top-left"] = 0] = "top-left";
825
+ Direction9[Direction9["top-right"] = 2] = "top-right";
826
+ Direction9[Direction9["bottom-right"] = 4] = "bottom-right";
827
+ Direction9[Direction9["bottom-left"] = 6] = "bottom-left";
828
+ })(exports.Direction9 || (exports.Direction9 = {}));
829
+
830
+ const directionData = [
831
+ { x: 0, y: 0 },
832
+ { x: 0.5, y: 0 },
833
+ { x: 1, y: 0 },
834
+ { x: 1, y: 0.5 },
835
+ { x: 1, y: 1 },
836
+ { x: 0.5, y: 1 },
837
+ { x: 0, y: 1 },
838
+ { x: 0, y: 0.5 },
839
+ { x: 0.5, y: 0.5 }
840
+ ];
841
+ directionData.forEach(item => item.type = 'percent');
842
+ const AroundHelper = {
843
+ directionData,
844
+ tempPoint: {},
845
+ get,
846
+ toPoint(around, box, to, onlyBoxSize, content, onlyContentSize) {
847
+ const point = get(around);
848
+ to.x = point.x;
849
+ to.y = point.y;
850
+ if (point.type === 'percent') {
851
+ to.x *= box.width;
852
+ to.y *= box.height;
853
+ if (content) {
854
+ if (!onlyContentSize)
855
+ to.x -= content.x, to.y -= content.y;
856
+ if (point.x)
857
+ to.x -= (point.x === 1) ? content.width : (point.x === 0.5 ? point.x * content.width : 0);
858
+ if (point.y)
859
+ to.y -= (point.y === 1) ? content.height : (point.y === 0.5 ? point.y * content.height : 0);
860
+ }
861
+ }
862
+ if (!onlyBoxSize)
863
+ to.x += box.x, to.y += box.y;
864
+ }
865
+ };
866
+ function get(around) {
867
+ return typeof around === 'string' ? directionData[exports.Direction9[around]] : around;
868
+ }
869
+
870
+ const { toPoint: toPoint$2 } = AroundHelper;
871
+ const AlignHelper = {
872
+ toPoint(align, content, box, to, onlyBoxSize, onlyContentSize) {
873
+ toPoint$2(align, box, to, onlyBoxSize, content, onlyContentSize);
874
+ }
875
+ };
876
+
806
877
  const { tempPointBounds: tempPointBounds$1, setPoint: setPoint$2, addPoint: addPoint$2, toBounds: toBounds$2 } = TwoPointBoundsHelper;
807
878
  const { toOuterPoint: toOuterPoint$2 } = MatrixHelper;
808
879
  const { float, fourNumber } = MathHelper;
809
880
  const { floor, ceil: ceil$1 } = Math;
810
881
  let right, bottom, boundsRight, boundsBottom;
811
882
  const point = {};
812
- const toPoint$2 = {};
883
+ const toPoint$1 = {};
884
+ const tempBounds$1 = {};
813
885
  const BoundsHelper = {
814
- tempBounds: {},
886
+ tempBounds: tempBounds$1,
815
887
  set(t, x = 0, y = 0, width = 0, height = 0) {
816
888
  t.x = x;
817
889
  t.y = y;
@@ -874,8 +946,8 @@ const BoundsHelper = {
874
946
  }
875
947
  B.move(to, -to.offsetX, -to.offsetY);
876
948
  },
877
- scale(t, scaleX, scaleY = scaleX) {
878
- PointHelper.scale(t, scaleX, scaleY);
949
+ scale(t, scaleX, scaleY = scaleX, onlySize) {
950
+ onlySize || PointHelper.scale(t, scaleX, scaleY);
879
951
  t.width *= scaleX;
880
952
  t.height *= scaleY;
881
953
  },
@@ -885,9 +957,9 @@ const BoundsHelper = {
885
957
  t.height *= scaleY;
886
958
  },
887
959
  tempToOuterOf(t, matrix) {
888
- B.copy(B.tempBounds, t);
889
- B.toOuterOf(B.tempBounds, matrix);
890
- return B.tempBounds;
960
+ B.copy(tempBounds$1, t);
961
+ B.toOuterOf(tempBounds$1, matrix);
962
+ return tempBounds$1;
891
963
  },
892
964
  getOuterOf(t, matrix) {
893
965
  t = Object.assign({}, t);
@@ -918,17 +990,17 @@ const BoundsHelper = {
918
990
  else {
919
991
  point.x = t.x;
920
992
  point.y = t.y;
921
- toOuterPoint$2(matrix, point, toPoint$2);
922
- setPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
993
+ toOuterPoint$2(matrix, point, toPoint$1);
994
+ setPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
923
995
  point.x = t.x + t.width;
924
- toOuterPoint$2(matrix, point, toPoint$2);
925
- addPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
996
+ toOuterPoint$2(matrix, point, toPoint$1);
997
+ addPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
926
998
  point.y = t.y + t.height;
927
- toOuterPoint$2(matrix, point, toPoint$2);
928
- addPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
999
+ toOuterPoint$2(matrix, point, toPoint$1);
1000
+ addPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
929
1001
  point.x = t.x;
930
- toOuterPoint$2(matrix, point, toPoint$2);
931
- addPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
1002
+ toOuterPoint$2(matrix, point, toPoint$1);
1003
+ addPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
932
1004
  toBounds$2(tempPointBounds$1, to);
933
1005
  }
934
1006
  },
@@ -938,9 +1010,21 @@ const BoundsHelper = {
938
1010
  B.scale(to, 1 / matrix.a, 1 / matrix.d);
939
1011
  },
940
1012
  getFitMatrix(t, put, baseScale = 1) {
941
- const scale = Math.min(baseScale, Math.min(t.width / put.width, t.height / put.height));
1013
+ const scale = Math.min(baseScale, B.getFitScale(t, put));
942
1014
  return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
943
1015
  },
1016
+ getFitScale(t, put, isCoverMode) {
1017
+ const sw = t.width / put.width, sh = t.height / put.height;
1018
+ return isCoverMode ? Math.max(sw, sh) : Math.min(sw, sh);
1019
+ },
1020
+ put(t, put, align = 'center', putScale = 1, changeSize = true, to) {
1021
+ to || (to = put);
1022
+ if (typeof putScale === 'string')
1023
+ putScale = B.getFitScale(t, put, putScale === 'cover');
1024
+ tempBounds$1.width = changeSize ? put.width *= putScale : put.width * putScale;
1025
+ tempBounds$1.height = changeSize ? put.height *= putScale : put.height * putScale;
1026
+ AlignHelper.toPoint(align, tempBounds$1, t, to, true, true);
1027
+ },
944
1028
  getSpread(t, spread, side) {
945
1029
  const n = {};
946
1030
  B.copyAndSpread(n, t, spread, false, side);
@@ -1114,8 +1198,8 @@ class Bounds {
1114
1198
  BoundsHelper.move(this, x, y);
1115
1199
  return this;
1116
1200
  }
1117
- scale(scaleX, scaleY) {
1118
- BoundsHelper.scale(this, scaleX, scaleY);
1201
+ scale(scaleX, scaleY, onlySize) {
1202
+ BoundsHelper.scale(this, scaleX, scaleY, onlySize);
1119
1203
  return this;
1120
1204
  }
1121
1205
  scaleOf(origin, scaleX, scaleY) {
@@ -1133,6 +1217,9 @@ class Bounds {
1133
1217
  getFitMatrix(put, baseScale) {
1134
1218
  return BoundsHelper.getFitMatrix(this, put, baseScale);
1135
1219
  }
1220
+ put(put, align, putScale) {
1221
+ BoundsHelper.put(this, put, align, putScale);
1222
+ }
1136
1223
  spread(fourNumber, side) {
1137
1224
  BoundsHelper.spread(this, fourNumber, side);
1138
1225
  return this;
@@ -1241,79 +1328,6 @@ class AutoBounds {
1241
1328
  }
1242
1329
  }
1243
1330
 
1244
- exports.Direction4 = void 0;
1245
- (function (Direction4) {
1246
- Direction4[Direction4["top"] = 0] = "top";
1247
- Direction4[Direction4["right"] = 1] = "right";
1248
- Direction4[Direction4["bottom"] = 2] = "bottom";
1249
- Direction4[Direction4["left"] = 3] = "left";
1250
- })(exports.Direction4 || (exports.Direction4 = {}));
1251
- exports.Direction9 = void 0;
1252
- (function (Direction9) {
1253
- Direction9[Direction9["topLeft"] = 0] = "topLeft";
1254
- Direction9[Direction9["top"] = 1] = "top";
1255
- Direction9[Direction9["topRight"] = 2] = "topRight";
1256
- Direction9[Direction9["right"] = 3] = "right";
1257
- Direction9[Direction9["bottomRight"] = 4] = "bottomRight";
1258
- Direction9[Direction9["bottom"] = 5] = "bottom";
1259
- Direction9[Direction9["bottomLeft"] = 6] = "bottomLeft";
1260
- Direction9[Direction9["left"] = 7] = "left";
1261
- Direction9[Direction9["center"] = 8] = "center";
1262
- Direction9[Direction9["top-left"] = 0] = "top-left";
1263
- Direction9[Direction9["top-right"] = 2] = "top-right";
1264
- Direction9[Direction9["bottom-right"] = 4] = "bottom-right";
1265
- Direction9[Direction9["bottom-left"] = 6] = "bottom-left";
1266
- })(exports.Direction9 || (exports.Direction9 = {}));
1267
-
1268
- const directionData = [
1269
- { x: 0, y: 0 },
1270
- { x: 0.5, y: 0 },
1271
- { x: 1, y: 0 },
1272
- { x: 1, y: 0.5 },
1273
- { x: 1, y: 1 },
1274
- { x: 0.5, y: 1 },
1275
- { x: 0, y: 1 },
1276
- { x: 0, y: 0.5 },
1277
- { x: 0.5, y: 0.5 }
1278
- ];
1279
- directionData.forEach(item => item.type = 'percent');
1280
- const AroundHelper = {
1281
- directionData,
1282
- tempPoint: {},
1283
- get,
1284
- toPoint(around, bounds, to, onlySize, pointBounds) {
1285
- const point = get(around);
1286
- to.x = point.x;
1287
- to.y = point.y;
1288
- if (point.type === 'percent') {
1289
- to.x *= bounds.width;
1290
- to.y *= bounds.height;
1291
- if (pointBounds) {
1292
- to.x -= pointBounds.x;
1293
- to.y -= pointBounds.y;
1294
- if (point.x)
1295
- to.x -= (point.x === 1) ? pointBounds.width : (point.x === 0.5 ? point.x * pointBounds.width : 0);
1296
- if (point.y)
1297
- to.y -= (point.y === 1) ? pointBounds.height : (point.y === 0.5 ? point.y * pointBounds.height : 0);
1298
- }
1299
- }
1300
- if (!onlySize) {
1301
- to.x += bounds.x;
1302
- to.y += bounds.y;
1303
- }
1304
- }
1305
- };
1306
- function get(around) {
1307
- return typeof around === 'string' ? directionData[exports.Direction9[around]] : around;
1308
- }
1309
-
1310
- const { toPoint: toPoint$1 } = AroundHelper;
1311
- const AlignHelper = {
1312
- toPoint(align, contentBounds, bounds, to, onlySize) {
1313
- toPoint$1(align, bounds, to, onlySize, contentBounds);
1314
- }
1315
- };
1316
-
1317
1331
  const StringNumberMap = {
1318
1332
  '0': 1,
1319
1333
  '1': 1,
@@ -1444,11 +1458,17 @@ const Plugin = {
1444
1458
  return rs;
1445
1459
  },
1446
1460
  need(name) {
1447
- console.error('please install plugin: ' + (name.includes('-x') ? '' : '@leafer-in/') + name);
1461
+ console.error('please install and import plugin: ' + (name.includes('-x') ? '' : '@leafer-in/') + name);
1448
1462
  }
1449
1463
  };
1450
1464
  setTimeout(() => check.forEach(name => Plugin.has(name, true)));
1451
1465
 
1466
+ const Creator = {
1467
+ editor(_options) {
1468
+ return Plugin.need('editor');
1469
+ }
1470
+ };
1471
+
1452
1472
  const debug$9 = Debug.get('UICreator');
1453
1473
  const UICreator = {
1454
1474
  list: {},
@@ -1586,6 +1606,10 @@ const DataHelper = {
1586
1606
  for (let i = 0, len = list.length; i < len; i++)
1587
1607
  map[list[i]] = true;
1588
1608
  return map;
1609
+ },
1610
+ stintSet(data, attrName, value) {
1611
+ value || (value = undefined);
1612
+ data[attrName] !== value && (data[attrName] = value);
1589
1613
  }
1590
1614
  };
1591
1615
  const { assign } = DataHelper;
@@ -2409,6 +2433,8 @@ const BezierHelper = {
2409
2433
  cY = points[i + 3];
2410
2434
  ba = sqrt$1(pow(bX - aX, 2) + pow(bY - aY, 2));
2411
2435
  cb = sqrt$1(pow(cX - bX, 2) + pow(cY - bY, 2));
2436
+ if (!ba && !cb)
2437
+ continue;
2412
2438
  d = ba + cb;
2413
2439
  ba = (t * ba) / d;
2414
2440
  cb = (t * cb) / d;
@@ -2591,7 +2617,11 @@ const BezierHelper = {
2591
2617
  const point = {};
2592
2618
  getPointAndSet(t, fromX, fromY, x1, y1, x2, y2, toX, toY, point);
2593
2619
  return point;
2594
- }
2620
+ },
2621
+ getDerivative(t, fromV, v1, v2, toV) {
2622
+ const o = 1 - t;
2623
+ return 3 * o * o * (v1 - fromV) + 6 * o * t * (v2 - v1) + 3 * t * t * (toV - v2);
2624
+ },
2595
2625
  };
2596
2626
  const { getPointAndSet, toTwoPointBounds: toTwoPointBounds$1, ellipse: ellipse$5 } = BezierHelper;
2597
2627
 
@@ -3384,7 +3414,7 @@ function canvasPatch(drawer) {
3384
3414
  }
3385
3415
 
3386
3416
  const FileHelper = {
3387
- opacityTypes: ['png', 'webp', 'svg'],
3417
+ alphaPixelTypes: ['png', 'webp', 'svg'],
3388
3418
  upperCaseTypeMap: {},
3389
3419
  mineType(type) {
3390
3420
  if (!type || type.startsWith('image'))
@@ -3411,7 +3441,7 @@ const FileHelper = {
3411
3441
  }
3412
3442
  };
3413
3443
  const F = FileHelper;
3414
- F.opacityTypes.forEach(type => F.upperCaseTypeMap[type] = type.toUpperCase());
3444
+ F.alphaPixelTypes.forEach(type => F.upperCaseTypeMap[type] = type.toUpperCase());
3415
3445
 
3416
3446
  const debug$4 = Debug.get('TaskProcessor');
3417
3447
  class TaskItem {
@@ -3728,8 +3758,8 @@ const ImageManager = {
3728
3758
  list.length = 0;
3729
3759
  }
3730
3760
  },
3731
- hasOpacityPixel(config) {
3732
- return FileHelper.opacityTypes.some(item => I.isFormat(item, config));
3761
+ hasAlphaPixel(config) {
3762
+ return FileHelper.alphaPixelTypes.some(item => I.isFormat(item, config));
3733
3763
  },
3734
3764
  isFormat(format, config) {
3735
3765
  if (config.format === format)
@@ -3767,13 +3797,16 @@ class LeaferImage {
3767
3797
  this.setView(view.config ? view.view : view);
3768
3798
  }
3769
3799
  ImageManager.isFormat('svg', config) && (this.isSVG = true);
3770
- ImageManager.hasOpacityPixel(config) && (this.hasOpacityPixel = true);
3800
+ ImageManager.hasAlphaPixel(config) && (this.hasAlphaPixel = true);
3771
3801
  }
3772
3802
  load(onSuccess, onError) {
3773
3803
  if (!this.loading) {
3774
3804
  this.loading = true;
3805
+ let { loadImage, loadImageWithProgress } = Platform.origin, onProgress = this.config.showProgress && loadImageWithProgress && this.onProgress.bind(this);
3806
+ if (onProgress)
3807
+ loadImage = loadImageWithProgress;
3775
3808
  Resource.tasker.add(() => __awaiter(this, void 0, void 0, function* () {
3776
- return yield Platform.origin.loadImage(this.url).then(img => this.setView(img)).catch((e) => {
3809
+ return yield loadImage(this.url, onProgress).then(img => this.setView(img)).catch((e) => {
3777
3810
  this.error = e;
3778
3811
  this.onComplete(false);
3779
3812
  });
@@ -3798,6 +3831,9 @@ class LeaferImage {
3798
3831
  this.view = img;
3799
3832
  this.onComplete(true);
3800
3833
  }
3834
+ onProgress(progress) {
3835
+ this.progress = progress;
3836
+ }
3801
3837
  onComplete(isSuccess) {
3802
3838
  let odd;
3803
3839
  this.waitComplete.forEach((item, index) => {
@@ -4267,9 +4303,16 @@ const LeafHelper = {
4267
4303
  }
4268
4304
  }
4269
4305
  },
4270
- updateAllChange(leaf) {
4271
- updateAllWorldOpacity(leaf);
4306
+ updateChange(leaf) {
4307
+ const layout = leaf.__layout;
4308
+ if (layout.stateStyleChanged)
4309
+ leaf.updateState();
4310
+ if (layout.opacityChanged)
4311
+ updateAllWorldOpacity(leaf);
4272
4312
  leaf.__updateChange();
4313
+ },
4314
+ updateAllChange(leaf) {
4315
+ updateChange(leaf);
4273
4316
  if (leaf.isBranch) {
4274
4317
  const { children } = leaf;
4275
4318
  for (let i = 0, len = children.length; i < len; i++) {
@@ -4405,7 +4448,7 @@ const LeafHelper = {
4405
4448
  }
4406
4449
  };
4407
4450
  const L = LeafHelper;
4408
- const { updateAllMatrix: updateAllMatrix$1, updateMatrix: updateMatrix$1, updateAllWorldOpacity, updateAllChange } = L;
4451
+ const { updateAllMatrix: updateAllMatrix$1, updateMatrix: updateMatrix$1, updateAllWorldOpacity, updateAllChange, updateChange } = L;
4409
4452
  function getTempLocal(t, world) {
4410
4453
  t.__layout.update();
4411
4454
  return t.parent ? PointHelper.tempToInnerOf(world, t.parent.__world) : world;
@@ -4442,7 +4485,7 @@ const LeafBoundsHelper = {
4442
4485
  }
4443
4486
  };
4444
4487
 
4445
- const { updateBounds: updateBounds$1 } = LeafHelper;
4488
+ const { updateBounds: updateBounds$2 } = LeafHelper;
4446
4489
  const BranchHelper = {
4447
4490
  sort(a, b) {
4448
4491
  return (a.__.zIndex === b.__.zIndex) ? (a.__tempNumber - b.__tempNumber) : (a.__.zIndex - b.__.zIndex);
@@ -4504,11 +4547,11 @@ const BranchHelper = {
4504
4547
  branch = branchStack[i];
4505
4548
  children = branch.children;
4506
4549
  for (let j = 0, len = children.length; j < len; j++) {
4507
- updateBounds$1(children[j]);
4550
+ updateBounds$2(children[j]);
4508
4551
  }
4509
4552
  if (exclude && exclude === branch)
4510
4553
  continue;
4511
- updateBounds$1(branch);
4554
+ updateBounds$2(branch);
4512
4555
  }
4513
4556
  }
4514
4557
  };
@@ -4526,7 +4569,7 @@ const WaitHelper = {
4526
4569
  }
4527
4570
  };
4528
4571
 
4529
- const { getRelativeWorld: getRelativeWorld$1 } = LeafHelper;
4572
+ const { getRelativeWorld: getRelativeWorld$1, updateBounds: updateBounds$1 } = LeafHelper;
4530
4573
  const { toOuterOf: toOuterOf$2, getPoints, copy: copy$2 } = BoundsHelper;
4531
4574
  const localContent = '_localContentBounds';
4532
4575
  const worldContent = '_worldContentBounds', worldBox = '_worldBoxBounds', worldStroke = '_worldStrokeBounds';
@@ -4570,7 +4613,9 @@ class LeafLayout {
4570
4613
  this._localRenderBounds = local;
4571
4614
  }
4572
4615
  update() {
4573
- const { leafer } = this.leaf;
4616
+ const { leaf } = this, { leafer } = leaf;
4617
+ if (leaf.isApp)
4618
+ return updateBounds$1(leaf);
4574
4619
  if (leafer) {
4575
4620
  if (leafer.ready)
4576
4621
  leafer.watcher.changed && leafer.layouter.layout();
@@ -4578,7 +4623,7 @@ class LeafLayout {
4578
4623
  leafer.start();
4579
4624
  }
4580
4625
  else {
4581
- let root = this.leaf;
4626
+ let root = leaf;
4582
4627
  while (root.parent && !root.parent.leafer) {
4583
4628
  root = root.parent;
4584
4629
  }
@@ -4800,7 +4845,7 @@ class LeafLayout {
4800
4845
  }
4801
4846
  childrenSortChange() {
4802
4847
  if (!this.childrenSortChanged) {
4803
- this.childrenSortChanged = true;
4848
+ this.childrenSortChanged = this.affectChildrenSort = true;
4804
4849
  this.leaf.forceUpdate('surface');
4805
4850
  }
4806
4851
  }
@@ -4867,6 +4912,40 @@ ImageEvent.LOAD = 'image.load';
4867
4912
  ImageEvent.LOADED = 'image.loaded';
4868
4913
  ImageEvent.ERROR = 'image.error';
4869
4914
 
4915
+ class BoundsEvent extends Event {
4916
+ static checkHas(leaf, type, mode) {
4917
+ if (mode === 'on') {
4918
+ type === WORLD ? leaf.__hasWorldEvent = true : leaf.__hasLocalEvent = true;
4919
+ }
4920
+ else {
4921
+ leaf.__hasLocalEvent = leaf.hasEvent(RESIZE) || leaf.hasEvent(INNER) || leaf.hasEvent(LOCAL);
4922
+ leaf.__hasWorldEvent = leaf.hasEvent(WORLD);
4923
+ }
4924
+ }
4925
+ static emitLocal(leaf) {
4926
+ if (leaf.leaferIsReady) {
4927
+ const { resized } = leaf.__layout;
4928
+ if (resized !== 'local') {
4929
+ leaf.emit(RESIZE, leaf);
4930
+ if (resized === 'inner')
4931
+ leaf.emit(INNER, leaf);
4932
+ }
4933
+ leaf.emit(LOCAL, leaf);
4934
+ }
4935
+ }
4936
+ static emitWorld(leaf) {
4937
+ if (leaf.leaferIsReady)
4938
+ leaf.emit(WORLD, this);
4939
+ }
4940
+ }
4941
+ BoundsEvent.RESIZE = 'bounds.resize';
4942
+ BoundsEvent.INNER = 'bounds.inner';
4943
+ BoundsEvent.LOCAL = 'bounds.local';
4944
+ BoundsEvent.WORLD = 'bounds.world';
4945
+ const { RESIZE, INNER, LOCAL, WORLD } = BoundsEvent;
4946
+ const boundsEventMap = {};
4947
+ [RESIZE, INNER, LOCAL, WORLD].forEach(key => boundsEventMap[key] = 1);
4948
+
4870
4949
  class ResizeEvent extends Event {
4871
4950
  get bigger() {
4872
4951
  if (!this.old)
@@ -4963,9 +5042,12 @@ class Eventer {
4963
5042
  set event(map) { this.on(map); }
4964
5043
  on(type, listener, options) {
4965
5044
  if (!listener) {
4966
- let event, map = type;
4967
- for (let key in map)
4968
- event = map[key], event instanceof Array ? this.on(key, event[0], event[1]) : this.on(key, event);
5045
+ let event;
5046
+ if (type instanceof Array)
5047
+ type.forEach(item => this.on(item[0], item[1], item[2]));
5048
+ else
5049
+ for (let key in type)
5050
+ (event = type[key]) instanceof Array ? this.on(key, event[0], event[1]) : this.on(key, event);
4969
5051
  return;
4970
5052
  }
4971
5053
  let capture, once;
@@ -4995,6 +5077,8 @@ class Eventer {
4995
5077
  else {
4996
5078
  map[type] = [item];
4997
5079
  }
5080
+ if (boundsEventMap[type])
5081
+ BoundsEvent.checkHas(this, type, 'on');
4998
5082
  }
4999
5083
  });
5000
5084
  }
@@ -5016,6 +5100,8 @@ class Eventer {
5016
5100
  events.splice(index, 1);
5017
5101
  if (!events.length)
5018
5102
  delete map[type];
5103
+ if (boundsEventMap[type])
5104
+ BoundsEvent.checkHas(this, type, 'off');
5019
5105
  }
5020
5106
  }
5021
5107
  });
@@ -5035,19 +5121,31 @@ class Eventer {
5035
5121
  }
5036
5122
  }
5037
5123
  on_(type, listener, bind, options) {
5038
- if (bind)
5039
- listener = listener.bind(bind);
5040
- this.on(type, listener, options);
5124
+ if (!listener)
5125
+ (type instanceof Array) && type.forEach(item => this.on(item[0], item[2] ? item[1] = item[1].bind(item[2]) : item[1], item[3]));
5126
+ else
5127
+ this.on(type, bind ? listener = listener.bind(bind) : listener, options);
5041
5128
  return { type, current: this, listener, options };
5042
5129
  }
5043
5130
  off_(id) {
5044
5131
  if (!id)
5045
5132
  return;
5046
5133
  const list = id instanceof Array ? id : [id];
5047
- list.forEach(item => item.current.off(item.type, item.listener, item.options));
5134
+ list.forEach(item => {
5135
+ if (!item.listener)
5136
+ (item.type instanceof Array) && item.type.forEach(v => item.current.off(v[0], v[1], v[3]));
5137
+ else
5138
+ item.current.off(item.type, item.listener, item.options);
5139
+ });
5048
5140
  list.length = 0;
5049
5141
  }
5050
- once(type, listener, capture) {
5142
+ once(type, listener, captureOrBind, capture) {
5143
+ if (!listener)
5144
+ return (type instanceof Array) && type.forEach(item => this.once(item[0], item[1], item[2], item[3]));
5145
+ if (typeof captureOrBind === 'object')
5146
+ listener = listener.bind(captureOrBind);
5147
+ else
5148
+ capture = captureOrBind;
5051
5149
  this.on(type, listener, { once: true, capture });
5052
5150
  }
5053
5151
  emit(type, event, capture) {
@@ -5168,9 +5266,9 @@ const LeafMatrix = {
5168
5266
  if (this.__local) {
5169
5267
  const layout = this.__layout, local = this.__local, data = this.__;
5170
5268
  if (layout.affectScaleOrRotation) {
5171
- if (layout.scaleChanged || layout.rotationChanged) {
5269
+ if ((layout.scaleChanged && (layout.resized = 'scale')) || layout.rotationChanged) {
5172
5270
  setLayout(local, data, null, null, layout.affectRotation);
5173
- layout.scaleChanged = layout.rotationChanged = false;
5271
+ layout.scaleChanged = layout.rotationChanged = undefined;
5174
5272
  }
5175
5273
  }
5176
5274
  local.e = data.x + data.offsetX;
@@ -5180,7 +5278,7 @@ const LeafMatrix = {
5180
5278
  translateInner(local, -tempPoint.x, -tempPoint.y, !data.around);
5181
5279
  }
5182
5280
  }
5183
- this.__layout.matrixChanged = false;
5281
+ this.__layout.matrixChanged = undefined;
5184
5282
  }
5185
5283
  };
5186
5284
 
@@ -5190,11 +5288,17 @@ const { toOuterOf: toOuterOf$1, copyAndSpread, copy: copy$1 } = BoundsHelper;
5190
5288
  const { toBounds } = PathBounds;
5191
5289
  const LeafBounds = {
5192
5290
  __updateWorldBounds() {
5193
- toOuterOf$1(this.__layout.renderBounds, this.__world, this.__world);
5194
- if (this.__layout.resized) {
5195
- this.__onUpdateSize();
5196
- this.__layout.resized = false;
5291
+ const layout = this.__layout;
5292
+ toOuterOf$1(layout.renderBounds, this.__world, this.__world);
5293
+ if (layout.resized) {
5294
+ if (layout.resized === 'inner')
5295
+ this.__onUpdateSize();
5296
+ if (this.__hasLocalEvent)
5297
+ BoundsEvent.emitLocal(this);
5298
+ layout.resized = undefined;
5197
5299
  }
5300
+ if (this.__hasWorldEvent)
5301
+ BoundsEvent.emitWorld(this);
5198
5302
  },
5199
5303
  __updateLocalBounds() {
5200
5304
  const layout = this.__layout;
@@ -5203,12 +5307,12 @@ const LeafBounds = {
5203
5307
  this.__updatePath();
5204
5308
  this.__updateRenderPath();
5205
5309
  this.__updateBoxBounds();
5206
- layout.resized = true;
5310
+ layout.resized = 'inner';
5207
5311
  }
5208
5312
  if (layout.localBoxChanged) {
5209
5313
  if (this.__local)
5210
5314
  this.__updateLocalBoxBounds();
5211
- layout.localBoxChanged = false;
5315
+ layout.localBoxChanged = undefined;
5212
5316
  if (layout.strokeSpread)
5213
5317
  layout.strokeChanged = true;
5214
5318
  if (layout.renderSpread)
@@ -5216,7 +5320,7 @@ const LeafBounds = {
5216
5320
  if (this.parent)
5217
5321
  this.parent.__layout.boxChange();
5218
5322
  }
5219
- layout.boxChanged = false;
5323
+ layout.boxChanged = undefined;
5220
5324
  if (layout.strokeChanged) {
5221
5325
  layout.strokeSpread = this.__updateStrokeSpread();
5222
5326
  if (layout.strokeSpread) {
@@ -5228,12 +5332,12 @@ const LeafBounds = {
5228
5332
  else {
5229
5333
  layout.spreadStrokeCancel();
5230
5334
  }
5231
- layout.strokeChanged = false;
5335
+ layout.strokeChanged = undefined;
5232
5336
  if (layout.renderSpread || layout.strokeSpread !== layout.strokeBoxSpread)
5233
5337
  layout.renderChanged = true;
5234
5338
  if (this.parent)
5235
5339
  this.parent.__layout.strokeChange();
5236
- layout.resized = true;
5340
+ layout.resized = 'inner';
5237
5341
  }
5238
5342
  if (layout.renderChanged) {
5239
5343
  layout.renderSpread = this.__updateRenderSpread();
@@ -5246,11 +5350,12 @@ const LeafBounds = {
5246
5350
  else {
5247
5351
  layout.spreadRenderCancel();
5248
5352
  }
5249
- layout.renderChanged = false;
5353
+ layout.renderChanged = undefined;
5250
5354
  if (this.parent)
5251
5355
  this.parent.__layout.renderChange();
5252
5356
  }
5253
- layout.boundsChanged = false;
5357
+ layout.resized || (layout.resized = 'local');
5358
+ layout.boundsChanged = undefined;
5254
5359
  },
5255
5360
  __updateLocalBoxBounds() {
5256
5361
  if (this.__hasMotionPath)
@@ -5790,7 +5895,7 @@ exports.Leaf = class Leaf {
5790
5895
  off(_type, _listener, _options) { }
5791
5896
  on_(_type, _listener, _bind, _options) { return undefined; }
5792
5897
  off_(_id) { }
5793
- once(_type, _listener, _capture) { }
5898
+ once(_type, _listener, _captureOrBind, _capture) { }
5794
5899
  emit(_type, _event, _capture) { }
5795
5900
  emitEvent(_event, _capture) { }
5796
5901
  hasEvent(_type, _capture) { return false; }
@@ -6127,13 +6232,14 @@ class LeafLevelList {
6127
6232
  }
6128
6233
  }
6129
6234
 
6130
- const version = "1.6.1";
6235
+ const version = "1.6.3";
6131
6236
 
6132
6237
  exports.AlignHelper = AlignHelper;
6133
6238
  exports.AroundHelper = AroundHelper;
6134
6239
  exports.AutoBounds = AutoBounds;
6135
6240
  exports.BezierHelper = BezierHelper;
6136
6241
  exports.Bounds = Bounds;
6242
+ exports.BoundsEvent = BoundsEvent;
6137
6243
  exports.BoundsHelper = BoundsHelper;
6138
6244
  exports.BranchHelper = BranchHelper;
6139
6245
  exports.BranchRender = BranchRender;
@@ -6247,4 +6353,3 @@ exports.tempPoint = tempPoint$2;
6247
6353
  exports.useModule = useModule;
6248
6354
  exports.version = version;
6249
6355
  exports.visibleType = visibleType;
6250
- //# sourceMappingURL=core.cjs.map