@opencode/theme 0.0.0-dev-177 → 0.0.0-dev-189
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/dist/tui/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type { ActionStates, Categorical, FormfieldColor, Hue, HueSource, HueScal
|
|
|
3
3
|
export { rgbToOklch } from "./color.js";
|
|
4
4
|
export { expandTheme } from "./expand.js";
|
|
5
5
|
export { migrateV1 } from "./v1-migrate.js";
|
|
6
|
+
export { migrateV1NewDesigns } from "./v1-migrate-new-designs.js";
|
|
6
7
|
export { parseThemeDocument, resolveTheme, resolveThemeDocument, themeDecodeError } from "./resolve.js";
|
|
7
8
|
export { selectTheme, selectThemeMode, supportsThemeMode, themeModes } from "./select.js";
|
|
8
9
|
export { generateSyntax } from "./syntax.js";
|
package/dist/tui/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export { ActionState, ActionVariant, BaseThemeDefinition, CategoricalDefinition,
|
|
|
2
2
|
export { rgbToOklch } from "./color.js";
|
|
3
3
|
export { expandTheme } from "./expand.js";
|
|
4
4
|
export { migrateV1 } from "./v1-migrate.js";
|
|
5
|
+
export { migrateV1NewDesigns } from "./v1-migrate-new-designs.js";
|
|
5
6
|
export { parseThemeDocument, resolveTheme, resolveThemeDocument, themeDecodeError } from "./resolve.js";
|
|
6
7
|
export { selectTheme, selectThemeMode, supportsThemeMode, themeModes } from "./select.js";
|
|
7
8
|
export { generateSyntax } from "./syntax.js";
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { RGBA } from "@opentui/core";
|
|
2
|
+
import { oklchToHex } from "./color.js";
|
|
3
|
+
import { HueStep } from "./schema.js";
|
|
4
|
+
import { base, byte, categoricalTokens, chromaticHues, detectMode, hex, inferHues, referenceHues, resolveV1, selectedForeground, toOklch, } from "./v1-migrate.js";
|
|
5
|
+
// Temporary V1 migration for the "new-designs" experiment. It lays V1 colors out on the opencode2 steps and
|
|
6
|
+
// replaces migrateV1 once the experiment ships.
|
|
7
|
+
export function migrateV1NewDesigns(theme) {
|
|
8
|
+
const light = resolveV1(theme, "light");
|
|
9
|
+
const dark = resolveV1(theme, "dark");
|
|
10
|
+
if (light.background.a > 0 && dark.background.a > 0 && light.background.equals(dark.background)) {
|
|
11
|
+
const lightMode = detectMode(light);
|
|
12
|
+
const darkMode = detectMode(dark);
|
|
13
|
+
if (lightMode === darkMode) {
|
|
14
|
+
const definition = migrateMode(lightMode === "light" ? light : dark, lightMode);
|
|
15
|
+
if (lightMode === "light")
|
|
16
|
+
return { base: base(definition), light: lightOverrides(definition) };
|
|
17
|
+
return { base: base(definition), dark: { hue: definition.hue } };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const lightDefinition = migrateMode(light, "light");
|
|
21
|
+
const darkDefinition = migrateMode(dark, "dark");
|
|
22
|
+
return {
|
|
23
|
+
base: base(lightDefinition),
|
|
24
|
+
light: lightOverrides(lightDefinition),
|
|
25
|
+
dark: darkDefinition,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// Light dialogs sit a step below the page like opencode2's, so rows can hover above them.
|
|
29
|
+
const lightDialog = {
|
|
30
|
+
background: {
|
|
31
|
+
base: "$hue.neutral.800",
|
|
32
|
+
raised: { high: "$hue.neutral.700" },
|
|
33
|
+
action: {
|
|
34
|
+
primary: { $hovered: "$hue.neutral.600" },
|
|
35
|
+
secondary: { $hovered: "$hue.neutral.600" },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
function lightOverrides(definition) {
|
|
40
|
+
return { hue: definition.hue, "@dialog": lightDialog };
|
|
41
|
+
}
|
|
42
|
+
// Mirrors the opencode2 token layout: text at 100/200/300, the page at 900, raised surfaces at 700/600/500,
|
|
43
|
+
// and each V1 color anchored at 400 with quieter steps around it.
|
|
44
|
+
function migrateMode(theme, mode) {
|
|
45
|
+
const color = (key) => hex(theme[key]);
|
|
46
|
+
const neutral = neutralScale(theme, mode);
|
|
47
|
+
const primary = "$hue.interactive.400";
|
|
48
|
+
return referenceHues({
|
|
49
|
+
...paletteHues(theme, neutral.scale, (color) => hueScale(color, mode, neutral)),
|
|
50
|
+
text: {
|
|
51
|
+
base: "$hue.neutral.100",
|
|
52
|
+
muted: "$hue.neutral.200",
|
|
53
|
+
faint: "$hue.neutral.300",
|
|
54
|
+
action: {
|
|
55
|
+
primary: {
|
|
56
|
+
base: "$text.base",
|
|
57
|
+
$disabled: "$text.faint",
|
|
58
|
+
$focused: "$text.base",
|
|
59
|
+
$selected: primary,
|
|
60
|
+
},
|
|
61
|
+
secondary: { base: "$text.muted", $hovered: "$text.base", $focused: "$hue.interactive.200" },
|
|
62
|
+
destructive: { base: hex(selectedForeground(theme, theme.error)), $disabled: "$text.faint" },
|
|
63
|
+
},
|
|
64
|
+
formfield: {
|
|
65
|
+
base: "$text.base",
|
|
66
|
+
$hovered: primary,
|
|
67
|
+
$focused: primary,
|
|
68
|
+
$pressed: primary,
|
|
69
|
+
$disabled: "$text.faint",
|
|
70
|
+
$selected: primary,
|
|
71
|
+
},
|
|
72
|
+
feedback: {
|
|
73
|
+
error: { base: color("error") },
|
|
74
|
+
warning: { base: color("warning") },
|
|
75
|
+
success: { base: color("success") },
|
|
76
|
+
info: { base: color("info") },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
background: {
|
|
80
|
+
base: "$hue.neutral.900",
|
|
81
|
+
raised: {
|
|
82
|
+
base: "$hue.neutral.700",
|
|
83
|
+
high: "$hue.neutral.600",
|
|
84
|
+
max: "$hue.neutral.500",
|
|
85
|
+
},
|
|
86
|
+
action: {
|
|
87
|
+
primary: {
|
|
88
|
+
base: "transparent",
|
|
89
|
+
$hovered: "$hue.neutral.700",
|
|
90
|
+
$focused: "$hue.interactive.600",
|
|
91
|
+
$selected: "transparent",
|
|
92
|
+
},
|
|
93
|
+
secondary: { base: "transparent" },
|
|
94
|
+
destructive: { base: color("error") },
|
|
95
|
+
},
|
|
96
|
+
formfield: {
|
|
97
|
+
base: "$background.base",
|
|
98
|
+
},
|
|
99
|
+
feedback: {
|
|
100
|
+
error: { base: "$background.base" },
|
|
101
|
+
warning: { base: "$background.base" },
|
|
102
|
+
success: { base: "$background.base" },
|
|
103
|
+
info: { base: "$background.base" },
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
...paletteTokens(theme),
|
|
107
|
+
"@dialog": {
|
|
108
|
+
background: {
|
|
109
|
+
base: "$background.raised.base",
|
|
110
|
+
action: {
|
|
111
|
+
primary: { $hovered: "$background.raised.max" },
|
|
112
|
+
secondary: { $hovered: "$background.raised.max" },
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// Step profiles measured from the opencode2 theme. Only lightness and chroma are taken from it; hues and
|
|
119
|
+
// anchors always come from the V1 theme being migrated.
|
|
120
|
+
const profiles = {
|
|
121
|
+
dark: {
|
|
122
|
+
// Lightness of each surface step above the page background.
|
|
123
|
+
surface: { 900: 0, 800: 0.039, 700: 0.057, 600: 0.11, 500: 0.175, 400: 0.253 },
|
|
124
|
+
// Where muted and faint text sit between the page (0) and the text color (1).
|
|
125
|
+
text: { 200: 0.719, 300: 0.538 },
|
|
126
|
+
// Lightness of each chromatic step relative to the neutral step of the same number.
|
|
127
|
+
hueLightness: { 100: -0.035, 200: -0.023, 300: -0.003, 600: 0.095, 700: 0.071, 800: 0.024, 900: 0.012 },
|
|
128
|
+
// Chroma of each chromatic step as a share of the anchor's chroma.
|
|
129
|
+
hueChroma: { 100: 0.1, 200: 0.24, 300: 0.22, 500: 0.64, 600: 0.2, 700: 0.14, 800: 0.09, 900: 0.07 },
|
|
130
|
+
// Step 500 sits this far from the anchor toward step 600.
|
|
131
|
+
hueMid: 0.55,
|
|
132
|
+
// Least share of the text-on-page contrast that text keeps on each background step.
|
|
133
|
+
readable: { 800: 0.95, 700: 0.92, 600: 0.81, 500: 0.66, 900: 0.99 },
|
|
134
|
+
readableHue: { 600: 0.7, 700: 0.82, 800: 0.92, 900: 0.99 },
|
|
135
|
+
},
|
|
136
|
+
light: {
|
|
137
|
+
surface: { 900: 0, 800: -0.015, 700: -0.039, 600: -0.102, 500: -0.145, 400: -0.227 },
|
|
138
|
+
text: { 200: 0.688, 300: 0.484 },
|
|
139
|
+
hueLightness: { 100: 0.083, 200: 0.13, 300: 0.116, 600: 0.021, 700: -0.002, 800: -0.004, 900: -0.008 },
|
|
140
|
+
hueChroma: { 100: 0.19, 200: 0.12, 300: 0.16, 500: 0.38, 600: 0.17, 700: 0.1, 800: 0.05, 900: 0.02 },
|
|
141
|
+
hueMid: 0.65,
|
|
142
|
+
readable: { 800: 0.96, 700: 0.89, 600: 0.74, 500: 0.64, 900: 0.97 },
|
|
143
|
+
readableHue: { 600: 0.78, 700: 0.88, 800: 0.93, 900: 0.97 },
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
// Body text on surfaces and selections should stay comfortable to read even in low-contrast themes.
|
|
147
|
+
const minimumSurfaceContrast = 4.5;
|
|
148
|
+
const maximumDimming = 0.6;
|
|
149
|
+
function neutralScale(theme, mode) {
|
|
150
|
+
const profile = profiles[mode];
|
|
151
|
+
const opaque = (color) => color.toInts()[3] > 0;
|
|
152
|
+
const element = [theme.backgroundElement, theme.backgroundMenu].find(opaque);
|
|
153
|
+
const sources = [
|
|
154
|
+
{ step: 900, color: theme.background },
|
|
155
|
+
{ step: 700, color: theme.backgroundPanel },
|
|
156
|
+
{ step: 600, color: element },
|
|
157
|
+
];
|
|
158
|
+
const reference = sources.find((source) => source.color && opaque(source.color));
|
|
159
|
+
const page = reference
|
|
160
|
+
? toOklch(reference.color)
|
|
161
|
+
: toOklch(mode === "dark" ? RGBA.fromInts(0, 0, 0) : RGBA.fromInts(255, 255, 255));
|
|
162
|
+
const pageLightness = page.l - (reference ? profile.surface[reference.step] : 0);
|
|
163
|
+
const tint = (...colors) => {
|
|
164
|
+
const color = colors.find((color) => color && opaque(color));
|
|
165
|
+
return color ? toOklch(color) : page;
|
|
166
|
+
};
|
|
167
|
+
const surfaceTint = {
|
|
168
|
+
900: tint(theme.background, theme.backgroundPanel, element),
|
|
169
|
+
800: tint(theme.backgroundPanel, theme.background, element),
|
|
170
|
+
700: tint(theme.backgroundPanel, theme.background, element),
|
|
171
|
+
600: tint(element, theme.backgroundPanel, theme.background),
|
|
172
|
+
500: tint(element, theme.backgroundPanel, theme.background),
|
|
173
|
+
400: tint(element, theme.backgroundPanel, theme.background),
|
|
174
|
+
};
|
|
175
|
+
const lightness = {};
|
|
176
|
+
// Lightness before readability dimming, so chromatic steps keep their place relative to the profile.
|
|
177
|
+
const planned = {};
|
|
178
|
+
const scale = {};
|
|
179
|
+
const text = toOklch(theme.text);
|
|
180
|
+
const pageColor = { ...surfaceTint[900], l: pageLightness };
|
|
181
|
+
const pageContrast = contrast(theme.text, RGBA.fromHex(oklchToHex(pageColor)));
|
|
182
|
+
// Pulls a generated background back toward the page until text on it keeps enough contrast.
|
|
183
|
+
const readable = (color, share) => {
|
|
184
|
+
const target = Math.max(pageContrast * share, Math.min(minimumSurfaceContrast, pageContrast * 0.95));
|
|
185
|
+
const passes = (amount) => contrast(theme.text, RGBA.fromHex(oklchToHex(mix(color, pageColor, amount)))) >= target;
|
|
186
|
+
if (passes(0))
|
|
187
|
+
return color;
|
|
188
|
+
// Stop short of the page so surfaces and selections stay visible in low-contrast themes.
|
|
189
|
+
if (!passes(maximumDimming))
|
|
190
|
+
return mix(color, pageColor, maximumDimming);
|
|
191
|
+
let [low, high] = [0, maximumDimming];
|
|
192
|
+
for (let index = 0; index < 12; index++) {
|
|
193
|
+
const amount = (low + high) / 2;
|
|
194
|
+
if (passes(amount))
|
|
195
|
+
high = amount;
|
|
196
|
+
else
|
|
197
|
+
low = amount;
|
|
198
|
+
}
|
|
199
|
+
return mix(color, pageColor, high);
|
|
200
|
+
};
|
|
201
|
+
for (const step of [800, 700, 600, 500, 400]) {
|
|
202
|
+
const generated = { ...surfaceTint[step], l: pageLightness + profile.surface[step] };
|
|
203
|
+
const color = step === 400 ? generated : readable(generated, profile.readable[step]);
|
|
204
|
+
planned[step] = generated.l;
|
|
205
|
+
lightness[step] = color.l;
|
|
206
|
+
scale[step] = oklchToHex(color);
|
|
207
|
+
}
|
|
208
|
+
lightness[900] = pageLightness;
|
|
209
|
+
scale[900] = hex(theme.background);
|
|
210
|
+
// Transparent V1 surfaces stay transparent so the terminal shows through, as they did before.
|
|
211
|
+
for (const [step, color] of [
|
|
212
|
+
[800, theme.backgroundPanel],
|
|
213
|
+
[700, theme.backgroundPanel],
|
|
214
|
+
[600, theme.backgroundElement],
|
|
215
|
+
]) {
|
|
216
|
+
if (!opaque(color))
|
|
217
|
+
scale[step] = hex(color);
|
|
218
|
+
}
|
|
219
|
+
lightness[100] = text.l;
|
|
220
|
+
scale[100] = hex(theme.text);
|
|
221
|
+
for (const step of [200, 300]) {
|
|
222
|
+
const generated = mix(pageColor, text, profile.text[step]);
|
|
223
|
+
lightness[step] = generated.l;
|
|
224
|
+
scale[step] = oklchToHex(generated);
|
|
225
|
+
}
|
|
226
|
+
// Keep the theme's own muted text on whichever text step it is closest to.
|
|
227
|
+
const muted = toOklch(theme.textMuted);
|
|
228
|
+
const mutedStep = Math.abs(muted.l - lightness[200]) <= Math.abs(muted.l - lightness[300]) ? 200 : 300;
|
|
229
|
+
lightness[mutedStep] = muted.l;
|
|
230
|
+
scale[mutedStep] = hex(theme.textMuted);
|
|
231
|
+
return { scale, lightness: { ...lightness, ...planned }, readable };
|
|
232
|
+
}
|
|
233
|
+
function hueScale(color, mode, neutral) {
|
|
234
|
+
const profile = profiles[mode];
|
|
235
|
+
const anchor = toOklch(color);
|
|
236
|
+
const alpha = color.toInts()[3];
|
|
237
|
+
const generate = (generated) => {
|
|
238
|
+
const value = oklchToHex(generated);
|
|
239
|
+
return alpha === 255 ? value : `${value}${byte(alpha)}`;
|
|
240
|
+
};
|
|
241
|
+
const lightness = (step) => neutral.lightness[step] + profile.hueLightness[step];
|
|
242
|
+
return Object.fromEntries(HueStep.literals.map((step) => {
|
|
243
|
+
if (step === 400)
|
|
244
|
+
return [step, hex(color)];
|
|
245
|
+
const generated = {
|
|
246
|
+
l: step === 500 ? anchor.l + (lightness(600) - anchor.l) * profile.hueMid : lightness(step),
|
|
247
|
+
c: anchor.c * profile.hueChroma[step],
|
|
248
|
+
h: anchor.h,
|
|
249
|
+
};
|
|
250
|
+
if (step === 600 || step === 700 || step === 800 || step === 900)
|
|
251
|
+
return [step, generate(neutral.readable(generated, profile.readableHue[step]))];
|
|
252
|
+
return [step, generate(generated)];
|
|
253
|
+
}));
|
|
254
|
+
}
|
|
255
|
+
function contrast(first, second) {
|
|
256
|
+
const luminance = (color) => {
|
|
257
|
+
const channel = (value) => (value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4);
|
|
258
|
+
return 0.2126 * channel(color.r) + 0.7152 * channel(color.g) + 0.0722 * channel(color.b);
|
|
259
|
+
};
|
|
260
|
+
const [lighter, darker] = [luminance(first), luminance(second)].sort((a, b) => b - a);
|
|
261
|
+
return (lighter + 0.05) / (darker + 0.05);
|
|
262
|
+
}
|
|
263
|
+
function mix(start, end, amount) {
|
|
264
|
+
const startHue = start.c > 0.002 ? start.h : end.h;
|
|
265
|
+
const endHue = end.c > 0.002 ? end.h : startHue;
|
|
266
|
+
const hue = ((((endHue - startHue) % 360) + 540) % 360) - 180;
|
|
267
|
+
return {
|
|
268
|
+
l: start.l + (end.l - start.l) * amount,
|
|
269
|
+
c: start.c + (end.c - start.c) * amount,
|
|
270
|
+
h: startHue + hue * amount,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function paletteHues(theme, gray, scale) {
|
|
274
|
+
const hues = inferHues(theme);
|
|
275
|
+
const categorical = categoricalTokens.flatMap((token) => {
|
|
276
|
+
const hue = hues.byToken[token];
|
|
277
|
+
return hue ? [hue] : [];
|
|
278
|
+
});
|
|
279
|
+
const uniqueCategorical = categorical.filter((hue, index) => categorical.indexOf(hue) === index);
|
|
280
|
+
return {
|
|
281
|
+
hue: {
|
|
282
|
+
gray,
|
|
283
|
+
...Object.fromEntries(chromaticHues.flatMap((name) => {
|
|
284
|
+
const match = hues.byHue[name];
|
|
285
|
+
return match ? [[name, scale(match.color)]] : [];
|
|
286
|
+
})),
|
|
287
|
+
accent: hues.byToken.accent ? `$hue.${hues.byToken.accent}` : "$hue.gray",
|
|
288
|
+
interactive: hues.byToken.primary ? `$hue.${hues.byToken.primary}` : "$hue.gray",
|
|
289
|
+
neutral: "$hue.gray",
|
|
290
|
+
},
|
|
291
|
+
categorical: uniqueCategorical.length ? uniqueCategorical : ["neutral"],
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function paletteTokens(theme) {
|
|
295
|
+
const color = (key) => hex(theme[key]);
|
|
296
|
+
return {
|
|
297
|
+
border: { base: color("border") },
|
|
298
|
+
scrollbar: { base: color("borderActive") },
|
|
299
|
+
diff: {
|
|
300
|
+
text: {
|
|
301
|
+
added: color("diffAdded"),
|
|
302
|
+
removed: color("diffRemoved"),
|
|
303
|
+
context: color("diffContext"),
|
|
304
|
+
hunkHeader: color("diffHunkHeader"),
|
|
305
|
+
},
|
|
306
|
+
background: {
|
|
307
|
+
added: color("diffAddedBg"),
|
|
308
|
+
removed: color("diffRemovedBg"),
|
|
309
|
+
context: color("diffContextBg"),
|
|
310
|
+
},
|
|
311
|
+
highlight: { added: color("diffHighlightAdded"), removed: color("diffHighlightRemoved") },
|
|
312
|
+
lineNumber: {
|
|
313
|
+
text: color("diffLineNumber"),
|
|
314
|
+
background: {
|
|
315
|
+
added: color("diffAddedLineNumberBg"),
|
|
316
|
+
removed: color("diffRemovedLineNumberBg"),
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
syntax: {
|
|
321
|
+
comment: color("syntaxComment"),
|
|
322
|
+
keyword: color("syntaxKeyword"),
|
|
323
|
+
function: color("syntaxFunction"),
|
|
324
|
+
variable: color("syntaxVariable"),
|
|
325
|
+
string: color("syntaxString"),
|
|
326
|
+
number: color("syntaxNumber"),
|
|
327
|
+
type: color("syntaxType"),
|
|
328
|
+
operator: color("syntaxOperator"),
|
|
329
|
+
punctuation: color("syntaxPunctuation"),
|
|
330
|
+
},
|
|
331
|
+
markdown: {
|
|
332
|
+
text: color("markdownText"),
|
|
333
|
+
heading: color("markdownHeading"),
|
|
334
|
+
link: color("markdownLink"),
|
|
335
|
+
linkText: color("markdownLinkText"),
|
|
336
|
+
code: color("markdownCode"),
|
|
337
|
+
blockQuote: color("markdownBlockQuote"),
|
|
338
|
+
emphasis: color("markdownEmph"),
|
|
339
|
+
strong: color("markdownStrong"),
|
|
340
|
+
horizontalRule: color("markdownHorizontalRule"),
|
|
341
|
+
listItem: color("markdownListItem"),
|
|
342
|
+
listEnumeration: color("markdownListEnumeration"),
|
|
343
|
+
image: color("markdownImage"),
|
|
344
|
+
imageText: color("markdownImageText"),
|
|
345
|
+
codeBlock: color("markdownCodeBlock"),
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
}
|
package/dist/tui/v1-migrate.d.ts
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
1
|
+
import { RGBA } from "@opentui/core";
|
|
2
|
+
import type { BaseThemeDefinition, Mode, ThemeDefinition, ThemeDocument } from "./index.js";
|
|
3
|
+
import type { Theme, ThemeV1Json } from "./v1.js";
|
|
4
|
+
export type ThemeColor = Exclude<keyof Theme, "thinkingOpacity" | "_hasSelectedListItemText">;
|
|
5
|
+
type ChromaticHue = "red" | "orange" | "yellow" | "green" | "cyan" | "blue" | "purple";
|
|
6
|
+
type V1HueToken = "secondary" | "accent" | "success" | "warning" | "primary" | "error" | "info";
|
|
7
|
+
export declare const chromaticHues: readonly ChromaticHue[];
|
|
8
|
+
export declare const categoricalTokens: readonly V1HueToken[];
|
|
3
9
|
export declare function migrateV1(theme: ThemeV1Json): ThemeDocument;
|
|
10
|
+
export declare function base(definition: ThemeDefinition): BaseThemeDefinition;
|
|
11
|
+
export declare function detectMode(theme: Theme): Mode;
|
|
12
|
+
export declare function referenceHues(theme: ThemeDefinition): ThemeDefinition;
|
|
13
|
+
export declare function inferHues(theme: Theme): {
|
|
14
|
+
byHue: Partial<Record<ChromaticHue, {
|
|
15
|
+
color: RGBA;
|
|
16
|
+
distance: number;
|
|
17
|
+
}>>;
|
|
18
|
+
byToken: Partial<Record<V1HueToken, ChromaticHue>>;
|
|
19
|
+
};
|
|
20
|
+
export declare function resolveV1(theme: ThemeV1Json, mode: "dark" | "light"): Theme;
|
|
21
|
+
export declare function selectedForeground(theme: Theme, background: RGBA): RGBA;
|
|
22
|
+
export declare function toOklch(color: RGBA): {
|
|
23
|
+
l: number;
|
|
24
|
+
c: number;
|
|
25
|
+
h: number;
|
|
26
|
+
};
|
|
27
|
+
export declare function hex(color: RGBA): string;
|
|
28
|
+
export declare function byte(value: number): string;
|
|
29
|
+
export {};
|
package/dist/tui/v1-migrate.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { RGBA } from "@opentui/core";
|
|
2
2
|
import { oklchToHex, rgbToOklch } from "./color.js";
|
|
3
3
|
import { HueStep } from "./schema.js";
|
|
4
|
-
const chromaticHues = ["red", "orange", "yellow", "green", "cyan", "blue", "purple"];
|
|
5
|
-
const categoricalTokens = [
|
|
4
|
+
export const chromaticHues = ["red", "orange", "yellow", "green", "cyan", "blue", "purple"];
|
|
5
|
+
export const categoricalTokens = [
|
|
6
6
|
"secondary",
|
|
7
7
|
"accent",
|
|
8
8
|
"success",
|
|
@@ -59,11 +59,11 @@ export function migrateV1(theme) {
|
|
|
59
59
|
dark: darkDefinition,
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
function base(definition) {
|
|
62
|
+
export function base(definition) {
|
|
63
63
|
const { hue: _, ...base } = definition;
|
|
64
64
|
return base;
|
|
65
65
|
}
|
|
66
|
-
function detectMode(theme) {
|
|
66
|
+
export function detectMode(theme) {
|
|
67
67
|
return luminance(theme.text) > luminance(theme.background) ? "dark" : "light";
|
|
68
68
|
}
|
|
69
69
|
function luminance(color) {
|
|
@@ -206,7 +206,7 @@ function migrateMode(theme, mode) {
|
|
|
206
206
|
},
|
|
207
207
|
});
|
|
208
208
|
}
|
|
209
|
-
function referenceHues(theme) {
|
|
209
|
+
export function referenceHues(theme) {
|
|
210
210
|
const definitions = theme.hue;
|
|
211
211
|
if (!definitions)
|
|
212
212
|
return theme;
|
|
@@ -258,7 +258,7 @@ function referenceHues(theme) {
|
|
|
258
258
|
}
|
|
259
259
|
return Object.fromEntries(Object.entries(theme).map(([key, value]) => [key, key === "hue" || key === "categorical" ? value : replace(value)]));
|
|
260
260
|
}
|
|
261
|
-
function inferHues(theme) {
|
|
261
|
+
export function inferHues(theme) {
|
|
262
262
|
const colors = [
|
|
263
263
|
["accent", theme.accent],
|
|
264
264
|
["success", theme.success],
|
|
@@ -312,7 +312,7 @@ function hueDistance(first, second) {
|
|
|
312
312
|
function ambiguous(color, chroma = toOklch(color).c) {
|
|
313
313
|
return color.toInts()[3] === 0 || chroma < minimumChroma;
|
|
314
314
|
}
|
|
315
|
-
function resolveV1(theme, mode) {
|
|
315
|
+
export function resolveV1(theme, mode) {
|
|
316
316
|
const defs = theme.defs ?? {};
|
|
317
317
|
function resolveColor(value, chain = []) {
|
|
318
318
|
if (value instanceof RGBA)
|
|
@@ -351,7 +351,7 @@ function resolveV1(theme, mode) {
|
|
|
351
351
|
thinkingOpacity: theme.theme.thinkingOpacity ?? 0.6,
|
|
352
352
|
};
|
|
353
353
|
}
|
|
354
|
-
function selectedForeground(theme, background) {
|
|
354
|
+
export function selectedForeground(theme, background) {
|
|
355
355
|
if (theme._hasSelectedListItemText)
|
|
356
356
|
return theme.selectedListItemText;
|
|
357
357
|
if (theme.background.a !== 0)
|
|
@@ -417,17 +417,17 @@ function interpolate(first, second, amount) {
|
|
|
417
417
|
const alpha = Math.max(0, Math.min(255, Math.round(first.toInts()[3] + (second.toInts()[3] - first.toInts()[3]) * amount)));
|
|
418
418
|
return alpha === 255 ? generated : `${generated}${byte(alpha)}`;
|
|
419
419
|
}
|
|
420
|
-
function toOklch(color) {
|
|
420
|
+
export function toOklch(color) {
|
|
421
421
|
const [red, green, blue] = color.toInts();
|
|
422
422
|
return rgbToOklch(red / 255, green / 255, blue / 255);
|
|
423
423
|
}
|
|
424
|
-
function hex(color) {
|
|
424
|
+
export function hex(color) {
|
|
425
425
|
return hexInts(...color.toInts());
|
|
426
426
|
}
|
|
427
427
|
function hexInts(r, g, b, a) {
|
|
428
428
|
return `#${byte(r)}${byte(g)}${byte(b)}${a === 255 ? "" : byte(a)}`;
|
|
429
429
|
}
|
|
430
|
-
function byte(value) {
|
|
430
|
+
export function byte(value) {
|
|
431
431
|
return value.toString(16).padStart(2, "0");
|
|
432
432
|
}
|
|
433
433
|
function ansi(code) {
|