@opencode/theme 2.0.8 → 2.0.10
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/categorical.d.ts +1 -0
- package/dist/tui/categorical.js +1 -0
- package/dist/tui/expand.js +8 -10
- package/dist/tui/index.d.ts +3 -3
- package/dist/tui/index.js +2 -2
- package/dist/tui/resolve.d.ts +2 -2
- package/dist/tui/resolve.js +49 -43
- package/dist/tui/schema.d.ts +1060 -4487
- package/dist/tui/schema.js +86 -49
- package/dist/tui/select.d.ts +3 -8
- package/dist/tui/select.js +2 -20
- package/dist/tui/syntax.d.ts +2 -2
- package/dist/tui/syntax.js +19 -19
- package/dist/tui/types.d.ts +16 -19
- package/dist/tui/v1-migrate.js +80 -55
- package/package.json +1 -1
- package/dist/tui/defaults.d.ts +0 -580
- package/dist/tui/defaults.js +0 -455
- package/dist/tui/fallback.d.ts +0 -2
- package/dist/tui/fallback.js +0 -56
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DEFAULT_CATEGORICAL: readonly ["blue", "purple", "green", "orange", "red", "cyan"];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_CATEGORICAL = ["blue", "purple", "green", "orange", "red", "cyan"];
|
package/dist/tui/expand.js
CHANGED
|
@@ -3,9 +3,7 @@ export function expandTheme(definition) {
|
|
|
3
3
|
return {
|
|
4
4
|
...definition,
|
|
5
5
|
...expandTokens(definition),
|
|
6
|
-
...
|
|
7
|
-
.filter(([key]) => key.startsWith("@context:"))
|
|
8
|
-
.map(([key, value]) => [key, expandTokens(value)])),
|
|
6
|
+
...(definition["@dialog"] ? { "@dialog": expandTokens(definition["@dialog"]) } : {}),
|
|
9
7
|
};
|
|
10
8
|
}
|
|
11
9
|
export function expandTokens(definition) {
|
|
@@ -20,7 +18,7 @@ export function mergeTheme(...values) {
|
|
|
20
18
|
if (!isRecord(value))
|
|
21
19
|
return result;
|
|
22
20
|
return Object.entries(value).reduce((next, [key, item]) => {
|
|
23
|
-
if (item === undefined
|
|
21
|
+
if (item === undefined)
|
|
24
22
|
return next;
|
|
25
23
|
return {
|
|
26
24
|
...next,
|
|
@@ -34,7 +32,7 @@ function expandText(definition) {
|
|
|
34
32
|
return;
|
|
35
33
|
return {
|
|
36
34
|
...definition,
|
|
37
|
-
|
|
35
|
+
muted: definition.muted ?? (definition.base ? "$text.base" : undefined),
|
|
38
36
|
action: expandActions(definition.action, "text.action"),
|
|
39
37
|
formfield: expandFormfield(definition.formfield, "text.formfield"),
|
|
40
38
|
feedback: definition.feedback
|
|
@@ -43,7 +41,7 @@ function expandText(definition) {
|
|
|
43
41
|
kind,
|
|
44
42
|
{
|
|
45
43
|
...feedback,
|
|
46
|
-
|
|
44
|
+
muted: feedback.muted ?? (feedback.base ? `$text.feedback.${kind}.base` : undefined),
|
|
47
45
|
},
|
|
48
46
|
];
|
|
49
47
|
}))
|
|
@@ -60,24 +58,24 @@ function expandBackground(definition) {
|
|
|
60
58
|
};
|
|
61
59
|
}
|
|
62
60
|
function expandFormfield(definition, path) {
|
|
63
|
-
if (!definition?.
|
|
61
|
+
if (!definition?.base)
|
|
64
62
|
return definition;
|
|
65
63
|
return {
|
|
66
64
|
...definition,
|
|
67
|
-
...Object.fromEntries(ActionState.literals.map((state) => [`$${state}`, definition[`$${state}`] ?? `$${path}.
|
|
65
|
+
...Object.fromEntries(ActionState.literals.map((state) => [`$${state}`, definition[`$${state}`] ?? `$${path}.base`])),
|
|
68
66
|
};
|
|
69
67
|
}
|
|
70
68
|
function expandActions(definition, path) {
|
|
71
69
|
if (!definition)
|
|
72
70
|
return;
|
|
73
71
|
return Object.fromEntries(Object.entries(definition).map(([variant, value]) => {
|
|
74
|
-
if (!value?.
|
|
72
|
+
if (!value?.base)
|
|
75
73
|
return [variant, value];
|
|
76
74
|
return [
|
|
77
75
|
variant,
|
|
78
76
|
{
|
|
79
77
|
...value,
|
|
80
|
-
...Object.fromEntries(ActionState.literals.map((state) => [`$${state}`, value[`$${state}`] ?? `$${path}.${variant}.
|
|
78
|
+
...Object.fromEntries(ActionState.literals.map((state) => [`$${state}`, value[`$${state}`] ?? `$${path}.${variant}.base`])),
|
|
81
79
|
},
|
|
82
80
|
];
|
|
83
81
|
}));
|
package/dist/tui/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { ActionState, type ActionStateKey, ActionVariant, BaseHue, CategoricalDefinition, FeedbackKind, FormfieldState, type FormfieldStateKey, HueAlias, HueName, HueStep, MarkdownDefinition, MarkdownToken, ModeDefinition, SyntaxDefinition, SyntaxToken, ThemeDefinition, ThemeDocument, type BackgroundDefinition, type DiffDefinition, type
|
|
2
|
-
export type {
|
|
3
|
-
export { DEFAULT_CATEGORICAL
|
|
1
|
+
export { ActionState, type ActionStateKey, ActionVariant, BaseHue, BaseThemeDefinition, CategoricalDefinition, FeedbackKind, FormfieldState, type FormfieldStateKey, HueAlias, HueName, HueStep, MarkdownDefinition, MarkdownToken, ModeDefinition, SurfaceName, SyntaxDefinition, SyntaxToken, ThemeDefinition, ThemeDocument, type BackgroundDefinition, type DiffDefinition, type FormfieldColorDefinition, type HueDefinition, type Mode, type StatefulColorDefinition, type TextDefinition, type ThemeTokensDefinition, } from "./schema.js";
|
|
2
|
+
export type { ActionStates, Categorical, FormfieldColor, Hue, HueSource, HueScale, ResolvedActionState, ResolvedFormfieldState, ResolvedTheme, ResolvedThemeTokens, StatefulColor, } from "./types.js";
|
|
3
|
+
export { DEFAULT_CATEGORICAL } from "./categorical.js";
|
|
4
4
|
export { expandTheme } from "./expand.js";
|
|
5
5
|
export { migrateV1 } from "./v1-migrate.js";
|
|
6
6
|
export { resolveTheme, resolveThemeDocument, themeDecodeError } from "./resolve.js";
|
package/dist/tui/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { ActionState, ActionVariant, BaseHue, CategoricalDefinition, FeedbackKind, FormfieldState, HueAlias, HueName, HueStep, MarkdownDefinition, MarkdownToken, ModeDefinition, SyntaxDefinition, SyntaxToken, ThemeDefinition, ThemeDocument, } from "./schema.js";
|
|
2
|
-
export { DEFAULT_CATEGORICAL
|
|
1
|
+
export { ActionState, ActionVariant, BaseHue, BaseThemeDefinition, CategoricalDefinition, FeedbackKind, FormfieldState, HueAlias, HueName, HueStep, MarkdownDefinition, MarkdownToken, ModeDefinition, SurfaceName, SyntaxDefinition, SyntaxToken, ThemeDefinition, ThemeDocument, } from "./schema.js";
|
|
2
|
+
export { DEFAULT_CATEGORICAL } from "./categorical.js";
|
|
3
3
|
export { expandTheme } from "./expand.js";
|
|
4
4
|
export { migrateV1 } from "./v1-migrate.js";
|
|
5
5
|
export { resolveTheme, resolveThemeDocument, themeDecodeError } from "./resolve.js";
|
package/dist/tui/resolve.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ThemeDefinition, ThemeDocument } from "./schema.js";
|
|
2
|
-
import type { ResolvedTheme } from "./index.js";
|
|
2
|
+
import type { Mode, ResolvedTheme } from "./index.js";
|
|
3
3
|
export declare function themeDecodeError(error: unknown, name: string): Error;
|
|
4
|
-
export declare function resolveThemeDocument(document: ThemeDocument, mode?:
|
|
4
|
+
export declare function resolveThemeDocument(document: ThemeDocument, mode?: Mode): ResolvedTheme;
|
|
5
5
|
export declare function resolveTheme(definition: ThemeDefinition): ResolvedTheme;
|
package/dist/tui/resolve.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { RGBA } from "@opentui/core";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ActionState, ActionVariant, BaseHue, FeedbackKind, HueAlias, HueStep, ThemeDefinition, ThemeDocument, } from "./schema.js";
|
|
7
|
-
import { selectTheme, selectThemeMode } from "./select.js";
|
|
3
|
+
import { expandTheme, mergeTheme } from "./expand.js";
|
|
4
|
+
import { ActionState, ActionVariant, BaseHue, HueAlias, HueStep, SurfaceName, ThemeDefinition, ThemeDocument, } from "./schema.js";
|
|
5
|
+
import { selectThemeMode } from "./select.js";
|
|
8
6
|
const decodeThemeDefinitionSchema = Schema.decodeUnknownSync(ThemeDefinition, { reportInput: true });
|
|
9
7
|
function decodeThemeDefinition(input) {
|
|
10
8
|
try {
|
|
@@ -21,37 +19,24 @@ export function themeDecodeError(error, name) {
|
|
|
21
19
|
}
|
|
22
20
|
export function resolveThemeDocument(document, mode) {
|
|
23
21
|
const selected = selectThemeMode(document, mode);
|
|
24
|
-
const definition =
|
|
25
|
-
|
|
26
|
-
const core = expandTokens(fallback(selected.mode));
|
|
27
|
-
const merged = document.standalone ? mergeTheme(core, definition) : mergeTheme(core, defaults, definition);
|
|
28
|
-
if (!merged["hue"])
|
|
29
|
-
throw new Error("Standalone themes must provide hues");
|
|
30
|
-
return resolveExpandedTheme({
|
|
31
|
-
...merged,
|
|
32
|
-
categorical: merged["categorical"] ?? DEFAULT_CATEGORICAL,
|
|
33
|
-
});
|
|
22
|
+
const definition = expandTheme(selected.theme);
|
|
23
|
+
return resolveExpandedTheme(definition);
|
|
34
24
|
}
|
|
35
25
|
export function resolveTheme(definition) {
|
|
36
26
|
return resolveExpandedTheme(expandTheme(decodeThemeDefinition(definition)));
|
|
37
27
|
}
|
|
38
28
|
function resolveExpandedTheme(definition) {
|
|
39
29
|
const hue = resolveHue(definition.hue);
|
|
40
|
-
const categorical =
|
|
30
|
+
const categorical = definition.categorical.map((name) => hue[name]);
|
|
41
31
|
const hueSteps = compileHueSteps(hue);
|
|
42
32
|
const base = tokens(definition);
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const contextual = {
|
|
51
|
-
elevated: context("elevated"),
|
|
52
|
-
overlay: context("overlay"),
|
|
53
|
-
};
|
|
54
|
-
return { ...resolved, contextual };
|
|
33
|
+
const views = {};
|
|
34
|
+
const view = (tokens) => ({
|
|
35
|
+
...resolveView(tokens, hue, categorical, hueSteps),
|
|
36
|
+
surface: (name) => views[name],
|
|
37
|
+
});
|
|
38
|
+
views.dialog = definition["@dialog"] ? view(contextualize(base, definition["@dialog"])) : view(base);
|
|
39
|
+
return view(base);
|
|
55
40
|
}
|
|
56
41
|
function tokens(definition) {
|
|
57
42
|
return {
|
|
@@ -66,32 +51,28 @@ function tokens(definition) {
|
|
|
66
51
|
}
|
|
67
52
|
function contextualize(base, override) {
|
|
68
53
|
const result = mergeTheme(base, override);
|
|
69
|
-
const baseText = base.text?.action;
|
|
70
|
-
const contextText = override.text?.action;
|
|
71
|
-
const baseBackground = base.background?.action;
|
|
72
|
-
const contextBackground = override.background?.action;
|
|
73
54
|
const text = result["text"];
|
|
74
55
|
const background = result["background"];
|
|
75
56
|
return {
|
|
76
57
|
...result,
|
|
77
|
-
text: { ...text, action: contextualActions(
|
|
78
|
-
background: { ...background, action: contextualActions(
|
|
58
|
+
text: { ...text, action: contextualActions(base.text?.action, override.text?.action) },
|
|
59
|
+
background: { ...background, action: contextualActions(base.background?.action, override.background?.action) },
|
|
79
60
|
};
|
|
80
61
|
}
|
|
81
|
-
function contextualActions(base,
|
|
62
|
+
function contextualActions(base, surface) {
|
|
82
63
|
return Object.fromEntries(ActionVariant.literals.map((variant) => {
|
|
83
64
|
const baseVariant = base?.[variant];
|
|
84
|
-
const
|
|
65
|
+
const surfaceVariant = surface?.[variant];
|
|
85
66
|
return [
|
|
86
67
|
variant,
|
|
87
|
-
Object.fromEntries(["
|
|
88
|
-
const key = state === "
|
|
68
|
+
Object.fromEntries(["base", ...ActionState.literals].map((state) => {
|
|
69
|
+
const key = state === "base" ? undefined : `$${state}`;
|
|
89
70
|
return [
|
|
90
|
-
key ?? "
|
|
91
|
-
(key ?
|
|
92
|
-
|
|
71
|
+
key ?? "base",
|
|
72
|
+
(key ? surfaceVariant?.[key] : undefined) ??
|
|
73
|
+
surfaceVariant?.base ??
|
|
93
74
|
(key ? baseVariant?.[key] : undefined) ??
|
|
94
|
-
baseVariant?.
|
|
75
|
+
baseVariant?.base,
|
|
95
76
|
];
|
|
96
77
|
})),
|
|
97
78
|
];
|
|
@@ -99,7 +80,32 @@ function contextualActions(base, context) {
|
|
|
99
80
|
}
|
|
100
81
|
function resolveView(definition, hue, categorical, hueSteps) {
|
|
101
82
|
const source = { hue, ...definition };
|
|
102
|
-
|
|
83
|
+
const resolved = createResolver(source)(source, "theme");
|
|
84
|
+
return {
|
|
85
|
+
...resolved,
|
|
86
|
+
hue,
|
|
87
|
+
categorical,
|
|
88
|
+
text: {
|
|
89
|
+
...resolved.text,
|
|
90
|
+
action: statefulActions(resolved.text.action),
|
|
91
|
+
formfield: statefulColor(resolved.text.formfield),
|
|
92
|
+
},
|
|
93
|
+
background: {
|
|
94
|
+
...resolved.background,
|
|
95
|
+
action: statefulActions(resolved.background.action),
|
|
96
|
+
formfield: statefulColor(resolved.background.formfield),
|
|
97
|
+
},
|
|
98
|
+
...hueSteps,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function statefulActions(actions) {
|
|
102
|
+
return Object.fromEntries(ActionVariant.literals.map((variant) => [variant, statefulColor(actions[variant])]));
|
|
103
|
+
}
|
|
104
|
+
function statefulColor(color) {
|
|
105
|
+
return {
|
|
106
|
+
...color,
|
|
107
|
+
state: (states) => color[ActionState.literals.find((state) => states[state]) ?? "base"],
|
|
108
|
+
};
|
|
103
109
|
}
|
|
104
110
|
function compileHueSteps(hue) {
|
|
105
111
|
const index = new WeakMap();
|