@promptctl/rich-js 0.17.0 → 0.18.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 (206) hide show
  1. package/README.md +13 -26
  2. package/package.json +7 -3
  3. package/dist/core/box.d.ts +0 -144
  4. package/dist/core/box.js +0 -391
  5. package/dist/core/cells.d.ts +0 -148
  6. package/dist/core/cells.js +0 -266
  7. package/dist/core/color.d.ts +0 -250
  8. package/dist/core/color.js +0 -1029
  9. package/dist/core/console.d.ts +0 -156
  10. package/dist/core/console.js +0 -472
  11. package/dist/core/emoji.d.ts +0 -24
  12. package/dist/core/emoji.js +0 -391
  13. package/dist/core/export-html.d.ts +0 -24
  14. package/dist/core/export-html.js +0 -106
  15. package/dist/core/export-lines.d.ts +0 -121
  16. package/dist/core/export-lines.js +0 -141
  17. package/dist/core/highlighter.d.ts +0 -33
  18. package/dist/core/highlighter.js +0 -124
  19. package/dist/core/json.d.ts +0 -27
  20. package/dist/core/json.js +0 -53
  21. package/dist/core/markup.d.ts +0 -97
  22. package/dist/core/markup.js +0 -619
  23. package/dist/core/measure.d.ts +0 -27
  24. package/dist/core/measure.js +0 -61
  25. package/dist/core/oklch.d.ts +0 -161
  26. package/dist/core/oklch.js +0 -312
  27. package/dist/core/osc8.d.ts +0 -68
  28. package/dist/core/osc8.js +0 -90
  29. package/dist/core/pretty.d.ts +0 -141
  30. package/dist/core/pretty.js +0 -472
  31. package/dist/core/protocol.d.ts +0 -137
  32. package/dist/core/protocol.js +0 -101
  33. package/dist/core/render.d.ts +0 -84
  34. package/dist/core/render.js +0 -145
  35. package/dist/core/segment.d.ts +0 -142
  36. package/dist/core/segment.js +0 -433
  37. package/dist/core/spinnerData.d.ts +0 -10
  38. package/dist/core/spinnerData.js +0 -115
  39. package/dist/core/strip.d.ts +0 -145
  40. package/dist/core/strip.js +0 -308
  41. package/dist/core/style.d.ts +0 -144
  42. package/dist/core/style.js +0 -723
  43. package/dist/core/subscription.d.ts +0 -12
  44. package/dist/core/subscription.js +0 -12
  45. package/dist/core/text.d.ts +0 -255
  46. package/dist/core/text.js +0 -990
  47. package/dist/core/wrap.d.ts +0 -41
  48. package/dist/core/wrap.js +0 -127
  49. package/dist/host/host-stream.d.ts +0 -30
  50. package/dist/host/host-stream.js +0 -35
  51. package/dist/host/index.d.ts +0 -3
  52. package/dist/host/index.js +0 -2
  53. package/dist/host/terminal-host.d.ts +0 -143
  54. package/dist/host/terminal-host.js +0 -132
  55. package/dist/index.d.ts +0 -87
  56. package/dist/index.js +0 -104
  57. package/dist/node/prompt.d.ts +0 -21
  58. package/dist/node/prompt.js +0 -30
  59. package/dist/node/save.d.ts +0 -17
  60. package/dist/node/save.js +0 -21
  61. package/dist/node/terminal-host.d.ts +0 -84
  62. package/dist/node/terminal-host.js +0 -160
  63. package/dist/node/traceback.d.ts +0 -27
  64. package/dist/node/traceback.js +0 -112
  65. package/dist/renderables/align.d.ts +0 -16
  66. package/dist/renderables/align.js +0 -46
  67. package/dist/renderables/columns.d.ts +0 -61
  68. package/dist/renderables/columns.js +0 -168
  69. package/dist/renderables/constrain.d.ts +0 -15
  70. package/dist/renderables/constrain.js +0 -37
  71. package/dist/renderables/flexStrip.d.ts +0 -41
  72. package/dist/renderables/flexStrip.js +0 -200
  73. package/dist/renderables/group.d.ts +0 -11
  74. package/dist/renderables/group.js +0 -15
  75. package/dist/renderables/layout.d.ts +0 -92
  76. package/dist/renderables/layout.js +0 -315
  77. package/dist/renderables/live.d.ts +0 -47
  78. package/dist/renderables/live.js +0 -131
  79. package/dist/renderables/markdown.d.ts +0 -24
  80. package/dist/renderables/markdown.js +0 -182
  81. package/dist/renderables/padding.d.ts +0 -38
  82. package/dist/renderables/padding.js +0 -140
  83. package/dist/renderables/panel.d.ts +0 -116
  84. package/dist/renderables/panel.js +0 -322
  85. package/dist/renderables/progress.d.ts +0 -90
  86. package/dist/renderables/progress.js +0 -241
  87. package/dist/renderables/progressBar.d.ts +0 -31
  88. package/dist/renderables/progressBar.js +0 -52
  89. package/dist/renderables/prompt.d.ts +0 -49
  90. package/dist/renderables/prompt.js +0 -125
  91. package/dist/renderables/rule.d.ts +0 -24
  92. package/dist/renderables/rule.js +0 -90
  93. package/dist/renderables/spinner.d.ts +0 -29
  94. package/dist/renderables/spinner.js +0 -64
  95. package/dist/renderables/status.d.ts +0 -23
  96. package/dist/renderables/status.js +0 -60
  97. package/dist/renderables/syntax.d.ts +0 -35
  98. package/dist/renderables/syntax.js +0 -114
  99. package/dist/renderables/table.d.ts +0 -182
  100. package/dist/renderables/table.js +0 -697
  101. package/dist/renderables/traceback.d.ts +0 -31
  102. package/dist/renderables/traceback.js +0 -109
  103. package/dist/renderables/tree.d.ts +0 -54
  104. package/dist/renderables/tree.js +0 -159
  105. package/dist/template-bindings/color-funcs.d.ts +0 -87
  106. package/dist/template-bindings/color-funcs.js +0 -219
  107. package/dist/template-bindings/helpers.d.ts +0 -24
  108. package/dist/template-bindings/helpers.js +0 -48
  109. package/dist/template-bindings/index.d.ts +0 -107
  110. package/dist/template-bindings/index.js +0 -144
  111. package/dist/template-bindings/palette-funcs.d.ts +0 -94
  112. package/dist/template-bindings/palette-funcs.js +0 -151
  113. package/dist/template-bindings/style-funcs.d.ts +0 -28
  114. package/dist/template-bindings/style-funcs.js +0 -151
  115. package/dist/themes/buildPalette.d.ts +0 -36
  116. package/dist/themes/buildPalette.js +0 -56
  117. package/dist/themes/colorMath.d.ts +0 -82
  118. package/dist/themes/colorMath.js +0 -254
  119. package/dist/themes/colorRef.d.ts +0 -51
  120. package/dist/themes/colorRef.js +0 -96
  121. package/dist/themes/data/atom-one-dark.d.ts +0 -3
  122. package/dist/themes/data/atom-one-dark.js +0 -158
  123. package/dist/themes/data/atom-one-light.d.ts +0 -3
  124. package/dist/themes/data/atom-one-light.js +0 -158
  125. package/dist/themes/data/catppuccin-frappe.d.ts +0 -3
  126. package/dist/themes/data/catppuccin-frappe.js +0 -158
  127. package/dist/themes/data/catppuccin-latte.d.ts +0 -3
  128. package/dist/themes/data/catppuccin-latte.js +0 -158
  129. package/dist/themes/data/catppuccin-macchiato.d.ts +0 -3
  130. package/dist/themes/data/catppuccin-macchiato.js +0 -158
  131. package/dist/themes/data/catppuccin-mocha.d.ts +0 -3
  132. package/dist/themes/data/catppuccin-mocha.js +0 -158
  133. package/dist/themes/data/cyberpunk.d.ts +0 -17
  134. package/dist/themes/data/cyberpunk.js +0 -191
  135. package/dist/themes/data/default.d.ts +0 -3
  136. package/dist/themes/data/default.js +0 -158
  137. package/dist/themes/data/dracula.d.ts +0 -3
  138. package/dist/themes/data/dracula.js +0 -158
  139. package/dist/themes/data/flexoki.d.ts +0 -3
  140. package/dist/themes/data/flexoki.js +0 -158
  141. package/dist/themes/data/gruvbox.d.ts +0 -3
  142. package/dist/themes/data/gruvbox.js +0 -158
  143. package/dist/themes/data/index.d.ts +0 -35
  144. package/dist/themes/data/index.js +0 -64
  145. package/dist/themes/data/monokai.d.ts +0 -3
  146. package/dist/themes/data/monokai.js +0 -158
  147. package/dist/themes/data/nord.d.ts +0 -3
  148. package/dist/themes/data/nord.js +0 -158
  149. package/dist/themes/data/rose-pine-dawn.d.ts +0 -3
  150. package/dist/themes/data/rose-pine-dawn.js +0 -158
  151. package/dist/themes/data/rose-pine-moon.d.ts +0 -3
  152. package/dist/themes/data/rose-pine-moon.js +0 -158
  153. package/dist/themes/data/rose-pine.d.ts +0 -3
  154. package/dist/themes/data/rose-pine.js +0 -158
  155. package/dist/themes/data/solarized-dark.d.ts +0 -3
  156. package/dist/themes/data/solarized-dark.js +0 -158
  157. package/dist/themes/data/solarized-light.d.ts +0 -3
  158. package/dist/themes/data/solarized-light.js +0 -158
  159. package/dist/themes/data/svg-export.d.ts +0 -3
  160. package/dist/themes/data/svg-export.js +0 -158
  161. package/dist/themes/data/textual-ansi.d.ts +0 -3
  162. package/dist/themes/data/textual-ansi.js +0 -158
  163. package/dist/themes/data/textual-dark.d.ts +0 -3
  164. package/dist/themes/data/textual-dark.js +0 -158
  165. package/dist/themes/data/textual-light.d.ts +0 -3
  166. package/dist/themes/data/textual-light.js +0 -158
  167. package/dist/themes/data/tokyo-night.d.ts +0 -3
  168. package/dist/themes/data/tokyo-night.js +0 -158
  169. package/dist/themes/data/types.d.ts +0 -15
  170. package/dist/themes/data/types.js +0 -1
  171. package/dist/themes/palette.d.ts +0 -21
  172. package/dist/themes/palette.js +0 -28
  173. package/dist/themes/ramp.d.ts +0 -83
  174. package/dist/themes/ramp.js +0 -122
  175. package/dist/themes/registry.d.ts +0 -43
  176. package/dist/themes/registry.js +0 -82
  177. package/dist/themes/terminalThemes.d.ts +0 -54
  178. package/dist/themes/terminalThemes.js +0 -68
  179. package/dist/themes/transpose.d.ts +0 -87
  180. package/dist/themes/transpose.js +0 -138
  181. package/dist/widgets/button.d.ts +0 -49
  182. package/dist/widgets/button.js +0 -206
  183. package/dist/widgets/checkbox.d.ts +0 -41
  184. package/dist/widgets/checkbox.js +0 -155
  185. package/dist/widgets/dropdown.d.ts +0 -67
  186. package/dist/widgets/dropdown.js +0 -453
  187. package/dist/widgets/event-router.d.ts +0 -78
  188. package/dist/widgets/event-router.js +0 -622
  189. package/dist/widgets/focus-manager.d.ts +0 -26
  190. package/dist/widgets/focus-manager.js +0 -193
  191. package/dist/widgets/index.d.ts +0 -22
  192. package/dist/widgets/index.js +0 -15
  193. package/dist/widgets/screen.d.ts +0 -98
  194. package/dist/widgets/screen.js +0 -530
  195. package/dist/widgets/slider.d.ts +0 -57
  196. package/dist/widgets/slider.js +0 -270
  197. package/dist/widgets/static-item.d.ts +0 -40
  198. package/dist/widgets/static-item.js +0 -60
  199. package/dist/widgets/text-input.d.ts +0 -274
  200. package/dist/widgets/text-input.js +0 -1162
  201. package/dist/widgets/toggle.d.ts +0 -44
  202. package/dist/widgets/toggle.js +0 -179
  203. package/dist/widgets/types.d.ts +0 -108
  204. package/dist/widgets/types.js +0 -31
  205. package/dist/widgets/widget-base.d.ts +0 -42
  206. package/dist/widgets/widget-base.js +0 -173
package/dist/core/osc8.js DELETED
@@ -1,90 +0,0 @@
1
- /**
2
- * The OSC 8 hyperlink wire grammar — which bytes may not appear inside a
3
- * link, how a link becomes bytes, and how bytes are read back as a link.
4
- *
5
- * [LAW:one-source-of-truth] The producer (`segmentsToString`, the one encoder
6
- * every link reaches the wire through) opens a link with `osc8Open` and closes
7
- * it with `OSC8_CLOSE`; every consumer that reads rendered bytes (a width measure, a
8
- * test extracting URLs) matches them with `OSC8`; the data-model boundary
9
- * (RichText) cleans URLs with `stripOscTerminators`. All four read the one
10
- * terminator set below, so the bytes a sanitizer removes and the bytes a
11
- * reader stops at cannot disagree.
12
- *
13
- * [LAW:locality-or-seam] This module depends on nothing; every consumer
14
- * imports downward.
15
- *
16
- * The `id=` parameter is what makes one link hover as one link. A terminal
17
- * treats cells as the same hyperlink when they share BOTH the URI and the id
18
- * (the OSC 8 spec, and VTE / iTerm2 / kitty / WezTerm alike); without an id,
19
- * each open sequence is its own link. The coalescer can only share one OSC 8
20
- * pair across a run of identical SGR, so a link whose text changes style
21
- * mid-span — a bold glyph beside plain text, a padded cell — is emitted as
22
- * several pairs, and would highlight piecewise on hover.
23
- *
24
- * [LAW:types-are-the-program] The id is a pure function of the URI, so the
25
- * byte stream stays a pure function of (style, text, destination): no counter,
26
- * no construction-order dependence. The consequence is deliberate: two spans
27
- * with the same URI hover as one link wherever they sit on screen, adjacent
28
- * or not — a click on either does the same thing, so they ARE one link.
29
- * Because terminals key on the (id, URI) PAIR, a hash collision between two
30
- * different URIs merges nothing — the URIs still differ — so a 32-bit hash is
31
- * exact, not approximate.
32
- */
33
- /**
34
- * The bytes that prematurely terminate an OSC 8 sequence: ESC (`\x1b`, which
35
- * begins ST `ESC \`), BEL (`\x07`), and the 8-bit ST (`\x9c`).
36
- */
37
- const TERMINATORS = "\\x1b\\x07\\x9c";
38
- const TERMINATOR_RE = new RegExp(`[${TERMINATORS}]`, "g");
39
- /** Remove every byte that could break a URL out of its OSC 8 wrap. */
40
- export function stripOscTerminators(url) {
41
- return url.replace(TERMINATOR_RE, "");
42
- }
43
- const utf8 = new TextEncoder();
44
- /**
45
- * FNV-1a, 32-bit, over the URL's UTF-8 bytes, as 8 lowercase hex digits — a
46
- * legal `id=` value (no `:`/`;`). UTF-8 rather than UTF-16 code units, so any
47
- * other runtime computing standard FNV-1a over the same URL gets the same id.
48
- */
49
- function linkId(url) {
50
- let h = 0x811c9dc5;
51
- for (const byte of utf8.encode(url)) {
52
- h ^= byte;
53
- h = Math.imul(h, 0x01000193);
54
- }
55
- return (h >>> 0).toString(16).padStart(8, "0");
56
- }
57
- /**
58
- * The bytes that open a hyperlink to `url`.
59
- *
60
- * [LAW:single-enforcer] Wire-byte trust boundary — the URL is sanitized at
61
- * the one place it becomes an OSC 8 sequence, whichever upstream API attached
62
- * it to the Style (RichText sanitizes at its data-model boundary too; a Style
63
- * built directly with `new Style({ link })` reaches here unsanitized).
64
- */
65
- export function osc8Open(url) {
66
- const clean = stripOscTerminators(url);
67
- return `\x1b]8;id=${linkId(clean)};${clean}\x1b\\`;
68
- }
69
- /** The bytes that close the current hyperlink. */
70
- export const OSC8_CLOSE = "\x1b]8;;\x1b\\";
71
- /**
72
- * Matches one OSC 8 sequence — an open or a close — terminated by `ESC \`,
73
- * BEL, or the 8-bit ST. Group 1 is the params, group 2 the URI; both are empty
74
- * on a close. To read bytes back use `osc8Sequences`; this pattern is exported
75
- * for composing into a larger one (a width measure's zero-width alternation).
76
- */
77
- export const OSC8 = new RegExp(`\\x1b\\]8;([^;${TERMINATORS}]*);([^${TERMINATORS}]*)(?:\\x1b\\\\|\\x07|\\x9c)`);
78
- const OSC8_SCAN = new RegExp(OSC8.source, "g");
79
- /**
80
- * Every OSC 8 sequence in `text`, in order — the typed way to read rendered
81
- * bytes back.
82
- */
83
- export function osc8Sequences(text) {
84
- return [...text.matchAll(OSC8_SCAN)].map((m) => ({
85
- index: m.index,
86
- length: m[0].length,
87
- params: m[1],
88
- uri: m[2],
89
- }));
90
- }
@@ -1,141 +0,0 @@
1
- /**
2
- * Pretty — formats JavaScript data structures with highlighting.
3
- *
4
- * Lives in `core/` beside `markup` and `emoji` because it does their job: turn
5
- * foreign input into `RichText`. It composes no other renderable — the trait
6
- * every file in `renderables/` shares and this one does not — and its imports
7
- * are core primitives only. `Console.print` accepts `unknown` and must turn any
8
- * of it into something renderable, so the formatter has to sit where `console`
9
- * can reach it without an upward edge. [LAW:one-way-deps]
10
- *
11
- * Two traversals share this file, and the split is the whole design. `_format`
12
- * lays a value out across lines; `_oneLine` answers only "does this fit on one
13
- * line, and if so what is it?". They meet at `_shape`, which describes a
14
- * container without committing to either layout. One traversal answering both
15
- * questions is what made this formatter exponential: every child was rendered
16
- * once to probe it and again to place it, so a node at depth d was visited 2^d
17
- * times.
18
- */
19
- import { Segment } from "./segment.js";
20
- import type { Highlighter } from "./highlighter.js";
21
- import type { Renderable, Measurable, RenderOptions } from "./protocol.js";
22
- export interface PrettyOptions {
23
- indent?: number;
24
- expandAll?: boolean;
25
- maxLength?: number;
26
- maxString?: number;
27
- /**
28
- * How many levels of nesting to descend before eliding. Unbounded by default.
29
- *
30
- * `Console.print` supplies a bound because it formats whatever it is handed;
31
- * a caller constructing a `Pretty` has seen their data and can say what they
32
- * want. Past the cap a container renders as `[...]`, `{...}`, `Map {...}` or
33
- * `Set {...}` — visible, so the reader knows the value continues.
34
- */
35
- maxDepth?: number;
36
- indentGuides?: boolean;
37
- /**
38
- * Who colours the formatted text. Defaults to a `ReprHighlighter`.
39
- *
40
- * Passed rather than imported so a caller's choice survives. `Console.print`
41
- * routes data arguments through here, and its `highlight` flag and custom
42
- * `highlighter` have to reach the output the same way they reach a printed
43
- * string — a `Pretty` reaching for its own singleton would silently outrank
44
- * both. `NullHighlighter` is the "none" case.
45
- */
46
- highlighter?: Highlighter;
47
- }
48
- export declare class Pretty implements Renderable, Measurable {
49
- readonly data: unknown;
50
- readonly indent: number;
51
- readonly expandAll: boolean;
52
- readonly maxLength: number | undefined;
53
- readonly maxString: number | undefined;
54
- readonly maxDepth: number;
55
- readonly indentGuides: boolean;
56
- readonly highlighter: Highlighter;
57
- constructor(data: unknown, options?: PrettyOptions);
58
- render(options: RenderOptions): Iterable<Segment>;
59
- measure(_options: RenderOptions): {
60
- minimum: number;
61
- maximum: number;
62
- };
63
- /**
64
- * The text a value shows without being reflected on, or `null` when it is an
65
- * object and the shape arms own it.
66
- *
67
- * Every kind answered here renders the same wherever it sits — no
68
- * indentation, no width to fit — which is why one method serves both
69
- * traversals.
70
- */
71
- private _scalar;
72
- /**
73
- * A container, or the text standing in for one that is empty or past the
74
- * depth cap.
75
- *
76
- * `positions` is a thunk because both of those answers are reachable from
77
- * `size` alone, and reaching a position is not free: a `Map` or `Set` reaches
78
- * its own through an iterator, so enumerating one only to elide it drains a
79
- * container to print `Set {...}`. `size` also says how many positions were
80
- * dropped, which is where the elision marker comes from — one derivation, so
81
- * the count and the bound cannot disagree.
82
- */
83
- private _container;
84
- /**
85
- * The brackets and positions of an object, layout-free. See `Shape`.
86
- *
87
- * `bound` is the most positions the caller could ever use. Laying out passes
88
- * `Infinity`, because it prints every position it is handed. A probe passes
89
- * what is left of its line, which is already more positions than a fitting
90
- * one could hold — `SEPARATOR` charges two cells apiece, so a container with
91
- * more positions than `budget` overruns however narrow its contents are.
92
- * Reaching past it only ever feeds a join that returns `null`, and reaching a
93
- * position is what drains a `Map` or `Set`.
94
- */
95
- private _shape;
96
- /** The laid-out form of a value, expanded across lines wherever one line will not do. */
97
- private _format;
98
- /** The arms for a non-null object, with `value` already on the open path. */
99
- private _formatObject;
100
- /**
101
- * One position, with every value in it laid out.
102
- *
103
- * `at.column` is where `slot.head` begins. Rather than hand-tracking a
104
- * second, parallel "column so far" alongside `out` — two values a future
105
- * edit could update out of step, silently reintroducing a stale-budget bug
106
- * of the same shape this file just fixed — each hole derives its own
107
- * column fresh from `out` via `lineColumn`, the one place "text just
108
- * emitted" becomes "column now". [LAW:one-source-of-truth] `out` is
109
- * already the complete record; `column` is a read of it, not a second copy
110
- * of the same fact. `_joinOneLine`'s probe sibling tracks the analogous
111
- * thing via `budget` shrinking instead, because a probe already discards
112
- * anything that overruns and so never needs to know where a multi-line
113
- * insert's last line ends.
114
- *
115
- * Each hole's `reserve` is its own `tail` plus, only for the slot's last
116
- * hole, whatever `at.reserve` already asked this whole slot to leave room
117
- * for (`_formatObject`'s trailing `,`). An earlier hole's tail is never
118
- * folded into a later hole's reserve — it is spent, not carried, the moment
119
- * `out` grows past it.
120
- */
121
- private _expandSlot;
122
- /** The one-line form of a value, or `null` when it will not fit `at.budget`. */
123
- private _oneLine;
124
- /**
125
- * A container's positions on one line, or `null` as soon as they overrun.
126
- *
127
- * The budget is spent as it goes and each position is asked for only what is
128
- * left, so a subtree that has already outgrown the line is abandoned where it
129
- * outgrew it rather than formatted in full and then measured.
130
- *
131
- * The brackets are charged before anything is read, and that ordering is what
132
- * bounds the traversal: a budget checked only against the finished text still
133
- * reads the whole subtree to produce text it then throws away. Charged first,
134
- * every level costs at least the two cells of its own brackets, so a probe
135
- * descends at most `budget / 2` levels however deep the data goes.
136
- */
137
- private _joinOneLine;
138
- /** One position on one line, or `null` when any value in it will not fit. */
139
- private _slotOneLine;
140
- private _addIndentGuides;
141
- }