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