@promptctl/rich-js 0.27.0 → 0.29.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 +7 -6
- package/THIRD-PARTY-NOTICES +42 -0
- package/dist/core/animation.d.ts +65 -46
- package/dist/core/animation.js +91 -67
- package/dist/core/ansi.d.ts +19 -12
- package/dist/core/ansi.js +114 -36
- 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 +94 -6
- package/dist/core/clock.d.ts +1 -1
- package/dist/core/color.d.ts +56 -57
- package/dist/core/color.js +79 -81
- package/dist/core/console.d.ts +24 -7
- package/dist/core/console.js +27 -8
- package/dist/core/control-codes.d.ts +61 -0
- package/dist/core/control-codes.js +157 -0
- package/dist/core/easing.d.ts +40 -40
- package/dist/core/easing.js +40 -40
- package/dist/core/env.d.ts +6 -0
- package/dist/core/env.js +9 -1
- package/dist/core/export-html.js +5 -4
- package/dist/core/export-lines.d.ts +13 -11
- package/dist/core/export-lines.js +19 -15
- package/dist/core/export-svg.d.ts +3 -3
- package/dist/core/export-svg.js +10 -9
- package/dist/core/json.js +9 -2
- package/dist/core/markup.js +5 -4
- package/dist/core/memo.d.ts +1 -1
- package/dist/core/memo.js +1 -1
- package/dist/core/oklch.d.ts +14 -14
- package/dist/core/oklch.js +10 -10
- 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/paint.d.ts +9 -9
- package/dist/core/paint.js +3 -3
- package/dist/core/pretty.d.ts +1 -1
- package/dist/core/pretty.js +23 -19
- package/dist/core/protocol.d.ts +47 -26
- package/dist/core/protocol.js +31 -23
- package/dist/core/render.d.ts +19 -14
- package/dist/core/render.js +30 -17
- package/dist/core/seal.d.ts +26 -0
- package/dist/core/seal.js +75 -0
- package/dist/core/segment.d.ts +12 -4
- package/dist/core/segment.js +16 -6
- package/dist/core/strip.d.ts +83 -83
- package/dist/core/strip.js +70 -70
- package/dist/core/style.d.ts +46 -18
- package/dist/core/style.js +92 -56
- package/dist/core/text-order.d.ts +51 -0
- package/dist/core/text-order.js +50 -0
- package/dist/core/text.d.ts +12 -2
- package/dist/core/text.js +136 -90
- package/dist/core/timeline.d.ts +5 -5
- package/dist/core/timeline.js +11 -11
- package/dist/core/tween.d.ts +6 -6
- package/dist/core/tween.js +10 -10
- package/dist/core/view.d.ts +5 -5
- package/dist/core/view.js +15 -14
- package/dist/core/wrap.d.ts +24 -6
- package/dist/core/wrap.js +82 -16
- package/dist/host/app.d.ts +50 -9
- package/dist/host/app.js +120 -15
- package/dist/host/host-environment.d.ts +2 -2
- package/dist/host/host-environment.js +2 -2
- package/dist/host/index.d.ts +3 -2
- package/dist/host/index.js +1 -0
- package/dist/host/input.d.ts +42 -9
- package/dist/host/input.js +91 -7
- package/dist/host/terminal-colors.d.ts +18 -0
- package/dist/host/terminal-colors.js +46 -0
- package/dist/host/terminal-host.d.ts +4 -3
- package/dist/host/terminal-host.js +1 -1
- package/dist/index.d.ts +17 -16
- package/dist/index.js +11 -11
- package/dist/node/prompt.d.ts +1 -1
- package/dist/node/prompt.js +1 -1
- package/dist/node/terminal-host.d.ts +1 -1
- package/dist/node/traceback.js +2 -2
- package/dist/renderables/change.d.ts +1 -3
- package/dist/renderables/change.js +6 -8
- package/dist/renderables/effect.d.ts +88 -87
- package/dist/renderables/effect.js +124 -114
- package/dist/renderables/effects.d.ts +105 -76
- package/dist/renderables/effects.js +309 -176
- package/dist/renderables/embed.d.ts +1 -1
- package/dist/renderables/embed.js +2 -2
- package/dist/renderables/flexStrip.d.ts +7 -7
- package/dist/renderables/flexStrip.js +15 -15
- package/dist/renderables/frames.d.ts +7 -16
- package/dist/renderables/frames.js +12 -27
- package/dist/renderables/glyph-effect.d.ts +22 -23
- package/dist/renderables/glyph-effect.js +43 -41
- package/dist/renderables/glyph-effects.d.ts +33 -14
- package/dist/renderables/glyph-effects.js +90 -22
- package/dist/renderables/html-entities.d.ts +1 -1
- package/dist/renderables/html-entities.js +1 -1
- package/dist/renderables/lifecycle.d.ts +8 -10
- package/dist/renderables/lifecycle.js +17 -18
- package/dist/renderables/live.d.ts +2 -2
- package/dist/renderables/live.js +7 -7
- package/dist/renderables/markdown-parse.js +3 -3
- package/dist/renderables/markdown.js +4 -2
- package/dist/renderables/panel.js +7 -5
- package/dist/renderables/progress.d.ts +1 -1
- package/dist/renderables/progress.js +1 -1
- package/dist/renderables/progressBar.d.ts +3 -3
- package/dist/renderables/progressBar.js +21 -18
- package/dist/renderables/prompt.d.ts +1 -1
- package/dist/renderables/scroll.d.ts +1 -1
- package/dist/renderables/scroll.js +3 -3
- package/dist/renderables/spinner.d.ts +4 -4
- package/dist/renderables/spinner.js +10 -10
- package/dist/renderables/syntax.d.ts +2 -2
- package/dist/renderables/syntax.js +9 -4
- package/dist/renderables/table.js +5 -4
- package/dist/renderables/traceback.d.ts +1 -1
- package/dist/renderables/traceback.js +1 -1
- package/dist/renderables/tree.js +3 -3
- package/dist/template-bindings/animation-funcs.d.ts +60 -29
- package/dist/template-bindings/animation-funcs.js +126 -43
- package/dist/template-bindings/color-funcs.d.ts +14 -14
- package/dist/template-bindings/color-funcs.js +25 -25
- package/dist/template-bindings/index.d.ts +16 -14
- package/dist/template-bindings/index.js +17 -14
- package/dist/template-bindings/palette-funcs.d.ts +2 -2
- package/dist/template-bindings/palette-funcs.js +4 -4
- package/dist/template-bindings/style-funcs.d.ts +5 -5
- package/dist/template-bindings/style-funcs.js +16 -16
- package/dist/themes/{transpose.d.ts → adjust.d.ts} +23 -23
- package/dist/themes/{transpose.js → adjust.js} +28 -28
- package/dist/themes/buildPalette.d.ts +6 -5
- package/dist/themes/buildPalette.js +22 -22
- package/dist/themes/colorMath.d.ts +16 -16
- package/dist/themes/colorMath.js +32 -32
- package/dist/themes/data/ansi-tables.d.ts +2 -2
- package/dist/themes/data/ansi-tables.js +2 -2
- package/dist/themes/data/index.js +1 -4
- package/dist/themes/data/textual-ansi.js +0 -143
- package/dist/themes/data/types.d.ts +4 -4
- package/dist/themes/data/types.js +2 -2
- package/dist/themes/palette.d.ts +12 -12
- package/dist/themes/palette.js +16 -16
- package/dist/themes/ramp.d.ts +17 -17
- package/dist/themes/ramp.js +12 -12
- package/dist/themes/registry.d.ts +6 -8
- package/dist/themes/registry.js +6 -8
- package/dist/themes/terminalThemes.d.ts +4 -11
- package/dist/themes/terminalThemes.js +31 -47
- package/dist/widgets/button.d.ts +3 -3
- package/dist/widgets/button.js +8 -8
- package/dist/widgets/checkbox.d.ts +2 -2
- package/dist/widgets/checkbox.js +4 -4
- package/dist/widgets/dropdown.d.ts +3 -3
- package/dist/widgets/dropdown.js +7 -5
- package/dist/widgets/event-router.d.ts +6 -6
- package/dist/widgets/event-router.js +2 -2
- package/dist/widgets/focus-manager.d.ts +3 -3
- package/dist/widgets/focus-manager.js +3 -3
- package/dist/widgets/index.d.ts +2 -2
- package/dist/widgets/index.js +1 -1
- package/dist/widgets/ink.d.ts +3 -3
- package/dist/widgets/ink.js +4 -4
- package/dist/widgets/slider.d.ts +2 -2
- package/dist/widgets/static-item.d.ts +2 -2
- package/dist/widgets/text-input.d.ts +2 -2
- package/dist/widgets/text-input.js +5 -5
- package/dist/widgets/themed-widget.js +4 -4
- package/dist/widgets/toggle.d.ts +4 -4
- package/dist/widgets/toggle.js +6 -6
- package/dist/widgets/types.d.ts +6 -6
- package/dist/widgets/types.js +2 -2
- package/dist/widgets/widget-app.d.ts +10 -10
- package/dist/widgets/widget-app.js +8 -8
- package/dist/widgets/widget-base.d.ts +2 -2
- 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 replaceZeroWidth(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,17 +2,103 @@
|
|
|
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
|
-
const
|
|
12
|
+
const SEPARATOR_STYLES = pattern(/[\u200d\ufe0f]/);
|
|
11
13
|
const PRINTABLE_ASCII = pattern(/^[ -~]*$/);
|
|
12
14
|
// Segmented afresh on every call: a cursor's step costs a few microseconds
|
|
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 "zeroWidth": 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 replaceZeroWidth(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 replaceZeroWidth(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 (!SEPARATOR_STYLES.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/clock.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export interface Clock {
|
|
|
45
45
|
/**
|
|
46
46
|
* Call `tick` once, when this clock reads `time` — as soon as it can for a
|
|
47
47
|
* time already past — unless the returned function is called first. What
|
|
48
|
-
* a host that knows when its frame next changes (`Segment.
|
|
48
|
+
* a host that knows when its frame next changes (`Segment.validUntil`)
|
|
49
49
|
* waits on. A `time` that is not a finite number of seconds throws; one
|
|
50
50
|
* further off than a platform timer can wait is waited for in turns.
|
|
51
51
|
*/
|