@filipgutica/design-system 1.0.38 → 1.0.39

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.
Files changed (43) hide show
  1. package/README.md +9 -8
  2. package/dist/theme-inputs.json +75 -0
  3. package/dist/themes/catppuccin.css +29 -2
  4. package/dist/themes/copper.css +7 -2
  5. package/dist/themes/fern.css +7 -2
  6. package/dist/themes/github.css +27 -0
  7. package/dist/themes/graphite-indigo.css +3 -2
  8. package/dist/themes/iris.css +7 -2
  9. package/dist/themes/lagoon.css +7 -2
  10. package/dist/themes/lapis.css +7 -2
  11. package/dist/tokens.d.ts +2 -1
  12. package/dist/tokens.js +92 -76
  13. package/dist/tokens.json +92 -76
  14. package/fonts/{OFL-IBM-Plex-Sans.txt → OFL-Inter.txt} +1 -1
  15. package/fonts/{OFL-IBM-Plex-Mono.txt → OFL-JetBrains-Mono.txt} +1 -1
  16. package/fonts/fonts.css +13 -13
  17. package/fonts/inter-latin-400-normal.woff2 +0 -0
  18. package/fonts/inter-latin-500-normal.woff2 +0 -0
  19. package/fonts/inter-latin-600-normal.woff2 +0 -0
  20. package/fonts/jetbrains-mono-latin-400-normal.woff2 +0 -0
  21. package/fonts/jetbrains-mono-latin-500-normal.woff2 +0 -0
  22. package/fonts/jetbrains-mono-latin-600-normal.woff2 +0 -0
  23. package/language/DESIGN.md +10 -9
  24. package/language/components.html +15 -17
  25. package/language/components.md +6 -6
  26. package/language/decisions.md +10 -6
  27. package/language/docs.html +2 -5
  28. package/language/product.html +0 -3
  29. package/language/reference.html +14 -15
  30. package/language/tokens.css +151 -13
  31. package/language/ui-sdk.css +2 -2
  32. package/package.json +2 -1
  33. package/theme-mapper/core.js +9 -8
  34. package/theme-mapper/engine.d.ts +37 -2
  35. package/theme-mapper/engine.js +49 -4
  36. package/theme-mapper/index.d.ts +5 -0
  37. package/theme-mapper/index.js +15 -0
  38. package/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
  39. package/fonts/ibm-plex-mono-latin-500-normal.woff2 +0 -0
  40. package/fonts/ibm-plex-mono-latin-600-normal.woff2 +0 -0
  41. package/fonts/ibm-plex-sans-latin-400-normal.woff2 +0 -0
  42. package/fonts/ibm-plex-sans-latin-500-normal.woff2 +0 -0
  43. package/fonts/ibm-plex-sans-latin-600-normal.woff2 +0 -0
@@ -5,7 +5,7 @@
5
5
  * DESIGN.md names these tokens; it never repeats their values.
6
6
  *
7
7
  * Two layers. The identity block at the top of :root is the theme's own: its hue
8
- * pair and fonts. This file carries the default theme. Another theme keeps this file
8
+ * pair, fonts, and base radius. This file carries the default theme. Another theme keeps this file
9
9
  * unchanged and loads its themes/<id>.css after it, on :root; that file may also set
10
10
  * the theme's neutrals. A new project can set the identity lines on :root in its own
11
11
  * stylesheet the same way. The dark blocks switch --color-project to
@@ -13,25 +13,34 @@
13
13
  * --color-nav-current-text, and --color-segmented-current-text at 4.5:1 on the new hue
14
14
  * and override them when they fall short. A theme file sets the last two for you; its
15
15
  * hue must carry --color-accent-text itself, which the contrast tests check.
16
- * The terminal plate tokens also belong to the identity layer; every other line is core.
16
+ * The terminal plate tokens draw the identity layer's captures but stay core: a theme
17
+ * does not set them. dist/theme-inputs.json lists every token a theme may set.
17
18
  *
18
19
  * Standalone HTML: import or inline this file.
19
20
  * Inline visuals: inherit the host font and theme variables; see DESIGN.md.
20
21
  * Repos: map these names onto the repository's own token system.
21
22
  *
22
23
  * Theme states: bare :root is light. prefers-color-scheme picks dark unless
23
- * data-theme="light" is set. data-theme="dark" forces dark.
24
+ * data-theme="light" is set. data-theme="dark" forces dark. data-theme="dark" or
25
+ * "light" on any element below <html>, or a .dark class on <html> or below it,
26
+ * themes that subtree; the subtree blocks at the end redeclare what each mode
27
+ * changes, and the subtree takes its mode's text colour. data-theme="light" wins over
28
+ * .dark on one element. A theme written by hand repeats its light values on
29
+ * :root [data-theme="light"] and its dark values on the dark subtree block's selectors,
30
+ * so they hold in a subtree too. A theme file does this for you.
24
31
  */
25
32
 
26
33
  :root {
27
34
  color-scheme: light;
28
35
 
29
- /* Identity layer: a project swaps these four lines. --color-project is the light-theme hue;
30
- --color-project-dark is the dark-theme hue, also used on terminal captures in both themes. */
36
+ /* Identity layer: a project swaps these five lines. --color-project is the light-theme hue;
37
+ --color-project-dark is the dark-theme hue, also used on terminal captures in both themes.
38
+ --radius-base sets every corner but the pill and the circle. */
31
39
  --color-project: #4b45d1;
32
40
  --color-project-dark: #a5a1ff;
33
- --font-ui: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
34
- --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
41
+ --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
42
+ --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
43
+ --radius-base: 8px;
35
44
 
36
45
  /* Core roles: only the identity lines above feed them. Neutral paper and graphite surfaces. */
37
46
  --color-bg: #f4f5f6;
@@ -170,14 +179,14 @@
170
179
  --measure: 68ch;
171
180
  --page-max: 960px;
172
181
  --page-wide: 1120px;
173
- --sidebar: 224px;
182
+ --sidebar-width: 224px;
174
183
 
175
184
  /* Shape */
176
- --radius-inline: 8px;
177
- --radius-control: 8px;
178
- --radius-panel: 12px;
179
- --radius-field: 8px;
180
- --radius-mark: 4px;
185
+ --radius-inline: var(--radius-base);
186
+ --radius-control: var(--radius-base);
187
+ --radius-panel: calc(var(--radius-base) * 1.5);
188
+ --radius-field: var(--radius-base);
189
+ --radius-mark: calc(var(--radius-base) * 0.5);
181
190
  --radius-pill: 999px;
182
191
  --radius-circle: 999px;
183
192
 
@@ -278,6 +287,133 @@
278
287
  --shadow-nav-current: var(--shadow-nav-current-dark);
279
288
  }
280
289
 
290
+ /* Subtree themes: data-theme="dark" or "light" on an element below <html>, or a .dark class on <html> or
291
+ below it, themes that subtree. Each block redeclares every token that differs between the modes or follows
292
+ one that does, so the tokens derived from them resolve again inside the subtree. The element paints its own
293
+ background, such as background: var(--color-bg). */
294
+
295
+ :root.dark:not(:where([data-theme="light"])), :root [data-theme="dark"], :root .dark:not(:where([data-theme="light"])) {
296
+ color-scheme: dark;
297
+ --color-project: var(--color-project-dark);
298
+ --color-bg: #0d1012;
299
+ --color-surface: #13171a;
300
+ --color-surface-raised: #181d21;
301
+ --color-surface-muted: #20262b;
302
+ --color-well: color-mix(in srgb, var(--color-bg) 87.5%, black);
303
+ --color-field-bg: var(--color-well);
304
+ --color-field-edge: var(--color-border-subtle);
305
+ --shadow-field: var(--shadow-sink);
306
+ --color-control-thumb: color-mix(in srgb, var(--color-surface-raised) 88%, white);
307
+ --color-nav-current: color-mix(in srgb, var(--color-accent) 20%, transparent);
308
+ --color-nav-current-text: var(--color-accent);
309
+ --color-segmented-current-text: var(--color-accent);
310
+ --color-row-hover: #20262b;
311
+ --color-row-selected: var(--color-surface-raised);
312
+ --color-border-subtle: #262d33;
313
+ --color-border: #78818a;
314
+ --color-text: #e6e9eb;
315
+ --color-muted: #9aa3ab;
316
+ --color-overlay: rgb(0 0 0 / 62%);
317
+ --color-accent: var(--color-project);
318
+ --color-accent-text: var(--color-bg);
319
+ --color-accent-hover: var(--color-text);
320
+ --color-button-hover: color-mix(in srgb, var(--color-accent) 85%, var(--color-text));
321
+ --color-link: #67c1df;
322
+ --color-focus: var(--color-accent);
323
+ --color-success: #4cc38a;
324
+ --color-warning: #e2a54b;
325
+ --color-error: #f0776c;
326
+ --color-info: #84adff;
327
+ --color-success-surface: #172d25;
328
+ --color-warning-surface: #2f281b;
329
+ --color-error-surface: #312020;
330
+ --color-info-surface: #202938;
331
+ --color-status-ink: var(--color-text);
332
+ --color-command-bg: var(--color-code);
333
+ --color-command-border: var(--color-border-subtle);
334
+ --color-code: var(--color-surface);
335
+ --color-code-text: var(--color-text);
336
+ --color-syntax-keyword: #d8c2a5;
337
+ --color-syntax-string: #a8bd9c;
338
+ --color-syntax-number: #d5b98c;
339
+ --color-syntax-comment: #a0a6b1;
340
+ --color-syntax-function: var(--color-syntax-keyword);
341
+ --color-syntax-type: var(--color-syntax-number);
342
+ --color-syntax-variable: var(--color-code-text);
343
+ --color-syntax-operator: var(--color-muted);
344
+ --color-syntax-punctuation: var(--color-muted);
345
+ --color-syntax-tag: var(--color-syntax-keyword);
346
+ --color-syntax-attribute: var(--color-syntax-number);
347
+ --shadow-raise: inset 0 1px 0 rgb(255 255 255 / 7%), 0 1px 2px rgb(0 0 0 / 45%);
348
+ --shadow-surface: 0 0 0 1px rgb(255 255 255 / 6%);
349
+ --shadow-sink: inset 1.2px 1.2px 3.6px rgb(0 0 0 / 55%), inset -1.2px -1.2px 3.6px rgb(255 255 255 / 5%);
350
+ --shadow-dialog: 0 8px 24px rgb(0 0 0 / 45%), 0 0 0 1px var(--color-border-subtle);
351
+ --shadow-nav-current: var(--shadow-nav-current-dark);
352
+ --shadow-field-focus: inset 0 0 0 2px color-mix(in srgb, var(--color-accent) 18%, transparent);
353
+ --shadow-field-focus-invalid: inset 0 0 0 2px color-mix(in srgb, var(--color-error) 18%, transparent);
354
+ }
355
+
356
+ :root [data-theme="light"] {
357
+ color-scheme: light;
358
+ --color-project: #4b45d1;
359
+ --color-bg: #f4f5f6;
360
+ --color-surface: #e9ebed;
361
+ --color-surface-raised: #fbfbfc;
362
+ --color-surface-muted: #e2e5e8;
363
+ --color-well: var(--color-surface-muted);
364
+ --color-field-bg: var(--color-surface-raised);
365
+ --color-field-edge: var(--color-border-subtle);
366
+ --shadow-field: none;
367
+ --color-control-thumb: var(--color-surface-raised);
368
+ --color-nav-current: color-mix(in srgb, var(--color-accent) 14%, var(--color-surface-raised));
369
+ --color-nav-current-text: var(--color-accent);
370
+ --color-segmented-current-text: var(--color-accent);
371
+ --color-row-hover: #e2e5e8;
372
+ --color-row-selected: var(--color-surface-raised);
373
+ --color-border-subtle: #d3d8dd;
374
+ --color-border: #6d747b;
375
+ --color-text: #101315;
376
+ --color-muted: #50575e;
377
+ --color-overlay: rgb(0 0 0 / 42%);
378
+ --color-accent: var(--color-project);
379
+ --color-accent-text: var(--color-bg);
380
+ --color-accent-hover: var(--color-text);
381
+ --color-button-hover: color-mix(in srgb, var(--color-accent) 85%, var(--color-text));
382
+ --color-link: #0b5f7c;
383
+ --color-focus: var(--color-accent);
384
+ --color-success: #157249;
385
+ --color-warning: #86532e;
386
+ --color-error: #bd342b;
387
+ --color-info: #175cd3;
388
+ --color-success-surface: #d9e5e1;
389
+ --color-warning-surface: #e7e2de;
390
+ --color-error-surface: #efe4e4;
391
+ --color-info-surface: #d9e3f2;
392
+ --color-status-ink: black;
393
+ --color-command-bg: var(--color-code);
394
+ --color-command-border: var(--color-border-subtle);
395
+ --color-code: var(--color-surface);
396
+ --color-code-text: var(--color-text);
397
+ --color-syntax-keyword: #715b42;
398
+ --color-syntax-string: #346347;
399
+ --color-syntax-number: #86532e;
400
+ --color-syntax-comment: #626772;
401
+ --color-syntax-function: var(--color-syntax-keyword);
402
+ --color-syntax-type: var(--color-syntax-number);
403
+ --color-syntax-variable: var(--color-code-text);
404
+ --color-syntax-operator: var(--color-muted);
405
+ --color-syntax-punctuation: var(--color-muted);
406
+ --color-syntax-tag: var(--color-syntax-keyword);
407
+ --color-syntax-attribute: var(--color-syntax-number);
408
+ --shadow-raise: 0 1px 2px rgb(16 24 40 / 12%), 0 0 0 1px rgb(16 24 40 / 6%);
409
+ --shadow-surface: 0 1px 2px rgb(16 24 40 / 6%), 0 0 0 1px rgb(16 24 40 / 6%);
410
+ --shadow-sink: inset 1.2px 1.2px 3.6px rgb(130 142 158 / 35%), inset -1.2px -1.2px 3.6px rgb(255 255 255 / 80%);
411
+ --shadow-dialog: 0 8px 24px rgb(16 16 24 / 12%), 0 0 0 1px var(--color-border-subtle);
412
+ --shadow-nav-current: 0 1px 3px rgb(130 142 158 / 40%);
413
+ --shadow-field-focus: inset 0 0 0 2px color-mix(in srgb, var(--color-accent) 18%, transparent);
414
+ --shadow-field-focus-invalid: inset 0 0 0 2px color-mix(in srgb, var(--color-error) 18%, transparent);
415
+ }
416
+
281
417
  /* Minimal base. Component styles live in components.html. The base sits in a layer, so any
282
418
  page or component rule outranks it whatever its specificity. A layered !important outranks an
283
419
  unlayered one, so reduced-motion exceptions belong here too. */
@@ -288,6 +424,8 @@ body { background: var(--color-bg); color: var(--color-text); }
288
424
  @layer base {
289
425
  *, *::before, *::after { box-sizing: border-box; }
290
426
  [hidden] { display: none !important; }
427
+ /* A subtree theme takes its mode's text colour, as the body does; the page paints its background. */
428
+ :where(:root.dark, :root [data-theme="dark"], :root [data-theme="light"], :root .dark) { color: var(--color-text); }
291
429
  body {
292
430
  margin: 0;
293
431
  font: var(--weight-regular) var(--text-md) / var(--leading) var(--font-ui);
@@ -199,7 +199,7 @@
199
199
  [data-slot="segmented-control"][data-orientation="horizontal"][data-size="sm"] > [data-slot="segmented-control-item"] { padding: 0 var(--space-2); }
200
200
  [data-slot="segmented-control"][data-orientation="horizontal"][data-size="lg"] { --item: var(--control-lg); font-size: var(--text-lg); }
201
201
  /* Line height 1 comes after the font shorthand, which would reset it: the label then sits centred in the item. */
202
- [data-slot="segmented-control"][data-orientation="horizontal"] > [data-slot="segmented-control-item"] { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: calc(var(--item) - 2 * var(--inset)); padding: 0 var(--space-3); border: 0; border-radius: calc(var(--radius-control) - var(--inset)); background: transparent; color: var(--color-muted); font: inherit; line-height: 1; cursor: pointer; }
202
+ [data-slot="segmented-control"][data-orientation="horizontal"] > [data-slot="segmented-control-item"] { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: calc(var(--item) - 2 * var(--inset)); padding: 0 var(--space-3); border: 0; border-radius: calc(var(--radius-control) - var(--inset)); background: transparent; color: var(--color-muted); font: inherit; line-height: normal; cursor: pointer; }
203
203
  [data-slot="segmented-control"][data-orientation="horizontal"][data-icon-only] > [data-slot="segmented-control-item"] { width: calc(var(--item) - 2 * var(--inset)); padding: 0; }
204
204
  /* Icon-only: a pill track with round options and thumb, concentric with it. A px radius keeps the thumb a pill while it moves. */
205
205
  [data-slot="segmented-control"][data-orientation="horizontal"][data-icon-only] { border-radius: var(--radius-pill); }
@@ -271,7 +271,7 @@
271
271
  The content holds a <header> (the title, then the close button) and a body that scrolls on its own.
272
272
  A top or bottom sheet is unsupported. */
273
273
  [data-slot="drawer-backdrop"] { position: fixed; inset: 0; background: var(--color-overlay); }
274
- [data-slot="drawer-content"]:is([data-side="left"], [data-side="right"]) { display: flex; flex-direction: column; width: min(calc(var(--sidebar) + var(--space-12)), calc(100vw - var(--space-12))); height: 100%; overflow: hidden; border: 1px solid transparent; background: var(--color-surface-raised); color: var(--color-text); box-shadow: var(--shadow-dialog); }
274
+ [data-slot="drawer-content"]:is([data-side="left"], [data-side="right"]) { display: flex; flex-direction: column; width: min(calc(var(--sidebar-width) + var(--space-12)), calc(100vw - var(--space-12))); height: 100%; overflow: hidden; border: 1px solid transparent; background: var(--color-surface-raised); color: var(--color-text); box-shadow: var(--shadow-dialog); }
275
275
  [data-slot="drawer-content"]:is([data-side="left"], [data-side="right"]) > header { display: flex; flex: none; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-subtle); }
276
276
  [data-slot="drawer-content"]:is([data-side="left"], [data-side="right"]) > :not(header) { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: var(--space-4); }
277
277
  [data-slot="drawer-content"]:is([data-side="left"], [data-side="right"]) > header > [data-slot="drawer-title"] { margin: 0; font-size: var(--text-md); font-weight: var(--weight-medium); letter-spacing: 0; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@filipgutica/design-system",
3
- "version": "1.0.38",
3
+ "version": "1.0.39",
4
4
  "description": "Filip's design language, tokens, and component catalogue for any framework",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -16,6 +16,7 @@
16
16
  "./themes/*.css": "./dist/themes/*.css",
17
17
  "./themes/*.tokens.json": "./dist/themes/*.tokens.json",
18
18
  "./tokens.json": "./dist/tokens.json",
19
+ "./theme-inputs.json": "./dist/theme-inputs.json",
19
20
  "./theme-mapper": {
20
21
  "types": "./theme-mapper/index.d.ts",
21
22
  "default": "./theme-mapper/index.js"
@@ -7,8 +7,9 @@ export const core = {
7
7
  "tokens": {
8
8
  "color-project": null,
9
9
  "color-project-dark": null,
10
- "font-ui": "\"IBM Plex Sans\", -apple-system, BlinkMacSystemFont, \"SF Pro Text\", \"Segoe UI\", system-ui, sans-serif",
11
- "font-mono": "\"IBM Plex Mono\", ui-monospace, \"SF Mono\", SFMono-Regular, Menlo, Consolas, monospace"
10
+ "font-ui": "\"Inter\", -apple-system, BlinkMacSystemFont, \"SF Pro Text\", \"Segoe UI\", system-ui, sans-serif",
11
+ "font-mono": "\"JetBrains Mono\", ui-monospace, \"SF Mono\", SFMono-Regular, Menlo, Consolas, monospace",
12
+ "radius-base": "8px"
12
13
  }
13
14
  },
14
15
  {
@@ -238,16 +239,16 @@ export const core = {
238
239
  "measure": "68ch",
239
240
  "page-max": "960px",
240
241
  "page-wide": "1120px",
241
- "sidebar": "224px"
242
+ "sidebar-width": "224px"
242
243
  }
243
244
  },
244
245
  {
245
246
  "tokens": {
246
- "radius-inline": "8px",
247
- "radius-control": "8px",
248
- "radius-panel": "12px",
249
- "radius-field": "8px",
250
- "radius-mark": "4px",
247
+ "radius-inline": "{radius-base}",
248
+ "radius-control": "{radius-base}",
249
+ "radius-panel": "calc({radius-base} * 1.5)",
250
+ "radius-field": "{radius-base}",
251
+ "radius-mark": "calc({radius-base} * 0.5)",
251
252
  "radius-pill": "999px",
252
253
  "radius-circle": "999px"
253
254
  }
@@ -8,13 +8,21 @@
8
8
  */
9
9
  /** @typedef {{ light: string, dark: string }} ModePair */
10
10
  /**
11
- * One theme's inputs, for light and for dark. Fonts and neutrals stay core unless the theme names its own.
11
+ * One theme's inputs, for light and for dark. Fonts, the base radius, and neutrals stay core unless the theme
12
+ * names its own.
12
13
  * @typedef {object} ThemeInputs
13
14
  * @property {ModePair} hue The hue, `--color-project` in light and `--color-project-dark`.
14
15
  * @property {{ ui?: string, mono?: string }} [fonts] The two font stacks.
16
+ * @property {string} [radius] The base radius, `--radius-base`, as a CSS length.
15
17
  * @property {{ light: Record<string, string>, dark: Record<string, string> }} [neutrals] Every NEUTRALS token, per mode.
16
18
  * @property {{ light?: Record<string, string>, dark?: Record<string, string> }} [syntax] Syntax colours by SYNTAX_ROLES
17
19
  * role, per mode. A role a theme leaves out stays core.
20
+ * @property {{ light?: Record<string, string>, dark?: Record<string, string> }} [textOnHue] The text on the hue's
21
+ * fills, by TEXT_ON_HUE_TOKENS name, per mode, for a theme that sets its own. Each value is `#rrggbb`, `white`,
22
+ * `black`, or a token reference such as `{color-bg}`; for example `{ light: { 'color-accent-text': '#ffffff' } }`.
23
+ * A token a theme leaves out keeps its default: `color-accent-text` stays `{color-bg}`, which a pale hue can fail,
24
+ * and the selected-fill text tokens take the first candidate that reaches 4.5:1, or the accent when none does.
25
+ * Run checkTheme on the result.
18
26
  */
19
27
  /**
20
28
  * Every token's resolved value in light and in dark, as getComputedStyle reports it.
@@ -48,6 +56,16 @@ export const SYNTAX_ROLES: string[];
48
56
  export const SURFACES: string[];
49
57
  /** The selected-fill text tokens, which take their readable value from the theme. */
50
58
  export const TEXT_ON_FILL_TOKENS: string[];
59
+ /** The text on the hue's fills, which a theme may set: the primary label and the selected-fill text. */
60
+ export const TEXT_ON_HUE_TOKENS: string[];
61
+ export function themeInputNames(data: TokenSource): {
62
+ hue: string[];
63
+ textOnHue: string[];
64
+ fonts: string[];
65
+ radius: string[];
66
+ neutrals: string[];
67
+ syntax: string[];
68
+ };
51
69
  export function applyTheme<Data extends TokenSource>(core: Data, theme: ThemeInputs): Data;
52
70
  /**
53
71
  * The contrast checks each theme must pass, in both modes.
@@ -75,7 +93,8 @@ export type ModePair = {
75
93
  dark: string;
76
94
  };
77
95
  /**
78
- * One theme's inputs, for light and for dark. Fonts and neutrals stay core unless the theme names its own.
96
+ * One theme's inputs, for light and for dark. Fonts, the base radius, and neutrals stay core unless the theme
97
+ * names its own.
79
98
  */
80
99
  export type ThemeInputs = {
81
100
  /**
@@ -89,6 +108,10 @@ export type ThemeInputs = {
89
108
  ui?: string;
90
109
  mono?: string;
91
110
  } | undefined;
111
+ /**
112
+ * The base radius, `--radius-base`, as a CSS length.
113
+ */
114
+ radius?: string | undefined;
92
115
  /**
93
116
  * Every NEUTRALS token, per mode.
94
117
  */
@@ -104,6 +127,18 @@ export type ThemeInputs = {
104
127
  light?: Record<string, string>;
105
128
  dark?: Record<string, string>;
106
129
  } | undefined;
130
+ /**
131
+ * The text on the hue's
132
+ * fills, by TEXT_ON_HUE_TOKENS name, per mode, for a theme that sets its own. Each value is `#rrggbb`, `white`,
133
+ * `black`, or a token reference such as `{color-bg}`; for example `{ light: { 'color-accent-text': '#ffffff' } }`.
134
+ * A token a theme leaves out keeps its default: `color-accent-text` stays `{color-bg}`, which a pale hue can fail,
135
+ * and the selected-fill text tokens take the first candidate that reaches 4.5:1, or the accent when none does.
136
+ * Run checkTheme on the result.
137
+ */
138
+ textOnHue?: {
139
+ light?: Record<string, string>;
140
+ dark?: Record<string, string>;
141
+ } | undefined;
107
142
  };
108
143
  /**
109
144
  * Every token's resolved value in light and in dark, as getComputedStyle reports it.
@@ -12,13 +12,21 @@
12
12
  */
13
13
  /** @typedef {{ light: string, dark: string }} ModePair */
14
14
  /**
15
- * One theme's inputs, for light and for dark. Fonts and neutrals stay core unless the theme names its own.
15
+ * One theme's inputs, for light and for dark. Fonts, the base radius, and neutrals stay core unless the theme
16
+ * names its own.
16
17
  * @typedef {object} ThemeInputs
17
18
  * @property {ModePair} hue The hue, `--color-project` in light and `--color-project-dark`.
18
19
  * @property {{ ui?: string, mono?: string }} [fonts] The two font stacks.
20
+ * @property {string} [radius] The base radius, `--radius-base`, as a CSS length.
19
21
  * @property {{ light: Record<string, string>, dark: Record<string, string> }} [neutrals] Every NEUTRALS token, per mode.
20
22
  * @property {{ light?: Record<string, string>, dark?: Record<string, string> }} [syntax] Syntax colours by SYNTAX_ROLES
21
23
  * role, per mode. A role a theme leaves out stays core.
24
+ * @property {{ light?: Record<string, string>, dark?: Record<string, string> }} [textOnHue] The text on the hue's
25
+ * fills, by TEXT_ON_HUE_TOKENS name, per mode, for a theme that sets its own. Each value is `#rrggbb`, `white`,
26
+ * `black`, or a token reference such as `{color-bg}`; for example `{ light: { 'color-accent-text': '#ffffff' } }`.
27
+ * A token a theme leaves out keeps its default: `color-accent-text` stays `{color-bg}`, which a pale hue can fail,
28
+ * and the selected-fill text tokens take the first candidate that reaches 4.5:1, or the accent when none does.
29
+ * Run checkTheme on the result.
22
30
  */
23
31
  /**
24
32
  * Every token's resolved value in light and in dark, as getComputedStyle reports it.
@@ -162,6 +170,34 @@ const TEXT_ON_FILL = {
162
170
  /** The selected-fill text tokens, which take their readable value from the theme. */
163
171
  export const TEXT_ON_FILL_TOKENS = Object.keys(TEXT_ON_FILL)
164
172
  const TEXT_CANDIDATES = ['{color-accent}', '{color-text}', 'black', 'white']
173
+ /** The text on the hue's fills, which a theme may set: the primary label and the selected-fill text. */
174
+ export const TEXT_ON_HUE_TOKENS = ['color-accent-text', ...TEXT_ON_FILL_TOKENS]
175
+
176
+ /**
177
+ * The tokens a theme may set, by kind, without their leading dashes. Every other token is core, and a theme
178
+ * never overrides it: the identity group's hue pair, fonts, and base radius; the text on the hue's fills,
179
+ * which a theme sets when its hue cannot carry the default; the neutrals, as a whole set; and the syntax
180
+ * colours, which an imported theme sets.
181
+ * @param {TokenSource} data
182
+ * @returns {{ hue: string[], textOnHue: string[], fonts: string[], radius: string[], neutrals: string[], syntax: string[] }}
183
+ */
184
+ export const themeInputNames = (data) => {
185
+ const identity = Object.keys(data.groups.find(({ identity: isIdentity }) => isIdentity)?.tokens ?? {})
186
+ /** @param {string} prefix */
187
+ const take = (prefix) => identity.filter((name) => name.startsWith(prefix))
188
+ const inputs = {
189
+ hue: take('color-'),
190
+ textOnHue: [...TEXT_ON_HUE_TOKENS],
191
+ fonts: take('font-'),
192
+ radius: take('radius-'),
193
+ neutrals: [...NEUTRALS],
194
+ syntax: SYNTAX_ROLES.map((role) => `color-syntax-${role}`),
195
+ }
196
+ const sorted = Object.values(inputs).flat()
197
+ const unsorted = identity.filter((name) => !sorted.includes(name))
198
+ if (unsorted.length > 0) throw new Error(`Identity tokens with no input kind: ${unsorted.join(', ')}`)
199
+ return inputs
200
+ }
165
201
 
166
202
  // Sets each TEXT_ON_FILL token to its first candidate that reaches 4.5:1, per mode. When none does, the
167
203
  // accent stays, so the contrast tests fail on it rather than on a silently chosen colour.
@@ -188,8 +224,9 @@ const withReadableText = (data) => {
188
224
  }
189
225
 
190
226
  /**
191
- * The core tokens with one theme's inputs filled in. Core leaves the hue pair empty; its font stacks and
192
- * neutrals stay unless the theme names its own. Then each selected-fill text token takes its readable value.
227
+ * The core tokens with one theme's inputs filled in. Core leaves the hue pair empty; its font stacks, base
228
+ * radius, and neutrals stay unless the theme names its own. Then each selected-fill text token takes its readable value,
229
+ * and any text on the hue the theme sets replaces it.
193
230
  * @template {TokenSource} Data
194
231
  * @param {Data} core
195
232
  * @param {ThemeInputs} theme
@@ -205,6 +242,7 @@ export const applyTheme = (core, theme) => {
205
242
  identity['color-project-dark'] = theme.hue.dark
206
243
  if (theme.fonts?.ui) identity['font-ui'] = theme.fonts.ui
207
244
  if (theme.fonts?.mono) identity['font-mono'] = theme.fonts.mono
245
+ if (theme.radius) identity['radius-base'] = theme.radius
208
246
  const { neutrals } = theme
209
247
  if (neutrals) for (const name of NEUTRALS) groupOf(data, name).tokens[name] = [neutrals.light[name], neutrals.dark[name]]
210
248
  for (const role of SYNTAX_ROLES) {
@@ -214,7 +252,14 @@ export const applyTheme = (core, theme) => {
214
252
  const { tokens } = groupOf(data, name)
215
253
  tokens[name] = [light ?? valueFor(tokens, name, LIGHT), dark ?? valueFor(tokens, name, DARK)]
216
254
  }
217
- return withReadableText(data)
255
+ withReadableText(data)
256
+ for (const name of TEXT_ON_HUE_TOKENS) {
257
+ const [light, dark] = [theme.textOnHue?.light?.[name], theme.textOnHue?.dark?.[name]]
258
+ if (light === undefined && dark === undefined) continue
259
+ const { tokens } = groupOf(data, name)
260
+ tokens[name] = [light ?? valueFor(tokens, name, LIGHT), dark ?? valueFor(tokens, name, DARK)]
261
+ }
262
+ return data
218
263
  }
219
264
 
220
265
  // The contrast checks, as data: each pair is an ink and the fill below it, as language/components.html draws
@@ -1,5 +1,10 @@
1
+ export function checkTheme(inputs: ThemeInputs): ThemeCheck[];
1
2
  export type VsCodeTheme = import("./vscode.js").VsCodeTheme;
2
3
  export type MappedTheme = import("./vscode.js").MappedTheme;
3
4
  export type Problem = import("./vscode.js").Problem;
4
5
  export type ThemeColours = import("./vscode.js").ThemeColours;
6
+ export type ThemeInputs = import("./engine.js").ThemeInputs;
7
+ export type ThemeCheck = import("./engine.js").CheckResult & {
8
+ ok: boolean;
9
+ };
5
10
  export { ThemeValidationError, mapVsCodeTheme, themeVariables } from "./vscode.js";
@@ -1,8 +1,23 @@
1
1
  // @filipgutica/design-system/theme-mapper: maps other theme formats onto the design system's theme inputs,
2
2
  // with no framework and no runtime dependencies. Experimental: the API may change in a minor release.
3
+ import { core } from './core.js'
4
+ import { applyTheme, passes, resolveData, themeChecks } from './engine.js'
5
+
3
6
  export { ThemeValidationError, mapVsCodeTheme, themeVariables } from './vscode.js'
4
7
 
5
8
  /** @typedef {import('./vscode.js').VsCodeTheme} VsCodeTheme */
6
9
  /** @typedef {import('./vscode.js').MappedTheme} MappedTheme */
7
10
  /** @typedef {import('./vscode.js').Problem} Problem */
8
11
  /** @typedef {import('./vscode.js').ThemeColours} ThemeColours */
12
+ /** @typedef {import('./engine.js').ThemeInputs} ThemeInputs */
13
+ /** @typedef {import('./engine.js').CheckResult & { ok: boolean }} ThemeCheck */
14
+
15
+ /**
16
+ * Runs the contrast checks every shipped theme passes, in light and dark, on one theme's inputs: the same
17
+ * checks as the token build. Each result has its lowest ratio per mode, and `ok` when both reach its minimum.
18
+ * Use it to check a theme this package does not ship. Experimental.
19
+ * @param {ThemeInputs} inputs
20
+ * @returns {ThemeCheck[]}
21
+ */
22
+ export const checkTheme = (inputs) => themeChecks(resolveData(applyTheme(core, inputs)))
23
+ .map((check) => ({ ...check, ok: passes(check.light, check.min) && passes(check.dark, check.min) }))