@promptctl/rich-js 0.19.0 → 0.21.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 (58) hide show
  1. package/README.md +3 -2
  2. package/dist/core/anchor.d.ts +5 -0
  3. package/dist/core/anchor.js +10 -0
  4. package/dist/core/color.d.ts +1 -0
  5. package/dist/core/color.js +14 -3
  6. package/dist/core/noise.d.ts +31 -0
  7. package/dist/core/noise.js +94 -0
  8. package/dist/core/paint.js +13 -2
  9. package/dist/core/pretty.d.ts +23 -2
  10. package/dist/core/pretty.js +54 -18
  11. package/dist/core/protocol.d.ts +2 -0
  12. package/dist/core/protocol.js +3 -2
  13. package/dist/core/selection.d.ts +12 -0
  14. package/dist/core/selection.js +14 -0
  15. package/dist/core/strip.d.ts +159 -76
  16. package/dist/core/strip.js +367 -215
  17. package/dist/core/style.js +10 -7
  18. package/dist/host/app.d.ts +68 -2
  19. package/dist/host/app.js +125 -15
  20. package/dist/host/index.d.ts +3 -1
  21. package/dist/host/index.js +1 -0
  22. package/dist/host/input.d.ts +87 -0
  23. package/dist/host/input.js +517 -0
  24. package/dist/host/terminal-host.d.ts +12 -0
  25. package/dist/host/terminal-host.js +2 -0
  26. package/dist/index.d.ts +11 -6
  27. package/dist/index.js +7 -4
  28. package/dist/node/terminal-host.d.ts +7 -0
  29. package/dist/node/terminal-host.js +7 -0
  30. package/dist/renderables/effect.d.ts +89 -16
  31. package/dist/renderables/effect.js +115 -42
  32. package/dist/renderables/effects.d.ts +260 -0
  33. package/dist/renderables/effects.js +596 -0
  34. package/dist/renderables/embed.d.ts +11 -5
  35. package/dist/renderables/embed.js +13 -6
  36. package/dist/renderables/flexStrip.d.ts +1 -1
  37. package/dist/renderables/flexStrip.js +10 -9
  38. package/dist/renderables/list-view.d.ts +42 -0
  39. package/dist/renderables/list-view.js +78 -0
  40. package/dist/renderables/progress.d.ts +6 -0
  41. package/dist/renderables/progress.js +11 -4
  42. package/dist/renderables/progressBar.d.ts +22 -2
  43. package/dist/renderables/progressBar.js +52 -7
  44. package/dist/renderables/rule.d.ts +2 -2
  45. package/dist/renderables/rule.js +12 -10
  46. package/dist/renderables/table.js +5 -7
  47. package/dist/renderables/viewport.d.ts +30 -0
  48. package/dist/renderables/viewport.js +59 -3
  49. package/dist/widgets/dropdown.js +3 -3
  50. package/dist/widgets/event-router.d.ts +31 -40
  51. package/dist/widgets/event-router.js +52 -483
  52. package/dist/widgets/hit.js +2 -4
  53. package/dist/widgets/index.d.ts +2 -1
  54. package/dist/widgets/types.d.ts +8 -25
  55. package/dist/widgets/types.js +8 -0
  56. package/dist/widgets/widget-app.d.ts +22 -7
  57. package/dist/widgets/widget-app.js +22 -12
  58. package/package.json +26 -18
@@ -25,6 +25,7 @@
25
25
  * single-style invariant on the cell type — the terminal supports per-column
26
26
  * styling, so the cell type does too.
27
27
  */
28
+ import type { Anchor } from "./anchor.js";
28
29
  import { Segment } from "./segment.js";
29
30
  import { Style } from "./style.js";
30
31
  import { type Measurable, type Renderable, type RenderOptions } from "./protocol.js";
@@ -44,14 +45,58 @@ import { type Measurable, type Renderable, type RenderOptions } from "./protocol
44
45
  export interface StyledRenderable extends Renderable {
45
46
  edgeStyle(side: "left" | "right", options: RenderOptions): Style;
46
47
  }
48
+ /**
49
+ * Where a join sits in its strip. `index` counts joins from the strip's start:
50
+ * the join before item `i` is `i`, and the end after the last of `n` items is
51
+ * `n`. It names the seam, not the line it lands on, so where a `FlexStrip`
52
+ * wraps, the end cap and the next line's lead both carry the index of the seam
53
+ * the wrap replaced — and every seam that survives a wrap keeps its own.
54
+ */
55
+ export interface JoinContext {
56
+ readonly index: number;
57
+ }
47
58
  export interface Joiner<T extends StyledRenderable = StyledRenderable> {
48
59
  /**
49
60
  * `left === null` marks the start endpoint; `right === null` marks the end
50
61
  * endpoint. The joiner decides what an endpoint looks like — typically
51
62
  * fg-only with no bg so the strip blends into the terminal background.
52
63
  */
53
- join(left: T | null, right: T | null): Renderable;
64
+ join(left: T | null, right: T | null, context: JoinContext): Renderable;
54
65
  }
66
+ /**
67
+ * The owner every cell a strip's joiner draws is stamped with
68
+ * (`Segment.anchorLines`), whatever the joiner: a seam is told by what drew
69
+ * it, never by its glyph, which an ASCII joiner draws otherwise and a lead may
70
+ * not draw at all. An effect reads it to leave a seam out of the words it
71
+ * keeps legible (`drawnOf`, `../renderables/effect.ts`).
72
+ *
73
+ * Inside it, every cell a `CellJoiner` draws names whose colour each of its
74
+ * two sides shows (`colorsOwnedBy`). One seam cell can show two neighbours —
75
+ * a powerline arrow is inked in the fill it points out of, over the fill it
76
+ * points into — so a cell has no single owner; each side has one.
77
+ */
78
+ export declare const JOIN: object;
79
+ /**
80
+ * Which of a cell's two colours on screen are `owner`'s: both, for a cell
81
+ * `owner` drew, itself or through an owner nested in its output; for a cell a
82
+ * `CellJoiner` drew, the sides shown in `owner`'s colour.
83
+ */
84
+ export declare function colorsOwnedBy(anchor: Anchor | undefined, owner: object): {
85
+ readonly fg: boolean;
86
+ readonly bg: boolean;
87
+ };
88
+ /**
89
+ * [LAW:single-enforcer] What `joiner` draws at one join, every cell stamped
90
+ * as `JOIN`'s: the one way `Strip` and `FlexStrip` draw a join.
91
+ */
92
+ export declare function drawJoin<T extends StyledRenderable>(joiner: Joiner<T>, left: T | null, right: T | null, context: JoinContext): Renderable;
93
+ /**
94
+ * [LAW:single-enforcer] What `item` draws, every cell stamped as the item's,
95
+ * so whoever holds the composed row reads which item drew a cell however the
96
+ * row was laid out or wrapped: the one way `Strip` and `FlexStrip` draw an
97
+ * item.
98
+ */
99
+ export declare function drawItem(item: StyledRenderable): Renderable;
55
100
  export declare class Strip<T extends StyledRenderable = StyledRenderable> implements Renderable, Measurable {
56
101
  readonly items: readonly T[];
57
102
  readonly joiner: Joiner<T>;
@@ -70,83 +115,121 @@ export declare class Strip<T extends StyledRenderable = StyledRenderable> implem
70
115
  };
71
116
  }
72
117
  /**
73
- * The least ΔE_OK two neighbouring backgrounds must differ by for the powerline
74
- * arrow between them to be seen. Below it the arrow is drawn in a colour the
75
- * eye cannot tell from its own background, so the joiner draws the divider
76
- * instead. Twice the ~.02 threshold of a visible difference, because a seam is
77
- * one cell wide.
118
+ * A colour a joiner's cell is drawn in. Each variant names where the colour
119
+ * comes from when the join is drawn:
120
+ * • an `edge` — a neighbour's ground (`bg`) or text (`fg`) at the column
121
+ * facing the join, read through `StyledRenderable.edgeStyle`;
122
+ * • a `role` — a style name, resolved against the render's theme, whose
123
+ * foreground colour is the colour;
124
+ * • a `mix` — two colours blended at `t` (0 is the first, 1 the second).
78
125
  */
79
- export declare const SEAM_MIN_DELTA_E = 0.04;
80
- export interface PowerlineJoinerOptions {
81
- /** Glyph for every join between two coloured items. */
82
- glyph: string;
83
- /**
84
- * Glyph drawn between neighbours whose backgrounds the eye cannot tell apart,
85
- * in the left item's text colour — the arrow itself would vanish into the
86
- * shared background.
87
- */
88
- divider: string;
89
- /**
90
- * Glyph for every join a coloured item is entered from nothing — the strip's
91
- * start, or a colourless left neighbour — painted in the right item's
92
- * background. `""` begins a coloured run flat.
93
- */
94
- lead: string;
95
- /**
96
- * Glyph for every join a coloured item leaves into nothing — the strip's end,
97
- * or a colourless right neighbour — painted in the left item's background.
98
- * `""` ends a coloured run flat.
99
- */
100
- tail: string;
101
- }
126
+ export type Paint = {
127
+ readonly edge: "left" | "right";
128
+ readonly part: "bg" | "fg";
129
+ } | {
130
+ readonly role: string;
131
+ } | {
132
+ readonly mix: readonly [Paint, Paint, number];
133
+ };
102
134
  /**
103
- * The powerline set: U+E0B0 (right-arrow) divided by U+E0B1 (thin right-arrow),
104
- * led by U+E0D7 (Nerd Fonts ple-left_hard_divider_inverse, the right-arrow's
105
- * inverse) and tailed by the arrow itself. The lead leaves empty a triangle
106
- * whose base is its cell's left edge and whose point touches the first item, so
107
- * the run opens notched — as if an arrow before it pointed in — rather than
108
- * with a shape pointing out. The notch is the terminal's own background showing
109
- * through, never a colour painted to imitate it, so it matches under a
110
- * translucent terminal background too. The lead is a Powerline Extra glyph: a
111
- * classic powerline font lacks it.
112
- */
113
- export declare const POWERLINE_JOINER_GLYPHS: Readonly<PowerlineJoinerOptions>;
114
- export declare class PowerlineJoiner<T extends StyledRenderable = StyledRenderable> implements Joiner<T> {
115
- private readonly _glyphs;
116
- constructor(options?: PowerlineJoinerOptions);
117
- join(left: T | null, right: T | null): Renderable;
118
- }
119
- export interface CapsuleJoinerOptions {
120
- /** Left-cap glyph (default: U+E0B6, powerline rounded left). */
121
- left?: string;
122
- /** Right-cap glyph (default: U+E0B4, powerline rounded right). */
123
- right?: string;
124
- /** Separator inserted between adjacent capsules in the middle position. */
125
- separator?: string;
126
- }
127
- export declare class CapsuleJoiner<T extends StyledRenderable = StyledRenderable> implements Joiner<T> {
128
- private readonly _caps;
129
- private readonly _separator;
130
- constructor(options?: CapsuleJoinerOptions);
131
- _emit(left: T | null, right: T | null, options: RenderOptions): Iterable<Segment>;
132
- join(left: T | null, right: T | null): Renderable;
133
- }
134
- export interface PlainJoinerOptions {
135
- separator?: string;
136
- style?: Style;
137
- }
138
- export declare class PlainJoiner<T extends StyledRenderable = StyledRenderable> implements Joiner<T> {
139
- private readonly _separator;
140
- private readonly _style;
141
- constructor(options?: PlainJoinerOptions);
142
- join(left: T | null, right: T | null): Renderable;
135
+ * A `Paint`, or `"ground"`: the terminal's own background, whose colour nobody
136
+ * knows. That is why it is never mixed (`Paint` excludes it), and why a cell
137
+ * may put it on one side only. As a cell's `fg` it is drawn in reverse video —
138
+ * the glyph's ink shows the terminal's background through a cell filled with
139
+ * the `bg` colour — so an inverted shape is the same glyph, never a glyph of
140
+ * its own.
141
+ */
142
+ export type CellColor = Paint | "ground";
143
+ /**
144
+ * One styled run of a join. A `oneOf` glyph is a set any member of which may
145
+ * stand in the cell; every member has the same width, because consumers
146
+ * measure a join by rendering it. Which member stands is hashed from the
147
+ * join's part, its `index` and the cell's place in it, so it holds still from
148
+ * frame to frame while the items before it do, and differs from seam to seam
149
+ * even between the same two colours.
150
+ */
151
+ export interface JoinCell {
152
+ readonly glyph: string | {
153
+ readonly oneOf: readonly string[];
154
+ };
155
+ readonly fg: CellColor;
156
+ readonly bg: CellColor;
143
157
  }
144
- export interface GradientJoinerOptions {
145
- /** Number of cells between adjacent items (default: 4). */
146
- steps?: number;
158
+ /**
159
+ * The cells a joiner draws at each kind of join:
160
+ * • `seam` — between two neighbours;
161
+ * • `divider` — in the seam's place where every seam cell's ink is drawn
162
+ * indistinct from its own ground (see `SEAM_MIN_DELTA_E`), so the seam
163
+ * would vanish;
164
+ * the same width as `seam`;
165
+ * • `lead` — where a run is entered from nothing: the strip's start, or a
166
+ * neighbour with no ground for the seam to paint. It cannot name `left`;
167
+ * • `tail` — where a run leaves into nothing. It cannot name `right`.
168
+ */
169
+ export interface JoinShape {
170
+ readonly seam: readonly JoinCell[];
171
+ readonly divider: readonly JoinCell[];
172
+ readonly lead: readonly JoinCell[];
173
+ readonly tail: readonly JoinCell[];
147
174
  }
148
- export declare class GradientJoiner<T extends StyledRenderable = StyledRenderable> implements Joiner<T> {
149
- private readonly _steps;
150
- constructor(options?: GradientJoinerOptions);
151
- join(left: T | null, right: T | null): Renderable;
175
+ /**
176
+ * The least ΔE_OK a seam cell's ink must differ from its own ground by for the
177
+ * seam to be seen. Below it the eye cannot tell the ink from the ground,
178
+ * so the joiner draws the divider instead. Twice the ~.02 threshold of a visible difference, because a seam is
179
+ * one cell wide.
180
+ */
181
+ export declare const SEAM_MIN_DELTA_E = 0.04;
182
+ /**
183
+ * The one joiner: what it draws at each join is the `JoinShape` it is given,
184
+ * so a new joiner is a value, never a class.
185
+ *
186
+ * Which part a join draws is read off its two neighbours. A neighbour is
187
+ * missing at the strip's ends, and counts as missing — an endpoint — when the
188
+ * shape paints with its ground anywhere and it has none to paint. With both present the
189
+ * join is the seam, or the divider where every seam cell's ink is drawn
190
+ * indistinct from its ground at `options.colorSystem`; with only the right, the lead; with only
191
+ * the left, the tail; with neither, nothing.
192
+ *
193
+ * `ascii` is the shape an ASCII-only output draws instead, whole.
194
+ */
195
+ export declare class CellJoiner<T extends StyledRenderable = StyledRenderable> implements Joiner<T> {
196
+ readonly shape: JoinShape;
197
+ readonly ascii: JoinShape;
198
+ private readonly _forms;
199
+ constructor(shape: JoinShape, ascii: JoinShape);
200
+ join(left: T | null, right: T | null, { index }: JoinContext): Renderable;
152
201
  }
202
+ /**
203
+ * The bundled joiners, by name. What each draws is `docs/strip.md`'s
204
+ * "Built-in joiners"; a name from config is read with `joinerNamed`.
205
+ */
206
+ export declare const JOINERS: Readonly<{
207
+ powerline: CellJoiner<StyledRenderable>;
208
+ prism: CellJoiner<StyledRenderable>;
209
+ slant: CellJoiner<StyledRenderable>;
210
+ backslant: CellJoiner<StyledRenderable>;
211
+ flame: CellJoiner<StyledRenderable>;
212
+ pixel: CellJoiner<StyledRenderable>;
213
+ ice: CellJoiner<StyledRenderable>;
214
+ bubble: CellJoiner<StyledRenderable>;
215
+ capsule: CellJoiner<StyledRenderable>;
216
+ wrapper: CellJoiner<StyledRenderable>;
217
+ metro: CellJoiner<StyledRenderable>;
218
+ stitch: CellJoiner<StyledRenderable>;
219
+ torn: CellJoiner<StyledRenderable>;
220
+ plain: CellJoiner<StyledRenderable>;
221
+ }>;
222
+ /**
223
+ * The bundled joiner `name` names — a name read from config, parsed. Throws on
224
+ * any other string, naming the ones there are; an own-key test, so `toString`
225
+ * and the rest of `Object.prototype` are not joiners.
226
+ */
227
+ export declare function joinerNamed(name: string): CellJoiner;
228
+ /**
229
+ * A ramp of `steps` cells from the left ground to the right. Each cell is the
230
+ * half block U+258C, ink on its left half and ground on its right, so it
231
+ * carries two samples; ASCII draws a space, keeping the grounds alone. Nothing
232
+ * at the ends, or beside a neighbour with no ground — there is no colour to
233
+ * ramp toward.
234
+ */
235
+ export declare function gradientJoiner(steps?: number): CellJoiner;