strata-react 1.0.29 → 1.0.32

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 CHANGED
@@ -127,7 +127,7 @@ strata-react is ESM-only (`exports` has only `import`), as is its peer `react-ro
127
127
  | 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 |
128
128
  | 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 |
129
129
  | 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 |
130
- | Compare | `Compare`, `PairVote`, `PairJudge`, `CompareAudio`, `CompareText`, `CompareGrid`, `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. `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. Frame stepping, loops, regions and the grid are the next changes |
130
+ | 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. `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. 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 |
131
131
  | 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 |
132
132
  | 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 |
133
133
  | Data loading | `StrataQueryProvider`, `createQueryClient`, `useLoad`, `useInfiniteLoad`, `useJob`, `toLoad`, `staleOf`, `fetchJson`, `HttpError`, `readErrorBody`, `fieldErrorsOf` | TanStack Query in, `Load<T>` out; a refetch that fails after a good read stays `ready` with `stale` set, never an error panel; `useInfiniteLoad` works out the cursor itself (after the last item held), merges pages by key and can `dismiss` an item at once; `useJob` polls a job's status only while it runs and invalidates the queries it changes once, when it ends; `fetchJson` reads an error response's body onto the `HttpError` (`body`, `reason`, `fieldErrors`, read by `readErrorBody` or the API's own `readError`) |
@@ -144,7 +144,7 @@ strata-react is ESM-only (`exports` has only `import`), as is its peer `react-ro
144
144
  | 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` |
145
145
  | 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 |
146
146
  | 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` |
147
- | Maps | `strata-react/map`: `RouteMap`; `geo`, `LatLng` (main entry) | Routes and a position that moves along them, on Leaflet (no react-leaflet), behind its own entry. Tiles are the app's (`tiles.light`, `tiles.dark`, each with its attribution); the dark scheme uses the dark set or a filter over the light one. Route colours are roles resolved at draw time; `values` with `colourScale` colour a route by value in runs of one step, with a key that names the steps; a single route gets direction chevrons and start/finish marks (a loop is one mark). The position is one marker moved with `setLatLng`: no route is redrawn for it (keep `routes` stable). Leaflet's keyboard pan and zoom stay; the map is named by `label` and described by a generated text alternative (routes, lengths, position along). Overlay slots `topEnd` and `bottomStart` avoid Leaflet's own controls and attribution. Leaflet's stylesheet is injected once, so an app imports nothing. `geo` (distance, bearing, bounds, `pointAlong`, `arrows`, `ends`) and `format.distance` need no map library |
147
+ | Maps | `strata-react/map`: `RouteMap`; `geo`, `LatLng` (main entry) | Routes and a position that moves along them, on Leaflet (no react-leaflet), behind its own entry. Tiles are the app's (`tiles.light`, `tiles.dark`, each with its attribution); the dark scheme uses the dark set or a filter over the light one. Route colours are roles resolved at draw time; `values` with `colourScale` colour a route by value in runs of one step, with a key that names the steps; a single route gets direction chevrons and start/finish marks (a loop is one mark). The position is one marker moved with `setLatLng`: no route is redrawn for it (keep `routes` stable). As picture content (a route inset over footage): `zoom` sets any zoom (animate it per frame), `follow="centre"` holds the view exactly on a position with no animation (a frame is deterministic), and `positions` draws several, each tied to a route, in its colour and named in the text alternative; routes are not redrawn for any of it. Leaflet's keyboard pan and zoom stay; the map is named by `label` and described by a generated text alternative (routes, lengths, position along). Overlay slots `topEnd` and `bottomStart` avoid Leaflet's own controls and attribution. Leaflet's stylesheet is injected once, so an app imports nothing. `geo` (distance, bearing, bounds, `pointAlong`, `arrows`, `ends`) and `format.distance` need no map library |
148
148
  | Timeline | `Timeline`, `useTimelineZoom`, `TimelineZoomControls`, `noOverlap` | Items with a start and a length in lanes on a zoomable time axis, for media edits, bookings, rotas and plans. The timeline draws and the app decides: every move, trim, lane change, selection and current-time change is reported (`onItemChange`, `onSelect`, `onPositionChange`) and the app applies it; `validate` refuses a change with a reason shown in words while it is made. One tab stop for the items; arrows move between them, Ctrl+arrows nudge and change lane, Alt+arrows trim, the current time is its own slider, `+` `-` `0` zoom, and each change is announced ("run-02.mp4 moved to 0:13"). The ruler picks steps people write on a scale so labels never collide. Lanes take drops from outside (`dropTypes`, `onDrop` with the lane and snapped time, `validateDrop`, and React Aria's keyboard drag landing at the current time), `laneRows` makes them taller, `kindColours` fixes each kind's stripe, and the header column fits its content. Only items near the view are rendered |
149
149
  | Sortable list | `SortableList` | Reorder a list and move items between lists, by pointer and by keyboard. React Aria's `GridList` with `useDragAndDrop` (no `@dnd-kit`): a grip per row is the drag handle, so clicking a row selects it and its own actions still work; Enter on the grip picks up, arrows and Tab choose a position or list, Enter drops, Escape cancels, with React Aria's screen-reader announcements. Items carry a kind (`getKind`); a list takes the kinds in `accepts` and says why it refuses another (`refuses`, shown with an icon while that kind is dragged over it). The list never changes the data: `onReorder` and `onInsert` report the move and the app applies it, undoably |
150
150
  | File intake | `FileButton`, `FileDropZone`, `FileOutcomes`, `MissingFile`, `useFileIntake` | Pick or drop local files, then one outcome per file. `FileButton` is React Aria's `FileTrigger` behind a real named button (the keyboard and phone route); `FileDropZone` is its `DropZone` and says what it takes while a drag is over it. `useFileIntake({ accept, acceptLabel, process })` judges each file after the drop, so a wrong one is named with its reason (type, `maxBytes`, your `check`), runs your own `process` per file (a throw becomes `Failed` with its message and a retry), and never blocks the rest. `FileOutcomes` draws the rows and announces one summary per batch. `MissingFile` is a status word and a "Relink" that opens the picker for that item; the name wraps in a narrow pane and a `thumbnail` can lead it. Nothing assumes a server |
@@ -1,4 +1,5 @@
1
1
  import { Candidate } from './compare';
2
+ import { Region } from '../lib/viewport';
2
3
  import * as React from "react";
3
4
  /** Props for `CompareGrid`. */
4
5
  export type CompareGridProps = {
@@ -13,9 +14,11 @@ export type CompareGridProps = {
13
14
  actions?: (item: Candidate) => React.ReactNode;
14
15
  /** Tiles per row at full width. Default 3. A narrow screen uses fewer. */
15
16
  columns?: 2 | 3 | 4;
17
+ /** Named boxes to look at enlarged in every tile at once, as in `Compare`: chips, keys `q` `w` `e` `r` `y` `u`, nearest-neighbour while one is shown, Shift-drag to make another. */
18
+ regions?: readonly Region[];
16
19
  /** Bind the zoom and full-screen keys on the window. Default true. */
17
20
  keys?: boolean;
18
21
  className?: string;
19
22
  };
20
23
  /** Many pictures in a grid, zoomed and panned together, and full screen. */
21
- export declare function CompareGrid({ label, items, blind, missing, actions, columns, keys, className }: CompareGridProps): React.JSX.Element;
24
+ export declare function CompareGrid({ label, items, blind, missing, actions, columns, regions, keys, className }: CompareGridProps): React.JSX.Element;
@@ -9,12 +9,13 @@ export declare function Caption({ c, blind }: {
9
9
  blind: boolean;
10
10
  }): React.JSX.Element;
11
11
  /** One picture inside a frame: a skeleton while it loads, the product's words if it fails. */
12
- export declare function Picture({ c, blind, missing, onNatural, imgRef }: {
12
+ export declare function Picture({ c, blind, missing, onNatural, imgRef, pixelated }: {
13
13
  c: Candidate;
14
14
  blind: boolean;
15
15
  missing: string;
16
16
  onNatural?: (w: number, h: number) => void;
17
17
  imgRef?: React.Ref<HTMLImageElement>;
18
+ pixelated?: boolean;
18
19
  }): React.JSX.Element;
19
20
  type ZoomProps = {
20
21
  viewport: Viewport;
@@ -43,4 +44,6 @@ export declare function FullscreenButton({ full, setFull }: {
43
44
  full: boolean;
44
45
  setFull: (f: boolean) => void;
45
46
  }): React.JSX.Element;
47
+ /** The width of an element, kept current: for "is this shown larger than its own pixels". */
48
+ export declare function useWidth(ref: React.RefObject<HTMLElement | null>): number;
46
49
  export {};
@@ -0,0 +1,37 @@
1
+ import { Region, ShareBox, Viewport } from '../lib/viewport';
2
+ import { Shortcut } from './hotkeys';
3
+ import * as React from "react";
4
+ /** What a view needs to show regions. */
5
+ export type RegionState = {
6
+ /** The given regions, then the ones drawn by hand. */
7
+ regions: readonly Region[];
8
+ /** The chosen region's id, `null` for the whole frame or any other zoom. */
9
+ active: string | null;
10
+ /** Choose a region (fill the frame with it) or `null` for the whole frame. */
11
+ choose: (id: string | null) => void;
12
+ /** Wrap the view's own `setViewport`, so a zoom or pan by hand clears the chosen region. */
13
+ setViewport: (next: Viewport) => void;
14
+ /** A box drawn by hand, as a new region. */
15
+ add: (rect: {
16
+ x0: number;
17
+ y0: number;
18
+ x1: number;
19
+ y1: number;
20
+ }) => void;
21
+ /** The box to outline on the whole frame (the chip being pointed at). */
22
+ peek: ShareBox | null;
23
+ setPeek: (id: string | null) => void;
24
+ shortcuts: Shortcut[];
25
+ };
26
+ /** Regions for one item: `reset` is a key that changes with the item, which drops the regions drawn by hand. */
27
+ export declare function useRegions({ regions, viewport, setViewport, frame, reset }: {
28
+ regions?: readonly Region[];
29
+ viewport: Viewport;
30
+ setViewport: (v: Viewport) => void;
31
+ frame: React.RefObject<HTMLElement | null>;
32
+ reset: string;
33
+ }): RegionState;
34
+ /** The chip strip: the whole frame and each region, one chosen. Renders nothing when there are no regions. */
35
+ export declare function RegionChips({ state }: {
36
+ state: RegionState;
37
+ }): React.JSX.Element | null;
@@ -0,0 +1,48 @@
1
+ import { Region } from '../lib/viewport';
2
+ import { Candidate, VideoMedia } from './compare';
3
+ import { Shortcut } from './hotkeys';
4
+ import { VideoLoop } from './video-clock';
5
+ import * as React from "react";
6
+ /** Props for `CompareVideoGrid`. */
7
+ export type CompareVideoGridProps = {
8
+ /** Names the grid for screen readers: "Five upscales of this clip". Required. */
9
+ label: string;
10
+ items: readonly Candidate<VideoMedia>[];
11
+ /** The source clip, drawn first and never blind, scaled up nearest-neighbour. Give its `label` ("Source"); its `note` shows. */
12
+ reference?: Candidate<VideoMedia>;
13
+ /** Whether the person must not learn which variant is which: cells are named by label only. Required, no default. */
14
+ blind: boolean;
15
+ /** The words shown where a video could not be loaded. Required. */
16
+ missing: string;
17
+ /** The words under a cell that has fallen behind the clock. Default "Catching up". */
18
+ catchingUp?: string;
19
+ /** What goes under a cell's caption: a button to compare it, a choice, a flag. */
20
+ actions?: (item: Candidate<VideoMedia>) => React.ReactNode;
21
+ /** Cells per row at full width. Default 3. A narrow screen uses fewer. */
22
+ columns?: 2 | 3 | 4;
23
+ /** Named boxes to look at enlarged in every cell at once, as in `Compare`. */
24
+ regions?: readonly Region[];
25
+ /** Speeds offered. Default 0.1 to 2. */
26
+ rates?: readonly number[];
27
+ /** Moments the app names, drawn on the seek bar; pressing one goes there and pauses. */
28
+ moments?: readonly {
29
+ time: number;
30
+ label: string;
31
+ }[];
32
+ /** The looped range in seconds; give it with `onLoopChange` to keep it when the item changes. */
33
+ loop?: VideoLoop;
34
+ onLoopChange?: (loop: VideoLoop) => void;
35
+ /** The `id` of the cell whose sound is heard. Default none: eight soundtracks at once are noise. */
36
+ audio?: string | null;
37
+ /** Draw nearest-neighbour when a video is shown larger than its own pixels (`zoomed`, default), always, or never. */
38
+ pixelated?: "zoomed" | "always" | "never";
39
+ /** Bind the keys on the window. Default true. */
40
+ keys?: boolean;
41
+ /** Shortcuts of the surrounding screen, bound with these and listed first in the same legend. */
42
+ extraShortcuts?: Shortcut[];
43
+ /** Drawn under the transport, above the legend. */
44
+ footer?: React.ReactNode;
45
+ className?: string;
46
+ };
47
+ /** Many videos in a grid on one clock, zoomed and panned together, with regions, a loop, stepping and full screen. */
48
+ export declare function CompareVideoGrid({ label, items, reference, blind, missing, catchingUp, actions, columns, regions, rates, moments, loop, onLoopChange, audio, pixelated, keys, extraShortcuts, footer, className }: CompareVideoGridProps): React.JSX.Element;
@@ -1,8 +1,11 @@
1
1
  import { Shortcut } from './hotkeys';
2
2
  import { Candidate, CompareMode, VideoMedia } from './compare';
3
+ import { VideoLoop } from './video-clock';
4
+ import { Region } from '../lib/viewport';
3
5
  import * as React from "react";
4
6
  /** The views a pair of videos has: pictures' views without the difference, which needs pixels. */
5
7
  export type VideoMode = Exclude<CompareMode, "difference">;
8
+ export type { VideoLoop };
6
9
  /** Props for `CompareVideo`. */
7
10
  export type CompareVideoProps = {
8
11
  /** Names the comparison for screen readers. Required. */
@@ -15,6 +18,18 @@ export type CompareVideoProps = {
15
18
  missing: string;
16
19
  mode: VideoMode;
17
20
  onModeChange: (mode: VideoMode) => void;
21
+ /** Speeds offered. Default 0.1, 0.25, 0.5, 1, 1.25, 1.5, 2: slow motion for sitting on a moment. */
22
+ rates?: readonly number[];
23
+ /** Moments the app names ("fast motion"), drawn on the seek bar; pressing one goes there and pauses. */
24
+ moments?: readonly {
25
+ time: number;
26
+ label: string;
27
+ }[];
28
+ /** The looped range in seconds, `null` for an end not set. Give it (with `onLoopChange`) to keep the range when the pair changes to another of the same item. Without it the component keeps its own. */
29
+ loop?: VideoLoop;
30
+ onLoopChange?: (loop: VideoLoop) => void;
31
+ /** Named boxes to look at enlarged, as in `Compare`, on the same clock; a box drawn by hand (Shift-drag) is for a paused clip. Nearest-neighbour while one is shown. */
32
+ regions?: readonly Region[];
18
33
  /** Which video's sound is heard; the other is muted. Default "a". */
19
34
  audio?: "a" | "b" | "none";
20
35
  /** Draw nearest-neighbour when shown larger than the video's own pixels (`zoomed`, default), always, or never. */
@@ -30,4 +45,4 @@ export type CompareVideoProps = {
30
45
  className?: string;
31
46
  };
32
47
  /** Two videos to judge by eye on one clock: side by side, swipe, fade or blink, zoomed together, with matched sound and full screen. */
33
- export declare function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, audio, pixelated, maxHeight, keys, extraShortcuts, footer, className }: CompareVideoProps): React.JSX.Element;
48
+ export declare function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, rates, regions, moments, loop: loopProp, onLoopChange, audio, pixelated, maxHeight, keys, extraShortcuts, footer, className }: CompareVideoProps): React.JSX.Element;
@@ -1,5 +1,6 @@
1
1
  import { Shortcut } from './hotkeys';
2
2
  import { ReadPixels } from './difference';
3
+ import { Region } from '../lib/viewport';
3
4
  import * as React from "react";
4
5
  /** A picture to compare. */
5
6
  export type ImageMedia = {
@@ -66,6 +67,8 @@ export type CompareProps = {
66
67
  modes?: readonly CompareMode[];
67
68
  /** How tall a frame may be, so the pair and the answer fit on one screen: a CSS length (`"60svh"`) or `"viewport"` (the window's height less room for the toolbar, captions, a vote bar and the key legend). The frame narrows to keep the picture's shape. Default: as tall as the width makes it. */
68
69
  maxHeight?: string;
70
+ /** Named boxes in the source's coordinates to look at enlarged: a strip of chips, keys `q` `w` `e` `r` `y` `u`, nearest-neighbour drawing while one is shown, and Shift-drag to make another. They work in every view. The same share of each side is shown, whatever its pixel size. Label them by content ("Face"), never by candidate. */
71
+ regions?: readonly Region[];
69
72
  /** Bind the view, zoom and full-screen keys on the window. Default true; turn off when a surrounding screen binds the same keys. */
70
73
  keys?: boolean;
71
74
  /** Shortcuts of the surrounding screen (the answer keys of a `PairVote`), bound with Compare's own and drawn in the same legend, so there is one list and the two cannot clash unseen. Listed first. */
@@ -75,4 +78,4 @@ export type CompareProps = {
75
78
  className?: string;
76
79
  };
77
80
  /** Two pictures to judge, side by side or laid over each other, zoomed and panned together, and full screen. */
78
- export declare function Compare({ label, a, b, blind, missing, mode, onModeChange, modes, keys, extraShortcuts, footer, maxHeight, cannotCompare, readPixels, defaultDifference, className }: CompareProps): React.JSX.Element;
81
+ export declare function Compare({ label, a, b, blind, missing, mode, onModeChange, modes, regions, keys, extraShortcuts, footer, maxHeight, cannotCompare, readPixels, defaultDifference, className }: CompareProps): React.JSX.Element;
@@ -23,6 +23,11 @@ export type SeekBarProps = TimeProps & {
23
23
  time: number;
24
24
  label: string;
25
25
  }[];
26
+ /** 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. */
27
+ onMarkPress?: (mark: {
28
+ time: number;
29
+ label: string;
30
+ }) => void;
26
31
  /** How far has loaded or been recorded, drawn behind the played part. */
27
32
  buffered?: number;
28
33
  /** Arrow key step in seconds. Default 5. */
@@ -34,7 +39,7 @@ export type SeekBarProps = TimeProps & {
34
39
  className?: string;
35
40
  };
36
41
  /** A seek bar: dragged, clicked and moved by keys (arrows `step`, Page keys `bigStep`, Home and End), with its time as the accessible value. */
37
- export declare function SeekBar({ time, duration: known, onSeek, marks, buffered, step, bigStep, label, precision, fps, disabled: off, className }: SeekBarProps): React.JSX.Element;
42
+ export declare function SeekBar({ time, duration: known, onSeek, marks, onMarkPress, buffered, step, bigStep, label, precision, fps, disabled: off, className }: SeekBarProps): React.JSX.Element;
38
43
  export type TransportProps = {
39
44
  playing: boolean;
40
45
  onPlayPause: () => void;
@@ -0,0 +1,60 @@
1
+ import { Shortcut } from './hotkeys';
2
+ import * as React from "react";
3
+ /** A range to loop, in seconds of the clip; the same seconds in every video. */
4
+ export type VideoLoop = {
5
+ start: number | null;
6
+ end: number | null;
7
+ };
8
+ /** Speeds offered by default: slow motion for sitting on a moment. */
9
+ export declare const SLOW_RATES: readonly [0.1, 0.25, 0.5, 1, 1.25, 1.5, 2];
10
+ /** Options for `useVideoClock`. */
11
+ export type VideoClockOptions = {
12
+ /** Frames per second of the leader: the unit of the sync tolerance and of a step. */
13
+ fps: number;
14
+ loop?: VideoLoop;
15
+ onLoopChange?: (loop: VideoLoop) => void;
16
+ /** The index of the video whose sound is heard; none when `null`. */
17
+ audio: number | null;
18
+ };
19
+ /** The clock and everything a transport needs. */
20
+ export type VideoClock = ReturnType<typeof useVideoClock>;
21
+ /** Plays, pauses, seeks, steps and loops any number of videos together. */
22
+ export declare function useVideoClock({ fps, loop: loopProp, onLoopChange, audio }: VideoClockOptions): {
23
+ attach: (index: number) => (el: HTMLVideoElement | null) => void;
24
+ restore: (e: React.SyntheticEvent<HTMLVideoElement>) => void;
25
+ wanted: boolean;
26
+ started: boolean;
27
+ play: () => void;
28
+ pause: () => void;
29
+ toggle: () => void;
30
+ seek: (time: number) => void;
31
+ step: (direction: 1 | -1) => void;
32
+ setRate: (rate: number) => void;
33
+ time: number;
34
+ rate: number;
35
+ buffered: number;
36
+ duration: number | null;
37
+ loaded: boolean;
38
+ failed: boolean;
39
+ loop: VideoLoop;
40
+ looping: boolean;
41
+ setPoint: (point: "start" | "end") => void;
42
+ clearLoop: () => void;
43
+ volume: number;
44
+ muted: boolean;
45
+ setVolume: (v: number) => void;
46
+ behind: ReadonlySet<number>;
47
+ setVisible: (index: number, visible: boolean) => void;
48
+ shortcuts: () => Shortcut[];
49
+ hasAudio: boolean;
50
+ fps: number;
51
+ };
52
+ /** The transport row (play, step, time, seek bar with moments and the loop's ends, speed, volume) and the loop row, for a clock. */
53
+ export declare function VideoControls({ clock, rates, moments }: {
54
+ clock: VideoClock;
55
+ rates?: readonly number[];
56
+ moments?: readonly {
57
+ time: number;
58
+ label: string;
59
+ }[];
60
+ }): React.JSX.Element;
@@ -1,4 +1,4 @@
1
- import { Viewport } from '../lib/viewport';
1
+ import { ShareBox, Viewport } from '../lib/viewport';
2
2
  import * as React from "react";
3
3
  /** The caller's zoom and pan, and how to change them. */
4
4
  export type ViewportState = {
@@ -23,6 +23,15 @@ export type ViewportFrameProps = ViewportState & {
23
23
  overlay?: React.ReactNode;
24
24
  /** The tallest the frame may be, as a CSS length (`"60svh"`). The width follows, narrower than the space it has and centred, so the picture keeps its shape. Default: no limit, the frame is as tall as its width and aspect make it. */
25
25
  maxHeight?: string;
26
+ /** Shift-drag draws a rectangle on the frame and calls this with it when let go (pixels from the frame's top left). Without it Shift-drag does nothing special. */
27
+ onBox?: (rect: {
28
+ x0: number;
29
+ y0: number;
30
+ x1: number;
31
+ y1: number;
32
+ }) => void;
33
+ /** A box to outline on the whole picture (a region being pointed at), as shares of it. Drawn only while the picture is fitted. */
34
+ outline?: ShareBox | null;
26
35
  className?: string;
27
36
  };
28
37
  /** A clipped frame whose children zoom and pan together; the viewport is the caller's, so frames can share one. */
@@ -41,5 +50,14 @@ export declare const ViewportFrame: React.ForwardRefExoticComponent<ViewportStat
41
50
  overlay?: React.ReactNode;
42
51
  /** The tallest the frame may be, as a CSS length (`"60svh"`). The width follows, narrower than the space it has and centred, so the picture keeps its shape. Default: no limit, the frame is as tall as its width and aspect make it. */
43
52
  maxHeight?: string;
53
+ /** Shift-drag draws a rectangle on the frame and calls this with it when let go (pixels from the frame's top left). Without it Shift-drag does nothing special. */
54
+ onBox?: (rect: {
55
+ x0: number;
56
+ y0: number;
57
+ x1: number;
58
+ y1: number;
59
+ }) => void;
60
+ /** A box to outline on the whole picture (a region being pointed at), as shares of it. Drawn only while the picture is fitted. */
61
+ outline?: ShareBox | null;
44
62
  className?: string;
45
63
  } & React.RefAttributes<HTMLDivElement>>;
package/dist/index.d.ts CHANGED
@@ -64,10 +64,11 @@ export { describeActionError, fieldErrorsOf } from './lib/errors';
64
64
  export { Compare, type CompareProps, type CompareMode, type Candidate, type ImageMedia, type AudioMedia, type TextMedia, type VideoMedia } from './components/compare';
65
65
  export { ViewportFrame, useViewport, type ViewportFrameProps, type ViewportState } from './components/viewport';
66
66
  export { FullscreenFrame, canFullscreen, type FullscreenFrameProps } from './components/fullscreen-frame';
67
- export { FIT, MIN_SCALE, MAX_SCALE, clampViewport, zoomAt, actualPixelsScale, type Viewport } from './lib/viewport';
67
+ export { FIT, MIN_SCALE, MAX_SCALE, clampViewport, zoomAt, actualPixelsScale, regionShares, boxViewport, type Viewport, type Region, type ShareBox } from './lib/viewport';
68
68
  export { PairVote, PairJudge, type PairVoteProps, type PairJudgeProps, type PairVoteSlot, type PairVoteWords, type PairAnswer, type Pair } from './components/pair-vote';
69
69
  export { CompareAudio, type CompareAudioProps } from './components/compare-audio';
70
- export { CompareVideo, type CompareVideoProps, type VideoMode } from './components/compare-video';
70
+ export { CompareVideoGrid, type CompareVideoGridProps } from './components/compare-video-grid';
71
+ export { CompareVideo, type CompareVideoProps, type VideoMode, type VideoLoop } from './components/compare-video';
71
72
  export { CompareText, type CompareTextProps } from './components/compare-text';
72
73
  export { diffWords, type TextDifference, type TextSegment } from './lib/text-diff';
73
74
  export { loudnessOf, matchGains, gainToVolume, measureLoudness, type Loudness } from './lib/loudness';