@leafer/core 2.0.2 → 2.0.4

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
@@ -206,6 +206,7 @@ class LeafData {
206
206
  }
207
207
  destroy() {
208
208
  this.__input = this.__middle = null;
209
+ if (this.__complexData) this.__complexData.destroy();
209
210
  }
210
211
  }
211
212
 
@@ -304,6 +305,8 @@ const {set: set$1, get: get$1, setTemp: setTemp, toTempAB: toTempAB} = FourNumbe
304
305
 
305
306
  const {round: round$3, pow: pow$1, max: max$1, floor: floor$2, PI: PI$1} = Math;
306
307
 
308
+ const tempScaleData = {};
309
+
307
310
  const MathHelper = {
308
311
  within(value, min, max) {
309
312
  if (isObject(min)) max = min.max, min = min.min;
@@ -347,6 +350,24 @@ const MathHelper = {
347
350
  } else if (scale) MathHelper.assignScale(scaleData, scale);
348
351
  return scaleData;
349
352
  },
353
+ getScaleFixedData(worldScaleData, scaleFixed, unscale, abs, _localScaleData) {
354
+ let {scaleX: scaleX, scaleY: scaleY} = worldScaleData;
355
+ if (abs || scaleFixed) scaleX < 0 && (scaleX = -scaleX), scaleY < 0 && (scaleY = -scaleY);
356
+ if (scaleFixed) {
357
+ if (scaleFixed === true) {
358
+ scaleX = scaleY = unscale ? 1 : 1 / scaleX;
359
+ } else {
360
+ let minScale;
361
+ if (isNumber(scaleFixed)) minScale = scaleFixed; else if (scaleFixed === "zoom-in") minScale = 1;
362
+ if (minScale) {
363
+ if (scaleX > minScale || scaleY > minScale) scaleX = scaleY = unscale ? 1 : 1 / scaleX; else scaleX = scaleY = unscale ? 1 : 1 / minScale;
364
+ }
365
+ }
366
+ }
367
+ tempScaleData.scaleX = scaleX;
368
+ tempScaleData.scaleY = scaleY;
369
+ return tempScaleData;
370
+ },
350
371
  assignScale(scaleData, scale) {
351
372
  if (isNumber(scale)) {
352
373
  scaleData.scaleX = scaleData.scaleY = scale;
@@ -843,8 +864,8 @@ const PointHelper = {
843
864
  if (isObject(originPoints[0])) points = [], originPoints.forEach(p => points.push(p.x, p.y));
844
865
  return points;
845
866
  },
846
- isSame(t, point) {
847
- return float$1(t.x) === float$1(point.x) && float$1(t.y) === float$1(point.y);
867
+ isSame(t, point, quick) {
868
+ return quick ? t.x === point.x && t.y === point.y : float$1(t.x) === float$1(point.x) && float$1(t.y) === float$1(point.y);
848
869
  },
849
870
  reset(t) {
850
871
  P$5.reset(t);
@@ -919,8 +940,8 @@ class Point {
919
940
  getAtan2(to) {
920
941
  return PointHelper.getAtan2(this, to);
921
942
  }
922
- isSame(point) {
923
- return PointHelper.isSame(this, point);
943
+ isSame(point, quick) {
944
+ return PointHelper.isSame(this, point, quick);
924
945
  }
925
946
  reset() {
926
947
  PointHelper.reset(this);
@@ -1176,9 +1197,9 @@ const AroundHelper = {
1176
1197
  }
1177
1198
  if (!onlyBoxSize) to.x += box.x, to.y += box.y;
1178
1199
  },
1179
- getPoint(around, box, to) {
1200
+ getPoint(around, box, to, onlyBoxSize = true) {
1180
1201
  if (!to) to = {};
1181
- AroundHelper.toPoint(around, box, to, true);
1202
+ AroundHelper.toPoint(around, box, to, onlyBoxSize);
1182
1203
  return to;
1183
1204
  }
1184
1205
  };
@@ -1445,6 +1466,9 @@ const BoundsHelper = {
1445
1466
  y: y + height
1446
1467
  } ];
1447
1468
  },
1469
+ getPoint(t, around, onlyBoxSize = false, to) {
1470
+ return AroundHelper.getPoint(around, t, to, onlyBoxSize);
1471
+ },
1448
1472
  hitRadiusPoint(t, point, pointMatrix) {
1449
1473
  if (pointMatrix) point = PointHelper.tempToInnerRadiusPointOf(point, pointMatrix);
1450
1474
  return point.x >= t.x - point.radiusX && point.x <= t.x + t.width + point.radiusX && (point.y >= t.y - point.radiusY && point.y <= t.y + t.height + point.radiusY);
@@ -1616,6 +1640,9 @@ class Bounds {
1616
1640
  getPoints() {
1617
1641
  return BoundsHelper.getPoints(this);
1618
1642
  }
1643
+ getPoint(around, onlyBoxSize, to) {
1644
+ return BoundsHelper.getPoint(this, around, onlyBoxSize, to);
1645
+ }
1619
1646
  hitPoint(point, pointMatrix) {
1620
1647
  return BoundsHelper.hitPoint(this, point, pointMatrix);
1621
1648
  }
@@ -4095,6 +4122,7 @@ const ImageManager = {
4095
4122
  return image;
4096
4123
  },
4097
4124
  recycle(image) {
4125
+ if (image.parent) image = image.parent;
4098
4126
  image.use--;
4099
4127
  setTimeout(() => {
4100
4128
  if (!image.use) {
@@ -4263,8 +4291,10 @@ class LeaferImage {
4263
4291
  return undefined;
4264
4292
  }
4265
4293
  clearLevels(_checkUse) {}
4294
+ destroyFilter() {}
4266
4295
  destroy() {
4267
4296
  this.clearLevels();
4297
+ this.destroyFilter();
4268
4298
  const {view: view} = this;
4269
4299
  if (view && view.close) view.close();
4270
4300
  this.config = {
@@ -4461,7 +4491,6 @@ function dimType(defaultValue) {
4461
4491
  if (this.__setAttr(key, value)) {
4462
4492
  const data = this.__;
4463
4493
  DataHelper.stintSet(data, "__useDim", data.dim || data.bright || data.dimskip);
4464
- this.__layout.surfaceChange();
4465
4494
  }
4466
4495
  }
4467
4496
  }));
@@ -4511,7 +4540,6 @@ function sortType(defaultValue) {
4511
4540
  return decorateLeafAttr(defaultValue, key => attr({
4512
4541
  set(value) {
4513
4542
  if (this.__setAttr(key, value)) {
4514
- this.__layout.surfaceChange();
4515
4543
  this.waitParent(() => {
4516
4544
  this.parent.__layout.childrenSortChange();
4517
4545
  });
@@ -4548,7 +4576,6 @@ function hitType(defaultValue) {
4548
4576
  set(value) {
4549
4577
  if (this.__setAttr(key, value)) {
4550
4578
  this.__layout.hitCanvasChanged = true;
4551
- if (Debug.showBounds === "hit") this.__layout.surfaceChange();
4552
4579
  if (this.leafer) this.leafer.updateCursor();
4553
4580
  }
4554
4581
  }
@@ -4754,6 +4781,10 @@ const LeafHelper = {
4754
4781
  if (layout.stateStyleChanged) leaf.updateState();
4755
4782
  if (layout.opacityChanged) updateAllWorldOpacity(leaf);
4756
4783
  leaf.__updateChange();
4784
+ if (layout.surfaceChanged) {
4785
+ if (leaf.__hasComplex) L.updateComplex(leaf);
4786
+ layout.surfaceChanged = false;
4787
+ }
4757
4788
  },
4758
4789
  updateAllChange(leaf) {
4759
4790
  updateChange(leaf);
@@ -4778,6 +4809,9 @@ const LeafHelper = {
4778
4809
  if (!fromWorld) fromWorld = leaf.__nowWorld;
4779
4810
  if (leaf.__worldFlipped || Platform.fullImageShadow) currentCanvas.copyWorldByReset(fromCanvas, fromWorld, leaf.__nowWorld, blendMode, onlyResetTransform); else currentCanvas.copyWorldToInner(fromCanvas, fromWorld, leaf.__layout.renderBounds, blendMode);
4780
4811
  },
4812
+ renderComplex(_leaf, _canvas, _options) {},
4813
+ updateComplex(_leaf) {},
4814
+ checkComplex(_leaf) {},
4781
4815
  moveWorld(t, x, y = 0, isInnerPoint, transition) {
4782
4816
  const local = isObject(x) ? Object.assign({}, x) : {
4783
4817
  x: x,
@@ -4889,6 +4923,9 @@ const LeafHelper = {
4889
4923
  divideParent(matrix, relative.scrollWorldTransform);
4890
4924
  return temp ? matrix : Object.assign({}, matrix);
4891
4925
  },
4926
+ updateScaleFixedWorld(_t) {},
4927
+ updateOuterBounds(_t) {},
4928
+ cacheId(_t) {},
4892
4929
  drop(t, parent, index, resize) {
4893
4930
  t.setTransform(L.getRelativeWorld(t, parent, true), resize);
4894
4931
  parent.add(t, index);
@@ -4939,7 +4976,8 @@ const LeafBoundsHelper = {
4939
4976
  return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localStrokeBounds;
4940
4977
  },
4941
4978
  localRenderBounds(target) {
4942
- return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localRenderBounds;
4979
+ const {__: __, __layout: __layout} = target;
4980
+ return __.eraser || __.visible === 0 ? null : __layout.localOuterBounds || __layout.localRenderBounds;
4943
4981
  },
4944
4982
  maskLocalBoxBounds(target, index) {
4945
4983
  return checkMask(target, index) && target.__localBoxBounds;
@@ -4948,7 +4986,8 @@ const LeafBoundsHelper = {
4948
4986
  return checkMask(target, index) && target.__layout.localStrokeBounds;
4949
4987
  },
4950
4988
  maskLocalRenderBounds(target, index) {
4951
- return checkMask(target, index) && target.__layout.localRenderBounds;
4989
+ const {__layout: __layout} = target;
4990
+ return checkMask(target, index) && (__layout.localOuterBounds || __layout.localRenderBounds);
4952
4991
  },
4953
4992
  excludeRenderBounds(child, options) {
4954
4993
  if (options.bounds && !options.bounds.hit(child.__world, options.matrix)) return true;
@@ -5468,7 +5507,6 @@ class LeafLayout {
5468
5507
  }
5469
5508
  opacityChange() {
5470
5509
  this.opacityChanged = true;
5471
- this.surfaceChanged || this.surfaceChange();
5472
5510
  }
5473
5511
  childrenSortChange() {
5474
5512
  if (!this.childrenSortChanged) {
@@ -5575,7 +5613,7 @@ class BoundsEvent extends Event {
5575
5613
  }
5576
5614
  }
5577
5615
  static emitWorld(leaf) {
5578
- if (leaf.leaferIsReady) leaf.emit(WORLD, this);
5616
+ if (leaf.leaferIsReady) leaf.emit(WORLD, leaf);
5579
5617
  }
5580
5618
  }
5581
5619
 
@@ -5961,6 +5999,7 @@ const LeafMatrix = {
5961
5999
  const {parent: parent, __layout: __layout, __world: __world, __scrollWorld: __scrollWorld, __: __} = this;
5962
6000
  multiplyParent$1(this.__local || __layout, parent ? parent.__scrollWorld || parent.__world : defaultWorld, __world, !!__layout.affectScaleOrRotation, __);
5963
6001
  if (__scrollWorld) translateInner(Object.assign(__scrollWorld, __world), __.scrollX, __.scrollY);
6002
+ if (__layout.scaleFixed) LeafHelper.updateScaleFixedWorld(this);
5964
6003
  },
5965
6004
  __updateLocalMatrix() {
5966
6005
  if (this.__local) {
@@ -5994,6 +6033,7 @@ const LeafBounds = {
5994
6033
  __updateWorldBounds() {
5995
6034
  const {__layout: __layout, __world: __world} = this;
5996
6035
  toOuterOf$1(__layout.renderBounds, __world, __world);
6036
+ if (this.__hasComplex) LeafHelper.checkComplex(this);
5997
6037
  if (__layout.resized) {
5998
6038
  if (__layout.resized === "inner") this.__onUpdateSize();
5999
6039
  if (this.__hasLocalEvent) BoundsEvent.emitLocal(this);
@@ -6043,6 +6083,7 @@ const LeafBounds = {
6043
6083
  layout.renderChanged = undefined;
6044
6084
  if (this.parent) this.parent.__layout.renderChange();
6045
6085
  }
6086
+ if (layout.outerScale) LeafHelper.updateOuterBounds(this);
6046
6087
  layout.resized || (layout.resized = "local");
6047
6088
  layout.boundsChanged = undefined;
6048
6089
  },
@@ -6109,7 +6150,7 @@ const LeafRender = {
6109
6150
  const data = this.__;
6110
6151
  if (data.bright && !options.topRendering) return options.topList.add(this);
6111
6152
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
6112
- canvas.opacity = options.dimOpacity && !data.dimskip ? data.opacity * options.dimOpacity : data.opacity;
6153
+ canvas.opacity = options.ignoreOpacity ? 1 : options.dimOpacity && !data.dimskip ? data.opacity * options.dimOpacity : data.opacity;
6113
6154
  if (this.__.__single) {
6114
6155
  if (data.eraser === "path") return this.__renderEraser(canvas, options);
6115
6156
  const tempCanvas = canvas.getSameCanvas(true, true);
@@ -6163,7 +6204,7 @@ const BranchRender = {
6163
6204
  if (data.eraser === "path") return this.__renderEraser(canvas, options);
6164
6205
  const tempCanvas = canvas.getSameCanvas(false, true);
6165
6206
  this.__renderBranch(tempCanvas, options);
6166
- canvas.opacity = options.dimOpacity ? data.opacity * options.dimOpacity : data.opacity;
6207
+ canvas.opacity = options.ignoreOpacity ? 1 : options.dimOpacity ? data.opacity * options.dimOpacity : data.opacity;
6167
6208
  canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, data.__blendMode, true);
6168
6209
  tempCanvas.recycle(nowWorld);
6169
6210
  } else {
@@ -6179,7 +6220,7 @@ const BranchRender = {
6179
6220
  const {children: children} = this;
6180
6221
  for (let i = 0, len = children.length; i < len; i++) {
6181
6222
  child = children[i];
6182
- excludeRenderBounds(child, options) || (child.__.complex ? child.__renderComplex(canvas, options) : child.__render(canvas, options));
6223
+ excludeRenderBounds(child, options) || (child.__hasComplex ? LeafHelper.renderComplex(child, canvas, options) : child.__render(canvas, options));
6183
6224
  }
6184
6225
  }
6185
6226
  },
@@ -6193,8 +6234,6 @@ const BranchRender = {
6193
6234
  }
6194
6235
  };
6195
6236
 
6196
- const tempScaleData = {};
6197
-
6198
6237
  const {LEAF: LEAF, create: create} = IncrementId;
6199
6238
 
6200
6239
  const {stintSet: stintSet} = DataHelper;
@@ -6205,6 +6244,8 @@ const {toOuterOf: toOuterOf} = BoundsHelper;
6205
6244
 
6206
6245
  const {copy: copy, move: move} = PointHelper;
6207
6246
 
6247
+ const {getScaleFixedData: getScaleFixedData} = MathHelper;
6248
+
6208
6249
  const {moveLocal: moveLocal, zoomOfLocal: zoomOfLocal, rotateOfLocal: rotateOfLocal, skewOfLocal: skewOfLocal, moveWorld: moveWorld, zoomOfWorld: zoomOfWorld, rotateOfWorld: rotateOfWorld, skewOfWorld: skewOfWorld, transform: transform, transformWorld: transformWorld, setTransform: setTransform, getFlipTransform: getFlipTransform, getLocalOrigin: getLocalOrigin, getRelativeWorld: getRelativeWorld, drop: drop} = LeafHelper;
6209
6250
 
6210
6251
  exports.Leaf = class Leaf {
@@ -6363,6 +6404,7 @@ exports.Leaf = class Leaf {
6363
6404
  this.__level = this.parent ? this.parent.__level + 1 : 1;
6364
6405
  if (this.animation) this.__runAnimation("in");
6365
6406
  if (this.__bubbleMap) this.__emitLifeEvent(ChildEvent.MOUNTED);
6407
+ if (leafer.cacheId) LeafHelper.cacheId(this);
6366
6408
  } else {
6367
6409
  this.__emitLifeEvent(ChildEvent.UNMOUNTED);
6368
6410
  }
@@ -6492,13 +6534,8 @@ exports.Leaf = class Leaf {
6492
6534
  if (scaleX < 0) scaleX = -scaleX;
6493
6535
  return scaleX > 1 ? scaleX : 1;
6494
6536
  }
6495
- getRenderScaleData(abs, scaleFixed) {
6496
- let {scaleX: scaleX, scaleY: scaleY} = ImageManager.patternLocked ? this.__world : this.__nowWorld;
6497
- if (abs) scaleX < 0 && (scaleX = -scaleX), scaleY < 0 && (scaleY = -scaleY);
6498
- if (scaleFixed === true || scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) scaleX = scaleY = 1;
6499
- tempScaleData.scaleX = scaleX;
6500
- tempScaleData.scaleY = scaleY;
6501
- return tempScaleData;
6537
+ getRenderScaleData(abs, scaleFixed, unscale = true) {
6538
+ return getScaleFixedData(ImageManager.patternLocked ? this.__world : this.__nowWorld || this.__world, scaleFixed, unscale, abs);
6502
6539
  }
6503
6540
  getTransform(relative) {
6504
6541
  return this.__layout.getTransform(relative || "local");
@@ -6537,14 +6574,16 @@ exports.Leaf = class Leaf {
6537
6574
  relative.innerToWorld(world, to, distance);
6538
6575
  world = to ? to : world;
6539
6576
  }
6540
- toInnerPoint(this.scrollWorldTransform, world, to, distance);
6577
+ toInnerPoint(this.worldTransform, world, to, distance);
6541
6578
  }
6542
6579
  innerToWorld(inner, to, distance, relative) {
6543
- toOuterPoint(this.scrollWorldTransform, inner, to, distance);
6580
+ toOuterPoint(this.worldTransform, inner, to, distance);
6544
6581
  if (relative) relative.worldToInner(to ? to : inner, null, distance);
6545
6582
  }
6546
6583
  getBoxPoint(world, relative, distance, change) {
6547
- return this.getBoxPointByInner(this.getInnerPoint(world, relative, distance, change), null, null, true);
6584
+ const inner = this.getInnerPoint(world, relative, distance, change);
6585
+ if (distance) return inner;
6586
+ return this.getBoxPointByInner(inner, null, null, true);
6548
6587
  }
6549
6588
  getBoxPointByInner(inner, _relative, _distance, change) {
6550
6589
  const point = change ? inner : Object.assign({}, inner), {x: x, y: y} = this.boxBounds;
@@ -6660,7 +6699,6 @@ exports.Leaf = class Leaf {
6660
6699
  __drawHitPath(_canvas) {}
6661
6700
  __updateHitCanvas() {}
6662
6701
  __render(_canvas, _options) {}
6663
- __renderComplex(_canvas, _options) {}
6664
6702
  __drawFast(_canvas, _options) {}
6665
6703
  __draw(_canvas, _options, _originCanvas) {}
6666
6704
  __clip(_canvas, _options) {}
@@ -6671,7 +6709,7 @@ exports.Leaf = class Leaf {
6671
6709
  __drawPath(_canvas) {}
6672
6710
  __drawRenderPath(_canvas) {}
6673
6711
  __updatePath() {}
6674
- __updateRenderPath() {}
6712
+ __updateRenderPath(_updateCache) {}
6675
6713
  getMotionPathData() {
6676
6714
  return Plugin.need("path");
6677
6715
  }
@@ -6745,9 +6783,11 @@ exports.Branch = class Branch extends exports.Leaf {
6745
6783
  return 0;
6746
6784
  }
6747
6785
  __updateRenderSpread() {
6786
+ let layout;
6748
6787
  const {children: children} = this;
6749
6788
  for (let i = 0, len = children.length; i < len; i++) {
6750
- if (children[i].__layout.renderSpread) return 1;
6789
+ layout = children[i].__layout;
6790
+ if (layout.renderSpread || layout.localOuterBounds) return 1;
6751
6791
  }
6752
6792
  return 0;
6753
6793
  }
@@ -7006,7 +7046,7 @@ class LeafLevelList {
7006
7046
  }
7007
7047
  }
7008
7048
 
7009
- const version = "2.0.2";
7049
+ const version = "2.0.4";
7010
7050
 
7011
7051
  exports.AlignHelper = AlignHelper;
7012
7052