@atom63/ui-react 0.2.0-beta.1 → 0.2.0-beta.10

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 (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +54 -50
  3. package/dist/{button-sktq-nvV.d.ts → button-CfLIHg-R.d.ts} +1 -1
  4. package/dist/chunk-GDUMA6FI.js +2678 -0
  5. package/dist/chunk-GDUMA6FI.js.map +1 -0
  6. package/dist/{chunk-STCXERLM.js → chunk-J77BAGTA.js} +8 -148
  7. package/dist/chunk-J77BAGTA.js.map +1 -0
  8. package/dist/chunk-NBHGMMQN.js +135 -0
  9. package/dist/chunk-NBHGMMQN.js.map +1 -0
  10. package/dist/{chunk-7VSPECOH.js → chunk-R67OZVA2.js} +4 -14
  11. package/dist/chunk-R67OZVA2.js.map +1 -0
  12. package/dist/chunk-UPPHQLZ2.js +18 -0
  13. package/dist/chunk-UPPHQLZ2.js.map +1 -0
  14. package/dist/{chunk-MXNO63TC.js → chunk-X5L5DEUZ.js} +597 -290
  15. package/dist/chunk-X5L5DEUZ.js.map +1 -0
  16. package/dist/{destination-link-C9NKeKLe.d.ts → destination-link-DMLeR-oF.d.ts} +1 -1
  17. package/dist/index-BDzW8upQ.d.ts +442 -0
  18. package/dist/index.d.ts +56 -454
  19. package/dist/index.js +402 -2987
  20. package/dist/index.js.map +1 -1
  21. package/dist/layout/index.js +4 -4
  22. package/dist/layout/index.js.map +1 -1
  23. package/dist/media/index.d.ts +15 -4
  24. package/dist/media/index.js +213 -46
  25. package/dist/media/index.js.map +1 -1
  26. package/dist/media/media-lightbox/parts/index.d.ts +23 -15
  27. package/dist/media/media-lightbox/parts/index.js +3 -2
  28. package/dist/preview/index.d.ts +16 -0
  29. package/dist/preview/index.js +6 -0
  30. package/dist/preview/index.js.map +1 -0
  31. package/dist/theme/index.d.ts +2 -2
  32. package/dist/theme/index.js +81 -36
  33. package/dist/theme/index.js.map +1 -1
  34. package/package.json +31 -27
  35. package/src/components/accordion/accordion.css +2 -4
  36. package/src/components/alert-dialog/alert-dialog.css +1 -1
  37. package/src/components/autocomplete/autocomplete.css +3 -7
  38. package/src/components/badge/badge.css +5 -8
  39. package/src/components/breadcrumb/breadcrumb.css +1 -2
  40. package/src/components/button/button.css +8 -6
  41. package/src/components/button-group/button-group.css +17 -1
  42. package/src/components/calendar/calendar.css +5 -8
  43. package/src/components/card/card.css +2 -2
  44. package/src/components/carousel/carousel.css +4 -8
  45. package/src/components/checkbox/checkbox.css +1 -1
  46. package/src/components/command/command.css +8 -0
  47. package/src/components/connected-panel/connected-panel.css +3 -2
  48. package/src/components/dialog/dialog.css +1 -1
  49. package/src/components/drawer/drawer.css +1 -1
  50. package/src/components/empty/empty.css +2 -2
  51. package/src/components/feedback-state/feedback-state.css +1 -1
  52. package/src/components/field/field.css +4 -4
  53. package/src/components/form/form.css +2 -2
  54. package/src/components/input/input.css +2 -6
  55. package/src/components/input-otp/input-otp.css +4 -11
  56. package/src/components/item/item.css +3 -3
  57. package/src/components/menu/menu.css +5 -4
  58. package/src/components/menubar/menubar.css +4 -1
  59. package/src/components/navigation-menu/navigation-menu.css +5 -1
  60. package/src/components/panel-setting-button/panel-setting-button.css +1 -1
  61. package/src/components/radio/radio.css +1 -1
  62. package/src/components/resizable/resizable.css +1 -1
  63. package/src/components/scroll-area/scroll-area.css +1 -2
  64. package/src/components/segmented-control/segmented-control.css +8 -1
  65. package/src/components/select/select.css +2 -6
  66. package/src/components/sidebar/sidebar.css +12 -12
  67. package/src/components/sidebar-nav-tree/sidebar-nav-tree.css +8 -8
  68. package/src/components/slider/slider.css +6 -6
  69. package/src/components/switch/switch.css +3 -3
  70. package/src/components/table/table.css +7 -1
  71. package/src/components/tabs/tabs.css +15 -1
  72. package/src/components/textarea/textarea.css +2 -6
  73. package/src/components/toggle/toggle.css +5 -4
  74. package/src/components/toggle-group/toggle-group.css +4 -4
  75. package/src/media/media-lightbox/media-lightbox.css +15 -5
  76. package/src/styles/index.css +1 -0
  77. package/src/styles/utilities.css +2253 -0
  78. package/dist/chunk-7VSPECOH.js.map +0 -1
  79. package/dist/chunk-MXNO63TC.js.map +0 -1
  80. package/dist/chunk-STCXERLM.js.map +0 -1
@@ -1,8 +1,9 @@
1
- import { usePortalContainer, DestinationLink, DestinationIndicator } from './chunk-7VSPECOH.js';
1
+ import { DestinationLink, DestinationIndicator } from './chunk-R67OZVA2.js';
2
+ import { usePortalContainer } from './chunk-UPPHQLZ2.js';
2
3
  import { cn } from './chunk-AJLHJRK6.js';
3
- import { createContext, useContext, useState, useEffect, useMemo, useRef, useCallback, useLayoutEffect, createElement } from 'react';
4
+ import { createContext, useContext, useState, useEffect, useMemo, useRef, useCallback, Children, useLayoutEffect, createElement } from 'react';
4
5
  import { flushSync, createPortal } from 'react-dom';
5
- import { AnimatePresence, motion, usePresence, animate } from 'motion/react';
6
+ import { AnimatePresence, motion, motionValue, usePresence, animate } from 'motion/react';
6
7
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
8
  import { mergeProps } from '@base-ui/react/merge-props';
8
9
  import { useRender } from '@base-ui/react/use-render';
@@ -76,6 +77,38 @@ function resolveLabels(overrides) {
76
77
  return overrides ? { ...DEFAULT_MEDIA_LIGHTBOX_LABELS, ...overrides } : DEFAULT_MEDIA_LIGHTBOX_LABELS;
77
78
  }
78
79
 
80
+ // src/media/media-lightbox/reveal-origin.ts
81
+ function revealOrigin(element) {
82
+ element?.scrollIntoView?.({ behavior: "instant", block: "nearest", inline: "nearest" });
83
+ }
84
+ function revealReturnTarget(origin) {
85
+ if (!origin) {
86
+ return null;
87
+ }
88
+ revealOrigin(origin);
89
+ return isClippedByAncestor(origin) ? null : origin;
90
+ }
91
+ var CLIP_TOLERANCE = 1;
92
+ function clips(element) {
93
+ const style = getComputedStyle(element);
94
+ return style.overflowX !== "visible" || style.overflowY !== "visible";
95
+ }
96
+ function isClippedByAncestor(element) {
97
+ const rect = element.getBoundingClientRect();
98
+ const root = element.ownerDocument.documentElement;
99
+ const body = element.ownerDocument.body;
100
+ for (let ancestor = element.parentElement; ancestor && ancestor !== root && ancestor !== body; ancestor = ancestor.parentElement) {
101
+ if (!clips(ancestor)) {
102
+ continue;
103
+ }
104
+ const bounds = ancestor.getBoundingClientRect();
105
+ if (rect.left < bounds.left - CLIP_TOLERANCE || rect.top < bounds.top - CLIP_TOLERANCE || rect.right > bounds.right + CLIP_TOLERANCE || rect.bottom > bounds.bottom + CLIP_TOLERANCE) {
106
+ return true;
107
+ }
108
+ }
109
+ return false;
110
+ }
111
+
79
112
  // src/media/media-lightbox/motion.ts
80
113
  var MEDIA_SPRING = {
81
114
  type: "spring",
@@ -91,6 +124,14 @@ var PULL_SETTLE_SPRING = {
91
124
  mass: 1,
92
125
  restDelta: 0.01
93
126
  };
127
+ var PAGE_SPRING = {
128
+ type: "spring",
129
+ stiffness: 420,
130
+ damping: 40,
131
+ mass: 1,
132
+ restDelta: 5e-4,
133
+ restSpeed: 0.01
134
+ };
94
135
  var ZOOM_STEP_SPRING = {
95
136
  type: "spring",
96
137
  stiffness: 700,
@@ -206,11 +247,12 @@ function runMediaViewTransition({
206
247
  return false;
207
248
  }
208
249
  const root = document.documentElement;
250
+ const target = direction === "out" ? revealReturnTarget(origin) : origin;
209
251
  const claim = () => {
210
- if (origin) {
211
- origin.style.viewTransitionName = MEDIA_VIEW_TRANSITION_NAME;
212
- origin.setAttribute(MORPH_TARGET_ATTRIBUTE, "");
213
- claimedOrigins.add(origin);
252
+ if (target) {
253
+ target.style.viewTransitionName = MEDIA_VIEW_TRANSITION_NAME;
254
+ target.setAttribute(MORPH_TARGET_ATTRIBUTE, "");
255
+ claimedOrigins.add(target);
214
256
  }
215
257
  };
216
258
  const release = () => {
@@ -400,7 +442,7 @@ function LightboxPortal({ children, onExitComplete }) {
400
442
  if (typeof document === "undefined") {
401
443
  return null;
402
444
  }
403
- const content = open ? children : null;
445
+ const content = open ? Children.toArray(children) : null;
404
446
  return createPortal(
405
447
  viewTransition ? content : /* @__PURE__ */ jsx(AnimatePresence, { onExitComplete, children: content }),
406
448
  portalContainer ?? document.body
@@ -1282,212 +1324,6 @@ function usePullToDismiss({
1282
1324
  };
1283
1325
  }, [backdropRef, enabled, onDismiss, reducedMotion, rootRef, stageRef, trackRef]);
1284
1326
  }
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
1327
  var LightboxZoomOptionsRegistryContext = createContext(null);
1492
1328
  function LightboxZoomOptionsRegistryProvider({
1493
1329
  children,
@@ -1539,14 +1375,6 @@ function LightboxContent({
1539
1375
  stageRef,
1540
1376
  trackRef
1541
1377
  });
1542
- useSwipeIntent({
1543
- enabled: !isZoomed,
1544
- onIntent: (delta) => {
1545
- goTo(index + delta);
1546
- },
1547
- rootRef,
1548
- stageRef
1549
- });
1550
1378
  useEffect(() => {
1551
1379
  restoreFocusRef.current = document.activeElement;
1552
1380
  rootRef.current?.focus({ preventScroll: true });
@@ -1667,8 +1495,10 @@ function LightboxBackdrop({
1667
1495
  const viewTransition = transition === "view-transition";
1668
1496
  const defaultProps = {
1669
1497
  // 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),
1498
+ // a translucent blur would forbid. It portals next to `Content`, so it
1499
+ // needs `Content`'s fixed layer too: `absolute` left it under any
1500
+ // positioned page chrome with a z-index, such as a sticky header.
1501
+ className: cn("fixed inset-0 z-50 bg-[var(--a63-media-stage)]", className),
1672
1502
  "data-slot": "media-lightbox-backdrop",
1673
1503
  onClick: close
1674
1504
  };
@@ -1711,44 +1541,495 @@ function LightboxStatus({
1711
1541
  render
1712
1542
  });
1713
1543
  }
1714
- function useStageTransition({
1544
+
1545
+ // src/media/media-lightbox/track-physics.ts
1546
+ var AXIS_LOCK_THRESHOLD = 8;
1547
+ var SWIPE_DISTANCE_RATIO = 0.2;
1548
+ var SWIPE_DISTANCE_CAP = 120;
1549
+ var SWIPE_VELOCITY = 0.5;
1550
+ var RUBBER_BAND_COEFFICIENT = 0.55;
1551
+ function swipeDistanceThreshold(viewportWidth) {
1552
+ return Math.min(SWIPE_DISTANCE_CAP, (viewportWidth || SWIPE_DISTANCE_CAP) * SWIPE_DISTANCE_RATIO);
1553
+ }
1554
+ function rubberBand(overshoot, dimension) {
1555
+ if (overshoot <= 0 || dimension <= 0) {
1556
+ return 0;
1557
+ }
1558
+ return (1 - 1 / (overshoot * RUBBER_BAND_COEFFICIENT / dimension + 1)) * dimension;
1559
+ }
1560
+ function resistEdges(position, lastIndex, step) {
1561
+ if (position < 0) {
1562
+ return -rubberBand(-position * step, step) / step;
1563
+ }
1564
+ if (position > lastIndex) {
1565
+ return lastIndex + rubberBand((position - lastIndex) * step, step) / step;
1566
+ }
1567
+ return position;
1568
+ }
1569
+ function releaseTarget({
1570
+ distanceThreshold,
1715
1571
  index,
1572
+ lastIndex,
1573
+ position,
1574
+ startPosition,
1575
+ step,
1576
+ velocity
1577
+ }) {
1578
+ let target;
1579
+ if (Math.abs(velocity) > SWIPE_VELOCITY) {
1580
+ target = velocity > 0 ? Math.ceil(position) : Math.floor(position);
1581
+ } else {
1582
+ const moved = (position - startPosition) * step;
1583
+ if (Math.abs(moved) > distanceThreshold) {
1584
+ target = moved > 0 ? Math.ceil(position) : Math.floor(position);
1585
+ } else {
1586
+ target = Math.round(position);
1587
+ }
1588
+ }
1589
+ const nearest = Math.min(Math.max(target, index - 1), index + 1);
1590
+ return Math.min(Math.max(nearest, 0), Math.max(lastIndex, 0));
1591
+ }
1592
+ function trackTransform(position) {
1593
+ const offset = Number((-position).toFixed(5)) || 0;
1594
+ return `translate3d(calc(${offset} * (100% + var(--a63-media-lightbox-gap, var(--a63-space-4))) * var(--a63-media-lightbox-track-sign, 1)), 0, 0)`;
1595
+ }
1596
+ var NO_DRAG_SELECTOR = '[data-a63-no-drag], video, a, button:not([tabindex="-1"])';
1597
+ var WHEEL_DRIVE_THRESHOLD = 60;
1598
+ var WHEEL_QUIET_MS = 160;
1599
+ var WHEEL_DECAY_RATIO = 0.4;
1600
+ var WHEEL_RISE_MARGIN = 12;
1601
+ function measureStep(strip) {
1602
+ const gap = Number.parseFloat(getComputedStyle(strip).columnGap);
1603
+ const step = strip.offsetWidth + (Number.isFinite(gap) ? gap : 0);
1604
+ if (step > 0) {
1605
+ return step;
1606
+ }
1607
+ return typeof window === "undefined" ? 1 : window.innerWidth || 1;
1608
+ }
1609
+ function union(span, from, to) {
1610
+ const lo = Math.min(from, to, span?.[0] ?? Number.POSITIVE_INFINITY);
1611
+ const hi = Math.max(from, to, span?.[1] ?? Number.NEGATIVE_INFINITY);
1612
+ return [lo, hi];
1613
+ }
1614
+ function useSlideTrack({
1615
+ enabled,
1616
+ goTo,
1617
+ index,
1618
+ itemCount,
1619
+ mountRadius,
1716
1620
  reducedMotion,
1717
- timing
1621
+ rootRef,
1622
+ stripRef,
1623
+ trackRef
1718
1624
  }) {
1719
- const [outgoingIndex, setOutgoingIndex] = useState(null);
1720
- const previousIndexRef = useRef(index);
1721
- const timerRef = useRef(null);
1722
- const durationMs = LIGHTBOX_TIMING[timing].vtDurationMs;
1625
+ const [position] = useState(() => motionValue(index));
1626
+ const [span, setSpan] = useState(null);
1627
+ const [spanIndex, setSpanIndex] = useState(index);
1628
+ if (spanIndex !== index) {
1629
+ setSpanIndex(index);
1630
+ const animates = !reducedMotion && Math.abs(index - spanIndex) === 1;
1631
+ setSpan(animates ? union(span, spanIndex, index) : null);
1632
+ }
1633
+ const indexRef = useRef(index);
1634
+ indexRef.current = index;
1635
+ const goToRef = useRef(goTo);
1636
+ goToRef.current = goTo;
1637
+ const lastIndexRef = useRef(itemCount - 1);
1638
+ lastIndexRef.current = itemCount - 1;
1639
+ const reducedMotionRef = useRef(reducedMotion);
1640
+ reducedMotionRef.current = reducedMotion;
1641
+ const mountRadiusRef = useRef(mountRadius);
1642
+ mountRadiusRef.current = mountRadius;
1643
+ const animationRef = useRef(null);
1644
+ const targetRef = useRef(null);
1645
+ const committedIndexRef = useRef(index);
1646
+ const controlRef = useRef(null);
1647
+ useLayoutEffect(() => {
1648
+ const strip = stripRef.current;
1649
+ if (!strip) {
1650
+ return;
1651
+ }
1652
+ let moving = false;
1653
+ let pagingRoot = null;
1654
+ const setMoving = (next) => {
1655
+ if (next === moving) {
1656
+ return;
1657
+ }
1658
+ moving = next;
1659
+ strip.style.willChange = next ? "transform" : "";
1660
+ if (next) {
1661
+ pagingRoot = rootRef.current;
1662
+ }
1663
+ pagingRoot?.toggleAttribute("data-paging", next);
1664
+ };
1665
+ const unsubscribe = position.on("change", (value) => {
1666
+ strip.style.transform = trackTransform(value);
1667
+ });
1668
+ const stop = () => {
1669
+ animationRef.current?.stop();
1670
+ animationRef.current = null;
1671
+ targetRef.current = null;
1672
+ position.stop();
1673
+ };
1674
+ const rest = () => {
1675
+ setMoving(false);
1676
+ const current = indexRef.current;
1677
+ position.jump(current);
1678
+ strip.style.transform = trackTransform(current);
1679
+ setSpan((value) => value === null ? value : null);
1680
+ };
1681
+ const settle = (target, velocity) => {
1682
+ stop();
1683
+ if (reducedMotionRef.current) {
1684
+ position.jump(target);
1685
+ if (target === indexRef.current) {
1686
+ rest();
1687
+ return;
1688
+ }
1689
+ requestAnimationFrame(() => {
1690
+ if (targetRef.current === null && !animationRef.current) {
1691
+ rest();
1692
+ }
1693
+ });
1694
+ return;
1695
+ }
1696
+ setMoving(true);
1697
+ targetRef.current = target;
1698
+ const controls = animate(position, target, {
1699
+ ...PAGE_SPRING,
1700
+ ...velocity === void 0 ? {} : { velocity },
1701
+ onComplete: () => {
1702
+ if (animationRef.current !== controls) {
1703
+ return;
1704
+ }
1705
+ animationRef.current = null;
1706
+ targetRef.current = null;
1707
+ if (Math.abs(position.get() - indexRef.current) > 1e-3) {
1708
+ settle(indexRef.current);
1709
+ return;
1710
+ }
1711
+ rest();
1712
+ }
1713
+ });
1714
+ animationRef.current = controls;
1715
+ };
1716
+ controlRef.current = {
1717
+ halt: () => {
1718
+ stop();
1719
+ setMoving(true);
1720
+ },
1721
+ redraw: () => {
1722
+ strip.style.transform = trackTransform(position.get());
1723
+ },
1724
+ rest: () => {
1725
+ stop();
1726
+ rest();
1727
+ },
1728
+ settle
1729
+ };
1730
+ return () => {
1731
+ controlRef.current = null;
1732
+ stop();
1733
+ unsubscribe();
1734
+ setMoving(false);
1735
+ };
1736
+ }, [position, rootRef, stripRef]);
1723
1737
  useLayoutEffect(() => {
1724
- const previous = previousIndexRef.current;
1725
- if (index === previous) {
1738
+ const previous = committedIndexRef.current;
1739
+ if (previous === index) {
1726
1740
  return;
1727
1741
  }
1728
- previousIndexRef.current = index;
1729
- if (timerRef.current !== null) {
1730
- clearTimeout(timerRef.current);
1731
- timerRef.current = null;
1742
+ committedIndexRef.current = index;
1743
+ const control = controlRef.current;
1744
+ if (!control) {
1745
+ return;
1732
1746
  }
1733
- if (reducedMotion) {
1734
- setOutgoingIndex(null);
1747
+ if (targetRef.current === index && animationRef.current) {
1748
+ control.redraw();
1749
+ return;
1750
+ }
1751
+ if (reducedMotion || Math.abs(index - previous) !== 1) {
1752
+ control.rest();
1753
+ return;
1754
+ }
1755
+ control.redraw();
1756
+ control.settle(index);
1757
+ }, [index, reducedMotion]);
1758
+ useEffect(() => {
1759
+ const track = trackRef.current;
1760
+ const strip = stripRef.current;
1761
+ if (!enabled || !track || !strip) {
1735
1762
  return;
1736
1763
  }
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);
1764
+ const settle = (target, velocityPxPerMs, step2) => {
1765
+ const control = controlRef.current;
1766
+ if (!control) {
1767
+ return;
1747
1768
  }
1748
- },
1749
- []
1750
- );
1751
- return { outgoingIndex };
1769
+ control.settle(target, velocityPxPerMs / step2 * 1e3);
1770
+ if (target !== indexRef.current) {
1771
+ goToRef.current(target);
1772
+ }
1773
+ };
1774
+ const release = (startPosition2, velocity2, step2) => {
1775
+ const target = releaseTarget({
1776
+ distanceThreshold: swipeDistanceThreshold(window.innerWidth),
1777
+ index: indexRef.current,
1778
+ lastIndex: lastIndexRef.current,
1779
+ position: position.get(),
1780
+ startPosition: startPosition2,
1781
+ step: step2,
1782
+ velocity: velocity2
1783
+ });
1784
+ settle(target, velocity2, step2);
1785
+ };
1786
+ const catchStrip = () => {
1787
+ if (!animationRef.current) {
1788
+ return false;
1789
+ }
1790
+ controlRef.current?.halt();
1791
+ return true;
1792
+ };
1793
+ const mountNeighbours = () => {
1794
+ if (mountRadiusRef.current >= 1) {
1795
+ return;
1796
+ }
1797
+ const current = indexRef.current;
1798
+ setSpan((value) => union(value, current - 1, current + 1));
1799
+ };
1800
+ let pointerId = null;
1801
+ let startX = 0;
1802
+ let startY = 0;
1803
+ let startPosition = 0;
1804
+ let step = 1;
1805
+ let rtl = false;
1806
+ let axis = null;
1807
+ let caught = false;
1808
+ const velocity = createVelocityTracker();
1809
+ let suppressNextClick = false;
1810
+ let suppressTimer = null;
1811
+ const forwardOf = (clientX) => rtl ? clientX - startX : startX - clientX;
1812
+ const handlePointerDown = (event) => {
1813
+ if (event.button !== 0) {
1814
+ return;
1815
+ }
1816
+ if (pointerId !== null) {
1817
+ if (axis === "horizontal" || caught) {
1818
+ controlRef.current?.settle(indexRef.current);
1819
+ }
1820
+ pointerId = null;
1821
+ axis = null;
1822
+ caught = false;
1823
+ return;
1824
+ }
1825
+ if (event.target?.closest(NO_DRAG_SELECTOR)) {
1826
+ return;
1827
+ }
1828
+ pointerId = event.pointerId;
1829
+ startX = event.clientX;
1830
+ startY = event.clientY;
1831
+ axis = null;
1832
+ caught = catchStrip();
1833
+ startPosition = position.get();
1834
+ step = measureStep(strip);
1835
+ rtl = isRtlTrack(track);
1836
+ velocity.reset(0, event.timeStamp);
1837
+ };
1838
+ const handlePointerMove = (event) => {
1839
+ if (event.pointerId !== pointerId) {
1840
+ return;
1841
+ }
1842
+ const dx = event.clientX - startX;
1843
+ const dy = event.clientY - startY;
1844
+ if (axis === null) {
1845
+ if (Math.abs(dx) < AXIS_LOCK_THRESHOLD && Math.abs(dy) < AXIS_LOCK_THRESHOLD) {
1846
+ return;
1847
+ }
1848
+ axis = Math.abs(dx) > Math.abs(dy) ? "horizontal" : "vertical";
1849
+ if (axis === "vertical") {
1850
+ pointerId = null;
1851
+ if (caught) {
1852
+ caught = false;
1853
+ controlRef.current?.settle(Math.round(position.get()));
1854
+ }
1855
+ return;
1856
+ }
1857
+ controlRef.current?.halt();
1858
+ mountNeighbours();
1859
+ track.style.userSelect = "none";
1860
+ }
1861
+ if (event.cancelable) {
1862
+ event.preventDefault();
1863
+ }
1864
+ const forward = forwardOf(event.clientX);
1865
+ velocity.push(forward, event.timeStamp);
1866
+ position.set(resistEdges(startPosition + forward / step, lastIndexRef.current, step));
1867
+ };
1868
+ const endGesture = (event, cancelled) => {
1869
+ if (event.pointerId !== pointerId) {
1870
+ return;
1871
+ }
1872
+ const wasHorizontal = axis === "horizontal";
1873
+ const wasCaught = caught;
1874
+ pointerId = null;
1875
+ axis = null;
1876
+ caught = false;
1877
+ track.style.userSelect = "";
1878
+ if (wasHorizontal) {
1879
+ suppressNextClick = true;
1880
+ if (suppressTimer) {
1881
+ clearTimeout(suppressTimer);
1882
+ }
1883
+ suppressTimer = setTimeout(() => {
1884
+ suppressNextClick = false;
1885
+ }, 0);
1886
+ }
1887
+ if (!wasHorizontal && !wasCaught) {
1888
+ return;
1889
+ }
1890
+ if (cancelled) {
1891
+ release(startPosition, 0, step);
1892
+ return;
1893
+ }
1894
+ velocity.push(forwardOf(event.clientX), event.timeStamp);
1895
+ release(startPosition, velocity.velocity(), step);
1896
+ };
1897
+ const handlePointerUp = (event) => {
1898
+ endGesture(event, false);
1899
+ };
1900
+ const handlePointerCancel = (event) => {
1901
+ endGesture(event, true);
1902
+ };
1903
+ const handleClickCapture = (event) => {
1904
+ if (!suppressNextClick) {
1905
+ return;
1906
+ }
1907
+ suppressNextClick = false;
1908
+ if (suppressTimer) {
1909
+ clearTimeout(suppressTimer);
1910
+ suppressTimer = null;
1911
+ }
1912
+ event.preventDefault();
1913
+ event.stopPropagation();
1914
+ };
1915
+ let wheelMode = "idle";
1916
+ let wheelStart = 0;
1917
+ let wheelForward = 0;
1918
+ let wheelStep = 1;
1919
+ let wheelRtl = false;
1920
+ let wheelPeak = 0;
1921
+ let wheelCoasting = false;
1922
+ let wheelFloor = Number.POSITIVE_INFINITY;
1923
+ const wheelVelocity = createVelocityTracker();
1924
+ let wheelQuietTimer = null;
1925
+ const finishWheel = (useVelocity) => {
1926
+ release(wheelStart, useVelocity ? wheelVelocity.velocity() : 0, wheelStep);
1927
+ };
1928
+ const armWheelQuietTimer = () => {
1929
+ if (wheelQuietTimer) {
1930
+ clearTimeout(wheelQuietTimer);
1931
+ }
1932
+ wheelQuietTimer = setTimeout(() => {
1933
+ wheelQuietTimer = null;
1934
+ if (wheelMode === "tracking") {
1935
+ finishWheel(false);
1936
+ }
1937
+ wheelMode = "idle";
1938
+ }, WHEEL_QUIET_MS);
1939
+ };
1940
+ const handleWheel = (event) => {
1941
+ if (event.ctrlKey || Math.abs(event.deltaX) <= Math.abs(event.deltaY)) {
1942
+ return;
1943
+ }
1944
+ if (event.cancelable) {
1945
+ event.preventDefault();
1946
+ }
1947
+ armWheelQuietTimer();
1948
+ const magnitude = Math.abs(event.deltaX);
1949
+ if (wheelMode === "spent") {
1950
+ if (!wheelCoasting) {
1951
+ if (magnitude > wheelPeak) {
1952
+ wheelPeak = magnitude;
1953
+ return;
1954
+ }
1955
+ if (magnitude >= wheelPeak * WHEEL_DECAY_RATIO) {
1956
+ return;
1957
+ }
1958
+ wheelCoasting = true;
1959
+ wheelFloor = magnitude;
1960
+ return;
1961
+ }
1962
+ if (magnitude < wheelFloor) {
1963
+ wheelFloor = magnitude;
1964
+ return;
1965
+ }
1966
+ if (magnitude - wheelFloor <= WHEEL_RISE_MARGIN) {
1967
+ return;
1968
+ }
1969
+ wheelMode = "idle";
1970
+ }
1971
+ if (wheelMode === "idle") {
1972
+ controlRef.current?.halt();
1973
+ mountNeighbours();
1974
+ wheelMode = "tracking";
1975
+ wheelStart = position.get();
1976
+ wheelForward = 0;
1977
+ wheelPeak = 0;
1978
+ wheelCoasting = false;
1979
+ wheelFloor = Number.POSITIVE_INFINITY;
1980
+ wheelStep = measureStep(strip);
1981
+ wheelRtl = isRtlTrack(track);
1982
+ wheelVelocity.reset(0, event.timeStamp);
1983
+ }
1984
+ const driven = Math.abs(wheelForward) > WHEEL_DRIVE_THRESHOLD;
1985
+ if (driven && magnitude > wheelPeak) {
1986
+ wheelPeak = magnitude;
1987
+ } else if (driven && magnitude < wheelPeak * WHEEL_DECAY_RATIO) {
1988
+ finishWheel(true);
1989
+ wheelMode = "spent";
1990
+ wheelCoasting = true;
1991
+ wheelFloor = magnitude;
1992
+ return;
1993
+ }
1994
+ wheelForward += wheelRtl ? -event.deltaX : event.deltaX;
1995
+ wheelVelocity.push(wheelForward, event.timeStamp);
1996
+ const anchor = Math.round(wheelStart);
1997
+ const raw = wheelStart + wheelForward / wheelStep;
1998
+ const bounded = Math.min(Math.max(raw, anchor - 1), anchor + 1);
1999
+ position.set(resistEdges(bounded, lastIndexRef.current, wheelStep));
2000
+ if (bounded !== raw) {
2001
+ finishWheel(true);
2002
+ wheelMode = "spent";
2003
+ wheelCoasting = false;
2004
+ wheelPeak = Math.max(wheelPeak, magnitude);
2005
+ }
2006
+ };
2007
+ track.addEventListener("pointerdown", handlePointerDown);
2008
+ window.addEventListener("pointermove", handlePointerMove, { passive: false });
2009
+ window.addEventListener("pointerup", handlePointerUp);
2010
+ window.addEventListener("pointercancel", handlePointerCancel);
2011
+ track.addEventListener("click", handleClickCapture, true);
2012
+ track.addEventListener("wheel", handleWheel, { passive: false });
2013
+ return () => {
2014
+ if (wheelQuietTimer) {
2015
+ clearTimeout(wheelQuietTimer);
2016
+ }
2017
+ if (suppressTimer) {
2018
+ clearTimeout(suppressTimer);
2019
+ }
2020
+ if (axis === "horizontal" || caught || wheelMode === "tracking") {
2021
+ controlRef.current?.settle(indexRef.current);
2022
+ }
2023
+ track.style.userSelect = "";
2024
+ track.removeEventListener("pointerdown", handlePointerDown);
2025
+ window.removeEventListener("pointermove", handlePointerMove);
2026
+ window.removeEventListener("pointerup", handlePointerUp);
2027
+ window.removeEventListener("pointercancel", handlePointerCancel);
2028
+ track.removeEventListener("click", handleClickCapture, true);
2029
+ track.removeEventListener("wheel", handleWheel);
2030
+ };
2031
+ }, [enabled, position, stripRef, trackRef]);
2032
+ return { span };
1752
2033
  }
1753
2034
  function LightboxViewport({
1754
2035
  className,
@@ -1775,12 +2056,24 @@ function LightboxSlides({
1775
2056
  render,
1776
2057
  ...props
1777
2058
  }) {
1778
- const { trackRef } = useLightboxRefs();
1779
- const { index } = useLightboxState();
1780
- const { items, labels, preload, reducedMotion, timing } = useLightboxConfig();
2059
+ const { rootRef, trackRef } = useLightboxRefs();
2060
+ const { goTo, index, isZoomed, itemCount } = useLightboxState();
2061
+ const { items, labels, preload, reducedMotion } = useLightboxConfig();
2062
+ const stripRef = useRef(null);
1781
2063
  const [livePreload, setLivePreload] = useState(0);
1782
2064
  const [trackDirection, setTrackDirection] = useState("ltr");
1783
- const { outgoingIndex } = useStageTransition({ index, reducedMotion, timing });
2065
+ const { span } = useSlideTrack({
2066
+ // A drag on zoomed media is a pan, not a page turn.
2067
+ enabled: !isZoomed,
2068
+ goTo,
2069
+ index,
2070
+ itemCount,
2071
+ mountRadius: livePreload,
2072
+ reducedMotion,
2073
+ rootRef,
2074
+ stripRef,
2075
+ trackRef
2076
+ });
1784
2077
  useEffect(() => {
1785
2078
  if (preload <= 0) {
1786
2079
  return;
@@ -1802,16 +2095,35 @@ function LightboxSlides({
1802
2095
  setTrackDirection(isRtlTrack(track) ? "rtl" : "ltr");
1803
2096
  }
1804
2097
  }, [trackRef]);
2098
+ const strip = /* @__PURE__ */ jsx(
2099
+ "div",
2100
+ {
2101
+ className: cn(
2102
+ "flex h-full w-full",
2103
+ "gap-[var(--a63-media-lightbox-gap,var(--a63-space-4))]",
2104
+ // The transform is physical; this flips it for a strip that runs
2105
+ // right to left, so the position arithmetic stays in reading order.
2106
+ "[--a63-media-lightbox-track-sign:1] rtl:[--a63-media-lightbox-track-sign:-1]"
2107
+ ),
2108
+ "data-slot": "media-lightbox-strip",
2109
+ ref: stripRef,
2110
+ style: { transform: trackTransform(index) },
2111
+ children: items.map((item, slideIndex) => {
2112
+ const isActive = slideIndex === index;
2113
+ const isNear = isActive || Math.abs(slideIndex - index) <= livePreload || span !== null && slideIndex >= span[0] && slideIndex <= span[1];
2114
+ const slide = { isActive, isNear, item, slideIndex };
2115
+ return /* @__PURE__ */ jsx(LightboxSlideContext.Provider, { value: slide, children: children(slide) }, item.id);
2116
+ })
2117
+ }
2118
+ );
1805
2119
  const defaultProps = {
1806
2120
  "aria-label": labels.gallery,
1807
2121
  "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),
2122
+ children: strip,
2123
+ // `touch-none`: the browser must not start a pan of its own under a drag
2124
+ // that is paging, pulling or pinching the photo. Each of those is handled
2125
+ // here, and a browser pan would cancel the pointer mid-gesture.
2126
+ className: cn("relative h-full w-full touch-none overflow-hidden", className),
1815
2127
  "data-active-index": index,
1816
2128
  "data-direction": trackDirection,
1817
2129
  "data-slot": "media-lightbox-track",
@@ -1836,27 +2148,16 @@ function LightboxSlide({
1836
2148
  throw new Error("Lightbox.Slide must be rendered inside Lightbox.Slides.");
1837
2149
  }
1838
2150
  const { isActive, item, slideIndex } = slide;
1839
- const { items, labels, reducedMotion, timing } = useLightboxConfig();
2151
+ const { items, labels } = useLightboxConfig();
1840
2152
  const hasThumbnails = useLightboxThumbnailsPresence();
1841
2153
  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
2154
  const defaultProps = {
1854
2155
  "aria-label": showThumbnails ? void 0 : `${item.title} \u2014 ${labels.position(slideIndex, items.length)}`,
1855
2156
  "aria-labelledby": showThumbnails ? `a63-media-lightbox-thumb-${item.id}` : void 0,
1856
2157
  "aria-roledescription": labels.slide,
1857
2158
  children,
1858
2159
  className: cn(
1859
- "absolute inset-0 flex h-full w-full items-center justify-center",
2160
+ "relative flex h-full w-full shrink-0 items-center justify-center",
1860
2161
  // A size container, so the frame can size itself against the slide in
1861
2162
  // *both* axes at once. Pinning one axis and letting the aspect ratio
1862
2163
  // drive the other only fits one orientation: pin the height and a photo
@@ -1865,8 +2166,9 @@ function LightboxSlide({
1865
2166
  // the frame both of the slide's dimensions, so it can take the smaller
1866
2167
  // of the two fits and land on the photo's shape either way.
1867
2168
  "[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.
2169
+ // Only the active slide is ever hit-tested. A neighbour a drag has half
2170
+ // revealed is still only a neighbour; a press on it lands on the track,
2171
+ // which is where catching a moving strip belongs.
1870
2172
  !isActive && "pointer-events-none",
1871
2173
  className
1872
2174
  ),
@@ -1877,8 +2179,7 @@ function LightboxSlide({
1877
2179
  // `inert` also drops the slide out of the tab order and out of
1878
2180
  // find-in-page, which `aria-hidden` alone does not.
1879
2181
  inert: !isActive,
1880
- role: showThumbnails ? "tabpanel" : "group",
1881
- style
2182
+ role: showThumbnails ? "tabpanel" : "group"
1882
2183
  };
1883
2184
  return useRender({
1884
2185
  defaultTagName: "div",
@@ -2105,12 +2406,15 @@ function useMediaAspect(thumbSrc, src) {
2105
2406
  }, [src, thumbSrc]);
2106
2407
  return aspect;
2107
2408
  }
2108
- function useOriginZoom(origin, enabled) {
2409
+ function useOriginZoom(origin, enabled, isActive) {
2109
2410
  const mediaRef = useRef(null);
2110
2411
  const [isPresent, safeToRemove] = usePresence();
2412
+ const isActiveRef = useRef(isActive);
2413
+ isActiveRef.current = isActive;
2414
+ const openingZoomRef = useRef(isActive);
2111
2415
  useLayoutEffect(() => {
2112
2416
  const media = mediaRef.current;
2113
- if (!media || !enabled) {
2417
+ if (!media || !enabled || !isPresent || !isActiveRef.current || !openingZoomRef.current) {
2114
2418
  return;
2115
2419
  }
2116
2420
  media.style.opacity = "0";
@@ -2127,6 +2431,7 @@ function useOriginZoom(origin, enabled) {
2127
2431
  }
2128
2432
  const morph = measureOriginMorph(media, box, origin ?? null);
2129
2433
  media.style.opacity = "1";
2434
+ openingZoomRef.current = false;
2130
2435
  if (morph) {
2131
2436
  media.style.transformOrigin = "center";
2132
2437
  media.style.willChange = "transform";
@@ -2164,19 +2469,20 @@ function useOriginZoom(origin, enabled) {
2164
2469
  cancelled = true;
2165
2470
  observer.disconnect();
2166
2471
  };
2167
- }, [enabled, origin]);
2472
+ }, [enabled, isPresent, origin]);
2168
2473
  useEffect(() => {
2169
2474
  const media = mediaRef.current;
2170
2475
  if (isPresent) {
2171
2476
  return;
2172
2477
  }
2173
- if (!media || !enabled) {
2478
+ if (!media || !enabled || !isActiveRef.current) {
2174
2479
  safeToRemove?.();
2175
2480
  return;
2176
2481
  }
2177
2482
  clearOriginMorph(media);
2483
+ const target = revealReturnTarget(origin);
2178
2484
  const box = media.getBoundingClientRect();
2179
- const morph = box.width > 0 ? measureOriginMorph(media, box, origin ?? null) : null;
2485
+ const morph = box.width > 0 ? measureOriginMorph(media, box, target) : null;
2180
2486
  const animation = morph ? (() => {
2181
2487
  media.style.transformOrigin = "center";
2182
2488
  media.style.willChange = "transform";
@@ -2214,7 +2520,8 @@ function LightboxFrame({
2214
2520
  const activeAspect = useMediaAspect(itemThumb, itemSrc);
2215
2521
  const frameRef = useOriginZoom(
2216
2522
  origin,
2217
- !reducedMotion && !viewTransition && (!itemThumb || activeAspect !== void 0)
2523
+ !reducedMotion && !viewTransition && (!itemThumb || activeAspect !== void 0),
2524
+ isActive
2218
2525
  );
2219
2526
  const slideAspect = activeAspect;
2220
2527
  const defaultProps = {
@@ -2268,7 +2575,7 @@ function LightboxFrame({
2268
2575
  return useRender({
2269
2576
  defaultTagName: "div",
2270
2577
  props: mergeProps(defaultProps, props),
2271
- ref: [isActive ? mediaRef : null, isActive ? frameRef : null, ref ?? null],
2578
+ ref: [isActive ? mediaRef : null, frameRef, ref ?? null],
2272
2579
  render: render ?? /* @__PURE__ */ jsx(
2273
2580
  motion.div,
2274
2581
  {
@@ -2740,6 +3047,6 @@ var Lightbox = {
2740
3047
  ZoomOut: LightboxZoomOut
2741
3048
  };
2742
3049
 
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
3050
+ export { AXIS_LOCK_THRESHOLD, 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, revealOrigin, runMediaViewTransition, supportsViewTransitions, useLightboxConfig, useLightboxRefs, useLightboxSlide, useLightboxState, useOptionalLightboxConfig, useReducedMotion };
3051
+ //# sourceMappingURL=chunk-X5L5DEUZ.js.map
3052
+ //# sourceMappingURL=chunk-X5L5DEUZ.js.map