@leafer-game/worker 1.4.2 → 1.5.1

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.
@@ -2029,13 +2029,11 @@ class LeaferCanvasBase extends Canvas$1 {
2029
2029
  this.worldTransform = {};
2030
2030
  if (!config)
2031
2031
  config = minSize;
2032
- if (!config.pixelRatio)
2033
- config.pixelRatio = Platform.devicePixelRatio;
2034
2032
  this.manager = manager;
2035
2033
  this.innerId = IncrementId.create(IncrementId.CNAVAS);
2036
2034
  const { width, height, pixelRatio } = config;
2037
2035
  this.autoLayout = !width || !height;
2038
- this.size.pixelRatio = pixelRatio;
2036
+ this.size.pixelRatio = pixelRatio | Platform.devicePixelRatio;
2039
2037
  this.config = config;
2040
2038
  this.init();
2041
2039
  }
@@ -2232,7 +2230,7 @@ class LeaferCanvasBase extends Canvas$1 {
2232
2230
  tempBounds$1.ceil();
2233
2231
  }
2234
2232
  isSameSize(size) {
2235
- return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
2233
+ return this.width === size.width && this.height === size.height && (!size.pixelRatio || this.pixelRatio === size.pixelRatio);
2236
2234
  }
2237
2235
  getSameCanvas(useSameWorldTransform, useSameSmooth) {
2238
2236
  const canvas = this.manager ? this.manager.get(this.size) : Creator.canvas(Object.assign({}, this.size));
@@ -4070,13 +4068,10 @@ function defineDataProcessor(target, key, defaultValue) {
4070
4068
  if (defaultValue === undefined) {
4071
4069
  property.get = function () { return this[computedKey]; };
4072
4070
  }
4073
- else if (typeof defaultValue === 'object') {
4074
- const { clone } = DataHelper;
4071
+ else if (typeof defaultValue === 'function') {
4075
4072
  property.get = function () {
4076
4073
  let v = this[computedKey];
4077
- if (v === undefined)
4078
- this[computedKey] = v = clone(defaultValue);
4079
- return v;
4074
+ return v === undefined ? defaultValue(this.__leaf) : v;
4080
4075
  };
4081
4076
  }
4082
4077
  if (key === 'width') {
@@ -5722,10 +5717,10 @@ let Leaf = class Leaf {
5722
5717
  static changeAttr(attrName, defaultValue, fn) {
5723
5718
  fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue);
5724
5719
  }
5725
- static addAttr(attrName, defaultValue, fn) {
5720
+ static addAttr(attrName, defaultValue, fn, helpValue) {
5726
5721
  if (!fn)
5727
5722
  fn = boundsType;
5728
- fn(defaultValue)(this.prototype, attrName);
5723
+ fn(defaultValue, helpValue)(this.prototype, attrName);
5729
5724
  }
5730
5725
  __emitLifeEvent(type) {
5731
5726
  if (this.hasEvent(type))
@@ -6052,7 +6047,7 @@ class LeafLevelList {
6052
6047
  }
6053
6048
  }
6054
6049
 
6055
- const version = "1.4.2";
6050
+ const version = "1.5.1";
6056
6051
 
6057
6052
  class LeaferCanvas extends LeaferCanvasBase {
6058
6053
  get allowBackgroundColor() { return true; }
@@ -6939,7 +6934,11 @@ const State = {
6939
6934
  setStyleName() { return Plugin.need('state'); },
6940
6935
  set() { return Plugin.need('state'); }
6941
6936
  };
6942
- const Transition = {};
6937
+ const Transition = {
6938
+ list: {},
6939
+ register(attrName, fn) { Transition.list[attrName] = fn; },
6940
+ get(attrName) { return Transition.list[attrName]; }
6941
+ };
6943
6942
 
6944
6943
  const { parse, objectToCanvasData } = PathConvert;
6945
6944
  const emptyPaint = {};
@@ -7363,9 +7362,6 @@ let UI = UI_1 = class UI extends Leaf {
7363
7362
  this.__drawPathByBox(pen);
7364
7363
  return pen;
7365
7364
  }
7366
- get editConfig() { return undefined; }
7367
- get editOuter() { return ''; }
7368
- get editInner() { return ''; }
7369
7365
  constructor(data) {
7370
7366
  super(data);
7371
7367
  }
@@ -7447,8 +7443,11 @@ let UI = UI_1 = class UI extends Leaf {
7447
7443
  export(_filename, _options) {
7448
7444
  return Plugin.need('export');
7449
7445
  }
7446
+ syncExport(_filename, _options) {
7447
+ return Plugin.need('export');
7448
+ }
7450
7449
  clone(data) {
7451
- const json = this.toJSON();
7450
+ const json = DataHelper.clone(this.toJSON());
7452
7451
  if (data)
7453
7452
  Object.assign(json, data);
7454
7453
  return UI_1.one(json);
@@ -7747,7 +7746,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7747
7746
  get layoutLocked() { return !this.layouter.running; }
7748
7747
  get FPS() { return this.renderer ? this.renderer.FPS : 60; }
7749
7748
  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(); }
7749
+ get clientBounds() { return (this.canvas && this.canvas.getClientBounds(true)) || getBoundsData(); }
7751
7750
  constructor(userConfig, data) {
7752
7751
  super(data);
7753
7752
  this.config = {
@@ -8049,6 +8048,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8049
8048
  getPagePointByClient(clientPoint, updateClient) {
8050
8049
  return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
8051
8050
  }
8051
+ getClientPointByWorld(worldPoint) {
8052
+ const { x, y } = this.clientBounds;
8053
+ return { x: x + worldPoint.x, y: y + worldPoint.y };
8054
+ }
8052
8055
  updateClientBounds() {
8053
8056
  this.canvas && this.canvas.updateClientBounds();
8054
8057
  }
@@ -10017,8 +10020,6 @@ ui$5.__updateHitCanvas = function () {
10017
10020
  h.setStrokeOptions(data);
10018
10021
  };
10019
10022
  ui$5.__hit = function (inner) {
10020
- if (Platform.name === 'miniapp')
10021
- this.__drawHitPath(this.__hitCanvas);
10022
10023
  const data = this.__;
10023
10024
  if (data.__isHitPixel && this.__hitPixel(inner))
10024
10025
  return true;
@@ -11373,13 +11374,14 @@ function toChar(data, charX, rowData, isOverflow) {
11373
11374
  }
11374
11375
 
11375
11376
  function layoutText(drawData, style) {
11376
- const { rows, bounds } = drawData;
11377
+ const { rows, bounds } = drawData, countRows = rows.length;
11377
11378
  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);
11379
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
11379
11380
  let starY = __baseLine;
11380
11381
  if (__clipText && realHeight > height) {
11381
11382
  realHeight = Math.max(height, __lineHeight);
11382
- drawData.overflow = rows.length;
11383
+ if (countRows > 1)
11384
+ drawData.overflow = countRows;
11383
11385
  }
11384
11386
  else if (height || autoSizeAlign) {
11385
11387
  switch (verticalAlign) {
@@ -11391,7 +11393,7 @@ function layoutText(drawData, style) {
11391
11393
  }
11392
11394
  starY += y;
11393
11395
  let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
11394
- for (let i = 0, len = rows.length; i < len; i++) {
11396
+ for (let i = 0, len = countRows; i < len; i++) {
11395
11397
  row = rows[i];
11396
11398
  row.x = x;
11397
11399
  if (row.width < width || (row.width > width && !__clipText)) {
@@ -11460,7 +11462,7 @@ function clipText(drawData, style, x, width) {
11460
11462
  if (i === end && charRight < right) {
11461
11463
  break;
11462
11464
  }
11463
- else if (charRight < right && char.char !== ' ') {
11465
+ else if ((charRight < right && char.char !== ' ') || !i) {
11464
11466
  row.data.splice(i + 1);
11465
11467
  row.width -= char.width;
11466
11468
  break;
@@ -12050,17 +12052,17 @@ State.getStyle = getStyle;
12050
12052
  State.updateStyle = updateStyle;
12051
12053
  State.updateEventStyle = updateEventStyle;
12052
12054
  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');
12055
+ UI.addAttr('selected', false, stateType, 'selectedStyle');
12056
+ UI.addAttr('disabled', false, stateType, 'disabledStyle');
12057
+ UI.addAttr('states', {}, stateStyleType);
12058
+ UI.addAttr('state', '', stateType);
12059
+ UI.addAttr('normalStyle', undefined, dataType);
12060
+ UI.addAttr('hoverStyle', undefined, stateStyleType);
12061
+ UI.addAttr('pressStyle', undefined, stateStyleType);
12062
+ UI.addAttr('focusStyle', undefined, stateStyleType);
12063
+ UI.addAttr('selectedStyle', undefined, stateStyleType);
12064
+ UI.addAttr('disabledStyle', undefined, stateStyleType);
12065
+ UI.addAttr('button', false, dataType);
12064
12066
  ui$3.focus = function (value = true) {
12065
12067
  this.waitLeafer(() => {
12066
12068
  let { focusData } = this.app.interaction;
@@ -13025,7 +13027,6 @@ const TransitionList = {
13025
13027
  innerShadow: shadow
13026
13028
  };
13027
13029
  const TransitionModule = {
13028
- list: TransitionList,
13029
13030
  value,
13030
13031
  number,
13031
13032
  color
@@ -13070,13 +13071,13 @@ function shadow(from, to, t) {
13070
13071
 
13071
13072
  Plugin.add('animate', 'color');
13072
13073
  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]; } }));
13074
+ Object.assign(Transition.list, TransitionList);
13075
+ Object.assign(Transition, TransitionModule);
13075
13076
  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');
13077
+ UI.addAttr('animation', undefined, animationType);
13078
+ UI.addAttr('animationOut', undefined, dataType);
13079
+ UI.addAttr('transition', true, dataType);
13080
+ UI.addAttr('transitionOut', undefined, dataType);
13080
13081
  ui$2.animate = function (keyframe, options, kill, isTemp) {
13081
13082
  if (keyframe === undefined)
13082
13083
  return this.__animate;
@@ -13250,7 +13251,7 @@ const HighCurveHelper = {
13250
13251
  toX = data[i + 1];
13251
13252
  toY = data[i + 2];
13252
13253
  distance = segments[index];
13253
- if (total + distance > motionDistance || !distanceData.total) {
13254
+ if (total + distance >= motionDistance || !distanceData.total) {
13254
13255
  if (!i)
13255
13256
  x = toX, y = toY;
13256
13257
  tempFrom.x = x;
@@ -13269,7 +13270,7 @@ const HighCurveHelper = {
13269
13270
  toX = data[i + 5];
13270
13271
  toY = data[i + 6];
13271
13272
  distance = segments[index];
13272
- if (total + distance > motionDistance) {
13273
+ if (total + distance >= motionDistance) {
13273
13274
  x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
13274
13275
  t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
13275
13276
  BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
@@ -13305,7 +13306,7 @@ const HighCurveHelper = {
13305
13306
  toX = data[i + 1];
13306
13307
  toY = data[i + 2];
13307
13308
  distance = segments[index];
13308
- if (total + distance > motionDistance || !distanceData.total) {
13309
+ if (total + distance >= motionDistance || !distanceData.total) {
13309
13310
  if (!i)
13310
13311
  x = toX, y = toY;
13311
13312
  tempFrom.x = x;
@@ -13326,7 +13327,7 @@ const HighCurveHelper = {
13326
13327
  toX = data[i + 5];
13327
13328
  toY = data[i + 6];
13328
13329
  distance = segments[index];
13329
- if (total + distance > motionDistance) {
13330
+ if (total + distance >= motionDistance) {
13330
13331
  t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
13331
13332
  HighBezierHelper.cut(path, t, x, y, x1, y1, x2, y2, toX, toY);
13332
13333
  return path;
@@ -13377,10 +13378,10 @@ Transition.register('motionRotation', function (from, to, t) {
13377
13378
  const ui$1 = UI.prototype;
13378
13379
  const { updateMatrix, updateAllMatrix } = LeafHelper;
13379
13380
  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');
13381
+ UI.addAttr('motionPath', undefined, motionPathType);
13382
+ UI.addAttr('motionPrecision', 1, motionPathType);
13383
+ UI.addAttr('motion', undefined, motionPathType);
13384
+ UI.addAttr('motionRotation', true, motionPathType);
13384
13385
  ui$1.getMotionPathData = function () {
13385
13386
  return getMotionPathData(getMotionPath(this));
13386
13387
  };