@astl/tokens 0.0.0 → 0.1.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.
- package/CHANGELOG.md +8 -0
- package/LICENSE +202 -0
- package/README.md +39 -0
- package/dist/built-in-templates.d.ts +4 -0
- package/dist/built-in-templates.d.ts.map +1 -0
- package/dist/built-in-templates.js +189 -0
- package/dist/built-in-templates.js.map +1 -0
- package/dist/css.d.ts +7 -0
- package/dist/css.d.ts.map +1 -0
- package/dist/css.js +46 -0
- package/dist/css.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/messages/en.json +6 -0
- package/dist/messages/pl.json +6 -0
- package/dist/templates.d.ts +92 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +324 -0
- package/dist/templates.js.map +1 -0
- package/dist/tokens.css +238 -0
- package/dist/tokens.d.ts +56 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +212 -0
- package/dist/tokens.js.map +1 -0
- package/package.json +39 -4
- package/src/built-in-templates.ts +204 -0
- package/src/css.ts +48 -0
- package/src/index.ts +32 -0
- package/src/messages/en.json +6 -0
- package/src/messages/pl.json +6 -0
- package/src/templates.ts +395 -0
- package/src/tokens.ts +319 -0
package/src/tokens.ts
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Neutral, brand-free design tokens. Every value becomes a CSS custom property `--astl-<name>`.
|
|
3
|
+
* Hosts brand the player by overriding these properties, never by styling internals.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type Theme = 'light' | 'dark' | 'hc';
|
|
7
|
+
|
|
8
|
+
/** `auto` follows `prefers-color-scheme` (light or dark). */
|
|
9
|
+
export type ThemeSetting = Theme | 'auto';
|
|
10
|
+
|
|
11
|
+
export const THEMES: readonly Theme[] = ['light', 'dark', 'hc'];
|
|
12
|
+
|
|
13
|
+
/** A slot of the group palette. */
|
|
14
|
+
export type PaletteSlot = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
15
|
+
|
|
16
|
+
/** A colour of the group palette. */
|
|
17
|
+
export type PaletteColor = `palette-${PaletteSlot}`;
|
|
18
|
+
|
|
19
|
+
/** The group palette: a colour (`palette-<n>`) and its soft fill (`palette-<n>-soft`) per slot. */
|
|
20
|
+
export type PaletteToken = PaletteColor | `${PaletteColor}-soft`;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The group palette in slot order: eight colours that tell groups apart (categories, pairs, zones, joined lines,
|
|
24
|
+
* found words, regions). Give groups the slots in order and start again after the eighth; each colour has a soft
|
|
25
|
+
* fill, `--astl-palette-<n>-soft`, for backgrounds.
|
|
26
|
+
* - Never red or green, the verdict colours: every slot stays at least 15 (CIEDE2000) from success and danger, and
|
|
27
|
+
* at least 10 from the partial amber (warning).
|
|
28
|
+
* - Neighbours stay apart for red-green colour blindness (protanopia, deuteranopia), also the eighth and the first:
|
|
29
|
+
* warm and cool slots alternate.
|
|
30
|
+
* - Each colour reads as text on the page and surface backgrounds (4.5:1, 7:1 in hc), and so do ink, ink-muted and
|
|
31
|
+
* the colour itself on its soft fill.
|
|
32
|
+
* - Colour never carries meaning alone: groups also differ by their label or a pattern. Under forced colours the
|
|
33
|
+
* palette gives way to system colours (CanvasText, and Canvas for the soft fills).
|
|
34
|
+
*/
|
|
35
|
+
export const PALETTE: readonly PaletteColor[] = [
|
|
36
|
+
'palette-1',
|
|
37
|
+
'palette-2',
|
|
38
|
+
'palette-3',
|
|
39
|
+
'palette-4',
|
|
40
|
+
'palette-5',
|
|
41
|
+
'palette-6',
|
|
42
|
+
'palette-7',
|
|
43
|
+
'palette-8',
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Per slot: the colour and its soft fill in light, the colour and its soft fill in dark, the colour in hc (darker,
|
|
48
|
+
* for 7:1; its fill is white, like every soft fill of hc). One row per slot keeps the player's first load small.
|
|
49
|
+
*/
|
|
50
|
+
const PALETTE_COLORS: readonly (readonly [string, string, string, string, string])[] = [
|
|
51
|
+
['#066086', '#e5f3fe', '#59c7fe', '#152c3a', '#035678'], // blue
|
|
52
|
+
['#7d5036', '#ffeee4', '#f9914d', '#37261c', '#884501'], // clay (orange in dark and hc)
|
|
53
|
+
['#6d377e', '#f8edfb', '#d08edc', '#332635', '#663575'], // purple
|
|
54
|
+
['#7c6301', '#f8f0e1', '#ffe490', '#2f2a19', '#6b5500'], // gold
|
|
55
|
+
['#016f6f', '#def5f5', '#10c7c8', '#0f2f2f', '#045455'], // teal
|
|
56
|
+
['#603211', '#ffede4', '#bd8c68', '#37271b', '#4e2104'], // brown
|
|
57
|
+
['#9a2b64', '#ffecf3', '#e27eaa', '#39242d', '#9a2562'], // magenta
|
|
58
|
+
['#4b4f00', '#f3f1e2', '#bdc16c', '#2b2b19', '#3d4100'], // olive
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
/** The palette tokens of a theme, or the system colours they become under forced colours. */
|
|
62
|
+
function palette(theme: Theme | 'forced'): Readonly<Record<PaletteToken, string>> {
|
|
63
|
+
return Object.fromEntries(
|
|
64
|
+
PALETTE.flatMap((color, i) => {
|
|
65
|
+
const [light = '', lightSoft = '', dark = '', darkSoft = '', hc = ''] = PALETTE_COLORS[i] ?? [];
|
|
66
|
+
const [main, soft] = {
|
|
67
|
+
light: [light, lightSoft],
|
|
68
|
+
dark: [dark, darkSoft],
|
|
69
|
+
hc: [hc, '#ffffff'],
|
|
70
|
+
forced: ['CanvasText', 'Canvas'],
|
|
71
|
+
}[theme];
|
|
72
|
+
return [
|
|
73
|
+
[color, main],
|
|
74
|
+
[`${color}-soft`, soft],
|
|
75
|
+
];
|
|
76
|
+
}),
|
|
77
|
+
) as Record<PaletteToken, string>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type ColorToken =
|
|
81
|
+
| 'canvas'
|
|
82
|
+
| 'surface'
|
|
83
|
+
| 'surface-raised'
|
|
84
|
+
| 'ink'
|
|
85
|
+
| 'ink-muted'
|
|
86
|
+
| 'line'
|
|
87
|
+
| 'outline'
|
|
88
|
+
| 'accent'
|
|
89
|
+
| 'on-accent'
|
|
90
|
+
| 'accent-soft'
|
|
91
|
+
| 'focus'
|
|
92
|
+
| 'success'
|
|
93
|
+
| 'success-soft'
|
|
94
|
+
| 'on-success'
|
|
95
|
+
| 'danger'
|
|
96
|
+
| 'danger-soft'
|
|
97
|
+
| 'warning'
|
|
98
|
+
| 'warning-soft'
|
|
99
|
+
| 'selected'
|
|
100
|
+
| 'selected-soft'
|
|
101
|
+
| PaletteToken;
|
|
102
|
+
|
|
103
|
+
export type ScaleToken =
|
|
104
|
+
| 'font-body'
|
|
105
|
+
| 'font-display'
|
|
106
|
+
| 'font-mono'
|
|
107
|
+
| 'size-content'
|
|
108
|
+
| 'size-ui'
|
|
109
|
+
| 'size-small'
|
|
110
|
+
| 'line-height-content'
|
|
111
|
+
| 'space-1'
|
|
112
|
+
| 'space-2'
|
|
113
|
+
| 'space-3'
|
|
114
|
+
| 'space-4'
|
|
115
|
+
| 'space-5'
|
|
116
|
+
| 'space-6'
|
|
117
|
+
| 'space-7'
|
|
118
|
+
| 'space-8'
|
|
119
|
+
| 'radius-s'
|
|
120
|
+
| 'radius-m'
|
|
121
|
+
| 'radius-l'
|
|
122
|
+
| 'radius-pill'
|
|
123
|
+
| 'outline-width'
|
|
124
|
+
| 'focus-width'
|
|
125
|
+
| 'focus-offset'
|
|
126
|
+
| 'target-min'
|
|
127
|
+
| 'duration-fast'
|
|
128
|
+
| 'duration-normal'
|
|
129
|
+
| 'separator-display';
|
|
130
|
+
|
|
131
|
+
/** Non-colour values that change with the theme. */
|
|
132
|
+
export type ThemeScaleToken = 'selected-bar' | 'selected-weight';
|
|
133
|
+
|
|
134
|
+
export type TokenName = ColorToken | ScaleToken | ThemeScaleToken;
|
|
135
|
+
|
|
136
|
+
export type ColorScheme = Readonly<Record<ColorToken, string>>;
|
|
137
|
+
|
|
138
|
+
export interface Tokens {
|
|
139
|
+
/** Theme-independent tokens: type, space, radii, widths, durations. */
|
|
140
|
+
readonly scale: Readonly<Record<ScaleToken, string>>;
|
|
141
|
+
/**
|
|
142
|
+
* Theme-dependent non-colour cues. `hc` marks selected items with a bar at their inline start and bold text, so
|
|
143
|
+
* selection never depends on a native control mark or on colour alone (and never looks like a verdict border).
|
|
144
|
+
*/
|
|
145
|
+
readonly themeScale: Readonly<Record<Theme, Readonly<Record<ThemeScaleToken, string>>>>;
|
|
146
|
+
/** Colours per theme. `hc` is black on white: every text pair reaches 7:1. */
|
|
147
|
+
readonly themes: Readonly<Record<Theme, ColorScheme>>;
|
|
148
|
+
/** System colours used under `forced-colors: active`. */
|
|
149
|
+
readonly forced: ColorScheme;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const systemStack =
|
|
153
|
+
'system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif';
|
|
154
|
+
|
|
155
|
+
export const tokens: Tokens = {
|
|
156
|
+
scale: {
|
|
157
|
+
'font-body': systemStack,
|
|
158
|
+
'font-display': systemStack,
|
|
159
|
+
'font-mono': 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',
|
|
160
|
+
'size-content': '1.1875rem',
|
|
161
|
+
'size-ui': '1rem',
|
|
162
|
+
'size-small': '0.875rem',
|
|
163
|
+
'line-height-content': '1.6',
|
|
164
|
+
'space-1': '0.25rem',
|
|
165
|
+
'space-2': '0.5rem',
|
|
166
|
+
'space-3': '0.75rem',
|
|
167
|
+
'space-4': '1rem',
|
|
168
|
+
'space-5': '1.5rem',
|
|
169
|
+
'space-6': '2rem',
|
|
170
|
+
'space-7': '3rem',
|
|
171
|
+
'space-8': '4rem',
|
|
172
|
+
'radius-s': '4px',
|
|
173
|
+
'radius-m': '8px',
|
|
174
|
+
'radius-l': '12px',
|
|
175
|
+
'radius-pill': '999px',
|
|
176
|
+
'outline-width': '2px',
|
|
177
|
+
'focus-width': '3px',
|
|
178
|
+
'focus-offset': '2px',
|
|
179
|
+
'target-min': '44px',
|
|
180
|
+
'duration-fast': '120ms',
|
|
181
|
+
'duration-normal': '200ms',
|
|
182
|
+
// `inline` shows the separator between options laid out as words (a select's buttons: "mat / hat"); looks set it.
|
|
183
|
+
'separator-display': 'none',
|
|
184
|
+
},
|
|
185
|
+
themeScale: {
|
|
186
|
+
light: { 'selected-bar': '0px', 'selected-weight': 'normal' },
|
|
187
|
+
dark: { 'selected-bar': '0px', 'selected-weight': 'normal' },
|
|
188
|
+
hc: { 'selected-bar': '6px', 'selected-weight': '700' },
|
|
189
|
+
},
|
|
190
|
+
themes: {
|
|
191
|
+
light: {
|
|
192
|
+
canvas: '#f3f4f6',
|
|
193
|
+
surface: '#ffffff',
|
|
194
|
+
'surface-raised': '#ffffff',
|
|
195
|
+
ink: '#16191d',
|
|
196
|
+
'ink-muted': '#4f5763',
|
|
197
|
+
line: '#d3d7de',
|
|
198
|
+
outline: '#6b7380',
|
|
199
|
+
accent: '#1d55c9',
|
|
200
|
+
'on-accent': '#ffffff',
|
|
201
|
+
'accent-soft': '#e7eefb',
|
|
202
|
+
focus: '#1d4fbf',
|
|
203
|
+
success: '#1b7337',
|
|
204
|
+
'success-soft': '#e5f3e9',
|
|
205
|
+
'on-success': '#ffffff',
|
|
206
|
+
danger: '#b3261e',
|
|
207
|
+
'danger-soft': '#fcebea',
|
|
208
|
+
warning: '#8a4f00',
|
|
209
|
+
'warning-soft': '#fcf1df',
|
|
210
|
+
selected: '#5233b8',
|
|
211
|
+
'selected-soft': '#efebfb',
|
|
212
|
+
...palette('light'),
|
|
213
|
+
},
|
|
214
|
+
dark: {
|
|
215
|
+
canvas: '#0f1114',
|
|
216
|
+
surface: '#1a1d21',
|
|
217
|
+
'surface-raised': '#23272c',
|
|
218
|
+
ink: '#eceef1',
|
|
219
|
+
'ink-muted': '#aab1bc',
|
|
220
|
+
line: '#3a3f47',
|
|
221
|
+
outline: '#8a929e',
|
|
222
|
+
accent: '#8bb3ff',
|
|
223
|
+
'on-accent': '#0a1530',
|
|
224
|
+
'accent-soft': '#1d2a45',
|
|
225
|
+
focus: '#9fc0ff',
|
|
226
|
+
success: '#6dcf8d',
|
|
227
|
+
'success-soft': '#14301f',
|
|
228
|
+
'on-success': '#062010',
|
|
229
|
+
danger: '#ff8a80',
|
|
230
|
+
'danger-soft': '#3d1715',
|
|
231
|
+
warning: '#f0bd62',
|
|
232
|
+
'warning-soft': '#3a2a0d',
|
|
233
|
+
selected: '#b9a6ff',
|
|
234
|
+
'selected-soft': '#2a2448',
|
|
235
|
+
...palette('dark'),
|
|
236
|
+
},
|
|
237
|
+
hc: {
|
|
238
|
+
canvas: '#ffffff',
|
|
239
|
+
surface: '#ffffff',
|
|
240
|
+
'surface-raised': '#ffffff',
|
|
241
|
+
ink: '#000000',
|
|
242
|
+
'ink-muted': '#2b2b2b',
|
|
243
|
+
line: '#000000',
|
|
244
|
+
outline: '#000000',
|
|
245
|
+
accent: '#000000',
|
|
246
|
+
'on-accent': '#ffffff',
|
|
247
|
+
'accent-soft': '#ffffff',
|
|
248
|
+
focus: '#000000',
|
|
249
|
+
success: '#005a1e',
|
|
250
|
+
'success-soft': '#ffffff',
|
|
251
|
+
'on-success': '#ffffff',
|
|
252
|
+
danger: '#8f0000',
|
|
253
|
+
'danger-soft': '#ffffff',
|
|
254
|
+
warning: '#5a3600',
|
|
255
|
+
'warning-soft': '#ffffff',
|
|
256
|
+
selected: '#000000',
|
|
257
|
+
'selected-soft': '#ffffff',
|
|
258
|
+
...palette('hc'),
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
forced: {
|
|
262
|
+
canvas: 'Canvas',
|
|
263
|
+
surface: 'Canvas',
|
|
264
|
+
'surface-raised': 'Canvas',
|
|
265
|
+
ink: 'CanvasText',
|
|
266
|
+
'ink-muted': 'CanvasText',
|
|
267
|
+
line: 'GrayText',
|
|
268
|
+
outline: 'ButtonText',
|
|
269
|
+
accent: 'Highlight',
|
|
270
|
+
'on-accent': 'HighlightText',
|
|
271
|
+
'accent-soft': 'Canvas',
|
|
272
|
+
focus: 'Highlight',
|
|
273
|
+
success: 'CanvasText',
|
|
274
|
+
'success-soft': 'Canvas',
|
|
275
|
+
'on-success': 'Canvas',
|
|
276
|
+
danger: 'CanvasText',
|
|
277
|
+
'danger-soft': 'Canvas',
|
|
278
|
+
warning: 'CanvasText',
|
|
279
|
+
'warning-soft': 'Canvas',
|
|
280
|
+
selected: 'Highlight',
|
|
281
|
+
'selected-soft': 'Canvas',
|
|
282
|
+
...palette('forced'),
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Text (foreground) on background pairs the themes guarantee: 4.5:1, and 7:1 in `hc`. Built by a pure call, so a
|
|
288
|
+
* bundle that does not use the list (the player) leaves it out.
|
|
289
|
+
*/
|
|
290
|
+
export const TEXT_PAIRS: readonly (readonly [ColorToken, ColorToken])[] = /* @__PURE__ */ (() => [
|
|
291
|
+
...(['canvas', 'surface', 'surface-raised'] as const).flatMap((bg) =>
|
|
292
|
+
(['ink', 'ink-muted', 'accent', 'success', 'danger', 'warning', 'selected'] as const).map(
|
|
293
|
+
(fg) => [fg, bg] as const,
|
|
294
|
+
),
|
|
295
|
+
),
|
|
296
|
+
...(['accent-soft', 'success-soft', 'danger-soft', 'warning-soft', 'selected-soft'] as const).flatMap(
|
|
297
|
+
(bg) => [['ink', bg] as const, ['ink-muted', bg] as const],
|
|
298
|
+
),
|
|
299
|
+
['on-accent', 'accent'],
|
|
300
|
+
['on-success', 'success'],
|
|
301
|
+
['accent', 'accent-soft'],
|
|
302
|
+
['success', 'success-soft'],
|
|
303
|
+
['danger', 'danger-soft'],
|
|
304
|
+
['warning', 'warning-soft'],
|
|
305
|
+
['selected', 'selected-soft'],
|
|
306
|
+
// The group palette: each colour on the page and surfaces; ink, ink-muted and the colour itself on its soft fill.
|
|
307
|
+
...PALETTE.flatMap((color) => [
|
|
308
|
+
...(['canvas', 'surface', 'surface-raised'] as const).map((bg) => [color, bg] as const),
|
|
309
|
+
...(['ink', 'ink-muted', color] as const).map((fg) => [fg, `${color}-soft`] as const),
|
|
310
|
+
]),
|
|
311
|
+
])();
|
|
312
|
+
|
|
313
|
+
/** Non-text pairs (control borders, focus rings, verdict borders) the themes guarantee: 3:1. Pure, as above. */
|
|
314
|
+
export const UI_PAIRS: readonly (readonly [ColorToken, ColorToken])[] = /* @__PURE__ */ (() =>
|
|
315
|
+
(['canvas', 'surface', 'surface-raised'] as const).flatMap((bg) =>
|
|
316
|
+
(['outline', 'focus', 'accent', 'success', 'danger', 'warning', 'selected'] as const).map(
|
|
317
|
+
(fg) => [fg, bg] as const,
|
|
318
|
+
),
|
|
319
|
+
))();
|