frosty 0.0.111 → 0.0.113

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 (73) hide show
  1. package/dist/_native.d.mts +19 -0
  2. package/dist/_native.d.mts.map +1 -0
  3. package/dist/_native.js +3 -3
  4. package/dist/_native.mjs +4 -4
  5. package/dist/dom.d.mts +15 -0
  6. package/dist/dom.d.mts.map +1 -0
  7. package/dist/dom.js +4 -4
  8. package/dist/dom.mjs +4 -4
  9. package/dist/index.d.mts +551 -0
  10. package/dist/index.d.mts.map +1 -0
  11. package/dist/index.d.ts +8 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +3 -3
  14. package/dist/index.mjs +4 -4
  15. package/dist/internals/common-CpEB3ieX.d.mts +3451 -0
  16. package/dist/internals/common-CpEB3ieX.d.mts.map +1 -0
  17. package/dist/internals/fragment-BlS4iF_x.d.mts +9 -0
  18. package/dist/internals/fragment-BlS4iF_x.d.mts.map +1 -0
  19. package/dist/internals/{fragment-CaAgTjMI.d.ts → fragment-Dch7YNeZ.d.ts} +4 -1
  20. package/dist/internals/{fragment-CaAgTjMI.d.ts.map → fragment-Dch7YNeZ.d.ts.map} +1 -1
  21. package/dist/internals/renderer-BQawOCgo.d.mts +38 -0
  22. package/dist/internals/renderer-BQawOCgo.d.mts.map +1 -0
  23. package/dist/internals/renderer-BelBgEvy.d.mts +47 -0
  24. package/dist/internals/renderer-BelBgEvy.d.mts.map +1 -0
  25. package/dist/internals/{renderer-D042jXUg.mjs → renderer-CA9aKFMW.mjs} +3 -3
  26. package/dist/internals/{renderer-D042jXUg.mjs.map → renderer-CA9aKFMW.mjs.map} +1 -1
  27. package/dist/internals/{renderer-mim3fEAf.js → renderer-CNz1Y3a_.js} +3 -3
  28. package/dist/internals/{renderer-mim3fEAf.js.map → renderer-CNz1Y3a_.js.map} +1 -1
  29. package/dist/internals/{renderer-DUavelz2.mjs → renderer-DowEJaeR.mjs} +4 -4
  30. package/dist/internals/{renderer-DUavelz2.mjs.map → renderer-DowEJaeR.mjs.map} +1 -1
  31. package/dist/internals/{renderer-B04DCuHt.js → renderer-I-1wuWMB.js} +4 -4
  32. package/dist/internals/{renderer-B04DCuHt.js.map → renderer-I-1wuWMB.js.map} +1 -1
  33. package/dist/internals/{runtime-BFi9M0jE.js → runtime-57ivQprw.js} +4 -1
  34. package/dist/internals/runtime-57ivQprw.js.map +1 -0
  35. package/dist/internals/{runtime-BB51vIJ7.mjs → runtime-Dp4_akLf.mjs} +4 -1
  36. package/dist/internals/runtime-Dp4_akLf.mjs.map +1 -0
  37. package/dist/internals/{state-DFlnc6I0.js → state-C9_fGuhZ.js} +9 -2
  38. package/dist/internals/state-C9_fGuhZ.js.map +1 -0
  39. package/dist/internals/{state-YzaxTA1n.mjs → state-DgSrjGGU.mjs} +9 -2
  40. package/dist/internals/state-DgSrjGGU.mjs.map +1 -0
  41. package/dist/internals/{sync-OyR_m41B.js → sync-B7gLfyQK.js} +2 -2
  42. package/dist/internals/{sync-OyR_m41B.js.map → sync-B7gLfyQK.js.map} +1 -1
  43. package/dist/internals/{sync-CxgNMmpR.mjs → sync-CeJllG9M.mjs} +2 -2
  44. package/dist/internals/{sync-CxgNMmpR.mjs.map → sync-CeJllG9M.mjs.map} +1 -1
  45. package/dist/internals/utils-CWsh4Zpu.d.mts +7 -0
  46. package/dist/internals/utils-CWsh4Zpu.d.mts.map +1 -0
  47. package/dist/jsx-dev-runtime.d.mts +11 -0
  48. package/dist/jsx-dev-runtime.d.mts.map +1 -0
  49. package/dist/jsx-dev-runtime.d.ts +1 -1
  50. package/dist/jsx-dev-runtime.js +1 -1
  51. package/dist/jsx-dev-runtime.mjs +1 -1
  52. package/dist/jsx-runtime.d.mts +23 -0
  53. package/dist/jsx-runtime.d.mts.map +1 -0
  54. package/dist/jsx-runtime.d.ts +1 -1
  55. package/dist/jsx-runtime.js +1 -1
  56. package/dist/jsx-runtime.mjs +2 -2
  57. package/dist/server-dom.d.mts +15 -0
  58. package/dist/server-dom.d.mts.map +1 -0
  59. package/dist/server-dom.js +4 -4
  60. package/dist/server-dom.mjs +4 -4
  61. package/dist/web.d.mts +211 -0
  62. package/dist/web.d.mts.map +1 -0
  63. package/dist/web.d.ts +99 -0
  64. package/dist/web.d.ts.map +1 -1
  65. package/dist/web.js +104 -5
  66. package/dist/web.js.map +1 -1
  67. package/dist/web.mjs +105 -6
  68. package/dist/web.mjs.map +1 -1
  69. package/package.json +5 -17
  70. package/dist/internals/runtime-BB51vIJ7.mjs.map +0 -1
  71. package/dist/internals/runtime-BFi9M0jE.js.map +0 -1
  72. package/dist/internals/state-DFlnc6I0.js.map +0 -1
  73. package/dist/internals/state-YzaxTA1n.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-CWsh4Zpu.d.mts","sources":["../../src/core/utils.ts"],"sourcesContent":["//\n// utils.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { Ref } from './types/common';\n\nexport const mergeRefs = <T>(...refs: (Ref<T> | null | undefined)[]) => (x: T) => {\n for (const ref of refs) {\n if (_.isNil(ref)) continue;\n else if (typeof ref === 'function') ref(x);\n else if (typeof ref === 'object') ref.current = x;\n else {\n console.error(`mergeRefs cannot handle Refs of type boolean, number or string, received ref ${ref}`);\n }\n }\n}\n\nlet counter = 0;\n\nexport const uniqueId = () => `${Date.now().toString(36)}${(counter++).toString(36)}${Math.random().toString(36).slice(2)}`;\n"],"names":[],"mappings":";;AACO,cAAA,SAAA,gBAAA,GAAA;AACA,cAAA,QAAA;;;;"}
@@ -0,0 +1,11 @@
1
+ import { _ as _ElementType, c as PropsType, C as ComponentNode } from './internals/common-CpEB3ieX.mjs';
2
+ export { JSX, jsx, jsxs } from './jsx-runtime.mjs';
3
+ export { F as Fragment } from './internals/fragment-BlS4iF_x.mjs';
4
+ import '@o2ter/utils-js';
5
+ import 'lodash';
6
+ import 'csstype';
7
+
8
+ declare function jsxDEV(type: _ElementType, props: PropsType, key?: string | number, isStaticChildren?: boolean, source?: any, self?: any): ComponentNode;
9
+
10
+ export { jsxDEV };
11
+ //# sourceMappingURL=jsx-dev-runtime.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-dev-runtime.d.mts","sources":["../src/jsx-dev-runtime.ts"],"sourcesContent":["//\n// jsx-dev-runtime.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport { ComponentNode } from './core/types/component';\nimport { _ElementType, PropsType } from './core/types/runtime';\nimport { jsx } from './jsx-runtime';\n\nexport * from './jsx-runtime';\n\nexport function jsxDEV(\n type: _ElementType,\n props: PropsType,\n key?: string | number,\n isStaticChildren?: boolean,\n source?: any,\n self?: any\n): ComponentNode {\n return jsx(type, props, key);\n}\n"],"names":[],"mappings":";;;;;;;AAGO,iBAAA,MAAA,OAAA,YAAA,SAAA,SAAA,gFAAA,aAAA;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { _ as _ElementType, c as PropsType, C as ComponentNode } from './internals/common-CpEB3ieX.js';
2
2
  export { JSX, jsx, jsxs } from './jsx-runtime.js';
3
- export { F as Fragment } from './internals/fragment-CaAgTjMI.js';
3
+ export { F as Fragment } from './internals/fragment-Dch7YNeZ.js';
4
4
  import '@o2ter/utils-js';
5
5
  import 'lodash';
6
6
  import 'csstype';
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var jsxRuntime = require('./jsx-runtime.js');
4
- var runtime = require('./internals/runtime-BFi9M0jE.js');
4
+ var runtime = require('./internals/runtime-57ivQprw.js');
5
5
  require('lodash');
6
6
 
7
7
  //
@@ -1,6 +1,6 @@
1
1
  import { jsx } from './jsx-runtime.mjs';
2
2
  export { JSX, jsxs } from './jsx-runtime.mjs';
3
- export { F as Fragment } from './internals/runtime-BB51vIJ7.mjs';
3
+ export { F as Fragment } from './internals/runtime-Dp4_akLf.mjs';
4
4
  import 'lodash';
5
5
 
6
6
  //
@@ -0,0 +1,23 @@
1
+ import { n as _IntrinsicElements, o as _IntrinsicAttributes, _ as _ElementType, C as ComponentNode, c as PropsType } from './internals/common-CpEB3ieX.mjs';
2
+ export { F as Fragment } from './internals/fragment-BlS4iF_x.mjs';
3
+ import '@o2ter/utils-js';
4
+ import 'lodash';
5
+ import 'csstype';
6
+
7
+ declare namespace JSX {
8
+ type IntrinsicElements = _IntrinsicElements;
9
+ type IntrinsicAttributes = _IntrinsicAttributes;
10
+ type ElementType = _ElementType;
11
+ type Element = ComponentNode;
12
+ type ElementChildrenAttribute = {
13
+ children: {};
14
+ };
15
+ }
16
+ declare const JSX: Readonly<{
17
+ Element: typeof ComponentNode;
18
+ }>;
19
+ declare function jsx(type: _ElementType, props: PropsType, key?: string | number): ComponentNode;
20
+ declare const jsxs: typeof jsx;
21
+
22
+ export { JSX, jsx, jsxs };
23
+ //# sourceMappingURL=jsx-runtime.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-runtime.d.mts","sources":["../src/jsx-runtime.ts"],"sourcesContent":["//\n// jsx-runtime.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport { ComponentNode } from './core/types/component';\nimport { _createElement, _ElementType, _IntrinsicAttributes, _IntrinsicElements, PropsType } from './core/types/runtime';\n\nexport { Fragment } from './core/components';\n\nexport declare namespace JSX {\n type IntrinsicElements = _IntrinsicElements;\n type IntrinsicAttributes = _IntrinsicAttributes;\n type ElementType = _ElementType;\n type Element = ComponentNode;\n type ElementChildrenAttribute = { children: {}; };\n};\n\nexport const JSX = Object.freeze({\n Element: ComponentNode,\n});\n\nexport function jsx(\n type: _ElementType,\n props: PropsType,\n key?: string | number\n): ComponentNode {\n return _createElement(type, { ...props, key });\n}\n\nexport const jsxs = jsx;\n"],"names":[],"mappings":";;;;;;AAGO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACO;AACA;;"}
@@ -1,5 +1,5 @@
1
1
  import { n as _IntrinsicElements, o as _IntrinsicAttributes, _ as _ElementType, C as ComponentNode, c as PropsType } from './internals/common-CpEB3ieX.js';
2
- export { F as Fragment } from './internals/fragment-CaAgTjMI.js';
2
+ export { F as Fragment } from './internals/fragment-Dch7YNeZ.js';
3
3
  import '@o2ter/utils-js';
4
4
  import 'lodash';
5
5
  import 'csstype';
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var runtime = require('./internals/runtime-BFi9M0jE.js');
3
+ var runtime = require('./internals/runtime-57ivQprw.js');
4
4
  require('lodash');
5
5
 
6
6
  //
@@ -1,5 +1,5 @@
1
- import { C as ComponentNode, _ as _createElement } from './internals/runtime-BB51vIJ7.mjs';
2
- export { F as Fragment } from './internals/runtime-BB51vIJ7.mjs';
1
+ import { C as ComponentNode, _ as _createElement } from './internals/runtime-Dp4_akLf.mjs';
2
+ export { F as Fragment } from './internals/runtime-Dp4_akLf.mjs';
3
3
  import 'lodash';
4
4
 
5
5
  //
@@ -0,0 +1,15 @@
1
+ import { JSDOM } from 'jsdom';
2
+ export * from 'jsdom';
3
+ import { _ as _DOMRenderer } from './internals/renderer-BQawOCgo.mjs';
4
+ import './internals/common-CpEB3ieX.mjs';
5
+ import '@o2ter/utils-js';
6
+ import 'lodash';
7
+ import 'csstype';
8
+ import './internals/renderer-BelBgEvy.mjs';
9
+
10
+ declare class ServerDOMRenderer extends _DOMRenderer {
11
+ constructor(dom?: JSDOM);
12
+ }
13
+
14
+ export { ServerDOMRenderer };
15
+ //# sourceMappingURL=server-dom.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-dom.d.mts","sources":["../src/renderer/server-dom.ts"],"sourcesContent":["//\n// dom.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { JSDOM } from 'jsdom';\nimport { _DOMRenderer } from './common';\n\nexport * from 'jsdom';\n\nexport class ServerDOMRenderer extends _DOMRenderer {\n\n constructor(dom = new JSDOM()) {\n super(dom.window);\n }\n\n /** @internal */\n get _server(): boolean {\n return true;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAGO,cAAA,iBAAA,SAAA,YAAA;AACP,sBAAA,KAAA;AACA;;;;"}
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var jsdom = require('jsdom');
4
- var renderer = require('./internals/renderer-B04DCuHt.js');
4
+ var renderer = require('./internals/renderer-I-1wuWMB.js');
5
5
  require('lodash');
6
6
  require('myers.js');
7
- require('./internals/renderer-mim3fEAf.js');
8
- require('./internals/state-DFlnc6I0.js');
9
- require('./internals/runtime-BFi9M0jE.js');
7
+ require('./internals/renderer-CNz1Y3a_.js');
8
+ require('./internals/state-C9_fGuhZ.js');
9
+ require('./internals/runtime-57ivQprw.js');
10
10
  require('nextick');
11
11
  require('postcss');
12
12
  require('postcss-js');
@@ -1,11 +1,11 @@
1
1
  import { JSDOM } from 'jsdom';
2
2
  export * from 'jsdom';
3
- import { _ as _DOMRenderer } from './internals/renderer-DUavelz2.mjs';
3
+ import { _ as _DOMRenderer } from './internals/renderer-DowEJaeR.mjs';
4
4
  import 'lodash';
5
5
  import 'myers.js';
6
- import './internals/renderer-D042jXUg.mjs';
7
- import './internals/state-YzaxTA1n.mjs';
8
- import './internals/runtime-BB51vIJ7.mjs';
6
+ import './internals/renderer-CA9aKFMW.mjs';
7
+ import './internals/state-DgSrjGGU.mjs';
8
+ import './internals/runtime-Dp4_akLf.mjs';
9
9
  import 'nextick';
10
10
  import 'postcss';
11
11
  import 'postcss-js';
package/dist/web.d.mts ADDED
@@ -0,0 +1,211 @@
1
+ import { S as SetStateAction, R as RefObject } from './internals/common-CpEB3ieX.mjs';
2
+ import * as jsdom from 'jsdom';
3
+ export { D as DOMNativeNode, _ as _DOMRenderer } from './internals/renderer-BQawOCgo.mjs';
4
+ import '@o2ter/utils-js';
5
+ import 'lodash';
6
+ import 'csstype';
7
+ import './internals/renderer-BelBgEvy.mjs';
8
+
9
+ /**
10
+ * Hook to access the current document object in a web renderer.
11
+ *
12
+ * @returns The current document object.
13
+ * @throws Error if used outside of a render function or with an unsupported renderer.
14
+ */
15
+ declare const useDocument: () => Document;
16
+
17
+ /**
18
+ * A hook that provides the current browser location and methods to manipulate the browser history.
19
+ *
20
+ * @returns An object with the following properties and methods:
21
+ * - `hash`: The fragment identifier of the URL.
22
+ * - `host`: The hostname and port number.
23
+ * - `hostname`: The domain name.
24
+ * - `href`: The full URL.
25
+ * - `origin`: The protocol, hostname, and port.
26
+ * - `pathname`: The path of the URL.
27
+ * - `port`: The port number.
28
+ * - `protocol`: The protocol scheme.
29
+ * - `search`: The query string.
30
+ * - `state`: The current state object associated with the history entry.
31
+ * - `back()`: Navigates to the previous entry in the history stack.
32
+ * - `forward()`: Navigates to the next entry in the history stack.
33
+ * - `pushState(data, url)`: Pushes a new entry onto the history stack.
34
+ * - `replaceState(data, url)`: Replaces the current history entry.
35
+ *
36
+ * The hook subscribes to changes in the browser's history and location, causing components to re-render when navigation occurs.
37
+ *
38
+ * @example
39
+ * const location = useLocation();
40
+ * console.log(location.pathname); // e.g., "/about"
41
+ * location.pushState({ some: 'state' }, '/new-path');
42
+ */
43
+ declare const useLocation: () => {
44
+ state: any;
45
+ back: () => void;
46
+ forward: () => void;
47
+ pushState: (data: any, url?: string | URL | null) => void;
48
+ replaceState: (data: any, url?: string | URL | null) => void;
49
+ origin: string;
50
+ hash: string;
51
+ host: string;
52
+ hostname: string;
53
+ href: string;
54
+ pathname: string;
55
+ port: string;
56
+ protocol: string;
57
+ search: string;
58
+ };
59
+ /**
60
+ * A hook for reading and updating the URL's query string (search parameters).
61
+ *
62
+ * @returns A tuple:
63
+ * - The first element is a `URLSearchParams` instance representing the current query string.
64
+ * - The second element is a function to update the search parameters, which accepts any valid
65
+ * `URLSearchParams` initializer (string, array, or object).
66
+ *
67
+ * Updating the search parameters will push a new history entry and update the URL in the address bar.
68
+ *
69
+ * @example
70
+ * const [searchParams, setSearchParams] = useSearchParams();
71
+ * const page = searchParams.get('page');
72
+ * setSearchParams({ page: '2', filter: 'active' });
73
+ */
74
+ declare const useSearchParams: () => readonly [URLSearchParams, (dispatch: SetStateAction<string | string[][] | Record<string, string> | URLSearchParams | undefined, URLSearchParams>, config?: {
75
+ replace?: boolean;
76
+ }) => void];
77
+
78
+ /**
79
+ * A hook that sets up a ResizeObserver on the given target element.
80
+ *
81
+ * @param target - The target element or a ref object containing the target element.
82
+ * @param callback - The callback function to be called when the target element is resized.
83
+ * @param options - Optional ResizeObserverOptions to configure the observer.
84
+ */
85
+ declare const useResizeObserver: (target: RefObject<Element | null | undefined> | Element | null | undefined, callback: (entry: ResizeObserverEntry) => void, options?: ResizeObserverOptions) => void;
86
+ /**
87
+ * A hook that sets up an IntersectionObserver on the given target element.
88
+ *
89
+ * @param target - The target element or a ref object containing the target element.
90
+ * @param callback - The callback function to be called when the target element's intersection changes.
91
+ */
92
+ declare const useIntersectionObserver: (target: RefObject<Element | null | undefined> | Element | null | undefined, callback: (entry: IntersectionObserverEntry) => void) => void;
93
+ /**
94
+ * A hook that sets up a MutationObserver on the given target node.
95
+ *
96
+ * @param target - The target node or a ref object containing the target node.
97
+ * @param callback - The callback function to be called when mutations are observed.
98
+ * @param options - Optional MutationObserverInit to configure the observer.
99
+ */
100
+ declare const useMutationObserver: (target: RefObject<Node | null | undefined> | Node | null | undefined, callback: MutationCallback, options?: MutationObserverInit) => void;
101
+ /**
102
+ * A hook that sets up a PerformanceObserver with the given callback and options.
103
+ *
104
+ * @param callback - The callback function to be called when performance entries are observed.
105
+ * @param options - Optional PerformanceObserverInit to configure the observer.
106
+ */
107
+ declare const usePerformanceObserver: (callback: PerformanceObserverCallback, options?: PerformanceObserverInit) => void;
108
+
109
+ /**
110
+ * A hook that returns the current online status of the browser.
111
+ * It listens to the 'online' and 'offline' events to update the status.
112
+ *
113
+ * @returns A boolean indicating whether the browser is online.
114
+ */
115
+ declare const useOnline: () => boolean;
116
+
117
+ /**
118
+ * A hook to manage server-side resources in a web renderer.
119
+ * It allows tracking and retrieving resources identified by a key.
120
+ *
121
+ * @param key - The unique key for the resource.
122
+ * @param resource - An optional function that returns the resource string when called on the server side.
123
+ * @returns The resource string if available, otherwise undefined.
124
+ * @throws Error if used outside of a render function or with an unsupported renderer.
125
+ */
126
+ declare const useServerResource: (key: string, resource?: () => string) => string | undefined;
127
+
128
+ /**
129
+ * A hook to manage a value in localStorage.
130
+ * It provides a stateful value and a function to update it.
131
+ *
132
+ * @param key - The key in localStorage to manage.
133
+ * @param initialValue - An optional initial value if the key does not exist in localStorage.
134
+ * @returns A tuple containing the current value and a function to update it.
135
+ */
136
+ declare const useLocalStorage: (key: string, initialValue?: string | null) => readonly [string | null, (v: SetStateAction<string | null | undefined>) => void];
137
+ /**
138
+ * A hook to manage a value in sessionStorage.
139
+ * It provides a stateful value and a function to update it.
140
+ *
141
+ * @param key - The key in sessionStorage to manage.
142
+ * @param initialValue - An optional initial value if the key does not exist in sessionStorage.
143
+ * @returns A tuple containing the current value and a function to update it.
144
+ */
145
+ declare const useSessionStorage: (key: string, initialValue?: string | null) => readonly [string | null, (v: SetStateAction<string | null | undefined>) => void];
146
+
147
+ /**
148
+ * A hook to get the current visibility state of the document.
149
+ * It listens to the 'visibilitychange' event to update the state.
150
+ *
151
+ * @returns A string indicating the current visibility state: 'active', 'inactive', 'background', or 'unknown'.
152
+ */
153
+ declare const useVisibility: () => "active" | "inactive" | "background" | "unknown";
154
+
155
+ /**
156
+ * Hook to access the current window object in a web renderer.
157
+ *
158
+ * @returns The current window object.
159
+ * @throws Error if used outside of a render function or with an unsupported renderer.
160
+ */
161
+ declare const useWindow: () => Window | jsdom.DOMWindow;
162
+ /**
163
+ * A hook that provides various metrics of the window object.
164
+ * It listens to the 'resize' event to update the metrics.
165
+ *
166
+ * @returns An object containing safe area insets, device pixel ratio, outer and inner dimensions of the window.
167
+ */
168
+ declare const useWindowMetrics: () => {
169
+ safeAreaInsets: {
170
+ top: number;
171
+ left: number;
172
+ right: number;
173
+ bottom: number;
174
+ };
175
+ devicePixelRatio: number;
176
+ outerWidth: number;
177
+ outerHeight: number;
178
+ innerWidth: number;
179
+ innerHeight: number;
180
+ };
181
+ /**
182
+ * A hook that provides metrics of the visual viewport.
183
+ * It listens to the 'resize' event of the visual viewport to update the metrics.
184
+ *
185
+ * @returns An object containing width, height, and scale of the visual viewport.
186
+ */
187
+ declare const useVisualViewportMetrics: () => {
188
+ width: number;
189
+ height: number;
190
+ scale: number;
191
+ } | null;
192
+ /**
193
+ * A hook that provides the current scroll position of the window.
194
+ * It listens to the 'scroll' event to update the position.
195
+ *
196
+ * @returns An object containing scrollX and scrollY values.
197
+ */
198
+ declare const useWindowScroll: () => {
199
+ scrollX: number;
200
+ scrollY: number;
201
+ };
202
+ /**
203
+ * A hook that detects the user's preferred color scheme (light or dark).
204
+ * It listens to changes in the '(prefers-color-scheme: dark)' media query.
205
+ *
206
+ * @returns A string indicating the current color scheme: 'light' or 'dark'.
207
+ */
208
+ declare const useColorScheme: () => "dark" | "light";
209
+
210
+ export { useColorScheme, useDocument, useIntersectionObserver, useLocalStorage, useLocation, useMutationObserver, useOnline, usePerformanceObserver, useResizeObserver, useSearchParams, useServerResource, useSessionStorage, useVisibility, useVisualViewportMetrics, useWindow, useWindowMetrics, useWindowScroll };
211
+ //# sourceMappingURL=web.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.d.mts","sources":["../src/web/document.ts","../src/web/location.ts","../src/web/observer.ts","../src/web/online.ts","../src/web/server.ts","../src/web/storage.ts","../src/web/visibility.ts","../src/web/window.ts"],"sourcesContent":["//\n// document.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { reconciler } from '../core/reconciler/state';\nimport { _DOMRenderer } from '../renderer/common';\n\n/**\n * Hook to access the current document object in a web renderer.\n * \n * @returns The current document object.\n * @throws Error if used outside of a render function or with an unsupported renderer.\n */\nexport const useDocument = () => {\n const state = reconciler.currentHookState;\n if (!state) throw Error('useDocument must be used within a render function.');\n if (state.renderer instanceof _DOMRenderer) {\n return state.renderer.document;\n } else {\n throw Error('Unsupported renderer.');\n }\n}","//\n// location.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { useMemo } from '../core/hooks/memo';\nimport { useCallback } from '../core/hooks/callback';\nimport { useSyncExternalStore } from '../core/hooks/sync';\nimport { EventEmitter } from '../core/reconciler/events';\nimport { SetStateAction } from '../core/types/common';\nimport { useWindow } from './window';\n\nconst emitters = new WeakMap<Document, EventEmitter>();\nconst emitterFor = (document: Document) => {\n if (!emitters.has(document)) emitters.set(document, new EventEmitter());\n return emitters.get(document)!;\n}\n\n/**\n * A hook that provides the current browser location and methods to manipulate the browser history.\n *\n * @returns An object with the following properties and methods:\n * - `hash`: The fragment identifier of the URL.\n * - `host`: The hostname and port number.\n * - `hostname`: The domain name.\n * - `href`: The full URL.\n * - `origin`: The protocol, hostname, and port.\n * - `pathname`: The path of the URL.\n * - `port`: The port number.\n * - `protocol`: The protocol scheme.\n * - `search`: The query string.\n * - `state`: The current state object associated with the history entry.\n * - `back()`: Navigates to the previous entry in the history stack.\n * - `forward()`: Navigates to the next entry in the history stack.\n * - `pushState(data, url)`: Pushes a new entry onto the history stack.\n * - `replaceState(data, url)`: Replaces the current history entry.\n *\n * The hook subscribes to changes in the browser's history and location, causing components to re-render when navigation occurs.\n *\n * @example\n * const location = useLocation();\n * console.log(location.pathname); // e.g., \"/about\"\n * location.pushState({ some: 'state' }, '/new-path');\n */\nexport const useLocation = () => {\n const window = useWindow();\n const emitter = emitterFor(window.document);\n const result = (history?: History) => ({\n ..._.pick(window.document.location, 'hash', 'host', 'hostname', 'href', 'origin', 'pathname', 'port', 'protocol', 'search'),\n state: history?.state ?? null,\n back: () => {\n history?.back();\n },\n forward: () => {\n history?.forward();\n emitter.emit('change');\n },\n pushState: (data: any, url?: string | URL | null) => {\n history?.pushState(data, '', url);\n emitter.emit('change');\n },\n replaceState: (data: any, url?: string | URL | null) => {\n history?.replaceState(data, '', url);\n emitter.emit('change');\n },\n });\n return useSyncExternalStore((onStoreChange) => {\n window.addEventListener('popstate', onStoreChange);\n const event = emitter.register('change', onStoreChange);\n return () => {\n window.removeEventListener('popstate', onStoreChange);\n event.remove();\n }\n }, () => result(window.history));\n}\n\n/**\n * A hook for reading and updating the URL's query string (search parameters).\n *\n * @returns A tuple:\n * - The first element is a `URLSearchParams` instance representing the current query string.\n * - The second element is a function to update the search parameters, which accepts any valid\n * `URLSearchParams` initializer (string, array, or object).\n *\n * Updating the search parameters will push a new history entry and update the URL in the address bar.\n *\n * @example\n * const [searchParams, setSearchParams] = useSearchParams();\n * const page = searchParams.get('page');\n * setSearchParams({ page: '2', filter: 'active' });\n */\nexport const useSearchParams = () => {\n const location = useLocation();\n const searchParams = useMemo(() => new URLSearchParams(location.search), [location.search]);\n type URLSearchParamsInit = ConstructorParameters<typeof URLSearchParams>[0];\n const setSearchParams = useCallback((\n dispatch: SetStateAction<URLSearchParamsInit, URLSearchParams>,\n config?: {\n replace?: boolean;\n },\n ) => {\n const params = _.isFunction(dispatch) ? dispatch(new URLSearchParams(location.search)) : dispatch;\n const newParams = new URLSearchParams(params);\n if (config?.replace === false) {\n location.pushState(location.state, `?${newParams.toString()}`);\n } else {\n location.replaceState(location.state, `?${newParams.toString()}`);\n }\n });\n return [searchParams, setSearchParams] as const;\n}\n","//\n// observer.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { useEffect } from '../core/hooks/effect';\nimport { useCallback } from '../core/hooks/callback';\nimport { RefObject } from '../core/types/common';\n\ninterface _Observer<T> {\n observe(target: Element, options?: T): void;\n unobserve(target: Element): void;\n}\n\nconst createObserver = <E extends { target: Element; }, T>(\n constructor: new (callback: (entries: E[]) => void) => _Observer<T>\n) => {\n const listeners = new WeakMap<Element, ((entry: E) => void)[]>();\n const observer = new constructor((entries) => {\n for (const entry of entries) {\n for (const listener of listeners.get(entry.target) ?? []) {\n (async () => {\n try {\n await listener(entry);\n } catch (e) {\n console.error(e);\n }\n })();\n }\n }\n });\n return {\n observe: (target: Element, callback: (entry: E) => void, options?: T) => {\n observer.observe(target, options);\n listeners.set(target, [...listeners.get(target) ?? [], callback]);\n },\n unobserve: (target: Element, callback: (entry: E) => void) => {\n const list = _.filter(listeners.get(target), x => x !== callback);\n listeners.set(target, list);\n if (_.isEmpty(list)) observer.unobserve?.(target);\n },\n };\n};\n\nconst observer = typeof window === 'undefined' ? undefined : {\n resize: createObserver(ResizeObserver),\n intersection: createObserver(IntersectionObserver),\n};\n\n/**\n * A hook that sets up a ResizeObserver on the given target element.\n * \n * @param target - The target element or a ref object containing the target element.\n * @param callback - The callback function to be called when the target element is resized.\n * @param options - Optional ResizeObserverOptions to configure the observer.\n */\nexport const useResizeObserver = (\n target: RefObject<Element | null | undefined> | Element | null | undefined,\n callback: (entry: ResizeObserverEntry) => void,\n options?: ResizeObserverOptions,\n) => {\n const _callback = useCallback(callback);\n useEffect(() => {\n const _target = target && 'current' in target ? target.current : target;\n if (!observer || !_target) return;\n observer.resize.observe(_target, _callback, options);\n return () => observer.resize.unobserve(_target, _callback);\n }, [target]);\n}\n\n/**\n * A hook that sets up an IntersectionObserver on the given target element.\n * \n * @param target - The target element or a ref object containing the target element.\n * @param callback - The callback function to be called when the target element's intersection changes.\n */\nexport const useIntersectionObserver = (\n target: RefObject<Element | null | undefined> | Element | null | undefined,\n callback: (entry: IntersectionObserverEntry) => void,\n) => {\n const _callback = useCallback(callback);\n useEffect(() => {\n const _target = target && 'current' in target ? target.current : target;\n if (!observer || !_target) return;\n observer.intersection.observe(_target, _callback);\n return () => observer.intersection.unobserve(_target, _callback);\n }, [target]);\n}\n\n/**\n * A hook that sets up a MutationObserver on the given target node.\n * \n * @param target - The target node or a ref object containing the target node.\n * @param callback - The callback function to be called when mutations are observed.\n * @param options - Optional MutationObserverInit to configure the observer.\n */\nexport const useMutationObserver = (\n target: RefObject<Node | null | undefined> | Node | null | undefined,\n callback: MutationCallback,\n options?: MutationObserverInit,\n) => {\n const _callback = useCallback(callback);\n useEffect(() => {\n const _target = target && 'current' in target ? target.current : target;\n if (typeof window === 'undefined' || !_target) return;\n const observer = new MutationObserver(_callback);\n observer.observe(_target, options);\n return () => observer.disconnect();\n }, [target]);\n}\n\n/**\n * A hook that sets up a PerformanceObserver with the given callback and options.\n * \n * @param callback - The callback function to be called when performance entries are observed.\n * @param options - Optional PerformanceObserverInit to configure the observer.\n */\nexport const usePerformanceObserver = (\n callback: PerformanceObserverCallback,\n options?: PerformanceObserverInit,\n) => {\n const _callback = useCallback(callback);\n useEffect(() => {\n if (typeof window === 'undefined') return;\n const observer = new PerformanceObserver(_callback);\n observer.observe(options);\n return () => observer.disconnect();\n }, []);\n}\n","//\n// online.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { useSyncExternalStore } from '../core/hooks/sync';\n\n/**\n * A hook that returns the current online status of the browser.\n * It listens to the 'online' and 'offline' events to update the status.\n * \n * @returns A boolean indicating whether the browser is online.\n */\nexport const useOnline = () => useSyncExternalStore((onStoreChange) => {\n window.addEventListener('offline', onStoreChange);\n window.addEventListener('online', onStoreChange);\n return () => {\n window.removeEventListener('offline', onStoreChange);\n window.removeEventListener('online', onStoreChange);\n };\n}, () => navigator.onLine, () => false);","//\n// server.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { reconciler } from '../core/reconciler/state';\nimport { _DOMRenderer } from '../renderer/common';\nimport { decompress } from '../renderer/minify/decompress';\n\nconst decodedSsrData = new WeakMap<Document, any>();\n\n/**\n * A hook to manage server-side resources in a web renderer.\n * It allows tracking and retrieving resources identified by a key.\n * \n * @param key - The unique key for the resource.\n * @param resource - An optional function that returns the resource string when called on the server side.\n * @returns The resource string if available, otherwise undefined.\n * @throws Error if used outside of a render function or with an unsupported renderer.\n */\nexport const useServerResource = (key: string, resource?: () => string): string | undefined => {\n const state = reconciler.currentHookState;\n if (!state) throw Error('useServerResource must be used within a render function.');\n if (state.renderer instanceof _DOMRenderer) {\n if (state.renderer._server) {\n const data = resource?.();\n if (!_.isString(data)) throw Error('Invalid return type of resource');\n state.renderer._tracked_server_resource.set(key, data);\n return data;\n } else {\n const cached = decodedSsrData.get(state.renderer.document);\n if (!_.isNil(cached)) return cached[key];\n const ssrData = state.renderer.document.querySelector('script[data-frosty-ssr-data]');\n if (ssrData instanceof HTMLElement) {\n try {\n const decoded = JSON.parse(decompress(ssrData.innerText.trim()));\n decodedSsrData.set(state.renderer.document, decoded);\n return decoded[key];\n } catch (e) {\n console.error(e);\n decodedSsrData.set(state.renderer.document, {});\n }\n ssrData.remove();\n } else {\n decodedSsrData.set(state.renderer.document, {});\n }\n }\n } else {\n throw Error('Unsupported renderer.');\n }\n}\n","//\n// storage.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { useSyncExternalStore } from '../core/hooks/sync';\nimport { useCallback } from '../core/hooks/callback';\nimport { SetStateAction } from '../core/types/common';\nimport { EventEmitter } from '../core/reconciler/events';\n\nconst emitters = new WeakMap<Storage, EventEmitter>();\nconst emitterFor = (storage: Storage) => {\n if (!emitters.has(storage)) emitters.set(storage, new EventEmitter());\n return emitters.get(storage)!;\n}\n\nconst _useStorage = (\n storage: () => Storage,\n key: string,\n initialValue?: string | null\n) => {\n const state = useSyncExternalStore((onStoreChange) => {\n const _storage = storage();\n const emitter = emitterFor(_storage);\n const callback = (ev: StorageEvent) => { \n if (!ev.storageArea || ev.storageArea === _storage) onStoreChange();\n };\n window.addEventListener('storage', callback);\n const event = emitter.register('change', onStoreChange);\n return () => {\n window.removeEventListener('storage', callback);\n event.remove();\n }\n }, () => storage().getItem(key), () => undefined);\n const setState = useCallback((v: SetStateAction<string | null | undefined>) => {\n try {\n const _storage = storage();\n const newValue = _.isFunction(v) ? v(state) : v;\n if (_.isNil(newValue)) {\n _storage.removeItem(key);\n } else {\n _storage.setItem(key, newValue);\n }\n const emitter = emitterFor(_storage);\n emitter.emit('change');\n } catch (e) {\n console.error(e);\n }\n }, [key]);\n return [state ?? initialValue ?? null, setState] as const;\n}\n\n/**\n * A hook to manage a value in localStorage.\n * It provides a stateful value and a function to update it.\n * \n * @param key - The key in localStorage to manage.\n * @param initialValue - An optional initial value if the key does not exist in localStorage.\n * @returns A tuple containing the current value and a function to update it.\n */\nexport const useLocalStorage = (\n key: string,\n initialValue?: string | null\n) => _useStorage(() => window.localStorage, key, initialValue);\n\n/** \n * A hook to manage a value in sessionStorage.\n * It provides a stateful value and a function to update it.\n * \n * @param key - The key in sessionStorage to manage.\n * @param initialValue - An optional initial value if the key does not exist in sessionStorage.\n * @returns A tuple containing the current value and a function to update it.\n */\nexport const useSessionStorage = (\n key: string,\n initialValue?: string | null\n) => _useStorage(() => window.sessionStorage, key, initialValue);\n","//\n// visibility.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { useSyncExternalStore } from '../core/hooks/sync';\nimport { useDocument } from './document';\n\n/**\n * A hook to get the current visibility state of the document.\n * It listens to the 'visibilitychange' event to update the state.\n * \n * @returns A string indicating the current visibility state: 'active', 'inactive', 'background', or 'unknown'.\n */\nexport const useVisibility = () => {\n const document = useDocument();\n return useSyncExternalStore((onStoreChange) => {\n document.addEventListener('visibilitychange', onStoreChange);\n return () => {\n document.removeEventListener('visibilitychange', onStoreChange);\n }\n }, () => {\n if (document.hasFocus()) {\n return 'active' as const;\n } else if (document.visibilityState === 'visible') {\n return 'inactive' as const;\n } else {\n return 'background' as const;\n }\n }, () => 'unknown' as const);\n}\n","//\n// window.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { useSyncExternalStore } from '../core/hooks/sync';\nimport { uniqueId } from '../core/utils';\nimport { reconciler } from '../core/reconciler/state';\nimport { _DOMRenderer } from '../renderer/common';\n\n/**\n * Hook to access the current window object in a web renderer.\n * \n * @returns The current window object.\n * @throws Error if used outside of a render function or with an unsupported renderer.\n */\nexport const useWindow = () => {\n const state = reconciler.currentHookState;\n if (!state) throw Error('useWindow must be used within a render function.');\n if (state.renderer instanceof _DOMRenderer) {\n return state.renderer.window;\n } else {\n throw Error('Unsupported renderer.');\n }\n}\n\nconst emptyInsets = { top: 0, left: 0, right: 0, bottom: 0 };\nconst safeAreaInsets = (window: ReturnType<typeof useWindow>) => {\n let support;\n if (!('CSS' in window) || !_.isFunction(window.CSS.supports)) {\n return emptyInsets;\n }\n if (window.CSS.supports('top: env(safe-area-inset-top)')) {\n support = 'env'\n } else if (window.CSS.supports('top: constant(safe-area-inset-top)')) {\n support = 'constant'\n } else {\n return emptyInsets;\n }\n const id = uniqueId();\n const style = document.createElement('style');\n style.textContent = `:root {\n --${id}-top: ${support}(safe-area-inset-top);\n --${id}-left: ${support}(safe-area-inset-left);\n --${id}-right: ${support}(safe-area-inset-right);\n --${id}-bottom: ${support}(safe-area-inset-bottom);\n }`;\n document.head.appendChild(style);\n const computedStyle = getComputedStyle(document.documentElement);\n const insets = {\n top: computedStyle.getPropertyValue(`--${id}-top`),\n left: computedStyle.getPropertyValue(`--${id}-left`),\n right: computedStyle.getPropertyValue(`--${id}-right`),\n bottom: computedStyle.getPropertyValue(`--${id}-bottom`),\n };\n style.remove();\n return _.mapValues(insets, v => parseFloat(v));\n}\n\n/**\n * A hook that provides various metrics of the window object.\n * It listens to the 'resize' event to update the metrics.\n * \n * @returns An object containing safe area insets, device pixel ratio, outer and inner dimensions of the window.\n */\nexport const useWindowMetrics = () => {\n const window = useWindow();\n return useSyncExternalStore((onStoreChange) => {\n window.addEventListener('resize', onStoreChange);\n return () => {\n window.removeEventListener('resize', onStoreChange);\n };\n }, () => ({\n safeAreaInsets: safeAreaInsets(window),\n devicePixelRatio: window.devicePixelRatio,\n outerWidth: window.outerWidth,\n outerHeight: window.outerHeight,\n innerWidth: window.innerWidth,\n innerHeight: window.innerHeight,\n }));\n}\n\n/** \n * A hook that provides metrics of the visual viewport.\n * It listens to the 'resize' event of the visual viewport to update the metrics.\n * \n * @returns An object containing width, height, and scale of the visual viewport.\n */\nexport const useVisualViewportMetrics = () => {\n const { visualViewport } = useWindow();\n return useSyncExternalStore((onStoreChange) => {\n visualViewport?.addEventListener('resize', onStoreChange);\n return () => {\n visualViewport?.removeEventListener('resize', onStoreChange);\n };\n }, () => visualViewport && ({\n width: visualViewport.width,\n height: visualViewport.height,\n scale: visualViewport.scale,\n }));\n}\n\n/**\n * A hook that provides the current scroll position of the window.\n * It listens to the 'scroll' event to update the position.\n * \n * @returns An object containing scrollX and scrollY values.\n */\nexport const useWindowScroll = () => {\n const window = useWindow();\n return useSyncExternalStore((onStoreChange) => {\n window.addEventListener('scroll', onStoreChange);\n return () => {\n window.removeEventListener('scroll', onStoreChange);\n };\n }, () => ({\n scrollX: window.scrollX,\n scrollY: window.scrollY,\n }));\n}\n\nconst colorSchemeDarkCache = new WeakMap<ReturnType<typeof useWindow>, MediaQueryList | undefined>();\n\n/**\n * A hook that detects the user's preferred color scheme (light or dark).\n * It listens to changes in the '(prefers-color-scheme: dark)' media query.\n * \n * @returns A string indicating the current color scheme: 'light' or 'dark'.\n */\nexport const useColorScheme = () => {\n const window = useWindow();\n if (!colorSchemeDarkCache.has(window)) colorSchemeDarkCache.set(window, window.matchMedia?.('(prefers-color-scheme: dark)'));\n const colorSchemeDark = colorSchemeDarkCache.get(window);\n return useSyncExternalStore((onStoreChange) => {\n colorSchemeDark?.addEventListener('change', onStoreChange);\n return () => {\n colorSchemeDark?.removeEventListener('change', onStoreChange);\n };\n }, () => colorSchemeDark?.matches ? 'dark' : 'light');\n}\n"],"names":[],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,WAAA,QAAA,QAAA;;ACLP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,WAAA;AACP;AACA;AACA;AACA,0CAAA,GAAA;AACA,6CAAA,GAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,eAAA,kBAAA,eAAA,aAAA,cAAA,uBAAA,MAAA,mBAAA,eAAA,cAAA,eAAA;AACP;AACA;;AC3DA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,iBAAA,WAAA,SAAA,CAAA,OAAA,uBAAA,OAAA,uCAAA,mBAAA,qBAAA,qBAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,uBAAA,WAAA,SAAA,CAAA,OAAA,uBAAA,OAAA,uCAAA,yBAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,mBAAA,WAAA,SAAA,CAAA,IAAA,uBAAA,IAAA,+BAAA,gBAAA,YAAA,oBAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,sBAAA,aAAA,2BAAA,YAAA,uBAAA;;AC9BP;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,SAAA;;ACNP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,iBAAA;;ACRP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,eAAA,8EAAA,cAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,iBAAA,8EAAA,cAAA;;AClBP;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,aAAA;;ACNP;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,SAAA,QAAA,MAAA,GAAwC,KAAe,CAAA,SAAA;AAC9D;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,gBAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,wBAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,eAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,cAAA;;;;"}
package/dist/web.d.ts CHANGED
@@ -6,6 +6,12 @@ import 'lodash';
6
6
  import 'csstype';
7
7
  import './internals/renderer--F4YB5QP.js';
8
8
 
9
+ /**
10
+ * Hook to access the current document object in a web renderer.
11
+ *
12
+ * @returns The current document object.
13
+ * @throws Error if used outside of a render function or with an unsupported renderer.
14
+ */
9
15
  declare const useDocument: () => Document;
10
16
 
11
17
  /**
@@ -69,21 +75,96 @@ declare const useSearchParams: () => readonly [URLSearchParams, (dispatch: SetSt
69
75
  replace?: boolean;
70
76
  }) => void];
71
77
 
78
+ /**
79
+ * A hook that sets up a ResizeObserver on the given target element.
80
+ *
81
+ * @param target - The target element or a ref object containing the target element.
82
+ * @param callback - The callback function to be called when the target element is resized.
83
+ * @param options - Optional ResizeObserverOptions to configure the observer.
84
+ */
72
85
  declare const useResizeObserver: (target: RefObject<Element | null | undefined> | Element | null | undefined, callback: (entry: ResizeObserverEntry) => void, options?: ResizeObserverOptions) => void;
86
+ /**
87
+ * A hook that sets up an IntersectionObserver on the given target element.
88
+ *
89
+ * @param target - The target element or a ref object containing the target element.
90
+ * @param callback - The callback function to be called when the target element's intersection changes.
91
+ */
73
92
  declare const useIntersectionObserver: (target: RefObject<Element | null | undefined> | Element | null | undefined, callback: (entry: IntersectionObserverEntry) => void) => void;
93
+ /**
94
+ * A hook that sets up a MutationObserver on the given target node.
95
+ *
96
+ * @param target - The target node or a ref object containing the target node.
97
+ * @param callback - The callback function to be called when mutations are observed.
98
+ * @param options - Optional MutationObserverInit to configure the observer.
99
+ */
74
100
  declare const useMutationObserver: (target: RefObject<Node | null | undefined> | Node | null | undefined, callback: MutationCallback, options?: MutationObserverInit) => void;
101
+ /**
102
+ * A hook that sets up a PerformanceObserver with the given callback and options.
103
+ *
104
+ * @param callback - The callback function to be called when performance entries are observed.
105
+ * @param options - Optional PerformanceObserverInit to configure the observer.
106
+ */
75
107
  declare const usePerformanceObserver: (callback: PerformanceObserverCallback, options?: PerformanceObserverInit) => void;
76
108
 
109
+ /**
110
+ * A hook that returns the current online status of the browser.
111
+ * It listens to the 'online' and 'offline' events to update the status.
112
+ *
113
+ * @returns A boolean indicating whether the browser is online.
114
+ */
77
115
  declare const useOnline: () => boolean;
78
116
 
117
+ /**
118
+ * A hook to manage server-side resources in a web renderer.
119
+ * It allows tracking and retrieving resources identified by a key.
120
+ *
121
+ * @param key - The unique key for the resource.
122
+ * @param resource - An optional function that returns the resource string when called on the server side.
123
+ * @returns The resource string if available, otherwise undefined.
124
+ * @throws Error if used outside of a render function or with an unsupported renderer.
125
+ */
79
126
  declare const useServerResource: (key: string, resource?: () => string) => string | undefined;
80
127
 
128
+ /**
129
+ * A hook to manage a value in localStorage.
130
+ * It provides a stateful value and a function to update it.
131
+ *
132
+ * @param key - The key in localStorage to manage.
133
+ * @param initialValue - An optional initial value if the key does not exist in localStorage.
134
+ * @returns A tuple containing the current value and a function to update it.
135
+ */
81
136
  declare const useLocalStorage: (key: string, initialValue?: string | null) => readonly [string | null, (v: SetStateAction<string | null | undefined>) => void];
137
+ /**
138
+ * A hook to manage a value in sessionStorage.
139
+ * It provides a stateful value and a function to update it.
140
+ *
141
+ * @param key - The key in sessionStorage to manage.
142
+ * @param initialValue - An optional initial value if the key does not exist in sessionStorage.
143
+ * @returns A tuple containing the current value and a function to update it.
144
+ */
82
145
  declare const useSessionStorage: (key: string, initialValue?: string | null) => readonly [string | null, (v: SetStateAction<string | null | undefined>) => void];
83
146
 
147
+ /**
148
+ * A hook to get the current visibility state of the document.
149
+ * It listens to the 'visibilitychange' event to update the state.
150
+ *
151
+ * @returns A string indicating the current visibility state: 'active', 'inactive', 'background', or 'unknown'.
152
+ */
84
153
  declare const useVisibility: () => "active" | "inactive" | "background" | "unknown";
85
154
 
155
+ /**
156
+ * Hook to access the current window object in a web renderer.
157
+ *
158
+ * @returns The current window object.
159
+ * @throws Error if used outside of a render function or with an unsupported renderer.
160
+ */
86
161
  declare const useWindow: () => Window | jsdom.DOMWindow;
162
+ /**
163
+ * A hook that provides various metrics of the window object.
164
+ * It listens to the 'resize' event to update the metrics.
165
+ *
166
+ * @returns An object containing safe area insets, device pixel ratio, outer and inner dimensions of the window.
167
+ */
87
168
  declare const useWindowMetrics: () => {
88
169
  safeAreaInsets: {
89
170
  top: number;
@@ -97,15 +178,33 @@ declare const useWindowMetrics: () => {
97
178
  innerWidth: number;
98
179
  innerHeight: number;
99
180
  };
181
+ /**
182
+ * A hook that provides metrics of the visual viewport.
183
+ * It listens to the 'resize' event of the visual viewport to update the metrics.
184
+ *
185
+ * @returns An object containing width, height, and scale of the visual viewport.
186
+ */
100
187
  declare const useVisualViewportMetrics: () => {
101
188
  width: number;
102
189
  height: number;
103
190
  scale: number;
104
191
  } | null;
192
+ /**
193
+ * A hook that provides the current scroll position of the window.
194
+ * It listens to the 'scroll' event to update the position.
195
+ *
196
+ * @returns An object containing scrollX and scrollY values.
197
+ */
105
198
  declare const useWindowScroll: () => {
106
199
  scrollX: number;
107
200
  scrollY: number;
108
201
  };
202
+ /**
203
+ * A hook that detects the user's preferred color scheme (light or dark).
204
+ * It listens to changes in the '(prefers-color-scheme: dark)' media query.
205
+ *
206
+ * @returns A string indicating the current color scheme: 'light' or 'dark'.
207
+ */
109
208
  declare const useColorScheme: () => "dark" | "light";
110
209
 
111
210
  export { useColorScheme, useDocument, useIntersectionObserver, useLocalStorage, useLocation, useMutationObserver, useOnline, usePerformanceObserver, useResizeObserver, useSearchParams, useServerResource, useSessionStorage, useVisibility, useVisualViewportMetrics, useWindow, useWindowMetrics, useWindowScroll };