leafer-game 2.1.10 → 2.2.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.
@@ -856,6 +856,11 @@ const PointHelper = {
856
856
  toOuterOf(t, matrix, to) {
857
857
  toOuterPoint$3(matrix, t, to);
858
858
  },
859
+ toVertical(t, rotation, verticalDistance, to) {
860
+ const r = rotation * OneRadian;
861
+ t.x += -Math.sin(r) * verticalDistance;
862
+ t.y += Math.cos(r) * verticalDistance;
863
+ },
859
864
  getCenter(t, to) {
860
865
  return {
861
866
  x: t.x + (to.x - t.x) / 2,
@@ -1295,7 +1300,6 @@ const BoundsHelper = {
1295
1300
  },
1296
1301
  copyAndSpread(t, bounds, spread, isShrink, side) {
1297
1302
  const {x: x, y: y, width: width, height: height} = bounds;
1298
- if (!spread) spread = 0;
1299
1303
  if (isArray(spread)) {
1300
1304
  const four = fourNumber$1(spread);
1301
1305
  isShrink ? B.set(t, x + four[3], y + four[0], width - four[1] - four[3], height - four[2] - four[0]) : B.set(t, x - four[3], y - four[0], width + four[1] + four[3], height + four[2] + four[0]);
@@ -3577,7 +3581,8 @@ const PathDrawer = {
3577
3581
  return;
3578
3582
  }
3579
3583
  }
3580
- }
3584
+ },
3585
+ drawPathByPoints(_drawer, _points, _closed) {}
3581
3586
  };
3582
3587
 
3583
3588
  const {M: M$2, L: L$3, C: C$1, Q: Q, Z: Z$2, N: N, D: D$1, X: X, G: G, F: F$1, O: O, P: P, U: U} = PathCommandMap;
@@ -6985,7 +6990,7 @@ class LeafLevelList {
6985
6990
  }
6986
6991
  }
6987
6992
 
6988
- const version = "2.1.10";
6993
+ const version = "2.2.0";
6989
6994
 
6990
6995
  const debug$5 = Debug.get("LeaferCanvas");
6991
6996
 
@@ -8723,8 +8728,9 @@ let UI = UI_1 = class UI extends Leaf {
8723
8728
  this.__drawPathByData(canvas, data.__pathForRender);
8724
8729
  }
8725
8730
  __drawPath(canvas) {
8731
+ const data = this.__;
8726
8732
  canvas.beginPath();
8727
- this.__drawPathByData(canvas, this.__.path, true);
8733
+ data.__usePointsMode ? PathDrawer.drawPathByPoints(canvas, data.points, data.closed) : this.__drawPathByData(canvas, data.path, true);
8728
8734
  }
8729
8735
  __drawPathByData(drawer, data, ignoreCornerRadius) {
8730
8736
  data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, ignoreCornerRadius);
@@ -9581,6 +9587,9 @@ let Polygon = class Polygon extends UI {
9581
9587
  get __tag() {
9582
9588
  return "Polygon";
9583
9589
  }
9590
+ get isPointsMode() {
9591
+ return this.points && !this.pathInputed;
9592
+ }
9584
9593
  __updatePath() {
9585
9594
  const data = this.__;
9586
9595
  const path = data.path = [];
@@ -9658,6 +9667,9 @@ let Line = class Line extends UI {
9658
9667
  get __tag() {
9659
9668
  return "Line";
9660
9669
  }
9670
+ get isPointsMode() {
9671
+ return this.points && !this.pathInputed;
9672
+ }
9661
9673
  get toPoint() {
9662
9674
  const {width: width, rotation: rotation} = this.__;
9663
9675
  const to = getPointData();
@@ -9816,7 +9828,7 @@ let Text = class Text extends UI {
9816
9828
  data.__font = `${italic ? "italic " : ""}${textCase === "small-caps" ? "small-caps " : ""}${fontWeight !== "normal" ? fontWeight + " " : ""}${fontSize || 12}px ${fontFamily || "caption"}`;
9817
9829
  stintSet$1(data, "__padding", padding && MathHelper.fourNumber(padding));
9818
9830
  stintSet$1(data, "__clipText", textOverflow !== "show" && !data.__autoSize);
9819
- stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || textCase !== "none");
9831
+ stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.motionText || textCase !== "none");
9820
9832
  data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === "") ? data.placeholder : data.text, this.__);
9821
9833
  }
9822
9834
  __updateBoxBounds() {
@@ -9841,7 +9853,7 @@ let Text = class Text extends UI {
9841
9853
  this.__updateNaturalSize();
9842
9854
  } else super.__updateBoxBounds();
9843
9855
  if (italic) b.width += fontSize * .16;
9844
- DataHelper.stintSet(this, "isOverflow", !includes(b, contentBounds));
9856
+ DataHelper.stintSet(this, "isOverflow", !includes(b, contentBounds) && !data.motionText);
9845
9857
  if (this.isOverflow) setList(data.__textBoxBounds = {}, [ b, contentBounds ]), layout.renderChanged = true; else data.__textBoxBounds = b;
9846
9858
  }
9847
9859
  __updateRenderSpread() {
@@ -11444,8 +11456,10 @@ ui$5.__hit = function(inner, forceHitFill) {
11444
11456
  if (!needHitFillPath && !needHitStrokePath) return false;
11445
11457
  const radiusWidth = inner.radiusX * 2;
11446
11458
  let hitWidth = radiusWidth;
11459
+ let {strokeAlign: strokeAlign} = data;
11460
+ if (data.motionText) hitWidth += data.fontSize / 2, strokeAlign = "center";
11447
11461
  if (needHitStrokePath) {
11448
- switch (data.strokeAlign) {
11462
+ switch (strokeAlign) {
11449
11463
  case "inside":
11450
11464
  hitWidth += strokeWidth * 2;
11451
11465
  if (!needHitFillPath && this.__hitFill(inner) && this.__hitStroke(inner, hitWidth)) return true;
@@ -11479,9 +11493,9 @@ rect.__hitFill = box$1.__hitFill = function(inner) {
11479
11493
  };
11480
11494
 
11481
11495
  Text.prototype.__drawHitPath = function(canvas) {
11482
- const {__lineHeight: __lineHeight, fontSize: fontSize, __baseLine: __baseLine, __letterSpacing: __letterSpacing, __textDrawData: data} = this.__;
11496
+ const data = this.__, {__lineHeight: __lineHeight, fontSize: fontSize, __baseLine: __baseLine, __letterSpacing: __letterSpacing, __textDrawData: drawData} = data;
11483
11497
  canvas.beginPath();
11484
- if (__letterSpacing < 0) this.__drawPathByBox(canvas); else data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
11498
+ if (data.motionText) this.__drawPathByData(canvas, data.__pathForMotionText); else if (__letterSpacing < 0) this.__drawPathByBox(canvas); else drawData.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
11485
11499
  };
11486
11500
 
11487
11501
  Group.prototype.pick = function(hitPoint, options) {
@@ -11841,8 +11855,7 @@ class Interaction extends InteractionBase {
11841
11855
  destroy() {
11842
11856
  if (this.view) {
11843
11857
  super.destroy();
11844
- this.view = null;
11845
- this.touches = null;
11858
+ this.view = this.touches = null;
11846
11859
  }
11847
11860
  }
11848
11861
  }
@@ -11889,7 +11902,8 @@ function fillPathOrText(ui, canvas, renderOptions) {
11889
11902
  ui.__.__font ? Paint.fillText(ui, canvas, renderOptions) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
11890
11903
  }
11891
11904
 
11892
- function fillText(ui, canvas, _renderOptions) {
11905
+ function fillText(ui, canvas, renderOptions) {
11906
+ if (ui.motionText) return Paint.fillMotionText(ui, canvas, renderOptions);
11893
11907
  const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
11894
11908
  if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
11895
11909
  let row;
@@ -13251,7 +13265,8 @@ const TextMode = 2;
13251
13265
 
13252
13266
  function layoutChar(drawData, style, width, _height) {
13253
13267
  const {rows: rows} = drawData;
13254
- const {textAlign: textAlign, paraIndent: paraIndent, __letterSpacing: __letterSpacing} = style;
13268
+ const {textAlign: textAlign, paraIndent: paraIndent} = style;
13269
+ const useLetter = style.__letterSpacing || style.motionText;
13255
13270
  const justifyLast = width && textAlign.includes("both");
13256
13271
  const justify = justifyLast || width && textAlign.includes("justify");
13257
13272
  const justifyLetter = justify && textAlign.includes("letter");
@@ -13264,8 +13279,8 @@ function layoutChar(drawData, style, width, _height) {
13264
13279
  remainingWidth = width - row.width - indentWidth;
13265
13280
  if (justifyLetter) addLetterWidth = remainingWidth / (row.words.reduce((total, item) => total + item.data.length, 0) - 1); else addWordWidth = wordsLength > 1 ? remainingWidth / (wordsLength - 1) : 0;
13266
13281
  }
13267
- mode = __letterSpacing || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
13268
- if (row.isOverflow && !__letterSpacing) row.textMode = true;
13282
+ mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
13283
+ if (row.isOverflow && !useLetter) row.textMode = true;
13269
13284
  if (mode === TextMode) {
13270
13285
  row.x += indentWidth;
13271
13286
  toTextChar$1(row);
@@ -13466,6 +13481,7 @@ function getDrawData(content, style) {
13466
13481
  let width = style.__getInput("width") || 0;
13467
13482
  let height = style.__getInput("height") || 0;
13468
13483
  const {__padding: padding} = style;
13484
+ if (style.motionText) width = height = 0;
13469
13485
  if (padding) {
13470
13486
  if (width) x = padding[left], width -= padding[right] + padding[left], !width && (width = .01); else if (!style.autoSizeAlign) x = padding[left];
13471
13487
  if (height) y = padding[top], height -= padding[top] + padding[bottom], !height && (height = .01); else if (!style.autoSizeAlign) y = padding[top];
@@ -15260,7 +15276,7 @@ const HighCurveHelper = {
15260
15276
  },
15261
15277
  getMotionPathData(data) {
15262
15278
  let total = 0, distance, segments = [];
15263
- let i = 0, x = 0, y = 0, toX, toY, command;
15279
+ let i = 0, x = 0, y = 0, toX, toY, command, closed;
15264
15280
  const len = data.length;
15265
15281
  while (i < len) {
15266
15282
  command = data[i];
@@ -15285,6 +15301,7 @@ const HighCurveHelper = {
15285
15301
  break;
15286
15302
 
15287
15303
  case Z:
15304
+ closed = true;
15288
15305
  i += 1;
15289
15306
 
15290
15307
  default:
@@ -15296,13 +15313,16 @@ const HighCurveHelper = {
15296
15313
  return {
15297
15314
  total: total,
15298
15315
  segments: segments,
15299
- data: data
15316
+ data: data,
15317
+ closed: closed
15300
15318
  };
15301
15319
  },
15302
- getDistancePoint(distanceData, motionDistance, motionPrecision) {
15303
- const {segments: segments, data: data} = distanceData;
15304
- motionDistance = UnitConvert.number(motionDistance, distanceData.total);
15305
- let total = 0, distance, to = {};
15320
+ getDistancePoint(distanceData, motionDistance, motionPrecision, offsetX) {
15321
+ const {segments: segments, data: data, total: total} = distanceData;
15322
+ motionDistance = UnitConvert.number(motionDistance, total);
15323
+ if (offsetX) motionDistance += offsetX;
15324
+ if (motionDistance > total) motionDistance = motionDistance % total;
15325
+ let nowDistance = 0, distance, to = {};
15306
15326
  let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
15307
15327
  let x1, y1, x2, y2, t;
15308
15328
  const len = data.length;
@@ -15314,15 +15334,20 @@ const HighCurveHelper = {
15314
15334
  toX = data[i + 1];
15315
15335
  toY = data[i + 2];
15316
15336
  distance = segments[index];
15317
- if (total + distance >= motionDistance || !distanceData.total) {
15318
- if (!i) x = toX, y = toY;
15319
- tempFrom.x = x;
15320
- tempFrom.y = y;
15337
+ if (nowDistance + distance >= motionDistance || !distanceData.total) {
15321
15338
  to.x = toX;
15322
15339
  to.y = toY;
15323
- PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true);
15324
- to.rotation = PointHelper.getAngle(tempFrom, to);
15325
- return to;
15340
+ if (i) {
15341
+ tempFrom.x = x;
15342
+ tempFrom.y = y;
15343
+ PointHelper.getDistancePoint(tempFrom, to, motionDistance - nowDistance, true);
15344
+ to.rotation = PointHelper.getAngle(tempFrom, to);
15345
+ return to;
15346
+ } else {
15347
+ const nextPoint = HighCurveHelper.getDistancePoint(distanceData, motionPrecision, motionPrecision, offsetX);
15348
+ to.rotation = nextPoint.rotation;
15349
+ return to;
15350
+ }
15326
15351
  }
15327
15352
  x = toX;
15328
15353
  y = toY;
@@ -15333,9 +15358,9 @@ const HighCurveHelper = {
15333
15358
  toX = data[i + 5];
15334
15359
  toY = data[i + 6];
15335
15360
  distance = segments[index];
15336
- if (total + distance >= motionDistance) {
15361
+ if (nowDistance + distance >= motionDistance) {
15337
15362
  x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
15338
- t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
15363
+ t = HighBezierHelper.getT(motionDistance - nowDistance, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
15339
15364
  BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
15340
15365
  to.rotation = HighBezierHelper.getRotation(t, x, y, x1, y1, x2, y2, toX, toY);
15341
15366
  return to;
@@ -15352,7 +15377,7 @@ const HighCurveHelper = {
15352
15377
  distance = 0;
15353
15378
  }
15354
15379
  index++;
15355
- total += distance;
15380
+ nowDistance += distance;
15356
15381
  }
15357
15382
  return to;
15358
15383
  },
@@ -15451,26 +15476,57 @@ const {updateMatrix: updateMatrix, updateAllMatrix: updateAllMatrix} = LeafHelpe
15451
15476
 
15452
15477
  const {updateBounds: updateBounds} = BranchHelper;
15453
15478
 
15479
+ const {toVertical: toVertical} = PointHelper;
15480
+
15454
15481
  UI.addAttr("motionPath", undefined, motionPathType);
15455
15482
 
15456
15483
  UI.addAttr("motionPrecision", 1, motionPathType);
15457
15484
 
15458
15485
  UI.addAttr("motion", undefined, motionPathType);
15459
15486
 
15487
+ UI.addAttr("motionVertical", "below", motionPathType);
15488
+
15460
15489
  UI.addAttr("motionRotation", true, motionPathType);
15461
15490
 
15491
+ ui$1.getMotionPath = function() {
15492
+ return getMotionPath(this);
15493
+ };
15494
+
15462
15495
  ui$1.getMotionPathData = function() {
15463
15496
  return getMotionPathData(getMotionPath(this));
15464
15497
  };
15465
15498
 
15466
- ui$1.getMotionPoint = function(motionDistance) {
15467
- const path = getMotionPath(this);
15468
- const data = getMotionPathData(path);
15499
+ ui$1.getMotionContentHeight = function() {
15500
+ return this.__layout.boxBounds.height;
15501
+ };
15502
+
15503
+ ui$1.getMotionPoint = function(motionDistance, motionVertical, pathElement, offsetX = 0, offsetY = 0) {
15504
+ if (!pathElement) pathElement = getMotionPath(this);
15505
+ const data = getMotionPathData(pathElement);
15469
15506
  if (!data.total) return {};
15470
- const point = HighCurveHelper.getDistancePoint(data, motionDistance, path.motionPrecision);
15471
- MatrixHelper.toOuterPoint(path.localTransform, point);
15507
+ const point = HighCurveHelper.getDistancePoint(data, motionDistance, pathElement.motionPrecision, offsetX);
15472
15508
  const {motionRotation: motionRotation} = this;
15473
- if (motionRotation === false) delete point.rotation; else if (isNumber(motionRotation)) point.rotation += motionRotation;
15509
+ if (isNumber(motionRotation)) point.rotation += motionRotation;
15510
+ let verticalType, verticalOffset;
15511
+ if (isObject(motionVertical)) verticalType = motionVertical.type, verticalOffset = motionVertical.offset; else if (isNumber(motionVertical)) verticalOffset = motionVertical; else verticalType = motionVertical;
15512
+ if (verticalType !== "below" || offsetY) {
15513
+ const {rotation: rotation} = point, height = this.getMotionContentHeight();
15514
+ if (verticalOffset) offsetY += verticalType === "above" ? -verticalOffset : verticalOffset;
15515
+ switch (verticalType) {
15516
+ case "above":
15517
+ toVertical(point, rotation, -height + offsetY);
15518
+ break;
15519
+
15520
+ case "center":
15521
+ toVertical(point, rotation, -height / 2 + offsetY);
15522
+ break;
15523
+
15524
+ case "below":
15525
+ default:
15526
+ toVertical(point, rotation, offsetY);
15527
+ }
15528
+ }
15529
+ MatrixHelper.toOuterPoint(pathElement.localTransform, point);
15474
15530
  return point;
15475
15531
  };
15476
15532
 
@@ -15502,7 +15558,11 @@ function updateMotion(leaf) {
15502
15558
  const data = getMotionPathData(leaf);
15503
15559
  if (data.total) leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion, leaf.motionPrecision);
15504
15560
  } else {
15505
- leaf.set(leaf.getMotionPoint(motion));
15561
+ if (leaf.motionText) leaf.__updateMotionText(); else {
15562
+ const point = leaf.getMotionPoint(motion);
15563
+ if (leaf.motionRotation === false) delete point.rotation;
15564
+ leaf.set(point);
15565
+ }
15506
15566
  if (!leaf.__hasAutoLayout) {
15507
15567
  if (leaf.isBranch) updateAllMatrix(leaf), updateBounds(leaf, leaf); else updateMatrix(leaf);
15508
15568
  }
@@ -15524,7 +15584,8 @@ function getMotionPath(leaf) {
15524
15584
  function getMotionPathData(leaf) {
15525
15585
  const data = leaf.__;
15526
15586
  if (data.__pathForMotion) return data.__pathForMotion;
15527
- return data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true));
15587
+ const path = data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true));
15588
+ return path;
15528
15589
  }
15529
15590
 
15530
15591
  const {Yes: Yes, NoAndSkip: NoAndSkip, YesAndSkip: YesAndSkip} = Answer;