strata-react 2.1.0 → 2.1.2

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,22 +1,23 @@
1
1
  import { i as typeSteps, n as KeyText, r as cn, t as Tooltip } from "./tooltip-BosfsWYh.js";
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-DBCsFIng.js";
3
- import { a as isDev, i as buttonVariants, n as IconButton, o as useInView, r as RowAction, t as Button } from "./button-CYXjU-fs.js";
3
+ import { a as isDev, i as buttonVariants, n as IconButton, o as useInView, r as RowAction, t as Button } from "./button-CjnotDTb.js";
4
4
  import { t as followAim } from "./follow-CXQsL86O.js";
5
5
  import { n as useViewPointers, r as useWheelZoom, t as useSettledStatus } from "./viewer-input-3Qa-o35k.js";
6
- 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-76skMt6i.js";
7
- 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-5u7sD_wG.js";
6
+ 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-D3sbBVka.js";
7
+ 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-ColD28Pp.js";
8
8
  import { n as useSharedCursor, r as geo, t as CursorScope } from "./cursor-Cwyvgwsw.js";
9
9
  import { a as fieldErrorsOf, i as errorPayload, n as describeActionError, o as readErrorBody, r as describeHttpError, t as HttpError } from "./errors-CmuwcWlb.js";
10
10
  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-1oOSMj_D.js";
11
11
  import * as React from "react";
12
12
  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, Input as Input$1, Keyboard, Link, ListBox, ListBoxItem, ListLayout, ListStateContext, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, Popover as Popover$1, RouterProvider, Row, SearchField, Select, SelectValue, Separator, Slider as Slider$1, SliderThumb, SliderTrack, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Table, TableBody, TableHeader, TableLayout, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Tree as Tree$1, TreeItem, TreeItemContent, Virtualizer, useDragAndDrop, useFilter } from "react-aria-components";
13
- import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronDown, ChevronLeft, ChevronRight, CircleAlert, CircleCheck, CircleDashed, Clock, CloudOff, Columns2, Ellipsis, Eye, EyeOff, FastForward, FileQuestion, Flag, Folder, FolderOpen, FolderX, GripVertical, ImageOff, Info, KeyRound, LayoutGrid, List, Loader, LoaderCircle, Lock, Maximize, Maximize2, Minimize, Minus, PanelBottomClose, PanelBottomOpen, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen, PanelTopClose, PanelTopOpen, Pause, Pencil, Play, Redo2, Rewind, RotateCcw, RotateCw, Scan, Search, Send, SkipBack, SkipForward, SlidersHorizontal, Square, StepBack, StepForward, Trash2, TriangleAlert, Undo2, Upload, Volume2, VolumeX, X, ZoomIn, ZoomOut } from "lucide-react";
13
+ import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronsUp, CircleAlert, CircleCheck, CircleDashed, Clock, CloudOff, Columns2, Ellipsis, Eye, EyeOff, FastForward, FileQuestion, Flag, Folder, FolderOpen, FolderX, GripVertical, ImageOff, Info, KeyRound, LayoutGrid, List, Loader, LoaderCircle, Lock, Maximize, Maximize2, Minimize, Minus, PanelBottomClose, PanelBottomOpen, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen, PanelTopClose, PanelTopOpen, Pause, Pencil, Play, Redo2, Rewind, RotateCcw, RotateCw, Scan, Search, Send, SkipBack, SkipForward, SlidersHorizontal, Square, StepBack, StepForward, Trash2, TriangleAlert, Undo2, Upload, Volume2, VolumeX, X, ZoomIn, ZoomOut } from "lucide-react";
14
14
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
15
15
  import { Link as Link$1, NavLink, useHref, useNavigate, useSearchParams } from "react-router";
16
16
  import { hashKey, useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/react-query";
17
17
  import { createSortedRowModel, flexRender, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
18
18
  import { UNSAFE_PortalProvider, VisuallyHidden, mergeProps, useDrag, useDrop, useFocusRing, useMove, useSlider, useSliderThumb, useUNSAFE_PortalContext } from "react-aria";
19
19
  import { LayoutInfo, Rect, Size, useSliderState } from "react-stately";
20
+ import { createPortal } from "react-dom";
20
21
  import pixelmatch from "pixelmatch";
21
22
 
22
23
  // src/lib/chords.ts
@@ -4001,29 +4002,50 @@ function Transport({ playing, onPlayPause, onStop, onToStart, onToEnd, onStepBac
4001
4002
  ]
4002
4003
  });
4003
4004
  }
4004
- /** A mute button and a volume slider with its value in percent. Muting sets the volume to 0 and remembers the level; unmuting puts it back. Moving the slider from 0 unmutes. */
4005
- function VolumeControl({ volume, onVolumeChange, max = 100, disabled, className }) {
4005
+ /** A mute button and a volume slider with its value in percent. Muting sets the volume to 0 and remembers the level; unmuting puts it back. Moving the slider from 0 unmutes. With `boost`, a Louder toggle lets it past 100. */
4006
+ function VolumeControl({ volume, onVolumeChange, max = 100, boost, disabled, className }) {
4006
4007
  const last = React.useRef(volume > 0 ? volume : 100);
4007
4008
  if (volume > 0) last.current = volume;
4008
4009
  const muted = volume === 0;
4010
+ const [louderAsked, setLouderAsked] = React.useState(false);
4011
+ const canBoost = boost !== void 0 && boost > 100;
4012
+ const louder = canBoost && (louderAsked || volume > 100 || last.current > 100);
4013
+ const top = canBoost ? louder ? boost : 100 : max;
4009
4014
  return /* @__PURE__ */ jsxs("div", {
4010
4015
  className: cn("flex min-w-0 items-center gap-2", className),
4011
- children: [/* @__PURE__ */ jsx(IconButton, {
4012
- icon: muted ? VolumeX : Volume2,
4013
- label: muted ? "Unmute" : "Mute",
4014
- hint: "M",
4015
- disabled,
4016
- onClick: () => onVolumeChange(muted ? last.current : 0)
4017
- }), /* @__PURE__ */ jsx(Slider, {
4018
- "aria-label": "Volume",
4019
- value: volume,
4020
- onChange: onVolumeChange,
4021
- min: 0,
4022
- max,
4023
- unit: "%",
4024
- disabled,
4025
- className: "w-40 min-w-24 shrink"
4026
- })]
4016
+ children: [
4017
+ /* @__PURE__ */ jsx(IconButton, {
4018
+ icon: muted ? VolumeX : Volume2,
4019
+ label: muted ? "Unmute" : "Mute",
4020
+ hint: "M",
4021
+ disabled,
4022
+ onClick: () => onVolumeChange(muted ? last.current : 0)
4023
+ }),
4024
+ /* @__PURE__ */ jsx(Slider, {
4025
+ "aria-label": "Volume",
4026
+ value: Math.min(volume, top),
4027
+ onChange: onVolumeChange,
4028
+ min: 0,
4029
+ max: top,
4030
+ unit: "%",
4031
+ disabled,
4032
+ className: "w-40 min-w-24 shrink"
4033
+ }),
4034
+ canBoost && /* @__PURE__ */ jsx(Toggle, {
4035
+ label: `Louder, up to ${boost}%`,
4036
+ icon: ChevronsUp,
4037
+ iconOnly: true,
4038
+ pressed: louder,
4039
+ disabled,
4040
+ onChange: (on) => {
4041
+ setLouderAsked(on);
4042
+ if (!on && (volume > 100 || last.current > 100)) {
4043
+ last.current = 100;
4044
+ onVolumeChange(muted ? 0 : 100);
4045
+ }
4046
+ }
4047
+ })
4048
+ ]
4027
4049
  });
4028
4050
  }
4029
4051
  /** A choice of playback speed ("0.5×", "1×", "1.5×"), named "Playback speed": React Aria's Select. */
@@ -4571,6 +4593,121 @@ function createWatchedRanges() {
4571
4593
  };
4572
4594
  }
4573
4595
 
4596
+ // src/components/media-sound.ts
4597
+ /** The limiter's threshold, dB under full scale. */
4598
+ const LIMIT_DB = -1;
4599
+ const RATIO = 20;
4600
+ /** Seconds: how fast an app's level glides to a new value (a time constant; about three of them to arrive). */
4601
+ const GLIDE = .5;
4602
+ const FOLLOW = .02;
4603
+ /** The compressor's automatic make-up gain at the limiter's settings, as the Web Audio spec defines it. */
4604
+ function makeupGain(threshold = -1, ratio = RATIO) {
4605
+ const atFullScale = threshold + (0 - threshold) / ratio;
4606
+ return Math.pow(1 / Math.pow(10, atFullScale / 20), .6);
4607
+ }
4608
+ const graphs = /* @__PURE__ */ new WeakMap();
4609
+ /**
4610
+ * Whether this browser can play a level past the element's own (it has Web Audio), and, given an element, whether its
4611
+ * source may go through it: same-origin (or a `blob:` or `data:` URL, as a stream engine's Media Source is), or loaded
4612
+ * with `crossOrigin` set (then the server must answer with CORS). Any other file comes out of a graph as silence, so it
4613
+ * is never routed: it plays at its own level, with no gain and no boost.
4614
+ */
4615
+ function canShapeSound(el) {
4616
+ if (typeof window === "undefined" || typeof window.AudioContext !== "function") return false;
4617
+ if (!el) return true;
4618
+ const src = el.currentSrc || el.getAttribute("src") || "";
4619
+ if (!src || el.crossOrigin !== null) return true;
4620
+ try {
4621
+ const url = new URL(src, window.location.href);
4622
+ return url.protocol === "blob:" || url.protocol === "data:" || url.origin === window.location.origin;
4623
+ } catch {
4624
+ return false;
4625
+ }
4626
+ }
4627
+ function graphFor(el) {
4628
+ const had = graphs.get(el);
4629
+ if (had) return had;
4630
+ if (!canShapeSound(el)) return null;
4631
+ const context = new AudioContext();
4632
+ const level = context.createGain();
4633
+ const boost = context.createGain();
4634
+ const limiter = context.createDynamicsCompressor();
4635
+ limiter.threshold.value = -1;
4636
+ limiter.knee.value = 0;
4637
+ limiter.ratio.value = RATIO;
4638
+ limiter.attack.value = .001;
4639
+ limiter.release.value = .1;
4640
+ const unlift = context.createGain();
4641
+ unlift.gain.value = 1 / makeupGain();
4642
+ level.connect(boost).connect(limiter).connect(unlift).connect(context.destination);
4643
+ const graph = {
4644
+ context,
4645
+ level,
4646
+ boost,
4647
+ routed: false,
4648
+ waiting: false,
4649
+ levelTarget: 1,
4650
+ boostTarget: 1
4651
+ };
4652
+ graphs.set(el, graph);
4653
+ return graph;
4654
+ }
4655
+ function route(el, graph) {
4656
+ if (graph.context.state !== "running") {
4657
+ graph.context.resume().catch(() => {});
4658
+ return;
4659
+ }
4660
+ if (graph.routed) return;
4661
+ if (!canShapeSound(el)) return;
4662
+ try {
4663
+ graph.context.createMediaElementSource(el).connect(graph.level);
4664
+ graph.routed = true;
4665
+ } catch {
4666
+ graph.routed = true;
4667
+ }
4668
+ }
4669
+ /**
4670
+ * Applies `gain` (the app's level, a factor) and `boost` (the person's, a factor of 1 or more) to an element's sound.
4671
+ * Makes nothing while both are 1 and no graph exists yet. Call again whenever either changes, and on `play` (the
4672
+ * gesture that lets the context start).
4673
+ */
4674
+ function shapeSound(el, gain, boost, glide = true) {
4675
+ if (!graphs.has(el) && gain === 1 && boost === 1) return;
4676
+ const graph = graphFor(el);
4677
+ if (!graph) return;
4678
+ const now = graph.context.currentTime;
4679
+ const wanted = Math.max(0, gain);
4680
+ if (wanted !== graph.levelTarget) {
4681
+ graph.levelTarget = wanted;
4682
+ graph.level.gain.cancelScheduledValues(now);
4683
+ graph.level.gain.setTargetAtTime(wanted, now, graph.routed && glide ? GLIDE : FOLLOW);
4684
+ }
4685
+ if (boost !== graph.boostTarget) {
4686
+ graph.boostTarget = boost;
4687
+ graph.boost.gain.cancelScheduledValues(now);
4688
+ graph.boost.gain.setTargetAtTime(boost, now, FOLLOW);
4689
+ }
4690
+ if (!graph.routed && !graph.waiting && graph.context.state !== "running") {
4691
+ graph.waiting = true;
4692
+ graph.context.addEventListener("statechange", function started() {
4693
+ if (graph.context.state !== "running") return;
4694
+ graph.context.removeEventListener("statechange", started);
4695
+ graph.waiting = false;
4696
+ route(el, graph);
4697
+ });
4698
+ }
4699
+ route(el, graph);
4700
+ }
4701
+ /**
4702
+ * Lets go of an element's audio while its player is gone: suspends its context, which frees the audio thread. Not
4703
+ * closed, since an element can be given to a context only once: the same element mounted again (React's double mount in
4704
+ * development) resumes it on the next `shapeSound`.
4705
+ */
4706
+ function releaseSound(el) {
4707
+ const graph = graphs.get(el);
4708
+ if (graph && graph.context.state === "running") graph.context.suspend().catch(() => {});
4709
+ }
4710
+
4574
4711
  // src/components/link.tsx
4575
4712
  function useTarget(target, newTab, state) {
4576
4713
  const navigate = useNavigate();
@@ -4631,6 +4768,10 @@ function TextLink(all) {
4631
4768
  }
4632
4769
 
4633
4770
  // src/components/media-player.tsx
4771
+ /** The most the volume goes to: a boost where Web Audio can play it, else 100. */
4772
+ function maxVolumeOf(boost, el) {
4773
+ return boost && boost > 100 && canShapeSound(el) ? boost : 100;
4774
+ }
4634
4775
  /** How far one notch of the wheel over a focused video moves the volume, in percent. */
4635
4776
  const WHEEL_VOLUME_STEP = 5;
4636
4777
  const idle = {
@@ -4642,6 +4783,7 @@ const idle = {
4642
4783
  buffered: 0,
4643
4784
  volume: 100,
4644
4785
  muted: false,
4786
+ maxVolume: 100,
4645
4787
  rate: 1,
4646
4788
  ended: false,
4647
4789
  loading: false,
@@ -4708,6 +4850,7 @@ function useMediaElement(ref, options = {}) {
4708
4850
  const windowEnded = React.useRef(false);
4709
4851
  const streamProblem = React.useRef(null);
4710
4852
  const edgePause = React.useRef(false);
4853
+ const extra = React.useRef(1);
4711
4854
  const contextGroup = useMediaGroupName();
4712
4855
  const group = options.group ?? contextGroup;
4713
4856
  const read = React.useCallback(() => {
@@ -4734,8 +4877,9 @@ function useMediaElement(ref, options = {}) {
4734
4877
  time: Number.isFinite(el.currentTime) ? el.currentTime : 0,
4735
4878
  duration: known,
4736
4879
  buffered: bufferedAhead(el),
4737
- volume: el.muted ? 0 : Math.round(el.volume * 100),
4880
+ volume: el.muted ? 0 : Math.round(el.volume * extra.current * 100),
4738
4881
  muted: el.muted,
4882
+ maxVolume: maxVolumeOf(opts.current.boost, el),
4739
4883
  rate: el.playbackRate,
4740
4884
  ended: endedNow,
4741
4885
  loading: !error && el.networkState === 2 && el.readyState < 3 && !el.paused,
@@ -4761,9 +4905,21 @@ function useMediaElement(ref, options = {}) {
4761
4905
  el.currentTime = w.end;
4762
4906
  opts.current.onWindowEnd?.();
4763
4907
  }, []);
4908
+ const gain = options.gain ?? 1;
4909
+ React.useEffect(() => {
4910
+ const el = ref.current;
4911
+ if (el) shapeSound(el, gain, extra.current);
4912
+ }, [ref, gain]);
4913
+ React.useEffect(() => {
4914
+ const el = ref.current;
4915
+ return () => {
4916
+ if (el) releaseSound(el);
4917
+ };
4918
+ }, [ref]);
4764
4919
  useElementListeners(ref, (el) => {
4765
4920
  el.preservesPitch = true;
4766
4921
  const on = (e) => {
4922
+ if (e.type === "play") shapeSound(el, opts.current.gain ?? 1, extra.current);
4767
4923
  if (e.type === "play" || e.type === "playing") blocked.current = null;
4768
4924
  if (e.type === "play") {
4769
4925
  windowEnded.current = false;
@@ -4983,9 +5139,12 @@ function useMediaElement(ref, options = {}) {
4983
5139
  setVolume: (volume) => {
4984
5140
  const el = ref.current;
4985
5141
  if (!el) return;
4986
- const v = Math.min(Math.max(volume, 0), 100);
5142
+ const v = Math.min(Math.max(volume, 0), maxVolumeOf(opts.current.boost, el));
4987
5143
  el.muted = v === 0;
4988
- if (v > 0) el.volume = v / 100;
5144
+ if (v > 0) el.volume = Math.min(v, 100) / 100;
5145
+ extra.current = v > 100 ? v / 100 : 1;
5146
+ shapeSound(el, opts.current.gain ?? 1, extra.current);
5147
+ read();
4989
5148
  },
4990
5149
  setRate: (rate) => {
4991
5150
  const el = ref.current;
@@ -5096,7 +5255,7 @@ function useCoarsePointer() {
5096
5255
  * a touch device), with the failure to load shown and retried. For an editor or a replay, use the
5097
5256
  * parts and `useMediaElement` directly.
5098
5257
  */
5099
- function MediaPlayer({ label, kind = "audio", src, sources, index: controlledIndex, onIndexChange, autoAdvance = true, controls = "auto", autoPlay, poster, session, rates, shortcuts = true, attach, growing, window: bound, loop, showFull, group, onTimeUpdate, onWindowEnd, onEnded, onTimeChange, spans, spanKinds, marks, onSpan, spanWords, start, resumeWords, onProgress, progressEvery, mediaRef, heading, overlay, status, warning, aspect, fullscreen = true, skip = {}, fps, float = false, className }) {
5258
+ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledIndex, onIndexChange, autoAdvance = true, controls = "auto", autoPlay, poster, session, rates, shortcuts = true, attach, growing, window: bound, loop, showFull, group, onTimeUpdate, onWindowEnd, onEnded, onTimeChange, spans, spanKinds, marks, onSpan, spanWords, start, resumeWords, onProgress, progressEvery, mediaRef, heading, overlay, status, warning, gain, boost, crossOrigin, aspect, fullscreen = true, skip = {}, fps, float = false, className }) {
5100
5259
  const list = React.useMemo(() => sources ?? (src ? [{
5101
5260
  src,
5102
5261
  title: label
@@ -5125,7 +5284,9 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
5125
5284
  onRetry: attach ? (t) => stream.current.reload(t) : void 0,
5126
5285
  onProgress: onProgress ? progress : void 0,
5127
5286
  progressEvery,
5128
- progressKey: current?.src
5287
+ progressKey: current?.src,
5288
+ gain,
5289
+ boost
5129
5290
  });
5130
5291
  React.useEffect(() => void (sourceIndex.current = index), [index]);
5131
5292
  stream.current = useAttachedSource(ref, current?.src, attach, media.reportProblem, growing !== void 0, start);
@@ -5378,7 +5539,8 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
5378
5539
  if (!el.contains(document.activeElement) || e.ctrlKey || !e.deltaY) return;
5379
5540
  e.preventDefault();
5380
5541
  const m = latest.current;
5381
- m.setVolume(Math.min(100, Math.max(0, m.volume + (e.deltaY < 0 ? WHEEL_VOLUME_STEP : -5))));
5542
+ const top = m.volume > 100 ? m.maxVolume : 100;
5543
+ m.setVolume(Math.min(top, Math.max(0, m.volume + (e.deltaY < 0 ? WHEEL_VOLUME_STEP : -5))));
5382
5544
  };
5383
5545
  el.addEventListener("wheel", onWheel, { passive: false });
5384
5546
  return () => el.removeEventListener("wheel", onWheel);
@@ -5501,6 +5663,7 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
5501
5663
  controls: native,
5502
5664
  autoPlay,
5503
5665
  preload: "metadata",
5666
+ crossOrigin,
5504
5667
  "aria-label": `${label}, ${kind}`
5505
5668
  };
5506
5669
  const hasSpans = (spans?.length ?? 0) > 0;
@@ -5777,7 +5940,8 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
5777
5940
  }),
5778
5941
  /* @__PURE__ */ jsx(VolumeControl, {
5779
5942
  volume: media.volume,
5780
- onVolumeChange: media.setVolume
5943
+ onVolumeChange: media.setVolume,
5944
+ boost: media.maxVolume > 100 ? media.maxVolume : void 0
5781
5945
  }),
5782
5946
  canFull && /* @__PURE__ */ jsx(IconButton, {
5783
5947
  icon: full ? Minimize : Maximize,
@@ -12535,17 +12699,22 @@ const pieceSide = 96;
12535
12699
  const placedSide = 72;
12536
12700
  const placedPicture = { "--type-picture-size": "2.5rem" };
12537
12701
  const placeSide = 160;
12538
- /** Pictures put into places with two taps (pick up, put down) for an answer that is an arrangement: give a number, order, match, sort. The app owns where each piece is and checks it; the board only moves what the learner asks. */
12539
- function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places, placeKey, placeLabel, renderPlace, placement, onMove, pileLabel, placeState = () => "open", marks, locked = false, stretch = false, beckon = false, beckonMs = 1600, className }) {
12702
+ /** Pictures put into places for an answer that is an arrangement (give a number, order, match, sort): two taps (pick up, put down), one tap when there is one place, or a drag. The app owns where each piece is and checks it; the board only moves what the learner asks, and keeps every piece's slot so nothing shifts. */
12703
+ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places, placeKey, placeLabel, renderPlace, placement, onMove, pileLabel, placeState = () => "open", marks, locked = false, stretch = false, beckon = false, beckonMs = 1600, check, limit, className }) {
12540
12704
  const fill = stretch ? "auto-fit" : "auto-fill";
12541
12705
  const [heldKey, setHeld] = React.useState(null);
12542
12706
  const [follow, setFollow] = React.useState(null);
12707
+ const [drag, setDrag] = React.useState(null);
12543
12708
  const buttons = React.useRef(/* @__PURE__ */ new Map());
12709
+ const zones = React.useRef(/* @__PURE__ */ new Map());
12710
+ const dragged = React.useRef(false);
12711
+ const stopDrag = React.useRef(null);
12544
12712
  const placeKeys = new Set(places.map(placeKey));
12545
12713
  const where = (p) => {
12546
12714
  const at = placement[pieceKey(p)];
12547
12715
  return at !== void 0 && placeKeys.has(at) ? at : null;
12548
12716
  };
12717
+ const only = places.length === 1 ? places[0] : void 0;
12549
12718
  const held = locked ? void 0 : pieces.find((p) => pieceKey(p) === heldKey);
12550
12719
  const heldAt = held === void 0 ? null : where(held);
12551
12720
  const lit = useBeckon(beckon && !locked && held === void 0, pieces.filter((p) => where(p) === null).map(pieceKey), beckonMs);
@@ -12554,93 +12723,277 @@ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places,
12554
12723
  buttons.current.get(follow)?.focus();
12555
12724
  setFollow(null);
12556
12725
  }, [follow]);
12557
- const move = (to) => {
12558
- if (held === void 0) return;
12559
- const key = pieceKey(held);
12726
+ React.useEffect(() => () => stopDrag.current?.(), []);
12727
+ React.useEffect(() => {
12728
+ if (locked) stopDrag.current?.();
12729
+ }, [locked]);
12730
+ const bumped = (key, to) => {
12731
+ const s = places.find((q) => placeKey(q) === to);
12732
+ const max = s === void 0 || limit === void 0 ? Infinity : limit(s);
12733
+ const there = pieces.filter((p) => pieceKey(p) !== key && where(p) === to);
12734
+ return there.length >= max ? there[0] : void 0;
12735
+ };
12736
+ const room = (s) => Math.min(pieces.length, limit === void 0 ? Infinity : limit(s));
12737
+ const send = (key, to) => {
12560
12738
  setHeld(null);
12739
+ const out = to === null ? void 0 : bumped(key, to);
12740
+ if (out !== void 0) onMove(pieceKey(out), null);
12561
12741
  onMove(key, to);
12562
12742
  setFollow(key);
12563
12743
  };
12744
+ const move = (to) => {
12745
+ if (held !== void 0) send(pieceKey(held), to);
12746
+ };
12747
+ const latest = React.useRef({
12748
+ send,
12749
+ placement,
12750
+ placeKeys
12751
+ });
12752
+ latest.current = {
12753
+ send,
12754
+ placement,
12755
+ placeKeys
12756
+ };
12757
+ const hit = (x, y) => {
12758
+ for (const [key, el] of zones.current) {
12759
+ const r = el.getBoundingClientRect();
12760
+ if (x >= r.left && x <= r.right && y >= r.top && y <= r.bottom) return key;
12761
+ }
12762
+ };
12763
+ const press = (key) => (e) => {
12764
+ if (locked || e.button !== 0 || !e.isPrimary) return;
12765
+ stopDrag.current?.();
12766
+ const el = e.currentTarget;
12767
+ const { clientX: x0, clientY: y0, pointerId } = e;
12768
+ let size = null;
12769
+ const moved = (ev) => {
12770
+ if (ev.pointerId !== pointerId) return;
12771
+ if (size === null) {
12772
+ if (Math.hypot(ev.clientX - x0, ev.clientY - y0) < DRAG_START) return;
12773
+ const r = el.getBoundingClientRect();
12774
+ size = {
12775
+ w: r.width,
12776
+ h: r.height
12777
+ };
12778
+ dragged.current = true;
12779
+ setHeld(key);
12780
+ }
12781
+ ev.preventDefault();
12782
+ setDrag({
12783
+ key,
12784
+ x: ev.clientX,
12785
+ y: ev.clientY,
12786
+ ...size,
12787
+ over: hit(ev.clientX, ev.clientY)
12788
+ });
12789
+ };
12790
+ const ended = (ev) => {
12791
+ if (ev.pointerId !== pointerId) return;
12792
+ stop();
12793
+ if (size === null) return;
12794
+ const over = ev.type === "pointerup" ? hit(ev.clientX, ev.clientY) : void 0;
12795
+ const { send, placement, placeKeys } = latest.current;
12796
+ const raw = placement[key];
12797
+ const at = raw !== void 0 && placeKeys.has(raw) ? raw : null;
12798
+ const to = over === PILE ? null : over;
12799
+ if (to !== void 0 && to !== at) send(key, to);
12800
+ else setHeld(null);
12801
+ setTimeout(() => {
12802
+ dragged.current = false;
12803
+ }, 0);
12804
+ };
12805
+ const stop = () => {
12806
+ window.removeEventListener("pointermove", moved);
12807
+ window.removeEventListener("pointerup", ended);
12808
+ window.removeEventListener("pointercancel", ended);
12809
+ stopDrag.current = null;
12810
+ setDrag(null);
12811
+ };
12812
+ window.addEventListener("pointermove", moved);
12813
+ window.addEventListener("pointerup", ended);
12814
+ window.addEventListener("pointercancel", ended);
12815
+ stopDrag.current = () => {
12816
+ stop();
12817
+ dragged.current = false;
12818
+ if (size !== null) setHeld(null);
12819
+ };
12820
+ };
12821
+ const zone = (key) => (el) => {
12822
+ if (el) zones.current.set(key, el);
12823
+ else zones.current.delete(key);
12824
+ };
12825
+ const ref = (key) => (el) => {
12826
+ if (el) buttons.current.set(key, el);
12827
+ else buttons.current.delete(key);
12828
+ };
12829
+ const pieceClass = (key) => cn("@container relative flex aspect-square w-full min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-overlay border-2 border-border bg-card p-1 text-card-foreground select-none outline-offset-2 transition-state press", "hover:border-primary disabled:cursor-default disabled:hover:border-border", "selected:border-info selected:bg-info-subtle selected:ring-4 selected:ring-info", key === lit?.key && cn(lit.className, "border-primary"));
12830
+ const picture = (p, placed) => /* @__PURE__ */ jsx("span", {
12831
+ "aria-hidden": true,
12832
+ className: "type-picture",
12833
+ style: placed ? {
12834
+ ...placedPicture,
12835
+ ...pictureInTile
12836
+ } : pictureInTile,
12837
+ children: renderPiece(p)
12838
+ });
12564
12839
  const piece = (p, placed) => {
12565
12840
  const key = pieceKey(p);
12566
12841
  const isHeld = held !== void 0 && pieceKey(held) === key;
12567
- return /* @__PURE__ */ jsxs(ToggleButton, {
12568
- ref: (el) => {
12569
- if (el) buttons.current.set(key, el);
12570
- else buttons.current.delete(key);
12842
+ const name = pieceLabel(p);
12843
+ const control = only !== void 0 ? /* @__PURE__ */ jsxs(Button$1, {
12844
+ ref: ref(key),
12845
+ isDisabled: locked,
12846
+ onPress: () => {
12847
+ if (!dragged.current) send(key, placed ? null : placeKey(only));
12571
12848
  },
12849
+ "aria-label": placed ? `Take ${name} out of ${placeLabel(only)}` : `Put ${name} in ${placeLabel(only)}`,
12850
+ "data-beckon": key === lit?.key || void 0,
12851
+ className: cn(pieceClass(key), "group", isHeld && "border-info bg-info-subtle ring-4 ring-info"),
12852
+ children: [picture(p, placed), placed && !locked && /* @__PURE__ */ jsx("span", {
12853
+ "aria-hidden": true,
12854
+ "data-remove": true,
12855
+ className: "absolute inset-0 flex items-center justify-center rounded-overlay bg-background/70 text-foreground opacity-0 transition-state group-hover:opacity-100 group-focus-visible:opacity-100",
12856
+ children: /* @__PURE__ */ jsx(X, {
12857
+ className: "size-3/4",
12858
+ strokeWidth: 3
12859
+ })
12860
+ })]
12861
+ }) : /* @__PURE__ */ jsxs(ToggleButton, {
12862
+ ref: ref(key),
12572
12863
  isSelected: isHeld,
12573
- onChange: (on) => setHeld(on ? key : null),
12864
+ onChange: (on) => {
12865
+ if (!dragged.current) setHeld(on ? key : null);
12866
+ },
12574
12867
  isDisabled: locked,
12575
- "aria-label": isHeld ? `${pieceLabel(p)}, ${marks.held.toLowerCase()}` : pieceLabel(p),
12868
+ "aria-label": isHeld ? `${name}, ${marks.held.toLowerCase()}` : name,
12576
12869
  "data-held": isHeld || void 0,
12577
12870
  "data-beckon": key === lit?.key || void 0,
12578
- className: cn("@container flex aspect-square min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-overlay border-2 border-border bg-card p-1 text-card-foreground select-none outline-offset-2 transition-state press", "hover:border-primary disabled:cursor-default disabled:hover:border-border", "selected:border-4 selected:border-primary selected:bg-muted", key === lit?.key && cn(lit.className, "border-primary")),
12579
- children: [/* @__PURE__ */ jsx("span", {
12580
- "aria-hidden": true,
12581
- className: "type-picture",
12582
- style: placed ? {
12583
- ...placedPicture,
12584
- ...pictureInTile
12585
- } : pictureInTile,
12586
- children: renderPiece(p)
12587
- }), isHeld && /* @__PURE__ */ jsx(Status, {
12871
+ className: pieceClass(key),
12872
+ children: [picture(p, placed), isHeld && /* @__PURE__ */ jsx(Status, {
12588
12873
  tone: "info",
12589
12874
  className: "max-w-full truncate",
12590
12875
  children: marks.held
12591
12876
  })]
12877
+ });
12878
+ return /* @__PURE__ */ jsx("div", {
12879
+ "data-piece": key,
12880
+ onPointerDownCapture: press(key),
12881
+ onDragStart: (e) => e.preventDefault(),
12882
+ className: cn("grid min-w-0", !locked && "touch-none", drag?.key === key && "opacity-30"),
12883
+ children: control
12592
12884
  }, key);
12593
12885
  };
12594
- const grid = (inside, name, side) => inside.length > 0 && /* @__PURE__ */ jsx("div", {
12595
- role: "group",
12596
- "aria-label": name,
12597
- className: "grid min-w-0 gap-2",
12598
- style: { gridTemplateColumns: `repeat(${side === placedSide ? "auto-fill" : fill}, minmax(min(${side}px, 100%), 1fr))` },
12599
- children: inside.map((p) => piece(p, side === placedSide))
12600
- });
12601
- const pile = pieces.filter((p) => where(p) === null);
12886
+ const columns = (side, fit) => ({ gridTemplateColumns: `repeat(${fit}, minmax(min(${side}px, 100%), 1fr))` });
12887
+ const slot = (p) => {
12888
+ if (where(p) === null) return piece(p, false);
12889
+ const key = pieceKey(p);
12890
+ const isHeld = held !== void 0 && pieceKey(held) === key && only === void 0;
12891
+ const gap = "aspect-square min-w-0 rounded-overlay border-2 border-dashed border-border";
12892
+ return isHeld ? /* @__PURE__ */ jsx(Button$1, {
12893
+ onPress: () => move(null),
12894
+ "aria-label": `Put ${pieceLabel(p)} back`,
12895
+ className: cn(gap, "cursor-pointer border-solid border-info ring-4 ring-info outline-offset-2 transition-state press hover:bg-info-subtle")
12896
+ }, key) : /* @__PURE__ */ jsx("div", {
12897
+ "aria-hidden": true,
12898
+ "data-gap": true,
12899
+ className: gap
12900
+ }, key);
12901
+ };
12902
+ const target = (over) => over && "bg-info-subtle";
12903
+ const swap = (out) => out === void 0 ? "" : ` in place of ${pieceLabel(out)}`;
12602
12904
  return /* @__PURE__ */ jsxs("section", {
12603
12905
  "aria-label": label,
12604
12906
  className: cn("grid min-w-0 gap-6", className),
12605
- children: [/* @__PURE__ */ jsxs("div", {
12606
- className: "grid min-w-0 gap-2",
12607
- children: [grid(pile, pileLabel, pieceSide), heldAt !== null && held !== void 0 && /* @__PURE__ */ jsx(Button$1, {
12608
- onPress: () => move(null),
12609
- className: "min-h-(--control-h) justify-self-start rounded-control border border-input bg-background px-3 type-label transition-state press hover:bg-muted",
12610
- children: `Put ${pieceLabel(held)} back`
12611
- })]
12612
- }), /* @__PURE__ */ jsx("div", {
12613
- className: "grid min-w-0 gap-4",
12614
- style: { gridTemplateColumns: `repeat(${fill}, minmax(min(${placeSide}px, 100%), 1fr))` },
12615
- children: places.map((s) => {
12616
- const key = placeKey(s);
12617
- const state = placeState(s);
12618
- const name = placeLabel(s);
12619
- const inside = pieces.filter((p) => where(p) === key);
12620
- const takes = held !== void 0 && heldAt !== key;
12621
- return /* @__PURE__ */ jsxs("div", {
12622
- "data-place": state,
12623
- className: cn("grid min-w-0 content-start gap-2 rounded-overlay border-2 border-dashed border-input p-2 transition-state", takes && "border-solid border-primary", state === "right" && "border-4 border-solid border-success bg-success-subtle", state === "wrong" && "border-solid border-muted-foreground"),
12624
- children: [/* @__PURE__ */ jsxs(Button$1, {
12625
- isDisabled: !takes,
12626
- onPress: () => move(key),
12627
- "aria-label": (takes && held !== void 0 ? `Put ${pieceLabel(held)} in ${name}` : name) + (state === "open" ? "" : `, ${marks[state].toLowerCase()}`),
12628
- className: "flex min-h-30 min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-surface outline-offset-2 transition-state press hover:bg-muted disabled:cursor-default disabled:hover:bg-transparent",
12629
- children: [/* @__PURE__ */ jsx("span", {
12630
- "aria-hidden": true,
12631
- className: renderPlace ? "type-picture" : "type-heading",
12632
- children: renderPlace ? renderPlace(s) : name
12633
- }), state !== "open" && /* @__PURE__ */ jsx(Status, {
12634
- tone: state === "right" ? "success" : "neutral",
12635
- className: "max-w-full truncate",
12636
- children: marks[state]
12907
+ children: [
12908
+ /* @__PURE__ */ jsx("div", {
12909
+ ref: zone(PILE),
12910
+ role: "group",
12911
+ "aria-label": pileLabel,
12912
+ className: cn("grid min-w-0 gap-2 rounded-overlay transition-state", target(drag?.over === PILE && heldAt !== null)),
12913
+ style: columns(pieceSide, fill),
12914
+ children: pieces.map(slot)
12915
+ }),
12916
+ /* @__PURE__ */ jsx("div", {
12917
+ className: "grid min-w-0 gap-4",
12918
+ style: only !== void 0 ? void 0 : columns(placeSide, fill),
12919
+ children: places.map((s) => {
12920
+ const key = placeKey(s);
12921
+ const state = placeState(s);
12922
+ const name = placeLabel(s);
12923
+ const inside = pieces.filter((p) => where(p) === key);
12924
+ const takes = held !== void 0 && heldAt !== key;
12925
+ return /* @__PURE__ */ jsxs("div", {
12926
+ ref: zone(key),
12927
+ "data-place": state,
12928
+ className: cn("grid min-w-0 content-start gap-2 rounded-overlay border-2 border-dashed border-input p-2 transition-state", takes && "border-solid border-info ring-4 ring-info", takes && target(drag?.over === key), state === "right" && "border-solid border-success bg-success-subtle ring-2 ring-success", state === "wrong" && "border-solid border-muted-foreground"),
12929
+ children: [/* @__PURE__ */ jsxs(Button$1, {
12930
+ isDisabled: !takes || only !== void 0,
12931
+ onPress: () => move(key),
12932
+ "aria-label": (takes && held !== void 0 && only === void 0 ? `Put ${pieceLabel(held)} in ${name}` + swap(bumped(pieceKey(held), key)) : name) + (state === "open" ? "" : `, ${marks[state].toLowerCase()}`),
12933
+ className: "flex min-h-30 min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-surface outline-offset-2 transition-state press hover:bg-muted disabled:cursor-default disabled:hover:bg-transparent",
12934
+ children: [/* @__PURE__ */ jsx("span", {
12935
+ "aria-hidden": true,
12936
+ className: renderPlace ? "type-picture" : "type-heading",
12937
+ children: renderPlace ? renderPlace(s) : name
12938
+ }), state !== "open" && /* @__PURE__ */ jsx(Status, {
12939
+ tone: state === "right" ? "success" : "neutral",
12940
+ className: "max-w-full truncate",
12941
+ children: marks[state]
12942
+ })]
12943
+ }), /* @__PURE__ */ jsxs("div", {
12944
+ role: inside.length > 0 ? "group" : void 0,
12945
+ "aria-label": inside.length > 0 ? `In ${name}` : void 0,
12946
+ className: "grid min-w-0 gap-2",
12947
+ style: columns(placedSide, "auto-fill"),
12948
+ children: [inside.map((p) => piece(p, true)), Array.from({ length: Math.max(0, room(s) - inside.length) }, (_, i) => /* @__PURE__ */ jsx("div", {
12949
+ "aria-hidden": true,
12950
+ "data-room": true,
12951
+ className: "aspect-square min-w-0"
12952
+ }, `room${i}`))]
12637
12953
  })]
12638
- }), grid(inside, `In ${name}`, placedSide)]
12639
- }, key);
12640
- })
12641
- })]
12954
+ }, key);
12955
+ })
12956
+ }),
12957
+ check && !locked && /* @__PURE__ */ jsxs(Button, {
12958
+ variant: "default",
12959
+ size: "lg",
12960
+ onClick: check.onCheck,
12961
+ disabled: check.disabled,
12962
+ className: "justify-self-center",
12963
+ children: [
12964
+ /* @__PURE__ */ jsx(Check, {
12965
+ "aria-hidden": true,
12966
+ strokeWidth: 3
12967
+ }),
12968
+ check.label,
12969
+ /* @__PURE__ */ jsx(Check, {
12970
+ "aria-hidden": true,
12971
+ strokeWidth: 3
12972
+ })
12973
+ ]
12974
+ }),
12975
+ drag !== null && createPortal((() => {
12976
+ const p = pieces.find((q) => pieceKey(q) === drag.key);
12977
+ return p === void 0 ? null : /* @__PURE__ */ jsx("div", {
12978
+ "aria-hidden": true,
12979
+ "data-dragging": true,
12980
+ className: "@container pointer-events-none fixed z-50 flex items-center justify-center rounded-overlay border-2 border-info bg-info-subtle p-1 text-card-foreground shadow-overlay ring-4 ring-info",
12981
+ style: {
12982
+ left: drag.x - drag.w / 2,
12983
+ top: drag.y - drag.h / 2,
12984
+ width: drag.w,
12985
+ height: drag.h
12986
+ },
12987
+ children: picture(p, where(p) !== null)
12988
+ });
12989
+ })(), document.body)
12990
+ ]
12642
12991
  });
12643
12992
  }
12993
+ /** The pile's key among the drop zones: not a string a place key can be. */
12994
+ const PILE = "\0pile";
12995
+ /** How far a press moves, in px, before it is a drag rather than a tap (a finger wobbles a few). */
12996
+ const DRAG_START = 8;
12644
12997
 
12645
12998
  // src/components/infinite-list.tsx
12646
12999
  const PendingFocus = React.createContext(null);