@cjser/string-width 8.2.1-cjser.2 → 8.2.2-cjser.2
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-cjser/index.cjs +7 -6
- package/index.js +12 -8
- package/package.json +4 -4
package/dist-cjser/index.cjs
CHANGED
|
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
28
|
|
|
29
|
-
// packages/@cjser/string-width/index.js
|
|
29
|
+
// packages/@cjser/string-width.tmp-26-1783614088733/index.js
|
|
30
30
|
var index_exports = {};
|
|
31
31
|
__export(index_exports, {
|
|
32
32
|
default: () => stringWidth
|
|
@@ -35,8 +35,9 @@ module.exports = __toCommonJS(index_exports);
|
|
|
35
35
|
var import_strip_ansi = __toESM(require("@cjser/strip-ansi"), 1);
|
|
36
36
|
var import_get_east_asian_width = require("@cjser/get-east-asian-width");
|
|
37
37
|
var segmenter = new Intl.Segmenter();
|
|
38
|
-
var zeroWidthClusterRegex = new RegExp("^(?:\\p{Default_Ignorable_Code_Point}|\\p{Control}|\\p{Format}|\\p{
|
|
39
|
-
var leadingNonPrintingRegex = new RegExp("^[\\p{Default_Ignorable_Code_Point}\\p{Control}\\p{Format}\\p{
|
|
38
|
+
var zeroWidthClusterRegex = new RegExp("^(?:\\p{Default_Ignorable_Code_Point}|\\p{Control}|\\p{Format}|\\p{Nonspacing_Mark}|\\p{Enclosing_Mark}|\\p{Surrogate})+$", "v");
|
|
39
|
+
var leadingNonPrintingRegex = new RegExp("^[\\p{Default_Ignorable_Code_Point}\\p{Control}\\p{Format}\\p{Nonspacing_Mark}\\p{Enclosing_Mark}\\p{Surrogate}]+", "v");
|
|
40
|
+
var spacingMarkRegex = new RegExp("\\p{Spacing_Mark}", "v");
|
|
40
41
|
var rgiEmojiRegex = new RegExp("^\\p{RGI_Emoji}$", "v");
|
|
41
42
|
var unqualifiedKeycapRegex = /^[\d#*]\u20E3$/;
|
|
42
43
|
var extendedPictographicRegex = new RegExp("\\p{Extended_Pictographic}", "gu");
|
|
@@ -103,7 +104,7 @@ function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
|
|
|
103
104
|
}
|
|
104
105
|
return width;
|
|
105
106
|
}
|
|
106
|
-
function
|
|
107
|
+
function trailingWidth(visibleSegment, eastAsianWidthOptions) {
|
|
107
108
|
let extra = 0;
|
|
108
109
|
let first = true;
|
|
109
110
|
for (const character of visibleSegment) {
|
|
@@ -111,7 +112,7 @@ function trailingHalfwidthWidth(visibleSegment, eastAsianWidthOptions) {
|
|
|
111
112
|
first = false;
|
|
112
113
|
continue;
|
|
113
114
|
}
|
|
114
|
-
if (character >= "\uFF00" && character <= "\uFFEF") {
|
|
115
|
+
if (spacingMarkRegex.test(character) || character >= "\uFF00" && character <= "\uFFEF") {
|
|
115
116
|
extra += (0, import_get_east_asian_width.eastAsianWidth)(character.codePointAt(0), eastAsianWidthOptions);
|
|
116
117
|
}
|
|
117
118
|
}
|
|
@@ -153,7 +154,7 @@ function stringWidth(input, options = {}) {
|
|
|
153
154
|
}
|
|
154
155
|
const codePoint = visibleSegment.codePointAt(0);
|
|
155
156
|
width += (0, import_get_east_asian_width.eastAsianWidth)(codePoint, eastAsianWidthOptions);
|
|
156
|
-
width +=
|
|
157
|
+
width += trailingWidth(visibleSegment, eastAsianWidthOptions);
|
|
157
158
|
}
|
|
158
159
|
return width;
|
|
159
160
|
}
|
package/index.js
CHANGED
|
@@ -5,21 +5,22 @@ import {eastAsianWidth} from '@cjser/get-east-asian-width';
|
|
|
5
5
|
Logic:
|
|
6
6
|
- Segment graphemes to match how terminals render clusters.
|
|
7
7
|
- Width rules:
|
|
8
|
-
1. Skip non-printing clusters (Default_Ignorable, Control, pure Mark, lone Surrogates). Tabs are ignored by design.
|
|
8
|
+
1. Skip non-printing clusters (Default_Ignorable, Control, pure nonspacing/enclosing Mark, lone Surrogates). Tabs are ignored by design.
|
|
9
9
|
2. RGI emoji clusters (\p{RGI_Emoji}) are double-width.
|
|
10
10
|
3. Minimally-qualified/unqualified emoji clusters (ZWJ sequences with 2+ Extended_Pictographic, or keycap sequences) are double-width.
|
|
11
11
|
4. Hangul jamo collapse each standard modern Hangul L+V or L+V+T syllable piece to width 2.
|
|
12
12
|
Unmatched repeated leading/vowel/trailing jamo stay additive because that matches how the terminals we target render them.
|
|
13
|
-
5. Otherwise use East Asian Width of the cluster's first visible code point, and add widths for trailing Halfwidth/Fullwidth Forms within the same cluster (e.g., dakuten/handakuten/prolonged sound mark).
|
|
13
|
+
5. Otherwise use East Asian Width of the cluster's first visible code point, and add widths for trailing spacing marks and Halfwidth/Fullwidth Forms within the same cluster (e.g., dakuten/handakuten/prolonged sound mark).
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
const segmenter = new Intl.Segmenter();
|
|
17
17
|
|
|
18
18
|
// Whole-cluster zero-width
|
|
19
|
-
const zeroWidthClusterRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Format}|\p{
|
|
19
|
+
const zeroWidthClusterRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Format}|\p{Nonspacing_Mark}|\p{Enclosing_Mark}|\p{Surrogate})+$/v;
|
|
20
20
|
|
|
21
21
|
// Pick the base scalar if the cluster starts with Prepend/Format/Marks
|
|
22
|
-
const leadingNonPrintingRegex = /^[\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{
|
|
22
|
+
const leadingNonPrintingRegex = /^[\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Nonspacing_Mark}\p{Enclosing_Mark}\p{Surrogate}]+/v;
|
|
23
|
+
const spacingMarkRegex = /\p{Spacing_Mark}/v;
|
|
23
24
|
|
|
24
25
|
// RGI emoji sequences
|
|
25
26
|
const rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
|
|
@@ -125,7 +126,7 @@ function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
|
|
|
125
126
|
return width;
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
function
|
|
129
|
+
function trailingWidth(visibleSegment, eastAsianWidthOptions) {
|
|
129
130
|
let extra = 0;
|
|
130
131
|
let first = true;
|
|
131
132
|
|
|
@@ -135,7 +136,10 @@ function trailingHalfwidthWidth(visibleSegment, eastAsianWidthOptions) {
|
|
|
135
136
|
continue;
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
if (
|
|
139
|
+
if (
|
|
140
|
+
spacingMarkRegex.test(character)
|
|
141
|
+
|| (character >= '\uFF00' && character <= '\uFFEF')
|
|
142
|
+
) {
|
|
139
143
|
extra += eastAsianWidth(character.codePointAt(0), eastAsianWidthOptions);
|
|
140
144
|
}
|
|
141
145
|
}
|
|
@@ -195,8 +199,8 @@ export default function stringWidth(input, options = {}) {
|
|
|
195
199
|
const codePoint = visibleSegment.codePointAt(0);
|
|
196
200
|
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
197
201
|
|
|
198
|
-
// Add width for trailing
|
|
199
|
-
width +=
|
|
202
|
+
// Add width for trailing spacing marks and Halfwidth/Fullwidth Forms (e.g., ゙, ゚, ー)
|
|
203
|
+
width += trailingWidth(visibleSegment, eastAsianWidthOptions);
|
|
200
204
|
}
|
|
201
205
|
|
|
202
206
|
return width;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cjser/string-width",
|
|
3
|
-
"version": "8.2.
|
|
3
|
+
"version": "8.2.2-cjser.2",
|
|
4
4
|
"description": "Get the visual width of a string - the number of columns required to display it",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"east-asian-width"
|
|
60
60
|
],
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@cjser/get-east-asian-width": "1.
|
|
62
|
+
"@cjser/get-east-asian-width": "1.6.0-cjser.2",
|
|
63
63
|
"@cjser/strip-ansi": "7.2.0-cjser.2"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
"types": "./index.d.ts",
|
|
71
71
|
"main": "./dist-cjser/index.cjs",
|
|
72
72
|
"cjser": {
|
|
73
|
-
"sourceVersion": "8.2.
|
|
73
|
+
"sourceVersion": "8.2.2",
|
|
74
74
|
"cjserVersion": 2,
|
|
75
75
|
"original": {
|
|
76
76
|
"name": "string-width",
|
|
77
|
-
"version": "8.2.
|
|
77
|
+
"version": "8.2.2",
|
|
78
78
|
"exports": {
|
|
79
79
|
"types": "./index.d.ts",
|
|
80
80
|
"default": "./index.js"
|