@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.esm.js CHANGED
@@ -204,6 +204,7 @@ class LeafData {
204
204
  }
205
205
  destroy() {
206
206
  this.__input = this.__middle = null;
207
+ if (this.__complexData) this.__complexData.destroy();
207
208
  }
208
209
  }
209
210
 
@@ -302,6 +303,8 @@ const {set: set$1, get: get$1, setTemp: setTemp, toTempAB: toTempAB} = FourNumbe
302
303
 
303
304
  const {round: round$3, pow: pow$1, max: max$1, floor: floor$2, PI: PI$1} = Math;
304
305
 
306
+ const tempScaleData = {};
307
+
305
308
  const MathHelper = {
306
309
  within(value, min, max) {
307
310
  if (isObject(min)) max = min.max, min = min.min;
@@ -345,6 +348,24 @@ const MathHelper = {
345
348
  } else if (scale) MathHelper.assignScale(scaleData, scale);
346
349
  return scaleData;
347
350
  },
351
+ getScaleFixedData(worldScaleData, scaleFixed, unscale, abs, _localScaleData) {
352
+ let {scaleX: scaleX, scaleY: scaleY} = worldScaleData;
353
+ if (abs || scaleFixed) scaleX < 0 && (scaleX = -scaleX), scaleY < 0 && (scaleY = -scaleY);
354
+ if (scaleFixed) {
355
+ if (scaleFixed === true) {
356
+ scaleX = scaleY = unscale ? 1 : 1 / scaleX;
357
+ } else {
358
+ let minScale;
359
+ if (isNumber(scaleFixed)) minScale = scaleFixed; else if (scaleFixed === "zoom-in") minScale = 1;
360
+ if (minScale) {
361
+ if (scaleX > minScale || scaleY > minScale) scaleX = scaleY = unscale ? 1 : 1 / scaleX; else scaleX = scaleY = unscale ? 1 : 1 / minScale;
362
+ }
363
+ }
364
+ }
365
+ tempScaleData.scaleX = scaleX;
366
+ tempScaleData.scaleY = scaleY;
367
+ return tempScaleData;
368
+ },
348
369
  assignScale(scaleData, scale) {
349
370
  if (isNumber(scale)) {
350
371
  scaleData.scaleX = scaleData.scaleY = scale;
@@ -841,8 +862,8 @@ const PointHelper = {
841
862
  if (isObject(originPoints[0])) points = [], originPoints.forEach(p => points.push(p.x, p.y));
842
863
  return points;
843
864
  },
844
- isSame(t, point) {
845
- return float$1(t.x) === float$1(point.x) && float$1(t.y) === float$1(point.y);
865
+ isSame(t, point, quick) {
866
+ 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);
846
867
  },
847
868
  reset(t) {
848
869
  P$5.reset(t);
@@ -917,8 +938,8 @@ class Point {
917
938
  getAtan2(to) {
918
939
  return PointHelper.getAtan2(this, to);
919
940
  }
920
- isSame(point) {
921
- return PointHelper.isSame(this, point);
941
+ isSame(point, quick) {
942
+ return PointHelper.isSame(this, point, quick);
922
943
  }
923
944
  reset() {
924
945
  PointHelper.reset(this);
@@ -1174,9 +1195,9 @@ const AroundHelper = {
1174
1195
  }
1175
1196
  if (!onlyBoxSize) to.x += box.x, to.y += box.y;
1176
1197
  },
1177
- getPoint(around, box, to) {
1198
+ getPoint(around, box, to, onlyBoxSize = true) {
1178
1199
  if (!to) to = {};
1179
- AroundHelper.toPoint(around, box, to, true);
1200
+ AroundHelper.toPoint(around, box, to, onlyBoxSize);
1180
1201
  return to;
1181
1202
  }
1182
1203
  };
@@ -1443,6 +1464,9 @@ const BoundsHelper = {
1443
1464
  y: y + height
1444
1465
  } ];
1445
1466
  },
1467
+ getPoint(t, around, onlyBoxSize = false, to) {
1468
+ return AroundHelper.getPoint(around, t, to, onlyBoxSize);
1469
+ },
1446
1470
  hitRadiusPoint(t, point, pointMatrix) {
1447
1471
  if (pointMatrix) point = PointHelper.tempToInnerRadiusPointOf(point, pointMatrix);
1448
1472
  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);
@@ -1614,6 +1638,9 @@ class Bounds {
1614
1638
  getPoints() {
1615
1639
  return BoundsHelper.getPoints(this);
1616
1640
  }
1641
+ getPoint(around, onlyBoxSize, to) {
1642
+ return BoundsHelper.getPoint(this, around, onlyBoxSize, to);
1643
+ }
1617
1644
  hitPoint(point, pointMatrix) {
1618
1645
  return BoundsHelper.hitPoint(this, point, pointMatrix);
1619
1646
  }
@@ -4093,6 +4120,7 @@ const ImageManager = {
4093
4120
  return image;
4094
4121
  },
4095
4122
  recycle(image) {
4123
+ if (image.parent) image = image.parent;
4096
4124
  image.use--;
4097
4125
  setTimeout(() => {
4098
4126
  if (!image.use) {
@@ -4261,8 +4289,10 @@ class LeaferImage {
4261
4289
  return undefined;
4262
4290
  }
4263
4291
  clearLevels(_checkUse) {}
4292
+ destroyFilter() {}
4264
4293
  destroy() {
4265
4294
  this.clearLevels();
4295
+ this.destroyFilter();
4266
4296
  const {view: view} = this;
4267
4297
  if (view && view.close) view.close();
4268
4298
  this.config = {
@@ -4459,7 +4489,6 @@ function dimType(defaultValue) {
4459
4489
  if (this.__setAttr(key, value)) {
4460
4490
  const data = this.__;
4461
4491
  DataHelper.stintSet(data, "__useDim", data.dim || data.bright || data.dimskip);
4462
- this.__layout.surfaceChange();
4463
4492
  }
4464
4493
  }
4465
4494
  }));
@@ -4509,7 +4538,6 @@ function sortType(defaultValue) {
4509
4538
  return decorateLeafAttr(defaultValue, key => attr({
4510
4539
  set(value) {
4511
4540
  if (this.__setAttr(key, value)) {
4512
- this.__layout.surfaceChange();
4513
4541
  this.waitParent(() => {
4514
4542
  this.parent.__layout.childrenSortChange();
4515
4543
  });
@@ -4546,7 +4574,6 @@ function hitType(defaultValue) {
4546
4574
  set(value) {
4547
4575
  if (this.__setAttr(key, value)) {
4548
4576
  this.__layout.hitCanvasChanged = true;
4549
- if (Debug.showBounds === "hit") this.__layout.surfaceChange();
4550
4577
  if (this.leafer) this.leafer.updateCursor();
4551
4578
  }
4552
4579
  }
@@ -4752,6 +4779,10 @@ const LeafHelper = {
4752
4779
  if (layout.stateStyleChanged) leaf.updateState();
4753
4780
  if (layout.opacityChanged) updateAllWorldOpacity(leaf);
4754
4781
  leaf.__updateChange();
4782
+ if (layout.surfaceChanged) {
4783
+ if (leaf.__hasComplex) L.updateComplex(leaf);
4784
+ layout.surfaceChanged = false;
4785
+ }
4755
4786
  },
4756
4787
  updateAllChange(leaf) {
4757
4788
  updateChange(leaf);
@@ -4776,6 +4807,9 @@ const LeafHelper = {
4776
4807
  if (!fromWorld) fromWorld = leaf.__nowWorld;
4777
4808
  if (leaf.__worldFlipped || Platform.fullImageShadow) currentCanvas.copyWorldByReset(fromCanvas, fromWorld, leaf.__nowWorld, blendMode, onlyResetTransform); else currentCanvas.copyWorldToInner(fromCanvas, fromWorld, leaf.__layout.renderBounds, blendMode);
4778
4809
  },
4810
+ renderComplex(_leaf, _canvas, _options) {},
4811
+ updateComplex(_leaf) {},
4812
+ checkComplex(_leaf) {},
4779
4813
  moveWorld(t, x, y = 0, isInnerPoint, transition) {
4780
4814
  const local = isObject(x) ? Object.assign({}, x) : {
4781
4815
  x: x,
@@ -4887,6 +4921,9 @@ const LeafHelper = {
4887
4921
  divideParent(matrix, relative.scrollWorldTransform);
4888
4922
  return temp ? matrix : Object.assign({}, matrix);
4889
4923
  },
4924
+ updateScaleFixedWorld(_t) {},
4925
+ updateOuterBounds(_t) {},
4926
+ cacheId(_t) {},
4890
4927
  drop(t, parent, index, resize) {
4891
4928
  t.setTransform(L.getRelativeWorld(t, parent, true), resize);
4892
4929
  parent.add(t, index);
@@ -4937,7 +4974,8 @@ const LeafBoundsHelper = {
4937
4974
  return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localStrokeBounds;
4938
4975
  },
4939
4976
  localRenderBounds(target) {
4940
- return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localRenderBounds;
4977
+ const {__: __, __layout: __layout} = target;
4978
+ return __.eraser || __.visible === 0 ? null : __layout.localOuterBounds || __layout.localRenderBounds;
4941
4979
  },
4942
4980
  maskLocalBoxBounds(target, index) {
4943
4981
  return checkMask(target, index) && target.__localBoxBounds;
@@ -4946,7 +4984,8 @@ const LeafBoundsHelper = {
4946
4984
  return checkMask(target, index) && target.__layout.localStrokeBounds;
4947
4985
  },
4948
4986
  maskLocalRenderBounds(target, index) {
4949
- return checkMask(target, index) && target.__layout.localRenderBounds;
4987
+ const {__layout: __layout} = target;
4988
+ return checkMask(target, index) && (__layout.localOuterBounds || __layout.localRenderBounds);
4950
4989
  },
4951
4990
  excludeRenderBounds(child, options) {
4952
4991
  if (options.bounds && !options.bounds.hit(child.__world, options.matrix)) return true;
@@ -5466,7 +5505,6 @@ class LeafLayout {
5466
5505
  }
5467
5506
  opacityChange() {
5468
5507
  this.opacityChanged = true;
5469
- this.surfaceChanged || this.surfaceChange();
5470
5508
  }
5471
5509
  childrenSortChange() {
5472
5510
  if (!this.childrenSortChanged) {
@@ -5573,7 +5611,7 @@ class BoundsEvent extends Event {
5573
5611
  }
5574
5612
  }
5575
5613
  static emitWorld(leaf) {
5576
- if (leaf.leaferIsReady) leaf.emit(WORLD, this);
5614
+ if (leaf.leaferIsReady) leaf.emit(WORLD, leaf);
5577
5615
  }
5578
5616
  }
5579
5617
 
@@ -5959,6 +5997,7 @@ const LeafMatrix = {
5959
5997
  const {parent: parent, __layout: __layout, __world: __world, __scrollWorld: __scrollWorld, __: __} = this;
5960
5998
  multiplyParent$1(this.__local || __layout, parent ? parent.__scrollWorld || parent.__world : defaultWorld, __world, !!__layout.affectScaleOrRotation, __);
5961
5999
  if (__scrollWorld) translateInner(Object.assign(__scrollWorld, __world), __.scrollX, __.scrollY);
6000
+ if (__layout.scaleFixed) LeafHelper.updateScaleFixedWorld(this);
5962
6001
  },
5963
6002
  __updateLocalMatrix() {
5964
6003
  if (this.__local) {
@@ -5992,6 +6031,7 @@ const LeafBounds = {
5992
6031
  __updateWorldBounds() {
5993
6032
  const {__layout: __layout, __world: __world} = this;
5994
6033
  toOuterOf$1(__layout.renderBounds, __world, __world);
6034
+ if (this.__hasComplex) LeafHelper.checkComplex(this);
5995
6035
  if (__layout.resized) {
5996
6036
  if (__layout.resized === "inner") this.__onUpdateSize();
5997
6037
  if (this.__hasLocalEvent) BoundsEvent.emitLocal(this);
@@ -6041,6 +6081,7 @@ const LeafBounds = {
6041
6081
  layout.renderChanged = undefined;
6042
6082
  if (this.parent) this.parent.__layout.renderChange();
6043
6083
  }
6084
+ if (layout.outerScale) LeafHelper.updateOuterBounds(this);
6044
6085
  layout.resized || (layout.resized = "local");
6045
6086
  layout.boundsChanged = undefined;
6046
6087
  },
@@ -6107,7 +6148,7 @@ const LeafRender = {
6107
6148
  const data = this.__;
6108
6149
  if (data.bright && !options.topRendering) return options.topList.add(this);
6109
6150
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
6110
- canvas.opacity = options.dimOpacity && !data.dimskip ? data.opacity * options.dimOpacity : data.opacity;
6151
+ canvas.opacity = options.ignoreOpacity ? 1 : options.dimOpacity && !data.dimskip ? data.opacity * options.dimOpacity : data.opacity;
6111
6152
  if (this.__.__single) {
6112
6153
  if (data.eraser === "path") return this.__renderEraser(canvas, options);
6113
6154
  const tempCanvas = canvas.getSameCanvas(true, true);
@@ -6161,7 +6202,7 @@ const BranchRender = {
6161
6202
  if (data.eraser === "path") return this.__renderEraser(canvas, options);
6162
6203
  const tempCanvas = canvas.getSameCanvas(false, true);
6163
6204
  this.__renderBranch(tempCanvas, options);
6164
- canvas.opacity = options.dimOpacity ? data.opacity * options.dimOpacity : data.opacity;
6205
+ canvas.opacity = options.ignoreOpacity ? 1 : options.dimOpacity ? data.opacity * options.dimOpacity : data.opacity;
6165
6206
  canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, data.__blendMode, true);
6166
6207
  tempCanvas.recycle(nowWorld);
6167
6208
  } else {
@@ -6177,7 +6218,7 @@ const BranchRender = {
6177
6218
  const {children: children} = this;
6178
6219
  for (let i = 0, len = children.length; i < len; i++) {
6179
6220
  child = children[i];
6180
- excludeRenderBounds(child, options) || (child.__.complex ? child.__renderComplex(canvas, options) : child.__render(canvas, options));
6221
+ excludeRenderBounds(child, options) || (child.__hasComplex ? LeafHelper.renderComplex(child, canvas, options) : child.__render(canvas, options));
6181
6222
  }
6182
6223
  }
6183
6224
  },
@@ -6191,8 +6232,6 @@ const BranchRender = {
6191
6232
  }
6192
6233
  };
6193
6234
 
6194
- const tempScaleData = {};
6195
-
6196
6235
  const {LEAF: LEAF, create: create} = IncrementId;
6197
6236
 
6198
6237
  const {stintSet: stintSet} = DataHelper;
@@ -6203,6 +6242,8 @@ const {toOuterOf: toOuterOf} = BoundsHelper;
6203
6242
 
6204
6243
  const {copy: copy, move: move} = PointHelper;
6205
6244
 
6245
+ const {getScaleFixedData: getScaleFixedData} = MathHelper;
6246
+
6206
6247
  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;
6207
6248
 
6208
6249
  let Leaf = class Leaf {
@@ -6361,6 +6402,7 @@ let Leaf = class Leaf {
6361
6402
  this.__level = this.parent ? this.parent.__level + 1 : 1;
6362
6403
  if (this.animation) this.__runAnimation("in");
6363
6404
  if (this.__bubbleMap) this.__emitLifeEvent(ChildEvent.MOUNTED);
6405
+ if (leafer.cacheId) LeafHelper.cacheId(this);
6364
6406
  } else {
6365
6407
  this.__emitLifeEvent(ChildEvent.UNMOUNTED);
6366
6408
  }
@@ -6490,13 +6532,8 @@ let Leaf = class Leaf {
6490
6532
  if (scaleX < 0) scaleX = -scaleX;
6491
6533
  return scaleX > 1 ? scaleX : 1;
6492
6534
  }
6493
- getRenderScaleData(abs, scaleFixed) {
6494
- let {scaleX: scaleX, scaleY: scaleY} = ImageManager.patternLocked ? this.__world : this.__nowWorld;
6495
- if (abs) scaleX < 0 && (scaleX = -scaleX), scaleY < 0 && (scaleY = -scaleY);
6496
- if (scaleFixed === true || scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) scaleX = scaleY = 1;
6497
- tempScaleData.scaleX = scaleX;
6498
- tempScaleData.scaleY = scaleY;
6499
- return tempScaleData;
6535
+ getRenderScaleData(abs, scaleFixed, unscale = true) {
6536
+ return getScaleFixedData(ImageManager.patternLocked ? this.__world : this.__nowWorld || this.__world, scaleFixed, unscale, abs);
6500
6537
  }
6501
6538
  getTransform(relative) {
6502
6539
  return this.__layout.getTransform(relative || "local");
@@ -6535,14 +6572,16 @@ let Leaf = class Leaf {
6535
6572
  relative.innerToWorld(world, to, distance);
6536
6573
  world = to ? to : world;
6537
6574
  }
6538
- toInnerPoint(this.scrollWorldTransform, world, to, distance);
6575
+ toInnerPoint(this.worldTransform, world, to, distance);
6539
6576
  }
6540
6577
  innerToWorld(inner, to, distance, relative) {
6541
- toOuterPoint(this.scrollWorldTransform, inner, to, distance);
6578
+ toOuterPoint(this.worldTransform, inner, to, distance);
6542
6579
  if (relative) relative.worldToInner(to ? to : inner, null, distance);
6543
6580
  }
6544
6581
  getBoxPoint(world, relative, distance, change) {
6545
- return this.getBoxPointByInner(this.getInnerPoint(world, relative, distance, change), null, null, true);
6582
+ const inner = this.getInnerPoint(world, relative, distance, change);
6583
+ if (distance) return inner;
6584
+ return this.getBoxPointByInner(inner, null, null, true);
6546
6585
  }
6547
6586
  getBoxPointByInner(inner, _relative, _distance, change) {
6548
6587
  const point = change ? inner : Object.assign({}, inner), {x: x, y: y} = this.boxBounds;
@@ -6658,7 +6697,6 @@ let Leaf = class Leaf {
6658
6697
  __drawHitPath(_canvas) {}
6659
6698
  __updateHitCanvas() {}
6660
6699
  __render(_canvas, _options) {}
6661
- __renderComplex(_canvas, _options) {}
6662
6700
  __drawFast(_canvas, _options) {}
6663
6701
  __draw(_canvas, _options, _originCanvas) {}
6664
6702
  __clip(_canvas, _options) {}
@@ -6669,7 +6707,7 @@ let Leaf = class Leaf {
6669
6707
  __drawPath(_canvas) {}
6670
6708
  __drawRenderPath(_canvas) {}
6671
6709
  __updatePath() {}
6672
- __updateRenderPath() {}
6710
+ __updateRenderPath(_updateCache) {}
6673
6711
  getMotionPathData() {
6674
6712
  return Plugin.need("path");
6675
6713
  }
@@ -6743,9 +6781,11 @@ let Branch = class Branch extends Leaf {
6743
6781
  return 0;
6744
6782
  }
6745
6783
  __updateRenderSpread() {
6784
+ let layout;
6746
6785
  const {children: children} = this;
6747
6786
  for (let i = 0, len = children.length; i < len; i++) {
6748
- if (children[i].__layout.renderSpread) return 1;
6787
+ layout = children[i].__layout;
6788
+ if (layout.renderSpread || layout.localOuterBounds) return 1;
6749
6789
  }
6750
6790
  return 0;
6751
6791
  }
@@ -7004,6 +7044,6 @@ class LeafLevelList {
7004
7044
  }
7005
7045
  }
7006
7046
 
7007
- const version = "2.0.2";
7047
+ const version = "2.0.4";
7008
7048
 
7009
7049
  export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, Eventer, FileHelper, FourNumberHelper, ImageEvent, ImageManager, IncrementId, LayoutEvent, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, LeaferCanvasBase, LeaferEvent, LeaferFilm, LeaferImage, LeaferVideo, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, PathBounds, PathCommandDataHelper, PathCommandMap, PathCommandNodeHelper, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Platform, Plugin, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Resource, Run, StringNumberMap, TaskItem, TaskProcessor, TwoPointBoundsHelper, UICreator, UnitConvertHelper, WaitHelper, WatchEvent, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, createDescriptor, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, dimType, doBoundsType, doStrokeType, emptyData, eraserType, extraPropertyEventMap, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isArray, isData, isEmptyData, isFinite, isNull, isNumber, isObject, isString, isUndefined, layoutProcessor, leaferTransformAttrMap, maskType, naturalBoundsType, opacityType, path, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, scrollType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, tryToNumber, useModule, version, visibleType };