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