ziko 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ziko.cjs +225 -458
- package/dist/ziko.js +225 -458
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +224 -442
- package/package.json +1 -1
- package/src/__ziko__/__state__.js +10 -10
- package/src/data/converter/index.js +6 -6
- package/src/data/converter/object.js +6 -2
- package/src/hooks/use-reactive.js +1 -1
- package/src/hooks/use-state.js +30 -28
- package/src/hooks/use-storage.js +99 -80
- package/src/math/functions/mapfun/index.d.ts +1 -1
- package/src/math/index.d.ts.txt +5 -0
- package/src/math/index.js +4 -4
- package/src/math/utils/index.js +100 -94
- package/src/math/utils/mapfun.js +1 -2
- package/src/math/index.d.ts +0 -5
- /package/src/math/functions/utils/{mapfun.d.ts → mapfun.d.ts.txt} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ziko",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"front-end",
|
|
@@ -4,18 +4,18 @@ export var __State__ = {
|
|
|
4
4
|
index : 0,
|
|
5
5
|
session_storage : null,
|
|
6
6
|
register: function(state){
|
|
7
|
-
if(!import.meta
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
this.store.set(this.index++, state)
|
|
7
|
+
// if(!import.meta?.env?.SSR && import.meta?.env?.DEV){
|
|
8
|
+
// if(!this.session) this.session_storage = useSessionStorage('ziko-state', {})
|
|
9
|
+
// const savedValue = this.session_storage.get(this.index)
|
|
10
|
+
// if(!savedValue) this.session_storage.add({[this.index] : state.value});
|
|
11
|
+
// else state.value = savedValue
|
|
12
|
+
// }
|
|
13
|
+
// this.store.set(this.index++, state)
|
|
14
14
|
},
|
|
15
15
|
update: function(index, value){
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
// if(!import.meta?.env?.SSR && import.meta?.env?.DEV){
|
|
17
|
+
// this.session_storage.add({[index] : value})
|
|
18
|
+
// }
|
|
19
19
|
},
|
|
20
20
|
|
|
21
21
|
}
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
svg2imgUrl,
|
|
23
23
|
svg2img
|
|
24
24
|
} from "./svg.js";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
// export{
|
|
26
|
+
// obj2str
|
|
27
|
+
// } from "./object.js"
|
|
28
|
+
// export{
|
|
29
|
+
// arr2str
|
|
30
|
+
// } from "./array.js"
|
|
31
31
|
export{
|
|
32
32
|
json2css
|
|
33
33
|
} from "./css.js"
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { arr2str } from "../index.js";
|
|
2
|
-
import { Complex, mapfun, Matrix } from "../../math/index.js";
|
|
1
|
+
// import { arr2str } from "../index.js";
|
|
2
|
+
// import { Complex, mapfun, Matrix } from "../../math/index.js";
|
|
3
|
+
|
|
4
|
+
import { Complex } from "../../math/complex/index.js";
|
|
5
|
+
import { Matrix } from "../../math/matrix/index.js";
|
|
6
|
+
import { mapfun } from "../../math/functions/utils/mapfun.js";
|
|
3
7
|
|
|
4
8
|
// const obj2str=(object)=>{
|
|
5
9
|
// const recursiveToString = (obj) => {
|
package/src/hooks/use-state.js
CHANGED
|
@@ -1,54 +1,56 @@
|
|
|
1
|
-
import { __init__global__ } from "../__ziko__/index.js";
|
|
1
|
+
// import { __init__global__ } from "../__ziko__/index.js";
|
|
2
2
|
|
|
3
|
-
if(!globalThis.__Ziko__) __init__global__()
|
|
3
|
+
// if (!globalThis.__Ziko__) __init__global__();
|
|
4
4
|
|
|
5
5
|
export function useState(initialValue) {
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
let current = store.get(index);
|
|
7
|
+
const state = {
|
|
8
|
+
value: initialValue,
|
|
9
|
+
subscribers: new Set(),
|
|
10
|
+
paused: false,
|
|
11
|
+
};
|
|
15
12
|
|
|
16
13
|
function getValue() {
|
|
17
14
|
return {
|
|
18
|
-
value:
|
|
15
|
+
value: state.value,
|
|
19
16
|
isStateGetter: () => true,
|
|
20
|
-
_subscribe: (fn) =>
|
|
17
|
+
_subscribe: (fn) => {
|
|
18
|
+
state.subscribers.add(fn);
|
|
19
|
+
return () => state.subscribers.delete(fn);
|
|
20
|
+
},
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function setValue(newValue) {
|
|
25
|
-
if (
|
|
25
|
+
if (state.paused) return;
|
|
26
|
+
|
|
26
27
|
if (typeof newValue === "function") {
|
|
27
|
-
newValue = newValue(
|
|
28
|
+
newValue = newValue(state.value);
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
|
|
31
|
+
if (!Object.is(newValue, state.value)) {
|
|
32
|
+
state.value = newValue;
|
|
33
|
+
state.subscribers.forEach((fn) => fn(state.value));
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
const controller = {
|
|
37
|
-
pause: () => {
|
|
38
|
-
resume: () => {
|
|
39
|
-
clear: () => {
|
|
38
|
+
pause: () => { state.paused = true; },
|
|
39
|
+
resume: () => { state.paused = false; },
|
|
40
|
+
clear: () => { state.subscribers.clear(); },
|
|
40
41
|
force: (newValue) => {
|
|
41
|
-
if (typeof newValue === "function")
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
if (typeof newValue === "function") {
|
|
43
|
+
newValue = newValue(state.value);
|
|
44
|
+
}
|
|
45
|
+
state.value = newValue;
|
|
46
|
+
state.subscribers.forEach((fn) => fn(state.value));
|
|
44
47
|
},
|
|
45
|
-
getSubscribers: () => new Set(
|
|
48
|
+
getSubscribers: () => new Set(state.subscribers),
|
|
46
49
|
};
|
|
47
50
|
|
|
48
51
|
return [getValue, setValue, controller];
|
|
49
52
|
}
|
|
50
53
|
|
|
51
|
-
|
|
52
54
|
export const isStateGetter = (arg) => {
|
|
53
|
-
return typeof arg ===
|
|
54
|
-
};
|
|
55
|
+
return typeof arg === "function" && arg?.()?.isStateGetter?.() === true;
|
|
56
|
+
};
|
package/src/hooks/use-storage.js
CHANGED
|
@@ -1,99 +1,118 @@
|
|
|
1
1
|
import { useIPC } from "./use-ipc.js";
|
|
2
2
|
|
|
3
3
|
class UseStorage {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
globalKey,
|
|
8
|
-
channel: use_channel ? useIPC(`Ziko:useStorage-${globalKey}`) : null,
|
|
9
|
-
oldItemKeys: new Set()
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
this.#init(initialValue, use_channel);
|
|
13
|
-
}
|
|
4
|
+
static RESERVED_KEYS = new Set([
|
|
5
|
+
"cache", "items", "set", "add", "remove", "get", "clear", "onStorageUpdated"
|
|
6
|
+
]);
|
|
14
7
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
}
|
|
8
|
+
constructor(storage, globalKey, initialValue, use_channel = true) {
|
|
9
|
+
this.cache = {
|
|
10
|
+
storage,
|
|
11
|
+
globalKey,
|
|
12
|
+
channel: use_channel ? useIPC(`Ziko:useStorage-${globalKey}`) : null,
|
|
13
|
+
oldItemKeys: new Set()
|
|
14
|
+
};
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.cache.oldItemKeys.forEach(k => delete this[k]);
|
|
28
|
-
for (const key in items) {
|
|
29
|
-
this[key] = items[key];
|
|
30
|
-
this.cache.oldItemKeys.add(key);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
#init(initialValue, use_channel) {
|
|
34
|
-
if (use_channel && this.cache.channel) this.cache.channel.on("Ziko-Storage-Updated", () => this.#maintain());
|
|
35
|
-
if (!initialValue) {
|
|
36
|
-
this.#maintain();
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (this.cache.storage.getItem(this.cache.globalKey)) {
|
|
40
|
-
const existing = this.items;
|
|
41
|
-
Object.keys(existing).forEach(k => this.cache.oldItemKeys.add(k));
|
|
42
|
-
this.#maintain();
|
|
43
|
-
}
|
|
44
|
-
else this.set(initialValue);
|
|
45
|
-
}
|
|
16
|
+
this.#init(initialValue, use_channel);
|
|
17
|
+
}
|
|
46
18
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
19
|
+
get items() {
|
|
20
|
+
const raw = this.cache.storage.getItem(this.cache.globalKey);
|
|
21
|
+
if (!raw) return {};
|
|
22
|
+
try {
|
|
23
|
+
return JSON.parse(raw);
|
|
24
|
+
} catch {
|
|
25
|
+
return {};
|
|
52
26
|
}
|
|
27
|
+
}
|
|
53
28
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
29
|
+
#maintain() {
|
|
30
|
+
const currentItems = this.items;
|
|
31
|
+
const currentKeys = new Set(Object.keys(currentItems));
|
|
32
|
+
|
|
33
|
+
// Cleanup keys that were removed
|
|
34
|
+
this.cache.oldItemKeys.forEach(key => {
|
|
35
|
+
if (!currentKeys.has(key)) {
|
|
36
|
+
delete this[key];
|
|
37
|
+
this.cache.oldItemKeys.delete(key);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Populate keys from storage onto `this`
|
|
42
|
+
for (const key in currentItems) {
|
|
43
|
+
if (!UseStorage.RESERVED_KEYS.has(key)) {
|
|
44
|
+
this[key] = currentItems[key];
|
|
45
|
+
this.cache.oldItemKeys.add(key);
|
|
46
|
+
}
|
|
60
47
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this.cache.oldItemKeys.delete(key);
|
|
67
|
-
});
|
|
68
|
-
this.set(items);
|
|
69
|
-
return this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#init(initialValue, use_channel) {
|
|
51
|
+
if (use_channel && this.cache.channel) {
|
|
52
|
+
this.cache.channel.on("Ziko-Storage-Updated", () => this.#maintain());
|
|
70
53
|
}
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
|
|
55
|
+
const hasStoredData = this.cache.storage.getItem(this.cache.globalKey) !== null;
|
|
56
|
+
|
|
57
|
+
if (hasStoredData) {
|
|
58
|
+
// Key already exists in storage -> Restore data to instance
|
|
59
|
+
this.#maintain();
|
|
60
|
+
} else if (initialValue !== undefined) {
|
|
61
|
+
// Key doesn't exist -> Seed with initialValue
|
|
62
|
+
this.set(initialValue);
|
|
63
|
+
} else {
|
|
64
|
+
// Key doesn't exist and no initialValue provided -> Default to empty
|
|
65
|
+
this.#maintain();
|
|
73
66
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
set(data) {
|
|
70
|
+
this.cache.storage.setItem(this.cache.globalKey, JSON.stringify(data));
|
|
71
|
+
if (this.cache.channel) {
|
|
72
|
+
this.cache.channel.emit("Ziko-Storage-Updated", data);
|
|
80
73
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
this.#maintain();
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
add(data) {
|
|
79
|
+
return this.set({
|
|
80
|
+
...this.items,
|
|
81
|
+
...data
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
remove(...keys) {
|
|
86
|
+
const items = { ...this.items };
|
|
87
|
+
keys.forEach(key => delete items[key]);
|
|
88
|
+
return this.set(items);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get(key) {
|
|
92
|
+
return this.items[key];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
clear() {
|
|
96
|
+
this.cache.storage.removeItem(this.cache.globalKey);
|
|
97
|
+
this.#maintain();
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
onStorageUpdated(callback) {
|
|
102
|
+
if (this.cache.channel) {
|
|
103
|
+
this.cache.channel.on("Ziko-Storage-Updated", callback);
|
|
86
104
|
}
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
87
107
|
}
|
|
88
108
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
new UseStorage(localStorage, key, initialValue, use_channel);
|
|
109
|
+
const useLocalStorage = (key, initialValue, use_channel = true) =>
|
|
110
|
+
new UseStorage(localStorage, key, initialValue, use_channel);
|
|
92
111
|
|
|
93
112
|
const useSessionStorage = (key, initialValue, use_channel = true) =>
|
|
94
|
-
|
|
113
|
+
new UseStorage(sessionStorage, key, initialValue, use_channel);
|
|
95
114
|
|
|
96
115
|
export {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
116
|
+
useLocalStorage,
|
|
117
|
+
useSessionStorage
|
|
118
|
+
};
|
package/src/math/index.js
CHANGED
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
// }
|
|
17
17
|
export * from "./const.js"
|
|
18
18
|
export * from "./functions/index.js"
|
|
19
|
-
export * from "./complex"
|
|
20
|
-
export * from "./matrix"
|
|
19
|
+
export * from "./complex/index.js"
|
|
20
|
+
export * from "./matrix/index.js"
|
|
21
21
|
// export * from "./discret"
|
|
22
|
-
export * from "./random"
|
|
23
|
-
export * from "./utils"
|
|
22
|
+
export * from "./random/index.js"
|
|
23
|
+
// export * from "./utils/index.js" // To Check
|
|
24
24
|
// export * from "./statistics"
|
|
25
25
|
// export default Math;
|
|
26
26
|
|
package/src/math/utils/index.js
CHANGED
|
@@ -1,102 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// map,
|
|
16
|
-
// clamp,
|
|
17
|
-
arange,
|
|
18
|
-
linspace,
|
|
19
|
-
logspace,
|
|
20
|
-
geomspace
|
|
21
|
-
} from "../signal/functions.js"
|
|
1
|
+
export * from './arithmetic.js'
|
|
2
|
+
export * from './checkers.js'
|
|
3
|
+
export * from './comparaison.js'
|
|
4
|
+
export * from './conversions.js'
|
|
5
|
+
export * from './discret.js'
|
|
6
|
+
// export * from './mapfun.js'
|
|
7
|
+
// // import { mapfun } from "../mapfun/index.js";
|
|
8
|
+
// // import {
|
|
9
|
+
// // add,
|
|
10
|
+
// // sub,
|
|
11
|
+
// // mul,
|
|
12
|
+
// // div,
|
|
13
|
+
// // modulo
|
|
14
|
+
// // } from "./arithmetic.js";
|
|
22
15
|
// import {
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
16
|
+
// zeros,
|
|
17
|
+
// ones,
|
|
18
|
+
// nums,
|
|
19
|
+
// // norm,
|
|
20
|
+
// // lerp,
|
|
21
|
+
// // map,
|
|
22
|
+
// // clamp,
|
|
23
|
+
// arange,
|
|
24
|
+
// linspace,
|
|
25
|
+
// logspace,
|
|
26
|
+
// geomspace
|
|
27
|
+
// } from "../signal/functions.js"
|
|
28
|
+
// // import {
|
|
29
|
+
// // deg2rad,
|
|
30
|
+
// // rad2deg
|
|
31
|
+
// // } from "./conversions.js"
|
|
32
|
+
// // import{
|
|
33
|
+
// // sum,
|
|
34
|
+
// // prod,
|
|
35
|
+
// // accum
|
|
36
|
+
// // } from "../statistics/index.js"
|
|
26
37
|
// import{
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} from "./
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// add,
|
|
42
|
-
// sub,
|
|
43
|
-
// mul,
|
|
44
|
-
// div,
|
|
45
|
-
// modulo,
|
|
38
|
+
// inRange,
|
|
39
|
+
// isApproximatlyEqual
|
|
40
|
+
// } from "./checkers.js"
|
|
41
|
+
// import{
|
|
42
|
+
// cartesianProduct,
|
|
43
|
+
// ppcm,
|
|
44
|
+
// pgcd
|
|
45
|
+
// } from "./discret.js"
|
|
46
|
+
// const Utils={
|
|
47
|
+
// // add,
|
|
48
|
+
// // sub,
|
|
49
|
+
// // mul,
|
|
50
|
+
// // div,
|
|
51
|
+
// // modulo,
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
// zeros,
|
|
54
|
+
// ones,
|
|
55
|
+
// nums,
|
|
56
|
+
// // norm,
|
|
57
|
+
// // lerp,
|
|
58
|
+
// // map,
|
|
59
|
+
// // clamp,
|
|
60
|
+
// arange,
|
|
61
|
+
// linspace,
|
|
62
|
+
// logspace,
|
|
63
|
+
// geomspace,
|
|
58
64
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
// // sum,
|
|
66
|
+
// // prod,
|
|
67
|
+
// // accum,
|
|
62
68
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
// cartesianProduct,
|
|
70
|
+
// ppcm,
|
|
71
|
+
// pgcd,
|
|
66
72
|
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
// // deg2rad,
|
|
74
|
+
// // rad2deg,
|
|
69
75
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
export {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
76
|
+
// inRange,
|
|
77
|
+
// isApproximatlyEqual
|
|
78
|
+
// }
|
|
79
|
+
// export {
|
|
80
|
+
// // mapfun,
|
|
81
|
+
// Utils,
|
|
82
|
+
// zeros,
|
|
83
|
+
// ones,
|
|
84
|
+
// nums,
|
|
85
|
+
// // sum,
|
|
86
|
+
// // prod,
|
|
87
|
+
// // add,
|
|
88
|
+
// // mul,
|
|
89
|
+
// // sub,
|
|
90
|
+
// // div,
|
|
91
|
+
// // modulo,
|
|
92
|
+
// // rad2deg,
|
|
93
|
+
// // deg2rad,
|
|
94
|
+
// arange,
|
|
95
|
+
// linspace,
|
|
96
|
+
// logspace,
|
|
97
|
+
// geomspace,
|
|
98
|
+
// // norm,
|
|
99
|
+
// // lerp,
|
|
100
|
+
// // map,
|
|
101
|
+
// // clamp,
|
|
102
|
+
// pgcd,
|
|
103
|
+
// ppcm,
|
|
104
|
+
// isApproximatlyEqual,
|
|
105
|
+
// inRange,
|
|
106
|
+
// cartesianProduct,
|
|
107
|
+
// };
|
|
102
108
|
|
package/src/math/utils/mapfun.js
CHANGED
package/src/math/index.d.ts
DELETED
|
File without changes
|