@promptctl/rich-js 0.24.0 → 0.24.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 (95) hide show
  1. package/THIRD-PARTY-NOTICES +29 -1
  2. package/dist/core/animation.d.ts +78 -0
  3. package/dist/core/animation.js +107 -0
  4. package/dist/core/cell-widths.d.ts +9 -0
  5. package/dist/core/cell-widths.js +140 -0
  6. package/dist/core/cells.d.ts +17 -11
  7. package/dist/core/cells.js +100 -25
  8. package/dist/core/console.js +5 -5
  9. package/dist/core/easing.d.ts +110 -10
  10. package/dist/core/easing.js +269 -36
  11. package/dist/core/json.js +2 -1
  12. package/dist/core/measure.js +2 -2
  13. package/dist/core/place.js +2 -1
  14. package/dist/core/pretty.js +2 -2
  15. package/dist/core/protocol.d.ts +73 -19
  16. package/dist/core/protocol.js +56 -15
  17. package/dist/core/render.js +2 -1
  18. package/dist/core/segment.d.ts +18 -1
  19. package/dist/core/segment.js +45 -44
  20. package/dist/core/strip.d.ts +3 -2
  21. package/dist/core/strip.js +11 -7
  22. package/dist/core/style.js +17 -6
  23. package/dist/core/text.js +22 -14
  24. package/dist/core/timeline.d.ts +84 -0
  25. package/dist/core/timeline.js +144 -0
  26. package/dist/core/tween.d.ts +49 -0
  27. package/dist/core/tween.js +69 -0
  28. package/dist/host/app.js +2 -2
  29. package/dist/index.d.ts +10 -7
  30. package/dist/index.js +13 -4
  31. package/dist/renderables/align.d.ts +3 -2
  32. package/dist/renderables/align.js +3 -0
  33. package/dist/renderables/columns.d.ts +3 -2
  34. package/dist/renderables/columns.js +7 -2
  35. package/dist/renderables/constrain.d.ts +3 -2
  36. package/dist/renderables/constrain.js +5 -1
  37. package/dist/renderables/effect.d.ts +43 -58
  38. package/dist/renderables/effect.js +58 -64
  39. package/dist/renderables/effects.d.ts +16 -14
  40. package/dist/renderables/effects.js +64 -45
  41. package/dist/renderables/embed.js +3 -2
  42. package/dist/renderables/flexStrip.d.ts +3 -2
  43. package/dist/renderables/flexStrip.js +6 -1
  44. package/dist/renderables/frames.d.ts +40 -19
  45. package/dist/renderables/frames.js +48 -21
  46. package/dist/renderables/group.d.ts +3 -2
  47. package/dist/renderables/group.js +5 -2
  48. package/dist/renderables/html-entities.d.ts +8 -0
  49. package/dist/renderables/html-entities.js +386 -0
  50. package/dist/renderables/layout.d.ts +3 -2
  51. package/dist/renderables/layout.js +15 -2
  52. package/dist/renderables/list-view.d.ts +3 -2
  53. package/dist/renderables/list-view.js +12 -5
  54. package/dist/renderables/live.js +2 -2
  55. package/dist/renderables/markdown-parse.d.ts +109 -0
  56. package/dist/renderables/markdown-parse.js +1421 -0
  57. package/dist/renderables/markdown-url.d.ts +19 -0
  58. package/dist/renderables/markdown-url.js +314 -0
  59. package/dist/renderables/markdown.d.ts +5 -7
  60. package/dist/renderables/markdown.js +356 -683
  61. package/dist/renderables/padding.d.ts +8 -20
  62. package/dist/renderables/padding.js +32 -50
  63. package/dist/renderables/panel.d.ts +26 -26
  64. package/dist/renderables/panel.js +67 -103
  65. package/dist/renderables/progress.d.ts +4 -2
  66. package/dist/renderables/progress.js +11 -2
  67. package/dist/renderables/progressBar.js +2 -2
  68. package/dist/renderables/python-space.d.ts +13 -0
  69. package/dist/renderables/python-space.js +24 -0
  70. package/dist/renderables/spinner.d.ts +26 -14
  71. package/dist/renderables/spinner.js +49 -37
  72. package/dist/renderables/syntax.js +2 -1
  73. package/dist/renderables/table.d.ts +19 -11
  74. package/dist/renderables/table.js +140 -156
  75. package/dist/renderables/traceback.d.ts +1 -1
  76. package/dist/renderables/traceback.js +6 -5
  77. package/dist/renderables/tree.d.ts +6 -5
  78. package/dist/renderables/tree.js +11 -7
  79. package/dist/renderables/viewport.d.ts +13 -5
  80. package/dist/renderables/viewport.js +41 -20
  81. package/dist/template-bindings/animation-funcs.js +2 -2
  82. package/dist/template-bindings/index.js +2 -1
  83. package/dist/themes/ramp.d.ts +18 -3
  84. package/dist/themes/ramp.js +23 -2
  85. package/dist/widgets/focus-manager.d.ts +21 -14
  86. package/dist/widgets/focus-manager.js +28 -29
  87. package/dist/widgets/index.d.ts +1 -1
  88. package/dist/widgets/static-item.d.ts +4 -3
  89. package/dist/widgets/static-item.js +9 -7
  90. package/dist/widgets/text-input.d.ts +28 -18
  91. package/dist/widgets/text-input.js +144 -101
  92. package/dist/widgets/widget-app.d.ts +19 -3
  93. package/dist/widgets/widget-app.js +39 -21
  94. package/dist/widgets/widget-base.js +0 -3
  95. package/package.json +2 -5
@@ -23,6 +23,7 @@
23
23
  */
24
24
  import { cellCount, cellLen, setCellSize } from "../core/cells.js";
25
25
  import { activeHighlighter, readStr } from "../core/markup.js";
26
+ import { render } from "../core/protocol.js";
26
27
  import { Segment } from "../core/segment.js";
27
28
  import { RichText } from "../core/text.js";
28
29
  /**
@@ -71,7 +72,7 @@ export class EmbeddedText {
71
72
  return text;
72
73
  }
73
74
  render(options) {
74
- return this.text(options).render(options);
75
+ return render(this.text(options), options);
75
76
  }
76
77
  /**
77
78
  * Measured unhighlighted, as Rich's `Measurement.get` reads a string with
@@ -163,7 +164,7 @@ export function present(content) {
163
164
  */
164
165
  export function drawLabel(text, options, base) {
165
166
  text.overflow = "ignore";
166
- return [...Segment.applyStyle(text.render(options), base)];
167
+ return [...Segment.applyStyle(render(text, options), base)];
167
168
  }
168
169
  /**
169
170
  * Caller content as a label, or no label at all: content that is not
@@ -16,7 +16,7 @@
16
16
  * FlexStrip reuses it verbatim. There is no second concept of "join."
17
17
  */
18
18
  import { Segment } from "../core/segment.js";
19
- import type { Renderable, Measurable, RenderOptions } from "../core/protocol.js";
19
+ import type { Composite, Renderable, Measurable, RenderOptions } from "../core/protocol.js";
20
20
  import { type Joiner, type StyledRenderable } from "../core/strip.js";
21
21
  export type FlexAlign = "left" | "center" | "right" | "justify";
22
22
  export interface FlexStripOptions<T extends StyledRenderable> {
@@ -27,12 +27,13 @@ export interface FlexStripOptions<T extends StyledRenderable> {
27
27
  /** Line alignment when packed items don't fill the available width (default "left"). */
28
28
  align?: FlexAlign;
29
29
  }
30
- export declare class FlexStrip<T extends StyledRenderable = StyledRenderable> implements Renderable, Measurable {
30
+ export declare class FlexStrip<T extends StyledRenderable = StyledRenderable> implements Renderable, Measurable, Composite {
31
31
  readonly items: readonly T[];
32
32
  readonly joiner: Joiner<T> | undefined;
33
33
  readonly gap: number;
34
34
  readonly align: FlexAlign;
35
35
  constructor(items: readonly T[], options?: FlexStripOptions<T>);
36
+ contents(): Iterable<Renderable>;
36
37
  render(options: RenderOptions): Iterable<Segment>;
37
38
  measure(options: RenderOptions): {
38
39
  minimum: number;
@@ -16,9 +16,10 @@
16
16
  * FlexStrip reuses it verbatim. There is no second concept of "join."
17
17
  */
18
18
  import { Segment } from "../core/segment.js";
19
+ import { render } from "../core/protocol.js";
19
20
  import { drawItem, drawJoin } from "../core/strip.js";
20
21
  function renderToBlock(r, options) {
21
- const segments = [...r.render(options)];
22
+ const segments = [...render(r, options)];
22
23
  let width = 0;
23
24
  for (const s of segments)
24
25
  width += s.cellLength;
@@ -55,6 +56,10 @@ export class FlexStrip {
55
56
  this.gap = options?.gap ?? 0;
56
57
  this.align = options?.align ?? "left";
57
58
  }
59
+ // The items; a join is drawn from what the joiner emits for it, not held.
60
+ contents() {
61
+ return this.items;
62
+ }
58
63
  *render(options) {
59
64
  const items = this.items;
60
65
  if (items.length === 0)
@@ -21,18 +21,23 @@
21
21
  *
22
22
  * The sequence and the moment are two values, because only one of them
23
23
  * changes from frame to frame. A `FrameSequence` is the frames prepared once
24
- * — the beat, the one width, each frame set into a line and padded — and a
25
- * `Frames` is that sequence at a `t`, whose work is one frame's — finding
26
- * which, and copying it: a host holds the sequence and asks it for a frame,
27
- * as `Spinner` holds its two, so a draw costs the same over ninety frames as
28
- * over one. The sequence is a value the host keeps, not a memo here: nothing
29
- * is looked up by key.
24
+ * — the beat, the one width, each frame set into a line and padded — and an
25
+ * `Animation` of the frame shown (`core/animation.ts`); a `Frames` is that
26
+ * sequence at a `t`, whose work is one frame's — finding which, and copying
27
+ * it: a host holds the sequence and asks it for a frame, as `Spinner` holds
28
+ * its two, so a draw costs the same over ninety frames as over one. The
29
+ * sequence is a value the host keeps, not a memo here: nothing is looked up
30
+ * by key.
30
31
  *
31
32
  * The frame drawn is drawn until the next begins, and its cells say so: they
32
- * are stamped with that moment (`Style.nextChange`), which rides up through
33
- * every container to whoever holds the composed frame (`Segment.nextChange`),
34
- * so a host drawing at `t` knows when to draw again, and one drawing slower
35
- * than the frames turn can see that it is skipping them.
33
+ * are stamped with the sequence's `nextChange` (`Style.nextChange`), which
34
+ * rides up through every container to whoever holds the composed frame
35
+ * (`Segment.nextChange`), so a host drawing at `t` knows when to draw again,
36
+ * and one drawing slower than the frames turn can see that it is skipping
37
+ * them. The stamp is put on by whoever draws the frame at a host time
38
+ * (`frameAt`) — a `Frames`, a `Spinner`, the template `frames` function —
39
+ * and the sequence's `at` hands over the frame alone, because the time a
40
+ * sequence is asked for may be one a `Timeline` mapped from the host's.
36
41
  *
37
42
  * Every frame is drawn at one width, the widest frame's, each padded on the
38
43
  * right to it, so whatever sits beside the frames never moves as they turn;
@@ -43,6 +48,7 @@
43
48
  * binding has no console for, so the frame arrives read, as a `Group`'s
44
49
  * children do.
45
50
  */
51
+ import type { Animation } from "../core/animation.js";
46
52
  import { type Beat } from "../core/easing.js";
47
53
  import type { Measurable, Renderable, RenderOptions } from "../core/protocol.js";
48
54
  import type { Segment } from "../core/segment.js";
@@ -53,7 +59,7 @@ export interface Frame {
53
59
  readonly seconds: number;
54
60
  }
55
61
  /** A sequence of frames prepared to be drawn: built once, asked for the frame at a time. */
56
- export declare class FrameSequence {
62
+ export declare class FrameSequence implements Animation<RichText> {
57
63
  /** Which frame is in progress when: the holds are the frames' seconds, in order. */
58
64
  readonly beat: Beat;
59
65
  /** The width every frame draws at: the widest frame's, in cells. */
@@ -62,16 +68,31 @@ export declare class FrameSequence {
62
68
  constructor(frames: readonly Frame[]);
63
69
  /**
64
70
  * The frame in progress at `t`, at `width` cells, ending no line: a copy,
65
- * the caller's to change, its every cell — padding included — stamped with
66
- * when it gives way to the next, `beat.end(t)`, so a blank frame among
67
- * drawn ones still turns. [LAW:one-source-of-truth] The stamp is the one
68
- * answer to when the frame changes, read off the cells
69
- * (`Segment.nextChange`): a sequence of nothing has no cell to carry one,
70
- * and a field saying a time would disagree with cells saying never.
71
- * `beat.at` refuses a `t` that is not finite.
71
+ * the caller's to change, carrying no word on when it changes — that is
72
+ * `frameAt`'s, stamped by whoever draws it at a host time. `beat.at`
73
+ * refuses a `t` that is not finite.
72
74
  */
73
- text(t: number): RichText;
75
+ at(t: number): RichText;
76
+ /** When the frame in progress at `t` gives way to the next: the beat's answer, its holds being the frames'. */
77
+ nextChange(t: number): number;
78
+ /** When the frame in progress at `t` began: the beat's answer. */
79
+ lastChange(t: number): number;
74
80
  }
81
+ /**
82
+ * The frame `animation` shows at host time `t`, its every cell — padding
83
+ * included, so a blank frame among drawn ones still turns — stamped with when
84
+ * it gives way to the next, `animation.nextChange(t)`. [LAW:one-source-of-truth]
85
+ * The stamp is that one answer carried on the cells (`Segment.nextChange`),
86
+ * so a container holding the frame passes it up without asking the
87
+ * animation; and it is put on here, where the host's time is known, and not
88
+ * in the animation's `at`, whose own time a `Timeline` or an
89
+ * `Animation.sequence` may have mapped from the host's — a stamp made there
90
+ * would be a moment on a clock the host cannot read. A copy is stamped, the
91
+ * caller's to change: an animation may hand back the one `RichText` it
92
+ * holds, as `Animation.constant` does, and a stamp on that would outlive
93
+ * the draw it was true for.
94
+ */
95
+ export declare function frameAt(animation: Animation<RichText>, t: number): RichText;
75
96
  export interface FramesOptions {
76
97
  /** The moment to draw, in seconds. */
77
98
  readonly t: number;
@@ -21,18 +21,23 @@
21
21
  *
22
22
  * The sequence and the moment are two values, because only one of them
23
23
  * changes from frame to frame. A `FrameSequence` is the frames prepared once
24
- * — the beat, the one width, each frame set into a line and padded — and a
25
- * `Frames` is that sequence at a `t`, whose work is one frame's — finding
26
- * which, and copying it: a host holds the sequence and asks it for a frame,
27
- * as `Spinner` holds its two, so a draw costs the same over ninety frames as
28
- * over one. The sequence is a value the host keeps, not a memo here: nothing
29
- * is looked up by key.
24
+ * — the beat, the one width, each frame set into a line and padded — and an
25
+ * `Animation` of the frame shown (`core/animation.ts`); a `Frames` is that
26
+ * sequence at a `t`, whose work is one frame's — finding which, and copying
27
+ * it: a host holds the sequence and asks it for a frame, as `Spinner` holds
28
+ * its two, so a draw costs the same over ninety frames as over one. The
29
+ * sequence is a value the host keeps, not a memo here: nothing is looked up
30
+ * by key.
30
31
  *
31
32
  * The frame drawn is drawn until the next begins, and its cells say so: they
32
- * are stamped with that moment (`Style.nextChange`), which rides up through
33
- * every container to whoever holds the composed frame (`Segment.nextChange`),
34
- * so a host drawing at `t` knows when to draw again, and one drawing slower
35
- * than the frames turn can see that it is skipping them.
33
+ * are stamped with the sequence's `nextChange` (`Style.nextChange`), which
34
+ * rides up through every container to whoever holds the composed frame
35
+ * (`Segment.nextChange`), so a host drawing at `t` knows when to draw again,
36
+ * and one drawing slower than the frames turn can see that it is skipping
37
+ * them. The stamp is put on by whoever draws the frame at a host time
38
+ * (`frameAt`) — a `Frames`, a `Spinner`, the template `frames` function —
39
+ * and the sequence's `at` hands over the frame alone, because the time a
40
+ * sequence is asked for may be one a `Timeline` mapped from the host's.
36
41
  *
37
42
  * Every frame is drawn at one width, the widest frame's, each padded on the
38
43
  * right to it, so whatever sits beside the frames never moves as they turn;
@@ -44,6 +49,7 @@
44
49
  * children do.
45
50
  */
46
51
  import { beat } from "../core/easing.js";
52
+ import { render } from "../core/protocol.js";
47
53
  import { Style } from "../core/style.js";
48
54
  import { setIntoLine } from "./embed.js";
49
55
  /** A sequence of frames prepared to be drawn: built once, asked for the frame at a time. */
@@ -69,17 +75,38 @@ export class FrameSequence {
69
75
  }
70
76
  /**
71
77
  * The frame in progress at `t`, at `width` cells, ending no line: a copy,
72
- * the caller's to change, its every cell — padding included — stamped with
73
- * when it gives way to the next, `beat.end(t)`, so a blank frame among
74
- * drawn ones still turns. [LAW:one-source-of-truth] The stamp is the one
75
- * answer to when the frame changes, read off the cells
76
- * (`Segment.nextChange`): a sequence of nothing has no cell to carry one,
77
- * and a field saying a time would disagree with cells saying never.
78
- * `beat.at` refuses a `t` that is not finite.
78
+ * the caller's to change, carrying no word on when it changes — that is
79
+ * `frameAt`'s, stamped by whoever draws it at a host time. `beat.at`
80
+ * refuses a `t` that is not finite.
79
81
  */
80
- text(t) {
81
- return this._shown[this.beat.at(t)].copy().stylize(new Style({ nextChange: this.beat.end(t) }));
82
+ at(t) {
83
+ return this._shown[this.beat.at(t)].copy();
82
84
  }
85
+ /** When the frame in progress at `t` gives way to the next: the beat's answer, its holds being the frames'. */
86
+ nextChange(t) {
87
+ return this.beat.nextChange(t);
88
+ }
89
+ /** When the frame in progress at `t` began: the beat's answer. */
90
+ lastChange(t) {
91
+ return this.beat.lastChange(t);
92
+ }
93
+ }
94
+ /**
95
+ * The frame `animation` shows at host time `t`, its every cell — padding
96
+ * included, so a blank frame among drawn ones still turns — stamped with when
97
+ * it gives way to the next, `animation.nextChange(t)`. [LAW:one-source-of-truth]
98
+ * The stamp is that one answer carried on the cells (`Segment.nextChange`),
99
+ * so a container holding the frame passes it up without asking the
100
+ * animation; and it is put on here, where the host's time is known, and not
101
+ * in the animation's `at`, whose own time a `Timeline` or an
102
+ * `Animation.sequence` may have mapped from the host's — a stamp made there
103
+ * would be a moment on a clock the host cannot read. A copy is stamped, the
104
+ * caller's to change: an animation may hand back the one `RichText` it
105
+ * holds, as `Animation.constant` does, and a stamp on that would outlive
106
+ * the draw it was true for.
107
+ */
108
+ export function frameAt(animation, t) {
109
+ return animation.at(t).copy().stylize(new Style({ nextChange: animation.nextChange(t) }));
83
110
  }
84
111
  /** A sequence's frame in progress at one moment, as a renderable. */
85
112
  export class Frames {
@@ -90,10 +117,10 @@ export class Frames {
90
117
  constructor(sequence, options) {
91
118
  this.sequence = sequence;
92
119
  this.t = options.t;
93
- this._shown = sequence.text(options.t);
120
+ this._shown = frameAt(sequence, options.t);
94
121
  }
95
122
  render(options) {
96
- return this._shown.render(options);
123
+ return render(this._shown, options);
97
124
  }
98
125
  /**
99
126
  * One width both ways: a frame is one picture, never wrapped apart at a
@@ -4,11 +4,12 @@
4
4
  */
5
5
  import type { Segment } from "../core/segment.js";
6
6
  import { type Measurement } from "../core/measure.js";
7
- import type { Measurable, Renderable, RenderOptions } from "../core/protocol.js";
8
- export declare class Group implements Renderable, Measurable {
7
+ import type { Composite, Measurable, Renderable, RenderOptions } from "../core/protocol.js";
8
+ export declare class Group implements Renderable, Measurable, Composite {
9
9
  readonly renderables: Renderable[];
10
10
  constructor(...renderables: Renderable[]);
11
11
  render(options: RenderOptions): Iterable<Segment>;
12
12
  /** As wide as its widest member: the reference's `measure_renderables`. */
13
13
  measure(options: RenderOptions): Measurement;
14
+ contents(): Iterable<Renderable>;
14
15
  }
@@ -3,7 +3,7 @@
3
3
  * No visual chrome — purely a container.
4
4
  */
5
5
  import { measureRenderables } from "../core/measure.js";
6
- import { stackedHeight } from "../core/protocol.js";
6
+ import { render, stackedHeight } from "../core/protocol.js";
7
7
  export class Group {
8
8
  renderables;
9
9
  constructor(...renderables) {
@@ -12,11 +12,14 @@ export class Group {
12
12
  *render(options) {
13
13
  const memberOptions = { ...options, height: stackedHeight(options.height) };
14
14
  for (const renderable of this.renderables) {
15
- yield* renderable.render(memberOptions);
15
+ yield* render(renderable, memberOptions);
16
16
  }
17
17
  }
18
18
  /** As wide as its widest member: the reference's `measure_renderables`. */
19
19
  measure(options) {
20
20
  return measureRenderables(options, this.renderables);
21
21
  }
22
+ contents() {
23
+ return this.renderables;
24
+ }
22
25
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * HTML's named character references, each name without its `;`, to the
3
+ * characters it stands for — the table markdown-it-py, Rich's parser, decodes
4
+ * with. Generated by scripts/html-entities.py from Python's
5
+ * `html.entities.html5`; regenerate rather than edit.
6
+ */
7
+ /** The characters `name`, a reference's name without its `&` and `;`, stands for, if it names any. */
8
+ export declare function namedReference(name: string): string | undefined;