strata-react 1.0.28 → 1.0.29

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. Video is the next change |
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 |
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`) |
@@ -2,9 +2,10 @@ import { Viewport } from '../lib/viewport';
2
2
  import { Shortcut } from './hotkeys';
3
3
  import { Candidate } from './compare';
4
4
  import * as React from "react";
5
+ export declare const VIEWPORT_HEIGHT = "max(16rem, calc(100svh - 14rem))";
5
6
  /** A word for a picture's name on the page: its label, with its note unless blind. */
6
7
  export declare function Caption({ c, blind }: {
7
- c: Candidate;
8
+ c: Candidate<unknown>;
8
9
  blind: boolean;
9
10
  }): React.JSX.Element;
10
11
  /** One picture inside a frame: a skeleton while it loads, the product's words if it fails. */
@@ -0,0 +1,33 @@
1
+ import { Shortcut } from './hotkeys';
2
+ import { Candidate, CompareMode, VideoMedia } from './compare';
3
+ import * as React from "react";
4
+ /** The views a pair of videos has: pictures' views without the difference, which needs pixels. */
5
+ export type VideoMode = Exclude<CompareMode, "difference">;
6
+ /** Props for `CompareVideo`. */
7
+ export type CompareVideoProps = {
8
+ /** Names the comparison for screen readers. Required. */
9
+ label: string;
10
+ a: Candidate<VideoMedia>;
11
+ b: Candidate<VideoMedia>;
12
+ /** Whether the person must not learn which video is which. Required, no default. */
13
+ blind: boolean;
14
+ /** The words shown when a video cannot be loaded: "Video not found". Required. */
15
+ missing: string;
16
+ mode: VideoMode;
17
+ onModeChange: (mode: VideoMode) => void;
18
+ /** Which video's sound is heard; the other is muted. Default "a". */
19
+ audio?: "a" | "b" | "none";
20
+ /** Draw nearest-neighbour when shown larger than the video's own pixels (`zoomed`, default), always, or never. */
21
+ pixelated?: "zoomed" | "always" | "never";
22
+ /** How tall a frame may be: a CSS length or `"viewport"`, as in `Compare`. */
23
+ maxHeight?: string;
24
+ /** Bind the keys on the window. Default true. */
25
+ keys?: boolean;
26
+ /** Shortcuts of the surrounding screen, bound with these and listed first in the same legend. */
27
+ extraShortcuts?: Shortcut[];
28
+ /** Drawn under the video, above the legend, and kept in full screen: where a vote bar goes. */
29
+ footer?: React.ReactNode;
30
+ className?: string;
31
+ };
32
+ /** 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;
@@ -20,6 +20,18 @@ export type TextMedia = {
20
20
  kind: "text";
21
21
  text: string;
22
22
  };
23
+ /** A video to compare (`CompareVideo`). Serve it under a neutral address when the comparison is blind: `src` reaches the page. */
24
+ export type VideoMedia = {
25
+ kind: "video";
26
+ src: string;
27
+ /** A still shown before the first frame. */
28
+ poster?: string;
29
+ /** Its size in pixels, for the shape of the frame, "1:1" and drawing candidates of different sizes in one box. */
30
+ width: number;
31
+ height: number;
32
+ /** Frames per second, if known: the unit of the sync tolerance and of the frame readout. Default 30. */
33
+ fps?: number;
34
+ };
23
35
  /** One side of a comparison. */
24
36
  export type Candidate<M = ImageMedia> = {
25
37
  /** Who it is: a variant name, a model. Never put on the page when `blind`, and never needed by it. */
package/dist/index.d.ts CHANGED
@@ -61,12 +61,13 @@ 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, type AudioMedia, type TextMedia } from './components/compare';
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
67
  export { FIT, MIN_SCALE, MAX_SCALE, clampViewport, zoomAt, actualPixelsScale, type Viewport } 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
71
  export { CompareText, type CompareTextProps } from './components/compare-text';
71
72
  export { diffWords, type TextDifference, type TextSegment } from './lib/text-diff';
72
73
  export { loudnessOf, matchGains, gainToVolume, measureLoudness, type Loudness } from './lib/loudness';
package/dist/index.js CHANGED
@@ -5285,7 +5285,7 @@ function InfiniteList({ state, label, children, skeleton, empty, moreLabel, more
5285
5285
  });
5286
5286
  }
5287
5287
  // src/components/line-chart.tsx
5288
- function useWidth() {
5288
+ function useWidth$1() {
5289
5289
  const ref = React.useRef(null);
5290
5290
  const [width, setWidth] = React.useState(0);
5291
5291
  React.useLayoutEffect(() => {
@@ -5369,7 +5369,7 @@ function fitTicks(ticks, scale, widthOf, gap = 12) {
5369
5369
  }
5370
5370
  /** One measured series, drawn in real pixels, with the peak and current readings labelled on the chart and every reading in a screen-reader table. Optional plan, threshold band and `colourScale`. */
5371
5371
  function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, formatX, xLabel = "Time", formatY, xTicks, yMin, yMax, colour = "var(--chart-1)", colourScale, colourScaleLabel, current, end, formatCurrent, readout, onPick, area, height = 280, className }) {
5372
- const [ref, width] = useWidth();
5372
+ const [ref, width] = useWidth$1();
5373
5373
  const gradientId = `heat-${React.useId().replace(/[^\w-]/g, "")}`;
5374
5374
  const all = [...series, ...planned ?? []];
5375
5375
  const xMin = Math.min(...all.map((p) => p.x));
@@ -6538,6 +6538,7 @@ function viewportTransform(v) {
6538
6538
  return `translate(${v.x}px, ${v.y}px) scale(${v.scale})`;
6539
6539
  }
6540
6540
  // src/components/compare-parts.tsx
6541
+ var VIEWPORT_HEIGHT = "max(16rem, calc(100svh - 14rem))";
6541
6542
  /** A word for a picture's name on the page: its label, with its note unless blind. */
6542
6543
  function Caption({ c, blind }) {
6543
6544
  return /* @__PURE__ */ jsxs("div", {
@@ -6955,14 +6956,13 @@ var ViewportFrame = React.forwardRef(function ViewportFrame({ label, aspect, vie
6955
6956
  });
6956
6957
  });
6957
6958
  // src/components/compare.tsx
6958
- var MODE_LABEL = {
6959
+ var MODE_LABEL$1 = {
6959
6960
  side: "Side by side",
6960
6961
  swipe: "Swipe",
6961
6962
  fade: "Fade",
6962
6963
  blink: "Blink",
6963
6964
  difference: "Difference"
6964
6965
  };
6965
- var VIEWPORT_HEIGHT = "max(16rem, calc(100svh - 14rem))";
6966
6966
  var ALL_MODES = [
6967
6967
  "side",
6968
6968
  "swipe",
@@ -6999,7 +6999,7 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
6999
6999
  ...extraShortcuts,
7000
7000
  ...offered.map((m, i) => ({
7001
7001
  keys: [String(i + 1)],
7002
- label: MODE_LABEL[m],
7002
+ label: MODE_LABEL$1[m],
7003
7003
  run: () => onModeChange(m)
7004
7004
  })),
7005
7005
  {
@@ -7167,7 +7167,7 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
7167
7167
  label: "View",
7168
7168
  options: offered.map((m) => ({
7169
7169
  value: m,
7170
- label: MODE_LABEL[m]
7170
+ label: MODE_LABEL$1[m]
7171
7171
  })),
7172
7172
  value: mode,
7173
7173
  onChange: (v) => onModeChange(v),
@@ -7823,6 +7823,392 @@ function CompareAudio({ label, a, b, blind, missing, levelMatch = true, align =
7823
7823
  ]
7824
7824
  });
7825
7825
  }
7826
+ // src/components/compare-video.tsx
7827
+ var MODES = [
7828
+ "side",
7829
+ "swipe",
7830
+ "fade",
7831
+ "blink"
7832
+ ];
7833
+ var MODE_LABEL = {
7834
+ side: "Side by side",
7835
+ swipe: "Swipe",
7836
+ fade: "Fade",
7837
+ blink: "Blink"
7838
+ };
7839
+ function useWidth(ref) {
7840
+ const [width, setWidth] = React.useState(0);
7841
+ React.useLayoutEffect(() => {
7842
+ const el = ref.current;
7843
+ if (!el) return;
7844
+ const read = () => setWidth(el.getBoundingClientRect().width);
7845
+ read();
7846
+ if (typeof ResizeObserver === "undefined") return;
7847
+ const ro = new ResizeObserver(read);
7848
+ ro.observe(el);
7849
+ return () => ro.disconnect();
7850
+ });
7851
+ return width;
7852
+ }
7853
+ /** Two videos to judge by eye on one clock: side by side, swipe, fade or blink, zoomed together, with matched sound and full screen. */
7854
+ function CompareVideo({ label, a, b, blind, missing, mode, onModeChange, audio = "a", pixelated = "zoomed", maxHeight, keys = true, extraShortcuts = [], footer, className }) {
7855
+ const refA = React.useRef(null);
7856
+ const refB = React.useRef(null);
7857
+ const sa = useMediaElement(refA);
7858
+ const sb = useMediaElement(refB);
7859
+ const { viewport, setViewport } = useViewport();
7860
+ const [full, setFull] = React.useState(false);
7861
+ const [divider, setDivider] = React.useState(50);
7862
+ const [blend, setBlend] = React.useState(50);
7863
+ const [showing, setShowing] = React.useState("a");
7864
+ const [volume, setVolume] = React.useState(100);
7865
+ const [muted, setMuted] = React.useState(false);
7866
+ const [wanted, setWanted] = React.useState(false);
7867
+ const frameRef = React.useRef(null);
7868
+ const frameWidth = useWidth(frameRef);
7869
+ const fps = a.media.fps ?? 30;
7870
+ const known = [sa.duration, sb.duration].filter((d) => d !== null);
7871
+ const duration = known.length ? Math.min(...known) : null;
7872
+ const failed = sa.error || sb.error;
7873
+ const play = () => {
7874
+ setWanted(true);
7875
+ sa.play();
7876
+ sb.play();
7877
+ };
7878
+ const pause = () => {
7879
+ setWanted(false);
7880
+ sa.pause();
7881
+ sb.pause();
7882
+ };
7883
+ const toggle = () => wanted ? pause() : play();
7884
+ const seek = (time) => {
7885
+ const t = Math.max(0, duration === null ? time : Math.min(time, duration));
7886
+ sa.seek(t);
7887
+ sb.seek(t);
7888
+ };
7889
+ const chosenRate = React.useRef(1);
7890
+ const setRate = (rate) => {
7891
+ chosenRate.current = rate;
7892
+ sa.setRate(rate);
7893
+ sb.setRate(rate);
7894
+ };
7895
+ React.useEffect(() => {
7896
+ if (sa.ended || sb.ended) {
7897
+ setWanted(false);
7898
+ refA.current?.pause();
7899
+ refB.current?.pause();
7900
+ }
7901
+ }, [sa.ended, sb.ended]);
7902
+ React.useEffect(() => {
7903
+ if (!wanted) return;
7904
+ let held = false;
7905
+ let frame = requestAnimationFrame(function tick() {
7906
+ const A = refA.current;
7907
+ const B = refB.current;
7908
+ if (A && B && !A.ended && !B.ended) {
7909
+ if (!(A.readyState >= 3 && B.readyState >= 3)) {
7910
+ if (!held) {
7911
+ held = true;
7912
+ A.pause();
7913
+ B.pause();
7914
+ }
7915
+ } else if (held) {
7916
+ held = false;
7917
+ A.play();
7918
+ B.play();
7919
+ } else if (!A.paused) {
7920
+ const drift = B.currentTime - A.currentTime;
7921
+ const one = 1 / fps;
7922
+ if (Math.abs(drift) > .3) B.currentTime = A.currentTime;
7923
+ else if (Math.abs(drift) > one) B.playbackRate = A.playbackRate * (drift > 0 ? .97 : 1.03);
7924
+ else if (Math.abs(drift) < one / 2 && B.playbackRate !== A.playbackRate) B.playbackRate = A.playbackRate;
7925
+ }
7926
+ }
7927
+ frame = requestAnimationFrame(tick);
7928
+ });
7929
+ return () => cancelAnimationFrame(frame);
7930
+ }, [wanted, fps]);
7931
+ const resume = React.useRef({
7932
+ time: 0,
7933
+ playing: false
7934
+ });
7935
+ if (sa.duration !== null) resume.current = {
7936
+ time: sa.time,
7937
+ playing: wanted
7938
+ };
7939
+ const restore = (e) => {
7940
+ const el = e.currentTarget;
7941
+ el.defaultPlaybackRate = chosenRate.current;
7942
+ el.playbackRate = chosenRate.current;
7943
+ if (resume.current.time > 0) el.currentTime = resume.current.time;
7944
+ if (resume.current.playing) el.play();
7945
+ };
7946
+ React.useEffect(() => {
7947
+ [[refA.current, "a"], [refB.current, "b"]].forEach(([el, side]) => {
7948
+ if (!(el instanceof HTMLVideoElement)) return;
7949
+ el.muted = audio !== side || muted || volume === 0;
7950
+ el.volume = volume / 100;
7951
+ });
7952
+ });
7953
+ const aspect = a.media.width / a.media.height;
7954
+ const natural = [a.media.width, a.media.height];
7955
+ const frameHeight = frameWidth / aspect;
7956
+ const sharpFor = (c) => {
7957
+ if (pixelated !== "zoomed") return pixelated === "always";
7958
+ const drawn = Math.min(frameWidth, frameHeight * (c.media.width / c.media.height));
7959
+ return drawn > 0 && viewport.scale * drawn / c.media.width > 1;
7960
+ };
7961
+ const zoom = useZoom({
7962
+ viewport,
7963
+ setViewport,
7964
+ frame: frameRef,
7965
+ natural
7966
+ });
7967
+ const flip = () => setShowing((s) => s === "a" ? "b" : "a");
7968
+ const video = (c, ref) => /* @__PURE__ */ jsx("video", {
7969
+ ref,
7970
+ src: c.media.src,
7971
+ poster: c.media.poster,
7972
+ preload: "auto",
7973
+ playsInline: true,
7974
+ "aria-label": `Video ${c.label}`,
7975
+ onLoadedMetadata: restore,
7976
+ style: sharpFor(c) ? { imageRendering: "pixelated" } : void 0,
7977
+ className: "absolute inset-0 size-full object-contain"
7978
+ });
7979
+ const skeleton = !failed && (sa.duration === null || sb.duration === null) && /* @__PURE__ */ jsx(Skeleton, {
7980
+ "aria-hidden": true,
7981
+ className: "absolute inset-0 size-full rounded-none"
7982
+ });
7983
+ const frameProps = {
7984
+ viewport,
7985
+ setViewport,
7986
+ aspect,
7987
+ maxHeight: maxHeight === "viewport" ? VIEWPORT_HEIGHT : maxHeight
7988
+ };
7989
+ const shortcuts = [
7990
+ ...extraShortcuts,
7991
+ ...MODES.map((m, i) => ({
7992
+ keys: [String(i + 1)],
7993
+ label: MODE_LABEL[m],
7994
+ run: () => onModeChange(m)
7995
+ })),
7996
+ {
7997
+ keys: ["x"],
7998
+ label: `Flip ${a.label} and ${b.label}`,
7999
+ run: flip,
8000
+ disabled: mode !== "blink"
8001
+ },
8002
+ {
8003
+ keys: [" ", "k"],
8004
+ label: "Play or pause",
8005
+ run: toggle
8006
+ },
8007
+ {
8008
+ keys: ["j"],
8009
+ label: "Back 1 s",
8010
+ run: () => seek(sa.time - 1),
8011
+ repeat: true
8012
+ },
8013
+ {
8014
+ keys: ["l"],
8015
+ label: "Forward 1 s",
8016
+ run: () => seek(sa.time + 1),
8017
+ repeat: true
8018
+ },
8019
+ ...audio === "none" ? [] : [{
8020
+ keys: ["m"],
8021
+ label: "Mute",
8022
+ run: () => setMuted((m) => !m)
8023
+ }],
8024
+ ...zoomShortcuts(zoom, full, setFull)
8025
+ ];
8026
+ useHotkeys(shortcuts, { enabled: keys });
8027
+ let body;
8028
+ if (mode === "side") body = /* @__PURE__ */ jsx("div", {
8029
+ className: "grid gap-3 sm:grid-cols-2",
8030
+ children: [[a, refA], [b, refB]].map(([c, ref], i) => /* @__PURE__ */ jsxs("figure", {
8031
+ className: "grid gap-1.5",
8032
+ children: [/* @__PURE__ */ jsx(Caption, {
8033
+ c,
8034
+ blind
8035
+ }), /* @__PURE__ */ jsxs(ViewportFrame, {
8036
+ ...frameProps,
8037
+ label: `Frame ${c.label}`,
8038
+ ref: i === 0 ? frameRef : void 0,
8039
+ children: [i === 0 && skeleton, video(c, ref)]
8040
+ })]
8041
+ }, i))
8042
+ });
8043
+ else body = /* @__PURE__ */ jsxs("figure", {
8044
+ className: "grid gap-1.5",
8045
+ children: [/* @__PURE__ */ jsxs("div", {
8046
+ className: "flex justify-between gap-4",
8047
+ children: [mode === "blink" ? /* @__PURE__ */ jsx(Caption, {
8048
+ c: showing === "a" ? a : b,
8049
+ blind
8050
+ }) : /* @__PURE__ */ jsx(Caption, {
8051
+ c: a,
8052
+ blind
8053
+ }), mode !== "blink" && /* @__PURE__ */ jsx(Caption, {
8054
+ c: b,
8055
+ blind
8056
+ })]
8057
+ }), /* @__PURE__ */ jsxs(ViewportFrame, {
8058
+ ...frameProps,
8059
+ ref: frameRef,
8060
+ cover: mode === "swipe" ? {
8061
+ content: video(a, refA),
8062
+ shown: divider
8063
+ } : void 0,
8064
+ label: mode === "blink" ? `Frame ${(showing === "a" ? a : b).label}` : `${a.label} over ${b.label}`,
8065
+ overlay: mode === "swipe" && /* @__PURE__ */ jsx(Slider$1, {
8066
+ "aria-label": `Divider between ${a.label} and ${b.label}`,
8067
+ value: divider,
8068
+ onChange: (v) => setDivider(v),
8069
+ minValue: 0,
8070
+ maxValue: 100,
8071
+ step: 1,
8072
+ className: "absolute inset-0",
8073
+ children: /* @__PURE__ */ jsx(SliderTrack, {
8074
+ className: "pointer-events-none h-full w-full",
8075
+ children: /* @__PURE__ */ jsxs(SliderThumb, {
8076
+ className: "pointer-events-auto grid h-full w-8 cursor-ew-resize place-items-center focus-visible:outline-2 focus-visible:outline-ring",
8077
+ style: { top: "50%" },
8078
+ children: [/* @__PURE__ */ jsx("span", {
8079
+ "aria-hidden": true,
8080
+ className: "col-start-1 row-start-1 h-full w-1 border-x border-background bg-foreground"
8081
+ }), /* @__PURE__ */ jsx("span", {
8082
+ "aria-hidden": true,
8083
+ className: "col-start-1 row-start-1 size-6 rounded-pill border-2 border-foreground bg-background"
8084
+ })]
8085
+ })
8086
+ })
8087
+ }),
8088
+ children: [
8089
+ skeleton,
8090
+ video(b, refB),
8091
+ mode !== "swipe" && /* @__PURE__ */ jsx("div", {
8092
+ className: "absolute inset-0",
8093
+ style: mode === "fade" ? { opacity: 1 - blend / 100 } : mode === "blink" ? { opacity: showing === "a" ? 1 : 0 } : void 0,
8094
+ children: video(a, refA)
8095
+ })
8096
+ ]
8097
+ })]
8098
+ });
8099
+ return /* @__PURE__ */ jsx(FullscreenFrame, {
8100
+ label,
8101
+ active: full,
8102
+ onActiveChange: setFull,
8103
+ className,
8104
+ children: /* @__PURE__ */ jsxs("section", {
8105
+ "aria-label": label,
8106
+ className: cn("grid gap-3", full && "min-h-0 flex-1 content-start overflow-auto"),
8107
+ children: [
8108
+ /* @__PURE__ */ jsxs(Toolbar, {
8109
+ label: "Comparison view",
8110
+ className: "items-center gap-2",
8111
+ children: [
8112
+ /* @__PURE__ */ jsx(ToggleGroup, {
8113
+ label: "View",
8114
+ options: MODES.map((m) => ({
8115
+ value: m,
8116
+ label: MODE_LABEL[m]
8117
+ })),
8118
+ value: mode,
8119
+ onChange: (v) => onModeChange(v),
8120
+ size: "sm"
8121
+ }),
8122
+ /* @__PURE__ */ jsx(ToolbarSeparator, {}),
8123
+ /* @__PURE__ */ jsx(ZoomControls, {
8124
+ viewport,
8125
+ zoom,
8126
+ natural
8127
+ }),
8128
+ /* @__PURE__ */ jsx(ToolbarSeparator, {}),
8129
+ /* @__PURE__ */ jsx(FullscreenButton, {
8130
+ full,
8131
+ setFull
8132
+ })
8133
+ ]
8134
+ }),
8135
+ mode === "fade" && /* @__PURE__ */ jsxs("div", {
8136
+ className: "flex items-center gap-3",
8137
+ children: [
8138
+ /* @__PURE__ */ jsx("span", {
8139
+ className: "type-caption text-muted-foreground",
8140
+ children: a.label
8141
+ }),
8142
+ /* @__PURE__ */ jsx(Slider, {
8143
+ "aria-label": `Blend from ${a.label} to ${b.label}`,
8144
+ value: blend,
8145
+ onChange: setBlend,
8146
+ min: 0,
8147
+ max: 100,
8148
+ unit: "%",
8149
+ hideValue: true,
8150
+ className: "flex-1"
8151
+ }),
8152
+ /* @__PURE__ */ jsx("span", {
8153
+ className: "type-caption text-muted-foreground",
8154
+ children: b.label
8155
+ })
8156
+ ]
8157
+ }),
8158
+ mode === "blink" && /* @__PURE__ */ jsx(ToggleGroup, {
8159
+ label: "Showing",
8160
+ options: [{
8161
+ value: "a",
8162
+ label: a.label
8163
+ }, {
8164
+ value: "b",
8165
+ label: b.label
8166
+ }],
8167
+ value: showing,
8168
+ onChange: (v) => setShowing(v),
8169
+ size: "sm",
8170
+ className: "justify-self-start"
8171
+ }),
8172
+ failed && /* @__PURE__ */ jsx("p", {
8173
+ role: "alert",
8174
+ className: "type-body-sm text-danger",
8175
+ children: missing
8176
+ }),
8177
+ body,
8178
+ /* @__PURE__ */ jsxs(Transport, {
8179
+ playing: wanted,
8180
+ onPlayPause: toggle,
8181
+ children: [
8182
+ /* @__PURE__ */ jsx(TimeReadout, {
8183
+ time: sa.time,
8184
+ duration
8185
+ }),
8186
+ /* @__PURE__ */ jsx(SeekBar, {
8187
+ time: sa.time,
8188
+ duration,
8189
+ onSeek: seek,
8190
+ buffered: sa.buffered,
8191
+ label: "Position",
8192
+ step: 1,
8193
+ precision: "frames",
8194
+ fps
8195
+ }),
8196
+ /* @__PURE__ */ jsx(RateChoice, {
8197
+ rate: sa.rate,
8198
+ onRateChange: setRate
8199
+ }),
8200
+ audio !== "none" && /* @__PURE__ */ jsx(VolumeControl, {
8201
+ volume: muted ? 0 : volume,
8202
+ onVolumeChange: (v) => (setMuted(false), setVolume(v))
8203
+ })
8204
+ ]
8205
+ }),
8206
+ footer,
8207
+ keys && /* @__PURE__ */ jsx(KeysLegend, { shortcuts })
8208
+ ]
8209
+ })
8210
+ });
8211
+ }
7826
8212
  var tokens = (text) => text.split(/(\s+)/).filter((t) => t !== "");
7827
8213
  var isSpace = (t) => /^\s+$/.test(t);
7828
8214
  /** Marks the words that differ between two texts, or returns null when the pair is too long to compare. */
@@ -8737,6 +9123,6 @@ function SaveStatus({ state, onRetry, className }) {
8737
9123
  ]
8738
9124
  });
8739
9125
  }
8740
- export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompositionBar, ContextMenu, DEFAULT_TOLERANCE, DataTable, DataView, Density, Dialog, Disclosure, Done, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, Inspector, InspectorSection, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, PairJudge, PairVote, Pane, Popover, PropertyList, PropertyRow, RateChoice, RowAction, SPEECH_RATES, SaveStatus, SeekBar, SelectableGrid, SideNav, Skeleton, Slider, SortableList, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, Transport, UndoBar, ViewportFrame, VirtualList, VolumeControl, Workspace, actualPixelsScale, buttonVariants, canFullscreen, clampViewport, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, diffWords, differences, fetchJson, fieldErrorsOf, format, formatChord, gainToVolume, geo, isReservedChord, isTypingTarget, labelOf, loudnessOf, matchGains, matchesAccept, matchesChord, measureLoudness, noOverlap, parseChord, parseSort, readErrorBody, readPixels, resample, serialiseSort, staleOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toast, toastTimeout, transportShortcuts, typeSteps, useActiveItem, useAsyncAction, useAutoSave, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useLeaveGuard, useLoad, useMediaElement, useSelection, useSystemColorScheme, useTimelineZoom, useUndoable, useViewport, useWorkspaceState, zoomAt };
9126
+ export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompositionBar, ContextMenu, DEFAULT_TOLERANCE, DataTable, DataView, Density, Dialog, Disclosure, Done, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, Inspector, InspectorSection, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, PairJudge, PairVote, Pane, Popover, PropertyList, PropertyRow, RateChoice, RowAction, SPEECH_RATES, SaveStatus, SeekBar, SelectableGrid, SideNav, Skeleton, Slider, SortableList, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, Transport, UndoBar, ViewportFrame, VirtualList, VolumeControl, Workspace, actualPixelsScale, buttonVariants, canFullscreen, clampViewport, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, diffWords, differences, fetchJson, fieldErrorsOf, format, formatChord, gainToVolume, geo, isReservedChord, isTypingTarget, labelOf, loudnessOf, matchGains, matchesAccept, matchesChord, measureLoudness, noOverlap, parseChord, parseSort, readErrorBody, readPixels, resample, serialiseSort, staleOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toast, toastTimeout, transportShortcuts, typeSteps, useActiveItem, useAsyncAction, useAutoSave, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useLeaveGuard, useLoad, useMediaElement, useSelection, useSystemColorScheme, useTimelineZoom, useUndoable, useViewport, useWorkspaceState, zoomAt };
8741
9127
 
8742
9128
  //# sourceMappingURL=index.js.map