@leafer-draw/worker 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() {
@@ -8376,7 +8387,7 @@ let UI = UI_1 = class UI extends Leaf {
8376
8387
  getPath(curve, pathForRender) {
8377
8388
  this.__layout.update();
8378
8389
  let path = pathForRender ? this.__.__pathForRender : this.__.path;
8379
- if (!path) pen.set(path = []), this.__drawPathByBox(pen, !pathForRender);
8390
+ if (!path) pen.set(path = []), this.__drawPathByBox(pen, "box", !pathForRender);
8380
8391
  return curve ? PathConvert.toCanvasData(path, true) : path;
8381
8392
  }
8382
8393
  getPathString(curve, pathForRender, floatLength) {
@@ -8414,10 +8425,10 @@ let UI = UI_1 = class UI extends Leaf {
8414
8425
  data.__usePointsMode ? PathDrawer.drawPathByPoints(canvas, data.points, data.closed) : this.__drawPathByData(canvas, data.path, true);
8415
8426
  }
8416
8427
  __drawPathByData(drawer, data, ignoreCornerRadius) {
8417
- data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, ignoreCornerRadius);
8428
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer, "box", ignoreCornerRadius);
8418
8429
  }
8419
- __drawPathByBox(drawer, ignoreCornerRadius) {
8420
- const {x: x, y: y, width: width, height: height} = this.__layout.boxBounds;
8430
+ __drawPathByBox(drawer, boundsType = "box", ignoreCornerRadius) {
8431
+ const {x: x, y: y, width: width, height: height} = this.__layout[boundsType + "Bounds"];
8421
8432
  if (this.__.cornerRadius && !ignoreCornerRadius) {
8422
8433
  const {cornerRadius: cornerRadius} = this.__;
8423
8434
  drawer.roundRect(x, y, width, height, isNumber(cornerRadius) ? [ cornerRadius ] : cornerRadius);
@@ -9499,14 +9510,15 @@ let Text = class Text extends UI {
9499
9510
  }
9500
9511
  __updateTextDrawData() {
9501
9512
  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;
9513
+ 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
9514
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
9504
9515
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
9516
+ data.__wordSpacing = UnitConvert.number(wordSpacing, fontSize);
9505
9517
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * .7) / 2;
9506
9518
  data.__font = `${italic ? "italic " : ""}${textCase === "small-caps" ? "small-caps " : ""}${fontWeight !== "normal" ? fontWeight + " " : ""}${fontSize || 12}px ${fontFamily || "caption"}`;
9507
9519
  stintSet$1(data, "__padding", padding && MathHelper.fourNumber(padding));
9508
9520
  stintSet$1(data, "__clipText", textOverflow !== "show" && !data.__autoSize);
9509
- stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.motionText || textCase !== "none");
9521
+ stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || data.__wordSpacing || data.motionText || textCase !== "none");
9510
9522
  data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === "") ? data.placeholder : data.text, this.__);
9511
9523
  }
9512
9524
  __updateBoxBounds() {
@@ -9604,6 +9616,8 @@ __decorate([ boundsType("none") ], Text.prototype, "textDecoration", void 0);
9604
9616
 
9605
9617
  __decorate([ boundsType(0) ], Text.prototype, "letterSpacing", void 0);
9606
9618
 
9619
+ __decorate([ boundsType(0) ], Text.prototype, "wordSpacing", void 0);
9620
+
9607
9621
  __decorate([ boundsType({
9608
9622
  type: "percent",
9609
9623
  value: 1.5
@@ -9700,7 +9714,7 @@ function fills(fills, ui, canvas, renderOptions) {
9700
9714
  if (scaleX !== 1) canvas.scale(scaleX, scaleY);
9701
9715
  }
9702
9716
  if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
9703
- fillPathOrText(ui, canvas, renderOptions);
9717
+ fillPathOrText(ui, canvas, renderOptions, true);
9704
9718
  canvas.restore();
9705
9719
  } else {
9706
9720
  if (originPaint.blendMode) {
@@ -9712,25 +9726,46 @@ function fills(fills, ui, canvas, renderOptions) {
9712
9726
  }
9713
9727
  }
9714
9728
 
9715
- function fillPathOrText(ui, canvas, renderOptions) {
9716
- ui.__.__font ? Paint.fillText(ui, canvas, renderOptions) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
9729
+ function fillPathOrText(ui, canvas, renderOptions, complexPaint) {
9730
+ ui.__.__font ? Paint.fillText(ui, canvas, renderOptions, complexPaint) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
9717
9731
  }
9718
9732
 
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;
9733
+ function fillText(ui, canvas, renderOptions, complexPaint) {
9734
+ const data = ui.__;
9722
9735
  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
- });
9736
+ let originCanvas;
9737
+ if (complexPaint) {
9738
+ originCanvas = canvas;
9739
+ canvas = canvas.getSameCanvas(true, true);
9740
+ canvas.font = ui.__.__font;
9741
+ canvas.fillStyle = "#000";
9742
+ }
9743
+ if (ui.motionText) {
9744
+ Paint.fillMotionText(ui, canvas, renderOptions);
9745
+ } else {
9746
+ let row;
9747
+ const {rows: rows, decorationY: decorationY} = data.__textDrawData;
9748
+ for (let i = 0, len = rows.length; i < len; i++) {
9749
+ row = rows[i];
9750
+ if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
9751
+ canvas.fillText(charData.char, charData.x, row.y);
9752
+ });
9753
+ }
9754
+ if (decorationY) {
9755
+ const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
9756
+ if (decorationColor) canvas.fillStyle = decorationColor;
9757
+ rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
9758
+ }
9729
9759
  }
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)));
9760
+ if (complexPaint) {
9761
+ canvas.beginPath();
9762
+ ui.__drawPathByBox(canvas, "render");
9763
+ canvas.fillStyle = originCanvas.fillStyle;
9764
+ canvas.setTransform(originCanvas.getTransform());
9765
+ canvas.blendMode = "source-in";
9766
+ canvas.fill();
9767
+ originCanvas.copyWorldByReset(canvas, ui.__nowWorld);
9768
+ canvas.recycle(ui.__nowWorld);
9734
9769
  }
9735
9770
  }
9736
9771
 
@@ -10850,9 +10885,9 @@ const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
10850
10885
 
10851
10886
  const breakChar = "- " + langBreak$1;
10852
10887
 
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 ] ];
10888
+ 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
10889
 
10855
- const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
10890
+ const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u{${start.toString(16)}}-\\u{${end.toString(16)}}]`).join("|"), "u");
10856
10891
 
10857
10892
  function mapChar(str) {
10858
10893
  const map = {};
@@ -10949,11 +10984,13 @@ function createRows(drawData, content, style) {
10949
10984
  rows = drawData.rows;
10950
10985
  bounds = drawData.bounds;
10951
10986
  findMaxWidth = !bounds.width && !style.autoSizeAlign;
10952
- const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
10987
+ const {paraIndent: paraIndent, textCase: textCase} = style;
10953
10988
  const {canvas: canvas} = Platform, {width: width} = bounds;
10954
10989
  if (style.__isCharMode) {
10955
10990
  const wrap = style.textWrap !== "none";
10956
10991
  const breakAll = style.textWrap === "break";
10992
+ const letterSpacing = style.__letterSpacing;
10993
+ const wordSpacing = style.__wordSpacing;
10957
10994
  paraStart = true;
10958
10995
  lastCharType = null;
10959
10996
  startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
@@ -10974,9 +11011,9 @@ function createRows(drawData, content, style) {
10974
11011
  charType = getCharType(char);
10975
11012
  if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
10976
11013
  charWidth = canvas.measureText(char).width;
10977
- if (__letterSpacing) {
10978
- if (__letterSpacing < 0) charSize = charWidth;
10979
- charWidth += __letterSpacing;
11014
+ if (letterSpacing) {
11015
+ if (letterSpacing < 0) charSize = charWidth;
11016
+ charWidth += letterSpacing;
10980
11017
  }
10981
11018
  langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
10982
11019
  afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
@@ -10997,11 +11034,11 @@ function createRows(drawData, content, style) {
10997
11034
  }
10998
11035
  if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
10999
11036
  if (charType === Break) {
11000
- if (char === " " && wordWidth) addWord();
11037
+ if (char === " " && wordWidth) addWord(wordSpacing);
11001
11038
  addChar(char, charWidth);
11002
11039
  addWord();
11003
11040
  } else if (langBreak || afterBreak) {
11004
- if (wordWidth) addWord();
11041
+ if (wordWidth) addWord(wordSpacing);
11005
11042
  addChar(char, charWidth);
11006
11043
  } else {
11007
11044
  addChar(char, charWidth);
@@ -11037,7 +11074,11 @@ function addChar(char, width) {
11037
11074
  wordWidth += width;
11038
11075
  }
11039
11076
 
11040
- function addWord() {
11077
+ function addWord(wordSpacing) {
11078
+ if (wordSpacing) {
11079
+ rowWidth += wordSpacing;
11080
+ word.addWidth = wordSpacing;
11081
+ }
11041
11082
  rowWidth += wordWidth;
11042
11083
  word.width = wordWidth;
11043
11084
  row.words.push(word);
@@ -11081,6 +11122,7 @@ function layoutChar(drawData, style, width, _height) {
11081
11122
  const {rows: rows} = drawData;
11082
11123
  const {textAlign: textAlign, paraIndent: paraIndent} = style;
11083
11124
  const useLetter = style.__letterSpacing || style.motionText;
11125
+ const wordSpacing = style.__wordSpacing;
11084
11126
  const justifyLast = width && textAlign.includes("both");
11085
11127
  const justify = justifyLast || width && textAlign.includes("justify");
11086
11128
  const justifyLetter = justify && textAlign.includes("letter");
@@ -11093,7 +11135,7 @@ function layoutChar(drawData, style, width, _height) {
11093
11135
  remainingWidth = width - row.width - indentWidth;
11094
11136
  if (justifyLetter) addLetterWidth = remainingWidth / (row.words.reduce((total, item) => total + item.data.length, 0) - 1); else addWordWidth = wordsLength > 1 ? remainingWidth / (wordsLength - 1) : 0;
11095
11137
  }
11096
- mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
11138
+ mode = useLetter || row.isOverflow || justifyLetter ? CharMode : addWordWidth || wordSpacing ? WordMode : TextMode;
11097
11139
  if (row.isOverflow && !useLetter) row.textMode = true;
11098
11140
  if (mode === TextMode) {
11099
11141
  row.x += indentWidth;
@@ -11113,6 +11155,7 @@ function layoutChar(drawData, style, width, _height) {
11113
11155
  } else {
11114
11156
  charX = toChar(word.data, charX, row.data, row.isOverflow, canJustify && addLetterWidth);
11115
11157
  }
11158
+ if (word.addWidth) charX += word.addWidth;
11116
11159
  if (canJustify) {
11117
11160
  isLastWord = index === wordsLength - 1;
11118
11161
  if (addWordWidth) {