frosty 0.0.112 → 0.0.114

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.
@@ -0,0 +1,19 @@
1
+ import { N as NativeElementType, c as PropsType, C as ComponentNode } from './internals/common-CpEB3ieX.mjs';
2
+ export { V as VNode, _ as _Renderer } from './internals/renderer-BelBgEvy.mjs';
3
+ export { u as uniqueId } from './internals/utils-CWsh4Zpu.mjs';
4
+ import '@o2ter/utils-js';
5
+ import 'lodash';
6
+ import 'csstype';
7
+
8
+ declare class EventEmitter {
9
+ private _listeners;
10
+ register(event: string, callback: (event: string, ...args: any[]) => void): {
11
+ remove: () => void;
12
+ };
13
+ emit(event: string, ...args: any[]): void;
14
+ }
15
+
16
+ declare function _createNativeElement(type: typeof NativeElementType, props: PropsType, key?: string | number): ComponentNode;
17
+
18
+ export { EventEmitter, NativeElementType, _createNativeElement };
19
+ //# sourceMappingURL=_native.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_native.d.mts","sources":["../src/core/reconciler/events.ts","../src/renderer/native.ts"],"sourcesContent":["//\n// events.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';\n\nexport class EventEmitter {\n\n private _listeners: Record<string, ((...args: any[]) => void)[]> = {};\n\n register(event: string, callback: (event: string, ...args: any[]) => void) {\n if (_.isNil(this._listeners[event])) this._listeners[event] = [];\n const _callback = (...args: any[]) => callback(event, ...args);\n this._listeners[event].push(_callback);\n return {\n remove: () => {\n this._listeners[event] = _.filter(this._listeners[event], x => x !== _callback);\n },\n };\n }\n\n emit(event: string, ...args: any[]) {\n this._listeners[event]?.forEach(async callback => {\n try {\n await callback(...args)\n } catch (e) {\n console.error(e);\n }\n });\n }\n}\n","//\n// native.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 { _createElement, PropsType } from '../core/types/runtime';\nimport { ComponentNode, NativeElementType } from '../core/types/component';\n\nexport { _Renderer } from '../core/renderer';\nexport { uniqueId } from '../core/utils';\nexport { EventEmitter } from '../core/reconciler/events';\nexport { VNode } from '../core/reconciler/vnode';\nexport { NativeElementType } from '../core/types/component';\n\nexport function _createNativeElement(\n type: typeof NativeElementType,\n props: PropsType,\n key?: string | number\n): ComponentNode {\n return _createElement(type, { ...props, key });\n}\n"],"names":[],"mappings":";;;;;;;AAAO,cAAA,YAAA;AACP;AACA;AACA;AACA;AACA;AACA;;ACCO,iBAAA,oBAAA,cAAA,iBAAA,SAAA,SAAA,0BAAA,aAAA;;;;"}
package/dist/dom.d.mts ADDED
@@ -0,0 +1,15 @@
1
+ import { _ as _DOMRenderer } from './internals/renderer-BQawOCgo.mjs';
2
+ import './internals/common-CpEB3ieX.mjs';
3
+ import '@o2ter/utils-js';
4
+ import 'lodash';
5
+ import 'csstype';
6
+ import './internals/renderer-BelBgEvy.mjs';
7
+ import 'jsdom';
8
+
9
+ declare class DOMRenderer extends _DOMRenderer {
10
+ static default: DOMRenderer;
11
+ static createRoot(root: Element): ReturnType<typeof DOMRenderer.default.createRoot>;
12
+ }
13
+
14
+ export { DOMRenderer };
15
+ //# sourceMappingURL=dom.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom.d.mts","sources":["../src/renderer/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 { _DOMRenderer } from './common';\n\nexport class DOMRenderer extends _DOMRenderer {\n\n static default = new DOMRenderer(window);\n\n static createRoot(root: Element): ReturnType<typeof DOMRenderer.default.createRoot> {\n return this.default.createRoot(root);\n }\n\n /** @internal */\n get _server(): boolean {\n return false;\n }\n}\n"],"names":[],"mappings":";;;;;;;;AACO,cAAA,WAAA,SAAA,YAAA;AACP,oBAAA,WAAA;AACA,4BAAA,OAAA,GAAA,UAAA,QAAA,WAAA,CAAA,OAAA,CAAA,UAAA;AACA;;;;"}
@@ -0,0 +1,551 @@
1
+ import { _ as _ElementType, N as NativeElementType, P as PropsWithChildren, C as ComponentNode, S as SetStateAction, a as ComponentType, E as ElementNode, R as RefObject, b as Ref, c as PropsType } from './internals/common-CpEB3ieX.mjs';
2
+ export { h as CSSProperties, e as ClassName, j as ComponentProps, k as ComponentPropsWithoutRef, m as ComponentRef, g as ExtendedCSSProperties, i as RefAttribute, l as RefCallback, f as StyleProp, d as createElement } from './internals/common-CpEB3ieX.mjs';
3
+ export { F as Fragment } from './internals/fragment-BlS4iF_x.mjs';
4
+ import _ from 'lodash';
5
+ import { Awaitable } from '@o2ter/utils-js';
6
+ export { m as mergeRefs } from './internals/utils-CWsh4Zpu.mjs';
7
+ import 'csstype';
8
+
9
+ /**
10
+ * Create a pair of Parent and Child components.
11
+ *
12
+ * @param allowTextChildren - Whether to allow text children in the Parent component.
13
+ * @param allowedChildTypes - An array of additional allowed child component types.
14
+ * @returns An object containing the Parent and Child components.
15
+ */
16
+ declare const createPairs: ({ allowTextChildren, allowedChildTypes }?: {
17
+ allowTextChildren?: boolean;
18
+ allowedChildTypes?: (_ElementType | typeof NativeElementType)[];
19
+ }) => {
20
+ Parent: ({ children }: PropsWithChildren<{}>) => ComponentNode;
21
+ Child: ({ children }: PropsWithChildren<{}>) => ComponentNode;
22
+ };
23
+
24
+ /**
25
+ * Represents a function to fetch asynchronous resources.
26
+ *
27
+ * @template T - The type of the resource being fetched.
28
+ * @template P - The type of the parameters passed to the fetch function.
29
+ *
30
+ * @param x - An object containing:
31
+ * - `abortSignal`: An `AbortSignal` to handle cancellation of the fetch operation.
32
+ * - `param`: Optional parameters for the fetch operation, passed by the `refresh` or `next` function.
33
+ * - `prevState`: The previous state of the resource, if applicable. This is only populated when the `next` function is called.
34
+ * - `dispatch`: A function to update the resource state during the fetch process.
35
+ *
36
+ * @returns A promise that resolves to the fetched resource or `void`.
37
+ */
38
+ type Fetch<T, P> = (x: {
39
+ abortSignal: AbortSignal;
40
+ param?: P;
41
+ prevState?: T;
42
+ dispatch: (value: SetStateAction<T, T | undefined>) => void;
43
+ }) => PromiseLike<void | T>;
44
+ /**
45
+ * Represents a function to fetch asynchronous iterable resources, such as streams or paginated data.
46
+ *
47
+ * @template T - The type of the resource items being fetched.
48
+ * @template P - The type of the parameters passed to the fetch function.
49
+ *
50
+ * @param x - An object containing:
51
+ * - `abortSignal`: An `AbortSignal` to handle cancellation of the fetch operation.
52
+ * - `param`: Optional parameters for the fetch operation, passed by the `refresh` or `next` function.
53
+ *
54
+ * @returns An `AsyncIterable` that yields the fetched resource items.
55
+ */
56
+ type FetchWithIterable<T, P> = (x: {
57
+ abortSignal: AbortSignal;
58
+ param?: P;
59
+ }) => Awaitable<AsyncIterable<T>>;
60
+ /**
61
+ * Configuration object for asynchronous resource fetching.
62
+ *
63
+ * @template F - The type of the fetch function.
64
+ *
65
+ * @property fetch - The fetch function to retrieve the resource.
66
+ * @property debounce - Optional debounce settings to control the frequency of fetch calls.
67
+ * - `wait`: The number of milliseconds to delay.
68
+ * - Other settings as defined in `_.DebounceSettings`.
69
+ */
70
+ type Config<F> = {
71
+ fetch: F;
72
+ debounce?: _.DebounceSettings & {
73
+ wait?: number;
74
+ };
75
+ };
76
+
77
+ type Errors = {
78
+ token: string;
79
+ error: any;
80
+ refresh: () => Awaitable<void>;
81
+ refreshing: boolean;
82
+ loading: boolean;
83
+ }[];
84
+ /**
85
+ * A context provider component for managing asynchronous resource errors.
86
+ *
87
+ * This component provides a shared context for tracking errors encountered during
88
+ * asynchronous operations. It allows child components to access and manage these errors
89
+ * using the `useResourceErrors` hook.
90
+ *
91
+ * ### Usage:
92
+ * Wrap your application or specific parts of it with this component to enable error tracking:
93
+ *
94
+ * ```tsx
95
+ * <ResourceErrors>
96
+ * <YourComponent />
97
+ * </ResourceErrors>
98
+ * ```
99
+ *
100
+ * @param children - The child components that will have access to the error context.
101
+ *
102
+ * @returns A context provider that wraps the provided children.
103
+ */
104
+ declare const ResourceErrors: ComponentType<PropsWithChildren<{}>>;
105
+ /**
106
+ * A hook to access the list of asynchronous resource errors.
107
+ *
108
+ * This hook allows components to retrieve the current list of errors being tracked
109
+ * in the `ResourceErrors` context. It must be used within a component that is
110
+ * a descendant of the `ResourceErrors` provider.
111
+ *
112
+ * ### Usage:
113
+ * ```tsx
114
+ * import { useEffect, useResourceErrors } from 'frosty';
115
+ *
116
+ * const errors = useResourceErrors();
117
+ *
118
+ * useEffect(() => {
119
+ * errors.forEach(({ token, error, refresh }) => {
120
+ * console.error(`Error [${token}]:`, error);
121
+ * // Optionally call refresh() to retry the operation
122
+ * });
123
+ * }, [errors]);
124
+ * ```
125
+ *
126
+ * @returns The list of errors currently being tracked in the context. Each error includes:
127
+ * - `token`: A unique identifier for the error.
128
+ * - `error`: The error object or message.
129
+ * - `refresh`: A function to retry the operation that caused the error.
130
+ */
131
+ declare const useResourceErrors: () => Errors;
132
+
133
+ /**
134
+ * A hook to manage asynchronous resources with support for debouncing, error handling, and state management.
135
+ *
136
+ * @template T - The type of the resource being fetched.
137
+ * @template P - The type of the parameters passed to the fetch function.
138
+ *
139
+ * @param config - The fetch function or a configuration object containing the fetch function and optional debounce settings.
140
+ * @param deps - An optional dependency array to control when the resource is refreshed.
141
+ *
142
+ * @returns An object containing:
143
+ * - `count`: The number of times the resource has been fetched.
144
+ * - `refreshing`: A boolean indicating if the resource is currently being refreshed.
145
+ * - `loading`: A boolean indicating if the resource is currently being loaded.
146
+ * - `resource`: The fetched resource.
147
+ * - `error`: Any error encountered during the fetch.
148
+ * - `cancel`: A function to cancel the current fetch operation.
149
+ * - `refresh`: A function to refresh the resource.
150
+ * - `next`: A function to fetch the next set of data (for paginated resources).
151
+ * - `setResource`: A function to manually update the resource state.
152
+ */
153
+ declare const useResource: <T, P = any>(config: Fetch<T, P> | Config<Fetch<T, P>>, deps?: any) => {
154
+ count: number;
155
+ refreshing: boolean;
156
+ loading: boolean;
157
+ resource: T | undefined;
158
+ error: any;
159
+ cancel: (reason?: any) => void;
160
+ refresh: (param?: P) => Promise<void>;
161
+ next: (param?: P) => Promise<void>;
162
+ setResource: (resource: T | ((prevState?: T) => T)) => void;
163
+ };
164
+ /**
165
+ * A hook to manage asynchronous iterable resources, such as streams or paginated data.
166
+ *
167
+ * @template T - The type of the resource items being fetched.
168
+ * @template P - The type of the parameters passed to the fetch function.
169
+ *
170
+ * @param config - The fetch function or a configuration object containing the fetch function and optional debounce settings.
171
+ * @param deps - An optional dependency array to control when the resource is refreshed.
172
+ *
173
+ * @returns An object containing the same properties as `useResource`, but optimized for iterable resources.
174
+ */
175
+ declare const useIterableResource: <T, P = any>(config: FetchWithIterable<T, P> | Config<FetchWithIterable<T, P>>, deps?: any) => {
176
+ count: number;
177
+ refreshing: boolean;
178
+ loading: boolean;
179
+ resource: T[] | undefined;
180
+ error: any;
181
+ cancel: (reason?: any) => void;
182
+ refresh: (param?: any) => Promise<void>;
183
+ setResource: (resource: T[] | ((prevState?: T[] | undefined) => T[])) => void;
184
+ };
185
+
186
+ /**
187
+ * A hook that repeatedly calls the provided callback function at the specified interval.
188
+ *
189
+ * @param callback - The function to be executed at each interval.
190
+ * @param ms - The delay in milliseconds between each call to the callback. If not provided, the interval will not be set.
191
+ * @returns void
192
+ *
193
+ * @example
194
+ * useInterval(() => {
195
+ * // Code to run every 1000ms
196
+ * }, 1000);
197
+ */
198
+ declare const useInterval: (callback: () => void, ms?: number) => void;
199
+
200
+ /**
201
+ * A class representing a store that holds a value and allows for subscription
202
+ * to changes in that value.
203
+ *
204
+ * @template T - The type of the value stored in the store.
205
+ *
206
+ * @example
207
+ * const store = createStore(0);
208
+ * store.setValue(1);
209
+ * store.subscribe((oldVal, newVal) => {
210
+ * console.log(`Value changed from ${oldVal} to ${newVal}`);
211
+ * });
212
+ */
213
+ declare class Store<T> {
214
+ #private;
215
+ /**
216
+ * Gets the current value of the store.
217
+ *
218
+ * @returns The current value of the store.
219
+ */
220
+ get value(): T;
221
+ /**
222
+ * Sets the value of the store and notifies all subscribers.
223
+ *
224
+ * @param dispatch - The new value or a function that returns the new value.
225
+ */
226
+ setValue(dispatch: SetStateAction<T>): void;
227
+ /**
228
+ * Subscribes to changes in the store's value.
229
+ *
230
+ * @param callback - The function to call when the value changes.
231
+ * @returns A function to unsubscribe from the store.
232
+ */
233
+ subscribe(callback: (oldVal: T, newVal: T) => void): () => void;
234
+ }
235
+ /**
236
+ * Creates a new store with the given initial value.
237
+ *
238
+ * @param initialValue - The initial value to be stored.
239
+ * @returns {Store<T>} A new store instance.
240
+ *
241
+ * @example
242
+ * const counterStore = createStore(0);
243
+ */
244
+ declare const createStore: <T extends unknown = any>(initialValue: T) => Store<T>;
245
+ /**
246
+ * A hook to subscribe to a store and select a slice of its state.
247
+ * The component will re-render when the selected state changes.
248
+ *
249
+ * @param store - The store instance to subscribe to.
250
+ * @param selector - A function to select a part of the store's state. Defaults to the entire state.
251
+ * @param equal - A function to compare selected values for equality. Defaults to deep equality.
252
+ * @returns The selected slice of the store's state.
253
+ *
254
+ * @example
255
+ * const count = useStore(counterStore);
256
+ *
257
+ * @example
258
+ * // Using a selector
259
+ * const userName = useStore(userStore, user => user.name);
260
+ */
261
+ declare const useStore: <T extends unknown = any, S = T>(store: Store<T>, selector?: (state: T) => S, equal?: (value: S, other: S) => boolean) => S;
262
+
263
+ /**
264
+ * Eagerly resolves a promise returned by the factory function and caches its result or error.
265
+ *
266
+ * This hook ensures the promise settles before rendering completes. If the promise is still pending,
267
+ * it returns `undefined` and schedules an immediate rerender of the current component. Once resolved, it returns the value.
268
+ * If rejected, it throws the error.
269
+ *
270
+ * #### Usage
271
+ * ```typescript
272
+ * const data = useAwaited(() => fetchData(id), [id]);
273
+ * ```
274
+ *
275
+ * #### Parameters
276
+ * - `factory`: `() => PromiseLike<T>`
277
+ * A function that returns a promise to resolve.
278
+ * - `deps` (optional): `any`
279
+ * Dependency array for memoization. The promise is recreated when dependencies change.
280
+ *
281
+ * #### Returns
282
+ * - `T | undefined`
283
+ * The resolved value, once available. Returns `undefined` while the promise is pending.
284
+ * - Throws the rejection error if the promise fails.
285
+ *
286
+ * #### Throws
287
+ * - Error if used outside a render function.
288
+ * - The rejection error if the promise fails.
289
+ *
290
+ * @template T Type of the resolved value.
291
+ */
292
+ declare const useAwaited: <T>(factory: () => PromiseLike<T>, deps?: any) => T | undefined;
293
+
294
+ /**
295
+ * A hook that creates a debounced version of a function.
296
+ * The debounced function delays invoking the callback until after
297
+ * the specified wait time has elapsed since the last time it was called.
298
+ *
299
+ * This is useful for optimizing performance in scenarios where frequent
300
+ * function calls (e.g., during user input or window resizing) can be expensive.
301
+ *
302
+ * @template T The type of the callback function.
303
+ * @param callback The function to debounce.
304
+ * @param settings Configuration options for debouncing, including:
305
+ * - `wait` (number): The number of milliseconds to delay.
306
+ * - Other lodash debounce options such as `leading` and `trailing`.
307
+ * @returns A debounced version of the callback function.
308
+ */
309
+ declare const useDebounce: <T extends (...args: any) => any>(callback: T, settings: _.DebounceSettings & {
310
+ wait?: number;
311
+ }) => _.DebouncedFunc<T>;
312
+ /**
313
+ * A hook that creates a debounced version of an asynchronous function.
314
+ * The debounced function delays invoking the callback until after
315
+ * the specified wait time has elapsed since the last time it was called.
316
+ *
317
+ * This is particularly useful for scenarios where frequent API calls
318
+ * or other asynchronous operations need to be throttled to improve performance.
319
+ *
320
+ * @template T The type of the asynchronous callback function.
321
+ * @param callback The asynchronous function to debounce.
322
+ * @param settings Configuration options for debouncing, including:
323
+ * - `wait` (number): The number of milliseconds to delay.
324
+ * - Other lodash debounce options such as `leading` and `trailing`.
325
+ * @returns A debounced version of the asynchronous callback function.
326
+ */
327
+ declare const useAsyncDebounce: <T extends (...args: any) => PromiseLike<any>>(callback: T, settings: _.DebounceSettings & {
328
+ wait?: number;
329
+ }) => (this: any, ...args: Parameters<T>) => Promise<T extends (...args: any) => PromiseLike<infer R> ? R : never>;
330
+
331
+ /**
332
+ * A hook that manages side effects with support for an `AbortSignal`.
333
+ * It ensures proper cleanup logic and handles asynchronous operations effectively.
334
+ *
335
+ * @param effect -
336
+ * A function that receives an `AbortSignal` and performs side effects.
337
+ * It can optionally return a cleanup function or a promise that resolves to a cleanup function.
338
+ *
339
+ * @param deps -
340
+ * An optional dependencies that determines when the effect should be re-executed.
341
+ *
342
+ * @example
343
+ * useEffect((signal) => {
344
+ * fetch('/api/data', { signal })
345
+ * .then(response => response.json())
346
+ * .then(data => console.log(data))
347
+ * .catch(err => {
348
+ * if (err.name === 'AbortError') {
349
+ * console.log('Fetch aborted');
350
+ * } else {
351
+ * console.error(err);
352
+ * }
353
+ * });
354
+ *
355
+ * return () => {
356
+ * console.log('Cleanup logic here');
357
+ * };
358
+ * }, []);
359
+ */
360
+ declare const useEffect: (effect: (signal: AbortSignal) => Awaitable<void | (() => Awaitable<void>)>, deps?: any) => void;
361
+
362
+ type Context<Value> = ReturnType<typeof _createContext<Value>>;
363
+ type ContextType<C extends Context<any>> = C extends Context<infer T> ? T : never;
364
+ declare const _createContext: <Value extends unknown>(defaultValue: Value) => ComponentType<{
365
+ value: Value;
366
+ children?: ElementNode | ((value: Value) => ElementNode);
367
+ }> & {
368
+ Consumer: ComponentType<{
369
+ children: (value: Value) => ElementNode;
370
+ }>;
371
+ };
372
+ /**
373
+ * Creates a new context object with an optional default value.
374
+ *
375
+ * A context object allows you to share a value across a component tree
376
+ * without explicitly passing it as a prop to every level.
377
+ *
378
+ * @template Value - The type of the value to be stored in the context.
379
+ * @param - The default value for the context.
380
+ * @returns A context object that can be used to provide and consume the value.
381
+ */
382
+ declare function createContext<Value>(defaultValue: Value): Context<Value>;
383
+ declare function createContext<Value = undefined>(): Context<Value | undefined>;
384
+ /**
385
+ * A hook that retrieves the current value of a context and optionally applies
386
+ * a selector function to transform the context value. This hook ensures that the component
387
+ * subscribes to the context and re-renders when the context value changes.
388
+ *
389
+ * @template T - The type of the context value.
390
+ * @template R - The type of the transformed value returned by the selector.
391
+ * @param context - The context object to retrieve the value from.
392
+ * @param selector - An optional selector function to transform the context value.
393
+ * Defaults to an identity function.
394
+ * @returns - The current value of the context, optionally transformed by the selector.
395
+ *
396
+ * @throws - Throws an error if the provided context is invalid or if the hook
397
+ * is used outside of a render function.
398
+ *
399
+ * @example
400
+ * const MyContext = createContext({ user: null });
401
+ *
402
+ * function MyComponent() {
403
+ * const user = useContext(MyContext, context => context.user);
404
+ * return <div>{user ? `Hello, ${user.name}` : 'Hello, Guest'}</div>;
405
+ * }
406
+ */
407
+ declare const useContext: <T, R = T>(context: Context<T>, selector?: (state: T) => R) => R;
408
+
409
+ /**
410
+ * A utility function that memoizes the result of a factory function.
411
+ *
412
+ * @template T The type of the value returned by the factory function.
413
+ * @param factory A function that produces a value to be memoized.
414
+ * @param deps An optional dependency array. The memoized value is recalculated
415
+ * only when the dependencies change.
416
+ * @returns The memoized value produced by the factory function.
417
+ */
418
+ declare const useMemo: <T>(factory: () => T, deps?: any) => T;
419
+
420
+ /**
421
+ * Creates a mutable reference object that persists across function calls.
422
+ *
423
+ * @template T The type of the value stored in the reference.
424
+ * @param initialValue The initial value to store in the reference.
425
+ * @returns An object with a `current` property that holds the value.
426
+ */
427
+ declare function useRef<T>(initialValue: T): RefObject<T>;
428
+ declare function useRef<T = undefined>(): RefObject<T | undefined>;
429
+ /**
430
+ * Associates a reference with a value created by an initializer function.
431
+ *
432
+ * @template T The type of the reference.
433
+ * @template R The type of the value created by the initializer function.
434
+ * @param ref A reference object or a callback function to receive the value.
435
+ * @param init A function that initializes and returns the value to associate with the reference.
436
+ * @param deps An optional dependency array. The initializer function is re-executed when the dependencies change.
437
+ */
438
+ declare const useRefHandle: <T, R extends T>(ref: Ref<T> | undefined, init: () => R, deps?: any) => void;
439
+
440
+ /**
441
+ * A hook that memoizes a callback function, ensuring that it only changes
442
+ * if its dependencies change. This is useful for optimizing performance by preventing
443
+ * unnecessary re-creations of functions.
444
+ *
445
+ * @template T - The type of the callback function.
446
+ * @param callback - The callback function to be memoized.
447
+ * @param deps - An optional dependencies. If provided, the callback
448
+ * will only be updated when one of these dependencies changes.
449
+ * If not provided, the callback will remain stable.
450
+ * @returns - A stable version of the callback function that will not change unless
451
+ * its dependencies change.
452
+ *
453
+ * @example
454
+ * const memoizedCallback = useCallback(() => {
455
+ * console.log('This function is memoized!');
456
+ * }, [dependency]);
457
+ */
458
+ declare function useCallback<T extends (...args: any) => any>(callback: T, deps?: any): T;
459
+ declare function useCallback<T extends ((...args: any) => any) | _.Falsey>(callback: T, deps?: any): T;
460
+
461
+ /**
462
+ * A hook function for managing state within a custom framework or library.
463
+ *
464
+ * @template T - The type of the state value.
465
+ * @param - The initial state value or a function that returns the initial state.
466
+ * @returns - A tuple containing the current state value and a function to update the state.
467
+ *
468
+ * The `useState` function provides a way to manage stateful values. It returns the current state
469
+ * and a setter function that can update the state. The setter function accepts either a new value
470
+ * or a function that receives the current state and returns the updated state.
471
+ *
472
+ * Example:
473
+ * ```typescript
474
+ * const [count, setCount] = useState(0);
475
+ * setCount(5); // Updates the state to 5
476
+ * setCount(prev => prev + 1); // Updates the state to the previous value + 1
477
+ * ```
478
+ */
479
+ declare function useState<T>(initialState: T | (() => T)): [T, (dispatch: SetStateAction<T>) => void];
480
+ declare function useState<T = undefined>(): [T | undefined, (dispatch: SetStateAction<T | undefined>) => void];
481
+
482
+ /**
483
+ * Retrieves the stack of parent components from the current hook state.
484
+ *
485
+ * This function accesses the current hook state and extracts the stack of
486
+ * parent components. It throws an error if called outside of a valid render
487
+ * context.
488
+ *
489
+ * @returns An array of parent components from the current hook state.
490
+ * @throws Will throw an error if the function is called outside of a valid render context.
491
+ */
492
+ declare const useStack: () => ComponentNode[];
493
+
494
+ /**
495
+ * A utility function that manages state using a reducer pattern.
496
+ *
497
+ * @template T The type of the state.
498
+ * @template A The type of the action object (optional).
499
+ * @param reducer A function that takes the current state and an action, and returns the new state.
500
+ * @param initialState The initial state value or a function that returns the initial state.
501
+ * @returns A tuple containing the current state and a dispatch function to update the state.
502
+ */
503
+ declare function useReducer<T>(reducer: (prevState: T) => T, initialState: T | (() => T)): [T, (dispatch: () => void) => void];
504
+ declare function useReducer<T, A = any>(reducer: (prevState: T, action: A) => T, initialState: T | (() => T)): [T, (dispatch: (action: A) => void) => void];
505
+ declare function useReducer<T = undefined>(reducer: (prevState: T | undefined) => T | undefined): [T | undefined, (dispatch: () => void) => void];
506
+ declare function useReducer<T = undefined, A = any>(reducer: (prevState: T | undefined, action: A) => T | undefined): [T | undefined, (dispatch: (action: A) => void) => void];
507
+
508
+ /**
509
+ * A hook utility for synchronizing with an external store.
510
+ *
511
+ * @template Snapshot - The type of the snapshot returned by the store.
512
+ * @param subscribe - A function that sets up a subscription to the external store.
513
+ * - `onStoreChange`: A callback to invoke when the store changes.
514
+ * - `signal`: An `AbortSignal` to handle cleanup when the subscription is no longer needed.
515
+ * - Returns an optional cleanup function or a promise resolving to one.
516
+ * @param getSnapshot - A function that retrieves the current snapshot of the store.
517
+ * @param getServerSnapshot - (Optional) A function that retrieves the snapshot of the store
518
+ * in a server environment.
519
+ * @returns The current snapshot of the store.
520
+ *
521
+ * @throws Will throw an error if used outside of a valid render context.
522
+ */
523
+ declare const useSyncExternalStore: <Snapshot>(subscribe: (onStoreChange: () => void, signal: AbortSignal) => Awaitable<void | (() => Awaitable<void>)>, getSnapshot: () => Snapshot, getServerSnapshot?: () => Snapshot) => Snapshot;
524
+
525
+ /**
526
+ * Returns a persistent storage Map associated with the current renderer instance.
527
+ * This hook allows components to store and retrieve values that persist across renders,
528
+ * scoped to the renderer. Must be called within a render function.
529
+ *
530
+ * @throws Error if called outside of a render function.
531
+ * @returns {Map<any, any>} The storage map for the current renderer.
532
+ */
533
+ declare const useRendererStorage: () => Map<any, any>;
534
+
535
+ type ErrorBoundaryProps = PropsWithChildren<{
536
+ silent?: boolean;
537
+ onError?: (error: any, component: ComponentNode, stack: ComponentNode[]) => void;
538
+ }>;
539
+ declare const ErrorBoundary: ComponentType<ErrorBoundaryProps>;
540
+
541
+ type PropsProviderProps = PropsWithChildren<{
542
+ callback: (v: {
543
+ type: _ElementType | typeof NativeElementType;
544
+ props: PropsType;
545
+ }) => PropsType | undefined | null;
546
+ }>;
547
+ declare const PropsProvider: ComponentType<PropsProviderProps>;
548
+
549
+ export { ComponentNode, ComponentType, ElementNode, _ElementType as ElementType, ErrorBoundary, PropsProvider, PropsWithChildren, Ref, RefObject, ResourceErrors, SetStateAction, createContext, createPairs, createStore, useAsyncDebounce, useAwaited, useCallback, useContext, useDebounce, useEffect, useInterval, useIterableResource, useMemo, useReducer, useRef, useRefHandle, useRendererStorage, useResource, useResourceErrors, useStack, useState, useStore, useSyncExternalStore };
550
+ export type { Context, ContextType };
551
+ //# sourceMappingURL=index.d.mts.map