@promptctl/rich-js 0.18.0 → 0.18.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 (221) hide show
  1. package/dist/core/anchor.d.ts +45 -0
  2. package/dist/core/anchor.js +39 -0
  3. package/dist/core/ansi.d.ts +65 -0
  4. package/dist/core/ansi.js +231 -0
  5. package/dist/core/box.d.ts +143 -0
  6. package/dist/core/box.js +379 -0
  7. package/dist/core/cells.d.ts +159 -0
  8. package/dist/core/cells.js +287 -0
  9. package/dist/core/color.d.ts +246 -0
  10. package/dist/core/color.js +1038 -0
  11. package/dist/core/console.d.ts +165 -0
  12. package/dist/core/console.js +527 -0
  13. package/dist/core/emoji.d.ts +24 -0
  14. package/dist/core/emoji.js +391 -0
  15. package/dist/core/export-html.d.ts +59 -0
  16. package/dist/core/export-html.js +200 -0
  17. package/dist/core/export-lines.d.ts +121 -0
  18. package/dist/core/export-lines.js +141 -0
  19. package/dist/core/highlighter.d.ts +33 -0
  20. package/dist/core/highlighter.js +124 -0
  21. package/dist/core/json.d.ts +27 -0
  22. package/dist/core/json.js +53 -0
  23. package/dist/core/markup.d.ts +119 -0
  24. package/dist/core/markup.js +731 -0
  25. package/dist/core/measure.d.ts +27 -0
  26. package/dist/core/measure.js +62 -0
  27. package/dist/core/oklch.d.ts +161 -0
  28. package/dist/core/oklch.js +312 -0
  29. package/dist/core/osc8.d.ts +68 -0
  30. package/dist/core/osc8.js +90 -0
  31. package/dist/core/place.d.ts +30 -0
  32. package/dist/core/place.js +51 -0
  33. package/dist/core/pretty.d.ts +144 -0
  34. package/dist/core/pretty.js +476 -0
  35. package/dist/core/protocol.d.ts +267 -0
  36. package/dist/core/protocol.js +163 -0
  37. package/dist/core/render.d.ts +84 -0
  38. package/dist/core/render.js +145 -0
  39. package/dist/core/segment.d.ts +161 -0
  40. package/dist/core/segment.js +492 -0
  41. package/dist/core/spinnerData.d.ts +12 -0
  42. package/dist/core/spinnerData.js +117 -0
  43. package/dist/core/strip.d.ts +141 -0
  44. package/dist/core/strip.js +305 -0
  45. package/dist/core/style.d.ts +169 -0
  46. package/dist/core/style.js +695 -0
  47. package/dist/core/subscription.d.ts +12 -0
  48. package/dist/core/subscription.js +12 -0
  49. package/dist/core/text.d.ts +256 -0
  50. package/dist/core/text.js +976 -0
  51. package/dist/core/wrap.d.ts +41 -0
  52. package/dist/core/wrap.js +127 -0
  53. package/dist/host/app.d.ts +121 -0
  54. package/dist/host/app.js +255 -0
  55. package/dist/host/host-environment.d.ts +26 -0
  56. package/dist/host/host-environment.js +44 -0
  57. package/dist/host/index.d.ts +5 -0
  58. package/dist/host/index.js +3 -0
  59. package/dist/host/terminal-host.d.ts +179 -0
  60. package/dist/host/terminal-host.js +186 -0
  61. package/dist/index.d.ts +91 -0
  62. package/dist/index.js +107 -0
  63. package/dist/node/prompt.d.ts +21 -0
  64. package/dist/node/prompt.js +30 -0
  65. package/dist/node/save.d.ts +17 -0
  66. package/dist/node/save.js +21 -0
  67. package/dist/node/terminal-host.d.ts +113 -0
  68. package/dist/node/terminal-host.js +227 -0
  69. package/dist/node/traceback.d.ts +37 -0
  70. package/dist/node/traceback.js +134 -0
  71. package/dist/renderables/align.d.ts +16 -0
  72. package/dist/renderables/align.js +33 -0
  73. package/dist/renderables/columns.d.ts +61 -0
  74. package/dist/renderables/columns.js +152 -0
  75. package/dist/renderables/constrain.d.ts +15 -0
  76. package/dist/renderables/constrain.js +37 -0
  77. package/dist/renderables/embed.d.ts +50 -0
  78. package/dist/renderables/embed.js +71 -0
  79. package/dist/renderables/flexStrip.d.ts +41 -0
  80. package/dist/renderables/flexStrip.js +200 -0
  81. package/dist/renderables/group.d.ts +11 -0
  82. package/dist/renderables/group.js +17 -0
  83. package/dist/renderables/layout.d.ts +92 -0
  84. package/dist/renderables/layout.js +312 -0
  85. package/dist/renderables/live.d.ts +50 -0
  86. package/dist/renderables/live.js +175 -0
  87. package/dist/renderables/markdown.d.ts +24 -0
  88. package/dist/renderables/markdown.js +184 -0
  89. package/dist/renderables/padding.d.ts +38 -0
  90. package/dist/renderables/padding.js +141 -0
  91. package/dist/renderables/panel.d.ts +116 -0
  92. package/dist/renderables/panel.js +307 -0
  93. package/dist/renderables/progress.d.ts +90 -0
  94. package/dist/renderables/progress.js +238 -0
  95. package/dist/renderables/progressBar.d.ts +31 -0
  96. package/dist/renderables/progressBar.js +53 -0
  97. package/dist/renderables/prompt.d.ts +49 -0
  98. package/dist/renderables/prompt.js +125 -0
  99. package/dist/renderables/rule.d.ts +25 -0
  100. package/dist/renderables/rule.js +90 -0
  101. package/dist/renderables/spinner.d.ts +31 -0
  102. package/dist/renderables/spinner.js +70 -0
  103. package/dist/renderables/status.d.ts +23 -0
  104. package/dist/renderables/status.js +60 -0
  105. package/dist/renderables/syntax.d.ts +35 -0
  106. package/dist/renderables/syntax.js +115 -0
  107. package/dist/renderables/table.d.ts +194 -0
  108. package/dist/renderables/table.js +795 -0
  109. package/dist/renderables/traceback.d.ts +31 -0
  110. package/dist/renderables/traceback.js +108 -0
  111. package/dist/renderables/tree.d.ts +68 -0
  112. package/dist/renderables/tree.js +150 -0
  113. package/dist/renderables/viewport.d.ts +114 -0
  114. package/dist/renderables/viewport.js +198 -0
  115. package/dist/template-bindings/color-funcs.d.ts +87 -0
  116. package/dist/template-bindings/color-funcs.js +217 -0
  117. package/dist/template-bindings/helpers.d.ts +24 -0
  118. package/dist/template-bindings/helpers.js +48 -0
  119. package/dist/template-bindings/index.d.ts +107 -0
  120. package/dist/template-bindings/index.js +146 -0
  121. package/dist/template-bindings/palette-funcs.d.ts +94 -0
  122. package/dist/template-bindings/palette-funcs.js +141 -0
  123. package/dist/template-bindings/style-funcs.d.ts +28 -0
  124. package/dist/template-bindings/style-funcs.js +155 -0
  125. package/dist/themes/buildPalette.d.ts +36 -0
  126. package/dist/themes/buildPalette.js +56 -0
  127. package/dist/themes/colorMath.d.ts +82 -0
  128. package/dist/themes/colorMath.js +254 -0
  129. package/dist/themes/colorRef.d.ts +51 -0
  130. package/dist/themes/colorRef.js +96 -0
  131. package/dist/themes/data/ansi-tables.d.ts +14 -0
  132. package/dist/themes/data/ansi-tables.js +49 -0
  133. package/dist/themes/data/atom-one-dark.d.ts +3 -0
  134. package/dist/themes/data/atom-one-dark.js +177 -0
  135. package/dist/themes/data/atom-one-light.d.ts +3 -0
  136. package/dist/themes/data/atom-one-light.js +177 -0
  137. package/dist/themes/data/catppuccin-frappe.d.ts +3 -0
  138. package/dist/themes/data/catppuccin-frappe.js +177 -0
  139. package/dist/themes/data/catppuccin-latte.d.ts +3 -0
  140. package/dist/themes/data/catppuccin-latte.js +177 -0
  141. package/dist/themes/data/catppuccin-macchiato.d.ts +3 -0
  142. package/dist/themes/data/catppuccin-macchiato.js +177 -0
  143. package/dist/themes/data/catppuccin-mocha.d.ts +3 -0
  144. package/dist/themes/data/catppuccin-mocha.js +177 -0
  145. package/dist/themes/data/cyberpunk.d.ts +17 -0
  146. package/dist/themes/data/cyberpunk.js +193 -0
  147. package/dist/themes/data/default.d.ts +3 -0
  148. package/dist/themes/data/default.js +160 -0
  149. package/dist/themes/data/dracula.d.ts +3 -0
  150. package/dist/themes/data/dracula.js +177 -0
  151. package/dist/themes/data/flexoki.d.ts +3 -0
  152. package/dist/themes/data/flexoki.js +177 -0
  153. package/dist/themes/data/gruvbox.d.ts +3 -0
  154. package/dist/themes/data/gruvbox.js +177 -0
  155. package/dist/themes/data/index.d.ts +35 -0
  156. package/dist/themes/data/index.js +64 -0
  157. package/dist/themes/data/monokai.d.ts +3 -0
  158. package/dist/themes/data/monokai.js +177 -0
  159. package/dist/themes/data/nord.d.ts +3 -0
  160. package/dist/themes/data/nord.js +177 -0
  161. package/dist/themes/data/rose-pine-dawn.d.ts +3 -0
  162. package/dist/themes/data/rose-pine-dawn.js +177 -0
  163. package/dist/themes/data/rose-pine-moon.d.ts +3 -0
  164. package/dist/themes/data/rose-pine-moon.js +177 -0
  165. package/dist/themes/data/rose-pine.d.ts +3 -0
  166. package/dist/themes/data/rose-pine.js +177 -0
  167. package/dist/themes/data/solarized-dark.d.ts +3 -0
  168. package/dist/themes/data/solarized-dark.js +177 -0
  169. package/dist/themes/data/solarized-light.d.ts +3 -0
  170. package/dist/themes/data/solarized-light.js +177 -0
  171. package/dist/themes/data/svg-export.d.ts +3 -0
  172. package/dist/themes/data/svg-export.js +177 -0
  173. package/dist/themes/data/textual-ansi.d.ts +3 -0
  174. package/dist/themes/data/textual-ansi.js +160 -0
  175. package/dist/themes/data/textual-dark.d.ts +3 -0
  176. package/dist/themes/data/textual-dark.js +160 -0
  177. package/dist/themes/data/textual-light.d.ts +3 -0
  178. package/dist/themes/data/textual-light.js +160 -0
  179. package/dist/themes/data/tokyo-night.d.ts +3 -0
  180. package/dist/themes/data/tokyo-night.js +177 -0
  181. package/dist/themes/data/types.d.ts +31 -0
  182. package/dist/themes/data/types.js +10 -0
  183. package/dist/themes/palette.d.ts +21 -0
  184. package/dist/themes/palette.js +28 -0
  185. package/dist/themes/ramp.d.ts +83 -0
  186. package/dist/themes/ramp.js +122 -0
  187. package/dist/themes/registry.d.ts +44 -0
  188. package/dist/themes/registry.js +94 -0
  189. package/dist/themes/terminalThemes.d.ts +49 -0
  190. package/dist/themes/terminalThemes.js +63 -0
  191. package/dist/themes/transpose.d.ts +87 -0
  192. package/dist/themes/transpose.js +138 -0
  193. package/dist/widgets/button.d.ts +49 -0
  194. package/dist/widgets/button.js +208 -0
  195. package/dist/widgets/checkbox.d.ts +41 -0
  196. package/dist/widgets/checkbox.js +157 -0
  197. package/dist/widgets/dropdown.d.ts +67 -0
  198. package/dist/widgets/dropdown.js +450 -0
  199. package/dist/widgets/event-router.d.ts +71 -0
  200. package/dist/widgets/event-router.js +629 -0
  201. package/dist/widgets/focus-manager.d.ts +45 -0
  202. package/dist/widgets/focus-manager.js +191 -0
  203. package/dist/widgets/hit.d.ts +64 -0
  204. package/dist/widgets/hit.js +113 -0
  205. package/dist/widgets/index.d.ts +20 -0
  206. package/dist/widgets/index.js +14 -0
  207. package/dist/widgets/slider.d.ts +57 -0
  208. package/dist/widgets/slider.js +270 -0
  209. package/dist/widgets/static-item.d.ts +34 -0
  210. package/dist/widgets/static-item.js +54 -0
  211. package/dist/widgets/text-input.d.ts +274 -0
  212. package/dist/widgets/text-input.js +1165 -0
  213. package/dist/widgets/toggle.d.ts +44 -0
  214. package/dist/widgets/toggle.js +180 -0
  215. package/dist/widgets/types.d.ts +87 -0
  216. package/dist/widgets/types.js +30 -0
  217. package/dist/widgets/widget-app.d.ts +63 -0
  218. package/dist/widgets/widget-app.js +199 -0
  219. package/dist/widgets/widget-base.d.ts +40 -0
  220. package/dist/widgets/widget-base.js +165 -0
  221. package/package.json +6 -2
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Pre-built `TerminalTheme` constants — every theme in the registry has a
3
+ * matching `<NAME>` export here. There is no inline-only theme; the data
4
+ * file is the single source of truth for every theme's hex values.
5
+ *
6
+ * Editing `data/<name>.ts` updates both the registry's full ~150-var
7
+ * palette (via `getThemePalette(name)`) AND the matching `TerminalTheme`
8
+ * constant exported below (via `getThemeBaseColors(name)`, which pulls
9
+ * just the 8 substrate keys). The two views never drift because both
10
+ * derive from the same authored data.
11
+ *
12
+ * [LAW:one-source-of-truth] Hex values live in `data/<name>.ts`. This
13
+ * module is a derived view that builds a `TerminalTheme` from each
14
+ * theme's eight base colors via `buildPalette` for the substrate palette,
15
+ * and from the theme's own ANSI table for the sixteen named colours.
16
+ *
17
+ * [LAW:one-type-per-behavior] Every theme has the same shape — name,
18
+ * `dark` flag, full Palette in the registry, `TerminalTheme` constant
19
+ * here. Consumers can pick any theme by name without branching on which
20
+ * APIs work for it.
21
+ *
22
+ * [LAW:one-way-deps] `core/color → themes/palette` remains the only edge
23
+ * into themes/. This file imports only sibling theme modules and core
24
+ * color primitives; nothing in `core/` imports back.
25
+ */
26
+ import { TerminalTheme } from "../core/color.js";
27
+ import { buildPalette } from "./buildPalette.js";
28
+ import { getThemeBaseColors } from "./registry.js";
29
+ function defineTheme(d) {
30
+ return new TerminalTheme(d.bg, d.fg, d.ansi, buildPalette(d.name, d.dark, {
31
+ primary: d.primary,
32
+ secondary: d.secondary,
33
+ accent: d.accent,
34
+ success: d.success,
35
+ warning: d.warning,
36
+ error: d.error,
37
+ background: d.bg,
38
+ foreground: d.fg,
39
+ }));
40
+ }
41
+ export const DEFAULT_TERMINAL_THEME = defineTheme(getThemeBaseColors("default"));
42
+ export const SVG_EXPORT_THEME = defineTheme(getThemeBaseColors("svg-export"));
43
+ export const MONOKAI = defineTheme(getThemeBaseColors("monokai"));
44
+ export const NORD = defineTheme(getThemeBaseColors("nord"));
45
+ export const GRUVBOX = defineTheme(getThemeBaseColors("gruvbox"));
46
+ export const DRACULA = defineTheme(getThemeBaseColors("dracula"));
47
+ export const TOKYO_NIGHT = defineTheme(getThemeBaseColors("tokyo-night"));
48
+ export const FLEXOKI = defineTheme(getThemeBaseColors("flexoki"));
49
+ export const CYBERPUNK = defineTheme(getThemeBaseColors("cyberpunk"));
50
+ export const CATPPUCCIN_MOCHA = defineTheme(getThemeBaseColors("catppuccin-mocha"));
51
+ export const CATPPUCCIN_LATTE = defineTheme(getThemeBaseColors("catppuccin-latte"));
52
+ export const CATPPUCCIN_FRAPPE = defineTheme(getThemeBaseColors("catppuccin-frappe"));
53
+ export const CATPPUCCIN_MACCHIATO = defineTheme(getThemeBaseColors("catppuccin-macchiato"));
54
+ export const SOLARIZED_DARK = defineTheme(getThemeBaseColors("solarized-dark"));
55
+ export const SOLARIZED_LIGHT = defineTheme(getThemeBaseColors("solarized-light"));
56
+ export const ROSE_PINE = defineTheme(getThemeBaseColors("rose-pine"));
57
+ export const ROSE_PINE_MOON = defineTheme(getThemeBaseColors("rose-pine-moon"));
58
+ export const ROSE_PINE_DAWN = defineTheme(getThemeBaseColors("rose-pine-dawn"));
59
+ export const ATOM_ONE_DARK = defineTheme(getThemeBaseColors("atom-one-dark"));
60
+ export const ATOM_ONE_LIGHT = defineTheme(getThemeBaseColors("atom-one-light"));
61
+ export const TEXTUAL_DARK = defineTheme(getThemeBaseColors("textual-dark"));
62
+ export const TEXTUAL_LIGHT = defineTheme(getThemeBaseColors("textual-light"));
63
+ export const TEXTUAL_ANSI = defineTheme(getThemeBaseColors("textual-ansi"));
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Transpose a Palette to a new "key" — analogous to transposing a melody.
3
+ *
4
+ * melody / chord progression :: Palette (relationships between colors)
5
+ * key (signature) :: ThemeKey (hue / chroma / lightness deltas)
6
+ * "in C major" / "in D…" :: the resulting transposed Palette
7
+ *
8
+ * Because OKLCH is perceptually uniform, "+30° hue" looks like a
9
+ * consistent jump everywhere on the color wheel — the way a perfect-fifth
10
+ * interval sounds the same in every musical key. Transposition is closed
11
+ * under composition: `transpose(transpose(p, k1), k2)` produces the same
12
+ * colors as a single transpose with the combined deltas, modulo round-trip
13
+ * quantization.
14
+ *
15
+ * [LAW:dataflow-not-control-flow] A single uniform per-color transform
16
+ * runs for every var in the palette. Anchor protection selects *which*
17
+ * `ThemeKey` to apply (data), not *whether* to apply one (branch).
18
+ *
19
+ * [LAW:one-source-of-truth] Anchor classification lives only in
20
+ * `ANCHORED_ROOTS` below. The buildPalette derivation guarantees every
21
+ * variant of a semantic root shares the root as its hyphen prefix
22
+ * (`error`, `error-darken-1`, `error-lighten-2`, ...), so one set covers
23
+ * the whole family.
24
+ *
25
+ * [LAW:one-way-deps] Imports flow `core/oklch → themes/transpose`;
26
+ * nothing in core/ depends back on this file.
27
+ */
28
+ import { type ThemeKey } from "../core/oklch.js";
29
+ import { Palette } from "./palette.js";
30
+ /**
31
+ * Semantic roots whose hue is locked under transposition. `error` must
32
+ * look red-ish, `success` green-ish, `warning` amber-ish — rotating the
33
+ * hue would make the UI lie about meaning. Lightness and chroma *still*
34
+ * transform for these roles, so they invert correctly during dark↔light
35
+ * flips and respond to chroma scaling alongside everything else.
36
+ */
37
+ export declare const ANCHORED_ROOTS: ReadonlySet<string>;
38
+ /**
39
+ * Whether a palette var's hue is locked under transposition. The single
40
+ * predicate used by `transposePalette`. Exported so callers building
41
+ * higher-level theme machinery can stay consistent with the locking rule.
42
+ */
43
+ export declare function isAnchored(varName: string): boolean;
44
+ /**
45
+ * Return a new `Palette` whose colors are the transposition of `palette`'s
46
+ * colors by `key`. Pure. Identity (`IDENTITY`) returns a Palette with byte-exact
47
+ * colors — fast-pathed so identity does not pay the sRGB↔OKLCH round-trip
48
+ * quantization cost.
49
+ *
50
+ * The `dark` flag of the result is derived from the actual lightness of
51
+ * the resulting `background` var (`Oklch.fromRgba(bg).l < 0.5`) — *not*
52
+ * from the key's coefficients. The strongest theorem: "dark iff
53
+ * background is dark." This is honest under every transform — pure
54
+ * lightness shifts, mirror-inversions, hue rotations that don't touch L,
55
+ * and combinations of all three. [LAW:types-are-the-program]
56
+ *
57
+ * The transposing path throws if the palette has no `background` var (the
58
+ * `dark`-flag derivation has nothing to read). Failing loudly is preferred
59
+ * over a silent fallback because the alternative — trusting the source
60
+ * `palette.dark` after an arbitrary L-transform — produces flags that lie.
61
+ * The identity fast-path is exempt: it preserves the source `dark` flag
62
+ * verbatim (no derivation), so it needs no `background` and never throws.
63
+ *
64
+ * @param name Optional override for the resulting palette name. Defaults
65
+ * to the source palette's name. Callers building a family of transposed
66
+ * palettes (e.g. "gruvbox +60°") supply their own.
67
+ */
68
+ export declare function transposePalette(palette: Palette, key: ThemeKey, name?: string): Palette;
69
+ /**
70
+ * Build the `ThemeKey` that rotates `palette` so its *tonic* var lands on
71
+ * `targetHueDeg`. The musical operation directly: a key is the set of
72
+ * intervals from the tonic, so "play this theme in the key of <hue>" means
73
+ * "shift every color by exactly the interval that carries the tonic's
74
+ * current hue to the target." Pick the tonic's pitch and the rest follows.
75
+ *
76
+ * Returns a hue-only key (chroma and lightness untouched). Callers that also
77
+ * want to scale chroma or shift lightness spread their own axes over the
78
+ * result — those are independent transposition dimensions, not part of
79
+ * choosing the key. [LAW:one-type-per-behavior] a degree-shift key and a
80
+ * root-note key are the *same* transform; this is just a second constructor
81
+ * for it, so `transposePalette` stays untouched.
82
+ *
83
+ * Throws if `tonicVar` is absent — the interval has no anchor to measure
84
+ * from, so there is no honest key to return. Failing loudly beats inventing
85
+ * a zero shift that would silently mean "no transposition."
86
+ */
87
+ export declare function themeKeyForRoot(palette: Palette, tonicVar: string, targetHueDeg: number): ThemeKey;
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Transpose a Palette to a new "key" — analogous to transposing a melody.
3
+ *
4
+ * melody / chord progression :: Palette (relationships between colors)
5
+ * key (signature) :: ThemeKey (hue / chroma / lightness deltas)
6
+ * "in C major" / "in D…" :: the resulting transposed Palette
7
+ *
8
+ * Because OKLCH is perceptually uniform, "+30° hue" looks like a
9
+ * consistent jump everywhere on the color wheel — the way a perfect-fifth
10
+ * interval sounds the same in every musical key. Transposition is closed
11
+ * under composition: `transpose(transpose(p, k1), k2)` produces the same
12
+ * colors as a single transpose with the combined deltas, modulo round-trip
13
+ * quantization.
14
+ *
15
+ * [LAW:dataflow-not-control-flow] A single uniform per-color transform
16
+ * runs for every var in the palette. Anchor protection selects *which*
17
+ * `ThemeKey` to apply (data), not *whether* to apply one (branch).
18
+ *
19
+ * [LAW:one-source-of-truth] Anchor classification lives only in
20
+ * `ANCHORED_ROOTS` below. The buildPalette derivation guarantees every
21
+ * variant of a semantic root shares the root as its hyphen prefix
22
+ * (`error`, `error-darken-1`, `error-lighten-2`, ...), so one set covers
23
+ * the whole family.
24
+ *
25
+ * [LAW:one-way-deps] Imports flow `core/oklch → themes/transpose`;
26
+ * nothing in core/ depends back on this file.
27
+ */
28
+ import { Oklch, isIdentityKey } from "../core/oklch.js";
29
+ import { Palette } from "./palette.js";
30
+ /**
31
+ * Semantic roots whose hue is locked under transposition. `error` must
32
+ * look red-ish, `success` green-ish, `warning` amber-ish — rotating the
33
+ * hue would make the UI lie about meaning. Lightness and chroma *still*
34
+ * transform for these roles, so they invert correctly during dark↔light
35
+ * flips and respond to chroma scaling alongside everything else.
36
+ */
37
+ // [LAW:types-are-the-program] The `ReadonlySet` type is the immutability
38
+ // enforcement — typed code cannot call `add`/`delete`. (`Object.freeze` is
39
+ // not used here because it is a no-op on Set membership; relying on it would
40
+ // imply a runtime guarantee it does not provide.)
41
+ export const ANCHORED_ROOTS = new Set([
42
+ "error",
43
+ "success",
44
+ "warning",
45
+ ]);
46
+ function rootOf(varName) {
47
+ const dash = varName.indexOf("-");
48
+ return dash === -1 ? varName : varName.slice(0, dash);
49
+ }
50
+ /**
51
+ * Whether a palette var's hue is locked under transposition. The single
52
+ * predicate used by `transposePalette`. Exported so callers building
53
+ * higher-level theme machinery can stay consistent with the locking rule.
54
+ */
55
+ export function isAnchored(varName) {
56
+ return ANCHORED_ROOTS.has(rootOf(varName));
57
+ }
58
+ /**
59
+ * Return a new `Palette` whose colors are the transposition of `palette`'s
60
+ * colors by `key`. Pure. Identity (`IDENTITY`) returns a Palette with byte-exact
61
+ * colors — fast-pathed so identity does not pay the sRGB↔OKLCH round-trip
62
+ * quantization cost.
63
+ *
64
+ * The `dark` flag of the result is derived from the actual lightness of
65
+ * the resulting `background` var (`Oklch.fromRgba(bg).l < 0.5`) — *not*
66
+ * from the key's coefficients. The strongest theorem: "dark iff
67
+ * background is dark." This is honest under every transform — pure
68
+ * lightness shifts, mirror-inversions, hue rotations that don't touch L,
69
+ * and combinations of all three. [LAW:types-are-the-program]
70
+ *
71
+ * The transposing path throws if the palette has no `background` var (the
72
+ * `dark`-flag derivation has nothing to read). Failing loudly is preferred
73
+ * over a silent fallback because the alternative — trusting the source
74
+ * `palette.dark` after an arbitrary L-transform — produces flags that lie.
75
+ * The identity fast-path is exempt: it preserves the source `dark` flag
76
+ * verbatim (no derivation), so it needs no `background` and never throws.
77
+ *
78
+ * @param name Optional override for the resulting palette name. Defaults
79
+ * to the source palette's name. Callers building a family of transposed
80
+ * palettes (e.g. "gruvbox +60°") supply their own.
81
+ */
82
+ export function transposePalette(palette, key, name) {
83
+ if (isIdentityKey(key)) {
84
+ return new Palette(name ?? palette.name, palette.dark, palette.vars);
85
+ }
86
+ // Anchors share *everything except* hue with the user's key. They still
87
+ // lightness-invert in a dark↔light flip; they still chroma-scale in a
88
+ // saturation sweep — only their hue is held.
89
+ const anchorKey = { ...key, hueShift: 0 };
90
+ const next = new Map();
91
+ for (const [varName, color] of palette.vars) {
92
+ const effective = isAnchored(varName) ? anchorKey : key;
93
+ next.set(varName, Oklch.fromRgba(color).applyKey(effective).toRgba());
94
+ }
95
+ const newBackground = next.get("background");
96
+ if (newBackground === undefined) {
97
+ throw new Error(`transposePalette: palette "${palette.name}" has no "background" ` +
98
+ `var; cannot derive the dark flag without a background color.`);
99
+ }
100
+ const newDark = Oklch.fromRgba(newBackground).l < 0.5;
101
+ return new Palette(name ?? palette.name, newDark, next);
102
+ }
103
+ /**
104
+ * Build the `ThemeKey` that rotates `palette` so its *tonic* var lands on
105
+ * `targetHueDeg`. The musical operation directly: a key is the set of
106
+ * intervals from the tonic, so "play this theme in the key of <hue>" means
107
+ * "shift every color by exactly the interval that carries the tonic's
108
+ * current hue to the target." Pick the tonic's pitch and the rest follows.
109
+ *
110
+ * Returns a hue-only key (chroma and lightness untouched). Callers that also
111
+ * want to scale chroma or shift lightness spread their own axes over the
112
+ * result — those are independent transposition dimensions, not part of
113
+ * choosing the key. [LAW:one-type-per-behavior] a degree-shift key and a
114
+ * root-note key are the *same* transform; this is just a second constructor
115
+ * for it, so `transposePalette` stays untouched.
116
+ *
117
+ * Throws if `tonicVar` is absent — the interval has no anchor to measure
118
+ * from, so there is no honest key to return. Failing loudly beats inventing
119
+ * a zero shift that would silently mean "no transposition."
120
+ */
121
+ export function themeKeyForRoot(palette, tonicVar, targetHueDeg) {
122
+ // Validate the numeric input at the boundary: a non-finite target would
123
+ // propagate as NaN to Oklch's constructor several calls downstream, where
124
+ // the error is far less actionable.
125
+ if (!Number.isFinite(targetHueDeg)) {
126
+ throw new RangeError(`themeKeyForRoot: targetHueDeg must be a finite number; got ${targetHueDeg}`);
127
+ }
128
+ const tonic = palette.get(tonicVar);
129
+ if (tonic === undefined) {
130
+ throw new Error(`themeKeyForRoot: palette "${palette.name}" has no "${tonicVar}" var ` +
131
+ `to use as the tonic; cannot measure the transposition interval.`);
132
+ }
133
+ const tonicHue = Oklch.fromRgba(tonic).h;
134
+ let hueShift = (targetHueDeg - tonicHue) % 360;
135
+ if (hueShift < 0)
136
+ hueShift += 360;
137
+ return { hueShift, chromaScale: 1, lightnessScale: 1, lightnessShift: 0 };
138
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Button widget — labeled action trigger with variant styling.
3
+ * [LAW:dataflow-not-control-flow] rendering is a pure function of observable state.
4
+ * [LAW:one-type-per-behavior] shared widget infrastructure lives on WidgetBase.
5
+ *
6
+ * Four visual states:
7
+ * normal — variant colors from theme semantic palette (muted)
8
+ * hover — full variant accent bg + on-accent fg (WCAG contrast)
9
+ * focus — brackets [ label ] surrounding the button
10
+ * active — same color pair as hover, plus bold (pressed cue)
11
+ *
12
+ * States compose: active > focus > hover > normal. Active and hover
13
+ * deliberately share colors — active differentiates via bold rather
14
+ * than fg/bg inversion, because inversion produces mostly-accent text
15
+ * on bg-tinted surface, which is unreadable for accents whose contrast
16
+ * partner depends on luminance.
17
+ */
18
+ import { Segment } from "../core/segment.js";
19
+ import type { RenderOptions } from "../core/protocol.js";
20
+ import type { TerminalTheme } from "../core/color.js";
21
+ import { WidgetBase } from "./widget-base.js";
22
+ import type { KeyEvent, WidgetMouseEvent } from "./types.js";
23
+ export type ButtonVariant = "default" | "primary" | "success" | "warning" | "danger";
24
+ export interface ButtonOptions {
25
+ label: string;
26
+ variant?: ButtonVariant;
27
+ id?: string;
28
+ disabled?: boolean;
29
+ theme?: TerminalTheme;
30
+ }
31
+ export declare class Button extends WidgetBase {
32
+ readonly id: string;
33
+ readonly focusable = true;
34
+ accessor label: string;
35
+ accessor variant: ButtonVariant;
36
+ private accessor _theme;
37
+ constructor(options: ButtonOptions);
38
+ setTheme(theme: TerminalTheme): void;
39
+ handleKey(event: KeyEvent): void;
40
+ handleMouse(event: WidgetMouseEvent): void;
41
+ setActive(value: boolean): void;
42
+ protected draw(_options: RenderOptions): Iterable<Segment>;
43
+ measure(_options: RenderOptions): {
44
+ minimum: number;
45
+ maximum: number;
46
+ };
47
+ private resolveColors;
48
+ private resolvePalette;
49
+ }
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Button widget — labeled action trigger with variant styling.
3
+ * [LAW:dataflow-not-control-flow] rendering is a pure function of observable state.
4
+ * [LAW:one-type-per-behavior] shared widget infrastructure lives on WidgetBase.
5
+ *
6
+ * Four visual states:
7
+ * normal — variant colors from theme semantic palette (muted)
8
+ * hover — full variant accent bg + on-accent fg (WCAG contrast)
9
+ * focus — brackets [ label ] surrounding the button
10
+ * active — same color pair as hover, plus bold (pressed cue)
11
+ *
12
+ * States compose: active > focus > hover > normal. Active and hover
13
+ * deliberately share colors — active differentiates via bold rather
14
+ * than fg/bg inversion, because inversion produces mostly-accent text
15
+ * on bg-tinted surface, which is unreadable for accents whose contrast
16
+ * partner depends on luminance.
17
+ */
18
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
19
+ var useValue = arguments.length > 2;
20
+ for (var i = 0; i < initializers.length; i++) {
21
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
22
+ }
23
+ return useValue ? value : void 0;
24
+ };
25
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
26
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
27
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
28
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
29
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
30
+ var _, done = false;
31
+ for (var i = decorators.length - 1; i >= 0; i--) {
32
+ var context = {};
33
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
34
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
35
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
36
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
37
+ if (kind === "accessor") {
38
+ if (result === void 0) continue;
39
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
40
+ if (_ = accept(result.get)) descriptor.get = _;
41
+ if (_ = accept(result.set)) descriptor.set = _;
42
+ if (_ = accept(result.init)) initializers.unshift(_);
43
+ }
44
+ else if (_ = accept(result)) {
45
+ if (kind === "field") initializers.unshift(_);
46
+ else descriptor[key] = _;
47
+ }
48
+ }
49
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
50
+ done = true;
51
+ };
52
+ import { observable, action, observableRef } from "mobx";
53
+ import { Segment } from "../core/segment.js";
54
+ import { Style } from "../core/style.js";
55
+ import { ColorSpec } from "../core/color.js";
56
+ import { cellLen } from "../core/cells.js";
57
+ import { DEFAULT_TERMINAL_THEME } from "../themes/terminalThemes.js";
58
+ import { WidgetBase } from "./widget-base.js";
59
+ // Variant → palette key mapping. Per variant:
60
+ // bg / fg — normal state. Muted accent bg + mostly-accent fg → readable.
61
+ // hover — full accent bg; pair with hoverFg, NOT with `fg`. The
62
+ // text-* keys are mostly-accent and would clash on a full
63
+ // accent bg.
64
+ // hoverFg — WCAG-correct contrast colour (on-${accent}) for full bg.
65
+ const VARIANT_KEYS = {
66
+ default: { bg: "surface", fg: "foreground", hover: "primary", hoverFg: "on-primary" },
67
+ primary: { bg: "primary-muted", fg: "text-primary", hover: "primary", hoverFg: "on-primary" },
68
+ success: { bg: "success-muted", fg: "text-success", hover: "success", hoverFg: "on-success" },
69
+ warning: { bg: "warning-muted", fg: "text-warning", hover: "warning", hoverFg: "on-warning" },
70
+ danger: { bg: "error-muted", fg: "text-error", hover: "error", hoverFg: "on-error" },
71
+ };
72
+ let Button = (() => {
73
+ let _classSuper = WidgetBase;
74
+ let _instanceExtraInitializers = [];
75
+ let _label_decorators;
76
+ let _label_initializers = [];
77
+ let _label_extraInitializers = [];
78
+ let _variant_decorators;
79
+ let _variant_initializers = [];
80
+ let _variant_extraInitializers = [];
81
+ let __theme_decorators;
82
+ let __theme_initializers = [];
83
+ let __theme_extraInitializers = [];
84
+ let _setTheme_decorators;
85
+ let _handleKey_decorators;
86
+ let _handleMouse_decorators;
87
+ let _setActive_decorators;
88
+ return class Button extends _classSuper {
89
+ static {
90
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
91
+ _label_decorators = [observable];
92
+ _variant_decorators = [observableRef];
93
+ __theme_decorators = [observableRef];
94
+ _setTheme_decorators = [action];
95
+ _handleKey_decorators = [action];
96
+ _handleMouse_decorators = [action];
97
+ _setActive_decorators = [action];
98
+ __esDecorate(this, null, _label_decorators, { kind: "accessor", name: "label", static: false, private: false, access: { has: obj => "label" in obj, get: obj => obj.label, set: (obj, value) => { obj.label = value; } }, metadata: _metadata }, _label_initializers, _label_extraInitializers);
99
+ __esDecorate(this, null, _variant_decorators, { kind: "accessor", name: "variant", static: false, private: false, access: { has: obj => "variant" in obj, get: obj => obj.variant, set: (obj, value) => { obj.variant = value; } }, metadata: _metadata }, _variant_initializers, _variant_extraInitializers);
100
+ __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);
101
+ __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);
102
+ __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);
103
+ __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);
104
+ __esDecorate(this, null, _setActive_decorators, { kind: "method", name: "setActive", static: false, private: false, access: { has: obj => "setActive" in obj, get: obj => obj.setActive }, metadata: _metadata }, null, _instanceExtraInitializers);
105
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
106
+ }
107
+ id = __runInitializers(this, _instanceExtraInitializers);
108
+ focusable = true;
109
+ #label_accessor_storage = __runInitializers(this, _label_initializers, void 0);
110
+ get label() { return this.#label_accessor_storage; }
111
+ set label(value) { this.#label_accessor_storage = value; }
112
+ #variant_accessor_storage = (__runInitializers(this, _label_extraInitializers), __runInitializers(this, _variant_initializers, void 0));
113
+ get variant() { return this.#variant_accessor_storage; }
114
+ set variant(value) { this.#variant_accessor_storage = value; }
115
+ #_theme_accessor_storage = (__runInitializers(this, _variant_extraInitializers), __runInitializers(this, __theme_initializers, void 0));
116
+ // [LAW:types-are-the-program] @observableRef so setTheme() triggers a
117
+ // re-render — see slider.ts.
118
+ get _theme() { return this.#_theme_accessor_storage; }
119
+ set _theme(value) { this.#_theme_accessor_storage = value; }
120
+ constructor(options) {
121
+ super();
122
+ __runInitializers(this, __theme_extraInitializers);
123
+ this.id = options.id ?? `button-${options.label.toLowerCase().replace(/\s+/g, "-")}`;
124
+ this.label = options.label;
125
+ this.variant = options.variant ?? "default";
126
+ this.disabled = options.disabled ?? false;
127
+ this._theme = options.theme ?? DEFAULT_TERMINAL_THEME;
128
+ }
129
+ setTheme(theme) { this._theme = theme; }
130
+ // --- Event handlers ---
131
+ handleKey(event) {
132
+ if (this.disabled)
133
+ return;
134
+ if (event.key === "enter" || event.key === "space") {
135
+ this.active = true;
136
+ this.emitSubmit();
137
+ // [LAW:one-source-of-truth] Keyboard activation must leave the widget
138
+ // in the same end state as mouse activation: `active` cleared after
139
+ // the press. Mouse has a natural mouse_up to clear it; keyboard does
140
+ // not, so we schedule the clear on the next microtask. The single-
141
+ // frame `active=true` paint gives the user the visual "pressed" cue
142
+ // and is then cleared, matching mouse behaviour.
143
+ queueMicrotask(() => { if (this.active)
144
+ this.setActive(false); });
145
+ event.stop();
146
+ }
147
+ }
148
+ handleMouse(event) {
149
+ if (this.disabled)
150
+ return;
151
+ if (event.type === "mouse_down") {
152
+ this.active = true;
153
+ }
154
+ // A release that dragged off the button cancels the press.
155
+ if (event.type === "mouse_up") {
156
+ if (this.active) {
157
+ this.active = false;
158
+ if (event.over)
159
+ this.emitSubmit();
160
+ }
161
+ }
162
+ }
163
+ // --- Active mutator (the keyboard-activation microtask uses this) ---
164
+ setActive(value) { this.active = value; }
165
+ // --- Rendering ---
166
+ draw(_options) {
167
+ // [LAW:dataflow-not-control-flow] same segment count and width every state
168
+ const focused = this.focused;
169
+ const left = focused ? "[" : " ";
170
+ const right = focused ? "]" : " ";
171
+ const text = `${left} ${this.label} ${right}`;
172
+ if (this.disabled) {
173
+ return [new Segment(text, new Style({ color: "#666666", bgcolor: "#333333", dim: true }))];
174
+ }
175
+ // Active and hover share the same colour pair (full accent bg + on-accent fg).
176
+ // Active is differentiated by bold, not by inverting fg/bg — inversion gives
177
+ // mostly-accent text on mostly-bg-tinted background, which is unreadable for
178
+ // accents whose contrast partner depends on luminance.
179
+ if (this.active || this.hovered) {
180
+ const fg = this.resolvePalette(VARIANT_KEYS[this.variant].hoverFg);
181
+ const bg = this.resolvePalette(VARIANT_KEYS[this.variant].hover);
182
+ return [new Segment(text, new Style({ color: fg, bgcolor: bg, bold: this.active }))];
183
+ }
184
+ const { fg, bg } = this.resolveColors("bg");
185
+ return [new Segment(text, new Style({ color: fg, bgcolor: bg }))];
186
+ }
187
+ measure(_options) {
188
+ // [LAW:one-source-of-truth] cellLen is the cell-width authority; .length
189
+ // counts UTF-16 code units and miscounts wide / emoji characters.
190
+ const width = cellLen(this.label) + 4;
191
+ return { minimum: width, maximum: width };
192
+ }
193
+ // --- Palette resolution ---
194
+ resolveColors(bgKey) {
195
+ const keys = VARIANT_KEYS[this.variant];
196
+ return {
197
+ fg: this.resolvePalette(keys.fg),
198
+ bg: this.resolvePalette(bgKey === "hover" ? keys.hover : keys.bg),
199
+ };
200
+ }
201
+ resolvePalette(key) {
202
+ const rgba = this._theme.palette.get(key);
203
+ // [LAW:no-defensive-null-guards] palette is required and must contain all keys.
204
+ return ColorSpec.fromRgba(rgba);
205
+ }
206
+ };
207
+ })();
208
+ export { Button };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Checkbox widget — boolean toggle with label.
3
+ * [LAW:dataflow-not-control-flow] one Segment of fixed width every render;
4
+ * the indicator character and style come from observable state.
5
+ * [LAW:one-type-per-behavior] shared widget infrastructure lives on WidgetBase.
6
+ *
7
+ * Visual states:
8
+ * unchecked — "[ ] label"
9
+ * checked — "[✓] label" (ASCII fallback "[x] label" when options.asciiOnly)
10
+ * focused — underline on the rendered segment (no width change)
11
+ * disabled — dimmed
12
+ */
13
+ import { Segment } from "../core/segment.js";
14
+ import { type RenderOptions } from "../core/protocol.js";
15
+ import type { TerminalTheme } from "../core/color.js";
16
+ import { WidgetBase } from "./widget-base.js";
17
+ import type { KeyEvent, WidgetMouseEvent } from "./types.js";
18
+ export interface CheckboxOptions {
19
+ label: string;
20
+ checked?: boolean;
21
+ id?: string;
22
+ disabled?: boolean;
23
+ theme?: TerminalTheme;
24
+ }
25
+ export declare class Checkbox extends WidgetBase {
26
+ readonly id: string;
27
+ readonly focusable = true;
28
+ accessor label: string;
29
+ accessor checked: boolean;
30
+ private accessor _theme;
31
+ constructor(options: CheckboxOptions);
32
+ setTheme(theme: TerminalTheme): void;
33
+ handleKey(event: KeyEvent): void;
34
+ handleMouse(event: WidgetMouseEvent): void;
35
+ protected draw(options: RenderOptions): Iterable<Segment>;
36
+ measure(_options: RenderOptions): {
37
+ minimum: number;
38
+ maximum: number;
39
+ };
40
+ private resolvePalette;
41
+ }