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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziko",
3
- "version": "1.1.0",
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.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)
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
- if(!import.meta.env.SSR && import.meta.env.DEV){
17
- this.session_storage.add({[index] : value})
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
- export{
26
- obj2str
27
- } from "./object.js"
28
- export{
29
- arr2str
30
- } from "./array.js"
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) => {
@@ -1,4 +1,4 @@
1
- import { mapfun } from '../math/index.js'
1
+ import { mapfun } from '../math/utils/mapfun.js'
2
2
  import { useState } from './use-state.js'
3
3
 
4
4
  const useReactive = (nested_value) => mapfun(
@@ -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 {store, index} = __Ziko__.__State__
8
- __Ziko__.__State__.register({
9
- value : initialValue,
10
- subscribers : new Set(),
11
- paused : false
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: current.value,
15
+ value: state.value,
19
16
  isStateGetter: () => true,
20
- _subscribe: (fn) => current.subscribers.add(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 (current.paused) return;
25
+ if (state.paused) return;
26
+
26
27
  if (typeof newValue === "function") {
27
- newValue = newValue(current.value);
28
+ newValue = newValue(state.value);
28
29
  }
29
- if (newValue !== current.value) {
30
- current.value = newValue;
31
- current.subscribers.forEach(fn => fn(current.value));
32
- __Ziko__.__State__.update(index, newValue)
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: () => { current.paused = true; },
38
- resume: () => { current.paused = false; },
39
- clear: () => { current.subscribers.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") newValue = newValue(current.value);
42
- current.value = newValue;
43
- current.subscribers.forEach(fn => fn(current.value));
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(current.subscribers),
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 === 'function' && arg?.()?.isStateGetter?.();
54
- };
55
+ return typeof arg === "function" && arg?.()?.isStateGetter?.() === true;
56
+ };
@@ -1,99 +1,118 @@
1
1
  import { useIPC } from "./use-ipc.js";
2
2
 
3
3
  class UseStorage {
4
- constructor(storage, globalKey, initialValue, use_channel = true) {
5
- this.cache = {
6
- storage,
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
- get items() {
16
- const raw = this.cache.storage.getItem(this.cache.globalKey);
17
- if (!raw) return {};
18
- try {
19
- return JSON.parse(raw);
20
- } catch {
21
- return {};
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
- #maintain() {
26
- const items = this.items;
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
- set(data) {
48
- this.cache.storage.setItem(this.cache.globalKey, JSON.stringify(data));
49
- if (this.cache.channel) this.cache.channel.emit("Ziko-Storage-Updated", data);
50
- this.#maintain();
51
- return this;
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
- add(data) {
55
- this.set({
56
- ...this.items,
57
- ...data
58
- });
59
- return this;
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
- remove(...keys) {
62
- const items = { ...this.items };
63
- keys.forEach(key => {
64
- delete items[key];
65
- delete this[key];
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
- get(key) {
72
- return this.items[key];
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
- clear() {
75
- this.cache.storage.removeItem(this.cache.globalKey);
76
- this.cache.oldItemKeys.forEach(k => delete this[k]);
77
- this.cache.oldItemKeys.clear();
78
- this.#maintain();
79
- return this;
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
- onStorageUpdated(callback) {
82
- if (this.cache.channel) {
83
- this.cache.channel.on("Ziko-Storage-Updated", callback);
84
- }
85
- return this;
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
- // factory functions
90
- const useLocaleStorage = (key, initialValue, use_channel = true) =>
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
- new UseStorage(sessionStorage, key, initialValue, use_channel);
113
+ new UseStorage(sessionStorage, key, initialValue, use_channel);
95
114
 
96
115
  export {
97
- useLocaleStorage,
98
- useSessionStorage
99
- };
116
+ useLocalStorage,
117
+ useSessionStorage
118
+ };
@@ -1,4 +1,4 @@
1
- import { Complex } from "../../../src/math/index.js";
1
+ import { Complex } from "../../../src/math/Complex/index.js";
2
2
  import { Matrix } from "../../../src/math/matrix/index.js";
3
3
 
4
4
  /**
@@ -0,0 +1,5 @@
1
+ export type * from './complex/index.d.ts'
2
+ // export type * from './time'
3
+ // export type * from './router'
4
+ // export type * from './hooks'
5
+ // export type * from './data'
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
 
@@ -1,102 +1,108 @@
1
- // import { mapfun } from "../mapfun/index.js";
2
- // import {
3
- // add,
4
- // sub,
5
- // mul,
6
- // div,
7
- // modulo
8
- // } from "./arithmetic.js";
9
- import {
10
- zeros,
11
- ones,
12
- nums,
13
- // norm,
14
- // lerp,
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
- // deg2rad,
24
- // rad2deg
25
- // } from "./conversions.js"
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
- // sum,
28
- // prod,
29
- // accum
30
- // } from "../statistics/index.js"
31
- import{
32
- inRange,
33
- isApproximatlyEqual
34
- } from "./checkers.js"
35
- import{
36
- cartesianProduct,
37
- ppcm,
38
- pgcd
39
- } from "./discret.js"
40
- const Utils={
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
- zeros,
48
- ones,
49
- nums,
50
- // norm,
51
- // lerp,
52
- // map,
53
- // clamp,
54
- arange,
55
- linspace,
56
- logspace,
57
- geomspace,
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
- // sum,
60
- // prod,
61
- // accum,
65
+ // // sum,
66
+ // // prod,
67
+ // // accum,
62
68
 
63
- cartesianProduct,
64
- ppcm,
65
- pgcd,
69
+ // cartesianProduct,
70
+ // ppcm,
71
+ // pgcd,
66
72
 
67
- // deg2rad,
68
- // rad2deg,
73
+ // // deg2rad,
74
+ // // rad2deg,
69
75
 
70
- inRange,
71
- isApproximatlyEqual
72
- }
73
- export {
74
- // mapfun,
75
- Utils,
76
- zeros,
77
- ones,
78
- nums,
79
- // sum,
80
- // prod,
81
- // add,
82
- // mul,
83
- // sub,
84
- // div,
85
- // modulo,
86
- // rad2deg,
87
- // deg2rad,
88
- arange,
89
- linspace,
90
- logspace,
91
- geomspace,
92
- // norm,
93
- // lerp,
94
- // map,
95
- // clamp,
96
- pgcd,
97
- ppcm,
98
- isApproximatlyEqual,
99
- inRange,
100
- cartesianProduct,
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
 
@@ -1,4 +1,4 @@
1
- const mapfun=(fun,...X)=>{
1
+ export const mapfun=(fun,...X)=>{
2
2
  const Y=X.map(x=>{
3
3
  if(
4
4
  x===null||
@@ -40,4 +40,3 @@ const mapfun=(fun,...X)=>{
40
40
  });
41
41
  return Y.length==1? Y[0]: Y;
42
42
  }
43
- export {mapfun}
@@ -1,5 +0,0 @@
1
- export type * from './math'
2
- export type * from './time'
3
- export type * from './router'
4
- export type * from './hooks'
5
- export type * from './data'