strata-react 2.1.0 → 2.1.1
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/README.md +1 -1
- package/UPGRADING.md +4 -0
- package/dist/hls.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +189 -26
- package/dist/index.js.map +1 -1
- package/dist/{media-player-BETa3P7K.d.ts → media-player-Buvu2l7R.d.ts} +20 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -233,7 +233,7 @@ thousands of lines. Such an app imports the same stylesheet **without the reset*
|
|
|
233
233
|
| Overlays | `Dialog`, `DialogProps`, `AlertDialog`, `Popover`, `Tooltip` | React Aria underneath. A dialog always has a title and, via `actions`'s close render prop, a way out; `closable={false}` while work cannot stop; `placement="end"` is a sheet. `AlertDialog` is the only confirm: required verb on the confirm button, Cancel focused first, no outside dismiss, stays open with the reason when an async confirm fails. `Popover` needs a `label`. `Tooltip` opens on hover and focus and `IconButton` uses it. All portal onto the `layer-*` stacking utilities |
|
|
234
234
|
| Value controls | `NumberField`, `Slider`, `ColorField`, `SecretField` | Set a number or colour precisely, inside `Field`. `NumberField` and `Slider` are React Aria's; the number field runs with `commitBehavior="validate"`, so a typed value outside `min`/`max` is kept on screen, explained in the `Field` ("Enter a value from 0% to 500%.") and never passed to `onChange`. A value that is not known is `null` and shows an en dash, never 0 or NaN. Digits and decimal mark follow `locale`. The unit sits inside the control, and in the slider's spoken value when `Intl` has it (%, °, ms, s, kB, MB, GB, kbps, Mbps). Arrows step, Home/End jump to the limits; `Slider editable` adds a number field. `ColorField`: platform picker, typed hex that is normalised, app suggestions, and a contrast note against `against`. No motion on value changes. `NumberField` options for a value set a little at a time or that costs work to change: `nudge={[0.1, 1, 10]}` (a toolbar of named step buttons that repeat when held and stop at the limits), `suggestion={{ value, label, reason }}` (a row with the reason in words and Use this value, never applied by itself) and `preview` (changes wait behind Apply and Revert; `onChange` is Apply's). `SecretField` is a credential the server keeps and never shows again: not set, set (no characters, no length, no input in the DOM), a masked entry with a Show toggle named for what it reveals, `onSave` through `AsyncButton`, Replace, a confirmed Remove that says what stops working, and a Test whose result is text beside it; a set, untouched field reports nothing |
|
|
235
235
|
| Notices and progress | `Alert`, `toast`, `StrataToastRegion`, `useClientWork`, `JobStatus` | Three weights. A `toast` confirms finished work and goes by itself (5 s plus 40 ms a character, 8 s minimum with an action, paused under the pointer or focus, always dismissable); it has no danger tone, because an error a person must act on is an inline `Alert` with its recovery as `action` (`announce` makes it `role="alert"` only when it answers something the person just did). `StrataToastRegion` goes once at the app root. `useClientWork` runs browser work with progress, cancel (aborts its `signal`, ends `cancelled`, never `failed`) and a double-start guard; `JobStatus` shows it exactly as it shows a server job, with `onCancel`, `cancelled` and `onDismiss` |
|
|
236
|
-
| Media player | `MediaPlayer`, `useMediaElement`, `SPEECH_RATES`, `useMediaSpans`, `SpanActions`, `PlayerNotice`, `SpanStrip`, `MediaContents` | Play a file or a sequence of chapters without the event glue: `marks` puts one file's own chapters (and `kind: "scene"` scenes, shorter) on the seek bar, each named in a tooltip and pressed to jump; the skip buttons beside Play step by scene (small) and chapter (large), or by 10 s and 1 min where a file has none (`skip`, `skipAction`); `fps` adds frame steps (`,` and `.`); `float` keeps a playing video in a corner box once the player has scrolled off the screen; and `MediaContents` lists them beside the player (the playing one marked, pressing one plays from its start, never scrolling the page); the element, its state, Strata's controls (or the browser's own on a touch device, `controls="auto"`), a load error with Try again, `navigator.mediaSession` metadata, the seek bar spanning the whole sequence. `useMediaElement(ref)` alone follows an element drawn with the browser's controls `spans` and `spanKinds` mark stretches (an intro, a recap, a sponsor read) on the seek bar as named ranges in a status role's tone and act on them as playback reaches them: `auto` skips (or mutes, for `action: "mute"`) with "Skipped intro" and Undo, `ask` offers a Skip button over the picture and on the `s` key, `off` only draws; each is acted on once, `onSpan` reports `skipped`, `muted`, `undone` or `played`, and `SeekBar` takes `spans` too. `mediaRef` hands out the player's state and requests (an object ref holds the latest, no render of its own), `overlay` draws the app's own thing over the picture only, `heading` (title, subtitle, avatar, each a link, with the app's router `state`) is drawn across the top of a video while paused or the pointer moves, and a video keeps a 16:9 (or `aspect`) box before its metadata loads. A video has a Full screen button and the `f` key by default (`fullscreen={false}` removes them); on the picture a click plays or pauses, a double click toggles full screen and the wheel sets the volume while the player has focus. A kind's `colour` names a custom property of the app's theme (`"--seg-sponsor"`) instead of a tone, each range carries `data-kind`, and under the browser's own controls a `SpanStrip` under the picture draws the ranges. `start` begins a first load at a time (an attacher's `startAt`, or a seek once the metadata is in) and says "Picked up at 2:05" with Start over (`resumeWords`); `onProgress` reports the position and the seconds actually played through, each once, a skipped span counted (`useMediaElement` takes it too, with `markWatched`). The HLS attacher starts a `growing` source at its beginning, honours `config.startPosition` and takes `words` for its failures. |
|
|
236
|
+
| Media player | `MediaPlayer`, `useMediaElement`, `SPEECH_RATES`, `useMediaSpans`, `SpanActions`, `PlayerNotice`, `SpanStrip`, `MediaContents` | Play a file or a sequence of chapters without the event glue: `marks` puts one file's own chapters (and `kind: "scene"` scenes, shorter) on the seek bar, each named in a tooltip and pressed to jump; the skip buttons beside Play step by scene (small) and chapter (large), or by 10 s and 1 min where a file has none (`skip`, `skipAction`); `fps` adds frame steps (`,` and `.`); `float` keeps a playing video in a corner box once the player has scrolled off the screen; and `MediaContents` lists them beside the player (the playing one marked, pressing one plays from its start, never scrolling the page); the element, its state, Strata's controls (or the browser's own on a touch device, `controls="auto"`), a load error with Try again, `navigator.mediaSession` metadata, the seek bar spanning the whole sequence. `useMediaElement(ref)` alone follows an element drawn with the browser's controls `spans` and `spanKinds` mark stretches (an intro, a recap, a sponsor read) on the seek bar as named ranges in a status role's tone and act on them as playback reaches them: `auto` skips (or mutes, for `action: "mute"`) with "Skipped intro" and Undo, `ask` offers a Skip button over the picture and on the `s` key, `off` only draws; each is acted on once, `onSpan` reports `skipped`, `muted`, `undone` or `played`, and `SeekBar` takes `spans` too. `mediaRef` hands out the player's state and requests (an object ref holds the latest, no render of its own), `overlay` draws the app's own thing over the picture only, `heading` (title, subtitle, avatar, each a link, with the app's router `state`) is drawn across the top of a video while paused or the pointer moves, and a video keeps a 16:9 (or `aspect`) box before its metadata loads. `gain` plays the sound at a factor through Web Audio (an app's loudness normalisation: 100% is the level the app chose; a change glides there) and `boost` lets the volume past 100% behind a Louder toggle (`VolumeControl boost`), both with a limiter at -1 dBFS; the element is routed only once its audio context runs, so a context the page may not start costs the gain, never the sound. A video has a Full screen button and the `f` key by default (`fullscreen={false}` removes them); on the picture a click plays or pauses, a double click toggles full screen and the wheel sets the volume while the player has focus. A kind's `colour` names a custom property of the app's theme (`"--seg-sponsor"`) instead of a tone, each range carries `data-kind`, and under the browser's own controls a `SpanStrip` under the picture draws the ranges. `start` begins a first load at a time (an attacher's `startAt`, or a seek once the metadata is in) and says "Picked up at 2:05" with Start over (`resumeWords`); `onProgress` reports the position and the seconds actually played through, each once, a skipped span counted (`useMediaElement` takes it too, with `markWatched`). The HLS attacher starts a `growing` source at its beginning, honours `config.startPosition` and takes `words` for its failures. |
|
|
237
237
|
| Edit lists | `EditListPlayer`, `useEditList`; `editTimes`, `locateInEdit`, `editTimeOf`, `continues`, `nextBreak` | An edit (clips that are stretches `[start, end)` of files) played as one timeline before it is rendered: two stacked `<video>` elements, the one behind already loaded and sought to the next clip that does not carry straight on, so a cut shows no gap; clips of one file that follow on play through; the cut is timed from the browser's frame callbacks (a refresh early by the frame loop where there are none); a seek bar marked at every clip, Previous and Next clip (P and N), frame steps with `fps` (`,` and `.`), a new edit (another revision) stays in the clip being watched, and the empty state is a required prop |
|
|
238
238
|
| Media playback | `useTimeline`, `TimelinePlayer`, `Transport`, `SeekBar`, `TimeReadout`, `VolumeControl`, `RateChoice`, `MediaStage`, `StageGuides`, `transportShortcuts`, `format.timecode` | The controls around anything that plays, wired to a player the app owns (HTML media, Web Audio, a canvas, a data replay). Every control is a named icon button in one toolbar; the play button's name is "Play" or "Pause". `SeekBar` has the formatted time as its accessible value, arrows step 5 s and Page keys 30 s by default, and optional marks. `VolumeControl` shows its percent, and muting remembers the level. `transportShortcuts` is the one list for `useHotkeys` and `KeysLegend` (Space and K, J and L, the arrows by a frame, Home and End). `format.timecode` prints m:ss, m:ss.mmm or m:ss:ff. `MediaStage` fits a picture of any aspect ratio into the pane with a letterbox on the sunken surface role, and takes overlays such as `StageGuides` `useTimeline` is the same state for a clock the app owns (a recorded run, a replay, an animation): rAF at `rate`, loops or stops, play at the end restarts, a seek pauses, `step` by `frame`, `startAt`, joins a `MediaGroup` and the key-owner rule, so `Transport`, `SeekBar` and `transportShortcuts` plug in; `TimelinePlayer` puts a stage (a `SceneViewport` given `time`) over the same control bar, with the stage keeping the arrow keys. |
|
|
239
239
|
| Listening and reading | `Waveform`, `TranscriptView`, `PlayWindowButton`, `MediaGroup`, `FilmStrip`; `resamplePeaks`, `peaksFromAudio`, `peakGain`, `phraseAt`, `wordAt`, `pickEvenly`, `frameAt` | Timed media: a waveform from peaks or a decoded file (one slider, marks by line style, named spans, zoom, a keyboard-made range, a spectrogram underlay, `normalise` to draw quiet sound to fill the height and say by how much); `FilmStrip` is a row of frames from a stretch of video that fits its width (picked evenly), each with its time, pressing one seeks (`onSeek`, one tab stop with arrow keys), and the frame at `time` inside `span` is ringed; timed text that marks the heard word and plays from any word (modes, speakers, follow and Jump to now, virtualised), with doubtful words (dotted, named, counted, "Only doubtful"), a mark per phrase set from a row menu (`states`, `onPhraseState`), correction in place (Enter or F2, `onEdit`) and a hover and focus card (`renderCard`); `MediaPlayer window` plays one stretch of a file, `MediaGroup` lets one player play at a time, `PlayWindowButton` is a row's play control on a shared element; a review transcript needs no player (`time` and `onSeek` are optional), takes `marking` (words become `MarkableText` marks with ids `wordId(phraseId, index)`, selected across rows that are not mounted) and shows a corrected word (`word.correction`) dotted with the original on hover and `onCorrectionPress` to open it |
|
package/UPGRADING.md
CHANGED
|
@@ -16,6 +16,10 @@ Every PR that changes what an app sees adds a line here (see `CLAUDE.md`, "Chang
|
|
|
16
16
|
- `CompareMode` has two more members, `"stack"` and `"match"`: a `Record<CompareMode, …>` in an app needs entries for them (or use `Partial`). The default `modes` is unchanged; pass them in `modes` to offer them.
|
|
17
17
|
- `Compare` in swipe now shows a "Swipe direction" toggle, and in fade a "Blend" toggle, under the toolbar: a test that counted radio groups or radios there sees them, and visual baselines of a `Compare` in swipe or fade move.
|
|
18
18
|
|
|
19
|
+
## 2026-11-28 (player gain and Louder)
|
|
20
|
+
|
|
21
|
+
- `MediaElementState` has a new member, `maxVolume` (100, or `boost` where Web Audio can play past it): a `MediaElementState` you build by hand in a test or story must supply it. Nothing else changes for a player given neither `gain` nor `boost`: no audio context is made.
|
|
22
|
+
|
|
19
23
|
## 2026-11-27 (no beckon under reduced motion)
|
|
20
24
|
|
|
21
25
|
- `ChoiceGrid`/`PlaceBoard` `beckon`: under `prefers-reduced-motion: reduce` no tile gets `data-beckon` or its border. A test that waits for `[data-beckon]` with `matchMedia` stubbed to reduce must not.
|
package/dist/hls.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as SourceAttacher } from "./media-player-
|
|
1
|
+
import { f as SourceAttacher } from "./media-player-Buvu2l7R.js";
|
|
2
2
|
import Hls, { HlsConfig } from "hls.js";
|
|
3
3
|
/** The parts of hls.js this entry uses, so the engine can be handed in (a test's, or an app's own build). */
|
|
4
4
|
export type HlsEngine = typeof Hls;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { A as AsyncActionOptions, B as RowAction, C as useColorScheme, D as DensityName, E as Density, F as useAsyncAction, H as buttonVariants, I as Button, L as ButtonProps, M as AsyncLabels, N as FieldErrors, O as DensityProps, P as Phase, R as IconButton, S as palettes, T as useSystemColorScheme, U as ControlSize, V as RowActionProps, W as IconComponent, _ as PaletteOption, a as browserMicrophone, b as colorSchemeScript, c as COLOR_SCHEME_STORAGE_KEY, d as ColorSchemeLabels, f as ColorSchemePreference, g as PaletteChoice, h as PALETTE_STORAGE_KEY, i as MicrophoneStream, j as AsyncButton, k as AsyncAction, l as ColorScheme, m as DEFAULT_PALETTE, n as MicrophoneContext, o as explainMicrophoneError, p as ColorSchemeState, r as MicrophoneError, s as useMicrophone, t as Microphone, u as ColorSchemeChoice, v as PaletteState, w as usePalette, x as paletteScript, y as ThemeProvider, z as IconButtonProps } from "./microphone-DDOnQHxf.js";
|
|
2
2
|
import { n as geo, t as LatLng } from "./geo-DfKa9JtK.js";
|
|
3
|
-
import { $ as LineChartGroupProps, A as RateChoice, B as VolumeControlProps, C as SpanBehaviour, D as useMediaSpans, E as SpanWords, F as StageGuides, G as isTypingTarget, H as HotkeysOptions, I as TimeReadout, J as ChartMark, K as keyName, L as Transport, M as SeekBarProps, N as SeekBarSpan, O as MediaStage, P as SpanStrip, Q as LineChartGroup, R as TransportProps, S as SpanActionsNotice, T as SpanOutcome, U as KeysLegend, V as transportShortcuts, W as Shortcut, X as GroupedChart, Y as ChartSpan, Z as LineChart, _ as MediaProgress, _t as skipAction, a as MediaPlayerProps, at as valueAt, b as PlayerNotice, bt as usePlayerWarnings, c as MediaSource, ct as CursorScope, d as SPEECH_RATES, dt as useSharedCursor, et as LineChartProps, f as SourceAttacher, ft as MediaMark, g as useMediaElement, gt as marksFor, h as useAttachedSource, ht as SkipSteps, i as MediaPlayer, it as logScale, j as SeekBar, k as Precision, l as MediaWindow, lt as CursorScopeProps, m as StreamContext, mt as SkipLevel, n as MediaElementState, nt as SpanTone, o as MediaProblem, ot as CursorMapping, p as StreamAttachment, pt as SkipAction, q as useHotkeys, r as MediaHeading, rt as YScale, s as MediaSession, st as CursorOwner, t as MediaElementOptions, tt as Point, u as ResumeWords, ut as SharedCursor, v as MediaSpanData, vt as PlayerWarning, w as SpanKind, x as SpanActions, y as MediaSpansState, yt as PlayerWarningEvent, z as VolumeControl } from "./media-player-
|
|
3
|
+
import { $ as LineChartGroupProps, A as RateChoice, B as VolumeControlProps, C as SpanBehaviour, D as useMediaSpans, E as SpanWords, F as StageGuides, G as isTypingTarget, H as HotkeysOptions, I as TimeReadout, J as ChartMark, K as keyName, L as Transport, M as SeekBarProps, N as SeekBarSpan, O as MediaStage, P as SpanStrip, Q as LineChartGroup, R as TransportProps, S as SpanActionsNotice, T as SpanOutcome, U as KeysLegend, V as transportShortcuts, W as Shortcut, X as GroupedChart, Y as ChartSpan, Z as LineChart, _ as MediaProgress, _t as skipAction, a as MediaPlayerProps, at as valueAt, b as PlayerNotice, bt as usePlayerWarnings, c as MediaSource, ct as CursorScope, d as SPEECH_RATES, dt as useSharedCursor, et as LineChartProps, f as SourceAttacher, ft as MediaMark, g as useMediaElement, gt as marksFor, h as useAttachedSource, ht as SkipSteps, i as MediaPlayer, it as logScale, j as SeekBar, k as Precision, l as MediaWindow, lt as CursorScopeProps, m as StreamContext, mt as SkipLevel, n as MediaElementState, nt as SpanTone, o as MediaProblem, ot as CursorMapping, p as StreamAttachment, pt as SkipAction, q as useHotkeys, r as MediaHeading, rt as YScale, s as MediaSession, st as CursorOwner, t as MediaElementOptions, tt as Point, u as ResumeWords, ut as SharedCursor, v as MediaSpanData, vt as PlayerWarning, w as SpanKind, x as SpanActions, y as MediaSpansState, yt as PlayerWarningEvent, z as VolumeControl } from "./media-player-Buvu2l7R.js";
|
|
4
4
|
import { ClassValue } from "clsx";
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
import { DropItem } from "react-aria-components";
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { a as fieldErrorsOf, i as errorPayload, n as describeActionError, o as r
|
|
|
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";
|
|
@@ -4001,29 +4001,50 @@ function Transport({ playing, onPlayPause, onStop, onToStart, onToEnd, onStepBac
|
|
|
4001
4001
|
]
|
|
4002
4002
|
});
|
|
4003
4003
|
}
|
|
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 }) {
|
|
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. With `boost`, a Louder toggle lets it past 100. */
|
|
4005
|
+
function VolumeControl({ volume, onVolumeChange, max = 100, boost, disabled, className }) {
|
|
4006
4006
|
const last = React.useRef(volume > 0 ? volume : 100);
|
|
4007
4007
|
if (volume > 0) last.current = volume;
|
|
4008
4008
|
const muted = volume === 0;
|
|
4009
|
+
const [louderAsked, setLouderAsked] = React.useState(false);
|
|
4010
|
+
const canBoost = boost !== void 0 && boost > 100;
|
|
4011
|
+
const louder = canBoost && (louderAsked || volume > 100 || last.current > 100);
|
|
4012
|
+
const top = canBoost ? louder ? boost : 100 : max;
|
|
4009
4013
|
return /* @__PURE__ */ jsxs("div", {
|
|
4010
4014
|
className: cn("flex min-w-0 items-center gap-2", className),
|
|
4011
|
-
children: [
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4015
|
+
children: [
|
|
4016
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
4017
|
+
icon: muted ? VolumeX : Volume2,
|
|
4018
|
+
label: muted ? "Unmute" : "Mute",
|
|
4019
|
+
hint: "M",
|
|
4020
|
+
disabled,
|
|
4021
|
+
onClick: () => onVolumeChange(muted ? last.current : 0)
|
|
4022
|
+
}),
|
|
4023
|
+
/* @__PURE__ */ jsx(Slider, {
|
|
4024
|
+
"aria-label": "Volume",
|
|
4025
|
+
value: Math.min(volume, top),
|
|
4026
|
+
onChange: onVolumeChange,
|
|
4027
|
+
min: 0,
|
|
4028
|
+
max: top,
|
|
4029
|
+
unit: "%",
|
|
4030
|
+
disabled,
|
|
4031
|
+
className: "w-40 min-w-24 shrink"
|
|
4032
|
+
}),
|
|
4033
|
+
canBoost && /* @__PURE__ */ jsx(Toggle, {
|
|
4034
|
+
label: `Louder, up to ${boost}%`,
|
|
4035
|
+
icon: ChevronsUp,
|
|
4036
|
+
iconOnly: true,
|
|
4037
|
+
pressed: louder,
|
|
4038
|
+
disabled,
|
|
4039
|
+
onChange: (on) => {
|
|
4040
|
+
setLouderAsked(on);
|
|
4041
|
+
if (!on && (volume > 100 || last.current > 100)) {
|
|
4042
|
+
last.current = 100;
|
|
4043
|
+
onVolumeChange(muted ? 0 : 100);
|
|
4044
|
+
}
|
|
4045
|
+
}
|
|
4046
|
+
})
|
|
4047
|
+
]
|
|
4027
4048
|
});
|
|
4028
4049
|
}
|
|
4029
4050
|
/** A choice of playback speed ("0.5×", "1×", "1.5×"), named "Playback speed": React Aria's Select. */
|
|
@@ -4571,6 +4592,121 @@ function createWatchedRanges() {
|
|
|
4571
4592
|
};
|
|
4572
4593
|
}
|
|
4573
4594
|
|
|
4595
|
+
// src/components/media-sound.ts
|
|
4596
|
+
/** The limiter's threshold, dB under full scale. */
|
|
4597
|
+
const LIMIT_DB = -1;
|
|
4598
|
+
const RATIO = 20;
|
|
4599
|
+
/** Seconds: how fast an app's level glides to a new value (a time constant; about three of them to arrive). */
|
|
4600
|
+
const GLIDE = .5;
|
|
4601
|
+
const FOLLOW = .02;
|
|
4602
|
+
/** The compressor's automatic make-up gain at the limiter's settings, as the Web Audio spec defines it. */
|
|
4603
|
+
function makeupGain(threshold = -1, ratio = RATIO) {
|
|
4604
|
+
const atFullScale = threshold + (0 - threshold) / ratio;
|
|
4605
|
+
return Math.pow(1 / Math.pow(10, atFullScale / 20), .6);
|
|
4606
|
+
}
|
|
4607
|
+
const graphs = /* @__PURE__ */ new WeakMap();
|
|
4608
|
+
/**
|
|
4609
|
+
* Whether this browser can play a level past the element's own (it has Web Audio), and, given an element, whether its
|
|
4610
|
+
* source may go through it: same-origin (or a `blob:` or `data:` URL, as a stream engine's Media Source is), or loaded
|
|
4611
|
+
* with `crossOrigin` set (then the server must answer with CORS). Any other file comes out of a graph as silence, so it
|
|
4612
|
+
* is never routed: it plays at its own level, with no gain and no boost.
|
|
4613
|
+
*/
|
|
4614
|
+
function canShapeSound(el) {
|
|
4615
|
+
if (typeof window === "undefined" || typeof window.AudioContext !== "function") return false;
|
|
4616
|
+
if (!el) return true;
|
|
4617
|
+
const src = el.currentSrc || el.getAttribute("src") || "";
|
|
4618
|
+
if (!src || el.crossOrigin !== null) return true;
|
|
4619
|
+
try {
|
|
4620
|
+
const url = new URL(src, window.location.href);
|
|
4621
|
+
return url.protocol === "blob:" || url.protocol === "data:" || url.origin === window.location.origin;
|
|
4622
|
+
} catch {
|
|
4623
|
+
return false;
|
|
4624
|
+
}
|
|
4625
|
+
}
|
|
4626
|
+
function graphFor(el) {
|
|
4627
|
+
const had = graphs.get(el);
|
|
4628
|
+
if (had) return had;
|
|
4629
|
+
if (!canShapeSound(el)) return null;
|
|
4630
|
+
const context = new AudioContext();
|
|
4631
|
+
const level = context.createGain();
|
|
4632
|
+
const boost = context.createGain();
|
|
4633
|
+
const limiter = context.createDynamicsCompressor();
|
|
4634
|
+
limiter.threshold.value = -1;
|
|
4635
|
+
limiter.knee.value = 0;
|
|
4636
|
+
limiter.ratio.value = RATIO;
|
|
4637
|
+
limiter.attack.value = .001;
|
|
4638
|
+
limiter.release.value = .1;
|
|
4639
|
+
const unlift = context.createGain();
|
|
4640
|
+
unlift.gain.value = 1 / makeupGain();
|
|
4641
|
+
level.connect(boost).connect(limiter).connect(unlift).connect(context.destination);
|
|
4642
|
+
const graph = {
|
|
4643
|
+
context,
|
|
4644
|
+
level,
|
|
4645
|
+
boost,
|
|
4646
|
+
routed: false,
|
|
4647
|
+
waiting: false,
|
|
4648
|
+
levelTarget: 1,
|
|
4649
|
+
boostTarget: 1
|
|
4650
|
+
};
|
|
4651
|
+
graphs.set(el, graph);
|
|
4652
|
+
return graph;
|
|
4653
|
+
}
|
|
4654
|
+
function route(el, graph) {
|
|
4655
|
+
if (graph.context.state !== "running") {
|
|
4656
|
+
graph.context.resume().catch(() => {});
|
|
4657
|
+
return;
|
|
4658
|
+
}
|
|
4659
|
+
if (graph.routed) return;
|
|
4660
|
+
if (!canShapeSound(el)) return;
|
|
4661
|
+
try {
|
|
4662
|
+
graph.context.createMediaElementSource(el).connect(graph.level);
|
|
4663
|
+
graph.routed = true;
|
|
4664
|
+
} catch {
|
|
4665
|
+
graph.routed = true;
|
|
4666
|
+
}
|
|
4667
|
+
}
|
|
4668
|
+
/**
|
|
4669
|
+
* Applies `gain` (the app's level, a factor) and `boost` (the person's, a factor of 1 or more) to an element's sound.
|
|
4670
|
+
* Makes nothing while both are 1 and no graph exists yet. Call again whenever either changes, and on `play` (the
|
|
4671
|
+
* gesture that lets the context start).
|
|
4672
|
+
*/
|
|
4673
|
+
function shapeSound(el, gain, boost, glide = true) {
|
|
4674
|
+
if (!graphs.has(el) && gain === 1 && boost === 1) return;
|
|
4675
|
+
const graph = graphFor(el);
|
|
4676
|
+
if (!graph) return;
|
|
4677
|
+
const now = graph.context.currentTime;
|
|
4678
|
+
const wanted = Math.max(0, gain);
|
|
4679
|
+
if (wanted !== graph.levelTarget) {
|
|
4680
|
+
graph.levelTarget = wanted;
|
|
4681
|
+
graph.level.gain.cancelScheduledValues(now);
|
|
4682
|
+
graph.level.gain.setTargetAtTime(wanted, now, graph.routed && glide ? GLIDE : FOLLOW);
|
|
4683
|
+
}
|
|
4684
|
+
if (boost !== graph.boostTarget) {
|
|
4685
|
+
graph.boostTarget = boost;
|
|
4686
|
+
graph.boost.gain.cancelScheduledValues(now);
|
|
4687
|
+
graph.boost.gain.setTargetAtTime(boost, now, FOLLOW);
|
|
4688
|
+
}
|
|
4689
|
+
if (!graph.routed && !graph.waiting && graph.context.state !== "running") {
|
|
4690
|
+
graph.waiting = true;
|
|
4691
|
+
graph.context.addEventListener("statechange", function started() {
|
|
4692
|
+
if (graph.context.state !== "running") return;
|
|
4693
|
+
graph.context.removeEventListener("statechange", started);
|
|
4694
|
+
graph.waiting = false;
|
|
4695
|
+
route(el, graph);
|
|
4696
|
+
});
|
|
4697
|
+
}
|
|
4698
|
+
route(el, graph);
|
|
4699
|
+
}
|
|
4700
|
+
/**
|
|
4701
|
+
* Lets go of an element's audio while its player is gone: suspends its context, which frees the audio thread. Not
|
|
4702
|
+
* closed, since an element can be given to a context only once: the same element mounted again (React's double mount in
|
|
4703
|
+
* development) resumes it on the next `shapeSound`.
|
|
4704
|
+
*/
|
|
4705
|
+
function releaseSound(el) {
|
|
4706
|
+
const graph = graphs.get(el);
|
|
4707
|
+
if (graph && graph.context.state === "running") graph.context.suspend().catch(() => {});
|
|
4708
|
+
}
|
|
4709
|
+
|
|
4574
4710
|
// src/components/link.tsx
|
|
4575
4711
|
function useTarget(target, newTab, state) {
|
|
4576
4712
|
const navigate = useNavigate();
|
|
@@ -4631,6 +4767,10 @@ function TextLink(all) {
|
|
|
4631
4767
|
}
|
|
4632
4768
|
|
|
4633
4769
|
// src/components/media-player.tsx
|
|
4770
|
+
/** The most the volume goes to: a boost where Web Audio can play it, else 100. */
|
|
4771
|
+
function maxVolumeOf(boost, el) {
|
|
4772
|
+
return boost && boost > 100 && canShapeSound(el) ? boost : 100;
|
|
4773
|
+
}
|
|
4634
4774
|
/** How far one notch of the wheel over a focused video moves the volume, in percent. */
|
|
4635
4775
|
const WHEEL_VOLUME_STEP = 5;
|
|
4636
4776
|
const idle = {
|
|
@@ -4642,6 +4782,7 @@ const idle = {
|
|
|
4642
4782
|
buffered: 0,
|
|
4643
4783
|
volume: 100,
|
|
4644
4784
|
muted: false,
|
|
4785
|
+
maxVolume: 100,
|
|
4645
4786
|
rate: 1,
|
|
4646
4787
|
ended: false,
|
|
4647
4788
|
loading: false,
|
|
@@ -4708,6 +4849,7 @@ function useMediaElement(ref, options = {}) {
|
|
|
4708
4849
|
const windowEnded = React.useRef(false);
|
|
4709
4850
|
const streamProblem = React.useRef(null);
|
|
4710
4851
|
const edgePause = React.useRef(false);
|
|
4852
|
+
const extra = React.useRef(1);
|
|
4711
4853
|
const contextGroup = useMediaGroupName();
|
|
4712
4854
|
const group = options.group ?? contextGroup;
|
|
4713
4855
|
const read = React.useCallback(() => {
|
|
@@ -4734,8 +4876,9 @@ function useMediaElement(ref, options = {}) {
|
|
|
4734
4876
|
time: Number.isFinite(el.currentTime) ? el.currentTime : 0,
|
|
4735
4877
|
duration: known,
|
|
4736
4878
|
buffered: bufferedAhead(el),
|
|
4737
|
-
volume: el.muted ? 0 : Math.round(el.volume * 100),
|
|
4879
|
+
volume: el.muted ? 0 : Math.round(el.volume * extra.current * 100),
|
|
4738
4880
|
muted: el.muted,
|
|
4881
|
+
maxVolume: maxVolumeOf(opts.current.boost, el),
|
|
4739
4882
|
rate: el.playbackRate,
|
|
4740
4883
|
ended: endedNow,
|
|
4741
4884
|
loading: !error && el.networkState === 2 && el.readyState < 3 && !el.paused,
|
|
@@ -4761,9 +4904,21 @@ function useMediaElement(ref, options = {}) {
|
|
|
4761
4904
|
el.currentTime = w.end;
|
|
4762
4905
|
opts.current.onWindowEnd?.();
|
|
4763
4906
|
}, []);
|
|
4907
|
+
const gain = options.gain ?? 1;
|
|
4908
|
+
React.useEffect(() => {
|
|
4909
|
+
const el = ref.current;
|
|
4910
|
+
if (el) shapeSound(el, gain, extra.current);
|
|
4911
|
+
}, [ref, gain]);
|
|
4912
|
+
React.useEffect(() => {
|
|
4913
|
+
const el = ref.current;
|
|
4914
|
+
return () => {
|
|
4915
|
+
if (el) releaseSound(el);
|
|
4916
|
+
};
|
|
4917
|
+
}, [ref]);
|
|
4764
4918
|
useElementListeners(ref, (el) => {
|
|
4765
4919
|
el.preservesPitch = true;
|
|
4766
4920
|
const on = (e) => {
|
|
4921
|
+
if (e.type === "play") shapeSound(el, opts.current.gain ?? 1, extra.current);
|
|
4767
4922
|
if (e.type === "play" || e.type === "playing") blocked.current = null;
|
|
4768
4923
|
if (e.type === "play") {
|
|
4769
4924
|
windowEnded.current = false;
|
|
@@ -4983,9 +5138,12 @@ function useMediaElement(ref, options = {}) {
|
|
|
4983
5138
|
setVolume: (volume) => {
|
|
4984
5139
|
const el = ref.current;
|
|
4985
5140
|
if (!el) return;
|
|
4986
|
-
const v = Math.min(Math.max(volume, 0),
|
|
5141
|
+
const v = Math.min(Math.max(volume, 0), maxVolumeOf(opts.current.boost, el));
|
|
4987
5142
|
el.muted = v === 0;
|
|
4988
|
-
if (v > 0) el.volume = v / 100;
|
|
5143
|
+
if (v > 0) el.volume = Math.min(v, 100) / 100;
|
|
5144
|
+
extra.current = v > 100 ? v / 100 : 1;
|
|
5145
|
+
shapeSound(el, opts.current.gain ?? 1, extra.current);
|
|
5146
|
+
read();
|
|
4989
5147
|
},
|
|
4990
5148
|
setRate: (rate) => {
|
|
4991
5149
|
const el = ref.current;
|
|
@@ -5096,7 +5254,7 @@ function useCoarsePointer() {
|
|
|
5096
5254
|
* a touch device), with the failure to load shown and retried. For an editor or a replay, use the
|
|
5097
5255
|
* parts and `useMediaElement` directly.
|
|
5098
5256
|
*/
|
|
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 }) {
|
|
5257
|
+
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
5258
|
const list = React.useMemo(() => sources ?? (src ? [{
|
|
5101
5259
|
src,
|
|
5102
5260
|
title: label
|
|
@@ -5125,7 +5283,9 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
|
|
|
5125
5283
|
onRetry: attach ? (t) => stream.current.reload(t) : void 0,
|
|
5126
5284
|
onProgress: onProgress ? progress : void 0,
|
|
5127
5285
|
progressEvery,
|
|
5128
|
-
progressKey: current?.src
|
|
5286
|
+
progressKey: current?.src,
|
|
5287
|
+
gain,
|
|
5288
|
+
boost
|
|
5129
5289
|
});
|
|
5130
5290
|
React.useEffect(() => void (sourceIndex.current = index), [index]);
|
|
5131
5291
|
stream.current = useAttachedSource(ref, current?.src, attach, media.reportProblem, growing !== void 0, start);
|
|
@@ -5378,7 +5538,8 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
|
|
|
5378
5538
|
if (!el.contains(document.activeElement) || e.ctrlKey || !e.deltaY) return;
|
|
5379
5539
|
e.preventDefault();
|
|
5380
5540
|
const m = latest.current;
|
|
5381
|
-
|
|
5541
|
+
const top = m.volume > 100 ? m.maxVolume : 100;
|
|
5542
|
+
m.setVolume(Math.min(top, Math.max(0, m.volume + (e.deltaY < 0 ? WHEEL_VOLUME_STEP : -5))));
|
|
5382
5543
|
};
|
|
5383
5544
|
el.addEventListener("wheel", onWheel, { passive: false });
|
|
5384
5545
|
return () => el.removeEventListener("wheel", onWheel);
|
|
@@ -5501,6 +5662,7 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
|
|
|
5501
5662
|
controls: native,
|
|
5502
5663
|
autoPlay,
|
|
5503
5664
|
preload: "metadata",
|
|
5665
|
+
crossOrigin,
|
|
5504
5666
|
"aria-label": `${label}, ${kind}`
|
|
5505
5667
|
};
|
|
5506
5668
|
const hasSpans = (spans?.length ?? 0) > 0;
|
|
@@ -5777,7 +5939,8 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
|
|
|
5777
5939
|
}),
|
|
5778
5940
|
/* @__PURE__ */ jsx(VolumeControl, {
|
|
5779
5941
|
volume: media.volume,
|
|
5780
|
-
onVolumeChange: media.setVolume
|
|
5942
|
+
onVolumeChange: media.setVolume,
|
|
5943
|
+
boost: media.maxVolume > 100 ? media.maxVolume : void 0
|
|
5781
5944
|
}),
|
|
5782
5945
|
canFull && /* @__PURE__ */ jsx(IconButton, {
|
|
5783
5946
|
icon: full ? Minimize : Maximize,
|