leafer-game 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/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:
@@ -4327,37 +4329,39 @@ var LeaferUI = function(exports) {
4327
4329
  if (oldValue === 0 || value === 0) doBoundsType(leaf);
4328
4330
  }
4329
4331
  }
4332
+ function sortParentChange(parent) {
4333
+ parent.__layout.childrenSortChange();
4334
+ if (parent.__.flow) parent.__layout.boxChange();
4335
+ }
4330
4336
  function sortType(defaultValue) {
4331
4337
  return decorateLeafAttr(defaultValue, key => attr({
4332
4338
  set(value) {
4333
4339
  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
- });
4340
+ this.waitParentChange(sortParentChange);
4339
4341
  }
4340
4342
  }
4341
4343
  }));
4342
4344
  }
4345
+ function maskParentChange(parent) {
4346
+ parent.__updateMask();
4347
+ }
4343
4348
  function maskType(defaultValue, updateSelf) {
4344
4349
  return decorateLeafAttr(defaultValue, key => attr({
4345
4350
  set(value) {
4346
4351
  if (this.__setAttr(key, value)) {
4347
4352
  this.__layout.boxChanged || this.__layout.boxChange();
4348
- updateSelf ? this.__updateMask() : this.waitParent(() => {
4349
- this.parent.__updateMask(value);
4350
- });
4353
+ updateSelf ? this.__updateMask() : this.waitParentChange(maskParentChange);
4351
4354
  }
4352
4355
  }
4353
4356
  }));
4354
4357
  }
4358
+ function eraserParentChange(parent) {
4359
+ parent.__updateEraser();
4360
+ }
4355
4361
  function eraserType(defaultValue) {
4356
4362
  return decorateLeafAttr(defaultValue, key => attr({
4357
4363
  set(value) {
4358
- this.__setAttr(key, value) && this.waitParent(() => {
4359
- this.parent.__updateEraser(value);
4360
- });
4364
+ this.__setAttr(key, value) && this.waitParentChange(eraserParentChange);
4361
4365
  }
4362
4366
  }));
4363
4367
  }
@@ -4716,10 +4720,11 @@ var LeaferUI = function(exports) {
4716
4720
  hasOffset(t) {
4717
4721
  return t.offsetX || t.offsetY;
4718
4722
  },
4719
- hasParent(p, parent) {
4723
+ hasParent(p, parent, minLevel) {
4720
4724
  if (!parent) return false;
4721
4725
  while (p) {
4722
4726
  if (parent === p) return true;
4727
+ if (minLevel && p.__level === minLevel) return;
4723
4728
  p = p.parent;
4724
4729
  }
4725
4730
  },
@@ -4736,6 +4741,9 @@ var LeaferUI = function(exports) {
4736
4741
  onAnimate && onAnimate();
4737
4742
  }
4738
4743
  };
4744
+ function isTrackChanges(leafer) {
4745
+ return leafer && leafer.config.trackChanges;
4746
+ }
4739
4747
  const L$1 = LeafHelper;
4740
4748
  const {updateAllMatrix: updateAllMatrix$4, updateMatrix: updateMatrix$2, updateAllWorldOpacity: updateAllWorldOpacity, updateAllChange: updateAllChange$1, updateChange: updateChange} = L$1;
4741
4749
  function getTempLocal(t, worldPoint) {
@@ -4783,6 +4791,16 @@ var LeaferUI = function(exports) {
4783
4791
  sort(a, b) {
4784
4792
  return a.__.zIndex === b.__.zIndex ? a.__tempNumber - b.__tempNumber : a.__.zIndex - b.__.zIndex;
4785
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
+ },
4786
4804
  pushAllChildBranch(branch, leafList) {
4787
4805
  branch.__tempNumber = 1;
4788
4806
  if (branch.__.__childBranchNumber) {
@@ -5667,7 +5685,7 @@ var LeaferUI = function(exports) {
5667
5685
  },
5668
5686
  emitPropertyEvent(type, name, oldValue, newValue) {
5669
5687
  const {leafer: leafer} = this;
5670
- if (leafer.config.trackChanges || leafer.zoomLayer === this) {
5688
+ if (isTrackChanges(leafer) || leafer.zoomLayer === this) {
5671
5689
  const event = new PropertyEvent(type, this, name, oldValue, newValue);
5672
5690
  this.isLeafer || this.hasEvent(type) && this.emitEvent(event);
5673
5691
  leafer.emitEvent(event);
@@ -6063,6 +6081,11 @@ var LeaferUI = function(exports) {
6063
6081
  this.__hasMask = this.__hasEraser = null;
6064
6082
  this.forceUpdate();
6065
6083
  }
6084
+ waitParentChange(item) {
6085
+ this.__parentChange || (this.__parentChange = []);
6086
+ if (!this.__parentChange.includes(item)) this.__parentChange.push(item);
6087
+ if (this.parent) item(this.parent, this);
6088
+ }
6066
6089
  waitParent(item, bind) {
6067
6090
  if (bind) item = item.bind(bind);
6068
6091
  this.parent ? item() : this.on(ChildEvent.ADD, item, "once");
@@ -6098,7 +6121,6 @@ var LeaferUI = function(exports) {
6098
6121
  }
6099
6122
  }
6100
6123
  __bindFrame(frame) {
6101
- if (this.isFrame && frame !== null) frame = this;
6102
6124
  this.frame = frame;
6103
6125
  if (this.isBranch) {
6104
6126
  const {children: children} = this;
@@ -6150,8 +6172,8 @@ var LeaferUI = function(exports) {
6150
6172
  __extraUpdate() {
6151
6173
  if (this.leaferIsReady) this.leafer.layouter.addExtra(this);
6152
6174
  }
6153
- __updateEraser(value) {
6154
- this.__hasEraser = value ? true : this.children.some(item => item.__.eraser);
6175
+ __updateEraser() {
6176
+ this.__hasEraser = this.children.some(item => item.__.eraser);
6155
6177
  }
6156
6178
  __renderEraser(canvas, options) {
6157
6179
  canvas.save();
@@ -6160,7 +6182,7 @@ var LeaferUI = function(exports) {
6160
6182
  canvas.clearRect(r.x, r.y, r.width, r.height);
6161
6183
  canvas.restore();
6162
6184
  }
6163
- __updateMask(_value) {
6185
+ __updateMask() {
6164
6186
  const hasMask = this.children.some(item => item.__.mask && item.__.visible && item.__.opacity);
6165
6187
  this.__hasMask = this.__.maskskip ? hasMask && 0 : hasMask;
6166
6188
  }
@@ -6403,13 +6425,17 @@ var LeaferUI = function(exports) {
6403
6425
  }
6404
6426
  if (child.parent) child.parent.remove(child);
6405
6427
  child.parent = this;
6406
- 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
+ }
6407
6432
  if (child.isBranch) this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
6408
6433
  const childLayout = child.__layout;
6409
6434
  childLayout.boxChanged || childLayout.boxChange();
6410
6435
  childLayout.matrixChanged || childLayout.matrixChange();
6436
+ if (child.__parentChange) child.__parentChange.forEach(item => item(this, child));
6411
6437
  if (child.__bubbleMap) child.__emitLifeEvent(ChildEvent.ADD);
6412
- if (this.isFrame) child.__bindFrame(this);
6438
+ if (this.frame) child.__bindFrame(this.frame);
6413
6439
  if (this.leafer) {
6414
6440
  child.__bindLeafer(this.leafer);
6415
6441
  if (this.leafer.created) this.__emitChildEvent(ChildEvent.ADD, child);
@@ -6469,11 +6495,11 @@ var LeaferUI = function(exports) {
6469
6495
  if (this.leafer.hitCanvasManager) this.leafer.hitCanvasManager.clear();
6470
6496
  }
6471
6497
  }
6472
- if (this.isFrame) child.__bindFrame(null);
6498
+ if (child.frame && !child.isFrame) child.__bindFrame(null);
6473
6499
  }
6474
6500
  __emitChildEvent(type, child) {
6475
6501
  const {leafer: leafer} = this;
6476
- if (leafer.config.trackChanges || leafer.zoomLayer === this) {
6502
+ if (isTrackChanges(leafer) || leafer.zoomLayer === this) {
6477
6503
  const event = new ChildEvent(type, child, this);
6478
6504
  if (this.hasEvent(type) && !this.isLeafer) this.emitEvent(event);
6479
6505
  leafer.emitEvent(event);
@@ -6626,7 +6652,12 @@ var LeaferUI = function(exports) {
6626
6652
  this.levelMap = null;
6627
6653
  }
6628
6654
  }
6629
- const version = "2.2.10";
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
+ }
6630
6661
  const debug$5 = Debug.get("LeaferCanvas");
6631
6662
  class LeaferCanvas extends LeaferCanvasBase {
6632
6663
  set zIndex(zIndex) {
@@ -7734,6 +7765,16 @@ var LeaferUI = function(exports) {
7734
7765
  });
7735
7766
  };
7736
7767
  }
7768
+ function frameType() {
7769
+ return (target, key) => {
7770
+ defineKey(target, key, {
7771
+ set(_value) {},
7772
+ get() {
7773
+ return this;
7774
+ }
7775
+ });
7776
+ };
7777
+ }
7737
7778
  function createAttr(defaultValue) {
7738
7779
  return (target, key) => {
7739
7780
  defineKey(target, key, createDescriptor(key, defaultValue));
@@ -8986,6 +9027,7 @@ var LeaferUI = function(exports) {
8986
9027
  return true;
8987
9028
  }
8988
9029
  };
9030
+ __decorate([ frameType() ], exports.Frame.prototype, "frame", void 0);
8989
9031
  __decorate([ dataProcessor(FrameData) ], exports.Frame.prototype, "__", void 0);
8990
9032
  __decorate([ surfaceType("#FFFFFF") ], exports.Frame.prototype, "fill", void 0);
8991
9033
  __decorate([ affectRenderBoundsType("hide") ], exports.Frame.prototype, "overflow", void 0);
@@ -12710,9 +12752,15 @@ var LeaferUI = function(exports) {
12710
12752
  });
12711
12753
  useCanvas();
12712
12754
  class RobotData extends UIData {
12755
+ get __isCanvas() {
12756
+ return true;
12757
+ }
12713
12758
  get __drawAfterFill() {
12714
12759
  return true;
12715
12760
  }
12761
+ get __boxStroke() {
12762
+ return !this.__pathInputed;
12763
+ }
12716
12764
  setRobot(value) {
12717
12765
  this._robot = value;
12718
12766
  this.__leaf.__updateRobot();
@@ -14097,14 +14145,20 @@ var LeaferUI = function(exports) {
14097
14145
  const value = from + (to - from) * t;
14098
14146
  return roundValue ? round(value) : value;
14099
14147
  }
14100
- function color(from, to, t) {
14101
- 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
+ });
14102
14156
  const rgb = number(from.r, to.r, t, 1) + "," + number(from.g, to.g, t, 1) + "," + number(from.b, to.b, t, 1);
14103
14157
  const a = number(from.a, to.a, t);
14104
14158
  return a === 1 ? "rgb(" + rgb + ")" : "rgba(" + rgb + "," + a + ")";
14105
14159
  }
14106
14160
  function paint(from, to, t) {
14107
- return isString(from) && isString(to) ? color(from, to, t) : to;
14161
+ return (isString(from) || !from) && (isString(to) || !to) ? color(from, to, t) : to;
14108
14162
  }
14109
14163
  function shadow(from, to, t) {
14110
14164
  if (isArray(from) || isArray(to)) return to;
@@ -14868,6 +14922,7 @@ var LeaferUI = function(exports) {
14868
14922
  exports.emptyData = emptyData;
14869
14923
  exports.eraserType = eraserType;
14870
14924
  exports.extraPropertyEventMap = extraPropertyEventMap;
14925
+ exports.frameType = frameType;
14871
14926
  exports.getBoundsData = getBoundsData;
14872
14927
  exports.getDescriptor = getDescriptor;
14873
14928
  exports.getMatrixData = getMatrixData;
@@ -14881,6 +14936,7 @@ var LeaferUI = function(exports) {
14881
14936
  exports.isNumber = isNumber;
14882
14937
  exports.isObject = isObject;
14883
14938
  exports.isString = isString;
14939
+ exports.isTrackChanges = isTrackChanges;
14884
14940
  exports.isUndefined = isUndefined;
14885
14941
  exports.layoutProcessor = layoutProcessor;
14886
14942
  exports.leaferTransformAttrMap = leaferTransformAttrMap;