@promptctl/rich-js 0.26.0 → 0.28.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/README.md +1 -0
- package/THIRD-PARTY-NOTICES +42 -0
- package/dist/core/animation.d.ts +52 -15
- package/dist/core/animation.js +82 -37
- package/dist/core/ansi.d.ts +15 -8
- package/dist/core/ansi.js +106 -28
- package/dist/core/bidi-data.d.ts +14 -0
- package/dist/core/bidi-data.js +385 -0
- package/dist/core/bidi.d.ts +89 -0
- package/dist/core/bidi.js +615 -0
- package/dist/core/box.d.ts +9 -1
- package/dist/core/box.js +11 -0
- package/dist/core/cell-widths.d.ts +3 -2
- package/dist/core/cell-widths.js +93 -93
- package/dist/core/cells.d.ts +20 -0
- package/dist/core/cells.js +93 -5
- package/dist/core/color.d.ts +26 -18
- package/dist/core/color.js +37 -34
- package/dist/core/console.d.ts +26 -1
- package/dist/core/console.js +26 -6
- package/dist/core/control-codes.d.ts +61 -0
- package/dist/core/control-codes.js +157 -0
- package/dist/core/easing.js +6 -1
- package/dist/core/env.d.ts +6 -0
- package/dist/core/env.js +9 -1
- package/dist/core/export-html.js +4 -3
- package/dist/core/export-lines.d.ts +2 -0
- package/dist/core/export-lines.js +7 -3
- package/dist/core/export-svg.js +6 -5
- package/dist/core/json.js +9 -2
- package/dist/core/markup.js +4 -3
- package/dist/core/oklch.d.ts +2 -0
- package/dist/core/oklch.js +3 -3
- package/dist/core/orient.d.ts +68 -0
- package/dist/core/orient.js +224 -0
- package/dist/core/osc8.d.ts +12 -5
- package/dist/core/osc8.js +14 -7
- package/dist/core/pretty.js +22 -18
- package/dist/core/protocol.d.ts +53 -22
- package/dist/core/protocol.js +14 -6
- package/dist/core/render.d.ts +8 -3
- package/dist/core/render.js +19 -5
- package/dist/core/seal.d.ts +26 -0
- package/dist/core/seal.js +75 -0
- package/dist/core/segment.d.ts +9 -1
- package/dist/core/segment.js +11 -1
- package/dist/core/style.d.ts +29 -1
- package/dist/core/style.js +41 -5
- package/dist/core/text-order.d.ts +51 -0
- package/dist/core/text-order.js +50 -0
- package/dist/core/text.d.ts +10 -0
- package/dist/core/text.js +133 -87
- package/dist/core/timeline.js +6 -6
- package/dist/core/view.d.ts +23 -9
- package/dist/core/view.js +37 -12
- package/dist/core/wrap.d.ts +24 -6
- package/dist/core/wrap.js +82 -16
- package/dist/host/app.d.ts +48 -7
- package/dist/host/app.js +116 -11
- package/dist/host/index.d.ts +3 -2
- package/dist/host/index.js +1 -0
- package/dist/host/input.d.ts +35 -2
- package/dist/host/input.js +88 -4
- package/dist/host/terminal-colors.d.ts +18 -0
- package/dist/host/terminal-colors.js +46 -0
- package/dist/host/terminal-host.d.ts +2 -1
- package/dist/index.d.ts +10 -8
- package/dist/index.js +2 -2
- package/dist/renderables/change.d.ts +1 -3
- package/dist/renderables/change.js +4 -6
- package/dist/renderables/effect.d.ts +61 -60
- package/dist/renderables/effect.js +91 -81
- package/dist/renderables/effects.d.ts +37 -8
- package/dist/renderables/effects.js +193 -55
- package/dist/renderables/frames.d.ts +1 -10
- package/dist/renderables/frames.js +1 -16
- package/dist/renderables/glyph-effect.d.ts +12 -13
- package/dist/renderables/glyph-effect.js +34 -32
- package/dist/renderables/glyph-effects.d.ts +27 -8
- package/dist/renderables/glyph-effects.js +75 -7
- package/dist/renderables/lifecycle.d.ts +40 -32
- package/dist/renderables/lifecycle.js +87 -48
- package/dist/renderables/live.d.ts +3 -3
- package/dist/renderables/live.js +4 -4
- package/dist/renderables/markdown.js +4 -2
- package/dist/renderables/panel.js +6 -4
- package/dist/renderables/progress.d.ts +11 -4
- package/dist/renderables/progress.js +29 -17
- package/dist/renderables/progressBar.d.ts +3 -3
- package/dist/renderables/progressBar.js +16 -13
- package/dist/renderables/syntax.js +7 -2
- package/dist/renderables/table.js +2 -1
- package/dist/template-bindings/animation-funcs.d.ts +49 -18
- package/dist/template-bindings/animation-funcs.js +115 -32
- package/dist/template-bindings/index.d.ts +7 -5
- package/dist/template-bindings/index.js +8 -5
- package/dist/template-bindings/palette-funcs.d.ts +1 -1
- package/dist/template-bindings/palette-funcs.js +1 -1
- package/dist/themes/buildPalette.d.ts +15 -39
- package/dist/themes/buildPalette.js +196 -67
- package/dist/themes/colorMath.d.ts +10 -4
- package/dist/themes/colorMath.js +33 -1
- package/dist/themes/data/index.js +1 -4
- package/dist/themes/data/textual-ansi.js +0 -143
- package/dist/themes/data/types.d.ts +3 -1
- package/dist/themes/palette.d.ts +22 -6
- package/dist/themes/palette.js +13 -21
- package/dist/themes/ramp.d.ts +1 -1
- package/dist/themes/ramp.js +1 -1
- package/dist/themes/registry.d.ts +7 -10
- package/dist/themes/registry.js +9 -30
- package/dist/themes/terminalThemes.d.ts +4 -10
- package/dist/themes/terminalThemes.js +31 -46
- package/dist/themes/transpose.d.ts +5 -10
- package/dist/themes/transpose.js +13 -24
- package/dist/widgets/button.d.ts +1 -1
- package/dist/widgets/button.js +6 -6
- package/dist/widgets/checkbox.js +4 -4
- package/dist/widgets/dropdown.d.ts +1 -1
- package/dist/widgets/dropdown.js +7 -5
- package/dist/widgets/event-router.js +2 -2
- package/dist/widgets/ink.d.ts +5 -4
- package/dist/widgets/ink.js +6 -9
- package/dist/widgets/text-input.d.ts +1 -1
- package/dist/widgets/text-input.js +41 -32
- package/dist/widgets/themed-widget.js +3 -3
- package/dist/widgets/toggle.d.ts +1 -1
- package/dist/widgets/toggle.js +5 -5
- package/dist/widgets/types.d.ts +2 -2
- package/dist/widgets/widget-app.d.ts +3 -3
- package/dist/widgets/widget-app.js +5 -5
- package/package.json +5 -4
package/dist/core/cell-widths.js
CHANGED
|
@@ -1,100 +1,102 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The cells Rich's `cell_len` gives each code point, and the code points VS16
|
|
3
3
|
* widens. Generated by scripts/cell-widths.py from Rich 15.0.0's Unicode 17.0.0
|
|
4
|
-
* table, which Rich builds from wcwidth's data
|
|
4
|
+
* table, which Rich builds from wcwidth's data, and the clause for C0 and C1
|
|
5
|
+
* controls that Rich answers ahead of it; regenerate rather than edit.
|
|
5
6
|
*/
|
|
6
7
|
// Every range of code points that does not take one cell, as [first, last,
|
|
7
8
|
// cells]: ascending, disjoint, adjacent ranges of one width merged.
|
|
8
9
|
const RANGES = [
|
|
9
|
-
[0x0,
|
|
10
|
-
[0x5c4, 0x5c5, 0], [0x5c7, 0x5c7, 0], [0x610, 0x61a, 0], [0x61c, 0x61c, 0], [0x64b, 0x65f, 0],
|
|
11
|
-
[0x6d6, 0x6dc, 0], [0x6df, 0x6e4, 0], [0x6e7, 0x6e8, 0], [0x6ea, 0x6ed, 0], [0x711, 0x711, 0],
|
|
12
|
-
[0x7a6, 0x7b0, 0], [0x7eb, 0x7f3, 0], [0x7fd, 0x7fd, 0], [0x816, 0x819, 0], [0x81b, 0x823, 0],
|
|
13
|
-
[0x829, 0x82d, 0], [0x859, 0x85b, 0], [0x897, 0x89f, 0], [0x8ca, 0x8e1, 0], [0x8e3, 0x903, 0],
|
|
14
|
-
[0x93e, 0x94f, 0], [0x951, 0x957, 0], [0x962, 0x963, 0], [0x981, 0x983, 0], [0x9bc, 0x9bc, 0],
|
|
15
|
-
[0x9c7, 0x9c8, 0], [0x9cb, 0x9cd, 0], [0x9d7, 0x9d7, 0], [0x9e2, 0x9e3, 0], [0x9fe, 0x9fe, 0],
|
|
16
|
-
[0xa3c, 0xa3c, 0], [0xa3e, 0xa42, 0], [0xa47, 0xa48, 0], [0xa4b, 0xa4d, 0], [0xa51, 0xa51, 0],
|
|
17
|
-
[0xa75, 0xa75, 0], [0xa81, 0xa83, 0], [0xabc, 0xabc, 0], [0xabe, 0xac5, 0], [0xac7, 0xac9, 0],
|
|
18
|
-
[0xae2, 0xae3, 0], [0xafa, 0xaff, 0], [0xb01, 0xb03, 0], [0xb3c, 0xb3c, 0], [0xb3e, 0xb44, 0],
|
|
19
|
-
[0xb4b, 0xb4d, 0], [0xb55, 0xb57, 0], [0xb62, 0xb63, 0], [0xb82, 0xb82, 0], [0xbbe, 0xbc2, 0],
|
|
20
|
-
[0xbca, 0xbcd, 0], [0xbd7, 0xbd7, 0], [0xc00, 0xc04, 0], [0xc3c, 0xc3c, 0], [0xc3e, 0xc44, 0],
|
|
21
|
-
[0xc4a, 0xc4d, 0], [0xc55, 0xc56, 0], [0xc62, 0xc63, 0], [0xc81, 0xc83, 0], [0xcbc, 0xcbc, 0],
|
|
22
|
-
[0xcc6, 0xcc8, 0], [0xcca, 0xccd, 0], [0xcd5, 0xcd6, 0], [0xce2, 0xce3, 0], [0xcf3, 0xcf3, 0],
|
|
23
|
-
[0xd3b, 0xd3c, 0], [0xd3e, 0xd44, 0], [0xd46, 0xd48, 0], [0xd4a, 0xd4d, 0], [0xd57, 0xd57, 0],
|
|
24
|
-
[0xd81, 0xd83, 0], [0xdca, 0xdca, 0], [0xdcf, 0xdd4, 0], [0xdd6, 0xdd6, 0], [0xdd8, 0xddf, 0],
|
|
25
|
-
[0xe31, 0xe31, 0], [0xe34, 0xe3a, 0], [0xe47, 0xe4e, 0], [0xeb1, 0xeb1, 0], [0xeb4, 0xebc, 0],
|
|
26
|
-
[0xf18, 0xf19, 0], [0xf35, 0xf35, 0], [0xf37, 0xf37, 0], [0xf39, 0xf39, 0], [0xf3e, 0xf3f, 0],
|
|
27
|
-
[0xf86, 0xf87, 0], [0xf8d, 0xf97, 0], [0xf99, 0xfbc, 0], [0xfc6, 0xfc6, 0], [0x102b, 0x103e, 0],
|
|
28
|
-
[
|
|
29
|
-
[0x108f, 0x108f, 0], [0x109a, 0x109d, 0], [0x1100, 0x115f, 2], [0x1160, 0x11ff, 0],
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
[
|
|
36
|
-
[0x200b, 0x200f, 0], [0x2028, 0x202e, 0], [0x2060, 0x206f, 0], [0x20d0, 0x20f0, 0],
|
|
37
|
-
[
|
|
38
|
-
[
|
|
39
|
-
[
|
|
40
|
-
[
|
|
41
|
-
[
|
|
42
|
-
[
|
|
43
|
-
[
|
|
44
|
-
[0x2cef, 0x2cf1, 0], [0x2d7f, 0x2d7f, 0], [0x2de0, 0x2dff, 0], [0x2e80, 0x2e99, 2],
|
|
45
|
-
[0x2f00, 0x2fd5, 2], [0x2ff0, 0x3029, 2], [0x302a, 0x302f, 0], [0x3030, 0x303e, 2],
|
|
46
|
-
[0x3099, 0x309a, 0], [0x309b, 0x30ff, 2], [0x3105, 0x312f, 2], [0x3131, 0x3163, 2],
|
|
47
|
-
[0x3165, 0x318e, 2], [0x3190, 0x31e5, 2], [0x31ef, 0x321e, 2], [0x3220, 0x3247, 2],
|
|
48
|
-
[0xa490, 0xa4c6, 2], [0xa66f, 0xa672, 0], [0xa674, 0xa67d, 0], [0xa69e, 0xa69f, 0],
|
|
49
|
-
[
|
|
50
|
-
[
|
|
51
|
-
[0xa947, 0xa953, 0], [0xa960, 0xa97c, 2], [0xa980, 0xa983, 0], [0xa9b3, 0xa9c0, 0],
|
|
52
|
-
[
|
|
53
|
-
[
|
|
54
|
-
[0xaaf5, 0xaaf6, 0], [0xabe3, 0xabea, 0], [0xabec, 0xabed, 0], [0xac00, 0xd7a3, 2],
|
|
55
|
-
[0xf900, 0xfaff, 2], [0xfb1e, 0xfb1e, 0], [0xfe00, 0xfe0f, 0], [0xfe10, 0xfe19, 2],
|
|
56
|
-
[0xfe30, 0xfe52, 2], [0xfe54, 0xfe66, 2], [0xfe68, 0xfe6b, 2], [0xfeff, 0xfeff, 0],
|
|
57
|
-
[0xffa0, 0xffa0, 0], [0xffe0, 0xffe6, 2], [0xfff0, 0xfffb, 0], [0x101fd, 0x101fd, 0],
|
|
58
|
-
[
|
|
59
|
-
[
|
|
60
|
-
[
|
|
61
|
-
[
|
|
62
|
-
[
|
|
63
|
-
[
|
|
64
|
-
[
|
|
65
|
-
[
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
[
|
|
69
|
-
[
|
|
70
|
-
[
|
|
71
|
-
[
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
75
|
-
[
|
|
76
|
-
[
|
|
77
|
-
[0x16b30, 0x16b36, 0], [0x16f4f, 0x16f4f, 0], [0x16f51, 0x16f87, 0], [0x16f8f, 0x16f92, 0],
|
|
78
|
-
[0x16fe4, 0x16fe4, 0], [0x16ff0, 0x16ff1, 0], [0x16ff2, 0x16ff6, 2], [0x17000, 0x18cd5, 2],
|
|
79
|
-
[
|
|
80
|
-
[
|
|
81
|
-
[0x1bc9d, 0x1bc9e, 0], [0x1bca0, 0x1bca3, 0], [0x1cf00, 0x1cf2d, 0], [0x1cf30, 0x1cf46, 0],
|
|
82
|
-
[0x1d16d, 0x1d182, 0], [0x1d185, 0x1d18b, 0], [0x1d1aa, 0x1d1ad, 0], [0x1d242, 0x1d244, 0],
|
|
83
|
-
[0x1d360, 0x1d376, 2], [0x1da00, 0x1da36, 0], [0x1da3b, 0x1da6c, 0], [0x1da75, 0x1da75, 0],
|
|
84
|
-
[
|
|
85
|
-
[
|
|
86
|
-
[
|
|
87
|
-
[0x1e6ee, 0x1e6ef, 0], [0x1e6f5, 0x1e6f5, 0], [0x1e8d0, 0x1e8d6, 0], [0x1e944, 0x1e94a, 0],
|
|
88
|
-
[
|
|
89
|
-
[
|
|
90
|
-
[
|
|
91
|
-
[0x1f3f4, 0x1f3f4, 2], [0x1f3f8, 0x1f3fa, 2], [0x1f3fb, 0x1f3ff, 0], [0x1f400, 0x1f43e, 2],
|
|
92
|
-
[
|
|
93
|
-
[
|
|
94
|
-
[
|
|
95
|
-
[
|
|
96
|
-
[
|
|
97
|
-
[0x1fadf, 0x1faea, 2], [0x1faef, 0x1faf8, 2], [0x20000, 0x2fffd, 2], [0x30000, 0x3fffd, 2],
|
|
10
|
+
[0x0, 0x1f, 0], [0x7f, 0x9f, 0], [0x300, 0x36f, 0], [0x483, 0x489, 0], [0x591, 0x5bd, 0], [0x5bf, 0x5bf, 0],
|
|
11
|
+
[0x5c1, 0x5c2, 0], [0x5c4, 0x5c5, 0], [0x5c7, 0x5c7, 0], [0x610, 0x61a, 0], [0x61c, 0x61c, 0], [0x64b, 0x65f, 0],
|
|
12
|
+
[0x670, 0x670, 0], [0x6d6, 0x6dc, 0], [0x6df, 0x6e4, 0], [0x6e7, 0x6e8, 0], [0x6ea, 0x6ed, 0], [0x711, 0x711, 0],
|
|
13
|
+
[0x730, 0x74a, 0], [0x7a6, 0x7b0, 0], [0x7eb, 0x7f3, 0], [0x7fd, 0x7fd, 0], [0x816, 0x819, 0], [0x81b, 0x823, 0],
|
|
14
|
+
[0x825, 0x827, 0], [0x829, 0x82d, 0], [0x859, 0x85b, 0], [0x897, 0x89f, 0], [0x8ca, 0x8e1, 0], [0x8e3, 0x903, 0],
|
|
15
|
+
[0x93a, 0x93c, 0], [0x93e, 0x94f, 0], [0x951, 0x957, 0], [0x962, 0x963, 0], [0x981, 0x983, 0], [0x9bc, 0x9bc, 0],
|
|
16
|
+
[0x9be, 0x9c4, 0], [0x9c7, 0x9c8, 0], [0x9cb, 0x9cd, 0], [0x9d7, 0x9d7, 0], [0x9e2, 0x9e3, 0], [0x9fe, 0x9fe, 0],
|
|
17
|
+
[0xa01, 0xa03, 0], [0xa3c, 0xa3c, 0], [0xa3e, 0xa42, 0], [0xa47, 0xa48, 0], [0xa4b, 0xa4d, 0], [0xa51, 0xa51, 0],
|
|
18
|
+
[0xa70, 0xa71, 0], [0xa75, 0xa75, 0], [0xa81, 0xa83, 0], [0xabc, 0xabc, 0], [0xabe, 0xac5, 0], [0xac7, 0xac9, 0],
|
|
19
|
+
[0xacb, 0xacd, 0], [0xae2, 0xae3, 0], [0xafa, 0xaff, 0], [0xb01, 0xb03, 0], [0xb3c, 0xb3c, 0], [0xb3e, 0xb44, 0],
|
|
20
|
+
[0xb47, 0xb48, 0], [0xb4b, 0xb4d, 0], [0xb55, 0xb57, 0], [0xb62, 0xb63, 0], [0xb82, 0xb82, 0], [0xbbe, 0xbc2, 0],
|
|
21
|
+
[0xbc6, 0xbc8, 0], [0xbca, 0xbcd, 0], [0xbd7, 0xbd7, 0], [0xc00, 0xc04, 0], [0xc3c, 0xc3c, 0], [0xc3e, 0xc44, 0],
|
|
22
|
+
[0xc46, 0xc48, 0], [0xc4a, 0xc4d, 0], [0xc55, 0xc56, 0], [0xc62, 0xc63, 0], [0xc81, 0xc83, 0], [0xcbc, 0xcbc, 0],
|
|
23
|
+
[0xcbe, 0xcc4, 0], [0xcc6, 0xcc8, 0], [0xcca, 0xccd, 0], [0xcd5, 0xcd6, 0], [0xce2, 0xce3, 0], [0xcf3, 0xcf3, 0],
|
|
24
|
+
[0xd00, 0xd03, 0], [0xd3b, 0xd3c, 0], [0xd3e, 0xd44, 0], [0xd46, 0xd48, 0], [0xd4a, 0xd4d, 0], [0xd57, 0xd57, 0],
|
|
25
|
+
[0xd62, 0xd63, 0], [0xd81, 0xd83, 0], [0xdca, 0xdca, 0], [0xdcf, 0xdd4, 0], [0xdd6, 0xdd6, 0], [0xdd8, 0xddf, 0],
|
|
26
|
+
[0xdf2, 0xdf3, 0], [0xe31, 0xe31, 0], [0xe34, 0xe3a, 0], [0xe47, 0xe4e, 0], [0xeb1, 0xeb1, 0], [0xeb4, 0xebc, 0],
|
|
27
|
+
[0xec8, 0xece, 0], [0xf18, 0xf19, 0], [0xf35, 0xf35, 0], [0xf37, 0xf37, 0], [0xf39, 0xf39, 0], [0xf3e, 0xf3f, 0],
|
|
28
|
+
[0xf71, 0xf84, 0], [0xf86, 0xf87, 0], [0xf8d, 0xf97, 0], [0xf99, 0xfbc, 0], [0xfc6, 0xfc6, 0], [0x102b, 0x103e, 0],
|
|
29
|
+
[0x1056, 0x1059, 0], [0x105e, 0x1060, 0], [0x1062, 0x1064, 0], [0x1067, 0x106d, 0], [0x1071, 0x1074, 0],
|
|
30
|
+
[0x1082, 0x108d, 0], [0x108f, 0x108f, 0], [0x109a, 0x109d, 0], [0x1100, 0x115f, 2], [0x1160, 0x11ff, 0],
|
|
31
|
+
[0x135d, 0x135f, 0], [0x1712, 0x1715, 0], [0x1732, 0x1734, 0], [0x1752, 0x1753, 0], [0x1772, 0x1773, 0],
|
|
32
|
+
[0x17b4, 0x17d3, 0], [0x17dd, 0x17dd, 0], [0x180b, 0x180f, 0], [0x1885, 0x1886, 0], [0x18a9, 0x18a9, 0],
|
|
33
|
+
[0x1920, 0x192b, 0], [0x1930, 0x193b, 0], [0x1a17, 0x1a1b, 0], [0x1a55, 0x1a5e, 0], [0x1a60, 0x1a7c, 0],
|
|
34
|
+
[0x1a7f, 0x1a7f, 0], [0x1ab0, 0x1add, 0], [0x1ae0, 0x1aeb, 0], [0x1b00, 0x1b04, 0], [0x1b34, 0x1b44, 0],
|
|
35
|
+
[0x1b6b, 0x1b73, 0], [0x1b80, 0x1b82, 0], [0x1ba1, 0x1bad, 0], [0x1be6, 0x1bf3, 0], [0x1c24, 0x1c37, 0],
|
|
36
|
+
[0x1cd0, 0x1cd2, 0], [0x1cd4, 0x1ce8, 0], [0x1ced, 0x1ced, 0], [0x1cf4, 0x1cf4, 0], [0x1cf7, 0x1cf9, 0],
|
|
37
|
+
[0x1dc0, 0x1dff, 0], [0x200b, 0x200f, 0], [0x2028, 0x202e, 0], [0x2060, 0x206f, 0], [0x20d0, 0x20f0, 0],
|
|
38
|
+
[0x231a, 0x231b, 2], [0x2329, 0x232a, 2], [0x23e9, 0x23ec, 2], [0x23f0, 0x23f0, 2], [0x23f3, 0x23f3, 2],
|
|
39
|
+
[0x25fd, 0x25fe, 2], [0x2614, 0x2615, 2], [0x2630, 0x2637, 2], [0x2648, 0x2653, 2], [0x267f, 0x267f, 2],
|
|
40
|
+
[0x268a, 0x268f, 2], [0x2693, 0x2693, 2], [0x26a1, 0x26a1, 2], [0x26aa, 0x26ab, 2], [0x26bd, 0x26be, 2],
|
|
41
|
+
[0x26c4, 0x26c5, 2], [0x26ce, 0x26ce, 2], [0x26d4, 0x26d4, 2], [0x26ea, 0x26ea, 2], [0x26f2, 0x26f3, 2],
|
|
42
|
+
[0x26f5, 0x26f5, 2], [0x26fa, 0x26fa, 2], [0x26fd, 0x26fd, 2], [0x2705, 0x2705, 2], [0x270a, 0x270b, 2],
|
|
43
|
+
[0x2728, 0x2728, 2], [0x274c, 0x274c, 2], [0x274e, 0x274e, 2], [0x2753, 0x2755, 2], [0x2757, 0x2757, 2],
|
|
44
|
+
[0x2795, 0x2797, 2], [0x27b0, 0x27b0, 2], [0x27bf, 0x27bf, 2], [0x2b1b, 0x2b1c, 2], [0x2b50, 0x2b50, 2],
|
|
45
|
+
[0x2b55, 0x2b55, 2], [0x2cef, 0x2cf1, 0], [0x2d7f, 0x2d7f, 0], [0x2de0, 0x2dff, 0], [0x2e80, 0x2e99, 2],
|
|
46
|
+
[0x2e9b, 0x2ef3, 2], [0x2f00, 0x2fd5, 2], [0x2ff0, 0x3029, 2], [0x302a, 0x302f, 0], [0x3030, 0x303e, 2],
|
|
47
|
+
[0x3041, 0x3096, 2], [0x3099, 0x309a, 0], [0x309b, 0x30ff, 2], [0x3105, 0x312f, 2], [0x3131, 0x3163, 2],
|
|
48
|
+
[0x3164, 0x3164, 0], [0x3165, 0x318e, 2], [0x3190, 0x31e5, 2], [0x31ef, 0x321e, 2], [0x3220, 0x3247, 2],
|
|
49
|
+
[0x3250, 0xa48c, 2], [0xa490, 0xa4c6, 2], [0xa66f, 0xa672, 0], [0xa674, 0xa67d, 0], [0xa69e, 0xa69f, 0],
|
|
50
|
+
[0xa6f0, 0xa6f1, 0], [0xa802, 0xa802, 0], [0xa806, 0xa806, 0], [0xa80b, 0xa80b, 0], [0xa823, 0xa827, 0],
|
|
51
|
+
[0xa82c, 0xa82c, 0], [0xa880, 0xa881, 0], [0xa8b4, 0xa8c5, 0], [0xa8e0, 0xa8f1, 0], [0xa8ff, 0xa8ff, 0],
|
|
52
|
+
[0xa926, 0xa92d, 0], [0xa947, 0xa953, 0], [0xa960, 0xa97c, 2], [0xa980, 0xa983, 0], [0xa9b3, 0xa9c0, 0],
|
|
53
|
+
[0xa9e5, 0xa9e5, 0], [0xaa29, 0xaa36, 0], [0xaa43, 0xaa43, 0], [0xaa4c, 0xaa4d, 0], [0xaa7b, 0xaa7d, 0],
|
|
54
|
+
[0xaab0, 0xaab0, 0], [0xaab2, 0xaab4, 0], [0xaab7, 0xaab8, 0], [0xaabe, 0xaabf, 0], [0xaac1, 0xaac1, 0],
|
|
55
|
+
[0xaaeb, 0xaaef, 0], [0xaaf5, 0xaaf6, 0], [0xabe3, 0xabea, 0], [0xabec, 0xabed, 0], [0xac00, 0xd7a3, 2],
|
|
56
|
+
[0xd7b0, 0xd7ff, 0], [0xf900, 0xfaff, 2], [0xfb1e, 0xfb1e, 0], [0xfe00, 0xfe0f, 0], [0xfe10, 0xfe19, 2],
|
|
57
|
+
[0xfe20, 0xfe2f, 0], [0xfe30, 0xfe52, 2], [0xfe54, 0xfe66, 2], [0xfe68, 0xfe6b, 2], [0xfeff, 0xfeff, 0],
|
|
58
|
+
[0xff01, 0xff60, 2], [0xffa0, 0xffa0, 0], [0xffe0, 0xffe6, 2], [0xfff0, 0xfffb, 0], [0x101fd, 0x101fd, 0],
|
|
59
|
+
[0x102e0, 0x102e0, 0], [0x10376, 0x1037a, 0], [0x10a01, 0x10a03, 0], [0x10a05, 0x10a06, 0], [0x10a0c, 0x10a0f, 0],
|
|
60
|
+
[0x10a38, 0x10a3a, 0], [0x10a3f, 0x10a3f, 0], [0x10ae5, 0x10ae6, 0], [0x10d24, 0x10d27, 0], [0x10d69, 0x10d6d, 0],
|
|
61
|
+
[0x10eab, 0x10eac, 0], [0x10efa, 0x10eff, 0], [0x10f46, 0x10f50, 0], [0x10f82, 0x10f85, 0], [0x11000, 0x11002, 0],
|
|
62
|
+
[0x11038, 0x11046, 0], [0x11070, 0x11070, 0], [0x11073, 0x11074, 0], [0x1107f, 0x11082, 0], [0x110b0, 0x110ba, 0],
|
|
63
|
+
[0x110c2, 0x110c2, 0], [0x11100, 0x11102, 0], [0x11127, 0x11134, 0], [0x11145, 0x11146, 0], [0x11173, 0x11173, 0],
|
|
64
|
+
[0x11180, 0x11182, 0], [0x111b3, 0x111c0, 0], [0x111c9, 0x111cc, 0], [0x111ce, 0x111cf, 0], [0x1122c, 0x11237, 0],
|
|
65
|
+
[0x1123e, 0x1123e, 0], [0x11241, 0x11241, 0], [0x112df, 0x112ea, 0], [0x11300, 0x11303, 0], [0x1133b, 0x1133c, 0],
|
|
66
|
+
[0x1133e, 0x11344, 0], [0x11347, 0x11348, 0], [0x1134b, 0x1134d, 0], [0x11357, 0x11357, 0], [0x11362, 0x11363, 0],
|
|
67
|
+
[0x11366, 0x1136c, 0], [0x11370, 0x11374, 0], [0x113b8, 0x113c0, 0], [0x113c2, 0x113c2, 0], [0x113c5, 0x113c5, 0],
|
|
68
|
+
[0x113c7, 0x113ca, 0], [0x113cc, 0x113d0, 0], [0x113d2, 0x113d2, 0], [0x113e1, 0x113e2, 0], [0x11435, 0x11446, 0],
|
|
69
|
+
[0x1145e, 0x1145e, 0], [0x114b0, 0x114c3, 0], [0x115af, 0x115b5, 0], [0x115b8, 0x115c0, 0], [0x115dc, 0x115dd, 0],
|
|
70
|
+
[0x11630, 0x11640, 0], [0x116ab, 0x116b7, 0], [0x1171d, 0x1172b, 0], [0x1182c, 0x1183a, 0], [0x11930, 0x11935, 0],
|
|
71
|
+
[0x11937, 0x11938, 0], [0x1193b, 0x1193e, 0], [0x11940, 0x11940, 0], [0x11942, 0x11943, 0], [0x119d1, 0x119d7, 0],
|
|
72
|
+
[0x119da, 0x119e0, 0], [0x119e4, 0x119e4, 0], [0x11a01, 0x11a0a, 0], [0x11a33, 0x11a39, 0], [0x11a3b, 0x11a3e, 0],
|
|
73
|
+
[0x11a47, 0x11a47, 0], [0x11a51, 0x11a5b, 0], [0x11a8a, 0x11a99, 0], [0x11b60, 0x11b67, 0], [0x11c2f, 0x11c36, 0],
|
|
74
|
+
[0x11c38, 0x11c3f, 0], [0x11c92, 0x11ca7, 0], [0x11ca9, 0x11cb6, 0], [0x11d31, 0x11d36, 0], [0x11d3a, 0x11d3a, 0],
|
|
75
|
+
[0x11d3c, 0x11d3d, 0], [0x11d3f, 0x11d45, 0], [0x11d47, 0x11d47, 0], [0x11d8a, 0x11d8e, 0], [0x11d90, 0x11d91, 0],
|
|
76
|
+
[0x11d93, 0x11d97, 0], [0x11ef3, 0x11ef6, 0], [0x11f00, 0x11f01, 0], [0x11f03, 0x11f03, 0], [0x11f34, 0x11f3a, 0],
|
|
77
|
+
[0x11f3e, 0x11f42, 0], [0x11f5a, 0x11f5a, 0], [0x13430, 0x13440, 0], [0x13447, 0x13455, 0], [0x1611e, 0x1612f, 0],
|
|
78
|
+
[0x16af0, 0x16af4, 0], [0x16b30, 0x16b36, 0], [0x16f4f, 0x16f4f, 0], [0x16f51, 0x16f87, 0], [0x16f8f, 0x16f92, 0],
|
|
79
|
+
[0x16fe0, 0x16fe3, 2], [0x16fe4, 0x16fe4, 0], [0x16ff0, 0x16ff1, 0], [0x16ff2, 0x16ff6, 2], [0x17000, 0x18cd5, 2],
|
|
80
|
+
[0x18cff, 0x18d1e, 2], [0x18d80, 0x18df2, 2], [0x1aff0, 0x1aff3, 2], [0x1aff5, 0x1affb, 2], [0x1affd, 0x1affe, 2],
|
|
81
|
+
[0x1b000, 0x1b122, 2], [0x1b132, 0x1b132, 2], [0x1b150, 0x1b152, 2], [0x1b155, 0x1b155, 2], [0x1b164, 0x1b167, 2],
|
|
82
|
+
[0x1b170, 0x1b2fb, 2], [0x1bc9d, 0x1bc9e, 0], [0x1bca0, 0x1bca3, 0], [0x1cf00, 0x1cf2d, 0], [0x1cf30, 0x1cf46, 0],
|
|
83
|
+
[0x1d165, 0x1d169, 0], [0x1d16d, 0x1d182, 0], [0x1d185, 0x1d18b, 0], [0x1d1aa, 0x1d1ad, 0], [0x1d242, 0x1d244, 0],
|
|
84
|
+
[0x1d300, 0x1d356, 2], [0x1d360, 0x1d376, 2], [0x1da00, 0x1da36, 0], [0x1da3b, 0x1da6c, 0], [0x1da75, 0x1da75, 0],
|
|
85
|
+
[0x1da84, 0x1da84, 0], [0x1da9b, 0x1da9f, 0], [0x1daa1, 0x1daaf, 0], [0x1e000, 0x1e006, 0], [0x1e008, 0x1e018, 0],
|
|
86
|
+
[0x1e01b, 0x1e021, 0], [0x1e023, 0x1e024, 0], [0x1e026, 0x1e02a, 0], [0x1e08f, 0x1e08f, 0], [0x1e130, 0x1e136, 0],
|
|
87
|
+
[0x1e2ae, 0x1e2ae, 0], [0x1e2ec, 0x1e2ef, 0], [0x1e4ec, 0x1e4ef, 0], [0x1e5ee, 0x1e5ef, 0], [0x1e6e3, 0x1e6e3, 0],
|
|
88
|
+
[0x1e6e6, 0x1e6e6, 0], [0x1e6ee, 0x1e6ef, 0], [0x1e6f5, 0x1e6f5, 0], [0x1e8d0, 0x1e8d6, 0], [0x1e944, 0x1e94a, 0],
|
|
89
|
+
[0x1f004, 0x1f004, 2], [0x1f0cf, 0x1f0cf, 2], [0x1f18e, 0x1f18e, 2], [0x1f191, 0x1f19a, 2], [0x1f200, 0x1f202, 2],
|
|
90
|
+
[0x1f210, 0x1f23b, 2], [0x1f240, 0x1f248, 2], [0x1f250, 0x1f251, 2], [0x1f260, 0x1f265, 2], [0x1f300, 0x1f320, 2],
|
|
91
|
+
[0x1f32d, 0x1f335, 2], [0x1f337, 0x1f37c, 2], [0x1f37e, 0x1f393, 2], [0x1f3a0, 0x1f3ca, 2], [0x1f3cf, 0x1f3d3, 2],
|
|
92
|
+
[0x1f3e0, 0x1f3f0, 2], [0x1f3f4, 0x1f3f4, 2], [0x1f3f8, 0x1f3fa, 2], [0x1f3fb, 0x1f3ff, 0], [0x1f400, 0x1f43e, 2],
|
|
93
|
+
[0x1f440, 0x1f440, 2], [0x1f442, 0x1f4fc, 2], [0x1f4ff, 0x1f53d, 2], [0x1f54b, 0x1f54e, 2], [0x1f550, 0x1f567, 2],
|
|
94
|
+
[0x1f57a, 0x1f57a, 2], [0x1f595, 0x1f596, 2], [0x1f5a4, 0x1f5a4, 2], [0x1f5fb, 0x1f64f, 2], [0x1f680, 0x1f6c5, 2],
|
|
95
|
+
[0x1f6cc, 0x1f6cc, 2], [0x1f6d0, 0x1f6d2, 2], [0x1f6d5, 0x1f6d8, 2], [0x1f6dc, 0x1f6df, 2], [0x1f6eb, 0x1f6ec, 2],
|
|
96
|
+
[0x1f6f4, 0x1f6fc, 2], [0x1f7e0, 0x1f7eb, 2], [0x1f7f0, 0x1f7f0, 2], [0x1f90c, 0x1f93a, 2], [0x1f93c, 0x1f945, 2],
|
|
97
|
+
[0x1f947, 0x1f9ff, 2], [0x1fa70, 0x1fa7c, 2], [0x1fa80, 0x1fa8a, 2], [0x1fa8e, 0x1fac6, 2], [0x1fac8, 0x1fac8, 2],
|
|
98
|
+
[0x1facd, 0x1fadc, 2], [0x1fadf, 0x1faea, 2], [0x1faef, 0x1faf8, 2], [0x20000, 0x2fffd, 2], [0x30000, 0x3fffd, 2],
|
|
99
|
+
[0xe0000, 0xe0fff, 0],
|
|
98
100
|
];
|
|
99
101
|
// The code points one cell wide on their own and two when VARIATION SELECTOR-16
|
|
100
102
|
// asks for emoji presentation.
|
|
@@ -116,10 +118,8 @@ const NARROW_TO_WIDE = new Set([
|
|
|
116
118
|
0x1f5e1, 0x1f5e3, 0x1f5e8, 0x1f5ef, 0x1f5f3, 0x1f5fa, 0x1f6cb, 0x1f6cd, 0x1f6ce, 0x1f6cf, 0x1f6e0, 0x1f6e1, 0x1f6e2,
|
|
117
119
|
0x1f6e3, 0x1f6e4, 0x1f6e5, 0x1f6e9, 0x1f6f0, 0x1f6f3,
|
|
118
120
|
]);
|
|
119
|
-
/** The cells Rich gives `codePoint` on its own
|
|
121
|
+
/** The cells Rich gives `codePoint` on its own. */
|
|
120
122
|
export function codePointWidth(codePoint) {
|
|
121
|
-
if (codePoint < 0x20 || (codePoint >= 0x7f && codePoint < 0xa0))
|
|
122
|
-
return 0;
|
|
123
123
|
let low = 0;
|
|
124
124
|
let high = RANGES.length - 1;
|
|
125
125
|
while (low <= high) {
|
package/dist/core/cells.d.ts
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Terminal cell width calculation: Rich's `cell_len`, ported.
|
|
3
3
|
*/
|
|
4
|
+
/**
|
|
5
|
+
* `text` with each code point the wire may not hold given by `replacement`, one
|
|
6
|
+
* at a time. A control, a line separator and a soft hyphen never are;
|
|
7
|
+
* a tag only in a subdivision flag, since elsewhere it is text no reader sees; a
|
|
8
|
+
* variation selector only directly on a glyph, so what can hide behind one glyph
|
|
9
|
+
* is one selector, and what can hide in a text is one per glyph. That last is not
|
|
10
|
+
* containable here: a real sequence and a planted one differ only by data this
|
|
11
|
+
* library does not carry.
|
|
12
|
+
*
|
|
13
|
+
* [LAW:one-source-of-truth] `measure` reads this, so `cellLen` is the width of what
|
|
14
|
+
* is written. A deletion keeps every cluster boundary the text had: it takes the
|
|
15
|
+
* run of ZWJs before it and the last run past any Extend after it, what a join
|
|
16
|
+
* across it would need (UAX #29 GB11). So the width of a string stays the sum over
|
|
17
|
+
* the clusters of the text as it was given, and every cut stays exact.
|
|
18
|
+
*/
|
|
19
|
+
export declare function replaceWithheld(text: string, replacement: (character: string) => string): string;
|
|
20
|
+
/** `character` as a Unicode escape a reader can see, for data on show. */
|
|
21
|
+
export declare function unicodeEscape(character: string): string;
|
|
22
|
+
/** `text` as the wire may hold it. */
|
|
23
|
+
export declare function wireText(text: string): string;
|
|
4
24
|
/**
|
|
5
25
|
* Returns the terminal cell width of a string.
|
|
6
26
|
*/
|
package/dist/core/cells.js
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
* Terminal cell width calculation: Rich's `cell_len`, ported.
|
|
3
3
|
*/
|
|
4
4
|
import { codePointWidth, widensToEmoji } from "./cell-widths.js";
|
|
5
|
+
import { controlClass, dispositionOf, SUBDIVISION_FLAG } from "./control-codes.js";
|
|
5
6
|
import { Memo } from "./memo.js";
|
|
6
7
|
import { pattern } from "./pattern.js";
|
|
7
8
|
const cellLenMemo = new Memo();
|
|
8
9
|
const ZWJ = 0x200d;
|
|
10
|
+
const ZWJ_CHARACTER = String.fromCodePoint(ZWJ);
|
|
9
11
|
const VS16 = 0xfe0f;
|
|
10
12
|
const JOINERS = pattern(/[\u200d\ufe0f]/);
|
|
11
13
|
const PRINTABLE_ASCII = pattern(/^[ -~]*$/);
|
|
@@ -13,6 +15,90 @@ const PRINTABLE_ASCII = pattern(/^[ -~]*$/);
|
|
|
13
15
|
// even in 10k code units, and a cache of segmentations would hold native
|
|
14
16
|
// memory for every string it kept.
|
|
15
17
|
const SEGMENTER = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
18
|
+
// The cells `codePoint` takes as what the census says is done with it. Exhaustive,
|
|
19
|
+
// so a new `Disposition` does not compile until it says what it measures.
|
|
20
|
+
function dispositionCells(codePoint) {
|
|
21
|
+
const disposition = dispositionOf(codePoint);
|
|
22
|
+
switch (disposition) {
|
|
23
|
+
case "strip": return 0;
|
|
24
|
+
case "keep": return codePointWidth(codePoint);
|
|
25
|
+
case "line-break": return 0;
|
|
26
|
+
case "pictured": return 0;
|
|
27
|
+
case "withheld": return 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const WITHHELD = pattern(new RegExp(controlClass((disposition) => disposition !== "keep"), "u"));
|
|
31
|
+
const SELECTOR = pattern(/\p{Variation_Selector}/u);
|
|
32
|
+
/**
|
|
33
|
+
* Whether the selector at `index` follows a code point that draws. Asked of the
|
|
34
|
+
* census and the vendored table, so an ideograph newer than the engine keeps its
|
|
35
|
+
* selector; the first code point of a string has nothing before it to judge.
|
|
36
|
+
*/
|
|
37
|
+
function selectsAGlyph(text, index) {
|
|
38
|
+
const previous = Array.from(text.slice(Math.max(0, index - 2), index)).at(-1);
|
|
39
|
+
return previous === undefined || dispositionCells(previous.codePointAt(0)) > 0;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* `text` with each code point the wire may not hold given by `replacement`, one
|
|
43
|
+
* at a time. A control, a line separator and a soft hyphen never are;
|
|
44
|
+
* a tag only in a subdivision flag, since elsewhere it is text no reader sees; a
|
|
45
|
+
* variation selector only directly on a glyph, so what can hide behind one glyph
|
|
46
|
+
* is one selector, and what can hide in a text is one per glyph. That last is not
|
|
47
|
+
* containable here: a real sequence and a planted one differ only by data this
|
|
48
|
+
* library does not carry.
|
|
49
|
+
*
|
|
50
|
+
* [LAW:one-source-of-truth] `measure` reads this, so `cellLen` is the width of what
|
|
51
|
+
* is written. A deletion keeps every cluster boundary the text had: it takes the
|
|
52
|
+
* run of ZWJs before it and the last run past any Extend after it, what a join
|
|
53
|
+
* across it would need (UAX #29 GB11). So the width of a string stays the sum over
|
|
54
|
+
* the clusters of the text as it was given, and every cut stays exact.
|
|
55
|
+
*/
|
|
56
|
+
export function replaceWithheld(text, replacement) {
|
|
57
|
+
if (text.match(WITHHELD) === null)
|
|
58
|
+
return text;
|
|
59
|
+
const gone = new Set();
|
|
60
|
+
const extended = new RegExp(`[\\p{Grapheme_Extend}\\p{Emoji_Modifier}${ZWJ_CHARACTER}]*`, "uy");
|
|
61
|
+
// A run is scanned once, so a text that is one long run stays linear.
|
|
62
|
+
let scanned = 0;
|
|
63
|
+
const takeJoiners = (last) => {
|
|
64
|
+
for (let at = last; text[at] === ZWJ_CHARACTER; at -= 1)
|
|
65
|
+
gone.add(at);
|
|
66
|
+
};
|
|
67
|
+
for (const match of text.matchAll(new RegExp(`(${SUBDIVISION_FLAG})|${WITHHELD.source}`, "gu"))) {
|
|
68
|
+
const [found, flag] = match;
|
|
69
|
+
if (flag !== undefined || (SELECTOR.test(found) && selectsAGlyph(text, match.index)))
|
|
70
|
+
continue;
|
|
71
|
+
gone.add(match.index);
|
|
72
|
+
takeJoiners(match.index - 1);
|
|
73
|
+
const end = match.index + found.length;
|
|
74
|
+
if (end < scanned)
|
|
75
|
+
continue;
|
|
76
|
+
extended.lastIndex = end;
|
|
77
|
+
extended.test(text);
|
|
78
|
+
scanned = extended.lastIndex;
|
|
79
|
+
const joiner = text.slice(end, scanned).lastIndexOf(ZWJ_CHARACTER);
|
|
80
|
+
if (joiner >= 0)
|
|
81
|
+
takeJoiners(end + joiner);
|
|
82
|
+
}
|
|
83
|
+
if (gone.size === 0)
|
|
84
|
+
return text;
|
|
85
|
+
let kept = "";
|
|
86
|
+
let at = 0;
|
|
87
|
+
for (const character of text) {
|
|
88
|
+
kept += gone.has(at) ? replacement(character) : character;
|
|
89
|
+
at += character.length;
|
|
90
|
+
}
|
|
91
|
+
return kept;
|
|
92
|
+
}
|
|
93
|
+
/** `character` as a Unicode escape a reader can see, for data on show. */
|
|
94
|
+
export function unicodeEscape(character) {
|
|
95
|
+
const hex = character.codePointAt(0).toString(16).padStart(4, "0");
|
|
96
|
+
return hex.length > 4 ? `\\u{${hex}}` : `\\u${hex}`;
|
|
97
|
+
}
|
|
98
|
+
/** `text` as the wire may hold it. */
|
|
99
|
+
export function wireText(text) {
|
|
100
|
+
return replaceWithheld(text, () => "");
|
|
101
|
+
}
|
|
16
102
|
// Rich's `cell_len` over a run of text: each code point the cells Rich's table
|
|
17
103
|
// gives it, but that a ZWJ takes the code point after it into the glyph before
|
|
18
104
|
// so neither adds a cell, and VS16 widens the last code point measured to two
|
|
@@ -34,7 +120,7 @@ function richCells(text) {
|
|
|
34
120
|
widenable = false;
|
|
35
121
|
}
|
|
36
122
|
else {
|
|
37
|
-
const width =
|
|
123
|
+
const width = dispositionCells(codePoint);
|
|
38
124
|
cells += width;
|
|
39
125
|
widenable = width > 0 ? widensToEmoji(codePoint) : widenable;
|
|
40
126
|
}
|
|
@@ -42,7 +128,8 @@ function richCells(text) {
|
|
|
42
128
|
return cells;
|
|
43
129
|
}
|
|
44
130
|
// [LAW:one-source-of-truth] the single authority for cell width. A string is
|
|
45
|
-
// the sum of
|
|
131
|
+
// what `wireText` leaves of it, the sum of those grapheme clusters, each measured
|
|
132
|
+
// as Rich measures it, so a cut
|
|
46
133
|
// between clusters splits the width exactly; the two part only where a ZWJ or
|
|
47
134
|
// VS16 reaches across a cluster boundary, as in `a` ZWJ `b`, which Rich counts
|
|
48
135
|
// as one cell and two clusters count as two. Without either, every code point
|
|
@@ -50,10 +137,11 @@ function richCells(text) {
|
|
|
50
137
|
function measure(text) {
|
|
51
138
|
if (PRINTABLE_ASCII.test(text))
|
|
52
139
|
return text.length;
|
|
53
|
-
|
|
54
|
-
|
|
140
|
+
const drawn = wireText(text);
|
|
141
|
+
if (!JOINERS.test(drawn))
|
|
142
|
+
return richCells(drawn);
|
|
55
143
|
let cells = 0;
|
|
56
|
-
for (const { segment } of SEGMENTER.segment(
|
|
144
|
+
for (const { segment } of SEGMENTER.segment(drawn))
|
|
57
145
|
cells += richCells(segment);
|
|
58
146
|
return cells;
|
|
59
147
|
}
|
package/dist/core/color.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Terminal color representation, parsing, downgrading, and ANSI code generation.
|
|
3
3
|
*/
|
|
4
|
-
import type
|
|
4
|
+
import { type Env } from "./env.js";
|
|
5
|
+
import { type TextOrder } from "./text-order.js";
|
|
6
|
+
import type { Palette } from "../themes/palette.js";
|
|
5
7
|
/**
|
|
6
8
|
* Immutable RGBA color value. Alpha defaults to 1 (fully opaque).
|
|
7
9
|
*
|
|
@@ -141,12 +143,6 @@ export type ColorSystemName = "auto" | keyof typeof COLOR_SYSTEM_DEPTHS;
|
|
|
141
143
|
* in the env values, not in which checks execute.
|
|
142
144
|
*/
|
|
143
145
|
export declare function detectColorSystem(options?: DetectColorOptions): ColorDepth | null;
|
|
144
|
-
/**
|
|
145
|
-
* A terminal that says it cannot be drawn on: `TERM` is `dumb` or `unknown`,
|
|
146
|
-
* as Emacs' shell mode sets it. It takes no colour and nothing that moves the
|
|
147
|
-
* cursor.
|
|
148
|
-
*/
|
|
149
|
-
export declare function isDumbTerminal(env: Env): boolean;
|
|
150
146
|
/**
|
|
151
147
|
* Where segments are written, as everything the serializer (`segmentsToString`)
|
|
152
148
|
* needs to know about it: the colour depth SGR is drawn at, whether OSC 8
|
|
@@ -165,6 +161,8 @@ export interface Destination {
|
|
|
165
161
|
* drawn and how it is encoded take one preference.
|
|
166
162
|
*/
|
|
167
163
|
readonly reducedMotion: boolean;
|
|
164
|
+
/** What the destination does with direction; `./text-order.ts` owns the three. */
|
|
165
|
+
readonly textOrder: TextOrder;
|
|
168
166
|
}
|
|
169
167
|
/**
|
|
170
168
|
* What `resolveDestination` is told about where it writes beyond the colour
|
|
@@ -174,6 +172,8 @@ export interface Destination {
|
|
|
174
172
|
*/
|
|
175
173
|
export interface DestinationOptions extends DetectColorOptions {
|
|
176
174
|
reducedMotion?: boolean;
|
|
175
|
+
/** The order the program knows its destination takes. Absent, `detectTextOrder` decides. */
|
|
176
|
+
textOrder?: TextOrder;
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
179
179
|
* Resolve a colour spec into a `Destination`.
|
|
@@ -244,7 +244,7 @@ export declare class ColorSpec {
|
|
|
244
244
|
/**
|
|
245
245
|
* Resolves to an actual RGB(A) value for any color type.
|
|
246
246
|
*/
|
|
247
|
-
getTruecolor(theme?:
|
|
247
|
+
getTruecolor(theme?: TerminalColors, foreground?: boolean): ColorRgba;
|
|
248
248
|
static default(): ColorSpec;
|
|
249
249
|
static fromAnsi(n: number): ColorSpec;
|
|
250
250
|
static fromRgba(value: ColorRgba): ColorSpec;
|
|
@@ -275,7 +275,7 @@ export declare class ColorSpec {
|
|
|
275
275
|
* `value` is opaque: a translucent colour has no one look until it is laid
|
|
276
276
|
* on a ground (`flattenAlpha`).
|
|
277
277
|
*/
|
|
278
|
-
static matchOn(value: ColorRgba, depth: ColorDepth, theme:
|
|
278
|
+
static matchOn(value: ColorRgba, depth: ColorDepth, theme: TerminalColors, foreground: boolean): ColorSpec;
|
|
279
279
|
/**
|
|
280
280
|
* Every colour `depth` writes by index, each with the colour a terminal
|
|
281
281
|
* known to show `theme` draws it in, lowest index first: the theme's
|
|
@@ -285,7 +285,7 @@ export declare class ColorSpec {
|
|
|
285
285
|
* depth only the default, so neither writes any by index. The colours
|
|
286
286
|
* `matchOn` rounds to, but for the default, read off the same two tables.
|
|
287
287
|
*/
|
|
288
|
-
static indexed(depth: ColorDepth, theme:
|
|
288
|
+
static indexed(depth: ColorDepth, theme: TerminalColors): readonly (readonly [ColorSpec, ColorRgba])[];
|
|
289
289
|
/**
|
|
290
290
|
* The spec a slot is written in once its colour moves from `was`, what its
|
|
291
291
|
* written spec draws on `theme`, to the opaque `now`: `matchOn`'s — or
|
|
@@ -294,7 +294,7 @@ export declare class ColorSpec {
|
|
|
294
294
|
* off any colour the depth can write — a theme slot, the default colour,
|
|
295
295
|
* the cube — keeps the spec it was written in.
|
|
296
296
|
*/
|
|
297
|
-
static matchMove(was: ColorRgba, now: ColorRgba, depth: ColorDepth, theme:
|
|
297
|
+
static matchMove(was: ColorRgba, now: ColorRgba, depth: ColorDepth, theme: TerminalColors, foreground: boolean): ColorSpec | undefined;
|
|
298
298
|
/**
|
|
299
299
|
* Parse a color string. Memoized (`Memo`): a string parsed again while
|
|
300
300
|
* remembered returns the same instance.
|
|
@@ -312,6 +312,17 @@ export declare function parseRgbaHex(hex: string): ColorRgba;
|
|
|
312
312
|
*/
|
|
313
313
|
export declare function parseHexColor(literal: string): ColorRgba;
|
|
314
314
|
export declare function blendRgb(color1: ColorRgba, color2: ColorRgba, crossFade?: number): ColorRgba;
|
|
315
|
+
/**
|
|
316
|
+
* What a terminal draws with: the part of a `TerminalTheme` a colour resolves
|
|
317
|
+
* against.
|
|
318
|
+
*/
|
|
319
|
+
export declare class TerminalColors {
|
|
320
|
+
readonly backgroundColor: ColorRgba;
|
|
321
|
+
readonly foregroundColor: ColorRgba;
|
|
322
|
+
readonly ansiColors: ColorTable;
|
|
323
|
+
private readonly checked;
|
|
324
|
+
constructor(backgroundColor: ColorRgba, foregroundColor: ColorRgba, ansiColors: ColorTable);
|
|
325
|
+
}
|
|
315
326
|
/**
|
|
316
327
|
* A terminal theme — surface/foreground baseline, the sixteen ANSI colours,
|
|
317
328
|
* and a semantic palette.
|
|
@@ -321,12 +332,9 @@ export declare function blendRgb(color1: ColorRgba, color2: ColorRgba, crossFade
|
|
|
321
332
|
* is ANSI colour 1 under every theme; which red that is, is the theme's to say,
|
|
322
333
|
* as it is in Rich, where each `TerminalTheme` carries its own table.
|
|
323
334
|
*/
|
|
324
|
-
export declare class TerminalTheme {
|
|
325
|
-
readonly
|
|
326
|
-
|
|
327
|
-
readonly ansiColors: ColorTable;
|
|
328
|
-
readonly palette: import("../themes/palette.js").Palette;
|
|
329
|
-
constructor(backgroundColor: ColorRgba, foregroundColor: ColorRgba, ansiColors: ColorTable, palette: import("../themes/palette.js").Palette);
|
|
335
|
+
export declare class TerminalTheme extends TerminalColors {
|
|
336
|
+
readonly palette: Palette;
|
|
337
|
+
constructor(backgroundColor: ColorRgba, foregroundColor: ColorRgba, ansiColors: ColorTable, palette: Palette);
|
|
330
338
|
}
|
|
331
339
|
export declare const STANDARD_TABLE: ColorTable;
|
|
332
340
|
export declare const EIGHT_BIT_TABLE: ColorTable;
|
|
@@ -345,7 +353,7 @@ export declare const WINDOWS_TABLE: ColorTable;
|
|
|
345
353
|
* that reads it. (Widgets fall back to `DEFAULT_TERMINAL_THEME`, which carries a
|
|
346
354
|
* palette this does not.)
|
|
347
355
|
*/
|
|
348
|
-
export declare function resolveTerminal(theme:
|
|
356
|
+
export declare function resolveTerminal(theme: TerminalColors | undefined, depth: ColorDepth): TerminalColors;
|
|
349
357
|
/**
|
|
350
358
|
* The table a downgrade to `depth` rounds a fixed colour against.
|
|
351
359
|
* [LAW:one-source-of-truth] `ColorSpec.downgrade` picks the index a colour is
|