@leafer-draw/worker 2.2.10 → 2.3.0

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.
@@ -470,7 +470,7 @@ function getMatrixData() {
470
470
 
471
471
  const {sin: sin$5, cos: cos$5, acos: acos, sqrt: sqrt$3} = Math;
472
472
 
473
- const {float: float$2} = MathHelper;
473
+ const {float: float$3} = MathHelper;
474
474
 
475
475
  const tempPoint$4 = {};
476
476
 
@@ -721,12 +721,12 @@ const MatrixHelper = {
721
721
  const cosR = c / scaleY;
722
722
  rotation = PI_2 - (d > 0 ? acos(-cosR) : -acos(cosR));
723
723
  }
724
- const cosR = float$2(cos$5(rotation));
724
+ const cosR = float$3(cos$5(rotation));
725
725
  const sinR = sin$5(rotation);
726
- scaleX = float$2(scaleX), scaleY = float$2(scaleY);
727
- skewX = cosR ? float$2((c / scaleY + sinR) / cosR / OneRadian, 9) : 0;
728
- skewY = cosR ? float$2((b / scaleX - sinR) / cosR / OneRadian, 9) : 0;
729
- rotation = float$2(rotation / OneRadian);
726
+ scaleX = float$3(scaleX), scaleY = float$3(scaleY);
727
+ skewX = cosR ? float$3((c / scaleY + sinR) / cosR / OneRadian, 9) : 0;
728
+ skewY = cosR ? float$3((b / scaleX - sinR) / cosR / OneRadian, 9) : 0;
729
+ rotation = float$3(rotation / OneRadian);
730
730
  } else {
731
731
  scaleX = a;
732
732
  scaleY = d;
@@ -770,7 +770,7 @@ const MatrixHelper = {
770
770
 
771
771
  const M$6 = MatrixHelper;
772
772
 
773
- const {float: float$1} = MathHelper;
773
+ const {float: float$2} = MathHelper;
774
774
 
775
775
  const {toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3} = MatrixHelper;
776
776
 
@@ -916,7 +916,7 @@ const PointHelper = {
916
916
  return points;
917
917
  },
918
918
  isSame(t, point, quick) {
919
- 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);
919
+ return quick ? t.x === point.x && t.y === point.y : float$2(t.x) === float$2(point.x) && float$2(t.y) === float$2(point.y);
920
920
  },
921
921
  reset(t) {
922
922
  t.x = t.y = 0;
@@ -1272,7 +1272,7 @@ const {tempPointBounds: tempPointBounds$1, setPoint: setPoint$2, addPoint: addPo
1272
1272
 
1273
1273
  const {toOuterPoint: toOuterPoint$2} = MatrixHelper;
1274
1274
 
1275
- const {float: float, fourNumber: fourNumber} = MathHelper;
1275
+ const {float: float$1, fourNumber: fourNumber} = MathHelper;
1276
1276
 
1277
1277
  const {floor: floor$1, ceil: ceil$1} = Math;
1278
1278
 
@@ -1447,10 +1447,10 @@ const BoundsHelper = {
1447
1447
  }
1448
1448
  },
1449
1449
  float(t, maxLength) {
1450
- t.x = float(t.x, maxLength);
1451
- t.y = float(t.y, maxLength);
1452
- t.width = float(t.width, maxLength);
1453
- t.height = float(t.height, maxLength);
1450
+ t.x = float$1(t.x, maxLength);
1451
+ t.y = float$1(t.y, maxLength);
1452
+ t.width = float$1(t.width, maxLength);
1453
+ t.height = float$1(t.height, maxLength);
1454
1454
  },
1455
1455
  add(t, bounds, isPoint) {
1456
1456
  right$1 = t.x + t.width;
@@ -3742,6 +3742,8 @@ const {getCenterX: getCenterX, getCenterY: getCenterY} = PointHelper;
3742
3742
 
3743
3743
  const {arcTo: arcTo} = PathCommandDataHelper;
3744
3744
 
3745
+ const {float: float} = MathHelper;
3746
+
3745
3747
  const PathCorner = {
3746
3748
  smooth(data, cornerRadius, _cornerSmoothing) {
3747
3749
  let command, lastCommand, commandLen, startXIndex, startYIndex, smoothLen;
@@ -3782,7 +3784,7 @@ const PathCorner = {
3782
3784
  break;
3783
3785
 
3784
3786
  case Z:
3785
- arcTo(smooth, x, y, startX, startY, cornerRadius, lastX, lastY, three);
3787
+ if (float(x) === float(startX) && float(y) === float(startY)) x = lastX, y = lastY; else arcTo(smooth, x, y, startX, startY, cornerRadius, lastX, lastY, three);
3786
3788
  break;
3787
3789
 
3788
3790
  default:
@@ -4607,39 +4609,44 @@ function doVisible(leaf, key, value, oldValue) {
4607
4609
  }
4608
4610
  }
4609
4611
 
4612
+ function sortParentChange(parent) {
4613
+ parent.__layout.childrenSortChange();
4614
+ if (parent.__.flow) parent.__layout.boxChange();
4615
+ }
4616
+
4610
4617
  function sortType(defaultValue) {
4611
4618
  return decorateLeafAttr(defaultValue, key => attr({
4612
4619
  set(value) {
4613
4620
  if (this.__setAttr(key, value)) {
4614
- this.waitParent(() => {
4615
- const {parent: parent} = this;
4616
- parent.__layout.childrenSortChange();
4617
- if (parent.__.flow) parent.__layout.boxChange();
4618
- });
4621
+ this.waitParentChange(sortParentChange);
4619
4622
  }
4620
4623
  }
4621
4624
  }));
4622
4625
  }
4623
4626
 
4627
+ function maskParentChange(parent) {
4628
+ parent.__updateMask();
4629
+ }
4630
+
4624
4631
  function maskType(defaultValue, updateSelf) {
4625
4632
  return decorateLeafAttr(defaultValue, key => attr({
4626
4633
  set(value) {
4627
4634
  if (this.__setAttr(key, value)) {
4628
4635
  this.__layout.boxChanged || this.__layout.boxChange();
4629
- updateSelf ? this.__updateMask() : this.waitParent(() => {
4630
- this.parent.__updateMask(value);
4631
- });
4636
+ updateSelf ? this.__updateMask() : this.waitParentChange(maskParentChange);
4632
4637
  }
4633
4638
  }
4634
4639
  }));
4635
4640
  }
4636
4641
 
4642
+ function eraserParentChange(parent) {
4643
+ parent.__updateEraser();
4644
+ }
4645
+
4637
4646
  function eraserType(defaultValue) {
4638
4647
  return decorateLeafAttr(defaultValue, key => attr({
4639
4648
  set(value) {
4640
- this.__setAttr(key, value) && this.waitParent(() => {
4641
- this.parent.__updateEraser(value);
4642
- });
4649
+ this.__setAttr(key, value) && this.waitParentChange(eraserParentChange);
4643
4650
  }
4644
4651
  }));
4645
4652
  }
@@ -5017,10 +5024,11 @@ const LeafHelper = {
5017
5024
  hasOffset(t) {
5018
5025
  return t.offsetX || t.offsetY;
5019
5026
  },
5020
- hasParent(p, parent) {
5027
+ hasParent(p, parent, minLevel) {
5021
5028
  if (!parent) return false;
5022
5029
  while (p) {
5023
5030
  if (parent === p) return true;
5031
+ if (minLevel && p.__level === minLevel) return;
5024
5032
  p = p.parent;
5025
5033
  }
5026
5034
  },
@@ -5038,6 +5046,10 @@ const LeafHelper = {
5038
5046
  }
5039
5047
  };
5040
5048
 
5049
+ function isTrackChanges(leafer) {
5050
+ return leafer && leafer.config.trackChanges;
5051
+ }
5052
+
5041
5053
  const L = LeafHelper;
5042
5054
 
5043
5055
  const {updateAllMatrix: updateAllMatrix$3, updateMatrix: updateMatrix$1, updateAllWorldOpacity: updateAllWorldOpacity, updateAllChange: updateAllChange$1, updateChange: updateChange} = L;
@@ -5092,6 +5104,16 @@ const BranchHelper = {
5092
5104
  sort(a, b) {
5093
5105
  return a.__.zIndex === b.__.zIndex ? a.__tempNumber - b.__tempNumber : a.__.zIndex - b.__.zIndex;
5094
5106
  },
5107
+ zIndex(branch, child, index) {
5108
+ const {children: children} = branch, before = children[index - 1], after = children[index];
5109
+ if (before && after) {
5110
+ if (child.zIndex < before.zIndex || child.zIndex > after.zIndex) child.zIndex = (before.zIndex + after.zIndex) / 2;
5111
+ } else if (before) {
5112
+ if (child.zIndex < before.zIndex) child.zIndex = before.zIndex + 1;
5113
+ } else if (after) {
5114
+ if (child.zIndex > after.zIndex) child.zIndex = after.zIndex - 1;
5115
+ }
5116
+ },
5095
5117
  pushAllChildBranch(branch, leafList) {
5096
5118
  branch.__tempNumber = 1;
5097
5119
  if (branch.__.__childBranchNumber) {
@@ -6058,7 +6080,7 @@ const LeafDataProxy = {
6058
6080
  },
6059
6081
  emitPropertyEvent(type, name, oldValue, newValue) {
6060
6082
  const {leafer: leafer} = this;
6061
- if (leafer.config.trackChanges || leafer.zoomLayer === this) {
6083
+ if (isTrackChanges(leafer) || leafer.zoomLayer === this) {
6062
6084
  const event = new PropertyEvent(type, this, name, oldValue, newValue);
6063
6085
  this.isLeafer || this.hasEvent(type) && this.emitEvent(event);
6064
6086
  leafer.emitEvent(event);
@@ -6473,6 +6495,11 @@ let Leaf = class Leaf {
6473
6495
  this.__hasMask = this.__hasEraser = null;
6474
6496
  this.forceUpdate();
6475
6497
  }
6498
+ waitParentChange(item) {
6499
+ this.__parentChange || (this.__parentChange = []);
6500
+ if (!this.__parentChange.includes(item)) this.__parentChange.push(item);
6501
+ if (this.parent) item(this.parent, this);
6502
+ }
6476
6503
  waitParent(item, bind) {
6477
6504
  if (bind) item = item.bind(bind);
6478
6505
  this.parent ? item() : this.on(ChildEvent.ADD, item, "once");
@@ -6508,7 +6535,6 @@ let Leaf = class Leaf {
6508
6535
  }
6509
6536
  }
6510
6537
  __bindFrame(frame) {
6511
- if (this.isFrame && frame !== null) frame = this;
6512
6538
  this.frame = frame;
6513
6539
  if (this.isBranch) {
6514
6540
  const {children: children} = this;
@@ -6560,8 +6586,8 @@ let Leaf = class Leaf {
6560
6586
  __extraUpdate() {
6561
6587
  if (this.leaferIsReady) this.leafer.layouter.addExtra(this);
6562
6588
  }
6563
- __updateEraser(value) {
6564
- this.__hasEraser = value ? true : this.children.some(item => item.__.eraser);
6589
+ __updateEraser() {
6590
+ this.__hasEraser = this.children.some(item => item.__.eraser);
6565
6591
  }
6566
6592
  __renderEraser(canvas, options) {
6567
6593
  canvas.save();
@@ -6570,7 +6596,7 @@ let Leaf = class Leaf {
6570
6596
  canvas.clearRect(r.x, r.y, r.width, r.height);
6571
6597
  canvas.restore();
6572
6598
  }
6573
- __updateMask(_value) {
6599
+ __updateMask() {
6574
6600
  const hasMask = this.children.some(item => item.__.mask && item.__.visible && item.__.opacity);
6575
6601
  this.__hasMask = this.__.maskskip ? hasMask && 0 : hasMask;
6576
6602
  }
@@ -6819,13 +6845,17 @@ let Branch = class Branch extends Leaf {
6819
6845
  }
6820
6846
  if (child.parent) child.parent.remove(child);
6821
6847
  child.parent = this;
6822
- noIndex ? this.children.push(child) : this.children.splice(index, 0, child);
6848
+ if (noIndex) this.children.push(child); else {
6849
+ BranchHelper.zIndex(this, child, index);
6850
+ this.children.splice(index, 0, child);
6851
+ }
6823
6852
  if (child.isBranch) this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
6824
6853
  const childLayout = child.__layout;
6825
6854
  childLayout.boxChanged || childLayout.boxChange();
6826
6855
  childLayout.matrixChanged || childLayout.matrixChange();
6856
+ if (child.__parentChange) child.__parentChange.forEach(item => item(this, child));
6827
6857
  if (child.__bubbleMap) child.__emitLifeEvent(ChildEvent.ADD);
6828
- if (this.isFrame) child.__bindFrame(this);
6858
+ if (this.frame) child.__bindFrame(this.frame);
6829
6859
  if (this.leafer) {
6830
6860
  child.__bindLeafer(this.leafer);
6831
6861
  if (this.leafer.created) this.__emitChildEvent(ChildEvent.ADD, child);
@@ -6885,11 +6915,11 @@ let Branch = class Branch extends Leaf {
6885
6915
  if (this.leafer.hitCanvasManager) this.leafer.hitCanvasManager.clear();
6886
6916
  }
6887
6917
  }
6888
- if (this.isFrame) child.__bindFrame(null);
6918
+ if (child.frame && !child.isFrame) child.__bindFrame(null);
6889
6919
  }
6890
6920
  __emitChildEvent(type, child) {
6891
6921
  const {leafer: leafer} = this;
6892
- if (leafer.config.trackChanges || leafer.zoomLayer === this) {
6922
+ if (isTrackChanges(leafer) || leafer.zoomLayer === this) {
6893
6923
  const event = new ChildEvent(type, child, this);
6894
6924
  if (this.hasEvent(type) && !this.isLeafer) this.emitEvent(event);
6895
6925
  leafer.emitEvent(event);
@@ -7046,7 +7076,13 @@ class LeafLevelList {
7046
7076
  }
7047
7077
  }
7048
7078
 
7049
- const version = "2.2.10";
7079
+ const version = "2.3.0";
7080
+
7081
+ if (typeof globalThis !== "undefined") {
7082
+ const globalLeafer = globalThis.Leafer || (globalThis.Leafer = {});
7083
+ globalLeafer.version = version;
7084
+ globalLeafer.Plugin = Plugin;
7085
+ }
7050
7086
 
7051
7087
  class LeaferCanvas extends LeaferCanvasBase {
7052
7088
  get allowBackgroundColor() {
@@ -7783,6 +7819,17 @@ function zoomLayerType() {
7783
7819
  };
7784
7820
  }
7785
7821
 
7822
+ function frameType() {
7823
+ return (target, key) => {
7824
+ defineKey(target, key, {
7825
+ set(_value) {},
7826
+ get() {
7827
+ return this;
7828
+ }
7829
+ });
7830
+ };
7831
+ }
7832
+
7786
7833
  function createAttr(defaultValue) {
7787
7834
  return (target, key) => {
7788
7835
  defineKey(target, key, createDescriptor(key, defaultValue));
@@ -9186,6 +9233,8 @@ let Frame = class Frame extends Box {
9186
9233
  }
9187
9234
  };
9188
9235
 
9236
+ __decorate([ frameType() ], Frame.prototype, "frame", void 0);
9237
+
9189
9238
  __decorate([ dataProcessor(FrameData) ], Frame.prototype, "__", void 0);
9190
9239
 
9191
9240
  __decorate([ surfaceType("#FFFFFF") ], Frame.prototype, "fill", void 0);
@@ -11415,4 +11464,4 @@ Object.assign(Effect, EffectModule);
11415
11464
 
11416
11465
  useCanvas();
11417
11466
 
11418
- export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, DataHelper, Debug, Direction4, Direction9, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Filter, FourNumberHelper, Frame, FrameData, Group, GroupData, Image, ImageData, ImageEvent, ImageManager, IncrementId, LayoutEvent, Layouter, LayouterHelper, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferFilm, LeaferImage, LeaferVideo, Line, LineData, MathHelper, Matrix, MatrixHelper, MyImage, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathBounds, PathCommandDataHelper, PathCommandMap, PathCommandNodeHelper, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNodeHandleType, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Platform, Plugin, Point, PointHelper, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Resource, Run, Star, StarData, State, StringNumberMap, TaskItem, TaskProcessor, Text, TextConvert, TextData, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIRender, UnitConvert, UnitConvertHelper, WaitHelper, WatchEvent, Watcher, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, createAttr, createDescriptor, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, dimType, doBoundsType, doStrokeType, doSurfaceType, effectType, 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, registerPointsCurve, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, scrollType, sortType, strokeType, surfaceType, tempBounds$2 as tempBounds, tempMatrix$2 as tempMatrix, tempPoint$3 as tempPoint, tryToNumber, useCanvas, useModule, version, visibleType, zoomLayerType };
11467
+ export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, DataHelper, Debug, Direction4, Direction9, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Filter, FourNumberHelper, Frame, FrameData, Group, GroupData, Image, ImageData, ImageEvent, ImageManager, IncrementId, LayoutEvent, Layouter, LayouterHelper, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferFilm, LeaferImage, LeaferVideo, Line, LineData, MathHelper, Matrix, MatrixHelper, MyImage, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathBounds, PathCommandDataHelper, PathCommandMap, PathCommandNodeHelper, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNodeHandleType, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Platform, Plugin, Point, PointHelper, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Resource, Run, Star, StarData, State, StringNumberMap, TaskItem, TaskProcessor, Text, TextConvert, TextData, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIRender, UnitConvert, UnitConvertHelper, WaitHelper, WatchEvent, Watcher, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, createAttr, createDescriptor, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, dimType, doBoundsType, doStrokeType, doSurfaceType, effectType, emptyData, eraserType, extraPropertyEventMap, frameType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isArray, isData, isEmptyData, isFinite, isNull, isNumber, isObject, isString, isTrackChanges, isUndefined, layoutProcessor, leaferTransformAttrMap, maskType, naturalBoundsType, opacityType, path, pathInputType, pathType, pen, positionType, registerPointsCurve, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, scrollType, sortType, strokeType, surfaceType, tempBounds$2 as tempBounds, tempMatrix$2 as tempMatrix, tempPoint$3 as tempPoint, tryToNumber, useCanvas, useModule, version, visibleType, zoomLayerType };