leafer-game 2.2.11 → 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/web.js CHANGED
@@ -433,7 +433,7 @@ var LeaferUI = function(exports) {
433
433
  };
434
434
  }
435
435
  const {sin: sin$6, cos: cos$6, acos: acos, sqrt: sqrt$5} = Math;
436
- const {float: float$5} = MathHelper;
436
+ const {float: float$6} = MathHelper;
437
437
  const tempPoint$7 = {};
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$5(cos$6(rotation));
684
+ const cosR = float$6(cos$6(rotation));
685
685
  const sinR = sin$6(rotation);
686
- scaleX = float$5(scaleX), scaleY = float$5(scaleY);
687
- skewX = cosR ? float$5((c / scaleY + sinR) / cosR / OneRadian, 9) : 0;
688
- skewY = cosR ? float$5((b / scaleX - sinR) / cosR / OneRadian, 9) : 0;
689
- rotation = float$5(rotation / OneRadian);
686
+ scaleX = float$6(scaleX), scaleY = float$6(scaleY);
687
+ skewX = cosR ? float$6((c / scaleY + sinR) / cosR / OneRadian, 9) : 0;
688
+ skewY = cosR ? float$6((b / scaleX - sinR) / cosR / OneRadian, 9) : 0;
689
+ rotation = float$6(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$7 = MatrixHelper;
731
- const {float: float$4} = MathHelper;
731
+ const {float: float$5} = MathHelper;
732
732
  const {toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3} = MatrixHelper;
733
733
  const {sin: sin$5, cos: cos$5, abs: abs$7, sqrt: sqrt$4, atan2: atan2$2, min: min$2, round: round$5} = 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$4(t.x) === float$4(point.x) && float$4(t.y) === float$4(point.y);
874
+ return quick ? t.x === point.x && t.y === point.y : float$5(t.x) === float$5(point.x) && float$5(t.y) === float$5(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$3, fourNumber: fourNumber$1} = MathHelper;
1209
+ const {float: float$4, fourNumber: fourNumber$1} = MathHelper;
1210
1210
  const {floor: floor$2, ceil: ceil$2} = 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$3(t.x, maxLength);
1379
- t.y = float$3(t.y, maxLength);
1380
- t.width = float$3(t.width, maxLength);
1381
- t.height = float$3(t.height, maxLength);
1378
+ t.x = float$4(t.x, maxLength);
1379
+ t.y = float$4(t.y, maxLength);
1380
+ t.width = float$4(t.width, maxLength);
1381
+ t.height = float$4(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$1, L: L$2, Z: Z$1} = PathCommandMap;
3517
3517
  const {getCenterX: getCenterX, getCenterY: getCenterY} = PointHelper;
3518
3518
  const {arcTo: arcTo} = PathCommandDataHelper;
3519
+ const {float: float$3} = MathHelper;
3519
3520
  const PathCorner = {
3520
3521
  smooth(data, cornerRadius, _cornerSmoothing) {
3521
3522
  let command, lastCommand, commandLen, startXIndex, startYIndex, smoothLen;
@@ -3556,7 +3557,8 @@ var LeaferUI = function(exports) {
3556
3557
  break;
3557
3558
 
3558
3559
  case Z$1:
3559
- arcTo(smooth, x, y, startX, startY, cornerRadius, lastX, lastY, three);
3560
+ if (float$3(x) === float$3(startX) && float$3(y) === float$3(startY)) x = lastX,
3561
+ y = lastY; else arcTo(smooth, x, y, startX, startY, cornerRadius, lastX, lastY, three);
3560
3562
  break;
3561
3563
 
3562
3564
  default:
@@ -4718,10 +4720,11 @@ var LeaferUI = function(exports) {
4718
4720
  hasOffset(t) {
4719
4721
  return t.offsetX || t.offsetY;
4720
4722
  },
4721
- hasParent(p, parent) {
4723
+ hasParent(p, parent, minLevel) {
4722
4724
  if (!parent) return false;
4723
4725
  while (p) {
4724
4726
  if (parent === p) return true;
4727
+ if (minLevel && p.__level === minLevel) return;
4725
4728
  p = p.parent;
4726
4729
  }
4727
4730
  },
@@ -4738,6 +4741,9 @@ var LeaferUI = function(exports) {
4738
4741
  onAnimate && onAnimate();
4739
4742
  }
4740
4743
  };
4744
+ function isTrackChanges(leafer) {
4745
+ return leafer && leafer.config.trackChanges;
4746
+ }
4741
4747
  const L$1 = LeafHelper;
4742
4748
  const {updateAllMatrix: updateAllMatrix$4, updateMatrix: updateMatrix$2, updateAllWorldOpacity: updateAllWorldOpacity, updateAllChange: updateAllChange$1, updateChange: updateChange} = L$1;
4743
4749
  function getTempLocal(t, worldPoint) {
@@ -4785,6 +4791,16 @@ var LeaferUI = function(exports) {
4785
4791
  sort(a, b) {
4786
4792
  return a.__.zIndex === b.__.zIndex ? a.__tempNumber - b.__tempNumber : a.__.zIndex - b.__.zIndex;
4787
4793
  },
4794
+ zIndex(branch, child, index) {
4795
+ const {children: children} = branch, before = children[index - 1], after = children[index];
4796
+ if (before && after) {
4797
+ if (child.zIndex < before.zIndex || child.zIndex > after.zIndex) child.zIndex = (before.zIndex + after.zIndex) / 2;
4798
+ } else if (before) {
4799
+ if (child.zIndex < before.zIndex) child.zIndex = before.zIndex + 1;
4800
+ } else if (after) {
4801
+ if (child.zIndex > after.zIndex) child.zIndex = after.zIndex - 1;
4802
+ }
4803
+ },
4788
4804
  pushAllChildBranch(branch, leafList) {
4789
4805
  branch.__tempNumber = 1;
4790
4806
  if (branch.__.__childBranchNumber) {
@@ -5669,7 +5685,7 @@ var LeaferUI = function(exports) {
5669
5685
  },
5670
5686
  emitPropertyEvent(type, name, oldValue, newValue) {
5671
5687
  const {leafer: leafer} = this;
5672
- if (leafer.config.trackChanges || leafer.zoomLayer === this) {
5688
+ if (isTrackChanges(leafer) || leafer.zoomLayer === this) {
5673
5689
  const event = new PropertyEvent(type, this, name, oldValue, newValue);
5674
5690
  this.isLeafer || this.hasEvent(type) && this.emitEvent(event);
5675
5691
  leafer.emitEvent(event);
@@ -6105,7 +6121,6 @@ var LeaferUI = function(exports) {
6105
6121
  }
6106
6122
  }
6107
6123
  __bindFrame(frame) {
6108
- if (this.isFrame && frame !== null) frame = this;
6109
6124
  this.frame = frame;
6110
6125
  if (this.isBranch) {
6111
6126
  const {children: children} = this;
@@ -6410,14 +6425,17 @@ var LeaferUI = function(exports) {
6410
6425
  }
6411
6426
  if (child.parent) child.parent.remove(child);
6412
6427
  child.parent = this;
6413
- noIndex ? this.children.push(child) : this.children.splice(index, 0, child);
6428
+ if (noIndex) this.children.push(child); else {
6429
+ BranchHelper.zIndex(this, child, index);
6430
+ this.children.splice(index, 0, child);
6431
+ }
6414
6432
  if (child.isBranch) this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
6415
6433
  const childLayout = child.__layout;
6416
6434
  childLayout.boxChanged || childLayout.boxChange();
6417
6435
  childLayout.matrixChanged || childLayout.matrixChange();
6418
6436
  if (child.__parentChange) child.__parentChange.forEach(item => item(this, child));
6419
6437
  if (child.__bubbleMap) child.__emitLifeEvent(ChildEvent.ADD);
6420
- if (this.isFrame) child.__bindFrame(this);
6438
+ if (this.frame) child.__bindFrame(this.frame);
6421
6439
  if (this.leafer) {
6422
6440
  child.__bindLeafer(this.leafer);
6423
6441
  if (this.leafer.created) this.__emitChildEvent(ChildEvent.ADD, child);
@@ -6477,11 +6495,11 @@ var LeaferUI = function(exports) {
6477
6495
  if (this.leafer.hitCanvasManager) this.leafer.hitCanvasManager.clear();
6478
6496
  }
6479
6497
  }
6480
- if (this.isFrame) child.__bindFrame(null);
6498
+ if (child.frame && !child.isFrame) child.__bindFrame(null);
6481
6499
  }
6482
6500
  __emitChildEvent(type, child) {
6483
6501
  const {leafer: leafer} = this;
6484
- if (leafer.config.trackChanges || leafer.zoomLayer === this) {
6502
+ if (isTrackChanges(leafer) || leafer.zoomLayer === this) {
6485
6503
  const event = new ChildEvent(type, child, this);
6486
6504
  if (this.hasEvent(type) && !this.isLeafer) this.emitEvent(event);
6487
6505
  leafer.emitEvent(event);
@@ -6634,7 +6652,12 @@ var LeaferUI = function(exports) {
6634
6652
  this.levelMap = null;
6635
6653
  }
6636
6654
  }
6637
- const version = "2.2.11";
6655
+ const version = "2.3.0";
6656
+ if (typeof globalThis !== "undefined") {
6657
+ const globalLeafer = globalThis.Leafer || (globalThis.Leafer = {});
6658
+ globalLeafer.version = version;
6659
+ globalLeafer.Plugin = Plugin;
6660
+ }
6638
6661
  const debug$5 = Debug.get("LeaferCanvas");
6639
6662
  class LeaferCanvas extends LeaferCanvasBase {
6640
6663
  set zIndex(zIndex) {
@@ -7742,6 +7765,16 @@ var LeaferUI = function(exports) {
7742
7765
  });
7743
7766
  };
7744
7767
  }
7768
+ function frameType() {
7769
+ return (target, key) => {
7770
+ defineKey(target, key, {
7771
+ set(_value) {},
7772
+ get() {
7773
+ return this;
7774
+ }
7775
+ });
7776
+ };
7777
+ }
7745
7778
  function createAttr(defaultValue) {
7746
7779
  return (target, key) => {
7747
7780
  defineKey(target, key, createDescriptor(key, defaultValue));
@@ -8994,6 +9027,7 @@ var LeaferUI = function(exports) {
8994
9027
  return true;
8995
9028
  }
8996
9029
  };
9030
+ __decorate([ frameType() ], exports.Frame.prototype, "frame", void 0);
8997
9031
  __decorate([ dataProcessor(FrameData) ], exports.Frame.prototype, "__", void 0);
8998
9032
  __decorate([ surfaceType("#FFFFFF") ], exports.Frame.prototype, "fill", void 0);
8999
9033
  __decorate([ affectRenderBoundsType("hide") ], exports.Frame.prototype, "overflow", void 0);
@@ -14111,14 +14145,20 @@ var LeaferUI = function(exports) {
14111
14145
  const value = from + (to - from) * t;
14112
14146
  return roundValue ? round(value) : value;
14113
14147
  }
14114
- function color(from, to, t) {
14115
- from = ColorConvert.object(from), to = ColorConvert.object(to);
14148
+ function color(fromColor, toColor, t) {
14149
+ let from = ColorConvert.object(fromColor), to = ColorConvert.object(toColor);
14150
+ if (!fromColor) from = Object.assign(Object.assign({}, to), {
14151
+ a: 0
14152
+ });
14153
+ if (!toColor) to = Object.assign(Object.assign({}, from), {
14154
+ a: 0
14155
+ });
14116
14156
  const rgb = number(from.r, to.r, t, 1) + "," + number(from.g, to.g, t, 1) + "," + number(from.b, to.b, t, 1);
14117
14157
  const a = number(from.a, to.a, t);
14118
14158
  return a === 1 ? "rgb(" + rgb + ")" : "rgba(" + rgb + "," + a + ")";
14119
14159
  }
14120
14160
  function paint(from, to, t) {
14121
- return isString(from) && isString(to) ? color(from, to, t) : to;
14161
+ return (isString(from) || !from) && (isString(to) || !to) ? color(from, to, t) : to;
14122
14162
  }
14123
14163
  function shadow(from, to, t) {
14124
14164
  if (isArray(from) || isArray(to)) return to;
@@ -14882,6 +14922,7 @@ var LeaferUI = function(exports) {
14882
14922
  exports.emptyData = emptyData;
14883
14923
  exports.eraserType = eraserType;
14884
14924
  exports.extraPropertyEventMap = extraPropertyEventMap;
14925
+ exports.frameType = frameType;
14885
14926
  exports.getBoundsData = getBoundsData;
14886
14927
  exports.getDescriptor = getDescriptor;
14887
14928
  exports.getMatrixData = getMatrixData;
@@ -14895,6 +14936,7 @@ var LeaferUI = function(exports) {
14895
14936
  exports.isNumber = isNumber;
14896
14937
  exports.isObject = isObject;
14897
14938
  exports.isString = isString;
14939
+ exports.isTrackChanges = isTrackChanges;
14898
14940
  exports.isUndefined = isUndefined;
14899
14941
  exports.layoutProcessor = layoutProcessor;
14900
14942
  exports.leaferTransformAttrMap = leaferTransformAttrMap;