@leafer/miniapp 2.1.0 → 2.1.2

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.
@@ -3070,7 +3070,7 @@ const PathConvert = {
3070
3070
  return needConvert ? PathConvert.toCanvasData(data, curveMode) : data;
3071
3071
  },
3072
3072
  toCanvasData(old, curveMode) {
3073
- let x = 0, y = 0, x1 = 0, y1 = 0, i = 0, len = old.length, controlX, controlY, command, lastCommand, smooth;
3073
+ let x = 0, y = 0, x1 = 0, y1 = 0, startX = 0, startY = 0, i = 0, len = old.length, controlX, controlY, command, lastCommand, smooth;
3074
3074
  const data = [];
3075
3075
  while (i < len) {
3076
3076
  command = old[i];
@@ -3082,7 +3082,8 @@ const PathConvert = {
3082
3082
  case M$a:
3083
3083
  x = old[i + 1];
3084
3084
  y = old[i + 2];
3085
- data.push(M$a, x, y);
3085
+ if (lastCommand === command) data.push(L$a, x, y); else data.push(M$a, x, y), startX = x,
3086
+ startY = y;
3086
3087
  i += 3;
3087
3088
  break;
3088
3089
 
@@ -3197,6 +3198,8 @@ const PathConvert = {
3197
3198
  case z:
3198
3199
  case Z$8:
3199
3200
  data.push(Z$8);
3201
+ x = startX;
3202
+ y = startY;
3200
3203
  i++;
3201
3204
  break;
3202
3205
 
@@ -6075,12 +6078,13 @@ const LeafBounds = {
6075
6078
  if (this.__hasWorldEvent) BoundsEvent.emitWorld(this);
6076
6079
  },
6077
6080
  __updateLocalBounds() {
6078
- const layout = this.__layout;
6081
+ const layout = this.__layout, data = this.__;
6079
6082
  if (layout.boxChanged) {
6080
- if (!this.__.__pathInputed) this.__updatePath();
6083
+ if (!data.__pathInputed) this.__updatePath();
6081
6084
  this.__updateRenderPath();
6082
6085
  this.__updateBoxBounds();
6083
6086
  layout.resized = "inner";
6087
+ if (data.__strokeGeometry) data.__strokeGeometry = undefined;
6084
6088
  }
6085
6089
  if (layout.localBoxChanged) {
6086
6090
  if (this.__local) this.__updateLocalBoxBounds();
@@ -6103,6 +6107,7 @@ const LeafBounds = {
6103
6107
  if (layout.renderSpread || layout.strokeSpread !== layout.strokeBoxSpread) layout.renderChanged = true;
6104
6108
  if (this.parent) this.parent.__layout.strokeChange();
6105
6109
  layout.resized = "inner";
6110
+ if (data.__strokeGeometry) data.__strokeGeometry = undefined;
6106
6111
  }
6107
6112
  if (layout.renderChanged) {
6108
6113
  layout.renderSpread = this.__updateRenderSpread();
@@ -7079,7 +7084,7 @@ class LeafLevelList {
7079
7084
  }
7080
7085
  }
7081
7086
 
7082
- const version = "2.1.0";
7087
+ const version = "2.1.2";
7083
7088
 
7084
7089
  class LeaferCanvas extends LeaferCanvasBase {
7085
7090
  get allowBackgroundColor() {
@@ -8313,7 +8318,7 @@ class UIData extends LeafData {
8313
8318
  const isStr = isString(value);
8314
8319
  if (isStr || value && isObject(value[0])) {
8315
8320
  this.__setInput("path", value);
8316
- this._path = isStr ? parse(value) : objectToCanvasData(value);
8321
+ this._path = isStr ? parse(value, this.__useArrow) : objectToCanvasData(value);
8317
8322
  } else {
8318
8323
  if (this.__input) this.__removeInput("path");
8319
8324
  this._path = value;
@@ -8428,7 +8433,11 @@ class EllipseData extends UIData {
8428
8433
  }
8429
8434
  }
8430
8435
 
8431
- class PolygonData extends LineData {}
8436
+ class PolygonData extends UIData {
8437
+ get __usePathBox() {
8438
+ return this.points || this.__pathInputed;
8439
+ }
8440
+ }
8432
8441
 
8433
8442
  class StarData extends UIData {
8434
8443
  get __boxStroke() {
@@ -8539,7 +8548,7 @@ const UIBounds = {
8539
8548
  if ((data.stroke || data.hitStroke === "all") && strokeWidth && strokeAlign !== "inside") {
8540
8549
  boxSpread = spread = strokeAlign === "center" ? strokeWidth / 2 : strokeWidth;
8541
8550
  if (!data.__boxStroke || data.__useArrow) {
8542
- const miterLimitAddWidth = data.__isLinePath ? 0 : 10 * spread;
8551
+ const miterLimitAddWidth = data.__isLinePath ? 0 : (data.strokeJoin === "miter" ? 10 : 1) * spread;
8543
8552
  const storkeCapAddWidth = data.strokeCap === "none" ? 0 : strokeWidth;
8544
8553
  spread += Math.max(miterLimitAddWidth, storkeCapAddWidth);
8545
8554
  }
@@ -9843,7 +9852,7 @@ __decorate([ resizeType() ], Canvas.prototype, "contextSettings", void 0);
9843
9852
 
9844
9853
  Canvas = __decorate([ registerUI() ], Canvas);
9845
9854
 
9846
- const {copyAndSpread: copyAndSpread$3, includes: includes, spread: spread, setList: setList} = BoundsHelper, {stintSet: stintSet$3} = DataHelper;
9855
+ const {copyAndSpread: copyAndSpread$3, includes: includes, setList: setList} = BoundsHelper, {stintSet: stintSet$3} = DataHelper;
9847
9856
 
9848
9857
  let Text = class Text extends UI {
9849
9858
  get __tag() {
@@ -9873,7 +9882,7 @@ let Text = class Text extends UI {
9873
9882
  const {bounds: contentBounds} = data.__textDrawData;
9874
9883
  const b = layout.boxBounds;
9875
9884
  layout.contentBounds = contentBounds;
9876
- if (data.__lineHeight < fontSize) spread(contentBounds, fontSize / 2);
9885
+ if (data.__lineHeight < fontSize) layout.renderChanged = true;
9877
9886
  if (autoWidth || autoHeight) {
9878
9887
  b.x = autoWidth ? contentBounds.x : 0;
9879
9888
  b.y = autoHeight ? contentBounds.y : 0;
@@ -9893,6 +9902,8 @@ let Text = class Text extends UI {
9893
9902
  __updateRenderSpread() {
9894
9903
  let spread = super.__updateRenderSpread();
9895
9904
  if (!spread) spread = this.isOverflow ? 1 : 0;
9905
+ const {__lineHeight: __lineHeight, fontSize: fontSize} = this.__;
9906
+ if (__lineHeight < fontSize) spread = FourNumberHelper.max(spread, (fontSize - __lineHeight) / 2);
9896
9907
  return spread;
9897
9908
  }
9898
9909
  __updateRenderBounds() {
@@ -11978,8 +11989,8 @@ function compute(attrName, ui) {
11978
11989
  }
11979
11990
  }
11980
11991
  }
11981
- data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
11982
11992
  if (leafPaints.length) {
11993
+ data["_" + attrName] = leafPaints;
11983
11994
  if (leafPaints.every(item => item.isTransparent)) {
11984
11995
  if (leafPaints.some(item => item.image)) isAlphaPixel = true;
11985
11996
  isTransparent = true;
@@ -11994,6 +12005,7 @@ function compute(attrName, ui) {
11994
12005
  }
11995
12006
  } else {
11996
12007
  data.__removePaint(attrName, false);
12008
+ data["_" + attrName] = "";
11997
12009
  }
11998
12010
  }
11999
12011
 
@@ -12143,11 +12155,12 @@ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds
12143
12155
  needUpdate = false;
12144
12156
  }
12145
12157
  }
12158
+ if (paint.mode === "brush") PaintImage.brush(leafPaint);
12146
12159
  if (!leafPaint.data) {
12147
12160
  PaintImage.createData(leafPaint, image, paint, boxBounds);
12148
- const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
12149
- const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
12150
- if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
12161
+ const {transform: transform} = leafPaint.data, {opacity: opacity} = paint;
12162
+ const clip = (transform && !transform.onlyScale || data.path || data.cornerRadius) && !leafPaint.brush;
12163
+ if (clip || opacity && opacity < 1 || paint.blendMode) leafPaint.complex = clip ? 2 : true;
12151
12164
  }
12152
12165
  if (paint.filter) PaintImage.applyFilter(leafPaint, image, paint.filter, ui);
12153
12166
  return needUpdate;
@@ -12237,6 +12250,7 @@ function getPatternData(paint, box, image) {
12237
12250
  break;
12238
12251
 
12239
12252
  case "repeat":
12253
+ case "brush":
12240
12254
  if (!sameBox || scaleX || rotation || skew) PaintImage.repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
12241
12255
  if (!repeat) data.repeat = "repeat";
12242
12256
  const count = isObject(repeat);
@@ -12377,7 +12391,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
12377
12391
  let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
12378
12392
  if (paint.patternId !== id && !ui.destroyed) {
12379
12393
  if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
12380
- const {image: image, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
12394
+ const {image: image, brush: brush, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
12381
12395
  let imageMatrix, xGap, yGap, {width: width, height: height} = image;
12382
12396
  if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
12383
12397
  width *= scaleX;
@@ -12385,6 +12399,10 @@ function createPattern(paint, ui, canvas, renderOptions) {
12385
12399
  if (gap) {
12386
12400
  xGap = gap.x * scaleX / abs$7(data.scaleX || 1);
12387
12401
  yGap = gap.y * scaleY / abs$7(data.scaleY || 1);
12402
+ if (brush) {
12403
+ const brushScale = PaintImage.getBrushScale(paint, ui);
12404
+ xGap /= brushScale, yGap /= brushScale;
12405
+ }
12388
12406
  }
12389
12407
  if (transform || scaleX !== 1 || scaleY !== 1) {
12390
12408
  scaleX *= getFloorScale(width + (xGap || 0));
@@ -12394,7 +12412,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
12394
12412
  scale$2(imageMatrix, 1 / scaleX, 1 / scaleY);
12395
12413
  }
12396
12414
  const imageCanvas = image.getCanvas(width, height, opacity, undefined, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
12397
- const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
12415
+ const pattern = brush ? imageCanvas : image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
12398
12416
  paint.style = pattern;
12399
12417
  paint.patternId = id;
12400
12418
  }
@@ -12415,9 +12433,9 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
12415
12433
 
12416
12434
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
12417
12435
  const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
12418
- const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
12436
+ const {image: image, brush: brush, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
12419
12437
  if (!data || paint.patternId === id && !exporting || snapshot) {
12420
- return false;
12438
+ if (!(brush && paint.style)) return false;
12421
12439
  } else {
12422
12440
  if (drawImage) {
12423
12441
  if (data.repeat) {
@@ -12431,18 +12449,18 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
12431
12449
  canvas.fillStyle = paint.style || "#000";
12432
12450
  canvas.fill();
12433
12451
  }
12434
- PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
12435
- return true;
12436
12452
  } else {
12437
12453
  if (!paint.style || originPaint.sync || exporting) PaintImage.createPattern(paint, ui, canvas, renderOptions); else PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
12438
- return false;
12454
+ if (!(brush && paint.style)) return false;
12439
12455
  }
12440
12456
  }
12457
+ PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
12458
+ return true;
12441
12459
  }
12442
12460
 
12443
12461
  function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
12444
- const {data: data, image: image, complex: complex} = paint;
12445
- let {width: width, height: height} = image;
12462
+ const {data: data, image: image, brush: brush, complex: complex} = paint;
12463
+ let {width: width, height: height} = image, view = brush || image;
12446
12464
  if (complex) {
12447
12465
  const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
12448
12466
  canvas.save();
@@ -12450,16 +12468,17 @@ function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions)
12450
12468
  blendMode && (canvas.blendMode = blendMode);
12451
12469
  opacity && (canvas.opacity *= opacity);
12452
12470
  transform && canvas.transform(transform);
12453
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12471
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12454
12472
  canvas.restore();
12455
12473
  } else {
12456
12474
  if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
12457
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12475
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12458
12476
  }
12459
12477
  }
12460
12478
 
12461
12479
  function getImageRenderScaleData(paint, ui, canvas, _renderOptions) {
12462
12480
  const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), {data: data} = paint;
12481
+ if (paint.brush) PaintImage.addBrushScale(scaleData, paint, ui);
12463
12482
  if (canvas) {
12464
12483
  const {pixelRatio: pixelRatio} = canvas;
12465
12484
  scaleData.scaleX *= pixelRatio;
@@ -12476,6 +12495,7 @@ function recycleImage(attrName, data) {
12476
12495
  const paints = data["_" + attrName];
12477
12496
  if (isArray(paints)) {
12478
12497
  let paint, image, recycleMap, input, url;
12498
+ const ui = data.__leaf;
12479
12499
  for (let i = 0, len = paints.length; i < len; i++) {
12480
12500
  paint = paints[i];
12481
12501
  image = paint.image;
@@ -12484,7 +12504,8 @@ function recycleImage(attrName, data) {
12484
12504
  if (!recycleMap) recycleMap = {};
12485
12505
  recycleMap[url] = true;
12486
12506
  ImageManager.recyclePaint(paint);
12487
- if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, data.__leaf);
12507
+ if (paint.brush) PaintImage.recycleBrush(paint, ui);
12508
+ if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, ui);
12488
12509
  if (image.loading) {
12489
12510
  if (!input) {
12490
12511
  input = data.__input && data.__input[attrName] || [];