@markii/ansi 0.15.0 → 0.17.0-next.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.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/dist/ansi.d.ts +26 -0
  3. package/dist/ansi.js +51 -0
  4. package/dist/components/badge.d.ts +1 -1
  5. package/dist/components/badge.js +5 -4
  6. package/dist/components/callout.d.ts +38 -13
  7. package/dist/components/callout.js +68 -31
  8. package/dist/components/card.d.ts +34 -2
  9. package/dist/components/card.js +55 -18
  10. package/dist/components/cell.d.ts +5 -11
  11. package/dist/components/cell.js +11 -15
  12. package/dist/components/chart.d.ts +4 -10
  13. package/dist/components/chart.js +16 -24
  14. package/dist/components/details-string.d.ts +26 -0
  15. package/dist/components/details-string.js +39 -0
  16. package/dist/components/details.d.ts +32 -10
  17. package/dist/components/details.js +28 -25
  18. package/dist/components/divider.js +12 -16
  19. package/dist/components/figure.d.ts +5 -16
  20. package/dist/components/figure.js +9 -19
  21. package/dist/components/index.d.ts +14 -10
  22. package/dist/components/index.js +19 -16
  23. package/dist/components/kbd.d.ts +1 -1
  24. package/dist/components/kbd.js +3 -2
  25. package/dist/components/layout-wrapper.d.ts +7 -22
  26. package/dist/components/layout-wrapper.js +9 -23
  27. package/dist/components/progress.d.ts +3 -11
  28. package/dist/components/progress.js +8 -17
  29. package/dist/components/rating.d.ts +1 -2
  30. package/dist/components/rating.js +3 -4
  31. package/dist/components/row.d.ts +35 -20
  32. package/dist/components/row.js +35 -51
  33. package/dist/components/stat.d.ts +3 -8
  34. package/dist/components/stat.js +5 -11
  35. package/dist/components/tab.d.ts +9 -8
  36. package/dist/components/tab.js +12 -10
  37. package/dist/components/table-grid.d.ts +2 -1
  38. package/dist/components/table-grid.js +14 -12
  39. package/dist/components/table.d.ts +5 -10
  40. package/dist/components/table.js +8 -13
  41. package/dist/components/tabs-string.d.ts +17 -0
  42. package/dist/components/tabs-string.js +30 -0
  43. package/dist/components/tabs.d.ts +31 -14
  44. package/dist/components/tabs.js +55 -30
  45. package/dist/failure-presentation.d.ts +15 -0
  46. package/dist/failure-presentation.js +22 -0
  47. package/dist/glyphs.d.ts +73 -0
  48. package/dist/glyphs.js +88 -0
  49. package/dist/index.d.ts +6 -4
  50. package/dist/index.js +10 -7
  51. package/dist/ink-string.d.ts +23 -0
  52. package/dist/ink-string.js +65 -0
  53. package/dist/interactive.d.ts +66 -0
  54. package/dist/interactive.js +207 -0
  55. package/dist/layout.js +1 -2
  56. package/dist/pack-loader.d.ts +64 -0
  57. package/dist/pack-loader.js +172 -0
  58. package/dist/pack-script.d.ts +44 -0
  59. package/dist/pack-script.js +135 -0
  60. package/dist/registry.d.ts +106 -100
  61. package/dist/registry.js +17 -9
  62. package/dist/render.d.ts +63 -25
  63. package/dist/render.js +1001 -380
  64. package/dist/text-grid.d.ts +90 -0
  65. package/dist/text-grid.js +300 -0
  66. package/package.json +9 -5
  67. package/dist/box.d.ts +0 -47
  68. package/dist/box.js +0 -209
  69. package/dist/measure.d.ts +0 -25
  70. package/dist/measure.js +0 -108
package/dist/measure.d.ts DELETED
@@ -1,25 +0,0 @@
1
- /**
2
- * Hand-written display-width measurement (no dependency is permitted here;
3
- * see AGENTS.md's Stack section and the batch brief). This is a DELIBERATE
4
- * APPROXIMATION of Unicode's East Asian Width property (UAX #11), not a
5
- * full Unicode width table: it covers the ranges most terminal content
6
- * actually uses (Latin text, CJK, common emoji, combining marks) and gets
7
- * one class of case knowingly wrong, documented below.
8
- *
9
- * KNOWN LIMITATION: a grapheme cluster joined by a zero-width joiner
10
- * (U+200D), such as a multi-person or multi-skin-tone emoji sequence,
11
- * measures as the sum of its parts rather than as the single glyph a
12
- * terminal actually draws. Getting this exactly right needs a real
13
- * grapheme-segmentation table, which this package deliberately does not
14
- * carry.
15
- */
16
- /** Removes every SGR and OSC 8 escape sequence this engine can itself produce, so `measure` counts only what a terminal actually draws. */
17
- export declare function stripAnsi(text: string): string;
18
- /**
19
- * The display width of `text`: ANSI escapes are stripped first, then every
20
- * remaining code point (iterated as a code point, not a UTF-16 code unit,
21
- * so a surrogate pair counts once) contributes its width per
22
- * `codePointWidth`'s rules. This is what every wrapping/padding/column
23
- * helper in `./box.ts` measures against.
24
- */
25
- export declare function measure(text: string): number;
package/dist/measure.js DELETED
@@ -1,108 +0,0 @@
1
- /**
2
- * Hand-written display-width measurement (no dependency is permitted here;
3
- * see AGENTS.md's Stack section and the batch brief). This is a DELIBERATE
4
- * APPROXIMATION of Unicode's East Asian Width property (UAX #11), not a
5
- * full Unicode width table: it covers the ranges most terminal content
6
- * actually uses (Latin text, CJK, common emoji, combining marks) and gets
7
- * one class of case knowingly wrong, documented below.
8
- *
9
- * KNOWN LIMITATION: a grapheme cluster joined by a zero-width joiner
10
- * (U+200D), such as a multi-person or multi-skin-tone emoji sequence,
11
- * measures as the sum of its parts rather than as the single glyph a
12
- * terminal actually draws. Getting this exactly right needs a real
13
- * grapheme-segmentation table, which this package deliberately does not
14
- * carry.
15
- */
16
- /** SGR: `ESC [ ... m`. */
17
- const SGR_PATTERN = /\x1b\[[0-9;]*m/g;
18
- /** OSC 8 hyperlink open/close: `ESC ] 8 ; ; ... BEL`. */
19
- const OSC8_PATTERN = /\x1b\]8;;[^\x07\x1b]*\x07/g;
20
- /** Removes every SGR and OSC 8 escape sequence this engine can itself produce, so `measure` counts only what a terminal actually draws. */
21
- export function stripAnsi(text) {
22
- return text.replace(OSC8_PATTERN, '').replace(SGR_PATTERN, '');
23
- }
24
- /** Combining marks: measure 0, since a terminal draws them layered onto the preceding column rather than advancing the cursor. */
25
- const COMBINING_RANGES = [
26
- [0x0300, 0x036f],
27
- [0x1ab0, 0x1aff],
28
- [0x1dc0, 0x1dff],
29
- [0x20d0, 0x20f0],
30
- [0xfe00, 0xfe0f],
31
- [0xfe20, 0xfe2f],
32
- ];
33
- /** Zero-width characters: measure 0 (zero-width space/joiner/non-joiner, word joiner, byte-order mark used as a zero-width no-break space). */
34
- const ZERO_WIDTH_RANGES = [
35
- [0x200b, 0x200d],
36
- [0x2060, 0x2060],
37
- [0xfeff, 0xfeff],
38
- ];
39
- /** East Asian Wide and Fullwidth: measure 2. */
40
- const WIDE_RANGES = [
41
- [0x1100, 0x115f],
42
- [0x2e80, 0x303e],
43
- [0x3041, 0x33ff],
44
- [0x3400, 0x4dbf],
45
- [0x4e00, 0x9fff],
46
- [0xa000, 0xa4cf],
47
- [0xac00, 0xd7a3],
48
- [0xf900, 0xfaff],
49
- [0xfe30, 0xfe6f],
50
- [0xff00, 0xff60],
51
- [0xffe0, 0xffe6],
52
- [0x20000, 0x2fffd],
53
- [0x30000, 0x3fffd],
54
- ];
55
- /** Common emoji ranges: measure 2. U+2600-U+27BF is included only when followed by the U+FE0F variation selector (see `measureText`). */
56
- const EMOJI_RANGES = [
57
- [0x1f300, 0x1f64f],
58
- [0x1f680, 0x1f6ff],
59
- [0x1f900, 0x1f9ff],
60
- [0x1fa70, 0x1faff],
61
- ];
62
- const EMOJI_PRESENTATION_LOW = 0x2600;
63
- const EMOJI_PRESENTATION_HIGH = 0x27bf;
64
- const VARIATION_SELECTOR_16 = 0xfe0f;
65
- function inRanges(code, ranges) {
66
- for (const [low, high] of ranges) {
67
- if (code >= low && code <= high)
68
- return true;
69
- }
70
- return false;
71
- }
72
- /**
73
- * The display width of one code point, given the NEXT code point in the
74
- * stream (needed only to check the emoji-variation-selector rule for the
75
- * dingbat range U+2600-U+27BF).
76
- */
77
- function codePointWidth(code, next) {
78
- if (inRanges(code, COMBINING_RANGES))
79
- return 0;
80
- if (inRanges(code, ZERO_WIDTH_RANGES))
81
- return 0;
82
- if (inRanges(code, WIDE_RANGES))
83
- return 2;
84
- if (inRanges(code, EMOJI_RANGES))
85
- return 2;
86
- if (code >= EMOJI_PRESENTATION_LOW &&
87
- code <= EMOJI_PRESENTATION_HIGH &&
88
- next === VARIATION_SELECTOR_16) {
89
- return 2;
90
- }
91
- return 1;
92
- }
93
- /**
94
- * The display width of `text`: ANSI escapes are stripped first, then every
95
- * remaining code point (iterated as a code point, not a UTF-16 code unit,
96
- * so a surrogate pair counts once) contributes its width per
97
- * `codePointWidth`'s rules. This is what every wrapping/padding/column
98
- * helper in `./box.ts` measures against.
99
- */
100
- export function measure(text) {
101
- const stripped = stripAnsi(text);
102
- const codePoints = Array.from(stripped, (char) => char.codePointAt(0) ?? 0);
103
- let width = 0;
104
- for (let index = 0; index < codePoints.length; index += 1) {
105
- width += codePointWidth(codePoints[index], codePoints[index + 1]);
106
- }
107
- return width;
108
- }