@whatsaaaa/design-system 0.3.1 → 0.4.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/README.md CHANGED
@@ -65,7 +65,7 @@ CI runs on every pull request:
65
65
  - the unit tests, with the contrast of every role pair in both themes,
66
66
  - that `assets/` is what the sources produce,
67
67
  - that the package and the style guide build,
68
- - the browser tests: no page overflows sideways at phone, tablet and desktop width in either theme, no page logs an error when it loads, the easter egg works with the mouse, the keyboard and reduced motion, the keys of the status line work and their switch turns them off, the path of the status line gives way at every width from 320 px and the theme button switches the theme, an element for one theme shows only in it, the browser's theme-color follows the theme, a control that takes the focus is not left under the status line and no bar or corner of the window cuts off its focus ring, the first tab starts on the border of the sidebar, both fonts draw Serbian Latin, and the pages of the style guide look like their stored screenshots.
68
+ - the browser tests: no page overflows sideways at phone, tablet and desktop width in either theme, no page logs an error when it loads, the easter egg works with the mouse, the keyboard and reduced motion, the keys of the status line work and their switch turns them off, the path of the status line gives way at every width from 320 px and the theme button switches the theme, a `dark` or `light` class chooses the theme as `data-theme` does, an element for one theme shows only in it, the browser's theme-color follows the theme, a control that takes the focus is not left under the status line and no bar or corner of the window cuts off its focus ring, the first tab starts on the border of the sidebar, both fonts draw Serbian Latin, and the pages of the style guide look like their stored screenshots.
69
69
 
70
70
  The screenshots are in `tests/browser/__screenshots__/` and are taken on Linux, in the Playwright container, so they are the same on every machine. After a change that is meant to be seen, update them:
71
71
 
@@ -1,19 +1,15 @@
1
- :is(.ws-theme-dark, .ws-status-line__item--dark):where([data-theme="light"], [data-theme="light"] *):not([data-theme="light"] [data-theme="dark"], [data-theme="light"] [data-theme="dark"] *), :is(.ws-theme-dark, .ws-status-line__item--dark):where([data-theme="light"] [data-theme="dark"] [data-theme="light"], [data-theme="light"] [data-theme="dark"] [data-theme="light"] *):not([data-theme="light"] [data-theme="dark"] [data-theme="light"] [data-theme="dark"], [data-theme="light"] [data-theme="dark"] [data-theme="light"] [data-theme="dark"] *) {
2
- display: none !important;
3
- }
4
-
5
- :is(.ws-theme-light, .ws-status-line__item--light):where([data-theme="dark"], [data-theme="dark"] *):not([data-theme="dark"] [data-theme="light"], [data-theme="dark"] [data-theme="light"] *), :is(.ws-theme-light, .ws-status-line__item--light):where([data-theme="dark"] [data-theme="light"] [data-theme="dark"], [data-theme="dark"] [data-theme="light"] [data-theme="dark"] *):not([data-theme="dark"] [data-theme="light"] [data-theme="dark"] [data-theme="light"], [data-theme="dark"] [data-theme="light"] [data-theme="dark"] [data-theme="light"] *) {
1
+ :is(.ws-theme-dark, .ws-status-line__item--dark):where(:is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *):not(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *), :is(.ws-theme-dark, .ws-status-line__item--dark):where(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *):not(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *), :is(.ws-theme-light, .ws-status-line__item--light):where(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *):not(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *), :is(.ws-theme-light, .ws-status-line__item--light):where(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *):not(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *) {
6
2
  display: none !important;
7
3
  }
8
4
 
9
5
  @media (prefers-color-scheme: light) {
10
- :is(.ws-theme-dark, .ws-status-line__item--dark):not([data-theme], [data-theme] *) {
6
+ :is(.ws-theme-dark, .ws-status-line__item--dark):not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark)), :is([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) *) {
11
7
  display: none !important;
12
8
  }
13
9
  }
14
10
 
15
11
  @media not (prefers-color-scheme: light) {
16
- :is(.ws-theme-light, .ws-status-line__item--light):not([data-theme], [data-theme] *) {
12
+ :is(.ws-theme-light, .ws-status-line__item--light):not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark)), :is([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) *) {
17
13
  display: none !important;
18
14
  }
19
15
  }
@@ -1,19 +1,15 @@
1
- :is(.ws-theme-dark, .ws-status-line__item--dark):where([data-theme="light"], [data-theme="light"] *):not([data-theme="light"] [data-theme="dark"], [data-theme="light"] [data-theme="dark"] *), :is(.ws-theme-dark, .ws-status-line__item--dark):where([data-theme="light"] [data-theme="dark"] [data-theme="light"], [data-theme="light"] [data-theme="dark"] [data-theme="light"] *):not([data-theme="light"] [data-theme="dark"] [data-theme="light"] [data-theme="dark"], [data-theme="light"] [data-theme="dark"] [data-theme="light"] [data-theme="dark"] *) {
2
- display: none !important;
3
- }
4
-
5
- :is(.ws-theme-light, .ws-status-line__item--light):where([data-theme="dark"], [data-theme="dark"] *):not([data-theme="dark"] [data-theme="light"], [data-theme="dark"] [data-theme="light"] *), :is(.ws-theme-light, .ws-status-line__item--light):where([data-theme="dark"] [data-theme="light"] [data-theme="dark"], [data-theme="dark"] [data-theme="light"] [data-theme="dark"] *):not([data-theme="dark"] [data-theme="light"] [data-theme="dark"] [data-theme="light"], [data-theme="dark"] [data-theme="light"] [data-theme="dark"] [data-theme="light"] *) {
1
+ :is(.ws-theme-dark, .ws-status-line__item--dark):where(:is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *):not(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *), :is(.ws-theme-dark, .ws-status-line__item--dark):where(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *):not(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *), :is(.ws-theme-light, .ws-status-line__item--light):where(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *):not(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *), :is(.ws-theme-light, .ws-status-line__item--light):where(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *):not(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *) {
6
2
  display: none !important;
7
3
  }
8
4
 
9
5
  @media (prefers-color-scheme: light) {
10
- :is(.ws-theme-dark, .ws-status-line__item--dark):not([data-theme], [data-theme] *) {
6
+ :is(.ws-theme-dark, .ws-status-line__item--dark):not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark)), :is([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) *) {
11
7
  display: none !important;
12
8
  }
13
9
  }
14
10
 
15
11
  @media not (prefers-color-scheme: light) {
16
- :is(.ws-theme-light, .ws-status-line__item--light):not([data-theme], [data-theme] *) {
12
+ :is(.ws-theme-light, .ws-status-line__item--light):not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark)), :is([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) *) {
17
13
  display: none !important;
18
14
  }
19
15
  }
package/dist/index.css CHANGED
@@ -280,7 +280,7 @@
280
280
  --ws-text-overline-line-height: 1.5;
281
281
  }
282
282
 
283
- :root, [data-theme="dark"] {
283
+ :root, [data-theme="dark"], .dark:where(:not([data-theme], .light)) {
284
284
  --lightningcss-light: ;
285
285
  --lightningcss-dark: initial;
286
286
  color-scheme: dark;
@@ -315,7 +315,7 @@
315
315
  --ws-color-warning-tint: #f6c17717;
316
316
  }
317
317
 
318
- [data-theme="light"] {
318
+ [data-theme="light"], .light:where(:not([data-theme], .dark)) {
319
319
  --lightningcss-light: initial;
320
320
  --lightningcss-dark: ;
321
321
  color-scheme: light;
@@ -351,7 +351,7 @@
351
351
  }
352
352
 
353
353
  @media (prefers-color-scheme: light) {
354
- :root:not([data-theme]) {
354
+ :root:not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) {
355
355
  --lightningcss-light: initial;
356
356
  --lightningcss-dark: ;
357
357
  color-scheme: light;
@@ -884,22 +884,18 @@ code, kbd, samp, pre {
884
884
  margin: 0;
885
885
  }
886
886
 
887
- :is(.ws-theme-dark, .ws-status-line__item--dark):where([data-theme="light"], [data-theme="light"] *):not([data-theme="light"] [data-theme="dark"], [data-theme="light"] [data-theme="dark"] *), :is(.ws-theme-dark, .ws-status-line__item--dark):where([data-theme="light"] [data-theme="dark"] [data-theme="light"], [data-theme="light"] [data-theme="dark"] [data-theme="light"] *):not([data-theme="light"] [data-theme="dark"] [data-theme="light"] [data-theme="dark"], [data-theme="light"] [data-theme="dark"] [data-theme="light"] [data-theme="dark"] *) {
888
- display: none !important;
889
- }
890
-
891
- :is(.ws-theme-light, .ws-status-line__item--light):where([data-theme="dark"], [data-theme="dark"] *):not([data-theme="dark"] [data-theme="light"], [data-theme="dark"] [data-theme="light"] *), :is(.ws-theme-light, .ws-status-line__item--light):where([data-theme="dark"] [data-theme="light"] [data-theme="dark"], [data-theme="dark"] [data-theme="light"] [data-theme="dark"] *):not([data-theme="dark"] [data-theme="light"] [data-theme="dark"] [data-theme="light"], [data-theme="dark"] [data-theme="light"] [data-theme="dark"] [data-theme="light"] *) {
887
+ :is(.ws-theme-dark, .ws-status-line__item--dark):where(:is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *):not(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *), :is(.ws-theme-dark, .ws-status-line__item--dark):where(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *):not(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *), :is(.ws-theme-light, .ws-status-line__item--light):where(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *):not(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *), :is(.ws-theme-light, .ws-status-line__item--light):where(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *):not(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *) {
892
888
  display: none !important;
893
889
  }
894
890
 
895
891
  @media (prefers-color-scheme: light) {
896
- :is(.ws-theme-dark, .ws-status-line__item--dark):not([data-theme], [data-theme] *) {
892
+ :is(.ws-theme-dark, .ws-status-line__item--dark):not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark)), :is([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) *) {
897
893
  display: none !important;
898
894
  }
899
895
  }
900
896
 
901
897
  @media not (prefers-color-scheme: light) {
902
- :is(.ws-theme-light, .ws-status-line__item--light):not([data-theme], [data-theme] *) {
898
+ :is(.ws-theme-light, .ws-status-line__item--light):not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark)), :is([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) *) {
903
899
  display: none !important;
904
900
  }
905
901
  }
@@ -7,8 +7,8 @@
7
7
  */
8
8
  /**
9
9
  * A script for the <head> that keeps the theme-color tags in step from the first paint on:
10
- * when the stylesheet is there, whenever data-theme on <html> changes, whoever changes it,
11
- * and when the system's theme changes. The first paint waits for the stylesheets in the
12
- * <head>, and so does the first animation frame.
10
+ * when the stylesheet is there, whenever data-theme or the class of <html> changes, whoever
11
+ * changes it, and when the system's theme changes. The first paint waits for the stylesheets
12
+ * in the <head>, and so does the first animation frame.
13
13
  */
14
14
  export declare const themeColorScript: string;
@@ -9,8 +9,8 @@ const TAGS = 'meta[name="theme-color"]';
9
9
  const TOKEN = '--ws-color-bg';
10
10
  /**
11
11
  * A script for the <head> that keeps the theme-color tags in step from the first paint on:
12
- * when the stylesheet is there, whenever data-theme on <html> changes, whoever changes it,
13
- * and when the system's theme changes. The first paint waits for the stylesheets in the
14
- * <head>, and so does the first animation frame.
12
+ * when the stylesheet is there, whenever data-theme or the class of <html> changes, whoever
13
+ * changes it, and when the system's theme changes. The first paint waits for the stylesheets
14
+ * in the <head>, and so does the first animation frame.
15
15
  */
16
- export const themeColorScript = `(function(){var d=document,r=d.documentElement;function p(){var c=getComputedStyle(r).getPropertyValue(${JSON.stringify(TOKEN)}).trim(),m=d.querySelectorAll(${JSON.stringify(TAGS)});if(!c)return;if(!m.length){m=[d.createElement('meta')];m[0].name='theme-color';d.head.appendChild(m[0])}for(var i=0;i<m.length;i++)m[i].content=c}new MutationObserver(p).observe(r,{attributeFilter:['data-theme']});matchMedia('(prefers-color-scheme: light)').addEventListener('change',p);requestAnimationFrame(p);addEventListener('load',p)})()`;
16
+ export const themeColorScript = `(function(){var d=document,r=d.documentElement;function p(){var c=getComputedStyle(r).getPropertyValue(${JSON.stringify(TOKEN)}).trim(),m=d.querySelectorAll(${JSON.stringify(TAGS)});if(!c)return;if(!m.length){m=[d.createElement('meta')];m[0].name='theme-color';d.head.appendChild(m[0])}for(var i=0;i<m.length;i++)m[i].content=c}new MutationObserver(p).observe(r,{attributeFilter:['data-theme','class']});matchMedia('(prefers-color-scheme: light)').addEventListener('change',p);requestAnimationFrame(p);addEventListener('load',p)})()`;
@@ -2,7 +2,7 @@ export type Theme = 'dark' | 'light';
2
2
  export type ThemeChoice = Theme | 'system';
3
3
  /** Where the choice is kept in localStorage. Nothing is stored while it follows the system. */
4
4
  export declare const THEME_STORAGE_KEY = "ws-theme";
5
- /** The theme chosen by hand, or `system`. */
5
+ /** The theme chosen by hand, with data-theme or a dark or light class, or `system`. */
6
6
  export declare function getThemeChoice(): ThemeChoice;
7
7
  /** The theme the page shows right now. */
8
8
  export declare function getTheme(): Theme;
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * The theme switch. The stylesheet does the work: dark is the default, light applies when
3
- * the system asks for it, and data-theme="dark" or "light" on <html> overrides both.
4
- * This module sets that attribute by hand and remembers the choice. The head script keeps
5
- * the browser's own bars, such as a phone's address bar, at the background of the theme shown.
3
+ * the system asks for it, and data-theme="dark" or "light" on <html> overrides both, as does
4
+ * a dark or light class where there is no data-theme. This module sets the attribute by hand
5
+ * and remembers the choice. The head script keeps the browser's own bars, such as a phone's
6
+ * address bar, at the background of the theme shown.
6
7
  */
7
8
  import { themeColorScript } from "./color.js";
8
9
  /** Where the choice is kept in localStorage. Nothing is stored while it follows the system. */
@@ -18,10 +19,21 @@ function stored() {
18
19
  return null;
19
20
  }
20
21
  }
21
- /** The theme chosen by hand, or `system`. */
22
+ /** The theme a dark or light class on <html> chooses, as a color mode library sets it. */
23
+ function classTheme() {
24
+ const { classList } = document.documentElement;
25
+ const dark = classList.contains('dark');
26
+ if (dark === classList.contains('light'))
27
+ return null;
28
+ return dark ? 'dark' : 'light';
29
+ }
30
+ /** The theme chosen by hand, with data-theme or a dark or light class, or `system`. */
22
31
  export function getThemeChoice() {
23
32
  const attribute = document.documentElement.dataset.theme;
24
- return isTheme(attribute) ? attribute : (stored() ?? 'system');
33
+ if (isTheme(attribute))
34
+ return attribute;
35
+ // on one element data-theme wins over the class, as in the stylesheet
36
+ return (attribute === undefined ? classTheme() : null) ?? stored() ?? 'system';
25
37
  }
26
38
  /** The theme the page shows right now. */
27
39
  export function getTheme() {
@@ -1,2 +1,2 @@
1
1
  // Applies a remembered theme before the first paint, and keeps theme-color in step with the theme shown. Generated from src/theme/index.ts.
2
- (function(){try{var t=localStorage.getItem("ws-theme");if(t==='dark'||t==='light')document.documentElement.dataset.theme=t}catch(e){}})();(function(){var d=document,r=d.documentElement;function p(){var c=getComputedStyle(r).getPropertyValue("--ws-color-bg").trim(),m=d.querySelectorAll("meta[name=\"theme-color\"]");if(!c)return;if(!m.length){m=[d.createElement('meta')];m[0].name='theme-color';d.head.appendChild(m[0])}for(var i=0;i<m.length;i++)m[i].content=c}new MutationObserver(p).observe(r,{attributeFilter:['data-theme']});matchMedia('(prefers-color-scheme: light)').addEventListener('change',p);requestAnimationFrame(p);addEventListener('load',p)})()
2
+ (function(){try{var t=localStorage.getItem("ws-theme");if(t==='dark'||t==='light')document.documentElement.dataset.theme=t}catch(e){}})();(function(){var d=document,r=d.documentElement;function p(){var c=getComputedStyle(r).getPropertyValue("--ws-color-bg").trim(),m=d.querySelectorAll("meta[name=\"theme-color\"]");if(!c)return;if(!m.length){m=[d.createElement('meta')];m[0].name='theme-color';d.head.appendChild(m[0])}for(var i=0;i<m.length;i++)m[i].content=c}new MutationObserver(p).observe(r,{attributeFilter:['data-theme','class']});matchMedia('(prefers-color-scheme: light)').addEventListener('change',p);requestAnimationFrame(p);addEventListener('load',p)})()
@@ -0,0 +1,21 @@
1
+ :is(.ws-theme-dark, .ws-status-line__item--dark):where(:is([data-theme='light'], .light:where(:not([data-theme], .dark))), :is([data-theme='light'], .light:where(:not([data-theme], .dark))) *):not(:is([data-theme='light'], .light:where(:not([data-theme], .dark))) :is([data-theme='dark'], .dark:where(:not([data-theme], .light))), :is([data-theme='light'], .light:where(:not([data-theme], .dark))) :is([data-theme='dark'], .dark:where(:not([data-theme], .light))) *),
2
+ :is(.ws-theme-dark, .ws-status-line__item--dark):where(:is([data-theme='light'], .light:where(:not([data-theme], .dark))) :is([data-theme='dark'], .dark:where(:not([data-theme], .light))) :is([data-theme='light'], .light:where(:not([data-theme], .dark))), :is([data-theme='light'], .light:where(:not([data-theme], .dark))) :is([data-theme='dark'], .dark:where(:not([data-theme], .light))) :is([data-theme='light'], .light:where(:not([data-theme], .dark))) *):not(:is([data-theme='light'], .light:where(:not([data-theme], .dark))) :is([data-theme='dark'], .dark:where(:not([data-theme], .light))) :is([data-theme='light'], .light:where(:not([data-theme], .dark))) :is([data-theme='dark'], .dark:where(:not([data-theme], .light))), :is([data-theme='light'], .light:where(:not([data-theme], .dark))) :is([data-theme='dark'], .dark:where(:not([data-theme], .light))) :is([data-theme='light'], .light:where(:not([data-theme], .dark))) :is([data-theme='dark'], .dark:where(:not([data-theme], .light))) *) {
3
+ display: none !important;
4
+ }
5
+
6
+ :is(.ws-theme-light, .ws-status-line__item--light):where(:is([data-theme='dark'], .dark:where(:not([data-theme], .light))), :is([data-theme='dark'], .dark:where(:not([data-theme], .light))) *):not(:is([data-theme='dark'], .dark:where(:not([data-theme], .light))) :is([data-theme='light'], .light:where(:not([data-theme], .dark))), :is([data-theme='dark'], .dark:where(:not([data-theme], .light))) :is([data-theme='light'], .light:where(:not([data-theme], .dark))) *),
7
+ :is(.ws-theme-light, .ws-status-line__item--light):where(:is([data-theme='dark'], .dark:where(:not([data-theme], .light))) :is([data-theme='light'], .light:where(:not([data-theme], .dark))) :is([data-theme='dark'], .dark:where(:not([data-theme], .light))), :is([data-theme='dark'], .dark:where(:not([data-theme], .light))) :is([data-theme='light'], .light:where(:not([data-theme], .dark))) :is([data-theme='dark'], .dark:where(:not([data-theme], .light))) *):not(:is([data-theme='dark'], .dark:where(:not([data-theme], .light))) :is([data-theme='light'], .light:where(:not([data-theme], .dark))) :is([data-theme='dark'], .dark:where(:not([data-theme], .light))) :is([data-theme='light'], .light:where(:not([data-theme], .dark))), :is([data-theme='dark'], .dark:where(:not([data-theme], .light))) :is([data-theme='light'], .light:where(:not([data-theme], .dark))) :is([data-theme='dark'], .dark:where(:not([data-theme], .light))) :is([data-theme='light'], .light:where(:not([data-theme], .dark))) *) {
8
+ display: none !important;
9
+ }
10
+
11
+ @media (prefers-color-scheme: light) {
12
+ :is(.ws-theme-dark, .ws-status-line__item--dark):not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark)), :is([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) *) {
13
+ display: none !important;
14
+ }
15
+ }
16
+
17
+ @media not (prefers-color-scheme: light) {
18
+ :is(.ws-theme-light, .ws-status-line__item--light):not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark)), :is([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) *) {
19
+ display: none !important;
20
+ }
21
+ }
package/dist/tokens.css CHANGED
@@ -11,6 +11,7 @@
11
11
  *
12
12
  * Dark is the default. Light applies when the system asks for it, and data-theme="dark" or
13
13
  * data-theme="light" on any element overrides both for that element and everything inside it.
14
+ * So does a dark or light class, where the element has no data-theme.
14
15
  */
15
16
 
16
17
  :root {
@@ -348,7 +349,8 @@
348
349
  }
349
350
 
350
351
  :root,
351
- [data-theme='dark'] {
352
+ [data-theme='dark'],
353
+ .dark:where(:not([data-theme], .light)) {
352
354
  color-scheme: dark;
353
355
  /* Page background. */
354
356
  --ws-color-bg: var(--ws-palette-main-base);
@@ -410,7 +412,8 @@
410
412
  --ws-color-warning-tint: #f6c17717;
411
413
  }
412
414
 
413
- [data-theme='light'] {
415
+ [data-theme='light'],
416
+ .light:where(:not([data-theme], .dark)) {
414
417
  color-scheme: light;
415
418
  /* Page background. */
416
419
  --ws-color-bg: var(--ws-palette-dawn-base);
@@ -473,7 +476,7 @@
473
476
  }
474
477
 
475
478
  @media (prefers-color-scheme: light) {
476
- :root:not([data-theme]) {
479
+ :root:not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) {
477
480
  color-scheme: light;
478
481
  /* Page background. */
479
482
  --ws-color-bg: var(--ws-palette-dawn-base);
@@ -5,7 +5,8 @@ import { whatsaaaaMarkdown } from "./markdown.js";
5
5
  export { whatsaaaaMarkdown } from "./markdown.js";
6
6
  /**
7
7
  * Sets data-theme before the first paint, from the choice VitePress remembers.
8
- * VitePress itself only sets its `dark` class, which the tokens do not read.
8
+ * VitePress itself only sets its `dark` class, and no class for light, which the tokens would
9
+ * read as the system's theme.
9
10
  * Where storage is blocked nothing is remembered, and the page follows the system.
10
11
  */
11
12
  const themeScript = `;(() => {
package/docs/usage.md CHANGED
@@ -66,7 +66,7 @@ The pairs that are checked for contrast are in `tokens/contrast.json`. If you ne
66
66
 
67
67
  ## 3. Theme
68
68
 
69
- Dark is the default. Light applies when the system asks for it. `data-theme="dark"` or `data-theme="light"` on `<html>` overrides the system. Do not write your own `prefers-color-scheme` rules: the tokens already switch, and an element that has to differ by theme takes a class.
69
+ Dark is the default. Light applies when the system asks for it. `data-theme="dark"` or `data-theme="light"` on `<html>` overrides the system, and so does a `dark` or `light` class, as Nuxt UI and VueUse's `useColorMode` set it. A library that marks light only by leaving `dark` off, such as the toggle script in Tailwind's docs or VueUse's `useDark`, needs a `light` class kept in step with it: on when light is chosen, off for dark or the system. For Tailwind's script that is `classList.toggle('light', localStorage.theme === 'light')` next to its toggle of `dark`. With no class the system decides. Do not write your own `prefers-color-scheme` rules: the tokens already switch, and an element that has to differ by theme takes a class.
70
70
 
71
71
  ```ts
72
72
  import { getTheme, setTheme, toggleTheme, themeInitScript } from '@whatsaaaa/design-system/theme'
@@ -77,7 +77,7 @@ setTheme('system') // follows the system again
77
77
 
78
78
  Run the head script before the stylesheet, so a remembered choice applies before the first paint. Inline `themeInitScript` in a `<script>`, or load it as a file: `<script src=".../theme/init.js"></script>`. It is a plain script, not a module.
79
79
 
80
- The browser's own bars, such as a phone's address bar, take the background of the theme shown, `--ws-color-bg`. The head script keeps `<meta name="theme-color">` at it from the first paint on, when the theme is chosen by hand, with `setTheme`, `toggleTheme` or anything else that sets `data-theme`, and when the system's theme changes. A page that has no theme-color tag gets one, so the head needs no tag of its own and no color in it:
80
+ The browser's own bars, such as a phone's address bar, take the background of the theme shown, `--ws-color-bg`. The head script keeps `<meta name="theme-color">` at it from the first paint on, when the theme is chosen by hand, with `setTheme`, `toggleTheme` or anything else that sets `data-theme` or the class of `<html>`, and when the system's theme changes. A page that has no theme-color tag gets one, so the head needs no tag of its own and no color in it:
81
81
 
82
82
  ```html
83
83
  <head>
@@ -91,7 +91,7 @@ The browser's own bars, such as a phone's address bar, take the background of th
91
91
 
92
92
  A theme-color tag that is there, with or without `media`, takes the theme's color too. Do not set it from a script of your own. A docs site gets the same script from the base config of the docs theme.
93
93
 
94
- An element for one theme only, such as a cut of a mark, takes `ws-theme-dark` or `ws-theme-light`. Put both in the page and the styles show the one of the theme in effect where it stands: the nearest `data-theme`, on `<html>` or on an element around it, or the system's theme. So the right one shows before any script runs. Do not swap them from a script.
94
+ An element for one theme only, such as a cut of a mark, takes `ws-theme-dark` or `ws-theme-light`. Put both in the page and the styles show the one of the theme in effect where it stands: the nearest `data-theme` or `dark` or `light` class, on `<html>` or on an element around it, or the system's theme. So the right one shows before any script runs. Do not swap them from a script.
95
95
 
96
96
  ```html
97
97
  <img class="ws-theme-dark" src="mark-on-dark.svg" alt="whatsaaaa" width="32" height="32" />
@@ -100,7 +100,15 @@ An element for one theme only, such as a cut of a mark, takes `ws-theme-dark` or
100
100
 
101
101
  On a page with a status line, its theme button is the theme switch at every width: see [the status line](#status-line).
102
102
 
103
- `data-theme` also works on any element, to keep a part of a page in one theme.
103
+ `data-theme` also works on any element, to keep a part of a page in one theme, and so does the class. Where they meet:
104
+
105
+ - On one element, `data-theme` wins over the class. An element with both the `dark` and the `light` class chooses nothing.
106
+ - The nearest choice around an element holds for it, made either way: a `light` part in a page with `data-theme="dark"` is light.
107
+ - Any choice, the attribute or the class, wins over the system's theme.
108
+
109
+ So a `dark` or `light` class you give an element for something else puts what is inside it in that theme. Use another name for it.
110
+
111
+ `setTheme` and `toggleTheme` write `data-theme`, and `getTheme` reads it, then the class of `<html>`. In an app whose color mode library owns the class, such as Nuxt UI or `useColorMode`, switch the theme with the library and leave `data-theme` alone: do not call `setTheme` or `toggleTheme`, because the attribute they write wins over the library's class from then on. Keep the head script for the browser's bars. With nothing remembered under `ws-theme` it sets no `data-theme`, and it follows the class. So do not give the library that storage key. An app that called `setTheme` or `toggleTheme` before, such as from a script that bridged the two, has visitors with a choice still remembered there. Remove it before the head script runs, with `localStorage.removeItem('ws-theme')`, or the `data-theme` the head script sets from it wins over the library's class on every load.
104
112
 
105
113
  ## 4. Type
106
114
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatsaaaa/design-system",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Whatsaaaa's design system: brand identity, design tokens, typography, docs theme and asset kit",
5
5
  "homepage": "https://github.com/whatsaaaa/design-system#readme",
6
6
  "bugs": "https://github.com/whatsaaaa/design-system/issues",
@@ -14,7 +14,8 @@ const { isDark } = useData()
14
14
  /** The slots this layout fills itself. A site's content for them goes inside, next to the theme's. */
15
15
  const OWN_SLOTS = ['nav-bar-content-after', 'doc-before', 'not-found', 'layout-bottom']
16
16
 
17
- // VitePress marks dark with a class on <html>. The tokens read data-theme, so mirror it.
17
+ // VitePress marks dark with a dark class on <html> and light with no class, which the tokens
18
+ // read as the system's theme. So data-theme says both.
18
19
  watchEffect(() => {
19
20
  if (inBrowser) document.documentElement.dataset.theme = isDark.value ? 'dark' : 'light'
20
21
  })