strata-react 1.0.40 → 1.0.41

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
@@ -121,6 +121,30 @@ function KilnRoom() {
121
121
 
122
122
  strata-react is ESM-only (`exports` has only `import`), as is its peer `react-router`. **Vitest is the supported runner**: it needs no configuration beyond the `strata-react/testing` helpers. An app on Jest has to do the work itself (strata-vid's `jest.base.config.js` is a working example): transform `.mjs` along with `.js`; leave `strata-react`, `react-router`, `@remix-run`, `cookie-es`, `@tanstack` and `pixelmatch` out of `transformIgnorePatterns` so Babel compiles them; and replace `import.meta` for CommonJS with a small Babel plugin (react-router reads it). Strata's own suite runs on Vitest only, so a Jest setup is the app's to keep working.
123
123
 
124
+ ### An app that already has its own Tailwind colours and sizes
125
+
126
+ `strata.css` clears Tailwind's stock colours, type sizes, radii, shadows and fonts, so `bg-stone-100`, `text-sm`, `rounded-xl` and
127
+ `shadow-lg` stop compiling (even `@apply bg-stone-100` fails to build). That is right for a new app and a cliff for an app of
128
+ thousands of lines. Such an app imports the same stylesheet **without the reset** and moves screens over one at a time:
129
+
130
+ ```css
131
+ @import "tailwindcss";
132
+ @import "strata-react/strata.migrate.css"; /* everything in strata.css except the namespace reset */
133
+ @import "./theme.generated.css"; /* still needed: the roles Strata's components use (bg-primary, border-input…) */
134
+ @import "./theme.css";
135
+ ```
136
+
137
+ 1. Supply the roles. Generate the palette with `palette.mjs` as for a new app, or, to keep today's look, write the role variables
138
+ from the app's own colours (`:root { --primary: var(--color-emerald-600); --background: var(--color-stone-50); … }` and the
139
+ `@theme inline { --color-primary: var(--primary); … }` mapping `palette.mjs` writes: the stock `--color-*` variables still exist
140
+ in this mode). Turn on dark mode through `ThemeProvider`; the app's own `dark:` classes keep working beside it.
141
+ 2. Convert a screen at a time to Strata components and roles. `npx strata-stock-classes src` lists the stock classes left
142
+ (colours, `text-sm`…, `rounded-xl`…, `shadow-lg`…, `font-serif`) by file and line, with the role that replaces each;
143
+ `--fail` exits 1 while any remain, to hold the line in CI. It reads class names as text, so it is a list to work from.
144
+ 3. When it finds none, change the import to `strata-react/strata.css`. A new app starts there; use the migration import only
145
+ for an existing one. The integration suite checks that a stock class and a Strata component compile together in this mode,
146
+ and that the normal one still removes the stock ones.
147
+
124
148
  ## Components
125
149
 
126
150
  | Group | Exports | Notes |
@@ -129,7 +153,7 @@ strata-react is ESM-only (`exports` has only `import`), as is its peer `react-ro
129
153
  | 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
154
  | 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
155
  | 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
- | 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 |
156
+ | 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); `maxHeight="fit"` measures the window for the pair and its surroundings instead of the `"viewport"` guess; `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
157
  | Selection | `useSelection`, `useChoices`, `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. A choice can imply others: `implies(key)` (on `useSelection`, and `useChoices` for a lazy tree) keeps what the person chose apart from what that brings in, follows it through, locks the implied keys (they only clear with what implied them), and gives `implied`, `because(key)`, `counts`, a `note` for the live region and `summary(noun, then)`, the line a destructive confirm can carry ("12 results will be forgotten: 8 chosen, 4 that depend on them") |
134
158
  | 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 |
135
159
  | 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`) |
package/UPGRADING.md CHANGED
@@ -11,6 +11,12 @@ time. While the version is 0.x, any release may break.
11
11
 
12
12
  Every PR that changes what an app sees adds a line here (see `CLAUDE.md`, "Changelog").
13
13
 
14
+ ## After v1.0.40 (2026-11-13)
15
+
16
+ - Two `StrataToastRegion`s mounted at once no longer draw every toast twice: the first mounted draws and a second draws nothing (and warns in development, naming `renderRoutes(..., { toasts: false })`). A test that worked around the doubling with `findAllByText` can use `findByText`; an app with a region in a layout and another in a page loses the page's.
17
+ - Full screen on `Compare` and `CompareVideo` now fills what the controls leave (measured), whatever `maxHeight` was, where a caller's `maxHeight` used to cap it too, and where no `maxHeight` left the frame as tall as its width made it. New `maxHeight="fit"` and `reserve` measure the page; `"viewport"` is still the fixed guess.
18
+ - A picture that loads with no size (an SVG without one) no longer sets `Compare`'s aspect to NaN; the 3:2 box stays.
19
+
14
20
  ## After v1.0.39 (2026-11-13)
15
21
 
16
22
  - `Tree`'s props are now a union: give `selected` and `onSelect` (one chosen node) or `choices` from `useChoices` (several). Code that passed `selected` and `onSelect` compiles as before.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ // strata-stock-classes: list the stock Tailwind classes an app still uses (src/migrate/cli.ts, built into dist/).
3
+ import { main } from "../dist/migrate-cli.js";
4
+
5
+ process.exitCode = await main(process.argv.slice(2));
@@ -4,6 +4,31 @@ import { Candidate } from './compare';
4
4
  import { FramePick } from './viewport';
5
5
  import * as React from "react";
6
6
  export declare const VIEWPORT_HEIGHT = "max(16rem, calc(100svh - 14rem))";
7
+ /** The least a frame is made, however little room is left: a pair this small can still be told apart. */
8
+ export declare const MIN_FIT = 120;
9
+ /** The tallest each row of frames may be so that all of `chrome` and `rows` rows fit in `space` pixels. Pure, so it is tested without a layout. */
10
+ export declare function fitFrames({ space, chrome, rows, min }: {
11
+ space: number;
12
+ chrome: number;
13
+ rows: number;
14
+ min?: number;
15
+ }): number;
16
+ /** Frame cap for what the caller asked for: a measured height for `"fit"` and in full screen (whatever the caller passed, so the frame fills what the controls leave), the guess for `"viewport"`, the caller's own length otherwise. */
17
+ export declare function frameCap(maxHeight: string | undefined, fit: number | null, full: boolean): string | undefined;
18
+ /**
19
+ * How tall each frame may be for the pair and everything around it to fit the window (issue #229), measured, not
20
+ * guessed. In the page: the window's height from the top of `root` (as the page is at its top), less what `root` draws
21
+ * besides its frames (toolbar, captions, footer, legend: the bottom of its last child, not its height, which a stretched
22
+ * full-screen section would inflate), less what follows it (later siblings of it and of its ancestors, then `reserve` for
23
+ * padding and gaps the caller knows). In full screen: the window from the top of `root`, nothing after. Divided by the
24
+ * rows of frames (side by side is one row; below `sm` it is two) and floored at `MIN_FIT`. Frames are found by
25
+ * `data-viewport-frame`, so an app never queries for them. Null until measured, or when `enabled` is false.
26
+ */
27
+ export declare function useFitHeight(root: React.RefObject<HTMLElement | null>, { enabled, full, reserve }: {
28
+ enabled: boolean;
29
+ full: boolean;
30
+ reserve?: number;
31
+ }): number | null;
7
32
  /** Words for click to choose, in the product's voice. */
8
33
  export type PickWords = {
9
34
  /** What hovering a side says, and what the frame is described as: `(label) => "Click to choose " + label`. */
@@ -45,8 +45,10 @@ export type CompareVideoProps = {
45
45
  audio?: "a" | "b" | "none";
46
46
  /** Draw nearest-neighbour when shown larger than the video's own pixels (`zoomed`, default), always, or never. */
47
47
  pixelated?: "zoomed" | "always" | "never";
48
- /** How tall a frame may be: a CSS length or `"viewport"`, as in `Compare`. */
48
+ /** How tall a frame may be: a CSS length, `"viewport"` (a fixed guess) or `"fit"` (measured), as in `Compare`; full screen fills what the controls leave. */
49
49
  maxHeight?: string;
50
+ /** With `maxHeight="fit"`: pixels of the page below this that it cannot measure, as in `Compare`. Default 0. */
51
+ reserve?: number;
50
52
  /** Bind the keys on the window. Default true. */
51
53
  keys?: boolean;
52
54
  /** Shortcuts of the surrounding screen, bound with these and listed first in the same legend. */
@@ -56,4 +58,4 @@ export type CompareVideoProps = {
56
58
  className?: string;
57
59
  };
58
60
  /** Two videos to judge by eye on one clock: side by side, swipe, fade or blink, zoomed together, with matched sound and full screen. */
59
- export declare function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, rates, regions, moments, loop: loopProp, onLoopChange, audio, onPick, pick, pickWords, autoPlay, loopWhole, pixelated, maxHeight, keys, extraShortcuts, footer, className }: CompareVideoProps): React.JSX.Element;
61
+ export declare function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, rates, regions, moments, loop: loopProp, onLoopChange, audio, onPick, pick, pickWords, autoPlay, loopWhole, pixelated, maxHeight, reserve, keys, extraShortcuts, footer, className }: CompareVideoProps): React.JSX.Element;
@@ -66,8 +66,10 @@ export type CompareProps = {
66
66
  readPixels?: ReadPixels;
67
67
  /** Which views are offered. Default all five. Must include `mode`. */
68
68
  modes?: readonly CompareMode[];
69
- /** 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. */
69
+ /** How tall a frame may be, so the pair and the answer fit on one screen: a CSS length (`"60svh"`), `"viewport"` (the window's height less a fixed 14rem for the toolbar, captions, a vote bar and the key legend: a guess), or `"fit"` (measured: the window from the top of this component, less what it draws besides its frames and what follows it in the page, shared between the rows of frames, never under 120 px; re-measured as the page changes; see `reserve`). The frame narrows to keep the picture's shape. In full screen the frame fills what the controls leave, whatever this is. Default: as tall as the width makes it. */
70
70
  maxHeight?: string;
71
+ /** With `maxHeight="fit"`: pixels of the page below this component that it cannot measure (padding and gaps of the screen around it); later siblings are measured. Default 0. */
72
+ reserve?: number;
71
73
  /** 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. */
72
74
  regions?: readonly Region[];
73
75
  /** Called with the side clicked or tapped, in the views where a click is unambiguous: side by side, swipe (by the side of the divider) and blink (the side showing). A pointer convenience: the keys and the vote bar stay the way to answer. A `PairVote` sets this for you. */
@@ -85,4 +87,4 @@ export type CompareProps = {
85
87
  className?: string;
86
88
  };
87
89
  /** Two pictures to judge, side by side or laid over each other, zoomed and panned together, and full screen. */
88
- export declare function Compare({ label, a, b, blind, missing, mode, onModeChange, modes, regions, onPick, pick, pickWords, keys, extraShortcuts, footer, maxHeight, cannotCompare, readPixels, defaultDifference, className }: CompareProps): React.JSX.Element;
90
+ export declare function Compare({ label, a, b, blind, missing, mode, onModeChange, modes, regions, onPick, pick, pickWords, keys, extraShortcuts, footer, maxHeight, reserve, cannotCompare, readPixels, defaultDifference, className }: CompareProps): React.JSX.Element;
@@ -1,3 +1,4 @@
1
+ import * as React from "react";
1
2
  /** What a toast says. */
2
3
  export type ToastContentProps = {
3
4
  /** What finished, past tense, in the product's words: "Export finished". */
@@ -29,5 +30,5 @@ export type StrataToastRegionProps = {
29
30
  label?: string;
30
31
  className?: string;
31
32
  };
32
- /** The one place toasts appear. Render it once at the app root. A labelled landmark (F6), polite, above panes and the undo bar. */
33
- export declare function StrataToastRegion({ label, className }: StrataToastRegionProps): import('react').JSX.Element;
33
+ /** The one place toasts appear. Render it once at the app root; a second one mounted at the same time draws nothing and warns in development. A labelled landmark (F6), polite, above panes and the undo bar. */
34
+ export declare function StrataToastRegion({ label, className }: StrataToastRegionProps): React.JSX.Element | null;
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { a as Textarea, c as Tooltip, d as typeSteps, i as NativeSelect, l as Ke
2
2
  import { a as toDate, i as format, n as NBSP, r as createFormat, t as MISSING } from "./format-B32-PVi2.js";
3
3
  import { a as useAsyncAction, c as KeysLegend, d as useInView, i as AsyncButton, l as isTypingTarget, n as NumberField, o as Toolbar, r as Slider, s as ToolbarSeparator, t as ColorField, u as useHotkeys } from "./value-controls-FO4zQiHP.js";
4
4
  import { a as readErrorBody, c as RowAction, i as fieldErrorsOf, l as buttonVariants, n as describeActionError, o as Button, r as describeHttpError, s as IconButton, t as HttpError } from "./errors-BunUBqpA.js";
5
- import { a as toLoad, c as toast, i as staleOf, l as toastTimeout, n as createQueryClient, o as useLoad, r as fetchJson, s as StrataToastRegion, t as StrataQueryProvider, u as overlaySurface } from "./query-D163gXXZ.js";
5
+ import { a as toLoad, c as toast, i as staleOf, l as toastTimeout, n as createQueryClient, o as useLoad, r as fetchJson, s as StrataToastRegion, t as StrataQueryProvider, u as overlaySurface } from "./query-B934ufsW.js";
6
6
  import { n as useSharedCursor, r as geo, t as CursorScope } from "./cursor-DDGBPiTJ.js";
7
7
  import { a as useColorScheme, i as colorSchemeScript, n as ColorSchemeChoice, o as useSystemColorScheme, r as ThemeProvider, s as Density, t as COLOR_SCHEME_STORAGE_KEY } from "./theme-DVaIxyNn.js";
8
8
  import * as React from "react";
@@ -8287,6 +8287,98 @@ function frameBoxToShares(rect, v, frame) {
8287
8287
  }
8288
8288
  // src/components/compare-parts.tsx
8289
8289
  var VIEWPORT_HEIGHT = "max(16rem, calc(100svh - 14rem))";
8290
+ /** The tallest each row of frames may be so that all of `chrome` and `rows` rows fit in `space` pixels. Pure, so it is tested without a layout. */
8291
+ function fitFrames({ space, chrome, rows, min = 120 }) {
8292
+ return Math.max(min, Math.floor((space - chrome) / Math.max(1, rows)));
8293
+ }
8294
+ /** Frame cap for what the caller asked for: a measured height for `"fit"` and in full screen (whatever the caller passed, so the frame fills what the controls leave), the guess for `"viewport"`, the caller's own length otherwise. */
8295
+ function frameCap(maxHeight, fit, full) {
8296
+ if ((maxHeight === "fit" || full) && fit !== null) return `${fit}px`;
8297
+ return maxHeight === "viewport" || maxHeight === "fit" ? VIEWPORT_HEIGHT : maxHeight;
8298
+ }
8299
+ /**
8300
+ * How tall each frame may be for the pair and everything around it to fit the window (issue #229), measured, not
8301
+ * guessed. In the page: the window's height from the top of `root` (as the page is at its top), less what `root` draws
8302
+ * besides its frames (toolbar, captions, footer, legend: the bottom of its last child, not its height, which a stretched
8303
+ * full-screen section would inflate), less what follows it (later siblings of it and of its ancestors, then `reserve` for
8304
+ * padding and gaps the caller knows). In full screen: the window from the top of `root`, nothing after. Divided by the
8305
+ * rows of frames (side by side is one row; below `sm` it is two) and floored at `MIN_FIT`. Frames are found by
8306
+ * `data-viewport-frame`, so an app never queries for them. Null until measured, or when `enabled` is false.
8307
+ */
8308
+ function useFitHeight(root, { enabled, full, reserve = 0 }) {
8309
+ const [fit, setFit] = React.useState(null);
8310
+ React.useLayoutEffect(() => {
8311
+ if (!enabled) {
8312
+ setFit(null);
8313
+ return;
8314
+ }
8315
+ const el = root.current;
8316
+ if (!el) return;
8317
+ const measure = () => {
8318
+ const frames = [...el.querySelectorAll("[data-viewport-frame]")].map((f) => f.getBoundingClientRect());
8319
+ if (!frames.length) return;
8320
+ const top = el.getBoundingClientRect().top;
8321
+ const rows = [];
8322
+ for (const r of frames) {
8323
+ const row = rows.find((x) => Math.abs(x.top - r.top) < 2);
8324
+ if (row) row.height = Math.max(row.height, r.height);
8325
+ else rows.push({
8326
+ top: r.top,
8327
+ height: r.height
8328
+ });
8329
+ }
8330
+ const chrome = Math.max(el.lastElementChild?.getBoundingClientRect().bottom ?? 0, ...frames.map((r) => r.bottom)) - top - rows.reduce((sum, r) => sum + r.height, 0);
8331
+ const windowHeight = document.documentElement.clientHeight;
8332
+ let space;
8333
+ if (full) {
8334
+ const pad = el.parentElement ? parseFloat(getComputedStyle(el.parentElement).paddingBottom) || 0 : 0;
8335
+ space = windowHeight - top - pad;
8336
+ } else {
8337
+ let after = 0;
8338
+ for (let n = el; n && n !== document.body; n = n.parentElement) for (let sib = n.nextElementSibling; sib; sib = sib.nextElementSibling) {
8339
+ const position = getComputedStyle(sib).position;
8340
+ if (position !== "fixed" && position !== "absolute") after += sib.getBoundingClientRect().height;
8341
+ }
8342
+ space = windowHeight - (top + window.scrollY) - after - reserve;
8343
+ }
8344
+ const next = fitFrames({
8345
+ space,
8346
+ chrome,
8347
+ rows: rows.length
8348
+ });
8349
+ setFit((was) => was !== null && Math.abs(was - next) <= 1 ? was : next);
8350
+ };
8351
+ let frame = 0;
8352
+ const schedule = () => {
8353
+ cancelAnimationFrame(frame);
8354
+ frame = requestAnimationFrame(measure);
8355
+ };
8356
+ measure();
8357
+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedule);
8358
+ observer?.observe(el);
8359
+ observer?.observe(document.body);
8360
+ const changes = new MutationObserver(schedule);
8361
+ changes.observe(el, {
8362
+ childList: true,
8363
+ subtree: true
8364
+ });
8365
+ window.addEventListener("resize", schedule);
8366
+ document.addEventListener("fullscreenchange", schedule);
8367
+ return () => {
8368
+ cancelAnimationFrame(frame);
8369
+ observer?.disconnect();
8370
+ changes.disconnect();
8371
+ window.removeEventListener("resize", schedule);
8372
+ document.removeEventListener("fullscreenchange", schedule);
8373
+ };
8374
+ }, [
8375
+ root,
8376
+ enabled,
8377
+ full,
8378
+ reserve
8379
+ ]);
8380
+ return fit;
8381
+ }
8290
8382
  /** What a pair's frames do with a click (issue #201): the same answer as the keys, only where a click is unambiguous. Blind: only a candidate's `label` is ever said. */
8291
8383
  function makePicker(a, b, onPick, words) {
8292
8384
  const choose = words?.choose ?? ((label) => `Click to choose ${label}`);
@@ -8373,7 +8465,7 @@ function Picture({ c, blind, missing, onNatural, imgRef, pixelated }) {
8373
8465
  style: pixelated ? { imageRendering: "pixelated" } : void 0,
8374
8466
  onLoad: (e) => {
8375
8467
  setState("ready");
8376
- onNatural?.(e.currentTarget.naturalWidth, e.currentTarget.naturalHeight);
8468
+ if (e.currentTarget.naturalWidth && e.currentTarget.naturalHeight) onNatural?.(e.currentTarget.naturalWidth, e.currentTarget.naturalHeight);
8377
8469
  },
8378
8470
  onError: () => setState("failed"),
8379
8471
  className: "absolute inset-0 size-full object-contain"
@@ -8723,6 +8815,7 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
8723
8815
  return /* @__PURE__ */ jsxs("div", {
8724
8816
  ref,
8725
8817
  role: "group",
8818
+ "data-viewport-frame": "",
8726
8819
  "aria-label": label,
8727
8820
  "aria-roledescription": "zoomable picture",
8728
8821
  tabIndex: 0,
@@ -9034,7 +9127,7 @@ var ALL_MODES = [
9034
9127
  "difference"
9035
9128
  ];
9036
9129
  /** Two pictures to judge, side by side or laid over each other, zoomed and panned together, and full screen. */
9037
- function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_MODES, regions, onPick, pick = true, pickWords, keys = true, extraShortcuts = [], footer, maxHeight, cannotCompare = "Could not read these pictures to compare their pixels.", readPixels, defaultDifference = "brightness", className }) {
9130
+ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_MODES, regions, onPick, pick = true, pickWords, keys = true, extraShortcuts = [], footer, maxHeight, reserve, cannotCompare = "Could not read these pictures to compare their pixels.", readPixels, defaultDifference = "brightness", className }) {
9038
9131
  const { viewport, setViewport } = useViewport();
9039
9132
  const [full, setFull] = React.useState(false);
9040
9133
  const pairKey = `${a.media.src}|${b.media.src}`;
@@ -9050,6 +9143,12 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
9050
9143
  const frameRef = React.useRef(null);
9051
9144
  const imgRef = React.useRef(null);
9052
9145
  const aspect = natural ? natural[0] / natural[1] : 3 / 2;
9146
+ const sectionRef = React.useRef(null);
9147
+ const fit = useFitHeight(sectionRef, {
9148
+ enabled: maxHeight === "fit" || full,
9149
+ full,
9150
+ reserve
9151
+ });
9053
9152
  const rg = useRegions({
9054
9153
  regions,
9055
9154
  viewport,
@@ -9101,7 +9200,7 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
9101
9200
  onBox: rg.add,
9102
9201
  outline: rg.peek,
9103
9202
  aspect,
9104
- maxHeight: maxHeight === "viewport" ? VIEWPORT_HEIGHT : maxHeight
9203
+ maxHeight: frameCap(maxHeight, fit, full)
9105
9204
  };
9106
9205
  let body;
9107
9206
  if (mode === "side") body = /* @__PURE__ */ jsx("div", {
@@ -9233,6 +9332,7 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
9233
9332
  onActiveChange: setFull,
9234
9333
  className,
9235
9334
  children: /* @__PURE__ */ jsxs("section", {
9335
+ ref: sectionRef,
9236
9336
  "aria-label": label,
9237
9337
  className: cn("grid gap-3", full && "min-h-0 flex-1 content-start overflow-auto"),
9238
9338
  children: [
@@ -10533,7 +10633,7 @@ var MODE_LABEL = {
10533
10633
  blink: "Blink"
10534
10634
  };
10535
10635
  /** Two videos to judge by eye on one clock: side by side, swipe, fade or blink, zoomed together, with matched sound and full screen. */
10536
- function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, rates = SLOW_RATES, regions, moments = [], loop: loopProp, onLoopChange, audio = "a", onPick, pick = true, pickWords, autoPlay = false, loopWhole = false, pixelated = "zoomed", maxHeight, keys = true, extraShortcuts = [], footer, className }) {
10636
+ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, rates = SLOW_RATES, regions, moments = [], loop: loopProp, onLoopChange, audio = "a", onPick, pick = true, pickWords, autoPlay = false, loopWhole = false, pixelated = "zoomed", maxHeight, reserve, keys = true, extraShortcuts = [], footer, className }) {
10537
10637
  const clock = useVideoClock({
10538
10638
  fps: a.media.fps ?? 30,
10539
10639
  loop: loopProp,
@@ -10553,6 +10653,12 @@ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, rates =
10553
10653
  const frameWidth = useWidth(frameRef);
10554
10654
  const { wanted, failed } = clock;
10555
10655
  const aspect = a.media.width / a.media.height;
10656
+ const sectionRef = React.useRef(null);
10657
+ const fit = useFitHeight(sectionRef, {
10658
+ enabled: maxHeight === "fit" || full,
10659
+ full,
10660
+ reserve
10661
+ });
10556
10662
  const natural = [a.media.width, a.media.height];
10557
10663
  const frameHeight = frameWidth / aspect;
10558
10664
  const sharpFor = (c) => {
@@ -10596,7 +10702,7 @@ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, rates =
10596
10702
  onBox: wanted ? void 0 : rg.add,
10597
10703
  outline: rg.peek,
10598
10704
  aspect,
10599
- maxHeight: maxHeight === "viewport" ? VIEWPORT_HEIGHT : maxHeight
10705
+ maxHeight: frameCap(maxHeight, fit, full)
10600
10706
  };
10601
10707
  const shortcuts = [
10602
10708
  ...extraShortcuts,
@@ -10696,6 +10802,7 @@ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, rates =
10696
10802
  onActiveChange: setFull,
10697
10803
  className,
10698
10804
  children: /* @__PURE__ */ jsxs("section", {
10805
+ ref: sectionRef,
10699
10806
  "aria-label": label,
10700
10807
  className: cn("grid gap-3", full && "min-h-0 flex-1 content-start overflow-auto"),
10701
10808
  children: [