@antv/g-lite 2.2.10 → 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.
- package/dist/index.esm.js +82 -57
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +82 -57
- package/dist/index.js.map +1 -1
- package/dist/index.umd.min.js +5 -5
- 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.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 12/
|
|
4
|
+
* @version 2.2.11
|
|
5
|
+
* @date 12/26/2024, 8:33:47 AM
|
|
6
6
|
* @author AntVis
|
|
7
7
|
* @docs https://g.antv.antgroup.com/
|
|
8
8
|
*/
|
|
@@ -11499,99 +11499,123 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11499
11499
|
} else if (textOverflow && textOverflow !== 'clip') {
|
|
11500
11500
|
ellipsis = textOverflow;
|
|
11501
11501
|
}
|
|
11502
|
+
var chars = Array.from(text);
|
|
11502
11503
|
var lines = [];
|
|
11503
|
-
var
|
|
11504
|
-
var
|
|
11504
|
+
var currentLineIndex = 0;
|
|
11505
|
+
var currentLineWidth = 0;
|
|
11505
11506
|
var cache = {};
|
|
11506
|
-
var calcWidth = function calcWidth(
|
|
11507
|
-
return _this2.getFromCache(
|
|
11507
|
+
var calcWidth = function calcWidth(txt) {
|
|
11508
|
+
return _this2.getFromCache(txt, letterSpacing, cache, context);
|
|
11508
11509
|
};
|
|
11509
|
-
var ellipsisWidth =
|
|
11510
|
-
|
|
11511
|
-
|
|
11512
|
-
|
|
11510
|
+
var ellipsisWidth = calcWidth(ellipsis);
|
|
11511
|
+
|
|
11512
|
+
/**
|
|
11513
|
+
* Find text fragments that will take up as much of the given line width as possible when rendered.
|
|
11514
|
+
*
|
|
11515
|
+
* @see https://github.com/antvis/G/issues/1833
|
|
11516
|
+
*
|
|
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
|
+
*/
|
|
11520
|
+
function findCharIndexClosestWidthThreshold(txt, textCharIndex, widthThreshold) {
|
|
11521
|
+
while (calcWidth(txt) < widthThreshold && textCharIndex < chars.length - 1) {
|
|
11522
|
+
textCharIndex += 1;
|
|
11523
|
+
txt += chars[textCharIndex];
|
|
11524
|
+
}
|
|
11525
|
+
while (calcWidth(txt) > widthThreshold) {
|
|
11526
|
+
textCharIndex -= 1;
|
|
11527
|
+
txt = txt.slice(0, -1);
|
|
11528
|
+
}
|
|
11529
|
+
return {
|
|
11530
|
+
txt: txt,
|
|
11531
|
+
textCharIndex: textCharIndex
|
|
11532
|
+
};
|
|
11533
|
+
}
|
|
11534
|
+
function appendEllipsis(lineIndex, textCharIndex) {
|
|
11513
11535
|
// If there is not enough space to display the string itself, it is clipped.
|
|
11514
11536
|
// @see https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow#values
|
|
11515
11537
|
if (ellipsisWidth <= 0 || ellipsisWidth > maxWidth) {
|
|
11516
11538
|
return;
|
|
11517
11539
|
}
|
|
11518
|
-
|
|
11519
|
-
|
|
11520
|
-
|
|
11521
|
-
var lastLineWidth = 0;
|
|
11522
|
-
var lastLineIndex = currentLineLength;
|
|
11523
|
-
for (var i = 0; i < currentLineLength; i++) {
|
|
11524
|
-
var width = calcWidth(lines[lineIndex][i]);
|
|
11525
|
-
if (lastLineWidth + width + ellipsisWidth > maxWidth) {
|
|
11526
|
-
lastLineIndex = i;
|
|
11527
|
-
break;
|
|
11528
|
-
}
|
|
11529
|
-
lastLineWidth += width;
|
|
11540
|
+
if (!lines[lineIndex]) {
|
|
11541
|
+
lines[lineIndex] = ellipsis;
|
|
11542
|
+
return;
|
|
11530
11543
|
}
|
|
11531
|
-
|
|
11544
|
+
var result = findCharIndexClosestWidthThreshold(lines[lineIndex], textCharIndex, maxWidth - ellipsisWidth);
|
|
11545
|
+
lines[lineIndex] = result.txt + ellipsis;
|
|
11532
11546
|
}
|
|
11533
|
-
var chars = Array.from(text);
|
|
11534
11547
|
for (var i = 0; i < chars.length; i++) {
|
|
11535
|
-
var
|
|
11536
|
-
var prevChar =
|
|
11537
|
-
var nextChar =
|
|
11538
|
-
var charWidth = calcWidth(
|
|
11539
|
-
if (this.isNewline(
|
|
11540
|
-
currentIndex++;
|
|
11541
|
-
|
|
11548
|
+
var _char2 = chars[i];
|
|
11549
|
+
var prevChar = chars[i - 1];
|
|
11550
|
+
var nextChar = chars[i + 1];
|
|
11551
|
+
var charWidth = calcWidth(_char2);
|
|
11552
|
+
if (this.isNewline(_char2)) {
|
|
11542
11553
|
// exceed maxLines, break immediately
|
|
11543
|
-
if (
|
|
11554
|
+
if (currentLineIndex + 1 >= maxLines) {
|
|
11544
11555
|
parsedStyle.isOverflowing = true;
|
|
11545
11556
|
if (i < chars.length - 1) {
|
|
11546
|
-
appendEllipsis(
|
|
11557
|
+
appendEllipsis(currentLineIndex, i);
|
|
11547
11558
|
}
|
|
11548
11559
|
break;
|
|
11549
11560
|
}
|
|
11550
|
-
|
|
11551
|
-
|
|
11561
|
+
currentLineIndex += 1;
|
|
11562
|
+
currentLineWidth = 0;
|
|
11563
|
+
lines[currentLineIndex] = '';
|
|
11552
11564
|
continue;
|
|
11553
11565
|
}
|
|
11554
|
-
if (
|
|
11555
|
-
|
|
11566
|
+
if (currentLineWidth > 0 && currentLineWidth + charWidth > maxWidth) {
|
|
11567
|
+
var result = findCharIndexClosestWidthThreshold(lines[currentLineIndex], i, maxWidth);
|
|
11568
|
+
if (result.textCharIndex !== i) {
|
|
11569
|
+
lines[currentLineIndex] = result.txt;
|
|
11570
|
+
if (result.textCharIndex === chars.length - 1) {
|
|
11571
|
+
break;
|
|
11572
|
+
}
|
|
11573
|
+
i = result.textCharIndex;
|
|
11574
|
+
_char2 = chars[i];
|
|
11575
|
+
prevChar = chars[i - 1];
|
|
11576
|
+
nextChar = chars[i + 1];
|
|
11577
|
+
charWidth = calcWidth(_char2);
|
|
11578
|
+
}
|
|
11579
|
+
if (currentLineIndex + 1 >= maxLines) {
|
|
11556
11580
|
parsedStyle.isOverflowing = true;
|
|
11557
|
-
appendEllipsis(
|
|
11581
|
+
appendEllipsis(currentLineIndex, i);
|
|
11558
11582
|
break;
|
|
11559
11583
|
}
|
|
11560
|
-
|
|
11561
|
-
|
|
11562
|
-
lines[
|
|
11563
|
-
if (this.isBreakingSpace(
|
|
11584
|
+
currentLineIndex += 1;
|
|
11585
|
+
currentLineWidth = 0;
|
|
11586
|
+
lines[currentLineIndex] = '';
|
|
11587
|
+
if (this.isBreakingSpace(_char2)) {
|
|
11564
11588
|
continue;
|
|
11565
11589
|
}
|
|
11566
|
-
if (!this.canBreakInLastChar(
|
|
11590
|
+
if (!this.canBreakInLastChar(_char2)) {
|
|
11567
11591
|
lines = this.trimToBreakable(lines);
|
|
11568
|
-
|
|
11592
|
+
currentLineWidth = this.sumTextWidthByCache(lines[currentLineIndex] || '', cache);
|
|
11569
11593
|
}
|
|
11570
|
-
if (this.shouldBreakByKinsokuShorui(
|
|
11594
|
+
if (this.shouldBreakByKinsokuShorui(_char2, nextChar)) {
|
|
11571
11595
|
lines = this.trimByKinsokuShorui(lines);
|
|
11572
|
-
|
|
11596
|
+
currentLineWidth += calcWidth(prevChar || '');
|
|
11573
11597
|
}
|
|
11574
11598
|
}
|
|
11575
|
-
|
|
11576
|
-
lines[
|
|
11599
|
+
currentLineWidth += charWidth;
|
|
11600
|
+
lines[currentLineIndex] = (lines[currentLineIndex] || '') + _char2;
|
|
11577
11601
|
}
|
|
11578
11602
|
return lines.join('\n');
|
|
11579
11603
|
}
|
|
11580
11604
|
}, {
|
|
11581
11605
|
key: "isBreakingSpace",
|
|
11582
|
-
value: function isBreakingSpace(
|
|
11583
|
-
if (typeof
|
|
11606
|
+
value: function isBreakingSpace(_char3) {
|
|
11607
|
+
if (typeof _char3 !== 'string') {
|
|
11584
11608
|
return false;
|
|
11585
11609
|
}
|
|
11586
|
-
return TEXT_METRICS.BreakingSpaces.indexOf(
|
|
11610
|
+
return TEXT_METRICS.BreakingSpaces.indexOf(_char3.charCodeAt(0)) >= 0;
|
|
11587
11611
|
}
|
|
11588
11612
|
}, {
|
|
11589
11613
|
key: "isNewline",
|
|
11590
|
-
value: function isNewline(
|
|
11591
|
-
if (typeof
|
|
11614
|
+
value: function isNewline(_char4) {
|
|
11615
|
+
if (typeof _char4 !== 'string') {
|
|
11592
11616
|
return false;
|
|
11593
11617
|
}
|
|
11594
|
-
return TEXT_METRICS.Newlines.indexOf(
|
|
11618
|
+
return TEXT_METRICS.Newlines.indexOf(_char4.charCodeAt(0)) >= 0;
|
|
11595
11619
|
}
|
|
11596
11620
|
}, {
|
|
11597
11621
|
key: "trimToBreakable",
|
|
@@ -11610,8 +11634,8 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11610
11634
|
}
|
|
11611
11635
|
}, {
|
|
11612
11636
|
key: "canBreakInLastChar",
|
|
11613
|
-
value: function canBreakInLastChar(
|
|
11614
|
-
if (
|
|
11637
|
+
value: function canBreakInLastChar(_char5) {
|
|
11638
|
+
if (_char5 && LATIN_REGEX.test(_char5)) return false;
|
|
11615
11639
|
return true;
|
|
11616
11640
|
}
|
|
11617
11641
|
}, {
|
|
@@ -11636,7 +11660,8 @@ var TextService = /*#__PURE__*/function () {
|
|
|
11636
11660
|
var width = cache[key];
|
|
11637
11661
|
if (typeof width !== 'number') {
|
|
11638
11662
|
var spacing = key.length * letterSpacing;
|
|
11639
|
-
|
|
11663
|
+
var metrics = context.measureText(key);
|
|
11664
|
+
width = metrics.width + spacing;
|
|
11640
11665
|
cache[key] = width;
|
|
11641
11666
|
}
|
|
11642
11667
|
return width;
|