@promptctl/rich-js 0.28.0 → 0.29.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 +7 -7
- package/dist/core/animation.d.ts +37 -37
- package/dist/core/animation.js +61 -61
- package/dist/core/ansi.d.ts +4 -4
- package/dist/core/ansi.js +9 -9
- package/dist/core/bidi.js +6 -6
- package/dist/core/cells.d.ts +1 -1
- package/dist/core/cells.js +5 -5
- package/dist/core/clock.d.ts +1 -1
- package/dist/core/color.d.ts +50 -50
- package/dist/core/color.js +69 -69
- package/dist/core/console.d.ts +8 -8
- package/dist/core/console.js +5 -5
- package/dist/core/control-codes.d.ts +3 -3
- package/dist/core/control-codes.js +7 -7
- package/dist/core/easing.d.ts +40 -40
- package/dist/core/easing.js +40 -40
- package/dist/core/env.d.ts +1 -1
- package/dist/core/env.js +1 -1
- package/dist/core/export-html.js +1 -1
- package/dist/core/export-lines.d.ts +11 -11
- package/dist/core/export-lines.js +12 -12
- package/dist/core/export-svg.d.ts +3 -3
- package/dist/core/export-svg.js +4 -4
- package/dist/core/markup.js +1 -1
- package/dist/core/memo.d.ts +1 -1
- package/dist/core/memo.js +1 -1
- package/dist/core/oklch.d.ts +14 -14
- package/dist/core/oklch.js +10 -10
- package/dist/core/orient.d.ts +3 -3
- package/dist/core/orient.js +3 -3
- package/dist/core/paint.d.ts +9 -9
- package/dist/core/paint.js +3 -3
- package/dist/core/pretty.d.ts +1 -1
- package/dist/core/pretty.js +3 -3
- package/dist/core/protocol.d.ts +26 -26
- package/dist/core/protocol.js +22 -22
- package/dist/core/render.d.ts +11 -11
- package/dist/core/render.js +12 -12
- package/dist/core/segment.d.ts +3 -3
- package/dist/core/segment.js +5 -5
- package/dist/core/strip.d.ts +83 -83
- package/dist/core/strip.js +70 -70
- package/dist/core/style.d.ts +20 -20
- package/dist/core/style.js +55 -55
- package/dist/core/text.d.ts +2 -2
- package/dist/core/text.js +5 -5
- package/dist/core/timeline.d.ts +5 -5
- package/dist/core/timeline.js +9 -9
- package/dist/core/tween.d.ts +6 -6
- package/dist/core/tween.js +10 -10
- package/dist/core/view.d.ts +4 -4
- package/dist/core/view.js +12 -12
- package/dist/host/app.d.ts +9 -9
- package/dist/host/app.js +12 -12
- package/dist/host/host-environment.d.ts +2 -2
- package/dist/host/host-environment.js +2 -2
- package/dist/host/index.d.ts +2 -2
- package/dist/host/input.d.ts +7 -7
- package/dist/host/input.js +4 -4
- package/dist/host/terminal-colors.d.ts +2 -2
- package/dist/host/terminal-colors.js +4 -4
- package/dist/host/terminal-host.d.ts +2 -2
- package/dist/host/terminal-host.js +1 -1
- package/dist/index.d.ts +14 -14
- package/dist/index.js +10 -10
- package/dist/node/prompt.d.ts +1 -1
- package/dist/node/prompt.js +1 -1
- package/dist/node/terminal-host.d.ts +1 -1
- package/dist/node/traceback.js +2 -2
- package/dist/renderables/change.js +2 -2
- package/dist/renderables/effect.d.ts +39 -39
- package/dist/renderables/effect.js +45 -45
- package/dist/renderables/effects.d.ts +81 -81
- package/dist/renderables/effects.js +157 -157
- package/dist/renderables/embed.d.ts +1 -1
- package/dist/renderables/embed.js +2 -2
- package/dist/renderables/flexStrip.d.ts +7 -7
- package/dist/renderables/flexStrip.js +15 -15
- package/dist/renderables/frames.d.ts +6 -6
- package/dist/renderables/frames.js +11 -11
- package/dist/renderables/glyph-effect.d.ts +15 -15
- package/dist/renderables/glyph-effect.js +17 -17
- package/dist/renderables/glyph-effects.d.ts +7 -7
- package/dist/renderables/glyph-effects.js +16 -16
- package/dist/renderables/html-entities.d.ts +1 -1
- package/dist/renderables/html-entities.js +1 -1
- package/dist/renderables/lifecycle.d.ts +4 -4
- package/dist/renderables/lifecycle.js +12 -12
- package/dist/renderables/live.d.ts +2 -2
- package/dist/renderables/live.js +7 -7
- package/dist/renderables/markdown-parse.js +3 -3
- package/dist/renderables/panel.js +3 -3
- package/dist/renderables/progress.d.ts +1 -1
- package/dist/renderables/progress.js +1 -1
- package/dist/renderables/progressBar.d.ts +1 -1
- package/dist/renderables/progressBar.js +6 -6
- package/dist/renderables/prompt.d.ts +1 -1
- package/dist/renderables/scroll.d.ts +1 -1
- package/dist/renderables/scroll.js +3 -3
- package/dist/renderables/spinner.d.ts +4 -4
- package/dist/renderables/spinner.js +10 -10
- package/dist/renderables/syntax.d.ts +2 -2
- package/dist/renderables/syntax.js +2 -2
- package/dist/renderables/table.js +3 -3
- package/dist/renderables/traceback.d.ts +1 -1
- package/dist/renderables/traceback.js +1 -1
- package/dist/renderables/tree.js +3 -3
- package/dist/template-bindings/animation-funcs.d.ts +14 -14
- package/dist/template-bindings/animation-funcs.js +27 -27
- package/dist/template-bindings/color-funcs.d.ts +14 -14
- package/dist/template-bindings/color-funcs.js +25 -25
- package/dist/template-bindings/index.d.ts +9 -9
- package/dist/template-bindings/index.js +9 -9
- package/dist/template-bindings/palette-funcs.d.ts +1 -1
- package/dist/template-bindings/palette-funcs.js +3 -3
- package/dist/template-bindings/style-funcs.d.ts +5 -5
- package/dist/template-bindings/style-funcs.js +16 -16
- package/dist/themes/{transpose.d.ts → adjust.d.ts} +23 -23
- package/dist/themes/{transpose.js → adjust.js} +28 -28
- package/dist/themes/buildPalette.d.ts +3 -3
- package/dist/themes/buildPalette.js +20 -20
- package/dist/themes/colorMath.d.ts +16 -16
- package/dist/themes/colorMath.js +32 -32
- package/dist/themes/data/ansi-tables.d.ts +2 -2
- package/dist/themes/data/ansi-tables.js +2 -2
- package/dist/themes/data/types.d.ts +4 -4
- package/dist/themes/data/types.js +2 -2
- package/dist/themes/palette.d.ts +12 -12
- package/dist/themes/palette.js +16 -16
- package/dist/themes/ramp.d.ts +17 -17
- package/dist/themes/ramp.js +12 -12
- package/dist/themes/registry.js +4 -4
- package/dist/themes/terminalThemes.d.ts +1 -1
- package/dist/themes/terminalThemes.js +1 -1
- package/dist/widgets/button.d.ts +2 -2
- package/dist/widgets/button.js +4 -4
- package/dist/widgets/checkbox.d.ts +2 -2
- package/dist/widgets/checkbox.js +2 -2
- package/dist/widgets/dropdown.d.ts +2 -2
- package/dist/widgets/dropdown.js +3 -3
- package/dist/widgets/event-router.d.ts +6 -6
- package/dist/widgets/event-router.js +2 -2
- package/dist/widgets/focus-manager.d.ts +3 -3
- package/dist/widgets/focus-manager.js +3 -3
- package/dist/widgets/index.d.ts +2 -2
- package/dist/widgets/index.js +1 -1
- package/dist/widgets/ink.d.ts +3 -3
- package/dist/widgets/ink.js +4 -4
- package/dist/widgets/slider.d.ts +2 -2
- package/dist/widgets/static-item.d.ts +2 -2
- package/dist/widgets/text-input.d.ts +2 -2
- package/dist/widgets/text-input.js +5 -5
- package/dist/widgets/themed-widget.js +1 -1
- package/dist/widgets/toggle.d.ts +3 -3
- package/dist/widgets/toggle.js +3 -3
- package/dist/widgets/types.d.ts +6 -6
- package/dist/widgets/types.js +2 -2
- package/dist/widgets/widget-app.d.ts +10 -10
- package/dist/widgets/widget-app.js +8 -8
- package/dist/widgets/widget-base.d.ts +2 -2
- package/package.json +1 -1
|
@@ -13,7 +13,7 @@ export interface ThemePaletteData {
|
|
|
13
13
|
readonly name: string;
|
|
14
14
|
readonly dark: boolean;
|
|
15
15
|
/**
|
|
16
|
-
* The sixteen
|
|
16
|
+
* The sixteen colors a terminal showing this theme draws `red`, `blue`,
|
|
17
17
|
* `bright_black` and the rest in. A theme without its own table would draw
|
|
18
18
|
* them in the VGA defaults (`blue` as #000080), which belong to no theme.
|
|
19
19
|
*/
|
|
@@ -22,12 +22,12 @@ export interface ThemePaletteData {
|
|
|
22
22
|
readonly vars: Readonly<Record<BaseRole, string> & Partial<Record<PaletteRole, string>>>;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* ANSI
|
|
25
|
+
* ANSI color numbers 0–15 in order: the eight normal colors, then their
|
|
26
26
|
* bright forms. Named rather than positional so a data file cannot shift a
|
|
27
|
-
*
|
|
27
|
+
* color into its neighbour's slot by miscounting.
|
|
28
28
|
*/
|
|
29
29
|
export declare const ANSI_SLOTS: readonly ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "brightBlack", "brightRed", "brightGreen", "brightYellow", "brightBlue", "brightMagenta", "brightCyan", "brightWhite"];
|
|
30
|
-
/** One `#RRGGBB` per ANSI
|
|
30
|
+
/** One `#RRGGBB` per ANSI color number, keyed by `ANSI_SLOTS`. */
|
|
31
31
|
export type AnsiColorsData = {
|
|
32
32
|
readonly [K in (typeof ANSI_SLOTS)[number]]: string;
|
|
33
33
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ANSI
|
|
2
|
+
* ANSI color numbers 0–15 in order: the eight normal colors, then their
|
|
3
3
|
* bright forms. Named rather than positional so a data file cannot shift a
|
|
4
|
-
*
|
|
4
|
+
* color into its neighbour's slot by miscounting.
|
|
5
5
|
*/
|
|
6
6
|
export const ANSI_SLOTS = [
|
|
7
7
|
"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white",
|
package/dist/themes/palette.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type Shade = `-${"darken" | "lighten"}-${1 | 2 | 3}`;
|
|
|
10
10
|
* list is read off those rules.
|
|
11
11
|
*/
|
|
12
12
|
export type PaletteRole = ShadedRole | `${ShadedRole}${Shade}` | `${AccentRole}-muted` | `text-${AccentRole}` | `on-${AccentRole}` | "background-muted" | "foreground-muted" | "foreground-disabled" | "surface-active" | "text" | "text-muted" | "text-disabled" | "border" | "border-blurred" | "block-cursor-background" | "block-cursor-foreground" | "block-cursor-blurred-background" | "block-cursor-blurred-foreground" | "block-hover-background" | "button-foreground" | "button-color-foreground" | "footer-background" | "footer-foreground" | "footer-description-background" | "footer-description-foreground" | "footer-item-background" | "footer-key-background" | "footer-key-foreground" | "input-cursor-background" | "input-cursor-foreground" | "input-selection-background" | "link-background" | "link-background-hover" | "link-color" | "link-color-hover" | `markdown-h${1 | 2 | 3 | 4 | 5 | 6}-${"background" | "color"}` | "scrollbar" | "scrollbar-active" | "scrollbar-hover" | "scrollbar-background" | "scrollbar-background-active" | "scrollbar-background-hover" | "scrollbar-corner-color";
|
|
13
|
-
/** A
|
|
13
|
+
/** A color for each role: what proves a palette complete. */
|
|
14
14
|
export type PaletteRoles = Readonly<Record<PaletteRole, ColorRgba>>;
|
|
15
15
|
/**
|
|
16
16
|
* A semantic palette: a named map from role → ColorRgba, holding every
|
|
@@ -22,20 +22,20 @@ export type PaletteRoles = Readonly<Record<PaletteRole, ColorRgba>>;
|
|
|
22
22
|
*
|
|
23
23
|
* Storage is uniformly ColorRgba; consumers that load from hex JSON
|
|
24
24
|
* parse to ColorRgba at load time. `get` is a bare lookup — turning an
|
|
25
|
-
* author-written *reference* (a name, or a `#RRGGBB` literal) into a
|
|
25
|
+
* author-written *reference* (a name, or a `#RRGGBB` literal) into a color
|
|
26
26
|
* is `resolveColorRef`'s job in `colorRef.ts`, so a Palette never has to
|
|
27
27
|
* know about the syntax callers write.
|
|
28
28
|
*
|
|
29
|
-
* Every
|
|
29
|
+
* Every color a Palette hands out is opaque or fully transparent. A theme's translucent variable
|
|
30
30
|
* (Textual's `boost`, a hover overlay) is a tint meant for that theme's own
|
|
31
|
-
* background, and a
|
|
31
|
+
* background, and a color leaving the palette no longer knows which
|
|
32
32
|
* background that was: the SGR writer would composite it over the terminal's
|
|
33
33
|
* black, which is not the theme's background, and draw a tint the theme never
|
|
34
34
|
* meant.
|
|
35
35
|
* So it is drawn onto `background` here, once, and the writer, the exporters
|
|
36
|
-
* and the contrast choosers all read the
|
|
37
|
-
* surface it keeps that
|
|
38
|
-
* The exception is a fully transparent
|
|
36
|
+
* and the contrast choosers all read the color it has there. On any other
|
|
37
|
+
* surface it keeps that color: the tint does not follow what is under it.
|
|
38
|
+
* The exception is a fully transparent color, Textual's "no background": it
|
|
39
39
|
* draws nothing on any surface, so it needs none and is handed out as it is,
|
|
40
40
|
* and a `Style` reads it as no background at all.
|
|
41
41
|
*
|
|
@@ -48,14 +48,14 @@ export declare class Palette {
|
|
|
48
48
|
constructor(name: string, dark: boolean, roles: PaletteRoles);
|
|
49
49
|
get(role: PaletteRole): ColorRgba;
|
|
50
50
|
get(role: string): ColorRgba | undefined;
|
|
51
|
-
/** This palette's roles, each put through `
|
|
52
|
-
mapRoles(
|
|
51
|
+
/** This palette's roles, each put through `color`: what a new palette is built from. */
|
|
52
|
+
mapRoles(color: (color: ColorRgba, role: PaletteRole) => ColorRgba): PaletteRoles;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
* A palette
|
|
55
|
+
* A palette color as it is drawn: composited onto the palette's own
|
|
56
56
|
* `background`, which has nothing under it and so must itself be opaque.
|
|
57
57
|
* [LAW:one-source-of-truth] The one statement of what a translucent palette
|
|
58
|
-
*
|
|
58
|
+
* color means; `buildPalette` draws its base colors through it before
|
|
59
59
|
* deriving from them.
|
|
60
60
|
*/
|
|
61
|
-
export declare function drawnOn(name: string, background: ColorRgba): (
|
|
61
|
+
export declare function drawnOn(name: string, background: ColorRgba): (color: ColorRgba) => ColorRgba;
|
package/dist/themes/palette.js
CHANGED
|
@@ -8,20 +8,20 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Storage is uniformly ColorRgba; consumers that load from hex JSON
|
|
10
10
|
* parse to ColorRgba at load time. `get` is a bare lookup — turning an
|
|
11
|
-
* author-written *reference* (a name, or a `#RRGGBB` literal) into a
|
|
11
|
+
* author-written *reference* (a name, or a `#RRGGBB` literal) into a color
|
|
12
12
|
* is `resolveColorRef`'s job in `colorRef.ts`, so a Palette never has to
|
|
13
13
|
* know about the syntax callers write.
|
|
14
14
|
*
|
|
15
|
-
* Every
|
|
15
|
+
* Every color a Palette hands out is opaque or fully transparent. A theme's translucent variable
|
|
16
16
|
* (Textual's `boost`, a hover overlay) is a tint meant for that theme's own
|
|
17
|
-
* background, and a
|
|
17
|
+
* background, and a color leaving the palette no longer knows which
|
|
18
18
|
* background that was: the SGR writer would composite it over the terminal's
|
|
19
19
|
* black, which is not the theme's background, and draw a tint the theme never
|
|
20
20
|
* meant.
|
|
21
21
|
* So it is drawn onto `background` here, once, and the writer, the exporters
|
|
22
|
-
* and the contrast choosers all read the
|
|
23
|
-
* surface it keeps that
|
|
24
|
-
* The exception is a fully transparent
|
|
22
|
+
* and the contrast choosers all read the color it has there. On any other
|
|
23
|
+
* surface it keeps that color: the tint does not follow what is under it.
|
|
24
|
+
* The exception is a fully transparent color, Textual's "no background": it
|
|
25
25
|
* draws nothing on any surface, so it needs none and is handed out as it is,
|
|
26
26
|
* and a `Style` reads it as no background at all.
|
|
27
27
|
*
|
|
@@ -35,29 +35,29 @@ export class Palette {
|
|
|
35
35
|
this.name = name;
|
|
36
36
|
this.dark = dark;
|
|
37
37
|
// [LAW:single-enforcer] Every palette is built through here, so this is
|
|
38
|
-
// where "a palette
|
|
38
|
+
// where "a palette color is opaque or draws nothing" holds.
|
|
39
39
|
const draw = drawnOn(name, roles.background);
|
|
40
|
-
this.vars = new Map(Object.entries(roles).map(([role,
|
|
40
|
+
this.vars = new Map(Object.entries(roles).map(([role, color]) => [role, draw(color)]));
|
|
41
41
|
}
|
|
42
42
|
get(role) {
|
|
43
43
|
return this.vars.get(role);
|
|
44
44
|
}
|
|
45
|
-
/** This palette's roles, each put through `
|
|
46
|
-
mapRoles(
|
|
47
|
-
return Object.fromEntries([...this.vars].map(([role, was]) => [role,
|
|
45
|
+
/** This palette's roles, each put through `color`: what a new palette is built from. */
|
|
46
|
+
mapRoles(color) {
|
|
47
|
+
return Object.fromEntries([...this.vars].map(([role, was]) => [role, color(was, role)]));
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
* A palette
|
|
51
|
+
* A palette color as it is drawn: composited onto the palette's own
|
|
52
52
|
* `background`, which has nothing under it and so must itself be opaque.
|
|
53
53
|
* [LAW:one-source-of-truth] The one statement of what a translucent palette
|
|
54
|
-
*
|
|
54
|
+
* color means; `buildPalette` draws its base colors through it before
|
|
55
55
|
* deriving from them.
|
|
56
56
|
*/
|
|
57
57
|
export function drawnOn(name, background) {
|
|
58
58
|
if (background.alpha !== 1) {
|
|
59
|
-
throw new RangeError(`palette ${JSON.stringify(name)}: background is the surface its translucent
|
|
59
|
+
throw new RangeError(`palette ${JSON.stringify(name)}: background is the surface its translucent colors are drawn on, so it must be opaque; got ${background.hex}`);
|
|
60
60
|
}
|
|
61
|
-
// A fully transparent
|
|
62
|
-
return (
|
|
61
|
+
// A fully transparent color is not a tint: it draws nothing on any surface.
|
|
62
|
+
return (color) => (color.alpha === 0 ? color : color.compositeOver(background));
|
|
63
63
|
}
|
package/dist/themes/ramp.d.ts
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
* color, and none takes a *measurement*. Without a ramp the answer gets
|
|
7
7
|
* computed outside the theme system — a script emits a hex, a template
|
|
8
8
|
* branches `if ge .pct 80 … else if ge .pct 50 …` — and that color decision
|
|
9
|
-
* can no longer
|
|
9
|
+
* can no longer adjust with the palette it was meant to belong to. A ramp
|
|
10
10
|
* is the one function whose input is a number, so the decision stays inside.
|
|
11
11
|
*
|
|
12
12
|
* A threshold cascade is a ramp too: the same stops with the `step` ease hold
|
|
13
13
|
* each color until the next position, which is exactly `≥ threshold → hotter`
|
|
14
14
|
* written as data. [LAW:one-type-per-behavior] One primitive; the easing is a
|
|
15
|
-
* value — any `
|
|
15
|
+
* value — any `Easing` from `core/easing`, the vocabulary every effect shares —
|
|
16
16
|
* so a gradient and a cascade differ by one word, not by which function was
|
|
17
17
|
* called. [LAW:dataflow-not-control-flow] `at` applies it unconditionally.
|
|
18
18
|
*
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* midpoints of an sRGB blend.
|
|
22
22
|
*
|
|
23
23
|
* A ramp also carries how far it has been moved: `scroll`, in spans, how
|
|
24
|
-
* far its
|
|
24
|
+
* far its colors have travelled along it, and `hue`, in turns, how far
|
|
25
25
|
* they are rotated round the OKLCH hue circle. A moved ramp is still a
|
|
26
26
|
* `ColorRamp`, so anything that reads a ramp reads a moving one frame by
|
|
27
27
|
* frame (`moving`) with nothing new to learn. [LAW:one-type-per-behavior]
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
*/
|
|
34
34
|
import { Animation } from "../core/animation.js";
|
|
35
35
|
import type { ColorRgba } from "../core/color.js";
|
|
36
|
-
import { type
|
|
36
|
+
import { type Easing } from "../core/easing.js";
|
|
37
37
|
/** One stop: the color the ramp is exactly `color` at position `at`. */
|
|
38
38
|
export interface ColorStop {
|
|
39
39
|
readonly at: number;
|
|
@@ -42,8 +42,8 @@ export interface ColorStop {
|
|
|
42
42
|
/**
|
|
43
43
|
* How a ramp moves over time, each part an `Animation<number>` that is
|
|
44
44
|
* `Animation.constant(0)` when not given. `scroll` is in spans: at 1 the
|
|
45
|
-
*
|
|
46
|
-
* wrapped back, so `Animation.continuous(
|
|
45
|
+
* colors have travelled the whole way from the first stop to the last and
|
|
46
|
+
* wrapped back, so `Animation.continuous(WrapMode.loop(seconds))` scrolls once
|
|
47
47
|
* every `seconds`. `hue` is in turns, CSS's `turn`: at 1 every hue has gone
|
|
48
48
|
* once round the circle. A one-shot that settles is a `tween` to where it
|
|
49
49
|
* rests.
|
|
@@ -68,13 +68,13 @@ export interface RampMotion {
|
|
|
68
68
|
* same way).
|
|
69
69
|
*/
|
|
70
70
|
export declare class ColorRamp {
|
|
71
|
-
readonly ease:
|
|
71
|
+
readonly ease: Easing;
|
|
72
72
|
readonly stops: readonly ColorStop[];
|
|
73
|
-
/** How far the
|
|
73
|
+
/** How far the colors have moved along the span, in spans, in [0, 1). */
|
|
74
74
|
readonly scroll: number;
|
|
75
75
|
/** How far every hue is rotated in OKLCH, in turns, in [0, 1). */
|
|
76
76
|
readonly hue: number;
|
|
77
|
-
constructor(ease:
|
|
77
|
+
constructor(ease: Easing, stops: readonly ColorStop[], scroll?: number, hue?: number);
|
|
78
78
|
/**
|
|
79
79
|
* The color at `value`. Below the first stop it is the first color; at or
|
|
80
80
|
* above the last stop it is the last; between two stops the raw progress
|
|
@@ -91,26 +91,26 @@ export declare class ColorRamp {
|
|
|
91
91
|
* CSS defines them. An ease that overshoots [0, 1] holds the end colors
|
|
92
92
|
* where it does: a ramp never paints outside its stops.
|
|
93
93
|
*
|
|
94
|
-
* A scrolled ramp reads, inside its span, the
|
|
94
|
+
* A scrolled ramp reads, inside its span, the color `scroll` spans behind
|
|
95
95
|
* `value`, wrapped back round the span as a repeating gradient does —
|
|
96
|
-
* seamless when the first and last stops are one
|
|
97
|
-
* its end
|
|
98
|
-
* the
|
|
96
|
+
* seamless when the first and last stops are one color; outside the span
|
|
97
|
+
* its end colors hold, however far it has scrolled. A rotated ramp turns
|
|
98
|
+
* the color read by `hue` at its own lightness and chroma. Unmoved, every
|
|
99
99
|
* read keeps the exactness above.
|
|
100
100
|
*/
|
|
101
101
|
at(value: number): ColorRgba;
|
|
102
|
-
/** The
|
|
102
|
+
/** The color at `value` with the ramp unmoved: the stops and the ease alone. */
|
|
103
103
|
private unmoved;
|
|
104
104
|
/**
|
|
105
105
|
* This ramp read over time: its span of positions, from the first stop's
|
|
106
106
|
* to the last's, crossed at a steady rate in `seconds` and held at the last
|
|
107
|
-
* stop from then on, each
|
|
107
|
+
* stop from then on, each color along the way the ramp's own. A color
|
|
108
108
|
* tween is a two-stop ramp over its seconds — the ramp's ease shaping the
|
|
109
109
|
* move, so `new ColorRamp(ease, [{ at: 0, color: a }, { at: 1, color: b
|
|
110
110
|
* }]).over(seconds)` is `a` eased to `b` — and a ramp of more stops over
|
|
111
111
|
* time is a sweep through all of them. [LAW:one-source-of-truth] The
|
|
112
112
|
* blending is `at`'s; what time adds is `tween`'s (`core/tween.ts`), so a
|
|
113
|
-
* host sampling once a second or sixty times reads the stop
|
|
113
|
+
* host sampling once a second or sixty times reads the stop colors byte
|
|
114
114
|
* for byte where `at` paints them.
|
|
115
115
|
*/
|
|
116
116
|
over(seconds: number): Animation<ColorRgba>;
|
|
@@ -122,7 +122,7 @@ export declare class ColorRamp {
|
|
|
122
122
|
* [LAW:one-source-of-truth] When it next changes is `Animation.all`'s
|
|
123
123
|
* answer over the two parts; nothing here says it a second time. Whether
|
|
124
124
|
* the depth it is drawn at can show the move is decided where it is drawn
|
|
125
|
-
* (`gradient`, through `
|
|
125
|
+
* (`gradient`, through `staticWhereUnchanged`).
|
|
126
126
|
*/
|
|
127
127
|
moving(motion: RampMotion): Animation<ColorRamp>;
|
|
128
128
|
}
|
package/dist/themes/ramp.js
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
* color, and none takes a *measurement*. Without a ramp the answer gets
|
|
7
7
|
* computed outside the theme system — a script emits a hex, a template
|
|
8
8
|
* branches `if ge .pct 80 … else if ge .pct 50 …` — and that color decision
|
|
9
|
-
* can no longer
|
|
9
|
+
* can no longer adjust with the palette it was meant to belong to. A ramp
|
|
10
10
|
* is the one function whose input is a number, so the decision stays inside.
|
|
11
11
|
*
|
|
12
12
|
* A threshold cascade is a ramp too: the same stops with the `step` ease hold
|
|
13
13
|
* each color until the next position, which is exactly `≥ threshold → hotter`
|
|
14
14
|
* written as data. [LAW:one-type-per-behavior] One primitive; the easing is a
|
|
15
|
-
* value — any `
|
|
15
|
+
* value — any `Easing` from `core/easing`, the vocabulary every effect shares —
|
|
16
16
|
* so a gradient and a cascade differ by one word, not by which function was
|
|
17
17
|
* called. [LAW:dataflow-not-control-flow] `at` applies it unconditionally.
|
|
18
18
|
*
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* midpoints of an sRGB blend.
|
|
22
22
|
*
|
|
23
23
|
* A ramp also carries how far it has been moved: `scroll`, in spans, how
|
|
24
|
-
* far its
|
|
24
|
+
* far its colors have travelled along it, and `hue`, in turns, how far
|
|
25
25
|
* they are rotated round the OKLCH hue circle. A moved ramp is still a
|
|
26
26
|
* `ColorRamp`, so anything that reads a ramp reads a moving one frame by
|
|
27
27
|
* frame (`moving`) with nothing new to learn. [LAW:one-type-per-behavior]
|
|
@@ -53,7 +53,7 @@ import { tween } from "../core/tween.js";
|
|
|
53
53
|
export class ColorRamp {
|
|
54
54
|
ease;
|
|
55
55
|
stops;
|
|
56
|
-
/** How far the
|
|
56
|
+
/** How far the colors have moved along the span, in spans, in [0, 1). */
|
|
57
57
|
scroll;
|
|
58
58
|
/** How far every hue is rotated in OKLCH, in turns, in [0, 1). */
|
|
59
59
|
hue;
|
|
@@ -92,11 +92,11 @@ export class ColorRamp {
|
|
|
92
92
|
* CSS defines them. An ease that overshoots [0, 1] holds the end colors
|
|
93
93
|
* where it does: a ramp never paints outside its stops.
|
|
94
94
|
*
|
|
95
|
-
* A scrolled ramp reads, inside its span, the
|
|
95
|
+
* A scrolled ramp reads, inside its span, the color `scroll` spans behind
|
|
96
96
|
* `value`, wrapped back round the span as a repeating gradient does —
|
|
97
|
-
* seamless when the first and last stops are one
|
|
98
|
-
* its end
|
|
99
|
-
* the
|
|
97
|
+
* seamless when the first and last stops are one color; outside the span
|
|
98
|
+
* its end colors hold, however far it has scrolled. A rotated ramp turns
|
|
99
|
+
* the color read by `hue` at its own lightness and chroma. Unmoved, every
|
|
100
100
|
* read keeps the exactness above.
|
|
101
101
|
*/
|
|
102
102
|
at(value) {
|
|
@@ -112,7 +112,7 @@ export class ColorRamp {
|
|
|
112
112
|
// Exact when unrotated: the OKLCH round trip can land a channel one off.
|
|
113
113
|
return this.hue === 0 ? read : Oklch.fromRgba(read).applyKey({ ...IDENTITY, hueShift: 360 * this.hue }).toRgba();
|
|
114
114
|
}
|
|
115
|
-
/** The
|
|
115
|
+
/** The color at `value` with the ramp unmoved: the stops and the ease alone. */
|
|
116
116
|
unmoved(value) {
|
|
117
117
|
const stops = this.stops;
|
|
118
118
|
// The last stop at or below `value`; -1 when `value` is below them all.
|
|
@@ -137,13 +137,13 @@ export class ColorRamp {
|
|
|
137
137
|
/**
|
|
138
138
|
* This ramp read over time: its span of positions, from the first stop's
|
|
139
139
|
* to the last's, crossed at a steady rate in `seconds` and held at the last
|
|
140
|
-
* stop from then on, each
|
|
140
|
+
* stop from then on, each color along the way the ramp's own. A color
|
|
141
141
|
* tween is a two-stop ramp over its seconds — the ramp's ease shaping the
|
|
142
142
|
* move, so `new ColorRamp(ease, [{ at: 0, color: a }, { at: 1, color: b
|
|
143
143
|
* }]).over(seconds)` is `a` eased to `b` — and a ramp of more stops over
|
|
144
144
|
* time is a sweep through all of them. [LAW:one-source-of-truth] The
|
|
145
145
|
* blending is `at`'s; what time adds is `tween`'s (`core/tween.ts`), so a
|
|
146
|
-
* host sampling once a second or sixty times reads the stop
|
|
146
|
+
* host sampling once a second or sixty times reads the stop colors byte
|
|
147
147
|
* for byte where `at` paints them.
|
|
148
148
|
*/
|
|
149
149
|
over(seconds) {
|
|
@@ -159,7 +159,7 @@ export class ColorRamp {
|
|
|
159
159
|
* [LAW:one-source-of-truth] When it next changes is `Animation.all`'s
|
|
160
160
|
* answer over the two parts; nothing here says it a second time. Whether
|
|
161
161
|
* the depth it is drawn at can show the move is decided where it is drawn
|
|
162
|
-
* (`gradient`, through `
|
|
162
|
+
* (`gradient`, through `staticWhereUnchanged`).
|
|
163
163
|
*/
|
|
164
164
|
moving(motion) {
|
|
165
165
|
const still = Animation.constant(0);
|
package/dist/themes/registry.js
CHANGED
|
@@ -29,8 +29,8 @@ function isThemeName(name) {
|
|
|
29
29
|
export function getThemeBaseColors(name) {
|
|
30
30
|
const data = THEMES[name];
|
|
31
31
|
const bg = parseHex(data.vars.background, data.name, "background");
|
|
32
|
-
// The
|
|
33
|
-
// the theme's own background, as a Palette draws every
|
|
32
|
+
// The colors `getThemePalette(name)` hands out for the same names: drawn on
|
|
33
|
+
// the theme's own background, as a Palette draws every color it holds.
|
|
34
34
|
const draw = drawnOn(data.name, bg);
|
|
35
35
|
const base = (key) => draw(parseHex(data.vars[key], data.name, key));
|
|
36
36
|
return {
|
|
@@ -57,7 +57,7 @@ function hydrate(data) {
|
|
|
57
57
|
const stated = Object.entries(data.vars).map(([role, hex]) => [role, parseHex(hex, data.name, `var ${role}`)]);
|
|
58
58
|
return buildPalette(data.name, data.dark, Object.fromEntries(stated));
|
|
59
59
|
}
|
|
60
|
-
// Theme data is authored, so a malformed
|
|
60
|
+
// Theme data is authored, so a malformed color names the theme and the key it
|
|
61
61
|
// sits under; the grammar itself is `parseHexColor`'s.
|
|
62
62
|
function parseHex(value, theme, key) {
|
|
63
63
|
try {
|
|
@@ -70,7 +70,7 @@ function parseHex(value, theme, key) {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
|
-
* An ANSI slot is a
|
|
73
|
+
* An ANSI slot is a color a terminal paints, never a blend, so it takes no
|
|
74
74
|
* alpha: `flattenAlpha` leaves a STANDARD spec alone and would pass one through.
|
|
75
75
|
*/
|
|
76
76
|
function parseOpaqueHex(value, theme, key) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* [LAW:one-source-of-truth] Hex values live in `data/<name>.ts`, and a theme's
|
|
7
7
|
* name means one palette: a constant here holds the very `Palette`
|
|
8
8
|
* `getThemePalette(name)` returns, and takes the background and foreground off
|
|
9
|
-
* it, with the theme's sixteen named
|
|
9
|
+
* it, with the theme's sixteen named colors beside it.
|
|
10
10
|
*
|
|
11
11
|
* [LAW:one-type-per-behavior] Every theme has the same shape — name,
|
|
12
12
|
* `dark` flag, full Palette in the registry, `TerminalTheme` constant
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* [LAW:one-source-of-truth] Hex values live in `data/<name>.ts`, and a theme's
|
|
7
7
|
* name means one palette: a constant here holds the very `Palette`
|
|
8
8
|
* `getThemePalette(name)` returns, and takes the background and foreground off
|
|
9
|
-
* it, with the theme's sixteen named
|
|
9
|
+
* it, with the theme's sixteen named colors beside it.
|
|
10
10
|
*
|
|
11
11
|
* [LAW:one-type-per-behavior] Every theme has the same shape — name,
|
|
12
12
|
* `dark` flag, full Palette in the registry, `TerminalTheme` constant
|
package/dist/widgets/button.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { Segment } from "../core/segment.js";
|
|
|
19
19
|
import type { RenderOptions } from "../core/protocol.js";
|
|
20
20
|
import type { TerminalTheme } from "../core/color.js";
|
|
21
21
|
import { ThemedWidget } from "./themed-widget.js";
|
|
22
|
-
import type {
|
|
22
|
+
import type { WidgetKeyEvent, WidgetMouseEvent } from "./types.js";
|
|
23
23
|
export type ButtonVariant = "default" | "primary" | "success" | "warning" | "danger";
|
|
24
24
|
export interface ButtonOptions {
|
|
25
25
|
label: string;
|
|
@@ -34,7 +34,7 @@ export declare class Button extends ThemedWidget {
|
|
|
34
34
|
accessor label: string;
|
|
35
35
|
accessor variant: ButtonVariant;
|
|
36
36
|
constructor(options: ButtonOptions);
|
|
37
|
-
handleKey(event:
|
|
37
|
+
handleKey(event: WidgetKeyEvent): void;
|
|
38
38
|
handleMouse(event: WidgetMouseEvent): void;
|
|
39
39
|
setActive(value: boolean): void;
|
|
40
40
|
protected draw(options: RenderOptions): Iterable<Segment>;
|
package/dist/widgets/button.js
CHANGED
|
@@ -49,7 +49,7 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
|
|
|
49
49
|
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
50
50
|
done = true;
|
|
51
51
|
};
|
|
52
|
-
import {
|
|
52
|
+
import { labeled } from "../core/orient.js";
|
|
53
53
|
import { action } from "mobx";
|
|
54
54
|
import { observableRef } from "./observable.js";
|
|
55
55
|
import { Style } from "../core/style.js";
|
|
@@ -61,7 +61,7 @@ import { ink } from "./ink.js";
|
|
|
61
61
|
// hover — full accent bg; pair with hoverFg, NOT with `fg`. The
|
|
62
62
|
// text-* keys are mostly-accent and would clash on a full
|
|
63
63
|
// accent bg.
|
|
64
|
-
// hoverFg — WCAG-correct contrast
|
|
64
|
+
// hoverFg — WCAG-correct contrast color (on-${accent}) for full bg.
|
|
65
65
|
const VARIANT_KEYS = {
|
|
66
66
|
default: { bg: "surface", fg: "foreground", hover: "primary", hoverFg: "on-primary" },
|
|
67
67
|
primary: { bg: "primary-muted", fg: "text-primary", hover: "primary", hoverFg: "on-primary" },
|
|
@@ -153,11 +153,11 @@ let Button = (() => {
|
|
|
153
153
|
const focused = this.focused;
|
|
154
154
|
const left = focused ? "[" : " ";
|
|
155
155
|
const right = focused ? "]" : " ";
|
|
156
|
-
const drawn = (style) =>
|
|
156
|
+
const drawn = (style) => labeled(`${left} `, this.label, ` ${right}`, style, options.textOrder);
|
|
157
157
|
if (this.disabled) {
|
|
158
158
|
return drawn(new Style(this.disabledInk));
|
|
159
159
|
}
|
|
160
|
-
// Active and hover share the same
|
|
160
|
+
// Active and hover share the same color pair (full accent bg + on-accent fg).
|
|
161
161
|
// Active is differentiated by bold, not by inverting fg/bg — inversion gives
|
|
162
162
|
// mostly-accent text on mostly-bg-tinted background, which is unreadable for
|
|
163
163
|
// accents whose contrast partner depends on luminance.
|
|
@@ -14,7 +14,7 @@ import { Segment } from "../core/segment.js";
|
|
|
14
14
|
import { type RenderOptions } from "../core/protocol.js";
|
|
15
15
|
import type { TerminalTheme } from "../core/color.js";
|
|
16
16
|
import { ThemedWidget } from "./themed-widget.js";
|
|
17
|
-
import type {
|
|
17
|
+
import type { WidgetKeyEvent, WidgetMouseEvent } from "./types.js";
|
|
18
18
|
export interface CheckboxOptions {
|
|
19
19
|
label: string;
|
|
20
20
|
checked?: boolean;
|
|
@@ -28,7 +28,7 @@ export declare class Checkbox extends ThemedWidget {
|
|
|
28
28
|
accessor label: string;
|
|
29
29
|
accessor checked: boolean;
|
|
30
30
|
constructor(options: CheckboxOptions);
|
|
31
|
-
handleKey(event:
|
|
31
|
+
handleKey(event: WidgetKeyEvent): void;
|
|
32
32
|
handleMouse(event: WidgetMouseEvent): void;
|
|
33
33
|
protected draw(options: RenderOptions): Iterable<Segment>;
|
|
34
34
|
measure(_options: RenderOptions): {
|
package/dist/widgets/checkbox.js
CHANGED
|
@@ -44,7 +44,7 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
|
|
|
44
44
|
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
45
45
|
done = true;
|
|
46
46
|
};
|
|
47
|
-
import {
|
|
47
|
+
import { labeled } from "../core/orient.js";
|
|
48
48
|
import { action } from "mobx";
|
|
49
49
|
import { observableRef } from "./observable.js";
|
|
50
50
|
import { Style } from "../core/style.js";
|
|
@@ -119,7 +119,7 @@ let Checkbox = (() => {
|
|
|
119
119
|
// --- Rendering ---
|
|
120
120
|
draw(options) {
|
|
121
121
|
const indicator = this.checked ? drawable(options, "✓", "x") : " ";
|
|
122
|
-
const drawn = (style) =>
|
|
122
|
+
const drawn = (style) => labeled(`[${indicator}] `, this.label, "", style, options.textOrder);
|
|
123
123
|
if (this.disabled) {
|
|
124
124
|
return drawn(new Style(this.disabledInk));
|
|
125
125
|
}
|
|
@@ -26,7 +26,7 @@ import { Segment } from "../core/segment.js";
|
|
|
26
26
|
import { type RenderOptions } from "../core/protocol.js";
|
|
27
27
|
import type { TerminalTheme } from "../core/color.js";
|
|
28
28
|
import { ThemedWidget } from "./themed-widget.js";
|
|
29
|
-
import type {
|
|
29
|
+
import type { WidgetKeyEvent, WidgetMouseEvent, WidgetFocusEvent, OverlayRenderable } from "./types.js";
|
|
30
30
|
export interface DropdownOptions {
|
|
31
31
|
options: string[];
|
|
32
32
|
selectedIndex?: number;
|
|
@@ -50,7 +50,7 @@ export declare class Dropdown extends ThemedWidget implements OverlayRenderable
|
|
|
50
50
|
}[];
|
|
51
51
|
constructor(options: DropdownOptions);
|
|
52
52
|
private clampIndex;
|
|
53
|
-
handleKey(event:
|
|
53
|
+
handleKey(event: WidgetKeyEvent): void;
|
|
54
54
|
handleMouse(event: WidgetMouseEvent): void;
|
|
55
55
|
handleFocus(event: WidgetFocusEvent): void;
|
|
56
56
|
protected draw(options: RenderOptions): Iterable<Segment>;
|
package/dist/widgets/dropdown.js
CHANGED
|
@@ -56,7 +56,7 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
|
|
|
56
56
|
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
57
57
|
done = true;
|
|
58
58
|
};
|
|
59
|
-
import {
|
|
59
|
+
import { labeled } from "../core/orient.js";
|
|
60
60
|
import { action } from "mobx";
|
|
61
61
|
import { observableRef } from "./observable.js";
|
|
62
62
|
import { Segment } from "../core/segment.js";
|
|
@@ -319,7 +319,7 @@ let Dropdown = (() => {
|
|
|
319
319
|
const headerLabel = this.headerText(maxLabelLen, caret);
|
|
320
320
|
return [
|
|
321
321
|
new Segment("[", baseStyle),
|
|
322
|
-
...
|
|
322
|
+
...labeled("", headerLabel, ` ${arrowChar}`, baseStyle, options.textOrder),
|
|
323
323
|
new Segment("]", baseStyle),
|
|
324
324
|
];
|
|
325
325
|
}
|
|
@@ -401,7 +401,7 @@ let Dropdown = (() => {
|
|
|
401
401
|
: new Style(ink(this.theme, "foreground", "surface"));
|
|
402
402
|
return [
|
|
403
403
|
new Segment(" ", rowStyle),
|
|
404
|
-
...
|
|
404
|
+
...labeled("", inner, "", rowStyle, order),
|
|
405
405
|
new Segment(" ", rowStyle),
|
|
406
406
|
];
|
|
407
407
|
}
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* It parses nothing and reads no terminal: `App` owns the one parser over its
|
|
6
6
|
* host's input (`host/input`), and `WidgetApp` hands this what the app hears.
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { WidgetKeyEvent } from "./types.js";
|
|
9
9
|
import type { FrameSource, KeyHandlerOptions } from "./types.js";
|
|
10
10
|
import type { Unsubscribe } from "../core/subscription.js";
|
|
11
|
-
import type {
|
|
11
|
+
import type { KeyEvent } from "../host/input.js";
|
|
12
12
|
import type { AppMouseEvent } from "../host/app.js";
|
|
13
|
-
import type {
|
|
14
|
-
type KeyHandler = (event:
|
|
13
|
+
import type { WheelEvent } from "../host/app.js";
|
|
14
|
+
type KeyHandler = (event: WidgetKeyEvent) => void;
|
|
15
15
|
export interface EventRouterOptions {
|
|
16
16
|
source: FrameSource;
|
|
17
17
|
/** Whether a left-button press focuses the widget under it before it hears the press. */
|
|
@@ -44,7 +44,7 @@ export declare class EventRouter {
|
|
|
44
44
|
onKey(handler: KeyHandler, options?: KeyHandlerOptions): Unsubscribe;
|
|
45
45
|
onMouse(handler: (event: AppMouseEvent) => void): Unsubscribe;
|
|
46
46
|
/** Route a key the app heard. */
|
|
47
|
-
key(press:
|
|
47
|
+
key(press: KeyEvent): void;
|
|
48
48
|
/** Route a pointer event the app heard. */
|
|
49
49
|
mouse(event: AppMouseEvent): void;
|
|
50
50
|
/**
|
|
@@ -53,7 +53,7 @@ export declare class EventRouter {
|
|
|
53
53
|
* Whether one moved is the answer: with none, the app passes the wheel
|
|
54
54
|
* outward.
|
|
55
55
|
*/
|
|
56
|
-
wheel({ x, y, lines }:
|
|
56
|
+
wheel({ x, y, lines }: WheelEvent): boolean;
|
|
57
57
|
private point;
|
|
58
58
|
private dispatchKey;
|
|
59
59
|
private dispatchMouse;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* It parses nothing and reads no terminal: `App` owns the one parser over its
|
|
6
6
|
* host's input (`host/input`), and `WidgetApp` hands this what the app hears.
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { WidgetKeyEvent } from "./types.js";
|
|
9
9
|
import { cellOf, drew, originOf, scrollTargetAt, widgetAt } from "./hit.js";
|
|
10
10
|
export class EventRouter {
|
|
11
11
|
source;
|
|
@@ -78,7 +78,7 @@ export class EventRouter {
|
|
|
78
78
|
}
|
|
79
79
|
/** Route a key the app heard. */
|
|
80
80
|
key(press) {
|
|
81
|
-
this.dispatchKey(new
|
|
81
|
+
this.dispatchKey(new WidgetKeyEvent(press, this.source.frameNow().time));
|
|
82
82
|
}
|
|
83
83
|
/** Route a pointer event the app heard. */
|
|
84
84
|
mouse(event) {
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* [LAW:dataflow-not-control-flow] focus transitions are observable state;
|
|
5
5
|
* widgets react to focus/blur events, the manager never skips dispatch.
|
|
6
6
|
*/
|
|
7
|
-
import type { InteractiveWidget, FocusManager,
|
|
7
|
+
import type { InteractiveWidget, FocusManager, WidgetKeyEvent } from "./types.js";
|
|
8
8
|
import type { Unsubscribe } from "../core/subscription.js";
|
|
9
9
|
/** What focus follows: the frame a `WidgetApp` just painted. */
|
|
10
10
|
export interface FocusView {
|
|
11
11
|
/** Every widget the view holds, in document order, whether or not it has a cell on screen. */
|
|
12
|
-
|
|
12
|
+
mounted(): readonly InteractiveWidget[];
|
|
13
13
|
/** The widgets with a cell on the frame on screen, in document order. */
|
|
14
14
|
onScreen(): readonly InteractiveWidget[];
|
|
15
15
|
/** The time a frame drawn now is drawn for (`RenderOptions.frame`), which a focus change is stamped with. */
|
|
@@ -46,7 +46,7 @@ export declare class DefaultFocusManager implements FocusManager {
|
|
|
46
46
|
*/
|
|
47
47
|
settle(): void;
|
|
48
48
|
onChange(handler: (current: InteractiveWidget | null) => void): Unsubscribe;
|
|
49
|
-
handleKey(event:
|
|
49
|
+
handleKey(event: WidgetKeyEvent): void;
|
|
50
50
|
private step;
|
|
51
51
|
private clear;
|
|
52
52
|
private setFocus;
|
|
@@ -90,10 +90,10 @@ let DefaultFocusManager = (() => {
|
|
|
90
90
|
return this.view.onScreen().filter(takesFocus);
|
|
91
91
|
}
|
|
92
92
|
next() {
|
|
93
|
-
this.step(this.view.
|
|
93
|
+
this.step(this.view.mounted());
|
|
94
94
|
}
|
|
95
95
|
prev() {
|
|
96
|
-
this.step([...this.view.
|
|
96
|
+
this.step([...this.view.mounted()].reverse());
|
|
97
97
|
}
|
|
98
98
|
// A widget not on screen yet can take focus: an app that is about to show
|
|
99
99
|
// it focuses it first, and the frame that shows it keeps it (`settle`).
|
|
@@ -118,7 +118,7 @@ let DefaultFocusManager = (() => {
|
|
|
118
118
|
*/
|
|
119
119
|
settle() {
|
|
120
120
|
const current = this.currentWidget;
|
|
121
|
-
if (current && takesFocus(current) && this.view.
|
|
121
|
+
if (current && takesFocus(current) && this.view.mounted().includes(current))
|
|
122
122
|
return;
|
|
123
123
|
const first = this.widgets[0];
|
|
124
124
|
if (first)
|