@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
@@ -27,7 +27,7 @@
27
27
  */
28
28
  import { Segment } from "./segment.js";
29
29
  import { Style } from "./style.js";
30
- import { type Renderable, type RenderOptions } from "./protocol.js";
30
+ import { type Measurable, type Renderable, type RenderOptions } from "./protocol.js";
31
31
  /**
32
32
  * Items in a `Strip` expose their per-edge style so joiners can paint the
33
33
  * transition glyph at each boundary.
@@ -52,90 +52,132 @@ export interface Joiner<T extends StyledRenderable = StyledRenderable> {
52
52
  */
53
53
  join(left: T | null, right: T | null): Renderable;
54
54
  }
55
- export declare class Strip<T extends StyledRenderable = StyledRenderable> implements Renderable {
55
+ export declare class Strip<T extends StyledRenderable = StyledRenderable> implements Renderable, Measurable {
56
56
  readonly items: readonly T[];
57
57
  readonly joiner: Joiner<T>;
58
58
  constructor(items: readonly T[], joiner: Joiner<T>);
59
59
  render(options: RenderOptions): Iterable<Segment>;
60
+ /**
61
+ * [LAW:one-source-of-truth] The width of the one row it draws, and that is
62
+ * both bounds: the row never wraps and no item is offered less than the whole
63
+ * width, so there is no narrower strip to report as a minimum. Read off the
64
+ * drawing rather than summed from the items' measurements, which describe
65
+ * how an item could be drawn, not how the walk draws it.
66
+ */
67
+ measure(options: RenderOptions): {
68
+ minimum: number;
69
+ maximum: number;
70
+ };
71
+ }
72
+ /**
73
+ * A colour a joiner's cell is drawn in. Each variant names where the colour
74
+ * comes from when the join is drawn:
75
+ * • an `edge` — a neighbour's ground (`bg`) or text (`fg`) at the column
76
+ * facing the join, read through `StyledRenderable.edgeStyle`;
77
+ * • a `role` — a style name, resolved against the render's theme, whose
78
+ * foreground colour is the colour;
79
+ * • a `mix` — two colours blended at `t` (0 is the first, 1 the second).
80
+ */
81
+ export type Paint = {
82
+ readonly edge: "left" | "right";
83
+ readonly part: "bg" | "fg";
84
+ } | {
85
+ readonly role: string;
86
+ } | {
87
+ readonly mix: readonly [Paint, Paint, number];
88
+ };
89
+ /**
90
+ * A `Paint`, or `"ground"`: the terminal's own background, whose colour nobody
91
+ * knows. That is why it is never mixed (`Paint` excludes it), and why a cell
92
+ * may put it on one side only. As a cell's `fg` it is drawn in reverse video —
93
+ * the glyph's ink shows the terminal's background through a cell filled with
94
+ * the `bg` colour — so an inverted shape is the same glyph, never a glyph of
95
+ * its own.
96
+ */
97
+ export type CellColor = Paint | "ground";
98
+ /**
99
+ * One styled run of a join. A `oneOf` glyph is a set any member of which may
100
+ * stand in the cell; every member has the same width, because consumers
101
+ * measure a join by rendering it.
102
+ */
103
+ export interface JoinCell {
104
+ readonly glyph: string | {
105
+ readonly oneOf: readonly string[];
106
+ };
107
+ readonly fg: CellColor;
108
+ readonly bg: CellColor;
60
109
  }
61
110
  /**
62
- * The least ΔE_OK two neighbouring backgrounds must differ by for the powerline
63
- * arrow between them to be seen. Below it the arrow is drawn in a colour the
64
- * eye cannot tell from its own background, so the joiner draws the divider
111
+ * The cells a joiner draws at each kind of join:
112
+ * • `seam` — between two neighbours;
113
+ * • `divider` — in the seam's place where the two grounds are drawn as one
114
+ * colour (see `SEAM_MIN_DELTA_E`), so the seam would vanish into them;
115
+ * the same width as `seam`;
116
+ * • `lead` — where a run is entered from nothing: the strip's start, or a
117
+ * neighbour with no ground for the seam to paint. It cannot name `left`;
118
+ * • `tail` — where a run leaves into nothing. It cannot name `right`.
119
+ */
120
+ export interface JoinShape {
121
+ readonly seam: readonly JoinCell[];
122
+ readonly divider: readonly JoinCell[];
123
+ readonly lead: readonly JoinCell[];
124
+ readonly tail: readonly JoinCell[];
125
+ }
126
+ /**
127
+ * The least ΔE_OK two neighbouring backgrounds must differ by for a seam drawn
128
+ * between them to be seen. Below it the seam is drawn in a colour the eye
129
+ * cannot tell from its own background, so the joiner draws the divider
65
130
  * instead. Twice the ~.02 threshold of a visible difference, because a seam is
66
131
  * one cell wide.
67
132
  */
68
133
  export declare const SEAM_MIN_DELTA_E = 0.04;
69
- export interface PowerlineJoinerOptions {
70
- /** Glyph for every join between two coloured items. */
71
- glyph: string;
72
- /**
73
- * Glyph drawn between neighbours whose backgrounds the eye cannot tell apart,
74
- * in the left item's text colour — the arrow itself would vanish into the
75
- * shared background.
76
- */
77
- divider: string;
78
- /**
79
- * Glyph for every join a coloured item is entered from nothing — the strip's
80
- * start, or a colourless left neighbour — painted in the right item's
81
- * background. `""` begins a coloured run flat.
82
- */
83
- lead: string;
84
- /**
85
- * Glyph for every join a coloured item leaves into nothing — the strip's end,
86
- * or a colourless right neighbour — painted in the left item's background.
87
- * `""` ends a coloured run flat.
88
- */
89
- tail: string;
90
- }
91
134
  /**
92
- * The powerline set: U+E0B0 (right-arrow) divided by U+E0B1 (thin right-arrow),
93
- * led by U+E0D7 (Nerd Fonts ple-left_hard_divider_inverse, the right-arrow's
94
- * inverse) and tailed by the arrow itself. The lead leaves empty a triangle
95
- * whose base is its cell's left edge and whose point touches the first item, so
96
- * the run opens notched — as if an arrow before it pointed in — rather than
97
- * with a shape pointing out. The notch is the terminal's own background showing
98
- * through, never a colour painted to imitate it, so it matches under a
99
- * translucent terminal background too. The lead is a Powerline Extra glyph: a
100
- * classic powerline font lacks it.
135
+ * The one joiner: what it draws at each join is the `JoinShape` it is given,
136
+ * so a new joiner is a value, never a class.
137
+ *
138
+ * Which part a join draws is read off its two neighbours. A neighbour is
139
+ * missing at the strip's ends, and counts as missing — an endpoint — when the
140
+ * shape paints with its ground anywhere and it has none to paint. With both present the
141
+ * join is the seam, or the divider where the two grounds are drawn as one
142
+ * colour at `options.colorSystem`; with only the right, the lead; with only
143
+ * the left, the tail; with neither, nothing.
144
+ *
145
+ * `ascii` is the shape an ASCII-only output draws instead, whole.
101
146
  */
102
- export declare const POWERLINE_JOINER_GLYPHS: Readonly<PowerlineJoinerOptions>;
103
- export declare class PowerlineJoiner<T extends StyledRenderable = StyledRenderable> implements Joiner<T> {
104
- private readonly _glyphs;
105
- constructor(options?: PowerlineJoinerOptions);
106
- join(left: T | null, right: T | null): Renderable;
107
- }
108
- export interface CapsuleJoinerOptions {
109
- /** Left-cap glyph (default: U+E0B6, powerline rounded left). */
110
- left?: string;
111
- /** Right-cap glyph (default: U+E0B4, powerline rounded right). */
112
- right?: string;
113
- /** Separator inserted between adjacent capsules in the middle position. */
114
- separator?: string;
115
- }
116
- export declare class CapsuleJoiner<T extends StyledRenderable = StyledRenderable> implements Joiner<T> {
117
- private readonly _caps;
118
- private readonly _separator;
119
- constructor(options?: CapsuleJoinerOptions);
120
- _emit(left: T | null, right: T | null, options: RenderOptions): Iterable<Segment>;
121
- join(left: T | null, right: T | null): Renderable;
122
- }
123
- export interface PlainJoinerOptions {
124
- separator?: string;
125
- style?: Style;
126
- }
127
- export declare class PlainJoiner<T extends StyledRenderable = StyledRenderable> implements Joiner<T> {
128
- private readonly _separator;
129
- private readonly _style;
130
- constructor(options?: PlainJoinerOptions);
131
- join(left: T | null, right: T | null): Renderable;
132
- }
133
- export interface GradientJoinerOptions {
134
- /** Number of cells between adjacent items (default: 4). */
135
- steps?: number;
136
- }
137
- export declare class GradientJoiner<T extends StyledRenderable = StyledRenderable> implements Joiner<T> {
138
- private readonly _steps;
139
- constructor(options?: GradientJoinerOptions);
147
+ export declare class CellJoiner<T extends StyledRenderable = StyledRenderable> implements Joiner<T> {
148
+ readonly shape: JoinShape;
149
+ readonly ascii: JoinShape;
150
+ private readonly _forms;
151
+ constructor(shape: JoinShape, ascii: JoinShape);
140
152
  join(left: T | null, right: T | null): Renderable;
141
153
  }
154
+ /**
155
+ * The powerline joiner: U+E0B0 (right-arrow) in the left ground over the
156
+ * right, divided by U+E0B1 (thin right-arrow) in the left item's text. The
157
+ * lead is the arrow with the left ground replaced by the terminal's — drawn
158
+ * in reverse video it leaves a notch whose base is the cell's left edge, inked
159
+ * in the terminal's background colour. That ink is opaque, so under a
160
+ * translucent terminal the notch does not let what is behind it through. The
161
+ * tail is the arrow over the terminal's ground.
162
+ * ASCII draws `>` everywhere and begins each run flat.
163
+ */
164
+ export declare const POWERLINE_JOINER: CellJoiner<StyledRenderable>;
165
+ /**
166
+ * Rounded pills: each run opened by U+E0B6 and closed by U+E0B4, both in its
167
+ * ground over the terminal's, a space between pills. ASCII draws `(` and `)`.
168
+ */
169
+ export declare const CAPSULE_JOINER: CellJoiner<StyledRenderable>;
170
+ /**
171
+ * ` | ` between every pair of items, in the theme's `strip.separator` colour;
172
+ * nothing at the ends. Its shape names no neighbour, so it joins items with no
173
+ * ground too.
174
+ */
175
+ export declare const PLAIN_JOINER: CellJoiner<StyledRenderable>;
176
+ /**
177
+ * A ramp of `steps` cells from the left ground to the right. Each cell is the
178
+ * half block U+258C, ink on its left half and ground on its right, so it
179
+ * carries two samples; ASCII draws a space, keeping the grounds alone. Nothing
180
+ * at the ends, or beside a neighbour with no ground — there is no colour to
181
+ * ramp toward.
182
+ */
183
+ export declare function gradientJoiner(steps?: number): CellJoiner;