@rxova/brand 0.15.1 → 1.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.
- package/MIGRATION.md +52 -0
- package/README.md +16 -72
- package/package.json +5 -22
- package/src/feed.ts +6 -38
- package/src/fonts.css +2 -34
- package/src/index.ts +2 -9
- package/src/sites.links.test.ts +7 -12
- package/src/sites.test.ts +1 -5
- package/src/sites.ts +8 -42
- package/src/tokens.css +8 -29
- package/src/astro.css +0 -90
- package/src/chrome.css +0 -59
- package/src/components/Footer.astro +0 -20
- package/src/components/Header.astro +0 -170
- package/src/components/ProjectSwitcher.astro +0 -102
- package/src/components/SiteFooter.astro +0 -190
- package/src/components/SiteShell.astro +0 -188
- package/src/components/SiteTitle.astro +0 -46
- package/src/components/SocialIcons.astro +0 -21
- package/src/components/ThemeScript.astro +0 -55
- package/src/components/ThemeSelect.astro +0 -59
- package/src/components/ThemeToggle.astro +0 -197
- package/src/env.d.ts +0 -21
- package/src/footer.css +0 -146
- package/src/starlight.css +0 -178
- package/src/starlight.ts +0 -134
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
/**
|
|
3
|
-
* Artifact document for rxova.org's non-Starlight page components.
|
|
4
|
-
*
|
|
5
|
-
* It lived in both packages as a 244-line file that differed on four lines, which
|
|
6
|
-
* is exactly how the menu came to render in a different order on each: a fix has to
|
|
7
|
-
* be made twice, and once was enough to forget.
|
|
8
|
-
*
|
|
9
|
-
* This deliberately owns no site header, footer, analytics or theme bootstrap.
|
|
10
|
-
* It gives an independently-built page component a standards-compliant document
|
|
11
|
-
* for its metadata and assets; rxova-website consumes its body and supplies the
|
|
12
|
-
* public shell at deploy time.
|
|
13
|
-
*/
|
|
14
|
-
import '../fonts.css'
|
|
15
|
-
import '../astro.css'
|
|
16
|
-
|
|
17
|
-
import { canonicalUrl, siteUrl } from '../sites.ts'
|
|
18
|
-
|
|
19
|
-
interface Props {
|
|
20
|
-
title: string
|
|
21
|
-
description: string
|
|
22
|
-
/** Canonical path, e.g. `/blog/why-rxova-has-a-blog`. Normalised below. */
|
|
23
|
-
path: string
|
|
24
|
-
ogType?: 'website' | 'article'
|
|
25
|
-
/**
|
|
26
|
-
* Absolute URL of the social card. Defaults to the umbrella card.
|
|
27
|
-
*
|
|
28
|
-
* A prop rather than something derived here, because what makes the best card
|
|
29
|
-
* differs per surface and only the caller knows: a post with a cover should
|
|
30
|
-
* share its cover, an update belongs to a project and should carry that
|
|
31
|
-
* project's card, and an index has neither.
|
|
32
|
-
*/
|
|
33
|
-
image?: string
|
|
34
|
-
/** Advertises an RSS feed for this surface, as `rel="alternate"`. */
|
|
35
|
-
feed?: { href: string; title: string }
|
|
36
|
-
/**
|
|
37
|
-
* JSON-LD for this page, emitted verbatim as `application/ld+json`.
|
|
38
|
-
*
|
|
39
|
-
* Structured data is the only way a crawler learns that /blog carries articles
|
|
40
|
-
* with an author and a date rather than prose it has to infer that from. Typed
|
|
41
|
-
* as unknown because the shapes differ per surface and schema.org is not worth
|
|
42
|
-
* modelling in TypeScript for three call sites.
|
|
43
|
-
*/
|
|
44
|
-
jsonLd?: unknown
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const { title, description, path, ogType = 'website', image, feed, jsonLd } = Astro.props
|
|
48
|
-
|
|
49
|
-
// Normalised here rather than at the four call sites: every one of them had
|
|
50
|
-
// dropped the trailing slash, so every blog and updates page was declaring itself
|
|
51
|
-
// canonical at a URL that 301s. A caller can forget again; this cannot.
|
|
52
|
-
const canonical = canonicalUrl(path)
|
|
53
|
-
|
|
54
|
-
const ogImage = image ?? siteUrl('/og/rxova.png')
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Serialise JSON-LD for an inline `<script>`.
|
|
58
|
-
*
|
|
59
|
-
* `<` is escaped because a `</script>` anywhere inside a string value — a post
|
|
60
|
-
* title about a tag, a description quoting markup — closes the element early and
|
|
61
|
-
* spills the rest of the payload into the document as text. `<` is valid
|
|
62
|
-
* JSON and parses back to `<`, so the structured data is unchanged.
|
|
63
|
-
*/
|
|
64
|
-
const serialiseJsonLd = (value: unknown): string => JSON.stringify(value).replace(/</g, '\\u003c')
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
<!doctype html>
|
|
68
|
-
<html lang="en">
|
|
69
|
-
<head>
|
|
70
|
-
<meta charset="utf-8" />
|
|
71
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
72
|
-
<link rel="canonical" href={canonical} />
|
|
73
|
-
<title>{title}</title>
|
|
74
|
-
<meta name="description" content={description} />
|
|
75
|
-
<meta property="og:title" content={title} />
|
|
76
|
-
<meta property="og:description" content={description} />
|
|
77
|
-
<meta property="og:type" content={ogType} />
|
|
78
|
-
<meta property="og:url" content={canonical} />
|
|
79
|
-
<meta property="og:image" content={ogImage} />
|
|
80
|
-
<meta name="twitter:card" content="summary_large_image" />
|
|
81
|
-
{feed && (
|
|
82
|
-
<link rel="alternate" type="application/rss+xml" title={feed.title} href={feed.href} />
|
|
83
|
-
)}
|
|
84
|
-
{jsonLd && (
|
|
85
|
-
<script type="application/ld+json" is:inline set:html={serialiseJsonLd(jsonLd)}></script>
|
|
86
|
-
)}
|
|
87
|
-
</head>
|
|
88
|
-
<body>
|
|
89
|
-
<main>
|
|
90
|
-
<slot />
|
|
91
|
-
</main>
|
|
92
|
-
|
|
93
|
-
<style>
|
|
94
|
-
main {
|
|
95
|
-
max-width: var(--max);
|
|
96
|
-
margin: 0 auto;
|
|
97
|
-
padding: clamp(2rem, 6vh, 3.5rem) 1.5rem 4rem;
|
|
98
|
-
}
|
|
99
|
-
</style>
|
|
100
|
-
|
|
101
|
-
<!-- Prose styling for rendered markdown. Global rather than scoped: the
|
|
102
|
-
markup comes from <Content /> at build time, so it carries none of
|
|
103
|
-
Astro's scoping attributes. Kept here so both /blog and /updates read
|
|
104
|
-
the same. -->
|
|
105
|
-
<style is:global>
|
|
106
|
-
.prose {
|
|
107
|
-
color: var(--muted);
|
|
108
|
-
line-height: 1.7;
|
|
109
|
-
}
|
|
110
|
-
.prose > * + * {
|
|
111
|
-
margin-top: 1.1rem;
|
|
112
|
-
}
|
|
113
|
-
.prose h2 {
|
|
114
|
-
color: var(--fg);
|
|
115
|
-
font-size: 1.25rem;
|
|
116
|
-
font-weight: 640;
|
|
117
|
-
letter-spacing: -0.01em;
|
|
118
|
-
margin-top: 2.5rem;
|
|
119
|
-
}
|
|
120
|
-
.prose h3 {
|
|
121
|
-
color: var(--fg);
|
|
122
|
-
font-size: 1.05rem;
|
|
123
|
-
font-weight: 620;
|
|
124
|
-
margin-top: 2rem;
|
|
125
|
-
}
|
|
126
|
-
.prose a {
|
|
127
|
-
color: var(--fg);
|
|
128
|
-
text-decoration: underline;
|
|
129
|
-
text-underline-offset: 2px;
|
|
130
|
-
}
|
|
131
|
-
.prose strong {
|
|
132
|
-
color: var(--fg);
|
|
133
|
-
font-weight: 620;
|
|
134
|
-
}
|
|
135
|
-
.prose ul,
|
|
136
|
-
.prose ol {
|
|
137
|
-
margin-left: 1.2rem;
|
|
138
|
-
}
|
|
139
|
-
.prose li + li {
|
|
140
|
-
margin-top: 0.35rem;
|
|
141
|
-
}
|
|
142
|
-
.prose code {
|
|
143
|
-
font-family: var(--mono);
|
|
144
|
-
font-size: 0.88em;
|
|
145
|
-
background: var(--tag-bg);
|
|
146
|
-
padding: 0.05rem 0.35rem;
|
|
147
|
-
border-radius: 4px;
|
|
148
|
-
}
|
|
149
|
-
.prose pre {
|
|
150
|
-
background: var(--card);
|
|
151
|
-
border: 1px solid var(--rule);
|
|
152
|
-
border-radius: 10px;
|
|
153
|
-
padding: 1rem 1.1rem;
|
|
154
|
-
/* Long lines scroll inside the block; the page itself never does. */
|
|
155
|
-
overflow-x: auto;
|
|
156
|
-
}
|
|
157
|
-
.prose pre code {
|
|
158
|
-
background: none;
|
|
159
|
-
padding: 0;
|
|
160
|
-
}
|
|
161
|
-
.prose blockquote {
|
|
162
|
-
border-left: 2px solid var(--rule);
|
|
163
|
-
padding-left: 1rem;
|
|
164
|
-
color: var(--faint);
|
|
165
|
-
}
|
|
166
|
-
.prose img {
|
|
167
|
-
max-width: 100%;
|
|
168
|
-
height: auto;
|
|
169
|
-
border-radius: 10px;
|
|
170
|
-
}
|
|
171
|
-
.prose table {
|
|
172
|
-
width: 100%;
|
|
173
|
-
border-collapse: collapse;
|
|
174
|
-
font-size: 0.95rem;
|
|
175
|
-
}
|
|
176
|
-
.prose th,
|
|
177
|
-
.prose td {
|
|
178
|
-
border-bottom: 1px solid var(--rule);
|
|
179
|
-
padding: 0.5rem 0.6rem;
|
|
180
|
-
text-align: left;
|
|
181
|
-
}
|
|
182
|
-
.prose th {
|
|
183
|
-
color: var(--fg);
|
|
184
|
-
font-weight: 620;
|
|
185
|
-
}
|
|
186
|
-
</style>
|
|
187
|
-
</body>
|
|
188
|
-
</html>
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
/**
|
|
3
|
-
* Starlight `SiteTitle` override.
|
|
4
|
-
*
|
|
5
|
-
* The mark links to rxova.org, not to the local docs home. That is deliberate:
|
|
6
|
-
* on an aggregated site the mark means "the umbrella", and the wordmark beside
|
|
7
|
-
* it says which project you are in — and links to that project's docs root.
|
|
8
|
-
*
|
|
9
|
-
* The mark's href is absolute because the four surfaces sit at four base paths.
|
|
10
|
-
* The wordmark uses Starlight's own `siteTitleHref`, which already accounts for
|
|
11
|
-
* the base and the locale.
|
|
12
|
-
*
|
|
13
|
-
* The image is imported from this package rather than read from each site's
|
|
14
|
-
* `public/`, so adopting the shared chrome does not also mean copying assets
|
|
15
|
-
* into three repos and keeping them in sync.
|
|
16
|
-
*/
|
|
17
|
-
import mark from '../../assets/rxova-logo-256.png'
|
|
18
|
-
import { RXOVA_ORIGIN } from '../sites.ts'
|
|
19
|
-
|
|
20
|
-
// Narrowed structurally rather than by declaring an `App.Locals` augmentation
|
|
21
|
-
// here: a consumer site already gets Starlight's own augmentation, and two
|
|
22
|
-
// declarations of the same property would collide at their build time.
|
|
23
|
-
const { siteTitle, siteTitleHref } = (
|
|
24
|
-
Astro.locals as unknown as {
|
|
25
|
-
starlightRoute: { siteTitle: string; siteTitleHref: string }
|
|
26
|
-
}
|
|
27
|
-
).starlightRoute
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
<div class="rx-site-title">
|
|
31
|
-
<a href={RXOVA_ORIGIN} class="rx-site-title__mark" aria-label="Rxova home">
|
|
32
|
-
<img src={mark.src} alt="" width="28" height="28" />
|
|
33
|
-
</a>
|
|
34
|
-
<span class="rx-site-title__sep" aria-hidden="true"></span>
|
|
35
|
-
<a href={siteTitleHref} class="rx-site-title__project" translate="no">
|
|
36
|
-
{siteTitle}
|
|
37
|
-
</a>
|
|
38
|
-
</div>
|
|
39
|
-
|
|
40
|
-
<style>
|
|
41
|
-
/* Visual styling lives in @rxova/brand/starlight.css so the Astro landing can
|
|
42
|
-
reuse the same classnames without importing this component. */
|
|
43
|
-
.rx-site-title__mark {
|
|
44
|
-
display: inline-flex;
|
|
45
|
-
}
|
|
46
|
-
</style>
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
/**
|
|
3
|
-
* Starlight `SocialIcons` override: the stock icons, plus the project switcher.
|
|
4
|
-
*
|
|
5
|
-
* Starlight has no dedicated slot in the header's right-hand cluster, and this
|
|
6
|
-
* is the documented place to add one — it sits immediately before search and
|
|
7
|
-
* the theme toggle on every page.
|
|
8
|
-
*/
|
|
9
|
-
import Default from '@astrojs/starlight/components/SocialIcons.astro'
|
|
10
|
-
import ProjectSwitcher from './ProjectSwitcher.astro'
|
|
11
|
-
import { projectFromBase } from '../sites.ts'
|
|
12
|
-
|
|
13
|
-
// Overrides receive no props, so the current project is inferred from the base
|
|
14
|
-
// path the aggregator mounts this site at.
|
|
15
|
-
const current = projectFromBase(import.meta.env.BASE_URL)
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
<ProjectSwitcher current={current} />
|
|
19
|
-
<Default>
|
|
20
|
-
<slot />
|
|
21
|
-
</Default>
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
/**
|
|
3
|
-
* The pre-paint theme script. Goes in `<head>`, before anything renders.
|
|
4
|
-
*
|
|
5
|
-
* This was copy-pasted between the landing page and the legal layout, and it had
|
|
6
|
-
* already drifted: the copy in Legal.astro read `theme`, a key nothing on this
|
|
7
|
-
* origin ever writes, so /privacy and /terms silently ignored the visitor's choice
|
|
8
|
-
* and always rendered the prefers-color-scheme default. Adding /blog and
|
|
9
|
-
* /changelog would have made four copies of a script whose whole job is to be
|
|
10
|
-
* identical everywhere, so it lives here now.
|
|
11
|
-
*
|
|
12
|
-
* The key is Starlight's, not ours. The docs sites at /packages/* are Starlight
|
|
13
|
-
* and write their choice to `starlight-theme`; same origin plus the same key means
|
|
14
|
-
* picking dark here keeps you in dark all the way into a project's docs, and back.
|
|
15
|
-
*
|
|
16
|
-
* No saved choice => no attribute => the CSS prefers-color-scheme default wins.
|
|
17
|
-
*
|
|
18
|
-
* Lives here because it is the one thing every rxova surface must do identically:
|
|
19
|
-
* the docs sites, the umbrella landing and /blog and /updates all read the same
|
|
20
|
-
* localStorage key, so a visitor keeps their choice walking between them. It was
|
|
21
|
-
* copied into three repos and had already drifted once — one copy read `theme`,
|
|
22
|
-
* which nothing on this origin writes, so those pages silently ignored the choice.
|
|
23
|
-
*
|
|
24
|
-
* Not the same thing as ThemeSelect.astro: that is the Starlight override for the
|
|
25
|
-
* docs sites' own toggle. This pair is for the surfaces that are not Starlight.
|
|
26
|
-
*/
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
<script is:inline>
|
|
30
|
-
;(function () {
|
|
31
|
-
function stored() {
|
|
32
|
-
try {
|
|
33
|
-
const t = localStorage.getItem('starlight-theme')
|
|
34
|
-
return t === 'light' || t === 'dark' ? t : null
|
|
35
|
-
} catch {
|
|
36
|
-
/* localStorage may be unavailable */
|
|
37
|
-
return null
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function sync() {
|
|
41
|
-
const t = stored()
|
|
42
|
-
if (t) document.documentElement.setAttribute('data-theme', t)
|
|
43
|
-
else document.documentElement.removeAttribute('data-theme')
|
|
44
|
-
}
|
|
45
|
-
sync()
|
|
46
|
-
// Going to a docs site and pressing Back restores this document from the
|
|
47
|
-
// bfcache: the DOM is reused as it was and this script does not run again, so
|
|
48
|
-
// the page would keep the theme it had when you left — even though the docs
|
|
49
|
-
// site may have written a new one to `starlight-theme` in the meantime.
|
|
50
|
-
// `pageshow` is the only notification of that restore.
|
|
51
|
-
window.addEventListener('pageshow', function (e) {
|
|
52
|
-
if (e.persisted) sync()
|
|
53
|
-
})
|
|
54
|
-
})()
|
|
55
|
-
</script>
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
/**
|
|
3
|
-
* Starlight's theme picker, plus a resync when the page comes out of the
|
|
4
|
-
* back/forward cache.
|
|
5
|
-
*
|
|
6
|
-
* Starlight applies the stored theme in two places, both of which run exactly
|
|
7
|
-
* once, while the document is being parsed: the inline script in
|
|
8
|
-
* `ThemeProvider.astro`, and the `<starlight-theme-select>` constructor. A
|
|
9
|
-
* back/forward navigation that hits the bfcache *restores* the document rather
|
|
10
|
-
* than parsing it, so neither runs again and the page keeps whatever
|
|
11
|
-
* `data-theme` it carried when the visitor left.
|
|
12
|
-
*
|
|
13
|
-
* All of rxova.org is one origin sharing one `starlight-theme` key, so that is
|
|
14
|
-
* a visible jump rather than a curiosity: pick a theme on the landing page or
|
|
15
|
-
* on another project's docs, press Back, and the restored page is still on the
|
|
16
|
-
* old one.
|
|
17
|
-
*
|
|
18
|
-
* This wraps rather than replaces Starlight's component — the picker, its
|
|
19
|
-
* labels and its own logic are untouched, and a Starlight release that changes
|
|
20
|
-
* them changes them here too.
|
|
21
|
-
*/
|
|
22
|
-
import Default from '@astrojs/starlight/components/ThemeSelect.astro'
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
<Default>
|
|
26
|
-
<slot />
|
|
27
|
-
</Default>
|
|
28
|
-
|
|
29
|
-
<script>
|
|
30
|
-
type Theme = 'auto' | 'dark' | 'light'
|
|
31
|
-
|
|
32
|
-
/** Same key and coercion Starlight uses; unknown values mean "follow the OS". */
|
|
33
|
-
const STORAGE_KEY = 'starlight-theme'
|
|
34
|
-
const parseTheme = (theme: unknown): Theme =>
|
|
35
|
-
theme === 'auto' || theme === 'dark' || theme === 'light' ? theme : 'auto'
|
|
36
|
-
const preferredColorScheme = (): Theme =>
|
|
37
|
-
matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'
|
|
38
|
-
|
|
39
|
-
// `pageshow` is the only notification of a bfcache restore. A normal load
|
|
40
|
-
// also fires it with `persisted: false`, which we ignore — Starlight has
|
|
41
|
-
// already done the work in that case.
|
|
42
|
-
window.addEventListener('pageshow', (event) => {
|
|
43
|
-
if (!event.persisted) return
|
|
44
|
-
|
|
45
|
-
let stored: string | null
|
|
46
|
-
try {
|
|
47
|
-
stored = localStorage.getItem(STORAGE_KEY)
|
|
48
|
-
} catch {
|
|
49
|
-
// Storage can throw outright (Safari private mode, blocked cookies).
|
|
50
|
-
// Leaving the restored theme alone is the right fallback.
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const theme = parseTheme(stored)
|
|
55
|
-
document.documentElement.dataset.theme = theme === 'auto' ? preferredColorScheme() : theme
|
|
56
|
-
// Keeps the picker from disagreeing with the page it controls.
|
|
57
|
-
StarlightThemeProvider.updatePickers(theme)
|
|
58
|
-
})
|
|
59
|
-
</script>
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
/**
|
|
3
|
-
* The fixed light/dark toggle in the top-right corner.
|
|
4
|
-
*
|
|
5
|
-
* Button, styles and behaviour in one place. It was inline on the landing page;
|
|
6
|
-
* /blog and /changelog want the same control, and a second copy of the icon
|
|
7
|
-
* swapping and the bfcache handling is exactly the duplication that let the
|
|
8
|
-
* pre-paint script drift (see ThemeScript.astro).
|
|
9
|
-
*
|
|
10
|
-
* Pairs with `<ThemeScript />` in `<head>`, which is what actually avoids the
|
|
11
|
-
* flash — this only handles clicks and keeps the icon honest.
|
|
12
|
-
*
|
|
13
|
-
* For the surfaces that are not Starlight — the umbrella landing, /blog, /updates.
|
|
14
|
-
* The docs sites get their toggle from Starlight, themed by ThemeSelect.astro.
|
|
15
|
-
*
|
|
16
|
-
* Pairs with ThemeScript.astro in <head>, which is what actually avoids the flash;
|
|
17
|
-
* this only handles clicks and keeps the icon honest.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
interface Props {
|
|
21
|
-
/**
|
|
22
|
-
* Pin the button to the top-right corner of the viewport.
|
|
23
|
-
*
|
|
24
|
-
* The default, because that is where it has always been and the landing lays
|
|
25
|
-
* out around it. `SiteShell` passes `false`: it puts the button in its own
|
|
26
|
-
* sticky header, and a fixed button over a fixed header is two things
|
|
27
|
-
* competing for the same corner — on a phone the floating one landed on top
|
|
28
|
-
* of the nav.
|
|
29
|
-
*/
|
|
30
|
-
floating?: boolean
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const { floating = true } = Astro.props
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
<button
|
|
37
|
-
id="theme-toggle"
|
|
38
|
-
class:list={['theme-toggle', { 'theme-toggle--floating': floating }]}
|
|
39
|
-
type="button"
|
|
40
|
-
aria-label="Toggle theme"
|
|
41
|
-
>
|
|
42
|
-
<span class="icon" aria-hidden="true">
|
|
43
|
-
<svg
|
|
44
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
45
|
-
viewBox="0 0 24 24"
|
|
46
|
-
width="24"
|
|
47
|
-
height="24"
|
|
48
|
-
fill="none"
|
|
49
|
-
stroke="currentColor"
|
|
50
|
-
stroke-width="2"
|
|
51
|
-
stroke-linecap="round"
|
|
52
|
-
stroke-linejoin="round"
|
|
53
|
-
>
|
|
54
|
-
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"></path>
|
|
55
|
-
</svg>
|
|
56
|
-
</span>
|
|
57
|
-
</button>
|
|
58
|
-
|
|
59
|
-
<style>
|
|
60
|
-
/* Quiet by default: no border, no fill, the same muted ink as the nav links
|
|
61
|
-
beside it. A bordered card-coloured box was the heaviest thing in a header
|
|
62
|
-
that is otherwise three grey words — it read as a primary control on a page
|
|
63
|
-
where changing the theme is the least important thing you can do. */
|
|
64
|
-
.theme-toggle {
|
|
65
|
-
flex: none;
|
|
66
|
-
width: 2rem;
|
|
67
|
-
height: 2rem;
|
|
68
|
-
display: grid;
|
|
69
|
-
place-items: center;
|
|
70
|
-
border: 1px solid transparent;
|
|
71
|
-
border-radius: 8px;
|
|
72
|
-
background: none;
|
|
73
|
-
color: var(--muted);
|
|
74
|
-
cursor: pointer;
|
|
75
|
-
transition:
|
|
76
|
-
color 0.15s ease,
|
|
77
|
-
border-color 0.15s ease,
|
|
78
|
-
background-color 0.2s ease;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/* Floating, it has no header to belong to and sits over arbitrary page
|
|
82
|
-
content, so it keeps the border and the fill — without them there is
|
|
83
|
-
nothing to say it is a button. */
|
|
84
|
-
.theme-toggle--floating {
|
|
85
|
-
position: fixed;
|
|
86
|
-
top: 1rem;
|
|
87
|
-
right: 1rem;
|
|
88
|
-
/* Above SiteShell's sticky header (z-index 10). Nothing pairs the two
|
|
89
|
-
today, but the whole point of a fixed button is that it stays reachable,
|
|
90
|
-
and the header would otherwise paint straight over it. */
|
|
91
|
-
z-index: 20;
|
|
92
|
-
width: 2.25rem;
|
|
93
|
-
height: 2.25rem;
|
|
94
|
-
border-color: var(--rule);
|
|
95
|
-
background: var(--card);
|
|
96
|
-
color: var(--fg);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
.theme-toggle .icon {
|
|
100
|
-
display: grid;
|
|
101
|
-
place-items: center;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/* `:global` because the icon is swapped by innerHTML in the script below, and
|
|
105
|
-
what that writes carries none of Astro's scoping attributes. Scoped, these
|
|
106
|
-
rules applied only to the SVG the server rendered — the first `render()`
|
|
107
|
-
replaced it with one at Lucide's own 24px and stroke-width 2, which is why
|
|
108
|
-
the button looked so much heavier than the nav beside it. */
|
|
109
|
-
.theme-toggle :global(svg) {
|
|
110
|
-
width: 1.05rem;
|
|
111
|
-
height: 1.05rem;
|
|
112
|
-
display: block;
|
|
113
|
-
stroke-width: 1.6;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
.theme-toggle:hover {
|
|
117
|
-
color: var(--fg);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
.theme-toggle--floating:hover {
|
|
121
|
-
border-color: var(--faint);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
.theme-toggle:focus-visible {
|
|
125
|
-
outline: 2px solid var(--accent);
|
|
126
|
-
outline-offset: 2px;
|
|
127
|
-
}
|
|
128
|
-
</style>
|
|
129
|
-
|
|
130
|
-
<script is:inline>
|
|
131
|
-
;(function () {
|
|
132
|
-
const root = document.documentElement
|
|
133
|
-
const btn = document.getElementById('theme-toggle')
|
|
134
|
-
const glyph = btn.querySelector('.icon')
|
|
135
|
-
const media = window.matchMedia('(prefers-color-scheme: dark)')
|
|
136
|
-
|
|
137
|
-
// Lucide icons (ISC licensed).
|
|
138
|
-
const ICON_MOON =
|
|
139
|
-
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/></svg>'
|
|
140
|
-
const ICON_SUN =
|
|
141
|
-
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/></svg>'
|
|
142
|
-
|
|
143
|
-
function current() {
|
|
144
|
-
return root.getAttribute('data-theme') || (media.matches ? 'dark' : 'light')
|
|
145
|
-
}
|
|
146
|
-
function stored() {
|
|
147
|
-
try {
|
|
148
|
-
const t = localStorage.getItem('starlight-theme')
|
|
149
|
-
return t === 'light' || t === 'dark' ? t : null
|
|
150
|
-
} catch {
|
|
151
|
-
/* localStorage may be unavailable */
|
|
152
|
-
return null
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
// Re-read the saved choice and reflect it in the DOM. Same job as the
|
|
156
|
-
// pre-paint script in <head>, minus the write.
|
|
157
|
-
function sync() {
|
|
158
|
-
const t = stored()
|
|
159
|
-
if (t) root.setAttribute('data-theme', t)
|
|
160
|
-
else root.removeAttribute('data-theme')
|
|
161
|
-
render()
|
|
162
|
-
}
|
|
163
|
-
function render() {
|
|
164
|
-
const dark = current() === 'dark'
|
|
165
|
-
// Show the icon of the theme you'd switch TO.
|
|
166
|
-
glyph.innerHTML = dark ? ICON_SUN : ICON_MOON
|
|
167
|
-
btn.setAttribute('aria-label', dark ? 'Switch to light theme' : 'Switch to dark theme')
|
|
168
|
-
}
|
|
169
|
-
function apply(t) {
|
|
170
|
-
root.setAttribute('data-theme', t)
|
|
171
|
-
try {
|
|
172
|
-
// Starlight's key — see the pre-paint script in <head>.
|
|
173
|
-
localStorage.setItem('starlight-theme', t)
|
|
174
|
-
} catch {
|
|
175
|
-
/* localStorage may be unavailable */
|
|
176
|
-
}
|
|
177
|
-
render()
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
btn.addEventListener('click', function () {
|
|
181
|
-
apply(current() === 'dark' ? 'light' : 'dark')
|
|
182
|
-
})
|
|
183
|
-
// Track the OS preference while the user hasn't overridden it.
|
|
184
|
-
media.addEventListener('change', function () {
|
|
185
|
-
if (!root.getAttribute('data-theme')) render()
|
|
186
|
-
})
|
|
187
|
-
// Going to a docs site and pressing Back restores this document from the
|
|
188
|
-
// bfcache: the DOM is reused as it was, so neither the pre-paint script nor
|
|
189
|
-
// this one runs again, and the page keeps the theme it had when you left —
|
|
190
|
-
// even though the docs site wrote a new one to `starlight-theme` in the
|
|
191
|
-
// meantime. `pageshow` is the only notification of that restore.
|
|
192
|
-
window.addEventListener('pageshow', function (e) {
|
|
193
|
-
if (e.persisted) sync()
|
|
194
|
-
})
|
|
195
|
-
render()
|
|
196
|
-
})()
|
|
197
|
-
</script>
|
package/src/env.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/// <reference types="astro/client" />
|
|
2
|
-
|
|
3
|
-
// Deliberately NOT referencing `@astrojs/starlight/locals` for the
|
|
4
|
-
// `Astro.locals.starlightRoute` augmentation: that declaration pulls in
|
|
5
|
-
// Starlight's own `.ts` sources, which import `virtual:starlight/*` modules
|
|
6
|
-
// that only exist inside an Astro build — so plain `tsc` fails on them.
|
|
7
|
-
// The one component that reads route data narrows it structurally instead.
|
|
8
|
-
|
|
9
|
-
// Same reasoning for this one. It mirrors Starlight's own `global.d.ts`, which
|
|
10
|
-
// we cannot `/// <reference>` because the package's types entry is `index.ts`
|
|
11
|
-
// and drags in those same virtual modules. The global is defined at runtime by
|
|
12
|
-
// the inline script in Starlight's `ThemeProvider.astro`; ThemeSelect.astro
|
|
13
|
-
// calls it. Re-check this against Starlight's `global.d.ts` on a major bump.
|
|
14
|
-
declare global {
|
|
15
|
-
interface StarlightThemeProvider {
|
|
16
|
-
updatePickers(theme?: string): void
|
|
17
|
-
}
|
|
18
|
-
var StarlightThemeProvider: StarlightThemeProvider
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export {}
|