leafer-game 1.4.2 → 1.5.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
@@ -4073,12 +4073,11 @@ var LeaferUI = (function (exports) {
4073
4073
  if (defaultValue === undefined) {
4074
4074
  property.get = function () { return this[computedKey]; };
4075
4075
  }
4076
- else if (typeof defaultValue === 'object') {
4077
- const { clone } = DataHelper;
4076
+ else if (typeof defaultValue === 'function') {
4078
4077
  property.get = function () {
4079
4078
  let v = this[computedKey];
4080
4079
  if (v === undefined)
4081
- this[computedKey] = v = clone(defaultValue);
4080
+ this[computedKey] = v = defaultValue(this.__leaf);
4082
4081
  return v;
4083
4082
  };
4084
4083
  }
@@ -5725,10 +5724,10 @@ var LeaferUI = (function (exports) {
5725
5724
  static changeAttr(attrName, defaultValue, fn) {
5726
5725
  fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue);
5727
5726
  }
5728
- static addAttr(attrName, defaultValue, fn) {
5727
+ static addAttr(attrName, defaultValue, fn, helpValue) {
5729
5728
  if (!fn)
5730
5729
  fn = boundsType;
5731
- fn(defaultValue)(this.prototype, attrName);
5730
+ fn(defaultValue, helpValue)(this.prototype, attrName);
5732
5731
  }
5733
5732
  __emitLifeEvent(type) {
5734
5733
  if (this.hasEvent(type))
@@ -6055,7 +6054,7 @@ var LeaferUI = (function (exports) {
6055
6054
  }
6056
6055
  }
6057
6056
 
6058
- const version = "1.4.2";
6057
+ const version = "1.5.0";
6059
6058
 
6060
6059
  const debug$5 = Debug.get('LeaferCanvas');
6061
6060
  class LeaferCanvas extends LeaferCanvasBase {
@@ -7123,7 +7122,11 @@ var LeaferUI = (function (exports) {
7123
7122
  setStyleName() { return Plugin.need('state'); },
7124
7123
  set() { return Plugin.need('state'); }
7125
7124
  };
7126
- const Transition = {};
7125
+ const Transition = {
7126
+ list: {},
7127
+ register(attrName, fn) { Transition.list[attrName] = fn; },
7128
+ get(attrName) { return Transition.list[attrName]; }
7129
+ };
7127
7130
 
7128
7131
  const { parse, objectToCanvasData } = PathConvert;
7129
7132
  const emptyPaint = {};
@@ -7547,9 +7550,6 @@ var LeaferUI = (function (exports) {
7547
7550
  this.__drawPathByBox(pen);
7548
7551
  return pen;
7549
7552
  }
7550
- get editConfig() { return undefined; }
7551
- get editOuter() { return ''; }
7552
- get editInner() { return ''; }
7553
7553
  constructor(data) {
7554
7554
  super(data);
7555
7555
  }
@@ -7631,8 +7631,11 @@ var LeaferUI = (function (exports) {
7631
7631
  export(_filename, _options) {
7632
7632
  return Plugin.need('export');
7633
7633
  }
7634
+ syncExport(_filename, _options) {
7635
+ return Plugin.need('export');
7636
+ }
7634
7637
  clone(data) {
7635
- const json = this.toJSON();
7638
+ const json = DataHelper.clone(this.toJSON());
7636
7639
  if (data)
7637
7640
  Object.assign(json, data);
7638
7641
  return UI_1.one(json);
@@ -7931,7 +7934,7 @@ var LeaferUI = (function (exports) {
7931
7934
  get layoutLocked() { return !this.layouter.running; }
7932
7935
  get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7933
7936
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
7934
- get clientBounds() { return this.canvas && this.canvas.getClientBounds(); }
7937
+ get clientBounds() { return (this.canvas && this.canvas.getClientBounds(true)) || getBoundsData(); }
7935
7938
  constructor(userConfig, data) {
7936
7939
  super(data);
7937
7940
  this.config = {
@@ -8233,6 +8236,10 @@ var LeaferUI = (function (exports) {
8233
8236
  getPagePointByClient(clientPoint, updateClient) {
8234
8237
  return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
8235
8238
  }
8239
+ getClientPointByWorld(worldPoint) {
8240
+ const { x, y } = this.clientBounds;
8241
+ return { x: x + worldPoint.x, y: y + worldPoint.y };
8242
+ }
8236
8243
  updateClientBounds() {
8237
8244
  this.canvas && this.canvas.updateClientBounds();
8238
8245
  }
@@ -10201,8 +10208,6 @@ var LeaferUI = (function (exports) {
10201
10208
  h.setStrokeOptions(data);
10202
10209
  };
10203
10210
  ui$5.__hit = function (inner) {
10204
- if (Platform.name === 'miniapp')
10205
- this.__drawHitPath(this.__hitCanvas);
10206
10211
  const data = this.__;
10207
10212
  if (data.__isHitPixel && this.__hitPixel(inner))
10208
10213
  return true;
@@ -11866,13 +11871,14 @@ var LeaferUI = (function (exports) {
11866
11871
  }
11867
11872
 
11868
11873
  function layoutText(drawData, style) {
11869
- const { rows, bounds } = drawData;
11874
+ const { rows, bounds } = drawData, countRows = rows.length;
11870
11875
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
11871
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
11876
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
11872
11877
  let starY = __baseLine;
11873
11878
  if (__clipText && realHeight > height) {
11874
11879
  realHeight = Math.max(height, __lineHeight);
11875
- drawData.overflow = rows.length;
11880
+ if (countRows > 1)
11881
+ drawData.overflow = countRows;
11876
11882
  }
11877
11883
  else if (height || autoSizeAlign) {
11878
11884
  switch (verticalAlign) {
@@ -11884,7 +11890,7 @@ var LeaferUI = (function (exports) {
11884
11890
  }
11885
11891
  starY += y;
11886
11892
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
11887
- for (let i = 0, len = rows.length; i < len; i++) {
11893
+ for (let i = 0, len = countRows; i < len; i++) {
11888
11894
  row = rows[i];
11889
11895
  row.x = x;
11890
11896
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -11953,7 +11959,7 @@ var LeaferUI = (function (exports) {
11953
11959
  if (i === end && charRight < right) {
11954
11960
  break;
11955
11961
  }
11956
- else if (charRight < right && char.char !== ' ') {
11962
+ else if ((charRight < right && char.char !== ' ') || !i) {
11957
11963
  row.data.splice(i + 1);
11958
11964
  row.width -= char.width;
11959
11965
  break;
@@ -12543,17 +12549,17 @@ var LeaferUI = (function (exports) {
12543
12549
  State.updateStyle = updateStyle;
12544
12550
  State.updateEventStyle = updateEventStyle;
12545
12551
  const ui$3 = exports.UI.prototype;
12546
- stateType(false, 'selectedStyle')(ui$3, 'selected');
12547
- stateType(false, 'disabledStyle')(ui$3, 'disabled');
12548
- stateStyleType({})(ui$3, 'states');
12549
- stateType('')(ui$3, 'state');
12550
- dataType()(ui$3, 'normalStyle');
12551
- stateStyleType()(ui$3, 'hoverStyle');
12552
- stateStyleType()(ui$3, 'pressStyle');
12553
- stateStyleType()(ui$3, 'focusStyle');
12554
- stateStyleType()(ui$3, 'selectedStyle');
12555
- stateStyleType()(ui$3, 'disabledStyle');
12556
- dataType(false)(ui$3, 'button');
12552
+ exports.UI.addAttr('selected', false, stateType, 'selectedStyle');
12553
+ exports.UI.addAttr('disabled', false, stateType, 'disabledStyle');
12554
+ exports.UI.addAttr('states', {}, stateStyleType);
12555
+ exports.UI.addAttr('state', '', stateType);
12556
+ exports.UI.addAttr('normalStyle', undefined, dataType);
12557
+ exports.UI.addAttr('hoverStyle', undefined, stateStyleType);
12558
+ exports.UI.addAttr('pressStyle', undefined, stateStyleType);
12559
+ exports.UI.addAttr('focusStyle', undefined, stateStyleType);
12560
+ exports.UI.addAttr('selectedStyle', undefined, stateStyleType);
12561
+ exports.UI.addAttr('disabledStyle', undefined, stateStyleType);
12562
+ exports.UI.addAttr('button', false, dataType);
12557
12563
  ui$3.focus = function (value = true) {
12558
12564
  this.waitLeafer(() => {
12559
12565
  let { focusData } = this.app.interaction;
@@ -13518,7 +13524,6 @@ var LeaferUI = (function (exports) {
13518
13524
  innerShadow: shadow
13519
13525
  };
13520
13526
  const TransitionModule = {
13521
- list: TransitionList,
13522
13527
  value,
13523
13528
  number,
13524
13529
  color
@@ -13563,13 +13568,13 @@ var LeaferUI = (function (exports) {
13563
13568
 
13564
13569
  Plugin.add('animate', 'color');
13565
13570
  State.canAnimate = true;
13566
- Object.assign(Transition, Object.assign(Object.assign({}, TransitionModule), { register(attrName, fn) { Transition.list[attrName] = fn; },
13567
- get(attrName) { return Transition.list[attrName]; } }));
13571
+ Object.assign(Transition.list, TransitionList);
13572
+ Object.assign(Transition, TransitionModule);
13568
13573
  const ui$2 = exports.UI.prototype;
13569
- animationType()(ui$2, 'animation');
13570
- dataType()(ui$2, 'animationOut');
13571
- dataType(true)(ui$2, 'transition');
13572
- dataType()(ui$2, 'transitionOut');
13574
+ exports.UI.addAttr('animation', undefined, animationType);
13575
+ exports.UI.addAttr('animationOut', undefined, dataType);
13576
+ exports.UI.addAttr('transition', true, dataType);
13577
+ exports.UI.addAttr('transitionOut', undefined, dataType);
13573
13578
  ui$2.animate = function (keyframe, options, kill, isTemp) {
13574
13579
  if (keyframe === undefined)
13575
13580
  return this.__animate;
@@ -13743,7 +13748,7 @@ var LeaferUI = (function (exports) {
13743
13748
  toX = data[i + 1];
13744
13749
  toY = data[i + 2];
13745
13750
  distance = segments[index];
13746
- if (total + distance > motionDistance || !distanceData.total) {
13751
+ if (total + distance >= motionDistance || !distanceData.total) {
13747
13752
  if (!i)
13748
13753
  x = toX, y = toY;
13749
13754
  tempFrom.x = x;
@@ -13762,7 +13767,7 @@ var LeaferUI = (function (exports) {
13762
13767
  toX = data[i + 5];
13763
13768
  toY = data[i + 6];
13764
13769
  distance = segments[index];
13765
- if (total + distance > motionDistance) {
13770
+ if (total + distance >= motionDistance) {
13766
13771
  x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
13767
13772
  t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
13768
13773
  BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
@@ -13798,7 +13803,7 @@ var LeaferUI = (function (exports) {
13798
13803
  toX = data[i + 1];
13799
13804
  toY = data[i + 2];
13800
13805
  distance = segments[index];
13801
- if (total + distance > motionDistance || !distanceData.total) {
13806
+ if (total + distance >= motionDistance || !distanceData.total) {
13802
13807
  if (!i)
13803
13808
  x = toX, y = toY;
13804
13809
  tempFrom.x = x;
@@ -13819,7 +13824,7 @@ var LeaferUI = (function (exports) {
13819
13824
  toX = data[i + 5];
13820
13825
  toY = data[i + 6];
13821
13826
  distance = segments[index];
13822
- if (total + distance > motionDistance) {
13827
+ if (total + distance >= motionDistance) {
13823
13828
  t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
13824
13829
  HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
13825
13830
  return path;
@@ -13870,10 +13875,10 @@ var LeaferUI = (function (exports) {
13870
13875
  const ui$1 = exports.UI.prototype;
13871
13876
  const { updateMatrix, updateAllMatrix } = LeafHelper;
13872
13877
  const { updateBounds } = BranchHelper;
13873
- motionPathType()(ui$1, 'motionPath');
13874
- motionPathType(1)(ui$1, 'motionPrecision');
13875
- motionPathType()(ui$1, 'motion');
13876
- motionPathType(true)(ui$1, 'motionRotation');
13878
+ exports.UI.addAttr('motionPath', undefined, motionPathType);
13879
+ exports.UI.addAttr('motionPrecision', 1, motionPathType);
13880
+ exports.UI.addAttr('motion', undefined, motionPathType);
13881
+ exports.UI.addAttr('motionRotation', true, motionPathType);
13877
13882
  ui$1.getMotionPathData = function () {
13878
13883
  return getMotionPathData(getMotionPath(this));
13879
13884
  };