@zaly/tui 0.0.4
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/LICENSE +21 -0
- package/README.md +59 -0
- package/assets/schemas/theme.schema.json +899 -0
- package/assets/themes/LICENSE-tokyonight.txt +201 -0
- package/assets/themes/NOTICES.md +69 -0
- package/assets/themes/ayu-dark.json +119 -0
- package/assets/themes/catppuccin-frappe.json +124 -0
- package/assets/themes/catppuccin-latte.json +124 -0
- package/assets/themes/catppuccin-macchiato.json +124 -0
- package/assets/themes/catppuccin-mocha.json +124 -0
- package/assets/themes/dracula-soft.json +119 -0
- package/assets/themes/dracula.json +119 -0
- package/assets/themes/everforest-dark.json +118 -0
- package/assets/themes/everforest-light.json +118 -0
- package/assets/themes/github-dark.json +123 -0
- package/assets/themes/github-light.json +123 -0
- package/assets/themes/gruvbox-dark-medium.json +112 -0
- package/assets/themes/kanagawa-dragon.json +115 -0
- package/assets/themes/kanagawa-wave.json +115 -0
- package/assets/themes/material-theme-palenight.json +114 -0
- package/assets/themes/min-dark.json +55 -0
- package/assets/themes/min-light.json +59 -0
- package/assets/themes/monokai.json +116 -0
- package/assets/themes/night-owl.json +116 -0
- package/assets/themes/nord.json +101 -0
- package/assets/themes/one-dark-pro.json +110 -0
- package/assets/themes/one-light.json +108 -0
- package/assets/themes/poimandres.json +123 -0
- package/assets/themes/rose-pine.json +98 -0
- package/assets/themes/solarized-dark.json +116 -0
- package/assets/themes/solarized-light.json +116 -0
- package/assets/themes/synthwave-84.json +100 -0
- package/assets/themes/tokyonight-day.json +157 -0
- package/assets/themes/tokyonight-moon.json +157 -0
- package/assets/themes/tokyonight-night.json +157 -0
- package/assets/themes/tokyonight-storm.json +157 -0
- package/assets/themes/vesper.json +103 -0
- package/assets/themes/vitesse-dark.json +126 -0
- package/assets/themes/vitesse-light.json +126 -0
- package/dist/ansi-Clq0ozyA.mjs +206 -0
- package/dist/ansi-Clq0ozyA.mjs.map +1 -0
- package/dist/ansi.d.mts +48 -0
- package/dist/ansi.d.mts.map +1 -0
- package/dist/ansi.mjs +2 -0
- package/dist/autocomplete-Dfw-yQDa.d.mts +100 -0
- package/dist/autocomplete-Dfw-yQDa.d.mts.map +1 -0
- package/dist/box-DyaByEiG.mjs +386 -0
- package/dist/box-DyaByEiG.mjs.map +1 -0
- package/dist/builder-D49ECBEf.mjs +385 -0
- package/dist/builder-D49ECBEf.mjs.map +1 -0
- package/dist/callbacks-CNjGNxVw.mjs +279 -0
- package/dist/callbacks-CNjGNxVw.mjs.map +1 -0
- package/dist/client-D6C_uczF.mjs +142 -0
- package/dist/client-D6C_uczF.mjs.map +1 -0
- package/dist/clipboard.d.mts +104 -0
- package/dist/clipboard.d.mts.map +1 -0
- package/dist/clipboard.mjs +404 -0
- package/dist/clipboard.mjs.map +1 -0
- package/dist/flex-Bguo-fUe.mjs +202 -0
- package/dist/flex-Bguo-fUe.mjs.map +1 -0
- package/dist/image-Cm5T-uw-.mjs +108 -0
- package/dist/image-Cm5T-uw-.mjs.map +1 -0
- package/dist/image.d.mts +123 -0
- package/dist/image.d.mts.map +1 -0
- package/dist/image.mjs +2 -0
- package/dist/index.d.mts +64 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +222 -0
- package/dist/index.mjs.map +1 -0
- package/dist/input-B5Vy-iaa.d.mts +141 -0
- package/dist/input-B5Vy-iaa.d.mts.map +1 -0
- package/dist/inspect-D1d9t-ni.mjs +101 -0
- package/dist/inspect-D1d9t-ni.mjs.map +1 -0
- package/dist/inspect-D6FW_QUo.d.mts +67 -0
- package/dist/inspect-D6FW_QUo.d.mts.map +1 -0
- package/dist/kitty-JbCJC0iQ.mjs +673 -0
- package/dist/kitty-JbCJC0iQ.mjs.map +1 -0
- package/dist/markdown.d.mts +24 -0
- package/dist/markdown.d.mts.map +1 -0
- package/dist/markdown.mjs +2 -0
- package/dist/md.bun.d.mts +14 -0
- package/dist/md.bun.d.mts.map +1 -0
- package/dist/md.bun.mjs +28 -0
- package/dist/md.bun.mjs.map +1 -0
- package/dist/md.node.d.mts +14 -0
- package/dist/md.node.d.mts.map +1 -0
- package/dist/md.node.mjs +126 -0
- package/dist/md.node.mjs.map +1 -0
- package/dist/node-BZ7f6HzU.mjs +316 -0
- package/dist/node-BZ7f6HzU.mjs.map +1 -0
- package/dist/picker-D8OLb6kZ.d.mts +36 -0
- package/dist/picker-D8OLb6kZ.d.mts.map +1 -0
- package/dist/picker-ndVVt6qF.mjs +621 -0
- package/dist/picker-ndVVt6qF.mjs.map +1 -0
- package/dist/queries-DH3bj74K.d.mts +1963 -0
- package/dist/queries-DH3bj74K.d.mts.map +1 -0
- package/dist/reactive-f7NpAi69.mjs +623 -0
- package/dist/reactive-f7NpAi69.mjs.map +1 -0
- package/dist/registry-U654j61Y.mjs +356 -0
- package/dist/registry-U654j61Y.mjs.map +1 -0
- package/dist/render-DxVLqqB9.mjs +74 -0
- package/dist/render-DxVLqqB9.mjs.map +1 -0
- package/dist/renderer-CdLCkJB-.mjs +42 -0
- package/dist/renderer-CdLCkJB-.mjs.map +1 -0
- package/dist/renderer-CxL4xbkl.mjs +2644 -0
- package/dist/renderer-CxL4xbkl.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/search-FvGnswRl.d.mts +49 -0
- package/dist/search-FvGnswRl.d.mts.map +1 -0
- package/dist/select-CbmAZdpt.d.mts +116 -0
- package/dist/select-CbmAZdpt.d.mts.map +1 -0
- package/dist/services/logger.d.mts +2 -0
- package/dist/services/logger.mjs +71 -0
- package/dist/services/logger.mjs.map +1 -0
- package/dist/services/notifier.d.mts +17 -0
- package/dist/services/notifier.d.mts.map +1 -0
- package/dist/services/notifier.mjs +71 -0
- package/dist/services/notifier.mjs.map +1 -0
- package/dist/services/picker.d.mts +36 -0
- package/dist/services/picker.d.mts.map +1 -0
- package/dist/services/picker.mjs +137 -0
- package/dist/services/picker.mjs.map +1 -0
- package/dist/services/prompt.d.mts +30 -0
- package/dist/services/prompt.d.mts.map +1 -0
- package/dist/services/prompt.mjs +83 -0
- package/dist/services/prompt.mjs.map +1 -0
- package/dist/shiki-BrjVUkeh.mjs +423 -0
- package/dist/shiki-BrjVUkeh.mjs.map +1 -0
- package/dist/size-D8JogYLy.mjs +34 -0
- package/dist/size-D8JogYLy.mjs.map +1 -0
- package/dist/style.d.mts +10 -0
- package/dist/style.d.mts.map +1 -0
- package/dist/style.mjs +4 -0
- package/dist/text.d.mts +33 -0
- package/dist/text.d.mts.map +1 -0
- package/dist/text.mjs +111 -0
- package/dist/text.mjs.map +1 -0
- package/dist/theme.config-CU3B50HN.mjs +832 -0
- package/dist/theme.config-CU3B50HN.mjs.map +1 -0
- package/dist/themes.d.mts +113 -0
- package/dist/themes.d.mts.map +1 -0
- package/dist/themes.mjs +2 -0
- package/dist/tree-C28QOVIK.d.mts +23 -0
- package/dist/tree-C28QOVIK.d.mts.map +1 -0
- package/dist/types-B9Eh7k2v.d.mts +212 -0
- package/dist/types-B9Eh7k2v.d.mts.map +1 -0
- package/dist/types-D3jk1rtk.d.mts +140 -0
- package/dist/types-D3jk1rtk.d.mts.map +1 -0
- package/dist/utils-3M4D_AXZ.mjs +40 -0
- package/dist/utils-3M4D_AXZ.mjs.map +1 -0
- package/dist/widgets/autocomplete.d.mts +2 -0
- package/dist/widgets/autocomplete.mjs +165 -0
- package/dist/widgets/autocomplete.mjs.map +1 -0
- package/dist/widgets/box.d.mts +2 -0
- package/dist/widgets/box.mjs +2 -0
- package/dist/widgets/code.d.mts +48 -0
- package/dist/widgets/code.d.mts.map +1 -0
- package/dist/widgets/code.mjs +59 -0
- package/dist/widgets/code.mjs.map +1 -0
- package/dist/widgets/completions/actions.d.mts +41 -0
- package/dist/widgets/completions/actions.d.mts.map +1 -0
- package/dist/widgets/completions/actions.mjs +48 -0
- package/dist/widgets/completions/actions.mjs.map +1 -0
- package/dist/widgets/completions/files.d.mts +29 -0
- package/dist/widgets/completions/files.d.mts.map +1 -0
- package/dist/widgets/completions/files.mjs +42 -0
- package/dist/widgets/completions/files.mjs.map +1 -0
- package/dist/widgets/completions/github.d.mts +64 -0
- package/dist/widgets/completions/github.d.mts.map +1 -0
- package/dist/widgets/completions/github.mjs +137 -0
- package/dist/widgets/completions/github.mjs.map +1 -0
- package/dist/widgets/completions/index.d.mts +4 -0
- package/dist/widgets/completions/index.mjs +4 -0
- package/dist/widgets/diff.d.mts +57 -0
- package/dist/widgets/diff.d.mts.map +1 -0
- package/dist/widgets/diff.mjs +199 -0
- package/dist/widgets/diff.mjs.map +1 -0
- package/dist/widgets/divider.d.mts +11 -0
- package/dist/widgets/divider.d.mts.map +1 -0
- package/dist/widgets/divider.mjs +9 -0
- package/dist/widgets/divider.mjs.map +1 -0
- package/dist/widgets/image.d.mts +37 -0
- package/dist/widgets/image.d.mts.map +1 -0
- package/dist/widgets/image.mjs +77 -0
- package/dist/widgets/image.mjs.map +1 -0
- package/dist/widgets/input.d.mts +2 -0
- package/dist/widgets/input.mjs +497 -0
- package/dist/widgets/input.mjs.map +1 -0
- package/dist/widgets/log.d.mts +2 -0
- package/dist/widgets/log.mjs +130 -0
- package/dist/widgets/log.mjs.map +1 -0
- package/dist/widgets/markdown.d.mts +45 -0
- package/dist/widgets/markdown.d.mts.map +1 -0
- package/dist/widgets/markdown.mjs +124 -0
- package/dist/widgets/markdown.mjs.map +1 -0
- package/dist/widgets/overlay.d.mts +2 -0
- package/dist/widgets/overlay.mjs +18 -0
- package/dist/widgets/overlay.mjs.map +1 -0
- package/dist/widgets/picker.d.mts +2 -0
- package/dist/widgets/picker.mjs +2 -0
- package/dist/widgets/progress.d.mts +48 -0
- package/dist/widgets/progress.d.mts.map +1 -0
- package/dist/widgets/progress.mjs +48 -0
- package/dist/widgets/progress.mjs.map +1 -0
- package/dist/widgets/select.d.mts +2 -0
- package/dist/widgets/select.mjs +195 -0
- package/dist/widgets/select.mjs.map +1 -0
- package/dist/widgets/show.d.mts +55 -0
- package/dist/widgets/show.d.mts.map +1 -0
- package/dist/widgets/show.mjs +85 -0
- package/dist/widgets/show.mjs.map +1 -0
- package/dist/widgets/spinner.d.mts +65 -0
- package/dist/widgets/spinner.d.mts.map +1 -0
- package/dist/widgets/spinner.mjs +147 -0
- package/dist/widgets/spinner.mjs.map +1 -0
- package/dist/widgets/text.d.mts +2 -0
- package/dist/widgets/text.mjs +32 -0
- package/dist/widgets/text.mjs.map +1 -0
- package/dist/widgets/tree.d.mts +2 -0
- package/dist/widgets/tree.mjs +73 -0
- package/dist/widgets/tree.mjs.map +1 -0
- package/dist/widgets/widget.d.mts +49 -0
- package/dist/widgets/widget.d.mts.map +1 -0
- package/dist/widgets/widget.mjs +40 -0
- package/dist/widgets/widget.mjs.map +1 -0
- package/dist/worker-DjHuQSbY.mjs +27 -0
- package/dist/worker-DjHuQSbY.mjs.map +1 -0
- package/package.json +117 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { t as defaultTheme } from "./registry-U654j61Y.mjs";
|
|
2
|
+
import { a as openAnsi, d as toHex, l as isHexColor, o as reapplyStyle, t as RESET, u as parseHex } from "./ansi-Clq0ozyA.mjs";
|
|
3
|
+
import { clamp } from "@zaly/shared";
|
|
4
|
+
//#region src/style/oklch.ts
|
|
5
|
+
const cache = /* @__PURE__ */ new Map();
|
|
6
|
+
function srgbToLinear(c) {
|
|
7
|
+
return c <= .04045 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
|
|
8
|
+
}
|
|
9
|
+
function linearToSrgb(c) {
|
|
10
|
+
return c <= .0031308 ? c * 12.92 : 1.055 * c ** (1 / 2.4) - .055;
|
|
11
|
+
}
|
|
12
|
+
function hexToOklch(hex) {
|
|
13
|
+
const [r8, g8, b8] = parseHex(hex);
|
|
14
|
+
const r = srgbToLinear(r8 / 255);
|
|
15
|
+
const g = srgbToLinear(g8 / 255);
|
|
16
|
+
const b = srgbToLinear(b8 / 255);
|
|
17
|
+
const l = .4122214708 * r + .5363325363 * g + .0514459929 * b;
|
|
18
|
+
const m = .2119034982 * r + .6806995451 * g + .1073969566 * b;
|
|
19
|
+
const s = .0883024619 * r + .2817188376 * g + .6299787005 * b;
|
|
20
|
+
const lp = Math.cbrt(l);
|
|
21
|
+
const mp = Math.cbrt(m);
|
|
22
|
+
const sp = Math.cbrt(s);
|
|
23
|
+
const L = .2104542553 * lp + .793617785 * mp - .0040720468 * sp;
|
|
24
|
+
const a = 1.9779984951 * lp - 2.428592205 * mp + .4505937099 * sp;
|
|
25
|
+
const b2 = .0259040371 * lp + .7827717662 * mp - .808675766 * sp;
|
|
26
|
+
return {
|
|
27
|
+
C: Math.hypot(a, b2),
|
|
28
|
+
L,
|
|
29
|
+
h: (Math.atan2(b2, a) * 180 / Math.PI + 360) % 360
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Convert OKLCH → linear sRGB (unclamped — callers can test for gamut). */
|
|
33
|
+
function oklchToLinearRgb({ L, C, h }) {
|
|
34
|
+
const hr = h * Math.PI / 180;
|
|
35
|
+
const a = C * Math.cos(hr);
|
|
36
|
+
const b2 = C * Math.sin(hr);
|
|
37
|
+
const lp = L + .3963377774 * a + .2158037573 * b2;
|
|
38
|
+
const mp = L - .1055613458 * a - .0638541728 * b2;
|
|
39
|
+
const sp = L - .0894841775 * a - 1.291485548 * b2;
|
|
40
|
+
const l = lp ** 3;
|
|
41
|
+
const m = mp ** 3;
|
|
42
|
+
const s = sp ** 3;
|
|
43
|
+
return [
|
|
44
|
+
4.0767416621 * l - 3.3077115913 * m + .2309699292 * s,
|
|
45
|
+
-1.2684380046 * l + 2.6097574011 * m - .3413193965 * s,
|
|
46
|
+
-.0041960863 * l - .7034186147 * m + 1.707614701 * s
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
function inGamut([r, g, b], eps = .001) {
|
|
50
|
+
return r >= -eps && r <= 1 + eps && g >= -eps && g <= 1 + eps && b >= -eps && b <= 1 + eps;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Convert OKLCH → hex, reducing chroma via binary search when the
|
|
54
|
+
* straightforward conversion falls outside sRGB. The search keeps `L`
|
|
55
|
+
* and `h` fixed and shrinks `C` toward the achromatic axis until the
|
|
56
|
+
* color fits, which is the CSS Color Level 4-recommended behavior.
|
|
57
|
+
*/
|
|
58
|
+
function oklchToHex(oklch) {
|
|
59
|
+
let rgb = oklchToLinearRgb(oklch);
|
|
60
|
+
if (!inGamut(rgb)) {
|
|
61
|
+
let lo = 0;
|
|
62
|
+
let hi = oklch.C;
|
|
63
|
+
for (let i = 0; i < 24; i++) {
|
|
64
|
+
const mid = (lo + hi) / 2;
|
|
65
|
+
if (inGamut(oklchToLinearRgb({
|
|
66
|
+
...oklch,
|
|
67
|
+
C: mid
|
|
68
|
+
}))) lo = mid;
|
|
69
|
+
else hi = mid;
|
|
70
|
+
}
|
|
71
|
+
rgb = oklchToLinearRgb({
|
|
72
|
+
...oklch,
|
|
73
|
+
C: lo
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const [r, g, b] = rgb.map((c) => linearToSrgb(Math.max(0, Math.min(1, c))));
|
|
77
|
+
return toHex(r * 255, g * 255, b * 255);
|
|
78
|
+
}
|
|
79
|
+
function shiftLightness(hex, delta) {
|
|
80
|
+
const key = `${hex}:${delta}`;
|
|
81
|
+
let ret = cache.get(key);
|
|
82
|
+
if (ret) return ret;
|
|
83
|
+
const okl = hexToOklch(hex);
|
|
84
|
+
const L = clamp(okl.L + delta, 0, 1);
|
|
85
|
+
const margin = Math.min(L, 1 - L);
|
|
86
|
+
const C = okl.C * Math.min(1, margin / .1);
|
|
87
|
+
cache.set(key, ret = oklchToHex({
|
|
88
|
+
...okl,
|
|
89
|
+
C,
|
|
90
|
+
L
|
|
91
|
+
}));
|
|
92
|
+
return ret;
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/style/style.ts
|
|
96
|
+
/**
|
|
97
|
+
* Build the opening SGR escape for a style descriptor. Returns '' if nothing
|
|
98
|
+
* would be emitted. Unresolvable colors (invalid or 'inherit') are dropped.
|
|
99
|
+
*
|
|
100
|
+
* When `theme` is provided, `fg`/`bg` values matching a theme color slot
|
|
101
|
+
* (e.g. `"primary"`, `"muted"`) are resolved against it first. The output
|
|
102
|
+
* ordering is attrs → fg → bg, combined into a single `\x1b[...m` run.
|
|
103
|
+
*
|
|
104
|
+
* @internal
|
|
105
|
+
*/
|
|
106
|
+
function openStyle(style, theme) {
|
|
107
|
+
const resolver = ThemeResolver.from(theme);
|
|
108
|
+
return openAnsi({
|
|
109
|
+
...style,
|
|
110
|
+
bg: style.bg !== void 0 ? resolver.getColor(style.bg, "bg") : void 0,
|
|
111
|
+
fg: style.fg !== void 0 ? resolver.getColor(style.fg, "fg") : void 0
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Resolve a style-slot reference into a `Style` object. A ref is either a
|
|
116
|
+
* theme slot name (string), an inline `Style`, or `undefined`:
|
|
117
|
+
*
|
|
118
|
+
* - Inline `Style` → returned as-is (no slot lookup).
|
|
119
|
+
* - String ref pointing at a **Color** slot → wrapped as `{ fg: <color> }`.
|
|
120
|
+
* - String ref pointing at a **Style** slot → returned directly.
|
|
121
|
+
* - String ref that doesn't match a slot → treated as a fg color
|
|
122
|
+
* (`{ fg: <ref> }`) and resolved downstream by `colorParams`.
|
|
123
|
+
* - `undefined` → `{}` (emits nothing).
|
|
124
|
+
*
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
127
|
+
function resolveStyle(ref, theme) {
|
|
128
|
+
return ThemeResolver.from(theme).getStyle(ref);
|
|
129
|
+
}
|
|
130
|
+
function parseColor(c) {
|
|
131
|
+
const m = c.match(/^(.+?)([+-]\d{1,3})$/);
|
|
132
|
+
if (!m) return { base: c };
|
|
133
|
+
let lightness = Number(m[2]);
|
|
134
|
+
if (!Number.isFinite(lightness)) throw new TypeError(`Invalid color step in color "${c}": ${m[2]}`);
|
|
135
|
+
lightness = Math.abs(lightness) < 1 ? lightness : lightness / 100;
|
|
136
|
+
return {
|
|
137
|
+
base: m[1],
|
|
138
|
+
lightness
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
var ThemeResolver = class ThemeResolver {
|
|
142
|
+
static #cache = /* @__PURE__ */ new Map();
|
|
143
|
+
static #main = new ThemeResolver();
|
|
144
|
+
#theme;
|
|
145
|
+
#styleCache = /* @__PURE__ */ new Map();
|
|
146
|
+
#colorCache = /* @__PURE__ */ new Map();
|
|
147
|
+
constructor(theme = {}) {
|
|
148
|
+
this.#theme = theme;
|
|
149
|
+
}
|
|
150
|
+
static from(theme) {
|
|
151
|
+
if (theme === void 0) return this.#main;
|
|
152
|
+
let resolver = this.#cache.get(theme);
|
|
153
|
+
if (!resolver) {
|
|
154
|
+
resolver = new ThemeResolver(theme);
|
|
155
|
+
this.#cache.set(theme, resolver);
|
|
156
|
+
}
|
|
157
|
+
return resolver;
|
|
158
|
+
}
|
|
159
|
+
getStyle(ref, seen) {
|
|
160
|
+
if (ref === void 0) return {};
|
|
161
|
+
if (typeof ref === "object") return ref.style ? {
|
|
162
|
+
...this.getStyle(ref.style, seen),
|
|
163
|
+
...ref
|
|
164
|
+
} : ref;
|
|
165
|
+
let ret = this.#styleCache.get(ref);
|
|
166
|
+
if (ret) return ret;
|
|
167
|
+
seen ??= /* @__PURE__ */ new Set();
|
|
168
|
+
if (seen.has(ref)) throw new TypeError(`Circular dependency for theme slot "${ref}".`);
|
|
169
|
+
seen.add(ref);
|
|
170
|
+
const value = this.#theme[ref];
|
|
171
|
+
ret = value === void 0 ? { fg: ref } : this.getStyle(value, seen);
|
|
172
|
+
this.#styleCache.set(ref, ret);
|
|
173
|
+
return ret;
|
|
174
|
+
}
|
|
175
|
+
getColor(ref, kind = "fg", seen) {
|
|
176
|
+
if (ref === void 0) return "inherit";
|
|
177
|
+
const key = `${kind}:${ref}`;
|
|
178
|
+
let ret = this.#colorCache.get(key);
|
|
179
|
+
if (ret) return ret;
|
|
180
|
+
seen ??= /* @__PURE__ */ new Set();
|
|
181
|
+
if (seen.has(ref)) throw new TypeError(`Circular dependency for theme slot "${ref}".`);
|
|
182
|
+
seen.add(ref);
|
|
183
|
+
const { base, lightness } = parseColor(ref);
|
|
184
|
+
let value = this.#theme[base] ?? base;
|
|
185
|
+
if (typeof value === "object") value = this.getColor(value[kind], kind, seen);
|
|
186
|
+
else if (value !== base) value = this.getColor(value, kind, seen);
|
|
187
|
+
ret = lightness !== void 0 && isHexColor(value) ? shiftLightness(value, lightness) : value;
|
|
188
|
+
this.#colorCache.set(key, ret);
|
|
189
|
+
return ret;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/style/builder.ts
|
|
194
|
+
/**
|
|
195
|
+
* Build styled strings via chainable property access.
|
|
196
|
+
*
|
|
197
|
+
* ```ts
|
|
198
|
+
* style().red.bold("err") // → "\x1b[1;31merr\x1b[0m"
|
|
199
|
+
* style().primary.bgAccent("x") // theme slots via the default theme
|
|
200
|
+
* style(myTheme).primary("x") // override the bound theme
|
|
201
|
+
* style().fg("#82aaff")("x") // hex via the escape hatch
|
|
202
|
+
* style().primary[300]("x") // tonal variant of the last color
|
|
203
|
+
* style().bgDiffAdd[200].fgDiffAdd("x") // per-channel variants on a Style slot
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* Each property access returns a fresh builder, so intermediates can be
|
|
207
|
+
* reused and extended without mutation:
|
|
208
|
+
*
|
|
209
|
+
* ```ts
|
|
210
|
+
* const err = style().red.bold
|
|
211
|
+
* err("oops"); err.underline("fatal")
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* Calling an empty builder is a no-op: `styleBuilder()("x")` returns `"x"` unchanged.
|
|
215
|
+
*/
|
|
216
|
+
function styleBuilder(theme = defaultTheme) {
|
|
217
|
+
return build({
|
|
218
|
+
current: {},
|
|
219
|
+
last: void 0,
|
|
220
|
+
theme: theme === false ? {
|
|
221
|
+
...defaultTheme,
|
|
222
|
+
enabled: false
|
|
223
|
+
} : theme
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const ATTRS = /* @__PURE__ */ new Set([
|
|
227
|
+
"bold",
|
|
228
|
+
"dim",
|
|
229
|
+
"italic",
|
|
230
|
+
"underline",
|
|
231
|
+
"inverse",
|
|
232
|
+
"strikethrough"
|
|
233
|
+
]);
|
|
234
|
+
function applyStyle(state, text) {
|
|
235
|
+
if (!text || state.theme.enabled === false) return text;
|
|
236
|
+
const open = openStyle(state.current, state.theme);
|
|
237
|
+
return open === "" ? text : open + reapplyStyle(text, open) + RESET;
|
|
238
|
+
}
|
|
239
|
+
function applyOp(fn, arg) {
|
|
240
|
+
if (typeof arg === "string" || typeof arg === "number") {
|
|
241
|
+
const key = String(arg);
|
|
242
|
+
const hit = fn[key];
|
|
243
|
+
if (hit !== void 0) return hit;
|
|
244
|
+
const child = fulfill(fn.state, arg);
|
|
245
|
+
Reflect.defineProperty(fn, key, {
|
|
246
|
+
configurable: false,
|
|
247
|
+
value: child,
|
|
248
|
+
writable: false
|
|
249
|
+
});
|
|
250
|
+
return child;
|
|
251
|
+
}
|
|
252
|
+
return fulfill(fn.state, arg);
|
|
253
|
+
}
|
|
254
|
+
/** Turn a parked chain + its arg into the real child chain. */
|
|
255
|
+
function fulfill(state, arg) {
|
|
256
|
+
const { current, last, theme, pending } = state;
|
|
257
|
+
switch (pending) {
|
|
258
|
+
case "fg": return build({
|
|
259
|
+
current: {
|
|
260
|
+
...current,
|
|
261
|
+
fg: arg
|
|
262
|
+
},
|
|
263
|
+
last: "fg",
|
|
264
|
+
theme
|
|
265
|
+
});
|
|
266
|
+
case "bg": return build({
|
|
267
|
+
current: {
|
|
268
|
+
...current,
|
|
269
|
+
bg: arg
|
|
270
|
+
},
|
|
271
|
+
last: "bg",
|
|
272
|
+
theme
|
|
273
|
+
});
|
|
274
|
+
case "lighten":
|
|
275
|
+
case "darken": {
|
|
276
|
+
if (last === void 0) return build({
|
|
277
|
+
current,
|
|
278
|
+
last,
|
|
279
|
+
theme
|
|
280
|
+
});
|
|
281
|
+
const existing = current[last];
|
|
282
|
+
if (typeof existing !== "string" || existing === "inherit") return build({
|
|
283
|
+
current,
|
|
284
|
+
last,
|
|
285
|
+
theme
|
|
286
|
+
});
|
|
287
|
+
const next = `${existing.replace(/[+-]\d+$/, "")}${pending === "lighten" ? "+" : "-"}${Math.abs(arg)}`;
|
|
288
|
+
return build({
|
|
289
|
+
current: {
|
|
290
|
+
...current,
|
|
291
|
+
[last]: next
|
|
292
|
+
},
|
|
293
|
+
last,
|
|
294
|
+
theme
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
default: return build({
|
|
298
|
+
current: {
|
|
299
|
+
...current,
|
|
300
|
+
...resolveStyle(arg, theme)
|
|
301
|
+
},
|
|
302
|
+
last,
|
|
303
|
+
theme
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/** Resolve a single property access on a chain to its child chain. */
|
|
308
|
+
function compileKey(state, key) {
|
|
309
|
+
const { current, last, theme } = state;
|
|
310
|
+
if (key === "fg" || key === "bg" || key === "lighten" || key === "darken" || key === "add") return build({
|
|
311
|
+
current,
|
|
312
|
+
last,
|
|
313
|
+
pending: key,
|
|
314
|
+
theme
|
|
315
|
+
});
|
|
316
|
+
if (ATTRS.has(key)) return build({
|
|
317
|
+
current: {
|
|
318
|
+
...current,
|
|
319
|
+
[key]: true
|
|
320
|
+
},
|
|
321
|
+
last,
|
|
322
|
+
theme
|
|
323
|
+
});
|
|
324
|
+
if (key.startsWith("bg") && key.length > 2 && key[2] === key[2].toUpperCase()) {
|
|
325
|
+
const color = key[2].toLowerCase() + key.slice(3);
|
|
326
|
+
return build({
|
|
327
|
+
current: {
|
|
328
|
+
...current,
|
|
329
|
+
bg: color
|
|
330
|
+
},
|
|
331
|
+
last: "bg",
|
|
332
|
+
theme
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
if (key.startsWith("fg") && key.length > 2 && key[2] === key[2].toUpperCase()) {
|
|
336
|
+
const color = key[2].toLowerCase() + key.slice(3);
|
|
337
|
+
return build({
|
|
338
|
+
current: {
|
|
339
|
+
...current,
|
|
340
|
+
fg: color
|
|
341
|
+
},
|
|
342
|
+
last: "fg",
|
|
343
|
+
theme
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
return build({
|
|
347
|
+
current: {
|
|
348
|
+
...current,
|
|
349
|
+
...resolveStyle(key, theme)
|
|
350
|
+
},
|
|
351
|
+
last: "fg",
|
|
352
|
+
theme
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
/** Shared Proxy handler — one instance, used by every chain. Reads
|
|
356
|
+
* state off the target (the `BuilderFn`), so chain construction
|
|
357
|
+
* doesn't allocate a fresh handler object per `build()` call. */
|
|
358
|
+
const proxyHandler = { get(target, key) {
|
|
359
|
+
if (typeof key !== "string") return void 0;
|
|
360
|
+
const cached = target[key];
|
|
361
|
+
if (cached !== void 0) return cached;
|
|
362
|
+
if (target.state.pending !== void 0) return void 0;
|
|
363
|
+
const child = compileKey(target.state, key);
|
|
364
|
+
if (child === void 0) return void 0;
|
|
365
|
+
Reflect.defineProperty(target, key, {
|
|
366
|
+
configurable: false,
|
|
367
|
+
value: child,
|
|
368
|
+
writable: false
|
|
369
|
+
});
|
|
370
|
+
return child;
|
|
371
|
+
} };
|
|
372
|
+
function build(state) {
|
|
373
|
+
const fn = state.pending === void 0 ? function apply(text) {
|
|
374
|
+
return applyStyle(state, text);
|
|
375
|
+
} : function applyOpCall(arg) {
|
|
376
|
+
return applyOp(fn, arg);
|
|
377
|
+
};
|
|
378
|
+
fn.state = state;
|
|
379
|
+
fn.theme = state.theme;
|
|
380
|
+
return new Proxy(fn, proxyHandler);
|
|
381
|
+
}
|
|
382
|
+
//#endregion
|
|
383
|
+
export { styleBuilder as t };
|
|
384
|
+
|
|
385
|
+
//# sourceMappingURL=builder-D49ECBEf.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder-D49ECBEf.mjs","names":["#cache","#main","#theme","#styleCache","#colorCache"],"sources":["../src/style/oklch.ts","../src/style/style.ts","../src/style/builder.ts"],"sourcesContent":["/**\n * OKLCH-based tonal scale generation for theme colors.\n *\n * Given a base hex color, `variant(hex, step)` returns a hex variant at\n * the Tailwind-v4-ish step (50..950). The base color's hue and chroma\n * are preserved; only lightness moves. When the resulting color falls\n * outside sRGB, chroma is reduced via binary search (CSS Color Level 4\n * \"MinDE chroma reduction\") until the color fits — that avoids the\n * saturation blowout you get from naive HSL lightening at the extremes.\n *\n * Matrix constants come from Björn Ottosson's reference OKLab spec:\n * https://bottosson.github.io/posts/oklab/\n */\n\nimport type { HexColor } from \"./types.ts\"\n\nimport { clamp } from \"@zaly/shared\"\nimport { parseHex, toHex } from \"./color.ts\"\n\nexport interface OKLCH {\n L: number\n C: number\n h: number\n}\n\nconst cache = new Map<string, HexColor>()\n\n// ---------- conversions ----------\n\nfunction srgbToLinear(c: number): number {\n return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4\n}\n\nfunction linearToSrgb(c: number): number {\n return c <= 0.0031308 ? c * 12.92 : 1.055 * c ** (1 / 2.4) - 0.055\n}\n\nexport function hexToOklch(hex: string): OKLCH {\n const [r8, g8, b8] = parseHex(hex)\n const r = srgbToLinear(r8 / 255)\n const g = srgbToLinear(g8 / 255)\n const b = srgbToLinear(b8 / 255)\n\n const l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b\n const m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b\n const s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b\n const lp = Math.cbrt(l)\n const mp = Math.cbrt(m)\n const sp = Math.cbrt(s)\n const L = 0.2104542553 * lp + 0.793617785 * mp - 0.0040720468 * sp\n const a = 1.9779984951 * lp - 2.428592205 * mp + 0.4505937099 * sp\n const b2 = 0.0259040371 * lp + 0.7827717662 * mp - 0.808675766 * sp\n const C = Math.hypot(a, b2)\n const h = ((Math.atan2(b2, a) * 180) / Math.PI + 360) % 360\n return { C, L, h }\n}\n\n/** Convert OKLCH → linear sRGB (unclamped — callers can test for gamut). */\nfunction oklchToLinearRgb({ L, C, h }: OKLCH): [number, number, number] {\n const hr = (h * Math.PI) / 180\n const a = C * Math.cos(hr)\n const b2 = C * Math.sin(hr)\n const lp = L + 0.3963377774 * a + 0.2158037573 * b2\n const mp = L - 0.1055613458 * a - 0.0638541728 * b2\n const sp = L - 0.0894841775 * a - 1.291485548 * b2\n const l = lp ** 3\n const m = mp ** 3\n const s = sp ** 3\n const r = 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s\n const g = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s\n const b = -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s\n return [r, g, b]\n}\n\nfunction inGamut([r, g, b]: [number, number, number], eps = 0.001): boolean {\n return r >= -eps && r <= 1 + eps && g >= -eps && g <= 1 + eps && b >= -eps && b <= 1 + eps\n}\n\n/**\n * Convert OKLCH → hex, reducing chroma via binary search when the\n * straightforward conversion falls outside sRGB. The search keeps `L`\n * and `h` fixed and shrinks `C` toward the achromatic axis until the\n * color fits, which is the CSS Color Level 4-recommended behavior.\n */\nexport function oklchToHex(oklch: OKLCH): HexColor {\n let rgb = oklchToLinearRgb(oklch)\n if (!inGamut(rgb)) {\n // Binary-search on C.\n let lo = 0\n let hi = oklch.C\n for (let i = 0; i < 24; i++) {\n const mid = (lo + hi) / 2\n if (inGamut(oklchToLinearRgb({ ...oklch, C: mid }))) lo = mid\n else hi = mid\n }\n rgb = oklchToLinearRgb({ ...oklch, C: lo })\n }\n const [r, g, b] = rgb.map((c) => linearToSrgb(Math.max(0, Math.min(1, c)))) as [\n number,\n number,\n number,\n ]\n return toHex(r * 255, g * 255, b * 255)\n}\n\nexport function shiftLightness(hex: HexColor, delta: number): HexColor {\n const key = `${hex}:${delta}`\n let ret = cache.get(key)\n if (ret) return ret\n\n const okl = hexToOklch(hex)\n const L = clamp(okl.L + delta, 0, 1)\n // Pull chroma toward 0 as L approaches an extreme. Keeps near-white\n // and near-black from going out of gamut.\n const margin = Math.min(L, 1 - L)\n const C = okl.C * Math.min(1, margin / 0.1)\n cache.set(key, (ret = oklchToHex({ ...okl, C, L })))\n return ret\n}\n","import type { Theme } from \"../themes/types.ts\"\nimport type { AnsiColor, AnsiStyle, Color, Style } from \"./types.ts\"\n\nimport { openAnsi } from \"./ansi.ts\"\nimport { isHexColor } from \"./color.ts\"\nimport { shiftLightness } from \"./oklch.ts\"\n\n/**\n * Build the opening SGR escape for a style descriptor. Returns '' if nothing\n * would be emitted. Unresolvable colors (invalid or 'inherit') are dropped.\n *\n * When `theme` is provided, `fg`/`bg` values matching a theme color slot\n * (e.g. `\"primary\"`, `\"muted\"`) are resolved against it first. The output\n * ordering is attrs → fg → bg, combined into a single `\\x1b[...m` run.\n *\n * @internal\n */\nexport function openStyle(style: Style, theme?: Theme): string {\n const resolver = ThemeResolver.from(theme)\n const ansiStyle: AnsiStyle = {\n ...style,\n bg: style.bg !== undefined ? resolver.getColor(style.bg, \"bg\") : undefined,\n fg: style.fg !== undefined ? resolver.getColor(style.fg, \"fg\") : undefined,\n }\n return openAnsi(ansiStyle)\n}\n\n/**\n * Resolve a style-slot reference into a `Style` object. A ref is either a\n * theme slot name (string), an inline `Style`, or `undefined`:\n *\n * - Inline `Style` → returned as-is (no slot lookup).\n * - String ref pointing at a **Color** slot → wrapped as `{ fg: <color> }`.\n * - String ref pointing at a **Style** slot → returned directly.\n * - String ref that doesn't match a slot → treated as a fg color\n * (`{ fg: <ref> }`) and resolved downstream by `colorParams`.\n * - `undefined` → `{}` (emits nothing).\n *\n * @internal\n */\nexport function resolveStyle(ref: string | Style | undefined, theme?: Theme): Style {\n return ThemeResolver.from(theme).getStyle(ref)\n}\n\nfunction parseColor(c: string): { base: string; lightness?: number } {\n const m = c.match(/^(.+?)([+-]\\d{1,3})$/)\n if (!m) return { base: c }\n let lightness = Number(m[2])\n if (!Number.isFinite(lightness))\n throw new TypeError(`Invalid color step in color \"${c}\": ${m[2]}`)\n lightness = Math.abs(lightness) < 1 ? lightness : lightness / 100\n return { base: m[1], lightness }\n}\n\nclass ThemeResolver {\n static #cache = new Map<Partial<Theme>, ThemeResolver>()\n static #main = new ThemeResolver()\n #theme: Partial<Theme>\n #styleCache = new Map<string, Style>()\n #colorCache = new Map<string, string>()\n\n private constructor(theme: Partial<Theme> = {}) {\n this.#theme = theme\n }\n\n static from(theme?: Theme): ThemeResolver {\n if (theme === undefined) return this.#main\n let resolver = this.#cache.get(theme)\n if (!resolver) {\n resolver = new ThemeResolver(theme)\n this.#cache.set(theme, resolver)\n }\n return resolver\n }\n\n getStyle(ref?: string | Style, seen?: Set<string>): Style {\n if (ref === undefined) return {}\n if (typeof ref === \"object\")\n return ref.style ? { ...this.getStyle(ref.style, seen), ...ref } : ref\n\n let ret = this.#styleCache.get(ref)\n if (ret) return ret\n\n seen ??= new Set<string>()\n if (seen.has(ref)) throw new TypeError(`Circular dependency for theme slot \"${ref}\".`)\n seen.add(ref)\n\n const value = this.#theme[ref as keyof Theme]\n ret = value === undefined ? { fg: ref as Color } : this.getStyle(value, seen)\n this.#styleCache.set(ref, ret)\n return ret\n }\n\n getColor(ref?: string, kind: \"fg\" | \"bg\" = \"fg\", seen?: Set<string>): AnsiColor {\n if (ref === undefined) return \"inherit\"\n\n const key = `${kind}:${ref}`\n let ret = this.#colorCache.get(key)\n if (ret) return ret as AnsiColor\n\n seen ??= new Set<string>()\n if (seen.has(ref)) throw new TypeError(`Circular dependency for theme slot \"${ref}\".`)\n seen.add(ref)\n\n const { base, lightness } = parseColor(ref)\n\n let value = this.#theme[base as keyof Theme] ?? base\n if (typeof value === \"object\") value = this.getColor(value[kind], kind, seen)\n else if (value !== base) value = this.getColor(value, kind, seen)\n ret = lightness !== undefined && isHexColor(value) ? shiftLightness(value, lightness) : value\n this.#colorCache.set(key, ret)\n return ret as AnsiColor\n }\n}\n","import type { Theme } from \"../themes/types.ts\"\nimport type { AnsiColorName, BrightAnsiColorName, Color, Style } from \"./types.ts\"\n\nimport { defaultTheme } from \"../themes/registry.ts\"\nimport { reapplyStyle, RESET } from \"./ansi.ts\"\nimport { openStyle, resolveStyle } from \"./style.ts\"\n\ntype AttrName = \"bold\" | \"dim\" | \"italic\" | \"underline\" | \"inverse\" | \"strikethrough\"\n\ntype AnyThemeKey = Exclude<keyof Theme, \"shiki\" | \"$schema\"> | (string & {})\n\n// Theme color slots that can chain as fg/bg. `fg`/`bg` become setter methods\n// below, so exclude them here to avoid naming collisions. `dim` is an attr on\n// the chain; users wanting theme-slot-dim for fg use `.fg(\"dim\")`.\ntype ChainSlot = Exclude<keyof Theme, \"fg\" | \"bg\" | AttrName>\n\ntype FgChainKey = AnsiColorName | BrightAnsiColorName | ChainSlot\ntype BgChainKey = `bg${Capitalize<FgChainKey>}`\ntype FgExtractKey = `fg${Capitalize<FgChainKey>}`\n\nexport type StyleBuilder = {\n theme: Theme\n (text: string): string\n fg: (color: Color) => StyleBuilder\n bg: (color: Color) => StyleBuilder\n add: (slot?: AnyThemeKey | Style) => StyleBuilder\n lighten: (n: number) => StyleBuilder\n darken: (n: number) => StyleBuilder\n // oxlint-disable-next-line typescript/consistent-indexed-object-style -- mapped over a key union, not an open string index\n} & {\n readonly [K in AttrName | FgChainKey | BgChainKey | FgExtractKey]: StyleBuilder\n}\n\n/**\n * Build styled strings via chainable property access.\n *\n * ```ts\n * style().red.bold(\"err\") // → \"\\x1b[1;31merr\\x1b[0m\"\n * style().primary.bgAccent(\"x\") // theme slots via the default theme\n * style(myTheme).primary(\"x\") // override the bound theme\n * style().fg(\"#82aaff\")(\"x\") // hex via the escape hatch\n * style().primary[300](\"x\") // tonal variant of the last color\n * style().bgDiffAdd[200].fgDiffAdd(\"x\") // per-channel variants on a Style slot\n * ```\n *\n * Each property access returns a fresh builder, so intermediates can be\n * reused and extended without mutation:\n *\n * ```ts\n * const err = style().red.bold\n * err(\"oops\"); err.underline(\"fatal\")\n * ```\n *\n * Calling an empty builder is a no-op: `styleBuilder()(\"x\")` returns `\"x\"` unchanged.\n */\nexport function styleBuilder(theme: Theme | false = defaultTheme): StyleBuilder {\n return build({\n current: {},\n last: undefined,\n theme: theme === false ? { ...defaultTheme, enabled: false } : theme,\n })\n}\n\nconst ATTRS = new Set<string>([\"bold\", \"dim\", \"italic\", \"underline\", \"inverse\", \"strikethrough\"])\n\n/** Pending \"arg-taking\" op on a chain. Set when the caller accesses\n * `.fg` / `.bg` / `.alpha` / `.add` — the chain is \"parked\" waiting\n * for its argument. Calling the parked chain consumes the arg and\n * produces the real child chain. */\ntype PendingOp = \"fg\" | \"bg\" | \"darken\" | \"add\" | \"lighten\"\n\n/** All the inputs a chain needs to behave correctly, gathered in one\n * object so we can pass it around cheaply instead of closing over\n * four separate vars. `current` is the accumulated Style, `last`\n * tracks which of `fg`/`bg` was most recently touched (for `[step]`\n * and `.alpha()`), `theme` is the resolved theme, `pending` is set\n * on parked arg-taking chains. */\ninterface BuilderState {\n current: Style\n last: \"fg\" | \"bg\" | undefined\n theme: Theme & { enabled?: boolean }\n pending?: PendingOp\n}\n\n/** The function wrapped by every chain's Proxy. Carries its own state\n * so module-level handlers can read it without closure gymnastics. */\ntype BuilderFn = {\n state: BuilderState\n theme: Theme\n} & (((text: string) => string) | ((arg: Color | number | Style | undefined) => StyleBuilder))\n\n// --- module-level handlers (shared across every chain) -----------------\n\nfunction applyStyle(state: BuilderState, text: string): string {\n if (!text || state.theme.enabled === false) return text\n const open = openStyle(state.current, state.theme)\n return open === \"\" ? text : open + reapplyStyle(text, open) + RESET\n}\n\nfunction applyOp(fn: BuilderFn, arg: Color | number | Style | undefined): StyleBuilder {\n // Cache primitive args on the call target itself via `defineProperty`\n // — repeated `.fg(\"#82aaff\")` hits the same child chain after the\n // first call, no rebuild. Object args (e.g. raw Style for `add`)\n // can't be property keys (`\"[object Object]\"` collision), so those\n // always rebuild.\n if (typeof arg === \"string\" || typeof arg === \"number\") {\n const key = String(arg)\n const hit = (fn as unknown as Record<string, unknown>)[key]\n if (hit !== undefined) return hit as StyleBuilder\n const child = fulfill(fn.state, arg)\n Reflect.defineProperty(fn, key, { configurable: false, value: child, writable: false })\n return child\n }\n return fulfill(fn.state, arg)\n}\n\n/** Turn a parked chain + its arg into the real child chain. */\nfunction fulfill(state: BuilderState, arg: unknown): StyleBuilder {\n const { current, last, theme, pending } = state\n switch (pending) {\n case \"fg\": {\n return build({ current: { ...current, fg: arg as Color }, last: \"fg\", theme })\n }\n case \"bg\": {\n return build({ current: { ...current, bg: arg as Color }, last: \"bg\", theme })\n }\n case \"lighten\":\n case \"darken\": {\n if (last === undefined) return build({ current, last, theme })\n const existing = current[last]\n if (typeof existing !== \"string\" || existing === \"inherit\") {\n return build({ current, last, theme })\n }\n const stripped = existing.replace(/[+-]\\d+$/, \"\")\n const n = Math.abs(arg as number)\n const next = `${stripped}${pending === \"lighten\" ? \"+\" : \"-\"}${n}` as Color\n return build({ current: { ...current, [last]: next }, last, theme })\n }\n default: {\n // \"add\" — no pending pending? defaults to rebuild with undef arg.\n return build({\n current: { ...current, ...resolveStyle(arg as string | Style | undefined, theme) },\n last,\n theme,\n })\n }\n }\n}\n\n/** Resolve a single property access on a chain to its child chain. */\nfunction compileKey(state: BuilderState, key: string): StyleBuilder | undefined {\n const { current, last, theme } = state\n\n // Arg-taking ops come back as chains parked in the `pending` state.\n if (key === \"fg\" || key === \"bg\" || key === \"lighten\" || key === \"darken\" || key === \"add\") {\n return build({ current, last, pending: key, theme })\n }\n\n if (ATTRS.has(key)) return build({ current: { ...current, [key]: true }, last, theme })\n\n // `bgFoo` / `fgFoo` → set the channel to the color at slot `foo`.\n // When the slot is a Style, `colorParams` extracts that channel.\n if (key.startsWith(\"bg\") && key.length > 2 && key[2] === key[2].toUpperCase()) {\n const color = (key[2].toLowerCase() + key.slice(3)) as Color\n return build({ current: { ...current, bg: color }, last: \"bg\", theme })\n }\n if (key.startsWith(\"fg\") && key.length > 2 && key[2] === key[2].toUpperCase()) {\n const color = (key[2].toLowerCase() + key.slice(3)) as Color\n return build({ current: { ...current, fg: color }, last: \"fg\", theme })\n }\n\n // Style-valued theme slot → merge its fields into the chain.\n // Anything else (ANSI color names, hex, unresolved slot refs) is\n // treated as a fg color by `colorParams` downstream.\n return build({ current: { ...current, ...resolveStyle(key, theme) }, last: \"fg\", theme })\n}\n\n/** Shared Proxy handler — one instance, used by every chain. Reads\n * state off the target (the `BuilderFn`), so chain construction\n * doesn't allocate a fresh handler object per `build()` call. */\nconst proxyHandler: ProxyHandler<BuilderFn> = {\n get(target, key) {\n if (typeof key !== \"string\") return undefined\n const cached = (target as unknown as Record<string, unknown>)[key]\n if (cached !== undefined) return cached\n // Parked chains can't be chained further — they're waiting for a call.\n if (target.state.pending !== undefined) return undefined\n const child = compileKey(target.state, key)\n if (child === undefined) return undefined\n Reflect.defineProperty(target, key, { configurable: false, value: child, writable: false })\n return child\n },\n}\n\nfunction build(state: BuilderState): StyleBuilder {\n // Two dedicated function shapes so V8 sees a stable signature on\n // each hot path — styling text vs. consuming an op arg are both\n // monomorphic after the build-time ternary.\n const fn = (\n state.pending === undefined\n ? function apply(text: string): string {\n return applyStyle(state, text)\n }\n : function applyOpCall(arg: Color | number | Style | undefined): StyleBuilder {\n return applyOp(fn, arg)\n }\n ) as BuilderFn\n fn.state = state\n fn.theme = state.theme\n return new Proxy(fn, proxyHandler) as unknown as StyleBuilder\n}\n"],"mappings":";;;;AAyBA,MAAM,wBAAQ,IAAI,IAAsB;AAIxC,SAAS,aAAa,GAAmB;CACvC,OAAO,KAAK,SAAU,IAAI,UAAU,IAAI,QAAS,UAAU;AAC7D;AAEA,SAAS,aAAa,GAAmB;CACvC,OAAO,KAAK,WAAY,IAAI,QAAQ,QAAQ,MAAM,IAAI,OAAO;AAC/D;AAEA,SAAgB,WAAW,KAAoB;CAC7C,MAAM,CAAC,IAAI,IAAI,MAAM,SAAS,GAAG;CACjC,MAAM,IAAI,a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