@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.
package/dist/worker.js CHANGED
@@ -433,7 +433,7 @@ var LeaferUI = function(exports) {
433
433
  };
434
434
  }
435
435
  const {sin: sin$5, cos: cos$5, acos: acos, sqrt: sqrt$3} = Math;
436
- const {float: float$2} = MathHelper;
436
+ const {float: float$3} = MathHelper;
437
437
  const tempPoint$4 = {};
438
438
  function getWorld() {
439
439
  return Object.assign(Object.assign(Object.assign({}, getMatrixData()), getBoundsData()), {
@@ -681,12 +681,12 @@ var LeaferUI = function(exports) {
681
681
  const cosR = c / scaleY;
682
682
  rotation = PI_2 - (d > 0 ? acos(-cosR) : -acos(cosR));
683
683
  }
684
- const cosR = float$2(cos$5(rotation));
684
+ const cosR = float$3(cos$5(rotation));
685
685
  const sinR = sin$5(rotation);
686
- scaleX = float$2(scaleX), scaleY = float$2(scaleY);
687
- skewX = cosR ? float$2((c / scaleY + sinR) / cosR / OneRadian, 9) : 0;
688
- skewY = cosR ? float$2((b / scaleX - sinR) / cosR / OneRadian, 9) : 0;
689
- rotation = float$2(rotation / OneRadian);
686
+ scaleX = float$3(scaleX), scaleY = float$3(scaleY);
687
+ skewX = cosR ? float$3((c / scaleY + sinR) / cosR / OneRadian, 9) : 0;
688
+ skewY = cosR ? float$3((b / scaleX - sinR) / cosR / OneRadian, 9) : 0;
689
+ rotation = float$3(rotation / OneRadian);
690
690
  } else {
691
691
  scaleX = a;
692
692
  scaleY = d;
@@ -728,7 +728,7 @@ var LeaferUI = function(exports) {
728
728
  }
729
729
  };
730
730
  const M$6 = MatrixHelper;
731
- const {float: float$1} = MathHelper;
731
+ const {float: float$2} = MathHelper;
732
732
  const {toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3} = MatrixHelper;
733
733
  const {sin: sin$4, cos: cos$4, abs: abs$5, sqrt: sqrt$2, atan2: atan2$2, min: min$1, round: round$2} = Math;
734
734
  const PointHelper = {
@@ -871,7 +871,7 @@ var LeaferUI = function(exports) {
871
871
  return points;
872
872
  },
873
873
  isSame(t, point, quick) {
874
- 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);
874
+ 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);
875
875
  },
876
876
  reset(t) {
877
877
  t.x = t.y = 0;
@@ -1206,7 +1206,7 @@ var LeaferUI = function(exports) {
1206
1206
  };
1207
1207
  const {tempPointBounds: tempPointBounds$1, setPoint: setPoint$2, addPoint: addPoint$2, toBounds: toBounds$2} = TwoPointBoundsHelper;
1208
1208
  const {toOuterPoint: toOuterPoint$2} = MatrixHelper;
1209
- const {float: float, fourNumber: fourNumber} = MathHelper;
1209
+ const {float: float$1, fourNumber: fourNumber} = MathHelper;
1210
1210
  const {floor: floor$1, ceil: ceil$1} = Math;
1211
1211
  let right$1, bottom$1, boundsRight, boundsBottom;
1212
1212
  const point = {};
@@ -1375,10 +1375,10 @@ var LeaferUI = function(exports) {
1375
1375
  }
1376
1376
  },
1377
1377
  float(t, maxLength) {
1378
- t.x = float(t.x, maxLength);
1379
- t.y = float(t.y, maxLength);
1380
- t.width = float(t.width, maxLength);
1381
- t.height = float(t.height, maxLength);
1378
+ t.x = float$1(t.x, maxLength);
1379
+ t.y = float$1(t.y, maxLength);
1380
+ t.width = float$1(t.width, maxLength);
1381
+ t.height = float$1(t.height, maxLength);
1382
1382
  },
1383
1383
  add(t, bounds, isPoint) {
1384
1384
  right$1 = t.x + t.width;
@@ -3516,6 +3516,7 @@ var LeaferUI = function(exports) {
3516
3516
  const {M: M, L: L$1, Z: Z} = PathCommandMap;
3517
3517
  const {getCenterX: getCenterX, getCenterY: getCenterY} = PointHelper;
3518
3518
  const {arcTo: arcTo} = PathCommandDataHelper;
3519
+ const {float: float} = MathHelper;
3519
3520
  const PathCorner = {
3520
3521
  smooth(data, cornerRadius, _cornerSmoothing) {
3521
3522
  let command, lastCommand, commandLen, startXIndex, startYIndex, smoothLen;
@@ -3556,7 +3557,7 @@ var LeaferUI = function(exports) {
3556
3557
  break;
3557
3558
 
3558
3559
  case Z:
3559
- arcTo(smooth, x, y, startX, startY, cornerRadius, lastX, lastY, three);
3560
+ if (float(x) === float(startX) && float(y) === float(startY)) x = lastX, y = lastY; else arcTo(smooth, x, y, startX, startY, cornerRadius, lastX, lastY, three);
3560
3561
  break;
3561
3562
 
3562
3563
  default:
@@ -4327,37 +4328,39 @@ var LeaferUI = function(exports) {
4327
4328
  if (oldValue === 0 || value === 0) doBoundsType(leaf);
4328
4329
  }
4329
4330
  }
4331
+ function sortParentChange(parent) {
4332
+ parent.__layout.childrenSortChange();
4333
+ if (parent.__.flow) parent.__layout.boxChange();
4334
+ }
4330
4335
  function sortType(defaultValue) {
4331
4336
  return decorateLeafAttr(defaultValue, key => attr({
4332
4337
  set(value) {
4333
4338
  if (this.__setAttr(key, value)) {
4334
- this.waitParent(() => {
4335
- const {parent: parent} = this;
4336
- parent.__layout.childrenSortChange();
4337
- if (parent.__.flow) parent.__layout.boxChange();
4338
- });
4339
+ this.waitParentChange(sortParentChange);
4339
4340
  }
4340
4341
  }
4341
4342
  }));
4342
4343
  }
4344
+ function maskParentChange(parent) {
4345
+ parent.__updateMask();
4346
+ }
4343
4347
  function maskType(defaultValue, updateSelf) {
4344
4348
  return decorateLeafAttr(defaultValue, key => attr({
4345
4349
  set(value) {
4346
4350
  if (this.__setAttr(key, value)) {
4347
4351
  this.__layout.boxChanged || this.__layout.boxChange();
4348
- updateSelf ? this.__updateMask() : this.waitParent(() => {
4349
- this.parent.__updateMask(value);
4350
- });
4352
+ updateSelf ? this.__updateMask() : this.waitParentChange(maskParentChange);
4351
4353
  }
4352
4354
  }
4353
4355
  }));
4354
4356
  }
4357
+ function eraserParentChange(parent) {
4358
+ parent.__updateEraser();
4359
+ }
4355
4360
  function eraserType(defaultValue) {
4356
4361
  return decorateLeafAttr(defaultValue, key => attr({
4357
4362
  set(value) {
4358
- this.__setAttr(key, value) && this.waitParent(() => {
4359
- this.parent.__updateEraser(value);
4360
- });
4363
+ this.__setAttr(key, value) && this.waitParentChange(eraserParentChange);
4361
4364
  }
4362
4365
  }));
4363
4366
  }
@@ -4716,10 +4719,11 @@ var LeaferUI = function(exports) {
4716
4719
  hasOffset(t) {
4717
4720
  return t.offsetX || t.offsetY;
4718
4721
  },
4719
- hasParent(p, parent) {
4722
+ hasParent(p, parent, minLevel) {
4720
4723
  if (!parent) return false;
4721
4724
  while (p) {
4722
4725
  if (parent === p) return true;
4726
+ if (minLevel && p.__level === minLevel) return;
4723
4727
  p = p.parent;
4724
4728
  }
4725
4729
  },
@@ -4736,6 +4740,9 @@ var LeaferUI = function(exports) {
4736
4740
  onAnimate && onAnimate();
4737
4741
  }
4738
4742
  };
4743
+ function isTrackChanges(leafer) {
4744
+ return leafer && leafer.config.trackChanges;
4745
+ }
4739
4746
  const L = LeafHelper;
4740
4747
  const {updateAllMatrix: updateAllMatrix$3, updateMatrix: updateMatrix$1, updateAllWorldOpacity: updateAllWorldOpacity, updateAllChange: updateAllChange$1, updateChange: updateChange} = L;
4741
4748
  function getTempLocal(t, worldPoint) {
@@ -4783,6 +4790,16 @@ var LeaferUI = function(exports) {
4783
4790
  sort(a, b) {
4784
4791
  return a.__.zIndex === b.__.zIndex ? a.__tempNumber - b.__tempNumber : a.__.zIndex - b.__.zIndex;
4785
4792
  },
4793
+ zIndex(branch, child, index) {
4794
+ const {children: children} = branch, before = children[index - 1], after = children[index];
4795
+ if (before && after) {
4796
+ if (child.zIndex < before.zIndex || child.zIndex > after.zIndex) child.zIndex = (before.zIndex + after.zIndex) / 2;
4797
+ } else if (before) {
4798
+ if (child.zIndex < before.zIndex) child.zIndex = before.zIndex + 1;
4799
+ } else if (after) {
4800
+ if (child.zIndex > after.zIndex) child.zIndex = after.zIndex - 1;
4801
+ }
4802
+ },
4786
4803
  pushAllChildBranch(branch, leafList) {
4787
4804
  branch.__tempNumber = 1;
4788
4805
  if (branch.__.__childBranchNumber) {
@@ -5667,7 +5684,7 @@ var LeaferUI = function(exports) {
5667
5684
  },
5668
5685
  emitPropertyEvent(type, name, oldValue, newValue) {
5669
5686
  const {leafer: leafer} = this;
5670
- if (leafer.config.trackChanges || leafer.zoomLayer === this) {
5687
+ if (isTrackChanges(leafer) || leafer.zoomLayer === this) {
5671
5688
  const event = new PropertyEvent(type, this, name, oldValue, newValue);
5672
5689
  this.isLeafer || this.hasEvent(type) && this.emitEvent(event);
5673
5690
  leafer.emitEvent(event);
@@ -6063,6 +6080,11 @@ var LeaferUI = function(exports) {
6063
6080
  this.__hasMask = this.__hasEraser = null;
6064
6081
  this.forceUpdate();
6065
6082
  }
6083
+ waitParentChange(item) {
6084
+ this.__parentChange || (this.__parentChange = []);
6085
+ if (!this.__parentChange.includes(item)) this.__parentChange.push(item);
6086
+ if (this.parent) item(this.parent, this);
6087
+ }
6066
6088
  waitParent(item, bind) {
6067
6089
  if (bind) item = item.bind(bind);
6068
6090
  this.parent ? item() : this.on(ChildEvent.ADD, item, "once");
@@ -6098,7 +6120,6 @@ var LeaferUI = function(exports) {
6098
6120
  }
6099
6121
  }
6100
6122
  __bindFrame(frame) {
6101
- if (this.isFrame && frame !== null) frame = this;
6102
6123
  this.frame = frame;
6103
6124
  if (this.isBranch) {
6104
6125
  const {children: children} = this;
@@ -6150,8 +6171,8 @@ var LeaferUI = function(exports) {
6150
6171
  __extraUpdate() {
6151
6172
  if (this.leaferIsReady) this.leafer.layouter.addExtra(this);
6152
6173
  }
6153
- __updateEraser(value) {
6154
- this.__hasEraser = value ? true : this.children.some(item => item.__.eraser);
6174
+ __updateEraser() {
6175
+ this.__hasEraser = this.children.some(item => item.__.eraser);
6155
6176
  }
6156
6177
  __renderEraser(canvas, options) {
6157
6178
  canvas.save();
@@ -6160,7 +6181,7 @@ var LeaferUI = function(exports) {
6160
6181
  canvas.clearRect(r.x, r.y, r.width, r.height);
6161
6182
  canvas.restore();
6162
6183
  }
6163
- __updateMask(_value) {
6184
+ __updateMask() {
6164
6185
  const hasMask = this.children.some(item => item.__.mask && item.__.visible && item.__.opacity);
6165
6186
  this.__hasMask = this.__.maskskip ? hasMask && 0 : hasMask;
6166
6187
  }
@@ -6403,13 +6424,17 @@ var LeaferUI = function(exports) {
6403
6424
  }
6404
6425
  if (child.parent) child.parent.remove(child);
6405
6426
  child.parent = this;
6406
- noIndex ? this.children.push(child) : this.children.splice(index, 0, child);
6427
+ if (noIndex) this.children.push(child); else {
6428
+ BranchHelper.zIndex(this, child, index);
6429
+ this.children.splice(index, 0, child);
6430
+ }
6407
6431
  if (child.isBranch) this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
6408
6432
  const childLayout = child.__layout;
6409
6433
  childLayout.boxChanged || childLayout.boxChange();
6410
6434
  childLayout.matrixChanged || childLayout.matrixChange();
6435
+ if (child.__parentChange) child.__parentChange.forEach(item => item(this, child));
6411
6436
  if (child.__bubbleMap) child.__emitLifeEvent(ChildEvent.ADD);
6412
- if (this.isFrame) child.__bindFrame(this);
6437
+ if (this.frame) child.__bindFrame(this.frame);
6413
6438
  if (this.leafer) {
6414
6439
  child.__bindLeafer(this.leafer);
6415
6440
  if (this.leafer.created) this.__emitChildEvent(ChildEvent.ADD, child);
@@ -6469,11 +6494,11 @@ var LeaferUI = function(exports) {
6469
6494
  if (this.leafer.hitCanvasManager) this.leafer.hitCanvasManager.clear();
6470
6495
  }
6471
6496
  }
6472
- if (this.isFrame) child.__bindFrame(null);
6497
+ if (child.frame && !child.isFrame) child.__bindFrame(null);
6473
6498
  }
6474
6499
  __emitChildEvent(type, child) {
6475
6500
  const {leafer: leafer} = this;
6476
- if (leafer.config.trackChanges || leafer.zoomLayer === this) {
6501
+ if (isTrackChanges(leafer) || leafer.zoomLayer === this) {
6477
6502
  const event = new ChildEvent(type, child, this);
6478
6503
  if (this.hasEvent(type) && !this.isLeafer) this.emitEvent(event);
6479
6504
  leafer.emitEvent(event);
@@ -6626,7 +6651,12 @@ var LeaferUI = function(exports) {
6626
6651
  this.levelMap = null;
6627
6652
  }
6628
6653
  }
6629
- const version = "2.2.10";
6654
+ const version = "2.3.0";
6655
+ if (typeof globalThis !== "undefined") {
6656
+ const globalLeafer = globalThis.Leafer || (globalThis.Leafer = {});
6657
+ globalLeafer.version = version;
6658
+ globalLeafer.Plugin = Plugin;
6659
+ }
6630
6660
  class LeaferCanvas extends LeaferCanvasBase {
6631
6661
  get allowBackgroundColor() {
6632
6662
  return true;
@@ -7330,6 +7360,16 @@ var LeaferUI = function(exports) {
7330
7360
  });
7331
7361
  };
7332
7362
  }
7363
+ function frameType() {
7364
+ return (target, key) => {
7365
+ defineKey(target, key, {
7366
+ set(_value) {},
7367
+ get() {
7368
+ return this;
7369
+ }
7370
+ });
7371
+ };
7372
+ }
7333
7373
  function createAttr(defaultValue) {
7334
7374
  return (target, key) => {
7335
7375
  defineKey(target, key, createDescriptor(key, defaultValue));
@@ -8582,6 +8622,7 @@ var LeaferUI = function(exports) {
8582
8622
  return true;
8583
8623
  }
8584
8624
  };
8625
+ __decorate([ frameType() ], exports.Frame.prototype, "frame", void 0);
8585
8626
  __decorate([ dataProcessor(FrameData) ], exports.Frame.prototype, "__", void 0);
8586
8627
  __decorate([ surfaceType("#FFFFFF") ], exports.Frame.prototype, "fill", void 0);
8587
8628
  __decorate([ affectRenderBoundsType("hide") ], exports.Frame.prototype, "overflow", void 0);
@@ -10701,6 +10742,7 @@ var LeaferUI = function(exports) {
10701
10742
  exports.emptyData = emptyData;
10702
10743
  exports.eraserType = eraserType;
10703
10744
  exports.extraPropertyEventMap = extraPropertyEventMap;
10745
+ exports.frameType = frameType;
10704
10746
  exports.getBoundsData = getBoundsData;
10705
10747
  exports.getDescriptor = getDescriptor;
10706
10748
  exports.getMatrixData = getMatrixData;
@@ -10714,6 +10756,7 @@ var LeaferUI = function(exports) {
10714
10756
  exports.isNumber = isNumber;
10715
10757
  exports.isObject = isObject;
10716
10758
  exports.isString = isString;
10759
+ exports.isTrackChanges = isTrackChanges;
10717
10760
  exports.isUndefined = isUndefined;
10718
10761
  exports.layoutProcessor = layoutProcessor;
10719
10762
  exports.leaferTransformAttrMap = leaferTransformAttrMap;