@wintermuted/ui-theme 0.21.7 → 1.0.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 James Onnyeholt
3
+ Copyright (c) 2026 Jameson Nyeholt
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,304 +1,46 @@
1
1
  # `@wintermuted/ui-theme`
2
2
 
3
- Shared design tokens and base component styles for Wintermuted projects.
3
+ Shared plain-CSS design tokens, resets, component styles, and light/dark themes for Wintermuted projects.
4
4
 
5
- The package is derived from the styling language introduced in the CV project and extracts the reusable parts of that system so application repositories can depend on a single source of truth instead of copying CSS.
5
+ See the [theme architecture guide](https://github.com/wintermuted/wintermuted-ui/blob/main/packages/ui-theme/docs/architecture.md) for CSS layers, token ownership, public-path registration, and extension rules.
6
6
 
7
7
  ## Install
8
8
 
9
- ### npmjs
10
-
11
- ```bash
9
+ ```sh
12
10
  npm install @wintermuted/ui-theme
13
11
  ```
14
12
 
15
- ### GitHub repository release
16
-
17
- If you prefer to consume the package directly from GitHub without GitHub Packages auth, install from a tagged release:
18
-
19
- ```bash
20
- npm install github:wintermuted/wintermuted-ui#v0.1.0
21
- ```
22
-
23
- ## Includes
24
-
25
- - Core color, spacing, radius, shadow, and typography tokens
26
- - Base document and form-control styling
27
- - Shared surface, button, badge, tag, list, separator, and side-nav primitives
28
- - Light and dark theme variables via `[data-theme="dark"]`
29
-
30
13
  ## Usage
31
14
 
32
- ### Full Theme (single import)
15
+ Import the complete theme through your application's bundler:
33
16
 
34
- ```ts
17
+ ```js
35
18
  import "@wintermuted/ui-theme";
36
19
  ```
37
20
 
38
- Then use the exported CSS variables in application styles:
39
-
40
- ```css
41
- .app-shell {
42
- color: var(--wm-color-text);
43
- background: var(--wm-color-surface);
44
- border: 1px solid var(--wm-color-border);
45
- }
46
- ```
47
-
48
- ### Modular Imports (factor by need)
49
-
50
- Import only the slices you need. Most component files require tokens, and many apps also want base element styles.
21
+ Or load only the CSS you need:
51
22
 
52
- ```ts
23
+ ```js
53
24
  import "@wintermuted/ui-theme/styles/tokens.css";
54
25
  import "@wintermuted/ui-theme/styles/base.css";
55
26
  import "@wintermuted/ui-theme/styles/components/button.css";
56
- import "@wintermuted/ui-theme/styles/components/card.css";
57
27
  ```
58
28
 
59
- Available modular entry points:
60
-
61
- - `@wintermuted/ui-theme/styles/tokens.css`
62
- - `@wintermuted/ui-theme/styles/base.css`
63
- - `@wintermuted/ui-theme/styles/components.css` (all components)
64
- - `@wintermuted/ui-theme/styles/components/button.css`
65
- - `@wintermuted/ui-theme/styles/components/card.css`
66
- - `@wintermuted/ui-theme/styles/components/badge.css`
67
- - `@wintermuted/ui-theme/styles/components/tag.css`
68
- - `@wintermuted/ui-theme/styles/components/list.css`
69
- - `@wintermuted/ui-theme/styles/components/separator.css`
70
- - `@wintermuted/ui-theme/styles/components/side-nav.css`
71
-
72
-
73
- ## Static Design System Test Page
74
-
75
- This repo includes a static showcase app for validating common component scenarios.
76
-
77
- The optional React examples run through the local Vite development server; the existing HTML pages stay static.
78
-
79
- ```bash
80
- npm run showcase:serve
81
- ```
29
+ The package exports `index.css`, `styles/tokens.css`, `styles/base.css`, `styles/components.css`, and individual component stylesheets. Use `--wm-*` custom properties in application styles. Set `data-theme="dark"` on the document root to select the dark theme.
82
30
 
83
- Then open `http://localhost:4174/showcase/`.
31
+ This package lives in `packages/ui-theme` within the [Wintermuted UI monorepo](https://github.com/wintermuted/wintermuted-ui). New monorepo tags are not directly installable as the theme through a GitHub-source npm dependency; use npm releases or a tarball produced by `npm pack --workspace=@wintermuted/ui-theme`.
84
32
 
85
- ### GitHub Copilot app
33
+ ## Migrating to 1.0
86
34
 
87
- Review and accept `.github/github-app.yml` when prompted by the app. Node.js 22
88
- and npm must be available locally.
35
+ Version 1.0.0 removes the legacy `react`, `react/select`, and `theme` entry points, their TypeScript mappings, and all React-related peer dependencies. CSS imports and `--wm-*` tokens are unchanged. CSS-only consumers need no React packages.
89
36
 
90
- The **Install dependencies** script runs `npm ci --no-audit --no-fund` when a
91
- session is created and can also be rerun manually. **Run showcase** starts the
92
- existing Vite development server on port 4174.
37
+ React components and theme runtime helpers now come exclusively from `@wintermuted/ui-react`:
93
38
 
94
- Open `http://127.0.0.1:4174/showcase/` to view the documentation and React examples.
95
- Automatic browser opening is disabled because Vite reports the repository root
96
- URL, while the showcase lives under `/showcase/`. Stop the run script before
97
- starting the showcase in another session, since the server requires port 4174.
98
-
99
- Helpful local viewing scripts:
100
-
101
- ```bash
102
- npm run showcase:open
103
- npm run showcase:open:sample-data
104
- npm run showcase:open:forms
105
- ```
106
-
107
- The showcase includes:
108
-
109
- - Light and dark theme toggle
110
- - Buttons, badges, cards, and alerts
111
- - Form controls and focus states
112
- - A representative data table
113
- - A sample-data page that renders stats, chart bars, and table rows from one dataset
114
-
115
- Files:
116
-
117
- - `showcase/index.html`
118
- - `showcase/sample-data.html`
119
- - `showcase/showcase.css`
120
-
121
- ## GitHub Pages Deployments
122
-
123
- The showcase is deployed with a preview/main pattern:
124
-
125
- - Pushes to `main` publish production content to the root Pages site.
126
- - Pull requests to `main` publish isolated previews under `previews/pr-<number>/showcase/`.
127
- - Closing a pull request removes its preview folder from `gh-pages`.
128
-
129
- Workflows:
130
-
131
- - `.github/workflows/deploy-showcase-pages.yml`
132
- - `.github/workflows/cleanup-showcase-preview.yml`
133
-
134
- ## Local Symlink Workflow (No Publish Step)
135
-
136
- Use npm link to symlink this theme into local consuming apps so style changes appear immediately.
137
-
138
- From this repo:
139
-
140
- ```bash
141
- npm run link:local -- <consumer-path> [consumer-path-2 ...]
142
- ```
143
-
144
- Workspace example:
145
-
146
- ```bash
147
- npm run link:local -- ../sub-killer ../cv
148
- ```
149
-
150
- When done testing, revert consumers back to normal package resolution:
151
-
152
- ```bash
153
- npm run unlink:local -- ../sub-killer ../cv
154
- ```
155
-
156
- Scripts:
157
-
158
- - `scripts/link-local.sh`
159
- - `scripts/unlink-local.sh`
160
- ## Publishing
161
-
162
- - Merges to main trigger auto-release, which bumps the minor version in package.json, creates a matching vX.Y.Z tag, and creates a GitHub release.
163
- - Tag pushes matching v* trigger the publish workflow, which publishes to npmjs using npm provenance.
164
- - Set the NPM_TOKEN repository secret with an npm automation token before running the workflow.
165
-
166
- ## Notes
167
-
168
- - The package intentionally avoids application-specific layout opinions.
169
- - Projects should keep product-specific selectors and layout rules in their own repositories.
170
- - Publishing is handled through GitHub Actions to npmjs.
171
-
172
- ## Optional React components
173
-
174
- The CSS/root entry points are unchanged and do not load or install React. Install React
175
- and ReactDOM 18.3+ (or 19) only for the React API. Add react-select 5.8+ only when using
176
- the separate select adapter:
177
-
178
- ```powershell
179
- npm install @wintermuted/ui-theme react react-dom
180
- npm install react-select
181
- ```
182
-
183
- ```tsx
39
+ ```js
184
40
  import "@wintermuted/ui-theme/index.css";
185
- import { createRoot } from "react-dom/client";
186
- import {
187
- Button, Card, CardHeader, CardTitle, CardBody, CardText, FieldGroup,
188
- Input, ThemeProvider, ThemeSelect,
189
- } from "@wintermuted/ui-theme/react";
190
- import { initTheme } from "@wintermuted/ui-theme/theme";
191
-
192
- initTheme({ storageKey: "my-app:theme" });
193
- createRoot(document.getElementById("root")!).render(
194
- <ThemeProvider storageKey="my-app:theme">
195
- <ThemeSelect />
196
- <Card>
197
- <CardHeader><CardTitle>Departures</CardTitle></CardHeader>
198
- <CardBody>
199
- <CardText>Select stops to see arrivals.</CardText>
200
- <FieldGroup label="Stop name" hint="Enter part of a name."><Input /></FieldGroup>
201
- <Button onClick={refresh}>Refresh arrivals</Button>
202
- </CardBody>
203
- </Card>
204
- </ThemeProvider>
205
- );
41
+ import { Button, ThemeProvider } from "@wintermuted/ui-react";
42
+ import { MultiSelect } from "@wintermuted/ui-react/select";
43
+ import { initTheme } from "@wintermuted/ui-react/theme";
206
44
  ```
207
45
 
208
- These are distributable ES modules, not TSX source, with separate declaration files.
209
- No application compiler needs to transpile JSX inside this package. React is never bundled.
210
- The `typesVersions` entries support TypeScript 4.9's legacy `moduleResolution: node`;
211
- conditional exports support newer resolvers. CI checks packed-package React 18,
212
- TypeScript 7/bundler, Vite 8 and Webpack 5 consumers, plus CSS-only installation without peers.
213
- For CRA 5/Jest consumers, allow this ESM package through Babel's dependency transform:
214
-
215
- ```json
216
- {
217
- "jest": {
218
- "transformIgnorePatterns": ["node_modules/(?!@wintermuted/ui-theme/)"]
219
- }
220
- }
221
- ```
222
-
223
- ### Component contracts
224
-
225
- All components come from `@wintermuted/ui-theme/react` except `MultiSelect`.
226
- Primitives preserve native attributes, `className`, `style`, children and refs.
227
-
228
- | Export | Contract |
229
- | --- | --- |
230
- | `Button` | Native button; defaults to `type="button"`. `variant`: primary, secondary, ghost, danger, success, warning, link. Optional `size="sm"` and decorative `icon`. Supply an accessible name for icon-only buttons. |
231
- | `Badge`, `Alert` | `tone`: neutral, info, success, warning, danger. Alert defaults to `role="status"`; opt into `role="alert"` for urgent messages. |
232
- | `Card`, `CardHeader`, `CardBody`, `CardTitle`, `CardText`, `CardFooter` | Semantic section/header/div/h3/p/footer slots; `as` selects an element or custom component. |
233
- | `ListGroup`, `ListItem`, `Nav` | Semantic ul/li/nav; `as` supports other elements or router links without a router dependency. Label navigation regions and use `aria-current="page"` on active links. Compose grid/flex layout in your application. |
234
- | `Input`, `Select` | Native input/select attributes and refs, including controlled or default values. Select takes native option children. |
235
- | `FieldGroup` | Required `label` and one control element; optional `htmlFor`, `hint`, `error`. Generates IDs and merges `aria-describedby`; errors set `aria-invalid`. Custom controls must forward the supplied ID/ARIA props to their input. |
236
- | `Table` | Native table attributes/ref, optional `responsive` overflow region. Provide a caption or `aria-label`, and native thead/tbody/th scope markup. |
237
- | `Spinner` | `label` defaults to Loading; status text stays available with reduced motion. |
238
- | `ProgressBar` | Native progress element, numeric `value`/`max` (defaults 0/100), accessible `label` or native label/ARIA association. Values clamp to range; nonfinite inputs or nonpositive max throw. |
239
- | `Accordion` | Native details attributes with `title` as summary; supports `open`, `onToggle` and normal keyboard behavior. |
240
- | `Tabs` | Required `label` and `items: {id,label,content,disabled?}[]`; optional controlled `value`, uncontrolled `defaultValue`, `onValueChange(id)`. Unique stable IDs required. Arrow Left/Right, Home/End skip disabled tabs. Inactive panels stay mounted and hidden. |
241
- | `Menu` | `label` trigger; `items: {id,label,onSelect?,href?,disabled?}[]`. Arrow Up/Down, Home/End, Escape and Tab; closes on selection, outside click or focus leaving. For router navigation use `onSelect` or compose ordinary links in Nav. |
242
- | `Tooltip` | `text` and one focusable element child that forwards ARIA props. Visible on focus/hover, Escape dismisses, descriptions are merged. Do not put interactive content in tooltips or use a tooltip as the only accessible name. |
243
- | `Dialog` | Required controlled `open`, `onClose()` and `title`. Uses native `dialog.showModal()` for top-layer modality and Escape, plus explicit Tab/Shift+Tab wrapping. Focus returns to the opener on close/unmount. Caller must set open=false in onClose. Native dialog-capable browsers required; no silent non-modal fallback. |
244
- | `ThemeProvider`, `useTheme`, `ThemeSelect` | See theme preferences below. |
245
-
246
- ### Searchable select
247
-
248
- ```tsx
249
- import { MultiSelect } from "@wintermuted/ui-theme/react/select";
250
-
251
- const options = [{ value: 1, label: "North at Main", stop: { id: 1 } }];
252
- <MultiSelect
253
- options={options}
254
- defaultValue={[options[0]]}
255
- onChange={values => values.map(option => option.stop.id)}
256
- />;
257
- ```
258
-
259
- The adapter preserves react-select `Props<Option, IsMulti, Group>` inference, option objects,
260
- `defaultValue`, `value`, `onChange`, formatted labels, menu portals and callbacks. `isMulti`
261
- defaults to true; set `isMulti={false}` for a single value. `styles` overrides merge over
262
- token-based defaults; application-specific behavior remains in the application. Provide
263
- an accessible name with `aria-label`, `inputId` plus a label, or `FieldGroup`.
264
- Portals inherit document-level theme tokens; nested scoped themes need a portal target
265
- inside that scope.
266
-
267
- ### Theme preferences
268
-
269
- `useTheme()` returns `{ preference, setPreference, resolvedTheme }`. Preference is
270
- `"system" | "light" | "dark"` and defaults to System. Overrides persist under
271
- `wintermuted:theme` by default; pass a namespaced `storageKey` to both initialization
272
- and provider to isolate applications. Returning to System follows OS changes immediately.
273
- Cross-tab storage changes synchronize. Storage failures warn explicitly while the current
274
- selection still works in memory.
275
-
276
- For client rendering, call `initTheme({ storageKey })` from the React-free
277
- `@wintermuted/ui-theme/theme` entry **before mounting React**. For SSR or first paint of
278
- server HTML, emit `getThemeScript(storageKey)` in a synchronous inline `<head>` script
279
- before styles, with the appropriate CSP nonce. Never interpolate an unsanitized key into
280
- your own script. The helper safely escapes `<` in serialized keys. Hydration markup should
281
- not branch on the client preference on the server; theme-dependent UI should render after
282
- mount. Importing the React-free helper on the server is safe.
283
-
284
- Only `document.documentElement.dataset.theme` and `style.colorScheme` are updated.
285
- Map styles, tile sources, transit data and application state are not changed.
286
- Use one document-level ThemeProvider per app. `ThemeSelect` defaults to label Appearance
287
- with System, Light and Dark options and must be inside a provider.
288
-
289
- ### Development and release
290
-
291
- Development uses React/ReactDOM 19 and matching React 19 types; the optional peer ranges
292
- and packed-consumer checks retain React 18.3 compatibility.
293
- TypeScript 7, Vite 8, and JSDOM 31 are the development baseline. Volta pins Node 22.23.5;
294
- JSDOM and Stylelint 18 require Node 22.22.2+, 24.15+, or 26+. Older TypeScript/Vite
295
- versions are no longer included in the consumer checks.
296
-
297
- Run `npm test` for DOM behavior/package contracts and `npm run test:browser` for native
298
- Chromium keyboard/focus/theme checks (`npx playwright install chromium` once if needed).
299
- Open `/showcase/react.html` with `npm run showcase:serve` for live examples.
300
- CI alone runs builds/type checks via `npm run test:consumers` and bundles the React
301
- showcase for Pages. Existing CSS pages are copied unchanged alongside it.
302
- Publication is still the automated release process; an unpublished source tarball with
303
- unchanged version metadata is an integration artifact, not proof that the registry version
304
- has these APIs. Do not commit machine-local tarball dependencies to consumers.
46
+ Install `@wintermuted/ui-react` and React/React DOM 18.3 or 19; add react-select 5.8 or newer only for the select adapter. See the [1.0 migration guide](https://github.com/wintermuted/wintermuted-ui/blob/main/docs/migration-to-v1.md) for installation, import mappings, test tooling, and release ordering.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wintermuted/ui-theme",
3
- "version": "0.21.7",
3
+ "version": "1.0.0",
4
4
  "description": "Shared Wintermuted UI theme (design tokens, base resets, and component styles) derived from the CV styling language.",
5
5
  "type": "module",
6
6
  "volta": {
@@ -18,14 +18,13 @@
18
18
  "index.js",
19
19
  "index.css",
20
20
  "styles/**/*.css",
21
- "react/**/*.js",
22
- "react/**/*.d.ts",
23
21
  "README.md",
24
22
  "LICENSE"
25
23
  ],
26
24
  "repository": {
27
25
  "type": "git",
28
- "url": "git+https://github.com/wintermuted/wintermuted-ui.git"
26
+ "url": "git+https://github.com/wintermuted/wintermuted-ui.git",
27
+ "directory": "packages/ui-theme"
29
28
  },
30
29
  "bugs": {
31
30
  "url": "https://github.com/wintermuted/ui-theme/issues"
@@ -37,18 +36,6 @@
37
36
  },
38
37
  "exports": {
39
38
  ".": "./index.js",
40
- "./react": {
41
- "types": "./react/index.d.ts",
42
- "default": "./react/index.js"
43
- },
44
- "./react/select": {
45
- "types": "./react/select.d.ts",
46
- "default": "./react/select.js"
47
- },
48
- "./theme": {
49
- "types": "./react/theme.d.ts",
50
- "default": "./react/theme.js"
51
- },
52
39
  "./index.css": "./index.css",
53
40
  "./styles/tokens.css": "./styles/tokens.css",
54
41
  "./styles/base.css": "./styles/base.css",
@@ -89,66 +76,20 @@
89
76
  "./styles/components/dialog.css": "./styles/components/dialog.css",
90
77
  "./styles/components/search-select.css": "./styles/components/search-select.css"
91
78
  },
92
- "typesVersions": {
93
- "*": {
94
- "react": [
95
- "react/index.d.ts"
96
- ],
97
- "react/select": [
98
- "react/select.d.ts"
99
- ],
100
- "theme": [
101
- "react/theme.d.ts"
102
- ]
103
- }
104
- },
105
- "peerDependencies": {
106
- "react": "^18.3.0 || ^19.0.0",
107
- "react-dom": "^18.3.0 || ^19.0.0",
108
- "react-select": "^5.8.0"
109
- },
110
- "peerDependenciesMeta": {
111
- "react": {
112
- "optional": true
113
- },
114
- "react-dom": {
115
- "optional": true
116
- },
117
- "react-select": {
118
- "optional": true
119
- }
120
- },
121
79
  "scripts": {
122
- "test": "node --test tests/*.test.js",
123
- "test:browser": "node --test browser-tests/*.test.js",
124
- "test:pack": "node tests/consumers.mjs --package-only",
125
- "test:consumers": "node tests/consumers.mjs",
126
- "showcase:serve": "vite --host 127.0.0.1 --port 4174 --strictPort",
127
- "showcase:build": "vite build --config showcase/vite.config.js",
128
- "showcase:open": "sh -c 'command -v open >/dev/null 2>&1 && open http://localhost:4174/showcase/ || xdg-open http://localhost:4174/showcase/'",
129
- "showcase:open:sample-data": "sh -c 'command -v open >/dev/null 2>&1 && open http://localhost:4174/showcase/sample-data.html || xdg-open http://localhost:4174/showcase/sample-data.html'",
130
- "showcase:open:forms": "sh -c 'command -v open >/dev/null 2>&1 && open http://localhost:4174/showcase/forms.html || xdg-open http://localhost:4174/showcase/forms.html'",
131
- "showcase:view": "npm run showcase:serve",
132
- "link:local": "bash scripts/link-local.sh",
133
- "unlink:local": "bash scripts/unlink-local.sh",
134
80
  "lint": "stylelint \"styles/**/*.css\" \"index.css\""
135
81
  },
136
- "devDependencies": {
137
- "@testing-library/react": "^16.3.0",
138
- "@testing-library/user-event": "^14.6.1",
139
- "@types/react": "^19.3.0",
140
- "@types/react-dom": "^19.3.0",
141
- "css-loader": "^7.1.2",
142
- "jsdom": "^31.0.1",
143
- "playwright": "^1.56.1",
144
- "react": "^19.3.1",
145
- "react-dom": "^19.3.1",
146
- "react-select": "^5.10.2",
147
- "style-loader": "^4.0.0",
148
- "stylelint": "^18.0.0",
149
- "stylelint-config-standard": "^41.0.0",
150
- "typescript": "^7.0.2",
151
- "vite": "^8.3.8",
152
- "webpack": "^5.102.1"
82
+ "nx": {
83
+ "name": "ui-theme",
84
+ "tags": ["type:library"],
85
+ "targets": {
86
+ "pack": {
87
+ "command": "npm pack --workspace=@wintermuted/ui-theme"
88
+ },
89
+ "nx-release-publish": {
90
+ "executor": "@nx/js:release-publish",
91
+ "options": { "packageRoot": "packages/ui-theme" }
92
+ }
93
+ }
153
94
  }
154
95
  }
package/react/index.d.ts DELETED
@@ -1,74 +0,0 @@
1
- import type * as React from "react";
2
- import type { ThemePreference, ResolvedTheme } from "./theme";
3
- export type { ThemePreference, ResolvedTheme } from "./theme";
4
-
5
- export type Tone = "neutral" | "info" | "success" | "warning" | "danger";
6
- type Primitive<Default extends React.ElementType> = {
7
- (props: { as?: Default } & React.ComponentPropsWithRef<Default>): React.ReactElement | null;
8
- <T extends React.ElementType>(
9
- props: { as: T } & Omit<React.ComponentPropsWithRef<T>, "as">
10
- ): React.ReactElement | null;
11
- };
12
- export const Card: Primitive<"section">;
13
- export const CardHeader: Primitive<"header">;
14
- export const CardBody: Primitive<"div">;
15
- export const CardTitle: Primitive<"h3">;
16
- export const CardText: Primitive<"p">;
17
- export const CardFooter: Primitive<"footer">;
18
- export const ListGroup: Primitive<"ul">;
19
- export const ListItem: Primitive<"li">;
20
- export const Nav: Primitive<"nav">;
21
- export const Input: Primitive<"input">;
22
- export const Select: Primitive<"select">;
23
-
24
- export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
25
- variant?: "primary" | "secondary" | "ghost" | "danger" | "success" | "warning" | "link";
26
- size?: "sm";
27
- icon?: React.ReactNode;
28
- }
29
- export const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
30
- export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> { tone?: Tone }
31
- export const Badge: React.ForwardRefExoticComponent<BadgeProps & React.RefAttributes<HTMLSpanElement>>;
32
- export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> { tone?: Tone }
33
- export const Alert: React.ForwardRefExoticComponent<AlertProps & React.RefAttributes<HTMLDivElement>>;
34
- export function Spinner(props: React.HTMLAttributes<HTMLSpanElement> & { label?: string }): React.ReactElement;
35
- export function ProgressBar(props: React.ProgressHTMLAttributes<HTMLProgressElement> & {
36
- value?: number; max?: number; label?: string;
37
- }): React.ReactElement;
38
- export const Table: React.ForwardRefExoticComponent<React.TableHTMLAttributes<HTMLTableElement> & {
39
- responsive?: boolean;
40
- } & React.RefAttributes<HTMLTableElement>>;
41
- export interface FieldGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> {
42
- label: React.ReactNode; htmlFor?: string; hint?: React.ReactNode; error?: React.ReactNode;
43
- children: React.ReactElement;
44
- }
45
- export function FieldGroup(props: FieldGroupProps): React.ReactElement;
46
- export function Accordion(props: Omit<React.DetailsHTMLAttributes<HTMLDetailsElement>, "title"> & {
47
- title: React.ReactNode;
48
- }): React.ReactElement;
49
- export interface TabItem { id: string; label: React.ReactNode; content: React.ReactNode; disabled?: boolean }
50
- export interface TabsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "defaultValue" | "onChange"> {
51
- items: TabItem[]; value?: string; defaultValue?: string;
52
- onValueChange?: (id: string) => void; label: string;
53
- }
54
- export function Tabs(props: TabsProps): React.ReactElement;
55
- export interface MenuItem {
56
- id: string; label: React.ReactNode; href?: string; disabled?: boolean;
57
- onSelect?: (event: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => void;
58
- }
59
- export function Menu(props: Omit<React.HTMLAttributes<HTMLDivElement>, "children"> & {
60
- label: React.ReactNode; items: MenuItem[];
61
- }): React.ReactElement;
62
- export function Tooltip(props: { text: string; children: React.ReactElement }): React.ReactElement;
63
- export function Dialog(props: Omit<React.DialogHTMLAttributes<HTMLDialogElement>, "open" | "onClose" | "title"> & {
64
- open: boolean; onClose: () => void; title: React.ReactNode;
65
- }): React.ReactElement;
66
- export interface ThemeContextValue {
67
- preference: ThemePreference;
68
- setPreference: (preference: ThemePreference) => void;
69
- resolvedTheme: ResolvedTheme;
70
- }
71
- export function ThemeProvider(props: { children: React.ReactNode; storageKey?: string }): React.ReactElement;
72
- export function useTheme(): ThemeContextValue;
73
- export function ThemeSelect(props: Omit<React.SelectHTMLAttributes<HTMLSelectElement>,
74
- "value" | "defaultValue" | "onChange"> & { label?: string }): React.ReactElement;
package/react/index.js DELETED
@@ -1,325 +0,0 @@
1
- import {
2
- Children, cloneElement, createContext, createElement as h, forwardRef,
3
- useContext, useEffect, useId, useLayoutEffect, useRef, useState,
4
- } from "react";
5
- import {
6
- DEFAULT_THEME_KEY, applyTheme, isThemePreference, readThemePreference, resolveTheme,
7
- } from "./theme.js";
8
-
9
- const cx = (...values) => values.filter(Boolean).join(" ");
10
- const useClientLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
11
-
12
- function primitive(tag, baseClass) {
13
- return forwardRef(function Primitive({ as = tag, className, ...props }, ref) {
14
- return h(as, { ...props, ref, className: cx(baseClass, className) });
15
- });
16
- }
17
-
18
- export const Card = primitive("section", "wm-card");
19
- export const CardHeader = primitive("header", "wm-card-header");
20
- export const CardBody = primitive("div", "wm-card-body");
21
- export const CardTitle = primitive("h3", "wm-card-title");
22
- export const CardText = primitive("p", "wm-card-text");
23
- export const CardFooter = primitive("footer", "wm-card-footer");
24
- export const ListGroup = primitive("ul", "wm-list-group");
25
- export const ListItem = primitive("li", "wm-list-item");
26
- export const Nav = primitive("nav", "wm-nav");
27
- export const Input = primitive("input", "wm-input");
28
- export const Select = primitive("select", "wm-select");
29
-
30
- export const Button = forwardRef(function Button({
31
- variant = "primary", size, icon, className, children, type = "button", ...props
32
- }, ref) {
33
- return h("button", {
34
- ...props, ref, type,
35
- className: cx("wm-btn", `wm-btn-${variant}`, size && `wm-btn-${size}`, className),
36
- }, icon && h("span", { "aria-hidden": true, className: "wm-btn-icon" }, icon), children);
37
- });
38
-
39
- export const Badge = forwardRef(function Badge({ tone = "neutral", className, ...props }, ref) {
40
- return h("span", { ...props, ref, className: cx("wm-badge", `wm-badge-${tone}`, className) });
41
- });
42
-
43
- export const Alert = forwardRef(function Alert({ tone = "info", className, role = "status", ...props }, ref) {
44
- return h("div", { ...props, ref, role, className: cx("wm-alert", `wm-alert-${tone}`, className) });
45
- });
46
-
47
- export function Spinner({ label = "Loading", className, ...props }) {
48
- return h("span", { ...props, role: "status", className: cx("wm-spinner", className) },
49
- h("span", { "aria-hidden": true, className: "wm-spinner-indicator" }),
50
- h("span", { className: "wm-sr-only" }, label));
51
- }
52
-
53
- export function ProgressBar({ value = 0, max = 100, label, className, ...props }) {
54
- if (!Number.isFinite(max) || max <= 0 || !Number.isFinite(value)) {
55
- throw new RangeError("ProgressBar requires a finite value and a positive finite max.");
56
- }
57
- return h("progress", { ...props, className: cx("wm-progress", className),
58
- value: Math.min(max, Math.max(0, value)), max, "aria-label": label ?? props["aria-label"] });
59
- }
60
-
61
- export const Table = forwardRef(function Table({ responsive = false, className, ...props }, ref) {
62
- const table = h("table", { ...props, ref, className: cx("wm-table", className) });
63
- return responsive ? h("div", { className: "wm-table-responsive", tabIndex: 0,
64
- role: "region", "aria-label": props["aria-label"] || "Scrollable table" }, table) : table;
65
- });
66
-
67
- export function FieldGroup({ label, htmlFor, hint, error, className, children, ...props }) {
68
- const id = useId();
69
- const descriptionId = `${id}-description`;
70
- const child = Children.only(children);
71
- const controlId = htmlFor || child.props.inputId || child.props.id || `${id}-control`;
72
- const describedBy = cx(child.props["aria-describedby"], (hint || error) && descriptionId) || undefined;
73
- return h("div", { ...props, className: cx("wm-field", className) },
74
- h("label", { htmlFor: controlId }, label),
75
- cloneElement(child, {
76
- id: controlId, "aria-describedby": describedBy,
77
- ...(child.props.inputId !== undefined ? { inputId: controlId } : {}),
78
- "aria-invalid": error ? true : child.props["aria-invalid"],
79
- }),
80
- (hint || error) && h("div", { id: descriptionId, className: error ? "wm-field-error" : "wm-field-hint" }, error || hint));
81
- }
82
-
83
- export function Accordion({ title, children, className, ...props }) {
84
- return h("details", { ...props, className: cx("wm-accordion", className) },
85
- h("summary", null, title), h("div", { className: "wm-accordion-body" }, children));
86
- }
87
-
88
- export function Tabs({ items, value, defaultValue, onValueChange, label, className, ...props }) {
89
- const prefix = useId();
90
- const [internal, setInternal] = useState(defaultValue);
91
- const requested = value === undefined ? internal : value;
92
- const active = items.find(item => item.id === requested && !item.disabled)?.id
93
- ?? items.find(item => !item.disabled)?.id;
94
- const refs = useRef([]);
95
- function activate(item) {
96
- if (value === undefined) setInternal(item.id);
97
- onValueChange?.(item.id);
98
- }
99
- function navigate(event, index) {
100
- const enabled = items.map((item, i) => item.disabled ? -1 : i).filter(i => i !== -1);
101
- const position = enabled.indexOf(index);
102
- let target;
103
- if (event.key === "ArrowRight") target = enabled[(position + 1) % enabled.length];
104
- if (event.key === "ArrowLeft") target = enabled[(position - 1 + enabled.length) % enabled.length];
105
- if (event.key === "Home") target = enabled[0];
106
- if (event.key === "End") target = enabled[enabled.length - 1];
107
- if (target === undefined) return;
108
- event.preventDefault();
109
- refs.current[target]?.focus();
110
- activate(items[target]);
111
- }
112
- return h("div", { ...props, className: cx("wm-tabs", className) },
113
- h("div", { role: "tablist", "aria-label": label, className: "wm-tab-bar" },
114
- items.map((item, index) => h("button", {
115
- key: item.id, id: `${prefix}-tab-${item.id}`, type: "button", role: "tab",
116
- "aria-selected": active === item.id, "aria-controls": `${prefix}-panel-${item.id}`,
117
- tabIndex: active === item.id ? 0 : -1, disabled: item.disabled,
118
- className: cx("wm-tab-btn", active === item.id && "wm-tab-btn-active"),
119
- ref: node => { refs.current[index] = node; },
120
- onKeyDown: event => navigate(event, index), onClick: () => activate(item),
121
- }, item.label))),
122
- items.map(item => h("div", { key: item.id, id: `${prefix}-panel-${item.id}`,
123
- role: "tabpanel", "aria-labelledby": `${prefix}-tab-${item.id}`,
124
- hidden: active !== item.id, tabIndex: 0, className: "wm-tab-panel" }, item.content)));
125
- }
126
-
127
- export function Menu({ label, items, className, ...props }) {
128
- const id = useId();
129
- const [open, setOpen] = useState(false);
130
- const trigger = useRef(null);
131
- const root = useRef(null);
132
- const refs = useRef([]);
133
- const focusLast = useRef(false);
134
- useClientLayoutEffect(() => {
135
- if (!open) return;
136
- const enabled = refs.current.filter(node => node && node.getAttribute("aria-disabled") !== "true");
137
- (focusLast.current ? enabled.at(-1) : enabled[0])?.focus();
138
- }, [open]);
139
- useEffect(() => {
140
- if (!open) return;
141
- const outside = event => { if (!root.current?.contains(event.target)) setOpen(false); };
142
- document.addEventListener("pointerdown", outside);
143
- return () => document.removeEventListener("pointerdown", outside);
144
- }, [open]);
145
- function close(restore = false) {
146
- setOpen(false);
147
- if (restore) trigger.current?.focus();
148
- }
149
- function navigate(event) {
150
- if (event.key === "Escape") { event.preventDefault(); close(true); return; }
151
- if (event.key === "Tab") { close(true); return; }
152
- const enabled = refs.current.filter(node => node && node.getAttribute("aria-disabled") !== "true");
153
- const index = enabled.indexOf(document.activeElement);
154
- let next;
155
- if (event.key === "ArrowDown") next = enabled[(index + 1) % enabled.length];
156
- if (event.key === "ArrowUp") next = enabled[(index - 1 + enabled.length) % enabled.length];
157
- if (event.key === "Home") next = enabled[0];
158
- if (event.key === "End") next = enabled.at(-1);
159
- if (next) { event.preventDefault(); next.focus(); }
160
- }
161
- return h("div", { ...props, ref: root, className: cx("wm-menu", className),
162
- onBlur: event => { if (!event.currentTarget.contains(event.relatedTarget)) close(); } },
163
- h(Button, { ref: trigger, variant: "secondary", "aria-haspopup": "menu",
164
- "aria-expanded": open, "aria-controls": open ? id : undefined,
165
- onClick: () => { focusLast.current = false; setOpen(!open); },
166
- onKeyDown: event => {
167
- if (open && event.key === "Escape") { event.preventDefault(); close(true); return; }
168
- if (event.key === "ArrowDown" || event.key === "ArrowUp") {
169
- event.preventDefault(); focusLast.current = event.key === "ArrowUp"; setOpen(true);
170
- }
171
- } }, label),
172
- open && h("ul", { id, role: "menu", "aria-label": typeof label === "string" ? label : "Actions",
173
- className: "wm-menu-items", onKeyDown: navigate },
174
- items.map((item, index) => h("li", { key: item.id, role: "none" },
175
- h(item.href && !item.disabled ? "a" : "button", {
176
- href: item.disabled ? undefined : item.href,
177
- type: item.href && !item.disabled ? undefined : "button",
178
- role: "menuitem", tabIndex: -1, "aria-disabled": item.disabled || undefined,
179
- ref: node => { refs.current[index] = node; },
180
- onClick: event => {
181
- if (item.disabled) { event.preventDefault(); return; }
182
- close(true); item.onSelect?.(event);
183
- },
184
- }, item.label)))));
185
- }
186
-
187
- export function Tooltip({ text, children }) {
188
- const id = useId();
189
- const [hovered, setHovered] = useState(false);
190
- const [focused, setFocused] = useState(false);
191
- const [dismissed, setDismissed] = useState(false);
192
- const visible = (hovered || focused) && !dismissed;
193
- const child = Children.only(children);
194
- useEffect(() => {
195
- if (!visible) return;
196
- const dismiss = event => { if (event.key === "Escape") setDismissed(true); };
197
- document.addEventListener("keydown", dismiss);
198
- return () => document.removeEventListener("keydown", dismiss);
199
- }, [visible]);
200
- return h("span", { className: "wm-tooltip-anchor",
201
- onMouseEnter: () => { setHovered(true); setDismissed(false); },
202
- onMouseLeave: () => setHovered(false),
203
- onFocus: () => { setFocused(true); setDismissed(false); },
204
- onBlur: event => { if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false); } },
205
- cloneElement(child, { "aria-describedby": cx(child.props["aria-describedby"], visible && id) || undefined }),
206
- visible && h("span", { id, role: "tooltip", className: "wm-tooltip" }, text));
207
- }
208
-
209
- export function Dialog({ open, onClose, title, children, className, ...props }) {
210
- const ref = useRef(null);
211
- const restoreTarget = useRef(null);
212
- const internalCloses = useRef(0);
213
- const titleId = useId();
214
- useClientLayoutEffect(() => {
215
- const dialog = ref.current;
216
- if (!open) return;
217
- if (!restoreTarget.current || !dialog.contains(document.activeElement)) {
218
- restoreTarget.current = document.activeElement;
219
- }
220
- const previous = restoreTarget.current;
221
- dialog.showModal();
222
- return () => {
223
- if (dialog.open) { internalCloses.current += 1; dialog.close(); }
224
- // Restore after React's commit-time focus restoration, including unmount.
225
- queueMicrotask(() => {
226
- if (dialog.open) return;
227
- if (previous?.isConnected) previous.focus();
228
- restoreTarget.current = null;
229
- });
230
- };
231
- }, [open]);
232
- function trapFocus(event) {
233
- props.onKeyDown?.(event);
234
- if (event.defaultPrevented || event.key !== "Tab") return;
235
- const dialog = ref.current;
236
- const candidates = Array.from(dialog.querySelectorAll(
237
- "a[href], area[href], button, input, select, textarea, summary, iframe, object, embed, audio[controls], video[controls], [tabindex], [contenteditable='true']",
238
- )).filter(node => (node.tabIndex >= 0 || (node.isContentEditable && !node.hasAttribute("tabindex")))
239
- && !node.matches(":disabled")
240
- && !node.closest("[inert]") && node.getClientRects().length > 0
241
- && window.getComputedStyle(node).visibility === "visible");
242
- const tabbable = candidates.filter(node => {
243
- if (node.tagName !== "INPUT" || node.type !== "radio" || !node.name) return true;
244
- const group = candidates.filter(other => other.tagName === "INPUT" && other.type === "radio"
245
- && other.name === node.name && other.form === node.form);
246
- return node === (group.find(other => other.checked) || group[0]);
247
- }).sort((a, b) => (a.tabIndex > 0 ? a.tabIndex : Infinity) - (b.tabIndex > 0 ? b.tabIndex : Infinity));
248
- const first = tabbable[0];
249
- const last = tabbable[tabbable.length - 1];
250
- if (!first) { event.preventDefault(); dialog.focus(); return; }
251
- if (event.shiftKey && (document.activeElement === first || document.activeElement === dialog)) {
252
- event.preventDefault(); last.focus();
253
- } else if (!event.shiftKey && (document.activeElement === last || document.activeElement === dialog)) {
254
- event.preventDefault(); first.focus();
255
- }
256
- }
257
- return h("dialog", { ...props, ref, "aria-labelledby": titleId,
258
- tabIndex: props.tabIndex ?? -1, onKeyDown: trapFocus,
259
- className: cx("wm-dialog", className),
260
- onCancel: event => {
261
- props.onCancel?.(event);
262
- const cancelled = event.defaultPrevented;
263
- event.preventDefault();
264
- if (!cancelled) onClose();
265
- },
266
- onClose: () => {
267
- if (internalCloses.current > 0) internalCloses.current -= 1;
268
- else if (open) onClose();
269
- } },
270
- h("header", { className: "wm-dialog-header" }, h("h3", { id: titleId }, title),
271
- h(Button, { variant: "ghost", onClick: onClose, "aria-label": "Close dialog" }, "Close")),
272
- h("div", { className: "wm-dialog-body" }, children));
273
- }
274
-
275
- const ThemeContext = createContext(null);
276
-
277
- export function ThemeProvider({ children, storageKey = DEFAULT_THEME_KEY }) {
278
- const [preference, setPreferenceState] = useState(() => readThemePreference(storageKey));
279
- const currentPreference = useRef(preference);
280
- const [resolvedTheme, setResolvedTheme] = useState(() => resolveTheme(preference));
281
- useClientLayoutEffect(() => {
282
- const sync = () => {
283
- const current = readThemePreference(storageKey);
284
- currentPreference.current = current;
285
- setPreferenceState(current);
286
- setResolvedTheme(applyTheme(current));
287
- };
288
- sync();
289
- const query = window.matchMedia?.("(prefers-color-scheme: dark)");
290
- const systemChange = () => setResolvedTheme(applyTheme(currentPreference.current));
291
- const storage = event => { if (event.key === storageKey || event.key === null) sync(); };
292
- query?.addEventListener("change", systemChange);
293
- window.addEventListener("storage", storage);
294
- return () => {
295
- query?.removeEventListener("change", systemChange);
296
- window.removeEventListener("storage", storage);
297
- };
298
- }, [storageKey]);
299
- function setPreference(next) {
300
- if (!isThemePreference(next)) throw new TypeError("Theme preference must be system, light, or dark.");
301
- try { window.localStorage.setItem(storageKey, next); }
302
- catch (error) { console.warn("Wintermuted theme preference could not be saved.", error); }
303
- currentPreference.current = next;
304
- setPreferenceState(next);
305
- setResolvedTheme(applyTheme(next));
306
- }
307
- return h(ThemeContext.Provider, { value: { preference, setPreference, resolvedTheme } }, children);
308
- }
309
-
310
- export function useTheme() {
311
- const theme = useContext(ThemeContext);
312
- if (!theme) throw new Error("useTheme must be used inside ThemeProvider.");
313
- return theme;
314
- }
315
-
316
- export function ThemeSelect({ label = "Appearance", id, ...props }) {
317
- const generated = useId();
318
- const { preference, setPreference } = useTheme();
319
- const controlId = id || generated;
320
- return h(FieldGroup, { label, htmlFor: controlId },
321
- h(Select, { ...props, id: controlId, value: preference, onChange: event => setPreference(event.target.value) },
322
- h("option", { value: "system" }, "System"),
323
- h("option", { value: "light" }, "Light"),
324
- h("option", { value: "dark" }, "Dark")));
325
- }
package/react/select.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { ReactElement } from "react";
2
- import type { GroupBase, Props } from "react-select";
3
-
4
- export type MultiSelectProps<Option = unknown, IsMulti extends boolean = true,
5
- Group extends GroupBase<Option> = GroupBase<Option>> = Props<Option, IsMulti, Group>;
6
-
7
- export function MultiSelect<Option = unknown, IsMulti extends boolean = true,
8
- Group extends GroupBase<Option> = GroupBase<Option>>(
9
- props: MultiSelectProps<Option, IsMulti, Group>
10
- ): ReactElement;
package/react/select.js DELETED
@@ -1,38 +0,0 @@
1
- import { createElement, useId } from "react";
2
- import ReactSelect, { mergeStyles } from "react-select";
3
-
4
- // Inline values are CSS variables so open menus follow a theme change immediately.
5
- const styles = {
6
- control: (base, state) => ({ ...base,
7
- backgroundColor: "var(--wm-color-bg)", color: "var(--wm-color-text)",
8
- borderColor: state.isFocused ? "var(--wm-color-accent)" : "var(--wm-color-border-strong)",
9
- borderRadius: "var(--wm-radius-xs)",
10
- boxShadow: state.isFocused ? "0 0 0 2px var(--wm-color-accent-border)" : "none",
11
- ":hover": { borderColor: "var(--wm-color-accent)" },
12
- }),
13
- menu: base => ({ ...base, backgroundColor: "var(--wm-color-surface-solid)",
14
- color: "var(--wm-color-text)", border: "1px solid var(--wm-color-border)" }),
15
- menuPortal: base => ({ ...base, color: "var(--wm-color-text)" }),
16
- option: (base, state) => ({ ...base,
17
- backgroundColor: state.isSelected ? "var(--wm-color-accent-soft)"
18
- : state.isFocused ? "var(--wm-color-surface-strong)" : "transparent",
19
- color: state.isDisabled ? "var(--wm-color-text-muted)" : "var(--wm-color-text)",
20
- ":active": { backgroundColor: "var(--wm-color-accent-soft)" },
21
- }),
22
- singleValue: base => ({ ...base, color: "var(--wm-color-text)" }),
23
- input: base => ({ ...base, color: "var(--wm-color-text)" }),
24
- placeholder: base => ({ ...base, color: "var(--wm-color-text-muted)" }),
25
- multiValue: base => ({ ...base, backgroundColor: "var(--wm-color-surface-strong)" }),
26
- multiValueLabel: base => ({ ...base, color: "var(--wm-color-text)" }),
27
- multiValueRemove: base => ({ ...base, color: "var(--wm-color-text-secondary)",
28
- ":hover": { backgroundColor: "var(--wm-color-danger-soft)", color: "var(--wm-color-danger)" } }),
29
- };
30
-
31
- export function MultiSelect({ styles: overrides, isMulti = true, id, className, ...props }) {
32
- const generated = useId();
33
- return createElement(ReactSelect, {
34
- instanceId: generated, ...props, inputId: props.inputId ?? id,
35
- className: ["wm-search-select", className].filter(Boolean).join(" "),
36
- isMulti, styles: mergeStyles(styles, overrides),
37
- });
38
- }
package/react/theme.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export type ThemePreference = "system" | "light" | "dark";
2
- export type ResolvedTheme = "light" | "dark";
3
- export const DEFAULT_THEME_KEY: string;
4
- export function isThemePreference(value: unknown): value is ThemePreference;
5
- export function readThemePreference(storageKey?: string): ThemePreference;
6
- export function resolveTheme(preference: ThemePreference): ResolvedTheme;
7
- export function applyTheme(preference: ThemePreference): ResolvedTheme;
8
- export function initTheme(options?: { storageKey?: string }): ResolvedTheme;
9
- export function getThemeScript(storageKey?: string): string;
package/react/theme.js DELETED
@@ -1,41 +0,0 @@
1
- export const DEFAULT_THEME_KEY = "wintermuted:theme";
2
-
3
- export function isThemePreference(value) {
4
- return value === "system" || value === "light" || value === "dark";
5
- }
6
-
7
- export function readThemePreference(storageKey = DEFAULT_THEME_KEY) {
8
- if (typeof window === "undefined") return "system";
9
- try {
10
- const stored = window.localStorage.getItem(storageKey);
11
- return isThemePreference(stored) ? stored : "system";
12
- } catch (error) {
13
- console.warn("Wintermuted theme preference could not be read.", error);
14
- return "system";
15
- }
16
- }
17
-
18
- export function resolveTheme(preference) {
19
- return preference === "system"
20
- ? (typeof window !== "undefined" && window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light")
21
- : preference;
22
- }
23
-
24
- export function applyTheme(preference) {
25
- const resolved = resolveTheme(preference);
26
- if (typeof document !== "undefined") {
27
- document.documentElement.dataset.theme = resolved;
28
- document.documentElement.style.colorScheme = resolved;
29
- }
30
- return resolved;
31
- }
32
-
33
- export function initTheme({ storageKey = DEFAULT_THEME_KEY } = {}) {
34
- return applyTheme(readThemePreference(storageKey));
35
- }
36
-
37
- // Keep this synchronous bootstrap self-contained so SSR can emit it before CSS.
38
- export function getThemeScript(storageKey = DEFAULT_THEME_KEY) {
39
- const key = JSON.stringify(storageKey).replace(/</g, "\\u003c");
40
- return `(function(){var p="system";try{var s=localStorage.getItem(${key});if(s==="light"||s==="dark")p=s;}catch(e){console.warn("Wintermuted theme preference could not be read.",e);}var t=p==="system"?(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"):p;document.documentElement.dataset.theme=t;document.documentElement.style.colorScheme=t;})();`;
41
- }