@cjlapao/ui-kit 0.2.24 → 0.2.26

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.
package/dist/index.js CHANGED
@@ -20956,6 +20956,17 @@ function StackCarousel({
20956
20956
  swipe = true,
20957
20957
  showNavigators = true,
20958
20958
  showStatus = true,
20959
+ loop = true,
20960
+ expandable = false,
20961
+ expanded,
20962
+ defaultExpanded = false,
20963
+ onExpandedChange,
20964
+ showExpandButton = false,
20965
+ expandOnHover = false,
20966
+ hoverExpandDelay = 2e3,
20967
+ hoverCollapseDelay = 500,
20968
+ expandLabel = "Expand stack",
20969
+ collapseLabel = "Collapse stack",
20959
20970
  ariaLabel = "Card stack",
20960
20971
  previousLabel = "Previous item",
20961
20972
  nextLabel = "Next item",
@@ -20968,12 +20979,51 @@ function StackCarousel({
20968
20979
  transparency,
20969
20980
  className = "",
20970
20981
  onKeyDown,
20982
+ onPointerEnter,
20983
+ onPointerMove,
20984
+ onPointerLeave,
20985
+ onWheelCapture,
20971
20986
  style,
20972
20987
  ...rest
20973
20988
  }) {
20974
20989
  const [internalIndex, setInternalIndex] = useState22(defaultActiveIndex);
20975
- const index = wrap(Number.isFinite(activeIndex ?? internalIndex) ? activeIndex ?? internalIndex : 0, items.length);
20976
- const layers = Math.min(items.length, Math.max(1, Math.min(3, Math.trunc(visibleCount) || 1)));
20990
+ const [internalExpanded, setInternalExpanded] = useState22(defaultExpanded);
20991
+ const isExpanded = expandable && (expanded ?? internalExpanded);
20992
+ const hoverTimer = useRef18(null);
20993
+ const collapseTimer = useRef18(null);
20994
+ const hoverOpened = useRef18(false);
20995
+ const setExpanded = useCallback12((value) => {
20996
+ if (expanded === void 0) setInternalExpanded(value);
20997
+ onExpandedChange?.(value);
20998
+ }, [expanded, onExpandedChange]);
20999
+ const clearHover = useCallback12(() => {
21000
+ if (hoverTimer.current !== null) clearTimeout(hoverTimer.current);
21001
+ hoverTimer.current = null;
21002
+ }, []);
21003
+ const clearCollapse = useCallback12(() => {
21004
+ if (collapseTimer.current !== null) clearTimeout(collapseTimer.current);
21005
+ collapseTimer.current = null;
21006
+ }, []);
21007
+ useEffect14(() => {
21008
+ clearHover();
21009
+ clearCollapse();
21010
+ return () => {
21011
+ clearHover();
21012
+ clearCollapse();
21013
+ };
21014
+ }, [expandable, expandOnHover, hoverExpandDelay, hoverCollapseDelay, isExpanded, clearHover, clearCollapse]);
21015
+ const armHover = (event) => {
21016
+ clearHover();
21017
+ clearCollapse();
21018
+ if (!expandable || !expandOnHover || isExpanded || event?.pointerType === "touch") return;
21019
+ hoverTimer.current = setTimeout(() => {
21020
+ hoverOpened.current = true;
21021
+ setExpanded(true);
21022
+ }, Math.max(0, Number.isFinite(hoverExpandDelay) ? hoverExpandDelay : 2e3));
21023
+ };
21024
+ const normalize = useCallback12((value) => loop ? wrap(value, items.length) : Math.max(0, Math.min(items.length - 1, Math.trunc(value))), [loop, items.length]);
21025
+ const index = normalize(Number.isFinite(activeIndex ?? internalIndex) ? activeIndex ?? internalIndex : 0);
21026
+ const layers = Math.min(loop ? items.length : items.length - index, Math.max(1, Math.min(3, Math.trunc(visibleCount) || 1)));
20977
21027
  const offset = Math.max(0, Number.isFinite(stackOffset) ? stackOffset : 12);
20978
21028
  const rootRef = useRef18(null);
20979
21029
  const measureRef = useRef18(null);
@@ -20984,16 +21034,20 @@ function StackCarousel({
20984
21034
  const wheelDelta = useRef18(0);
20985
21035
  const touch = useRef18(null);
20986
21036
  const label = (i) => getItemLabel?.(items[i], i) ?? `Item ${i + 1}`;
21037
+ useLayoutEffect7(() => {
21038
+ if (!isExpanded && document.activeElement instanceof Element && rootRef.current?.contains(document.activeElement) && document.activeElement.closest("[inert]"))
21039
+ rootRef.current.focus({ preventScroll: true });
21040
+ }, [isExpanded]);
20987
21041
  const navigate = useCallback12((next, focus = false) => {
20988
21042
  if (items.length < 2) return;
20989
- const normalized = wrap(next, items.length);
21043
+ const normalized = normalize(next);
20990
21044
  if (normalized === index) return;
20991
21045
  if (focus || measureRef.current?.contains(document.activeElement)) {
20992
21046
  rootRef.current?.focus({ preventScroll: true });
20993
21047
  }
20994
21048
  if (activeIndex === void 0) setInternalIndex(normalized);
20995
21049
  onActiveIndexChange?.(normalized);
20996
- }, [items.length, index, activeIndex, onActiveIndexChange]);
21050
+ }, [items.length, index, activeIndex, onActiveIndexChange, normalize]);
20997
21051
  useLayoutEffect7(() => {
20998
21052
  const old = previousIndex.current;
20999
21053
  previousIndex.current = index;
@@ -21014,7 +21068,7 @@ function StackCarousel({
21014
21068
  const observer = new ResizeObserver(measure);
21015
21069
  observer.observe(element);
21016
21070
  return () => observer.disconnect();
21017
- }, [index, items.length, items[index]]);
21071
+ }, [index, items.length, items[index], isExpanded]);
21018
21072
  const canScrollInside = useCallback12((target, delta) => {
21019
21073
  let element = target instanceof Element ? target : null;
21020
21074
  while (element && element !== rootRef.current) {
@@ -21026,7 +21080,7 @@ function StackCarousel({
21026
21080
  }, []);
21027
21081
  useEffect14(() => {
21028
21082
  const root = rootRef.current;
21029
- if (!root || !swipe || items.length < 2) return;
21083
+ if (!root || !swipe || isExpanded || items.length < 2) return;
21030
21084
  const handleMove = (event) => {
21031
21085
  const start = touch.current;
21032
21086
  if (!start || event.touches.length !== 1) return;
@@ -21036,10 +21090,10 @@ function StackCarousel({
21036
21090
  };
21037
21091
  root.addEventListener("touchmove", handleMove, { passive: false });
21038
21092
  return () => root.removeEventListener("touchmove", handleMove);
21039
- }, [swipe, items.length, canScrollInside]);
21093
+ }, [swipe, isExpanded, items.length, canScrollInside]);
21040
21094
  useEffect14(() => {
21041
21095
  const root = rootRef.current;
21042
- if (!root || !wheel || items.length < 2) return;
21096
+ if (!root || !wheel || isExpanded || items.length < 2) return;
21043
21097
  const handleWheel = (event) => {
21044
21098
  if (event.ctrlKey || event.metaKey || !event.deltaY || Math.abs(event.deltaX) > Math.abs(event.deltaY) || canScrollInside(event.target, event.deltaY)) return;
21045
21099
  event.preventDefault();
@@ -21055,11 +21109,11 @@ function StackCarousel({
21055
21109
  };
21056
21110
  root.addEventListener("wheel", handleWheel, { passive: false });
21057
21111
  return () => root.removeEventListener("wheel", handleWheel);
21058
- }, [wheel, items.length, index, navigate, canScrollInside]);
21059
- const visible = Array.from({ length: layers }, (_, rank) => wrap(index + rank, items.length));
21112
+ }, [wheel, isExpanded, items.length, index, navigate, canScrollInside]);
21113
+ const visible = isExpanded ? items.map((_, i) => i) : Array.from({ length: layers }, (_, rank) => normalize(index + rank));
21060
21114
  const rendered = [...visible];
21061
21115
  const transitionFrom = previousIndex.current !== index ? previousIndex.current : outgoing;
21062
- if (transitionFrom !== null && transitionFrom < items.length && !rendered.includes(transitionFrom)) rendered.push(transitionFrom);
21116
+ if (!isExpanded && transitionFrom !== null && transitionFrom < items.length && !rendered.includes(transitionFrom)) rendered.push(transitionFrom);
21063
21117
  return (
21064
21118
  // A focusable carousel region owns arrow navigation; child controls keep
21065
21119
  // their native key handling. It is a region rather than a single button.
@@ -21075,9 +21129,31 @@ function StackCarousel({
21075
21129
  tabIndex: 0,
21076
21130
  className: `min-w-0 outline-none focus-visible:ring-2 focus-visible:ring-blue-400 rounded-lg ${className}`,
21077
21131
  style,
21132
+ onPointerEnter: (event) => {
21133
+ onPointerEnter?.(event);
21134
+ if (!event.defaultPrevented) armHover(event);
21135
+ },
21136
+ onPointerMove: (event) => {
21137
+ onPointerMove?.(event);
21138
+ if (!event.defaultPrevented) armHover(event);
21139
+ },
21140
+ onWheelCapture: (event) => {
21141
+ onWheelCapture?.(event);
21142
+ if (event.deltaX || event.deltaY) armHover();
21143
+ },
21144
+ onPointerLeave: (event) => {
21145
+ onPointerLeave?.(event);
21146
+ clearHover();
21147
+ clearCollapse();
21148
+ if (hoverOpened.current) collapseTimer.current = setTimeout(() => {
21149
+ collapseTimer.current = null;
21150
+ hoverOpened.current = false;
21151
+ setExpanded(false);
21152
+ }, Math.max(0, Number.isFinite(hoverCollapseDelay) ? hoverCollapseDelay : 500));
21153
+ },
21078
21154
  onKeyDown: (event) => {
21079
21155
  onKeyDown?.(event);
21080
- if (event.defaultPrevented || event.target !== event.currentTarget) return;
21156
+ if (event.defaultPrevented || event.target !== event.currentTarget || isExpanded) return;
21081
21157
  const next = event.key === "ArrowDown" || event.key === "ArrowRight" ? index + 1 : event.key === "ArrowUp" || event.key === "ArrowLeft" ? index - 1 : event.key === "Home" ? 0 : event.key === "End" ? items.length - 1 : null;
21082
21158
  if (next !== null && items.length > 1) {
21083
21159
  event.preventDefault();
@@ -21090,9 +21166,10 @@ function StackCarousel({
21090
21166
  {
21091
21167
  className: "relative transition-[height] duration-300 ease-out motion-reduce:transition-none",
21092
21168
  "data-stack-carousel-track": true,
21093
- style: { height: height ? height + Math.max(0, layers - 1) * offset : void 0 },
21169
+ "data-expanded": isExpanded,
21170
+ style: { height: !isExpanded && height ? height + Math.max(0, layers - 1) * offset : void 0 },
21094
21171
  onTouchStart: (event) => {
21095
- if (!swipe || event.touches.length !== 1) {
21172
+ if (!swipe || isExpanded || event.touches.length !== 1) {
21096
21173
  touch.current = null;
21097
21174
  return;
21098
21175
  }
@@ -21112,7 +21189,7 @@ function StackCarousel({
21112
21189
  },
21113
21190
  children: rendered.map((i) => {
21114
21191
  const rank = visible.indexOf(i);
21115
- const active = rank === 0;
21192
+ const active = isExpanded || rank === 0;
21116
21193
  const leaving = rank < 0;
21117
21194
  return /* @__PURE__ */ jsxs90(
21118
21195
  "div",
@@ -21120,19 +21197,20 @@ function StackCarousel({
21120
21197
  "data-stack-rank": rank,
21121
21198
  className: `w-full origin-top transition-[transform,opacity,height] duration-300 ease-out motion-reduce:transition-none ${getSurfaceCornerClass(corner)}`,
21122
21199
  style: {
21123
- position: height || !active ? "absolute" : "relative",
21200
+ position: isExpanded ? "relative" : height || !active ? "absolute" : "relative",
21124
21201
  top: 0,
21125
- zIndex: leaving ? 4 : 3 - rank,
21202
+ marginTop: isExpanded && rank > 0 ? offset : void 0,
21203
+ zIndex: isExpanded ? 0 : leaving ? 4 : 3 - rank,
21126
21204
  opacity: leaving ? 0 : 1,
21127
21205
  pointerEvents: leaving ? "none" : void 0,
21128
- transform: leaving ? "translateY(-16px) scaleX(1.02)" : `translateY(${rank * offset}px) scaleX(${1 - rank * 0.04})`,
21206
+ transform: isExpanded ? "none" : leaving ? "translateY(-16px) scaleX(1.02)" : `translateY(${rank * offset}px) scaleX(${1 - rank * 0.04})`,
21129
21207
  height: !active && height ? height : void 0
21130
21208
  },
21131
21209
  children: [
21132
21210
  /* @__PURE__ */ jsx194(
21133
21211
  "div",
21134
21212
  {
21135
- ref: active ? measureRef : void 0,
21213
+ ref: i === index ? measureRef : void 0,
21136
21214
  inert: !active || void 0,
21137
21215
  "aria-hidden": !active || void 0,
21138
21216
  style: { height: !active && height ? height : void 0 },
@@ -21167,7 +21245,7 @@ function StackCarousel({
21167
21245
  })
21168
21246
  }
21169
21247
  ),
21170
- /* @__PURE__ */ jsxs90("div", { className: showStatus || showNavigators && items.length > 1 ? "mt-3 flex items-center justify-between gap-3 text-xs text-neutral-600 dark:text-neutral-400" : void 0, children: [
21248
+ /* @__PURE__ */ jsxs90("div", { className: showStatus || showNavigators && items.length > 1 || expandable && showExpandButton ? "mt-3 flex items-center justify-between gap-3 text-xs text-neutral-600 dark:text-neutral-400" : void 0, children: [
21171
21249
  /* @__PURE__ */ jsxs90("span", { className: showStatus ? void 0 : "sr-only", role: "status", "aria-live": "polite", "aria-atomic": "true", children: [
21172
21250
  label(index),
21173
21251
  " \xB7 ",
@@ -21175,27 +21253,37 @@ function StackCarousel({
21175
21253
  " / ",
21176
21254
  items.length
21177
21255
  ] }),
21178
- showNavigators && items.length > 1 && /* @__PURE__ */ jsxs90("div", { className: "ml-auto flex items-center gap-1", children: [
21179
- /* @__PURE__ */ jsx194(
21180
- "button",
21181
- {
21182
- type: "button",
21183
- "aria-label": previousLabel,
21184
- onClick: () => navigate(index - 1),
21185
- className: "rounded-md px-2 py-1 hover:bg-black/5 focus-visible:outline-2 dark:hover:bg-white/10",
21186
- children: "\u2191"
21187
- }
21188
- ),
21189
- /* @__PURE__ */ jsx194(
21190
- "button",
21191
- {
21192
- type: "button",
21193
- "aria-label": nextLabel,
21194
- onClick: () => navigate(index + 1),
21195
- className: "rounded-md px-2 py-1 hover:bg-black/5 focus-visible:outline-2 dark:hover:bg-white/10",
21196
- children: "\u2193"
21197
- }
21198
- )
21256
+ (showNavigators && items.length > 1 || expandable && showExpandButton) && /* @__PURE__ */ jsxs90("div", { className: "ml-auto flex items-center gap-1", children: [
21257
+ expandable && showExpandButton && /* @__PURE__ */ jsx194("button", { type: "button", "aria-expanded": isExpanded, onClick: () => {
21258
+ hoverOpened.current = false;
21259
+ clearHover();
21260
+ clearCollapse();
21261
+ setExpanded(!isExpanded);
21262
+ }, className: "rounded-md px-2 py-1 hover:bg-black/5 dark:hover:bg-white/10", children: isExpanded ? collapseLabel : expandLabel }),
21263
+ showNavigators && !isExpanded && items.length > 1 && /* @__PURE__ */ jsxs90(Fragment15, { children: [
21264
+ /* @__PURE__ */ jsx194(
21265
+ "button",
21266
+ {
21267
+ type: "button",
21268
+ "aria-label": previousLabel,
21269
+ disabled: !loop && index === 0,
21270
+ onClick: () => navigate(index - 1),
21271
+ className: "rounded-md px-2 py-1 hover:bg-black/5 focus-visible:outline-2 dark:hover:bg-white/10",
21272
+ children: "\u2191"
21273
+ }
21274
+ ),
21275
+ /* @__PURE__ */ jsx194(
21276
+ "button",
21277
+ {
21278
+ type: "button",
21279
+ "aria-label": nextLabel,
21280
+ disabled: !loop && index === items.length - 1,
21281
+ onClick: () => navigate(index + 1),
21282
+ className: "rounded-md px-2 py-1 hover:bg-black/5 focus-visible:outline-2 dark:hover:bg-white/10",
21283
+ children: "\u2193"
21284
+ }
21285
+ )
21286
+ ] })
21199
21287
  ] })
21200
21288
  ] })
21201
21289
  ] })
@@ -38429,12 +38517,15 @@ var CollapsibleBody = ({
38429
38517
  surface.body,
38430
38518
  inset,
38431
38519
  "pt-0",
38432
- isExpanded && !fillHeight ? SCROLLBAR : "overflow-hidden",
38520
+ !fillHeight ? SCROLLBAR : "overflow-hidden",
38433
38521
  contentClassName
38434
38522
  ),
38435
38523
  style: {
38436
- maxHeight: isExpanded && !fillHeight ? `min(${contentMaxHeight}px, 65vh)` : void 0,
38437
- minHeight: isExpanded ? minExpandedHeight : void 0
38524
+ maxHeight: !fillHeight ? `min(${contentMaxHeight}px, 65vh)` : void 0,
38525
+ // Keep intrinsic content sizing stable throughout the grid
38526
+ // transition. Removing these bounds on collapse first expands
38527
+ // a scrollable body to its full content height.
38528
+ minHeight: minExpandedHeight
38438
38529
  },
38439
38530
  children
38440
38531
  }
@@ -63930,6 +64021,12 @@ var ConnectionFlow = React88.forwardRef(function ConnectionFlow2({
63930
64021
  highlightPath = true,
63931
64022
  showControls = true,
63932
64023
  fitOnLoad = false,
64024
+ followMode,
64025
+ defaultFollowMode = "off",
64026
+ onFollowModeChange,
64027
+ activeNodeIds,
64028
+ followPadding = 40,
64029
+ followDuration = 400,
63933
64030
  interactive = true,
63934
64031
  minZoom = 0.25,
63935
64032
  maxZoom = 2,
@@ -63961,6 +64058,24 @@ var ConnectionFlow = React88.forwardRef(function ConnectionFlow2({
63961
64058
  const viewportRef = useRef68(null);
63962
64059
  const wheelAreaRef = useRef68(null);
63963
64060
  const manuallyNavigated = useRef68(false);
64061
+ const [internalFollow, setInternalFollow] = useState78(defaultFollowMode);
64062
+ const follow = followMode ?? internalFollow;
64063
+ const followFrame = useRef68(null);
64064
+ const followZoomChange = useRef68(onZoomChange);
64065
+ followZoomChange.current = onZoomChange;
64066
+ const cancelFollow = useCallback44(() => {
64067
+ if (followFrame.current !== null) cancelAnimationFrame(followFrame.current);
64068
+ followFrame.current = null;
64069
+ }, []);
64070
+ const requestFollow = useCallback44((mode) => {
64071
+ if (followMode === void 0) setInternalFollow(mode);
64072
+ onFollowModeChange?.(mode);
64073
+ }, [followMode, onFollowModeChange]);
64074
+ const pauseFollowing = useCallback44(() => {
64075
+ cancelFollow();
64076
+ if (follow === "following") requestFollow("paused");
64077
+ }, [cancelFollow, follow, requestFollow]);
64078
+ useEffect70(() => cancelFollow, [cancelFollow]);
63964
64079
  const [viewport, setViewport] = useState78({ width: 0, height: 0 });
63965
64080
  const [hoveredId, setHoveredId] = useState78(null);
63966
64081
  const [selectedId, setSelectedId] = useState78(null);
@@ -63983,6 +64098,8 @@ var ConnectionFlow = React88.forwardRef(function ConnectionFlow2({
63983
64098
  if (connection.editable !== false) onConnectionEdit?.(connection);
63984
64099
  };
63985
64100
  const [scale, setScale] = useState78(1);
64101
+ const currentScale = useRef68(scale);
64102
+ currentScale.current = scale;
63986
64103
  const [panning, setPanning] = useState78(false);
63987
64104
  const [expanded, setExpanded] = useState78(
63988
64105
  () => /* @__PURE__ */ new Set()
@@ -64058,10 +64175,11 @@ var ConnectionFlow = React88.forwardRef(function ConnectionFlow2({
64058
64175
  if (!element || !apply) return;
64059
64176
  pendingScroll.current = null;
64060
64177
  apply(element);
64061
- }, [scale]);
64178
+ });
64062
64179
  const setZoom = useCallback44(
64063
64180
  (value, anchor) => {
64064
64181
  manuallyNavigated.current = true;
64182
+ pauseFollowing();
64065
64183
  const next = clampZoom2(value);
64066
64184
  if (next === scale) return;
64067
64185
  const element = viewportRef.current;
@@ -64080,7 +64198,7 @@ var ConnectionFlow = React88.forwardRef(function ConnectionFlow2({
64080
64198
  setScale(next);
64081
64199
  onZoomChange?.(next);
64082
64200
  },
64083
- [clampZoom2, scale, onZoomChange]
64201
+ [clampZoom2, scale, onZoomChange, pauseFollowing]
64084
64202
  );
64085
64203
  const fit = useCallback44(() => {
64086
64204
  const element = viewportRef.current;
@@ -64098,11 +64216,14 @@ var ConnectionFlow = React88.forwardRef(function ConnectionFlow2({
64098
64216
  onZoomChange?.(next);
64099
64217
  }, [layout, drawing.offsetX, drawing.offsetY, drawing.width, drawing.height, maxZoom, clampZoom2, onZoomChange]);
64100
64218
  useImperativeHandle4(ref, () => ({
64219
+ pauseFollowing,
64220
+ resumeFollowing: () => requestFollow("following"),
64101
64221
  dismissGhost: (id) => editorRef.current?.dismissGhost(id),
64102
64222
  zoomIn: () => setZoom(scale * 1.2),
64103
64223
  zoomOut: () => setZoom(scale / 1.2),
64104
64224
  fit: () => {
64105
64225
  manuallyNavigated.current = true;
64226
+ pauseFollowing();
64106
64227
  fit();
64107
64228
  },
64108
64229
  setZoom: (value) => setZoom(value)
@@ -64133,8 +64254,44 @@ var ConnectionFlow = React88.forwardRef(function ConnectionFlow2({
64133
64254
  return () => element.removeEventListener("wheel", onWheel);
64134
64255
  }, [interactive, scale, setZoom, loading, nodes.length > 0]);
64135
64256
  useEffect70(() => {
64136
- if (fitOnLoad && viewport.width && !manuallyNavigated.current) fit();
64137
- }, [fitOnLoad, nodes, viewport.width, viewport.height]);
64257
+ if (follow === "off" && fitOnLoad && viewport.width && !manuallyNavigated.current) fit();
64258
+ }, [fitOnLoad, nodes, viewport.width, viewport.height, follow]);
64259
+ const activeCards = layout.nodes.filter((n) => activeNodeIds ? activeNodeIds.includes(n.id) : nodeIsActive(n.node));
64260
+ const followTargets = JSON.stringify(activeCards.map((n) => [n.x, n.y, n.width, n.height]));
64261
+ useEffect70(() => {
64262
+ cancelFollow();
64263
+ const element = viewportRef.current;
64264
+ const boxes = JSON.parse(followTargets);
64265
+ if (follow !== "following" || loading || !element || !boxes.length || !viewport.width || !viewport.height) return;
64266
+ const left = Math.min(...boxes.map((b) => b[0])), top = Math.min(...boxes.map((b) => b[1]));
64267
+ const right = Math.max(...boxes.map((b) => b[0] + b[2])), bottom = Math.max(...boxes.map((b) => b[1] + b[3]));
64268
+ const padding = Number.isFinite(followPadding) ? Math.max(0, followPadding) : 40;
64269
+ const next = clampZoom2(Math.min(maxZoom, Math.max(1, viewport.width - 2 * padding) / Math.max(1, right - left), Math.max(1, viewport.height - 2 * padding) / Math.max(1, bottom - top)));
64270
+ const from = { scale: currentScale.current, x: element.scrollLeft, y: element.scrollTop };
64271
+ const target = { x: Math.max(0, ((left + right) / 2 - drawing.offsetX) * next - viewport.width / 2), y: Math.max(0, ((top + bottom) / 2 - drawing.offsetY) * next - viewport.height / 2) };
64272
+ const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
64273
+ const duration = reduced || !animated ? 0 : Number.isFinite(followDuration) ? Math.max(0, followDuration) : 400;
64274
+ const start = performance.now();
64275
+ const tick = (time) => {
64276
+ const progress2 = duration ? Math.min(1, Math.max(0, (time - start) / duration)) : 1;
64277
+ const ease = 1 - (1 - progress2) ** 3;
64278
+ const value = from.scale + (next - from.scale) * ease;
64279
+ pendingScroll.current = (el) => {
64280
+ el.scrollLeft = from.x + (target.x - from.x) * ease;
64281
+ el.scrollTop = from.y + (target.y - from.y) * ease;
64282
+ };
64283
+ if (value === currentScale.current) {
64284
+ pendingScroll.current(element);
64285
+ pendingScroll.current = null;
64286
+ }
64287
+ setScale(value);
64288
+ followZoomChange.current?.(value);
64289
+ followFrame.current = progress2 < 1 ? requestAnimationFrame(tick) : null;
64290
+ };
64291
+ if (duration) followFrame.current = requestAnimationFrame(tick);
64292
+ else tick(start);
64293
+ return cancelFollow;
64294
+ }, [follow, followTargets, viewport.width, viewport.height, drawing.offsetX, drawing.offsetY, followPadding, followDuration, animated, loading, clampZoom2, maxZoom, cancelFollow]);
64138
64295
  const onHover = (node) => {
64139
64296
  setHoveredId(node?.id ?? null);
64140
64297
  onNodeHover?.(node?.node ?? null);
@@ -64256,12 +64413,14 @@ var ConnectionFlow = React88.forwardRef(function ConnectionFlow2({
64256
64413
  {
64257
64414
  variant: "auto",
64258
64415
  viewportRef,
64416
+ "data-follow-mode": follow,
64259
64417
  viewportClassName: "!overflow-hidden",
64260
64418
  className: "h-full w-full min-w-0 select-none",
64261
64419
  style: { cursor: panning ? "grabbing" : void 0 },
64262
64420
  onPointerDown: (event) => {
64263
64421
  if (event.button === 0 && editMode && !event.target.closest("[data-flow-node], [data-flow-connection-hit], button, input, select, textarea")) selectConnection(null);
64264
64422
  if (!interactive || event.button !== 0) return;
64423
+ if (event.target.closest?.('[data-slot="scrollarea-scrollbar"]')) pauseFollowing();
64265
64424
  if (editMode && event.target.closest("[data-flow-node]")) return;
64266
64425
  if (event.target.closest(
64267
64426
  'button, a, input, select, textarea, [data-no-pan], [data-slot="scrollarea-scrollbar"]'
@@ -64271,6 +64430,7 @@ var ConnectionFlow = React88.forwardRef(function ConnectionFlow2({
64271
64430
  const element = viewportRef.current;
64272
64431
  if (!element) return;
64273
64432
  manuallyNavigated.current = true;
64433
+ pauseFollowing();
64274
64434
  setPanning(true);
64275
64435
  panStart.current = {
64276
64436
  x: event.clientX,
@@ -64329,6 +64489,7 @@ var ConnectionFlow = React88.forwardRef(function ConnectionFlow2({
64329
64489
  onBounds: onEditBounds,
64330
64490
  onStart: () => {
64331
64491
  manuallyNavigated.current = true;
64492
+ pauseFollowing();
64332
64493
  }
64333
64494
  }
64334
64495
  )
@@ -64343,6 +64504,16 @@ var ConnectionFlow = React88.forwardRef(function ConnectionFlow2({
64343
64504
  "data-no-pan": true,
64344
64505
  className: "absolute bottom-3 right-3 z-10 flex items-center gap-0.5 rounded-lg border border-neutral-200 bg-white/90 p-1 shadow-sm backdrop-blur dark:border-neutral-700 dark:bg-neutral-900/90",
64345
64506
  children: [
64507
+ /* @__PURE__ */ jsx298(
64508
+ "button",
64509
+ {
64510
+ type: "button",
64511
+ "aria-pressed": follow === "following",
64512
+ className: "rounded-md px-2 py-1 text-xs text-neutral-600 hover:bg-black/5 dark:text-neutral-300 dark:hover:bg-white/10",
64513
+ onClick: () => follow === "following" ? pauseFollowing() : requestFollow("following"),
64514
+ children: follow === "following" ? "Pause following" : follow === "paused" ? "Resume following" : "Follow active"
64515
+ }
64516
+ ),
64346
64517
  /* @__PURE__ */ jsx298(
64347
64518
  IconButton_default,
64348
64519
  {
@@ -64354,6 +64525,7 @@ var ConnectionFlow = React88.forwardRef(function ConnectionFlow2({
64354
64525
  tooltip: "Fit to view",
64355
64526
  onClick: () => {
64356
64527
  manuallyNavigated.current = true;
64528
+ pauseFollowing();
64357
64529
  fit();
64358
64530
  }
64359
64531
  }