@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.esm.js CHANGED
@@ -23,8 +23,6 @@ const Platform = {
23
23
  }
24
24
  };
25
25
 
26
- const Creator = {};
27
-
28
26
  const IncrementId = {
29
27
  RUNTIME: 'runtime',
30
28
  LEAF: 'leaf',
@@ -464,8 +462,10 @@ const PointHelper = {
464
462
  t.y = halfPixel ? round$2(t.y - 0.5) + 0.5 : round$2(t.y);
465
463
  },
466
464
  move(t, x, y) {
467
- t.x += x;
468
- t.y += y;
465
+ if (typeof x === 'object')
466
+ t.x += x.x, t.y += x.y;
467
+ else
468
+ t.x += x, t.y += y;
469
469
  },
470
470
  scale(t, scaleX, scaleY = scaleX) {
471
471
  if (t.x)
@@ -801,15 +801,87 @@ const TwoPointBoundsHelper = {
801
801
  };
802
802
  const { addPoint: addPoint$3 } = TwoPointBoundsHelper;
803
803
 
804
+ var Direction4;
805
+ (function (Direction4) {
806
+ Direction4[Direction4["top"] = 0] = "top";
807
+ Direction4[Direction4["right"] = 1] = "right";
808
+ Direction4[Direction4["bottom"] = 2] = "bottom";
809
+ Direction4[Direction4["left"] = 3] = "left";
810
+ })(Direction4 || (Direction4 = {}));
811
+ var Direction9;
812
+ (function (Direction9) {
813
+ Direction9[Direction9["topLeft"] = 0] = "topLeft";
814
+ Direction9[Direction9["top"] = 1] = "top";
815
+ Direction9[Direction9["topRight"] = 2] = "topRight";
816
+ Direction9[Direction9["right"] = 3] = "right";
817
+ Direction9[Direction9["bottomRight"] = 4] = "bottomRight";
818
+ Direction9[Direction9["bottom"] = 5] = "bottom";
819
+ Direction9[Direction9["bottomLeft"] = 6] = "bottomLeft";
820
+ Direction9[Direction9["left"] = 7] = "left";
821
+ Direction9[Direction9["center"] = 8] = "center";
822
+ Direction9[Direction9["top-left"] = 0] = "top-left";
823
+ Direction9[Direction9["top-right"] = 2] = "top-right";
824
+ Direction9[Direction9["bottom-right"] = 4] = "bottom-right";
825
+ Direction9[Direction9["bottom-left"] = 6] = "bottom-left";
826
+ })(Direction9 || (Direction9 = {}));
827
+
828
+ const directionData = [
829
+ { x: 0, y: 0 },
830
+ { x: 0.5, y: 0 },
831
+ { x: 1, y: 0 },
832
+ { x: 1, y: 0.5 },
833
+ { x: 1, y: 1 },
834
+ { x: 0.5, y: 1 },
835
+ { x: 0, y: 1 },
836
+ { x: 0, y: 0.5 },
837
+ { x: 0.5, y: 0.5 }
838
+ ];
839
+ directionData.forEach(item => item.type = 'percent');
840
+ const AroundHelper = {
841
+ directionData,
842
+ tempPoint: {},
843
+ get,
844
+ toPoint(around, box, to, onlyBoxSize, content, onlyContentSize) {
845
+ const point = get(around);
846
+ to.x = point.x;
847
+ to.y = point.y;
848
+ if (point.type === 'percent') {
849
+ to.x *= box.width;
850
+ to.y *= box.height;
851
+ if (content) {
852
+ if (!onlyContentSize)
853
+ to.x -= content.x, to.y -= content.y;
854
+ if (point.x)
855
+ to.x -= (point.x === 1) ? content.width : (point.x === 0.5 ? point.x * content.width : 0);
856
+ if (point.y)
857
+ to.y -= (point.y === 1) ? content.height : (point.y === 0.5 ? point.y * content.height : 0);
858
+ }
859
+ }
860
+ if (!onlyBoxSize)
861
+ to.x += box.x, to.y += box.y;
862
+ }
863
+ };
864
+ function get(around) {
865
+ return typeof around === 'string' ? directionData[Direction9[around]] : around;
866
+ }
867
+
868
+ const { toPoint: toPoint$2 } = AroundHelper;
869
+ const AlignHelper = {
870
+ toPoint(align, content, box, to, onlyBoxSize, onlyContentSize) {
871
+ toPoint$2(align, box, to, onlyBoxSize, content, onlyContentSize);
872
+ }
873
+ };
874
+
804
875
  const { tempPointBounds: tempPointBounds$1, setPoint: setPoint$2, addPoint: addPoint$2, toBounds: toBounds$2 } = TwoPointBoundsHelper;
805
876
  const { toOuterPoint: toOuterPoint$2 } = MatrixHelper;
806
877
  const { float, fourNumber } = MathHelper;
807
878
  const { floor, ceil: ceil$1 } = Math;
808
879
  let right, bottom, boundsRight, boundsBottom;
809
880
  const point = {};
810
- const toPoint$2 = {};
881
+ const toPoint$1 = {};
882
+ const tempBounds$1 = {};
811
883
  const BoundsHelper = {
812
- tempBounds: {},
884
+ tempBounds: tempBounds$1,
813
885
  set(t, x = 0, y = 0, width = 0, height = 0) {
814
886
  t.x = x;
815
887
  t.y = y;
@@ -872,8 +944,8 @@ const BoundsHelper = {
872
944
  }
873
945
  B.move(to, -to.offsetX, -to.offsetY);
874
946
  },
875
- scale(t, scaleX, scaleY = scaleX) {
876
- PointHelper.scale(t, scaleX, scaleY);
947
+ scale(t, scaleX, scaleY = scaleX, onlySize) {
948
+ onlySize || PointHelper.scale(t, scaleX, scaleY);
877
949
  t.width *= scaleX;
878
950
  t.height *= scaleY;
879
951
  },
@@ -883,9 +955,9 @@ const BoundsHelper = {
883
955
  t.height *= scaleY;
884
956
  },
885
957
  tempToOuterOf(t, matrix) {
886
- B.copy(B.tempBounds, t);
887
- B.toOuterOf(B.tempBounds, matrix);
888
- return B.tempBounds;
958
+ B.copy(tempBounds$1, t);
959
+ B.toOuterOf(tempBounds$1, matrix);
960
+ return tempBounds$1;
889
961
  },
890
962
  getOuterOf(t, matrix) {
891
963
  t = Object.assign({}, t);
@@ -916,17 +988,17 @@ const BoundsHelper = {
916
988
  else {
917
989
  point.x = t.x;
918
990
  point.y = t.y;
919
- toOuterPoint$2(matrix, point, toPoint$2);
920
- setPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
991
+ toOuterPoint$2(matrix, point, toPoint$1);
992
+ setPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
921
993
  point.x = t.x + t.width;
922
- toOuterPoint$2(matrix, point, toPoint$2);
923
- addPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
994
+ toOuterPoint$2(matrix, point, toPoint$1);
995
+ addPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
924
996
  point.y = t.y + t.height;
925
- toOuterPoint$2(matrix, point, toPoint$2);
926
- addPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
997
+ toOuterPoint$2(matrix, point, toPoint$1);
998
+ addPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
927
999
  point.x = t.x;
928
- toOuterPoint$2(matrix, point, toPoint$2);
929
- addPoint$2(tempPointBounds$1, toPoint$2.x, toPoint$2.y);
1000
+ toOuterPoint$2(matrix, point, toPoint$1);
1001
+ addPoint$2(tempPointBounds$1, toPoint$1.x, toPoint$1.y);
930
1002
  toBounds$2(tempPointBounds$1, to);
931
1003
  }
932
1004
  },
@@ -936,9 +1008,21 @@ const BoundsHelper = {
936
1008
  B.scale(to, 1 / matrix.a, 1 / matrix.d);
937
1009
  },
938
1010
  getFitMatrix(t, put, baseScale = 1) {
939
- const scale = Math.min(baseScale, Math.min(t.width / put.width, t.height / put.height));
1011
+ const scale = Math.min(baseScale, B.getFitScale(t, put));
940
1012
  return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
941
1013
  },
1014
+ getFitScale(t, put, isCoverMode) {
1015
+ const sw = t.width / put.width, sh = t.height / put.height;
1016
+ return isCoverMode ? Math.max(sw, sh) : Math.min(sw, sh);
1017
+ },
1018
+ put(t, put, align = 'center', putScale = 1, changeSize = true, to) {
1019
+ to || (to = put);
1020
+ if (typeof putScale === 'string')
1021
+ putScale = B.getFitScale(t, put, putScale === 'cover');
1022
+ tempBounds$1.width = changeSize ? put.width *= putScale : put.width * putScale;
1023
+ tempBounds$1.height = changeSize ? put.height *= putScale : put.height * putScale;
1024
+ AlignHelper.toPoint(align, tempBounds$1, t, to, true, true);
1025
+ },
942
1026
  getSpread(t, spread, side) {
943
1027
  const n = {};
944
1028
  B.copyAndSpread(n, t, spread, false, side);
@@ -1112,8 +1196,8 @@ class Bounds {
1112
1196
  BoundsHelper.move(this, x, y);
1113
1197
  return this;
1114
1198
  }
1115
- scale(scaleX, scaleY) {
1116
- BoundsHelper.scale(this, scaleX, scaleY);
1199
+ scale(scaleX, scaleY, onlySize) {
1200
+ BoundsHelper.scale(this, scaleX, scaleY, onlySize);
1117
1201
  return this;
1118
1202
  }
1119
1203
  scaleOf(origin, scaleX, scaleY) {
@@ -1131,6 +1215,9 @@ class Bounds {
1131
1215
  getFitMatrix(put, baseScale) {
1132
1216
  return BoundsHelper.getFitMatrix(this, put, baseScale);
1133
1217
  }
1218
+ put(put, align, putScale) {
1219
+ BoundsHelper.put(this, put, align, putScale);
1220
+ }
1134
1221
  spread(fourNumber, side) {
1135
1222
  BoundsHelper.spread(this, fourNumber, side);
1136
1223
  return this;
@@ -1239,79 +1326,6 @@ class AutoBounds {
1239
1326
  }
1240
1327
  }
1241
1328
 
1242
- var Direction4;
1243
- (function (Direction4) {
1244
- Direction4[Direction4["top"] = 0] = "top";
1245
- Direction4[Direction4["right"] = 1] = "right";
1246
- Direction4[Direction4["bottom"] = 2] = "bottom";
1247
- Direction4[Direction4["left"] = 3] = "left";
1248
- })(Direction4 || (Direction4 = {}));
1249
- var Direction9;
1250
- (function (Direction9) {
1251
- Direction9[Direction9["topLeft"] = 0] = "topLeft";
1252
- Direction9[Direction9["top"] = 1] = "top";
1253
- Direction9[Direction9["topRight"] = 2] = "topRight";
1254
- Direction9[Direction9["right"] = 3] = "right";
1255
- Direction9[Direction9["bottomRight"] = 4] = "bottomRight";
1256
- Direction9[Direction9["bottom"] = 5] = "bottom";
1257
- Direction9[Direction9["bottomLeft"] = 6] = "bottomLeft";
1258
- Direction9[Direction9["left"] = 7] = "left";
1259
- Direction9[Direction9["center"] = 8] = "center";
1260
- Direction9[Direction9["top-left"] = 0] = "top-left";
1261
- Direction9[Direction9["top-right"] = 2] = "top-right";
1262
- Direction9[Direction9["bottom-right"] = 4] = "bottom-right";
1263
- Direction9[Direction9["bottom-left"] = 6] = "bottom-left";
1264
- })(Direction9 || (Direction9 = {}));
1265
-
1266
- const directionData = [
1267
- { x: 0, y: 0 },
1268
- { x: 0.5, y: 0 },
1269
- { x: 1, y: 0 },
1270
- { x: 1, y: 0.5 },
1271
- { x: 1, y: 1 },
1272
- { x: 0.5, y: 1 },
1273
- { x: 0, y: 1 },
1274
- { x: 0, y: 0.5 },
1275
- { x: 0.5, y: 0.5 }
1276
- ];
1277
- directionData.forEach(item => item.type = 'percent');
1278
- const AroundHelper = {
1279
- directionData,
1280
- tempPoint: {},
1281
- get,
1282
- toPoint(around, bounds, to, onlySize, pointBounds) {
1283
- const point = get(around);
1284
- to.x = point.x;
1285
- to.y = point.y;
1286
- if (point.type === 'percent') {
1287
- to.x *= bounds.width;
1288
- to.y *= bounds.height;
1289
- if (pointBounds) {
1290
- to.x -= pointBounds.x;
1291
- to.y -= pointBounds.y;
1292
- if (point.x)
1293
- to.x -= (point.x === 1) ? pointBounds.width : (point.x === 0.5 ? point.x * pointBounds.width : 0);
1294
- if (point.y)
1295
- to.y -= (point.y === 1) ? pointBounds.height : (point.y === 0.5 ? point.y * pointBounds.height : 0);
1296
- }
1297
- }
1298
- if (!onlySize) {
1299
- to.x += bounds.x;
1300
- to.y += bounds.y;
1301
- }
1302
- }
1303
- };
1304
- function get(around) {
1305
- return typeof around === 'string' ? directionData[Direction9[around]] : around;
1306
- }
1307
-
1308
- const { toPoint: toPoint$1 } = AroundHelper;
1309
- const AlignHelper = {
1310
- toPoint(align, contentBounds, bounds, to, onlySize) {
1311
- toPoint$1(align, bounds, to, onlySize, contentBounds);
1312
- }
1313
- };
1314
-
1315
1329
  const StringNumberMap = {
1316
1330
  '0': 1,
1317
1331
  '1': 1,
@@ -1442,11 +1456,17 @@ const Plugin = {
1442
1456
  return rs;
1443
1457
  },
1444
1458
  need(name) {
1445
- console.error('please install plugin: ' + (name.includes('-x') ? '' : '@leafer-in/') + name);
1459
+ console.error('please install and import plugin: ' + (name.includes('-x') ? '' : '@leafer-in/') + name);
1446
1460
  }
1447
1461
  };
1448
1462
  setTimeout(() => check.forEach(name => Plugin.has(name, true)));
1449
1463
 
1464
+ const Creator = {
1465
+ editor(_options) {
1466
+ return Plugin.need('editor');
1467
+ }
1468
+ };
1469
+
1450
1470
  const debug$9 = Debug.get('UICreator');
1451
1471
  const UICreator = {
1452
1472
  list: {},
@@ -1584,6 +1604,10 @@ const DataHelper = {
1584
1604
  for (let i = 0, len = list.length; i < len; i++)
1585
1605
  map[list[i]] = true;
1586
1606
  return map;
1607
+ },
1608
+ stintSet(data, attrName, value) {
1609
+ value || (value = undefined);
1610
+ data[attrName] !== value && (data[attrName] = value);
1587
1611
  }
1588
1612
  };
1589
1613
  const { assign } = DataHelper;
@@ -2407,6 +2431,8 @@ const BezierHelper = {
2407
2431
  cY = points[i + 3];
2408
2432
  ba = sqrt$1(pow(bX - aX, 2) + pow(bY - aY, 2));
2409
2433
  cb = sqrt$1(pow(cX - bX, 2) + pow(cY - bY, 2));
2434
+ if (!ba && !cb)
2435
+ continue;
2410
2436
  d = ba + cb;
2411
2437
  ba = (t * ba) / d;
2412
2438
  cb = (t * cb) / d;
@@ -2589,7 +2615,11 @@ const BezierHelper = {
2589
2615
  const point = {};
2590
2616
  getPointAndSet(t, fromX, fromY, x1, y1, x2, y2, toX, toY, point);
2591
2617
  return point;
2592
- }
2618
+ },
2619
+ getDerivative(t, fromV, v1, v2, toV) {
2620
+ const o = 1 - t;
2621
+ return 3 * o * o * (v1 - fromV) + 6 * o * t * (v2 - v1) + 3 * t * t * (toV - v2);
2622
+ },
2593
2623
  };
2594
2624
  const { getPointAndSet, toTwoPointBounds: toTwoPointBounds$1, ellipse: ellipse$5 } = BezierHelper;
2595
2625
 
@@ -3382,7 +3412,7 @@ function canvasPatch(drawer) {
3382
3412
  }
3383
3413
 
3384
3414
  const FileHelper = {
3385
- opacityTypes: ['png', 'webp', 'svg'],
3415
+ alphaPixelTypes: ['png', 'webp', 'svg'],
3386
3416
  upperCaseTypeMap: {},
3387
3417
  mineType(type) {
3388
3418
  if (!type || type.startsWith('image'))
@@ -3409,7 +3439,7 @@ const FileHelper = {
3409
3439
  }
3410
3440
  };
3411
3441
  const F = FileHelper;
3412
- F.opacityTypes.forEach(type => F.upperCaseTypeMap[type] = type.toUpperCase());
3442
+ F.alphaPixelTypes.forEach(type => F.upperCaseTypeMap[type] = type.toUpperCase());
3413
3443
 
3414
3444
  const debug$4 = Debug.get('TaskProcessor');
3415
3445
  class TaskItem {
@@ -3726,8 +3756,8 @@ const ImageManager = {
3726
3756
  list.length = 0;
3727
3757
  }
3728
3758
  },
3729
- hasOpacityPixel(config) {
3730
- return FileHelper.opacityTypes.some(item => I.isFormat(item, config));
3759
+ hasAlphaPixel(config) {
3760
+ return FileHelper.alphaPixelTypes.some(item => I.isFormat(item, config));
3731
3761
  },
3732
3762
  isFormat(format, config) {
3733
3763
  if (config.format === format)
@@ -3765,13 +3795,16 @@ class LeaferImage {
3765
3795
  this.setView(view.config ? view.view : view);
3766
3796
  }
3767
3797
  ImageManager.isFormat('svg', config) && (this.isSVG = true);
3768
- ImageManager.hasOpacityPixel(config) && (this.hasOpacityPixel = true);
3798
+ ImageManager.hasAlphaPixel(config) && (this.hasAlphaPixel = true);
3769
3799
  }
3770
3800
  load(onSuccess, onError) {
3771
3801
  if (!this.loading) {
3772
3802
  this.loading = true;
3803
+ let { loadImage, loadImageWithProgress } = Platform.origin, onProgress = this.config.showProgress && loadImageWithProgress && this.onProgress.bind(this);
3804
+ if (onProgress)
3805
+ loadImage = loadImageWithProgress;
3773
3806
  Resource.tasker.add(() => __awaiter(this, void 0, void 0, function* () {
3774
- return yield Platform.origin.loadImage(this.url).then(img => this.setView(img)).catch((e) => {
3807
+ return yield loadImage(this.url, onProgress).then(img => this.setView(img)).catch((e) => {
3775
3808
  this.error = e;
3776
3809
  this.onComplete(false);
3777
3810
  });
@@ -3796,6 +3829,9 @@ class LeaferImage {
3796
3829
  this.view = img;
3797
3830
  this.onComplete(true);
3798
3831
  }
3832
+ onProgress(progress) {
3833
+ this.progress = progress;
3834
+ }
3799
3835
  onComplete(isSuccess) {
3800
3836
  let odd;
3801
3837
  this.waitComplete.forEach((item, index) => {
@@ -4265,9 +4301,16 @@ const LeafHelper = {
4265
4301
  }
4266
4302
  }
4267
4303
  },
4268
- updateAllChange(leaf) {
4269
- updateAllWorldOpacity(leaf);
4304
+ updateChange(leaf) {
4305
+ const layout = leaf.__layout;
4306
+ if (layout.stateStyleChanged)
4307
+ leaf.updateState();
4308
+ if (layout.opacityChanged)
4309
+ updateAllWorldOpacity(leaf);
4270
4310
  leaf.__updateChange();
4311
+ },
4312
+ updateAllChange(leaf) {
4313
+ updateChange(leaf);
4271
4314
  if (leaf.isBranch) {
4272
4315
  const { children } = leaf;
4273
4316
  for (let i = 0, len = children.length; i < len; i++) {
@@ -4403,7 +4446,7 @@ const LeafHelper = {
4403
4446
  }
4404
4447
  };
4405
4448
  const L = LeafHelper;
4406
- const { updateAllMatrix: updateAllMatrix$1, updateMatrix: updateMatrix$1, updateAllWorldOpacity, updateAllChange } = L;
4449
+ const { updateAllMatrix: updateAllMatrix$1, updateMatrix: updateMatrix$1, updateAllWorldOpacity, updateAllChange, updateChange } = L;
4407
4450
  function getTempLocal(t, world) {
4408
4451
  t.__layout.update();
4409
4452
  return t.parent ? PointHelper.tempToInnerOf(world, t.parent.__world) : world;
@@ -4440,7 +4483,7 @@ const LeafBoundsHelper = {
4440
4483
  }
4441
4484
  };
4442
4485
 
4443
- const { updateBounds: updateBounds$1 } = LeafHelper;
4486
+ const { updateBounds: updateBounds$2 } = LeafHelper;
4444
4487
  const BranchHelper = {
4445
4488
  sort(a, b) {
4446
4489
  return (a.__.zIndex === b.__.zIndex) ? (a.__tempNumber - b.__tempNumber) : (a.__.zIndex - b.__.zIndex);
@@ -4502,11 +4545,11 @@ const BranchHelper = {
4502
4545
  branch = branchStack[i];
4503
4546
  children = branch.children;
4504
4547
  for (let j = 0, len = children.length; j < len; j++) {
4505
- updateBounds$1(children[j]);
4548
+ updateBounds$2(children[j]);
4506
4549
  }
4507
4550
  if (exclude && exclude === branch)
4508
4551
  continue;
4509
- updateBounds$1(branch);
4552
+ updateBounds$2(branch);
4510
4553
  }
4511
4554
  }
4512
4555
  };
@@ -4524,7 +4567,7 @@ const WaitHelper = {
4524
4567
  }
4525
4568
  };
4526
4569
 
4527
- const { getRelativeWorld: getRelativeWorld$1 } = LeafHelper;
4570
+ const { getRelativeWorld: getRelativeWorld$1, updateBounds: updateBounds$1 } = LeafHelper;
4528
4571
  const { toOuterOf: toOuterOf$2, getPoints, copy: copy$2 } = BoundsHelper;
4529
4572
  const localContent = '_localContentBounds';
4530
4573
  const worldContent = '_worldContentBounds', worldBox = '_worldBoxBounds', worldStroke = '_worldStrokeBounds';
@@ -4568,7 +4611,9 @@ class LeafLayout {
4568
4611
  this._localRenderBounds = local;
4569
4612
  }
4570
4613
  update() {
4571
- const { leafer } = this.leaf;
4614
+ const { leaf } = this, { leafer } = leaf;
4615
+ if (leaf.isApp)
4616
+ return updateBounds$1(leaf);
4572
4617
  if (leafer) {
4573
4618
  if (leafer.ready)
4574
4619
  leafer.watcher.changed && leafer.layouter.layout();
@@ -4576,7 +4621,7 @@ class LeafLayout {
4576
4621
  leafer.start();
4577
4622
  }
4578
4623
  else {
4579
- let root = this.leaf;
4624
+ let root = leaf;
4580
4625
  while (root.parent && !root.parent.leafer) {
4581
4626
  root = root.parent;
4582
4627
  }
@@ -4798,7 +4843,7 @@ class LeafLayout {
4798
4843
  }
4799
4844
  childrenSortChange() {
4800
4845
  if (!this.childrenSortChanged) {
4801
- this.childrenSortChanged = true;
4846
+ this.childrenSortChanged = this.affectChildrenSort = true;
4802
4847
  this.leaf.forceUpdate('surface');
4803
4848
  }
4804
4849
  }
@@ -4865,6 +4910,40 @@ ImageEvent.LOAD = 'image.load';
4865
4910
  ImageEvent.LOADED = 'image.loaded';
4866
4911
  ImageEvent.ERROR = 'image.error';
4867
4912
 
4913
+ class BoundsEvent extends Event {
4914
+ static checkHas(leaf, type, mode) {
4915
+ if (mode === 'on') {
4916
+ type === WORLD ? leaf.__hasWorldEvent = true : leaf.__hasLocalEvent = true;
4917
+ }
4918
+ else {
4919
+ leaf.__hasLocalEvent = leaf.hasEvent(RESIZE) || leaf.hasEvent(INNER) || leaf.hasEvent(LOCAL);
4920
+ leaf.__hasWorldEvent = leaf.hasEvent(WORLD);
4921
+ }
4922
+ }
4923
+ static emitLocal(leaf) {
4924
+ if (leaf.leaferIsReady) {
4925
+ const { resized } = leaf.__layout;
4926
+ if (resized !== 'local') {
4927
+ leaf.emit(RESIZE, leaf);
4928
+ if (resized === 'inner')
4929
+ leaf.emit(INNER, leaf);
4930
+ }
4931
+ leaf.emit(LOCAL, leaf);
4932
+ }
4933
+ }
4934
+ static emitWorld(leaf) {
4935
+ if (leaf.leaferIsReady)
4936
+ leaf.emit(WORLD, this);
4937
+ }
4938
+ }
4939
+ BoundsEvent.RESIZE = 'bounds.resize';
4940
+ BoundsEvent.INNER = 'bounds.inner';
4941
+ BoundsEvent.LOCAL = 'bounds.local';
4942
+ BoundsEvent.WORLD = 'bounds.world';
4943
+ const { RESIZE, INNER, LOCAL, WORLD } = BoundsEvent;
4944
+ const boundsEventMap = {};
4945
+ [RESIZE, INNER, LOCAL, WORLD].forEach(key => boundsEventMap[key] = 1);
4946
+
4868
4947
  class ResizeEvent extends Event {
4869
4948
  get bigger() {
4870
4949
  if (!this.old)
@@ -4961,9 +5040,12 @@ class Eventer {
4961
5040
  set event(map) { this.on(map); }
4962
5041
  on(type, listener, options) {
4963
5042
  if (!listener) {
4964
- let event, map = type;
4965
- for (let key in map)
4966
- event = map[key], event instanceof Array ? this.on(key, event[0], event[1]) : this.on(key, event);
5043
+ let event;
5044
+ if (type instanceof Array)
5045
+ type.forEach(item => this.on(item[0], item[1], item[2]));
5046
+ else
5047
+ for (let key in type)
5048
+ (event = type[key]) instanceof Array ? this.on(key, event[0], event[1]) : this.on(key, event);
4967
5049
  return;
4968
5050
  }
4969
5051
  let capture, once;
@@ -4993,6 +5075,8 @@ class Eventer {
4993
5075
  else {
4994
5076
  map[type] = [item];
4995
5077
  }
5078
+ if (boundsEventMap[type])
5079
+ BoundsEvent.checkHas(this, type, 'on');
4996
5080
  }
4997
5081
  });
4998
5082
  }
@@ -5014,6 +5098,8 @@ class Eventer {
5014
5098
  events.splice(index, 1);
5015
5099
  if (!events.length)
5016
5100
  delete map[type];
5101
+ if (boundsEventMap[type])
5102
+ BoundsEvent.checkHas(this, type, 'off');
5017
5103
  }
5018
5104
  }
5019
5105
  });
@@ -5033,19 +5119,31 @@ class Eventer {
5033
5119
  }
5034
5120
  }
5035
5121
  on_(type, listener, bind, options) {
5036
- if (bind)
5037
- listener = listener.bind(bind);
5038
- this.on(type, listener, options);
5122
+ if (!listener)
5123
+ (type instanceof Array) && type.forEach(item => this.on(item[0], item[2] ? item[1] = item[1].bind(item[2]) : item[1], item[3]));
5124
+ else
5125
+ this.on(type, bind ? listener = listener.bind(bind) : listener, options);
5039
5126
  return { type, current: this, listener, options };
5040
5127
  }
5041
5128
  off_(id) {
5042
5129
  if (!id)
5043
5130
  return;
5044
5131
  const list = id instanceof Array ? id : [id];
5045
- list.forEach(item => item.current.off(item.type, item.listener, item.options));
5132
+ list.forEach(item => {
5133
+ if (!item.listener)
5134
+ (item.type instanceof Array) && item.type.forEach(v => item.current.off(v[0], v[1], v[3]));
5135
+ else
5136
+ item.current.off(item.type, item.listener, item.options);
5137
+ });
5046
5138
  list.length = 0;
5047
5139
  }
5048
- once(type, listener, capture) {
5140
+ once(type, listener, captureOrBind, capture) {
5141
+ if (!listener)
5142
+ return (type instanceof Array) && type.forEach(item => this.once(item[0], item[1], item[2], item[3]));
5143
+ if (typeof captureOrBind === 'object')
5144
+ listener = listener.bind(captureOrBind);
5145
+ else
5146
+ capture = captureOrBind;
5049
5147
  this.on(type, listener, { once: true, capture });
5050
5148
  }
5051
5149
  emit(type, event, capture) {
@@ -5166,9 +5264,9 @@ const LeafMatrix = {
5166
5264
  if (this.__local) {
5167
5265
  const layout = this.__layout, local = this.__local, data = this.__;
5168
5266
  if (layout.affectScaleOrRotation) {
5169
- if (layout.scaleChanged || layout.rotationChanged) {
5267
+ if ((layout.scaleChanged && (layout.resized = 'scale')) || layout.rotationChanged) {
5170
5268
  setLayout(local, data, null, null, layout.affectRotation);
5171
- layout.scaleChanged = layout.rotationChanged = false;
5269
+ layout.scaleChanged = layout.rotationChanged = undefined;
5172
5270
  }
5173
5271
  }
5174
5272
  local.e = data.x + data.offsetX;
@@ -5178,7 +5276,7 @@ const LeafMatrix = {
5178
5276
  translateInner(local, -tempPoint.x, -tempPoint.y, !data.around);
5179
5277
  }
5180
5278
  }
5181
- this.__layout.matrixChanged = false;
5279
+ this.__layout.matrixChanged = undefined;
5182
5280
  }
5183
5281
  };
5184
5282
 
@@ -5188,11 +5286,17 @@ const { toOuterOf: toOuterOf$1, copyAndSpread, copy: copy$1 } = BoundsHelper;
5188
5286
  const { toBounds } = PathBounds;
5189
5287
  const LeafBounds = {
5190
5288
  __updateWorldBounds() {
5191
- toOuterOf$1(this.__layout.renderBounds, this.__world, this.__world);
5192
- if (this.__layout.resized) {
5193
- this.__onUpdateSize();
5194
- this.__layout.resized = false;
5289
+ const layout = this.__layout;
5290
+ toOuterOf$1(layout.renderBounds, this.__world, this.__world);
5291
+ if (layout.resized) {
5292
+ if (layout.resized === 'inner')
5293
+ this.__onUpdateSize();
5294
+ if (this.__hasLocalEvent)
5295
+ BoundsEvent.emitLocal(this);
5296
+ layout.resized = undefined;
5195
5297
  }
5298
+ if (this.__hasWorldEvent)
5299
+ BoundsEvent.emitWorld(this);
5196
5300
  },
5197
5301
  __updateLocalBounds() {
5198
5302
  const layout = this.__layout;
@@ -5201,12 +5305,12 @@ const LeafBounds = {
5201
5305
  this.__updatePath();
5202
5306
  this.__updateRenderPath();
5203
5307
  this.__updateBoxBounds();
5204
- layout.resized = true;
5308
+ layout.resized = 'inner';
5205
5309
  }
5206
5310
  if (layout.localBoxChanged) {
5207
5311
  if (this.__local)
5208
5312
  this.__updateLocalBoxBounds();
5209
- layout.localBoxChanged = false;
5313
+ layout.localBoxChanged = undefined;
5210
5314
  if (layout.strokeSpread)
5211
5315
  layout.strokeChanged = true;
5212
5316
  if (layout.renderSpread)
@@ -5214,7 +5318,7 @@ const LeafBounds = {
5214
5318
  if (this.parent)
5215
5319
  this.parent.__layout.boxChange();
5216
5320
  }
5217
- layout.boxChanged = false;
5321
+ layout.boxChanged = undefined;
5218
5322
  if (layout.strokeChanged) {
5219
5323
  layout.strokeSpread = this.__updateStrokeSpread();
5220
5324
  if (layout.strokeSpread) {
@@ -5226,12 +5330,12 @@ const LeafBounds = {
5226
5330
  else {
5227
5331
  layout.spreadStrokeCancel();
5228
5332
  }
5229
- layout.strokeChanged = false;
5333
+ layout.strokeChanged = undefined;
5230
5334
  if (layout.renderSpread || layout.strokeSpread !== layout.strokeBoxSpread)
5231
5335
  layout.renderChanged = true;
5232
5336
  if (this.parent)
5233
5337
  this.parent.__layout.strokeChange();
5234
- layout.resized = true;
5338
+ layout.resized = 'inner';
5235
5339
  }
5236
5340
  if (layout.renderChanged) {
5237
5341
  layout.renderSpread = this.__updateRenderSpread();
@@ -5244,11 +5348,12 @@ const LeafBounds = {
5244
5348
  else {
5245
5349
  layout.spreadRenderCancel();
5246
5350
  }
5247
- layout.renderChanged = false;
5351
+ layout.renderChanged = undefined;
5248
5352
  if (this.parent)
5249
5353
  this.parent.__layout.renderChange();
5250
5354
  }
5251
- layout.boundsChanged = false;
5355
+ layout.resized || (layout.resized = 'local');
5356
+ layout.boundsChanged = undefined;
5252
5357
  },
5253
5358
  __updateLocalBoxBounds() {
5254
5359
  if (this.__hasMotionPath)
@@ -5788,7 +5893,7 @@ let Leaf = class Leaf {
5788
5893
  off(_type, _listener, _options) { }
5789
5894
  on_(_type, _listener, _bind, _options) { return undefined; }
5790
5895
  off_(_id) { }
5791
- once(_type, _listener, _capture) { }
5896
+ once(_type, _listener, _captureOrBind, _capture) { }
5792
5897
  emit(_type, _event, _capture) { }
5793
5898
  emitEvent(_event, _capture) { }
5794
5899
  hasEvent(_type, _capture) { return false; }
@@ -6125,7 +6230,6 @@ class LeafLevelList {
6125
6230
  }
6126
6231
  }
6127
6232
 
6128
- const version = "1.6.1";
6233
+ const version = "1.6.3";
6129
6234
 
6130
- export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, Eventer, 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, Plugin, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Resource, 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, isEmptyData, isNull, 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 };
6131
- //# sourceMappingURL=core.esm.js.map
6235
+ export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, Eventer, 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, Plugin, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Resource, 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, isEmptyData, isNull, 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 };