@opencode-ai/theme 0.0.0-next-16415 → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,182 +0,0 @@
1
- import { Schema } from "effect";
2
- export const HueStep = Schema.Literals([100, 200, 300, 400, 500, 600, 700, 800, 900]);
3
- export const BaseHue = Schema.Literals(["gray", "red", "orange", "yellow", "green", "cyan", "blue", "purple"]);
4
- export const HueAlias = Schema.Literals(["accent", "interactive", "neutral"]);
5
- export const ActionVariant = Schema.Literals(["primary", "destructive"]);
6
- export const ActionState = Schema.Literals(["disabled", "pressed", "focused", "selected", "hovered"]);
7
- export const FormfieldState = ActionState;
8
- export const FeedbackKind = Schema.Literals(["error", "warning", "success", "info"]);
9
- const Mode = Schema.Literals(["light", "dark"]);
10
- const HexColor = Schema.String.check(Schema.isPattern(/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i));
11
- const ColorValue = Schema.Union([
12
- HexColor,
13
- Schema.Literal("transparent"),
14
- Schema.TemplateLiteral(["$", Schema.NonEmptyString]),
15
- ]);
16
- export const HueName = Schema.Union([BaseHue, HueAlias]);
17
- export const CategoricalDefinition = Schema.Array(HueName).check(Schema.isMinLength(1));
18
- const HueColorValue = Schema.Union([HexColor, Schema.TemplateLiteral(["$hue.", HueName, ".", HueStep])]);
19
- const ContextKey = Schema.Literals(["@context:elevated", "@context:overlay"]);
20
- const HueScaleDefinition = Schema.Record(HueStep, HexColor);
21
- const HueValueDefinition = Schema.Union([Schema.TemplateLiteral(["$hue.", HueName]), HueScaleDefinition]);
22
- const HueDefinition = Schema.Struct({
23
- gray: HueValueDefinition,
24
- red: HueValueDefinition,
25
- orange: HueValueDefinition,
26
- yellow: HueValueDefinition,
27
- green: HueValueDefinition,
28
- cyan: HueValueDefinition,
29
- blue: HueValueDefinition,
30
- purple: HueValueDefinition,
31
- accent: HueValueDefinition,
32
- interactive: HueValueDefinition,
33
- neutral: HueValueDefinition,
34
- });
35
- const HueOverrideDefinition = Schema.Struct({
36
- gray: Schema.optional(HueValueDefinition),
37
- red: Schema.optional(HueValueDefinition),
38
- orange: Schema.optional(HueValueDefinition),
39
- yellow: Schema.optional(HueValueDefinition),
40
- green: Schema.optional(HueValueDefinition),
41
- cyan: Schema.optional(HueValueDefinition),
42
- blue: Schema.optional(HueValueDefinition),
43
- purple: Schema.optional(HueValueDefinition),
44
- accent: Schema.optional(HueValueDefinition),
45
- interactive: Schema.optional(HueValueDefinition),
46
- neutral: Schema.optional(HueValueDefinition),
47
- });
48
- const StatefulColorDefinition = Schema.Struct({
49
- default: Schema.optional(ColorValue),
50
- $hovered: Schema.optional(ColorValue),
51
- $focused: Schema.optional(ColorValue),
52
- $pressed: Schema.optional(ColorValue),
53
- $selected: Schema.optional(ColorValue),
54
- $disabled: Schema.optional(ColorValue),
55
- });
56
- const ActionColorDefinition = Schema.Struct({
57
- primary: Schema.optional(StatefulColorDefinition),
58
- destructive: Schema.optional(StatefulColorDefinition),
59
- });
60
- const TextFeedbackDefinition = Schema.Struct({
61
- default: Schema.optional(ColorValue),
62
- subdued: Schema.optional(ColorValue),
63
- });
64
- const BackgroundFeedbackDefinition = Schema.Struct({
65
- default: Schema.optional(ColorValue),
66
- });
67
- const TextDefinition = Schema.Struct({
68
- default: Schema.optional(ColorValue),
69
- subdued: Schema.optional(ColorValue),
70
- action: Schema.optional(ActionColorDefinition),
71
- formfield: Schema.optional(StatefulColorDefinition),
72
- feedback: Schema.optional(Schema.Struct({
73
- error: Schema.optional(TextFeedbackDefinition),
74
- warning: Schema.optional(TextFeedbackDefinition),
75
- success: Schema.optional(TextFeedbackDefinition),
76
- info: Schema.optional(TextFeedbackDefinition),
77
- })),
78
- });
79
- const BackgroundDefinition = Schema.Struct({
80
- default: Schema.optional(ColorValue),
81
- surface: Schema.optional(Schema.Struct({
82
- offset: Schema.optional(ColorValue),
83
- overlay: Schema.optional(ColorValue),
84
- })),
85
- action: Schema.optional(ActionColorDefinition),
86
- formfield: Schema.optional(StatefulColorDefinition),
87
- feedback: Schema.optional(Schema.Struct({
88
- error: Schema.optional(BackgroundFeedbackDefinition),
89
- warning: Schema.optional(BackgroundFeedbackDefinition),
90
- success: Schema.optional(BackgroundFeedbackDefinition),
91
- info: Schema.optional(BackgroundFeedbackDefinition),
92
- })),
93
- });
94
- export const SyntaxToken = Schema.Literals([
95
- "comment",
96
- "keyword",
97
- "function",
98
- "variable",
99
- "string",
100
- "number",
101
- "type",
102
- "operator",
103
- "punctuation",
104
- ]);
105
- export const SyntaxDefinition = Schema.Record(SyntaxToken, Schema.optionalKey(HueColorValue));
106
- export const MarkdownToken = Schema.Literals([
107
- "text",
108
- "heading",
109
- "link",
110
- "linkText",
111
- "code",
112
- "blockQuote",
113
- "emphasis",
114
- "strong",
115
- "horizontalRule",
116
- "listItem",
117
- "listEnumeration",
118
- "image",
119
- "imageText",
120
- "codeBlock",
121
- ]);
122
- export const MarkdownDefinition = Schema.Record(MarkdownToken, Schema.optionalKey(HueColorValue));
123
- const DiffDefinition = Schema.Struct({
124
- text: Schema.optional(Schema.Struct({
125
- added: Schema.optional(ColorValue),
126
- removed: Schema.optional(ColorValue),
127
- context: Schema.optional(ColorValue),
128
- hunkHeader: Schema.optional(ColorValue),
129
- })),
130
- background: Schema.optional(Schema.Struct({
131
- added: Schema.optional(ColorValue),
132
- removed: Schema.optional(ColorValue),
133
- context: Schema.optional(ColorValue),
134
- })),
135
- highlight: Schema.optional(Schema.Struct({ added: Schema.optional(ColorValue), removed: Schema.optional(ColorValue) })),
136
- lineNumber: Schema.optional(Schema.Struct({
137
- text: Schema.optional(ColorValue),
138
- background: Schema.optional(Schema.Struct({ added: Schema.optional(ColorValue), removed: Schema.optional(ColorValue) })),
139
- })),
140
- });
141
- const ThemeTokensDefinition = Schema.Struct({
142
- text: Schema.optional(TextDefinition),
143
- background: Schema.optional(BackgroundDefinition),
144
- border: Schema.optional(Schema.Struct({ default: Schema.optional(ColorValue) })),
145
- scrollbar: Schema.optional(Schema.Struct({ default: Schema.optional(ColorValue) })),
146
- diff: Schema.optional(DiffDefinition),
147
- syntax: Schema.optional(SyntaxDefinition),
148
- markdown: Schema.optional(MarkdownDefinition),
149
- });
150
- const ThemeDefinitionFields = Schema.Struct({
151
- hue: HueDefinition,
152
- categorical: Schema.optional(CategoricalDefinition),
153
- ...ThemeTokensDefinition.fields,
154
- "@context:elevated": Schema.optional(ThemeTokensDefinition),
155
- "@context:overlay": Schema.optional(ThemeTokensDefinition),
156
- });
157
- export const ThemeDefinition = ThemeDefinitionFields;
158
- const FileThemeDefinition = Schema.Struct({
159
- hue: Schema.optional(HueOverrideDefinition),
160
- categorical: Schema.optional(CategoricalDefinition),
161
- ...ThemeTokensDefinition.fields,
162
- "@context:elevated": Schema.optional(ThemeTokensDefinition),
163
- "@context:overlay": Schema.optional(ThemeTokensDefinition),
164
- });
165
- const MergeModeDefinition = Schema.Struct({
166
- mergeMode: Schema.Literal(true),
167
- hue: Schema.optional(HueOverrideDefinition),
168
- categorical: Schema.optional(CategoricalDefinition),
169
- ...ThemeTokensDefinition.fields,
170
- "@context:elevated": Schema.optional(ThemeTokensDefinition),
171
- "@context:overlay": Schema.optional(ThemeTokensDefinition),
172
- });
173
- export const ModeDefinition = Schema.Union([MergeModeDefinition, FileThemeDefinition]);
174
- const FileMetadata = {
175
- $schema: Schema.optional(Schema.String),
176
- version: Schema.Literal(2),
177
- standalone: Schema.optional(Schema.Boolean),
178
- };
179
- export const ThemeDocument = Schema.Union([
180
- Schema.Struct({ ...FileMetadata, light: ModeDefinition, dark: Schema.optional(ModeDefinition) }),
181
- Schema.Struct({ ...FileMetadata, light: Schema.optional(ModeDefinition), dark: ModeDefinition }),
182
- ]);
@@ -1,13 +0,0 @@
1
- import type { FileThemeDefinition, Mode, ThemeDefinition, ThemeDocument } from "./index.js";
2
- export declare function selectTheme(document: ThemeDocument & {
3
- light: ThemeDefinition;
4
- dark: ThemeDefinition;
5
- }, mode?: Mode): ThemeDefinition;
6
- export declare function selectTheme(document: ThemeDocument, mode?: Mode): FileThemeDefinition;
7
- export declare function selectThemeMode(document: ThemeDocument, mode?: Mode): {
8
- theme: FileThemeDefinition;
9
- mode: Mode;
10
- expanded: boolean;
11
- };
12
- export declare function themeModes(document: ThemeDocument): readonly Mode[];
13
- export declare function supportsThemeMode(document: ThemeDocument, mode: Mode): boolean;
@@ -1,36 +0,0 @@
1
- import { expandTheme, mergeTheme } from "./expand.js";
2
- export function selectTheme(document, mode) {
3
- return selectThemeMode(document, mode).theme;
4
- }
5
- export function selectThemeMode(document, mode = "light") {
6
- const modes = themeModes(document);
7
- const selectedMode = modes.includes(mode) ? mode : modes[0];
8
- const selected = document[selectedMode];
9
- if (!selected)
10
- throw new Error("Theme must provide at least one mode");
11
- if (merges(document.light) && merges(document.dark))
12
- throw new Error("Light and dark themes cannot both merge modes");
13
- if (!merges(selected))
14
- return { theme: selected, mode: selectedMode, expanded: false };
15
- const otherMode = selectedMode === "light" ? "dark" : "light";
16
- const other = document[otherMode];
17
- if (!other)
18
- throw new Error(`The ${selectedMode} theme cannot merge without a ${otherMode} theme`);
19
- const merged = mergeTheme(expandTheme(other), expandTheme(selected));
20
- if (!merged["hue"])
21
- throw new Error(`The ${otherMode} theme must provide hues when ${selectedMode} merges modes`);
22
- return { theme: merged, mode: selectedMode, expanded: true };
23
- }
24
- export function themeModes(document) {
25
- if (merges(document.light) && !document.dark)
26
- throw new Error("The light theme cannot merge without a dark theme");
27
- if (merges(document.dark) && !document.light)
28
- throw new Error("The dark theme cannot merge without a light theme");
29
- return ["light", "dark"].filter((mode) => document[mode] !== undefined);
30
- }
31
- export function supportsThemeMode(document, mode) {
32
- return themeModes(document).includes(mode);
33
- }
34
- function merges(definition) {
35
- return definition !== undefined && "mergeMode" in definition && definition.mergeMode === true;
36
- }
@@ -1,3 +0,0 @@
1
- import { SyntaxStyle } from "@opentui/core";
2
- import type { Mode, ResolvedThemeView } from "./index.js";
3
- export declare function generateSyntax(theme: ResolvedThemeView, mode: Mode): SyntaxStyle;
@@ -1,75 +0,0 @@
1
- import { SyntaxStyle } from "@opentui/core";
2
- export function generateSyntax(theme, mode) {
3
- const step = mode === "light" ? 800 : 200;
4
- const syntax = theme.syntax;
5
- const markdown = theme.markdown;
6
- const feedback = theme.text.feedback;
7
- return SyntaxStyle.fromTheme([
8
- rule(["default"], theme.text.default),
9
- rule(["prompt"], theme.hue.accent[step]),
10
- rule(["extmark.file"], feedback.warning.default, { bold: true }),
11
- rule(["extmark.agent"], theme.categorical[0][step], { bold: true }),
12
- // V1 migration preserves its selected/inverse foreground in this action state.
13
- rule(["extmark.paste"], theme.text.action.primary.focused, {
14
- background: feedback.warning.default,
15
- bold: true,
16
- }),
17
- rule(["comment", "comment.documentation"], syntax.comment, { italic: true }),
18
- rule(["string", "symbol", "character.special", "character"], syntax.string),
19
- rule(["number", "boolean", "constant", "float"], syntax.number),
20
- rule(["keyword.return", "keyword.conditional", "keyword.repeat", "keyword.coroutine"], syntax.keyword, {
21
- italic: true,
22
- }),
23
- rule(["keyword.type"], syntax.type, { bold: true, italic: true }),
24
- rule(["keyword.function", "function.method"], syntax.function),
25
- rule(["keyword"], syntax.keyword, { italic: true }),
26
- rule(["keyword.import", "string.escape", "string.regexp", "tag.attribute", "keyword.export"], syntax.keyword),
27
- rule(["operator", "keyword.operator", "punctuation.delimiter", "keyword.conditional.ternary"], syntax.operator),
28
- rule(["variable", "variable.parameter", "function.method.call", "function.call", "property", "parameter", "field"], syntax.variable),
29
- rule(["variable.member", "function", "constructor"], syntax.function),
30
- rule(["type", "module", "class", "namespace"], syntax.type),
31
- rule(["type.definition"], syntax.type, { bold: true }),
32
- rule(["punctuation", "punctuation.bracket"], syntax.punctuation),
33
- rule(["variable.builtin", "type.builtin", "function.builtin", "module.builtin", "constant.builtin", "variable.super"], feedback.error.default),
34
- rule(["keyword.directive", "keyword.modifier", "keyword.exception"], syntax.keyword, { italic: true }),
35
- rule(["punctuation.special", "tag.delimiter"], syntax.operator),
36
- rule([
37
- "markup.heading",
38
- "markup.heading.2",
39
- "markup.heading.3",
40
- "markup.heading.4",
41
- "markup.heading.5",
42
- "markup.heading.6",
43
- ], markdown.heading, { bold: true }),
44
- rule(["markup.heading.1"], markdown.heading, { bold: true, underline: true }),
45
- rule(["markup.bold", "markup.strong"], markdown.strong, { bold: true }),
46
- rule(["markup.italic"], markdown.emphasis, { italic: true }),
47
- rule(["markup.list"], markdown.listItem),
48
- rule(["markup.quote"], markdown.blockQuote, { italic: true }),
49
- rule(["markup.raw", "markup.raw.block"], markdown.code),
50
- rule(["markup.raw.inline"], markdown.code, { background: theme.background.default }),
51
- rule(["markup.link", "markup.link.url", "string.special", "string.special.url"], markdown.link, {
52
- underline: true,
53
- }),
54
- rule(["markup.link.label"], markdown.linkText, { underline: true }),
55
- rule(["label"], markdown.linkText),
56
- rule(["spell", "nospell"], theme.text.default),
57
- rule(["markup.underline"], theme.text.default, { underline: true }),
58
- rule(["comment.error"], feedback.error.default, { italic: true, bold: true }),
59
- rule(["comment.warning"], feedback.warning.default, { italic: true, bold: true }),
60
- rule(["comment.todo", "comment.note"], feedback.info.default, { italic: true, bold: true }),
61
- rule(["attribute", "annotation"], feedback.warning.default),
62
- rule(["tag"], feedback.error.default),
63
- rule(["markup.strikethrough", "markup.list.unchecked", "debug"], theme.text.subdued),
64
- rule(["markup.list.checked"], feedback.success.default),
65
- rule(["diff.plus"], theme.diff.text.added, { background: theme.diff.background.added }),
66
- rule(["diff.minus"], theme.diff.text.removed, { background: theme.diff.background.removed }),
67
- rule(["diff.delta"], theme.diff.text.context, { background: theme.diff.background.context }),
68
- rule(["error"], feedback.error.default, { bold: true }),
69
- rule(["warning"], feedback.warning.default, { bold: true }),
70
- rule(["info"], feedback.info.default),
71
- ]);
72
- }
73
- function rule(scope, foreground, style = {}) {
74
- return { scope, style: { foreground, ...style } };
75
- }
@@ -1,77 +0,0 @@
1
- import type { RGBA } from "@opentui/core";
2
- import type { ActionState, ActionVariant, BaseHue, FeedbackKind, HueAlias, HueStep, MarkdownToken, ContextKey, SyntaxToken } from "./schema.js";
3
- export type ResolvedActionState = "default" | ActionState;
4
- export type ResolvedFormfieldState = ResolvedActionState;
5
- export type HueScale = Readonly<Record<HueStep, RGBA>>;
6
- export type Hue = Readonly<Record<BaseHue | HueAlias, HueScale>>;
7
- export type HueSource = Readonly<{
8
- hue: BaseHue | HueAlias;
9
- step: HueStep;
10
- }>;
11
- export type Categorical = readonly HueScale[];
12
- export type StatefulColor = Readonly<Record<ResolvedActionState, RGBA>>;
13
- export type FormfieldColor = StatefulColor;
14
- export type ResolvedThemeView = {
15
- readonly hue: Hue;
16
- readonly categorical: Categorical;
17
- readonly source: (color: RGBA) => HueSource | undefined;
18
- readonly increase: (color: RGBA, amount?: number) => RGBA;
19
- readonly decrease: (color: RGBA, amount?: number) => RGBA;
20
- readonly text: {
21
- readonly default: RGBA;
22
- readonly subdued: RGBA;
23
- readonly action: Readonly<Record<ActionVariant, StatefulColor>>;
24
- readonly formfield: FormfieldColor;
25
- readonly feedback: Readonly<Record<FeedbackKind, {
26
- readonly default: RGBA;
27
- readonly subdued: RGBA;
28
- }>>;
29
- };
30
- readonly background: {
31
- readonly default: RGBA;
32
- readonly surface: {
33
- readonly offset: RGBA;
34
- readonly overlay: RGBA;
35
- };
36
- readonly action: Readonly<Record<ActionVariant, StatefulColor>>;
37
- readonly formfield: FormfieldColor;
38
- readonly feedback: Readonly<Record<FeedbackKind, {
39
- readonly default: RGBA;
40
- }>>;
41
- };
42
- readonly border: {
43
- readonly default: RGBA;
44
- };
45
- readonly scrollbar: {
46
- readonly default: RGBA;
47
- };
48
- readonly diff: {
49
- readonly text: {
50
- readonly added: RGBA;
51
- readonly removed: RGBA;
52
- readonly context: RGBA;
53
- readonly hunkHeader: RGBA;
54
- };
55
- readonly background: {
56
- readonly added: RGBA;
57
- readonly removed: RGBA;
58
- readonly context: RGBA;
59
- };
60
- readonly highlight: {
61
- readonly added: RGBA;
62
- readonly removed: RGBA;
63
- };
64
- readonly lineNumber: {
65
- readonly text: RGBA;
66
- readonly background: {
67
- readonly added: RGBA;
68
- readonly removed: RGBA;
69
- };
70
- };
71
- };
72
- readonly syntax: Readonly<Record<SyntaxToken, RGBA>>;
73
- readonly markdown: Readonly<Record<MarkdownToken, RGBA>>;
74
- };
75
- export type ResolvedTheme = ResolvedThemeView & {
76
- readonly contexts: Readonly<Partial<Record<ContextKey, ResolvedThemeView>>>;
77
- };
package/dist/tui/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import type { ThemeDocument } from "./index.js";
2
- import type { ThemeV1Json } from "./v1.js";
3
- export declare function migrateV1(theme: ThemeV1Json): ThemeDocument;