-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-theme.js
More file actions
179 lines (173 loc) · 5.15 KB
/
Copy pathcode-theme.js
File metadata and controls
179 lines (173 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**
* Expressive Code themes for Datasheet.
*
* Starlight ships Expressive Code with its own syntax themes, which bake in a
* full rainbow palette. That is exactly what Datasheet is not: the whole design
* holds chroma back so the single per-site accent means something. A default
* syntax theme puts six unrelated hues inside every code block and the page
* stops reading as one thing.
*
* So these are near-monochrome. Structure is carried by weight and by the
* neutral ramp; the accent appears on strings only, because strings are the
* part of a config snippet a reader is usually looking for. Comments drop well
* back — in reference docs they are asides, not content.
*
* The accent is baked in at build time rather than referenced as a CSS
* variable, because Shiki resolves token colours to literal hex while
* highlighting. That is fine: the accent is known when the plugin is
* configured, and it cannot change at runtime.
*/
/**
* @param {object} opts
* @param {string} opts.accent Site accent, used for strings.
* @returns {object} A VS Code style theme object accepted by Expressive Code.
*/
export function datasheetDark({ accent }) {
const bg = "#0e1014";
const fg = "#c3c9d4";
const bright = "#e2e5ec";
const dim = "#9aa1b0";
const faint = "#454b57";
return {
name: "datasheet-dark",
type: "dark",
colors: {
"editor.background": bg,
"editor.foreground": fg,
"editor.selectionBackground": "#232733",
"editorLineNumber.foreground": faint,
"editorLineNumber.activeForeground": dim,
},
tokenColors: tokens({ fg, bright, dim, faint, accent }),
};
}
/**
* @param {object} opts
* @param {string} opts.accent
* @returns {object}
*/
export function datasheetLight({ accent }) {
const bg = "#fbfbf9";
const fg = "#3a3a36";
const bright = "#141412";
const dim = "#6a6a62";
const faint = "#a8a79e";
return {
name: "datasheet-light",
type: "light",
colors: {
"editor.background": bg,
"editor.foreground": fg,
"editor.selectionBackground": "#e6e6e0",
"editorLineNumber.foreground": faint,
"editorLineNumber.activeForeground": dim,
},
tokenColors: tokens({ fg, bright, dim, faint, accent }),
};
}
/**
* Shared scope mapping. Four roles only — keyword/identifier, value, muted,
* comment — deliberately coarse so no snippet ends up speckled.
*/
function tokens({ fg, bright, dim, faint, accent }) {
return [
{
scope: ["comment", "punctuation.definition.comment"],
settings: { foreground: faint, fontStyle: "italic" },
},
{
scope: [
"string",
"string.quoted",
"string.template",
"punctuation.definition.string",
],
settings: { foreground: accent },
},
{
scope: [
"keyword",
"storage",
"storage.type",
"keyword.control",
"keyword.operator.new",
"variable.language",
"constant.language",
],
settings: { foreground: bright, fontStyle: "bold" },
},
{
scope: [
"entity.name.tag",
"entity.name.function",
"support.function",
"support.type",
"support.class",
],
settings: { foreground: bright },
},
{
// YAML/TOML/JSON keys — the left-hand column of every options example.
scope: [
"entity.name.tag.yaml",
"support.type.property-name",
"meta.object-literal.key",
"variable.other.key",
],
settings: { foreground: bright },
},
{
scope: [
"constant.numeric",
"constant.language.boolean",
"constant.other",
],
settings: { foreground: dim },
},
{
scope: [
"punctuation",
"meta.brace",
"keyword.operator",
"punctuation.separator",
],
settings: { foreground: dim },
},
{
scope: ["variable", "variable.other", "meta.definition.variable.name"],
settings: { foreground: fg },
},
];
}
/**
* Frame chrome — tab bars, borders, copy button — pulled onto the theme's
* hairlines. These accept CSS variables because they are emitted as CSS, not
* resolved by Shiki.
*
* @returns {object}
*/
export function datasheetStyleOverrides() {
return {
borderRadius: "2px",
borderColor: "var(--sl-color-hairline)",
codeBackground: "var(--gs-panel)",
codeFontFamily: "var(--sl-font-mono)",
uiFontFamily: "var(--sl-font-mono)",
uiFontSize: "0.6875rem",
frames: {
editorBackground: "var(--gs-panel)",
editorTabBarBackground: "var(--gs-bg)",
editorTabBarBorderBottomColor: "var(--sl-color-hairline)",
editorActiveTabBackground: "var(--gs-panel)",
editorActiveTabForeground: "var(--sl-color-white)",
editorActiveTabBorderColor: "var(--sl-color-hairline)",
editorActiveTabIndicatorTopColor: "var(--gs-accent)",
editorActiveTabIndicatorBottomColor: "transparent",
terminalBackground: "var(--gs-panel)",
terminalTitlebarBackground: "var(--gs-bg)",
terminalTitlebarBorderBottomColor: "var(--sl-color-hairline)",
terminalTitlebarForeground: "var(--gs-dim)",
frameBoxShadowCssValue: "none",
},
};
}