@leafer-game/miniapp 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.
@@ -817,6 +817,11 @@ const PointHelper = {
817
817
  toOuterOf(t, matrix, to) {
818
818
  toOuterPoint$3(matrix, t, to);
819
819
  },
820
+ toVertical(t, rotation, verticalDistance, to) {
821
+ const r = rotation * OneRadian;
822
+ t.x += -Math.sin(r) * verticalDistance;
823
+ t.y += Math.cos(r) * verticalDistance;
824
+ },
820
825
  getCenter(t, to) {
821
826
  return {
822
827
  x: t.x + (to.x - t.x) / 2,
@@ -1256,7 +1261,6 @@ const BoundsHelper = {
1256
1261
  },
1257
1262
  copyAndSpread(t, bounds, spread, isShrink, side) {
1258
1263
  const {x: x, y: y, width: width, height: height} = bounds;
1259
- if (!spread) spread = 0;
1260
1264
  if (isArray(spread)) {
1261
1265
  const four = fourNumber$1(spread);
1262
1266
  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
  class LeaferCanvas extends LeaferCanvasBase {
6991
6996
  get allowBackgroundColor() {
@@ -8688,8 +8693,9 @@ let UI = UI_1 = class UI extends Leaf {
8688
8693
  this.__drawPathByData(canvas, data.__pathForRender);
8689
8694
  }
8690
8695
  __drawPath(canvas) {
8696
+ const data = this.__;
8691
8697
  canvas.beginPath();
8692
- this.__drawPathByData(canvas, this.__.path, true);
8698
+ data.__usePointsMode ? PathDrawer.drawPathByPoints(canvas, data.points, data.closed) : this.__drawPathByData(canvas, data.path, true);
8693
8699
  }
8694
8700
  __drawPathByData(drawer, data, ignoreCornerRadius) {
8695
8701
  data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, ignoreCornerRadius);
@@ -9546,6 +9552,9 @@ let Polygon = class Polygon extends UI {
9546
9552
  get __tag() {
9547
9553
  return "Polygon";
9548
9554
  }
9555
+ get isPointsMode() {
9556
+ return this.points && !this.pathInputed;
9557
+ }
9549
9558
  __updatePath() {
9550
9559
  const data = this.__;
9551
9560
  const path = data.path = [];
@@ -9623,6 +9632,9 @@ let Line = class Line extends UI {
9623
9632
  get __tag() {
9624
9633
  return "Line";
9625
9634
  }
9635
+ get isPointsMode() {
9636
+ return this.points && !this.pathInputed;
9637
+ }
9626
9638
  get toPoint() {
9627
9639
  const {width: width, rotation: rotation} = this.__;
9628
9640
  const to = getPointData();
@@ -9781,7 +9793,7 @@ let Text = class Text extends UI {
9781
9793
  data.__font = `${italic ? "italic " : ""}${textCase === "small-caps" ? "small-caps " : ""}${fontWeight !== "normal" ? fontWeight + " " : ""}${fontSize || 12}px ${fontFamily || "caption"}`;
9782
9794
  stintSet$1(data, "__padding", padding && MathHelper.fourNumber(padding));
9783
9795
  stintSet$1(data, "__clipText", textOverflow !== "show" && !data.__autoSize);
9784
- stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || textCase !== "none");
9796
+ stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.motionText || textCase !== "none");
9785
9797
  data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === "") ? data.placeholder : data.text, this.__);
9786
9798
  }
9787
9799
  __updateBoxBounds() {
@@ -9806,7 +9818,7 @@ let Text = class Text extends UI {
9806
9818
  this.__updateNaturalSize();
9807
9819
  } else super.__updateBoxBounds();
9808
9820
  if (italic) b.width += fontSize * .16;
9809
- DataHelper.stintSet(this, "isOverflow", !includes(b, contentBounds));
9821
+ DataHelper.stintSet(this, "isOverflow", !includes(b, contentBounds) && !data.motionText);
9810
9822
  if (this.isOverflow) setList(data.__textBoxBounds = {}, [ b, contentBounds ]), layout.renderChanged = true; else data.__textBoxBounds = b;
9811
9823
  }
9812
9824
  __updateRenderSpread() {
@@ -11409,8 +11421,10 @@ ui$5.__hit = function(inner, forceHitFill) {
11409
11421
  if (!needHitFillPath && !needHitStrokePath) return false;
11410
11422
  const radiusWidth = inner.radiusX * 2;
11411
11423
  let hitWidth = radiusWidth;
11424
+ let {strokeAlign: strokeAlign} = data;
11425
+ if (data.motionText) hitWidth += data.fontSize / 2, strokeAlign = "center";
11412
11426
  if (needHitStrokePath) {
11413
- switch (data.strokeAlign) {
11427
+ switch (strokeAlign) {
11414
11428
  case "inside":
11415
11429
  hitWidth += strokeWidth * 2;
11416
11430
  if (!needHitFillPath && this.__hitFill(inner) && this.__hitStroke(inner, hitWidth)) return true;
@@ -11444,9 +11458,9 @@ rect.__hitFill = box$1.__hitFill = function(inner) {
11444
11458
  };
11445
11459
 
11446
11460
  Text.prototype.__drawHitPath = function(canvas) {
11447
- const {__lineHeight: __lineHeight, fontSize: fontSize, __baseLine: __baseLine, __letterSpacing: __letterSpacing, __textDrawData: data} = this.__;
11461
+ const data = this.__, {__lineHeight: __lineHeight, fontSize: fontSize, __baseLine: __baseLine, __letterSpacing: __letterSpacing, __textDrawData: drawData} = data;
11448
11462
  canvas.beginPath();
11449
- if (__letterSpacing < 0) this.__drawPathByBox(canvas); else data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
11463
+ 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));
11450
11464
  };
11451
11465
 
11452
11466
  Group.prototype.pick = function(hitPoint, options) {
@@ -11633,7 +11647,8 @@ function fillPathOrText(ui, canvas, renderOptions) {
11633
11647
  ui.__.__font ? Paint.fillText(ui, canvas, renderOptions) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
11634
11648
  }
11635
11649
 
11636
- function fillText(ui, canvas, _renderOptions) {
11650
+ function fillText(ui, canvas, renderOptions) {
11651
+ if (ui.motionText) return Paint.fillMotionText(ui, canvas, renderOptions);
11637
11652
  const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
11638
11653
  if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
11639
11654
  let row;
@@ -12995,7 +13010,8 @@ const TextMode = 2;
12995
13010
 
12996
13011
  function layoutChar(drawData, style, width, _height) {
12997
13012
  const {rows: rows} = drawData;
12998
- const {textAlign: textAlign, paraIndent: paraIndent, __letterSpacing: __letterSpacing} = style;
13013
+ const {textAlign: textAlign, paraIndent: paraIndent} = style;
13014
+ const useLetter = style.__letterSpacing || style.motionText;
12999
13015
  const justifyLast = width && textAlign.includes("both");
13000
13016
  const justify = justifyLast || width && textAlign.includes("justify");
13001
13017
  const justifyLetter = justify && textAlign.includes("letter");
@@ -13008,8 +13024,8 @@ function layoutChar(drawData, style, width, _height) {
13008
13024
  remainingWidth = width - row.width - indentWidth;
13009
13025
  if (justifyLetter) addLetterWidth = remainingWidth / (row.words.reduce((total, item) => total + item.data.length, 0) - 1); else addWordWidth = wordsLength > 1 ? remainingWidth / (wordsLength - 1) : 0;
13010
13026
  }
13011
- mode = __letterSpacing || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
13012
- if (row.isOverflow && !__letterSpacing) row.textMode = true;
13027
+ mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
13028
+ if (row.isOverflow && !useLetter) row.textMode = true;
13013
13029
  if (mode === TextMode) {
13014
13030
  row.x += indentWidth;
13015
13031
  toTextChar$1(row);
@@ -13210,6 +13226,7 @@ function getDrawData(content, style) {
13210
13226
  let width = style.__getInput("width") || 0;
13211
13227
  let height = style.__getInput("height") || 0;
13212
13228
  const {__padding: padding} = style;
13229
+ if (style.motionText) width = height = 0;
13213
13230
  if (padding) {
13214
13231
  if (width) x = padding[left], width -= padding[right] + padding[left], !width && (width = .01); else if (!style.autoSizeAlign) x = padding[left];
13215
13232
  if (height) y = padding[top], height -= padding[top] + padding[bottom], !height && (height = .01); else if (!style.autoSizeAlign) y = padding[top];
@@ -15010,7 +15027,7 @@ const HighCurveHelper = {
15010
15027
  },
15011
15028
  getMotionPathData(data) {
15012
15029
  let total = 0, distance, segments = [];
15013
- let i = 0, x = 0, y = 0, toX, toY, command;
15030
+ let i = 0, x = 0, y = 0, toX, toY, command, closed;
15014
15031
  const len = data.length;
15015
15032
  while (i < len) {
15016
15033
  command = data[i];
@@ -15035,6 +15052,7 @@ const HighCurveHelper = {
15035
15052
  break;
15036
15053
 
15037
15054
  case Z:
15055
+ closed = true;
15038
15056
  i += 1;
15039
15057
 
15040
15058
  default:
@@ -15046,13 +15064,16 @@ const HighCurveHelper = {
15046
15064
  return {
15047
15065
  total: total,
15048
15066
  segments: segments,
15049
- data: data
15067
+ data: data,
15068
+ closed: closed
15050
15069
  };
15051
15070
  },
15052
- getDistancePoint(distanceData, motionDistance, motionPrecision) {
15053
- const {segments: segments, data: data} = distanceData;
15054
- motionDistance = UnitConvert.number(motionDistance, distanceData.total);
15055
- let total = 0, distance, to = {};
15071
+ getDistancePoint(distanceData, motionDistance, motionPrecision, offsetX) {
15072
+ const {segments: segments, data: data, total: total} = distanceData;
15073
+ motionDistance = UnitConvert.number(motionDistance, total);
15074
+ if (offsetX) motionDistance += offsetX;
15075
+ if (motionDistance > total) motionDistance = motionDistance % total;
15076
+ let nowDistance = 0, distance, to = {};
15056
15077
  let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
15057
15078
  let x1, y1, x2, y2, t;
15058
15079
  const len = data.length;
@@ -15064,15 +15085,20 @@ const HighCurveHelper = {
15064
15085
  toX = data[i + 1];
15065
15086
  toY = data[i + 2];
15066
15087
  distance = segments[index];
15067
- if (total + distance >= motionDistance || !distanceData.total) {
15068
- if (!i) x = toX, y = toY;
15069
- tempFrom.x = x;
15070
- tempFrom.y = y;
15088
+ if (nowDistance + distance >= motionDistance || !distanceData.total) {
15071
15089
  to.x = toX;
15072
15090
  to.y = toY;
15073
- PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true);
15074
- to.rotation = PointHelper.getAngle(tempFrom, to);
15075
- return to;
15091
+ if (i) {
15092
+ tempFrom.x = x;
15093
+ tempFrom.y = y;
15094
+ PointHelper.getDistancePoint(tempFrom, to, motionDistance - nowDistance, true);
15095
+ to.rotation = PointHelper.getAngle(tempFrom, to);
15096
+ return to;
15097
+ } else {
15098
+ const nextPoint = HighCurveHelper.getDistancePoint(distanceData, motionPrecision, motionPrecision, offsetX);
15099
+ to.rotation = nextPoint.rotation;
15100
+ return to;
15101
+ }
15076
15102
  }
15077
15103
  x = toX;
15078
15104
  y = toY;
@@ -15083,9 +15109,9 @@ const HighCurveHelper = {
15083
15109
  toX = data[i + 5];
15084
15110
  toY = data[i + 6];
15085
15111
  distance = segments[index];
15086
- if (total + distance >= motionDistance) {
15112
+ if (nowDistance + distance >= motionDistance) {
15087
15113
  x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
15088
- t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
15114
+ t = HighBezierHelper.getT(motionDistance - nowDistance, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
15089
15115
  BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
15090
15116
  to.rotation = HighBezierHelper.getRotation(t, x, y, x1, y1, x2, y2, toX, toY);
15091
15117
  return to;
@@ -15102,7 +15128,7 @@ const HighCurveHelper = {
15102
15128
  distance = 0;
15103
15129
  }
15104
15130
  index++;
15105
- total += distance;
15131
+ nowDistance += distance;
15106
15132
  }
15107
15133
  return to;
15108
15134
  },
@@ -15201,26 +15227,57 @@ const {updateMatrix: updateMatrix, updateAllMatrix: updateAllMatrix} = LeafHelpe
15201
15227
 
15202
15228
  const {updateBounds: updateBounds} = BranchHelper;
15203
15229
 
15230
+ const {toVertical: toVertical} = PointHelper;
15231
+
15204
15232
  UI.addAttr("motionPath", undefined, motionPathType);
15205
15233
 
15206
15234
  UI.addAttr("motionPrecision", 1, motionPathType);
15207
15235
 
15208
15236
  UI.addAttr("motion", undefined, motionPathType);
15209
15237
 
15238
+ UI.addAttr("motionVertical", "below", motionPathType);
15239
+
15210
15240
  UI.addAttr("motionRotation", true, motionPathType);
15211
15241
 
15242
+ ui$1.getMotionPath = function() {
15243
+ return getMotionPath(this);
15244
+ };
15245
+
15212
15246
  ui$1.getMotionPathData = function() {
15213
15247
  return getMotionPathData(getMotionPath(this));
15214
15248
  };
15215
15249
 
15216
- ui$1.getMotionPoint = function(motionDistance) {
15217
- const path = getMotionPath(this);
15218
- const data = getMotionPathData(path);
15250
+ ui$1.getMotionContentHeight = function() {
15251
+ return this.__layout.boxBounds.height;
15252
+ };
15253
+
15254
+ ui$1.getMotionPoint = function(motionDistance, motionVertical, pathElement, offsetX = 0, offsetY = 0) {
15255
+ if (!pathElement) pathElement = getMotionPath(this);
15256
+ const data = getMotionPathData(pathElement);
15219
15257
  if (!data.total) return {};
15220
- const point = HighCurveHelper.getDistancePoint(data, motionDistance, path.motionPrecision);
15221
- MatrixHelper.toOuterPoint(path.localTransform, point);
15258
+ const point = HighCurveHelper.getDistancePoint(data, motionDistance, pathElement.motionPrecision, offsetX);
15222
15259
  const {motionRotation: motionRotation} = this;
15223
- if (motionRotation === false) delete point.rotation; else if (isNumber(motionRotation)) point.rotation += motionRotation;
15260
+ if (isNumber(motionRotation)) point.rotation += motionRotation;
15261
+ let verticalType, verticalOffset;
15262
+ if (isObject(motionVertical)) verticalType = motionVertical.type, verticalOffset = motionVertical.offset; else if (isNumber(motionVertical)) verticalOffset = motionVertical; else verticalType = motionVertical;
15263
+ if (verticalType !== "below" || offsetY) {
15264
+ const {rotation: rotation} = point, height = this.getMotionContentHeight();
15265
+ if (verticalOffset) offsetY += verticalType === "above" ? -verticalOffset : verticalOffset;
15266
+ switch (verticalType) {
15267
+ case "above":
15268
+ toVertical(point, rotation, -height + offsetY);
15269
+ break;
15270
+
15271
+ case "center":
15272
+ toVertical(point, rotation, -height / 2 + offsetY);
15273
+ break;
15274
+
15275
+ case "below":
15276
+ default:
15277
+ toVertical(point, rotation, offsetY);
15278
+ }
15279
+ }
15280
+ MatrixHelper.toOuterPoint(pathElement.localTransform, point);
15224
15281
  return point;
15225
15282
  };
15226
15283
 
@@ -15252,7 +15309,11 @@ function updateMotion(leaf) {
15252
15309
  const data = getMotionPathData(leaf);
15253
15310
  if (data.total) leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion, leaf.motionPrecision);
15254
15311
  } else {
15255
- leaf.set(leaf.getMotionPoint(motion));
15312
+ if (leaf.motionText) leaf.__updateMotionText(); else {
15313
+ const point = leaf.getMotionPoint(motion);
15314
+ if (leaf.motionRotation === false) delete point.rotation;
15315
+ leaf.set(point);
15316
+ }
15256
15317
  if (!leaf.__hasAutoLayout) {
15257
15318
  if (leaf.isBranch) updateAllMatrix(leaf), updateBounds(leaf, leaf); else updateMatrix(leaf);
15258
15319
  }
@@ -15274,7 +15335,8 @@ function getMotionPath(leaf) {
15274
15335
  function getMotionPathData(leaf) {
15275
15336
  const data = leaf.__;
15276
15337
  if (data.__pathForMotion) return data.__pathForMotion;
15277
- return data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true));
15338
+ const path = data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true));
15339
+ return path;
15278
15340
  }
15279
15341
 
15280
15342
  const {Yes: Yes, NoAndSkip: NoAndSkip, YesAndSkip: YesAndSkip} = Answer;