@promptctl/rich-js 0.18.0 → 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.
- package/README.md +9 -7
- package/dist/core/anchor.d.ts +45 -0
- package/dist/core/anchor.js +39 -0
- package/dist/core/ansi.d.ts +65 -0
- package/dist/core/ansi.js +231 -0
- package/dist/core/box.d.ts +145 -0
- package/dist/core/box.js +372 -0
- package/dist/core/cells.d.ts +192 -0
- package/dist/core/cells.js +334 -0
- package/dist/core/clock.d.ts +48 -0
- package/dist/core/clock.js +42 -0
- package/dist/core/color.d.ts +326 -0
- package/dist/core/color.js +1225 -0
- package/dist/core/console.d.ts +196 -0
- package/dist/core/console.js +596 -0
- package/dist/core/easing.d.ts +86 -0
- package/dist/core/easing.js +171 -0
- package/dist/core/emoji.d.ts +24 -0
- package/dist/core/emoji.js +391 -0
- package/dist/core/env.d.ts +16 -0
- package/dist/core/env.js +16 -0
- package/dist/core/export-html.d.ts +59 -0
- package/dist/core/export-html.js +197 -0
- package/dist/core/export-lines.d.ts +130 -0
- package/dist/core/export-lines.js +159 -0
- package/dist/core/export-svg.d.ts +49 -0
- package/dist/core/export-svg.js +213 -0
- package/dist/core/fnv1a.d.ts +10 -0
- package/dist/core/fnv1a.js +17 -0
- package/dist/core/highlighter.d.ts +33 -0
- package/dist/core/highlighter.js +190 -0
- package/dist/core/json.d.ts +27 -0
- package/dist/core/json.js +53 -0
- package/dist/core/markup.d.ts +140 -0
- package/dist/core/markup.js +654 -0
- package/dist/core/measure.d.ts +27 -0
- package/dist/core/measure.js +67 -0
- package/dist/core/memo.d.ts +19 -0
- package/dist/core/memo.js +34 -0
- package/dist/core/oklch.d.ts +161 -0
- package/dist/core/oklch.js +312 -0
- package/dist/core/osc8.d.ts +68 -0
- package/dist/core/osc8.js +78 -0
- package/dist/core/paint.d.ts +107 -0
- package/dist/core/paint.js +150 -0
- package/dist/core/place.d.ts +30 -0
- package/dist/core/place.js +49 -0
- package/dist/core/pretty.d.ts +247 -0
- package/dist/core/pretty.js +906 -0
- package/dist/core/protocol.d.ts +305 -0
- package/dist/core/protocol.js +183 -0
- package/dist/core/render.d.ts +87 -0
- package/dist/core/render.js +105 -0
- package/dist/core/segment.d.ts +162 -0
- package/dist/core/segment.js +488 -0
- package/dist/core/spinnerData.d.ts +12 -0
- package/dist/core/spinnerData.js +117 -0
- package/dist/core/strip.d.ts +152 -0
- package/dist/core/strip.js +326 -0
- package/dist/core/style.d.ts +189 -0
- package/dist/core/style.js +758 -0
- package/dist/core/subscription.d.ts +12 -0
- package/dist/core/subscription.js +12 -0
- package/dist/core/text.d.ts +283 -0
- package/dist/core/text.js +1097 -0
- package/dist/core/wrap.d.ts +46 -0
- package/dist/core/wrap.js +140 -0
- package/dist/host/app.d.ts +133 -0
- package/dist/host/app.js +285 -0
- package/dist/host/host-environment.d.ts +26 -0
- package/dist/host/host-environment.js +44 -0
- package/dist/host/index.d.ts +6 -0
- package/dist/host/index.js +3 -0
- package/dist/host/terminal-host.d.ts +180 -0
- package/dist/host/terminal-host.js +186 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.js +114 -0
- package/dist/node/prompt.d.ts +34 -0
- package/dist/node/prompt.js +51 -0
- package/dist/node/save.d.ts +18 -0
- package/dist/node/save.js +24 -0
- package/dist/node/terminal-host.d.ts +114 -0
- package/dist/node/terminal-host.js +227 -0
- package/dist/node/traceback.d.ts +38 -0
- package/dist/node/traceback.js +98 -0
- package/dist/renderables/align.d.ts +16 -0
- package/dist/renderables/align.js +26 -0
- package/dist/renderables/columns.d.ts +77 -0
- package/dist/renderables/columns.js +191 -0
- package/dist/renderables/constrain.d.ts +15 -0
- package/dist/renderables/constrain.js +31 -0
- package/dist/renderables/effect.d.ts +98 -0
- package/dist/renderables/effect.js +160 -0
- package/dist/renderables/embed.d.ts +107 -0
- package/dist/renderables/embed.js +160 -0
- package/dist/renderables/flexStrip.d.ts +41 -0
- package/dist/renderables/flexStrip.js +200 -0
- package/dist/renderables/group.d.ts +14 -0
- package/dist/renderables/group.js +22 -0
- package/dist/renderables/layout.d.ts +75 -0
- package/dist/renderables/layout.js +223 -0
- package/dist/renderables/live.d.ts +74 -0
- package/dist/renderables/live.js +188 -0
- package/dist/renderables/markdown.d.ts +38 -0
- package/dist/renderables/markdown.js +587 -0
- package/dist/renderables/padding.d.ts +59 -0
- package/dist/renderables/padding.js +147 -0
- package/dist/renderables/panel.d.ts +114 -0
- package/dist/renderables/panel.js +303 -0
- package/dist/renderables/progress.d.ts +178 -0
- package/dist/renderables/progress.js +362 -0
- package/dist/renderables/progressBar.d.ts +31 -0
- package/dist/renderables/progressBar.js +64 -0
- package/dist/renderables/prompt.d.ts +71 -0
- package/dist/renderables/prompt.js +165 -0
- package/dist/renderables/ratio.d.ts +123 -0
- package/dist/renderables/ratio.js +213 -0
- package/dist/renderables/rule.d.ts +26 -0
- package/dist/renderables/rule.js +86 -0
- package/dist/renderables/spinner.d.ts +57 -0
- package/dist/renderables/spinner.js +103 -0
- package/dist/renderables/status.d.ts +29 -0
- package/dist/renderables/status.js +46 -0
- package/dist/renderables/syntax.d.ts +65 -0
- package/dist/renderables/syntax.js +166 -0
- package/dist/renderables/table.d.ts +232 -0
- package/dist/renderables/table.js +973 -0
- package/dist/renderables/traceback.d.ts +32 -0
- package/dist/renderables/traceback.js +279 -0
- package/dist/renderables/tree.d.ts +76 -0
- package/dist/renderables/tree.js +177 -0
- package/dist/renderables/viewport.d.ts +114 -0
- package/dist/renderables/viewport.js +196 -0
- package/dist/template-bindings/color-funcs.d.ts +109 -0
- package/dist/template-bindings/color-funcs.js +243 -0
- package/dist/template-bindings/helpers.d.ts +26 -0
- package/dist/template-bindings/helpers.js +33 -0
- package/dist/template-bindings/index.d.ts +119 -0
- package/dist/template-bindings/index.js +162 -0
- package/dist/template-bindings/palette-funcs.d.ts +96 -0
- package/dist/template-bindings/palette-funcs.js +145 -0
- package/dist/template-bindings/style-funcs.d.ts +28 -0
- package/dist/template-bindings/style-funcs.js +157 -0
- package/dist/themes/buildPalette.d.ts +57 -0
- package/dist/themes/buildPalette.js +100 -0
- package/dist/themes/colorMath.d.ts +94 -0
- package/dist/themes/colorMath.js +280 -0
- package/dist/themes/colorRef.d.ts +36 -0
- package/dist/themes/colorRef.js +78 -0
- package/dist/themes/data/ansi-tables.d.ts +14 -0
- package/dist/themes/data/ansi-tables.js +49 -0
- package/dist/themes/data/atom-one-dark.d.ts +3 -0
- package/dist/themes/data/atom-one-dark.js +177 -0
- package/dist/themes/data/atom-one-light.d.ts +3 -0
- package/dist/themes/data/atom-one-light.js +177 -0
- package/dist/themes/data/catppuccin-frappe.d.ts +3 -0
- package/dist/themes/data/catppuccin-frappe.js +177 -0
- package/dist/themes/data/catppuccin-latte.d.ts +3 -0
- package/dist/themes/data/catppuccin-latte.js +177 -0
- package/dist/themes/data/catppuccin-macchiato.d.ts +3 -0
- package/dist/themes/data/catppuccin-macchiato.js +177 -0
- package/dist/themes/data/catppuccin-mocha.d.ts +3 -0
- package/dist/themes/data/catppuccin-mocha.js +177 -0
- package/dist/themes/data/cyberpunk.d.ts +17 -0
- package/dist/themes/data/cyberpunk.js +193 -0
- package/dist/themes/data/default.d.ts +3 -0
- package/dist/themes/data/default.js +160 -0
- package/dist/themes/data/dracula.d.ts +3 -0
- package/dist/themes/data/dracula.js +177 -0
- package/dist/themes/data/flexoki.d.ts +3 -0
- package/dist/themes/data/flexoki.js +177 -0
- package/dist/themes/data/gruvbox.d.ts +3 -0
- package/dist/themes/data/gruvbox.js +177 -0
- package/dist/themes/data/index.d.ts +35 -0
- package/dist/themes/data/index.js +64 -0
- package/dist/themes/data/monokai.d.ts +3 -0
- package/dist/themes/data/monokai.js +177 -0
- package/dist/themes/data/nord.d.ts +3 -0
- package/dist/themes/data/nord.js +177 -0
- package/dist/themes/data/rose-pine-dawn.d.ts +3 -0
- package/dist/themes/data/rose-pine-dawn.js +177 -0
- package/dist/themes/data/rose-pine-moon.d.ts +3 -0
- package/dist/themes/data/rose-pine-moon.js +177 -0
- package/dist/themes/data/rose-pine.d.ts +3 -0
- package/dist/themes/data/rose-pine.js +177 -0
- package/dist/themes/data/solarized-dark.d.ts +3 -0
- package/dist/themes/data/solarized-dark.js +177 -0
- package/dist/themes/data/solarized-light.d.ts +3 -0
- package/dist/themes/data/solarized-light.js +177 -0
- package/dist/themes/data/svg-export.d.ts +3 -0
- package/dist/themes/data/svg-export.js +177 -0
- package/dist/themes/data/textual-ansi.d.ts +3 -0
- package/dist/themes/data/textual-ansi.js +160 -0
- package/dist/themes/data/textual-dark.d.ts +3 -0
- package/dist/themes/data/textual-dark.js +160 -0
- package/dist/themes/data/textual-light.d.ts +3 -0
- package/dist/themes/data/textual-light.js +160 -0
- package/dist/themes/data/tokyo-night.d.ts +3 -0
- package/dist/themes/data/tokyo-night.js +177 -0
- package/dist/themes/data/types.d.ts +31 -0
- package/dist/themes/data/types.js +10 -0
- package/dist/themes/palette.d.ts +45 -0
- package/dist/themes/palette.js +71 -0
- package/dist/themes/ramp.d.ts +70 -0
- package/dist/themes/ramp.js +103 -0
- package/dist/themes/registry.d.ts +44 -0
- package/dist/themes/registry.js +105 -0
- package/dist/themes/terminalThemes.d.ts +49 -0
- package/dist/themes/terminalThemes.js +63 -0
- package/dist/themes/transpose.d.ts +87 -0
- package/dist/themes/transpose.js +138 -0
- package/dist/widgets/button.d.ts +45 -0
- package/dist/widgets/button.js +177 -0
- package/dist/widgets/checkbox.d.ts +38 -0
- package/dist/widgets/checkbox.js +135 -0
- package/dist/widgets/dropdown.d.ts +64 -0
- package/dist/widgets/dropdown.js +416 -0
- package/dist/widgets/event-router.d.ts +71 -0
- package/dist/widgets/event-router.js +629 -0
- package/dist/widgets/focus-manager.d.ts +45 -0
- package/dist/widgets/focus-manager.js +191 -0
- package/dist/widgets/hit.d.ts +64 -0
- package/dist/widgets/hit.js +113 -0
- package/dist/widgets/index.d.ts +20 -0
- package/dist/widgets/index.js +14 -0
- package/dist/widgets/ink.d.ts +22 -0
- package/dist/widgets/ink.js +31 -0
- package/dist/widgets/slider.d.ts +54 -0
- package/dist/widgets/slider.js +247 -0
- package/dist/widgets/static-item.d.ts +34 -0
- package/dist/widgets/static-item.js +54 -0
- package/dist/widgets/text-input.d.ts +283 -0
- package/dist/widgets/text-input.js +1174 -0
- package/dist/widgets/themed-widget.d.ts +20 -0
- package/dist/widgets/themed-widget.js +89 -0
- package/dist/widgets/toggle.d.ts +41 -0
- package/dist/widgets/toggle.js +157 -0
- package/dist/widgets/types.d.ts +87 -0
- package/dist/widgets/types.js +30 -0
- package/dist/widgets/widget-app.d.ts +65 -0
- package/dist/widgets/widget-app.js +206 -0
- package/dist/widgets/widget-base.d.ts +42 -0
- package/dist/widgets/widget-base.js +172 -0
- package/package.json +16 -2
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
export declare const DEFAULT_TERMINAL_THEME: TerminalTheme;
|
|
28
|
+
export declare const SVG_EXPORT_THEME: TerminalTheme;
|
|
29
|
+
export declare const MONOKAI: TerminalTheme;
|
|
30
|
+
export declare const NORD: TerminalTheme;
|
|
31
|
+
export declare const GRUVBOX: TerminalTheme;
|
|
32
|
+
export declare const DRACULA: TerminalTheme;
|
|
33
|
+
export declare const TOKYO_NIGHT: TerminalTheme;
|
|
34
|
+
export declare const FLEXOKI: TerminalTheme;
|
|
35
|
+
export declare const CYBERPUNK: TerminalTheme;
|
|
36
|
+
export declare const CATPPUCCIN_MOCHA: TerminalTheme;
|
|
37
|
+
export declare const CATPPUCCIN_LATTE: TerminalTheme;
|
|
38
|
+
export declare const CATPPUCCIN_FRAPPE: TerminalTheme;
|
|
39
|
+
export declare const CATPPUCCIN_MACCHIATO: TerminalTheme;
|
|
40
|
+
export declare const SOLARIZED_DARK: TerminalTheme;
|
|
41
|
+
export declare const SOLARIZED_LIGHT: TerminalTheme;
|
|
42
|
+
export declare const ROSE_PINE: TerminalTheme;
|
|
43
|
+
export declare const ROSE_PINE_MOON: TerminalTheme;
|
|
44
|
+
export declare const ROSE_PINE_DAWN: TerminalTheme;
|
|
45
|
+
export declare const ATOM_ONE_DARK: TerminalTheme;
|
|
46
|
+
export declare const ATOM_ONE_LIGHT: TerminalTheme;
|
|
47
|
+
export declare const TEXTUAL_DARK: TerminalTheme;
|
|
48
|
+
export declare const TEXTUAL_LIGHT: TerminalTheme;
|
|
49
|
+
export declare const TEXTUAL_ANSI: TerminalTheme;
|
|
@@ -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,45 @@
|
|
|
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 { ThemedWidget } from "./themed-widget.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 ThemedWidget {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly focusable = true;
|
|
34
|
+
accessor label: string;
|
|
35
|
+
accessor variant: ButtonVariant;
|
|
36
|
+
constructor(options: ButtonOptions);
|
|
37
|
+
handleKey(event: KeyEvent): void;
|
|
38
|
+
handleMouse(event: WidgetMouseEvent): void;
|
|
39
|
+
setActive(value: boolean): void;
|
|
40
|
+
protected draw(_options: RenderOptions): Iterable<Segment>;
|
|
41
|
+
measure(_options: RenderOptions): {
|
|
42
|
+
minimum: number;
|
|
43
|
+
maximum: number;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
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 { cellLen } from "../core/cells.js";
|
|
56
|
+
import { ThemedWidget } from "./themed-widget.js";
|
|
57
|
+
import { ink } from "./ink.js";
|
|
58
|
+
// Variant → palette key mapping. Per variant:
|
|
59
|
+
// bg / fg — normal state. Muted accent bg + mostly-accent fg → readable.
|
|
60
|
+
// hover — full accent bg; pair with hoverFg, NOT with `fg`. The
|
|
61
|
+
// text-* keys are mostly-accent and would clash on a full
|
|
62
|
+
// accent bg.
|
|
63
|
+
// hoverFg — WCAG-correct contrast colour (on-${accent}) for full bg.
|
|
64
|
+
const VARIANT_KEYS = {
|
|
65
|
+
default: { bg: "surface", fg: "foreground", hover: "primary", hoverFg: "on-primary" },
|
|
66
|
+
primary: { bg: "primary-muted", fg: "text-primary", hover: "primary", hoverFg: "on-primary" },
|
|
67
|
+
success: { bg: "success-muted", fg: "text-success", hover: "success", hoverFg: "on-success" },
|
|
68
|
+
warning: { bg: "warning-muted", fg: "text-warning", hover: "warning", hoverFg: "on-warning" },
|
|
69
|
+
danger: { bg: "error-muted", fg: "text-error", hover: "error", hoverFg: "on-error" },
|
|
70
|
+
};
|
|
71
|
+
let Button = (() => {
|
|
72
|
+
let _classSuper = ThemedWidget;
|
|
73
|
+
let _instanceExtraInitializers = [];
|
|
74
|
+
let _label_decorators;
|
|
75
|
+
let _label_initializers = [];
|
|
76
|
+
let _label_extraInitializers = [];
|
|
77
|
+
let _variant_decorators;
|
|
78
|
+
let _variant_initializers = [];
|
|
79
|
+
let _variant_extraInitializers = [];
|
|
80
|
+
let _handleKey_decorators;
|
|
81
|
+
let _handleMouse_decorators;
|
|
82
|
+
let _setActive_decorators;
|
|
83
|
+
return class Button extends _classSuper {
|
|
84
|
+
static {
|
|
85
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
86
|
+
_label_decorators = [observable];
|
|
87
|
+
_variant_decorators = [observableRef];
|
|
88
|
+
_handleKey_decorators = [action];
|
|
89
|
+
_handleMouse_decorators = [action];
|
|
90
|
+
_setActive_decorators = [action];
|
|
91
|
+
__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);
|
|
92
|
+
__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);
|
|
93
|
+
__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);
|
|
94
|
+
__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);
|
|
95
|
+
__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);
|
|
96
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
97
|
+
}
|
|
98
|
+
id = __runInitializers(this, _instanceExtraInitializers);
|
|
99
|
+
focusable = true;
|
|
100
|
+
#label_accessor_storage = __runInitializers(this, _label_initializers, void 0);
|
|
101
|
+
get label() { return this.#label_accessor_storage; }
|
|
102
|
+
set label(value) { this.#label_accessor_storage = value; }
|
|
103
|
+
#variant_accessor_storage = (__runInitializers(this, _label_extraInitializers), __runInitializers(this, _variant_initializers, void 0));
|
|
104
|
+
get variant() { return this.#variant_accessor_storage; }
|
|
105
|
+
set variant(value) { this.#variant_accessor_storage = value; }
|
|
106
|
+
constructor(options) {
|
|
107
|
+
super(options.theme);
|
|
108
|
+
__runInitializers(this, _variant_extraInitializers);
|
|
109
|
+
this.id = options.id ?? `button-${options.label.toLowerCase().replace(/\s+/g, "-")}`;
|
|
110
|
+
this.label = options.label;
|
|
111
|
+
this.variant = options.variant ?? "default";
|
|
112
|
+
this.disabled = options.disabled ?? false;
|
|
113
|
+
}
|
|
114
|
+
// --- Event handlers ---
|
|
115
|
+
handleKey(event) {
|
|
116
|
+
if (this.disabled)
|
|
117
|
+
return;
|
|
118
|
+
if (event.key === "enter" || event.key === "space") {
|
|
119
|
+
this.active = true;
|
|
120
|
+
this.emitSubmit();
|
|
121
|
+
// [LAW:one-source-of-truth] Keyboard activation must leave the widget
|
|
122
|
+
// in the same end state as mouse activation: `active` cleared after
|
|
123
|
+
// the press. Mouse has a natural mouse_up to clear it; keyboard does
|
|
124
|
+
// not, so we schedule the clear on the next microtask. The single-
|
|
125
|
+
// frame `active=true` paint gives the user the visual "pressed" cue
|
|
126
|
+
// and is then cleared, matching mouse behaviour.
|
|
127
|
+
queueMicrotask(() => { if (this.active)
|
|
128
|
+
this.setActive(false); });
|
|
129
|
+
event.stop();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
handleMouse(event) {
|
|
133
|
+
if (this.disabled)
|
|
134
|
+
return;
|
|
135
|
+
if (event.type === "mouse_down") {
|
|
136
|
+
this.active = true;
|
|
137
|
+
}
|
|
138
|
+
// A release that dragged off the button cancels the press.
|
|
139
|
+
if (event.type === "mouse_up") {
|
|
140
|
+
if (this.active) {
|
|
141
|
+
this.active = false;
|
|
142
|
+
if (event.over)
|
|
143
|
+
this.emitSubmit();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// --- Active mutator (the keyboard-activation microtask uses this) ---
|
|
148
|
+
setActive(value) { this.active = value; }
|
|
149
|
+
// --- Rendering ---
|
|
150
|
+
draw(_options) {
|
|
151
|
+
// [LAW:dataflow-not-control-flow] same segment count and width every state
|
|
152
|
+
const focused = this.focused;
|
|
153
|
+
const left = focused ? "[" : " ";
|
|
154
|
+
const right = focused ? "]" : " ";
|
|
155
|
+
const text = `${left} ${this.label} ${right}`;
|
|
156
|
+
if (this.disabled) {
|
|
157
|
+
return [new Segment(text, new Style(this.disabledInk))];
|
|
158
|
+
}
|
|
159
|
+
// Active and hover share the same colour pair (full accent bg + on-accent fg).
|
|
160
|
+
// Active is differentiated by bold, not by inverting fg/bg — inversion gives
|
|
161
|
+
// mostly-accent text on mostly-bg-tinted background, which is unreadable for
|
|
162
|
+
// accents whose contrast partner depends on luminance.
|
|
163
|
+
const keys = VARIANT_KEYS[this.variant];
|
|
164
|
+
if (this.active || this.hovered) {
|
|
165
|
+
return [new Segment(text, new Style({ ...ink(this.theme, keys.hoverFg, keys.hover), bold: this.active }))];
|
|
166
|
+
}
|
|
167
|
+
return [new Segment(text, new Style(ink(this.theme, keys.fg, keys.bg)))];
|
|
168
|
+
}
|
|
169
|
+
measure(_options) {
|
|
170
|
+
// [LAW:one-source-of-truth] cellLen is the cell-width authority; .length
|
|
171
|
+
// counts UTF-16 code units and miscounts wide / emoji characters.
|
|
172
|
+
const width = cellLen(this.label) + 4;
|
|
173
|
+
return { minimum: width, maximum: width };
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
})();
|
|
177
|
+
export { Button };
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { ThemedWidget } from "./themed-widget.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 ThemedWidget {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly focusable = true;
|
|
28
|
+
accessor label: string;
|
|
29
|
+
accessor checked: boolean;
|
|
30
|
+
constructor(options: CheckboxOptions);
|
|
31
|
+
handleKey(event: KeyEvent): void;
|
|
32
|
+
handleMouse(event: WidgetMouseEvent): void;
|
|
33
|
+
protected draw(options: RenderOptions): Iterable<Segment>;
|
|
34
|
+
measure(_options: RenderOptions): {
|
|
35
|
+
minimum: number;
|
|
36
|
+
maximum: number;
|
|
37
|
+
};
|
|
38
|
+
}
|