@promptctl/rich-js 0.24.1 → 0.25.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 (156) hide show
  1. package/README.md +7 -0
  2. package/dist/core/anchor.d.ts +5 -0
  3. package/dist/core/anchor.js +11 -4
  4. package/dist/core/animation.d.ts +175 -10
  5. package/dist/core/animation.js +283 -15
  6. package/dist/core/ansi.js +2 -2
  7. package/dist/core/box.d.ts +7 -7
  8. package/dist/core/cells.d.ts +23 -13
  9. package/dist/core/cells.js +58 -48
  10. package/dist/core/clock.d.ts +2 -2
  11. package/dist/core/clock.js +6 -4
  12. package/dist/core/color.d.ts +27 -10
  13. package/dist/core/color.js +21 -29
  14. package/dist/core/console.d.ts +28 -17
  15. package/dist/core/console.js +44 -39
  16. package/dist/core/easing.d.ts +30 -0
  17. package/dist/core/easing.js +65 -20
  18. package/dist/core/emoji.d.ts +1 -1
  19. package/dist/core/emoji.js +1 -2
  20. package/dist/core/export-html.js +2 -1
  21. package/dist/core/export-lines.js +3 -3
  22. package/dist/core/highlighter.d.ts +9 -8
  23. package/dist/core/highlighter.js +3 -2
  24. package/dist/core/json.js +2 -2
  25. package/dist/core/markup.js +16 -12
  26. package/dist/core/measure.js +2 -2
  27. package/dist/core/memo.d.ts +11 -2
  28. package/dist/core/memo.js +16 -0
  29. package/dist/core/oklch.js +17 -6
  30. package/dist/core/osc8.d.ts +1 -1
  31. package/dist/core/osc8.js +4 -5
  32. package/dist/core/paint.d.ts +2 -1
  33. package/dist/core/paint.js +4 -3
  34. package/dist/core/pattern.d.ts +21 -0
  35. package/dist/core/pattern.js +21 -0
  36. package/dist/core/pretty.js +9 -10
  37. package/dist/core/protocol.d.ts +100 -39
  38. package/dist/core/protocol.js +167 -21
  39. package/dist/core/render.d.ts +15 -2
  40. package/dist/core/render.js +25 -5
  41. package/dist/core/segment.d.ts +13 -5
  42. package/dist/core/segment.js +23 -9
  43. package/dist/core/spinnerData.d.ts +1 -1
  44. package/dist/core/state.d.ts +53 -0
  45. package/dist/core/state.js +82 -0
  46. package/dist/core/strip.d.ts +13 -16
  47. package/dist/core/strip.js +119 -110
  48. package/dist/core/style.d.ts +47 -14
  49. package/dist/core/style.js +57 -28
  50. package/dist/core/text.d.ts +5 -8
  51. package/dist/core/text.js +116 -124
  52. package/dist/core/timeline.d.ts +30 -5
  53. package/dist/core/timeline.js +43 -7
  54. package/dist/core/tween.d.ts +1 -1
  55. package/dist/core/tween.js +5 -3
  56. package/dist/core/view.d.ts +92 -0
  57. package/dist/core/view.js +83 -0
  58. package/dist/host/app.d.ts +49 -21
  59. package/dist/host/app.js +71 -37
  60. package/dist/host/input.js +3 -4
  61. package/dist/index.d.ts +24 -12
  62. package/dist/index.js +9 -4
  63. package/dist/node/traceback.js +4 -3
  64. package/dist/renderables/align.d.ts +2 -3
  65. package/dist/renderables/align.js +0 -3
  66. package/dist/renderables/change.d.ts +42 -0
  67. package/dist/renderables/change.js +112 -0
  68. package/dist/renderables/columns.d.ts +3 -4
  69. package/dist/renderables/columns.js +2 -7
  70. package/dist/renderables/constrain.d.ts +2 -3
  71. package/dist/renderables/constrain.js +0 -3
  72. package/dist/renderables/effect.d.ts +132 -54
  73. package/dist/renderables/effect.js +188 -115
  74. package/dist/renderables/effects.d.ts +122 -11
  75. package/dist/renderables/effects.js +238 -94
  76. package/dist/renderables/embed.d.ts +1 -1
  77. package/dist/renderables/embed.js +16 -8
  78. package/dist/renderables/flexStrip.d.ts +2 -3
  79. package/dist/renderables/flexStrip.js +0 -4
  80. package/dist/renderables/frames.d.ts +35 -54
  81. package/dist/renderables/frames.js +43 -58
  82. package/dist/renderables/glyph-effect.d.ts +158 -0
  83. package/dist/renderables/glyph-effect.js +237 -0
  84. package/dist/renderables/glyph-effects.d.ts +147 -0
  85. package/dist/renderables/glyph-effects.js +283 -0
  86. package/dist/renderables/group.d.ts +3 -4
  87. package/dist/renderables/group.js +0 -3
  88. package/dist/renderables/layout.d.ts +12 -12
  89. package/dist/renderables/layout.js +40 -46
  90. package/dist/renderables/lifecycle.d.ts +77 -0
  91. package/dist/renderables/lifecycle.js +132 -0
  92. package/dist/renderables/list-view.d.ts +4 -5
  93. package/dist/renderables/list-view.js +9 -13
  94. package/dist/renderables/live.d.ts +36 -21
  95. package/dist/renderables/live.js +88 -41
  96. package/dist/renderables/markdown-parse.d.ts +4 -4
  97. package/dist/renderables/markdown-parse.js +52 -46
  98. package/dist/renderables/markdown-url.js +11 -11
  99. package/dist/renderables/padding.d.ts +4 -5
  100. package/dist/renderables/padding.js +0 -3
  101. package/dist/renderables/panel.d.ts +14 -16
  102. package/dist/renderables/panel.js +6 -14
  103. package/dist/renderables/progress.d.ts +83 -34
  104. package/dist/renderables/progress.js +182 -95
  105. package/dist/renderables/progressBar.d.ts +22 -12
  106. package/dist/renderables/progressBar.js +32 -9
  107. package/dist/renderables/prompt.js +3 -2
  108. package/dist/renderables/python-space.js +2 -1
  109. package/dist/renderables/scroll.d.ts +50 -0
  110. package/dist/renderables/scroll.js +106 -0
  111. package/dist/renderables/spinner.d.ts +35 -14
  112. package/dist/renderables/spinner.js +65 -25
  113. package/dist/renderables/status.js +1 -1
  114. package/dist/renderables/syntax.d.ts +10 -9
  115. package/dist/renderables/syntax.js +3 -2
  116. package/dist/renderables/table.d.ts +34 -40
  117. package/dist/renderables/table.js +41 -63
  118. package/dist/renderables/traceback.d.ts +2 -2
  119. package/dist/renderables/traceback.js +6 -5
  120. package/dist/renderables/tree.d.ts +27 -25
  121. package/dist/renderables/tree.js +104 -58
  122. package/dist/renderables/viewport.d.ts +75 -44
  123. package/dist/renderables/viewport.js +145 -82
  124. package/dist/template-bindings/animation-funcs.d.ts +78 -9
  125. package/dist/template-bindings/animation-funcs.js +132 -14
  126. package/dist/template-bindings/index.d.ts +5 -5
  127. package/dist/template-bindings/index.js +5 -5
  128. package/dist/themes/ramp.d.ts +46 -3
  129. package/dist/themes/ramp.js +61 -4
  130. package/dist/themes/registry.js +5 -7
  131. package/dist/widgets/button.js +3 -2
  132. package/dist/widgets/checkbox.js +4 -3
  133. package/dist/widgets/dropdown.d.ts +3 -1
  134. package/dist/widgets/dropdown.js +20 -15
  135. package/dist/widgets/event-router.js +4 -2
  136. package/dist/widgets/focus-manager.d.ts +2 -0
  137. package/dist/widgets/focus-manager.js +6 -4
  138. package/dist/widgets/hit.d.ts +6 -0
  139. package/dist/widgets/hit.js +8 -1
  140. package/dist/widgets/observable.d.ts +23 -0
  141. package/dist/widgets/observable.js +43 -0
  142. package/dist/widgets/slider.d.ts +1 -1
  143. package/dist/widgets/slider.js +12 -3
  144. package/dist/widgets/static-item.d.ts +2 -3
  145. package/dist/widgets/static-item.js +0 -3
  146. package/dist/widgets/text-input.d.ts +28 -32
  147. package/dist/widgets/text-input.js +360 -346
  148. package/dist/widgets/themed-widget.js +2 -1
  149. package/dist/widgets/toggle.js +4 -3
  150. package/dist/widgets/types.d.ts +10 -4
  151. package/dist/widgets/types.js +8 -2
  152. package/dist/widgets/widget-app.d.ts +14 -4
  153. package/dist/widgets/widget-app.js +36 -7
  154. package/dist/widgets/widget-base.d.ts +2 -2
  155. package/dist/widgets/widget-base.js +29 -18
  156. package/package.json +8 -1
@@ -1,20 +1,28 @@
1
1
  /**
2
- * Effected — a renderable whose finished cells' colours pass through an
3
- * effect at a moment `t`.
2
+ * Effected — a renderable whose finished cells' looks — colours and text
3
+ * attributes — pass through an effect at a moment `t`.
4
4
  *
5
5
  * An effect is, for what an element draws in a frame, an `Animation`
6
6
  * (`core/animation.ts`) of what is done to its cells: its value at `t` is a
7
- * function from a cell's colours and where the cell is to the cell's new
8
- * colours (`EffectFrame`), and it says when that next changes as every
7
+ * function from a cell's look and where the cell is to the cell's new look
8
+ * (`EffectFrame`), and it says when that next changes as every
9
9
  * animation does. Whatever holds for the whole frame is worked out once, in
10
10
  * the effect and its `at(t)`, and every cell of the frame is handed to the
11
11
  * function `at(t)` returns, but for those a wrapper keeps back: `confined`
12
12
  * hands over only the cells its owners drew, so an effect never counts on
13
- * seeing them all. Shimmer, pulse, fade and dissolve are all this one shape,
14
- * differing by what the function does with its inputs
15
- * [LAW:one-type-per-behavior]; two effects stack by nesting one wrapper in
16
- * another, which is the same as calling one after the other but for what the
17
- * outer one measures: the inner one's output.
13
+ * seeing them all. Shimmer, pulse, fade, dissolve and a blinking attribute
14
+ * are all this one shape, differing by what the function does with its
15
+ * inputs [LAW:one-type-per-behavior]; two effects stack by nesting one
16
+ * wrapper in another, which is the same as calling one after the other but
17
+ * for what the outer one measures: the inner one's output.
18
+ *
19
+ * A cell's look is one value, its colours and its attributes together
20
+ * (`CellLook`), rather than an attribute stage beside the colour one, so
21
+ * everything that takes an `Effect` — `confined`, `onBeat`,
22
+ * `Animation.all`, nesting over a glyph effect — takes one that moves
23
+ * attributes with no second copy of itself. `reverse` is the one attribute
24
+ * a look leaves out (`CellAttributes`): it decides which of a style's slots
25
+ * a colour on screen is in, and a swap of the two is already a colour move.
18
26
  *
19
27
  * What the element draws (`Drawn`) — the cells the effect will be handed,
20
28
  * and the colours of its words — is measured here, in the render, off the
@@ -23,10 +31,12 @@
23
31
  * against (`onColors`, `./effects.ts`), so no caller derives it a second time
24
32
  * from a render of its own.
25
33
  *
26
- * [LAW:no-ambient-temporal-coupling] `t` is a constructor argument, not a
27
- * clock read. Whoever draws frames builds the view for each frame's `t`, so
28
- * the same `t` always draws the same bytes, at 30 frames a second or one
29
- * every two seconds.
34
+ * An `Effected` is the element under its effect over time: an
35
+ * `Animation<Renderable>`, placed wherever a renderable goes and drawn at
36
+ * the time of the frame it is drawn in. Its value at `t` is the element
37
+ * through the effect at `t` (`Recolored`). [LAW:no-ambient-temporal-coupling]
38
+ * The time is the frame's, never a clock read, so the same time always draws
39
+ * the same bytes, at 30 frames a second or one every two seconds.
30
40
  *
31
41
  * What an effect may not do is the contract this module holds:
32
42
  *
@@ -36,26 +46,30 @@
36
46
  * segment's link and meta and carries its anchor shifted to the run's first
37
47
  * cell (`Style.shiftedBy`), so hit testing still finds the owner.
38
48
  * - A cell whose colours come back unchanged keeps its original `ColorSpec`,
39
- * and a segment whose every cell is unchanged is yielded with its look as
40
- * it was, so the identity effect is byte-identical; what it gains is when
41
- * the frame next changes (`Style.nextChange`), which writes no byte.
49
+ * one whose attributes come back as its style set them keeps them, and a
50
+ * segment whose every cell is unchanged is yielded with its look as
51
+ * it was, so the identity effect is byte-identical; what an `Effected` gains is when
52
+ * the frame next changes (`Style.hold`), which writes no byte.
42
53
  * Neighbouring cells the output depth
43
54
  * writes alike stay one segment: a segment is cut only where the written
44
- * colours change, so two colours that land on one index are one run.
55
+ * colours or the attributes change, so two colours that land on one index
56
+ * are one run.
45
57
  * - New colours are built with `ColorSpec.fromRgba`, never parsed from a
46
58
  * string, so no frame adds an entry to a parse cache.
47
- * - With no colour output (`colorSystem: null`) there is nothing for an
48
- * effect to change, and the child's segments pass through untouched.
59
+ * - With no colour output (`colorSystem: null`) no style is written at all,
60
+ * attributes included, so there is nothing for an effect to change, and
61
+ * the child's segments pass through untouched.
49
62
  *
50
63
  * Positions are the child's own: row and column count from the top-left of
51
64
  * what the child drew, so a sweep crosses the element, not the screen.
52
65
  */
53
66
  import { type Anchor } from "../core/anchor.js";
54
67
  import { Animation } from "../core/animation.js";
68
+ import type { Hold } from "../core/style.js";
55
69
  import { ColorDepth, type ColorRgba, type TerminalTheme } from "../core/color.js";
56
- import type { Beat } from "../core/easing.js";
57
- import type { Composite, Measurable, Renderable, RenderOptions } from "../core/protocol.js";
70
+ import type { Measurable, Renderable, RenderOptions } from "../core/protocol.js";
58
71
  import { Segment } from "../core/segment.js";
72
+ import { type Attributes } from "../core/style.js";
59
73
  /**
60
74
  * A cell's foreground and background as they appear on screen — the glyph's
61
75
  * colour and the colour behind it — which are the colours an effect moves.
@@ -65,6 +79,16 @@ export interface CellColors {
65
79
  readonly fg: ColorRgba;
66
80
  readonly bg: ColorRgba;
67
81
  }
82
+ /**
83
+ * The text attributes an effect moves: every one a style sets but
84
+ * `reverse`, each on, off or unset as the cell's style has it. An unset
85
+ * one lets a style laid beneath show through, as it does undrawn.
86
+ */
87
+ export type CellAttributes = Omit<Attributes, "reverse">;
88
+ /** What an effect moves in a cell: its colours as the screen shows them, and its attributes. */
89
+ export interface CellLook extends CellColors {
90
+ readonly attributes: CellAttributes;
91
+ }
68
92
  /**
69
93
  * Where a cell is in the output of the renderable an effect wraps, its seed:
70
94
  * a number in [0, 1) that is the same for that cell on every frame, for an
@@ -141,8 +165,8 @@ export interface Drawn {
141
165
  /** The terminal the frame is drawn on. */
142
166
  readonly theme: TerminalTheme;
143
167
  }
144
- /** What an effect does to the cells of one frame: each cell's colours and where it is in, its colours out. Return `colors` to leave a cell be. */
145
- export type EffectFrame = (colors: CellColors, cell: EffectCell) => CellColors;
168
+ /** What an effect does to the cells of one frame: each cell's look and where it is in, its look out. Return `look` to leave a cell be. */
169
+ export type EffectFrame = (look: CellLook, cell: EffectCell) => CellLook;
146
170
  /**
147
171
  * For an element drawing `drawn`, the animation of what is done to its cells.
148
172
  * [LAW:types-are-the-program] Per-frame work is `at(t)`, so it runs once a
@@ -159,8 +183,6 @@ export type EffectFrame = (colors: CellColors, cell: EffectCell) => CellColors;
159
183
  */
160
184
  export type Effect = (drawn: Drawn) => Animation<EffectFrame>;
161
185
  export interface EffectedOptions {
162
- /** The moment to draw, in seconds. */
163
- readonly t: number;
164
186
  /**
165
187
  * Names the element for its seeds, so two elements showing the same text do
166
188
  * not twinkle in lockstep. The same key gives the same seeds on every frame.
@@ -173,21 +195,71 @@ export interface EffectedOptions {
173
195
  */
174
196
  readonly theme: TerminalTheme;
175
197
  }
176
- export declare class Effected implements Renderable, Measurable, Composite {
198
+ /** A frame an effect drew at a moment, and the hold the effect says it is in there. */
199
+ export interface Moved {
200
+ readonly segments: Iterable<Segment>;
201
+ readonly hold: Hold;
202
+ }
203
+ /**
204
+ * An `Effected` at `t`, or an element through an effect at a time an
205
+ * animation's `at` was handed — a lifecycle's time since it entered: `renderable`
206
+ * with its cells' looks passed through `effect` at `t`, saying nothing of
207
+ * when that changes, since whatever placed the animation stamps its hold.
208
+ * [LAW:one-type-per-behavior]
209
+ */
210
+ export declare class Recolored implements Renderable, Measurable {
177
211
  readonly renderable: Renderable;
178
212
  readonly effect: Effect;
179
213
  readonly t: number;
180
214
  readonly key: string;
181
215
  readonly theme: TerminalTheme;
182
- constructor(renderable: Renderable, effect: Effect, options: EffectedOptions);
216
+ constructor(renderable: Renderable, effect: Effect, options: EffectedOptions & {
217
+ readonly t: number;
218
+ });
183
219
  render(options: RenderOptions): Iterable<Segment>;
184
- contents(): Iterable<Renderable>;
185
- private _moved;
220
+ /** The frame the effect draws at `t`, and the hold it says that is in. */
221
+ moved(options: RenderOptions): Moved;
186
222
  private _recolored;
187
223
  measure(options: RenderOptions): {
188
224
  minimum: number;
189
225
  maximum: number;
190
226
  };
227
+ /**
228
+ * The specs that draw a cell's slot colours `to` where the segment drew
229
+ * `from` with `wire`: each moved slot in the spec `movedSpecs` writes it
230
+ * in, the rest as `wire` wrote them.
231
+ */
232
+ private respec;
233
+ }
234
+ /**
235
+ * `renderable` under `effect` over time: an `Animation<Renderable>` whose
236
+ * value at `t` is the element through the effect at `t`, placed wherever a
237
+ * renderable goes. Its own answer to when it changes is `t`, at every time:
238
+ * an `Effect` is made from what the element draws, so with nothing drawn
239
+ * nothing can say more — early, never false. Placed, it says exactly: its
240
+ * cells carry the effect's own hold at the frame's time and the output's
241
+ * depth (`stampFrame`), under whatever the element already said, so at a
242
+ * depth that shows no motion a loop says it never changes there and the
243
+ * host sleeps.
244
+ */
245
+ export declare class Effected implements Animation<Renderable> {
246
+ readonly renderable: Renderable;
247
+ readonly effect: Effect;
248
+ readonly key: string;
249
+ readonly theme: TerminalTheme;
250
+ constructor(renderable: Renderable, effect: Effect, options: EffectedOptions);
251
+ /** The element through the effect at `t`, unstamped. */
252
+ at(t: number): Recolored;
253
+ nextChange(t: number): number;
254
+ lastChange(t: number): number;
255
+ /** The element under the effect with its motion taken out. */
256
+ reduced(): Effected;
257
+ /** Drawn at the frame's time, its cells stamped with the effect's exact hold there. */
258
+ render(options: RenderOptions): Iterable<Segment>;
259
+ measure(options: RenderOptions): {
260
+ minimum: number;
261
+ maximum: number;
262
+ };
191
263
  /**
192
264
  * The colours the screen shows for `pair` once it is drawn moved to `to`,
193
265
  * both as the screen shows them, at `depth` on `theme`: what an effect
@@ -196,34 +268,34 @@ export declare class Effected implements Renderable, Measurable, Composite {
196
268
  * moved slot is written with.
197
269
  */
198
270
  static shows(pair: Pair, to: CellColors, depth: ColorDepth, theme: TerminalTheme): CellColors;
199
- /**
200
- * The specs that draw a cell's slot colours `to` where the segment drew
201
- * `from` with `wire`: each moved slot in the spec `movedSpecs` writes it
202
- * in, the rest as `wire` wrote them.
203
- */
204
- private respec;
205
- /** A cell's seed: FNV-1a of the key and the position, scaled into [0, 1). */
206
- private seed;
207
271
  }
208
272
  /**
209
- * `effect` sampled and held on `beat`: drawn at the moment the hold in
210
- * progress began (`Beat.lastChange`), so within a hold every frame is the frame
211
- * at its start, and at each hold's start it moves on. A continuous effect
212
- * given a short curve becomes one that steps — a `wheel` turning a sixth of
213
- * a turn once a second — and at one redraw a second a hold shorter than a
214
- * second is skipped, as frames are. [LAW:no-ambient-temporal-coupling] The
215
- * held time is a function of `t`, so the same `t` draws the same bytes at
216
- * any rate. The frame next changes at a hold's start, and only one the
217
- * sampled effect has moved by: the first hold start at or after what it
218
- * answers for the frame held now (`Beat.nextChange`). An effect that moves
219
- * every frame makes the beat's own answer, the end of this hold; one that is
220
- * done and says never leaves the beat saying never too, since the hold after
221
- * this one would draw the same frame. The answer is read off what the effect
222
- * says, never off a comparison of frames: an effect that steps and is back
223
- * on the same colour by the next hold still turns the beat there, an early
224
- * answer the contract allows.
273
+ * A cell's seed: FNV-1a of the element's key and the cell's position, scaled
274
+ * into [0, 1). [LAW:one-source-of-truth] One rule for a colour effect's seeds
275
+ * and a glyph effect's, so one element under both twinkles from one seed.
276
+ */
277
+ export declare function cellSeed(key: string, row: number, col: number): number;
278
+ /** A glyph of a segment, placed where its cell is drawn — or none for a newline, which is no cell. */
279
+ export interface WalkedGlyph {
280
+ readonly glyph: string;
281
+ readonly cell: Placed | undefined;
282
+ }
283
+ /**
284
+ * Each glyph of each of `segments`, where its cell sits: rows and columns
285
+ * from the top-left of the output, a wide glyph one cell at its first
286
+ * column, and its anchor shifted to that column as `Style.shiftedBy` shifts
287
+ * a run's. A control segment draws nothing and has none.
288
+ * [LAW:one-source-of-truth] The one walk: what `Drawn.cells` lists, what the
289
+ * render hands a colour effect, and what a glyph effect (`./glyph-effect.ts`)
290
+ * is handed are all read off it.
291
+ */
292
+ export declare function walkGlyphs(segments: readonly Segment[]): (readonly WalkedGlyph[])[];
293
+ /**
294
+ * Whether `text` draws ink: anything but blanks. [LAW:one-source-of-truth]
295
+ * The one test, so the words a colour effect lights are the words a glyph
296
+ * effect (`./glyph-effects.ts`) scrambles and its particles pass behind.
225
297
  */
226
- export declare function onBeat(effect: Effect, beat: Beat): Effect;
298
+ export declare function inked(text: string): boolean;
227
299
  /**
228
300
  * `effect` on the colours any of `owners` drew, itself or through an owner
229
301
  * nested in its output, and every other colour left as it is: one item of a
@@ -242,3 +314,9 @@ export declare function confined(effect: Effect, ...owners: readonly object[]):
242
314
  * output under an effect to read the contrast its words are left at.
243
315
  */
244
316
  export declare function drawnOf(segments: Iterable<Segment>, depth: ColorDepth, theme: TerminalTheme): Drawn;
317
+ /**
318
+ * The attributes a look carries, read off anything that sets them — a
319
+ * `Style`, or a look a frame returned with more on it than `CellAttributes`
320
+ * names. [LAW:one-source-of-truth] The one place `reverse` is left out.
321
+ */
322
+ export declare function cellAttributes(of: CellAttributes): CellAttributes;