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