@leafer-game/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$5:
3083
3083
  x = old[i + 1];
3084
3084
  y = old[i + 2];
3085
- data.push(M$5, x, y);
3085
+ data.push(lastCommand === command ? L$6 : M$5, 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() {
@@ -8154,7 +8156,7 @@ class UIData extends LeafData {
8154
8156
  const isStr = isString(value);
8155
8157
  if (isStr || value && isObject(value[0])) {
8156
8158
  this.__setInput("path", value);
8157
- this._path = isStr ? parse(value) : objectToCanvasData(value);
8159
+ this._path = isStr ? parse(value, this.__useArrow) : objectToCanvasData(value);
8158
8160
  } else {
8159
8161
  if (this.__input) this.__removeInput("path");
8160
8162
  this._path = value;
@@ -8269,7 +8271,11 @@ class EllipseData extends UIData {
8269
8271
  }
8270
8272
  }
8271
8273
 
8272
- class PolygonData extends LineData {}
8274
+ class PolygonData extends UIData {
8275
+ get __usePathBox() {
8276
+ return this.points || this.__pathInputed;
8277
+ }
8278
+ }
8273
8279
 
8274
8280
  class StarData extends UIData {
8275
8281
  get __boxStroke() {
@@ -8380,7 +8386,7 @@ const UIBounds = {
8380
8386
  if ((data.stroke || data.hitStroke === "all") && strokeWidth && strokeAlign !== "inside") {
8381
8387
  boxSpread = spread = strokeAlign === "center" ? strokeWidth / 2 : strokeWidth;
8382
8388
  if (!data.__boxStroke || data.__useArrow) {
8383
- const miterLimitAddWidth = data.__isLinePath ? 0 : 10 * spread;
8389
+ const miterLimitAddWidth = data.__isLinePath ? 0 : (data.strokeJoin === "miter" ? 10 : 1) * spread;
8384
8390
  const storkeCapAddWidth = data.strokeCap === "none" ? 0 : strokeWidth;
8385
8391
  spread += Math.max(miterLimitAddWidth, storkeCapAddWidth);
8386
8392
  }
@@ -9684,7 +9690,7 @@ __decorate([ resizeType() ], Canvas.prototype, "contextSettings", void 0);
9684
9690
 
9685
9691
  Canvas = __decorate([ registerUI() ], Canvas);
9686
9692
 
9687
- const {copyAndSpread: copyAndSpread$1, includes: includes, spread: spread, setList: setList} = BoundsHelper, {stintSet: stintSet$1} = DataHelper;
9693
+ const {copyAndSpread: copyAndSpread$1, includes: includes, setList: setList} = BoundsHelper, {stintSet: stintSet$1} = DataHelper;
9688
9694
 
9689
9695
  let Text = class Text extends UI {
9690
9696
  get __tag() {
@@ -9712,9 +9718,10 @@ let Text = class Text extends UI {
9712
9718
  const {fontSize: fontSize, italic: italic, padding: padding, __autoWidth: autoWidth, __autoHeight: autoHeight} = data;
9713
9719
  this.__updateTextDrawData();
9714
9720
  const {bounds: contentBounds} = data.__textDrawData;
9721
+ console.log(contentBounds);
9715
9722
  const b = layout.boxBounds;
9716
9723
  layout.contentBounds = contentBounds;
9717
- if (data.__lineHeight < fontSize) spread(contentBounds, fontSize / 2);
9724
+ if (data.__lineHeight < fontSize) layout.renderChanged = true;
9718
9725
  if (autoWidth || autoHeight) {
9719
9726
  b.x = autoWidth ? contentBounds.x : 0;
9720
9727
  b.y = autoHeight ? contentBounds.y : 0;
@@ -9734,6 +9741,8 @@ let Text = class Text extends UI {
9734
9741
  __updateRenderSpread() {
9735
9742
  let spread = super.__updateRenderSpread();
9736
9743
  if (!spread) spread = this.isOverflow ? 1 : 0;
9744
+ const {__lineHeight: __lineHeight, fontSize: fontSize} = this.__;
9745
+ if (__lineHeight < fontSize) spread = FourNumberHelper.max(spread, (fontSize - __lineHeight) / 2);
9737
9746
  return spread;
9738
9747
  }
9739
9748
  __updateRenderBounds() {
@@ -11707,8 +11716,8 @@ function compute(attrName, ui) {
11707
11716
  }
11708
11717
  }
11709
11718
  }
11710
- data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
11711
11719
  if (leafPaints.length) {
11720
+ data["_" + attrName] = leafPaints;
11712
11721
  if (leafPaints.every(item => item.isTransparent)) {
11713
11722
  if (leafPaints.some(item => item.image)) isAlphaPixel = true;
11714
11723
  isTransparent = true;
@@ -11723,6 +11732,7 @@ function compute(attrName, ui) {
11723
11732
  }
11724
11733
  } else {
11725
11734
  data.__removePaint(attrName, false);
11735
+ data["_" + attrName] = "";
11726
11736
  }
11727
11737
  }
11728
11738
 
@@ -11872,11 +11882,12 @@ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds
11872
11882
  needUpdate = false;
11873
11883
  }
11874
11884
  }
11885
+ if (paint.mode === "brush") PaintImage.brush(leafPaint);
11875
11886
  if (!leafPaint.data) {
11876
11887
  PaintImage.createData(leafPaint, image, paint, boxBounds);
11877
- const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
11878
- const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
11879
- if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
11888
+ const {transform: transform} = leafPaint.data, {opacity: opacity} = paint;
11889
+ const clip = (transform && !transform.onlyScale || data.path || data.cornerRadius) && !leafPaint.brush;
11890
+ if (clip || opacity && opacity < 1 || paint.blendMode) leafPaint.complex = clip ? 2 : true;
11880
11891
  }
11881
11892
  if (paint.filter) PaintImage.applyFilter(leafPaint, image, paint.filter, ui);
11882
11893
  return needUpdate;
@@ -11966,6 +11977,7 @@ function getPatternData(paint, box, image) {
11966
11977
  break;
11967
11978
 
11968
11979
  case "repeat":
11980
+ case "brush":
11969
11981
  if (!sameBox || scaleX || rotation || skew) PaintImage.repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
11970
11982
  if (!repeat) data.repeat = "repeat";
11971
11983
  const count = isObject(repeat);
@@ -12106,7 +12118,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
12106
12118
  let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
12107
12119
  if (paint.patternId !== id && !ui.destroyed) {
12108
12120
  if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
12109
- const {image: image, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
12121
+ const {image: image, brush: brush, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
12110
12122
  let imageMatrix, xGap, yGap, {width: width, height: height} = image;
12111
12123
  if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
12112
12124
  width *= scaleX;
@@ -12114,6 +12126,10 @@ function createPattern(paint, ui, canvas, renderOptions) {
12114
12126
  if (gap) {
12115
12127
  xGap = gap.x * scaleX / abs$2(data.scaleX || 1);
12116
12128
  yGap = gap.y * scaleY / abs$2(data.scaleY || 1);
12129
+ if (brush) {
12130
+ const brushScale = PaintImage.getBrushScale(paint, ui);
12131
+ xGap /= brushScale, yGap /= brushScale;
12132
+ }
12117
12133
  }
12118
12134
  if (transform || scaleX !== 1 || scaleY !== 1) {
12119
12135
  scaleX *= getFloorScale(width + (xGap || 0));
@@ -12123,7 +12139,7 @@ function createPattern(paint, ui, canvas, renderOptions) {
12123
12139
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
12124
12140
  }
12125
12141
  const imageCanvas = image.getCanvas(width, height, opacity, undefined, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
12126
- const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
12142
+ const pattern = brush ? imageCanvas : image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
12127
12143
  paint.style = pattern;
12128
12144
  paint.patternId = id;
12129
12145
  }
@@ -12144,9 +12160,9 @@ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
12144
12160
 
12145
12161
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
12146
12162
  const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
12147
- const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
12163
+ const {image: image, brush: brush, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
12148
12164
  if (!data || paint.patternId === id && !exporting || snapshot) {
12149
- return false;
12165
+ if (!(brush && paint.style)) return false;
12150
12166
  } else {
12151
12167
  if (drawImage) {
12152
12168
  if (data.repeat) {
@@ -12160,18 +12176,18 @@ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
12160
12176
  canvas.fillStyle = paint.style || "#000";
12161
12177
  canvas.fill();
12162
12178
  }
12163
- PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
12164
- return true;
12165
12179
  } else {
12166
12180
  if (!paint.style || originPaint.sync || exporting) PaintImage.createPattern(paint, ui, canvas, renderOptions); else PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
12167
- return false;
12181
+ if (!(brush && paint.style)) return false;
12168
12182
  }
12169
12183
  }
12184
+ PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
12185
+ return true;
12170
12186
  }
12171
12187
 
12172
12188
  function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
12173
- const {data: data, image: image, complex: complex} = paint;
12174
- let {width: width, height: height} = image;
12189
+ const {data: data, image: image, brush: brush, complex: complex} = paint;
12190
+ let {width: width, height: height} = image, view = brush || image;
12175
12191
  if (complex) {
12176
12192
  const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
12177
12193
  canvas.save();
@@ -12179,16 +12195,17 @@ function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions)
12179
12195
  blendMode && (canvas.blendMode = blendMode);
12180
12196
  opacity && (canvas.opacity *= opacity);
12181
12197
  transform && canvas.transform(transform);
12182
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12198
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12183
12199
  canvas.restore();
12184
12200
  } else {
12185
12201
  if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
12186
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12202
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
12187
12203
  }
12188
12204
  }
12189
12205
 
12190
12206
  function getImageRenderScaleData(paint, ui, canvas, _renderOptions) {
12191
12207
  const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), {data: data} = paint;
12208
+ if (paint.brush) PaintImage.addBrushScale(scaleData, paint, ui);
12192
12209
  if (canvas) {
12193
12210
  const {pixelRatio: pixelRatio} = canvas;
12194
12211
  scaleData.scaleX *= pixelRatio;
@@ -12205,6 +12222,7 @@ function recycleImage(attrName, data) {
12205
12222
  const paints = data["_" + attrName];
12206
12223
  if (isArray(paints)) {
12207
12224
  let paint, image, recycleMap, input, url;
12225
+ const ui = data.__leaf;
12208
12226
  for (let i = 0, len = paints.length; i < len; i++) {
12209
12227
  paint = paints[i];
12210
12228
  image = paint.image;
@@ -12213,7 +12231,8 @@ function recycleImage(attrName, data) {
12213
12231
  if (!recycleMap) recycleMap = {};
12214
12232
  recycleMap[url] = true;
12215
12233
  ImageManager.recyclePaint(paint);
12216
- if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, data.__leaf);
12234
+ if (paint.brush) PaintImage.recycleBrush(paint, ui);
12235
+ if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, ui);
12217
12236
  if (image.loading) {
12218
12237
  if (!input) {
12219
12238
  input = data.__input && data.__input[attrName] || [];