@constructive-io/ui 0.10.0 → 0.11.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.
@@ -458,6 +458,35 @@ function createOffsetTransition(_config = {}) {
458
458
  mass: .8
459
459
  };
460
460
  }
461
+ /**
462
+ * Enter transition for card slide-in (x: 100% → offset).
463
+ * Tween + snappy ease — distinct from offset springs used after settle.
464
+ */
465
+ function createEnterTransition(config = {}) {
466
+ const { duration, enterEase } = {
467
+ ...DEFAULT_ANIMATION_CONFIG,
468
+ ...config
469
+ };
470
+ return {
471
+ type: "tween",
472
+ duration,
473
+ ease: enterEase
474
+ };
475
+ }
476
+ /**
477
+ * Exit transition for card slide-out (offset → x: 100%).
478
+ */
479
+ function createExitTransition(config = {}) {
480
+ const { duration, exitEase } = {
481
+ ...DEFAULT_ANIMATION_CONFIG,
482
+ ...config
483
+ };
484
+ return {
485
+ type: "tween",
486
+ duration,
487
+ ease: exitEase
488
+ };
489
+ }
461
490
  const backdropVariants = {
462
491
  initial: { opacity: 0 },
463
492
  animate: {
@@ -502,20 +531,6 @@ const swipeDismissTransition = {
502
531
  1
503
532
  ]
504
533
  };
505
- /**
506
- * Exit transition for the last card - coordinated slide + fade.
507
- * Uses tween (not spring) for smooth opacity animation.
508
- */
509
- const lastCardExitTransition = {
510
- type: "tween",
511
- duration: .25,
512
- ease: [
513
- .4,
514
- 0,
515
- .6,
516
- 1
517
- ]
518
- };
519
534
  /** Spring config for peek hover expansion - playful and bouncy */
520
535
  const peekHoverSpring = {
521
536
  type: "spring",
@@ -956,6 +971,7 @@ function usePeekGestures(options) {
956
971
  //#region src/components/stack/stack-card.tsx
957
972
  /** Default hover expansion in pixels */
958
973
  const DEFAULT_HOVER_EXPANSION = 48;
974
+ const reducedMotionTransition = { duration: 0 };
959
975
  function StackCardInner({ card, index, totalCards, topCardWidth, animation, isMobile = false, renderHeader, peekGestureConfig, compressionRatio = 1, adjustedPeekOffset, dragX = 0, gestureBind, isPeekHovered = false, onPeekHoverStart, onPeekHoverEnd, peekDragOffset = 0, onPeekDragStart, onPeekDrag, onPeekDragEnd, isLastCard = false, className }) {
960
976
  const { config, api, state } = useStackContext();
961
977
  const prefersReducedMotion = useReducedMotion();
@@ -981,6 +997,8 @@ function StackCardInner({ card, index, totalCards, topCardWidth, animation, isMo
981
997
  ]);
982
998
  const cardWidth = isMobile ? "100%" : normalizeWidth(card.width, config.defaultWidth);
983
999
  const offsetTransition = createOffsetTransition(animation);
1000
+ const enterTransition = createEnterTransition(animation);
1001
+ const exitTransition = createExitTransition(animation);
984
1002
  const handleClose = useCallback(() => {
985
1003
  api.dismiss(card.id);
986
1004
  }, [api, card.id]);
@@ -1047,16 +1065,15 @@ function StackCardInner({ card, index, totalCards, topCardWidth, animation, isMo
1047
1065
  const initialX = prefersReducedMotion ? xOffset : "100%";
1048
1066
  const exitX = prefersReducedMotion ? xOffset : "100%";
1049
1067
  const exitOpacity = prefersReducedMotion ? 0 : isLastCard ? 0 : 1;
1050
- let activeTransition = offsetTransition;
1051
- if (peekGestures.isDragging || peekDragOffset > 0) activeTransition = peekDragSpring;
1052
- else if (isPeekHovered) activeTransition = peekHoverSpring;
1053
- const exitAnimation = isLastCard && !prefersReducedMotion ? {
1068
+ let activeTransition = prefersReducedMotion ? reducedMotionTransition : isAnimationComplete ? offsetTransition : enterTransition;
1069
+ if (!prefersReducedMotion) {
1070
+ if (peekGestures.isDragging || peekDragOffset > 0) activeTransition = peekDragSpring;
1071
+ else if (isPeekHovered) activeTransition = peekHoverSpring;
1072
+ }
1073
+ const exitAnimation = {
1054
1074
  x: exitX,
1055
1075
  opacity: exitOpacity,
1056
- transition: lastCardExitTransition
1057
- } : {
1058
- x: exitX,
1059
- opacity: exitOpacity
1076
+ transition: prefersReducedMotion ? reducedMotionTransition : exitTransition
1060
1077
  };
1061
1078
  return /* @__PURE__ */ jsxs(motion.div, {
1062
1079
  "data-slot": "stack-card",
@@ -1066,7 +1083,7 @@ function StackCardInner({ card, index, totalCards, topCardWidth, animation, isMo
1066
1083
  "data-offset": baseOffset,
1067
1084
  initial: {
1068
1085
  x: initialX,
1069
- opacity: prefersReducedMotion ? 0 : 1
1086
+ opacity: 1
1070
1087
  },
1071
1088
  animate: {
1072
1089
  x: animateX,
@@ -1398,7 +1415,6 @@ function CardStackViewport({ backdrop = true, renderBackdrop, renderHeader, rend
1398
1415
  "data-slot": "stack-viewport",
1399
1416
  className: cn("pointer-events-none fixed inset-0", className),
1400
1417
  children: /* @__PURE__ */ jsxs(AnimatePresence, {
1401
- initial: false,
1402
1418
  mode: "popLayout",
1403
1419
  onExitComplete: handleExitComplete,
1404
1420
  children: [shouldShowBackdrop && hasCards && renderBackdropNode(resolvedBackdrop.config), visibleCards.map((card, visibleIndex) => {
@@ -1527,5 +1543,5 @@ function DefaultCardSkeleton() {
1527
1543
  }
1528
1544
 
1529
1545
  //#endregion
1530
- export { snapBackSpring as A, useStackLayoutMode as B, createCardVariants as C, peekHoverSpring as D, peekDragSpring as E, useCardReady as F, useCardStack as I, useIsTopCard as L, CardStackProvider as M, useCardIndex as N, peekSlideSpring as O, useCardInjectedProps as P, useStackCards as R, backdropVariants as S, createReducedMotionVariants as T, parseWidthToPixels as _, useStackGestures as a, StackBackdrop as b, calculateResponsiveOffset as c, getCascadeOffset as d, getResponsiveCardOffset as f, normalizeWidth as g, isCardVisible as h, useStackResponsive as i, swipeDismissTransition as j, reducedMotionBackdropVariants as k, getCardOffset as l, getVisibleCardIndices as m, CardStackViewport as n, StackCard as o, getSideBySideOffset as p, useIsMobile as r, usePeekGestures as s, DeferredCardContent as t, getCardZIndex as u, StackHeader as v, createOffsetTransition as w, DEFAULT_ANIMATION_CONFIG as x, StackHeaderSlot as y, useStackContext as z };
1531
- //# sourceMappingURL=stack-jMdxDrex.js.map
1546
+ export { peekSlideSpring as A, useStackCards as B, createCardVariants as C, createReducedMotionVariants as D, createOffsetTransition as E, useCardIndex as F, useStackLayoutMode as H, useCardInjectedProps as I, useCardReady as L, snapBackSpring as M, swipeDismissTransition as N, peekDragSpring as O, CardStackProvider as P, useCardStack as R, backdropVariants as S, createExitTransition as T, useStackContext as V, parseWidthToPixels as _, useStackGestures as a, StackBackdrop as b, calculateResponsiveOffset as c, getCascadeOffset as d, getResponsiveCardOffset as f, normalizeWidth as g, isCardVisible as h, useStackResponsive as i, reducedMotionBackdropVariants as j, peekHoverSpring as k, getCardOffset as l, getVisibleCardIndices as m, CardStackViewport as n, StackCard as o, getSideBySideOffset as p, useIsMobile as r, usePeekGestures as s, DeferredCardContent as t, getCardZIndex as u, StackHeader as v, createEnterTransition as w, DEFAULT_ANIMATION_CONFIG as x, StackHeaderSlot as y, useIsTopCard as z };
1547
+ //# sourceMappingURL=stack-C9GROTGA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stack-C9GROTGA.js","names":["React","React","DEFAULT_HOVER_EXPANSION","DEFAULT_VELOCITY_THRESHOLD","React"],"sources":["../src/components/stack/stack-context.tsx","../src/components/stack/stack-animations.ts","../src/components/stack/stack-backdrop.tsx","../src/components/stack/stack-header.tsx","../src/components/stack/stack-utils.ts","../src/components/stack/use-peek-gestures.ts","../src/components/stack/stack-card.tsx","../src/components/stack/use-stack-gestures.ts","../src/components/stack/use-stack-responsive.ts","../src/components/stack/stack-viewport.tsx","../src/components/stack/deferred-card-content.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createContext, useContext, useEffect, useMemo, useReducer, useRef, useState } from 'react';\n\nimport type {\n CardId,\n CardPushOptions,\n CardSpec,\n CardStackApi,\n CardStackProviderProps,\n DismissOptions,\n LayoutMode,\n PushOptions,\n StackAction,\n StackContextValue,\n StackState,\n} from './stack.types';\n\n// =============================================================================\n// Constants\n// =============================================================================\n\nconst DEFAULT_Z_INDEX_BASE = 100;\nconst DEFAULT_PEEK_OFFSET = 48;\nconst DEFAULT_WIDTH = 480;\n\n// =============================================================================\n// Reducer\n// =============================================================================\n\nfunction stackReducer(state: StackState, action: StackAction): StackState {\n switch (action.type) {\n case 'PUSH': {\n // Remove existing card with same ID to prevent duplicates\n const filtered = state.cards.filter((c) => c.id !== action.card.id);\n return { cards: [...filtered, action.card] };\n }\n\n case 'POP': {\n const count = Math.max(1, action.count);\n if (state.cards.length === 0) return state;\n return { cards: state.cards.slice(0, -count) };\n }\n\n case 'POP_TO': {\n const index = state.cards.findIndex((c) => c.id === action.id);\n if (index === -1) return state;\n return { cards: state.cards.slice(0, index + 1) };\n }\n\n case 'REPLACE_TOP': {\n if (state.cards.length === 0) {\n return { cards: [action.card] };\n }\n const newCards = [...state.cards];\n newCards[newCards.length - 1] = action.card;\n return { cards: newCards };\n }\n\n case 'RESET': {\n return { cards: action.cards };\n }\n\n case 'CLEAR': {\n return { cards: [] };\n }\n\n case 'UPDATE_PROPS': {\n const index = state.cards.findIndex((c) => c.id === action.id);\n if (index === -1) return state;\n\n const card = state.cards[index];\n const prevProps = (card.props ?? {}) as Record<string, unknown>;\n const newProps =\n typeof action.patch === 'function'\n ? (action.patch as (prev: unknown) => unknown)(card.props)\n : { ...prevProps, ...(action.patch as Record<string, unknown>) };\n\n const newCards = [...state.cards];\n newCards[index] = { ...card, props: newProps };\n return { cards: newCards };\n }\n\n case 'SET_TITLE': {\n const index = state.cards.findIndex((c) => c.id === action.id);\n if (index === -1) return state;\n\n const newCards = [...state.cards];\n newCards[index] = { ...newCards[index], title: action.title };\n return { cards: newCards };\n }\n\n case 'SET_DESCRIPTION': {\n const index = state.cards.findIndex((c) => c.id === action.id);\n if (index === -1) return state;\n\n const newCards = [...state.cards];\n newCards[index] = { ...newCards[index], description: action.description };\n return { cards: newCards };\n }\n\n case 'SET_WIDTH': {\n const index = state.cards.findIndex((c) => c.id === action.id);\n if (index === -1) return state;\n\n const newCards = [...state.cards];\n newCards[index] = { ...newCards[index], width: action.width };\n return { cards: newCards };\n }\n\n case 'SET_DISMISSABLE': {\n const index = state.cards.findIndex((c) => c.id === action.id);\n if (index === -1) return state;\n\n const newCards = [...state.cards];\n newCards[index] = { ...newCards[index], dismissable: action.dismissable };\n return { cards: newCards };\n }\n\n case 'DISMISS': {\n const index = state.cards.findIndex((c) => c.id === action.id);\n if (index === -1) return state;\n\n if (action.cascade) {\n // Cascade: remove this card and all cards above it\n return { cards: state.cards.slice(0, index) };\n } else {\n // No cascade: remove only this specific card\n return { cards: state.cards.filter((c) => c.id !== action.id) };\n }\n }\n\n case 'INSERT_AT': {\n const clampedIndex = Math.max(0, Math.min(action.index, state.cards.length));\n // Remove existing card with same ID\n const filtered = state.cards.filter((c) => c.id !== action.card.id);\n const newCards = [...filtered];\n newCards.splice(clampedIndex, 0, action.card);\n return { cards: newCards };\n }\n\n default:\n return state;\n }\n}\n\n// =============================================================================\n// Context\n// =============================================================================\n\nconst StackContext = createContext<StackContextValue | null>(null);\n\n// =============================================================================\n// Provider\n// =============================================================================\n\nexport function CardStackProvider({\n children,\n routes = {},\n initial = [],\n onChange,\n zIndexBase = DEFAULT_Z_INDEX_BASE,\n layoutMode = 'cascade',\n defaultPeekOffset = DEFAULT_PEEK_OFFSET,\n defaultWidth = DEFAULT_WIDTH,\n}: CardStackProviderProps) {\n const [state, reducerDispatch] = useReducer(stackReducer, { cards: initial });\n\n // Stable routes ref for API methods\n const routesRef = useRef(routes);\n useEffect(() => {\n routesRef.current = routes;\n }, [routes]);\n\n // State ref for API methods (avoid stale closures)\n const stateRef = useRef(state);\n useEffect(() => {\n stateRef.current = state;\n }, [state]);\n\n // Keep imperative reads current across multiple dispatches in the same event.\n const dispatch = React.useCallback(\n (action: StackAction) => {\n stateRef.current = stackReducer(stateRef.current, action);\n reducerDispatch(action);\n },\n [reducerDispatch],\n );\n\n // Track previous cards for onChange callback and onClose detection\n const prevCardsRef = useRef(state.cards);\n\n // Call onChange when cards change, and onClose for removed cards\n useEffect(() => {\n if (prevCardsRef.current !== state.cards) {\n const prevCards = prevCardsRef.current;\n const currentIds = new Set(state.cards.map((c) => c.id));\n\n // Find removed cards and call their onClose callbacks\n for (const card of prevCards) {\n if (!currentIds.has(card.id)) {\n card.onClose?.();\n }\n }\n\n prevCardsRef.current = state.cards;\n onChange?.(state.cards);\n }\n }, [state.cards, onChange]);\n\n // Build stable API object\n const api = useMemo<CardStackApi>(() => {\n // Read operations use stateRef to get current state\n const top = () => {\n const cards = stateRef.current.cards;\n return cards.length > 0 ? cards[cards.length - 1] : null;\n };\n\n const currentId = () => top()?.id ?? null;\n\n const canPop = () => stateRef.current.cards.length > 0;\n\n const size = () => stateRef.current.cards.length;\n\n const get = (id: CardId) => stateRef.current.cards.find((c) => c.id === id) ?? null;\n\n const getAll = () => [...stateRef.current.cards];\n\n const has = (id: CardId) => stateRef.current.cards.some((c) => c.id === id);\n\n // Navigation operations\n const push = <P,>(card: CardSpec<P>, options?: PushOptions) => {\n // If replaceFrom is specified, first remove all cards above that card\n if (options?.replaceFrom) {\n const fromIndex = stateRef.current.cards.findIndex((c) => c.id === options.replaceFrom);\n if (fromIndex !== -1 && fromIndex < stateRef.current.cards.length - 1) {\n // Pop cards above the 'from' card\n dispatch({ type: 'POP_TO', id: options.replaceFrom });\n }\n }\n dispatch({ type: 'PUSH', card: card as CardSpec });\n return card.id;\n };\n\n const pushRoute = <P,>(\n route: string,\n props?: P,\n opts?: { id?: CardId; title?: string; width?: string | number },\n ) => {\n const routeDef = routesRef.current[route];\n if (!routeDef) {\n throw new Error(`Stack: Route \"${route}\" not found in registry`);\n }\n\n const id = opts?.id ?? routeDef.getId?.(props) ?? route;\n const card: CardSpec<P> = {\n id,\n title: opts?.title ?? routeDef.defaultTitle,\n Component: routeDef.Component as CardSpec<P>['Component'],\n props,\n width: opts?.width ?? routeDef.defaultWidth,\n peekOffset: routeDef.defaultPeekOffset,\n };\n\n dispatch({ type: 'PUSH', card: card as CardSpec });\n return id;\n };\n\n const pop = (count = 1) => {\n dispatch({ type: 'POP', count });\n };\n\n const popTo = (id: CardId) => {\n dispatch({ type: 'POP_TO', id });\n };\n\n const replaceTop = <P,>(card: CardSpec<P>) => {\n dispatch({ type: 'REPLACE_TOP', card: card as CardSpec });\n return card.id;\n };\n\n const reset = (cards: CardSpec[]) => {\n dispatch({ type: 'RESET', cards });\n };\n\n const clear = () => {\n dispatch({ type: 'CLEAR' });\n };\n\n // Update operations\n const updateProps = <P,>(id: CardId, patch: Partial<P> | ((prev: P) => P)) => {\n dispatch({ type: 'UPDATE_PROPS', id, patch });\n };\n\n const setTitle = (id: CardId, title?: string) => {\n dispatch({ type: 'SET_TITLE', id, title });\n };\n\n const setDescription = (id: CardId, description?: string) => {\n dispatch({ type: 'SET_DESCRIPTION', id, description });\n };\n\n const setWidth = (id: CardId, width?: string | number) => {\n dispatch({ type: 'SET_WIDTH', id, width });\n };\n\n const setDismissable = (id: CardId, dismissable: boolean) => {\n dispatch({ type: 'SET_DISMISSABLE', id, dismissable });\n };\n\n // Advanced operations\n const dismiss = (id: CardId, options?: DismissOptions) => {\n const cascade = options?.cascade ?? true; // Default: cascade\n dispatch({ type: 'DISMISS', id, cascade });\n };\n\n const insertAt = <P,>(index: number, card: CardSpec<P>) => {\n dispatch({ type: 'INSERT_AT', index, card: card as CardSpec });\n return card.id;\n };\n\n return {\n top,\n currentId,\n canPop,\n size,\n get,\n getAll,\n has,\n push,\n pushRoute,\n pop,\n popTo,\n replaceTop,\n reset,\n clear,\n updateProps,\n setTitle,\n setDescription,\n setWidth,\n setDismissable,\n dismiss,\n insertAt,\n };\n }, [dispatch]);\n\n // Global escape key handler - pop top card only\n useEffect(() => {\n const handleEscape = (event: KeyboardEvent) => {\n if (event.key === 'Escape' && stateRef.current.cards.length > 0) {\n event.preventDefault();\n event.stopPropagation();\n const topCard = stateRef.current.cards[stateRef.current.cards.length - 1];\n if (topCard.dismissable !== false) {\n api.pop();\n }\n }\n };\n\n document.addEventListener('keydown', handleEscape, true);\n return () => document.removeEventListener('keydown', handleEscape, true);\n }, [api]);\n\n const contextValue = useMemo<StackContextValue>(\n () => ({\n state,\n api,\n config: {\n routes,\n zIndexBase,\n layoutMode,\n defaultPeekOffset,\n defaultWidth,\n },\n }),\n [state, api, routes, zIndexBase, layoutMode, defaultPeekOffset, defaultWidth],\n );\n\n return <StackContext.Provider value={contextValue}>{children}</StackContext.Provider>;\n}\n\n// =============================================================================\n// Hooks\n// =============================================================================\n\nexport function useCardStack(): CardStackApi {\n const context = useContext(StackContext);\n if (!context) {\n throw new Error('useCardStack must be used within a CardStackProvider');\n }\n return context.api;\n}\n\nexport function useStackContext(): StackContextValue {\n const context = useContext(StackContext);\n if (!context) {\n throw new Error('useStackContext must be used within a CardStackProvider');\n }\n return context;\n}\n\n/** Hook to get current layout mode */\nexport function useStackLayoutMode(): LayoutMode {\n const context = useStackContext();\n return context.config.layoutMode;\n}\n\n/** Hook to get stack cards (triggers re-render on change) */\nexport function useStackCards(): CardSpec[] {\n const context = useStackContext();\n return context.state.cards;\n}\n\n/** Hook to check if a card is the top card */\nexport function useIsTopCard(id: CardId): boolean {\n const context = useStackContext();\n const cards = context.state.cards;\n return cards.length > 0 && cards[cards.length - 1].id === id;\n}\n\n/** Hook to get card index in stack */\nexport function useCardIndex(id: CardId): number {\n const context = useStackContext();\n return context.state.cards.findIndex((c) => c.id === id);\n}\n\n/** Create injected card props for a specific card */\nexport function useCardInjectedProps(id: CardId) {\n const api = useCardStack();\n\n return useMemo(\n () => ({\n card: {\n id,\n push: <P,>(\n card: Omit<CardSpec<P>, 'id'> & { id?: CardId },\n options?: CardPushOptions,\n ): CardId => {\n // Generate ID if not provided\n const cardId = card.id ?? `${id}-child-${Date.now()}`;\n const fullCard = { ...card, id: cardId } as CardSpec<P>;\n\n if (options?.append) {\n // Escape hatch: just push on top of the stack\n return api.push(fullCard);\n } else {\n // Default: replace cards above this card, then push\n return api.push(fullCard, { replaceFrom: id });\n }\n },\n close: () => api.dismiss(id),\n setTitle: (title?: string) => api.setTitle(id, title),\n setDescription: (description?: string) => api.setDescription(id, description),\n setWidth: (width?: string | number) => api.setWidth(id, width),\n setDismissable: (dismissable: boolean) => api.setDismissable(id, dismissable),\n updateProps: <P,>(patch: Partial<P> | ((prev: P) => P)) => api.updateProps(id, patch),\n },\n }),\n [id, api],\n );\n}\n\n// =============================================================================\n// Card Ready Context - for deferring data loading until after animation\n// =============================================================================\n\ninterface CardReadyContextValue {\n /** True when the card's enter animation has completed */\n isAnimationComplete: boolean;\n}\n\nconst CardReadyContext = createContext<CardReadyContextValue | null>(null);\n\n/** Provider for card animation state - used internally by StackCard */\nexport function CardReadyProvider({\n children,\n isAnimationComplete,\n}: {\n children: React.ReactNode;\n isAnimationComplete: boolean;\n}) {\n const value = useMemo(() => ({ isAnimationComplete }), [isAnimationComplete]);\n return <CardReadyContext.Provider value={value}>{children}</CardReadyContext.Provider>;\n}\n\n/**\n * Hook to check if the card's enter animation is complete.\n * Use this to defer data fetching until after the slide-in animation.\n *\n * @example\n * ```tsx\n * function MyCard() {\n * const { isReady } = useCardReady();\n *\n * // Data query that only runs after animation completes\n * const { data, isLoading } = useQuery({\n * queryKey: ['myData'],\n * queryFn: fetchData,\n * enabled: isReady, // Don't fetch until animation done\n * });\n *\n * return (\n * <Select disabled={isLoading || !isReady}>\n * {data?.map(item => <SelectItem key={item.id}>{item.name}</SelectItem>)}\n * </Select>\n * );\n * }\n * ```\n */\nexport function useCardReady(): { isReady: boolean } {\n const context = useContext(CardReadyContext);\n\n // If not in a card context (standalone usage), assume ready immediately\n if (!context) {\n return { isReady: true };\n }\n\n return { isReady: context.isAnimationComplete };\n}\n","import type { Transition, Variants } from 'motion/react';\n\nimport type { AnimationConfig } from './stack.types';\n\n// =============================================================================\n// Default Animation Config\n// =============================================================================\n\nexport const DEFAULT_ANIMATION_CONFIG: Required<AnimationConfig> = {\n\tduration: 0.2,\n\tenterEase: [0.32, 0.72, 0, 1], // Snappy entrance\n\texitEase: [0.4, 0, 0.6, 1], // Physical exit\n};\n\n// =============================================================================\n// Card Variants\n// =============================================================================\n\n/**\n * Create motion variants for card enter/exit animations.\n * Uses transform-only properties for GPU compositing.\n */\nexport function createCardVariants(config: AnimationConfig = {}): Variants {\n\tconst { duration, enterEase, exitEase } = {\n\t\t...DEFAULT_ANIMATION_CONFIG,\n\t\t...config,\n\t};\n\n\treturn {\n\t\tinitial: {\n\t\t\tx: '100%',\n\t\t},\n\t\tanimate: {\n\t\t\tx: 0,\n\t\t\ttransition: {\n\t\t\t\ttype: 'tween',\n\t\t\t\tduration,\n\t\t\t\tease: enterEase as [number, number, number, number],\n\t\t\t},\n\t\t},\n\t\texit: {\n\t\t\tx: '100%',\n\t\t\ttransition: {\n\t\t\t\ttype: 'tween',\n\t\t\t\tduration,\n\t\t\t\tease: exitEase as [number, number, number, number],\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Create transition for offset animations (when cards above change).\n * Uses spring for playful slide-back feel when cards are dismissed.\n */\nexport function createOffsetTransition(_config: AnimationConfig = {}): Transition {\n\treturn {\n\t\ttype: 'spring',\n\t\tstiffness: 300,\n\t\tdamping: 30,\n\t\tmass: 0.8,\n\t};\n}\n\n/**\n * Enter transition for card slide-in (x: 100% → offset).\n * Tween + snappy ease — distinct from offset springs used after settle.\n */\nexport function createEnterTransition(config: AnimationConfig = {}): Transition {\n\tconst { duration, enterEase } = {\n\t\t...DEFAULT_ANIMATION_CONFIG,\n\t\t...config,\n\t};\n\n\treturn {\n\t\ttype: 'tween',\n\t\tduration,\n\t\tease: enterEase as [number, number, number, number],\n\t};\n}\n\n/**\n * Exit transition for card slide-out (offset → x: 100%).\n */\nexport function createExitTransition(config: AnimationConfig = {}): Transition {\n\tconst { duration, exitEase } = {\n\t\t...DEFAULT_ANIMATION_CONFIG,\n\t\t...config,\n\t};\n\n\treturn {\n\t\ttype: 'tween',\n\t\tduration,\n\t\tease: exitEase as [number, number, number, number],\n\t};\n}\n\n// =============================================================================\n// Backdrop Variants\n// =============================================================================\n\nexport const backdropVariants: Variants = {\n\tinitial: {\n\t\topacity: 0,\n\t},\n\tanimate: {\n\t\topacity: 1,\n\t\ttransition: {\n\t\t\tduration: 0.2,\n\t\t\tease: 'easeOut',\n\t\t},\n\t},\n\texit: {\n\t\topacity: 0,\n\t\ttransition: {\n\t\t\tduration: 0.25,\n\t\t\tease: [0.4, 0, 0.6, 1], // Match card exit easing\n\t\t},\n\t},\n};\n\n// =============================================================================\n// Gesture Animation\n// =============================================================================\n\n/**\n * Create spring config for snap-back animation after cancelled swipe.\n */\nexport const snapBackSpring: Transition = {\n\ttype: 'spring',\n\tstiffness: 400,\n\tdamping: 30,\n\tmass: 0.8,\n};\n\n/**\n * Create transition for swipe-to-dismiss.\n */\nexport const swipeDismissTransition: Transition = {\n\ttype: 'tween',\n\tduration: 0.2,\n\tease: [0.4, 0, 0.6, 1],\n};\n\n/**\n * Exit transition for the last card - coordinated slide + fade.\n * Uses tween (not spring) for smooth opacity animation.\n */\nexport const lastCardExitTransition: Transition = {\n\ttype: 'tween',\n\tduration: 0.25,\n\tease: [0.4, 0, 0.6, 1], // Physical exit easing\n};\n\n// =============================================================================\n// Peek Zone Animation\n// =============================================================================\n\n/** Spring config for peek hover expansion - playful and bouncy */\nexport const peekHoverSpring: Transition = {\n\ttype: 'spring',\n\tstiffness: 500,\n\tdamping: 25,\n\tmass: 0.6,\n};\n\n/** Spring config for peek drag - responsive during interaction */\nexport const peekDragSpring: Transition = {\n\ttype: 'spring',\n\tstiffness: 600,\n\tdamping: 35,\n\tmass: 0.5,\n};\n\n/** Spring config for multi-card slide during peek drag */\nexport const peekSlideSpring: Transition = {\n\ttype: 'spring',\n\tstiffness: 400,\n\tdamping: 30,\n\tmass: 0.7,\n};\n\n// =============================================================================\n// Reduced Motion\n// =============================================================================\n\n/**\n * Create variants with reduced motion support.\n * Instant transitions when user prefers reduced motion.\n */\nexport function createReducedMotionVariants(): Variants {\n\treturn {\n\t\tinitial: {\n\t\t\tx: 0,\n\t\t\topacity: 0,\n\t\t},\n\t\tanimate: {\n\t\t\tx: 0,\n\t\t\topacity: 1,\n\t\t\ttransition: { duration: 0 },\n\t\t},\n\t\texit: {\n\t\t\tx: 0,\n\t\t\topacity: 0,\n\t\t\ttransition: { duration: 0 },\n\t\t},\n\t};\n}\n\nexport const reducedMotionBackdropVariants: Variants = {\n\tinitial: { opacity: 0 },\n\tanimate: { opacity: 1, transition: { duration: 0 } },\n\texit: { opacity: 0, transition: { duration: 0 } },\n};\n","'use client';\n\nimport * as React from 'react';\nimport { motion, useReducedMotion } from 'motion/react';\n\nimport { cn } from '../../lib/utils';\n\nimport { backdropVariants, reducedMotionBackdropVariants } from './stack-animations';\nimport { useCardStack, useStackContext } from './stack-context';\nimport type { BackdropConfig } from './stack.types';\n\nexport type StackBackdropProps = {\n\t/** Additional class names */\n\tclassName?: string;\n\t/** Click handler (typically closes the stack) */\n\tonClick?: () => void;\n\t/** Backdrop configuration (blur, custom className) */\n\tconfig?: BackdropConfig;\n};\n\nexport function StackBackdrop({ className, onClick, config: backdropConfig }: StackBackdropProps) {\n\tconst { config, state } = useStackContext();\n\tconst api = useCardStack();\n\tconst prefersReducedMotion = useReducedMotion();\n\n\tconst handleClick = React.useCallback(() => {\n\t\tif (state.cards.some((c) => c.dismissable === false)) return;\n\t\tif (onClick) {\n\t\t\tonClick();\n\t\t} else {\n\t\t\t// Default behavior: clear the entire stack\n\t\t\tapi.clear();\n\t\t}\n\t}, [onClick, api, state.cards]);\n\n\tconst variants = prefersReducedMotion ? reducedMotionBackdropVariants : backdropVariants;\n\n\t// Resolve backdrop styling - blur is off by default\n\tconst useBlur = backdropConfig?.blur ?? false;\n\n\treturn (\n\t\t<motion.div\n\t\t\tdata-slot=\"stack-backdrop\"\n\t\t\tvariants={variants}\n\t\t\tinitial=\"initial\"\n\t\t\tanimate=\"animate\"\n\t\t\texit=\"exit\"\n\t\t\tonClick={handleClick}\n\t\t\tstyle={{ zIndex: config.zIndexBase - 1 }}\n\t\t\tclassName={cn(\n\t\t\t\t'fixed inset-0',\n\t\t\t\t'cursor-pointer',\n\t\t\t\t// Default overlay or custom className\n\t\t\t\tbackdropConfig?.className ?? 'bg-black/50',\n\t\t\t\t// Optional blur\n\t\t\t\tuseBlur && 'backdrop-blur-sm',\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t/>\n\t);\n}\n","'use client';\n\nimport * as React from 'react';\nimport { ChevronRight } from 'lucide-react';\n\nimport { cn } from '../../lib/utils';\n\nimport type { CardSpec } from './stack.types';\n\n// =============================================================================\n// Size Variants\n// =============================================================================\n\ntype HeaderSize = 'sm' | 'md' | 'lg';\n\nconst sizeStyles = {\n sm: {\n title: 'text-sm font-semibold',\n description: 'text-xs',\n height: 'h-12',\n heightWithDesc: 'h-14',\n },\n md: {\n title: 'text-base font-semibold',\n description: 'text-sm',\n height: 'h-14',\n heightWithDesc: 'h-18',\n },\n lg: {\n title: 'text-lg font-semibold',\n description: 'text-sm',\n height: 'h-16',\n heightWithDesc: 'h-20',\n },\n} satisfies Record<HeaderSize, { title: string; description: string; height: string; heightWithDesc: string }>;\n\n// =============================================================================\n// Component\n// =============================================================================\n\nexport type StackHeaderProps = {\n /** The card spec */\n card: CardSpec;\n /** Close handler */\n onClose: () => void;\n /** Additional class names */\n className?: string;\n /** Custom title renderer */\n renderTitle?: (card: CardSpec) => React.ReactNode;\n};\n\nexport function StackHeader({ card, onClose, className, renderTitle }: StackHeaderProps) {\n const title = renderTitle ? renderTitle(card) : card.title;\n const hasDescription = !!card.description;\n const size = card.headerSize ?? 'md';\n const styles = sizeStyles[size];\n\n return (\n <div\n data-slot=\"stack-header\"\n className={cn(\n 'flex shrink-0 items-center justify-between',\n 'border-b border-border/50',\n 'px-4',\n hasDescription ? styles.heightWithDesc : styles.height,\n className\n )}\n >\n {/* Title & Description */}\n <div className=\"flex-1 min-w-0\">\n {title && <h2 className={cn('text-foreground truncate', styles.title)}>{title}</h2>}\n {card.description && (\n <p className={cn('text-muted-foreground truncate', styles.description)}>{card.description}</p>\n )}\n </div>\n\n {/* Close button */}\n {card.dismissable !== false && (\n <button\n type=\"button\"\n onClick={onClose}\n className={cn(\n 'flex h-8 w-8 items-center justify-center',\n 'rounded-md',\n 'text-muted-foreground hover:text-foreground',\n 'hover:bg-muted/50',\n 'transition-colors',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring'\n )}\n aria-label=\"Close\"\n >\n <ChevronRight className=\"h-5 w-5\" />\n </button>\n )}\n </div>\n );\n}\n\nexport type StackHeaderSlotProps = {\n /** Additional class names */\n className?: string;\n children: React.ReactNode;\n};\n\n/** Slot for custom header content */\nexport function StackHeaderSlot({ className, children }: StackHeaderSlotProps) {\n return (\n <div\n data-slot=\"stack-header-slot\"\n className={cn('flex h-12 shrink-0 items-center', 'border-b border-border/50', 'px-4', className)}\n >\n {children}\n </div>\n );\n}\n","import type { CardSpec, LayoutMode } from './stack.types';\n\n// =============================================================================\n// Offset Calculations\n// =============================================================================\n\n/**\n * Calculate the X offset for a card in cascade mode.\n * Cards below the top are pushed left by (cardsAbove * peekOffset).\n */\nexport function getCascadeOffset(\n\tcardIndex: number,\n\ttotalCards: number,\n\tcards: CardSpec[],\n\tdefaultPeekOffset: number,\n): number {\n\tconst cardsAbove = totalCards - cardIndex - 1;\n\tif (cardsAbove <= 0) return 0;\n\n\t// Use card-specific peekOffset if defined, else default\n\tconst card = cards[cardIndex];\n\tconst peekOffset = card?.peekOffset ?? defaultPeekOffset;\n\n\treturn cardsAbove * peekOffset;\n}\n\n/**\n * Calculate the X offset for a card in side-by-side mode.\n * - Top card: no offset\n * - Second card: pushed by top card's width (fully visible side-by-side)\n * - Deeper cards: cascade further with peekOffset increments\n */\nexport function getSideBySideOffset(\n\tcardIndex: number,\n\ttotalCards: number,\n\ttopCardWidth: number,\n\tdefaultPeekOffset: number,\n): number {\n\tif (totalCards === 0) return 0;\n\n\tconst cardsAbove = totalCards - cardIndex - 1;\n\n\t// Top card - no offset\n\tif (cardsAbove === 0) return 0;\n\n\t// Second card - pushed by top card width (side-by-side)\n\tif (cardsAbove === 1) return topCardWidth;\n\n\t// Deeper cards - cascade further\n\tconst extraDepth = cardsAbove - 1;\n\treturn topCardWidth + extraDepth * defaultPeekOffset;\n}\n\n/**\n * Get the offset for a card based on layout mode.\n */\nexport function getCardOffset(\n\tcardIndex: number,\n\ttotalCards: number,\n\tcards: CardSpec[],\n\tlayoutMode: LayoutMode,\n\ttopCardWidth: number,\n\tdefaultPeekOffset: number,\n): number {\n\tif (layoutMode === 'side-by-side') {\n\t\treturn getSideBySideOffset(cardIndex, totalCards, topCardWidth, defaultPeekOffset);\n\t}\n\treturn getCascadeOffset(cardIndex, totalCards, cards, defaultPeekOffset);\n}\n\n// =============================================================================\n// Responsive Offset Compression\n// =============================================================================\n\n/** Minimum visible peek for a card (in px) before it collapses - must be large enough to click */\nconst MIN_VISIBLE_PEEK = 24;\n\n/** Padding from viewport edges */\nconst VIEWPORT_PADDING = 16;\n\nexport type ResponsiveOffsetConfig = {\n\tviewportWidth: number;\n\ttopCardWidth: number;\n\tsecondCardWidth: number;\n\ttotalCards: number;\n\tdefaultPeekOffset: number;\n\tlayoutMode: LayoutMode;\n};\n\nexport type ResponsiveOffsetResult = {\n\t/** Compression ratio (1 = full, 0 = fully compressed) */\n\tcompressionRatio: number;\n\t/** Whether cards should collapse to mobile/single-card mode */\n\tshouldCollapse: boolean;\n\t/** Adjusted peek offset after compression */\n\tadjustedPeekOffset: number;\n\t/** Available space for peek offsets */\n\tavailableSpace: number;\n};\n\n/**\n * Calculate responsive offset compression based on viewport width.\n * As viewport shrinks, offsets compress until hitting mobile breakpoint.\n *\n * The algorithm:\n * 1. Calculate space needed: topCardWidth + secondCardWidth (for side-by-side)\n * 2. Calculate available space: viewportWidth - padding\n * 3. If not enough space, compress the second card's offset\n * 4. When compression reaches threshold, trigger collapse to mobile\n */\nexport function calculateResponsiveOffset(config: ResponsiveOffsetConfig): ResponsiveOffsetResult {\n\tconst {\n\t\tviewportWidth,\n\t\ttopCardWidth,\n\t\tsecondCardWidth,\n\t\ttotalCards,\n\t\tdefaultPeekOffset,\n\t\tlayoutMode,\n\t} = config;\n\n\t// Available viewport space (with padding)\n\tconst availableWidth = viewportWidth - VIEWPORT_PADDING * 2;\n\n\tif (totalCards <= 1) {\n\t\treturn {\n\t\t\tcompressionRatio: 1,\n\t\t\tshouldCollapse: false,\n\t\t\tadjustedPeekOffset: defaultPeekOffset,\n\t\t\tavailableSpace: availableWidth,\n\t\t};\n\t}\n\n\tif (layoutMode === 'side-by-side') {\n\t\t// Side-by-side: we want both cards fully visible\n\t\t// Ideal: topCardWidth + secondCardWidth\n\t\tconst idealWidth = topCardWidth + secondCardWidth;\n\n\t\tif (availableWidth >= idealWidth) {\n\t\t\t// Plenty of space - full side-by-side\n\t\t\treturn {\n\t\t\t\tcompressionRatio: 1,\n\t\t\t\tshouldCollapse: false,\n\t\t\t\tadjustedPeekOffset: defaultPeekOffset,\n\t\t\t\tavailableSpace: availableWidth - topCardWidth,\n\t\t\t};\n\t\t}\n\n\t\t// Calculate how much we need to compress\n\t\t// The second card gets pushed under the top card\n\t\tconst overflow = idealWidth - availableWidth;\n\t\tconst maxCompression = secondCardWidth - MIN_VISIBLE_PEEK;\n\n\t\tif (overflow >= maxCompression) {\n\t\t\t// Not enough space even with full compression - collapse to mobile\n\t\t\treturn {\n\t\t\t\tcompressionRatio: 0,\n\t\t\t\tshouldCollapse: true,\n\t\t\t\tadjustedPeekOffset: 0,\n\t\t\t\tavailableSpace: 0,\n\t\t\t};\n\t\t}\n\n\t\t// Compress the offset - second card slides under top card\n\t\t// compressionRatio: 1 = full visibility, 0 = collapsed\n\t\tconst compressionRatio = 1 - overflow / maxCompression;\n\t\tconst adjustedSecondCardVisible = secondCardWidth - overflow;\n\n\t\treturn {\n\t\t\tcompressionRatio,\n\t\t\tshouldCollapse: false,\n\t\t\tadjustedPeekOffset: defaultPeekOffset * compressionRatio,\n\t\t\tavailableSpace: adjustedSecondCardVisible,\n\t\t};\n\t}\n\n\t// Cascade mode: calculate based on peek offsets\n\tconst cascadeDepth = totalCards - 1;\n\tconst totalPeekNeeded = cascadeDepth * defaultPeekOffset;\n\tconst idealWidth = topCardWidth + totalPeekNeeded;\n\n\tif (availableWidth >= idealWidth) {\n\t\treturn {\n\t\t\tcompressionRatio: 1,\n\t\t\tshouldCollapse: false,\n\t\t\tadjustedPeekOffset: defaultPeekOffset,\n\t\t\tavailableSpace: totalPeekNeeded,\n\t\t};\n\t}\n\n\t// Compress peek offsets proportionally\n\tconst availableForPeek = Math.max(0, availableWidth - topCardWidth);\n\tconst minPeekNeeded = cascadeDepth * MIN_VISIBLE_PEEK;\n\n\tif (availableForPeek < minPeekNeeded) {\n\t\t// Not enough space - collapse\n\t\treturn {\n\t\t\tcompressionRatio: 0,\n\t\t\tshouldCollapse: true,\n\t\t\tadjustedPeekOffset: 0,\n\t\t\tavailableSpace: 0,\n\t\t};\n\t}\n\n\t// Calculate compressed peek offset\n\tconst compressionRatio = availableForPeek / totalPeekNeeded;\n\tconst adjustedPeekOffset = defaultPeekOffset * compressionRatio;\n\n\treturn {\n\t\tcompressionRatio,\n\t\tshouldCollapse: false,\n\t\tadjustedPeekOffset: Math.max(MIN_VISIBLE_PEEK, adjustedPeekOffset),\n\t\tavailableSpace: availableForPeek,\n\t};\n}\n\n/**\n * Get responsive card offset that compresses based on viewport.\n * Ensures every card has at least MIN_VISIBLE_PEEK visible past cards above it.\n */\nexport function getResponsiveCardOffset(\n\tcardIndex: number,\n\ttotalCards: number,\n\tcards: CardSpec[],\n\tlayoutMode: LayoutMode,\n\ttopCardWidth: number,\n\tadjustedPeekOffset: number,\n\tcompressionRatio: number,\n\tdefaultWidth: number = 480,\n): number {\n\tif (totalCards === 0) return 0;\n\n\tconst cardsAbove = totalCards - cardIndex - 1;\n\tif (cardsAbove === 0) return 0;\n\n\tif (layoutMode === 'side-by-side') {\n\t\t// Helper to get card width\n\t\tconst getWidth = (idx: number): number => {\n\t\t\tconst card = cards[idx];\n\t\t\tconst w = card?.width;\n\t\t\tif (w === undefined) return defaultWidth;\n\t\t\tif (typeof w === 'number') return w;\n\t\t\tif (w.endsWith('px')) return parseFloat(w) || defaultWidth;\n\t\t\treturn defaultWidth;\n\t\t};\n\n\t\t// Helper to get ideal offset for any card index (using standard side-by-side formula)\n\t\tconst getIdealOffset = (idx: number): number => {\n\t\t\tconst cardsAboveIdx = totalCards - idx - 1;\n\t\t\tif (cardsAboveIdx === 0) return 0;\n\t\t\tif (cardsAboveIdx === 1) return topCardWidth * compressionRatio + adjustedPeekOffset * (1 - compressionRatio);\n\t\t\tconst extraDepth = cardsAboveIdx - 1;\n\t\t\tconst secondOffset = topCardWidth * compressionRatio + adjustedPeekOffset * (1 - compressionRatio);\n\t\t\treturn secondOffset + extraDepth * adjustedPeekOffset;\n\t\t};\n\n\t\t// Compute adjusted offsets for ALL cards from top to bottom\n\t\t// This ensures cards account for adjustments made to cards above them\n\t\t//\n\t\t// Coordinate system (from viewport right edge):\n\t\t// - Card at offset O with width W has: right edge at O, left edge at O + W\n\t\t// - For card's left peek (24px) to be visible past cardAbove:\n\t\t// currentCard.leftEdge - MIN_VISIBLE_PEEK > cardAbove.leftEdge\n\t\t// (currentOffset + currentWidth - MIN_VISIBLE_PEEK) > (aboveOffset + aboveWidth)\n\t\t// currentOffset > aboveOffset + aboveWidth - currentWidth + MIN_VISIBLE_PEEK\n\n\t\tconst adjustedOffsets: number[] = new Array(totalCards).fill(0);\n\n\t\t// Process from top card (highest index) to bottom card (index 0)\n\t\tfor (let idx = totalCards - 1; idx >= 0; idx--) {\n\t\t\tconst ideal = getIdealOffset(idx);\n\t\t\tconst width = getWidth(idx);\n\n\t\t\t// Check if this card allows being covered (escape hatch)\n\t\t\tconst cardAtIdx = cards[idx];\n\t\t\tconst allowCover = cardAtIdx?.allowCover ?? false;\n\n\t\t\tif (allowCover) {\n\t\t\t\tadjustedOffsets[idx] = ideal;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Find minimum offset needed to peek past all cards above\n\t\t\tlet minRequired = 0;\n\t\t\tfor (let j = idx + 1; j < totalCards; j++) {\n\t\t\t\t// Use the ADJUSTED offset of cards above (already computed)\n\t\t\t\tconst aboveLeftEdge = adjustedOffsets[j] + getWidth(j);\n\t\t\t\tconst required = aboveLeftEdge - width + MIN_VISIBLE_PEEK;\n\t\t\t\tminRequired = Math.max(minRequired, required);\n\t\t\t}\n\n\t\t\tadjustedOffsets[idx] = Math.max(ideal, minRequired);\n\t\t}\n\n\t\treturn adjustedOffsets[cardIndex];\n\t}\n\n\t// Cascade mode - use adjusted peek offset\n\tconst card = cards[cardIndex];\n\tconst peekOffset = card?.peekOffset ?? adjustedPeekOffset;\n\treturn cardsAbove * peekOffset * compressionRatio + cardsAbove * MIN_VISIBLE_PEEK * (1 - compressionRatio);\n}\n\n// =============================================================================\n// Width Utilities\n// =============================================================================\n\n/**\n * Normalize width to CSS value.\n */\nexport function normalizeWidth(width: string | number | undefined, defaultWidth: string | number): string {\n\tif (width === undefined) {\n\t\treturn typeof defaultWidth === 'number' ? `${defaultWidth}px` : defaultWidth;\n\t}\n\treturn typeof width === 'number' ? `${width}px` : width;\n}\n\n/**\n * Parse width to pixels (for offset calculations).\n * Returns undefined if width cannot be parsed to pixels.\n */\nexport function parseWidthToPixels(width: string | number | undefined): number | undefined {\n\tif (width === undefined) return undefined;\n\tif (typeof width === 'number') return width;\n\n\t// Handle px values\n\tif (width.endsWith('px')) {\n\t\tconst parsed = parseFloat(width);\n\t\treturn isNaN(parsed) ? undefined : parsed;\n\t}\n\n\t// Handle rem values (assume 16px base)\n\tif (width.endsWith('rem')) {\n\t\tconst parsed = parseFloat(width);\n\t\treturn isNaN(parsed) ? undefined : parsed * 16;\n\t}\n\n\t// Can't parse percentage or other values without DOM measurement\n\treturn undefined;\n}\n\n// =============================================================================\n// Z-Index Utilities\n// =============================================================================\n\n/**\n * Calculate z-index for a card based on its position in the stack.\n */\nexport function getCardZIndex(cardIndex: number, zIndexBase: number): number {\n\treturn zIndexBase + cardIndex * 10;\n}\n\n// =============================================================================\n// Visibility Utilities\n// =============================================================================\n\n/**\n * Determine which cards should be rendered based on peekDepth.\n * Returns indices of cards that should be rendered (from bottom to top).\n */\nexport function getVisibleCardIndices(totalCards: number, peekDepth: number): number[] {\n\tif (totalCards === 0) return [];\n\n\t// Always render the top card\n\tconst startIndex = Math.max(0, totalCards - peekDepth - 1);\n\tconst indices: number[] = [];\n\n\tfor (let i = startIndex; i < totalCards; i++) {\n\t\tindices.push(i);\n\t}\n\n\treturn indices;\n}\n\n/**\n * Check if a card should be rendered based on peekDepth.\n */\nexport function isCardVisible(cardIndex: number, totalCards: number, peekDepth: number): boolean {\n\tif (totalCards === 0) return false;\n\tconst startIndex = Math.max(0, totalCards - peekDepth - 1);\n\treturn cardIndex >= startIndex;\n}\n","'use client';\n\nimport { useCallback, useRef, useState } from 'react';\nimport { useReducedMotion } from 'motion/react';\n\nimport type { PeekGestureConfig } from './stack.types';\n\n// =============================================================================\n// Constants\n// =============================================================================\n\nconst DEFAULT_HOVER_EXPANSION = 48; // px\nconst DEFAULT_DRAG_THRESHOLD = 80; // px\nconst DEFAULT_VELOCITY_THRESHOLD = 400; // px/s\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport type UsePeekGesturesOptions = PeekGestureConfig & {\n\t/** Card index in the stack */\n\tcardIndex: number;\n\t/** Total cards in stack */\n\ttotalCards: number;\n\t/** Callback when click on peek zone (dismiss cards above) */\n\tonPeekClick: () => void;\n\t/** Callback when drag completes dismiss threshold */\n\tonPeekDragDismiss: () => void;\n\t/** Callback during drag to update multi-card offset */\n\tonPeekDrag?: (dragOffset: number) => void;\n\t/** Callback when drag ends without dismiss */\n\tonPeekDragCancel?: () => void;\n};\n\nexport type UsePeekGesturesResult = {\n\t/** Whether peek zone is hovered */\n\tisHovered: boolean;\n\t/** Whether actively dragging */\n\tisDragging: boolean;\n\t/** Current drag offset (positive = dragging right/dismiss direction) */\n\tdragOffset: number;\n\t/** Hover expansion amount in px */\n\thoverExpansion: number;\n\t/** Handlers for the peek zone element */\n\thandlers: {\n\t\tonMouseEnter: () => void;\n\t\tonMouseLeave: () => void;\n\t\tonClick: (e: React.MouseEvent) => void;\n\t\tonPointerDown: (e: React.PointerEvent) => void;\n\t\tonPointerMove: (e: React.PointerEvent) => void;\n\t\tonPointerUp: (e: React.PointerEvent) => void;\n\t\tonPointerCancel: (e: React.PointerEvent) => void;\n\t};\n};\n\n// =============================================================================\n// Hook\n// =============================================================================\n\n/**\n * Hook for peek zone interactions: hover expansion, click-to-dismiss, drag-to-dismiss.\n * Works on both mobile and desktop.\n */\nexport function usePeekGestures(options: UsePeekGesturesOptions): UsePeekGesturesResult {\n\tconst {\n\t\tenabled = true,\n\t\tdragToDismiss = true,\n\t\thoverExpansion = DEFAULT_HOVER_EXPANSION,\n\t\tdragThreshold = DEFAULT_DRAG_THRESHOLD,\n\t\tdragVelocityThreshold = DEFAULT_VELOCITY_THRESHOLD,\n\t\tcardIndex,\n\t\ttotalCards,\n\t\tonPeekClick,\n\t\tonPeekDragDismiss,\n\t\tonPeekDrag,\n\t\tonPeekDragCancel,\n\t} = options;\n\n\tconst prefersReducedMotion = useReducedMotion();\n\n\tconst [isHovered, setIsHovered] = useState(false);\n\tconst [isDragging, setIsDragging] = useState(false);\n\tconst [dragOffset, setDragOffset] = useState(0);\n\n\t// Tracking refs for drag\n\tconst startXRef = useRef(0);\n\tconst startTimeRef = useRef(0);\n\tconst pointerIdRef = useRef<number | null>(null);\n\tconst hasDraggedRef = useRef(false);\n\n\t// Only enable for non-top cards\n\tconst isTopCard = cardIndex === totalCards - 1;\n\tconst isEnabled = enabled && !isTopCard;\n\n\t// Handlers\n\tconst handleMouseEnter = useCallback(() => {\n\t\tif (!isEnabled || prefersReducedMotion) return;\n\t\tsetIsHovered(true);\n\t}, [isEnabled, prefersReducedMotion]);\n\n\tconst handleMouseLeave = useCallback(() => {\n\t\tif (!isEnabled) return;\n\t\tsetIsHovered(false);\n\t}, [isEnabled]);\n\n\tconst handleClick = useCallback(\n\t\t(e: React.MouseEvent) => {\n\t\t\tif (!isEnabled) return;\n\n\t\t\t// Don't trigger click if we just finished dragging\n\t\t\tif (hasDraggedRef.current) {\n\t\t\t\thasDraggedRef.current = false;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\te.stopPropagation();\n\t\t\tonPeekClick();\n\t\t},\n\t\t[isEnabled, onPeekClick],\n\t);\n\n\tconst handlePointerDown = useCallback(\n\t\t(e: React.PointerEvent) => {\n\t\t\tif (!isEnabled || !dragToDismiss) return;\n\n\t\t\t// Only handle primary pointer\n\t\t\tif (e.pointerType === 'mouse' && e.button !== 0) return;\n\n\t\t\tpointerIdRef.current = e.pointerId;\n\t\t\t(e.target as HTMLElement).setPointerCapture(e.pointerId);\n\n\t\t\tstartXRef.current = e.clientX;\n\t\t\tstartTimeRef.current = Date.now();\n\t\t\thasDraggedRef.current = false;\n\t\t\tsetIsDragging(true);\n\n\t\t\te.stopPropagation();\n\t\t},\n\t\t[isEnabled, dragToDismiss],\n\t);\n\n\tconst handlePointerMove = useCallback(\n\t\t(e: React.PointerEvent) => {\n\t\t\tif (!isEnabled || pointerIdRef.current !== e.pointerId) return;\n\n\t\t\tconst deltaX = e.clientX - startXRef.current;\n\n\t\t\t// Only allow dragging to the right (positive = dismiss direction)\n\t\t\tconst clampedDelta = Math.max(0, deltaX);\n\n\t\t\t// Mark as dragged if moved more than 5px (prevents accidental drags)\n\t\t\tif (clampedDelta > 5) {\n\t\t\t\thasDraggedRef.current = true;\n\t\t\t}\n\n\t\t\tsetDragOffset(clampedDelta);\n\t\t\tonPeekDrag?.(clampedDelta);\n\n\t\t\te.stopPropagation();\n\t\t},\n\t\t[isEnabled, onPeekDrag],\n\t);\n\n\tconst handlePointerUp = useCallback(\n\t\t(e: React.PointerEvent) => {\n\t\t\tif (!isEnabled || pointerIdRef.current !== e.pointerId) return;\n\n\t\t\t(e.target as HTMLElement).releasePointerCapture(e.pointerId);\n\n\t\t\tconst deltaX = e.clientX - startXRef.current;\n\t\t\tconst deltaTime = Date.now() - startTimeRef.current;\n\t\t\tconst velocity = deltaTime > 0 ? (deltaX / deltaTime) * 1000 : 0;\n\n\t\t\t// Check if should dismiss\n\t\t\tconst shouldDismiss = deltaX > dragThreshold || velocity > dragVelocityThreshold;\n\n\t\t\tif (shouldDismiss && deltaX > 0) {\n\t\t\t\tonPeekDragDismiss();\n\t\t\t} else {\n\t\t\t\tonPeekDragCancel?.();\n\t\t\t}\n\n\t\t\t// Reset state\n\t\t\tpointerIdRef.current = null;\n\t\t\tsetIsDragging(false);\n\t\t\tsetDragOffset(0);\n\n\t\t\te.stopPropagation();\n\t\t},\n\t\t[isEnabled, dragThreshold, dragVelocityThreshold, onPeekDragDismiss, onPeekDragCancel],\n\t);\n\n\tconst handlePointerCancel = useCallback(\n\t\t(e: React.PointerEvent) => {\n\t\t\tif (pointerIdRef.current === e.pointerId) {\n\t\t\t\tpointerIdRef.current = null;\n\t\t\t\tsetIsDragging(false);\n\t\t\t\tsetDragOffset(0);\n\t\t\t\tonPeekDragCancel?.();\n\t\t\t}\n\t\t},\n\t\t[onPeekDragCancel],\n\t);\n\n\treturn {\n\t\tisHovered,\n\t\tisDragging,\n\t\tdragOffset,\n\t\thoverExpansion: isEnabled && !prefersReducedMotion ? hoverExpansion : 0,\n\t\thandlers: {\n\t\t\tonMouseEnter: handleMouseEnter,\n\t\t\tonMouseLeave: handleMouseLeave,\n\t\t\tonClick: handleClick,\n\t\t\tonPointerDown: handlePointerDown,\n\t\t\tonPointerMove: handlePointerMove,\n\t\t\tonPointerUp: handlePointerUp,\n\t\t\tonPointerCancel: handlePointerCancel,\n\t\t},\n\t};\n}\n","'use client';\n\nimport * as React from 'react';\nimport { memo, useMemo, useCallback, useState } from 'react';\nimport { motion, useReducedMotion } from 'motion/react';\n\nimport { cn } from '../../lib/utils';\n\nimport {\n\tcreateEnterTransition,\n\tcreateExitTransition,\n\tcreateOffsetTransition,\n\tpeekHoverSpring,\n\tpeekDragSpring,\n} from './stack-animations';\nimport { CardReadyProvider, useCardInjectedProps, useStackContext } from './stack-context';\nimport { StackHeader } from './stack-header';\nimport type { AnimationConfig, CardSpec, CardStackApi, GestureConfig, PeekGestureConfig } from './stack.types';\nimport { getCardZIndex, getResponsiveCardOffset, normalizeWidth } from './stack-utils';\nimport { usePeekGestures } from './use-peek-gestures';\nimport type { StackGestureBind } from './use-stack-gestures';\n\n/** Default hover expansion in pixels */\nconst DEFAULT_HOVER_EXPANSION = 48;\nconst reducedMotionTransition = { duration: 0 } as const;\n\nexport type StackCardProps = {\n\t/** The card specification */\n\tcard: CardSpec;\n\t/** Index of this card in the stack */\n\tindex: number;\n\t/** Total number of cards in the stack */\n\ttotalCards: number;\n\t/** Width of the top card (for side-by-side calculations) */\n\ttopCardWidth: number;\n\t/** Animation configuration */\n\tanimation?: AnimationConfig;\n\t/** Whether this is a mobile viewport */\n\tisMobile?: boolean;\n\t/** Gesture configuration for mobile */\n\tgestureConfig?: GestureConfig;\n\t/** Peek gesture configuration */\n\tpeekGestureConfig?: PeekGestureConfig;\n\t/** Custom header renderer */\n\trenderHeader?: (card: CardSpec, api: CardStackApi) => React.ReactNode;\n\t/** Compression ratio for responsive offset (1 = full, 0 = collapsed) */\n\tcompressionRatio?: number;\n\t/** Adjusted peek offset after compression */\n\tadjustedPeekOffset?: number;\n\t/** Drag state from gesture hook (for top card swipe-to-dismiss) */\n\tdragX?: number;\n\t/** Gesture bind from @use-gesture/react */\n\tgestureBind?: StackGestureBind;\n\t/** Whether this card's peek zone is hovered (viewport-coordinated) */\n\tisPeekHovered?: boolean;\n\t/** Callback when peek hover starts */\n\tonPeekHoverStart?: (cardIndex: number) => void;\n\t/** Callback when peek hover ends */\n\tonPeekHoverEnd?: (cardIndex: number) => void;\n\t/** Peek drag offset applied to this card (when cards above are being dragged via peek zone) */\n\tpeekDragOffset?: number;\n\t/** Callback when peek drag starts on this card's peek zone */\n\tonPeekDragStart?: (cardIndex: number) => void;\n\t/** Callback during peek drag on this card's peek zone */\n\tonPeekDrag?: (cardIndex: number, offset: number) => void;\n\t/** Callback when peek drag ends on this card's peek zone */\n\tonPeekDragEnd?: (cardIndex: number, shouldDismiss: boolean) => void;\n\t/** Whether this is the last card (for exit animation with fade) */\n\tisLastCard?: boolean;\n\t/** Additional class name for the card */\n\tclassName?: string;\n};\n\nfunction StackCardInner({\n\tcard,\n\tindex,\n\ttotalCards,\n\ttopCardWidth,\n\tanimation,\n\tisMobile = false,\n\trenderHeader,\n\tpeekGestureConfig,\n\tcompressionRatio = 1,\n\tadjustedPeekOffset,\n\tdragX = 0,\n\tgestureBind,\n\tisPeekHovered = false,\n\tonPeekHoverStart,\n\tonPeekHoverEnd,\n\tpeekDragOffset = 0,\n\tonPeekDragStart,\n\tonPeekDrag,\n\tonPeekDragEnd,\n\tisLastCard = false,\n\tclassName,\n}: StackCardProps) {\n\tconst { config, api, state } = useStackContext();\n\tconst prefersReducedMotion = useReducedMotion();\n\tconst injectedProps = useCardInjectedProps(card.id);\n\n\t// Track when enter animation completes - used by useCardReady() hook\n\t// Start true if reduced motion is preferred (no animation to wait for)\n\tconst [isAnimationComplete, setAnimationComplete] = useState(prefersReducedMotion ?? false);\n\n\t// Handler for animation completion - fires when any animation on this element completes\n\t// The first animation to complete after mount is the enter animation\n\tconst handleAnimationComplete = useCallback(() => {\n\t\tsetAnimationComplete(true);\n\t}, []);\n\n\t// Calculate card positioning\n\tconst isTopCard = index === totalCards - 1;\n\tconst isSecondCard = index === totalCards - 2;\n\t// In side-by-side mode, second card is fully visible - no peek needed\n\t// Peek zone only for cards that are actually peeking (partially hidden under cards above)\n\tconst hasPeekZone = !isTopCard && !isMobile && !(config.layoutMode === 'side-by-side' && isSecondCard);\n\tconst zIndex = getCardZIndex(index, config.zIndexBase);\n\n\t// Use adjusted peek offset or default\n\tconst effectivePeekOffset = adjustedPeekOffset ?? config.defaultPeekOffset;\n\n\t// Calculate responsive offset (compresses as viewport shrinks)\n\tconst baseOffset = useMemo(\n\t\t() =>\n\t\t\tgetResponsiveCardOffset(\n\t\t\t\tindex,\n\t\t\t\ttotalCards,\n\t\t\t\tstate.cards,\n\t\t\t\tconfig.layoutMode,\n\t\t\t\ttopCardWidth,\n\t\t\t\teffectivePeekOffset,\n\t\t\t\tcompressionRatio,\n\t\t\t\ttypeof config.defaultWidth === 'number' ? config.defaultWidth : 480,\n\t\t\t),\n\t\t[index, totalCards, state.cards, config.layoutMode, topCardWidth, effectivePeekOffset, compressionRatio, config.defaultWidth],\n\t);\n\n\t// Card width\n\tconst cardWidth = isMobile ? '100%' : normalizeWidth(card.width, config.defaultWidth);\n\n\t// Animation transitions: enter/exit tweens, offset spring after settle\n\tconst offsetTransition = createOffsetTransition(animation);\n\tconst enterTransition = createEnterTransition(animation);\n\tconst exitTransition = createExitTransition(animation);\n\n\t// Close handler\n\tconst handleClose = useCallback(() => {\n\t\tapi.dismiss(card.id);\n\t}, [api, card.id]);\n\n\t// Peek gesture callbacks\n\tconst handlePeekClick = useCallback(() => {\n\t\tconst cardsAbove = state.cards.slice(index + 1);\n\t\tif (cardsAbove.some((c) => c.dismissable === false)) return;\n\t\tapi.popTo(card.id);\n\t}, [api, card.id, state.cards, index]);\n\n\tconst handlePeekDragDismiss = useCallback(() => {\n\t\tconst cardsAbove = state.cards.slice(index + 1);\n\t\tif (cardsAbove.some((c) => c.dismissable === false)) return;\n\t\tonPeekDragEnd?.(index, true);\n\t}, [index, onPeekDragEnd, state.cards]);\n\n\tconst handlePeekDrag = useCallback(\n\t\t(offset: number) => {\n\t\t\tonPeekDrag?.(index, offset);\n\t\t},\n\t\t[index, onPeekDrag],\n\t);\n\n\tconst handlePeekDragCancel = useCallback(() => {\n\t\tonPeekDragEnd?.(index, false);\n\t}, [index, onPeekDragEnd]);\n\n\t// Peek hover callbacks (forward to viewport)\n\tconst handlePeekHoverStart = useCallback(() => {\n\t\tonPeekHoverStart?.(index);\n\t}, [index, onPeekHoverStart]);\n\n\tconst handlePeekHoverEnd = useCallback(() => {\n\t\tonPeekHoverEnd?.(index);\n\t}, [index, onPeekHoverEnd]);\n\n\t// Peek gestures hook\n\tconst peekGestures = usePeekGestures({\n\t\t...peekGestureConfig,\n\t\tcardIndex: index,\n\t\ttotalCards,\n\t\tonPeekClick: handlePeekClick,\n\t\tonPeekDragDismiss: handlePeekDragDismiss,\n\t\tonPeekDrag: handlePeekDrag,\n\t\tonPeekDragCancel: handlePeekDragCancel,\n\t});\n\n\t// Calculate hover expansion using viewport-coordinated hover state\n\tconst hoverExpansion = hasPeekZone && isPeekHovered && !peekGestures.isDragging && !prefersReducedMotion\n\t\t? (peekGestureConfig?.hoverExpansion ?? DEFAULT_HOVER_EXPANSION)\n\t\t: 0;\n\n\t// Combined X transform: base offset + swipe drag + hover expansion + peek drag from other cards\n\t// Note: peekDragOffset is applied when cards ABOVE this one are being dragged\n\tconst xOffset = -baseOffset + dragX - hoverExpansion + peekDragOffset;\n\n\t// Render the card component with injected props, wrapped in CardReadyProvider\n\tconst CardComponent = card.Component;\n\tconst cardContent = useMemo(() => {\n\t\treturn (\n\t\t\t<CardReadyProvider isAnimationComplete={isAnimationComplete}>\n\t\t\t\t<CardComponent {...(card.props as object)} {...injectedProps} />\n\t\t\t</CardReadyProvider>\n\t\t);\n\t}, [CardComponent, card.props, injectedProps, isAnimationComplete]);\n\n\t// Custom or default header\n\tconst headerContent = renderHeader ? (\n\t\trenderHeader(card, api)\n\t) : (\n\t\t<StackHeader card={card} onClose={handleClose} />\n\t);\n\n\t// Animation states\n\tconst animateX = xOffset;\n\tconst initialX = prefersReducedMotion ? xOffset : '100%';\n\tconst exitX = prefersReducedMotion ? xOffset : '100%';\n\t// Last card fades out as it slides for smoother exit when backdrop is also fading\n\tconst exitOpacity = prefersReducedMotion ? 0 : (isLastCard ? 0 : 1);\n\n\t// Enter uses snappy tween until first settle; then spring for offset/peek.\n\t// Peek/drag always win while interacting.\n\tlet activeTransition = prefersReducedMotion\n\t\t? reducedMotionTransition\n\t\t: isAnimationComplete\n\t\t\t? offsetTransition\n\t\t\t: enterTransition;\n\tif (!prefersReducedMotion) {\n\t\tif (peekGestures.isDragging || peekDragOffset > 0) {\n\t\t\tactiveTransition = peekDragSpring;\n\t\t} else if (isPeekHovered) {\n\t\t\tactiveTransition = peekHoverSpring;\n\t\t}\n\t}\n\n\t// Exit always honors the configured tween; reduced motion settles immediately.\n\tconst exitAnimation = {\n\t\tx: exitX,\n\t\topacity: exitOpacity,\n\t\ttransition: prefersReducedMotion ? reducedMotionTransition : exitTransition,\n\t};\n\n\treturn (\n\t\t<motion.div\n\t\t\tdata-slot=\"stack-card\"\n\t\t\tdata-card-id={card.id}\n\t\t\tdata-card-index={index}\n\t\t\tdata-is-top={isTopCard}\n\t\t\tdata-offset={baseOffset}\n\t\t\tinitial={{ x: initialX, opacity: 1 }}\n\t\t\tanimate={{ x: animateX, opacity: 1 }}\n\t\t\texit={exitAnimation}\n\t\t\ttransition={activeTransition}\n\t\t\tonAnimationComplete={handleAnimationComplete}\n\t\t\tstyle={{\n\t\t\t\tposition: 'fixed',\n\t\t\t\ttop: 0,\n\t\t\t\tright: 0,\n\t\t\t\theight: '100dvh',\n\t\t\t\twidth: cardWidth,\n\t\t\t\tzIndex,\n\t\t\t\t// On mobile, allow vertical pan (scroll) but handle horizontal ourselves\n\t\t\t\t// This prevents conflict with iOS Safari gestures while allowing content scroll\n\t\t\t\ttouchAction: isMobile ? 'pan-y pinch-zoom' : undefined,\n\t\t\t}}\n\t\t\tclassName={cn(\n\t\t\t\t'flex flex-col',\n\t\t\t\t'bg-background',\n\t\t\t\t'shadow-lg',\n\t\t\t\t'border-l border-border/50',\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t// Gesture binding for swipe-to-dismiss (from @use-gesture/react)\n\t\t\t{...(isTopCard && isMobile && gestureBind ? gestureBind() : {})}\n\t\t>\n\t\t\t{/* Peek Zone - invisible overlay for gesture handling */}\n\t\t\t{hasPeekZone && (\n\t\t\t\t<div\n\t\t\t\t\tdata-slot=\"peek-zone\"\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t'absolute inset-y-0',\n\t\t\t\t\t\t'cursor-pointer',\n\t\t\t\t\t\t// Visual feedback during hover/drag (using viewport-coordinated state)\n\t\t\t\t\t\tisPeekHovered && 'bg-primary/5',\n\t\t\t\t\t\tpeekGestures.isDragging && 'bg-primary/10',\n\t\t\t\t\t)}\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\t// Peek zone covers the visible peek area (baseOffset determines how much is visible)\n\t\t\t\t\t\t// Minimum 32px, expands when hovered to keep mouse inside during animation\n\t\t\t\t\t\tleft: 0,\n\t\t\t\t\t\twidth: isPeekHovered\n\t\t\t\t\t\t\t? Math.max(32, baseOffset) + hoverExpansion\n\t\t\t\t\t\t\t: Math.max(32, baseOffset),\n\t\t\t\t\t\tzIndex: zIndex + 1,\n\t\t\t\t\t\t// Smooth transition to prevent sudden size jumps\n\t\t\t\t\t\ttransition: 'width 0.15s ease-out',\n\t\t\t\t\t}}\n\t\t\t\t\t// Use viewport-coordinated hover + local gesture handlers\n\t\t\t\t\tonMouseEnter={handlePeekHoverStart}\n\t\t\t\t\tonMouseLeave={handlePeekHoverEnd}\n\t\t\t\t\tonClick={peekGestures.handlers.onClick}\n\t\t\t\t\tonPointerDown={peekGestures.handlers.onPointerDown}\n\t\t\t\t\tonPointerMove={peekGestures.handlers.onPointerMove}\n\t\t\t\t\tonPointerUp={peekGestures.handlers.onPointerUp}\n\t\t\t\t\tonPointerCancel={peekGestures.handlers.onPointerCancel}\n\t\t\t\t/>\n\t\t\t)}\n\n\t\t\t{/* Header */}\n\t\t\t{headerContent}\n\n\t\t\t{/* Content */}\n\t\t\t<div\n\t\t\t\tdata-slot=\"stack-card-content\"\n\t\t\t\tclassName=\"flex-1 overflow-auto\"\n\t\t\t\tstyle={{\n\t\t\t\t\t// Allow vertical scroll but let us handle horizontal\n\t\t\t\t\ttouchAction: isMobile ? 'pan-y pinch-zoom' : undefined,\n\t\t\t\t}}\n\t\t\t\t// Gesture binding also on content area (touch target is often inside here)\n\t\t\t\t{...(isTopCard && isMobile && gestureBind ? gestureBind() : {})}\n\t\t\t>\n\t\t\t\t{cardContent}\n\t\t\t</div>\n\t\t</motion.div>\n\t);\n}\n\n// Memoize to prevent re-renders when other cards change\nexport const StackCard = memo(StackCardInner);\n","'use client';\n\nimport { useState, useCallback, useRef } from 'react';\nimport { useDrag } from '@use-gesture/react';\nimport { useReducedMotion } from 'motion/react';\n\nimport type { GestureConfig } from './stack.types';\n\n// =============================================================================\n// Constants\n// =============================================================================\n\n/** Distance threshold to trigger dismiss */\nconst DEFAULT_SWIPE_THRESHOLD = 120; // px\n\n/** Velocity threshold for quick flick dismiss */\nconst DEFAULT_VELOCITY_THRESHOLD = 0.6; // px/ms (use-gesture uses px/ms)\n\n/** Minimum drag distance before velocity dismiss can apply */\nconst MIN_VELOCITY_DISTANCE = 60; // px\n\n/** Left edge zone to ignore (avoid iOS Safari back gesture conflict) */\nconst EDGE_IGNORE_ZONE = 30; // px from left edge\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport type UseStackGesturesOptions = GestureConfig & {\n\t/** Whether gestures are enabled */\n\tenabled?: boolean;\n\t/** Callback when swipe completes and should dismiss */\n\tonDismiss: () => void;\n};\n\nexport type StackGestureBind = () => object;\n\nexport type UseStackGesturesResult = {\n\t/** Current drag X offset */\n\tdragX: number;\n\t/** Whether currently dragging */\n\tisDragging: boolean;\n\t/** Bind function to attach to the draggable element */\n\tbind: StackGestureBind;\n};\n\n// =============================================================================\n// Hook\n// =============================================================================\n\n/**\n * Hook for swipe-to-dismiss gesture on stack cards using @use-gesture/react.\n *\n * Features:\n * - Only allows swiping to the right (positive X direction)\n * - Ignores touches near left edge (avoids iOS Safari back gesture conflict)\n * - Requires horizontal intent before activating (won't interfere with scroll)\n * - Dismisses on release after distance or velocity threshold\n * - Auto-dismisses near the end of the drag (configurable)\n * - 1:1 finger tracking for responsive feel\n */\nexport function useStackGestures(options: UseStackGesturesOptions): UseStackGesturesResult {\n\tconst {\n\t\tenabled = true,\n\t\tswipeToPop = true,\n\t\tswipeThreshold = DEFAULT_SWIPE_THRESHOLD,\n\t\tvelocityThreshold = DEFAULT_VELOCITY_THRESHOLD,\n\t\tautoDismissThreshold,\n\t\tonDismiss,\n\t} = options;\n\n\n\tconst prefersReducedMotion = useReducedMotion();\n\tconst isEnabled = enabled && swipeToPop && !prefersReducedMotion;\n\n\tconst [dragX, setDragX] = useState(0);\n\tconst [isDragging, setIsDragging] = useState(false);\n\n\tconst handleDismiss = useCallback(() => {\n\t\tonDismiss();\n\t}, [onDismiss]);\n\n\tconst dismissedRef = useRef(false);\n\tconst velocityMinDistance = Math.max(MIN_VELOCITY_DISTANCE, swipeThreshold * 0.25);\n\n\tconst bind = useDrag(\n\t\t({ active, movement: [mx], velocity: [vx], direction: [dx], initial: [initialX], xy: [currentX], cancel, first }) => {\n\t\t\t// On first event, check if touch started near left edge\n\t\t\tif (first && initialX < EDGE_IGNORE_ZONE) {\n\t\t\t\tcancel();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (first) {\n\t\t\t\tdismissedRef.current = false;\n\t\t\t}\n\n\t\t\t// Only allow rightward movement (positive direction)\n\t\t\t// If user is dragging left, clamp to 0\n\t\t\tconst clampedX = Math.max(0, mx);\n\n\t\t\tif (active) {\n\t\t\t\tconst canAutoDismiss =\n\t\t\t\t\tautoDismissThreshold !== undefined &&\n\t\t\t\t\t!dismissedRef.current &&\n\t\t\t\t\tdx > 0 &&\n\t\t\t\t\tclampedX >= 24 &&\n\t\t\t\t\tcurrentX >= autoDismissThreshold;\n\n\t\t\t\tif (canAutoDismiss) {\n\t\t\t\t\tdismissedRef.current = true;\n\t\t\t\t\tsetDragX(0);\n\t\t\t\t\tsetIsDragging(false);\n\t\t\t\t\thandleDismiss();\n\t\t\t\t\tcancel();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetDragX(clampedX);\n\t\t\t\tsetIsDragging(true);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!dismissedRef.current) {\n\t\t\t\tconst shouldDismiss =\n\t\t\t\t\tdx > 0 &&\n\t\t\t\t\t(clampedX > swipeThreshold || (vx > velocityThreshold && clampedX > velocityMinDistance));\n\n\t\t\t\tif (shouldDismiss) {\n\t\t\t\t\thandleDismiss();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Reset state\n\t\t\tsetDragX(0);\n\t\t\tsetIsDragging(false);\n\t\t},\n\t\t{\n\t\t\tenabled: isEnabled,\n\t\t\t// Only activate after moving 10px (prevents accidental triggers)\n\t\t\tthreshold: 10,\n\t\t\t// Lock to horizontal axis once gesture starts\n\t\t\taxis: 'x',\n\t\t\t// Filter by direction - only track if moving more horizontally than vertically\n\t\t\tfilterTaps: true,\n\t\t\t// Use touch-action to allow vertical scroll\n\t\t\tpointer: {\n\t\t\t\ttouch: true,\n\t\t\t},\n\t\t},\n\t);\n\n\treturn {\n\t\tdragX,\n\t\tisDragging,\n\t\tbind,\n\t};\n}\n","'use client';\n\nimport { useCallback, useEffect, useState } from 'react';\n\nimport type { MobileConfig } from './stack.types';\n\n// =============================================================================\n// Constants\n// =============================================================================\n\nconst DEFAULT_MOBILE_BREAKPOINT = 768;\n\n// =============================================================================\n// Hook\n// =============================================================================\n\nexport type UseStackResponsiveOptions = MobileConfig;\n\nexport type UseStackResponsiveResult = {\n\t/** Whether the current viewport is mobile-sized */\n\tisMobile: boolean;\n\t/** Current viewport width */\n\tviewportWidth: number;\n\t/** The breakpoint being used */\n\tbreakpoint: number;\n};\n\n/**\n * Hook to detect mobile viewport and provide responsive information.\n */\nexport function useStackResponsive(\n\toptions: UseStackResponsiveOptions = {},\n): UseStackResponsiveResult {\n\tconst { breakpoint = DEFAULT_MOBILE_BREAKPOINT } = options;\n\n\t// Initialize with SSR-safe defaults\n\tconst [state, setState] = useState<{ isMobile: boolean; viewportWidth: number }>(() => {\n\t\t// During SSR, assume desktop\n\t\tif (typeof window === 'undefined') {\n\t\t\treturn { isMobile: false, viewportWidth: 1024 };\n\t\t}\n\t\tconst width = window.innerWidth;\n\t\treturn { isMobile: width < breakpoint, viewportWidth: width };\n\t});\n\n\tconst updateState = useCallback(() => {\n\t\tconst width = window.innerWidth;\n\t\tsetState((prev) => {\n\t\t\tconst isMobile = width < breakpoint;\n\t\t\tif (prev.isMobile === isMobile && prev.viewportWidth === width) {\n\t\t\t\treturn prev;\n\t\t\t}\n\t\t\treturn { isMobile, viewportWidth: width };\n\t\t});\n\t}, [breakpoint]);\n\n\tuseEffect(() => {\n\t\t// Update on mount (in case SSR assumption was wrong)\n\t\tupdateState();\n\n\t\t// Listen for resize\n\t\twindow.addEventListener('resize', updateState);\n\t\treturn () => window.removeEventListener('resize', updateState);\n\t}, [updateState]);\n\n\treturn {\n\t\tisMobile: state.isMobile,\n\t\tviewportWidth: state.viewportWidth,\n\t\tbreakpoint,\n\t};\n}\n\n/**\n * Simple hook to just get isMobile boolean.\n */\nexport function useIsMobile(breakpoint = DEFAULT_MOBILE_BREAKPOINT): boolean {\n\tconst { isMobile } = useStackResponsive({ breakpoint });\n\treturn isMobile;\n}\n","'use client';\n\nimport * as React from 'react';\nimport { useMemo, useState, useCallback, useEffect, useRef } from 'react';\nimport { AnimatePresence } from 'motion/react';\nimport { createPortal } from 'react-dom';\n\nimport { cn } from '../../lib/utils';\n\nimport { PORTAL_ROOT_ID, useRootPortalContainer } from '@constructive-io/ui/portal';\n\nimport { StackBackdrop } from './stack-backdrop';\nimport { StackCard } from './stack-card';\nimport { useStackCards, useStackContext } from './stack-context';\nimport type { BackdropConfig, CardStackViewportProps } from './stack.types';\nimport { useStackGestures } from './use-stack-gestures';\nimport { useStackResponsive } from './use-stack-responsive';\nimport {\n\tcalculateResponsiveOffset,\n\tisCardVisible,\n\tparseWidthToPixels,\n\ttype ResponsiveOffsetResult,\n} from './stack-utils';\n\n// =============================================================================\n// Constants\n// =============================================================================\n\nconst DEFAULT_PEEK_DEPTH = 2;\n// =============================================================================\n// Types\n// =============================================================================\n\ntype PeekDragState = {\n\t/** Index of the card whose peek zone is being dragged (-1 = none) */\n\tsourceIndex: number;\n\t/** Current drag offset in pixels */\n\toffset: number;\n};\n\ntype PeekHoverState = {\n\t/** Index of the card whose peek zone is hovered (-1 = none) */\n\thoveredIndex: number;\n};\n\n// =============================================================================\n// Component\n// =============================================================================\n\nexport function CardStackViewport({\n\tbackdrop = true,\n\trenderBackdrop,\n\trenderHeader,\n\trenderEmpty,\n\tpeekDepth = DEFAULT_PEEK_DEPTH,\n\tanimation,\n\tmobile,\n\tpeekGestures,\n\tclassName,\n}: CardStackViewportProps) {\n\tconst { config, api } = useStackContext();\n\tconst cards = useStackCards();\n\n\t// Responsive behavior\n\tconst { isMobile, viewportWidth } = useStackResponsive(mobile);\n\n\t// Peek drag state - tracks which card's peek zone is being dragged\n\tconst [peekDrag, setPeekDrag] = useState<PeekDragState>({ sourceIndex: -1, offset: 0 });\n\n\t// Peek hover state - only one card can be hovered at a time (viewport-coordinated)\n\tconst [peekHover, setPeekHover] = useState<PeekHoverState>({ hoveredIndex: -1 });\n\tconst hoverEndTimeoutRef = useRef<NodeJS.Timeout | null>(null);\n\n\t// Track previous card count to detect stack changes\n\tconst prevCardCountRef = useRef(cards.length);\n\n\t// Track if exit animations have completed.\n\t// Key insight: This starts true (no animations pending when empty).\n\t// When cards appear, we set it to false (animations may be needed).\n\t// When cards disappear, it's still false from previous render, so AnimatePresence runs exits.\n\t// Only after onExitComplete fires do we set it back to true.\n\tconst [exitComplete, setExitComplete] = useState(cards.length === 0);\n\n\t// When cards appear, mark exit as not complete (we have active content)\n\tuseEffect(() => {\n\t\tif (cards.length > 0) {\n\t\t\tsetExitComplete(false);\n\t\t}\n\t}, [cards.length]);\n\n\t// Clear hover state when stack changes (cards added/removed)\n\tuseEffect(() => {\n\t\tif (cards.length !== prevCardCountRef.current) {\n\t\t\t// Stack changed - clear any hover state to prevent stale highlights\n\t\t\tsetPeekHover({ hoveredIndex: -1 });\n\t\t\t// Also clear any pending hover-end timeout\n\t\t\tif (hoverEndTimeoutRef.current) {\n\t\t\t\tclearTimeout(hoverEndTimeoutRef.current);\n\t\t\t\thoverEndTimeoutRef.current = null;\n\t\t\t}\n\t\t\tprevCardCountRef.current = cards.length;\n\t\t}\n\t}, [cards.length]);\n\n\t// Callback when all exit animations complete\n\tconst handleExitComplete = useCallback(() => {\n\t\tsetExitComplete(true);\n\t}, []);\n\n\t// Calculate card widths\n\tconst cardWidths = useMemo(() => {\n\t\tif (cards.length === 0) return { topCardWidth: 0, secondCardWidth: 0 };\n\n\t\tconst topCard = cards[cards.length - 1];\n\t\tconst topCardWidth = parseWidthToPixels(topCard.width ?? config.defaultWidth) ?? 480;\n\n\t\tconst secondCard = cards.length > 1 ? cards[cards.length - 2] : null;\n\t\tconst secondCardWidth = secondCard\n\t\t\t? (parseWidthToPixels(secondCard.width ?? config.defaultWidth) ?? 480)\n\t\t\t: 0;\n\n\t\treturn { topCardWidth, secondCardWidth };\n\t}, [cards, config.defaultWidth]);\n\n\t// Calculate responsive offset compression\n\tconst responsiveOffset = useMemo<ResponsiveOffsetResult>(() => {\n\t\treturn calculateResponsiveOffset({\n\t\t\tviewportWidth,\n\t\t\ttopCardWidth: cardWidths.topCardWidth,\n\t\t\tsecondCardWidth: cardWidths.secondCardWidth,\n\t\t\ttotalCards: cards.length,\n\t\t\tdefaultPeekOffset: config.defaultPeekOffset,\n\t\t\tlayoutMode: config.layoutMode,\n\t\t});\n\t}, [viewportWidth, cardWidths, cards.length, config.defaultPeekOffset, config.layoutMode]);\n\n\t// Determine if we should use mobile/collapsed mode\n\tconst useFullScreen = isMobile || responsiveOffset.shouldCollapse;\n\n\t// Gesture handling for top card swipe-to-dismiss\n\tconst handleDismiss = useCallback(() => {\n\t\tconst topCard = api.top();\n\t\tif (topCard?.dismissable === false) return;\n\t\tapi.pop();\n\t}, [api]);\n\n\t// Use useFullScreen for gesture enabling (matches what we pass to cards)\n\tconst swipeThreshold =\n\t\tmobile?.gestures?.swipeThreshold ?? Math.max(120, Math.round(viewportWidth * 0.35));\n\tconst autoDismissThreshold =\n\t\tmobile?.gestures?.autoDismissThreshold ?? Math.max(swipeThreshold, Math.round(viewportWidth * 0.8));\n\n\tconst { dragX, bind: gestureBind } = useStackGestures({\n\t\tenabled: useFullScreen && cards.length > 0,\n\t\t...mobile?.gestures,\n\t\tswipeThreshold,\n\t\tautoDismissThreshold,\n\t\tonDismiss: handleDismiss,\n\t});\n\n\t// Peek hover handlers - coordinate so only one card shows hover at a time\n\tconst handlePeekHoverStart = useCallback((cardIndex: number) => {\n\t\t// Clear any pending hover-end timeout\n\t\tif (hoverEndTimeoutRef.current) {\n\t\t\tclearTimeout(hoverEndTimeoutRef.current);\n\t\t\thoverEndTimeoutRef.current = null;\n\t\t}\n\t\tsetPeekHover({ hoveredIndex: cardIndex });\n\t}, []);\n\n\tconst handlePeekHoverEnd = useCallback((cardIndex: number) => {\n\t\t// Debounce hover-end to prevent flickering during animation\n\t\tif (hoverEndTimeoutRef.current) {\n\t\t\tclearTimeout(hoverEndTimeoutRef.current);\n\t\t}\n\t\thoverEndTimeoutRef.current = setTimeout(() => {\n\t\t\tsetPeekHover((prev) => (prev.hoveredIndex === cardIndex ? { hoveredIndex: -1 } : prev));\n\t\t\thoverEndTimeoutRef.current = null;\n\t\t}, 100);\n\t}, []);\n\n\t// Peek drag handlers - coordinate multi-card animation\n\tconst handlePeekDrag = useCallback((cardIndex: number, offset: number) => {\n\t\tsetPeekDrag({ sourceIndex: cardIndex, offset });\n\t}, []);\n\n\tconst handlePeekDragEnd = useCallback(\n\t\t(cardIndex: number, shouldDismiss: boolean) => {\n\t\t\tif (shouldDismiss) {\n\t\t\t\t// Check if any card above the dragged card is undismissable\n\t\t\t\tconst cardsAbove = cards.slice(cardIndex + 1);\n\t\t\t\tif (cardsAbove.some((c) => c.dismissable === false)) {\n\t\t\t\t\tsetPeekDrag({ sourceIndex: -1, offset: 0 });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Pop all cards above the dragged card's peek zone\n\t\t\t\tconst card = cards[cardIndex];\n\t\t\t\tif (card) {\n\t\t\t\t\tapi.popTo(card.id);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Reset peek drag state\n\t\t\tsetPeekDrag({ sourceIndex: -1, offset: 0 });\n\t\t},\n\t\t[api, cards],\n\t);\n\n\t// Determine which cards to render based on peekDepth\n\tconst visibleCards = useMemo(() => {\n\t\treturn cards.filter((_, index) => isCardVisible(index, cards.length, peekDepth));\n\t}, [cards, peekDepth]);\n\n\t// Portal container\n\tconst portalContainer = useRootPortalContainer();\n\n\t// Content to render - keep AnimatePresence mounted for exit animations\n\t// Note: backdropNode is created inside render to access resolvedBackdrop\n\tconst renderBackdropNode = (config?: BackdropConfig) => {\n\t\tconst defaultBackdrop = <StackBackdrop key=\"backdrop\" className=\"pointer-events-auto\" config={config} />;\n\t\tif (renderBackdrop) {\n\t\t\tconst customBackdrop = renderBackdrop();\n\t\t\treturn React.isValidElement(customBackdrop)\n\t\t\t\t? React.cloneElement(customBackdrop, { key: 'backdrop' })\n\t\t\t\t: defaultBackdrop;\n\t\t}\n\t\treturn defaultBackdrop;\n\t};\n\n\t// Track if we have cards (for backdrop and portal rendering)\n\tconst hasCards = cards.length > 0;\n\n\t// Resolve backdrop config - first card takes precedence, then viewport prop\n\t// Returns: { enabled: boolean, config: BackdropConfig | undefined }\n\tconst resolvedBackdrop = useMemo(() => {\n\t\tconst firstCard = cards[0];\n\t\tconst cardBackdrop = firstCard?.backdrop;\n\n\t\t// First card's backdrop setting takes precedence\n\t\tif (cardBackdrop !== undefined) {\n\t\t\tif (cardBackdrop === false) {\n\t\t\t\treturn { enabled: false, config: undefined };\n\t\t\t}\n\t\t\tif (cardBackdrop === true) {\n\t\t\t\treturn { enabled: true, config: undefined };\n\t\t\t}\n\t\t\t// Object config from card\n\t\t\treturn { enabled: true, config: cardBackdrop as BackdropConfig };\n\t\t}\n\n\t\t// Fall back to viewport's backdrop prop\n\t\tif (backdrop === false) {\n\t\t\treturn { enabled: false, config: undefined };\n\t\t}\n\t\tif (backdrop === true) {\n\t\t\treturn { enabled: true, config: undefined };\n\t\t}\n\t\t// Object config from viewport\n\t\treturn { enabled: true, config: backdrop as BackdropConfig };\n\t}, [cards, backdrop]);\n\n\tconst shouldShowBackdrop = resolvedBackdrop.enabled;\n\n\t// Render nothing if no cards and exit animations are complete\n\t// This ensures AnimatePresence stays mounted during exit animations\n\tif (!hasCards && exitComplete) {\n\t\treturn renderEmpty ? renderEmpty() : null;\n\t}\n\n\tconst content = (\n\t\t<div data-slot=\"stack-viewport\" className={cn('pointer-events-none fixed inset-0', className)}>\n\t\t\t{/* initial must stay true: viewport unmounts when empty, so first open remounts\n\t\t\t AnimatePresence with cards already present. initial={false} skips enter. */}\n\t\t\t<AnimatePresence mode=\"popLayout\" onExitComplete={handleExitComplete}>\n\t\t\t\t{/* Backdrop - only when cards exist and first card wants it */}\n\t\t\t\t{shouldShowBackdrop && hasCards && renderBackdropNode(resolvedBackdrop.config)}\n\n\t\t\t\t{/* Cards */}\n\t\t\t\t{visibleCards.map((card, visibleIndex) => {\n\t\t\t\t\t// Calculate actual index in full stack\n\t\t\t\t\tconst actualIndex = cards.length - visibleCards.length + visibleIndex;\n\t\t\t\t\tconst isTopCard = actualIndex === cards.length - 1;\n\t\t\t\t\t// Last card = only card in stack, used for exit animation with fade\n\t\t\t\t\tconst isLastCard = cards.length === 1 && isTopCard;\n\n\t\t\t\t\t// Calculate peek drag offset for this card\n\t\t\t\t\t// Cards above the peek drag source get the drag offset applied\n\t\t\t\t\tconst peekDragOffset =\n\t\t\t\t\t\tpeekDrag.sourceIndex >= 0 && actualIndex > peekDrag.sourceIndex\n\t\t\t\t\t\t\t? peekDrag.offset\n\t\t\t\t\t\t\t: 0;\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<StackCard\n\t\t\t\t\t\t\tkey={card.id}\n\t\t\t\t\t\t\tcard={card}\n\t\t\t\t\t\t\tindex={actualIndex}\n\t\t\t\t\t\t\ttotalCards={cards.length}\n\t\t\t\t\t\t\ttopCardWidth={cardWidths.topCardWidth}\n\t\t\t\t\t\t\tanimation={animation}\n\t\t\t\t\t\t\tisMobile={useFullScreen}\n\t\t\t\t\t\t\trenderHeader={renderHeader}\n\t\t\t\t\t\t\tpeekGestureConfig={peekGestures}\n\t\t\t\t\t\t\t// Responsive compression\n\t\t\t\t\t\t\tcompressionRatio={responsiveOffset.compressionRatio}\n\t\t\t\t\t\t\tadjustedPeekOffset={responsiveOffset.adjustedPeekOffset}\n\t\t\t\t\t\t\t// Top card swipe-to-dismiss\n\t\t\t\t\t\t\tdragX={isTopCard ? dragX : 0}\n\t\t\t\t\t\t\tgestureBind={isTopCard ? gestureBind : undefined}\n\t\t\t\t\t\t\t// Peek hover coordination (viewport-level)\n\t\t\t\t\t\t\tisPeekHovered={peekHover.hoveredIndex === actualIndex}\n\t\t\t\t\t\t\tonPeekHoverStart={handlePeekHoverStart}\n\t\t\t\t\t\t\tonPeekHoverEnd={handlePeekHoverEnd}\n\t\t\t\t\t\t\t// Peek drag coordination\n\t\t\t\t\t\t\tpeekDragOffset={peekDragOffset}\n\t\t\t\t\t\t\tonPeekDrag={handlePeekDrag}\n\t\t\t\t\t\t\tonPeekDragEnd={handlePeekDragEnd}\n\t\t\t\t\t\t\t// Last card exit animation (slide + fade)\n\t\t\t\t\t\t\tisLastCard={isLastCard}\n\t\t\t\t\t\t\tclassName=\"pointer-events-auto\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t})}\n\t\t\t</AnimatePresence>\n\t\t</div>\n\t);\n\n\t// Render into portal if available, otherwise render in place\n\tif (portalContainer) {\n\t\treturn createPortal(content, portalContainer);\n\t}\n\n\treturn content;\n}\n","'use client';\n\nimport { useEffect, useState } from 'react';\n\nimport { Skeleton } from '../skeleton';\n\nexport interface DeferredCardContentProps {\n\tchildren: React.ReactNode;\n\t/** Custom placeholder while waiting for animation to complete */\n\tplaceholder?: React.ReactNode;\n\t/** Delay in ms before showing content (default: 220, slightly after 200ms animation) */\n\tdelay?: number;\n\t/** Whether to show content immediately (useful for edit mode where data is cached) */\n\timmediate?: boolean;\n\t/**\n\t * Priority level for scheduling content render:\n\t * - 'high': Uses half the delay for faster content display\n\t * - 'normal': Standard delay with rAF (default)\n\t * - 'low': Uses requestIdleCallback when available for non-critical content\n\t */\n\tpriority?: 'high' | 'normal' | 'low';\n\t/** Callback when content becomes ready to render */\n\tonReady?: () => void;\n}\n\n/**\n * Defers rendering of heavy content until after Stack card animation completes.\n * This prevents layout thrashing and dropped frames during the slide-in animation.\n *\n * Usage:\n * ```tsx\n * <DeferredCardContent placeholder={<MySkeleton />}>\n * <HeavyContent />\n * </DeferredCardContent>\n * ```\n *\n * With priority:\n * ```tsx\n * <DeferredCardContent priority=\"low\" placeholder={<MySkeleton />}>\n * <NonCriticalContent />\n * </DeferredCardContent>\n * ```\n */\nexport function DeferredCardContent({\n\tchildren,\n\tplaceholder,\n\tdelay = 220,\n\timmediate = false,\n\tpriority = 'normal',\n\tonReady,\n}: DeferredCardContentProps) {\n\tconst [ready, setReady] = useState(immediate);\n\n\tuseEffect(() => {\n\t\tif (immediate) {\n\t\t\tonReady?.();\n\t\t\treturn;\n\t\t}\n\n\t\tlet cancelled = false;\n\n\t\tconst scheduleReady = () => {\n\t\t\tif (cancelled) return;\n\t\t\tsetReady(true);\n\t\t\tonReady?.();\n\t\t};\n\n\t\t// Adjust delay based on priority\n\t\tconst effectiveDelay = priority === 'high' ? Math.floor(delay / 2) : delay;\n\n\t\t// Use requestIdleCallback for low priority when available\n\t\tif (priority === 'low' && 'requestIdleCallback' in window) {\n\t\t\tconst timeoutId = setTimeout(() => {\n\t\t\t\tconst idleId = window.requestIdleCallback(scheduleReady, { timeout: effectiveDelay });\n\t\t\t\treturn () => window.cancelIdleCallback(idleId);\n\t\t\t}, effectiveDelay);\n\n\t\t\treturn () => {\n\t\t\t\tcancelled = true;\n\t\t\t\tclearTimeout(timeoutId);\n\t\t\t};\n\t\t}\n\n\t\t// Use setTimeout + rAF to sync with browser's paint cycle\n\t\t// This ensures content renders after animation settles\n\t\tconst timeoutId = setTimeout(() => {\n\t\t\tconst rafId = requestAnimationFrame(scheduleReady);\n\t\t\treturn () => cancelAnimationFrame(rafId);\n\t\t}, effectiveDelay);\n\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t\tclearTimeout(timeoutId);\n\t\t};\n\t}, [delay, immediate, priority, onReady]);\n\n\tif (!ready) {\n\t\treturn placeholder ?? <DefaultCardSkeleton />;\n\t}\n\n\treturn <>{children}</>;\n}\n\n/**\n * Default skeleton placeholder for card content.\n * Shows a reasonable loading state for typical form-based cards.\n */\nfunction DefaultCardSkeleton() {\n\treturn (\n\t\t<div className=\"space-y-6 p-6\">\n\t\t\t{/* Header area skeleton */}\n\t\t\t<div className=\"flex items-center justify-center py-4\">\n\t\t\t\t<Skeleton className=\"h-24 w-48 rounded-lg\" />\n\t\t\t</div>\n\t\t\t{/* Form field skeletons */}\n\t\t\t<div className=\"space-y-4\">\n\t\t\t\t<div className=\"space-y-2\">\n\t\t\t\t\t<Skeleton className=\"h-4 w-20\" />\n\t\t\t\t\t<Skeleton className=\"h-10 w-full\" />\n\t\t\t\t</div>\n\t\t\t\t<div className=\"space-y-2\">\n\t\t\t\t\t<Skeleton className=\"h-4 w-16\" />\n\t\t\t\t\t<Skeleton className=\"h-10 w-full\" />\n\t\t\t\t</div>\n\t\t\t\t<div className=\"space-y-2\">\n\t\t\t\t\t<Skeleton className=\"h-4 w-24\" />\n\t\t\t\t\t<Skeleton className=\"h-10 w-full\" />\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;AAuBA,MAAM,uBAAuB;AAC7B,MAAM,sBAAsB;AAC5B,MAAM,gBAAgB;AAMtB,SAAS,aAAa,OAAmB,QAAiC;CACxE,QAAQ,OAAO,MAAf;EACE,KAAK,QAGH,OAAO,EAAE,OAAO,CAAC,GADA,MAAM,MAAM,QAAQ,MAAM,EAAE,OAAO,OAAO,KAAK,EACr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,YAAY;GACZ,aAAa,SAAS;EACvB;CACD,GAAG;EAAC;EAAO;EAAW;EAAU;CAAO,CAAC;CAExC,IAAI,CAAC,OACJ,OAAO,eAAe,oBAAC,qBAAD,CAAsB;CAG7C,OAAO,gCAAG,SAAW;AACtB;;;;;AAMA,SAAS,sBAAsB;CAC9B,OACC,qBAAC,OAAD;EAAK,WAAU;YAAf,CAEC,oBAAC,OAAD;GAAK,WAAU;aACd,oBAAC,UAAD,EAAU,WAAU,uBAAwB;EACxC,IAEL,qBAAC,OAAD;GAAK,WAAU;aAAf;IACC,qBAAC,OAAD;KAAK,WAAU;eAAf,CACC,oBAAC,UAAD,EAAU,WAAU,WAAY,IAChC,oBAAC,UAAD,EAAU,WAAU,cAAe,EAC/B;;IACL,qBAAC,OAAD;KAAK,WAAU;eAAf,CACC,oBAAC,UAAD,EAAU,WAAU,WAAY,IAChC,oBAAC,UAAD,EAAU,WAAU,cAAe,EAC/B;;IACL,qBAAC,OAAD;KAAK,WAAU;eAAf,CACC,oBAAC,UAAD,EAAU,WAAU,WAAY,IAChC,oBAAC,UAAD,EAAU,WAAU,cAAe,EAC/B;;GACD;IACD;;AAEP"}
@@ -459,6 +459,35 @@ function createOffsetTransition(_config = {}) {
459
459
  mass: .8
460
460
  };
461
461
  }
462
+ /**
463
+ * Enter transition for card slide-in (x: 100% → offset).
464
+ * Tween + snappy ease — distinct from offset springs used after settle.
465
+ */
466
+ function createEnterTransition(config = {}) {
467
+ const { duration, enterEase } = {
468
+ ...DEFAULT_ANIMATION_CONFIG,
469
+ ...config
470
+ };
471
+ return {
472
+ type: "tween",
473
+ duration,
474
+ ease: enterEase
475
+ };
476
+ }
477
+ /**
478
+ * Exit transition for card slide-out (offset → x: 100%).
479
+ */
480
+ function createExitTransition(config = {}) {
481
+ const { duration, exitEase } = {
482
+ ...DEFAULT_ANIMATION_CONFIG,
483
+ ...config
484
+ };
485
+ return {
486
+ type: "tween",
487
+ duration,
488
+ ease: exitEase
489
+ };
490
+ }
462
491
  const backdropVariants = {
463
492
  initial: { opacity: 0 },
464
493
  animate: {
@@ -503,20 +532,6 @@ const swipeDismissTransition = {
503
532
  1
504
533
  ]
505
534
  };
506
- /**
507
- * Exit transition for the last card - coordinated slide + fade.
508
- * Uses tween (not spring) for smooth opacity animation.
509
- */
510
- const lastCardExitTransition = {
511
- type: "tween",
512
- duration: .25,
513
- ease: [
514
- .4,
515
- 0,
516
- .6,
517
- 1
518
- ]
519
- };
520
535
  /** Spring config for peek hover expansion - playful and bouncy */
521
536
  const peekHoverSpring = {
522
537
  type: "spring",
@@ -957,6 +972,7 @@ function usePeekGestures(options) {
957
972
  //#region src/components/stack/stack-card.tsx
958
973
  /** Default hover expansion in pixels */
959
974
  const DEFAULT_HOVER_EXPANSION = 48;
975
+ const reducedMotionTransition = { duration: 0 };
960
976
  function StackCardInner({ card, index, totalCards, topCardWidth, animation, isMobile = false, renderHeader, peekGestureConfig, compressionRatio = 1, adjustedPeekOffset, dragX = 0, gestureBind, isPeekHovered = false, onPeekHoverStart, onPeekHoverEnd, peekDragOffset = 0, onPeekDragStart, onPeekDrag, onPeekDragEnd, isLastCard = false, className }) {
961
977
  const { config, api, state } = useStackContext();
962
978
  const prefersReducedMotion = (0, motion_react.useReducedMotion)();
@@ -982,6 +998,8 @@ function StackCardInner({ card, index, totalCards, topCardWidth, animation, isMo
982
998
  ]);
983
999
  const cardWidth = isMobile ? "100%" : normalizeWidth(card.width, config.defaultWidth);
984
1000
  const offsetTransition = createOffsetTransition(animation);
1001
+ const enterTransition = createEnterTransition(animation);
1002
+ const exitTransition = createExitTransition(animation);
985
1003
  const handleClose = (0, react.useCallback)(() => {
986
1004
  api.dismiss(card.id);
987
1005
  }, [api, card.id]);
@@ -1048,16 +1066,15 @@ function StackCardInner({ card, index, totalCards, topCardWidth, animation, isMo
1048
1066
  const initialX = prefersReducedMotion ? xOffset : "100%";
1049
1067
  const exitX = prefersReducedMotion ? xOffset : "100%";
1050
1068
  const exitOpacity = prefersReducedMotion ? 0 : isLastCard ? 0 : 1;
1051
- let activeTransition = offsetTransition;
1052
- if (peekGestures.isDragging || peekDragOffset > 0) activeTransition = peekDragSpring;
1053
- else if (isPeekHovered) activeTransition = peekHoverSpring;
1054
- const exitAnimation = isLastCard && !prefersReducedMotion ? {
1069
+ let activeTransition = prefersReducedMotion ? reducedMotionTransition : isAnimationComplete ? offsetTransition : enterTransition;
1070
+ if (!prefersReducedMotion) {
1071
+ if (peekGestures.isDragging || peekDragOffset > 0) activeTransition = peekDragSpring;
1072
+ else if (isPeekHovered) activeTransition = peekHoverSpring;
1073
+ }
1074
+ const exitAnimation = {
1055
1075
  x: exitX,
1056
1076
  opacity: exitOpacity,
1057
- transition: lastCardExitTransition
1058
- } : {
1059
- x: exitX,
1060
- opacity: exitOpacity
1077
+ transition: prefersReducedMotion ? reducedMotionTransition : exitTransition
1061
1078
  };
1062
1079
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(motion_react.motion.div, {
1063
1080
  "data-slot": "stack-card",
@@ -1067,7 +1084,7 @@ function StackCardInner({ card, index, totalCards, topCardWidth, animation, isMo
1067
1084
  "data-offset": baseOffset,
1068
1085
  initial: {
1069
1086
  x: initialX,
1070
- opacity: prefersReducedMotion ? 0 : 1
1087
+ opacity: 1
1071
1088
  },
1072
1089
  animate: {
1073
1090
  x: animateX,
@@ -1399,7 +1416,6 @@ function CardStackViewport({ backdrop = true, renderBackdrop, renderHeader, rend
1399
1416
  "data-slot": "stack-viewport",
1400
1417
  className: require_utils.cn("pointer-events-none fixed inset-0", className),
1401
1418
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(motion_react.AnimatePresence, {
1402
- initial: false,
1403
1419
  mode: "popLayout",
1404
1420
  onExitComplete: handleExitComplete,
1405
1421
  children: [shouldShowBackdrop && hasCards && renderBackdropNode(resolvedBackdrop.config), visibleCards.map((card, visibleIndex) => {
@@ -1594,6 +1610,18 @@ Object.defineProperty(exports, 'createCardVariants', {
1594
1610
  return createCardVariants;
1595
1611
  }
1596
1612
  });
1613
+ Object.defineProperty(exports, 'createEnterTransition', {
1614
+ enumerable: true,
1615
+ get: function () {
1616
+ return createEnterTransition;
1617
+ }
1618
+ });
1619
+ Object.defineProperty(exports, 'createExitTransition', {
1620
+ enumerable: true,
1621
+ get: function () {
1622
+ return createExitTransition;
1623
+ }
1624
+ });
1597
1625
  Object.defineProperty(exports, 'createOffsetTransition', {
1598
1626
  enumerable: true,
1599
1627
  get: function () {
@@ -1768,4 +1796,4 @@ Object.defineProperty(exports, 'useStackResponsive', {
1768
1796
  return useStackResponsive;
1769
1797
  }
1770
1798
  });
1771
- //# sourceMappingURL=stack-DKdvlOM6.cjs.map
1799
+ //# sourceMappingURL=stack-ci2lkfkr.cjs.map