leafer-ui 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$4:
3083
3083
  x = old[i + 1];
3084
3084
  y = old[i + 2];
3085
- data.push(M$4, x, y);
3085
+ if (lastCommand === command) data.push(L$5, x, y); else data.push(M$4, 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$4:
3199
3200
  data.push(Z$4);
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
  const debug$5 = Debug.get("LeaferCanvas");
7085
7090
 
@@ -8348,7 +8353,7 @@ class UIData extends LeafData {
8348
8353
  const isStr = isString(value);
8349
8354
  if (isStr || value && isObject(value[0])) {
8350
8355
  this.__setInput("path", value);
8351
- this._path = isStr ? parse(value) : objectToCanvasData(value);
8356
+ this._path = isStr ? parse(value, this.__useArrow) : objectToCanvasData(value);
8352
8357
  } else {
8353
8358
  if (this.__input) this.__removeInput("path");
8354
8359
  this._path = value;
@@ -8463,7 +8468,11 @@ class EllipseData extends UIData {
8463
8468
  }
8464
8469
  }
8465
8470
 
8466
- class PolygonData extends LineData {}
8471
+ class PolygonData extends UIData {
8472
+ get __usePathBox() {
8473
+ return this.points || this.__pathInputed;
8474
+ }
8475
+ }
8467
8476
 
8468
8477
  class StarData extends UIData {
8469
8478
  get __boxStroke() {
@@ -8574,7 +8583,7 @@ const UIBounds = {
8574
8583
  if ((data.stroke || data.hitStroke === "all") && strokeWidth && strokeAlign !== "inside") {
8575
8584
  boxSpread = spread = strokeAlign === "center" ? strokeWidth / 2 : strokeWidth;
8576
8585
  if (!data.__boxStroke || data.__useArrow) {
8577
- const miterLimitAddWidth = data.__isLinePath ? 0 : 10 * spread;
8586
+ const miterLimitAddWidth = data.__isLinePath ? 0 : (data.strokeJoin === "miter" ? 10 : 1) * spread;
8578
8587
  const storkeCapAddWidth = data.strokeCap === "none" ? 0 : strokeWidth;
8579
8588
  spread += Math.max(miterLimitAddWidth, storkeCapAddWidth);
8580
8589
  }
@@ -9878,7 +9887,7 @@ __decorate([ resizeType() ], Canvas.prototype, "contextSettings", void 0);
9878
9887
 
9879
9888
  Canvas = __decorate([ registerUI() ], Canvas);
9880
9889
 
9881
- const {copyAndSpread: copyAndSpread$1, includes: includes, spread: spread, setList: setList} = BoundsHelper, {stintSet: stintSet$1} = DataHelper;
9890
+ const {copyAndSpread: copyAndSpread$1, includes: includes, setList: setList} = BoundsHelper, {stintSet: stintSet$1} = DataHelper;
9882
9891
 
9883
9892
  let Text = class Text extends UI {
9884
9893
  get __tag() {
@@ -9908,7 +9917,7 @@ let Text = class Text extends UI {
9908
9917
  const {bounds: contentBounds} = data.__textDrawData;
9909
9918
  const b = layout.boxBounds;
9910
9919
  layout.contentBounds = contentBounds;
9911
- if (data.__lineHeight < fontSize) spread(contentBounds, fontSize / 2);
9920
+ if (data.__lineHeight < fontSize) layout.renderChanged = true;
9912
9921
  if (autoWidth || autoHeight) {
9913
9922
  b.x = autoWidth ? contentBounds.x : 0;
9914
9923
  b.y = autoHeight ? contentBounds.y : 0;
@@ -9928,6 +9937,8 @@ let Text = class Text extends UI {
9928
9937
  __updateRenderSpread() {
9929
9938
  let spread = super.__updateRenderSpread();
9930
9939
  if (!spread) spread = this.isOverflow ? 1 : 0;
9940
+ const {__lineHeight: __lineHeight, fontSize: fontSize} = this.__;
9941
+ if (__lineHeight < fontSize) spread = FourNumberHelper.max(spread, (fontSize - __lineHeight) / 2);
9931
9942
  return spread;
9932
9943
  }
9933
9944
  __updateRenderBounds() {
@@ -12234,8 +12245,8 @@ function compute(attrName, ui) {
12234
12245
  }
12235
12246
  }
12236
12247
  }
12237
- data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
12238
12248
  if (leafPaints.length) {
12249
+ data["_" + attrName] = leafPaints;
12239
12250
  if (leafPaints.every(item => item.isTransparent)) {
12240
12251
  if (leafPaints.some(item => item.image)) isAlphaPixel = true;
12241
12252
  isTransparent = true;
@@ -12250,6 +12261,7 @@ function compute(attrName, ui) {
12250
12261
  }
12251
12262
  } else {
12252
12263
  data.__removePaint(attrName, false);
12264
+ data["_" + attrName] = "";
12253
12265
  }
12254
12266
  }
12255
12267
 
@@ -12399,11 +12411,12 @@ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds
12399
12411
  needUpdate = false;
12400
12412
  }
12401
12413
  }
12414
+ if (paint.mode === "brush") PaintImage.brush(leafPaint);
12402
12415
  if (!leafPaint.data) {
12403
12416
  PaintImage.createData(leafPaint, image, paint, boxBounds);
12404
- const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
12405
- const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
12406
- if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
12417
+ const {transform: transform} = leafPaint.data, {opacity: opacity} = paint;
12418
+ const clip = (transform && !transform.onlyScale || data.path || data.cornerRadius) && !leafPaint.brush;
12419
+ if (clip || opacity && opacity < 1 || paint.blendMode) leafPaint.complex = clip ? 2 : true;
12407
12420
  }
12408
12421
  if (paint.filter) PaintImage.applyFilter(leafPaint, image, paint.filter, ui);
12409
12422
  return needUpdate;
@@ -12493,6 +12506,7 @@ function getPatternData(paint, box, image) {
12493
12506
  break;
12494
12507
 
12495
12508
  case "repeat":
12509
+ case "brush":
12496
12510
  if (!sameBox || scaleX || rotation || skew) PaintImage.repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
12497
12511
  if (!repeat) data.repeat = "repeat";
12498
12512
  const count = isObject(repeat);
@@ -12633,7 +12647,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
12633
12647
  let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
12634
12648
  if (paint.patternId !== id && !ui.destroyed) {
12635
12649
  if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
12636
- const {image: image, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
12650
+ const {image: image, brush: brush, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
12637
12651
  let imageMatrix, xGap, yGap, {width: width, height: height} = image;
12638
12652
  if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
12639
12653
  width *= scaleX;
@@ -12641,6 +12655,10 @@ function createPattern(paint, ui, canvas, renderOptions) {
12641
12655
  if (gap) {
12642
12656
  xGap = gap.x * scaleX / abs$1(data.scaleX || 1);
12643
12657
  yGap = gap.y * scaleY / abs$1(data.scaleY || 1);
12658
+ if (brush) {
12659
+ const brushScale = PaintImage.getBrushScale(paint, ui);
12660
+ xGap /= brushScale, yGap /= brushScale;
12661
+ }
12644
12662
  }
12645
12663
  if (transform || scaleX !== 1 || scaleY !== 1) {
12646
12664
  scaleX *= getFloorScale(width + (xGap || 0));
@@ -12650,7 +12668,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
12650
12668
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
12651
12669
  }
12652
12670
  const imageCanvas = image.getCanvas(width, height, opacity, undefined, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
12653
- const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
12671
+ const pattern = brush ? imageCanvas : image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
12654
12672
  paint.style = pattern;
12655
12673
  paint.patternId = id;
12656
12674
  }
@@ -12671,9 +12689,9 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
12671
12689
 
12672
12690
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
12673
12691
  const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
12674
- const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
12692
+ const {image: image, brush: brush, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
12675
12693
  if (!data || paint.patternId === id && !exporting || snapshot) {
12676
- return false;
12694
+ if (!(brush && paint.style)) return false;
12677
12695
  } else {
12678
12696
  if (drawImage) {
12679
12697
  if (data.repeat) {
@@ -12687,18 +12705,18 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
12687
12705
  canvas.fillStyle = paint.style || "#000";
12688
12706
  canvas.fill();
12689
12707
  }
12690
- PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
12691
- return true;
12692
12708
  } else {
12693
12709
  if (!paint.style || originPaint.sync || exporting) PaintImage.createPattern(paint, ui, canvas, renderOptions); else PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
12694
- return false;
12710
+ if (!(brush && paint.style)) return false;
12695
12711
  }
12696
12712
  }
12713
+ PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
12714
+ return true;
12697
12715
  }
12698
12716
 
12699
12717
  function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
12700
- const {data: data, image: image, complex: complex} = paint;
12701
- let {width: width, height: height} = image;
12718
+ const {data: data, image: image, brush: brush, complex: complex} = paint;
12719
+ let {width: width, height: height} = image, view = brush || image;
12702
12720
  if (complex) {
12703
12721
  const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
12704
12722
  canvas.save();
@@ -12706,16 +12724,17 @@ function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions)
12706
12724
  blendMode && (canvas.blendMode = blendMode);
12707
12725
  opacity && (canvas.opacity *= opacity);
12708
12726
  transform && canvas.transform(transform);
12709
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12727
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12710
12728
  canvas.restore();
12711
12729
  } else {
12712
12730
  if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
12713
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12731
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12714
12732
  }
12715
12733
  }
12716
12734
 
12717
12735
  function getImageRenderScaleData(paint, ui, canvas, _renderOptions) {
12718
12736
  const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), {data: data} = paint;
12737
+ if (paint.brush) PaintImage.addBrushScale(scaleData, paint, ui);
12719
12738
  if (canvas) {
12720
12739
  const {pixelRatio: pixelRatio} = canvas;
12721
12740
  scaleData.scaleX *= pixelRatio;
@@ -12732,6 +12751,7 @@ function recycleImage(attrName, data) {
12732
12751
  const paints = data["_" + attrName];
12733
12752
  if (isArray(paints)) {
12734
12753
  let paint, image, recycleMap, input, url;
12754
+ const ui = data.__leaf;
12735
12755
  for (let i = 0, len = paints.length; i < len; i++) {
12736
12756
  paint = paints[i];
12737
12757
  image = paint.image;
@@ -12740,7 +12760,8 @@ function recycleImage(attrName, data) {
12740
12760
  if (!recycleMap) recycleMap = {};
12741
12761
  recycleMap[url] = true;
12742
12762
  ImageManager.recyclePaint(paint);
12743
- if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, data.__leaf);
12763
+ if (paint.brush) PaintImage.recycleBrush(paint, ui);
12764
+ if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, ui);
12744
12765
  if (image.loading) {
12745
12766
  if (!input) {
12746
12767
  input = data.__input && data.__input[attrName] || [];