strata-react 1.0.29 → 1.0.31

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`, `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; the grid is the next change. `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`) |
@@ -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;
@@ -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;
@@ -1,8 +1,14 @@
1
1
  import { Shortcut } from './hotkeys';
2
2
  import { Candidate, CompareMode, VideoMedia } from './compare';
3
+ import { Region } from '../lib/viewport';
3
4
  import * as React from "react";
4
5
  /** The views a pair of videos has: pictures' views without the difference, which needs pixels. */
5
6
  export type VideoMode = Exclude<CompareMode, "difference">;
7
+ /** A range to loop, in seconds of the clip; the same seconds in both videos. */
8
+ export type VideoLoop = {
9
+ start: number | null;
10
+ end: number | null;
11
+ };
6
12
  /** Props for `CompareVideo`. */
7
13
  export type CompareVideoProps = {
8
14
  /** Names the comparison for screen readers. Required. */
@@ -15,6 +21,18 @@ export type CompareVideoProps = {
15
21
  missing: string;
16
22
  mode: VideoMode;
17
23
  onModeChange: (mode: VideoMode) => void;
24
+ /** Speeds offered. Default 0.1, 0.25, 0.5, 1, 1.25, 1.5, 2: slow motion for sitting on a moment. */
25
+ rates?: readonly number[];
26
+ /** Moments the app names ("fast motion"), drawn on the seek bar; pressing one goes there and pauses. */
27
+ moments?: readonly {
28
+ time: number;
29
+ label: string;
30
+ }[];
31
+ /** 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. */
32
+ loop?: VideoLoop;
33
+ onLoopChange?: (loop: VideoLoop) => void;
34
+ /** 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. */
35
+ regions?: readonly Region[];
18
36
  /** Which video's sound is heard; the other is muted. Default "a". */
19
37
  audio?: "a" | "b" | "none";
20
38
  /** Draw nearest-neighbour when shown larger than the video's own pixels (`zoomed`, default), always, or never. */
@@ -30,4 +48,4 @@ export type CompareVideoProps = {
30
48
  className?: string;
31
49
  };
32
50
  /** 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;
51
+ 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;
@@ -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,10 @@ 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 { CompareVideo, type CompareVideoProps, type VideoMode, type VideoLoop } from './components/compare-video';
71
71
  export { CompareText, type CompareTextProps } from './components/compare-text';
72
72
  export { diffWords, type TextDifference, type TextSegment } from './lib/text-diff';
73
73
  export { loudnessOf, matchGains, gainToVolume, measureLoudness, type Loudness } from './lib/loudness';