@alexgorbatchev/shadcn 0.0.155 → 0.0.157

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",
@@ -1141,10 +1355,10 @@ function ImageComparisonToolbar({
1141
1355
  ]
1142
1356
  })
1143
1357
  }),
1144
- /* @__PURE__ */ jsx10(ToolbarSection, {
1358
+ mode === "toggle" && /* @__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,
@@ -1153,7 +1367,7 @@ function ImageComparisonToolbar({
1153
1367
  variant: "outline",
1154
1368
  size: "sm",
1155
1369
  spacing: 0,
1156
- disabled: mode !== "toggle",
1370
+ density,
1157
1371
  children: [
1158
1372
  /* @__PURE__ */ jsx10(ToggleGroupItem2, {
1159
1373
  value: "before",
@@ -1166,10 +1380,10 @@ function ImageComparisonToolbar({
1166
1380
  ]
1167
1381
  })
1168
1382
  }),
1169
- /* @__PURE__ */ jsx10(ToolbarSection, {
1383
+ mode === "side-by-side" && /* @__PURE__ */ jsx10(ToolbarSection, {
1170
1384
  title: "Orientation",
1171
1385
  titleId: `${id}-orientation`,
1172
- children: /* @__PURE__ */ jsxs7(ToggleGroup2, {
1386
+ children: /* @__PURE__ */ jsxs8(ToggleGroup2, {
1173
1387
  "aria-labelledby": `${id}-orientation`,
1174
1388
  required: true,
1175
1389
  value: [orientation],
@@ -1177,9 +1391,9 @@ function ImageComparisonToolbar({
1177
1391
  variant: "outline",
1178
1392
  size: "sm",
1179
1393
  spacing: 0,
1180
- disabled: mode !== "side-by-side",
1394
+ density,
1181
1395
  children: [
1182
- /* @__PURE__ */ jsxs7(ToggleGroupItem2, {
1396
+ /* @__PURE__ */ jsxs8(ToggleGroupItem2, {
1183
1397
  value: "horizontal",
1184
1398
  children: [
1185
1399
  /* @__PURE__ */ jsx10(Columns2Icon, {
@@ -1188,7 +1402,7 @@ function ImageComparisonToolbar({
1188
1402
  "Horizontal"
1189
1403
  ]
1190
1404
  }),
1191
- /* @__PURE__ */ jsxs7(ToggleGroupItem2, {
1405
+ /* @__PURE__ */ jsxs8(ToggleGroupItem2, {
1192
1406
  value: "vertical",
1193
1407
  children: [
1194
1408
  /* @__PURE__ */ jsx10(Rows2Icon, {
@@ -1205,14 +1419,15 @@ function ImageComparisonToolbar({
1205
1419
  titleId: `${id}-zoom`,
1206
1420
  children: /* @__PURE__ */ jsx10(ImageZoomToggle, {
1207
1421
  zoom,
1208
- onZoomChange
1422
+ onZoomChange,
1423
+ density
1209
1424
  })
1210
1425
  }),
1211
- /* @__PURE__ */ jsx10(Button2, {
1426
+ mode === "toggle" && /* @__PURE__ */ jsx10(Button2, {
1212
1427
  variant: "outline",
1213
1428
  size: "sm",
1214
- disabled: mode !== "toggle",
1215
- className: "touch-none",
1429
+ density,
1430
+ className: "shrink-0 touch-none",
1216
1431
  onPointerDown: (event) => {
1217
1432
  if (event.button === 0)
1218
1433
  onPeekChange(true);
@@ -1232,51 +1447,86 @@ function ImageComparisonToolbar({
1232
1447
  onContextMenu: (event) => event.preventDefault(),
1233
1448
  children: `Hold to show ${side === "before" ? "after" : "before"}`
1234
1449
  }),
1235
- /* @__PURE__ */ jsxs7(Field2, {
1236
- orientation: "horizontal",
1450
+ /* @__PURE__ */ jsxs8("div", {
1451
+ className: "flex shrink-0 flex-wrap items-center gap-2",
1237
1452
  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, {
1453
+ /* @__PURE__ */ jsxs8("div", {
1454
+ className: "flex items-center gap-1.5",
1246
1455
  children: [
1247
- /* @__PURE__ */ jsx10(FieldLabel2, {
1456
+ /* @__PURE__ */ jsx10(Switch2, {
1457
+ id: `${id}-differences`,
1458
+ "aria-describedby": `${id}-differences-status`,
1459
+ checked: showDifferences && !isUnavailable,
1460
+ disabled: isUnavailable,
1461
+ onCheckedChange: onShowDifferencesChange
1462
+ }),
1463
+ /* @__PURE__ */ jsx10("label", {
1248
1464
  htmlFor: `${id}-differences`,
1465
+ className: "cursor-pointer text-sm leading-none font-medium whitespace-nowrap select-none",
1249
1466
  children: "Highlight differences"
1467
+ })
1468
+ ]
1469
+ }),
1470
+ showDifferences && differences.status === "ready" && /* @__PURE__ */ jsxs8("span", {
1471
+ "data-slot": "image-comparison-legend",
1472
+ className: "flex items-center gap-1.5 text-xs whitespace-nowrap text-muted-foreground",
1473
+ children: [
1474
+ /* @__PURE__ */ jsx10("span", {
1475
+ "aria-hidden": "true",
1476
+ 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
1477
  }),
1251
- showDifferences && differences.status === "ready" && /* @__PURE__ */ jsxs7(FieldDescription2, {
1252
- "data-slot": "image-comparison-legend",
1253
- className: "flex items-center gap-1.5",
1478
+ "Changed region"
1479
+ ]
1480
+ }),
1481
+ hasStepper && /* @__PURE__ */ jsxs8("div", {
1482
+ role: "group",
1483
+ "aria-label": "Changed regions",
1484
+ "data-slot": "image-comparison-stepper",
1485
+ className: "flex items-center gap-1.5 border-s border-border ps-2",
1486
+ children: [
1487
+ /* @__PURE__ */ jsxs8("span", {
1488
+ "data-slot": "image-comparison-change-count",
1489
+ className: "text-xs whitespace-nowrap text-muted-foreground tabular-nums",
1254
1490
  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"
1491
+ "Change ",
1492
+ activeRegionIndex + 1,
1493
+ " of ",
1494
+ regionCount
1260
1495
  ]
1496
+ }),
1497
+ /* @__PURE__ */ jsx10(Button2, {
1498
+ variant: "outline",
1499
+ size: "icon-sm",
1500
+ density,
1501
+ "aria-label": "Previous change",
1502
+ "aria-keyshortcuts": "Shift+N",
1503
+ onClick: () => onStepChange(-1),
1504
+ children: /* @__PURE__ */ jsx10(ChevronLeftIcon2, {})
1505
+ }),
1506
+ /* @__PURE__ */ jsx10(Button2, {
1507
+ variant: "outline",
1508
+ size: "icon-sm",
1509
+ density,
1510
+ "aria-label": "Next change",
1511
+ "aria-keyshortcuts": "N",
1512
+ onClick: () => onStepChange(1),
1513
+ children: /* @__PURE__ */ jsx10(ChevronRightIcon2, {})
1261
1514
  })
1262
1515
  ]
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: [
1516
+ }),
1270
1517
  /* @__PURE__ */ jsx10("p", {
1271
1518
  id: `${id}-differences-status`,
1272
1519
  role: "status",
1273
- children: describeDifferences(differences, showDifferences)
1274
- }),
1275
- sizeMismatch && /* @__PURE__ */ jsx10("p", {
1276
- "data-slot": "image-comparison-size-mismatch",
1277
- children: sizeMismatch
1520
+ className: hasStepper || !statusText ? "sr-only" : "text-xs text-muted-foreground",
1521
+ children: statusText
1278
1522
  })
1279
1523
  ]
1524
+ }),
1525
+ toolbar,
1526
+ sizeMismatch && /* @__PURE__ */ jsx10("p", {
1527
+ "data-slot": "image-comparison-size-mismatch",
1528
+ className: "w-full text-xs text-muted-foreground",
1529
+ children: sizeMismatch
1280
1530
  })
1281
1531
  ]
1282
1532
  });
@@ -1287,21 +1537,42 @@ import { jsx as jsx11 } from "react/jsx-runtime";
1287
1537
  function toPercent2(value, total) {
1288
1538
  return `${value / total * 100}%`;
1289
1539
  }
1290
- function ImageDifferenceOverlay({ diff }) {
1540
+ function ImageDifferenceOverlay({
1541
+ diff,
1542
+ activeIndex,
1543
+ onCommentRegion
1544
+ }) {
1545
+ const count = diff.regions.length;
1291
1546
  return /* @__PURE__ */ jsx11("div", {
1292
1547
  "data-slot": "image-difference-overlay",
1293
- "aria-hidden": "true",
1548
+ "aria-hidden": onCommentRegion ? undefined : "true",
1294
1549
  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}`))
1550
+ children: diff.regions.map((region, index) => {
1551
+ const isNearRight = (region.x + region.width) / diff.width > 0.8;
1552
+ return /* @__PURE__ */ jsx11(ImageRegionMarker, {
1553
+ "data-slot": "image-difference-region",
1554
+ variant: "difference",
1555
+ active: index === activeIndex,
1556
+ region: {
1557
+ left: toPercent2(region.x, diff.width),
1558
+ top: toPercent2(region.y, diff.height),
1559
+ width: toPercent2(region.width, diff.width),
1560
+ height: toPercent2(region.height, diff.height)
1561
+ },
1562
+ children: onCommentRegion && /* @__PURE__ */ jsx11(ImageRegionMarkerBadge, {
1563
+ "data-slot": "image-difference-comment",
1564
+ position: isNearRight ? { left: "0", top: "calc(100% + 6px)" } : { left: "calc(100% + 6px)", top: "0" },
1565
+ children: /* @__PURE__ */ jsx11(Button2, {
1566
+ variant: "secondary",
1567
+ size: "xs",
1568
+ "aria-label": `Comment on change ${index + 1} of ${count}`,
1569
+ onPointerDown: (event) => event.stopPropagation(),
1570
+ onClick: () => onCommentRegion(region, index),
1571
+ children: "Comment"
1572
+ })
1573
+ })
1574
+ }, `${region.x}:${region.y}:${region.width}:${region.height}`);
1575
+ })
1305
1576
  });
1306
1577
  }
1307
1578
 
@@ -1309,7 +1580,7 @@ function ImageDifferenceOverlay({ diff }) {
1309
1580
  import { DirectionProvider } from "@base-ui/react/direction-provider";
1310
1581
  import { Slider as SliderPrimitive } from "@base-ui/react/slider";
1311
1582
  import { ChevronsLeftRightIcon } from "lucide-react";
1312
- import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
1583
+ import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
1313
1584
  function ImageSwipeDivider({
1314
1585
  value,
1315
1586
  onValueChange,
@@ -1330,7 +1601,7 @@ function ImageSwipeDivider({
1330
1601
  className: "pointer-events-none absolute inset-0",
1331
1602
  children: /* @__PURE__ */ jsx12(SliderPrimitive.Control, {
1332
1603
  className: "pointer-events-none absolute inset-0",
1333
- children: /* @__PURE__ */ jsxs8(SliderPrimitive.Thumb, {
1604
+ children: /* @__PURE__ */ jsxs9(SliderPrimitive.Thumb, {
1334
1605
  "data-slot": "image-swipe-divider-handle",
1335
1606
  getAriaLabel: () => "Swipe divider",
1336
1607
  getAriaValueText: (_formatted, current) => `${beforeLabel} ${current}%, ${afterLabel} ${100 - current}%`,
@@ -1355,7 +1626,7 @@ function ImageSwipeDivider({
1355
1626
  }
1356
1627
 
1357
1628
  // src/components/image-viewer/hooks/useImageDifferences.ts
1358
- import { useEffect as useEffect2, useRef as useRef4, useState as useState5 } from "react";
1629
+ import { useEffect as useEffect2, useRef as useRef5, useState as useState6 } from "react";
1359
1630
 
1360
1631
  // src/components/image-viewer/computeImageDiff.ts
1361
1632
  var DEFAULT_THRESHOLD = 32;
@@ -1568,9 +1839,9 @@ function useImageDifferences({
1568
1839
  beforeRef,
1569
1840
  afterRef
1570
1841
  }) {
1571
- const [entries, setEntries] = useState5(() => new Map);
1572
- const startedRef = useRef4(new Set);
1573
- const controllerRef = useRef4(undefined);
1842
+ const [entries, setEntries] = useState6(() => new Map);
1843
+ const startedRef = useRef5(new Set);
1844
+ const controllerRef = useRef5(undefined);
1574
1845
  useEffect2(() => () => controllerRef.current?.abort(), [pairKey]);
1575
1846
  useEffect2(() => {
1576
1847
  const before = beforeRef.current;
@@ -1609,9 +1880,9 @@ function useImageDifferences({
1609
1880
  }
1610
1881
 
1611
1882
  // src/components/image-viewer/ImageComparison.tsx
1612
- import { jsx as jsx13, jsxs as jsxs9, Fragment as Fragment2 } from "react/jsx-runtime";
1883
+ import { jsx as jsx13, jsxs as jsxs10, Fragment as Fragment2 } from "react/jsx-runtime";
1613
1884
  function ComparisonPane({ header, children }) {
1614
- return /* @__PURE__ */ jsxs9("div", {
1885
+ return /* @__PURE__ */ jsxs10("div", {
1615
1886
  "data-slot": "image-comparison-pane",
1616
1887
  "data-scroll": "none",
1617
1888
  className: "flex min-h-0 min-w-0 flex-1 flex-col",
@@ -1625,6 +1896,12 @@ function ComparisonPane({ header, children }) {
1625
1896
  ]
1626
1897
  });
1627
1898
  }
1899
+ function getRegionCenter(region, diff) {
1900
+ return {
1901
+ x: diff.width > 0 ? (region.x + region.width / 2) / diff.width : 0.5,
1902
+ y: diff.height > 0 ? (region.y + region.height / 2) / diff.height : 0.5
1903
+ };
1904
+ }
1628
1905
  function ImageComparison({
1629
1906
  before,
1630
1907
  after,
@@ -1637,7 +1914,7 @@ function ImageComparison({
1637
1914
  defaultSide = "after",
1638
1915
  onSideChange,
1639
1916
  orientation: orientationProp,
1640
- defaultOrientation = "horizontal",
1917
+ defaultOrientation,
1641
1918
  onOrientationChange,
1642
1919
  zoom: zoomProp,
1643
1920
  defaultZoom = "fit",
@@ -1646,65 +1923,97 @@ function ImageComparison({
1646
1923
  defaultShowDifferences = false,
1647
1924
  onShowDifferencesChange,
1648
1925
  showToolbar = true,
1926
+ toolbar,
1927
+ beforeOverlay,
1928
+ afterOverlay,
1929
+ stageOverlay,
1930
+ onCommentDifference,
1931
+ onSwipePositionChange,
1932
+ onStageKeyDown,
1933
+ stageKeyShortcuts,
1649
1934
  label = "Image comparison",
1650
1935
  density
1651
1936
  }) {
1652
- const [mode, setModeState] = useControlled2({
1937
+ const [mode, setModeState] = useControlled3({
1653
1938
  controlled: modeProp,
1654
1939
  default: defaultMode,
1655
1940
  name: "ImageComparison",
1656
1941
  state: "mode"
1657
1942
  });
1658
- const [side, setSideState] = useControlled2({
1943
+ const [side, setSideState] = useControlled3({
1659
1944
  controlled: sideProp,
1660
1945
  default: defaultSide,
1661
1946
  name: "ImageComparison",
1662
1947
  state: "side"
1663
1948
  });
1664
- const [orientation, setOrientationState] = useControlled2({
1949
+ const [chosenOrientation, setOrientationState] = useControlled3({
1665
1950
  controlled: orientationProp,
1666
1951
  default: defaultOrientation,
1667
1952
  name: "ImageComparison",
1668
1953
  state: "orientation"
1669
1954
  });
1670
- const [zoom, setZoomState] = useControlled2({
1955
+ const [zoom, setZoomState] = useControlled3({
1671
1956
  controlled: zoomProp,
1672
1957
  default: defaultZoom,
1673
1958
  name: "ImageComparison",
1674
1959
  state: "zoom"
1675
1960
  });
1676
- const [showDifferences, setShowDifferencesState] = useControlled2({
1961
+ const [showDifferences, setShowDifferencesState] = useControlled3({
1677
1962
  controlled: showDifferencesProp,
1678
1963
  default: defaultShowDifferences,
1679
1964
  name: "ImageComparison",
1680
1965
  state: "showDifferences"
1681
1966
  });
1682
- const [isPeeking, setIsPeeking] = useState6(false);
1683
- const [position, setPosition] = useState6(50);
1967
+ const pairKey = `${before.src}
1968
+ ${after.src}`;
1969
+ const [isPeeking, setIsPeeking] = useState7(false);
1970
+ const [position, setPosition] = useState7(50);
1971
+ const [activeRegionIndex, setActiveRegionIndex] = useState7(0);
1972
+ const [changeAnnouncement, setChangeAnnouncement] = useState7("");
1973
+ const [lastPairKey, setLastPairKey] = useState7(pairKey);
1974
+ const [lastShowDifferences, setLastShowDifferences] = useState7(showDifferences);
1975
+ if (lastPairKey !== pairKey || lastShowDifferences !== showDifferences) {
1976
+ setLastPairKey(pairKey);
1977
+ setLastShowDifferences(showDifferences);
1978
+ setActiveRegionIndex(0);
1979
+ setChangeAnnouncement("");
1980
+ }
1684
1981
  const [beforeImage, beforeHandlers] = useImageLoad(before.src);
1685
1982
  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 });
1983
+ const beforeRef = useRef6(null);
1984
+ const afterRef = useRef6(null);
1985
+ const stageRef = useRef6(null);
1986
+ const singleViewportRef = useRef6(null);
1987
+ const beforeViewportRef = useRef6(null);
1988
+ const afterViewportRef = useRef6(null);
1989
+ const expectedScrollRef = useRef6(new WeakMap);
1990
+ const center = useRef6({ x: 0.5, y: 0.5 });
1991
+ const stageSize = useElementSize(stageRef);
1992
+ const autoOrientation = stageSize && stageSize.height > stageSize.width ? "vertical" : "horizontal";
1993
+ const orientation = chosenOrientation ?? autoOrientation;
1692
1994
  const failedLabel = afterImage.status === "error" ? afterLabel : beforeImage.status === "error" ? beforeLabel : undefined;
1693
1995
  const differences = useImageDifferences({
1694
- pairKey: `${before.src}
1695
- ${after.src}`,
1996
+ pairKey,
1696
1997
  enabled: showDifferences,
1697
1998
  loaded: beforeImage.status === "loaded" && afterImage.status === "loaded",
1698
1999
  loadFailure: failedLabel ? `Pixels cannot be read: the ${failedLabel} image could not be loaded.` : undefined,
1699
2000
  beforeRef,
1700
2001
  afterRef
1701
2002
  });
2003
+ const regions = showDifferences && differences.status === "ready" ? differences.diff.regions : [];
2004
+ const clampedActiveIndex = regions.length > 0 ? Math.min(activeRegionIndex, regions.length - 1) : 0;
1702
2005
  const shownSide = mode !== "toggle" ? "after" : isPeeking ? side === "before" ? "after" : "before" : side;
1703
2006
  const isShowingBefore = shownSide === "before";
1704
- const overlay = showDifferences && differences.status === "ready" ? /* @__PURE__ */ jsx13(ImageDifferenceOverlay, {
1705
- diff: differences.diff
2007
+ const diffOverlay = showDifferences && differences.status === "ready" ? /* @__PURE__ */ jsx13(ImageDifferenceOverlay, {
2008
+ diff: differences.diff,
2009
+ activeIndex: clampedActiveIndex
2010
+ }) : null;
2011
+ const interactiveDiffOverlay = showDifferences && differences.status === "ready" ? /* @__PURE__ */ jsx13(ImageDifferenceOverlay, {
2012
+ diff: differences.diff,
2013
+ activeIndex: clampedActiveIndex,
2014
+ onCommentRegion: onCommentDifference ? (region, index) => onCommentDifference(region, index, differences.diff) : undefined
1706
2015
  }) : null;
1707
- const fallback = failedLabel ? /* @__PURE__ */ jsxs9("p", {
2016
+ const fallback = failedLabel ? /* @__PURE__ */ jsxs10("p", {
1708
2017
  "data-slot": "image-comparison-error",
1709
2018
  className: "m-auto p-panel text-center text-sm text-muted-foreground",
1710
2019
  children: [
@@ -1721,20 +2030,53 @@ ${after.src}`,
1721
2030
  setSideState(next);
1722
2031
  onSideChange?.(next);
1723
2032
  }
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
2033
  function setOrientation(next) {
1734
2034
  setOrientationState(next);
1735
2035
  onOrientationChange?.(next);
1736
2036
  }
2037
+ function scrollViewportToPoint(viewport, point) {
2038
+ if (!viewport)
2039
+ return;
2040
+ const stageElement = viewport.querySelector("[data-slot=image-stage]");
2041
+ if (!stageElement || stageElement.offsetWidth <= 0 || stageElement.offsetHeight <= 0)
2042
+ return;
2043
+ const maxLeft = Math.max(0, viewport.scrollWidth - viewport.clientWidth);
2044
+ const maxTop = Math.max(0, viewport.scrollHeight - viewport.clientHeight);
2045
+ const left = Math.round(Math.min(maxLeft, Math.max(0, point.x * stageElement.offsetWidth - viewport.clientWidth / 2)));
2046
+ const top = Math.round(Math.min(maxTop, Math.max(0, point.y * stageElement.offsetHeight - viewport.clientHeight / 2)));
2047
+ expectedScrollRef.current.set(viewport, { left, top });
2048
+ viewport.scrollTo({ left, top, behavior: "instant" });
2049
+ }
2050
+ function scrollAllViewportsToPoint(point) {
2051
+ scrollViewportToPoint(singleViewportRef.current, point);
2052
+ scrollViewportToPoint(beforeViewportRef.current, point);
2053
+ scrollViewportToPoint(afterViewportRef.current, point);
2054
+ }
2055
+ function stepChange(delta) {
2056
+ if (differences.status !== "ready" || differences.diff.regions.length === 0)
2057
+ return;
2058
+ const count = differences.diff.regions.length;
2059
+ const next = (clampedActiveIndex + delta + count) % count;
2060
+ const region = differences.diff.regions[next];
2061
+ if (!region)
2062
+ return;
2063
+ const point = getRegionCenter(region, differences.diff);
2064
+ center.current = point;
2065
+ setActiveRegionIndex(next);
2066
+ setChangeAnnouncement(`Change ${next + 1} of ${count}`);
2067
+ scrollAllViewportsToPoint(point);
2068
+ }
1737
2069
  function setZoom(next) {
2070
+ if (next === 1 && showDifferences && differences.status === "ready" && differences.diff.regions.length > 0) {
2071
+ const first = differences.diff.regions[0];
2072
+ if (first) {
2073
+ const point = getRegionCenter(first, differences.diff);
2074
+ center.current = point;
2075
+ setActiveRegionIndex(0);
2076
+ if (zoom === 1)
2077
+ scrollAllViewportsToPoint(point);
2078
+ }
2079
+ }
1738
2080
  setZoomState(next);
1739
2081
  onZoomChange?.(next);
1740
2082
  }
@@ -1742,6 +2084,25 @@ ${after.src}`,
1742
2084
  setShowDifferencesState(next);
1743
2085
  onShowDifferencesChange?.(next);
1744
2086
  }
2087
+ function handlePositionChange(next) {
2088
+ setPosition(next);
2089
+ onSwipePositionChange?.(next);
2090
+ }
2091
+ function handleStageKey(event, activeSide) {
2092
+ onStageKeyDown?.(event, activeSide);
2093
+ if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey)
2094
+ return;
2095
+ const key = event.key.toLowerCase();
2096
+ if (key === "n" && regions.length > 0) {
2097
+ event.preventDefault();
2098
+ stepChange(event.shiftKey ? -1 : 1);
2099
+ return;
2100
+ }
2101
+ if (mode === "toggle" && !event.shiftKey && (key === "b" || key === "a")) {
2102
+ event.preventDefault();
2103
+ setSide(key === "b" ? "before" : "after");
2104
+ }
2105
+ }
1745
2106
  function syncScroll(source, target) {
1746
2107
  const expected = expectedScrollRef.current.get(source);
1747
2108
  expectedScrollRef.current.delete(source);
@@ -1762,7 +2123,7 @@ ${after.src}`,
1762
2123
  crossOrigin: after.crossOrigin,
1763
2124
  draggable: false,
1764
2125
  "data-slot": "image-comparison-after",
1765
- className: cn2("absolute inset-0 size-full bg-background select-none", className),
2126
+ className: cn2("absolute inset-0 size-full bg-background outline-1 -outline-offset-1 outline-media-edge select-none", className),
1766
2127
  onLoad: afterHandlers.onLoad,
1767
2128
  onError: afterHandlers.onError
1768
2129
  });
@@ -1775,15 +2136,17 @@ ${after.src}`,
1775
2136
  crossOrigin: before.crossOrigin,
1776
2137
  draggable: false,
1777
2138
  "data-slot": "image-comparison-before",
1778
- className: cn2("absolute inset-0 size-full bg-background object-contain select-none", className),
2139
+ className: cn2("absolute inset-0 size-full bg-background object-contain outline-1 -outline-offset-1 outline-media-edge select-none", className),
1779
2140
  style,
1780
2141
  onLoad: beforeHandlers.onLoad,
1781
2142
  onError: beforeHandlers.onError
1782
2143
  });
1783
2144
  }
2145
+ const sharedStageKeys = [regions.length > 0 ? "N Shift+N" : undefined, stageKeyShortcuts].filter(Boolean).join(" ");
2146
+ const toggleStageKeys = ["B A", sharedStageKeys].filter(Boolean).join(" ");
1784
2147
  let content;
1785
2148
  if (mode === "side-by-side") {
1786
- content = /* @__PURE__ */ jsxs9("div", {
2149
+ content = /* @__PURE__ */ jsxs10("div", {
1787
2150
  "data-slot": "image-comparison-panes",
1788
2151
  className: cn2("flex min-h-0 min-w-0 flex-1", orientation === "vertical" ? "flex-col" : "flex-row"),
1789
2152
  children: [
@@ -1791,7 +2154,7 @@ ${after.src}`,
1791
2154
  header: /* @__PURE__ */ jsx13("span", {
1792
2155
  children: beforeLabel
1793
2156
  }),
1794
- children: /* @__PURE__ */ jsxs9(ImageViewport, {
2157
+ children: /* @__PURE__ */ jsxs10(ImageViewport, {
1795
2158
  label: beforeLabel,
1796
2159
  zoom,
1797
2160
  naturalSize: afterImage.size,
@@ -1800,9 +2163,12 @@ ${after.src}`,
1800
2163
  fallback,
1801
2164
  viewportRef: beforeViewportRef,
1802
2165
  onViewportScroll: (viewport) => syncScroll(viewport, afterViewportRef.current),
2166
+ onStageKeyDown: (event) => handleStageKey(event, "before"),
2167
+ stageKeyShortcuts: sharedStageKeys || undefined,
1803
2168
  children: [
1804
2169
  renderBeforeImage(),
1805
- overlay
2170
+ beforeOverlay,
2171
+ diffOverlay
1806
2172
  ]
1807
2173
  })
1808
2174
  }),
@@ -1813,7 +2179,7 @@ ${after.src}`,
1813
2179
  header: /* @__PURE__ */ jsx13("span", {
1814
2180
  children: afterLabel
1815
2181
  }),
1816
- children: /* @__PURE__ */ jsxs9(ImageViewport, {
2182
+ children: /* @__PURE__ */ jsxs10(ImageViewport, {
1817
2183
  label: afterLabel,
1818
2184
  zoom,
1819
2185
  naturalSize: afterImage.size,
@@ -1822,9 +2188,12 @@ ${after.src}`,
1822
2188
  fallback,
1823
2189
  viewportRef: afterViewportRef,
1824
2190
  onViewportScroll: (viewport) => syncScroll(viewport, beforeViewportRef.current),
2191
+ onStageKeyDown: (event) => handleStageKey(event, "after"),
2192
+ stageKeyShortcuts: sharedStageKeys || undefined,
1825
2193
  children: [
1826
2194
  renderAfterImage(),
1827
- overlay
2195
+ afterOverlay,
2196
+ interactiveDiffOverlay
1828
2197
  ]
1829
2198
  })
1830
2199
  })
@@ -1832,7 +2201,7 @@ ${after.src}`,
1832
2201
  });
1833
2202
  } else if (mode === "swipe") {
1834
2203
  content = /* @__PURE__ */ jsx13(ComparisonPane, {
1835
- header: /* @__PURE__ */ jsxs9(Fragment2, {
2204
+ header: /* @__PURE__ */ jsxs10(Fragment2, {
1836
2205
  children: [
1837
2206
  /* @__PURE__ */ jsx13("span", {
1838
2207
  children: beforeLabel
@@ -1842,30 +2211,36 @@ ${after.src}`,
1842
2211
  })
1843
2212
  ]
1844
2213
  }),
1845
- children: /* @__PURE__ */ jsxs9(ImageViewport, {
2214
+ children: /* @__PURE__ */ jsxs10(ImageViewport, {
1846
2215
  label: `${beforeLabel} and ${afterLabel}`,
1847
2216
  zoom,
1848
2217
  naturalSize: afterImage.size,
1849
2218
  center,
1850
2219
  onZoomChange: setZoom,
1851
2220
  fallback,
2221
+ viewportRef: singleViewportRef,
2222
+ onStageKeyDown: (event) => handleStageKey(event, position > 50 ? "before" : "after"),
2223
+ stageKeyShortcuts: sharedStageKeys || undefined,
1852
2224
  children: [
1853
2225
  renderAfterImage(),
1854
2226
  renderBeforeImage(undefined, { clipPath: `inset(0 ${100 - position}% 0 0)` }),
1855
- overlay,
2227
+ beforeOverlay,
2228
+ afterOverlay,
2229
+ interactiveDiffOverlay,
1856
2230
  /* @__PURE__ */ jsx13(ImageSwipeDivider, {
1857
2231
  value: position,
1858
- onValueChange: setPosition,
2232
+ onValueChange: handlePositionChange,
1859
2233
  beforeLabel,
1860
2234
  afterLabel
1861
- })
2235
+ }),
2236
+ stageOverlay
1862
2237
  ]
1863
2238
  })
1864
2239
  });
1865
2240
  } else {
1866
2241
  const showingLabel = isShowingBefore ? beforeLabel : afterLabel;
1867
2242
  content = /* @__PURE__ */ jsx13(ComparisonPane, {
1868
- header: /* @__PURE__ */ jsxs9("span", {
2243
+ header: /* @__PURE__ */ jsxs10("span", {
1869
2244
  "data-slot": "image-comparison-showing",
1870
2245
  "aria-live": "polite",
1871
2246
  children: [
@@ -1873,24 +2248,28 @@ ${after.src}`,
1873
2248
  showingLabel
1874
2249
  ]
1875
2250
  }),
1876
- children: /* @__PURE__ */ jsxs9(ImageViewport, {
2251
+ children: /* @__PURE__ */ jsxs10(ImageViewport, {
1877
2252
  label: showingLabel,
1878
2253
  zoom,
1879
2254
  naturalSize: afterImage.size,
1880
2255
  center,
1881
2256
  onZoomChange: setZoom,
1882
2257
  fallback,
1883
- onStageKeyDown: handleToggleStageKey,
1884
- stageKeyShortcuts: "B A",
2258
+ viewportRef: singleViewportRef,
2259
+ onStageKeyDown: (event) => handleStageKey(event, shownSide),
2260
+ stageKeyShortcuts: toggleStageKeys,
1885
2261
  children: [
1886
2262
  renderAfterImage(isShowingBefore ? "invisible" : undefined),
1887
2263
  renderBeforeImage(isShowingBefore ? undefined : "invisible"),
1888
- overlay
2264
+ beforeOverlay,
2265
+ afterOverlay,
2266
+ interactiveDiffOverlay,
2267
+ stageOverlay
1889
2268
  ]
1890
2269
  })
1891
2270
  });
1892
2271
  }
1893
- return /* @__PURE__ */ jsx13("div", {
2272
+ return /* @__PURE__ */ jsxs10("div", {
1894
2273
  role: "group",
1895
2274
  "aria-label": label,
1896
2275
  "data-slot": "image-comparison",
@@ -1900,37 +2279,44 @@ ${after.src}`,
1900
2279
  "data-orientation": orientation,
1901
2280
  "data-zoom": zoom,
1902
2281
  "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
- })
2282
+ className: "@container flex size-full min-h-0 min-w-0 flex-1 flex-col",
2283
+ children: [
2284
+ showToolbar && /* @__PURE__ */ jsx13(ImageComparisonToolbar, {
2285
+ mode,
2286
+ onModeChange: setMode,
2287
+ side,
2288
+ onSideChange: setSide,
2289
+ orientation,
2290
+ onOrientationChange: setOrientation,
2291
+ zoom,
2292
+ onZoomChange: setZoom,
2293
+ showDifferences,
2294
+ onShowDifferencesChange: setShowDifferences,
2295
+ differences,
2296
+ activeRegionIndex: clampedActiveIndex,
2297
+ onStepChange: stepChange,
2298
+ onPeekChange: setIsPeeking,
2299
+ beforeLabel,
2300
+ afterLabel,
2301
+ beforeSize: beforeImage.size,
2302
+ afterSize: afterImage.size,
2303
+ toolbar,
2304
+ density
2305
+ }),
2306
+ /* @__PURE__ */ jsx13("div", {
2307
+ ref: stageRef,
2308
+ "data-slot": "image-comparison-stage",
2309
+ "data-scroll": "none",
2310
+ className: "flex min-h-0 min-w-0 flex-1",
2311
+ children: content
2312
+ }),
2313
+ /* @__PURE__ */ jsx13("p", {
2314
+ role: "status",
2315
+ "data-slot": "image-comparison-change-announcement",
2316
+ className: "sr-only",
2317
+ children: changeAnnouncement
2318
+ })
2319
+ ]
1934
2320
  });
1935
2321
  }
1936
2322
  export {