@leafer-game/worker 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
  class LeaferCanvas extends LeaferCanvasBase {
6058
6057
  get allowBackgroundColor() { return true; }
@@ -6939,7 +6938,11 @@ const State = {
6939
6938
  setStyleName() { return Plugin.need('state'); },
6940
6939
  set() { return Plugin.need('state'); }
6941
6940
  };
6942
- const Transition = {};
6941
+ const Transition = {
6942
+ list: {},
6943
+ register(attrName, fn) { Transition.list[attrName] = fn; },
6944
+ get(attrName) { return Transition.list[attrName]; }
6945
+ };
6943
6946
 
6944
6947
  const { parse, objectToCanvasData } = PathConvert;
6945
6948
  const emptyPaint = {};
@@ -7363,9 +7366,6 @@ let UI = UI_1 = class UI extends Leaf {
7363
7366
  this.__drawPathByBox(pen);
7364
7367
  return pen;
7365
7368
  }
7366
- get editConfig() { return undefined; }
7367
- get editOuter() { return ''; }
7368
- get editInner() { return ''; }
7369
7369
  constructor(data) {
7370
7370
  super(data);
7371
7371
  }
@@ -7447,8 +7447,11 @@ let UI = UI_1 = class UI extends Leaf {
7447
7447
  export(_filename, _options) {
7448
7448
  return Plugin.need('export');
7449
7449
  }
7450
+ syncExport(_filename, _options) {
7451
+ return Plugin.need('export');
7452
+ }
7450
7453
  clone(data) {
7451
- const json = this.toJSON();
7454
+ const json = DataHelper.clone(this.toJSON());
7452
7455
  if (data)
7453
7456
  Object.assign(json, data);
7454
7457
  return UI_1.one(json);
@@ -7747,7 +7750,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7747
7750
  get layoutLocked() { return !this.layouter.running; }
7748
7751
  get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7749
7752
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
7750
- get clientBounds() { return this.canvas && this.canvas.getClientBounds(); }
7753
+ get clientBounds() { return (this.canvas && this.canvas.getClientBounds(true)) || getBoundsData(); }
7751
7754
  constructor(userConfig, data) {
7752
7755
  super(data);
7753
7756
  this.config = {
@@ -8049,6 +8052,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8049
8052
  getPagePointByClient(clientPoint, updateClient) {
8050
8053
  return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
8051
8054
  }
8055
+ getClientPointByWorld(worldPoint) {
8056
+ const { x, y } = this.clientBounds;
8057
+ return { x: x + worldPoint.x, y: y + worldPoint.y };
8058
+ }
8052
8059
  updateClientBounds() {
8053
8060
  this.canvas && this.canvas.updateClientBounds();
8054
8061
  }
@@ -10017,8 +10024,6 @@ ui$5.__updateHitCanvas = function () {
10017
10024
  h.setStrokeOptions(data);
10018
10025
  };
10019
10026
  ui$5.__hit = function (inner) {
10020
- if (Platform.name === 'miniapp')
10021
- this.__drawHitPath(this.__hitCanvas);
10022
10027
  const data = this.__;
10023
10028
  if (data.__isHitPixel && this.__hitPixel(inner))
10024
10029
  return true;
@@ -11373,13 +11378,14 @@ function toChar(data, charX, rowData, isOverflow) {
11373
11378
  }
11374
11379
 
11375
11380
  function layoutText(drawData, style) {
11376
- const { rows, bounds } = drawData;
11381
+ const { rows, bounds } = drawData, countRows = rows.length;
11377
11382
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
11378
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
11383
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
11379
11384
  let starY = __baseLine;
11380
11385
  if (__clipText && realHeight > height) {
11381
11386
  realHeight = Math.max(height, __lineHeight);
11382
- drawData.overflow = rows.length;
11387
+ if (countRows > 1)
11388
+ drawData.overflow = countRows;
11383
11389
  }
11384
11390
  else if (height || autoSizeAlign) {
11385
11391
  switch (verticalAlign) {
@@ -11391,7 +11397,7 @@ function layoutText(drawData, style) {
11391
11397
  }
11392
11398
  starY += y;
11393
11399
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
11394
- for (let i = 0, len = rows.length; i < len; i++) {
11400
+ for (let i = 0, len = countRows; i < len; i++) {
11395
11401
  row = rows[i];
11396
11402
  row.x = x;
11397
11403
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -11460,7 +11466,7 @@ function clipText(drawData, style, x, width) {
11460
11466
  if (i === end && charRight < right) {
11461
11467
  break;
11462
11468
  }
11463
- else if (charRight < right && char.char !== ' ') {
11469
+ else if ((charRight < right && char.char !== ' ') || !i) {
11464
11470
  row.data.splice(i + 1);
11465
11471
  row.width -= char.width;
11466
11472
  break;
@@ -12050,17 +12056,17 @@ State.getStyle = getStyle;
12050
12056
  State.updateStyle = updateStyle;
12051
12057
  State.updateEventStyle = updateEventStyle;
12052
12058
  const ui$3 = UI.prototype;
12053
- stateType(false, 'selectedStyle')(ui$3, 'selected');
12054
- stateType(false, 'disabledStyle')(ui$3, 'disabled');
12055
- stateStyleType({})(ui$3, 'states');
12056
- stateType('')(ui$3, 'state');
12057
- dataType()(ui$3, 'normalStyle');
12058
- stateStyleType()(ui$3, 'hoverStyle');
12059
- stateStyleType()(ui$3, 'pressStyle');
12060
- stateStyleType()(ui$3, 'focusStyle');
12061
- stateStyleType()(ui$3, 'selectedStyle');
12062
- stateStyleType()(ui$3, 'disabledStyle');
12063
- dataType(false)(ui$3, 'button');
12059
+ UI.addAttr('selected', false, stateType, 'selectedStyle');
12060
+ UI.addAttr('disabled', false, stateType, 'disabledStyle');
12061
+ UI.addAttr('states', {}, stateStyleType);
12062
+ UI.addAttr('state', '', stateType);
12063
+ UI.addAttr('normalStyle', undefined, dataType);
12064
+ UI.addAttr('hoverStyle', undefined, stateStyleType);
12065
+ UI.addAttr('pressStyle', undefined, stateStyleType);
12066
+ UI.addAttr('focusStyle', undefined, stateStyleType);
12067
+ UI.addAttr('selectedStyle', undefined, stateStyleType);
12068
+ UI.addAttr('disabledStyle', undefined, stateStyleType);
12069
+ UI.addAttr('button', false, dataType);
12064
12070
  ui$3.focus = function (value = true) {
12065
12071
  this.waitLeafer(() => {
12066
12072
  let { focusData } = this.app.interaction;
@@ -13025,7 +13031,6 @@ const TransitionList = {
13025
13031
  innerShadow: shadow
13026
13032
  };
13027
13033
  const TransitionModule = {
13028
- list: TransitionList,
13029
13034
  value,
13030
13035
  number,
13031
13036
  color
@@ -13070,13 +13075,13 @@ function shadow(from, to, t) {
13070
13075
 
13071
13076
  Plugin.add('animate', 'color');
13072
13077
  State.canAnimate = true;
13073
- Object.assign(Transition, Object.assign(Object.assign({}, TransitionModule), { register(attrName, fn) { Transition.list[attrName] = fn; },
13074
- get(attrName) { return Transition.list[attrName]; } }));
13078
+ Object.assign(Transition.list, TransitionList);
13079
+ Object.assign(Transition, TransitionModule);
13075
13080
  const ui$2 = UI.prototype;
13076
- animationType()(ui$2, 'animation');
13077
- dataType()(ui$2, 'animationOut');
13078
- dataType(true)(ui$2, 'transition');
13079
- dataType()(ui$2, 'transitionOut');
13081
+ UI.addAttr('animation', undefined, animationType);
13082
+ UI.addAttr('animationOut', undefined, dataType);
13083
+ UI.addAttr('transition', true, dataType);
13084
+ UI.addAttr('transitionOut', undefined, dataType);
13080
13085
  ui$2.animate = function (keyframe, options, kill, isTemp) {
13081
13086
  if (keyframe === undefined)
13082
13087
  return this.__animate;
@@ -13250,7 +13255,7 @@ const HighCurveHelper = {
13250
13255
  toX = data[i + 1];
13251
13256
  toY = data[i + 2];
13252
13257
  distance = segments[index];
13253
- if (total + distance > motionDistance || !distanceData.total) {
13258
+ if (total + distance >= motionDistance || !distanceData.total) {
13254
13259
  if (!i)
13255
13260
  x = toX, y = toY;
13256
13261
  tempFrom.x = x;
@@ -13269,7 +13274,7 @@ const HighCurveHelper = {
13269
13274
  toX = data[i + 5];
13270
13275
  toY = data[i + 6];
13271
13276
  distance = segments[index];
13272
- if (total + distance > motionDistance) {
13277
+ if (total + distance >= motionDistance) {
13273
13278
  x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
13274
13279
  t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
13275
13280
  BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
@@ -13305,7 +13310,7 @@ const HighCurveHelper = {
13305
13310
  toX = data[i + 1];
13306
13311
  toY = data[i + 2];
13307
13312
  distance = segments[index];
13308
- if (total + distance > motionDistance || !distanceData.total) {
13313
+ if (total + distance >= motionDistance || !distanceData.total) {
13309
13314
  if (!i)
13310
13315
  x = toX, y = toY;
13311
13316
  tempFrom.x = x;
@@ -13326,7 +13331,7 @@ const HighCurveHelper = {
13326
13331
  toX = data[i + 5];
13327
13332
  toY = data[i + 6];
13328
13333
  distance = segments[index];
13329
- if (total + distance > motionDistance) {
13334
+ if (total + distance >= motionDistance) {
13330
13335
  t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
13331
13336
  HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
13332
13337
  return path;
@@ -13377,10 +13382,10 @@ Transition.register('motionRotation', function (from, to, t) {
13377
13382
  const ui$1 = UI.prototype;
13378
13383
  const { updateMatrix, updateAllMatrix } = LeafHelper;
13379
13384
  const { updateBounds } = BranchHelper;
13380
- motionPathType()(ui$1, 'motionPath');
13381
- motionPathType(1)(ui$1, 'motionPrecision');
13382
- motionPathType()(ui$1, 'motion');
13383
- motionPathType(true)(ui$1, 'motionRotation');
13385
+ UI.addAttr('motionPath', undefined, motionPathType);
13386
+ UI.addAttr('motionPrecision', 1, motionPathType);
13387
+ UI.addAttr('motion', undefined, motionPathType);
13388
+ UI.addAttr('motionRotation', true, motionPathType);
13384
13389
  ui$1.getMotionPathData = function () {
13385
13390
  return getMotionPathData(getMotionPath(this));
13386
13391
  };