strata-react 1.3.23 → 1.3.24

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
@@ -2,7 +2,7 @@ import { i as typeSteps, n as KeyText, r as cn, t as Tooltip } from "./tooltip-D
2
2
  import { a as Textarea, c as useSearchParam, d as createFormat, f as format, i as NativeSelect, l as MISSING, n as Field, o as useFieldControl, p as toDate, r as Input, s as controlHeight, t as ChoiceGroup, u as NBSP } from "./field-BjeE_FeB.js";
3
3
  import { a as isDev, i as buttonVariants, n as IconButton, o as useInView, r as RowAction, t as Button } from "./button-KGJI6jQr.js";
4
4
  import { A as StrataQueryProvider, C as toast, D as LoadError, E as EmptyState, F as useLoad, I as usePoll, L as overlaySurface, M as fetchJson, N as staleOf, O as Skeleton, P as toLoad, S as StrataToastRegion, T as DataView$1, _ as clampViewport, a as useMicrophone, b as viewportTransform, d as zoomToBox, f as FIT, g as boxViewport, h as actualPixelsScale, i as explainMicrophoneError, j as createQueryClient, k as StaleNotice, l as readingOrder, m as MIN_SCALE, n as MicrophoneError, o as Thumbnail, p as MAX_SCALE, r as browserMicrophone, s as ThumbnailSkeleton, t as MicrophoneContext, u as regionStyle, v as frameBoxToShares, w as toastTimeout, x as zoomAt, y as regionShares } from "./microphone-Bo3WaXgD.js";
5
- import { a as useAsyncAction, c as KeysLegend, d as useHotkeys, i as AsyncButton, l as isTypingTarget, n as NumberField, o as Toolbar, r as Slider, s as ToolbarSeparator, t as ColorField, u as keyName } from "./value-controls-Dq2-QpvA.js";
5
+ import { a as useAsyncAction, c as KeysLegend, d as useHotkeys, i as AsyncButton, l as isTypingTarget, n as NumberField, o as Toolbar, r as Slider, s as ToolbarSeparator, t as ColorField, u as keyName } from "./value-controls-Dm_EYfZW.js";
6
6
  import { n as useSharedCursor, r as geo, t as CursorScope } from "./cursor-DDGBPiTJ.js";
7
7
  import { a as fieldErrorsOf, i as errorPayload, n as describeActionError, o as readErrorBody, r as describeHttpError, t as HttpError } from "./errors-BUvY1Z4d.js";
8
8
  import { a as PaletteChoice, c as paletteScript, d as usePalette, f as useSystemColorScheme, i as PALETTE_STORAGE_KEY, l as palettes, n as ColorSchemeChoice, o as ThemeProvider, p as Density, r as DEFAULT_PALETTE, s as colorSchemeScript, t as COLOR_SCHEME_STORAGE_KEY, u as useColorScheme } from "./theme-CxYZkUNk.js";
@@ -1645,6 +1645,7 @@ function LinkCard({ title, description, marks, as: Heading = "h3", className, ex
1645
1645
  const describedBy = [description && descriptionId, marks && marksId].filter(Boolean).join(" ") || void 0;
1646
1646
  const linkClass = "rounded-control outline-none after:absolute after:inset-0 after:rounded-surface";
1647
1647
  return /* @__PURE__ */ jsxs("div", {
1648
+ "data-part": "link-card",
1648
1649
  className: cn("relative grid content-start gap-1.5 rounded-surface border border-border bg-background p-4 transition-state", "hover:border-muted-foreground has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-ring", className),
1649
1650
  children: [
1650
1651
  /* @__PURE__ */ jsx(Heading, {
@@ -3651,7 +3652,7 @@ function FullscreenFrame({ label, active, onActiveChange, modal: allowModal = tr
3651
3652
  });
3652
3653
  }
3653
3654
  // src/components/media.tsx
3654
- var clamp$3 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
3655
+ var clamp$4 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
3655
3656
  var timecode = (t, { precision, fps }) => format.timecode(t, {
3656
3657
  precision,
3657
3658
  fps
@@ -3742,8 +3743,8 @@ function SpanStrip({ spans, duration, label = "Marked parts", precision = "secon
3742
3743
  function drawableSpans(spans, duration) {
3743
3744
  return spans.map((s) => ({
3744
3745
  ...s,
3745
- start: clamp$3(s.start, 0, duration),
3746
- end: clamp$3(s.end, 0, duration)
3746
+ start: clamp$4(s.start, 0, duration),
3747
+ end: clamp$4(s.end, 0, duration)
3747
3748
  })).filter((s) => Number.isFinite(s.start) && Number.isFinite(s.end) && s.end > s.start).sort((a, b) => a.start - b.start);
3748
3749
  }
3749
3750
  /** A seek bar: dragged, clicked and moved by keys (arrows `step`, Page keys `bigStep`, Home and End), with its time as the accessible value. */
@@ -3752,8 +3753,8 @@ function SeekBar({ time, duration: known, onSeek, marks = [], spans = [], onMark
3752
3753
  const disabled = off || duration === 0;
3753
3754
  const track = React.useRef(null);
3754
3755
  const input = React.useRef(null);
3755
- const frac = duration > 0 ? clamp$3(time / duration, 0, 1) : 0;
3756
- const seekTo = (t) => onSeek(clamp$3(t, 0, duration));
3756
+ const frac = duration > 0 ? clamp$4(time / duration, 0, 1) : 0;
3757
+ const seekTo = (t) => onSeek(clamp$4(t, 0, duration));
3757
3758
  const shared = useSharedCursor();
3758
3759
  const joined = Boolean(cursorProp) && shared !== null;
3759
3760
  const mapping = typeof cursorProp === "object" ? cursorProp : void 0;
@@ -3790,7 +3791,7 @@ function SeekBar({ time, duration: known, onSeek, marks = [], spans = [], onMark
3790
3791
  minValue: 0,
3791
3792
  maxValue: Math.max(duration, fine),
3792
3793
  step: fine,
3793
- value: [clamp$3(time, 0, duration)],
3794
+ value: [clamp$4(time, 0, duration)],
3794
3795
  onChange: ([t]) => seekTo(t),
3795
3796
  numberFormatter: timeText,
3796
3797
  isDisabled: disabled
@@ -3832,7 +3833,7 @@ function SeekBar({ time, duration: known, onSeek, marks = [], spans = [], onMark
3832
3833
  onPointerMove: (e) => {
3833
3834
  if (!joined || duration === 0) return;
3834
3835
  const box = e.currentTarget.getBoundingClientRect();
3835
- shared.setPointer(toCursor(clamp$3((e.clientX - box.left) / (box.width || 1) * duration, 0, duration)));
3836
+ shared.setPointer(toCursor(clamp$4((e.clientX - box.left) / (box.width || 1) * duration, 0, duration)));
3836
3837
  },
3837
3838
  onPointerLeave: () => shared?.setPointer(null)
3838
3839
  }),
@@ -3846,7 +3847,7 @@ function SeekBar({ time, duration: known, onSeek, marks = [], spans = [], onMark
3846
3847
  buffered !== void 0 && duration > 0 && /* @__PURE__ */ jsx("span", {
3847
3848
  "aria-hidden": true,
3848
3849
  className: "absolute left-0 h-1.5 rounded-pill bg-neutral-4",
3849
- style: { width: `${clamp$3(buffered / duration, 0, 1) * 100}%` }
3850
+ style: { width: `${clamp$4(buffered / duration, 0, 1) * 100}%` }
3850
3851
  }),
3851
3852
  /* @__PURE__ */ jsx("span", {
3852
3853
  "aria-hidden": true,
@@ -4020,27 +4021,31 @@ function RateChoice({ rate, onRateChange, rates = [
4020
4021
  /**
4021
4022
  * The shortcuts a player takes, as one list for `useHotkeys` and `KeysLegend`: Space and K play
4022
4023
  * or pause, J and L go back or forward `jump` seconds, the arrows by `frame` seconds, Home and End
4023
- * to the ends, M mutes. Pass the player's actions; the labels are the legend's words.
4024
+ * to the ends, M mutes. Pass the player's actions; the labels are the legend's words. `stageKeys` is for a transport beside a stage that uses the arrows (see `TimelinePlayer`).
4024
4025
  */
4025
- function transportShortcuts({ toggle, seek, time, duration, frame = 1 / 30, jump = 1, toggleMute }) {
4026
- const to = (t) => () => seek(clamp$3(t, 0, duration));
4026
+ function transportShortcuts({ toggle, seek, time, duration, frame = 1 / 30, jump = 1, toggleMute, stageKeys }) {
4027
+ const to = (t) => () => seek(clamp$4(t, 0, duration));
4028
+ const anywhere = stageKeys || void 0;
4027
4029
  return [
4028
4030
  {
4029
4031
  keys: [" ", "k"],
4030
4032
  label: "Play or pause",
4031
- run: toggle
4033
+ run: toggle,
4034
+ anywhere
4032
4035
  },
4033
4036
  {
4034
4037
  keys: ["j"],
4035
4038
  label: `Back ${jump} s`,
4036
4039
  run: to(time - jump),
4037
- repeat: true
4040
+ repeat: true,
4041
+ anywhere
4038
4042
  },
4039
4043
  {
4040
4044
  keys: ["l"],
4041
4045
  label: `Forward ${jump} s`,
4042
4046
  run: to(time + jump),
4043
- repeat: true
4047
+ repeat: true,
4048
+ anywhere
4044
4049
  },
4045
4050
  {
4046
4051
  keys: ["ArrowLeft"],
@@ -4057,17 +4062,20 @@ function transportShortcuts({ toggle, seek, time, duration, frame = 1 / 30, jump
4057
4062
  {
4058
4063
  keys: ["Home"],
4059
4064
  label: "Go to start",
4060
- run: to(0)
4065
+ run: to(0),
4066
+ anywhere
4061
4067
  },
4062
4068
  {
4063
4069
  keys: ["End"],
4064
4070
  label: "Go to end",
4065
- run: to(duration)
4071
+ run: to(duration),
4072
+ anywhere
4066
4073
  },
4067
4074
  ...toggleMute ? [{
4068
4075
  keys: ["m"],
4069
4076
  label: "Mute",
4070
- run: toggleMute
4077
+ run: toggleMute,
4078
+ anywhere
4071
4079
  }] : []
4072
4080
  ];
4073
4081
  }
@@ -4179,9 +4187,68 @@ function StageGuides({ safe, thirds, centre, className }) {
4179
4187
  children: [draw("stroke-foreground", 3), draw("stroke-background", 1)]
4180
4188
  });
4181
4189
  }
4190
+ // src/components/key-owner.ts
4191
+ var members = /* @__PURE__ */ new Set();
4192
+ var active = null;
4193
+ var warned = false;
4194
+ var snapshot = {
4195
+ count: 0,
4196
+ active: null
4197
+ };
4198
+ var listeners = /* @__PURE__ */ new Set();
4199
+ var emit = () => {
4200
+ snapshot = {
4201
+ count: members.size,
4202
+ active
4203
+ };
4204
+ listeners.forEach((l) => l());
4205
+ };
4206
+ var subscribe = (l) => {
4207
+ listeners.add(l);
4208
+ return () => void listeners.delete(l);
4209
+ };
4210
+ var get = () => snapshot;
4211
+ /**
4212
+ * Joins the page's key owners while `enabled`, and takes the keys whenever `playing` turns true. Spread nothing: call
4213
+ * `claim` from the region's focus and pointer-down handlers, and bind the player's `useHotkeys` with `enabled: owner.owns`.
4214
+ */
4215
+ function useKeyOwner(enabled, playing = false) {
4216
+ const id = React.useId();
4217
+ React.useEffect(() => {
4218
+ if (!enabled) return;
4219
+ members.add(id);
4220
+ if (members.size === 2 && !warned && isDev()) {
4221
+ warned = true;
4222
+ console.warn("strata-react: several players are on this page, so Space, K, J, L and M go to the one last played or focused. Pass shortcuts={false} to one you bind your own keys for.");
4223
+ }
4224
+ emit();
4225
+ return () => {
4226
+ members.delete(id);
4227
+ if (active === id) active = null;
4228
+ emit();
4229
+ };
4230
+ }, [id, enabled]);
4231
+ const page = React.useSyncExternalStore(subscribe, get, get);
4232
+ const claim = React.useCallback(() => {
4233
+ if (active === id || !members.has(id)) return;
4234
+ active = id;
4235
+ emit();
4236
+ }, [id]);
4237
+ React.useEffect(() => {
4238
+ if (playing && enabled) claim();
4239
+ }, [
4240
+ playing,
4241
+ enabled,
4242
+ claim
4243
+ ]);
4244
+ return {
4245
+ owns: enabled && (page.count <= 1 || page.active === id),
4246
+ claim
4247
+ };
4248
+ }
4182
4249
  // src/components/media-group.tsx
4183
4250
  var groups = /* @__PURE__ */ new Map();
4184
- /** Adds an element to a named group until the returned function is called; whenever one plays, the others pause. */
4251
+ /** Adds an element, or a `useTimeline` clock, to a named group until the returned function is called; whenever one plays, the others pause. */
4185
4252
  function joinMediaGroup(name, el) {
4186
4253
  let members = groups.get(name);
4187
4254
  if (!members) groups.set(name, members = /* @__PURE__ */ new Set());
@@ -4946,48 +5013,6 @@ function useAttachedSource(ref, src, attach, onProblem, growing, start) {
4946
5013
  }, []);
4947
5014
  return React.useMemo(() => ({ reload: (at) => hold.current?.attachment.reload(at) }), []);
4948
5015
  }
4949
- var keyPlayers = (() => {
4950
- const ids = /* @__PURE__ */ new Set();
4951
- let active = null;
4952
- let warned = false;
4953
- const listeners = /* @__PURE__ */ new Set();
4954
- let snapshot = {
4955
- count: 0,
4956
- active: null
4957
- };
4958
- const emit = () => {
4959
- snapshot = {
4960
- count: ids.size,
4961
- active
4962
- };
4963
- listeners.forEach((l) => l());
4964
- };
4965
- return {
4966
- subscribe: (l) => {
4967
- listeners.add(l);
4968
- return () => void listeners.delete(l);
4969
- },
4970
- get: () => snapshot,
4971
- add(id) {
4972
- ids.add(id);
4973
- if (ids.size === 2 && !warned && isDev()) {
4974
- warned = true;
4975
- console.warn("strata-react: several MediaPlayers are on this page, so Space, K, J, L and M go to the one last played or focused. Pass shortcuts={false} to one you bind your own keys for.");
4976
- }
4977
- emit();
4978
- },
4979
- remove(id) {
4980
- ids.delete(id);
4981
- if (active === id) active = null;
4982
- emit();
4983
- },
4984
- use(id) {
4985
- if (active === id || !ids.has(id)) return;
4986
- active = id;
4987
- emit();
4988
- }
4989
- };
4990
- })();
4991
5016
  /** Playback speeds an audiobook or lecture listener expects. */
4992
5017
  var SPEECH_RATES = [
4993
5018
  .75,
@@ -5361,25 +5386,7 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
5361
5386
  frames,
5362
5387
  fps
5363
5388
  ]);
5364
- const id = React.useId();
5365
- React.useEffect(() => {
5366
- if (!shortcuts || native) return;
5367
- keyPlayers.add(id);
5368
- return () => keyPlayers.remove(id);
5369
- }, [
5370
- id,
5371
- shortcuts,
5372
- native
5373
- ]);
5374
- const page = React.useSyncExternalStore(keyPlayers.subscribe, keyPlayers.get, keyPlayers.get);
5375
- React.useEffect(() => {
5376
- if (media.playing && shortcuts && !native) keyPlayers.use(id);
5377
- }, [
5378
- media.playing,
5379
- id,
5380
- shortcuts,
5381
- native
5382
- ]);
5389
+ const owner = useKeyOwner(shortcuts && !native, media.playing);
5383
5390
  const activeKeys = autoHide ? keys.map((shortcut) => ({
5384
5391
  ...shortcut,
5385
5392
  run: () => {
@@ -5387,7 +5394,7 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
5387
5394
  shortcut.run();
5388
5395
  }
5389
5396
  })) : keys;
5390
- useHotkeys(activeKeys, { enabled: shortcuts && !native && (page.count <= 1 || page.active === id) });
5397
+ useHotkeys(activeKeys, { enabled: shortcuts && !native && owner.owns });
5391
5398
  React.useEffect(() => {
5392
5399
  if (!session || typeof navigator === "undefined" || !("mediaSession" in navigator) || typeof MediaMetadata === "undefined") return;
5393
5400
  const s = navigator.mediaSession;
@@ -5504,12 +5511,12 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
5504
5511
  role: "group",
5505
5512
  "aria-label": label,
5506
5513
  "data-floating": floating || void 0,
5507
- onFocusCapture: () => keyPlayers.use(id),
5514
+ onFocusCapture: owner.claim,
5508
5515
  onMouseMoveCapture: autoHide ? wakeControls : void 0,
5509
5516
  onKeyDownCapture: autoHide ? wakeControls : void 0,
5510
5517
  onMouseLeave: autoHide && !full ? sleepControls : void 0,
5511
5518
  onPointerDownCapture: () => {
5512
- keyPlayers.use(id);
5519
+ owner.claim();
5513
5520
  if (autoHide) wakeControls();
5514
5521
  },
5515
5522
  className: cn("relative grid w-full gap-2", full && "flex h-full min-h-0 flex-col", floating && cn("fixed right-4 bottom-4 layer-bar w-80 max-w-full gap-1.5 p-2", "rounded-overlay border border-border bg-popover text-popover-foreground shadow-overlay enter-overlay")),
@@ -6863,7 +6870,7 @@ async function defaultDecode(data) {
6863
6870
  ctx.close?.();
6864
6871
  }
6865
6872
  }
6866
- var clamp$2 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
6873
+ var clamp$3 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
6867
6874
  var clock = (t) => format.runningTime(t);
6868
6875
  /** An audio waveform with marks, spans and a playhead: one slider you click, drag or key to seek, zoom, and a range to select. */
6869
6876
  function Waveform({ label, peaks, source, duration: given, time, onSeek, marks = [], spans = [], underlay, range: controlledRange, onRangeChange, step = 5, bigStep = 30, defaultView, buckets = 2e3, normalise = false, decode = defaultDecode, words = WORDS, disabled, className }) {
@@ -6912,7 +6919,7 @@ function Waveform({ label, peaks, source, duration: given, time, onSeek, marks =
6912
6919
  const span = Math.max(v1 - v0, 1e-6);
6913
6920
  const zoomBy = (factor, about) => {
6914
6921
  const centre = about ?? (time >= v0 && time <= v1 ? time : (v0 + v1) / 2);
6915
- const next = clamp$2(span * factor, Math.min(duration, .5), duration);
6922
+ const next = clamp$3(span * factor, Math.min(duration, .5), duration);
6916
6923
  const from = centre - (centre - v0) / span * next;
6917
6924
  setView(next >= duration - 1e-6 ? null : clampView(from, next, duration));
6918
6925
  };
@@ -6987,8 +6994,8 @@ function Waveform({ label, peaks, source, duration: given, time, onSeek, marks =
6987
6994
  minValue: v0,
6988
6995
  maxValue: Math.max(v1, v0 + .01),
6989
6996
  step: .01,
6990
- value: [clamp$2(time, v0, Math.max(v1, v0 + .01))],
6991
- onChange: ([t]) => onSeek(clamp$2(t, 0, duration)),
6997
+ value: [clamp$3(time, v0, Math.max(v1, v0 + .01))],
6998
+ onChange: ([t]) => onSeek(clamp$3(t, 0, duration)),
6992
6999
  numberFormatter: timeText,
6993
7000
  isDisabled: off
6994
7001
  });
@@ -7004,7 +7011,7 @@ function Waveform({ label, peaks, source, duration: given, time, onSeek, marks =
7004
7011
  isDisabled: off
7005
7012
  }, state);
7006
7013
  const { focusProps, isFocusVisible } = useFocusRing();
7007
- const seekTo = (t) => onSeek(clamp$2(t, 0, duration));
7014
+ const seekTo = (t) => onSeek(clamp$3(t, 0, duration));
7008
7015
  const onKeyDownCapture = (e) => {
7009
7016
  if (off) return;
7010
7017
  const big = e.shiftKey ? bigStep : step;
@@ -7077,8 +7084,8 @@ function Waveform({ label, peaks, source, duration: given, time, onSeek, marks =
7077
7084
  for (let x = 0; x < width; x += column) {
7078
7085
  const [lo, hi] = peaksBetween(pair, (v0 + x / width * (v1 - v0)) / duration, (v0 + (x + column) / width * (v1 - v0)) / duration);
7079
7086
  if (!Number.isFinite(lo)) continue;
7080
- const top = 50 - clamp$2(hi * gain, -1, 1) * 48;
7081
- const bottom = 50 - clamp$2(lo * gain, -1, 1) * 48;
7087
+ const top = 50 - clamp$3(hi * gain, -1, 1) * 48;
7088
+ const bottom = 50 - clamp$3(lo * gain, -1, 1) * 48;
7082
7089
  d += `M${x + .5} ${top.toFixed(1)}V${Math.max(bottom, top + 1).toFixed(1)}`;
7083
7090
  }
7084
7091
  return d;
@@ -7152,8 +7159,8 @@ function Waveform({ label, peaks, source, duration: given, time, onSeek, marks =
7152
7159
  })
7153
7160
  }) }),
7154
7161
  spans.map((s) => {
7155
- const a = clamp$2(px(s.from), 0, width);
7156
- const b = clamp$2(px(s.to), 0, width);
7162
+ const a = clamp$3(px(s.from), 0, width);
7163
+ const b = clamp$3(px(s.to), 0, width);
7157
7164
  const tone = TONE$1[s.tone ?? "neutral"];
7158
7165
  return b > a ? /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("rect", {
7159
7166
  x: a,
@@ -7171,9 +7178,9 @@ function Waveform({ label, peaks, source, duration: given, time, onSeek, marks =
7171
7178
  })] }, `${s.from}-${s.to}-${s.label}`) : null;
7172
7179
  }),
7173
7180
  shown && /* @__PURE__ */ jsx("rect", {
7174
- x: clamp$2(px(shown[0]), 0, width),
7181
+ x: clamp$3(px(shown[0]), 0, width),
7175
7182
  y: 0,
7176
- width: Math.max(clamp$2(px(shown[1]), 0, width) - clamp$2(px(shown[0]), 0, width), 1),
7183
+ width: Math.max(clamp$3(px(shown[1]), 0, width) - clamp$3(px(shown[0]), 0, width), 1),
7177
7184
  height: 100,
7178
7185
  fill: "var(--primary-5)",
7179
7186
  opacity: .45
@@ -7247,7 +7254,7 @@ function Waveform({ label, peaks, source, duration: given, time, onSeek, marks =
7247
7254
  children: /* @__PURE__ */ jsx("div", {
7248
7255
  ...thumbProps,
7249
7256
  className: "absolute inset-y-0 w-0",
7250
- style: { left: `${clamp$2((time - v0) / span, 0, 1) * 100}%` },
7257
+ style: { left: `${clamp$3((time - v0) / span, 0, 1) * 100}%` },
7251
7258
  children: /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", {
7252
7259
  ref: input,
7253
7260
  ...mergeProps(inputProps, focusProps, { "aria-describedby": summaryId }),
@@ -7310,6 +7317,174 @@ function Waveform({ label, peaks, source, duration: given, time, onSeek, marks =
7310
7317
  ]
7311
7318
  });
7312
7319
  }
7320
+ // src/components/use-timeline.ts
7321
+ var clamp$2 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
7322
+ /** A playhead the app owns, in the shape `Transport`, `SeekBar` and `transportShortcuts` take. */
7323
+ function useTimeline({ duration, rate = 1, frame = 1 / 30, loop = false, startAt = "start", group, keys = true }) {
7324
+ const length = Number.isFinite(duration) && duration > 0 ? duration : 0;
7325
+ const [at, setAt] = React.useState(null);
7326
+ const [playing, setPlaying] = React.useState(false);
7327
+ const time = clamp$2(at ?? (startAt === "end" ? length : 0), 0, length);
7328
+ const live = React.useRef({
7329
+ time,
7330
+ length,
7331
+ rate,
7332
+ loop
7333
+ });
7334
+ live.current = {
7335
+ time,
7336
+ length,
7337
+ rate,
7338
+ loop
7339
+ };
7340
+ const member = React.useRef(null);
7341
+ if (!member.current) {
7342
+ const listeners = /* @__PURE__ */ new Set();
7343
+ member.current = {
7344
+ paused: true,
7345
+ pause: () => {},
7346
+ addEventListener: (_, l) => void listeners.add(l),
7347
+ removeEventListener: (_, l) => void listeners.delete(l),
7348
+ start: () => listeners.forEach((l) => l())
7349
+ };
7350
+ }
7351
+ const contextGroup = useMediaGroupName();
7352
+ const name = group ?? contextGroup;
7353
+ React.useEffect(() => name && member.current ? joinMediaGroup(name, member.current) : void 0, [name]);
7354
+ const pause = React.useCallback(() => setPlaying(false), []);
7355
+ if (member.current) {
7356
+ member.current.paused = !playing;
7357
+ member.current.pause = pause;
7358
+ }
7359
+ const play = React.useCallback(() => {
7360
+ const { time: t, length: n, loop: again } = live.current;
7361
+ if (n === 0) return;
7362
+ if (t >= n && !again) setAt(0);
7363
+ else setAt(t);
7364
+ setPlaying(true);
7365
+ member.current?.start();
7366
+ }, []);
7367
+ const seek = React.useCallback((to) => {
7368
+ setAt(clamp$2(to, 0, live.current.length));
7369
+ setPlaying(false);
7370
+ }, []);
7371
+ const toggle = React.useCallback(() => playing ? pause() : play(), [
7372
+ playing,
7373
+ pause,
7374
+ play
7375
+ ]);
7376
+ React.useEffect(() => {
7377
+ if (!playing) return;
7378
+ let last = performance.now();
7379
+ let id = requestAnimationFrame(function tick() {
7380
+ const now = performance.now();
7381
+ const { time: t, length: n, rate: r, loop: again } = live.current;
7382
+ let next = t + (now - last) / 1e3 * r;
7383
+ last = now;
7384
+ if (next >= n) {
7385
+ if (again) next = n > 0 ? next % n : 0;
7386
+ else {
7387
+ setAt(n);
7388
+ setPlaying(false);
7389
+ return;
7390
+ }
7391
+ }
7392
+ live.current = {
7393
+ ...live.current,
7394
+ time: next
7395
+ };
7396
+ setAt(next);
7397
+ id = requestAnimationFrame(tick);
7398
+ });
7399
+ return () => cancelAnimationFrame(id);
7400
+ }, [playing]);
7401
+ const owner = useKeyOwner(keys, playing);
7402
+ const regionProps = React.useMemo(() => ({
7403
+ onFocusCapture: owner.claim,
7404
+ onPointerDownCapture: owner.claim
7405
+ }), [owner.claim]);
7406
+ return {
7407
+ time,
7408
+ duration: length,
7409
+ playing,
7410
+ ended: !playing && length > 0 && time >= length && !loop,
7411
+ rate,
7412
+ frame,
7413
+ play,
7414
+ pause,
7415
+ toggle,
7416
+ seek,
7417
+ step: (count) => seek(live.current.time + count * frame),
7418
+ ownsKeys: owner.owns,
7419
+ regionProps
7420
+ };
7421
+ }
7422
+ // src/components/timeline-player.tsx
7423
+ /** A stage over a control bar for a timeline the app owns: transport, seek bar, time and speed, with the keys following the clock last used and the stage keeping its arrows. */
7424
+ function TimelinePlayer({ clock, label, stage, rates, onRateChange, legend = false, className }) {
7425
+ const bar = React.useRef(null);
7426
+ const fps = Math.max(1, Math.round(1 / clock.frame));
7427
+ const shortcuts = transportShortcuts({
7428
+ toggle: clock.toggle,
7429
+ seek: clock.seek,
7430
+ time: clock.time,
7431
+ duration: clock.duration,
7432
+ frame: clock.frame,
7433
+ stageKeys: true
7434
+ });
7435
+ const { live } = useHotkeys(shortcuts, {
7436
+ enabled: clock.ownsKeys,
7437
+ within: bar
7438
+ });
7439
+ return /* @__PURE__ */ jsxs("div", {
7440
+ role: "group",
7441
+ "aria-label": label,
7442
+ ...clock.regionProps,
7443
+ className: cn("grid min-w-0 gap-2", className),
7444
+ children: [
7445
+ /* @__PURE__ */ jsx("div", {
7446
+ className: "min-w-0",
7447
+ children: stage
7448
+ }),
7449
+ /* @__PURE__ */ jsxs("div", {
7450
+ ref: bar,
7451
+ className: "flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1",
7452
+ children: [
7453
+ /* @__PURE__ */ jsx(Transport, {
7454
+ playing: clock.playing,
7455
+ onPlayPause: clock.toggle,
7456
+ onToStart: () => clock.seek(0),
7457
+ onToEnd: () => clock.seek(clock.duration),
7458
+ onStepBack: () => clock.step(-1),
7459
+ onStepForward: () => clock.step(1),
7460
+ className: "shrink-0"
7461
+ }),
7462
+ /* @__PURE__ */ jsx(SeekBar, {
7463
+ time: clock.time,
7464
+ duration: clock.duration,
7465
+ onSeek: clock.seek,
7466
+ label: `Seek ${label}`,
7467
+ precision: "frames",
7468
+ fps,
7469
+ step: Math.max(clock.frame, clock.duration / 50)
7470
+ }),
7471
+ /* @__PURE__ */ jsx(TimeReadout, {
7472
+ time: clock.time,
7473
+ duration: clock.duration,
7474
+ precision: "frames",
7475
+ fps
7476
+ }),
7477
+ rates && onRateChange && /* @__PURE__ */ jsx(RateChoice, {
7478
+ rate: clock.rate,
7479
+ onRateChange,
7480
+ rates
7481
+ })
7482
+ ]
7483
+ }),
7484
+ legend && /* @__PURE__ */ jsx(KeysLegend, { shortcuts: live })
7485
+ ]
7486
+ });
7487
+ }
7313
7488
  // src/lib/timeline.ts
7314
7489
  /** 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. */
7315
7490
  var STEPS = [
@@ -9468,6 +9643,7 @@ function Inspector({ title, kind, empty, selectionKey, storageKey, actions, summ
9468
9643
  value: state,
9469
9644
  children: /* @__PURE__ */ jsx("aside", {
9470
9645
  ref: root,
9646
+ "data-part": "inspector",
9471
9647
  tabIndex: -1,
9472
9648
  "aria-labelledby": title === null ? void 0 : headingId,
9473
9649
  "aria-label": title === null ? "Properties" : void 0,
@@ -9476,6 +9652,7 @@ function Inspector({ title, kind, empty, selectionKey, storageKey, actions, summ
9476
9652
  className: "grid grid-cols-1 gap-4",
9477
9653
  children: [
9478
9654
  /* @__PURE__ */ jsxs("header", {
9655
+ "data-part": "inspector-header",
9479
9656
  className: "flex items-start gap-3",
9480
9657
  children: [/* @__PURE__ */ jsxs("div", {
9481
9658
  className: "min-w-0 flex-1",
@@ -9513,6 +9690,7 @@ function InspectorSection({ id, title, defaultOpen = true, actions, children, cl
9513
9690
  const expanded = inspector ? inspector.isOpen(id, defaultOpen) : own;
9514
9691
  const onChange = (open) => inspector ? inspector.setOpen(id, open) : setOwn(open);
9515
9692
  return /* @__PURE__ */ jsx(Disclosure$1, {
9693
+ "data-part": "inspector-section",
9516
9694
  isExpanded: expanded,
9517
9695
  onExpandedChange: onChange,
9518
9696
  className: cn("min-w-0 border-t border-border first:border-t-0", className),
@@ -16724,6 +16902,7 @@ function Workspace({ label, state, narrowBelow = 720, onFiles, acceptLabel, clas
16724
16902
  /** The bar across the top of a `Workspace`: the tool's name as the heading, a polite status line, the few actions, then an end slot for the scheme and palette choice. Wraps on a phone. */
16725
16903
  function WorkspaceBar({ title, status, actions, end, className }) {
16726
16904
  return /* @__PURE__ */ jsxs("header", {
16905
+ "data-part": "workspace-bar",
16727
16906
  className: cn("flex min-h-(--control-h) shrink-0 flex-wrap items-center gap-x-3 gap-y-1 border-b border-border px-3 py-1", className),
16728
16907
  children: [
16729
16908
  /* @__PURE__ */ jsx("h1", {
@@ -16781,6 +16960,7 @@ function Pane({ id, name, grow, size = 280, min, max, collapsible, defaultCollap
16781
16960
  id: `pane-${id}`,
16782
16961
  "aria-labelledby": headingId,
16783
16962
  "data-pane": id,
16963
+ "data-part": "pane",
16784
16964
  "data-collapsed": folded || void 0,
16785
16965
  "data-grow": grow || void 0,
16786
16966
  "data-min": grow ? least : void 0,
@@ -16788,10 +16968,12 @@ function Pane({ id, name, grow, size = 280, min, max, collapsible, defaultCollap
16788
16968
  style,
16789
16969
  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),
16790
16970
  children: [/* @__PURE__ */ jsxs("header", {
16971
+ "data-part": "pane-header",
16791
16972
  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"),
16792
16973
  children: [
16793
16974
  /* @__PURE__ */ jsx("h2", {
16794
16975
  id: headingId,
16976
+ "data-part": "pane-title",
16795
16977
  className: cn("type-label min-w-0 flex-1 truncate", rail && "sr-only"),
16796
16978
  children: name
16797
16979
  }),
@@ -19974,6 +20156,6 @@ function FolderPicker({ label, useFolders: useListing, value, onChange, onChoose
19974
20156
  ]
19975
20157
  });
19976
20158
  }
19977
- export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BookViewer, BoxList, BoxOverlay, BoxedPicture, Breadcrumb, BulkBar, Button, ButtonLink, ByteView, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGrid, ChoiceGridSkeleton, ChoiceGroup, ClipsProvider, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, Console, ContextMenu, Conversation, CursorScope, DEFAULT_PALETTE, DEFAULT_TOLERANCE, DataTable, DataView$1 as DataView, Density, Dialog, Disclosure, Done, DragSource, EmptyState, FIT, Field, FileButton, FileDropOverlay, FileDropZone, FileOutcomes, FilmStrip, FolderPicker, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, InputLevel, Inspector, InspectorSection, JobStatus, JobsTable, KeysLegend, LEVEL_FLOOR_DB, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, ListeningLevel, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaContents, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MicrophoneContext, MicrophoneError, MissingFile, NBSP, NativeSelect, NumberField, OutboxStatus, PALETTE_STORAGE_KEY, PageHeader, PairJudge, PairVote, PaletteChoice, Pane, PauseButton, PixelImage, PlaceBoard, PlayWindowButton, PlayerNotice, Popover, PropertyList, PropertyRow, RateChoice, RegionEditor, RichText, RowAction, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, ScheduleTable, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, ShortcutEditor, SideNav, Skeleton, Slider, SortableList, SpanActions, SpanStrip, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, SystemPanel, TableSkeleton, Tabs, TakeLevel, TextLink, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TileGrid, TileGridSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, UndoBar, ViewOptions, ViewportFrame, VirtualList, VolumeControl, Waveform, WorkflowSteps, WorkflowSummary, Workspace, WorkspaceBar, actualPixelsScale, ancestorsOf, apiPage, appBase, boxViewport, browserMicrophone, buttonVariants, canFullscreen, canPlayClips, canSay, canSpeak, checkKey, clampToRoom, clampViewport, clipsQueryKey, cn, colorSchemeScript, commandShortcut, countMarks, createApi, createFormat, createOutbox, createQueryClient, createReserve, createSegmenter, createTypedApi, crossedThreshold, currentItem, describeActionError, describeHttpError, describeRegion, describeWorkflowSummary, detectPlatform, diffWords, differences, diskThresholds, drawRect, ease, encodeWav, errorPayload, explainMicrophoneError, fetchJson, fieldErrorsOf, findPage, fitRect, format, formatChord, frameAt, gainToVolume, geo, gridPoints, gutterOf, inputLevelThresholds, isDoubtful, isRefusal, isReservedChord, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, keyName, labelOf, lerpRect, logScale, loudnessOf, marksFor, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, moveGutter, moveRect, noOverlap, normaliseAngle, pageName, paletteScript, palettes, parentOf, parseChord, parseInline, parseRichText, parseSort, peakDb, peakGain, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, pickEvenly, pickVoice, pixelZoom, plainText, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, regionStyle, resample, resamplePeaks, resizeRect, rgbaToBlob, rmsDb, safeHref, sayPosition, serialiseSort, settleCut, skipAction, snapToGrid, sortRows, speak, speechLevel, splitRect, staleOf, stepId, stepOnGrid, stopSpeaking, summariseWorkflow, textOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, turnRect, turnedSize, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoRecorder, useAutoSave, useBookUrl, useBoxes, useChoices, useClientWork, useClips, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useMicrophone, useObjectUrl, useOutbox, useOutboxStarted, usePalette, usePlayerWarnings, usePoll, useRebindableShortcuts, useRecorder, useReserve, useSayOnShow, useSearchParam, useSelection, useSharedCursor, useSpeech, useSystemColorScheme, useSystemInfo, useTimelineZoom, useUndoable, useViewOptions, useViewport, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
20159
+ export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BookViewer, BoxList, BoxOverlay, BoxedPicture, Breadcrumb, BulkBar, Button, ButtonLink, ByteView, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGrid, ChoiceGridSkeleton, ChoiceGroup, ClipsProvider, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, Console, ContextMenu, Conversation, CursorScope, DEFAULT_PALETTE, DEFAULT_TOLERANCE, DataTable, DataView$1 as DataView, Density, Dialog, Disclosure, Done, DragSource, EmptyState, FIT, Field, FileButton, FileDropOverlay, FileDropZone, FileOutcomes, FilmStrip, FolderPicker, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, InputLevel, Inspector, InspectorSection, JobStatus, JobsTable, KeysLegend, LEVEL_FLOOR_DB, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, ListeningLevel, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaContents, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MicrophoneContext, MicrophoneError, MissingFile, NBSP, NativeSelect, NumberField, OutboxStatus, PALETTE_STORAGE_KEY, PageHeader, PairJudge, PairVote, PaletteChoice, Pane, PauseButton, PixelImage, PlaceBoard, PlayWindowButton, PlayerNotice, Popover, PropertyList, PropertyRow, RateChoice, RegionEditor, RichText, RowAction, SPEECH_RATES, STRATA_DRAG_TYPE, SaveStatus, SayAgain, ScheduleTable, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, ShortcutEditor, SideNav, Skeleton, Slider, SortableList, SpanActions, SpanStrip, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, SystemPanel, TableSkeleton, Tabs, TakeLevel, TextLink, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TileGrid, TileGridSkeleton, TimeReadout, Timeline, TimelinePlayer, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, UndoBar, ViewOptions, ViewportFrame, VirtualList, VolumeControl, Waveform, WorkflowSteps, WorkflowSummary, Workspace, WorkspaceBar, actualPixelsScale, ancestorsOf, apiPage, appBase, boxViewport, browserMicrophone, buttonVariants, canFullscreen, canPlayClips, canSay, canSpeak, checkKey, clampToRoom, clampViewport, clipsQueryKey, cn, colorSchemeScript, commandShortcut, countMarks, createApi, createFormat, createOutbox, createQueryClient, createReserve, createSegmenter, createTypedApi, crossedThreshold, currentItem, describeActionError, describeHttpError, describeRegion, describeWorkflowSummary, detectPlatform, diffWords, differences, diskThresholds, drawRect, ease, encodeWav, errorPayload, explainMicrophoneError, fetchJson, fieldErrorsOf, findPage, fitRect, format, formatChord, frameAt, gainToVolume, geo, gridPoints, gutterOf, inputLevelThresholds, isDoubtful, isRefusal, isReservedChord, isTaskRunning, isTypingTarget, isWorkflowRunning, jobProgressText, joinMediaGroup, joinRects, joinSamples, keyName, labelOf, lerpRect, logScale, loudnessOf, marksFor, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, moveGutter, moveRect, noOverlap, normaliseAngle, pageName, paletteScript, palettes, parentOf, parseChord, parseInline, parseRichText, parseSort, peakDb, peakGain, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, pickEvenly, pickVoice, pixelZoom, plainText, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, regionStyle, resample, resamplePeaks, resizeRect, rgbaToBlob, rmsDb, safeHref, sayPosition, serialiseSort, settleCut, skipAction, snapToGrid, sortRows, speak, speechLevel, splitRect, staleOf, stepId, stepOnGrid, stopSpeaking, summariseWorkflow, textOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, turnRect, turnedSize, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoRecorder, useAutoSave, useBookUrl, useBoxes, useChoices, useClientWork, useClips, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useMicrophone, useObjectUrl, useOutbox, useOutboxStarted, usePalette, usePlayerWarnings, usePoll, useRebindableShortcuts, useRecorder, useReserve, useSayOnShow, useSearchParam, useSelection, useSharedCursor, useSpeech, useSystemColorScheme, useSystemInfo, useTimeline, useTimelineZoom, useUndoable, useViewOptions, useViewport, useWorkflowRun, useWorkspaceState, valueAt, viewOf, viewsOf, withBase, wordAt, wordId, zoomAt, zoomToBox };
19978
20160
 
19979
20161
  //# sourceMappingURL=index.js.map