@metacensus/library-ui 0.15.0 → 0.17.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 +110 -16
- package/TRADEMARKS.md +4 -4
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/marks/Marks.d.ts +2 -5
- package/dist/marks/Marks.js +33 -8
- package/dist/marks/Marks.js.map +1 -1
- package/dist/organization/facts.d.ts +15 -0
- package/dist/organization/facts.js +21 -0
- package/dist/organization/facts.js.map +1 -0
- package/dist/organization/index.d.ts +3 -0
- package/dist/organization/index.js +4 -0
- package/dist/organization/index.js.map +1 -0
- package/dist/organization/serialize.d.ts +12 -0
- package/dist/organization/serialize.js +47 -0
- package/dist/organization/serialize.js.map +1 -0
- package/dist/organization/stewards.d.ts +16 -0
- package/dist/organization/stewards.js +111 -0
- package/dist/organization/stewards.js.map +1 -0
- package/dist/site/links.d.ts +14 -0
- package/dist/site/links.js +44 -0
- package/dist/site/links.js.map +1 -0
- package/dist/tools/CiteThisPage.d.ts +14 -0
- package/dist/tools/CiteThisPage.js +13 -0
- package/dist/tools/CiteThisPage.js.map +1 -0
- package/dist/tools/cite.d.ts +18 -0
- package/dist/tools/cite.js +73 -0
- package/dist/tools/cite.js.map +1 -0
- package/dist/tools/display.d.ts +28 -0
- package/dist/tools/display.js +101 -0
- package/dist/tools/display.js.map +1 -0
- package/marks/wordmark-lockup.svg +1 -7
- package/package.json +18 -1
- package/src/chrome/Footer.astro +25 -0
- package/src/chrome/Header.astro +40 -0
- package/src/css/styles.css +158 -32
- package/src/css/tokens.css +0 -8
- package/src/inventory/routes.mjs +122 -0
- package/src/organization/OrganizationJsonLd.astro +5 -0
- package/dist/tools/theme.d.ts +0 -18
- package/dist/tools/theme.js +0 -68
- package/dist/tools/theme.js.map +0 -1
package/src/css/styles.css
CHANGED
|
@@ -17,7 +17,42 @@
|
|
|
17
17
|
width: auto;
|
|
18
18
|
}
|
|
19
19
|
.mc-fill-auto {
|
|
20
|
-
fill:
|
|
20
|
+
fill: var(--mc-purple-bold);
|
|
21
|
+
overflow: visible;
|
|
22
|
+
}
|
|
23
|
+
/* The halo under an `auto` mark, rendered only on a dark ground: the OS
|
|
24
|
+
setting, or the nearest `.dark` or `.light` ancestor, as tokens.css
|
|
25
|
+
resolves the scheme. */
|
|
26
|
+
.mc-halo-flood {
|
|
27
|
+
flood-color: var(--mc-purple-tint);
|
|
28
|
+
}
|
|
29
|
+
.mc-halo {
|
|
30
|
+
display: none;
|
|
31
|
+
}
|
|
32
|
+
@media (prefers-color-scheme: dark) {
|
|
33
|
+
.mc-halo {
|
|
34
|
+
display: inline;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
@scope (.dark) {
|
|
38
|
+
.mc-halo {
|
|
39
|
+
display: inline;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
@scope (.light) {
|
|
43
|
+
.mc-halo {
|
|
44
|
+
display: none;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
.mc-halo-still {
|
|
48
|
+
display: none;
|
|
49
|
+
}
|
|
50
|
+
/* `.still`: animations stopped, as displayScript sets it. */
|
|
51
|
+
:root.still .mc-halo-moving {
|
|
52
|
+
display: none;
|
|
53
|
+
}
|
|
54
|
+
:root.still .mc-halo-still {
|
|
55
|
+
display: inline;
|
|
21
56
|
}
|
|
22
57
|
.mc-fill-solid {
|
|
23
58
|
fill: var(--mc-purple-bold);
|
|
@@ -64,6 +99,52 @@
|
|
|
64
99
|
gap: 0.75rem;
|
|
65
100
|
}
|
|
66
101
|
|
|
102
|
+
.mc-main-bar {
|
|
103
|
+
z-index: 40;
|
|
104
|
+
flex-wrap: nowrap;
|
|
105
|
+
gap: 1rem;
|
|
106
|
+
}
|
|
107
|
+
.mc-main-bar .mc-nav {
|
|
108
|
+
margin-inline: auto;
|
|
109
|
+
}
|
|
110
|
+
.mc-main-bar .mc-header-home {
|
|
111
|
+
margin-inline-end: 0;
|
|
112
|
+
}
|
|
113
|
+
@media (width < 48rem) {
|
|
114
|
+
.mc-main-bar {
|
|
115
|
+
padding-block: 0.5rem;
|
|
116
|
+
}
|
|
117
|
+
.mc-main-bar .mc-header-home {
|
|
118
|
+
flex: none;
|
|
119
|
+
width: calc(1.5rem * 27 / 23);
|
|
120
|
+
overflow: hidden;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* The page's section bar: scrolls with the page until it reaches the viewport's top. */
|
|
125
|
+
.mc-section-bar {
|
|
126
|
+
position: sticky;
|
|
127
|
+
top: 0;
|
|
128
|
+
z-index: 30;
|
|
129
|
+
display: flex;
|
|
130
|
+
justify-content: safe center;
|
|
131
|
+
gap: clamp(0.75rem, 3vw, 1.5rem);
|
|
132
|
+
padding: 0.625rem 1rem;
|
|
133
|
+
background: var(--mc-ground);
|
|
134
|
+
border-bottom: 1px solid var(--mc-hairline);
|
|
135
|
+
font-size: 0.875rem;
|
|
136
|
+
font-weight: 500;
|
|
137
|
+
white-space: nowrap;
|
|
138
|
+
overflow-x: auto;
|
|
139
|
+
}
|
|
140
|
+
.mc-section-bar a {
|
|
141
|
+
color: var(--mc-ink);
|
|
142
|
+
text-decoration: none;
|
|
143
|
+
}
|
|
144
|
+
.mc-section-bar a:hover {
|
|
145
|
+
color: var(--mc-ink-accent);
|
|
146
|
+
}
|
|
147
|
+
|
|
67
148
|
/* Nav: a checkbox opens the list on a narrow screen, with no JS. */
|
|
68
149
|
.mc-nav {
|
|
69
150
|
position: relative;
|
|
@@ -151,6 +232,14 @@
|
|
|
151
232
|
flex-wrap: wrap;
|
|
152
233
|
gap: 2rem;
|
|
153
234
|
}
|
|
235
|
+
.mc-footer-column {
|
|
236
|
+
display: flex;
|
|
237
|
+
flex-direction: column;
|
|
238
|
+
gap: 0.75rem;
|
|
239
|
+
}
|
|
240
|
+
.mc-footer a {
|
|
241
|
+
color: var(--mc-ink);
|
|
242
|
+
}
|
|
154
243
|
|
|
155
244
|
/* Button. */
|
|
156
245
|
.mc-button {
|
|
@@ -271,6 +360,33 @@
|
|
|
271
360
|
color: var(--mc-tint-blue-ink);
|
|
272
361
|
}
|
|
273
362
|
|
|
363
|
+
/* CiteThisPage: a disclosure on the card role. */
|
|
364
|
+
.mc-cite {
|
|
365
|
+
padding: 0.75rem 1rem;
|
|
366
|
+
border: 1px solid var(--mc-hairline);
|
|
367
|
+
border-radius: var(--mc-radius);
|
|
368
|
+
background: var(--mc-card);
|
|
369
|
+
color: var(--mc-ink);
|
|
370
|
+
}
|
|
371
|
+
.mc-cite-summary {
|
|
372
|
+
cursor: pointer;
|
|
373
|
+
font-weight: 500;
|
|
374
|
+
}
|
|
375
|
+
.mc-cite-summary:focus-visible {
|
|
376
|
+
outline: 2px solid var(--mc-line-accent);
|
|
377
|
+
outline-offset: 2px;
|
|
378
|
+
}
|
|
379
|
+
.mc-cite-text {
|
|
380
|
+
margin: 0.75rem 0;
|
|
381
|
+
overflow-wrap: anywhere;
|
|
382
|
+
}
|
|
383
|
+
.mc-cite-downloads {
|
|
384
|
+
display: flex;
|
|
385
|
+
flex-wrap: wrap;
|
|
386
|
+
gap: 0.5rem;
|
|
387
|
+
margin: 0;
|
|
388
|
+
}
|
|
389
|
+
|
|
274
390
|
/* Form kit. */
|
|
275
391
|
.mc-field {
|
|
276
392
|
display: flex;
|
|
@@ -321,56 +437,66 @@
|
|
|
321
437
|
font-size: 0.875rem;
|
|
322
438
|
}
|
|
323
439
|
|
|
324
|
-
/*
|
|
325
|
-
|
|
326
|
-
.mc-
|
|
440
|
+
/* Display controls: a round icon button fixed at the viewport's bottom-left
|
|
441
|
+
corner, with a panel above it. */
|
|
442
|
+
.mc-display {
|
|
327
443
|
position: fixed;
|
|
328
444
|
inset-block-end: 1rem;
|
|
329
|
-
inset-inline-
|
|
445
|
+
inset-inline-start: 1rem;
|
|
330
446
|
z-index: 40;
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
447
|
+
}
|
|
448
|
+
.mc-display-button {
|
|
449
|
+
display: grid;
|
|
450
|
+
place-items: center;
|
|
451
|
+
width: 2.75rem;
|
|
334
452
|
height: 2.75rem;
|
|
335
|
-
padding: 0
|
|
453
|
+
padding: 0;
|
|
336
454
|
border: 1px solid var(--mc-hairline);
|
|
337
455
|
border-radius: 999px;
|
|
338
456
|
background: var(--mc-card);
|
|
339
457
|
color: var(--mc-ink);
|
|
340
458
|
box-shadow: 0 2px 8px color-mix(in srgb, var(--mc-ink) 20%, transparent);
|
|
341
|
-
font: inherit;
|
|
342
|
-
font-weight: 500;
|
|
343
|
-
white-space: nowrap;
|
|
344
459
|
cursor: pointer;
|
|
345
460
|
}
|
|
346
|
-
.mc-
|
|
347
|
-
flex: none;
|
|
461
|
+
.mc-display-button svg {
|
|
348
462
|
width: 1.25rem;
|
|
349
463
|
height: 1.25rem;
|
|
350
464
|
}
|
|
351
|
-
.mc-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
465
|
+
.mc-display-panel {
|
|
466
|
+
position: absolute;
|
|
467
|
+
inset-block-end: calc(100% + 0.5rem);
|
|
468
|
+
inset-inline-start: 0;
|
|
469
|
+
box-sizing: border-box;
|
|
470
|
+
width: 14rem;
|
|
471
|
+
max-width: calc(100vw - 2rem);
|
|
472
|
+
display: flex;
|
|
473
|
+
flex-direction: column;
|
|
474
|
+
gap: 0.75rem;
|
|
475
|
+
padding: 0.75rem 1rem;
|
|
476
|
+
border: 1px solid var(--mc-hairline);
|
|
477
|
+
border-radius: var(--mc-radius);
|
|
478
|
+
background: var(--mc-card);
|
|
479
|
+
color: var(--mc-ink);
|
|
480
|
+
box-shadow: 0 2px 8px color-mix(in srgb, var(--mc-ink) 20%, transparent);
|
|
481
|
+
}
|
|
482
|
+
/* Bridges the gap to the button so the pointer crosses it without leaving. */
|
|
483
|
+
.mc-display-panel::before {
|
|
484
|
+
content: '';
|
|
485
|
+
position: absolute;
|
|
486
|
+
inset-inline: 0;
|
|
487
|
+
inset-block-start: 100%;
|
|
488
|
+
height: 0.5rem;
|
|
357
489
|
}
|
|
358
|
-
.mc-
|
|
359
|
-
|
|
360
|
-
max-width: 4rem;
|
|
361
|
-
margin-inline: 0.5rem 0.25rem;
|
|
490
|
+
.mc-display-panel[hidden] {
|
|
491
|
+
display: none;
|
|
362
492
|
}
|
|
363
|
-
.mc-
|
|
493
|
+
.mc-display-button:focus-visible,
|
|
494
|
+
.mc-display-panel input:focus-visible {
|
|
364
495
|
outline: 2px solid var(--mc-ink-accent);
|
|
365
496
|
outline-offset: 2px;
|
|
366
497
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
transition: none;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
/* The footer's last line stays clear of the toggle at the page's end. */
|
|
373
|
-
:root:has(.mc-theme-toggle) .mc-footer {
|
|
498
|
+
/* The footer's last line stays clear of the button at the page's end. */
|
|
499
|
+
:root:has(.mc-display) .mc-footer {
|
|
374
500
|
padding-block-end: 5rem;
|
|
375
501
|
}
|
|
376
502
|
|
package/src/css/tokens.css
CHANGED
|
@@ -83,14 +83,6 @@
|
|
|
83
83
|
);
|
|
84
84
|
--mc-tint-blue-ink: light-dark(var(--mc-blue-bold), var(--mc-blue-mid));
|
|
85
85
|
|
|
86
|
-
/* Gradients: two stops, never a third. */
|
|
87
|
-
--mc-gradient-hero: linear-gradient(
|
|
88
|
-
to right,
|
|
89
|
-
var(--mc-purple-bold),
|
|
90
|
-
var(--mc-purple-mid)
|
|
91
|
-
);
|
|
92
|
-
--mc-gradient-lockup: linear-gradient(to right, #37128a, #ab82ec);
|
|
93
|
-
|
|
94
86
|
/* Type: the face only, no scale. */
|
|
95
87
|
--mc-font-sans:
|
|
96
88
|
'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto,
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Writes ROUTES.md from the build: every page Astro emits, its audience and
|
|
2
|
+
// purpose from a JSON file of entries, and the links and forms in its built
|
|
3
|
+
// HTML. The build fails when a route has no entry, an entry has no route, or a
|
|
4
|
+
// page links where `deniedLinks` denies.
|
|
5
|
+
import { readFile, writeFile } from 'node:fs/promises'
|
|
6
|
+
import { URL, fileURLToPath } from 'node:url'
|
|
7
|
+
|
|
8
|
+
const ENTRIES = 'src/inventory/routes.json'
|
|
9
|
+
const OUTPUT = 'ROUTES.md'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {object} [options]
|
|
13
|
+
* @param {(hrefs: string[]) => string[]} [options.deniedLinks] The hrefs a page may not link to.
|
|
14
|
+
* @returns {import("astro").AstroIntegration}
|
|
15
|
+
*/
|
|
16
|
+
export default function routeInventory({ deniedLinks = () => [] } = {}) {
|
|
17
|
+
let base = '/'
|
|
18
|
+
let root = new URL('file:///')
|
|
19
|
+
return {
|
|
20
|
+
name: 'route-inventory',
|
|
21
|
+
hooks: {
|
|
22
|
+
'astro:config:done': ({ config }) => {
|
|
23
|
+
base = config.base.replace(/\/?$/, '/')
|
|
24
|
+
root = config.root
|
|
25
|
+
},
|
|
26
|
+
'astro:build:done': async ({ dir, assets }) => {
|
|
27
|
+
/** @type {Record<string, { audience: string, purpose: string }>} */
|
|
28
|
+
const entries = JSON.parse(
|
|
29
|
+
await readFile(new URL(ENTRIES, root), 'utf8'),
|
|
30
|
+
)
|
|
31
|
+
const patterns = [...assets.keys()].sort()
|
|
32
|
+
const missing = patterns.filter((p) => !entries[p])
|
|
33
|
+
const stale = Object.keys(entries).filter((p) => !assets.has(p))
|
|
34
|
+
if (missing.length || stale.length) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`${ENTRIES} must name every route once: ` +
|
|
37
|
+
`missing ${missing.join(', ') || 'none'}; ` +
|
|
38
|
+
`no such route ${stale.join(', ') || 'none'}`,
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const dirPath = fileURLToPath(dir)
|
|
43
|
+
const sections = []
|
|
44
|
+
const denied = []
|
|
45
|
+
for (const pattern of patterns) {
|
|
46
|
+
const { audience, purpose } = entries[pattern]
|
|
47
|
+
const lines = [
|
|
48
|
+
`## \`${pattern}\``,
|
|
49
|
+
'',
|
|
50
|
+
`- Audience: ${audience}`,
|
|
51
|
+
`- Purpose: ${purpose}`,
|
|
52
|
+
]
|
|
53
|
+
for (const file of [...(assets.get(pattern) ?? [])].sort((a, b) =>
|
|
54
|
+
a.href.localeCompare(b.href),
|
|
55
|
+
)) {
|
|
56
|
+
const path = fileURLToPath(file)
|
|
57
|
+
.slice(dirPath.length)
|
|
58
|
+
.replace(/(^|\/)index\.html$/, '$1')
|
|
59
|
+
const html = await readFile(file, 'utf8')
|
|
60
|
+
const links = linksIn(html)
|
|
61
|
+
for (const href of deniedLinks(links)) {
|
|
62
|
+
denied.push(`${base}${path} links ${href}`)
|
|
63
|
+
}
|
|
64
|
+
lines.push(
|
|
65
|
+
`- \`${base}${path}\``,
|
|
66
|
+
` - Links: ${list(links)}`,
|
|
67
|
+
` - Forms: ${list(formsIn(html))}`,
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
sections.push(lines.join('\n'))
|
|
71
|
+
}
|
|
72
|
+
if (denied.length) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`A page links where deniedLinks denies: ${denied.join('; ')}`,
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
await writeFile(
|
|
78
|
+
new URL(OUTPUT, root),
|
|
79
|
+
`# Routes\n\nGenerated by the build from the built pages and ${ENTRIES}. Edit the entries, not this file.\n\n${sections.join('\n\n')}\n`,
|
|
80
|
+
)
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** @param {string[]} items */
|
|
87
|
+
const list = (items) =>
|
|
88
|
+
items.length ? items.map((i) => `\`${i}\``).join(', ') : 'none'
|
|
89
|
+
|
|
90
|
+
/** @param {string} value */
|
|
91
|
+
const decode = (value) => value.replaceAll('&', '&')
|
|
92
|
+
|
|
93
|
+
/** Every distinct `<a href>`, sorted. @param {string} html */
|
|
94
|
+
const linksIn = (html) =>
|
|
95
|
+
[
|
|
96
|
+
...new Set(
|
|
97
|
+
[...html.matchAll(/<a\b[^>]*?\shref="([^"]*)"/g)].map((m) =>
|
|
98
|
+
decode(m[1]),
|
|
99
|
+
),
|
|
100
|
+
),
|
|
101
|
+
].sort()
|
|
102
|
+
|
|
103
|
+
/** Each `<form>` as its method, action and field names. @param {string} html */
|
|
104
|
+
const formsIn = (html) =>
|
|
105
|
+
[...html.matchAll(/<form\b([^>]*)>([\s\S]*?)<\/form>/g)].map(
|
|
106
|
+
([, attrs, body]) => {
|
|
107
|
+
const method = (
|
|
108
|
+
/\smethod="([^"]*)"/.exec(attrs)?.[1] ?? 'get'
|
|
109
|
+
).toUpperCase()
|
|
110
|
+
const action = /\saction="([^"]*)"/.exec(attrs)?.[1]
|
|
111
|
+
const fields = [
|
|
112
|
+
...new Set(
|
|
113
|
+
[
|
|
114
|
+
...body.matchAll(
|
|
115
|
+
/<(?:input|select|textarea)\b[^>]*?\sname="([^"]*)"/g,
|
|
116
|
+
),
|
|
117
|
+
].map((m) => m[1]),
|
|
118
|
+
),
|
|
119
|
+
]
|
|
120
|
+
return `${action ? `${method} ${decode(action)}` : 'no action'}: ${fields.join(' ')}`
|
|
121
|
+
},
|
|
122
|
+
)
|
package/dist/tools/theme.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** `system` follows the OS; `light` and `dark` are the viewer's override. */
|
|
2
|
-
export type Theme = 'system' | 'light' | 'dark';
|
|
3
|
-
/** Inline this in `<head>`, before first paint: it puts the stored override on
|
|
4
|
-
* `<html>` as the `.light` or `.dark` class that tokens.css honours. */
|
|
5
|
-
export declare const themeScript: string;
|
|
6
|
-
declare function write(theme: Theme): void;
|
|
7
|
-
/** The viewer's theme and a setter. Renders `system` on the server. */
|
|
8
|
-
export declare function useTheme(): {
|
|
9
|
-
theme: Theme;
|
|
10
|
-
setTheme: typeof write;
|
|
11
|
-
};
|
|
12
|
-
/** A round button fixed at the bottom of the viewport: the current theme's
|
|
13
|
-
* icon, its name on hover or focus, and a click to the next of system, light,
|
|
14
|
-
* dark. Render it once per page, from the layout; hydrate it alone. */
|
|
15
|
-
export declare function ThemeToggle({ className }: {
|
|
16
|
-
className?: string;
|
|
17
|
-
}): import("react").JSX.Element;
|
|
18
|
-
export {};
|
package/dist/tools/theme.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useSyncExternalStore } from 'react';
|
|
3
|
-
import { cn } from './cn.js';
|
|
4
|
-
const KEY = 'mc-theme';
|
|
5
|
-
/** Inline this in `<head>`, before first paint: it puts the stored override on
|
|
6
|
-
* `<html>` as the `.light` or `.dark` class that tokens.css honours. */
|
|
7
|
-
export const themeScript = `try{var t=localStorage.getItem(${JSON.stringify(KEY)});if(t==="light"||t==="dark")document.documentElement.classList.add(t)}catch(e){}`;
|
|
8
|
-
const listeners = new Set();
|
|
9
|
-
function subscribe(listener) {
|
|
10
|
-
listeners.add(listener);
|
|
11
|
-
return () => void listeners.delete(listener);
|
|
12
|
-
}
|
|
13
|
-
// The class on `<html>` is the truth: the head script set it from storage.
|
|
14
|
-
function read() {
|
|
15
|
-
const classes = document.documentElement.classList;
|
|
16
|
-
return classes.contains('dark')
|
|
17
|
-
? 'dark'
|
|
18
|
-
: classes.contains('light')
|
|
19
|
-
? 'light'
|
|
20
|
-
: 'system';
|
|
21
|
-
}
|
|
22
|
-
function write(theme) {
|
|
23
|
-
const root = document.documentElement;
|
|
24
|
-
root.classList.remove('light', 'dark');
|
|
25
|
-
if (theme !== 'system')
|
|
26
|
-
root.classList.add(theme);
|
|
27
|
-
try {
|
|
28
|
-
if (theme === 'system')
|
|
29
|
-
localStorage.removeItem(KEY);
|
|
30
|
-
else
|
|
31
|
-
localStorage.setItem(KEY, theme);
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
// Blocked storage: the override lasts the page.
|
|
35
|
-
}
|
|
36
|
-
listeners.forEach((listener) => listener());
|
|
37
|
-
}
|
|
38
|
-
/** The viewer's theme and a setter. Renders `system` on the server. */
|
|
39
|
-
export function useTheme() {
|
|
40
|
-
const theme = useSyncExternalStore(subscribe, read, () => 'system');
|
|
41
|
-
return { theme, setTheme: write };
|
|
42
|
-
}
|
|
43
|
-
const NEXT = {
|
|
44
|
-
system: 'light',
|
|
45
|
-
light: 'dark',
|
|
46
|
-
dark: 'system',
|
|
47
|
-
};
|
|
48
|
-
const NAMES = {
|
|
49
|
-
system: 'System',
|
|
50
|
-
light: 'Light',
|
|
51
|
-
dark: 'Dark',
|
|
52
|
-
};
|
|
53
|
-
/** Lucide's `monitor`, `sun` and `moon` on a 24-unit square, under the ISC
|
|
54
|
-
* license in LICENSES/ISC.txt. */
|
|
55
|
-
const ICONS = {
|
|
56
|
-
system: (_jsxs(_Fragment, { children: [_jsx("rect", { x: "2", y: "3", width: "20", height: "14", rx: "2" }), _jsx("path", { d: "M8 21h8M12 17v4" })] })),
|
|
57
|
-
light: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "12", cy: "12", r: "4" }), _jsx("path", { d: "M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41" })] })),
|
|
58
|
-
dark: _jsx("path", { d: "M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" }),
|
|
59
|
-
};
|
|
60
|
-
/** A round button fixed at the bottom of the viewport: the current theme's
|
|
61
|
-
* icon, its name on hover or focus, and a click to the next of system, light,
|
|
62
|
-
* dark. Render it once per page, from the layout; hydrate it alone. */
|
|
63
|
-
export function ThemeToggle({ className }) {
|
|
64
|
-
const { theme, setTheme } = useTheme();
|
|
65
|
-
const name = NAMES[theme];
|
|
66
|
-
return (_jsxs("button", { type: "button", className: cn('mc-theme-toggle', className), "aria-label": `Theme: ${name}. Switch to ${NAMES[NEXT[theme]]}`, onClick: () => setTheme(NEXT[theme]), children: [_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: ICONS[theme] }), _jsx("span", { className: "mc-theme-toggle-name", children: name })] }));
|
|
67
|
-
}
|
|
68
|
-
//# sourceMappingURL=theme.js.map
|
package/dist/tools/theme.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../../src/tools/theme.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAkB,MAAM,OAAO,CAAA;AAC5D,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAK5B,MAAM,GAAG,GAAG,UAAU,CAAA;AAEtB;yEACyE;AACzE,MAAM,CAAC,MAAM,WAAW,GAAG,kCAAkC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,mFAAmF,CAAA;AAEnK,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAA;AAEvC,SAAS,SAAS,CAAC,QAAoB;IACrC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IACvB,OAAO,GAAG,EAAE,CAAC,KAAK,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;AAC9C,CAAC;AAED,2EAA2E;AAC3E,SAAS,IAAI;IACX,MAAM,OAAO,GAAG,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAA;IAClD,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC7B,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;YACzB,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,QAAQ,CAAA;AAChB,CAAC;AAED,SAAS,KAAK,C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