@atom63/ui-react 0.2.0-beta.0

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 (92) hide show
  1. package/README.md +121 -0
  2. package/dist/button-sktq-nvV.d.ts +13 -0
  3. package/dist/chunk-7VSPECOH.js +73 -0
  4. package/dist/chunk-7VSPECOH.js.map +1 -0
  5. package/dist/chunk-AJLHJRK6.js +11 -0
  6. package/dist/chunk-AJLHJRK6.js.map +1 -0
  7. package/dist/chunk-MXNO63TC.js +2745 -0
  8. package/dist/chunk-MXNO63TC.js.map +1 -0
  9. package/dist/chunk-STCXERLM.js +354 -0
  10. package/dist/chunk-STCXERLM.js.map +1 -0
  11. package/dist/destination-link-C9NKeKLe.d.ts +34 -0
  12. package/dist/index.d.ts +1605 -0
  13. package/dist/index.js +7337 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/layout/index.d.ts +196 -0
  16. package/dist/layout/index.js +500 -0
  17. package/dist/layout/index.js.map +1 -0
  18. package/dist/media/index.d.ts +208 -0
  19. package/dist/media/index.js +1498 -0
  20. package/dist/media/index.js.map +1 -0
  21. package/dist/media/media-lightbox/parts/index.d.ts +284 -0
  22. package/dist/media/media-lightbox/parts/index.js +5 -0
  23. package/dist/media/media-lightbox/parts/index.js.map +1 -0
  24. package/dist/theme/index.d.ts +350 -0
  25. package/dist/theme/index.js +1173 -0
  26. package/dist/theme/index.js.map +1 -0
  27. package/dist/types-Dxe5IzjE.d.ts +145 -0
  28. package/package.json +188 -0
  29. package/src/components/accordion/accordion.css +196 -0
  30. package/src/components/alert/alert.css +189 -0
  31. package/src/components/alert-dialog/alert-dialog.css +205 -0
  32. package/src/components/autocomplete/autocomplete.css +240 -0
  33. package/src/components/avatar/avatar.css +147 -0
  34. package/src/components/badge/badge.css +223 -0
  35. package/src/components/breadcrumb/breadcrumb.css +99 -0
  36. package/src/components/button/button.css +594 -0
  37. package/src/components/button-group/button-group.css +412 -0
  38. package/src/components/calendar/calendar.css +271 -0
  39. package/src/components/card/card.css +421 -0
  40. package/src/components/carousel/carousel.css +163 -0
  41. package/src/components/checkbox/checkbox.css +113 -0
  42. package/src/components/collapsible/collapsible.css +59 -0
  43. package/src/components/command/command.css +226 -0
  44. package/src/components/connected-panel/connected-panel.css +437 -0
  45. package/src/components/copy-button/copy-button.css +57 -0
  46. package/src/components/dialog/dialog.css +221 -0
  47. package/src/components/drawer/drawer.css +265 -0
  48. package/src/components/empty/empty.css +145 -0
  49. package/src/components/feedback-state/feedback-state.css +141 -0
  50. package/src/components/field/field.css +260 -0
  51. package/src/components/form/form.css +32 -0
  52. package/src/components/frame/frame.css +115 -0
  53. package/src/components/hover-card/hover-card.css +80 -0
  54. package/src/components/input/input.css +291 -0
  55. package/src/components/input-otp/input-otp.css +145 -0
  56. package/src/components/item/item.css +216 -0
  57. package/src/components/kbd/kbd.css +72 -0
  58. package/src/components/label/label.css +37 -0
  59. package/src/components/load-more-trigger/load-more-trigger.css +109 -0
  60. package/src/components/marquee/marquee.css +79 -0
  61. package/src/components/menu/menu.css +216 -0
  62. package/src/components/menubar/menubar.css +67 -0
  63. package/src/components/navigation-menu/navigation-menu.css +275 -0
  64. package/src/components/pagination/pagination.css +86 -0
  65. package/src/components/panel-setting-button/panel-setting-button.css +76 -0
  66. package/src/components/popover/popover.css +89 -0
  67. package/src/components/preview-card/preview-card.css +69 -0
  68. package/src/components/progress/progress.css +70 -0
  69. package/src/components/radio/radio.css +115 -0
  70. package/src/components/resizable/resizable.css +99 -0
  71. package/src/components/scroll-area/scroll-area.css +130 -0
  72. package/src/components/scrollable-list/scrollable-list.css +144 -0
  73. package/src/components/segmented-control/segmented-control.css +235 -0
  74. package/src/components/select/select.css +261 -0
  75. package/src/components/separator/separator.css +43 -0
  76. package/src/components/sheet/sheet.css +209 -0
  77. package/src/components/sidebar/sidebar.css +728 -0
  78. package/src/components/sidebar-nav-tree/sidebar-nav-tree.css +179 -0
  79. package/src/components/skeleton/skeleton.css +42 -0
  80. package/src/components/slider/slider.css +124 -0
  81. package/src/components/switch/switch.css +149 -0
  82. package/src/components/table/table.css +183 -0
  83. package/src/components/tabs/tabs.css +416 -0
  84. package/src/components/text-ticker/text-ticker.css +139 -0
  85. package/src/components/textarea/textarea.css +122 -0
  86. package/src/components/toggle/toggle.css +185 -0
  87. package/src/components/toggle-group/toggle-group.css +102 -0
  88. package/src/components/tooltip/tooltip.css +133 -0
  89. package/src/media/media-lightbox/media-lightbox.css +171 -0
  90. package/src/styles/index.css +3 -0
  91. package/src/styles/recipes.css +70 -0
  92. package/src/styles/reset.css +22 -0
@@ -0,0 +1,2745 @@
1
+ import { usePortalContainer, DestinationLink, DestinationIndicator } from './chunk-7VSPECOH.js';
2
+ import { cn } from './chunk-AJLHJRK6.js';
3
+ import { createContext, useContext, useState, useEffect, useMemo, useRef, useCallback, useLayoutEffect, createElement } from 'react';
4
+ import { flushSync, createPortal } from 'react-dom';
5
+ import { AnimatePresence, motion, usePresence, animate } from 'motion/react';
6
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
+ import { mergeProps } from '@base-ui/react/merge-props';
8
+ import { useRender } from '@base-ui/react/use-render';
9
+ import { Sun, Moon } from 'lucide-react';
10
+
11
+ var LightboxConfigContext = createContext(null);
12
+ var LightboxStateContext = createContext(null);
13
+ var LightboxSlideContext = createContext(null);
14
+ function required(value, part) {
15
+ if (value === null) {
16
+ throw new Error(`${part} must be rendered inside Lightbox.Root.`);
17
+ }
18
+ return value;
19
+ }
20
+ function useLightboxConfig() {
21
+ return required(useContext(LightboxConfigContext), "This lightbox part");
22
+ }
23
+ function useOptionalLightboxConfig() {
24
+ return useContext(LightboxConfigContext);
25
+ }
26
+ function useLightboxState() {
27
+ return required(useContext(LightboxStateContext), "This lightbox part");
28
+ }
29
+ function useLightboxSlide() {
30
+ return useContext(LightboxSlideContext);
31
+ }
32
+ var LightboxRefsContext = createContext(null);
33
+ function useLightboxRefs() {
34
+ const refs = useContext(LightboxRefsContext);
35
+ if (refs === null) {
36
+ throw new Error("This lightbox part must be rendered inside Lightbox.Root.");
37
+ }
38
+ return refs;
39
+ }
40
+ function useReducedMotion() {
41
+ const [prefersReducedMotion, setPrefersReducedMotion] = useState(false);
42
+ useEffect(() => {
43
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
44
+ return;
45
+ }
46
+ const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
47
+ setPrefersReducedMotion(mediaQuery.matches);
48
+ const handleChange = (event) => {
49
+ setPrefersReducedMotion(event.matches);
50
+ };
51
+ mediaQuery.addEventListener("change", handleChange);
52
+ return () => {
53
+ mediaQuery.removeEventListener("change", handleChange);
54
+ };
55
+ }, []);
56
+ return prefersReducedMotion;
57
+ }
58
+
59
+ // src/media/media-lightbox/labels.ts
60
+ var DEFAULT_MEDIA_LIGHTBOX_LABELS = {
61
+ appearance: (title, target) => `Show ${target} version of ${title}`,
62
+ carousel: "carousel",
63
+ close: "Close media viewer",
64
+ gallery: "Media",
65
+ next: "Next media",
66
+ openDestination: (title) => `Open ${title}`,
67
+ position: (index, total) => `${index + 1} of ${total}`,
68
+ previous: "Previous media",
69
+ slide: "slide",
70
+ thumbnails: "Choose media",
71
+ view: (title) => `View ${title}`,
72
+ zoomIn: (title) => `Zoom into ${title}`,
73
+ zoomOut: (title) => `Zoom out of ${title}`
74
+ };
75
+ function resolveLabels(overrides) {
76
+ return overrides ? { ...DEFAULT_MEDIA_LIGHTBOX_LABELS, ...overrides } : DEFAULT_MEDIA_LIGHTBOX_LABELS;
77
+ }
78
+
79
+ // src/media/media-lightbox/motion.ts
80
+ var MEDIA_SPRING = {
81
+ type: "spring",
82
+ stiffness: 520,
83
+ damping: 44,
84
+ mass: 1,
85
+ restDelta: 5e-4
86
+ };
87
+ var PULL_SETTLE_SPRING = {
88
+ type: "spring",
89
+ stiffness: 400,
90
+ damping: 40,
91
+ mass: 1,
92
+ restDelta: 0.01
93
+ };
94
+ var ZOOM_STEP_SPRING = {
95
+ type: "spring",
96
+ stiffness: 700,
97
+ damping: 52,
98
+ mass: 1,
99
+ restDelta: 5e-4
100
+ };
101
+ var MEDIA_FADE = { duration: 0.22, ease: [0.32, 0.72, 0, 1] };
102
+ var BACKDROP_IN = {
103
+ duration: 0.18,
104
+ ease: [0.25, 0.46, 0.45, 0.94]
105
+ };
106
+ var BACKDROP_OUT = {
107
+ delay: 0.14,
108
+ duration: 0.12,
109
+ ease: "linear"
110
+ };
111
+ var CHROME_IN = {
112
+ delay: 0.06,
113
+ duration: 0.16,
114
+ ease: "easeOut"
115
+ };
116
+ var CHROME_OUT = { duration: 0.12, ease: "easeIn" };
117
+ var CHROME_EXIT_OFFSET = 8;
118
+
119
+ // src/media/media-lightbox/timing.ts
120
+ var EMPHASIZED = "var(--a63-motion-ease-emphasized, cubic-bezier(0.32, 0.72, 0, 1))";
121
+ var LIGHTBOX_TIMING = {
122
+ default: { mediaSpring: MEDIA_SPRING, vtDurationMs: 360, vtEasing: EMPHASIZED },
123
+ snappy: {
124
+ mediaSpring: { ...MEDIA_SPRING, damping: 40, stiffness: 640 },
125
+ vtDurationMs: 340,
126
+ vtEasing: EMPHASIZED
127
+ },
128
+ relaxed: {
129
+ mediaSpring: { ...MEDIA_SPRING, damping: 46, stiffness: 420 },
130
+ vtDurationMs: 400,
131
+ vtEasing: EMPHASIZED
132
+ },
133
+ spring: {
134
+ mediaSpring: { ...MEDIA_SPRING, damping: 34, stiffness: 380 },
135
+ vtDurationMs: 450,
136
+ vtEasing: EMPHASIZED
137
+ }
138
+ };
139
+ var DURATION_VAR = "--a63-lightbox-vt-duration";
140
+ var EASING_VAR = "--a63-lightbox-vt-easing";
141
+ function applyTimingVars(element, timing) {
142
+ const spec = LIGHTBOX_TIMING[timing];
143
+ element.style.setProperty(DURATION_VAR, `${spec.vtDurationMs}ms`);
144
+ element.style.setProperty(EASING_VAR, spec.vtEasing);
145
+ }
146
+ function clearTimingVars(element) {
147
+ element.style.removeProperty(DURATION_VAR);
148
+ element.style.removeProperty(EASING_VAR);
149
+ }
150
+
151
+ // src/media/media-lightbox/view-transition.ts
152
+ var MEDIA_VIEW_TRANSITION_NAME = "a63-media-lightbox-media";
153
+ var TRANSITION_CLASS = "a63-media-lightbox-vt";
154
+ var DIRECTION_CLASS = {
155
+ in: "a63-media-lightbox-vt-in",
156
+ out: "a63-media-lightbox-vt-out"
157
+ };
158
+ var MORPH_TARGET_ATTRIBUTE = "data-a63-morph-target";
159
+ var inFlight = false;
160
+ var settleWaiters = [];
161
+ function notifySettled() {
162
+ const waiters = settleWaiters.splice(0, settleWaiters.length);
163
+ for (const waiter of waiters) {
164
+ waiter();
165
+ }
166
+ }
167
+ function whenMediaViewTransitionSettles() {
168
+ if (!inFlight && (typeof document === "undefined" || !document.documentElement.classList.contains(TRANSITION_CLASS))) {
169
+ return Promise.resolve();
170
+ }
171
+ return new Promise((resolve) => {
172
+ settleWaiters.push(resolve);
173
+ });
174
+ }
175
+ var claimedOrigins = /* @__PURE__ */ new Set();
176
+ function supportsViewTransitions() {
177
+ return typeof document !== "undefined" && typeof document.startViewTransition === "function";
178
+ }
179
+ function preferCheapMediaTransition() {
180
+ if (typeof window === "undefined") {
181
+ return false;
182
+ }
183
+ if (typeof window.matchMedia === "function" && (window.matchMedia("(prefers-reduced-motion: reduce)").matches || window.matchMedia("(prefers-reduced-data: reduce)").matches)) {
184
+ return true;
185
+ }
186
+ const nav = navigator;
187
+ if (nav.connection?.saveData) {
188
+ return true;
189
+ }
190
+ const effectiveType = nav.connection?.effectiveType;
191
+ if (effectiveType === "slow-2g" || effectiveType === "2g") {
192
+ return true;
193
+ }
194
+ if (typeof nav.deviceMemory === "number" && nav.deviceMemory <= 4) {
195
+ return true;
196
+ }
197
+ return false;
198
+ }
199
+ function runMediaViewTransition({
200
+ origin,
201
+ direction,
202
+ update,
203
+ timing = "default"
204
+ }) {
205
+ if (!supportsViewTransitions() || inFlight) {
206
+ return false;
207
+ }
208
+ const root = document.documentElement;
209
+ const claim = () => {
210
+ if (origin) {
211
+ origin.style.viewTransitionName = MEDIA_VIEW_TRANSITION_NAME;
212
+ origin.setAttribute(MORPH_TARGET_ATTRIBUTE, "");
213
+ claimedOrigins.add(origin);
214
+ }
215
+ };
216
+ const release = () => {
217
+ for (const marked of claimedOrigins) {
218
+ marked.style.viewTransitionName = "";
219
+ marked.removeAttribute(MORPH_TARGET_ATTRIBUTE);
220
+ }
221
+ claimedOrigins.clear();
222
+ };
223
+ inFlight = true;
224
+ const directionClass = DIRECTION_CLASS[direction];
225
+ root.classList.add(TRANSITION_CLASS, directionClass);
226
+ applyTimingVars(root, timing);
227
+ if (direction === "in") {
228
+ claim();
229
+ }
230
+ const transition = document.startViewTransition(() => {
231
+ if (direction === "in") {
232
+ release();
233
+ flushSync(update);
234
+ return;
235
+ }
236
+ flushSync(update);
237
+ claim();
238
+ });
239
+ const cleanup = () => {
240
+ inFlight = false;
241
+ root.classList.remove(TRANSITION_CLASS, directionClass);
242
+ clearTimingVars(root);
243
+ release();
244
+ notifySettled();
245
+ };
246
+ void transition.finished.then(cleanup, cleanup);
247
+ return true;
248
+ }
249
+ var LightboxThumbnailsPresenceContext = createContext(false);
250
+ var LightboxThumbnailsRegistryContext = createContext(null);
251
+ function LightboxThumbnailsRegistryProvider({ children }) {
252
+ const [present, setPresent] = useState(false);
253
+ return createElement(
254
+ LightboxThumbnailsRegistryContext.Provider,
255
+ { value: setPresent },
256
+ createElement(LightboxThumbnailsPresenceContext.Provider, { value: present }, children)
257
+ );
258
+ }
259
+ function useLightboxThumbnailsPresence() {
260
+ return useContext(LightboxThumbnailsPresenceContext);
261
+ }
262
+ function useLightboxThumbnailsRegistry() {
263
+ const register = useContext(LightboxThumbnailsRegistryContext);
264
+ if (register === null) {
265
+ throw new Error("This lightbox part must be rendered inside Lightbox.Root.");
266
+ }
267
+ return register;
268
+ }
269
+ var IDLE_ZOOM_API = {
270
+ isZoomed: false,
271
+ zoomIn: () => {
272
+ },
273
+ zoomOut: () => {
274
+ }
275
+ };
276
+ var LightboxZoomRegistryContext = createContext(
277
+ null
278
+ );
279
+ function LightboxZoomRegistryProvider({
280
+ children,
281
+ value
282
+ }) {
283
+ return createElement(LightboxZoomRegistryContext.Provider, { value }, children);
284
+ }
285
+ function useLightboxZoomRegistry() {
286
+ const registerZoom = useContext(LightboxZoomRegistryContext);
287
+ if (registerZoom === null) {
288
+ throw new Error("This lightbox part must be rendered inside Lightbox.Root.");
289
+ }
290
+ return registerZoom;
291
+ }
292
+ function LightboxRoot({
293
+ appearance,
294
+ children,
295
+ index,
296
+ items,
297
+ labels: labelOverrides,
298
+ onAppearanceChange,
299
+ onIndexChange,
300
+ onOpenChange,
301
+ open,
302
+ origin,
303
+ preload = 1,
304
+ timing = "default",
305
+ transition = "flip"
306
+ }) {
307
+ const reducedMotion = useReducedMotion();
308
+ const [zoomApi, setZoomApi] = useState(IDLE_ZOOM_API);
309
+ const labels = useMemo(() => resolveLabels(labelOverrides), [labelOverrides]);
310
+ const rootRef = useRef(null);
311
+ const backdropRef = useRef(null);
312
+ const stageRef = useRef(null);
313
+ const trackRef = useRef(null);
314
+ const mediaRef = useRef(null);
315
+ const zoomRef = useRef(null);
316
+ const refs = useMemo(
317
+ () => ({
318
+ backdropRef,
319
+ mediaRef,
320
+ rootRef,
321
+ stageRef,
322
+ trackRef,
323
+ zoomRef
324
+ }),
325
+ []
326
+ );
327
+ const goTo = useCallback(
328
+ (nextIndex) => {
329
+ if (nextIndex < 0 || nextIndex >= items.length) {
330
+ return;
331
+ }
332
+ onIndexChange(nextIndex);
333
+ },
334
+ [items.length, onIndexChange]
335
+ );
336
+ const close = useCallback(() => {
337
+ onOpenChange(false);
338
+ }, [onOpenChange]);
339
+ const config = useMemo(
340
+ () => ({
341
+ appearance,
342
+ items,
343
+ labels,
344
+ onAppearanceChange,
345
+ open,
346
+ origin,
347
+ preload,
348
+ reducedMotion,
349
+ timing,
350
+ transition
351
+ }),
352
+ [
353
+ appearance,
354
+ items,
355
+ labels,
356
+ onAppearanceChange,
357
+ open,
358
+ origin,
359
+ preload,
360
+ reducedMotion,
361
+ timing,
362
+ transition
363
+ ]
364
+ );
365
+ const state = useMemo(
366
+ () => ({
367
+ close,
368
+ goTo,
369
+ index,
370
+ isZoomed: zoomApi.isZoomed,
371
+ itemCount: items.length,
372
+ zoomIn: zoomApi.zoomIn,
373
+ zoomOut: zoomApi.zoomOut
374
+ }),
375
+ [close, goTo, index, items.length, zoomApi]
376
+ );
377
+ return /* @__PURE__ */ jsx(LightboxThumbnailsRegistryProvider, { children: /* @__PURE__ */ jsx(LightboxZoomRegistryProvider, { value: setZoomApi, children: /* @__PURE__ */ jsx(LightboxConfigContext.Provider, { value: config, children: /* @__PURE__ */ jsx(LightboxStateContext.Provider, { value: state, children: /* @__PURE__ */ jsx(LightboxRefsContext.Provider, { value: refs, children }) }) }) }) });
378
+ }
379
+ function LightboxPortal({ children, onExitComplete }) {
380
+ const { open, transition } = useLightboxConfig();
381
+ const portalContainer = usePortalContainer();
382
+ const viewTransition = transition === "view-transition";
383
+ const wasOpenRef = useRef(open);
384
+ useEffect(() => {
385
+ const wasOpen = wasOpenRef.current;
386
+ wasOpenRef.current = open;
387
+ if (!viewTransition || open || !wasOpen) {
388
+ return;
389
+ }
390
+ let cancelled = false;
391
+ void whenMediaViewTransitionSettles().then(() => {
392
+ if (!cancelled) {
393
+ onExitComplete?.();
394
+ }
395
+ });
396
+ return () => {
397
+ cancelled = true;
398
+ };
399
+ }, [onExitComplete, open, viewTransition]);
400
+ if (typeof document === "undefined") {
401
+ return null;
402
+ }
403
+ const content = open ? children : null;
404
+ return createPortal(
405
+ viewTransition ? content : /* @__PURE__ */ jsx(AnimatePresence, { onExitComplete, children: content }),
406
+ portalContainer ?? document.body
407
+ );
408
+ }
409
+
410
+ // src/media/media-lightbox/direction.ts
411
+ function isRtlTrack(track) {
412
+ return getComputedStyle(track).direction === "rtl";
413
+ }
414
+ function arrowIndexDelta(key, rtl) {
415
+ if (key === "ArrowRight") {
416
+ return rtl ? -1 : 1;
417
+ }
418
+ if (key === "ArrowLeft") {
419
+ return rtl ? 1 : -1;
420
+ }
421
+ return void 0;
422
+ }
423
+
424
+ // src/media/media-lightbox/scroll-lock.ts
425
+ var QUIET_MS = 600;
426
+ var MAX_MS = 1500;
427
+ var depth = 0;
428
+ var previousOverflow = null;
429
+ var quietTimer = null;
430
+ var capTimer = null;
431
+ var listening = null;
432
+ function engage() {
433
+ if (previousOverflow === null) {
434
+ previousOverflow = document.body.style.overflow;
435
+ }
436
+ document.body.style.overflow = "hidden";
437
+ }
438
+ function releaseIfIdle() {
439
+ if (depth > 0 || quietTimer !== null || previousOverflow === null) {
440
+ return;
441
+ }
442
+ document.body.style.overflow = previousOverflow;
443
+ previousOverflow = null;
444
+ }
445
+ function lockBodyScroll() {
446
+ if (typeof document === "undefined") {
447
+ return () => {
448
+ };
449
+ }
450
+ depth += 1;
451
+ engage();
452
+ let released = false;
453
+ return () => {
454
+ if (released) {
455
+ return;
456
+ }
457
+ released = true;
458
+ depth = Math.max(depth - 1, 0);
459
+ releaseIfIdle();
460
+ };
461
+ }
462
+ function holdBodyScrollThroughMomentum() {
463
+ if (typeof window === "undefined") {
464
+ return;
465
+ }
466
+ engage();
467
+ const stop = () => {
468
+ if (quietTimer) {
469
+ clearTimeout(quietTimer);
470
+ quietTimer = null;
471
+ }
472
+ if (capTimer) {
473
+ clearTimeout(capTimer);
474
+ capTimer = null;
475
+ }
476
+ if (listening) {
477
+ window.removeEventListener("wheel", listening, { capture: true });
478
+ listening = null;
479
+ }
480
+ releaseIfIdle();
481
+ };
482
+ const extend = () => {
483
+ if (quietTimer) {
484
+ clearTimeout(quietTimer);
485
+ }
486
+ quietTimer = setTimeout(stop, QUIET_MS);
487
+ };
488
+ if (listening) {
489
+ extend();
490
+ return;
491
+ }
492
+ listening = extend;
493
+ window.addEventListener("wheel", listening, { capture: true, passive: true });
494
+ capTimer = setTimeout(stop, MAX_MS);
495
+ extend();
496
+ }
497
+ var MIN_SCALE = 1;
498
+ var FALLBACK_MAX_SCALE = 4;
499
+ var ZOOM_STEP = 2;
500
+ var KEYBOARD_PAN = 50;
501
+ var DOUBLE_TAP_SCALE = 2.5;
502
+ var ZOOM_EPSILON = 0.01;
503
+ var IDENTITY = { scale: 1, x: 0, y: 0 };
504
+ function baselineTransform(scale) {
505
+ return { scale, x: 0, y: 0 };
506
+ }
507
+ function clamp(value, min, max) {
508
+ return Math.min(Math.max(value, min), max);
509
+ }
510
+ function useMediaZoom({
511
+ enabled,
512
+ reducedMotion,
513
+ index,
514
+ zoomRef,
515
+ trackRef,
516
+ minZoom,
517
+ maxZoom,
518
+ zoomStep,
519
+ doubleTapScale,
520
+ keyboardPanDistance,
521
+ wheelSensitivity,
522
+ scrollToZoom = false,
523
+ onZoomChange
524
+ }) {
525
+ const [isZoomed, setIsZoomed] = useState(false);
526
+ const transformRef = useRef(IDENTITY);
527
+ const applyRef = useRef(() => {
528
+ });
529
+ const keyRef = useRef(() => false);
530
+ const zoomInRef = useRef(() => {
531
+ });
532
+ const zoomOutRef = useRef(() => {
533
+ });
534
+ const zoomChangeRef = useRef(onZoomChange);
535
+ zoomChangeRef.current = onZoomChange;
536
+ const handleKey = useCallback((key) => keyRef.current(key), []);
537
+ const zoomIn = useCallback(() => {
538
+ zoomInRef.current();
539
+ }, []);
540
+ const zoomOut = useCallback(() => {
541
+ zoomOutRef.current();
542
+ }, []);
543
+ useEffect(() => {
544
+ const zoom = zoomRef.current;
545
+ const track = trackRef.current;
546
+ if (!enabled || !zoom || !track) {
547
+ return;
548
+ }
549
+ const resolvedMinZoom = minZoom ?? MIN_SCALE;
550
+ const resolvedZoomStep = zoomStep ?? ZOOM_STEP;
551
+ const resolvedDoubleTapScale = doubleTapScale ?? DOUBLE_TAP_SCALE;
552
+ const resolvedKeyboardPanDistance = keyboardPanDistance ?? KEYBOARD_PAN;
553
+ const resolvedWheelSensitivity = wheelSensitivity ?? 100;
554
+ const baseline = baselineTransform(resolvedMinZoom);
555
+ const previousTransform = transformRef.current;
556
+ transformRef.current = baseline;
557
+ let frameW = 0;
558
+ let frameH = 0;
559
+ let naturalW = 0;
560
+ let originX = 0;
561
+ let originY = 0;
562
+ let zoomed = previousTransform.scale > resolvedMinZoom + ZOOM_EPSILON;
563
+ let gestureRaf = 0;
564
+ let wheelMul = 1;
565
+ let wheelX = 0;
566
+ let wheelY = 0;
567
+ let pinchPending = null;
568
+ let stepAnimation = null;
569
+ let drawn = previousTransform;
570
+ const draw = (next) => {
571
+ if (drawn.scale !== next.scale) {
572
+ zoomChangeRef.current?.(next.scale);
573
+ }
574
+ const ceiling = maxScale();
575
+ const progress = ceiling > resolvedMinZoom ? (next.scale - resolvedMinZoom) / (ceiling - resolvedMinZoom) : 0;
576
+ drawn = next;
577
+ zoom.style.transform = `translate3d(${next.x}px, ${next.y}px, 0) scale(${next.scale})`;
578
+ zoom.style.setProperty("--a63-lightbox-zoom-progress", progress.toFixed(3));
579
+ };
580
+ const cacheOrigin = () => {
581
+ const rect = zoom.getBoundingClientRect();
582
+ const current = transformRef.current;
583
+ originX = rect.left + rect.width / 2 - current.x;
584
+ originY = rect.top + rect.height / 2 - current.y;
585
+ };
586
+ const measure = () => {
587
+ frameW = zoom.offsetWidth;
588
+ frameH = zoom.offsetHeight;
589
+ const img2 = zoom.querySelector('[data-slot="media-lightbox-image"]');
590
+ if (img2 && img2.naturalWidth > 0) {
591
+ naturalW = img2.naturalWidth;
592
+ }
593
+ cacheOrigin();
594
+ };
595
+ measure();
596
+ const maxScale = () => {
597
+ if (typeof maxZoom === "number") {
598
+ return maxZoom;
599
+ }
600
+ if (naturalW > 0 && frameW > 0) {
601
+ return Math.max(naturalW / frameW, resolvedMinZoom + 0.5);
602
+ }
603
+ return FALLBACK_MAX_SCALE;
604
+ };
605
+ const limit = (next) => {
606
+ const overflowX = frameW * (next.scale - 1) / 2;
607
+ const overflowY = frameH * (next.scale - 1) / 2;
608
+ return {
609
+ scale: next.scale,
610
+ x: clamp(next.x, -overflowX, overflowX),
611
+ y: clamp(next.y, -overflowY, overflowY)
612
+ };
613
+ };
614
+ const paint = (next) => {
615
+ transformRef.current = next;
616
+ draw(next);
617
+ };
618
+ const syncChrome = (zoomedNow) => {
619
+ if (zoomedNow === zoomed) {
620
+ return;
621
+ }
622
+ zoomed = zoomedNow;
623
+ setIsZoomed(zoomedNow);
624
+ zoom.style.cursor = zoomedNow ? "grab" : "";
625
+ zoom.style.willChange = zoomedNow ? "transform" : "";
626
+ track.style.overflowX = zoomedNow ? "hidden" : "";
627
+ track.style.touchAction = zoomedNow ? "none" : "";
628
+ };
629
+ const apply = (next, animated = false) => {
630
+ const bounded = limit({ ...next, scale: clamp(next.scale, resolvedMinZoom, maxScale()) });
631
+ syncChrome(bounded.scale > resolvedMinZoom + ZOOM_EPSILON);
632
+ stepAnimation?.stop();
633
+ stepAnimation = null;
634
+ if (!animated || reducedMotion) {
635
+ paint(bounded);
636
+ return;
637
+ }
638
+ const from = drawn;
639
+ transformRef.current = bounded;
640
+ stepAnimation = animate(0, 1, {
641
+ ...ZOOM_STEP_SPRING,
642
+ onComplete: () => {
643
+ stepAnimation = null;
644
+ draw(bounded);
645
+ },
646
+ onUpdate: (progress) => {
647
+ draw({
648
+ scale: from.scale + (bounded.scale - from.scale) * progress,
649
+ x: from.x + (bounded.x - from.x) * progress,
650
+ y: from.y + (bounded.y - from.y) * progress
651
+ });
652
+ }
653
+ });
654
+ };
655
+ applyRef.current = apply;
656
+ apply(baseline);
657
+ const visualCentre = () => {
658
+ const current = transformRef.current;
659
+ return { x: originX + current.x, y: originY + current.y };
660
+ };
661
+ const scaleAt = (nextScale, clientX, clientY, animated = false) => {
662
+ const current = transformRef.current;
663
+ const target = clamp(nextScale, resolvedMinZoom, maxScale());
664
+ if (target === current.scale) {
665
+ return;
666
+ }
667
+ const centre = visualCentre();
668
+ const unitX = (clientX - centre.x) / current.scale;
669
+ const unitY = (clientY - centre.y) / current.scale;
670
+ apply(
671
+ {
672
+ scale: target,
673
+ x: current.x + unitX * (current.scale - target),
674
+ y: current.y + unitY * (current.scale - target)
675
+ },
676
+ animated
677
+ );
678
+ };
679
+ const flushGesture = () => {
680
+ gestureRaf = 0;
681
+ if (pinchPending) {
682
+ const pending = pinchPending;
683
+ pinchPending = null;
684
+ wheelMul = 1;
685
+ scaleAt(pending.scale, pending.x, pending.y);
686
+ return;
687
+ }
688
+ if (wheelMul === 1) {
689
+ return;
690
+ }
691
+ const mul = wheelMul;
692
+ wheelMul = 1;
693
+ scaleAt(transformRef.current.scale * mul, wheelX, wheelY);
694
+ };
695
+ const scheduleGesture = () => {
696
+ if (!gestureRaf) {
697
+ gestureRaf = requestAnimationFrame(flushGesture);
698
+ }
699
+ };
700
+ zoomInRef.current = () => {
701
+ const current = transformRef.current;
702
+ const c = visualCentre();
703
+ scaleAt(current.scale * resolvedZoomStep, c.x, c.y, true);
704
+ };
705
+ zoomOutRef.current = () => {
706
+ const current = transformRef.current;
707
+ if (current.scale <= resolvedMinZoom + ZOOM_EPSILON) {
708
+ return;
709
+ }
710
+ const c = visualCentre();
711
+ scaleAt(current.scale / resolvedZoomStep, c.x, c.y, true);
712
+ };
713
+ const handleWheel = (event) => {
714
+ if (!event.ctrlKey && !scrollToZoom) {
715
+ return;
716
+ }
717
+ event.preventDefault();
718
+ pinchPending = null;
719
+ wheelMul *= Math.exp(-event.deltaY / resolvedWheelSensitivity);
720
+ wheelX = event.clientX;
721
+ wheelY = event.clientY;
722
+ scheduleGesture();
723
+ };
724
+ const handleDoubleClick = (event) => {
725
+ event.preventDefault();
726
+ if (transformRef.current.scale > resolvedMinZoom + ZOOM_EPSILON) {
727
+ apply(baseline, true);
728
+ return;
729
+ }
730
+ const current = transformRef.current;
731
+ const centre = visualCentre();
732
+ const unitX = (event.clientX - centre.x) / current.scale;
733
+ const unitY = (event.clientY - centre.y) / current.scale;
734
+ apply(
735
+ {
736
+ scale: resolvedDoubleTapScale,
737
+ x: current.x + unitX * (current.scale - resolvedDoubleTapScale),
738
+ y: current.y + unitY * (current.scale - resolvedDoubleTapScale)
739
+ },
740
+ true
741
+ );
742
+ };
743
+ const points = /* @__PURE__ */ new Map();
744
+ let pinchDistance = 0;
745
+ let pinchScale = 1;
746
+ let panning = false;
747
+ let panX = 0;
748
+ let panY = 0;
749
+ const centreOf = () => {
750
+ const all = [...points.values()];
751
+ const sum = all.reduce((acc, p) => ({ x: acc.x + p.x, y: acc.y + p.y }), { x: 0, y: 0 });
752
+ return { x: sum.x / all.length, y: sum.y / all.length };
753
+ };
754
+ const spread = () => {
755
+ const [a, b] = [...points.values()];
756
+ if (!a || !b) {
757
+ return 0;
758
+ }
759
+ return Math.hypot(a.x - b.x, a.y - b.y);
760
+ };
761
+ const handlePointerDown = (event) => {
762
+ const zoomedNow = transformRef.current.scale > resolvedMinZoom + ZOOM_EPSILON;
763
+ if (event.pointerType === "mouse" && !zoomedNow) {
764
+ return;
765
+ }
766
+ if (event.target?.closest("[data-a63-no-drag]")) {
767
+ return;
768
+ }
769
+ points.set(event.pointerId, { x: event.clientX, y: event.clientY });
770
+ if (points.size === 2) {
771
+ pinchDistance = spread();
772
+ pinchScale = transformRef.current.scale;
773
+ panning = false;
774
+ return;
775
+ }
776
+ if (points.size === 1 && zoomedNow) {
777
+ panning = true;
778
+ panX = event.clientX;
779
+ panY = event.clientY;
780
+ }
781
+ };
782
+ const handlePointerMove = (event) => {
783
+ if (!points.has(event.pointerId)) {
784
+ return;
785
+ }
786
+ points.set(event.pointerId, { x: event.clientX, y: event.clientY });
787
+ if (points.size >= 2) {
788
+ const distance = spread();
789
+ if (pinchDistance > 0 && distance > 0) {
790
+ const centre = centreOf();
791
+ pinchPending = {
792
+ scale: pinchScale * distance / pinchDistance,
793
+ x: centre.x,
794
+ y: centre.y
795
+ };
796
+ wheelMul = 1;
797
+ scheduleGesture();
798
+ }
799
+ return;
800
+ }
801
+ if (!panning) {
802
+ return;
803
+ }
804
+ const current = transformRef.current;
805
+ apply({
806
+ scale: current.scale,
807
+ x: current.x + event.clientX - panX,
808
+ y: current.y + event.clientY - panY
809
+ });
810
+ panX = event.clientX;
811
+ panY = event.clientY;
812
+ };
813
+ const endPointer = (event) => {
814
+ points.delete(event.pointerId);
815
+ if (points.size < 2) {
816
+ pinchDistance = 0;
817
+ }
818
+ if (points.size === 0) {
819
+ panning = false;
820
+ }
821
+ };
822
+ keyRef.current = (key) => {
823
+ const current = transformRef.current;
824
+ const zoomedNow = current.scale > resolvedMinZoom + ZOOM_EPSILON;
825
+ const centre = visualCentre();
826
+ if (key === "+" || key === "=") {
827
+ scaleAt(current.scale * resolvedZoomStep, centre.x, centre.y, true);
828
+ return true;
829
+ }
830
+ if (key === "-" || key === "_") {
831
+ scaleAt(current.scale / resolvedZoomStep, centre.x, centre.y, true);
832
+ return true;
833
+ }
834
+ if (key === "0") {
835
+ apply(baseline, true);
836
+ return true;
837
+ }
838
+ if (!zoomedNow) {
839
+ return false;
840
+ }
841
+ const pan = {
842
+ ArrowDown: [0, -resolvedKeyboardPanDistance],
843
+ ArrowLeft: [resolvedKeyboardPanDistance, 0],
844
+ ArrowRight: [-resolvedKeyboardPanDistance, 0],
845
+ ArrowUp: [0, resolvedKeyboardPanDistance]
846
+ };
847
+ const delta = pan[key];
848
+ if (!delta) {
849
+ return false;
850
+ }
851
+ apply({ scale: current.scale, x: current.x + delta[0], y: current.y + delta[1] });
852
+ return true;
853
+ };
854
+ const handleResize = () => {
855
+ measure();
856
+ apply(transformRef.current);
857
+ };
858
+ const handleImageLoad = () => {
859
+ measure();
860
+ apply(transformRef.current);
861
+ };
862
+ const img = zoom.querySelector('[data-slot="media-lightbox-image"]');
863
+ img?.addEventListener("load", handleImageLoad);
864
+ window.addEventListener("resize", handleResize);
865
+ track.addEventListener("wheel", handleWheel, { passive: false });
866
+ track.addEventListener("dblclick", handleDoubleClick);
867
+ track.addEventListener("pointerdown", handlePointerDown, { passive: true });
868
+ window.addEventListener("pointermove", handlePointerMove, { passive: true });
869
+ window.addEventListener("pointerup", endPointer, { passive: true });
870
+ window.addEventListener("pointercancel", endPointer, { passive: true });
871
+ return () => {
872
+ applyRef.current = () => {
873
+ };
874
+ keyRef.current = () => false;
875
+ zoomInRef.current = () => {
876
+ };
877
+ zoomOutRef.current = () => {
878
+ };
879
+ if (gestureRaf) {
880
+ cancelAnimationFrame(gestureRaf);
881
+ }
882
+ stepAnimation?.stop();
883
+ stepAnimation = null;
884
+ window.removeEventListener("resize", handleResize);
885
+ img?.removeEventListener("load", handleImageLoad);
886
+ track.removeEventListener("wheel", handleWheel);
887
+ track.removeEventListener("dblclick", handleDoubleClick);
888
+ track.removeEventListener("pointerdown", handlePointerDown);
889
+ window.removeEventListener("pointermove", handlePointerMove);
890
+ window.removeEventListener("pointerup", endPointer);
891
+ window.removeEventListener("pointercancel", endPointer);
892
+ track.style.overflowX = "";
893
+ track.style.touchAction = "";
894
+ zoom.style.transform = "";
895
+ zoom.style.cursor = "";
896
+ zoom.style.transition = "";
897
+ zoom.style.willChange = "";
898
+ zoom.style.removeProperty("--a63-lightbox-zoom-progress");
899
+ };
900
+ }, [
901
+ enabled,
902
+ index,
903
+ reducedMotion,
904
+ minZoom,
905
+ maxZoom,
906
+ zoomStep,
907
+ doubleTapScale,
908
+ keyboardPanDistance,
909
+ wheelSensitivity,
910
+ scrollToZoom,
911
+ trackRef,
912
+ zoomRef
913
+ ]);
914
+ return { handleKey, isZoomed, zoomIn, zoomOut };
915
+ }
916
+
917
+ // src/media/media-lightbox/velocity.ts
918
+ var DEFAULT_WINDOW_MS = 100;
919
+ var MIN_SPAN_MS = 8;
920
+ function createVelocityTracker(windowMs = DEFAULT_WINDOW_MS) {
921
+ let samples = [];
922
+ const push = (value, time) => {
923
+ samples.push({ time, value });
924
+ const cutoff = time - windowMs * 2;
925
+ const keepFrom = samples.findIndex((sample) => sample.time >= cutoff);
926
+ if (keepFrom > 1) {
927
+ samples = samples.slice(keepFrom - 1);
928
+ }
929
+ };
930
+ return {
931
+ push,
932
+ reset: (value, time) => {
933
+ samples = [{ time, value }];
934
+ },
935
+ velocity: () => {
936
+ const last = samples.at(-1);
937
+ if (!last) {
938
+ return 0;
939
+ }
940
+ const first = samples.find((sample) => last.time - sample.time <= windowMs) ?? samples.at(-2) ?? last;
941
+ const span = first === last ? samples.at(-2) ?? last : first;
942
+ const elapsed = last.time - span.time;
943
+ if (elapsed < MIN_SPAN_MS) {
944
+ return 0;
945
+ }
946
+ return (last.value - span.value) / elapsed;
947
+ }
948
+ };
949
+ }
950
+
951
+ // src/media/media-lightbox/wheel-momentum.ts
952
+ var MIN_DECAYING_SAMPLES = 3;
953
+ var MAX_GAP_MS = 50;
954
+ var PEAK_RATIO = 0.85;
955
+ var MOMENTUM_QUIET_MS = 120;
956
+ var MOMENTUM_MAX_MS = 1200;
957
+ function swallowWheelMomentum() {
958
+ if (typeof window === "undefined") {
959
+ return;
960
+ }
961
+ let quiet = null;
962
+ const stop = () => {
963
+ if (quiet) {
964
+ clearTimeout(quiet);
965
+ quiet = null;
966
+ }
967
+ clearTimeout(cap);
968
+ window.removeEventListener("wheel", onWheel, { capture: true });
969
+ };
970
+ const onWheel = (event) => {
971
+ if (event.cancelable) {
972
+ event.preventDefault();
973
+ }
974
+ if (quiet) {
975
+ clearTimeout(quiet);
976
+ }
977
+ quiet = setTimeout(stop, MOMENTUM_QUIET_MS);
978
+ };
979
+ const cap = setTimeout(stop, MOMENTUM_MAX_MS);
980
+ window.addEventListener("wheel", onWheel, { capture: true, passive: false });
981
+ quiet = setTimeout(stop, MOMENTUM_QUIET_MS);
982
+ }
983
+ function createWheelMomentum() {
984
+ let peak = 0;
985
+ let previous = 0;
986
+ let previousTime = 0;
987
+ let decaying = 0;
988
+ let started = false;
989
+ const reset = () => {
990
+ peak = 0;
991
+ previous = 0;
992
+ previousTime = 0;
993
+ decaying = 0;
994
+ started = false;
995
+ };
996
+ return {
997
+ push: (delta, time) => {
998
+ const magnitude = Math.abs(delta);
999
+ const gap = started ? time - previousTime : 0;
1000
+ const rapid = started && gap >= 0 && gap <= MAX_GAP_MS;
1001
+ if (started && !rapid) {
1002
+ peak = magnitude;
1003
+ decaying = 0;
1004
+ } else if (magnitude < previous && magnitude < peak * PEAK_RATIO) {
1005
+ decaying += 1;
1006
+ } else {
1007
+ decaying = 0;
1008
+ }
1009
+ peak = Math.max(peak, magnitude);
1010
+ previous = magnitude;
1011
+ previousTime = time;
1012
+ started = true;
1013
+ return decaying >= MIN_DECAYING_SAMPLES;
1014
+ },
1015
+ reset
1016
+ };
1017
+ }
1018
+
1019
+ // src/media/media-lightbox/use-pull-to-dismiss.ts
1020
+ var DISMISS_DISTANCE_CAP = 120;
1021
+ var DISMISS_DISTANCE_RATIO = 0.14;
1022
+ var DISMISS_VELOCITY = 0.6;
1023
+ var WHEEL_SETTLE_MS = 140;
1024
+ var DISMISSED_UNWIND_MS = 900;
1025
+ var MAX_SCALE_DROP = 0.2;
1026
+ var BACKDROP_FLOOR = 0.35;
1027
+ function dismissDistance() {
1028
+ if (typeof window === "undefined") {
1029
+ return DISMISS_DISTANCE_CAP;
1030
+ }
1031
+ return Math.min(DISMISS_DISTANCE_CAP, window.innerHeight * DISMISS_DISTANCE_RATIO);
1032
+ }
1033
+ function usePullToDismiss({
1034
+ enabled,
1035
+ reducedMotion,
1036
+ onDismiss,
1037
+ stageRef,
1038
+ backdropRef,
1039
+ trackRef,
1040
+ rootRef
1041
+ }) {
1042
+ useEffect(() => {
1043
+ const stage = stageRef.current;
1044
+ const backdrop = backdropRef.current;
1045
+ const track = trackRef.current;
1046
+ const root = rootRef.current;
1047
+ if (!enabled || !stage || !track) {
1048
+ return;
1049
+ }
1050
+ let offset = 0;
1051
+ let startX = 0;
1052
+ let startY = 0;
1053
+ let pointerId = null;
1054
+ let threshold = dismissDistance();
1055
+ const velocity = createVelocityTracker();
1056
+ let claimed = null;
1057
+ let wheelTimer = null;
1058
+ let wheelLastTime = 0;
1059
+ let wheelOpen = false;
1060
+ let wheelSpent = false;
1061
+ const wheelMomentum = createWheelMomentum();
1062
+ let suppressNextClick = false;
1063
+ let suppressTimer = null;
1064
+ let unwindTimer = null;
1065
+ const paint = (value) => {
1066
+ stage.style.willChange = "transform";
1067
+ offset = value;
1068
+ const progress = Math.min(Math.abs(value) / threshold, 1);
1069
+ if (root) {
1070
+ root.dataset.pulling = value === 0 ? "false" : "true";
1071
+ root.style.setProperty("--a63-media-lightbox-pull", String(progress));
1072
+ root.style.setProperty("--a63-lightbox-pull-progress", String(progress));
1073
+ }
1074
+ const fade = Math.min(Math.abs(value) / (threshold * 3), 1);
1075
+ const scale = reducedMotion ? 1 : 1 - fade * MAX_SCALE_DROP;
1076
+ stage.style.transform = `translate3d(0, ${value}px, 0) scale(${scale})`;
1077
+ if (backdrop) {
1078
+ backdrop.style.opacity = String(1 - fade * (1 - BACKDROP_FLOOR));
1079
+ }
1080
+ };
1081
+ const reset = () => {
1082
+ stage.style.transform = "";
1083
+ stage.style.transformOrigin = "";
1084
+ stage.style.willChange = "";
1085
+ if (backdrop) {
1086
+ backdrop.style.opacity = "";
1087
+ }
1088
+ if (root) {
1089
+ root.dataset.pulling = "false";
1090
+ root.style.removeProperty("--a63-media-lightbox-pull");
1091
+ root.style.removeProperty("--a63-lightbox-pull-progress");
1092
+ }
1093
+ offset = 0;
1094
+ };
1095
+ const settle = (velocityPxPerMs) => {
1096
+ const shouldDismiss = Math.abs(offset) > threshold || Math.abs(velocityPxPerMs) > DISMISS_VELOCITY;
1097
+ if (shouldDismiss) {
1098
+ onDismiss();
1099
+ unwindTimer = setTimeout(() => {
1100
+ unwindTimer = null;
1101
+ if (stage.isConnected) {
1102
+ const from2 = offset;
1103
+ if (reducedMotion) {
1104
+ paint(0);
1105
+ reset();
1106
+ return;
1107
+ }
1108
+ void animate(from2, 0, {
1109
+ ...PULL_SETTLE_SPRING,
1110
+ onComplete: reset,
1111
+ onUpdate: paint,
1112
+ velocity: velocityPxPerMs * 1e3
1113
+ });
1114
+ }
1115
+ }, DISMISSED_UNWIND_MS);
1116
+ return true;
1117
+ }
1118
+ if (offset === 0) {
1119
+ return false;
1120
+ }
1121
+ if (reducedMotion) {
1122
+ paint(0);
1123
+ reset();
1124
+ return false;
1125
+ }
1126
+ const from = offset;
1127
+ void animate(from, 0, {
1128
+ ...PULL_SETTLE_SPRING,
1129
+ onComplete: reset,
1130
+ onUpdate: paint,
1131
+ // Hand the spring the speed the finger let go at, so the rubber-band
1132
+ // continues the gesture instead of restarting from stationary.
1133
+ velocity: velocityPxPerMs * 1e3
1134
+ });
1135
+ return false;
1136
+ };
1137
+ const handlePointerDown = (event) => {
1138
+ if (event.button !== 0 || pointerId !== null) {
1139
+ return;
1140
+ }
1141
+ if (event.target?.closest(
1142
+ '[data-a63-no-drag], video, a, button:not([tabindex="-1"])'
1143
+ )) {
1144
+ return;
1145
+ }
1146
+ pointerId = event.pointerId;
1147
+ claimed = null;
1148
+ startX = event.clientX;
1149
+ startY = event.clientY;
1150
+ threshold = dismissDistance();
1151
+ velocity.reset(0, event.timeStamp);
1152
+ stage.style.transformOrigin = "center";
1153
+ };
1154
+ const handlePointerMove = (event) => {
1155
+ if (event.pointerId !== pointerId) {
1156
+ return;
1157
+ }
1158
+ const dx = event.clientX - startX;
1159
+ const dy = event.clientY - startY;
1160
+ if (claimed === null) {
1161
+ if (Math.abs(dx) < 8 && Math.abs(dy) < 8) {
1162
+ return;
1163
+ }
1164
+ claimed = Math.abs(dy) > Math.abs(dx);
1165
+ if (claimed) {
1166
+ track.style.userSelect = "none";
1167
+ track.style.cursor = "grabbing";
1168
+ }
1169
+ }
1170
+ if (!claimed) {
1171
+ return;
1172
+ }
1173
+ if (event.cancelable) {
1174
+ event.preventDefault();
1175
+ }
1176
+ velocity.push(dy, event.timeStamp);
1177
+ paint(dy);
1178
+ };
1179
+ const endPointer = (event) => {
1180
+ if (event.pointerId !== pointerId) {
1181
+ return;
1182
+ }
1183
+ pointerId = null;
1184
+ track.style.userSelect = "";
1185
+ track.style.cursor = "";
1186
+ if (claimed) {
1187
+ velocity.push(offset, event.timeStamp);
1188
+ suppressNextClick = true;
1189
+ if (suppressTimer) {
1190
+ clearTimeout(suppressTimer);
1191
+ }
1192
+ suppressTimer = setTimeout(() => {
1193
+ suppressNextClick = false;
1194
+ }, 0);
1195
+ settle(velocity.velocity());
1196
+ }
1197
+ claimed = null;
1198
+ };
1199
+ const handleClickCapture = (event) => {
1200
+ if (!suppressNextClick) {
1201
+ return;
1202
+ }
1203
+ suppressNextClick = false;
1204
+ event.stopPropagation();
1205
+ event.preventDefault();
1206
+ };
1207
+ const endWheelGesture = (velocityPxPerMs) => {
1208
+ if (wheelTimer) {
1209
+ clearTimeout(wheelTimer);
1210
+ wheelTimer = null;
1211
+ }
1212
+ wheelSpent = true;
1213
+ if (settle(velocityPxPerMs)) {
1214
+ holdBodyScrollThroughMomentum();
1215
+ swallowWheelMomentum();
1216
+ }
1217
+ };
1218
+ const handleWheel = (event) => {
1219
+ if (Math.abs(event.deltaX) >= Math.abs(event.deltaY)) {
1220
+ return;
1221
+ }
1222
+ if (event.cancelable) {
1223
+ event.preventDefault();
1224
+ }
1225
+ const idle = !wheelOpen || event.timeStamp - wheelLastTime > WHEEL_SETTLE_MS;
1226
+ wheelLastTime = event.timeStamp;
1227
+ if (idle) {
1228
+ wheelOpen = true;
1229
+ wheelSpent = false;
1230
+ threshold = dismissDistance();
1231
+ velocity.reset(offset, event.timeStamp);
1232
+ wheelMomentum.reset();
1233
+ }
1234
+ const coasting = wheelMomentum.push(event.deltaY, event.timeStamp);
1235
+ if (wheelSpent) {
1236
+ return;
1237
+ }
1238
+ if (coasting) {
1239
+ endWheelGesture(velocity.velocity());
1240
+ return;
1241
+ }
1242
+ stage.style.transformOrigin = "center";
1243
+ const next = offset - event.deltaY;
1244
+ velocity.push(next, event.timeStamp);
1245
+ paint(next);
1246
+ if (Math.abs(next) > threshold) {
1247
+ endWheelGesture(velocity.velocity());
1248
+ return;
1249
+ }
1250
+ if (wheelTimer) {
1251
+ clearTimeout(wheelTimer);
1252
+ }
1253
+ wheelTimer = setTimeout(() => {
1254
+ wheelTimer = null;
1255
+ wheelOpen = false;
1256
+ settle(0);
1257
+ }, WHEEL_SETTLE_MS);
1258
+ };
1259
+ track.addEventListener("pointerdown", handlePointerDown, { passive: true });
1260
+ window.addEventListener("pointermove", handlePointerMove, { passive: false });
1261
+ window.addEventListener("pointerup", endPointer, { passive: true });
1262
+ window.addEventListener("pointercancel", endPointer, { passive: true });
1263
+ track.addEventListener("click", handleClickCapture, { capture: true });
1264
+ track.addEventListener("wheel", handleWheel, { passive: false });
1265
+ return () => {
1266
+ if (wheelTimer) {
1267
+ clearTimeout(wheelTimer);
1268
+ }
1269
+ if (suppressTimer) {
1270
+ clearTimeout(suppressTimer);
1271
+ }
1272
+ if (unwindTimer) {
1273
+ clearTimeout(unwindTimer);
1274
+ }
1275
+ track.removeEventListener("pointerdown", handlePointerDown);
1276
+ window.removeEventListener("pointermove", handlePointerMove);
1277
+ window.removeEventListener("pointerup", endPointer);
1278
+ window.removeEventListener("pointercancel", endPointer);
1279
+ track.removeEventListener("click", handleClickCapture, { capture: true });
1280
+ track.removeEventListener("wheel", handleWheel);
1281
+ reset();
1282
+ };
1283
+ }, [backdropRef, enabled, onDismiss, reducedMotion, rootRef, stageRef, trackRef]);
1284
+ }
1285
+ var AXIS_LOCK_THRESHOLD = 8;
1286
+ var SWIPE_DISTANCE_RATIO = 0.2;
1287
+ var SWIPE_DISTANCE_CAP = 120;
1288
+ var SWIPE_VELOCITY = 0.5;
1289
+ var NO_SWIPE_SELECTOR = '[data-a63-no-drag], video, a, button:not([tabindex="-1"])';
1290
+ var WHEEL_DISTANCE_THRESHOLD = 60;
1291
+ var WHEEL_QUIET_MS = 160;
1292
+ var WHEEL_DECAY_RATIO = 0.4;
1293
+ var WHEEL_RISE_MARGIN = 12;
1294
+ function useSwipeIntent({ enabled, onIntent, rootRef, stageRef }) {
1295
+ const intentRef = useRef(onIntent);
1296
+ intentRef.current = onIntent;
1297
+ useEffect(() => {
1298
+ const root = rootRef.current;
1299
+ const stage = stageRef.current;
1300
+ if (!enabled || !root || !stage) {
1301
+ return;
1302
+ }
1303
+ let pointerId = null;
1304
+ let startX = 0;
1305
+ let startY = 0;
1306
+ const velocity = createVelocityTracker();
1307
+ let axis = null;
1308
+ let suppressNextClick = false;
1309
+ let suppressTimer = null;
1310
+ const handlePointerDown = (event) => {
1311
+ if (event.button !== 0 || pointerId !== null) {
1312
+ return;
1313
+ }
1314
+ if (event.target?.closest(NO_SWIPE_SELECTOR)) {
1315
+ return;
1316
+ }
1317
+ pointerId = event.pointerId;
1318
+ startX = event.clientX;
1319
+ startY = event.clientY;
1320
+ axis = null;
1321
+ velocity.reset(event.clientX, event.timeStamp);
1322
+ };
1323
+ const handlePointerMove = (event) => {
1324
+ if (event.pointerId !== pointerId) {
1325
+ return;
1326
+ }
1327
+ const dx = event.clientX - startX;
1328
+ const dy = event.clientY - startY;
1329
+ if (axis === null) {
1330
+ if (Math.abs(dx) < AXIS_LOCK_THRESHOLD && Math.abs(dy) < AXIS_LOCK_THRESHOLD) {
1331
+ return;
1332
+ }
1333
+ axis = Math.abs(dx) > Math.abs(dy) ? "horizontal" : "vertical";
1334
+ if (axis === "vertical") {
1335
+ pointerId = null;
1336
+ return;
1337
+ }
1338
+ }
1339
+ velocity.push(event.clientX, event.timeStamp);
1340
+ };
1341
+ const endGesture = (event, report) => {
1342
+ if (event.pointerId !== pointerId) {
1343
+ return;
1344
+ }
1345
+ const dx = event.clientX - startX;
1346
+ const wasHorizontal = axis === "horizontal";
1347
+ pointerId = null;
1348
+ axis = null;
1349
+ if (wasHorizontal) {
1350
+ suppressNextClick = true;
1351
+ if (suppressTimer) {
1352
+ clearTimeout(suppressTimer);
1353
+ }
1354
+ suppressTimer = setTimeout(() => {
1355
+ suppressNextClick = false;
1356
+ }, 0);
1357
+ }
1358
+ if (!report || !wasHorizontal) {
1359
+ return;
1360
+ }
1361
+ velocity.push(event.clientX, event.timeStamp);
1362
+ const speed = velocity.velocity();
1363
+ const distanceThreshold = Math.min(
1364
+ SWIPE_DISTANCE_CAP,
1365
+ (window.innerWidth || SWIPE_DISTANCE_CAP) * SWIPE_DISTANCE_RATIO
1366
+ );
1367
+ const passedDistance = Math.abs(dx) > distanceThreshold;
1368
+ const passedVelocity = Math.abs(speed) > SWIPE_VELOCITY;
1369
+ if (!passedDistance && !passedVelocity) {
1370
+ return;
1371
+ }
1372
+ const rtl = isRtlTrack(stage);
1373
+ const key = dx < 0 ? "ArrowRight" : "ArrowLeft";
1374
+ const delta = arrowIndexDelta(key, rtl);
1375
+ if (delta !== 1 && delta !== -1) {
1376
+ return;
1377
+ }
1378
+ intentRef.current(delta);
1379
+ };
1380
+ const handlePointerUp = (event) => {
1381
+ endGesture(event, true);
1382
+ };
1383
+ const handlePointerCancel = (event) => {
1384
+ endGesture(event, false);
1385
+ };
1386
+ let wheelAccumulated = 0;
1387
+ let wheelLocked = false;
1388
+ let wheelCoasting = false;
1389
+ let wheelPeak = 0;
1390
+ let wheelFloor = Number.POSITIVE_INFINITY;
1391
+ let wheelQuietTimer = null;
1392
+ const resetWheelGesture = () => {
1393
+ wheelLocked = false;
1394
+ wheelCoasting = false;
1395
+ wheelAccumulated = 0;
1396
+ wheelPeak = 0;
1397
+ wheelFloor = Number.POSITIVE_INFINITY;
1398
+ };
1399
+ const armWheelQuietTimer = () => {
1400
+ if (wheelQuietTimer) {
1401
+ clearTimeout(wheelQuietTimer);
1402
+ }
1403
+ wheelQuietTimer = setTimeout(() => {
1404
+ wheelQuietTimer = null;
1405
+ resetWheelGesture();
1406
+ }, WHEEL_QUIET_MS);
1407
+ };
1408
+ const handleWheel = (event) => {
1409
+ if (Math.abs(event.deltaX) <= Math.abs(event.deltaY)) {
1410
+ return;
1411
+ }
1412
+ if (event.cancelable) {
1413
+ event.preventDefault();
1414
+ }
1415
+ armWheelQuietTimer();
1416
+ const magnitude = Math.abs(event.deltaX);
1417
+ if (wheelLocked) {
1418
+ if (!wheelCoasting) {
1419
+ if (magnitude > wheelPeak) {
1420
+ wheelPeak = magnitude;
1421
+ return;
1422
+ }
1423
+ if (magnitude >= wheelPeak * WHEEL_DECAY_RATIO) {
1424
+ return;
1425
+ }
1426
+ wheelCoasting = true;
1427
+ wheelFloor = magnitude;
1428
+ return;
1429
+ }
1430
+ if (magnitude < wheelFloor) {
1431
+ wheelFloor = magnitude;
1432
+ return;
1433
+ }
1434
+ if (magnitude - wheelFloor <= WHEEL_RISE_MARGIN) {
1435
+ return;
1436
+ }
1437
+ resetWheelGesture();
1438
+ }
1439
+ wheelAccumulated += event.deltaX;
1440
+ if (Math.abs(wheelAccumulated) <= WHEEL_DISTANCE_THRESHOLD) {
1441
+ return;
1442
+ }
1443
+ wheelLocked = true;
1444
+ wheelCoasting = false;
1445
+ wheelPeak = magnitude;
1446
+ wheelFloor = Number.POSITIVE_INFINITY;
1447
+ const dx = wheelAccumulated;
1448
+ wheelAccumulated = 0;
1449
+ const rtl = isRtlTrack(stage);
1450
+ const key = dx > 0 ? "ArrowRight" : "ArrowLeft";
1451
+ const delta = arrowIndexDelta(key, rtl);
1452
+ if (delta !== 1 && delta !== -1) {
1453
+ return;
1454
+ }
1455
+ intentRef.current(delta);
1456
+ };
1457
+ const handleClickCapture = (event) => {
1458
+ if (!suppressNextClick) {
1459
+ return;
1460
+ }
1461
+ suppressNextClick = false;
1462
+ if (suppressTimer) {
1463
+ clearTimeout(suppressTimer);
1464
+ suppressTimer = null;
1465
+ }
1466
+ event.preventDefault();
1467
+ event.stopPropagation();
1468
+ };
1469
+ root.addEventListener("pointerdown", handlePointerDown);
1470
+ window.addEventListener("pointermove", handlePointerMove);
1471
+ window.addEventListener("pointerup", handlePointerUp);
1472
+ window.addEventListener("pointercancel", handlePointerCancel);
1473
+ root.addEventListener("click", handleClickCapture, true);
1474
+ root.addEventListener("wheel", handleWheel, { passive: false });
1475
+ return () => {
1476
+ if (wheelQuietTimer) {
1477
+ clearTimeout(wheelQuietTimer);
1478
+ }
1479
+ if (suppressTimer) {
1480
+ clearTimeout(suppressTimer);
1481
+ }
1482
+ root.removeEventListener("pointerdown", handlePointerDown);
1483
+ window.removeEventListener("pointermove", handlePointerMove);
1484
+ window.removeEventListener("pointerup", handlePointerUp);
1485
+ window.removeEventListener("pointercancel", handlePointerCancel);
1486
+ root.removeEventListener("click", handleClickCapture, true);
1487
+ root.removeEventListener("wheel", handleWheel);
1488
+ };
1489
+ }, [enabled, rootRef, stageRef]);
1490
+ }
1491
+ var LightboxZoomOptionsRegistryContext = createContext(null);
1492
+ function LightboxZoomOptionsRegistryProvider({
1493
+ children,
1494
+ value
1495
+ }) {
1496
+ return createElement(LightboxZoomOptionsRegistryContext.Provider, { value }, children);
1497
+ }
1498
+ function useLightboxZoomOptionsRegistry() {
1499
+ const register = useContext(LightboxZoomOptionsRegistryContext);
1500
+ if (register === null) {
1501
+ throw new Error("This lightbox part must be rendered inside Lightbox.Content.");
1502
+ }
1503
+ return register;
1504
+ }
1505
+ var FOCUSABLE_SELECTOR = 'a[href], button:not([disabled]):not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), input, select, textarea';
1506
+ function LightboxContent({
1507
+ children,
1508
+ className,
1509
+ ref,
1510
+ render,
1511
+ ...props
1512
+ }) {
1513
+ const { rootRef, backdropRef, stageRef, trackRef, zoomRef } = useLightboxRefs();
1514
+ const { items, labels, reducedMotion, transition } = useLightboxConfig();
1515
+ const { close, goTo, index } = useLightboxState();
1516
+ const registerZoom = useLightboxZoomRegistry();
1517
+ const item = items[index];
1518
+ const position = labels.position(index, items.length);
1519
+ const viewTransition = transition === "view-transition";
1520
+ const restoreFocusRef = useRef(null);
1521
+ const [zoomOptions, setZoomOptions] = useState(null);
1522
+ const { handleKey, isZoomed, zoomIn, zoomOut } = useMediaZoom({
1523
+ enabled: true,
1524
+ index,
1525
+ reducedMotion,
1526
+ trackRef,
1527
+ zoomRef,
1528
+ ...zoomOptions
1529
+ });
1530
+ useEffect(() => {
1531
+ registerZoom({ isZoomed, zoomIn, zoomOut });
1532
+ }, [registerZoom, isZoomed, zoomIn, zoomOut]);
1533
+ usePullToDismiss({
1534
+ backdropRef,
1535
+ enabled: !isZoomed,
1536
+ onDismiss: close,
1537
+ reducedMotion,
1538
+ rootRef,
1539
+ stageRef,
1540
+ trackRef
1541
+ });
1542
+ useSwipeIntent({
1543
+ enabled: !isZoomed,
1544
+ onIntent: (delta) => {
1545
+ goTo(index + delta);
1546
+ },
1547
+ rootRef,
1548
+ stageRef
1549
+ });
1550
+ useEffect(() => {
1551
+ restoreFocusRef.current = document.activeElement;
1552
+ rootRef.current?.focus({ preventScroll: true });
1553
+ return () => {
1554
+ const trigger = restoreFocusRef.current;
1555
+ const restore = () => {
1556
+ trigger?.focus({ preventScroll: true });
1557
+ };
1558
+ if (document.documentElement.classList.contains("a63-media-lightbox-vt")) {
1559
+ void whenMediaViewTransitionSettles().then(restore);
1560
+ return;
1561
+ }
1562
+ restore();
1563
+ };
1564
+ }, [rootRef]);
1565
+ useEffect(() => lockBodyScroll(), []);
1566
+ useEffect(() => {
1567
+ const handleKeyDown = (event) => {
1568
+ if (!event.ctrlKey && !event.metaKey && !event.altKey && handleKey(event.key)) {
1569
+ event.preventDefault();
1570
+ return;
1571
+ }
1572
+ if (event.key === "Escape") {
1573
+ event.preventDefault();
1574
+ if (isZoomed) {
1575
+ handleKey("0");
1576
+ return;
1577
+ }
1578
+ close();
1579
+ return;
1580
+ }
1581
+ if (!isZoomed) {
1582
+ const delta = arrowIndexDelta(
1583
+ event.key,
1584
+ trackRef.current ? isRtlTrack(trackRef.current) : false
1585
+ );
1586
+ if (delta !== void 0) {
1587
+ event.preventDefault();
1588
+ goTo(index + delta);
1589
+ return;
1590
+ }
1591
+ }
1592
+ if (event.key === "Home" && !isZoomed) {
1593
+ event.preventDefault();
1594
+ goTo(0);
1595
+ return;
1596
+ }
1597
+ if (event.key === "End" && !isZoomed) {
1598
+ event.preventDefault();
1599
+ goTo(items.length - 1);
1600
+ return;
1601
+ }
1602
+ if (event.key !== "Tab") {
1603
+ return;
1604
+ }
1605
+ const focusable = [
1606
+ ...rootRef.current?.querySelectorAll(FOCUSABLE_SELECTOR) ?? []
1607
+ ];
1608
+ if (focusable.length === 0) {
1609
+ return;
1610
+ }
1611
+ const first = focusable[0];
1612
+ const last = focusable.at(-1);
1613
+ if (!first || !last) {
1614
+ return;
1615
+ }
1616
+ if (document.activeElement === rootRef.current) {
1617
+ event.preventDefault();
1618
+ (event.shiftKey ? last : first).focus({ preventScroll: true });
1619
+ return;
1620
+ }
1621
+ if (event.shiftKey && document.activeElement === first) {
1622
+ event.preventDefault();
1623
+ last.focus({ preventScroll: true });
1624
+ } else if (!event.shiftKey && document.activeElement === last) {
1625
+ event.preventDefault();
1626
+ first.focus({ preventScroll: true });
1627
+ }
1628
+ };
1629
+ document.addEventListener("keydown", handleKeyDown);
1630
+ return () => {
1631
+ document.removeEventListener("keydown", handleKeyDown);
1632
+ };
1633
+ }, [close, goTo, handleKey, index, isZoomed, items.length, rootRef, trackRef]);
1634
+ const defaultProps = {
1635
+ "aria-label": `${item.title} \u2014 ${position}`,
1636
+ "aria-modal": "true",
1637
+ children: /* @__PURE__ */ jsx(LightboxZoomOptionsRegistryProvider, { value: setZoomOptions, children }),
1638
+ className: cn("fixed inset-0 z-50 flex flex-col", className),
1639
+ "data-open": "",
1640
+ "data-pulling": "false",
1641
+ "data-slot": "media-lightbox",
1642
+ "data-transition": viewTransition ? "view-transition" : "flip",
1643
+ "data-zoomed": isZoomed ? "true" : "false",
1644
+ role: "dialog",
1645
+ style: {
1646
+ "--a63-media-lightbox-media-h": "100%"
1647
+ },
1648
+ // Programmatically focusable on open, but never a tab stop of its own.
1649
+ tabIndex: -1
1650
+ };
1651
+ return useRender({
1652
+ defaultTagName: "div",
1653
+ props: mergeProps(defaultProps, props),
1654
+ ref: [rootRef, ref ?? null],
1655
+ render
1656
+ });
1657
+ }
1658
+ function LightboxBackdrop({
1659
+ className,
1660
+ ref,
1661
+ render,
1662
+ ...props
1663
+ }) {
1664
+ const { backdropRef } = useLightboxRefs();
1665
+ const { close } = useLightboxState();
1666
+ const { transition } = useLightboxConfig();
1667
+ const viewTransition = transition === "view-transition";
1668
+ const defaultProps = {
1669
+ // Opaque, no backdrop-filter: the page behind can stop painting, which
1670
+ // a translucent blur would forbid.
1671
+ className: cn("absolute inset-0 bg-black", className),
1672
+ "data-slot": "media-lightbox-backdrop",
1673
+ onClick: close
1674
+ };
1675
+ return useRender({
1676
+ defaultTagName: "div",
1677
+ props: mergeProps(defaultProps, props),
1678
+ ref: [backdropRef, ref ?? null],
1679
+ render: render ?? /* @__PURE__ */ jsx(
1680
+ motion.div,
1681
+ {
1682
+ animate: viewTransition ? void 0 : { opacity: 1 },
1683
+ exit: viewTransition ? void 0 : { opacity: 0, transition: BACKDROP_OUT },
1684
+ initial: viewTransition ? void 0 : { opacity: 0 },
1685
+ transition: BACKDROP_IN
1686
+ }
1687
+ )
1688
+ });
1689
+ }
1690
+ function LightboxStatus({
1691
+ className,
1692
+ ref,
1693
+ render,
1694
+ ...props
1695
+ }) {
1696
+ const { items, labels } = useLightboxConfig();
1697
+ const { index } = useLightboxState();
1698
+ const item = items[index];
1699
+ const position = labels.position(index, items.length);
1700
+ const defaultProps = {
1701
+ "aria-atomic": true,
1702
+ "aria-live": "polite",
1703
+ children: `${item.title}, ${position}`,
1704
+ className: cn("sr-only", className),
1705
+ "data-slot": "media-lightbox-status"
1706
+ };
1707
+ return useRender({
1708
+ defaultTagName: "div",
1709
+ props: mergeProps(defaultProps, props),
1710
+ ref: ref ?? null,
1711
+ render
1712
+ });
1713
+ }
1714
+ function useStageTransition({
1715
+ index,
1716
+ reducedMotion,
1717
+ timing
1718
+ }) {
1719
+ const [outgoingIndex, setOutgoingIndex] = useState(null);
1720
+ const previousIndexRef = useRef(index);
1721
+ const timerRef = useRef(null);
1722
+ const durationMs = LIGHTBOX_TIMING[timing].vtDurationMs;
1723
+ useLayoutEffect(() => {
1724
+ const previous = previousIndexRef.current;
1725
+ if (index === previous) {
1726
+ return;
1727
+ }
1728
+ previousIndexRef.current = index;
1729
+ if (timerRef.current !== null) {
1730
+ clearTimeout(timerRef.current);
1731
+ timerRef.current = null;
1732
+ }
1733
+ if (reducedMotion) {
1734
+ setOutgoingIndex(null);
1735
+ return;
1736
+ }
1737
+ setOutgoingIndex(previous);
1738
+ timerRef.current = setTimeout(() => {
1739
+ setOutgoingIndex(null);
1740
+ timerRef.current = null;
1741
+ }, durationMs);
1742
+ }, [durationMs, index, reducedMotion]);
1743
+ useLayoutEffect(
1744
+ () => () => {
1745
+ if (timerRef.current !== null) {
1746
+ clearTimeout(timerRef.current);
1747
+ }
1748
+ },
1749
+ []
1750
+ );
1751
+ return { outgoingIndex };
1752
+ }
1753
+ function LightboxViewport({
1754
+ className,
1755
+ ref,
1756
+ render,
1757
+ ...props
1758
+ }) {
1759
+ const { stageRef } = useLightboxRefs();
1760
+ const defaultProps = {
1761
+ className: cn("relative z-10 min-h-0 flex-1", className),
1762
+ "data-slot": "media-lightbox-viewport"
1763
+ };
1764
+ return useRender({
1765
+ defaultTagName: "div",
1766
+ props: mergeProps(defaultProps, props),
1767
+ ref: [stageRef, ref ?? null],
1768
+ render
1769
+ });
1770
+ }
1771
+ function LightboxSlides({
1772
+ children,
1773
+ className,
1774
+ ref,
1775
+ render,
1776
+ ...props
1777
+ }) {
1778
+ const { trackRef } = useLightboxRefs();
1779
+ const { index } = useLightboxState();
1780
+ const { items, labels, preload, reducedMotion, timing } = useLightboxConfig();
1781
+ const [livePreload, setLivePreload] = useState(0);
1782
+ const [trackDirection, setTrackDirection] = useState("ltr");
1783
+ const { outgoingIndex } = useStageTransition({ index, reducedMotion, timing });
1784
+ useEffect(() => {
1785
+ if (preload <= 0) {
1786
+ return;
1787
+ }
1788
+ let inner = 0;
1789
+ const outer = requestAnimationFrame(() => {
1790
+ inner = requestAnimationFrame(() => {
1791
+ setLivePreload(preload);
1792
+ });
1793
+ });
1794
+ return () => {
1795
+ cancelAnimationFrame(outer);
1796
+ cancelAnimationFrame(inner);
1797
+ };
1798
+ }, [preload]);
1799
+ useLayoutEffect(() => {
1800
+ const track = trackRef.current;
1801
+ if (track) {
1802
+ setTrackDirection(isRtlTrack(track) ? "rtl" : "ltr");
1803
+ }
1804
+ }, [trackRef]);
1805
+ const defaultProps = {
1806
+ "aria-label": labels.gallery,
1807
+ "aria-roledescription": labels.carousel,
1808
+ children: items.map((item, slideIndex) => {
1809
+ const isActive = slideIndex === index;
1810
+ const isNear = isActive || slideIndex === outgoingIndex || Math.abs(slideIndex - index) <= livePreload;
1811
+ const slide = { isActive, isNear, item, slideIndex };
1812
+ return /* @__PURE__ */ jsx(LightboxSlideContext.Provider, { value: slide, children: children(slide) }, item.id);
1813
+ }),
1814
+ className: cn("relative h-full w-full overflow-hidden", className),
1815
+ "data-active-index": index,
1816
+ "data-direction": trackDirection,
1817
+ "data-slot": "media-lightbox-track",
1818
+ role: "group"
1819
+ };
1820
+ return useRender({
1821
+ defaultTagName: "div",
1822
+ props: mergeProps(defaultProps, props),
1823
+ ref: [trackRef, ref ?? null],
1824
+ render
1825
+ });
1826
+ }
1827
+ function LightboxSlide({
1828
+ children,
1829
+ className,
1830
+ ref,
1831
+ render,
1832
+ ...props
1833
+ }) {
1834
+ const slide = useLightboxSlide();
1835
+ if (slide === null) {
1836
+ throw new Error("Lightbox.Slide must be rendered inside Lightbox.Slides.");
1837
+ }
1838
+ const { isActive, item, slideIndex } = slide;
1839
+ const { items, labels, reducedMotion, timing } = useLightboxConfig();
1840
+ const hasThumbnails = useLightboxThumbnailsPresence();
1841
+ const showThumbnails = hasThumbnails && items.length > 1;
1842
+ const { vtDurationMs, vtEasing } = LIGHTBOX_TIMING[timing];
1843
+ const style = {
1844
+ opacity: isActive ? 1 : 0,
1845
+ // Reduced motion switches instantly: no transition property means the
1846
+ // opacity value above lands on the very frame it changes.
1847
+ ...reducedMotion ? {} : {
1848
+ transitionDuration: `${vtDurationMs}ms`,
1849
+ transitionProperty: "opacity",
1850
+ transitionTimingFunction: vtEasing
1851
+ }
1852
+ };
1853
+ const defaultProps = {
1854
+ "aria-label": showThumbnails ? void 0 : `${item.title} \u2014 ${labels.position(slideIndex, items.length)}`,
1855
+ "aria-labelledby": showThumbnails ? `a63-media-lightbox-thumb-${item.id}` : void 0,
1856
+ "aria-roledescription": labels.slide,
1857
+ children,
1858
+ className: cn(
1859
+ "absolute inset-0 flex h-full w-full items-center justify-center",
1860
+ // A size container, so the frame can size itself against the slide in
1861
+ // *both* axes at once. Pinning one axis and letting the aspect ratio
1862
+ // drive the other only fits one orientation: pin the height and a photo
1863
+ // wider than the screen overflows and gets clamped back to the screen's
1864
+ // shape, pin the width and a taller one does the same. `cqw`/`cqh` give
1865
+ // the frame both of the slide's dimensions, so it can take the smaller
1866
+ // of the two fits and land on the photo's shape either way.
1867
+ "[container-type:size]",
1868
+ // Only the active slide should ever be hit-tested: a slide fading out
1869
+ // (or one that never left `opacity: 0`) still occupies the same box.
1870
+ !isActive && "pointer-events-none",
1871
+ className
1872
+ ),
1873
+ ...isActive ? { "data-active": "" } : {},
1874
+ "data-index": slideIndex,
1875
+ "data-slot": "media-lightbox-slide",
1876
+ id: `a63-media-lightbox-slide-${item.id}`,
1877
+ // `inert` also drops the slide out of the tab order and out of
1878
+ // find-in-page, which `aria-hidden` alone does not.
1879
+ inert: !isActive,
1880
+ role: showThumbnails ? "tabpanel" : "group",
1881
+ style
1882
+ };
1883
+ return useRender({
1884
+ defaultTagName: "div",
1885
+ props: mergeProps(defaultProps, props),
1886
+ ref: ref ?? null,
1887
+ render
1888
+ });
1889
+ }
1890
+
1891
+ // src/media/media-lightbox/origin-morph.ts
1892
+ function isOnScreen(rect) {
1893
+ return rect.width > 0 && rect.bottom > 0 && rect.right > 0 && rect.top < window.innerHeight && rect.left < window.innerWidth;
1894
+ }
1895
+ function readRadius(element) {
1896
+ const value = Number.parseFloat(getComputedStyle(element).borderTopLeftRadius);
1897
+ return Number.isFinite(value) ? value : 0;
1898
+ }
1899
+ function lerp(from, to, progress) {
1900
+ return from + (to - from) * progress;
1901
+ }
1902
+ function guessedMediaBox(media, origin) {
1903
+ const originRect = origin.getBoundingClientRect();
1904
+ const stage = media.parentElement;
1905
+ if (!stage || originRect.width === 0 || originRect.height === 0) {
1906
+ return null;
1907
+ }
1908
+ const stageRect = stage.getBoundingClientRect();
1909
+ if (stageRect.width <= 0 || stageRect.height <= 0) {
1910
+ return null;
1911
+ }
1912
+ const aspect = originRect.width / originRect.height;
1913
+ let width = stageRect.width;
1914
+ let height = width / aspect;
1915
+ if (height > stageRect.height) {
1916
+ height = stageRect.height;
1917
+ width = height * aspect;
1918
+ }
1919
+ return {
1920
+ height,
1921
+ left: stageRect.left + (stageRect.width - width) / 2,
1922
+ top: stageRect.top + (stageRect.height - height) / 2,
1923
+ width
1924
+ };
1925
+ }
1926
+ function measureOriginMorph(media, mediaBox, origin) {
1927
+ if (!origin || mediaBox.width <= 0 || mediaBox.height <= 0) {
1928
+ return null;
1929
+ }
1930
+ const originRect = origin.getBoundingClientRect();
1931
+ if (!isOnScreen(originRect)) {
1932
+ return null;
1933
+ }
1934
+ const layoutWidth = media.offsetWidth;
1935
+ const layoutHeight = media.offsetHeight;
1936
+ const measured = layoutWidth > 0 ? mediaBox.width / layoutWidth : 1;
1937
+ const ancestorScale = Math.abs(measured - 1) < 0.01 ? 1 : measured;
1938
+ const mediaWidth = ancestorScale === 1 ? mediaBox.width : layoutWidth;
1939
+ const mediaHeight = ancestorScale === 1 ? mediaBox.height : layoutHeight;
1940
+ if (mediaWidth <= 0 || mediaHeight <= 0) {
1941
+ return null;
1942
+ }
1943
+ return {
1944
+ ancestorScale,
1945
+ dx: (originRect.left + originRect.width / 2 - (mediaBox.left + mediaBox.width / 2)) / ancestorScale,
1946
+ dy: (originRect.top + originRect.height / 2 - (mediaBox.top + mediaBox.height / 2)) / ancestorScale,
1947
+ mediaHeight,
1948
+ mediaRadius: readRadius(media),
1949
+ mediaWidth,
1950
+ originHeight: originRect.height,
1951
+ originRadius: readRadius(origin),
1952
+ originWidth: originRect.width,
1953
+ scale: Math.max(originRect.width / mediaBox.width, originRect.height / mediaBox.height)
1954
+ };
1955
+ }
1956
+ function paintOriginMorph(media, morph, progress) {
1957
+ const scale = lerp(morph.scale, 1, progress);
1958
+ const x = lerp(morph.dx, 0, progress);
1959
+ const y = lerp(morph.dy, 0, progress);
1960
+ const toLocal = morph.ancestorScale * scale;
1961
+ const visibleWidth = lerp(morph.originWidth, morph.mediaWidth * morph.ancestorScale, progress);
1962
+ const visibleHeight = lerp(morph.originHeight, morph.mediaHeight * morph.ancestorScale, progress);
1963
+ const insetX = Math.max((morph.mediaWidth - visibleWidth / toLocal) / 2, 0);
1964
+ const insetY = Math.max((morph.mediaHeight - visibleHeight / toLocal) / 2, 0);
1965
+ const radius = lerp(morph.originRadius, morph.mediaRadius * morph.ancestorScale, progress) / toLocal;
1966
+ media.style.transform = `translate3d(${x}px, ${y}px, 0) scale(${scale})`;
1967
+ media.style.clipPath = `inset(${insetY}px ${insetX}px round ${radius}px)`;
1968
+ }
1969
+ function clearOriginMorph(media) {
1970
+ media.style.transform = "";
1971
+ media.style.clipPath = "";
1972
+ media.style.transformOrigin = "";
1973
+ media.style.willChange = "";
1974
+ }
1975
+ var MEDIA_BOX = "max-h-[var(--a63-media-lightbox-media-h,100%)] max-w-[min(92vw,1400px)] object-contain";
1976
+ var LIGHTBOX_IMAGE_SIZES = "min(92vw, 1400px)";
1977
+ function resolveMediaSrc(item, appearance) {
1978
+ if (item.lightSrc && item.darkSrc) {
1979
+ return appearance === "light" ? item.lightSrc : item.darkSrc;
1980
+ }
1981
+ return item.src ?? item.lightSrc ?? item.darkSrc;
1982
+ }
1983
+ function resolveThumbSrc(item, appearance) {
1984
+ if (item.thumbLightSrc && item.thumbDarkSrc) {
1985
+ return appearance === "light" ? item.thumbLightSrc : item.thumbDarkSrc;
1986
+ }
1987
+ return item.thumbSrc ?? item.thumbLightSrc ?? item.thumbDarkSrc;
1988
+ }
1989
+ function hasMedia(item, src) {
1990
+ if (item.render) {
1991
+ return true;
1992
+ }
1993
+ if (item.kind === "video") {
1994
+ return Boolean(item.sources?.length);
1995
+ }
1996
+ return Boolean(src);
1997
+ }
1998
+ function SlideMedia({
1999
+ active,
2000
+ filled,
2001
+ item,
2002
+ src,
2003
+ thumbSrc
2004
+ }) {
2005
+ if (item.render) {
2006
+ return /* @__PURE__ */ jsx("div", { className: cn(MEDIA_BOX, "overflow-auto"), "data-slot": "media-lightbox-custom", children: item.render });
2007
+ }
2008
+ if (item.kind === "video") {
2009
+ if (!item.sources?.length) {
2010
+ return null;
2011
+ }
2012
+ return (
2013
+ // eslint-disable-next-line jsx-a11y/media-has-caption -- captions are the caller's to supply through `tracks`; nothing here can invent them.
2014
+ /* @__PURE__ */ jsx(
2015
+ "video",
2016
+ {
2017
+ "aria-label": item.alt,
2018
+ className: MEDIA_BOX,
2019
+ controls: true,
2020
+ "data-slot": "media-lightbox-video",
2021
+ "data-a63-no-drag": "",
2022
+ playsInline: true,
2023
+ poster: item.poster,
2024
+ preload: active ? "metadata" : "none",
2025
+ children: item.sources.map((source) => /* @__PURE__ */ jsx("source", { src: source.src, type: source.type }, source.src))
2026
+ }
2027
+ )
2028
+ );
2029
+ }
2030
+ if (!src) {
2031
+ return null;
2032
+ }
2033
+ const photo = /* @__PURE__ */ jsx(
2034
+ "img",
2035
+ {
2036
+ alt: item.alt,
2037
+ className: filled ? "absolute inset-0 size-full object-contain" : MEDIA_BOX,
2038
+ "data-slot": "media-lightbox-image",
2039
+ decoding: "async",
2040
+ draggable: false,
2041
+ fetchPriority: active ? "high" : "low",
2042
+ loading: active ? "eager" : "lazy",
2043
+ sizes: item.sizes ?? LIGHTBOX_IMAGE_SIZES,
2044
+ src,
2045
+ srcSet: item.srcSet
2046
+ }
2047
+ );
2048
+ if (!filled || !thumbSrc || thumbSrc === src) {
2049
+ return photo;
2050
+ }
2051
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2052
+ /* @__PURE__ */ jsx(
2053
+ "img",
2054
+ {
2055
+ alt: "",
2056
+ "aria-hidden": true,
2057
+ className: "absolute inset-0 size-full object-contain",
2058
+ "data-slot": "media-lightbox-placeholder",
2059
+ decoding: "async",
2060
+ draggable: false,
2061
+ src: thumbSrc
2062
+ }
2063
+ ),
2064
+ photo
2065
+ ] });
2066
+ }
2067
+ function useMediaAspect(thumbSrc, src) {
2068
+ const [aspect, setAspect] = useState(void 0);
2069
+ useEffect(() => {
2070
+ if (typeof Image === "undefined" || !thumbSrc && !src) {
2071
+ setAspect(void 0);
2072
+ return;
2073
+ }
2074
+ let cancelled = false;
2075
+ const detachers = [];
2076
+ const watch = (candidate, authoritative) => {
2077
+ if (!candidate) {
2078
+ return;
2079
+ }
2080
+ const probe = new Image();
2081
+ const read = () => {
2082
+ if (cancelled || probe.naturalWidth <= 0 || probe.naturalHeight <= 0) {
2083
+ return;
2084
+ }
2085
+ const ratio = probe.naturalWidth / probe.naturalHeight;
2086
+ setAspect((current) => current === void 0 || authoritative ? ratio : current);
2087
+ };
2088
+ probe.addEventListener("load", read);
2089
+ detachers.push(() => {
2090
+ probe.removeEventListener("load", read);
2091
+ });
2092
+ probe.src = candidate;
2093
+ if (probe.complete) {
2094
+ read();
2095
+ }
2096
+ };
2097
+ watch(thumbSrc, false);
2098
+ watch(src, true);
2099
+ return () => {
2100
+ cancelled = true;
2101
+ for (const detach of detachers) {
2102
+ detach();
2103
+ }
2104
+ };
2105
+ }, [src, thumbSrc]);
2106
+ return aspect;
2107
+ }
2108
+ function useOriginZoom(origin, enabled) {
2109
+ const mediaRef = useRef(null);
2110
+ const [isPresent, safeToRemove] = usePresence();
2111
+ useLayoutEffect(() => {
2112
+ const media = mediaRef.current;
2113
+ if (!media || !enabled) {
2114
+ return;
2115
+ }
2116
+ media.style.opacity = "0";
2117
+ let cancelled = false;
2118
+ const startZoom = () => {
2119
+ if (cancelled) {
2120
+ return true;
2121
+ }
2122
+ clearOriginMorph(media);
2123
+ const measured = media.getBoundingClientRect();
2124
+ const box = measured.width > 0 ? measured : origin ? guessedMediaBox(media, origin) : null;
2125
+ if (!box) {
2126
+ return false;
2127
+ }
2128
+ const morph = measureOriginMorph(media, box, origin ?? null);
2129
+ media.style.opacity = "1";
2130
+ if (morph) {
2131
+ media.style.transformOrigin = "center";
2132
+ media.style.willChange = "transform";
2133
+ paintOriginMorph(media, morph, 0);
2134
+ void animate(0, 1, {
2135
+ ...MEDIA_SPRING,
2136
+ onComplete: () => {
2137
+ clearOriginMorph(media);
2138
+ },
2139
+ onUpdate: (progress) => {
2140
+ paintOriginMorph(media, morph, progress);
2141
+ }
2142
+ });
2143
+ } else {
2144
+ void animate(media, { opacity: [0, 1] }, MEDIA_FADE);
2145
+ }
2146
+ return true;
2147
+ };
2148
+ if (startZoom() || typeof ResizeObserver === "undefined") {
2149
+ if (media.style.opacity === "0") {
2150
+ media.style.opacity = "1";
2151
+ void animate(media, { opacity: [0, 1] }, MEDIA_FADE);
2152
+ }
2153
+ return () => {
2154
+ cancelled = true;
2155
+ };
2156
+ }
2157
+ const observer = new ResizeObserver(() => {
2158
+ if (startZoom()) {
2159
+ observer.disconnect();
2160
+ }
2161
+ });
2162
+ observer.observe(media);
2163
+ return () => {
2164
+ cancelled = true;
2165
+ observer.disconnect();
2166
+ };
2167
+ }, [enabled, origin]);
2168
+ useEffect(() => {
2169
+ const media = mediaRef.current;
2170
+ if (isPresent) {
2171
+ return;
2172
+ }
2173
+ if (!media || !enabled) {
2174
+ safeToRemove?.();
2175
+ return;
2176
+ }
2177
+ clearOriginMorph(media);
2178
+ const box = media.getBoundingClientRect();
2179
+ const morph = box.width > 0 ? measureOriginMorph(media, box, origin ?? null) : null;
2180
+ const animation = morph ? (() => {
2181
+ media.style.transformOrigin = "center";
2182
+ media.style.willChange = "transform";
2183
+ return animate(1, 0, {
2184
+ ...MEDIA_SPRING,
2185
+ onUpdate: (progress) => {
2186
+ paintOriginMorph(media, morph, progress);
2187
+ }
2188
+ });
2189
+ })() : animate(media, { opacity: 0 }, MEDIA_FADE);
2190
+ void animation.then(() => {
2191
+ safeToRemove?.();
2192
+ });
2193
+ }, [enabled, isPresent, origin, safeToRemove]);
2194
+ return mediaRef;
2195
+ }
2196
+ function LightboxFrame({
2197
+ children,
2198
+ className,
2199
+ ref,
2200
+ render,
2201
+ ...props
2202
+ }) {
2203
+ const slide = useLightboxSlide();
2204
+ if (slide === null) {
2205
+ throw new Error("Lightbox.Frame must be rendered inside Lightbox.Slide.");
2206
+ }
2207
+ const { isActive, isNear, item } = slide;
2208
+ const { appearance, origin, reducedMotion, transition } = useLightboxConfig();
2209
+ const { isZoomed } = useLightboxState();
2210
+ const { mediaRef } = useLightboxRefs();
2211
+ const viewTransition = transition === "view-transition";
2212
+ const itemThumb = isNear ? resolveThumbSrc(item, appearance?.[item.id]) : void 0;
2213
+ const itemSrc = isNear ? resolveMediaSrc(item, appearance?.[item.id]) : void 0;
2214
+ const activeAspect = useMediaAspect(itemThumb, itemSrc);
2215
+ const frameRef = useOriginZoom(
2216
+ origin,
2217
+ !reducedMotion && !viewTransition && (!itemThumb || activeAspect !== void 0)
2218
+ );
2219
+ const slideAspect = activeAspect;
2220
+ const defaultProps = {
2221
+ children,
2222
+ className: cn(
2223
+ "relative flex max-h-full min-h-0",
2224
+ "items-center justify-center",
2225
+ // `overflow-hidden` is mechanism, not decoration: it is what clips the
2226
+ // media to the frame during the morph. The corner radius that clip
2227
+ // follows is the caller's — `origin-morph` reads it off this element, so
2228
+ // it has to land here via `className` rather than on a child.
2229
+ //
2230
+ // It lifts while zoomed. The frame is photo-shaped, so clipping to it
2231
+ // would mean magnifying a picture inside a fixed window: the part of the
2232
+ // photo you zoomed towards leaves the frame and simply disappears.
2233
+ // Released, the enlarged photo runs to the edges of the track, which
2234
+ // clips at the viewport — which is the whole screen, and the only
2235
+ // boundary a zoom should answer to.
2236
+ !isZoomed && "overflow-hidden",
2237
+ // With the shape known the frame can size itself from the slide, which
2238
+ // is the only definite box in the chain. Without it the frame has to
2239
+ // wait for the photo, and a placeholder inside would be sizing itself
2240
+ // against a box that is sizing itself against the placeholder.
2241
+ //
2242
+ // Both of the slide's axes, via its size container: width follows the
2243
+ // slide, and the ceiling on that width is the width this aspect ratio
2244
+ // would reach at the slide's full height. Whichever runs out first
2245
+ // wins, which is exactly `object-contain`'s rule — but applied to the
2246
+ // frame, so the frame *is* the picture rather than a box the picture is
2247
+ // letterboxed inside. That matters beyond neatness: everything the
2248
+ // frame owns is addressed to its own edges. The morph flies the
2249
+ // thumbnail to them, the corner radius is drawn on them, and the
2250
+ // full-bleed close area begins outside them — so a frame larger than
2251
+ // the photo overshoots the morph, rounds corners nobody can see, and
2252
+ // covers taps meant for the close area with bands that look exactly
2253
+ // like backdrop.
2254
+ slideAspect !== void 0 && "h-auto max-h-[100cqh] w-[100cqw] max-w-[calc(100cqh*var(--a63-lightbox-aspect))]",
2255
+ className
2256
+ ),
2257
+ // Only carried by the active slide, and only when the browser itself owns
2258
+ // the transition: a second element sharing the morph's name would strand
2259
+ // the browser's snapshot pairing (see `view-transition.ts`'s "name
2260
+ // isolation").
2261
+ ...isActive && viewTransition ? { [MORPH_TARGET_ATTRIBUTE]: "" } : {},
2262
+ "data-slot": "media-lightbox-frame",
2263
+ style: {
2264
+ ...slideAspect === void 0 ? {} : { "--a63-lightbox-aspect": slideAspect, aspectRatio: slideAspect },
2265
+ ...isActive && viewTransition ? { viewTransitionName: MEDIA_VIEW_TRANSITION_NAME } : {}
2266
+ }
2267
+ };
2268
+ return useRender({
2269
+ defaultTagName: "div",
2270
+ props: mergeProps(defaultProps, props),
2271
+ ref: [isActive ? mediaRef : null, isActive ? frameRef : null, ref ?? null],
2272
+ render: render ?? /* @__PURE__ */ jsx(
2273
+ motion.div,
2274
+ {
2275
+ animate: reducedMotion && isActive ? { opacity: 1 } : void 0,
2276
+ initial: reducedMotion && isActive ? { opacity: 0 } : void 0,
2277
+ transition: MEDIA_FADE
2278
+ }
2279
+ )
2280
+ });
2281
+ }
2282
+ function LightboxZoom({
2283
+ children,
2284
+ className,
2285
+ doubleTapScale,
2286
+ keyboardPanDistance,
2287
+ maxZoom,
2288
+ minZoom,
2289
+ onZoomChange,
2290
+ ref,
2291
+ render,
2292
+ scrollToZoom,
2293
+ wheelSensitivity,
2294
+ zoomStep,
2295
+ ...props
2296
+ }) {
2297
+ const slide = useLightboxSlide();
2298
+ if (slide === null) {
2299
+ throw new Error("Lightbox.Zoom must be rendered inside Lightbox.Slide.");
2300
+ }
2301
+ const { isActive, isNear, item } = slide;
2302
+ const { appearance } = useLightboxConfig();
2303
+ const { zoomRef } = useLightboxRefs();
2304
+ const registerOptions = useLightboxZoomOptionsRegistry();
2305
+ const itemThumb = isNear ? resolveThumbSrc(item, appearance?.[item.id]) : void 0;
2306
+ const itemSrc = isNear ? resolveMediaSrc(item, appearance?.[item.id]) : void 0;
2307
+ const slideAspect = useMediaAspect(itemThumb, itemSrc);
2308
+ useEffect(() => {
2309
+ if (!isActive) {
2310
+ return;
2311
+ }
2312
+ registerOptions({
2313
+ doubleTapScale,
2314
+ keyboardPanDistance,
2315
+ maxZoom,
2316
+ minZoom,
2317
+ onZoomChange,
2318
+ scrollToZoom,
2319
+ wheelSensitivity,
2320
+ zoomStep
2321
+ });
2322
+ return () => {
2323
+ registerOptions(null);
2324
+ };
2325
+ }, [
2326
+ doubleTapScale,
2327
+ isActive,
2328
+ keyboardPanDistance,
2329
+ maxZoom,
2330
+ minZoom,
2331
+ onZoomChange,
2332
+ registerOptions,
2333
+ scrollToZoom,
2334
+ wheelSensitivity,
2335
+ zoomStep
2336
+ ]);
2337
+ const defaultProps = {
2338
+ children,
2339
+ className: cn(
2340
+ "relative",
2341
+ isActive && "transform-gpu will-change-transform",
2342
+ // Mirrors `Frame`'s own `h-full`: without an explicit size, an
2343
+ // absolutely positioned `filled` photo (see `Media`) has nothing to
2344
+ // size itself against and collapses this box to zero height.
2345
+ slideAspect !== void 0 && "size-full",
2346
+ className
2347
+ ),
2348
+ "data-slot": "media-lightbox-zoom"
2349
+ };
2350
+ return useRender({
2351
+ defaultTagName: "div",
2352
+ props: mergeProps(defaultProps, props),
2353
+ ref: [isActive ? zoomRef : null, ref ?? null],
2354
+ render
2355
+ });
2356
+ }
2357
+ function LightboxMedia() {
2358
+ const slide = useLightboxSlide();
2359
+ if (slide === null) {
2360
+ throw new Error("Lightbox.Media must be rendered inside Lightbox.Slide.");
2361
+ }
2362
+ const { isActive, isNear, item } = slide;
2363
+ const { appearance } = useLightboxConfig();
2364
+ const src = resolveMediaSrc(item, appearance?.[item.id]);
2365
+ const thumbSrc = resolveThumbSrc(item, appearance?.[item.id]);
2366
+ const aspect = useMediaAspect(isNear ? thumbSrc : void 0, isNear ? src : void 0);
2367
+ const filled = aspect !== void 0;
2368
+ if (!isNear || !hasMedia(item, src)) {
2369
+ return null;
2370
+ }
2371
+ return /* @__PURE__ */ jsx(SlideMedia, { active: isActive, filled, item, src, thumbSrc });
2372
+ }
2373
+ function LightboxClose({
2374
+ className,
2375
+ render,
2376
+ ...props
2377
+ }) {
2378
+ const { labels } = useLightboxConfig();
2379
+ const { close } = useLightboxState();
2380
+ const defaultProps = {
2381
+ "aria-label": labels.close,
2382
+ className,
2383
+ "data-slot": "media-lightbox-close",
2384
+ onClick: close,
2385
+ type: "button"
2386
+ };
2387
+ return useRender({
2388
+ defaultTagName: "button",
2389
+ props: mergeProps(defaultProps, props),
2390
+ render
2391
+ });
2392
+ }
2393
+ function LightboxPrevious({
2394
+ className,
2395
+ render,
2396
+ ...props
2397
+ }) {
2398
+ const { labels } = useLightboxConfig();
2399
+ const { goTo, index } = useLightboxState();
2400
+ const disabled = index <= 0;
2401
+ const defaultProps = {
2402
+ "aria-label": labels.previous,
2403
+ className,
2404
+ "data-slot": "media-lightbox-previous",
2405
+ disabled,
2406
+ onClick: () => {
2407
+ goTo(index - 1);
2408
+ },
2409
+ type: "button",
2410
+ ...disabled ? { "data-disabled": "" } : {}
2411
+ };
2412
+ return useRender({
2413
+ defaultTagName: "button",
2414
+ props: mergeProps(defaultProps, props),
2415
+ render
2416
+ });
2417
+ }
2418
+ function LightboxNext({
2419
+ className,
2420
+ render,
2421
+ ...props
2422
+ }) {
2423
+ const { labels } = useLightboxConfig();
2424
+ const { goTo, index, itemCount } = useLightboxState();
2425
+ const disabled = index >= itemCount - 1;
2426
+ const defaultProps = {
2427
+ "aria-label": labels.next,
2428
+ className,
2429
+ "data-slot": "media-lightbox-next",
2430
+ disabled,
2431
+ onClick: () => {
2432
+ goTo(index + 1);
2433
+ },
2434
+ type: "button",
2435
+ ...disabled ? { "data-disabled": "" } : {}
2436
+ };
2437
+ return useRender({
2438
+ defaultTagName: "button",
2439
+ props: mergeProps(defaultProps, props),
2440
+ render
2441
+ });
2442
+ }
2443
+ function LightboxCounter({
2444
+ children,
2445
+ className,
2446
+ render,
2447
+ ...props
2448
+ }) {
2449
+ const { items, labels } = useLightboxConfig();
2450
+ const { index } = useLightboxState();
2451
+ const total = items.length;
2452
+ const current = index + 1;
2453
+ const defaultProps = {
2454
+ // "3 of 7" is a run of digits either side of a word, which a
2455
+ // right-to-left paragraph reorders into "of 7 3"; taking the direction
2456
+ // from the text itself keeps an English counter readable inside an RTL
2457
+ // gallery and lets a translated one read right to left.
2458
+ children: children ? children(current, total) : labels.position(index, total),
2459
+ className,
2460
+ "data-slot": "media-lightbox-counter",
2461
+ dir: "auto"
2462
+ };
2463
+ return useRender({
2464
+ defaultTagName: "p",
2465
+ props: mergeProps(defaultProps, props),
2466
+ render
2467
+ });
2468
+ }
2469
+ function LightboxCaption({
2470
+ className,
2471
+ render,
2472
+ ...props
2473
+ }) {
2474
+ const { items } = useLightboxConfig();
2475
+ const { index } = useLightboxState();
2476
+ const item = items[index];
2477
+ const defaultProps = {
2478
+ children: item?.caption ?? "",
2479
+ className,
2480
+ "data-slot": "media-lightbox-caption"
2481
+ };
2482
+ const element = useRender({
2483
+ defaultTagName: "p",
2484
+ props: mergeProps(defaultProps, props),
2485
+ render
2486
+ });
2487
+ return item?.caption ? element : null;
2488
+ }
2489
+ function LightboxZoomIn({
2490
+ className,
2491
+ render,
2492
+ ...props
2493
+ }) {
2494
+ const { items, labels } = useLightboxConfig();
2495
+ const { index, zoomIn } = useLightboxState();
2496
+ const item = items[index];
2497
+ const defaultProps = {
2498
+ "aria-label": item ? labels.zoomIn(item.title) : void 0,
2499
+ className,
2500
+ "data-slot": "media-lightbox-zoom-in",
2501
+ onClick: zoomIn,
2502
+ type: "button"
2503
+ };
2504
+ return useRender({
2505
+ defaultTagName: "button",
2506
+ props: mergeProps(defaultProps, props),
2507
+ render
2508
+ });
2509
+ }
2510
+ function LightboxZoomOut({
2511
+ className,
2512
+ render,
2513
+ ...props
2514
+ }) {
2515
+ const { items, labels } = useLightboxConfig();
2516
+ const { index, isZoomed, zoomOut } = useLightboxState();
2517
+ const item = items[index];
2518
+ const disabled = !isZoomed;
2519
+ const defaultProps = {
2520
+ "aria-label": item ? labels.zoomOut(item.title) : void 0,
2521
+ className,
2522
+ "data-slot": "media-lightbox-zoom-out",
2523
+ disabled,
2524
+ onClick: zoomOut,
2525
+ type: "button",
2526
+ ...disabled ? { "data-disabled": "" } : {}
2527
+ };
2528
+ return useRender({
2529
+ defaultTagName: "button",
2530
+ props: mergeProps(defaultProps, props),
2531
+ render
2532
+ });
2533
+ }
2534
+ var LightboxThumbnailContext = createContext(null);
2535
+ function useLightboxThumbnail() {
2536
+ const value = useContext(LightboxThumbnailContext);
2537
+ if (value === null) {
2538
+ throw new Error("Lightbox.Thumbnail must be rendered inside Lightbox.Thumbnails.");
2539
+ }
2540
+ return value;
2541
+ }
2542
+ function LightboxThumbnails({
2543
+ children,
2544
+ className,
2545
+ ref,
2546
+ render,
2547
+ ...props
2548
+ }) {
2549
+ const { items, labels, reducedMotion } = useLightboxConfig();
2550
+ const { goTo, index } = useLightboxState();
2551
+ const register = useLightboxThumbnailsRegistry();
2552
+ const listRef = useRef(null);
2553
+ useEffect(() => {
2554
+ register(true);
2555
+ return () => {
2556
+ register(false);
2557
+ };
2558
+ }, [register]);
2559
+ useEffect(() => {
2560
+ const active = listRef.current?.querySelector('[aria-selected="true"]');
2561
+ active?.scrollIntoView?.({
2562
+ behavior: reducedMotion ? "auto" : "smooth",
2563
+ block: "nearest",
2564
+ inline: "center"
2565
+ });
2566
+ }, [index, reducedMotion]);
2567
+ const handleKeyDown = (event) => {
2568
+ const moves = {
2569
+ ArrowLeft: index - 1,
2570
+ ArrowRight: index + 1,
2571
+ End: items.length - 1,
2572
+ Home: 0
2573
+ };
2574
+ const next = moves[event.key];
2575
+ if (next === void 0) {
2576
+ return;
2577
+ }
2578
+ event.preventDefault();
2579
+ event.stopPropagation();
2580
+ const clamped = Math.min(Math.max(next, 0), items.length - 1);
2581
+ goTo(clamped);
2582
+ listRef.current?.querySelectorAll('[role="tab"]')[clamped]?.focus();
2583
+ };
2584
+ const defaultProps = {
2585
+ "aria-label": labels.thumbnails,
2586
+ children: items.map((item, itemIndex) => {
2587
+ const value = {
2588
+ index: itemIndex,
2589
+ isActive: itemIndex === index,
2590
+ item
2591
+ };
2592
+ return /* @__PURE__ */ jsx(LightboxThumbnailContext.Provider, { value, children: children ? children(value) : /* @__PURE__ */ jsx(LightboxThumbnail, {}) }, item.id);
2593
+ }),
2594
+ className: cn(
2595
+ "flex max-w-full [scrollbar-width:none] gap-1.5 overflow-x-auto snap-x",
2596
+ "[&::-webkit-scrollbar]:hidden",
2597
+ className
2598
+ ),
2599
+ "data-slot": "media-lightbox-thumbnails",
2600
+ onKeyDown: handleKeyDown,
2601
+ role: "tablist"
2602
+ };
2603
+ return useRender({
2604
+ defaultTagName: "div",
2605
+ props: mergeProps(defaultProps, props),
2606
+ ref: [listRef, ref ?? null],
2607
+ render
2608
+ });
2609
+ }
2610
+ function LightboxThumbnail({
2611
+ children,
2612
+ className,
2613
+ render,
2614
+ ...props
2615
+ }) {
2616
+ const { index: itemIndex, isActive, item } = useLightboxThumbnail();
2617
+ const { appearance, labels } = useLightboxConfig();
2618
+ const { goTo, itemCount } = useLightboxState();
2619
+ const appearanceFor = appearance?.[item.id];
2620
+ const src = resolveThumbSrc(item, appearanceFor) ?? item.poster ?? resolveMediaSrc(item, appearanceFor);
2621
+ const defaultProps = {
2622
+ "aria-controls": `a63-media-lightbox-slide-${item.id}`,
2623
+ "aria-label": `${item.title} \u2014 ${labels.position(itemIndex, itemCount)}`,
2624
+ "aria-selected": isActive,
2625
+ children: children ?? (src ? /* @__PURE__ */ jsx(
2626
+ "img",
2627
+ {
2628
+ alt: "",
2629
+ className: "size-full object-cover",
2630
+ decoding: "async",
2631
+ draggable: false,
2632
+ loading: "lazy",
2633
+ src
2634
+ }
2635
+ ) : null),
2636
+ className,
2637
+ ...isActive ? { "data-active": "" } : {},
2638
+ "data-index": itemIndex,
2639
+ "data-slot": "media-lightbox-thumbnail",
2640
+ id: `a63-media-lightbox-thumb-${item.id}`,
2641
+ onClick: () => {
2642
+ goTo(itemIndex);
2643
+ },
2644
+ role: "tab",
2645
+ tabIndex: isActive ? 0 : -1,
2646
+ type: "button"
2647
+ };
2648
+ return useRender({
2649
+ defaultTagName: "button",
2650
+ props: mergeProps(defaultProps, props),
2651
+ render
2652
+ });
2653
+ }
2654
+ function isExternalHref(href) {
2655
+ return /^https?:\/\//i.test(href);
2656
+ }
2657
+ function LightboxAppearanceToggle({
2658
+ className,
2659
+ render,
2660
+ ...props
2661
+ }) {
2662
+ const { appearance, items, labels, onAppearanceChange } = useLightboxConfig();
2663
+ const { index } = useLightboxState();
2664
+ const item = items[index];
2665
+ const canToggle = Boolean(item?.lightSrc && item.darkSrc && onAppearanceChange);
2666
+ const isDark = (appearance?.[item?.id ?? ""] ?? "dark") !== "light";
2667
+ const target = isDark ? "light" : "dark";
2668
+ const defaultProps = {
2669
+ "aria-label": item ? labels.appearance(item.title, target) : void 0,
2670
+ children: isDark ? /* @__PURE__ */ jsx(Sun, { "aria-hidden": true, className: "size-5" }) : /* @__PURE__ */ jsx(Moon, { "aria-hidden": true, className: "size-5" }),
2671
+ className,
2672
+ "data-slot": "media-lightbox-appearance-toggle",
2673
+ onClick: () => {
2674
+ if (item) {
2675
+ onAppearanceChange?.(item.id, target);
2676
+ }
2677
+ },
2678
+ type: "button"
2679
+ };
2680
+ const element = useRender({
2681
+ defaultTagName: "button",
2682
+ props: mergeProps(defaultProps, props),
2683
+ render
2684
+ });
2685
+ return canToggle ? element : null;
2686
+ }
2687
+ function LightboxDestination({
2688
+ children,
2689
+ className,
2690
+ // Internal links always render through `item.renderHref`; a caller-supplied
2691
+ // `render` would silently be dropped by `DestinationLink` for external
2692
+ // links anyway, so it is deliberately not accepted here.
2693
+ render: _render,
2694
+ ...props
2695
+ }) {
2696
+ const { items, labels } = useLightboxConfig();
2697
+ const { index } = useLightboxState();
2698
+ const item = items[index];
2699
+ if (!item?.href) {
2700
+ return null;
2701
+ }
2702
+ const external = isExternalHref(item.href);
2703
+ return /* @__PURE__ */ jsx(
2704
+ DestinationLink,
2705
+ {
2706
+ "aria-label": labels.openDestination(item.title),
2707
+ className,
2708
+ href: item.href,
2709
+ kind: external ? "external" : "internal",
2710
+ render: external ? void 0 : item.renderHref,
2711
+ ...props,
2712
+ children: children ?? /* @__PURE__ */ jsx(DestinationIndicator, { className: "size-5", kind: external ? "external" : "internal" })
2713
+ }
2714
+ );
2715
+ }
2716
+
2717
+ // src/media/media-lightbox/parts/index.ts
2718
+ var Lightbox = {
2719
+ AppearanceToggle: LightboxAppearanceToggle,
2720
+ Backdrop: LightboxBackdrop,
2721
+ Caption: LightboxCaption,
2722
+ Close: LightboxClose,
2723
+ Content: LightboxContent,
2724
+ Counter: LightboxCounter,
2725
+ Destination: LightboxDestination,
2726
+ Frame: LightboxFrame,
2727
+ Media: LightboxMedia,
2728
+ Next: LightboxNext,
2729
+ Portal: LightboxPortal,
2730
+ Previous: LightboxPrevious,
2731
+ Root: LightboxRoot,
2732
+ Slide: LightboxSlide,
2733
+ Slides: LightboxSlides,
2734
+ Status: LightboxStatus,
2735
+ Thumbnail: LightboxThumbnail,
2736
+ Thumbnails: LightboxThumbnails,
2737
+ Viewport: LightboxViewport,
2738
+ Zoom: LightboxZoom,
2739
+ ZoomIn: LightboxZoomIn,
2740
+ ZoomOut: LightboxZoomOut
2741
+ };
2742
+
2743
+ export { CHROME_EXIT_OFFSET, CHROME_IN, CHROME_OUT, DEFAULT_MEDIA_LIGHTBOX_LABELS, Lightbox, LightboxAppearanceToggle, LightboxBackdrop, LightboxCaption, LightboxClose, LightboxContent, LightboxCounter, LightboxDestination, LightboxFrame, LightboxMedia, LightboxNext, LightboxPortal, LightboxPrevious, LightboxRoot, LightboxSlide, LightboxSlides, LightboxStatus, LightboxThumbnail, LightboxThumbnails, LightboxViewport, LightboxZoom, LightboxZoomIn, LightboxZoomOut, preferCheapMediaTransition, runMediaViewTransition, supportsViewTransitions, useLightboxConfig, useLightboxRefs, useLightboxSlide, useLightboxState, useOptionalLightboxConfig, useReducedMotion };
2744
+ //# sourceMappingURL=chunk-MXNO63TC.js.map
2745
+ //# sourceMappingURL=chunk-MXNO63TC.js.map