@leafer/miniapp 2.1.11 → 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$4(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,
@@ -6985,7 +6990,7 @@ class LeafLevelList {
6985
6990
  }
6986
6991
  }
6987
6992
 
6988
- const version = "2.1.11";
6993
+ const version = "2.2.0";
6989
6994
 
6990
6995
  class LeaferCanvas extends LeaferCanvasBase {
6991
6996
  get allowBackgroundColor() {
@@ -9788,7 +9793,7 @@ let Text = class Text extends UI {
9788
9793
  data.__font = `${italic ? "italic " : ""}${textCase === "small-caps" ? "small-caps " : ""}${fontWeight !== "normal" ? fontWeight + " " : ""}${fontSize || 12}px ${fontFamily || "caption"}`;
9789
9794
  stintSet$3(data, "__padding", padding && MathHelper.fourNumber(padding));
9790
9795
  stintSet$3(data, "__clipText", textOverflow !== "show" && !data.__autoSize);
9791
- stintSet$3(data, "__isCharMode", width || height || data.__letterSpacing || textCase !== "none");
9796
+ stintSet$3(data, "__isCharMode", width || height || data.__letterSpacing || data.motionText || textCase !== "none");
9792
9797
  data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === "") ? data.placeholder : data.text, this.__);
9793
9798
  }
9794
9799
  __updateBoxBounds() {
@@ -9813,7 +9818,7 @@ let Text = class Text extends UI {
9813
9818
  this.__updateNaturalSize();
9814
9819
  } else super.__updateBoxBounds();
9815
9820
  if (italic) b.width += fontSize * .16;
9816
- DataHelper.stintSet(this, "isOverflow", !includes(b, contentBounds));
9821
+ DataHelper.stintSet(this, "isOverflow", !includes(b, contentBounds) && !data.motionText);
9817
9822
  if (this.isOverflow) setList(data.__textBoxBounds = {}, [ b, contentBounds ]), layout.renderChanged = true; else data.__textBoxBounds = b;
9818
9823
  }
9819
9824
  __updateRenderSpread() {
@@ -11416,8 +11421,10 @@ ui$5.__hit = function(inner, forceHitFill) {
11416
11421
  if (!needHitFillPath && !needHitStrokePath) return false;
11417
11422
  const radiusWidth = inner.radiusX * 2;
11418
11423
  let hitWidth = radiusWidth;
11424
+ let {strokeAlign: strokeAlign} = data;
11425
+ if (data.motionText) hitWidth += data.fontSize / 2, strokeAlign = "center";
11419
11426
  if (needHitStrokePath) {
11420
- switch (data.strokeAlign) {
11427
+ switch (strokeAlign) {
11421
11428
  case "inside":
11422
11429
  hitWidth += strokeWidth * 2;
11423
11430
  if (!needHitFillPath && this.__hitFill(inner) && this.__hitStroke(inner, hitWidth)) return true;
@@ -11451,9 +11458,9 @@ rect.__hitFill = box$3.__hitFill = function(inner) {
11451
11458
  };
11452
11459
 
11453
11460
  Text.prototype.__drawHitPath = function(canvas) {
11454
- 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;
11455
11462
  canvas.beginPath();
11456
- 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));
11457
11464
  };
11458
11465
 
11459
11466
  Group.prototype.pick = function(hitPoint, options) {
@@ -11640,7 +11647,8 @@ function fillPathOrText(ui, canvas, renderOptions) {
11640
11647
  ui.__.__font ? Paint.fillText(ui, canvas, renderOptions) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
11641
11648
  }
11642
11649
 
11643
- function fillText(ui, canvas, _renderOptions) {
11650
+ function fillText(ui, canvas, renderOptions) {
11651
+ if (ui.motionText) return Paint.fillMotionText(ui, canvas, renderOptions);
11644
11652
  const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
11645
11653
  if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
11646
11654
  let row;
@@ -13002,7 +13010,8 @@ const TextMode = 2;
13002
13010
 
13003
13011
  function layoutChar(drawData, style, width, _height) {
13004
13012
  const {rows: rows} = drawData;
13005
- const {textAlign: textAlign, paraIndent: paraIndent, __letterSpacing: __letterSpacing} = style;
13013
+ const {textAlign: textAlign, paraIndent: paraIndent} = style;
13014
+ const useLetter = style.__letterSpacing || style.motionText;
13006
13015
  const justifyLast = width && textAlign.includes("both");
13007
13016
  const justify = justifyLast || width && textAlign.includes("justify");
13008
13017
  const justifyLetter = justify && textAlign.includes("letter");
@@ -13015,8 +13024,8 @@ function layoutChar(drawData, style, width, _height) {
13015
13024
  remainingWidth = width - row.width - indentWidth;
13016
13025
  if (justifyLetter) addLetterWidth = remainingWidth / (row.words.reduce((total, item) => total + item.data.length, 0) - 1); else addWordWidth = wordsLength > 1 ? remainingWidth / (wordsLength - 1) : 0;
13017
13026
  }
13018
- mode = __letterSpacing || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
13019
- 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;
13020
13029
  if (mode === TextMode) {
13021
13030
  row.x += indentWidth;
13022
13031
  toTextChar$1(row);
@@ -13217,6 +13226,7 @@ function getDrawData$1(content, style) {
13217
13226
  let width = style.__getInput("width") || 0;
13218
13227
  let height = style.__getInput("height") || 0;
13219
13228
  const {__padding: padding} = style;
13229
+ if (style.motionText) width = height = 0;
13220
13230
  if (padding) {
13221
13231
  if (width) x = padding[left$3], width -= padding[right$3] + padding[left$3], !width && (width = .01); else if (!style.autoSizeAlign) x = padding[left$3];
13222
13232
  if (height) y = padding[top$2], height -= padding[top$2] + padding[bottom$2], !height && (height = .01); else if (!style.autoSizeAlign) y = padding[top$2];
@@ -19111,7 +19121,7 @@ const HighCurveHelper = {
19111
19121
  },
19112
19122
  getMotionPathData(data) {
19113
19123
  let total = 0, distance, segments = [];
19114
- let i = 0, x = 0, y = 0, toX, toY, command;
19124
+ let i = 0, x = 0, y = 0, toX, toY, command, closed;
19115
19125
  const len = data.length;
19116
19126
  while (i < len) {
19117
19127
  command = data[i];
@@ -19136,6 +19146,7 @@ const HighCurveHelper = {
19136
19146
  break;
19137
19147
 
19138
19148
  case Z$1:
19149
+ closed = true;
19139
19150
  i += 1;
19140
19151
 
19141
19152
  default:
@@ -19147,13 +19158,16 @@ const HighCurveHelper = {
19147
19158
  return {
19148
19159
  total: total,
19149
19160
  segments: segments,
19150
- data: data
19161
+ data: data,
19162
+ closed: closed
19151
19163
  };
19152
19164
  },
19153
- getDistancePoint(distanceData, motionDistance, motionPrecision) {
19154
- const {segments: segments, data: data} = distanceData;
19155
- motionDistance = UnitConvert.number(motionDistance, distanceData.total);
19156
- let total = 0, distance, to = {};
19165
+ getDistancePoint(distanceData, motionDistance, motionPrecision, offsetX) {
19166
+ const {segments: segments, data: data, total: total} = distanceData;
19167
+ motionDistance = UnitConvert.number(motionDistance, total);
19168
+ if (offsetX) motionDistance += offsetX;
19169
+ if (motionDistance > total) motionDistance = motionDistance % total;
19170
+ let nowDistance = 0, distance, to = {};
19157
19171
  let i = 0, index = 0, x = 0, y = 0, toX, toY, command;
19158
19172
  let x1, y1, x2, y2, t;
19159
19173
  const len = data.length;
@@ -19165,15 +19179,20 @@ const HighCurveHelper = {
19165
19179
  toX = data[i + 1];
19166
19180
  toY = data[i + 2];
19167
19181
  distance = segments[index];
19168
- if (total + distance >= motionDistance || !distanceData.total) {
19169
- if (!i) x = toX, y = toY;
19170
- tempFrom.x = x;
19171
- tempFrom.y = y;
19182
+ if (nowDistance + distance >= motionDistance || !distanceData.total) {
19172
19183
  to.x = toX;
19173
19184
  to.y = toY;
19174
- PointHelper.getDistancePoint(tempFrom, to, motionDistance - total, true);
19175
- to.rotation = PointHelper.getAngle(tempFrom, to);
19176
- return to;
19185
+ if (i) {
19186
+ tempFrom.x = x;
19187
+ tempFrom.y = y;
19188
+ PointHelper.getDistancePoint(tempFrom, to, motionDistance - nowDistance, true);
19189
+ to.rotation = PointHelper.getAngle(tempFrom, to);
19190
+ return to;
19191
+ } else {
19192
+ const nextPoint = HighCurveHelper.getDistancePoint(distanceData, motionPrecision, motionPrecision, offsetX);
19193
+ to.rotation = nextPoint.rotation;
19194
+ return to;
19195
+ }
19177
19196
  }
19178
19197
  x = toX;
19179
19198
  y = toY;
@@ -19184,9 +19203,9 @@ const HighCurveHelper = {
19184
19203
  toX = data[i + 5];
19185
19204
  toY = data[i + 6];
19186
19205
  distance = segments[index];
19187
- if (total + distance >= motionDistance) {
19206
+ if (nowDistance + distance >= motionDistance) {
19188
19207
  x1 = data[i + 1], y1 = data[i + 2], x2 = data[i + 3], y2 = data[i + 4];
19189
- t = HighBezierHelper.getT(motionDistance - total, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
19208
+ t = HighBezierHelper.getT(motionDistance - nowDistance, distance, x, y, x1, y1, x2, y2, toX, toY, motionPrecision);
19190
19209
  BezierHelper.getPointAndSet(t, x, y, x1, y1, x2, y2, toX, toY, to);
19191
19210
  to.rotation = HighBezierHelper.getRotation(t, x, y, x1, y1, x2, y2, toX, toY);
19192
19211
  return to;
@@ -19203,7 +19222,7 @@ const HighCurveHelper = {
19203
19222
  distance = 0;
19204
19223
  }
19205
19224
  index++;
19206
- total += distance;
19225
+ nowDistance += distance;
19207
19226
  }
19208
19227
  return to;
19209
19228
  },
@@ -19302,26 +19321,57 @@ const {updateMatrix: updateMatrix, updateAllMatrix: updateAllMatrix} = LeafHelpe
19302
19321
 
19303
19322
  const {updateBounds: updateBounds} = BranchHelper;
19304
19323
 
19324
+ const {toVertical: toVertical} = PointHelper;
19325
+
19305
19326
  UI.addAttr("motionPath", undefined, motionPathType);
19306
19327
 
19307
19328
  UI.addAttr("motionPrecision", 1, motionPathType);
19308
19329
 
19309
19330
  UI.addAttr("motion", undefined, motionPathType);
19310
19331
 
19332
+ UI.addAttr("motionVertical", "below", motionPathType);
19333
+
19311
19334
  UI.addAttr("motionRotation", true, motionPathType);
19312
19335
 
19336
+ ui$2.getMotionPath = function() {
19337
+ return getMotionPath(this);
19338
+ };
19339
+
19313
19340
  ui$2.getMotionPathData = function() {
19314
19341
  return getMotionPathData(getMotionPath(this));
19315
19342
  };
19316
19343
 
19317
- ui$2.getMotionPoint = function(motionDistance) {
19318
- const path = getMotionPath(this);
19319
- const data = getMotionPathData(path);
19344
+ ui$2.getMotionContentHeight = function() {
19345
+ return this.__layout.boxBounds.height;
19346
+ };
19347
+
19348
+ ui$2.getMotionPoint = function(motionDistance, motionVertical, pathElement, offsetX = 0, offsetY = 0) {
19349
+ if (!pathElement) pathElement = getMotionPath(this);
19350
+ const data = getMotionPathData(pathElement);
19320
19351
  if (!data.total) return {};
19321
- const point = HighCurveHelper.getDistancePoint(data, motionDistance, path.motionPrecision);
19322
- MatrixHelper.toOuterPoint(path.localTransform, point);
19352
+ const point = HighCurveHelper.getDistancePoint(data, motionDistance, pathElement.motionPrecision, offsetX);
19323
19353
  const {motionRotation: motionRotation} = this;
19324
- if (motionRotation === false) delete point.rotation; else if (isNumber(motionRotation)) point.rotation += motionRotation;
19354
+ if (isNumber(motionRotation)) point.rotation += motionRotation;
19355
+ let verticalType, verticalOffset;
19356
+ if (isObject(motionVertical)) verticalType = motionVertical.type, verticalOffset = motionVertical.offset; else if (isNumber(motionVertical)) verticalOffset = motionVertical; else verticalType = motionVertical;
19357
+ if (verticalType !== "below" || offsetY) {
19358
+ const {rotation: rotation} = point, height = this.getMotionContentHeight();
19359
+ if (verticalOffset) offsetY += verticalType === "above" ? -verticalOffset : verticalOffset;
19360
+ switch (verticalType) {
19361
+ case "above":
19362
+ toVertical(point, rotation, -height + offsetY);
19363
+ break;
19364
+
19365
+ case "center":
19366
+ toVertical(point, rotation, -height / 2 + offsetY);
19367
+ break;
19368
+
19369
+ case "below":
19370
+ default:
19371
+ toVertical(point, rotation, offsetY);
19372
+ }
19373
+ }
19374
+ MatrixHelper.toOuterPoint(pathElement.localTransform, point);
19325
19375
  return point;
19326
19376
  };
19327
19377
 
@@ -19353,7 +19403,11 @@ function updateMotion(leaf) {
19353
19403
  const data = getMotionPathData(leaf);
19354
19404
  if (data.total) leaf.__.__pathForRender = HighCurveHelper.getDistancePath(data, motion, leaf.motionPrecision);
19355
19405
  } else {
19356
- leaf.set(leaf.getMotionPoint(motion));
19406
+ if (leaf.motionText) leaf.__updateMotionText(); else {
19407
+ const point = leaf.getMotionPoint(motion);
19408
+ if (leaf.motionRotation === false) delete point.rotation;
19409
+ leaf.set(point);
19410
+ }
19357
19411
  if (!leaf.__hasAutoLayout) {
19358
19412
  if (leaf.isBranch) updateAllMatrix(leaf), updateBounds(leaf, leaf); else updateMatrix(leaf);
19359
19413
  }
@@ -19375,7 +19429,8 @@ function getMotionPath(leaf) {
19375
19429
  function getMotionPathData(leaf) {
19376
19430
  const data = leaf.__;
19377
19431
  if (data.__pathForMotion) return data.__pathForMotion;
19378
- return data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true));
19432
+ const path = data.__pathForMotion = HighCurveHelper.getMotionPathData(leaf.getPath(true, true));
19433
+ return path;
19379
19434
  }
19380
19435
 
19381
19436
  function stateType(defaultValue, styleName) {