@zentauri-ui/zentauri-components 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -21
- package/dist/chunk-2VQJ6OIL.js +31 -0
- package/dist/chunk-2VQJ6OIL.js.map +1 -0
- package/dist/chunk-73VCO5TE.mjs +29 -0
- package/dist/chunk-73VCO5TE.mjs.map +1 -0
- package/dist/chunk-BSWYZTYK.js +31 -0
- package/dist/chunk-BSWYZTYK.js.map +1 -0
- package/dist/chunk-CY5BQKRZ.mjs +29 -0
- package/dist/chunk-CY5BQKRZ.mjs.map +1 -0
- package/dist/chunk-DFEZH7TC.mjs +27 -0
- package/dist/chunk-DFEZH7TC.mjs.map +1 -0
- package/dist/chunk-FT2LMA66.mjs +25 -0
- package/dist/chunk-FT2LMA66.mjs.map +1 -0
- package/dist/chunk-JE3PD5ZA.js +107 -0
- package/dist/chunk-JE3PD5ZA.js.map +1 -0
- package/dist/chunk-JXCTEAXD.js +38 -0
- package/dist/chunk-JXCTEAXD.js.map +1 -0
- package/dist/chunk-LIJ6BDGP.mjs +36 -0
- package/dist/chunk-LIJ6BDGP.mjs.map +1 -0
- package/dist/chunk-PMAF6FBF.mjs +37 -0
- package/dist/chunk-PMAF6FBF.mjs.map +1 -0
- package/dist/chunk-TZ2JVWTZ.mjs +104 -0
- package/dist/chunk-TZ2JVWTZ.mjs.map +1 -0
- package/dist/chunk-UIYFEP3I.js +39 -0
- package/dist/chunk-UIYFEP3I.js.map +1 -0
- package/dist/chunk-UOZYPWDZ.js +32 -0
- package/dist/chunk-UOZYPWDZ.js.map +1 -0
- package/dist/chunk-WL5I7RVS.mjs +54 -0
- package/dist/chunk-WL5I7RVS.mjs.map +1 -0
- package/dist/chunk-WP7GYBRI.js +27 -0
- package/dist/chunk-WP7GYBRI.js.map +1 -0
- package/dist/chunk-YPLVTUYL.js +56 -0
- package/dist/chunk-YPLVTUYL.js.map +1 -0
- package/dist/hooks/useBodyScrollLock.d.mts +14 -0
- package/dist/hooks/useBodyScrollLock.d.ts +14 -0
- package/dist/hooks/useBodyScrollLock.js +13 -0
- package/dist/hooks/useBodyScrollLock.js.map +1 -0
- package/dist/hooks/useBodyScrollLock.mjs +4 -0
- package/dist/hooks/useBodyScrollLock.mjs.map +1 -0
- package/dist/hooks/useClickOutside.d.mts +23 -0
- package/dist/hooks/useClickOutside.d.ts +23 -0
- package/dist/hooks/useClickOutside.js +13 -0
- package/dist/hooks/useClickOutside.js.map +1 -0
- package/dist/hooks/useClickOutside.mjs +4 -0
- package/dist/hooks/useClickOutside.mjs.map +1 -0
- package/dist/hooks/useClipboard.d.mts +22 -0
- package/dist/hooks/useClipboard.d.ts +22 -0
- package/dist/hooks/useClipboard.js +51 -0
- package/dist/hooks/useClipboard.js.map +1 -0
- package/dist/hooks/useClipboard.mjs +49 -0
- package/dist/hooks/useClipboard.mjs.map +1 -0
- package/dist/hooks/useControllableState.d.mts +22 -0
- package/dist/hooks/useControllableState.d.ts +22 -0
- package/dist/hooks/useControllableState.js +13 -0
- package/dist/hooks/useControllableState.js.map +1 -0
- package/dist/hooks/useControllableState.mjs +4 -0
- package/dist/hooks/useControllableState.mjs.map +1 -0
- package/dist/hooks/useDebouncedValue.d.mts +14 -0
- package/dist/hooks/useDebouncedValue.d.ts +14 -0
- package/dist/hooks/useDebouncedValue.js +22 -0
- package/dist/hooks/useDebouncedValue.js.map +1 -0
- package/dist/hooks/useDebouncedValue.mjs +20 -0
- package/dist/hooks/useDebouncedValue.mjs.map +1 -0
- package/dist/hooks/useDisclosure.d.mts +25 -0
- package/dist/hooks/useDisclosure.d.ts +25 -0
- package/dist/hooks/useDisclosure.js +37 -0
- package/dist/hooks/useDisclosure.js.map +1 -0
- package/dist/hooks/useDisclosure.mjs +35 -0
- package/dist/hooks/useDisclosure.mjs.map +1 -0
- package/dist/hooks/useDocumentTitle.d.mts +19 -0
- package/dist/hooks/useDocumentTitle.d.ts +19 -0
- package/dist/hooks/useDocumentTitle.js +40 -0
- package/dist/hooks/useDocumentTitle.js.map +1 -0
- package/dist/hooks/useDocumentTitle.mjs +38 -0
- package/dist/hooks/useDocumentTitle.mjs.map +1 -0
- package/dist/hooks/useFocusManagement.d.mts +24 -0
- package/dist/hooks/useFocusManagement.d.ts +24 -0
- package/dist/hooks/useFocusManagement.js +14 -0
- package/dist/hooks/useFocusManagement.js.map +1 -0
- package/dist/hooks/useFocusManagement.mjs +5 -0
- package/dist/hooks/useFocusManagement.mjs.map +1 -0
- package/dist/hooks/useHover.d.mts +15 -0
- package/dist/hooks/useHover.d.ts +15 -0
- package/dist/hooks/useHover.js +37 -0
- package/dist/hooks/useHover.js.map +1 -0
- package/dist/hooks/useHover.mjs +35 -0
- package/dist/hooks/useHover.mjs.map +1 -0
- package/dist/hooks/useInView.d.mts +19 -0
- package/dist/hooks/useInView.d.ts +19 -0
- package/dist/hooks/useInView.js +15 -0
- package/dist/hooks/useInView.js.map +1 -0
- package/dist/hooks/useInView.mjs +13 -0
- package/dist/hooks/useInView.mjs.map +1 -0
- package/dist/hooks/useIntersectionObserver.d.mts +19 -0
- package/dist/hooks/useIntersectionObserver.d.ts +19 -0
- package/dist/hooks/useIntersectionObserver.js +13 -0
- package/dist/hooks/useIntersectionObserver.js.map +1 -0
- package/dist/hooks/useIntersectionObserver.mjs +4 -0
- package/dist/hooks/useIntersectionObserver.mjs.map +1 -0
- package/dist/hooks/useIsMounted.d.mts +11 -0
- package/dist/hooks/useIsMounted.d.ts +11 -0
- package/dist/hooks/useIsMounted.js +20 -0
- package/dist/hooks/useIsMounted.js.map +1 -0
- package/dist/hooks/useIsMounted.mjs +18 -0
- package/dist/hooks/useIsMounted.mjs.map +1 -0
- package/dist/hooks/useIsomorphicLayoutEffect.d.mts +11 -0
- package/dist/hooks/useIsomorphicLayoutEffect.d.ts +11 -0
- package/dist/hooks/useIsomorphicLayoutEffect.js +11 -0
- package/dist/hooks/useIsomorphicLayoutEffect.js.map +1 -0
- package/dist/hooks/useIsomorphicLayoutEffect.mjs +9 -0
- package/dist/hooks/useIsomorphicLayoutEffect.mjs.map +1 -0
- package/dist/hooks/useLocalStorage.d.mts +22 -0
- package/dist/hooks/useLocalStorage.d.ts +22 -0
- package/dist/hooks/useLocalStorage.js +84 -0
- package/dist/hooks/useLocalStorage.js.map +1 -0
- package/dist/hooks/useLocalStorage.mjs +82 -0
- package/dist/hooks/useLocalStorage.mjs.map +1 -0
- package/dist/hooks/useMediaQuery.d.mts +13 -0
- package/dist/hooks/useMediaQuery.d.ts +13 -0
- package/dist/hooks/useMediaQuery.js +13 -0
- package/dist/hooks/useMediaQuery.js.map +1 -0
- package/dist/hooks/useMediaQuery.mjs +4 -0
- package/dist/hooks/useMediaQuery.mjs.map +1 -0
- package/dist/hooks/useNetworkStatus.d.mts +10 -0
- package/dist/hooks/useNetworkStatus.d.ts +10 -0
- package/dist/hooks/useNetworkStatus.js +30 -0
- package/dist/hooks/useNetworkStatus.js.map +1 -0
- package/dist/hooks/useNetworkStatus.mjs +28 -0
- package/dist/hooks/useNetworkStatus.mjs.map +1 -0
- package/dist/hooks/usePageVisibility.d.mts +10 -0
- package/dist/hooks/usePageVisibility.d.ts +10 -0
- package/dist/hooks/usePageVisibility.js +28 -0
- package/dist/hooks/usePageVisibility.js.map +1 -0
- package/dist/hooks/usePageVisibility.mjs +26 -0
- package/dist/hooks/usePageVisibility.mjs.map +1 -0
- package/dist/hooks/usePagination.d.mts +5 -0
- package/dist/hooks/usePagination.d.ts +5 -0
- package/dist/hooks/usePagination.js +18 -0
- package/dist/hooks/usePagination.js.map +1 -0
- package/dist/hooks/usePagination.mjs +5 -0
- package/dist/hooks/usePagination.mjs.map +1 -0
- package/dist/hooks/usePrefersColorScheme.d.mts +10 -0
- package/dist/hooks/usePrefersColorScheme.d.ts +10 -0
- package/dist/hooks/usePrefersColorScheme.js +17 -0
- package/dist/hooks/usePrefersColorScheme.js.map +1 -0
- package/dist/hooks/usePrefersColorScheme.mjs +15 -0
- package/dist/hooks/usePrefersColorScheme.mjs.map +1 -0
- package/dist/hooks/usePrefersReducedMotion.d.mts +10 -0
- package/dist/hooks/usePrefersReducedMotion.d.ts +10 -0
- package/dist/hooks/usePrefersReducedMotion.js +13 -0
- package/dist/hooks/usePrefersReducedMotion.js.map +1 -0
- package/dist/hooks/usePrefersReducedMotion.mjs +11 -0
- package/dist/hooks/usePrefersReducedMotion.mjs.map +1 -0
- package/dist/hooks/useResizeObserver.d.mts +23 -0
- package/dist/hooks/useResizeObserver.d.ts +23 -0
- package/dist/hooks/useResizeObserver.js +38 -0
- package/dist/hooks/useResizeObserver.js.map +1 -0
- package/dist/hooks/useResizeObserver.mjs +36 -0
- package/dist/hooks/useResizeObserver.mjs.map +1 -0
- package/dist/hooks/useSessionStorage.d.mts +22 -0
- package/dist/hooks/useSessionStorage.d.ts +22 -0
- package/dist/hooks/useSessionStorage.js +58 -0
- package/dist/hooks/useSessionStorage.js.map +1 -0
- package/dist/hooks/useSessionStorage.mjs +56 -0
- package/dist/hooks/useSessionStorage.mjs.map +1 -0
- package/dist/hooks/useThrottledCallback.d.mts +14 -0
- package/dist/hooks/useThrottledCallback.d.ts +14 -0
- package/dist/hooks/useThrottledCallback.js +27 -0
- package/dist/hooks/useThrottledCallback.js.map +1 -0
- package/dist/hooks/useThrottledCallback.mjs +25 -0
- package/dist/hooks/useThrottledCallback.mjs.map +1 -0
- package/dist/hooks/useToggle.d.mts +9 -0
- package/dist/hooks/useToggle.d.ts +9 -0
- package/dist/hooks/useToggle.js +20 -0
- package/dist/hooks/useToggle.js.map +1 -0
- package/dist/hooks/useToggle.mjs +18 -0
- package/dist/hooks/useToggle.mjs.map +1 -0
- package/dist/hooks/useWindowSize.d.mts +14 -0
- package/dist/hooks/useWindowSize.d.ts +14 -0
- package/dist/hooks/useWindowSize.js +30 -0
- package/dist/hooks/useWindowSize.js.map +1 -0
- package/dist/hooks/useWindowSize.mjs +28 -0
- package/dist/hooks/useWindowSize.mjs.map +1 -0
- package/dist/hooks/utils.d.mts +8 -0
- package/dist/hooks/utils.d.ts +8 -0
- package/dist/hooks/utils.js +24 -0
- package/dist/hooks/utils.js.map +1 -0
- package/dist/hooks/utils.mjs +3 -0
- package/dist/hooks/utils.mjs.map +1 -0
- package/dist/index-ClPu5gDp.d.ts +86 -0
- package/dist/index-D4p9fn1o.d.mts +86 -0
- package/dist/ui/accordion.js +5 -5
- package/dist/ui/accordion.mjs +1 -1
- package/dist/ui/alert.js +7 -7
- package/dist/ui/alert.mjs +1 -1
- package/dist/ui/avatar.js +6 -6
- package/dist/ui/avatar.js.map +1 -1
- package/dist/ui/avatar.mjs +1 -1
- package/dist/ui/avatar.mjs.map +1 -1
- package/dist/ui/badge.js +2 -2
- package/dist/ui/badge.mjs +1 -1
- package/dist/ui/breadcrumb.js +7 -7
- package/dist/ui/breadcrumb.mjs +1 -1
- package/dist/ui/buttons.js +3 -3
- package/dist/ui/buttons.mjs +1 -1
- package/dist/ui/card.js +7 -7
- package/dist/ui/card.js.map +1 -1
- package/dist/ui/card.mjs +1 -1
- package/dist/ui/card.mjs.map +1 -1
- package/dist/ui/divider.js +6 -6
- package/dist/ui/divider.mjs +1 -1
- package/dist/ui/drawer.js +15 -60
- package/dist/ui/drawer.js.map +1 -1
- package/dist/ui/drawer.mjs +9 -54
- package/dist/ui/drawer.mjs.map +1 -1
- package/dist/ui/dropdown.js +6 -13
- package/dist/ui/dropdown.js.map +1 -1
- package/dist/ui/dropdown.mjs +4 -11
- package/dist/ui/dropdown.mjs.map +1 -1
- package/dist/ui/empty-state.js +6 -6
- package/dist/ui/empty-state.js.map +1 -1
- package/dist/ui/empty-state.mjs +1 -1
- package/dist/ui/empty-state.mjs.map +1 -1
- package/dist/ui/file-upload.js +3 -3
- package/dist/ui/file-upload.mjs +1 -1
- package/dist/ui/inputs.js +3 -3
- package/dist/ui/inputs.mjs +1 -1
- package/dist/ui/modal.js +16 -61
- package/dist/ui/modal.js.map +1 -1
- package/dist/ui/modal.mjs +9 -54
- package/dist/ui/modal.mjs.map +1 -1
- package/dist/ui/pagination.d.mts +3 -81
- package/dist/ui/pagination.d.ts +3 -81
- package/dist/ui/pagination.js +13 -122
- package/dist/ui/pagination.js.map +1 -1
- package/dist/ui/pagination.mjs +5 -114
- package/dist/ui/pagination.mjs.map +1 -1
- package/dist/ui/progress.js +7 -10
- package/dist/ui/progress.js.map +1 -1
- package/dist/ui/progress.mjs +1 -4
- package/dist/ui/progress.mjs.map +1 -1
- package/dist/ui/select.js +6 -6
- package/dist/ui/select.mjs +1 -1
- package/dist/ui/skeleton.js +7 -7
- package/dist/ui/skeleton.mjs +1 -1
- package/dist/ui/slider.js +9 -9
- package/dist/ui/slider.js.map +1 -1
- package/dist/ui/slider.mjs +1 -1
- package/dist/ui/slider.mjs.map +1 -1
- package/dist/ui/spinner.js +24 -10
- package/dist/ui/spinner.js.map +1 -1
- package/dist/ui/spinner.mjs +17 -3
- package/dist/ui/spinner.mjs.map +1 -1
- package/dist/ui/stepper.js +6 -6
- package/dist/ui/stepper.mjs +1 -1
- package/dist/ui/table.js +9 -9
- package/dist/ui/table.js.map +1 -1
- package/dist/ui/table.mjs +1 -1
- package/dist/ui/table.mjs.map +1 -1
- package/dist/ui/tabs.js +5 -5
- package/dist/ui/tabs.mjs +1 -1
- package/dist/ui/toast.js +7 -7
- package/dist/ui/toast.js.map +1 -1
- package/dist/ui/toast.mjs +1 -1
- package/dist/ui/toast.mjs.map +1 -1
- package/dist/ui/toggle.js +3 -3
- package/dist/ui/toggle.mjs +1 -1
- package/dist/ui/tooltip.js +2 -2
- package/dist/ui/tooltip.mjs +1 -1
- package/package.json +7 -2
- package/dist/chunk-B23TPTVG.mjs +0 -11
- package/dist/chunk-B23TPTVG.mjs.map +0 -1
- package/dist/chunk-WZ2GOU2J.js +0 -13
- package/dist/chunk-WZ2GOU2J.js.map +0 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
// src/hooks/useHover/useHover.ts
|
|
7
|
+
function useHover() {
|
|
8
|
+
const [element, setElement] = react.useState(null);
|
|
9
|
+
const [hovered, setHovered] = react.useState(false);
|
|
10
|
+
const setRef = react.useCallback((node) => {
|
|
11
|
+
setElement(node);
|
|
12
|
+
}, []);
|
|
13
|
+
react.useEffect(() => {
|
|
14
|
+
if (element == null) {
|
|
15
|
+
setHovered(false);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const onEnter = () => {
|
|
19
|
+
setHovered(true);
|
|
20
|
+
};
|
|
21
|
+
const onLeave = () => {
|
|
22
|
+
setHovered(false);
|
|
23
|
+
};
|
|
24
|
+
element.addEventListener("pointerenter", onEnter);
|
|
25
|
+
element.addEventListener("pointerleave", onLeave);
|
|
26
|
+
return () => {
|
|
27
|
+
setHovered(false);
|
|
28
|
+
element.removeEventListener("pointerenter", onEnter);
|
|
29
|
+
element.removeEventListener("pointerleave", onLeave);
|
|
30
|
+
};
|
|
31
|
+
}, [element]);
|
|
32
|
+
return [setRef, hovered];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
exports.useHover = useHover;
|
|
36
|
+
//# sourceMappingURL=useHover.js.map
|
|
37
|
+
//# sourceMappingURL=useHover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useHover/useHover.ts"],"names":["useState","useCallback","useEffect"],"mappings":";;;;;AAeO,SAAS,QAAA,GAA6D;AAC3E,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAIA,eAAmB,IAAI,CAAA;AACrD,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAIA,eAAS,KAAK,CAAA;AAE5C,EAAA,MAAM,MAAA,GAASC,iBAAA,CAAY,CAAC,IAAA,KAAmB;AAC7C,IAAA,UAAA,CAAW,IAAI,CAAA;AAAA,EACjB,CAAA,EAAG,EAAE,CAAA;AAEL,EAAAC,eAAA,CAAU,MAAM;AACd,IAAA,IAAI,WAAW,IAAA,EAAM;AACnB,MAAA,UAAA,CAAW,KAAK,CAAA;AAChB,MAAA;AAAA,IACF;AACA,IAAA,MAAM,UAAU,MAAM;AACpB,MAAA,UAAA,CAAW,IAAI,CAAA;AAAA,IACjB,CAAA;AACA,IAAA,MAAM,UAAU,MAAM;AACpB,MAAA,UAAA,CAAW,KAAK,CAAA;AAAA,IAClB,CAAA;AACA,IAAA,OAAA,CAAQ,gBAAA,CAAiB,gBAAgB,OAAO,CAAA;AAChD,IAAA,OAAA,CAAQ,gBAAA,CAAiB,gBAAgB,OAAO,CAAA;AAChD,IAAA,OAAO,MAAM;AACX,MAAA,UAAA,CAAW,KAAK,CAAA;AAChB,MAAA,OAAA,CAAQ,mBAAA,CAAoB,gBAAgB,OAAO,CAAA;AACnD,MAAA,OAAA,CAAQ,mBAAA,CAAoB,gBAAgB,OAAO,CAAA;AAAA,IACrD,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,OAAO,CAAC,CAAA;AAEZ,EAAA,OAAO,CAAC,QAAQ,OAAO,CAAA;AACzB","file":"useHover.js","sourcesContent":["\"use client\";\n\nimport type { RefCallback } from \"react\";\nimport { useCallback, useEffect, useState } from \"react\";\n\n/**\n * Tracks pointer hover state for a single DOM node using `pointerenter` / `pointerleave`.\n *\n * When the ref target changes (or unmounts), hover is cleared so state does not stay `true` after\n * retargeting without a `pointerleave` on the previous node.\n *\n * @typeParam T - HTMLElement subtype for the ref callback (e.g. `HTMLDivElement`).\n * @returns A tuple `[setRef, hovered]` where `setRef` is a callback ref to attach to the target element\n * and `hovered` is `true` while the pointer is over that element (primary button agnostic).\n */\nexport function useHover<T extends HTMLElement>(): [RefCallback<T>, boolean] {\n const [element, setElement] = useState<T | null>(null);\n const [hovered, setHovered] = useState(false);\n\n const setRef = useCallback((node: T | null) => {\n setElement(node);\n }, []);\n\n useEffect(() => {\n if (element == null) {\n setHovered(false);\n return;\n }\n const onEnter = () => {\n setHovered(true);\n };\n const onLeave = () => {\n setHovered(false);\n };\n element.addEventListener(\"pointerenter\", onEnter);\n element.addEventListener(\"pointerleave\", onLeave);\n return () => {\n setHovered(false);\n element.removeEventListener(\"pointerenter\", onEnter);\n element.removeEventListener(\"pointerleave\", onLeave);\n };\n }, [element]);\n\n return [setRef, hovered];\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
// src/hooks/useHover/useHover.ts
|
|
5
|
+
function useHover() {
|
|
6
|
+
const [element, setElement] = useState(null);
|
|
7
|
+
const [hovered, setHovered] = useState(false);
|
|
8
|
+
const setRef = useCallback((node) => {
|
|
9
|
+
setElement(node);
|
|
10
|
+
}, []);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (element == null) {
|
|
13
|
+
setHovered(false);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const onEnter = () => {
|
|
17
|
+
setHovered(true);
|
|
18
|
+
};
|
|
19
|
+
const onLeave = () => {
|
|
20
|
+
setHovered(false);
|
|
21
|
+
};
|
|
22
|
+
element.addEventListener("pointerenter", onEnter);
|
|
23
|
+
element.addEventListener("pointerleave", onLeave);
|
|
24
|
+
return () => {
|
|
25
|
+
setHovered(false);
|
|
26
|
+
element.removeEventListener("pointerenter", onEnter);
|
|
27
|
+
element.removeEventListener("pointerleave", onLeave);
|
|
28
|
+
};
|
|
29
|
+
}, [element]);
|
|
30
|
+
return [setRef, hovered];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { useHover };
|
|
34
|
+
//# sourceMappingURL=useHover.mjs.map
|
|
35
|
+
//# sourceMappingURL=useHover.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useHover/useHover.ts"],"names":[],"mappings":";;;AAeO,SAAS,QAAA,GAA6D;AAC3E,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAmB,IAAI,CAAA;AACrD,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAS,KAAK,CAAA;AAE5C,EAAA,MAAM,MAAA,GAAS,WAAA,CAAY,CAAC,IAAA,KAAmB;AAC7C,IAAA,UAAA,CAAW,IAAI,CAAA;AAAA,EACjB,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,WAAW,IAAA,EAAM;AACnB,MAAA,UAAA,CAAW,KAAK,CAAA;AAChB,MAAA;AAAA,IACF;AACA,IAAA,MAAM,UAAU,MAAM;AACpB,MAAA,UAAA,CAAW,IAAI,CAAA;AAAA,IACjB,CAAA;AACA,IAAA,MAAM,UAAU,MAAM;AACpB,MAAA,UAAA,CAAW,KAAK,CAAA;AAAA,IAClB,CAAA;AACA,IAAA,OAAA,CAAQ,gBAAA,CAAiB,gBAAgB,OAAO,CAAA;AAChD,IAAA,OAAA,CAAQ,gBAAA,CAAiB,gBAAgB,OAAO,CAAA;AAChD,IAAA,OAAO,MAAM;AACX,MAAA,UAAA,CAAW,KAAK,CAAA;AAChB,MAAA,OAAA,CAAQ,mBAAA,CAAoB,gBAAgB,OAAO,CAAA;AACnD,MAAA,OAAA,CAAQ,mBAAA,CAAoB,gBAAgB,OAAO,CAAA;AAAA,IACrD,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,OAAO,CAAC,CAAA;AAEZ,EAAA,OAAO,CAAC,QAAQ,OAAO,CAAA;AACzB","file":"useHover.mjs","sourcesContent":["\"use client\";\n\nimport type { RefCallback } from \"react\";\nimport { useCallback, useEffect, useState } from \"react\";\n\n/**\n * Tracks pointer hover state for a single DOM node using `pointerenter` / `pointerleave`.\n *\n * When the ref target changes (or unmounts), hover is cleared so state does not stay `true` after\n * retargeting without a `pointerleave` on the previous node.\n *\n * @typeParam T - HTMLElement subtype for the ref callback (e.g. `HTMLDivElement`).\n * @returns A tuple `[setRef, hovered]` where `setRef` is a callback ref to attach to the target element\n * and `hovered` is `true` while the pointer is over that element (primary button agnostic).\n */\nexport function useHover<T extends HTMLElement>(): [RefCallback<T>, boolean] {\n const [element, setElement] = useState<T | null>(null);\n const [hovered, setHovered] = useState(false);\n\n const setRef = useCallback((node: T | null) => {\n setElement(node);\n }, []);\n\n useEffect(() => {\n if (element == null) {\n setHovered(false);\n return;\n }\n const onEnter = () => {\n setHovered(true);\n };\n const onLeave = () => {\n setHovered(false);\n };\n element.addEventListener(\"pointerenter\", onEnter);\n element.addEventListener(\"pointerleave\", onLeave);\n return () => {\n setHovered(false);\n element.removeEventListener(\"pointerenter\", onEnter);\n element.removeEventListener(\"pointerleave\", onLeave);\n };\n }, [element]);\n\n return [setRef, hovered];\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RefCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
type UseInViewParams = IntersectionObserverInit & {
|
|
4
|
+
/** When `false`, no observer is attached (useful to pause work when off-screen lists are virtualized). */
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Convenience wrapper around {@link useIntersectionObserver} that exposes only a boolean `inView` flag.
|
|
9
|
+
*
|
|
10
|
+
* `inView` is `true` when the latest `IntersectionObserverEntry.isIntersecting` is truthy; otherwise `false`.
|
|
11
|
+
* Accepts the same `root`, `rootMargin`, `threshold`, and `enabled` options as the underlying observer.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam T - Observed element type.
|
|
14
|
+
* @param params - IntersectionObserver options plus optional `enabled` flag.
|
|
15
|
+
* @returns `[setRef, inView]` callback ref and intersection boolean.
|
|
16
|
+
*/
|
|
17
|
+
declare function useInView<T extends Element>(params?: UseInViewParams): [RefCallback<T>, boolean];
|
|
18
|
+
|
|
19
|
+
export { type UseInViewParams, useInView };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RefCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
type UseInViewParams = IntersectionObserverInit & {
|
|
4
|
+
/** When `false`, no observer is attached (useful to pause work when off-screen lists are virtualized). */
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Convenience wrapper around {@link useIntersectionObserver} that exposes only a boolean `inView` flag.
|
|
9
|
+
*
|
|
10
|
+
* `inView` is `true` when the latest `IntersectionObserverEntry.isIntersecting` is truthy; otherwise `false`.
|
|
11
|
+
* Accepts the same `root`, `rootMargin`, `threshold`, and `enabled` options as the underlying observer.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam T - Observed element type.
|
|
14
|
+
* @param params - IntersectionObserver options plus optional `enabled` flag.
|
|
15
|
+
* @returns `[setRef, inView]` callback ref and intersection boolean.
|
|
16
|
+
*/
|
|
17
|
+
declare function useInView<T extends Element>(params?: UseInViewParams): [RefCallback<T>, boolean];
|
|
18
|
+
|
|
19
|
+
export { type UseInViewParams, useInView };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var chunkJXCTEAXD_js = require('../chunk-JXCTEAXD.js');
|
|
5
|
+
|
|
6
|
+
// src/hooks/useInView/useInView.ts
|
|
7
|
+
function useInView(params = {}) {
|
|
8
|
+
const [setRef, entry] = chunkJXCTEAXD_js.useIntersectionObserver(params);
|
|
9
|
+
const inView = Boolean(entry?.isIntersecting);
|
|
10
|
+
return [setRef, inView];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useInView = useInView;
|
|
14
|
+
//# sourceMappingURL=useInView.js.map
|
|
15
|
+
//# sourceMappingURL=useInView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useInView/useInView.ts"],"names":["useIntersectionObserver"],"mappings":";;;;;AAqBO,SAAS,SAAA,CACd,MAAA,GAA0B,EAAC,EACA;AAC3B,EAAA,MAAM,CAAC,MAAA,EAAQ,KAAK,CAAA,GAAIA,yCAA2B,MAAM,CAAA;AACzD,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,KAAA,EAAO,cAAc,CAAA;AAC5C,EAAA,OAAO,CAAC,QAAQ,MAAM,CAAA;AACxB","file":"useInView.js","sourcesContent":["\"use client\";\n\nimport type { RefCallback } from \"react\";\n\nimport { useIntersectionObserver } from \"../useIntersectionObserver\";\n\nexport type UseInViewParams = IntersectionObserverInit & {\n /** When `false`, no observer is attached (useful to pause work when off-screen lists are virtualized). */\n enabled?: boolean;\n};\n\n/**\n * Convenience wrapper around {@link useIntersectionObserver} that exposes only a boolean `inView` flag.\n *\n * `inView` is `true` when the latest `IntersectionObserverEntry.isIntersecting` is truthy; otherwise `false`.\n * Accepts the same `root`, `rootMargin`, `threshold`, and `enabled` options as the underlying observer.\n *\n * @typeParam T - Observed element type.\n * @param params - IntersectionObserver options plus optional `enabled` flag.\n * @returns `[setRef, inView]` callback ref and intersection boolean.\n */\nexport function useInView<T extends Element>(\n params: UseInViewParams = {},\n): [RefCallback<T>, boolean] {\n const [setRef, entry] = useIntersectionObserver<T>(params);\n const inView = Boolean(entry?.isIntersecting);\n return [setRef, inView];\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useIntersectionObserver } from '../chunk-LIJ6BDGP.mjs';
|
|
3
|
+
|
|
4
|
+
// src/hooks/useInView/useInView.ts
|
|
5
|
+
function useInView(params = {}) {
|
|
6
|
+
const [setRef, entry] = useIntersectionObserver(params);
|
|
7
|
+
const inView = Boolean(entry?.isIntersecting);
|
|
8
|
+
return [setRef, inView];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { useInView };
|
|
12
|
+
//# sourceMappingURL=useInView.mjs.map
|
|
13
|
+
//# sourceMappingURL=useInView.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useInView/useInView.ts"],"names":[],"mappings":";;;AAqBO,SAAS,SAAA,CACd,MAAA,GAA0B,EAAC,EACA;AAC3B,EAAA,MAAM,CAAC,MAAA,EAAQ,KAAK,CAAA,GAAI,wBAA2B,MAAM,CAAA;AACzD,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,KAAA,EAAO,cAAc,CAAA;AAC5C,EAAA,OAAO,CAAC,QAAQ,MAAM,CAAA;AACxB","file":"useInView.mjs","sourcesContent":["\"use client\";\n\nimport type { RefCallback } from \"react\";\n\nimport { useIntersectionObserver } from \"../useIntersectionObserver\";\n\nexport type UseInViewParams = IntersectionObserverInit & {\n /** When `false`, no observer is attached (useful to pause work when off-screen lists are virtualized). */\n enabled?: boolean;\n};\n\n/**\n * Convenience wrapper around {@link useIntersectionObserver} that exposes only a boolean `inView` flag.\n *\n * `inView` is `true` when the latest `IntersectionObserverEntry.isIntersecting` is truthy; otherwise `false`.\n * Accepts the same `root`, `rootMargin`, `threshold`, and `enabled` options as the underlying observer.\n *\n * @typeParam T - Observed element type.\n * @param params - IntersectionObserver options plus optional `enabled` flag.\n * @returns `[setRef, inView]` callback ref and intersection boolean.\n */\nexport function useInView<T extends Element>(\n params: UseInViewParams = {},\n): [RefCallback<T>, boolean] {\n const [setRef, entry] = useIntersectionObserver<T>(params);\n const inView = Boolean(entry?.isIntersecting);\n return [setRef, inView];\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RefCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
type UseIntersectionObserverParams = IntersectionObserverInit & {
|
|
4
|
+
/** When `false`, disconnects the observer until re-enabled (saves work for hidden or inactive content). */
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Observes a single element with the browser `IntersectionObserver` API and exposes the latest entry.
|
|
9
|
+
*
|
|
10
|
+
* Returns a callback ref: assign it to the element to measure. When `enabled` is false or `IntersectionObserver`
|
|
11
|
+
* is undefined (unsupported environment), the effect is a no-op and `entry` may stay `undefined`.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam T - Observed element type.
|
|
14
|
+
* @param params - Standard `IntersectionObserverInit` fields plus optional `enabled` (default `true`).
|
|
15
|
+
* @returns `[setRef, entry]` where `entry` is the most recent callback record for the observed target.
|
|
16
|
+
*/
|
|
17
|
+
declare function useIntersectionObserver<T extends Element>(params?: UseIntersectionObserverParams): [RefCallback<T>, IntersectionObserverEntry | undefined];
|
|
18
|
+
|
|
19
|
+
export { type UseIntersectionObserverParams, useIntersectionObserver };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RefCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
type UseIntersectionObserverParams = IntersectionObserverInit & {
|
|
4
|
+
/** When `false`, disconnects the observer until re-enabled (saves work for hidden or inactive content). */
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Observes a single element with the browser `IntersectionObserver` API and exposes the latest entry.
|
|
9
|
+
*
|
|
10
|
+
* Returns a callback ref: assign it to the element to measure. When `enabled` is false or `IntersectionObserver`
|
|
11
|
+
* is undefined (unsupported environment), the effect is a no-op and `entry` may stay `undefined`.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam T - Observed element type.
|
|
14
|
+
* @param params - Standard `IntersectionObserverInit` fields plus optional `enabled` (default `true`).
|
|
15
|
+
* @returns `[setRef, entry]` where `entry` is the most recent callback record for the observed target.
|
|
16
|
+
*/
|
|
17
|
+
declare function useIntersectionObserver<T extends Element>(params?: UseIntersectionObserverParams): [RefCallback<T>, IntersectionObserverEntry | undefined];
|
|
18
|
+
|
|
19
|
+
export { type UseIntersectionObserverParams, useIntersectionObserver };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var chunkJXCTEAXD_js = require('../chunk-JXCTEAXD.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "useIntersectionObserver", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkJXCTEAXD_js.useIntersectionObserver; }
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=useIntersectionObserver.js.map
|
|
13
|
+
//# sourceMappingURL=useIntersectionObserver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"useIntersectionObserver.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"useIntersectionObserver.mjs"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a stable function that reports whether the component is currently mounted.
|
|
3
|
+
*
|
|
4
|
+
* Useful to guard async completions (fetch, timers) so `setState` does not run after unmount.
|
|
5
|
+
* The returned function identity is stable across renders; it reads a ref updated in an effect.
|
|
6
|
+
*
|
|
7
|
+
* @returns `() => boolean` — `true` after mount until unmount cleanup runs.
|
|
8
|
+
*/
|
|
9
|
+
declare function useIsMounted(): () => boolean;
|
|
10
|
+
|
|
11
|
+
export { useIsMounted };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a stable function that reports whether the component is currently mounted.
|
|
3
|
+
*
|
|
4
|
+
* Useful to guard async completions (fetch, timers) so `setState` does not run after unmount.
|
|
5
|
+
* The returned function identity is stable across renders; it reads a ref updated in an effect.
|
|
6
|
+
*
|
|
7
|
+
* @returns `() => boolean` — `true` after mount until unmount cleanup runs.
|
|
8
|
+
*/
|
|
9
|
+
declare function useIsMounted(): () => boolean;
|
|
10
|
+
|
|
11
|
+
export { useIsMounted };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
// src/hooks/useIsMounted/useIsMounted.ts
|
|
7
|
+
function useIsMounted() {
|
|
8
|
+
const mounted = react.useRef(false);
|
|
9
|
+
react.useEffect(() => {
|
|
10
|
+
mounted.current = true;
|
|
11
|
+
return () => {
|
|
12
|
+
mounted.current = false;
|
|
13
|
+
};
|
|
14
|
+
}, []);
|
|
15
|
+
return react.useCallback(() => mounted.current, []);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.useIsMounted = useIsMounted;
|
|
19
|
+
//# sourceMappingURL=useIsMounted.js.map
|
|
20
|
+
//# sourceMappingURL=useIsMounted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useIsMounted/useIsMounted.ts"],"names":["useRef","useEffect","useCallback"],"mappings":";;;;;AAYO,SAAS,YAAA,GAA8B;AAC5C,EAAA,MAAM,OAAA,GAAUA,aAAO,KAAK,CAAA;AAC5B,EAAAC,eAAA,CAAU,MAAM;AACd,IAAA,OAAA,CAAQ,OAAA,GAAU,IAAA;AAClB,IAAA,OAAO,MAAM;AACX,MAAA,OAAA,CAAQ,OAAA,GAAU,KAAA;AAAA,IACpB,CAAA;AAAA,EACF,CAAA,EAAG,EAAE,CAAA;AACL,EAAA,OAAOC,iBAAA,CAAY,MAAM,OAAA,CAAQ,OAAA,EAAS,EAAE,CAAA;AAC9C","file":"useIsMounted.js","sourcesContent":["\"use client\";\n\nimport { useCallback, useEffect, useRef } from \"react\";\n\n/**\n * Returns a stable function that reports whether the component is currently mounted.\n *\n * Useful to guard async completions (fetch, timers) so `setState` does not run after unmount.\n * The returned function identity is stable across renders; it reads a ref updated in an effect.\n *\n * @returns `() => boolean` — `true` after mount until unmount cleanup runs.\n */\nexport function useIsMounted(): () => boolean {\n const mounted = useRef(false);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n return useCallback(() => mounted.current, []);\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRef, useEffect, useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
// src/hooks/useIsMounted/useIsMounted.ts
|
|
5
|
+
function useIsMounted() {
|
|
6
|
+
const mounted = useRef(false);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
mounted.current = true;
|
|
9
|
+
return () => {
|
|
10
|
+
mounted.current = false;
|
|
11
|
+
};
|
|
12
|
+
}, []);
|
|
13
|
+
return useCallback(() => mounted.current, []);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { useIsMounted };
|
|
17
|
+
//# sourceMappingURL=useIsMounted.mjs.map
|
|
18
|
+
//# sourceMappingURL=useIsMounted.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useIsMounted/useIsMounted.ts"],"names":[],"mappings":";;;AAYO,SAAS,YAAA,GAA8B;AAC5C,EAAA,MAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAC5B,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,OAAA,CAAQ,OAAA,GAAU,IAAA;AAClB,IAAA,OAAO,MAAM;AACX,MAAA,OAAA,CAAQ,OAAA,GAAU,KAAA;AAAA,IACpB,CAAA;AAAA,EACF,CAAA,EAAG,EAAE,CAAA;AACL,EAAA,OAAO,WAAA,CAAY,MAAM,OAAA,CAAQ,OAAA,EAAS,EAAE,CAAA;AAC9C","file":"useIsMounted.mjs","sourcesContent":["\"use client\";\n\nimport { useCallback, useEffect, useRef } from \"react\";\n\n/**\n * Returns a stable function that reports whether the component is currently mounted.\n *\n * Useful to guard async completions (fetch, timers) so `setState` does not run after unmount.\n * The returned function identity is stable across renders; it reads a ref updated in an effect.\n *\n * @returns `() => boolean` — `true` after mount until unmount cleanup runs.\n */\nexport function useIsMounted(): () => boolean {\n const mounted = useRef(false);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n return useCallback(() => mounted.current, []);\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runs `useLayoutEffect` in the browser and `useEffect` on the server to avoid SSR warnings.
|
|
5
|
+
*
|
|
6
|
+
* Use for DOM measurements or synchronous paint updates that must run before the browser paints,
|
|
7
|
+
* but only when the code path is safe on the client; on the server the timing matches `useEffect`.
|
|
8
|
+
*/
|
|
9
|
+
declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
|
|
10
|
+
|
|
11
|
+
export { useIsomorphicLayoutEffect };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runs `useLayoutEffect` in the browser and `useEffect` on the server to avoid SSR warnings.
|
|
5
|
+
*
|
|
6
|
+
* Use for DOM measurements or synchronous paint updates that must run before the browser paints,
|
|
7
|
+
* but only when the code path is safe on the client; on the server the timing matches `useEffect`.
|
|
8
|
+
*/
|
|
9
|
+
declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
|
|
10
|
+
|
|
11
|
+
export { useIsomorphicLayoutEffect };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
// src/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.ts
|
|
7
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? react.useLayoutEffect : react.useEffect;
|
|
8
|
+
|
|
9
|
+
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
10
|
+
//# sourceMappingURL=useIsomorphicLayoutEffect.js.map
|
|
11
|
+
//# sourceMappingURL=useIsomorphicLayoutEffect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.ts"],"names":["useLayoutEffect","useEffect"],"mappings":";;;;;AAUO,IAAM,yBAAA,GACX,OAAO,MAAA,KAAW,WAAA,GAAcA,qBAAA,GAAkBC","file":"useIsomorphicLayoutEffect.js","sourcesContent":["\"use client\";\n\nimport { useEffect, useLayoutEffect } from \"react\";\n\n/**\n * Runs `useLayoutEffect` in the browser and `useEffect` on the server to avoid SSR warnings.\n *\n * Use for DOM measurements or synchronous paint updates that must run before the browser paints,\n * but only when the code path is safe on the client; on the server the timing matches `useEffect`.\n */\nexport const useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLayoutEffect, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
// src/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.ts
|
|
5
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
6
|
+
|
|
7
|
+
export { useIsomorphicLayoutEffect };
|
|
8
|
+
//# sourceMappingURL=useIsomorphicLayoutEffect.mjs.map
|
|
9
|
+
//# sourceMappingURL=useIsomorphicLayoutEffect.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":";;;AAUO,IAAM,yBAAA,GACX,OAAO,MAAA,KAAW,WAAA,GAAc,eAAA,GAAkB","file":"useIsomorphicLayoutEffect.mjs","sourcesContent":["\"use client\";\n\nimport { useEffect, useLayoutEffect } from \"react\";\n\n/**\n * Runs `useLayoutEffect` in the browser and `useEffect` on the server to avoid SSR warnings.\n *\n * Use for DOM measurements or synchronous paint updates that must run before the browser paints,\n * but only when the code path is safe on the client; on the server the timing matches `useEffect`.\n */\nexport const useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type UseLocalStorageResult<T> = [
|
|
2
|
+
T,
|
|
3
|
+
(value: T | ((previous: T) => T)) => void,
|
|
4
|
+
() => void
|
|
5
|
+
];
|
|
6
|
+
/**
|
|
7
|
+
* Syncs JSON-serialized state with `window.localStorage` under a fixed key.
|
|
8
|
+
*
|
|
9
|
+
* - Initial read runs on the client; SSR uses `initialValue`.
|
|
10
|
+
* - `setValue` persists with `JSON.stringify` and updates React state; functional updates supported.
|
|
11
|
+
* - `remove` clears the key and resets state to `initialValue`.
|
|
12
|
+
* - Subscribes to the `storage` event so updates from other tabs (or same tab via `storage` dispatch quirks) reconcile.
|
|
13
|
+
* - Read/write failures (private mode, quota) fall back silently on read; write errors are swallowed except `remove` logs on failure.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam T - Stored value type; must be compatible with `JSON.stringify` / `parse`.
|
|
16
|
+
* @param key - `localStorage` key.
|
|
17
|
+
* @param initialValue - Fallback when missing, invalid JSON, or during SSR.
|
|
18
|
+
* @returns `[stored, setValue, remove]` tuple mirroring `useState` plus explicit removal.
|
|
19
|
+
*/
|
|
20
|
+
declare function useLocalStorage<T>(key: string, initialValue: T): UseLocalStorageResult<T>;
|
|
21
|
+
|
|
22
|
+
export { type UseLocalStorageResult, useLocalStorage };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type UseLocalStorageResult<T> = [
|
|
2
|
+
T,
|
|
3
|
+
(value: T | ((previous: T) => T)) => void,
|
|
4
|
+
() => void
|
|
5
|
+
];
|
|
6
|
+
/**
|
|
7
|
+
* Syncs JSON-serialized state with `window.localStorage` under a fixed key.
|
|
8
|
+
*
|
|
9
|
+
* - Initial read runs on the client; SSR uses `initialValue`.
|
|
10
|
+
* - `setValue` persists with `JSON.stringify` and updates React state; functional updates supported.
|
|
11
|
+
* - `remove` clears the key and resets state to `initialValue`.
|
|
12
|
+
* - Subscribes to the `storage` event so updates from other tabs (or same tab via `storage` dispatch quirks) reconcile.
|
|
13
|
+
* - Read/write failures (private mode, quota) fall back silently on read; write errors are swallowed except `remove` logs on failure.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam T - Stored value type; must be compatible with `JSON.stringify` / `parse`.
|
|
16
|
+
* @param key - `localStorage` key.
|
|
17
|
+
* @param initialValue - Fallback when missing, invalid JSON, or during SSR.
|
|
18
|
+
* @returns `[stored, setValue, remove]` tuple mirroring `useState` plus explicit removal.
|
|
19
|
+
*/
|
|
20
|
+
declare function useLocalStorage<T>(key: string, initialValue: T): UseLocalStorageResult<T>;
|
|
21
|
+
|
|
22
|
+
export { type UseLocalStorageResult, useLocalStorage };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
// src/hooks/useLocalStorage/useLocalStorage.ts
|
|
7
|
+
function readValue(key, fallback) {
|
|
8
|
+
if (typeof window === "undefined") {
|
|
9
|
+
return fallback;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
const raw = window.localStorage.getItem(key);
|
|
13
|
+
if (raw == null) {
|
|
14
|
+
return fallback;
|
|
15
|
+
}
|
|
16
|
+
return JSON.parse(raw);
|
|
17
|
+
} catch {
|
|
18
|
+
return fallback;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function useLocalStorage(key, initialValue) {
|
|
22
|
+
const [stored, setStored] = react.useState(
|
|
23
|
+
() => readValue(key, initialValue)
|
|
24
|
+
);
|
|
25
|
+
const setValue = react.useCallback(
|
|
26
|
+
(value) => {
|
|
27
|
+
setStored((previous) => {
|
|
28
|
+
const next = typeof value === "function" ? value(previous) : value;
|
|
29
|
+
try {
|
|
30
|
+
if (typeof window !== "undefined") {
|
|
31
|
+
window.localStorage.setItem(key, JSON.stringify(next));
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
return next;
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
[key]
|
|
39
|
+
);
|
|
40
|
+
const remove = react.useCallback(() => {
|
|
41
|
+
try {
|
|
42
|
+
if (typeof window !== "undefined") {
|
|
43
|
+
window.localStorage.removeItem(key);
|
|
44
|
+
}
|
|
45
|
+
} catch {
|
|
46
|
+
console.error(`Failed to remove item from localStorage: ${key}`);
|
|
47
|
+
}
|
|
48
|
+
setStored(initialValue);
|
|
49
|
+
}, [initialValue, key]);
|
|
50
|
+
react.useEffect(() => {
|
|
51
|
+
setStored((prev) => {
|
|
52
|
+
const next = readValue(key, initialValue);
|
|
53
|
+
return JSON.stringify(prev) === JSON.stringify(next) ? prev : next;
|
|
54
|
+
});
|
|
55
|
+
}, [key]);
|
|
56
|
+
react.useEffect(() => {
|
|
57
|
+
if (typeof window === "undefined") {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const onStorage = (event) => {
|
|
61
|
+
if (event.key !== key) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (event.newValue == null) {
|
|
65
|
+
setStored(initialValue);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
setStored(JSON.parse(event.newValue));
|
|
70
|
+
} catch {
|
|
71
|
+
setStored(initialValue);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
window.addEventListener("storage", onStorage);
|
|
75
|
+
return () => {
|
|
76
|
+
window.removeEventListener("storage", onStorage);
|
|
77
|
+
};
|
|
78
|
+
}, [initialValue, key]);
|
|
79
|
+
return [stored, setValue, remove];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
exports.useLocalStorage = useLocalStorage;
|
|
83
|
+
//# sourceMappingURL=useLocalStorage.js.map
|
|
84
|
+
//# sourceMappingURL=useLocalStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useLocalStorage/useLocalStorage.ts"],"names":["useState","useCallback","useEffect"],"mappings":";;;;;AAIA,SAAS,SAAA,CAAa,KAAa,QAAA,EAAgB;AACjD,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC,IAAA,OAAO,QAAA;AAAA,E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alStorage.js","sourcesContent":["\"use client\";\n\nimport { useCallback, useEffect, useState } from \"react\";\n\nfunction readValue<T>(key: string, fallback: T): T {\n if (typeof window === \"undefined\") {\n return fallback;\n }\n try {\n const raw = window.localStorage.getItem(key);\n if (raw == null) {\n return fallback;\n }\n return JSON.parse(raw) as T;\n } catch {\n return fallback;\n }\n}\n\nexport type UseLocalStorageResult<T> = [\n T,\n (value: T | ((previous: T) => T)) => void,\n () => void,\n];\n\n/**\n * Syncs JSON-serialized state with `window.localStorage` under a fixed key.\n *\n * - Initial read runs on the client; SSR uses `initialValue`.\n * - `setValue` persists with `JSON.stringify` and updates React state; functional updates supported.\n * - `remove` clears the key and resets state to `initialValue`.\n * - Subscribes to the `storage` event so updates from other tabs (or same tab via `storage` dispatch quirks) reconcile.\n * - Read/write failures (private mode, quota) fall back silently on read; write errors are swallowed except `remove` logs on failure.\n *\n * @typeParam T - Stored value type; must be compatible with `JSON.stringify` / `parse`.\n * @param key - `localStorage` key.\n * @param initialValue - Fallback when missing, invalid JSON, or during SSR.\n * @returns `[stored, setValue, remove]` tuple mirroring `useState` plus explicit removal.\n */\nexport function useLocalStorage<T>(\n key: string,\n initialValue: T,\n): UseLocalStorageResult<T> {\n const [stored, setStored] = useState<T>(() =>\n readValue(key, initialValue),\n );\n\n const setValue = useCallback(\n (value: T | ((previous: T) => T)) => {\n setStored((previous) => {\n const next =\n typeof value === \"function\" ? (value as (p: T) => T)(previous) : value;\n try {\n if (typeof window !== \"undefined\") {\n window.localStorage.setItem(key, JSON.stringify(next));\n }\n } catch {\n /* quota or private mode */\n }\n return next;\n });\n },\n [key],\n );\n\n const remove = useCallback(() => {\n try {\n if (typeof window !== \"undefined\") {\n window.localStorage.removeItem(key);\n }\n } catch {\n console.error(`Failed to remove item from localStorage: ${key}`);\n }\n setStored(initialValue);\n }, [initialValue, key]);\n\n useEffect(() => {\n setStored((prev) => {\n const next = readValue(key, initialValue);\n return JSON.stringify(prev) === JSON.stringify(next) ? prev : next;\n });\n }, [key]);\n\n useEffect(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n const onStorage = (event: StorageEvent) => {\n if (event.key !== key) {\n return;\n }\n if (event.newValue == null) {\n setStored(initialValue);\n return;\n }\n try {\n setStored(JSON.parse(event.newValue) as T);\n } catch {\n setStored(initialValue);\n }\n };\n window.addEventListener(\"storage\", onStorage);\n return () => {\n window.removeEventListener(\"storage\", onStorage);\n };\n }, [initialValue, key]);\n\n return [stored, setValue, remove];\n}\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
// src/hooks/useLocalStorage/useLocalStorage.ts
|
|
5
|
+
function readValue(key, fallback) {
|
|
6
|
+
if (typeof window === "undefined") {
|
|
7
|
+
return fallback;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const raw = window.localStorage.getItem(key);
|
|
11
|
+
if (raw == null) {
|
|
12
|
+
return fallback;
|
|
13
|
+
}
|
|
14
|
+
return JSON.parse(raw);
|
|
15
|
+
} catch {
|
|
16
|
+
return fallback;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function useLocalStorage(key, initialValue) {
|
|
20
|
+
const [stored, setStored] = useState(
|
|
21
|
+
() => readValue(key, initialValue)
|
|
22
|
+
);
|
|
23
|
+
const setValue = useCallback(
|
|
24
|
+
(value) => {
|
|
25
|
+
setStored((previous) => {
|
|
26
|
+
const next = typeof value === "function" ? value(previous) : value;
|
|
27
|
+
try {
|
|
28
|
+
if (typeof window !== "undefined") {
|
|
29
|
+
window.localStorage.setItem(key, JSON.stringify(next));
|
|
30
|
+
}
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
return next;
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
[key]
|
|
37
|
+
);
|
|
38
|
+
const remove = useCallback(() => {
|
|
39
|
+
try {
|
|
40
|
+
if (typeof window !== "undefined") {
|
|
41
|
+
window.localStorage.removeItem(key);
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
console.error(`Failed to remove item from localStorage: ${key}`);
|
|
45
|
+
}
|
|
46
|
+
setStored(initialValue);
|
|
47
|
+
}, [initialValue, key]);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
setStored((prev) => {
|
|
50
|
+
const next = readValue(key, initialValue);
|
|
51
|
+
return JSON.stringify(prev) === JSON.stringify(next) ? prev : next;
|
|
52
|
+
});
|
|
53
|
+
}, [key]);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (typeof window === "undefined") {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const onStorage = (event) => {
|
|
59
|
+
if (event.key !== key) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (event.newValue == null) {
|
|
63
|
+
setStored(initialValue);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
setStored(JSON.parse(event.newValue));
|
|
68
|
+
} catch {
|
|
69
|
+
setStored(initialValue);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
window.addEventListener("storage", onStorage);
|
|
73
|
+
return () => {
|
|
74
|
+
window.removeEventListener("storage", onStorage);
|
|
75
|
+
};
|
|
76
|
+
}, [initialValue, key]);
|
|
77
|
+
return [stored, setValue, remove];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { useLocalStorage };
|
|
81
|
+
//# sourceMappingURL=useLocalStorage.mjs.map
|
|
82
|
+
//# sourceMappingURL=useLocalStorage.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useLocalStorage/useLocalStorage.ts"],"names":[],"mappings":";;;AAIA,SAAS,SAAA,CAAa,KAAa,QAAA,EAAgB;AACjD,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,IAAI;AACF,IAAA,MAAM,G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ect, useState } from \"react\";\n\nfunction readValue<T>(key: string, fallback: T): T {\n if (typeof window === \"undefined\") {\n return fallback;\n }\n try {\n const raw = window.localStorage.getItem(key);\n if (raw == null) {\n return fallback;\n }\n return JSON.parse(raw) as T;\n } catch {\n return fallback;\n }\n}\n\nexport type UseLocalStorageResult<T> = [\n T,\n (value: T | ((previous: T) => T)) => void,\n () => void,\n];\n\n/**\n * Syncs JSON-serialized state with `window.localStorage` under a fixed key.\n *\n * - Initial read runs on the client; SSR uses `initialValue`.\n * - `setValue` persists with `JSON.stringify` and updates React state; functional updates supported.\n * - `remove` clears the key and resets state to `initialValue`.\n * - Subscribes to the `storage` event so updates from other tabs (or same tab via `storage` dispatch quirks) reconcile.\n * - Read/write failures (private mode, quota) fall back silently on read; write errors are swallowed except `remove` logs on failure.\n *\n * @typeParam T - Stored value type; must be compatible with `JSON.stringify` / `parse`.\n * @param key - `localStorage` key.\n * @param initialValue - Fallback when missing, invalid JSON, or during SSR.\n * @returns `[stored, setValue, remove]` tuple mirroring `useState` plus explicit removal.\n */\nexport function useLocalStorage<T>(\n key: string,\n initialValue: T,\n): UseLocalStorageResult<T> {\n const [stored, setStored] = useState<T>(() =>\n readValue(key, initialValue),\n );\n\n const setValue = useCallback(\n (value: T | ((previous: T) => T)) => {\n setStored((previous) => {\n const next =\n typeof value === \"function\" ? (value as (p: T) => T)(previous) : value;\n try {\n if (typeof window !== \"undefined\") {\n window.localStorage.setItem(key, JSON.stringify(next));\n }\n } catch {\n /* quota or private mode */\n }\n return next;\n });\n },\n [key],\n );\n\n const remove = useCallback(() => {\n try {\n if (typeof window !== \"undefined\") {\n window.localStorage.removeItem(key);\n }\n } catch {\n console.error(`Failed to remove item from localStorage: ${key}`);\n }\n setStored(initialValue);\n }, [initialValue, key]);\n\n useEffect(() => {\n setStored((prev) => {\n const next = readValue(key, initialValue);\n return JSON.stringify(prev) === JSON.stringify(next) ? prev : next;\n });\n }, [key]);\n\n useEffect(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n const onStorage = (event: StorageEvent) => {\n if (event.key !== key) {\n return;\n }\n if (event.newValue == null) {\n setStored(initialValue);\n return;\n }\n try {\n setStored(JSON.parse(event.newValue) as T);\n } catch {\n setStored(initialValue);\n }\n };\n window.addEventListener(\"storage\", onStorage);\n return () => {\n window.removeEventListener(\"storage\", onStorage);\n };\n }, [initialValue, key]);\n\n return [stored, setValue, remove];\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscribes to `window.matchMedia(query)` and returns whether the query currently matches.
|
|
3
|
+
*
|
|
4
|
+
* On the server or when `matchMedia` is missing, `defaultValue` is used for the initial render and the effect no-ops.
|
|
5
|
+
* The `change` listener keeps `matches` updated when the viewport or user settings change.
|
|
6
|
+
*
|
|
7
|
+
* @param query - A valid media query string, e.g. `"(min-width: 768px)"`.
|
|
8
|
+
* @param defaultValue - Value to use before hydration or when `matchMedia` is unavailable (default `false`).
|
|
9
|
+
* @returns Current `matches` boolean for the query.
|
|
10
|
+
*/
|
|
11
|
+
declare function useMediaQuery(query: string, defaultValue?: boolean): boolean;
|
|
12
|
+
|
|
13
|
+
export { useMediaQuery };
|