@promptctl/rich-js 0.18.1 → 0.20.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 (169) hide show
  1. package/README.md +11 -8
  2. package/dist/core/box.d.ts +3 -1
  3. package/dist/core/box.js +6 -13
  4. package/dist/core/cells.d.ts +61 -28
  5. package/dist/core/cells.js +171 -124
  6. package/dist/core/clock.d.ts +48 -0
  7. package/dist/core/clock.js +42 -0
  8. package/dist/core/color.d.ts +99 -18
  9. package/dist/core/color.js +334 -146
  10. package/dist/core/console.d.ts +38 -7
  11. package/dist/core/console.js +159 -90
  12. package/dist/core/easing.d.ts +86 -0
  13. package/dist/core/easing.js +171 -0
  14. package/dist/core/env.d.ts +16 -0
  15. package/dist/core/env.js +16 -0
  16. package/dist/core/export-html.js +1 -4
  17. package/dist/core/export-lines.d.ts +22 -13
  18. package/dist/core/export-lines.js +37 -19
  19. package/dist/core/export-svg.d.ts +49 -0
  20. package/dist/core/export-svg.js +213 -0
  21. package/dist/core/fnv1a.d.ts +10 -0
  22. package/dist/core/fnv1a.js +17 -0
  23. package/dist/core/highlighter.d.ts +2 -2
  24. package/dist/core/highlighter.js +113 -47
  25. package/dist/core/json.js +1 -1
  26. package/dist/core/markup.d.ts +28 -7
  27. package/dist/core/markup.js +235 -312
  28. package/dist/core/measure.d.ts +3 -3
  29. package/dist/core/measure.js +12 -7
  30. package/dist/core/memo.d.ts +19 -0
  31. package/dist/core/memo.js +34 -0
  32. package/dist/core/noise.d.ts +31 -0
  33. package/dist/core/noise.js +94 -0
  34. package/dist/core/osc8.d.ts +6 -6
  35. package/dist/core/osc8.js +9 -21
  36. package/dist/core/paint.d.ts +107 -0
  37. package/dist/core/paint.js +161 -0
  38. package/dist/core/place.d.ts +1 -1
  39. package/dist/core/place.js +4 -6
  40. package/dist/core/pretty.d.ts +126 -2
  41. package/dist/core/pretty.js +571 -105
  42. package/dist/core/protocol.d.ts +43 -3
  43. package/dist/core/protocol.js +23 -2
  44. package/dist/core/render.d.ts +33 -30
  45. package/dist/core/render.js +43 -83
  46. package/dist/core/segment.d.ts +6 -5
  47. package/dist/core/segment.js +11 -15
  48. package/dist/core/selection.d.ts +12 -0
  49. package/dist/core/selection.js +14 -0
  50. package/dist/core/strip.d.ts +116 -74
  51. package/dist/core/strip.js +266 -217
  52. package/dist/core/style.d.ts +27 -7
  53. package/dist/core/style.js +106 -41
  54. package/dist/core/text.d.ts +43 -16
  55. package/dist/core/text.js +180 -59
  56. package/dist/core/wrap.d.ts +5 -0
  57. package/dist/core/wrap.js +16 -3
  58. package/dist/host/app.d.ts +95 -17
  59. package/dist/host/app.js +201 -61
  60. package/dist/host/index.d.ts +4 -1
  61. package/dist/host/index.js +1 -0
  62. package/dist/host/input.d.ts +84 -0
  63. package/dist/host/input.js +498 -0
  64. package/dist/host/terminal-host.d.ts +15 -2
  65. package/dist/host/terminal-host.js +2 -0
  66. package/dist/index.d.ts +26 -14
  67. package/dist/index.js +17 -7
  68. package/dist/node/prompt.d.ts +13 -0
  69. package/dist/node/prompt.js +30 -9
  70. package/dist/node/save.d.ts +4 -3
  71. package/dist/node/save.js +6 -3
  72. package/dist/node/terminal-host.d.ts +10 -2
  73. package/dist/node/terminal-host.js +7 -0
  74. package/dist/node/traceback.d.ts +2 -1
  75. package/dist/node/traceback.js +3 -39
  76. package/dist/renderables/align.js +2 -9
  77. package/dist/renderables/columns.d.ts +45 -29
  78. package/dist/renderables/columns.js +142 -103
  79. package/dist/renderables/constrain.js +6 -12
  80. package/dist/renderables/effect.d.ts +113 -0
  81. package/dist/renderables/effect.js +182 -0
  82. package/dist/renderables/effects.d.ts +252 -0
  83. package/dist/renderables/effects.js +565 -0
  84. package/dist/renderables/embed.d.ts +94 -31
  85. package/dist/renderables/embed.js +141 -45
  86. package/dist/renderables/group.d.ts +6 -3
  87. package/dist/renderables/group.js +5 -0
  88. package/dist/renderables/layout.d.ts +6 -23
  89. package/dist/renderables/layout.js +24 -113
  90. package/dist/renderables/list-view.d.ts +42 -0
  91. package/dist/renderables/list-view.js +78 -0
  92. package/dist/renderables/live.d.ts +40 -16
  93. package/dist/renderables/live.js +96 -83
  94. package/dist/renderables/markdown.d.ts +16 -2
  95. package/dist/renderables/markdown.js +521 -118
  96. package/dist/renderables/padding.d.ts +22 -1
  97. package/dist/renderables/padding.js +30 -24
  98. package/dist/renderables/panel.d.ts +31 -33
  99. package/dist/renderables/panel.js +137 -141
  100. package/dist/renderables/progress.d.ts +110 -16
  101. package/dist/renderables/progress.js +212 -81
  102. package/dist/renderables/progressBar.d.ts +24 -4
  103. package/dist/renderables/progressBar.js +78 -23
  104. package/dist/renderables/prompt.d.ts +37 -15
  105. package/dist/renderables/prompt.js +125 -85
  106. package/dist/renderables/ratio.d.ts +123 -0
  107. package/dist/renderables/ratio.js +213 -0
  108. package/dist/renderables/rule.d.ts +3 -2
  109. package/dist/renderables/rule.js +50 -52
  110. package/dist/renderables/spinner.d.ts +28 -2
  111. package/dist/renderables/spinner.js +52 -19
  112. package/dist/renderables/status.d.ts +13 -7
  113. package/dist/renderables/status.js +15 -29
  114. package/dist/renderables/syntax.d.ts +37 -7
  115. package/dist/renderables/syntax.js +134 -83
  116. package/dist/renderables/table.d.ts +58 -20
  117. package/dist/renderables/table.js +373 -197
  118. package/dist/renderables/traceback.d.ts +5 -4
  119. package/dist/renderables/traceback.js +239 -68
  120. package/dist/renderables/tree.d.ts +10 -2
  121. package/dist/renderables/tree.js +61 -34
  122. package/dist/renderables/viewport.d.ts +30 -0
  123. package/dist/renderables/viewport.js +61 -7
  124. package/dist/template-bindings/color-funcs.d.ts +31 -9
  125. package/dist/template-bindings/color-funcs.js +40 -14
  126. package/dist/template-bindings/helpers.d.ts +4 -2
  127. package/dist/template-bindings/helpers.js +5 -20
  128. package/dist/template-bindings/index.d.ts +29 -17
  129. package/dist/template-bindings/index.js +36 -20
  130. package/dist/template-bindings/palette-funcs.d.ts +3 -1
  131. package/dist/template-bindings/palette-funcs.js +11 -7
  132. package/dist/template-bindings/style-funcs.js +4 -2
  133. package/dist/themes/buildPalette.d.ts +24 -3
  134. package/dist/themes/buildPalette.js +52 -8
  135. package/dist/themes/colorMath.d.ts +29 -17
  136. package/dist/themes/colorMath.js +74 -48
  137. package/dist/themes/colorRef.d.ts +2 -17
  138. package/dist/themes/colorRef.js +13 -31
  139. package/dist/themes/palette.d.ts +24 -0
  140. package/dist/themes/palette.js +46 -3
  141. package/dist/themes/ramp.d.ts +21 -34
  142. package/dist/themes/ramp.js +23 -42
  143. package/dist/themes/registry.js +39 -28
  144. package/dist/widgets/button.d.ts +2 -6
  145. package/dist/widgets/button.js +9 -40
  146. package/dist/widgets/checkbox.d.ts +2 -5
  147. package/dist/widgets/checkbox.js +9 -31
  148. package/dist/widgets/dropdown.d.ts +2 -5
  149. package/dist/widgets/dropdown.js +17 -51
  150. package/dist/widgets/event-router.d.ts +31 -40
  151. package/dist/widgets/event-router.js +52 -483
  152. package/dist/widgets/index.d.ts +2 -1
  153. package/dist/widgets/ink.d.ts +22 -0
  154. package/dist/widgets/ink.js +31 -0
  155. package/dist/widgets/slider.d.ts +2 -5
  156. package/dist/widgets/slider.js +11 -34
  157. package/dist/widgets/text-input.d.ts +19 -10
  158. package/dist/widgets/text-input.js +156 -147
  159. package/dist/widgets/themed-widget.d.ts +20 -0
  160. package/dist/widgets/themed-widget.js +89 -0
  161. package/dist/widgets/toggle.d.ts +2 -5
  162. package/dist/widgets/toggle.js +8 -31
  163. package/dist/widgets/types.d.ts +8 -25
  164. package/dist/widgets/types.js +8 -0
  165. package/dist/widgets/widget-app.d.ts +24 -7
  166. package/dist/widgets/widget-app.js +35 -18
  167. package/dist/widgets/widget-base.d.ts +2 -0
  168. package/dist/widgets/widget-base.js +9 -2
  169. package/package.json +31 -17
@@ -0,0 +1,252 @@
1
+ /**
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
5
+ * in `EFFECT_CURVES` are the ones signed off by eye in the effects-feel demo
6
+ * (`npm run effects-feel`), at 30 fps and at one frame a second.
7
+ *
8
+ * Each effect is something a first-time observer already knows from life —
9
+ * a slow glow, sunlight moving on water, the colours of daylight, fireflies, ink
10
+ * blooming in water, mist lifting — because a motion the eye recognises
11
+ * reads as calm and alive, where a motion it has to learn reads as a widget.
12
+ * What makes those motions familiar is what every curve here keeps:
13
+ *
14
+ * - Nothing jumps. Every curve is continuous in time, built from smooth
15
+ * noise (`core/noise.ts`) and smooth waveforms, so at one frame a second a cell
16
+ * moves a little and at thirty it glides.
17
+ * - Nothing repeats exactly. Rhythms are perturbed by slow noise, and each
18
+ * breath, firefly's flash and pass of light is an event of its own, with
19
+ * its own strength and moment, the way no breath or gust is the last one
20
+ * again. A weaker event is a shorter one, so its strength costs nothing
21
+ * in smoothness.
22
+ * - Neighbours move together. Variation is spatially coherent — patches,
23
+ * filaments, fronts — never per-cell static.
24
+ * - Light only ever lights, and never takes the words away. Ink and the
25
+ * fill under it both move toward the light and never darken, each by its
26
+ * own share: the share a colour can take while every cell it is drawn in
27
+ * still reads at its resting contrast or WCAG AA, whichever is lower. A
28
+ * cell with contrast to spare glows brightly; one with none barely moves.
29
+ * - Elements are apart. Each sits at its own `z` in the noise, so two
30
+ * elements under one effect do not move in lockstep.
31
+ *
32
+ * Colour moves are in OKLCH, where equal steps look equal. A curve's `ease`
33
+ * maps its intensity in [0, 1] — how strongly the effect acts on a cell at a
34
+ * moment — onto its swing, for the loops and the transitions alike.
35
+ *
36
+ * [LAW:no-ambient-temporal-coupling] No curve reads a clock; `t` is the
37
+ * effect's argument, so the frame owner decides when to sample.
38
+ *
39
+ * Every import below names something the package exports, but for `noise`,
40
+ * which the docs' effects playground page supplies itself: each of its
41
+ * cards runs this file's own declarations as the program a visitor edits
42
+ * (`examples/effects-playground/programs.ts`), on the published library.
43
+ */
44
+ import { ColorRgba } from "../core/color.js";
45
+ import { type Ease } from "../core/easing.js";
46
+ import type { CellColors, Effect, EffectCell } from "./effect.js";
47
+ /** What a loop does to one colour at strength `w` in [0, 1]: at 0, nothing. */
48
+ export type Touch = (color: ColorRgba, w: number) => ColorRgba;
49
+ /** How strongly a loop acts on a cell at a moment, in [0, 1]; `onColors` holds a field outside it to it. */
50
+ export type Field = (cell: EffectCell, t: number) => number;
51
+ /** A looping effect: what it does to a colour, and where and when, how strongly. */
52
+ export interface Loop {
53
+ readonly touch: Touch;
54
+ readonly field: Field;
55
+ }
56
+ /**
57
+ * A cell's ink and ground as the screen shows them, and which of the two are
58
+ * the terminal's: what an `Effect` is handed for that cell.
59
+ */
60
+ export interface Pair extends CellColors {
61
+ readonly terminal: EffectCell["terminal"];
62
+ }
63
+ /**
64
+ * How much of `touch` each of `colors` (hex) can take: the largest share in
65
+ * [0, 1] at which every pair in `pairs` that shows it, touched at the same
66
+ * strength, still reads at its resting contrast or `LEGIBLE`, whichever is
67
+ * lower. A colour in a pair but not in `colors` takes none, and so does one
68
+ * the terminal supplies, whatever its hex, as in `onColors`. One of `colors`
69
+ * no pair writes has nothing to be measured against, and throws.
70
+ *
71
+ * Colours are settled lightest first, each against every partner: one
72
+ * already settled at its share, one not yet settled as it is. So the lighter
73
+ * colour of a cell takes the light first and its darker partner spends
74
+ * whatever contrast is left — pale lettering lifting off a dark fill gives
75
+ * the fill room to glow — and a darker colour left as it is always holds,
76
+ * because its lighter partner was settled against exactly that.
77
+ */
78
+ export declare function shares(pairs: readonly Pair[], colors: ReadonlySet<string>, touch: Touch): Map<string, number>;
79
+ /**
80
+ * A loop as an `Effect` on a subject's own colours, by hex, wherever a cell
81
+ * shows them, each touched at its share of the cell's strength. A powerline
82
+ * strip's fill is the ground of its cells and the ink of the seam glyphs
83
+ * between them, so the arrow moves with the cell it points out of. A colour
84
+ * the terminal supplies (`EffectCell.terminal`) is not the subject's, whatever
85
+ * its hex, and takes no share.
86
+ */
87
+ export declare function onColors(share: ReadonlyMap<string, number>, loop: Loop): Effect;
88
+ /** How the curves below are tuned: one period (or duration), ease and swing. */
89
+ export interface Curve {
90
+ /** Seconds: a looping effect's period, a transition's duration. */
91
+ readonly seconds: number;
92
+ /** Intensity in [0, 1] to the fraction of `swing` applied. One that overshoots, as a CSS `cubic-bezier` may, saturates: an effect never acts past its swing. */
93
+ readonly ease: Ease;
94
+ /** How far the move goes at full intensity, in [0, 1]; what 1 means is the effect's. */
95
+ readonly swing: number;
96
+ }
97
+ /**
98
+ * Each effect's curve as it was signed off. Every loop's period is a prime
99
+ * number of seconds, so no two loops come back into step within a sitting.
100
+ * The periods are long on purpose: at one frame a second a loop's colour
101
+ * moves by no more than a just-noticeable step from one frame to the next.
102
+ */
103
+ export declare const EFFECT_CURVES: {
104
+ readonly shimmer: {
105
+ readonly seconds: 109;
106
+ readonly ease: Ease;
107
+ readonly swing: 0.9;
108
+ };
109
+ readonly pulse: {
110
+ readonly seconds: 43;
111
+ readonly ease: Ease;
112
+ readonly swing: 0.85;
113
+ };
114
+ readonly sparkle: {
115
+ readonly seconds: 139;
116
+ readonly ease: Ease;
117
+ readonly swing: 0.95;
118
+ };
119
+ readonly wheel: {
120
+ readonly seconds: 907;
121
+ readonly ease: Ease;
122
+ readonly swing: 1;
123
+ };
124
+ readonly fade: {
125
+ readonly seconds: 20;
126
+ readonly ease: Ease;
127
+ readonly swing: 1;
128
+ };
129
+ readonly dissolve: {
130
+ readonly seconds: 30;
131
+ readonly ease: Ease;
132
+ readonly swing: 1;
133
+ };
134
+ };
135
+ /** The lights the loops were signed off casting, warm as sunlight and fireflies are. */
136
+ export declare const EFFECT_LIGHTS: {
137
+ readonly sun: ColorRgba;
138
+ readonly firefly: ColorRgba;
139
+ };
140
+ /** How far a shimmer's light reaches either side of its centre, in columns, as signed off. */
141
+ export declare const SHIMMER_WIDTH = 24;
142
+ /**
143
+ * A colour under `glow`: the one way every light here falls. It moves `w` of
144
+ * the way toward the light's colour, and never below its own lightness —
145
+ * light can warm a colour and lift it, never darken it. A colour already
146
+ * lighter than the light only warms, and white, which has no warmer shade at
147
+ * its lightness, stays white.
148
+ */
149
+ export declare function light(glow: ColorRgba): Touch;
150
+ /**
151
+ * Pulse, as a gentle glow on one element of a screen: the colours handed to
152
+ * it, an element's own, warm into `light` and settle back, over and over, the
153
+ * way an indicator breathes while something is waiting. Swing: how far into
154
+ * the light it goes at the top of a beat, 0–1. The element glows as one —
155
+ * every cell it is drawn in at once — and the colours not handed to it, the
156
+ * rest of the screen, stay as they are, so what pulses is what was chosen.
157
+ * Each element keeps a time of its own, a little quicker or slower than
158
+ * another's by `z`, and no beat is quite the last: the rhythm wanders ahead
159
+ * and behind its metronome and each beat goes a little deeper or shallower
160
+ * than the one before. A beat starts and ends in rest, so `t = 0` draws the
161
+ * element untouched.
162
+ */
163
+ export declare function pulse(curve: Curve, glow: ColorRgba, z: number): Loop;
164
+ /**
165
+ * Shimmer, as sunlight moving across water. Swing: how far into `light` the
166
+ * brightest glint goes, 0–1. A soft band of light, `width` columns either
167
+ * side of its centre, crosses columns 0 to `span`, entering and leaving
168
+ * fully off the row, `STRIDE` columns in about three quarters of a period. Its passes
169
+ * come the way light comes and goes on water as clouds move: while the sun
170
+ * is out they are bright and follow close on one another, one sometimes
171
+ * catching the last; under cloud they thin to faint ones with the row still
172
+ * for a while between, and the light is never gone for long. Each crosses at its own unhurried pace, drifting a little ahead
173
+ * and behind as it goes. Inside a band the light is a faint glow broken
174
+ * into a glitter path — bright filaments where two ripples cross — carried
175
+ * on a slow current and re-forming as they go, so the glints dance while
176
+ * the band glides. Before the first pass enters, the row is untouched.
177
+ */
178
+ export declare function shimmer(curve: Curve, span: number, width: number, glow: ColorRgba, z: number): Loop;
179
+ /**
180
+ * Sparkle, as fireflies. Swing: how far into the firefly's `light` a glow
181
+ * goes at its brightest, 0–1. About one firefly to every eight columns of
182
+ * `span`, each keeping near a home of its own. A firefly flashes — kindles,
183
+ * drifts a few cells glowing, slowing as it fades — then flies on in the
184
+ * dark and flashes again somewhere a few cells off, the way fireflies at
185
+ * dusk are seen: a short lit stroke, then gone, each time a little
186
+ * elsewhere. Each keeps its own irregular time, now and then letting a turn
187
+ * pass dark, so most moments a few are lit, at different brightnesses. Its
188
+ * light is a soft halo several cells wide, brightest where it is, so as it
189
+ * drifts the glow slides between cells rather than hopping. `seconds` is a firefly's
190
+ * turn: its brightest flash, rise and fall, takes `FLASH` of it, and a
191
+ * dimmer one less.
192
+ */
193
+ export declare function sparkle(curve: Curve, span: number, glow: ColorRgba, z: number): Loop;
194
+ /**
195
+ * How much of a cell shows at `t`: 1 is the cell as drawn, 0 is the cell gone
196
+ * to the terminal's ground. Read per cell, so cells can arrive or leave apart. One
197
+ * outside [0, 1] is held to it.
198
+ */
199
+ export type Visibility = (cell: EffectCell, t: number) => number;
200
+ /**
201
+ * A cell mixed toward the terminal's `ground` by how hidden it is: its fill
202
+ * toward the ground, and its ink toward that fill, so an element with fills
203
+ * of its own — a powerline strip — arrives and leaves whole, fill and words
204
+ * together, never as bare coloured blocks. Invisible is ink and fill equal
205
+ * to the ground. `swing` scales the hiding — 1 reaches fully invisible. A
206
+ * cell wholly shown is returned as it was.
207
+ */
208
+ export declare function veiled(visibility: Visibility, swing: number, ground: ColorRgba): Effect;
209
+ /**
210
+ * An effect that runs once: a fade-in or a dissolve-out from its start time
211
+ * over its curve's `seconds`. `done(t)` is true from the moment every cell
212
+ * has arrived or gone, so the caller knows when to stop drawing an element
213
+ * that is leaving, or to drop the effect from one that has arrived.
214
+ */
215
+ export interface Transition {
216
+ readonly effect: Effect;
217
+ done(t: number): boolean;
218
+ }
219
+ /**
220
+ * Fade-in starting at `start`, as ink blooming in water: patches of the
221
+ * element surface first and the rest follows outward from them, each cell
222
+ * rising smoothly over its own part of the duration. Whole at
223
+ * `start + seconds`.
224
+ */
225
+ export declare function fadeIn(curve: Curve, start: number, z: number, ground: ColorRgba): Transition;
226
+ /**
227
+ * Dissolve-out starting at `start`, as mist lifting: the element thins in
228
+ * drifting patches, each cell fading smoothly over its own part of the
229
+ * duration, until nothing is left at `start + seconds`. Mist does not lift
230
+ * in one breath: towards the end, patches of what is left — the later a cell
231
+ * goes, the likelier — rise back part way, as the last of it eddies, before
232
+ * they thin away for good.
233
+ */
234
+ export declare function dissolveOut(curve: Curve, start: number, z: number, ground: ColorRgba): Transition;
235
+ /**
236
+ * Wheel, as the colour of daylight going round: every hue turning the whole
237
+ * way round once a period — far too slowly to be seen moving, so a glance
238
+ * sees a steady palette and an hour's absence a different one — each
239
+ * segment of the element at its own pace. Swing: how far the segments stray
240
+ * from one another, 0–1, 1 being half a turn apart. A segment is a fill of
241
+ * the element's own — one of `fills`, the colours it draws as a ground — and
242
+ * it turns at its own pace wherever it is drawn: as the ground of its cells,
243
+ * and as the ink of the seam glyph pointing out of it into the next, so a
244
+ * powerline cap keeps the colour of the cell it caps. An ink that is no fill
245
+ * turns with the ground it sits on, so a cell's words and fill turn
246
+ * together; on the terminal's ground, a run of text's ink is a segment of
247
+ * its own. A segment's stray is slow noise of its own, at `STRAY_PERIODS`,
248
+ * so no two keep step, and the row never shows one spread of hues twice.
249
+ * Lightness and chroma are kept, so the words read as they did; the turn
250
+ * only happens to `colors`, the element's own, never the terminal's.
251
+ */
252
+ export declare function wheel(curve: Curve, colors: ReadonlySet<string>, fills: ReadonlySet<string>, z: number): Effect;