@antv/g-lite 2.2.12 → 2.2.14

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.
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /*!
2
2
  * @antv/g-lite
3
3
  * @description A core module for rendering engine implements DOM API.
4
- * @version 2.2.12
5
- * @date 12/26/2024, 12:57:25 PM
4
+ * @version 2.2.14
5
+ * @date 1/2/2025, 2:54:20 AM
6
6
  * @author AntVis
7
7
  * @docs https://g.antv.antgroup.com/
8
8
  */
@@ -11484,6 +11484,7 @@ var TextService = /*#__PURE__*/function () {
11484
11484
  key: "wordWrap",
11485
11485
  value: function wordWrap(text, parsedStyle, offscreenCanvas) {
11486
11486
  var _this2 = this;
11487
+ var self = this;
11487
11488
  var _parsedStyle$wordWrap2 = parsedStyle.wordWrapWidth,
11488
11489
  wordWrapWidth = _parsedStyle$wordWrap2 === void 0 ? 0 : _parsedStyle$wordWrap2,
11489
11490
  _parsedStyle$letterSp2 = parsedStyle.letterSpacing,
@@ -11503,6 +11504,7 @@ var TextService = /*#__PURE__*/function () {
11503
11504
  var lines = [];
11504
11505
  var currentLineIndex = 0;
11505
11506
  var currentLineWidth = 0;
11507
+ var prevLineLastCharIndex = 0;
11506
11508
  var cache = {};
11507
11509
  var calcWidth = function calcWidth(txt) {
11508
11510
  return _this2.getFromCache(txt, letterSpacing, cache, context);
@@ -11514,21 +11516,25 @@ var TextService = /*#__PURE__*/function () {
11514
11516
  *
11515
11517
  * @see https://github.com/antvis/G/issues/1833
11516
11518
  *
11517
- * @param txt - Current line of text
11518
- * @param textCharIndex - The index of the last character of the current line in the entire text
11519
+ * @param lineTxt - Current line of text
11520
+ * @param txtLastCharIndex - The index of the last character of the current line in the entire text
11521
+ * @param txtStartCharIndex - The index of the start character of the current line in the entire text
11519
11522
  */
11520
- function findCharIndexClosestWidthThreshold(txt, textCharIndex, widthThreshold) {
11521
- while (calcWidth(txt) < widthThreshold && textCharIndex < chars.length - 1) {
11522
- textCharIndex += 1;
11523
- txt += chars[textCharIndex];
11523
+ function findCharIndexClosestWidthThreshold(lineTxt, txtLastCharIndex, txtStartCharIndex, widthThreshold) {
11524
+ while (calcWidth(lineTxt) < widthThreshold && txtLastCharIndex < chars.length - 1) {
11525
+ if (self.isNewline(chars[txtLastCharIndex + 1])) {
11526
+ break;
11527
+ }
11528
+ txtLastCharIndex += 1;
11529
+ lineTxt += chars[txtLastCharIndex];
11524
11530
  }
11525
- while (calcWidth(txt) > widthThreshold && textCharIndex > 0) {
11526
- textCharIndex -= 1;
11527
- txt = txt.slice(0, -1);
11531
+ while (calcWidth(lineTxt) > widthThreshold && txtLastCharIndex > txtStartCharIndex) {
11532
+ txtLastCharIndex -= 1;
11533
+ lineTxt = lineTxt.slice(0, -1);
11528
11534
  }
11529
11535
  return {
11530
- txt: txt,
11531
- textCharIndex: textCharIndex
11536
+ lineTxt: lineTxt,
11537
+ txtLastCharIndex: txtLastCharIndex
11532
11538
  };
11533
11539
  }
11534
11540
  function appendEllipsis(lineIndex, textCharIndex) {
@@ -11541,8 +11547,8 @@ var TextService = /*#__PURE__*/function () {
11541
11547
  lines[lineIndex] = ellipsis;
11542
11548
  return;
11543
11549
  }
11544
- var result = findCharIndexClosestWidthThreshold(lines[lineIndex], textCharIndex, maxWidth - ellipsisWidth);
11545
- lines[lineIndex] = result.txt + ellipsis;
11550
+ var result = findCharIndexClosestWidthThreshold(lines[lineIndex], textCharIndex, prevLineLastCharIndex + 1, maxWidth - ellipsisWidth);
11551
+ lines[lineIndex] = result.lineTxt + ellipsis;
11546
11552
  }
11547
11553
  for (var i = 0; i < chars.length; i++) {
11548
11554
  var _char2 = chars[i];
@@ -11558,19 +11564,20 @@ var TextService = /*#__PURE__*/function () {
11558
11564
  }
11559
11565
  break;
11560
11566
  }
11567
+ prevLineLastCharIndex = i - 1;
11561
11568
  currentLineIndex += 1;
11562
11569
  currentLineWidth = 0;
11563
11570
  lines[currentLineIndex] = '';
11564
11571
  continue;
11565
11572
  }
11566
11573
  if (currentLineWidth > 0 && currentLineWidth + charWidth > maxWidth) {
11567
- var result = findCharIndexClosestWidthThreshold(lines[currentLineIndex], i - 1, maxWidth);
11568
- if (result.textCharIndex !== i - 1) {
11569
- lines[currentLineIndex] = result.txt;
11570
- if (result.textCharIndex === chars.length - 1) {
11574
+ var result = findCharIndexClosestWidthThreshold(lines[currentLineIndex], i - 1, prevLineLastCharIndex + 1, maxWidth);
11575
+ if (result.txtLastCharIndex !== i - 1) {
11576
+ lines[currentLineIndex] = result.lineTxt;
11577
+ if (result.txtLastCharIndex === chars.length - 1) {
11571
11578
  break;
11572
11579
  }
11573
- i = result.textCharIndex + 1;
11580
+ i = result.txtLastCharIndex + 1;
11574
11581
  _char2 = chars[i];
11575
11582
  prevChar = chars[i - 1];
11576
11583
  nextChar = chars[i + 1];
@@ -11581,6 +11588,7 @@ var TextService = /*#__PURE__*/function () {
11581
11588
  appendEllipsis(currentLineIndex, i - 1);
11582
11589
  break;
11583
11590
  }
11591
+ prevLineLastCharIndex = i - 1;
11584
11592
  currentLineIndex += 1;
11585
11593
  currentLineWidth = 0;
11586
11594
  lines[currentLineIndex] = '';