@rxova/brand 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -98,9 +98,14 @@ once and gets both modes for free.
98
98
 
99
99
  ## Development
100
100
 
101
+ The package lives in a two-package workspace — itself and `apps/preview`, a
102
+ Starlight site that renders it. Run everything from the repo root; Turbo fans the
103
+ tasks out and replays whatever the commit did not touch.
104
+
101
105
  ```sh
102
106
  pnpm install
103
- pnpm run verify # format, lint, tsc, astro check, social cards, package contract
107
+ pnpm run dev # the preview site the only place to *look* at the theme
108
+ pnpm run verify # audit, dedupe, format, lint, types, astro check, cards, contract
104
109
  pnpm run og # re-render the social cards after a palette or tagline change
105
110
  ```
106
111
 
@@ -119,7 +124,13 @@ are perfectly correct.
119
124
 
120
125
  ### Trying a change in a consumer
121
126
 
122
- The package has no `workspace:*` shortcut, so iterate through snapshot releases:
127
+ `apps/preview` links the package by `workspace:*`, so most changes can be seen
128
+ immediately with `pnpm run dev`. It cannot catch a `files` omission, though —
129
+ the link resolves to the source directory, where every file exists. That is what
130
+ `check:exports` is for.
131
+
132
+ For a real external consumer (the landing, a docs site), iterate through snapshot
133
+ releases:
123
134
 
124
135
  1. Add a changeset (`pnpm exec changeset`).
125
136
  2. Run the **Snapshot** workflow — publishes `0.x.y-next.N` to the `next` tag.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxova/brand",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "Design tokens, Starlight theme and shared site chrome for rxova.org",
6
6
  "keywords": [
@@ -15,11 +15,12 @@
15
15
  "homepage": "https://rxova.org",
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "git+https://github.com/rxova/brand.git"
18
+ "url": "git+https://github.com/rxova/brand.git",
19
+ "directory": "packages/brand"
19
20
  },
20
21
  "bugs": "https://github.com/rxova/brand/issues",
21
22
  "engines": {
22
- "node": ">=20.19.0"
23
+ "node": ">=24.0.0"
23
24
  },
24
25
  "sideEffects": [
25
26
  "*.css"
@@ -54,42 +55,20 @@
54
55
  "devDependencies": {
55
56
  "@astrojs/check": "^0.9.9",
56
57
  "@astrojs/starlight": "^0.41.4",
57
- "@changesets/changelog-github": "^0.7.0",
58
- "@changesets/cli": "^2.29.7",
59
- "@commitlint/cli": "^21.2.1",
60
- "@commitlint/config-conventional": "^21.2.0",
61
- "@eslint/js": "^10.0.1",
62
58
  "@resvg/resvg-js": "^2.6.2",
63
59
  "@types/node": "^26.1.1",
64
60
  "astro": "^7.1.3",
65
- "eslint": "^10.7.0",
66
- "eslint-plugin-astro": "^1.3.0",
67
- "globals": "^17.6.0",
68
- "husky": "^9.1.7",
69
- "lint-staged": "^17.2.0",
70
- "prettier": "^3.9.6",
71
- "prettier-plugin-astro": "^0.14.0",
61
+ "publint": "^0.3.21",
72
62
  "satori": "^0.29.0",
73
- "typescript": "6.0.3",
74
- "typescript-eslint": "^8.65.0"
75
- },
76
- "lint-staged": {
77
- "*.{ts,tsx,astro,mjs,js}": [
78
- "eslint --fix",
79
- "prettier --write"
80
- ],
81
- "*.{json,jsonc,css,md,mdx,yaml,yml}": "prettier --write"
63
+ "tsx": "^4.23.1",
64
+ "typescript": "6.0.3"
82
65
  },
83
66
  "scripts": {
84
- "lint": "eslint .",
85
- "lint:fix": "eslint . --fix",
86
- "format": "prettier --write .",
87
- "format:check": "prettier --check .",
88
67
  "typecheck": "tsc --noEmit",
89
68
  "check:astro": "astro check",
90
- "check:exports": "node scripts/check-exports.mjs",
91
- "og": "node scripts/generate-og.mjs",
92
- "check:og": "node scripts/generate-og.mjs --check",
93
- "verify": "pnpm run format:check && pnpm run lint && pnpm run typecheck && pnpm run check:astro && pnpm run check:og && pnpm run check:exports"
69
+ "pack:smoke": "node --import tsx scripts/pack-smoke.ts",
70
+ "check:exports": "publint --strict",
71
+ "og": "node --import tsx scripts/generate-og.ts",
72
+ "check:og": "node --import tsx scripts/generate-og.ts --check"
94
73
  }
95
74
  }
@@ -0,0 +1,57 @@
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><slot /></Default>
26
+
27
+ <script>
28
+ type Theme = 'auto' | 'dark' | 'light'
29
+
30
+ /** Same key and coercion Starlight uses; unknown values mean "follow the OS". */
31
+ const STORAGE_KEY = 'starlight-theme'
32
+ const parseTheme = (theme: unknown): Theme =>
33
+ theme === 'auto' || theme === 'dark' || theme === 'light' ? theme : 'auto'
34
+ const preferredColorScheme = (): Theme =>
35
+ matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'
36
+
37
+ // `pageshow` is the only notification of a bfcache restore. A normal load
38
+ // also fires it with `persisted: false`, which we ignore — Starlight has
39
+ // already done the work in that case.
40
+ window.addEventListener('pageshow', (event) => {
41
+ if (!event.persisted) return
42
+
43
+ let stored: string | null
44
+ try {
45
+ stored = localStorage.getItem(STORAGE_KEY)
46
+ } catch {
47
+ // Storage can throw outright (Safari private mode, blocked cookies).
48
+ // Leaving the restored theme alone is the right fallback.
49
+ return
50
+ }
51
+
52
+ const theme = parseTheme(stored)
53
+ document.documentElement.dataset.theme = theme === 'auto' ? preferredColorScheme() : theme
54
+ // Keeps the picker from disagreeing with the page it controls.
55
+ StarlightThemeProvider.updatePickers(theme)
56
+ })
57
+ </script>
package/src/env.d.ts CHANGED
@@ -5,3 +5,17 @@
5
5
  // Starlight's own `.ts` sources, which import `virtual:starlight/*` modules
6
6
  // that only exist inside an Astro build — so plain `tsc` fails on them.
7
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 {}
package/src/starlight.ts CHANGED
@@ -73,6 +73,10 @@ export function sharedStarlightConfig({
73
73
  // Starlight's default footer (pagination, edit link, last updated) plus
74
74
  // the shared four-column site footer beneath it.
75
75
  Footer: '@rxova/brand/components/Footer.astro',
76
+ // Starlight's own picker, plus a resync when a page is restored from the
77
+ // back/forward cache — without it, changing the theme on one rxova.org
78
+ // surface and pressing Back leaves the restored page on the old theme.
79
+ ThemeSelect: '@rxova/brand/components/ThemeSelect.astro',
76
80
  ...components,
77
81
  },
78
82