ziko 0.49.5 → 0.49.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ziko.cjs +316 -230
- package/dist/ziko.js +320 -234
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +313 -228
- package/package.json +1 -1
- package/src/__ziko__/__state__.js +1 -1
- package/src/hooks/index.js +10 -1
- package/src/hooks/use-channel.js +2 -19
- package/src/hooks/use-derived.js +1 -1
- package/src/hooks/use-event-emitter.js +68 -0
- package/src/hooks/use-favicon.js +59 -0
- package/src/hooks/use-media-query.js +59 -0
- package/src/hooks/use-root.js +73 -0
- package/src/hooks/use-storage.js +99 -0
- package/src/hooks/use-thread.js +55 -0
- package/src/hooks/use-title.js +43 -0
- package/src/reactivity/hooks/head/useFavIcon.js +4 -4
- package/src/reactivity/hooks/head/useTitle.js +1 -1
- package/src/use/index.js +3 -3
- package/src/use/{use-event-emmiter.js → use-event-emmiter.js.txt} +3 -3
- package/types/hooks/index.d.ts +11 -1
- package/types/hooks/use-Thread.d.ts +33 -0
- package/types/hooks/use-derived.d.ts +14 -0
- package/types/hooks/use-event-emitter.d.ts +46 -0
- package/types/hooks/use-favicon.d.ts +41 -0
- package/types/hooks/use-media-query.d.ts +24 -0
- package/types/hooks/use-reactive.d.ts +14 -0
- package/types/hooks/use-root.d.ts +15 -0
- package/types/hooks/use-state.d.ts +25 -0
- package/types/hooks/use-storage.d.ts +47 -0
- package/types/hooks/use-title.d.ts +37 -0
- /package/src/use/{use-channel.js → use-channel.js.txt} +0 -0
- /package/src/use/{use-storage.js → use-storage.js.txt} +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// use-thread.d.ts
|
|
2
|
+
|
|
3
|
+
export declare class UseThread {
|
|
4
|
+
constructor();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Call a function inside the worker.
|
|
8
|
+
* @param func - Function to execute (cannot capture outer scope)
|
|
9
|
+
* @param callback - Callback receiving (result, error)
|
|
10
|
+
* @param args - Optional arguments array to pass to the function
|
|
11
|
+
* @param close - Automatically close the worker after execution (default true)
|
|
12
|
+
*/
|
|
13
|
+
call<T = any>(
|
|
14
|
+
func: (...args: any[]) => T,
|
|
15
|
+
callback: (result: T | null, error: string | null) => void,
|
|
16
|
+
args?: any[],
|
|
17
|
+
close?: boolean
|
|
18
|
+
): this;
|
|
19
|
+
|
|
20
|
+
/** Terminate the worker manually */
|
|
21
|
+
terminate(): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Helper function for single-use worker threads.
|
|
26
|
+
* Immediately executes the function and returns the UseThread instance.
|
|
27
|
+
*/
|
|
28
|
+
export declare const useThread: <T = any>(
|
|
29
|
+
func: (...args: any[]) => T,
|
|
30
|
+
callback: (result: T | null, error: string | null) => void,
|
|
31
|
+
args?: any[],
|
|
32
|
+
close?: boolean
|
|
33
|
+
) => UseThread;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function useDerived<T>(
|
|
2
|
+
deriveFn: (...values: any[]) => T,
|
|
3
|
+
sources: Array<
|
|
4
|
+
() => {
|
|
5
|
+
value: any;
|
|
6
|
+
isStateGetter: () => true;
|
|
7
|
+
_subscribe: (fn: (value: any) => void) => void;
|
|
8
|
+
}
|
|
9
|
+
>
|
|
10
|
+
): () => {
|
|
11
|
+
value: T;
|
|
12
|
+
isStateGetter: () => true;
|
|
13
|
+
_subscribe: (fn: (value: T) => void) => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
declare class UseEventEmitter {
|
|
2
|
+
constructor(maxListeners?: number);
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Register and listen for an event.
|
|
6
|
+
* The listener will be called every time the event is emitted.
|
|
7
|
+
*/
|
|
8
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Register and listen for an event ONCE.
|
|
12
|
+
* After the first call, the listener is automatically removed.
|
|
13
|
+
*/
|
|
14
|
+
once(event: string, listener: (...args: any[]) => void): this;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Remove a specific listener.
|
|
18
|
+
*/
|
|
19
|
+
off(event: string, listener: (...args: any[]) => void): this;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Emit an event and call all listeners associated with it.
|
|
23
|
+
* Returns true if the event had listeners; otherwise false.
|
|
24
|
+
*/
|
|
25
|
+
emit(event: string, data?: any): boolean;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Remove all listeners for a specific event.
|
|
29
|
+
*/
|
|
30
|
+
remove(event: string): this;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Clear all events and their listeners.
|
|
34
|
+
*/
|
|
35
|
+
clear(): this;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Set the maximum number of listeners allowed per event.
|
|
39
|
+
*/
|
|
40
|
+
setMaxListeners(max: number): this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Create a new event emitter instance */
|
|
44
|
+
declare const useEventEmitter: (maxListeners?: number) => UseEventEmitter;
|
|
45
|
+
|
|
46
|
+
export { UseEventEmitter, useEventEmitter };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare class UseFavIcon {
|
|
2
|
+
/**
|
|
3
|
+
* Create a favicon manager.
|
|
4
|
+
* @param FavIcon Initial favicon URL.
|
|
5
|
+
* @param withEmitter Whether to enable an internal event emitter (default: true).
|
|
6
|
+
*/
|
|
7
|
+
constructor(FavIcon?: string, withEmitter?: boolean);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Sets the favicon URL.
|
|
11
|
+
* Emits "ziko:favicon-changed" if emitter is enabled.
|
|
12
|
+
*/
|
|
13
|
+
setFavicon(href: string): this;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns the current favicon URL.
|
|
17
|
+
*/
|
|
18
|
+
readonly current: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Listen for favicon changes.
|
|
22
|
+
* Callback receives the new href as a string.
|
|
23
|
+
*/
|
|
24
|
+
onChange(callback: (href: string) => void): this;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* To Do
|
|
28
|
+
* Disable or remove the internal event emitter entirely.
|
|
29
|
+
*/
|
|
30
|
+
removeEventEmitter(): this;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Enable the internal event emitter manually.
|
|
34
|
+
*/
|
|
35
|
+
useEventEmitter(): this;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Factory function to create a `UseFavIcon` instance.
|
|
40
|
+
*/
|
|
41
|
+
export declare const useFavIcon: (FavIcon?: string, withEmitter?: boolean) => UseFavIcon;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface MediaQueryRule {
|
|
2
|
+
query: string;
|
|
3
|
+
callback: () => void;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export class UseMediaQuery {
|
|
7
|
+
// Private fields (only for type awareness; not accessible)
|
|
8
|
+
private readonly #mediaQueryRules: MediaQueryRule[];
|
|
9
|
+
private readonly #fallback: () => void;
|
|
10
|
+
private #lastCalledCallback: (() => void) | null;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
mediaQueryRules?: MediaQueryRule[],
|
|
14
|
+
fallback?: () => void
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Helper function to create a UseMediaQuery instance.
|
|
20
|
+
*/
|
|
21
|
+
export function useMediaQuery(
|
|
22
|
+
mediaQueryRules?: MediaQueryRule[],
|
|
23
|
+
fallback?: () => void
|
|
24
|
+
): UseMediaQuery;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { mapfun, MapfunResult } from "../math/utils/mapfun.d.ts";
|
|
2
|
+
import { useState } from "./use-state.d.ts";
|
|
3
|
+
|
|
4
|
+
export function useReactive<
|
|
5
|
+
T
|
|
6
|
+
>(
|
|
7
|
+
nested_value: T
|
|
8
|
+
): MapfunResult<
|
|
9
|
+
(n: any) => {
|
|
10
|
+
get: ReturnType<typeof useState<any>>[0];
|
|
11
|
+
set: ReturnType<typeof useState<any>>[1];
|
|
12
|
+
},
|
|
13
|
+
T
|
|
14
|
+
>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class UseRoot<PropMap extends Record<string, string>> {
|
|
2
|
+
constructor(PropsMap: PropMap, options?: UseRootOptions);
|
|
3
|
+
|
|
4
|
+
currentPropsMap: PropMap;
|
|
5
|
+
namespace: string;
|
|
6
|
+
ValidateCssProps: boolean;
|
|
7
|
+
|
|
8
|
+
/** Dynamically created CSS variable references */
|
|
9
|
+
[K in keyof PropMap]: string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Apply a new set of properties
|
|
13
|
+
*/
|
|
14
|
+
use(PropsMap: PropMap): this;
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function useState<T>(
|
|
2
|
+
initialValue: T
|
|
3
|
+
): [
|
|
4
|
+
/** getter function */
|
|
5
|
+
() => {
|
|
6
|
+
value: T;
|
|
7
|
+
isStateGetter: () => true;
|
|
8
|
+
_subscribe: (fn: (value: T) => void) => void;
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
/** setter function */
|
|
12
|
+
(newValue: T | ((prev: T) => T)) => void,
|
|
13
|
+
|
|
14
|
+
/** controller */
|
|
15
|
+
{
|
|
16
|
+
pause: () => void;
|
|
17
|
+
resume: () => void;
|
|
18
|
+
clear: () => void;
|
|
19
|
+
force: (newValue: T | ((prev: T) => T)) => void;
|
|
20
|
+
getSubscribers: () => Set<(value: T) => void>;
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
/** check if argument is a state getter */
|
|
25
|
+
export function isStateGetter(arg: any): boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// use-storage.d.ts
|
|
2
|
+
|
|
3
|
+
export declare class UseStorage {
|
|
4
|
+
constructor(
|
|
5
|
+
storage: Storage,
|
|
6
|
+
globalKey: string,
|
|
7
|
+
initialValue?: Record<string, any>,
|
|
8
|
+
use_channel?: boolean
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
/** Current stored items */
|
|
12
|
+
readonly items: Record<string, any>;
|
|
13
|
+
|
|
14
|
+
/** Set entire storage */
|
|
15
|
+
set(data: Record<string, any>): this;
|
|
16
|
+
|
|
17
|
+
/** Merge new data into existing storage */
|
|
18
|
+
add(data: Record<string, any>): this;
|
|
19
|
+
|
|
20
|
+
/** Remove keys from storage */
|
|
21
|
+
remove(...keys: string[]): this;
|
|
22
|
+
|
|
23
|
+
/** Get a single key */
|
|
24
|
+
get(key: string): any;
|
|
25
|
+
|
|
26
|
+
/** Clear storage completely */
|
|
27
|
+
clear(): this;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Listen for any storage updates.
|
|
31
|
+
* Callback receives the data passed to the last .set() / .add() / .remove()
|
|
32
|
+
*/
|
|
33
|
+
onStorageUpdated(callback: (data: Record<string, any>) => void): this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Factory functions */
|
|
37
|
+
export declare const useLocaleStorage: (
|
|
38
|
+
key: string,
|
|
39
|
+
initialValue?: Record<string, any>,
|
|
40
|
+
use_channel?: boolean
|
|
41
|
+
) => UseStorage;
|
|
42
|
+
|
|
43
|
+
export declare const useSessionStorage: (
|
|
44
|
+
key: string,
|
|
45
|
+
initialValue?: Record<string, any>,
|
|
46
|
+
use_channel?: boolean
|
|
47
|
+
) => UseStorage;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare class UseTitle {
|
|
2
|
+
/**
|
|
3
|
+
* Create a reactive title manager.
|
|
4
|
+
* @param title Initial title. Defaults to `document.title`.
|
|
5
|
+
* @param withEmitter Whether to create an internal event emitter. Default: true.
|
|
6
|
+
*/
|
|
7
|
+
constructor(title?: string, withEmitter?: boolean);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Enables the internal event emitter.
|
|
11
|
+
*/
|
|
12
|
+
useEventEmitter(): this;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Sets the document title.
|
|
16
|
+
* Emits "ziko:title-changed" if emitter is enabled.
|
|
17
|
+
*/
|
|
18
|
+
setTitle(title: string): this;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Returns the current document title.
|
|
22
|
+
*/
|
|
23
|
+
readonly current: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Listen for title changes.
|
|
27
|
+
*/
|
|
28
|
+
onChange(callback: (title: string) => void): this;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* To Do
|
|
32
|
+
* Disable or remove the internal event emitter entirely.
|
|
33
|
+
*/
|
|
34
|
+
removeEventEmitter(): this;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export declare const useTitle: (title?: string, withEmitter?: boolean) => UseTitle;
|
|
File without changes
|
|
File without changes
|