@leafer-game/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.
package/dist/worker.js CHANGED
@@ -2872,7 +2872,7 @@ var LeaferUI = function(exports) {
2872
2872
  return needConvert ? PathConvert.toCanvasData(data, curveMode) : data;
2873
2873
  },
2874
2874
  toCanvasData(old, curveMode) {
2875
- let x = 0, y = 0, x1 = 0, y1 = 0, i = 0, len = old.length, controlX, controlY, command, lastCommand, smooth;
2875
+ let x = 0, y = 0, x1 = 0, y1 = 0, startX = 0, startY = 0, i = 0, len = old.length, controlX, controlY, command, lastCommand, smooth;
2876
2876
  const data = [];
2877
2877
  while (i < len) {
2878
2878
  command = old[i];
@@ -2884,7 +2884,8 @@ var LeaferUI = function(exports) {
2884
2884
  case M$5:
2885
2885
  x = old[i + 1];
2886
2886
  y = old[i + 2];
2887
- data.push(M$5, x, y);
2887
+ if (lastCommand === command) data.push(L$6, x, y); else data.push(M$5, x, y), startX = x,
2888
+ startY = y;
2888
2889
  i += 3;
2889
2890
  break;
2890
2891
 
@@ -2999,6 +3000,8 @@ var LeaferUI = function(exports) {
2999
3000
  case z:
3000
3001
  case Z$5:
3001
3002
  data.push(Z$5);
3003
+ x = startX;
3004
+ y = startY;
3002
3005
  i++;
3003
3006
  break;
3004
3007
 
@@ -5680,12 +5683,13 @@ var LeaferUI = function(exports) {
5680
5683
  if (this.__hasWorldEvent) BoundsEvent.emitWorld(this);
5681
5684
  },
5682
5685
  __updateLocalBounds() {
5683
- const layout = this.__layout;
5686
+ const layout = this.__layout, data = this.__;
5684
5687
  if (layout.boxChanged) {
5685
- if (!this.__.__pathInputed) this.__updatePath();
5688
+ if (!data.__pathInputed) this.__updatePath();
5686
5689
  this.__updateRenderPath();
5687
5690
  this.__updateBoxBounds();
5688
5691
  layout.resized = "inner";
5692
+ if (data.__strokeGeometry) data.__strokeGeometry = undefined;
5689
5693
  }
5690
5694
  if (layout.localBoxChanged) {
5691
5695
  if (this.__local) this.__updateLocalBoxBounds();
@@ -5708,6 +5712,7 @@ var LeaferUI = function(exports) {
5708
5712
  if (layout.renderSpread || layout.strokeSpread !== layout.strokeBoxSpread) layout.renderChanged = true;
5709
5713
  if (this.parent) this.parent.__layout.strokeChange();
5710
5714
  layout.resized = "inner";
5715
+ if (data.__strokeGeometry) data.__strokeGeometry = undefined;
5711
5716
  }
5712
5717
  if (layout.renderChanged) {
5713
5718
  layout.renderSpread = this.__updateRenderSpread();
@@ -6663,7 +6668,7 @@ var LeaferUI = function(exports) {
6663
6668
  this.levelMap = null;
6664
6669
  }
6665
6670
  }
6666
- const version = "2.1.0";
6671
+ const version = "2.1.2";
6667
6672
  class LeaferCanvas extends LeaferCanvasBase {
6668
6673
  get allowBackgroundColor() {
6669
6674
  return true;
@@ -7681,7 +7686,7 @@ var LeaferUI = function(exports) {
7681
7686
  const isStr = isString(value);
7682
7687
  if (isStr || value && isObject(value[0])) {
7683
7688
  this.__setInput("path", value);
7684
- this._path = isStr ? parse(value) : objectToCanvasData(value);
7689
+ this._path = isStr ? parse(value, this.__useArrow) : objectToCanvasData(value);
7685
7690
  } else {
7686
7691
  if (this.__input) this.__removeInput("path");
7687
7692
  this._path = value;
@@ -7787,7 +7792,11 @@ var LeaferUI = function(exports) {
7787
7792
  return !this.__pathInputed;
7788
7793
  }
7789
7794
  }
7790
- class PolygonData extends LineData {}
7795
+ class PolygonData extends UIData {
7796
+ get __usePathBox() {
7797
+ return this.points || this.__pathInputed;
7798
+ }
7799
+ }
7791
7800
  class StarData extends UIData {
7792
7801
  get __boxStroke() {
7793
7802
  return !this.__pathInputed;
@@ -7889,7 +7898,7 @@ var LeaferUI = function(exports) {
7889
7898
  if ((data.stroke || data.hitStroke === "all") && strokeWidth && strokeAlign !== "inside") {
7890
7899
  boxSpread = spread = strokeAlign === "center" ? strokeWidth / 2 : strokeWidth;
7891
7900
  if (!data.__boxStroke || data.__useArrow) {
7892
- const miterLimitAddWidth = data.__isLinePath ? 0 : 10 * spread;
7901
+ const miterLimitAddWidth = data.__isLinePath ? 0 : (data.strokeJoin === "miter" ? 10 : 1) * spread;
7893
7902
  const storkeCapAddWidth = data.strokeCap === "none" ? 0 : strokeWidth;
7894
7903
  spread += Math.max(miterLimitAddWidth, storkeCapAddWidth);
7895
7904
  }
@@ -9026,7 +9035,7 @@ var LeaferUI = function(exports) {
9026
9035
  __decorate([ dataType(false) ], exports.Canvas.prototype, "safeResize", void 0);
9027
9036
  __decorate([ resizeType() ], exports.Canvas.prototype, "contextSettings", void 0);
9028
9037
  exports.Canvas = __decorate([ registerUI() ], exports.Canvas);
9029
- const {copyAndSpread: copyAndSpread$1, includes: includes, spread: spread, setList: setList} = BoundsHelper, {stintSet: stintSet$1} = DataHelper;
9038
+ const {copyAndSpread: copyAndSpread$1, includes: includes, setList: setList} = BoundsHelper, {stintSet: stintSet$1} = DataHelper;
9030
9039
  exports.Text = class Text extends exports.UI {
9031
9040
  get __tag() {
9032
9041
  return "Text";
@@ -9055,7 +9064,7 @@ var LeaferUI = function(exports) {
9055
9064
  const {bounds: contentBounds} = data.__textDrawData;
9056
9065
  const b = layout.boxBounds;
9057
9066
  layout.contentBounds = contentBounds;
9058
- if (data.__lineHeight < fontSize) spread(contentBounds, fontSize / 2);
9067
+ if (data.__lineHeight < fontSize) layout.renderChanged = true;
9059
9068
  if (autoWidth || autoHeight) {
9060
9069
  b.x = autoWidth ? contentBounds.x : 0;
9061
9070
  b.y = autoHeight ? contentBounds.y : 0;
@@ -9075,6 +9084,8 @@ var LeaferUI = function(exports) {
9075
9084
  __updateRenderSpread() {
9076
9085
  let spread = super.__updateRenderSpread();
9077
9086
  if (!spread) spread = this.isOverflow ? 1 : 0;
9087
+ const {__lineHeight: __lineHeight, fontSize: fontSize} = this.__;
9088
+ if (__lineHeight < fontSize) spread = FourNumberHelper.max(spread, (fontSize - __lineHeight) / 2);
9078
9089
  return spread;
9079
9090
  }
9080
9091
  __updateRenderBounds() {
@@ -10865,8 +10876,8 @@ var LeaferUI = function(exports) {
10865
10876
  }
10866
10877
  }
10867
10878
  }
10868
- data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
10869
10879
  if (leafPaints.length) {
10880
+ data["_" + attrName] = leafPaints;
10870
10881
  if (leafPaints.every(item => item.isTransparent)) {
10871
10882
  if (leafPaints.some(item => item.image)) isAlphaPixel = true;
10872
10883
  isTransparent = true;
@@ -10881,6 +10892,7 @@ var LeaferUI = function(exports) {
10881
10892
  }
10882
10893
  } else {
10883
10894
  data.__removePaint(attrName, false);
10895
+ data["_" + attrName] = "";
10884
10896
  }
10885
10897
  }
10886
10898
  function getLeafPaint(attrName, paint, ui) {
@@ -11024,11 +11036,12 @@ var LeaferUI = function(exports) {
11024
11036
  needUpdate = false;
11025
11037
  }
11026
11038
  }
11039
+ if (paint.mode === "brush") PaintImage.brush(leafPaint);
11027
11040
  if (!leafPaint.data) {
11028
11041
  PaintImage.createData(leafPaint, image, paint, boxBounds);
11029
- const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
11030
- const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
11031
- if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
11042
+ const {transform: transform} = leafPaint.data, {opacity: opacity} = paint;
11043
+ const clip = (transform && !transform.onlyScale || data.path || data.cornerRadius) && !leafPaint.brush;
11044
+ if (clip || opacity && opacity < 1 || paint.blendMode) leafPaint.complex = clip ? 2 : true;
11032
11045
  }
11033
11046
  if (paint.filter) PaintImage.applyFilter(leafPaint, image, paint.filter, ui);
11034
11047
  return needUpdate;
@@ -11107,6 +11120,7 @@ var LeaferUI = function(exports) {
11107
11120
  break;
11108
11121
 
11109
11122
  case "repeat":
11123
+ case "brush":
11110
11124
  if (!sameBox || scaleX || rotation || skew) PaintImage.repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
11111
11125
  if (!repeat) data.repeat = "repeat";
11112
11126
  const count = isObject(repeat);
@@ -11234,7 +11248,7 @@ var LeaferUI = function(exports) {
11234
11248
  let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
11235
11249
  if (paint.patternId !== id && !ui.destroyed) {
11236
11250
  if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
11237
- const {image: image, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
11251
+ const {image: image, brush: brush, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
11238
11252
  let imageMatrix, xGap, yGap, {width: width, height: height} = image;
11239
11253
  if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
11240
11254
  width *= scaleX;
@@ -11242,6 +11256,10 @@ var LeaferUI = function(exports) {
11242
11256
  if (gap) {
11243
11257
  xGap = gap.x * scaleX / abs$2(data.scaleX || 1);
11244
11258
  yGap = gap.y * scaleY / abs$2(data.scaleY || 1);
11259
+ if (brush) {
11260
+ const brushScale = PaintImage.getBrushScale(paint, ui);
11261
+ xGap /= brushScale, yGap /= brushScale;
11262
+ }
11245
11263
  }
11246
11264
  if (transform || scaleX !== 1 || scaleY !== 1) {
11247
11265
  scaleX *= getFloorScale(width + (xGap || 0));
@@ -11251,7 +11269,7 @@ var LeaferUI = function(exports) {
11251
11269
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
11252
11270
  }
11253
11271
  const imageCanvas = image.getCanvas(width, height, opacity, undefined, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
11254
- const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
11272
+ const pattern = brush ? imageCanvas : image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
11255
11273
  paint.style = pattern;
11256
11274
  paint.patternId = id;
11257
11275
  }
@@ -11270,9 +11288,9 @@ var LeaferUI = function(exports) {
11270
11288
  }
11271
11289
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
11272
11290
  const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
11273
- const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
11291
+ const {image: image, brush: brush, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
11274
11292
  if (!data || paint.patternId === id && !exporting || snapshot) {
11275
- return false;
11293
+ if (!(brush && paint.style)) return false;
11276
11294
  } else {
11277
11295
  if (drawImage) {
11278
11296
  if (data.repeat) {
@@ -11286,17 +11304,17 @@ var LeaferUI = function(exports) {
11286
11304
  canvas.fillStyle = paint.style || "#000";
11287
11305
  canvas.fill();
11288
11306
  }
11289
- PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
11290
- return true;
11291
11307
  } else {
11292
11308
  if (!paint.style || originPaint.sync || exporting) PaintImage.createPattern(paint, ui, canvas, renderOptions); else PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
11293
- return false;
11309
+ if (!(brush && paint.style)) return false;
11294
11310
  }
11295
11311
  }
11312
+ PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
11313
+ return true;
11296
11314
  }
11297
11315
  function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
11298
- const {data: data, image: image, complex: complex} = paint;
11299
- let {width: width, height: height} = image;
11316
+ const {data: data, image: image, brush: brush, complex: complex} = paint;
11317
+ let {width: width, height: height} = image, view = brush || image;
11300
11318
  if (complex) {
11301
11319
  const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
11302
11320
  canvas.save();
@@ -11304,15 +11322,16 @@ var LeaferUI = function(exports) {
11304
11322
  blendMode && (canvas.blendMode = blendMode);
11305
11323
  opacity && (canvas.opacity *= opacity);
11306
11324
  transform && canvas.transform(transform);
11307
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
11325
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
11308
11326
  canvas.restore();
11309
11327
  } else {
11310
11328
  if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
11311
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
11329
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
11312
11330
  }
11313
11331
  }
11314
11332
  function getImageRenderScaleData(paint, ui, canvas, _renderOptions) {
11315
11333
  const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), {data: data} = paint;
11334
+ if (paint.brush) PaintImage.addBrushScale(scaleData, paint, ui);
11316
11335
  if (canvas) {
11317
11336
  const {pixelRatio: pixelRatio} = canvas;
11318
11337
  scaleData.scaleX *= pixelRatio;
@@ -11328,6 +11347,7 @@ var LeaferUI = function(exports) {
11328
11347
  const paints = data["_" + attrName];
11329
11348
  if (isArray(paints)) {
11330
11349
  let paint, image, recycleMap, input, url;
11350
+ const ui = data.__leaf;
11331
11351
  for (let i = 0, len = paints.length; i < len; i++) {
11332
11352
  paint = paints[i];
11333
11353
  image = paint.image;
@@ -11336,7 +11356,8 @@ var LeaferUI = function(exports) {
11336
11356
  if (!recycleMap) recycleMap = {};
11337
11357
  recycleMap[url] = true;
11338
11358
  ImageManager.recyclePaint(paint);
11339
- if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, data.__leaf);
11359
+ if (paint.brush) PaintImage.recycleBrush(paint, ui);
11360
+ if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, ui);
11340
11361
  if (image.loading) {
11341
11362
  if (!input) {
11342
11363
  input = data.__input && data.__input[attrName] || [];