@promptctl/rich-js 0.18.1 → 0.19.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 (150) hide show
  1. package/README.md +9 -7
  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 +98 -18
  9. package/dist/core/color.js +331 -144
  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/osc8.d.ts +6 -6
  33. package/dist/core/osc8.js +9 -21
  34. package/dist/core/paint.d.ts +107 -0
  35. package/dist/core/paint.js +150 -0
  36. package/dist/core/place.d.ts +1 -1
  37. package/dist/core/place.js +4 -6
  38. package/dist/core/pretty.d.ts +105 -2
  39. package/dist/core/pretty.js +527 -97
  40. package/dist/core/protocol.d.ts +41 -3
  41. package/dist/core/protocol.js +20 -0
  42. package/dist/core/render.d.ts +33 -30
  43. package/dist/core/render.js +43 -83
  44. package/dist/core/segment.d.ts +6 -5
  45. package/dist/core/segment.js +11 -15
  46. package/dist/core/strip.d.ts +13 -2
  47. package/dist/core/strip.js +44 -23
  48. package/dist/core/style.d.ts +27 -7
  49. package/dist/core/style.js +97 -34
  50. package/dist/core/text.d.ts +43 -16
  51. package/dist/core/text.js +180 -59
  52. package/dist/core/wrap.d.ts +5 -0
  53. package/dist/core/wrap.js +16 -3
  54. package/dist/host/app.d.ts +31 -19
  55. package/dist/host/app.js +90 -60
  56. package/dist/host/index.d.ts +2 -1
  57. package/dist/host/terminal-host.d.ts +3 -2
  58. package/dist/index.d.ts +17 -10
  59. package/dist/index.js +11 -4
  60. package/dist/node/prompt.d.ts +13 -0
  61. package/dist/node/prompt.js +30 -9
  62. package/dist/node/save.d.ts +4 -3
  63. package/dist/node/save.js +6 -3
  64. package/dist/node/terminal-host.d.ts +3 -2
  65. package/dist/node/traceback.d.ts +2 -1
  66. package/dist/node/traceback.js +3 -39
  67. package/dist/renderables/align.js +2 -9
  68. package/dist/renderables/columns.d.ts +45 -29
  69. package/dist/renderables/columns.js +142 -103
  70. package/dist/renderables/constrain.js +6 -12
  71. package/dist/renderables/effect.d.ts +98 -0
  72. package/dist/renderables/effect.js +160 -0
  73. package/dist/renderables/embed.d.ts +87 -30
  74. package/dist/renderables/embed.js +134 -45
  75. package/dist/renderables/group.d.ts +6 -3
  76. package/dist/renderables/group.js +5 -0
  77. package/dist/renderables/layout.d.ts +6 -23
  78. package/dist/renderables/layout.js +24 -113
  79. package/dist/renderables/live.d.ts +40 -16
  80. package/dist/renderables/live.js +96 -83
  81. package/dist/renderables/markdown.d.ts +16 -2
  82. package/dist/renderables/markdown.js +521 -118
  83. package/dist/renderables/padding.d.ts +22 -1
  84. package/dist/renderables/padding.js +30 -24
  85. package/dist/renderables/panel.d.ts +31 -33
  86. package/dist/renderables/panel.js +137 -141
  87. package/dist/renderables/progress.d.ts +104 -16
  88. package/dist/renderables/progress.js +205 -81
  89. package/dist/renderables/progressBar.d.ts +2 -2
  90. package/dist/renderables/progressBar.js +30 -19
  91. package/dist/renderables/prompt.d.ts +37 -15
  92. package/dist/renderables/prompt.js +125 -85
  93. package/dist/renderables/ratio.d.ts +123 -0
  94. package/dist/renderables/ratio.js +213 -0
  95. package/dist/renderables/rule.d.ts +1 -0
  96. package/dist/renderables/rule.js +44 -48
  97. package/dist/renderables/spinner.d.ts +28 -2
  98. package/dist/renderables/spinner.js +52 -19
  99. package/dist/renderables/status.d.ts +13 -7
  100. package/dist/renderables/status.js +15 -29
  101. package/dist/renderables/syntax.d.ts +37 -7
  102. package/dist/renderables/syntax.js +134 -83
  103. package/dist/renderables/table.d.ts +58 -20
  104. package/dist/renderables/table.js +370 -192
  105. package/dist/renderables/traceback.d.ts +5 -4
  106. package/dist/renderables/traceback.js +239 -68
  107. package/dist/renderables/tree.d.ts +10 -2
  108. package/dist/renderables/tree.js +61 -34
  109. package/dist/renderables/viewport.js +2 -4
  110. package/dist/template-bindings/color-funcs.d.ts +31 -9
  111. package/dist/template-bindings/color-funcs.js +40 -14
  112. package/dist/template-bindings/helpers.d.ts +4 -2
  113. package/dist/template-bindings/helpers.js +5 -20
  114. package/dist/template-bindings/index.d.ts +29 -17
  115. package/dist/template-bindings/index.js +36 -20
  116. package/dist/template-bindings/palette-funcs.d.ts +3 -1
  117. package/dist/template-bindings/palette-funcs.js +11 -7
  118. package/dist/template-bindings/style-funcs.js +4 -2
  119. package/dist/themes/buildPalette.d.ts +24 -3
  120. package/dist/themes/buildPalette.js +52 -8
  121. package/dist/themes/colorMath.d.ts +29 -17
  122. package/dist/themes/colorMath.js +74 -48
  123. package/dist/themes/colorRef.d.ts +2 -17
  124. package/dist/themes/colorRef.js +13 -31
  125. package/dist/themes/palette.d.ts +24 -0
  126. package/dist/themes/palette.js +46 -3
  127. package/dist/themes/ramp.d.ts +21 -34
  128. package/dist/themes/ramp.js +23 -42
  129. package/dist/themes/registry.js +39 -28
  130. package/dist/widgets/button.d.ts +2 -6
  131. package/dist/widgets/button.js +9 -40
  132. package/dist/widgets/checkbox.d.ts +2 -5
  133. package/dist/widgets/checkbox.js +9 -31
  134. package/dist/widgets/dropdown.d.ts +2 -5
  135. package/dist/widgets/dropdown.js +14 -48
  136. package/dist/widgets/ink.d.ts +22 -0
  137. package/dist/widgets/ink.js +31 -0
  138. package/dist/widgets/slider.d.ts +2 -5
  139. package/dist/widgets/slider.js +11 -34
  140. package/dist/widgets/text-input.d.ts +19 -10
  141. package/dist/widgets/text-input.js +156 -147
  142. package/dist/widgets/themed-widget.d.ts +20 -0
  143. package/dist/widgets/themed-widget.js +89 -0
  144. package/dist/widgets/toggle.d.ts +2 -5
  145. package/dist/widgets/toggle.js +8 -31
  146. package/dist/widgets/widget-app.d.ts +2 -0
  147. package/dist/widgets/widget-app.js +13 -6
  148. package/dist/widgets/widget-base.d.ts +2 -0
  149. package/dist/widgets/widget-base.js +9 -2
  150. package/package.json +11 -1
@@ -54,13 +54,12 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
54
54
  import { observable, action, observableRef } from "mobx";
55
55
  import { Segment } from "../core/segment.js";
56
56
  import { Style } from "../core/style.js";
57
- import { ColorSpec } from "../core/color.js";
58
- import { DEFAULT_TERMINAL_THEME } from "../themes/terminalThemes.js";
59
57
  import { drawable } from "../core/protocol.js";
60
- import { WidgetBase } from "./widget-base.js";
58
+ import { ThemedWidget } from "./themed-widget.js";
59
+ import { ink } from "./ink.js";
61
60
  const DEFAULT_WIDTH = 20;
62
61
  let Slider = (() => {
63
- let _classSuper = WidgetBase;
62
+ let _classSuper = ThemedWidget;
64
63
  let _instanceExtraInitializers = [];
65
64
  let _value_decorators;
66
65
  let _value_initializers = [];
@@ -77,10 +76,6 @@ let Slider = (() => {
77
76
  let _width_decorators;
78
77
  let _width_initializers = [];
79
78
  let _width_extraInitializers = [];
80
- let __theme_decorators;
81
- let __theme_initializers = [];
82
- let __theme_extraInitializers = [];
83
- let _setTheme_decorators;
84
79
  let _handleKey_decorators;
85
80
  let _handleMouse_decorators;
86
81
  let _setValue_decorators;
@@ -92,8 +87,6 @@ let Slider = (() => {
92
87
  _max_decorators = [observableRef];
93
88
  _step_decorators = [observableRef];
94
89
  _width_decorators = [observableRef];
95
- __theme_decorators = [observableRef];
96
- _setTheme_decorators = [action];
97
90
  _handleKey_decorators = [action];
98
91
  _handleMouse_decorators = [action];
99
92
  _setValue_decorators = [action];
@@ -102,8 +95,6 @@ let Slider = (() => {
102
95
  __esDecorate(this, null, _max_decorators, { kind: "accessor", name: "max", static: false, private: false, access: { has: obj => "max" in obj, get: obj => obj.max, set: (obj, value) => { obj.max = value; } }, metadata: _metadata }, _max_initializers, _max_extraInitializers);
103
96
  __esDecorate(this, null, _step_decorators, { kind: "accessor", name: "step", static: false, private: false, access: { has: obj => "step" in obj, get: obj => obj.step, set: (obj, value) => { obj.step = value; } }, metadata: _metadata }, _step_initializers, _step_extraInitializers);
104
97
  __esDecorate(this, null, _width_decorators, { kind: "accessor", name: "width", static: false, private: false, access: { has: obj => "width" in obj, get: obj => obj.width, set: (obj, value) => { obj.width = value; } }, metadata: _metadata }, _width_initializers, _width_extraInitializers);
105
- __esDecorate(this, null, __theme_decorators, { kind: "accessor", name: "_theme", static: false, private: false, access: { has: obj => "_theme" in obj, get: obj => obj._theme, set: (obj, value) => { obj._theme = value; } }, metadata: _metadata }, __theme_initializers, __theme_extraInitializers);
106
- __esDecorate(this, null, _setTheme_decorators, { kind: "method", name: "setTheme", static: false, private: false, access: { has: obj => "setTheme" in obj, get: obj => obj.setTheme }, metadata: _metadata }, null, _instanceExtraInitializers);
107
98
  __esDecorate(this, null, _handleKey_decorators, { kind: "method", name: "handleKey", static: false, private: false, access: { has: obj => "handleKey" in obj, get: obj => obj.handleKey }, metadata: _metadata }, null, _instanceExtraInitializers);
108
99
  __esDecorate(this, null, _handleMouse_decorators, { kind: "method", name: "handleMouse", static: false, private: false, access: { has: obj => "handleMouse" in obj, get: obj => obj.handleMouse }, metadata: _metadata }, null, _instanceExtraInitializers);
109
100
  __esDecorate(this, null, _setValue_decorators, { kind: "method", name: "setValue", static: false, private: false, access: { has: obj => "setValue" in obj, get: obj => obj.setValue }, metadata: _metadata }, null, _instanceExtraInitializers);
@@ -126,15 +117,9 @@ let Slider = (() => {
126
117
  #width_accessor_storage = (__runInitializers(this, _step_extraInitializers), __runInitializers(this, _width_initializers, void 0));
127
118
  get width() { return this.#width_accessor_storage; }
128
119
  set width(value) { this.#width_accessor_storage = value; }
129
- #_theme_accessor_storage = (__runInitializers(this, _width_extraInitializers), __runInitializers(this, __theme_initializers, void 0));
130
- // [LAW:types-are-the-program] @observableRef so setTheme() triggers a
131
- // re-render — render() reads _theme.palette, so the theme reference must
132
- // participate in MobX reactivity for Screen's autorun to fire on swap.
133
- get _theme() { return this.#_theme_accessor_storage; }
134
- set _theme(value) { this.#_theme_accessor_storage = value; }
135
- _dragging = (__runInitializers(this, __theme_extraInitializers), false);
120
+ _dragging = (__runInitializers(this, _width_extraInitializers), false);
136
121
  constructor(options = {}) {
137
- super();
122
+ super(options.theme);
138
123
  this.id = options.id ?? `slider-${Math.random().toString(36).slice(2, 8)}`;
139
124
  this.min = options.min ?? 0;
140
125
  this.max = options.max ?? 100;
@@ -150,9 +135,7 @@ let Slider = (() => {
150
135
  this.width = width;
151
136
  this.value = clampSnap(options.value ?? this.min, this.min, this.max, this.step);
152
137
  this.disabled = options.disabled ?? false;
153
- this._theme = options.theme ?? DEFAULT_TERMINAL_THEME;
154
138
  }
155
- setTheme(theme) { this._theme = theme; }
156
139
  // --- Event handlers ---
157
140
  handleKey(event) {
158
141
  if (this.disabled)
@@ -225,14 +208,14 @@ let Slider = (() => {
225
208
  const markerIdx = Math.round(fraction * (this.width - 1));
226
209
  const baseAttrs = { underline: this.focused };
227
210
  const filledStyle = this.disabled
228
- ? new Style({ color: "#666666", bgcolor: "#333333", dim: true, ...baseAttrs })
229
- : new Style({ color: this.resolvePalette("primary"), ...baseAttrs });
211
+ ? new Style({ ...this.disabledInk, ...baseAttrs })
212
+ : new Style({ ...ink(this.theme, "text-primary", "background"), ...baseAttrs });
230
213
  const unfilledStyle = this.disabled
231
- ? new Style({ color: "#666666", bgcolor: "#333333", dim: true, ...baseAttrs })
232
- : new Style({ color: this.resolvePalette("surface"), ...baseAttrs });
214
+ ? new Style({ ...this.disabledInk, ...baseAttrs })
215
+ : new Style({ ...ink(this.theme, "foreground", "background"), dim: true, ...baseAttrs });
233
216
  const markerStyle = this.disabled
234
- ? new Style({ color: "#666666", bgcolor: "#333333", dim: true, bold: true, ...baseAttrs })
235
- : new Style({ color: this.resolvePalette("primary"), bold: true, ...baseAttrs });
217
+ ? new Style({ ...this.disabledInk, bold: true, ...baseAttrs })
218
+ : new Style({ ...ink(this.theme, "text-primary", "background"), bold: true, ...baseAttrs });
236
219
  const segments = [];
237
220
  if (markerIdx > 0) {
238
221
  segments.push(new Segment(trackChar.repeat(markerIdx), filledStyle));
@@ -247,12 +230,6 @@ let Slider = (() => {
247
230
  measure(_options) {
248
231
  return { minimum: this.width, maximum: this.width };
249
232
  }
250
- // --- Palette resolution ---
251
- resolvePalette(key) {
252
- const rgba = this._theme.palette.get(key);
253
- // [LAW:no-defensive-null-guards] palette must contain all keys.
254
- return ColorSpec.fromRgba(rgba);
255
- }
256
233
  };
257
234
  })();
258
235
  export { Slider };
@@ -22,10 +22,15 @@
22
22
  * [LAW:types-are-the-program] Three integer spaces coexist: `CellCol` (terminal
23
23
  * cell columns), `CodeUnit` (JS UTF-16 indices), and `CodePoint` (code-unit
24
24
  * offsets that are additionally on a Unicode code-point boundary — a subtype of
25
- * `CodeUnit`). `cursorPosition` is `CodePoint`; it is never inside a surrogate
26
- * pair by construction. Visual positions are `CellCol`. The three are never
25
+ * `CodeUnit`). `cursorPosition` is `CodePoint`, and stronger: its setter
26
+ * parses any offset to a grapheme-cluster boundary. Visual positions are `CellCol`. The three are never
27
27
  * interchangeable — the type system enforces this at every crossing point.
28
28
  *
29
+ * [LAW:one-source-of-truth] The cursor moves, deletes and draws one grapheme
30
+ * cluster at a time (`nextGrapheme` / `prevGrapheme`) — the unit `cellLen`
31
+ * measures — so `👍🏽` is one step and one cursor cell, never a glyph and a
32
+ * stray skin-tone swatch.
33
+ *
29
34
  * Keymap (readline / emacs compatible):
30
35
  *
31
36
  * ─── motion ───
@@ -57,10 +62,10 @@
57
62
  */
58
63
  import { Segment } from "../core/segment.js";
59
64
  import { Style } from "../core/style.js";
60
- import { type CellCol, type CodePoint } from "../core/cells.js";
65
+ import { type CellCol, type CodePoint, type CodeUnit } from "../core/cells.js";
61
66
  import { type RenderOptions } from "../core/protocol.js";
62
67
  import type { TerminalTheme } from "../core/color.js";
63
- import { WidgetBase } from "./widget-base.js";
68
+ import { ThemedWidget } from "./themed-widget.js";
64
69
  import type { KeyEvent, WidgetMouseEvent } from "./types.js";
65
70
  /**
66
71
  * A soft-wrap strategy. Given one logical line of text and cell-width budgets,
@@ -182,13 +187,16 @@ export interface TextInputOptions {
182
187
  */
183
188
  contentStyle?: Style;
184
189
  }
185
- export declare class TextInput extends WidgetBase {
190
+ export declare class TextInput extends ThemedWidget {
186
191
  readonly id: string;
187
192
  readonly focusable = true;
188
- accessor value: string;
189
- accessor cursorPosition: CodePoint;
193
+ private accessor _value;
194
+ private accessor _cursor;
195
+ get value(): string;
196
+ set value(v: string);
197
+ get cursorPosition(): CodePoint;
198
+ set cursorPosition(p: CodeUnit);
190
199
  accessor placeholder: string;
191
- private _theme;
192
200
  private readonly _maxLength;
193
201
  private readonly _password;
194
202
  private readonly _multiline;
@@ -217,9 +225,9 @@ export declare class TextInput extends WidgetBase {
217
225
  private _killBuffer;
218
226
  private _scrollStart;
219
227
  private _singleLineViewportStart;
228
+ private _singleLineAsciiOnly;
220
229
  readonly multiline: boolean;
221
230
  constructor(options?: TextInputOptions);
222
- setTheme(theme: TerminalTheme): void;
223
231
  handleKey(event: KeyEvent): void;
224
232
  handleMouse(event: WidgetMouseEvent): void;
225
233
  setHovered(value: boolean): void;
@@ -247,7 +255,9 @@ export declare class TextInput extends WidgetBase {
247
255
  private _lineStart;
248
256
  private _lineEnd;
249
257
  private _insertText;
258
+ protected get ground(): Style;
250
259
  protected draw(options: RenderOptions): Iterable<Segment>;
260
+ private _shown;
251
261
  private _renderSingleLine;
252
262
  private _renderMultiline;
253
263
  private _emitRowContent;
@@ -270,5 +280,4 @@ export declare class TextInput extends WidgetBase {
270
280
  * - no render has happened yet (cache is empty).
271
281
  */
272
282
  get scrollIndicatorText(): string | undefined;
273
- private resolvePalette;
274
283
  }