@promptctl/rich-js 0.24.1 → 0.25.1

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 +24 -33
  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 +98 -29
  47. package/dist/core/strip.js +211 -150
  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 +158 -63
  73. package/dist/renderables/effect.js +378 -155
  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,7 +1,8 @@
1
1
  /**
2
2
  * The effect catalogue: shimmer, pulse, sparkle and wheel, which loop for as
3
- * long as they are drawn, and fade-in and dissolve-out, which run once and
4
- * are done. Each is an `Effect` for `Effected` (`./effect.ts`); the defaults
3
+ * long as they are drawn, fade-in and dissolve-out, which run once and are
4
+ * done, a blink and a bold pulse, which move an attribute on a beat, and a
5
+ * gradient, which lays a colour ramp across an element and may move it. Each is an `Effect` for `Effected` (`./effect.ts`); the defaults
5
6
  * in `EFFECT_CURVES` are the ones signed off by eye in the effects-feel demo
6
7
  * (`npm run effects-feel`), at 30 fps and at one frame a second, and
7
8
  * `EFFECT_CATALOGUE` makes every one of them at those, by name, one way.
@@ -13,7 +14,10 @@
13
14
  * One effect here is not ambience but a signal, and keeps none of this on
14
15
  * purpose: `steppedInk` steps its ink through colours on a beat, the news
15
16
  * that something is at its limit, and jumps from slot to slot where the
16
- * loops hold still. What makes the loops' motions familiar is what every
17
+ * loops hold still. Nor is `gradient` a light: it paints an ink rather than
18
+ * lighting it, so it may darken one, and a ramp scrolled across it jumps
19
+ * where the ramp wraps unless its ends are one colour. Of the list below it
20
+ * keeps the words. What makes the loops' motions familiar is what every
17
21
  * curve of theirs keeps:
18
22
  *
19
23
  * - Nothing jumps. Every curve is continuous in time, built from smooth
@@ -46,9 +50,11 @@
46
50
  * cards runs this file's own declarations as the program a visitor edits
47
51
  * (`examples/effects-playground/programs.ts`), on the published library.
48
52
  */
53
+ import { Animation } from "../core/animation.js";
49
54
  import { ColorRgba } from "../core/color.js";
50
- import { type Timing } from "../core/easing.js";
51
- import { type Drawn, type Effect, type EffectCell } from "./effect.js";
55
+ import { type Beat, type Timing } from "../core/easing.js";
56
+ import type { ColorRamp } from "../themes/ramp.js";
57
+ import { type CellAttributes, type Drawn, type Effect, type EffectCell } from "./effect.js";
52
58
  /** What a loop does to one colour at strength `w` in [0, 1]: at 0, nothing. */
53
59
  export type Touch = (color: ColorRgba, w: number) => ColorRgba;
54
60
  /**
@@ -98,6 +104,28 @@ export declare function shares({ pairs, depth, theme }: Drawn, colors: ReadonlyS
98
104
  * drawing what an earlier one drew costs no settling.
99
105
  */
100
106
  export declare function onColors(loop: Loop, colors?: ReadonlySet<string>): Effect;
107
+ /**
108
+ * A ramp laid across the element: each lit cell's ink is the colour `ramp`
109
+ * shows at `t` at the cell's column, the element's leftmost cell reading
110
+ * the ramp's first stop and its rightmost its last, each at its cell's
111
+ * centre — or, where that colour would not read on the cell's ground, the
112
+ * nearest that does (`legibleInks`, as `steppedInk` writes its steps). A
113
+ * ramp that moves (`ColorRamp.moving`) scrolls along the element and turns
114
+ * its hues, and the frame changes when the ramp does — every frame for a
115
+ * loop, never again once a tween settles; a still one is
116
+ * `Animation.constant(ramp)`. Lit cells are those whose ink is one of
117
+ * `colors`, named as a style names them (`"#a6e3a1"`, `"bright_green"`),
118
+ * opaque, and matched as the screen shows them at the frame's depth — so
119
+ * below truecolor every ink that lands on the same palette colour is lit —
120
+ * by default every colour the element sets itself — never an ink the terminal supplies: a
121
+ * rule's line by its colour and not its title, a panel's border and not its
122
+ * body. The element is where its frame lists
123
+ * cells, as the fireflies read it, so a padded or confined element has the
124
+ * ramp across what it shows. On a sixteen-colour terminal nothing moves
125
+ * (`stillOnSlots`): a gradient there is jumps between slots, and the cells
126
+ * hold as drawn.
127
+ */
128
+ export declare function gradient(ramp: Animation<ColorRamp>, colors?: readonly string[]): Effect;
101
129
  /**
102
130
  * A loop as an `Effect` on colours by hex, each touched at the share
103
131
  * `share` gives it of the cell's strength in a frame drawing what `Drawn`
@@ -115,6 +143,14 @@ export interface Curve extends Timing {
115
143
  /** How far the move goes at full intensity, in [0, 1]; what 1 means is the effect's. */
116
144
  readonly swing: number;
117
145
  }
146
+ /** Throws, naming the field, unless `curve` has a positive, finite `seconds` and a `swing` in [0, 1]. */
147
+ export declare function requireCurve(curve: Curve): void;
148
+ /**
149
+ * Throws, naming `what`, unless `z` is a finite place in the noise. Noise at
150
+ * a place that is not a number is not a number, which no effect could tell
151
+ * from a dim cell or an empty sky. [LAW:no-silent-failure]
152
+ */
153
+ export declare function requireZ(what: string, z: number): void;
118
154
  /**
119
155
  * Each effect's curve as it was signed off. Every loop's period is a prime
120
156
  * number of seconds, so no two loops come back into step within a sitting.
@@ -241,13 +277,48 @@ export declare function veiled(visibility: Visibility, swing: number): Effect;
241
277
  * draws it at the time since it began. `done(t)` is true from the moment
242
278
  * every cell has arrived or gone, so the caller knows when to stop drawing an
243
279
  * element that is leaving, or to drop the effect from one that has arrived.
244
- * Until then the effect's frame changes every frame, and from then never:
245
- * its `nextChange` is `done` read as a time. [LAW:one-source-of-truth]
280
+ *
281
+ * `schedule` is when its frame next changes on that clock, whatever the
282
+ * element draws: what a caller drawing the transition inside an animation —
283
+ * a lifecycle — says its frame does, since the frame it hands over carries
284
+ * no word of its own (`stampFrame`, `../core/animation.ts`). Until done it changes
285
+ * every frame, or on each hold of a beat (`onBeat`), and from then never.
286
+ * [LAW:one-source-of-truth] `done` is that schedule read as a fact — done
287
+ * from the first moment it never changes again — so no transition carries
288
+ * two answers to when it is over.
246
289
  */
247
- export interface Transition {
248
- readonly effect: Effect;
290
+ export declare class Transition<E = Effect> {
291
+ readonly effect: E;
292
+ readonly schedule: Animation<unknown>;
293
+ constructor(effect: E, schedule: Animation<unknown>);
249
294
  done(t: number): boolean;
250
295
  }
296
+ /**
297
+ * `effect` run once over `seconds` as a `Transition`: what it draws until it
298
+ * is done, then held. [LAW:single-enforcer] The one rule for when a
299
+ * transition is done and what it answers after, for a colour effect and a
300
+ * glyph effect (`./glyph-effects.ts`) alike.
301
+ */
302
+ export declare function transition<D, F>(seconds: number, effect: (drawn: D) => Animation<F>): Transition<(drawn: D) => Animation<F>>;
303
+ /**
304
+ * `effect` sampled and held on `beat`: drawn at the moment the hold in
305
+ * progress began (`Beat.lastChange`), so within a hold every frame is the frame
306
+ * at its start, and at each hold's start it moves on. A continuous effect
307
+ * given a short curve becomes one that steps — a `wheel` turning a sixth of
308
+ * a turn once a second — and at one redraw a second a hold shorter than a
309
+ * second is skipped, as frames are. [LAW:no-ambient-temporal-coupling] The
310
+ * held time is a function of `t`, so the same `t` draws the same bytes at
311
+ * any rate. The frame next changes at a hold's start, and only one the
312
+ * sampled effect has moved by (`Animation.onBeat`): an effect that moves
313
+ * every frame turns the beat at the end of this hold, and one that is done
314
+ * and says never leaves the beat saying never too.
315
+ *
316
+ * A transition steps the same way, its schedule with it, so a fade-in on a
317
+ * beat arrives a hold at a time and is done at the first hold that starts
318
+ * after it was: an element arriving through it wakes its host on the beats.
319
+ */
320
+ export declare function onBeat(effect: Effect, beat: Beat): Effect;
321
+ export declare function onBeat<E extends (drawn: never) => Animation<unknown>>(transition: Transition<E>, beat: Beat): Transition<E>;
251
322
  /**
252
323
  * Fade-in, as ink blooming in water: patches of the element surface first
253
324
  * and the rest follows outward from them, each cell rising smoothly over its
@@ -307,7 +378,8 @@ export interface ColorStep {
307
378
  * that does (`stillOnSlots`). A cell whose ground no offered colour reads
308
379
  * on keeps the ink it rested in.
309
380
  *
310
- * The search is settled once for each ink, ground and step, so a frame
381
+ * The search is settled once for each ground and step — below truecolor,
382
+ * which colours read on a ground once for that ground — so a frame
311
383
  * inside a step redoes none, and nor does a later pass of the beat: at sixty
312
384
  * frames a second a one-second step is sixty identical frames, and the
313
385
  * frame changes when the beat does: the signal is the beat mapped to inks.
@@ -315,9 +387,47 @@ export interface ColorStep {
315
387
  * nothing here reads a clock.
316
388
  */
317
389
  export declare function steppedInk(steps: readonly ColorStep[]): Effect;
390
+ /**
391
+ * A text attribute turned on and off on a beat: each pass, the cell as its
392
+ * element drew it for `off` seconds, then with `attribute` on for `on`.
393
+ */
394
+ export interface Blink {
395
+ readonly attribute: keyof CellAttributes;
396
+ readonly off: number;
397
+ readonly on: number;
398
+ }
399
+ /**
400
+ * `spec.attribute` blinking: off, the cell as drawn, so that hold's frame is
401
+ * the identity and writes the element's own bytes; on, the attribute set.
402
+ * It changes when its beat does, at a hold's end, and never between.
403
+ * A blink and a bold pulse are this one function at two specs
404
+ * (`ATTRIBUTE_DEFAULTS`) [LAW:one-type-per-behavior].
405
+ */
406
+ export declare function blink({ attribute, off, on }: Blink): Effect;
407
+ /** The names of the effects that move an attribute. */
408
+ export type AttributeLoopName = "blink" | "boldPulse";
409
+ /**
410
+ * Each attribute effect's spec: a blink hides the words for half of each
411
+ * second, as a terminal's own blink does, and a bold pulse holds them bold
412
+ * for the last three tenths of each second.
413
+ */
414
+ export declare const ATTRIBUTE_DEFAULTS: {
415
+ readonly blink: {
416
+ readonly attribute: "conceal";
417
+ readonly off: 0.5;
418
+ readonly on: 0.5;
419
+ };
420
+ readonly boldPulse: {
421
+ readonly attribute: "bold";
422
+ readonly off: 0.7;
423
+ readonly on: 0.3;
424
+ };
425
+ };
318
426
  /**
319
427
  * What a catalogue effect is made for: the element it is drawn on, at `z` in
320
- * the noise, so two elements under one effect do not move in lockstep. How
428
+ * the noise, so two elements under one effect drawn from noise do not move in
429
+ * lockstep. An effect on a beat alone (a blink) draws no noise, and keeps
430
+ * every element in step, as a terminal's own blink does. How
321
431
  * wide the element is, the effect reads off each frame (`Drawn.cells`).
322
432
  */
323
433
  export interface EffectTarget {
@@ -341,4 +451,5 @@ export type TransitionName = "fade" | "dissolve";
341
451
  export declare const EFFECT_CATALOGUE: {
342
452
  readonly loops: Readonly<Record<LoopName, (element: EffectTarget, curve?: Curve) => Effect>>;
343
453
  readonly transitions: Readonly<Record<TransitionName, (element: EffectTarget, curve?: Curve) => Transition>>;
454
+ readonly attributes: Readonly<Record<AttributeLoopName, (element: EffectTarget) => Effect>>;
344
455
  };