leafer-game 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/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.1.0";
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) {
@@ -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;
@@ -7981,7 +7983,11 @@ var LeaferUI = function(exports) {
7981
7983
  return !this.__pathInputed;
7982
7984
  }
7983
7985
  }
7984
- class PolygonData extends LineData {}
7986
+ class PolygonData extends UIData {
7987
+ get __usePathBox() {
7988
+ return this.points || this.__pathInputed;
7989
+ }
7990
+ }
7985
7991
  class StarData extends UIData {
7986
7992
  get __boxStroke() {
7987
7993
  return !this.__pathInputed;
@@ -8083,7 +8089,7 @@ var LeaferUI = function(exports) {
8083
8089
  if ((data.stroke || data.hitStroke === "all") && strokeWidth && strokeAlign !== "inside") {
8084
8090
  boxSpread = spread = strokeAlign === "center" ? strokeWidth / 2 : strokeWidth;
8085
8091
  if (!data.__boxStroke || data.__useArrow) {
8086
- const miterLimitAddWidth = data.__isLinePath ? 0 : 10 * spread;
8092
+ const miterLimitAddWidth = data.__isLinePath ? 0 : (data.strokeJoin === "miter" ? 10 : 1) * spread;
8087
8093
  const storkeCapAddWidth = data.strokeCap === "none" ? 0 : strokeWidth;
8088
8094
  spread += Math.max(miterLimitAddWidth, storkeCapAddWidth);
8089
8095
  }
@@ -9220,7 +9226,7 @@ var LeaferUI = function(exports) {
9220
9226
  __decorate([ dataType(false) ], exports.Canvas.prototype, "safeResize", void 0);
9221
9227
  __decorate([ resizeType() ], exports.Canvas.prototype, "contextSettings", void 0);
9222
9228
  exports.Canvas = __decorate([ registerUI() ], exports.Canvas);
9223
- 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;
9224
9230
  exports.Text = class Text extends exports.UI {
9225
9231
  get __tag() {
9226
9232
  return "Text";
@@ -9247,9 +9253,10 @@ var LeaferUI = function(exports) {
9247
9253
  const {fontSize: fontSize, italic: italic, padding: padding, __autoWidth: autoWidth, __autoHeight: autoHeight} = data;
9248
9254
  this.__updateTextDrawData();
9249
9255
  const {bounds: contentBounds} = data.__textDrawData;
9256
+ console.log(contentBounds);
9250
9257
  const b = layout.boxBounds;
9251
9258
  layout.contentBounds = contentBounds;
9252
- if (data.__lineHeight < fontSize) spread(contentBounds, fontSize / 2);
9259
+ if (data.__lineHeight < fontSize) layout.renderChanged = true;
9253
9260
  if (autoWidth || autoHeight) {
9254
9261
  b.x = autoWidth ? contentBounds.x : 0;
9255
9262
  b.y = autoHeight ? contentBounds.y : 0;
@@ -9269,6 +9276,8 @@ var LeaferUI = function(exports) {
9269
9276
  __updateRenderSpread() {
9270
9277
  let spread = super.__updateRenderSpread();
9271
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);
9272
9281
  return spread;
9273
9282
  }
9274
9283
  __updateRenderBounds() {
@@ -11388,8 +11397,8 @@ var LeaferUI = function(exports) {
11388
11397
  }
11389
11398
  }
11390
11399
  }
11391
- data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
11392
11400
  if (leafPaints.length) {
11401
+ data["_" + attrName] = leafPaints;
11393
11402
  if (leafPaints.every(item => item.isTransparent)) {
11394
11403
  if (leafPaints.some(item => item.image)) isAlphaPixel = true;
11395
11404
  isTransparent = true;
@@ -11404,6 +11413,7 @@ var LeaferUI = function(exports) {
11404
11413
  }
11405
11414
  } else {
11406
11415
  data.__removePaint(attrName, false);
11416
+ data["_" + attrName] = "";
11407
11417
  }
11408
11418
  }
11409
11419
  function getLeafPaint(attrName, paint, ui) {
@@ -11547,11 +11557,12 @@ var LeaferUI = function(exports) {
11547
11557
  needUpdate = false;
11548
11558
  }
11549
11559
  }
11560
+ if (paint.mode === "brush") PaintImage.brush(leafPaint);
11550
11561
  if (!leafPaint.data) {
11551
11562
  PaintImage.createData(leafPaint, image, paint, boxBounds);
11552
- const {transform: transform} = leafPaint.data, {opacity: opacity, blendMode: blendMode} = paint;
11553
- const clip = transform && !transform.onlyScale || data.path || data.cornerRadius;
11554
- 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;
11555
11566
  }
11556
11567
  if (paint.filter) PaintImage.applyFilter(leafPaint, image, paint.filter, ui);
11557
11568
  return needUpdate;
@@ -11630,6 +11641,7 @@ var LeaferUI = function(exports) {
11630
11641
  break;
11631
11642
 
11632
11643
  case "repeat":
11644
+ case "brush":
11633
11645
  if (!sameBox || scaleX || rotation || skew) PaintImage.repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
11634
11646
  if (!repeat) data.repeat = "repeat";
11635
11647
  const count = isObject(repeat);
@@ -11757,7 +11769,7 @@ var LeaferUI = function(exports) {
11757
11769
  let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
11758
11770
  if (paint.patternId !== id && !ui.destroyed) {
11759
11771
  if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
11760
- 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);
11761
11773
  let imageMatrix, xGap, yGap, {width: width, height: height} = image;
11762
11774
  if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
11763
11775
  width *= scaleX;
@@ -11765,6 +11777,10 @@ var LeaferUI = function(exports) {
11765
11777
  if (gap) {
11766
11778
  xGap = gap.x * scaleX / abs$2(data.scaleX || 1);
11767
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
+ }
11768
11784
  }
11769
11785
  if (transform || scaleX !== 1 || scaleY !== 1) {
11770
11786
  scaleX *= getFloorScale(width + (xGap || 0));
@@ -11774,7 +11790,7 @@ var LeaferUI = function(exports) {
11774
11790
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
11775
11791
  }
11776
11792
  const imageCanvas = image.getCanvas(width, height, opacity, undefined, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace);
11777
- 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);
11778
11794
  paint.style = pattern;
11779
11795
  paint.patternId = id;
11780
11796
  }
@@ -11793,9 +11809,9 @@ var LeaferUI = function(exports) {
11793
11809
  }
11794
11810
  function checkImage(paint, drawImage, ui, canvas, renderOptions) {
11795
11811
  const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + "-" + scaleY;
11796
- 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;
11797
11813
  if (!data || paint.patternId === id && !exporting || snapshot) {
11798
- return false;
11814
+ if (!(brush && paint.style)) return false;
11799
11815
  } else {
11800
11816
  if (drawImage) {
11801
11817
  if (data.repeat) {
@@ -11809,17 +11825,17 @@ var LeaferUI = function(exports) {
11809
11825
  canvas.fillStyle = paint.style || "#000";
11810
11826
  canvas.fill();
11811
11827
  }
11812
- PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
11813
- return true;
11814
11828
  } else {
11815
11829
  if (!paint.style || originPaint.sync || exporting) PaintImage.createPattern(paint, ui, canvas, renderOptions); else PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
11816
- return false;
11830
+ if (!(brush && paint.style)) return false;
11817
11831
  }
11818
11832
  }
11833
+ PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
11834
+ return true;
11819
11835
  }
11820
11836
  function drawImage(paint, imageScaleX, imageScaleY, ui, canvas, _renderOptions) {
11821
- const {data: data, image: image, complex: complex} = paint;
11822
- 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;
11823
11839
  if (complex) {
11824
11840
  const {blendMode: blendMode, opacity: opacity} = paint.originPaint, {transform: transform} = data;
11825
11841
  canvas.save();
@@ -11827,15 +11843,16 @@ var LeaferUI = function(exports) {
11827
11843
  blendMode && (canvas.blendMode = blendMode);
11828
11844
  opacity && (canvas.opacity *= opacity);
11829
11845
  transform && canvas.transform(transform);
11830
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
11846
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
11831
11847
  canvas.restore();
11832
11848
  } else {
11833
11849
  if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
11834
- image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
11850
+ view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY);
11835
11851
  }
11836
11852
  }
11837
11853
  function getImageRenderScaleData(paint, ui, canvas, _renderOptions) {
11838
11854
  const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), {data: data} = paint;
11855
+ if (paint.brush) PaintImage.addBrushScale(scaleData, paint, ui);
11839
11856
  if (canvas) {
11840
11857
  const {pixelRatio: pixelRatio} = canvas;
11841
11858
  scaleData.scaleX *= pixelRatio;
@@ -11851,6 +11868,7 @@ var LeaferUI = function(exports) {
11851
11868
  const paints = data["_" + attrName];
11852
11869
  if (isArray(paints)) {
11853
11870
  let paint, image, recycleMap, input, url;
11871
+ const ui = data.__leaf;
11854
11872
  for (let i = 0, len = paints.length; i < len; i++) {
11855
11873
  paint = paints[i];
11856
11874
  image = paint.image;
@@ -11859,7 +11877,8 @@ var LeaferUI = function(exports) {
11859
11877
  if (!recycleMap) recycleMap = {};
11860
11878
  recycleMap[url] = true;
11861
11879
  ImageManager.recyclePaint(paint);
11862
- 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);
11863
11882
  if (image.loading) {
11864
11883
  if (!input) {
11865
11884
  input = data.__input && data.__input[attrName] || [];