@leafer-game/miniapp 2.2.9 → 2.2.11

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.
@@ -4607,39 +4607,44 @@ function doVisible(leaf, key, value, oldValue) {
4607
4607
  }
4608
4608
  }
4609
4609
 
4610
+ function sortParentChange(parent) {
4611
+ parent.__layout.childrenSortChange();
4612
+ if (parent.__.flow) parent.__layout.boxChange();
4613
+ }
4614
+
4610
4615
  function sortType(defaultValue) {
4611
4616
  return decorateLeafAttr(defaultValue, key => attr({
4612
4617
  set(value) {
4613
4618
  if (this.__setAttr(key, value)) {
4614
- this.waitParent(() => {
4615
- const {parent: parent} = this;
4616
- parent.__layout.childrenSortChange();
4617
- if (parent.__.flow) parent.__layout.boxChange();
4618
- });
4619
+ this.waitParentChange(sortParentChange);
4619
4620
  }
4620
4621
  }
4621
4622
  }));
4622
4623
  }
4623
4624
 
4625
+ function maskParentChange(parent) {
4626
+ parent.__updateMask();
4627
+ }
4628
+
4624
4629
  function maskType(defaultValue, updateSelf) {
4625
4630
  return decorateLeafAttr(defaultValue, key => attr({
4626
4631
  set(value) {
4627
4632
  if (this.__setAttr(key, value)) {
4628
4633
  this.__layout.boxChanged || this.__layout.boxChange();
4629
- updateSelf ? this.__updateMask() : this.waitParent(() => {
4630
- this.parent.__updateMask(value);
4631
- });
4634
+ updateSelf ? this.__updateMask() : this.waitParentChange(maskParentChange);
4632
4635
  }
4633
4636
  }
4634
4637
  }));
4635
4638
  }
4636
4639
 
4640
+ function eraserParentChange(parent) {
4641
+ parent.__updateEraser();
4642
+ }
4643
+
4637
4644
  function eraserType(defaultValue) {
4638
4645
  return decorateLeafAttr(defaultValue, key => attr({
4639
4646
  set(value) {
4640
- this.__setAttr(key, value) && this.waitParent(() => {
4641
- this.parent.__updateEraser(value);
4642
- });
4647
+ this.__setAttr(key, value) && this.waitParentChange(eraserParentChange);
4643
4648
  }
4644
4649
  }));
4645
4650
  }
@@ -6473,6 +6478,11 @@ let Leaf = class Leaf {
6473
6478
  this.__hasMask = this.__hasEraser = null;
6474
6479
  this.forceUpdate();
6475
6480
  }
6481
+ waitParentChange(item) {
6482
+ this.__parentChange || (this.__parentChange = []);
6483
+ if (!this.__parentChange.includes(item)) this.__parentChange.push(item);
6484
+ if (this.parent) item(this.parent, this);
6485
+ }
6476
6486
  waitParent(item, bind) {
6477
6487
  if (bind) item = item.bind(bind);
6478
6488
  this.parent ? item() : this.on(ChildEvent.ADD, item, "once");
@@ -6560,8 +6570,8 @@ let Leaf = class Leaf {
6560
6570
  __extraUpdate() {
6561
6571
  if (this.leaferIsReady) this.leafer.layouter.addExtra(this);
6562
6572
  }
6563
- __updateEraser(value) {
6564
- this.__hasEraser = value ? true : this.children.some(item => item.__.eraser);
6573
+ __updateEraser() {
6574
+ this.__hasEraser = this.children.some(item => item.__.eraser);
6565
6575
  }
6566
6576
  __renderEraser(canvas, options) {
6567
6577
  canvas.save();
@@ -6570,7 +6580,7 @@ let Leaf = class Leaf {
6570
6580
  canvas.clearRect(r.x, r.y, r.width, r.height);
6571
6581
  canvas.restore();
6572
6582
  }
6573
- __updateMask(_value) {
6583
+ __updateMask() {
6574
6584
  const hasMask = this.children.some(item => item.__.mask && item.__.visible && item.__.opacity);
6575
6585
  this.__hasMask = this.__.maskskip ? hasMask && 0 : hasMask;
6576
6586
  }
@@ -6824,6 +6834,7 @@ let Branch = class Branch extends Leaf {
6824
6834
  const childLayout = child.__layout;
6825
6835
  childLayout.boxChanged || childLayout.boxChange();
6826
6836
  childLayout.matrixChanged || childLayout.matrixChange();
6837
+ if (child.__parentChange) child.__parentChange.forEach(item => item(this, child));
6827
6838
  if (child.__bubbleMap) child.__emitLifeEvent(ChildEvent.ADD);
6828
6839
  if (this.isFrame) child.__bindFrame(this);
6829
6840
  if (this.leafer) {
@@ -7046,7 +7057,7 @@ class LeafLevelList {
7046
7057
  }
7047
7058
  }
7048
7059
 
7049
- const version = "2.2.9";
7060
+ const version = "2.2.11";
7050
7061
 
7051
7062
  class LeaferCanvas extends LeaferCanvasBase {
7052
7063
  get allowBackgroundColor() {
@@ -8750,7 +8761,7 @@ let UI = UI_1 = class UI extends Leaf {
8750
8761
  getPath(curve, pathForRender) {
8751
8762
  this.__layout.update();
8752
8763
  let path = pathForRender ? this.__.__pathForRender : this.__.path;
8753
- if (!path) pen.set(path = []), this.__drawPathByBox(pen, !pathForRender);
8764
+ if (!path) pen.set(path = []), this.__drawPathByBox(pen, "box", !pathForRender);
8754
8765
  return curve ? PathConvert.toCanvasData(path, true) : path;
8755
8766
  }
8756
8767
  getPathString(curve, pathForRender, floatLength) {
@@ -8788,10 +8799,10 @@ let UI = UI_1 = class UI extends Leaf {
8788
8799
  data.__usePointsMode ? PathDrawer.drawPathByPoints(canvas, data.points, data.closed) : this.__drawPathByData(canvas, data.path, true);
8789
8800
  }
8790
8801
  __drawPathByData(drawer, data, ignoreCornerRadius) {
8791
- data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, ignoreCornerRadius);
8802
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, "box", ignoreCornerRadius);
8792
8803
  }
8793
- __drawPathByBox(drawer, ignoreCornerRadius) {
8794
- const {x: x, y: y, width: width, height: height} = this.__layout.boxBounds;
8804
+ __drawPathByBox(drawer, boundsType = "box", ignoreCornerRadius) {
8805
+ const {x: x, y: y, width: width, height: height} = this.__layout[boundsType + "Bounds"];
8795
8806
  if (this.__.cornerRadius && !ignoreCornerRadius) {
8796
8807
  const {cornerRadius: cornerRadius} = this.__;
8797
8808
  drawer.roundRect(x, y, width, height, isNumber(cornerRadius) ? [ cornerRadius ] : cornerRadius);
@@ -9873,14 +9884,15 @@ let Text = class Text extends UI {
9873
9884
  }
9874
9885
  __updateTextDrawData() {
9875
9886
  const data = this.__;
9876
- const {lineHeight: lineHeight, letterSpacing: letterSpacing, fontFamily: fontFamily, fontSize: fontSize, fontWeight: fontWeight, italic: italic, textCase: textCase, textOverflow: textOverflow, padding: padding, width: width, height: height} = data;
9887
+ const {lineHeight: lineHeight, letterSpacing: letterSpacing, wordSpacing: wordSpacing, fontFamily: fontFamily, fontSize: fontSize, fontWeight: fontWeight, italic: italic, textCase: textCase, textOverflow: textOverflow, padding: padding, width: width, height: height} = data;
9877
9888
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
9878
9889
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
9890
+ data.__wordSpacing = UnitConvert.number(wordSpacing, fontSize);
9879
9891
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * .7) / 2;
9880
9892
  data.__font = `${italic ? "italic " : ""}${textCase === "small-caps" ? "small-caps " : ""}${fontWeight !== "normal" ? fontWeight + " " : ""}${fontSize || 12}px ${fontFamily || "caption"}`;
9881
9893
  stintSet$1(data, "__padding", padding && MathHelper.fourNumber(padding));
9882
9894
  stintSet$1(data, "__clipText", textOverflow !== "show" && !data.__autoSize);
9883
- stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.motionText || textCase !== "none");
9895
+ stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.__wordSpacing || data.motionText || textCase !== "none");
9884
9896
  data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === "") ? data.placeholder : data.text, this.__);
9885
9897
  }
9886
9898
  __updateBoxBounds() {
@@ -9978,6 +9990,8 @@ __decorate([ boundsType("none") ], Text.prototype, "textDecoration", void 0);
9978
9990
 
9979
9991
  __decorate([ boundsType(0) ], Text.prototype, "letterSpacing", void 0);
9980
9992
 
9993
+ __decorate([ boundsType(0) ], Text.prototype, "wordSpacing", void 0);
9994
+
9981
9995
  __decorate([ boundsType({
9982
9996
  type: "percent",
9983
9997
  value: 1.5
@@ -11720,7 +11734,7 @@ function fills(fills, ui, canvas, renderOptions) {
11720
11734
  if (scaleX !== 1) canvas.scale(scaleX, scaleY);
11721
11735
  }
11722
11736
  if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
11723
- fillPathOrText(ui, canvas, renderOptions);
11737
+ fillPathOrText(ui, canvas, renderOptions, true);
11724
11738
  canvas.restore();
11725
11739
  } else {
11726
11740
  if (originPaint.blendMode) {
@@ -11732,25 +11746,46 @@ function fills(fills, ui, canvas, renderOptions) {
11732
11746
  }
11733
11747
  }
11734
11748
 
11735
- function fillPathOrText(ui, canvas, renderOptions) {
11736
- ui.__.__font ? Paint.fillText(ui, canvas, renderOptions) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
11749
+ function fillPathOrText(ui, canvas, renderOptions, complexPaint) {
11750
+ ui.__.__font ? Paint.fillText(ui, canvas, renderOptions, complexPaint) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
11737
11751
  }
11738
11752
 
11739
- function fillText(ui, canvas, renderOptions) {
11740
- if (ui.motionText) return Paint.fillMotionText(ui, canvas, renderOptions);
11741
- const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
11753
+ function fillText(ui, canvas, renderOptions, complexPaint) {
11754
+ const data = ui.__;
11742
11755
  if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
11743
- let row;
11744
- for (let i = 0, len = rows.length; i < len; i++) {
11745
- row = rows[i];
11746
- if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
11747
- canvas.fillText(charData.char, charData.x, row.y);
11748
- });
11756
+ let originCanvas;
11757
+ if (complexPaint) {
11758
+ originCanvas = canvas;
11759
+ canvas = canvas.getSameCanvas(true, true);
11760
+ canvas.font = ui.__.__font;
11761
+ canvas.fillStyle = "#000";
11762
+ }
11763
+ if (ui.motionText) {
11764
+ Paint.fillMotionText(ui, canvas, renderOptions);
11765
+ } else {
11766
+ let row;
11767
+ const {rows: rows, decorationY: decorationY} = data.__textDrawData;
11768
+ for (let i = 0, len = rows.length; i < len; i++) {
11769
+ row = rows[i];
11770
+ if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
11771
+ canvas.fillText(charData.char, charData.x, row.y);
11772
+ });
11773
+ }
11774
+ if (decorationY) {
11775
+ const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
11776
+ if (decorationColor) canvas.fillStyle = decorationColor;
11777
+ rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
11778
+ }
11749
11779
  }
11750
- if (decorationY) {
11751
- const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
11752
- if (decorationColor) canvas.fillStyle = decorationColor;
11753
- rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
11780
+ if (complexPaint) {
11781
+ canvas.beginPath();
11782
+ ui.__drawPathByBox(canvas, "render");
11783
+ canvas.fillStyle = originCanvas.fillStyle;
11784
+ canvas.setTransform(originCanvas.getTransform());
11785
+ canvas.blendMode = "source-in";
11786
+ canvas.fill();
11787
+ originCanvas.copyWorldByReset(canvas, ui.__nowWorld);
11788
+ canvas.recycle(ui.__nowWorld);
11754
11789
  }
11755
11790
  }
11756
11791
 
@@ -12870,9 +12905,9 @@ const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
12870
12905
 
12871
12906
  const breakChar = "- " + langBreak$1;
12872
12907
 
12873
- const cjkRangeList = [ [ 19968, 40959 ], [ 13312, 19903 ], [ 131072, 173791 ], [ 173824, 177983 ], [ 177984, 178207 ], [ 178208, 183983 ], [ 183984, 191471 ], [ 196608, 201551 ], [ 201552, 205743 ], [ 11904, 12031 ], [ 12032, 12255 ], [ 12272, 12287 ], [ 12288, 12351 ], [ 12736, 12783 ], [ 12800, 13055 ], [ 13056, 13311 ], [ 63744, 64255 ], [ 65072, 65103 ], [ 127488, 127743 ], [ 194560, 195103 ] ];
12908
+ const cjkRangeList = [ [ 19968, 40959 ], [ 13312, 19903 ], [ 131072, 173791 ], [ 173824, 177983 ], [ 177984, 178207 ], [ 178208, 183983 ], [ 183984, 191471 ], [ 196608, 201551 ], [ 201552, 205743 ], [ 11904, 12031 ], [ 12032, 12255 ], [ 12272, 12287 ], [ 12288, 12351 ], [ 4352, 4607 ], [ 12352, 12447 ], [ 12448, 12543 ], [ 12544, 12591 ], [ 12592, 12687 ], [ 12688, 12703 ], [ 12704, 12735 ], [ 12784, 12799 ], [ 12736, 12783 ], [ 12800, 13055 ], [ 13056, 13311 ], [ 63744, 64255 ], [ 65072, 65103 ], [ 127488, 127743 ], [ 194560, 195103 ] ];
12874
12909
 
12875
- const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
12910
+ const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u{${start.toString(16)}}-\\u{${end.toString(16)}}]`).join("|"), "u");
12876
12911
 
12877
12912
  function mapChar(str) {
12878
12913
  const map = {};
@@ -12969,11 +13004,13 @@ function createRows(drawData, content, style) {
12969
13004
  rows = drawData.rows;
12970
13005
  bounds = drawData.bounds;
12971
13006
  findMaxWidth = !bounds.width && !style.autoSizeAlign;
12972
- const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
13007
+ const {paraIndent: paraIndent, textCase: textCase} = style;
12973
13008
  const {canvas: canvas} = Platform, {width: width} = bounds;
12974
13009
  if (style.__isCharMode) {
12975
13010
  const wrap = style.textWrap !== "none";
12976
13011
  const breakAll = style.textWrap === "break";
13012
+ const letterSpacing = style.__letterSpacing;
13013
+ const wordSpacing = style.__wordSpacing;
12977
13014
  paraStart = true;
12978
13015
  lastCharType = null;
12979
13016
  startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
@@ -12994,9 +13031,9 @@ function createRows(drawData, content, style) {
12994
13031
  charType = getCharType(char);
12995
13032
  if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
12996
13033
  charWidth = canvas.measureText(char).width;
12997
- if (__letterSpacing) {
12998
- if (__letterSpacing < 0) charSize = charWidth;
12999
- charWidth += __letterSpacing;
13034
+ if (letterSpacing) {
13035
+ if (letterSpacing < 0) charSize = charWidth;
13036
+ charWidth += letterSpacing;
13000
13037
  }
13001
13038
  langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
13002
13039
  afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
@@ -13017,11 +13054,11 @@ function createRows(drawData, content, style) {
13017
13054
  }
13018
13055
  if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
13019
13056
  if (charType === Break) {
13020
- if (char === " " && wordWidth) addWord();
13057
+ if (char === " " && wordWidth) addWord(wordSpacing);
13021
13058
  addChar(char, charWidth);
13022
13059
  addWord();
13023
13060
  } else if (langBreak || afterBreak) {
13024
- if (wordWidth) addWord();
13061
+ if (wordWidth) addWord(wordSpacing);
13025
13062
  addChar(char, charWidth);
13026
13063
  } else {
13027
13064
  addChar(char, charWidth);
@@ -13057,7 +13094,11 @@ function addChar(char, width) {
13057
13094
  wordWidth += width;
13058
13095
  }
13059
13096
 
13060
- function addWord() {
13097
+ function addWord(wordSpacing) {
13098
+ if (wordSpacing) {
13099
+ rowWidth += wordSpacing;
13100
+ word.addWidth = wordSpacing;
13101
+ }
13061
13102
  rowWidth += wordWidth;
13062
13103
  word.width = wordWidth;
13063
13104
  row.words.push(word);
@@ -13101,6 +13142,7 @@ function layoutChar(drawData, style, width, _height) {
13101
13142
  const {rows: rows} = drawData;
13102
13143
  const {textAlign: textAlign, paraIndent: paraIndent} = style;
13103
13144
  const useLetter = style.__letterSpacing || style.motionText;
13145
+ const wordSpacing = style.__wordSpacing;
13104
13146
  const justifyLast = width && textAlign.includes("both");
13105
13147
  const justify = justifyLast || width && textAlign.includes("justify");
13106
13148
  const justifyLetter = justify && textAlign.includes("letter");
@@ -13113,7 +13155,7 @@ function layoutChar(drawData, style, width, _height) {
13113
13155
  remainingWidth = width - row.width - indentWidth;
13114
13156
  if (justifyLetter) addLetterWidth = remainingWidth / (row.words.reduce((total, item) => total + item.data.length, 0) - 1); else addWordWidth = wordsLength > 1 ? remainingWidth / (wordsLength - 1) : 0;
13115
13157
  }
13116
- mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
13158
+ mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth || wordSpacing ? WordMode : TextMode;
13117
13159
  if (row.isOverflow && !useLetter) row.textMode = true;
13118
13160
  if (mode === TextMode) {
13119
13161
  row.x += indentWidth;
@@ -13133,6 +13175,7 @@ function layoutChar(drawData, style, width, _height) {
13133
13175
  } else {
13134
13176
  charX = toChar(word.data, charX, row.data, row.isOverflow, canJustify && addLetterWidth);
13135
13177
  }
13178
+ if (word.addWidth) charX += word.addWidth;
13136
13179
  if (canJustify) {
13137
13180
  isLastWord = index === wordsLength - 1;
13138
13181
  if (addWordWidth) {
@@ -13416,9 +13459,15 @@ try {
13416
13459
  } catch (_a) {}
13417
13460
 
13418
13461
  class RobotData extends UIData {
13462
+ get __isCanvas() {
13463
+ return true;
13464
+ }
13419
13465
  get __drawAfterFill() {
13420
13466
  return true;
13421
13467
  }
13468
+ get __boxStroke() {
13469
+ return !this.__pathInputed;
13470
+ }
13422
13471
  setRobot(value) {
13423
13472
  this._robot = value;
13424
13473
  this.__leaf.__updateRobot();