strata-react 1.0.37 → 1.0.38
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 +3 -3
- package/UPGRADING.md +3 -0
- package/dist/components/infinite-list.d.ts +17 -2
- package/dist/components/media-player.d.ts +19 -2
- package/dist/components/media-spans.d.ts +78 -0
- package/dist/components/media.d.ts +14 -1
- package/dist/components/thumbnail.d.ts +7 -3
- package/dist/hls/index.d.ts +12 -1
- package/dist/hls.js +8 -4
- package/dist/hls.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +363 -42
- package/dist/index.js.map +1 -1
- package/dist/{query-BJcxJLhh.js → query-CJ1pSPiC.js} +4 -4
- package/dist/query-CJ1pSPiC.js.map +1 -0
- package/dist/strata.css +15 -8
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/dist/query-BJcxJLhh.js.map +0 -1
package/README.md
CHANGED
|
@@ -128,7 +128,7 @@ strata-react is ESM-only (`exports` has only `import`), as is its peer `react-ro
|
|
|
128
128
|
| Actions | `Button`, `IconButton`, `RowAction`, `AsyncButton`, `useAsyncAction` | Default is `outline`; one filled button per view; `IconButton` requires `label`; `RowAction` is named for its row ("Withdraw Tom Ellery"); `AsyncButton` keeps one width through idle, pending, done and error, and announces `error` with its retry label; buttons carry `data-variant` and `AsyncButton` `data-phase` for tests; `useAsyncAction` returns `{ phase, run, error, thrown, fieldErrors, clearFieldError }` with a stable `run`, describes an `HttpError` in a sentence with the server's own reason for a 4xx (`describeActionError`, or the product's own `describeError`), and `validate` plus a server's 422 put messages on `fieldErrors` for each `Field` |
|
|
129
129
|
| Form | `Field`, `Input`, `Textarea`, `NativeSelect`, `ChoiceGroup`, `Checkbox` | `Field` wires label, hint, error, `aria-describedby`, `aria-invalid`, and `action` puts a one-field form's button on the control's row with the hint and error under both; `Checkbox` requires `label` and is one target with it, and has a mixed state |
|
|
130
130
|
| Status and figures | `Status`, `Metric`, `MetricStrip`, `Meter`, `crossedThreshold`, `CompositionBar` | A status is always a word; figures have no icons or sparklines; `Meter` is a `meter` named for what it measures, with its reading in words ("72% used"), threshold notches, and a `Status` word once a threshold is crossed (each threshold must name its state); `CompositionBar` is a stacked bar over a table naming every part, its amount and share, and names the remainder (`total` needs `restLabel`); a part that is there reads "<1%" and keeps a sliver, never "0%"; `JobStatus` is a long-running server job: a required word per state beside the app's sentence, a progress bar when the total is known, each failure named with its reason, announced only when the item changes or the job ends |
|
|
131
|
-
| Data | `DataView`, `Load<T>`, `Stale`, `StaleNotice`, `LoadError`, `EmptyState`, `Skeleton`, `Thumbnail`, `ThumbnailSkeleton`, `DataTable`, `TableSkeleton`, `VirtualList`, `InfiniteList`, `LoadMore`, `useInView`, `LineChart` | `DataView` requires skeleton and empty, keeps data on screen under a `StaleNotice` (why, how old, Try again) when a refresh fails, and takes an `error` renderer for an app's own look of a failed read (default `LoadError`, always inside an alert); `Thumbnail` is a remote image in a box of fixed `aspect`, with a skeleton while it loads, the required `missing` words (or a `fallback` drawing, such as an avatar's initial) when it fails or `src` is null, required `alt`, `children` overlaid in its corners, and a request only once it nears the screen (`eager` for the first few); tables, lists and tile grids virtualise from 100 rows, on React Aria's Virtualizer; a `DataTable` is a React Aria table (a `grid`) over TanStack Table's data model; a `DataTable` column with `value` sorts by type with missing values last both ways and draws a placeholder (`missing`, default an en dash); `InfiniteList` loads the next page on approach, with a skeleton for it, a Try again row when it fails and a Show more button for the keyboard, and `scroll="page"` draws a grid that scrolls with the page; `LoadMore` is that next-page row for any list or grid; charts label values directly; `LineChart` can also follow an app's position (`current`), read a value at the pointer or by arrow keys (`readout`, one slider whose value text is the reading), report a picked x (`onPick`) and fill one flat area (`area`); `xLabel` names the x column of its table |
|
|
131
|
+
| Data | `DataView`, `Load<T>`, `Stale`, `StaleNotice`, `LoadError`, `EmptyState`, `Skeleton`, `Thumbnail`, `ThumbnailSkeleton`, `DataTable`, `TableSkeleton`, `VirtualList`, `InfiniteList`, `LoadMore`, `useInView`, `LineChart` | `DataView` requires skeleton and empty, keeps data on screen under a `StaleNotice` (why, how old, Try again) when a refresh fails, and takes an `error` renderer for an app's own look of a failed read (default `LoadError`, always inside an alert); `Thumbnail` is a remote image in a box of fixed `aspect`, with a skeleton while it loads, the required `missing` words (or a `fallback` drawing, such as an avatar's initial) when it fails or `src` is null, required `alt`, `children` overlaid in its corners, and a request only once it nears the screen (`eager` for the first few); tables, lists and tile grids virtualise from 100 rows, on React Aria's Virtualizer; a `DataTable` is a React Aria table (a `grid`) over TanStack Table's data model; a `DataTable` column with `value` sorts by type with missing values last both ways and draws a placeholder (`missing`, default an en dash); `InfiniteList` loads the next page on approach, with a skeleton for it, a Try again row when it fails and a Show more button for the keyboard, and `scroll="page"` draws a grid that scrolls with the page; `LoadMore` is that next-page row for any list or grid; charts label values directly; `LineChart` can also follow an app's position (`current`), read a value at the pointer or by arrow keys (`readout`, one slider whose value text is the reading), report a picked x (`onPick`) and fill one flat area (`area`); `xLabel` names the x column of its table `Thumbnail`'s `src` may be a list tried in order, `onLoad` can reject a picture that loaded (a host's grey placeholder) and `onMissing` is told once when none worked; with `alt=""` and a `fallback` its missing state is presentational. `LoadMore` and `InfiniteList` can draw the Show more and loading rows the app's way (`more`, `loading`, and `ruled={false}` for no hairlines). |
|
|
132
132
|
| Compare | `Compare`, `PairVote`, `PairJudge`, `CompareAudio`, `CompareText`, `CompareGrid`, `CompareVideoGrid`, `ViewportFrame`, `useViewport`, `FullscreenFrame`, `useDifference`, `differences` | Two pictures judged together: side by side, swipe (a divider that moves from the keyboard), fade, blink (`x` flips) and difference (a live difference blend with amplify, or pixelmatch's changed pixels with a tolerance and the share that differ; pixels are read only when that view is open, at most 2048 px on the long side, and a picture the browser will not let the page read says so in words); `CompareGrid` is every candidate at once with the same zoom and full screen, and `actions` for what a tile offers; one zoom and pan for both sides (buttons, `+` `-` `0`, Ctrl-wheel or trackpad pinch, drag, arrow keys, double click, `1:1`), and full screen (the browser's Fullscreen API, a modal where there is none). `blind` is required: a blind comparison names pictures by `label` only and never writes the variant `id`, `note` or `alt`. A picture that fails shows the required `missing` words in its place; the keys come from one `Shortcut[]` shared with `KeysLegend`, and `keys={false}` leaves them to a surrounding screen. `PairVote` wraps `Compare` for a blind pairwise judgment: answer keys `a` `b` `t` `s` in Compare's one legend, a vote bar with no filled button, `pending`, a flag menu, a progress line, preload and Undo, and click to choose (a click on the picture you prefer, not a drag or double click; in swipe the side of the divider, in blink the side showing, none in fade or difference; `onPick` on `Compare` and `CompareVideo`, `pick={false}` turns it off). `CompareAudio` is one transport for two clips with an A/B switch that keeps the playhead (same time, or the same share when the lengths differ), a loop range and loudness matching (the louder clip turned down to the quieter, by RMS); `CompareText` is two texts scrolled together with a word diff and an optional reference; `PairJudge` is the answering around any of them; `CompareVideo` is two videos on one clock (play, pause, seek and speed drive both, the follower kept within a frame, both held while either waits for data) in side by side, swipe, fade and blink, with zoom and pan locked and nearest-neighbour pixels past 1:1, candidates of different sizes drawn in one box, one soundtrack (`audio`), and the same slots as the rest. `autoPlay` starts the pair once both can play (muted; not with reduced motion unless `"always"`) and `loopWhole` loops the whole clip when no range is set (also on `CompareVideoGrid`). Frame by frame (`,` `.`), a loop range the app can hold (`i` `o` `c`), speeds down to 0.1 and named `moments` are in it; `CompareVideoGrid` is every candidate's video at once on that one clock (one transport, one zoom, regions, a loop, stepping), light on the browser (metadata only until the first play, cells out of sight paused and left out of the sync, sound off unless `audio` names a cell, a cell that falls behind marked "Catching up"), with an optional `reference` drawn first, never blind and nearest-neighbour. `regions` (on `Compare`, `CompareVideo` and `CompareGrid`) names boxes in the source's coordinates to look at enlarged: chips, keys `q` `w` `e` `r` `y` `u`, nearest-neighbour drawing, the box outlined while its chip is pointed at, and Shift-drag to make another |
|
|
133
133
|
| Selection | `useSelection`, `BulkBar`, `SelectableGrid`, `DataTable`'s `selection` (`RowSelection<T>`) | Opt-in checkbox column with "Select all shown" that respects `isSelectable`; Shift-click or Shift+Space chooses or clears the run from the last row clicked, in the order shown; `initial` (keys or a test on the row) chooses a row the first time it appears, so it applies to data that loads later; the selection drops rows that are gone; `BulkBar` announces the count politely, and while it is up its one filled action is the view's only one (the screen's primary goes to `outline`); `SelectableGrid` is the same selection as a grid of pictures (`renderImage`), each tile one labelled target, virtualised from 100 tiles |
|
|
134
134
|
| Expansion | `Disclosure`, `useExpanded`, `DataTable`'s `expansion` (`RowExpansion<T>`) | Show more of one row in place. The toggle is a button with `aria-expanded`; the body is mounted only while open, so a request inside it runs on first open (unlike `<details>`, which mounts every closed body); `useExpanded({ param })` shares the open keys across a list or table and keeps them in the URL; a table's detail row spans the data columns and is measured when virtualised |
|
|
@@ -136,7 +136,7 @@ strata-react is ESM-only (`exports` has only `import`), as is its peer `react-ro
|
|
|
136
136
|
| Page and navigation | `AppShell`, `SideNav`, `Breadcrumb`, `Tabs`, `PageHeader`, `LinkCard`, `LinkCardList` | React Router; tab and sort state in the URL; a `LinkCard` is one link named by its title, described by its text and `Status` marks, with the whole card as the target (`to` a route, `href` elsewhere, marked with an arrow) |
|
|
137
137
|
| Keyboard | `useHotkeys`, `KeysLegend`, `Shortcut`, `useActiveItem`, `ActiveList`, `isTypingTarget` | For queues worked from the keyboard; one shortcut list drives the handler and the legend; keys never fire while typing; answering moves focus to the next item |
|
|
138
138
|
| Theme | `ThemeProvider`, `useColorScheme`, `useSystemColorScheme`, `ColorSchemeChoice`, `colorSchemeScript` | System, light or dark; sets `.dark`, persists in localStorage when it can; `ColorSchemeChoice` is a radio list for a settings page, or `compact` icon segments named "Appearance" for an app with no settings page |
|
|
139
|
-
| Density | `Density`, `DensityName`, `ThemeProvider`'s `density`, `ControlSize` (`size="sm"` on `Input`, `NativeSelect`, `NumberField`, `IconButton`) | Control height is two variables, `--control-h` and `--control-h-sm`. `<ThemeProvider density="compact">` or `<Density page value="compact">` sets them app-wide, including dialogs and menus, which portal out of the app's root; `<Density value="compact">` is one region (a toolbar, a dense panel) and does not reach its overlays. A coarse pointer (touch) always gets 44px targets, whatever the density |
|
|
139
|
+
| Density | `Density`, `DensityName`, `ThemeProvider`'s `density`, `ControlSize` (`size="sm"` on `Input`, `NativeSelect`, `NumberField`, `IconButton`) | Control height is two variables, `--control-h` and `--control-h-sm`. `<ThemeProvider density="compact">` or `<Density page value="compact">` sets them app-wide, including dialogs and menus, which portal out of the app's root; `<Density value="compact">` is one region (a toolbar, a dense panel) and does not reach its overlays. A coarse pointer (touch) always gets 44px targets, whatever the density A second look for a region is roles alone: set `--control-h`, `--control-h-sm`, `--control-px`, `--control-px-sm`, `--control-icon` and each type step's `--type-<step>-size`, `-leading` and `-weight` (`caption`, `label`, `body-sm`, `body`, `heading`, `title`, `figure`) on a class; the defaults are today's values. |
|
|
140
140
|
| Workspace | `Workspace`, `Split`, `Pane`, `useWorkspaceState`, `WorkspaceState` | One screen of panes for a tool: splits of panes with a growing stage, a header on every pane (name, actions, fold button), separators that resize by pointer and by keyboard (arrows, Shift, Home, End, Enter to restore) within each pane's `min` and `max`, panes that fold to a rail or header bar with a visible way back (and `state.toggle(id)` from a menu), sizes and folds remembered with `useWorkspaceState("name")`, and stacking below 720px. Each pane is a labelled region |
|
|
141
141
|
| History and save state | `useHistory`, `useHistoryState`, `History`, `useAutoSave`, `SaveStatus`, `SaveState`, `useLeaveGuard` | Undo and redo for a document edited over a session: a step is a name and an `undo`/`redo` pair, `begin(label)` groups a drag into one step, a `key` merges a slider's pushes, a `limit` drops the oldest. `history.commands` are Undo and Redo as `Command`s ("Undo move clip", Mod+Z, Mod+Shift+Z or Mod+Y) for `useCommands` and `Menu`. `useAutoSave` debounces and never overlaps saves; `SaveStatus` is the fixed-width sign ("Saved 10:42", "Saving…", "Unsaved changes", "Not saved" with the reason and "Try again"), quiet except for a failure and its recovery. For one removal that commits after a few seconds, use `useUndoable` |
|
|
142
142
|
| Toolbar and toggles | `Toolbar`, `ToolbarSeparator`, `Toggle`, `ToggleGroup`, `Switch` | A toolbar is one tab stop with arrows, Home and End inside; needs a `label`. `Toggle` (`aria-pressed`) and `ToggleGroup` (one of 2 to 7, always one chosen) show chosen as an ink border on a tint, never the filled primary, so they do not break the one-filled-button rule; an icon-only toggle still needs its `label` (shown as a tooltip). `Switch` is only for a setting that applies at once, label and control one target |
|
|
@@ -144,7 +144,7 @@ strata-react is ESM-only (`exports` has only `import`), as is its peer `react-ro
|
|
|
144
144
|
| 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 |
|
|
145
145
|
| Value controls | `NumberField`, `Slider`, `ColorField` | 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 |
|
|
146
146
|
| 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` |
|
|
147
|
-
| Media player | `MediaPlayer`, `useMediaElement`, `SPEECH_RATES` | Play a file or a sequence of chapters without the event glue: 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 |
|
|
147
|
+
| Media player | `MediaPlayer`, `useMediaElement`, `SPEECH_RATES`, `useMediaSpans`, `SpanActions` | Play a file or a sequence of chapters without the event glue: 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, and a video keeps a 16:9 (or `aspect`) box before its metadata loads. The HLS attacher starts a `growing` source at its beginning, honours `config.startPosition` and takes `words` for its failures. |
|
|
148
148
|
| Media playback | `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` |
|
|
149
149
|
| Listening and reading | `Waveform`, `TranscriptView`, `PlayWindowButton`, `MediaGroup`; `resamplePeaks`, `peaksFromAudio`, `phraseAt`, `wordAt` | 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); timed text that marks the heard word and plays from any word (modes, speakers, follow and Jump to now, virtualised); `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 |
|
|
150
150
|
| Streams | `MediaPlayer attach`/`growing`, `useAttachedSource`, `attachHls` (`strata-react/hls`) | A source the element cannot play is attached by an engine; a source still being made says so, shows what exists as ready, and waits at its end without ending |
|
package/UPGRADING.md
CHANGED
|
@@ -14,6 +14,9 @@ Every PR that changes what an app sees adds a line here (see `CLAUDE.md`, "Chang
|
|
|
14
14
|
## After v0.1.17 (2026-11-11 to 2026-11-12)
|
|
15
15
|
|
|
16
16
|
- `RouteMap` now always has a tile under the last pixel column of the map (Leaflet could leave one bare, depending on the path the view took). A `RouteMap` baseline in a centred follow may gain one column of tile at the right edge.
|
|
17
|
+
- The type steps (`type-body`…) now read `--type-<step>-size`, `-leading` and `-weight` with today's values as the fallback, and `Button` reads `--control-px`, `--control-px-sm` and `--control-icon` (defaults 1rem, 0.75rem, 1rem, declared on `:root`): nothing to change unless an app already defines variables with those names. `Thumbnail`'s missing state with `alt=""` and no `missing` words is `aria-hidden` instead of an `img` named ""; a test that found it by role finds nothing. `Thumbnail`'s `src` type widened to a list; `onLoad`, `onMissing` are new.
|
|
18
|
+
- `MediaPlayer` with `kind="video"` draws the picture in a box (`aspect`, else the video's own shape, else 16:9 before its metadata loads) instead of letting the element size itself: a page that styled around the old height, and any video player baseline, will see the box. `VolumeControl`'s slider now shrinks (`min-w-24`) in a narrow row.
|
|
19
|
+
- `createHlsAttacher` and `attachHls`: a `growing` source now starts at its beginning (`startPosition` 0) where it started at the live edge, and `config.startPosition` is honoured on a first load; a test that expected `-1` for either sees `0` or the app's value. `StreamContext` has an optional `growing` for any other engine to read.
|
|
17
20
|
- `PairVote` and `Compare`/`CompareVideo` with `onPick` now choose on a click (after a 300 ms wait for a double click), so a screen that passes `onPick` or uses `PairVote` sees clicks answer; `pick={false}` keeps a click for panning only. `PairVoteSlot` gains an optional `onPick`: a custom `view` that spreads the whole slot onto `Compare` or `CompareVideo` gets it, and one that picks fields by hand adds it. `CompareVideo` and `CompareVideoGrid` now go back to 0, paused, when the pair's sources change (before, the position carried over). New props `autoPlay` and `loopWhole` are off by default.
|
|
18
21
|
- `MediaElementState` has new members (`window`, `playWindow`, `ready`, `waitingForMore`, `reportProblem`): code that builds one by hand (a stand-in for `Transport`, say) must add them. `useMediaElement` and `MediaPlayer` now keep the pitch whenever the rate changes (`preservesPitch`).
|
|
19
22
|
- `RouteMap` draws a "Reset view" button under the zoom control; a test that counts the map's buttons, and any `RouteMap` visual baseline, will see it.
|
|
@@ -16,6 +16,15 @@ export type LoadMoreProps<T> = {
|
|
|
16
16
|
keepAtLeast?: number;
|
|
17
17
|
/** Draws a failed later page, given the reason and the Try again. Rendered inside a `role="alert"` box. */
|
|
18
18
|
error?: (failure: LoadFailure) => React.ReactNode;
|
|
19
|
+
/** Draws the idle row (the "Show more" button) in the app's own look, given the label and the request. It must call `load` from a real button; focus moves to the first new item afterwards as with the default. */
|
|
20
|
+
more?: (row: {
|
|
21
|
+
label: string;
|
|
22
|
+
load: () => void;
|
|
23
|
+
}) => React.ReactNode;
|
|
24
|
+
/** Draws the row while a page is on its way, given `moreSkeleton`. The row is hidden from assistive technology as the default is; the "Loading more" announcement stays. */
|
|
25
|
+
loading?: (skeleton: React.ReactNode) => React.ReactNode;
|
|
26
|
+
/** A hairline above the idle, loading and end rows. Default true; `false` for a look with no rules between pages. */
|
|
27
|
+
ruled?: boolean;
|
|
19
28
|
className?: string;
|
|
20
29
|
};
|
|
21
30
|
/**
|
|
@@ -24,7 +33,7 @@ export type LoadMoreProps<T> = {
|
|
|
24
33
|
* keyboard, and `end` after the last page. After Show more it focuses the first new item: mark
|
|
25
34
|
* each item with `data-index` and put this row beside the list, in the same parent.
|
|
26
35
|
*/
|
|
27
|
-
export declare function LoadMore<T>({ state, moreLabel, moreSkeleton, end, rootMargin, keepAtLeast, error: drawError, className, }: LoadMoreProps<T>): React.JSX.Element | null;
|
|
36
|
+
export declare function LoadMore<T>({ state, moreLabel, moreSkeleton, end, rootMargin, keepAtLeast, error: drawError, more: drawMore, loading: drawLoading, ruled, className, }: LoadMoreProps<T>): React.JSX.Element | null;
|
|
28
37
|
/** The infinite list's props. */
|
|
29
38
|
export type InfiniteListProps<T> = {
|
|
30
39
|
state: InfiniteLoad<T>;
|
|
@@ -53,10 +62,16 @@ export type InfiniteListProps<T> = {
|
|
|
53
62
|
error?: (failure: LoadFailure) => React.ReactNode;
|
|
54
63
|
/** Draws a failed later page. Defaults to a danger row with Try again. */
|
|
55
64
|
moreError?: (failure: LoadFailure) => React.ReactNode;
|
|
65
|
+
/** Draws the "Show more" row in the app's own look, as `LoadMore`'s `more`. */
|
|
66
|
+
moreRow?: LoadMoreProps<T>["more"];
|
|
67
|
+
/** Draws the row while a page is on its way, as `LoadMore`'s `loading`. */
|
|
68
|
+
moreLoading?: LoadMoreProps<T>["loading"];
|
|
69
|
+
/** A hairline above the next-page rows. Default true. */
|
|
70
|
+
ruled?: boolean;
|
|
56
71
|
estimateSize?: number;
|
|
57
72
|
height?: number;
|
|
58
73
|
virtualizeFrom?: number;
|
|
59
74
|
className?: string;
|
|
60
75
|
};
|
|
61
76
|
/** A cursor-paged list for `useInfiniteLoad`: DataView's first-page states, virtual rows (or a page-scrolled grid), and a `LoadMore` row that loads on approach, shows a skeleton, or says why it failed with Try again. */
|
|
62
|
-
export declare function InfiniteList<T>({ state, label, children, skeleton, empty, moreLabel, moreSkeleton, end, rootMargin, keepAtLeast, scroll, listClassName, error, moreError, estimateSize, height, virtualizeFrom, className, }: InfiniteListProps<T>): React.JSX.Element;
|
|
77
|
+
export declare function InfiniteList<T>({ state, label, children, skeleton, empty, moreLabel, moreSkeleton, end, rootMargin, keepAtLeast, scroll, listClassName, error, moreError, moreRow, moreLoading, ruled, estimateSize, height, virtualizeFrom, className, }: InfiniteListProps<T>): React.JSX.Element;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MediaSpanData, SpanKind, SpanOutcome, SpanWords } from './media-spans';
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
/** Why a player is not playing, for the app to word. */
|
|
3
4
|
export type MediaProblem = {
|
|
@@ -75,6 +76,8 @@ export type StreamContext = {
|
|
|
75
76
|
startAt: number;
|
|
76
77
|
/** Tell the player the stream failed, in words for the person: it shows the load error with Try again. */
|
|
77
78
|
onProblem: (message: string) => void;
|
|
79
|
+
/** The source is still being made (`MediaPlayer growing`): its start exists and the edge moves, so a first load starts at the beginning, not at the newest part. */
|
|
80
|
+
growing?: boolean;
|
|
78
81
|
};
|
|
79
82
|
/** A stream engine's hold on an element, so the player can end it and restart it. */
|
|
80
83
|
export type StreamAttachment = {
|
|
@@ -94,7 +97,7 @@ export type SourceAttacher = (el: HTMLMediaElement, src: string, context: Stream
|
|
|
94
97
|
* Use it for a plain `<video>` the app owns, with `useMediaElement`; `MediaPlayer` does it for `attach`.
|
|
95
98
|
* Returns `reload`, for the player's Try again (`useMediaElement`'s `onRetry`), and gives the engine's failures to `onProblem` (`reportProblem`).
|
|
96
99
|
*/
|
|
97
|
-
export declare function useAttachedSource(ref: React.RefObject<HTMLMediaElement | null>, src: string | undefined, attach: SourceAttacher | undefined, onProblem?: (message: string) => void): {
|
|
100
|
+
export declare function useAttachedSource(ref: React.RefObject<HTMLMediaElement | null>, src: string | undefined, attach: SourceAttacher | undefined, onProblem?: (message: string) => void, growing?: boolean): {
|
|
98
101
|
reload: (at: number) => void;
|
|
99
102
|
};
|
|
100
103
|
/** One file in a sequence. */
|
|
@@ -156,6 +159,20 @@ export type MediaPlayerProps = {
|
|
|
156
159
|
onEnded?: () => void;
|
|
157
160
|
/** Called as the element plays, with the time in the whole sequence. */
|
|
158
161
|
onTimeChange?: (time: number) => void;
|
|
162
|
+
/** Marked stretches (an intro, a recap, a sponsor read), in seconds on the player's timeline: drawn on the seek bar, and acted on as playback reaches them as `spanKinds` says (strata-react issue #207). */
|
|
163
|
+
spans?: readonly MediaSpanData[];
|
|
164
|
+
/** For each kind of span: its `label`, its `tone` (a status role) and what happens on reaching one: `"auto"` skips it (or mutes it, for a span whose `action` is `"mute"`) with "Skipped intro" and Undo, `"ask"` offers a Skip button over the picture (and the `s` key), `"off"` (default) only draws it. Keep the object stable (state or `useMemo`). */
|
|
165
|
+
spanKinds?: Readonly<Record<string, SpanKind>>;
|
|
166
|
+
/** Told what was done with a span: `skipped`, `muted`, `undone` or `played`. */
|
|
167
|
+
onSpan?: (span: MediaSpanData, what: SpanOutcome) => void;
|
|
168
|
+
/** The Skip button's and the notice's words, in the product's language. */
|
|
169
|
+
spanWords?: SpanWords;
|
|
170
|
+
/** The player's state and requests (`seek`, `setVolume`, `time`, `duration`…), for an app that acts on playback from beside it: a chapter list, comments at a time (strata-react issue #211). An object ref holds the latest state without rendering again; a function ref is called with it on every render. */
|
|
171
|
+
mediaRef?: React.Ref<MediaElementState>;
|
|
172
|
+
/** Drawn over the picture only (never the controls) in a box that fills it; the app's classes choose the corner (`absolute bottom-3 right-3`). Anything interactive in it is clickable and focusable. A video's box keeps its shape before the metadata loads, so the overlay has a stable place. */
|
|
173
|
+
overlay?: (media: MediaElementState) => React.ReactNode;
|
|
174
|
+
/** The picture's shape before its metadata loads (and after, when given): a width over a height, or "16/9". Default "16/9" until the video says its own. */
|
|
175
|
+
aspect?: number | `${number}/${number}`;
|
|
159
176
|
className?: string;
|
|
160
177
|
};
|
|
161
178
|
/** Playback speeds an audiobook or lecture listener expects. */
|
|
@@ -165,4 +182,4 @@ export declare const SPEECH_RATES: readonly number[];
|
|
|
165
182
|
* a touch device), with the failure to load shown and retried. For an editor or a replay, use the
|
|
166
183
|
* parts and `useMediaElement` directly.
|
|
167
184
|
*/
|
|
168
|
-
export declare function MediaPlayer({ label, kind, src, sources, index: controlledIndex, onIndexChange, autoAdvance, controls, autoPlay, poster, session, rates, shortcuts, attach, growing, window: bound, loop, showFull, group, onTimeUpdate, onWindowEnd, onEnded, onTimeChange, className, }: MediaPlayerProps): React.JSX.Element;
|
|
185
|
+
export declare function MediaPlayer({ label, kind, src, sources, index: controlledIndex, onIndexChange, autoAdvance, controls, autoPlay, poster, session, rates, shortcuts, attach, growing, window: bound, loop, showFull, group, onTimeUpdate, onWindowEnd, onEnded, onTimeChange, spans, spanKinds, onSpan, spanWords, mediaRef, overlay, aspect, className, }: MediaPlayerProps): React.JSX.Element;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { SeekBarSpan } from './media';
|
|
2
|
+
import { SpanTone } from './line-chart';
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
/** What happens when playback reaches a kind of stretch. `"off"` only draws it. */
|
|
5
|
+
export type SpanBehaviour = "auto" | "ask" | "off";
|
|
6
|
+
/** How one kind of stretch is drawn and treated. */
|
|
7
|
+
export type SpanKind = {
|
|
8
|
+
/** "Intro": its name on the bar and in the buttons ("Skip intro"). */
|
|
9
|
+
label: string;
|
|
10
|
+
/** Default "off". */
|
|
11
|
+
behaviour?: SpanBehaviour;
|
|
12
|
+
/** Default "info". */
|
|
13
|
+
tone?: SpanTone;
|
|
14
|
+
};
|
|
15
|
+
/** A stretch of the recording, in seconds on the player's timeline, of one of the `spanKinds`. */
|
|
16
|
+
export type MediaSpanData = {
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
kind: string;
|
|
20
|
+
/** What acting on it does: skip to its end (default), or mute until it ends. */
|
|
21
|
+
action?: "skip" | "mute";
|
|
22
|
+
};
|
|
23
|
+
/** What the player did with a stretch, for an app that records it: `skipped`, `muted`, `undone` (the person took it back), `played` (it was offered and let play, or played after Undo). */
|
|
24
|
+
export type SpanOutcome = "skipped" | "muted" | "undone" | "played";
|
|
25
|
+
/** The words of the Skip button and the notice, in the product's voice. Each takes the kind's label. */
|
|
26
|
+
export type SpanWords = {
|
|
27
|
+
/** Default `Skip intro` (the label in lower case). */
|
|
28
|
+
skip?: (label: string) => string;
|
|
29
|
+
/** Default `Skipped intro`. */
|
|
30
|
+
skipped?: (label: string) => string;
|
|
31
|
+
/** Default `Mute sponsor`. */
|
|
32
|
+
mute?: (label: string) => string;
|
|
33
|
+
/** Default `Muted sponsor`. */
|
|
34
|
+
muted?: (label: string) => string;
|
|
35
|
+
/** Default "Undo". */
|
|
36
|
+
undo?: string;
|
|
37
|
+
};
|
|
38
|
+
type Options = {
|
|
39
|
+
spans?: readonly MediaSpanData[];
|
|
40
|
+
kinds?: Readonly<Record<string, SpanKind>>;
|
|
41
|
+
words?: SpanWords;
|
|
42
|
+
onSpan?: (span: MediaSpanData, what: SpanOutcome) => void;
|
|
43
|
+
/** Seconds, on the same timeline as the spans. */
|
|
44
|
+
time: number;
|
|
45
|
+
playing: boolean;
|
|
46
|
+
/** The length, once known: spans are cut to it. */
|
|
47
|
+
duration: number | null;
|
|
48
|
+
/** Seconds that exist so far, for a source still being made; a span ending beyond it is not skipped yet. */
|
|
49
|
+
limit?: number;
|
|
50
|
+
seek: (time: number) => void;
|
|
51
|
+
/** 0 to 100; 0 is muted. */
|
|
52
|
+
volume: number;
|
|
53
|
+
setVolume: (volume: number) => void;
|
|
54
|
+
};
|
|
55
|
+
/** What `useMediaSpans` gives the player. */
|
|
56
|
+
export type MediaSpansState = {
|
|
57
|
+
/** For `SeekBar spans`. */
|
|
58
|
+
bars: SeekBarSpan[];
|
|
59
|
+
/** The stretch being played that the person can skip (or mute), with its button's words; null when none is offered. */
|
|
60
|
+
offer: {
|
|
61
|
+
label: string;
|
|
62
|
+
run: () => void;
|
|
63
|
+
} | null;
|
|
64
|
+
/** What was just done, with the way back; gone after a few seconds. */
|
|
65
|
+
notice: {
|
|
66
|
+
text: string;
|
|
67
|
+
undoLabel: string;
|
|
68
|
+
undo: () => void;
|
|
69
|
+
} | null;
|
|
70
|
+
};
|
|
71
|
+
/** Draws the spans' ranges and acts on them as playback reaches them. See the file comment for the rules. */
|
|
72
|
+
export declare function useMediaSpans({ spans, kinds, words, onSpan, time, playing, duration, limit, seek, volume, setVolume }: Options): MediaSpansState;
|
|
73
|
+
/** The Skip button and the "Skipped intro, Undo" notice, for the player to draw over a picture or under the bar. The notice's live region is always present, so a screen reader hears what is put in it. */
|
|
74
|
+
export declare function SpanActions({ state, className }: {
|
|
75
|
+
state: MediaSpansState;
|
|
76
|
+
className?: string;
|
|
77
|
+
}): React.JSX.Element;
|
|
78
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SpanTone } from './line-chart';
|
|
1
2
|
import { Shortcut } from './hotkeys';
|
|
2
3
|
import { CursorMapping } from './cursor';
|
|
3
4
|
import * as React from "react";
|
|
@@ -13,6 +14,16 @@ export declare function TimeReadout({ time, duration, precision, fps, className
|
|
|
13
14
|
} & TimeProps & {
|
|
14
15
|
className?: string;
|
|
15
16
|
}): React.JSX.Element;
|
|
17
|
+
/** A stretch of the bar, drawn as a range: an intro, a recap, an advert break. */
|
|
18
|
+
export type SeekBarSpan = {
|
|
19
|
+
/** Seconds. */
|
|
20
|
+
start: number;
|
|
21
|
+
end: number;
|
|
22
|
+
/** Its name for a screen reader and the tooltip: "Intro". The bar adds its times: "Intro, 0:00 to 0:12". */
|
|
23
|
+
label: string;
|
|
24
|
+
/** Default "info". */
|
|
25
|
+
tone?: SpanTone;
|
|
26
|
+
};
|
|
16
27
|
export type SeekBarProps = TimeProps & {
|
|
17
28
|
time: number;
|
|
18
29
|
/** Seconds; null, NaN or 0 while it is not known (a stream before its metadata): the bar is drawn disabled, with no thumb. */
|
|
@@ -24,6 +35,8 @@ export type SeekBarProps = TimeProps & {
|
|
|
24
35
|
time: number;
|
|
25
36
|
label: string;
|
|
26
37
|
}[];
|
|
38
|
+
/** Stretches drawn along the bar as ranges (strata-react issue #207): each named for a screen reader and in a tooltip, in a status role's colour, and never thinner than a few pixels so a one-second span still shows. They only draw; `MediaPlayer`'s `spans` is what acts on them. */
|
|
39
|
+
spans?: readonly SeekBarSpan[];
|
|
27
40
|
/** What pressing a mark does. Default seeks to it; a screen that wants to land on it and pause (a moment to look at) passes its own. */
|
|
28
41
|
onMarkPress?: (mark: {
|
|
29
42
|
time: number;
|
|
@@ -44,7 +57,7 @@ export type SeekBarProps = TimeProps & {
|
|
|
44
57
|
className?: string;
|
|
45
58
|
};
|
|
46
59
|
/** A seek bar: dragged, clicked and moved by keys (arrows `step`, Page keys `bigStep`, Home and End), with its time as the accessible value. */
|
|
47
|
-
export declare function SeekBar({ time, duration: known, onSeek, marks, onMarkPress, buffered, step, bigStep, label, precision, fps, disabled: off, cursor: cursorProp, className }: SeekBarProps): React.JSX.Element;
|
|
60
|
+
export declare function SeekBar({ time, duration: known, onSeek, marks, spans, onMarkPress, buffered, step, bigStep, label, precision, fps, disabled: off, cursor: cursorProp, className }: SeekBarProps): React.JSX.Element;
|
|
48
61
|
export type TransportProps = {
|
|
49
62
|
playing: boolean;
|
|
50
63
|
onPlayPause: () => void;
|
|
@@ -3,8 +3,8 @@ import * as React from "react";
|
|
|
3
3
|
export type AspectRatio = number | `${number}/${number}`;
|
|
4
4
|
/** The thumbnail's props. Either `missing` (the words shown when there is no image) or a `fallback` drawing is required. */
|
|
5
5
|
export type ThumbnailProps = {
|
|
6
|
-
/** The image URL. `null` when the record has no photo: the `missing` words show without a request. */
|
|
7
|
-
src: string | null;
|
|
6
|
+
/** The image URL, or a list of them tried in order (the next one when a request fails or `onLoad` rejects it). `null` or an empty list when the record has no photo: the `missing` words show without a request. */
|
|
7
|
+
src: string | readonly string[] | null;
|
|
8
8
|
/** What the photo shows ("Celadon bowl, front"). `""` only when the text beside it already says it. */
|
|
9
9
|
alt: string;
|
|
10
10
|
/** Width over height. The box has this shape before the image loads. Default `1`. */
|
|
@@ -19,6 +19,10 @@ export type ThumbnailProps = {
|
|
|
19
19
|
rootMargin?: string;
|
|
20
20
|
/** Layout at the call site: a width (`w-24`, `w-full`), or `rounded-pill` for an avatar. The height follows from `aspect`. */
|
|
21
21
|
className?: string;
|
|
22
|
+
/** Sees each image that loaded, with the index of its source. Return `false` to reject it (a host's grey placeholder answered with a 200): the next source is tried, or the missing state shows. */
|
|
23
|
+
onLoad?: (image: HTMLImageElement, index: number) => boolean | void;
|
|
24
|
+
/** Called once when the thumbnail ends in its missing state after a request failed or was rejected, never for a record with no source. */
|
|
25
|
+
onMissing?: () => void;
|
|
22
26
|
/** Overlays drawn above the image in the same box (a running time, a "Saved" badge), in place whether the image has loaded, failed or is missing. */
|
|
23
27
|
children?: React.ReactNode;
|
|
24
28
|
} & ({
|
|
@@ -33,7 +37,7 @@ export type ThumbnailProps = {
|
|
|
33
37
|
fallback: React.ReactNode;
|
|
34
38
|
});
|
|
35
39
|
/** A box of fixed aspect ratio for a remote image: a skeleton until it loads, the `missing` words (or a `fallback`) if it cannot, a request only when it nears the screen, and `children` overlaid in its corners. `alt` and `missing` or `fallback` are required. */
|
|
36
|
-
export declare function Thumbnail({ src, alt, missing, aspect, fit, srcSet, sizes, eager, rootMargin, className, fallback, children, }: ThumbnailProps): React.JSX.Element;
|
|
40
|
+
export declare function Thumbnail({ src, alt, missing, aspect, fit, srcSet, sizes, eager, rootMargin, className, fallback, onLoad, onMissing, children, }: ThumbnailProps): React.JSX.Element;
|
|
37
41
|
/** The loading shape of a `Thumbnail`, for a `DataView` skeleton: the same box and aspect ratio, so nothing moves when the list arrives. */
|
|
38
42
|
export declare function ThumbnailSkeleton({ aspect, className }: {
|
|
39
43
|
aspect?: AspectRatio;
|
package/dist/hls/index.d.ts
CHANGED
|
@@ -2,18 +2,29 @@ import { default as Hls, HlsConfig } from 'hls.js';
|
|
|
2
2
|
import { SourceAttacher } from '../components/media-player';
|
|
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;
|
|
5
|
+
declare const WORDS: {
|
|
6
|
+
network: string;
|
|
7
|
+
media: string;
|
|
8
|
+
other: string;
|
|
9
|
+
unsupported: string;
|
|
10
|
+
};
|
|
11
|
+
/** The words an HLS attacher says for each way a stream fails. */
|
|
12
|
+
export type HlsWords = Partial<Record<keyof typeof WORDS, string>>;
|
|
5
13
|
/** Options of an HLS attacher. */
|
|
6
14
|
export type HlsAttacherOptions = {
|
|
7
15
|
/** Which to use where both would do: `"engine"` (default) is hls.js, `"native"` is the element's own HLS. Where only one is available that one is used. */
|
|
8
16
|
prefer?: "engine" | "native";
|
|
9
17
|
/** hls.js's own configuration. */
|
|
10
18
|
config?: Partial<HlsConfig>;
|
|
19
|
+
/** What each failure says in the product's words (the connection dropped, the stream could not be decoded, anything else, no support here). Defaults are plain English. */
|
|
20
|
+
words?: HlsWords;
|
|
11
21
|
};
|
|
12
22
|
/** Makes a `SourceAttacher` around an hls.js engine: the engine where the browser has Media Source Extensions, otherwise the element's own HLS. */
|
|
13
|
-
export declare function createHlsAttacher(Engine: HlsEngine, { prefer, config }?: HlsAttacherOptions): SourceAttacher;
|
|
23
|
+
export declare function createHlsAttacher(Engine: HlsEngine, { prefer, config, words }?: HlsAttacherOptions): SourceAttacher;
|
|
14
24
|
/** HLS for `MediaPlayer attach` and `useAttachedSource`: hls.js where the browser has Media Source Extensions, the element's own HLS where it does not. */
|
|
15
25
|
export declare const attachHls: SourceAttacher;
|
|
16
26
|
/** An HLS attacher with options: `prefer: "native"`, or hls.js's own `config` (buffer sizes, headers). */
|
|
17
27
|
export declare const hlsAttacher: (options: HlsAttacherOptions) => SourceAttacher;
|
|
18
28
|
/** Whether this browser can play HLS at all, natively or through hls.js. */
|
|
19
29
|
export declare function hlsSupported(): boolean;
|
|
30
|
+
export {};
|
package/dist/hls.js
CHANGED
|
@@ -7,7 +7,11 @@ var WORDS = {
|
|
|
7
7
|
unsupported: "This browser cannot play this kind of stream."
|
|
8
8
|
};
|
|
9
9
|
/** Makes a `SourceAttacher` around an hls.js engine: the engine where the browser has Media Source Extensions, otherwise the element's own HLS. */
|
|
10
|
-
function createHlsAttacher(Engine, { prefer = "engine", config = {} } = {}) {
|
|
10
|
+
function createHlsAttacher(Engine, { prefer = "engine", config = {}, words = {} } = {}) {
|
|
11
|
+
const say = {
|
|
12
|
+
...WORDS,
|
|
13
|
+
...words
|
|
14
|
+
};
|
|
11
15
|
return (el, src, context) => {
|
|
12
16
|
const native = el.canPlayType("application/vnd.apple.mpegurl") !== "" && (prefer === "native" || !Engine.isSupported());
|
|
13
17
|
let engine = null;
|
|
@@ -32,12 +36,12 @@ function createHlsAttacher(Engine, { prefer = "engine", config = {} } = {}) {
|
|
|
32
36
|
return;
|
|
33
37
|
}
|
|
34
38
|
if (!Engine.isSupported()) {
|
|
35
|
-
context.onProblem(
|
|
39
|
+
context.onProblem(say.unsupported);
|
|
36
40
|
return;
|
|
37
41
|
}
|
|
38
42
|
const hls = new Engine({
|
|
39
43
|
...config,
|
|
40
|
-
startPosition: at > 0 ? at : -1
|
|
44
|
+
startPosition: at > 0 ? at : config.startPosition ?? (context.growing ? 0 : -1)
|
|
41
45
|
});
|
|
42
46
|
engine = hls;
|
|
43
47
|
let recoveries = 0;
|
|
@@ -53,7 +57,7 @@ function createHlsAttacher(Engine, { prefer = "engine", config = {} } = {}) {
|
|
|
53
57
|
recoveries++;
|
|
54
58
|
hls.recoverMediaError();
|
|
55
59
|
} else {
|
|
56
|
-
context.onProblem(data.type === Engine.ErrorTypes.NETWORK_ERROR ?
|
|
60
|
+
context.onProblem(data.type === Engine.ErrorTypes.NETWORK_ERROR ? say.network : data.type === Engine.ErrorTypes.MEDIA_ERROR ? say.media : say.other);
|
|
57
61
|
stop();
|
|
58
62
|
}
|
|
59
63
|
});
|
package/dist/hls.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hls.js","names":[],"sources":["../src/hls/index.ts"],"sourcesContent":["import Hls, { type HlsConfig } from \"hls.js\";\nimport type { SourceAttacher, StreamAttachment, StreamContext } from \"../components/media-player\";\n\n// The HLS entry: `import { attachHls } from \"strata-react/hls\"` (strata-react issue #179, from\n// strata-360, whose film preview is an HLS stream that starts playing after a couple of seconds and\n// keeps growing while the rest is made). `hls.js` is an optional peer that only this entry imports, as\n// `leaflet` is for the map, so an app that never plays a stream never installs it, and the main entry\n// never reaches it (the peer-contract test walks the built chunks to keep that true).\n//\n// It is a `SourceAttacher`, the one shape the main entry knows: `<MediaPlayer attach={attachHls}\n// src=\"…/film.m3u8\" />`, or `useAttachedSource(ref, src, attachHls, media.reportProblem)` beside\n// `useMediaElement` for a plain `<video>` (the panorama viewer, the compare components). It does three\n// things the engine does not do for a player:\n//\n// - **The engine wherever it can run, the element's own HLS where it cannot.** The brief was \"native\n// where the browser plays it\", but Chromium now plays HLS natively and, checked in Chromium 158 here,\n// its native pipeline failed (`DEMUXER_ERROR_COULD_NOT_PARSE`) on a growing playlist that hls.js plays,\n// which is the case this exists for. So hls.js is used wherever Media Source Extensions exist, one\n// behaviour on every browser, and the element's `src` only where they do not (older iOS). `prefer:\n// \"native\"` turns that around for an app that wants the system's own player behaviour.\n// - **Recovers what can be recovered, and says what cannot.** hls.js reports a fatal error for a\n// dropped connection or a decoder hiccup that its own `startLoad()` or `recoverMediaError()` fixes;\n// up to three of those are tried quietly (the count resets once a segment loads), and only then does\n// the player's load error appear, in words, with Try again. Try again restarts the engine at the\n// time playback had reached.\n// - **Cleans up**: the engine is destroyed when the source changes, the attacher changes or the player\n// unmounts, so a source switch never leaves two engines on one element.\n//\n// What is *growing* is the player's business (`MediaPlayer growing`), not the engine's: hls.js plays a\n// playlist with no end-list as a live one and the element reports the end of what exists as its\n// seekable range.\n//\n// Checked: hls.js has `isSupported()` (false with no Media Source Extensions), `startPosition` for a\n// restart in place, `startLoad()` and `recoverMediaError()` for the two recoverable kinds of fatal\n// error, and `Events.FRAG_LOADED` to know it is working again.\n\n/** The parts of hls.js this entry uses, so the engine can be handed in (a test's, or an app's own build). */\nexport type HlsEngine = typeof Hls;\n\nconst WORDS = {\n network: \"The connection to the stream dropped.\",\n media: \"The stream could not be decoded.\",\n other: \"The stream could not be played.\",\n unsupported: \"This browser cannot play this kind of stream.\",\n};\n\n/** Options of an HLS attacher. */\nexport type HlsAttacherOptions = {\n /** Which to use where both would do: `\"engine\"` (default) is hls.js, `\"native\"` is the element's own HLS. Where only one is available that one is used. */\n prefer?: \"engine\" | \"native\";\n /** hls.js's own configuration. */\n config?: Partial<HlsConfig>;\n};\n\n/** Makes a `SourceAttacher` around an hls.js engine: the engine where the browser has Media Source Extensions, otherwise the element's own HLS. */\nexport function createHlsAttacher(Engine: HlsEngine, { prefer = \"engine\", config = {} }: HlsAttacherOptions = {}): SourceAttacher {\n return (el: HTMLMediaElement, src: string, context: StreamContext): StreamAttachment => {\n const canNative = el.canPlayType(\"application/vnd.apple.mpegurl\") !== \"\";\n const native = canNative && (prefer === \"native\" || !Engine.isSupported());\n let engine: Hls | null = null;\n let seekOnLoad: (() => void) | null = null;\n\n const stop = () => {\n engine?.destroy();\n engine = null;\n if (seekOnLoad) el.removeEventListener(\"loadedmetadata\", seekOnLoad);\n seekOnLoad = null;\n };\n\n const start = (at: number) => {\n stop();\n if (native) {\n el.src = src;\n if (at > 0) {\n seekOnLoad = () => {\n el.currentTime = at;\n seekOnLoad = null;\n };\n el.addEventListener(\"loadedmetadata\", seekOnLoad, { once: true });\n }\n return;\n }\n if (!Engine.isSupported()) {\n context.onProblem(
|
|
1
|
+
{"version":3,"file":"hls.js","names":[],"sources":["../src/hls/index.ts"],"sourcesContent":["import Hls, { type HlsConfig } from \"hls.js\";\nimport type { SourceAttacher, StreamAttachment, StreamContext } from \"../components/media-player\";\n\n// The HLS entry: `import { attachHls } from \"strata-react/hls\"` (strata-react issue #179, from\n// strata-360, whose film preview is an HLS stream that starts playing after a couple of seconds and\n// keeps growing while the rest is made). `hls.js` is an optional peer that only this entry imports, as\n// `leaflet` is for the map, so an app that never plays a stream never installs it, and the main entry\n// never reaches it (the peer-contract test walks the built chunks to keep that true).\n//\n// It is a `SourceAttacher`, the one shape the main entry knows: `<MediaPlayer attach={attachHls}\n// src=\"…/film.m3u8\" />`, or `useAttachedSource(ref, src, attachHls, media.reportProblem)` beside\n// `useMediaElement` for a plain `<video>` (the panorama viewer, the compare components). It does three\n// things the engine does not do for a player:\n//\n// - **The engine wherever it can run, the element's own HLS where it cannot.** The brief was \"native\n// where the browser plays it\", but Chromium now plays HLS natively and, checked in Chromium 158 here,\n// its native pipeline failed (`DEMUXER_ERROR_COULD_NOT_PARSE`) on a growing playlist that hls.js plays,\n// which is the case this exists for. So hls.js is used wherever Media Source Extensions exist, one\n// behaviour on every browser, and the element's `src` only where they do not (older iOS). `prefer:\n// \"native\"` turns that around for an app that wants the system's own player behaviour.\n// - **Recovers what can be recovered, and says what cannot.** hls.js reports a fatal error for a\n// dropped connection or a decoder hiccup that its own `startLoad()` or `recoverMediaError()` fixes;\n// up to three of those are tried quietly (the count resets once a segment loads), and only then does\n// the player's load error appear, in words, with Try again. Try again restarts the engine at the\n// time playback had reached.\n// - **Cleans up**: the engine is destroyed when the source changes, the attacher changes or the player\n// unmounts, so a source switch never leaves two engines on one element.\n//\n// What is *growing* is the player's business (`MediaPlayer growing`), not the engine's: hls.js plays a\n// playlist with no end-list as a live one and the element reports the end of what exists as its\n// seekable range.\n//\n// Checked: hls.js has `isSupported()` (false with no Media Source Extensions), `startPosition` for a\n// restart in place, `startLoad()` and `recoverMediaError()` for the two recoverable kinds of fatal\n// error, and `Events.FRAG_LOADED` to know it is working again.\n\n/** The parts of hls.js this entry uses, so the engine can be handed in (a test's, or an app's own build). */\nexport type HlsEngine = typeof Hls;\n\nconst WORDS = {\n network: \"The connection to the stream dropped.\",\n media: \"The stream could not be decoded.\",\n other: \"The stream could not be played.\",\n unsupported: \"This browser cannot play this kind of stream.\",\n};\n\n/** The words an HLS attacher says for each way a stream fails. */\nexport type HlsWords = Partial<Record<keyof typeof WORDS, string>>;\n\n/** Options of an HLS attacher. */\nexport type HlsAttacherOptions = {\n /** Which to use where both would do: `\"engine\"` (default) is hls.js, `\"native\"` is the element's own HLS. Where only one is available that one is used. */\n prefer?: \"engine\" | \"native\";\n /** hls.js's own configuration. */\n config?: Partial<HlsConfig>;\n /** What each failure says in the product's words (the connection dropped, the stream could not be decoded, anything else, no support here). Defaults are plain English. */\n words?: HlsWords;\n};\n\n/** Makes a `SourceAttacher` around an hls.js engine: the engine where the browser has Media Source Extensions, otherwise the element's own HLS. */\nexport function createHlsAttacher(Engine: HlsEngine, { prefer = \"engine\", config = {}, words = {} }: HlsAttacherOptions = {}): SourceAttacher {\n const say = { ...WORDS, ...words };\n return (el: HTMLMediaElement, src: string, context: StreamContext): StreamAttachment => {\n const canNative = el.canPlayType(\"application/vnd.apple.mpegurl\") !== \"\";\n const native = canNative && (prefer === \"native\" || !Engine.isSupported());\n let engine: Hls | null = null;\n let seekOnLoad: (() => void) | null = null;\n\n const stop = () => {\n engine?.destroy();\n engine = null;\n if (seekOnLoad) el.removeEventListener(\"loadedmetadata\", seekOnLoad);\n seekOnLoad = null;\n };\n\n const start = (at: number) => {\n stop();\n if (native) {\n el.src = src;\n if (at > 0) {\n seekOnLoad = () => {\n el.currentTime = at;\n seekOnLoad = null;\n };\n el.addEventListener(\"loadedmetadata\", seekOnLoad, { once: true });\n }\n return;\n }\n if (!Engine.isSupported()) {\n context.onProblem(say.unsupported);\n return;\n }\n // Where playback had reached, else the app's own start, else the beginning of a source still being made\n // (an EVENT playlist counts as live to hls.js, which with -1 would start at the newest part), else hls.js's choice.\n const hls = new Engine({ ...config, startPosition: at > 0 ? at : (config.startPosition ?? (context.growing ? 0 : -1)) });\n engine = hls;\n let recoveries = 0;\n hls.on(Engine.Events.FRAG_LOADED, () => {\n recoveries = 0;\n });\n hls.on(Engine.Events.ERROR, (_event, data) => {\n if (!data.fatal || engine !== hls) return;\n if (recoveries < 3 && data.type === Engine.ErrorTypes.NETWORK_ERROR) {\n recoveries++;\n hls.startLoad();\n } else if (recoveries < 3 && data.type === Engine.ErrorTypes.MEDIA_ERROR) {\n recoveries++;\n hls.recoverMediaError();\n } else {\n context.onProblem(data.type === Engine.ErrorTypes.NETWORK_ERROR ? say.network : data.type === Engine.ErrorTypes.MEDIA_ERROR ? say.media : say.other);\n stop();\n }\n });\n hls.loadSource(src);\n hls.attachMedia(el);\n };\n\n start(context.startAt);\n return {\n detach: () => {\n stop();\n if (native) el.removeAttribute(\"src\");\n },\n reload: start,\n };\n };\n}\n\n/** HLS for `MediaPlayer attach` and `useAttachedSource`: hls.js where the browser has Media Source Extensions, the element's own HLS where it does not. */\nexport const attachHls: SourceAttacher = createHlsAttacher(Hls);\n\n/** An HLS attacher with options: `prefer: \"native\"`, or hls.js's own `config` (buffer sizes, headers). */\nexport const hlsAttacher = (options: HlsAttacherOptions): SourceAttacher => createHlsAttacher(Hls, options);\n\n/** Whether this browser can play HLS at all, natively or through hls.js. */\nexport function hlsSupported(): boolean {\n if (typeof document === \"undefined\") return false;\n return document.createElement(\"video\").canPlayType(\"application/vnd.apple.mpegurl\") !== \"\" || Hls.isSupported();\n}\n"],"mappings":";;AAuCA,IAAM,QAAQ;CACZ,SAAS;CACT,OAAO;CACP,OAAO;CACP,aAAa;AACf;;AAgBA,SAAgB,kBAAkB,QAAmB,EAAE,SAAS,UAAU,SAAS,CAAC,GAAG,QAAQ,CAAC,MAA0B,CAAC,GAAmB;CAC5I,MAAM,MAAM;EAAE,GAAG;EAAO,GAAG;CAAM;CACjC,QAAQ,IAAsB,KAAa,YAA6C;EAEtF,MAAM,SADY,GAAG,YAAY,+BAA+B,MAAM,OACzC,WAAW,YAAY,CAAC,OAAO,YAAY;EACxE,IAAI,SAAqB;EACzB,IAAI,aAAkC;EAEtC,MAAM,aAAa;GACjB,QAAQ,QAAQ;GAChB,SAAS;GACT,IAAI,YAAY,GAAG,oBAAoB,kBAAkB,UAAU;GACnE,aAAa;EACf;EAEA,MAAM,SAAS,OAAe;GAC5B,KAAK;GACL,IAAI,QAAQ;IACV,GAAG,MAAM;IACT,IAAI,KAAK,GAAG;KACV,mBAAmB;MACjB,GAAG,cAAc;MACjB,aAAa;KACf;KACA,GAAG,iBAAiB,kBAAkB,YAAY,EAAE,MAAM,KAAK,CAAC;IAClE;IACA;GACF;GACA,IAAI,CAAC,OAAO,YAAY,GAAG;IACzB,QAAQ,UAAU,IAAI,WAAW;IACjC;GACF;GAGA,MAAM,MAAM,IAAI,OAAO;IAAE,GAAG;IAAQ,eAAe,KAAK,IAAI,KAAM,OAAO,kBAAkB,QAAQ,UAAU,IAAI;GAAK,CAAC;GACvH,SAAS;GACT,IAAI,aAAa;GACjB,IAAI,GAAG,OAAO,OAAO,mBAAmB;IACtC,aAAa;GACf,CAAC;GACD,IAAI,GAAG,OAAO,OAAO,QAAQ,QAAQ,SAAS;IAC5C,IAAI,CAAC,KAAK,SAAS,WAAW,KAAK;IACnC,IAAI,aAAa,KAAK,KAAK,SAAS,OAAO,WAAW,eAAe;KACnE;KACA,IAAI,UAAU;IAChB,OAAO,IAAI,aAAa,KAAK,KAAK,SAAS,OAAO,WAAW,aAAa;KACxE;KACA,IAAI,kBAAkB;IACxB,OAAO;KACL,QAAQ,UAAU,KAAK,SAAS,OAAO,WAAW,gBAAgB,IAAI,UAAU,KAAK,SAAS,OAAO,WAAW,cAAc,IAAI,QAAQ,IAAI,KAAK;KACnJ,KAAK;IACP;GACF,CAAC;GACD,IAAI,WAAW,GAAG;GAClB,IAAI,YAAY,EAAE;EACpB;EAEA,MAAM,QAAQ,OAAO;EACrB,OAAO;GACL,cAAc;IACZ,KAAK;IACL,IAAI,QAAQ,GAAG,gBAAgB,KAAK;GACtC;GACA,QAAQ;EACV;CACF;AACF;;AAGA,IAAa,YAA4B,kBAAkB,GAAG;;AAG9D,IAAa,eAAe,YAAgD,kBAAkB,KAAK,OAAO;;AAG1G,SAAgB,eAAwB;CACtC,IAAI,OAAO,aAAa,aAAa,OAAO;CAC5C,OAAO,SAAS,cAAc,OAAO,CAAC,CAAC,YAAY,+BAA+B,MAAM,MAAM,IAAI,YAAY;AAChH"}
|
package/dist/index.d.ts
CHANGED
|
@@ -36,12 +36,13 @@ export { JobStatus, type JobStatusProps, type JobFailure, type JobWords } from '
|
|
|
36
36
|
export { Thumbnail, ThumbnailSkeleton, type ThumbnailProps, type AspectRatio } from './components/thumbnail';
|
|
37
37
|
export { DataTable, TableSkeleton, parseSort, serialiseSort, type CellValue, type Column, type Sort, type DataTableProps, type RowSelection, type RowExpansion, } from './components/data-table';
|
|
38
38
|
export { MediaPlayer, useMediaElement, useAttachedSource, SPEECH_RATES, type MediaPlayerProps, type MediaElementState, type MediaElementOptions, type MediaWindow, type StreamContext, type StreamAttachment, type SourceAttacher, type MediaProblem, type MediaSource, type MediaSession } from './components/media-player';
|
|
39
|
+
export { useMediaSpans, SpanActions, type MediaSpanData, type SpanKind, type SpanBehaviour, type SpanOutcome, type SpanWords, type MediaSpansState } from './components/media-spans';
|
|
39
40
|
export { TranscriptView, type TranscriptViewProps, type TranscriptSeek } from './components/transcript-view';
|
|
40
41
|
export { phraseAt, wordAt, type TranscriptGroup, type TranscriptPhrase, type TranscriptWord } from './lib/transcript';
|
|
41
42
|
export { Waveform, type WaveformProps, type WaveformMark, type WaveformMarkKind, type WaveformSpan, type WaveformTone } from './components/waveform';
|
|
42
43
|
export { resamplePeaks, toPeakPair, peaksFromAudio, type WaveformPeaks, type PeakPair, type DecodedAudio } from './lib/waveform';
|
|
43
44
|
export { MediaGroup, PlayWindowButton, joinMediaGroup, type PlayWindowButtonProps } from './components/media-group';
|
|
44
|
-
export { Transport, TimeReadout, SeekBar, VolumeControl, RateChoice, MediaStage, StageGuides, transportShortcuts, type TransportProps, type SeekBarProps, type VolumeControlProps, type Precision } from './components/media';
|
|
45
|
+
export { Transport, TimeReadout, SeekBar, VolumeControl, RateChoice, MediaStage, StageGuides, transportShortcuts, type TransportProps, type SeekBarProps, type SeekBarSpan, type VolumeControlProps, type Precision } from './components/media';
|
|
45
46
|
export { Timeline, TimelineZoomControls, useTimelineZoom, noOverlap, type TimelineProps, type TimelineItem, type TimelineLane, type TimelineMarker, type TimelineChange, type TimelineDrop } from './components/timeline';
|
|
46
47
|
export { tickStep, ticksBetween, tickLabel } from './lib/timeline';
|
|
47
48
|
export { SortableList, type SortableListProps, type DropTarget } from './components/sortable-list';
|