strata-react 1.0.39 → 1.0.41
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 +29 -5
- package/UPGRADING.md +11 -0
- package/bin/strata-stock-classes.js +5 -0
- package/dist/components/button.d.ts +3 -0
- package/dist/components/checkbox.d.ts +3 -2
- package/dist/components/compare-parts.d.ts +25 -0
- package/dist/components/compare-video.d.ts +4 -2
- package/dist/components/compare.d.ts +4 -2
- package/dist/components/secret-field.d.ts +34 -0
- package/dist/components/selection.d.ts +45 -1
- package/dist/components/toast.d.ts +3 -2
- package/dist/components/transcript-view.d.ts +18 -2
- package/dist/components/tree.d.ts +16 -6
- package/dist/components/value-controls.d.ts +20 -4
- package/dist/{query-CJ1pSPiC.js → errors-BunUBqpA.js} +5 -176
- package/dist/errors-BunUBqpA.js.map +1 -0
- package/dist/{field-7Z4N5r5g.js → field-DeKNvGox.js} +74 -5
- package/dist/field-DeKNvGox.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +847 -332
- package/dist/index.js.map +1 -1
- package/dist/lib/choice.d.ts +29 -0
- package/dist/lib/transcript.d.ts +16 -0
- package/dist/map.js +2 -2
- package/dist/migrate/cli.d.ts +2 -0
- package/dist/migrate/stock-classes.d.ts +11 -0
- package/dist/migrate-cli.js +128 -0
- package/dist/migrate-cli.js.map +1 -0
- package/dist/panorama.js +2 -2
- package/dist/query-B934ufsW.js +209 -0
- package/dist/query-B934ufsW.js.map +1 -0
- package/dist/strata.css +6 -0
- package/dist/strata.migrate.css +224 -0
- package/dist/testing.js +2 -2
- package/dist/{theme-CFNi6WUO.js → theme-DVaIxyNn.js} +6 -75
- package/dist/theme-DVaIxyNn.js.map +1 -0
- package/dist/value-controls-FO4zQiHP.js +735 -0
- package/dist/value-controls-FO4zQiHP.js.map +1 -0
- package/package.json +7 -2
- package/dist/field-7Z4N5r5g.js.map +0 -1
- package/dist/query-CJ1pSPiC.js.map +0 -1
- package/dist/theme-CFNi6WUO.js.map +0 -1
- package/dist/value-controls-D6O9TsM6.js +0 -356
- package/dist/value-controls-D6O9TsM6.js.map +0 -1
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/* strata-react: the token contract, the namespace reset, the type steps, motion utilities and the
|
|
2
|
+
base layer. It ships no colours. A product imports it between Tailwind and its own theme:
|
|
3
|
+
|
|
4
|
+
@import "tailwindcss";
|
|
5
|
+
@import "strata-react/strata.css";
|
|
6
|
+
@import "./theme.generated.css"; (palette.mjs output: shadcn roles + 12-step ramps)
|
|
7
|
+
@import "./theme.css"; (status roles, fonts, any subject colours, with reasons)
|
|
8
|
+
|
|
9
|
+
An app that already has its own Tailwind colours and sizes imports "strata-react/strata.migrate.css"
|
|
10
|
+
instead: this file without the reset below, so its stock classes keep compiling while it moves
|
|
11
|
+
screens over (the build writes it from this file: scripts/copy-css.mjs). The README says when.
|
|
12
|
+
|
|
13
|
+
The research behind every value is in jburnhams/ux-research, ui-library/tokens.md. */
|
|
14
|
+
|
|
15
|
+
/* MIGRATION MODE (strata.migrate.css): Tailwind's stock colours, sizes, radii, shadows and fonts are NOT cleared here, so an
|
|
16
|
+
app's own `bg-stone-100` and `text-sm` keep compiling beside Strata's roles. Switch the import to strata.css once
|
|
17
|
+
`strata-stock-classes` finds nothing left. */
|
|
18
|
+
|
|
19
|
+
/* React Aria's state variants (`selected:`, `pressed:`, `hover:`, `focus-visible:`, `disabled:`, `open:`,
|
|
20
|
+
`invalid:`, `expanded:`, `sort-ascending:`…): each reads the `data-*` attribute React Aria Components
|
|
21
|
+
sets, so state is styled once where it is used and never copied into a variant map. On a plain
|
|
22
|
+
element `hover:`, `focus-visible:` and `disabled:` still mean the browser's own (the plugin only takes
|
|
23
|
+
over on elements React Aria marks with `data-rac`). The plugin is a dependency of strata-react, so an
|
|
24
|
+
app needs no install step for it. */
|
|
25
|
+
@plugin "tailwindcss-react-aria-components";
|
|
26
|
+
|
|
27
|
+
@custom-variant dark (&:is(.dark *));
|
|
28
|
+
|
|
29
|
+
/* Status roles are part of the contract but not of the generated palette: the product solves them
|
|
30
|
+
(pale tint + dark ink of one hue, ink >= 6:1 on its tint and on the ground) and sets the
|
|
31
|
+
variables in its theme. Strata only names them. Never the accent. */
|
|
32
|
+
@theme inline {
|
|
33
|
+
--color-success: var(--success);
|
|
34
|
+
--color-success-subtle: var(--success-subtle);
|
|
35
|
+
--color-warning: var(--warning);
|
|
36
|
+
--color-warning-subtle: var(--warning-subtle);
|
|
37
|
+
--color-danger: var(--danger);
|
|
38
|
+
--color-danger-subtle: var(--danger-subtle);
|
|
39
|
+
--color-info: var(--info);
|
|
40
|
+
--color-info-subtle: var(--info-subtle);
|
|
41
|
+
--color-surface-sunken: var(--surface-sunken);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@theme {
|
|
45
|
+
/* System faces until the product names its own (a later @theme block wins). One family on an
|
|
46
|
+
Operate surface; --font-display is for page titles only. */
|
|
47
|
+
--font-sans: ui-sans-serif, system-ui, sans-serif;
|
|
48
|
+
--font-mono: ui-monospace, "SFMono-Regular", Menlo, monospace;
|
|
49
|
+
--font-display: var(--font-sans);
|
|
50
|
+
|
|
51
|
+
/* Radius by role. Optical nesting: inner = outer - padding, so a control inside an 8px overlay
|
|
52
|
+
with 4px padding is 4px, never the same value as its container. */
|
|
53
|
+
--radius-control: 4px;
|
|
54
|
+
--radius-surface: 6px;
|
|
55
|
+
--radius-overlay: 8px;
|
|
56
|
+
--radius-pill: 9999px;
|
|
57
|
+
|
|
58
|
+
/* One elevation channel per surface: hairlines for things on the page, a shadow only for what
|
|
59
|
+
floats above it. */
|
|
60
|
+
--shadow-overlay: 0 1px 2px oklch(0% 0 0 / 0.08), 0 8px 24px oklch(0% 0 0 / 0.12);
|
|
61
|
+
|
|
62
|
+
/* Effects (colour, opacity) never overshoot; spatial gets Material Standard's barely visible
|
|
63
|
+
settle. Expressive springs are a product allowance, recorded in its DESIGN.md. */
|
|
64
|
+
--ease-effects: cubic-bezier(0.34, 0.8, 0.34, 1);
|
|
65
|
+
--ease-spatial: cubic-bezier(0.27, 1.06, 0.18, 1);
|
|
66
|
+
--ease-moment: cubic-bezier(0.23, 1, 0.32, 1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Non-colour defaults in the base layer, so any unlayered rule in the product's theme wins
|
|
70
|
+
regardless of import order. */
|
|
71
|
+
@layer base {
|
|
72
|
+
:root {
|
|
73
|
+
--surface-sunken: var(--neutral-2);
|
|
74
|
+
|
|
75
|
+
/* Density: control heights move together (button, input, select). */
|
|
76
|
+
--control-h: 2.5rem;
|
|
77
|
+
--control-h-sm: 2rem;
|
|
78
|
+
/* A button's side padding and icon size, a role like its height (issue #210): a second look scopes them on a class. */
|
|
79
|
+
--control-px: 1rem;
|
|
80
|
+
--control-px-sm: 0.75rem;
|
|
81
|
+
--control-icon: 1rem;
|
|
82
|
+
|
|
83
|
+
--motion-effects: 200ms;
|
|
84
|
+
--motion-spatial: 350ms;
|
|
85
|
+
/* Press feedback is the one motion on a frequent action: 100ms, 2%, felt more than seen. A
|
|
86
|
+
moment is the rare, earned one; slower, hard ease-out, no overshoot. */
|
|
87
|
+
--motion-press: 100ms;
|
|
88
|
+
--motion-moment: 500ms;
|
|
89
|
+
|
|
90
|
+
/* The page title's voice. A product with a display face sets these with it. */
|
|
91
|
+
--title-weight: 650;
|
|
92
|
+
--title-stretch: 100%;
|
|
93
|
+
--title-tracking: -0.01em;
|
|
94
|
+
}
|
|
95
|
+
.dark {
|
|
96
|
+
--surface-sunken: var(--neutral-1);
|
|
97
|
+
}
|
|
98
|
+
/* `default` exists so a region can step back to ordinary density inside a compact page. */
|
|
99
|
+
[data-density="default"] {
|
|
100
|
+
--control-h: 2.5rem;
|
|
101
|
+
--control-h-sm: 2rem;
|
|
102
|
+
}
|
|
103
|
+
[data-density="compact"] {
|
|
104
|
+
--control-h: 2rem;
|
|
105
|
+
--control-h-sm: 1.75rem;
|
|
106
|
+
}
|
|
107
|
+
/* After the density rules, so a coarse pointer always wins: every control stays a 44px target. */
|
|
108
|
+
@media (pointer: coarse) {
|
|
109
|
+
:root,
|
|
110
|
+
[data-density="default"],
|
|
111
|
+
[data-density="compact"] {
|
|
112
|
+
--control-h: 2.75rem;
|
|
113
|
+
--control-h-sm: 2.75rem;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* Type steps as utilities, not --text-* keys: a compound of size, line height and weight that
|
|
119
|
+
cn() can tell apart from text colours. Operate scale, ratio about 1.2, fixed rem; nothing above
|
|
120
|
+
28px except `type-display`, which is for Persuade surfaces only. */
|
|
121
|
+
/* Each step reads its own variables and falls back to today's value, so a product with another scale (or a
|
|
122
|
+
region with a second look) sets `--type-body-size`, `--type-body-leading`, `--type-heading-weight`… on a
|
|
123
|
+
class and every component with that step follows (issue #210). Names: --type-<step>-size, -leading, -weight. */
|
|
124
|
+
@utility type-caption { font-size: var(--type-caption-size, 0.75rem); line-height: var(--type-caption-leading, 1rem); font-weight: var(--type-caption-weight, 400); }
|
|
125
|
+
@utility type-label { font-size: var(--type-label-size, 0.875rem); line-height: var(--type-label-leading, 1.25rem); font-weight: var(--type-label-weight, 500); }
|
|
126
|
+
@utility type-body-sm { font-size: var(--type-body-sm-size, 0.875rem); line-height: var(--type-body-sm-leading, 1.25rem); font-weight: var(--type-body-sm-weight, 400); }
|
|
127
|
+
@utility type-body { font-size: var(--type-body-size, 1rem); line-height: var(--type-body-leading, 1.5rem); font-weight: var(--type-body-weight, 400); }
|
|
128
|
+
@utility type-heading { font-size: var(--type-heading-size, 1.125rem); line-height: var(--type-heading-leading, 1.5rem); font-weight: var(--type-heading-weight, 600); }
|
|
129
|
+
@utility type-title {
|
|
130
|
+
font-family: var(--font-display);
|
|
131
|
+
font-size: var(--type-title-size, 1.75rem);
|
|
132
|
+
line-height: var(--type-title-leading, 2.25rem);
|
|
133
|
+
font-weight: var(--title-weight);
|
|
134
|
+
font-stretch: var(--title-stretch);
|
|
135
|
+
letter-spacing: var(--title-tracking);
|
|
136
|
+
}
|
|
137
|
+
@utility type-figure { font-size: var(--type-figure-size, 1.75rem); line-height: var(--type-figure-leading, 2.25rem); font-weight: var(--type-figure-weight, 500); font-variant-numeric: tabular-nums; }
|
|
138
|
+
@utility type-display {
|
|
139
|
+
font-family: var(--font-display);
|
|
140
|
+
font-size: clamp(2.25rem, 1.5rem + 3vw, 4rem);
|
|
141
|
+
line-height: 1.05;
|
|
142
|
+
font-weight: var(--title-weight);
|
|
143
|
+
font-stretch: var(--title-stretch);
|
|
144
|
+
letter-spacing: -0.02em;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* State transitions: named properties only (never `transition: all`). `scale` is listed for the
|
|
148
|
+
press feedback and runs at the shorter press duration. */
|
|
149
|
+
@utility transition-state {
|
|
150
|
+
transition-property: color, background-color, border-color, opacity, box-shadow, scale;
|
|
151
|
+
transition-duration: var(--motion-effects), var(--motion-effects), var(--motion-effects), var(--motion-effects),
|
|
152
|
+
var(--motion-effects), var(--motion-press);
|
|
153
|
+
transition-timing-function: var(--ease-effects);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* Press feedback: 2% is the most a control used tens of times a day can move without feeling slow. */
|
|
157
|
+
@utility press {
|
|
158
|
+
&:active:not(:disabled) { scale: 0.98; }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* A moment's entrance: CSS only, runs once when the element mounts. Reduced motion collapses it. */
|
|
162
|
+
@utility enter-moment {
|
|
163
|
+
transition-property: opacity, translate;
|
|
164
|
+
transition-duration: var(--motion-moment);
|
|
165
|
+
transition-timing-function: var(--ease-moment);
|
|
166
|
+
@starting-style { opacity: 0; translate: 0 -0.75rem; }
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* Stacking, once, for every floating thing, so an app never writes a z-index. A bar (the undo
|
|
170
|
+
bar, toasts) sits above panes and sticky headers; overlays (dialogs, popovers, menus) above
|
|
171
|
+
bars; a tooltip above everything, since it can name a control inside an overlay. */
|
|
172
|
+
@utility layer-bar { z-index: 50; }
|
|
173
|
+
@utility layer-overlay { z-index: 60; }
|
|
174
|
+
@utility layer-tip { z-index: 70; }
|
|
175
|
+
|
|
176
|
+
/* The dim behind a dialog or full-screen view. Black at an alpha, not the foreground role: in a dark
|
|
177
|
+
theme `foreground` is light, so a foreground scrim brightened the page instead of dimming it
|
|
178
|
+
(strata-react issue #136). Not a theme role, so no app has anything to add; darker in the dark
|
|
179
|
+
scheme, where the same alpha would barely show. */
|
|
180
|
+
@utility scrim {
|
|
181
|
+
background-color: rgb(0 0 0 / 0.4);
|
|
182
|
+
:where(.dark) & { background-color: rgb(0 0 0 / 0.65); }
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/* An overlay's entrance: an ordinary effect (fade and 2% scale), CSS only, once on mount. Overlays
|
|
186
|
+
are occasional (character.md), so the effects duration and no overshoot; they close at once.
|
|
187
|
+
Reduced motion collapses it in the rule below. */
|
|
188
|
+
@utility enter-overlay {
|
|
189
|
+
transition-property: opacity, scale;
|
|
190
|
+
transition-duration: var(--motion-effects);
|
|
191
|
+
transition-timing-function: var(--ease-effects);
|
|
192
|
+
@starting-style { opacity: 0; scale: 0.98; }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
@layer base {
|
|
196
|
+
html { color-scheme: light; }
|
|
197
|
+
.dark { color-scheme: dark; }
|
|
198
|
+
body {
|
|
199
|
+
background-color: var(--background);
|
|
200
|
+
color: var(--foreground);
|
|
201
|
+
font-family: var(--font-sans);
|
|
202
|
+
font-size: 1rem;
|
|
203
|
+
line-height: 1.5rem;
|
|
204
|
+
-webkit-font-smoothing: antialiased;
|
|
205
|
+
}
|
|
206
|
+
/* One focus treatment for everything focusable, so no component can forget it. */
|
|
207
|
+
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
|
|
208
|
+
/* Except where a script moved focus to a heading to announce a result (Done): the heading is not
|
|
209
|
+
a control, so a ring around it says "press me" to nobody. */
|
|
210
|
+
h1[tabindex="-1"]:focus-visible, h2[tabindex="-1"]:focus-visible { outline: none; }
|
|
211
|
+
::selection { background-color: var(--primary-5); color: var(--foreground); }
|
|
212
|
+
a { text-underline-offset: 0.2em; }
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
@media (prefers-reduced-motion: reduce) {
|
|
216
|
+
*, *::before, *::after {
|
|
217
|
+
animation-duration: 0.01ms !important;
|
|
218
|
+
animation-iteration-count: 1 !important;
|
|
219
|
+
transition-duration: 0.01ms !important;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/* The built components, so their classes are generated. */
|
|
224
|
+
@source "./*.js";
|
package/dist/testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as toast, n as createQueryClient, s as StrataToastRegion, t as StrataQueryProvider } from "./query-
|
|
2
|
-
import { r as ThemeProvider } from "./theme-
|
|
1
|
+
import { c as toast, n as createQueryClient, s as StrataToastRegion, t as StrataQueryProvider } from "./query-B934ufsW.js";
|
|
2
|
+
import { r as ThemeProvider } from "./theme-DVaIxyNn.js";
|
|
3
3
|
import "react";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { MemoryRouter, RouterProvider, createMemoryRouter } from "react-router";
|
|
@@ -1,77 +1,8 @@
|
|
|
1
|
-
import { c as
|
|
1
|
+
import { c as Tooltip$1, t as ChoiceGroup, u as cn } from "./field-DeKNvGox.js";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import { Radio, RadioGroup
|
|
4
|
-
import {
|
|
5
|
-
import { Fragment, jsx
|
|
6
|
-
// src/components/key-glyphs.tsx
|
|
7
|
-
var GLYPHS = {
|
|
8
|
-
"←": {
|
|
9
|
-
icon: ArrowLeft,
|
|
10
|
-
name: "left arrow"
|
|
11
|
-
},
|
|
12
|
-
"→": {
|
|
13
|
-
icon: ArrowRight,
|
|
14
|
-
name: "right arrow"
|
|
15
|
-
},
|
|
16
|
-
"↑": {
|
|
17
|
-
icon: ArrowUp,
|
|
18
|
-
name: "up arrow"
|
|
19
|
-
},
|
|
20
|
-
"↓": {
|
|
21
|
-
icon: ArrowDown,
|
|
22
|
-
name: "down arrow"
|
|
23
|
-
},
|
|
24
|
-
"⌘": {
|
|
25
|
-
icon: Command,
|
|
26
|
-
name: "Command"
|
|
27
|
-
},
|
|
28
|
-
"⌃": {
|
|
29
|
-
icon: ChevronUp,
|
|
30
|
-
name: "Control"
|
|
31
|
-
},
|
|
32
|
-
"⌥": {
|
|
33
|
-
icon: Option,
|
|
34
|
-
name: "Option"
|
|
35
|
-
},
|
|
36
|
-
"⇧": {
|
|
37
|
-
icon: ArrowBigUp,
|
|
38
|
-
name: "Shift"
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var PATTERN = new RegExp(`([${Object.keys(GLYPHS).join("")}])`);
|
|
42
|
-
/** Key text with its arrows and modifier symbols drawn as icons, each with its name for screen readers. Other text is left as it is. */
|
|
43
|
-
function KeyText({ children }) {
|
|
44
|
-
return /* @__PURE__ */ jsx(Fragment, { children: children.split(PATTERN).map((part, i) => {
|
|
45
|
-
const glyph = GLYPHS[part];
|
|
46
|
-
if (!glyph) return part ? /* @__PURE__ */ jsx(React.Fragment, { children: part }, i) : null;
|
|
47
|
-
const Icon = glyph.icon;
|
|
48
|
-
return /* @__PURE__ */ jsxs(React.Fragment, { children: [/* @__PURE__ */ jsx(Icon, {
|
|
49
|
-
"aria-hidden": true,
|
|
50
|
-
className: "inline size-[1em] align-[-0.125em]"
|
|
51
|
-
}), /* @__PURE__ */ jsxs("span", {
|
|
52
|
-
className: "sr-only",
|
|
53
|
-
children: [glyph.name, " "]
|
|
54
|
-
})] }, i);
|
|
55
|
-
}) });
|
|
56
|
-
}
|
|
57
|
-
// src/components/tooltip.tsx
|
|
58
|
-
/** A hover-and-focus tooltip for a control, portalled above everything. Words only; not the only home of information. */
|
|
59
|
-
function Tooltip$1({ label, hint, children, side = "top", delay = 500, open, className }) {
|
|
60
|
-
return /* @__PURE__ */ jsxs(TooltipTrigger, {
|
|
61
|
-
delay,
|
|
62
|
-
closeDelay: 0,
|
|
63
|
-
isOpen: open,
|
|
64
|
-
children: [children, /* @__PURE__ */ jsxs(Tooltip, {
|
|
65
|
-
placement: side,
|
|
66
|
-
offset: 6,
|
|
67
|
-
className: cn("layer-tip enter-overlay max-w-xs rounded-control bg-foreground px-2 py-1 type-caption text-background", className),
|
|
68
|
-
children: [label, hint != null && /* @__PURE__ */ jsx("span", {
|
|
69
|
-
className: "ml-2 opacity-70",
|
|
70
|
-
children: typeof hint === "string" ? /* @__PURE__ */ jsx(KeyText, { children: hint }) : hint
|
|
71
|
-
})]
|
|
72
|
-
})]
|
|
73
|
-
});
|
|
74
|
-
}
|
|
3
|
+
import { Radio, RadioGroup } from "react-aria-components";
|
|
4
|
+
import { Monitor, Moon, Sun } from "lucide-react";
|
|
5
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
75
6
|
// src/components/density.tsx
|
|
76
7
|
/** The density attribute's page-level setter, shared by `ThemeProvider`. @internal */
|
|
77
8
|
function useDensityOn(value, target) {
|
|
@@ -258,6 +189,6 @@ function ColorSchemeChoice({ legend, labels = defaultLabels, compact = false, cl
|
|
|
258
189
|
}))
|
|
259
190
|
});
|
|
260
191
|
}
|
|
261
|
-
export { useColorScheme as a,
|
|
192
|
+
export { useColorScheme as a, colorSchemeScript as i, ColorSchemeChoice as n, useSystemColorScheme as o, ThemeProvider as r, Density as s, COLOR_SCHEME_STORAGE_KEY as t };
|
|
262
193
|
|
|
263
|
-
//# sourceMappingURL=theme-
|
|
194
|
+
//# sourceMappingURL=theme-DVaIxyNn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-DVaIxyNn.js","names":["_Fragment","Tooltip"],"sources":["../src/components/density.tsx","../src/components/theme.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../lib/utils\";\n\n// Density is how much a screen packs in: `default` for forms and pages, `compact` for a tool screen\n// worked for hours (an editor, an inspector, a timeline). strata.css moves --control-h and\n// --control-h-sm together on `[data-density]`; this is how an app says which (issue #117, from\n// strata-vid, whose export dialog came out at default density over a compact editor).\n//\n// There are two places it can live, and they are different on purpose:\n// - the page (`ThemeProvider density` or `<Density page>`): the attribute goes on the document's\n// root element, so everything Strata renders sees it, including `Dialog`, `Menu`, `ContextMenu`,\n// `Popover` and `CommandMenu`, which portal to <body> and so are never inside the app's own root.\n// An app chooses it once, here.\n// - a region (`<Density value=\"compact\">`): a wrapper element, for a dense inspector inside an\n// ordinary app. Its overlays portal out of it and stay at the page's density, which is right: a\n// confirm opened from a dense panel is still the app's confirm.\n//\n// `default` exists as a value so a region can step back inside a compact page. A coarse pointer\n// still gets 44px targets in every density (strata.css).\n\n/** How much a screen packs in: `default`, or `compact` for a tool screen. */\nexport type DensityName = \"default\" | \"compact\";\n\n/** The density attribute's page-level setter, shared by `ThemeProvider`. @internal */\nexport function useDensityOn(value: DensityName | undefined, target?: HTMLElement | null) {\n React.useLayoutEffect(() => {\n if (value === undefined) return;\n const element = target === undefined ? document.documentElement : target;\n if (!element) return;\n const before = element.getAttribute(\"data-density\");\n element.setAttribute(\"data-density\", value);\n return () => {\n if (before === null) element.removeAttribute(\"data-density\");\n else element.setAttribute(\"data-density\", before);\n };\n }, [value, target]);\n}\n\n/** Props for `Density`. */\nexport type DensityProps = {\n value: DensityName;\n /** Set it on the document's root element for the whole page, overlays included, instead of wrapping a region. Renders only its children. */\n page?: boolean;\n /** For the wrapper of a region: layout classes (the wrapper is a plain `div`; `contents` takes it out of layout). */\n className?: string;\n children?: React.ReactNode;\n};\n\n/** Sets the density of a region (a wrapper `div`), or of the whole page with `page`, where overlays are reached too. */\nexport function Density({ value, page = false, className, children }: DensityProps) {\n useDensityOn(page ? value : undefined);\n if (page) return <>{children}</>;\n return (\n <div data-density={value} className={cn(className)}>\n {children}\n </div>\n );\n}\n","import * as React from \"react\";\nimport { useDensityOn, type DensityName } from \"./density\";\nimport { Radio, RadioGroup } from \"react-aria-components\";\nimport { Tooltip } from \"./tooltip\";\nimport { Monitor, Moon, Sun } from \"lucide-react\";\nimport type { IconComponent } from \"../lib/icon\";\nimport { cn } from \"../lib/utils\";\nimport { ChoiceGroup } from \"./field\";\n\n// strata.css keys dark mode on a `.dark` ancestor (`@custom-variant dark (&:is(.dark *))`) and\n// gives `.dark` its `color-scheme`, but nothing in the library set the class, so every app wrote\n// the same matchMedia listener by hand (strata-listory did, in web/src/main.tsx). This is that\n// listener, once:\n// - Three choices, not two. \"system\" follows the operating system and keeps following it when it\n// changes at dusk; \"light\" and \"dark\" are a person's override. A toggle with only light and dark\n// loses the system setting the first time it is pressed.\n// - The choice persists in localStorage, read and written inside try/catch. Storage throws in\n// private windows, with blocked site data and in sandboxed frames; the theme then simply does\n// not persist, and the page still renders. A stored value that is not one of the three is\n// ignored.\n// - Another tab changing the choice changes this one too (the `storage` event).\n// - The first render uses the default preference, as a server render would, and the stored choice\n// is applied in a layout effect, so server-rendered markup hydrates cleanly and nothing paints\n// with the wrong scheme (found in review).\n// - The class is set in a layout effect, before paint. A page that must not flash light on first\n// load before React runs puts `colorSchemeScript()` in an inline script in its `<head>`.\n// - `ColorSchemeChoice` is the picker for a settings page: a `ChoiceGroup` of the three, with\n// \"Match this device\" first because it is the default and the one most people should keep. A\n// product that wants the choice elsewhere (a menu item, a header button) builds it from\n// `useColorScheme`. Changing theme is rare, so the picker has no motion and no icon flourish.\n// - `compact` is the same choice for an app with no settings page (a homepage, a single-page\n// tool), sized to sit in a header or footer: three segments with an icon each, named\n// \"Appearance\" (strata-react issue #25). They are still native radio buttons, so arrow keys move\n// the choice and a screen reader hears \"Match this device, radio button, 1 of 3, Appearance\".\n// Each segment is named by `aria-label` on its radio and shows the same words as a tooltip; the\n// icons are the familiar three (screen, sun, moon), and none of them is a toggle that loses the\n// system setting. The visible words are left out only because the icons are that well known.\n// - Storybook's decorator and `renderWithStrata({ colorScheme })` run through this provider, so\n// stories and tests see the same class, in the same place, as an app.\n\n/** What a person chose: follow the operating system, or a fixed light or dark theme. */\nexport type ColorSchemePreference = \"system\" | \"light\" | \"dark\";\n/** The scheme in effect after \"system\" is resolved. */\nexport type ColorScheme = \"light\" | \"dark\";\n\n/** The localStorage key `ThemeProvider` uses unless given another. */\nexport const COLOR_SCHEME_STORAGE_KEY = \"strata-color-scheme\";\n\nconst QUERY = \"(prefers-color-scheme: dark)\";\nconst PREFERENCES: readonly ColorSchemePreference[] = [\"system\", \"light\", \"dark\"];\n\nfunction isPreference(value: unknown): value is ColorSchemePreference {\n return typeof value === \"string\" && (PREFERENCES as readonly string[]).includes(value);\n}\n\nfunction readStored(key: string | null): ColorSchemePreference | null {\n if (key === null) return null;\n try {\n const value = window.localStorage.getItem(key);\n return isPreference(value) ? value : null;\n } catch {\n return null;\n }\n}\n\nfunction writeStored(key: string | null, value: ColorSchemePreference) {\n if (key === null) return;\n try {\n window.localStorage.setItem(key, value);\n } catch {\n // Storage unavailable (private window, blocked site data): the choice lasts this visit only.\n }\n}\n\nfunction media(): MediaQueryList | null {\n return typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" ? window.matchMedia(QUERY) : null;\n}\n\nfunction subscribeSystem(onChange: () => void) {\n const list = media();\n if (!list) return () => undefined;\n list.addEventListener(\"change\", onChange);\n return () => list.removeEventListener(\"change\", onChange);\n}\n\nconst systemSnapshot = (): ColorScheme => (media()?.matches ? \"dark\" : \"light\");\nconst serverSnapshot = (): ColorScheme => \"light\";\n\n/** The operating system's colour scheme, kept current as it changes. Light where it cannot be read (the server, jsdom). */\nexport function useSystemColorScheme(): ColorScheme {\n return React.useSyncExternalStore(subscribeSystem, systemSnapshot, serverSnapshot);\n}\n\n/** What `useColorScheme` returns: the chosen preference, the scheme in effect, and a setter that persists the choice. */\nexport type ColorSchemeState = {\n preference: ColorSchemePreference;\n scheme: ColorScheme;\n setPreference: (preference: ColorSchemePreference) => void;\n};\n\nconst Context = React.createContext<ColorSchemeState | null>(null);\n\n/** Sets the `.dark` class strata.css keys on, from a system, light or dark preference that persists in localStorage when it can. */\nexport function ThemeProvider({\n children,\n defaultPreference = \"system\",\n storageKey = COLOR_SCHEME_STORAGE_KEY,\n target,\n density,\n}: {\n children: React.ReactNode;\n /** The preference before a person has chosen one. */\n defaultPreference?: ColorSchemePreference;\n /** Where the choice is kept in localStorage; `null` keeps it for this visit only. */\n storageKey?: string | null;\n /**\n * The element that gets the `.dark` class; the document's root element when left out. A nested\n * target can turn a light page's panel dark, not the reverse: strata.css keys dark on any\n * `.dark` ancestor. Pass the element itself (keep it in state with a callback ref, since a\n * wrapping element's ref is not attached yet when this provider's effect first runs); `null`\n * means it has not mounted yet, and nothing is set until it has.\n */\n target?: HTMLElement | null;\n /**\n * How much the screen packs in, set on the same element as the colour scheme (the root, so\n * overlays are reached): `compact` for a tool screen. See `Density`. Left out, nothing is set.\n */\n density?: DensityName;\n}) {\n // The first render uses the default, as the server does, so a server-rendered tree hydrates\n // without a mismatch; the stored choice is read in a layout effect, which re-renders before the\n // browser paints, so a client-only app still never shows the default first.\n const [preference, setState] = React.useState<ColorSchemePreference>(defaultPreference);\n React.useLayoutEffect(() => {\n const stored = readStored(storageKey);\n if (stored) setState(stored);\n }, [storageKey]);\n const system = useSystemColorScheme();\n const scheme: ColorScheme = preference === \"system\" ? system : preference;\n\n const setPreference = React.useCallback(\n (next: ColorSchemePreference) => {\n setState(next);\n writeStored(storageKey, next);\n },\n [storageKey],\n );\n\n // Another tab changed the choice. A cleared key (`newValue` null) falls back to the default.\n React.useEffect(() => {\n if (storageKey === null) return;\n const onStorage = (event: StorageEvent) => {\n if (event.key !== storageKey && event.key !== null) return;\n const value = event.key === null ? null : event.newValue;\n setState(isPreference(value) ? value : defaultPreference);\n };\n window.addEventListener(\"storage\", onStorage);\n return () => window.removeEventListener(\"storage\", onStorage);\n }, [storageKey, defaultPreference]);\n\n React.useLayoutEffect(() => {\n const element = target === undefined ? document.documentElement : target;\n if (!element) return;\n element.classList.toggle(\"dark\", scheme === \"dark\");\n return () => element.classList.remove(\"dark\");\n }, [scheme, target]);\n\n useDensityOn(density, target);\n\n const value = React.useMemo(() => ({ preference, scheme, setPreference }), [preference, scheme, setPreference]);\n return <Context.Provider value={value}>{children}</Context.Provider>;\n}\n\n/** The person's colour-scheme preference, the scheme in effect, and a setter that persists it. Must be inside `ThemeProvider`. */\nexport function useColorScheme(): ColorSchemeState {\n const value = React.useContext(Context);\n if (!value) throw new Error(\"useColorScheme must be used inside a ThemeProvider.\");\n return value;\n}\n\n/**\n * The body of an inline `<script>` for the page's `<head>` that sets `.dark` before the first\n * paint, from the stored choice or the operating system, so a dark page does not flash light while\n * the bundle loads. Pass the same key and default as the `ThemeProvider`.\n */\nexport function colorSchemeScript(\n storageKey: string = COLOR_SCHEME_STORAGE_KEY,\n defaultPreference: ColorSchemePreference = \"system\",\n): string {\n const key = JSON.stringify(storageKey);\n const fallback = JSON.stringify(defaultPreference);\n return (\n `(function(){var p=${fallback};try{var s=localStorage.getItem(${key});` +\n `if(s===\"system\"||s===\"light\"||s===\"dark\")p=s}catch(e){}` +\n `var d=p===\"dark\"||(p===\"system\"&&window.matchMedia&&matchMedia(${JSON.stringify(QUERY)}).matches);` +\n `document.documentElement.classList.toggle(\"dark\",!!d)})()`\n );\n}\n\n/** The words `ColorSchemeChoice` shows for each preference. */\nexport type ColorSchemeLabels = Record<ColorSchemePreference, { label: string; detail?: string }>;\n\nconst defaultLabels: ColorSchemeLabels = {\n system: { label: \"Match this device\", detail: \"Light or dark as your system setting changes\" },\n light: { label: \"Light\" },\n dark: { label: \"Dark\" },\n};\n\nconst icons: Record<ColorSchemePreference, IconComponent> = { system: Monitor, light: Sun, dark: Moon };\n\n/** The three colour-scheme preferences as radio buttons, bound to the nearest `ThemeProvider`. A list for a settings page, or `compact` icon segments named \"Appearance\" for a header. */\nexport function ColorSchemeChoice({\n legend,\n labels = defaultLabels,\n compact = false,\n className,\n}: {\n /** The group's name, as the page words it. Defaults to \"Theme\", or \"Appearance\" when `compact`. */\n legend?: string;\n /** Overrides the words for each choice, in the product's voice. */\n labels?: Partial<ColorSchemeLabels>;\n /** Three icon segments for a header or footer, for an app with no settings page. */\n compact?: boolean;\n /** Layout at the call site (compact only). */\n className?: string;\n}) {\n const { preference, setPreference } = useColorScheme();\n const name = React.useId();\n const words = { ...defaultLabels, ...labels };\n if (compact) {\n return (\n <RadioGroup\n aria-label={legend ?? \"Appearance\"}\n orientation=\"horizontal\"\n name={name}\n value={preference}\n onChange={(value) => {\n if (isPreference(value)) setPreference(value);\n }}\n className={cn(\"inline-flex gap-0.5 rounded-surface border border-border bg-background p-0.5\", className)}\n >\n {PREFERENCES.map((value) => {\n const Icon = icons[value];\n return (\n <Tooltip key={value} label={words[value].label}>\n <Radio\n value={value}\n aria-label={words[value].label}\n className={cn(\n // Outer 6px less 2px padding: the segments are 4px, as optical nesting asks.\n \"grid size-(--control-h-sm) cursor-pointer place-items-center rounded-control text-muted-foreground transition-state\",\n \"hover:text-foreground selected:bg-muted selected:text-foreground\",\n \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring\",\n )}\n >\n <Icon aria-hidden className=\"size-4\" />\n </Radio>\n </Tooltip>\n );\n })}\n </RadioGroup>\n );\n }\n return (\n <ChoiceGroup\n legend={legend ?? \"Theme\"}\n name={name}\n value={preference}\n onChange={(value) => {\n if (isPreference(value)) setPreference(value);\n }}\n choices={PREFERENCES.map((value) => ({ value, ...words[value] }))}\n />\n );\n}\n"],"mappings":";;;;;;;AAwBA,SAAgB,aAAa,OAAgC,QAA6B;CACxF,MAAM,sBAAsB;EAC1B,IAAI,UAAU,KAAA,GAAW;EACzB,MAAM,UAAU,WAAW,KAAA,IAAY,SAAS,kBAAkB;EAClE,IAAI,CAAC,SAAS;EACd,MAAM,SAAS,QAAQ,aAAa,cAAc;EAClD,QAAQ,aAAa,gBAAgB,KAAK;EAC1C,aAAa;GACX,IAAI,WAAW,MAAM,QAAQ,gBAAgB,cAAc;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