@stryke/hooks 0.4.47 → 0.4.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -1
  3. package/dist/env/src/runtime-checks.cjs +57 -1
  4. package/dist/env/src/runtime-checks.mjs +56 -1
  5. package/dist/env/src/runtime-checks.mjs.map +1 -1
  6. package/dist/helpers/src/debounce.cjs +62 -1
  7. package/dist/helpers/src/debounce.mjs +61 -1
  8. package/dist/helpers/src/debounce.mjs.map +1 -1
  9. package/dist/helpers/src/throttle.cjs +43 -1
  10. package/dist/helpers/src/throttle.mjs +42 -1
  11. package/dist/helpers/src/throttle.mjs.map +1 -1
  12. package/dist/index.cjs +41 -1
  13. package/dist/index.mjs +19 -1
  14. package/dist/type-checks/src/get-object-tag.cjs +15 -1
  15. package/dist/type-checks/src/get-object-tag.mjs +14 -1
  16. package/dist/type-checks/src/get-object-tag.mjs.map +1 -1
  17. package/dist/type-checks/src/is-equal.cjs +19 -1
  18. package/dist/type-checks/src/is-equal.mjs +18 -1
  19. package/dist/type-checks/src/is-equal.mjs.map +1 -1
  20. package/dist/type-checks/src/is-function.cjs +25 -1
  21. package/dist/type-checks/src/is-function.mjs +25 -1
  22. package/dist/type-checks/src/is-function.mjs.map +1 -1
  23. package/dist/types/src/base.cjs +6 -1
  24. package/dist/types/src/base.mjs +5 -1
  25. package/dist/types/src/base.mjs.map +1 -1
  26. package/dist/use-battery.cjs +60 -1
  27. package/dist/use-battery.mjs +58 -1
  28. package/dist/use-battery.mjs.map +1 -1
  29. package/dist/use-callback-ref.cjs +18 -1
  30. package/dist/use-callback-ref.mjs +17 -1
  31. package/dist/use-callback-ref.mjs.map +1 -1
  32. package/dist/use-callback-stable.cjs +26 -1
  33. package/dist/use-callback-stable.mjs +26 -1
  34. package/dist/use-callback-stable.mjs.map +1 -1
  35. package/dist/use-click-away.cjs +33 -1
  36. package/dist/use-click-away.mjs +32 -1
  37. package/dist/use-click-away.mjs.map +1 -1
  38. package/dist/use-compose-refs.cjs +43 -1
  39. package/dist/use-compose-refs.mjs +40 -1
  40. package/dist/use-compose-refs.mjs.map +1 -1
  41. package/dist/use-copy-to-clipboard.cjs +38 -1
  42. package/dist/use-copy-to-clipboard.mjs +37 -1
  43. package/dist/use-copy-to-clipboard.mjs.map +1 -1
  44. package/dist/use-debounce.cjs +44 -1
  45. package/dist/use-debounce.mjs +42 -1
  46. package/dist/use-debounce.mjs.map +1 -1
  47. package/dist/use-did-finish-ssr.cjs +27 -1
  48. package/dist/use-did-finish-ssr.mjs +24 -1
  49. package/dist/use-did-finish-ssr.mjs.map +1 -1
  50. package/dist/use-escape-keydown.cjs +23 -1
  51. package/dist/use-escape-keydown.mjs +22 -1
  52. package/dist/use-escape-keydown.mjs.map +1 -1
  53. package/dist/use-event.cjs +27 -1
  54. package/dist/use-event.mjs +26 -1
  55. package/dist/use-event.mjs.map +1 -1
  56. package/dist/use-hover.cjs +33 -1
  57. package/dist/use-hover.mjs +32 -1
  58. package/dist/use-hover.mjs.map +1 -1
  59. package/dist/use-idle.cjs +50 -1
  60. package/dist/use-idle.mjs +49 -1
  61. package/dist/use-idle.mjs.map +1 -1
  62. package/dist/use-isomorphic-layout-effect.cjs +14 -1
  63. package/dist/use-isomorphic-layout-effect.mjs +13 -1
  64. package/dist/use-isomorphic-layout-effect.mjs.map +1 -1
  65. package/dist/use-keyboard-visible.cjs +24 -1
  66. package/dist/use-keyboard-visible.mjs +23 -1
  67. package/dist/use-keyboard-visible.mjs.map +1 -1
  68. package/dist/use-memo-stable.cjs +48 -1
  69. package/dist/use-memo-stable.mjs +47 -1
  70. package/dist/use-memo-stable.mjs.map +1 -1
  71. package/dist/use-network-state.cjs +57 -1
  72. package/dist/use-network-state.mjs +55 -1
  73. package/dist/use-network-state.mjs.map +1 -1
  74. package/dist/use-previous.cjs +20 -1
  75. package/dist/use-previous.mjs +19 -1
  76. package/dist/use-previous.mjs.map +1 -1
  77. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"use-compose-refs.mjs","names":[],"sources":["../src/use-compose-refs.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport type { Ref, RefObject } from \"react\";\nimport { useCallback } from \"react\";\n\n// from radix\n// https://raw.githubusercontent.com/radix-ui/primitives/main/packages/react/compose-refs/src/composeRefs.tsx\n\n/**\n * Set a given ref to a given value\n * This utility takes care of different types of refs: callback refs and RefObject(s)\n *\n * @param ref - The ref to set\n * @param value - The value to set the ref to\n */\nexport function setRef<T>(ref: Ref<T> | undefined, value: T) {\n if (ref) {\n if (isFunction(ref)) {\n ref(value);\n } else {\n (ref as RefObject<T>).current = value;\n }\n }\n}\n\n/**\n * A utility to compose multiple refs together\n * Accepts callback refs and RefObject(s)\n *\n * @param refs - The refs to compose\n * @returns A function that sets all refs to a given value\n */\nexport function composeRefs<T>(...refs: Ref<T>[]) {\n return (node: T) => {\n for (const ref of refs) {\n setRef(ref, node);\n }\n };\n}\n\n/**\n * A custom hook that composes multiple refs\n * Accepts callback refs and RefObject(s)\n *\n * @param refs - The refs to compose\n * @returns A function that sets all refs to a given value\n */\nexport function useComposedRefs<T>(...refs: Ref<T>[]) {\n return useCallback(composeRefs(...refs), refs);\n}\n"],"mappings":"mGAgCA,SAAgB,EAAU,EAAyB,EAAU,CACvD,IACE,EAAW,EAAI,CACjB,EAAI,EAAM,CAET,EAAqB,QAAU,GAYtC,SAAgB,EAAe,GAAG,EAAgB,CAChD,MAAQ,IAAY,CAClB,IAAK,IAAM,KAAO,EAChB,EAAO,EAAK,EAAK,EAYvB,SAAgB,EAAmB,GAAG,EAAgB,CACpD,OAAO,EAAY,EAAY,GAAG,EAAK,CAAE,EAAK"}
1
+ {"version":3,"file":"use-compose-refs.mjs","names":[],"sources":["../src/use-compose-refs.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport type { Ref, RefObject } from \"react\";\nimport { useCallback } from \"react\";\n\n// from radix\n// https://raw.githubusercontent.com/radix-ui/primitives/main/packages/react/compose-refs/src/composeRefs.tsx\n\n/**\n * Set a given ref to a given value\n * This utility takes care of different types of refs: callback refs and RefObject(s)\n *\n * @param ref - The ref to set\n * @param value - The value to set the ref to\n */\nexport function setRef<T>(ref: Ref<T> | undefined, value: T) {\n if (ref) {\n if (isFunction(ref)) {\n ref(value);\n } else {\n (ref as RefObject<T>).current = value;\n }\n }\n}\n\n/**\n * A utility to compose multiple refs together\n * Accepts callback refs and RefObject(s)\n *\n * @param refs - The refs to compose\n * @returns A function that sets all refs to a given value\n */\nexport function composeRefs<T>(...refs: Ref<T>[]) {\n return (node: T) => {\n for (const ref of refs) {\n setRef(ref, node);\n }\n };\n}\n\n/**\n * A custom hook that composes multiple refs\n * Accepts callback refs and RefObject(s)\n *\n * @param refs - The refs to compose\n * @returns A function that sets all refs to a given value\n */\nexport function useComposedRefs<T>(...refs: Ref<T>[]) {\n return useCallback(composeRefs(...refs), refs);\n}\n"],"mappings":";;;;;;;;;;;AAgCA,SAAgB,OAAU,KAAyB,OAAU;AAC3D,KAAI,IACF,KAAI,WAAW,IAAI,CACjB,KAAI,MAAM;KAEV,CAAC,IAAqB,UAAU;;;;;;;;;AAYtC,SAAgB,YAAe,GAAG,MAAgB;AAChD,SAAQ,SAAY;AAClB,OAAK,MAAM,OAAO,KAChB,QAAO,KAAK,KAAK;;;;;;;;;;AAYvB,SAAgB,gBAAmB,GAAG,MAAgB;AACpD,QAAO,YAAY,YAAY,GAAG,KAAK,EAAE,KAAK"}
@@ -1 +1,38 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./types/src/base.cjs`);let n=require(`react`);function r(e){let t=document.createElement(`textarea`);t.value=e,document.body.append(t),t.select(),document.execCommand(`copy`),t.remove()}function i(){let[e,i]=(0,n.useState)(null);return[e,(0,n.useCallback)(async e=>{await(async()=>{try{if(navigator?.clipboard?.writeText)await navigator.clipboard.writeText(e??t.EMPTY_STRING),i(e??t.EMPTY_STRING);else throw Error(`writeText not supported`)}catch{r(e??t.EMPTY_STRING),i(e??t.EMPTY_STRING)}})()},[])]}exports.useCopyToClipboard=i;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_base = require('./types/src/base.cjs');
3
+ let react = require("react");
4
+
5
+ //#region src/use-copy-to-clipboard.ts
6
+ function oldSchoolCopy(text) {
7
+ const tempTextArea = document.createElement("textarea");
8
+ tempTextArea.value = text;
9
+ document.body.append(tempTextArea);
10
+ tempTextArea.select();
11
+ document.execCommand("copy");
12
+ tempTextArea.remove();
13
+ }
14
+ /**
15
+ * Copies a value to the clipboard
16
+ *
17
+ * @returns A tuple with the copied value and a function to copy a value to the clipboard
18
+ */
19
+ function useCopyToClipboard() {
20
+ const [state, setState] = (0, react.useState)(null);
21
+ return [state, (0, react.useCallback)(async (value) => {
22
+ const handleCopy = async () => {
23
+ try {
24
+ if (navigator?.clipboard?.writeText) {
25
+ await navigator.clipboard.writeText(value ?? require_base.EMPTY_STRING);
26
+ setState(value ?? require_base.EMPTY_STRING);
27
+ } else throw new Error("writeText not supported");
28
+ } catch {
29
+ oldSchoolCopy(value ?? require_base.EMPTY_STRING);
30
+ setState(value ?? require_base.EMPTY_STRING);
31
+ }
32
+ };
33
+ await handleCopy();
34
+ }, [])];
35
+ }
36
+
37
+ //#endregion
38
+ exports.useCopyToClipboard = useCopyToClipboard;
@@ -1,2 +1,38 @@
1
- import{EMPTY_STRING as e}from"./types/src/base.mjs";import{useCallback as t,useState as n}from"react";function r(e){let t=document.createElement(`textarea`);t.value=e,document.body.append(t),t.select(),document.execCommand(`copy`),t.remove()}function i(){let[i,a]=n(null);return[i,t(async t=>{await(async()=>{try{if(navigator?.clipboard?.writeText)await navigator.clipboard.writeText(t??e),a(t??e);else throw Error(`writeText not supported`)}catch{r(t??e),a(t??e)}})()},[])]}export{i as useCopyToClipboard};
1
+ import { EMPTY_STRING } from "./types/src/base.mjs";
2
+ import { useCallback, useState } from "react";
3
+
4
+ //#region src/use-copy-to-clipboard.ts
5
+ function oldSchoolCopy(text) {
6
+ const tempTextArea = document.createElement("textarea");
7
+ tempTextArea.value = text;
8
+ document.body.append(tempTextArea);
9
+ tempTextArea.select();
10
+ document.execCommand("copy");
11
+ tempTextArea.remove();
12
+ }
13
+ /**
14
+ * Copies a value to the clipboard
15
+ *
16
+ * @returns A tuple with the copied value and a function to copy a value to the clipboard
17
+ */
18
+ function useCopyToClipboard() {
19
+ const [state, setState] = useState(null);
20
+ return [state, useCallback(async (value) => {
21
+ const handleCopy = async () => {
22
+ try {
23
+ if (navigator?.clipboard?.writeText) {
24
+ await navigator.clipboard.writeText(value ?? EMPTY_STRING);
25
+ setState(value ?? EMPTY_STRING);
26
+ } else throw new Error("writeText not supported");
27
+ } catch {
28
+ oldSchoolCopy(value ?? EMPTY_STRING);
29
+ setState(value ?? EMPTY_STRING);
30
+ }
31
+ };
32
+ await handleCopy();
33
+ }, [])];
34
+ }
35
+
36
+ //#endregion
37
+ export { useCopyToClipboard };
2
38
  //# sourceMappingURL=use-copy-to-clipboard.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-copy-to-clipboard.mjs","names":[],"sources":["../src/use-copy-to-clipboard.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { EMPTY_STRING } from \"@stryke/types/base\";\nimport { useCallback, useState } from \"react\";\n\nfunction oldSchoolCopy(text: string) {\n const tempTextArea = document.createElement(\"textarea\");\n tempTextArea.value = text;\n document.body.append(tempTextArea);\n tempTextArea.select();\n document.execCommand(\"copy\");\n tempTextArea.remove();\n}\n\n/**\n * Copies a value to the clipboard\n *\n * @returns A tuple with the copied value and a function to copy a value to the clipboard\n */\nexport function useCopyToClipboard() {\n const [state, setState] = useState<string | null>(null);\n\n const copyToClipboard = useCallback(async (value: string | null) => {\n const handleCopy = async () => {\n try {\n if (navigator?.clipboard?.writeText) {\n await navigator.clipboard.writeText(value ?? EMPTY_STRING);\n setState(value ?? EMPTY_STRING);\n } else {\n throw new Error(\"writeText not supported\");\n }\n } catch {\n oldSchoolCopy(value ?? EMPTY_STRING);\n setState(value ?? EMPTY_STRING);\n }\n };\n\n await handleCopy();\n }, []);\n\n return [state, copyToClipboard];\n}\n"],"mappings":"sGAqBA,SAAS,EAAc,EAAc,CACnC,IAAM,EAAe,SAAS,cAAc,WAAW,CACvD,EAAa,MAAQ,EACrB,SAAS,KAAK,OAAO,EAAa,CAClC,EAAa,QAAQ,CACrB,SAAS,YAAY,OAAO,CAC5B,EAAa,QAAQ,CAQvB,SAAgB,GAAqB,CACnC,GAAM,CAAC,EAAO,GAAY,EAAwB,KAAK,CAoBvD,MAAO,CAAC,EAlBgB,EAAY,KAAO,IAAyB,CAelE,MAdmB,SAAY,CAC7B,GAAI,CACF,GAAI,WAAW,WAAW,UACxB,MAAM,UAAU,UAAU,UAAU,GAAS,EAAa,CAC1D,EAAS,GAAS,EAAa,MAE/B,MAAU,MAAM,0BAA0B,MAEtC,CACN,EAAc,GAAS,EAAa,CACpC,EAAS,GAAS,EAAa,KAIjB,EACjB,EAAE,CAAC,CAEyB"}
1
+ {"version":3,"file":"use-copy-to-clipboard.mjs","names":[],"sources":["../src/use-copy-to-clipboard.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { EMPTY_STRING } from \"@stryke/types/base\";\nimport { useCallback, useState } from \"react\";\n\nfunction oldSchoolCopy(text: string) {\n const tempTextArea = document.createElement(\"textarea\");\n tempTextArea.value = text;\n document.body.append(tempTextArea);\n tempTextArea.select();\n document.execCommand(\"copy\");\n tempTextArea.remove();\n}\n\n/**\n * Copies a value to the clipboard\n *\n * @returns A tuple with the copied value and a function to copy a value to the clipboard\n */\nexport function useCopyToClipboard() {\n const [state, setState] = useState<string | null>(null);\n\n const copyToClipboard = useCallback(async (value: string | null) => {\n const handleCopy = async () => {\n try {\n if (navigator?.clipboard?.writeText) {\n await navigator.clipboard.writeText(value ?? EMPTY_STRING);\n setState(value ?? EMPTY_STRING);\n } else {\n throw new Error(\"writeText not supported\");\n }\n } catch {\n oldSchoolCopy(value ?? EMPTY_STRING);\n setState(value ?? EMPTY_STRING);\n }\n };\n\n await handleCopy();\n }, []);\n\n return [state, copyToClipboard];\n}\n"],"mappings":";;;;AAqBA,SAAS,cAAc,MAAc;CACnC,MAAM,eAAe,SAAS,cAAc,WAAW;AACvD,cAAa,QAAQ;AACrB,UAAS,KAAK,OAAO,aAAa;AAClC,cAAa,QAAQ;AACrB,UAAS,YAAY,OAAO;AAC5B,cAAa,QAAQ;;;;;;;AAQvB,SAAgB,qBAAqB;CACnC,MAAM,CAAC,OAAO,YAAY,SAAwB,KAAK;AAoBvD,QAAO,CAAC,OAlBgB,YAAY,OAAO,UAAyB;EAClE,MAAM,aAAa,YAAY;AAC7B,OAAI;AACF,QAAI,WAAW,WAAW,WAAW;AACnC,WAAM,UAAU,UAAU,UAAU,SAAS,aAAa;AAC1D,cAAS,SAAS,aAAa;UAE/B,OAAM,IAAI,MAAM,0BAA0B;WAEtC;AACN,kBAAc,SAAS,aAAa;AACpC,aAAS,SAAS,aAAa;;;AAInC,QAAM,YAAY;IACjB,EAAE,CAAC,CAEyB"}
@@ -1 +1,44 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./helpers/src/debounce.cjs`);let n=require(`react`);function r(e,r,i={}){let a=(0,n.useRef)(null);return(0,n.useEffect)(()=>()=>{a.current?.cancel()},[]),(0,n.useMemo)(()=>(a.current=t.debounce(e,r,i),a.current),[e,i,r])}function i(e,t=0){let[r,i]=(0,n.useState)(e);return(0,n.useEffect)(()=>{let n=setTimeout(()=>{i(t=>t===e?t:e)},t);return()=>{clearTimeout(n)}},[t,e]),r}exports.useDebounce=r,exports.useDebounceValue=i;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_debounce = require('./helpers/src/debounce.cjs');
3
+ let react = require("react");
4
+
5
+ //#region src/use-debounce.ts
6
+ function useDebounce(fn, wait, options = {}) {
7
+ const dbEffect = (0, react.useRef)(null);
8
+ (0, react.useEffect)(() => {
9
+ return () => {
10
+ dbEffect.current?.cancel();
11
+ };
12
+ }, []);
13
+ return (0, react.useMemo)(() => {
14
+ dbEffect.current = require_debounce.debounce(fn, wait, options);
15
+ return dbEffect.current;
16
+ }, [
17
+ fn,
18
+ options,
19
+ wait
20
+ ]);
21
+ }
22
+ /**
23
+ * Returns a value once it stops changing after "amt" time.
24
+ * Note: you may need to memo or this will keep re-rendering
25
+ */
26
+ function useDebounceValue(val, amt = 0) {
27
+ const [state, setState] = (0, react.useState)(val);
28
+ (0, react.useEffect)(() => {
29
+ const tm = setTimeout(() => {
30
+ setState((prev) => {
31
+ if (prev === val) return prev;
32
+ return val;
33
+ });
34
+ }, amt);
35
+ return () => {
36
+ clearTimeout(tm);
37
+ };
38
+ }, [amt, val]);
39
+ return state;
40
+ }
41
+
42
+ //#endregion
43
+ exports.useDebounce = useDebounce;
44
+ exports.useDebounceValue = useDebounceValue;
@@ -1,2 +1,43 @@
1
- import{debounce as e}from"./helpers/src/debounce.mjs";import{useEffect as t,useMemo as n,useRef as r,useState as i}from"react";function a(i,a,o={}){let s=r(null);return t(()=>()=>{s.current?.cancel()},[]),n(()=>(s.current=e(i,a,o),s.current),[i,o,a])}function o(e,n=0){let[r,a]=i(e);return t(()=>{let t=setTimeout(()=>{a(t=>t===e?t:e)},n);return()=>{clearTimeout(t)}},[n,e]),r}export{a as useDebounce,o as useDebounceValue};
1
+ import { debounce } from "./helpers/src/debounce.mjs";
2
+ import { useEffect, useMemo, useRef, useState } from "react";
3
+
4
+ //#region src/use-debounce.ts
5
+ function useDebounce(fn, wait, options = {}) {
6
+ const dbEffect = useRef(null);
7
+ useEffect(() => {
8
+ return () => {
9
+ dbEffect.current?.cancel();
10
+ };
11
+ }, []);
12
+ return useMemo(() => {
13
+ dbEffect.current = debounce(fn, wait, options);
14
+ return dbEffect.current;
15
+ }, [
16
+ fn,
17
+ options,
18
+ wait
19
+ ]);
20
+ }
21
+ /**
22
+ * Returns a value once it stops changing after "amt" time.
23
+ * Note: you may need to memo or this will keep re-rendering
24
+ */
25
+ function useDebounceValue(val, amt = 0) {
26
+ const [state, setState] = useState(val);
27
+ useEffect(() => {
28
+ const tm = setTimeout(() => {
29
+ setState((prev) => {
30
+ if (prev === val) return prev;
31
+ return val;
32
+ });
33
+ }, amt);
34
+ return () => {
35
+ clearTimeout(tm);
36
+ };
37
+ }, [amt, val]);
38
+ return state;
39
+ }
40
+
41
+ //#endregion
42
+ export { useDebounce, useDebounceValue };
2
43
  //# sourceMappingURL=use-debounce.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-debounce.mjs","names":[],"sources":["../src/use-debounce.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { DebounceOptions } from \"@stryke/helpers/debounce\";\nimport { debounce } from \"@stryke/helpers/debounce\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\n\n// export function debounce<A extends Function>(\n// func: A,\n// wait?: number,\n// leading?: boolean\n// ): A & {\n// cancel: () => void;\n// } {\n// let timeout: any;\n// let isCancelled = false;\n\n// function debounced(this: any) {\n// isCancelled = false;\n// const args = arguments;\n// if (leading && !timeout) {\n// func.apply(this, args);\n// }\n// clearTimeout(timeout);\n// timeout = setTimeout(() => {\n// timeout = null;\n// if (!(leading || isCancelled)) {\n// func.apply(this, args);\n// }\n// isCancelled = false;\n// }, wait);\n// }\n\n// debounced.cancel = () => {\n// isCancelled = true;\n// };\n\n// return debounced as any;\n// }\n\nexport function useDebounce<\n A extends (...args: any) => any | undefined | null,\n DebouncedFn extends A & {\n cancel: () => void;\n }\n>(fn: A, wait: number, options: DebounceOptions = {}): DebouncedFn {\n const dbEffect = useRef<DebouncedFn | null>(null);\n\n useEffect(() => {\n return () => {\n dbEffect.current?.cancel();\n };\n }, []);\n\n return useMemo(() => {\n dbEffect.current = debounce(fn, wait, options) as unknown as DebouncedFn;\n return dbEffect.current;\n }, [fn, options, wait]);\n}\n\n/**\n * Returns a value once it stops changing after \"amt\" time.\n * Note: you may need to memo or this will keep re-rendering\n */\nexport function useDebounceValue<A>(val: A, amt = 0): A {\n const [state, setState] = useState(val);\n\n useEffect(() => {\n const tm = setTimeout(() => {\n setState(prev => {\n if (prev === val) return prev;\n return val;\n });\n }, amt);\n\n return () => {\n clearTimeout(tm);\n };\n }, [amt, val]);\n\n return state;\n}\n"],"mappings":"+HAuDA,SAAgB,EAKd,EAAO,EAAc,EAA2B,EAAE,CAAe,CACjE,IAAM,EAAW,EAA2B,KAAK,CAQjD,OANA,UACe,CACX,EAAS,SAAS,QAAQ,EAE3B,EAAE,CAAC,CAEC,OACL,EAAS,QAAU,EAAS,EAAI,EAAM,EAAQ,CACvC,EAAS,SACf,CAAC,EAAI,EAAS,EAAK,CAAC,CAOzB,SAAgB,EAAoB,EAAQ,EAAM,EAAM,CACtD,GAAM,CAAC,EAAO,GAAY,EAAS,EAAI,CAevC,OAbA,MAAgB,CACd,IAAM,EAAK,eAAiB,CAC1B,EAAS,GACH,IAAS,EAAY,EAClB,EACP,EACD,EAAI,CAEP,UAAa,CACX,aAAa,EAAG,GAEjB,CAAC,EAAK,EAAI,CAAC,CAEP"}
1
+ {"version":3,"file":"use-debounce.mjs","names":[],"sources":["../src/use-debounce.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { DebounceOptions } from \"@stryke/helpers/debounce\";\nimport { debounce } from \"@stryke/helpers/debounce\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\n\n// export function debounce<A extends Function>(\n// func: A,\n// wait?: number,\n// leading?: boolean\n// ): A & {\n// cancel: () => void;\n// } {\n// let timeout: any;\n// let isCancelled = false;\n\n// function debounced(this: any) {\n// isCancelled = false;\n// const args = arguments;\n// if (leading && !timeout) {\n// func.apply(this, args);\n// }\n// clearTimeout(timeout);\n// timeout = setTimeout(() => {\n// timeout = null;\n// if (!(leading || isCancelled)) {\n// func.apply(this, args);\n// }\n// isCancelled = false;\n// }, wait);\n// }\n\n// debounced.cancel = () => {\n// isCancelled = true;\n// };\n\n// return debounced as any;\n// }\n\nexport function useDebounce<\n A extends (...args: any) => any | undefined | null,\n DebouncedFn extends A & {\n cancel: () => void;\n }\n>(fn: A, wait: number, options: DebounceOptions = {}): DebouncedFn {\n const dbEffect = useRef<DebouncedFn | null>(null);\n\n useEffect(() => {\n return () => {\n dbEffect.current?.cancel();\n };\n }, []);\n\n return useMemo(() => {\n dbEffect.current = debounce(fn, wait, options) as unknown as DebouncedFn;\n return dbEffect.current;\n }, [fn, options, wait]);\n}\n\n/**\n * Returns a value once it stops changing after \"amt\" time.\n * Note: you may need to memo or this will keep re-rendering\n */\nexport function useDebounceValue<A>(val: A, amt = 0): A {\n const [state, setState] = useState(val);\n\n useEffect(() => {\n const tm = setTimeout(() => {\n setState(prev => {\n if (prev === val) return prev;\n return val;\n });\n }, amt);\n\n return () => {\n clearTimeout(tm);\n };\n }, [amt, val]);\n\n return state;\n}\n"],"mappings":";;;;AAuDA,SAAgB,YAKd,IAAO,MAAc,UAA2B,EAAE,EAAe;CACjE,MAAM,WAAW,OAA2B,KAAK;AAEjD,iBAAgB;AACd,eAAa;AACX,YAAS,SAAS,QAAQ;;IAE3B,EAAE,CAAC;AAEN,QAAO,cAAc;AACnB,WAAS,UAAU,SAAS,IAAI,MAAM,QAAQ;AAC9C,SAAO,SAAS;IACf;EAAC;EAAI;EAAS;EAAK,CAAC;;;;;;AAOzB,SAAgB,iBAAoB,KAAQ,MAAM,GAAM;CACtD,MAAM,CAAC,OAAO,YAAY,SAAS,IAAI;AAEvC,iBAAgB;EACd,MAAM,KAAK,iBAAiB;AAC1B,aAAS,SAAQ;AACf,QAAI,SAAS,IAAK,QAAO;AACzB,WAAO;KACP;KACD,IAAI;AAEP,eAAa;AACX,gBAAa,GAAG;;IAEjB,CAAC,KAAK,IAAI,CAAC;AAEd,QAAO"}
@@ -1 +1,27 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./type-checks/src/is-function.cjs`);let n=require(`react`);const r=()=>{},i=()=>r;function a(e,t){if(process.env.TAMAGUI_TARGET===`native`)return e??!0;if(t?.sync)return(0,n.useSyncExternalStore)(i,()=>e??!0,()=>!1);let[r,a]=(0,n.useState)(e);return(0,n.useEffect)(()=>{a(e??!0)},[e]),r??!1}function o(e){return a(e,{sync:!0})}function s(e){return a()?t.isFunction(e)?e():e:void 0}exports.useClientValue=s,exports.useDidFinishSSR=a,exports.useDidFinishSSRSync=o;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_is_function = require('./type-checks/src/is-function.cjs');
3
+ let react = require("react");
4
+
5
+ //#region src/use-did-finish-ssr.ts
6
+ const emptyFn = () => {};
7
+ const emptyFnFn = () => emptyFn;
8
+ function useDidFinishSSR(value, options) {
9
+ if (process.env.TAMAGUI_TARGET === "native") return value ?? true;
10
+ if (options?.sync) return (0, react.useSyncExternalStore)(emptyFnFn, () => value ?? true, () => false);
11
+ const [cur, setCur] = (0, react.useState)(value);
12
+ (0, react.useEffect)(() => {
13
+ setCur(value ?? true);
14
+ }, [value]);
15
+ return cur ?? false;
16
+ }
17
+ function useDidFinishSSRSync(value) {
18
+ return useDidFinishSSR(value, { sync: true });
19
+ }
20
+ function useClientValue(value) {
21
+ return useDidFinishSSR() ? require_is_function.isFunction(value) ? value() : value : void 0;
22
+ }
23
+
24
+ //#endregion
25
+ exports.useClientValue = useClientValue;
26
+ exports.useDidFinishSSR = useDidFinishSSR;
27
+ exports.useDidFinishSSRSync = useDidFinishSSRSync;
@@ -1,2 +1,25 @@
1
- import{isFunction as e}from"./type-checks/src/is-function.mjs";import{useEffect as t,useState as n,useSyncExternalStore as r}from"react";const i=()=>{},a=()=>i;function o(e,i){if(process.env.TAMAGUI_TARGET===`native`)return e??!0;if(i?.sync)return r(a,()=>e??!0,()=>!1);let[o,s]=n(e);return t(()=>{s(e??!0)},[e]),o??!1}function s(e){return o(e,{sync:!0})}function c(t){return o()?e(t)?t():t:void 0}export{c as useClientValue,o as useDidFinishSSR,s as useDidFinishSSRSync};
1
+ import { isFunction } from "./type-checks/src/is-function.mjs";
2
+ import { useEffect, useState, useSyncExternalStore } from "react";
3
+
4
+ //#region src/use-did-finish-ssr.ts
5
+ const emptyFn = () => {};
6
+ const emptyFnFn = () => emptyFn;
7
+ function useDidFinishSSR(value, options) {
8
+ if (process.env.TAMAGUI_TARGET === "native") return value ?? true;
9
+ if (options?.sync) return useSyncExternalStore(emptyFnFn, () => value ?? true, () => false);
10
+ const [cur, setCur] = useState(value);
11
+ useEffect(() => {
12
+ setCur(value ?? true);
13
+ }, [value]);
14
+ return cur ?? false;
15
+ }
16
+ function useDidFinishSSRSync(value) {
17
+ return useDidFinishSSR(value, { sync: true });
18
+ }
19
+ function useClientValue(value) {
20
+ return useDidFinishSSR() ? isFunction(value) ? value() : value : void 0;
21
+ }
22
+
23
+ //#endregion
24
+ export { useClientValue, useDidFinishSSR, useDidFinishSSRSync };
2
25
  //# sourceMappingURL=use-did-finish-ssr.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-did-finish-ssr.mjs","names":[],"sources":["../src/use-did-finish-ssr.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { useEffect, useState, useSyncExternalStore } from \"react\";\n\nconst emptyFn = () => {};\nconst emptyFnFn = () => emptyFn;\n\nexport function useDidFinishSSR<A = boolean>(\n value?: A,\n options?: {\n sync?: boolean;\n }\n): A | false {\n if (process.env.TAMAGUI_TARGET === \"native\") {\n return (value ?? true) as false | A;\n }\n\n if (options?.sync) {\n return useSyncExternalStore(\n emptyFnFn,\n () => value ?? true,\n () => false as any\n );\n }\n\n const [cur, setCur] = useState<any>(value);\n useEffect(() => {\n setCur(value ?? true);\n }, [value]);\n return cur ?? false;\n}\n\nexport function useDidFinishSSRSync<A = boolean>(value?: A): A | false {\n return useDidFinishSSR(value, {\n sync: true\n });\n}\n\ntype FunctionOrValue<Value> = Value extends () => infer X ? X : Value;\n\nexport function useClientValue<Value>(\n value?: Value\n): FunctionOrValue<Value> | undefined {\n const done = useDidFinishSSR();\n\n return done\n ? isFunction(value)\n ? value()\n : (value as FunctionOrValue<Value>)\n : undefined;\n}\n"],"mappings":"yIAqBA,MAAM,MAAgB,GAChB,MAAkB,EAExB,SAAgB,EACd,EACA,EAGW,CACX,GAAI,QAAQ,IAAI,iBAAmB,SACjC,OAAQ,GAAS,GAGnB,GAAI,GAAS,KACX,OAAO,EACL,MACM,GAAS,OACT,GACP,CAGH,GAAM,CAAC,EAAK,GAAU,EAAc,EAAM,CAI1C,OAHA,MAAgB,CACd,EAAO,GAAS,GAAK,EACpB,CAAC,EAAM,CAAC,CACJ,GAAO,GAGhB,SAAgB,EAAiC,EAAsB,CACrE,OAAO,EAAgB,EAAO,CAC5B,KAAM,GACP,CAAC,CAKJ,SAAgB,EACd,EACoC,CAGpC,OAFa,GAAiB,CAG1B,EAAW,EAAM,CACf,GAAO,CACN,EACH,IAAA"}
1
+ {"version":3,"file":"use-did-finish-ssr.mjs","names":[],"sources":["../src/use-did-finish-ssr.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { useEffect, useState, useSyncExternalStore } from \"react\";\n\nconst emptyFn = () => {};\nconst emptyFnFn = () => emptyFn;\n\nexport function useDidFinishSSR<A = boolean>(\n value?: A,\n options?: {\n sync?: boolean;\n }\n): A | false {\n if (process.env.TAMAGUI_TARGET === \"native\") {\n return (value ?? true) as false | A;\n }\n\n if (options?.sync) {\n return useSyncExternalStore(\n emptyFnFn,\n () => value ?? true,\n () => false as any\n );\n }\n\n const [cur, setCur] = useState<any>(value);\n useEffect(() => {\n setCur(value ?? true);\n }, [value]);\n return cur ?? false;\n}\n\nexport function useDidFinishSSRSync<A = boolean>(value?: A): A | false {\n return useDidFinishSSR(value, {\n sync: true\n });\n}\n\ntype FunctionOrValue<Value> = Value extends () => infer X ? X : Value;\n\nexport function useClientValue<Value>(\n value?: Value\n): FunctionOrValue<Value> | undefined {\n const done = useDidFinishSSR();\n\n return done\n ? isFunction(value)\n ? value()\n : (value as FunctionOrValue<Value>)\n : undefined;\n}\n"],"mappings":";;;;AAqBA,MAAM,gBAAgB;AACtB,MAAM,kBAAkB;AAExB,SAAgB,gBACd,OACA,SAGW;AACX,KAAI,QAAQ,IAAI,mBAAmB,SACjC,QAAQ,SAAS;AAGnB,KAAI,SAAS,KACX,QAAO,qBACL,iBACM,SAAS,YACT,MACP;CAGH,MAAM,CAAC,KAAK,UAAU,SAAc,MAAM;AAC1C,iBAAgB;AACd,SAAO,SAAS,KAAK;IACpB,CAAC,MAAM,CAAC;AACX,QAAO,OAAO;;AAGhB,SAAgB,oBAAiC,OAAsB;AACrE,QAAO,gBAAgB,OAAO,EAC5B,MAAM,MACP,CAAC;;AAKJ,SAAgB,eACd,OACoC;AAGpC,QAFa,iBAAiB,GAG1B,WAAW,MAAM,GACf,OAAO,GACN,QACH"}
@@ -1 +1,23 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./use-callback-ref.cjs`);let n=require(`react`);function r(e,r=globalThis?.document){let i=t.useCallbackRef(e);(0,n.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i(e)};return r.addEventListener(`keydown`,e),()=>{r.removeEventListener(`keydown`,e)}},[i,r])}exports.useEscapeKeydown=r;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_use_callback_ref = require('./use-callback-ref.cjs');
3
+ let react = require("react");
4
+
5
+ //#region src/use-escape-keydown.ts
6
+ /**
7
+ * Listens for when the escape key is down
8
+ */
9
+ function useEscapeKeydown(onEscapeKeyDownProp, ownerDocument = globalThis?.document) {
10
+ const onEscapeKeyDown = require_use_callback_ref.useCallbackRef(onEscapeKeyDownProp);
11
+ (0, react.useEffect)(() => {
12
+ const handleKeyDown = (event) => {
13
+ if (event.key === "Escape") onEscapeKeyDown(event);
14
+ };
15
+ ownerDocument.addEventListener("keydown", handleKeyDown);
16
+ return () => {
17
+ ownerDocument.removeEventListener("keydown", handleKeyDown);
18
+ };
19
+ }, [onEscapeKeyDown, ownerDocument]);
20
+ }
21
+
22
+ //#endregion
23
+ exports.useEscapeKeydown = useEscapeKeydown;
@@ -1,2 +1,23 @@
1
- import{useCallbackRef as e}from"./use-callback-ref.mjs";import{useEffect as t}from"react";function n(n,r=globalThis?.document){let i=e(n);t(()=>{let e=e=>{e.key===`Escape`&&i(e)};return r.addEventListener(`keydown`,e),()=>{r.removeEventListener(`keydown`,e)}},[i,r])}export{n as useEscapeKeydown};
1
+ import { useCallbackRef } from "./use-callback-ref.mjs";
2
+ import { useEffect } from "react";
3
+
4
+ //#region src/use-escape-keydown.ts
5
+ /**
6
+ * Listens for when the escape key is down
7
+ */
8
+ function useEscapeKeydown(onEscapeKeyDownProp, ownerDocument = globalThis?.document) {
9
+ const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp);
10
+ useEffect(() => {
11
+ const handleKeyDown = (event) => {
12
+ if (event.key === "Escape") onEscapeKeyDown(event);
13
+ };
14
+ ownerDocument.addEventListener("keydown", handleKeyDown);
15
+ return () => {
16
+ ownerDocument.removeEventListener("keydown", handleKeyDown);
17
+ };
18
+ }, [onEscapeKeyDown, ownerDocument]);
19
+ }
20
+
21
+ //#endregion
22
+ export { useEscapeKeydown };
2
23
  //# sourceMappingURL=use-escape-keydown.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-escape-keydown.mjs","names":[],"sources":["../src/use-escape-keydown.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useEffect } from \"react\";\nimport { useCallbackRef } from \"./use-callback-ref\";\n\n/**\n * Listens for when the escape key is down\n */\nexport function useEscapeKeydown(\n onEscapeKeyDownProp?: (event: KeyboardEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp);\n\n useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n onEscapeKeyDown(event);\n }\n };\n\n ownerDocument.addEventListener(\"keydown\", handleKeyDown);\n\n return () => {\n ownerDocument.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [onEscapeKeyDown, ownerDocument]);\n}\n"],"mappings":"0FAwBA,SAAgB,EACd,EACA,EAA0B,YAAY,SACtC,CACA,IAAM,EAAkB,EAAe,EAAoB,CAE3D,MAAgB,CACd,IAAM,EAAiB,GAAyB,CAC1C,EAAM,MAAQ,UAChB,EAAgB,EAAM,EAM1B,OAFA,EAAc,iBAAiB,UAAW,EAAc,KAE3C,CACX,EAAc,oBAAoB,UAAW,EAAc,GAE5D,CAAC,EAAiB,EAAc,CAAC"}
1
+ {"version":3,"file":"use-escape-keydown.mjs","names":[],"sources":["../src/use-escape-keydown.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useEffect } from \"react\";\nimport { useCallbackRef } from \"./use-callback-ref\";\n\n/**\n * Listens for when the escape key is down\n */\nexport function useEscapeKeydown(\n onEscapeKeyDownProp?: (event: KeyboardEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp);\n\n useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n onEscapeKeyDown(event);\n }\n };\n\n ownerDocument.addEventListener(\"keydown\", handleKeyDown);\n\n return () => {\n ownerDocument.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [onEscapeKeyDown, ownerDocument]);\n}\n"],"mappings":";;;;;;;AAwBA,SAAgB,iBACd,qBACA,gBAA0B,YAAY,UACtC;CACA,MAAM,kBAAkB,eAAe,oBAAoB;AAE3D,iBAAgB;EACd,MAAM,iBAAiB,UAAyB;AAC9C,OAAI,MAAM,QAAQ,SAChB,iBAAgB,MAAM;;AAI1B,gBAAc,iBAAiB,WAAW,cAAc;AAExD,eAAa;AACX,iBAAc,oBAAoB,WAAW,cAAc;;IAE5D,CAAC,iBAAiB,cAAc,CAAC"}
@@ -1 +1,27 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./use-isomorphic-layout-effect.cjs`);let n=require(`react`);const r=()=>{throw Error(`Cannot call an event handler while rendering.`)};function i(e){return a(e,r,!0)}function a(e,r,i){let a=(0,n.useRef)(r??e);return t.useIsomorphicLayoutEffect(()=>{a.current=e}),(0,n.useCallback)(i?(...e)=>a.current?.apply(null,e):()=>a.current,[])}exports.useEvent=i;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_use_isomorphic_layout_effect = require('./use-isomorphic-layout-effect.cjs');
3
+ let react = require("react");
4
+
5
+ //#region src/use-event.ts
6
+ const defaultValue = () => {
7
+ throw new Error("Cannot call an event handler while rendering.");
8
+ };
9
+ /**
10
+ * The function returns a memoized event handler.
11
+ *
12
+ * @param callback - The event handler to memoize.
13
+ * @returns A memoized event handler.
14
+ */
15
+ function useEvent(callback) {
16
+ return useGet(callback, defaultValue, true);
17
+ }
18
+ function useGet(currentValue, initialValue, forwardToFunction) {
19
+ const curRef = (0, react.useRef)(initialValue ?? currentValue);
20
+ require_use_isomorphic_layout_effect.useIsomorphicLayoutEffect(() => {
21
+ curRef.current = currentValue;
22
+ });
23
+ return (0, react.useCallback)(forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current, []);
24
+ }
25
+
26
+ //#endregion
27
+ exports.useEvent = useEvent;
@@ -1,2 +1,27 @@
1
- import{useIsomorphicLayoutEffect as e}from"./use-isomorphic-layout-effect.mjs";import{useCallback as t,useRef as n}from"react";const r=()=>{throw Error(`Cannot call an event handler while rendering.`)};function i(e){return a(e,r,!0)}function a(r,i,a){let o=n(i??r);return e(()=>{o.current=r}),t(a?(...e)=>o.current?.apply(null,e):()=>o.current,[])}export{i as useEvent};
1
+ import { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.mjs";
2
+ import { useCallback, useRef } from "react";
3
+
4
+ //#region src/use-event.ts
5
+ const defaultValue = () => {
6
+ throw new Error("Cannot call an event handler while rendering.");
7
+ };
8
+ /**
9
+ * The function returns a memoized event handler.
10
+ *
11
+ * @param callback - The event handler to memoize.
12
+ * @returns A memoized event handler.
13
+ */
14
+ function useEvent(callback) {
15
+ return useGet(callback, defaultValue, true);
16
+ }
17
+ function useGet(currentValue, initialValue, forwardToFunction) {
18
+ const curRef = useRef(initialValue ?? currentValue);
19
+ useIsomorphicLayoutEffect(() => {
20
+ curRef.current = currentValue;
21
+ });
22
+ return useCallback(forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current, []);
23
+ }
24
+
25
+ //#endregion
26
+ export { useEvent };
2
27
  //# sourceMappingURL=use-event.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-event.mjs","names":[],"sources":["../src/use-event.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useCallback, useRef } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"./use-isomorphic-layout-effect\";\n\ntype AnyFunction = (...args: any[]) => any;\n\nconst defaultValue = () => {\n throw new Error(\"Cannot call an event handler while rendering.\");\n};\n\n/**\n * The function returns a memoized event handler.\n *\n * @param callback - The event handler to memoize.\n * @returns A memoized event handler.\n */\nexport function useEvent<T extends AnyFunction>(callback?: T): T {\n return useGet(callback, defaultValue, true) as T;\n}\n\n// keeps a reference to the current value easily\nfunction useGet<A>(\n currentValue: A,\n initialValue?: any,\n forwardToFunction?: boolean\n): () => A {\n const curRef = useRef<any>(initialValue ?? currentValue);\n useIsomorphicLayoutEffect(() => {\n curRef.current = currentValue;\n });\n\n return useCallback(\n forwardToFunction\n ? // eslint-disable-next-line ts/no-unsafe-call\n (...args) => curRef.current?.apply(null, args)\n : () => curRef.current,\n []\n );\n}\n"],"mappings":"+HAuBA,MAAM,MAAqB,CACzB,MAAU,MAAM,gDAAgD,EASlE,SAAgB,EAAgC,EAAiB,CAC/D,OAAO,EAAO,EAAU,EAAc,GAAK,CAI7C,SAAS,EACP,EACA,EACA,EACS,CACT,IAAM,EAAS,EAAY,GAAgB,EAAa,CAKxD,OAJA,MAAgC,CAC9B,EAAO,QAAU,GACjB,CAEK,EACL,GAEK,GAAG,IAAS,EAAO,SAAS,MAAM,KAAM,EAAK,KACxC,EAAO,QACjB,EAAE,CACH"}
1
+ {"version":3,"file":"use-event.mjs","names":[],"sources":["../src/use-event.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useCallback, useRef } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"./use-isomorphic-layout-effect\";\n\ntype AnyFunction = (...args: any[]) => any;\n\nconst defaultValue = () => {\n throw new Error(\"Cannot call an event handler while rendering.\");\n};\n\n/**\n * The function returns a memoized event handler.\n *\n * @param callback - The event handler to memoize.\n * @returns A memoized event handler.\n */\nexport function useEvent<T extends AnyFunction>(callback?: T): T {\n return useGet(callback, defaultValue, true) as T;\n}\n\n// keeps a reference to the current value easily\nfunction useGet<A>(\n currentValue: A,\n initialValue?: any,\n forwardToFunction?: boolean\n): () => A {\n const curRef = useRef<any>(initialValue ?? currentValue);\n useIsomorphicLayoutEffect(() => {\n curRef.current = currentValue;\n });\n\n return useCallback(\n forwardToFunction\n ? // eslint-disable-next-line ts/no-unsafe-call\n (...args) => curRef.current?.apply(null, args)\n : () => curRef.current,\n []\n );\n}\n"],"mappings":";;;;AAuBA,MAAM,qBAAqB;AACzB,OAAM,IAAI,MAAM,gDAAgD;;;;;;;;AASlE,SAAgB,SAAgC,UAAiB;AAC/D,QAAO,OAAO,UAAU,cAAc,KAAK;;AAI7C,SAAS,OACP,cACA,cACA,mBACS;CACT,MAAM,SAAS,OAAY,gBAAgB,aAAa;AACxD,iCAAgC;AAC9B,SAAO,UAAU;GACjB;AAEF,QAAO,YACL,qBAEK,GAAG,SAAS,OAAO,SAAS,MAAM,MAAM,KAAK,SACxC,OAAO,SACjB,EAAE,CACH"}
@@ -1 +1,33 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`);let t=require(`react`);const n=()=>{let[e,n]=(0,t.useState)(!1),r=(0,t.useRef)(null),i=(0,t.useCallback)(()=>{n(!0)},[]),a=(0,t.useCallback)(()=>{n(!1)},[]);return[(0,t.useCallback)(e=>{r.current?.nodeType===Node.ELEMENT_NODE&&(r.current.removeEventListener(`mouseenter`,i),r.current.removeEventListener(`mouseleave`,a)),e?.nodeType===Node.ELEMENT_NODE&&(e.addEventListener(`mouseenter`,i),e.addEventListener(`mouseleave`,a)),r.current=e},[i,a]),e]};exports.useHover=n;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let react = require("react");
3
+
4
+ //#region src/use-hover.ts
5
+ /**
6
+ * A hook that returns tuple containing a ref and a boolean indicating if the element (referenced by the ref) is being hovered.
7
+ *
8
+ * @returns A tuple containing a ref and a boolean indicating if the element is being hovered
9
+ */
10
+ const useHover = () => {
11
+ const [hovering, setHovering] = (0, react.useState)(false);
12
+ const previousNode = (0, react.useRef)(null);
13
+ const handleMouseEnter = (0, react.useCallback)(() => {
14
+ setHovering(true);
15
+ }, []);
16
+ const handleMouseLeave = (0, react.useCallback)(() => {
17
+ setHovering(false);
18
+ }, []);
19
+ return [(0, react.useCallback)((node) => {
20
+ if (previousNode.current?.nodeType === Node.ELEMENT_NODE) {
21
+ previousNode.current.removeEventListener("mouseenter", handleMouseEnter);
22
+ previousNode.current.removeEventListener("mouseleave", handleMouseLeave);
23
+ }
24
+ if (node?.nodeType === Node.ELEMENT_NODE) {
25
+ node.addEventListener("mouseenter", handleMouseEnter);
26
+ node.addEventListener("mouseleave", handleMouseLeave);
27
+ }
28
+ previousNode.current = node;
29
+ }, [handleMouseEnter, handleMouseLeave]), hovering];
30
+ };
31
+
32
+ //#endregion
33
+ exports.useHover = useHover;
@@ -1,2 +1,33 @@
1
- import{useCallback as e,useRef as t,useState as n}from"react";const r=()=>{let[r,i]=n(!1),a=t(null),o=e(()=>{i(!0)},[]),s=e(()=>{i(!1)},[]);return[e(e=>{a.current?.nodeType===Node.ELEMENT_NODE&&(a.current.removeEventListener(`mouseenter`,o),a.current.removeEventListener(`mouseleave`,s)),e?.nodeType===Node.ELEMENT_NODE&&(e.addEventListener(`mouseenter`,o),e.addEventListener(`mouseleave`,s)),a.current=e},[o,s]),r]};export{r as useHover};
1
+ import { useCallback, useRef, useState } from "react";
2
+
3
+ //#region src/use-hover.ts
4
+ /**
5
+ * A hook that returns tuple containing a ref and a boolean indicating if the element (referenced by the ref) is being hovered.
6
+ *
7
+ * @returns A tuple containing a ref and a boolean indicating if the element is being hovered
8
+ */
9
+ const useHover = () => {
10
+ const [hovering, setHovering] = useState(false);
11
+ const previousNode = useRef(null);
12
+ const handleMouseEnter = useCallback(() => {
13
+ setHovering(true);
14
+ }, []);
15
+ const handleMouseLeave = useCallback(() => {
16
+ setHovering(false);
17
+ }, []);
18
+ return [useCallback((node) => {
19
+ if (previousNode.current?.nodeType === Node.ELEMENT_NODE) {
20
+ previousNode.current.removeEventListener("mouseenter", handleMouseEnter);
21
+ previousNode.current.removeEventListener("mouseleave", handleMouseLeave);
22
+ }
23
+ if (node?.nodeType === Node.ELEMENT_NODE) {
24
+ node.addEventListener("mouseenter", handleMouseEnter);
25
+ node.addEventListener("mouseleave", handleMouseLeave);
26
+ }
27
+ previousNode.current = node;
28
+ }, [handleMouseEnter, handleMouseLeave]), hovering];
29
+ };
30
+
31
+ //#endregion
32
+ export { useHover };
2
33
  //# sourceMappingURL=use-hover.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-hover.mjs","names":[],"sources":["../src/use-hover.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useCallback, useRef, useState } from \"react\";\n\n/**\n * A hook that returns tuple containing a ref and a boolean indicating if the element (referenced by the ref) is being hovered.\n *\n * @returns A tuple containing a ref and a boolean indicating if the element is being hovered\n */\nexport const useHover = (): [(node: HTMLElement) => void, boolean] => {\n const [hovering, setHovering] = useState(false);\n const previousNode = useRef<HTMLElement | null>(null);\n\n const handleMouseEnter = useCallback(() => {\n setHovering(true);\n }, []);\n const handleMouseLeave = useCallback(() => {\n setHovering(false);\n }, []);\n\n const customRef = useCallback(\n (node: HTMLElement) => {\n if (previousNode.current?.nodeType === Node.ELEMENT_NODE) {\n previousNode.current.removeEventListener(\n \"mouseenter\",\n handleMouseEnter\n );\n previousNode.current.removeEventListener(\n \"mouseleave\",\n handleMouseLeave\n );\n }\n\n if (node?.nodeType === Node.ELEMENT_NODE) {\n node.addEventListener(\"mouseenter\", handleMouseEnter);\n node.addEventListener(\"mouseleave\", handleMouseLeave);\n }\n\n previousNode.current = node;\n },\n [handleMouseEnter, handleMouseLeave]\n );\n\n return [customRef, hovering];\n};\n"],"mappings":"8DAyBA,MAAa,MAAyD,CACpE,GAAM,CAAC,EAAU,GAAe,EAAS,GAAM,CACzC,EAAe,EAA2B,KAAK,CAE/C,EAAmB,MAAkB,CACzC,EAAY,GAAK,EAChB,EAAE,CAAC,CACA,EAAmB,MAAkB,CACzC,EAAY,GAAM,EACjB,EAAE,CAAC,CAyBN,MAAO,CAvBW,EACf,GAAsB,CACjB,EAAa,SAAS,WAAa,KAAK,eAC1C,EAAa,QAAQ,oBACnB,aACA,EACD,CACD,EAAa,QAAQ,oBACnB,aACA,EACD,EAGC,GAAM,WAAa,KAAK,eAC1B,EAAK,iBAAiB,aAAc,EAAiB,CACrD,EAAK,iBAAiB,aAAc,EAAiB,EAGvD,EAAa,QAAU,GAEzB,CAAC,EAAkB,EAAiB,CACrC,CAEkB,EAAS"}
1
+ {"version":3,"file":"use-hover.mjs","names":[],"sources":["../src/use-hover.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { useCallback, useRef, useState } from \"react\";\n\n/**\n * A hook that returns tuple containing a ref and a boolean indicating if the element (referenced by the ref) is being hovered.\n *\n * @returns A tuple containing a ref and a boolean indicating if the element is being hovered\n */\nexport const useHover = (): [(node: HTMLElement) => void, boolean] => {\n const [hovering, setHovering] = useState(false);\n const previousNode = useRef<HTMLElement | null>(null);\n\n const handleMouseEnter = useCallback(() => {\n setHovering(true);\n }, []);\n const handleMouseLeave = useCallback(() => {\n setHovering(false);\n }, []);\n\n const customRef = useCallback(\n (node: HTMLElement) => {\n if (previousNode.current?.nodeType === Node.ELEMENT_NODE) {\n previousNode.current.removeEventListener(\n \"mouseenter\",\n handleMouseEnter\n );\n previousNode.current.removeEventListener(\n \"mouseleave\",\n handleMouseLeave\n );\n }\n\n if (node?.nodeType === Node.ELEMENT_NODE) {\n node.addEventListener(\"mouseenter\", handleMouseEnter);\n node.addEventListener(\"mouseleave\", handleMouseLeave);\n }\n\n previousNode.current = node;\n },\n [handleMouseEnter, handleMouseLeave]\n );\n\n return [customRef, hovering];\n};\n"],"mappings":";;;;;;;;AAyBA,MAAa,iBAAyD;CACpE,MAAM,CAAC,UAAU,eAAe,SAAS,MAAM;CAC/C,MAAM,eAAe,OAA2B,KAAK;CAErD,MAAM,mBAAmB,kBAAkB;AACzC,cAAY,KAAK;IAChB,EAAE,CAAC;CACN,MAAM,mBAAmB,kBAAkB;AACzC,cAAY,MAAM;IACjB,EAAE,CAAC;AAyBN,QAAO,CAvBW,aACf,SAAsB;AACrB,MAAI,aAAa,SAAS,aAAa,KAAK,cAAc;AACxD,gBAAa,QAAQ,oBACnB,cACA,iBACD;AACD,gBAAa,QAAQ,oBACnB,cACA,iBACD;;AAGH,MAAI,MAAM,aAAa,KAAK,cAAc;AACxC,QAAK,iBAAiB,cAAc,iBAAiB;AACrD,QAAK,iBAAiB,cAAc,iBAAiB;;AAGvD,eAAa,UAAU;IAEzB,CAAC,kBAAkB,iBAAiB,CACrC,EAEkB,SAAS"}
package/dist/use-idle.cjs CHANGED
@@ -1 +1,50 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./helpers/src/throttle.cjs`);let n=require(`react`);const r=(e=1e3*60)=>{let[r,i]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{let n=-1,r=()=>{i(!0)},a=t.throttle(()=>{i(!1),clearTimeout(n),n=setTimeout(r,e)},500),o=()=>{document.hidden||a()};return n=setTimeout(r,e),addEventListener(`mousemove`,a),addEventListener(`mousedown`,a),window.addEventListener(`resize`,a),addEventListener(`keydown`,a),addEventListener(`touchstart`,a),window.addEventListener(`wheel`,a),document.addEventListener(`visibilitychange`,o),()=>{removeEventListener(`mousemove`,a),removeEventListener(`mousedown`,a),window.removeEventListener(`resize`,a),removeEventListener(`keydown`,a),removeEventListener(`touchstart`,a),window.removeEventListener(`wheel`,a),document.removeEventListener(`visibilitychange`,o),clearTimeout(n)}},[e]),r};exports.useIdle=r;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_throttle = require('./helpers/src/throttle.cjs');
3
+ let react = require("react");
4
+
5
+ //#region src/use-idle.ts
6
+ /**
7
+ * A hook that returns a boolean indicating if the user is idle.
8
+ *
9
+ * @param ms - The number of milliseconds to wait before considering the user as idle
10
+ * @returns A boolean indicating if the user is idle
11
+ */
12
+ const useIdle = (ms = 1e3 * 60) => {
13
+ const [idle, setIdle] = (0, react.useState)(false);
14
+ (0, react.useEffect)(() => {
15
+ let timeoutId = -1;
16
+ const handleTimeout = () => {
17
+ setIdle(true);
18
+ };
19
+ const handleEvent = require_throttle.throttle(() => {
20
+ setIdle(false);
21
+ clearTimeout(timeoutId);
22
+ timeoutId = setTimeout(handleTimeout, ms);
23
+ }, 500);
24
+ const handleVisibilityChange = () => {
25
+ if (!document.hidden) handleEvent();
26
+ };
27
+ timeoutId = setTimeout(handleTimeout, ms);
28
+ addEventListener("mousemove", handleEvent);
29
+ addEventListener("mousedown", handleEvent);
30
+ window.addEventListener("resize", handleEvent);
31
+ addEventListener("keydown", handleEvent);
32
+ addEventListener("touchstart", handleEvent);
33
+ window.addEventListener("wheel", handleEvent);
34
+ document.addEventListener("visibilitychange", handleVisibilityChange);
35
+ return () => {
36
+ removeEventListener("mousemove", handleEvent);
37
+ removeEventListener("mousedown", handleEvent);
38
+ window.removeEventListener("resize", handleEvent);
39
+ removeEventListener("keydown", handleEvent);
40
+ removeEventListener("touchstart", handleEvent);
41
+ window.removeEventListener("wheel", handleEvent);
42
+ document.removeEventListener("visibilitychange", handleVisibilityChange);
43
+ clearTimeout(timeoutId);
44
+ };
45
+ }, [ms]);
46
+ return idle;
47
+ };
48
+
49
+ //#endregion
50
+ exports.useIdle = useIdle;