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.
@@ -4070,12 +4070,11 @@ function defineDataProcessor(target, key, defaultValue) {
4070
4070
  if (defaultValue === undefined) {
4071
4071
  property.get = function () { return this[computedKey]; };
4072
4072
  }
4073
- else if (typeof defaultValue === 'object') {
4074
- const { clone } = DataHelper;
4073
+ else if (typeof defaultValue === 'function') {
4075
4074
  property.get = function () {
4076
4075
  let v = this[computedKey];
4077
4076
  if (v === undefined)
4078
- this[computedKey] = v = clone(defaultValue);
4077
+ this[computedKey] = v = defaultValue(this.__leaf);
4079
4078
  return v;
4080
4079
  };
4081
4080
  }
@@ -5722,10 +5721,10 @@ let Leaf = class Leaf {
5722
5721
  static changeAttr(attrName, defaultValue, fn) {
5723
5722
  fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue);
5724
5723
  }
5725
- static addAttr(attrName, defaultValue, fn) {
5724
+ static addAttr(attrName, defaultValue, fn, helpValue) {
5726
5725
  if (!fn)
5727
5726
  fn = boundsType;
5728
- fn(defaultValue)(this.prototype, attrName);
5727
+ fn(defaultValue, helpValue)(this.prototype, attrName);
5729
5728
  }
5730
5729
  __emitLifeEvent(type) {
5731
5730
  if (this.hasEvent(type))
@@ -6052,7 +6051,7 @@ class LeafLevelList {
6052
6051
  }
6053
6052
  }
6054
6053
 
6055
- const version = "1.4.2";
6054
+ const version = "1.5.0";
6056
6055
 
6057
6056
  const debug$5 = Debug.get('LeaferCanvas');
6058
6057
  class LeaferCanvas extends LeaferCanvasBase {
@@ -7120,7 +7119,11 @@ const State = {
7120
7119
  setStyleName() { return Plugin.need('state'); },
7121
7120
  set() { return Plugin.need('state'); }
7122
7121
  };
7123
- const Transition = {};
7122
+ const Transition = {
7123
+ list: {},
7124
+ register(attrName, fn) { Transition.list[attrName] = fn; },
7125
+ get(attrName) { return Transition.list[attrName]; }
7126
+ };
7124
7127
 
7125
7128
  const { parse, objectToCanvasData } = PathConvert;
7126
7129
  const emptyPaint = {};
@@ -7544,9 +7547,6 @@ let UI = UI_1 = class UI extends Leaf {
7544
7547
  this.__drawPathByBox(pen);
7545
7548
  return pen;
7546
7549
  }
7547
- get editConfig() { return undefined; }
7548
- get editOuter() { return ''; }
7549
- get editInner() { return ''; }
7550
7550
  constructor(data) {
7551
7551
  super(data);
7552
7552
  }
@@ -7628,8 +7628,11 @@ let UI = UI_1 = class UI extends Leaf {
7628
7628
  export(_filename, _options) {
7629
7629
  return Plugin.need('export');
7630
7630
  }
7631
+ syncExport(_filename, _options) {
7632
+ return Plugin.need('export');
7633
+ }
7631
7634
  clone(data) {
7632
- const json = this.toJSON();
7635
+ const json = DataHelper.clone(this.toJSON());
7633
7636
  if (data)
7634
7637
  Object.assign(json, data);
7635
7638
  return UI_1.one(json);
@@ -7928,7 +7931,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7928
7931
  get layoutLocked() { return !this.layouter.running; }
7929
7932
  get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7930
7933
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
7931
- get clientBounds() { return this.canvas && this.canvas.getClientBounds(); }
7934
+ get clientBounds() { return (this.canvas && this.canvas.getClientBounds(true)) || getBoundsData(); }
7932
7935
  constructor(userConfig, data) {
7933
7936
  super(data);
7934
7937
  this.config = {
@@ -8230,6 +8233,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8230
8233
  getPagePointByClient(clientPoint, updateClient) {
8231
8234
  return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
8232
8235
  }
8236
+ getClientPointByWorld(worldPoint) {
8237
+ const { x, y } = this.clientBounds;
8238
+ return { x: x + worldPoint.x, y: y + worldPoint.y };
8239
+ }
8233
8240
  updateClientBounds() {
8234
8241
  this.canvas && this.canvas.updateClientBounds();
8235
8242
  }
@@ -10198,8 +10205,6 @@ ui$5.__updateHitCanvas = function () {
10198
10205
  h.setStrokeOptions(data);
10199
10206
  };
10200
10207
  ui$5.__hit = function (inner) {
10201
- if (Platform.name === 'miniapp')
10202
- this.__drawHitPath(this.__hitCanvas);
10203
10208
  const data = this.__;
10204
10209
  if (data.__isHitPixel && this.__hitPixel(inner))
10205
10210
  return true;
@@ -11863,13 +11868,14 @@ function toChar(data, charX, rowData, isOverflow) {
11863
11868
  }
11864
11869
 
11865
11870
  function layoutText(drawData, style) {
11866
- const { rows, bounds } = drawData;
11871
+ const { rows, bounds } = drawData, countRows = rows.length;
11867
11872
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
11868
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
11873
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
11869
11874
  let starY = __baseLine;
11870
11875
  if (__clipText && realHeight > height) {
11871
11876
  realHeight = Math.max(height, __lineHeight);
11872
- drawData.overflow = rows.length;
11877
+ if (countRows > 1)
11878
+ drawData.overflow = countRows;
11873
11879
  }
11874
11880
  else if (height || autoSizeAlign) {
11875
11881
  switch (verticalAlign) {
@@ -11881,7 +11887,7 @@ function layoutText(drawData, style) {
11881
11887
  }
11882
11888
  starY += y;
11883
11889
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
11884
- for (let i = 0, len = rows.length; i < len; i++) {
11890
+ for (let i = 0, len = countRows; i < len; i++) {
11885
11891
  row = rows[i];
11886
11892
  row.x = x;
11887
11893
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -11950,7 +11956,7 @@ function clipText(drawData, style, x, width) {
11950
11956
  if (i === end && charRight < right) {
11951
11957
  break;
11952
11958
  }
11953
- else if (charRight < right && char.char !== ' ') {
11959
+ else if ((charRight < right && char.char !== ' ') || !i) {
11954
11960
  row.data.splice(i + 1);
11955
11961
  row.width -= char.width;
11956
11962
  break;
@@ -12540,17 +12546,17 @@ State.getStyle = getStyle;
12540
12546
  State.updateStyle = updateStyle;
12541
12547
  State.updateEventStyle = updateEventStyle;
12542
12548
  const ui$3 = UI.prototype;
12543
- stateType(false, 'selectedStyle')(ui$3, 'selected');
12544
- stateType(false, 'disabledStyle')(ui$3, 'disabled');
12545
- stateStyleType({})(ui$3, 'states');
12546
- stateType('')(ui$3, 'state');
12547
- dataType()(ui$3, 'normalStyle');
12548
- stateStyleType()(ui$3, 'hoverStyle');
12549
- stateStyleType()(ui$3, 'pressStyle');
12550
- stateStyleType()(ui$3, 'focusStyle');
12551
- stateStyleType()(ui$3, 'selectedStyle');
12552
- stateStyleType()(ui$3, 'disabledStyle');
12553
- dataType(false)(ui$3, 'button');
12549
+ UI.addAttr('selected', false, stateType, 'selectedStyle');
12550
+ UI.addAttr('disabled', false, stateType, 'disabledStyle');
12551
+ UI.addAttr('states', {}, stateStyleType);
12552
+ UI.addAttr('state', '', stateType);
12553
+ UI.addAttr('normalStyle', undefined, dataType);
12554
+ UI.addAttr('hoverStyle', undefined, stateStyleType);
12555
+ UI.addAttr('pressStyle', undefined, stateStyleType);
12556
+ UI.addAttr('focusStyle', undefined, stateStyleType);
12557
+ UI.addAttr('selectedStyle', undefined, stateStyleType);
12558
+ UI.addAttr('disabledStyle', undefined, stateStyleType);
12559
+ UI.addAttr('button', false, dataType);
12554
12560
  ui$3.focus = function (value = true) {
12555
12561
  this.waitLeafer(() => {
12556
12562
  let { focusData } = this.app.interaction;
@@ -13515,7 +13521,6 @@ const TransitionList = {
13515
13521
  innerShadow: shadow
13516
13522
  };
13517
13523
  const TransitionModule = {
13518
- list: TransitionList,
13519
13524
  value,
13520
13525
  number,
13521
13526
  color
@@ -13560,13 +13565,13 @@ function shadow(from, to, t) {
13560
13565
 
13561
13566
  Plugin.add('animate', 'color');
13562
13567
  State.canAnimate = true;
13563
- Object.assign(Transition, Object.assign(Object.assign({}, TransitionModule), { register(attrName, fn) { Transition.list[attrName] = fn; },
13564
- get(attrName) { return Transition.list[attrName]; } }));
13568
+ Object.assign(Transition.list, TransitionList);
13569
+ Object.assign(Transition, TransitionModule);
13565
13570
  const ui$2 = UI.prototype;
13566
- animationType()(ui$2, 'animation');
13567
- dataType()(ui$2, 'animationOut');
13568
- dataType(true)(ui$2, 'transition');
13569
- dataType()(ui$2, 'transitionOut');
13571
+ UI.addAttr('animation', undefined, animationType);
13572
+ UI.addAttr('animationOut', undefined, dataType);
13573
+ UI.addAttr('transition', true, dataType);
13574
+ UI.addAttr('transitionOut', undefined, dataType);
13570
13575
  ui$2.animate = function (keyframe, options, kill, isTemp) {
13571
13576
  if (keyframe === undefined)
13572
13577
  return this.__animate;
@@ -13740,7 +13745,7 @@ const HighCurveHelper = {
13740
13745
  toX = data[i + 1];
13741
13746
  toY = data[i + 2];
13742
13747
  distance = segments[index];
13743
- if (total + distance > motionDistance || !distanceData.total) {
13748
+ if (total + distance >= motionDistance || !distanceData.total) {
13744
13749
  if (!i)
13745
13750
  x = toX, y = toY;
13746
13751
  tempFrom.x = x;
@@ -13759,7 +13764,7 @@ const HighCurveHelper = {
13759
13764
  toX = data[i + 5];
13760
13765
  toY = data[i + 6];
13761
13766
  distance = segments[index];
13762
- if (total + distance > motionDistance) {
13767
+ if (total + distance >= motionDistance) {
13763
13768
  x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
13764
13769
  t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
13765
13770
  BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
@@ -13795,7 +13800,7 @@ const HighCurveHelper = {
13795
13800
  toX = data[i + 1];
13796
13801
  toY = data[i + 2];
13797
13802
  distance = segments[index];
13798
- if (total + distance > motionDistance || !distanceData.total) {
13803
+ if (total + distance >= motionDistance || !distanceData.total) {
13799
13804
  if (!i)
13800
13805
  x = toX, y = toY;
13801
13806
  tempFrom.x = x;
@@ -13816,7 +13821,7 @@ const HighCurveHelper = {
13816
13821
  toX = data[i + 5];
13817
13822
  toY = data[i + 6];
13818
13823
  distance = segments[index];
13819
- if (total + distance > motionDistance) {
13824
+ if (total + distance >= motionDistance) {
13820
13825
  t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
13821
13826
  HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
13822
13827
  return path;
@@ -13867,10 +13872,10 @@ Transition.register('motionRotation', function (from, to, t) {
13867
13872
  const ui$1 = UI.prototype;
13868
13873
  const { updateMatrix, updateAllMatrix } = LeafHelper;
13869
13874
  const { updateBounds } = BranchHelper;
13870
- motionPathType()(ui$1, 'motionPath');
13871
- motionPathType(1)(ui$1, 'motionPrecision');
13872
- motionPathType()(ui$1, 'motion');
13873
- motionPathType(true)(ui$1, 'motionRotation');
13875
+ UI.addAttr('motionPath', undefined, motionPathType);
13876
+ UI.addAttr('motionPrecision', 1, motionPathType);
13877
+ UI.addAttr('motion', undefined, motionPathType);
13878
+ UI.addAttr('motionRotation', true, motionPathType);
13874
13879
  ui$1.getMotionPathData = function () {
13875
13880
  return getMotionPathData(getMotionPath(this));
13876
13881
  };