@descent-vtt/spec-brief 0.2.7 → 0.3.0
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/CHANGELOG.md +67 -1
- package/README.md +162 -29
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +61 -43
- package/dist/cli.js.map +1 -1
- package/dist/collisions.js +13 -8
- package/dist/collisions.js.map +1 -1
- package/dist/config.js +2 -1
- package/dist/config.js.map +1 -1
- package/dist/corpus.d.ts +5 -0
- package/dist/corpus.js +7 -0
- package/dist/corpus.js.map +1 -1
- package/dist/glob.d.ts +6 -5
- package/dist/glob.js +22 -103
- package/dist/glob.js.map +1 -1
- package/dist/lint.js +1 -0
- package/dist/lint.js.map +1 -1
- package/dist/report.d.ts +18 -4
- package/dist/report.js +98 -28
- package/dist/report.js.map +1 -1
- package/dist/rules.d.ts +2 -0
- package/dist/rules.js +21 -8
- package/dist/rules.js.map +1 -1
- package/dist/schedule.js +12 -10
- package/dist/schedule.js.map +1 -1
- package/dist/schema.d.ts +5 -1
- package/dist/schema.js +6 -2
- package/dist/schema.js.map +1 -1
- package/dist/scope.d.ts +26 -4
- package/dist/scope.js +64 -8
- package/dist/scope.js.map +1 -1
- package/dist/trigger.js +59 -3
- package/dist/trigger.js.map +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/types.js.map +1 -1
- package/dist/vendor/spec-core/markdown/frontmatter.d.ts +11 -1
- package/dist/vendor/spec-core/markdown/frontmatter.js +20 -3
- package/dist/vendor/spec-core/markdown/frontmatter.js.map +1 -1
- package/dist/vendor/spec-core/pattern/glob.d.ts +85 -0
- package/dist/vendor/spec-core/pattern/glob.js +207 -17
- package/dist/vendor/spec-core/pattern/glob.js.map +1 -1
- package/dist/vendor/spec-core/pattern/index.d.ts +2 -2
- package/dist/vendor/spec-core/pattern/index.js +1 -1
- package/dist/vendor/spec-core/pattern/index.js.map +1 -1
- package/dist/vendor/spec-core/text/index.d.ts +1 -0
- package/dist/vendor/spec-core/text/index.js +1 -0
- package/dist/vendor/spec-core/text/index.js.map +1 -1
- package/dist/vendor/spec-core/text/width.d.ts +30 -0
- package/dist/vendor/spec-core/text/width.js +113 -0
- package/dist/vendor/spec-core/text/width.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How many columns of a terminal a text takes, for a tool that lines up the
|
|
3
|
+
* columns of a table it prints: `.padEnd` counts UTF-16 units, and `已接受`
|
|
4
|
+
* is three of them and six columns.
|
|
5
|
+
*
|
|
6
|
+
* Counted per grapheme cluster, as a terminal draws one: a cluster takes the
|
|
7
|
+
* width of the first character in it that shows, and what follows that
|
|
8
|
+
* character - a combining mark, a variation selector, a joiner and what it
|
|
9
|
+
* joins - adds nothing.
|
|
10
|
+
*
|
|
11
|
+
* - An East Asian Wide or Fullwidth character takes two: Han, kana and
|
|
12
|
+
* hangul, full-width forms, and most emoji.
|
|
13
|
+
* - So does an emoji sequence, whatever its first character's own width: an
|
|
14
|
+
* emoji and the presentation selector U+FE0F (`❤` with it, and a keycap),
|
|
15
|
+
* a modifier base and a skin tone (`☝` with one), and a flag, two
|
|
16
|
+
* regional indicators.
|
|
17
|
+
* - A cluster of nothing that shows takes none: combining marks, format
|
|
18
|
+
* characters - the zero-width space and joiners, the byte-order mark, the
|
|
19
|
+
* bidirectional controls - and control characters. A soft hyphen shows, as
|
|
20
|
+
* terminals draw one.
|
|
21
|
+
* - Everything else takes one, East Asian Ambiguous included, as a terminal
|
|
22
|
+
* draws it outside a legacy East Asian mode.
|
|
23
|
+
*
|
|
24
|
+
* The widths are the table below, fixed. Grapheme clusters and general
|
|
25
|
+
* categories are the runtime's, and a runtime knows the characters of its
|
|
26
|
+
* own Unicode version: only a character assigned after the older of two
|
|
27
|
+
* hosts' versions can be counted differently on them.
|
|
28
|
+
*/
|
|
29
|
+
/** The columns a text takes in a terminal. */
|
|
30
|
+
export declare function displayWidth(text: string): number;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How many columns of a terminal a text takes, for a tool that lines up the
|
|
3
|
+
* columns of a table it prints: `.padEnd` counts UTF-16 units, and `已接受`
|
|
4
|
+
* is three of them and six columns.
|
|
5
|
+
*
|
|
6
|
+
* Counted per grapheme cluster, as a terminal draws one: a cluster takes the
|
|
7
|
+
* width of the first character in it that shows, and what follows that
|
|
8
|
+
* character - a combining mark, a variation selector, a joiner and what it
|
|
9
|
+
* joins - adds nothing.
|
|
10
|
+
*
|
|
11
|
+
* - An East Asian Wide or Fullwidth character takes two: Han, kana and
|
|
12
|
+
* hangul, full-width forms, and most emoji.
|
|
13
|
+
* - So does an emoji sequence, whatever its first character's own width: an
|
|
14
|
+
* emoji and the presentation selector U+FE0F (`❤` with it, and a keycap),
|
|
15
|
+
* a modifier base and a skin tone (`☝` with one), and a flag, two
|
|
16
|
+
* regional indicators.
|
|
17
|
+
* - A cluster of nothing that shows takes none: combining marks, format
|
|
18
|
+
* characters - the zero-width space and joiners, the byte-order mark, the
|
|
19
|
+
* bidirectional controls - and control characters. A soft hyphen shows, as
|
|
20
|
+
* terminals draw one.
|
|
21
|
+
* - Everything else takes one, East Asian Ambiguous included, as a terminal
|
|
22
|
+
* draws it outside a legacy East Asian mode.
|
|
23
|
+
*
|
|
24
|
+
* The widths are the table below, fixed. Grapheme clusters and general
|
|
25
|
+
* categories are the runtime's, and a runtime knows the characters of its
|
|
26
|
+
* own Unicode version: only a character assigned after the older of two
|
|
27
|
+
* hosts' versions can be counted differently on them.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* The East Asian Wide and Fullwidth code points of Unicode 16.0.0
|
|
31
|
+
* (EastAsianWidth-16.0.0.txt), the unassigned ones its `@missing` lines
|
|
32
|
+
* make Wide included, as the first and last of each run, in order.
|
|
33
|
+
*
|
|
34
|
+
* 16.0 is the version both supported lines have: Node 22.16.0 reports
|
|
35
|
+
* `process.versions.unicode` 16.0, and Node 24.18.1 17.0, which Node 22 does
|
|
36
|
+
* not ship. A character is counted as the older line knows it; one 17.0
|
|
37
|
+
* added counts one, as it does on a host that cannot name it.
|
|
38
|
+
*/
|
|
39
|
+
const WIDE = [
|
|
40
|
+
0x1100, 0x115f, 0x231a, 0x231b, 0x2329, 0x232a, 0x23e9, 0x23ec, 0x23f0, 0x23f0, 0x23f3, 0x23f3,
|
|
41
|
+
0x25fd, 0x25fe, 0x2614, 0x2615, 0x2630, 0x2637, 0x2648, 0x2653, 0x267f, 0x267f, 0x268a, 0x268f,
|
|
42
|
+
0x2693, 0x2693, 0x26a1, 0x26a1, 0x26aa, 0x26ab, 0x26bd, 0x26be, 0x26c4, 0x26c5, 0x26ce, 0x26ce,
|
|
43
|
+
0x26d4, 0x26d4, 0x26ea, 0x26ea, 0x26f2, 0x26f3, 0x26f5, 0x26f5, 0x26fa, 0x26fa, 0x26fd, 0x26fd,
|
|
44
|
+
0x2705, 0x2705, 0x270a, 0x270b, 0x2728, 0x2728, 0x274c, 0x274c, 0x274e, 0x274e, 0x2753, 0x2755,
|
|
45
|
+
0x2757, 0x2757, 0x2795, 0x2797, 0x27b0, 0x27b0, 0x27bf, 0x27bf, 0x2b1b, 0x2b1c, 0x2b50, 0x2b50,
|
|
46
|
+
0x2b55, 0x2b55, 0x2e80, 0x2e99, 0x2e9b, 0x2ef3, 0x2f00, 0x2fd5, 0x2ff0, 0x303e, 0x3041, 0x3096,
|
|
47
|
+
0x3099, 0x30ff, 0x3105, 0x312f, 0x3131, 0x318e, 0x3190, 0x31e5, 0x31ef, 0x321e, 0x3220, 0x3247,
|
|
48
|
+
0x3250, 0xa48c, 0xa490, 0xa4c6, 0xa960, 0xa97c, 0xac00, 0xd7a3, 0xf900, 0xfaff, 0xfe10, 0xfe19,
|
|
49
|
+
0xfe30, 0xfe52, 0xfe54, 0xfe66, 0xfe68, 0xfe6b, 0xff01, 0xff60, 0xffe0, 0xffe6, 0x16fe0, 0x16fe4,
|
|
50
|
+
0x16ff0, 0x16ff1, 0x17000, 0x187f7, 0x18800, 0x18cd5, 0x18cff, 0x18d08, 0x1aff0, 0x1aff3,
|
|
51
|
+
0x1aff5, 0x1affb, 0x1affd, 0x1affe, 0x1b000, 0x1b122, 0x1b132, 0x1b132, 0x1b150, 0x1b152,
|
|
52
|
+
0x1b155, 0x1b155, 0x1b164, 0x1b167, 0x1b170, 0x1b2fb, 0x1d300, 0x1d356, 0x1d360, 0x1d376,
|
|
53
|
+
0x1f004, 0x1f004, 0x1f0cf, 0x1f0cf, 0x1f18e, 0x1f18e, 0x1f191, 0x1f19a, 0x1f200, 0x1f202,
|
|
54
|
+
0x1f210, 0x1f23b, 0x1f240, 0x1f248, 0x1f250, 0x1f251, 0x1f260, 0x1f265, 0x1f300, 0x1f320,
|
|
55
|
+
0x1f32d, 0x1f335, 0x1f337, 0x1f37c, 0x1f37e, 0x1f393, 0x1f3a0, 0x1f3ca, 0x1f3cf, 0x1f3d3,
|
|
56
|
+
0x1f3e0, 0x1f3f0, 0x1f3f4, 0x1f3f4, 0x1f3f8, 0x1f43e, 0x1f440, 0x1f440, 0x1f442, 0x1f4fc,
|
|
57
|
+
0x1f4ff, 0x1f53d, 0x1f54b, 0x1f54e, 0x1f550, 0x1f567, 0x1f57a, 0x1f57a, 0x1f595, 0x1f596,
|
|
58
|
+
0x1f5a4, 0x1f5a4, 0x1f5fb, 0x1f64f, 0x1f680, 0x1f6c5, 0x1f6cc, 0x1f6cc, 0x1f6d0, 0x1f6d2,
|
|
59
|
+
0x1f6d5, 0x1f6d7, 0x1f6dc, 0x1f6df, 0x1f6eb, 0x1f6ec, 0x1f6f4, 0x1f6fc, 0x1f7e0, 0x1f7eb,
|
|
60
|
+
0x1f7f0, 0x1f7f0, 0x1f90c, 0x1f93a, 0x1f93c, 0x1f945, 0x1f947, 0x1f9ff, 0x1fa70, 0x1fa7c,
|
|
61
|
+
0x1fa80, 0x1fa89, 0x1fa8f, 0x1fac6, 0x1face, 0x1fadc, 0x1fadf, 0x1fae9, 0x1faf0, 0x1faf8,
|
|
62
|
+
0x20000, 0x2fffd, 0x30000, 0x3fffd,
|
|
63
|
+
];
|
|
64
|
+
/** A character that shows: anything but a control, a format character or a mark, and the soft hyphen. */
|
|
65
|
+
const SHOWN = /[^\p{Cc}\p{Cf}\p{Mn}\p{Me}]|\u00ad/u;
|
|
66
|
+
/**
|
|
67
|
+
* The start of an emoji sequence a terminal draws as one wide picture: an
|
|
68
|
+
* emoji and the presentation selector, a modifier base and its modifier, or
|
|
69
|
+
* two regional indicators, a flag.
|
|
70
|
+
*/
|
|
71
|
+
const EMOJI_SEQUENCE = /^(?:\p{Emoji}\ufe0f|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}|\p{Regional_Indicator}{2})/u;
|
|
72
|
+
// Made the first time a width is asked for: loading the segmentation rules
|
|
73
|
+
// costs milliseconds that a tool which never measures a string - every one
|
|
74
|
+
// that copies this module for its line tables - would pay on each start.
|
|
75
|
+
let graphemes;
|
|
76
|
+
/** The columns a text takes in a terminal. */
|
|
77
|
+
export function displayWidth(text) {
|
|
78
|
+
// A named locale, so the host's default is never read; clusters are the
|
|
79
|
+
// same in every locale, and they are what a segmenter gives unless told
|
|
80
|
+
// otherwise.
|
|
81
|
+
graphemes ??= new Intl.Segmenter('en');
|
|
82
|
+
let width = 0;
|
|
83
|
+
for (const { segment } of graphemes.segment(text))
|
|
84
|
+
width += clusterWidth(segment);
|
|
85
|
+
return width;
|
|
86
|
+
}
|
|
87
|
+
function clusterWidth(cluster) {
|
|
88
|
+
const at = cluster.search(SHOWN);
|
|
89
|
+
if (at < 0)
|
|
90
|
+
return 0;
|
|
91
|
+
const shown = cluster.slice(at);
|
|
92
|
+
return isWide(shown.codePointAt(0)) || EMOJI_SEQUENCE.test(shown) ? 2 : 1;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Whether a code point is in {@link WIDE}, by bisection over its runs. The
|
|
96
|
+
* search is half-open, as `inRanges`'s is: `high` is one past the last run
|
|
97
|
+
* still in question.
|
|
98
|
+
*/
|
|
99
|
+
function isWide(point) {
|
|
100
|
+
let low = 0;
|
|
101
|
+
let high = WIDE.length / 2;
|
|
102
|
+
while (low < high) {
|
|
103
|
+
const mid = (low + high) >> 1;
|
|
104
|
+
if (point < WIDE[2 * mid])
|
|
105
|
+
high = mid;
|
|
106
|
+
else if (point > WIDE[2 * mid + 1])
|
|
107
|
+
low = mid + 1;
|
|
108
|
+
else
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=width.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"width.js","sourceRoot":"","sources":["../../../../src/vendor/spec-core/text/width.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;;;;GASG;AACH,MAAM,IAAI,GAAsB;IAC9B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAC9F,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAC9F,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAC9F,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAC9F,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,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I,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * How many columns of a terminal a text takes, for a tool that lines up the\n * columns of a table it prints: `.padEnd` counts UTF-16 units, and `已接受`\n * is three of them and six columns.\n *\n * Counted per grapheme cluster, as a terminal draws one: a cluster takes the\n * width of the first character in it that shows, and what follows that\n * character - a combining mark, a variation selector, a joiner and what it\n * joins - adds nothing.\n *\n * - An East Asian Wide or Fullwidth character takes two: Han, kana and\n * hangul, full-width forms, and most emoji.\n * - So does an emoji sequence, whatever its first character's own width: an\n * emoji and the presentation selector U+FE0F (`❤` with it, and a keycap),\n * a modifier base and a skin tone (`☝` with one), and a flag, two\n * regional indicators.\n * - A cluster of nothing that shows takes none: combining marks, format\n * characters - the zero-width space and joiners, the byte-order mark, the\n * bidirectional controls - and control characters. A soft hyphen shows, as\n * terminals draw one.\n * - Everything else takes one, East Asian Ambiguous included, as a terminal\n * draws it outside a legacy East Asian mode.\n *\n * The widths are the table below, fixed. Grapheme clusters and general\n * categories are the runtime's, and a runtime knows the characters of its\n * own Unicode version: only a character assigned after the older of two\n * hosts' versions can be counted differently on them.\n */\n\n/**\n * The East Asian Wide and Fullwidth code points of Unicode 16.0.0\n * (EastAsianWidth-16.0.0.txt), the unassigned ones its `@missing` lines\n * make Wide included, as the first and last of each run, in order.\n *\n * 16.0 is the version both supported lines have: Node 22.16.0 reports\n * `process.versions.unicode` 16.0, and Node 24.18.1 17.0, which Node 22 does\n * not ship. A character is counted as the older line knows it; one 17.0\n * added counts one, as it does on a host that cannot name it.\n */\nconst WIDE: readonly number[] = [\n 0x1100, 0x115f, 0x231a, 0x231b, 0x2329, 0x232a, 0x23e9, 0x23ec, 0x23f0, 0x23f0, 0x23f3, 0x23f3,\n 0x25fd, 0x25fe, 0x2614, 0x2615, 0x2630, 0x2637, 0x2648, 0x2653, 0x267f, 0x267f, 0x268a, 0x268f,\n 0x2693, 0x2693, 0x26a1, 0x26a1, 0x26aa, 0x26ab, 0x26bd, 0x26be, 0x26c4, 0x26c5, 0x26ce, 0x26ce,\n 0x26d4, 0x26d4, 0x26ea, 0x26ea, 0x26f2, 0x26f3, 0x26f5, 0x26f5, 0x26fa, 0x26fa, 0x26fd, 0x26fd,\n 0x2705, 0x2705, 0x270a, 0x270b, 0x2728, 0x2728, 0x274c, 0x274c, 0x274e, 0x274e, 0x2753, 0x2755,\n 0x2757, 0x2757, 0x2795, 0x2797, 0x27b0, 0x27b0, 0x27bf, 0x27bf, 0x2b1b, 0x2b1c, 0x2b50, 0x2b50,\n 0x2b55, 0x2b55, 0x2e80, 0x2e99, 0x2e9b, 0x2ef3, 0x2f00, 0x2fd5, 0x2ff0, 0x303e, 0x3041, 0x3096,\n 0x3099, 0x30ff, 0x3105, 0x312f, 0x3131, 0x318e, 0x3190, 0x31e5, 0x31ef, 0x321e, 0x3220, 0x3247,\n 0x3250, 0xa48c, 0xa490, 0xa4c6, 0xa960, 0xa97c, 0xac00, 0xd7a3, 0xf900, 0xfaff, 0xfe10, 0xfe19,\n 0xfe30, 0xfe52, 0xfe54, 0xfe66, 0xfe68, 0xfe6b, 0xff01, 0xff60, 0xffe0, 0xffe6, 0x16fe0, 0x16fe4,\n 0x16ff0, 0x16ff1, 0x17000, 0x187f7, 0x18800, 0x18cd5, 0x18cff, 0x18d08, 0x1aff0, 0x1aff3,\n 0x1aff5, 0x1affb, 0x1affd, 0x1affe, 0x1b000, 0x1b122, 0x1b132, 0x1b132, 0x1b150, 0x1b152,\n 0x1b155, 0x1b155, 0x1b164, 0x1b167, 0x1b170, 0x1b2fb, 0x1d300, 0x1d356, 0x1d360, 0x1d376,\n 0x1f004, 0x1f004, 0x1f0cf, 0x1f0cf, 0x1f18e, 0x1f18e, 0x1f191, 0x1f19a, 0x1f200, 0x1f202,\n 0x1f210, 0x1f23b, 0x1f240, 0x1f248, 0x1f250, 0x1f251, 0x1f260, 0x1f265, 0x1f300, 0x1f320,\n 0x1f32d, 0x1f335, 0x1f337, 0x1f37c, 0x1f37e, 0x1f393, 0x1f3a0, 0x1f3ca, 0x1f3cf, 0x1f3d3,\n 0x1f3e0, 0x1f3f0, 0x1f3f4, 0x1f3f4, 0x1f3f8, 0x1f43e, 0x1f440, 0x1f440, 0x1f442, 0x1f4fc,\n 0x1f4ff, 0x1f53d, 0x1f54b, 0x1f54e, 0x1f550, 0x1f567, 0x1f57a, 0x1f57a, 0x1f595, 0x1f596,\n 0x1f5a4, 0x1f5a4, 0x1f5fb, 0x1f64f, 0x1f680, 0x1f6c5, 0x1f6cc, 0x1f6cc, 0x1f6d0, 0x1f6d2,\n 0x1f6d5, 0x1f6d7, 0x1f6dc, 0x1f6df, 0x1f6eb, 0x1f6ec, 0x1f6f4, 0x1f6fc, 0x1f7e0, 0x1f7eb,\n 0x1f7f0, 0x1f7f0, 0x1f90c, 0x1f93a, 0x1f93c, 0x1f945, 0x1f947, 0x1f9ff, 0x1fa70, 0x1fa7c,\n 0x1fa80, 0x1fa89, 0x1fa8f, 0x1fac6, 0x1face, 0x1fadc, 0x1fadf, 0x1fae9, 0x1faf0, 0x1faf8,\n 0x20000, 0x2fffd, 0x30000, 0x3fffd,\n];\n\n/** A character that shows: anything but a control, a format character or a mark, and the soft hyphen. */\nconst SHOWN = /[^\\p{Cc}\\p{Cf}\\p{Mn}\\p{Me}]|\\u00ad/u;\n\n/**\n * The start of an emoji sequence a terminal draws as one wide picture: an\n * emoji and the presentation selector, a modifier base and its modifier, or\n * two regional indicators, a flag.\n */\nconst EMOJI_SEQUENCE = /^(?:\\p{Emoji}\\ufe0f|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}|\\p{Regional_Indicator}{2})/u;\n\n// Made the first time a width is asked for: loading the segmentation rules\n// costs milliseconds that a tool which never measures a string - every one\n// that copies this module for its line tables - would pay on each start.\nlet graphemes: Intl.Segmenter | undefined;\n\n/** The columns a text takes in a terminal. */\nexport function displayWidth(text: string): number {\n // A named locale, so the host's default is never read; clusters are the\n // same in every locale, and they are what a segmenter gives unless told\n // otherwise.\n graphemes ??= new Intl.Segmenter('en');\n let width = 0;\n for (const { segment } of graphemes.segment(text)) width += clusterWidth(segment);\n return width;\n}\n\nfunction clusterWidth(cluster: string): number {\n const at = cluster.search(SHOWN);\n if (at < 0) return 0;\n const shown = cluster.slice(at);\n return isWide(shown.codePointAt(0) as number) || EMOJI_SEQUENCE.test(shown) ? 2 : 1;\n}\n\n/**\n * Whether a code point is in {@link WIDE}, by bisection over its runs. The\n * search is half-open, as `inRanges`'s is: `high` is one past the last run\n * still in question.\n */\nfunction isWide(point: number): boolean {\n let low = 0;\n let high = WIDE.length / 2;\n while (low < high) {\n const mid = (low + high) >> 1;\n if (point < (WIDE[2 * mid] as number)) high = mid;\n else if (point > (WIDE[2 * mid + 1] as number)) low = mid + 1;\n else return true;\n }\n return false;\n}\n"]}
|
package/package.json
CHANGED