silvery 0.19.2 → 0.21.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 -4
- package/dist/Text-Lq0dmj8-.mjs +239 -0
- package/dist/Text-Lq0dmj8-.mjs.map +1 -0
- package/dist/UPNG-Bo33r8rA.mjs +3 -0
- package/dist/UPNG-DosRPdF4.mjs +5075 -0
- package/dist/UPNG-DosRPdF4.mjs.map +1 -0
- package/dist/__vite-browser-external-2447137e-D_JM6skp.mjs +6 -0
- package/dist/__vite-browser-external-2447137e-D_JM6skp.mjs.map +1 -0
- package/dist/{animation-Cn64yepo.mjs → animation-ZMN2_XKv.mjs} +2 -2
- package/dist/animation-ZMN2_XKv.mjs.map +1 -0
- package/dist/{ansi-Cc33mW54.d.mts → ansi-2Xn0yatP.d.mts} +1 -1
- package/dist/{ansi-Cc33mW54.d.mts.map → ansi-2Xn0yatP.d.mts.map} +1 -1
- package/dist/{ansi-CLOitHKx.mjs → ansi-D1KQMAbf.mjs} +1 -1
- package/dist/{ansi-CLOitHKx.mjs.map → ansi-D1KQMAbf.mjs.map} +1 -1
- package/dist/ansi-yC4RyBNY.mjs +22441 -0
- package/dist/ansi-yC4RyBNY.mjs.map +1 -0
- package/dist/apng-CR08rIaH.mjs +58 -0
- package/dist/apng-CR08rIaH.mjs.map +1 -0
- package/dist/apng-DaHfVaVI.mjs +3 -0
- package/dist/assets/resvgjs.darwin-arm64-BtufyGW1.node +0 -0
- package/dist/assets/skia.darwin-arm64-DQs5sT6N.node +0 -0
- package/dist/backend-B-WYLUib.mjs +13396 -0
- package/dist/backend-B-WYLUib.mjs.map +1 -0
- package/dist/backends-CUtan80W.mjs +3 -0
- package/dist/backends-DIVYzKqd.mjs +1083 -0
- package/dist/backends-DIVYzKqd.mjs.map +1 -0
- package/dist/bound-term-0sPrrzH1.d.mts +4640 -0
- package/dist/bound-term-0sPrrzH1.d.mts.map +1 -0
- package/dist/canvas-1v7dPT-_.mjs +3 -0
- package/dist/canvas-CSuPOMNt.mjs +1442 -0
- package/dist/canvas-CSuPOMNt.mjs.map +1 -0
- package/dist/{chunk-Vs_PY4HZ.mjs → chunk-BSw8zbkd.mjs} +1 -1
- package/dist/cli-dvo0r2fs.mjs +4 -0
- package/dist/compare-CQodSH4G.mjs +376 -0
- package/dist/compare-CQodSH4G.mjs.map +1 -0
- package/dist/compare-DHlcxEYA.mjs +3 -0
- package/dist/context-BU5LkkIy.mjs.map +1 -1
- package/dist/devtools-CJdt5H0X.mjs +2 -0
- package/dist/{devtools-DxkSLXDA.mjs → devtools-DcQjgyjL.mjs} +5 -4
- package/dist/{devtools-DxkSLXDA.mjs.map → devtools-DcQjgyjL.mjs.map} +1 -1
- package/dist/easing-BI-ASGMO.d.mts +24 -0
- package/dist/easing-BI-ASGMO.d.mts.map +1 -0
- package/dist/{eta-Bb3RH3wh.mjs → eta-CJlGH06n.mjs} +1 -1
- package/dist/{eta-Bb3RH3wh.mjs.map → eta-CJlGH06n.mjs.map} +1 -1
- package/dist/flexily-zero-adapter-C3Vj0fPt.mjs +306 -0
- package/dist/flexily-zero-adapter-C3Vj0fPt.mjs.map +1 -0
- package/dist/{flexily-zero-adapter-CMxXhdOL.mjs → flexily-zero-adapter-C4lW_Ov5.mjs} +1 -1
- package/dist/fonts-BFmhXDv7.mjs +88 -0
- package/dist/fonts-BFmhXDv7.mjs.map +1 -0
- package/dist/gif-C_AjaT9d.mjs +188 -0
- package/dist/gif-C_AjaT9d.mjs.map +1 -0
- package/dist/gif-DaC4XrxA.mjs +3 -0
- package/dist/gifenc-BOUT-KFB.mjs +730 -0
- package/dist/gifenc-BOUT-KFB.mjs.map +1 -0
- package/dist/image-C2Birh2x.mjs +1252 -0
- package/dist/image-C2Birh2x.mjs.map +1 -0
- package/dist/index-BUMxS65f.d.mts +453 -0
- package/dist/index-BUMxS65f.d.mts.map +1 -0
- package/dist/{index-D3saHouR.d.mts → index-CSQf13CI.d.mts} +1057 -1133
- package/dist/index-CSQf13CI.d.mts.map +1 -0
- package/dist/{index-BXslOebb.d.mts → index-Cl9KKjQ_.d.mts} +4919 -3921
- package/dist/index-Cl9KKjQ_.d.mts.map +1 -0
- package/dist/index-XbNrPhWl.d.mts +336 -0
- package/dist/index-XbNrPhWl.d.mts.map +1 -0
- package/dist/index.d.mts +8 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +14 -12
- package/dist/index.mjs.map +1 -1
- package/dist/key-mapping-CS-YD_cD.mjs +132 -0
- package/dist/key-mapping-CS-YD_cD.mjs.map +1 -0
- package/dist/key-mapping-Yn-Jgrij.mjs +3 -0
- package/dist/{layout-engine-B6Cdz1yZ.mjs → layout-engine-C07LEXWT.mjs} +1 -1
- package/dist/layout-engine-C2px0RJE.mjs +67 -0
- package/dist/layout-engine-C2px0RJE.mjs.map +1 -0
- package/dist/layout-signals-Cnw6xk8Q.mjs +988 -0
- package/dist/layout-signals-Cnw6xk8Q.mjs.map +1 -0
- package/dist/mouse-events-Dki3ISIp.mjs +1044 -0
- package/dist/mouse-events-Dki3ISIp.mjs.map +1 -0
- package/dist/{multi-progress-Bq9Oi_WI.mjs → multi-progress-CIRjrzma.mjs} +3 -3
- package/dist/{multi-progress-Bq9Oi_WI.mjs.map → multi-progress-CIRjrzma.mjs.map} +1 -1
- package/dist/{multi-progress-DAQC7eap.d.mts → multi-progress-DHZ2xUT2.d.mts} +2 -2
- package/dist/{multi-progress-DAQC7eap.d.mts.map → multi-progress-DHZ2xUT2.d.mts.map} +1 -1
- package/dist/{node-BeWlnCPY.mjs → node-CjM5Rt-M.mjs} +4 -4
- package/dist/node-CjM5Rt-M.mjs.map +1 -0
- package/dist/playwright-D5YiZcNS.mjs +76397 -0
- package/dist/playwright-D5YiZcNS.mjs.map +1 -0
- package/dist/png-codec-Dp84742B.mjs +36 -0
- package/dist/png-codec-Dp84742B.mjs.map +1 -0
- package/dist/png-codec-QwOtJ8Zs.mjs +3 -0
- package/dist/progress-DB_Xo071.mjs +675 -0
- package/dist/progress-DB_Xo071.mjs.map +1 -0
- package/dist/{progress-bar-CXE5Qfkd.mjs → progress-bar-oJwq22CR.mjs} +4 -4
- package/dist/{progress-bar-CXE5Qfkd.mjs.map → progress-bar-oJwq22CR.mjs.map} +1 -1
- package/dist/rasterizer-BRXrDdWx.mjs +3 -0
- package/dist/rasterizer-CpEhJvdR.mjs +296 -0
- package/dist/rasterizer-CpEhJvdR.mjs.map +1 -0
- package/dist/reconciler-DldIJB93.mjs +2083 -0
- package/dist/reconciler-DldIJB93.mjs.map +1 -0
- package/dist/{render-string-CDCeYkS3.mjs → render-string-BcoCpjCB.mjs} +1 -1
- package/dist/{render-string-Darrg7ku.mjs → render-string-DkQacASz.mjs} +2707 -549
- package/dist/render-string-DkQacASz.mjs.map +1 -0
- package/dist/resvg-js-DkOndZI3.mjs +203 -0
- package/dist/resvg-js-DkOndZI3.mjs.map +1 -0
- package/dist/runtime.d.mts +3 -2
- package/dist/runtime.mjs +3 -3
- package/dist/schemes-JjNp4aSl.mjs +2611 -0
- package/dist/schemes-JjNp4aSl.mjs.map +1 -0
- package/dist/{spinner-CGo34vyR.d.mts → spinner-CZINHpkV.d.mts} +2 -2
- package/dist/{spinner-CGo34vyR.d.mts.map → spinner-CZINHpkV.d.mts.map} +1 -1
- package/dist/{spinner-CeOmcuw_.mjs → spinner-D9lrHr8s.mjs} +7 -7
- package/dist/spinner-D9lrHr8s.mjs.map +1 -0
- package/dist/src-5w9QR6_8.mjs +1071 -0
- package/dist/src-5w9QR6_8.mjs.map +1 -0
- package/dist/src-BNTToU7l.mjs +4387 -0
- package/dist/src-BNTToU7l.mjs.map +1 -0
- package/dist/{src-CF-6UN01.mjs → src-BR4xNwdG.mjs} +10436 -2622
- package/dist/src-BR4xNwdG.mjs.map +1 -0
- package/dist/{types-Bk2yw9Qj.mjs → src-DKp-_OFG.mjs} +34 -94
- package/dist/src-DKp-_OFG.mjs.map +1 -0
- package/dist/src-bt8wSrfJ.mjs +258 -0
- package/dist/src-bt8wSrfJ.mjs.map +1 -0
- package/dist/src-e33Y6kNJ.mjs +3 -0
- package/dist/src-iDwu25UD.mjs +1814 -0
- package/dist/src-iDwu25UD.mjs.map +1 -0
- package/dist/steps-Bp2uNqnn.d.mts +202 -0
- package/dist/steps-Bp2uNqnn.d.mts.map +1 -0
- package/dist/svg-15lZZzxq.mjs +486 -0
- package/dist/svg-15lZZzxq.mjs.map +1 -0
- package/dist/svg-Cz0UXcDj.mjs +255 -0
- package/dist/svg-Cz0UXcDj.mjs.map +1 -0
- package/dist/svg-DY72a4HK.mjs +3 -0
- package/dist/svg-g1D6ErwR.d.mts +82 -0
- package/dist/svg-g1D6ErwR.d.mts.map +1 -0
- package/dist/term.d.mts +3 -0
- package/dist/term.mjs +9 -0
- package/dist/term.mjs.map +1 -0
- package/dist/theme.d.mts +95 -2
- package/dist/theme.d.mts.map +1 -0
- package/dist/theme.mjs +9 -3
- package/dist/theme.mjs.map +1 -0
- package/dist/{types-BH_v3iMT.d.mts → types-kt_fKR37.d.mts} +2 -15
- package/dist/types-kt_fKR37.d.mts.map +1 -0
- package/dist/ui/animation.d.mts +2 -1
- package/dist/ui/animation.mjs +1 -1
- package/dist/ui/ansi.d.mts +1 -1
- package/dist/ui/ansi.mjs +1 -1
- package/dist/ui/cli.d.mts +3 -3
- package/dist/ui/cli.mjs +5 -5
- package/dist/ui/display.d.mts +1 -1
- package/dist/ui/image.d.mts +2 -2
- package/dist/ui/image.mjs +2 -2
- package/dist/ui/input.d.mts +1 -1
- package/dist/ui/input.mjs +4 -2
- package/dist/ui/input.mjs.map +1 -1
- package/dist/ui/progress.d.mts +5 -249
- package/dist/ui/progress.mjs +5 -858
- package/dist/ui/react.d.mts +1 -1
- package/dist/ui/react.mjs +2 -2
- package/dist/ui/recording-chrome-react.d.mts +21 -0
- package/dist/ui/recording-chrome-react.d.mts.map +1 -0
- package/dist/ui/recording-chrome-react.mjs +105 -0
- package/dist/ui/recording-chrome-react.mjs.map +1 -0
- package/dist/ui/recording-chrome.d.mts +2 -0
- package/dist/ui/recording-chrome.mjs +2 -0
- package/dist/ui/utils.mjs +1 -1
- package/dist/ui/wrappers.d.mts +3 -3
- package/dist/ui/wrappers.mjs +2 -2
- package/dist/ui.d.mts +7 -6
- package/dist/ui.mjs +8 -7
- package/dist/{useLatest-Bg2x4bfP.d.mts → useLatest-DRDDVwjh.d.mts} +5 -25
- package/dist/useLatest-DRDDVwjh.d.mts.map +1 -0
- package/dist/{with-text-input-CRfoiFFG.d.mts → with-text-input-YeohVLeo.d.mts} +4 -55
- package/dist/with-text-input-YeohVLeo.d.mts.map +1 -0
- package/dist/wrapper-C70ATkVv.mjs +3527 -0
- package/dist/wrapper-C70ATkVv.mjs.map +1 -0
- package/dist/{wrappers-UTADQkSY.mjs → wrappers-BCUYITrY.mjs} +5 -157
- package/dist/wrappers-BCUYITrY.mjs.map +1 -0
- package/dist/{yoga-adapter-8oRGRw8V.mjs → yoga-adapter-BnZX1PAY.mjs} +28 -2
- package/dist/yoga-adapter-BnZX1PAY.mjs.map +1 -0
- package/dist/yoga-adapter-DxgsQ_gg.mjs +2 -0
- package/dist/zipBundle-3nqeDRtm.mjs +3 -0
- package/dist/zipBundle-VNAYFmqJ.mjs +2003 -0
- package/dist/zipBundle-VNAYFmqJ.mjs.map +1 -0
- package/package.json +20 -9
- package/dist/animation-Cn64yepo.mjs.map +0 -1
- package/dist/cli-BKp0YtBD.mjs +0 -4
- package/dist/devtools-9QY4teqI.mjs +0 -2
- package/dist/flexily-zero-adapter-BlQa46nr.mjs +0 -3385
- package/dist/flexily-zero-adapter-BlQa46nr.mjs.map +0 -1
- package/dist/image-CTII5QWI.mjs +0 -477
- package/dist/image-CTII5QWI.mjs.map +0 -1
- package/dist/index-BXslOebb.d.mts.map +0 -1
- package/dist/index-BnA7mNpo.d.mts +0 -175
- package/dist/index-BnA7mNpo.d.mts.map +0 -1
- package/dist/index-D3saHouR.d.mts.map +0 -1
- package/dist/layout-engine-ClUgv6jB.mjs +0 -50
- package/dist/layout-engine-ClUgv6jB.mjs.map +0 -1
- package/dist/node-BeWlnCPY.mjs.map +0 -1
- package/dist/reconciler-Cwgm8hRR.mjs +0 -8459
- package/dist/reconciler-Cwgm8hRR.mjs.map +0 -1
- package/dist/render-string-Darrg7ku.mjs.map +0 -1
- package/dist/spinner-CeOmcuw_.mjs.map +0 -1
- package/dist/src-B5GjfG7g.mjs +0 -4305
- package/dist/src-B5GjfG7g.mjs.map +0 -1
- package/dist/src-CChwjk0Z.mjs +0 -738
- package/dist/src-CChwjk0Z.mjs.map +0 -1
- package/dist/src-CF-6UN01.mjs.map +0 -1
- package/dist/src-NCKb8kE5.mjs +0 -2660
- package/dist/src-NCKb8kE5.mjs.map +0 -1
- package/dist/types-BH_v3iMT.d.mts.map +0 -1
- package/dist/types-Bk2yw9Qj.mjs.map +0 -1
- package/dist/ui/progress.d.mts.map +0 -1
- package/dist/ui/progress.mjs.map +0 -1
- package/dist/useLatest-Bg2x4bfP.d.mts.map +0 -1
- package/dist/with-text-input-CRfoiFFG.d.mts.map +0 -1
- package/dist/wrappers-UTADQkSY.mjs.map +0 -1
- package/dist/yoga-adapter-8oRGRw8V.mjs.map +0 -1
- package/dist/yoga-adapter-D_CcxSt5.mjs +0 -2
|
@@ -0,0 +1,4387 @@
|
|
|
1
|
+
import { i as __require, n as __esmMin } from "./chunk-BSw8zbkd.mjs";
|
|
2
|
+
import { blend, brighten, checkContrast, colorDistance, complement, contrastFg, darken, deltaE, ensureContrast, hexToOklch, hexToRgb as hexToRgb$1, oklchToHex, relativeLuminance } from "@silvery/color";
|
|
3
|
+
import "string-width";
|
|
4
|
+
//#region packages/ansi/src/constants.ts
|
|
5
|
+
/**
|
|
6
|
+
* Build underline color escape code for RGB values.
|
|
7
|
+
* Format: \x1b[58:2::r:g:bm (SGR 58 with RGB color space)
|
|
8
|
+
*/
|
|
9
|
+
function buildUnderlineColorCode(r, g, b) {
|
|
10
|
+
return `\x1b[58:2::${r}:${g}:${b}m`;
|
|
11
|
+
}
|
|
12
|
+
var UNDERLINE_CODES, UNDERLINE_STANDARD, UNDERLINE_RESET_STANDARD, UNDERLINE_COLOR_RESET;
|
|
13
|
+
var init_constants = __esmMin((() => {
|
|
14
|
+
UNDERLINE_CODES = {
|
|
15
|
+
none: "\x1B[4:0m",
|
|
16
|
+
single: "\x1B[4:1m",
|
|
17
|
+
double: "\x1B[4:2m",
|
|
18
|
+
curly: "\x1B[4:3m",
|
|
19
|
+
dotted: "\x1B[4:4m",
|
|
20
|
+
dashed: "\x1B[4:5m",
|
|
21
|
+
reset: "\x1B[4:0m"
|
|
22
|
+
};
|
|
23
|
+
UNDERLINE_STANDARD = "\x1B[4m";
|
|
24
|
+
UNDERLINE_RESET_STANDARD = "\x1B[24m";
|
|
25
|
+
UNDERLINE_COLOR_RESET = "\x1B[59m";
|
|
26
|
+
}));
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region packages/ansi/src/caps.ts
|
|
29
|
+
/**
|
|
30
|
+
* Default capabilities — modern-terminal-ish defaults for headless / emulator /
|
|
31
|
+
* unknown contexts. Heuristic fields (`maybe*`) bake in "probably dark, no
|
|
32
|
+
* nerd font, wide emojis like Ghostty/iTerm" — callers override via
|
|
33
|
+
* `createTerminalProfile({caps})`.
|
|
34
|
+
*/
|
|
35
|
+
function defaultCaps() {
|
|
36
|
+
return {
|
|
37
|
+
cursor: false,
|
|
38
|
+
input: false,
|
|
39
|
+
colorLevel: "truecolor",
|
|
40
|
+
colorForced: false,
|
|
41
|
+
colorProvenance: "auto",
|
|
42
|
+
unicode: true,
|
|
43
|
+
underlineStyles: [
|
|
44
|
+
"double",
|
|
45
|
+
"curly",
|
|
46
|
+
"dotted",
|
|
47
|
+
"dashed"
|
|
48
|
+
],
|
|
49
|
+
underlineColor: true,
|
|
50
|
+
overline: true,
|
|
51
|
+
textSizing: false,
|
|
52
|
+
kittyKeyboard: false,
|
|
53
|
+
bracketedPaste: true,
|
|
54
|
+
mouse: true,
|
|
55
|
+
kittyGraphics: false,
|
|
56
|
+
sixel: false,
|
|
57
|
+
osc52: false,
|
|
58
|
+
hyperlinks: false,
|
|
59
|
+
notifications: false,
|
|
60
|
+
syncOutput: false,
|
|
61
|
+
maybeDarkBackground: true,
|
|
62
|
+
maybeNerdFont: false,
|
|
63
|
+
maybeWideEmojis: true
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
var init_caps = __esmMin((() => {}));
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region packages/ansi/src/emulator.ts
|
|
69
|
+
/**
|
|
70
|
+
* Default emulator identity — unknown terminal, unversioned, no `TERM` set.
|
|
71
|
+
* Matches what a non-TTY Node process sees when run from CI without env vars.
|
|
72
|
+
*/
|
|
73
|
+
function defaultEmulator() {
|
|
74
|
+
return {
|
|
75
|
+
program: "",
|
|
76
|
+
version: "",
|
|
77
|
+
TERM: ""
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
var init_emulator = __esmMin((() => {}));
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region packages/ansi/src/theme/invariants.ts
|
|
83
|
+
/**
|
|
84
|
+
* Theme invariants — post-derivation visibility + optional WCAG checks.
|
|
85
|
+
*
|
|
86
|
+
* Two independent invariant groups:
|
|
87
|
+
*
|
|
88
|
+
* 1. **Visibility (always checked)** — selection and cursor must be
|
|
89
|
+
* distinguishable from bg. These fail silently because ensureContrast
|
|
90
|
+
* doesn't touch `bg-selected`/`bg-cursor`; you get "invisible selection"
|
|
91
|
+
* bugs that only surface via user complaints.
|
|
92
|
+
*
|
|
93
|
+
* 2. **WCAG contrast (opt-in)** — `deriveTheme()` already runs `ensureContrast`
|
|
94
|
+
* on every text/bg pair as it builds the Theme (lenient auto-adjust). A
|
|
95
|
+
* second validation pass is redundant for normal use. Enable it explicitly
|
|
96
|
+
* at build time to *verify* that shipped themes meet the targets, or when
|
|
97
|
+
* loading a hand-authored Theme object that skipped `deriveTheme`.
|
|
98
|
+
*
|
|
99
|
+
* This is why `validateThemeInvariants` defaults to `{ wcag: false }` — the
|
|
100
|
+
* existing derivation already handles contrast. Callers opt in via
|
|
101
|
+
* `validateThemeInvariants(theme, { wcag: true })` for strict pre-ship audits.
|
|
102
|
+
*
|
|
103
|
+
* All token access is Sterling-shaped — flat hyphen keys (`bg-accent`,
|
|
104
|
+
* `fg-on-error`, `border-focus`) exist on every Theme via the derive +
|
|
105
|
+
* bakeFlat pipeline. No concat-kebab legacy names (`primaryfg`, `mutedbg`, …)
|
|
106
|
+
* — those were removed in silvery 0.19.0 (Sterling interior migration).
|
|
107
|
+
*/
|
|
108
|
+
function lightness(hex) {
|
|
109
|
+
const o = hexToOklch(hex);
|
|
110
|
+
return o ? o.L : null;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Validate post-derivation invariants on a Theme.
|
|
114
|
+
*
|
|
115
|
+
* Default: visibility checks only (selection ΔL, cursor ΔE). These are
|
|
116
|
+
* invariants that `deriveTheme` doesn't enforce and that matter for every
|
|
117
|
+
* theme regardless of authoring pedigree.
|
|
118
|
+
*
|
|
119
|
+
* Opt into WCAG contrast checks via `{ wcag: true }`. Use at build-time to
|
|
120
|
+
* verify bundled themes, or when loading hand-authored Theme objects that
|
|
121
|
+
* didn't flow through `deriveTheme`'s `ensureContrast` pass.
|
|
122
|
+
*
|
|
123
|
+
* Non-hex values (ANSI names from `ansi16` mode) are skipped with no
|
|
124
|
+
* violation — ANSI 16 themes can't be contrast-checked in hex space.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* // Default — visibility only, fast
|
|
129
|
+
* const { ok, violations } = validateThemeInvariants(theme)
|
|
130
|
+
*
|
|
131
|
+
* // Build-time audit — full WCAG check
|
|
132
|
+
* const audit = validateThemeInvariants(theme, { wcag: true })
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
function validateThemeInvariants(theme, opts = {}) {
|
|
136
|
+
const checkWcag = opts.wcag ?? false;
|
|
137
|
+
const checkVisibility = opts.visibility ?? true;
|
|
138
|
+
const violations = [];
|
|
139
|
+
if (checkWcag) {
|
|
140
|
+
const themeRecord = theme;
|
|
141
|
+
for (const pair of CONTRAST_PAIRS) {
|
|
142
|
+
const fg = themeRecord[pair.fg];
|
|
143
|
+
const bg = themeRecord[pair.bg];
|
|
144
|
+
if (typeof fg !== "string" || typeof bg !== "string") continue;
|
|
145
|
+
const r = checkContrast(fg, bg);
|
|
146
|
+
if (r === null) continue;
|
|
147
|
+
if (r.ratio < pair.min) violations.push({
|
|
148
|
+
rule: pair.rule,
|
|
149
|
+
tokens: [pair.fg, pair.bg],
|
|
150
|
+
actual: r.ratio,
|
|
151
|
+
required: pair.min,
|
|
152
|
+
message: `${pair.fg} (${fg}) on ${pair.bg} (${bg}) is ${r.ratio.toFixed(2)}:1, needs ${pair.min.toFixed(1)}:1`
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (checkVisibility) {
|
|
157
|
+
const themeAny = theme;
|
|
158
|
+
const selectionBg = themeAny["bg-selected"] ?? "";
|
|
159
|
+
const cursorBg = themeAny["bg-cursor"] ?? themeAny["cursorbg"] ?? "";
|
|
160
|
+
const selectionKey = "bg-selected";
|
|
161
|
+
const cursorKey = themeAny["bg-cursor"] !== void 0 ? "bg-cursor" : "cursorbg";
|
|
162
|
+
const lBg = lightness(theme.bg);
|
|
163
|
+
const lSelBg = lightness(selectionBg);
|
|
164
|
+
if (lBg !== null && lSelBg !== null) {
|
|
165
|
+
const dL = Math.abs(lSelBg - lBg);
|
|
166
|
+
if (dL < .08) violations.push({
|
|
167
|
+
rule: "visibility:selection",
|
|
168
|
+
tokens: [selectionKey, "bg"],
|
|
169
|
+
actual: dL,
|
|
170
|
+
required: SELECTION_DELTA_L$1,
|
|
171
|
+
message: `${selectionKey} (${selectionBg}) differs from bg (${theme.bg}) by ΔL=${dL.toFixed(3)}, needs ≥ ${SELECTION_DELTA_L$1.toFixed(2)}`
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const oBg = hexToOklch(theme.bg);
|
|
175
|
+
const oCursorBg = hexToOklch(cursorBg);
|
|
176
|
+
if (oBg && oCursorBg) {
|
|
177
|
+
const de = deltaE(oBg, oCursorBg);
|
|
178
|
+
if (de < .15) violations.push({
|
|
179
|
+
rule: "visibility:cursor",
|
|
180
|
+
tokens: [cursorKey, "bg"],
|
|
181
|
+
actual: de,
|
|
182
|
+
required: CURSOR_DELTA_E$1,
|
|
183
|
+
message: `${cursorKey} (${cursorBg}) differs from bg (${theme.bg}) by ΔE=${de.toFixed(3)}, needs ≥ ${CURSOR_DELTA_E$1.toFixed(2)}`
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
ok: violations.length === 0,
|
|
189
|
+
violations
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Format violations as a multiline error message for throws/logs.
|
|
194
|
+
*/
|
|
195
|
+
function formatViolations(violations) {
|
|
196
|
+
if (violations.length === 0) return "";
|
|
197
|
+
return violations.map((v) => ` - [${v.rule}] ${v.message}`).join("\n");
|
|
198
|
+
}
|
|
199
|
+
var AA_RATIO, FAINT_RATIO, SELECTION_DELTA_L$1, CURSOR_DELTA_E$1, CONTRAST_PAIRS, ThemeInvariantError;
|
|
200
|
+
var init_invariants = __esmMin((() => {
|
|
201
|
+
AA_RATIO = 4.5;
|
|
202
|
+
FAINT_RATIO = 1.5;
|
|
203
|
+
SELECTION_DELTA_L$1 = .08;
|
|
204
|
+
CURSOR_DELTA_E$1 = .15;
|
|
205
|
+
CONTRAST_PAIRS = [
|
|
206
|
+
{
|
|
207
|
+
rule: "contrast:fg/bg",
|
|
208
|
+
fg: "fg",
|
|
209
|
+
bg: "bg",
|
|
210
|
+
min: AA_RATIO
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
rule: "contrast:fg/bg-surface-default",
|
|
214
|
+
fg: "fg",
|
|
215
|
+
bg: "bg-surface-default",
|
|
216
|
+
min: AA_RATIO
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
rule: "contrast:fg/bg-surface-subtle",
|
|
220
|
+
fg: "fg",
|
|
221
|
+
bg: "bg-surface-subtle",
|
|
222
|
+
min: AA_RATIO
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
rule: "contrast:fg/bg-surface-raised",
|
|
226
|
+
fg: "fg",
|
|
227
|
+
bg: "bg-surface-raised",
|
|
228
|
+
min: AA_RATIO
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
rule: "contrast:fg/bg-surface-hover",
|
|
232
|
+
fg: "fg",
|
|
233
|
+
bg: "bg-surface-hover",
|
|
234
|
+
min: AA_RATIO
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
rule: "contrast:fg/bg-surface-overlay",
|
|
238
|
+
fg: "fg",
|
|
239
|
+
bg: "bg-surface-overlay",
|
|
240
|
+
min: AA_RATIO
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
rule: "contrast:fg/bg-muted",
|
|
244
|
+
fg: "fg",
|
|
245
|
+
bg: "bg-muted",
|
|
246
|
+
min: AA_RATIO
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
rule: "contrast:fg-muted/bg",
|
|
250
|
+
fg: "fg-muted",
|
|
251
|
+
bg: "bg",
|
|
252
|
+
min: 3
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
rule: "contrast:fg-muted/bg-muted",
|
|
256
|
+
fg: "fg-muted",
|
|
257
|
+
bg: "bg-muted",
|
|
258
|
+
min: 3
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
rule: "contrast:fg-accent/bg",
|
|
262
|
+
fg: "fg-accent",
|
|
263
|
+
bg: "bg",
|
|
264
|
+
min: AA_RATIO
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
rule: "contrast:fg-error/bg",
|
|
268
|
+
fg: "fg-error",
|
|
269
|
+
bg: "bg",
|
|
270
|
+
min: AA_RATIO
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
rule: "contrast:fg-warning/bg",
|
|
274
|
+
fg: "fg-warning",
|
|
275
|
+
bg: "bg",
|
|
276
|
+
min: AA_RATIO
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
rule: "contrast:fg-success/bg",
|
|
280
|
+
fg: "fg-success",
|
|
281
|
+
bg: "bg",
|
|
282
|
+
min: AA_RATIO
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
rule: "contrast:fg-info/bg",
|
|
286
|
+
fg: "fg-info",
|
|
287
|
+
bg: "bg",
|
|
288
|
+
min: AA_RATIO
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
rule: "contrast:fg-on-accent/bg-accent",
|
|
292
|
+
fg: "fg-on-accent",
|
|
293
|
+
bg: "bg-accent",
|
|
294
|
+
min: AA_RATIO
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
rule: "contrast:fg-on-error/bg-error",
|
|
298
|
+
fg: "fg-on-error",
|
|
299
|
+
bg: "bg-error",
|
|
300
|
+
min: AA_RATIO
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
rule: "contrast:fg-on-warning/bg-warning",
|
|
304
|
+
fg: "fg-on-warning",
|
|
305
|
+
bg: "bg-warning",
|
|
306
|
+
min: AA_RATIO
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
rule: "contrast:fg-on-success/bg-success",
|
|
310
|
+
fg: "fg-on-success",
|
|
311
|
+
bg: "bg-success",
|
|
312
|
+
min: AA_RATIO
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
rule: "contrast:fg-on-info/bg-info",
|
|
316
|
+
fg: "fg-on-info",
|
|
317
|
+
bg: "bg-info",
|
|
318
|
+
min: AA_RATIO
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
rule: "contrast:fg-on-selected/bg-selected",
|
|
322
|
+
fg: "fg-on-selected",
|
|
323
|
+
bg: "bg-selected",
|
|
324
|
+
min: AA_RATIO
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
rule: "contrast:fg-cursor/bg-cursor",
|
|
328
|
+
fg: "fg-cursor",
|
|
329
|
+
bg: "bg-cursor",
|
|
330
|
+
min: AA_RATIO
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
rule: "contrast:border-default/bg",
|
|
334
|
+
fg: "border-default",
|
|
335
|
+
bg: "bg",
|
|
336
|
+
min: 3
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
rule: "contrast:border-focus/bg",
|
|
340
|
+
fg: "border-focus",
|
|
341
|
+
bg: "bg",
|
|
342
|
+
min: 3
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
rule: "contrast:border-muted/bg",
|
|
346
|
+
fg: "border-muted",
|
|
347
|
+
bg: "bg",
|
|
348
|
+
min: FAINT_RATIO
|
|
349
|
+
}
|
|
350
|
+
];
|
|
351
|
+
ThemeInvariantError = class extends Error {
|
|
352
|
+
violations;
|
|
353
|
+
constructor(violations) {
|
|
354
|
+
super(`Theme invariants failed (${violations.length} violation${violations.length === 1 ? "" : "s"}):\n${formatViolations(violations)}`);
|
|
355
|
+
this.name = "ThemeInvariantError";
|
|
356
|
+
this.violations = violations;
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
}));
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region packages/ansi/src/theme/derived.ts
|
|
362
|
+
/**
|
|
363
|
+
* deriveFields — single helper that fills all derived theme sections.
|
|
364
|
+
*
|
|
365
|
+
* Eliminates 4-way duplication of brand, categorical ring, state-variant, and
|
|
366
|
+
* variants population across:
|
|
367
|
+
* - derive.ts (deriveTruecolorTheme + deriveAnsi16Theme)
|
|
368
|
+
* - default-schemes.ts (ansi16DarkTheme + ansi16LightTheme)
|
|
369
|
+
* - @silvery/theme/generate.ts (generateTheme)
|
|
370
|
+
* - @silvery/theme/schemes/index.ts (ansi16DarkTheme + ansi16LightTheme)
|
|
371
|
+
*
|
|
372
|
+
* Canonical authority: derive.ts truecolor path. ANSI16 paths are aligned to
|
|
373
|
+
* deriveAnsi16Theme output (which is itself the canonical ANSI16 reference).
|
|
374
|
+
*/
|
|
375
|
+
/**
|
|
376
|
+
* Derive the shared "delta" fields common to every theme object:
|
|
377
|
+
* brand tokens, categorical ring, state variants, and typography variants.
|
|
378
|
+
*
|
|
379
|
+
* Pass a `shift` function for truecolor hover/active derivation (OKLCH
|
|
380
|
+
* brighten/darken). Omit `shift` for ANSI16 — hover/active fall back to the
|
|
381
|
+
* base color (no intermediate intensities available on 16-color terminals).
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* // Truecolor (dark theme)
|
|
385
|
+
* import { brighten, darken } from "@silvery/color"
|
|
386
|
+
* deriveFields({ shift: (hex, a) => brighten(hex, a), primary, ... })
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* // ANSI16 — no shift function
|
|
390
|
+
* deriveFields({ primary, accent, fg, selectionbg, surfacebg, ring })
|
|
391
|
+
*/
|
|
392
|
+
function deriveFields(input) {
|
|
393
|
+
const { dark, shift, primary, accent, fg, selectionbg, surfacebg, ring } = input;
|
|
394
|
+
const applyShift = dark !== void 0 ? (color, amount) => dark ? brighten(color, amount) : darken(color, amount) : shift ?? ((color, _amount) => color);
|
|
395
|
+
return {
|
|
396
|
+
brand: primary,
|
|
397
|
+
"brand-hover": applyShift(primary, .04),
|
|
398
|
+
"brand-active": applyShift(primary, .08),
|
|
399
|
+
...ring,
|
|
400
|
+
"primary-hover": applyShift(primary, .04),
|
|
401
|
+
"primary-active": applyShift(primary, .08),
|
|
402
|
+
"accent-hover": applyShift(accent, .04),
|
|
403
|
+
"accent-active": applyShift(accent, .08),
|
|
404
|
+
"fg-hover": applyShift(fg, .04),
|
|
405
|
+
"fg-active": applyShift(fg, .08),
|
|
406
|
+
"bg-selected-hover": applyShift(selectionbg, .04),
|
|
407
|
+
"bg-surface-hover": applyShift(surfacebg, .04),
|
|
408
|
+
variants: DEFAULT_VARIANTS$1
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
var DEFAULT_VARIANTS$1;
|
|
412
|
+
var init_derived = __esmMin((() => {
|
|
413
|
+
DEFAULT_VARIANTS$1 = {
|
|
414
|
+
h1: {
|
|
415
|
+
color: "$primary",
|
|
416
|
+
bold: true
|
|
417
|
+
},
|
|
418
|
+
h2: {
|
|
419
|
+
color: "$accent",
|
|
420
|
+
bold: true
|
|
421
|
+
},
|
|
422
|
+
h3: { bold: true },
|
|
423
|
+
body: {},
|
|
424
|
+
"body-muted": { color: "$muted" },
|
|
425
|
+
"fine-print": {
|
|
426
|
+
color: "$muted",
|
|
427
|
+
dim: true
|
|
428
|
+
},
|
|
429
|
+
strong: { bold: true },
|
|
430
|
+
em: { italic: true },
|
|
431
|
+
link: {
|
|
432
|
+
color: "$fg-link",
|
|
433
|
+
underlineStyle: "single"
|
|
434
|
+
},
|
|
435
|
+
key: {
|
|
436
|
+
color: "$accent",
|
|
437
|
+
bold: true
|
|
438
|
+
},
|
|
439
|
+
code: { backgroundColor: "$mutedbg" },
|
|
440
|
+
kbd: {
|
|
441
|
+
backgroundColor: "$mutedbg",
|
|
442
|
+
color: "$accent",
|
|
443
|
+
bold: true
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
}));
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region packages/ansi/src/sterling/contrast.ts
|
|
449
|
+
/**
|
|
450
|
+
* Sterling contrast guardrails — D3 from sterling-preflight.md.
|
|
451
|
+
*
|
|
452
|
+
* Two modes:
|
|
453
|
+
* - `strict` — throw when a core role pair fails WCAG AA 4.5:1.
|
|
454
|
+
* Used by the catalog test (all 84 shipped schemes must pass).
|
|
455
|
+
* - `auto-lift` — adjust OKLCH lightness until AA passes (±0.04L increments
|
|
456
|
+
* up to ~0.20L). Logs at debug; silent by default. Used for user schemes
|
|
457
|
+
* at runtime.
|
|
458
|
+
*
|
|
459
|
+
* Pinned tokens (per-role overrides supplied by scheme authors) are excluded
|
|
460
|
+
* from auto-lift and from strict-mode enforcement — the author accepts the
|
|
461
|
+
* contrast consequence of pinning.
|
|
462
|
+
*/
|
|
463
|
+
/**
|
|
464
|
+
* Verify `fg` on `bg` meets `target` ratio. Returns `null` when already
|
|
465
|
+
* passing; otherwise returns a ContrastViolation.
|
|
466
|
+
*/
|
|
467
|
+
function checkAA(token, fg, bg, target = WCAG_AA) {
|
|
468
|
+
const r = checkContrast(fg, bg);
|
|
469
|
+
if (!r) return null;
|
|
470
|
+
if (r.ratio >= target) return null;
|
|
471
|
+
return {
|
|
472
|
+
token,
|
|
473
|
+
fg,
|
|
474
|
+
bg,
|
|
475
|
+
ratio: r.ratio,
|
|
476
|
+
target
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Auto-lift `fg` against `bg` until the `target` contrast ratio is met,
|
|
481
|
+
* via OKLCH L shifts (hue + chroma preserved). Light bg → darken;
|
|
482
|
+
* dark bg → lighten.
|
|
483
|
+
*
|
|
484
|
+
* Implementation note: binary-searches the minimum L shift achieving the
|
|
485
|
+
* target. Falls back to a best-effort value if the target is unreachable
|
|
486
|
+
* (e.g., yellow against white can never hit 4.5:1 at any lightness while
|
|
487
|
+
* preserving yellow hue; the result is the darkest in-gamut yellow).
|
|
488
|
+
*/
|
|
489
|
+
function autoLift(fg, bg, target = WCAG_AA) {
|
|
490
|
+
const current = checkContrast(fg, bg);
|
|
491
|
+
if (!current) return {
|
|
492
|
+
value: fg,
|
|
493
|
+
lifted: false
|
|
494
|
+
};
|
|
495
|
+
if (current.ratio >= target) return {
|
|
496
|
+
value: fg,
|
|
497
|
+
lifted: false
|
|
498
|
+
};
|
|
499
|
+
const adjusted = ensureContrast(fg, bg, target);
|
|
500
|
+
return {
|
|
501
|
+
value: adjusted,
|
|
502
|
+
lifted: adjusted !== fg
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
var WCAG_AA, ContrastError;
|
|
506
|
+
var init_contrast = __esmMin((() => {
|
|
507
|
+
WCAG_AA = 4.5;
|
|
508
|
+
ContrastError = class extends Error {
|
|
509
|
+
violations;
|
|
510
|
+
constructor(violations) {
|
|
511
|
+
const summary = violations.slice(0, 5).map((v) => `${v.token}: ${v.ratio.toFixed(2)} < ${v.target} (fg=${v.fg}, bg=${v.bg})`).join("; ");
|
|
512
|
+
const extra = violations.length > 5 ? ` (+${violations.length - 5} more)` : "";
|
|
513
|
+
super(`Sterling contrast: ${violations.length} violation(s): ${summary}${extra}`);
|
|
514
|
+
this.name = "ContrastError";
|
|
515
|
+
this.violations = violations;
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
}));
|
|
519
|
+
//#endregion
|
|
520
|
+
//#region packages/ansi/src/sterling/derive.ts
|
|
521
|
+
/**
|
|
522
|
+
* Sterling derivation — preservative OKLCH rules over a 22-color ColorScheme.
|
|
523
|
+
*
|
|
524
|
+
* Implements design-system.md §"Derivation rules" with guardrails from D3.
|
|
525
|
+
* Produces the nested `Roles` shape. `flatten.ts` projects the flat keys.
|
|
526
|
+
*
|
|
527
|
+
* Derivation is:
|
|
528
|
+
* 1. `scheme.primary` (or fallback) → accent.fg / accent.bg / info.fg
|
|
529
|
+
* 2. status roles from `scheme.red / yellow / green / primary`
|
|
530
|
+
* 3. Adaptive OKLCH hover/active L-shift (direction = base-L, not scheme.dark):
|
|
531
|
+
* baseL > 0.6 → darken (hover −0.04L, active −0.08L)
|
|
532
|
+
* baseL ≤ 0.6 → brighten (hover +0.04L, active +0.08L)
|
|
533
|
+
* At L extremes (target L > 0.9 or < 0.1) chroma is proportionally
|
|
534
|
+
* reduced so the color pushes toward gray instead of collapsing to
|
|
535
|
+
* white/black — fixes the Frappe yellow/light-accent whiteout.
|
|
536
|
+
* 4. `fgOn` picked for WCAG AA against role's `bg` (prefers scheme bg/fg)
|
|
537
|
+
* 5. surface ramp via OKLCH blend
|
|
538
|
+
* 6. contrast guardrail: strict throws, auto-lift adjusts
|
|
539
|
+
*
|
|
540
|
+
* Per-hue delta adaptation: yellows (H ∈ [80, 110]) get ±0.06L / ±0.10L,
|
|
541
|
+
* low-chroma schemes (C < 0.05) get ±0.06L / ±0.10L. Everything else uses
|
|
542
|
+
* the standard ±0.04L / ±0.08L.
|
|
543
|
+
*
|
|
544
|
+
* Pinned tokens (via `DeriveOptions.pins`) bypass both the rule and
|
|
545
|
+
* auto-lift; they're written verbatim onto the Theme.
|
|
546
|
+
*/
|
|
547
|
+
/**
|
|
548
|
+
* Build the 16-slot ANSI palette from a ColorScheme. Indexed `$color0` …
|
|
549
|
+
* `$color15` by the framework's token resolver.
|
|
550
|
+
*/
|
|
551
|
+
function buildPalette(scheme) {
|
|
552
|
+
return [
|
|
553
|
+
scheme.black,
|
|
554
|
+
scheme.red,
|
|
555
|
+
scheme.green,
|
|
556
|
+
scheme.yellow,
|
|
557
|
+
scheme.blue,
|
|
558
|
+
scheme.magenta,
|
|
559
|
+
scheme.cyan,
|
|
560
|
+
scheme.white,
|
|
561
|
+
scheme.brightBlack,
|
|
562
|
+
scheme.brightRed,
|
|
563
|
+
scheme.brightGreen,
|
|
564
|
+
scheme.brightYellow,
|
|
565
|
+
scheme.brightBlue,
|
|
566
|
+
scheme.brightMagenta,
|
|
567
|
+
scheme.brightCyan,
|
|
568
|
+
scheme.brightWhite
|
|
569
|
+
];
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Derive the 8-hue categorical ring from a ColorScheme. Mirrors the legacy
|
|
573
|
+
* derive.ts logic — blends scheme hues for the missing Sterling slots
|
|
574
|
+
* (orange from red+yellow, teal from green+cyan, pink from magenta+red).
|
|
575
|
+
*/
|
|
576
|
+
function buildCategoricalHues(scheme) {
|
|
577
|
+
const dark = scheme.dark ?? true;
|
|
578
|
+
return {
|
|
579
|
+
red: scheme.red,
|
|
580
|
+
orange: blend(scheme.red, scheme.yellow, .5),
|
|
581
|
+
yellow: scheme.yellow,
|
|
582
|
+
green: scheme.green,
|
|
583
|
+
teal: blend(scheme.green, scheme.cyan, .5),
|
|
584
|
+
blue: dark ? scheme.brightBlue : scheme.blue,
|
|
585
|
+
purple: scheme.magenta,
|
|
586
|
+
pink: blend(scheme.magenta, scheme.red, .5)
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
function isYellowish(hex) {
|
|
590
|
+
const o = hexToOklch(hex);
|
|
591
|
+
if (!o) return false;
|
|
592
|
+
return o.H >= 80 && o.H <= 120;
|
|
593
|
+
}
|
|
594
|
+
function isLowChroma(hex) {
|
|
595
|
+
const o = hexToOklch(hex);
|
|
596
|
+
if (!o) return false;
|
|
597
|
+
return o.C < .05;
|
|
598
|
+
}
|
|
599
|
+
/** Compute state-shift deltas for a given base color. Wider for yellows + low-chroma. */
|
|
600
|
+
function stateDeltas(base) {
|
|
601
|
+
if (isYellowish(base) || isLowChroma(base)) return {
|
|
602
|
+
hover: .06,
|
|
603
|
+
active: .1
|
|
604
|
+
};
|
|
605
|
+
return {
|
|
606
|
+
hover: .04,
|
|
607
|
+
active: .08
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Adaptive L-shift: direction follows the token's own luminance, NOT
|
|
612
|
+
* scheme.dark. High-L tokens (yellows, light accents) darken; low-L tokens
|
|
613
|
+
* brighten. Uniform handling — yields a reliable "more active than hover"
|
|
614
|
+
* relationship no matter what hue/lightness the base is.
|
|
615
|
+
*
|
|
616
|
+
* Chroma preservation at L extremes: when the target L pushes past 0.9
|
|
617
|
+
* (approaching white) or below 0.1 (approaching black), chroma is scaled
|
|
618
|
+
* down proportionally so the color drifts toward gray rather than
|
|
619
|
+
* collapsing to #FFFFFF or #000000. This preserves perceptual differences
|
|
620
|
+
* between the base / hover / active states even on intrinsically-bright
|
|
621
|
+
* tokens (catppuccin-frappe yellow, light blue accents, etc.).
|
|
622
|
+
*
|
|
623
|
+
* Returns the original hex unchanged when OKLCH parsing fails.
|
|
624
|
+
*/
|
|
625
|
+
function shiftL(hex, amount) {
|
|
626
|
+
const o = hexToOklch(hex);
|
|
627
|
+
if (!o) return hex;
|
|
628
|
+
const direction = o.L > .6 ? -1 : 1;
|
|
629
|
+
const targetL = clamp01(o.L + direction * amount);
|
|
630
|
+
let nextC = o.C;
|
|
631
|
+
if (targetL > .9 || targetL < .1) {
|
|
632
|
+
const factor = clamp01(1 - Math.abs(targetL - .5) * 2);
|
|
633
|
+
nextC = o.C * factor;
|
|
634
|
+
}
|
|
635
|
+
return oklchToHex({
|
|
636
|
+
L: targetL,
|
|
637
|
+
C: nextC,
|
|
638
|
+
H: o.H
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
function clamp01(x) {
|
|
642
|
+
return x < 0 ? 0 : x > 1 ? 1 : x;
|
|
643
|
+
}
|
|
644
|
+
/** Label the direction the adaptive L-shift took, for trace rule strings. */
|
|
645
|
+
function shiftLabel(hex) {
|
|
646
|
+
const o = hexToOklch(hex);
|
|
647
|
+
if (!o) return "brighten";
|
|
648
|
+
return o.L > .6 ? "darken" : "brighten";
|
|
649
|
+
}
|
|
650
|
+
function inferMode(scheme, explicit) {
|
|
651
|
+
if (explicit) return explicit;
|
|
652
|
+
if (typeof scheme.dark === "boolean") return scheme.dark ? "dark" : "light";
|
|
653
|
+
const lum = relativeLuminance(scheme.background);
|
|
654
|
+
return lum !== null && lum < .5 ? "dark" : "light";
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Pick a foreground color to draw on a filled `bg` of a role. Prefers
|
|
658
|
+
* `scheme.background` if it beats AA against the role bg (i.e. the role bg
|
|
659
|
+
* is bright enough that using dark text reads); otherwise `scheme.foreground`;
|
|
660
|
+
* otherwise falls back to white/black by bg luminance.
|
|
661
|
+
*/
|
|
662
|
+
function pickFgOn(roleBg, scheme) {
|
|
663
|
+
const candidates = [
|
|
664
|
+
scheme.foreground,
|
|
665
|
+
scheme.background,
|
|
666
|
+
"#FFFFFF",
|
|
667
|
+
"#000000"
|
|
668
|
+
];
|
|
669
|
+
let best = candidates[0];
|
|
670
|
+
let bestRatio = 0;
|
|
671
|
+
for (const c of candidates) {
|
|
672
|
+
const r = checkAA("fgOn", c, roleBg);
|
|
673
|
+
if (r === null) return c;
|
|
674
|
+
if (r.ratio > bestRatio) {
|
|
675
|
+
best = c;
|
|
676
|
+
bestRatio = r.ratio;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return best;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Resolve a pin for a token path. Accepts both nested (`"accent.hover.bg"`)
|
|
683
|
+
* and flat (`"bg-accent-hover"`) forms. Returns the pinned hex or undefined.
|
|
684
|
+
*/
|
|
685
|
+
function pin(pins, nested, flat) {
|
|
686
|
+
if (!pins) return void 0;
|
|
687
|
+
return pins[nested] ?? pins[flat];
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Shared guard: handles pin → rule → contrast check → auto-lift → record.
|
|
691
|
+
* `target` defaults to WCAG_AA (4.5); callers use 3.0 for "muted" tokens
|
|
692
|
+
* that are deemphasized by design.
|
|
693
|
+
*/
|
|
694
|
+
function guardTarget(nestedPath, flatPath, rule, inputs, value, against, target, contrast, pins, trace, violations) {
|
|
695
|
+
const pinned = pin(pins, nestedPath, flatPath);
|
|
696
|
+
if (pinned !== void 0) {
|
|
697
|
+
trace.push({
|
|
698
|
+
token: nestedPath,
|
|
699
|
+
rule: "pinned by scheme author",
|
|
700
|
+
inputs: [pinned],
|
|
701
|
+
output: pinned,
|
|
702
|
+
pinned: true
|
|
703
|
+
});
|
|
704
|
+
return pinned;
|
|
705
|
+
}
|
|
706
|
+
if (against === void 0) {
|
|
707
|
+
trace.push({
|
|
708
|
+
token: nestedPath,
|
|
709
|
+
rule,
|
|
710
|
+
inputs,
|
|
711
|
+
output: value
|
|
712
|
+
});
|
|
713
|
+
return value;
|
|
714
|
+
}
|
|
715
|
+
if (checkAA(nestedPath, value, against, target) === null) {
|
|
716
|
+
trace.push({
|
|
717
|
+
token: nestedPath,
|
|
718
|
+
rule,
|
|
719
|
+
inputs,
|
|
720
|
+
output: value
|
|
721
|
+
});
|
|
722
|
+
return value;
|
|
723
|
+
}
|
|
724
|
+
const lifted = autoLift(value, against, target);
|
|
725
|
+
const finalValue = lifted.value;
|
|
726
|
+
const residual = checkAA(nestedPath, finalValue, against, target);
|
|
727
|
+
if (residual !== null) violations.push(residual);
|
|
728
|
+
trace.push({
|
|
729
|
+
token: nestedPath,
|
|
730
|
+
rule: lifted.lifted ? `${rule} + auto-lift` : rule,
|
|
731
|
+
inputs,
|
|
732
|
+
output: finalValue,
|
|
733
|
+
...lifted.lifted ? { liftedFrom: value } : {}
|
|
734
|
+
});
|
|
735
|
+
return finalValue;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Derive a Theme's nested roles from a ColorScheme. Guardrails applied.
|
|
739
|
+
*/
|
|
740
|
+
function deriveRoles(scheme, opts) {
|
|
741
|
+
const mode = inferMode(scheme, opts.mode);
|
|
742
|
+
const contrast = opts.contrast ?? "auto-lift";
|
|
743
|
+
const pins = opts.pins;
|
|
744
|
+
const trace = [];
|
|
745
|
+
const violations = [];
|
|
746
|
+
const primary = scheme.primary ?? (mode === "dark" ? scheme.brightBlue : scheme.blue);
|
|
747
|
+
const bg = scheme.background;
|
|
748
|
+
const fg = scheme.foreground;
|
|
749
|
+
function guard(nestedPath, flatPath, rule, inputs, value, against, target = WCAG_AA) {
|
|
750
|
+
return guardTarget(nestedPath, flatPath, rule, inputs, value, against, target, contrast, pins, trace, violations);
|
|
751
|
+
}
|
|
752
|
+
const accentBase = guard("accent.fg", "fg-accent", "scheme.primary", [primary], primary, bg);
|
|
753
|
+
const accentBg = guard("accent.bg", "bg-accent", "scheme.primary", [primary], primary);
|
|
754
|
+
const deltaA = stateDeltas(accentBg);
|
|
755
|
+
const bgDir = shiftLabel(accentBg);
|
|
756
|
+
const accentHoverBg = guard("accent.hover.bg", "bg-accent-hover", `OKLCH ${bgDir} ${deltaA.hover}L on accent.bg`, [accentBg], shiftL(accentBg, deltaA.hover));
|
|
757
|
+
const accentActiveBg = guard("accent.active.bg", "bg-accent-active", `OKLCH ${bgDir} ${deltaA.active}L on accent.bg`, [accentBg], shiftL(accentBg, deltaA.active));
|
|
758
|
+
const accentFgOn = guard("accent.fgOn", "fg-on-accent", "contrast-pick(scheme.fg/bg/BW)", [accentBg], pickFgOn(accentBg, scheme), accentBg);
|
|
759
|
+
const accentBorder = guard("accent.border", "border-accent", "= accent.bg", [accentBg], accentBg);
|
|
760
|
+
const fgDir = shiftLabel(accentBase);
|
|
761
|
+
const accentHoverFg = guard("accent.hover.fg", "fg-accent-hover", `OKLCH ${fgDir} ${deltaA.hover}L on accent.fg`, [accentBase], shiftL(accentBase, deltaA.hover), bg);
|
|
762
|
+
const accentActiveFg = guard("accent.active.fg", "fg-accent-active", `OKLCH ${fgDir} ${deltaA.active}L on accent.fg`, [accentBase], shiftL(accentBase, deltaA.active), bg);
|
|
763
|
+
const accent = {
|
|
764
|
+
fg: accentBase,
|
|
765
|
+
bg: accentBg,
|
|
766
|
+
fgOn: accentFgOn,
|
|
767
|
+
border: accentBorder,
|
|
768
|
+
hover: {
|
|
769
|
+
fg: accentHoverFg,
|
|
770
|
+
bg: accentHoverBg
|
|
771
|
+
},
|
|
772
|
+
active: {
|
|
773
|
+
fg: accentActiveFg,
|
|
774
|
+
bg: accentActiveBg
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
const info = buildInteractive("info", primary, scheme, opts, trace, violations);
|
|
778
|
+
const success = buildInteractive("success", scheme.green, scheme, opts, trace, violations);
|
|
779
|
+
const warning = buildInteractive("warning", scheme.yellow, scheme, opts, trace, violations);
|
|
780
|
+
const error = buildInteractive("error", scheme.red, scheme, opts, trace, violations);
|
|
781
|
+
const mutedBg = guard("muted.bg", "bg-muted", "blend(bg, fg, 0.08)", [bg, fg], blend(bg, fg, .08));
|
|
782
|
+
const muted = {
|
|
783
|
+
fg: guard("muted.fg", "fg-muted", "blend(fg, bg, 0.4)", [fg, bg], blend(fg, bg, .4), mutedBg, 3),
|
|
784
|
+
bg: mutedBg
|
|
785
|
+
};
|
|
786
|
+
const fgForSurfaceLift = ensureContrast(fg, blend(bg, fg, .08), WCAG_AA);
|
|
787
|
+
const surfaceDefault = guard("surface.default", "bg-surface-default", "scheme.background", [bg], bg);
|
|
788
|
+
const surface = {
|
|
789
|
+
default: surfaceDefault,
|
|
790
|
+
subtle: guard("surface.subtle", "bg-surface-subtle", "blend(bg, fg, 0.03)", [bg, fg], blend(bg, fg, .03), fgForSurfaceLift, WCAG_AA),
|
|
791
|
+
raised: guard("surface.raised", "bg-surface-raised", "blend(bg, fg, 0.10)", [bg, fg], blend(bg, fg, .1), fgForSurfaceLift, WCAG_AA),
|
|
792
|
+
overlay: guard("surface.overlay", "bg-surface-overlay", "blend(bg, fg, 0.12)", [bg, fg], blend(bg, fg, .12), fgForSurfaceLift, WCAG_AA),
|
|
793
|
+
hover: guard("surface.hover", "bg-surface-hover", "blend(bg, fg, 0.10)", [bg, fg], blend(bg, fg, .1), fgForSurfaceLift, WCAG_AA)
|
|
794
|
+
};
|
|
795
|
+
const borderDefault = guard("border.default", "border-default", "blend(bg, fg, 0.18)", [bg, fg], blend(bg, fg, .18), bg, 3);
|
|
796
|
+
const border = {
|
|
797
|
+
default: borderDefault,
|
|
798
|
+
focus: guard("border.focus", "border-focus", "= accent.bg", [accentBg], accentBg, bg),
|
|
799
|
+
muted: guard("border.muted", "border-muted", "blend(bg, fg, 0.10)", [bg, fg], blend(bg, fg, .1), bg, 1.5)
|
|
800
|
+
};
|
|
801
|
+
const cursorBgRaw = guard("cursor.bg", "bg-cursor", "scheme.cursorColor (visibility-repaired ΔE ≥ 0.15 vs bg)", [scheme.cursorColor, bg], repairCursorBg$1(scheme.cursorColor, bg));
|
|
802
|
+
const cursor = {
|
|
803
|
+
fg: guard("cursor.fg", "fg-cursor", "scheme.cursorText", [scheme.cursorText], scheme.cursorText, cursorBgRaw),
|
|
804
|
+
bg: cursorBgRaw
|
|
805
|
+
};
|
|
806
|
+
const selectedBg = guard("selected.bg", "bg-selected", "scheme.selectionBackground (visibility-repaired ΔL ≥ 0.08 vs bg)", [scheme.selectionBackground, bg], repairSelectionBg$1(scheme.selectionBackground, bg));
|
|
807
|
+
const selectedFgOn = guard("selected.fgOn", "fg-on-selected", "scheme.selectionForeground", [scheme.selectionForeground], scheme.selectionForeground, selectedBg);
|
|
808
|
+
const selectedDeltaH = stateDeltas(selectedBg);
|
|
809
|
+
const selected = {
|
|
810
|
+
bg: selectedBg,
|
|
811
|
+
fgOn: selectedFgOn,
|
|
812
|
+
hover: { bg: guard("selected.hover.bg", "bg-selected-hover", `OKLCH ${shiftLabel(selectedBg)} ${selectedDeltaH.hover}L on selected.bg`, [selectedBg], shiftL(selectedBg, selectedDeltaH.hover)) }
|
|
813
|
+
};
|
|
814
|
+
const inverseBg = guard("inverse.bg", "bg-inverse", "blend(fg, bg, 0.1)", [fg, bg], blend(fg, bg, .1));
|
|
815
|
+
const inverse = {
|
|
816
|
+
bg: inverseBg,
|
|
817
|
+
fgOn: guard("inverse.fgOn", "fg-on-inverse", "contrast-pick(scheme.fg/bg/BW)", [inverseBg], pickFgOn(inverseBg, scheme), inverseBg)
|
|
818
|
+
};
|
|
819
|
+
const link = { fg: guard("link.fg", "fg-link", mode === "dark" ? "scheme.brightBlue" : "scheme.blue", [mode === "dark" ? scheme.brightBlue : scheme.blue], mode === "dark" ? scheme.brightBlue : scheme.blue, bg) };
|
|
820
|
+
const fgDisabledRaw = blend(surfaceDefault, fg, .38);
|
|
821
|
+
const fgDisabled = guard("disabled.fg", "fg-disabled", "composite(fg @ 0.38, surface.default), ≥3:1", [fg, surfaceDefault], fgDisabledRaw, surfaceDefault, 3);
|
|
822
|
+
const borderDisabled = guard("disabled.border", "border-disabled", "composite(border-default @ 0.24, surface.default)", [borderDefault, surfaceDefault], blend(surfaceDefault, borderDefault, .24));
|
|
823
|
+
return {
|
|
824
|
+
roles: {
|
|
825
|
+
accent,
|
|
826
|
+
info,
|
|
827
|
+
success,
|
|
828
|
+
warning,
|
|
829
|
+
error,
|
|
830
|
+
muted,
|
|
831
|
+
surface,
|
|
832
|
+
border,
|
|
833
|
+
cursor,
|
|
834
|
+
selected,
|
|
835
|
+
inverse,
|
|
836
|
+
link,
|
|
837
|
+
disabled: {
|
|
838
|
+
fg: fgDisabled,
|
|
839
|
+
bg: guard("disabled.bg", "bg-disabled", "composite(border-default @ 0.12, surface.default)", [borderDefault, surfaceDefault], blend(surfaceDefault, borderDefault, .12)),
|
|
840
|
+
border: borderDisabled
|
|
841
|
+
}
|
|
842
|
+
},
|
|
843
|
+
mode,
|
|
844
|
+
trace,
|
|
845
|
+
violations
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Nudge selectionBg's OKLCH L until it differs from bg by ≥ SELECTION_DELTA_L.
|
|
850
|
+
* Mirrors the legacy theme's repairSelectionBg behavior — preserves hue +
|
|
851
|
+
* chroma but guarantees the highlight reads against any background. Non-hex
|
|
852
|
+
* input returns unchanged.
|
|
853
|
+
*/
|
|
854
|
+
function repairSelectionBg$1(selectionBg, bg) {
|
|
855
|
+
const oSel = hexToOklch(selectionBg);
|
|
856
|
+
const oBg = hexToOklch(bg);
|
|
857
|
+
if (!oSel || !oBg) return selectionBg;
|
|
858
|
+
const dL = Math.abs(oSel.L - oBg.L);
|
|
859
|
+
if (dL >= SELECTION_DELTA_L) return selectionBg;
|
|
860
|
+
const needed = SELECTION_DELTA_L - dL + .005;
|
|
861
|
+
const direction = oSel.L >= oBg.L ? 1 : -1;
|
|
862
|
+
return oklchToHex({
|
|
863
|
+
L: clamp01(oSel.L + direction * needed),
|
|
864
|
+
C: oSel.C,
|
|
865
|
+
H: oSel.H
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Nudge cursorBg's OKLCH L until it differs from bg by ≥ CURSOR_DELTA_E
|
|
870
|
+
* (perceptual distance, not just lightness). Preserves hue + chroma but
|
|
871
|
+
* guarantees the cursor reads against the surrounding bg.
|
|
872
|
+
*
|
|
873
|
+
* Uses ΔE (OKLCH perceptual distance) rather than ΔL because two colors at
|
|
874
|
+
* the same lightness but different hue/chroma are still visibly distinct —
|
|
875
|
+
* a yellow cursor on a blue bg of equal L is perfectly visible. Only when
|
|
876
|
+
* ΔE falls below the visibility floor do we lift L to compensate.
|
|
877
|
+
*
|
|
878
|
+
* Mirrors `repairSelectionBg` in shape; the repair primitive is L because
|
|
879
|
+
* shifting hue or chroma would change the author-intended cursor color
|
|
880
|
+
* identity. L is the "size" knob — bigger ΔL → more visible without
|
|
881
|
+
* recoloring.
|
|
882
|
+
*
|
|
883
|
+
* Non-hex input returns unchanged.
|
|
884
|
+
*/
|
|
885
|
+
function repairCursorBg$1(cursorBg, bg) {
|
|
886
|
+
const oCur = hexToOklch(cursorBg);
|
|
887
|
+
const oBg = hexToOklch(bg);
|
|
888
|
+
if (!oCur || !oBg) return cursorBg;
|
|
889
|
+
if (deltaE(oCur, oBg) >= CURSOR_DELTA_E) return cursorBg;
|
|
890
|
+
const direction = oCur.L >= oBg.L ? 1 : -1;
|
|
891
|
+
const TARGET = CURSOR_DELTA_E + .005;
|
|
892
|
+
let lo = 0;
|
|
893
|
+
let hi = direction > 0 ? 1 - oCur.L : oCur.L;
|
|
894
|
+
for (let i = 0; i < 24; i++) {
|
|
895
|
+
const mid = (lo + hi) / 2;
|
|
896
|
+
if (deltaE({
|
|
897
|
+
L: clamp01(oCur.L + direction * mid),
|
|
898
|
+
C: oCur.C,
|
|
899
|
+
H: oCur.H
|
|
900
|
+
}, oBg) >= TARGET) hi = mid;
|
|
901
|
+
else lo = mid;
|
|
902
|
+
}
|
|
903
|
+
return oklchToHex({
|
|
904
|
+
L: clamp01(oCur.L + direction * hi),
|
|
905
|
+
C: oCur.C,
|
|
906
|
+
H: oCur.H
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
function buildInteractive(name, seed, scheme, opts, trace, violations) {
|
|
910
|
+
const pins = opts.pins;
|
|
911
|
+
const contrast = opts.contrast ?? "auto-lift";
|
|
912
|
+
const bg = scheme.background;
|
|
913
|
+
const guard = (nestedPath, flatPath, rule, inputs, value, against, target = WCAG_AA) => guardTarget(nestedPath, flatPath, rule, inputs, value, against, target, contrast, pins, trace, violations);
|
|
914
|
+
const fg = guard(`${name}.fg`, `fg-${name}`, seedRule$1(name), [seed], seed, bg);
|
|
915
|
+
const roleBg = guard(`${name}.bg`, `bg-${name}`, seedRule$1(name), [seed], seed);
|
|
916
|
+
const delta = stateDeltas(roleBg);
|
|
917
|
+
const bgDir = shiftLabel(roleBg);
|
|
918
|
+
const fgOn = guard(`${name}.fgOn`, `fg-on-${name}`, "contrast-pick(scheme.fg/bg/BW)", [roleBg], pickFgOn(roleBg, scheme), roleBg);
|
|
919
|
+
const hoverBg = guard(`${name}.hover.bg`, `bg-${name}-hover`, `OKLCH ${bgDir} ${delta.hover}L`, [roleBg], shiftL(roleBg, delta.hover));
|
|
920
|
+
const activeBg = guard(`${name}.active.bg`, `bg-${name}-active`, `OKLCH ${bgDir} ${delta.active}L`, [roleBg], shiftL(roleBg, delta.active));
|
|
921
|
+
return {
|
|
922
|
+
fg,
|
|
923
|
+
bg: roleBg,
|
|
924
|
+
fgOn,
|
|
925
|
+
hover: { bg: hoverBg },
|
|
926
|
+
active: { bg: activeBg }
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
function seedRule$1(name) {
|
|
930
|
+
switch (name) {
|
|
931
|
+
case "info": return "scheme.primary (info mirrors accent's seed, derived independently)";
|
|
932
|
+
case "success": return "scheme.green";
|
|
933
|
+
case "warning": return "scheme.yellow";
|
|
934
|
+
case "error": return "scheme.red";
|
|
935
|
+
case "accent": return "scheme.primary";
|
|
936
|
+
default: return `scheme.${name}`;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Derive a full Theme (pre-flatten) from a ColorScheme. Throws `ContrastError`
|
|
941
|
+
* in strict mode if any role pair fails WCAG AA. Callers typically wrap this
|
|
942
|
+
* with `flatten()` (from `flatten.ts`) to get the user-facing Theme.
|
|
943
|
+
*
|
|
944
|
+
* Returned Theme is NOT frozen and DOES NOT contain flat keys yet.
|
|
945
|
+
*/
|
|
946
|
+
function deriveTheme$1(scheme, opts = {}) {
|
|
947
|
+
const { roles, mode, trace, violations } = deriveRoles(scheme, opts);
|
|
948
|
+
if ((opts.contrast ?? "auto-lift") === "strict" && violations.length > 0) throw new ContrastError(violations);
|
|
949
|
+
return {
|
|
950
|
+
...roles,
|
|
951
|
+
...buildCategoricalHues(scheme),
|
|
952
|
+
name: scheme.name,
|
|
953
|
+
mode,
|
|
954
|
+
variants: DEFAULT_VARIANTS,
|
|
955
|
+
palette: buildPalette(scheme),
|
|
956
|
+
...opts.trace ? { derivationTrace: trace } : {}
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Merge a DeepPartial<Theme> onto an existing Theme (for `sterling.theme()`).
|
|
961
|
+
* Nested role objects are spread deeply; flat keys are replaced if present.
|
|
962
|
+
*/
|
|
963
|
+
function mergePartial(base, patch) {
|
|
964
|
+
if (!patch) return base;
|
|
965
|
+
const out = { ...base };
|
|
966
|
+
for (const [k, v] of Object.entries(patch)) {
|
|
967
|
+
if (v === void 0) continue;
|
|
968
|
+
const cur = base[k];
|
|
969
|
+
if (cur && typeof cur === "object" && typeof v === "object" && !Array.isArray(v)) {
|
|
970
|
+
out[k] = {
|
|
971
|
+
...cur,
|
|
972
|
+
...v
|
|
973
|
+
};
|
|
974
|
+
for (const [k2, v2] of Object.entries(v)) if (v2 && typeof v2 === "object" && !Array.isArray(v2) && cur[k2] && typeof cur[k2] === "object") out[k][k2] = {
|
|
975
|
+
...cur[k2],
|
|
976
|
+
...v2
|
|
977
|
+
};
|
|
978
|
+
} else out[k] = v;
|
|
979
|
+
}
|
|
980
|
+
return out;
|
|
981
|
+
}
|
|
982
|
+
var DEFAULT_VARIANTS, SELECTION_DELTA_L, CURSOR_DELTA_E;
|
|
983
|
+
var init_derive$1 = __esmMin((() => {
|
|
984
|
+
init_contrast();
|
|
985
|
+
DEFAULT_VARIANTS = {
|
|
986
|
+
h1: {
|
|
987
|
+
color: "$fg-accent",
|
|
988
|
+
bold: true
|
|
989
|
+
},
|
|
990
|
+
h2: {
|
|
991
|
+
color: "$fg-accent",
|
|
992
|
+
bold: true
|
|
993
|
+
},
|
|
994
|
+
h3: { bold: true },
|
|
995
|
+
h4: {
|
|
996
|
+
color: "$fg-muted",
|
|
997
|
+
bold: true
|
|
998
|
+
},
|
|
999
|
+
h5: {
|
|
1000
|
+
color: "$fg-muted",
|
|
1001
|
+
italic: true
|
|
1002
|
+
},
|
|
1003
|
+
h6: {
|
|
1004
|
+
color: "$fg-muted",
|
|
1005
|
+
dim: true
|
|
1006
|
+
},
|
|
1007
|
+
body: {},
|
|
1008
|
+
"body-muted": { color: "$fg-muted" },
|
|
1009
|
+
"fine-print": {
|
|
1010
|
+
color: "$fg-muted",
|
|
1011
|
+
dim: true
|
|
1012
|
+
},
|
|
1013
|
+
strong: { bold: true },
|
|
1014
|
+
em: { italic: true },
|
|
1015
|
+
link: {
|
|
1016
|
+
color: "$fg-accent",
|
|
1017
|
+
underlineStyle: "single"
|
|
1018
|
+
},
|
|
1019
|
+
key: {
|
|
1020
|
+
color: "$fg-accent",
|
|
1021
|
+
bold: true
|
|
1022
|
+
},
|
|
1023
|
+
code: { backgroundColor: "$bg-muted" },
|
|
1024
|
+
kbd: {
|
|
1025
|
+
backgroundColor: "$bg-muted",
|
|
1026
|
+
color: "$fg-accent",
|
|
1027
|
+
bold: true
|
|
1028
|
+
}
|
|
1029
|
+
};
|
|
1030
|
+
SELECTION_DELTA_L = .08;
|
|
1031
|
+
CURSOR_DELTA_E = .15;
|
|
1032
|
+
}));
|
|
1033
|
+
//#endregion
|
|
1034
|
+
//#region packages/ansi/src/sterling/inline.ts
|
|
1035
|
+
/**
|
|
1036
|
+
* Sterling flat-token inlining — merges Sterling flat tokens onto a Theme.
|
|
1037
|
+
*
|
|
1038
|
+
* Invoked implicitly by `deriveTheme`, `loadTheme`, and `deriveAnsi16Theme`
|
|
1039
|
+
* so every Theme `@silvery/ansi` produces has Sterling flat tokens baked in.
|
|
1040
|
+
* Callers do not need to call this directly.
|
|
1041
|
+
*
|
|
1042
|
+
* Behavior:
|
|
1043
|
+
* - Preserves every existing Theme field unchanged
|
|
1044
|
+
* - Writes Sterling flat tokens (`bg-accent`, `fg-on-accent`, `border-focus`, …)
|
|
1045
|
+
* only when the key isn't already present as a string (so author pins /
|
|
1046
|
+
* palette-provided values win)
|
|
1047
|
+
* - Not frozen (theme overlays mutate in a few callers)
|
|
1048
|
+
*
|
|
1049
|
+
* A ColorScheme can be supplied for full fidelity. When omitted, Sterling
|
|
1050
|
+
* derives from a ColorScheme reconstructed from the theme's own palette —
|
|
1051
|
+
* lossy for ANSI slot colors but sufficient for Sterling's 6-slot surface.
|
|
1052
|
+
*
|
|
1053
|
+
* Exported from `@silvery/ansi` for advanced users who author Theme objects
|
|
1054
|
+
* by hand and want to ensure the flat tokens are populated; for scheme →
|
|
1055
|
+
* Theme construction `deriveTheme`/`loadTheme` handle this automatically.
|
|
1056
|
+
*/
|
|
1057
|
+
/**
|
|
1058
|
+
* Build a ColorScheme-shaped input from a Theme when the original
|
|
1059
|
+
* scheme isn't available (hand-crafted themes, picker round-trips).
|
|
1060
|
+
*
|
|
1061
|
+
* Reads legacy single-hex hints that the legacy `deriveTheme` path still
|
|
1062
|
+
* emits (`theme.primary`, `theme.accent`, `theme.cursorbg`, …) via bracket
|
|
1063
|
+
* access. Selection / inverse / link aliases were dropped in 0.21.0 — pulls
|
|
1064
|
+
* those from Sterling's nested role objects (`theme.selected.bg`,
|
|
1065
|
+
* `theme.inverse.bg`, `theme.link.fg`).
|
|
1066
|
+
*/
|
|
1067
|
+
function schemeFromTheme(theme) {
|
|
1068
|
+
const palette = theme.palette ?? [];
|
|
1069
|
+
const legacy = theme;
|
|
1070
|
+
const primary = legacy["primary"];
|
|
1071
|
+
const accent = legacy["accent"];
|
|
1072
|
+
const errorHex = (typeof legacy["error"] === "string" ? legacy["error"] : theme.error?.fg) ?? "#000000";
|
|
1073
|
+
const successHex = (typeof legacy["success"] === "string" ? legacy["success"] : theme.success?.fg) ?? "#000000";
|
|
1074
|
+
const warningHex = (typeof legacy["warning"] === "string" ? legacy["warning"] : theme.warning?.fg) ?? "#000000";
|
|
1075
|
+
const infoHex = (typeof legacy["info"] === "string" ? legacy["info"] : theme.info?.fg) ?? "#000000";
|
|
1076
|
+
const accentHex = accent ?? theme.accent?.fg ?? primary ?? "#000000";
|
|
1077
|
+
const primaryHex = primary ?? theme.accent?.fg ?? "#000000";
|
|
1078
|
+
const mutedHex = (typeof legacy["muted"] === "string" ? legacy["muted"] : theme.muted?.fg) ?? "#888888";
|
|
1079
|
+
const cursorBg = legacy["cursorbg"] ?? theme.cursor?.bg ?? theme.bg;
|
|
1080
|
+
const cursorFg = legacy["cursor"] ?? theme.cursor?.fg ?? theme.fg;
|
|
1081
|
+
const selectionBg = theme.selected?.bg ?? theme.bg;
|
|
1082
|
+
const selectionFg = theme.selected?.fgOn ?? theme.fg;
|
|
1083
|
+
return {
|
|
1084
|
+
name: theme.name,
|
|
1085
|
+
dark: isDark(theme.bg),
|
|
1086
|
+
primary: primaryHex,
|
|
1087
|
+
black: palette[0] ?? "#000000",
|
|
1088
|
+
red: palette[1] ?? errorHex,
|
|
1089
|
+
green: palette[2] ?? successHex,
|
|
1090
|
+
yellow: palette[3] ?? warningHex,
|
|
1091
|
+
blue: palette[4] ?? primaryHex,
|
|
1092
|
+
magenta: palette[5] ?? accentHex,
|
|
1093
|
+
cyan: palette[6] ?? infoHex,
|
|
1094
|
+
white: palette[7] ?? theme.fg,
|
|
1095
|
+
brightBlack: palette[8] ?? mutedHex,
|
|
1096
|
+
brightRed: palette[9] ?? errorHex,
|
|
1097
|
+
brightGreen: palette[10] ?? successHex,
|
|
1098
|
+
brightYellow: palette[11] ?? warningHex,
|
|
1099
|
+
brightBlue: palette[12] ?? primaryHex,
|
|
1100
|
+
brightMagenta: palette[13] ?? accentHex,
|
|
1101
|
+
brightCyan: palette[14] ?? infoHex,
|
|
1102
|
+
brightWhite: palette[15] ?? theme.fg,
|
|
1103
|
+
foreground: theme.fg,
|
|
1104
|
+
background: theme.bg,
|
|
1105
|
+
cursorColor: cursorBg,
|
|
1106
|
+
cursorText: cursorFg,
|
|
1107
|
+
selectionBackground: selectionBg,
|
|
1108
|
+
selectionForeground: selectionFg
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Quick luminance check — matches relativeLuminance threshold (0.5). Avoids
|
|
1113
|
+
* pulling in @silvery/color for a single boolean.
|
|
1114
|
+
*/
|
|
1115
|
+
function isDark(hex) {
|
|
1116
|
+
const m = /^#?([0-9a-f]{6})$/i.exec(hex);
|
|
1117
|
+
if (!m?.[1]) return true;
|
|
1118
|
+
const n = parseInt(m[1], 16);
|
|
1119
|
+
const r = n >> 16 & 255;
|
|
1120
|
+
const g = n >> 8 & 255;
|
|
1121
|
+
const b = n & 255;
|
|
1122
|
+
return (.2126 * r + .7152 * g + .0722 * b) / 255 < .5;
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1125
|
+
* Write Sterling flat tokens onto a Theme and return the augmented object.
|
|
1126
|
+
* Sets a key only when it's not already a string on the theme (so author
|
|
1127
|
+
* pins / palette-provided values win).
|
|
1128
|
+
*
|
|
1129
|
+
* When `scheme` is provided, Sterling derives directly from it (full fidelity).
|
|
1130
|
+
* Otherwise a scheme is reconstructed from the theme's palette (lossy on ANSI
|
|
1131
|
+
* slots but fine for Sterling's derivation surface).
|
|
1132
|
+
*/
|
|
1133
|
+
function inlineSterlingTokens(theme, scheme) {
|
|
1134
|
+
const src = scheme ?? schemeFromTheme(theme);
|
|
1135
|
+
const { roles } = deriveRoles(src, { contrast: "auto-lift" });
|
|
1136
|
+
const out = { ...theme };
|
|
1137
|
+
const setIfAbsent = (key, value) => {
|
|
1138
|
+
if (!(key in out) || typeof out[key] !== "string") out[key] = value;
|
|
1139
|
+
};
|
|
1140
|
+
const accent = roles.accent;
|
|
1141
|
+
if (accent) {
|
|
1142
|
+
setIfAbsent("fg-accent", accent.fg);
|
|
1143
|
+
setIfAbsent("bg-accent", accent.bg);
|
|
1144
|
+
setIfAbsent("fg-on-accent", accent.fgOn);
|
|
1145
|
+
for (const state of ["hover", "active"]) {
|
|
1146
|
+
const s = accent[state];
|
|
1147
|
+
if (!s) continue;
|
|
1148
|
+
setIfAbsent(`fg-accent-${state}`, s.fg);
|
|
1149
|
+
setIfAbsent(`bg-accent-${state}`, s.bg);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
for (const role of [
|
|
1153
|
+
"info",
|
|
1154
|
+
"success",
|
|
1155
|
+
"warning",
|
|
1156
|
+
"error"
|
|
1157
|
+
]) {
|
|
1158
|
+
const r = roles[role];
|
|
1159
|
+
if (!r) continue;
|
|
1160
|
+
setIfAbsent(`fg-${role}`, r.fg);
|
|
1161
|
+
setIfAbsent(`bg-${role}`, r.bg);
|
|
1162
|
+
setIfAbsent(`fg-on-${role}`, r.fgOn);
|
|
1163
|
+
for (const state of ["hover", "active"]) {
|
|
1164
|
+
const s = r[state];
|
|
1165
|
+
if (!s) continue;
|
|
1166
|
+
setIfAbsent(`bg-${role}-${state}`, s.bg);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
if (roles.accent && "border" in roles.accent) setIfAbsent("border-accent", roles.accent.border);
|
|
1170
|
+
const surf = roles.surface;
|
|
1171
|
+
if (surf) {
|
|
1172
|
+
out["bg-surface-default"] = surf.default;
|
|
1173
|
+
out["bg-surface-subtle"] = surf.subtle;
|
|
1174
|
+
out["bg-surface-raised"] = surf.raised;
|
|
1175
|
+
out["bg-surface-overlay"] = surf.overlay;
|
|
1176
|
+
out["bg-surface-hover"] = surf.hover;
|
|
1177
|
+
}
|
|
1178
|
+
const b = roles.border;
|
|
1179
|
+
if (b) {
|
|
1180
|
+
setIfAbsent("border-default", b.default);
|
|
1181
|
+
setIfAbsent("border-focus", b.focus);
|
|
1182
|
+
setIfAbsent("border-muted", b.muted);
|
|
1183
|
+
}
|
|
1184
|
+
const c = roles.cursor;
|
|
1185
|
+
if (c) {
|
|
1186
|
+
setIfAbsent("fg-cursor", c.fg);
|
|
1187
|
+
setIfAbsent("bg-cursor", c.bg);
|
|
1188
|
+
}
|
|
1189
|
+
const m = roles.muted;
|
|
1190
|
+
if (m) {
|
|
1191
|
+
setIfAbsent("fg-muted", m.fg);
|
|
1192
|
+
setIfAbsent("bg-muted", m.bg);
|
|
1193
|
+
}
|
|
1194
|
+
const sel = roles.selected;
|
|
1195
|
+
if (sel) {
|
|
1196
|
+
setIfAbsent("bg-selected", sel.bg);
|
|
1197
|
+
setIfAbsent("fg-on-selected", sel.fgOn);
|
|
1198
|
+
setIfAbsent("bg-selected-hover", sel.hover.bg);
|
|
1199
|
+
}
|
|
1200
|
+
const inv = roles.inverse;
|
|
1201
|
+
if (inv) {
|
|
1202
|
+
setIfAbsent("bg-inverse", inv.bg);
|
|
1203
|
+
setIfAbsent("fg-on-inverse", inv.fgOn);
|
|
1204
|
+
}
|
|
1205
|
+
const lnk = roles.link;
|
|
1206
|
+
if (lnk) setIfAbsent("fg-link", lnk.fg);
|
|
1207
|
+
const dis = roles.disabled;
|
|
1208
|
+
if (dis) {
|
|
1209
|
+
setIfAbsent("fg-disabled", dis.fg);
|
|
1210
|
+
setIfAbsent("bg-disabled", dis.bg);
|
|
1211
|
+
setIfAbsent("border-disabled", dis.border);
|
|
1212
|
+
}
|
|
1213
|
+
setIfAbsent("fg", src.foreground);
|
|
1214
|
+
setIfAbsent("bg", src.background);
|
|
1215
|
+
setIfAbsent("fg-default", src.foreground);
|
|
1216
|
+
setIfAbsent("bg-default", src.background);
|
|
1217
|
+
setIfAbsent("bg-backdrop", blend(src.background, "#000000", .4));
|
|
1218
|
+
return out;
|
|
1219
|
+
}
|
|
1220
|
+
var init_inline = __esmMin((() => {
|
|
1221
|
+
init_derive$1();
|
|
1222
|
+
}));
|
|
1223
|
+
//#endregion
|
|
1224
|
+
//#region packages/ansi/src/theme/derive.ts
|
|
1225
|
+
/**
|
|
1226
|
+
* Theme derivation — transforms a ColorScheme into a Theme.
|
|
1227
|
+
*/
|
|
1228
|
+
/**
|
|
1229
|
+
* Derive a Theme from a ColorScheme, with Sterling flat tokens baked in.
|
|
1230
|
+
*
|
|
1231
|
+
* Every Theme `@silvery/ansi` produces passes through `inlineSterlingTokens`
|
|
1232
|
+
* so consumers can read `$bg-accent`, `$bg-surface-overlay`, `$border-default`,
|
|
1233
|
+
* `$fg-muted`, etc. directly off the returned object. This is the one
|
|
1234
|
+
* canonical Theme shape in silvery — there is no separate "partial" Theme.
|
|
1235
|
+
*/
|
|
1236
|
+
function deriveTheme(palette, mode = "truecolor", adjustments) {
|
|
1237
|
+
return inlineSterlingTokens(mode === "ansi16" ? deriveAnsi16ThemeRaw(palette) : deriveTruecolorTheme(palette, adjustments), palette);
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Load and validate a theme from a ColorScheme.
|
|
1241
|
+
*
|
|
1242
|
+
* Combines `deriveTheme()` (auto-adjust via ensureContrast with project-tuned
|
|
1243
|
+
* thresholds) with `validateThemeInvariants()` (post-derivation visibility +
|
|
1244
|
+
* optional WCAG).
|
|
1245
|
+
*
|
|
1246
|
+
* We don't re-impose WCAG on top of derive's tweaked thresholds — default
|
|
1247
|
+
* validation checks visibility invariants only (selection/cursor vs bg) that
|
|
1248
|
+
* derive doesn't handle.
|
|
1249
|
+
*
|
|
1250
|
+
* @example
|
|
1251
|
+
* ```ts
|
|
1252
|
+
* // Default: lenient + visibility-only (derive already handled contrast)
|
|
1253
|
+
* const theme = loadTheme(myScheme)
|
|
1254
|
+
*
|
|
1255
|
+
* // Build-time audit: strict + full WCAG
|
|
1256
|
+
* const theme = loadTheme(myScheme, { enforce: "strict", wcag: true })
|
|
1257
|
+
* ```
|
|
1258
|
+
*/
|
|
1259
|
+
function loadTheme(palette, opts = {}) {
|
|
1260
|
+
const mode = opts.mode ?? "truecolor";
|
|
1261
|
+
const enforce = opts.enforce ?? "lenient";
|
|
1262
|
+
const theme = deriveTheme(palette, mode, opts.adjustments);
|
|
1263
|
+
if (enforce === "off") return theme;
|
|
1264
|
+
const { ok, violations } = validateThemeInvariants(theme, { wcag: opts.wcag });
|
|
1265
|
+
if (!ok) {
|
|
1266
|
+
if (enforce === "strict") throw new ThemeInvariantError(violations);
|
|
1267
|
+
if (opts.violations) opts.violations.push(...violations);
|
|
1268
|
+
}
|
|
1269
|
+
return theme;
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* Build a "raw" Theme with legacy single-hex role fields. The output is NOT a
|
|
1273
|
+
* complete Sterling Theme — Sterling roles + flat tokens are layered on by
|
|
1274
|
+
* `inlineSterlingTokens` at the end of `deriveTheme`. The cast at the bottom
|
|
1275
|
+
* (`as unknown as Theme`) acknowledges the staged construction; the contract
|
|
1276
|
+
* `deriveTheme()` returns a fully-shaped Sterling Theme is honored at the
|
|
1277
|
+
* `deriveTheme` boundary, not here.
|
|
1278
|
+
*
|
|
1279
|
+
* Legacy fields (`primary`, `primaryfg`, `accent`, `accentfg`, `errorfg`,
|
|
1280
|
+
* `successfg`, `warningfg`, `infofg`, `secondaryfg`, `focusborder`,
|
|
1281
|
+
* `inputborder`, `disabledfg`, `mutedbg`, `surfacebg`, `popoverbg`, `cursor`,
|
|
1282
|
+
* `cursorbg`, `secondary`, `border`) are still emitted at runtime so app code
|
|
1283
|
+
* that still uses `theme.primary` / `theme.errorfg` keeps working. The selection
|
|
1284
|
+
* / inverse / link aliases (`inverse`, `inversebg`, `selection`, `selectionbg`,
|
|
1285
|
+
* `link`) were dropped in 0.21.0 (sterling-purge-legacy-tokens) — consumers must
|
|
1286
|
+
* read Sterling's flat tokens (`bg-selected`, `fg-on-selected`, `bg-inverse`,
|
|
1287
|
+
* `fg-on-inverse`, `fg-link`).
|
|
1288
|
+
*/
|
|
1289
|
+
function deriveTruecolorTheme(p, adjustments) {
|
|
1290
|
+
const dark = p.dark ?? true;
|
|
1291
|
+
const bg = p.background;
|
|
1292
|
+
function ensure(token, color, against, target) {
|
|
1293
|
+
const result = ensureContrast(color, against, target);
|
|
1294
|
+
if (adjustments && result !== color) {
|
|
1295
|
+
const before = checkContrast(color, against);
|
|
1296
|
+
const after = checkContrast(result, against);
|
|
1297
|
+
adjustments.push({
|
|
1298
|
+
token,
|
|
1299
|
+
from: color,
|
|
1300
|
+
to: result,
|
|
1301
|
+
against,
|
|
1302
|
+
target,
|
|
1303
|
+
ratioBefore: before?.ratio ?? 0,
|
|
1304
|
+
ratioAfter: after?.ratio ?? 0
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
return result;
|
|
1308
|
+
}
|
|
1309
|
+
const surfacebg = blend(bg, p.foreground, .03);
|
|
1310
|
+
const popoverbg = blend(bg, p.foreground, .08);
|
|
1311
|
+
const fg = ensure("fg", p.foreground, popoverbg, AA$1);
|
|
1312
|
+
const primary = ensure("primary", p.primary ?? (dark ? p.yellow : p.blue), bg, AA$1);
|
|
1313
|
+
const accent = ensure("accent", complement(primary), bg, AA$1);
|
|
1314
|
+
const secondary = ensure("secondary", blend(primary, accent, .35), bg, AA$1);
|
|
1315
|
+
const error = ensure("error", p.red, bg, AA$1);
|
|
1316
|
+
const warning = ensure("warning", p.yellow, bg, AA$1);
|
|
1317
|
+
const success = ensure("success", p.green, bg, AA$1);
|
|
1318
|
+
const info = ensure("info", blend(fg, accent, .5), bg, AA$1);
|
|
1319
|
+
const red = ensure("red", p.red, bg, AA$1);
|
|
1320
|
+
const orange = ensure("orange", blend(p.red, p.yellow, .5), bg, AA$1);
|
|
1321
|
+
const yellow = ensure("yellow", p.yellow, bg, AA$1);
|
|
1322
|
+
const green = ensure("green", p.green, bg, AA$1);
|
|
1323
|
+
const teal = ensure("teal", blend(p.green, p.cyan, .5), bg, AA$1);
|
|
1324
|
+
const blue = ensure("blue", dark ? p.brightBlue : p.blue, bg, AA$1);
|
|
1325
|
+
const purple = ensure("purple", p.magenta, bg, AA$1);
|
|
1326
|
+
const pink = ensure("pink", blend(p.magenta, p.red, .5), bg, AA$1);
|
|
1327
|
+
const mutedbg = blend(bg, p.foreground, .04);
|
|
1328
|
+
const muted = ensure("muted", blend(fg, bg, .4), mutedbg, AA$1);
|
|
1329
|
+
const disabledfg = ensure("disabledfg", blend(fg, bg, .5), bg, DIM);
|
|
1330
|
+
const border = ensure("border", blend(bg, p.foreground, .15), bg, FAINT$1);
|
|
1331
|
+
const inputborder = ensure("inputborder", blend(bg, p.foreground, .25), bg, CONTROL);
|
|
1332
|
+
const selectionBg = repairSelectionBg(p.selectionBackground, bg);
|
|
1333
|
+
const cursorBgRepaired = repairCursorBg(p.cursorColor, bg);
|
|
1334
|
+
const cursor = ensure("cursor", p.cursorText, cursorBgRepaired, AA$1);
|
|
1335
|
+
const derived = deriveFields({
|
|
1336
|
+
dark,
|
|
1337
|
+
primary,
|
|
1338
|
+
accent,
|
|
1339
|
+
fg,
|
|
1340
|
+
selectionbg: selectionBg,
|
|
1341
|
+
surfacebg,
|
|
1342
|
+
ring: {
|
|
1343
|
+
red,
|
|
1344
|
+
orange,
|
|
1345
|
+
yellow,
|
|
1346
|
+
green,
|
|
1347
|
+
teal,
|
|
1348
|
+
blue,
|
|
1349
|
+
purple,
|
|
1350
|
+
pink
|
|
1351
|
+
}
|
|
1352
|
+
});
|
|
1353
|
+
return {
|
|
1354
|
+
name: p.name ?? (dark ? "derived-dark" : "derived-light"),
|
|
1355
|
+
bg,
|
|
1356
|
+
fg,
|
|
1357
|
+
muted,
|
|
1358
|
+
mutedbg,
|
|
1359
|
+
surface: fg,
|
|
1360
|
+
surfacebg,
|
|
1361
|
+
popover: fg,
|
|
1362
|
+
popoverbg,
|
|
1363
|
+
cursor,
|
|
1364
|
+
cursorbg: cursorBgRepaired,
|
|
1365
|
+
primary,
|
|
1366
|
+
primaryfg: contrastFg(primary),
|
|
1367
|
+
secondary,
|
|
1368
|
+
secondaryfg: contrastFg(secondary),
|
|
1369
|
+
accent,
|
|
1370
|
+
accentfg: contrastFg(accent),
|
|
1371
|
+
error,
|
|
1372
|
+
errorfg: contrastFg(error),
|
|
1373
|
+
warning,
|
|
1374
|
+
warningfg: contrastFg(warning),
|
|
1375
|
+
success,
|
|
1376
|
+
successfg: contrastFg(success),
|
|
1377
|
+
info,
|
|
1378
|
+
infofg: contrastFg(info),
|
|
1379
|
+
border,
|
|
1380
|
+
inputborder,
|
|
1381
|
+
focusborder: ensure("focusborder", dark ? p.brightBlue : p.blue, bg, AA$1),
|
|
1382
|
+
disabledfg,
|
|
1383
|
+
palette: [
|
|
1384
|
+
p.black,
|
|
1385
|
+
p.red,
|
|
1386
|
+
p.green,
|
|
1387
|
+
p.yellow,
|
|
1388
|
+
p.blue,
|
|
1389
|
+
p.magenta,
|
|
1390
|
+
p.cyan,
|
|
1391
|
+
p.white,
|
|
1392
|
+
p.brightBlack,
|
|
1393
|
+
p.brightRed,
|
|
1394
|
+
p.brightGreen,
|
|
1395
|
+
p.brightYellow,
|
|
1396
|
+
p.brightBlue,
|
|
1397
|
+
p.brightMagenta,
|
|
1398
|
+
p.brightCyan,
|
|
1399
|
+
p.brightWhite
|
|
1400
|
+
],
|
|
1401
|
+
...derived
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
function deriveAnsi16Theme(p) {
|
|
1405
|
+
return inlineSterlingTokens(deriveAnsi16ThemeRaw(p), p);
|
|
1406
|
+
}
|
|
1407
|
+
function deriveAnsi16ThemeRaw(p) {
|
|
1408
|
+
const dark = p.dark ?? true;
|
|
1409
|
+
const primaryColor = dark ? p.yellow : p.blue;
|
|
1410
|
+
const accentColor = p.cyan;
|
|
1411
|
+
const derived = deriveFields({
|
|
1412
|
+
primary: primaryColor,
|
|
1413
|
+
accent: accentColor,
|
|
1414
|
+
fg: p.foreground,
|
|
1415
|
+
selectionbg: p.selectionBackground,
|
|
1416
|
+
surfacebg: p.black,
|
|
1417
|
+
ring: {
|
|
1418
|
+
red: dark ? p.brightRed : p.red,
|
|
1419
|
+
orange: dark ? p.brightRed : p.red,
|
|
1420
|
+
yellow: p.yellow,
|
|
1421
|
+
green: dark ? p.brightGreen : p.green,
|
|
1422
|
+
teal: p.cyan,
|
|
1423
|
+
blue: dark ? p.brightBlue : p.blue,
|
|
1424
|
+
purple: p.magenta,
|
|
1425
|
+
pink: dark ? p.brightMagenta : p.magenta
|
|
1426
|
+
}
|
|
1427
|
+
});
|
|
1428
|
+
return {
|
|
1429
|
+
name: p.name ?? (dark ? "derived-ansi16-dark" : "derived-ansi16-light"),
|
|
1430
|
+
bg: p.background,
|
|
1431
|
+
fg: p.foreground,
|
|
1432
|
+
muted: p.white,
|
|
1433
|
+
mutedbg: p.black,
|
|
1434
|
+
surface: p.foreground,
|
|
1435
|
+
surfacebg: p.black,
|
|
1436
|
+
popover: p.foreground,
|
|
1437
|
+
popoverbg: p.black,
|
|
1438
|
+
cursor: p.cursorText,
|
|
1439
|
+
cursorbg: p.cursorColor,
|
|
1440
|
+
primary: primaryColor,
|
|
1441
|
+
primaryfg: p.black,
|
|
1442
|
+
secondary: p.magenta,
|
|
1443
|
+
secondaryfg: p.black,
|
|
1444
|
+
accent: accentColor,
|
|
1445
|
+
accentfg: p.black,
|
|
1446
|
+
error: dark ? p.brightRed : p.red,
|
|
1447
|
+
errorfg: p.black,
|
|
1448
|
+
warning: p.yellow,
|
|
1449
|
+
warningfg: p.black,
|
|
1450
|
+
success: dark ? p.brightGreen : p.green,
|
|
1451
|
+
successfg: p.black,
|
|
1452
|
+
info: p.cyan,
|
|
1453
|
+
infofg: p.black,
|
|
1454
|
+
border: p.brightBlack,
|
|
1455
|
+
inputborder: p.brightBlack,
|
|
1456
|
+
focusborder: dark ? p.brightBlue : p.blue,
|
|
1457
|
+
disabledfg: p.brightBlack,
|
|
1458
|
+
palette: [
|
|
1459
|
+
p.black,
|
|
1460
|
+
p.red,
|
|
1461
|
+
p.green,
|
|
1462
|
+
p.yellow,
|
|
1463
|
+
p.blue,
|
|
1464
|
+
p.magenta,
|
|
1465
|
+
p.cyan,
|
|
1466
|
+
p.white,
|
|
1467
|
+
p.brightBlack,
|
|
1468
|
+
p.brightRed,
|
|
1469
|
+
p.brightGreen,
|
|
1470
|
+
p.brightYellow,
|
|
1471
|
+
p.brightBlue,
|
|
1472
|
+
p.brightMagenta,
|
|
1473
|
+
p.brightCyan,
|
|
1474
|
+
p.brightWhite
|
|
1475
|
+
],
|
|
1476
|
+
...derived
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* Nudge `selectionBg`'s OKLCH lightness until it differs from `bg` by at least
|
|
1481
|
+
* `SELECTION_DELTA_L`. Preserves hue + chroma. Non-hex input returns unchanged.
|
|
1482
|
+
*
|
|
1483
|
+
* Direction: shift away from bg — if bg is dark, lift L; if bg is light, drop L.
|
|
1484
|
+
* If the input already meets the threshold, it's returned unchanged.
|
|
1485
|
+
*/
|
|
1486
|
+
function repairSelectionBg(selectionBg, bg) {
|
|
1487
|
+
const oSel = hexToOklch(selectionBg);
|
|
1488
|
+
const oBg = hexToOklch(bg);
|
|
1489
|
+
if (!oSel || !oBg) return selectionBg;
|
|
1490
|
+
const dL = Math.abs(oSel.L - oBg.L);
|
|
1491
|
+
if (dL >= .08) return selectionBg;
|
|
1492
|
+
const needed = SELECTION_DELTA_L$1 - dL + .005;
|
|
1493
|
+
const direction = oSel.L >= oBg.L ? 1 : -1;
|
|
1494
|
+
return oklchToHex({
|
|
1495
|
+
L: Math.max(0, Math.min(1, oSel.L + direction * needed)),
|
|
1496
|
+
C: oSel.C,
|
|
1497
|
+
H: oSel.H
|
|
1498
|
+
});
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* Nudge `cursorBg`'s OKLCH values until it differs from `bg` by at least
|
|
1502
|
+
* `CURSOR_DELTA_E`. Shifts lightness first (preserves hue/chroma aesthetics).
|
|
1503
|
+
* Non-hex input returns unchanged.
|
|
1504
|
+
*/
|
|
1505
|
+
function repairCursorBg(cursorBg, bg) {
|
|
1506
|
+
const d = colorDistance(cursorBg, bg);
|
|
1507
|
+
if (d === null || d >= .15) return cursorBg;
|
|
1508
|
+
const oCur = hexToOklch(cursorBg);
|
|
1509
|
+
const oBg = hexToOklch(bg);
|
|
1510
|
+
const lGap = SELECTION_DELTA_L$1 + .02;
|
|
1511
|
+
const direction = oCur.L >= oBg.L ? 1 : -1;
|
|
1512
|
+
const candidate = oklchToHex({
|
|
1513
|
+
L: Math.max(0, Math.min(1, oCur.L + direction * lGap)),
|
|
1514
|
+
C: oCur.C,
|
|
1515
|
+
H: oCur.H
|
|
1516
|
+
});
|
|
1517
|
+
const d2 = colorDistance(candidate, bg);
|
|
1518
|
+
if (d2 !== null && d2 >= .15) return candidate;
|
|
1519
|
+
return oBg.L > .5 ? "#000000" : "#FFFFFF";
|
|
1520
|
+
}
|
|
1521
|
+
var AA$1, DIM, FAINT$1, CONTROL;
|
|
1522
|
+
var init_derive = __esmMin((() => {
|
|
1523
|
+
init_invariants();
|
|
1524
|
+
init_derived();
|
|
1525
|
+
init_inline();
|
|
1526
|
+
AA$1 = 4.5;
|
|
1527
|
+
DIM = 3;
|
|
1528
|
+
FAINT$1 = 1.5;
|
|
1529
|
+
CONTROL = 3;
|
|
1530
|
+
}));
|
|
1531
|
+
//#endregion
|
|
1532
|
+
//#region packages/ansi/src/theme/default-schemes.ts
|
|
1533
|
+
var defaultDarkScheme, defaultLightScheme, ansi16DarkTheme, ansi16LightTheme;
|
|
1534
|
+
var init_default_schemes = __esmMin((() => {
|
|
1535
|
+
init_derive();
|
|
1536
|
+
defaultDarkScheme = {
|
|
1537
|
+
name: "default-dark",
|
|
1538
|
+
dark: true,
|
|
1539
|
+
black: "#2e3440",
|
|
1540
|
+
red: "#bf616a",
|
|
1541
|
+
green: "#a3be8c",
|
|
1542
|
+
yellow: "#ebcb8b",
|
|
1543
|
+
blue: "#81a1c1",
|
|
1544
|
+
magenta: "#b48ead",
|
|
1545
|
+
cyan: "#88c0d0",
|
|
1546
|
+
white: "#d8dee9",
|
|
1547
|
+
brightBlack: "#4c566a",
|
|
1548
|
+
brightRed: "#bf616a",
|
|
1549
|
+
brightGreen: "#a3be8c",
|
|
1550
|
+
brightYellow: "#ebcb8b",
|
|
1551
|
+
brightBlue: "#81a1c1",
|
|
1552
|
+
brightMagenta: "#b48ead",
|
|
1553
|
+
brightCyan: "#8fbcbb",
|
|
1554
|
+
brightWhite: "#eceff4",
|
|
1555
|
+
foreground: "#d8dee9",
|
|
1556
|
+
background: "#2e3440",
|
|
1557
|
+
cursorColor: "#d8dee9",
|
|
1558
|
+
cursorText: "#2e3440",
|
|
1559
|
+
selectionBackground: "#434c5e",
|
|
1560
|
+
selectionForeground: "#d8dee9"
|
|
1561
|
+
};
|
|
1562
|
+
defaultLightScheme = {
|
|
1563
|
+
name: "default-light",
|
|
1564
|
+
dark: false,
|
|
1565
|
+
black: "#5c6370",
|
|
1566
|
+
red: "#d20f39",
|
|
1567
|
+
green: "#40a02b",
|
|
1568
|
+
yellow: "#df8e1d",
|
|
1569
|
+
blue: "#1e66f5",
|
|
1570
|
+
magenta: "#8839ef",
|
|
1571
|
+
cyan: "#179299",
|
|
1572
|
+
white: "#dce0e8",
|
|
1573
|
+
brightBlack: "#6c7086",
|
|
1574
|
+
brightRed: "#d20f39",
|
|
1575
|
+
brightGreen: "#40a02b",
|
|
1576
|
+
brightYellow: "#df8e1d",
|
|
1577
|
+
brightBlue: "#1e66f5",
|
|
1578
|
+
brightMagenta: "#8839ef",
|
|
1579
|
+
brightCyan: "#179299",
|
|
1580
|
+
brightWhite: "#eff1f5",
|
|
1581
|
+
foreground: "#4c4f69",
|
|
1582
|
+
background: "#eff1f5",
|
|
1583
|
+
cursorColor: "#dc8a78",
|
|
1584
|
+
cursorText: "#eff1f5",
|
|
1585
|
+
selectionBackground: "#ccd0da",
|
|
1586
|
+
selectionForeground: "#4c4f69"
|
|
1587
|
+
};
|
|
1588
|
+
ansi16DarkTheme = deriveAnsi16Theme(defaultDarkScheme);
|
|
1589
|
+
ansi16LightTheme = deriveAnsi16Theme(defaultLightScheme);
|
|
1590
|
+
}));
|
|
1591
|
+
//#endregion
|
|
1592
|
+
//#region packages/ansi/src/osc-palette.ts
|
|
1593
|
+
function queryPaletteColor(index, write) {
|
|
1594
|
+
if (index < 0 || index > 255) throw new RangeError(`Palette index must be 0-255, got ${index}`);
|
|
1595
|
+
write(`${ESC$4}]4;${index};?${BEL$2}`);
|
|
1596
|
+
}
|
|
1597
|
+
function queryMultiplePaletteColors(indices, write) {
|
|
1598
|
+
for (const index of indices) queryPaletteColor(index, write);
|
|
1599
|
+
}
|
|
1600
|
+
function setPaletteColor(index, color, write) {
|
|
1601
|
+
if (index < 0 || index > 255) throw new RangeError(`Palette index must be 0-255, got ${index}`);
|
|
1602
|
+
write(`${ESC$4}]4;${index};${color}${BEL$2}`);
|
|
1603
|
+
}
|
|
1604
|
+
function parsePaletteResponse(input) {
|
|
1605
|
+
const prefixIdx = input.indexOf(OSC4_PREFIX);
|
|
1606
|
+
if (prefixIdx === -1) return null;
|
|
1607
|
+
const bodyStart = prefixIdx + OSC4_PREFIX.length;
|
|
1608
|
+
let bodyEnd = input.indexOf(BEL$2, bodyStart);
|
|
1609
|
+
if (bodyEnd === -1) bodyEnd = input.indexOf(`${ESC$4}\\`, bodyStart);
|
|
1610
|
+
if (bodyEnd === -1) return null;
|
|
1611
|
+
const body = input.slice(bodyStart, bodyEnd);
|
|
1612
|
+
const match = OSC4_BODY_RE.exec(body);
|
|
1613
|
+
if (!match) return null;
|
|
1614
|
+
const index = Number.parseInt(match[1], 10);
|
|
1615
|
+
if (index < 0 || index > 255) return null;
|
|
1616
|
+
return {
|
|
1617
|
+
index,
|
|
1618
|
+
color: `#${normalizeHexChannel$1(match[2])}${normalizeHexChannel$1(match[3])}${normalizeHexChannel$1(match[4])}`
|
|
1619
|
+
};
|
|
1620
|
+
}
|
|
1621
|
+
function normalizeHexChannel$1(hex) {
|
|
1622
|
+
switch (hex.length) {
|
|
1623
|
+
case 1: return hex + hex;
|
|
1624
|
+
case 2: return hex;
|
|
1625
|
+
default: return hex.slice(0, 2);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
var ESC$4, BEL$2, OSC4_PREFIX, OSC4_BODY_RE;
|
|
1629
|
+
var init_osc_palette = __esmMin((() => {
|
|
1630
|
+
ESC$4 = "\x1B";
|
|
1631
|
+
BEL$2 = "\x07";
|
|
1632
|
+
OSC4_PREFIX = `${ESC$4}]4;`;
|
|
1633
|
+
OSC4_BODY_RE = /^(\d+);rgb:([0-9a-fA-F]{1,4})\/([0-9a-fA-F]{1,4})\/([0-9a-fA-F]{1,4})$/;
|
|
1634
|
+
}));
|
|
1635
|
+
//#endregion
|
|
1636
|
+
//#region packages/ansi/src/protocol-error.ts
|
|
1637
|
+
/** Narrowing helper — true if `err` is a ProtocolError. */
|
|
1638
|
+
function isProtocolError(err) {
|
|
1639
|
+
return err instanceof ProtocolError;
|
|
1640
|
+
}
|
|
1641
|
+
var INPUT_TRUNCATE_LENGTH, ProtocolError;
|
|
1642
|
+
var init_protocol_error = __esmMin((() => {
|
|
1643
|
+
INPUT_TRUNCATE_LENGTH = 256;
|
|
1644
|
+
ProtocolError = class extends Error {
|
|
1645
|
+
name = "ProtocolError";
|
|
1646
|
+
parser;
|
|
1647
|
+
input;
|
|
1648
|
+
inputLength;
|
|
1649
|
+
reason;
|
|
1650
|
+
constructor(opts) {
|
|
1651
|
+
const inputLength = opts.input.length;
|
|
1652
|
+
const truncated = inputLength > INPUT_TRUNCATE_LENGTH ? `${opts.input.slice(0, INPUT_TRUNCATE_LENGTH)}…<${inputLength - INPUT_TRUNCATE_LENGTH} more chars>` : opts.input;
|
|
1653
|
+
super(`${opts.parser}: ${opts.reason} (input=${JSON.stringify(truncated)})`);
|
|
1654
|
+
this.parser = opts.parser;
|
|
1655
|
+
this.input = truncated;
|
|
1656
|
+
this.inputLength = inputLength;
|
|
1657
|
+
this.reason = opts.reason;
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
}));
|
|
1661
|
+
//#endregion
|
|
1662
|
+
//#region packages/ansi/src/osc-colors.ts
|
|
1663
|
+
function normalizeHexChannel(hex) {
|
|
1664
|
+
switch (hex.length) {
|
|
1665
|
+
case 1: return hex + hex;
|
|
1666
|
+
case 2: return hex;
|
|
1667
|
+
default: return hex.slice(0, 2);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
/**
|
|
1671
|
+
* Parse an OSC 10/11/12 color query response.
|
|
1672
|
+
*
|
|
1673
|
+
* Return semantics (see {@link ProtocolError} for the full contract):
|
|
1674
|
+
* - `null` — input does not contain the OSC `oscCode` prefix (not for us).
|
|
1675
|
+
* - `throw ProtocolError` — prefix matched (we committed to this protocol)
|
|
1676
|
+
* but the response is malformed: missing terminator, body is not a valid
|
|
1677
|
+
* `rgb:RRRR/GGGG/BBBB` spec, etc.
|
|
1678
|
+
*
|
|
1679
|
+
* Exported for testing and so callers in chained-discriminator pipelines
|
|
1680
|
+
* can dispatch raw input through the parser directly. Most users should
|
|
1681
|
+
* use {@link queryForegroundColor} / {@link queryBackgroundColor} /
|
|
1682
|
+
* {@link queryCursorColor} which wrap this with the write+read cycle.
|
|
1683
|
+
*/
|
|
1684
|
+
function parseOscColorResponse(input, oscCode) {
|
|
1685
|
+
const prefix = `${ESC$3}]${oscCode};`;
|
|
1686
|
+
const prefixIdx = input.indexOf(prefix);
|
|
1687
|
+
if (prefixIdx === -1) return null;
|
|
1688
|
+
const bodyStart = prefixIdx + prefix.length;
|
|
1689
|
+
let bodyEnd = input.indexOf(BEL$1, bodyStart);
|
|
1690
|
+
if (bodyEnd === -1) bodyEnd = input.indexOf(`${ESC$3}\\`, bodyStart);
|
|
1691
|
+
if (bodyEnd === -1) throw new ProtocolError({
|
|
1692
|
+
parser: "parseOscColorResponse",
|
|
1693
|
+
input,
|
|
1694
|
+
reason: `OSC ${oscCode} prefix present but missing terminator (expected BEL or ST)`
|
|
1695
|
+
});
|
|
1696
|
+
const body = input.slice(bodyStart, bodyEnd);
|
|
1697
|
+
const match = RGB_BODY_RE$1.exec(body);
|
|
1698
|
+
if (!match) throw new ProtocolError({
|
|
1699
|
+
parser: "parseOscColorResponse",
|
|
1700
|
+
input,
|
|
1701
|
+
reason: `OSC ${oscCode} body is not a valid rgb:RRRR/GGGG/BBBB spec (body=${JSON.stringify(body)})`
|
|
1702
|
+
});
|
|
1703
|
+
return `#${normalizeHexChannel(match[1])}${normalizeHexChannel(match[2])}${normalizeHexChannel(match[3])}`;
|
|
1704
|
+
}
|
|
1705
|
+
async function queryOscColor(write, read, oscCode, timeoutMs) {
|
|
1706
|
+
write(`${ESC$3}]${oscCode};?${BEL$1}`);
|
|
1707
|
+
const data = await read(timeoutMs);
|
|
1708
|
+
if (data == null) return null;
|
|
1709
|
+
return parseOscColorResponse(data, oscCode);
|
|
1710
|
+
}
|
|
1711
|
+
async function queryForegroundColor(write, read, timeoutMs = 200) {
|
|
1712
|
+
return queryOscColor(write, read, 10, timeoutMs);
|
|
1713
|
+
}
|
|
1714
|
+
async function queryBackgroundColor(write, read, timeoutMs = 200) {
|
|
1715
|
+
return queryOscColor(write, read, 11, timeoutMs);
|
|
1716
|
+
}
|
|
1717
|
+
async function queryCursorColor(write, read, timeoutMs = 200) {
|
|
1718
|
+
return queryOscColor(write, read, 12, timeoutMs);
|
|
1719
|
+
}
|
|
1720
|
+
function setForegroundColor(write, color) {
|
|
1721
|
+
write(`${ESC$3}]10;${color}${BEL$1}`);
|
|
1722
|
+
}
|
|
1723
|
+
function setBackgroundColor(write, color) {
|
|
1724
|
+
write(`${ESC$3}]11;${color}${BEL$1}`);
|
|
1725
|
+
}
|
|
1726
|
+
function setCursorColor(write, color) {
|
|
1727
|
+
write(`${ESC$3}]12;${color}${BEL$1}`);
|
|
1728
|
+
}
|
|
1729
|
+
function resetForegroundColor(write) {
|
|
1730
|
+
write(`${ESC$3}]110${BEL$1}`);
|
|
1731
|
+
}
|
|
1732
|
+
function resetBackgroundColor(write) {
|
|
1733
|
+
write(`${ESC$3}]111${BEL$1}`);
|
|
1734
|
+
}
|
|
1735
|
+
function resetCursorColor(write) {
|
|
1736
|
+
write(`${ESC$3}]112${BEL$1}`);
|
|
1737
|
+
}
|
|
1738
|
+
async function detectColorScheme(write, read, timeoutMs = 200) {
|
|
1739
|
+
const bg = await queryBackgroundColor(write, read, timeoutMs);
|
|
1740
|
+
if (bg == null) return null;
|
|
1741
|
+
const r = parseInt(bg.slice(1, 3), 16) / 255;
|
|
1742
|
+
const g = parseInt(bg.slice(3, 5), 16) / 255;
|
|
1743
|
+
const b = parseInt(bg.slice(5, 7), 16) / 255;
|
|
1744
|
+
return .2126 * r + .7152 * g + .0722 * b > .5 ? "light" : "dark";
|
|
1745
|
+
}
|
|
1746
|
+
var ESC$3, BEL$1, RGB_BODY_RE$1;
|
|
1747
|
+
var init_osc_colors = __esmMin((() => {
|
|
1748
|
+
init_protocol_error();
|
|
1749
|
+
ESC$3 = "\x1B";
|
|
1750
|
+
BEL$1 = "\x07";
|
|
1751
|
+
RGB_BODY_RE$1 = /rgb:([0-9a-fA-F]{1,4})\/([0-9a-fA-F]{1,4})\/([0-9a-fA-F]{1,4})/;
|
|
1752
|
+
}));
|
|
1753
|
+
//#endregion
|
|
1754
|
+
//#region packages/ansi/src/theme/detect.ts
|
|
1755
|
+
/**
|
|
1756
|
+
* Probe the terminal for its 22-slot color scheme via OSC 4/10/11 queries.
|
|
1757
|
+
*
|
|
1758
|
+
* Pure terminal primitive — no fingerprinting, no theme derivation. Returns the
|
|
1759
|
+
* raw probed slots (or `null` if probing isn't available, e.g. non-TTY).
|
|
1760
|
+
*
|
|
1761
|
+
* For the full detection cascade (override → probe → fingerprint → fallback +
|
|
1762
|
+
* theme derivation), use `detectScheme` from `@silvery/ansi` or
|
|
1763
|
+
* `detectTheme` from `@silvery/theme`.
|
|
1764
|
+
*
|
|
1765
|
+
* `probeColors` is the canonical name; `detectTerminalScheme` is the legacy
|
|
1766
|
+
* alias kept for backward compatibility.
|
|
1767
|
+
*
|
|
1768
|
+
* Call styles:
|
|
1769
|
+
* await probeColors() // default timeout, standalone
|
|
1770
|
+
* await probeColors(150) // legacy positional timeout
|
|
1771
|
+
* await probeColors({ timeoutMs: 150 }) // options form
|
|
1772
|
+
* await probeColors({ input: inputOwner, timeoutMs: 150 }) // routed through InputOwner
|
|
1773
|
+
*/
|
|
1774
|
+
async function probeColors(timeoutOrOpts) {
|
|
1775
|
+
const opts = typeof timeoutOrOpts === "number" ? { timeoutMs: timeoutOrOpts } : timeoutOrOpts ?? {};
|
|
1776
|
+
const timeoutMs = opts.timeoutMs ?? 150;
|
|
1777
|
+
if (opts.input) return probeColorsViaOwner(opts.input, timeoutMs);
|
|
1778
|
+
const stdin = process.stdin;
|
|
1779
|
+
const stdout = process.stdout;
|
|
1780
|
+
if (!stdin.isTTY || !stdout.isTTY) return null;
|
|
1781
|
+
const otherListeners = stdin.listenerCount("data") > 0;
|
|
1782
|
+
const wasRaw = stdin.isRaw;
|
|
1783
|
+
let didSetRaw = false;
|
|
1784
|
+
if (!wasRaw && !otherListeners) {
|
|
1785
|
+
stdin.setRawMode(true);
|
|
1786
|
+
didSetRaw = true;
|
|
1787
|
+
}
|
|
1788
|
+
let buffer = "";
|
|
1789
|
+
const onData = (chunk) => {
|
|
1790
|
+
buffer += chunk.toString();
|
|
1791
|
+
};
|
|
1792
|
+
stdin.on("data", onData);
|
|
1793
|
+
try {
|
|
1794
|
+
const write = (s) => {
|
|
1795
|
+
stdout.write(s);
|
|
1796
|
+
};
|
|
1797
|
+
const read = (ms) => new Promise((resolve) => {
|
|
1798
|
+
if (buffer.length > 0) {
|
|
1799
|
+
const result = buffer;
|
|
1800
|
+
buffer = "";
|
|
1801
|
+
resolve(result);
|
|
1802
|
+
return;
|
|
1803
|
+
}
|
|
1804
|
+
const timer = setTimeout(() => {
|
|
1805
|
+
resolve(buffer.length > 0 ? buffer : null);
|
|
1806
|
+
buffer = "";
|
|
1807
|
+
}, ms);
|
|
1808
|
+
const check = (_chunk) => {
|
|
1809
|
+
clearTimeout(timer);
|
|
1810
|
+
stdin.removeListener("data", check);
|
|
1811
|
+
const result = buffer;
|
|
1812
|
+
buffer = "";
|
|
1813
|
+
resolve(result);
|
|
1814
|
+
};
|
|
1815
|
+
stdin.on("data", check);
|
|
1816
|
+
});
|
|
1817
|
+
const bg = await queryBackgroundColor(write, read, timeoutMs);
|
|
1818
|
+
const fg = await queryForegroundColor(write, read, timeoutMs);
|
|
1819
|
+
const ansi = new Array(16).fill(null);
|
|
1820
|
+
queryMultiplePaletteColors(Array.from({ length: 16 }, (_, i) => i), write);
|
|
1821
|
+
await new Promise((resolve) => setTimeout(resolve, timeoutMs));
|
|
1822
|
+
const remaining = buffer;
|
|
1823
|
+
buffer = "";
|
|
1824
|
+
if (remaining) {
|
|
1825
|
+
const oscPrefix = "\x1B]4;";
|
|
1826
|
+
let pos = 0;
|
|
1827
|
+
while (pos < remaining.length) {
|
|
1828
|
+
const nextOsc = remaining.indexOf(oscPrefix, pos);
|
|
1829
|
+
if (nextOsc === -1) break;
|
|
1830
|
+
let end = remaining.indexOf("\x07", nextOsc);
|
|
1831
|
+
if (end === -1) end = remaining.indexOf("\x1B\\", nextOsc);
|
|
1832
|
+
if (end === -1) break;
|
|
1833
|
+
const parsed = parsePaletteResponse(remaining.slice(nextOsc, end + 1));
|
|
1834
|
+
if (parsed && parsed.index >= 0 && parsed.index < 16) ansi[parsed.index] = parsed.color;
|
|
1835
|
+
pos = end + 1;
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
const dark = bg ? isDarkColor(bg) : true;
|
|
1839
|
+
const palette = { dark };
|
|
1840
|
+
if (bg) palette.background = bg;
|
|
1841
|
+
if (fg) palette.foreground = fg;
|
|
1842
|
+
const ansiFields = [
|
|
1843
|
+
"black",
|
|
1844
|
+
"red",
|
|
1845
|
+
"green",
|
|
1846
|
+
"yellow",
|
|
1847
|
+
"blue",
|
|
1848
|
+
"magenta",
|
|
1849
|
+
"cyan",
|
|
1850
|
+
"white",
|
|
1851
|
+
"brightBlack",
|
|
1852
|
+
"brightRed",
|
|
1853
|
+
"brightGreen",
|
|
1854
|
+
"brightYellow",
|
|
1855
|
+
"brightBlue",
|
|
1856
|
+
"brightMagenta",
|
|
1857
|
+
"brightCyan",
|
|
1858
|
+
"brightWhite"
|
|
1859
|
+
];
|
|
1860
|
+
for (let i = 0; i < 16; i++) if (ansi[i]) palette[ansiFields[i]] = ansi[i];
|
|
1861
|
+
if (fg) palette.cursorColor = fg;
|
|
1862
|
+
if (bg) palette.cursorText = bg;
|
|
1863
|
+
return {
|
|
1864
|
+
fg,
|
|
1865
|
+
bg,
|
|
1866
|
+
ansi,
|
|
1867
|
+
dark,
|
|
1868
|
+
palette
|
|
1869
|
+
};
|
|
1870
|
+
} finally {
|
|
1871
|
+
stdin.removeListener("data", onData);
|
|
1872
|
+
if (didSetRaw) stdin.setRawMode(false);
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
/** OSC response parser for a specific OSC code (10 or 11). Returns the
|
|
1876
|
+
* first matching response in the buffer and the byte count to consume
|
|
1877
|
+
* (the end of that response, so leading garbage is cleared as well).
|
|
1878
|
+
*/
|
|
1879
|
+
function parseOscColor(acc, oscCode) {
|
|
1880
|
+
const prefix = `${ESC$2}]${oscCode};`;
|
|
1881
|
+
const prefixIdx = acc.indexOf(prefix);
|
|
1882
|
+
if (prefixIdx === -1) return null;
|
|
1883
|
+
const bodyStart = prefixIdx + prefix.length;
|
|
1884
|
+
let bodyEnd = acc.indexOf(BEL, bodyStart);
|
|
1885
|
+
let terminatorLen = 1;
|
|
1886
|
+
if (bodyEnd === -1) {
|
|
1887
|
+
bodyEnd = acc.indexOf(`${ESC$2}\\`, bodyStart);
|
|
1888
|
+
terminatorLen = 2;
|
|
1889
|
+
if (bodyEnd === -1) return null;
|
|
1890
|
+
}
|
|
1891
|
+
const body = acc.slice(bodyStart, bodyEnd);
|
|
1892
|
+
const match = RGB_BODY_RE.exec(body);
|
|
1893
|
+
if (!match) return null;
|
|
1894
|
+
return {
|
|
1895
|
+
result: `#${normalizeHex(match[1])}${normalizeHex(match[2])}${normalizeHex(match[3])}`,
|
|
1896
|
+
consumed: bodyEnd + terminatorLen
|
|
1897
|
+
};
|
|
1898
|
+
}
|
|
1899
|
+
function normalizeHex(channel) {
|
|
1900
|
+
if (channel.length === 1) return channel + channel;
|
|
1901
|
+
if (channel.length === 2) return channel;
|
|
1902
|
+
return channel.slice(0, 2);
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Route OSC 10/11/4 queries through an InputOwner. Same semantics as the
|
|
1906
|
+
* standalone `probeColors` path (FG + BG sequentially, 16 palette slots in
|
|
1907
|
+
* one burst with a final drain), but all stdin access is owner-mediated —
|
|
1908
|
+
* no direct raw-mode toggles, no stdin.on("data").
|
|
1909
|
+
*/
|
|
1910
|
+
async function probeColorsViaOwner(input, timeoutMs) {
|
|
1911
|
+
const fgQuery = `${ESC$2}]10;?${BEL}`;
|
|
1912
|
+
const fg = await input.probe({
|
|
1913
|
+
query: fgQuery,
|
|
1914
|
+
parse: (acc) => parseOscColor(acc, 10),
|
|
1915
|
+
timeoutMs
|
|
1916
|
+
});
|
|
1917
|
+
const bgQuery = `${ESC$2}]11;?${BEL}`;
|
|
1918
|
+
const bg = await input.probe({
|
|
1919
|
+
query: bgQuery,
|
|
1920
|
+
parse: (acc) => parseOscColor(acc, 11),
|
|
1921
|
+
timeoutMs
|
|
1922
|
+
});
|
|
1923
|
+
const ansi = new Array(16).fill(null);
|
|
1924
|
+
let filled = 0;
|
|
1925
|
+
const oscPrefix = `${ESC$2}]4;`;
|
|
1926
|
+
let burstQuery = "";
|
|
1927
|
+
for (let i = 0; i < 16; i++) burstQuery += `${ESC$2}]4;${i};?${BEL}`;
|
|
1928
|
+
await input.probe({
|
|
1929
|
+
query: burstQuery,
|
|
1930
|
+
parse: (acc) => {
|
|
1931
|
+
let pos = 0;
|
|
1932
|
+
while (pos < acc.length) {
|
|
1933
|
+
const next = acc.indexOf(oscPrefix, pos);
|
|
1934
|
+
if (next === -1) break;
|
|
1935
|
+
let end = acc.indexOf(BEL, next);
|
|
1936
|
+
let termLen = 1;
|
|
1937
|
+
if (end === -1) {
|
|
1938
|
+
end = acc.indexOf(`${ESC$2}\\`, next);
|
|
1939
|
+
termLen = 2;
|
|
1940
|
+
if (end === -1) break;
|
|
1941
|
+
}
|
|
1942
|
+
const parsed = parsePaletteResponse(acc.slice(next, end + termLen));
|
|
1943
|
+
if (parsed && parsed.index >= 0 && parsed.index < 16 && ansi[parsed.index] == null) {
|
|
1944
|
+
ansi[parsed.index] = parsed.color;
|
|
1945
|
+
filled++;
|
|
1946
|
+
}
|
|
1947
|
+
pos = end + termLen;
|
|
1948
|
+
}
|
|
1949
|
+
if (filled === 16) return {
|
|
1950
|
+
result: true,
|
|
1951
|
+
consumed: acc.length
|
|
1952
|
+
};
|
|
1953
|
+
return null;
|
|
1954
|
+
},
|
|
1955
|
+
timeoutMs
|
|
1956
|
+
});
|
|
1957
|
+
const dark = bg ? isDarkColor(bg) : true;
|
|
1958
|
+
const palette = { dark };
|
|
1959
|
+
if (bg) palette.background = bg;
|
|
1960
|
+
if (fg) palette.foreground = fg;
|
|
1961
|
+
const ansiFields = [
|
|
1962
|
+
"black",
|
|
1963
|
+
"red",
|
|
1964
|
+
"green",
|
|
1965
|
+
"yellow",
|
|
1966
|
+
"blue",
|
|
1967
|
+
"magenta",
|
|
1968
|
+
"cyan",
|
|
1969
|
+
"white",
|
|
1970
|
+
"brightBlack",
|
|
1971
|
+
"brightRed",
|
|
1972
|
+
"brightGreen",
|
|
1973
|
+
"brightYellow",
|
|
1974
|
+
"brightBlue",
|
|
1975
|
+
"brightMagenta",
|
|
1976
|
+
"brightCyan",
|
|
1977
|
+
"brightWhite"
|
|
1978
|
+
];
|
|
1979
|
+
for (let i = 0; i < 16; i++) if (ansi[i]) palette[ansiFields[i]] = ansi[i];
|
|
1980
|
+
if (fg) palette.cursorColor = fg;
|
|
1981
|
+
if (bg) palette.cursorText = bg;
|
|
1982
|
+
if (fg == null && bg == null && filled === 0) return null;
|
|
1983
|
+
return {
|
|
1984
|
+
fg,
|
|
1985
|
+
bg,
|
|
1986
|
+
ansi,
|
|
1987
|
+
dark,
|
|
1988
|
+
palette
|
|
1989
|
+
};
|
|
1990
|
+
}
|
|
1991
|
+
async function detectTheme(opts = {}) {
|
|
1992
|
+
const colorLevel = opts.caps?.colorLevel;
|
|
1993
|
+
if (colorLevel === "mono" || colorLevel === "ansi16") return opts.caps?.darkBackground ?? true ? ansi16DarkTheme : ansi16LightTheme;
|
|
1994
|
+
const detected = await probeColors({
|
|
1995
|
+
timeoutMs: opts.timeoutMs,
|
|
1996
|
+
input: opts.input
|
|
1997
|
+
});
|
|
1998
|
+
const isDark = detected?.dark ?? opts.caps?.darkBackground ?? true;
|
|
1999
|
+
const fallback = opts.fallback ?? (isDark ? opts.fallbackDark ?? defaultDarkScheme : opts.fallbackLight ?? defaultLightScheme);
|
|
2000
|
+
if (!detected) return deriveTheme(fallback);
|
|
2001
|
+
return deriveTheme({
|
|
2002
|
+
...fallback,
|
|
2003
|
+
...stripNulls$1(detected.palette)
|
|
2004
|
+
});
|
|
2005
|
+
}
|
|
2006
|
+
function stripNulls$1(partial) {
|
|
2007
|
+
const result = {};
|
|
2008
|
+
for (const [k, v] of Object.entries(partial)) if (v != null) result[k] = v;
|
|
2009
|
+
return result;
|
|
2010
|
+
}
|
|
2011
|
+
function isDarkColor(hex) {
|
|
2012
|
+
const r = parseInt(hex.slice(1, 3), 16) / 255;
|
|
2013
|
+
const g = parseInt(hex.slice(3, 5), 16) / 255;
|
|
2014
|
+
const b = parseInt(hex.slice(5, 7), 16) / 255;
|
|
2015
|
+
return .2126 * r + .7152 * g + .0722 * b <= .5;
|
|
2016
|
+
}
|
|
2017
|
+
var ESC$2, BEL, RGB_BODY_RE, detectTerminalScheme;
|
|
2018
|
+
var init_detect = __esmMin((() => {
|
|
2019
|
+
init_derive();
|
|
2020
|
+
init_default_schemes();
|
|
2021
|
+
init_osc_palette();
|
|
2022
|
+
init_osc_colors();
|
|
2023
|
+
ESC$2 = "\x1B";
|
|
2024
|
+
BEL = "\x07";
|
|
2025
|
+
RGB_BODY_RE = /rgb:([0-9a-fA-F]{1,4})\/([0-9a-fA-F]{1,4})\/([0-9a-fA-F]{1,4})/;
|
|
2026
|
+
detectTerminalScheme = probeColors;
|
|
2027
|
+
}));
|
|
2028
|
+
//#endregion
|
|
2029
|
+
//#region packages/ansi/src/color-maps.ts
|
|
2030
|
+
/** Find nearest ANSI 16 color index for an RGB value. */
|
|
2031
|
+
function nearestAnsi16(r, g, b) {
|
|
2032
|
+
let bestIdx = 0;
|
|
2033
|
+
let bestDist = Infinity;
|
|
2034
|
+
for (let i = 0; i < 16; i++) {
|
|
2035
|
+
const [cr, cg, cb] = ANSI_16_COLORS[i];
|
|
2036
|
+
const dist = (r - cr) ** 2 + (g - cg) ** 2 + (b - cb) ** 2;
|
|
2037
|
+
if (dist < bestDist) {
|
|
2038
|
+
bestDist = dist;
|
|
2039
|
+
bestIdx = i;
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
return bestIdx;
|
|
2043
|
+
}
|
|
2044
|
+
/** Convert RGB to 256-color index (using the 6x6x6 color cube). */
|
|
2045
|
+
function rgbToAnsi256(r, g, b) {
|
|
2046
|
+
if (r === g && g === b) {
|
|
2047
|
+
if (r < 8) return 16;
|
|
2048
|
+
if (r > 248) return 231;
|
|
2049
|
+
return Math.round((r - 8) / 247 * 24) + 232;
|
|
2050
|
+
}
|
|
2051
|
+
const ri = Math.round(r / 255 * 5);
|
|
2052
|
+
const gi = Math.round(g / 255 * 5);
|
|
2053
|
+
const bi = Math.round(b / 255 * 5);
|
|
2054
|
+
return 16 + 36 * ri + 6 * gi + bi;
|
|
2055
|
+
}
|
|
2056
|
+
/**
|
|
2057
|
+
* Generate SGR foreground code for an RGB color at the given color tier.
|
|
2058
|
+
* Returns the SGR parameter string (e.g., "31" or "38;5;196" or "38;2;255;0;0").
|
|
2059
|
+
*
|
|
2060
|
+
* Tiers `"truecolor"`, `"256"`, and `"ansi16"` emit color codes. `"mono"`
|
|
2061
|
+
* is handled by the caller (no SGR code is emitted for color at the mono tier)
|
|
2062
|
+
* — this function coerces `"mono"` to the `"ansi16"` code path rather than
|
|
2063
|
+
* throwing, since callers that get here with `"mono"` have already bypassed
|
|
2064
|
+
* the mono short-circuit.
|
|
2065
|
+
*/
|
|
2066
|
+
function fgFromRgb(r, g, b, tier) {
|
|
2067
|
+
if (tier === "truecolor") return `38;2;${r};${g};${b}`;
|
|
2068
|
+
if (tier === "256") return `38;5;${rgbToAnsi256(r, g, b)}`;
|
|
2069
|
+
const idx = nearestAnsi16(r, g, b);
|
|
2070
|
+
return idx < 8 ? `${30 + idx}` : `${82 + idx}`;
|
|
2071
|
+
}
|
|
2072
|
+
/**
|
|
2073
|
+
* Generate SGR background code for an RGB color at the given color tier.
|
|
2074
|
+
* See {@link fgFromRgb} for tier handling.
|
|
2075
|
+
*/
|
|
2076
|
+
function bgFromRgb(r, g, b, tier) {
|
|
2077
|
+
if (tier === "truecolor") return `48;2;${r};${g};${b}`;
|
|
2078
|
+
if (tier === "256") return `48;5;${rgbToAnsi256(r, g, b)}`;
|
|
2079
|
+
const idx = nearestAnsi16(r, g, b);
|
|
2080
|
+
return idx < 8 ? `${40 + idx}` : `${92 + idx}`;
|
|
2081
|
+
}
|
|
2082
|
+
/**
|
|
2083
|
+
* Convert a 256-palette index back to its canonical xterm hex value.
|
|
2084
|
+
*
|
|
2085
|
+
* Mirrors `rgbToAnsi256`:
|
|
2086
|
+
* - 16–231: 6×6×6 color cube. Index = 16 + 36·r + 6·g + b (each channel 0..5).
|
|
2087
|
+
* - 232–255: 24-step grayscale ramp.
|
|
2088
|
+
* - 0–15: ANSI 16 slots (reuses ANSI16_SLOT_HEX for exact parity with
|
|
2089
|
+
* `nearestAnsi16`).
|
|
2090
|
+
*/
|
|
2091
|
+
function ansi256ToHex(idx) {
|
|
2092
|
+
if (idx < 0 || idx > 255 || !Number.isInteger(idx)) return "#000000";
|
|
2093
|
+
if (idx < 16) {
|
|
2094
|
+
const [r, g, b] = ANSI_16_COLORS[idx];
|
|
2095
|
+
return rgbToHexHash(r, g, b);
|
|
2096
|
+
}
|
|
2097
|
+
if (idx < 232) {
|
|
2098
|
+
const levels = [
|
|
2099
|
+
0,
|
|
2100
|
+
95,
|
|
2101
|
+
135,
|
|
2102
|
+
175,
|
|
2103
|
+
215,
|
|
2104
|
+
255
|
|
2105
|
+
];
|
|
2106
|
+
const i = idx - 16;
|
|
2107
|
+
const r = levels[Math.floor(i / 36)];
|
|
2108
|
+
const g = levels[Math.floor(i % 36 / 6)];
|
|
2109
|
+
const b = levels[i % 6];
|
|
2110
|
+
return rgbToHexHash(r, g, b);
|
|
2111
|
+
}
|
|
2112
|
+
const gray = 8 + (idx - 232) * 10;
|
|
2113
|
+
return rgbToHexHash(gray, gray, gray);
|
|
2114
|
+
}
|
|
2115
|
+
function rgbToHexHash(r, g, b) {
|
|
2116
|
+
const h = (n) => n.toString(16).padStart(2, "0");
|
|
2117
|
+
return `#${h(r)}${h(g)}${h(b)}`;
|
|
2118
|
+
}
|
|
2119
|
+
function parseHexLocal(hex) {
|
|
2120
|
+
if (typeof hex !== "string") return null;
|
|
2121
|
+
let s = hex.trim();
|
|
2122
|
+
if (s.startsWith("#")) s = s.slice(1);
|
|
2123
|
+
if (s.length === 3) s = s.split("").map((c) => c + c).join("");
|
|
2124
|
+
if (s.length !== 6) return null;
|
|
2125
|
+
const r = parseInt(s.slice(0, 2), 16);
|
|
2126
|
+
const g = parseInt(s.slice(2, 4), 16);
|
|
2127
|
+
const b = parseInt(s.slice(4, 6), 16);
|
|
2128
|
+
if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) return null;
|
|
2129
|
+
return [
|
|
2130
|
+
r,
|
|
2131
|
+
g,
|
|
2132
|
+
b
|
|
2133
|
+
];
|
|
2134
|
+
}
|
|
2135
|
+
/**
|
|
2136
|
+
* Hex-in / hex-out quantization for previews.
|
|
2137
|
+
*
|
|
2138
|
+
* Takes any hex color and returns the hex a real terminal at that tier would
|
|
2139
|
+
* actually emit. Used by the Sterling storybook to make the `1/2/3/4` tier
|
|
2140
|
+
* toggle visibly different in-process — the output phase already does this
|
|
2141
|
+
* when writing to a real TTY, but preview surfaces (theme swatches, rendered
|
|
2142
|
+
* components inside a storybook app) bypass output-phase quantization. Apply
|
|
2143
|
+
* `quantizeHex` at render time to mimic tier-specific terminal output.
|
|
2144
|
+
*
|
|
2145
|
+
* - `truecolor`: returns the input unchanged (normalized to `#rrggbb`).
|
|
2146
|
+
* - `256`: snaps to the nearest xterm-256 slot, then returns that slot's hex.
|
|
2147
|
+
* - `ansi16`: snaps to one of the 16 standard slots (canonical xterm RGB).
|
|
2148
|
+
* - `mono`: luminance threshold (>= 0.5 → `#ffffff`, else `#000000`).
|
|
2149
|
+
*
|
|
2150
|
+
* Returns the input unchanged if it cannot be parsed as a hex color.
|
|
2151
|
+
*/
|
|
2152
|
+
function quantizeHex(hex, tier) {
|
|
2153
|
+
const rgb = parseHexLocal(hex);
|
|
2154
|
+
if (!rgb) return hex;
|
|
2155
|
+
const [r, g, b] = rgb;
|
|
2156
|
+
if (tier === "truecolor") return rgbToHexHash(r, g, b);
|
|
2157
|
+
if (tier === "256") return ansi256ToHex(rgbToAnsi256(r, g, b));
|
|
2158
|
+
if (tier === "ansi16") {
|
|
2159
|
+
const [cr, cg, cb] = ANSI_16_COLORS[nearestAnsi16(r, g, b)];
|
|
2160
|
+
return rgbToHexHash(cr, cg, cb);
|
|
2161
|
+
}
|
|
2162
|
+
return (.2126 * r + .7152 * g + .0722 * b) / 255 >= .5 ? "#ffffff" : "#000000";
|
|
2163
|
+
}
|
|
2164
|
+
function isHexLeaf$1(value) {
|
|
2165
|
+
return typeof value === "string" && HEX_LEAF_RE$1.test(value);
|
|
2166
|
+
}
|
|
2167
|
+
/**
|
|
2168
|
+
* Pre-quantize every hex leaf in a Theme (or any object tree) to the
|
|
2169
|
+
* requested color tier.
|
|
2170
|
+
*
|
|
2171
|
+
* Walks the input recursively — each string leaf matching `#rgb` / `#rrggbb`
|
|
2172
|
+
* is passed through {@link quantizeHex}; all other values (numbers, booleans,
|
|
2173
|
+
* non-hex strings like `"Nord"`, null/undefined, arrays of non-hex values)
|
|
2174
|
+
* pass through unchanged. Arrays and nested objects are rebuilt with
|
|
2175
|
+
* quantized leaves.
|
|
2176
|
+
*
|
|
2177
|
+
* Works on both the legacy ANSI Theme (flat hex tokens + `palette` array)
|
|
2178
|
+
* and the Sterling Theme (nested roles + flat tokens) — the structural rule
|
|
2179
|
+
* "any leaf that looks like a hex is a color value" holds for both.
|
|
2180
|
+
*
|
|
2181
|
+
* @example Pre-cache tier variants
|
|
2182
|
+
* ```ts
|
|
2183
|
+
* import { pickColorLevel } from "silvery"
|
|
2184
|
+
*
|
|
2185
|
+
* const themes = {
|
|
2186
|
+
* truecolor: theme,
|
|
2187
|
+
* ansi16: pickColorLevel(theme, "ansi16"),
|
|
2188
|
+
* mono: pickColorLevel(theme, "mono"),
|
|
2189
|
+
* }
|
|
2190
|
+
* ```
|
|
2191
|
+
*
|
|
2192
|
+
* @example Storybook — show multiple tiers simultaneously
|
|
2193
|
+
* ```tsx
|
|
2194
|
+
* <ThemeProvider theme={pickColorLevel(theme, "ansi16")}>
|
|
2195
|
+
* <AlertPreview />
|
|
2196
|
+
* </ThemeProvider>
|
|
2197
|
+
* ```
|
|
2198
|
+
*
|
|
2199
|
+
* Notes:
|
|
2200
|
+
* - `truecolor` is a no-op — returns the input unchanged (identity).
|
|
2201
|
+
* - The result is structurally identical to the input (same keys, same
|
|
2202
|
+
* nesting); only hex leaves are remapped.
|
|
2203
|
+
* - Idempotent per tier: `pickColorLevel(pickColorLevel(t, "ansi16"), "ansi16")`
|
|
2204
|
+
* yields the same hex values as `pickColorLevel(t, "ansi16")`.
|
|
2205
|
+
* - Does not freeze the returned object. Callers that want immutability
|
|
2206
|
+
* should `Object.freeze()` (or deep-freeze) the result themselves.
|
|
2207
|
+
*/
|
|
2208
|
+
function pickColorLevel(theme, tier) {
|
|
2209
|
+
if (tier === "truecolor") return theme;
|
|
2210
|
+
return pickColorLevelWalk(theme, tier);
|
|
2211
|
+
}
|
|
2212
|
+
function pickColorLevelWalk(obj, tier) {
|
|
2213
|
+
if (obj == null) return obj;
|
|
2214
|
+
if (isHexLeaf$1(obj)) return quantizeHex(obj, tier);
|
|
2215
|
+
if (Array.isArray(obj)) return obj.map((v) => pickColorLevelWalk(v, tier));
|
|
2216
|
+
if (typeof obj === "object") {
|
|
2217
|
+
const out = {};
|
|
2218
|
+
for (const [k, v] of Object.entries(obj)) out[k] = pickColorLevelWalk(v, tier);
|
|
2219
|
+
return out;
|
|
2220
|
+
}
|
|
2221
|
+
return obj;
|
|
2222
|
+
}
|
|
2223
|
+
var MODIFIERS, FG_COLORS, BG_COLORS, ANSI_16_COLORS, ANSI16_SLOT_HEX, HEX_LEAF_RE$1;
|
|
2224
|
+
var init_color_maps = __esmMin((() => {
|
|
2225
|
+
MODIFIERS = {
|
|
2226
|
+
reset: [0, 0],
|
|
2227
|
+
bold: [1, 22],
|
|
2228
|
+
dim: [2, 22],
|
|
2229
|
+
italic: [3, 23],
|
|
2230
|
+
underline: [4, 24],
|
|
2231
|
+
inverse: [7, 27],
|
|
2232
|
+
hidden: [8, 28],
|
|
2233
|
+
strikethrough: [9, 29],
|
|
2234
|
+
overline: [53, 55]
|
|
2235
|
+
};
|
|
2236
|
+
FG_COLORS = {
|
|
2237
|
+
black: 30,
|
|
2238
|
+
red: 31,
|
|
2239
|
+
green: 32,
|
|
2240
|
+
yellow: 33,
|
|
2241
|
+
blue: 34,
|
|
2242
|
+
magenta: 35,
|
|
2243
|
+
cyan: 36,
|
|
2244
|
+
white: 37,
|
|
2245
|
+
blackBright: 90,
|
|
2246
|
+
gray: 90,
|
|
2247
|
+
grey: 90,
|
|
2248
|
+
redBright: 91,
|
|
2249
|
+
greenBright: 92,
|
|
2250
|
+
yellowBright: 93,
|
|
2251
|
+
blueBright: 94,
|
|
2252
|
+
magentaBright: 95,
|
|
2253
|
+
cyanBright: 96,
|
|
2254
|
+
whiteBright: 97
|
|
2255
|
+
};
|
|
2256
|
+
BG_COLORS = {
|
|
2257
|
+
bgBlack: 40,
|
|
2258
|
+
bgRed: 41,
|
|
2259
|
+
bgGreen: 42,
|
|
2260
|
+
bgYellow: 43,
|
|
2261
|
+
bgBlue: 44,
|
|
2262
|
+
bgMagenta: 45,
|
|
2263
|
+
bgCyan: 46,
|
|
2264
|
+
bgWhite: 47,
|
|
2265
|
+
bgBlackBright: 100,
|
|
2266
|
+
bgGray: 100,
|
|
2267
|
+
bgGrey: 100,
|
|
2268
|
+
bgRedBright: 101,
|
|
2269
|
+
bgGreenBright: 102,
|
|
2270
|
+
bgYellowBright: 103,
|
|
2271
|
+
bgBlueBright: 104,
|
|
2272
|
+
bgMagentaBright: 105,
|
|
2273
|
+
bgCyanBright: 106,
|
|
2274
|
+
bgWhiteBright: 107
|
|
2275
|
+
};
|
|
2276
|
+
ANSI_16_COLORS = [
|
|
2277
|
+
[
|
|
2278
|
+
0,
|
|
2279
|
+
0,
|
|
2280
|
+
0
|
|
2281
|
+
],
|
|
2282
|
+
[
|
|
2283
|
+
128,
|
|
2284
|
+
0,
|
|
2285
|
+
0
|
|
2286
|
+
],
|
|
2287
|
+
[
|
|
2288
|
+
0,
|
|
2289
|
+
128,
|
|
2290
|
+
0
|
|
2291
|
+
],
|
|
2292
|
+
[
|
|
2293
|
+
128,
|
|
2294
|
+
128,
|
|
2295
|
+
0
|
|
2296
|
+
],
|
|
2297
|
+
[
|
|
2298
|
+
0,
|
|
2299
|
+
0,
|
|
2300
|
+
128
|
|
2301
|
+
],
|
|
2302
|
+
[
|
|
2303
|
+
128,
|
|
2304
|
+
0,
|
|
2305
|
+
128
|
|
2306
|
+
],
|
|
2307
|
+
[
|
|
2308
|
+
0,
|
|
2309
|
+
128,
|
|
2310
|
+
128
|
|
2311
|
+
],
|
|
2312
|
+
[
|
|
2313
|
+
192,
|
|
2314
|
+
192,
|
|
2315
|
+
192
|
|
2316
|
+
],
|
|
2317
|
+
[
|
|
2318
|
+
128,
|
|
2319
|
+
128,
|
|
2320
|
+
128
|
|
2321
|
+
],
|
|
2322
|
+
[
|
|
2323
|
+
255,
|
|
2324
|
+
0,
|
|
2325
|
+
0
|
|
2326
|
+
],
|
|
2327
|
+
[
|
|
2328
|
+
0,
|
|
2329
|
+
255,
|
|
2330
|
+
0
|
|
2331
|
+
],
|
|
2332
|
+
[
|
|
2333
|
+
255,
|
|
2334
|
+
255,
|
|
2335
|
+
0
|
|
2336
|
+
],
|
|
2337
|
+
[
|
|
2338
|
+
0,
|
|
2339
|
+
0,
|
|
2340
|
+
255
|
|
2341
|
+
],
|
|
2342
|
+
[
|
|
2343
|
+
255,
|
|
2344
|
+
0,
|
|
2345
|
+
255
|
|
2346
|
+
],
|
|
2347
|
+
[
|
|
2348
|
+
0,
|
|
2349
|
+
255,
|
|
2350
|
+
255
|
|
2351
|
+
],
|
|
2352
|
+
[
|
|
2353
|
+
255,
|
|
2354
|
+
255,
|
|
2355
|
+
255
|
|
2356
|
+
]
|
|
2357
|
+
];
|
|
2358
|
+
ANSI16_SLOT_HEX = {
|
|
2359
|
+
black: "#000000",
|
|
2360
|
+
red: "#800000",
|
|
2361
|
+
green: "#008000",
|
|
2362
|
+
yellow: "#808000",
|
|
2363
|
+
blue: "#000080",
|
|
2364
|
+
magenta: "#800080",
|
|
2365
|
+
cyan: "#008080",
|
|
2366
|
+
white: "#c0c0c0",
|
|
2367
|
+
blackBright: "#808080",
|
|
2368
|
+
gray: "#808080",
|
|
2369
|
+
grey: "#808080",
|
|
2370
|
+
redBright: "#ff0000",
|
|
2371
|
+
greenBright: "#00ff00",
|
|
2372
|
+
yellowBright: "#ffff00",
|
|
2373
|
+
blueBright: "#0000ff",
|
|
2374
|
+
magentaBright: "#ff00ff",
|
|
2375
|
+
cyanBright: "#00ffff",
|
|
2376
|
+
whiteBright: "#ffffff"
|
|
2377
|
+
};
|
|
2378
|
+
HEX_LEAF_RE$1 = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/;
|
|
2379
|
+
}));
|
|
2380
|
+
//#endregion
|
|
2381
|
+
//#region packages/ansi/src/profile.ts
|
|
2382
|
+
/**
|
|
2383
|
+
* Build a {@link TerminalProfile} from the current environment.
|
|
2384
|
+
*
|
|
2385
|
+
* Priority for the final `colorLevel` (highest wins):
|
|
2386
|
+
* 1. `NO_COLOR` env var → `"mono"`
|
|
2387
|
+
* 2. `FORCE_COLOR` env var → `0/false → mono, 1 → ansi16, 2 → 256, 3 → truecolor`
|
|
2388
|
+
* 3. `options.colorLevel` (caller-supplied explicit tier)
|
|
2389
|
+
* 4. `options.caps.colorLevel` (base caps' pre-detected tier)
|
|
2390
|
+
* 5. Auto-detected tier from env (TERM, COLORTERM, TERM_PROGRAM, …)
|
|
2391
|
+
*
|
|
2392
|
+
* The env-var precedence (1 & 2) matches the existing `detectColor()` semantics
|
|
2393
|
+
* and is observed on every silvery entry point — tests pass with explicit
|
|
2394
|
+
* env vars even when a caller forces a tier via `colorLevel`.
|
|
2395
|
+
*
|
|
2396
|
+
* When `options.caps` is provided, the profile treats those as the base
|
|
2397
|
+
* capabilities and skips the env-based caps detection — only the color tier
|
|
2398
|
+
* is resolved through the precedence chain above. When `options.caps` is
|
|
2399
|
+
* absent, the full `detectTerminalProfileFromEnv` pass runs.
|
|
2400
|
+
*
|
|
2401
|
+
* No I/O beyond whatever `detectTerminalCaps()` already does (a `defaults read`
|
|
2402
|
+
* call on macOS for Apple Terminal dark-mode heuristics — cached).
|
|
2403
|
+
*
|
|
2404
|
+
* @example
|
|
2405
|
+
* ```ts
|
|
2406
|
+
* // Auto-detect from process.env + process.stdout
|
|
2407
|
+
* const profile = createTerminalProfile()
|
|
2408
|
+
* console.log(profile.colorLevel) // "truecolor" on Ghostty
|
|
2409
|
+
*
|
|
2410
|
+
* // Force a tier (still honors NO_COLOR / FORCE_COLOR env precedence)
|
|
2411
|
+
* const forced = createTerminalProfile({ colorLevel: "256" })
|
|
2412
|
+
*
|
|
2413
|
+
* // Term path — base caps already detected, just resolve color tier.
|
|
2414
|
+
* const termProfile = createTerminalProfile({
|
|
2415
|
+
* colorLevel: userColorLevel,
|
|
2416
|
+
* caps: term.caps,
|
|
2417
|
+
* })
|
|
2418
|
+
*
|
|
2419
|
+
* // Headless/test fixture — zero env influence
|
|
2420
|
+
* const fake = createTerminalProfile({
|
|
2421
|
+
* env: {},
|
|
2422
|
+
* stdout: { isTTY: true },
|
|
2423
|
+
* colorLevel: "truecolor",
|
|
2424
|
+
* })
|
|
2425
|
+
* ```
|
|
2426
|
+
*/
|
|
2427
|
+
function createTerminalProfile(options = {}) {
|
|
2428
|
+
const env = options.env ?? process.env;
|
|
2429
|
+
const stdout = options.stdout ?? process.stdout;
|
|
2430
|
+
const stdin = "stdin" in options ? options.stdin : process.stdin;
|
|
2431
|
+
const envTier = envColorTier(env);
|
|
2432
|
+
const overrideTier = options.colorLevel === null ? "mono" : options.colorLevel ?? void 0;
|
|
2433
|
+
const baseCapsTier = options.caps?.colorLevel;
|
|
2434
|
+
let resolvedTier;
|
|
2435
|
+
let colorProvenance;
|
|
2436
|
+
if (envTier !== void 0) {
|
|
2437
|
+
resolvedTier = envTier;
|
|
2438
|
+
colorProvenance = "env";
|
|
2439
|
+
} else if (overrideTier !== void 0) {
|
|
2440
|
+
resolvedTier = overrideTier;
|
|
2441
|
+
colorProvenance = "override";
|
|
2442
|
+
} else if (baseCapsTier !== void 0) {
|
|
2443
|
+
resolvedTier = baseCapsTier;
|
|
2444
|
+
colorProvenance = "caller-caps";
|
|
2445
|
+
} else {
|
|
2446
|
+
resolvedTier = detectColorFromEnv(env, stdout);
|
|
2447
|
+
colorProvenance = "auto";
|
|
2448
|
+
}
|
|
2449
|
+
const detected = options.caps ? void 0 : detectTerminalProfileFromEnv(env, stdout);
|
|
2450
|
+
const baseCaps = options.caps ? {
|
|
2451
|
+
...defaultCaps(),
|
|
2452
|
+
...options.caps
|
|
2453
|
+
} : detected.caps;
|
|
2454
|
+
const baseEmulator = options.emulator ? {
|
|
2455
|
+
...defaultEmulator(),
|
|
2456
|
+
...options.emulator
|
|
2457
|
+
} : detected?.emulator ?? defaultEmulator();
|
|
2458
|
+
const inputResolved = options.caps?.input ?? (stdin?.isTTY === true && typeof stdin.setRawMode === "function");
|
|
2459
|
+
return freezeProfileInDev({
|
|
2460
|
+
emulator: baseEmulator,
|
|
2461
|
+
caps: {
|
|
2462
|
+
...baseCaps,
|
|
2463
|
+
colorLevel: resolvedTier,
|
|
2464
|
+
colorForced: colorProvenance === "env" || colorProvenance === "override",
|
|
2465
|
+
colorProvenance,
|
|
2466
|
+
input: inputResolved
|
|
2467
|
+
},
|
|
2468
|
+
colorLevel: resolvedTier
|
|
2469
|
+
});
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* Freeze a profile (plus its nested caps / emulator) in dev builds so
|
|
2473
|
+
* `profile.colorLevel === profile.caps.colorLevel` and every other invariant
|
|
2474
|
+
* can't silently drift via direct mutation. Production builds skip the
|
|
2475
|
+
* freeze to keep the allocation cheap; the type-level `readonly` fields
|
|
2476
|
+
* already block TS-side writes.
|
|
2477
|
+
*
|
|
2478
|
+
* Per km-silvery.profile-immutable (/pro review 2026-04-23): profiles are
|
|
2479
|
+
* snapshot values by contract. Any caller that needs to "change" a profile
|
|
2480
|
+
* must build a new one — the plateau-era single-source-of-truth guarantee
|
|
2481
|
+
* leans on this.
|
|
2482
|
+
*/
|
|
2483
|
+
function freezeProfileInDev(profile) {
|
|
2484
|
+
if (process.env.NODE_ENV === "production") return profile;
|
|
2485
|
+
Object.freeze(profile.caps);
|
|
2486
|
+
Object.freeze(profile.emulator);
|
|
2487
|
+
Object.freeze(profile);
|
|
2488
|
+
return profile;
|
|
2489
|
+
}
|
|
2490
|
+
/**
|
|
2491
|
+
* Build a {@link TerminalProfile} with an OSC-detected `theme` bundled in.
|
|
2492
|
+
*
|
|
2493
|
+
* Async because the theme probe writes OSC queries to stdout and waits for
|
|
2494
|
+
* responses on stdin. This is the Phase-H2 variant of
|
|
2495
|
+
* {@link createTerminalProfile} — everything the sync factory does, plus:
|
|
2496
|
+
*
|
|
2497
|
+
* 1. Run `detectTheme` (OSC 4/10/11 probe with fallback) once.
|
|
2498
|
+
* 2. Pre-quantize the resulting theme via {@link pickColorLevel} when the
|
|
2499
|
+
* tier was forced ({@link TerminalCaps.colorForced} is `true`) so
|
|
2500
|
+
* token hex values match what the pipeline will actually emit.
|
|
2501
|
+
* 3. Return the profile with `theme` populated — one detection, one profile
|
|
2502
|
+
* flowing end-to-end through run() / createApp().
|
|
2503
|
+
*
|
|
2504
|
+
* Call sites previously ran `createTerminalProfile(...)` + `detectTheme(...)`
|
|
2505
|
+
* + `pickColorLevel(...)` as three separate steps on both the Term-path and
|
|
2506
|
+
* options-path branches. Collapsing that into one function removes the
|
|
2507
|
+
* duplication and the possibility of the three views disagreeing about
|
|
2508
|
+
* what was forced.
|
|
2509
|
+
*
|
|
2510
|
+
* When `probeTheme` is `false`, behaves like the sync {@link createTerminalProfile}
|
|
2511
|
+
* but wrapped in a Promise — useful for call sites that want uniform async
|
|
2512
|
+
* treatment regardless of whether a probe is needed.
|
|
2513
|
+
*
|
|
2514
|
+
* @example
|
|
2515
|
+
* ```ts
|
|
2516
|
+
* // Node entry point with TUI-safe probing.
|
|
2517
|
+
* const profile = await probeTerminalProfile({
|
|
2518
|
+
* colorLevel: options.colorLevel,
|
|
2519
|
+
* caps: term.profile.caps,
|
|
2520
|
+
* fallbackDark: nord,
|
|
2521
|
+
* fallbackLight: catppuccinLatte,
|
|
2522
|
+
* input: probeOwner, // structural InputOwner from @silvery/ag-term
|
|
2523
|
+
* })
|
|
2524
|
+
* // profile.caps, profile.colorLevel, profile.caps.colorForced, profile.theme
|
|
2525
|
+
* ```
|
|
2526
|
+
*
|
|
2527
|
+
* @see createTerminalProfile — sync variant, no theme probe
|
|
2528
|
+
* @see DetectThemeOptions — the underlying probe options this wraps
|
|
2529
|
+
*/
|
|
2530
|
+
async function probeTerminalProfile(options = {}) {
|
|
2531
|
+
const profile = createTerminalProfile(options);
|
|
2532
|
+
if (options.probeTheme === false) return profile;
|
|
2533
|
+
const theme = await detectTheme({
|
|
2534
|
+
caps: profile.caps,
|
|
2535
|
+
fallbackDark: options.fallbackDark,
|
|
2536
|
+
fallbackLight: options.fallbackLight,
|
|
2537
|
+
timeoutMs: options.timeoutMs,
|
|
2538
|
+
input: options.input
|
|
2539
|
+
});
|
|
2540
|
+
const resolvedTheme = profile.caps.colorForced ? pickColorLevel(theme, profile.colorLevel) : theme;
|
|
2541
|
+
return freezeProfileInDev({
|
|
2542
|
+
...profile,
|
|
2543
|
+
theme: resolvedTheme
|
|
2544
|
+
});
|
|
2545
|
+
}
|
|
2546
|
+
/**
|
|
2547
|
+
* Deterministic variant of {@link detectColor} that takes env+stdout as args.
|
|
2548
|
+
* Exported-internal so the shim `detectColor()` can delegate without reading
|
|
2549
|
+
* `process.env` twice.
|
|
2550
|
+
*/
|
|
2551
|
+
function detectColorFromEnv(env, stdout) {
|
|
2552
|
+
if (env.NO_COLOR !== void 0) return "mono";
|
|
2553
|
+
const forceColor = env.FORCE_COLOR;
|
|
2554
|
+
if (forceColor !== void 0) {
|
|
2555
|
+
if (forceColor === "0" || forceColor === "false") return "mono";
|
|
2556
|
+
if (forceColor === "1") return "ansi16";
|
|
2557
|
+
if (forceColor === "2") return "256";
|
|
2558
|
+
if (forceColor === "3") return "truecolor";
|
|
2559
|
+
return "ansi16";
|
|
2560
|
+
}
|
|
2561
|
+
if (!stdout.isTTY) return "mono";
|
|
2562
|
+
if (env.TERM === "dumb") return "mono";
|
|
2563
|
+
const colorTerm = env.COLORTERM;
|
|
2564
|
+
if (colorTerm === "truecolor" || colorTerm === "24bit") return "truecolor";
|
|
2565
|
+
const term = env.TERM ?? "";
|
|
2566
|
+
if (term.includes("truecolor") || term.includes("24bit") || term.includes("xterm-ghostty") || term.includes("xterm-kitty") || term.includes("wezterm")) return "truecolor";
|
|
2567
|
+
if (term.includes("256color") || term.includes("256")) return "256";
|
|
2568
|
+
const termProgram = env.TERM_PROGRAM;
|
|
2569
|
+
if (termProgram === "iTerm.app" || termProgram === "Apple_Terminal") return termProgram === "iTerm.app" ? "truecolor" : "256";
|
|
2570
|
+
if (termProgram === "Ghostty" || termProgram === "WezTerm") return "truecolor";
|
|
2571
|
+
if (env.KITTY_WINDOW_ID) return "truecolor";
|
|
2572
|
+
if (term.includes("xterm") || term.includes("color") || term.includes("ansi")) return "ansi16";
|
|
2573
|
+
if (CI_ENVS.some((name) => env[name] !== void 0)) return "ansi16";
|
|
2574
|
+
if (env.WT_SESSION) return "truecolor";
|
|
2575
|
+
return "ansi16";
|
|
2576
|
+
}
|
|
2577
|
+
/**
|
|
2578
|
+
* Env-only FORCE_COLOR / NO_COLOR tier probe. Returns `undefined` when no
|
|
2579
|
+
* env override applies. Used by {@link createTerminalProfile} to enforce that
|
|
2580
|
+
* env always beats caller-supplied overrides.
|
|
2581
|
+
*/
|
|
2582
|
+
function envColorTier(env) {
|
|
2583
|
+
if (env.NO_COLOR !== void 0) return "mono";
|
|
2584
|
+
const force = env.FORCE_COLOR;
|
|
2585
|
+
if (force !== void 0) {
|
|
2586
|
+
if (force === "0" || force === "false") return "mono";
|
|
2587
|
+
if (force === "1") return "ansi16";
|
|
2588
|
+
if (force === "2") return "256";
|
|
2589
|
+
if (force === "3") return "truecolor";
|
|
2590
|
+
return "ansi16";
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
/**
|
|
2594
|
+
* Deterministic env-based detection of the full two-layer profile
|
|
2595
|
+
* ({@link TerminalCaps} + {@link TerminalEmulator}). Reads env explicitly
|
|
2596
|
+
* (no `process.env` access) so callers can inject custom environments in
|
|
2597
|
+
* tests. Color tier is derived via {@link detectColorFromEnv} and therefore
|
|
2598
|
+
* honors FORCE_COLOR / NO_COLOR.
|
|
2599
|
+
*/
|
|
2600
|
+
function detectTerminalProfileFromEnv(env, stdout) {
|
|
2601
|
+
const program = env.TERM_PROGRAM ?? "";
|
|
2602
|
+
const programLower = program.toLowerCase();
|
|
2603
|
+
const version = env.TERM_PROGRAM_VERSION ?? "";
|
|
2604
|
+
const TERM = env.TERM ?? "";
|
|
2605
|
+
const noColor = env.NO_COLOR !== void 0;
|
|
2606
|
+
const isAppleTerminal = programLower === "apple_terminal";
|
|
2607
|
+
const colorLevel = noColor ? "mono" : detectColorFromEnv(env, stdout);
|
|
2608
|
+
const isKitty = TERM === "xterm-kitty";
|
|
2609
|
+
const isITerm = programLower === "iterm.app";
|
|
2610
|
+
const isGhostty = programLower === "ghostty";
|
|
2611
|
+
const isWezTerm = programLower === "wezterm";
|
|
2612
|
+
const isAlacritty = programLower === "alacritty";
|
|
2613
|
+
const isFoot = TERM === "foot" || TERM === "foot-extra";
|
|
2614
|
+
const isDumb = TERM === "dumb";
|
|
2615
|
+
const isModern = !isDumb && (isKitty || isITerm || isGhostty || isWezTerm || isFoot);
|
|
2616
|
+
let isKittyWithTextSizing = false;
|
|
2617
|
+
if (isKitty) {
|
|
2618
|
+
const parts = version.split(".");
|
|
2619
|
+
const major = Number(parts[0]) || 0;
|
|
2620
|
+
const minor = Number(parts[1]) || 0;
|
|
2621
|
+
isKittyWithTextSizing = major > 0 || major === 0 && minor >= 40;
|
|
2622
|
+
}
|
|
2623
|
+
let maybeDarkBackground = !isAppleTerminal;
|
|
2624
|
+
const colorFgBg = env.COLORFGBG;
|
|
2625
|
+
if (colorFgBg) {
|
|
2626
|
+
const parts = colorFgBg.split(";");
|
|
2627
|
+
const bg = parseInt(parts[parts.length - 1] ?? "", 10);
|
|
2628
|
+
if (!isNaN(bg)) maybeDarkBackground = bg < 7;
|
|
2629
|
+
} else if (isAppleTerminal) maybeDarkBackground = detectMacOSDarkMode();
|
|
2630
|
+
let maybeNerdFont = isModern || isAlacritty;
|
|
2631
|
+
const nfEnv = env.NERDFONT;
|
|
2632
|
+
if (nfEnv === "0" || nfEnv === "false") maybeNerdFont = false;
|
|
2633
|
+
else if (nfEnv === "1" || nfEnv === "true") maybeNerdFont = true;
|
|
2634
|
+
const underlineExtensions = isModern || !isDumb && isAlacritty;
|
|
2635
|
+
const underlineStyles = underlineExtensions ? [
|
|
2636
|
+
"double",
|
|
2637
|
+
"curly",
|
|
2638
|
+
"dotted",
|
|
2639
|
+
"dashed"
|
|
2640
|
+
] : [];
|
|
2641
|
+
const unicode = isModern || !isDumb && env.WT_SESSION !== void 0 || env.KITTY_WINDOW_ID !== void 0 || utf8Locale(env) || !isDumb && termImpliesUnicode(TERM) || env.CI !== void 0 && env.GITHUB_ACTIONS !== void 0;
|
|
2642
|
+
const cursor = stdout.isTTY === true && TERM !== "dumb";
|
|
2643
|
+
return {
|
|
2644
|
+
emulator: {
|
|
2645
|
+
program,
|
|
2646
|
+
version,
|
|
2647
|
+
TERM
|
|
2648
|
+
},
|
|
2649
|
+
caps: {
|
|
2650
|
+
cursor,
|
|
2651
|
+
input: false,
|
|
2652
|
+
colorLevel,
|
|
2653
|
+
colorForced: noColor || env.FORCE_COLOR !== void 0,
|
|
2654
|
+
colorProvenance: noColor || env.FORCE_COLOR !== void 0 ? "env" : "auto",
|
|
2655
|
+
unicode,
|
|
2656
|
+
underlineStyles,
|
|
2657
|
+
underlineColor: underlineExtensions,
|
|
2658
|
+
overline: underlineExtensions,
|
|
2659
|
+
textSizing: isKittyWithTextSizing,
|
|
2660
|
+
kittyKeyboard: !isDumb && (isKitty || isGhostty || isWezTerm || isFoot),
|
|
2661
|
+
bracketedPaste: true,
|
|
2662
|
+
mouse: true,
|
|
2663
|
+
kittyGraphics: !isDumb && (isKitty || isGhostty),
|
|
2664
|
+
sixel: !isDumb && (isFoot || isWezTerm),
|
|
2665
|
+
osc52: isModern || !isDumb && isAlacritty,
|
|
2666
|
+
hyperlinks: isModern || !isDumb && isAlacritty,
|
|
2667
|
+
notifications: isITerm || isKitty,
|
|
2668
|
+
syncOutput: isModern || !isDumb && isAlacritty,
|
|
2669
|
+
maybeDarkBackground,
|
|
2670
|
+
maybeNerdFont,
|
|
2671
|
+
maybeWideEmojis: !isAppleTerminal
|
|
2672
|
+
},
|
|
2673
|
+
colorLevel
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
/**
|
|
2677
|
+
* Does `env.LANG` / `LC_ALL` / `LC_CTYPE` name a UTF-8 locale? Absorbed from
|
|
2678
|
+
* the retired `detectUnicode()` helper.
|
|
2679
|
+
*/
|
|
2680
|
+
function utf8Locale(env) {
|
|
2681
|
+
const lang = (env.LANG ?? env.LC_ALL ?? env.LC_CTYPE ?? "").toLowerCase();
|
|
2682
|
+
return lang.includes("utf-8") || lang.includes("utf8");
|
|
2683
|
+
}
|
|
2684
|
+
/**
|
|
2685
|
+
* Does the `TERM` value imply a multiplexer / terminal family we know renders
|
|
2686
|
+
* unicode correctly? Absorbed from the retired `detectUnicode()` helper.
|
|
2687
|
+
*/
|
|
2688
|
+
function termImpliesUnicode(term) {
|
|
2689
|
+
return term.includes("xterm") || term.includes("rxvt") || term.includes("screen") || term.includes("tmux");
|
|
2690
|
+
}
|
|
2691
|
+
function detectMacOSDarkMode() {
|
|
2692
|
+
if (cachedMacOSDarkMode !== void 0) return cachedMacOSDarkMode;
|
|
2693
|
+
try {
|
|
2694
|
+
const { spawnSync } = __require("child_process");
|
|
2695
|
+
cachedMacOSDarkMode = spawnSync("defaults", [
|
|
2696
|
+
"read",
|
|
2697
|
+
"-g",
|
|
2698
|
+
"AppleInterfaceStyle"
|
|
2699
|
+
], {
|
|
2700
|
+
encoding: "utf-8",
|
|
2701
|
+
timeout: 500
|
|
2702
|
+
}).stdout?.trim() === "Dark";
|
|
2703
|
+
} catch {
|
|
2704
|
+
cachedMacOSDarkMode = false;
|
|
2705
|
+
}
|
|
2706
|
+
return cachedMacOSDarkMode;
|
|
2707
|
+
}
|
|
2708
|
+
var CI_ENVS, cachedMacOSDarkMode;
|
|
2709
|
+
var init_profile = __esmMin((() => {
|
|
2710
|
+
init_caps();
|
|
2711
|
+
init_emulator();
|
|
2712
|
+
init_detect();
|
|
2713
|
+
init_color_maps();
|
|
2714
|
+
CI_ENVS = [
|
|
2715
|
+
"CI",
|
|
2716
|
+
"GITHUB_ACTIONS",
|
|
2717
|
+
"GITLAB_CI",
|
|
2718
|
+
"JENKINS_URL",
|
|
2719
|
+
"BUILDKITE",
|
|
2720
|
+
"CIRCLECI",
|
|
2721
|
+
"TRAVIS"
|
|
2722
|
+
];
|
|
2723
|
+
}));
|
|
2724
|
+
//#endregion
|
|
2725
|
+
//#region packages/ansi/src/sgr-codes.ts
|
|
2726
|
+
/**
|
|
2727
|
+
* SGR (Select Graphic Rendition) color code helpers.
|
|
2728
|
+
*
|
|
2729
|
+
* Shared by buffer.ts (styleToAnsiCodes) and output-phase.ts (styleTransition).
|
|
2730
|
+
* Emits the shortest possible SGR code string for a given color.
|
|
2731
|
+
*/
|
|
2732
|
+
/**
|
|
2733
|
+
* Emit the shortest SGR code string for a foreground color.
|
|
2734
|
+
* - Basic 0-7: 4-bit code (30+N)
|
|
2735
|
+
* - Extended 8-255: 256-color (38;5;N)
|
|
2736
|
+
* - RGB: true color (38;2;R;G;B)
|
|
2737
|
+
*/
|
|
2738
|
+
function fgColorCode(color) {
|
|
2739
|
+
if (typeof color === "number") {
|
|
2740
|
+
if (color >= 0 && color <= 7) return `${30 + color}`;
|
|
2741
|
+
return `38;5;${color}`;
|
|
2742
|
+
}
|
|
2743
|
+
return `38;2;${color.r};${color.g};${color.b}`;
|
|
2744
|
+
}
|
|
2745
|
+
/**
|
|
2746
|
+
* Emit the shortest SGR code string for a background color.
|
|
2747
|
+
* - Basic 0-7: 4-bit code (40+N)
|
|
2748
|
+
* - Extended 8-255: 256-color (48;5;N)
|
|
2749
|
+
* - RGB: true color (48;2;R;G;B)
|
|
2750
|
+
*/
|
|
2751
|
+
function bgColorCode(color) {
|
|
2752
|
+
if (typeof color === "number") {
|
|
2753
|
+
if (color >= 0 && color <= 7) return `${40 + color}`;
|
|
2754
|
+
return `48;5;${color}`;
|
|
2755
|
+
}
|
|
2756
|
+
return `48;2;${color.r};${color.g};${color.b}`;
|
|
2757
|
+
}
|
|
2758
|
+
var init_sgr_codes = __esmMin((() => {}));
|
|
2759
|
+
//#endregion
|
|
2760
|
+
//#region packages/ansi/src/utils.ts
|
|
2761
|
+
/**
|
|
2762
|
+
* Emit a warning exactly once per process, keyed by `id`.
|
|
2763
|
+
*
|
|
2764
|
+
* The first call with a given `id` invokes `emit(message)`; subsequent calls
|
|
2765
|
+
* with the same `id` are no-ops. Use for dev-mode checks that would otherwise
|
|
2766
|
+
* spam the console on every render pass / every keystroke / every reconcile.
|
|
2767
|
+
*
|
|
2768
|
+
* Consolidates what used to be three parallel `let hasWarned*` latches
|
|
2769
|
+
* scattered across silvery packages (`test/index.tsx`,
|
|
2770
|
+
* `ag-react/reconciler/host-config.ts`, `ag/keys.ts`). See
|
|
2771
|
+
* km-silvery.latch-consolidation.
|
|
2772
|
+
*
|
|
2773
|
+
* @param id - Unique warning identifier (stable across restarts). Convention:
|
|
2774
|
+
* `<package>:<short-slug>`, e.g. `"silvery/test:termless-leak"`,
|
|
2775
|
+
* `"silvery/ag-react:box-in-text"`.
|
|
2776
|
+
* @param emit - Callback that actually produces the warning. Called once.
|
|
2777
|
+
* Omit to use `console.warn` with no message (rarely useful — prefer an
|
|
2778
|
+
* explicit emit).
|
|
2779
|
+
*
|
|
2780
|
+
* @example
|
|
2781
|
+
* ```ts
|
|
2782
|
+
* import { warnOnce } from "@silvery/ansi"
|
|
2783
|
+
*
|
|
2784
|
+
* function validateBoxInText() {
|
|
2785
|
+
* if (!isValid) {
|
|
2786
|
+
* warnOnce("silvery/ag-react:box-in-text", () =>
|
|
2787
|
+
* console.warn("<Box> cannot be nested inside <Text>.")
|
|
2788
|
+
* )
|
|
2789
|
+
* }
|
|
2790
|
+
* }
|
|
2791
|
+
* ```
|
|
2792
|
+
*/
|
|
2793
|
+
function warnOnce(id, emit) {
|
|
2794
|
+
if (_firedWarnings.has(id)) return;
|
|
2795
|
+
_firedWarnings.add(id);
|
|
2796
|
+
emit();
|
|
2797
|
+
}
|
|
2798
|
+
var _firedWarnings;
|
|
2799
|
+
var init_utils = __esmMin((() => {
|
|
2800
|
+
_firedWarnings = /* @__PURE__ */ new Set();
|
|
2801
|
+
}));
|
|
2802
|
+
//#endregion
|
|
2803
|
+
//#region packages/ansi/src/flatten.ts
|
|
2804
|
+
function isHexLeaf(value) {
|
|
2805
|
+
return typeof value === "string" && HEX_LEAF_RE.test(value);
|
|
2806
|
+
}
|
|
2807
|
+
/**
|
|
2808
|
+
* Populate flat hyphen-keys onto `theme` in-place by walking hex leaves and
|
|
2809
|
+
* asking `rule` where each leaf should also live at the root.
|
|
2810
|
+
*
|
|
2811
|
+
* Both the nested and flat forms reference the SAME string (not copies) —
|
|
2812
|
+
* `bakeFlat({...}).accent.bg === bakeFlat({...})["bg-accent"]`.
|
|
2813
|
+
*
|
|
2814
|
+
* `rule` defaults to {@link defaultFlattenRule} (channel-role-state).
|
|
2815
|
+
* Rules returning `null` for a path skip that leaf — useful for suppressing
|
|
2816
|
+
* metadata or implementing partial projections.
|
|
2817
|
+
*
|
|
2818
|
+
* The returned object is deep-frozen. The input object is mutated in place
|
|
2819
|
+
* and returned; callers that want an unfrozen copy should `structuredClone`
|
|
2820
|
+
* before calling.
|
|
2821
|
+
*
|
|
2822
|
+
* @param theme nested POJO of hex-string leaves (plus optional metadata)
|
|
2823
|
+
* @param rule how to compute flat keys from nested paths
|
|
2824
|
+
* @returns the same object, with flat keys added and frozen
|
|
2825
|
+
*/
|
|
2826
|
+
function bakeFlat(theme, rule = defaultFlattenRule) {
|
|
2827
|
+
const root = theme;
|
|
2828
|
+
if (Object.isFrozen(root)) return theme;
|
|
2829
|
+
walk(root, [], root, rule);
|
|
2830
|
+
freezeDeep(root);
|
|
2831
|
+
return theme;
|
|
2832
|
+
}
|
|
2833
|
+
function walk(node, path, root, rule) {
|
|
2834
|
+
for (const key of Object.keys(node)) {
|
|
2835
|
+
if (node === root && key.includes("-")) continue;
|
|
2836
|
+
const value = node[key];
|
|
2837
|
+
const subpath = [...path, key];
|
|
2838
|
+
if (isHexLeaf(value)) {
|
|
2839
|
+
const flatKey = rule(subpath);
|
|
2840
|
+
if (flatKey !== null) root[flatKey] = value;
|
|
2841
|
+
continue;
|
|
2842
|
+
}
|
|
2843
|
+
if (value && typeof value === "object" && !Array.isArray(value)) walk(value, subpath, root, rule);
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
function freezeDeep(o) {
|
|
2847
|
+
if (o === null || typeof o !== "object") return;
|
|
2848
|
+
if (Object.isFrozen(o)) return;
|
|
2849
|
+
Object.freeze(o);
|
|
2850
|
+
for (const k of Object.keys(o)) freezeDeep(o[k]);
|
|
2851
|
+
}
|
|
2852
|
+
var defaultFlattenRule, HEX_LEAF_RE;
|
|
2853
|
+
var init_flatten = __esmMin((() => {
|
|
2854
|
+
defaultFlattenRule = (path) => {
|
|
2855
|
+
if (path.length < 2) return null;
|
|
2856
|
+
const role = path[0];
|
|
2857
|
+
const last = path[path.length - 1];
|
|
2858
|
+
const mid = path.slice(1, -1);
|
|
2859
|
+
if (last === "fgOn") return `fg-on-${role}`;
|
|
2860
|
+
if (last === "fg" || last === "bg" || last === "border") {
|
|
2861
|
+
const state = mid.length > 0 ? mid.join("-") : void 0;
|
|
2862
|
+
return state ? `${last}-${role}-${state}` : `${last}-${role}`;
|
|
2863
|
+
}
|
|
2864
|
+
if (role === "surface") return `bg-surface-${last}`;
|
|
2865
|
+
if (role === "border") return `border-${last}`;
|
|
2866
|
+
return null;
|
|
2867
|
+
};
|
|
2868
|
+
HEX_LEAF_RE = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?([0-9a-fA-F]{2})?$/;
|
|
2869
|
+
}));
|
|
2870
|
+
//#endregion
|
|
2871
|
+
//#region packages/ansi/src/terminal-control.ts
|
|
2872
|
+
function enableMouse(options = {}) {
|
|
2873
|
+
return `${CSI$1}?1003h${CSI$1}?1006h${options.pixels ? `${CSI$1}?1016h` : ""}`;
|
|
2874
|
+
}
|
|
2875
|
+
/**
|
|
2876
|
+
* Disable mouse tracking. Disables in reverse order of enabling.
|
|
2877
|
+
*/
|
|
2878
|
+
function disableMouse() {
|
|
2879
|
+
return `${CSI$1}?1016l${CSI$1}?1006l${CSI$1}?1003l`;
|
|
2880
|
+
}
|
|
2881
|
+
/**
|
|
2882
|
+
* Enable bracketed paste mode (DEC private mode 2004).
|
|
2883
|
+
* Terminal wraps pasted text with markers so the app can distinguish
|
|
2884
|
+
* paste from typed input.
|
|
2885
|
+
*/
|
|
2886
|
+
function enableBracketedPaste() {
|
|
2887
|
+
return `${CSI$1}?2004h`;
|
|
2888
|
+
}
|
|
2889
|
+
/**
|
|
2890
|
+
* Disable bracketed paste mode.
|
|
2891
|
+
*/
|
|
2892
|
+
function disableBracketedPaste() {
|
|
2893
|
+
return `${CSI$1}?2004l`;
|
|
2894
|
+
}
|
|
2895
|
+
/**
|
|
2896
|
+
* Enable the Kitty keyboard protocol (push mode).
|
|
2897
|
+
*
|
|
2898
|
+
* Sends CSI > flags u to opt into the specified modes.
|
|
2899
|
+
* Supported by: Ghostty, Kitty, WezTerm, foot. Ignored by unsupported terminals.
|
|
2900
|
+
*
|
|
2901
|
+
* Flags are a bitfield:
|
|
2902
|
+
*
|
|
2903
|
+
* | Flag | Bit | Description |
|
|
2904
|
+
* | ---- | --- | ----------------------------------------- |
|
|
2905
|
+
* | 1 | 0 | Disambiguate escape codes |
|
|
2906
|
+
* | 2 | 1 | Report event types (press/repeat/release) |
|
|
2907
|
+
* | 4 | 2 | Report alternate keys |
|
|
2908
|
+
* | 8 | 3 | Report all keys as escape codes |
|
|
2909
|
+
* | 16 | 4 | Report associated text |
|
|
2910
|
+
*
|
|
2911
|
+
* @param flags Bitfield of Kitty keyboard flags
|
|
2912
|
+
*/
|
|
2913
|
+
function enableKittyKeyboard(flags = 1) {
|
|
2914
|
+
return `${CSI$1}>${flags}u`;
|
|
2915
|
+
}
|
|
2916
|
+
/**
|
|
2917
|
+
* Disable the Kitty keyboard protocol (pop mode stack).
|
|
2918
|
+
* Sends CSI < u to restore the previous keyboard mode.
|
|
2919
|
+
*/
|
|
2920
|
+
function disableKittyKeyboard() {
|
|
2921
|
+
return `${CSI$1}<u`;
|
|
2922
|
+
}
|
|
2923
|
+
var ESC$1, CSI$1;
|
|
2924
|
+
var init_terminal_control = __esmMin((() => {
|
|
2925
|
+
ESC$1 = "\x1B";
|
|
2926
|
+
CSI$1 = `${ESC$1}[`;
|
|
2927
|
+
`${ESC$1}`;
|
|
2928
|
+
}));
|
|
2929
|
+
//#endregion
|
|
2930
|
+
//#region packages/ansi/src/kitty-graphics.ts
|
|
2931
|
+
/**
|
|
2932
|
+
* Derive a stable placement ID for a given (x, y) cell. Max column = 9999,
|
|
2933
|
+
* which comfortably exceeds any realistic terminal width.
|
|
2934
|
+
*/
|
|
2935
|
+
function backdropPlacementId(x, y) {
|
|
2936
|
+
return x * BACKDROP_PLACEMENT_X_STRIDE + y + 1;
|
|
2937
|
+
}
|
|
2938
|
+
/**
|
|
2939
|
+
* Encode a Uint8Array as base64. Kitty expects standard base64 (with `+`/`/`
|
|
2940
|
+
* and `=` padding). We use Buffer when available (Node/Bun), fall back to
|
|
2941
|
+
* btoa for browser/canvas adapters (the canvas target may never actually
|
|
2942
|
+
* need to emit Kitty escapes — this is just defensive).
|
|
2943
|
+
*/
|
|
2944
|
+
function base64Encode(bytes) {
|
|
2945
|
+
if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
|
|
2946
|
+
let binary = "";
|
|
2947
|
+
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
2948
|
+
const g = globalThis;
|
|
2949
|
+
if (typeof g.btoa === "function") return g.btoa(binary);
|
|
2950
|
+
throw new Error("base64 encoding unavailable in this environment");
|
|
2951
|
+
}
|
|
2952
|
+
/**
|
|
2953
|
+
* Build a tiny RGBA pixel grid for the scrim overlay.
|
|
2954
|
+
*
|
|
2955
|
+
* Kitty's graphics protocol paints images at native pixel resolution scaled
|
|
2956
|
+
* to `c` x `r` cells. A 2x2 RGBA image scaled to a single cell (~10x20 px
|
|
2957
|
+
* depending on font) gives us a smooth fill. We intentionally keep the
|
|
2958
|
+
* image tiny to minimize base64 payload size on the upload frame.
|
|
2959
|
+
*
|
|
2960
|
+
* Pixel color: `(r, g, b, a)` where `r/g/b` is the scrim tint and `a` is the
|
|
2961
|
+
* alpha (0-255). For a dark backdrop we use near-black at ~50% alpha, which
|
|
2962
|
+
* darkens the emoji underneath without completely hiding it.
|
|
2963
|
+
*
|
|
2964
|
+
* Width/height = 2 pixels — 16 bytes total, ~24 bytes base64. Upload is ~60
|
|
2965
|
+
* bytes including control chars. One-time cost per modal session.
|
|
2966
|
+
*/
|
|
2967
|
+
function buildScrimPixels(tint, alpha) {
|
|
2968
|
+
const a = Math.max(0, Math.min(255, Math.round(alpha)));
|
|
2969
|
+
const r = Math.max(0, Math.min(255, Math.round(tint.r)));
|
|
2970
|
+
const g = Math.max(0, Math.min(255, Math.round(tint.g)));
|
|
2971
|
+
const b = Math.max(0, Math.min(255, Math.round(tint.b)));
|
|
2972
|
+
const bytes = new Uint8Array(16);
|
|
2973
|
+
for (let i = 0; i < 4; i++) {
|
|
2974
|
+
bytes[i * 4 + 0] = r;
|
|
2975
|
+
bytes[i * 4 + 1] = g;
|
|
2976
|
+
bytes[i * 4 + 2] = b;
|
|
2977
|
+
bytes[i * 4 + 3] = a;
|
|
2978
|
+
}
|
|
2979
|
+
return bytes;
|
|
2980
|
+
}
|
|
2981
|
+
/**
|
|
2982
|
+
* APC wrapper: `\x1b_G<control>[;<payload>]\x1b\\`.
|
|
2983
|
+
*
|
|
2984
|
+
* The protocol allows chunking large payloads via `m=1` but our scrim is
|
|
2985
|
+
* tiny — always fits in one chunk.
|
|
2986
|
+
*/
|
|
2987
|
+
function apc(control, payload) {
|
|
2988
|
+
if (payload === void 0 || payload === "") return `\x1b_G${control}\x1b\\`;
|
|
2989
|
+
return `\x1b_G${control};${payload}\x1b\\`;
|
|
2990
|
+
}
|
|
2991
|
+
/**
|
|
2992
|
+
* Emit a one-shot image upload. Terminal stores the RGBA pixels under
|
|
2993
|
+
* `i=<imageId>` and keeps them until explicitly freed. Subsequent placements
|
|
2994
|
+
* reference the image by ID without re-sending pixel data.
|
|
2995
|
+
*
|
|
2996
|
+
* `q=2` suppresses the terminal's OK/error reply — otherwise we'd see stray
|
|
2997
|
+
* APC sequences back on stdin.
|
|
2998
|
+
*/
|
|
2999
|
+
function kittyUploadScrimImage(pixels, width, height, imageId = BACKDROP_SCRIM_IMAGE_ID) {
|
|
3000
|
+
const payload = base64Encode(pixels);
|
|
3001
|
+
return apc(`a=t,f=32,s=${width},v=${height},i=${imageId},q=2`, payload);
|
|
3002
|
+
}
|
|
3003
|
+
/**
|
|
3004
|
+
* Emit a cell placement. Places `imageId` at the current cursor position
|
|
3005
|
+
* covering `c` cols and `r` rows with z-index `z`. `C=1` prevents the cursor
|
|
3006
|
+
* from advancing after placement (critical — otherwise every placement
|
|
3007
|
+
* shifts the cursor, breaking the caller's positioning).
|
|
3008
|
+
*
|
|
3009
|
+
* Placement ID (`p=<pid>`) is stable per cell so incremental frames can
|
|
3010
|
+
* replace placements without accumulating duplicates.
|
|
3011
|
+
*/
|
|
3012
|
+
function kittyPlaceAt(opts) {
|
|
3013
|
+
const imageId = opts.imageId ?? 48879;
|
|
3014
|
+
const cols = opts.cols ?? 1;
|
|
3015
|
+
const rows = opts.rows ?? 1;
|
|
3016
|
+
const z = opts.z ?? 1;
|
|
3017
|
+
return apc(`a=p,i=${imageId},p=${opts.placementId},c=${cols},r=${rows},z=${z},C=1,q=2`);
|
|
3018
|
+
}
|
|
3019
|
+
/**
|
|
3020
|
+
* Delete ALL placements of our scrim image without freeing the image.
|
|
3021
|
+
* Used when the modal closes — we leave the image cached in case another
|
|
3022
|
+
* modal opens, but remove every overlay cell at once.
|
|
3023
|
+
*/
|
|
3024
|
+
function kittyDeleteAllScrimPlacements(imageId = BACKDROP_SCRIM_IMAGE_ID) {
|
|
3025
|
+
return apc(`a=d,d=i,i=${imageId},q=2`);
|
|
3026
|
+
}
|
|
3027
|
+
/**
|
|
3028
|
+
* Absolute cursor position (CUP). 1-based row/col per VT100.
|
|
3029
|
+
*
|
|
3030
|
+
* Used to position the cursor before emitting a placement so the placement
|
|
3031
|
+
* lands in the right cell. Kept small and local — the rest of the pipeline
|
|
3032
|
+
* uses more elaborate cursor tracking, but for out-of-band overlay emission
|
|
3033
|
+
* we just want a deterministic "jump here, place, done."
|
|
3034
|
+
*/
|
|
3035
|
+
function cupTo(col, row) {
|
|
3036
|
+
return `\x1b[${row + 1};${col + 1}H`;
|
|
3037
|
+
}
|
|
3038
|
+
var BACKDROP_SCRIM_IMAGE_ID, BACKDROP_PLACEMENT_X_STRIDE;
|
|
3039
|
+
var init_kitty_graphics = __esmMin((() => {
|
|
3040
|
+
BACKDROP_SCRIM_IMAGE_ID = 48879;
|
|
3041
|
+
BACKDROP_PLACEMENT_X_STRIDE = 1e4;
|
|
3042
|
+
}));
|
|
3043
|
+
//#endregion
|
|
3044
|
+
//#region packages/ansi/src/style/colors.ts
|
|
3045
|
+
var THEME_TOKEN_DEFAULTS;
|
|
3046
|
+
var init_colors = __esmMin((() => {
|
|
3047
|
+
init_color_maps();
|
|
3048
|
+
THEME_TOKEN_DEFAULTS = {
|
|
3049
|
+
primary: 33,
|
|
3050
|
+
secondary: 36,
|
|
3051
|
+
accent: 35,
|
|
3052
|
+
error: 31,
|
|
3053
|
+
warning: 33,
|
|
3054
|
+
success: 32,
|
|
3055
|
+
info: 36,
|
|
3056
|
+
muted: 2,
|
|
3057
|
+
link: 34,
|
|
3058
|
+
border: 90,
|
|
3059
|
+
surface: 37
|
|
3060
|
+
};
|
|
3061
|
+
}));
|
|
3062
|
+
//#endregion
|
|
3063
|
+
//#region packages/ansi/src/style/style.ts
|
|
3064
|
+
/**
|
|
3065
|
+
* Resolve a color value against a theme — the canonical token resolver.
|
|
3066
|
+
*
|
|
3067
|
+
* If the color starts with `$`, looks up the token in the theme.
|
|
3068
|
+
* Supports `$primary`, `$surface-bg` (hyphens stripped), `$color0`–`$color15` (palette).
|
|
3069
|
+
* Non-`$` strings pass through unchanged. Returns undefined if no theme or unknown token.
|
|
3070
|
+
*
|
|
3071
|
+
* Compatible with @silvery/theme's Theme type (or any object with string properties).
|
|
3072
|
+
*/
|
|
3073
|
+
function resolveThemeColor(name, theme) {
|
|
3074
|
+
if (!name) return void 0;
|
|
3075
|
+
if (!name.startsWith("$")) return name;
|
|
3076
|
+
if (!theme) return void 0;
|
|
3077
|
+
return resolveToken(name, theme);
|
|
3078
|
+
}
|
|
3079
|
+
/** Internal: resolve a token name (with or without $ prefix) against a theme.
|
|
3080
|
+
*
|
|
3081
|
+
* Resolution order:
|
|
3082
|
+
* 1. Direct key lookup — finds Sterling flat keys (`bg-accent`,
|
|
3083
|
+
* `fg-on-error`, `border-focus`, …) and legacy kebab keys
|
|
3084
|
+
* (`primary-hover`, `fg-hover`, `bg-surface-hover`) and plain names
|
|
3085
|
+
* (`bg`, `primary`, `muted`).
|
|
3086
|
+
* 2. No-hyphen fallback — `$surface-bg` → `theme.surfacebg`,
|
|
3087
|
+
* `$focus-border` → `theme.focusborder`.
|
|
3088
|
+
*
|
|
3089
|
+
* The old `LEGACY_ALIASES` table (e.g. `fgmuted` → `muted`, `bgsurface` →
|
|
3090
|
+
* `surfacebg`) was removed in 0.18.1 once every shipped default Theme ships
|
|
3091
|
+
* with Sterling flat tokens baked in — `theme["fg-muted"]` and
|
|
3092
|
+
* `theme["bg-surface-subtle"]` are direct fields now, so no alias fallback
|
|
3093
|
+
* is required for canonical Sterling tokens. Tokens that existed only as
|
|
3094
|
+
* aliases (e.g. `$bg-surface`, `$fg-on-primary`, `$border-input`,
|
|
3095
|
+
* `$fg-disabled`) no longer resolve — callers should use the canonical
|
|
3096
|
+
* Sterling equivalents (`$bg-surface-default`, `$fg-on-accent`,
|
|
3097
|
+
* `$border-default`, `$fg-muted`).
|
|
3098
|
+
*/
|
|
3099
|
+
function resolveToken(name, theme) {
|
|
3100
|
+
if (!theme) return void 0;
|
|
3101
|
+
const token = name.startsWith("$") ? name.slice(1) : name;
|
|
3102
|
+
if (token.startsWith("color")) {
|
|
3103
|
+
const idx = parseInt(token.slice(5), 10);
|
|
3104
|
+
if (idx >= 0 && idx < 16 && theme.palette && idx < theme.palette.length) return theme.palette[idx];
|
|
3105
|
+
}
|
|
3106
|
+
const themeObj = theme;
|
|
3107
|
+
const direct = themeObj[token];
|
|
3108
|
+
if (typeof direct === "string") return direct;
|
|
3109
|
+
const noHyphen = token.replace(/-/g, "");
|
|
3110
|
+
if (noHyphen !== token) {
|
|
3111
|
+
const stripped = themeObj[noHyphen];
|
|
3112
|
+
if (typeof stripped === "string") return stripped;
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
/** Convert chalk numeric level (0-3) to {@link ColorLevel}. */
|
|
3116
|
+
function fromChalkLevel(n) {
|
|
3117
|
+
if (n <= 0) return "mono";
|
|
3118
|
+
if (n === 1) return "ansi16";
|
|
3119
|
+
if (n === 2) return "256";
|
|
3120
|
+
return "truecolor";
|
|
3121
|
+
}
|
|
3122
|
+
/** Convert {@link ColorLevel} to chalk numeric level (0-3). */
|
|
3123
|
+
function toChalkLevel(cl) {
|
|
3124
|
+
if (cl === "mono") return 0;
|
|
3125
|
+
if (cl === "ansi16") return 1;
|
|
3126
|
+
if (cl === "256") return 2;
|
|
3127
|
+
return 3;
|
|
3128
|
+
}
|
|
3129
|
+
/**
|
|
3130
|
+
* Create a style object for terminal output.
|
|
3131
|
+
*
|
|
3132
|
+
* @param options - Color level and optional theme
|
|
3133
|
+
* @returns A chainable style object (chalk-compatible API)
|
|
3134
|
+
*
|
|
3135
|
+
* @example
|
|
3136
|
+
* ```ts
|
|
3137
|
+
* import { createStyle } from "@silvery/ansi"
|
|
3138
|
+
*
|
|
3139
|
+
* const s = createStyle()
|
|
3140
|
+
* console.log(s.bold.red("Error!"))
|
|
3141
|
+
* console.log(s.hex("#818cf8")("Indigo"))
|
|
3142
|
+
*
|
|
3143
|
+
* // With theme
|
|
3144
|
+
* const s = createStyle({ theme })
|
|
3145
|
+
* console.log(s.primary("Deploy"))
|
|
3146
|
+
* console.log(s.success("Done"))
|
|
3147
|
+
* ```
|
|
3148
|
+
*/
|
|
3149
|
+
function createStyle(options) {
|
|
3150
|
+
const ref = {
|
|
3151
|
+
level: "mono",
|
|
3152
|
+
theme: options?.theme,
|
|
3153
|
+
caps: {
|
|
3154
|
+
underlineStyles: false,
|
|
3155
|
+
underlineColor: false
|
|
3156
|
+
}
|
|
3157
|
+
};
|
|
3158
|
+
if (options?.level !== void 0 && options.level !== null) {
|
|
3159
|
+
ref.level = options.level;
|
|
3160
|
+
ref.caps = options.caps ?? ref.caps;
|
|
3161
|
+
} else if (options?.level === null) {
|
|
3162
|
+
ref.level = "mono";
|
|
3163
|
+
ref.caps = options.caps ?? ref.caps;
|
|
3164
|
+
} else try {
|
|
3165
|
+
const profile = createTerminalProfile({ stdout: process.stdout });
|
|
3166
|
+
ref.level = profile.colorLevel;
|
|
3167
|
+
ref.caps = options?.caps ?? {
|
|
3168
|
+
underlineStyles: profile.caps.underlineStyles.length > 0,
|
|
3169
|
+
underlineColor: profile.caps.underlineColor
|
|
3170
|
+
};
|
|
3171
|
+
} catch {
|
|
3172
|
+
ref.level = "mono";
|
|
3173
|
+
ref.caps = options?.caps ?? ref.caps;
|
|
3174
|
+
}
|
|
3175
|
+
return createChainWithRef({
|
|
3176
|
+
opens: [],
|
|
3177
|
+
closes: []
|
|
3178
|
+
}, ref);
|
|
3179
|
+
}
|
|
3180
|
+
/**
|
|
3181
|
+
* Create a chain that reads level from a mutable ref.
|
|
3182
|
+
* This allows `style.level = 3` to affect all subsequent calls.
|
|
3183
|
+
*/
|
|
3184
|
+
function createChainWithRef(state, ref) {
|
|
3185
|
+
const proxyRef = { proxy: null };
|
|
3186
|
+
const handler = {
|
|
3187
|
+
apply(_target, _thisArg, args) {
|
|
3188
|
+
const level = ref.level;
|
|
3189
|
+
if (state.visible && level === "mono") return "";
|
|
3190
|
+
let text;
|
|
3191
|
+
if (args.length === 0) text = "";
|
|
3192
|
+
else if (Array.isArray(args[0]) && "raw" in args[0]) text = String.raw(args[0], ...args.slice(1));
|
|
3193
|
+
else if (args.length > 1) text = args.map((a) => String(a ?? "")).join(" ");
|
|
3194
|
+
else text = String(args[0] ?? "");
|
|
3195
|
+
if (text === "") return "";
|
|
3196
|
+
if (level === "mono" || state.opens.length === 0) return text;
|
|
3197
|
+
const open = `${ESC}${state.opens.join(";")}m`;
|
|
3198
|
+
const close = `${ESC}${state.closes.join(";")}m`;
|
|
3199
|
+
for (const closeCode of state.closes) {
|
|
3200
|
+
const closeSeq = `${ESC}${closeCode}m`;
|
|
3201
|
+
const parts = text.split(closeSeq);
|
|
3202
|
+
if (parts.length > 1) text = parts.join(`${closeSeq}${open}`);
|
|
3203
|
+
}
|
|
3204
|
+
if (text.includes("\n")) text = text.replace(/\r?\n/g, `${close}$&${open}`);
|
|
3205
|
+
return `${open}${text}${close}`;
|
|
3206
|
+
},
|
|
3207
|
+
get(_target, prop) {
|
|
3208
|
+
if (typeof prop === "symbol") return void 0;
|
|
3209
|
+
if (prop === "level") return toChalkLevel(ref.level);
|
|
3210
|
+
if (prop === "resolve") return (token) => resolveToken(token, ref.theme);
|
|
3211
|
+
if (prop === "visible") return createChainWithRef({
|
|
3212
|
+
...state,
|
|
3213
|
+
visible: true
|
|
3214
|
+
}, ref);
|
|
3215
|
+
if (prop === "call" || prop === "apply" || prop === "bind") return Function.prototype[prop].bind(proxyRef.proxy);
|
|
3216
|
+
const level = ref.level;
|
|
3217
|
+
if (prop === "hex" || prop === "bgHex") return (color) => {
|
|
3218
|
+
if (level === "mono") return createChainWithRef(state, ref);
|
|
3219
|
+
const rgb = hexToRgb$1(color);
|
|
3220
|
+
if (!rgb) return createChainWithRef(state, ref);
|
|
3221
|
+
const code = prop === "hex" ? fgFromRgb(rgb[0], rgb[1], rgb[2], level) : bgFromRgb(rgb[0], rgb[1], rgb[2], level);
|
|
3222
|
+
const close = prop === "hex" ? "39" : "49";
|
|
3223
|
+
return createChainWithRef({
|
|
3224
|
+
opens: [...state.opens, code],
|
|
3225
|
+
closes: [...state.closes, close]
|
|
3226
|
+
}, ref);
|
|
3227
|
+
};
|
|
3228
|
+
if (prop === "rgb" || prop === "bgRgb") return (r, g, b) => {
|
|
3229
|
+
if (level === "mono") return createChainWithRef(state, ref);
|
|
3230
|
+
const code = prop === "rgb" ? fgFromRgb(r, g, b, level) : bgFromRgb(r, g, b, level);
|
|
3231
|
+
const close = prop === "rgb" ? "39" : "49";
|
|
3232
|
+
return createChainWithRef({
|
|
3233
|
+
opens: [...state.opens, code],
|
|
3234
|
+
closes: [...state.closes, close]
|
|
3235
|
+
}, ref);
|
|
3236
|
+
};
|
|
3237
|
+
if (prop === "ansi256") return (code) => {
|
|
3238
|
+
if (level === "mono") return createChainWithRef(state, ref);
|
|
3239
|
+
return createChainWithRef({
|
|
3240
|
+
opens: [...state.opens, `38;5;${code}`],
|
|
3241
|
+
closes: [...state.closes, "39"]
|
|
3242
|
+
}, ref);
|
|
3243
|
+
};
|
|
3244
|
+
if (prop === "bgAnsi256") return (code) => {
|
|
3245
|
+
if (level === "mono") return createChainWithRef(state, ref);
|
|
3246
|
+
return createChainWithRef({
|
|
3247
|
+
opens: [...state.opens, `48;5;${code}`],
|
|
3248
|
+
closes: [...state.closes, "49"]
|
|
3249
|
+
}, ref);
|
|
3250
|
+
};
|
|
3251
|
+
if (prop === "curlyUnderline" || prop === "dottedUnderline" || prop === "dashedUnderline" || prop === "doubleUnderline") {
|
|
3252
|
+
const styleName = prop.slice(0, prop.length - 9);
|
|
3253
|
+
return (text) => applyExtendedUnderline(text, styleName, ref);
|
|
3254
|
+
}
|
|
3255
|
+
if (prop === "underlineColor") return (r, g, b, text) => applyUnderlineColor(text, r, g, b, ref);
|
|
3256
|
+
if (prop === "styledUnderline") return (styleName, rgb, text) => applyStyledUnderline(text, styleName, rgb, ref);
|
|
3257
|
+
if (prop in MODIFIERS) {
|
|
3258
|
+
if (level === "mono") return createChainWithRef(state, ref);
|
|
3259
|
+
const [open, close] = MODIFIERS[prop];
|
|
3260
|
+
return createChainWithRef({
|
|
3261
|
+
opens: [...state.opens, String(open)],
|
|
3262
|
+
closes: [...state.closes, String(close)]
|
|
3263
|
+
}, ref);
|
|
3264
|
+
}
|
|
3265
|
+
if (prop in FG_COLORS) {
|
|
3266
|
+
if (level === "mono") return createChainWithRef(state, ref);
|
|
3267
|
+
return createChainWithRef({
|
|
3268
|
+
opens: [...state.opens, String(FG_COLORS[prop])],
|
|
3269
|
+
closes: [...state.closes, "39"]
|
|
3270
|
+
}, ref);
|
|
3271
|
+
}
|
|
3272
|
+
if (prop in BG_COLORS) {
|
|
3273
|
+
if (level === "mono") return createChainWithRef(state, ref);
|
|
3274
|
+
return createChainWithRef({
|
|
3275
|
+
opens: [...state.opens, String(BG_COLORS[prop])],
|
|
3276
|
+
closes: [...state.closes, "49"]
|
|
3277
|
+
}, ref);
|
|
3278
|
+
}
|
|
3279
|
+
if (THEME_TOKENS.has(prop)) {
|
|
3280
|
+
if (level === "mono") return createChainWithRef(state, ref);
|
|
3281
|
+
const hex = resolveToken(prop, ref.theme);
|
|
3282
|
+
if (hex) {
|
|
3283
|
+
const rgb = hexToRgb$1(hex);
|
|
3284
|
+
if (rgb) {
|
|
3285
|
+
const code = fgFromRgb(rgb[0], rgb[1], rgb[2], level);
|
|
3286
|
+
if (prop === "link") return createChainWithRef({
|
|
3287
|
+
opens: [
|
|
3288
|
+
...state.opens,
|
|
3289
|
+
code,
|
|
3290
|
+
"4"
|
|
3291
|
+
],
|
|
3292
|
+
closes: [
|
|
3293
|
+
...state.closes,
|
|
3294
|
+
"39",
|
|
3295
|
+
"24"
|
|
3296
|
+
]
|
|
3297
|
+
}, ref);
|
|
3298
|
+
return createChainWithRef({
|
|
3299
|
+
opens: [...state.opens, code],
|
|
3300
|
+
closes: [...state.closes, "39"]
|
|
3301
|
+
}, ref);
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
const fallback = THEME_TOKEN_DEFAULTS[prop];
|
|
3305
|
+
if (fallback !== void 0) {
|
|
3306
|
+
if (prop === "muted") return createChainWithRef({
|
|
3307
|
+
opens: [...state.opens, String(fallback)],
|
|
3308
|
+
closes: [...state.closes, "22"]
|
|
3309
|
+
}, ref);
|
|
3310
|
+
if (prop === "link") return createChainWithRef({
|
|
3311
|
+
opens: [
|
|
3312
|
+
...state.opens,
|
|
3313
|
+
String(fallback),
|
|
3314
|
+
"4"
|
|
3315
|
+
],
|
|
3316
|
+
closes: [
|
|
3317
|
+
...state.closes,
|
|
3318
|
+
"39",
|
|
3319
|
+
"24"
|
|
3320
|
+
]
|
|
3321
|
+
}, ref);
|
|
3322
|
+
return createChainWithRef({
|
|
3323
|
+
opens: [...state.opens, String(fallback)],
|
|
3324
|
+
closes: [...state.closes, "39"]
|
|
3325
|
+
}, ref);
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3328
|
+
},
|
|
3329
|
+
set(_target, prop, value) {
|
|
3330
|
+
if (prop === "level") {
|
|
3331
|
+
ref.level = fromChalkLevel(value);
|
|
3332
|
+
return true;
|
|
3333
|
+
}
|
|
3334
|
+
return false;
|
|
3335
|
+
},
|
|
3336
|
+
has(_target, prop) {
|
|
3337
|
+
if (prop === "level") return true;
|
|
3338
|
+
if (typeof prop === "symbol") return false;
|
|
3339
|
+
return prop in MODIFIERS || prop in FG_COLORS || prop in BG_COLORS || THEME_TOKENS.has(prop) || KNOWN_METHODS.has(prop);
|
|
3340
|
+
}
|
|
3341
|
+
};
|
|
3342
|
+
const target = function() {};
|
|
3343
|
+
const proxy = new Proxy(target, handler);
|
|
3344
|
+
proxyRef.proxy = proxy;
|
|
3345
|
+
return proxy;
|
|
3346
|
+
}
|
|
3347
|
+
/** `style.curlyUnderline(text)` / `.dotted` / `.dashed` / `.double`. */
|
|
3348
|
+
function applyExtendedUnderline(text, name, ref) {
|
|
3349
|
+
if (ref.level === "mono") return text;
|
|
3350
|
+
if (!ref.caps.underlineStyles) return `${UNDERLINE_OPEN}${text}${UNDERLINE_CLOSE}`;
|
|
3351
|
+
return `${UNDERLINE_CODES[name]}${text}${UNDERLINE_CODES.reset}`;
|
|
3352
|
+
}
|
|
3353
|
+
/** `style.underlineColor(r, g, b, text)`. */
|
|
3354
|
+
function applyUnderlineColor(text, r, g, b, ref) {
|
|
3355
|
+
if (ref.level === "mono") return text;
|
|
3356
|
+
if (!ref.caps.underlineColor) return `${UNDERLINE_OPEN}${text}${UNDERLINE_CLOSE}`;
|
|
3357
|
+
return `${UNDERLINE_STANDARD}${buildUnderlineColorCode(r, g, b)}${text}${UNDERLINE_COLOR_RESET}${UNDERLINE_RESET_STANDARD}`;
|
|
3358
|
+
}
|
|
3359
|
+
/** `style.styledUnderline(name, [r,g,b], text)`. */
|
|
3360
|
+
function applyStyledUnderline(text, name, rgb, ref) {
|
|
3361
|
+
if (ref.level === "mono") return text;
|
|
3362
|
+
if (!ref.caps.underlineStyles) return `${UNDERLINE_OPEN}${text}${UNDERLINE_CLOSE}`;
|
|
3363
|
+
const [r, g, b] = rgb;
|
|
3364
|
+
const styleCode = UNDERLINE_CODES[name];
|
|
3365
|
+
if (!ref.caps.underlineColor) return `${styleCode}${text}${UNDERLINE_CODES.reset}`;
|
|
3366
|
+
return `${styleCode}${buildUnderlineColorCode(r, g, b)}${text}${UNDERLINE_CODES.reset}${UNDERLINE_COLOR_RESET}`;
|
|
3367
|
+
}
|
|
3368
|
+
var ESC, KNOWN_METHODS, THEME_TOKENS, UNDERLINE_OPEN, UNDERLINE_CLOSE;
|
|
3369
|
+
var init_style = __esmMin((() => {
|
|
3370
|
+
init_profile();
|
|
3371
|
+
init_constants();
|
|
3372
|
+
init_colors();
|
|
3373
|
+
ESC = "\x1B[";
|
|
3374
|
+
KNOWN_METHODS = new Set([
|
|
3375
|
+
"hex",
|
|
3376
|
+
"rgb",
|
|
3377
|
+
"bgHex",
|
|
3378
|
+
"bgRgb",
|
|
3379
|
+
"ansi256",
|
|
3380
|
+
"bgAnsi256",
|
|
3381
|
+
"resolve",
|
|
3382
|
+
"curlyUnderline",
|
|
3383
|
+
"dottedUnderline",
|
|
3384
|
+
"dashedUnderline",
|
|
3385
|
+
"doubleUnderline",
|
|
3386
|
+
"underlineColor",
|
|
3387
|
+
"styledUnderline"
|
|
3388
|
+
]);
|
|
3389
|
+
THEME_TOKENS = new Set([
|
|
3390
|
+
"primary",
|
|
3391
|
+
"secondary",
|
|
3392
|
+
"accent",
|
|
3393
|
+
"error",
|
|
3394
|
+
"warning",
|
|
3395
|
+
"success",
|
|
3396
|
+
"info",
|
|
3397
|
+
"muted",
|
|
3398
|
+
"link",
|
|
3399
|
+
"border",
|
|
3400
|
+
"surface"
|
|
3401
|
+
]);
|
|
3402
|
+
createStyle();
|
|
3403
|
+
UNDERLINE_OPEN = "\x1B[4m";
|
|
3404
|
+
UNDERLINE_CLOSE = "\x1B[24m";
|
|
3405
|
+
}));
|
|
3406
|
+
//#endregion
|
|
3407
|
+
//#region packages/ansi/src/style/mixed-proxy.ts
|
|
3408
|
+
/**
|
|
3409
|
+
* Create a proxy that wraps a style instance with additional properties.
|
|
3410
|
+
*
|
|
3411
|
+
* The proxy makes the result:
|
|
3412
|
+
* - Callable: result('text') applies current styles
|
|
3413
|
+
* - Chainable: result.bold.red('text') chains styles
|
|
3414
|
+
* - Extended: result.anyExtraProp accesses extra properties
|
|
3415
|
+
*
|
|
3416
|
+
* Extra properties take priority over style properties on name collision.
|
|
3417
|
+
*/
|
|
3418
|
+
function createMixedStyle(style, extra) {
|
|
3419
|
+
return createChainProxy(style, extra);
|
|
3420
|
+
}
|
|
3421
|
+
/**
|
|
3422
|
+
* Internal recursive proxy builder for style chain + extra properties.
|
|
3423
|
+
*/
|
|
3424
|
+
function createChainProxy(currentStyle, extra) {
|
|
3425
|
+
const handler = {
|
|
3426
|
+
apply(_target, _thisArg, args) {
|
|
3427
|
+
return currentStyle(...args);
|
|
3428
|
+
},
|
|
3429
|
+
get(_target, prop) {
|
|
3430
|
+
if (prop in extra) {
|
|
3431
|
+
const value = extra[prop];
|
|
3432
|
+
if (typeof value === "function") return value;
|
|
3433
|
+
return value;
|
|
3434
|
+
}
|
|
3435
|
+
if (typeof prop === "symbol") return extra[prop];
|
|
3436
|
+
if (STYLE_METHODS.has(prop)) {
|
|
3437
|
+
const method = currentStyle[prop];
|
|
3438
|
+
if (typeof method === "function") return (...args) => {
|
|
3439
|
+
return createChainProxy(method.apply(currentStyle, args), extra);
|
|
3440
|
+
};
|
|
3441
|
+
}
|
|
3442
|
+
const styleProp = currentStyle[prop];
|
|
3443
|
+
if (styleProp !== void 0) {
|
|
3444
|
+
if (typeof styleProp === "function" || typeof styleProp === "object") return createChainProxy(styleProp, extra);
|
|
3445
|
+
return styleProp;
|
|
3446
|
+
}
|
|
3447
|
+
},
|
|
3448
|
+
set(_target, prop, value) {
|
|
3449
|
+
extra[prop] = value;
|
|
3450
|
+
return true;
|
|
3451
|
+
},
|
|
3452
|
+
defineProperty(_target, prop, descriptor) {
|
|
3453
|
+
Object.defineProperty(extra, prop, descriptor);
|
|
3454
|
+
return true;
|
|
3455
|
+
},
|
|
3456
|
+
has(_target, prop) {
|
|
3457
|
+
if (prop in extra) return true;
|
|
3458
|
+
if (typeof prop === "string" && prop in currentStyle) return true;
|
|
3459
|
+
return false;
|
|
3460
|
+
}
|
|
3461
|
+
};
|
|
3462
|
+
const proxyTarget = function() {};
|
|
3463
|
+
return new Proxy(proxyTarget, handler);
|
|
3464
|
+
}
|
|
3465
|
+
var STYLE_METHODS;
|
|
3466
|
+
var init_mixed_proxy = __esmMin((() => {
|
|
3467
|
+
STYLE_METHODS = new Set([
|
|
3468
|
+
"hex",
|
|
3469
|
+
"bgHex",
|
|
3470
|
+
"rgb",
|
|
3471
|
+
"bgRgb",
|
|
3472
|
+
"ansi256",
|
|
3473
|
+
"bgAnsi256"
|
|
3474
|
+
]);
|
|
3475
|
+
}));
|
|
3476
|
+
//#endregion
|
|
3477
|
+
//#region packages/ansi/src/theme/monochrome.ts
|
|
3478
|
+
/**
|
|
3479
|
+
* Produce per-token monochrome attrs from a base Theme.
|
|
3480
|
+
*
|
|
3481
|
+
* Currently returns `DEFAULT_MONO_ATTRS` — a canonical mapping. Passed the
|
|
3482
|
+
* theme to allow per-theme overrides in the future (e.g., a palette that
|
|
3483
|
+
* prefers `underline` for accents over `italic`). The argument is reserved.
|
|
3484
|
+
*/
|
|
3485
|
+
function deriveMonochromeTheme(theme) {
|
|
3486
|
+
return DEFAULT_MONO_ATTRS;
|
|
3487
|
+
}
|
|
3488
|
+
/**
|
|
3489
|
+
* Resolve mono-attrs from a color *string* — the high-level entry point
|
|
3490
|
+
* consumed by the render pipeline.
|
|
3491
|
+
*
|
|
3492
|
+
* Accepts strings like `"$primary"`, `"$fg-muted"`, `"$border-focus"`. Strips
|
|
3493
|
+
* the `$` prefix and looks the name up directly against `DEFAULT_MONO_ATTRS`,
|
|
3494
|
+
* which carries both legacy keys (`muted`, `surfacebg`, `focusborder`, …) AND
|
|
3495
|
+
* Sterling flat tokens (`fg-muted`, `bg-surface-default`, `border-focus`, …)
|
|
3496
|
+
* as first-class entries. Returns `undefined` for non-token strings (hex,
|
|
3497
|
+
* rgb(), named ANSI colors) — callers should treat this as "no attrs".
|
|
3498
|
+
*
|
|
3499
|
+
* A secondary no-hyphen fallback (`$surface-bg` → `surfacebg`) keeps the
|
|
3500
|
+
* legacy hyphenated-compound form working for callers that still emit that
|
|
3501
|
+
* shape.
|
|
3502
|
+
*
|
|
3503
|
+
* @param color The color string (e.g. `"$primary"`, `"#ff0000"`, `"red"`)
|
|
3504
|
+
* @param theme Active theme (reserved for per-theme overrides)
|
|
3505
|
+
* @returns Array of mono-attrs for the token, or `undefined` if not a
|
|
3506
|
+
* recognized token.
|
|
3507
|
+
*/
|
|
3508
|
+
function monoAttrsForColorString(color, theme) {
|
|
3509
|
+
if (!color.startsWith("$")) return void 0;
|
|
3510
|
+
const name = color.slice(1);
|
|
3511
|
+
const attrs = deriveMonochromeTheme(theme);
|
|
3512
|
+
const direct = attrs[name];
|
|
3513
|
+
if (direct !== void 0) return direct;
|
|
3514
|
+
const noHyphen = name.replace(/-/g, "");
|
|
3515
|
+
if (noHyphen !== name) {
|
|
3516
|
+
const stripped = attrs[noHyphen];
|
|
3517
|
+
if (stripped !== void 0) return stripped;
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
var DEFAULT_MONO_ATTRS;
|
|
3521
|
+
var init_monochrome = __esmMin((() => {
|
|
3522
|
+
DEFAULT_MONO_ATTRS = {
|
|
3523
|
+
bg: [],
|
|
3524
|
+
mutedbg: [],
|
|
3525
|
+
surfacebg: [],
|
|
3526
|
+
popoverbg: [],
|
|
3527
|
+
border: [],
|
|
3528
|
+
cursorbg: [],
|
|
3529
|
+
fg: [],
|
|
3530
|
+
muted: ["dim"],
|
|
3531
|
+
disabledfg: ["dim"],
|
|
3532
|
+
surface: [],
|
|
3533
|
+
popover: [],
|
|
3534
|
+
primary: ["bold"],
|
|
3535
|
+
secondary: ["bold"],
|
|
3536
|
+
accent: ["italic", "bold"],
|
|
3537
|
+
error: ["bold", "inverse"],
|
|
3538
|
+
warning: ["bold"],
|
|
3539
|
+
success: ["bold"],
|
|
3540
|
+
info: ["italic"],
|
|
3541
|
+
primaryfg: [],
|
|
3542
|
+
secondaryfg: [],
|
|
3543
|
+
accentfg: [],
|
|
3544
|
+
errorfg: ["inverse"],
|
|
3545
|
+
warningfg: [],
|
|
3546
|
+
successfg: [],
|
|
3547
|
+
infofg: [],
|
|
3548
|
+
focusborder: ["bold"],
|
|
3549
|
+
inputborder: [],
|
|
3550
|
+
cursor: [],
|
|
3551
|
+
"fg-muted": ["dim"],
|
|
3552
|
+
"bg-muted": [],
|
|
3553
|
+
"fg-accent": ["italic", "bold"],
|
|
3554
|
+
"bg-accent": [],
|
|
3555
|
+
"fg-on-accent": [],
|
|
3556
|
+
"border-accent": [],
|
|
3557
|
+
"fg-accent-hover": ["italic", "bold"],
|
|
3558
|
+
"bg-accent-hover": [],
|
|
3559
|
+
"fg-accent-active": ["italic", "bold"],
|
|
3560
|
+
"bg-accent-active": [],
|
|
3561
|
+
"fg-info": ["italic"],
|
|
3562
|
+
"bg-info": [],
|
|
3563
|
+
"fg-on-info": [],
|
|
3564
|
+
"bg-info-hover": [],
|
|
3565
|
+
"bg-info-active": [],
|
|
3566
|
+
"fg-success": ["bold"],
|
|
3567
|
+
"bg-success": [],
|
|
3568
|
+
"fg-on-success": [],
|
|
3569
|
+
"bg-success-hover": [],
|
|
3570
|
+
"bg-success-active": [],
|
|
3571
|
+
"fg-warning": ["bold"],
|
|
3572
|
+
"bg-warning": [],
|
|
3573
|
+
"fg-on-warning": [],
|
|
3574
|
+
"bg-warning-hover": [],
|
|
3575
|
+
"bg-warning-active": [],
|
|
3576
|
+
"fg-error": ["bold", "inverse"],
|
|
3577
|
+
"bg-error": [],
|
|
3578
|
+
"fg-on-error": ["inverse"],
|
|
3579
|
+
"bg-error-hover": [],
|
|
3580
|
+
"bg-error-active": [],
|
|
3581
|
+
"bg-surface-default": [],
|
|
3582
|
+
"bg-surface-subtle": [],
|
|
3583
|
+
"bg-surface-raised": [],
|
|
3584
|
+
"bg-surface-overlay": [],
|
|
3585
|
+
"bg-surface-hover": [],
|
|
3586
|
+
"border-default": [],
|
|
3587
|
+
"border-focus": ["bold"],
|
|
3588
|
+
"border-muted": [],
|
|
3589
|
+
"fg-cursor": [],
|
|
3590
|
+
"bg-cursor": [],
|
|
3591
|
+
"bg-selected": ["inverse"],
|
|
3592
|
+
"fg-on-selected": [],
|
|
3593
|
+
"bg-selected-hover": ["inverse"],
|
|
3594
|
+
"bg-inverse": ["inverse"],
|
|
3595
|
+
"fg-on-inverse": [],
|
|
3596
|
+
"fg-link": ["underline"]
|
|
3597
|
+
};
|
|
3598
|
+
}));
|
|
3599
|
+
//#endregion
|
|
3600
|
+
//#region packages/ansi/src/theme/fingerprint.ts
|
|
3601
|
+
/**
|
|
3602
|
+
* Map ΔE thresholds into a 0–1 confidence.
|
|
3603
|
+
*
|
|
3604
|
+
* sumΔE=0 + maxΔE=0 → 1.0 (perfect match)
|
|
3605
|
+
* sumΔE=30 (threshold) → ~0.5
|
|
3606
|
+
* sumΔE≥60 → ~0.0
|
|
3607
|
+
*/
|
|
3608
|
+
function computeConfidence(sumDE, maxDE, sumThreshold) {
|
|
3609
|
+
const sumScore = Math.max(0, 1 - sumDE / (sumThreshold * 2));
|
|
3610
|
+
const maxScore = Math.max(0, 1 - maxDE / 16);
|
|
3611
|
+
return Math.max(0, Math.min(1, .7 * sumScore + .3 * maxScore));
|
|
3612
|
+
}
|
|
3613
|
+
/**
|
|
3614
|
+
* Match probed slots against a catalog, returning the best candidate if it
|
|
3615
|
+
* satisfies both sum and per-slot thresholds. Returns `null` if nothing matches.
|
|
3616
|
+
*
|
|
3617
|
+
* `probed` is a partial ColorScheme — whatever slots OSC queries returned. Missing
|
|
3618
|
+
* slots are skipped (still counted as "not compared"). Non-hex values are
|
|
3619
|
+
* ignored (ΔE can't be computed).
|
|
3620
|
+
*/
|
|
3621
|
+
function fingerprintMatch(probed, catalog, opts = {}) {
|
|
3622
|
+
const sumThreshold = opts.sumThreshold ?? 30;
|
|
3623
|
+
const perSlotThreshold = opts.perSlotThreshold ?? 8;
|
|
3624
|
+
let best = null;
|
|
3625
|
+
for (const scheme of catalog) {
|
|
3626
|
+
let sumDE = 0;
|
|
3627
|
+
let maxDE = 0;
|
|
3628
|
+
let slotsCompared = 0;
|
|
3629
|
+
for (const field of FINGERPRINT_FIELDS) {
|
|
3630
|
+
const probedVal = probed[field];
|
|
3631
|
+
const catalogVal = scheme[field];
|
|
3632
|
+
if (typeof probedVal !== "string" || typeof catalogVal !== "string") continue;
|
|
3633
|
+
const de = colorDistance(probedVal, catalogVal);
|
|
3634
|
+
if (de === null) continue;
|
|
3635
|
+
const scaled = de * 100;
|
|
3636
|
+
sumDE += scaled;
|
|
3637
|
+
if (scaled > maxDE) maxDE = scaled;
|
|
3638
|
+
slotsCompared++;
|
|
3639
|
+
}
|
|
3640
|
+
if (slotsCompared === 0) continue;
|
|
3641
|
+
if (maxDE > perSlotThreshold) continue;
|
|
3642
|
+
if (sumDE > sumThreshold) continue;
|
|
3643
|
+
if (best === null || sumDE < best.sumDeltaE) best = {
|
|
3644
|
+
scheme,
|
|
3645
|
+
sumDeltaE: sumDE,
|
|
3646
|
+
maxDeltaE: maxDE,
|
|
3647
|
+
slotsCompared,
|
|
3648
|
+
confidence: computeConfidence(sumDE, maxDE, sumThreshold)
|
|
3649
|
+
};
|
|
3650
|
+
}
|
|
3651
|
+
return best;
|
|
3652
|
+
}
|
|
3653
|
+
var FINGERPRINT_FIELDS;
|
|
3654
|
+
var init_fingerprint = __esmMin((() => {
|
|
3655
|
+
FINGERPRINT_FIELDS = [
|
|
3656
|
+
"foreground",
|
|
3657
|
+
"background",
|
|
3658
|
+
"black",
|
|
3659
|
+
"red",
|
|
3660
|
+
"green",
|
|
3661
|
+
"yellow",
|
|
3662
|
+
"blue",
|
|
3663
|
+
"magenta",
|
|
3664
|
+
"cyan",
|
|
3665
|
+
"white",
|
|
3666
|
+
"brightBlack",
|
|
3667
|
+
"brightRed",
|
|
3668
|
+
"brightGreen",
|
|
3669
|
+
"brightYellow",
|
|
3670
|
+
"brightBlue",
|
|
3671
|
+
"brightMagenta",
|
|
3672
|
+
"brightCyan",
|
|
3673
|
+
"brightWhite"
|
|
3674
|
+
];
|
|
3675
|
+
}));
|
|
3676
|
+
//#endregion
|
|
3677
|
+
//#region packages/ansi/src/theme/types.ts
|
|
3678
|
+
var COLOR_SCHEME_FIELDS;
|
|
3679
|
+
var init_types = __esmMin((() => {
|
|
3680
|
+
COLOR_SCHEME_FIELDS = [
|
|
3681
|
+
"black",
|
|
3682
|
+
"red",
|
|
3683
|
+
"green",
|
|
3684
|
+
"yellow",
|
|
3685
|
+
"blue",
|
|
3686
|
+
"magenta",
|
|
3687
|
+
"cyan",
|
|
3688
|
+
"white",
|
|
3689
|
+
"brightBlack",
|
|
3690
|
+
"brightRed",
|
|
3691
|
+
"brightGreen",
|
|
3692
|
+
"brightYellow",
|
|
3693
|
+
"brightBlue",
|
|
3694
|
+
"brightMagenta",
|
|
3695
|
+
"brightCyan",
|
|
3696
|
+
"brightWhite",
|
|
3697
|
+
"foreground",
|
|
3698
|
+
"background",
|
|
3699
|
+
"cursorColor",
|
|
3700
|
+
"cursorText",
|
|
3701
|
+
"selectionBackground",
|
|
3702
|
+
"selectionForeground"
|
|
3703
|
+
];
|
|
3704
|
+
}));
|
|
3705
|
+
//#endregion
|
|
3706
|
+
//#region packages/ansi/src/theme/orchestrator.ts
|
|
3707
|
+
function envOverride() {
|
|
3708
|
+
const v = process.env.SILVERY_COLOR;
|
|
3709
|
+
if (!v) return null;
|
|
3710
|
+
if (v === "truecolor" || v === "256" || v === "ansi16" || v === "scheme" || v === "mono" || v === "auto") return v;
|
|
3711
|
+
return null;
|
|
3712
|
+
}
|
|
3713
|
+
/**
|
|
3714
|
+
* Detect the terminal's color scheme + derive a theme in one call.
|
|
3715
|
+
*
|
|
3716
|
+
* Runs the 4-layer detection cascade (override → probe → fingerprint →
|
|
3717
|
+
* fallback) and returns a fully-resolved Theme along with provenance metadata
|
|
3718
|
+
* so callers can log how the scheme was determined.
|
|
3719
|
+
*
|
|
3720
|
+
* This is the recommended entry point for apps — it handles all the gotchas
|
|
3721
|
+
* (non-TTY environments, failed probes, partial OSC responses, catalog matches,
|
|
3722
|
+
* bg-mode inference) and returns something you can hand to `ThemeProvider`.
|
|
3723
|
+
*
|
|
3724
|
+
* @example
|
|
3725
|
+
* ```ts
|
|
3726
|
+
* import { detectScheme } from "@silvery/ansi"
|
|
3727
|
+
* import { builtinPalettes } from "@silvery/theme/schemes"
|
|
3728
|
+
*
|
|
3729
|
+
* const { scheme, theme, source, matchedName, confidence } = await detectScheme({
|
|
3730
|
+
* catalog: Object.values(builtinPalettes),
|
|
3731
|
+
* enforce: "lenient",
|
|
3732
|
+
* })
|
|
3733
|
+
* console.log(`${source === "fingerprint" ? `detected ${matchedName}` : source} (${(confidence * 100).toFixed(0)}%)`)
|
|
3734
|
+
* ```
|
|
3735
|
+
*/
|
|
3736
|
+
async function detectScheme(opts = {}) {
|
|
3737
|
+
const enforce = opts.enforce ?? "lenient";
|
|
3738
|
+
const wcag = opts.wcag ?? false;
|
|
3739
|
+
if (opts.override) {
|
|
3740
|
+
const theme = loadTheme(opts.override, {
|
|
3741
|
+
enforce,
|
|
3742
|
+
wcag
|
|
3743
|
+
});
|
|
3744
|
+
return {
|
|
3745
|
+
scheme: opts.override,
|
|
3746
|
+
theme,
|
|
3747
|
+
source: "override",
|
|
3748
|
+
confidence: 1,
|
|
3749
|
+
slotSources: allSlotsFrom("fallback"),
|
|
3750
|
+
matchedName: opts.override.name
|
|
3751
|
+
};
|
|
3752
|
+
}
|
|
3753
|
+
const envMode = envOverride();
|
|
3754
|
+
if (envMode === "mono" || envMode === "ansi16") {
|
|
3755
|
+
const fallback = opts.darkFallback !== false ? defaultDarkScheme : defaultLightScheme;
|
|
3756
|
+
return {
|
|
3757
|
+
scheme: fallback,
|
|
3758
|
+
theme: loadTheme(fallback, {
|
|
3759
|
+
enforce,
|
|
3760
|
+
wcag
|
|
3761
|
+
}),
|
|
3762
|
+
source: "override",
|
|
3763
|
+
confidence: 1,
|
|
3764
|
+
slotSources: allSlotsFrom("fallback"),
|
|
3765
|
+
matchedName: fallback.name
|
|
3766
|
+
};
|
|
3767
|
+
}
|
|
3768
|
+
const detected = await probeColors({
|
|
3769
|
+
timeoutMs: opts.timeoutMs,
|
|
3770
|
+
input: opts.input
|
|
3771
|
+
});
|
|
3772
|
+
if (!detected) {
|
|
3773
|
+
const fallback = opts.darkFallback !== false ? defaultDarkScheme : defaultLightScheme;
|
|
3774
|
+
return {
|
|
3775
|
+
scheme: fallback,
|
|
3776
|
+
theme: loadTheme(fallback, {
|
|
3777
|
+
enforce,
|
|
3778
|
+
wcag
|
|
3779
|
+
}),
|
|
3780
|
+
source: "fallback",
|
|
3781
|
+
confidence: 0,
|
|
3782
|
+
slotSources: allSlotsFrom("fallback"),
|
|
3783
|
+
matchedName: fallback.name
|
|
3784
|
+
};
|
|
3785
|
+
}
|
|
3786
|
+
const catalog = opts.catalog ?? [];
|
|
3787
|
+
if (catalog.length > 0) {
|
|
3788
|
+
const match = fingerprintMatch(detected.palette, catalog);
|
|
3789
|
+
if (match) {
|
|
3790
|
+
const theme = loadTheme(match.scheme, {
|
|
3791
|
+
enforce,
|
|
3792
|
+
wcag
|
|
3793
|
+
});
|
|
3794
|
+
return {
|
|
3795
|
+
scheme: match.scheme,
|
|
3796
|
+
theme,
|
|
3797
|
+
source: "fingerprint",
|
|
3798
|
+
confidence: match.confidence,
|
|
3799
|
+
slotSources: allSlotsFrom("catalog"),
|
|
3800
|
+
matchedName: match.scheme.name
|
|
3801
|
+
};
|
|
3802
|
+
}
|
|
3803
|
+
}
|
|
3804
|
+
const fallback = detected.dark ? defaultDarkScheme : defaultLightScheme;
|
|
3805
|
+
const probedSlots = stripNulls(detected.palette);
|
|
3806
|
+
const derivedSlots = deriveMissingSlotsFromProbe(probedSlots);
|
|
3807
|
+
const merged = {
|
|
3808
|
+
...fallback,
|
|
3809
|
+
...derivedSlots,
|
|
3810
|
+
...probedSlots
|
|
3811
|
+
};
|
|
3812
|
+
const theme = loadTheme(merged, {
|
|
3813
|
+
enforce,
|
|
3814
|
+
wcag
|
|
3815
|
+
});
|
|
3816
|
+
const slotSources = {};
|
|
3817
|
+
for (const field of COLOR_SCHEME_FIELDS) slotSources[field] = typeof detected.palette[field] === "string" ? "probed" : field in derivedSlots ? "derived" : "fallback";
|
|
3818
|
+
const probedCount = Object.values(slotSources).filter((s) => s === "probed").length;
|
|
3819
|
+
return {
|
|
3820
|
+
scheme: merged,
|
|
3821
|
+
theme,
|
|
3822
|
+
source: "probed",
|
|
3823
|
+
confidence: Math.min(1, probedCount / 18),
|
|
3824
|
+
slotSources,
|
|
3825
|
+
matchedName: void 0
|
|
3826
|
+
};
|
|
3827
|
+
}
|
|
3828
|
+
function stripNulls(partial) {
|
|
3829
|
+
const result = {};
|
|
3830
|
+
for (const [k, v] of Object.entries(partial)) if (v != null) result[k] = v;
|
|
3831
|
+
return result;
|
|
3832
|
+
}
|
|
3833
|
+
function deriveMissingSlotsFromProbe(probed) {
|
|
3834
|
+
const out = {};
|
|
3835
|
+
if (typeof probed.background === "string" && typeof probed.foreground === "string" && typeof probed.selectionBackground !== "string") out.selectionBackground = blend(probed.background, probed.foreground, .16);
|
|
3836
|
+
if (typeof probed.foreground === "string" && typeof probed.selectionForeground !== "string") out.selectionForeground = probed.foreground;
|
|
3837
|
+
return out;
|
|
3838
|
+
}
|
|
3839
|
+
function allSlotsFrom(src) {
|
|
3840
|
+
const out = {};
|
|
3841
|
+
for (const field of COLOR_SCHEME_FIELDS) out[field] = src;
|
|
3842
|
+
return out;
|
|
3843
|
+
}
|
|
3844
|
+
/**
|
|
3845
|
+
* Shortcut: detect scheme + return the Theme only. For apps that don't care
|
|
3846
|
+
* about provenance. Same defaults as `detectScheme`.
|
|
3847
|
+
*
|
|
3848
|
+
* @example
|
|
3849
|
+
* ```ts
|
|
3850
|
+
* const theme = await detectSchemeTheme({ catalog: Object.values(builtinPalettes) })
|
|
3851
|
+
* render(<ThemeProvider theme={theme}>…</ThemeProvider>)
|
|
3852
|
+
* ```
|
|
3853
|
+
*/
|
|
3854
|
+
async function detectSchemeTheme(opts = {}) {
|
|
3855
|
+
const { theme } = await detectScheme(opts);
|
|
3856
|
+
return theme;
|
|
3857
|
+
}
|
|
3858
|
+
var init_orchestrator = __esmMin((() => {
|
|
3859
|
+
init_types();
|
|
3860
|
+
init_derive();
|
|
3861
|
+
init_detect();
|
|
3862
|
+
init_fingerprint();
|
|
3863
|
+
init_default_schemes();
|
|
3864
|
+
}));
|
|
3865
|
+
//#endregion
|
|
3866
|
+
//#region packages/ansi/src/theme/tokens.ts
|
|
3867
|
+
var KNOWN_VARIANTS;
|
|
3868
|
+
var init_tokens = __esmMin((() => {
|
|
3869
|
+
KNOWN_VARIANTS = [
|
|
3870
|
+
"h1",
|
|
3871
|
+
"h2",
|
|
3872
|
+
"h3",
|
|
3873
|
+
"body",
|
|
3874
|
+
"body-muted",
|
|
3875
|
+
"fine-print",
|
|
3876
|
+
"strong",
|
|
3877
|
+
"em",
|
|
3878
|
+
"link",
|
|
3879
|
+
"key",
|
|
3880
|
+
"code",
|
|
3881
|
+
"kbd"
|
|
3882
|
+
];
|
|
3883
|
+
})), CSI;
|
|
3884
|
+
var init_color_scheme = __esmMin((() => {
|
|
3885
|
+
CSI = `[`;
|
|
3886
|
+
`${CSI}`;
|
|
3887
|
+
`${CSI}`;
|
|
3888
|
+
}));
|
|
3889
|
+
//#endregion
|
|
3890
|
+
//#region packages/ansi/src/theme/generators.ts
|
|
3891
|
+
var init_generators = __esmMin((() => {}));
|
|
3892
|
+
//#endregion
|
|
3893
|
+
//#region packages/ansi/src/theme/auto-generate.ts
|
|
3894
|
+
var init_auto_generate = __esmMin((() => {
|
|
3895
|
+
init_generators();
|
|
3896
|
+
init_derive();
|
|
3897
|
+
}));
|
|
3898
|
+
//#endregion
|
|
3899
|
+
//#region packages/ansi/src/theme/generate.ts
|
|
3900
|
+
/**
|
|
3901
|
+
* Generate a complete ANSI 16 theme from a primary color + dark/light preference.
|
|
3902
|
+
*
|
|
3903
|
+
* All token values are ANSI color names (e.g. "yellow", "blueBright").
|
|
3904
|
+
*/
|
|
3905
|
+
function generateTheme(primary, dark) {
|
|
3906
|
+
const fg = dark ? "whiteBright" : "black";
|
|
3907
|
+
const accent = primary;
|
|
3908
|
+
const selectionbg = primary;
|
|
3909
|
+
const surfacebg = dark ? "black" : "white";
|
|
3910
|
+
const derived = deriveFields({
|
|
3911
|
+
primary,
|
|
3912
|
+
accent,
|
|
3913
|
+
fg,
|
|
3914
|
+
selectionbg,
|
|
3915
|
+
surfacebg,
|
|
3916
|
+
ring: {
|
|
3917
|
+
red: dark ? "redBright" : "red",
|
|
3918
|
+
orange: dark ? "redBright" : "red",
|
|
3919
|
+
yellow: "yellow",
|
|
3920
|
+
green: dark ? "greenBright" : "green",
|
|
3921
|
+
teal: "cyan",
|
|
3922
|
+
blue: dark ? "blueBright" : "blue",
|
|
3923
|
+
purple: "magenta",
|
|
3924
|
+
pink: dark ? "magentaBright" : "magenta"
|
|
3925
|
+
}
|
|
3926
|
+
});
|
|
3927
|
+
return {
|
|
3928
|
+
name: `${dark ? "dark" : "light"}-${primary}`,
|
|
3929
|
+
bg: "",
|
|
3930
|
+
fg,
|
|
3931
|
+
muted: dark ? "white" : "blackBright",
|
|
3932
|
+
mutedbg: dark ? "black" : "white",
|
|
3933
|
+
surface: dark ? "whiteBright" : "black",
|
|
3934
|
+
surfacebg,
|
|
3935
|
+
popover: dark ? "whiteBright" : "black",
|
|
3936
|
+
popoverbg: dark ? "blackBright" : "white",
|
|
3937
|
+
inverse: dark ? "black" : "whiteBright",
|
|
3938
|
+
inversebg: dark ? "whiteBright" : "black",
|
|
3939
|
+
cursor: "black",
|
|
3940
|
+
cursorbg: primary,
|
|
3941
|
+
selection: "black",
|
|
3942
|
+
selectionbg: primary,
|
|
3943
|
+
primary,
|
|
3944
|
+
primaryfg: "black",
|
|
3945
|
+
secondary: primary,
|
|
3946
|
+
secondaryfg: "black",
|
|
3947
|
+
accent: primary,
|
|
3948
|
+
accentfg: "black",
|
|
3949
|
+
error: dark ? "redBright" : "red",
|
|
3950
|
+
errorfg: "black",
|
|
3951
|
+
warning: primary,
|
|
3952
|
+
warningfg: "black",
|
|
3953
|
+
success: dark ? "greenBright" : "green",
|
|
3954
|
+
successfg: "black",
|
|
3955
|
+
info: dark ? "cyanBright" : "cyan",
|
|
3956
|
+
infofg: "black",
|
|
3957
|
+
border: "gray",
|
|
3958
|
+
inputborder: "gray",
|
|
3959
|
+
focusborder: dark ? "blueBright" : "blue",
|
|
3960
|
+
link: "blueBright",
|
|
3961
|
+
disabledfg: "gray",
|
|
3962
|
+
palette: [
|
|
3963
|
+
"black",
|
|
3964
|
+
"red",
|
|
3965
|
+
"green",
|
|
3966
|
+
"yellow",
|
|
3967
|
+
"blue",
|
|
3968
|
+
"magenta",
|
|
3969
|
+
"cyan",
|
|
3970
|
+
"white",
|
|
3971
|
+
"blackBright",
|
|
3972
|
+
"redBright",
|
|
3973
|
+
"greenBright",
|
|
3974
|
+
"yellowBright",
|
|
3975
|
+
"blueBright",
|
|
3976
|
+
"magentaBright",
|
|
3977
|
+
"cyanBright",
|
|
3978
|
+
"whiteBright"
|
|
3979
|
+
],
|
|
3980
|
+
...derived
|
|
3981
|
+
};
|
|
3982
|
+
}
|
|
3983
|
+
var init_generate = __esmMin((() => {
|
|
3984
|
+
init_derived();
|
|
3985
|
+
}));
|
|
3986
|
+
//#endregion
|
|
3987
|
+
//#region packages/ansi/src/sterling/flat-tokens.ts
|
|
3988
|
+
var STERLING_FLAT_TOKENS;
|
|
3989
|
+
var init_flat_tokens = __esmMin((() => {
|
|
3990
|
+
STERLING_FLAT_TOKENS = [
|
|
3991
|
+
"bg-surface-default",
|
|
3992
|
+
"bg-surface-subtle",
|
|
3993
|
+
"bg-surface-raised",
|
|
3994
|
+
"bg-surface-overlay",
|
|
3995
|
+
"bg-surface-hover",
|
|
3996
|
+
"border-default",
|
|
3997
|
+
"border-focus",
|
|
3998
|
+
"border-muted",
|
|
3999
|
+
"fg-cursor",
|
|
4000
|
+
"bg-cursor",
|
|
4001
|
+
"fg-muted",
|
|
4002
|
+
"bg-muted",
|
|
4003
|
+
"fg-accent",
|
|
4004
|
+
"bg-accent",
|
|
4005
|
+
"fg-on-accent",
|
|
4006
|
+
"fg-accent-hover",
|
|
4007
|
+
"bg-accent-hover",
|
|
4008
|
+
"fg-accent-active",
|
|
4009
|
+
"bg-accent-active",
|
|
4010
|
+
"border-accent",
|
|
4011
|
+
"fg-info",
|
|
4012
|
+
"bg-info",
|
|
4013
|
+
"fg-on-info",
|
|
4014
|
+
"bg-info-hover",
|
|
4015
|
+
"bg-info-active",
|
|
4016
|
+
"fg-success",
|
|
4017
|
+
"bg-success",
|
|
4018
|
+
"fg-on-success",
|
|
4019
|
+
"bg-success-hover",
|
|
4020
|
+
"bg-success-active",
|
|
4021
|
+
"fg-warning",
|
|
4022
|
+
"bg-warning",
|
|
4023
|
+
"fg-on-warning",
|
|
4024
|
+
"bg-warning-hover",
|
|
4025
|
+
"bg-warning-active",
|
|
4026
|
+
"fg-error",
|
|
4027
|
+
"bg-error",
|
|
4028
|
+
"fg-on-error",
|
|
4029
|
+
"bg-error-hover",
|
|
4030
|
+
"bg-error-active",
|
|
4031
|
+
"bg-selected",
|
|
4032
|
+
"fg-on-selected",
|
|
4033
|
+
"bg-selected-hover",
|
|
4034
|
+
"bg-inverse",
|
|
4035
|
+
"fg-on-inverse",
|
|
4036
|
+
"fg-link",
|
|
4037
|
+
"fg-disabled",
|
|
4038
|
+
"bg-disabled",
|
|
4039
|
+
"border-disabled",
|
|
4040
|
+
"bg-backdrop",
|
|
4041
|
+
"fg-default",
|
|
4042
|
+
"bg-default"
|
|
4043
|
+
];
|
|
4044
|
+
}));
|
|
4045
|
+
//#endregion
|
|
4046
|
+
//#region packages/ansi/src/sterling/defaults.ts
|
|
4047
|
+
function defaultScheme(mode = "dark") {
|
|
4048
|
+
return mode === "dark" ? darkBaseline : lightBaseline;
|
|
4049
|
+
}
|
|
4050
|
+
var darkBaseline, lightBaseline;
|
|
4051
|
+
var init_defaults = __esmMin((() => {
|
|
4052
|
+
darkBaseline = {
|
|
4053
|
+
name: "sterling-dark",
|
|
4054
|
+
dark: true,
|
|
4055
|
+
primary: "#7FB4CA",
|
|
4056
|
+
black: "#1E1E2E",
|
|
4057
|
+
red: "#E06C75",
|
|
4058
|
+
green: "#98C379",
|
|
4059
|
+
yellow: "#E5C07B",
|
|
4060
|
+
blue: "#61AFEF",
|
|
4061
|
+
magenta: "#C678DD",
|
|
4062
|
+
cyan: "#56B6C2",
|
|
4063
|
+
white: "#ABB2BF",
|
|
4064
|
+
brightBlack: "#5C6370",
|
|
4065
|
+
brightRed: "#E06C75",
|
|
4066
|
+
brightGreen: "#98C379",
|
|
4067
|
+
brightYellow: "#E5C07B",
|
|
4068
|
+
brightBlue: "#61AFEF",
|
|
4069
|
+
brightMagenta: "#C678DD",
|
|
4070
|
+
brightCyan: "#56B6C2",
|
|
4071
|
+
brightWhite: "#FFFFFF",
|
|
4072
|
+
foreground: "#E4E4E7",
|
|
4073
|
+
background: "#16181D",
|
|
4074
|
+
cursorColor: "#E4E4E7",
|
|
4075
|
+
cursorText: "#16181D",
|
|
4076
|
+
selectionBackground: "#3E4452",
|
|
4077
|
+
selectionForeground: "#E4E4E7"
|
|
4078
|
+
};
|
|
4079
|
+
lightBaseline = {
|
|
4080
|
+
name: "sterling-light",
|
|
4081
|
+
dark: false,
|
|
4082
|
+
primary: "#1F6FEB",
|
|
4083
|
+
black: "#24292F",
|
|
4084
|
+
red: "#CF222E",
|
|
4085
|
+
green: "#1A7F37",
|
|
4086
|
+
yellow: "#9A6700",
|
|
4087
|
+
blue: "#0969DA",
|
|
4088
|
+
magenta: "#8250DF",
|
|
4089
|
+
cyan: "#1B7C83",
|
|
4090
|
+
white: "#6E7781",
|
|
4091
|
+
brightBlack: "#57606A",
|
|
4092
|
+
brightRed: "#A40E26",
|
|
4093
|
+
brightGreen: "#2DA44E",
|
|
4094
|
+
brightYellow: "#BF8700",
|
|
4095
|
+
brightBlue: "#218BFF",
|
|
4096
|
+
brightMagenta: "#A475F9",
|
|
4097
|
+
brightCyan: "#3192AA",
|
|
4098
|
+
brightWhite: "#8C959F",
|
|
4099
|
+
foreground: "#1F2328",
|
|
4100
|
+
background: "#FFFFFF",
|
|
4101
|
+
cursorColor: "#1F2328",
|
|
4102
|
+
cursorText: "#FFFFFF",
|
|
4103
|
+
selectionBackground: "#DDF4FF",
|
|
4104
|
+
selectionForeground: "#1F2328"
|
|
4105
|
+
};
|
|
4106
|
+
}));
|
|
4107
|
+
//#endregion
|
|
4108
|
+
//#region packages/ansi/src/sterling/define.ts
|
|
4109
|
+
function resolveFlatten(flatten) {
|
|
4110
|
+
if (flatten === false || flatten === void 0) return (t) => t;
|
|
4111
|
+
if (typeof flatten === "function") {
|
|
4112
|
+
const rule = flatten;
|
|
4113
|
+
return (t) => bakeFlat(t, rule);
|
|
4114
|
+
}
|
|
4115
|
+
return (t) => bakeFlat(t);
|
|
4116
|
+
}
|
|
4117
|
+
/**
|
|
4118
|
+
* Wrap a DesignSystem so every derivation method auto-applies `bakeFlat`
|
|
4119
|
+
* per the `flatten` flag. Pass your raw system (one that returns nested
|
|
4120
|
+
* themes) and this returns a user-facing system whose outputs have flat
|
|
4121
|
+
* keys populated.
|
|
4122
|
+
*/
|
|
4123
|
+
function defineDesignSystem(def) {
|
|
4124
|
+
const flatten = resolveFlatten(def.flatten);
|
|
4125
|
+
return {
|
|
4126
|
+
name: def.name,
|
|
4127
|
+
shape: def.shape,
|
|
4128
|
+
flatten: def.flatten,
|
|
4129
|
+
defaults: (mode) => flatten(def.defaults(mode)),
|
|
4130
|
+
theme: (partial, opts) => flatten(def.theme(partial, opts)),
|
|
4131
|
+
deriveFromScheme: (scheme, opts) => flatten(def.deriveFromScheme(scheme, opts)),
|
|
4132
|
+
deriveFromColor: (color, opts) => flatten(def.deriveFromColor(color, opts)),
|
|
4133
|
+
deriveFromPair: (light, dark, opts) => {
|
|
4134
|
+
const pair = def.deriveFromPair(light, dark, opts);
|
|
4135
|
+
return {
|
|
4136
|
+
light: flatten(pair.light),
|
|
4137
|
+
dark: flatten(pair.dark)
|
|
4138
|
+
};
|
|
4139
|
+
},
|
|
4140
|
+
deriveFromSchemeWithBrand: (scheme, brand, opts) => flatten(def.deriveFromSchemeWithBrand(scheme, brand, opts))
|
|
4141
|
+
};
|
|
4142
|
+
}
|
|
4143
|
+
var init_define = __esmMin((() => {
|
|
4144
|
+
init_flatten();
|
|
4145
|
+
}));
|
|
4146
|
+
//#endregion
|
|
4147
|
+
//#region packages/ansi/src/sterling/sterling.ts
|
|
4148
|
+
/**
|
|
4149
|
+
* Sterling — silvery's canonical DesignSystem.
|
|
4150
|
+
*
|
|
4151
|
+
* This is the default system shipped from `@silvery/theme`. It implements
|
|
4152
|
+
* the `DesignSystem` contract from `types.ts` and serves as the reference
|
|
4153
|
+
* for alternative systems (`@silvery/design-material`, `-primer`, etc.).
|
|
4154
|
+
*
|
|
4155
|
+
* The flat-projection (`theme["bg-accent"]` as a sibling of `theme.accent.bg`
|
|
4156
|
+
* on the same object) is NOT Sterling-specific — it's a framework feature.
|
|
4157
|
+
* Sterling opts in via `flatten: true` in {@link defineDesignSystem}, which
|
|
4158
|
+
* auto-applies `bakeFlat` (from `@silvery/ansi`) to every derivation's
|
|
4159
|
+
* output. The default rule is channel-role-state (`fg-accent`, `bg-accent-hover`,
|
|
4160
|
+
* `fg-on-error`, `bg-surface-subtle`, `border-focus`, …) — exactly what
|
|
4161
|
+
* Sterling's pre-generalization `populateFlat` produced.
|
|
4162
|
+
*
|
|
4163
|
+
* All derivation functions return a frozen Theme with both nested roles
|
|
4164
|
+
* AND flat hyphen keys populated — the user-facing `$fg-accent` syntax
|
|
4165
|
+
* resolves against the flat keys, while programmatic access uses nested.
|
|
4166
|
+
*/
|
|
4167
|
+
/**
|
|
4168
|
+
* Internal: build a nested Theme (no flat keys). `defineDesignSystem` applies
|
|
4169
|
+
* `bakeFlat` afterwards — the inner derivation stays flat-agnostic.
|
|
4170
|
+
*
|
|
4171
|
+
* Also pre-populates the standalone flat tokens that don't come from a role
|
|
4172
|
+
* walk: `bg-backdrop` (modal scrim), and `fg-default`/`bg-default` (explicit
|
|
4173
|
+
* aliases for canvas fg/bg). bakeFlat preserves pre-existing root-level
|
|
4174
|
+
* hyphen keys, so writing these here is the simplest seam.
|
|
4175
|
+
*/
|
|
4176
|
+
function buildRawTheme(scheme, opts = {}) {
|
|
4177
|
+
const base = deriveTheme$1(scheme, opts);
|
|
4178
|
+
const out = base;
|
|
4179
|
+
if (typeof out["bg-backdrop"] !== "string") out["bg-backdrop"] = blend(scheme.background, "#000000", .4);
|
|
4180
|
+
if (typeof out["fg-default"] !== "string") out["fg-default"] = scheme.foreground;
|
|
4181
|
+
if (typeof out["bg-default"] !== "string") out["bg-default"] = scheme.background;
|
|
4182
|
+
return base;
|
|
4183
|
+
}
|
|
4184
|
+
/**
|
|
4185
|
+
* Apply a brand overlay to a ColorScheme — overrides `primary` and relevant
|
|
4186
|
+
* ANSI hue slots with the brand color. Keeps the rest of the scheme intact.
|
|
4187
|
+
* Per Appendix F: brand is a theme INPUT, not a public token sibling of accent.
|
|
4188
|
+
*/
|
|
4189
|
+
function applyBrand(scheme, brand) {
|
|
4190
|
+
return {
|
|
4191
|
+
...scheme,
|
|
4192
|
+
primary: brand
|
|
4193
|
+
};
|
|
4194
|
+
}
|
|
4195
|
+
var STERLING_SHAPE, rawSterling, sterling;
|
|
4196
|
+
var init_sterling$1 = __esmMin((() => {
|
|
4197
|
+
init_derive$1();
|
|
4198
|
+
init_flat_tokens();
|
|
4199
|
+
init_defaults();
|
|
4200
|
+
init_define();
|
|
4201
|
+
STERLING_SHAPE = {
|
|
4202
|
+
flatTokens: STERLING_FLAT_TOKENS,
|
|
4203
|
+
roles: [
|
|
4204
|
+
"accent",
|
|
4205
|
+
"info",
|
|
4206
|
+
"success",
|
|
4207
|
+
"warning",
|
|
4208
|
+
"error",
|
|
4209
|
+
"muted",
|
|
4210
|
+
"surface",
|
|
4211
|
+
"border",
|
|
4212
|
+
"cursor",
|
|
4213
|
+
"selected",
|
|
4214
|
+
"inverse",
|
|
4215
|
+
"link",
|
|
4216
|
+
"disabled"
|
|
4217
|
+
],
|
|
4218
|
+
states: ["hover", "active"]
|
|
4219
|
+
};
|
|
4220
|
+
rawSterling = {
|
|
4221
|
+
name: "sterling",
|
|
4222
|
+
shape: STERLING_SHAPE,
|
|
4223
|
+
flatten: true,
|
|
4224
|
+
defaults(mode = "dark") {
|
|
4225
|
+
return buildRawTheme(defaultScheme(mode), { contrast: "auto-lift" });
|
|
4226
|
+
},
|
|
4227
|
+
theme(partial, opts = {}) {
|
|
4228
|
+
const base = buildRawTheme(defaultScheme(opts.mode ?? "dark"), {
|
|
4229
|
+
...opts,
|
|
4230
|
+
contrast: opts.contrast ?? "auto-lift"
|
|
4231
|
+
});
|
|
4232
|
+
if (!partial) return base;
|
|
4233
|
+
return mergePartial(base, partial);
|
|
4234
|
+
},
|
|
4235
|
+
deriveFromScheme(scheme, opts = {}) {
|
|
4236
|
+
return buildRawTheme(scheme, opts);
|
|
4237
|
+
},
|
|
4238
|
+
deriveFromColor(color, opts = {}) {
|
|
4239
|
+
return buildRawTheme({
|
|
4240
|
+
...defaultScheme(opts.mode ?? "dark"),
|
|
4241
|
+
name: `seed:${color}`,
|
|
4242
|
+
primary: color,
|
|
4243
|
+
blue: color,
|
|
4244
|
+
brightBlue: blend(color, "#ffffff", .15)
|
|
4245
|
+
}, opts);
|
|
4246
|
+
},
|
|
4247
|
+
deriveFromPair(light, dark, opts = {}) {
|
|
4248
|
+
return {
|
|
4249
|
+
light: buildRawTheme(light, {
|
|
4250
|
+
...opts,
|
|
4251
|
+
mode: "light"
|
|
4252
|
+
}),
|
|
4253
|
+
dark: buildRawTheme(dark, {
|
|
4254
|
+
...opts,
|
|
4255
|
+
mode: "dark"
|
|
4256
|
+
})
|
|
4257
|
+
};
|
|
4258
|
+
},
|
|
4259
|
+
deriveFromSchemeWithBrand(scheme, brand, opts = {}) {
|
|
4260
|
+
return buildRawTheme(applyBrand(scheme, brand), opts);
|
|
4261
|
+
}
|
|
4262
|
+
};
|
|
4263
|
+
sterling = defineDesignSystem(rawSterling);
|
|
4264
|
+
}));
|
|
4265
|
+
//#endregion
|
|
4266
|
+
//#region packages/ansi/src/sterling/token-manifest.ts
|
|
4267
|
+
function capitalize(s) {
|
|
4268
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
4269
|
+
}
|
|
4270
|
+
function seedRule(role) {
|
|
4271
|
+
switch (role) {
|
|
4272
|
+
case "info": return "scheme.primary (info mirrors accent's seed).";
|
|
4273
|
+
case "success": return "scheme.green.";
|
|
4274
|
+
case "warning": return "scheme.yellow.";
|
|
4275
|
+
case "error": return "scheme.red.";
|
|
4276
|
+
}
|
|
4277
|
+
}
|
|
4278
|
+
var AA, NA;
|
|
4279
|
+
var init_token_manifest = __esmMin((() => {
|
|
4280
|
+
AA = "AA 4.5:1";
|
|
4281
|
+
NA = "—";
|
|
4282
|
+
[...[
|
|
4283
|
+
"info",
|
|
4284
|
+
"success",
|
|
4285
|
+
"warning",
|
|
4286
|
+
"error"
|
|
4287
|
+
].flatMap((role) => [
|
|
4288
|
+
{
|
|
4289
|
+
flat: `fg-${role}`,
|
|
4290
|
+
path: `${role}.fg`,
|
|
4291
|
+
family: role,
|
|
4292
|
+
axis: "fg",
|
|
4293
|
+
purpose: `${capitalize(role)} status text.`,
|
|
4294
|
+
derivation: seedRule(role),
|
|
4295
|
+
contrast: AA,
|
|
4296
|
+
tierNotes: "Seeds from the matching ANSI palette slot."
|
|
4297
|
+
},
|
|
4298
|
+
{
|
|
4299
|
+
flat: `bg-${role}`,
|
|
4300
|
+
path: `${role}.bg`,
|
|
4301
|
+
family: role,
|
|
4302
|
+
axis: "bg",
|
|
4303
|
+
purpose: `${capitalize(role)} fill — alerts, badges.`,
|
|
4304
|
+
derivation: seedRule(role),
|
|
4305
|
+
contrast: NA,
|
|
4306
|
+
tierNotes: "Distinct from siblings in ALL 84 palettes (collision test)."
|
|
4307
|
+
},
|
|
4308
|
+
{
|
|
4309
|
+
flat: `fg-on-${role}`,
|
|
4310
|
+
path: `${role}.fgOn`,
|
|
4311
|
+
family: role,
|
|
4312
|
+
axis: "fg-on",
|
|
4313
|
+
purpose: `Foreground when drawing text ON \`bg-${role}\`.`,
|
|
4314
|
+
derivation: "contrast-pick(scheme.fg / scheme.bg / black / white) for AA on bg.",
|
|
4315
|
+
contrast: AA,
|
|
4316
|
+
tierNotes: "Pre-quantization pick."
|
|
4317
|
+
},
|
|
4318
|
+
{
|
|
4319
|
+
flat: `bg-${role}-hover`,
|
|
4320
|
+
path: `${role}.hover.bg`,
|
|
4321
|
+
family: role,
|
|
4322
|
+
axis: "bg-hover",
|
|
4323
|
+
purpose: `Hover fill for ${role} surfaces.`,
|
|
4324
|
+
derivation: `OKLCH ±0.04L on bg-${role}.`,
|
|
4325
|
+
contrast: NA,
|
|
4326
|
+
tierNotes: "Often collapses with bg in ansi16."
|
|
4327
|
+
},
|
|
4328
|
+
{
|
|
4329
|
+
flat: `bg-${role}-active`,
|
|
4330
|
+
path: `${role}.active.bg`,
|
|
4331
|
+
family: role,
|
|
4332
|
+
axis: "bg-active",
|
|
4333
|
+
purpose: `Pressed/active fill for ${role} surfaces.`,
|
|
4334
|
+
derivation: `OKLCH ±0.08L on bg-${role}.`,
|
|
4335
|
+
contrast: NA,
|
|
4336
|
+
tierNotes: "Collapses to bg in low tiers."
|
|
4337
|
+
}
|
|
4338
|
+
])];
|
|
4339
|
+
}));
|
|
4340
|
+
//#endregion
|
|
4341
|
+
//#region packages/ansi/src/sterling/index.ts
|
|
4342
|
+
var init_sterling = __esmMin((() => {
|
|
4343
|
+
init_sterling$1();
|
|
4344
|
+
init_define();
|
|
4345
|
+
init_derive$1();
|
|
4346
|
+
init_inline();
|
|
4347
|
+
init_flat_tokens();
|
|
4348
|
+
init_token_manifest();
|
|
4349
|
+
init_defaults();
|
|
4350
|
+
init_contrast();
|
|
4351
|
+
}));
|
|
4352
|
+
//#endregion
|
|
4353
|
+
//#region packages/ansi/src/index.ts
|
|
4354
|
+
var init_src = __esmMin((() => {
|
|
4355
|
+
init_caps();
|
|
4356
|
+
init_profile();
|
|
4357
|
+
init_sgr_codes();
|
|
4358
|
+
init_utils();
|
|
4359
|
+
init_color_maps();
|
|
4360
|
+
init_flatten();
|
|
4361
|
+
init_terminal_control();
|
|
4362
|
+
init_kitty_graphics();
|
|
4363
|
+
init_style();
|
|
4364
|
+
init_mixed_proxy();
|
|
4365
|
+
init_colors();
|
|
4366
|
+
init_derive();
|
|
4367
|
+
init_derived();
|
|
4368
|
+
init_monochrome();
|
|
4369
|
+
init_fingerprint();
|
|
4370
|
+
init_orchestrator();
|
|
4371
|
+
init_invariants();
|
|
4372
|
+
init_default_schemes();
|
|
4373
|
+
init_types();
|
|
4374
|
+
init_tokens();
|
|
4375
|
+
init_detect();
|
|
4376
|
+
init_protocol_error();
|
|
4377
|
+
init_osc_palette();
|
|
4378
|
+
init_color_scheme();
|
|
4379
|
+
init_generators();
|
|
4380
|
+
init_auto_generate();
|
|
4381
|
+
init_generate();
|
|
4382
|
+
init_sterling();
|
|
4383
|
+
}));
|
|
4384
|
+
//#endregion
|
|
4385
|
+
export { queryMultiplePaletteColors as $, bgColorCode as A, detectColorScheme as B, disableMouse as C, bakeFlat as D, enableMouse as E, pickColorLevel as F, resetCursorColor as G, queryCursorColor as H, quantizeHex as I, setCursorColor as J, resetForegroundColor as K, detectTerminalScheme as L, createTerminalProfile as M, probeTerminalProfile as N, defaultFlattenRule as O, ANSI16_SLOT_HEX as P, parsePaletteResponse as Q, detectTheme as R, disableKittyKeyboard as S, enableKittyKeyboard as T, queryForegroundColor as U, queryBackgroundColor as V, resetBackgroundColor as W, ProtocolError as X, setForegroundColor as Y, isProtocolError as Z, cupTo as _, STERLING_FLAT_TOKENS as a, deriveRoles as at, kittyUploadScrimImage as b, detectScheme as c, WCAG_AA as ct, monoAttrsForColorString as d, deriveFields as dt, queryPaletteColor as et, createMixedStyle as f, defaultCaps as ft, buildScrimPixels as g, backdropPlacementId as h, defaultScheme as i, deriveTheme as it, fgColorCode as j, warnOnce as k, detectSchemeTheme as l, autoLift as lt, resolveThemeColor as m, sterling as n, ansi16DarkTheme as nt, generateTheme as o, deriveTheme$1 as ot, createStyle as p, setBackgroundColor as q, defineDesignSystem as r, ansi16LightTheme as rt, KNOWN_VARIANTS as s, ContrastError as st, init_src as t, setPaletteColor as tt, COLOR_SCHEME_FIELDS as u, checkAA as ut, kittyDeleteAllScrimPlacements as v, enableBracketedPaste as w, disableBracketedPaste as x, kittyPlaceAt as y, probeColors as z };
|
|
4386
|
+
|
|
4387
|
+
//# sourceMappingURL=src-BNTToU7l.mjs.map
|