strata-react 1.0.5 → 1.0.7

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/dist/index.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import { C as readErrorBody, E as typeSteps, S as fieldErrorsOf, T as cn, _ as Textarea, a as toLoad, b as describeActionError, c as ColorSchemeChoice, d as useColorScheme, f as useSystemColorScheme, g as NativeSelect, h as Input, i as staleOf, l as ThemeProvider, m as Field, n as createQueryClient, o as useLoad, p as ChoiceGroup, r as fetchJson, s as COLOR_SCHEME_STORAGE_KEY, t as StrataQueryProvider, u as colorSchemeScript, v as useFieldControl, w as Tooltip, x as describeHttpError, y as HttpError } from "./query-CXlmWmrY.js";
2
2
  import * as React from "react";
3
- import { Autocomplete, Button as Button$1, Checkbox as Checkbox$1, Dialog as Dialog$1, DialogTrigger, Header, Heading, I18nProvider, Input as Input$1, Keyboard, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, NumberField as NumberField$1, Popover as Popover$1, SearchField, Separator, Slider as Slider$1, SliderOutput, SliderThumb, SliderTrack, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, UNSTABLE_Toast, UNSTABLE_ToastContent, UNSTABLE_ToastQueue, UNSTABLE_ToastRegion, useFilter } from "react-aria-components";
3
+ import { Autocomplete, Button as Button$1, Checkbox as Checkbox$1, Dialog as Dialog$1, DialogTrigger, Disclosure as Disclosure$1, DisclosurePanel, DropZone, FileTrigger, Header, Heading, I18nProvider, Input as Input$1, Keyboard, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, NumberField as NumberField$1, Popover as Popover$1, SearchField, Separator, Slider as Slider$1, SliderOutput, SliderThumb, SliderTrack, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, UNSTABLE_Toast, UNSTABLE_ToastContent, UNSTABLE_ToastQueue, UNSTABLE_ToastRegion, useFilter } from "react-aria-components";
4
4
  import { cva } from "class-variance-authority";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
- import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, History, ImageOff, Info, LoaderCircle, Maximize, Minimize, Minus, RotateCcw, Scan, Search, Trash2, TriangleAlert, X, ZoomIn, ZoomOut } from "lucide-react";
6
+ import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, FileQuestion, History, ImageOff, Info, Loader, LoaderCircle, Maximize, Minimize, Minus, RotateCcw, Scan, Search, Trash2, TriangleAlert, Upload, X, ZoomIn, ZoomOut } from "lucide-react";
7
7
  import { Link, NavLink, useSearchParams } from "react-router";
8
8
  import { createSortedRowModel, flexRender, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
9
9
  import { useVirtualizer } from "@tanstack/react-virtual";
10
10
  import { hashKey, useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/react-query";
11
+ import pixelmatch from "pixelmatch";
11
12
  // src/lib/format.ts
12
13
  var NBSP = "\xA0";
13
14
  /** The placeholder printed for a value that is not known: an en dash. */
@@ -2873,6 +2874,480 @@ function TableSkeleton({ rows = 4, columns = 5 }) {
2873
2874
  }, r))]
2874
2875
  });
2875
2876
  }
2877
+ // src/components/file-intake.tsx
2878
+ /** The picker as a button. `children` is its visible name ("Add files"); `accept` narrows what the dialog shows. */
2879
+ function FileButton({ accept, multiple = false, onFiles, icon: Icon, children, ...props }) {
2880
+ return /* @__PURE__ */ jsx(FileTrigger, {
2881
+ acceptedFileTypes: accept,
2882
+ allowsMultiple: multiple,
2883
+ onSelect: (list) => {
2884
+ const files = list ? Array.from(list) : [];
2885
+ if (files.length) onFiles(files);
2886
+ },
2887
+ children: /* @__PURE__ */ jsxs(Button, {
2888
+ ...props,
2889
+ children: [Icon && /* @__PURE__ */ jsx(Icon, { "aria-hidden": true }), children]
2890
+ })
2891
+ });
2892
+ }
2893
+ /** A region that takes dropped files and offers the picker as its keyboard alternative. */
2894
+ function FileDropZone({ onFiles, acceptLabel, title, disabled, children, className }) {
2895
+ const onDrop = async (e) => {
2896
+ const items = e.items.filter((i) => i.kind === "file");
2897
+ const files = await Promise.all(items.map((i) => i.getFile()));
2898
+ if (files.length) onFiles(files);
2899
+ };
2900
+ return /* @__PURE__ */ jsx(DropZone, {
2901
+ "aria-label": title,
2902
+ isDisabled: disabled,
2903
+ onDrop,
2904
+ className: ({ isDropTarget, isFocusVisible }) => cn("grid min-w-0 justify-items-center gap-2 rounded-surface border border-dashed border-input px-4 py-6 text-center", isDropTarget && "border-solid border-primary bg-muted", isFocusVisible && "outline-2 outline-offset-2 outline-ring", className),
2905
+ children: ({ isDropTarget }) => /* @__PURE__ */ jsxs(Fragment, { children: [
2906
+ /* @__PURE__ */ jsx(Upload, {
2907
+ "aria-hidden": true,
2908
+ className: "size-5 text-muted-foreground"
2909
+ }),
2910
+ /* @__PURE__ */ jsx("p", {
2911
+ className: "type-body",
2912
+ children: isDropTarget ? `Drop to add ${acceptLabel}` : title
2913
+ }),
2914
+ children
2915
+ ] })
2916
+ });
2917
+ }
2918
+ var rowStatus = {
2919
+ processing: {
2920
+ tone: "info",
2921
+ word: "Adding…",
2922
+ icon: Loader
2923
+ },
2924
+ added: {
2925
+ tone: "success",
2926
+ word: "Added",
2927
+ icon: CircleCheck
2928
+ },
2929
+ rejected: {
2930
+ tone: "warning",
2931
+ word: "Not added",
2932
+ icon: CircleAlert
2933
+ },
2934
+ failed: {
2935
+ tone: "danger",
2936
+ word: "Failed",
2937
+ icon: CircleAlert
2938
+ }
2939
+ };
2940
+ /** One row per file offered: its name, a status word, and for a rejected or failed file the reason and (for failed) a retry. Announces a summary politely when a batch finishes. */
2941
+ function FileOutcomes({ intake, className }) {
2942
+ const { outcomes, retry, dismiss, pending } = intake;
2943
+ const [summary, setSummary] = React.useState("");
2944
+ const announced = React.useRef(/* @__PURE__ */ new Set());
2945
+ React.useEffect(() => {
2946
+ if (pending > 0) return;
2947
+ const fresh = outcomes.filter((o) => !announced.current.has(o.id));
2948
+ if (!fresh.length) return;
2949
+ for (const o of fresh) announced.current.add(o.id);
2950
+ const added = fresh.filter((o) => o.status === "added").length;
2951
+ const problems = fresh.length - added;
2952
+ setSummary([added && `${added} added`, problems && `${problems} not added`].filter(Boolean).join(", "));
2953
+ }, [pending, outcomes]);
2954
+ return /* @__PURE__ */ jsxs("div", {
2955
+ className: cn("min-w-0", className),
2956
+ children: [/* @__PURE__ */ jsx("p", {
2957
+ role: "status",
2958
+ className: "sr-only",
2959
+ children: summary
2960
+ }), outcomes.length > 0 && /* @__PURE__ */ jsx("ul", {
2961
+ className: "grid divide-y divide-border border-y border-border",
2962
+ children: outcomes.map((o) => {
2963
+ const s = rowStatus[o.status];
2964
+ const reason = o.status === "rejected" || o.status === "failed" ? o.reason : void 0;
2965
+ return /* @__PURE__ */ jsxs("li", {
2966
+ className: "grid gap-1 py-2",
2967
+ children: [/* @__PURE__ */ jsxs("div", {
2968
+ className: "flex items-center gap-3",
2969
+ children: [
2970
+ /* @__PURE__ */ jsx("span", {
2971
+ className: "min-w-0 flex-1 truncate type-body",
2972
+ title: o.name,
2973
+ children: o.name
2974
+ }),
2975
+ /* @__PURE__ */ jsx(Status, {
2976
+ tone: s.tone,
2977
+ icon: s.icon,
2978
+ children: s.word
2979
+ }),
2980
+ o.status === "failed" && /* @__PURE__ */ jsx(RowAction, {
2981
+ label: "Try again",
2982
+ subject: o.name,
2983
+ onClick: () => retry(o.id)
2984
+ }),
2985
+ o.status !== "processing" && /* @__PURE__ */ jsx(IconButton, {
2986
+ icon: X,
2987
+ label: `Dismiss ${o.name}`,
2988
+ onClick: () => dismiss(o.id)
2989
+ })
2990
+ ]
2991
+ }), reason && /* @__PURE__ */ jsx("p", {
2992
+ className: "type-body-sm text-muted-foreground",
2993
+ children: reason
2994
+ })]
2995
+ }, o.id);
2996
+ })
2997
+ })]
2998
+ });
2999
+ }
3000
+ /** A saved item whose file is gone: the item's name, a "File missing" status (a word and an icon) and a "Relink" button that opens the picker for this one item. */
3001
+ function MissingFile({ name, accept, onRelink, className }) {
3002
+ return /* @__PURE__ */ jsxs("div", {
3003
+ className: cn("flex min-w-0 items-center gap-3", className),
3004
+ children: [
3005
+ /* @__PURE__ */ jsx("span", {
3006
+ className: "min-w-0 flex-1 truncate type-body",
3007
+ title: name,
3008
+ children: name
3009
+ }),
3010
+ /* @__PURE__ */ jsx(Status, {
3011
+ tone: "warning",
3012
+ icon: FileQuestion,
3013
+ children: "File missing"
3014
+ }),
3015
+ /* @__PURE__ */ jsx(FileButton, {
3016
+ accept,
3017
+ variant: "ghost",
3018
+ size: "sm",
3019
+ "aria-label": `Relink ${name}`,
3020
+ onFiles: ([file]) => onRelink(file),
3021
+ children: "Relink"
3022
+ })
3023
+ ]
3024
+ });
3025
+ }
3026
+ // src/lib/file-intake.ts
3027
+ /** Whether a file matches one entry of an `accept` list: extension, exact type or `family/*`, ignoring case. */
3028
+ function matchesAccept(file, accept) {
3029
+ const name = file.name.toLowerCase();
3030
+ const type = file.type.toLowerCase();
3031
+ return accept.some((entry) => {
3032
+ const a = entry.trim().toLowerCase();
3033
+ if (a.startsWith(".")) return name.endsWith(a);
3034
+ if (a.endsWith("/*")) return type.startsWith(a.slice(0, -1));
3035
+ return type === a;
3036
+ });
3037
+ }
3038
+ var MB = 1048576;
3039
+ var sizeWords = (bytes) => bytes >= MB ? `${(bytes / MB).toFixed(bytes >= 100 * MB ? 0 : 1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} kB`;
3040
+ /** Per-file outcomes for files picked or dropped: type and size checks with a named reason, the app's own `process` per file, retry and dismiss. */
3041
+ function useFileIntake(options) {
3042
+ const [outcomes, setOutcomes] = React.useState([]);
3043
+ const opts = React.useRef(options);
3044
+ opts.current = options;
3045
+ const files = React.useRef(/* @__PURE__ */ new Map());
3046
+ const controllers = React.useRef(/* @__PURE__ */ new Map());
3047
+ const counter = React.useRef(0);
3048
+ const alive = React.useRef(true);
3049
+ const patch = React.useCallback((id, next) => {
3050
+ setOutcomes((all) => all.map((o) => o.id === id ? next(o) : o));
3051
+ }, []);
3052
+ const run = React.useCallback((id, file) => {
3053
+ const controller = new AbortController();
3054
+ controllers.current.set(id, controller);
3055
+ const base = {
3056
+ id,
3057
+ name: file.name,
3058
+ size: file.size
3059
+ };
3060
+ patch(id, () => ({
3061
+ ...base,
3062
+ status: "processing"
3063
+ }));
3064
+ Promise.resolve().then(() => opts.current.process?.(file, { signal: controller.signal })).then(() => !controller.signal.aborted && patch(id, () => ({
3065
+ ...base,
3066
+ status: "added"
3067
+ })), (error) => {
3068
+ if (controller.signal.aborted) return;
3069
+ const reason = error instanceof Error && error.message ? error.message : `${file.name} could not be added. Try again.`;
3070
+ patch(id, () => ({
3071
+ ...base,
3072
+ status: "failed",
3073
+ reason
3074
+ }));
3075
+ }).finally(() => controllers.current.delete(id));
3076
+ }, [patch]);
3077
+ const start = React.useCallback((id, file) => {
3078
+ const base = {
3079
+ id,
3080
+ name: file.name,
3081
+ size: file.size
3082
+ };
3083
+ patch(id, () => ({
3084
+ ...base,
3085
+ status: "processing"
3086
+ }));
3087
+ Promise.resolve().then(() => opts.current.check?.(file)).then((reason) => {
3088
+ if (!alive.current || !files.current.has(id)) return;
3089
+ if (reason) {
3090
+ files.current.delete(id);
3091
+ patch(id, () => ({
3092
+ ...base,
3093
+ status: "rejected",
3094
+ reason
3095
+ }));
3096
+ } else run(id, file);
3097
+ }, (error) => {
3098
+ if (!alive.current || !files.current.has(id)) return;
3099
+ const reason = error instanceof Error && error.message ? error.message : `${file.name} could not be checked. Try again.`;
3100
+ patch(id, () => ({
3101
+ ...base,
3102
+ status: "failed",
3103
+ reason
3104
+ }));
3105
+ });
3106
+ }, [patch, run]);
3107
+ const add = React.useCallback((offered) => {
3108
+ const list = Array.from(offered);
3109
+ const { accept, acceptLabel, multiple = true, maxBytes } = opts.current;
3110
+ list.forEach((file, index) => {
3111
+ const id = `f${++counter.current}`;
3112
+ const base = {
3113
+ id,
3114
+ name: file.name,
3115
+ size: file.size
3116
+ };
3117
+ const reject = (reason) => setOutcomes((all) => [...all, {
3118
+ ...base,
3119
+ status: "rejected",
3120
+ reason
3121
+ }]);
3122
+ if (!multiple && index > 0) return reject(`${file.name} was not added: this takes one file at a time.`);
3123
+ if (!matchesAccept(file, accept)) return reject(`${file.name} is not a type this accepts. Add ${acceptLabel}.`);
3124
+ if (maxBytes !== void 0 && file.size > maxBytes) return reject(`${file.name} is ${sizeWords(file.size)}, over the ${sizeWords(maxBytes)} limit.`);
3125
+ files.current.set(id, file);
3126
+ setOutcomes((all) => [...all, {
3127
+ ...base,
3128
+ status: "processing"
3129
+ }]);
3130
+ start(id, file);
3131
+ });
3132
+ }, [patch, start]);
3133
+ const dismiss = React.useCallback((id) => {
3134
+ controllers.current.get(id)?.abort();
3135
+ controllers.current.delete(id);
3136
+ files.current.delete(id);
3137
+ setOutcomes((all) => all.filter((o) => o.id !== id));
3138
+ }, []);
3139
+ const retry = React.useCallback((id) => {
3140
+ const file = files.current.get(id);
3141
+ if (file) start(id, file);
3142
+ }, [start]);
3143
+ const clear = React.useCallback(() => {
3144
+ setOutcomes((all) => {
3145
+ for (const o of all) if (o.status !== "processing") files.current.delete(o.id);
3146
+ return all.filter((o) => o.status === "processing");
3147
+ });
3148
+ }, []);
3149
+ React.useEffect(() => {
3150
+ alive.current = true;
3151
+ const live = controllers.current;
3152
+ return () => {
3153
+ alive.current = false;
3154
+ for (const c of live.values()) c.abort();
3155
+ live.clear();
3156
+ };
3157
+ }, []);
3158
+ const pending = outcomes.filter((o) => o.status === "processing").length;
3159
+ return React.useMemo(() => ({
3160
+ outcomes,
3161
+ add,
3162
+ retry,
3163
+ dismiss,
3164
+ clear,
3165
+ pending
3166
+ }), [
3167
+ outcomes,
3168
+ add,
3169
+ retry,
3170
+ dismiss,
3171
+ clear,
3172
+ pending
3173
+ ]);
3174
+ }
3175
+ // src/components/inspector.tsx
3176
+ function readRemembered(key) {
3177
+ if (!key) return {};
3178
+ try {
3179
+ const raw = window.localStorage.getItem(key);
3180
+ const parsed = raw ? JSON.parse(raw) : {};
3181
+ return parsed && typeof parsed === "object" ? parsed : {};
3182
+ } catch {
3183
+ return {};
3184
+ }
3185
+ }
3186
+ var InspectorContext = React.createContext(null);
3187
+ /** A panel of properties for the selected thing: a labelled region with a heading, an empty state when `title` is null, and sections whose open state is remembered. */
3188
+ function Inspector({ title, kind, empty, selectionKey, storageKey, actions, summary, children, className }) {
3189
+ const headingId = React.useId();
3190
+ const [remembered, setRemembered] = React.useState(() => readRemembered(storageKey));
3191
+ const root = React.useRef(null);
3192
+ const heading = React.useRef(null);
3193
+ const state = React.useMemo(() => ({
3194
+ isOpen: (id, defaultOpen) => remembered[id] ?? defaultOpen,
3195
+ setOpen: (id, open) => setRemembered((prev) => {
3196
+ const next = {
3197
+ ...prev,
3198
+ [id]: open
3199
+ };
3200
+ if (storageKey) try {
3201
+ window.localStorage.setItem(storageKey, JSON.stringify(next));
3202
+ } catch {}
3203
+ return next;
3204
+ })
3205
+ }), [remembered, storageKey]);
3206
+ const hadFocus = React.useRef(false);
3207
+ React.useEffect(() => {
3208
+ const el = root.current;
3209
+ const onFocus = () => hadFocus.current = true;
3210
+ const onBlur = (e) => {
3211
+ if (!e.relatedTarget) return;
3212
+ hadFocus.current = false;
3213
+ };
3214
+ el?.addEventListener("focusin", onFocus);
3215
+ el?.addEventListener("focusout", onBlur);
3216
+ return () => {
3217
+ el?.removeEventListener("focusin", onFocus);
3218
+ el?.removeEventListener("focusout", onBlur);
3219
+ };
3220
+ }, []);
3221
+ React.useEffect(() => {
3222
+ if (hadFocus.current && (document.activeElement === document.body || !document.activeElement)) (heading.current ?? root.current)?.focus();
3223
+ }, [selectionKey, title]);
3224
+ return /* @__PURE__ */ jsx(InspectorContext.Provider, {
3225
+ value: state,
3226
+ children: /* @__PURE__ */ jsx("aside", {
3227
+ ref: root,
3228
+ tabIndex: -1,
3229
+ "aria-labelledby": title === null ? void 0 : headingId,
3230
+ "aria-label": title === null ? "Properties" : void 0,
3231
+ className: cn("min-w-0", className),
3232
+ children: title === null ? empty : /* @__PURE__ */ jsxs("div", {
3233
+ className: "grid gap-4",
3234
+ children: [
3235
+ /* @__PURE__ */ jsxs("header", {
3236
+ className: "flex items-start gap-3",
3237
+ children: [/* @__PURE__ */ jsxs("div", {
3238
+ className: "min-w-0 flex-1",
3239
+ children: [/* @__PURE__ */ jsx(Heading, {
3240
+ level: 2,
3241
+ id: headingId,
3242
+ ref: heading,
3243
+ tabIndex: -1,
3244
+ title,
3245
+ className: "truncate type-heading outline-offset-2",
3246
+ children: title
3247
+ }), kind && /* @__PURE__ */ jsx("p", {
3248
+ className: "type-body-sm text-muted-foreground",
3249
+ children: kind
3250
+ })]
3251
+ }), actions && /* @__PURE__ */ jsx("div", {
3252
+ className: "flex shrink-0 items-center gap-1",
3253
+ children: actions
3254
+ })]
3255
+ }),
3256
+ summary,
3257
+ /* @__PURE__ */ jsx("div", {
3258
+ className: "grid",
3259
+ children
3260
+ }, selectionKey)
3261
+ ]
3262
+ })
3263
+ })
3264
+ });
3265
+ }
3266
+ /** A titled group of rows that collapses. The body is mounted only while open; the open state is remembered by the surrounding `Inspector` (and held locally outside one). */
3267
+ function InspectorSection({ id, title, defaultOpen = true, actions, children, className }) {
3268
+ const inspector = React.useContext(InspectorContext);
3269
+ const [own, setOwn] = React.useState(defaultOpen);
3270
+ const expanded = inspector ? inspector.isOpen(id, defaultOpen) : own;
3271
+ const onChange = (open) => inspector ? inspector.setOpen(id, open) : setOwn(open);
3272
+ return /* @__PURE__ */ jsx(Disclosure$1, {
3273
+ isExpanded: expanded,
3274
+ onExpandedChange: onChange,
3275
+ className: cn("min-w-0 border-t border-border first:border-t-0", className),
3276
+ children: ({ isExpanded }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
3277
+ className: "flex items-center gap-2",
3278
+ children: [/* @__PURE__ */ jsx(Heading, {
3279
+ level: 3,
3280
+ className: "min-w-0 flex-1",
3281
+ children: /* @__PURE__ */ jsxs(Button$1, {
3282
+ slot: "trigger",
3283
+ className: "-mx-1 flex min-h-(--control-h-sm) w-full cursor-pointer items-center gap-2 rounded-control px-1 text-left type-label hover:bg-muted",
3284
+ children: [/* @__PURE__ */ jsx(ChevronRight, {
3285
+ "aria-hidden": true,
3286
+ className: cn("size-4 shrink-0 text-muted-foreground", isExpanded && "rotate-90")
3287
+ }), /* @__PURE__ */ jsx("span", {
3288
+ className: "min-w-0 flex-1 truncate",
3289
+ children: title
3290
+ })]
3291
+ })
3292
+ }), actions && /* @__PURE__ */ jsx("div", {
3293
+ className: "flex shrink-0 items-center gap-1",
3294
+ children: actions
3295
+ })]
3296
+ }), /* @__PURE__ */ jsx(DisclosurePanel, { children: isExpanded && /* @__PURE__ */ jsx("div", {
3297
+ className: "grid gap-4 pt-2 pb-4 pl-6",
3298
+ children
3299
+ }) })] })
3300
+ });
3301
+ }
3302
+ /** One editable property: a `Field` (label, hint, error wired to the control) with a "Reset <label>" that shows only while `modified`. */
3303
+ function PropertyRow({ label, hint, error, modified, onReset, children, className }) {
3304
+ const reset = modified && onReset ? /* @__PURE__ */ jsx(IconButton, {
3305
+ icon: RotateCcw,
3306
+ label: `Reset ${label.toLowerCase()}`,
3307
+ onClick: onReset
3308
+ }) : void 0;
3309
+ return /* @__PURE__ */ jsx(Field, {
3310
+ label,
3311
+ hint,
3312
+ error,
3313
+ action: reset,
3314
+ className,
3315
+ children
3316
+ });
3317
+ }
3318
+ /** Read-only facts as a description list: term left, value right, long strings truncated with the full value on hover, a missing value printed as an en dash, units muted after a non-breaking space. */
3319
+ function PropertyList({ items, label, className }) {
3320
+ return /* @__PURE__ */ jsx("dl", {
3321
+ "aria-label": label,
3322
+ className: cn("grid gap-y-1.5", className),
3323
+ children: items.map(({ term, value, unit }) => {
3324
+ const missing = value === null || value === void 0 || value === "";
3325
+ return /* @__PURE__ */ jsxs("div", {
3326
+ className: "grid grid-cols-5 gap-x-3 type-body-sm",
3327
+ children: [/* @__PURE__ */ jsx("dt", {
3328
+ className: "col-span-2 min-w-0 text-muted-foreground",
3329
+ children: term
3330
+ }), /* @__PURE__ */ jsx("dd", {
3331
+ className: "col-span-3 min-w-0 tabular-nums",
3332
+ children: /* @__PURE__ */ jsxs("span", {
3333
+ className: "block truncate",
3334
+ title: typeof value === "string" ? value : void 0,
3335
+ children: [missing ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
3336
+ "aria-hidden": true,
3337
+ children: format.missing
3338
+ }), /* @__PURE__ */ jsx("span", {
3339
+ className: "sr-only",
3340
+ children: "Not known"
3341
+ })] }) : value, !missing && unit && /* @__PURE__ */ jsx("span", {
3342
+ className: "text-muted-foreground",
3343
+ children: ` ${unit}`
3344
+ })]
3345
+ })
3346
+ })]
3347
+ }, term);
3348
+ })
3349
+ });
3350
+ }
2876
3351
  // src/components/selectable-grid.tsx
2877
3352
  var minWidth = {
2878
3353
  sm: 96,
@@ -4156,48 +4631,6 @@ function useJob({ isRunning, every = 2e3, invalidates = [], describeError, ...op
4156
4631
  poll
4157
4632
  };
4158
4633
  }
4159
- // src/lib/viewport.ts
4160
- /** The picture fitted in its frame, not panned. */
4161
- var FIT = {
4162
- scale: 1,
4163
- x: 0,
4164
- y: 0
4165
- };
4166
- /** The least zoom: the whole picture fitted. */
4167
- var MIN_SCALE = 1;
4168
- /** The most zoom, 32 times the fit. */
4169
- var MAX_SCALE = 32;
4170
- /** Keeps the picture from being dragged out of its frame: at most half the extra width or height past each edge. */
4171
- function clampViewport(v, frame) {
4172
- const scale = Math.min(32, Math.max(1, v.scale));
4173
- if (scale === 1) return FIT;
4174
- const mx = (scale - 1) * frame.width / 2;
4175
- const my = (scale - 1) * frame.height / 2;
4176
- return {
4177
- scale,
4178
- x: Math.min(mx, Math.max(-mx, v.x)),
4179
- y: Math.min(my, Math.max(-my, v.y))
4180
- };
4181
- }
4182
- /** A new scale with the point under `at` (pixels from the frame's centre) staying under it. */
4183
- function zoomAt(v, nextScale, at, frame) {
4184
- const scale = Math.min(32, Math.max(1, nextScale));
4185
- const k = scale / v.scale;
4186
- return clampViewport({
4187
- scale,
4188
- x: at.x - k * (at.x - v.x),
4189
- y: at.y - k * (at.y - v.y)
4190
- }, frame);
4191
- }
4192
- /** The scale at which the picture's own pixels are drawn one to one: its natural width over the width it is fitted at. */
4193
- function actualPixelsScale(naturalWidth, fittedWidth) {
4194
- if (!naturalWidth || !fittedWidth) return 1;
4195
- return Math.min(32, Math.max(1, naturalWidth / fittedWidth));
4196
- }
4197
- /** The CSS transform for a viewport. */
4198
- function viewportTransform(v) {
4199
- return `translate(${v.x}px, ${v.y}px) scale(${v.scale})`;
4200
- }
4201
4634
  // src/components/fullscreen-frame.tsx
4202
4635
  /** Whether this browser can show an element full screen. False in jsdom and on iPhone, where the modal fallback is used. */
4203
4636
  function canFullscreen() {
@@ -4252,6 +4685,314 @@ function FullscreenFrame({ label, active, onActiveChange, children, className })
4252
4685
  })
4253
4686
  });
4254
4687
  }
4688
+ // src/lib/viewport.ts
4689
+ /** The picture fitted in its frame, not panned. */
4690
+ var FIT = {
4691
+ scale: 1,
4692
+ x: 0,
4693
+ y: 0
4694
+ };
4695
+ /** The least zoom: the whole picture fitted. */
4696
+ var MIN_SCALE = 1;
4697
+ /** The most zoom, 32 times the fit. */
4698
+ var MAX_SCALE = 32;
4699
+ /** Keeps the picture from being dragged out of its frame: at most half the extra width or height past each edge. */
4700
+ function clampViewport(v, frame) {
4701
+ const scale = Math.min(32, Math.max(1, v.scale));
4702
+ if (scale === 1) return FIT;
4703
+ const mx = (scale - 1) * frame.width / 2;
4704
+ const my = (scale - 1) * frame.height / 2;
4705
+ return {
4706
+ scale,
4707
+ x: Math.min(mx, Math.max(-mx, v.x)),
4708
+ y: Math.min(my, Math.max(-my, v.y))
4709
+ };
4710
+ }
4711
+ /** A new scale with the point under `at` (pixels from the frame's centre) staying under it. */
4712
+ function zoomAt(v, nextScale, at, frame) {
4713
+ const scale = Math.min(32, Math.max(1, nextScale));
4714
+ const k = scale / v.scale;
4715
+ return clampViewport({
4716
+ scale,
4717
+ x: at.x - k * (at.x - v.x),
4718
+ y: at.y - k * (at.y - v.y)
4719
+ }, frame);
4720
+ }
4721
+ /** The scale at which the picture's own pixels are drawn one to one: its natural width over the width it is fitted at. */
4722
+ function actualPixelsScale(naturalWidth, fittedWidth) {
4723
+ if (!naturalWidth || !fittedWidth) return 1;
4724
+ return Math.min(32, Math.max(1, naturalWidth / fittedWidth));
4725
+ }
4726
+ /** The CSS transform for a viewport. */
4727
+ function viewportTransform(v) {
4728
+ return `translate(${v.x}px, ${v.y}px) scale(${v.scale})`;
4729
+ }
4730
+ // src/components/compare-parts.tsx
4731
+ /** A word for a picture's name on the page: its label, with its note unless blind. */
4732
+ function Caption({ c, blind }) {
4733
+ return /* @__PURE__ */ jsxs("div", {
4734
+ className: "flex items-baseline gap-2",
4735
+ children: [/* @__PURE__ */ jsx("span", {
4736
+ className: "type-label",
4737
+ children: c.label
4738
+ }), !blind && c.note && /* @__PURE__ */ jsx("span", {
4739
+ className: "type-caption text-muted-foreground",
4740
+ children: c.note
4741
+ })]
4742
+ });
4743
+ }
4744
+ /** One picture inside a frame: a skeleton while it loads, the product's words if it fails. */
4745
+ function Picture({ c, blind, missing, onNatural, imgRef }) {
4746
+ const [state, setState] = React.useState("loading");
4747
+ React.useEffect(() => setState("loading"), [c.media.src]);
4748
+ const alt = blind ? c.label : c.media.alt;
4749
+ if (state === "failed") return /* @__PURE__ */ jsxs("div", {
4750
+ role: "img",
4751
+ "aria-label": `${alt}: ${missing}`,
4752
+ className: "absolute inset-0 grid place-content-center justify-items-center gap-2 text-muted-foreground",
4753
+ children: [/* @__PURE__ */ jsx(ImageOff, {
4754
+ "aria-hidden": true,
4755
+ className: "size-6"
4756
+ }), /* @__PURE__ */ jsx("span", {
4757
+ className: "type-body-sm",
4758
+ children: missing
4759
+ })]
4760
+ });
4761
+ return /* @__PURE__ */ jsxs(Fragment, { children: [state === "loading" && /* @__PURE__ */ jsx(Skeleton, {
4762
+ "aria-hidden": true,
4763
+ className: "absolute inset-0 size-full rounded-none"
4764
+ }), /* @__PURE__ */ jsx("img", {
4765
+ ref: imgRef,
4766
+ src: c.media.src,
4767
+ alt,
4768
+ draggable: false,
4769
+ onLoad: (e) => {
4770
+ setState("ready");
4771
+ onNatural?.(e.currentTarget.naturalWidth, e.currentTarget.naturalHeight);
4772
+ },
4773
+ onError: () => setState("failed"),
4774
+ className: "absolute inset-0 size-full object-contain"
4775
+ })] });
4776
+ }
4777
+ var frameSize = (frame) => {
4778
+ const r = frame.current?.getBoundingClientRect();
4779
+ return {
4780
+ width: r?.width ?? 0,
4781
+ height: r?.height ?? 0
4782
+ };
4783
+ };
4784
+ /** Zoom steps about the frame's centre, and 1:1. */
4785
+ function useZoom({ viewport, setViewport, frame, natural }) {
4786
+ const by = (k) => setViewport(zoomAt(viewport, viewport.scale * k, {
4787
+ x: 0,
4788
+ y: 0
4789
+ }, frameSize(frame)));
4790
+ const actual = () => {
4791
+ const f = frameSize(frame);
4792
+ const fitted = natural ? Math.min(f.width, f.height * (natural[0] / natural[1])) : f.width;
4793
+ setViewport(zoomAt(viewport, actualPixelsScale(natural?.[0] ?? 0, fitted), {
4794
+ x: 0,
4795
+ y: 0
4796
+ }, f));
4797
+ };
4798
+ return {
4799
+ by,
4800
+ actual,
4801
+ fit: () => setViewport(FIT)
4802
+ };
4803
+ }
4804
+ /** The shortcuts for zoom and full screen, to join a screen's own list. */
4805
+ function zoomShortcuts(zoom, full, setFull) {
4806
+ return [
4807
+ {
4808
+ keys: ["+", "="],
4809
+ label: "Zoom in",
4810
+ run: () => zoom.by(1.5),
4811
+ repeat: true
4812
+ },
4813
+ {
4814
+ keys: ["-"],
4815
+ label: "Zoom out",
4816
+ run: () => zoom.by(1 / 1.5),
4817
+ repeat: true
4818
+ },
4819
+ {
4820
+ keys: ["0"],
4821
+ label: "Fit",
4822
+ run: zoom.fit
4823
+ },
4824
+ {
4825
+ keys: ["f"],
4826
+ label: full ? "Leave full screen" : "Full screen",
4827
+ run: () => setFull(!full)
4828
+ }
4829
+ ];
4830
+ }
4831
+ /** Zoom out, in, fit, 1:1 and the zoom now, for inside a `Toolbar`. */
4832
+ function ZoomControls({ viewport, zoom, natural }) {
4833
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
4834
+ /* @__PURE__ */ jsx(IconButton, {
4835
+ icon: ZoomOut,
4836
+ label: "Zoom out",
4837
+ onPress: () => zoom.by(1 / 1.5),
4838
+ disabled: viewport.scale <= 1
4839
+ }),
4840
+ /* @__PURE__ */ jsx(IconButton, {
4841
+ icon: ZoomIn,
4842
+ label: "Zoom in",
4843
+ onPress: () => zoom.by(1.5)
4844
+ }),
4845
+ /* @__PURE__ */ jsx(IconButton, {
4846
+ icon: Scan,
4847
+ label: "Fit",
4848
+ onPress: zoom.fit,
4849
+ disabled: viewport.scale === 1
4850
+ }),
4851
+ /* @__PURE__ */ jsx(Button, {
4852
+ size: "sm",
4853
+ variant: "ghost",
4854
+ onPress: zoom.actual,
4855
+ disabled: !natural,
4856
+ children: "1:1"
4857
+ }),
4858
+ /* @__PURE__ */ jsx("span", {
4859
+ "aria-live": "off",
4860
+ className: "type-caption tabular-nums text-muted-foreground",
4861
+ children: viewport.scale === 1 ? "Fit" : `${viewport.scale.toFixed(1)}×`
4862
+ })
4863
+ ] });
4864
+ }
4865
+ /** The full-screen button, for inside a `Toolbar`. */
4866
+ function FullscreenButton({ full, setFull }) {
4867
+ return /* @__PURE__ */ jsx(IconButton, {
4868
+ icon: full ? Minimize : Maximize,
4869
+ label: full ? "Leave full screen" : "Full screen",
4870
+ onPress: () => setFull(!full)
4871
+ });
4872
+ }
4873
+ // src/lib/image-diff.ts
4874
+ /** The longest side, in pixels, a picture is compared at. */
4875
+ var MAX_SIDE = 2048;
4876
+ /** pixelmatch's own default colour distance below which two pixels are the same. */
4877
+ var DEFAULT_TOLERANCE = .1;
4878
+ /** The picture drawn at another size, each new pixel taken from the nearest old one. Used to bring the second picture to the first's size. */
4879
+ function resample(p, width, height) {
4880
+ if (p.width === width && p.height === height) return p;
4881
+ const data = new Uint8ClampedArray(width * height * 4);
4882
+ for (let y = 0; y < height; y++) {
4883
+ const sy = Math.min(p.height - 1, Math.floor((y + .5) * p.height / height));
4884
+ for (let x = 0; x < width; x++) {
4885
+ const sx = Math.min(p.width - 1, Math.floor((x + .5) * p.width / width));
4886
+ const from = (sy * p.width + sx) * 4;
4887
+ const to = (y * width + x) * 4;
4888
+ data[to] = p.data[from];
4889
+ data[to + 1] = p.data[from + 1];
4890
+ data[to + 2] = p.data[from + 2];
4891
+ data[to + 3] = p.data[from + 3];
4892
+ }
4893
+ }
4894
+ return {
4895
+ data,
4896
+ width,
4897
+ height
4898
+ };
4899
+ }
4900
+ /**
4901
+ * Which pixels differ between two pictures. `b` is resampled to `a`'s size first when they differ,
4902
+ * so a re-encoded or resized rendering still lines up. `tolerance` is pixelmatch's `threshold`, 0 to 1.
4903
+ */
4904
+ function differences(a, b, tolerance = DEFAULT_TOLERANCE) {
4905
+ const other = resample(b, a.width, a.height);
4906
+ const marks = new Uint8ClampedArray(a.width * a.height * 4);
4907
+ const differing = pixelmatch(a.data, other.data, marks, a.width, a.height, {
4908
+ threshold: tolerance,
4909
+ diffMask: true,
4910
+ alpha: 0
4911
+ });
4912
+ return {
4913
+ marks,
4914
+ width: a.width,
4915
+ height: a.height,
4916
+ differing,
4917
+ total: a.width * a.height
4918
+ };
4919
+ }
4920
+ /** Reads a picture's pixels by drawing it on a canvas, scaled down so its long side is at most `maxSide`. Rejects when the picture cannot be loaded or the browser will not let a page read it (a picture from another site without CORS headers). */
4921
+ async function readPixels(src, maxSide = MAX_SIDE) {
4922
+ const img = new Image();
4923
+ img.crossOrigin = "anonymous";
4924
+ img.src = src;
4925
+ await img.decode();
4926
+ const scale = Math.min(1, maxSide / Math.max(img.naturalWidth, img.naturalHeight));
4927
+ const width = Math.max(1, Math.round(img.naturalWidth * scale));
4928
+ const height = Math.max(1, Math.round(img.naturalHeight * scale));
4929
+ const canvas = document.createElement("canvas");
4930
+ canvas.width = width;
4931
+ canvas.height = height;
4932
+ const ctx = canvas.getContext("2d", { willReadFrequently: true });
4933
+ if (!ctx) throw new Error("This browser cannot read a picture's pixels.");
4934
+ ctx.drawImage(img, 0, 0, width, height);
4935
+ const { data } = ctx.getImageData(0, 0, width, height);
4936
+ return {
4937
+ data,
4938
+ width,
4939
+ height
4940
+ };
4941
+ }
4942
+ // src/components/difference.tsx
4943
+ /** The pixels that differ between two pictures at a tolerance (0 to 1), read only while `enabled`. */
4944
+ function useDifference(a, b, tolerance, enabled, read = readPixels) {
4945
+ const [loaded, setLoaded] = React.useState(null);
4946
+ const key = `${a}|${b}`;
4947
+ const reader = React.useRef(read);
4948
+ reader.current = read;
4949
+ React.useEffect(() => {
4950
+ if (!enabled) return;
4951
+ let cancelled = false;
4952
+ setLoaded(null);
4953
+ Promise.all([reader.current(a), reader.current(b)]).then(([pa, pb]) => !cancelled && setLoaded({
4954
+ key,
4955
+ a: pa,
4956
+ b: pb
4957
+ }), () => !cancelled && setLoaded("failed"));
4958
+ return () => {
4959
+ cancelled = true;
4960
+ };
4961
+ }, [
4962
+ a,
4963
+ b,
4964
+ key,
4965
+ enabled
4966
+ ]);
4967
+ const deferred = React.useDeferredValue(tolerance);
4968
+ const difference = React.useMemo(() => loaded && loaded !== "failed" && loaded.key === key ? differences(loaded.a, loaded.b, deferred) : null, [
4969
+ loaded,
4970
+ key,
4971
+ deferred
4972
+ ]);
4973
+ if (loaded === "failed") return { status: "failed" };
4974
+ return difference ? {
4975
+ status: "ready",
4976
+ difference
4977
+ } : { status: "loading" };
4978
+ }
4979
+ /** The marks of a difference drawn over the picture: a canvas that fits its frame the way the picture does (`object-contain`). */
4980
+ function DifferenceMarks({ difference }) {
4981
+ const ref = React.useRef(null);
4982
+ React.useEffect(() => {
4983
+ const canvas = ref.current;
4984
+ const ctx = canvas?.getContext("2d");
4985
+ if (!canvas || !ctx) return;
4986
+ canvas.width = difference.width;
4987
+ canvas.height = difference.height;
4988
+ ctx.putImageData(new ImageData(difference.marks, difference.width, difference.height), 0, 0);
4989
+ }, [difference]);
4990
+ return /* @__PURE__ */ jsx("canvas", {
4991
+ ref,
4992
+ "aria-hidden": true,
4993
+ className: "absolute inset-0 size-full object-contain"
4994
+ });
4995
+ }
4255
4996
  // src/components/viewport.tsx
4256
4997
  /** Zoom and pan held in React state, to give to every `ViewportFrame` that should move together. */
4257
4998
  function useViewport(initial = FIT) {
@@ -4402,62 +5143,18 @@ var MODE_LABEL = {
4402
5143
  side: "Side by side",
4403
5144
  swipe: "Swipe",
4404
5145
  fade: "Fade",
4405
- blink: "Blink"
5146
+ blink: "Blink",
5147
+ difference: "Difference"
4406
5148
  };
4407
5149
  var ALL_MODES = [
4408
5150
  "side",
4409
5151
  "swipe",
4410
5152
  "fade",
4411
- "blink"
5153
+ "blink",
5154
+ "difference"
4412
5155
  ];
4413
- /** A word for a picture's name on the page: its label, with its note unless blind. */
4414
- function Caption({ c, blind }) {
4415
- return /* @__PURE__ */ jsxs("div", {
4416
- className: "flex items-baseline gap-2",
4417
- children: [/* @__PURE__ */ jsx("span", {
4418
- className: "type-label",
4419
- children: c.label
4420
- }), !blind && c.note && /* @__PURE__ */ jsx("span", {
4421
- className: "type-caption text-muted-foreground",
4422
- children: c.note
4423
- })]
4424
- });
4425
- }
4426
- /** One picture inside a frame: a skeleton while it loads, the product's words if it fails. */
4427
- function Picture({ c, blind, missing, onNatural, imgRef }) {
4428
- const [state, setState] = React.useState("loading");
4429
- React.useEffect(() => setState("loading"), [c.media.src]);
4430
- const alt = blind ? c.label : c.media.alt;
4431
- if (state === "failed") return /* @__PURE__ */ jsxs("div", {
4432
- role: "img",
4433
- "aria-label": `${alt}: ${missing}`,
4434
- className: "absolute inset-0 grid place-content-center justify-items-center gap-2 text-muted-foreground",
4435
- children: [/* @__PURE__ */ jsx(ImageOff, {
4436
- "aria-hidden": true,
4437
- className: "size-6"
4438
- }), /* @__PURE__ */ jsx("span", {
4439
- className: "type-body-sm",
4440
- children: missing
4441
- })]
4442
- });
4443
- return /* @__PURE__ */ jsxs(Fragment, { children: [state === "loading" && /* @__PURE__ */ jsx(Skeleton, {
4444
- "aria-hidden": true,
4445
- className: "absolute inset-0 size-full rounded-none"
4446
- }), /* @__PURE__ */ jsx("img", {
4447
- ref: imgRef,
4448
- src: c.media.src,
4449
- alt,
4450
- draggable: false,
4451
- onLoad: (e) => {
4452
- setState("ready");
4453
- onNatural?.(e.currentTarget.naturalWidth, e.currentTarget.naturalHeight);
4454
- },
4455
- onError: () => setState("failed"),
4456
- className: "absolute inset-0 size-full object-contain"
4457
- })] });
4458
- }
4459
5156
  /** Two pictures to judge, side by side or laid over each other, zoomed and panned together, and full screen. */
4460
- function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_MODES, keys = true, className }) {
5157
+ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_MODES, keys = true, cannotCompare = "Could not read these pictures to compare their pixels.", readPixels, defaultDifference = "brightness", className }) {
4461
5158
  const { viewport, setViewport } = useViewport();
4462
5159
  const [full, setFull] = React.useState(false);
4463
5160
  const pairKey = `${a.media.src}|${b.media.src}`;
@@ -4466,28 +5163,19 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
4466
5163
  const [divider, setDivider] = React.useState(50);
4467
5164
  const [blend, setBlend] = React.useState(50);
4468
5165
  const [showing, setShowing] = React.useState("a");
5166
+ const [style, setStyle] = React.useState(defaultDifference);
5167
+ const [amplify, setAmplify] = React.useState(4);
5168
+ const [tolerance, setTolerance] = React.useState(10);
5169
+ const diff = useDifference(a.media.src, b.media.src, tolerance / 100, mode === "difference" && style === "pixels", readPixels);
4469
5170
  const frameRef = React.useRef(null);
4470
5171
  const imgRef = React.useRef(null);
4471
5172
  const aspect = natural ? natural[0] / natural[1] : 3 / 2;
4472
- const frameSize = () => {
4473
- const r = frameRef.current?.getBoundingClientRect();
4474
- return {
4475
- width: r?.width ?? 0,
4476
- height: r?.height ?? 0
4477
- };
4478
- };
4479
- const zoomBy = (k) => setViewport(zoomAt(viewport, viewport.scale * k, {
4480
- x: 0,
4481
- y: 0
4482
- }, frameSize()));
4483
- const actual = () => {
4484
- const f = frameSize();
4485
- const fitted = natural ? Math.min(f.width, f.height * (natural[0] / natural[1])) : f.width;
4486
- setViewport(zoomAt(viewport, actualPixelsScale(natural?.[0] ?? 0, fitted), {
4487
- x: 0,
4488
- y: 0
4489
- }, f));
4490
- };
5173
+ const zoom = useZoom({
5174
+ viewport,
5175
+ setViewport,
5176
+ frame: frameRef,
5177
+ natural
5178
+ });
4491
5179
  const flip = () => setShowing((s) => s === "a" ? "b" : "a");
4492
5180
  const offered = modes.includes(mode) ? modes : [mode, ...modes];
4493
5181
  const shortcuts = [
@@ -4502,28 +5190,7 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
4502
5190
  run: flip,
4503
5191
  disabled: mode !== "blink"
4504
5192
  },
4505
- {
4506
- keys: ["+", "="],
4507
- label: "Zoom in",
4508
- run: () => zoomBy(1.5),
4509
- repeat: true
4510
- },
4511
- {
4512
- keys: ["-"],
4513
- label: "Zoom out",
4514
- run: () => zoomBy(1 / 1.5),
4515
- repeat: true
4516
- },
4517
- {
4518
- keys: ["0"],
4519
- label: "Fit",
4520
- run: () => setViewport(FIT)
4521
- },
4522
- {
4523
- keys: ["f"],
4524
- label: full ? "Leave full screen" : "Full screen",
4525
- run: () => setFull((f) => !f)
4526
- }
5193
+ ...zoomShortcuts(zoom, full, setFull)
4527
5194
  ];
4528
5195
  useHotkeys(shortcuts, { enabled: keys });
4529
5196
  const pane = (c, ref, onNatural) => /* @__PURE__ */ jsx(Picture, {
@@ -4558,6 +5225,56 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
4558
5225
  })]
4559
5226
  }, i))
4560
5227
  });
5228
+ else if (mode === "difference") body = /* @__PURE__ */ jsxs("figure", {
5229
+ className: "grid gap-1.5",
5230
+ children: [/* @__PURE__ */ jsxs("div", {
5231
+ className: "flex justify-between gap-4",
5232
+ children: [
5233
+ /* @__PURE__ */ jsx(Caption, {
5234
+ c: a,
5235
+ blind
5236
+ }),
5237
+ /* @__PURE__ */ jsx("span", {
5238
+ className: "type-caption text-muted-foreground",
5239
+ children: "against"
5240
+ }),
5241
+ /* @__PURE__ */ jsx(Caption, {
5242
+ c: b,
5243
+ blind
5244
+ })
5245
+ ]
5246
+ }), /* @__PURE__ */ jsx(ViewportFrame, {
5247
+ ...frameProps,
5248
+ ref: frameRef,
5249
+ label: `Difference between ${a.label} and ${b.label}`,
5250
+ children: style === "brightness" ? /* @__PURE__ */ jsxs("div", {
5251
+ className: "absolute inset-0 isolate",
5252
+ style: { filter: `brightness(${amplify})` },
5253
+ children: [/* @__PURE__ */ jsx("div", {
5254
+ className: "absolute inset-0 bg-background",
5255
+ children: pane(a, imgRef, learn)
5256
+ }), /* @__PURE__ */ jsx("div", {
5257
+ className: "absolute inset-0 bg-background mix-blend-difference",
5258
+ children: pane(b)
5259
+ })]
5260
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [
5261
+ /* @__PURE__ */ jsx("div", {
5262
+ className: "absolute inset-0 opacity-35",
5263
+ children: pane(a, imgRef, learn)
5264
+ }),
5265
+ diff.status === "ready" && /* @__PURE__ */ jsx(DifferenceMarks, { difference: diff.difference }),
5266
+ diff.status === "loading" && /* @__PURE__ */ jsx(Skeleton, {
5267
+ "aria-hidden": true,
5268
+ className: "absolute inset-0 size-full rounded-none opacity-40"
5269
+ }),
5270
+ diff.status === "failed" && /* @__PURE__ */ jsx("p", {
5271
+ role: "alert",
5272
+ className: "absolute inset-x-0 bottom-0 bg-background/90 p-2 type-body-sm text-danger",
5273
+ children: cannotCompare
5274
+ })
5275
+ ] })
5276
+ })]
5277
+ });
4561
5278
  else {
4562
5279
  const top = mode === "blink" ? showing === "a" ? a : b : a;
4563
5280
  const bottom = b;
@@ -4638,40 +5355,15 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
4638
5355
  size: "sm"
4639
5356
  }),
4640
5357
  /* @__PURE__ */ jsx(ToolbarSeparator, {}),
4641
- /* @__PURE__ */ jsx(IconButton, {
4642
- icon: ZoomOut,
4643
- label: "Zoom out",
4644
- onPress: () => zoomBy(1 / 1.5),
4645
- disabled: viewport.scale <= 1
4646
- }),
4647
- /* @__PURE__ */ jsx(IconButton, {
4648
- icon: ZoomIn,
4649
- label: "Zoom in",
4650
- onPress: () => zoomBy(1.5)
4651
- }),
4652
- /* @__PURE__ */ jsx(IconButton, {
4653
- icon: Scan,
4654
- label: "Fit",
4655
- onPress: () => setViewport(FIT),
4656
- disabled: viewport.scale === 1
4657
- }),
4658
- /* @__PURE__ */ jsx(Button, {
4659
- size: "sm",
4660
- variant: "ghost",
4661
- onPress: actual,
4662
- disabled: !natural,
4663
- children: "1:1"
4664
- }),
4665
- /* @__PURE__ */ jsx("span", {
4666
- "aria-live": "off",
4667
- className: "type-caption tabular-nums text-muted-foreground",
4668
- children: viewport.scale === 1 ? "Fit" : `${viewport.scale.toFixed(1)}×`
5358
+ /* @__PURE__ */ jsx(ZoomControls, {
5359
+ viewport,
5360
+ zoom,
5361
+ natural
4669
5362
  }),
4670
5363
  /* @__PURE__ */ jsx(ToolbarSeparator, {}),
4671
- /* @__PURE__ */ jsx(IconButton, {
4672
- icon: full ? Minimize : Maximize,
4673
- label: full ? "Leave full screen" : "Full screen",
4674
- onPress: () => setFull(!full)
5364
+ /* @__PURE__ */ jsx(FullscreenButton, {
5365
+ full,
5366
+ setFull
4675
5367
  })
4676
5368
  ]
4677
5369
  }),
@@ -4698,6 +5390,70 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
4698
5390
  })
4699
5391
  ]
4700
5392
  }),
5393
+ mode === "difference" && /* @__PURE__ */ jsxs("div", {
5394
+ className: "grid gap-2",
5395
+ children: [/* @__PURE__ */ jsx(ToggleGroup, {
5396
+ label: "Difference style",
5397
+ options: [{
5398
+ value: "brightness",
5399
+ label: "Brightness"
5400
+ }, {
5401
+ value: "pixels",
5402
+ label: "Changed pixels"
5403
+ }],
5404
+ value: style,
5405
+ onChange: (v) => setStyle(v),
5406
+ size: "sm",
5407
+ className: "justify-self-start"
5408
+ }), style === "brightness" ? /* @__PURE__ */ jsxs("div", {
5409
+ className: "flex items-center gap-3",
5410
+ children: [
5411
+ /* @__PURE__ */ jsx("span", {
5412
+ className: "type-caption text-muted-foreground",
5413
+ children: "Amplify"
5414
+ }),
5415
+ /* @__PURE__ */ jsx(Slider, {
5416
+ "aria-label": "Amplify differences",
5417
+ value: amplify,
5418
+ onChange: setAmplify,
5419
+ min: 1,
5420
+ max: 8,
5421
+ hideValue: true,
5422
+ className: "flex-1"
5423
+ }),
5424
+ /* @__PURE__ */ jsxs("span", {
5425
+ className: "w-8 type-caption tabular-nums text-muted-foreground",
5426
+ children: [amplify, "×"]
5427
+ })
5428
+ ]
5429
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
5430
+ className: "flex items-center gap-3",
5431
+ children: [
5432
+ /* @__PURE__ */ jsx("span", {
5433
+ className: "type-caption text-muted-foreground",
5434
+ children: "Tolerance"
5435
+ }),
5436
+ /* @__PURE__ */ jsx(Slider, {
5437
+ "aria-label": "Tolerance for a changed pixel",
5438
+ value: tolerance,
5439
+ onChange: setTolerance,
5440
+ min: 0,
5441
+ max: 50,
5442
+ unit: "%",
5443
+ hideValue: true,
5444
+ className: "flex-1"
5445
+ }),
5446
+ /* @__PURE__ */ jsxs("span", {
5447
+ className: "w-10 type-caption tabular-nums text-muted-foreground",
5448
+ children: [tolerance, "%"]
5449
+ })
5450
+ ]
5451
+ }), /* @__PURE__ */ jsx("p", {
5452
+ role: "status",
5453
+ className: "type-body-sm text-muted-foreground",
5454
+ children: diff.status === "ready" ? diff.difference.differing === 0 ? "No pixels differ at this tolerance." : `${format.share(diff.difference.differing / diff.difference.total)} of pixels differ at this tolerance.` : diff.status === "loading" ? "Comparing pixels…" : ""
5455
+ })] })]
5456
+ }),
4701
5457
  mode === "blink" && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(ToggleGroup, {
4702
5458
  label: "Showing",
4703
5459
  options: [{
@@ -4717,6 +5473,91 @@ function Compare({ label, a, b, blind, missing, mode, onModeChange, modes = ALL_
4717
5473
  })
4718
5474
  });
4719
5475
  }
4720
- export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompositionBar, ContextMenu, DataTable, DataView, Dialog, Disclosure, Done, EmptyState, FIT, Field, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MIN_SCALE, MISSING, Menu, Meter, Metric, MetricStrip, NBSP, NativeSelect, NumberField, PageHeader, Popover, RowAction, SelectableGrid, SideNav, Skeleton, Slider, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, UndoBar, ViewportFrame, VirtualList, actualPixelsScale, buttonVariants, canFullscreen, clampViewport, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, fetchJson, fieldErrorsOf, format, formatChord, isReservedChord, isTypingTarget, labelOf, matchesChord, parseChord, parseSort, readErrorBody, serialiseSort, staleOf, toDate, toLoad, toast, toastTimeout, typeSteps, useActiveItem, useAsyncAction, useClientWork, useColorScheme, useCommands, useExpanded, useHotkeys, useInView, useInfiniteLoad, useJob, useLoad, useSelection, useSystemColorScheme, useUndoable, useViewport, zoomAt };
5476
+ // src/components/compare-grid.tsx
5477
+ var COLUMNS = {
5478
+ 2: "sm:grid-cols-2",
5479
+ 3: "sm:grid-cols-2 lg:grid-cols-3",
5480
+ 4: "sm:grid-cols-2 lg:grid-cols-4"
5481
+ };
5482
+ /** Many pictures in a grid, zoomed and panned together, and full screen. */
5483
+ function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys = true, className }) {
5484
+ const { viewport, setViewport } = useViewport();
5485
+ const [full, setFull] = React.useState(false);
5486
+ const key = items.map((i) => i.media.src).join("|");
5487
+ const [learned, setLearned] = React.useState(null);
5488
+ const natural = items[0]?.media.size ?? (learned?.key === key ? learned.size : null);
5489
+ const aspect = natural ? natural[0] / natural[1] : 3 / 2;
5490
+ const first = React.useRef(null);
5491
+ const zoom = useZoom({
5492
+ viewport,
5493
+ setViewport,
5494
+ frame: first,
5495
+ natural
5496
+ });
5497
+ const shortcuts = zoomShortcuts(zoom, full, setFull);
5498
+ useHotkeys(shortcuts, { enabled: keys });
5499
+ return /* @__PURE__ */ jsx(FullscreenFrame, {
5500
+ label,
5501
+ active: full,
5502
+ onActiveChange: setFull,
5503
+ className,
5504
+ children: /* @__PURE__ */ jsxs("section", {
5505
+ "aria-label": label,
5506
+ className: cn("grid gap-3", full && "min-h-0 flex-1 content-start overflow-auto"),
5507
+ children: [
5508
+ /* @__PURE__ */ jsxs(Toolbar, {
5509
+ label: "Zoom",
5510
+ className: "items-center gap-2",
5511
+ children: [
5512
+ /* @__PURE__ */ jsx(ZoomControls, {
5513
+ viewport,
5514
+ zoom,
5515
+ natural
5516
+ }),
5517
+ /* @__PURE__ */ jsx(ToolbarSeparator, {}),
5518
+ /* @__PURE__ */ jsx(FullscreenButton, {
5519
+ full,
5520
+ setFull
5521
+ })
5522
+ ]
5523
+ }),
5524
+ /* @__PURE__ */ jsx("div", {
5525
+ className: cn("grid gap-3", COLUMNS[columns]),
5526
+ children: items.map((c, i) => /* @__PURE__ */ jsxs("figure", {
5527
+ className: "grid content-start gap-1.5",
5528
+ children: [
5529
+ /* @__PURE__ */ jsx(Caption, {
5530
+ c,
5531
+ blind
5532
+ }),
5533
+ /* @__PURE__ */ jsx(ViewportFrame, {
5534
+ viewport,
5535
+ setViewport,
5536
+ aspect,
5537
+ label: blind ? `Picture ${c.label}` : c.label,
5538
+ ref: i === 0 ? first : void 0,
5539
+ children: /* @__PURE__ */ jsx(Picture, {
5540
+ c,
5541
+ blind,
5542
+ missing,
5543
+ onNatural: i === 0 ? (w, h) => setLearned({
5544
+ key,
5545
+ size: [w, h]
5546
+ }) : void 0
5547
+ })
5548
+ }),
5549
+ actions && /* @__PURE__ */ jsx("div", {
5550
+ className: "flex flex-wrap gap-2",
5551
+ children: actions(c)
5552
+ })
5553
+ ]
5554
+ }, c.id))
5555
+ }),
5556
+ keys && /* @__PURE__ */ jsx(KeysLegend, { shortcuts })
5557
+ ]
5558
+ })
5559
+ });
5560
+ }
5561
+ export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareGrid, CompositionBar, ContextMenu, DEFAULT_TOLERANCE, DataTable, DataView, 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, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, Popover, PropertyList, PropertyRow, RowAction, SelectableGrid, SideNav, Skeleton, Slider, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, UndoBar, ViewportFrame, VirtualList, actualPixelsScale, buttonVariants, canFullscreen, clampViewport, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, differences, fetchJson, fieldErrorsOf, format, formatChord, isReservedChord, isTypingTarget, labelOf, matchesAccept, matchesChord, parseChord, parseSort, readErrorBody, readPixels, resample, serialiseSort, staleOf, toDate, toLoad, toast, toastTimeout, typeSteps, useActiveItem, useAsyncAction, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHotkeys, useInView, useInfiniteLoad, useJob, useLoad, useSelection, useSystemColorScheme, useUndoable, useViewport, zoomAt };
4721
5562
 
4722
5563
  //# sourceMappingURL=index.js.map