@kumix/ui 0.3.0 → 0.3.2
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/README.md +46 -17
- package/dist/components/agents/agent-activity/activity-row.d.ts +8 -0
- package/dist/components/agents/agent-activity/activity-row.d.ts.map +1 -0
- package/dist/components/agents/agent-activity/activity-row.js +228 -0
- package/dist/components/agents/agent-activity/activity-row.js.map +1 -0
- package/dist/components/agents/agent-activity/index.d.ts +6 -0
- package/dist/components/agents/agent-activity/index.d.ts.map +1 -0
- package/dist/components/agents/agent-activity/index.js +182 -0
- package/dist/components/agents/agent-activity/index.js.map +1 -0
- package/dist/components/agents/agent-code.d.ts +25 -0
- package/dist/components/agents/agent-code.d.ts.map +1 -0
- package/dist/components/agents/agent-code.js +117 -0
- package/dist/components/agents/agent-code.js.map +1 -0
- package/dist/components/agents/agent-disclosure.d.ts +12 -0
- package/dist/components/agents/agent-disclosure.d.ts.map +1 -0
- package/dist/components/agents/agent-disclosure.js +36 -0
- package/dist/components/agents/agent-disclosure.js.map +1 -0
- package/dist/components/agents/ai-sidebar.d.ts +41 -0
- package/dist/components/agents/ai-sidebar.d.ts.map +1 -0
- package/dist/components/agents/ai-sidebar.js +576 -0
- package/dist/components/agents/ai-sidebar.js.map +1 -0
- package/dist/components/agents/approval-card/index.d.ts +51 -0
- package/dist/components/agents/approval-card/index.d.ts.map +1 -0
- package/dist/components/agents/approval-card/index.js +317 -0
- package/dist/components/agents/approval-card/index.js.map +1 -0
- package/dist/components/agents/chat-app.d.ts +10 -0
- package/dist/components/agents/chat-app.d.ts.map +1 -0
- package/dist/components/agents/chat-app.js +20 -0
- package/dist/components/agents/chat-app.js.map +1 -0
- package/dist/components/agents/citations.d.ts +45 -0
- package/dist/components/agents/citations.d.ts.map +1 -0
- package/dist/components/agents/citations.js +175 -0
- package/dist/components/agents/citations.js.map +1 -0
- package/dist/components/agents/code-block.d.ts +21 -0
- package/dist/components/agents/code-block.d.ts.map +1 -0
- package/dist/components/agents/code-block.js +113 -0
- package/dist/components/agents/code-block.js.map +1 -0
- package/dist/components/agents/file-diff.d.ts +30 -0
- package/dist/components/agents/file-diff.d.ts.map +1 -0
- package/dist/components/agents/file-diff.js +186 -0
- package/dist/components/agents/file-diff.js.map +1 -0
- package/dist/components/agents/image-generation.d.ts +27 -0
- package/dist/components/agents/image-generation.d.ts.map +1 -0
- package/dist/components/agents/image-generation.js +308 -0
- package/dist/components/agents/image-generation.js.map +1 -0
- package/dist/components/agents/loading-states/agent-progress.d.ts +16 -0
- package/dist/components/agents/loading-states/agent-progress.d.ts.map +1 -0
- package/dist/components/agents/loading-states/agent-progress.js +117 -0
- package/dist/components/agents/loading-states/agent-progress.js.map +1 -0
- package/dist/components/agents/loading-states/reasoning-text.d.ts +20 -0
- package/dist/components/agents/loading-states/reasoning-text.d.ts.map +1 -0
- package/dist/components/agents/loading-states/reasoning-text.js +184 -0
- package/dist/components/agents/loading-states/reasoning-text.js.map +1 -0
- package/dist/components/agents/loading-states/thinking-shimmer.d.ts +13 -0
- package/dist/components/agents/loading-states/thinking-shimmer.d.ts.map +1 -0
- package/dist/components/agents/loading-states/thinking-shimmer.js +17 -0
- package/dist/components/agents/loading-states/thinking-shimmer.js.map +1 -0
- package/dist/components/agents/message-bubble.d.ts +38 -0
- package/dist/components/agents/message-bubble.d.ts.map +1 -0
- package/dist/components/agents/message-bubble.js +182 -0
- package/dist/components/agents/message-bubble.js.map +1 -0
- package/dist/components/agents/message-context.d.ts +6 -0
- package/dist/components/agents/message-context.d.ts.map +1 -0
- package/dist/components/agents/message-context.js +8 -0
- package/dist/components/agents/message-context.js.map +1 -0
- package/dist/components/agents/message-scroller.d.ts +30 -0
- package/dist/components/agents/message-scroller.d.ts.map +1 -0
- package/dist/components/agents/message-scroller.js +314 -0
- package/dist/components/agents/message-scroller.js.map +1 -0
- package/dist/components/agents/message.d.ts +37 -0
- package/dist/components/agents/message.d.ts.map +1 -0
- package/dist/components/agents/message.js +139 -0
- package/dist/components/agents/message.js.map +1 -0
- package/dist/components/agents/prompt-input.d.ts +37 -0
- package/dist/components/agents/prompt-input.d.ts.map +1 -0
- package/dist/components/agents/prompt-input.js +216 -0
- package/dist/components/agents/prompt-input.js.map +1 -0
- package/dist/components/agents/streaming-response.d.ts +35 -0
- package/dist/components/agents/streaming-response.d.ts.map +1 -0
- package/dist/components/agents/streaming-response.js +151 -0
- package/dist/components/agents/streaming-response.js.map +1 -0
- package/dist/components/agents/todo-list.d.ts +24 -0
- package/dist/components/agents/todo-list.d.ts.map +1 -0
- package/dist/components/agents/todo-list.js +334 -0
- package/dist/components/agents/todo-list.js.map +1 -0
- package/dist/components/agents/tool-approval.d.ts +33 -0
- package/dist/components/agents/tool-approval.d.ts.map +1 -0
- package/dist/components/agents/tool-approval.js +166 -0
- package/dist/components/agents/tool-approval.js.map +1 -0
- package/dist/components/agents/tool-result.d.ts +34 -0
- package/dist/components/agents/tool-result.d.ts.map +1 -0
- package/dist/components/agents/tool-result.js +220 -0
- package/dist/components/agents/tool-result.js.map +1 -0
- package/dist/components/custom/confirm-dialog.d.ts +16 -0
- package/dist/components/custom/confirm-dialog.d.ts.map +1 -0
- package/dist/components/custom/confirm-dialog.js +93 -0
- package/dist/components/custom/confirm-dialog.js.map +1 -0
- package/dist/components/custom/toast.d.ts +20 -0
- package/dist/components/custom/toast.d.ts.map +1 -0
- package/dist/components/custom/toast.js +73 -0
- package/dist/components/custom/toast.js.map +1 -0
- package/dist/components/motion/action-swap.js +1 -1
- package/dist/components/motion/animated-badge.js +1 -1
- package/dist/components/motion/animated-number.js +1 -1
- package/dist/components/motion/animated-sidebar.d.ts.map +1 -1
- package/dist/components/motion/animated-sidebar.js +3 -3
- package/dist/components/motion/animated-sidebar.js.map +1 -1
- package/dist/components/motion/animated-toast-stack.js +1 -1
- package/dist/components/motion/attachment-upload.d.ts +47 -0
- package/dist/components/motion/attachment-upload.d.ts.map +1 -0
- package/dist/components/motion/attachment-upload.js +737 -0
- package/dist/components/motion/attachment-upload.js.map +1 -0
- package/dist/components/motion/availability-scheduler/copy-menu.d.ts +10 -0
- package/dist/components/motion/availability-scheduler/copy-menu.d.ts.map +1 -0
- package/dist/components/motion/availability-scheduler/copy-menu.js +3 -0
- package/dist/components/motion/availability-scheduler/day-row.d.ts +15 -0
- package/dist/components/motion/availability-scheduler/day-row.d.ts.map +1 -0
- package/dist/components/motion/availability-scheduler/day-row.js +181 -0
- package/dist/components/motion/availability-scheduler/day-row.js.map +1 -0
- package/dist/components/motion/availability-scheduler/icon-button.d.ts +15 -0
- package/dist/components/motion/availability-scheduler/icon-button.d.ts.map +1 -0
- package/dist/components/motion/availability-scheduler/icon-button.js +24 -0
- package/dist/components/motion/availability-scheduler/icon-button.js.map +1 -0
- package/dist/components/motion/availability-scheduler/index.d.ts +14 -0
- package/dist/components/motion/availability-scheduler/index.d.ts.map +1 -0
- package/dist/components/motion/availability-scheduler/index.js +59 -0
- package/dist/components/motion/availability-scheduler/index.js.map +1 -0
- package/dist/components/motion/availability-scheduler/time-select.d.ts +10 -0
- package/dist/components/motion/availability-scheduler/time-select.d.ts.map +1 -0
- package/dist/components/motion/availability-scheduler/time-select.js +26 -0
- package/dist/components/motion/availability-scheduler/time-select.js.map +1 -0
- package/dist/components/motion/bloom-menu.d.ts +17 -0
- package/dist/components/motion/bloom-menu.d.ts.map +1 -0
- package/dist/components/motion/bloom-menu.js +170 -0
- package/dist/components/motion/bloom-menu.js.map +1 -0
- package/dist/components/motion/bottom-sheet.js +1 -1
- package/dist/components/motion/bounce-sidebar.js +1 -1
- package/dist/components/motion/bouncy-accordion.js +1 -1
- package/dist/components/motion/button/base.js +1 -1
- package/dist/components/motion/button/index.d.ts +4 -0
- package/dist/components/motion/button/index.js +5 -0
- package/dist/components/motion/button/magnetic.js +1 -1
- package/dist/components/motion/button/stateful.js +1 -1
- package/dist/components/motion/center-morph-modal.js +3 -3
- package/dist/components/motion/center-morph-modal.js.map +1 -1
- package/dist/components/motion/checkbox.js +1 -1
- package/dist/components/motion/chromatic-text-reveal.js +2 -2
- package/dist/components/motion/chromatic-text-reveal.js.map +1 -1
- package/dist/components/motion/command-palette.d.ts +26 -0
- package/dist/components/motion/command-palette.d.ts.map +1 -0
- package/dist/components/motion/command-palette.js +250 -0
- package/dist/components/motion/command-palette.js.map +1 -0
- package/dist/components/motion/context-menu.js +1 -1
- package/dist/components/motion/cylinder-carousel.js +1 -1
- package/dist/components/motion/dock.js +1 -1
- package/dist/components/motion/drawer.js +1 -1
- package/dist/components/motion/dynamic-island.d.ts +22 -0
- package/dist/components/motion/dynamic-island.d.ts.map +1 -0
- package/dist/components/motion/dynamic-island.js +143 -0
- package/dist/components/motion/dynamic-island.js.map +1 -0
- package/dist/components/motion/expandable-action-bar.d.ts +52 -0
- package/dist/components/motion/expandable-action-bar.d.ts.map +1 -0
- package/dist/components/motion/expandable-action-bar.js +191 -0
- package/dist/components/motion/expandable-action-bar.js.map +1 -0
- package/dist/components/motion/expandable-tabs.d.ts +33 -0
- package/dist/components/motion/expandable-tabs.d.ts.map +1 -0
- package/dist/components/motion/expandable-tabs.js +291 -0
- package/dist/components/motion/expandable-tabs.js.map +1 -0
- package/dist/components/motion/feedback-widget.d.ts +18 -0
- package/dist/components/motion/feedback-widget.d.ts.map +1 -0
- package/dist/components/motion/feedback-widget.js +413 -0
- package/dist/components/motion/feedback-widget.js.map +1 -0
- package/dist/components/motion/file-upload.d.ts +48 -0
- package/dist/components/motion/file-upload.d.ts.map +1 -0
- package/dist/components/motion/file-upload.js +382 -0
- package/dist/components/motion/file-upload.js.map +1 -0
- package/dist/components/motion/hold-action-button.js +1 -1
- package/dist/components/motion/infinite-masonry.d.ts +31 -0
- package/dist/components/motion/infinite-masonry.d.ts.map +1 -0
- package/dist/components/motion/infinite-masonry.js +223 -0
- package/dist/components/motion/infinite-masonry.js.map +1 -0
- package/dist/components/motion/input.js +1 -1
- package/dist/components/motion/loader.js +1 -1
- package/dist/components/motion/magnetic.js +1 -1
- package/dist/components/motion/morphing-modal.js +1 -1
- package/dist/components/motion/not-found/glitch.d.ts +6 -0
- package/dist/components/motion/not-found/glitch.d.ts.map +1 -0
- package/dist/components/motion/not-found/glitch.js +90 -0
- package/dist/components/motion/not-found/glitch.js.map +1 -0
- package/dist/components/motion/not-found/magnetic.d.ts +6 -0
- package/dist/components/motion/not-found/magnetic.d.ts.map +1 -0
- package/dist/components/motion/not-found/magnetic.js +47 -0
- package/dist/components/motion/not-found/magnetic.js.map +1 -0
- package/dist/components/motion/not-found/shared.d.ts +32 -0
- package/dist/components/motion/not-found/shared.d.ts.map +1 -0
- package/dist/components/motion/not-found/shared.js +52 -0
- package/dist/components/motion/not-found/shared.js.map +1 -0
- package/dist/components/motion/not-found/spotlight.d.ts +6 -0
- package/dist/components/motion/not-found/spotlight.d.ts.map +1 -0
- package/dist/components/motion/not-found/spotlight.js +70 -0
- package/dist/components/motion/not-found/spotlight.js.map +1 -0
- package/dist/components/motion/not-found/stacked.d.ts +6 -0
- package/dist/components/motion/not-found/stacked.d.ts.map +1 -0
- package/dist/components/motion/not-found/stacked.js +95 -0
- package/dist/components/motion/not-found/stacked.js.map +1 -0
- package/dist/components/motion/not-found/terminal.d.ts +6 -0
- package/dist/components/motion/not-found/terminal.d.ts.map +1 -0
- package/dist/components/motion/not-found/terminal.js +90 -0
- package/dist/components/motion/not-found/terminal.js.map +1 -0
- package/dist/components/motion/notification-stack.d.ts +35 -0
- package/dist/components/motion/notification-stack.d.ts.map +1 -0
- package/dist/components/motion/notification-stack.js +187 -0
- package/dist/components/motion/notification-stack.js.map +1 -0
- package/dist/components/motion/number-ticker.js +1 -1
- package/dist/components/motion/otp-input.d.ts +32 -0
- package/dist/components/motion/otp-input.d.ts.map +1 -0
- package/dist/components/motion/otp-input.js +272 -0
- package/dist/components/motion/otp-input.js.map +1 -0
- package/dist/components/motion/overflow-actions.d.ts +39 -0
- package/dist/components/motion/overflow-actions.d.ts.map +1 -0
- package/dist/components/motion/overflow-actions.js +220 -0
- package/dist/components/motion/overflow-actions.js.map +1 -0
- package/dist/components/motion/parallax.js +1 -1
- package/dist/components/motion/popover-morph.js +2 -2
- package/dist/components/motion/popover-morph.js.map +1 -1
- package/dist/components/motion/popover.js +1 -1
- package/dist/components/motion/preview-rail.d.ts +10 -2
- package/dist/components/motion/preview-rail.d.ts.map +1 -1
- package/dist/components/motion/preview-rail.js +58 -27
- package/dist/components/motion/preview-rail.js.map +1 -1
- package/dist/components/motion/pull-to-refresh.js +2 -2
- package/dist/components/motion/pull-to-refresh.js.map +1 -1
- package/dist/components/motion/radio.js +1 -1
- package/dist/components/motion/range-slider-bubble.js +1 -1
- package/dist/components/motion/range-slider-fluid.js +1 -1
- package/dist/components/motion/range-slider-ruler.js +2 -2
- package/dist/components/motion/range-slider-ruler.js.map +1 -1
- package/dist/components/motion/range-slider-wave.js +1 -1
- package/dist/components/motion/range-slider.js +1 -1
- package/dist/components/motion/scroll-progress.js +1 -1
- package/dist/components/motion/scroll-reveal.js +1 -1
- package/dist/components/motion/select-morph.js +1 -1
- package/dist/components/motion/select.js +1 -1
- package/dist/components/motion/shader-background.js +1 -1
- package/dist/components/motion/shared-layout-bg.js +2 -2
- package/dist/components/motion/shared-layout-bg.js.map +1 -1
- package/dist/components/motion/slide-action-button.js +1 -1
- package/dist/components/motion/smooth-scroll.js +1 -1
- package/dist/components/motion/swipeable-list.d.ts +60 -0
- package/dist/components/motion/swipeable-list.d.ts.map +1 -0
- package/dist/components/motion/swipeable-list.js +254 -0
- package/dist/components/motion/swipeable-list.js.map +1 -0
- package/dist/components/motion/switch.js +1 -1
- package/dist/components/motion/table/index.js +1 -1
- package/dist/components/motion/table/table-header.js +1 -1
- package/dist/components/motion/table/table-menu.js +1 -1
- package/dist/components/motion/tabs.js +1 -1
- package/dist/components/motion/text-reveal.js +1 -1
- package/dist/components/motion/text-shimmer.d.ts.map +1 -1
- package/dist/components/motion/text-shimmer.js +4 -3
- package/dist/components/motion/text-shimmer.js.map +1 -1
- package/dist/components/motion/theme-toggle.js +1 -1
- package/dist/components/motion/tilt-card.js +1 -1
- package/dist/components/motion/tooltip.js +1 -1
- package/dist/components/motion/wheel-picker.js +1 -1
- package/dist/components/reui/alert.d.ts +1 -1
- package/dist/components/reui/badge.d.ts +1 -1
- package/dist/components/reui/data-grid/data-grid-column-filter.d.ts +4 -3
- package/dist/components/reui/data-grid/data-grid-column-filter.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-filter.js +1 -2
- package/dist/components/reui/data-grid/data-grid-column-filter.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.d.ts +15 -4
- package/dist/components/reui/data-grid/data-grid-column-header.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.js +35 -7
- package/dist/components/reui/data-grid/data-grid-column-header.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-visibility.d.ts +3 -2
- package/dist/components/reui/data-grid/data-grid-column-visibility.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-visibility.js +0 -1
- package/dist/components/reui/data-grid/data-grid-column-visibility.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-pagination.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-pagination.js +2 -3
- package/dist/components/reui/data-grid/data-grid-pagination.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.js +12 -7
- package/dist/components/reui/data-grid/data-grid-scroll-area.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.d.ts +71 -4
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js +146 -39
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.d.ts +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.js +4 -5
- package/dist/components/reui/data-grid/data-grid-table-dnd.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.d.ts +6 -5
- package/dist/components/reui/data-grid/data-grid-table-virtual.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.js +9 -10
- package/dist/components/reui/data-grid/data-grid-table-virtual.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.d.ts +60 -33
- package/dist/components/reui/data-grid/data-grid-table.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.js +153 -69
- package/dist/components/reui/data-grid/data-grid-table.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid.d.ts +105 -20
- package/dist/components/reui/data-grid/data-grid.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid.js +83 -10
- package/dist/components/reui/data-grid/data-grid.js.map +1 -1
- package/dist/components/reui/date-selector.js +47 -44
- package/dist/components/reui/date-selector.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-dnd.d.ts.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-dnd.js +20 -2
- package/dist/components/reui/event-calendar/event-calendar-dnd.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-recurrence.js +7 -5
- package/dist/components/reui/event-calendar/event-calendar-recurrence.js.map +1 -1
- package/dist/components/reui/filters.js +26 -21
- package/dist/components/reui/filters.js.map +1 -1
- package/dist/components/reui/frame.d.ts +1 -1
- package/dist/components/reui/gantt/gantt-view.js +1 -1
- package/dist/components/reui/icon-tile.d.ts +1 -1
- package/dist/components/reui/icon-tile.d.ts.map +1 -1
- package/dist/components/reui/icon-tile.js +8 -1
- package/dist/components/reui/icon-tile.js.map +1 -1
- package/dist/components/reui/phone-input.js +1 -1
- package/dist/components/reui/sortable.js +13 -11
- package/dist/components/reui/sortable.js.map +1 -1
- package/dist/components/ui/attachment.d.ts +1 -1
- package/dist/components/ui/button-group.d.ts +1 -1
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/button.js +1 -1
- package/dist/components/ui/field.d.ts +1 -1
- package/dist/components/ui/item.d.ts +1 -1
- package/dist/components/ui/questionnaire.d.ts +21 -0
- package/dist/components/ui/questionnaire.d.ts.map +1 -0
- package/dist/components/ui/questionnaire.js +164 -0
- package/dist/components/ui/questionnaire.js.map +1 -0
- package/dist/copy-menu-Bk5GP9Gp.js +201 -0
- package/dist/copy-menu-Bk5GP9Gp.js.map +1 -0
- package/dist/hooks/use-body-classes.d.ts +0 -3
- package/dist/hooks/use-body-classes.d.ts.map +1 -1
- package/dist/hooks/use-body-classes.js +0 -3
- package/dist/hooks/use-body-classes.js.map +1 -1
- package/dist/hooks/use-copy-to-clipboard.d.ts +0 -3
- package/dist/hooks/use-copy-to-clipboard.d.ts.map +1 -1
- package/dist/hooks/use-copy-to-clipboard.js +0 -3
- package/dist/hooks/use-copy-to-clipboard.js.map +1 -1
- package/dist/hooks/use-file-upload.js +6 -4
- package/dist/hooks/use-file-upload.js.map +1 -1
- package/dist/hooks/use-hydrated.d.ts +0 -10
- package/dist/hooks/use-hydrated.d.ts.map +1 -1
- package/dist/hooks/use-hydrated.js +0 -10
- package/dist/hooks/use-hydrated.js.map +1 -1
- package/dist/hooks/use-intersection-observer.d.ts.map +1 -1
- package/dist/hooks/use-intersection-observer.js +0 -5
- package/dist/hooks/use-intersection-observer.js.map +1 -1
- package/dist/hooks/use-is-mac.d.ts +0 -5
- package/dist/hooks/use-is-mac.d.ts.map +1 -1
- package/dist/hooks/use-is-mac.js +0 -5
- package/dist/hooks/use-is-mac.js.map +1 -1
- package/dist/hooks/use-media-query.d.ts +0 -5
- package/dist/hooks/use-media-query.d.ts.map +1 -1
- package/dist/hooks/use-media-query.js +0 -5
- package/dist/hooks/use-media-query.js.map +1 -1
- package/dist/hooks/use-meta-color.d.ts.map +1 -1
- package/dist/hooks/use-meta-color.js +0 -3
- package/dist/hooks/use-meta-color.js.map +1 -1
- package/dist/hooks/use-mutation-observer.d.ts.map +1 -1
- package/dist/hooks/use-mutation-observer.js +0 -5
- package/dist/hooks/use-mutation-observer.js.map +1 -1
- package/dist/hooks/use-scroll-position.d.ts.map +1 -1
- package/dist/hooks/use-scroll-position.js +0 -5
- package/dist/hooks/use-scroll-position.js.map +1 -1
- package/dist/hooks/use-slider-input.d.ts.map +1 -1
- package/dist/hooks/use-slider-input.js +0 -5
- package/dist/hooks/use-slider-input.js.map +1 -1
- package/dist/hooks/use-viewport.d.ts +0 -5
- package/dist/hooks/use-viewport.d.ts.map +1 -1
- package/dist/hooks/use-viewport.js +0 -5
- package/dist/hooks/use-viewport.js.map +1 -1
- package/dist/lib/favicon.d.ts +5 -0
- package/dist/lib/favicon.d.ts.map +1 -0
- package/dist/lib/favicon.js +12 -0
- package/dist/lib/favicon.js.map +1 -0
- package/dist/lib/text-shimmer.d.ts +8 -0
- package/dist/lib/text-shimmer.d.ts.map +1 -0
- package/dist/lib/text-shimmer.js +10 -0
- package/dist/lib/text-shimmer.js.map +1 -0
- package/dist/types-j36vVGtZ.d.ts +78 -0
- package/dist/types-j36vVGtZ.d.ts.map +1 -0
- package/dist/types-smkWN_7x.d.ts +20 -0
- package/dist/types-smkWN_7x.d.ts.map +1 -0
- package/package.json +18 -13
- package/dist/components/ui/sonner.d.ts +0 -7
- package/dist/components/ui/sonner.d.ts.map +0 -1
- package/dist/components/ui/sonner.js +0 -32
- package/dist/components/ui/sonner.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-body-classes.d.ts","names":[],"sources":["../../src/hooks/use-body-classes.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-body-classes.d.ts","names":[],"sources":["../../src/hooks/use-body-classes.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;cAuBa,iBAAkB"}
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
import { useEffect } from "react";
|
|
3
3
|
//#region src/hooks/use-body-classes.ts
|
|
4
4
|
/**
|
|
5
|
-
* Body class management hook for React components.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
5
|
* Adds classes to `document.body` while the component is mounted.
|
|
9
6
|
* Shared classes are reference-counted, so one component unmounting does not
|
|
10
7
|
* remove a class that another mounted component still owns.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-body-classes.js","names":[],"sources":["../../src/hooks/use-body-classes.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"use-body-classes.js","names":[],"sources":["../../src/hooks/use-body-classes.ts"],"sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\n\n/**\n * Adds classes to `document.body` while the component is mounted.\n * Shared classes are reference-counted, so one component unmounting does not\n * remove a class that another mounted component still owns.\n *\n * @param className - Space-separated string of CSS class names to apply to body\n *\n * @example\n * ```tsx\n * // Single class\n * useBodyClasses('dark-theme');\n *\n * // Multiple classes\n * useBodyClasses('modal-open overflow-hidden');\n *\n * // Conditional classes\n * useBodyClasses(isModalOpen ? 'modal-open' : '');\n * ```\n */\nexport const useBodyClasses = (className: string) => {\n useEffect(() => {\n if (!className.trim()) return;\n\n const classList = className.split(/\\s+/).filter(Boolean);\n\n classList.forEach((cls) => {\n const count = bodyClassCounts.get(cls) ?? 0;\n bodyClassCounts.set(cls, count + 1);\n if (count === 0) {\n document.body.classList.add(cls);\n }\n });\n\n return () => {\n classList.forEach((cls) => {\n const nextCount = (bodyClassCounts.get(cls) ?? 1) - 1;\n if (nextCount <= 0) {\n bodyClassCounts.delete(cls);\n document.body.classList.remove(cls);\n return;\n }\n bodyClassCounts.set(cls, nextCount);\n });\n };\n }, [className]);\n};\n\nconst bodyClassCounts = new Map<string, number>();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,kBAAkB,cAAsB;CACnD,gBAAgB;EACd,IAAI,CAAC,UAAU,KAAK,GAAG;EAEvB,MAAM,YAAY,UAAU,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO;EAEvD,UAAU,SAAS,QAAQ;GACzB,MAAM,QAAQ,gBAAgB,IAAI,GAAG,KAAK;GAC1C,gBAAgB,IAAI,KAAK,QAAQ,CAAC;GAClC,IAAI,UAAU,GACZ,SAAS,KAAK,UAAU,IAAI,GAAG;EAEnC,CAAC;EAED,aAAa;GACX,UAAU,SAAS,QAAQ;IACzB,MAAM,aAAa,gBAAgB,IAAI,GAAG,KAAK,KAAK;IACpD,IAAI,aAAa,GAAG;KAClB,gBAAgB,OAAO,GAAG;KAC1B,SAAS,KAAK,UAAU,OAAO,GAAG;KAClC;IACF;IACA,gBAAgB,IAAI,KAAK,SAAS;GACpC,CAAC;EACH;CACF,GAAG,CAAC,SAAS,CAAC;AAChB;AAEA,MAAM,kCAAkB,IAAI,IAAoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-copy-to-clipboard.d.ts","names":[],"sources":["../../src/hooks/use-copy-to-clipboard.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-copy-to-clipboard.d.ts","names":[],"sources":["../../src/hooks/use-copy-to-clipboard.ts"],"mappings":";;;;UASU;;EAER;;EAEA;;;;;;;;;;;;;;;;;;;;;;;iBAwBc,qBAAqB,SAAgB,WAAU;;;;EAW7C,OAAA,kBAAM"}
|
|
@@ -3,9 +3,6 @@ import * as React$1 from "react";
|
|
|
3
3
|
import { isDevelopment } from "@kumix/utils";
|
|
4
4
|
//#region src/hooks/use-copy-to-clipboard.ts
|
|
5
5
|
/**
|
|
6
|
-
* Clipboard copy functionality hook for React components.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
6
|
* Copies text to the clipboard and exposes temporary copied state.
|
|
10
7
|
*
|
|
11
8
|
* @param options - Configuration options for the hook
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-copy-to-clipboard.js","names":["React"],"sources":["../../src/hooks/use-copy-to-clipboard.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"use-copy-to-clipboard.js","names":["React"],"sources":["../../src/hooks/use-copy-to-clipboard.ts"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { isDevelopment } from \"@kumix/utils\";\n\n/**\n * Configuration options for the copy to clipboard hook\n */\ninterface UseCopyToClipboardOptions {\n /** Duration in milliseconds to show the copied state (default: 2000ms) */\n timeout?: number;\n /** Callback function executed after successful copy operation */\n onCopy?: () => void;\n}\n\n/**\n * Copies text to the clipboard and exposes temporary copied state.\n *\n * @param options - Configuration options for the hook\n * @returns Object containing copied state and an async copy function. The copy\n * function resolves to `true` when text is copied and `false` otherwise.\n *\n * @example\n * ```tsx\n * const { copied, copy } = useCopyToClipboard({\n * timeout: 3000,\n * onCopy: () => toast.success('Copied to clipboard!')\n * });\n *\n * return (\n * <button onClick={() => copy('Hello World')}>\n * {copied ? 'Copied!' : 'Copy Text'}\n * </button>\n * );\n * ```\n */\nexport function useCopyToClipboard({ timeout = 2000, onCopy }: UseCopyToClipboardOptions = {}) {\n const [copied, setCopied] = React.useState(false);\n const timerRef = React.useRef<ReturnType<typeof setTimeout>>(null);\n\n React.useEffect(() => {\n return () => {\n if (timerRef.current) clearTimeout(timerRef.current);\n };\n }, []);\n\n const copy = React.useCallback(\n async (value: string) => {\n if (typeof window === \"undefined\" || !navigator.clipboard?.writeText) {\n if (isDevelopment) {\n console.warn(\"Clipboard API not supported in this environment\");\n }\n return false;\n }\n\n if (!value) {\n if (isDevelopment) {\n console.warn(\"Cannot copy empty value to clipboard\");\n }\n return false;\n }\n\n try {\n await navigator.clipboard.writeText(value);\n setCopied(true);\n onCopy?.();\n\n if (timerRef.current) clearTimeout(timerRef.current);\n timerRef.current = setTimeout(() => {\n setCopied(false);\n }, timeout);\n return true;\n } catch (error) {\n if (isDevelopment) {\n console.error(\"Failed to copy text to clipboard:\", error);\n }\n return false;\n }\n },\n [timeout, onCopy],\n );\n\n return {\n /** Whether text was recently copied (true for timeout duration) */\n copied,\n /** Function to copy text to clipboard */\n copy,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,mBAAmB,EAAE,UAAU,KAAM,WAAsC,CAAC,GAAG;CAC7F,MAAM,CAAC,QAAQ,aAAaA,QAAM,SAAS,KAAK;CAChD,MAAM,WAAWA,QAAM,OAAsC,IAAI;CAEjE,QAAM,gBAAgB;EACpB,aAAa;GACX,IAAI,SAAS,SAAS,aAAa,SAAS,OAAO;EACrD;CACF,GAAG,CAAC,CAAC;CAsCL,OAAO;;EAEL;;EAEA,MAxCWA,QAAM,YACjB,OAAO,UAAkB;GACvB,IAAI,OAAO,WAAW,eAAe,CAAC,UAAU,WAAW,WAAW;IACpE,IAAI,eACF,QAAQ,KAAK,iDAAiD;IAEhE,OAAO;GACT;GAEA,IAAI,CAAC,OAAO;IACV,IAAI,eACF,QAAQ,KAAK,sCAAsC;IAErD,OAAO;GACT;GAEA,IAAI;IACF,MAAM,UAAU,UAAU,UAAU,KAAK;IACzC,UAAU,IAAI;IACd,SAAS;IAET,IAAI,SAAS,SAAS,aAAa,SAAS,OAAO;IACnD,SAAS,UAAU,iBAAiB;KAClC,UAAU,KAAK;IACjB,GAAG,OAAO;IACV,OAAO;GACT,SAAS,OAAO;IACd,IAAI,eACF,QAAQ,MAAM,qCAAqC,KAAK;IAE1D,OAAO;GACT;EACF,GACA,CAAC,SAAS,MAAM,CAOb;CACL;AACF"}
|
|
@@ -166,10 +166,12 @@ const useFileUpload = (options = {}) => {
|
|
|
166
166
|
isDragging: false
|
|
167
167
|
}));
|
|
168
168
|
if (inputRef.current?.disabled) return;
|
|
169
|
-
if (e.dataTransfer.files && e.dataTransfer.files.length > 0)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
|
170
|
+
if (!multiple) {
|
|
171
|
+
const file = e.dataTransfer.files[0];
|
|
172
|
+
addFiles([file]);
|
|
173
|
+
} else addFiles(e.dataTransfer.files);
|
|
174
|
+
}
|
|
173
175
|
}, [addFiles, multiple]);
|
|
174
176
|
const handleFileChange = useCallback((e) => {
|
|
175
177
|
if (e.target.files && e.target.files.length > 0) addFiles(e.target.files);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-file-upload.js","names":[],"sources":["../../src/hooks/use-file-upload.ts"],"sourcesContent":["\"use client\";\n\nimport type React from \"react\";\nimport {\n type ChangeEvent,\n type DragEvent,\n type InputHTMLAttributes,\n useCallback,\n useRef,\n useState,\n} from \"react\";\n\nexport type FileMetadata = {\n name: string;\n size: number;\n type: string;\n url: string;\n id: string;\n};\n\nexport type FileWithPreview = {\n file: File | FileMetadata;\n id: string;\n preview?: string;\n};\n\nexport type FileUploadOptions = {\n maxFiles?: number; // Only used when multiple is true, defaults to Infinity\n maxSize?: number; // in bytes\n accept?: string;\n multiple?: boolean; // Defaults to false\n initialFiles?: FileMetadata[];\n onFilesChange?: (files: FileWithPreview[]) => void; // Callback when files change\n onFilesAdded?: (addedFiles: FileWithPreview[]) => void; // Callback when new files are added\n onError?: (errors: string[]) => void;\n};\n\nexport type FileUploadState = {\n files: FileWithPreview[];\n isDragging: boolean;\n errors: string[];\n};\n\nexport type FileUploadActions = {\n addFiles: (files: FileList | File[]) => void;\n removeFile: (id: string) => void;\n clearFiles: () => void;\n clearErrors: () => void;\n handleDragEnter: (e: DragEvent<HTMLElement>) => void;\n handleDragLeave: (e: DragEvent<HTMLElement>) => void;\n handleDragOver: (e: DragEvent<HTMLElement>) => void;\n handleDrop: (e: DragEvent<HTMLElement>) => void;\n handleFileChange: (e: ChangeEvent<HTMLInputElement>) => void;\n openFileDialog: () => void;\n getInputProps: (\n props?: InputHTMLAttributes<HTMLInputElement>,\n ) => InputHTMLAttributes<HTMLInputElement> & {\n ref: React.Ref<HTMLInputElement>;\n };\n};\n\nexport const useFileUpload = (\n options: FileUploadOptions = {},\n): [FileUploadState, FileUploadActions] => {\n const {\n maxFiles = Number.POSITIVE_INFINITY,\n maxSize = Number.POSITIVE_INFINITY,\n accept = \"*\",\n multiple = false,\n initialFiles = [],\n onFilesChange,\n onFilesAdded,\n onError,\n } = options;\n\n const [state, setState] = useState<FileUploadState>({\n files: initialFiles.map((file) => ({\n file,\n id: file.id,\n preview: file.url,\n })),\n isDragging: false,\n errors: [],\n });\n\n const inputRef = useRef<HTMLInputElement>(null);\n\n const validateFile = useCallback(\n (file: File | FileMetadata): string | null => {\n if (file.size > maxSize) {\n return `File \"${file.name}\" exceeds the maximum size of ${formatBytes(maxSize)}.`;\n }\n\n if (accept !== \"*\") {\n const acceptedTypes = accept.split(\",\").map((type) => type.trim());\n const fileType = file.type || \"\";\n const fileExtension = `.${file.name.split(\".\").pop()}`;\n\n const isAccepted = acceptedTypes.some((type) => {\n if (type.startsWith(\".\")) {\n return fileExtension.toLowerCase() === type.toLowerCase();\n }\n if (type.endsWith(\"/*\")) {\n const baseType = type.split(\"/\")[0];\n return fileType.startsWith(`${baseType}/`);\n }\n return fileType === type;\n });\n\n if (!isAccepted) {\n return `File \"${file.name}\" is not an accepted file type.`;\n }\n }\n\n return null;\n },\n [accept, maxSize],\n );\n\n const createPreview = useCallback((file: File | FileMetadata): string | undefined => {\n if (file instanceof File) {\n return URL.createObjectURL(file);\n }\n return file.url;\n }, []);\n\n const generateUniqueId = useCallback((file: File | FileMetadata): string => {\n if (file instanceof File) {\n return `${file.name}-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;\n }\n return file.id;\n }, []);\n\n const clearFiles = useCallback(() => {\n setState((prev) => {\n // Clean up object URLs\n for (const file of prev.files) {\n if (file.preview && file.file instanceof File && file.file.type.startsWith(\"image/\")) {\n URL.revokeObjectURL(file.preview);\n }\n }\n\n if (inputRef.current) {\n inputRef.current.value = \"\";\n }\n\n const newState = {\n ...prev,\n files: [],\n errors: [],\n };\n\n onFilesChange?.(newState.files);\n return newState;\n });\n }, [onFilesChange]);\n\n const addFiles = useCallback(\n (newFiles: FileList | File[]) => {\n if (!newFiles || newFiles.length === 0) return;\n\n const newFilesArray = Array.from(newFiles);\n const errors: string[] = [];\n\n // Clear existing errors when new files are uploaded\n setState((prev) => ({ ...prev, errors: [] }));\n\n // In single file mode, clear existing files first\n if (!multiple) {\n clearFiles();\n }\n\n // Check if adding these files would exceed maxFiles (only in multiple mode)\n if (\n multiple &&\n maxFiles !== Number.POSITIVE_INFINITY &&\n state.files.length + newFilesArray.length > maxFiles\n ) {\n errors.push(`You can only upload a maximum of ${maxFiles} files.`);\n onError?.(errors);\n setState((prev) => ({ ...prev, errors }));\n return;\n }\n\n const validFiles: FileWithPreview[] = [];\n\n for (const file of newFilesArray) {\n // Only check for duplicates if multiple files are allowed\n if (multiple) {\n const isDuplicate = state.files.some(\n (existingFile) =>\n existingFile.file.name === file.name && existingFile.file.size === file.size,\n );\n\n // Skip duplicate files silently\n if (isDuplicate) {\n continue;\n }\n }\n\n // Check file size\n if (file.size > maxSize) {\n errors.push(\n multiple\n ? `Some files exceed the maximum size of ${formatBytes(maxSize)}.`\n : `File exceeds the maximum size of ${formatBytes(maxSize)}.`,\n );\n continue;\n }\n\n const error = validateFile(file);\n if (error) {\n errors.push(error);\n } else {\n validFiles.push({\n file,\n id: generateUniqueId(file),\n preview: createPreview(file),\n });\n }\n }\n\n // Only update state if we have valid files to add\n if (validFiles.length > 0) {\n // Call the onFilesAdded callback with the newly added valid files\n onFilesAdded?.(validFiles);\n\n setState((prev) => {\n const newFiles = !multiple ? validFiles : [...prev.files, ...validFiles];\n onFilesChange?.(newFiles);\n return {\n ...prev,\n files: newFiles,\n errors,\n };\n });\n } else if (errors.length > 0) {\n onError?.(errors);\n setState((prev) => ({\n ...prev,\n errors,\n }));\n }\n\n // Reset input value after handling files\n if (inputRef.current) {\n inputRef.current.value = \"\";\n }\n },\n [\n state.files,\n maxFiles,\n multiple,\n maxSize,\n validateFile,\n createPreview,\n generateUniqueId,\n clearFiles,\n onFilesChange,\n onFilesAdded,\n onError,\n ],\n );\n\n const removeFile = useCallback(\n (id: string) => {\n setState((prev) => {\n const fileToRemove = prev.files.find((file) => file.id === id);\n if (\n fileToRemove?.preview &&\n fileToRemove.file instanceof File &&\n fileToRemove.file.type.startsWith(\"image/\")\n ) {\n URL.revokeObjectURL(fileToRemove.preview);\n }\n\n const newFiles = prev.files.filter((file) => file.id !== id);\n onFilesChange?.(newFiles);\n\n return {\n ...prev,\n files: newFiles,\n errors: [],\n };\n });\n },\n [onFilesChange],\n );\n\n const clearErrors = useCallback(() => {\n setState((prev) => ({\n ...prev,\n errors: [],\n }));\n }, []);\n\n const handleDragEnter = useCallback((e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n setState((prev) => ({ ...prev, isDragging: true }));\n }, []);\n\n const handleDragLeave = useCallback((e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n\n if (e.currentTarget.contains(e.relatedTarget as Node)) {\n return;\n }\n\n setState((prev) => ({ ...prev, isDragging: false }));\n }, []);\n\n const handleDragOver = useCallback((e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n }, []);\n\n const handleDrop = useCallback(\n (e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n setState((prev) => ({ ...prev, isDragging: false }));\n\n // Don't process files if the input is disabled\n if (inputRef.current?.disabled) {\n return;\n }\n\n if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {\n // In single file mode, only use the first file\n if (!multiple) {\n const file = e.dataTransfer.files[0];\n addFiles([file]);\n } else {\n addFiles(e.dataTransfer.files);\n }\n }\n },\n [addFiles, multiple],\n );\n\n const handleFileChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n if (e.target.files && e.target.files.length > 0) {\n addFiles(e.target.files);\n }\n },\n [addFiles],\n );\n\n const openFileDialog = useCallback(() => {\n if (inputRef.current) {\n inputRef.current.click();\n }\n }, []);\n\n const getInputProps = useCallback(\n (props: InputHTMLAttributes<HTMLInputElement> = {}) => {\n return {\n ...props,\n type: \"file\" as const,\n onChange: handleFileChange,\n accept: props.accept || accept,\n multiple: props.multiple !== undefined ? props.multiple : multiple,\n ref: inputRef,\n };\n },\n [accept, multiple, handleFileChange],\n );\n\n return [\n state,\n {\n addFiles,\n removeFile,\n clearFiles,\n clearErrors,\n handleDragEnter,\n handleDragLeave,\n handleDragOver,\n handleDrop,\n handleFileChange,\n openFileDialog,\n getInputProps,\n },\n ];\n};\n\n// Helper function to format bytes to human-readable format\nexport const formatBytes = (bytes: number, decimals = 2): string => {\n if (bytes === 0) return \"0 Bytes\";\n\n const k = 1024;\n const dm = decimals < 0 ? 0 : decimals;\n const sizes = [\"Bytes\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"];\n\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n\n return `${Number.parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;\n};\n"],"mappings":";;;AA6DA,MAAa,iBACX,UAA6B,CAAC,MACW;CACzC,MAAM,EACJ,WAAW,OAAO,mBAClB,UAAU,OAAO,mBACjB,SAAS,KACT,WAAW,OACX,eAAe,CAAC,GAChB,eACA,cACA,YACE;CAEJ,MAAM,CAAC,OAAO,YAAY,SAA0B;EAClD,OAAO,aAAa,KAAK,UAAU;GACjC;GACA,IAAI,KAAK;GACT,SAAS,KAAK;EAChB,EAAE;EACF,YAAY;EACZ,QAAQ,CAAC;CACX,CAAC;CAED,MAAM,WAAW,OAAyB,IAAI;CAE9C,MAAM,eAAe,aAClB,SAA6C;EAC5C,IAAI,KAAK,OAAO,SACd,OAAO,SAAS,KAAK,KAAK,gCAAgC,YAAY,OAAO,EAAE;EAGjF,IAAI,WAAW,KAAK;GAClB,MAAM,gBAAgB,OAAO,MAAM,GAAG,CAAC,CAAC,KAAK,SAAS,KAAK,KAAK,CAAC;GACjE,MAAM,WAAW,KAAK,QAAQ;GAC9B,MAAM,gBAAgB,IAAI,KAAK,KAAK,MAAM,GAAG,CAAC,CAAC,IAAI;GAanD,IAAI,CAXe,cAAc,MAAM,SAAS;IAC9C,IAAI,KAAK,WAA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EA,MAAM,mBAAmB,aACtB,MAAqC;EACpC,IAAI,EAAE,OAAO,SAAS,EAAE,OAAO,MAAM,SAAS,GAC5C,SAAS,EAAE,OAAO,KAAK;CAE3B,GACA,CAAC,QAAQ,CACX;CAsBA,OAAO,CACL,OACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,gBAhCmB,kBAAkB;GACvC,IAAI,SAAS,SACX,SAAS,QAAQ,MAAM;EAE3B,GAAG,CAAC,CA4Ba;EACb,eA3BkB,aACnB,QAA+C,CAAC,MAAM;GACrD,OAAO;IACL,GAAG;IACH,MAAM;IACN,UAAU;IACV,QAAQ,MAAM,UAAU;IACxB,UAAU,MAAM,aAAa,KAAA,IAAY,MAAM,WAAW;IAC1D,KAAK;GACP;EACF,GACA;GAAC;GAAQ;GAAU;EAAgB,CAgBrB;CACd,CACF;AACF;AAGA,MAAa,eAAe,OAAe,WAAW,MAAc;CAClE,IAAI,UAAU,GAAG,OAAO;CAExB,MAAM,IAAI;CACV,MAAM,KAAK,WAAW,IAAI,IAAI;CAC9B,MAAM,QAAQ;EAAC;EAAS;EAAM;EAAM;EAAM;EAAM;EAAM;EAAM;EAAM;CAAI;CAEtE,MAAM,IAAI,KAAK,MAAM,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,CAAC,CAAC;CAElD,OAAO,GAAG,OAAO,YAAY,QAAQ,KAAK,EAAA,CAAG,QAAQ,EAAE,CAAC,EAAE,GAAG,MAAM;AACrE"}
|
|
1
|
+
{"version":3,"file":"use-file-upload.js","names":[],"sources":["../../src/hooks/use-file-upload.ts"],"sourcesContent":["\"use client\";\n\nimport type React from \"react\";\nimport {\n type ChangeEvent,\n type DragEvent,\n type InputHTMLAttributes,\n useCallback,\n useRef,\n useState,\n} from \"react\";\n\nexport type FileMetadata = {\n name: string;\n size: number;\n type: string;\n url: string;\n id: string;\n};\n\nexport type FileWithPreview = {\n file: File | FileMetadata;\n id: string;\n preview?: string;\n};\n\nexport type FileUploadOptions = {\n maxFiles?: number; // Only used when multiple is true, defaults to Infinity\n maxSize?: number; // in bytes\n accept?: string;\n multiple?: boolean; // Defaults to false\n initialFiles?: FileMetadata[];\n onFilesChange?: (files: FileWithPreview[]) => void; // Callback when files change\n onFilesAdded?: (addedFiles: FileWithPreview[]) => void; // Callback when new files are added\n onError?: (errors: string[]) => void;\n};\n\nexport type FileUploadState = {\n files: FileWithPreview[];\n isDragging: boolean;\n errors: string[];\n};\n\nexport type FileUploadActions = {\n addFiles: (files: FileList | File[]) => void;\n removeFile: (id: string) => void;\n clearFiles: () => void;\n clearErrors: () => void;\n handleDragEnter: (e: DragEvent<HTMLElement>) => void;\n handleDragLeave: (e: DragEvent<HTMLElement>) => void;\n handleDragOver: (e: DragEvent<HTMLElement>) => void;\n handleDrop: (e: DragEvent<HTMLElement>) => void;\n handleFileChange: (e: ChangeEvent<HTMLInputElement>) => void;\n openFileDialog: () => void;\n getInputProps: (\n props?: InputHTMLAttributes<HTMLInputElement>,\n ) => InputHTMLAttributes<HTMLInputElement> & {\n ref: React.Ref<HTMLInputElement>;\n };\n};\n\nexport const useFileUpload = (\n options: FileUploadOptions = {},\n): [FileUploadState, FileUploadActions] => {\n const {\n maxFiles = Number.POSITIVE_INFINITY,\n maxSize = Number.POSITIVE_INFINITY,\n accept = \"*\",\n multiple = false,\n initialFiles = [],\n onFilesChange,\n onFilesAdded,\n onError,\n } = options;\n\n const [state, setState] = useState<FileUploadState>({\n files: initialFiles.map((file) => ({\n file,\n id: file.id,\n preview: file.url,\n })),\n isDragging: false,\n errors: [],\n });\n\n const inputRef = useRef<HTMLInputElement>(null);\n\n const validateFile = useCallback(\n (file: File | FileMetadata): string | null => {\n if (file.size > maxSize) {\n return `File \"${file.name}\" exceeds the maximum size of ${formatBytes(maxSize)}.`;\n }\n\n if (accept !== \"*\") {\n const acceptedTypes = accept.split(\",\").map((type) => type.trim());\n const fileType = file.type || \"\";\n const fileExtension = `.${file.name.split(\".\").pop()}`;\n\n const isAccepted = acceptedTypes.some((type) => {\n if (type.startsWith(\".\")) {\n return fileExtension.toLowerCase() === type.toLowerCase();\n }\n if (type.endsWith(\"/*\")) {\n const baseType = type.split(\"/\")[0];\n return fileType.startsWith(`${baseType}/`);\n }\n return fileType === type;\n });\n\n if (!isAccepted) {\n return `File \"${file.name}\" is not an accepted file type.`;\n }\n }\n\n return null;\n },\n [accept, maxSize],\n );\n\n const createPreview = useCallback((file: File | FileMetadata): string | undefined => {\n if (file instanceof File) {\n return URL.createObjectURL(file);\n }\n return file.url;\n }, []);\n\n const generateUniqueId = useCallback((file: File | FileMetadata): string => {\n if (file instanceof File) {\n return `${file.name}-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;\n }\n return file.id;\n }, []);\n\n const clearFiles = useCallback(() => {\n setState((prev) => {\n // Clean up object URLs\n for (const file of prev.files) {\n if (file.preview && file.file instanceof File && file.file.type.startsWith(\"image/\")) {\n URL.revokeObjectURL(file.preview);\n }\n }\n\n if (inputRef.current) {\n inputRef.current.value = \"\";\n }\n\n const newState = {\n ...prev,\n files: [],\n errors: [],\n };\n\n onFilesChange?.(newState.files);\n return newState;\n });\n }, [onFilesChange]);\n\n const addFiles = useCallback(\n (newFiles: FileList | File[]) => {\n if (!newFiles || newFiles.length === 0) return;\n\n const newFilesArray = Array.from(newFiles);\n const errors: string[] = [];\n\n // Clear existing errors when new files are uploaded\n setState((prev) => ({ ...prev, errors: [] }));\n\n // In single file mode, clear existing files first\n if (!multiple) {\n clearFiles();\n }\n\n // Check if adding these files would exceed maxFiles (only in multiple mode)\n if (\n multiple &&\n maxFiles !== Number.POSITIVE_INFINITY &&\n state.files.length + newFilesArray.length > maxFiles\n ) {\n errors.push(`You can only upload a maximum of ${maxFiles} files.`);\n onError?.(errors);\n setState((prev) => ({ ...prev, errors }));\n return;\n }\n\n const validFiles: FileWithPreview[] = [];\n\n for (const file of newFilesArray) {\n // Only check for duplicates if multiple files are allowed\n if (multiple) {\n const isDuplicate = state.files.some(\n (existingFile) =>\n existingFile.file.name === file.name && existingFile.file.size === file.size,\n );\n\n // Skip duplicate files silently\n if (isDuplicate) {\n continue;\n }\n }\n\n // Check file size\n if (file.size > maxSize) {\n errors.push(\n multiple\n ? `Some files exceed the maximum size of ${formatBytes(maxSize)}.`\n : `File exceeds the maximum size of ${formatBytes(maxSize)}.`,\n );\n continue;\n }\n\n const error = validateFile(file);\n if (error) {\n errors.push(error);\n } else {\n validFiles.push({\n file,\n id: generateUniqueId(file),\n preview: createPreview(file),\n });\n }\n }\n\n // Only update state if we have valid files to add\n if (validFiles.length > 0) {\n // Call the onFilesAdded callback with the newly added valid files\n onFilesAdded?.(validFiles);\n\n setState((prev) => {\n const newFiles = !multiple ? validFiles : [...prev.files, ...validFiles];\n onFilesChange?.(newFiles);\n return {\n ...prev,\n files: newFiles,\n errors,\n };\n });\n } else if (errors.length > 0) {\n onError?.(errors);\n setState((prev) => ({\n ...prev,\n errors,\n }));\n }\n\n // Reset input value after handling files\n if (inputRef.current) {\n inputRef.current.value = \"\";\n }\n },\n [\n state.files,\n maxFiles,\n multiple,\n maxSize,\n validateFile,\n createPreview,\n generateUniqueId,\n clearFiles,\n onFilesChange,\n onFilesAdded,\n onError,\n ],\n );\n\n const removeFile = useCallback(\n (id: string) => {\n setState((prev) => {\n const fileToRemove = prev.files.find((file) => file.id === id);\n if (\n fileToRemove?.preview &&\n fileToRemove.file instanceof File &&\n fileToRemove.file.type.startsWith(\"image/\")\n ) {\n URL.revokeObjectURL(fileToRemove.preview);\n }\n\n const newFiles = prev.files.filter((file) => file.id !== id);\n onFilesChange?.(newFiles);\n\n return {\n ...prev,\n files: newFiles,\n errors: [],\n };\n });\n },\n [onFilesChange],\n );\n\n const clearErrors = useCallback(() => {\n setState((prev) => ({\n ...prev,\n errors: [],\n }));\n }, []);\n\n const handleDragEnter = useCallback((e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n setState((prev) => ({ ...prev, isDragging: true }));\n }, []);\n\n const handleDragLeave = useCallback((e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n\n if (e.currentTarget.contains(e.relatedTarget as Node)) {\n return;\n }\n\n setState((prev) => ({ ...prev, isDragging: false }));\n }, []);\n\n const handleDragOver = useCallback((e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n }, []);\n\n const handleDrop = useCallback(\n (e: DragEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n setState((prev) => ({ ...prev, isDragging: false }));\n\n // Don't process files if the input is disabled\n if (inputRef.current?.disabled) {\n return;\n }\n\n if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {\n // In single file mode, only use the first file\n if (!multiple) {\n const file = e.dataTransfer.files[0];\n addFiles([file]);\n } else {\n addFiles(e.dataTransfer.files);\n }\n }\n },\n [addFiles, multiple],\n );\n\n const handleFileChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n if (e.target.files && e.target.files.length > 0) {\n addFiles(e.target.files);\n }\n },\n [addFiles],\n );\n\n const openFileDialog = useCallback(() => {\n if (inputRef.current) {\n inputRef.current.click();\n }\n }, []);\n\n const getInputProps = useCallback(\n (props: InputHTMLAttributes<HTMLInputElement> = {}) => {\n return {\n ...props,\n type: \"file\" as const,\n onChange: handleFileChange,\n accept: props.accept || accept,\n multiple: props.multiple !== undefined ? props.multiple : multiple,\n ref: inputRef,\n };\n },\n [accept, multiple, handleFileChange],\n );\n\n return [\n state,\n {\n addFiles,\n removeFile,\n clearFiles,\n clearErrors,\n handleDragEnter,\n handleDragLeave,\n handleDragOver,\n handleDrop,\n handleFileChange,\n openFileDialog,\n getInputProps,\n },\n ];\n};\n\n// Helper function to format bytes to human-readable format\nexport const formatBytes = (bytes: number, decimals = 2): string => {\n if (bytes === 0) return \"0 Bytes\";\n\n const k = 1024;\n const dm = decimals < 0 ? 0 : decimals;\n const sizes = [\"Bytes\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"];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QAAQ,MAAM,UAAU;IACxB,UAAU,MAAM,aAAa,KAAA,IAAY,MAAM,WAAW;IAC1D,KAAK;GACP;EACF,GACA;GAAC;GAAQ;GAAU;EAAgB,CAgBrB;CACd,CACF;AACF;AAGA,MAAa,eAAe,OAAe,WAAW,MAAc;CAClE,IAAI,UAAU,GAAG,OAAO;CAExB,MAAM,IAAI;CACV,MAAM,KAAK,WAAW,IAAI,IAAI;CAC9B,MAAM,QAAQ;EAAC;EAAS;EAAM;EAAM;EAAM;EAAM;EAAM;EAAM;EAAM;CAAI;CAEtE,MAAM,IAAI,KAAK,MAAM,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,CAAC,CAAC;CAElD,OAAO,GAAG,OAAO,YAAY,QAAQ,KAAK,EAAA,CAAG,QAAQ,EAAE,CAAC,EAAE,GAAG,MAAM;AACrE"}
|
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
//#region src/hooks/use-hydrated.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Hydration state hook for React components
|
|
4
|
-
* Returns a boolean indicating whether the component is running on the client
|
|
5
|
-
* with SSR-safe behavior to prevent hydration mismatches.
|
|
6
|
-
*
|
|
7
|
-
* This hook leverages `useSyncExternalStore` to provide a stable value between
|
|
8
|
-
* server and client renders: `false` during SSR, `true` after client hydration.
|
|
9
|
-
* The external store does not emit updates because the hydration state is static
|
|
10
|
-
* for the lifetime of the component.
|
|
11
|
-
*/
|
|
12
2
|
/**
|
|
13
3
|
* Hook that indicates whether code is executing on the client after hydration
|
|
14
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-hydrated.d.ts","names":[],"sources":["../../src/hooks/use-hydrated.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-hydrated.d.ts","names":[],"sources":["../../src/hooks/use-hydrated.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;iBA0BgB"}
|
|
@@ -2,16 +2,6 @@
|
|
|
2
2
|
import { useSyncExternalStore } from "react";
|
|
3
3
|
//#region src/hooks/use-hydrated.ts
|
|
4
4
|
/**
|
|
5
|
-
* Hydration state hook for React components
|
|
6
|
-
* Returns a boolean indicating whether the component is running on the client
|
|
7
|
-
* with SSR-safe behavior to prevent hydration mismatches.
|
|
8
|
-
*
|
|
9
|
-
* This hook leverages `useSyncExternalStore` to provide a stable value between
|
|
10
|
-
* server and client renders: `false` during SSR, `true` after client hydration.
|
|
11
|
-
* The external store does not emit updates because the hydration state is static
|
|
12
|
-
* for the lifetime of the component.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
5
|
* Hook that indicates whether code is executing on the client after hydration
|
|
16
6
|
*
|
|
17
7
|
* Features:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-hydrated.js","names":[],"sources":["../../src/hooks/use-hydrated.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"use-hydrated.js","names":[],"sources":["../../src/hooks/use-hydrated.ts"],"sourcesContent":["\"use client\";\n\nimport { useSyncExternalStore } from \"react\";\n\n/**\n * Hook that indicates whether code is executing on the client after hydration\n *\n * Features:\n * - SSR-safe: returns `false` on the server to avoid hydration mismatches\n * - Client-stable: returns `true` after hydration and remains stable\n * - Minimal overhead: uses a no-op external store subscription\n *\n * @returns Boolean indicating hydration state (`true` on client, `false` on server)\n *\n * @example\n * ```tsx\n * // Conditionally render client-only components safely\n * function ClientOnly() {\n * const hydrated = useHydrated();\n * if (!hydrated) return null;\n * return <InteractiveChart />;\n * }\n * ```\n *\n * @since 1.0.0\n */\nexport function useHydrated() {\n return useSyncExternalStore(\n subscribe,\n () => true,\n () => false,\n );\n}\n\n/**\n * External store subscription used by `useHydrated`\n * No updates are dispatched because hydration state is static.\n * Returns an unsubscribe function for API conformity.\n */\nfunction subscribe() {\n return () => {};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,cAAc;CAC5B,OAAO,qBACL,iBACM,YACA,KACR;AACF;;;;;;AAOA,SAAS,YAAY;CACnB,aAAa,CAAC;AAChB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intersection-observer.d.ts","names":[],"sources":["../../src/hooks/use-intersection-observer.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"use-intersection-observer.d.ts","names":[],"sources":["../../src/hooks/use-intersection-observer.ts"],"mappings":";;;;;;;;UAUU,oCAAoC;;;;;;;;EAQ5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsHc,wBACd,YAAY,QAAM,UAAU,mBAE1B,WACA,MACA,YACA,sBACC"}
|
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
import * as React$1 from "react";
|
|
3
3
|
//#region src/hooks/use-intersection-observer.ts
|
|
4
4
|
/**
|
|
5
|
-
* Intersection observer hook for React components
|
|
6
|
-
* Efficiently observes visibility of DOM elements using a shared IntersectionObserver instance.
|
|
7
|
-
* Ideal for lazy loading, infinite scrolling, and animating elements when they enter the viewport.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
5
|
* A shared intersection observer to manage multiple targets with a single observer instance.
|
|
11
6
|
* Optimized for high-density lists (like the patterns grid).
|
|
12
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intersection-observer.js","names":["React"],"sources":["../../src/hooks/use-intersection-observer.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"use-intersection-observer.js","names":["React"],"sources":["../../src/hooks/use-intersection-observer.ts"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\n/**\n * Configuration options for the `useIntersectionObserver` hook.\n *\n * Extends the native `IntersectionObserverInit` options with an additional\n * convenience flag for freezing the observer state.\n */\ninterface IntersectionObserverOptions extends IntersectionObserverInit {\n /**\n * When `true`, the hook stops observing once the element becomes visible\n * and keeps returning `true` for subsequent renders.\n *\n * This is useful for one-time animations or lazy loading where you only\n * care about the first time an element enters the viewport.\n */\n freezeOnceVisible?: boolean;\n}\n\n/**\n * A shared intersection observer to manage multiple targets with a single observer instance.\n * Optimized for high-density lists (like the patterns grid).\n */\nclass SharedObserver {\n private observer: IntersectionObserver | null = null;\n private callbacks = new Map<Element, (isIntersecting: boolean) => void>();\n private options: IntersectionObserverInit;\n\n constructor(options: IntersectionObserverInit) {\n this.options = options;\n }\n\n private getObserver() {\n if (!this.observer) {\n this.observer = new IntersectionObserver((entries) => {\n entries.forEach((entry) => {\n const callback = this.callbacks.get(entry.target);\n if (callback) {\n callback(entry.isIntersecting);\n }\n });\n }, this.options);\n }\n return this.observer;\n }\n\n observe(element: Element, callback: (isIntersecting: boolean) => void) {\n this.callbacks.set(element, callback);\n this.getObserver().observe(element);\n }\n\n unobserve(element: Element) {\n this.callbacks.delete(element);\n this.observer?.unobserve(element);\n }\n\n get size() {\n return this.callbacks.size;\n }\n\n disconnect() {\n this.observer?.disconnect();\n this.callbacks.clear();\n this.observer = null;\n }\n}\n\n// Singleton instances for common observer options to maximize reuse.\nconst observers = new Map<string, SharedObserver>();\nconst rootIds = new WeakMap<Element, number>();\nlet rootId = 0;\n\nfunction getRootKey(root: Element | Document | null | undefined) {\n if (!root) return \"null\";\n if (!rootIds.has(root as Element)) {\n rootIds.set(root as Element, ++rootId);\n }\n return rootIds.get(root as Element);\n}\n\n/**\n * Get or create a shared `IntersectionObserver` instance based on the provided options.\n *\n * Using a shared observer reduces the number of underlying `IntersectionObserver`\n * instances created by the browser, which is especially beneficial for pages\n * with many observed elements.\n *\n * @param options - Intersection observer configuration (threshold, root, rootMargin)\n * @returns A shared `SharedObserver` instance for the given options\n */\nfunction getSharedObserver(options: IntersectionObserverInit) {\n const threshold = Array.isArray(options.threshold)\n ? options.threshold.join(\",\")\n : (options.threshold ?? 0);\n const key = `${getRootKey(options.root)}|${options.rootMargin ?? \"0px\"}|${threshold}`;\n if (!observers.has(key)) {\n observers.set(key, new SharedObserver(options));\n }\n return { key, observer: observers.get(key)! };\n}\n\n/**\n * React hook that tracks whether a DOM element is currently intersecting the viewport.\n *\n * Features:\n * - Uses a shared `IntersectionObserver` instance for better performance.\n * - Supports custom `threshold`, `root`, and `rootMargin` options.\n * - Optional `freezeOnceVisible` flag to stop observing after first intersection.\n *\n * @param elementRef - React ref pointing to the DOM element to observe.\n * @param options - Optional observer configuration and behavior flags.\n * @param options.threshold - Intersection threshold(s) for triggering visibility changes.\n * @param options.root - Scrollable ancestor element to use as the viewport (defaults to browser viewport).\n * @param options.rootMargin - Margin around the root, expressed in CSS units (e.g. `\"0px 0px -20% 0px\"`).\n * @param options.freezeOnceVisible - When `true`, stops observing after the element first becomes visible.\n *\n * @returns `true` when the element is intersecting based on the given options, otherwise `false`.\n *\n * @example\n * ```tsx\n * const ref = React.useRef<HTMLDivElement | null>(null);\n * const isVisible = useIntersectionObserver(ref, {\n * threshold: 0.2,\n * rootMargin: \"0px 0px -10% 0px\",\n * freezeOnceVisible: true,\n * });\n *\n * return (\n * <div ref={ref} className={isVisible ? \"animate-in\" : \"opacity-0\"}>\n * I will animate when I enter the viewport.\n * </div>\n * );\n * ```\n */\nexport function useIntersectionObserver(\n elementRef: React.RefObject<Element | null>,\n {\n threshold = 0,\n root = null,\n rootMargin = \"0%\",\n freezeOnceVisible = false,\n }: IntersectionObserverOptions = {},\n): boolean {\n const [isIntersecting, setIntersecting] = React.useState(false);\n const frozen = React.useRef(false);\n\n React.useEffect(() => {\n const element = elementRef?.current;\n if (!element || (freezeOnceVisible && frozen.current)) return;\n if (typeof IntersectionObserver === \"undefined\") return;\n\n const { key, observer } = getSharedObserver({ threshold, root, rootMargin });\n\n observer.observe(element, (intersecting) => {\n setIntersecting(intersecting);\n if (intersecting && freezeOnceVisible) {\n frozen.current = true;\n observer.unobserve(element);\n }\n });\n\n return () => {\n observer.unobserve(element);\n if (observer.size === 0) {\n observer.disconnect();\n observers.delete(key);\n }\n };\n }, [elementRef, threshold, root, rootMargin, freezeOnceVisible]);\n\n return isIntersecting;\n}\n"],"mappings":";;;;;;;AAyBA,IAAM,iBA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OAAO,CAAC;CAEhD,OAAO;EAAE;EAAK,UAAU,UAAU,IAAI,GAAG;CAAG;AAC9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,wBACd,YACA,EACE,YAAY,GACZ,OAAO,MACP,aAAa,MACb,oBAAoB,UACW,CAAC,GACzB;CACT,MAAM,CAAC,gBAAgB,mBAAmBA,QAAM,SAAS,KAAK;CAC9D,MAAM,SAASA,QAAM,OAAO,KAAK;CAEjC,QAAM,gBAAgB;EACpB,MAAM,UAAU,YAAY;EAC5B,IAAI,CAAC,WAAY,qBAAqB,OAAO,SAAU;EACvD,IAAI,OAAO,yBAAyB,aAAa;EAEjD,MAAM,EAAE,KAAK,aAAa,kBAAkB;GAAE;GAAW;GAAM;EAAW,CAAC;EAE3E,SAAS,QAAQ,UAAU,iBAAiB;GAC1C,gBAAgB,YAAY;GAC5B,IAAI,gBAAgB,mBAAmB;IACrC,OAAO,UAAU;IACjB,SAAS,UAAU,OAAO;GAC5B;EACF,CAAC;EAED,aAAa;GACX,SAAS,UAAU,OAAO;GAC1B,IAAI,SAAS,SAAS,GAAG;IACvB,SAAS,WAAW;IACpB,UAAU,OAAO,GAAG;GACtB;EACF;CACF,GAAG;EAAC;EAAY;EAAW;EAAM;EAAY;CAAiB,CAAC;CAE/D,OAAO;AACT"}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
//#region src/hooks/use-is-mac.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Platform detection hook for React components
|
|
4
|
-
* Determines whether the current user agent is running on a macOS device.
|
|
5
|
-
* Useful for rendering platform-specific keyboard shortcuts or UI variations.
|
|
6
|
-
*/
|
|
7
2
|
/**
|
|
8
3
|
* React hook that returns whether the current browser reports a macOS platform.
|
|
9
4
|
* It prefers `navigator.userAgentData.platform` when available and falls back
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-is-mac.d.ts","names":[],"sources":["../../src/hooks/use-is-mac.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-is-mac.d.ts","names":[],"sources":["../../src/hooks/use-is-mac.ts"],"mappings":";;;;;;;;;;;;;;;;;;;iBAsBgB"}
|
package/dist/hooks/use-is-mac.js
CHANGED
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
3
|
//#region src/hooks/use-is-mac.ts
|
|
4
4
|
/**
|
|
5
|
-
* Platform detection hook for React components
|
|
6
|
-
* Determines whether the current user agent is running on a macOS device.
|
|
7
|
-
* Useful for rendering platform-specific keyboard shortcuts or UI variations.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
5
|
* React hook that returns whether the current browser reports a macOS platform.
|
|
11
6
|
* It prefers `navigator.userAgentData.platform` when available and falls back
|
|
12
7
|
* to `navigator.userAgent`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-is-mac.js","names":[],"sources":["../../src/hooks/use-is-mac.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"use-is-mac.js","names":[],"sources":["../../src/hooks/use-is-mac.ts"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useState } from \"react\";\n\n/**\n * React hook that returns whether the current browser reports a macOS platform.\n * It prefers `navigator.userAgentData.platform` when available and falls back\n * to `navigator.userAgent`.\n *\n * @returns `true` if the current platform is macOS, otherwise `false`.\n *\n * @example\n * ```tsx\n * const isMac = useIsMac();\n *\n * return (\n * <kbd>\n * {isMac ? \"⌘\" : \"Ctrl\"} + K\n * </kbd>\n * );\n * ```\n */\nexport function useIsMac() {\n const [isMac, setIsMac] = useState(false);\n\n useEffect(() => {\n const platform =\n (navigator as Navigator & { userAgentData?: { platform?: string } }).userAgentData\n ?.platform ??\n navigator.userAgent ??\n \"\";\n setIsMac(platform.toUpperCase().includes(\"MAC\"));\n }, []);\n\n return isMac;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,WAAW;CACzB,MAAM,CAAC,OAAO,YAAY,SAAS,KAAK;CAExC,gBAAgB;EACd,MAAM,WACH,UAAoE,eACjE,YACJ,UAAU,aACV;EACF,SAAS,SAAS,YAAY,CAAC,CAAC,SAAS,KAAK,CAAC;CACjD,GAAG,CAAC,CAAC;CAEL,OAAO;AACT"}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
//#region src/hooks/use-media-query.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Media query hook for responsive React components
|
|
4
|
-
* Provides real-time tracking of CSS media query matches
|
|
5
|
-
* with SSR-safe implementation and automatic cleanup
|
|
6
|
-
*/
|
|
7
2
|
/**
|
|
8
3
|
* Hook for tracking CSS media query matches in React components
|
|
9
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-media-query.d.ts","names":[],"sources":["../../src/hooks/use-media-query.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-media-query.d.ts","names":[],"sources":["../../src/hooks/use-media-query.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsCa,gBAAiB"}
|
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
import { useCallback, useSyncExternalStore } from "react";
|
|
3
3
|
//#region src/hooks/use-media-query.ts
|
|
4
4
|
/**
|
|
5
|
-
* Media query hook for responsive React components
|
|
6
|
-
* Provides real-time tracking of CSS media query matches
|
|
7
|
-
* with SSR-safe implementation and automatic cleanup
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
5
|
* Hook for tracking CSS media query matches in React components
|
|
11
6
|
*
|
|
12
7
|
* Features:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-media-query.js","names":[],"sources":["../../src/hooks/use-media-query.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"use-media-query.js","names":[],"sources":["../../src/hooks/use-media-query.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useSyncExternalStore } from \"react\";\n\n/**\n * Hook for tracking CSS media query matches in React components\n *\n * Features:\n * - Real-time updates when media query state changes\n * - SSR-safe implementation\n * - Automatic event listener cleanup\n * - Supports all standard CSS media queries\n *\n * @param query - CSS media query string (e.g., '(min-width: 768px)')\n * @returns Boolean indicating whether the media query currently matches\n *\n * @example\n * ```tsx\n * // Basic responsive behavior\n * const isMobile = useMediaQuery('(max-width: 768px)');\n * const isTablet = useMediaQuery('(min-width: 769px) and (max-width: 1024px)');\n * const isDesktop = useMediaQuery('(min-width: 1025px)');\n *\n * // Dark mode preference\n * const prefersDark = useMediaQuery('(prefers-color-scheme: dark)');\n *\n * // Reduced motion preference\n * const prefersReducedMotion = useMediaQuery('(prefers-reduced-motion: reduce)');\n *\n * return (\n * <div>\n * {isMobile && <MobileLayout />}\n * {isTablet && <TabletLayout />}\n * {isDesktop && <DesktopLayout />}\n * </div>\n * );\n * ```\n */\nexport const useMediaQuery = (query: string): boolean => {\n // Subscribe to media query changes and clean up automatically\n const subscribe = useCallback(\n (onChange: () => void) => {\n const matchMedia = window.matchMedia(query);\n matchMedia.addEventListener(\"change\", onChange);\n return () => {\n matchMedia.removeEventListener(\"change\", onChange);\n };\n },\n [query],\n );\n\n // Read the current match status on the client\n const getSnapshot = useCallback(() => window.matchMedia(query).matches, [query]);\n\n // Always report false during SSR to avoid hydration mismatches\n const getServerSnapshot = () => false;\n\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,iBAAiB,UAA2B;CAEvD,MAAM,YAAY,aACf,aAAyB;EACxB,MAAM,aAAa,OAAO,WAAW,KAAK;EAC1C,WAAW,iBAAiB,UAAU,QAAQ;EAC9C,aAAa;GACX,WAAW,oBAAoB,UAAU,QAAQ;EACnD;CACF,GACA,CAAC,KAAK,CACR;CAGA,MAAM,cAAc,kBAAkB,OAAO,WAAW,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC;CAG/E,MAAM,0BAA0B;CAEhC,OAAO,qBAAqB,WAAW,aAAa,iBAAiB;AACvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-meta-color.d.ts","names":[],"sources":["../../src/hooks/use-meta-color.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"use-meta-color.d.ts","names":[],"sources":["../../src/hooks/use-meta-color.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0EgB,aAAa,uBAAuB;;;;EAqDH,eAAA"}
|
|
@@ -4,9 +4,6 @@ import { META_THEME_COLORS, THEME_MODES } from "@kumix/utils";
|
|
|
4
4
|
import { useTheme } from "next-themes";
|
|
5
5
|
//#region src/hooks/use-meta-color.ts
|
|
6
6
|
/**
|
|
7
|
-
* Meta theme color management hook for React components.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
7
|
* Calculates and applies the HTML `theme-color` meta tag from `next-themes`.
|
|
11
8
|
* The returned setter can be used for temporary manual overrides.
|
|
12
9
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-meta-color.js","names":["React"],"sources":["../../src/hooks/use-meta-color.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"use-meta-color.js","names":["React"],"sources":["../../src/hooks/use-meta-color.ts"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { useTheme } from \"next-themes\";\n\nimport { META_THEME_COLORS, THEME_MODES } from \"@kumix/utils\";\n\n/**\n * Calculates and applies the HTML `theme-color` meta tag from `next-themes`.\n * The returned setter can be used for temporary manual overrides.\n *\n * @param defaultColors - Optional custom color configuration (defaults to META_THEME_COLORS)\n * @returns Object containing current meta color and setter function.\n *\n * @example\n * ```tsx\n * // Basic usage with default colors (supports light, dark, and system)\n * function App() {\n * const { metaColor, setMetaColor } = useMetaColor();\n *\n * // metaColor automatically updates based on theme (light/dark/system)\n * useEffect(() => {\n * console.log('Current meta color:', metaColor);\n * }, [metaColor]);\n *\n * return <div>App content</div>;\n * }\n *\n * // Custom colors with system theme support\n * function CustomThemeApp() {\n * const customColors = {\n * light: '#f0f0f0',\n * dark: '#1a1a1a',\n * system: 'auto' // Will resolve to light or dark based on OS preference\n * };\n * const { metaColor } = useMetaColor(customColors);\n *\n * return <div style={{ backgroundColor: metaColor }}>Custom themed app</div>;\n * }\n *\n * // Manual meta color override for special pages\n * function SpecialPage() {\n * const { setMetaColor } = useMetaColor();\n *\n * useEffect(() => {\n * // Override meta color for this page\n * setMetaColor('#ff0000');\n *\n * // Cleanup: reset to theme color when leaving page\n * return () => {\n * setMetaColor(''); // This will revert to theme-based color\n * };\n * }, [setMetaColor]);\n *\n * return <div>Special page with red theme color</div>;\n * }\n *\n * // Integration with theme switcher\n * function ThemeAwareComponent() {\n * const { theme, setTheme } = useTheme();\n * const { metaColor } = useMetaColor();\n *\n * return (\n * <div>\n * <p>Current theme: {theme}</p>\n * <p>Meta color: {metaColor}</p>\n * <button onClick={() => setTheme('light')}>Light</button>\n * <button onClick={() => setTheme('dark')}>Dark</button>\n * <button onClick={() => setTheme('system')}>System</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useMetaColor(defaultColors?: typeof META_THEME_COLORS) {\n /** Get resolved theme from next-themes */\n const { resolvedTheme } = useTheme();\n\n /**\n * Helper function to detect system dark mode preference\n */\n const isSystemDarkMode = React.useCallback(() => {\n if (typeof window === \"undefined\") return false;\n return window.matchMedia(\"(prefers-color-scheme: dark)\").matches;\n }, []);\n\n /**\n * Get effective theme mode (resolves 'system' to actual preference)\n */\n const getEffectiveTheme = React.useCallback(\n (theme: string | undefined) => {\n if (theme === THEME_MODES.SYSTEM) {\n return isSystemDarkMode() ? THEME_MODES.DARK : THEME_MODES.LIGHT;\n }\n return theme;\n },\n [isSystemDarkMode],\n );\n\n /**\n * Calculate appropriate meta color based on current theme\n * Handles light, dark, and system themes properly\n * Memoized to prevent unnecessary recalculations\n */\n const metaColor = React.useMemo(() => {\n const colorsToUse = defaultColors ?? META_THEME_COLORS;\n\n // Get the effective theme (resolves system to light/dark)\n const effectiveTheme = getEffectiveTheme(resolvedTheme);\n\n // Handle different theme modes\n if (effectiveTheme === THEME_MODES.DARK) {\n return colorsToUse[THEME_MODES.DARK];\n } else if (effectiveTheme === THEME_MODES.LIGHT) {\n return colorsToUse[THEME_MODES.LIGHT];\n }\n\n // Fallback to light theme if resolvedTheme is undefined (during hydration)\n return colorsToUse[THEME_MODES.LIGHT];\n }, [resolvedTheme, defaultColors, getEffectiveTheme]);\n\n /**\n * Manually set meta theme color in the document\n * Useful for temporary color overrides or custom scenarios\n *\n * @param color - Hex color string to set as meta theme color\n */\n const setMetaColor = React.useCallback((color: string) => {\n // Find and update the meta theme-color tag\n const metaTag = document.querySelector('meta[name=\"theme-color\"]');\n if (metaTag) {\n metaTag.setAttribute(\"content\", color);\n } else {\n // Create meta tag if it doesn't exist\n const newMetaTag = document.createElement(\"meta\");\n newMetaTag.name = \"theme-color\";\n newMetaTag.content = color;\n document.head.appendChild(newMetaTag);\n }\n }, []);\n\n React.useEffect(() => {\n setMetaColor(metaColor);\n }, [metaColor, setMetaColor]);\n\n return {\n /** Current meta theme color based on resolved theme */\n metaColor,\n /** Function to manually set meta theme color */\n setMetaColor,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,aAAa,eAA0C;;CAErE,MAAM,EAAE,kBAAkB,SAAS;;;;CAKnC,MAAM,mBAAmBA,QAAM,kBAAkB;EAC/C,IAAI,OAAO,WAAW,aAAa,OAAO;EAC1C,OAAO,OAAO,WAAW,8BAA8B,CAAC,CAAC;CAC3D,GAAG,CAAC,CAAC;;;;CAKL,MAAM,oBAAoBA,QAAM,aAC7B,UAA8B;EAC7B,IAAI,UAAU,YAAY,QACxB,OAAO,iBAAiB,IAAI,YAAY,OAAO,YAAY;EAE7D,OAAO;CACT,GACA,CAAC,gBAAgB,CACnB;;;;;;CAOA,MAAM,YAAYA,QAAM,cAAc;EACpC,MAAM,cAAc,iBAAiB;EAGrC,MAAM,iBAAiB,kBAAkB,aAAa;EAGtD,IAAI,mBAAmB,YAAY,MACjC,OAAO,YAAY,YAAY;OAC1B,IAAI,mBAAmB,YAAY,OACxC,OAAO,YAAY,YAAY;EAIjC,OAAO,YAAY,YAAY;CACjC,GAAG;EAAC;EAAe;EAAe;CAAiB,CAAC;;;;;;;CAQpD,MAAM,eAAeA,QAAM,aAAa,UAAkB;EAExD,MAAM,UAAU,SAAS,cAAc,4BAA0B;EACjE,IAAI,SACF,QAAQ,aAAa,WAAW,KAAK;OAChC;GAEL,MAAM,aAAa,SAAS,cAAc,MAAM;GAChD,WAAW,OAAO;GAClB,WAAW,UAAU;GACrB,SAAS,KAAK,YAAY,UAAU;EACtC;CACF,GAAG,CAAC,CAAC;CAEL,QAAM,gBAAgB;EACpB,aAAa,SAAS;CACxB,GAAG,CAAC,WAAW,YAAY,CAAC;CAE5B,OAAO;;EAEL;;EAEA;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mutation-observer.d.ts","names":[],"sources":["../../src/hooks/use-mutation-observer.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"use-mutation-observer.d.ts","names":[],"sources":["../../src/hooks/use-mutation-observer.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0Ea,sBACX,KAAK,QAAM,UAAU,qBACrB,UAAU,kBACV,UAAS"}
|
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
import * as React$1 from "react";
|
|
3
3
|
//#region src/hooks/use-mutation-observer.ts
|
|
4
4
|
/**
|
|
5
|
-
* DOM Mutation Observer hook for React components
|
|
6
|
-
* Provides a React-friendly interface for observing DOM changes
|
|
7
|
-
* with automatic cleanup and ref integration
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
5
|
* Default options for MutationObserver
|
|
11
6
|
* Observes all types of mutations by default
|
|
12
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mutation-observer.js","names":[],"sources":["../../src/hooks/use-mutation-observer.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"use-mutation-observer.js","names":[],"sources":["../../src/hooks/use-mutation-observer.ts"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\n/**\n * Default options for MutationObserver\n * Observes all types of mutations by default\n */\nconst DEFAULT_OPTIONS: MutationObserverInit = {\n /** Watch for attribute changes */\n attributes: true,\n /** Watch for text content changes */\n characterData: true,\n /** Watch for child element additions/removals */\n childList: true,\n /** Watch for changes in descendant elements */\n subtree: true,\n};\n\n/**\n * Hook to observe DOM mutations on a referenced element\n *\n * This hook provides a React-friendly way to use the MutationObserver API.\n * It automatically handles observer creation, cleanup, and ref management.\n * Useful for detecting DOM changes that occur outside of React's control.\n *\n * Features:\n * - Automatic observer lifecycle management\n * - Configurable observation options\n * - Ref-based element targeting\n * - Automatic cleanup on unmount\n *\n * @param ref - React ref pointing to the element to observe\n * @param callback - Function called when mutations are detected\n * @param options - MutationObserver configuration options\n *\n * @example\n * ```tsx\n * function DynamicContent() {\n * const contentRef = useRef<HTMLDivElement>(null);\n *\n * // Watch for any changes to the content div\n * useMutationObserver(\n * contentRef,\n * (mutations) => {\n * mutations.forEach((mutation) => {\n * console.log('DOM changed:', mutation.type);\n * });\n * }\n * );\n *\n * return <div ref={contentRef}>Dynamic content here</div>;\n * }\n *\n * // Watch only for attribute changes\n * function AttributeWatcher() {\n * const elementRef = useRef<HTMLElement>(null);\n *\n * useMutationObserver(\n * elementRef,\n * (mutations) => {\n * mutations.forEach((mutation) => {\n * if (mutation.type === 'attributes') {\n * console.log('Attribute changed:', mutation.attributeName);\n * }\n * });\n * },\n * { attributes: true, childList: false, subtree: false }\n * );\n *\n * return <div ref={elementRef}>Watched element</div>;\n * }\n * ```\n */\nexport const useMutationObserver = (\n ref: React.RefObject<HTMLElement | null>,\n callback: MutationCallback,\n options: MutationObserverInit = DEFAULT_OPTIONS,\n) => {\n React.useEffect(() => {\n // Only proceed if ref has a current element\n if (ref.current) {\n // Create new MutationObserver instance\n const observer = new MutationObserver(callback);\n\n // Start observing the target element\n observer.observe(ref.current, options);\n\n // Cleanup function to disconnect observer\n return () => {\n observer.disconnect();\n };\n }\n }, [ref, callback, options]); // Re-run effect when dependencies change\n};\n"],"mappings":";;;;;;;AAQA,MAAM,kBAAwC;;CAE5C,YAAY;;CAEZ,eAAe;;CAEf,WAAW;;CAEX,SAAS;AACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAa,uBACX,KACA,UACA,UAAgC,oBAC7B;CACH,QAAM,gBAAgB;EAEpB,IAAI,IAAI,SAAS;GAEf,MAAM,WAAW,IAAI,iBAAiB,QAAQ;GAG9C,SAAS,QAAQ,IAAI,SAAS,OAAO;GAGrC,aAAa;IACX,SAAS,WAAW;GACtB;EACF;CACF,GAAG;EAAC;EAAK;EAAU;CAAO,CAAC;AAC7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-scroll-position.d.ts","names":[],"sources":["../../src/hooks/use-scroll-position.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"use-scroll-position.d.ts","names":[],"sources":["../../src/hooks/use-scroll-position.ts"],"mappings":";;;;;UAOU;;EAER,YAAY,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkEzB,sBAAqB,cAAe"}
|
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
3
|
//#region src/hooks/use-scroll-position.ts
|
|
4
4
|
/**
|
|
5
|
-
* Scroll position tracking hook for React components
|
|
6
|
-
* Monitors scroll position of window or specific elements
|
|
7
|
-
* with real-time updates and automatic cleanup
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
5
|
* Hook to track scroll position of window or specific elements
|
|
11
6
|
*
|
|
12
7
|
* This hook provides real-time tracking of scroll position with support
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-scroll-position.js","names":[],"sources":["../../src/hooks/use-scroll-position.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"use-scroll-position.js","names":[],"sources":["../../src/hooks/use-scroll-position.ts"],"sourcesContent":["\"use client\";\n\nimport { type RefObject, useEffect, useState } from \"react\";\n\n/**\n * Configuration options for the scroll position hook\n */\ninterface UseScrollPositionProps {\n /** Optional ref to a specific scrollable element (defaults to document) */\n targetRef?: RefObject<HTMLElement | Document | undefined>;\n}\n\n/**\n * Hook to track scroll position of window or specific elements\n *\n * This hook provides real-time tracking of scroll position with support\n * for both window scrolling and element-specific scrolling. It automatically\n * handles event listener management and cleanup.\n *\n * Features:\n * - Real-time scroll position tracking\n * - Support for window and element scrolling\n * - Automatic event listener cleanup\n * - SSR-safe implementation\n * - Performance optimized\n *\n * @param options - Configuration options for the hook\n * @returns Current scroll position in pixels\n *\n * @example\n * ```tsx\n * // Track window scroll position\n * function ScrollIndicator() {\n * const scrollPosition = useScrollPosition();\n *\n * return (\n * <div className=\"scroll-indicator\">\n * Scrolled: {scrollPosition}px\n * </div>\n * );\n * }\n *\n * // Track specific element scroll position\n * function ScrollableContent() {\n * const contentRef = useRef<HTMLDivElement>(null);\n * const scrollPosition = useScrollPosition({ targetRef: contentRef });\n *\n * return (\n * <div\n * ref={contentRef}\n * className=\"h-96 overflow-y-auto\"\n * >\n * <div className=\"h-[1000px]\">\n * <p>Scroll position: {scrollPosition}px</p>\n * <p>Long content here...</p>\n * </div>\n * </div>\n * );\n * }\n *\n * // Show/hide header based on scroll\n * function StickyHeader() {\n * const scrollPosition = useScrollPosition();\n * const isVisible = scrollPosition < 100;\n *\n * return (\n * <header className={`transition-transform ${\n * isVisible ? 'translate-y-0' : '-translate-y-full'\n * }`}>\n * Header content\n * </header>\n * );\n * }\n * ```\n */\nexport const useScrollPosition = ({ targetRef }: UseScrollPositionProps = {}): number => {\n /** State to track current scroll position */\n const [scrollPosition, setScrollPosition] = useState<number>(0);\n\n useEffect(() => {\n // Determine the target element (fallback to document if not provided)\n const target = targetRef?.current || document;\n\n // Determine the scrollable element (window for document, element for others)\n const scrollable = target === document ? window : target;\n\n /**\n * Update scroll position state\n * Handles both window and element scrolling\n */\n const updatePosition = () => {\n // Get scroll position based on target type\n const scrollY =\n target === document\n ? window.scrollY || window.pageYOffset // Fallback for older browsers\n : (target as HTMLElement).scrollTop;\n\n setScrollPosition(scrollY);\n };\n\n // Add scroll event listener\n scrollable.addEventListener(\"scroll\", updatePosition, { passive: true });\n\n // Set initial scroll position\n updatePosition();\n\n // Cleanup function to remove event listener\n return () => {\n scrollable.removeEventListener(\"scroll\", updatePosition);\n };\n }, [targetRef]); // Re-run effect when targetRef changes\n\n return scrollPosition;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,MAAa,qBAAqB,EAAE,cAAsC,CAAC,MAAc;;CAEvF,MAAM,CAAC,gBAAgB,qBAAqB,SAAiB,CAAC;CAE9D,gBAAgB;EAEd,MAAM,SAAS,WAAW,WAAW;EAGrC,MAAM,aAAa,WAAW,WAAW,SAAS;;;;;EAMlD,MAAM,uBAAuB;GAE3B,MAAM,UACJ,WAAW,WACP,OAAO,WAAW,OAAO,cACxB,OAAuB;GAE9B,kBAAkB,OAAO;EAC3B;EAGA,WAAW,iBAAiB,UAAU,gBAAgB,EAAE,SAAS,KAAK,CAAC;EAGvE,eAAe;EAGf,aAAa;GACX,WAAW,oBAAoB,UAAU,cAAc;EACzD;CACF,GAAG,CAAC,SAAS,CAAC;CAEd,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-slider-input.d.ts","names":[],"sources":["../../src/hooks/use-slider-input.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"use-slider-input.d.ts","names":[],"sources":["../../src/hooks/use-slider-input.ts"],"mappings":";;;;;UAQU;;EAER;;EAEA;;EAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiEc,iBAAiB,UAAU,UAAU,gBAAgB;;;;;;;;;;EAanB,qBAAA;;EAa1C,oBAAA,GAAA,QAAM,YAAY,mBAAiB;;EAsB/B,yBAAA,eAAM"}
|
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
import { useCallback, useState } from "react";
|
|
3
3
|
//#region src/hooks/use-slider-input.ts
|
|
4
4
|
/**
|
|
5
|
-
* Dual slider input management hook for React components
|
|
6
|
-
* Provides synchronized state management between range slider and number inputs
|
|
7
|
-
* with validation and boundary enforcement
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
5
|
* Hook for managing dual slider input with synchronized state
|
|
11
6
|
*
|
|
12
7
|
* This hook provides state management for components that need both
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-slider-input.js","names":[],"sources":["../../src/hooks/use-slider-input.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"use-slider-input.js","names":[],"sources":["../../src/hooks/use-slider-input.ts"],"sourcesContent":["\"use client\";\n\nimport type * as React from \"react\";\nimport { useCallback, useState } from \"react\";\n\n/**\n * Configuration options for the slider input hook\n */\ninterface UseSliderInputProps {\n /** Minimum allowed value for the range */\n minValue: number;\n /** Maximum allowed value for the range */\n maxValue: number;\n /** Initial values for the range [min, max] */\n initialValue: [number, number];\n}\n\n/**\n * Hook for managing dual slider input with synchronized state\n *\n * This hook provides state management for components that need both\n * a range slider and corresponding number inputs. It handles synchronization\n * between the two input types, validation, and boundary enforcement.\n *\n * Features:\n * - Synchronized slider and input values\n * - Automatic validation and boundary enforcement\n * - Prevents invalid range configurations (min > max)\n * - Optimized with useCallback for performance\n *\n * @param props - Configuration options for the hook\n * @returns Object containing state and handlers for slider and inputs\n *\n * @example\n * ```tsx\n * function PriceRangeFilter() {\n * const {\n * sliderValues,\n * inputValues,\n * handleSliderChange,\n * handleInputChange,\n * validateAndUpdateValue\n * } = useSliderInput({\n * minValue: 0,\n * maxValue: 1000,\n * initialValue: [100, 500]\n * });\n *\n * return (\n * <div className=\"price-range\">\n * <div className=\"inputs\">\n * <input\n * type=\"number\"\n * value={inputValues[0]}\n * onChange={(e) => handleInputChange(e, 0)}\n * onBlur={() => validateAndUpdateValue(inputValues[0], 0)}\n * placeholder=\"Min price\"\n * />\n * <input\n * type=\"number\"\n * value={inputValues[1]}\n * onChange={(e) => handleInputChange(e, 1)}\n * onBlur={() => validateAndUpdateValue(inputValues[1], 1)}\n * placeholder=\"Max price\"\n * />\n * </div>\n *\n * <Slider\n * value={sliderValues}\n * onValueChange={handleSliderChange}\n * min={0}\n * max={1000}\n * step={10}\n * />\n * </div>\n * );\n * }\n * ```\n */\nexport function useSliderInput({ minValue, maxValue, initialValue }: UseSliderInputProps) {\n /** State for slider component values */\n const [sliderValues, setSliderValues] = useState<[number, number]>(initialValue);\n\n /** State for input field values (may temporarily differ from slider) */\n const [inputValues, setInputValues] = useState<[number, number]>(initialValue);\n\n /**\n * Handle slider value changes and sync with input values\n * Called when user interacts with the range slider\n *\n * @param values - New slider values [min, max]\n */\n const handleSliderChange = useCallback((values: [number, number]) => {\n setSliderValues(values);\n setInputValues(values); // Keep inputs in sync with slider\n }, []);\n\n /**\n * Handle input field changes\n * Updates input state without immediately affecting slider\n *\n * @param e - Input change event\n * @param index - Index of the input (0 for min, 1 for max)\n */\n const handleInputChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>, index: 0 | 1) => {\n const newValue = parseFloat(e.target.value);\n\n // Only update if the value is a valid number\n if (!Number.isNaN(newValue)) {\n const updatedInputs = [...inputValues] as [number, number];\n updatedInputs[index] = newValue;\n setInputValues(updatedInputs);\n }\n },\n [inputValues],\n );\n\n /**\n * Validate and update slider values from input\n * Called when input loses focus or user presses Enter\n * Enforces boundaries and prevents invalid ranges\n *\n * @param value - Value to validate and apply\n * @param index - Index of the value (0 for min, 1 for max)\n */\n const validateAndUpdateValue = useCallback(\n (value: number, index: 0 | 1) => {\n const updatedSlider = [...sliderValues] as [number, number];\n\n if (index === 0) {\n // Validate minimum value\n // Ensure it's not less than minValue and not greater than current max\n updatedSlider[0] = Math.max(minValue, Math.min(value, sliderValues[1]));\n } else {\n // Validate maximum value\n // Ensure it's not greater than maxValue and not less than current min\n updatedSlider[1] = Math.min(maxValue, Math.max(value, sliderValues[0]));\n }\n\n // Update both slider and input values to validated values\n setSliderValues(updatedSlider);\n setInputValues(updatedSlider);\n },\n [sliderValues, minValue, maxValue],\n );\n\n return {\n /** Function to manually set slider values */\n setSliderValues,\n /** Function to manually set input values */\n setInputValues,\n /** Current slider values [min, max] */\n sliderValues,\n /** Current input values [min, max] */\n inputValues,\n /** Handler for slider value changes */\n handleSliderChange,\n /** Handler for input field changes */\n handleInputChange,\n /** Function to validate and update values from inputs */\n validateAndUpdateValue,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EA,SAAgB,eAAe,EAAE,UAAU,UAAU,gBAAqC;;CAExF,MAAM,CAAC,cAAc,mBAAmB,SAA2B,YAAY;;CAG/E,MAAM,CAAC,aAAa,kBAAkB,SAA2B,YAAY;CA+D7E,OAAO;;EAEL;;EAEA;;EAEA;;EAEA;;EAEA,oBAjEyB,aAAa,WAA6B;GACnE,gBAAgB,MAAM;GACtB,eAAe,MAAM;EACvB,GAAG,CAAC,CA8De;;EAEjB,mBAvDwB,aACvB,GAAwC,UAAiB;GACxD,MAAM,WAAW,WAAW,EAAE,OAAO,KAAK;GAG1C,IAAI,CAAC,OAAO,MAAM,QAAQ,GAAG;IAC3B,MAAM,gBAAgB,CAAC,GAAG,WAAW;IACrC,cAAc,SAAS;IACvB,eAAe,aAAa;GAC9B;EACF,GACA,CAAC,WAAW,CA4CI;;EAEhB,wBAnC6B,aAC5B,OAAe,UAAiB;GAC/B,MAAM,gBAAgB,CAAC,GAAG,YAAY;GAEtC,IAAI,UAAU,GAGZ,cAAc,KAAK,KAAK,IAAI,UAAU,KAAK,IAAI,OAAO,aAAa,EAAE,CAAC;QAItE,cAAc,KAAK,KAAK,IAAI,UAAU,KAAK,IAAI,OAAO,aAAa,EAAE,CAAC;GAIxE,gBAAgB,aAAa;GAC7B,eAAe,aAAa;EAC9B,GACA;GAAC;GAAc;GAAU;EAAQ,CAiBZ;CACvB;AACF"}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
//#region src/hooks/use-viewport.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Viewport dimensions tracking hook for React components
|
|
4
|
-
* Provides real-time viewport width and height with automatic updates
|
|
5
|
-
* on window resize events with SSR-safe implementation
|
|
6
|
-
*/
|
|
7
2
|
/**
|
|
8
3
|
* Type definition for viewport dimensions
|
|
9
4
|
* Returns tuple of [width, height] in pixels
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-viewport.d.ts","names":[],"sources":["../../src/hooks/use-viewport.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-viewport.d.ts","names":[],"sources":["../../src/hooks/use-viewport.ts"],"mappings":";;;;;KAQK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA2DQ,mBAAkB"}
|
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
3
|
//#region src/hooks/use-viewport.ts
|
|
4
4
|
/**
|
|
5
|
-
* Viewport dimensions tracking hook for React components
|
|
6
|
-
* Provides real-time viewport width and height with automatic updates
|
|
7
|
-
* on window resize events with SSR-safe implementation
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
5
|
* Hook to track viewport dimensions with real-time updates
|
|
11
6
|
*
|
|
12
7
|
* This hook provides the current viewport dimensions and automatically
|