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