@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,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal color representation, parsing, downgrading, and ANSI code generation.
|
|
3
|
+
*/
|
|
4
|
+
import type { Env } from "./env.js";
|
|
5
|
+
/**
|
|
6
|
+
* Immutable RGBA color value. Alpha defaults to 1 (fully opaque).
|
|
7
|
+
*
|
|
8
|
+
* [LAW:single-enforcer] The constructor is the sole validation site for
|
|
9
|
+
* channel/alpha invariants. Float-arithmetic callers (HSL roundtrips, blends,
|
|
10
|
+
* lerps) are responsible for `Math.round` + clamp before construction; the
|
|
11
|
+
* constructor throws rather than silently masking out-of-range input.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ColorRgba {
|
|
14
|
+
readonly red: number;
|
|
15
|
+
readonly green: number;
|
|
16
|
+
readonly blue: number;
|
|
17
|
+
readonly alpha: number;
|
|
18
|
+
constructor(red: number, green: number, blue: number, alpha?: number);
|
|
19
|
+
/** 6-char `#RRGGBB` when fully opaque, 8-char `#RRGGBBAA` otherwise. */
|
|
20
|
+
get hex(): string;
|
|
21
|
+
/** `rgb(r,g,b)` when fully opaque, `rgba(r,g,b,a)` otherwise. */
|
|
22
|
+
get rgb(): string;
|
|
23
|
+
/** [r/255, g/255, b/255, alpha] — alpha is already 0..1, no division. */
|
|
24
|
+
get normalized(): [number, number, number, number];
|
|
25
|
+
/**
|
|
26
|
+
* Composite this color over an opaque background. Returns a fully opaque
|
|
27
|
+
* ColorRgba (alpha=1). Per-channel linear interpolation by alpha.
|
|
28
|
+
*
|
|
29
|
+
* [LAW:dataflow-not-control-flow] alpha=1 short-circuits to `this`, so
|
|
30
|
+
* callers can invoke this unconditionally; the data decides whether work
|
|
31
|
+
* happens.
|
|
32
|
+
*/
|
|
33
|
+
compositeOver(bg: ColorRgba): ColorRgba;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The surface a terminal draws a translucent colour over. A terminal cannot
|
|
37
|
+
* know what lies under its cells, so the SGR writer (`Style.toSgrCodes`), the
|
|
38
|
+
* exports that picture its output (`resolveLook`), the strip's seam test and
|
|
39
|
+
* the contrast choosers (`themes/colorMath`) all composite over this one
|
|
40
|
+
* colour. [LAW:one-source-of-truth] One constant, so
|
|
41
|
+
* the colour text is chosen against is the colour the writer draws.
|
|
42
|
+
*/
|
|
43
|
+
export declare const SURFACE_BLACK: ColorRgba;
|
|
44
|
+
/**
|
|
45
|
+
* WCAG 2.x relative luminance (0..1) of an opaque color. The single
|
|
46
|
+
* luminance function in the codebase — `contrastFor`, `contrastRatio`, and
|
|
47
|
+
* any caller that needs to reason about readability all funnel through it.
|
|
48
|
+
* [LAW:one-source-of-truth]
|
|
49
|
+
*/
|
|
50
|
+
export declare function relativeLuminance(c: ColorRgba): number;
|
|
51
|
+
/**
|
|
52
|
+
* WCAG 2.x contrast ratio between two colors, in [1, 21]. Symmetric — the
|
|
53
|
+
* order of arguments does not matter. 4.5 is the AA threshold for normal
|
|
54
|
+
* text, 3.0 for large text.
|
|
55
|
+
*
|
|
56
|
+
* Assumes opaque inputs: alpha is ignored, since the displayed contrast of a
|
|
57
|
+
* translucent color depends on what it composites over. For a translucent
|
|
58
|
+
* foreground, flatten it first (or use `ensureContrast`, which does).
|
|
59
|
+
*/
|
|
60
|
+
export declare function contrastRatio(a: ColorRgba, b: ColorRgba): number;
|
|
61
|
+
/**
|
|
62
|
+
* An indexed palette: entry `i` of `colors` is terminal index `firstIndex + i`.
|
|
63
|
+
* `firstIndex` lets a table hold only the part of a palette a downgrade may
|
|
64
|
+
* choose (the 256-colour cube and grey ramp start at 16) while every index it
|
|
65
|
+
* reports is the terminal's own.
|
|
66
|
+
*/
|
|
67
|
+
export declare class ColorTable {
|
|
68
|
+
private readonly colors;
|
|
69
|
+
readonly firstIndex: number;
|
|
70
|
+
private readonly matchMemo;
|
|
71
|
+
private readonly readableMemo;
|
|
72
|
+
constructor(colors: ColorRgba[], firstIndex?: number);
|
|
73
|
+
get(index: number): ColorRgba;
|
|
74
|
+
private luminanceCache;
|
|
75
|
+
/** Each entry's relative luminance, computed once per table. */
|
|
76
|
+
private luminances;
|
|
77
|
+
/** How many entries the table holds (terminal indices `firstIndex`…). */
|
|
78
|
+
get size(): number;
|
|
79
|
+
/**
|
|
80
|
+
* Finds the nearest table index to the given color (Euclidean RGB distance, cached).
|
|
81
|
+
* Alpha is part of the cache key so two values that differ only in alpha
|
|
82
|
+
* don't collide, but is not used in the distance metric.
|
|
83
|
+
*/
|
|
84
|
+
match(value: ColorRgba): number;
|
|
85
|
+
private nearest;
|
|
86
|
+
/**
|
|
87
|
+
* The nearest entry to `value` (the distance `match` uses) among those that
|
|
88
|
+
* clear `minRatio` against `on`; when none does, the entry with the most
|
|
89
|
+
* contrast against `on`. Text downgraded on its own background: `match`
|
|
90
|
+
* moves text and background independently, and two independent roundings
|
|
91
|
+
* can meet in the middle, so a pair that read at 4.5:1 in truecolor can
|
|
92
|
+
* draw at 2:1. [LAW:dataflow-not-control-flow] One scan scores every entry;
|
|
93
|
+
* the ratio decides which one wins.
|
|
94
|
+
*/
|
|
95
|
+
matchReadable(value: ColorRgba, on: ColorRgba, minRatio: number): number;
|
|
96
|
+
private nearestReadable;
|
|
97
|
+
/**
|
|
98
|
+
* The nearest entry to `value` (the distance `match` uses) among those
|
|
99
|
+
* `accept` takes, given each entry's colour and terminal index; `undefined`
|
|
100
|
+
* when it takes none. Entries are offered nearest-first (ties to the lower
|
|
101
|
+
* index) and the first taken wins, so an expensive predicate runs only as
|
|
102
|
+
* far out as the answer. Uncached: the predicate is the caller's, and a
|
|
103
|
+
* closure has no key.
|
|
104
|
+
*/
|
|
105
|
+
matchWhere(value: ColorRgba, accept: (entry: ColorRgba, index: number) => boolean): number | undefined;
|
|
106
|
+
}
|
|
107
|
+
export declare enum ColorDepth {
|
|
108
|
+
DEFAULT = 0,
|
|
109
|
+
STANDARD = 1,
|
|
110
|
+
EIGHT_BIT = 2,
|
|
111
|
+
TRUECOLOR = 3,
|
|
112
|
+
WINDOWS = 4
|
|
113
|
+
}
|
|
114
|
+
export interface DetectColorOptions {
|
|
115
|
+
/** Environment to probe. Defaults to `process.env`. */
|
|
116
|
+
env?: Env;
|
|
117
|
+
/** Whether output is going to a real terminal. Defaults to `process.stdout?.isTTY`. */
|
|
118
|
+
isTTY?: boolean;
|
|
119
|
+
}
|
|
120
|
+
declare const COLOR_SYSTEM_DEPTHS: {
|
|
121
|
+
readonly truecolor: ColorDepth.TRUECOLOR;
|
|
122
|
+
readonly "256": ColorDepth.EIGHT_BIT;
|
|
123
|
+
readonly ansi: ColorDepth.STANDARD;
|
|
124
|
+
readonly none: null;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* A colour system by name: `"auto"` detects it from the environment, and each
|
|
128
|
+
* other name is a fixed depth — `"none"` no colour. `ColorDepth.WINDOWS` has
|
|
129
|
+
* no name; pass the enum value where a `ColorDepth` is accepted.
|
|
130
|
+
*/
|
|
131
|
+
export type ColorSystemName = "auto" | keyof typeof COLOR_SYSTEM_DEPTHS;
|
|
132
|
+
/**
|
|
133
|
+
* Detect the terminal's color capability from env + TTY state.
|
|
134
|
+
*
|
|
135
|
+
* Probes (in priority order): NO_COLOR (per https://no-color.org —
|
|
136
|
+
* any non-empty value disables color), FORCE_COLOR (numeric/boolean override),
|
|
137
|
+
* TTY presence, TERM=dumb/unknown, COLORTERM, known terminal/TERM_PROGRAM
|
|
138
|
+
* names, and TERM regex patterns. Returns `null` for "no color".
|
|
139
|
+
*
|
|
140
|
+
* [LAW:dataflow-not-control-flow] Same probes run every call; variability is
|
|
141
|
+
* in the env values, not in which checks execute.
|
|
142
|
+
*/
|
|
143
|
+
export declare function detectColorSystem(options?: DetectColorOptions): ColorDepth | null;
|
|
144
|
+
/**
|
|
145
|
+
* A terminal that says it cannot be drawn on: `TERM` is `dumb` or `unknown`,
|
|
146
|
+
* as Emacs' shell mode sets it. It takes no colour and nothing that moves the
|
|
147
|
+
* cursor.
|
|
148
|
+
*/
|
|
149
|
+
export declare function isDumbTerminal(env: Env): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Where segments are written, as everything the serializer (`segmentsToString`)
|
|
152
|
+
* needs to know about it: the colour depth SGR is drawn at, and whether OSC 8
|
|
153
|
+
* hyperlinks are emitted. The serializer takes this value whole, so a fact the
|
|
154
|
+
* encoding comes to need joins it here rather than the serializer's signature.
|
|
155
|
+
*/
|
|
156
|
+
export interface Destination {
|
|
157
|
+
readonly colorSystem: ColorDepth | null;
|
|
158
|
+
readonly hyperlinks: boolean;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Resolve a colour spec into a `Destination`.
|
|
162
|
+
*
|
|
163
|
+
* [LAW:single-enforcer] The one place a spec becomes both facts. A hyperlink is
|
|
164
|
+
* not a colour: an explicit depth — `"none"` and `null` included — states a
|
|
165
|
+
* colour choice and keeps links, and under `"auto"` links follow what the
|
|
166
|
+
* terminal can take (no TTY, TERM=dumb: none) while NO_COLOR and FORCE_COLOR=0,
|
|
167
|
+
* colour preferences, leave them alone. A FORCE_COLOR that forces colour on
|
|
168
|
+
* declares the destination takes escapes, so it keeps links on a pipe too.
|
|
169
|
+
*/
|
|
170
|
+
export declare function resolveDestination(spec: ColorSystemName | ColorDepth | null, options?: DetectColorOptions): Destination;
|
|
171
|
+
/**
|
|
172
|
+
* Resolve a colour system name into a `ColorDepth` (or `null` for no color).
|
|
173
|
+
*
|
|
174
|
+
* `"auto"` triggers env-based detection; every other name is a fixed depth.
|
|
175
|
+
* A name outside the vocabulary — reachable only from untyped JavaScript —
|
|
176
|
+
* throws: silent fallback would mask a typo.
|
|
177
|
+
*
|
|
178
|
+
* [LAW:single-enforcer] All name→ColorDepth resolution flows through here.
|
|
179
|
+
*/
|
|
180
|
+
export declare function resolveColorSystem(spec: ColorSystemName, options?: DetectColorOptions): ColorDepth | null;
|
|
181
|
+
export declare class ColorParseError extends Error {
|
|
182
|
+
constructor(message: string);
|
|
183
|
+
}
|
|
184
|
+
export declare class ColorSpec {
|
|
185
|
+
readonly name: string;
|
|
186
|
+
readonly type: ColorDepth;
|
|
187
|
+
readonly number: number | undefined;
|
|
188
|
+
readonly value: ColorRgba | undefined;
|
|
189
|
+
private downgradeCache;
|
|
190
|
+
constructor(name: string, type: ColorDepth, number?: number, value?: ColorRgba);
|
|
191
|
+
get isDefault(): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* The colour every terminal draws this spec as, where that is fixed — before
|
|
194
|
+
* any alpha is flattened, so a translucent value is drawn composited over
|
|
195
|
+
* its ground (`flattenAlpha`) and should be measured that way: a
|
|
196
|
+
* truecolor value, or a 256-colour cube or grey-ramp entry (xterm fixes
|
|
197
|
+
* indices 16–255, and `fromAnsi` types only those as EIGHT_BIT). ANSI 0–15,
|
|
198
|
+
* the default colour and a blend reaching either are the terminal theme's
|
|
199
|
+
* own, so they have none.
|
|
200
|
+
*/
|
|
201
|
+
get fixedValue(): ColorRgba | undefined;
|
|
202
|
+
get isSystemDefined(): boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Generates SGR parameter strings for this color.
|
|
205
|
+
*/
|
|
206
|
+
getAnsiCodes(foreground?: boolean): string[];
|
|
207
|
+
/**
|
|
208
|
+
* Composite this color's alpha (if any) against an opaque background,
|
|
209
|
+
* returning a fully-opaque ColorSpec. Non-truecolor specs (palette
|
|
210
|
+
* indices, default) have no alpha and pass through unchanged.
|
|
211
|
+
*
|
|
212
|
+
* [LAW:single-enforcer] Sole alpha-flattening site for the render
|
|
213
|
+
* pipeline. Run *before* downgrade — otherwise palette matching on the
|
|
214
|
+
* still-translucent RGB silently drops alpha (the "flatten then lose
|
|
215
|
+
* alpha" path the unification ticket forbids).
|
|
216
|
+
*
|
|
217
|
+
* [LAW:dataflow-not-control-flow] `ColorRgba.compositeOver` is a no-op
|
|
218
|
+
* when alpha=1, so callers invoke this unconditionally; the data
|
|
219
|
+
* (alpha value) decides whether work happens.
|
|
220
|
+
*/
|
|
221
|
+
flattenAlpha(bg: ColorRgba): ColorSpec;
|
|
222
|
+
/**
|
|
223
|
+
* Downgrade to a lower-fidelity color depth. Cached.
|
|
224
|
+
*/
|
|
225
|
+
downgrade(targetSystem: ColorDepth): ColorSpec;
|
|
226
|
+
/**
|
|
227
|
+
* Resolves to an actual RGB(A) value for any color type.
|
|
228
|
+
*/
|
|
229
|
+
getTruecolor(theme?: TerminalTheme, foreground?: boolean): ColorRgba;
|
|
230
|
+
static default(): ColorSpec;
|
|
231
|
+
static fromAnsi(n: number): ColorSpec;
|
|
232
|
+
static fromRgba(value: ColorRgba): ColorSpec;
|
|
233
|
+
static fromRgb(r: number, g: number, b: number): ColorSpec;
|
|
234
|
+
/**
|
|
235
|
+
* The colour `t` of the way from `from` to `to`: what `blend(from,to,t)`
|
|
236
|
+
* parses to. Two fixed colours mix to a fixed colour. A mix reaching a
|
|
237
|
+
* theme's own colour stays a mix until it is drawn, so whatever theme draws
|
|
238
|
+
* an end draws the mix from it: exported under a theme whose `blue` is
|
|
239
|
+
* #61afef, a mix with `blue` starts from #61afef. A terminal is told its RGB
|
|
240
|
+
* under the standard table, the only one a render has.
|
|
241
|
+
*
|
|
242
|
+
* Each end is one opaque colour: `default` is no colour to mix, and a
|
|
243
|
+
* translucent end has no one shade until it is laid on a ground.
|
|
244
|
+
*/
|
|
245
|
+
static blend(from: ColorSpec, to: ColorSpec, t: number): ColorSpec;
|
|
246
|
+
/**
|
|
247
|
+
* The spec that draws `value` nearest to it at `depth` on a terminal known
|
|
248
|
+
* to show `theme`, as the colour of the glyph (`foreground`) or of the
|
|
249
|
+
* ground. Where `downgrade` knows no terminal, and so rounds only against
|
|
250
|
+
* colours every terminal fixes (or, at sixteen colours, the stock
|
|
251
|
+
* sixteen), this rounds against every colour the depth can write whose
|
|
252
|
+
* look `theme` fixes: the default colour, the theme's sixteen, and at 256
|
|
253
|
+
* colours the cube and grey ramp too. A colour read off any of those and
|
|
254
|
+
* moved a little is drawn as the colour it came from — or, where the theme
|
|
255
|
+
* gives two slots one colour, as the lower slot, which looks the same.
|
|
256
|
+
*
|
|
257
|
+
* `value` is opaque: a translucent colour has no one look until it is laid
|
|
258
|
+
* on a ground (`flattenAlpha`).
|
|
259
|
+
*/
|
|
260
|
+
static matchOn(value: ColorRgba, depth: ColorDepth, theme: TerminalTheme, foreground: boolean): ColorSpec;
|
|
261
|
+
/**
|
|
262
|
+
* Parse a color string. Memoized (`Memo`): a string parsed again while
|
|
263
|
+
* remembered returns the same instance.
|
|
264
|
+
*/
|
|
265
|
+
static parse(colorString: string): ColorSpec;
|
|
266
|
+
private performDowngrade;
|
|
267
|
+
}
|
|
268
|
+
/** Six hex digits, no `#`, as an opaque colour. @throws {ColorParseError} on anything else. */
|
|
269
|
+
export declare function parseRgbHex(hex: string): ColorRgba;
|
|
270
|
+
/** Eight hex digits, no `#`, the last pair alpha. @throws {ColorParseError} on anything else. */
|
|
271
|
+
export declare function parseRgbaHex(hex: string): ColorRgba;
|
|
272
|
+
/**
|
|
273
|
+
* A `#RRGGBB` or `#RRGGBBAA` literal, exactly — no surrounding whitespace.
|
|
274
|
+
* @throws {ColorParseError} on anything else.
|
|
275
|
+
*/
|
|
276
|
+
export declare function parseHexColor(literal: string): ColorRgba;
|
|
277
|
+
export declare function blendRgb(color1: ColorRgba, color2: ColorRgba, crossFade?: number): ColorRgba;
|
|
278
|
+
/**
|
|
279
|
+
* A terminal theme — surface/foreground baseline, the sixteen ANSI colours,
|
|
280
|
+
* and a semantic palette.
|
|
281
|
+
*
|
|
282
|
+
* **`ansiColors` is the theme's own sixteen colours**, the shades a terminal
|
|
283
|
+
* showing this theme draws `red`, `blue` and the rest in. `ColorSpec.parse("red")`
|
|
284
|
+
* is ANSI colour 1 under every theme; which red that is, is the theme's to say,
|
|
285
|
+
* as it is in Rich, where each `TerminalTheme` carries its own table.
|
|
286
|
+
*/
|
|
287
|
+
export declare class TerminalTheme {
|
|
288
|
+
readonly backgroundColor: ColorRgba;
|
|
289
|
+
readonly foregroundColor: ColorRgba;
|
|
290
|
+
readonly ansiColors: ColorTable;
|
|
291
|
+
readonly palette: import("../themes/palette.js").Palette;
|
|
292
|
+
constructor(backgroundColor: ColorRgba, foregroundColor: ColorRgba, ansiColors: ColorTable, palette: import("../themes/palette.js").Palette);
|
|
293
|
+
}
|
|
294
|
+
export declare const STANDARD_TABLE: ColorTable;
|
|
295
|
+
export declare const EIGHT_BIT_TABLE: ColorTable;
|
|
296
|
+
/**
|
|
297
|
+
* What a downgrade to 256 colours may choose: the cube and the grey ramp,
|
|
298
|
+
* indices 16–255. Indices 0–15 are the terminal's own ANSI colours, which
|
|
299
|
+
* every theme redefines, so their RGB is unknown and a match against them is
|
|
300
|
+
* a guess; Python Rich never picks them either.
|
|
301
|
+
*/
|
|
302
|
+
export declare const EIGHT_BIT_DOWNGRADE_TABLE: ColorTable;
|
|
303
|
+
export declare const WINDOWS_TABLE: ColorTable;
|
|
304
|
+
/**
|
|
305
|
+
* The terminal a colour at `depth` is drawn by: `theme`, or when a caller names
|
|
306
|
+
* none, the one the depth assumes — the Windows console at WINDOWS, the VGA
|
|
307
|
+
* sixteen otherwise — for `ColorSpec.getTruecolor` and the contrast measurement
|
|
308
|
+
* that reads it. (Widgets fall back to `DEFAULT_TERMINAL_THEME`, which carries a
|
|
309
|
+
* palette this does not.)
|
|
310
|
+
*/
|
|
311
|
+
export declare function resolveTerminal(theme: TerminalTheme | undefined, depth: ColorDepth): TerminalTheme;
|
|
312
|
+
/**
|
|
313
|
+
* The table a downgrade to `depth` rounds a fixed colour against.
|
|
314
|
+
* [LAW:one-source-of-truth] `ColorSpec.downgrade` picks the index a colour is
|
|
315
|
+
* written as from it, and colorMath hands back its entries as colours the
|
|
316
|
+
* writer rounds to those same indices.
|
|
317
|
+
*/
|
|
318
|
+
export declare function downgradeTable(depth: ColorDepth.EIGHT_BIT | ColorDepth.STANDARD | ColorDepth.WINDOWS): ColorTable;
|
|
319
|
+
export declare const ANSI_COLOR_NAMES: Record<string, number>;
|
|
320
|
+
/**
|
|
321
|
+
* Every word `ColorSpec.parse` accepts as a name rather than a `#hex`,
|
|
322
|
+
* `rgb()` or `color(N)` form: `default` and the named palette entries, which
|
|
323
|
+
* are exactly the two name checks `parseSingle` makes.
|
|
324
|
+
*/
|
|
325
|
+
export declare const COLOR_NAMES: readonly string[];
|
|
326
|
+
export {};
|