@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.esm.js +28 -20
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +28 -20
- package/dist/index.js.map +1 -1
- package/dist/index.umd.min.js +4 -4
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/types/services/TextService.d.ts.map +1 -1
package/dist/index.esm.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.
|
|
5
|
-
* @date
|
|
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
|
*/
|
|
@@ -11463,6 +11463,7 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11463
11463
|
key: "wordWrap",
|
|
11464
11464
|
value: function wordWrap(text, parsedStyle, offscreenCanvas) {
|
|
11465
11465
|
var _this2 = this;
|
|
11466
|
+
var self = this;
|
|
11466
11467
|
var _parsedStyle$wordWrap2 = parsedStyle.wordWrapWidth,
|
|
11467
11468
|
wordWrapWidth = _parsedStyle$wordWrap2 === void 0 ? 0 : _parsedStyle$wordWrap2,
|
|
11468
11469
|
_parsedStyle$letterSp2 = parsedStyle.letterSpacing,
|
|
@@ -11482,6 +11483,7 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11482
11483
|
var lines = [];
|
|
11483
11484
|
var currentLineIndex = 0;
|
|
11484
11485
|
var currentLineWidth = 0;
|
|
11486
|
+
var prevLineLastCharIndex = 0;
|
|
11485
11487
|
var cache = {};
|
|
11486
11488
|
var calcWidth = function calcWidth(txt) {
|
|
11487
11489
|
return _this2.getFromCache(txt, letterSpacing, cache, context);
|
|
@@ -11493,21 +11495,25 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11493
11495
|
*
|
|
11494
11496
|
* @see https://github.com/antvis/G/issues/1833
|
|
11495
11497
|
*
|
|
11496
|
-
* @param
|
|
11497
|
-
* @param
|
|
11498
|
+
* @param lineTxt - Current line of text
|
|
11499
|
+
* @param txtLastCharIndex - The index of the last character of the current line in the entire text
|
|
11500
|
+
* @param txtStartCharIndex - The index of the start character of the current line in the entire text
|
|
11498
11501
|
*/
|
|
11499
|
-
function findCharIndexClosestWidthThreshold(
|
|
11500
|
-
while (calcWidth(
|
|
11501
|
-
|
|
11502
|
-
|
|
11502
|
+
function findCharIndexClosestWidthThreshold(lineTxt, txtLastCharIndex, txtStartCharIndex, widthThreshold) {
|
|
11503
|
+
while (calcWidth(lineTxt) < widthThreshold && txtLastCharIndex < chars.length - 1) {
|
|
11504
|
+
if (self.isNewline(chars[txtLastCharIndex + 1])) {
|
|
11505
|
+
break;
|
|
11506
|
+
}
|
|
11507
|
+
txtLastCharIndex += 1;
|
|
11508
|
+
lineTxt += chars[txtLastCharIndex];
|
|
11503
11509
|
}
|
|
11504
|
-
while (calcWidth(
|
|
11505
|
-
|
|
11506
|
-
|
|
11510
|
+
while (calcWidth(lineTxt) > widthThreshold && txtLastCharIndex > txtStartCharIndex) {
|
|
11511
|
+
txtLastCharIndex -= 1;
|
|
11512
|
+
lineTxt = lineTxt.slice(0, -1);
|
|
11507
11513
|
}
|
|
11508
11514
|
return {
|
|
11509
|
-
|
|
11510
|
-
|
|
11515
|
+
lineTxt: lineTxt,
|
|
11516
|
+
txtLastCharIndex: txtLastCharIndex
|
|
11511
11517
|
};
|
|
11512
11518
|
}
|
|
11513
11519
|
function appendEllipsis(lineIndex, textCharIndex) {
|
|
@@ -11520,8 +11526,8 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11520
11526
|
lines[lineIndex] = ellipsis;
|
|
11521
11527
|
return;
|
|
11522
11528
|
}
|
|
11523
|
-
var result = findCharIndexClosestWidthThreshold(lines[lineIndex], textCharIndex, maxWidth - ellipsisWidth);
|
|
11524
|
-
lines[lineIndex] = result.
|
|
11529
|
+
var result = findCharIndexClosestWidthThreshold(lines[lineIndex], textCharIndex, prevLineLastCharIndex + 1, maxWidth - ellipsisWidth);
|
|
11530
|
+
lines[lineIndex] = result.lineTxt + ellipsis;
|
|
11525
11531
|
}
|
|
11526
11532
|
for (var i = 0; i < chars.length; i++) {
|
|
11527
11533
|
var _char2 = chars[i];
|
|
@@ -11537,19 +11543,20 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11537
11543
|
}
|
|
11538
11544
|
break;
|
|
11539
11545
|
}
|
|
11546
|
+
prevLineLastCharIndex = i - 1;
|
|
11540
11547
|
currentLineIndex += 1;
|
|
11541
11548
|
currentLineWidth = 0;
|
|
11542
11549
|
lines[currentLineIndex] = '';
|
|
11543
11550
|
continue;
|
|
11544
11551
|
}
|
|
11545
11552
|
if (currentLineWidth > 0 && currentLineWidth + charWidth > maxWidth) {
|
|
11546
|
-
var result = findCharIndexClosestWidthThreshold(lines[currentLineIndex], i - 1, maxWidth);
|
|
11547
|
-
if (result.
|
|
11548
|
-
lines[currentLineIndex] = result.
|
|
11549
|
-
if (result.
|
|
11553
|
+
var result = findCharIndexClosestWidthThreshold(lines[currentLineIndex], i - 1, prevLineLastCharIndex + 1, maxWidth);
|
|
11554
|
+
if (result.txtLastCharIndex !== i - 1) {
|
|
11555
|
+
lines[currentLineIndex] = result.lineTxt;
|
|
11556
|
+
if (result.txtLastCharIndex === chars.length - 1) {
|
|
11550
11557
|
break;
|
|
11551
11558
|
}
|
|
11552
|
-
i = result.
|
|
11559
|
+
i = result.txtLastCharIndex + 1;
|
|
11553
11560
|
_char2 = chars[i];
|
|
11554
11561
|
prevChar = chars[i - 1];
|
|
11555
11562
|
nextChar = chars[i + 1];
|
|
@@ -11560,6 +11567,7 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11560
11567
|
appendEllipsis(currentLineIndex, i - 1);
|
|
11561
11568
|
break;
|
|
11562
11569
|
}
|
|
11570
|
+
prevLineLastCharIndex = i - 1;
|
|
11563
11571
|
currentLineIndex += 1;
|
|
11564
11572
|
currentLineWidth = 0;
|
|
11565
11573
|
lines[currentLineIndex] = '';
|