@leafer/miniapp 2.0.9 → 2.1.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.
@@ -3082,7 +3082,7 @@ 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
+ data.push(lastCommand === command ? L$a : M$a, x, y);
3086
3086
  i += 3;
3087
3087
  break;
3088
3088
 
@@ -6075,12 +6075,13 @@ const LeafBounds = {
6075
6075
  if (this.__hasWorldEvent) BoundsEvent.emitWorld(this);
6076
6076
  },
6077
6077
  __updateLocalBounds() {
6078
- const layout = this.__layout;
6078
+ const layout = this.__layout, data = this.__;
6079
6079
  if (layout.boxChanged) {
6080
- if (!this.__.__pathInputed) this.__updatePath();
6080
+ if (!data.__pathInputed) this.__updatePath();
6081
6081
  this.__updateRenderPath();
6082
6082
  this.__updateBoxBounds();
6083
6083
  layout.resized = "inner";
6084
+ if (data.__strokeGeometry) data.__strokeGeometry = undefined;
6084
6085
  }
6085
6086
  if (layout.localBoxChanged) {
6086
6087
  if (this.__local) this.__updateLocalBoxBounds();
@@ -6103,6 +6104,7 @@ const LeafBounds = {
6103
6104
  if (layout.renderSpread || layout.strokeSpread !== layout.strokeBoxSpread) layout.renderChanged = true;
6104
6105
  if (this.parent) this.parent.__layout.strokeChange();
6105
6106
  layout.resized = "inner";
6107
+ if (data.__strokeGeometry) data.__strokeGeometry = undefined;
6106
6108
  }
6107
6109
  if (layout.renderChanged) {
6108
6110
  layout.renderSpread = this.__updateRenderSpread();
@@ -7079,7 +7081,7 @@ class LeafLevelList {
7079
7081
  }
7080
7082
  }
7081
7083
 
7082
- const version = "2.0.9";
7084
+ const version = "2.1.1";
7083
7085
 
7084
7086
  class LeaferCanvas extends LeaferCanvasBase {
7085
7087
  get allowBackgroundColor() {
@@ -8244,8 +8246,8 @@ class UIData extends LeafData {
8244
8246
  return this.__getRealStrokeWidth();
8245
8247
  }
8246
8248
  get __maxStrokeWidth() {
8247
- const t = this;
8248
- return t.__hasMultiStrokeStyle ? Math.max(t.__hasMultiStrokeStyle, t.strokeWidth) : t.strokeWidth;
8249
+ const t = this, strokeWidth = t.__hasStrokeSides || t.strokeWidth;
8250
+ return t.__hasMultiStrokeStyle ? Math.max(t.__hasMultiStrokeStyle, strokeWidth) : strokeWidth;
8249
8251
  }
8250
8252
  get __hasMultiPaint() {
8251
8253
  const t = this;
@@ -8313,7 +8315,7 @@ class UIData extends LeafData {
8313
8315
  const isStr = isString(value);
8314
8316
  if (isStr || value && isObject(value[0])) {
8315
8317
  this.__setInput("path", value);
8316
- this._path = isStr ? parse(value) : objectToCanvasData(value);
8318
+ this._path = isStr ? parse(value, this.__useArrow) : objectToCanvasData(value);
8317
8319
  } else {
8318
8320
  if (this.__input) this.__removeInput("path");
8319
8321
  this._path = value;
@@ -8346,6 +8348,10 @@ class UIData extends LeafData {
8346
8348
  }
8347
8349
  return strokeWidth;
8348
8350
  }
8351
+ __checkComplex() {
8352
+ const t = this;
8353
+ stintSet$5(t, "__complex", t.__isFills || t.__isStrokes || t.cornerRadius || t.__useEffect);
8354
+ }
8349
8355
  __setPaint(attrName, value) {
8350
8356
  this.__setInput(attrName, value);
8351
8357
  const layout = this.__leaf.__layout;
@@ -8424,7 +8430,11 @@ class EllipseData extends UIData {
8424
8430
  }
8425
8431
  }
8426
8432
 
8427
- class PolygonData extends LineData {}
8433
+ class PolygonData extends UIData {
8434
+ get __usePathBox() {
8435
+ return this.points || this.__pathInputed;
8436
+ }
8437
+ }
8428
8438
 
8429
8439
  class StarData extends UIData {
8430
8440
  get __boxStroke() {
@@ -8535,7 +8545,7 @@ const UIBounds = {
8535
8545
  if ((data.stroke || data.hitStroke === "all") && strokeWidth && strokeAlign !== "inside") {
8536
8546
  boxSpread = spread = strokeAlign === "center" ? strokeWidth / 2 : strokeWidth;
8537
8547
  if (!data.__boxStroke || data.__useArrow) {
8538
- const miterLimitAddWidth = data.__isLinePath ? 0 : 10 * spread;
8548
+ const miterLimitAddWidth = data.__isLinePath ? 0 : (data.strokeJoin === "miter" ? 10 : 1) * spread;
8539
8549
  const storkeCapAddWidth = data.strokeCap === "none" ? 0 : strokeWidth;
8540
8550
  spread += Math.max(miterLimitAddWidth, storkeCapAddWidth);
8541
8551
  }
@@ -8580,7 +8590,7 @@ const UIRender = {
8580
8590
  data.__useEffect = !!(shadow || otherEffect);
8581
8591
  }
8582
8592
  data.__checkSingle();
8583
- stintSet$4(data, "__complex", data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect);
8593
+ data.__checkComplex();
8584
8594
  },
8585
8595
  __drawFast(canvas, options) {
8586
8596
  drawFast(this, canvas, options);
@@ -9839,7 +9849,7 @@ __decorate([ resizeType() ], Canvas.prototype, "contextSettings", void 0);
9839
9849
 
9840
9850
  Canvas = __decorate([ registerUI() ], Canvas);
9841
9851
 
9842
- const {copyAndSpread: copyAndSpread$3, includes: includes, spread: spread, setList: setList} = BoundsHelper, {stintSet: stintSet$3} = DataHelper;
9852
+ const {copyAndSpread: copyAndSpread$3, includes: includes, setList: setList} = BoundsHelper, {stintSet: stintSet$3} = DataHelper;
9843
9853
 
9844
9854
  let Text = class Text extends UI {
9845
9855
  get __tag() {
@@ -9867,9 +9877,10 @@ let Text = class Text extends UI {
9867
9877
  const {fontSize: fontSize, italic: italic, padding: padding, __autoWidth: autoWidth, __autoHeight: autoHeight} = data;
9868
9878
  this.__updateTextDrawData();
9869
9879
  const {bounds: contentBounds} = data.__textDrawData;
9880
+ console.log(contentBounds);
9870
9881
  const b = layout.boxBounds;
9871
9882
  layout.contentBounds = contentBounds;
9872
- if (data.__lineHeight < fontSize) spread(contentBounds, fontSize / 2);
9883
+ if (data.__lineHeight < fontSize) layout.renderChanged = true;
9873
9884
  if (autoWidth || autoHeight) {
9874
9885
  b.x = autoWidth ? contentBounds.x : 0;
9875
9886
  b.y = autoHeight ? contentBounds.y : 0;
@@ -9889,6 +9900,8 @@ let Text = class Text extends UI {
9889
9900
  __updateRenderSpread() {
9890
9901
  let spread = super.__updateRenderSpread();
9891
9902
  if (!spread) spread = this.isOverflow ? 1 : 0;
9903
+ const {__lineHeight: __lineHeight, fontSize: fontSize} = this.__;
9904
+ if (__lineHeight < fontSize) spread = FourNumberHelper.max(spread, (fontSize - __lineHeight) / 2);
9892
9905
  return spread;
9893
9906
  }
9894
9907
  __updateRenderBounds() {
@@ -11974,8 +11987,8 @@ function compute(attrName, ui) {
11974
11987
  }
11975
11988
  }
11976
11989
  }
11977
- data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
11978
11990
  if (leafPaints.length) {
11991
+ data["_" + attrName] = leafPaints;
11979
11992
  if (leafPaints.every(item => item.isTransparent)) {
11980
11993
  if (leafPaints.some(item => item.image)) isAlphaPixel = true;
11981
11994
  isTransparent = true;
@@ -11990,6 +12003,7 @@ function compute(attrName, ui) {
11990
12003
  }
11991
12004
  } else {
11992
12005
  data.__removePaint(attrName, false);
12006
+ data["_" + attrName] = "";
11993
12007
  }
11994
12008
  }
11995
12009
 
@@ -12139,11 +12153,12 @@ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds
12139
12153
  needUpdate = false;
12140
12154
  }
12141
12155
  }
12156
+ if (paint.mode === "brush") PaintImage.brush(leafPaint);
12142
12157
  if (!leafPaint.data) {
12143
12158
  PaintImage.createData(leafPaint, image, paint, boxBounds);
12144
- const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
12145
- const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
12146
- if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
12159
+ const {transform: transform} = leafPaint.data, {opacity: opacity} = paint;
12160
+ const clip = (transform && !transform.onlyScale || data.path || data.cornerRadius) && !leafPaint.brush;
12161
+ if (clip || opacity && opacity < 1 || paint.blendMode) leafPaint.complex = clip ? 2 : true;
12147
12162
  }
12148
12163
  if (paint.filter) PaintImage.applyFilter(leafPaint, image, paint.filter, ui);
12149
12164
  return needUpdate;
@@ -12233,6 +12248,7 @@ function getPatternData(paint, box, image) {
12233
12248
  break;
12234
12249
 
12235
12250
  case "repeat":
12251
+ case "brush":
12236
12252
  if (!sameBox || scaleX || rotation || skew) PaintImage.repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
12237
12253
  if (!repeat) data.repeat = "repeat";
12238
12254
  const count = isObject(repeat);
@@ -12373,7 +12389,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
12373
12389
  let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
12374
12390
  if (paint.patternId !== id && !ui.destroyed) {
12375
12391
  if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
12376
- const {image: image, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
12392
+ const {image: image, brush: brush, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
12377
12393
  let imageMatrix, xGap, yGap, {width: width, height: height} = image;
12378
12394
  if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
12379
12395
  width *= scaleX;
@@ -12381,6 +12397,10 @@ function createPattern(paint, ui, canvas, renderOptions) {
12381
12397
  if (gap) {
12382
12398
  xGap = gap.x * scaleX / abs$7(data.scaleX || 1);
12383
12399
  yGap = gap.y * scaleY / abs$7(data.scaleY || 1);
12400
+ if (brush) {
12401
+ const brushScale = PaintImage.getBrushScale(paint, ui);
12402
+ xGap /= brushScale, yGap /= brushScale;
12403
+ }
12384
12404
  }
12385
12405
  if (transform || scaleX !== 1 || scaleY !== 1) {
12386
12406
  scaleX *= getFloorScale(width + (xGap || 0));
@@ -12390,7 +12410,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
12390
12410
  scale$2(imageMatrix, 1 / scaleX, 1 / scaleY);
12391
12411
  }
12392
12412
  const imageCanvas = image.getCanvas(width, height, opacity, undefined, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
12393
- const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
12413
+ const pattern = brush ? imageCanvas : image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
12394
12414
  paint.style = pattern;
12395
12415
  paint.patternId = id;
12396
12416
  }
@@ -12411,9 +12431,9 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
12411
12431
 
12412
12432
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
12413
12433
  const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
12414
- const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
12434
+ const {image: image, brush: brush, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
12415
12435
  if (!data || paint.patternId === id && !exporting || snapshot) {
12416
- return false;
12436
+ if (!(brush && paint.style)) return false;
12417
12437
  } else {
12418
12438
  if (drawImage) {
12419
12439
  if (data.repeat) {
@@ -12427,18 +12447,18 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
12427
12447
  canvas.fillStyle = paint.style || "#000";
12428
12448
  canvas.fill();
12429
12449
  }
12430
- PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
12431
- return true;
12432
12450
  } else {
12433
12451
  if (!paint.style || originPaint.sync || exporting) PaintImage.createPattern(paint, ui, canvas, renderOptions); else PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
12434
- return false;
12452
+ if (!(brush && paint.style)) return false;
12435
12453
  }
12436
12454
  }
12455
+ PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
12456
+ return true;
12437
12457
  }
12438
12458
 
12439
12459
  function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
12440
- const {data: data, image: image, complex: complex} = paint;
12441
- let {width: width, height: height} = image;
12460
+ const {data: data, image: image, brush: brush, complex: complex} = paint;
12461
+ let {width: width, height: height} = image, view = brush || image;
12442
12462
  if (complex) {
12443
12463
  const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
12444
12464
  canvas.save();
@@ -12446,16 +12466,17 @@ function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions)
12446
12466
  blendMode && (canvas.blendMode = blendMode);
12447
12467
  opacity && (canvas.opacity *= opacity);
12448
12468
  transform && canvas.transform(transform);
12449
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12469
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12450
12470
  canvas.restore();
12451
12471
  } else {
12452
12472
  if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
12453
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12473
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12454
12474
  }
12455
12475
  }
12456
12476
 
12457
12477
  function getImageRenderScaleData(paint, ui, canvas, _renderOptions) {
12458
12478
  const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), {data: data} = paint;
12479
+ if (paint.brush) PaintImage.addBrushScale(scaleData, paint, ui);
12459
12480
  if (canvas) {
12460
12481
  const {pixelRatio: pixelRatio} = canvas;
12461
12482
  scaleData.scaleX *= pixelRatio;
@@ -12472,6 +12493,7 @@ function recycleImage(attrName, data) {
12472
12493
  const paints = data["_" + attrName];
12473
12494
  if (isArray(paints)) {
12474
12495
  let paint, image, recycleMap, input, url;
12496
+ const ui = data.__leaf;
12475
12497
  for (let i = 0, len = paints.length; i < len; i++) {
12476
12498
  paint = paints[i];
12477
12499
  image = paint.image;
@@ -12480,7 +12502,8 @@ function recycleImage(attrName, data) {
12480
12502
  if (!recycleMap) recycleMap = {};
12481
12503
  recycleMap[url] = true;
12482
12504
  ImageManager.recyclePaint(paint);
12483
- if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, data.__leaf);
12505
+ if (paint.brush) PaintImage.recycleBrush(paint, ui);
12506
+ if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, ui);
12484
12507
  if (image.loading) {
12485
12508
  if (!input) {
12486
12509
  input = data.__input && data.__input[attrName] || [];