@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
@@ -6,20 +6,20 @@ import { Style } from "../core/style.js";
6
6
  import { Box } from "../core/box.js";
7
7
  import { RichText } from "../core/text.js";
8
8
  import type { PaddingDimensions } from "./padding.js";
9
- import type { Composite, Renderable, Measurable, RenderOptions } from "../core/protocol.js";
9
+ import type { Renderable, Measurable, RenderOptions } from "../core/protocol.js";
10
10
  /**
11
- * A lazily-resolved border accessory. Strings render inline in the
12
- * border style; a `RichText` accessory lays ONLY its wrapping `style` over
13
- * the border's (per-range spans within the RichText are not preserved — the
14
- * accessory is a small status indicator, not an arbitrary span carrier).
15
- * A function form is evaluated at render time, *after* content has been
16
- * rendered for the current frame — use this when the accessory mirrors
17
- * state that the wrapped renderable populates during its own `render()`
18
- * (e.g. a widget's post-render scroll position). A width that leaves the
19
- * content no column does not render it, as Rich's does not, and the thunk
20
- * then reads the state of the last frame that did.
11
+ * A border accessory. Strings render inline in the border style; a
12
+ * `RichText` accessory lays ONLY its wrapping `style` over the border's
13
+ * (per-range spans within the RichText are not preserved — the accessory is a
14
+ * small status indicator, not an arbitrary span carrier).
15
+ *
16
+ * [LAW:no-ambient-temporal-coupling] A function form is handed the rows the
17
+ * body drew this frame, so an accessory that mirrors the content's layout (a
18
+ * widget's scroll position) reads it off the frame it labels, not off state
19
+ * the content kept from an earlier one. A width that leaves the content no column does not render it,
20
+ * as Rich's does not, and the rows it is handed are then blank.
21
21
  */
22
- export type BorderAccessory = string | RichText | (() => string | RichText | undefined);
22
+ export type BorderAccessory = string | RichText | ((body: readonly (readonly Segment[])[]) => string | RichText | undefined);
23
23
  export interface PanelOptions {
24
24
  box?: Box;
25
25
  title?: string | RichText;
@@ -48,7 +48,7 @@ export interface PanelOptions {
48
48
  width?: number;
49
49
  padding?: PaddingDimensions;
50
50
  }
51
- export declare class Panel implements Renderable, Measurable, Composite {
51
+ export declare class Panel implements Renderable, Measurable {
52
52
  readonly renderable: Renderable;
53
53
  readonly box: Box;
54
54
  readonly title: string | RichText | undefined;
@@ -73,7 +73,6 @@ export declare class Panel implements Renderable, Measurable, Composite {
73
73
  get padding(): readonly [number, number, number, number];
74
74
  constructor(content: string | RichText | Renderable, options?: PanelOptions);
75
75
  render(rawOptions: RenderOptions): Iterable<Segment>;
76
- contents(): Iterable<Renderable>;
77
76
  /**
78
77
  * The body's rows, held to the region as Rich's `render_lines` holds them —
79
78
  * padded below, cropped from the bottom — and each exactly `spanWidth`
@@ -82,8 +81,7 @@ export declare class Panel implements Renderable, Measurable, Composite {
82
81
  * `Console.render` renders nothing under one column, so outside a region it
83
82
  * draws no rows, padding rows included, and inside one the frame stands
84
83
  * around empty rows. The render happens before either border is drawn,
85
- * because a `bottomRightAccessory` thunk reads state the content's render
86
- * populates.
84
+ * because a `bottomRightAccessory` function is handed the rows it drew.
87
85
  */
88
86
  private _renderBody;
89
87
  measure(rawOptions: RenderOptions): {
@@ -140,12 +140,7 @@ export class Panel {
140
140
  yield new Segment(frame.right.repeat(geometry.right), border);
141
141
  yield Segment.line();
142
142
  }
143
- yield* this._renderBottomBorder(options, box, geometry, border);
144
- }
145
- // The body is the one thing a panel draws through `render`: its title and
146
- // subtitle are text it builds.
147
- *contents() {
148
- yield this._body;
143
+ yield* this._renderBottomBorder(options, box, geometry, border, bodyLines);
149
144
  }
150
145
  /**
151
146
  * The body's rows, held to the region as Rich's `render_lines` holds them —
@@ -155,8 +150,7 @@ export class Panel {
155
150
  * `Console.render` renders nothing under one column, so outside a region it
156
151
  * draws no rows, padding rows included, and inside one the frame stands
157
152
  * around empty rows. The render happens before either border is drawn,
158
- * because a `bottomRightAccessory` thunk reads state the content's render
159
- * populates.
153
+ * because a `bottomRightAccessory` function is handed the rows it drew.
160
154
  */
161
155
  _renderBody(options, spanWidth) {
162
156
  // Two border rows are the panel's own, and the vertical padding is the
@@ -230,10 +224,8 @@ export class Panel {
230
224
  yield* borderRow(options, box.top, geometry, geometry.spanWidth, this._titleLabel, titleStyle, border, box.top.right.repeat(geometry.right));
231
225
  yield Segment.line();
232
226
  }
233
- *_renderBottomBorder(options, box, geometry, border) {
234
- // Resolve the right accessory *now*, after the body has rendered —
235
- // `BorderAccessory` owns what a thunk sees.
236
- const accessory = this._resolveAccessory(this.bottomRightAccessory);
227
+ *_renderBottomBorder(options, box, geometry, border, body) {
228
+ const accessory = this._resolveAccessory(this.bottomRightAccessory, body);
237
229
  const accessoryDisplay = accessory === undefined
238
230
  ? ""
239
231
  : typeof accessory === "string"
@@ -253,11 +245,11 @@ export class Panel {
253
245
  yield new Segment(afterAccessory, border);
254
246
  yield Segment.line();
255
247
  }
256
- _resolveAccessory(a) {
248
+ _resolveAccessory(a, body) {
257
249
  if (a === undefined)
258
250
  return undefined;
259
251
  if (typeof a === "function")
260
- return a();
252
+ return a(body);
261
253
  return a;
262
254
  }
263
255
  // --- Static factory ---
@@ -5,10 +5,11 @@ import type { Segment } from "../core/segment.js";
5
5
  import { RichText } from "../core/text.js";
6
6
  import { Console } from "../core/console.js";
7
7
  import type { Style } from "../core/style.js";
8
- import { ProgressBar } from "./progressBar.js";
9
- import { type Clock } from "../core/clock.js";
8
+ import type { Clock } from "../core/clock.js";
10
9
  import { type ColumnOptions } from "./table.js";
11
- import type { Composite, Renderable, RenderOptions } from "../core/protocol.js";
10
+ import type { FrameHost, Renderable, RenderOptions } from "../core/protocol.js";
11
+ import { Animation } from "../core/animation.js";
12
+ import type { Timing } from "../core/easing.js";
12
13
  export interface TaskOptions {
13
14
  total?: number;
14
15
  start?: boolean;
@@ -22,30 +23,31 @@ export interface TaskUpdateOptions {
22
23
  refresh?: boolean;
23
24
  }
24
25
  export interface Task {
25
- id: number;
26
- description: string;
27
- total: number | undefined;
28
- completed: number;
29
- visible: boolean;
30
- /** When the task started, in seconds on its `Progress`'s clock; undefined until it has. */
31
- startTime: number | undefined;
26
+ readonly id: number;
27
+ readonly description: string;
28
+ readonly total: number | undefined;
29
+ readonly completed: number;
32
30
  /**
33
- * Rich's `Task.get_time()`: the moment the frame being drawn is drawn at, in
34
- * seconds on its `Progress`'s clock, so a column animates without reading one.
31
+ * The count a bar shows, over its `Progress`'s clock: `completed` itself,
32
+ * or moving to it after each update when the `Progress` was given a `fill`
33
+ * timing. `completed` stays the count; only the bar draws this.
35
34
  */
36
- time: number;
35
+ readonly fill: Animation<number>;
36
+ readonly visible: boolean;
37
+ /** When the task started, in seconds on its `Progress`'s host's time; undefined until it has, as of the frame being drawn. */
38
+ readonly startTime: number | undefined;
37
39
  /**
38
40
  * Rich's `Task.elapsed`: seconds since the task started, as of the frame
39
- * being drawn — `Progress` reads its clock once a frame and hands columns
41
+ * being drawn — `Progress` takes the time once a frame and hands columns
40
42
  * the result, so no column reads a clock. Undefined until the task starts.
41
43
  */
42
- elapsed: number | undefined;
44
+ readonly elapsed: number | undefined;
43
45
  /**
44
46
  * Rich's `Task.finished_time`: the elapsed time the first time an update
45
47
  * finds a started task at its total, kept from then on, so a finished task
46
48
  * stays finished however its count moves after.
47
49
  */
48
- finishedTime: number | undefined;
50
+ readonly finishedTime: number | undefined;
49
51
  /**
50
52
  * Rich's `Task.speed`: steps a second over the updates that moved the task
51
53
  * in the `SPEED_ESTIMATE_PERIOD` before its latest update — measured back from
@@ -53,7 +55,7 @@ export interface Task {
53
55
  * speed it had. Undefined until the task has started and two such updates lie
54
56
  * apart in time.
55
57
  */
56
- speed: number | undefined;
58
+ readonly speed: number | undefined;
57
59
  }
58
60
  /**
59
61
  * One cell of a `Progress` row, made for the task on that row. Not a
@@ -82,8 +84,16 @@ export declare class BarColumn implements ProgressColumn {
82
84
  readonly barWidth: number;
83
85
  readonly tableColumn: ColumnOptions;
84
86
  constructor(barWidth?: number);
85
- /** Rich's `BarColumn`: a task not yet started, or with no total to fill toward, pulses. */
86
- render(task: Task): ProgressBar;
87
+ /**
88
+ * Rich's `BarColumn`: a task not yet started, or with no total to fill
89
+ * toward, pulses, and a pulse draws no fill. Otherwise the bar is the
90
+ * task's `fill` drawn at the frame's time, every cell stamped with when the
91
+ * fill next moves, so a host draws while it eases and the bar asks for
92
+ * nothing once it lands. Its colour is the task's: an ease that overshoots
93
+ * the total does not finish the bar, and one that dips back does not
94
+ * unfinish it.
95
+ */
96
+ render(task: Task): Renderable;
87
97
  }
88
98
  /**
89
99
  * Rich's `{task.percentage:>3.0f}%`: the percentage right-aligned in three
@@ -112,7 +122,7 @@ export declare class TimeRemainingColumn implements ProgressColumn {
112
122
  }
113
123
  export declare class TimeElapsedColumn implements ProgressColumn {
114
124
  readonly tableColumn: ColumnOptions;
115
- render(task: Task): RichText;
125
+ render(task: Task): Renderable;
116
126
  }
117
127
  export interface SpinnerColumnOptions {
118
128
  /** The frame's style. Defaults to `progress.spinner`, a name its console's theme resolves. */
@@ -125,7 +135,7 @@ export interface SpinnerColumnOptions {
125
135
  export declare class SpinnerColumn implements ProgressColumn {
126
136
  readonly tableColumn: ColumnOptions;
127
137
  private readonly _spinner;
128
- private _finishedText;
138
+ private readonly _finishedText;
129
139
  constructor(spinnerName?: string, options?: SpinnerColumnOptions);
130
140
  render(task: Task): Renderable;
131
141
  }
@@ -144,39 +154,77 @@ export declare class MofNCompleteColumn implements ProgressColumn {
144
154
  constructor(options?: MofNCompleteColumnOptions);
145
155
  render(task: Task): RichText;
146
156
  }
147
- export interface ProgressOptions {
157
+ /**
158
+ * How a `Progress` is set up. It is drawn by one host, and every time it
159
+ * keeps or draws at is that host's `frameTime`: by its own `Live`, which the
160
+ * options for that `Live` configure, or, given `drawnBy`, by another host —
161
+ * which then does all the drawing, so none of them apply.
162
+ */
163
+ export type ProgressOptions = ProgressDisplayOptions & (OwnLiveOptions | DrawnByOptions);
164
+ interface ProgressDisplayOptions {
165
+ expand?: boolean;
166
+ /**
167
+ * How a bar's fill moves to a task's new count: eased over this timing
168
+ * from wherever it is when the count changes, so a bar advancing in bursts
169
+ * reads as motion. Unset, the bar jumps to the count, as Rich's does.
170
+ */
171
+ fill?: Timing;
172
+ }
173
+ interface OwnLiveOptions {
174
+ drawnBy?: undefined;
175
+ console?: Console;
148
176
  refreshPerSecond?: number;
149
177
  autoRefresh?: boolean;
150
178
  transient?: boolean;
151
- expand?: boolean;
152
- console?: Console;
153
179
  /**
154
- * What tasks are timed by and frames are drawn on, Rich's `get_time`;
155
- * defaults to the platform's monotonic clock. Handed on to the `Live`.
180
+ * What its own `Live` ticks on, and so what tasks are timed by — Rich's
181
+ * `get_time`; defaults to the platform's monotonic clock.
156
182
  */
157
183
  clock?: Clock;
158
184
  }
159
- export declare class Progress implements Renderable, Composite {
160
- private _columns;
161
- private _tasks;
162
- private _nextId;
163
- private _live;
164
- private _console;
165
- private readonly _clock;
185
+ interface DrawnByOptions {
186
+ /**
187
+ * The host — a `Live`, an `App` — whose frames this `Progress` is drawn in:
188
+ * tasks are timed by its `frameTime`, so they hold while its timeline is
189
+ * paused and run back while it is reversed. Drawn in any other host's
190
+ * frame, the `Progress` throws.
191
+ */
192
+ drawnBy: FrameHost;
193
+ console?: never;
194
+ refreshPerSecond?: never;
195
+ autoRefresh?: never;
196
+ transient?: never;
197
+ clock?: never;
198
+ }
199
+ export declare class Progress implements Renderable {
200
+ private readonly _columns;
201
+ private readonly _tasks;
202
+ private readonly _live;
203
+ private readonly _host;
204
+ /** A task's fill after its count changes at `now`, from the value it shows then. */
205
+ private readonly _refill;
166
206
  readonly expand: boolean;
167
207
  constructor(...columns: (ProgressColumn | ProgressOptions)[]);
208
+ /** The console its own `Live` prints above the bars through. */
168
209
  get console(): Console;
169
210
  /** Rich's `Progress.finished`: every task finished, and so true with none. */
170
211
  get finished(): boolean;
171
212
  static getDefaultColumns(): ProgressColumn[];
172
213
  addTask(description: string, options?: TaskOptions): number;
214
+ private _task;
173
215
  updateTask(taskId: number, options: TaskUpdateOptions): void;
174
216
  startTask(taskId: number): void;
175
217
  start(): void;
218
+ /**
219
+ * Every bar settles at its count, so the frame drawn next — its own `Live`'s
220
+ * final one, handed back here, or the next of the host that draws it —
221
+ * shows where the work got to, not a bar caught mid-ease.
222
+ */
176
223
  stop(): void;
177
224
  refresh(): void;
225
+ private _ownLive;
178
226
  render(options: RenderOptions): Iterable<Segment>;
179
- contents(): Iterable<Renderable>;
227
+ private _framed;
180
228
  private _table;
181
229
  }
182
230
  export declare function track<T>(iterable: Iterable<T>, options?: {
@@ -184,3 +232,4 @@ export declare function track<T>(iterable: Iterable<T>, options?: {
184
232
  total?: number;
185
233
  console?: Console;
186
234
  }): Iterable<T>;
235
+ export {};