strata-react 1.0.33 → 1.0.35

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 (55) hide show
  1. package/README.md +12 -2
  2. package/UPGRADING.md +1 -0
  3. package/dist/components/conversation.d.ts +67 -0
  4. package/dist/components/dialog.d.ts +1 -1
  5. package/dist/components/folder-picker.d.ts +42 -0
  6. package/dist/components/lightbox.d.ts +34 -0
  7. package/dist/components/markable-text.d.ts +56 -0
  8. package/dist/components/media-group.d.ts +25 -0
  9. package/dist/components/media-player.d.ts +80 -2
  10. package/dist/components/region-editor.d.ts +55 -0
  11. package/dist/components/sequence-timeline.d.ts +50 -0
  12. package/dist/components/transcript-view.d.ts +36 -0
  13. package/dist/components/tree.d.ts +41 -0
  14. package/dist/components/waveform.d.ts +66 -0
  15. package/dist/{cursor-DplHNzj3.js → cursor-DDGBPiTJ.js} +2 -200
  16. package/dist/cursor-DDGBPiTJ.js.map +1 -0
  17. package/dist/field-7Z4N5r5g.js +178 -0
  18. package/dist/field-7Z4N5r5g.js.map +1 -0
  19. package/dist/format-B32-PVi2.js +201 -0
  20. package/dist/format-B32-PVi2.js.map +1 -0
  21. package/dist/hls/index.d.ts +19 -0
  22. package/dist/hls.js +84 -0
  23. package/dist/hls.js.map +1 -0
  24. package/dist/index.d.ts +17 -1
  25. package/dist/index.js +3454 -568
  26. package/dist/index.js.map +1 -1
  27. package/dist/lib/marks.d.ts +6 -0
  28. package/dist/lib/region.d.ts +46 -0
  29. package/dist/lib/rich-text.d.ts +44 -0
  30. package/dist/lib/sequence.d.ts +34 -0
  31. package/dist/lib/transcript.d.ts +28 -0
  32. package/dist/lib/waveform.d.ts +36 -0
  33. package/dist/map.js +4 -2
  34. package/dist/map.js.map +1 -1
  35. package/dist/panorama/gl.d.ts +16 -0
  36. package/dist/panorama/index.d.ts +2 -0
  37. package/dist/panorama/panorama-viewer.d.ts +56 -0
  38. package/dist/panorama/projection.d.ts +45 -0
  39. package/dist/panorama.js +657 -0
  40. package/dist/panorama.js.map +1 -0
  41. package/dist/{query-DgJMyXTT.js → query-BJcxJLhh.js} +3 -2
  42. package/dist/{query-DgJMyXTT.js.map → query-BJcxJLhh.js.map} +1 -1
  43. package/dist/{run-BqZGKhW9.js → run-DzyLrZlA.js} +23 -5
  44. package/dist/run-DzyLrZlA.js.map +1 -0
  45. package/dist/testing.js +2 -2
  46. package/dist/{theme-BgTOESmN.js → theme-CFNi6WUO.js} +5 -175
  47. package/dist/theme-CFNi6WUO.js.map +1 -0
  48. package/dist/value-controls-D6O9TsM6.js +356 -0
  49. package/dist/value-controls-D6O9TsM6.js.map +1 -0
  50. package/dist/visual-cli.js +1 -1
  51. package/dist/visual.js +1 -1
  52. package/package.json +19 -4
  53. package/dist/cursor-DplHNzj3.js.map +0 -1
  54. package/dist/run-BqZGKhW9.js.map +0 -1
  55. package/dist/theme-BgTOESmN.js.map +0 -1
@@ -0,0 +1,66 @@
1
+ import { DecodedAudio, WaveformPeaks } from '../lib/waveform';
2
+ import * as React from "react";
3
+ /** What a mark is, which sets how its line is drawn. */
4
+ export type WaveformMarkKind = "beat" | "bar" | "downbeat" | "chapter";
5
+ /** A moment on the waveform: a beat, a bar line, the first downbeat, a chapter. */
6
+ export type WaveformMark = {
7
+ time: number;
8
+ label?: string;
9
+ kind?: WaveformMarkKind; /** In the list for screen readers. Default: yes, except beats. */
10
+ listed?: boolean;
11
+ };
12
+ /** Shading tones for spans. */
13
+ export type WaveformTone = "neutral" | "info" | "success" | "warning" | "danger";
14
+ /** A stretch of the file: voice, silence, a chosen part. */
15
+ export type WaveformSpan = {
16
+ from: number;
17
+ to: number;
18
+ label: string;
19
+ tone?: WaveformTone;
20
+ };
21
+ type Common = {
22
+ /** Names the waveform: "Waveform of the interview". */
23
+ label: string;
24
+ /** Seconds. Needed with `peaks`; with `source` it defaults to the decoded file's. */
25
+ duration?: number;
26
+ /** The playhead, seconds. */
27
+ time: number;
28
+ /** A click, a drag or a key moved the playhead. */
29
+ onSeek: (time: number) => void;
30
+ marks?: readonly WaveformMark[];
31
+ spans?: readonly WaveformSpan[];
32
+ /** A picture under the plot on the same x axis (a spectrogram `<img>`): it is stretched to the file's length and follows the zoom. */
33
+ underlay?: React.ReactNode;
34
+ /** The chosen range, seconds, or null. Leave out to let the component hold it. */
35
+ range?: readonly [number, number] | null;
36
+ onRangeChange?: (range: [number, number] | null) => void;
37
+ /** Seconds an arrow key moves. Default 5. */
38
+ step?: number;
39
+ /** Seconds Shift or a Page key moves. Default 30. */
40
+ bigStep?: number;
41
+ /** The part of the file shown at first, seconds (zoomed in). The component keeps the view after that. */
42
+ defaultView?: readonly [number, number];
43
+ /** How many peaks a decoded file is reduced to. Default 2000. */
44
+ buckets?: number;
45
+ /** Turns a decoded file into samples. Default: the browser's `AudioContext.decodeAudioData`. */
46
+ decode?: (data: ArrayBuffer) => Promise<DecodedAudio>;
47
+ /** The words of the reading state; defaults say "Reading the waveform". */
48
+ words?: {
49
+ running: string;
50
+ finished: string;
51
+ failed: string;
52
+ };
53
+ disabled?: boolean;
54
+ className?: string;
55
+ };
56
+ /** `peaks` or a `source` to decode: one of them, so a waveform with nothing to draw cannot be written. */
57
+ export type WaveformProps = Common & ({
58
+ peaks: WaveformPeaks;
59
+ source?: never;
60
+ } | {
61
+ source: string | Blob;
62
+ peaks?: never;
63
+ });
64
+ /** An audio waveform with marks, spans and a playhead: one slider you click, drag or key to seek, zoom, and a range to select. */
65
+ export declare function Waveform({ label, peaks, source, duration: given, time, onSeek, marks, spans, underlay, range: controlledRange, onRangeChange, step, bigStep, defaultView, buckets, decode, words, disabled, className }: WaveformProps): React.JSX.Element;
66
+ export {};
@@ -1,203 +1,5 @@
1
1
  import * as React from "react";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
- // src/lib/format.ts
4
- var NBSP = "\xA0";
5
- /** The placeholder printed for a value that is not known: an en dash. */
6
- var MISSING = "–";
7
- var BYTE_UNITS = [
8
- "B",
9
- "kB",
10
- "MB",
11
- "GB",
12
- "TB",
13
- "PB"
14
- ];
15
- var BYTE_SIZE = Object.fromEntries(BYTE_UNITS.map((u, i) => [u, 1e3 ** i]));
16
- /** A Date from a Date, an ISO string or epoch milliseconds; throws a RangeError naming the input when it is not a date. */
17
- function toDate(value) {
18
- const date = value instanceof Date ? value : new Date(value);
19
- if (Number.isNaN(date.getTime())) throw new RangeError(`Not a date: ${JSON.stringify(String(value))}`);
20
- return date;
21
- }
22
- function callableDate(df, missing) {
23
- const format = (value) => value == null ? missing : df.format(toDate(value));
24
- return Object.assign(format, {
25
- format,
26
- formatToParts: (value) => df.formatToParts(toDate(value)),
27
- formatRange: (start, end) => df.formatRange(toDate(start), toDate(end)),
28
- resolvedOptions: () => df.resolvedOptions()
29
- });
30
- }
31
- function callable(nf, missing) {
32
- const format = (value) => value == null ? missing : nf.format(value);
33
- return Object.assign(format, {
34
- format,
35
- formatToParts: (value) => nf.formatToParts(value),
36
- resolvedOptions: () => nf.resolvedOptions()
37
- });
38
- }
39
- var DAY = 864e5;
40
- var AGO_STEPS = [
41
- ["year", 365 * DAY],
42
- ["month", 30 * DAY],
43
- ["week", 7 * DAY],
44
- ["day", DAY],
45
- ["hour", 36e5],
46
- ["minute", 6e4]
47
- ];
48
- /** 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. */
49
- function createFormat(locale, options = {}) {
50
- const { timeZone, missing = "–" } = options;
51
- const dates = (opts) => callableDate(new Intl.DateTimeFormat(locale, {
52
- ...opts,
53
- timeZone
54
- }), missing);
55
- const integer = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }), missing);
56
- const decimal = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }), missing);
57
- const percent = callable(new Intl.NumberFormat(locale, {
58
- style: "percent",
59
- maximumFractionDigits: 0
60
- }), missing);
61
- const compact = callable(new Intl.NumberFormat(locale, {
62
- notation: "compact",
63
- maximumFractionDigits: 1
64
- }), missing);
65
- const relative = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
66
- const plurals = new Intl.PluralRules(locale);
67
- const clock = dates({
68
- hour: "2-digit",
69
- minute: "2-digit"
70
- });
71
- const day = dates({
72
- weekday: "long",
73
- day: "numeric",
74
- month: "long"
75
- });
76
- const shortDay = dates({
77
- weekday: "short",
78
- hour: "2-digit",
79
- minute: "2-digit"
80
- });
81
- const date = dates({ dateStyle: "medium" });
82
- const dateTime = dates({
83
- dateStyle: "medium",
84
- timeStyle: "short"
85
- });
86
- const withUnit = (value, unit, fmt = integer) => `${fmt.format(value)} ${unit}`;
87
- return {
88
- locale,
89
- /** The zone times are shown in, or `undefined` for the viewer's own. */
90
- timeZone,
91
- /** Whole numbers with grouping: `format.integer(1222)` is "1,222". */
92
- integer,
93
- /** One decimal place at most: `format.decimal(3.14)` is "3.1". */
94
- decimal,
95
- /** A ratio as a whole percent: `format.percent(0.42)` is "42%". */
96
- percent,
97
- /**
98
- * A part's share of a whole, as `percent` but never misleading at the ends: a part above 0 that
99
- * rounds to 0 is "<1%", and one short of the whole that rounds to 100 is ">99%".
100
- * `format.share(2.4 / 512)` is "<1%".
101
- */
102
- share: (value) => {
103
- if (value == null || Number.isNaN(value)) return missing;
104
- if (value > 0 && value < .005) return `<${percent.format(.01)}`;
105
- if (value >= .995 && value < 1) return `>${percent.format(.99)}`;
106
- return percent.format(value);
107
- },
108
- /** 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. */
109
- compact,
110
- /**
111
- * How long ago (or how far ahead) a time is, in the largest unit it reaches:
112
- * "3 weeks ago", "yesterday", "in 2 hours", "now" under a minute. Pass `now` in tests.
113
- */
114
- ago: (value, now = /* @__PURE__ */ new Date()) => {
115
- if (value == null) return missing;
116
- const diff = toDate(value).getTime() - toDate(now).getTime();
117
- const span = Math.abs(diff);
118
- for (const [unit, size] of AGO_STEPS) if (span >= size) return relative.format(Math.sign(diff) * Math.floor(span / size), unit);
119
- return relative.format(0, "second");
120
- },
121
- /**
122
- * A media running time from seconds, as a player shows it: "4:05", "1:02:09". Unknown
123
- * (null, negative, not finite) prints the placeholder. Set it in `tabular-nums`.
124
- */
125
- runningTime: (seconds) => {
126
- if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return missing;
127
- const s = Math.floor(seconds);
128
- const two = (n) => String(n).padStart(2, "0");
129
- const [h, m] = [Math.floor(s / 3600), Math.floor(s % 3600 / 60)];
130
- return h > 0 ? `${h}:${two(m)}:${two(s % 60)}` : `${m}:${two(s % 60)}`;
131
- },
132
- /**
133
- * A position in media as an editor shows it, to a chosen precision: "4:05" (seconds), "4:05.250"
134
- * (`"ms"`), or "0:04:05:07" (`"frames"` at `fps`, the last part the frame). Hours appear only
135
- * from one hour, except in frames. Frames are always four parts, hours included, as SMPTE
136
- * timecode is (non-drop frame, with colons): a three-part "1:05:00" reads as one hour five, so
137
- * a frame count must never be three. Editors write the same four parts (strata-react issue
138
- * #122). Floors, never rounds up, so a time never reads ahead of the picture. Unknown (null,
139
- * negative, not finite) prints the placeholder. Set it in `tabular-nums`.
140
- */
141
- timecode: (seconds, { precision = "seconds", fps = 30 } = {}) => {
142
- if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return missing;
143
- const whole = Math.floor(seconds);
144
- const two = (n) => String(n).padStart(2, "0");
145
- const [h, m] = [Math.floor(whole / 3600), Math.floor(whole % 3600 / 60)];
146
- const base = h > 0 ? `${h}:${two(m)}:${two(whole % 60)}` : `${m}:${two(whole % 60)}`;
147
- if (precision === "ms") return `${base}.${String(Math.min(Math.floor((seconds - whole) * 1e3 + 1e-6), 999)).padStart(3, "0")}`;
148
- if (precision === "frames") return `${h}:${two(m)}:${two(whole % 60)}:${two(Math.min(Math.floor((seconds - whole) * fps + 1e-6), Math.ceil(fps) - 1))}`;
149
- return base;
150
- },
151
- /** What a missing value prints as: an en dash unless `createFormat`'s `missing` says otherwise. */
152
- missing,
153
- /** A time of day: `format.clock(at)` is "06:05". */
154
- clock,
155
- /** A day without its year, for this week's things: `format.day(at)` is "Sunday 8 November". */
156
- day,
157
- /** A weekday and time, for chart axes and recent rows: `format.shortDay(at)` is "Sun 06:05". */
158
- shortDay,
159
- /** A date with its year, for a record or a deadline: `format.date(at)` is "8 Nov 2026". */
160
- date,
161
- /** A date and time, for a log or history row: `format.dateTime(at)` is "8 Nov 2026, 06:05". */
162
- dateTime,
163
- /** A figure and its unit joined by a non-breaking space (`NBSP`), so they never wrap apart. */
164
- withUnit,
165
- /** A temperature in °C, joined by a non-breaking space. */
166
- celsius: (value) => withUnit(value, "°C"),
167
- /**
168
- * A size in bytes in the largest decimal unit it reaches (kB, MB, GB, TB, as disks and
169
- * networks are sold): one decimal below 10 ("5.2 GB"), whole above ("431 GB"). Pass `unit`
170
- * to fix the unit, so figures compared side by side ("431 of 466 GB") share one.
171
- */
172
- bytes: (value, unit) => {
173
- const chosen = unit ?? [...BYTE_UNITS].reverse().find((u) => Math.abs(value) >= BYTE_SIZE[u]) ?? "B";
174
- const scaled = value / BYTE_SIZE[chosen];
175
- return withUnit(scaled, chosen, Math.abs(scaled) < 10 && chosen !== "B" ? decimal : integer);
176
- },
177
- /**
178
- * A distance in metres as a person says it: metres under a kilometre ("850 m"), then
179
- * kilometres, one decimal below 100 ("12.4 km"), whole above; `"imperial"` is feet under a
180
- * tenth of a mile ("320 ft"), then miles ("7.7 mi").
181
- */
182
- distance: (metres, system = "metric") => {
183
- if (system === "imperial") {
184
- const miles = metres / 1609.344;
185
- return miles < .1 ? withUnit(metres * 3.28084, "ft") : withUnit(miles, "mi", miles < 100 ? decimal : integer);
186
- }
187
- return Math.abs(metres) < 1e3 ? withUnit(metres, "m") : withUnit(metres / 1e3, "km", Math.abs(metres) < 1e5 ? decimal : integer);
188
- },
189
- /** The unit `bytes` would choose for a value, to share it across a set of figures. */
190
- byteUnit: (value) => [...BYTE_UNITS].reverse().find((u) => Math.abs(value) >= BYTE_SIZE[u]) ?? "B",
191
- /**
192
- * "1 piece", "6 pieces": the count and its noun, so copy never reads "1 pieces". They are
193
- * joined by a non-breaking space (`NBSP`), not a plain one: in a test, match with the same
194
- * call or a `\s` regex, not a typed "6 pieces" string in a role's `name`.
195
- */
196
- count: (value, one, many = `${one}s`, { compact: short = false } = {}) => value == null ? missing : `${(short ? compact : integer).format(value)} ${plurals.select(value) === "one" ? one : many}`
197
- };
198
- }
199
- /** The en-GB formatters. */
200
- var format = createFormat("en-GB");
201
3
  // src/lib/geo.ts
202
4
  var RAD = Math.PI / 180;
203
5
  var EARTH_RADIUS_M = 6371e3;
@@ -483,6 +285,6 @@ function useSharedCursor(source) {
483
285
  setPlayback
484
286
  ]);
485
287
  }
486
- export { NBSP as a, toDate as c, MISSING as i, useSharedCursor as n, createFormat as o, geo as r, format as s, CursorScope as t };
288
+ export { useSharedCursor as n, geo as r, CursorScope as t };
487
289
 
488
- //# sourceMappingURL=cursor-DplHNzj3.js.map
290
+ //# sourceMappingURL=cursor-DDGBPiTJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor-DDGBPiTJ.js","names":[],"sources":["../src/lib/geo.ts","../src/components/cursor.tsx"],"sourcesContent":["// Geometry for routes on a map (strata-react issue #80; the helpers jonathanburnhams.com wrote by\n// hand for its activity maps). Pure functions on `[latitude, longitude]` pairs in degrees, no map\n// library, so they live in the main entry and an app can use them for a text alternative or a\n// profile without installing the map's peer.\n//\n// Distances are great-circle (haversine) on a 6,371 km sphere, which is within half a percent of\n// the true figure at any route length a person runs, rides or drives. Bearings use a flat\n// approximation between neighbouring points (the longitude scaled by the cosine of the mean\n// latitude), fine for the short hops a chevron or a heading needs and wrong for a leg of hundreds\n// of kilometres: `bearing` is for neighbouring points, not for a flight.\n\n/** A position: `[latitude, longitude]` in degrees. */\nexport type LatLng = readonly [lat: number, lng: number];\n\nconst RAD = Math.PI / 180;\nconst EARTH_RADIUS_M = 6_371_000;\n\n/** Great-circle distance between two positions, in metres. */\nexport function distance([lat1, lng1]: LatLng, [lat2, lng2]: LatLng): number {\n const a = Math.sin(((lat2 - lat1) * RAD) / 2) ** 2 + Math.cos(lat1 * RAD) * Math.cos(lat2 * RAD) * Math.sin(((lng2 - lng1) * RAD) / 2) ** 2;\n return 2 * EARTH_RADIUS_M * Math.asin(Math.sqrt(a));\n}\n\n/** The direction from `a` to `b` in degrees clockwise from north (0 to 360), for neighbouring points. */\nexport function bearing([lat1, lng1]: LatLng, [lat2, lng2]: LatLng): number {\n const dx = (lng2 - lng1) * Math.cos((((lat1 + lat2) / 2) * Math.PI) / 180);\n const dy = lat2 - lat1;\n return ((Math.atan2(dx, dy) * 180) / Math.PI + 360) % 360;\n}\n\n/** The running distance along a route at each point, in metres, starting at 0. */\nexport function cumulative(points: readonly LatLng[]): number[] {\n const out = points.length ? [0] : [];\n for (let i = 1; i < points.length; i++) out.push(out[i - 1] + distance(points[i - 1], points[i]));\n return out;\n}\n\n/** The length of a route in metres. */\nexport function length(points: readonly LatLng[]): number {\n let total = 0;\n for (let i = 1; i < points.length; i++) total += distance(points[i - 1], points[i]);\n return total;\n}\n\n/** The south-west and north-east corners that hold every point, or null for none. */\nexport function bounds(points: readonly LatLng[]): [LatLng, LatLng] | null {\n if (!points.length) return null;\n let south = Infinity;\n let north = -Infinity;\n let west = Infinity;\n let east = -Infinity;\n for (const [lat, lng] of points) {\n if (lat < south) south = lat;\n if (lat > north) north = lat;\n if (lng < west) west = lng;\n if (lng > east) east = lng;\n }\n return [\n [south, west],\n [north, east],\n ];\n}\n\n/** The position `metres` along a route (clamped to its ends), by linear interpolation, or null for no points. */\nexport function pointAlong(points: readonly LatLng[], metres: number, along: readonly number[] = cumulative(points)): LatLng | null {\n if (!points.length) return null;\n const total = along[along.length - 1];\n const d = Math.min(Math.max(metres, 0), total);\n if (points.length === 1 || total === 0) return points[0];\n let lo = 1;\n let hi = points.length - 1;\n while (lo < hi) {\n const mid = (lo + hi) >> 1;\n if (along[mid] < d) lo = mid + 1;\n else hi = mid;\n }\n const [p, q] = [points[lo - 1], points[lo]];\n const t = (d - along[lo - 1]) / (along[lo] - along[lo - 1] || 1);\n return [p[0] + (q[0] - p[0]) * t, p[1] + (q[1] - p[1]) * t];\n}\n\n/**\n * `count` positions evenly spaced by distance along a route (the ends skipped), each with the\n * direction of travel there. The direction is smoothed: the bearing from a point a fraction\n * (`window`) of the spacing before to one the same distance after, so GPS jitter and a tight bend\n * do not turn a chevron sideways.\n */\nexport function arrows(points: readonly LatLng[], count = 5, window = 0.4): { position: LatLng; bearing: number }[] {\n if (points.length < 2 || count < 1) return [];\n const along = cumulative(points);\n const total = along[along.length - 1];\n if (total === 0) return [];\n const spacing = total / (count + 1);\n const half = spacing * window;\n return Array.from({ length: count }, (_, i) => {\n const target = spacing * (i + 1);\n const before = pointAlong(points, target - half, along)!;\n const after = pointAlong(points, target + half, along)!;\n return { position: pointAlong(points, target, along)!, bearing: bearing(before, after) };\n });\n}\n\n/** The first and last positions, and whether they are within `loopWithin` metres of each other (a loop), or null for no route. */\nexport function ends(points: readonly LatLng[], loopWithin = 50): { start: LatLng; finish: LatLng; loop: boolean } | null {\n if (!points.length) return null;\n const start = points[0];\n const finish = points[points.length - 1];\n return { start, finish, loop: distance(start, finish) <= loopWithin };\n}\n\n/** The index of the point nearest `position`, for \"where on the route is this?\". */\nexport function nearest(points: readonly LatLng[], position: LatLng): number {\n let best = -1;\n let bestD = Infinity;\n points.forEach((p, i) => {\n const d = distance(p, position);\n if (d < bestD) {\n bestD = d;\n best = i;\n }\n });\n return best;\n}\n\n/** The part of a route between two distances along it (metres, clamped, either order): the cut ends and every point between. Empty for no route. */\nexport function slice(points: readonly LatLng[], from: number, to: number, along: readonly number[] = cumulative(points)): LatLng[] {\n if (!points.length) return [];\n const [a, b] = from <= to ? [from, to] : [to, from];\n const start = pointAlong(points, a, along)!;\n const end = pointAlong(points, b, along)!;\n const lo = Math.max(a, 0);\n const hi = Math.min(b, along[along.length - 1]);\n const inside = points.filter((_, i) => along[i] > lo && along[i] < hi);\n return [start, ...inside, end];\n}\n\n/**\n * The nearest point on a route to `position`, not only its vertices: where it lies, how far along the\n * route that is, and how far `position` is from the route. The inverse of `pointAlong` (a cursor on a\n * map is a distance on a chart). Each leg is flattened around its own latitude, which is exact enough\n * for any leg a recording has; `index` is the leg's first point. Null for fewer than one point.\n */\nexport function snap(points: readonly LatLng[], position: LatLng, along: readonly number[] = cumulative(points)): { position: LatLng; metres: number; offset: number; index: number } | null {\n if (!points.length) return null;\n if (points.length === 1) return { position: points[0], metres: 0, offset: distance(points[0], position), index: 0 };\n let best: { position: LatLng; metres: number; offset: number; index: number } | null = null;\n for (let i = 1; i < points.length; i++) {\n const [p, q] = [points[i - 1], points[i]];\n const k = Math.cos((((p[0] + q[0]) / 2) * Math.PI) / 180);\n const [dx, dy] = [(q[1] - p[1]) * k, q[0] - p[0]];\n const len2 = dx * dx + dy * dy;\n const t = len2 === 0 ? 0 : Math.min(1, Math.max(0, (((position[1] - p[1]) * k) * dx + (position[0] - p[0]) * dy) / len2));\n const at: LatLng = [p[0] + (q[0] - p[0]) * t, p[1] + (q[1] - p[1]) * t];\n const offset = distance(at, position);\n if (!best || offset < best.offset) best = { position: at, metres: along[i - 1] + (along[i] - along[i - 1]) * t, offset, index: i - 1 };\n }\n return best;\n}\n\n/** Route geometry helpers: `geo.distance`, `bearing`, `length`, `cumulative`, `bounds`, `pointAlong`, `snap` (its inverse), `slice`, `arrows`, `ends`, `nearest`. */\nexport const geo = { distance, bearing, cumulative, length, bounds, pointAlong, snap, slice, arrows, ends, nearest };\n","import * as React from \"react\";\n\n// A shared cursor: one position that a map, several charts and a seek bar all show at once (strata-react\n// issue #184, from strata-360, where the cursor on the elevation and pace charts is the marker on the\n// route). Each of those components already draws one position well; what an app lacked was the wiring.\n//\n// One position in a canonical unit the app chooses (metres along a route, or seconds), and every member\n// says how its own x maps to it (`CursorMapping`; the identity when they already agree). The rules:\n//\n// - **A writer never reacts to its own writes.** Every member has a `source` id, and a position whose\n// source is its own is not drawn back at it (a chart's own pointer already draws its own rule).\n// - **Two owners, and the pointer wins.** Playback sets the cursor (sixty times a second); a pointer or\n// key over any member sets it too, and holds it until it leaves, and then playback's position is\n// still there. Stored as two entries, not one value, so \"pointer left\" has something to fall back to.\n// - **It is not announced as it moves.** The scope has one polite live region, written at most once a\n// second and only for a pointer or key (never playback): sixty announcements a second are worse than\n// silence (§3.22).\n// - **A store, not state in the scope.** Members subscribe to it; the scope's children do not render\n// when the cursor moves, only the members that read it.\n//\n// Checked: React Aria has no shared-pointer part; `useSyncExternalStore` is React's own.\n\n/** Who set the cursor: a pointer or key over a member, or playback (a player's clock). */\nexport type CursorOwner = \"pointer\" | \"playback\";\n\n/** How a member's own x relates to the scope's unit. Both default to the identity. */\nexport type CursorMapping = {\n /** From this member's x to the scope's unit (a chart in seconds in a scope in metres: look it up in the series). */\n toCursor?: (x: number) => number;\n /** From the scope's unit to this member's x. */\n fromCursor?: (at: number) => number;\n};\n\ntype Entry = { at: number; source: string };\ntype Snapshot = {\n /** The position now: the pointer's while there is one, else playback's; null when neither is set. */\n at: number | null;\n /** Who wrote `at`; a member ignores a position it wrote. */\n source: string | null;\n owner: CursorOwner | null;\n};\n\nconst EMPTY: Snapshot = { at: null, source: null, owner: null };\n\nclass CursorStore {\n private pointer: Entry | null = null;\n private playback: Entry | null = null;\n private listeners = new Set<() => void>();\n snapshot: Snapshot = EMPTY;\n subscribe = (fn: () => void) => {\n this.listeners.add(fn);\n return () => void this.listeners.delete(fn);\n };\n private publish() {\n const e = this.pointer ?? this.playback;\n const owner: CursorOwner | null = this.pointer ? \"pointer\" : this.playback ? \"playback\" : null;\n if (e?.at === this.snapshot.at && e?.source === this.snapshot.source && owner === this.snapshot.owner) return;\n this.snapshot = e ? { at: e.at, source: e.source, owner } : EMPTY;\n for (const l of this.listeners) l();\n }\n /** A pointer or key over a member. `null` means it left: it clears only if the pointer was this member's, so a stale leave cannot remove another member's position. */\n setPointer(at: number | null, source: string) {\n if (at === null) {\n if (this.pointer?.source !== source) return;\n this.pointer = null;\n } else this.pointer = { at, source };\n this.publish();\n }\n setPlayback(at: number | null, source: string) {\n this.playback = at === null ? null : { at, source };\n this.publish();\n }\n}\n\nconst Scope = React.createContext<CursorStore | null>(null);\n\nexport type CursorScopeProps = {\n children: React.ReactNode;\n /** Words for the position in the scope's unit (\"12.4 km along\", \"1:23\"), for the polite announcement. Without it nothing is announced. */\n format?: (at: number) => string;\n /** Milliseconds between announcements. Default 1000. */\n announceEvery?: number;\n};\n\n/** Holds one cursor position for the charts, map and seek bar inside it, with a throttled polite announcement of where a pointer or key has put it. */\nexport function CursorScope({ children, format, announceEvery = 1000 }: CursorScopeProps) {\n const store = React.useRef<CursorStore | null>(null);\n store.current ??= new CursorStore();\n return (\n <Scope.Provider value={store.current}>\n {children}\n {format && <CursorAnnouncer store={store.current} format={format} every={announceEvery} />}\n </Scope.Provider>\n );\n}\n\n/** The live region: the latest pointer position, at most once per `every` ms (a throttle, so a pointer that never rests is still announced). */\nfunction CursorAnnouncer({ store, format, every }: { store: CursorStore; format: (at: number) => string; every: number }) {\n const snap = React.useSyncExternalStore(store.subscribe, () => store.snapshot, () => EMPTY);\n const [text, setText] = React.useState(\"\");\n const latest = React.useRef({ snap, format });\n latest.current = { snap, format };\n const last = React.useRef(0);\n const timer = React.useRef<number | undefined>(undefined);\n React.useEffect(() => {\n // Playback moves the cursor every frame and is never spoken; a pointer leaving says nothing.\n if (snap.owner !== \"pointer\" || snap.at === null) return;\n const speak = () => {\n timer.current = undefined;\n last.current = Date.now();\n const { snap: s, format: f } = latest.current;\n if (s.owner === \"pointer\" && s.at !== null) setText(f(s.at));\n };\n const wait = last.current + every - Date.now();\n if (wait <= 0) speak();\n else timer.current ??= window.setTimeout(speak, wait);\n }, [snap, every]);\n React.useEffect(() => () => window.clearTimeout(timer.current), []);\n return (\n <p role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n {text}\n </p>\n );\n}\n\n/** What a member reads and writes. */\nexport type SharedCursor = Snapshot & {\n /** This member's own id: positions it writes are not drawn back at it. */\n source: string;\n /** The position another member (or playback) put there, in the scope's unit; null when none or when this member wrote it. */\n other: number | null;\n /** The pointer or keyboard is at `at` over this member (the scope's unit). `null`: it left. */\n setPointer: (at: number | null) => void;\n /** Playback is at `at` (the scope's unit). Call it from the player's clock; `null` when it stops. */\n setPlayback: (at: number | null) => void;\n};\n\n/**\n * Join the nearest `CursorScope` as one member. Returns null outside a scope, so a component can take a\n * `cursor` prop and do nothing when the app has not set one up. `source` is this member's id; the\n * default is a unique one.\n */\nexport function useSharedCursor(source?: string): SharedCursor | null {\n const store = React.useContext(Scope);\n const own = React.useId();\n const id = source ?? own;\n const subscribe = React.useCallback((fn: () => void) => (store ? store.subscribe(fn) : () => {}), [store]);\n const snap = React.useSyncExternalStore(subscribe, () => store?.snapshot ?? EMPTY, () => EMPTY);\n const setPointer = React.useCallback((at: number | null) => store?.setPointer(at, id), [store, id]);\n const setPlayback = React.useCallback((at: number | null) => store?.setPlayback(at, id), [store, id]);\n return React.useMemo(\n () => (store ? { ...snap, source: id, other: snap.at !== null && snap.source !== id ? snap.at : null, setPointer, setPlayback } : null),\n [store, snap, id, setPointer, setPlayback],\n );\n}\n"],"mappings":";;;AAcA,IAAM,MAAM,KAAK,KAAK;AACtB,IAAM,iBAAiB;;AAGvB,SAAgB,SAAS,CAAC,MAAM,OAAe,CAAC,MAAM,OAAuB;CAC3E,MAAM,IAAI,KAAK,KAAM,OAAO,QAAQ,MAAO,CAAC,KAAK,IAAI,KAAK,IAAI,OAAO,GAAG,IAAI,KAAK,IAAI,OAAO,GAAG,IAAI,KAAK,KAAM,OAAO,QAAQ,MAAO,CAAC,KAAK;CAC1I,OAAO,IAAI,iBAAiB,KAAK,KAAK,KAAK,KAAK,CAAC,CAAC;AACpD;;AAGA,SAAgB,QAAQ,CAAC,MAAM,OAAe,CAAC,MAAM,OAAuB;CAC1E,MAAM,MAAM,OAAO,QAAQ,KAAK,KAAO,OAAO,QAAQ,IAAK,KAAK,KAAM,GAAG;CAC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C;CAChB,MAAM,sBAAsB,OAAO,aAAa,MAAM,OAAO,GAAG,CAAC,CAAC;CAClE,OACE,oBAAC,KAAD;EAAG,MAAK;EAAS,aAAU;EAAS,WAAU;EAC3C,UAAA;CACA,CAAA;AAEP;;;;;;AAmBA,SAAgB,gBAAgB,QAAsC;CACpE,MAAM,QAAQ,MAAM,WAAW,KAAK;CACpC,MAAM,MAAM,MAAM,MAAM;CACxB,MAAM,KAAK,UAAU;CACrB,MAAM,YAAY,MAAM,aAAa,OAAoB,QAAQ,MAAM,UAAU,EAAE,UAAU,CAAC,GAAI,CAAC,KAAK,CAAC;CACzG,MAAM,OAAO,MAAM,qBAAqB,iBAAiB,OAAO,YAAY,aAAa,KAAK;CAC9F,MAAM,aAAa,MAAM,aAAa,OAAsB,OAAO,WAAW,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;CAClG,MAAM,cAAc,MAAM,aAAa,OAAsB,OAAO,YAAY,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;CACpG,OAAO,MAAM,cACJ,QAAQ;EAAE,GAAG;EAAM,QAAQ;EAAI,OAAO,KAAK,OAAO,QAAQ,KAAK,WAAW,KAAK,KAAK,KAAK;EAAM;EAAY;CAAY,IAAI,MAClI;EAAC;EAAO;EAAM;EAAI;EAAY;CAAW,CAC3C;AACF"}
@@ -0,0 +1,178 @@
1
+ import { clsx } from "clsx";
2
+ import { extendTailwindMerge } from "tailwind-merge";
3
+ import * as React from "react";
4
+ import { Label, Radio, RadioGroup } from "react-aria-components";
5
+ import { CircleAlert } from "lucide-react";
6
+ import { 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
+ // src/lib/control.ts
32
+ /** The height class of each control size. */
33
+ var controlHeight = {
34
+ default: "h-(--control-h)",
35
+ sm: "h-(--control-h-sm)"
36
+ };
37
+ // src/components/field.tsx
38
+ var FieldContext = React.createContext(null);
39
+ /** @internal The surrounding Field, and where a control reports its own message. */
40
+ function useFieldControl() {
41
+ const field = React.useContext(FieldContext);
42
+ return {
43
+ field,
44
+ report: field?.report ?? noReport
45
+ };
46
+ }
47
+ function useField(id) {
48
+ const field = React.useContext(FieldContext);
49
+ return {
50
+ id: field?.id ?? id,
51
+ "aria-describedby": field?.describedBy,
52
+ "aria-invalid": field?.invalid || void 0
53
+ };
54
+ }
55
+ var noReport = () => {};
56
+ /** A labelled form field: wires the label, hint, error, `aria-describedby` and `aria-invalid` into the one control it wraps. */
57
+ function Field({ label, id: idProp, hint, error, action, children, className }) {
58
+ const generated = React.useId();
59
+ const id = idProp ?? generated;
60
+ const hintId = hint ? `${id}-hint` : void 0;
61
+ const [reported, report] = React.useState();
62
+ const shown = error ?? reported;
63
+ const errorId = shown ? `${id}-error` : void 0;
64
+ const describedBy = [errorId, hintId].filter(Boolean).join(" ") || void 0;
65
+ return /* @__PURE__ */ jsx(FieldContext.Provider, {
66
+ value: {
67
+ id,
68
+ label,
69
+ describedBy,
70
+ invalid: Boolean(shown),
71
+ report
72
+ },
73
+ children: /* @__PURE__ */ jsxs("div", {
74
+ className: cn("grid min-w-0 content-start gap-1.5", className),
75
+ children: [
76
+ /* @__PURE__ */ jsx("label", {
77
+ htmlFor: id,
78
+ className: "type-label text-foreground",
79
+ children: label
80
+ }),
81
+ action ? /* @__PURE__ */ jsxs("div", {
82
+ className: "flex flex-wrap items-start gap-2",
83
+ children: [/* @__PURE__ */ jsx("div", {
84
+ className: "min-w-40 flex-1",
85
+ children
86
+ }), /* @__PURE__ */ jsx("div", {
87
+ className: "flex shrink-0 items-center",
88
+ children: action
89
+ })]
90
+ }) : children,
91
+ shown && /* @__PURE__ */ jsxs("p", {
92
+ id: errorId,
93
+ className: "flex items-start gap-1.5 type-body-sm text-danger",
94
+ children: [/* @__PURE__ */ jsx(CircleAlert, {
95
+ "aria-hidden": true,
96
+ className: "mt-0.5 size-4 shrink-0"
97
+ }), shown]
98
+ }),
99
+ hint && /* @__PURE__ */ jsx("p", {
100
+ id: hintId,
101
+ className: "type-body-sm text-muted-foreground",
102
+ children: hint
103
+ })
104
+ ]
105
+ })
106
+ });
107
+ }
108
+ 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";
109
+ /** 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. */
110
+ function Input$1({ className, id, size = "default", ...props }) {
111
+ return /* @__PURE__ */ jsx("input", {
112
+ ...useField(id),
113
+ className: cn(control, controlHeight[size], className),
114
+ ...props
115
+ });
116
+ }
117
+ /** A multi-line input that picks up its id and descriptions from the surrounding `Field`. */
118
+ function Textarea({ className, id, ...props }) {
119
+ return /* @__PURE__ */ jsx("textarea", {
120
+ ...useField(id),
121
+ className: cn(control, "min-h-24 py-2", className),
122
+ ...props
123
+ });
124
+ }
125
+ /** The platform select, styled. The default for short lists, especially on touch screens. `size="sm"` is --control-h-sm. */
126
+ function NativeSelect({ className, id, size = "default", ...props }) {
127
+ return /* @__PURE__ */ jsx("select", {
128
+ ...useField(id),
129
+ className: cn(control, controlHeight[size], "pr-8", className),
130
+ ...props
131
+ });
132
+ }
133
+ /** 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. */
134
+ function ChoiceGroup({ legend, name, choices, value, onChange, error }) {
135
+ const errorId = React.useId();
136
+ return /* @__PURE__ */ jsxs(RadioGroup, {
137
+ name,
138
+ value,
139
+ onChange,
140
+ "aria-describedby": error ? errorId : void 0,
141
+ className: "grid gap-2",
142
+ children: [
143
+ /* @__PURE__ */ jsx(Label, {
144
+ className: "mb-1.5 type-label text-foreground",
145
+ children: legend
146
+ }),
147
+ choices.map((c) => /* @__PURE__ */ jsxs(Radio, {
148
+ value: c.value,
149
+ className: "group flex min-h-(--control-h-sm) cursor-pointer items-start gap-3 py-1",
150
+ children: [/* @__PURE__ */ jsx("span", {
151
+ "aria-hidden": true,
152
+ 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",
153
+ children: /* @__PURE__ */ jsx("span", { className: "size-2 rounded-pill bg-primary opacity-0 group-selected:opacity-100" })
154
+ }), /* @__PURE__ */ jsxs("span", {
155
+ className: "grid",
156
+ children: [/* @__PURE__ */ jsx("span", {
157
+ className: "type-body",
158
+ children: c.label
159
+ }), c.detail && /* @__PURE__ */ jsx("span", {
160
+ className: "type-body-sm text-muted-foreground",
161
+ children: c.detail
162
+ })]
163
+ })]
164
+ }, c.value)),
165
+ error && /* @__PURE__ */ jsxs("p", {
166
+ id: errorId,
167
+ className: "flex items-start gap-1.5 type-body-sm text-danger",
168
+ children: [/* @__PURE__ */ jsx(CircleAlert, {
169
+ "aria-hidden": true,
170
+ className: "mt-0.5 size-4 shrink-0"
171
+ }), error]
172
+ })
173
+ ]
174
+ });
175
+ }
176
+ export { Textarea as a, cn as c, NativeSelect as i, typeSteps as l, Field as n, useFieldControl as o, Input$1 as r, controlHeight as s, ChoiceGroup as t };
177
+
178
+ //# sourceMappingURL=field-7Z4N5r5g.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-7Z4N5r5g.js","names":["Input"],"sources":["../src/lib/utils.ts","../src/lib/control.ts","../src/components/field.tsx"],"sourcesContent":["import { clsx, type ClassValue } from \"clsx\";\nimport { extendTailwindMerge } from \"tailwind-merge\";\n\n// Teach tailwind-merge that `type-*` utilities are font sizes. Without this, cn() cannot tell\n// `type-label` from a colour and may drop one of two classes that both survive in CSS; with stock\n// shadcn the same bug drops `text-muted-foreground` next to a custom `text-*` size.\nexport const typeSteps = [\"caption\", \"label\", \"body-sm\", \"body\", \"heading\", \"title\", \"figure\", \"display\"] as const;\n\n// The radius roles too, so `rounded-pill` at a call site (a round avatar Thumbnail) replaces a\n// component's `rounded-control` instead of both surviving and CSS order picking one.\nconst radiusRoles = [\"control\", \"surface\", \"overlay\", \"pill\"] as const;\n\nconst twMerge = extendTailwindMerge({\n extend: {\n theme: { radius: [...radiusRoles] },\n classGroups: {\n \"font-size\": [{ type: [...typeSteps] }],\n },\n },\n});\n\n/** clsx + tailwind-merge, taught that `type-*` utilities are font sizes and `rounded-control`, `-surface`, `-overlay`, `-pill` are radii. */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","// Control sizes, one set for everything that sits in a toolbar or a property row: `default` is\n// --control-h and `sm` is --control-h-sm, so two controls of the same size name are the same height\n// in every density (issue #117). Button, IconButton, Toggle, ToggleGroup, Input, NativeSelect and\n// NumberField all take it as `size`.\n\n/** The size names a control takes: `default` (--control-h) or `sm` (--control-h-sm). */\nexport type ControlSize = \"default\" | \"sm\";\n\n/** The height class of each control size. */\nexport const controlHeight: Record<ControlSize, string> = {\n default: \"h-(--control-h)\",\n sm: \"h-(--control-h-sm)\",\n};\n","import * as React from \"react\";\nimport { CircleAlert } from \"lucide-react\";\nimport { Label, Radio, RadioGroup } from \"react-aria-components\";\nimport { cn } from \"../lib/utils\";\nimport { controlHeight, type ControlSize } from \"../lib/control\";\n\n// Field owns the wiring a generated form usually forgets: the label's htmlFor, aria-describedby\n// pointing at the hint and the error, and aria-invalid. Controls read it from context, so a control\n// inside a Field cannot end up unlabelled or silently invalid.\n//\n// A one-field form (\"paste a link, Add\", a search box, \"invite by email\") puts its button on the\n// control's row, not beside the whole field (strata-react issue #46, from the Tubes Library\n// screen): in a plain flex row the button lines up with label, hint and error together and drifts\n// off the input whenever one shows. `action` is drawn on the control's row, both at --control-h,\n// with the hint and the error under both across the full width. It wraps under the control only\n// when the row cannot keep the control 10rem wide beside it (a 250px inspector body keeps a Reset beside its slider, issue #116): on a phone a short \"Add\" stays on the\n// row, as a search box's button does, and a long label or a narrow column wraps. The error and hint stay the input's description; the\n// button is not described by them. Field messages for a form come from `useAsyncAction`'s\n// `fieldErrors` (its `validate`, or the server's 422), so no `problem` state is kept by hand.\n\ntype FieldState = { id: string; label: string; describedBy?: string; invalid: boolean; report: (message: string | undefined) => void };\nconst FieldContext = React.createContext<FieldState | null>(null);\n\n// A control that checks what was typed (a number field, a colour field) reports its own message to\n// the Field it sits in, which draws it as the field's error, so a value outside the limits is\n// explained in the same place and way as a server's 422, with nothing for the screen to wire.\n// `error` from the screen wins over the control's own. Outside a Field `report` does nothing and\n// the control marks itself invalid without a message.\n/** @internal The surrounding Field, and where a control reports its own message. */\nexport function useFieldControl() {\n const field = React.useContext(FieldContext);\n return { field, report: field?.report ?? noReport };\n}\n\nfunction useField(id?: string) {\n const field = React.useContext(FieldContext);\n return {\n // Inside a Field the Field's id wins, so the label always points at the control. To choose the\n // id yourself, pass it to Field.\n id: field?.id ?? id,\n \"aria-describedby\": field?.describedBy,\n \"aria-invalid\": field?.invalid || undefined,\n };\n}\n\nconst noReport = () => {};\n\nexport type FieldProps = {\n label: string;\n /** The control's id, when the page needs a known one (an anchor, a test). Generated otherwise. */\n id?: string;\n /** What the person needs to know before typing, such as limits or units. */\n hint?: React.ReactNode;\n /** What went wrong and how to fix it, in one sentence. Shown under the control, never in a toast. */\n error?: string;\n /** A button on the control's row, for a one-field form (an `AsyncButton` \"Add\"). The hint and error run under both; on a narrow screen it wraps under the control. */\n action?: React.ReactNode;\n children: React.ReactNode;\n className?: string;\n};\n\n/** A labelled form field: wires the label, hint, error, `aria-describedby` and `aria-invalid` into the one control it wraps. */\nexport function Field({ label, id: idProp, hint, error, action, children, className }: FieldProps) {\n const generated = React.useId();\n const id = idProp ?? generated;\n const hintId = hint ? `${id}-hint` : undefined;\n const [reported, report] = React.useState<string>();\n const shown = error ?? reported;\n const errorId = shown ? `${id}-error` : undefined;\n const describedBy = [errorId, hintId].filter(Boolean).join(\" \") || undefined;\n\n return (\n <FieldContext.Provider value={{ id, label, describedBy, invalid: Boolean(shown), report }}>\n <div className={cn(\"grid min-w-0 content-start gap-1.5\", className)}>\n <label htmlFor={id} className=\"type-label text-foreground\">\n {label}\n </label>\n {action ? (\n <div className=\"flex flex-wrap items-start gap-2\">\n <div className=\"min-w-40 flex-1\">{children}</div>\n <div className=\"flex shrink-0 items-center\">{action}</div>\n </div>\n ) : (\n children\n )}\n {shown && (\n <p id={errorId} className=\"flex items-start gap-1.5 type-body-sm text-danger\">\n <CircleAlert aria-hidden className=\"mt-0.5 size-4 shrink-0\" />\n {shown}\n </p>\n )}\n {hint && (\n <p id={hintId} className=\"type-body-sm text-muted-foreground\">\n {hint}\n </p>\n )}\n </div>\n </FieldContext.Provider>\n );\n}\n\nconst control =\n \"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\";\n\n/** 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. */\nexport function Input({ className, id, size = \"default\", ...props }: Omit<React.ComponentProps<\"input\">, \"size\"> & { size?: ControlSize }) {\n return <input {...useField(id)} className={cn(control, controlHeight[size], className)} {...props} />;\n}\n\n/** A multi-line input that picks up its id and descriptions from the surrounding `Field`. */\nexport function Textarea({ className, id, ...props }: React.ComponentProps<\"textarea\">) {\n return <textarea {...useField(id)} className={cn(control, \"min-h-24 py-2\", className)} {...props} />;\n}\n\n// A native select, styled. For short option lists on a touch screen it beats a custom listbox:\n// the platform picker, typeahead and form autofill all work with no code.\n/** The platform select, styled. The default for short lists, especially on touch screens. `size=\"sm\"` is --control-h-sm. */\nexport function NativeSelect({ className, id, size = \"default\", ...props }: Omit<React.ComponentProps<\"select\">, \"size\"> & { size?: ControlSize }) {\n return <select {...useField(id)} className={cn(control, controlHeight[size], \"pr-8\", className)} {...props} />;\n}\n\n// Radio choices: React Aria's RadioGroup (a group named by its label, arrow-key movement, one tab\n// stop), and each row wraps its control so the whole row is one hit target. The dot is drawn from\n// tokens, not the platform's accent-color radio.\nexport type Choice = { value: string; label: string; detail?: string };\n\n/** 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. */\nexport function ChoiceGroup({\n legend,\n name,\n choices,\n value,\n onChange,\n error,\n}: {\n legend: string;\n name: string;\n choices: Choice[];\n value: string;\n onChange: (value: string) => void;\n error?: string;\n}) {\n const errorId = React.useId();\n return (\n <RadioGroup name={name} value={value} onChange={onChange} aria-describedby={error ? errorId : undefined} className=\"grid gap-2\">\n <Label className=\"mb-1.5 type-label text-foreground\">{legend}</Label>\n {choices.map((c) => (\n <Radio key={c.value} value={c.value} className=\"group flex min-h-(--control-h-sm) cursor-pointer items-start gap-3 py-1\">\n <span\n aria-hidden\n 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\"\n >\n <span className=\"size-2 rounded-pill bg-primary opacity-0 group-selected:opacity-100\" />\n </span>\n <span className=\"grid\">\n <span className=\"type-body\">{c.label}</span>\n {c.detail && <span className=\"type-body-sm text-muted-foreground\">{c.detail}</span>}\n </span>\n </Radio>\n ))}\n {error && (\n <p id={errorId} className=\"flex items-start gap-1.5 type-body-sm text-danger\">\n <CircleAlert aria-hidden className=\"mt-0.5 size-4 shrink-0\" />\n {error}\n </p>\n )}\n </RadioGroup>\n );\n}\n"],"mappings":";;;;;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