ziko 0.34.2 → 0.35.1
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 +162 -162
- package/dist/ziko.js +194 -248
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +194 -248
- package/package.json +6 -4
- package/src/index.js +2 -2
- package/src/reactivity/hooks/UI/index.js +2 -2
- package/src/reactivity/hooks/index.js +1 -1
- package/src/ui/{elements/ZikoUIElement.js → constructors/ziko-ui-element.js} +12 -7
- package/src/ui/constructors/ziko-ui-node.js +15 -0
- package/src/ui/elements/flex/index.js +1 -1
- package/src/ui/elements/grid/index.js +1 -1
- package/src/ui/elements/io/Inputs/__helpers__.js +1 -1
- package/src/ui/elements/io/Inputs/input/index.js +1 -1
- package/src/ui/elements/io/Inputs/input-file/input-image.js +1 -1
- package/src/ui/elements/io/Select/index.js +1 -1
- package/src/ui/elements/io/Textarea/index.js +1 -1
- package/src/ui/elements/list/index.js +1 -1
- package/src/ui/elements/media/Image/figure.js +1 -1
- package/src/ui/elements/media/Image/image.js +1 -1
- package/src/ui/elements/media/__ZikoUIDynamicMediaELement__.js +1 -1
- package/src/ui/elements/misc/hyperscript.js +1 -1
- package/src/ui/elements/misc/index.js +1 -1
- package/src/ui/elements/misc/suspense.js +1 -1
- package/src/ui/elements/misc/xml-wrapper.js +1 -1
- package/src/ui/elements/semantic/index.js +1 -1
- package/src/ui/elements/table/elements.js +1 -1
- package/src/ui/elements/table/table.js +1 -1
- package/src/ui/elements/text/__ZikoUIText__.js +1 -1
- package/src/ui/elements/text/heading.js +1 -1
- package/src/ui/index.js +1 -1
- package/src/ui/tags/index.js +1 -1
- package/src/ui/utils/index.js +1 -1
- package/src/watch/dom-observer/ziko-observer.js +15 -0
package/dist/ziko.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Thu Aug 07 2025 11:37:20 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
|
|
@@ -1202,6 +1202,22 @@
|
|
|
1202
1202
|
}
|
|
1203
1203
|
};
|
|
1204
1204
|
|
|
1205
|
+
class ZikoUINode {
|
|
1206
|
+
constructor(node){
|
|
1207
|
+
this.cache = {
|
|
1208
|
+
node
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
isZikoUINode(){
|
|
1212
|
+
return true
|
|
1213
|
+
}
|
|
1214
|
+
get node(){
|
|
1215
|
+
return this.cache.node;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
globalThis.node = (node) => new ZikoUINode(node);
|
|
1220
|
+
|
|
1205
1221
|
const DomMethods = {
|
|
1206
1222
|
append(...ele) {
|
|
1207
1223
|
__addItem__.call(this, "append", "push", ...ele);
|
|
@@ -1728,7 +1744,7 @@
|
|
|
1728
1744
|
});
|
|
1729
1745
|
});
|
|
1730
1746
|
|
|
1731
|
-
|
|
1747
|
+
class ZikoUseStyle {
|
|
1732
1748
|
constructor(style = {}, use = style.hasOwnProperty("default")? "default" : Object.keys(style)[0], id = 0) {
|
|
1733
1749
|
this.id = "Ziko-Style-" + id;
|
|
1734
1750
|
this.keys = new Set();
|
|
@@ -1800,7 +1816,9 @@
|
|
|
1800
1816
|
if (style && typeof style === "object") return this.#useStyleObject(style);
|
|
1801
1817
|
return this;
|
|
1802
1818
|
}
|
|
1803
|
-
}
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
const useStyle = (styles, use, id) => new ZikoUseStyle(styles, use, id);
|
|
1804
1822
|
|
|
1805
1823
|
const addSuffixeToNumber=(value,suffixe="px")=>{
|
|
1806
1824
|
if(typeof value === "number") value+=suffixe;
|
|
@@ -3236,82 +3254,6 @@
|
|
|
3236
3254
|
|
|
3237
3255
|
const useHead$1=({ title, lang, icon, meta, noscript })=>new ZikoHead$1({ title, lang, icon, meta, noscript });
|
|
3238
3256
|
|
|
3239
|
-
class ZikoUseStyle {
|
|
3240
|
-
constructor(style = {}, use = style.hasOwnProperty("default")? "default" : Object.keys(style)[0], id = 0) {
|
|
3241
|
-
this.id = "Ziko-Style-" + id;
|
|
3242
|
-
this.keys = new Set();
|
|
3243
|
-
this.styles = {
|
|
3244
|
-
default: {
|
|
3245
|
-
fontSize: "1em",
|
|
3246
|
-
color : "green"
|
|
3247
|
-
},
|
|
3248
|
-
other: {
|
|
3249
|
-
fontSize : "2em",
|
|
3250
|
-
color : "cyan"
|
|
3251
|
-
}
|
|
3252
|
-
};
|
|
3253
|
-
style && this.add(style);
|
|
3254
|
-
use && this.use(use);
|
|
3255
|
-
}
|
|
3256
|
-
|
|
3257
|
-
get current() {
|
|
3258
|
-
return [...this.keys].reduce((key, value) => {
|
|
3259
|
-
key[value] = `var(--${value}-${this.id})`;
|
|
3260
|
-
return key;
|
|
3261
|
-
}, {});
|
|
3262
|
-
}
|
|
3263
|
-
|
|
3264
|
-
add(name, style = {}) {
|
|
3265
|
-
if (name && typeof name === 'object' && !Array.isArray(name)) {
|
|
3266
|
-
Object.assign(this.styles, name);
|
|
3267
|
-
} else if (typeof name === 'string') {
|
|
3268
|
-
Object.assign(this.styles, { [name]: style });
|
|
3269
|
-
}
|
|
3270
|
-
return this;
|
|
3271
|
-
}
|
|
3272
|
-
|
|
3273
|
-
#useStyleIndex(index) {
|
|
3274
|
-
const keys = Object.keys(this.styles);
|
|
3275
|
-
for (let a in this.styles[keys[index]]) {
|
|
3276
|
-
if (Object.prototype.hasOwnProperty.call(this.styles[keys[index]], a)) {
|
|
3277
|
-
document.documentElement.style.setProperty(`--${a}-${this.id}`, this.styles[keys[index]][a]);
|
|
3278
|
-
this.keys.add(a);
|
|
3279
|
-
}
|
|
3280
|
-
}
|
|
3281
|
-
return this;
|
|
3282
|
-
}
|
|
3283
|
-
|
|
3284
|
-
#useStyleName(name) {
|
|
3285
|
-
if (!this.styles[name]) return this;
|
|
3286
|
-
for (let a in this.styles[name]) {
|
|
3287
|
-
if (Object.prototype.hasOwnProperty.call(this.styles[name], a)) {
|
|
3288
|
-
document.documentElement.style.setProperty(`--${a}-${this.id}`, this.styles[name][a]);
|
|
3289
|
-
this.keys.add(a);
|
|
3290
|
-
}
|
|
3291
|
-
}
|
|
3292
|
-
return this;
|
|
3293
|
-
}
|
|
3294
|
-
|
|
3295
|
-
#useStyleObject(style) {
|
|
3296
|
-
for (let a in style) {
|
|
3297
|
-
if (Object.prototype.hasOwnProperty.call(style, a)) {
|
|
3298
|
-
document.documentElement.style.setProperty(`--${a}-${this.id}`, style[a]);
|
|
3299
|
-
this.keys.add(a);
|
|
3300
|
-
}
|
|
3301
|
-
}
|
|
3302
|
-
return this;
|
|
3303
|
-
}
|
|
3304
|
-
|
|
3305
|
-
use(style) {
|
|
3306
|
-
if (typeof style === "number") return this.#useStyleIndex(style);
|
|
3307
|
-
if (typeof style === "string") return this.#useStyleName(style);
|
|
3308
|
-
if (style && typeof style === "object") return this.#useStyleObject(style);
|
|
3309
|
-
return this;
|
|
3310
|
-
}
|
|
3311
|
-
}
|
|
3312
|
-
|
|
3313
|
-
const useStyle = (styles, use, id) => new ZikoUseStyle(styles, use, id);
|
|
3314
|
-
|
|
3315
3257
|
/*
|
|
3316
3258
|
[
|
|
3317
3259
|
{
|
|
@@ -3410,8 +3352,9 @@
|
|
|
3410
3352
|
...Hooks,
|
|
3411
3353
|
};
|
|
3412
3354
|
|
|
3413
|
-
class ZikoUIElement {
|
|
3355
|
+
class ZikoUIElement extends ZikoUINode{
|
|
3414
3356
|
constructor(element, name="", {el_type="html", useDefaultStyle=false}={}){
|
|
3357
|
+
super();
|
|
3415
3358
|
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
3416
3359
|
if(typeof element === "string") {
|
|
3417
3360
|
switch(el_type){
|
|
@@ -3423,7 +3366,7 @@
|
|
|
3423
3366
|
else {
|
|
3424
3367
|
this.target = element.parentElement;
|
|
3425
3368
|
}
|
|
3426
|
-
if(element)this.__ele__ = element;
|
|
3369
|
+
// if(element)this.__ele__ = element;
|
|
3427
3370
|
compose(
|
|
3428
3371
|
this,
|
|
3429
3372
|
DomMethods,
|
|
@@ -3435,8 +3378,9 @@
|
|
|
3435
3378
|
// compose(this, ExternalMethods);
|
|
3436
3379
|
// });
|
|
3437
3380
|
// }
|
|
3438
|
-
this.cache
|
|
3381
|
+
Object.assign(this.cache, {
|
|
3439
3382
|
name,
|
|
3383
|
+
isInteractive : [true, false][Math.floor(2*Math.random())],
|
|
3440
3384
|
parent:null,
|
|
3441
3385
|
isBody:false,
|
|
3442
3386
|
isRoot:false,
|
|
@@ -3447,7 +3391,7 @@
|
|
|
3447
3391
|
attributes: {},
|
|
3448
3392
|
filters: {},
|
|
3449
3393
|
temp:{}
|
|
3450
|
-
};
|
|
3394
|
+
});
|
|
3451
3395
|
this.events = {
|
|
3452
3396
|
ptr:null,
|
|
3453
3397
|
mouse:null,
|
|
@@ -3465,6 +3409,7 @@
|
|
|
3465
3409
|
resize:null,
|
|
3466
3410
|
intersection:null
|
|
3467
3411
|
};
|
|
3412
|
+
if(element)Object.assign(this.cache,{element});
|
|
3468
3413
|
this.uuid = `${this.cache.name}-${Random.string(16)}`;
|
|
3469
3414
|
this.ui_index = globalThis.__Ziko__.__CACHE__.get_ui_index();
|
|
3470
3415
|
this.cache.style.linkTo(this);
|
|
@@ -3492,12 +3437,13 @@
|
|
|
3492
3437
|
}
|
|
3493
3438
|
}
|
|
3494
3439
|
get element(){
|
|
3495
|
-
return this.
|
|
3440
|
+
return this.cache.element;
|
|
3496
3441
|
}
|
|
3497
3442
|
isInteractive(){
|
|
3498
|
-
return
|
|
3443
|
+
return this.cache.isInteractive;
|
|
3499
3444
|
}
|
|
3500
|
-
get
|
|
3445
|
+
// Remove get
|
|
3446
|
+
isZikoUIElement(){
|
|
3501
3447
|
return true;
|
|
3502
3448
|
}
|
|
3503
3449
|
register(){
|
|
@@ -3554,7 +3500,7 @@
|
|
|
3554
3500
|
return UI.render(render);
|
|
3555
3501
|
}
|
|
3556
3502
|
style(styles){
|
|
3557
|
-
styles instanceof ZikoUseStyle
|
|
3503
|
+
styles instanceof ZikoUseStyle ? this.st.style(styles.current): this.st.style(styles);
|
|
3558
3504
|
return this;
|
|
3559
3505
|
}
|
|
3560
3506
|
size(width,height){
|
|
@@ -7670,167 +7616,6 @@
|
|
|
7670
7616
|
...CANVAS
|
|
7671
7617
|
};
|
|
7672
7618
|
|
|
7673
|
-
class ZikoUseChannel{
|
|
7674
|
-
constructor(name = ""){
|
|
7675
|
-
this.channel = new BroadcastChannel(name);
|
|
7676
|
-
this.EVENTS_DATAS_PAIRS = new Map();
|
|
7677
|
-
this.EVENTS_HANDLERS_PAIRS = new Map();
|
|
7678
|
-
this.LAST_RECEIVED_EVENT = "";
|
|
7679
|
-
this.UUID="ziko-channel"+Random.string(10);
|
|
7680
|
-
this.SUBSCRIBERS = new Set([this.UUID]);
|
|
7681
|
-
}
|
|
7682
|
-
get broadcast(){
|
|
7683
|
-
// update receiver
|
|
7684
|
-
return this;
|
|
7685
|
-
}
|
|
7686
|
-
emit(event, data){
|
|
7687
|
-
this.EVENTS_DATAS_PAIRS.set(event,data);
|
|
7688
|
-
this.#maintainEmit(event);
|
|
7689
|
-
return this;
|
|
7690
|
-
}
|
|
7691
|
-
on(event,handler=console.log){
|
|
7692
|
-
this.EVENTS_HANDLERS_PAIRS.set(event,handler);
|
|
7693
|
-
this.#maintainOn();
|
|
7694
|
-
return this;
|
|
7695
|
-
}
|
|
7696
|
-
#maintainOn(){
|
|
7697
|
-
this.channel.onmessage = (e) => {
|
|
7698
|
-
this.LAST_RECEIVED_EVENT=e.data.last_sended_event;
|
|
7699
|
-
const USER_ID=e.data.userId;
|
|
7700
|
-
this.SUBSCRIBERS.add(USER_ID);
|
|
7701
|
-
const Data=e.data.EVENTS_DATAS_PAIRS.get(this.LAST_RECEIVED_EVENT);
|
|
7702
|
-
const Handler=this.EVENTS_HANDLERS_PAIRS.get(this.LAST_RECEIVED_EVENT);
|
|
7703
|
-
if(Data && Handler)Handler(Data);
|
|
7704
|
-
};
|
|
7705
|
-
return this;
|
|
7706
|
-
}
|
|
7707
|
-
#maintainEmit(event){
|
|
7708
|
-
this.channel.postMessage({
|
|
7709
|
-
EVENTS_DATAS_PAIRS:this.EVENTS_DATAS_PAIRS,
|
|
7710
|
-
last_sended_event:event,
|
|
7711
|
-
userId:this.UUID
|
|
7712
|
-
});
|
|
7713
|
-
return this;
|
|
7714
|
-
}
|
|
7715
|
-
close(){
|
|
7716
|
-
this.channel.close();
|
|
7717
|
-
return this;
|
|
7718
|
-
}
|
|
7719
|
-
}
|
|
7720
|
-
const useChannel = name => new ZikoUseChannel(name);
|
|
7721
|
-
|
|
7722
|
-
// To do : remove old items
|
|
7723
|
-
class ZikoUseStorage{
|
|
7724
|
-
constructor(storage, globalKey, initialValue){
|
|
7725
|
-
this.cache={
|
|
7726
|
-
storage,
|
|
7727
|
-
globalKey,
|
|
7728
|
-
channel:useChannel(`Ziko:useStorage-${globalKey}`),
|
|
7729
|
-
oldItemKeys:new Set()
|
|
7730
|
-
};
|
|
7731
|
-
this.#init(initialValue);
|
|
7732
|
-
this.#maintain();
|
|
7733
|
-
}
|
|
7734
|
-
get items(){
|
|
7735
|
-
return JSON.parse(this.cache.storage[this.cache.globalKey]??null);
|
|
7736
|
-
}
|
|
7737
|
-
#maintain() {
|
|
7738
|
-
for(let i in this.items)Object.assign(this, { [[i]]: this.items[i] });
|
|
7739
|
-
}
|
|
7740
|
-
#init(initialValue){
|
|
7741
|
-
this.cache.channel=useChannel(`Ziko:useStorage-${this.cache.globalKey}`);
|
|
7742
|
-
this.cache.channel.on("Ziko-Storage-Updated",()=>this.#maintain());
|
|
7743
|
-
if(!initialValue)return;
|
|
7744
|
-
if(this.cache.storage[this.cache.globalKey]){
|
|
7745
|
-
Object.keys(this.items).forEach(key=>this.cache.oldItemKeys.add(key));
|
|
7746
|
-
console.group("Ziko:useStorage");
|
|
7747
|
-
console.warn(`Storage key '${this.cache.globalKey}' already exists. we will not overwrite it.`);
|
|
7748
|
-
console.info(`%cWe'll keep the existing data.`,"background-color:#2222dd; color:gold;");
|
|
7749
|
-
console.group("");
|
|
7750
|
-
}
|
|
7751
|
-
else this.set(initialValue);
|
|
7752
|
-
}
|
|
7753
|
-
set(data){
|
|
7754
|
-
this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(data));
|
|
7755
|
-
this.cache.channel.emit("Ziko-Storage-Updated",{});
|
|
7756
|
-
Object.keys(data).forEach(key=>this.cache.oldItemKeys.add(key));
|
|
7757
|
-
this.#maintain();
|
|
7758
|
-
return this
|
|
7759
|
-
}
|
|
7760
|
-
add(data){
|
|
7761
|
-
const db={
|
|
7762
|
-
...this.items,
|
|
7763
|
-
...data
|
|
7764
|
-
};
|
|
7765
|
-
this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(db));
|
|
7766
|
-
this.#maintain();
|
|
7767
|
-
return this;
|
|
7768
|
-
}
|
|
7769
|
-
remove(...keys){
|
|
7770
|
-
const db={...this.items};
|
|
7771
|
-
for(let i=0;i<keys.length;i++){
|
|
7772
|
-
delete db[keys[i]];
|
|
7773
|
-
delete this[keys[i]];
|
|
7774
|
-
}
|
|
7775
|
-
this.set(db);
|
|
7776
|
-
return this;
|
|
7777
|
-
}
|
|
7778
|
-
get(key){
|
|
7779
|
-
return this.items[key];
|
|
7780
|
-
}
|
|
7781
|
-
clear(){
|
|
7782
|
-
this.cache.storage.removeItem(this.cache.globalKey);
|
|
7783
|
-
this.#maintain();
|
|
7784
|
-
return this;
|
|
7785
|
-
}
|
|
7786
|
-
|
|
7787
|
-
}
|
|
7788
|
-
const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
|
|
7789
|
-
const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
|
|
7790
|
-
|
|
7791
|
-
class ZikoUseThreed {
|
|
7792
|
-
#workerContent;
|
|
7793
|
-
constructor() {
|
|
7794
|
-
this.#workerContent = (
|
|
7795
|
-
function (msg) {
|
|
7796
|
-
try {
|
|
7797
|
-
const func = new Function("return " + msg.data.fun)();
|
|
7798
|
-
let result = func();
|
|
7799
|
-
postMessage({ result });
|
|
7800
|
-
} catch (error) {
|
|
7801
|
-
postMessage({ error: error.message });
|
|
7802
|
-
} finally {
|
|
7803
|
-
if (msg.data.close) self.close();
|
|
7804
|
-
}
|
|
7805
|
-
}
|
|
7806
|
-
).toString();
|
|
7807
|
-
this.blob = new Blob(["this.onmessage = " + this.#workerContent], { type: "text/javascript" });
|
|
7808
|
-
this.worker = new Worker(window.URL.createObjectURL(this.blob));
|
|
7809
|
-
}
|
|
7810
|
-
call(func, callback, close = true) {
|
|
7811
|
-
this.worker.postMessage({
|
|
7812
|
-
fun: func.toString(),
|
|
7813
|
-
close
|
|
7814
|
-
});
|
|
7815
|
-
this.worker.onmessage = function (e) {
|
|
7816
|
-
if (e.data.error) {
|
|
7817
|
-
console.error(e.data.error);
|
|
7818
|
-
} else {
|
|
7819
|
-
callback(e.data.result);
|
|
7820
|
-
}
|
|
7821
|
-
};
|
|
7822
|
-
return this;
|
|
7823
|
-
}
|
|
7824
|
-
}
|
|
7825
|
-
|
|
7826
|
-
const useThread = (func, callback , close) => {
|
|
7827
|
-
const T = new ZikoUseThreed();
|
|
7828
|
-
if (func) {
|
|
7829
|
-
T.call(func, callback , close);
|
|
7830
|
-
}
|
|
7831
|
-
return T;
|
|
7832
|
-
};
|
|
7833
|
-
|
|
7834
7619
|
class ZikoUseFavIcon{
|
|
7835
7620
|
constructor(FavIcon,useEventEmitter=true){
|
|
7836
7621
|
this.#init();
|
|
@@ -8271,6 +8056,167 @@
|
|
|
8271
8056
|
// ...Params
|
|
8272
8057
|
};
|
|
8273
8058
|
|
|
8059
|
+
class ZikoUseChannel{
|
|
8060
|
+
constructor(name = ""){
|
|
8061
|
+
this.channel = new BroadcastChannel(name);
|
|
8062
|
+
this.EVENTS_DATAS_PAIRS = new Map();
|
|
8063
|
+
this.EVENTS_HANDLERS_PAIRS = new Map();
|
|
8064
|
+
this.LAST_RECEIVED_EVENT = "";
|
|
8065
|
+
this.UUID="ziko-channel"+Random.string(10);
|
|
8066
|
+
this.SUBSCRIBERS = new Set([this.UUID]);
|
|
8067
|
+
}
|
|
8068
|
+
get broadcast(){
|
|
8069
|
+
// update receiver
|
|
8070
|
+
return this;
|
|
8071
|
+
}
|
|
8072
|
+
emit(event, data){
|
|
8073
|
+
this.EVENTS_DATAS_PAIRS.set(event,data);
|
|
8074
|
+
this.#maintainEmit(event);
|
|
8075
|
+
return this;
|
|
8076
|
+
}
|
|
8077
|
+
on(event,handler=console.log){
|
|
8078
|
+
this.EVENTS_HANDLERS_PAIRS.set(event,handler);
|
|
8079
|
+
this.#maintainOn();
|
|
8080
|
+
return this;
|
|
8081
|
+
}
|
|
8082
|
+
#maintainOn(){
|
|
8083
|
+
this.channel.onmessage = (e) => {
|
|
8084
|
+
this.LAST_RECEIVED_EVENT=e.data.last_sended_event;
|
|
8085
|
+
const USER_ID=e.data.userId;
|
|
8086
|
+
this.SUBSCRIBERS.add(USER_ID);
|
|
8087
|
+
const Data=e.data.EVENTS_DATAS_PAIRS.get(this.LAST_RECEIVED_EVENT);
|
|
8088
|
+
const Handler=this.EVENTS_HANDLERS_PAIRS.get(this.LAST_RECEIVED_EVENT);
|
|
8089
|
+
if(Data && Handler)Handler(Data);
|
|
8090
|
+
};
|
|
8091
|
+
return this;
|
|
8092
|
+
}
|
|
8093
|
+
#maintainEmit(event){
|
|
8094
|
+
this.channel.postMessage({
|
|
8095
|
+
EVENTS_DATAS_PAIRS:this.EVENTS_DATAS_PAIRS,
|
|
8096
|
+
last_sended_event:event,
|
|
8097
|
+
userId:this.UUID
|
|
8098
|
+
});
|
|
8099
|
+
return this;
|
|
8100
|
+
}
|
|
8101
|
+
close(){
|
|
8102
|
+
this.channel.close();
|
|
8103
|
+
return this;
|
|
8104
|
+
}
|
|
8105
|
+
}
|
|
8106
|
+
const useChannel = name => new ZikoUseChannel(name);
|
|
8107
|
+
|
|
8108
|
+
// To do : remove old items
|
|
8109
|
+
class ZikoUseStorage{
|
|
8110
|
+
constructor(storage, globalKey, initialValue){
|
|
8111
|
+
this.cache={
|
|
8112
|
+
storage,
|
|
8113
|
+
globalKey,
|
|
8114
|
+
channel:useChannel(`Ziko:useStorage-${globalKey}`),
|
|
8115
|
+
oldItemKeys:new Set()
|
|
8116
|
+
};
|
|
8117
|
+
this.#init(initialValue);
|
|
8118
|
+
this.#maintain();
|
|
8119
|
+
}
|
|
8120
|
+
get items(){
|
|
8121
|
+
return JSON.parse(this.cache.storage[this.cache.globalKey]??null);
|
|
8122
|
+
}
|
|
8123
|
+
#maintain() {
|
|
8124
|
+
for(let i in this.items)Object.assign(this, { [[i]]: this.items[i] });
|
|
8125
|
+
}
|
|
8126
|
+
#init(initialValue){
|
|
8127
|
+
this.cache.channel=useChannel(`Ziko:useStorage-${this.cache.globalKey}`);
|
|
8128
|
+
this.cache.channel.on("Ziko-Storage-Updated",()=>this.#maintain());
|
|
8129
|
+
if(!initialValue)return;
|
|
8130
|
+
if(this.cache.storage[this.cache.globalKey]){
|
|
8131
|
+
Object.keys(this.items).forEach(key=>this.cache.oldItemKeys.add(key));
|
|
8132
|
+
console.group("Ziko:useStorage");
|
|
8133
|
+
console.warn(`Storage key '${this.cache.globalKey}' already exists. we will not overwrite it.`);
|
|
8134
|
+
console.info(`%cWe'll keep the existing data.`,"background-color:#2222dd; color:gold;");
|
|
8135
|
+
console.group("");
|
|
8136
|
+
}
|
|
8137
|
+
else this.set(initialValue);
|
|
8138
|
+
}
|
|
8139
|
+
set(data){
|
|
8140
|
+
this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(data));
|
|
8141
|
+
this.cache.channel.emit("Ziko-Storage-Updated",{});
|
|
8142
|
+
Object.keys(data).forEach(key=>this.cache.oldItemKeys.add(key));
|
|
8143
|
+
this.#maintain();
|
|
8144
|
+
return this
|
|
8145
|
+
}
|
|
8146
|
+
add(data){
|
|
8147
|
+
const db={
|
|
8148
|
+
...this.items,
|
|
8149
|
+
...data
|
|
8150
|
+
};
|
|
8151
|
+
this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(db));
|
|
8152
|
+
this.#maintain();
|
|
8153
|
+
return this;
|
|
8154
|
+
}
|
|
8155
|
+
remove(...keys){
|
|
8156
|
+
const db={...this.items};
|
|
8157
|
+
for(let i=0;i<keys.length;i++){
|
|
8158
|
+
delete db[keys[i]];
|
|
8159
|
+
delete this[keys[i]];
|
|
8160
|
+
}
|
|
8161
|
+
this.set(db);
|
|
8162
|
+
return this;
|
|
8163
|
+
}
|
|
8164
|
+
get(key){
|
|
8165
|
+
return this.items[key];
|
|
8166
|
+
}
|
|
8167
|
+
clear(){
|
|
8168
|
+
this.cache.storage.removeItem(this.cache.globalKey);
|
|
8169
|
+
this.#maintain();
|
|
8170
|
+
return this;
|
|
8171
|
+
}
|
|
8172
|
+
|
|
8173
|
+
}
|
|
8174
|
+
const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
|
|
8175
|
+
const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
|
|
8176
|
+
|
|
8177
|
+
class ZikoUseThreed {
|
|
8178
|
+
#workerContent;
|
|
8179
|
+
constructor() {
|
|
8180
|
+
this.#workerContent = (
|
|
8181
|
+
function (msg) {
|
|
8182
|
+
try {
|
|
8183
|
+
const func = new Function("return " + msg.data.fun)();
|
|
8184
|
+
let result = func();
|
|
8185
|
+
postMessage({ result });
|
|
8186
|
+
} catch (error) {
|
|
8187
|
+
postMessage({ error: error.message });
|
|
8188
|
+
} finally {
|
|
8189
|
+
if (msg.data.close) self.close();
|
|
8190
|
+
}
|
|
8191
|
+
}
|
|
8192
|
+
).toString();
|
|
8193
|
+
this.blob = new Blob(["this.onmessage = " + this.#workerContent], { type: "text/javascript" });
|
|
8194
|
+
this.worker = new Worker(window.URL.createObjectURL(this.blob));
|
|
8195
|
+
}
|
|
8196
|
+
call(func, callback, close = true) {
|
|
8197
|
+
this.worker.postMessage({
|
|
8198
|
+
fun: func.toString(),
|
|
8199
|
+
close
|
|
8200
|
+
});
|
|
8201
|
+
this.worker.onmessage = function (e) {
|
|
8202
|
+
if (e.data.error) {
|
|
8203
|
+
console.error(e.data.error);
|
|
8204
|
+
} else {
|
|
8205
|
+
callback(e.data.result);
|
|
8206
|
+
}
|
|
8207
|
+
};
|
|
8208
|
+
return this;
|
|
8209
|
+
}
|
|
8210
|
+
}
|
|
8211
|
+
|
|
8212
|
+
const useThread = (func, callback , close) => {
|
|
8213
|
+
const T = new ZikoUseThreed();
|
|
8214
|
+
if (func) {
|
|
8215
|
+
T.call(func, callback , close);
|
|
8216
|
+
}
|
|
8217
|
+
return T;
|
|
8218
|
+
};
|
|
8219
|
+
|
|
8274
8220
|
[
|
|
8275
8221
|
App,
|
|
8276
8222
|
Math$1,
|