leafer-ui 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
  const debug$5 = Debug.get("LeaferCanvas");
7052
7063
 
@@ -8785,7 +8796,7 @@ let UI = UI_1 = class UI extends Leaf {
8785
8796
  getPath(curve, pathForRender) {
8786
8797
  this.__layout.update();
8787
8798
  let path = pathForRender ? this.__.__pathForRender : this.__.path;
8788
- if (!path) pen.set(path = []), this.__drawPathByBox(pen, !pathForRender);
8799
+ if (!path) pen.set(path = []), this.__drawPathByBox(pen, "box", !pathForRender);
8789
8800
  return curve ? PathConvert.toCanvasData(path, true) : path;
8790
8801
  }
8791
8802
  getPathString(curve, pathForRender, floatLength) {
@@ -8823,10 +8834,10 @@ let UI = UI_1 = class UI extends Leaf {
8823
8834
  data.__usePointsMode ? PathDrawer.drawPathByPoints(canvas, data.points, data.closed) : this.__drawPathByData(canvas, data.path, true);
8824
8835
  }
8825
8836
  __drawPathByData(drawer, data, ignoreCornerRadius) {
8826
- data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, ignoreCornerRadius);
8837
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, "box", ignoreCornerRadius);
8827
8838
  }
8828
- __drawPathByBox(drawer, ignoreCornerRadius) {
8829
- const {x: x, y: y, width: width, height: height} = this.__layout.boxBounds;
8839
+ __drawPathByBox(drawer, boundsType = "box", ignoreCornerRadius) {
8840
+ const {x: x, y: y, width: width, height: height} = this.__layout[boundsType + "Bounds"];
8830
8841
  if (this.__.cornerRadius && !ignoreCornerRadius) {
8831
8842
  const {cornerRadius: cornerRadius} = this.__;
8832
8843
  drawer.roundRect(x, y, width, height, isNumber(cornerRadius) ? [ cornerRadius ] : cornerRadius);
@@ -9908,14 +9919,15 @@ let Text = class Text extends UI {
9908
9919
  }
9909
9920
  __updateTextDrawData() {
9910
9921
  const data = this.__;
9911
- const {lineHeight: lineHeight, letterSpacing: letterSpacing, fontFamily: fontFamily, fontSize: fontSize, fontWeight: fontWeight, italic: italic, textCase: textCase, textOverflow: textOverflow, padding: padding, width: width, height: height} = data;
9922
+ 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;
9912
9923
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
9913
9924
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
9925
+ data.__wordSpacing = UnitConvert.number(wordSpacing, fontSize);
9914
9926
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * .7) / 2;
9915
9927
  data.__font = `${italic ? "italic " : ""}${textCase === "small-caps" ? "small-caps " : ""}${fontWeight !== "normal" ? fontWeight + " " : ""}${fontSize || 12}px ${fontFamily || "caption"}`;
9916
9928
  stintSet$1(data, "__padding", padding && MathHelper.fourNumber(padding));
9917
9929
  stintSet$1(data, "__clipText", textOverflow !== "show" && !data.__autoSize);
9918
- stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.motionText || textCase !== "none");
9930
+ stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.__wordSpacing || data.motionText || textCase !== "none");
9919
9931
  data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === "") ? data.placeholder : data.text, this.__);
9920
9932
  }
9921
9933
  __updateBoxBounds() {
@@ -10013,6 +10025,8 @@ __decorate([ boundsType("none") ], Text.prototype, "textDecoration", void 0);
10013
10025
 
10014
10026
  __decorate([ boundsType(0) ], Text.prototype, "letterSpacing", void 0);
10015
10027
 
10028
+ __decorate([ boundsType(0) ], Text.prototype, "wordSpacing", void 0);
10029
+
10016
10030
  __decorate([ boundsType({
10017
10031
  type: "percent",
10018
10032
  value: 1.5
@@ -11975,7 +11989,7 @@ function fills(fills, ui, canvas, renderOptions) {
11975
11989
  if (scaleX !== 1) canvas.scale(scaleX, scaleY);
11976
11990
  }
11977
11991
  if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
11978
- fillPathOrText(ui, canvas, renderOptions);
11992
+ fillPathOrText(ui, canvas, renderOptions, true);
11979
11993
  canvas.restore();
11980
11994
  } else {
11981
11995
  if (originPaint.blendMode) {
@@ -11987,25 +12001,46 @@ function fills(fills, ui, canvas, renderOptions) {
11987
12001
  }
11988
12002
  }
11989
12003
 
11990
- function fillPathOrText(ui, canvas, renderOptions) {
11991
- ui.__.__font ? Paint.fillText(ui, canvas, renderOptions) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
12004
+ function fillPathOrText(ui, canvas, renderOptions, complexPaint) {
12005
+ ui.__.__font ? Paint.fillText(ui, canvas, renderOptions, complexPaint) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
11992
12006
  }
11993
12007
 
11994
- function fillText(ui, canvas, renderOptions) {
11995
- if (ui.motionText) return Paint.fillMotionText(ui, canvas, renderOptions);
11996
- const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
12008
+ function fillText(ui, canvas, renderOptions, complexPaint) {
12009
+ const data = ui.__;
11997
12010
  if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
11998
- let row;
11999
- for (let i = 0, len = rows.length; i < len; i++) {
12000
- row = rows[i];
12001
- if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
12002
- canvas.fillText(charData.char, charData.x, row.y);
12003
- });
12011
+ let originCanvas;
12012
+ if (complexPaint) {
12013
+ originCanvas = canvas;
12014
+ canvas = canvas.getSameCanvas(true, true);
12015
+ canvas.font = ui.__.__font;
12016
+ canvas.fillStyle = "#000";
12017
+ }
12018
+ if (ui.motionText) {
12019
+ Paint.fillMotionText(ui, canvas, renderOptions);
12020
+ } else {
12021
+ let row;
12022
+ const {rows: rows, decorationY: decorationY} = data.__textDrawData;
12023
+ for (let i = 0, len = rows.length; i < len; i++) {
12024
+ row = rows[i];
12025
+ if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
12026
+ canvas.fillText(charData.char, charData.x, row.y);
12027
+ });
12028
+ }
12029
+ if (decorationY) {
12030
+ const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
12031
+ if (decorationColor) canvas.fillStyle = decorationColor;
12032
+ rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
12033
+ }
12004
12034
  }
12005
- if (decorationY) {
12006
- const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
12007
- if (decorationColor) canvas.fillStyle = decorationColor;
12008
- rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
12035
+ if (complexPaint) {
12036
+ canvas.beginPath();
12037
+ ui.__drawPathByBox(canvas, "render");
12038
+ canvas.fillStyle = originCanvas.fillStyle;
12039
+ canvas.setTransform(originCanvas.getTransform());
12040
+ canvas.blendMode = "source-in";
12041
+ canvas.fill();
12042
+ originCanvas.copyWorldByReset(canvas, ui.__nowWorld);
12043
+ canvas.recycle(ui.__nowWorld);
12009
12044
  }
12010
12045
  }
12011
12046
 
@@ -13125,9 +13160,9 @@ const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
13125
13160
 
13126
13161
  const breakChar = "- " + langBreak$1;
13127
13162
 
13128
- 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 ] ];
13163
+ 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 ] ];
13129
13164
 
13130
- const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
13165
+ const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u{${start.toString(16)}}-\\u{${end.toString(16)}}]`).join("|"), "u");
13131
13166
 
13132
13167
  function mapChar(str) {
13133
13168
  const map = {};
@@ -13224,11 +13259,13 @@ function createRows(drawData, content, style) {
13224
13259
  rows = drawData.rows;
13225
13260
  bounds = drawData.bounds;
13226
13261
  findMaxWidth = !bounds.width && !style.autoSizeAlign;
13227
- const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
13262
+ const {paraIndent: paraIndent, textCase: textCase} = style;
13228
13263
  const {canvas: canvas} = Platform, {width: width} = bounds;
13229
13264
  if (style.__isCharMode) {
13230
13265
  const wrap = style.textWrap !== "none";
13231
13266
  const breakAll = style.textWrap === "break";
13267
+ const letterSpacing = style.__letterSpacing;
13268
+ const wordSpacing = style.__wordSpacing;
13232
13269
  paraStart = true;
13233
13270
  lastCharType = null;
13234
13271
  startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
@@ -13249,9 +13286,9 @@ function createRows(drawData, content, style) {
13249
13286
  charType = getCharType(char);
13250
13287
  if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
13251
13288
  charWidth = canvas.measureText(char).width;
13252
- if (__letterSpacing) {
13253
- if (__letterSpacing < 0) charSize = charWidth;
13254
- charWidth += __letterSpacing;
13289
+ if (letterSpacing) {
13290
+ if (letterSpacing < 0) charSize = charWidth;
13291
+ charWidth += letterSpacing;
13255
13292
  }
13256
13293
  langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
13257
13294
  afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
@@ -13272,11 +13309,11 @@ function createRows(drawData, content, style) {
13272
13309
  }
13273
13310
  if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
13274
13311
  if (charType === Break) {
13275
- if (char === " " && wordWidth) addWord();
13312
+ if (char === " " && wordWidth) addWord(wordSpacing);
13276
13313
  addChar(char, charWidth);
13277
13314
  addWord();
13278
13315
  } else if (langBreak || afterBreak) {
13279
- if (wordWidth) addWord();
13316
+ if (wordWidth) addWord(wordSpacing);
13280
13317
  addChar(char, charWidth);
13281
13318
  } else {
13282
13319
  addChar(char, charWidth);
@@ -13312,7 +13349,11 @@ function addChar(char, width) {
13312
13349
  wordWidth += width;
13313
13350
  }
13314
13351
 
13315
- function addWord() {
13352
+ function addWord(wordSpacing) {
13353
+ if (wordSpacing) {
13354
+ rowWidth += wordSpacing;
13355
+ word.addWidth = wordSpacing;
13356
+ }
13316
13357
  rowWidth += wordWidth;
13317
13358
  word.width = wordWidth;
13318
13359
  row.words.push(word);
@@ -13356,6 +13397,7 @@ function layoutChar(drawData, style, width, _height) {
13356
13397
  const {rows: rows} = drawData;
13357
13398
  const {textAlign: textAlign, paraIndent: paraIndent} = style;
13358
13399
  const useLetter = style.__letterSpacing || style.motionText;
13400
+ const wordSpacing = style.__wordSpacing;
13359
13401
  const justifyLast = width && textAlign.includes("both");
13360
13402
  const justify = justifyLast || width && textAlign.includes("justify");
13361
13403
  const justifyLetter = justify && textAlign.includes("letter");
@@ -13368,7 +13410,7 @@ function layoutChar(drawData, style, width, _height) {
13368
13410
  remainingWidth = width - row.width - indentWidth;
13369
13411
  if (justifyLetter) addLetterWidth = remainingWidth / (row.words.reduce((total, item) => total + item.data.length, 0) - 1); else addWordWidth = wordsLength > 1 ? remainingWidth / (wordsLength - 1) : 0;
13370
13412
  }
13371
- mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
13413
+ mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth || wordSpacing ? WordMode : TextMode;
13372
13414
  if (row.isOverflow && !useLetter) row.textMode = true;
13373
13415
  if (mode === TextMode) {
13374
13416
  row.x += indentWidth;
@@ -13388,6 +13430,7 @@ function layoutChar(drawData, style, width, _height) {
13388
13430
  } else {
13389
13431
  charX = toChar(word.data, charX, row.data, row.isOverflow, canJustify && addLetterWidth);
13390
13432
  }
13433
+ if (word.addWidth) charX += word.addWidth;
13391
13434
  if (canJustify) {
13392
13435
  isLastWord = index === wordsLength - 1;
13393
13436
  if (addWordWidth) {