@whatsaaaa/design-system 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/LICENSE +51 -0
  2. package/README.md +150 -2
  3. package/assets/building-blocks/apple-touch-icon.png +0 -0
  4. package/assets/building-blocks/favicon-16.png +0 -0
  5. package/assets/building-blocks/favicon-32.png +0 -0
  6. package/assets/building-blocks/favicon.ico +0 -0
  7. package/assets/building-blocks/favicon.svg +1 -0
  8. package/assets/building-blocks/icon-192.png +0 -0
  9. package/assets/building-blocks/icon-512.png +0 -0
  10. package/assets/building-blocks/lockup-dark.svg +1 -0
  11. package/assets/building-blocks/lockup-light.svg +1 -0
  12. package/assets/building-blocks/mark-mono.svg +1 -0
  13. package/assets/building-blocks/mark-on-dark.svg +1 -0
  14. package/assets/building-blocks/mark-on-light.svg +1 -0
  15. package/assets/building-blocks/mark.svg +1 -0
  16. package/assets/building-blocks/readme-header.png +0 -0
  17. package/assets/building-blocks/readme-header.svg +1 -0
  18. package/assets/building-blocks/social-card.png +0 -0
  19. package/assets/building-blocks/social-card.svg +1 -0
  20. package/assets/building-blocks/wordmark-dark.svg +1 -0
  21. package/assets/building-blocks/wordmark-light.svg +1 -0
  22. package/assets/dotfiles/apple-touch-icon.png +0 -0
  23. package/assets/dotfiles/favicon-16.png +0 -0
  24. package/assets/dotfiles/favicon-32.png +0 -0
  25. package/assets/dotfiles/favicon.ico +0 -0
  26. package/assets/dotfiles/favicon.svg +1 -0
  27. package/assets/dotfiles/icon-192.png +0 -0
  28. package/assets/dotfiles/icon-512.png +0 -0
  29. package/assets/dotfiles/lockup-dark.svg +1 -0
  30. package/assets/dotfiles/lockup-light.svg +1 -0
  31. package/assets/dotfiles/mark-mono.svg +1 -0
  32. package/assets/dotfiles/mark-on-dark.svg +1 -0
  33. package/assets/dotfiles/mark-on-light.svg +1 -0
  34. package/assets/dotfiles/mark.svg +1 -0
  35. package/assets/dotfiles/readme-header.png +0 -0
  36. package/assets/dotfiles/readme-header.svg +1 -0
  37. package/assets/dotfiles/social-card.png +0 -0
  38. package/assets/dotfiles/social-card.svg +1 -0
  39. package/assets/dotfiles/wordmark-dark.svg +1 -0
  40. package/assets/dotfiles/wordmark-light.svg +1 -0
  41. package/assets/form-builder/apple-touch-icon.png +0 -0
  42. package/assets/form-builder/favicon-16.png +0 -0
  43. package/assets/form-builder/favicon-32.png +0 -0
  44. package/assets/form-builder/favicon.ico +0 -0
  45. package/assets/form-builder/favicon.svg +1 -0
  46. package/assets/form-builder/icon-192.png +0 -0
  47. package/assets/form-builder/icon-512.png +0 -0
  48. package/assets/form-builder/lockup-dark.svg +1 -0
  49. package/assets/form-builder/lockup-light.svg +1 -0
  50. package/assets/form-builder/mark-mono.svg +1 -0
  51. package/assets/form-builder/mark-on-dark.svg +1 -0
  52. package/assets/form-builder/mark-on-light.svg +1 -0
  53. package/assets/form-builder/mark.svg +1 -0
  54. package/assets/form-builder/readme-header.png +0 -0
  55. package/assets/form-builder/readme-header.svg +1 -0
  56. package/assets/form-builder/social-card.png +0 -0
  57. package/assets/form-builder/social-card.svg +1 -0
  58. package/assets/form-builder/wordmark-dark.svg +1 -0
  59. package/assets/form-builder/wordmark-light.svg +1 -0
  60. package/assets/manifest.json +541 -0
  61. package/assets/whatsaaaa/apple-touch-icon.png +0 -0
  62. package/assets/whatsaaaa/favicon-16.png +0 -0
  63. package/assets/whatsaaaa/favicon-32.png +0 -0
  64. package/assets/whatsaaaa/favicon.ico +0 -0
  65. package/assets/whatsaaaa/favicon.svg +1 -0
  66. package/assets/whatsaaaa/icon-192.png +0 -0
  67. package/assets/whatsaaaa/icon-512.png +0 -0
  68. package/assets/whatsaaaa/lockup-dark.svg +1 -0
  69. package/assets/whatsaaaa/lockup-light.svg +1 -0
  70. package/assets/whatsaaaa/mark-mono.svg +1 -0
  71. package/assets/whatsaaaa/mark-on-dark.svg +1 -0
  72. package/assets/whatsaaaa/mark-on-light.svg +1 -0
  73. package/assets/whatsaaaa/mark.svg +1 -0
  74. package/assets/whatsaaaa/pose-blink-dark.svg +1 -0
  75. package/assets/whatsaaaa/pose-blink-light.svg +1 -0
  76. package/assets/whatsaaaa/pose-idle-dark.svg +1 -0
  77. package/assets/whatsaaaa/pose-idle-light.svg +1 -0
  78. package/assets/whatsaaaa/pose-lost-dark.svg +1 -0
  79. package/assets/whatsaaaa/pose-lost-light.svg +1 -0
  80. package/assets/whatsaaaa/pose-shout-dark.svg +1 -0
  81. package/assets/whatsaaaa/pose-shout-light.svg +1 -0
  82. package/assets/whatsaaaa/pose-wag-left-dark.svg +1 -0
  83. package/assets/whatsaaaa/pose-wag-left-light.svg +1 -0
  84. package/assets/whatsaaaa/pose-wag-right-dark.svg +1 -0
  85. package/assets/whatsaaaa/pose-wag-right-light.svg +1 -0
  86. package/assets/whatsaaaa/readme-header.png +0 -0
  87. package/assets/whatsaaaa/readme-header.svg +1 -0
  88. package/assets/whatsaaaa/social-card.png +0 -0
  89. package/assets/whatsaaaa/social-card.svg +1 -0
  90. package/assets/whatsaaaa/wordmark-dark.svg +1 -0
  91. package/assets/whatsaaaa/wordmark-light.svg +1 -0
  92. package/dist/color.d.ts +5 -0
  93. package/dist/color.js +7 -0
  94. package/dist/css/base.css +50 -0
  95. package/dist/css/callout.css +64 -0
  96. package/dist/css/code.css +50 -0
  97. package/dist/css/ghost.css +93 -0
  98. package/dist/css/icons.css +8 -0
  99. package/dist/css/prose.css +320 -0
  100. package/dist/css/terminal.css +424 -0
  101. package/dist/fonts/inter-latin-ext-wght-italic.woff2 +0 -0
  102. package/dist/fonts/inter-latin-ext-wght-normal.woff2 +0 -0
  103. package/dist/fonts/inter-latin-wght-italic.woff2 +0 -0
  104. package/dist/fonts/inter-latin-wght-normal.woff2 +0 -0
  105. package/dist/fonts/inter.OFL.txt +93 -0
  106. package/dist/fonts/jetbrains-mono-latin-ext-wght-italic.woff2 +0 -0
  107. package/dist/fonts/jetbrains-mono-latin-ext-wght-normal.woff2 +0 -0
  108. package/dist/fonts/jetbrains-mono-latin-wght-italic.woff2 +0 -0
  109. package/dist/fonts/jetbrains-mono-latin-wght-normal.woff2 +0 -0
  110. package/dist/fonts/jetbrains-mono.OFL.txt +93 -0
  111. package/dist/fonts.css +85 -0
  112. package/dist/ghost/bubble.d.ts +16 -0
  113. package/dist/ghost/bubble.js +50 -0
  114. package/dist/ghost/glyphs.d.ts +12 -0
  115. package/dist/ghost/glyphs.js +19 -0
  116. package/dist/ghost/index.d.ts +57 -0
  117. package/dist/ghost/index.js +227 -0
  118. package/dist/identity/ghost.d.ts +28 -0
  119. package/dist/identity/ghost.js +129 -0
  120. package/dist/identity/marks.d.ts +48 -0
  121. package/dist/identity/marks.js +52 -0
  122. package/dist/identity/sprite.d.ts +43 -0
  123. package/dist/identity/sprite.js +100 -0
  124. package/dist/index.css +1404 -0
  125. package/dist/shiki/index.d.ts +20 -0
  126. package/dist/shiki/index.js +64 -0
  127. package/dist/shortcuts/index.d.ts +62 -0
  128. package/dist/shortcuts/index.js +169 -0
  129. package/dist/shortcuts/init.js +2 -0
  130. package/dist/theme/index.d.ts +24 -0
  131. package/dist/theme/index.js +60 -0
  132. package/dist/theme/init.js +2 -0
  133. package/dist/tokens.css +537 -0
  134. package/dist/tokens.d.ts +194 -0
  135. package/dist/tokens.js +336 -0
  136. package/dist/vitepress-config/index.d.ts +16 -0
  137. package/dist/vitepress-config/index.js +36 -0
  138. package/dist/vitepress-config/markdown.d.ts +6 -0
  139. package/dist/vitepress-config/markdown.js +50 -0
  140. package/dist/vitepress-config/types.d.ts +16 -0
  141. package/dist/vitepress-config/types.js +1 -0
  142. package/docs/usage.md +226 -0
  143. package/licenses/README.md +10 -0
  144. package/licenses/departure-mono.OFL.txt +93 -0
  145. package/licenses/rose-pine-palette.LICENSE +21 -0
  146. package/package.json +162 -3
  147. package/src/vitepress/Layout.vue +77 -0
  148. package/src/vitepress/components/Crumb.vue +32 -0
  149. package/src/vitepress/components/NavGhost.vue +23 -0
  150. package/src/vitepress/components/NotFound.vue +22 -0
  151. package/src/vitepress/components/StatusLine.vue +128 -0
  152. package/src/vitepress/env.d.ts +2 -0
  153. package/src/vitepress/index.ts +34 -0
  154. package/src/vitepress/path.ts +19 -0
  155. package/src/vitepress/styles/doc.css +385 -0
  156. package/src/vitepress/styles/home.css +47 -0
  157. package/src/vitepress/styles/layout.css +97 -0
  158. package/src/vitepress/styles/nav.css +441 -0
  159. package/src/vitepress/styles/search.css +55 -0
  160. package/src/vitepress/styles/sidebar.css +173 -0
  161. package/src/vitepress/styles/vars.css +204 -0
  162. package/src/vitepress/support.ts +15 -0
  163. package/src/vitepress/theme.d.ts +8 -0
  164. package/tokens/contrast.json +271 -0
  165. package/tokens/core.tokens.json +743 -0
  166. package/tokens/palette.tokens.json +222 -0
  167. package/tokens/theme-dark.tokens.json +146 -0
  168. package/tokens/theme-light.tokens.json +146 -0
  169. 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,62 @@
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:
5
+ *
6
+ * <button type="button" data-ws-key="t"><kbd class="ws-kbd">t</kbd>theme</button>
7
+ *
8
+ * Pressing t clicks that button, so the hint and the action are one element. The styles
9
+ * keep key hints hidden until `enableShortcuts()` has run, so a page never shows a hint
10
+ * 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.
12
+ *
13
+ * The number keys go to the tabs of a tab bar, which numbers them.
14
+ *
15
+ * The keys are single characters that act on the whole page, so the page carries a switch
16
+ * for them, declared the same way:
17
+ *
18
+ * <button type="button" class="ws-status-line__switch" role="switch"
19
+ * aria-label="Shortcut keys" data-ws-keys-switch>
20
+ * keys
21
+ * <span class="ws-status-line__on" aria-hidden="true">on</span>
22
+ * <span class="ws-status-line__off" aria-hidden="true">off</span>
23
+ * </button>
24
+ *
25
+ * Pressing it turns every key off or on again, and the browser remembers the choice. With
26
+ * the keys off the controls stay and work by hand. Only what names a key goes: the key caps
27
+ * and the numbers of the tabs. The state of the switch, `aria-checked`, is set here: the
28
+ * styles keep the switch hidden until it has one, so it never shows a state that is not the
29
+ * real one. A key acts only on a page that has that switch: a page without it has no
30
+ * shortcuts.
31
+ *
32
+ * A held key acts once. The repeats a keyboard sends while a key is down do nothing, so a
33
+ * finger that rests on t does not flash the page between its themes.
34
+ */
35
+ export interface ShortcutOptions {
36
+ /** A selector for the tabs the number keys go to, in their order. */
37
+ tabs?: string;
38
+ }
39
+ /** Where the choice is kept in localStorage. Nothing is stored while the keys are on. */
40
+ export declare const KEYS_STORAGE_KEY = "ws-keys";
41
+ /** Whether keys pressed on this element are typed into a field. Shortcuts leave those alone. */
42
+ export declare function isTyping(element: Element | null): boolean;
43
+ /** Whether single keys are shortcuts on this page right now: turned on, and not switched off. */
44
+ export declare function shortcutsOn(): boolean;
45
+ /**
46
+ * Turns the shortcuts on, unless the visitor has switched them off, and wires the switch.
47
+ * Returns a function that takes all of it away again. Call it once the status line is in
48
+ * the page.
49
+ *
50
+ * A key works only while the control that shows its hint is rendered and the page has the
51
+ * switch, and a held key works once. Keys typed into a field, and keys pressed with Ctrl,
52
+ * Alt or Cmd, are left alone.
53
+ */
54
+ export declare function enableShortcuts({ tabs }?: ShortcutOptions): () => void;
55
+ /**
56
+ * A script for the <head> that marks the page before the first paint when the keys are
57
+ * remembered as off. The styles then leave out what names a key, the numbers of the tabs
58
+ * among it, from the start instead of taking it away once `enableShortcuts()` runs.
59
+ *
60
+ * <script>{keysInitScript}</script>
61
+ */
62
+ export declare const keysInitScript: string;
@@ -0,0 +1,169 @@
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:
5
+ *
6
+ * <button type="button" data-ws-key="t"><kbd class="ws-kbd">t</kbd>theme</button>
7
+ *
8
+ * Pressing t clicks that button, so the hint and the action are one element. The styles
9
+ * keep key hints hidden until `enableShortcuts()` has run, so a page never shows a hint
10
+ * 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.
12
+ *
13
+ * The number keys go to the tabs of a tab bar, which numbers them.
14
+ *
15
+ * The keys are single characters that act on the whole page, so the page carries a switch
16
+ * for them, declared the same way:
17
+ *
18
+ * <button type="button" class="ws-status-line__switch" role="switch"
19
+ * aria-label="Shortcut keys" data-ws-keys-switch>
20
+ * keys
21
+ * <span class="ws-status-line__on" aria-hidden="true">on</span>
22
+ * <span class="ws-status-line__off" aria-hidden="true">off</span>
23
+ * </button>
24
+ *
25
+ * Pressing it turns every key off or on again, and the browser remembers the choice. With
26
+ * the keys off the controls stay and work by hand. Only what names a key goes: the key caps
27
+ * and the numbers of the tabs. The state of the switch, `aria-checked`, is set here: the
28
+ * styles keep the switch hidden until it has one, so it never shows a state that is not the
29
+ * real one. A key acts only on a page that has that switch: a page without it has no
30
+ * shortcuts.
31
+ *
32
+ * A held key acts once. The repeats a keyboard sends while a key is down do nothing, so a
33
+ * finger that rests on t does not flash the page between its themes.
34
+ */
35
+ /** Where the choice is kept in localStorage. Nothing is stored while the keys are on. */
36
+ export const KEYS_STORAGE_KEY = 'ws-keys';
37
+ const EDITABLE = 'input, textarea, select, [contenteditable=""], [contenteditable="true"]';
38
+ const DECLARED = '[data-ws-key]';
39
+ const SWITCH = '[data-ws-keys-switch]';
40
+ /** Whether keys pressed on this element are typed into a field. Shortcuts leave those alone. */
41
+ export function isTyping(element) {
42
+ return !!element?.closest(EDITABLE);
43
+ }
44
+ /** Whether single keys are shortcuts on this page right now: turned on, and not switched off. */
45
+ export function shortcutsOn() {
46
+ return document.documentElement.dataset.wsKeys === 'on';
47
+ }
48
+ function isVisible(element) {
49
+ // an element that is not rendered has no boxes
50
+ return element.getClientRects().length > 0;
51
+ }
52
+ function rememberedOff() {
53
+ try {
54
+ return localStorage.getItem(KEYS_STORAGE_KEY) === 'off';
55
+ }
56
+ catch {
57
+ // storage can be blocked. The keys are then on, and the switch holds for this page.
58
+ return false;
59
+ }
60
+ }
61
+ function remember(on) {
62
+ try {
63
+ if (on)
64
+ localStorage.removeItem(KEYS_STORAGE_KEY);
65
+ else
66
+ localStorage.setItem(KEYS_STORAGE_KEY, 'off');
67
+ }
68
+ catch {
69
+ // the choice still holds for this page
70
+ }
71
+ }
72
+ function targetFor(key, tabSelector) {
73
+ const declared = [...document.querySelectorAll(DECLARED)].find((element) => element.dataset.wsKey === key &&
74
+ isVisible(element) &&
75
+ !element.disabled &&
76
+ element.getAttribute('aria-disabled') !== 'true');
77
+ if (declared)
78
+ return declared;
79
+ if (/^[1-9]$/.test(key)) {
80
+ const tabs = [...document.querySelectorAll(tabSelector)].filter(isVisible);
81
+ return tabs[Number(key) - 1];
82
+ }
83
+ return undefined;
84
+ }
85
+ /**
86
+ * Turns the shortcuts on, unless the visitor has switched them off, and wires the switch.
87
+ * Returns a function that takes all of it away again. Call it once the status line is in
88
+ * the page.
89
+ *
90
+ * A key works only while the control that shows its hint is rendered and the page has the
91
+ * switch, and a held key works once. Keys typed into a field, and keys pressed with Ctrl,
92
+ * Alt or Cmd, are left alone.
93
+ */
94
+ export function enableShortcuts({ tabs = '.ws-tabs a' } = {}) {
95
+ const root = document.documentElement;
96
+ const switches = () => [...document.querySelectorAll(SWITCH)];
97
+ let on = !rememberedOff();
98
+ /**
99
+ * Says on the page what `on` holds: the styles show the hints by it, the switch has its
100
+ * state, and a control names its key to assistive technology only while the key works.
101
+ */
102
+ const show = () => {
103
+ const controls = switches();
104
+ const live = on && controls.length > 0;
105
+ for (const control of controls)
106
+ control.setAttribute('aria-checked', String(on));
107
+ for (const control of document.querySelectorAll(DECLARED)) {
108
+ if (live)
109
+ control.setAttribute('aria-keyshortcuts', control.dataset.wsKey);
110
+ else
111
+ control.removeAttribute('aria-keyshortcuts');
112
+ }
113
+ if (controls.length > 0)
114
+ root.dataset.wsKeys = on ? 'on' : 'off';
115
+ else
116
+ delete root.dataset.wsKeys;
117
+ };
118
+ const onKeyDown = (event) => {
119
+ if (!on || event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey)
120
+ return;
121
+ if (event.target instanceof Element && isTyping(event.target))
122
+ return;
123
+ if (switches().length === 0)
124
+ return;
125
+ const target = targetFor(event.key, tabs);
126
+ if (!target)
127
+ return;
128
+ event.preventDefault();
129
+ // the repeats of a held key are the page's too, and do nothing
130
+ if (!event.repeat)
131
+ target.click();
132
+ };
133
+ const onClick = (event) => {
134
+ if (!(event.target instanceof Element) || !event.target.closest(SWITCH))
135
+ return;
136
+ on = !on;
137
+ remember(on);
138
+ show();
139
+ };
140
+ // another tab or an embedded page of the same site flipped the switch
141
+ const onStorage = (event) => {
142
+ if (event.key !== KEYS_STORAGE_KEY && event.key !== null)
143
+ return;
144
+ on = !rememberedOff();
145
+ show();
146
+ };
147
+ document.addEventListener('keydown', onKeyDown);
148
+ document.addEventListener('click', onClick);
149
+ window.addEventListener('storage', onStorage);
150
+ show();
151
+ return () => {
152
+ document.removeEventListener('keydown', onKeyDown);
153
+ document.removeEventListener('click', onClick);
154
+ window.removeEventListener('storage', onStorage);
155
+ for (const control of switches())
156
+ control.removeAttribute('aria-checked');
157
+ for (const control of document.querySelectorAll(DECLARED))
158
+ control.removeAttribute('aria-keyshortcuts');
159
+ delete root.dataset.wsKeys;
160
+ };
161
+ }
162
+ /**
163
+ * A script for the <head> that marks the page before the first paint when the keys are
164
+ * remembered as off. The styles then leave out what names a key, the numbers of the tabs
165
+ * among it, from the start instead of taking it away once `enableShortcuts()` runs.
166
+ *
167
+ * <script>{keysInitScript}</script>
168
+ */
169
+ 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){}})()