@leafer-draw/worker 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
  class LeaferCanvas extends LeaferCanvasBase {
7085
7090
  get allowBackgroundColor() {
@@ -7954,7 +7959,7 @@ class UIData extends LeafData {
7954
7959
  const isStr = isString(value);
7955
7960
  if (isStr || value && isObject(value[0])) {
7956
7961
  this.__setInput("path", value);
7957
- this._path = isStr ? parse(value) : objectToCanvasData(value);
7962
+ this._path = isStr ? parse(value, this.__useArrow) : objectToCanvasData(value);
7958
7963
  } else {
7959
7964
  if (this.__input) this.__removeInput("path");
7960
7965
  this._path = value;
@@ -8069,7 +8074,11 @@ class EllipseData extends UIData {
8069
8074
  }
8070
8075
  }
8071
8076
 
8072
- class PolygonData extends LineData {}
8077
+ class PolygonData extends UIData {
8078
+ get __usePathBox() {
8079
+ return this.points || this.__pathInputed;
8080
+ }
8081
+ }
8073
8082
 
8074
8083
  class StarData extends UIData {
8075
8084
  get __boxStroke() {
@@ -8180,7 +8189,7 @@ const UIBounds = {
8180
8189
  if ((data.stroke || data.hitStroke === "all") && strokeWidth && strokeAlign !== "inside") {
8181
8190
  boxSpread = spread = strokeAlign === "center" ? strokeWidth / 2 : strokeWidth;
8182
8191
  if (!data.__boxStroke || data.__useArrow) {
8183
- const miterLimitAddWidth = data.__isLinePath ? 0 : 10 * spread;
8192
+ const miterLimitAddWidth = data.__isLinePath ? 0 : (data.strokeJoin === "miter" ? 10 : 1) * spread;
8184
8193
  const storkeCapAddWidth = data.strokeCap === "none" ? 0 : strokeWidth;
8185
8194
  spread += Math.max(miterLimitAddWidth, storkeCapAddWidth);
8186
8195
  }
@@ -9484,7 +9493,7 @@ __decorate([ resizeType() ], Canvas.prototype, "contextSettings", void 0);
9484
9493
 
9485
9494
  Canvas = __decorate([ registerUI() ], Canvas);
9486
9495
 
9487
- const {copyAndSpread: copyAndSpread$1, includes: includes, spread: spread, setList: setList} = BoundsHelper, {stintSet: stintSet$1} = DataHelper;
9496
+ const {copyAndSpread: copyAndSpread$1, includes: includes, setList: setList} = BoundsHelper, {stintSet: stintSet$1} = DataHelper;
9488
9497
 
9489
9498
  let Text = class Text extends UI {
9490
9499
  get __tag() {
@@ -9514,7 +9523,7 @@ let Text = class Text extends UI {
9514
9523
  const {bounds: contentBounds} = data.__textDrawData;
9515
9524
  const b = layout.boxBounds;
9516
9525
  layout.contentBounds = contentBounds;
9517
- if (data.__lineHeight < fontSize) spread(contentBounds, fontSize / 2);
9526
+ if (data.__lineHeight < fontSize) layout.renderChanged = true;
9518
9527
  if (autoWidth || autoHeight) {
9519
9528
  b.x = autoWidth ? contentBounds.x : 0;
9520
9529
  b.y = autoHeight ? contentBounds.y : 0;
@@ -9534,6 +9543,8 @@ let Text = class Text extends UI {
9534
9543
  __updateRenderSpread() {
9535
9544
  let spread = super.__updateRenderSpread();
9536
9545
  if (!spread) spread = this.isOverflow ? 1 : 0;
9546
+ const {__lineHeight: __lineHeight, fontSize: fontSize} = this.__;
9547
+ if (__lineHeight < fontSize) spread = FourNumberHelper.max(spread, (fontSize - __lineHeight) / 2);
9537
9548
  return spread;
9538
9549
  }
9539
9550
  __updateRenderBounds() {
@@ -9991,8 +10002,8 @@ function compute(attrName, ui) {
9991
10002
  }
9992
10003
  }
9993
10004
  }
9994
- data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
9995
10005
  if (leafPaints.length) {
10006
+ data["_" + attrName] = leafPaints;
9996
10007
  if (leafPaints.every(item => item.isTransparent)) {
9997
10008
  if (leafPaints.some(item => item.image)) isAlphaPixel = true;
9998
10009
  isTransparent = true;
@@ -10007,6 +10018,7 @@ function compute(attrName, ui) {
10007
10018
  }
10008
10019
  } else {
10009
10020
  data.__removePaint(attrName, false);
10021
+ data["_" + attrName] = "";
10010
10022
  }
10011
10023
  }
10012
10024
 
@@ -10156,11 +10168,12 @@ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds
10156
10168
  needUpdate = false;
10157
10169
  }
10158
10170
  }
10171
+ if (paint.mode === "brush") PaintImage.brush(leafPaint);
10159
10172
  if (!leafPaint.data) {
10160
10173
  PaintImage.createData(leafPaint, image, paint, boxBounds);
10161
- const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
10162
- const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
10163
- if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
10174
+ const {transform: transform} = leafPaint.data, {opacity: opacity} = paint;
10175
+ const clip = (transform && !transform.onlyScale || data.path || data.cornerRadius) && !leafPaint.brush;
10176
+ if (clip || opacity && opacity < 1 || paint.blendMode) leafPaint.complex = clip ? 2 : true;
10164
10177
  }
10165
10178
  if (paint.filter) PaintImage.applyFilter(leafPaint, image, paint.filter, ui);
10166
10179
  return needUpdate;
@@ -10250,6 +10263,7 @@ function getPatternData(paint, box, image) {
10250
10263
  break;
10251
10264
 
10252
10265
  case "repeat":
10266
+ case "brush":
10253
10267
  if (!sameBox || scaleX || rotation || skew) PaintImage.repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
10254
10268
  if (!repeat) data.repeat = "repeat";
10255
10269
  const count = isObject(repeat);
@@ -10390,7 +10404,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
10390
10404
  let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
10391
10405
  if (paint.patternId !== id && !ui.destroyed) {
10392
10406
  if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
10393
- const {image: image, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
10407
+ const {image: image, brush: brush, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
10394
10408
  let imageMatrix, xGap, yGap, {width: width, height: height} = image;
10395
10409
  if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
10396
10410
  width *= scaleX;
@@ -10398,6 +10412,10 @@ function createPattern(paint, ui, canvas, renderOptions) {
10398
10412
  if (gap) {
10399
10413
  xGap = gap.x * scaleX / abs$1(data.scaleX || 1);
10400
10414
  yGap = gap.y * scaleY / abs$1(data.scaleY || 1);
10415
+ if (brush) {
10416
+ const brushScale = PaintImage.getBrushScale(paint, ui);
10417
+ xGap /= brushScale, yGap /= brushScale;
10418
+ }
10401
10419
  }
10402
10420
  if (transform || scaleX !== 1 || scaleY !== 1) {
10403
10421
  scaleX *= getFloorScale(width + (xGap || 0));
@@ -10407,7 +10425,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
10407
10425
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
10408
10426
  }
10409
10427
  const imageCanvas = image.getCanvas(width, height, opacity, undefined, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
10410
- const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
10428
+ const pattern = brush ? imageCanvas : image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
10411
10429
  paint.style = pattern;
10412
10430
  paint.patternId = id;
10413
10431
  }
@@ -10428,9 +10446,9 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
10428
10446
 
10429
10447
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
10430
10448
  const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
10431
- const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
10449
+ const {image: image, brush: brush, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
10432
10450
  if (!data || paint.patternId === id && !exporting || snapshot) {
10433
- return false;
10451
+ if (!(brush && paint.style)) return false;
10434
10452
  } else {
10435
10453
  if (drawImage) {
10436
10454
  if (data.repeat) {
@@ -10444,18 +10462,18 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
10444
10462
  canvas.fillStyle = paint.style || "#000";
10445
10463
  canvas.fill();
10446
10464
  }
10447
- PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
10448
- return true;
10449
10465
  } else {
10450
10466
  if (!paint.style || originPaint.sync || exporting) PaintImage.createPattern(paint, ui, canvas, renderOptions); else PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
10451
- return false;
10467
+ if (!(brush && paint.style)) return false;
10452
10468
  }
10453
10469
  }
10470
+ PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
10471
+ return true;
10454
10472
  }
10455
10473
 
10456
10474
  function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
10457
- const {data: data, image: image, complex: complex} = paint;
10458
- let {width: width, height: height} = image;
10475
+ const {data: data, image: image, brush: brush, complex: complex} = paint;
10476
+ let {width: width, height: height} = image, view = brush || image;
10459
10477
  if (complex) {
10460
10478
  const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
10461
10479
  canvas.save();
@@ -10463,16 +10481,17 @@ function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions)
10463
10481
  blendMode && (canvas.blendMode = blendMode);
10464
10482
  opacity && (canvas.opacity *= opacity);
10465
10483
  transform && canvas.transform(transform);
10466
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
10484
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
10467
10485
  canvas.restore();
10468
10486
  } else {
10469
10487
  if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
10470
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
10488
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
10471
10489
  }
10472
10490
  }
10473
10491
 
10474
10492
  function getImageRenderScaleData(paint, ui, canvas, _renderOptions) {
10475
10493
  const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), {data: data} = paint;
10494
+ if (paint.brush) PaintImage.addBrushScale(scaleData, paint, ui);
10476
10495
  if (canvas) {
10477
10496
  const {pixelRatio: pixelRatio} = canvas;
10478
10497
  scaleData.scaleX *= pixelRatio;
@@ -10489,6 +10508,7 @@ function recycleImage(attrName, data) {
10489
10508
  const paints = data["_" + attrName];
10490
10509
  if (isArray(paints)) {
10491
10510
  let paint, image, recycleMap, input, url;
10511
+ const ui = data.__leaf;
10492
10512
  for (let i = 0, len = paints.length; i < len; i++) {
10493
10513
  paint = paints[i];
10494
10514
  image = paint.image;
@@ -10497,7 +10517,8 @@ function recycleImage(attrName, data) {
10497
10517
  if (!recycleMap) recycleMap = {};
10498
10518
  recycleMap[url] = true;
10499
10519
  ImageManager.recyclePaint(paint);
10500
- if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, data.__leaf);
10520
+ if (paint.brush) PaintImage.recycleBrush(paint, ui);
10521
+ if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, ui);
10501
10522
  if (image.loading) {
10502
10523
  if (!input) {
10503
10524
  input = data.__input && data.__input[attrName] || [];