strata-react 1.3.15 → 1.3.17

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.
Files changed (58) hide show
  1. package/README.md +47 -8
  2. package/UPGRADING.md +15 -0
  3. package/dist/components/data-table.d.ts +6 -0
  4. package/dist/components/field.d.ts +2 -0
  5. package/dist/components/hotkeys.d.ts +1 -1
  6. package/dist/components/link-card.d.ts +4 -2
  7. package/dist/components/pause-button.d.ts +7 -0
  8. package/dist/components/schedule-table.d.ts +24 -0
  9. package/dist/components/system-panel.d.ts +58 -0
  10. package/dist/components/theme.d.ts +46 -1
  11. package/dist/components/thumbnail.d.ts +2 -0
  12. package/dist/{errors-D99YX4XL.js → errors-jep2voNI.js} +42 -3
  13. package/dist/errors-jep2voNI.js.map +1 -0
  14. package/dist/field-t4Hoer0d.js +587 -0
  15. package/dist/field-t4Hoer0d.js.map +1 -0
  16. package/dist/index.d.ts +6 -3
  17. package/dist/index.js +669 -463
  18. package/dist/index.js.map +1 -1
  19. package/dist/lib/breakpoint.d.ts +4 -0
  20. package/dist/lib/format.d.ts +59 -6
  21. package/dist/map.js +2 -3
  22. package/dist/map.js.map +1 -1
  23. package/dist/microphone-Cu1u5Yml.js +547 -0
  24. package/dist/microphone-Cu1u5Yml.js.map +1 -0
  25. package/dist/panorama.js +3 -2
  26. package/dist/panorama.js.map +1 -1
  27. package/dist/query/index.d.ts +5 -1
  28. package/dist/query/poll.d.ts +24 -0
  29. package/dist/reading.css +11 -0
  30. package/dist/{run-hR9neQHM.js → run-BT2WKzMz.js} +83 -17
  31. package/dist/run-BT2WKzMz.js.map +1 -0
  32. package/dist/strata.bare.css +279 -0
  33. package/dist/strata.css +840 -10
  34. package/dist/strata.migrate.css +15 -6
  35. package/dist/testing/index.d.ts +4 -2
  36. package/dist/testing.js +34 -6
  37. package/dist/testing.js.map +1 -1
  38. package/dist/{theme-By3DSUTs.js → theme-DXacprlw.js} +147 -6
  39. package/dist/theme-DXacprlw.js.map +1 -0
  40. package/dist/{value-controls-B7iNh4WO.js → value-controls-DB5l5Qe2.js} +21 -46
  41. package/dist/value-controls-DB5l5Qe2.js.map +1 -0
  42. package/dist/visual/capture.d.ts +2 -0
  43. package/dist/visual/fonts.d.ts +18 -0
  44. package/dist/visual/index.d.ts +1 -0
  45. package/dist/visual/types.d.ts +7 -1
  46. package/dist/visual-cli.js +1 -1
  47. package/dist/visual.js +1 -1
  48. package/package.json +12 -3
  49. package/dist/errors-D99YX4XL.js.map +0 -1
  50. package/dist/field-QCCmWTuY.js +0 -321
  51. package/dist/field-QCCmWTuY.js.map +0 -1
  52. package/dist/format-B32-PVi2.js +0 -201
  53. package/dist/format-B32-PVi2.js.map +0 -1
  54. package/dist/microphone-BZXMKTCM.js +0 -292
  55. package/dist/microphone-BZXMKTCM.js.map +0 -1
  56. package/dist/run-hR9neQHM.js.map +0 -1
  57. package/dist/theme-By3DSUTs.js.map +0 -1
  58. package/dist/value-controls-B7iNh4WO.js.map +0 -1
@@ -0,0 +1,587 @@
1
+ import { clsx } from "clsx";
2
+ import { extendTailwindMerge } from "tailwind-merge";
3
+ import * as React from "react";
4
+ import { Label, Radio, RadioGroup, Tooltip, TooltipTrigger } from "react-aria-components";
5
+ import { ArrowBigUp, ArrowDown, ArrowLeft, ArrowRight, ArrowUp, ChevronUp, CircleAlert, Command, Option } from "lucide-react";
6
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ import { useSearchParams } from "react-router";
8
+ // src/lib/utils.ts
9
+ var typeSteps = [
10
+ "caption",
11
+ "label",
12
+ "body-sm",
13
+ "body",
14
+ "heading",
15
+ "title",
16
+ "figure",
17
+ "display",
18
+ "picture"
19
+ ];
20
+ var twMerge = extendTailwindMerge({ extend: {
21
+ theme: { radius: [...[
22
+ "control",
23
+ "surface",
24
+ "overlay",
25
+ "pill"
26
+ ]] },
27
+ classGroups: { "font-size": [{ type: [...typeSteps] }] }
28
+ } });
29
+ /** clsx + tailwind-merge, taught that `type-*` utilities are font sizes and `rounded-control`, `-surface`, `-overlay`, `-pill` are radii. */
30
+ function cn(...inputs) {
31
+ return twMerge(clsx(inputs));
32
+ }
33
+ // src/lib/format.ts
34
+ var NBSP = "\xA0";
35
+ /** The placeholder printed for a value that is not known: an en dash. */
36
+ var MISSING = "–";
37
+ var BYTE_UNITS = [
38
+ "B",
39
+ "kB",
40
+ "MB",
41
+ "GB",
42
+ "TB",
43
+ "PB"
44
+ ];
45
+ var BYTE_SIZE = Object.fromEntries(BYTE_UNITS.map((u, i) => [u, 1e3 ** i]));
46
+ var BINARY_UNITS = [
47
+ "B",
48
+ "KiB",
49
+ "MiB",
50
+ "GiB",
51
+ "TiB",
52
+ "PiB"
53
+ ];
54
+ var BINARY_SIZE = Object.fromEntries(BINARY_UNITS.map((u, i) => [u, 1024 ** i]));
55
+ var SIZE = {
56
+ ...BYTE_SIZE,
57
+ ...BINARY_SIZE
58
+ };
59
+ function chooseByteUnit(value, binary) {
60
+ return [...binary ? BINARY_UNITS : BYTE_UNITS].reverse().find((u) => Math.abs(value) >= SIZE[u]) ?? "B";
61
+ }
62
+ /** A Date from a Date, an ISO string or epoch milliseconds; throws a RangeError naming the input when it is not a date. */
63
+ function toDate(value) {
64
+ const date = value instanceof Date ? value : new Date(value);
65
+ if (Number.isNaN(date.getTime())) throw new RangeError(`Not a date: ${JSON.stringify(String(value))}`);
66
+ return date;
67
+ }
68
+ function callableDate(df, missing) {
69
+ const format = (value) => value == null ? missing : df.format(toDate(value));
70
+ return Object.assign(format, {
71
+ format,
72
+ formatToParts: (value) => df.formatToParts(toDate(value)),
73
+ formatRange: (start, end) => df.formatRange(toDate(start), toDate(end)),
74
+ resolvedOptions: () => df.resolvedOptions()
75
+ });
76
+ }
77
+ function callable(nf, missing) {
78
+ const format = (value) => value == null ? missing : nf.format(value);
79
+ return Object.assign(format, {
80
+ format,
81
+ formatToParts: (value) => nf.formatToParts(value),
82
+ resolvedOptions: () => nf.resolvedOptions()
83
+ });
84
+ }
85
+ var DAY = 864e5;
86
+ var AGO_STEPS = [
87
+ ["year", 365 * DAY],
88
+ ["month", 30 * DAY],
89
+ ["week", 7 * DAY],
90
+ ["day", DAY],
91
+ ["hour", 36e5],
92
+ ["minute", 6e4]
93
+ ];
94
+ /** Intl formatters for one locale (and optionally one time zone): integers, decimals, percent, dates, times, units with a non-breaking space, byte sizes, and counted nouns. */
95
+ function createFormat(locale, options = {}) {
96
+ const { timeZone, missing = "–" } = options;
97
+ const dates = (opts) => callableDate(new Intl.DateTimeFormat(locale, {
98
+ ...opts,
99
+ timeZone
100
+ }), missing);
101
+ const integer = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }), missing);
102
+ const decimal = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }), missing);
103
+ const percent = callable(new Intl.NumberFormat(locale, {
104
+ style: "percent",
105
+ maximumFractionDigits: 0
106
+ }), missing);
107
+ const compact = callable(new Intl.NumberFormat(locale, {
108
+ notation: "compact",
109
+ maximumFractionDigits: 1
110
+ }), missing);
111
+ const relative = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
112
+ const plurals = new Intl.PluralRules(locale);
113
+ const clock = dates({
114
+ hour: "2-digit",
115
+ minute: "2-digit"
116
+ });
117
+ const day = dates({
118
+ weekday: "long",
119
+ day: "numeric",
120
+ month: "long"
121
+ });
122
+ const shortDay = dates({
123
+ weekday: "short",
124
+ hour: "2-digit",
125
+ minute: "2-digit"
126
+ });
127
+ const date = dates({ dateStyle: "medium" });
128
+ const dateTime = dates({
129
+ dateStyle: "medium",
130
+ timeStyle: "short"
131
+ });
132
+ const withUnit = (value, unit, fmt = integer) => `${fmt.format(value)} ${unit}`;
133
+ return {
134
+ locale,
135
+ /** The zone times are shown in, or `undefined` for the viewer's own. */
136
+ timeZone,
137
+ /** Whole numbers with grouping: `format.integer(1222)` is "1,222". */
138
+ integer,
139
+ /** One decimal place at most: `format.decimal(3.14)` is "3.1". */
140
+ decimal,
141
+ /** A ratio as a whole percent: `format.percent(0.42)` is "42%". */
142
+ percent,
143
+ /**
144
+ * A part's share of a whole, as `percent` but never misleading at the ends: a part above 0 that
145
+ * rounds to 0 is "<1%", and one short of the whole that rounds to 100 is ">99%".
146
+ * `format.share(2.4 / 512)` is "<1%".
147
+ */
148
+ share: (value) => {
149
+ if (value == null || Number.isNaN(value)) return missing;
150
+ if (value > 0 && value < .005) return `<${percent.format(.01)}`;
151
+ if (value >= .995 && value < 1) return `>${percent.format(.99)}`;
152
+ return percent.format(value);
153
+ },
154
+ /** A figure in short form for counts that run to thousands: `format.compact(1234)` is "1.2k" in en-GB, "1.2K" in en-US. */
155
+ compact,
156
+ /**
157
+ * How long ago (or how far ahead) a time is, in the largest unit it reaches:
158
+ * "3 weeks ago", "yesterday", "in 2 hours", "now" under a minute. Pass `now` in tests.
159
+ */
160
+ ago: (value, now = /* @__PURE__ */ new Date()) => {
161
+ if (value == null) return missing;
162
+ const diff = toDate(value).getTime() - toDate(now).getTime();
163
+ const span = Math.abs(diff);
164
+ for (const [unit, size] of AGO_STEPS) if (span >= size) return relative.format(Math.sign(diff) * Math.floor(span / size), unit);
165
+ return relative.format(0, "second");
166
+ },
167
+ /**
168
+ * A media running time from seconds, as a player shows it: "4:05", "1:02:09". Unknown
169
+ * (null, negative, not finite) prints the placeholder. Set it in `tabular-nums`.
170
+ */
171
+ runningTime: (seconds) => {
172
+ if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return missing;
173
+ const s = Math.floor(seconds);
174
+ const two = (n) => String(n).padStart(2, "0");
175
+ const [h, m] = [Math.floor(s / 3600), Math.floor(s % 3600 / 60)];
176
+ return h > 0 ? `${h}:${two(m)}:${two(s % 60)}` : `${m}:${two(s % 60)}`;
177
+ },
178
+ /**
179
+ * A position in media as an editor shows it, to a chosen precision: "4:05" (seconds), "4:05.250"
180
+ * (`"ms"`), or "0:04:05:07" (`"frames"` at `fps`, the last part the frame). Hours appear only
181
+ * from one hour, except in frames. Frames are always four parts, hours included, as SMPTE
182
+ * timecode is (non-drop frame, with colons): a three-part "1:05:00" reads as one hour five, so
183
+ * a frame count must never be three. Editors write the same four parts (strata-react issue
184
+ * #122). Floors, never rounds up, so a time never reads ahead of the picture. Unknown (null,
185
+ * negative, not finite) prints the placeholder. Set it in `tabular-nums`.
186
+ */
187
+ timecode: (seconds, { precision = "seconds", fps = 30 } = {}) => {
188
+ if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return missing;
189
+ const whole = Math.floor(seconds);
190
+ const two = (n) => String(n).padStart(2, "0");
191
+ const [h, m] = [Math.floor(whole / 3600), Math.floor(whole % 3600 / 60)];
192
+ const base = h > 0 ? `${h}:${two(m)}:${two(whole % 60)}` : `${m}:${two(whole % 60)}`;
193
+ if (precision === "ms") return `${base}.${String(Math.min(Math.floor((seconds - whole) * 1e3 + 1e-6), 999)).padStart(3, "0")}`;
194
+ if (precision === "frames") return `${h}:${two(m)}:${two(whole % 60)}:${two(Math.min(Math.floor((seconds - whole) * fps + 1e-6), Math.ceil(fps) - 1))}`;
195
+ return base;
196
+ },
197
+ /** What a missing value prints as: an en dash unless `createFormat`'s `missing` says otherwise. */
198
+ missing,
199
+ /** A time of day: `format.clock(at)` is "06:05". */
200
+ clock,
201
+ /** A day without its year, for this week's things: `format.day(at)` is "Sunday 8 November". */
202
+ day,
203
+ /** A weekday and time, for chart axes and recent rows: `format.shortDay(at)` is "Sun 06:05". */
204
+ shortDay,
205
+ /** A date with its year, for a record or a deadline: `format.date(at)` is "8 Nov 2026". */
206
+ date,
207
+ /** A date and time, for a log or history row: `format.dateTime(at)` is "8 Nov 2026, 06:05". */
208
+ dateTime,
209
+ /** A figure and its unit joined by a non-breaking space (`NBSP`), so they never wrap apart. */
210
+ withUnit,
211
+ /** A temperature in °C, joined by a non-breaking space. */
212
+ celsius: (value) => withUnit(value, "°C"),
213
+ /**
214
+ * A size in bytes in the largest decimal unit it reaches (kB, MB, GB, TB, as disks and
215
+ * networks are sold): one decimal below 10 ("5.2 GB"), whole above ("431 GB"). Pass `unit`
216
+ * to fix the unit, so figures compared side by side ("431 of 466 GB") share one. Memory is
217
+ * read in binary units: `{ binary: true }` writes KiB, MiB, GiB ("7.6 GiB"), and a binary
218
+ * unit ("GiB") picks that too. The second argument is a unit or `{ binary, unit }`.
219
+ */
220
+ bytes: (value, unitOrOptions) => {
221
+ const { binary = false, unit } = typeof unitOrOptions === "string" ? { unit: unitOrOptions } : unitOrOptions ?? {};
222
+ const chosen = unit ?? chooseByteUnit(value, binary);
223
+ const scaled = value / SIZE[chosen];
224
+ return withUnit(scaled, chosen, Math.abs(scaled) < 10 && chosen !== "B" ? decimal : integer);
225
+ },
226
+ /**
227
+ * A length of time in words, the unit chosen by size: "45 s", "16 min", "3.5 h", "2 days". Unknown
228
+ * (null, negative, not finite) prints the placeholder. `style: "parts"` is an uptime, the two
229
+ * largest units written out: "1d 1h 0m", "2h 5m", "5m 3s". Not `runningTime`, which is a media clock.
230
+ */
231
+ duration: (seconds, { style = "approx" } = {}) => {
232
+ if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return missing;
233
+ if (style === "parts") {
234
+ const s = Math.floor(seconds);
235
+ const [d, h, m] = [
236
+ Math.floor(s / 86400),
237
+ Math.floor(s % 86400 / 3600),
238
+ Math.floor(s % 3600 / 60)
239
+ ];
240
+ if (d > 0) return `${d}d ${h}h ${m}m`;
241
+ if (h > 0) return `${h}h ${m}m`;
242
+ if (m > 0) return `${m}m ${s % 60}s`;
243
+ return `${s}s`;
244
+ }
245
+ if (seconds < 60) return withUnit(Math.floor(seconds), "s");
246
+ if (seconds < 3600) return withUnit(Math.floor(seconds / 60), "min");
247
+ if (seconds < 86400) return withUnit(seconds / 3600, "h", decimal);
248
+ const days = seconds / 86400;
249
+ return withUnit(days, plurals.select(Math.round(days * 10) / 10) === "one" ? "day" : "days", decimal);
250
+ },
251
+ /**
252
+ * A reading and its unit: `format.measure(12.34, "GB")` is "12.3 GB" (one decimal at most, a
253
+ * non-breaking space). `"%"` takes the figure as percent points and goes through `percent`, so
254
+ * the locale decides the spacing: `format.measure(41, "%")` is "41%". Unknown prints the placeholder.
255
+ */
256
+ measure: (value, unit) => value == null ? missing : unit === "%" ? percent.format(value / 100) : withUnit(value, unit, decimal),
257
+ /**
258
+ * A tick for the axis of a chart of the past, from seconds before now: "now", "−30 s", "−2 min",
259
+ * "−6 h", "−3 d" (a true minus sign). Pass it as `LineChart`'s `formatX` after turning x into seconds ago.
260
+ */
261
+ agoTick: (secondsAgo) => {
262
+ if (secondsAgo == null || !Number.isFinite(secondsAgo)) return missing;
263
+ const s = Math.abs(secondsAgo);
264
+ if (s < 1) return "now";
265
+ const [n, unit] = s < 60 ? [s, "s"] : s < 3600 ? [s / 60, "min"] : s < 86400 ? [s / 3600, "h"] : [s / 86400, "d"];
266
+ return `−${integer.format(n)} ${unit}`;
267
+ },
268
+ /**
269
+ * A distance in metres as a person says it: metres under a kilometre ("850 m"), then
270
+ * kilometres, one decimal below 100 ("12.4 km"), whole above; `"imperial"` is feet under a
271
+ * tenth of a mile ("320 ft"), then miles ("7.7 mi").
272
+ */
273
+ distance: (metres, system = "metric") => {
274
+ if (system === "imperial") {
275
+ const miles = metres / 1609.344;
276
+ return miles < .1 ? withUnit(metres * 3.28084, "ft") : withUnit(miles, "mi", miles < 100 ? decimal : integer);
277
+ }
278
+ return Math.abs(metres) < 1e3 ? withUnit(metres, "m") : withUnit(metres / 1e3, "km", Math.abs(metres) < 1e5 ? decimal : integer);
279
+ },
280
+ /** The unit `bytes` would choose for a value, to share it across a set of figures. */
281
+ byteUnit: (value, { binary = false } = {}) => chooseByteUnit(value, binary),
282
+ /**
283
+ * "1 piece", "6 pieces": the count and its noun, so copy never reads "1 pieces". They are
284
+ * joined by a non-breaking space (`NBSP`), not a plain one: in a test, match with the same
285
+ * call or a `\s` regex, not a typed "6 pieces" string in a role's `name`.
286
+ */
287
+ count: (value, one, many = `${one}s`, { compact: short = false } = {}) => value == null ? missing : `${(short ? compact : integer).format(value)} ${plurals.select(value) === "one" ? one : many}`
288
+ };
289
+ }
290
+ /** The en-GB formatters. */
291
+ var format = createFormat("en-GB");
292
+ // src/components/key-glyphs.tsx
293
+ var GLYPHS = {
294
+ "←": {
295
+ icon: ArrowLeft,
296
+ name: "left arrow"
297
+ },
298
+ "→": {
299
+ icon: ArrowRight,
300
+ name: "right arrow"
301
+ },
302
+ "↑": {
303
+ icon: ArrowUp,
304
+ name: "up arrow"
305
+ },
306
+ "↓": {
307
+ icon: ArrowDown,
308
+ name: "down arrow"
309
+ },
310
+ "⌘": {
311
+ icon: Command,
312
+ name: "Command"
313
+ },
314
+ "⌃": {
315
+ icon: ChevronUp,
316
+ name: "Control"
317
+ },
318
+ "⌥": {
319
+ icon: Option,
320
+ name: "Option"
321
+ },
322
+ "⇧": {
323
+ icon: ArrowBigUp,
324
+ name: "Shift"
325
+ }
326
+ };
327
+ var PATTERN = new RegExp(`([${Object.keys(GLYPHS).join("")}])`);
328
+ /** 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. */
329
+ function KeyText({ children }) {
330
+ return /* @__PURE__ */ jsx(Fragment, { children: children.split(PATTERN).map((part, i) => {
331
+ const glyph = GLYPHS[part];
332
+ if (!glyph) return part ? /* @__PURE__ */ jsx(React.Fragment, { children: part }, i) : null;
333
+ const Icon = glyph.icon;
334
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [/* @__PURE__ */ jsx(Icon, {
335
+ "aria-hidden": true,
336
+ className: "inline size-[1em] align-[-0.125em]"
337
+ }), /* @__PURE__ */ jsxs("span", {
338
+ className: "sr-only",
339
+ children: [glyph.name, " "]
340
+ })] }, i);
341
+ }) });
342
+ }
343
+ // src/components/tooltip.tsx
344
+ /** A hover-and-focus tooltip for a control, portalled above everything. Words only; not the only home of information. */
345
+ function Tooltip$1({ label, hint, children, side = "top", delay = 500, open, className }) {
346
+ return /* @__PURE__ */ jsxs(TooltipTrigger, {
347
+ delay,
348
+ closeDelay: 0,
349
+ isOpen: open,
350
+ children: [children, /* @__PURE__ */ jsxs(Tooltip, {
351
+ placement: side,
352
+ offset: 6,
353
+ className: cn("layer-tip enter-overlay max-w-xs rounded-control bg-foreground px-2 py-1 type-caption text-background", className),
354
+ children: [label, hint != null && /* @__PURE__ */ jsx("span", {
355
+ className: "ml-2 opacity-70",
356
+ children: typeof hint === "string" ? /* @__PURE__ */ jsx(KeyText, { children: hint }) : hint
357
+ })]
358
+ })]
359
+ });
360
+ }
361
+ // src/lib/search-param.ts
362
+ /**
363
+ * One value held in a URL search parameter (React Router): `const [mode, setMode] = useSearchParam("mode", { default: "all", parse: isMode })`.
364
+ * Reads and validates it, drops the param when set to the default or `null`, keeps the others, and replaces the history entry by default.
365
+ */
366
+ function useSearchParam(key, { default: fallback, parse, replace = true }) {
367
+ const [params, setParams] = useSearchParams();
368
+ const raw = params.get(key);
369
+ let value = fallback;
370
+ if (raw !== null) {
371
+ const parsed = parse ? parse(raw) : raw;
372
+ if (parsed === true) value = raw;
373
+ else if (typeof parsed === "string") value = parsed;
374
+ }
375
+ const set = React.useCallback((next) => setParams((p) => {
376
+ const out = new URLSearchParams(p);
377
+ if (next === null || next === fallback) out.delete(key);
378
+ else out.set(key, next);
379
+ return out;
380
+ }, { replace }), [
381
+ key,
382
+ fallback,
383
+ replace,
384
+ setParams
385
+ ]);
386
+ return [value, set];
387
+ }
388
+ // src/lib/control.ts
389
+ /** The height class of each control size. */
390
+ var controlHeight = {
391
+ default: "h-(--control-h)",
392
+ sm: "h-(--control-h-sm)"
393
+ };
394
+ // src/components/field.tsx
395
+ var FieldContext = React.createContext(null);
396
+ /** @internal The surrounding Field, and where a control reports its own message. */
397
+ function useFieldControl() {
398
+ const field = React.useContext(FieldContext);
399
+ return {
400
+ field,
401
+ report: field?.report ?? noReport
402
+ };
403
+ }
404
+ function useField(id) {
405
+ const field = React.useContext(FieldContext);
406
+ return {
407
+ id: field?.id ?? id,
408
+ "aria-describedby": field?.describedBy,
409
+ "aria-invalid": field?.invalid || void 0
410
+ };
411
+ }
412
+ var noReport = () => {};
413
+ /** A labelled form field: wires the label, hint, error, `aria-describedby` and `aria-invalid` into the one control it wraps. */
414
+ function Field({ label, id: idProp, hint, error, action, children, className }) {
415
+ const generated = React.useId();
416
+ const id = idProp ?? generated;
417
+ const hintId = hint ? `${id}-hint` : void 0;
418
+ const [reported, report] = React.useState();
419
+ const shown = error ?? reported;
420
+ const errorId = shown ? `${id}-error` : void 0;
421
+ const describedBy = [errorId, hintId].filter(Boolean).join(" ") || void 0;
422
+ return /* @__PURE__ */ jsx(FieldContext.Provider, {
423
+ value: {
424
+ id,
425
+ label,
426
+ describedBy,
427
+ invalid: Boolean(shown),
428
+ report
429
+ },
430
+ children: /* @__PURE__ */ jsxs("div", {
431
+ className: cn("grid min-w-0 content-start gap-1.5", className),
432
+ children: [
433
+ /* @__PURE__ */ jsx("label", {
434
+ htmlFor: id,
435
+ className: "type-label text-foreground",
436
+ children: label
437
+ }),
438
+ action ? /* @__PURE__ */ jsxs("div", {
439
+ className: "flex flex-wrap items-start gap-2",
440
+ children: [/* @__PURE__ */ jsx("div", {
441
+ className: "min-w-40 flex-1",
442
+ children
443
+ }), /* @__PURE__ */ jsx("div", {
444
+ className: "flex shrink-0 items-center",
445
+ children: action
446
+ })]
447
+ }) : children,
448
+ shown && /* @__PURE__ */ jsxs("p", {
449
+ id: errorId,
450
+ className: "flex items-start gap-1.5 type-body-sm text-danger",
451
+ children: [/* @__PURE__ */ jsx(CircleAlert, {
452
+ "aria-hidden": true,
453
+ className: "mt-0.5 size-4 shrink-0"
454
+ }), shown]
455
+ }),
456
+ hint && /* @__PURE__ */ jsx("p", {
457
+ id: hintId,
458
+ className: "type-body-sm text-muted-foreground",
459
+ children: hint
460
+ })
461
+ ]
462
+ })
463
+ });
464
+ }
465
+ 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";
466
+ /** 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. */
467
+ function Input$1({ className, id, size = "default", ...props }) {
468
+ return /* @__PURE__ */ jsx("input", {
469
+ ...useField(id),
470
+ className: cn(control, controlHeight[size], className),
471
+ ...props
472
+ });
473
+ }
474
+ /** A multi-line input that picks up its id and descriptions from the surrounding `Field`. */
475
+ function Textarea({ className, id, ...props }) {
476
+ return /* @__PURE__ */ jsx("textarea", {
477
+ ...useField(id),
478
+ className: cn(control, "min-h-24 py-2", className),
479
+ ...props
480
+ });
481
+ }
482
+ /** The platform select, styled. The default for short lists, especially on touch screens. `size="sm"` is --control-h-sm. */
483
+ function NativeSelect(props) {
484
+ return props.param === void 0 ? /* @__PURE__ */ jsx(PlainSelect, { ...props }) : /* @__PURE__ */ jsx(ParamSelect, { ...props });
485
+ }
486
+ function PlainSelect({ className, id, size = "default", ...props }) {
487
+ return /* @__PURE__ */ jsx("select", {
488
+ ...useField(id),
489
+ className: cn(control, controlHeight[size], "pr-8", className),
490
+ ...props
491
+ });
492
+ }
493
+ /** The values of every `<option>`, looking inside `<optgroup>`s and fragments. */
494
+ function optionValues(children) {
495
+ return React.Children.toArray(children).flatMap((c) => {
496
+ if (!React.isValidElement(c)) return [];
497
+ if (c.type === "option") return [c.props.value ?? String(c.props.children)];
498
+ return optionValues(c.props.children);
499
+ });
500
+ }
501
+ function ParamSelect({ param, paramDefault, onChange, children, ...props }) {
502
+ const options = optionValues(children);
503
+ const [value, setValue] = useSearchParam(param, {
504
+ default: paramDefault,
505
+ parse: (raw) => options.length === 0 || options.includes(raw)
506
+ });
507
+ return /* @__PURE__ */ jsx(PlainSelect, {
508
+ ...props,
509
+ value,
510
+ onChange: (e) => {
511
+ setValue(e.target.value);
512
+ onChange?.(e.target.value);
513
+ },
514
+ children
515
+ });
516
+ }
517
+ /** 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. */
518
+ function ChoiceGroup(props) {
519
+ return props.param === void 0 ? /* @__PURE__ */ jsx(ChoiceGroupView, { ...props }) : /* @__PURE__ */ jsx(ParamChoiceGroup, { ...props });
520
+ }
521
+ function ParamChoiceGroup({ param, choices, onChange, ...props }) {
522
+ const [value, setValue] = useSearchParam(param, {
523
+ default: choices[0]?.value ?? "",
524
+ parse: (raw) => choices.some((c) => c.value === raw)
525
+ });
526
+ return /* @__PURE__ */ jsx(ChoiceGroupView, {
527
+ ...props,
528
+ choices,
529
+ value,
530
+ onChange: (next) => {
531
+ setValue(next);
532
+ onChange?.(next);
533
+ }
534
+ });
535
+ }
536
+ function ChoiceGroupView({ legend, name, choices, value, onChange, error }) {
537
+ const errorId = React.useId();
538
+ return /* @__PURE__ */ jsxs(RadioGroup, {
539
+ name,
540
+ value,
541
+ onChange,
542
+ "aria-describedby": error ? errorId : void 0,
543
+ className: "grid gap-2",
544
+ children: [
545
+ /* @__PURE__ */ jsx(Label, {
546
+ className: "mb-1.5 type-label text-foreground",
547
+ children: legend
548
+ }),
549
+ choices.map((c) => /* @__PURE__ */ jsxs(Radio, {
550
+ value: c.value,
551
+ className: "group flex min-h-(--control-h-sm) cursor-pointer items-start gap-3 py-1",
552
+ children: [
553
+ /* @__PURE__ */ jsx("span", {
554
+ "aria-hidden": true,
555
+ 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",
556
+ children: /* @__PURE__ */ jsx("span", { className: "size-2 rounded-pill bg-primary opacity-0 group-selected:opacity-100" })
557
+ }),
558
+ c.leading && /* @__PURE__ */ jsx("span", {
559
+ className: "mt-0.5 shrink-0",
560
+ children: c.leading
561
+ }),
562
+ /* @__PURE__ */ jsxs("span", {
563
+ className: "grid",
564
+ children: [/* @__PURE__ */ jsx("span", {
565
+ className: "type-body",
566
+ children: c.label
567
+ }), c.detail && /* @__PURE__ */ jsx("span", {
568
+ className: "type-body-sm text-muted-foreground",
569
+ children: c.detail
570
+ })]
571
+ })
572
+ ]
573
+ }, c.value)),
574
+ error && /* @__PURE__ */ jsxs("p", {
575
+ id: errorId,
576
+ className: "flex items-start gap-1.5 type-body-sm text-danger",
577
+ children: [/* @__PURE__ */ jsx(CircleAlert, {
578
+ "aria-hidden": true,
579
+ className: "mt-0.5 size-4 shrink-0"
580
+ }), error]
581
+ })
582
+ ]
583
+ });
584
+ }
585
+ export { typeSteps as _, Textarea as a, useSearchParam as c, MISSING as d, NBSP as f, cn as g, toDate as h, NativeSelect as i, Tooltip$1 as l, format as m, Field as n, useFieldControl as o, createFormat as p, Input$1 as r, controlHeight as s, ChoiceGroup as t, KeyText as u };
586
+
587
+ //# sourceMappingURL=field-t4Hoer0d.js.map