@leafer-draw/worker 2.2.9 → 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.
@@ -7046,7 +7046,7 @@ class LeafLevelList {
7046
7046
  }
7047
7047
  }
7048
7048
 
7049
- const version = "2.2.9";
7049
+ const version = "2.2.10";
7050
7050
 
7051
7051
  class LeaferCanvas extends LeaferCanvasBase {
7052
7052
  get allowBackgroundColor() {
@@ -8376,7 +8376,7 @@ let UI = UI_1 = class UI extends Leaf {
8376
8376
  getPath(curve, pathForRender) {
8377
8377
  this.__layout.update();
8378
8378
  let path = pathForRender ? this.__.__pathForRender : this.__.path;
8379
- if (!path) pen.set(path = []), this.__drawPathByBox(pen, !pathForRender);
8379
+ if (!path) pen.set(path = []), this.__drawPathByBox(pen, "box", !pathForRender);
8380
8380
  return curve ? PathConvert.toCanvasData(path, true) : path;
8381
8381
  }
8382
8382
  getPathString(curve, pathForRender, floatLength) {
@@ -8414,10 +8414,10 @@ let UI = UI_1 = class UI extends Leaf {
8414
8414
  data.__usePointsMode ? PathDrawer.drawPathByPoints(canvas, data.points, data.closed) : this.__drawPathByData(canvas, data.path, true);
8415
8415
  }
8416
8416
  __drawPathByData(drawer, data, ignoreCornerRadius) {
8417
- data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, ignoreCornerRadius);
8417
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, "box", ignoreCornerRadius);
8418
8418
  }
8419
- __drawPathByBox(drawer, ignoreCornerRadius) {
8420
- const {x: x, y: y, width: width, height: height} = this.__layout.boxBounds;
8419
+ __drawPathByBox(drawer, boundsType = "box", ignoreCornerRadius) {
8420
+ const {x: x, y: y, width: width, height: height} = this.__layout[boundsType + "Bounds"];
8421
8421
  if (this.__.cornerRadius && !ignoreCornerRadius) {
8422
8422
  const {cornerRadius: cornerRadius} = this.__;
8423
8423
  drawer.roundRect(x, y, width, height, isNumber(cornerRadius) ? [ cornerRadius ] : cornerRadius);
@@ -9499,14 +9499,15 @@ let Text = class Text extends UI {
9499
9499
  }
9500
9500
  __updateTextDrawData() {
9501
9501
  const data = this.__;
9502
- const {lineHeight: lineHeight, letterSpacing: letterSpacing, fontFamily: fontFamily, fontSize: fontSize, fontWeight: fontWeight, italic: italic, textCase: textCase, textOverflow: textOverflow, padding: padding, width: width, height: height} = data;
9502
+ 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;
9503
9503
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
9504
9504
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
9505
+ data.__wordSpacing = UnitConvert.number(wordSpacing, fontSize);
9505
9506
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * .7) / 2;
9506
9507
  data.__font = `${italic ? "italic " : ""}${textCase === "small-caps" ? "small-caps " : ""}${fontWeight !== "normal" ? fontWeight + " " : ""}${fontSize || 12}px ${fontFamily || "caption"}`;
9507
9508
  stintSet$1(data, "__padding", padding && MathHelper.fourNumber(padding));
9508
9509
  stintSet$1(data, "__clipText", textOverflow !== "show" && !data.__autoSize);
9509
- stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.motionText || textCase !== "none");
9510
+ stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.__wordSpacing || data.motionText || textCase !== "none");
9510
9511
  data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === "") ? data.placeholder : data.text, this.__);
9511
9512
  }
9512
9513
  __updateBoxBounds() {
@@ -9604,6 +9605,8 @@ __decorate([ boundsType("none") ], Text.prototype, "textDecoration", void 0);
9604
9605
 
9605
9606
  __decorate([ boundsType(0) ], Text.prototype, "letterSpacing", void 0);
9606
9607
 
9608
+ __decorate([ boundsType(0) ], Text.prototype, "wordSpacing", void 0);
9609
+
9607
9610
  __decorate([ boundsType({
9608
9611
  type: "percent",
9609
9612
  value: 1.5
@@ -9700,7 +9703,7 @@ function fills(fills, ui, canvas, renderOptions) {
9700
9703
  if (scaleX !== 1) canvas.scale(scaleX, scaleY);
9701
9704
  }
9702
9705
  if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
9703
- fillPathOrText(ui, canvas, renderOptions);
9706
+ fillPathOrText(ui, canvas, renderOptions, true);
9704
9707
  canvas.restore();
9705
9708
  } else {
9706
9709
  if (originPaint.blendMode) {
@@ -9712,25 +9715,46 @@ function fills(fills, ui, canvas, renderOptions) {
9712
9715
  }
9713
9716
  }
9714
9717
 
9715
- function fillPathOrText(ui, canvas, renderOptions) {
9716
- ui.__.__font ? Paint.fillText(ui, canvas, renderOptions) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
9718
+ function fillPathOrText(ui, canvas, renderOptions, complexPaint) {
9719
+ ui.__.__font ? Paint.fillText(ui, canvas, renderOptions, complexPaint) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
9717
9720
  }
9718
9721
 
9719
- function fillText(ui, canvas, renderOptions) {
9720
- if (ui.motionText) return Paint.fillMotionText(ui, canvas, renderOptions);
9721
- const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
9722
+ function fillText(ui, canvas, renderOptions, complexPaint) {
9723
+ const data = ui.__;
9722
9724
  if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
9723
- let row;
9724
- for (let i = 0, len = rows.length; i < len; i++) {
9725
- row = rows[i];
9726
- if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
9727
- canvas.fillText(charData.char, charData.x, row.y);
9728
- });
9725
+ let originCanvas;
9726
+ if (complexPaint) {
9727
+ originCanvas = canvas;
9728
+ canvas = canvas.getSameCanvas(true, true);
9729
+ canvas.font = ui.__.__font;
9730
+ canvas.fillStyle = "#000";
9731
+ }
9732
+ if (ui.motionText) {
9733
+ Paint.fillMotionText(ui, canvas, renderOptions);
9734
+ } else {
9735
+ let row;
9736
+ const {rows: rows, decorationY: decorationY} = data.__textDrawData;
9737
+ for (let i = 0, len = rows.length; i < len; i++) {
9738
+ row = rows[i];
9739
+ if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
9740
+ canvas.fillText(charData.char, charData.x, row.y);
9741
+ });
9742
+ }
9743
+ if (decorationY) {
9744
+ const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
9745
+ if (decorationColor) canvas.fillStyle = decorationColor;
9746
+ rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
9747
+ }
9729
9748
  }
9730
- if (decorationY) {
9731
- const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
9732
- if (decorationColor) canvas.fillStyle = decorationColor;
9733
- rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
9749
+ if (complexPaint) {
9750
+ canvas.beginPath();
9751
+ ui.__drawPathByBox(canvas, "render");
9752
+ canvas.fillStyle = originCanvas.fillStyle;
9753
+ canvas.setTransform(originCanvas.getTransform());
9754
+ canvas.blendMode = "source-in";
9755
+ canvas.fill();
9756
+ originCanvas.copyWorldByReset(canvas, ui.__nowWorld);
9757
+ canvas.recycle(ui.__nowWorld);
9734
9758
  }
9735
9759
  }
9736
9760
 
@@ -10850,9 +10874,9 @@ const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
10850
10874
 
10851
10875
  const breakChar = "- " + langBreak$1;
10852
10876
 
10853
- 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 ] ];
10877
+ 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 ] ];
10854
10878
 
10855
- const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
10879
+ const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u{${start.toString(16)}}-\\u{${end.toString(16)}}]`).join("|"), "u");
10856
10880
 
10857
10881
  function mapChar(str) {
10858
10882
  const map = {};
@@ -10949,11 +10973,13 @@ function createRows(drawData, content, style) {
10949
10973
  rows = drawData.rows;
10950
10974
  bounds = drawData.bounds;
10951
10975
  findMaxWidth = !bounds.width && !style.autoSizeAlign;
10952
- const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
10976
+ const {paraIndent: paraIndent, textCase: textCase} = style;
10953
10977
  const {canvas: canvas} = Platform, {width: width} = bounds;
10954
10978
  if (style.__isCharMode) {
10955
10979
  const wrap = style.textWrap !== "none";
10956
10980
  const breakAll = style.textWrap === "break";
10981
+ const letterSpacing = style.__letterSpacing;
10982
+ const wordSpacing = style.__wordSpacing;
10957
10983
  paraStart = true;
10958
10984
  lastCharType = null;
10959
10985
  startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
@@ -10974,9 +11000,9 @@ function createRows(drawData, content, style) {
10974
11000
  charType = getCharType(char);
10975
11001
  if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
10976
11002
  charWidth = canvas.measureText(char).width;
10977
- if (__letterSpacing) {
10978
- if (__letterSpacing < 0) charSize = charWidth;
10979
- charWidth += __letterSpacing;
11003
+ if (letterSpacing) {
11004
+ if (letterSpacing < 0) charSize = charWidth;
11005
+ charWidth += letterSpacing;
10980
11006
  }
10981
11007
  langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
10982
11008
  afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
@@ -10997,11 +11023,11 @@ function createRows(drawData, content, style) {
10997
11023
  }
10998
11024
  if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
10999
11025
  if (charType === Break) {
11000
- if (char === " " && wordWidth) addWord();
11026
+ if (char === " " && wordWidth) addWord(wordSpacing);
11001
11027
  addChar(char, charWidth);
11002
11028
  addWord();
11003
11029
  } else if (langBreak || afterBreak) {
11004
- if (wordWidth) addWord();
11030
+ if (wordWidth) addWord(wordSpacing);
11005
11031
  addChar(char, charWidth);
11006
11032
  } else {
11007
11033
  addChar(char, charWidth);
@@ -11037,7 +11063,11 @@ function addChar(char, width) {
11037
11063
  wordWidth += width;
11038
11064
  }
11039
11065
 
11040
- function addWord() {
11066
+ function addWord(wordSpacing) {
11067
+ if (wordSpacing) {
11068
+ rowWidth += wordSpacing;
11069
+ word.addWidth = wordSpacing;
11070
+ }
11041
11071
  rowWidth += wordWidth;
11042
11072
  word.width = wordWidth;
11043
11073
  row.words.push(word);
@@ -11081,6 +11111,7 @@ function layoutChar(drawData, style, width, _height) {
11081
11111
  const {rows: rows} = drawData;
11082
11112
  const {textAlign: textAlign, paraIndent: paraIndent} = style;
11083
11113
  const useLetter = style.__letterSpacing || style.motionText;
11114
+ const wordSpacing = style.__wordSpacing;
11084
11115
  const justifyLast = width && textAlign.includes("both");
11085
11116
  const justify = justifyLast || width && textAlign.includes("justify");
11086
11117
  const justifyLetter = justify && textAlign.includes("letter");
@@ -11093,7 +11124,7 @@ function layoutChar(drawData, style, width, _height) {
11093
11124
  remainingWidth = width - row.width - indentWidth;
11094
11125
  if (justifyLetter) addLetterWidth = remainingWidth / (row.words.reduce((total, item) => total + item.data.length, 0) - 1); else addWordWidth = wordsLength > 1 ? remainingWidth / (wordsLength - 1) : 0;
11095
11126
  }
11096
- mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
11127
+ mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth || wordSpacing ? WordMode : TextMode;
11097
11128
  if (row.isOverflow && !useLetter) row.textMode = true;
11098
11129
  if (mode === TextMode) {
11099
11130
  row.x += indentWidth;
@@ -11113,6 +11144,7 @@ function layoutChar(drawData, style, width, _height) {
11113
11144
  } else {
11114
11145
  charX = toChar(word.data, charX, row.data, row.isOverflow, canJustify && addLetterWidth);
11115
11146
  }
11147
+ if (word.addWidth) charX += word.addWidth;
11116
11148
  if (canJustify) {
11117
11149
  isLastWord = index === wordsLength - 1;
11118
11150
  if (addWordWidth) {