@whatsaaaa/design-system 0.0.0 → 0.1.1

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 (168) hide show
  1. package/README.md +151 -0
  2. package/assets/building-blocks/apple-touch-icon.png +0 -0
  3. package/assets/building-blocks/favicon-16.png +0 -0
  4. package/assets/building-blocks/favicon-32.png +0 -0
  5. package/assets/building-blocks/favicon.ico +0 -0
  6. package/assets/building-blocks/favicon.svg +1 -0
  7. package/assets/building-blocks/icon-192.png +0 -0
  8. package/assets/building-blocks/icon-512.png +0 -0
  9. package/assets/building-blocks/lockup-dark.svg +1 -0
  10. package/assets/building-blocks/lockup-light.svg +1 -0
  11. package/assets/building-blocks/mark-mono.svg +1 -0
  12. package/assets/building-blocks/mark-on-dark.svg +1 -0
  13. package/assets/building-blocks/mark-on-light.svg +1 -0
  14. package/assets/building-blocks/mark.svg +1 -0
  15. package/assets/building-blocks/readme-header.png +0 -0
  16. package/assets/building-blocks/readme-header.svg +1 -0
  17. package/assets/building-blocks/social-card.png +0 -0
  18. package/assets/building-blocks/social-card.svg +1 -0
  19. package/assets/building-blocks/wordmark-dark.svg +1 -0
  20. package/assets/building-blocks/wordmark-light.svg +1 -0
  21. package/assets/dotfiles/apple-touch-icon.png +0 -0
  22. package/assets/dotfiles/favicon-16.png +0 -0
  23. package/assets/dotfiles/favicon-32.png +0 -0
  24. package/assets/dotfiles/favicon.ico +0 -0
  25. package/assets/dotfiles/favicon.svg +1 -0
  26. package/assets/dotfiles/icon-192.png +0 -0
  27. package/assets/dotfiles/icon-512.png +0 -0
  28. package/assets/dotfiles/lockup-dark.svg +1 -0
  29. package/assets/dotfiles/lockup-light.svg +1 -0
  30. package/assets/dotfiles/mark-mono.svg +1 -0
  31. package/assets/dotfiles/mark-on-dark.svg +1 -0
  32. package/assets/dotfiles/mark-on-light.svg +1 -0
  33. package/assets/dotfiles/mark.svg +1 -0
  34. package/assets/dotfiles/readme-header.png +0 -0
  35. package/assets/dotfiles/readme-header.svg +1 -0
  36. package/assets/dotfiles/social-card.png +0 -0
  37. package/assets/dotfiles/social-card.svg +1 -0
  38. package/assets/dotfiles/wordmark-dark.svg +1 -0
  39. package/assets/dotfiles/wordmark-light.svg +1 -0
  40. package/assets/form-builder/apple-touch-icon.png +0 -0
  41. package/assets/form-builder/favicon-16.png +0 -0
  42. package/assets/form-builder/favicon-32.png +0 -0
  43. package/assets/form-builder/favicon.ico +0 -0
  44. package/assets/form-builder/favicon.svg +1 -0
  45. package/assets/form-builder/icon-192.png +0 -0
  46. package/assets/form-builder/icon-512.png +0 -0
  47. package/assets/form-builder/lockup-dark.svg +1 -0
  48. package/assets/form-builder/lockup-light.svg +1 -0
  49. package/assets/form-builder/mark-mono.svg +1 -0
  50. package/assets/form-builder/mark-on-dark.svg +1 -0
  51. package/assets/form-builder/mark-on-light.svg +1 -0
  52. package/assets/form-builder/mark.svg +1 -0
  53. package/assets/form-builder/readme-header.png +0 -0
  54. package/assets/form-builder/readme-header.svg +1 -0
  55. package/assets/form-builder/social-card.png +0 -0
  56. package/assets/form-builder/social-card.svg +1 -0
  57. package/assets/form-builder/wordmark-dark.svg +1 -0
  58. package/assets/form-builder/wordmark-light.svg +1 -0
  59. package/assets/manifest.json +541 -0
  60. package/assets/whatsaaaa/apple-touch-icon.png +0 -0
  61. package/assets/whatsaaaa/favicon-16.png +0 -0
  62. package/assets/whatsaaaa/favicon-32.png +0 -0
  63. package/assets/whatsaaaa/favicon.ico +0 -0
  64. package/assets/whatsaaaa/favicon.svg +1 -0
  65. package/assets/whatsaaaa/icon-192.png +0 -0
  66. package/assets/whatsaaaa/icon-512.png +0 -0
  67. package/assets/whatsaaaa/lockup-dark.svg +1 -0
  68. package/assets/whatsaaaa/lockup-light.svg +1 -0
  69. package/assets/whatsaaaa/mark-mono.svg +1 -0
  70. package/assets/whatsaaaa/mark-on-dark.svg +1 -0
  71. package/assets/whatsaaaa/mark-on-light.svg +1 -0
  72. package/assets/whatsaaaa/mark.svg +1 -0
  73. package/assets/whatsaaaa/pose-blink-dark.svg +1 -0
  74. package/assets/whatsaaaa/pose-blink-light.svg +1 -0
  75. package/assets/whatsaaaa/pose-idle-dark.svg +1 -0
  76. package/assets/whatsaaaa/pose-idle-light.svg +1 -0
  77. package/assets/whatsaaaa/pose-lost-dark.svg +1 -0
  78. package/assets/whatsaaaa/pose-lost-light.svg +1 -0
  79. package/assets/whatsaaaa/pose-shout-dark.svg +1 -0
  80. package/assets/whatsaaaa/pose-shout-light.svg +1 -0
  81. package/assets/whatsaaaa/pose-wag-left-dark.svg +1 -0
  82. package/assets/whatsaaaa/pose-wag-left-light.svg +1 -0
  83. package/assets/whatsaaaa/pose-wag-right-dark.svg +1 -0
  84. package/assets/whatsaaaa/pose-wag-right-light.svg +1 -0
  85. package/assets/whatsaaaa/readme-header.png +0 -0
  86. package/assets/whatsaaaa/readme-header.svg +1 -0
  87. package/assets/whatsaaaa/social-card.png +0 -0
  88. package/assets/whatsaaaa/social-card.svg +1 -0
  89. package/assets/whatsaaaa/wordmark-dark.svg +1 -0
  90. package/assets/whatsaaaa/wordmark-light.svg +1 -0
  91. package/dist/color.d.ts +5 -0
  92. package/dist/color.js +7 -0
  93. package/dist/css/base.css +50 -0
  94. package/dist/css/callout.css +64 -0
  95. package/dist/css/code.css +50 -0
  96. package/dist/css/ghost.css +93 -0
  97. package/dist/css/icons.css +8 -0
  98. package/dist/css/prose.css +320 -0
  99. package/dist/css/terminal.css +424 -0
  100. package/dist/fonts/inter-latin-ext-wght-italic.woff2 +0 -0
  101. package/dist/fonts/inter-latin-ext-wght-normal.woff2 +0 -0
  102. package/dist/fonts/inter-latin-wght-italic.woff2 +0 -0
  103. package/dist/fonts/inter-latin-wght-normal.woff2 +0 -0
  104. package/dist/fonts/inter.OFL.txt +93 -0
  105. package/dist/fonts/jetbrains-mono-latin-ext-wght-italic.woff2 +0 -0
  106. package/dist/fonts/jetbrains-mono-latin-ext-wght-normal.woff2 +0 -0
  107. package/dist/fonts/jetbrains-mono-latin-wght-italic.woff2 +0 -0
  108. package/dist/fonts/jetbrains-mono-latin-wght-normal.woff2 +0 -0
  109. package/dist/fonts/jetbrains-mono.OFL.txt +93 -0
  110. package/dist/fonts.css +85 -0
  111. package/dist/ghost/bubble.d.ts +16 -0
  112. package/dist/ghost/bubble.js +50 -0
  113. package/dist/ghost/glyphs.d.ts +12 -0
  114. package/dist/ghost/glyphs.js +19 -0
  115. package/dist/ghost/index.d.ts +57 -0
  116. package/dist/ghost/index.js +227 -0
  117. package/dist/identity/ghost.d.ts +28 -0
  118. package/dist/identity/ghost.js +129 -0
  119. package/dist/identity/marks.d.ts +48 -0
  120. package/dist/identity/marks.js +52 -0
  121. package/dist/identity/sprite.d.ts +43 -0
  122. package/dist/identity/sprite.js +100 -0
  123. package/dist/index.css +1404 -0
  124. package/dist/shiki/index.d.ts +20 -0
  125. package/dist/shiki/index.js +64 -0
  126. package/dist/shortcuts/index.d.ts +48 -0
  127. package/dist/shortcuts/index.js +155 -0
  128. package/dist/shortcuts/init.js +2 -0
  129. package/dist/theme/index.d.ts +24 -0
  130. package/dist/theme/index.js +60 -0
  131. package/dist/theme/init.js +2 -0
  132. package/dist/tokens.css +537 -0
  133. package/dist/tokens.d.ts +194 -0
  134. package/dist/tokens.js +336 -0
  135. package/dist/vitepress-config/index.d.ts +16 -0
  136. package/dist/vitepress-config/index.js +36 -0
  137. package/dist/vitepress-config/markdown.d.ts +6 -0
  138. package/dist/vitepress-config/markdown.js +50 -0
  139. package/dist/vitepress-config/types.d.ts +16 -0
  140. package/dist/vitepress-config/types.js +1 -0
  141. package/docs/usage.md +226 -0
  142. package/licenses/README.md +10 -0
  143. package/licenses/departure-mono.OFL.txt +93 -0
  144. package/licenses/rose-pine-palette.LICENSE +21 -0
  145. package/package.json +155 -3
  146. package/src/vitepress/Layout.vue +77 -0
  147. package/src/vitepress/components/Crumb.vue +32 -0
  148. package/src/vitepress/components/NavGhost.vue +23 -0
  149. package/src/vitepress/components/NotFound.vue +22 -0
  150. package/src/vitepress/components/StatusLine.vue +128 -0
  151. package/src/vitepress/env.d.ts +2 -0
  152. package/src/vitepress/index.ts +34 -0
  153. package/src/vitepress/path.ts +19 -0
  154. package/src/vitepress/styles/doc.css +385 -0
  155. package/src/vitepress/styles/home.css +47 -0
  156. package/src/vitepress/styles/layout.css +97 -0
  157. package/src/vitepress/styles/nav.css +441 -0
  158. package/src/vitepress/styles/search.css +55 -0
  159. package/src/vitepress/styles/sidebar.css +173 -0
  160. package/src/vitepress/styles/vars.css +204 -0
  161. package/src/vitepress/support.ts +15 -0
  162. package/src/vitepress/theme.d.ts +8 -0
  163. package/tokens/contrast.json +271 -0
  164. package/tokens/core.tokens.json +743 -0
  165. package/tokens/palette.tokens.json +222 -0
  166. package/tokens/theme-dark.tokens.json +146 -0
  167. package/tokens/theme-light.tokens.json +146 -0
  168. package/tokens/whatsaaaa.resolver.json +43 -0
@@ -0,0 +1,20 @@
1
+ /** A TextMate theme, the format Shiki takes. */
2
+ export declare const codeTheme: {
3
+ name: string;
4
+ type: "dark";
5
+ colors: {
6
+ 'editor.background': string;
7
+ 'editor.foreground': string;
8
+ 'editor.selectionBackground': string;
9
+ };
10
+ tokenColors: {
11
+ scope: string[];
12
+ settings: {
13
+ foreground: string;
14
+ fontStyle: string;
15
+ } | {
16
+ foreground: string;
17
+ fontStyle?: undefined;
18
+ };
19
+ }[];
20
+ };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The code theme for Shiki, built from the tokens, for VitePress, Astro and anything else
3
+ * that highlights with Shiki. One theme for both page themes: code blocks stay dark.
4
+ *
5
+ * The official Rosé Pine code theme sets keywords in pine, which is 3.2:1 on the code
6
+ * background. This one keeps every syntax color at AA.
7
+ */
8
+ import { resolver } from '../../dist/tokens.js';
9
+ import { colorHex } from "../color.js";
10
+ const tokens = resolver.apply({ theme: 'dark' });
11
+ const hex = (id) => colorHex(tokens[id].$value);
12
+ const rule = (scope, foreground, fontStyle) => ({
13
+ scope,
14
+ settings: fontStyle ? { foreground, fontStyle } : { foreground },
15
+ });
16
+ /** A TextMate theme, the format Shiki takes. */
17
+ export const codeTheme = {
18
+ name: 'whatsaaaa',
19
+ type: 'dark',
20
+ colors: {
21
+ 'editor.background': hex('code.bg'),
22
+ 'editor.foreground': hex('code.text'),
23
+ 'editor.selectionBackground': hex('code.selection'),
24
+ },
25
+ tokenColors: [
26
+ rule(['comment', 'punctuation.definition.comment'], hex('syntax.comment'), 'italic'),
27
+ rule([
28
+ 'keyword',
29
+ 'storage',
30
+ 'storage.type',
31
+ 'storage.modifier',
32
+ 'keyword.control',
33
+ 'keyword.operator.new',
34
+ 'keyword.operator.expression',
35
+ ], hex('syntax.keyword')),
36
+ rule(['string', 'string.quoted', 'string.template', 'punctuation.definition.string'], hex('syntax.string')),
37
+ rule(['entity.name.function', 'support.function', 'meta.function-call', 'variable.function'], hex('syntax.function')),
38
+ rule([
39
+ 'entity.name.type',
40
+ 'entity.name.class',
41
+ 'support.type',
42
+ 'support.class',
43
+ 'entity.name.tag',
44
+ 'entity.other.attribute-name',
45
+ 'support.type.property-name',
46
+ 'meta.object-literal.key',
47
+ ], hex('syntax.type')),
48
+ rule([
49
+ 'constant',
50
+ 'constant.numeric',
51
+ 'constant.language',
52
+ 'constant.character',
53
+ 'variable.language',
54
+ 'support.constant',
55
+ ], hex('syntax.constant')),
56
+ rule(['punctuation', 'meta.brace', 'keyword.operator', 'meta.delimiter'], hex('syntax.punctuation')),
57
+ rule(['variable', 'variable.other', 'variable.parameter', 'meta.embedded', 'source'], hex('code.text')),
58
+ rule(['markup.heading', 'markup.bold'], hex('syntax.keyword'), 'bold'),
59
+ rule(['markup.italic'], hex('code.text'), 'italic'),
60
+ rule(['markup.underline.link', 'markup.inline.raw'], hex('syntax.type')),
61
+ rule(['markup.inserted'], hex('syntax.type')),
62
+ rule(['markup.deleted'], hex('syntax.keyword')),
63
+ ],
64
+ };
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Keyboard shortcuts that cannot lie, and that a visitor can switch off.
3
+ *
4
+ * A shortcut is declared on the control it presses, with `data-ws-key`, so pressing the key
5
+ * clicks that control and the hint and the action are one element. The number keys go to the
6
+ * tabs of a tab bar, which numbers them. The switch, declared with `data-ws-keys-switch`,
7
+ * turns every key off or on again, and the choice is kept in localStorage.
8
+ *
9
+ * The styles keep key hints hidden until `enableShortcuts()` has run, so a page never shows a
10
+ * hint for a key that does nothing. For the same reason `aria-keyshortcuts` is set here, while
11
+ * the key works, and not written in the markup. The state of the switch, `aria-checked`, is
12
+ * set here too: the styles keep the switch hidden until it has one, so it never shows a state
13
+ * that is not the real one. A key acts only on a page that has that switch: a page without it
14
+ * has no shortcuts.
15
+ *
16
+ * A held key acts once. The repeats a keyboard sends while a key is down do nothing, so a
17
+ * finger that rests on t does not flash the page between its themes.
18
+ *
19
+ * The markup and the rules for a page that uses this module are in docs/usage.md, section 7.
20
+ */
21
+ export interface ShortcutOptions {
22
+ /** A selector for the tabs the number keys go to, in their order. */
23
+ tabs?: string;
24
+ }
25
+ /** Where the choice is kept in localStorage. Nothing is stored while the keys are on. */
26
+ export declare const KEYS_STORAGE_KEY = "ws-keys";
27
+ /** Whether keys pressed on this element are typed into a field. Shortcuts leave those alone. */
28
+ export declare function isTyping(element: Element | null): boolean;
29
+ /** Whether single keys are shortcuts on this page right now: turned on, and not switched off. */
30
+ export declare function shortcutsOn(): boolean;
31
+ /**
32
+ * Turns the shortcuts on, unless the visitor has switched them off, and wires the switch.
33
+ * Returns a function that takes all of it away again. Call it once the status line is in
34
+ * the page.
35
+ *
36
+ * A key works only while the control that shows its hint is rendered and the page has the
37
+ * switch, and a held key works once. Keys typed into a field, and keys pressed with Ctrl,
38
+ * Alt or Cmd, are left alone.
39
+ */
40
+ export declare function enableShortcuts({ tabs }?: ShortcutOptions): () => void;
41
+ /**
42
+ * A script for the <head> that marks the page before the first paint when the keys are
43
+ * remembered as off. The styles then leave out what names a key, the numbers of the tabs
44
+ * among it, from the start instead of taking it away once `enableShortcuts()` runs.
45
+ *
46
+ * <script>{keysInitScript}</script>
47
+ */
48
+ export declare const keysInitScript: string;
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Keyboard shortcuts that cannot lie, and that a visitor can switch off.
3
+ *
4
+ * A shortcut is declared on the control it presses, with `data-ws-key`, so pressing the key
5
+ * clicks that control and the hint and the action are one element. The number keys go to the
6
+ * tabs of a tab bar, which numbers them. The switch, declared with `data-ws-keys-switch`,
7
+ * turns every key off or on again, and the choice is kept in localStorage.
8
+ *
9
+ * The styles keep key hints hidden until `enableShortcuts()` has run, so a page never shows a
10
+ * hint for a key that does nothing. For the same reason `aria-keyshortcuts` is set here, while
11
+ * the key works, and not written in the markup. The state of the switch, `aria-checked`, is
12
+ * set here too: the styles keep the switch hidden until it has one, so it never shows a state
13
+ * that is not the real one. A key acts only on a page that has that switch: a page without it
14
+ * has no shortcuts.
15
+ *
16
+ * A held key acts once. The repeats a keyboard sends while a key is down do nothing, so a
17
+ * finger that rests on t does not flash the page between its themes.
18
+ *
19
+ * The markup and the rules for a page that uses this module are in docs/usage.md, section 7.
20
+ */
21
+ /** Where the choice is kept in localStorage. Nothing is stored while the keys are on. */
22
+ export const KEYS_STORAGE_KEY = 'ws-keys';
23
+ const EDITABLE = 'input, textarea, select, [contenteditable=""], [contenteditable="true"]';
24
+ const DECLARED = '[data-ws-key]';
25
+ const SWITCH = '[data-ws-keys-switch]';
26
+ /** Whether keys pressed on this element are typed into a field. Shortcuts leave those alone. */
27
+ export function isTyping(element) {
28
+ return !!element?.closest(EDITABLE);
29
+ }
30
+ /** Whether single keys are shortcuts on this page right now: turned on, and not switched off. */
31
+ export function shortcutsOn() {
32
+ return document.documentElement.dataset.wsKeys === 'on';
33
+ }
34
+ function isVisible(element) {
35
+ // an element that is not rendered has no boxes
36
+ return element.getClientRects().length > 0;
37
+ }
38
+ function rememberedOff() {
39
+ try {
40
+ return localStorage.getItem(KEYS_STORAGE_KEY) === 'off';
41
+ }
42
+ catch {
43
+ // storage can be blocked. The keys are then on, and the switch holds for this page.
44
+ return false;
45
+ }
46
+ }
47
+ function remember(on) {
48
+ try {
49
+ if (on)
50
+ localStorage.removeItem(KEYS_STORAGE_KEY);
51
+ else
52
+ localStorage.setItem(KEYS_STORAGE_KEY, 'off');
53
+ }
54
+ catch {
55
+ // the choice still holds for this page
56
+ }
57
+ }
58
+ function targetFor(key, tabSelector) {
59
+ const declared = [...document.querySelectorAll(DECLARED)].find((element) => element.dataset.wsKey === key &&
60
+ isVisible(element) &&
61
+ !element.disabled &&
62
+ element.getAttribute('aria-disabled') !== 'true');
63
+ if (declared)
64
+ return declared;
65
+ if (/^[1-9]$/.test(key)) {
66
+ const tabs = [...document.querySelectorAll(tabSelector)].filter(isVisible);
67
+ return tabs[Number(key) - 1];
68
+ }
69
+ return undefined;
70
+ }
71
+ /**
72
+ * Turns the shortcuts on, unless the visitor has switched them off, and wires the switch.
73
+ * Returns a function that takes all of it away again. Call it once the status line is in
74
+ * the page.
75
+ *
76
+ * A key works only while the control that shows its hint is rendered and the page has the
77
+ * switch, and a held key works once. Keys typed into a field, and keys pressed with Ctrl,
78
+ * Alt or Cmd, are left alone.
79
+ */
80
+ export function enableShortcuts({ tabs = '.ws-tabs a' } = {}) {
81
+ const root = document.documentElement;
82
+ const switches = () => [...document.querySelectorAll(SWITCH)];
83
+ let on = !rememberedOff();
84
+ /**
85
+ * Says on the page what `on` holds: the styles show the hints by it, the switch has its
86
+ * state, and a control names its key to assistive technology only while the key works.
87
+ */
88
+ const show = () => {
89
+ const controls = switches();
90
+ const live = on && controls.length > 0;
91
+ for (const control of controls)
92
+ control.setAttribute('aria-checked', String(on));
93
+ for (const control of document.querySelectorAll(DECLARED)) {
94
+ if (live)
95
+ control.setAttribute('aria-keyshortcuts', control.dataset.wsKey);
96
+ else
97
+ control.removeAttribute('aria-keyshortcuts');
98
+ }
99
+ if (controls.length > 0)
100
+ root.dataset.wsKeys = on ? 'on' : 'off';
101
+ else
102
+ delete root.dataset.wsKeys;
103
+ };
104
+ const onKeyDown = (event) => {
105
+ if (!on || event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey)
106
+ return;
107
+ if (event.target instanceof Element && isTyping(event.target))
108
+ return;
109
+ if (switches().length === 0)
110
+ return;
111
+ const target = targetFor(event.key, tabs);
112
+ if (!target)
113
+ return;
114
+ event.preventDefault();
115
+ // the repeats of a held key are the page's too, and do nothing
116
+ if (!event.repeat)
117
+ target.click();
118
+ };
119
+ const onClick = (event) => {
120
+ if (!(event.target instanceof Element) || !event.target.closest(SWITCH))
121
+ return;
122
+ on = !on;
123
+ remember(on);
124
+ show();
125
+ };
126
+ // another tab or an embedded page of the same site flipped the switch
127
+ const onStorage = (event) => {
128
+ if (event.key !== KEYS_STORAGE_KEY && event.key !== null)
129
+ return;
130
+ on = !rememberedOff();
131
+ show();
132
+ };
133
+ document.addEventListener('keydown', onKeyDown);
134
+ document.addEventListener('click', onClick);
135
+ window.addEventListener('storage', onStorage);
136
+ show();
137
+ return () => {
138
+ document.removeEventListener('keydown', onKeyDown);
139
+ document.removeEventListener('click', onClick);
140
+ window.removeEventListener('storage', onStorage);
141
+ for (const control of switches())
142
+ control.removeAttribute('aria-checked');
143
+ for (const control of document.querySelectorAll(DECLARED))
144
+ control.removeAttribute('aria-keyshortcuts');
145
+ delete root.dataset.wsKeys;
146
+ };
147
+ }
148
+ /**
149
+ * A script for the <head> that marks the page before the first paint when the keys are
150
+ * remembered as off. The styles then leave out what names a key, the numbers of the tabs
151
+ * among it, from the start instead of taking it away once `enableShortcuts()` runs.
152
+ *
153
+ * <script>{keysInitScript}</script>
154
+ */
155
+ export const keysInitScript = `(function(){try{if(localStorage.getItem(${JSON.stringify(KEYS_STORAGE_KEY)})==='off')document.documentElement.dataset.wsKeys='off'}catch(e){}})()`;
@@ -0,0 +1,2 @@
1
+ // Marks the page before the first paint when the keys are remembered as off. Generated from src/shortcuts/index.ts.
2
+ (function(){try{if(localStorage.getItem("ws-keys")==='off')document.documentElement.dataset.wsKeys='off'}catch(e){}})()
@@ -0,0 +1,24 @@
1
+ /**
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.
5
+ */
6
+ export type Theme = 'dark' | 'light';
7
+ export type ThemeChoice = Theme | 'system';
8
+ /** Where the choice is kept in localStorage. Nothing is stored while it follows the system. */
9
+ export declare const THEME_STORAGE_KEY = "ws-theme";
10
+ /** The theme chosen by hand, or `system`. */
11
+ export declare function getThemeChoice(): ThemeChoice;
12
+ /** The theme the page shows right now. */
13
+ export declare function getTheme(): Theme;
14
+ /** Chooses a theme by hand, or `system` to follow the system setting again. */
15
+ export declare function setTheme(choice: ThemeChoice): void;
16
+ /** Switches to the other theme and returns it. */
17
+ export declare function toggleTheme(): Theme;
18
+ /**
19
+ * A script for the <head>, before any stylesheet, that applies a remembered choice before
20
+ * the first paint. Without it a page chosen dark by hand flashes light on a light system.
21
+ *
22
+ * <script>{themeInitScript}</script>
23
+ */
24
+ export declare const themeInitScript: string;
@@ -0,0 +1,60 @@
1
+ /**
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.
5
+ */
6
+ /** Where the choice is kept in localStorage. Nothing is stored while it follows the system. */
7
+ export const THEME_STORAGE_KEY = 'ws-theme';
8
+ const isTheme = (value) => value === 'dark' || value === 'light';
9
+ function stored() {
10
+ try {
11
+ const value = localStorage.getItem(THEME_STORAGE_KEY);
12
+ return isTheme(value) ? value : null;
13
+ }
14
+ catch {
15
+ // storage can be blocked. The theme then follows the system.
16
+ return null;
17
+ }
18
+ }
19
+ /** The theme chosen by hand, or `system`. */
20
+ export function getThemeChoice() {
21
+ const attribute = document.documentElement.dataset.theme;
22
+ return isTheme(attribute) ? attribute : (stored() ?? 'system');
23
+ }
24
+ /** The theme the page shows right now. */
25
+ export function getTheme() {
26
+ const choice = getThemeChoice();
27
+ if (choice !== 'system')
28
+ return choice;
29
+ return matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
30
+ }
31
+ /** Chooses a theme by hand, or `system` to follow the system setting again. */
32
+ export function setTheme(choice) {
33
+ const root = document.documentElement;
34
+ if (choice === 'system')
35
+ delete root.dataset.theme;
36
+ else
37
+ root.dataset.theme = choice;
38
+ try {
39
+ if (choice === 'system')
40
+ localStorage.removeItem(THEME_STORAGE_KEY);
41
+ else
42
+ localStorage.setItem(THEME_STORAGE_KEY, choice);
43
+ }
44
+ catch {
45
+ // the choice still holds for this page
46
+ }
47
+ }
48
+ /** Switches to the other theme and returns it. */
49
+ export function toggleTheme() {
50
+ const next = getTheme() === 'dark' ? 'light' : 'dark';
51
+ setTheme(next);
52
+ return next;
53
+ }
54
+ /**
55
+ * A script for the <head>, before any stylesheet, that applies a remembered choice before
56
+ * the first paint. Without it a page chosen dark by hand flashes light on a light system.
57
+ *
58
+ * <script>{themeInitScript}</script>
59
+ */
60
+ export const themeInitScript = `(function(){try{var t=localStorage.getItem(${JSON.stringify(THEME_STORAGE_KEY)});if(t==='dark'||t==='light')document.documentElement.dataset.theme=t}catch(e){}})()`;
@@ -0,0 +1,2 @@
1
+ // Applies a remembered theme before the first paint. 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){}})()