@promptctl/rich-js 0.18.0 → 0.19.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 (244) hide show
  1. package/README.md +9 -7
  2. package/dist/core/anchor.d.ts +45 -0
  3. package/dist/core/anchor.js +39 -0
  4. package/dist/core/ansi.d.ts +65 -0
  5. package/dist/core/ansi.js +231 -0
  6. package/dist/core/box.d.ts +145 -0
  7. package/dist/core/box.js +372 -0
  8. package/dist/core/cells.d.ts +192 -0
  9. package/dist/core/cells.js +334 -0
  10. package/dist/core/clock.d.ts +48 -0
  11. package/dist/core/clock.js +42 -0
  12. package/dist/core/color.d.ts +326 -0
  13. package/dist/core/color.js +1225 -0
  14. package/dist/core/console.d.ts +196 -0
  15. package/dist/core/console.js +596 -0
  16. package/dist/core/easing.d.ts +86 -0
  17. package/dist/core/easing.js +171 -0
  18. package/dist/core/emoji.d.ts +24 -0
  19. package/dist/core/emoji.js +391 -0
  20. package/dist/core/env.d.ts +16 -0
  21. package/dist/core/env.js +16 -0
  22. package/dist/core/export-html.d.ts +59 -0
  23. package/dist/core/export-html.js +197 -0
  24. package/dist/core/export-lines.d.ts +130 -0
  25. package/dist/core/export-lines.js +159 -0
  26. package/dist/core/export-svg.d.ts +49 -0
  27. package/dist/core/export-svg.js +213 -0
  28. package/dist/core/fnv1a.d.ts +10 -0
  29. package/dist/core/fnv1a.js +17 -0
  30. package/dist/core/highlighter.d.ts +33 -0
  31. package/dist/core/highlighter.js +190 -0
  32. package/dist/core/json.d.ts +27 -0
  33. package/dist/core/json.js +53 -0
  34. package/dist/core/markup.d.ts +140 -0
  35. package/dist/core/markup.js +654 -0
  36. package/dist/core/measure.d.ts +27 -0
  37. package/dist/core/measure.js +67 -0
  38. package/dist/core/memo.d.ts +19 -0
  39. package/dist/core/memo.js +34 -0
  40. package/dist/core/oklch.d.ts +161 -0
  41. package/dist/core/oklch.js +312 -0
  42. package/dist/core/osc8.d.ts +68 -0
  43. package/dist/core/osc8.js +78 -0
  44. package/dist/core/paint.d.ts +107 -0
  45. package/dist/core/paint.js +150 -0
  46. package/dist/core/place.d.ts +30 -0
  47. package/dist/core/place.js +49 -0
  48. package/dist/core/pretty.d.ts +247 -0
  49. package/dist/core/pretty.js +906 -0
  50. package/dist/core/protocol.d.ts +305 -0
  51. package/dist/core/protocol.js +183 -0
  52. package/dist/core/render.d.ts +87 -0
  53. package/dist/core/render.js +105 -0
  54. package/dist/core/segment.d.ts +162 -0
  55. package/dist/core/segment.js +488 -0
  56. package/dist/core/spinnerData.d.ts +12 -0
  57. package/dist/core/spinnerData.js +117 -0
  58. package/dist/core/strip.d.ts +152 -0
  59. package/dist/core/strip.js +326 -0
  60. package/dist/core/style.d.ts +189 -0
  61. package/dist/core/style.js +758 -0
  62. package/dist/core/subscription.d.ts +12 -0
  63. package/dist/core/subscription.js +12 -0
  64. package/dist/core/text.d.ts +283 -0
  65. package/dist/core/text.js +1097 -0
  66. package/dist/core/wrap.d.ts +46 -0
  67. package/dist/core/wrap.js +140 -0
  68. package/dist/host/app.d.ts +133 -0
  69. package/dist/host/app.js +285 -0
  70. package/dist/host/host-environment.d.ts +26 -0
  71. package/dist/host/host-environment.js +44 -0
  72. package/dist/host/index.d.ts +6 -0
  73. package/dist/host/index.js +3 -0
  74. package/dist/host/terminal-host.d.ts +180 -0
  75. package/dist/host/terminal-host.js +186 -0
  76. package/dist/index.d.ts +98 -0
  77. package/dist/index.js +114 -0
  78. package/dist/node/prompt.d.ts +34 -0
  79. package/dist/node/prompt.js +51 -0
  80. package/dist/node/save.d.ts +18 -0
  81. package/dist/node/save.js +24 -0
  82. package/dist/node/terminal-host.d.ts +114 -0
  83. package/dist/node/terminal-host.js +227 -0
  84. package/dist/node/traceback.d.ts +38 -0
  85. package/dist/node/traceback.js +98 -0
  86. package/dist/renderables/align.d.ts +16 -0
  87. package/dist/renderables/align.js +26 -0
  88. package/dist/renderables/columns.d.ts +77 -0
  89. package/dist/renderables/columns.js +191 -0
  90. package/dist/renderables/constrain.d.ts +15 -0
  91. package/dist/renderables/constrain.js +31 -0
  92. package/dist/renderables/effect.d.ts +98 -0
  93. package/dist/renderables/effect.js +160 -0
  94. package/dist/renderables/embed.d.ts +107 -0
  95. package/dist/renderables/embed.js +160 -0
  96. package/dist/renderables/flexStrip.d.ts +41 -0
  97. package/dist/renderables/flexStrip.js +200 -0
  98. package/dist/renderables/group.d.ts +14 -0
  99. package/dist/renderables/group.js +22 -0
  100. package/dist/renderables/layout.d.ts +75 -0
  101. package/dist/renderables/layout.js +223 -0
  102. package/dist/renderables/live.d.ts +74 -0
  103. package/dist/renderables/live.js +188 -0
  104. package/dist/renderables/markdown.d.ts +38 -0
  105. package/dist/renderables/markdown.js +587 -0
  106. package/dist/renderables/padding.d.ts +59 -0
  107. package/dist/renderables/padding.js +147 -0
  108. package/dist/renderables/panel.d.ts +114 -0
  109. package/dist/renderables/panel.js +303 -0
  110. package/dist/renderables/progress.d.ts +178 -0
  111. package/dist/renderables/progress.js +362 -0
  112. package/dist/renderables/progressBar.d.ts +31 -0
  113. package/dist/renderables/progressBar.js +64 -0
  114. package/dist/renderables/prompt.d.ts +71 -0
  115. package/dist/renderables/prompt.js +165 -0
  116. package/dist/renderables/ratio.d.ts +123 -0
  117. package/dist/renderables/ratio.js +213 -0
  118. package/dist/renderables/rule.d.ts +26 -0
  119. package/dist/renderables/rule.js +86 -0
  120. package/dist/renderables/spinner.d.ts +57 -0
  121. package/dist/renderables/spinner.js +103 -0
  122. package/dist/renderables/status.d.ts +29 -0
  123. package/dist/renderables/status.js +46 -0
  124. package/dist/renderables/syntax.d.ts +65 -0
  125. package/dist/renderables/syntax.js +166 -0
  126. package/dist/renderables/table.d.ts +232 -0
  127. package/dist/renderables/table.js +973 -0
  128. package/dist/renderables/traceback.d.ts +32 -0
  129. package/dist/renderables/traceback.js +279 -0
  130. package/dist/renderables/tree.d.ts +76 -0
  131. package/dist/renderables/tree.js +177 -0
  132. package/dist/renderables/viewport.d.ts +114 -0
  133. package/dist/renderables/viewport.js +196 -0
  134. package/dist/template-bindings/color-funcs.d.ts +109 -0
  135. package/dist/template-bindings/color-funcs.js +243 -0
  136. package/dist/template-bindings/helpers.d.ts +26 -0
  137. package/dist/template-bindings/helpers.js +33 -0
  138. package/dist/template-bindings/index.d.ts +119 -0
  139. package/dist/template-bindings/index.js +162 -0
  140. package/dist/template-bindings/palette-funcs.d.ts +96 -0
  141. package/dist/template-bindings/palette-funcs.js +145 -0
  142. package/dist/template-bindings/style-funcs.d.ts +28 -0
  143. package/dist/template-bindings/style-funcs.js +157 -0
  144. package/dist/themes/buildPalette.d.ts +57 -0
  145. package/dist/themes/buildPalette.js +100 -0
  146. package/dist/themes/colorMath.d.ts +94 -0
  147. package/dist/themes/colorMath.js +280 -0
  148. package/dist/themes/colorRef.d.ts +36 -0
  149. package/dist/themes/colorRef.js +78 -0
  150. package/dist/themes/data/ansi-tables.d.ts +14 -0
  151. package/dist/themes/data/ansi-tables.js +49 -0
  152. package/dist/themes/data/atom-one-dark.d.ts +3 -0
  153. package/dist/themes/data/atom-one-dark.js +177 -0
  154. package/dist/themes/data/atom-one-light.d.ts +3 -0
  155. package/dist/themes/data/atom-one-light.js +177 -0
  156. package/dist/themes/data/catppuccin-frappe.d.ts +3 -0
  157. package/dist/themes/data/catppuccin-frappe.js +177 -0
  158. package/dist/themes/data/catppuccin-latte.d.ts +3 -0
  159. package/dist/themes/data/catppuccin-latte.js +177 -0
  160. package/dist/themes/data/catppuccin-macchiato.d.ts +3 -0
  161. package/dist/themes/data/catppuccin-macchiato.js +177 -0
  162. package/dist/themes/data/catppuccin-mocha.d.ts +3 -0
  163. package/dist/themes/data/catppuccin-mocha.js +177 -0
  164. package/dist/themes/data/cyberpunk.d.ts +17 -0
  165. package/dist/themes/data/cyberpunk.js +193 -0
  166. package/dist/themes/data/default.d.ts +3 -0
  167. package/dist/themes/data/default.js +160 -0
  168. package/dist/themes/data/dracula.d.ts +3 -0
  169. package/dist/themes/data/dracula.js +177 -0
  170. package/dist/themes/data/flexoki.d.ts +3 -0
  171. package/dist/themes/data/flexoki.js +177 -0
  172. package/dist/themes/data/gruvbox.d.ts +3 -0
  173. package/dist/themes/data/gruvbox.js +177 -0
  174. package/dist/themes/data/index.d.ts +35 -0
  175. package/dist/themes/data/index.js +64 -0
  176. package/dist/themes/data/monokai.d.ts +3 -0
  177. package/dist/themes/data/monokai.js +177 -0
  178. package/dist/themes/data/nord.d.ts +3 -0
  179. package/dist/themes/data/nord.js +177 -0
  180. package/dist/themes/data/rose-pine-dawn.d.ts +3 -0
  181. package/dist/themes/data/rose-pine-dawn.js +177 -0
  182. package/dist/themes/data/rose-pine-moon.d.ts +3 -0
  183. package/dist/themes/data/rose-pine-moon.js +177 -0
  184. package/dist/themes/data/rose-pine.d.ts +3 -0
  185. package/dist/themes/data/rose-pine.js +177 -0
  186. package/dist/themes/data/solarized-dark.d.ts +3 -0
  187. package/dist/themes/data/solarized-dark.js +177 -0
  188. package/dist/themes/data/solarized-light.d.ts +3 -0
  189. package/dist/themes/data/solarized-light.js +177 -0
  190. package/dist/themes/data/svg-export.d.ts +3 -0
  191. package/dist/themes/data/svg-export.js +177 -0
  192. package/dist/themes/data/textual-ansi.d.ts +3 -0
  193. package/dist/themes/data/textual-ansi.js +160 -0
  194. package/dist/themes/data/textual-dark.d.ts +3 -0
  195. package/dist/themes/data/textual-dark.js +160 -0
  196. package/dist/themes/data/textual-light.d.ts +3 -0
  197. package/dist/themes/data/textual-light.js +160 -0
  198. package/dist/themes/data/tokyo-night.d.ts +3 -0
  199. package/dist/themes/data/tokyo-night.js +177 -0
  200. package/dist/themes/data/types.d.ts +31 -0
  201. package/dist/themes/data/types.js +10 -0
  202. package/dist/themes/palette.d.ts +45 -0
  203. package/dist/themes/palette.js +71 -0
  204. package/dist/themes/ramp.d.ts +70 -0
  205. package/dist/themes/ramp.js +103 -0
  206. package/dist/themes/registry.d.ts +44 -0
  207. package/dist/themes/registry.js +105 -0
  208. package/dist/themes/terminalThemes.d.ts +49 -0
  209. package/dist/themes/terminalThemes.js +63 -0
  210. package/dist/themes/transpose.d.ts +87 -0
  211. package/dist/themes/transpose.js +138 -0
  212. package/dist/widgets/button.d.ts +45 -0
  213. package/dist/widgets/button.js +177 -0
  214. package/dist/widgets/checkbox.d.ts +38 -0
  215. package/dist/widgets/checkbox.js +135 -0
  216. package/dist/widgets/dropdown.d.ts +64 -0
  217. package/dist/widgets/dropdown.js +416 -0
  218. package/dist/widgets/event-router.d.ts +71 -0
  219. package/dist/widgets/event-router.js +629 -0
  220. package/dist/widgets/focus-manager.d.ts +45 -0
  221. package/dist/widgets/focus-manager.js +191 -0
  222. package/dist/widgets/hit.d.ts +64 -0
  223. package/dist/widgets/hit.js +113 -0
  224. package/dist/widgets/index.d.ts +20 -0
  225. package/dist/widgets/index.js +14 -0
  226. package/dist/widgets/ink.d.ts +22 -0
  227. package/dist/widgets/ink.js +31 -0
  228. package/dist/widgets/slider.d.ts +54 -0
  229. package/dist/widgets/slider.js +247 -0
  230. package/dist/widgets/static-item.d.ts +34 -0
  231. package/dist/widgets/static-item.js +54 -0
  232. package/dist/widgets/text-input.d.ts +283 -0
  233. package/dist/widgets/text-input.js +1174 -0
  234. package/dist/widgets/themed-widget.d.ts +20 -0
  235. package/dist/widgets/themed-widget.js +89 -0
  236. package/dist/widgets/toggle.d.ts +41 -0
  237. package/dist/widgets/toggle.js +157 -0
  238. package/dist/widgets/types.d.ts +87 -0
  239. package/dist/widgets/types.js +30 -0
  240. package/dist/widgets/widget-app.d.ts +65 -0
  241. package/dist/widgets/widget-app.js +206 -0
  242. package/dist/widgets/widget-base.d.ts +42 -0
  243. package/dist/widgets/widget-base.js +172 -0
  244. package/package.json +16 -2
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Unsubscribe — the shape every `on…()` in this library hands back.
3
+ *
4
+ * [LAW:decomposition] It lives in `core/` because two subsystems that must not
5
+ * depend on each other both need it: `host/` returns one from `onData` and
6
+ * `onResize`, `widgets/` returns one from `onChange`, `onSubmit`, `onKey` and
7
+ * `onMouse`. Either home above this tier would make the other import a
8
+ * subsystem it has no business knowing about — the extraction of `src/host/`
9
+ * out of `src/widgets/` is what surfaced that, since the type was sitting in
10
+ * `widgets/types.ts` and the host seam was importing it from there.
11
+ */
12
+ export type Unsubscribe = () => void;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Unsubscribe — the shape every `on…()` in this library hands back.
3
+ *
4
+ * [LAW:decomposition] It lives in `core/` because two subsystems that must not
5
+ * depend on each other both need it: `host/` returns one from `onData` and
6
+ * `onResize`, `widgets/` returns one from `onChange`, `onSubmit`, `onKey` and
7
+ * `onMouse`. Either home above this tier would make the other import a
8
+ * subsystem it has no business knowing about — the extraction of `src/host/`
9
+ * out of `src/widgets/` is what surfaced that, since the type was sitting in
10
+ * `widgets/types.ts` and the host seam was importing it from there.
11
+ */
12
+ export {};
@@ -0,0 +1,283 @@
1
+ /**
2
+ * RichText — styled text with spans. The primary text type for the library.
3
+ */
4
+ import { Segment } from "./segment.js";
5
+ import { Style, type TextStyle } from "./style.js";
6
+ import type { Renderable, Measurable, OverflowMethod, RenderOptions } from "./protocol.js";
7
+ export declare function stripControlChars(text: string): string;
8
+ /**
9
+ * The style a stored `TextStyle` stands for in this render.
10
+ *
11
+ * A parsed string can carry a link, so the result is sanitized on the way out
12
+ * as well.
13
+ */
14
+ export declare function resolveStyle(options: RenderOptions, style: TextStyle): Style;
15
+ export declare class Span {
16
+ readonly start: number;
17
+ readonly end: number;
18
+ readonly style: TextStyle;
19
+ constructor(start: number, end: number, style: TextStyle);
20
+ get hasLength(): boolean;
21
+ toString(): string;
22
+ split(offset: number): [Span, Span | undefined];
23
+ move(delta: number): Span;
24
+ rightCrop(offset: number): Span;
25
+ extend(count: number): Span;
26
+ }
27
+ export interface RichTextOptions {
28
+ style?: TextStyle;
29
+ justify?: "left" | "center" | "right" | "full";
30
+ overflow?: OverflowMethod;
31
+ end?: string;
32
+ tabSize?: number;
33
+ noWrap?: boolean;
34
+ }
35
+ export declare class RichText implements Renderable, Measurable {
36
+ private _text;
37
+ private _spans;
38
+ private _style;
39
+ private _justify;
40
+ private _overflow;
41
+ private _end;
42
+ private _tabSize;
43
+ private _noWrap;
44
+ constructor(text?: string, options?: RichTextOptions);
45
+ get plain(): string;
46
+ set plain(value: string);
47
+ get length(): number;
48
+ /**
49
+ * The cells of the plain text with each tab widened to its stop counted from
50
+ * this text's own column 0, as `render` widens it — so it is the drawn width
51
+ * of a one-line text set at a stop. A deliberate departure from Rich, whose
52
+ * `Text.cell_len` counts a tab as no cells, so everything sized by it — a
53
+ * truncation, an alignment, a header's remaining width — decided on a width
54
+ * no render draws.
55
+ */
56
+ get cellLength(): number;
57
+ get hasContent(): boolean;
58
+ /** The base style every span layers over, resolved at render unless it is a `Style`. */
59
+ get style(): TextStyle;
60
+ set style(value: TextStyle);
61
+ get justify(): "left" | "center" | "right" | "full" | undefined;
62
+ set justify(value: "left" | "center" | "right" | "full" | undefined);
63
+ get overflow(): OverflowMethod | undefined;
64
+ set overflow(value: OverflowMethod | undefined);
65
+ get end(): string;
66
+ set end(value: string);
67
+ get noWrap(): boolean;
68
+ set noWrap(value: boolean);
69
+ get spans(): readonly Span[];
70
+ /**
71
+ * This text's own style, spans aside, as the render drawing it resolves it.
72
+ * A name the render's theme does not define resolves to no style, because
73
+ * text forgives a missing name.
74
+ */
75
+ resolvedStyle(options: RenderOptions): Style;
76
+ /**
77
+ * The style of the cell-column at the named edge — base style merged with
78
+ * any spans covering the leftmost (side="left") or rightmost (side="right")
79
+ * character.
80
+ *
81
+ * [LAW:locality-or-seam] Used by `Joiner`s to paint the transition between
82
+ * adjacent `Strip` items. Joiners only ever need the column adjacent to
83
+ * them, so the cell type exposes that column rather than constraining its
84
+ * interior to be uniform. For RichText with uniform styling, both edges
85
+ * return the same style; for RichText with edge variation, each edge
86
+ * accurately reports the column the joiner actually meets.
87
+ *
88
+ * Position is by character index (not cell column). For wide-character
89
+ * text, the last character occupies the rightmost cell column — the bg
90
+ * of that character covers both columns, so character-index lookup gives
91
+ * the correct edge color.
92
+ *
93
+ * Takes the render's options because the edge is reported as it will be
94
+ * drawn, and a style name draws as whatever the render's theme says.
95
+ */
96
+ edgeStyle(side: "left" | "right", options: RenderOptions): Style;
97
+ append(content: string | RichText, style?: TextStyle): this;
98
+ contains(needle: string | RichText): boolean;
99
+ at(index: number): RichText;
100
+ slice(start?: number, end?: number): RichText;
101
+ /**
102
+ * The one way a span enters this text. [LAW:single-enforcer] An empty style
103
+ * adds nothing, as the reference's `if style:` has it, and every other style
104
+ * is admitted as given.
105
+ */
106
+ private _addSpan;
107
+ stylize(style: TextStyle, start?: number, end?: number): this;
108
+ highlightRegex(pattern: RegExp, style?: TextStyle): number;
109
+ highlightWords(words: string[], style: TextStyle, options?: {
110
+ caseSensitive?: boolean;
111
+ }): number;
112
+ copy(): RichText;
113
+ blankCopy(text?: string): RichText;
114
+ split(separator?: string): RichText[];
115
+ divide(offsets: number[]): RichText[];
116
+ rstrip(): this;
117
+ pad(count: number, char?: string): this;
118
+ /**
119
+ * Each tab widened to the next tab stop, in place, as Rich's
120
+ * `Text.expand_tabs` widens it: spans move with the characters they style, so
121
+ * the text measures what it will draw.
122
+ */
123
+ expandTabs(): this;
124
+ padLeft(count: number, char?: string): this;
125
+ padRight(count: number, char?: string): this;
126
+ setLength(length: number): this;
127
+ extendStyle(count: number): this;
128
+ /**
129
+ * Truncate to a fixed cell-column width, in one of three modes.
130
+ *
131
+ * - `mode: "right"` (default) \u2014 drop characters from the right; append
132
+ * `marker` (if any) at the cut.
133
+ * - `mode: "left"` \u2014 drop characters from the left; prepend `marker` at
134
+ * the cut.
135
+ * - `mode: "middle"` \u2014 keep equal halves from both ends; place `marker`
136
+ * in the middle.
137
+ *
138
+ * Marker default is `"\u2026"`. Pass `marker: ""` for raw cropping without an
139
+ * indicator glyph. A marker wider than `width` is itself cut to the glyphs
140
+ * that fit, and the text takes whatever cells that leaves — all of them, when
141
+ * not one glyph of the marker fits — so the result is never wider than asked.
142
+ * Every cut, marker and text alike, falls between grapheme clusters.
143
+ *
144
+ * Spans are preserved through the cut: characters that survive keep their
145
+ * styling; the marker (if any) is inserted as plain text with no span.
146
+ * Use `stylize(...)` on the result to color the marker if needed.
147
+ *
148
+ * Text that fits comes back untouched. Text that is cut has its tabs widened
149
+ * to their stops first, as `expandTabs` widens them, so the width cut to is
150
+ * the width drawn.
151
+ *
152
+ * [LAW:dataflow-not-control-flow] mode/marker/width all flow as values;
153
+ * the walk is the same shape regardless. No "if truncated then rebuild"
154
+ * branch \u2014 the unchanged path just early-returns when content fits.
155
+ */
156
+ truncate(width: number, options?: {
157
+ mode?: "right" | "left" | "middle";
158
+ marker?: string;
159
+ }): this;
160
+ private _cropRightTo;
161
+ private _cropLeftTo;
162
+ align(justify: "left" | "center" | "right", width: number): this;
163
+ removeSuffix(suffix: string): this;
164
+ appendTokens(tokens: Array<[string, TextStyle?]>): this;
165
+ static assemble(parts: Array<string | [string, TextStyle?] | RichText>, options?: {
166
+ style?: TextStyle;
167
+ }): RichText;
168
+ static styled(text: string, style: TextStyle): RichText;
169
+ /**
170
+ * Concatenate a sequence of `RichText` fragments into a single `RichText`,
171
+ * flattening each fragment's wrapping `style` onto a span over that
172
+ * fragment's range so downstream rendering preserves the original styling.
173
+ *
174
+ * Designed for the template engine's `RichText[]` output: a top-level
175
+ * `{{ red "x" }}{{ blue "y" }}` evaluates to two fragments — one with
176
+ * wrapping `style = red`, one with `blue` — and consumers that want a
177
+ * single styled string for downstream rendering need both styles
178
+ * preserved as spans on the concatenated result, which is what `append()`
179
+ * does with each fragment.
180
+ *
181
+ * Empty input → empty `RichText` with `end: ""`. Caller can override
182
+ * `end` (defaults to `""` — the engine-output case rarely wants a
183
+ * trailing newline added by the container).
184
+ */
185
+ static fromFragments(fragments: readonly RichText[], options?: {
186
+ end?: string;
187
+ }): RichText;
188
+ render(options: RenderOptions): Iterable<Segment>;
189
+ measure(options: RenderOptions): {
190
+ minimum: number;
191
+ maximum: number;
192
+ };
193
+ /**
194
+ * The rendered text cut at every span edge, each piece carrying the base
195
+ * style plus every span covering it.
196
+ *
197
+ * Walked span-first rather than piece-first, and that direction is the whole
198
+ * performance argument. The pieces are cut at the span edges themselves, so
199
+ * a span covers a piece exactly when it covers the piece's first character —
200
+ * which makes each span's run of pieces a contiguous range it can be written
201
+ * into once, instead of a question every piece asks of every span. The
202
+ * piece-first form charged `spans x pieces`, and the pieces are themselves
203
+ * cut by the spans, so anything styling densely paid the square in ordinary
204
+ * use: 8,000 one-character spans took 211ms where 1,000 took 3.2ms. Every
205
+ * `Highlighter` over a large value reaches that, and so does `Pretty`, whose
206
+ * indent guides emit a span per indent character.
207
+ *
208
+ * Span-first is also what keeps the composition honest, for free. `Style.add`
209
+ * is order-dependent and the last writer wins, so the pieces have to fold
210
+ * their styles in `_spans` order — which iterating `_spans` is, and which a
211
+ * sweep ordered by position would have had to reconstruct.
212
+ *
213
+ * [LAW:dataflow-not-control-flow] A span covering nothing — empty, reversed,
214
+ * or entirely past the text — still cuts the text where its edges land, as it
215
+ * always did, and then folds into no piece at all: its range comes out empty
216
+ * and no case handles it.
217
+ */
218
+ private _buildSegments;
219
+ /**
220
+ * The pieces one logical line wrapped into, each placed in a canvas
221
+ * `maxWidth` wide, as Rich's `Lines.justify` places them — pinned block for
222
+ * block against the reference in `test/core/text-justify.test.ts`.
223
+ *
224
+ * It is handed the whole wrapped line because `full` is the one mode a
225
+ * piece cannot answer alone: the reference leaves a paragraph's last line
226
+ * ragged, so where the piece sits decides its answer where the other three
227
+ * modes need only the piece itself. The set that decides "last" is this one
228
+ * and not the whole render — `Text.wrap` calls `Lines.justify` once per
229
+ * *logical* line — and `Segment.divide` already handed it over whole.
230
+ */
231
+ private _justifyLines;
232
+ /**
233
+ * One line placed in a canvas `maxWidth` wide.
234
+ *
235
+ * Centre and right align on the line's *content*. The whitespace a wrap
236
+ * leaves on the end of the line it closed is the break's own padding, not
237
+ * text, and aligning around it pushes the text half a gap off true — a
238
+ * centred title that wraps drifts left on every line that happens to end in
239
+ * a space. Left keeps that whitespace, because there it is already on the
240
+ * side the padding goes.
241
+ *
242
+ * `undefined` is not `"left"`: it is Rich's `"default"`, which places the
243
+ * line without padding it at all. That distinction is what lets a soft-wrapped
244
+ * `Console.print` leave its lines at their natural width.
245
+ *
246
+ * The padding is drawn in the text's base style, as the reference pads
247
+ * inside the `Text` it justifies: a title "on red" fills its row in red.
248
+ */
249
+ private _justifyLine;
250
+ /**
251
+ * One line of a wrapped paragraph, its gaps widened until it fills the
252
+ * canvas — what `justify: "full"` promises, and what the reference's
253
+ * `Lines.justify` does to every line of a paragraph but the last.
254
+ *
255
+ * Slack goes in a cell at a time, starting at the rightmost gap and walking
256
+ * left, round and round until the line is full. That order is the
257
+ * reference's own, and what it decides is where an odd cell lands when the
258
+ * slack will not divide evenly: the right-hand gaps take it.
259
+ *
260
+ * The words come from the line's *text* split on a single space, with the
261
+ * blank a trailing separator leaves behind dropped — `Text.split` and
262
+ * `String.prototype.split` agree on that list, empty words and all. Two
263
+ * consequences read as bugs until you know whose they are: a run of n
264
+ * spaces is n gaps rather than one, so spacing an author widened stretches
265
+ * instead of collapsing, and the whitespace a wrap left hanging is a gap
266
+ * like the rest, which is why a filled line does not keep it. Both are
267
+ * pinned in `text-justify.golden.txt`, by the `uneven` and `sentence`
268
+ * blocks respectively.
269
+ */
270
+ private _fillLine;
271
+ /**
272
+ * One wrapped line cut to the canvas.
273
+ *
274
+ * Everything reaching here already survived wrapping, so the only text still
275
+ * too wide is text no break could help: a word longer than the canvas under
276
+ * a non-folding overflow method, a glyph wider than the budget, a canvas
277
+ * with no cells at all, or a `noWrap` line, which no break was allowed to
278
+ * help. That is what makes the overflow method a last resort rather than the
279
+ * first thing a long cell meets. `"fold"` has nothing left to fold here and
280
+ * cuts as `"crop"` does, as the reference's `truncate` does.
281
+ */
282
+ private _fitLine;
283
+ }