strata-react 1.0.33 → 1.0.36
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 +13 -3
- package/UPGRADING.md +2 -0
- package/dist/components/compare-parts.d.ts +16 -0
- package/dist/components/compare-video-grid.d.ts +5 -1
- package/dist/components/compare-video.d.ts +12 -1
- package/dist/components/compare.d.ts +8 -1
- package/dist/components/conversation.d.ts +67 -0
- package/dist/components/dialog.d.ts +1 -1
- package/dist/components/folder-picker.d.ts +42 -0
- package/dist/components/lightbox.d.ts +34 -0
- package/dist/components/markable-text.d.ts +56 -0
- package/dist/components/media-group.d.ts +25 -0
- package/dist/components/media-player.d.ts +80 -2
- package/dist/components/pair-vote.d.ts +3 -2
- package/dist/components/region-editor.d.ts +55 -0
- package/dist/components/sequence-timeline.d.ts +50 -0
- package/dist/components/transcript-view.d.ts +36 -0
- package/dist/components/tree.d.ts +41 -0
- package/dist/components/video-clock.d.ts +9 -1
- package/dist/components/viewport.d.ts +22 -0
- package/dist/components/waveform.d.ts +66 -0
- package/dist/{cursor-DplHNzj3.js → cursor-DDGBPiTJ.js} +2 -200
- package/dist/cursor-DDGBPiTJ.js.map +1 -0
- package/dist/field-7Z4N5r5g.js +178 -0
- package/dist/field-7Z4N5r5g.js.map +1 -0
- package/dist/format-B32-PVi2.js +201 -0
- package/dist/format-B32-PVi2.js.map +1 -0
- package/dist/hls/index.d.ts +19 -0
- package/dist/hls.js +84 -0
- package/dist/hls.js.map +1 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +3646 -584
- package/dist/index.js.map +1 -1
- package/dist/lib/marks.d.ts +6 -0
- package/dist/lib/region.d.ts +46 -0
- package/dist/lib/rich-text.d.ts +44 -0
- package/dist/lib/sequence.d.ts +34 -0
- package/dist/lib/transcript.d.ts +28 -0
- package/dist/lib/waveform.d.ts +36 -0
- package/dist/map.js +4 -2
- package/dist/map.js.map +1 -1
- package/dist/panorama/gl.d.ts +16 -0
- package/dist/panorama/index.d.ts +2 -0
- package/dist/panorama/panorama-viewer.d.ts +56 -0
- package/dist/panorama/projection.d.ts +45 -0
- package/dist/panorama.js +657 -0
- package/dist/panorama.js.map +1 -0
- package/dist/{query-DgJMyXTT.js → query-BJcxJLhh.js} +3 -2
- package/dist/{query-DgJMyXTT.js.map → query-BJcxJLhh.js.map} +1 -1
- package/dist/{run-BqZGKhW9.js → run-DzyLrZlA.js} +23 -5
- package/dist/run-DzyLrZlA.js.map +1 -0
- package/dist/testing.js +2 -2
- package/dist/{theme-BgTOESmN.js → theme-CFNi6WUO.js} +5 -175
- package/dist/theme-CFNi6WUO.js.map +1 -0
- package/dist/value-controls-D6O9TsM6.js +356 -0
- package/dist/value-controls-D6O9TsM6.js.map +1 -0
- package/dist/visual-cli.js +1 -1
- package/dist/visual.js +1 -1
- package/package.json +19 -4
- package/dist/cursor-DplHNzj3.js.map +0 -1
- package/dist/run-BqZGKhW9.js.map +0 -1
- package/dist/theme-BgTOESmN.js.map +0 -1
|
@@ -1,33 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { extendTailwindMerge } from "tailwind-merge";
|
|
1
|
+
import { c as cn, t as ChoiceGroup } from "./field-7Z4N5r5g.js";
|
|
3
2
|
import * as React from "react";
|
|
4
|
-
import {
|
|
5
|
-
import { ArrowBigUp, ArrowDown, ArrowLeft, ArrowRight, ArrowUp, ChevronUp,
|
|
3
|
+
import { Radio, RadioGroup, Tooltip, TooltipTrigger } from "react-aria-components";
|
|
4
|
+
import { ArrowBigUp, ArrowDown, ArrowLeft, ArrowRight, ArrowUp, ChevronUp, Command, Monitor, Moon, Option, Sun } from "lucide-react";
|
|
6
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
-
// src/lib/utils.ts
|
|
8
|
-
var typeSteps = [
|
|
9
|
-
"caption",
|
|
10
|
-
"label",
|
|
11
|
-
"body-sm",
|
|
12
|
-
"body",
|
|
13
|
-
"heading",
|
|
14
|
-
"title",
|
|
15
|
-
"figure",
|
|
16
|
-
"display"
|
|
17
|
-
];
|
|
18
|
-
var twMerge = extendTailwindMerge({ extend: {
|
|
19
|
-
theme: { radius: [...[
|
|
20
|
-
"control",
|
|
21
|
-
"surface",
|
|
22
|
-
"overlay",
|
|
23
|
-
"pill"
|
|
24
|
-
]] },
|
|
25
|
-
classGroups: { "font-size": [{ type: [...typeSteps] }] }
|
|
26
|
-
} });
|
|
27
|
-
/** clsx + tailwind-merge, taught that `type-*` utilities are font sizes and `rounded-control`, `-surface`, `-overlay`, `-pill` are radii. */
|
|
28
|
-
function cn(...inputs) {
|
|
29
|
-
return twMerge(clsx(inputs));
|
|
30
|
-
}
|
|
31
6
|
// src/components/key-glyphs.tsx
|
|
32
7
|
var GLYPHS = {
|
|
33
8
|
"←": {
|
|
@@ -97,151 +72,6 @@ function Tooltip$1({ label, hint, children, side = "top", delay = 500, open, cla
|
|
|
97
72
|
})]
|
|
98
73
|
});
|
|
99
74
|
}
|
|
100
|
-
// src/lib/control.ts
|
|
101
|
-
/** The height class of each control size. */
|
|
102
|
-
var controlHeight = {
|
|
103
|
-
default: "h-(--control-h)",
|
|
104
|
-
sm: "h-(--control-h-sm)"
|
|
105
|
-
};
|
|
106
|
-
// src/components/field.tsx
|
|
107
|
-
var FieldContext = React.createContext(null);
|
|
108
|
-
/** @internal The surrounding Field, and where a control reports its own message. */
|
|
109
|
-
function useFieldControl() {
|
|
110
|
-
const field = React.useContext(FieldContext);
|
|
111
|
-
return {
|
|
112
|
-
field,
|
|
113
|
-
report: field?.report ?? noReport
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function useField(id) {
|
|
117
|
-
const field = React.useContext(FieldContext);
|
|
118
|
-
return {
|
|
119
|
-
id: field?.id ?? id,
|
|
120
|
-
"aria-describedby": field?.describedBy,
|
|
121
|
-
"aria-invalid": field?.invalid || void 0
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
var noReport = () => {};
|
|
125
|
-
/** A labelled form field: wires the label, hint, error, `aria-describedby` and `aria-invalid` into the one control it wraps. */
|
|
126
|
-
function Field({ label, id: idProp, hint, error, action, children, className }) {
|
|
127
|
-
const generated = React.useId();
|
|
128
|
-
const id = idProp ?? generated;
|
|
129
|
-
const hintId = hint ? `${id}-hint` : void 0;
|
|
130
|
-
const [reported, report] = React.useState();
|
|
131
|
-
const shown = error ?? reported;
|
|
132
|
-
const errorId = shown ? `${id}-error` : void 0;
|
|
133
|
-
const describedBy = [errorId, hintId].filter(Boolean).join(" ") || void 0;
|
|
134
|
-
return /* @__PURE__ */ jsx(FieldContext.Provider, {
|
|
135
|
-
value: {
|
|
136
|
-
id,
|
|
137
|
-
label,
|
|
138
|
-
describedBy,
|
|
139
|
-
invalid: Boolean(shown),
|
|
140
|
-
report
|
|
141
|
-
},
|
|
142
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
143
|
-
className: cn("grid min-w-0 content-start gap-1.5", className),
|
|
144
|
-
children: [
|
|
145
|
-
/* @__PURE__ */ jsx("label", {
|
|
146
|
-
htmlFor: id,
|
|
147
|
-
className: "type-label text-foreground",
|
|
148
|
-
children: label
|
|
149
|
-
}),
|
|
150
|
-
action ? /* @__PURE__ */ jsxs("div", {
|
|
151
|
-
className: "flex flex-wrap items-start gap-2",
|
|
152
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
153
|
-
className: "min-w-40 flex-1",
|
|
154
|
-
children
|
|
155
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
156
|
-
className: "flex shrink-0 items-center",
|
|
157
|
-
children: action
|
|
158
|
-
})]
|
|
159
|
-
}) : children,
|
|
160
|
-
shown && /* @__PURE__ */ jsxs("p", {
|
|
161
|
-
id: errorId,
|
|
162
|
-
className: "flex items-start gap-1.5 type-body-sm text-danger",
|
|
163
|
-
children: [/* @__PURE__ */ jsx(CircleAlert, {
|
|
164
|
-
"aria-hidden": true,
|
|
165
|
-
className: "mt-0.5 size-4 shrink-0"
|
|
166
|
-
}), shown]
|
|
167
|
-
}),
|
|
168
|
-
hint && /* @__PURE__ */ jsx("p", {
|
|
169
|
-
id: hintId,
|
|
170
|
-
className: "type-body-sm text-muted-foreground",
|
|
171
|
-
children: hint
|
|
172
|
-
})
|
|
173
|
-
]
|
|
174
|
-
})
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
var control = "w-full min-w-0 rounded-control border border-input bg-background px-3 type-body text-foreground transition-state placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-70 aria-invalid:border-danger";
|
|
178
|
-
/** A text input that picks up its id and descriptions from the surrounding `Field`. `size="sm"` is --control-h-sm; the native `size` (a width in characters) is not passed on. */
|
|
179
|
-
function Input$1({ className, id, size = "default", ...props }) {
|
|
180
|
-
return /* @__PURE__ */ jsx("input", {
|
|
181
|
-
...useField(id),
|
|
182
|
-
className: cn(control, controlHeight[size], className),
|
|
183
|
-
...props
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
/** A multi-line input that picks up its id and descriptions from the surrounding `Field`. */
|
|
187
|
-
function Textarea({ className, id, ...props }) {
|
|
188
|
-
return /* @__PURE__ */ jsx("textarea", {
|
|
189
|
-
...useField(id),
|
|
190
|
-
className: cn(control, "min-h-24 py-2", className),
|
|
191
|
-
...props
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
/** The platform select, styled. The default for short lists, especially on touch screens. `size="sm"` is --control-h-sm. */
|
|
195
|
-
function NativeSelect({ className, id, size = "default", ...props }) {
|
|
196
|
-
return /* @__PURE__ */ jsx("select", {
|
|
197
|
-
...useField(id),
|
|
198
|
-
className: cn(control, controlHeight[size], "pr-8", className),
|
|
199
|
-
...props
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
/** Radio choices in a fieldset with a legend; each whole row is the hit target. For 2 to 5 options that each need a sentence. */
|
|
203
|
-
function ChoiceGroup({ legend, name, choices, value, onChange, error }) {
|
|
204
|
-
const errorId = React.useId();
|
|
205
|
-
return /* @__PURE__ */ jsxs(RadioGroup, {
|
|
206
|
-
name,
|
|
207
|
-
value,
|
|
208
|
-
onChange,
|
|
209
|
-
"aria-describedby": error ? errorId : void 0,
|
|
210
|
-
className: "grid gap-2",
|
|
211
|
-
children: [
|
|
212
|
-
/* @__PURE__ */ jsx(Label, {
|
|
213
|
-
className: "mb-1.5 type-label text-foreground",
|
|
214
|
-
children: legend
|
|
215
|
-
}),
|
|
216
|
-
choices.map((c) => /* @__PURE__ */ jsxs(Radio, {
|
|
217
|
-
value: c.value,
|
|
218
|
-
className: "group flex min-h-(--control-h-sm) cursor-pointer items-start gap-3 py-1",
|
|
219
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
220
|
-
"aria-hidden": true,
|
|
221
|
-
className: "mt-1 grid size-4 shrink-0 place-items-center rounded-pill border border-input bg-background transition-state group-selected:border-primary group-focus-visible:outline-2 group-focus-visible:outline-offset-2 group-focus-visible:outline-ring",
|
|
222
|
-
children: /* @__PURE__ */ jsx("span", { className: "size-2 rounded-pill bg-primary opacity-0 group-selected:opacity-100" })
|
|
223
|
-
}), /* @__PURE__ */ jsxs("span", {
|
|
224
|
-
className: "grid",
|
|
225
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
226
|
-
className: "type-body",
|
|
227
|
-
children: c.label
|
|
228
|
-
}), c.detail && /* @__PURE__ */ jsx("span", {
|
|
229
|
-
className: "type-body-sm text-muted-foreground",
|
|
230
|
-
children: c.detail
|
|
231
|
-
})]
|
|
232
|
-
})]
|
|
233
|
-
}, c.value)),
|
|
234
|
-
error && /* @__PURE__ */ jsxs("p", {
|
|
235
|
-
id: errorId,
|
|
236
|
-
className: "flex items-start gap-1.5 type-body-sm text-danger",
|
|
237
|
-
children: [/* @__PURE__ */ jsx(CircleAlert, {
|
|
238
|
-
"aria-hidden": true,
|
|
239
|
-
className: "mt-0.5 size-4 shrink-0"
|
|
240
|
-
}), error]
|
|
241
|
-
})
|
|
242
|
-
]
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
75
|
// src/components/density.tsx
|
|
246
76
|
/** The density attribute's page-level setter, shared by `ThemeProvider`. @internal */
|
|
247
77
|
function useDensityOn(value, target) {
|
|
@@ -428,6 +258,6 @@ function ColorSchemeChoice({ legend, labels = defaultLabels, compact = false, cl
|
|
|
428
258
|
}))
|
|
429
259
|
});
|
|
430
260
|
}
|
|
431
|
-
export {
|
|
261
|
+
export { useColorScheme as a, Tooltip$1 as c, colorSchemeScript as i, KeyText as l, ColorSchemeChoice as n, useSystemColorScheme as o, ThemeProvider as r, Density as s, COLOR_SCHEME_STORAGE_KEY as t };
|
|
432
262
|
|
|
433
|
-
//# sourceMappingURL=theme-
|
|
263
|
+
//# sourceMappingURL=theme-CFNi6WUO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-CFNi6WUO.js","names":["_Fragment","Tooltip","AriaTooltip","_Fragment","Tooltip"],"sources":["../src/components/key-glyphs.tsx","../src/components/tooltip.tsx","../src/components/density.tsx","../src/components/theme.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { ArrowBigUp, ArrowDown, ArrowLeft, ArrowRight, ArrowUp, ChevronUp, Command, Option, type LucideIcon } from \"lucide-react\";\n\n// Keys drawn as icons where a font cannot be trusted to have them (strata-react issue #136, from\n// strata-vid). The arrows (← → ↑ ↓) and the macOS modifiers (⌘ ⌃ ⌥ ⇧) are outside the latin subset of\n// the bundled variable fonts, so a legend drew them in whatever face the machine had: different on\n// every machine, and `strata-visual` fails a shot with text in a system font. Lucide's icons are\n// SVG, so they draw the same everywhere and take the text colour. Each is hidden from assistive\n// technology and followed by its name in screen-reader-only text (\"left arrow\", \"Command\"), so the\n// keycap reads as words rather than as a symbol each screen reader pronounces its own way.\n// Checked: React Aria has no keyboard-shortcut display beyond the `Keyboard` slot (which only\n// labels the text it is given), so this is the glyph mapping the slot's content needs.\n\nconst GLYPHS: Record<string, { icon: LucideIcon; name: string }> = {\n \"←\": { icon: ArrowLeft, name: \"left arrow\" },\n \"→\": { icon: ArrowRight, name: \"right arrow\" },\n \"↑\": { icon: ArrowUp, name: \"up arrow\" },\n \"↓\": { icon: ArrowDown, name: \"down arrow\" },\n \"⌘\": { icon: Command, name: \"Command\" },\n \"⌃\": { icon: ChevronUp, name: \"Control\" },\n \"⌥\": { icon: Option, name: \"Option\" },\n \"⇧\": { icon: ArrowBigUp, name: \"Shift\" },\n};\nconst PATTERN = new RegExp(`([${Object.keys(GLYPHS).join(\"\")}])`);\n\n/** 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. */\nexport function KeyText({ children }: { children: string }) {\n return (\n <>\n {children.split(PATTERN).map((part, i) => {\n const glyph = GLYPHS[part];\n if (!glyph) return part ? <React.Fragment key={i}>{part}</React.Fragment> : null;\n const Icon = glyph.icon;\n return (\n <React.Fragment key={i}>\n <Icon aria-hidden className=\"inline size-[1em] align-[-0.125em]\" />\n <span className=\"sr-only\">{glyph.name} </span>\n </React.Fragment>\n );\n })}\n </>\n );\n}\n","import { KeyText } from \"./key-glyphs\";\nimport * as React from \"react\";\nimport { Tooltip as AriaTooltip, TooltipTrigger } from \"react-aria-components\";\nimport { cn } from \"../lib/utils\";\n\n// A tooltip names or explains a control; it is never the only place information lives. React Aria\n// opens it on keyboard focus as well as hover (strata-vid's old hover-only tooltip hid it from\n// keyboard users), after a short delay so a pointer crossing a toolbar does not flash every tip,\n// and shares the delay between neighbouring tips. It holds only words: anything interactive is a\n// Popover. It is portalled to the body, so a parent's overflow cannot clip it, and sits on the\n// `layer-tip` layer above dialogs, since it can name a control inside one.\n//\n// `IconButton` uses it for its required `label`, so the name and the visible hint come from one\n// string and cannot drift.\n\n/** Props for `Tooltip`. */\nexport type TooltipProps = {\n /** The words: a control's name or one sentence about it. Not interactive. */\n label: React.ReactNode;\n /** A shortcut or other aside shown after the label, muted (\"Ctrl+Z\"). */\n hint?: React.ReactNode;\n /** The element that gets the tip. It must be a React Aria pressable or focusable (a Strata `Button` is). */\n children: React.ReactElement;\n /** Which side of the trigger it prefers; it flips when there is no room. Default `top`. */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n /** Milliseconds before it opens on hover. Focus opens it at once. Default 500. */\n delay?: number;\n /** A controlled open state, for a story or test that needs it shown. */\n open?: boolean;\n className?: string;\n};\n\n/** A hover-and-focus tooltip for a control, portalled above everything. Words only; not the only home of information. */\nexport function Tooltip({ label, hint, children, side = \"top\", delay = 500, open, className }: TooltipProps) {\n return (\n <TooltipTrigger delay={delay} closeDelay={0} isOpen={open}>\n {children}\n <AriaTooltip\n placement={side}\n offset={6}\n className={cn(\"layer-tip enter-overlay max-w-xs rounded-control bg-foreground px-2 py-1 type-caption text-background\", className)}\n >\n {label}\n {hint != null && <span className=\"ml-2 opacity-70\">{typeof hint === \"string\" ? <KeyText>{hint}</KeyText> : hint}</span>}\n </AriaTooltip>\n </TooltipTrigger>\n );\n}\n","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":";;;;;;AAaA,IAAM,SAA6D;CACjE,KAAK;EAAE,MAAM;EAAW,MAAM;CAAa;CAC3C,KAAK;EAAE,MAAM;EAAY,MAAM;CAAc;CAC7C,KAAK;EAAE,MAAM;EAAS,MAAM;CAAW;CACvC,KAAK;EAAE,MAAM;EAAW,MAAM;CAAa;CAC3C,KAAK;EAAE,MAAM;EAAS,MAAM;CAAU;CACtC,KAAK;EAAE,MAAM;EAAW,MAAM;CAAU;CACxC,KAAK;EAAE,MAAM;EAAQ,MAAM;CAAS;CACpC,KAAK;EAAE,MAAM;EAAY,MAAM;CAAQ;AACzC;AACA,IAAM,UAAU,IAAI,OAAO,KAAK,OAAO,KAAK,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,GAAG;;AAGhE,SAAgB,QAAQ,EAAE,YAAkC;CAC1D,OACE,oBAAAA,UAAA,EAAA,UACG,SAAS,MAAM,OAAO,CAAC,CAAC,KAAK,MAAM,MAAM;EACxC,MAAM,QAAQ,OAAO;EACrB,IAAI,CAAC,OAAO,OAAO,OAAO,oBAAC,MAAM,UAAP,EAAA,UAAyB,KAAqB,GAAzB,CAAyB,IAAI;EAC5E,MAAM,OAAO,MAAM;EACnB,OACE,qBAAC,MAAM,UAAP,EAAA,UAAA,CACE,oBAAC,MAAD;GAAM,eAAA;GAAY,WAAU;EAAsC,CAAA,GAClE,qBAAC,QAAD;GAAM,WAAU;GAAhB,UAAA,CAA2B,MAAM,MAAK,GAAO;EAC/B,CAAA,CAA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AkB,EAChC,QACA,SAAS,eACT,UAAU,OACV,aAUC;CACD,MAAM,EAAE,YAAY,kBAAkB,eAAe;CACrD,MAAM,OAAO,MAAM,MAAM;CACzB,MAAM,QAAQ;EAAE,GAAG;EAAe,GAAG;CAAO;CAC5C,IAAI,SACF,OACE,oBAAC,YAAD;EACE,cAAY,UAAU;EACtB,aAAY;EACN;EACN,OAAO;EACP,WAAW,UAAU;GACnB,IAAI,aAAa,KAAK,GAAG,cAAc,KAAK;EAC9C;EACA,WAAW,GAAG,gFAAgF,SAAS;EAEtG,UAAA,YAAY,KAAK,UAAU;GAC1B,MAAM,OAAO,MAAM;GACnB,OACE,oBAACC,WAAD;IAAqB,OAAO,MAAM,MAAM,CAAC;IACzC,UAAA,oBAAC,OAAD;KACS;KACP,cAAY,MAAM,MAAM,CAAC;KACzB,WAAW,GAET,uHACA,oEACA,mFACF;KAEA,UAAA,oBAAC,MAAD;MAAM,eAAA;MAAY,WAAU;KAAU,CAAA;IACjC,CAAA;GACE,GAbK,KAaL;EAEb,CAAC;CACS,CAAA;CAGhB,OACE,oBAAC,aAAD;EACE,QAAQ,UAAU;EACZ;EACN,OAAO;EACP,WAAW,UAAU;GACnB,IAAI,aAAa,KAAK,GAAG,cAAc,KAAK;EAC9C;EACA,SAAS,YAAY,KAAK,WAAW;GAAE;GAAO,GAAG,MAAM;EAAO,EAAE;CACjE,CAAA;AAEL"}
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { c as cn, o as useFieldControl, s as controlHeight } from "./field-7Z4N5r5g.js";
|
|
2
|
+
import { i as format } from "./format-B32-PVi2.js";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { I18nProvider, Input, NumberField, Slider, SliderOutput, SliderThumb, SliderTrack } from "react-aria-components";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/lib/in-view.ts
|
|
7
|
+
/**
|
|
8
|
+
* Whether an element is within `rootMargin` of its scroll region (the nearest
|
|
9
|
+
* `[data-strata-scroll]` ancestor, else the viewport). Returns a callback ref, so it follows the
|
|
10
|
+
* element as it mounts and unmounts.
|
|
11
|
+
*/
|
|
12
|
+
function useInView({ active = true, rootMargin = "0px", once = false, unsupported = false } = {}) {
|
|
13
|
+
const [inView, setInView] = React.useState(false);
|
|
14
|
+
const [el, setEl] = React.useState(null);
|
|
15
|
+
const seen = once && inView;
|
|
16
|
+
React.useEffect(() => {
|
|
17
|
+
if (seen) return;
|
|
18
|
+
if (!active || !el) {
|
|
19
|
+
setInView(false);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (typeof IntersectionObserver === "undefined") {
|
|
23
|
+
setInView(unsupported);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const root = el.parentElement?.closest("[data-strata-scroll]") ?? null;
|
|
27
|
+
const observer = new IntersectionObserver((entries) => setInView(entries[entries.length - 1].isIntersecting), {
|
|
28
|
+
root,
|
|
29
|
+
rootMargin
|
|
30
|
+
});
|
|
31
|
+
observer.observe(el);
|
|
32
|
+
return () => observer.disconnect();
|
|
33
|
+
}, [
|
|
34
|
+
active,
|
|
35
|
+
el,
|
|
36
|
+
rootMargin,
|
|
37
|
+
seen,
|
|
38
|
+
unsupported
|
|
39
|
+
]);
|
|
40
|
+
return {
|
|
41
|
+
ref: setEl,
|
|
42
|
+
inView
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// src/lib/number-input.ts
|
|
46
|
+
/** Reads `#rgb`, `#rrggbb` (with or without the #) as lower-case `#rrggbb`, or null. */
|
|
47
|
+
function parseHex(text) {
|
|
48
|
+
const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(text.trim());
|
|
49
|
+
if (!m) return null;
|
|
50
|
+
const h = m[1].toLowerCase();
|
|
51
|
+
return "#" + (h.length === 3 ? [...h].map((c) => c + c).join("") : h);
|
|
52
|
+
}
|
|
53
|
+
function luminance(hex) {
|
|
54
|
+
const v = [
|
|
55
|
+
1,
|
|
56
|
+
3,
|
|
57
|
+
5
|
|
58
|
+
].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255).map((c) => c <= .03928 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4);
|
|
59
|
+
return .2126 * v[0] + .7152 * v[1] + .0722 * v[2];
|
|
60
|
+
}
|
|
61
|
+
/** WCAG contrast ratio between two `#rrggbb` colours, 1 to 21. */
|
|
62
|
+
function contrastRatio(a, b) {
|
|
63
|
+
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
64
|
+
return (hi + .05) / (lo + .05);
|
|
65
|
+
}
|
|
66
|
+
// src/components/value-controls.tsx
|
|
67
|
+
var box = "flex w-full min-w-0 items-center rounded-control border border-input bg-background px-3 type-body text-foreground transition-state disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-70 has-[input:disabled]:cursor-not-allowed has-[input:disabled]:bg-muted has-[input:disabled]:opacity-70 aria-invalid:border-danger has-[input:focus-visible]:outline-2 has-[input:focus-visible]:outline-offset-2 has-[input:focus-visible]:outline-ring";
|
|
68
|
+
/** A number with its unit joined by a non-breaking space; `%` and `°` stay attached. */
|
|
69
|
+
function withUnit(text, unit) {
|
|
70
|
+
if (!unit) return text;
|
|
71
|
+
return unit === "%" || unit === "°" ? text + unit : text + "\xA0" + unit;
|
|
72
|
+
}
|
|
73
|
+
var intlUnits = {
|
|
74
|
+
"%": "percent",
|
|
75
|
+
"°": "degree",
|
|
76
|
+
ms: "millisecond",
|
|
77
|
+
s: "second",
|
|
78
|
+
kB: "kilobyte",
|
|
79
|
+
MB: "megabyte",
|
|
80
|
+
GB: "gigabyte",
|
|
81
|
+
kbps: "kilobit-per-second",
|
|
82
|
+
Mbps: "megabit-per-second"
|
|
83
|
+
};
|
|
84
|
+
function decimalsOf(n) {
|
|
85
|
+
const s = String(n);
|
|
86
|
+
if (s.includes("e-")) return Number(s.split("e-")[1]) + (s.split("e-")[0].split(".")[1]?.length ?? 0);
|
|
87
|
+
return s.split(".")[1]?.length ?? 0;
|
|
88
|
+
}
|
|
89
|
+
function useNumberText(locale, places) {
|
|
90
|
+
return React.useMemo(() => {
|
|
91
|
+
const f = new Intl.NumberFormat(locale, {
|
|
92
|
+
maximumFractionDigits: places,
|
|
93
|
+
minimumFractionDigits: 0
|
|
94
|
+
});
|
|
95
|
+
return (n) => f.format(n);
|
|
96
|
+
}, [locale, places]);
|
|
97
|
+
}
|
|
98
|
+
function formatOptionsFor(places, unit) {
|
|
99
|
+
const base = {
|
|
100
|
+
maximumFractionDigits: places,
|
|
101
|
+
minimumFractionDigits: 0
|
|
102
|
+
};
|
|
103
|
+
const known = unit ? intlUnits[unit] : void 0;
|
|
104
|
+
return known ? {
|
|
105
|
+
...base,
|
|
106
|
+
style: "unit",
|
|
107
|
+
unit: known,
|
|
108
|
+
unitDisplay: "narrow"
|
|
109
|
+
} : base;
|
|
110
|
+
}
|
|
111
|
+
function describeRange(min, max, show, unit) {
|
|
112
|
+
const a = min === void 0 ? "" : withUnit(show(min), unit);
|
|
113
|
+
const b = max === void 0 ? "" : withUnit(show(max), unit);
|
|
114
|
+
if (min !== void 0 && max !== void 0) return `Enter a value from ${a} to ${b}.`;
|
|
115
|
+
if (min !== void 0) return `Enter ${a} or more.`;
|
|
116
|
+
if (max !== void 0) return `Enter ${b} or less.`;
|
|
117
|
+
return "Enter a number.";
|
|
118
|
+
}
|
|
119
|
+
/** A number with a unit on React Aria's number field: typed input is validated, not clamped, so an out-of-range value is explained in the surrounding `Field` and never passed on; empty stays `null`. */
|
|
120
|
+
function NumberField$1({ value, onChange, min, max, step = 1, places, unit, locale = format.locale, required = false, disabled, id: idProp, name, size = "default", className, "aria-label": ariaLabel }) {
|
|
121
|
+
const { field, report } = useFieldControl();
|
|
122
|
+
const digits = places ?? Math.max(decimalsOf(step), min === void 0 ? 0 : decimalsOf(min));
|
|
123
|
+
const show = useNumberText(locale, digits);
|
|
124
|
+
const [own, setOwn] = React.useState(false);
|
|
125
|
+
const unitId = React.useId();
|
|
126
|
+
const [local, setLocal] = React.useState(value ?? NaN);
|
|
127
|
+
const [seen, setSeen] = React.useState(value);
|
|
128
|
+
if (seen !== value) {
|
|
129
|
+
setSeen(value);
|
|
130
|
+
setLocal(value ?? NaN);
|
|
131
|
+
}
|
|
132
|
+
const fail = (message) => {
|
|
133
|
+
setOwn(true);
|
|
134
|
+
report(message);
|
|
135
|
+
};
|
|
136
|
+
const ok = () => {
|
|
137
|
+
setOwn(false);
|
|
138
|
+
report(void 0);
|
|
139
|
+
};
|
|
140
|
+
const handle = (n) => {
|
|
141
|
+
setLocal(n);
|
|
142
|
+
if (Number.isNaN(n)) {
|
|
143
|
+
if (required) return fail("Enter a value.");
|
|
144
|
+
ok();
|
|
145
|
+
if (value !== null) onChange(null);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (min !== void 0 && n < min || max !== void 0 && n > max) return fail(describeRange(min, max, show, unit));
|
|
149
|
+
ok();
|
|
150
|
+
if (n !== value) onChange(n);
|
|
151
|
+
};
|
|
152
|
+
const invalid = field?.invalid || own;
|
|
153
|
+
return /* @__PURE__ */ jsx(I18nProvider, {
|
|
154
|
+
locale,
|
|
155
|
+
children: /* @__PURE__ */ jsxs(NumberField, {
|
|
156
|
+
value: local,
|
|
157
|
+
onChange: handle,
|
|
158
|
+
minValue: min,
|
|
159
|
+
maxValue: max,
|
|
160
|
+
step,
|
|
161
|
+
formatOptions: {
|
|
162
|
+
maximumFractionDigits: digits,
|
|
163
|
+
minimumFractionDigits: 0
|
|
164
|
+
},
|
|
165
|
+
commitBehavior: "validate",
|
|
166
|
+
isDisabled: disabled,
|
|
167
|
+
isInvalid: invalid || void 0,
|
|
168
|
+
name,
|
|
169
|
+
"aria-label": ariaLabel ?? field?.label,
|
|
170
|
+
className: cn(box, controlHeight[size], className),
|
|
171
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
172
|
+
id: idProp ?? field?.id,
|
|
173
|
+
placeholder: format.missing,
|
|
174
|
+
"aria-describedby": [field?.describedBy, unit ? unitId : void 0].filter(Boolean).join(" ") || void 0,
|
|
175
|
+
className: "min-w-0 flex-1 bg-transparent tabular-nums outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"
|
|
176
|
+
}), unit && /* @__PURE__ */ jsxs("span", {
|
|
177
|
+
id: unitId,
|
|
178
|
+
className: "ml-2 shrink-0 type-body-sm text-muted-foreground",
|
|
179
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
180
|
+
"aria-hidden": true,
|
|
181
|
+
children: unit
|
|
182
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
183
|
+
className: "sr-only",
|
|
184
|
+
children: intlUnits[unit] ? intlUnits[unit].replace(/-/g, " ") : unit
|
|
185
|
+
})]
|
|
186
|
+
})]
|
|
187
|
+
})
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
/** A slider on React Aria with its current value always printed beside the track (and spoken with the unit when `Intl` knows it); `editable` adds a number field to type an exact value. */
|
|
191
|
+
function Slider$1({ value, onChange, min, max, step = 1, unit, locale = format.locale, editable = false, hideValue = false, places, disabled, className, "aria-label": ariaLabel }) {
|
|
192
|
+
const { field } = useFieldControl();
|
|
193
|
+
const digits = places ?? Math.max(decimalsOf(step), decimalsOf(min));
|
|
194
|
+
const show = useNumberText(locale, digits);
|
|
195
|
+
const name = ariaLabel ?? field?.label ?? "Value";
|
|
196
|
+
const text = withUnit(show(value), unit);
|
|
197
|
+
return /* @__PURE__ */ jsx(I18nProvider, {
|
|
198
|
+
locale,
|
|
199
|
+
children: /* @__PURE__ */ jsxs(Slider, {
|
|
200
|
+
value,
|
|
201
|
+
onChange: (v) => onChange(v),
|
|
202
|
+
minValue: min,
|
|
203
|
+
maxValue: max,
|
|
204
|
+
step,
|
|
205
|
+
formatOptions: formatOptionsFor(digits, unit),
|
|
206
|
+
isDisabled: disabled,
|
|
207
|
+
"aria-label": name,
|
|
208
|
+
"aria-describedby": field?.describedBy,
|
|
209
|
+
className: cn("flex min-w-0 items-center gap-3", className),
|
|
210
|
+
children: [/* @__PURE__ */ jsx(SliderTrack, {
|
|
211
|
+
className: "relative flex h-(--control-h) min-w-0 flex-1 cursor-pointer items-center disabled:cursor-not-allowed disabled:opacity-50",
|
|
212
|
+
children: ({ state }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
213
|
+
/* @__PURE__ */ jsx("span", {
|
|
214
|
+
"aria-hidden": true,
|
|
215
|
+
className: "absolute inset-x-0 h-1.5 rounded-pill bg-muted"
|
|
216
|
+
}),
|
|
217
|
+
/* @__PURE__ */ jsx("span", {
|
|
218
|
+
"aria-hidden": true,
|
|
219
|
+
className: "absolute left-0 h-1.5 rounded-pill bg-primary",
|
|
220
|
+
style: { width: `${state.getThumbPercent(0) * 100}%` }
|
|
221
|
+
}),
|
|
222
|
+
/* @__PURE__ */ jsx(SliderThumb, { className: "top-1/2 size-5 rounded-pill border-2 border-primary bg-background focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring" })
|
|
223
|
+
] })
|
|
224
|
+
}), editable ? /* @__PURE__ */ jsx(NumberField$1, {
|
|
225
|
+
className: "w-28 shrink-0",
|
|
226
|
+
"aria-label": `${name}, exact value`,
|
|
227
|
+
value,
|
|
228
|
+
onChange: (v) => v !== null && onChange(v),
|
|
229
|
+
min,
|
|
230
|
+
max,
|
|
231
|
+
step,
|
|
232
|
+
unit,
|
|
233
|
+
locale,
|
|
234
|
+
places: digits,
|
|
235
|
+
required: true,
|
|
236
|
+
disabled
|
|
237
|
+
}) : !hideValue && /* @__PURE__ */ jsx(SliderOutput, {
|
|
238
|
+
"aria-hidden": true,
|
|
239
|
+
className: "w-16 shrink-0 text-right type-body-sm tabular-nums text-foreground",
|
|
240
|
+
children: text
|
|
241
|
+
})]
|
|
242
|
+
})
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/** Choose a colour with the platform picker, see and type its hex value, pick from the app's suggestions, and get a note when it would be hard to see on `against`. A half-typed value is never passed on. */
|
|
246
|
+
function ColorField({ value, onChange, suggestions, against, againstLabel = "the background", minContrast = 3, disabled, id: idProp, className, "aria-label": ariaLabel }) {
|
|
247
|
+
const { field, report } = useFieldControl();
|
|
248
|
+
const label = ariaLabel ?? field?.label;
|
|
249
|
+
const pickerName = label ? `${label}, picker` : "Colour picker";
|
|
250
|
+
const [draft, setDraft] = React.useState(null);
|
|
251
|
+
const [own, setOwn] = React.useState(false);
|
|
252
|
+
const text = draft ?? value ?? "";
|
|
253
|
+
const ratio = value && against ? contrastRatio(value, against) : null;
|
|
254
|
+
const commitText = (t) => {
|
|
255
|
+
if (t.trim() === "") {
|
|
256
|
+
setOwn(false);
|
|
257
|
+
report(void 0);
|
|
258
|
+
if (value !== null) onChange(null);
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
const hex = parseHex(t);
|
|
262
|
+
if (!hex) {
|
|
263
|
+
setOwn(true);
|
|
264
|
+
report("Enter a colour like #1a7f64.");
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
setOwn(false);
|
|
268
|
+
report(void 0);
|
|
269
|
+
if (hex !== value) onChange(hex);
|
|
270
|
+
return true;
|
|
271
|
+
};
|
|
272
|
+
const pick = (hex) => {
|
|
273
|
+
setDraft(null);
|
|
274
|
+
setOwn(false);
|
|
275
|
+
report(void 0);
|
|
276
|
+
if (hex !== value) onChange(hex);
|
|
277
|
+
};
|
|
278
|
+
const invalid = field?.invalid || own;
|
|
279
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
280
|
+
className: cn("grid min-w-0 gap-2", className),
|
|
281
|
+
children: [
|
|
282
|
+
/* @__PURE__ */ jsxs("div", {
|
|
283
|
+
className: cn(box, controlHeight.default, "gap-2 px-2"),
|
|
284
|
+
"aria-invalid": invalid || void 0,
|
|
285
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
286
|
+
className: "relative size-6 shrink-0 overflow-hidden rounded-control border border-input",
|
|
287
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
288
|
+
"aria-hidden": true,
|
|
289
|
+
className: cn("absolute inset-0", value === null && "bg-muted"),
|
|
290
|
+
style: value ? { background: value } : void 0
|
|
291
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
292
|
+
type: "color",
|
|
293
|
+
"aria-label": pickerName,
|
|
294
|
+
value: value ?? "#000000",
|
|
295
|
+
disabled,
|
|
296
|
+
onChange: (e) => pick(e.target.value),
|
|
297
|
+
className: "absolute inset-0 size-full cursor-pointer opacity-0 disabled:cursor-not-allowed"
|
|
298
|
+
})]
|
|
299
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
300
|
+
id: idProp ?? field?.id,
|
|
301
|
+
type: "text",
|
|
302
|
+
autoComplete: "off",
|
|
303
|
+
spellCheck: false,
|
|
304
|
+
disabled,
|
|
305
|
+
"aria-label": ariaLabel,
|
|
306
|
+
"aria-describedby": field?.describedBy,
|
|
307
|
+
"aria-invalid": invalid || void 0,
|
|
308
|
+
placeholder: format.missing,
|
|
309
|
+
value: text,
|
|
310
|
+
onChange: (e) => setDraft(e.target.value),
|
|
311
|
+
onBlur: () => {
|
|
312
|
+
if (draft !== null && commitText(draft)) setDraft(null);
|
|
313
|
+
},
|
|
314
|
+
onKeyDown: (e) => {
|
|
315
|
+
if (e.key === "Enter" && draft !== null && commitText(draft)) setDraft(null);
|
|
316
|
+
if (e.key === "Escape" && draft !== null) {
|
|
317
|
+
setDraft(null);
|
|
318
|
+
setOwn(false);
|
|
319
|
+
report(void 0);
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
className: "min-w-0 flex-1 bg-transparent tabular-nums outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"
|
|
323
|
+
})]
|
|
324
|
+
}),
|
|
325
|
+
suggestions && suggestions.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
326
|
+
role: "group",
|
|
327
|
+
"aria-label": "Suggested colours",
|
|
328
|
+
className: "flex flex-wrap gap-1.5",
|
|
329
|
+
children: suggestions.map((hex) => /* @__PURE__ */ jsx("button", {
|
|
330
|
+
type: "button",
|
|
331
|
+
disabled,
|
|
332
|
+
"aria-label": hex,
|
|
333
|
+
"aria-pressed": value === hex,
|
|
334
|
+
onClick: () => pick(hex),
|
|
335
|
+
className: "size-6 cursor-pointer rounded-control border border-input transition-state aria-pressed:outline-2 aria-pressed:outline-offset-2 aria-pressed:outline-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
|
336
|
+
style: { background: hex }
|
|
337
|
+
}, hex))
|
|
338
|
+
}),
|
|
339
|
+
ratio !== null && ratio < minContrast && /* @__PURE__ */ jsxs("p", {
|
|
340
|
+
className: "type-body-sm text-warning",
|
|
341
|
+
children: [
|
|
342
|
+
"Hard to see on ",
|
|
343
|
+
againstLabel,
|
|
344
|
+
": contrast ",
|
|
345
|
+
format.decimal(ratio),
|
|
346
|
+
":1, aim for ",
|
|
347
|
+
format.decimal(minContrast),
|
|
348
|
+
":1 or more."
|
|
349
|
+
]
|
|
350
|
+
})
|
|
351
|
+
]
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
export { useInView as i, NumberField$1 as n, Slider$1 as r, ColorField as t };
|
|
355
|
+
|
|
356
|
+
//# sourceMappingURL=value-controls-D6O9TsM6.js.map
|