leafer-game 2.0.9 → 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/web.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.0.9";
6668
+ const version = "2.1.1";
6667
6669
  const debug$5 = Debug.get("LeaferCanvas");
6668
6670
  class LeaferCanvas extends LeaferCanvasBase {
6669
6671
  set zIndex(zIndex) {
@@ -7806,8 +7808,8 @@ var LeaferUI = function(exports) {
7806
7808
  return this.__getRealStrokeWidth();
7807
7809
  }
7808
7810
  get __maxStrokeWidth() {
7809
- const t = this;
7810
- return t.__hasMultiStrokeStyle ? Math.max(t.__hasMultiStrokeStyle, t.strokeWidth) : t.strokeWidth;
7811
+ const t = this, strokeWidth = t.__hasStrokeSides || t.strokeWidth;
7812
+ return t.__hasMultiStrokeStyle ? Math.max(t.__hasMultiStrokeStyle, strokeWidth) : strokeWidth;
7811
7813
  }
7812
7814
  get __hasMultiPaint() {
7813
7815
  const t = this;
@@ -7875,7 +7877,7 @@ var LeaferUI = function(exports) {
7875
7877
  const isStr = isString(value);
7876
7878
  if (isStr || value && isObject(value[0])) {
7877
7879
  this.__setInput("path", value);
7878
- this._path = isStr ? parse(value) : objectToCanvasData(value);
7880
+ this._path = isStr ? parse(value, this.__useArrow) : objectToCanvasData(value);
7879
7881
  } else {
7880
7882
  if (this.__input) this.__removeInput("path");
7881
7883
  this._path = value;
@@ -7908,6 +7910,10 @@ var LeaferUI = function(exports) {
7908
7910
  }
7909
7911
  return strokeWidth;
7910
7912
  }
7913
+ __checkComplex() {
7914
+ const t = this;
7915
+ stintSet$3(t, "__complex", t.__isFills || t.__isStrokes || t.cornerRadius || t.__useEffect);
7916
+ }
7911
7917
  __setPaint(attrName, value) {
7912
7918
  this.__setInput(attrName, value);
7913
7919
  const layout = this.__leaf.__layout;
@@ -7977,7 +7983,11 @@ var LeaferUI = function(exports) {
7977
7983
  return !this.__pathInputed;
7978
7984
  }
7979
7985
  }
7980
- class PolygonData extends LineData {}
7986
+ class PolygonData extends UIData {
7987
+ get __usePathBox() {
7988
+ return this.points || this.__pathInputed;
7989
+ }
7990
+ }
7981
7991
  class StarData extends UIData {
7982
7992
  get __boxStroke() {
7983
7993
  return !this.__pathInputed;
@@ -8079,7 +8089,7 @@ var LeaferUI = function(exports) {
8079
8089
  if ((data.stroke || data.hitStroke === "all") && strokeWidth && strokeAlign !== "inside") {
8080
8090
  boxSpread = spread = strokeAlign === "center" ? strokeWidth / 2 : strokeWidth;
8081
8091
  if (!data.__boxStroke || data.__useArrow) {
8082
- const miterLimitAddWidth = data.__isLinePath ? 0 : 10 * spread;
8092
+ const miterLimitAddWidth = data.__isLinePath ? 0 : (data.strokeJoin === "miter" ? 10 : 1) * spread;
8083
8093
  const storkeCapAddWidth = data.strokeCap === "none" ? 0 : strokeWidth;
8084
8094
  spread += Math.max(miterLimitAddWidth, storkeCapAddWidth);
8085
8095
  }
@@ -8122,7 +8132,7 @@ var LeaferUI = function(exports) {
8122
8132
  data.__useEffect = !!(shadow || otherEffect);
8123
8133
  }
8124
8134
  data.__checkSingle();
8125
- stintSet$2(data, "__complex", data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect);
8135
+ data.__checkComplex();
8126
8136
  },
8127
8137
  __drawFast(canvas, options) {
8128
8138
  drawFast(this, canvas, options);
@@ -9216,7 +9226,7 @@ var LeaferUI = function(exports) {
9216
9226
  __decorate([ dataType(false) ], exports.Canvas.prototype, "safeResize", void 0);
9217
9227
  __decorate([ resizeType() ], exports.Canvas.prototype, "contextSettings", void 0);
9218
9228
  exports.Canvas = __decorate([ registerUI() ], exports.Canvas);
9219
- const {copyAndSpread: copyAndSpread$1, includes: includes, spread: spread, setList: setList} = BoundsHelper, {stintSet: stintSet$1} = DataHelper;
9229
+ const {copyAndSpread: copyAndSpread$1, includes: includes, setList: setList} = BoundsHelper, {stintSet: stintSet$1} = DataHelper;
9220
9230
  exports.Text = class Text extends exports.UI {
9221
9231
  get __tag() {
9222
9232
  return "Text";
@@ -9243,9 +9253,10 @@ var LeaferUI = function(exports) {
9243
9253
  const {fontSize: fontSize, italic: italic, padding: padding, __autoWidth: autoWidth, __autoHeight: autoHeight} = data;
9244
9254
  this.__updateTextDrawData();
9245
9255
  const {bounds: contentBounds} = data.__textDrawData;
9256
+ console.log(contentBounds);
9246
9257
  const b = layout.boxBounds;
9247
9258
  layout.contentBounds = contentBounds;
9248
- if (data.__lineHeight < fontSize) spread(contentBounds, fontSize / 2);
9259
+ if (data.__lineHeight < fontSize) layout.renderChanged = true;
9249
9260
  if (autoWidth || autoHeight) {
9250
9261
  b.x = autoWidth ? contentBounds.x : 0;
9251
9262
  b.y = autoHeight ? contentBounds.y : 0;
@@ -9265,6 +9276,8 @@ var LeaferUI = function(exports) {
9265
9276
  __updateRenderSpread() {
9266
9277
  let spread = super.__updateRenderSpread();
9267
9278
  if (!spread) spread = this.isOverflow ? 1 : 0;
9279
+ const {__lineHeight: __lineHeight, fontSize: fontSize} = this.__;
9280
+ if (__lineHeight < fontSize) spread = FourNumberHelper.max(spread, (fontSize - __lineHeight) / 2);
9268
9281
  return spread;
9269
9282
  }
9270
9283
  __updateRenderBounds() {
@@ -11384,8 +11397,8 @@ var LeaferUI = function(exports) {
11384
11397
  }
11385
11398
  }
11386
11399
  }
11387
- data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
11388
11400
  if (leafPaints.length) {
11401
+ data["_" + attrName] = leafPaints;
11389
11402
  if (leafPaints.every(item => item.isTransparent)) {
11390
11403
  if (leafPaints.some(item => item.image)) isAlphaPixel = true;
11391
11404
  isTransparent = true;
@@ -11400,6 +11413,7 @@ var LeaferUI = function(exports) {
11400
11413
  }
11401
11414
  } else {
11402
11415
  data.__removePaint(attrName, false);
11416
+ data["_" + attrName] = "";
11403
11417
  }
11404
11418
  }
11405
11419
  function getLeafPaint(attrName, paint, ui) {
@@ -11543,11 +11557,12 @@ var LeaferUI = function(exports) {
11543
11557
  needUpdate = false;
11544
11558
  }
11545
11559
  }
11560
+ if (paint.mode === "brush") PaintImage.brush(leafPaint);
11546
11561
  if (!leafPaint.data) {
11547
11562
  PaintImage.createData(leafPaint, image, paint, boxBounds);
11548
- const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
11549
- const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
11550
- if (clip || opacity && opacity < 1 || blendMode) leafPaint.complex = clip ? 2 : true;
11563
+ const {transform: transform} = leafPaint.data, {opacity: opacity} = paint;
11564
+ const clip = (transform && !transform.onlyScale || data.path || data.cornerRadius) && !leafPaint.brush;
11565
+ if (clip || opacity && opacity < 1 || paint.blendMode) leafPaint.complex = clip ? 2 : true;
11551
11566
  }
11552
11567
  if (paint.filter) PaintImage.applyFilter(leafPaint, image, paint.filter, ui);
11553
11568
  return needUpdate;
@@ -11626,6 +11641,7 @@ var LeaferUI = function(exports) {
11626
11641
  break;
11627
11642
 
11628
11643
  case "repeat":
11644
+ case "brush":
11629
11645
  if (!sameBox || scaleX || rotation || skew) PaintImage.repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
11630
11646
  if (!repeat) data.repeat = "repeat";
11631
11647
  const count = isObject(repeat);
@@ -11753,7 +11769,7 @@ var LeaferUI = function(exports) {
11753
11769
  let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
11754
11770
  if (paint.patternId !== id && !ui.destroyed) {
11755
11771
  if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
11756
- const {image: image, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
11772
+ const {image: image, brush: brush, data: data} = paint, {opacity: opacity} = paint.originPaint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
11757
11773
  let imageMatrix, xGap, yGap, {width: width, height: height} = image;
11758
11774
  if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
11759
11775
  width *= scaleX;
@@ -11761,6 +11777,10 @@ var LeaferUI = function(exports) {
11761
11777
  if (gap) {
11762
11778
  xGap = gap.x * scaleX / abs$2(data.scaleX || 1);
11763
11779
  yGap = gap.y * scaleY / abs$2(data.scaleY || 1);
11780
+ if (brush) {
11781
+ const brushScale = PaintImage.getBrushScale(paint, ui);
11782
+ xGap /= brushScale, yGap /= brushScale;
11783
+ }
11764
11784
  }
11765
11785
  if (transform || scaleX !== 1 || scaleY !== 1) {
11766
11786
  scaleX *= getFloorScale(width + (xGap || 0));
@@ -11770,7 +11790,7 @@ var LeaferUI = function(exports) {
11770
11790
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
11771
11791
  }
11772
11792
  const imageCanvas = image.getCanvas(width, height, opacity, undefined, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
11773
- const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
11793
+ const pattern = brush ? imageCanvas : image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
11774
11794
  paint.style = pattern;
11775
11795
  paint.patternId = id;
11776
11796
  }
@@ -11789,9 +11809,9 @@ var LeaferUI = function(exports) {
11789
11809
  }
11790
11810
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
11791
11811
  const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
11792
- const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
11812
+ const {image: image, brush: brush, data: data, originPaint: originPaint} = paint, {exporting: exporting, snapshot: snapshot} = renderOptions;
11793
11813
  if (!data || paint.patternId === id && !exporting || snapshot) {
11794
- return false;
11814
+ if (!(brush && paint.style)) return false;
11795
11815
  } else {
11796
11816
  if (drawImage) {
11797
11817
  if (data.repeat) {
@@ -11805,17 +11825,17 @@ var LeaferUI = function(exports) {
11805
11825
  canvas.fillStyle = paint.style || "#000";
11806
11826
  canvas.fill();
11807
11827
  }
11808
- PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
11809
- return true;
11810
11828
  } else {
11811
11829
  if (!paint.style || originPaint.sync || exporting) PaintImage.createPattern(paint, ui, canvas, renderOptions); else PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
11812
- return false;
11830
+ if (!(brush && paint.style)) return false;
11813
11831
  }
11814
11832
  }
11833
+ PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
11834
+ return true;
11815
11835
  }
11816
11836
  function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
11817
- const {data: data, image: image, complex: complex} = paint;
11818
- let {width: width, height: height} = image;
11837
+ const {data: data, image: image, brush: brush, complex: complex} = paint;
11838
+ let {width: width, height: height} = image, view = brush || image;
11819
11839
  if (complex) {
11820
11840
  const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
11821
11841
  canvas.save();
@@ -11823,15 +11843,16 @@ var LeaferUI = function(exports) {
11823
11843
  blendMode && (canvas.blendMode = blendMode);
11824
11844
  opacity && (canvas.opacity *= opacity);
11825
11845
  transform && canvas.transform(transform);
11826
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
11846
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
11827
11847
  canvas.restore();
11828
11848
  } else {
11829
11849
  if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
11830
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
11850
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
11831
11851
  }
11832
11852
  }
11833
11853
  function getImageRenderScaleData(paint, ui, canvas, _renderOptions) {
11834
11854
  const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), {data: data} = paint;
11855
+ if (paint.brush) PaintImage.addBrushScale(scaleData, paint, ui);
11835
11856
  if (canvas) {
11836
11857
  const {pixelRatio: pixelRatio} = canvas;
11837
11858
  scaleData.scaleX *= pixelRatio;
@@ -11847,6 +11868,7 @@ var LeaferUI = function(exports) {
11847
11868
  const paints = data["_" + attrName];
11848
11869
  if (isArray(paints)) {
11849
11870
  let paint, image, recycleMap, input, url;
11871
+ const ui = data.__leaf;
11850
11872
  for (let i = 0, len = paints.length; i < len; i++) {
11851
11873
  paint = paints[i];
11852
11874
  image = paint.image;
@@ -11855,7 +11877,8 @@ var LeaferUI = function(exports) {
11855
11877
  if (!recycleMap) recycleMap = {};
11856
11878
  recycleMap[url] = true;
11857
11879
  ImageManager.recyclePaint(paint);
11858
- if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, data.__leaf);
11880
+ if (paint.brush) PaintImage.recycleBrush(paint, ui);
11881
+ if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, ui);
11859
11882
  if (image.loading) {
11860
11883
  if (!input) {
11861
11884
  input = data.__input && data.__input[attrName] || [];