strata-react 1.0.26 → 1.0.28

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`, `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. Pictures only so far: text, audio and video 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. Video is the next change |
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`) |
@@ -0,0 +1,30 @@
1
+ import { Loudness } from '../lib/loudness';
2
+ import { AudioMedia, Candidate } from './compare';
3
+ import { Shortcut } from './hotkeys';
4
+ import * as React from "react";
5
+ /** Props for `CompareAudio`. */
6
+ export type CompareAudioProps = {
7
+ /** Names the comparison for screen readers. Required. */
8
+ label: string;
9
+ a: Candidate<AudioMedia>;
10
+ b: Candidate<AudioMedia>;
11
+ /** Whether the person must not learn which clip is which. Required, no default. */
12
+ blind: boolean;
13
+ /** The words shown when a clip cannot be loaded: "Clip not found". Required. */
14
+ missing: string;
15
+ /** Turn the louder clip down to the quieter one. Default true. */
16
+ levelMatch?: boolean;
17
+ /** How a switch carries the playhead over: the same time, the same share of the clip, or by share when the lengths differ by more than 2%. Default "auto". */
18
+ align?: "time" | "proportion" | "auto";
19
+ /** Measures a clip's level. Default decodes it in the browser. */
20
+ measure?: (src: string) => Promise<Loudness>;
21
+ /** Bind the keys on the window. Default true. */
22
+ keys?: boolean;
23
+ /** Shortcuts of the surrounding screen, bound with these and listed first in the same legend. */
24
+ extraShortcuts?: Shortcut[];
25
+ /** Drawn under the controls, above the legend: where a vote bar goes. */
26
+ footer?: React.ReactNode;
27
+ className?: string;
28
+ };
29
+ /** Two clips to judge by ear: one transport, a switch that keeps the playhead, a loop, and matched levels. */
30
+ export declare function CompareAudio({ label, a, b, blind, missing, levelMatch, align, measure, keys, extraShortcuts, footer, className }: CompareAudioProps): React.JSX.Element;
@@ -0,0 +1,32 @@
1
+ import { Candidate, TextMedia } from './compare';
2
+ import { Shortcut } from './hotkeys';
3
+ import * as React from "react";
4
+ /** Props for `CompareText`. */
5
+ export type CompareTextProps = {
6
+ /** Names the comparison for screen readers. Required. */
7
+ label: string;
8
+ a: Candidate<TextMedia>;
9
+ b: Candidate<TextMedia>;
10
+ /** Whether the person must not learn which text is which. Required, no default. */
11
+ blind: boolean;
12
+ /** A ground-truth text, shown above both; the diff starts against it, and can be switched to the other candidate. */
13
+ reference?: {
14
+ label: string;
15
+ text: string;
16
+ };
17
+ /** Start with the word differences marked. Default false. */
18
+ defaultDiff?: boolean;
19
+ /** Said when the pair is too long to compare word by word. Default says so plainly. */
20
+ tooLong?: string;
21
+ /** Scroll the two panes together. Default true. */
22
+ linkedScroll?: boolean;
23
+ /** Bind the keys (`d` marks the differences) on the window. Default true. */
24
+ keys?: boolean;
25
+ /** Shortcuts of the surrounding screen (a `PairJudge`'s answer keys), bound with these and listed first in the same legend. */
26
+ extraShortcuts?: Shortcut[];
27
+ /** Drawn under the texts, above the legend: where a vote bar goes. */
28
+ footer?: React.ReactNode;
29
+ className?: string;
30
+ };
31
+ /** Two texts side by side with scrolling together, an optional reference, and a word diff on request. */
32
+ export declare function CompareText({ label, a, b, blind, reference, defaultDiff, tooLong, linkedScroll, keys, extraShortcuts, footer, className }: CompareTextProps): React.JSX.Element;
@@ -10,6 +10,16 @@ export type ImageMedia = {
10
10
  /** Its natural size in pixels, if known, so the frame has its shape and "1:1" is exact before the picture loads. */
11
11
  size?: readonly [number, number];
12
12
  };
13
+ /** A clip to compare by listening (`CompareAudio`). Serve it under a neutral address when the comparison is blind. */
14
+ export type AudioMedia = {
15
+ kind: "audio";
16
+ src: string;
17
+ };
18
+ /** A text to compare by reading (`CompareText`). */
19
+ export type TextMedia = {
20
+ kind: "text";
21
+ text: string;
22
+ };
13
23
  /** One side of a comparison. */
14
24
  export type Candidate<M = ImageMedia> = {
15
25
  /** Who it is: a variant name, a model. Never put on the page when `blind`, and never needed by it. */
@@ -42,6 +52,8 @@ export type CompareProps = {
42
52
  readPixels?: ReadPixels;
43
53
  /** Which views are offered. Default all five. Must include `mode`. */
44
54
  modes?: readonly CompareMode[];
55
+ /** 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. */
56
+ maxHeight?: string;
45
57
  /** Bind the view, zoom and full-screen keys on the window. Default true; turn off when a surrounding screen binds the same keys. */
46
58
  keys?: boolean;
47
59
  /** 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. */
@@ -51,4 +63,4 @@ export type CompareProps = {
51
63
  className?: string;
52
64
  };
53
65
  /** Two pictures to judge, side by side or laid over each other, zoomed and panned together, and full screen. */
54
- export declare function Compare({ label, a, b, blind, missing, mode, onModeChange, modes, keys, extraShortcuts, footer, cannotCompare, readPixels, defaultDifference, className }: CompareProps): React.JSX.Element;
66
+ export declare function Compare({ label, a, b, blind, missing, mode, onModeChange, modes, keys, extraShortcuts, footer, maxHeight, cannotCompare, readPixels, defaultDifference, className }: CompareProps): React.JSX.Element;
@@ -1,5 +1,6 @@
1
- import { Candidate, CompareProps } from './compare';
1
+ import { Candidate, CompareProps, ImageMedia } from './compare';
2
2
  import { Load } from './data-view';
3
+ import { Shortcut } from './hotkeys';
3
4
  import * as React from "react";
4
5
  /** One answer to a pair: a side, "about the same", "can't tell", or a flag with its reason. */
5
6
  export type PairAnswer = {
@@ -8,11 +9,16 @@ export type PairAnswer = {
8
9
  answer: "flag";
9
10
  reason: string;
10
11
  };
11
- /** A pair to judge. */
12
- export type Pair = {
12
+ /** A pair to judge: pictures by default, or any media a `view` draws (`CompareAudio`, `CompareText`). */
13
+ export type Pair<M = ImageMedia> = {
13
14
  label: string;
14
- a: Candidate;
15
- b: Candidate;
15
+ a: Candidate<M>;
16
+ b: Candidate<M>;
17
+ };
18
+ /** What `PairVote` hands a `view`: the answer keys for the view's legend and the vote bar for its footer. Pass both to `CompareAudio`, `CompareText` or your own. */
19
+ export type PairVoteSlot = {
20
+ extraShortcuts: Shortcut[];
21
+ footer: React.ReactNode;
16
22
  };
17
23
  /** Words for the vote bar, all in the product's voice. */
18
24
  export type PairVoteWords = {
@@ -27,10 +33,10 @@ export type PairVoteWords = {
27
33
  /** The flag menu's button. Default "Flag this pair". */
28
34
  flag?: string;
29
35
  };
30
- /** Props for `PairVote`. */
31
- export type PairVoteProps = Omit<CompareProps, "label" | "a" | "b" | "extraShortcuts" | "footer"> & {
36
+ /** What every pair judgment takes, whatever it draws. */
37
+ export type PairJudgeProps<M> = {
32
38
  /** The pair now being judged, as a read. */
33
- pair: Load<Pair | null>;
39
+ pair: Load<Pair<M> | null>;
34
40
  /** Mirrors the pictures and the bar while the pair loads. Required. */
35
41
  skeleton: React.ReactNode;
36
42
  /** What to show when there is nothing left to judge, and what to do next. Required. */
@@ -43,7 +49,7 @@ export type PairVoteProps = Omit<CompareProps, "label" | "a" | "b" | "extraShort
43
49
  progress?: React.ReactNode;
44
50
  /** Reasons the judge can give for setting a pair aside ("Picture missing", "Not the same scene"); no flag menu without them. */
45
51
  flagReasons?: readonly string[];
46
- /** Addresses of the next pairs' pictures, fetched ahead so the next pair is on screen the moment this one is answered. */
52
+ /** Addresses of the next pairs' pictures or clips, fetched ahead so the next pair is ready the moment this one is answered. */
47
53
  preload?: readonly string[];
48
54
  /** The answer just given: what it was, how to take it back, and what to show of the pair after (`reveal`, never during the judgment). */
49
55
  last?: {
@@ -52,6 +58,12 @@ export type PairVoteProps = Omit<CompareProps, "label" | "a" | "b" | "extraShort
52
58
  reveal?: React.ReactNode;
53
59
  };
54
60
  words?: PairVoteWords;
61
+ /** Draws the pair: `(slot, pair) => <CompareAudio {...pair} {...slot} blind missing=… />`. Pass the whole `slot` through so the answer keys share the view's legend and the bar sits in its footer. */
62
+ view: (slot: PairVoteSlot, pair: Pair<M>) => React.ReactNode;
55
63
  };
56
- /** A blind pairwise judgment: two pictures in `Compare`, answer keys in its legend, and a vote bar that never leans on either side. */
64
+ /** Props for `PairVote`: the pair judgment, drawn with `Compare`. */
65
+ export type PairVoteProps = Omit<PairJudgeProps<ImageMedia>, "view"> & Omit<CompareProps, "label" | "a" | "b" | "extraShortcuts" | "footer">;
66
+ /** A blind pairwise judgment of two pictures: `Compare`, answer keys in its legend, and a vote bar that never leans on either side. */
57
67
  export declare function PairVote({ pair, skeleton, empty, onAnswer, pending, progress, flagReasons, preload, last, words, ...compare }: PairVoteProps): React.JSX.Element;
68
+ /** A blind pairwise judgment of anything: the answer keys, vote bar, pending, flag menu, progress, preload and Undo around a `view` that draws the pair (`CompareAudio`, `CompareText`, your own). */
69
+ export declare function PairJudge<M>({ pair, skeleton, empty, onAnswer, pending, progress, flagReasons, preload, last, words, view }: PairJudgeProps<M>): React.JSX.Element;
@@ -21,6 +21,8 @@ export type ViewportFrameProps = ViewportState & {
21
21
  };
22
22
  /** Drawn over the frame, not zoomed with it: a divider to drag, a corner label. Its pointer, key and double-click events do not reach the frame, so using it never pans the picture. */
23
23
  overlay?: React.ReactNode;
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
+ maxHeight?: string;
24
26
  className?: string;
25
27
  };
26
28
  /** A clipped frame whose children zoom and pan together; the viewport is the caller's, so frames can share one. */
@@ -37,5 +39,7 @@ export declare const ViewportFrame: React.ForwardRefExoticComponent<ViewportStat
37
39
  };
38
40
  /** Drawn over the frame, not zoomed with it: a divider to drag, a corner label. Its pointer, key and double-click events do not reach the frame, so using it never pans the picture. */
39
41
  overlay?: React.ReactNode;
42
+ /** 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
+ maxHeight?: string;
40
44
  className?: string;
41
45
  } & React.RefAttributes<HTMLDivElement>>;
package/dist/index.d.ts CHANGED
@@ -61,11 +61,15 @@ export { useActiveItem, ActiveList, type ActiveItem } from './components/active-
61
61
  export { ThemeProvider, useColorScheme, useSystemColorScheme, ColorSchemeChoice, colorSchemeScript, COLOR_SCHEME_STORAGE_KEY, type ColorScheme, type ColorSchemePreference, type ColorSchemeLabels, type ColorSchemeState, } from './components/theme';
62
62
  export { StrataQueryProvider, createQueryClient, toLoad, staleOf, useLoad, useInfiniteLoad, useJob, fetchJson, HttpError, describeHttpError, readErrorBody, type DescribeError, type ErrorBody, type FetchJsonOptions, type InfiniteLoad, type InfiniteLoadOptions, type Job, type JobOptions, type More, } from './query';
63
63
  export { describeActionError, fieldErrorsOf } from './lib/errors';
64
- export { Compare, type CompareProps, type CompareMode, type Candidate, type ImageMedia } from './components/compare';
64
+ export { Compare, type CompareProps, type CompareMode, type Candidate, type ImageMedia, type AudioMedia, type TextMedia } 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
67
  export { FIT, MIN_SCALE, MAX_SCALE, clampViewport, zoomAt, actualPixelsScale, type Viewport } from './lib/viewport';
68
- export { PairVote, type PairVoteProps, type PairVoteWords, type PairAnswer, type Pair } from './components/pair-vote';
68
+ export { PairVote, PairJudge, type PairVoteProps, type PairJudgeProps, type PairVoteSlot, type PairVoteWords, type PairAnswer, type Pair } from './components/pair-vote';
69
+ export { CompareAudio, type CompareAudioProps } from './components/compare-audio';
70
+ export { CompareText, type CompareTextProps } from './components/compare-text';
71
+ export { diffWords, type TextDifference, type TextSegment } from './lib/text-diff';
72
+ export { loudnessOf, matchGains, gainToVolume, measureLoudness, type Loudness } from './lib/loudness';
69
73
  export { CompareGrid, type CompareGridProps } from './components/compare-grid';
70
74
  export { useDifference, type DifferenceState, type ReadPixels } from './components/difference';
71
75
  export { differences, readPixels, resample, MAX_SIDE, DEFAULT_TOLERANCE, type Difference, type Pixels } from './lib/image-diff';