strata-react 1.0.15 → 1.0.20

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/dist/index.js CHANGED
@@ -1,198 +1,17 @@
1
- import { C as describeHttpError, D as cn, E as Tooltip, O as typeSteps, S as describeActionError, T as readErrorBody, _ as NativeSelect, a as toLoad, b as controlHeight, c as ColorSchemeChoice, d as useColorScheme, f as useSystemColorScheme, g as Input, h as Field, i as staleOf, l as ThemeProvider, m as ChoiceGroup, n as createQueryClient, o as useLoad, p as Density, r as fetchJson, s as COLOR_SCHEME_STORAGE_KEY, t as StrataQueryProvider, u as colorSchemeScript, v as Textarea, w as fieldErrorsOf, x as HttpError, y as useFieldControl } from "./query-CIh1Dpgn.js";
1
+ import { _ as cn, a as useColorScheme, c as ChoiceGroup, d as NativeSelect, f as Textarea, g as KeyText, h as Tooltip, i as colorSchemeScript, l as Field, m as controlHeight, n as ColorSchemeChoice, o as useSystemColorScheme, p as useFieldControl, r as ThemeProvider, s as Density, t as COLOR_SCHEME_STORAGE_KEY, u as Input, v as typeSteps } from "./theme-BgTOESmN.js";
2
+ import { a as format, i as createFormat, n as MISSING, o as toDate, r as NBSP, t as geo } from "./geo-C0jcFp4q.js";
3
+ import { a as toLoad, c as describeActionError, d as readErrorBody, i as staleOf, l as describeHttpError, n as createQueryClient, o as useLoad, r as fetchJson, s as HttpError, t as StrataQueryProvider, u as fieldErrorsOf } from "./query-CP78goXj.js";
2
4
  import * as React from "react";
3
5
  import { Autocomplete, Button as Button$1, Cell, Checkbox as Checkbox$1, Collection, Column, Dialog as Dialog$1, DialogTrigger, Disclosure as Disclosure$1, DisclosurePanel, DropIndicator, DropZone, FileTrigger, GridLayout, GridList, GridListItem, Header, Heading, I18nProvider, Input as Input$1, Keyboard, ListLayout, ListStateContext, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, NumberField as NumberField$1, Popover as Popover$1, Row, SearchField, Separator, Slider as Slider$1, SliderOutput, SliderThumb, SliderTrack, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Table, TableBody, TableHeader, TableLayout, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, UNSTABLE_Toast, UNSTABLE_ToastContent, UNSTABLE_ToastQueue, UNSTABLE_ToastRegion, Virtualizer, useDragAndDrop, useFilter } from "react-aria-components";
4
6
  import { cva } from "class-variance-authority";
7
+ import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, FileQuestion, GripVertical, History, ImageOff, Info, Loader, LoaderCircle, Maximize, Maximize2, Minimize, Minus, PanelBottomClose, PanelBottomOpen, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen, PanelTopClose, PanelTopOpen, Pause, Play, Redo2, RotateCcw, Scan, Search, SkipBack, SkipForward, Square, StepBack, StepForward, Trash2, TriangleAlert, Undo2, Upload, Volume2, VolumeX, X, ZoomIn, ZoomOut } from "lucide-react";
5
8
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
- import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, FileQuestion, GripVertical, History, ImageOff, Info, Loader, LoaderCircle, Maximize, Maximize2, Minimize, Minus, Pause, Play, Redo2, RotateCcw, Scan, Search, SkipBack, SkipForward, Square, StepBack, StepForward, Trash2, TriangleAlert, Undo2, Upload, Volume2, VolumeX, X, ZoomIn, ZoomOut } from "lucide-react";
7
9
  import { Link, NavLink, useSearchParams } from "react-router";
8
10
  import { createSortedRowModel, flexRender, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
9
- import { VisuallyHidden, mergeProps, useFocusRing, useSlider, useSliderThumb } from "react-aria";
11
+ import { VisuallyHidden, mergeProps, useDrop, useFocusRing, useMove, useSlider, useSliderThumb } from "react-aria";
10
12
  import { Size, useSliderState } from "react-stately";
11
13
  import { hashKey, useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/react-query";
12
14
  import pixelmatch from "pixelmatch";
13
- // src/lib/format.ts
14
- var NBSP = "\xA0";
15
- /** The placeholder printed for a value that is not known: an en dash. */
16
- var MISSING = "–";
17
- var BYTE_UNITS = [
18
- "B",
19
- "kB",
20
- "MB",
21
- "GB",
22
- "TB",
23
- "PB"
24
- ];
25
- var BYTE_SIZE = Object.fromEntries(BYTE_UNITS.map((u, i) => [u, 1e3 ** i]));
26
- /** A Date from a Date, an ISO string or epoch milliseconds; throws a RangeError naming the input when it is not a date. */
27
- function toDate(value) {
28
- const date = value instanceof Date ? value : new Date(value);
29
- if (Number.isNaN(date.getTime())) throw new RangeError(`Not a date: ${JSON.stringify(String(value))}`);
30
- return date;
31
- }
32
- function callableDate(df, missing) {
33
- const format = (value) => value == null ? missing : df.format(toDate(value));
34
- return Object.assign(format, {
35
- format,
36
- formatToParts: (value) => df.formatToParts(toDate(value)),
37
- formatRange: (start, end) => df.formatRange(toDate(start), toDate(end)),
38
- resolvedOptions: () => df.resolvedOptions()
39
- });
40
- }
41
- function callable(nf, missing) {
42
- const format = (value) => value == null ? missing : nf.format(value);
43
- return Object.assign(format, {
44
- format,
45
- formatToParts: (value) => nf.formatToParts(value),
46
- resolvedOptions: () => nf.resolvedOptions()
47
- });
48
- }
49
- var DAY = 864e5;
50
- var AGO_STEPS = [
51
- ["year", 365 * DAY],
52
- ["month", 30 * DAY],
53
- ["week", 7 * DAY],
54
- ["day", DAY],
55
- ["hour", 36e5],
56
- ["minute", 6e4]
57
- ];
58
- /** 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. */
59
- function createFormat(locale, options = {}) {
60
- const { timeZone, missing = "–" } = options;
61
- const dates = (opts) => callableDate(new Intl.DateTimeFormat(locale, {
62
- ...opts,
63
- timeZone
64
- }), missing);
65
- const integer = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }), missing);
66
- const decimal = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }), missing);
67
- const percent = callable(new Intl.NumberFormat(locale, {
68
- style: "percent",
69
- maximumFractionDigits: 0
70
- }), missing);
71
- const compact = callable(new Intl.NumberFormat(locale, {
72
- notation: "compact",
73
- maximumFractionDigits: 1
74
- }), missing);
75
- const relative = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
76
- const plurals = new Intl.PluralRules(locale);
77
- const clock = dates({
78
- hour: "2-digit",
79
- minute: "2-digit"
80
- });
81
- const day = dates({
82
- weekday: "long",
83
- day: "numeric",
84
- month: "long"
85
- });
86
- const shortDay = dates({
87
- weekday: "short",
88
- hour: "2-digit",
89
- minute: "2-digit"
90
- });
91
- const date = dates({ dateStyle: "medium" });
92
- const dateTime = dates({
93
- dateStyle: "medium",
94
- timeStyle: "short"
95
- });
96
- const withUnit = (value, unit, fmt = integer) => `${fmt.format(value)} ${unit}`;
97
- return {
98
- locale,
99
- /** The zone times are shown in, or `undefined` for the viewer's own. */
100
- timeZone,
101
- /** Whole numbers with grouping: `format.integer(1222)` is "1,222". */
102
- integer,
103
- /** One decimal place at most: `format.decimal(3.14)` is "3.1". */
104
- decimal,
105
- /** A ratio as a whole percent: `format.percent(0.42)` is "42%". */
106
- percent,
107
- /**
108
- * A part's share of a whole, as `percent` but never misleading at the ends: a part above 0 that
109
- * rounds to 0 is "<1%", and one short of the whole that rounds to 100 is ">99%".
110
- * `format.share(2.4 / 512)` is "<1%".
111
- */
112
- share: (value) => {
113
- if (value == null || Number.isNaN(value)) return missing;
114
- if (value > 0 && value < .005) return `<${percent.format(.01)}`;
115
- if (value >= .995 && value < 1) return `>${percent.format(.99)}`;
116
- return percent.format(value);
117
- },
118
- /** 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. */
119
- compact,
120
- /**
121
- * How long ago (or how far ahead) a time is, in the largest unit it reaches:
122
- * "3 weeks ago", "yesterday", "in 2 hours", "now" under a minute. Pass `now` in tests.
123
- */
124
- ago: (value, now = /* @__PURE__ */ new Date()) => {
125
- if (value == null) return missing;
126
- const diff = toDate(value).getTime() - toDate(now).getTime();
127
- const span = Math.abs(diff);
128
- for (const [unit, size] of AGO_STEPS) if (span >= size) return relative.format(Math.sign(diff) * Math.floor(span / size), unit);
129
- return relative.format(0, "second");
130
- },
131
- /**
132
- * A media running time from seconds, as a player shows it: "4:05", "1:02:09". Unknown
133
- * (null, negative, not finite) prints the placeholder. Set it in `tabular-nums`.
134
- */
135
- runningTime: (seconds) => {
136
- if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return missing;
137
- const s = Math.floor(seconds);
138
- const two = (n) => String(n).padStart(2, "0");
139
- const [h, m] = [Math.floor(s / 3600), Math.floor(s % 3600 / 60)];
140
- return h > 0 ? `${h}:${two(m)}:${two(s % 60)}` : `${m}:${two(s % 60)}`;
141
- },
142
- /**
143
- * A position in media as an editor shows it, to a chosen precision: "4:05" (seconds), "4:05.250"
144
- * (`"ms"`), or "4:05:07" (`"frames"` at `fps`, the last part the frame). Hours appear only from
145
- * one hour. Floors, never rounds up, so a time never reads ahead of the picture. Unknown
146
- * (null, negative, not finite) prints the placeholder. Set it in `tabular-nums`.
147
- */
148
- timecode: (seconds, { precision = "seconds", fps = 30 } = {}) => {
149
- if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return missing;
150
- const whole = Math.floor(seconds);
151
- const two = (n) => String(n).padStart(2, "0");
152
- const [h, m] = [Math.floor(whole / 3600), Math.floor(whole % 3600 / 60)];
153
- const base = h > 0 ? `${h}:${two(m)}:${two(whole % 60)}` : `${m}:${two(whole % 60)}`;
154
- if (precision === "ms") return `${base}.${String(Math.min(Math.floor((seconds - whole) * 1e3 + 1e-6), 999)).padStart(3, "0")}`;
155
- if (precision === "frames") return `${base}:${two(Math.min(Math.floor((seconds - whole) * fps + 1e-6), Math.ceil(fps) - 1))}`;
156
- return base;
157
- },
158
- /** What a missing value prints as: an en dash unless `createFormat`'s `missing` says otherwise. */
159
- missing,
160
- /** A time of day: `format.clock(at)` is "06:05". */
161
- clock,
162
- /** A day without its year, for this week's things: `format.day(at)` is "Sunday 8 November". */
163
- day,
164
- /** A weekday and time, for chart axes and recent rows: `format.shortDay(at)` is "Sun 06:05". */
165
- shortDay,
166
- /** A date with its year, for a record or a deadline: `format.date(at)` is "8 Nov 2026". */
167
- date,
168
- /** A date and time, for a log or history row: `format.dateTime(at)` is "8 Nov 2026, 06:05". */
169
- dateTime,
170
- /** A figure and its unit joined by a non-breaking space (`NBSP`), so they never wrap apart. */
171
- withUnit,
172
- /** A temperature in °C, joined by a non-breaking space. */
173
- celsius: (value) => withUnit(value, "°C"),
174
- /**
175
- * A size in bytes in the largest decimal unit it reaches (kB, MB, GB, TB, as disks and
176
- * networks are sold): one decimal below 10 ("5.2 GB"), whole above ("431 GB"). Pass `unit`
177
- * to fix the unit, so figures compared side by side ("431 of 466 GB") share one.
178
- */
179
- bytes: (value, unit) => {
180
- const chosen = unit ?? [...BYTE_UNITS].reverse().find((u) => Math.abs(value) >= BYTE_SIZE[u]) ?? "B";
181
- const scaled = value / BYTE_SIZE[chosen];
182
- return withUnit(scaled, chosen, Math.abs(scaled) < 10 && chosen !== "B" ? decimal : integer);
183
- },
184
- /** The unit `bytes` would choose for a value, to share it across a set of figures. */
185
- byteUnit: (value) => [...BYTE_UNITS].reverse().find((u) => Math.abs(value) >= BYTE_SIZE[u]) ?? "B",
186
- /**
187
- * "1 piece", "6 pieces": the count and its noun, so copy never reads "1 pieces". They are
188
- * joined by a non-breaking space (`NBSP`), not a plain one: in a test, match with the same
189
- * call or a `\s` regex, not a typed "6 pieces" string in a role's `name`.
190
- */
191
- count: (value, one, many = `${one}s`, { compact: short = false } = {}) => value == null ? missing : `${(short ? compact : integer).format(value)} ${plurals.select(value) === "one" ? one : many}`
192
- };
193
- }
194
- /** The en-GB formatters. */
195
- var format = createFormat("en-GB");
196
15
  // src/lib/in-view.ts
197
16
  /**
198
17
  * Whether an element is within `rootMargin` of its scroll region (the nearest
@@ -504,7 +323,7 @@ function KeysLegend({ shortcuts, label = "Keyboard shortcuts", className }) {
504
323
  children: " or "
505
324
  }), /* @__PURE__ */ jsx("kbd", {
506
325
  className: "min-w-5 rounded-control border border-border bg-surface-sunken px-1 text-center font-mono text-foreground",
507
- children: KEY_NAMES[k] ?? k
326
+ children: /* @__PURE__ */ jsx(KeyText, { children: KEY_NAMES[k] ?? k })
508
327
  })] }, k))
509
328
  }), /* @__PURE__ */ jsx("dd", { children: s.label })]
510
329
  }, s.keys.join(" ")))
@@ -560,7 +379,7 @@ function CommandLegend({ commands, platform, label = "Keyboard shortcuts", class
560
379
  className: cn("flex items-center gap-1.5", isDisabled(c) && "opacity-50"),
561
380
  children: [/* @__PURE__ */ jsx("dt", { children: /* @__PURE__ */ jsx("kbd", {
562
381
  className: "min-w-5 rounded-control border border-border bg-surface-sunken px-1 text-center font-mono text-foreground",
563
- children: commandShortcut(c, where)
382
+ children: /* @__PURE__ */ jsx(KeyText, { children: commandShortcut(c, where) ?? "" })
564
383
  }) }), /* @__PURE__ */ jsx("dd", { children: labelOf(c) })]
565
384
  }, c.id))
566
385
  });
@@ -592,7 +411,7 @@ function Item({ command, platform }) {
592
411
  }),
593
412
  shortcut && /* @__PURE__ */ jsx(Keyboard, {
594
413
  className: "ml-6 shrink-0 font-mono type-caption text-muted-foreground",
595
- children: shortcut
414
+ children: /* @__PURE__ */ jsx(KeyText, { children: shortcut })
596
415
  }),
597
416
  reason && /* @__PURE__ */ jsx(Text, {
598
417
  slot: "description",
@@ -763,7 +582,7 @@ function CommandMenu({ commands, open, onOpenChange, shortcut = "Mod+K", label =
763
582
  isOpen,
764
583
  onOpenChange: set,
765
584
  isDismissable: true,
766
- className: "layer-overlay fixed inset-0 grid justify-items-center overflow-hidden bg-foreground/40 p-4 pt-24",
585
+ className: "layer-overlay fixed inset-0 grid justify-items-center overflow-hidden scrim p-4 pt-24",
767
586
  children: /* @__PURE__ */ jsxs(Modal, {
768
587
  className: cn("flex max-h-full w-full max-w-lg flex-col self-start outline-none", overlaySurface),
769
588
  children: [/* @__PURE__ */ jsx(Dialog$1, {
@@ -962,7 +781,7 @@ function Driven({ open, onOpenChange, children }) {
962
781
  onOpenChange
963
782
  });
964
783
  }
965
- var overlayClass = "layer-overlay fixed inset-0 grid overflow-hidden bg-foreground/40";
784
+ var overlayClass = "layer-overlay fixed inset-0 grid overflow-hidden scrim";
966
785
  /** A modal dialog with a required title; focus goes in and returns, Escape and a close control dismiss it. `placement="end"` makes it a sheet. */
967
786
  function Dialog({ title, description, trigger, open, onOpenChange, className, children, actions, hideTitle, closable = true, placement = "center", size = "md" }) {
968
787
  const descriptionId = React.useId();
@@ -1250,7 +1069,7 @@ function AsyncButton({ phase, labels, error, disabled, ...props }) {
1250
1069
  }
1251
1070
  /** Runs an async action and reports its phase, its error and any field messages. `done` returns to `idle` after `settleMs`; `run` never changes identity. */
1252
1071
  function useAsyncAction(action, { settleMs = 2e3, onError, describeError = describeActionError, validate, onInvalid } = {}) {
1253
- const [state, setState] = React.useState(idle);
1072
+ const [state, setState] = React.useState(idle$1);
1254
1073
  const timer = React.useRef(void 0);
1255
1074
  const unreported = React.useRef(void 0);
1256
1075
  const latest = React.useRef({
@@ -1278,22 +1097,22 @@ function useAsyncAction(action, { settleMs = 2e3, onError, describeError = descr
1278
1097
  if (invalid) {
1279
1098
  unreported.current = { invalid };
1280
1099
  setState({
1281
- ...idle,
1100
+ ...idle$1,
1282
1101
  fieldErrors: invalid
1283
1102
  });
1284
1103
  return;
1285
1104
  }
1286
1105
  setState({
1287
- ...idle,
1106
+ ...idle$1,
1288
1107
  phase: "pending"
1289
1108
  });
1290
1109
  try {
1291
1110
  await latest.current.action(...args);
1292
1111
  setState({
1293
- ...idle,
1112
+ ...idle$1,
1294
1113
  phase: "done"
1295
1114
  });
1296
- timer.current = window.setTimeout(() => setState(idle), latest.current.settleMs);
1115
+ timer.current = window.setTimeout(() => setState(idle$1), latest.current.settleMs);
1297
1116
  } catch (thrown) {
1298
1117
  unreported.current = { thrown };
1299
1118
  setState({
@@ -1333,7 +1152,7 @@ function useAsyncAction(action, { settleMs = 2e3, onError, describeError = descr
1333
1152
  clearFieldError
1334
1153
  };
1335
1154
  }
1336
- var idle = {
1155
+ var idle$1 = {
1337
1156
  phase: "idle",
1338
1157
  error: void 0,
1339
1158
  thrown: void 0,
@@ -2958,7 +2777,7 @@ function TableSkeleton({ rows = 4, columns = 5 }) {
2958
2777
  });
2959
2778
  }
2960
2779
  // src/components/media.tsx
2961
- var clamp$1 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
2780
+ var clamp$2 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
2962
2781
  var timecode = (t, { precision, fps }) => format.timecode(t, {
2963
2782
  precision,
2964
2783
  fps
@@ -3000,11 +2819,13 @@ function TimeReadout({ time, duration, precision = "seconds", fps = 30, classNam
3000
2819
  });
3001
2820
  }
3002
2821
  /** A seek bar: dragged, clicked and moved by keys (arrows `step`, Page keys `bigStep`, Home and End), with its time as the accessible value. */
3003
- function SeekBar({ time, duration, onSeek, marks = [], buffered, step = 5, bigStep = 30, label = "Seek", precision = "seconds", fps = 30, disabled, className }) {
2822
+ function SeekBar({ time, duration: known, onSeek, marks = [], buffered, step = 5, bigStep = 30, label = "Seek", precision = "seconds", fps = 30, disabled: off, className }) {
2823
+ const duration = known && Number.isFinite(known) && known > 0 ? known : 0;
2824
+ const disabled = off || duration === 0;
3004
2825
  const track = React.useRef(null);
3005
2826
  const input = React.useRef(null);
3006
- const frac = duration > 0 ? clamp$1(time / duration, 0, 1) : 0;
3007
- const seekTo = (t) => onSeek(clamp$1(t, 0, duration));
2827
+ const frac = duration > 0 ? clamp$2(time / duration, 0, 1) : 0;
2828
+ const seekTo = (t) => onSeek(clamp$2(t, 0, duration));
3008
2829
  const timeText = React.useMemo(() => {
3009
2830
  const say = (t) => timecode(t, {
3010
2831
  precision,
@@ -3021,7 +2842,7 @@ function SeekBar({ time, duration, onSeek, marks = [], buffered, step = 5, bigSt
3021
2842
  minValue: 0,
3022
2843
  maxValue: Math.max(duration, fine),
3023
2844
  step: fine,
3024
- value: [clamp$1(time, 0, duration)],
2845
+ value: [clamp$2(time, 0, duration)],
3025
2846
  onChange: ([t]) => seekTo(t),
3026
2847
  numberFormatter: timeText,
3027
2848
  isDisabled: disabled
@@ -3070,7 +2891,7 @@ function SeekBar({ time, duration, onSeek, marks = [], buffered, step = 5, bigSt
3070
2891
  buffered !== void 0 && duration > 0 && /* @__PURE__ */ jsx("span", {
3071
2892
  "aria-hidden": true,
3072
2893
  className: "absolute left-0 h-1.5 rounded-pill bg-neutral-4",
3073
- style: { width: `${clamp$1(buffered / duration, 0, 1) * 100}%` }
2894
+ style: { width: `${clamp$2(buffered / duration, 0, 1) * 100}%` }
3074
2895
  }),
3075
2896
  /* @__PURE__ */ jsx("span", {
3076
2897
  "aria-hidden": true,
@@ -3206,7 +3027,7 @@ function RateChoice({ rate, onRateChange, rates = [
3206
3027
  * to the ends, M mutes. Pass the player's actions; the labels are the legend's words.
3207
3028
  */
3208
3029
  function transportShortcuts({ toggle, seek, time, duration, frame = 1 / 30, jump = 1, toggleMute }) {
3209
- const to = (t) => () => seek(clamp$1(t, 0, duration));
3030
+ const to = (t) => () => seek(clamp$2(t, 0, duration));
3210
3031
  return [
3211
3032
  {
3212
3033
  keys: [" ", "k"],
@@ -3362,6 +3183,480 @@ function StageGuides({ safe, thirds, centre, className }) {
3362
3183
  children: [draw("stroke-foreground", 3), draw("stroke-background", 1)]
3363
3184
  });
3364
3185
  }
3186
+ // src/components/media-player.tsx
3187
+ var idle = {
3188
+ playing: false,
3189
+ time: 0,
3190
+ duration: null,
3191
+ buffered: 0,
3192
+ volume: 100,
3193
+ muted: false,
3194
+ rate: 1,
3195
+ ended: false,
3196
+ loading: false,
3197
+ error: null
3198
+ };
3199
+ var LOAD_MESSAGES = {
3200
+ 2: "The connection dropped while it was loading.",
3201
+ 3: "The file could not be decoded.",
3202
+ 4: "This format is not supported or the file is not there."
3203
+ };
3204
+ function bufferedAhead(el) {
3205
+ const ranges = el.buffered;
3206
+ for (let i = 0; i < ranges.length; i++) if (el.currentTime >= ranges.start(i) && el.currentTime <= ranges.end(i)) return ranges.end(i);
3207
+ return 0;
3208
+ }
3209
+ function useElementListeners(ref, bind) {
3210
+ const bound = React.useRef(null);
3211
+ const latest = React.useRef(bind);
3212
+ latest.current = bind;
3213
+ React.useEffect(() => {
3214
+ const el = ref.current;
3215
+ if (bound.current?.el === el) return;
3216
+ bound.current?.unbind();
3217
+ bound.current = el ? {
3218
+ el,
3219
+ unbind: latest.current(el)
3220
+ } : null;
3221
+ });
3222
+ React.useEffect(() => () => {
3223
+ bound.current?.unbind();
3224
+ bound.current = null;
3225
+ }, []);
3226
+ }
3227
+ var EVENTS = [
3228
+ "loadstart",
3229
+ "loadedmetadata",
3230
+ "durationchange",
3231
+ "timeupdate",
3232
+ "progress",
3233
+ "play",
3234
+ "playing",
3235
+ "pause",
3236
+ "ended",
3237
+ "volumechange",
3238
+ "ratechange",
3239
+ "seeking",
3240
+ "seeked",
3241
+ "waiting",
3242
+ "canplay",
3243
+ "emptied",
3244
+ "error"
3245
+ ];
3246
+ /** Follows an `<audio>` or `<video>` and returns its state and the requests a player makes. Works with the browser's own controls too. */
3247
+ function useMediaElement(ref) {
3248
+ const [snapshot, setSnapshot] = React.useState(idle);
3249
+ const blocked = React.useRef(null);
3250
+ const pendingSeek = React.useRef(null);
3251
+ const read = React.useCallback(() => {
3252
+ const el = ref.current;
3253
+ if (!el) return;
3254
+ const finite = Number.isFinite(el.duration) && el.duration > 0;
3255
+ let error = blocked.current;
3256
+ if (el.error && el.error.code !== 1) error = {
3257
+ kind: "load",
3258
+ message: LOAD_MESSAGES[el.error.code] ?? "It could not be played."
3259
+ };
3260
+ const next = {
3261
+ playing: !el.paused && !el.ended,
3262
+ time: Number.isFinite(el.currentTime) ? el.currentTime : 0,
3263
+ duration: finite ? el.duration : null,
3264
+ buffered: bufferedAhead(el),
3265
+ volume: el.muted ? 0 : Math.round(el.volume * 100),
3266
+ muted: el.muted,
3267
+ rate: el.playbackRate,
3268
+ ended: el.ended,
3269
+ loading: !error && el.networkState === 2 && el.readyState < 3 && !el.paused,
3270
+ error
3271
+ };
3272
+ setSnapshot((previous) => Object.keys(next).every((k) => Object.is(previous[k], next[k]) || k === "error" && previous.error?.message === next.error?.message && previous.error?.kind === next.error?.kind) ? previous : next);
3273
+ }, [ref]);
3274
+ useElementListeners(ref, (el) => {
3275
+ const on = (e) => {
3276
+ if (e.type === "play" || e.type === "playing") blocked.current = null;
3277
+ if (e.type === "loadedmetadata" && pendingSeek.current !== null) {
3278
+ el.currentTime = pendingSeek.current;
3279
+ pendingSeek.current = null;
3280
+ }
3281
+ if (e.type === "emptied" || e.type === "loadstart") blocked.current = null;
3282
+ read();
3283
+ };
3284
+ for (const type of EVENTS) el.addEventListener(type, on);
3285
+ read();
3286
+ return () => {
3287
+ for (const type of EVENTS) el.removeEventListener(type, on);
3288
+ };
3289
+ });
3290
+ return React.useMemo(() => {
3291
+ const play = async () => {
3292
+ const el = ref.current;
3293
+ if (!el) return;
3294
+ try {
3295
+ await el.play();
3296
+ } catch (e) {
3297
+ if (e instanceof DOMException && e.name === "NotAllowedError") {
3298
+ blocked.current = {
3299
+ kind: "blocked",
3300
+ message: "The browser blocked playback until you press Play."
3301
+ };
3302
+ read();
3303
+ } else if (!(e instanceof DOMException && e.name === "AbortError")) read();
3304
+ }
3305
+ };
3306
+ return {
3307
+ ...snapshot,
3308
+ play,
3309
+ pause: () => ref.current?.pause(),
3310
+ toggle: () => {
3311
+ const el = ref.current;
3312
+ if (!el) return;
3313
+ if (el.paused || el.ended) play();
3314
+ else el.pause();
3315
+ },
3316
+ seek: (time) => {
3317
+ const el = ref.current;
3318
+ if (!el) return;
3319
+ if (el.readyState < 1) pendingSeek.current = Math.max(0, time);
3320
+ else el.currentTime = Math.max(0, Number.isFinite(el.duration) ? Math.min(time, el.duration) : time);
3321
+ read();
3322
+ },
3323
+ setVolume: (volume) => {
3324
+ const el = ref.current;
3325
+ if (!el) return;
3326
+ const v = Math.min(Math.max(volume, 0), 100);
3327
+ el.muted = v === 0;
3328
+ if (v > 0) el.volume = v / 100;
3329
+ },
3330
+ setRate: (rate) => {
3331
+ const el = ref.current;
3332
+ if (!el) return;
3333
+ el.defaultPlaybackRate = rate;
3334
+ el.playbackRate = rate;
3335
+ },
3336
+ retry: () => {
3337
+ const el = ref.current;
3338
+ if (!el) return;
3339
+ const resume = !el.paused;
3340
+ const at = el.currentTime;
3341
+ blocked.current = null;
3342
+ el.load();
3343
+ if (at > 0) pendingSeek.current = at;
3344
+ read();
3345
+ if (resume) play();
3346
+ }
3347
+ };
3348
+ }, [
3349
+ snapshot,
3350
+ ref,
3351
+ read
3352
+ ]);
3353
+ }
3354
+ /** Playback speeds an audiobook or lecture listener expects. */
3355
+ var SPEECH_RATES = [
3356
+ .75,
3357
+ 1,
3358
+ 1.25,
3359
+ 1.5,
3360
+ 1.75,
3361
+ 2,
3362
+ 2.5,
3363
+ 3
3364
+ ];
3365
+ var JUMP = 10;
3366
+ function useCoarsePointer() {
3367
+ const [coarse, setCoarse] = React.useState(false);
3368
+ React.useEffect(() => {
3369
+ if (typeof matchMedia !== "function") return;
3370
+ const query = matchMedia("(pointer: coarse)");
3371
+ const read = () => setCoarse(query.matches);
3372
+ read();
3373
+ query.addEventListener?.("change", read);
3374
+ return () => query.removeEventListener?.("change", read);
3375
+ }, []);
3376
+ return coarse;
3377
+ }
3378
+ /**
3379
+ * Plays a file or a sequence: the element, its state, and Strata's controls (or the browser's own on
3380
+ * a touch device), with the failure to load shown and retried. For an editor or a replay, use the
3381
+ * parts and `useMediaElement` directly.
3382
+ */
3383
+ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledIndex, onIndexChange, autoAdvance = true, controls = "auto", autoPlay, poster, session, rates, shortcuts = true, onEnded, onTimeChange, className }) {
3384
+ const list = React.useMemo(() => sources ?? (src ? [{
3385
+ src,
3386
+ title: label
3387
+ }] : []), [
3388
+ sources,
3389
+ src,
3390
+ label
3391
+ ]);
3392
+ const [ownIndex, setOwnIndex] = React.useState(0);
3393
+ const index = Math.min(controlledIndex ?? ownIndex, Math.max(list.length - 1, 0));
3394
+ const current = list[index];
3395
+ const ref = React.useRef(null);
3396
+ const media = useMediaElement(ref);
3397
+ const coarse = useCoarsePointer();
3398
+ const native = controls === "native" || controls === "auto" && coarse;
3399
+ const go = React.useCallback((to) => {
3400
+ if (controlledIndex === void 0) setOwnIndex(to);
3401
+ onIndexChange?.(to);
3402
+ }, [controlledIndex, onIndexChange]);
3403
+ const resume = React.useRef(false);
3404
+ const startAt = React.useRef(null);
3405
+ const keep = React.useRef({
3406
+ index,
3407
+ playing: media.playing,
3408
+ go,
3409
+ onEnded,
3410
+ autoAdvance,
3411
+ last: list.length - 1
3412
+ });
3413
+ keep.current = {
3414
+ index,
3415
+ playing: media.playing,
3416
+ go,
3417
+ onEnded,
3418
+ autoAdvance,
3419
+ last: list.length - 1
3420
+ };
3421
+ const wasSrc = React.useRef(current?.src);
3422
+ React.useEffect(() => {
3423
+ if (wasSrc.current === current?.src) return;
3424
+ wasSrc.current = current?.src;
3425
+ if (!ref.current) return;
3426
+ if (startAt.current !== null) {
3427
+ media.seek(startAt.current);
3428
+ startAt.current = null;
3429
+ }
3430
+ if (resume.current) {
3431
+ resume.current = false;
3432
+ media.play();
3433
+ }
3434
+ }, [current?.src]);
3435
+ const onEnd = React.useCallback(() => {
3436
+ const k = keep.current;
3437
+ if (k.autoAdvance && k.index < k.last) {
3438
+ resume.current = true;
3439
+ k.go(k.index + 1);
3440
+ } else k.onEnded?.();
3441
+ }, []);
3442
+ useElementListeners(ref, (el) => {
3443
+ el.addEventListener("ended", onEnd);
3444
+ return () => el.removeEventListener("ended", onEnd);
3445
+ });
3446
+ const offsets = React.useMemo(() => {
3447
+ if (list.length < 2 || !list.every((s) => s.duration && s.duration > 0)) return null;
3448
+ let at = 0;
3449
+ return list.map((s) => {
3450
+ const start = at;
3451
+ at += s.duration;
3452
+ return start;
3453
+ });
3454
+ }, [list]);
3455
+ const total = offsets ? offsets[offsets.length - 1] + list[list.length - 1].duration : null;
3456
+ const time = (offsets ? offsets[index] : 0) + media.time;
3457
+ const duration = total ?? media.duration;
3458
+ const seek = (t) => {
3459
+ if (!offsets) return media.seek(t);
3460
+ let to = offsets.length - 1;
3461
+ while (to > 0 && offsets[to] > t) to--;
3462
+ if (to === index) return media.seek(t - offsets[to]);
3463
+ resume.current = media.playing;
3464
+ startAt.current = t - offsets[to];
3465
+ go(to);
3466
+ };
3467
+ const step = (by) => {
3468
+ const to = index + by;
3469
+ if (to < 0 || to > list.length - 1) return;
3470
+ resume.current = media.playing;
3471
+ go(to);
3472
+ };
3473
+ React.useEffect(() => {
3474
+ if (onTimeChange) onTimeChange(time);
3475
+ }, [time]);
3476
+ useHotkeys(React.useMemo(() => [
3477
+ {
3478
+ keys: [" ", "k"],
3479
+ label: "Play or pause",
3480
+ run: media.toggle
3481
+ },
3482
+ {
3483
+ keys: ["j"],
3484
+ label: `Back ${JUMP} s`,
3485
+ run: () => seek(time - JUMP),
3486
+ repeat: true
3487
+ },
3488
+ {
3489
+ keys: ["l"],
3490
+ label: `Forward ${JUMP} s`,
3491
+ run: () => seek(time + JUMP),
3492
+ repeat: true
3493
+ },
3494
+ {
3495
+ keys: ["m"],
3496
+ label: "Mute",
3497
+ run: () => media.setVolume(media.muted ? 100 : 0)
3498
+ }
3499
+ ], [
3500
+ media,
3501
+ time,
3502
+ offsets,
3503
+ index
3504
+ ]), { enabled: shortcuts && !native });
3505
+ React.useEffect(() => {
3506
+ if (!session || typeof navigator === "undefined" || !("mediaSession" in navigator) || typeof MediaMetadata === "undefined") return;
3507
+ const s = navigator.mediaSession;
3508
+ s.metadata = new MediaMetadata({
3509
+ title: current?.title ?? session.title,
3510
+ artist: session.artist,
3511
+ album: session.album ?? (list.length > 1 ? session.title : void 0),
3512
+ artwork: session.artwork ? [{ src: session.artwork }] : []
3513
+ });
3514
+ return () => {
3515
+ s.metadata = null;
3516
+ };
3517
+ }, [
3518
+ session,
3519
+ current?.title,
3520
+ list.length
3521
+ ]);
3522
+ React.useEffect(() => {
3523
+ if (!session || typeof navigator === "undefined" || !("mediaSession" in navigator)) return;
3524
+ const s = navigator.mediaSession;
3525
+ const set = (action, handler) => {
3526
+ try {
3527
+ s.setActionHandler(action, handler);
3528
+ } catch {}
3529
+ };
3530
+ set("play", () => void media.play());
3531
+ set("pause", media.pause);
3532
+ set("seekbackward", () => seek(time - JUMP));
3533
+ set("seekforward", () => seek(time + JUMP));
3534
+ set("previoustrack", index > 0 ? () => step(-1) : null);
3535
+ set("nexttrack", index < list.length - 1 ? () => step(1) : null);
3536
+ return () => {
3537
+ for (const a of [
3538
+ "play",
3539
+ "pause",
3540
+ "seekbackward",
3541
+ "seekforward",
3542
+ "previoustrack",
3543
+ "nexttrack"
3544
+ ]) set(a, null);
3545
+ };
3546
+ }, [
3547
+ session,
3548
+ media,
3549
+ time,
3550
+ index,
3551
+ list.length
3552
+ ]);
3553
+ const common = {
3554
+ ref,
3555
+ src: current?.src,
3556
+ controls: native,
3557
+ autoPlay,
3558
+ preload: "metadata",
3559
+ "aria-label": label
3560
+ };
3561
+ const element = kind === "video" ? /* @__PURE__ */ jsx("video", {
3562
+ ...common,
3563
+ poster,
3564
+ playsInline: true,
3565
+ className: "w-full rounded-surface bg-surface-sunken"
3566
+ }) : /* @__PURE__ */ jsx("audio", {
3567
+ ...common,
3568
+ className: native ? "w-full" : "hidden"
3569
+ });
3570
+ const what = kind === "video" ? "this video" : "this recording";
3571
+ return /* @__PURE__ */ jsxs("div", {
3572
+ role: "group",
3573
+ "aria-label": label,
3574
+ className: cn("grid w-full gap-2", className),
3575
+ children: [
3576
+ element,
3577
+ media.error?.kind === "load" && /* @__PURE__ */ jsx(Alert, {
3578
+ tone: "danger",
3579
+ announce: true,
3580
+ title: `Could not load ${what}`,
3581
+ action: /* @__PURE__ */ jsx(Button, {
3582
+ size: "sm",
3583
+ variant: "outline",
3584
+ onClick: media.retry,
3585
+ children: "Try again"
3586
+ }),
3587
+ children: media.error.message
3588
+ }),
3589
+ media.error?.kind === "blocked" && /* @__PURE__ */ jsx("p", {
3590
+ role: "status",
3591
+ className: "type-body-sm text-muted-foreground",
3592
+ children: media.error.message
3593
+ }),
3594
+ !native && /* @__PURE__ */ jsxs("div", {
3595
+ className: "grid gap-2",
3596
+ children: [/* @__PURE__ */ jsxs("div", {
3597
+ className: "flex min-w-0 items-center gap-3",
3598
+ children: [/* @__PURE__ */ jsx(SeekBar, {
3599
+ time,
3600
+ duration,
3601
+ onSeek: seek,
3602
+ buffered: offsets ? void 0 : media.buffered,
3603
+ marks: offsets ? list.map((s, i) => ({
3604
+ time: offsets[i],
3605
+ label: s.title
3606
+ })).slice(1) : [],
3607
+ step: JUMP,
3608
+ bigStep: 60,
3609
+ label: `Seek in ${label}`
3610
+ }), /* @__PURE__ */ jsx(TimeReadout, {
3611
+ time,
3612
+ duration
3613
+ })]
3614
+ }), /* @__PURE__ */ jsxs("div", {
3615
+ className: "flex flex-wrap items-center gap-x-4 gap-y-2",
3616
+ children: [
3617
+ /* @__PURE__ */ jsxs(Transport, {
3618
+ playing: media.playing,
3619
+ onPlayPause: media.toggle,
3620
+ children: [list.length > 1 && /* @__PURE__ */ jsx(IconButton, {
3621
+ icon: SkipBack,
3622
+ label: "Previous chapter",
3623
+ disabled: index === 0,
3624
+ onClick: () => step(-1)
3625
+ }), list.length > 1 && /* @__PURE__ */ jsx(IconButton, {
3626
+ icon: SkipForward,
3627
+ label: "Next chapter",
3628
+ disabled: index === list.length - 1,
3629
+ onClick: () => step(1)
3630
+ })]
3631
+ }),
3632
+ list.length > 1 && /* @__PURE__ */ jsxs("span", {
3633
+ className: "type-body-sm text-muted-foreground",
3634
+ children: [
3635
+ current?.title,
3636
+ " (",
3637
+ index + 1,
3638
+ " of ",
3639
+ list.length,
3640
+ ")"
3641
+ ]
3642
+ }),
3643
+ /* @__PURE__ */ jsxs("span", {
3644
+ className: "ml-auto flex items-center gap-3",
3645
+ children: [/* @__PURE__ */ jsx(RateChoice, {
3646
+ rate: media.rate,
3647
+ onRateChange: media.setRate,
3648
+ rates
3649
+ }), /* @__PURE__ */ jsx(VolumeControl, {
3650
+ volume: media.volume,
3651
+ onVolumeChange: media.setVolume
3652
+ })]
3653
+ })
3654
+ ]
3655
+ })]
3656
+ })
3657
+ ]
3658
+ });
3659
+ }
3365
3660
  // src/lib/timeline.ts
3366
3661
  /** Steps a person would write on a scale, in seconds: 1, 2, 5 and 10 × 10ⁿ below a minute, then 15 s, 30 s, minutes, quarter hours, hours, days. ux-research components.md §3.8: ticks land on values people would write. */
3367
3662
  var STEPS = [
@@ -3412,7 +3707,7 @@ function tickLabel(time, step) {
3412
3707
  const base = h > 0 ? `${h}:${two(m)}:${two(s)}` : `${m}:${two(s)}`;
3413
3708
  return decimals ? `${base}.${String(Math.round((time - whole) * 10 ** decimals)).padStart(decimals, "0")}` : base;
3414
3709
  }
3415
- function clamp(value, min, max) {
3710
+ function clamp$1(value, min, max) {
3416
3711
  return Math.min(Math.max(value, min), max);
3417
3712
  }
3418
3713
  /** The point to snap `time` to: the nearest of `points` within `thresholdPx` at this zoom, or `null`. */
@@ -3427,14 +3722,13 @@ function snapTo(time, points, pxPerUnit, thresholdPx = 8) {
3427
3722
  /** Round away float noise from adding steps (0.1 + 0.2). */
3428
3723
  var tidy = (n) => Math.round(n * 1e6) / 1e6;
3429
3724
  // src/components/timeline.tsx
3430
- var HEADER_W = "w-40";
3431
3725
  var EDGE_PX = 8;
3432
3726
  var DRAG_THRESHOLD = 3;
3433
3727
  var defaultFormat = (t) => tickLabel(t, 1);
3434
3728
  /** Zoom state for a timeline: `zoomIn`, `zoomOut`, and `fit` to a viewport width. Pass `zoom` and `setZoom` as the timeline's `zoom` and `onZoomChange`. */
3435
3729
  function useTimelineZoom({ initial = 20, min = .5, max = 400 } = {}) {
3436
3730
  const [zoom, set] = React.useState(initial);
3437
- const setZoom = React.useCallback((z) => set(clamp(z, min, max)), [min, max]);
3731
+ const setZoom = React.useCallback((z) => set(clamp$1(z, min, max)), [min, max]);
3438
3732
  return {
3439
3733
  zoom,
3440
3734
  setZoom,
@@ -3479,7 +3773,7 @@ function noOverlap(items) {
3479
3773
  };
3480
3774
  }
3481
3775
  /** Items placed on a zoomable time axis in lanes, with a current-time rule and markers. Reports every move, trim, selection and time change; the app applies them. Keyboard-complete, and only the items near the view are rendered. */
3482
- function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, position, onPositionChange, follow, markers = [], selectedIds, onSelect, onItemChange, onDelete, validate, snapPoints = [], snap = true, step = 1, minLength, renderItem, formatTime = defaultFormat, empty, className }) {
3776
+ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, position, onPositionChange, follow, markers = [], selectedIds, onSelect, onItemChange, onDelete, validate, snapPoints = [], snap = true, step = 1, minLength, renderItem, kindColours, laneRows = 1, dropTypes, dropLength, onDrop, validateDrop, formatTime = defaultFormat, empty, className }) {
3483
3777
  const min = minLength ?? step;
3484
3778
  const scroller = React.useRef(null);
3485
3779
  const laneRefs = React.useRef(/* @__PURE__ */ new Map());
@@ -3491,6 +3785,7 @@ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, posit
3491
3785
  const dragRef = React.useRef(null);
3492
3786
  const [focusId, setFocusId] = React.useState(null);
3493
3787
  const [said, setSaid] = React.useState("");
3788
+ const [hover, setHover] = React.useState(null);
3494
3789
  const refocus = React.useRef(null);
3495
3790
  const selected = selectedIds ?? /* @__PURE__ */ new Set();
3496
3791
  const laneIndex = React.useMemo(() => new Map(lanes.map((l, i) => [l.id, i])), [lanes]);
@@ -3588,7 +3883,7 @@ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, posit
3588
3883
  handled();
3589
3884
  const dir = k === "ArrowLeft" ? -1 : 1;
3590
3885
  commit(item, {
3591
- start: clamp(tidy(item.start + dir * step * big), from, to - item.length),
3886
+ start: clamp$1(tidy(item.start + dir * step * big), from, to - item.length),
3592
3887
  length: item.length,
3593
3888
  lane: item.lane
3594
3889
  });
@@ -3608,7 +3903,7 @@ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, posit
3608
3903
  handled();
3609
3904
  const dir = k === "ArrowLeft" ? -1 : 1;
3610
3905
  if (e.shiftKey) {
3611
- const start = clamp(tidy(item.start + dir * step), from, item.start + item.length - min);
3906
+ const start = clamp$1(tidy(item.start + dir * step), from, item.start + item.length - min);
3612
3907
  commit(item, {
3613
3908
  start,
3614
3909
  length: tidy(item.start + item.length - start),
@@ -3616,7 +3911,7 @@ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, posit
3616
3911
  });
3617
3912
  } else commit(item, {
3618
3913
  start: item.start,
3619
- length: clamp(tidy(item.length + dir * step), min, to - item.start),
3914
+ length: clamp$1(tidy(item.length + dir * step), min, to - item.start),
3620
3915
  lane: item.lane
3621
3916
  });
3622
3917
  return;
@@ -3658,6 +3953,58 @@ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, posit
3658
3953
  }
3659
3954
  }
3660
3955
  };
3956
+ /** Snaps an item of `length` starting at `start` to whichever of its ends is nearer an edge. */
3957
+ const snapMove = (start, length, exclude) => {
3958
+ const edges = [...snapTimes, ...items.filter((i) => i.id !== exclude).flatMap((i) => [i.start, i.start + i.length])];
3959
+ const a = snap ? snapTo(start, edges, zoom) : null;
3960
+ const b = snap ? snapTo(start + length, edges, zoom) : null;
3961
+ if (a && (!b || Math.abs(a.time - start) <= Math.abs(b.time - (start + length)))) return {
3962
+ start: a.time,
3963
+ guide: a.point
3964
+ };
3965
+ if (b) return {
3966
+ start: b.time - length,
3967
+ guide: b.point
3968
+ };
3969
+ return {
3970
+ start,
3971
+ guide: null
3972
+ };
3973
+ };
3974
+ const dropLen = dropLength ?? step * 5;
3975
+ const dropAt = (lane, px) => {
3976
+ const at = px === null ? position ?? from : from + px / zoom;
3977
+ const snapped = snapMove(at, dropLen);
3978
+ const next = {
3979
+ start: clamp$1(tidy(snapped.start), from, Math.max(to - dropLen, from)),
3980
+ length: dropLen,
3981
+ lane
3982
+ };
3983
+ return {
3984
+ next,
3985
+ guide: snapped.guide,
3986
+ reason: validateDrop?.(next) ?? null
3987
+ };
3988
+ };
3989
+ const onLaneHover = (lane, px) => {
3990
+ const h = dropAt(lane, px);
3991
+ setHover(h);
3992
+ if (px === null) setSaid(h.reason ?? `Drop here: ${laneLabel(lane)} at ${formatTime(h.next.start)}.`);
3993
+ };
3994
+ const onLaneDrop = (lane, px, dropped) => {
3995
+ setHover(null);
3996
+ const h = dropAt(lane, px);
3997
+ if (h.reason) {
3998
+ setSaid(h.reason);
3999
+ return;
4000
+ }
4001
+ onDrop?.({
4002
+ ...h.next,
4003
+ items: dropped
4004
+ });
4005
+ setSaid(`Added at ${formatTime(h.next.start)}, ${laneLabel(lane)}.`);
4006
+ };
4007
+ const dropsOn = Boolean(dropTypes?.length && onDrop);
3661
4008
  const begin = (e, item, mode) => {
3662
4009
  if (e.button !== 0) return;
3663
4010
  e.stopPropagation();
@@ -3706,28 +4053,21 @@ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, posit
3706
4053
  return s ? s.time : t;
3707
4054
  };
3708
4055
  if (d.mode === "move") {
3709
- let start = o.start + dt;
3710
- const a = snap ? snapTo(start, edges, zoom) : null;
3711
- const b = snap ? snapTo(start + o.length, edges, zoom) : null;
3712
- if (a && (!b || Math.abs(a.time - start) <= Math.abs(b.time - (start + o.length)))) {
3713
- start = a.time;
3714
- guide = a.point;
3715
- } else if (b) {
3716
- start = b.time - o.length;
3717
- guide = b.point;
3718
- }
4056
+ const m = snapMove(o.start + dt, o.length, o.id);
4057
+ const start = m.start;
4058
+ guide = m.guide;
3719
4059
  next = {
3720
- start: clamp(tidy(start), from, to - o.length),
4060
+ start: clamp$1(tidy(start), from, to - o.length),
3721
4061
  length: o.length,
3722
4062
  lane: laneAt(e.clientY, o.lane)
3723
4063
  };
3724
4064
  } else if (d.mode === "end") next = {
3725
4065
  start: o.start,
3726
- length: clamp(tidy(snapped(o.start + o.length + dt) - o.start), min, to - o.start),
4066
+ length: clamp$1(tidy(snapped(o.start + o.length + dt) - o.start), min, to - o.start),
3727
4067
  lane: o.lane
3728
4068
  };
3729
4069
  else {
3730
- const start = clamp(tidy(snapped(o.start + dt)), from, o.start + o.length - min);
4070
+ const start = clamp$1(tidy(snapped(o.start + dt)), from, o.start + o.length - min);
3731
4071
  next = {
3732
4072
  start,
3733
4073
  length: tidy(o.start + o.length - start),
@@ -3764,7 +4104,7 @@ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, posit
3764
4104
  to,
3765
4105
  stepSize
3766
4106
  ]);
3767
- const setPosition = (t) => onPositionChange?.(clamp(tidy(t), from, to));
4107
+ const setPosition = (t) => onPositionChange?.(clamp$1(tidy(t), from, to));
3768
4108
  const scrubTrack = React.useRef(null);
3769
4109
  const scrubInput = React.useRef(null);
3770
4110
  const spokenTime = React.useMemo(() => ({
@@ -3776,7 +4116,7 @@ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, posit
3776
4116
  minValue: from,
3777
4117
  maxValue: Math.max(to, from + 1e-9),
3778
4118
  step: .001,
3779
- value: [clamp(position ?? from, from, to)],
4119
+ value: [clamp$1(position ?? from, from, to)],
3780
4120
  onChange: ([t]) => setPosition(t),
3781
4121
  numberFormatter: spokenTime,
3782
4122
  isDisabled: position === void 0 || !onPositionChange
@@ -3840,6 +4180,7 @@ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, posit
3840
4180
  "aria-label": label,
3841
4181
  onKeyDown,
3842
4182
  className: cn("min-w-0 text-foreground", className),
4183
+ style: { "--lane-h": `calc(var(--control-h) * ${Math.max(laneRows, 1)})` },
3843
4184
  children: [
3844
4185
  /* @__PURE__ */ jsx("p", {
3845
4186
  role: "status",
@@ -3849,12 +4190,12 @@ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, posit
3849
4190
  /* @__PURE__ */ jsxs("div", {
3850
4191
  className: "flex",
3851
4192
  children: [/* @__PURE__ */ jsxs("div", {
3852
- className: cn("shrink-0 border-r border-border", HEADER_W),
4193
+ className: "w-max max-w-80 min-w-40 shrink-0 border-r border-border",
3853
4194
  children: [/* @__PURE__ */ jsx("div", {
3854
4195
  className: "h-8 border-b border-border",
3855
4196
  "aria-hidden": true
3856
4197
  }), lanes.map((l) => /* @__PURE__ */ jsxs("div", {
3857
- className: "flex h-(--control-h) items-center gap-1 border-b border-border px-2 type-label",
4198
+ className: "flex h-(--lane-h) items-center gap-1 border-b border-border px-2 type-label",
3858
4199
  children: [/* @__PURE__ */ jsx("span", {
3859
4200
  className: "min-w-0 flex-1 truncate",
3860
4201
  title: l.label,
@@ -3919,12 +4260,21 @@ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, posit
3919
4260
  className: "p-4",
3920
4261
  children: empty
3921
4262
  }),
3922
- lanes.map((l) => /* @__PURE__ */ jsx("div", {
3923
- role: "group",
3924
- "aria-label": l.label,
3925
- ref: (el) => void (el ? laneRefs.current.set(l.id, el) : laneRefs.current.delete(l.id)),
3926
- className: "relative h-(--control-h) border-b border-border",
3927
- children: (sorted.get(l.id) ?? []).filter(visible).map((item) => {
4263
+ lanes.map((l) => /* @__PURE__ */ jsxs(LaneRow, {
4264
+ label: l.label,
4265
+ register: (el) => void (el ? laneRefs.current.set(l.id, el) : laneRefs.current.delete(l.id)),
4266
+ types: dropsOn ? dropTypes : void 0,
4267
+ onHover: (px) => onLaneHover(l.id, px),
4268
+ onLeave: () => setHover(null),
4269
+ onDropItems: (px, dropped) => onLaneDrop(l.id, px, dropped),
4270
+ children: [hover && hover.next.lane === l.id && /* @__PURE__ */ jsx("div", {
4271
+ "aria-hidden": true,
4272
+ className: cn("pointer-events-none absolute top-1 bottom-1 rounded-control border border-dashed", hover.reason ? "border-danger bg-danger-subtle" : "border-primary bg-muted"),
4273
+ style: {
4274
+ left: x(hover.next.start),
4275
+ width: Math.max(hover.next.length * zoom, 4)
4276
+ }
4277
+ }), (sorted.get(l.id) ?? []).filter(visible).map((item) => {
3928
4278
  const live = drag?.id === item.id && drag.moved ? drag : null;
3929
4279
  const shown = live ? live.next : item;
3930
4280
  const laneShift = live ? (laneIndex.get(live.next.lane) ?? 0) - (laneIndex.get(item.lane) ?? 0) : 0;
@@ -3946,8 +4296,8 @@ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, posit
3946
4296
  style: {
3947
4297
  left: px,
3948
4298
  width: w,
3949
- borderTopColor: item.kind ? kindColour(item.kind, items) : void 0,
3950
- transform: laneShift ? `translateY(calc(var(--control-h) * ${laneShift}))` : void 0,
4299
+ borderTopColor: item.kind ? kindColours?.[item.kind] ?? kindColour(item.kind, items) : void 0,
4300
+ transform: laneShift ? `translateY(calc(var(--lane-h) * ${laneShift}))` : void 0,
3951
4301
  zIndex: live ? 10 : void 0
3952
4302
  },
3953
4303
  children: [
@@ -3976,36 +4326,45 @@ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, posit
3976
4326
  })
3977
4327
  ]
3978
4328
  }, item.id);
3979
- })
4329
+ })]
3980
4330
  }, l.id)),
3981
4331
  position !== void 0 && /* @__PURE__ */ jsx("div", {
3982
4332
  "aria-hidden": true,
3983
4333
  className: "pointer-events-none absolute top-8 bottom-0 w-0.5 bg-primary",
3984
4334
  style: { left: x(position) - 1 }
3985
4335
  }),
3986
- drag?.moved && drag.guide !== null && /* @__PURE__ */ jsx("div", {
3987
- "aria-hidden": true,
3988
- className: "pointer-events-none absolute top-0 bottom-0 w-px bg-foreground",
3989
- style: { left: x(drag.guide) }
3990
- })
4336
+ (() => {
4337
+ const guide = drag?.moved ? drag.guide : hover?.guide ?? null;
4338
+ return guide !== null && /* @__PURE__ */ jsx("div", {
4339
+ "aria-hidden": true,
4340
+ className: "pointer-events-none absolute top-0 bottom-0 w-px bg-foreground",
4341
+ style: { left: x(guide) }
4342
+ });
4343
+ })()
3991
4344
  ]
3992
4345
  })
3993
4346
  })]
3994
4347
  }),
3995
- drag?.moved && /* @__PURE__ */ jsx("p", {
3996
- "aria-hidden": true,
3997
- className: "mt-1 flex items-center gap-1.5 type-body-sm tabular-nums text-muted-foreground",
3998
- children: drag.reason ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Ban, { className: "size-4 shrink-0 text-danger" }), /* @__PURE__ */ jsx("span", {
3999
- className: "text-danger",
4000
- children: drag.reason
4001
- })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
4002
- formatTime(drag.next.start),
4003
- " to ",
4004
- formatTime(drag.next.start + drag.next.length),
4005
- ", ",
4006
- laneLabel(drag.next.lane)
4007
- ] })
4008
- })
4348
+ (() => {
4349
+ const info = drag?.moved ? {
4350
+ next: drag.next,
4351
+ reason: drag.reason
4352
+ } : hover;
4353
+ return info && /* @__PURE__ */ jsx("p", {
4354
+ "aria-hidden": true,
4355
+ className: "mt-1 flex items-center gap-1.5 type-body-sm tabular-nums text-muted-foreground",
4356
+ children: info.reason ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Ban, { className: "size-4 shrink-0 text-danger" }), /* @__PURE__ */ jsx("span", {
4357
+ className: "text-danger",
4358
+ children: info.reason
4359
+ })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
4360
+ formatTime(info.next.start),
4361
+ " to ",
4362
+ formatTime(info.next.start + info.next.length),
4363
+ ", ",
4364
+ laneLabel(info.next.lane)
4365
+ ] })
4366
+ });
4367
+ })()
4009
4368
  ]
4010
4369
  });
4011
4370
  }
@@ -4025,6 +4384,32 @@ function DefaultItem({ item, width }) {
4025
4384
  })]
4026
4385
  });
4027
4386
  }
4387
+ /** One lane: a labelled group that is a React Aria drop target when `types` is given. `px` is the pointer's distance along the lane, or null for a keyboard drag (the lane is then the focused element). */
4388
+ function LaneRow({ label, register, types, onHover, onLeave, onDropItems, children }) {
4389
+ const ref = React.useRef(null);
4390
+ const keyboard = () => document.activeElement === ref.current;
4391
+ const { dropProps } = useDrop({
4392
+ ref,
4393
+ isDisabled: !types,
4394
+ getDropOperation: (t) => types?.some((type) => t.has(type)) ? "copy" : "cancel",
4395
+ onDropEnter: (e) => onHover(keyboard() ? null : e.x),
4396
+ onDropMove: (e) => onHover(keyboard() ? null : e.x),
4397
+ onDropExit: onLeave,
4398
+ onDrop: (e) => e.dropOperation !== "cancel" && onDropItems(keyboard() ? null : e.x, e.items)
4399
+ });
4400
+ return /* @__PURE__ */ jsx("div", {
4401
+ ...types ? dropProps : {},
4402
+ ref: (el) => {
4403
+ ref.current = el;
4404
+ register(el);
4405
+ },
4406
+ role: "group",
4407
+ "aria-label": label,
4408
+ tabIndex: types ? -1 : void 0,
4409
+ className: "relative h-(--lane-h) border-b border-border",
4410
+ children
4411
+ });
4412
+ }
4028
4413
  // src/components/sortable-list.tsx
4029
4414
  var KIND = "strata-kind/";
4030
4415
  var ID = "strata-item/id";
@@ -4267,30 +4652,38 @@ function FileOutcomes({ intake, className }) {
4267
4652
  })]
4268
4653
  });
4269
4654
  }
4270
- /** A saved item whose file is gone: the item's name, a "File missing" status (a word and an icon) and a "Relink" button that opens the picker for this one item. */
4271
- function MissingFile({ name, accept, onRelink, className }) {
4655
+ /**
4656
+ * A saved item whose file is gone: the item's name, a "File missing" status (a word and an icon) and a "Relink" button that opens the picker for this one item.
4657
+ * In a narrow column the name keeps its own line, in full, and the status and button wrap under it. An optional `thumbnail` sits beside all three.
4658
+ */
4659
+ function MissingFile({ name, accept, onRelink, thumbnail, className }) {
4272
4660
  return /* @__PURE__ */ jsxs("div", {
4273
4661
  className: cn("flex min-w-0 items-center gap-3", className),
4274
- children: [
4275
- /* @__PURE__ */ jsx("span", {
4276
- className: "min-w-0 flex-1 truncate type-body",
4662
+ children: [thumbnail && /* @__PURE__ */ jsx("div", {
4663
+ className: "shrink-0",
4664
+ children: thumbnail
4665
+ }), /* @__PURE__ */ jsxs("div", {
4666
+ className: "flex min-w-0 flex-1 flex-wrap items-center gap-x-3 gap-y-1",
4667
+ children: [/* @__PURE__ */ jsx("span", {
4668
+ className: "min-w-40 flex-auto break-words type-body",
4277
4669
  title: name,
4278
4670
  children: name
4279
- }),
4280
- /* @__PURE__ */ jsx(Status, {
4281
- tone: "warning",
4282
- icon: FileQuestion,
4283
- children: "File missing"
4284
- }),
4285
- /* @__PURE__ */ jsx(FileButton, {
4286
- accept,
4287
- variant: "ghost",
4288
- size: "sm",
4289
- "aria-label": `Relink ${name}`,
4290
- onFiles: ([file]) => onRelink(file),
4291
- children: "Relink"
4292
- })
4293
- ]
4671
+ }), /* @__PURE__ */ jsxs("div", {
4672
+ className: "flex items-center gap-2",
4673
+ children: [/* @__PURE__ */ jsx(Status, {
4674
+ tone: "warning",
4675
+ icon: FileQuestion,
4676
+ children: "File missing"
4677
+ }), /* @__PURE__ */ jsx(FileButton, {
4678
+ accept,
4679
+ variant: "ghost",
4680
+ size: "sm",
4681
+ "aria-label": `Relink ${name}`,
4682
+ onFiles: ([file]) => onRelink(file),
4683
+ children: "Relink"
4684
+ })]
4685
+ })]
4686
+ })]
4294
4687
  });
4295
4688
  }
4296
4689
  // src/lib/file-intake.ts
@@ -5059,7 +5452,7 @@ function fitTicks(ticks, scale, widthOf, gap = 12) {
5059
5452
  return sorted.slice(0, 1);
5060
5453
  }
5061
5454
  /** One measured series, drawn in real pixels, with the peak and current readings labelled on the chart and every reading in a screen-reader table. Optional plan, threshold band and `colourScale`. */
5062
- function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, formatX, formatY, xTicks, yMin, yMax, colour = "var(--chart-1)", colourScale, colourScaleLabel, current, formatCurrent, readout, onPick, area, height = 280, className }) {
5455
+ function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, formatX, xLabel = "Time", formatY, xTicks, yMin, yMax, colour = "var(--chart-1)", colourScale, colourScaleLabel, current, formatCurrent, readout, onPick, area, height = 280, className }) {
5063
5456
  const [ref, width] = useWidth();
5064
5457
  const gradientId = `heat-${React.useId().replace(/[^\w-]/g, "")}`;
5065
5458
  const all = [...series, ...planned ?? []];
@@ -5220,7 +5613,7 @@ function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, fo
5220
5613
  /* @__PURE__ */ jsx("caption", { children: label }),
5221
5614
  /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
5222
5615
  scope: "col",
5223
- children: "Time"
5616
+ children: xLabel
5224
5617
  }), /* @__PURE__ */ jsx("th", {
5225
5618
  scope: "col",
5226
5619
  children: seriesLabel
@@ -5232,7 +5625,8 @@ function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, fo
5232
5625
  seriesLabel,
5233
5626
  series,
5234
5627
  formatX,
5235
- formatY
5628
+ formatY,
5629
+ xLabel
5236
5630
  ]);
5237
5631
  const sorted = React.useMemo(() => [...series].sort((p, q) => p.x - q.x), [series]);
5238
5632
  const interactive = Boolean(readout || onPick);
@@ -6170,7 +6564,7 @@ function FullscreenFrame({ label, active, onActiveChange, children, className })
6170
6564
  isOpen: true,
6171
6565
  onOpenChange: (o) => !o && onActiveChange(false),
6172
6566
  isDismissable: true,
6173
- className: "layer-overlay fixed inset-0 bg-foreground/40",
6567
+ className: "layer-overlay fixed inset-0 scrim",
6174
6568
  children: /* @__PURE__ */ jsx(Modal, {
6175
6569
  className: cn("h-full w-full outline-none", overlaySurface, "rounded-none"),
6176
6570
  children: /* @__PURE__ */ jsx(Dialog$1, {
@@ -6481,7 +6875,9 @@ function DifferenceMarks({ difference }) {
6481
6875
  if (!canvas || !ctx) return;
6482
6876
  canvas.width = difference.width;
6483
6877
  canvas.height = difference.height;
6484
- ctx.putImageData(new ImageData(difference.marks, difference.width, difference.height), 0, 0);
6878
+ const image = ctx.createImageData(difference.width, difference.height);
6879
+ image.data.set(difference.marks);
6880
+ ctx.putImageData(image, 0, 0);
6485
6881
  }, [difference]);
6486
6882
  return /* @__PURE__ */ jsx("canvas", {
6487
6883
  ref,
@@ -7054,6 +7450,311 @@ function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys
7054
7450
  })
7055
7451
  });
7056
7452
  }
7453
+ // src/components/workspace.tsx
7454
+ var readPersisted = (key) => {
7455
+ const empty = {
7456
+ sizes: {},
7457
+ collapsed: {}
7458
+ };
7459
+ if (!key) return empty;
7460
+ try {
7461
+ const raw = JSON.parse(window.localStorage.getItem(`strata:workspace:${key}`) ?? "null");
7462
+ if (!raw || typeof raw !== "object") return empty;
7463
+ const sizes = {};
7464
+ for (const [k, v] of Object.entries(raw.sizes ?? {})) if (typeof v === "number" && Number.isFinite(v)) sizes[k] = v;
7465
+ const collapsed = {};
7466
+ for (const [k, v] of Object.entries(raw.collapsed ?? {})) if (typeof v === "boolean") collapsed[k] = v;
7467
+ return {
7468
+ sizes,
7469
+ collapsed
7470
+ };
7471
+ } catch {
7472
+ return empty;
7473
+ }
7474
+ };
7475
+ /** The sizes and folded panes of a `Workspace`; with `persist`, remembered in localStorage under that name. */
7476
+ function useWorkspaceState(persist) {
7477
+ const [saved, setSaved] = React.useState(() => readPersisted(persist));
7478
+ const [narrow, setNarrow] = React.useState(false);
7479
+ const [narrowOpen, setNarrowOpen] = React.useState({});
7480
+ const defaults = React.useRef(/* @__PURE__ */ new Map());
7481
+ React.useEffect(() => {
7482
+ if (!persist) return;
7483
+ try {
7484
+ window.localStorage.setItem(`strata:workspace:${persist}`, JSON.stringify(saved));
7485
+ } catch {}
7486
+ }, [persist, saved]);
7487
+ return React.useMemo(() => {
7488
+ const isCollapsed = (id, fallback = defaults.current.get(id) ?? false) => narrow ? !narrowOpen[id] : saved.collapsed[id] ?? fallback;
7489
+ const setCollapsed = (id, collapsed) => {
7490
+ if (narrow) setNarrowOpen((o) => ({
7491
+ ...o,
7492
+ [id]: !collapsed
7493
+ }));
7494
+ else setSaved((s) => ({
7495
+ ...s,
7496
+ collapsed: {
7497
+ ...s.collapsed,
7498
+ [id]: collapsed
7499
+ }
7500
+ }));
7501
+ };
7502
+ return {
7503
+ isCollapsed,
7504
+ setCollapsed,
7505
+ toggle: (id) => setCollapsed(id, !isCollapsed(id)),
7506
+ reset: () => setSaved({
7507
+ sizes: {},
7508
+ collapsed: {}
7509
+ }),
7510
+ sizeOf: (id) => saved.sizes[id],
7511
+ setSize: (id, size) => setSaved((s) => {
7512
+ const sizes = { ...s.sizes };
7513
+ if (size === null) delete sizes[id];
7514
+ else sizes[id] = Math.round(size);
7515
+ return {
7516
+ ...s,
7517
+ sizes
7518
+ };
7519
+ }),
7520
+ register: (id, defaultCollapsed) => void defaults.current.set(id, defaultCollapsed),
7521
+ narrow,
7522
+ setNarrow
7523
+ };
7524
+ }, [
7525
+ saved,
7526
+ narrow,
7527
+ narrowOpen
7528
+ ]);
7529
+ }
7530
+ var StateContext = React.createContext(null);
7531
+ var useState_ = () => {
7532
+ const state = React.useContext(StateContext);
7533
+ if (!state) throw new Error("strata-react: a Pane or Split must be inside a Workspace.");
7534
+ return state;
7535
+ };
7536
+ var SlotContext = React.createContext({
7537
+ direction: "row",
7538
+ edge: "only",
7539
+ stacked: false
7540
+ });
7541
+ /** The workspace: a labelled region that holds the splits and panes, and stacks them when narrow. */
7542
+ function Workspace({ label, state, narrowBelow = 720, className, children }) {
7543
+ const ref = React.useRef(null);
7544
+ const { setNarrow } = state;
7545
+ React.useLayoutEffect(() => {
7546
+ const el = ref.current;
7547
+ if (!el || typeof ResizeObserver === "undefined") return;
7548
+ const measure = () => {
7549
+ const width = el.getBoundingClientRect().width;
7550
+ setNarrow(width > 0 && width < narrowBelow);
7551
+ };
7552
+ measure();
7553
+ const observer = new ResizeObserver(measure);
7554
+ observer.observe(el);
7555
+ return () => observer.disconnect();
7556
+ }, [narrowBelow, setNarrow]);
7557
+ return /* @__PURE__ */ jsx(StateContext.Provider, {
7558
+ value: state,
7559
+ children: /* @__PURE__ */ jsx("div", {
7560
+ ref,
7561
+ role: "group",
7562
+ "aria-label": label,
7563
+ className: cn("flex h-full min-h-0 min-w-0 flex-col overflow-hidden bg-background", className),
7564
+ children
7565
+ })
7566
+ });
7567
+ }
7568
+ var iconsFor = (direction, edge, stacked) => {
7569
+ if (stacked || direction === "column") return edge === "start" ? [PanelTopClose, PanelTopOpen] : [PanelBottomClose, PanelBottomOpen];
7570
+ return edge === "end" ? [PanelRightClose, PanelRightOpen] : [PanelLeftClose, PanelLeftOpen];
7571
+ };
7572
+ /** A region of a workspace with a consistent header (name, actions, fold button) and a body that scrolls. */
7573
+ function Pane({ id, name, grow, size = 280, min, max, collapsible, defaultCollapsed, actions, className, children }) {
7574
+ const state = useState_();
7575
+ const { direction, edge, stacked } = React.useContext(SlotContext);
7576
+ const headingId = React.useId();
7577
+ const { register } = state;
7578
+ React.useLayoutEffect(() => register(id, Boolean(defaultCollapsed)), [
7579
+ register,
7580
+ id,
7581
+ defaultCollapsed
7582
+ ]);
7583
+ const folded = Boolean(collapsible) && state.isCollapsed(id, Boolean(defaultCollapsed));
7584
+ const rail = folded && direction === "row" && !stacked;
7585
+ const least = min ?? (grow ? direction === "row" ? 240 : 120 : 160);
7586
+ const current = state.sizeOf(id) ?? size;
7587
+ const [closeIcon, openIcon] = iconsFor(direction, edge, stacked);
7588
+ const style = grow ? {
7589
+ flex: "1 1 0%",
7590
+ [direction === "row" ? "minWidth" : "minHeight"]: least
7591
+ } : folded ? { flex: "0 0 auto" } : stacked ? {
7592
+ flex: "0 1 auto",
7593
+ maxHeight: "50%"
7594
+ } : {
7595
+ flex: `0 1 ${Math.max(least, Math.min(current, max ?? Infinity))}px`,
7596
+ [direction === "row" ? "minWidth" : "minHeight"]: least,
7597
+ ...max ? { [direction === "row" ? "maxWidth" : "maxHeight"]: max } : {}
7598
+ };
7599
+ return /* @__PURE__ */ jsxs("section", {
7600
+ id: `pane-${id}`,
7601
+ "aria-labelledby": headingId,
7602
+ "data-pane": id,
7603
+ "data-collapsed": folded || void 0,
7604
+ "data-grow": grow || void 0,
7605
+ "data-min": grow ? least : void 0,
7606
+ "data-size": grow || folded ? void 0 : current,
7607
+ style,
7608
+ className: cn("flex min-h-0 min-w-0 flex-col overflow-hidden bg-background", rail && cn("w-(--control-h) items-center", edge === "end" ? "border-l border-border" : "border-r border-border"), className),
7609
+ children: [/* @__PURE__ */ jsxs("header", {
7610
+ className: cn("flex shrink-0 items-center gap-1 pl-3 pr-1", rail ? "h-auto flex-col py-1 pl-1" : "h-(--control-h) border-b border-border"),
7611
+ children: [
7612
+ /* @__PURE__ */ jsx("h2", {
7613
+ id: headingId,
7614
+ className: cn("type-label min-w-0 flex-1 truncate", rail && "sr-only"),
7615
+ children: name
7616
+ }),
7617
+ !folded && actions,
7618
+ collapsible && /* @__PURE__ */ jsx(IconButton, {
7619
+ size: "sm",
7620
+ icon: folded ? openIcon : closeIcon,
7621
+ label: folded ? `Show ${name}` : `Hide ${name}`,
7622
+ "aria-expanded": !folded,
7623
+ "aria-controls": `pane-body-${id}`,
7624
+ onPress: () => state.toggle(id)
7625
+ })
7626
+ ]
7627
+ }), /* @__PURE__ */ jsx("div", {
7628
+ id: `pane-body-${id}`,
7629
+ hidden: folded,
7630
+ className: "min-h-0 min-w-0 flex-1 overflow-auto",
7631
+ children
7632
+ })]
7633
+ });
7634
+ }
7635
+ var isPane = (c) => React.isValidElement(c) && c.type === Pane;
7636
+ var clamp = (n, lo, hi) => Math.min(Math.max(n, lo), hi);
7637
+ function Separator$1({ pane, direction, sign, container }) {
7638
+ const state = useState_();
7639
+ const [moving, setMoving] = React.useState(false);
7640
+ const min = pane.min ?? 160;
7641
+ const start = pane.size ?? 280;
7642
+ const size = state.sizeOf(pane.id) ?? start;
7643
+ const latest = React.useRef(size);
7644
+ latest.current = size;
7645
+ const measure = () => {
7646
+ const own = Array.from(container.current?.children ?? []).find((el) => el.dataset.pane === pane.id);
7647
+ return own ? Math.round(own.getBoundingClientRect()[direction === "row" ? "width" : "height"]) : 0;
7648
+ };
7649
+ const current = () => {
7650
+ const drawn = measure();
7651
+ return drawn > 0 && drawn < latest.current ? drawn : latest.current;
7652
+ };
7653
+ const [drawn, setDrawn] = React.useState(0);
7654
+ React.useEffect(() => {
7655
+ const root = container.current;
7656
+ if (!root || typeof ResizeObserver === "undefined") return;
7657
+ const observer = new ResizeObserver(() => setDrawn(measure()));
7658
+ observer.observe(root);
7659
+ setDrawn(measure());
7660
+ return () => observer.disconnect();
7661
+ }, [size, direction]);
7662
+ const shown = drawn > 0 && drawn < size ? drawn : size;
7663
+ const room = () => {
7664
+ const root = container.current;
7665
+ const kids = Array.from(root?.children ?? []);
7666
+ const own = kids.find((el) => el.dataset.pane === pane.id);
7667
+ const stage = kids.find((el) => el.dataset.grow !== void 0 || el.dataset.split !== void 0);
7668
+ if (!own || !stage) return Infinity;
7669
+ const dim = direction === "row" ? "width" : "height";
7670
+ const stageSize = stage.getBoundingClientRect()[dim];
7671
+ if (stageSize <= 0) return Infinity;
7672
+ const stageMin = Number(stage.dataset.min ?? 0);
7673
+ return own.getBoundingClientRect()[dim] + stageSize - stageMin;
7674
+ };
7675
+ const upper = () => Math.max(min, Math.min(pane.max ?? Infinity, room()));
7676
+ const apply = (next) => state.setSize(pane.id, clamp(next, min, upper()));
7677
+ const { moveProps } = useMove({
7678
+ onMoveStart: () => setMoving(true),
7679
+ onMove: ({ deltaX, deltaY, pointerType, shiftKey }) => {
7680
+ const delta = (direction === "row" ? deltaX : deltaY) * (pointerType === "keyboard" ? shiftKey ? 50 : 10 : 1);
7681
+ if (!delta) return;
7682
+ const next = clamp(current() + sign * delta, min, upper());
7683
+ latest.current = next;
7684
+ apply(next);
7685
+ },
7686
+ onMoveEnd: () => setMoving(false)
7687
+ });
7688
+ const restore = () => state.setSize(pane.id, null);
7689
+ const keys = {
7690
+ onKeyDown: (e) => {
7691
+ if (e.key === "Home") apply(min);
7692
+ else if (e.key === "End") apply(upper());
7693
+ else if (e.key === "Enter") restore();
7694
+ else return;
7695
+ e.preventDefault();
7696
+ },
7697
+ onDoubleClick: restore
7698
+ };
7699
+ const vertical = direction === "row";
7700
+ return /* @__PURE__ */ jsx("div", {
7701
+ role: "separator",
7702
+ tabIndex: 0,
7703
+ "aria-orientation": vertical ? "vertical" : "horizontal",
7704
+ "aria-label": `Resize ${pane.name}`,
7705
+ "aria-controls": `pane-${pane.id}`,
7706
+ "aria-valuenow": Math.round(shown),
7707
+ "aria-valuemin": min,
7708
+ "aria-valuemax": Number.isFinite(pane.max ?? Infinity) ? pane.max : void 0,
7709
+ "data-moving": moving || void 0,
7710
+ ...mergeProps(moveProps, keys),
7711
+ className: cn("relative shrink-0 touch-none bg-border transition-state hover:bg-primary focus-visible:bg-primary data-[moving]:bg-primary", vertical ? "w-px cursor-col-resize before:absolute before:inset-y-0 before:-inset-x-1" : "h-px cursor-row-resize before:absolute before:inset-x-0 before:-inset-y-1", "pointer-coarse:before:-inset-x-2")
7712
+ });
7713
+ }
7714
+ /** Lays its children out in a row or a column, with a separator between a fixed pane and its neighbour. A nested split takes the space the fixed panes leave. */
7715
+ function Split({ direction, className, children }) {
7716
+ const state = useState_();
7717
+ const ref = React.useRef(null);
7718
+ const stacked = direction === "row" && state.narrow;
7719
+ const effective = stacked ? "column" : direction;
7720
+ const items = React.Children.toArray(children);
7721
+ const slotted = (c) => isPane(c) || React.isValidElement(c) && c.type === Split;
7722
+ const grows = (c) => isPane(c) ? Boolean(c.props.grow) : true;
7723
+ const out = [];
7724
+ items.forEach((child, i) => {
7725
+ const growIndex = items.findIndex((c) => slotted(c) && grows(c));
7726
+ const edge = growIndex < 0 ? "only" : i < growIndex ? "start" : i > growIndex ? "end" : "only";
7727
+ out.push(/* @__PURE__ */ jsx(SlotContext.Provider, {
7728
+ value: {
7729
+ direction: effective,
7730
+ edge,
7731
+ stacked
7732
+ },
7733
+ children: child
7734
+ }, React.isValidElement(child) && child.key != null ? child.key : i));
7735
+ const next = items[i + 1];
7736
+ if (next === void 0 || !slotted(child) || !slotted(next)) return;
7737
+ const fixed = (c) => isPane(c) && !c.props.grow && !(c.props.collapsible && state.isCollapsed(c.props.id, c.props.defaultCollapsed));
7738
+ const before = fixed(child);
7739
+ const after = fixed(next);
7740
+ if (stacked || !before && !after) return;
7741
+ const controlled = before ? child : next;
7742
+ out.push(/* @__PURE__ */ jsx(Separator$1, {
7743
+ pane: controlled.props,
7744
+ direction: effective,
7745
+ sign: before ? 1 : -1,
7746
+ container: ref
7747
+ }, `sep-${i}`));
7748
+ });
7749
+ const growPane = items.find((c) => isPane(c) && Boolean(c.props.grow));
7750
+ return /* @__PURE__ */ jsx("div", {
7751
+ ref,
7752
+ "data-split": direction,
7753
+ "data-min": growPane ? growPane.props.min ?? (direction === "row" ? 240 : 120) : void 0,
7754
+ className: cn("flex min-h-0 min-w-0 flex-1", effective === "row" ? "flex-row" : "flex-col", className),
7755
+ children: out
7756
+ });
7757
+ }
7057
7758
  // src/components/history.tsx
7058
7759
  var compose = (older, newer) => ({
7059
7760
  label: older.label,
@@ -7396,6 +8097,6 @@ function SaveStatus({ state, onRetry, className }) {
7396
8097
  ]
7397
8098
  });
7398
8099
  }
7399
- export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareGrid, CompositionBar, ContextMenu, DEFAULT_TOLERANCE, DataTable, DataView, Density, Dialog, Disclosure, Done, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, Inspector, InspectorSection, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, MediaStage, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, Popover, PropertyList, PropertyRow, RateChoice, RowAction, SaveStatus, SeekBar, SelectableGrid, SideNav, Skeleton, Slider, SortableList, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, Transport, UndoBar, ViewportFrame, VirtualList, VolumeControl, actualPixelsScale, buttonVariants, canFullscreen, clampViewport, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, differences, fetchJson, fieldErrorsOf, format, formatChord, isReservedChord, isTypingTarget, labelOf, matchesAccept, matchesChord, noOverlap, parseChord, parseSort, readErrorBody, readPixels, resample, serialiseSort, staleOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toast, toastTimeout, transportShortcuts, typeSteps, useActiveItem, useAsyncAction, useAutoSave, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useLeaveGuard, useLoad, useSelection, useSystemColorScheme, useTimelineZoom, useUndoable, useViewport, zoomAt };
8100
+ export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareGrid, CompositionBar, ContextMenu, DEFAULT_TOLERANCE, DataTable, DataView, Density, Dialog, Disclosure, Done, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, Inspector, InspectorSection, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, Pane, Popover, PropertyList, PropertyRow, RateChoice, RowAction, SPEECH_RATES, SaveStatus, SeekBar, SelectableGrid, SideNav, Skeleton, Slider, SortableList, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, Transport, UndoBar, ViewportFrame, VirtualList, VolumeControl, Workspace, actualPixelsScale, buttonVariants, canFullscreen, clampViewport, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, differences, fetchJson, fieldErrorsOf, format, formatChord, geo, isReservedChord, isTypingTarget, labelOf, matchesAccept, matchesChord, noOverlap, parseChord, parseSort, readErrorBody, readPixels, resample, serialiseSort, staleOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toast, toastTimeout, transportShortcuts, typeSteps, useActiveItem, useAsyncAction, useAutoSave, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useLeaveGuard, useLoad, useMediaElement, useSelection, useSystemColorScheme, useTimelineZoom, useUndoable, useViewport, useWorkspaceState, zoomAt };
7400
8101
 
7401
8102
  //# sourceMappingURL=index.js.map