leafer-ui 2.2.8 → 2.2.10

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.
@@ -2992,7 +2992,7 @@ const PathCommandNodeHelper = {
2992
2992
  toCommand(_nodes) {
2993
2993
  return [];
2994
2994
  },
2995
- toNode(_data) {
2995
+ toNode(_data, _filterSamePoint) {
2996
2996
  return [];
2997
2997
  }
2998
2998
  };
@@ -7046,7 +7046,7 @@ class LeafLevelList {
7046
7046
  }
7047
7047
  }
7048
7048
 
7049
- const version = "2.2.8";
7049
+ const version = "2.2.10";
7050
7050
 
7051
7051
  const debug$5 = Debug.get("LeaferCanvas");
7052
7052
 
@@ -8785,7 +8785,7 @@ let UI = UI_1 = class UI extends Leaf {
8785
8785
  getPath(curve, pathForRender) {
8786
8786
  this.__layout.update();
8787
8787
  let path = pathForRender ? this.__.__pathForRender : this.__.path;
8788
- if (!path) pen.set(path = []), this.__drawPathByBox(pen, !pathForRender);
8788
+ if (!path) pen.set(path = []), this.__drawPathByBox(pen, "box", !pathForRender);
8789
8789
  return curve ? PathConvert.toCanvasData(path, true) : path;
8790
8790
  }
8791
8791
  getPathString(curve, pathForRender, floatLength) {
@@ -8823,10 +8823,10 @@ let UI = UI_1 = class UI extends Leaf {
8823
8823
  data.__usePointsMode ? PathDrawer.drawPathByPoints(canvas, data.points, data.closed) : this.__drawPathByData(canvas, data.path, true);
8824
8824
  }
8825
8825
  __drawPathByData(drawer, data, ignoreCornerRadius) {
8826
- data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, ignoreCornerRadius);
8826
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, "box", ignoreCornerRadius);
8827
8827
  }
8828
- __drawPathByBox(drawer, ignoreCornerRadius) {
8829
- const {x: x, y: y, width: width, height: height} = this.__layout.boxBounds;
8828
+ __drawPathByBox(drawer, boundsType = "box", ignoreCornerRadius) {
8829
+ const {x: x, y: y, width: width, height: height} = this.__layout[boundsType + "Bounds"];
8830
8830
  if (this.__.cornerRadius && !ignoreCornerRadius) {
8831
8831
  const {cornerRadius: cornerRadius} = this.__;
8832
8832
  drawer.roundRect(x, y, width, height, isNumber(cornerRadius) ? [ cornerRadius ] : cornerRadius);
@@ -9908,14 +9908,15 @@ let Text = class Text extends UI {
9908
9908
  }
9909
9909
  __updateTextDrawData() {
9910
9910
  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;
9911
+ 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
9912
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
9913
9913
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
9914
+ data.__wordSpacing = UnitConvert.number(wordSpacing, fontSize);
9914
9915
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * .7) / 2;
9915
9916
  data.__font = `${italic ? "italic " : ""}${textCase === "small-caps" ? "small-caps " : ""}${fontWeight !== "normal" ? fontWeight + " " : ""}${fontSize || 12}px ${fontFamily || "caption"}`;
9916
9917
  stintSet$1(data, "__padding", padding && MathHelper.fourNumber(padding));
9917
9918
  stintSet$1(data, "__clipText", textOverflow !== "show" && !data.__autoSize);
9918
- stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.motionText || textCase !== "none");
9919
+ stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.__wordSpacing || data.motionText || textCase !== "none");
9919
9920
  data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === "") ? data.placeholder : data.text, this.__);
9920
9921
  }
9921
9922
  __updateBoxBounds() {
@@ -10013,6 +10014,8 @@ __decorate([ boundsType("none") ], Text.prototype, "textDecoration", void 0);
10013
10014
 
10014
10015
  __decorate([ boundsType(0) ], Text.prototype, "letterSpacing", void 0);
10015
10016
 
10017
+ __decorate([ boundsType(0) ], Text.prototype, "wordSpacing", void 0);
10018
+
10016
10019
  __decorate([ boundsType({
10017
10020
  type: "percent",
10018
10021
  value: 1.5
@@ -11975,7 +11978,7 @@ function fills(fills, ui, canvas, renderOptions) {
11975
11978
  if (scaleX !== 1) canvas.scale(scaleX, scaleY);
11976
11979
  }
11977
11980
  if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
11978
- fillPathOrText(ui, canvas, renderOptions);
11981
+ fillPathOrText(ui, canvas, renderOptions, true);
11979
11982
  canvas.restore();
11980
11983
  } else {
11981
11984
  if (originPaint.blendMode) {
@@ -11987,25 +11990,46 @@ function fills(fills, ui, canvas, renderOptions) {
11987
11990
  }
11988
11991
  }
11989
11992
 
11990
- function fillPathOrText(ui, canvas, renderOptions) {
11991
- ui.__.__font ? Paint.fillText(ui, canvas, renderOptions) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
11993
+ function fillPathOrText(ui, canvas, renderOptions, complexPaint) {
11994
+ ui.__.__font ? Paint.fillText(ui, canvas, renderOptions, complexPaint) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
11992
11995
  }
11993
11996
 
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;
11997
+ function fillText(ui, canvas, renderOptions, complexPaint) {
11998
+ const data = ui.__;
11997
11999
  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
- });
12000
+ let originCanvas;
12001
+ if (complexPaint) {
12002
+ originCanvas = canvas;
12003
+ canvas = canvas.getSameCanvas(true, true);
12004
+ canvas.font = ui.__.__font;
12005
+ canvas.fillStyle = "#000";
12006
+ }
12007
+ if (ui.motionText) {
12008
+ Paint.fillMotionText(ui, canvas, renderOptions);
12009
+ } else {
12010
+ let row;
12011
+ const {rows: rows, decorationY: decorationY} = data.__textDrawData;
12012
+ for (let i = 0, len = rows.length; i < len; i++) {
12013
+ row = rows[i];
12014
+ if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
12015
+ canvas.fillText(charData.char, charData.x, row.y);
12016
+ });
12017
+ }
12018
+ if (decorationY) {
12019
+ const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
12020
+ if (decorationColor) canvas.fillStyle = decorationColor;
12021
+ rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
12022
+ }
12004
12023
  }
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)));
12024
+ if (complexPaint) {
12025
+ canvas.beginPath();
12026
+ ui.__drawPathByBox(canvas, "render");
12027
+ canvas.fillStyle = originCanvas.fillStyle;
12028
+ canvas.setTransform(originCanvas.getTransform());
12029
+ canvas.blendMode = "source-in";
12030
+ canvas.fill();
12031
+ originCanvas.copyWorldByReset(canvas, ui.__nowWorld);
12032
+ canvas.recycle(ui.__nowWorld);
12009
12033
  }
12010
12034
  }
12011
12035
 
@@ -13125,9 +13149,9 @@ const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
13125
13149
 
13126
13150
  const breakChar = "- " + langBreak$1;
13127
13151
 
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 ] ];
13152
+ 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
13153
 
13130
- const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
13154
+ const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u{${start.toString(16)}}-\\u{${end.toString(16)}}]`).join("|"), "u");
13131
13155
 
13132
13156
  function mapChar(str) {
13133
13157
  const map = {};
@@ -13224,11 +13248,13 @@ function createRows(drawData, content, style) {
13224
13248
  rows = drawData.rows;
13225
13249
  bounds = drawData.bounds;
13226
13250
  findMaxWidth = !bounds.width && !style.autoSizeAlign;
13227
- const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
13251
+ const {paraIndent: paraIndent, textCase: textCase} = style;
13228
13252
  const {canvas: canvas} = Platform, {width: width} = bounds;
13229
13253
  if (style.__isCharMode) {
13230
13254
  const wrap = style.textWrap !== "none";
13231
13255
  const breakAll = style.textWrap === "break";
13256
+ const letterSpacing = style.__letterSpacing;
13257
+ const wordSpacing = style.__wordSpacing;
13232
13258
  paraStart = true;
13233
13259
  lastCharType = null;
13234
13260
  startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
@@ -13249,9 +13275,9 @@ function createRows(drawData, content, style) {
13249
13275
  charType = getCharType(char);
13250
13276
  if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
13251
13277
  charWidth = canvas.measureText(char).width;
13252
- if (__letterSpacing) {
13253
- if (__letterSpacing < 0) charSize = charWidth;
13254
- charWidth += __letterSpacing;
13278
+ if (letterSpacing) {
13279
+ if (letterSpacing < 0) charSize = charWidth;
13280
+ charWidth += letterSpacing;
13255
13281
  }
13256
13282
  langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
13257
13283
  afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
@@ -13272,11 +13298,11 @@ function createRows(drawData, content, style) {
13272
13298
  }
13273
13299
  if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
13274
13300
  if (charType === Break) {
13275
- if (char === " " && wordWidth) addWord();
13301
+ if (char === " " && wordWidth) addWord(wordSpacing);
13276
13302
  addChar(char, charWidth);
13277
13303
  addWord();
13278
13304
  } else if (langBreak || afterBreak) {
13279
- if (wordWidth) addWord();
13305
+ if (wordWidth) addWord(wordSpacing);
13280
13306
  addChar(char, charWidth);
13281
13307
  } else {
13282
13308
  addChar(char, charWidth);
@@ -13312,7 +13338,11 @@ function addChar(char, width) {
13312
13338
  wordWidth += width;
13313
13339
  }
13314
13340
 
13315
- function addWord() {
13341
+ function addWord(wordSpacing) {
13342
+ if (wordSpacing) {
13343
+ rowWidth += wordSpacing;
13344
+ word.addWidth = wordSpacing;
13345
+ }
13316
13346
  rowWidth += wordWidth;
13317
13347
  word.width = wordWidth;
13318
13348
  row.words.push(word);
@@ -13356,6 +13386,7 @@ function layoutChar(drawData, style, width, _height) {
13356
13386
  const {rows: rows} = drawData;
13357
13387
  const {textAlign: textAlign, paraIndent: paraIndent} = style;
13358
13388
  const useLetter = style.__letterSpacing || style.motionText;
13389
+ const wordSpacing = style.__wordSpacing;
13359
13390
  const justifyLast = width && textAlign.includes("both");
13360
13391
  const justify = justifyLast || width && textAlign.includes("justify");
13361
13392
  const justifyLetter = justify && textAlign.includes("letter");
@@ -13368,7 +13399,7 @@ function layoutChar(drawData, style, width, _height) {
13368
13399
  remainingWidth = width - row.width - indentWidth;
13369
13400
  if (justifyLetter) addLetterWidth = remainingWidth / (row.words.reduce((total, item) => total + item.data.length, 0) - 1); else addWordWidth = wordsLength > 1 ? remainingWidth / (wordsLength - 1) : 0;
13370
13401
  }
13371
- mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
13402
+ mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth || wordSpacing ? WordMode : TextMode;
13372
13403
  if (row.isOverflow && !useLetter) row.textMode = true;
13373
13404
  if (mode === TextMode) {
13374
13405
  row.x += indentWidth;
@@ -13388,6 +13419,7 @@ function layoutChar(drawData, style, width, _height) {
13388
13419
  } else {
13389
13420
  charX = toChar(word.data, charX, row.data, row.isOverflow, canJustify && addLetterWidth);
13390
13421
  }
13422
+ if (word.addWidth) charX += word.addWidth;
13391
13423
  if (canJustify) {
13392
13424
  isLastWord = index === wordsLength - 1;
13393
13425
  if (addWordWidth) {