@alexgorbatchev/shadcn 0.0.94 → 0.0.96

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.
Files changed (75) hide show
  1. package/dist/{chunk-bdsdkjcq.js → chunk-1vqyxxma.js} +1 -1
  2. package/dist/{chunk-j2tm6kjm.js → chunk-20ebs5z7.js} +1 -1
  3. package/dist/{chunk-25g7d9m7.js → chunk-22ybn8qf.js} +1 -1
  4. package/dist/chunk-2jsgsjas.js +27 -0
  5. package/dist/{chunk-q0qa9d0w.js → chunk-59emaywr.js} +1 -1
  6. package/dist/{chunk-fnqdw884.js → chunk-5xkfbnap.js} +1 -1
  7. package/dist/{chunk-afegpa2s.js → chunk-6s630syb.js} +1 -1
  8. package/dist/{chunk-fkxhe17e.js → chunk-6z6qn9zr.js} +1 -1
  9. package/dist/{chunk-tz7zjkw3.js → chunk-b2sn56jy.js} +1 -1
  10. package/dist/{chunk-w67bf59k.js → chunk-cjbh4fp5.js} +1 -1
  11. package/dist/{chunk-fg1h007n.js → chunk-d2nyvsjc.js} +1 -1
  12. package/dist/{chunk-r73tntkx.js → chunk-h3a6hmnb.js} +1 -1
  13. package/dist/{chunk-kt1ra60a.js → chunk-j62723nh.js} +1 -1
  14. package/dist/{chunk-6fj02yzp.js → chunk-paswgbzy.js} +3 -3
  15. package/dist/{chunk-s8qhybtb.js → chunk-pj739h1d.js} +1 -1
  16. package/dist/{chunk-k1428vt3.js → chunk-q6ay6f5f.js} +1 -1
  17. package/dist/{chunk-2sx5jnyv.js → chunk-qs48ad08.js} +1 -1
  18. package/dist/{chunk-4p4vggpr.js → chunk-r3yp5xm2.js} +1 -1
  19. package/dist/{chunk-5rzhnmv6.js → chunk-r63yrdr2.js} +1 -1
  20. package/dist/{chunk-mjxhvwgg.js → chunk-tzf47swm.js} +4 -4
  21. package/dist/{chunk-hyhr09xy.js → chunk-v3ep6b3p.js} +1 -1
  22. package/dist/{chunk-77zbd22x.js → chunk-w9mmcpfj.js} +2 -2
  23. package/dist/{chunk-wrm689qy.js → chunk-wgvpxw3p.js} +8 -8
  24. package/dist/{chunk-kq3348h4.js → chunk-xfx55ter.js} +2 -2
  25. package/dist/{chunk-t6gbcj27.js → chunk-xyttc32e.js} +2 -1
  26. package/dist/{chunk-nssz3p32.js → chunk-zz3egmv4.js} +1 -1
  27. package/dist/components/assistant-ui/elements/CommandPalette.js +3 -3
  28. package/dist/components/assistant-ui/elements/GenerativeUi.js +4 -4
  29. package/dist/components/assistant-ui/elements/Image.js +2 -2
  30. package/dist/components/assistant-ui/elements/ImageGallery.js +2 -2
  31. package/dist/components/assistant-ui/elements/MermaidDiagram.js +3 -3
  32. package/dist/components/assistant-ui/elements/MermaidZoom.js +2 -2
  33. package/dist/components/assistant-ui/elements/ModelSelector.js +9 -9
  34. package/dist/components/assistant-ui/elements/ModelSelectorContent.js +8 -8
  35. package/dist/components/assistant-ui/elements/ModelSelectorEmpty.js +3 -3
  36. package/dist/components/assistant-ui/elements/ModelSelectorFocusAnchor.js +3 -3
  37. package/dist/components/assistant-ui/elements/ModelSelectorGroup.js +3 -3
  38. package/dist/components/assistant-ui/elements/ModelSelectorItem.js +3 -3
  39. package/dist/components/assistant-ui/elements/ModelSelectorList.js +5 -5
  40. package/dist/components/assistant-ui/elements/ModelSelectorSearch.js +3 -3
  41. package/dist/components/assistant-ui/elements/ModelSelectorSeparator.js +3 -3
  42. package/dist/components/assistant-ui/index.js +17 -17
  43. package/dist/components/assistant-ui/native/AssistantModal.js +5 -5
  44. package/dist/components/assistant-ui/native/AssistantSidebar.js +5 -5
  45. package/dist/components/assistant-ui/native/AttachmentPreview.js +2 -2
  46. package/dist/components/assistant-ui/native/McpConfigDialog.js +2 -2
  47. package/dist/components/assistant-ui/native/MermaidDiagram.js +4 -4
  48. package/dist/components/assistant-ui/native/ModelSelector.js +11 -11
  49. package/dist/components/assistant-ui/native/Thread.js +4 -4
  50. package/dist/components/assistant-ui/native/index.js +20 -20
  51. package/dist/components/command/index.js +2 -2
  52. package/dist/components/image-viewer/FramedImage.d.ts +16 -0
  53. package/dist/components/image-viewer/ImageRegionMarker.d.ts +33 -8
  54. package/dist/components/image-viewer/ImageRegionSelect.d.ts +12 -0
  55. package/dist/components/image-viewer/ImageViewer.d.ts +32 -7
  56. package/dist/components/image-viewer/ImageViewport.d.ts +20 -5
  57. package/dist/components/image-viewer/ImageZoomControl.d.ts +18 -0
  58. package/dist/components/image-viewer/ImageZoomToggle.d.ts +1 -1
  59. package/dist/components/image-viewer/getImageStageSize.d.ts +2 -1
  60. package/dist/components/image-viewer/imageZoom.d.ts +26 -0
  61. package/dist/components/image-viewer/index.d.ts +9 -2
  62. package/dist/components/image-viewer/index.js +638 -171
  63. package/dist/components/image-viewer/types.d.ts +13 -2
  64. package/dist/components/json-render/index.js +7 -5
  65. package/dist/index.js +2 -2
  66. package/dist/prototype.js +1 -1
  67. package/dist/theme.css +5 -0
  68. package/llms/components/data-display/FramedImage.md +66 -0
  69. package/llms/components/data-display/ImageComparison.md +3 -3
  70. package/llms/components/data-display/ImageRegionMarker.md +19 -3
  71. package/llms/components/data-display/ImageViewer.md +28 -9
  72. package/llms/components/data-display/ImageZoomToggle.md +3 -3
  73. package/llms/components/overlays/Dialog.md +17 -0
  74. package/llms.txt +5 -4
  75. package/package.json +1 -1
@@ -3,19 +3,23 @@ import {
3
3
  } from "../../chunk-en44w1pn.js";
4
4
  import"../../chunk-7ny0vyek.js";
5
5
  import"../../chunk-8ssktt4b.js";
6
+ import"../../chunk-e6hk39ev.js";
7
+ import"../../chunk-x90xmrba.js";
8
+ import"../../chunk-jpvw9xqy.js";
9
+ import {
10
+ Button2
11
+ } from "../../chunk-32t5kc0y.js";
6
12
  import {
13
+ Toggle2,
7
14
  ToggleGroup2,
8
15
  ToggleGroupItem2
9
16
  } from "../../chunk-9n617bte.js";
17
+ import {
18
+ FramedImage2
19
+ } from "../../chunk-2jsgsjas.js";
10
20
  import {
11
21
  Separator2
12
22
  } from "../../chunk-52aadmkc.js";
13
- import"../../chunk-e6hk39ev.js";
14
- import"../../chunk-x90xmrba.js";
15
- import"../../chunk-jpvw9xqy.js";
16
- import {
17
- Button2
18
- } from "../../chunk-32t5kc0y.js";
19
23
  import"../../chunk-m32ptxf3.js";
20
24
  import {
21
25
  Field2,
@@ -30,18 +34,75 @@ import"../../chunk-5mydsjp3.js";
30
34
 
31
35
  // src/components/image-viewer/ImageViewer.tsx
32
36
  import { useControlled } from "@base-ui/utils/useControlled";
33
- import { useRef as useRef2 } from "react";
37
+ import { useIsoLayoutEffect as useIsoLayoutEffect3 } from "@base-ui/utils/useIsoLayoutEffect";
38
+ import { useMergedRefs as useMergedRefs2 } from "@base-ui/utils/useMergedRefs";
39
+ import {
40
+ useRef as useRef2,
41
+ useState as useState3
42
+ } from "react";
34
43
 
35
44
  // src/components/image-viewer/ImageViewport.tsx
36
45
  import { useIsoLayoutEffect as useIsoLayoutEffect2 } from "@base-ui/utils/useIsoLayoutEffect";
37
46
  import { useMergedRefs } from "@base-ui/utils/useMergedRefs";
38
- import { useRef } from "react";
47
+ import { useStableCallback } from "@base-ui/utils/useStableCallback";
48
+ import {
49
+ useEffect,
50
+ useRef
51
+ } from "react";
52
+
53
+ // src/components/image-viewer/imageZoom.ts
54
+ var MAX_IMAGE_ZOOM = 4;
55
+ var IMAGE_ZOOM_STEPS = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4];
56
+ var EPSILON = 0.001;
57
+ var TALL_RATIO = 1.25;
58
+ function clamp(value, min, max) {
59
+ return Math.min(max, Math.max(min, value));
60
+ }
61
+ function getImageZoomScales(natural, viewport) {
62
+ if (natural.width <= 0 || natural.height <= 0)
63
+ return { fit: 1, fitWidth: 1 };
64
+ const fit = Math.max(0, Math.min(1, viewport.width / natural.width, viewport.height / natural.height));
65
+ const fitWidth = Math.max(0, Math.min(MAX_IMAGE_ZOOM, viewport.width / natural.width));
66
+ return { fit, fitWidth };
67
+ }
68
+ function getMinimumScale(scales) {
69
+ return Math.min(scales.fit, MAX_IMAGE_ZOOM);
70
+ }
71
+ function resolveImageZoomScale(zoom, scales) {
72
+ if (zoom === "fit")
73
+ return scales.fit;
74
+ if (zoom === "fit-width")
75
+ return scales.fitWidth;
76
+ return clamp(zoom, getMinimumScale(scales), MAX_IMAGE_ZOOM);
77
+ }
78
+ function clampImageZoomScale(scale, scales) {
79
+ return clamp(scale, getMinimumScale(scales), MAX_IMAGE_ZOOM);
80
+ }
81
+ function getNextImageZoom(scale) {
82
+ return IMAGE_ZOOM_STEPS.find((step) => step > scale + EPSILON) ?? MAX_IMAGE_ZOOM;
83
+ }
84
+ function getPreviousImageZoom(scale, scales) {
85
+ const previous = IMAGE_ZOOM_STEPS.findLast((step) => step < scale - EPSILON);
86
+ return previous === undefined || previous <= scales.fit + EPSILON ? "fit" : previous;
87
+ }
88
+ function getOpeningImageZoom(natural, viewport, minimumWidth = 0) {
89
+ const scales = getImageZoomScales(natural, viewport);
90
+ const isTall = natural.height > viewport.height && scales.fitWidth > scales.fit * TALL_RATIO;
91
+ const zoom = isTall ? "fit-width" : "fit";
92
+ const scale = resolveImageZoomScale(zoom, scales);
93
+ if (natural.width <= 0 || natural.width * scale >= minimumWidth - EPSILON)
94
+ return zoom;
95
+ return clamp(minimumWidth / natural.width, scale, MAX_IMAGE_ZOOM);
96
+ }
97
+ function formatImageZoom(scale) {
98
+ return `${Math.round(scale * 100)}%`;
99
+ }
39
100
 
40
101
  // src/components/image-viewer/getImageStageSize.ts
41
102
  function getImageStageSize(natural, viewport, zoom) {
42
103
  const width = Math.max(0, natural.width);
43
104
  const height = Math.max(0, natural.height);
44
- const scale = zoom === "original" || width === 0 || height === 0 ? 1 : Math.max(0, Math.min(1, viewport.width / width, viewport.height / height));
105
+ const scale = resolveImageZoomScale(zoom, getImageZoomScales({ width, height }, viewport));
45
106
  return { width: width * scale, height: height * scale, scale };
46
107
  }
47
108
 
@@ -69,6 +130,32 @@ function useElementSize(ref) {
69
130
 
70
131
  // src/components/image-viewer/ImageViewport.tsx
71
132
  import { jsx } from "react/jsx-runtime";
133
+ var PAN_THRESHOLD = 4;
134
+ var KEY_PAN_FRACTION = 0.1;
135
+ var KEY_PAN_MINIMUM = 40;
136
+ var STAGE_KEYS = "+ = - 0 1 ArrowUp ArrowDown ArrowLeft ArrowRight";
137
+ function clampUnit(value) {
138
+ return Math.min(1, Math.max(0, value));
139
+ }
140
+ function getDistance(points) {
141
+ const [first, second] = points;
142
+ if (!first || !second)
143
+ return 0;
144
+ return Math.hypot(second.clientX - first.clientX, second.clientY - first.clientY);
145
+ }
146
+ function getMidpoint(points) {
147
+ const [first, second] = points;
148
+ if (!first || !second)
149
+ return first ?? { clientX: 0, clientY: 0 };
150
+ return { clientX: (first.clientX + second.clientX) / 2, clientY: (first.clientY + second.clientY) / 2 };
151
+ }
152
+ function getWheelPixels(event) {
153
+ if (event.deltaMode === WheelEvent.DOM_DELTA_LINE)
154
+ return event.deltaY * 16;
155
+ if (event.deltaMode === WheelEvent.DOM_DELTA_PAGE)
156
+ return event.deltaY * 400;
157
+ return event.deltaY;
158
+ }
72
159
  function ImageViewport({
73
160
  label,
74
161
  zoom,
@@ -77,14 +164,24 @@ function ImageViewport({
77
164
  children,
78
165
  fallback,
79
166
  viewportRef,
80
- onViewportScroll
167
+ onViewportScroll,
168
+ onZoomChange,
169
+ onStageKeyDown,
170
+ stageKeyShortcuts
81
171
  }) {
82
172
  const elementRef = useRef(null);
173
+ const stageRef = useRef(null);
83
174
  const ref = useMergedRefs(elementRef, viewportRef);
84
175
  const viewportSize = useElementSize(elementRef);
176
+ const pointers = useRef(new Map);
177
+ const gesture = useRef(null);
178
+ const suppressClick = useRef(false);
179
+ const scales = naturalSize && viewportSize ? getImageZoomScales(naturalSize, viewportSize) : undefined;
85
180
  const stage = naturalSize && viewportSize ? getImageStageSize(naturalSize, viewportSize, zoom) : undefined;
86
181
  const stageWidth = stage?.width ?? 0;
87
182
  const stageHeight = stage?.height ?? 0;
183
+ const canPanX = viewportSize !== undefined && stageWidth > viewportSize.width + 0.5;
184
+ const canPanY = viewportSize !== undefined && stageHeight > viewportSize.height + 0.5;
88
185
  useIsoLayoutEffect2(() => {
89
186
  const viewport = elementRef.current;
90
187
  if (!viewport || stageWidth === 0 || stageHeight === 0)
@@ -96,9 +193,48 @@ function ImageViewport({
96
193
  viewport.scrollLeft = center.current.x * stageWidth - viewport.clientWidth / 2;
97
194
  viewport.scrollTop = center.current.y * stageHeight - viewport.clientHeight / 2;
98
195
  }, [center, stageHeight, stageWidth, zoom]);
196
+ const changeZoom = useStableCallback((next, anchor) => {
197
+ const viewport = elementRef.current;
198
+ const stageElement = stageRef.current;
199
+ if (!onZoomChange || !viewport || !stageElement || !naturalSize || !viewportSize)
200
+ return;
201
+ const nextStage = getImageStageSize(naturalSize, viewportSize, next);
202
+ if (nextStage.width > 0 && nextStage.height > 0) {
203
+ const frame = viewport.getBoundingClientRect();
204
+ const box = stageElement.getBoundingClientRect();
205
+ const middle = {
206
+ clientX: frame.left + viewport.clientLeft + viewport.clientWidth / 2,
207
+ clientY: frame.top + viewport.clientTop + viewport.clientHeight / 2
208
+ };
209
+ const point = anchor ?? middle;
210
+ const x = box.width > 0 ? (point.clientX - box.left) / box.width : 0.5;
211
+ const y = box.height > 0 ? (point.clientY - box.top) / box.height : 0.5;
212
+ center.current = {
213
+ x: clampUnit(x - (point.clientX - middle.clientX) / nextStage.width),
214
+ y: clampUnit(y - (point.clientY - middle.clientY) / nextStage.height)
215
+ };
216
+ }
217
+ onZoomChange(next);
218
+ });
219
+ const handleWheel = useStableCallback((event) => {
220
+ if (!(event.ctrlKey || event.metaKey) || !onZoomChange || !stage || !scales)
221
+ return;
222
+ event.preventDefault();
223
+ const next = clampImageZoomScale(stage.scale * Math.exp(-getWheelPixels(event) * 0.01), scales);
224
+ if (Math.abs(next - stage.scale) > 0.0005)
225
+ changeZoom(next, event);
226
+ });
227
+ useEffect(() => {
228
+ const viewport = elementRef.current;
229
+ if (!viewport)
230
+ return;
231
+ const listener = (event) => handleWheel(event);
232
+ viewport.addEventListener("wheel", listener, { passive: false });
233
+ return () => viewport.removeEventListener("wheel", listener);
234
+ }, [handleWheel]);
99
235
  function handleScroll(event) {
100
236
  const viewport = event.currentTarget;
101
- if (zoom === "original" && stageWidth > 0 && stageHeight > 0) {
237
+ if (zoom !== "fit" && stageWidth > 0 && stageHeight > 0) {
102
238
  center.current = {
103
239
  x: stageWidth > viewport.clientWidth ? (viewport.scrollLeft + viewport.clientWidth / 2) / stageWidth : 0.5,
104
240
  y: stageHeight > viewport.clientHeight ? (viewport.scrollTop + viewport.clientHeight / 2) / stageHeight : 0.5
@@ -106,16 +242,145 @@ function ImageViewport({
106
242
  }
107
243
  onViewportScroll?.(viewport);
108
244
  }
245
+ function handleKeyDown(event) {
246
+ if (event.target !== event.currentTarget)
247
+ return;
248
+ onStageKeyDown?.(event);
249
+ if (event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || !stage || !scales)
250
+ return;
251
+ const viewport = event.currentTarget;
252
+ const panX = Math.max(KEY_PAN_MINIMUM, viewport.clientWidth * KEY_PAN_FRACTION);
253
+ const panY = Math.max(KEY_PAN_MINIMUM, viewport.clientHeight * KEY_PAN_FRACTION);
254
+ switch (event.key) {
255
+ case "+":
256
+ case "=":
257
+ if (!onZoomChange)
258
+ return;
259
+ changeZoom(getNextImageZoom(stage.scale));
260
+ break;
261
+ case "-":
262
+ case "_":
263
+ if (!onZoomChange)
264
+ return;
265
+ changeZoom(getPreviousImageZoom(stage.scale, scales));
266
+ break;
267
+ case "0":
268
+ if (!onZoomChange)
269
+ return;
270
+ changeZoom("fit");
271
+ break;
272
+ case "1":
273
+ if (!onZoomChange)
274
+ return;
275
+ changeZoom(1);
276
+ break;
277
+ case "ArrowLeft":
278
+ case "ArrowRight":
279
+ if (!canPanX)
280
+ return;
281
+ viewport.scrollBy({ left: event.key === "ArrowLeft" ? -panX : panX, behavior: "instant" });
282
+ break;
283
+ case "ArrowUp":
284
+ case "ArrowDown":
285
+ if (!canPanY)
286
+ return;
287
+ viewport.scrollBy({ top: event.key === "ArrowUp" ? -panY : panY, behavior: "instant" });
288
+ break;
289
+ default:
290
+ return;
291
+ }
292
+ event.preventDefault();
293
+ }
294
+ function handlePointerDown(event) {
295
+ if (event.pointerType === "mouse" && event.button !== 0)
296
+ return;
297
+ pointers.current.set(event.pointerId, { clientX: event.clientX, clientY: event.clientY });
298
+ const points = [...pointers.current.values()];
299
+ if (points.length === 2 && event.pointerType === "touch" && onZoomChange && stage) {
300
+ gesture.current = { kind: "pinch", distance: getDistance(points), scale: stage.scale };
301
+ return;
302
+ }
303
+ if (points.length !== 1 || event.defaultPrevented)
304
+ return;
305
+ const viewport = event.currentTarget;
306
+ gesture.current = {
307
+ kind: "pan",
308
+ pointerId: event.pointerId,
309
+ startX: event.clientX,
310
+ startY: event.clientY,
311
+ left: viewport.scrollLeft,
312
+ top: viewport.scrollTop,
313
+ moved: false
314
+ };
315
+ }
316
+ function handlePointerMove(event) {
317
+ if (!pointers.current.has(event.pointerId))
318
+ return;
319
+ pointers.current.set(event.pointerId, { clientX: event.clientX, clientY: event.clientY });
320
+ const current = gesture.current;
321
+ if (!current)
322
+ return;
323
+ if (current.kind === "pinch") {
324
+ const points = [...pointers.current.values()];
325
+ const distance = getDistance(points);
326
+ if (!scales || current.distance <= 0 || distance <= 0)
327
+ return;
328
+ const next = clampImageZoomScale(current.scale * distance / current.distance, scales);
329
+ changeZoom(next, getMidpoint(points));
330
+ return;
331
+ }
332
+ if (current.pointerId !== event.pointerId)
333
+ return;
334
+ const dx = event.clientX - current.startX;
335
+ const dy = event.clientY - current.startY;
336
+ const viewport = event.currentTarget;
337
+ if (!current.moved) {
338
+ if (Math.abs(dx) < PAN_THRESHOLD && Math.abs(dy) < PAN_THRESHOLD)
339
+ return;
340
+ current.moved = true;
341
+ suppressClick.current = true;
342
+ viewport.setPointerCapture(event.pointerId);
343
+ viewport.dataset.panning = "";
344
+ }
345
+ viewport.scrollLeft = current.left - dx;
346
+ viewport.scrollTop = current.top - dy;
347
+ }
348
+ function handlePointerEnd(event) {
349
+ pointers.current.delete(event.pointerId);
350
+ const current = gesture.current;
351
+ if (current?.kind === "pinch" && pointers.current.size < 2)
352
+ gesture.current = null;
353
+ if (current?.kind === "pan" && current.pointerId === event.pointerId)
354
+ gesture.current = null;
355
+ delete event.currentTarget.dataset.panning;
356
+ }
357
+ function handleClickCapture(event) {
358
+ if (!suppressClick.current)
359
+ return;
360
+ suppressClick.current = false;
361
+ event.preventDefault();
362
+ event.stopPropagation();
363
+ }
109
364
  return /* @__PURE__ */ jsx("div", {
110
365
  ref,
111
366
  role: "region",
112
- "aria-label": label,
367
+ "aria-label": stage ? `${label}, ${formatImageZoom(stage.scale)}` : label,
368
+ "aria-keyshortcuts": onZoomChange ? [STAGE_KEYS, stageKeyShortcuts].filter(Boolean).join(" ") : stageKeyShortcuts,
113
369
  tabIndex: 0,
114
370
  "data-slot": "image-viewport",
115
371
  "data-zoom": zoom,
372
+ "data-scale": stage?.scale,
373
+ "data-pannable": canPanX || canPanY ? "" : undefined,
116
374
  onScroll: handleScroll,
117
- className: cn2("flex min-h-0 min-w-0 flex-1 overscroll-contain outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-inset", zoom === "fit" ? "overflow-hidden" : "overflow-auto"),
375
+ onKeyDown: handleKeyDown,
376
+ onPointerDown: handlePointerDown,
377
+ onPointerMove: handlePointerMove,
378
+ onPointerUp: handlePointerEnd,
379
+ onPointerCancel: handlePointerEnd,
380
+ onClickCapture: handleClickCapture,
381
+ 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"),
118
382
  children: fallback ?? /* @__PURE__ */ jsx("div", {
383
+ ref: stageRef,
119
384
  "data-slot": "image-stage",
120
385
  className: "relative m-auto shrink-0",
121
386
  style: { width: stageWidth, height: stageHeight },
@@ -124,38 +389,72 @@ function ImageViewport({
124
389
  });
125
390
  }
126
391
 
127
- // src/components/image-viewer/ImageZoomToggle.tsx
392
+ // src/components/image-viewer/ImageZoomControl.tsx
393
+ import { MinusIcon, PlusIcon } from "lucide-react";
128
394
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
129
- function ImageZoomToggle({
395
+ function ImageZoomControl({
130
396
  zoom,
397
+ scale,
398
+ scales,
131
399
  onZoomChange,
132
400
  label = "Zoom",
133
- size = "sm",
134
- orientation = "horizontal",
135
- layout = "content",
136
- disabled = false,
137
401
  density
138
402
  }) {
139
- return /* @__PURE__ */ jsxs(ToggleGroup2, {
403
+ const isMeasured = scale !== undefined && scales !== undefined;
404
+ return /* @__PURE__ */ jsxs("div", {
405
+ role: "group",
140
406
  "aria-label": label,
141
- required: true,
142
- value: [zoom],
143
- onValueChange: (value) => onZoomChange(value[0] === "original" ? "original" : "fit"),
144
- variant: "outline",
145
- size,
146
- spacing: 0,
147
- orientation,
148
- layout,
149
- disabled,
150
- density,
407
+ "data-slot": "image-zoom-control",
408
+ "data-density": density,
409
+ className: "flex shrink-0 items-center gap-control-gap",
151
410
  children: [
152
- /* @__PURE__ */ jsx2(ToggleGroupItem2, {
153
- value: "fit",
154
- children: "Fit to screen"
411
+ /* @__PURE__ */ jsx2(Toggle2, {
412
+ variant: "outline",
413
+ size: "sm",
414
+ density,
415
+ pressed: zoom === "fit",
416
+ onPressedChange: () => onZoomChange("fit"),
417
+ children: "Fit"
155
418
  }),
156
- /* @__PURE__ */ jsx2(ToggleGroupItem2, {
157
- value: "original",
158
- children: "Original size"
419
+ /* @__PURE__ */ jsx2(Toggle2, {
420
+ variant: "outline",
421
+ size: "sm",
422
+ density,
423
+ pressed: zoom === "fit-width",
424
+ onPressedChange: () => onZoomChange("fit-width"),
425
+ children: "Fit width"
426
+ }),
427
+ /* @__PURE__ */ jsx2(Button2, {
428
+ variant: "outline",
429
+ size: "icon-sm",
430
+ density,
431
+ focusableWhenDisabled: true,
432
+ "aria-label": "Zoom out",
433
+ disabled: !isMeasured || zoom === "fit" || scale <= scales.fit + 0.001,
434
+ onClick: () => {
435
+ if (isMeasured)
436
+ onZoomChange(getPreviousImageZoom(scale, scales));
437
+ },
438
+ children: /* @__PURE__ */ jsx2(MinusIcon, {})
439
+ }),
440
+ /* @__PURE__ */ jsx2("output", {
441
+ "aria-label": "Zoom level",
442
+ "data-slot": "image-zoom-level",
443
+ className: "min-w-12 text-center text-sm tabular-nums",
444
+ children: isMeasured ? formatImageZoom(scale) : "–"
445
+ }),
446
+ /* @__PURE__ */ jsx2(Button2, {
447
+ variant: "outline",
448
+ size: "icon-sm",
449
+ density,
450
+ focusableWhenDisabled: true,
451
+ "aria-label": "Zoom in",
452
+ disabled: !isMeasured || scale >= MAX_IMAGE_ZOOM - 0.001,
453
+ onClick: () => {
454
+ if (isMeasured)
455
+ onZoomChange(getNextImageZoom(scale));
456
+ },
457
+ children: /* @__PURE__ */ jsx2(PlusIcon, {})
159
458
  })
160
459
  ]
161
460
  });
@@ -182,13 +481,18 @@ function ImageViewer({
182
481
  alt,
183
482
  crossOrigin,
184
483
  zoom: zoomProp,
185
- defaultZoom = "fit",
484
+ defaultZoom,
186
485
  onZoomChange,
486
+ openingWidth,
187
487
  showZoomControl = false,
488
+ toolbar,
188
489
  overlay,
189
490
  imageRef,
190
491
  overlayRef,
492
+ stageRef,
191
493
  label,
494
+ onStageKeyDown,
495
+ stageKeyShortcuts,
192
496
  onLoad,
193
497
  onError,
194
498
  density
@@ -200,33 +504,60 @@ function ImageViewer({
200
504
  state: "zoom"
201
505
  });
202
506
  const center = useRef2({ x: 0.5, y: 0.5 });
507
+ const viewportRef = useRef2(null);
508
+ const mergedStageRef = useMergedRefs2(viewportRef, stageRef);
509
+ const viewportSize = useElementSize(viewportRef);
203
510
  const [image, imageHandlers] = useImageLoad(src);
511
+ const [openingZoom, setOpeningZoom] = useState3();
512
+ const naturalSize = image.size;
513
+ const scales = naturalSize && viewportSize ? getImageZoomScales(naturalSize, viewportSize) : undefined;
514
+ useIsoLayoutEffect3(() => {
515
+ if (zoom !== undefined || openingZoom !== undefined || !naturalSize || !viewportSize)
516
+ return;
517
+ const opening = getOpeningImageZoom(naturalSize, viewportSize, openingWidth);
518
+ const stageHeight = naturalSize.height * resolveImageZoomScale(opening, getImageZoomScales(naturalSize, viewportSize));
519
+ if (stageHeight > viewportSize.height)
520
+ center.current = { x: 0.5, y: viewportSize.height / 2 / stageHeight };
521
+ setOpeningZoom(opening);
522
+ }, [naturalSize, openingWidth, openingZoom, viewportSize, zoom]);
523
+ const shownZoom = zoom ?? openingZoom ?? "fit";
524
+ const scale = scales ? resolveImageZoomScale(shownZoom, scales) : undefined;
204
525
  function setZoom(next) {
205
526
  setZoomState(next);
527
+ setOpeningZoom(next);
206
528
  onZoomChange?.(next);
207
529
  }
208
530
  return /* @__PURE__ */ jsxs2("div", {
209
531
  "data-slot": "image-viewer",
210
532
  "data-scroll": "none",
211
533
  "data-density": density,
212
- "data-zoom": zoom,
534
+ "data-zoom": shownZoom,
213
535
  "data-status": image.status,
214
536
  className: "flex size-full min-h-0 min-w-0 flex-1 flex-col gap-2",
215
537
  children: [
216
- showZoomControl && /* @__PURE__ */ jsx3("div", {
538
+ (showZoomControl || toolbar !== undefined) && /* @__PURE__ */ jsxs2("div", {
217
539
  "data-slot": "image-viewer-toolbar",
218
- className: "flex shrink-0 justify-end",
219
- children: /* @__PURE__ */ jsx3(ImageZoomToggle, {
220
- zoom,
221
- onZoomChange: setZoom,
222
- density
223
- })
540
+ className: "flex shrink-0 flex-nowrap items-center gap-control-gap overflow-x-auto overscroll-x-contain *:shrink-0",
541
+ children: [
542
+ showZoomControl && /* @__PURE__ */ jsx3(ImageZoomControl, {
543
+ zoom: shownZoom,
544
+ scale,
545
+ scales,
546
+ onZoomChange: setZoom,
547
+ density
548
+ }),
549
+ toolbar
550
+ ]
224
551
  }),
225
552
  /* @__PURE__ */ jsxs2(ImageViewport, {
226
553
  label: label ?? alt,
227
- zoom,
228
- naturalSize: image.size,
554
+ zoom: shownZoom,
555
+ naturalSize,
229
556
  center,
557
+ viewportRef: mergedStageRef,
558
+ onZoomChange: setZoom,
559
+ onStageKeyDown,
560
+ stageKeyShortcuts,
230
561
  fallback: image.status === "error" ? /* @__PURE__ */ jsx3("p", {
231
562
  "data-slot": "image-viewer-error",
232
563
  className: "m-auto p-panel text-center text-sm text-muted-foreground",
@@ -240,7 +571,7 @@ function ImageViewer({
240
571
  crossOrigin,
241
572
  draggable: false,
242
573
  "data-slot": "image-viewer-image",
243
- className: "block size-full select-none",
574
+ className: "block size-full outline-1 -outline-offset-1 outline-media-edge select-none",
244
575
  onLoad: (event) => {
245
576
  imageHandlers.onLoad(event);
246
577
  onLoad?.(event);
@@ -261,20 +592,180 @@ function ImageViewer({
261
592
  ]
262
593
  });
263
594
  }
595
+ // src/components/image-viewer/ImageZoomToggle.tsx
596
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
597
+ function ImageZoomToggle({
598
+ zoom,
599
+ onZoomChange,
600
+ label = "Zoom",
601
+ size = "sm",
602
+ orientation = "horizontal",
603
+ layout = "content",
604
+ disabled = false,
605
+ density
606
+ }) {
607
+ return /* @__PURE__ */ jsxs3(ToggleGroup2, {
608
+ "aria-label": label,
609
+ value: zoom === "fit" ? ["fit"] : zoom === 1 ? ["original"] : [],
610
+ onValueChange: (value) => {
611
+ if (value[0] !== undefined)
612
+ onZoomChange(value[0] === "original" ? 1 : "fit");
613
+ },
614
+ variant: "outline",
615
+ size,
616
+ spacing: 0,
617
+ orientation,
618
+ layout,
619
+ disabled,
620
+ density,
621
+ children: [
622
+ /* @__PURE__ */ jsx4(ToggleGroupItem2, {
623
+ value: "fit",
624
+ children: "Fit to screen"
625
+ }),
626
+ /* @__PURE__ */ jsx4(ToggleGroupItem2, {
627
+ value: "original",
628
+ children: "Original size"
629
+ })
630
+ ]
631
+ });
632
+ }
633
+ // src/components/image-viewer/ImageRegionSelect.tsx
634
+ import { useRef as useRef3, useState as useState4 } from "react";
635
+
636
+ // src/components/image-viewer/getNormalizedImagePoint.ts
637
+ function clampUnit2(value) {
638
+ return Math.min(1, Math.max(0, value));
639
+ }
640
+ function getNormalizedImagePoint(point, box) {
641
+ return {
642
+ x: box.width > 0 ? clampUnit2((point.clientX - box.left) / box.width) : 0,
643
+ y: box.height > 0 ? clampUnit2((point.clientY - box.top) / box.height) : 0
644
+ };
645
+ }
646
+
647
+ // src/components/image-viewer/ImageRegionMarker.tsx
648
+ import { cva } from "class-variance-authority";
649
+ import { jsx as jsx5 } from "react/jsx-runtime";
650
+ var imageRegionMarkerVariants = cva("pointer-events-none absolute rounded-xs shadow-[0_0_0_4px_var(--background)] ring-1 ring-background outline-2 outline-offset-1 forced-colors:outline-[Highlight]", {
651
+ variants: {
652
+ variant: {
653
+ comment: "bg-primary/10 outline-primary",
654
+ draft: "bg-primary/10 outline-dashed outline-primary",
655
+ difference: "bg-warning/10 outline-warning"
656
+ }
657
+ },
658
+ defaultVariants: { variant: "comment" }
659
+ });
660
+ function ImageRegionMarker({
661
+ variant,
662
+ region,
663
+ className,
664
+ style,
665
+ ...props
666
+ }) {
667
+ return /* @__PURE__ */ jsx5("div", {
668
+ "data-slot": "image-region-marker",
669
+ "data-variant": variant ?? "comment",
670
+ className: cn2(imageRegionMarkerVariants({ variant }), className),
671
+ style: region ? { ...style, ...region } : style,
672
+ ...props
673
+ });
674
+ }
675
+ function ImageRegionMarkerBadge({
676
+ position,
677
+ interactive = true,
678
+ className,
679
+ style,
680
+ ...props
681
+ }) {
682
+ return /* @__PURE__ */ jsx5("div", {
683
+ "data-slot": "image-region-marker-badge",
684
+ "data-interactive": interactive,
685
+ className: cn2("absolute z-10 rounded-sm shadow-[0_0_0_4px_var(--background)] outline-2 outline-primary forced-colors:outline-[Highlight]", interactive ? "pointer-events-auto" : "pointer-events-none", className),
686
+ style: position ? { ...style, ...position } : style,
687
+ ...props
688
+ });
689
+ }
690
+
691
+ // src/components/image-viewer/ImageRegionSelect.tsx
692
+ import { jsx as jsx6 } from "react/jsx-runtime";
693
+ var MINIMUM_DRAG = 4;
694
+ function toRegion(start, end) {
695
+ return {
696
+ x: Math.min(start.x, end.x),
697
+ y: Math.min(start.y, end.y),
698
+ width: Math.abs(end.x - start.x),
699
+ height: Math.abs(end.y - start.y)
700
+ };
701
+ }
702
+ function ImageRegionSelect({ onSelect }) {
703
+ const drag = useRef3(null);
704
+ const [draft, setDraft] = useState4();
705
+ const point = (event) => getNormalizedImagePoint(event, event.currentTarget.getBoundingClientRect());
706
+ function cancel() {
707
+ drag.current = null;
708
+ setDraft(undefined);
709
+ }
710
+ return /* @__PURE__ */ jsx6("div", {
711
+ "data-slot": "image-region-select",
712
+ className: "absolute inset-0 cursor-crosshair touch-none",
713
+ onPointerDown: (event) => {
714
+ if (drag.current) {
715
+ if (drag.current.pointerId !== event.pointerId)
716
+ cancel();
717
+ return;
718
+ }
719
+ if (event.pointerType === "mouse" && event.button !== 0)
720
+ return;
721
+ event.preventDefault();
722
+ event.currentTarget.setPointerCapture(event.pointerId);
723
+ drag.current = { pointerId: event.pointerId, start: point(event) };
724
+ setDraft(undefined);
725
+ },
726
+ onPointerMove: (event) => {
727
+ if (drag.current?.pointerId === event.pointerId)
728
+ setDraft(toRegion(drag.current.start, point(event)));
729
+ },
730
+ onPointerUp: (event) => {
731
+ const current = drag.current;
732
+ if (current?.pointerId !== event.pointerId)
733
+ return;
734
+ cancel();
735
+ const region = toRegion(current.start, point(event));
736
+ const bounds = event.currentTarget.getBoundingClientRect();
737
+ if (region.width * bounds.width < MINIMUM_DRAG && region.height * bounds.height < MINIMUM_DRAG)
738
+ return;
739
+ onSelect(region);
740
+ },
741
+ onPointerCancel: cancel,
742
+ children: draft && /* @__PURE__ */ jsx6(ImageRegionMarker, {
743
+ variant: "draft",
744
+ "aria-hidden": "true",
745
+ "data-slot": "image-region-select-draft",
746
+ region: {
747
+ left: `${draft.x * 100}%`,
748
+ top: `${draft.y * 100}%`,
749
+ width: `${draft.width * 100}%`,
750
+ height: `${draft.height * 100}%`
751
+ }
752
+ })
753
+ });
754
+ }
264
755
  // src/components/image-viewer/ImageComparison.tsx
265
756
  import { useControlled as useControlled2 } from "@base-ui/utils/useControlled";
266
- import { useRef as useRef4, useState as useState4 } from "react";
757
+ import { useRef as useRef5, useState as useState6 } from "react";
267
758
 
268
759
  // src/components/image-viewer/ImageComparisonToolbar.tsx
269
760
  import { Columns2Icon, Rows2Icon } from "lucide-react";
270
761
  import { useId } from "react";
271
- import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
762
+ import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
272
763
  function ToolbarSection({ title, titleId, children }) {
273
- return /* @__PURE__ */ jsxs3("div", {
764
+ return /* @__PURE__ */ jsxs4("div", {
274
765
  "data-slot": "image-comparison-toolbar-section",
275
766
  className: "flex min-w-0 flex-col gap-1.5",
276
767
  children: [
277
- /* @__PURE__ */ jsx4("span", {
768
+ /* @__PURE__ */ jsx7("span", {
278
769
  id: titleId,
279
770
  className: "sr-only text-xs font-medium text-muted-foreground @3xl:not-sr-only",
280
771
  children: title
@@ -325,17 +816,17 @@ function ImageComparisonToolbar({
325
816
  const isUnavailable = differences.status === "unavailable";
326
817
  const releasePeek = () => onPeekChange(false);
327
818
  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;
328
- return /* @__PURE__ */ jsxs3("div", {
819
+ return /* @__PURE__ */ jsxs4("div", {
329
820
  role: "group",
330
821
  "aria-label": "Comparison controls",
331
822
  "data-slot": "image-comparison-toolbar",
332
823
  "data-density": density,
333
824
  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",
334
825
  children: [
335
- /* @__PURE__ */ jsx4(ToolbarSection, {
826
+ /* @__PURE__ */ jsx7(ToolbarSection, {
336
827
  title: "Mode",
337
828
  titleId: `${id}-mode`,
338
- children: /* @__PURE__ */ jsxs3(ToggleGroup2, {
829
+ children: /* @__PURE__ */ jsxs4(ToggleGroup2, {
339
830
  "aria-labelledby": `${id}-mode`,
340
831
  required: true,
341
832
  value: [mode],
@@ -344,25 +835,25 @@ function ImageComparisonToolbar({
344
835
  size: "sm",
345
836
  spacing: 0,
346
837
  children: [
347
- /* @__PURE__ */ jsx4(ToggleGroupItem2, {
838
+ /* @__PURE__ */ jsx7(ToggleGroupItem2, {
348
839
  value: "toggle",
349
840
  children: "Toggle"
350
841
  }),
351
- /* @__PURE__ */ jsx4(ToggleGroupItem2, {
842
+ /* @__PURE__ */ jsx7(ToggleGroupItem2, {
352
843
  value: "swipe",
353
844
  children: "Swipe"
354
845
  }),
355
- /* @__PURE__ */ jsx4(ToggleGroupItem2, {
846
+ /* @__PURE__ */ jsx7(ToggleGroupItem2, {
356
847
  value: "side-by-side",
357
848
  children: "Side by side"
358
849
  })
359
850
  ]
360
851
  })
361
852
  }),
362
- /* @__PURE__ */ jsx4(ToolbarSection, {
853
+ /* @__PURE__ */ jsx7(ToolbarSection, {
363
854
  title: "Orientation",
364
855
  titleId: `${id}-orientation`,
365
- children: /* @__PURE__ */ jsxs3(ToggleGroup2, {
856
+ children: /* @__PURE__ */ jsxs4(ToggleGroup2, {
366
857
  "aria-labelledby": `${id}-orientation`,
367
858
  required: true,
368
859
  value: [orientation],
@@ -372,19 +863,19 @@ function ImageComparisonToolbar({
372
863
  spacing: 0,
373
864
  disabled: mode !== "side-by-side",
374
865
  children: [
375
- /* @__PURE__ */ jsxs3(ToggleGroupItem2, {
866
+ /* @__PURE__ */ jsxs4(ToggleGroupItem2, {
376
867
  value: "horizontal",
377
868
  children: [
378
- /* @__PURE__ */ jsx4(Columns2Icon, {
869
+ /* @__PURE__ */ jsx7(Columns2Icon, {
379
870
  "data-icon": "inline-start"
380
871
  }),
381
872
  "Horizontal"
382
873
  ]
383
874
  }),
384
- /* @__PURE__ */ jsxs3(ToggleGroupItem2, {
875
+ /* @__PURE__ */ jsxs4(ToggleGroupItem2, {
385
876
  value: "vertical",
386
877
  children: [
387
- /* @__PURE__ */ jsx4(Rows2Icon, {
878
+ /* @__PURE__ */ jsx7(Rows2Icon, {
388
879
  "data-icon": "inline-start"
389
880
  }),
390
881
  "Vertical"
@@ -393,15 +884,15 @@ function ImageComparisonToolbar({
393
884
  ]
394
885
  })
395
886
  }),
396
- /* @__PURE__ */ jsx4(ToolbarSection, {
887
+ /* @__PURE__ */ jsx7(ToolbarSection, {
397
888
  title: "Zoom",
398
889
  titleId: `${id}-zoom`,
399
- children: /* @__PURE__ */ jsx4(ImageZoomToggle, {
890
+ children: /* @__PURE__ */ jsx7(ImageZoomToggle, {
400
891
  zoom,
401
892
  onZoomChange
402
893
  })
403
894
  }),
404
- /* @__PURE__ */ jsx4(Button2, {
895
+ /* @__PURE__ */ jsx7(Button2, {
405
896
  variant: "outline",
406
897
  size: "sm",
407
898
  disabled: mode !== "toggle",
@@ -425,27 +916,27 @@ function ImageComparisonToolbar({
425
916
  onContextMenu: (event) => event.preventDefault(),
426
917
  children: "Hold to show before"
427
918
  }),
428
- /* @__PURE__ */ jsxs3(Field2, {
919
+ /* @__PURE__ */ jsxs4(Field2, {
429
920
  orientation: "horizontal",
430
921
  children: [
431
- /* @__PURE__ */ jsx4(Switch2, {
922
+ /* @__PURE__ */ jsx7(Switch2, {
432
923
  id: `${id}-differences`,
433
924
  "aria-describedby": `${id}-differences-status`,
434
925
  checked: showDifferences && !isUnavailable,
435
926
  disabled: isUnavailable,
436
927
  onCheckedChange: onShowDifferencesChange
437
928
  }),
438
- /* @__PURE__ */ jsxs3(FieldContent2, {
929
+ /* @__PURE__ */ jsxs4(FieldContent2, {
439
930
  children: [
440
- /* @__PURE__ */ jsx4(FieldLabel2, {
931
+ /* @__PURE__ */ jsx7(FieldLabel2, {
441
932
  htmlFor: `${id}-differences`,
442
933
  children: "Highlight differences"
443
934
  }),
444
- showDifferences && differences.status === "ready" && /* @__PURE__ */ jsxs3(FieldDescription2, {
935
+ showDifferences && differences.status === "ready" && /* @__PURE__ */ jsxs4(FieldDescription2, {
445
936
  "data-slot": "image-comparison-legend",
446
937
  className: "flex items-center gap-1.5",
447
938
  children: [
448
- /* @__PURE__ */ jsx4("span", {
939
+ /* @__PURE__ */ jsx7("span", {
449
940
  "aria-hidden": "true",
450
941
  className: "mx-[3px] size-2.5 shrink-0 rounded-xs bg-warning/10 ring-1 ring-background outline-2 outline-offset-1 outline-warning"
451
942
  }),
@@ -456,16 +947,16 @@ function ImageComparisonToolbar({
456
947
  })
457
948
  ]
458
949
  }),
459
- /* @__PURE__ */ jsxs3("div", {
950
+ /* @__PURE__ */ jsxs4("div", {
460
951
  "data-slot": "image-comparison-status",
461
952
  className: "flex min-w-0 flex-col gap-1 text-xs text-muted-foreground",
462
953
  children: [
463
- /* @__PURE__ */ jsx4("p", {
954
+ /* @__PURE__ */ jsx7("p", {
464
955
  id: `${id}-differences-status`,
465
956
  role: "status",
466
957
  children: describeDifferences(differences, showDifferences)
467
958
  }),
468
- sizeMismatch && /* @__PURE__ */ jsx4("p", {
959
+ sizeMismatch && /* @__PURE__ */ jsx7("p", {
469
960
  "data-slot": "image-comparison-size-mismatch",
470
961
  children: sizeMismatch
471
962
  })
@@ -475,49 +966,20 @@ function ImageComparisonToolbar({
475
966
  });
476
967
  }
477
968
 
478
- // src/components/image-viewer/ImageRegionMarker.tsx
479
- import { cva } from "class-variance-authority";
480
- import { jsx as jsx5 } from "react/jsx-runtime";
481
- var imageRegionMarkerVariants = cva("pointer-events-none absolute rounded-xs shadow-[0_0_0_4px_var(--background)] ring-1 ring-background outline-2 outline-offset-1 forced-colors:outline-[Highlight]", {
482
- variants: {
483
- variant: {
484
- comment: "bg-primary/10 outline-primary",
485
- draft: "bg-primary/10 outline-dashed outline-primary",
486
- difference: "bg-warning/10 outline-warning"
487
- }
488
- },
489
- defaultVariants: { variant: "comment" }
490
- });
491
- function ImageRegionMarker({ variant, className, ...props }) {
492
- return /* @__PURE__ */ jsx5("div", {
493
- "data-slot": "image-region-marker",
494
- "data-variant": variant ?? "comment",
495
- className: cn2(imageRegionMarkerVariants({ variant }), className),
496
- ...props
497
- });
498
- }
499
- function ImageRegionMarkerBadge({ className, ...props }) {
500
- return /* @__PURE__ */ jsx5("div", {
501
- "data-slot": "image-region-marker-badge",
502
- className: cn2("pointer-events-auto absolute z-10 rounded-sm shadow-[0_0_0_4px_var(--background)] outline-2 outline-primary forced-colors:outline-[Highlight]", className),
503
- ...props
504
- });
505
- }
506
-
507
969
  // src/components/image-viewer/ImageDifferenceOverlay.tsx
508
- import { jsx as jsx6 } from "react/jsx-runtime";
970
+ import { jsx as jsx8 } from "react/jsx-runtime";
509
971
  function toPercent(value, total) {
510
972
  return `${value / total * 100}%`;
511
973
  }
512
974
  function ImageDifferenceOverlay({ diff }) {
513
- return /* @__PURE__ */ jsx6("div", {
975
+ return /* @__PURE__ */ jsx8("div", {
514
976
  "data-slot": "image-difference-overlay",
515
977
  "aria-hidden": "true",
516
978
  className: "pointer-events-none absolute inset-0",
517
- children: diff.regions.map((region) => /* @__PURE__ */ jsx6(ImageRegionMarker, {
979
+ children: diff.regions.map((region) => /* @__PURE__ */ jsx8(ImageRegionMarker, {
518
980
  "data-slot": "image-difference-region",
519
981
  variant: "difference",
520
- style: {
982
+ region: {
521
983
  left: toPercent(region.x, diff.width),
522
984
  top: toPercent(region.y, diff.height),
523
985
  width: toPercent(region.width, diff.width),
@@ -531,16 +993,16 @@ function ImageDifferenceOverlay({ diff }) {
531
993
  import { DirectionProvider } from "@base-ui/react/direction-provider";
532
994
  import { Slider as SliderPrimitive } from "@base-ui/react/slider";
533
995
  import { ChevronsLeftRightIcon } from "lucide-react";
534
- import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
996
+ import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
535
997
  function ImageSwipeDivider({
536
998
  value,
537
999
  onValueChange,
538
1000
  beforeLabel,
539
1001
  afterLabel
540
1002
  }) {
541
- return /* @__PURE__ */ jsx7(DirectionProvider, {
1003
+ return /* @__PURE__ */ jsx9(DirectionProvider, {
542
1004
  direction: "ltr",
543
- children: /* @__PURE__ */ jsx7(SliderPrimitive.Root, {
1005
+ children: /* @__PURE__ */ jsx9(SliderPrimitive.Root, {
544
1006
  dir: "ltr",
545
1007
  "data-slot": "image-swipe-divider",
546
1008
  value,
@@ -550,22 +1012,22 @@ function ImageSwipeDivider({
550
1012
  step: 1,
551
1013
  largeStep: 10,
552
1014
  className: "pointer-events-none absolute inset-0",
553
- children: /* @__PURE__ */ jsx7(SliderPrimitive.Control, {
1015
+ children: /* @__PURE__ */ jsx9(SliderPrimitive.Control, {
554
1016
  className: "pointer-events-none absolute inset-0",
555
- children: /* @__PURE__ */ jsxs4(SliderPrimitive.Thumb, {
1017
+ children: /* @__PURE__ */ jsxs5(SliderPrimitive.Thumb, {
556
1018
  "data-slot": "image-swipe-divider-handle",
557
1019
  getAriaLabel: () => "Swipe divider",
558
1020
  getAriaValueText: (_formatted, current) => `${beforeLabel} ${current}%, ${afterLabel} ${100 - current}%`,
559
1021
  className: "group/divider pointer-events-auto flex h-full w-6 cursor-ew-resize touch-none flex-col items-center justify-center select-none",
560
1022
  children: [
561
- /* @__PURE__ */ jsx7("span", {
1023
+ /* @__PURE__ */ jsx9("span", {
562
1024
  "aria-hidden": "true",
563
1025
  className: "absolute inset-y-0 start-1/2 w-0.5 -translate-x-1/2 bg-foreground ring-1 ring-background"
564
1026
  }),
565
- /* @__PURE__ */ jsx7("span", {
1027
+ /* @__PURE__ */ jsx9("span", {
566
1028
  "aria-hidden": "true",
567
1029
  className: "relative flex h-8 w-5 items-center justify-center rounded-sm border border-border bg-background text-foreground shadow-frame group-has-[:focus-visible]/divider:border-ring group-has-[:focus-visible]/divider:ring-1 group-has-[:focus-visible]/divider:ring-ring group-data-dragging/divider:border-ring",
568
- children: /* @__PURE__ */ jsx7(ChevronsLeftRightIcon, {
1030
+ children: /* @__PURE__ */ jsx9(ChevronsLeftRightIcon, {
569
1031
  className: "size-3.5"
570
1032
  })
571
1033
  })
@@ -577,7 +1039,7 @@ function ImageSwipeDivider({
577
1039
  }
578
1040
 
579
1041
  // src/components/image-viewer/hooks/useImageDifferences.ts
580
- import { useEffect, useRef as useRef3, useState as useState3 } from "react";
1042
+ import { useEffect as useEffect2, useRef as useRef4, useState as useState5 } from "react";
581
1043
 
582
1044
  // src/components/image-viewer/computeImageDiff.ts
583
1045
  var DEFAULT_THRESHOLD = 32;
@@ -790,11 +1252,11 @@ function useImageDifferences({
790
1252
  beforeRef,
791
1253
  afterRef
792
1254
  }) {
793
- const [entries, setEntries] = useState3(() => new Map);
794
- const startedRef = useRef3(new Set);
795
- const controllerRef = useRef3(undefined);
796
- useEffect(() => () => controllerRef.current?.abort(), [pairKey]);
797
- useEffect(() => {
1255
+ const [entries, setEntries] = useState5(() => new Map);
1256
+ const startedRef = useRef4(new Set);
1257
+ const controllerRef = useRef4(undefined);
1258
+ useEffect2(() => () => controllerRef.current?.abort(), [pairKey]);
1259
+ useEffect2(() => {
798
1260
  const before = beforeRef.current;
799
1261
  const after = afterRef.current;
800
1262
  if (!loaded || !before || !after)
@@ -809,7 +1271,7 @@ function useImageDifferences({
809
1271
  isCurrent = false;
810
1272
  };
811
1273
  }, [afterRef, beforeRef, loaded, pairKey]);
812
- useEffect(() => {
1274
+ useEffect2(() => {
813
1275
  const before = beforeRef.current;
814
1276
  const after = afterRef.current;
815
1277
  if (!enabled || !loaded || !before || !after || startedRef.current.has(pairKey))
@@ -831,14 +1293,14 @@ function useImageDifferences({
831
1293
  }
832
1294
 
833
1295
  // src/components/image-viewer/ImageComparison.tsx
834
- import { jsx as jsx8, jsxs as jsxs5, Fragment } from "react/jsx-runtime";
1296
+ import { jsx as jsx10, jsxs as jsxs6, Fragment } from "react/jsx-runtime";
835
1297
  function ComparisonPane({ header, children }) {
836
- return /* @__PURE__ */ jsxs5("div", {
1298
+ return /* @__PURE__ */ jsxs6("div", {
837
1299
  "data-slot": "image-comparison-pane",
838
1300
  "data-scroll": "none",
839
1301
  className: "flex min-h-0 min-w-0 flex-1 flex-col",
840
1302
  children: [
841
- /* @__PURE__ */ jsx8("div", {
1303
+ /* @__PURE__ */ jsx10("div", {
842
1304
  "data-slot": "image-comparison-pane-header",
843
1305
  className: "flex h-control shrink-0 items-center justify-between gap-2 px-control-x text-xs font-medium text-muted-foreground",
844
1306
  children: header
@@ -892,16 +1354,16 @@ function ImageComparison({
892
1354
  name: "ImageComparison",
893
1355
  state: "showDifferences"
894
1356
  });
895
- const [isPeeking, setIsPeeking] = useState4(false);
896
- const [position, setPosition] = useState4(50);
1357
+ const [isPeeking, setIsPeeking] = useState6(false);
1358
+ const [position, setPosition] = useState6(50);
897
1359
  const [beforeImage, beforeHandlers] = useImageLoad(before.src);
898
1360
  const [afterImage, afterHandlers] = useImageLoad(after.src);
899
- const beforeRef = useRef4(null);
900
- const afterRef = useRef4(null);
901
- const beforeViewportRef = useRef4(null);
902
- const afterViewportRef = useRef4(null);
903
- const expectedScrollRef = useRef4(new WeakMap);
904
- const center = useRef4({ x: 0.5, y: 0.5 });
1361
+ const beforeRef = useRef5(null);
1362
+ const afterRef = useRef5(null);
1363
+ const beforeViewportRef = useRef5(null);
1364
+ const afterViewportRef = useRef5(null);
1365
+ const expectedScrollRef = useRef5(new WeakMap);
1366
+ const center = useRef5({ x: 0.5, y: 0.5 });
905
1367
  const failedLabel = afterImage.status === "error" ? afterLabel : beforeImage.status === "error" ? beforeLabel : undefined;
906
1368
  const differences = useImageDifferences({
907
1369
  pairKey: `${before.src}
@@ -913,10 +1375,10 @@ ${after.src}`,
913
1375
  afterRef
914
1376
  });
915
1377
  const isShowingBefore = mode === "toggle" && isPeeking;
916
- const overlay = showDifferences && differences.status === "ready" ? /* @__PURE__ */ jsx8(ImageDifferenceOverlay, {
1378
+ const overlay = showDifferences && differences.status === "ready" ? /* @__PURE__ */ jsx10(ImageDifferenceOverlay, {
917
1379
  diff: differences.diff
918
1380
  }) : null;
919
- const fallback = failedLabel ? /* @__PURE__ */ jsxs5("p", {
1381
+ const fallback = failedLabel ? /* @__PURE__ */ jsxs6("p", {
920
1382
  "data-slot": "image-comparison-error",
921
1383
  className: "m-auto p-panel text-center text-sm text-muted-foreground",
922
1384
  children: [
@@ -954,7 +1416,7 @@ ${after.src}`,
954
1416
  }
955
1417
  }
956
1418
  function renderAfterImage(className) {
957
- return /* @__PURE__ */ jsx8("img", {
1419
+ return /* @__PURE__ */ jsx10("img", {
958
1420
  ref: afterRef,
959
1421
  src: after.src,
960
1422
  alt: after.alt,
@@ -967,7 +1429,7 @@ ${after.src}`,
967
1429
  });
968
1430
  }
969
1431
  function renderBeforeImage(className, style) {
970
- return /* @__PURE__ */ jsx8("img", {
1432
+ return /* @__PURE__ */ jsx10("img", {
971
1433
  ref: beforeRef,
972
1434
  src: before.src,
973
1435
  alt: before.alt,
@@ -982,19 +1444,20 @@ ${after.src}`,
982
1444
  }
983
1445
  let content;
984
1446
  if (mode === "side-by-side") {
985
- content = /* @__PURE__ */ jsxs5("div", {
1447
+ content = /* @__PURE__ */ jsxs6("div", {
986
1448
  "data-slot": "image-comparison-panes",
987
1449
  className: cn2("flex min-h-0 min-w-0 flex-1", orientation === "vertical" ? "flex-col" : "flex-row"),
988
1450
  children: [
989
- /* @__PURE__ */ jsx8(ComparisonPane, {
990
- header: /* @__PURE__ */ jsx8("span", {
1451
+ /* @__PURE__ */ jsx10(ComparisonPane, {
1452
+ header: /* @__PURE__ */ jsx10("span", {
991
1453
  children: beforeLabel
992
1454
  }),
993
- children: /* @__PURE__ */ jsxs5(ImageViewport, {
1455
+ children: /* @__PURE__ */ jsxs6(ImageViewport, {
994
1456
  label: beforeLabel,
995
1457
  zoom,
996
1458
  naturalSize: afterImage.size,
997
1459
  center,
1460
+ onZoomChange: setZoom,
998
1461
  fallback,
999
1462
  viewportRef: beforeViewportRef,
1000
1463
  onViewportScroll: (viewport) => syncScroll(viewport, afterViewportRef.current),
@@ -1004,18 +1467,19 @@ ${after.src}`,
1004
1467
  ]
1005
1468
  })
1006
1469
  }),
1007
- /* @__PURE__ */ jsx8(Separator2, {
1470
+ /* @__PURE__ */ jsx10(Separator2, {
1008
1471
  orientation: orientation === "vertical" ? "horizontal" : "vertical"
1009
1472
  }),
1010
- /* @__PURE__ */ jsx8(ComparisonPane, {
1011
- header: /* @__PURE__ */ jsx8("span", {
1473
+ /* @__PURE__ */ jsx10(ComparisonPane, {
1474
+ header: /* @__PURE__ */ jsx10("span", {
1012
1475
  children: afterLabel
1013
1476
  }),
1014
- children: /* @__PURE__ */ jsxs5(ImageViewport, {
1477
+ children: /* @__PURE__ */ jsxs6(ImageViewport, {
1015
1478
  label: afterLabel,
1016
1479
  zoom,
1017
1480
  naturalSize: afterImage.size,
1018
1481
  center,
1482
+ onZoomChange: setZoom,
1019
1483
  fallback,
1020
1484
  viewportRef: afterViewportRef,
1021
1485
  onViewportScroll: (viewport) => syncScroll(viewport, beforeViewportRef.current),
@@ -1028,28 +1492,29 @@ ${after.src}`,
1028
1492
  ]
1029
1493
  });
1030
1494
  } else if (mode === "swipe") {
1031
- content = /* @__PURE__ */ jsx8(ComparisonPane, {
1032
- header: /* @__PURE__ */ jsxs5(Fragment, {
1495
+ content = /* @__PURE__ */ jsx10(ComparisonPane, {
1496
+ header: /* @__PURE__ */ jsxs6(Fragment, {
1033
1497
  children: [
1034
- /* @__PURE__ */ jsx8("span", {
1498
+ /* @__PURE__ */ jsx10("span", {
1035
1499
  children: beforeLabel
1036
1500
  }),
1037
- /* @__PURE__ */ jsx8("span", {
1501
+ /* @__PURE__ */ jsx10("span", {
1038
1502
  children: afterLabel
1039
1503
  })
1040
1504
  ]
1041
1505
  }),
1042
- children: /* @__PURE__ */ jsxs5(ImageViewport, {
1506
+ children: /* @__PURE__ */ jsxs6(ImageViewport, {
1043
1507
  label: `${beforeLabel} and ${afterLabel}`,
1044
1508
  zoom,
1045
1509
  naturalSize: afterImage.size,
1046
1510
  center,
1511
+ onZoomChange: setZoom,
1047
1512
  fallback,
1048
1513
  children: [
1049
1514
  renderAfterImage(),
1050
1515
  renderBeforeImage(undefined, { clipPath: `inset(0 ${100 - position}% 0 0)` }),
1051
1516
  overlay,
1052
- /* @__PURE__ */ jsx8(ImageSwipeDivider, {
1517
+ /* @__PURE__ */ jsx10(ImageSwipeDivider, {
1053
1518
  value: position,
1054
1519
  onValueChange: setPosition,
1055
1520
  beforeLabel,
@@ -1060,8 +1525,8 @@ ${after.src}`,
1060
1525
  });
1061
1526
  } else {
1062
1527
  const showingLabel = isShowingBefore ? beforeLabel : afterLabel;
1063
- content = /* @__PURE__ */ jsx8(ComparisonPane, {
1064
- header: /* @__PURE__ */ jsxs5("span", {
1528
+ content = /* @__PURE__ */ jsx10(ComparisonPane, {
1529
+ header: /* @__PURE__ */ jsxs6("span", {
1065
1530
  "data-slot": "image-comparison-showing",
1066
1531
  "aria-live": "polite",
1067
1532
  children: [
@@ -1069,11 +1534,12 @@ ${after.src}`,
1069
1534
  showingLabel
1070
1535
  ]
1071
1536
  }),
1072
- children: /* @__PURE__ */ jsxs5(ImageViewport, {
1537
+ children: /* @__PURE__ */ jsxs6(ImageViewport, {
1073
1538
  label: showingLabel,
1074
1539
  zoom,
1075
1540
  naturalSize: afterImage.size,
1076
1541
  center,
1542
+ onZoomChange: setZoom,
1077
1543
  fallback,
1078
1544
  children: [
1079
1545
  renderAfterImage(isShowingBefore ? "invisible" : undefined),
@@ -1083,7 +1549,7 @@ ${after.src}`,
1083
1549
  })
1084
1550
  });
1085
1551
  }
1086
- return /* @__PURE__ */ jsx8("div", {
1552
+ return /* @__PURE__ */ jsx10("div", {
1087
1553
  role: "group",
1088
1554
  "aria-label": label,
1089
1555
  "data-slot": "image-comparison",
@@ -1094,16 +1560,16 @@ ${after.src}`,
1094
1560
  "data-zoom": zoom,
1095
1561
  "data-showing": isShowingBefore ? "before" : "after",
1096
1562
  className: "@container flex size-full min-h-0 min-w-0 flex-1",
1097
- children: /* @__PURE__ */ jsxs5("div", {
1563
+ children: /* @__PURE__ */ jsxs6("div", {
1098
1564
  className: "flex min-h-0 min-w-0 flex-1 flex-col @3xl:flex-row",
1099
1565
  children: [
1100
- /* @__PURE__ */ jsx8("div", {
1566
+ /* @__PURE__ */ jsx10("div", {
1101
1567
  "data-slot": "image-comparison-stage",
1102
1568
  "data-scroll": "none",
1103
1569
  className: "flex min-h-0 min-w-0 flex-1",
1104
1570
  children: content
1105
1571
  }),
1106
- showToolbar && /* @__PURE__ */ jsx8(ImageComparisonToolbar, {
1572
+ showToolbar && /* @__PURE__ */ jsx10(ImageComparisonToolbar, {
1107
1573
  mode,
1108
1574
  onModeChange: setMode,
1109
1575
  orientation,
@@ -1124,22 +1590,23 @@ ${after.src}`,
1124
1590
  })
1125
1591
  });
1126
1592
  }
1127
- // src/components/image-viewer/getNormalizedImagePoint.ts
1128
- function clampUnit(value) {
1129
- return Math.min(1, Math.max(0, value));
1130
- }
1131
- function getNormalizedImagePoint(point, box) {
1132
- return {
1133
- x: box.width > 0 ? clampUnit((point.clientX - box.left) / box.width) : 0,
1134
- y: box.height > 0 ? clampUnit((point.clientY - box.top) / box.height) : 0
1135
- };
1136
- }
1137
1593
  export {
1594
+ FramedImage2 as FramedImage,
1595
+ IMAGE_ZOOM_STEPS,
1138
1596
  ImageComparison,
1139
1597
  ImageRegionMarker,
1140
1598
  ImageRegionMarkerBadge,
1599
+ ImageRegionSelect,
1141
1600
  ImageViewer,
1601
+ ImageZoomControl,
1142
1602
  ImageZoomToggle,
1603
+ MAX_IMAGE_ZOOM,
1143
1604
  computeImageDiff,
1144
- getNormalizedImagePoint
1605
+ formatImageZoom,
1606
+ getImageZoomScales,
1607
+ getNextImageZoom,
1608
+ getNormalizedImagePoint,
1609
+ getOpeningImageZoom,
1610
+ getPreviousImageZoom,
1611
+ resolveImageZoomScale
1145
1612
  };