ziko 1.1.1 → 1.3.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 +196 -114
- package/dist/ziko.js +196 -114
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +194 -114
- package/package.json +1 -1
- package/src/__ziko__/__state__.js +10 -10
- package/src/dom/components/index.js +1 -0
- package/src/dom/components/swap/index.d.ts +80 -0
- package/src/dom/components/swap/index.js +59 -0
- package/src/dom/index.js +3 -1
- package/src/hooks/use-state.js +30 -28
- package/src/hooks/use-storage.js +99 -80
package/dist/ziko.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Thu Jul 30 2026 19:50:38 GMT+0100 (UTC+01:00)
|
|
6
6
|
Git-Repo : https://github.com/zakarialaoui10/ziko.js
|
|
7
7
|
Git-Wiki : https://github.com/zakarialaoui10/ziko.js/wiki
|
|
8
8
|
Released under MIT License
|
|
@@ -1876,115 +1876,134 @@ class UseIPC {
|
|
|
1876
1876
|
const useIPC = (name) => new UseIPC(name);
|
|
1877
1877
|
|
|
1878
1878
|
class UseStorage {
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
globalKey,
|
|
1883
|
-
channel: use_channel ? useIPC(`Ziko:useStorage-${globalKey}`) : null,
|
|
1884
|
-
oldItemKeys: new Set()
|
|
1885
|
-
};
|
|
1879
|
+
static RESERVED_KEYS = new Set([
|
|
1880
|
+
"cache", "items", "set", "add", "remove", "get", "clear", "onStorageUpdated"
|
|
1881
|
+
]);
|
|
1886
1882
|
|
|
1887
|
-
|
|
1888
|
-
|
|
1883
|
+
constructor(storage, globalKey, initialValue, use_channel = true) {
|
|
1884
|
+
this.cache = {
|
|
1885
|
+
storage,
|
|
1886
|
+
globalKey,
|
|
1887
|
+
channel: use_channel ? useIPC(`Ziko:useStorage-${globalKey}`) : null,
|
|
1888
|
+
oldItemKeys: new Set()
|
|
1889
|
+
};
|
|
1889
1890
|
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
if (!raw) return {};
|
|
1893
|
-
try {
|
|
1894
|
-
return JSON.parse(raw);
|
|
1895
|
-
} catch {
|
|
1896
|
-
return {};
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1891
|
+
this.#init(initialValue, use_channel);
|
|
1892
|
+
}
|
|
1899
1893
|
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
}
|
|
1908
|
-
#init(initialValue, use_channel) {
|
|
1909
|
-
if (use_channel && this.cache.channel) this.cache.channel.on("Ziko-Storage-Updated", () => this.#maintain());
|
|
1910
|
-
if (!initialValue) {
|
|
1911
|
-
this.#maintain();
|
|
1912
|
-
return;
|
|
1913
|
-
}
|
|
1914
|
-
if (this.cache.storage.getItem(this.cache.globalKey)) {
|
|
1915
|
-
const existing = this.items;
|
|
1916
|
-
Object.keys(existing).forEach(k => this.cache.oldItemKeys.add(k));
|
|
1917
|
-
this.#maintain();
|
|
1918
|
-
}
|
|
1919
|
-
else this.set(initialValue);
|
|
1894
|
+
get items() {
|
|
1895
|
+
const raw = this.cache.storage.getItem(this.cache.globalKey);
|
|
1896
|
+
if (!raw) return {};
|
|
1897
|
+
try {
|
|
1898
|
+
return JSON.parse(raw);
|
|
1899
|
+
} catch {
|
|
1900
|
+
return {};
|
|
1920
1901
|
}
|
|
1902
|
+
}
|
|
1921
1903
|
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
this.#maintain();
|
|
1926
|
-
return this;
|
|
1927
|
-
}
|
|
1904
|
+
#maintain() {
|
|
1905
|
+
const currentItems = this.items;
|
|
1906
|
+
const currentKeys = new Set(Object.keys(currentItems));
|
|
1928
1907
|
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1908
|
+
// Cleanup keys that were removed
|
|
1909
|
+
this.cache.oldItemKeys.forEach(key => {
|
|
1910
|
+
if (!currentKeys.has(key)) {
|
|
1911
|
+
delete this[key];
|
|
1912
|
+
this.cache.oldItemKeys.delete(key);
|
|
1913
|
+
}
|
|
1914
|
+
});
|
|
1915
|
+
|
|
1916
|
+
// Populate keys from storage onto `this`
|
|
1917
|
+
for (const key in currentItems) {
|
|
1918
|
+
if (!UseStorage.RESERVED_KEYS.has(key)) {
|
|
1919
|
+
this[key] = currentItems[key];
|
|
1920
|
+
this.cache.oldItemKeys.add(key);
|
|
1921
|
+
}
|
|
1935
1922
|
}
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
this.cache.oldItemKeys.delete(key);
|
|
1942
|
-
});
|
|
1943
|
-
this.set(items);
|
|
1944
|
-
return this;
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
#init(initialValue, use_channel) {
|
|
1926
|
+
if (use_channel && this.cache.channel) {
|
|
1927
|
+
this.cache.channel.on("Ziko-Storage-Updated", () => this.#maintain());
|
|
1945
1928
|
}
|
|
1946
|
-
|
|
1947
|
-
|
|
1929
|
+
|
|
1930
|
+
const hasStoredData = this.cache.storage.getItem(this.cache.globalKey) !== null;
|
|
1931
|
+
|
|
1932
|
+
if (hasStoredData) {
|
|
1933
|
+
// Key already exists in storage -> Restore data to instance
|
|
1934
|
+
this.#maintain();
|
|
1935
|
+
} else if (initialValue !== undefined) {
|
|
1936
|
+
// Key doesn't exist -> Seed with initialValue
|
|
1937
|
+
this.set(initialValue);
|
|
1938
|
+
} else {
|
|
1939
|
+
// Key doesn't exist and no initialValue provided -> Default to empty
|
|
1940
|
+
this.#maintain();
|
|
1948
1941
|
}
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
set(data) {
|
|
1945
|
+
this.cache.storage.setItem(this.cache.globalKey, JSON.stringify(data));
|
|
1946
|
+
if (this.cache.channel) {
|
|
1947
|
+
this.cache.channel.emit("Ziko-Storage-Updated", data);
|
|
1955
1948
|
}
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1949
|
+
this.#maintain();
|
|
1950
|
+
return this;
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
add(data) {
|
|
1954
|
+
return this.set({
|
|
1955
|
+
...this.items,
|
|
1956
|
+
...data
|
|
1957
|
+
});
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
remove(...keys) {
|
|
1961
|
+
const items = { ...this.items };
|
|
1962
|
+
keys.forEach(key => delete items[key]);
|
|
1963
|
+
return this.set(items);
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
get(key) {
|
|
1967
|
+
return this.items[key];
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
clear() {
|
|
1971
|
+
this.cache.storage.removeItem(this.cache.globalKey);
|
|
1972
|
+
this.#maintain();
|
|
1973
|
+
return this;
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
onStorageUpdated(callback) {
|
|
1977
|
+
if (this.cache.channel) {
|
|
1978
|
+
this.cache.channel.on("Ziko-Storage-Updated", callback);
|
|
1961
1979
|
}
|
|
1980
|
+
return this;
|
|
1981
|
+
}
|
|
1962
1982
|
}
|
|
1963
1983
|
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
new UseStorage(localStorage, key, initialValue, use_channel);
|
|
1984
|
+
const useLocalStorage = (key, initialValue, use_channel = true) =>
|
|
1985
|
+
new UseStorage(localStorage, key, initialValue, use_channel);
|
|
1967
1986
|
|
|
1968
1987
|
const useSessionStorage = (key, initialValue, use_channel = true) =>
|
|
1969
|
-
|
|
1988
|
+
new UseStorage(sessionStorage, key, initialValue, use_channel);
|
|
1970
1989
|
|
|
1971
1990
|
var __State__ = {
|
|
1972
1991
|
store : new Map(),
|
|
1973
1992
|
index : 0,
|
|
1974
1993
|
session_storage : null,
|
|
1975
1994
|
register: function(state){
|
|
1976
|
-
if(!
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
}
|
|
1982
|
-
this.store.set(this.index++, state)
|
|
1995
|
+
// if(!import.meta?.env?.SSR && import.meta?.env?.DEV){
|
|
1996
|
+
// if(!this.session) this.session_storage = useSessionStorage('ziko-state', {})
|
|
1997
|
+
// const savedValue = this.session_storage.get(this.index)
|
|
1998
|
+
// if(!savedValue) this.session_storage.add({[this.index] : state.value});
|
|
1999
|
+
// else state.value = savedValue
|
|
2000
|
+
// }
|
|
2001
|
+
// this.store.set(this.index++, state)
|
|
1983
2002
|
},
|
|
1984
2003
|
update: function(index, value){
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
2004
|
+
// if(!import.meta?.env?.SSR && import.meta?.env?.DEV){
|
|
2005
|
+
// this.session_storage.add({[index] : value})
|
|
2006
|
+
// }
|
|
1988
2007
|
},
|
|
1989
2008
|
|
|
1990
2009
|
};
|
|
@@ -2161,57 +2180,61 @@ var LifecycleMethods = /*#__PURE__*/Object.freeze({
|
|
|
2161
2180
|
unmount: unmount
|
|
2162
2181
|
});
|
|
2163
2182
|
|
|
2164
|
-
|
|
2183
|
+
// import { __init__global__ } from "../__ziko__/index.js";
|
|
2184
|
+
|
|
2185
|
+
// if (!globalThis.__Ziko__) __init__global__();
|
|
2165
2186
|
|
|
2166
2187
|
function useState(initialValue) {
|
|
2167
2188
|
|
|
2168
|
-
const
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
});
|
|
2174
|
-
|
|
2175
|
-
let current = store.get(index);
|
|
2189
|
+
const state = {
|
|
2190
|
+
value: initialValue,
|
|
2191
|
+
subscribers: new Set(),
|
|
2192
|
+
paused: false,
|
|
2193
|
+
};
|
|
2176
2194
|
|
|
2177
2195
|
function getValue() {
|
|
2178
2196
|
return {
|
|
2179
|
-
value:
|
|
2197
|
+
value: state.value,
|
|
2180
2198
|
isStateGetter: () => true,
|
|
2181
|
-
_subscribe: (fn) =>
|
|
2199
|
+
_subscribe: (fn) => {
|
|
2200
|
+
state.subscribers.add(fn);
|
|
2201
|
+
return () => state.subscribers.delete(fn);
|
|
2202
|
+
},
|
|
2182
2203
|
};
|
|
2183
2204
|
}
|
|
2184
2205
|
|
|
2185
2206
|
function setValue(newValue) {
|
|
2186
|
-
if (
|
|
2207
|
+
if (state.paused) return;
|
|
2208
|
+
|
|
2187
2209
|
if (typeof newValue === "function") {
|
|
2188
|
-
newValue = newValue(
|
|
2210
|
+
newValue = newValue(state.value);
|
|
2189
2211
|
}
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2212
|
+
|
|
2213
|
+
if (!Object.is(newValue, state.value)) {
|
|
2214
|
+
state.value = newValue;
|
|
2215
|
+
state.subscribers.forEach((fn) => fn(state.value));
|
|
2194
2216
|
}
|
|
2195
2217
|
}
|
|
2196
2218
|
|
|
2197
2219
|
const controller = {
|
|
2198
|
-
pause: () => {
|
|
2199
|
-
resume: () => {
|
|
2200
|
-
clear: () => {
|
|
2220
|
+
pause: () => { state.paused = true; },
|
|
2221
|
+
resume: () => { state.paused = false; },
|
|
2222
|
+
clear: () => { state.subscribers.clear(); },
|
|
2201
2223
|
force: (newValue) => {
|
|
2202
|
-
if (typeof newValue === "function")
|
|
2203
|
-
|
|
2204
|
-
|
|
2224
|
+
if (typeof newValue === "function") {
|
|
2225
|
+
newValue = newValue(state.value);
|
|
2226
|
+
}
|
|
2227
|
+
state.value = newValue;
|
|
2228
|
+
state.subscribers.forEach((fn) => fn(state.value));
|
|
2205
2229
|
},
|
|
2206
|
-
getSubscribers: () => new Set(
|
|
2230
|
+
getSubscribers: () => new Set(state.subscribers),
|
|
2207
2231
|
};
|
|
2208
2232
|
|
|
2209
2233
|
return [getValue, setValue, controller];
|
|
2210
2234
|
}
|
|
2211
2235
|
|
|
2212
|
-
|
|
2213
2236
|
const isStateGetter = (arg) => {
|
|
2214
|
-
return typeof arg ===
|
|
2237
|
+
return typeof arg === "function" && arg?.()?.isStateGetter?.() === true;
|
|
2215
2238
|
};
|
|
2216
2239
|
|
|
2217
2240
|
const camel2hyphencase = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
|
|
@@ -3481,6 +3504,63 @@ const Switch=({key, cases})=> new UISwitch(key, cases);
|
|
|
3481
3504
|
// return this.cases[matched]()
|
|
3482
3505
|
// }
|
|
3483
3506
|
|
|
3507
|
+
class UISwap extends UIElement$1 {
|
|
3508
|
+
#DISPLAYS_MAP = new WeakMap()
|
|
3509
|
+
constructor({ activeIndex = 0 } = {}, ...items) {
|
|
3510
|
+
super({ element: 'div' });
|
|
3511
|
+
this.style({ display: 'contents' });
|
|
3512
|
+
|
|
3513
|
+
this.states = {
|
|
3514
|
+
activeIndex
|
|
3515
|
+
};
|
|
3516
|
+
|
|
3517
|
+
this.append(...items);
|
|
3518
|
+
this.#setup();
|
|
3519
|
+
}
|
|
3520
|
+
get activeItem(){
|
|
3521
|
+
return this.items[this.states.activeIndex]
|
|
3522
|
+
}
|
|
3523
|
+
#setup() {
|
|
3524
|
+
this.items.forEach((n, i) => {
|
|
3525
|
+
// Store initial display style (fallback to empty string or default)
|
|
3526
|
+
const initialDisplay = n.element?.style?.display || '';
|
|
3527
|
+
this.#DISPLAYS_MAP.set(n, initialDisplay);
|
|
3528
|
+
|
|
3529
|
+
if (i !== this.states.activeIndex) {
|
|
3530
|
+
n.style({ display: 'none' });
|
|
3531
|
+
}
|
|
3532
|
+
});
|
|
3533
|
+
}
|
|
3534
|
+
next(n = 1) {
|
|
3535
|
+
return this.activate(this.states.activeIndex + n);
|
|
3536
|
+
}
|
|
3537
|
+
previous(n = 1) {
|
|
3538
|
+
return this.activate(this.states.activeIndex - n);
|
|
3539
|
+
}
|
|
3540
|
+
activate(index) {
|
|
3541
|
+
if (!this.items.length) return this;
|
|
3542
|
+
|
|
3543
|
+
const currentItem = this.items.at(this.states.activeIndex);
|
|
3544
|
+
|
|
3545
|
+
if (currentItem) {
|
|
3546
|
+
currentItem.style({ display: 'none' });
|
|
3547
|
+
}
|
|
3548
|
+
|
|
3549
|
+
const len = this.items.length;
|
|
3550
|
+
this.states.activeIndex = ((index % len) + len) % len;
|
|
3551
|
+
|
|
3552
|
+
const activeItem = this.items.at(this.states.activeIndex);
|
|
3553
|
+
if (activeItem) {
|
|
3554
|
+
const restoredDisplay = this.#DISPLAYS_MAP.get(activeItem) || 'block';
|
|
3555
|
+
activeItem.style({ display: restoredDisplay === 'none' ? 'block' : restoredDisplay });
|
|
3556
|
+
}
|
|
3557
|
+
|
|
3558
|
+
return this;
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
|
|
3562
|
+
const Swap = call_with_optional_props(UISwap);
|
|
3563
|
+
|
|
3484
3564
|
const { PI, sqrt: sqrt$1, cos: cos$2, sin: sin$2, acos, pow } = Math;
|
|
3485
3565
|
|
|
3486
3566
|
const linear = t => t;
|
|
@@ -4907,6 +4987,7 @@ exports.SPA = SPA;
|
|
|
4907
4987
|
exports.SVGWrapper = SVGWrapper;
|
|
4908
4988
|
exports.Scheduler = Scheduler;
|
|
4909
4989
|
exports.Suspense = Suspense;
|
|
4990
|
+
exports.Swap = Swap;
|
|
4910
4991
|
exports.SwipeEvent = SwipeEvent;
|
|
4911
4992
|
exports.Switch = Switch;
|
|
4912
4993
|
exports.Tick = Tick;
|
|
@@ -4918,6 +4999,7 @@ exports.UIFlex = UIFlex;
|
|
|
4918
4999
|
exports.UIHTMLWrapper = UIHTMLWrapper;
|
|
4919
5000
|
exports.UINode = UINode;
|
|
4920
5001
|
exports.UISVGWrapper = UISVGWrapper;
|
|
5002
|
+
exports.UISwap = UISwap;
|
|
4921
5003
|
exports.UISwitch = UISwitch;
|
|
4922
5004
|
exports.UIView = UIView;
|
|
4923
5005
|
exports.UseRoot = UseRoot;
|
|
@@ -5077,7 +5159,7 @@ exports.trunc = trunc;
|
|
|
5077
5159
|
exports.useDerived = useDerived;
|
|
5078
5160
|
exports.useEventEmitter = useEventEmitter;
|
|
5079
5161
|
exports.useIPC = useIPC;
|
|
5080
|
-
exports.
|
|
5162
|
+
exports.useLocalStorage = useLocalStorage;
|
|
5081
5163
|
exports.useMediaQuery = useMediaQuery;
|
|
5082
5164
|
exports.useQueryParams = useQueryParams;
|
|
5083
5165
|
exports.useReactive = useReactive;
|