@constructive-io/ui 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/dist/components/alert-dialog.d.ts +31 -0
  2. package/dist/components/alert-dialog.js +314 -0
  3. package/dist/components/alert-dialog.js.map +1 -0
  4. package/dist/components/alert.d.ts +14 -0
  5. package/dist/components/alert.js +38 -0
  6. package/dist/components/alert.js.map +1 -0
  7. package/dist/components/autocomplete.d.ts +28 -0
  8. package/dist/components/autocomplete.js +395 -0
  9. package/dist/components/autocomplete.js.map +1 -0
  10. package/dist/components/avatar.d.ts +13 -0
  11. package/dist/components/avatar.js +37 -0
  12. package/dist/components/avatar.js.map +1 -0
  13. package/dist/components/badge.d.ts +15 -0
  14. package/dist/components/badge.js +43 -0
  15. package/dist/components/badge.js.map +1 -0
  16. package/dist/components/breadcrumb.d.ts +14 -0
  17. package/dist/components/breadcrumb.js +154 -0
  18. package/dist/components/breadcrumb.js.map +1 -0
  19. package/dist/components/button.d.ts +17 -0
  20. package/dist/components/button.js +62 -0
  21. package/dist/components/button.js.map +1 -0
  22. package/dist/components/calendar-rac.d.ts +13 -0
  23. package/dist/components/calendar-rac.js +82 -0
  24. package/dist/components/calendar-rac.js.map +1 -0
  25. package/dist/components/card.d.ts +19 -0
  26. package/dist/components/card.js +75 -0
  27. package/dist/components/card.js.map +1 -0
  28. package/dist/components/checkbox-group.d.ts +7 -0
  29. package/dist/components/checkbox-group.js +16 -0
  30. package/dist/components/checkbox-group.js.map +1 -0
  31. package/dist/components/checkbox.d.ts +8 -0
  32. package/dist/components/checkbox.js +67 -0
  33. package/dist/components/checkbox.js.map +1 -0
  34. package/dist/components/collapsible.d.ts +54 -0
  35. package/dist/components/collapsible.js +121 -0
  36. package/dist/components/collapsible.js.map +1 -0
  37. package/dist/components/combobox.d.ts +44 -0
  38. package/dist/components/combobox.js +486 -0
  39. package/dist/components/combobox.js.map +1 -0
  40. package/dist/components/command.d.ts +43 -0
  41. package/dist/components/command.js +690 -0
  42. package/dist/components/command.js.map +1 -0
  43. package/dist/components/dialog.d.ts +35 -0
  44. package/dist/components/dialog.js +440 -0
  45. package/dist/components/dialog.js.map +1 -0
  46. package/dist/components/dock.d.ts +31 -0
  47. package/dist/components/dock.js +111 -0
  48. package/dist/components/dock.js.map +1 -0
  49. package/dist/components/drawer.d.ts +16 -0
  50. package/dist/components/drawer.js +147 -0
  51. package/dist/components/drawer.js.map +1 -0
  52. package/dist/components/dropdown-menu.d.ts +50 -0
  53. package/dist/components/dropdown-menu.js +380 -0
  54. package/dist/components/dropdown-menu.js.map +1 -0
  55. package/dist/components/field.d.ts +51 -0
  56. package/dist/components/field.js +115 -0
  57. package/dist/components/field.js.map +1 -0
  58. package/dist/components/flickering-grid.d.ts +15 -0
  59. package/dist/components/flickering-grid.js +147 -0
  60. package/dist/components/flickering-grid.js.map +1 -0
  61. package/dist/components/form-control.d.ts +15 -0
  62. package/dist/components/form-control.js +173 -0
  63. package/dist/components/form-control.js.map +1 -0
  64. package/dist/components/form.d.ts +37 -0
  65. package/dist/components/form.js +179 -0
  66. package/dist/components/form.js.map +1 -0
  67. package/dist/components/input-group.d.ts +18 -0
  68. package/dist/components/input-group.js +177 -0
  69. package/dist/components/input-group.js.map +1 -0
  70. package/dist/components/input.d.ts +11 -0
  71. package/dist/components/input.js +60 -0
  72. package/dist/components/input.js.map +1 -0
  73. package/dist/components/json-input.d.ts +25 -0
  74. package/dist/components/json-input.js +351 -0
  75. package/dist/components/json-input.js.map +1 -0
  76. package/dist/components/label.d.ts +11 -0
  77. package/dist/components/label.js +27 -0
  78. package/dist/components/label.js.map +1 -0
  79. package/dist/components/motion-grid.d.ts +20 -0
  80. package/dist/components/motion-grid.js +81 -0
  81. package/dist/components/motion-grid.js.map +1 -0
  82. package/dist/components/multi-select.d.ts +198 -0
  83. package/dist/components/multi-select.js +882 -0
  84. package/dist/components/multi-select.js.map +1 -0
  85. package/dist/components/page-header.d.ts +17 -0
  86. package/dist/components/page-header.js +17 -0
  87. package/dist/components/page-header.js.map +1 -0
  88. package/dist/components/pagination.d.ts +19 -0
  89. package/dist/components/pagination.js +144 -0
  90. package/dist/components/pagination.js.map +1 -0
  91. package/dist/components/popover.d.ts +35 -0
  92. package/dist/components/popover.js +188 -0
  93. package/dist/components/popover.js.map +1 -0
  94. package/dist/components/portal.d.ts +108 -0
  95. package/dist/components/portal.js +75 -0
  96. package/dist/components/portal.js.map +1 -0
  97. package/dist/components/progress.d.ts +10 -0
  98. package/dist/components/progress.js +30 -0
  99. package/dist/components/progress.js.map +1 -0
  100. package/dist/components/progressive-blur-scroll-container.d.ts +25 -0
  101. package/dist/components/progressive-blur-scroll-container.js +142 -0
  102. package/dist/components/progressive-blur-scroll-container.js.map +1 -0
  103. package/dist/components/progressive-blur.d.ts +16 -0
  104. package/dist/components/progressive-blur.js +68 -0
  105. package/dist/components/progressive-blur.js.map +1 -0
  106. package/dist/components/radio-group.d.ts +10 -0
  107. package/dist/components/radio-group.js +37 -0
  108. package/dist/components/radio-group.js.map +1 -0
  109. package/dist/components/record-picker.d.ts +16 -0
  110. package/dist/components/record-picker.js +366 -0
  111. package/dist/components/record-picker.js.map +1 -0
  112. package/dist/components/resizable.d.ts +11 -0
  113. package/dist/components/resizable.js +52 -0
  114. package/dist/components/resizable.js.map +1 -0
  115. package/dist/components/responsive-diagram.d.ts +10 -0
  116. package/dist/components/responsive-diagram.js +63 -0
  117. package/dist/components/responsive-diagram.js.map +1 -0
  118. package/dist/components/scroll-area.d.ts +12 -0
  119. package/dist/components/scroll-area.js +69 -0
  120. package/dist/components/scroll-area.js.map +1 -0
  121. package/dist/components/select.d.ts +47 -0
  122. package/dist/components/select.js +287 -0
  123. package/dist/components/select.js.map +1 -0
  124. package/dist/components/separator.d.ts +11 -0
  125. package/dist/components/separator.js +24 -0
  126. package/dist/components/separator.js.map +1 -0
  127. package/dist/components/sheet.d.ts +112 -0
  128. package/dist/components/sheet.js +600 -0
  129. package/dist/components/sheet.js.map +1 -0
  130. package/dist/components/sidebar.d.ts +77 -0
  131. package/dist/components/sidebar.js +1217 -0
  132. package/dist/components/sidebar.js.map +1 -0
  133. package/dist/components/skeleton.d.ts +7 -0
  134. package/dist/components/skeleton.js +16 -0
  135. package/dist/components/skeleton.js.map +1 -0
  136. package/dist/components/sonner.d.ts +10 -0
  137. package/dist/components/sonner.js +23 -0
  138. package/dist/components/sonner.js.map +1 -0
  139. package/dist/components/stack/index.d.ts +663 -0
  140. package/dist/components/stack/index.js +1418 -0
  141. package/dist/components/stack/index.js.map +1 -0
  142. package/dist/components/stepper.d.ts +30 -0
  143. package/dist/components/stepper.js +280 -0
  144. package/dist/components/stepper.js.map +1 -0
  145. package/dist/components/switch.d.ts +8 -0
  146. package/dist/components/switch.js +40 -0
  147. package/dist/components/switch.js.map +1 -0
  148. package/dist/components/table.d.ts +15 -0
  149. package/dist/components/table.js +65 -0
  150. package/dist/components/table.js.map +1 -0
  151. package/dist/components/tabs.d.ts +10 -0
  152. package/dist/components/tabs.js +48 -0
  153. package/dist/components/tabs.js.map +1 -0
  154. package/dist/components/tags.d.ts +42 -0
  155. package/dist/components/tags.js +728 -0
  156. package/dist/components/tags.js.map +1 -0
  157. package/dist/components/textarea.d.ts +10 -0
  158. package/dist/components/textarea.js +54 -0
  159. package/dist/components/textarea.js.map +1 -0
  160. package/dist/components/toast/index.d.ts +52 -0
  161. package/dist/components/toast/index.js +221 -0
  162. package/dist/components/toast/index.js.map +1 -0
  163. package/dist/components/tooltip.d.ts +29 -0
  164. package/dist/components/tooltip.js +174 -0
  165. package/dist/components/tooltip.js.map +1 -0
  166. package/dist/components/unlink-button.d.ts +14 -0
  167. package/dist/components/unlink-button.js +91 -0
  168. package/dist/components/unlink-button.js.map +1 -0
  169. package/dist/index.cjs +7692 -0
  170. package/dist/index.cjs.map +1 -0
  171. package/dist/index.d.cts +2157 -0
  172. package/dist/index.d.ts +2157 -0
  173. package/dist/index.js +7375 -0
  174. package/dist/index.js.map +1 -0
  175. package/package.json +490 -0
  176. package/src/styles/globals.css +397 -0
@@ -0,0 +1,1418 @@
1
+ "use client";
2
+ import * as React from 'react';
3
+ import { createContext, memo, useState, useCallback, useMemo, useContext, useRef, useReducer, useEffect } from 'react';
4
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
+ import { useReducedMotion, motion, AnimatePresence } from 'motion/react';
6
+ import { createPortal } from 'react-dom';
7
+ import { clsx } from 'clsx';
8
+ import { twMerge } from 'tailwind-merge';
9
+ import { ChevronRight } from 'lucide-react';
10
+ import { useDrag } from '@use-gesture/react';
11
+
12
+ // src/components/stack/stack-context.tsx
13
+ var DEFAULT_Z_INDEX_BASE = 100;
14
+ var DEFAULT_PEEK_OFFSET = 48;
15
+ var DEFAULT_WIDTH = 480;
16
+ function stackReducer(state, action) {
17
+ switch (action.type) {
18
+ case "PUSH": {
19
+ const filtered = state.cards.filter((c) => c.id !== action.card.id);
20
+ return { cards: [...filtered, action.card] };
21
+ }
22
+ case "POP": {
23
+ const count = Math.max(1, action.count);
24
+ if (state.cards.length === 0) return state;
25
+ return { cards: state.cards.slice(0, -count) };
26
+ }
27
+ case "POP_TO": {
28
+ const index = state.cards.findIndex((c) => c.id === action.id);
29
+ if (index === -1) return state;
30
+ return { cards: state.cards.slice(0, index + 1) };
31
+ }
32
+ case "REPLACE_TOP": {
33
+ if (state.cards.length === 0) {
34
+ return { cards: [action.card] };
35
+ }
36
+ const newCards = [...state.cards];
37
+ newCards[newCards.length - 1] = action.card;
38
+ return { cards: newCards };
39
+ }
40
+ case "RESET": {
41
+ return { cards: action.cards };
42
+ }
43
+ case "CLEAR": {
44
+ return { cards: [] };
45
+ }
46
+ case "UPDATE_PROPS": {
47
+ const index = state.cards.findIndex((c) => c.id === action.id);
48
+ if (index === -1) return state;
49
+ const card = state.cards[index];
50
+ const prevProps = card.props ?? {};
51
+ const newProps = typeof action.patch === "function" ? action.patch(card.props) : { ...prevProps, ...action.patch };
52
+ const newCards = [...state.cards];
53
+ newCards[index] = { ...card, props: newProps };
54
+ return { cards: newCards };
55
+ }
56
+ case "SET_TITLE": {
57
+ const index = state.cards.findIndex((c) => c.id === action.id);
58
+ if (index === -1) return state;
59
+ const newCards = [...state.cards];
60
+ newCards[index] = { ...newCards[index], title: action.title };
61
+ return { cards: newCards };
62
+ }
63
+ case "SET_DESCRIPTION": {
64
+ const index = state.cards.findIndex((c) => c.id === action.id);
65
+ if (index === -1) return state;
66
+ const newCards = [...state.cards];
67
+ newCards[index] = { ...newCards[index], description: action.description };
68
+ return { cards: newCards };
69
+ }
70
+ case "SET_WIDTH": {
71
+ const index = state.cards.findIndex((c) => c.id === action.id);
72
+ if (index === -1) return state;
73
+ const newCards = [...state.cards];
74
+ newCards[index] = { ...newCards[index], width: action.width };
75
+ return { cards: newCards };
76
+ }
77
+ case "DISMISS": {
78
+ const index = state.cards.findIndex((c) => c.id === action.id);
79
+ if (index === -1) return state;
80
+ if (action.cascade) {
81
+ return { cards: state.cards.slice(0, index) };
82
+ } else {
83
+ return { cards: state.cards.filter((c) => c.id !== action.id) };
84
+ }
85
+ }
86
+ case "INSERT_AT": {
87
+ const clampedIndex = Math.max(0, Math.min(action.index, state.cards.length));
88
+ const filtered = state.cards.filter((c) => c.id !== action.card.id);
89
+ const newCards = [...filtered];
90
+ newCards.splice(clampedIndex, 0, action.card);
91
+ return { cards: newCards };
92
+ }
93
+ default:
94
+ return state;
95
+ }
96
+ }
97
+ var StackContext = createContext(null);
98
+ function CardStackProvider({
99
+ children,
100
+ routes = {},
101
+ initial = [],
102
+ onChange,
103
+ zIndexBase = DEFAULT_Z_INDEX_BASE,
104
+ layoutMode = "cascade",
105
+ defaultPeekOffset = DEFAULT_PEEK_OFFSET,
106
+ defaultWidth = DEFAULT_WIDTH
107
+ }) {
108
+ const [state, dispatch] = useReducer(stackReducer, { cards: initial });
109
+ const prevCardsRef = useRef(state.cards);
110
+ useEffect(() => {
111
+ if (prevCardsRef.current !== state.cards) {
112
+ const prevCards = prevCardsRef.current;
113
+ const currentIds = new Set(state.cards.map((c) => c.id));
114
+ for (const card of prevCards) {
115
+ if (!currentIds.has(card.id)) {
116
+ card.onClose?.();
117
+ }
118
+ }
119
+ prevCardsRef.current = state.cards;
120
+ onChange?.(state.cards);
121
+ }
122
+ }, [state.cards, onChange]);
123
+ const routesRef = useRef(routes);
124
+ routesRef.current = routes;
125
+ const stateRef = useRef(state);
126
+ stateRef.current = state;
127
+ const api = useMemo(() => {
128
+ const top = () => {
129
+ const cards = stateRef.current.cards;
130
+ return cards.length > 0 ? cards[cards.length - 1] : null;
131
+ };
132
+ const currentId = () => top()?.id ?? null;
133
+ const canPop = () => stateRef.current.cards.length > 0;
134
+ const size = () => stateRef.current.cards.length;
135
+ const get = (id) => stateRef.current.cards.find((c) => c.id === id) ?? null;
136
+ const getAll = () => [...stateRef.current.cards];
137
+ const has = (id) => stateRef.current.cards.some((c) => c.id === id);
138
+ const push = (card, options) => {
139
+ if (options?.replaceFrom) {
140
+ const fromIndex = stateRef.current.cards.findIndex((c) => c.id === options.replaceFrom);
141
+ if (fromIndex !== -1 && fromIndex < stateRef.current.cards.length - 1) {
142
+ dispatch({ type: "POP_TO", id: options.replaceFrom });
143
+ }
144
+ }
145
+ dispatch({ type: "PUSH", card });
146
+ return card.id;
147
+ };
148
+ const pushRoute = (route, props, opts) => {
149
+ const routeDef = routesRef.current[route];
150
+ if (!routeDef) {
151
+ throw new Error(`Stack: Route "${route}" not found in registry`);
152
+ }
153
+ const id = opts?.id ?? routeDef.getId?.(props) ?? route;
154
+ const card = {
155
+ id,
156
+ title: opts?.title ?? routeDef.defaultTitle,
157
+ Component: routeDef.Component,
158
+ props,
159
+ width: opts?.width ?? routeDef.defaultWidth,
160
+ peekOffset: routeDef.defaultPeekOffset
161
+ };
162
+ dispatch({ type: "PUSH", card });
163
+ return id;
164
+ };
165
+ const pop = (count = 1) => {
166
+ dispatch({ type: "POP", count });
167
+ };
168
+ const popTo = (id) => {
169
+ dispatch({ type: "POP_TO", id });
170
+ };
171
+ const replaceTop = (card) => {
172
+ dispatch({ type: "REPLACE_TOP", card });
173
+ return card.id;
174
+ };
175
+ const reset = (cards) => {
176
+ dispatch({ type: "RESET", cards });
177
+ };
178
+ const clear = () => {
179
+ dispatch({ type: "CLEAR" });
180
+ };
181
+ const updateProps = (id, patch) => {
182
+ dispatch({ type: "UPDATE_PROPS", id, patch });
183
+ };
184
+ const setTitle = (id, title) => {
185
+ dispatch({ type: "SET_TITLE", id, title });
186
+ };
187
+ const setDescription = (id, description) => {
188
+ dispatch({ type: "SET_DESCRIPTION", id, description });
189
+ };
190
+ const setWidth = (id, width) => {
191
+ dispatch({ type: "SET_WIDTH", id, width });
192
+ };
193
+ const dismiss = (id, options) => {
194
+ const cascade = options?.cascade ?? true;
195
+ dispatch({ type: "DISMISS", id, cascade });
196
+ };
197
+ const insertAt = (index, card) => {
198
+ dispatch({ type: "INSERT_AT", index, card });
199
+ return card.id;
200
+ };
201
+ return {
202
+ top,
203
+ currentId,
204
+ canPop,
205
+ size,
206
+ get,
207
+ getAll,
208
+ has,
209
+ push,
210
+ pushRoute,
211
+ pop,
212
+ popTo,
213
+ replaceTop,
214
+ reset,
215
+ clear,
216
+ updateProps,
217
+ setTitle,
218
+ setDescription,
219
+ setWidth,
220
+ dismiss,
221
+ insertAt
222
+ };
223
+ }, []);
224
+ useEffect(() => {
225
+ const handleEscape = (event) => {
226
+ if (event.key === "Escape" && stateRef.current.cards.length > 0) {
227
+ event.preventDefault();
228
+ event.stopPropagation();
229
+ api.pop();
230
+ }
231
+ };
232
+ document.addEventListener("keydown", handleEscape, true);
233
+ return () => document.removeEventListener("keydown", handleEscape, true);
234
+ }, [api]);
235
+ const contextValue = useMemo(
236
+ () => ({
237
+ state,
238
+ api,
239
+ config: {
240
+ routes,
241
+ zIndexBase,
242
+ layoutMode,
243
+ defaultPeekOffset,
244
+ defaultWidth
245
+ }
246
+ }),
247
+ [state, api, routes, zIndexBase, layoutMode, defaultPeekOffset, defaultWidth]
248
+ );
249
+ return /* @__PURE__ */ jsx(StackContext.Provider, { value: contextValue, children });
250
+ }
251
+ function useCardStack() {
252
+ const context = useContext(StackContext);
253
+ if (!context) {
254
+ throw new Error("useCardStack must be used within a CardStackProvider");
255
+ }
256
+ return context.api;
257
+ }
258
+ function useStackContext() {
259
+ const context = useContext(StackContext);
260
+ if (!context) {
261
+ throw new Error("useStackContext must be used within a CardStackProvider");
262
+ }
263
+ return context;
264
+ }
265
+ function useStackLayoutMode() {
266
+ const context = useStackContext();
267
+ return context.config.layoutMode;
268
+ }
269
+ function useStackCards() {
270
+ const context = useStackContext();
271
+ return context.state.cards;
272
+ }
273
+ function useIsTopCard(id) {
274
+ const context = useStackContext();
275
+ const cards = context.state.cards;
276
+ return cards.length > 0 && cards[cards.length - 1].id === id;
277
+ }
278
+ function useCardIndex(id) {
279
+ const context = useStackContext();
280
+ return context.state.cards.findIndex((c) => c.id === id);
281
+ }
282
+ function useCardInjectedProps(id) {
283
+ const api = useCardStack();
284
+ return useMemo(
285
+ () => ({
286
+ card: {
287
+ id,
288
+ push: (card, options) => {
289
+ const cardId = card.id ?? `${id}-child-${Date.now()}`;
290
+ const fullCard = { ...card, id: cardId };
291
+ if (options?.append) {
292
+ return api.push(fullCard);
293
+ } else {
294
+ return api.push(fullCard, { replaceFrom: id });
295
+ }
296
+ },
297
+ close: () => api.dismiss(id),
298
+ setTitle: (title) => api.setTitle(id, title),
299
+ setDescription: (description) => api.setDescription(id, description),
300
+ setWidth: (width) => api.setWidth(id, width),
301
+ updateProps: (patch) => api.updateProps(id, patch)
302
+ }
303
+ }),
304
+ [id, api]
305
+ );
306
+ }
307
+ var CardReadyContext = createContext(null);
308
+ function CardReadyProvider({
309
+ children,
310
+ isAnimationComplete
311
+ }) {
312
+ const value = useMemo(() => ({ isAnimationComplete }), [isAnimationComplete]);
313
+ return /* @__PURE__ */ jsx(CardReadyContext.Provider, { value, children });
314
+ }
315
+ function useCardReady() {
316
+ const context = useContext(CardReadyContext);
317
+ if (!context) {
318
+ return { isReady: true };
319
+ }
320
+ return { isReady: context.isAnimationComplete };
321
+ }
322
+ function cn(...inputs) {
323
+ return twMerge(clsx(inputs));
324
+ }
325
+ var PORTAL_ROOT_ID = "portal-root";
326
+ React.createContext({
327
+ layer: "base",
328
+ depth: 0,
329
+ floatingPortalStrategy: "root",
330
+ floatingZIndex: "default"
331
+ });
332
+ function useRootPortalContainer() {
333
+ const [container, setContainer] = React.useState(null);
334
+ React.useLayoutEffect(() => {
335
+ const el = document.getElementById(PORTAL_ROOT_ID);
336
+ setContainer(el);
337
+ }, []);
338
+ return container;
339
+ }
340
+
341
+ // src/components/stack/stack-animations.ts
342
+ var DEFAULT_ANIMATION_CONFIG = {
343
+ duration: 0.2,
344
+ enterEase: [0.32, 0.72, 0, 1],
345
+ // Snappy entrance
346
+ exitEase: [0.4, 0, 0.6, 1]
347
+ // Physical exit
348
+ };
349
+ function createCardVariants(config = {}) {
350
+ const { duration, enterEase, exitEase } = {
351
+ ...DEFAULT_ANIMATION_CONFIG,
352
+ ...config
353
+ };
354
+ return {
355
+ initial: {
356
+ x: "100%"
357
+ },
358
+ animate: {
359
+ x: 0,
360
+ transition: {
361
+ type: "tween",
362
+ duration,
363
+ ease: enterEase
364
+ }
365
+ },
366
+ exit: {
367
+ x: "100%",
368
+ transition: {
369
+ type: "tween",
370
+ duration,
371
+ ease: exitEase
372
+ }
373
+ }
374
+ };
375
+ }
376
+ function createOffsetTransition(_config = {}) {
377
+ return {
378
+ type: "spring",
379
+ stiffness: 300,
380
+ damping: 30,
381
+ mass: 0.8
382
+ };
383
+ }
384
+ var backdropVariants = {
385
+ initial: {
386
+ opacity: 0
387
+ },
388
+ animate: {
389
+ opacity: 1,
390
+ transition: {
391
+ duration: 0.2,
392
+ ease: "easeOut"
393
+ }
394
+ },
395
+ exit: {
396
+ opacity: 0,
397
+ transition: {
398
+ duration: 0.25,
399
+ ease: [0.4, 0, 0.6, 1]
400
+ // Match card exit easing
401
+ }
402
+ }
403
+ };
404
+ var snapBackSpring = {
405
+ type: "spring",
406
+ stiffness: 400,
407
+ damping: 30,
408
+ mass: 0.8
409
+ };
410
+ var swipeDismissTransition = {
411
+ type: "tween",
412
+ duration: 0.2,
413
+ ease: [0.4, 0, 0.6, 1]
414
+ };
415
+ var lastCardExitTransition = {
416
+ type: "tween",
417
+ duration: 0.25,
418
+ ease: [0.4, 0, 0.6, 1]
419
+ // Physical exit easing
420
+ };
421
+ var peekHoverSpring = {
422
+ type: "spring",
423
+ stiffness: 500,
424
+ damping: 25,
425
+ mass: 0.6
426
+ };
427
+ var peekDragSpring = {
428
+ type: "spring",
429
+ stiffness: 600,
430
+ damping: 35,
431
+ mass: 0.5
432
+ };
433
+ var peekSlideSpring = {
434
+ type: "spring",
435
+ stiffness: 400,
436
+ damping: 30,
437
+ mass: 0.7
438
+ };
439
+ function createReducedMotionVariants() {
440
+ return {
441
+ initial: {
442
+ x: 0,
443
+ opacity: 0
444
+ },
445
+ animate: {
446
+ x: 0,
447
+ opacity: 1,
448
+ transition: { duration: 0 }
449
+ },
450
+ exit: {
451
+ x: 0,
452
+ opacity: 0,
453
+ transition: { duration: 0 }
454
+ }
455
+ };
456
+ }
457
+ var reducedMotionBackdropVariants = {
458
+ initial: { opacity: 0 },
459
+ animate: { opacity: 1, transition: { duration: 0 } },
460
+ exit: { opacity: 0, transition: { duration: 0 } }
461
+ };
462
+ function StackBackdrop({ className, onClick, config: backdropConfig }) {
463
+ const { config } = useStackContext();
464
+ const api = useCardStack();
465
+ const prefersReducedMotion = useReducedMotion();
466
+ const handleClick = React.useCallback(() => {
467
+ if (onClick) {
468
+ onClick();
469
+ } else {
470
+ api.clear();
471
+ }
472
+ }, [onClick, api]);
473
+ const variants = prefersReducedMotion ? reducedMotionBackdropVariants : backdropVariants;
474
+ const useBlur = backdropConfig?.blur ?? false;
475
+ return /* @__PURE__ */ jsx(
476
+ motion.div,
477
+ {
478
+ "data-slot": "stack-backdrop",
479
+ variants,
480
+ initial: "initial",
481
+ animate: "animate",
482
+ exit: "exit",
483
+ onClick: handleClick,
484
+ style: {
485
+ zIndex: config.zIndexBase - 1,
486
+ willChange: "opacity"
487
+ },
488
+ className: cn(
489
+ "fixed inset-0",
490
+ "cursor-pointer",
491
+ // Default overlay or custom className
492
+ backdropConfig?.className ?? "bg-black/50",
493
+ // Optional blur
494
+ useBlur && "backdrop-blur-sm",
495
+ className
496
+ )
497
+ }
498
+ );
499
+ }
500
+ var sizeStyles = {
501
+ sm: {
502
+ title: "text-sm font-semibold",
503
+ description: "text-xs",
504
+ height: "h-12",
505
+ heightWithDesc: "h-14"
506
+ },
507
+ md: {
508
+ title: "text-base font-semibold",
509
+ description: "text-sm",
510
+ height: "h-14",
511
+ heightWithDesc: "h-18"
512
+ },
513
+ lg: {
514
+ title: "text-lg font-semibold",
515
+ description: "text-sm",
516
+ height: "h-16",
517
+ heightWithDesc: "h-20"
518
+ }
519
+ };
520
+ function StackHeader({ card, onClose, className, renderTitle }) {
521
+ const title = renderTitle ? renderTitle(card) : card.title;
522
+ const hasDescription = !!card.description;
523
+ const size = card.headerSize ?? "md";
524
+ const styles = sizeStyles[size];
525
+ return /* @__PURE__ */ jsxs(
526
+ "div",
527
+ {
528
+ "data-slot": "stack-header",
529
+ className: cn(
530
+ "flex shrink-0 items-center justify-between",
531
+ "border-b border-border/50",
532
+ "px-4",
533
+ hasDescription ? styles.heightWithDesc : styles.height,
534
+ className
535
+ ),
536
+ children: [
537
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
538
+ title && /* @__PURE__ */ jsx("h2", { className: cn("text-foreground truncate", styles.title), children: title }),
539
+ card.description && /* @__PURE__ */ jsx("p", { className: cn("text-muted-foreground truncate", styles.description), children: card.description })
540
+ ] }),
541
+ /* @__PURE__ */ jsx(
542
+ "button",
543
+ {
544
+ type: "button",
545
+ onClick: onClose,
546
+ className: cn(
547
+ "flex h-8 w-8 items-center justify-center",
548
+ "rounded-md",
549
+ "text-muted-foreground hover:text-foreground",
550
+ "hover:bg-muted/50",
551
+ "transition-colors",
552
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
553
+ ),
554
+ "aria-label": "Close",
555
+ children: /* @__PURE__ */ jsx(ChevronRight, { className: "h-5 w-5" })
556
+ }
557
+ )
558
+ ]
559
+ }
560
+ );
561
+ }
562
+ function StackHeaderSlot({ className, children }) {
563
+ return /* @__PURE__ */ jsx(
564
+ "div",
565
+ {
566
+ "data-slot": "stack-header-slot",
567
+ className: cn("flex h-12 shrink-0 items-center", "border-b border-border/50", "px-4", className),
568
+ children
569
+ }
570
+ );
571
+ }
572
+
573
+ // src/components/stack/stack-utils.ts
574
+ function getCascadeOffset(cardIndex, totalCards, cards, defaultPeekOffset) {
575
+ const cardsAbove = totalCards - cardIndex - 1;
576
+ if (cardsAbove <= 0) return 0;
577
+ const card = cards[cardIndex];
578
+ const peekOffset = card?.peekOffset ?? defaultPeekOffset;
579
+ return cardsAbove * peekOffset;
580
+ }
581
+ function getSideBySideOffset(cardIndex, totalCards, topCardWidth, defaultPeekOffset) {
582
+ if (totalCards === 0) return 0;
583
+ const cardsAbove = totalCards - cardIndex - 1;
584
+ if (cardsAbove === 0) return 0;
585
+ if (cardsAbove === 1) return topCardWidth;
586
+ const extraDepth = cardsAbove - 1;
587
+ return topCardWidth + extraDepth * defaultPeekOffset;
588
+ }
589
+ function getCardOffset(cardIndex, totalCards, cards, layoutMode, topCardWidth, defaultPeekOffset) {
590
+ if (layoutMode === "side-by-side") {
591
+ return getSideBySideOffset(cardIndex, totalCards, topCardWidth, defaultPeekOffset);
592
+ }
593
+ return getCascadeOffset(cardIndex, totalCards, cards, defaultPeekOffset);
594
+ }
595
+ var MIN_VISIBLE_PEEK = 24;
596
+ var VIEWPORT_PADDING = 16;
597
+ function calculateResponsiveOffset(config) {
598
+ const {
599
+ viewportWidth,
600
+ topCardWidth,
601
+ secondCardWidth,
602
+ totalCards,
603
+ defaultPeekOffset,
604
+ layoutMode
605
+ } = config;
606
+ const availableWidth = viewportWidth - VIEWPORT_PADDING * 2;
607
+ if (totalCards <= 1) {
608
+ return {
609
+ compressionRatio: 1,
610
+ shouldCollapse: false,
611
+ adjustedPeekOffset: defaultPeekOffset,
612
+ availableSpace: availableWidth
613
+ };
614
+ }
615
+ if (layoutMode === "side-by-side") {
616
+ const idealWidth2 = topCardWidth + secondCardWidth;
617
+ if (availableWidth >= idealWidth2) {
618
+ return {
619
+ compressionRatio: 1,
620
+ shouldCollapse: false,
621
+ adjustedPeekOffset: defaultPeekOffset,
622
+ availableSpace: availableWidth - topCardWidth
623
+ };
624
+ }
625
+ const overflow = idealWidth2 - availableWidth;
626
+ const maxCompression = secondCardWidth - MIN_VISIBLE_PEEK;
627
+ if (overflow >= maxCompression) {
628
+ return {
629
+ compressionRatio: 0,
630
+ shouldCollapse: true,
631
+ adjustedPeekOffset: 0,
632
+ availableSpace: 0
633
+ };
634
+ }
635
+ const compressionRatio2 = 1 - overflow / maxCompression;
636
+ const adjustedSecondCardVisible = secondCardWidth - overflow;
637
+ return {
638
+ compressionRatio: compressionRatio2,
639
+ shouldCollapse: false,
640
+ adjustedPeekOffset: defaultPeekOffset * compressionRatio2,
641
+ availableSpace: adjustedSecondCardVisible
642
+ };
643
+ }
644
+ const cascadeDepth = totalCards - 1;
645
+ const totalPeekNeeded = cascadeDepth * defaultPeekOffset;
646
+ const idealWidth = topCardWidth + totalPeekNeeded;
647
+ if (availableWidth >= idealWidth) {
648
+ return {
649
+ compressionRatio: 1,
650
+ shouldCollapse: false,
651
+ adjustedPeekOffset: defaultPeekOffset,
652
+ availableSpace: totalPeekNeeded
653
+ };
654
+ }
655
+ const availableForPeek = Math.max(0, availableWidth - topCardWidth);
656
+ const minPeekNeeded = cascadeDepth * MIN_VISIBLE_PEEK;
657
+ if (availableForPeek < minPeekNeeded) {
658
+ return {
659
+ compressionRatio: 0,
660
+ shouldCollapse: true,
661
+ adjustedPeekOffset: 0,
662
+ availableSpace: 0
663
+ };
664
+ }
665
+ const compressionRatio = availableForPeek / totalPeekNeeded;
666
+ const adjustedPeekOffset = defaultPeekOffset * compressionRatio;
667
+ return {
668
+ compressionRatio,
669
+ shouldCollapse: false,
670
+ adjustedPeekOffset: Math.max(MIN_VISIBLE_PEEK, adjustedPeekOffset),
671
+ availableSpace: availableForPeek
672
+ };
673
+ }
674
+ function getResponsiveCardOffset(cardIndex, totalCards, cards, layoutMode, topCardWidth, adjustedPeekOffset, compressionRatio, defaultWidth = 480) {
675
+ if (totalCards === 0) return 0;
676
+ const cardsAbove = totalCards - cardIndex - 1;
677
+ if (cardsAbove === 0) return 0;
678
+ if (layoutMode === "side-by-side") {
679
+ const getWidth = (idx) => {
680
+ const card2 = cards[idx];
681
+ const w = card2?.width;
682
+ if (w === void 0) return defaultWidth;
683
+ if (typeof w === "number") return w;
684
+ if (w.endsWith("px")) return parseFloat(w) || defaultWidth;
685
+ return defaultWidth;
686
+ };
687
+ const getIdealOffset = (idx) => {
688
+ const cardsAboveIdx = totalCards - idx - 1;
689
+ if (cardsAboveIdx === 0) return 0;
690
+ if (cardsAboveIdx === 1) return topCardWidth * compressionRatio + adjustedPeekOffset * (1 - compressionRatio);
691
+ const extraDepth = cardsAboveIdx - 1;
692
+ const secondOffset = topCardWidth * compressionRatio + adjustedPeekOffset * (1 - compressionRatio);
693
+ return secondOffset + extraDepth * adjustedPeekOffset;
694
+ };
695
+ const adjustedOffsets = new Array(totalCards).fill(0);
696
+ for (let idx = totalCards - 1; idx >= 0; idx--) {
697
+ const ideal = getIdealOffset(idx);
698
+ const width = getWidth(idx);
699
+ const cardAtIdx = cards[idx];
700
+ const allowCover = cardAtIdx?.allowCover ?? false;
701
+ if (allowCover) {
702
+ adjustedOffsets[idx] = ideal;
703
+ continue;
704
+ }
705
+ let minRequired = 0;
706
+ for (let j = idx + 1; j < totalCards; j++) {
707
+ const aboveLeftEdge = adjustedOffsets[j] + getWidth(j);
708
+ const required = aboveLeftEdge - width + MIN_VISIBLE_PEEK;
709
+ minRequired = Math.max(minRequired, required);
710
+ }
711
+ adjustedOffsets[idx] = Math.max(ideal, minRequired);
712
+ }
713
+ return adjustedOffsets[cardIndex];
714
+ }
715
+ const card = cards[cardIndex];
716
+ const peekOffset = card?.peekOffset ?? adjustedPeekOffset;
717
+ return cardsAbove * peekOffset * compressionRatio + cardsAbove * MIN_VISIBLE_PEEK * (1 - compressionRatio);
718
+ }
719
+ function normalizeWidth(width, defaultWidth) {
720
+ if (width === void 0) {
721
+ return typeof defaultWidth === "number" ? `${defaultWidth}px` : defaultWidth;
722
+ }
723
+ return typeof width === "number" ? `${width}px` : width;
724
+ }
725
+ function parseWidthToPixels(width) {
726
+ if (width === void 0) return void 0;
727
+ if (typeof width === "number") return width;
728
+ if (width.endsWith("px")) {
729
+ const parsed = parseFloat(width);
730
+ return isNaN(parsed) ? void 0 : parsed;
731
+ }
732
+ if (width.endsWith("rem")) {
733
+ const parsed = parseFloat(width);
734
+ return isNaN(parsed) ? void 0 : parsed * 16;
735
+ }
736
+ return void 0;
737
+ }
738
+ function getCardZIndex(cardIndex, zIndexBase) {
739
+ return zIndexBase + cardIndex * 10;
740
+ }
741
+ function getVisibleCardIndices(totalCards, peekDepth) {
742
+ if (totalCards === 0) return [];
743
+ const startIndex = Math.max(0, totalCards - peekDepth - 1);
744
+ const indices = [];
745
+ for (let i = startIndex; i < totalCards; i++) {
746
+ indices.push(i);
747
+ }
748
+ return indices;
749
+ }
750
+ function isCardVisible(cardIndex, totalCards, peekDepth) {
751
+ if (totalCards === 0) return false;
752
+ const startIndex = Math.max(0, totalCards - peekDepth - 1);
753
+ return cardIndex >= startIndex;
754
+ }
755
+ var DEFAULT_HOVER_EXPANSION = 48;
756
+ var DEFAULT_DRAG_THRESHOLD = 80;
757
+ var DEFAULT_VELOCITY_THRESHOLD = 400;
758
+ function usePeekGestures(options) {
759
+ const {
760
+ enabled = true,
761
+ dragToDismiss = true,
762
+ hoverExpansion = DEFAULT_HOVER_EXPANSION,
763
+ dragThreshold = DEFAULT_DRAG_THRESHOLD,
764
+ dragVelocityThreshold = DEFAULT_VELOCITY_THRESHOLD,
765
+ cardIndex,
766
+ totalCards,
767
+ onPeekClick,
768
+ onPeekDragDismiss,
769
+ onPeekDrag,
770
+ onPeekDragCancel
771
+ } = options;
772
+ const prefersReducedMotion = useReducedMotion();
773
+ const [isHovered, setIsHovered] = useState(false);
774
+ const [isDragging, setIsDragging] = useState(false);
775
+ const [dragOffset, setDragOffset] = useState(0);
776
+ const startXRef = useRef(0);
777
+ const startTimeRef = useRef(0);
778
+ const pointerIdRef = useRef(null);
779
+ const hasDraggedRef = useRef(false);
780
+ const isTopCard = cardIndex === totalCards - 1;
781
+ const isEnabled = enabled && !isTopCard;
782
+ const handleMouseEnter = useCallback(() => {
783
+ if (!isEnabled || prefersReducedMotion) return;
784
+ setIsHovered(true);
785
+ }, [isEnabled, prefersReducedMotion]);
786
+ const handleMouseLeave = useCallback(() => {
787
+ if (!isEnabled) return;
788
+ setIsHovered(false);
789
+ }, [isEnabled]);
790
+ const handleClick = useCallback(
791
+ (e) => {
792
+ if (!isEnabled) return;
793
+ if (hasDraggedRef.current) {
794
+ hasDraggedRef.current = false;
795
+ return;
796
+ }
797
+ e.stopPropagation();
798
+ onPeekClick();
799
+ },
800
+ [isEnabled, onPeekClick]
801
+ );
802
+ const handlePointerDown = useCallback(
803
+ (e) => {
804
+ if (!isEnabled || !dragToDismiss) return;
805
+ if (e.pointerType === "mouse" && e.button !== 0) return;
806
+ pointerIdRef.current = e.pointerId;
807
+ e.target.setPointerCapture(e.pointerId);
808
+ startXRef.current = e.clientX;
809
+ startTimeRef.current = Date.now();
810
+ hasDraggedRef.current = false;
811
+ setIsDragging(true);
812
+ e.stopPropagation();
813
+ },
814
+ [isEnabled, dragToDismiss]
815
+ );
816
+ const handlePointerMove = useCallback(
817
+ (e) => {
818
+ if (!isEnabled || pointerIdRef.current !== e.pointerId) return;
819
+ const deltaX = e.clientX - startXRef.current;
820
+ const clampedDelta = Math.max(0, deltaX);
821
+ if (clampedDelta > 5) {
822
+ hasDraggedRef.current = true;
823
+ }
824
+ setDragOffset(clampedDelta);
825
+ onPeekDrag?.(clampedDelta);
826
+ e.stopPropagation();
827
+ },
828
+ [isEnabled, onPeekDrag]
829
+ );
830
+ const handlePointerUp = useCallback(
831
+ (e) => {
832
+ if (!isEnabled || pointerIdRef.current !== e.pointerId) return;
833
+ e.target.releasePointerCapture(e.pointerId);
834
+ const deltaX = e.clientX - startXRef.current;
835
+ const deltaTime = Date.now() - startTimeRef.current;
836
+ const velocity = deltaTime > 0 ? deltaX / deltaTime * 1e3 : 0;
837
+ const shouldDismiss = deltaX > dragThreshold || velocity > dragVelocityThreshold;
838
+ if (shouldDismiss && deltaX > 0) {
839
+ onPeekDragDismiss();
840
+ } else {
841
+ onPeekDragCancel?.();
842
+ }
843
+ pointerIdRef.current = null;
844
+ setIsDragging(false);
845
+ setDragOffset(0);
846
+ e.stopPropagation();
847
+ },
848
+ [isEnabled, dragThreshold, dragVelocityThreshold, onPeekDragDismiss, onPeekDragCancel]
849
+ );
850
+ const handlePointerCancel = useCallback(
851
+ (e) => {
852
+ if (pointerIdRef.current === e.pointerId) {
853
+ pointerIdRef.current = null;
854
+ setIsDragging(false);
855
+ setDragOffset(0);
856
+ onPeekDragCancel?.();
857
+ }
858
+ },
859
+ [onPeekDragCancel]
860
+ );
861
+ return {
862
+ isHovered,
863
+ isDragging,
864
+ dragOffset,
865
+ hoverExpansion: isEnabled && !prefersReducedMotion ? hoverExpansion : 0,
866
+ handlers: {
867
+ onMouseEnter: handleMouseEnter,
868
+ onMouseLeave: handleMouseLeave,
869
+ onClick: handleClick,
870
+ onPointerDown: handlePointerDown,
871
+ onPointerMove: handlePointerMove,
872
+ onPointerUp: handlePointerUp,
873
+ onPointerCancel: handlePointerCancel
874
+ }
875
+ };
876
+ }
877
+ var DEFAULT_HOVER_EXPANSION2 = 48;
878
+ function StackCardInner({
879
+ card,
880
+ index,
881
+ totalCards,
882
+ topCardWidth,
883
+ animation,
884
+ isMobile = false,
885
+ renderHeader,
886
+ peekGestureConfig,
887
+ compressionRatio = 1,
888
+ adjustedPeekOffset,
889
+ dragX = 0,
890
+ gestureBind,
891
+ isPeekHovered = false,
892
+ onPeekHoverStart,
893
+ onPeekHoverEnd,
894
+ peekDragOffset = 0,
895
+ onPeekDragStart,
896
+ onPeekDrag,
897
+ onPeekDragEnd,
898
+ isLastCard = false,
899
+ className
900
+ }) {
901
+ const { config, api, state } = useStackContext();
902
+ const prefersReducedMotion = useReducedMotion();
903
+ const injectedProps = useCardInjectedProps(card.id);
904
+ const [isAnimationComplete, setAnimationComplete] = useState(prefersReducedMotion ?? false);
905
+ const handleAnimationComplete = useCallback(() => {
906
+ setAnimationComplete(true);
907
+ }, []);
908
+ const isTopCard = index === totalCards - 1;
909
+ const isSecondCard = index === totalCards - 2;
910
+ const hasPeekZone = !isTopCard && !isMobile && !(config.layoutMode === "side-by-side" && isSecondCard);
911
+ const zIndex = getCardZIndex(index, config.zIndexBase);
912
+ const effectivePeekOffset = adjustedPeekOffset ?? config.defaultPeekOffset;
913
+ const baseOffset = useMemo(
914
+ () => getResponsiveCardOffset(
915
+ index,
916
+ totalCards,
917
+ state.cards,
918
+ config.layoutMode,
919
+ topCardWidth,
920
+ effectivePeekOffset,
921
+ compressionRatio,
922
+ typeof config.defaultWidth === "number" ? config.defaultWidth : 480
923
+ ),
924
+ [index, totalCards, state.cards, config.layoutMode, topCardWidth, effectivePeekOffset, compressionRatio, config.defaultWidth]
925
+ );
926
+ const cardWidth = isMobile ? "100%" : normalizeWidth(card.width, config.defaultWidth);
927
+ const offsetTransition = createOffsetTransition(animation);
928
+ const handleClose = useCallback(() => {
929
+ api.dismiss(card.id);
930
+ }, [api, card.id]);
931
+ const handlePeekClick = useCallback(() => {
932
+ api.popTo(card.id);
933
+ }, [api, card.id]);
934
+ const handlePeekDragDismiss = useCallback(() => {
935
+ onPeekDragEnd?.(index, true);
936
+ }, [index, onPeekDragEnd]);
937
+ const handlePeekDrag = useCallback(
938
+ (offset) => {
939
+ onPeekDrag?.(index, offset);
940
+ },
941
+ [index, onPeekDrag]
942
+ );
943
+ const handlePeekDragCancel = useCallback(() => {
944
+ onPeekDragEnd?.(index, false);
945
+ }, [index, onPeekDragEnd]);
946
+ const handlePeekHoverStart = useCallback(() => {
947
+ onPeekHoverStart?.(index);
948
+ }, [index, onPeekHoverStart]);
949
+ const handlePeekHoverEnd = useCallback(() => {
950
+ onPeekHoverEnd?.(index);
951
+ }, [index, onPeekHoverEnd]);
952
+ const peekGestures = usePeekGestures({
953
+ ...peekGestureConfig,
954
+ cardIndex: index,
955
+ totalCards,
956
+ onPeekClick: handlePeekClick,
957
+ onPeekDragDismiss: handlePeekDragDismiss,
958
+ onPeekDrag: handlePeekDrag,
959
+ onPeekDragCancel: handlePeekDragCancel
960
+ });
961
+ const hoverExpansion = hasPeekZone && isPeekHovered && !peekGestures.isDragging && !prefersReducedMotion ? peekGestureConfig?.hoverExpansion ?? DEFAULT_HOVER_EXPANSION2 : 0;
962
+ const xOffset = -baseOffset + dragX - hoverExpansion + peekDragOffset;
963
+ const CardComponent = card.Component;
964
+ const cardContent = useMemo(() => {
965
+ return /* @__PURE__ */ jsx(CardReadyProvider, { isAnimationComplete, children: /* @__PURE__ */ jsx(CardComponent, { ...card.props, ...injectedProps }) });
966
+ }, [CardComponent, card.props, injectedProps, isAnimationComplete]);
967
+ const headerContent = renderHeader ? renderHeader(card, api) : /* @__PURE__ */ jsx(StackHeader, { card, onClose: handleClose });
968
+ const animateX = xOffset;
969
+ const initialX = prefersReducedMotion ? xOffset : "100%";
970
+ const exitX = prefersReducedMotion ? xOffset : "100%";
971
+ const exitOpacity = prefersReducedMotion ? 0 : isLastCard ? 0 : 1;
972
+ let activeTransition = offsetTransition;
973
+ if (peekGestures.isDragging || peekDragOffset > 0) {
974
+ activeTransition = peekDragSpring;
975
+ } else if (isPeekHovered) {
976
+ activeTransition = peekHoverSpring;
977
+ }
978
+ const exitAnimation = isLastCard && !prefersReducedMotion ? { x: exitX, opacity: exitOpacity, transition: lastCardExitTransition } : { x: exitX, opacity: exitOpacity };
979
+ return /* @__PURE__ */ jsxs(
980
+ motion.div,
981
+ {
982
+ "data-slot": "stack-card",
983
+ "data-card-id": card.id,
984
+ "data-card-index": index,
985
+ "data-is-top": isTopCard,
986
+ "data-offset": baseOffset,
987
+ initial: { x: initialX, opacity: prefersReducedMotion ? 0 : 1 },
988
+ animate: { x: animateX, opacity: 1 },
989
+ exit: exitAnimation,
990
+ transition: activeTransition,
991
+ onAnimationComplete: handleAnimationComplete,
992
+ style: {
993
+ position: "fixed",
994
+ top: 0,
995
+ right: 0,
996
+ height: "100dvh",
997
+ width: cardWidth,
998
+ zIndex,
999
+ willChange: "transform",
1000
+ // On mobile, allow vertical pan (scroll) but handle horizontal ourselves
1001
+ // This prevents conflict with iOS Safari gestures while allowing content scroll
1002
+ touchAction: isMobile ? "pan-y pinch-zoom" : void 0
1003
+ },
1004
+ className: cn(
1005
+ "flex flex-col",
1006
+ "bg-background",
1007
+ "shadow-lg",
1008
+ "border-l border-border/50",
1009
+ className
1010
+ ),
1011
+ ...isTopCard && isMobile && gestureBind ? gestureBind() : {},
1012
+ children: [
1013
+ hasPeekZone && /* @__PURE__ */ jsx(
1014
+ "div",
1015
+ {
1016
+ "data-slot": "peek-zone",
1017
+ className: cn(
1018
+ "absolute inset-y-0",
1019
+ "cursor-pointer",
1020
+ // Visual feedback during hover/drag (using viewport-coordinated state)
1021
+ isPeekHovered && "bg-primary/5",
1022
+ peekGestures.isDragging && "bg-primary/10"
1023
+ ),
1024
+ style: {
1025
+ // Peek zone covers the visible peek area (baseOffset determines how much is visible)
1026
+ // Minimum 32px, expands when hovered to keep mouse inside during animation
1027
+ left: 0,
1028
+ width: isPeekHovered ? Math.max(32, baseOffset) + hoverExpansion : Math.max(32, baseOffset),
1029
+ zIndex: zIndex + 1,
1030
+ // Smooth transition to prevent sudden size jumps
1031
+ transition: "width 0.15s ease-out"
1032
+ },
1033
+ onMouseEnter: handlePeekHoverStart,
1034
+ onMouseLeave: handlePeekHoverEnd,
1035
+ onClick: peekGestures.handlers.onClick,
1036
+ onPointerDown: peekGestures.handlers.onPointerDown,
1037
+ onPointerMove: peekGestures.handlers.onPointerMove,
1038
+ onPointerUp: peekGestures.handlers.onPointerUp,
1039
+ onPointerCancel: peekGestures.handlers.onPointerCancel
1040
+ }
1041
+ ),
1042
+ headerContent,
1043
+ /* @__PURE__ */ jsx(
1044
+ "div",
1045
+ {
1046
+ "data-slot": "stack-card-content",
1047
+ className: "flex-1 overflow-auto",
1048
+ style: {
1049
+ // Allow vertical scroll but let us handle horizontal
1050
+ touchAction: isMobile ? "pan-y pinch-zoom" : void 0
1051
+ },
1052
+ ...isTopCard && isMobile && gestureBind ? gestureBind() : {},
1053
+ children: cardContent
1054
+ }
1055
+ )
1056
+ ]
1057
+ }
1058
+ );
1059
+ }
1060
+ var StackCard = memo(StackCardInner);
1061
+ var DEFAULT_SWIPE_THRESHOLD = 120;
1062
+ var DEFAULT_VELOCITY_THRESHOLD2 = 0.6;
1063
+ var MIN_VELOCITY_DISTANCE = 60;
1064
+ var EDGE_IGNORE_ZONE = 30;
1065
+ function useStackGestures(options) {
1066
+ const {
1067
+ enabled = true,
1068
+ swipeToPop = true,
1069
+ swipeThreshold = DEFAULT_SWIPE_THRESHOLD,
1070
+ velocityThreshold = DEFAULT_VELOCITY_THRESHOLD2,
1071
+ autoDismissThreshold,
1072
+ onDismiss
1073
+ } = options;
1074
+ const prefersReducedMotion = useReducedMotion();
1075
+ const isEnabled = enabled && swipeToPop && !prefersReducedMotion;
1076
+ const [dragX, setDragX] = useState(0);
1077
+ const [isDragging, setIsDragging] = useState(false);
1078
+ const handleDismiss = useCallback(() => {
1079
+ onDismiss();
1080
+ }, [onDismiss]);
1081
+ const dismissedRef = useRef(false);
1082
+ const velocityMinDistance = Math.max(MIN_VELOCITY_DISTANCE, swipeThreshold * 0.25);
1083
+ const bind = useDrag(
1084
+ ({ active, movement: [mx], velocity: [vx], direction: [dx], initial: [initialX], xy: [currentX], cancel, first }) => {
1085
+ if (first && initialX < EDGE_IGNORE_ZONE) {
1086
+ cancel();
1087
+ return;
1088
+ }
1089
+ if (first) {
1090
+ dismissedRef.current = false;
1091
+ }
1092
+ const clampedX = Math.max(0, mx);
1093
+ if (active) {
1094
+ const canAutoDismiss = autoDismissThreshold !== void 0 && !dismissedRef.current && dx > 0 && clampedX >= 24 && currentX >= autoDismissThreshold;
1095
+ if (canAutoDismiss) {
1096
+ dismissedRef.current = true;
1097
+ setDragX(0);
1098
+ setIsDragging(false);
1099
+ handleDismiss();
1100
+ cancel();
1101
+ return;
1102
+ }
1103
+ setDragX(clampedX);
1104
+ setIsDragging(true);
1105
+ return;
1106
+ }
1107
+ if (!dismissedRef.current) {
1108
+ const shouldDismiss = dx > 0 && (clampedX > swipeThreshold || vx > velocityThreshold && clampedX > velocityMinDistance);
1109
+ if (shouldDismiss) {
1110
+ handleDismiss();
1111
+ }
1112
+ }
1113
+ setDragX(0);
1114
+ setIsDragging(false);
1115
+ },
1116
+ {
1117
+ enabled: isEnabled,
1118
+ // Only activate after moving 10px (prevents accidental triggers)
1119
+ threshold: 10,
1120
+ // Lock to horizontal axis once gesture starts
1121
+ axis: "x",
1122
+ // Filter by direction - only track if moving more horizontally than vertically
1123
+ filterTaps: true,
1124
+ // Use touch-action to allow vertical scroll
1125
+ pointer: {
1126
+ touch: true
1127
+ }
1128
+ }
1129
+ );
1130
+ return {
1131
+ dragX,
1132
+ isDragging,
1133
+ bind
1134
+ };
1135
+ }
1136
+ var DEFAULT_MOBILE_BREAKPOINT = 768;
1137
+ function useStackResponsive(options = {}) {
1138
+ const { breakpoint = DEFAULT_MOBILE_BREAKPOINT } = options;
1139
+ const [state, setState] = useState(() => {
1140
+ if (typeof window === "undefined") {
1141
+ return { isMobile: false, viewportWidth: 1024 };
1142
+ }
1143
+ const width = window.innerWidth;
1144
+ return { isMobile: width < breakpoint, viewportWidth: width };
1145
+ });
1146
+ const updateState = useCallback(() => {
1147
+ const width = window.innerWidth;
1148
+ setState((prev) => {
1149
+ const isMobile = width < breakpoint;
1150
+ if (prev.isMobile === isMobile && prev.viewportWidth === width) {
1151
+ return prev;
1152
+ }
1153
+ return { isMobile, viewportWidth: width };
1154
+ });
1155
+ }, [breakpoint]);
1156
+ useEffect(() => {
1157
+ updateState();
1158
+ window.addEventListener("resize", updateState);
1159
+ return () => window.removeEventListener("resize", updateState);
1160
+ }, [updateState]);
1161
+ return {
1162
+ isMobile: state.isMobile,
1163
+ viewportWidth: state.viewportWidth,
1164
+ breakpoint
1165
+ };
1166
+ }
1167
+ function useIsMobile(breakpoint = DEFAULT_MOBILE_BREAKPOINT) {
1168
+ const { isMobile } = useStackResponsive({ breakpoint });
1169
+ return isMobile;
1170
+ }
1171
+ var DEFAULT_PEEK_DEPTH = 2;
1172
+ function CardStackViewport({
1173
+ backdrop = true,
1174
+ renderBackdrop,
1175
+ renderHeader,
1176
+ renderEmpty,
1177
+ peekDepth = DEFAULT_PEEK_DEPTH,
1178
+ animation,
1179
+ mobile,
1180
+ peekGestures,
1181
+ className
1182
+ }) {
1183
+ const { config, api } = useStackContext();
1184
+ const cards = useStackCards();
1185
+ const { isMobile, viewportWidth } = useStackResponsive(mobile);
1186
+ const [peekDrag, setPeekDrag] = useState({ sourceIndex: -1, offset: 0 });
1187
+ const [peekHover, setPeekHover] = useState({ hoveredIndex: -1 });
1188
+ const hoverEndTimeoutRef = useRef(null);
1189
+ const prevCardCountRef = useRef(cards.length);
1190
+ const [exitComplete, setExitComplete] = useState(cards.length === 0);
1191
+ useEffect(() => {
1192
+ if (cards.length > 0) {
1193
+ setExitComplete(false);
1194
+ }
1195
+ }, [cards.length]);
1196
+ useEffect(() => {
1197
+ if (cards.length !== prevCardCountRef.current) {
1198
+ setPeekHover({ hoveredIndex: -1 });
1199
+ if (hoverEndTimeoutRef.current) {
1200
+ clearTimeout(hoverEndTimeoutRef.current);
1201
+ hoverEndTimeoutRef.current = null;
1202
+ }
1203
+ prevCardCountRef.current = cards.length;
1204
+ }
1205
+ }, [cards.length]);
1206
+ const handleExitComplete = useCallback(() => {
1207
+ setExitComplete(true);
1208
+ }, []);
1209
+ const cardWidths = useMemo(() => {
1210
+ if (cards.length === 0) return { topCardWidth: 0, secondCardWidth: 0 };
1211
+ const topCard = cards[cards.length - 1];
1212
+ const topCardWidth = parseWidthToPixels(topCard.width ?? config.defaultWidth) ?? 480;
1213
+ const secondCard = cards.length > 1 ? cards[cards.length - 2] : null;
1214
+ const secondCardWidth = secondCard ? parseWidthToPixels(secondCard.width ?? config.defaultWidth) ?? 480 : 0;
1215
+ return { topCardWidth, secondCardWidth };
1216
+ }, [cards, config.defaultWidth]);
1217
+ const responsiveOffset = useMemo(() => {
1218
+ return calculateResponsiveOffset({
1219
+ viewportWidth,
1220
+ topCardWidth: cardWidths.topCardWidth,
1221
+ secondCardWidth: cardWidths.secondCardWidth,
1222
+ totalCards: cards.length,
1223
+ defaultPeekOffset: config.defaultPeekOffset,
1224
+ layoutMode: config.layoutMode
1225
+ });
1226
+ }, [viewportWidth, cardWidths, cards.length, config.defaultPeekOffset, config.layoutMode]);
1227
+ const useFullScreen = isMobile || responsiveOffset.shouldCollapse;
1228
+ const handleDismiss = useCallback(() => {
1229
+ api.pop();
1230
+ }, [api]);
1231
+ const swipeThreshold = mobile?.gestures?.swipeThreshold ?? Math.max(120, Math.round(viewportWidth * 0.35));
1232
+ const autoDismissThreshold = mobile?.gestures?.autoDismissThreshold ?? Math.max(swipeThreshold, Math.round(viewportWidth * 0.8));
1233
+ const { dragX, bind: gestureBind } = useStackGestures({
1234
+ enabled: useFullScreen && cards.length > 0,
1235
+ ...mobile?.gestures,
1236
+ swipeThreshold,
1237
+ autoDismissThreshold,
1238
+ onDismiss: handleDismiss
1239
+ });
1240
+ const handlePeekHoverStart = useCallback((cardIndex) => {
1241
+ if (hoverEndTimeoutRef.current) {
1242
+ clearTimeout(hoverEndTimeoutRef.current);
1243
+ hoverEndTimeoutRef.current = null;
1244
+ }
1245
+ setPeekHover({ hoveredIndex: cardIndex });
1246
+ }, []);
1247
+ const handlePeekHoverEnd = useCallback((cardIndex) => {
1248
+ if (hoverEndTimeoutRef.current) {
1249
+ clearTimeout(hoverEndTimeoutRef.current);
1250
+ }
1251
+ hoverEndTimeoutRef.current = setTimeout(() => {
1252
+ setPeekHover((prev) => prev.hoveredIndex === cardIndex ? { hoveredIndex: -1 } : prev);
1253
+ hoverEndTimeoutRef.current = null;
1254
+ }, 100);
1255
+ }, []);
1256
+ const handlePeekDrag = useCallback((cardIndex, offset) => {
1257
+ setPeekDrag({ sourceIndex: cardIndex, offset });
1258
+ }, []);
1259
+ const handlePeekDragEnd = useCallback(
1260
+ (cardIndex, shouldDismiss) => {
1261
+ if (shouldDismiss) {
1262
+ const card = cards[cardIndex];
1263
+ if (card) {
1264
+ api.popTo(card.id);
1265
+ }
1266
+ }
1267
+ setPeekDrag({ sourceIndex: -1, offset: 0 });
1268
+ },
1269
+ [api, cards]
1270
+ );
1271
+ const visibleCards = useMemo(() => {
1272
+ return cards.filter((_, index) => isCardVisible(index, cards.length, peekDepth));
1273
+ }, [cards, peekDepth]);
1274
+ const portalContainer = useRootPortalContainer();
1275
+ const renderBackdropNode = (config2) => {
1276
+ const defaultBackdrop = /* @__PURE__ */ jsx(StackBackdrop, { className: "pointer-events-auto", config: config2 }, "backdrop");
1277
+ if (renderBackdrop) {
1278
+ const customBackdrop = renderBackdrop();
1279
+ return React.isValidElement(customBackdrop) ? React.cloneElement(customBackdrop, { key: "backdrop" }) : defaultBackdrop;
1280
+ }
1281
+ return defaultBackdrop;
1282
+ };
1283
+ const hasCards = cards.length > 0;
1284
+ const resolvedBackdrop = useMemo(() => {
1285
+ const firstCard = cards[0];
1286
+ const cardBackdrop = firstCard?.backdrop;
1287
+ if (cardBackdrop !== void 0) {
1288
+ if (cardBackdrop === false) {
1289
+ return { enabled: false, config: void 0 };
1290
+ }
1291
+ if (cardBackdrop === true) {
1292
+ return { enabled: true, config: void 0 };
1293
+ }
1294
+ return { enabled: true, config: cardBackdrop };
1295
+ }
1296
+ if (backdrop === false) {
1297
+ return { enabled: false, config: void 0 };
1298
+ }
1299
+ if (backdrop === true) {
1300
+ return { enabled: true, config: void 0 };
1301
+ }
1302
+ return { enabled: true, config: backdrop };
1303
+ }, [cards, backdrop]);
1304
+ const shouldShowBackdrop = resolvedBackdrop.enabled;
1305
+ if (!hasCards && exitComplete) {
1306
+ return renderEmpty ? renderEmpty() : null;
1307
+ }
1308
+ const content = /* @__PURE__ */ jsx("div", { "data-slot": "stack-viewport", className: cn("pointer-events-none fixed inset-0", className), children: /* @__PURE__ */ jsxs(AnimatePresence, { mode: "popLayout", onExitComplete: handleExitComplete, children: [
1309
+ shouldShowBackdrop && hasCards && renderBackdropNode(resolvedBackdrop.config),
1310
+ visibleCards.map((card, visibleIndex) => {
1311
+ const actualIndex = cards.length - visibleCards.length + visibleIndex;
1312
+ const isTopCard = actualIndex === cards.length - 1;
1313
+ const isLastCard = cards.length === 1 && isTopCard;
1314
+ const peekDragOffset = peekDrag.sourceIndex >= 0 && actualIndex > peekDrag.sourceIndex ? peekDrag.offset : 0;
1315
+ return /* @__PURE__ */ jsx(
1316
+ StackCard,
1317
+ {
1318
+ card,
1319
+ index: actualIndex,
1320
+ totalCards: cards.length,
1321
+ topCardWidth: cardWidths.topCardWidth,
1322
+ animation,
1323
+ isMobile: useFullScreen,
1324
+ renderHeader,
1325
+ peekGestureConfig: peekGestures,
1326
+ compressionRatio: responsiveOffset.compressionRatio,
1327
+ adjustedPeekOffset: responsiveOffset.adjustedPeekOffset,
1328
+ dragX: isTopCard ? dragX : 0,
1329
+ gestureBind: isTopCard ? gestureBind : void 0,
1330
+ isPeekHovered: peekHover.hoveredIndex === actualIndex,
1331
+ onPeekHoverStart: handlePeekHoverStart,
1332
+ onPeekHoverEnd: handlePeekHoverEnd,
1333
+ peekDragOffset,
1334
+ onPeekDrag: handlePeekDrag,
1335
+ onPeekDragEnd: handlePeekDragEnd,
1336
+ isLastCard,
1337
+ className: "pointer-events-auto"
1338
+ },
1339
+ card.id
1340
+ );
1341
+ })
1342
+ ] }) });
1343
+ if (portalContainer) {
1344
+ return createPortal(content, portalContainer);
1345
+ }
1346
+ return content;
1347
+ }
1348
+ function Skeleton({ className, ...props }) {
1349
+ return /* @__PURE__ */ jsx("div", { "data-slot": "skeleton", className: cn("bg-primary/10 animate-pulse rounded-md", className), ...props });
1350
+ }
1351
+ function DeferredCardContent({
1352
+ children,
1353
+ placeholder,
1354
+ delay = 220,
1355
+ immediate = false,
1356
+ priority = "normal",
1357
+ onReady
1358
+ }) {
1359
+ const [ready, setReady] = useState(immediate);
1360
+ useEffect(() => {
1361
+ if (immediate) {
1362
+ onReady?.();
1363
+ return;
1364
+ }
1365
+ let cancelled = false;
1366
+ const scheduleReady = () => {
1367
+ if (cancelled) return;
1368
+ setReady(true);
1369
+ onReady?.();
1370
+ };
1371
+ const effectiveDelay = priority === "high" ? Math.floor(delay / 2) : delay;
1372
+ if (priority === "low" && "requestIdleCallback" in window) {
1373
+ const timeoutId2 = setTimeout(() => {
1374
+ const idleId = window.requestIdleCallback(scheduleReady, { timeout: effectiveDelay });
1375
+ return () => window.cancelIdleCallback(idleId);
1376
+ }, effectiveDelay);
1377
+ return () => {
1378
+ cancelled = true;
1379
+ clearTimeout(timeoutId2);
1380
+ };
1381
+ }
1382
+ const timeoutId = setTimeout(() => {
1383
+ const rafId = requestAnimationFrame(scheduleReady);
1384
+ return () => cancelAnimationFrame(rafId);
1385
+ }, effectiveDelay);
1386
+ return () => {
1387
+ cancelled = true;
1388
+ clearTimeout(timeoutId);
1389
+ };
1390
+ }, [delay, immediate, priority, onReady]);
1391
+ if (!ready) {
1392
+ return placeholder ?? /* @__PURE__ */ jsx(DefaultCardSkeleton, {});
1393
+ }
1394
+ return /* @__PURE__ */ jsx(Fragment, { children });
1395
+ }
1396
+ function DefaultCardSkeleton() {
1397
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-6 p-6", children: [
1398
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ jsx(Skeleton, { className: "h-24 w-48 rounded-lg" }) }),
1399
+ /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
1400
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
1401
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-20" }),
1402
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-10 w-full" })
1403
+ ] }),
1404
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
1405
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-16" }),
1406
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-10 w-full" })
1407
+ ] }),
1408
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
1409
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-24" }),
1410
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-10 w-full" })
1411
+ ] })
1412
+ ] })
1413
+ ] });
1414
+ }
1415
+
1416
+ export { CardStackProvider, CardStackViewport, DEFAULT_ANIMATION_CONFIG, DeferredCardContent, StackBackdrop, StackCard, StackHeader, StackHeaderSlot, backdropVariants, calculateResponsiveOffset, createCardVariants, createOffsetTransition, createReducedMotionVariants, getCardOffset, getCardZIndex, getCascadeOffset, getResponsiveCardOffset, getSideBySideOffset, getVisibleCardIndices, isCardVisible, normalizeWidth, parseWidthToPixels, peekDragSpring, peekHoverSpring, peekSlideSpring, reducedMotionBackdropVariants, snapBackSpring, swipeDismissTransition, useCardIndex, useCardInjectedProps, useCardReady, useCardStack, useIsMobile, useIsTopCard, usePeekGestures, useStackCards, useStackContext, useStackGestures, useStackLayoutMode, useStackResponsive };
1417
+ //# sourceMappingURL=index.js.map
1418
+ //# sourceMappingURL=index.js.map