@alexgorbatchev/shadcn 0.0.155 → 0.0.156

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.
@@ -23,9 +23,7 @@ import {
23
23
  } from "../../chunk-52aadmkc.js";
24
24
  import {
25
25
  Field2,
26
- FieldContent2,
27
- FieldLabel2,
28
- FieldDescription2
26
+ FieldLabel2
29
27
  } from "../../chunk-5ez5vgkn.js";
30
28
  import {
31
29
  NumberField2,
@@ -53,7 +51,7 @@ import { useIsoLayoutEffect as useIsoLayoutEffect2 } from "@base-ui/utils/useIso
53
51
  import { useMergedRefs as useMergedRefs2 } from "@base-ui/utils/useMergedRefs";
54
52
  import {
55
53
  useRef as useRef2,
56
- useState as useState2
54
+ useState as useState3
57
55
  } from "react";
58
56
 
59
57
  // src/components/image-viewer/ImageViewport.tsx
@@ -62,7 +60,8 @@ import { useMergedRefs } from "@base-ui/utils/useMergedRefs";
62
60
  import { useStableCallback } from "@base-ui/utils/useStableCallback";
63
61
  import {
64
62
  useEffect,
65
- useRef
63
+ useRef,
64
+ useState
66
65
  } from "react";
67
66
 
68
67
  // src/components/image-viewer/imageZoom.ts
@@ -122,7 +121,8 @@ function getImageStageSize(natural, viewport, zoom) {
122
121
  }
123
122
 
124
123
  // src/components/image-viewer/ImageViewport.tsx
125
- import { jsx } from "react/jsx-runtime";
124
+ import { jsx, jsxs } from "react/jsx-runtime";
125
+ var NO_SCROLL_HINTS = { left: false, right: false, top: false, bottom: false };
126
126
  var PAN_THRESHOLD = 4;
127
127
  var KEY_PAN_FRACTION = 0.1;
128
128
  var KEY_PAN_MINIMUM = 40;
@@ -166,6 +166,7 @@ function ImageViewport({
166
166
  const stageRef = useRef(null);
167
167
  const ref = useMergedRefs(elementRef, viewportRef);
168
168
  const viewportSize = useElementSize(elementRef);
169
+ const [scrollHints, setScrollHints] = useState(NO_SCROLL_HINTS);
169
170
  const pointers = useRef(new Map);
170
171
  const gesture = useRef(null);
171
172
  const suppressClick = useRef(false);
@@ -175,17 +176,28 @@ function ImageViewport({
175
176
  const stageHeight = stage?.height ?? 0;
176
177
  const canPanX = viewportSize !== undefined && stageWidth > viewportSize.width + 0.5;
177
178
  const canPanY = viewportSize !== undefined && stageHeight > viewportSize.height + 0.5;
179
+ const updateScrollHints = useStableCallback((viewport) => {
180
+ const next = zoom === "fit" ? NO_SCROLL_HINTS : {
181
+ left: viewport.scrollLeft > 1,
182
+ right: viewport.scrollLeft + viewport.clientWidth < viewport.scrollWidth - 1,
183
+ top: viewport.scrollTop > 1,
184
+ bottom: viewport.scrollTop + viewport.clientHeight < viewport.scrollHeight - 1
185
+ };
186
+ setScrollHints((current) => current.left === next.left && current.right === next.right && current.top === next.top && current.bottom === next.bottom ? current : next);
187
+ });
178
188
  useIsoLayoutEffect(() => {
179
189
  const viewport = elementRef.current;
180
190
  if (!viewport || stageWidth === 0 || stageHeight === 0)
181
191
  return;
182
192
  if (zoom === "fit") {
183
193
  center.current = { x: 0.5, y: 0.5 };
194
+ updateScrollHints(viewport);
184
195
  return;
185
196
  }
186
197
  viewport.scrollLeft = center.current.x * stageWidth - viewport.clientWidth / 2;
187
198
  viewport.scrollTop = center.current.y * stageHeight - viewport.clientHeight / 2;
188
- }, [center, stageHeight, stageWidth, zoom]);
199
+ updateScrollHints(viewport);
200
+ }, [center, stageHeight, stageWidth, updateScrollHints, zoom]);
189
201
  const changeZoom = useStableCallback((next, anchor) => {
190
202
  const viewport = elementRef.current;
191
203
  const stageElement = stageRef.current;
@@ -233,6 +245,7 @@ function ImageViewport({
233
245
  y: stageHeight > viewport.clientHeight ? (viewport.scrollTop + viewport.clientHeight / 2) / stageHeight : 0.5
234
246
  };
235
247
  }
248
+ updateScrollHints(viewport);
236
249
  onViewportScroll?.(viewport);
237
250
  }
238
251
  function handleKeyDown(event) {
@@ -354,37 +367,68 @@ function ImageViewport({
354
367
  event.preventDefault();
355
368
  event.stopPropagation();
356
369
  }
357
- return /* @__PURE__ */ jsx("div", {
358
- ref,
359
- role: "region",
360
- "aria-label": stage ? `${label}, ${formatImageZoom(stage.scale)}` : label,
361
- "aria-keyshortcuts": onZoomChange ? [STAGE_KEYS, stageKeyShortcuts].filter(Boolean).join(" ") : stageKeyShortcuts,
362
- tabIndex: 0,
363
- "data-slot": "image-viewport",
364
- "data-zoom": zoom,
365
- "data-scale": stage?.scale,
366
- "data-pannable": canPanX || canPanY ? "" : undefined,
367
- onScroll: handleScroll,
368
- onKeyDown: handleKeyDown,
369
- onPointerDown: handlePointerDown,
370
- onPointerMove: handlePointerMove,
371
- onPointerUp: handlePointerEnd,
372
- onPointerCancel: handlePointerEnd,
373
- onClickCapture: handleClickCapture,
374
- className: cn2("flex min-h-0 min-w-0 flex-1 touch-none overscroll-contain outline-none select-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-inset data-pannable:cursor-grab data-panning:cursor-grabbing", zoom === "fit" ? "overflow-hidden" : "overflow-auto"),
375
- children: fallback ?? /* @__PURE__ */ jsx("div", {
376
- ref: stageRef,
377
- "data-slot": "image-stage",
378
- className: "relative m-auto shrink-0",
379
- style: { width: stageWidth, height: stageHeight },
380
- children
381
- })
370
+ return /* @__PURE__ */ jsxs("div", {
371
+ "data-slot": "image-viewport-frame",
372
+ "data-scroll": "none",
373
+ className: "relative flex min-h-0 min-w-0 flex-1",
374
+ children: [
375
+ /* @__PURE__ */ jsx("div", {
376
+ ref,
377
+ role: "region",
378
+ "aria-label": stage ? `${label}, ${formatImageZoom(stage.scale)}` : label,
379
+ "aria-keyshortcuts": onZoomChange ? [STAGE_KEYS, stageKeyShortcuts].filter(Boolean).join(" ") : stageKeyShortcuts,
380
+ tabIndex: 0,
381
+ "data-slot": "image-viewport",
382
+ "data-zoom": zoom,
383
+ "data-scale": stage?.scale,
384
+ "data-pannable": canPanX || canPanY ? "" : undefined,
385
+ onScroll: handleScroll,
386
+ onKeyDown: handleKeyDown,
387
+ onPointerDown: handlePointerDown,
388
+ onPointerMove: handlePointerMove,
389
+ onPointerUp: handlePointerEnd,
390
+ onPointerCancel: handlePointerEnd,
391
+ onClickCapture: handleClickCapture,
392
+ className: cn2("flex min-h-0 min-w-0 flex-1 touch-none overscroll-contain outline-none select-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-inset data-pannable:cursor-grab data-panning:cursor-grabbing", zoom === "fit" ? "overflow-hidden" : "overflow-auto"),
393
+ children: fallback ?? /* @__PURE__ */ jsx("div", {
394
+ ref: stageRef,
395
+ "data-slot": "image-stage",
396
+ className: "relative m-auto shrink-0",
397
+ style: { width: stageWidth, height: stageHeight },
398
+ children
399
+ })
400
+ }),
401
+ scrollHints.left && /* @__PURE__ */ jsx("div", {
402
+ "data-slot": "image-viewport-scroll-hint",
403
+ "data-edge": "left",
404
+ "aria-hidden": "true",
405
+ className: "pointer-events-none absolute inset-y-0 left-0 w-5 border-l-2 border-primary/50 bg-gradient-to-r from-black/25 to-transparent"
406
+ }),
407
+ scrollHints.right && /* @__PURE__ */ jsx("div", {
408
+ "data-slot": "image-viewport-scroll-hint",
409
+ "data-edge": "right",
410
+ "aria-hidden": "true",
411
+ className: "pointer-events-none absolute inset-y-0 right-0 w-5 border-r-2 border-primary/50 bg-gradient-to-l from-black/25 to-transparent"
412
+ }),
413
+ scrollHints.top && /* @__PURE__ */ jsx("div", {
414
+ "data-slot": "image-viewport-scroll-hint",
415
+ "data-edge": "top",
416
+ "aria-hidden": "true",
417
+ className: "pointer-events-none absolute inset-x-0 top-0 h-5 border-t-2 border-primary/50 bg-gradient-to-b from-black/25 to-transparent"
418
+ }),
419
+ scrollHints.bottom && /* @__PURE__ */ jsx("div", {
420
+ "data-slot": "image-viewport-scroll-hint",
421
+ "data-edge": "bottom",
422
+ "aria-hidden": "true",
423
+ className: "pointer-events-none absolute inset-x-0 bottom-0 h-5 border-b-2 border-primary/50 bg-gradient-to-t from-black/25 to-transparent"
424
+ })
425
+ ]
382
426
  });
383
427
  }
384
428
 
385
429
  // src/components/image-viewer/ImageZoomControl.tsx
386
430
  import { MinusIcon, PlusIcon } from "lucide-react";
387
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
431
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
388
432
  function ImageZoomControl({
389
433
  zoom,
390
434
  scale,
@@ -394,7 +438,7 @@ function ImageZoomControl({
394
438
  density
395
439
  }) {
396
440
  const isMeasured = scale !== undefined && scales !== undefined;
397
- return /* @__PURE__ */ jsxs("div", {
441
+ return /* @__PURE__ */ jsxs2("div", {
398
442
  role: "group",
399
443
  "aria-label": label,
400
444
  "data-slot": "image-zoom-control",
@@ -454,9 +498,9 @@ function ImageZoomControl({
454
498
  }
455
499
 
456
500
  // src/components/image-viewer/hooks/useImageLoad.ts
457
- import { useState } from "react";
501
+ import { useState as useState2 } from "react";
458
502
  function useImageLoad(src) {
459
- const [state, setState] = useState({ src, status: "loading" });
503
+ const [state, setState] = useState2({ src, status: "loading" });
460
504
  const handlers = {
461
505
  onLoad: (event) => {
462
506
  const image = event.currentTarget;
@@ -468,7 +512,7 @@ function useImageLoad(src) {
468
512
  }
469
513
 
470
514
  // src/components/image-viewer/ImageViewer.tsx
471
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
515
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
472
516
  function ImageViewer({
473
517
  src,
474
518
  alt,
@@ -501,7 +545,7 @@ function ImageViewer({
501
545
  const mergedStageRef = useMergedRefs2(viewportRef, stageRef);
502
546
  const viewportSize = useElementSize(viewportRef);
503
547
  const [image, imageHandlers] = useImageLoad(src);
504
- const [openingZoom, setOpeningZoom] = useState2();
548
+ const [openingZoom, setOpeningZoom] = useState3();
505
549
  const naturalSize = image.size;
506
550
  const scales = naturalSize && viewportSize ? getImageZoomScales(naturalSize, viewportSize) : undefined;
507
551
  useIsoLayoutEffect2(() => {
@@ -520,7 +564,7 @@ function ImageViewer({
520
564
  setOpeningZoom(next);
521
565
  onZoomChange?.(next);
522
566
  }
523
- return /* @__PURE__ */ jsxs2("div", {
567
+ return /* @__PURE__ */ jsxs3("div", {
524
568
  "data-slot": "image-viewer",
525
569
  "data-scroll": "none",
526
570
  "data-density": density,
@@ -528,7 +572,7 @@ function ImageViewer({
528
572
  "data-status": image.status,
529
573
  className: "flex size-full min-h-0 min-w-0 flex-1 flex-col gap-2",
530
574
  children: [
531
- (showZoomControl || toolbar !== undefined) && /* @__PURE__ */ jsxs2("div", {
575
+ (showZoomControl || toolbar !== undefined) && /* @__PURE__ */ jsxs3("div", {
532
576
  "data-slot": "image-viewer-toolbar",
533
577
  className: "flex shrink-0 flex-wrap items-center gap-control-gap *:shrink-0",
534
578
  children: [
@@ -542,7 +586,7 @@ function ImageViewer({
542
586
  toolbar
543
587
  ]
544
588
  }),
545
- /* @__PURE__ */ jsxs2(ImageViewport, {
589
+ /* @__PURE__ */ jsxs3(ImageViewport, {
546
590
  label: label ?? alt,
547
591
  zoom: shownZoom,
548
592
  naturalSize,
@@ -586,7 +630,7 @@ function ImageViewer({
586
630
  });
587
631
  }
588
632
  // src/components/image-viewer/ImageZoomToggle.tsx
589
- import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
633
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
590
634
  function ImageZoomToggle({
591
635
  zoom,
592
636
  onZoomChange,
@@ -597,7 +641,7 @@ function ImageZoomToggle({
597
641
  disabled = false,
598
642
  density
599
643
  }) {
600
- return /* @__PURE__ */ jsxs3(ToggleGroup2, {
644
+ return /* @__PURE__ */ jsxs4(ToggleGroup2, {
601
645
  "aria-label": label,
602
646
  value: zoom === "fit" ? ["fit"] : zoom === 1 ? ["original"] : [],
603
647
  onValueChange: (value) => {
@@ -624,7 +668,7 @@ function ImageZoomToggle({
624
668
  });
625
669
  }
626
670
  // src/components/image-viewer/ImageRegionSelect.tsx
627
- import { useRef as useRef3, useState as useState3 } from "react";
671
+ import { useRef as useRef3, useState as useState4 } from "react";
628
672
 
629
673
  // src/components/image-viewer/getNormalizedImagePoint.ts
630
674
  function clampUnit2(value) {
@@ -704,6 +748,7 @@ var imageRegionMarkerVariants = cva("pointer-events-none absolute rounded-xs sha
704
748
  });
705
749
  function ImageRegionMarker({
706
750
  variant,
751
+ active = false,
707
752
  region,
708
753
  className,
709
754
  style,
@@ -712,7 +757,8 @@ function ImageRegionMarker({
712
757
  return /* @__PURE__ */ jsx5("div", {
713
758
  "data-slot": "image-region-marker",
714
759
  "data-variant": variant ?? "comment",
715
- className: cn2(imageRegionMarkerVariants({ variant }), className),
760
+ "data-active": active ? "" : undefined,
761
+ className: cn2(imageRegionMarkerVariants({ variant }), active && "z-10 outline-[3px]", active && variant === "difference" && "bg-warning/20", className),
716
762
  style: region ? { ...style, ...region } : style,
717
763
  ...props
718
764
  });
@@ -752,10 +798,10 @@ function toBox(region) {
752
798
  height: `${region.height * 100}%`
753
799
  };
754
800
  }
755
- function ImageRegionSelect({ region, onRegionChange }) {
801
+ function ImageRegionSelect({ region, onRegionChange, onStart }) {
756
802
  const drag = useRef3(null);
757
803
  const pendingClick = useRef3(null);
758
- const [draft, setDraft] = useState3();
804
+ const [draft, setDraft] = useState4();
759
805
  const point = (event) => getNormalizedImagePoint(event, event.currentTarget.getBoundingClientRect());
760
806
  function cancel() {
761
807
  drag.current = null;
@@ -786,7 +832,9 @@ function ImageRegionSelect({ region, onRegionChange }) {
786
832
  return;
787
833
  event.preventDefault();
788
834
  event.currentTarget.setPointerCapture(event.pointerId);
789
- drag.current = { pointerId: event.pointerId, start: point(event) };
835
+ const start = point(event);
836
+ onStart?.(start);
837
+ drag.current = { pointerId: event.pointerId, start };
790
838
  },
791
839
  onPointerMove: (event) => {
792
840
  const current = drag.current;
@@ -825,7 +873,7 @@ function ImageRegionSelect({ region, onRegionChange }) {
825
873
  }
826
874
  // src/components/image-viewer/ImageRegionFields.tsx
827
875
  import { useId } from "react";
828
- import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
876
+ import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
829
877
  var FIELDS = [
830
878
  ["x", "Left"],
831
879
  ["y", "Top"],
@@ -843,14 +891,14 @@ function ImageRegionFields({
843
891
  density
844
892
  }) {
845
893
  const id = useId();
846
- return /* @__PURE__ */ jsxs4("div", {
894
+ return /* @__PURE__ */ jsxs5("div", {
847
895
  role: "group",
848
896
  "aria-label": label,
849
897
  "data-slot": "image-region-fields",
850
898
  "data-density": density,
851
899
  className: cn2("flex flex-wrap items-end gap-control-gap", className),
852
900
  children: [
853
- FIELDS.map(([key, name]) => /* @__PURE__ */ jsxs4(Field2, {
901
+ FIELDS.map(([key, name]) => /* @__PURE__ */ jsxs5(Field2, {
854
902
  className: "w-20",
855
903
  children: [
856
904
  /* @__PURE__ */ jsx7(FieldLabel2, {
@@ -888,9 +936,66 @@ function ImageRegionFields({
888
936
  });
889
937
  }
890
938
  // src/components/image-viewer/ImageGallery.tsx
939
+ import { useControlled as useControlled2 } from "@base-ui/utils/useControlled";
891
940
  import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
892
- import { useState as useState4 } from "react";
893
- import { jsx as jsx8, jsxs as jsxs5, Fragment } from "react/jsx-runtime";
941
+ import {
942
+ useRef as useRef4,
943
+ useState as useState5
944
+ } from "react";
945
+ import { jsx as jsx8, jsxs as jsxs6, Fragment } from "react/jsx-runtime";
946
+ function CompareAllPane({
947
+ item,
948
+ zoom,
949
+ center,
950
+ onZoomChange,
951
+ viewportRef,
952
+ onViewportScroll,
953
+ footer
954
+ }) {
955
+ const [image, imageHandlers] = useImageLoad(item.src);
956
+ return /* @__PURE__ */ jsxs6("section", {
957
+ "aria-label": item.label,
958
+ "data-slot": "image-gallery-compare-pane",
959
+ className: "flex min-h-64 min-w-0 flex-col overflow-hidden rounded-md border border-border bg-background @2xl:min-h-0",
960
+ children: [
961
+ /* @__PURE__ */ jsx8("div", {
962
+ "data-slot": "image-gallery-compare-header",
963
+ className: "flex h-control shrink-0 items-center justify-between gap-2 border-b border-border px-control-x text-xs font-medium text-muted-foreground",
964
+ children: /* @__PURE__ */ jsx8("span", {
965
+ className: "truncate",
966
+ children: item.label
967
+ })
968
+ }),
969
+ /* @__PURE__ */ jsx8(ImageViewport, {
970
+ label: item.label,
971
+ zoom,
972
+ naturalSize: image.size,
973
+ center,
974
+ onZoomChange,
975
+ viewportRef,
976
+ onViewportScroll,
977
+ fallback: image.status === "error" ? /* @__PURE__ */ jsx8("p", {
978
+ className: "m-auto p-panel text-center text-sm text-muted-foreground",
979
+ children: "Image could not be loaded."
980
+ }) : undefined,
981
+ children: /* @__PURE__ */ jsx8("img", {
982
+ src: item.src,
983
+ alt: item.alt,
984
+ draggable: false,
985
+ "data-slot": "image-gallery-compare-image",
986
+ className: "block size-full outline-1 -outline-offset-1 outline-media-edge select-none",
987
+ onLoad: imageHandlers.onLoad,
988
+ onError: imageHandlers.onError
989
+ })
990
+ }),
991
+ footer !== undefined && footer !== null && /* @__PURE__ */ jsx8("div", {
992
+ "data-slot": "image-gallery-compare-footer",
993
+ className: "flex shrink-0 items-center justify-between gap-2 border-t border-border p-2",
994
+ children: footer
995
+ })
996
+ ]
997
+ });
998
+ }
894
999
  function isFitted(stage) {
895
1000
  return stage.closest("[data-slot=image-viewer]")?.getAttribute("data-zoom") === "fit";
896
1001
  }
@@ -908,11 +1013,32 @@ function ImageGallery({
908
1013
  stageRef,
909
1014
  onStageKeyDown,
910
1015
  stageKeyShortcuts,
1016
+ compareAll: compareAllProp,
1017
+ defaultCompareAll = false,
1018
+ onCompareAllChange,
1019
+ allowCompareAll,
1020
+ compareAllLabel = "Compare all",
1021
+ renderItemFooter,
911
1022
  density
912
1023
  }) {
913
- const [announcement, setAnnouncement] = useState4("");
1024
+ const [announcement, setAnnouncement] = useState5("");
1025
+ const [compareZoom, setCompareZoom] = useState5("fit");
1026
+ const [isComparingAll, setCompareAllState] = useControlled2({
1027
+ controlled: compareAllProp,
1028
+ default: defaultCompareAll,
1029
+ name: "ImageGallery",
1030
+ state: "compareAll"
1031
+ });
1032
+ const compareCenter = useRef4({ x: 0.5, y: 0.5 });
1033
+ const compareViewports = useRef4(new Map);
1034
+ const expectedScrollRef = useRef4(new WeakMap);
914
1035
  const item = items[index];
915
1036
  const count = items.length;
1037
+ const canCompareAll = count > 1 && (allowCompareAll ?? (compareAllProp !== undefined || onCompareAllChange !== undefined || renderItemFooter !== undefined));
1038
+ function setCompareAll(next) {
1039
+ setCompareAllState(next);
1040
+ onCompareAllChange?.(next);
1041
+ }
916
1042
  function step(next) {
917
1043
  const target = items[next];
918
1044
  if (!target)
@@ -931,13 +1057,84 @@ function ImageGallery({
931
1057
  event.preventDefault();
932
1058
  step(event.key === "ArrowLeft" ? index - 1 : index + 1);
933
1059
  }
1060
+ function syncCompareScroll(sourceKey, source) {
1061
+ const expected = expectedScrollRef.current.get(source);
1062
+ expectedScrollRef.current.delete(source);
1063
+ if (expected?.left === source.scrollLeft && expected.top === source.scrollTop)
1064
+ return;
1065
+ for (const [key, target] of compareViewports.current) {
1066
+ if (key === sourceKey)
1067
+ continue;
1068
+ const previous = { left: target.scrollLeft, top: target.scrollTop };
1069
+ target.scrollLeft = source.scrollLeft;
1070
+ target.scrollTop = source.scrollTop;
1071
+ if (target.scrollLeft !== previous.left || target.scrollTop !== previous.top) {
1072
+ expectedScrollRef.current.set(target, { left: target.scrollLeft, top: target.scrollTop });
1073
+ }
1074
+ }
1075
+ }
934
1076
  if (!item)
935
1077
  return /* @__PURE__ */ jsx8("div", {
936
1078
  "data-slot": "image-gallery",
937
1079
  "data-density": density
938
1080
  });
939
- return /* @__PURE__ */ jsxs5("div", {
1081
+ if (canCompareAll && isComparingAll) {
1082
+ return /* @__PURE__ */ jsxs6("div", {
1083
+ "data-slot": "image-gallery",
1084
+ "data-mode": "compare-all",
1085
+ "data-scroll": "none",
1086
+ "data-density": density,
1087
+ className: "@container flex size-full min-h-0 min-w-0 flex-1 flex-col gap-2",
1088
+ children: [
1089
+ /* @__PURE__ */ jsxs6("div", {
1090
+ "data-slot": "image-gallery-toolbar",
1091
+ className: "flex shrink-0 flex-wrap items-center gap-control-gap *:shrink-0",
1092
+ children: [
1093
+ /* @__PURE__ */ jsx8(ImageZoomToggle, {
1094
+ zoom: compareZoom,
1095
+ onZoomChange: setCompareZoom,
1096
+ density
1097
+ }),
1098
+ /* @__PURE__ */ jsx8(Toggle2, {
1099
+ variant: "outline",
1100
+ size: "sm",
1101
+ density,
1102
+ pressed: true,
1103
+ onPressedChange: setCompareAll,
1104
+ children: compareAllLabel
1105
+ })
1106
+ ]
1107
+ }),
1108
+ /* @__PURE__ */ jsx8("div", {
1109
+ "data-slot": "image-gallery-compare-grid",
1110
+ className: cn2("grid min-h-0 min-w-0 flex-1 grid-cols-1 gap-3 overflow-y-auto @2xl:overflow-hidden", count === 2 ? "@2xl:grid-cols-2" : "@xl:grid-cols-2 @3xl:grid-cols-3"),
1111
+ children: items.map((entry, entryIndex) => /* @__PURE__ */ jsx8(CompareAllPane, {
1112
+ item: entry,
1113
+ zoom: compareZoom,
1114
+ center: compareCenter,
1115
+ onZoomChange: setCompareZoom,
1116
+ viewportRef: (node) => {
1117
+ if (node)
1118
+ compareViewports.current.set(entry.key, node);
1119
+ else
1120
+ compareViewports.current.delete(entry.key);
1121
+ },
1122
+ onViewportScroll: (viewport) => syncCompareScroll(entry.key, viewport),
1123
+ footer: renderItemFooter?.(entry, entryIndex)
1124
+ }, entry.key))
1125
+ }),
1126
+ /* @__PURE__ */ jsx8("p", {
1127
+ role: "status",
1128
+ "data-slot": "image-gallery-status",
1129
+ className: "sr-only",
1130
+ children: announcement
1131
+ })
1132
+ ]
1133
+ });
1134
+ }
1135
+ return /* @__PURE__ */ jsxs6("div", {
940
1136
  "data-slot": "image-gallery",
1137
+ "data-mode": "single",
941
1138
  "data-scroll": "none",
942
1139
  "data-density": density,
943
1140
  className: "flex size-full min-h-0 min-w-0 flex-1 flex-col",
@@ -954,9 +1151,9 @@ function ImageGallery({
954
1151
  onStageKeyDown: handleStageKey,
955
1152
  stageKeyShortcuts,
956
1153
  density,
957
- toolbar: /* @__PURE__ */ jsxs5(Fragment, {
1154
+ toolbar: /* @__PURE__ */ jsxs6(Fragment, {
958
1155
  children: [
959
- /* @__PURE__ */ jsxs5("div", {
1156
+ /* @__PURE__ */ jsxs6("div", {
960
1157
  role: "group",
961
1158
  "aria-label": "Images",
962
1159
  "data-slot": "image-gallery-stepper",
@@ -965,12 +1162,13 @@ function ImageGallery({
965
1162
  /* @__PURE__ */ jsx8(Button2, {
966
1163
  variant: "outline",
967
1164
  size: "icon-sm",
1165
+ density,
968
1166
  "aria-label": previousLabel,
969
1167
  disabledReason: index === 0 ? "This is the first image" : undefined,
970
1168
  onClick: () => step(index - 1),
971
1169
  children: /* @__PURE__ */ jsx8(ChevronLeftIcon, {})
972
1170
  }),
973
- /* @__PURE__ */ jsxs5("span", {
1171
+ /* @__PURE__ */ jsxs6("span", {
974
1172
  "data-slot": "image-gallery-position",
975
1173
  className: "text-xs text-muted-foreground tabular-nums",
976
1174
  children: [
@@ -982,6 +1180,7 @@ function ImageGallery({
982
1180
  /* @__PURE__ */ jsx8(Button2, {
983
1181
  variant: "outline",
984
1182
  size: "icon-sm",
1183
+ density,
985
1184
  "aria-label": nextLabel,
986
1185
  disabledReason: index === count - 1 ? "This is the last image" : undefined,
987
1186
  onClick: () => step(index + 1),
@@ -989,6 +1188,14 @@ function ImageGallery({
989
1188
  })
990
1189
  ]
991
1190
  }),
1191
+ canCompareAll && /* @__PURE__ */ jsx8(Toggle2, {
1192
+ variant: "outline",
1193
+ size: "sm",
1194
+ density,
1195
+ pressed: false,
1196
+ onPressedChange: setCompareAll,
1197
+ children: compareAllLabel
1198
+ }),
992
1199
  toolbar
993
1200
  ]
994
1201
  })
@@ -1003,7 +1210,7 @@ function ImageGallery({
1003
1210
  });
1004
1211
  }
1005
1212
  // src/components/image-viewer/MediaShell.tsx
1006
- import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
1213
+ import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
1007
1214
  function MediaShell({
1008
1215
  open,
1009
1216
  onOpenChange,
@@ -1015,12 +1222,12 @@ function MediaShell({
1015
1222
  return /* @__PURE__ */ jsx9(Dialog2, {
1016
1223
  open,
1017
1224
  onOpenChange,
1018
- children: /* @__PURE__ */ jsxs6(DialogContent2, {
1225
+ children: /* @__PURE__ */ jsxs7(DialogContent2, {
1019
1226
  size: "fullscreen",
1020
1227
  density,
1021
1228
  "data-slot": "media-shell",
1022
1229
  children: [
1023
- /* @__PURE__ */ jsxs6(DialogHeader2, {
1230
+ /* @__PURE__ */ jsxs7(DialogHeader2, {
1024
1231
  children: [
1025
1232
  /* @__PURE__ */ jsx9(DialogTitle2, {
1026
1233
  className: "truncate",
@@ -1042,21 +1249,21 @@ function MediaShell({
1042
1249
  });
1043
1250
  }
1044
1251
  // src/components/image-viewer/ImageComparison.tsx
1045
- import { useControlled as useControlled2 } from "@base-ui/utils/useControlled";
1046
- import { useRef as useRef5, useState as useState6 } from "react";
1252
+ import { useControlled as useControlled3 } from "@base-ui/utils/useControlled";
1253
+ import { useRef as useRef6, useState as useState7 } from "react";
1047
1254
 
1048
1255
  // src/components/image-viewer/ImageComparisonToolbar.tsx
1049
- import { Columns2Icon, Rows2Icon } from "lucide-react";
1256
+ import { ChevronLeftIcon as ChevronLeftIcon2, ChevronRightIcon as ChevronRightIcon2, Columns2Icon, Rows2Icon } from "lucide-react";
1050
1257
  import { useId as useId2 } from "react";
1051
- import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
1258
+ import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
1052
1259
  function ToolbarSection({ title, titleId, children }) {
1053
- return /* @__PURE__ */ jsxs7("div", {
1260
+ return /* @__PURE__ */ jsxs8("div", {
1054
1261
  "data-slot": "image-comparison-toolbar-section",
1055
- className: "flex min-w-0 flex-col gap-1.5",
1262
+ className: "flex shrink-0 items-center",
1056
1263
  children: [
1057
1264
  /* @__PURE__ */ jsx10("span", {
1058
1265
  id: titleId,
1059
- className: "sr-only text-xs font-medium text-muted-foreground @3xl:not-sr-only",
1266
+ className: "sr-only",
1060
1267
  children: title
1061
1268
  }),
1062
1269
  children
@@ -1096,28 +1303,34 @@ function ImageComparisonToolbar({
1096
1303
  showDifferences,
1097
1304
  onShowDifferencesChange,
1098
1305
  differences,
1306
+ activeRegionIndex,
1307
+ onStepChange,
1099
1308
  onPeekChange,
1100
1309
  beforeLabel,
1101
1310
  afterLabel,
1102
1311
  beforeSize,
1103
1312
  afterSize,
1313
+ toolbar,
1104
1314
  density
1105
1315
  }) {
1106
1316
  const id = useId2();
1107
1317
  const isUnavailable = differences.status === "unavailable";
1318
+ const regionCount = showDifferences && differences.status === "ready" ? differences.diff.regions.length : 0;
1319
+ const hasStepper = regionCount > 0;
1108
1320
  const releasePeek = () => onPeekChange(false);
1321
+ const statusText = describeDifferences(differences, showDifferences);
1109
1322
  const sizeMismatch = beforeSize && afterSize && (beforeSize.width !== afterSize.width || beforeSize.height !== afterSize.height) ? `Sizes differ: ${beforeLabel} ${formatSize(beforeSize)}, ${afterLabel} ${formatSize(afterSize)}. ` + `${beforeLabel} is fitted inside the ${afterLabel} image box.` : undefined;
1110
- return /* @__PURE__ */ jsxs7("div", {
1323
+ return /* @__PURE__ */ jsxs8("div", {
1111
1324
  role: "group",
1112
1325
  "aria-label": "Comparison controls",
1113
1326
  "data-slot": "image-comparison-toolbar",
1114
1327
  "data-density": density,
1115
- className: "flex shrink-0 flex-wrap items-end gap-x-panel gap-y-3 border-t border-border p-panel-sm @3xl:w-72 @3xl:flex-col @3xl:flex-nowrap @3xl:items-stretch @3xl:overflow-y-auto @3xl:border-t-0 @3xl:border-s",
1328
+ className: "flex shrink-0 flex-wrap items-center gap-x-2 gap-y-2 border-b border-border px-panel-sm py-2",
1116
1329
  children: [
1117
1330
  /* @__PURE__ */ jsx10(ToolbarSection, {
1118
1331
  title: "Mode",
1119
1332
  titleId: `${id}-mode`,
1120
- children: /* @__PURE__ */ jsxs7(ToggleGroup2, {
1333
+ children: /* @__PURE__ */ jsxs8(ToggleGroup2, {
1121
1334
  "aria-labelledby": `${id}-mode`,
1122
1335
  required: true,
1123
1336
  value: [mode],
@@ -1125,6 +1338,7 @@ function ImageComparisonToolbar({
1125
1338
  variant: "outline",
1126
1339
  size: "sm",
1127
1340
  spacing: 0,
1341
+ density,
1128
1342
  children: [
1129
1343
  /* @__PURE__ */ jsx10(ToggleGroupItem2, {
1130
1344
  value: "toggle",
@@ -1144,7 +1358,7 @@ function ImageComparisonToolbar({
1144
1358
  /* @__PURE__ */ jsx10(ToolbarSection, {
1145
1359
  title: "Shown image",
1146
1360
  titleId: `${id}-side`,
1147
- children: /* @__PURE__ */ jsxs7(ToggleGroup2, {
1361
+ children: /* @__PURE__ */ jsxs8(ToggleGroup2, {
1148
1362
  "aria-labelledby": `${id}-side`,
1149
1363
  "aria-keyshortcuts": "B A",
1150
1364
  required: true,
@@ -1154,6 +1368,7 @@ function ImageComparisonToolbar({
1154
1368
  size: "sm",
1155
1369
  spacing: 0,
1156
1370
  disabled: mode !== "toggle",
1371
+ density,
1157
1372
  children: [
1158
1373
  /* @__PURE__ */ jsx10(ToggleGroupItem2, {
1159
1374
  value: "before",
@@ -1169,7 +1384,7 @@ function ImageComparisonToolbar({
1169
1384
  /* @__PURE__ */ jsx10(ToolbarSection, {
1170
1385
  title: "Orientation",
1171
1386
  titleId: `${id}-orientation`,
1172
- children: /* @__PURE__ */ jsxs7(ToggleGroup2, {
1387
+ children: /* @__PURE__ */ jsxs8(ToggleGroup2, {
1173
1388
  "aria-labelledby": `${id}-orientation`,
1174
1389
  required: true,
1175
1390
  value: [orientation],
@@ -1178,8 +1393,9 @@ function ImageComparisonToolbar({
1178
1393
  size: "sm",
1179
1394
  spacing: 0,
1180
1395
  disabled: mode !== "side-by-side",
1396
+ density,
1181
1397
  children: [
1182
- /* @__PURE__ */ jsxs7(ToggleGroupItem2, {
1398
+ /* @__PURE__ */ jsxs8(ToggleGroupItem2, {
1183
1399
  value: "horizontal",
1184
1400
  children: [
1185
1401
  /* @__PURE__ */ jsx10(Columns2Icon, {
@@ -1188,7 +1404,7 @@ function ImageComparisonToolbar({
1188
1404
  "Horizontal"
1189
1405
  ]
1190
1406
  }),
1191
- /* @__PURE__ */ jsxs7(ToggleGroupItem2, {
1407
+ /* @__PURE__ */ jsxs8(ToggleGroupItem2, {
1192
1408
  value: "vertical",
1193
1409
  children: [
1194
1410
  /* @__PURE__ */ jsx10(Rows2Icon, {
@@ -1205,14 +1421,16 @@ function ImageComparisonToolbar({
1205
1421
  titleId: `${id}-zoom`,
1206
1422
  children: /* @__PURE__ */ jsx10(ImageZoomToggle, {
1207
1423
  zoom,
1208
- onZoomChange
1424
+ onZoomChange,
1425
+ density
1209
1426
  })
1210
1427
  }),
1211
1428
  /* @__PURE__ */ jsx10(Button2, {
1212
1429
  variant: "outline",
1213
1430
  size: "sm",
1431
+ density,
1214
1432
  disabled: mode !== "toggle",
1215
- className: "touch-none",
1433
+ className: "shrink-0 touch-none",
1216
1434
  onPointerDown: (event) => {
1217
1435
  if (event.button === 0)
1218
1436
  onPeekChange(true);
@@ -1232,51 +1450,86 @@ function ImageComparisonToolbar({
1232
1450
  onContextMenu: (event) => event.preventDefault(),
1233
1451
  children: `Hold to show ${side === "before" ? "after" : "before"}`
1234
1452
  }),
1235
- /* @__PURE__ */ jsxs7(Field2, {
1236
- orientation: "horizontal",
1453
+ /* @__PURE__ */ jsxs8("div", {
1454
+ className: "flex shrink-0 flex-wrap items-center gap-2",
1237
1455
  children: [
1238
- /* @__PURE__ */ jsx10(Switch2, {
1239
- id: `${id}-differences`,
1240
- "aria-describedby": `${id}-differences-status`,
1241
- checked: showDifferences && !isUnavailable,
1242
- disabled: isUnavailable,
1243
- onCheckedChange: onShowDifferencesChange
1244
- }),
1245
- /* @__PURE__ */ jsxs7(FieldContent2, {
1456
+ /* @__PURE__ */ jsxs8("div", {
1457
+ className: "flex items-center gap-1.5",
1246
1458
  children: [
1247
- /* @__PURE__ */ jsx10(FieldLabel2, {
1459
+ /* @__PURE__ */ jsx10(Switch2, {
1460
+ id: `${id}-differences`,
1461
+ "aria-describedby": `${id}-differences-status`,
1462
+ checked: showDifferences && !isUnavailable,
1463
+ disabled: isUnavailable,
1464
+ onCheckedChange: onShowDifferencesChange
1465
+ }),
1466
+ /* @__PURE__ */ jsx10("label", {
1248
1467
  htmlFor: `${id}-differences`,
1468
+ className: "cursor-pointer text-sm leading-none font-medium whitespace-nowrap select-none",
1249
1469
  children: "Highlight differences"
1470
+ })
1471
+ ]
1472
+ }),
1473
+ showDifferences && differences.status === "ready" && /* @__PURE__ */ jsxs8("span", {
1474
+ "data-slot": "image-comparison-legend",
1475
+ className: "flex items-center gap-1.5 text-xs whitespace-nowrap text-muted-foreground",
1476
+ children: [
1477
+ /* @__PURE__ */ jsx10("span", {
1478
+ "aria-hidden": "true",
1479
+ className: "mx-[3px] size-2.5 shrink-0 rounded-xs bg-warning/10 ring-1 ring-background outline-2 outline-offset-1 outline-warning"
1250
1480
  }),
1251
- showDifferences && differences.status === "ready" && /* @__PURE__ */ jsxs7(FieldDescription2, {
1252
- "data-slot": "image-comparison-legend",
1253
- className: "flex items-center gap-1.5",
1481
+ "Changed region"
1482
+ ]
1483
+ }),
1484
+ hasStepper && /* @__PURE__ */ jsxs8("div", {
1485
+ role: "group",
1486
+ "aria-label": "Changed regions",
1487
+ "data-slot": "image-comparison-stepper",
1488
+ className: "flex items-center gap-1.5 border-s border-border ps-2",
1489
+ children: [
1490
+ /* @__PURE__ */ jsxs8("span", {
1491
+ "data-slot": "image-comparison-change-count",
1492
+ className: "text-xs whitespace-nowrap text-muted-foreground tabular-nums",
1254
1493
  children: [
1255
- /* @__PURE__ */ jsx10("span", {
1256
- "aria-hidden": "true",
1257
- className: "mx-[3px] size-2.5 shrink-0 rounded-xs bg-warning/10 ring-1 ring-background outline-2 outline-offset-1 outline-warning"
1258
- }),
1259
- "Changed region"
1494
+ "Change ",
1495
+ activeRegionIndex + 1,
1496
+ " of ",
1497
+ regionCount
1260
1498
  ]
1499
+ }),
1500
+ /* @__PURE__ */ jsx10(Button2, {
1501
+ variant: "outline",
1502
+ size: "icon-sm",
1503
+ density,
1504
+ "aria-label": "Previous change",
1505
+ "aria-keyshortcuts": "Shift+N",
1506
+ onClick: () => onStepChange(-1),
1507
+ children: /* @__PURE__ */ jsx10(ChevronLeftIcon2, {})
1508
+ }),
1509
+ /* @__PURE__ */ jsx10(Button2, {
1510
+ variant: "outline",
1511
+ size: "icon-sm",
1512
+ density,
1513
+ "aria-label": "Next change",
1514
+ "aria-keyshortcuts": "N",
1515
+ onClick: () => onStepChange(1),
1516
+ children: /* @__PURE__ */ jsx10(ChevronRightIcon2, {})
1261
1517
  })
1262
1518
  ]
1263
- })
1264
- ]
1265
- }),
1266
- /* @__PURE__ */ jsxs7("div", {
1267
- "data-slot": "image-comparison-status",
1268
- className: "flex min-w-0 flex-col gap-1 text-xs text-muted-foreground",
1269
- children: [
1519
+ }),
1270
1520
  /* @__PURE__ */ jsx10("p", {
1271
1521
  id: `${id}-differences-status`,
1272
1522
  role: "status",
1273
- children: describeDifferences(differences, showDifferences)
1274
- }),
1275
- sizeMismatch && /* @__PURE__ */ jsx10("p", {
1276
- "data-slot": "image-comparison-size-mismatch",
1277
- children: sizeMismatch
1523
+ className: hasStepper || !statusText ? "sr-only" : "text-xs text-muted-foreground",
1524
+ children: statusText
1278
1525
  })
1279
1526
  ]
1527
+ }),
1528
+ toolbar,
1529
+ sizeMismatch && /* @__PURE__ */ jsx10("p", {
1530
+ "data-slot": "image-comparison-size-mismatch",
1531
+ className: "w-full text-xs text-muted-foreground",
1532
+ children: sizeMismatch
1280
1533
  })
1281
1534
  ]
1282
1535
  });
@@ -1287,21 +1540,42 @@ import { jsx as jsx11 } from "react/jsx-runtime";
1287
1540
  function toPercent2(value, total) {
1288
1541
  return `${value / total * 100}%`;
1289
1542
  }
1290
- function ImageDifferenceOverlay({ diff }) {
1543
+ function ImageDifferenceOverlay({
1544
+ diff,
1545
+ activeIndex,
1546
+ onCommentRegion
1547
+ }) {
1548
+ const count = diff.regions.length;
1291
1549
  return /* @__PURE__ */ jsx11("div", {
1292
1550
  "data-slot": "image-difference-overlay",
1293
- "aria-hidden": "true",
1551
+ "aria-hidden": onCommentRegion ? undefined : "true",
1294
1552
  className: "pointer-events-none absolute inset-0",
1295
- children: diff.regions.map((region) => /* @__PURE__ */ jsx11(ImageRegionMarker, {
1296
- "data-slot": "image-difference-region",
1297
- variant: "difference",
1298
- region: {
1299
- left: toPercent2(region.x, diff.width),
1300
- top: toPercent2(region.y, diff.height),
1301
- width: toPercent2(region.width, diff.width),
1302
- height: toPercent2(region.height, diff.height)
1303
- }
1304
- }, `${region.x}:${region.y}:${region.width}:${region.height}`))
1553
+ children: diff.regions.map((region, index) => {
1554
+ const isNearRight = (region.x + region.width) / diff.width > 0.8;
1555
+ return /* @__PURE__ */ jsx11(ImageRegionMarker, {
1556
+ "data-slot": "image-difference-region",
1557
+ variant: "difference",
1558
+ active: index === activeIndex,
1559
+ region: {
1560
+ left: toPercent2(region.x, diff.width),
1561
+ top: toPercent2(region.y, diff.height),
1562
+ width: toPercent2(region.width, diff.width),
1563
+ height: toPercent2(region.height, diff.height)
1564
+ },
1565
+ children: onCommentRegion && /* @__PURE__ */ jsx11(ImageRegionMarkerBadge, {
1566
+ "data-slot": "image-difference-comment",
1567
+ position: isNearRight ? { left: "0", top: "calc(100% + 6px)" } : { left: "calc(100% + 6px)", top: "0" },
1568
+ children: /* @__PURE__ */ jsx11(Button2, {
1569
+ variant: "secondary",
1570
+ size: "xs",
1571
+ "aria-label": `Comment on change ${index + 1} of ${count}`,
1572
+ onPointerDown: (event) => event.stopPropagation(),
1573
+ onClick: () => onCommentRegion(region, index),
1574
+ children: "Comment"
1575
+ })
1576
+ })
1577
+ }, `${region.x}:${region.y}:${region.width}:${region.height}`);
1578
+ })
1305
1579
  });
1306
1580
  }
1307
1581
 
@@ -1309,7 +1583,7 @@ function ImageDifferenceOverlay({ diff }) {
1309
1583
  import { DirectionProvider } from "@base-ui/react/direction-provider";
1310
1584
  import { Slider as SliderPrimitive } from "@base-ui/react/slider";
1311
1585
  import { ChevronsLeftRightIcon } from "lucide-react";
1312
- import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
1586
+ import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
1313
1587
  function ImageSwipeDivider({
1314
1588
  value,
1315
1589
  onValueChange,
@@ -1330,7 +1604,7 @@ function ImageSwipeDivider({
1330
1604
  className: "pointer-events-none absolute inset-0",
1331
1605
  children: /* @__PURE__ */ jsx12(SliderPrimitive.Control, {
1332
1606
  className: "pointer-events-none absolute inset-0",
1333
- children: /* @__PURE__ */ jsxs8(SliderPrimitive.Thumb, {
1607
+ children: /* @__PURE__ */ jsxs9(SliderPrimitive.Thumb, {
1334
1608
  "data-slot": "image-swipe-divider-handle",
1335
1609
  getAriaLabel: () => "Swipe divider",
1336
1610
  getAriaValueText: (_formatted, current) => `${beforeLabel} ${current}%, ${afterLabel} ${100 - current}%`,
@@ -1355,7 +1629,7 @@ function ImageSwipeDivider({
1355
1629
  }
1356
1630
 
1357
1631
  // src/components/image-viewer/hooks/useImageDifferences.ts
1358
- import { useEffect as useEffect2, useRef as useRef4, useState as useState5 } from "react";
1632
+ import { useEffect as useEffect2, useRef as useRef5, useState as useState6 } from "react";
1359
1633
 
1360
1634
  // src/components/image-viewer/computeImageDiff.ts
1361
1635
  var DEFAULT_THRESHOLD = 32;
@@ -1568,9 +1842,9 @@ function useImageDifferences({
1568
1842
  beforeRef,
1569
1843
  afterRef
1570
1844
  }) {
1571
- const [entries, setEntries] = useState5(() => new Map);
1572
- const startedRef = useRef4(new Set);
1573
- const controllerRef = useRef4(undefined);
1845
+ const [entries, setEntries] = useState6(() => new Map);
1846
+ const startedRef = useRef5(new Set);
1847
+ const controllerRef = useRef5(undefined);
1574
1848
  useEffect2(() => () => controllerRef.current?.abort(), [pairKey]);
1575
1849
  useEffect2(() => {
1576
1850
  const before = beforeRef.current;
@@ -1609,9 +1883,9 @@ function useImageDifferences({
1609
1883
  }
1610
1884
 
1611
1885
  // src/components/image-viewer/ImageComparison.tsx
1612
- import { jsx as jsx13, jsxs as jsxs9, Fragment as Fragment2 } from "react/jsx-runtime";
1886
+ import { jsx as jsx13, jsxs as jsxs10, Fragment as Fragment2 } from "react/jsx-runtime";
1613
1887
  function ComparisonPane({ header, children }) {
1614
- return /* @__PURE__ */ jsxs9("div", {
1888
+ return /* @__PURE__ */ jsxs10("div", {
1615
1889
  "data-slot": "image-comparison-pane",
1616
1890
  "data-scroll": "none",
1617
1891
  className: "flex min-h-0 min-w-0 flex-1 flex-col",
@@ -1625,6 +1899,12 @@ function ComparisonPane({ header, children }) {
1625
1899
  ]
1626
1900
  });
1627
1901
  }
1902
+ function getRegionCenter(region, diff) {
1903
+ return {
1904
+ x: diff.width > 0 ? (region.x + region.width / 2) / diff.width : 0.5,
1905
+ y: diff.height > 0 ? (region.y + region.height / 2) / diff.height : 0.5
1906
+ };
1907
+ }
1628
1908
  function ImageComparison({
1629
1909
  before,
1630
1910
  after,
@@ -1637,7 +1917,7 @@ function ImageComparison({
1637
1917
  defaultSide = "after",
1638
1918
  onSideChange,
1639
1919
  orientation: orientationProp,
1640
- defaultOrientation = "horizontal",
1920
+ defaultOrientation,
1641
1921
  onOrientationChange,
1642
1922
  zoom: zoomProp,
1643
1923
  defaultZoom = "fit",
@@ -1646,65 +1926,97 @@ function ImageComparison({
1646
1926
  defaultShowDifferences = false,
1647
1927
  onShowDifferencesChange,
1648
1928
  showToolbar = true,
1929
+ toolbar,
1930
+ beforeOverlay,
1931
+ afterOverlay,
1932
+ stageOverlay,
1933
+ onCommentDifference,
1934
+ onSwipePositionChange,
1935
+ onStageKeyDown,
1936
+ stageKeyShortcuts,
1649
1937
  label = "Image comparison",
1650
1938
  density
1651
1939
  }) {
1652
- const [mode, setModeState] = useControlled2({
1940
+ const [mode, setModeState] = useControlled3({
1653
1941
  controlled: modeProp,
1654
1942
  default: defaultMode,
1655
1943
  name: "ImageComparison",
1656
1944
  state: "mode"
1657
1945
  });
1658
- const [side, setSideState] = useControlled2({
1946
+ const [side, setSideState] = useControlled3({
1659
1947
  controlled: sideProp,
1660
1948
  default: defaultSide,
1661
1949
  name: "ImageComparison",
1662
1950
  state: "side"
1663
1951
  });
1664
- const [orientation, setOrientationState] = useControlled2({
1952
+ const [chosenOrientation, setOrientationState] = useControlled3({
1665
1953
  controlled: orientationProp,
1666
1954
  default: defaultOrientation,
1667
1955
  name: "ImageComparison",
1668
1956
  state: "orientation"
1669
1957
  });
1670
- const [zoom, setZoomState] = useControlled2({
1958
+ const [zoom, setZoomState] = useControlled3({
1671
1959
  controlled: zoomProp,
1672
1960
  default: defaultZoom,
1673
1961
  name: "ImageComparison",
1674
1962
  state: "zoom"
1675
1963
  });
1676
- const [showDifferences, setShowDifferencesState] = useControlled2({
1964
+ const [showDifferences, setShowDifferencesState] = useControlled3({
1677
1965
  controlled: showDifferencesProp,
1678
1966
  default: defaultShowDifferences,
1679
1967
  name: "ImageComparison",
1680
1968
  state: "showDifferences"
1681
1969
  });
1682
- const [isPeeking, setIsPeeking] = useState6(false);
1683
- const [position, setPosition] = useState6(50);
1970
+ const pairKey = `${before.src}
1971
+ ${after.src}`;
1972
+ const [isPeeking, setIsPeeking] = useState7(false);
1973
+ const [position, setPosition] = useState7(50);
1974
+ const [activeRegionIndex, setActiveRegionIndex] = useState7(0);
1975
+ const [changeAnnouncement, setChangeAnnouncement] = useState7("");
1976
+ const [lastPairKey, setLastPairKey] = useState7(pairKey);
1977
+ const [lastShowDifferences, setLastShowDifferences] = useState7(showDifferences);
1978
+ if (lastPairKey !== pairKey || lastShowDifferences !== showDifferences) {
1979
+ setLastPairKey(pairKey);
1980
+ setLastShowDifferences(showDifferences);
1981
+ setActiveRegionIndex(0);
1982
+ setChangeAnnouncement("");
1983
+ }
1684
1984
  const [beforeImage, beforeHandlers] = useImageLoad(before.src);
1685
1985
  const [afterImage, afterHandlers] = useImageLoad(after.src);
1686
- const beforeRef = useRef5(null);
1687
- const afterRef = useRef5(null);
1688
- const beforeViewportRef = useRef5(null);
1689
- const afterViewportRef = useRef5(null);
1690
- const expectedScrollRef = useRef5(new WeakMap);
1691
- const center = useRef5({ x: 0.5, y: 0.5 });
1986
+ const beforeRef = useRef6(null);
1987
+ const afterRef = useRef6(null);
1988
+ const stageRef = useRef6(null);
1989
+ const singleViewportRef = useRef6(null);
1990
+ const beforeViewportRef = useRef6(null);
1991
+ const afterViewportRef = useRef6(null);
1992
+ const expectedScrollRef = useRef6(new WeakMap);
1993
+ const center = useRef6({ x: 0.5, y: 0.5 });
1994
+ const stageSize = useElementSize(stageRef);
1995
+ const autoOrientation = stageSize && stageSize.height > stageSize.width ? "vertical" : "horizontal";
1996
+ const orientation = chosenOrientation ?? autoOrientation;
1692
1997
  const failedLabel = afterImage.status === "error" ? afterLabel : beforeImage.status === "error" ? beforeLabel : undefined;
1693
1998
  const differences = useImageDifferences({
1694
- pairKey: `${before.src}
1695
- ${after.src}`,
1999
+ pairKey,
1696
2000
  enabled: showDifferences,
1697
2001
  loaded: beforeImage.status === "loaded" && afterImage.status === "loaded",
1698
2002
  loadFailure: failedLabel ? `Pixels cannot be read: the ${failedLabel} image could not be loaded.` : undefined,
1699
2003
  beforeRef,
1700
2004
  afterRef
1701
2005
  });
2006
+ const regions = showDifferences && differences.status === "ready" ? differences.diff.regions : [];
2007
+ const clampedActiveIndex = regions.length > 0 ? Math.min(activeRegionIndex, regions.length - 1) : 0;
1702
2008
  const shownSide = mode !== "toggle" ? "after" : isPeeking ? side === "before" ? "after" : "before" : side;
1703
2009
  const isShowingBefore = shownSide === "before";
1704
- const overlay = showDifferences && differences.status === "ready" ? /* @__PURE__ */ jsx13(ImageDifferenceOverlay, {
1705
- diff: differences.diff
2010
+ const diffOverlay = showDifferences && differences.status === "ready" ? /* @__PURE__ */ jsx13(ImageDifferenceOverlay, {
2011
+ diff: differences.diff,
2012
+ activeIndex: clampedActiveIndex
1706
2013
  }) : null;
1707
- const fallback = failedLabel ? /* @__PURE__ */ jsxs9("p", {
2014
+ const interactiveDiffOverlay = showDifferences && differences.status === "ready" ? /* @__PURE__ */ jsx13(ImageDifferenceOverlay, {
2015
+ diff: differences.diff,
2016
+ activeIndex: clampedActiveIndex,
2017
+ onCommentRegion: onCommentDifference ? (region, index) => onCommentDifference(region, index, differences.diff) : undefined
2018
+ }) : null;
2019
+ const fallback = failedLabel ? /* @__PURE__ */ jsxs10("p", {
1708
2020
  "data-slot": "image-comparison-error",
1709
2021
  className: "m-auto p-panel text-center text-sm text-muted-foreground",
1710
2022
  children: [
@@ -1721,20 +2033,53 @@ ${after.src}`,
1721
2033
  setSideState(next);
1722
2034
  onSideChange?.(next);
1723
2035
  }
1724
- function handleToggleStageKey(event) {
1725
- if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
1726
- return;
1727
- const key = event.key.toLowerCase();
1728
- if (key !== "b" && key !== "a")
1729
- return;
1730
- event.preventDefault();
1731
- setSide(key === "b" ? "before" : "after");
1732
- }
1733
2036
  function setOrientation(next) {
1734
2037
  setOrientationState(next);
1735
2038
  onOrientationChange?.(next);
1736
2039
  }
2040
+ function scrollViewportToPoint(viewport, point) {
2041
+ if (!viewport)
2042
+ return;
2043
+ const stageElement = viewport.querySelector("[data-slot=image-stage]");
2044
+ if (!stageElement || stageElement.offsetWidth <= 0 || stageElement.offsetHeight <= 0)
2045
+ return;
2046
+ const maxLeft = Math.max(0, viewport.scrollWidth - viewport.clientWidth);
2047
+ const maxTop = Math.max(0, viewport.scrollHeight - viewport.clientHeight);
2048
+ const left = Math.round(Math.min(maxLeft, Math.max(0, point.x * stageElement.offsetWidth - viewport.clientWidth / 2)));
2049
+ const top = Math.round(Math.min(maxTop, Math.max(0, point.y * stageElement.offsetHeight - viewport.clientHeight / 2)));
2050
+ expectedScrollRef.current.set(viewport, { left, top });
2051
+ viewport.scrollTo({ left, top, behavior: "instant" });
2052
+ }
2053
+ function scrollAllViewportsToPoint(point) {
2054
+ scrollViewportToPoint(singleViewportRef.current, point);
2055
+ scrollViewportToPoint(beforeViewportRef.current, point);
2056
+ scrollViewportToPoint(afterViewportRef.current, point);
2057
+ }
2058
+ function stepChange(delta) {
2059
+ if (differences.status !== "ready" || differences.diff.regions.length === 0)
2060
+ return;
2061
+ const count = differences.diff.regions.length;
2062
+ const next = (clampedActiveIndex + delta + count) % count;
2063
+ const region = differences.diff.regions[next];
2064
+ if (!region)
2065
+ return;
2066
+ const point = getRegionCenter(region, differences.diff);
2067
+ center.current = point;
2068
+ setActiveRegionIndex(next);
2069
+ setChangeAnnouncement(`Change ${next + 1} of ${count}`);
2070
+ scrollAllViewportsToPoint(point);
2071
+ }
1737
2072
  function setZoom(next) {
2073
+ if (next === 1 && showDifferences && differences.status === "ready" && differences.diff.regions.length > 0) {
2074
+ const first = differences.diff.regions[0];
2075
+ if (first) {
2076
+ const point = getRegionCenter(first, differences.diff);
2077
+ center.current = point;
2078
+ setActiveRegionIndex(0);
2079
+ if (zoom === 1)
2080
+ scrollAllViewportsToPoint(point);
2081
+ }
2082
+ }
1738
2083
  setZoomState(next);
1739
2084
  onZoomChange?.(next);
1740
2085
  }
@@ -1742,6 +2087,25 @@ ${after.src}`,
1742
2087
  setShowDifferencesState(next);
1743
2088
  onShowDifferencesChange?.(next);
1744
2089
  }
2090
+ function handlePositionChange(next) {
2091
+ setPosition(next);
2092
+ onSwipePositionChange?.(next);
2093
+ }
2094
+ function handleStageKey(event, activeSide) {
2095
+ onStageKeyDown?.(event, activeSide);
2096
+ if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey)
2097
+ return;
2098
+ const key = event.key.toLowerCase();
2099
+ if (key === "n" && regions.length > 0) {
2100
+ event.preventDefault();
2101
+ stepChange(event.shiftKey ? -1 : 1);
2102
+ return;
2103
+ }
2104
+ if (mode === "toggle" && !event.shiftKey && (key === "b" || key === "a")) {
2105
+ event.preventDefault();
2106
+ setSide(key === "b" ? "before" : "after");
2107
+ }
2108
+ }
1745
2109
  function syncScroll(source, target) {
1746
2110
  const expected = expectedScrollRef.current.get(source);
1747
2111
  expectedScrollRef.current.delete(source);
@@ -1762,7 +2126,7 @@ ${after.src}`,
1762
2126
  crossOrigin: after.crossOrigin,
1763
2127
  draggable: false,
1764
2128
  "data-slot": "image-comparison-after",
1765
- className: cn2("absolute inset-0 size-full bg-background select-none", className),
2129
+ className: cn2("absolute inset-0 size-full bg-background outline-1 -outline-offset-1 outline-media-edge select-none", className),
1766
2130
  onLoad: afterHandlers.onLoad,
1767
2131
  onError: afterHandlers.onError
1768
2132
  });
@@ -1775,15 +2139,17 @@ ${after.src}`,
1775
2139
  crossOrigin: before.crossOrigin,
1776
2140
  draggable: false,
1777
2141
  "data-slot": "image-comparison-before",
1778
- className: cn2("absolute inset-0 size-full bg-background object-contain select-none", className),
2142
+ className: cn2("absolute inset-0 size-full bg-background object-contain outline-1 -outline-offset-1 outline-media-edge select-none", className),
1779
2143
  style,
1780
2144
  onLoad: beforeHandlers.onLoad,
1781
2145
  onError: beforeHandlers.onError
1782
2146
  });
1783
2147
  }
2148
+ const sharedStageKeys = [regions.length > 0 ? "N Shift+N" : undefined, stageKeyShortcuts].filter(Boolean).join(" ");
2149
+ const toggleStageKeys = ["B A", sharedStageKeys].filter(Boolean).join(" ");
1784
2150
  let content;
1785
2151
  if (mode === "side-by-side") {
1786
- content = /* @__PURE__ */ jsxs9("div", {
2152
+ content = /* @__PURE__ */ jsxs10("div", {
1787
2153
  "data-slot": "image-comparison-panes",
1788
2154
  className: cn2("flex min-h-0 min-w-0 flex-1", orientation === "vertical" ? "flex-col" : "flex-row"),
1789
2155
  children: [
@@ -1791,7 +2157,7 @@ ${after.src}`,
1791
2157
  header: /* @__PURE__ */ jsx13("span", {
1792
2158
  children: beforeLabel
1793
2159
  }),
1794
- children: /* @__PURE__ */ jsxs9(ImageViewport, {
2160
+ children: /* @__PURE__ */ jsxs10(ImageViewport, {
1795
2161
  label: beforeLabel,
1796
2162
  zoom,
1797
2163
  naturalSize: afterImage.size,
@@ -1800,9 +2166,12 @@ ${after.src}`,
1800
2166
  fallback,
1801
2167
  viewportRef: beforeViewportRef,
1802
2168
  onViewportScroll: (viewport) => syncScroll(viewport, afterViewportRef.current),
2169
+ onStageKeyDown: (event) => handleStageKey(event, "before"),
2170
+ stageKeyShortcuts: sharedStageKeys || undefined,
1803
2171
  children: [
1804
2172
  renderBeforeImage(),
1805
- overlay
2173
+ beforeOverlay,
2174
+ diffOverlay
1806
2175
  ]
1807
2176
  })
1808
2177
  }),
@@ -1813,7 +2182,7 @@ ${after.src}`,
1813
2182
  header: /* @__PURE__ */ jsx13("span", {
1814
2183
  children: afterLabel
1815
2184
  }),
1816
- children: /* @__PURE__ */ jsxs9(ImageViewport, {
2185
+ children: /* @__PURE__ */ jsxs10(ImageViewport, {
1817
2186
  label: afterLabel,
1818
2187
  zoom,
1819
2188
  naturalSize: afterImage.size,
@@ -1822,9 +2191,12 @@ ${after.src}`,
1822
2191
  fallback,
1823
2192
  viewportRef: afterViewportRef,
1824
2193
  onViewportScroll: (viewport) => syncScroll(viewport, beforeViewportRef.current),
2194
+ onStageKeyDown: (event) => handleStageKey(event, "after"),
2195
+ stageKeyShortcuts: sharedStageKeys || undefined,
1825
2196
  children: [
1826
2197
  renderAfterImage(),
1827
- overlay
2198
+ afterOverlay,
2199
+ interactiveDiffOverlay
1828
2200
  ]
1829
2201
  })
1830
2202
  })
@@ -1832,7 +2204,7 @@ ${after.src}`,
1832
2204
  });
1833
2205
  } else if (mode === "swipe") {
1834
2206
  content = /* @__PURE__ */ jsx13(ComparisonPane, {
1835
- header: /* @__PURE__ */ jsxs9(Fragment2, {
2207
+ header: /* @__PURE__ */ jsxs10(Fragment2, {
1836
2208
  children: [
1837
2209
  /* @__PURE__ */ jsx13("span", {
1838
2210
  children: beforeLabel
@@ -1842,30 +2214,36 @@ ${after.src}`,
1842
2214
  })
1843
2215
  ]
1844
2216
  }),
1845
- children: /* @__PURE__ */ jsxs9(ImageViewport, {
2217
+ children: /* @__PURE__ */ jsxs10(ImageViewport, {
1846
2218
  label: `${beforeLabel} and ${afterLabel}`,
1847
2219
  zoom,
1848
2220
  naturalSize: afterImage.size,
1849
2221
  center,
1850
2222
  onZoomChange: setZoom,
1851
2223
  fallback,
2224
+ viewportRef: singleViewportRef,
2225
+ onStageKeyDown: (event) => handleStageKey(event, position > 50 ? "before" : "after"),
2226
+ stageKeyShortcuts: sharedStageKeys || undefined,
1852
2227
  children: [
1853
2228
  renderAfterImage(),
1854
2229
  renderBeforeImage(undefined, { clipPath: `inset(0 ${100 - position}% 0 0)` }),
1855
- overlay,
2230
+ beforeOverlay,
2231
+ afterOverlay,
2232
+ interactiveDiffOverlay,
1856
2233
  /* @__PURE__ */ jsx13(ImageSwipeDivider, {
1857
2234
  value: position,
1858
- onValueChange: setPosition,
2235
+ onValueChange: handlePositionChange,
1859
2236
  beforeLabel,
1860
2237
  afterLabel
1861
- })
2238
+ }),
2239
+ stageOverlay
1862
2240
  ]
1863
2241
  })
1864
2242
  });
1865
2243
  } else {
1866
2244
  const showingLabel = isShowingBefore ? beforeLabel : afterLabel;
1867
2245
  content = /* @__PURE__ */ jsx13(ComparisonPane, {
1868
- header: /* @__PURE__ */ jsxs9("span", {
2246
+ header: /* @__PURE__ */ jsxs10("span", {
1869
2247
  "data-slot": "image-comparison-showing",
1870
2248
  "aria-live": "polite",
1871
2249
  children: [
@@ -1873,24 +2251,28 @@ ${after.src}`,
1873
2251
  showingLabel
1874
2252
  ]
1875
2253
  }),
1876
- children: /* @__PURE__ */ jsxs9(ImageViewport, {
2254
+ children: /* @__PURE__ */ jsxs10(ImageViewport, {
1877
2255
  label: showingLabel,
1878
2256
  zoom,
1879
2257
  naturalSize: afterImage.size,
1880
2258
  center,
1881
2259
  onZoomChange: setZoom,
1882
2260
  fallback,
1883
- onStageKeyDown: handleToggleStageKey,
1884
- stageKeyShortcuts: "B A",
2261
+ viewportRef: singleViewportRef,
2262
+ onStageKeyDown: (event) => handleStageKey(event, shownSide),
2263
+ stageKeyShortcuts: toggleStageKeys,
1885
2264
  children: [
1886
2265
  renderAfterImage(isShowingBefore ? "invisible" : undefined),
1887
2266
  renderBeforeImage(isShowingBefore ? undefined : "invisible"),
1888
- overlay
2267
+ beforeOverlay,
2268
+ afterOverlay,
2269
+ interactiveDiffOverlay,
2270
+ stageOverlay
1889
2271
  ]
1890
2272
  })
1891
2273
  });
1892
2274
  }
1893
- return /* @__PURE__ */ jsx13("div", {
2275
+ return /* @__PURE__ */ jsxs10("div", {
1894
2276
  role: "group",
1895
2277
  "aria-label": label,
1896
2278
  "data-slot": "image-comparison",
@@ -1900,37 +2282,44 @@ ${after.src}`,
1900
2282
  "data-orientation": orientation,
1901
2283
  "data-zoom": zoom,
1902
2284
  "data-showing": isShowingBefore ? "before" : "after",
1903
- className: "@container flex size-full min-h-0 min-w-0 flex-1",
1904
- children: /* @__PURE__ */ jsxs9("div", {
1905
- className: "flex min-h-0 min-w-0 flex-1 flex-col @3xl:flex-row",
1906
- children: [
1907
- /* @__PURE__ */ jsx13("div", {
1908
- "data-slot": "image-comparison-stage",
1909
- "data-scroll": "none",
1910
- className: "flex min-h-0 min-w-0 flex-1",
1911
- children: content
1912
- }),
1913
- showToolbar && /* @__PURE__ */ jsx13(ImageComparisonToolbar, {
1914
- mode,
1915
- onModeChange: setMode,
1916
- side,
1917
- onSideChange: setSide,
1918
- orientation,
1919
- onOrientationChange: setOrientation,
1920
- zoom,
1921
- onZoomChange: setZoom,
1922
- showDifferences,
1923
- onShowDifferencesChange: setShowDifferences,
1924
- differences,
1925
- onPeekChange: setIsPeeking,
1926
- beforeLabel,
1927
- afterLabel,
1928
- beforeSize: beforeImage.size,
1929
- afterSize: afterImage.size,
1930
- density
1931
- })
1932
- ]
1933
- })
2285
+ className: "@container flex size-full min-h-0 min-w-0 flex-1 flex-col",
2286
+ children: [
2287
+ showToolbar && /* @__PURE__ */ jsx13(ImageComparisonToolbar, {
2288
+ mode,
2289
+ onModeChange: setMode,
2290
+ side,
2291
+ onSideChange: setSide,
2292
+ orientation,
2293
+ onOrientationChange: setOrientation,
2294
+ zoom,
2295
+ onZoomChange: setZoom,
2296
+ showDifferences,
2297
+ onShowDifferencesChange: setShowDifferences,
2298
+ differences,
2299
+ activeRegionIndex: clampedActiveIndex,
2300
+ onStepChange: stepChange,
2301
+ onPeekChange: setIsPeeking,
2302
+ beforeLabel,
2303
+ afterLabel,
2304
+ beforeSize: beforeImage.size,
2305
+ afterSize: afterImage.size,
2306
+ toolbar,
2307
+ density
2308
+ }),
2309
+ /* @__PURE__ */ jsx13("div", {
2310
+ ref: stageRef,
2311
+ "data-slot": "image-comparison-stage",
2312
+ "data-scroll": "none",
2313
+ className: "flex min-h-0 min-w-0 flex-1",
2314
+ children: content
2315
+ }),
2316
+ /* @__PURE__ */ jsx13("p", {
2317
+ role: "status",
2318
+ "data-slot": "image-comparison-change-announcement",
2319
+ className: "sr-only",
2320
+ children: changeAnnouncement
2321
+ })
2322
+ ]
1934
2323
  });
1935
2324
  }
1936
2325
  export {