ziko 0.36.1 → 0.37.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 +160 -91
- package/dist/ziko.js +160 -91
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +160 -91
- package/package.json +4 -2
- package/readme.md +19 -13
- package/src/reactivity/hooks/Head/useFavIcon.js +1 -1
- package/src/reactivity/hooks/Head/useTitle.js +1 -1
- package/src/reactivity/hooks/UI/index.js +1 -1
- package/src/ui/methods/dom.js +18 -10
- package/src/use/index.js +15 -3
- package/src/use/{interactions/use-channel.js → use-channel.js} +1 -1
- package/src/use/use-root.js +77 -0
- package/src/use/use-state.js +22 -0
- package/src/use/{storage/index.js → use-storage.js} +1 -1
- package/src/use/app/index.js +0 -0
- package/src/use/decorators/index.js +0 -2
- package/src/use/interactions/index.js +0 -3
- /package/src/use/{decorators/use-debounce.js → use-debounce.js} +0 -0
- /package/src/use/{interactions/use-event-emmiter.js → use-event-emmiter.js} +0 -0
- /package/src/use/{app/use-favicon.js → use-favicon.js} +0 -0
- /package/src/use/{app/use-link.js → use-link.js} +0 -0
- /package/src/use/{app/use-meta.js → use-meta.js} +0 -0
- /package/src/use/{interactions/use-thread.js → use-thread.js} +0 -0
- /package/src/use/{decorators/use-throttle.js → use-throttle.js} +0 -0
- /package/src/use/{app/use-title.js → use-title.js} +0 -0
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 : Fri Aug 15 2025 09:48: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
|
|
@@ -1292,17 +1292,25 @@ function __addItem__(adder, pusher, ...ele) {
|
|
|
1292
1292
|
}
|
|
1293
1293
|
for (let i = 0; i < ele.length; i++) {
|
|
1294
1294
|
if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
|
|
1295
|
-
if (
|
|
1296
|
-
typeof globalThis?.Node === "function" &&
|
|
1297
|
-
ele[i] instanceof globalThis?.Node
|
|
1298
|
-
)
|
|
1299
|
-
ele[i] = new this.constructor(ele[i]);
|
|
1295
|
+
if (typeof globalThis?.Node === "function" && ele[i] instanceof globalThis?.Node) ele[i] = new this.constructor(ele[i]);
|
|
1300
1296
|
if (ele[i]?.isZikoUIElement) {
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
}
|
|
1297
|
+
ele[i].cache.parent = this;
|
|
1298
|
+
this.element[adder](ele[i].element);
|
|
1299
|
+
ele[i].target = this.element;
|
|
1300
|
+
this.items[pusher](ele[i]);
|
|
1301
|
+
}
|
|
1302
|
+
// Fix Items Latter
|
|
1303
|
+
if( ele[i] instanceof Function){
|
|
1304
|
+
const getter = ele[i]();
|
|
1305
|
+
if (getter.isStateGetter) {
|
|
1306
|
+
const textNode = document?.createTextNode(getter.value);
|
|
1307
|
+
this.element.appendChild(textNode);
|
|
1308
|
+
getter._subscribe(
|
|
1309
|
+
(newValue) => (textNode.textContent = newValue),
|
|
1310
|
+
);
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
else if (ele[i] instanceof Object) {
|
|
1306
1314
|
if (ele[i]?.style) this.style(ele[i]?.style);
|
|
1307
1315
|
if (ele[i]?.attr) {
|
|
1308
1316
|
Object.entries(ele[i].attr).forEach((n) =>
|
|
@@ -3293,52 +3301,16 @@ class ZikoUseMediaQuery {
|
|
|
3293
3301
|
|
|
3294
3302
|
const useMediaQuery = (mediaQueryRules,fallback) => new ZikoUseMediaQuery(mediaQueryRules,fallback);
|
|
3295
3303
|
|
|
3296
|
-
class ZikoUseRoot{
|
|
3297
|
-
constructor(props){
|
|
3298
|
-
this.props={};
|
|
3299
|
-
props && this.set(props);
|
|
3300
|
-
}
|
|
3301
|
-
get(prop){
|
|
3302
|
-
return this.props[prop]
|
|
3303
|
-
}
|
|
3304
|
-
// getStaticValue(){
|
|
3305
|
-
// return document.documentElement.style.getPropertyValue("--primary-col")
|
|
3306
|
-
// }
|
|
3307
|
-
set(props){
|
|
3308
|
-
Object.entries(props).forEach(([key,value])=>this.#setOneProp(key, value));
|
|
3309
|
-
return this;
|
|
3310
|
-
}
|
|
3311
|
-
#setOneProp(prop, value){
|
|
3312
|
-
const CssProp = `--${Str.camel2hyphencase(prop)}`;
|
|
3313
|
-
document.documentElement.style.setProperty(CssProp,value);
|
|
3314
|
-
Object.assign(this.props, {[prop]: `var(${CssProp})`});
|
|
3315
|
-
Object.assign(this, {[prop] : `var(${CssProp})`});
|
|
3316
|
-
}
|
|
3317
|
-
}
|
|
3318
|
-
|
|
3319
|
-
const useRootValue=CssVar=>{
|
|
3320
|
-
if(!CssVar.startsWith("--")) CssVar = `--${Str.camel2hyphencase(CssVar)}`;
|
|
3321
|
-
return `var(${CssVar})`
|
|
3322
|
-
};
|
|
3323
|
-
// const useRootStaticValue=CssVar=>{
|
|
3324
|
-
// if(!CssVar.startsWith("--")) CssVar = `--${Str.camel2hyphencase(CssVar)}`
|
|
3325
|
-
// return globalThis.document.documentElement.style.getPropertyValue(CssVar)
|
|
3326
|
-
// }
|
|
3327
|
-
const useRoot=(props)=>new ZikoUseRoot(props);
|
|
3328
|
-
|
|
3329
3304
|
// export * from "./window"
|
|
3330
3305
|
|
|
3331
3306
|
var Hooks = /*#__PURE__*/Object.freeze({
|
|
3332
3307
|
__proto__: null,
|
|
3333
3308
|
ZikoHead: ZikoHead$1,
|
|
3334
|
-
ZikoUseRoot: ZikoUseRoot,
|
|
3335
3309
|
ZikoUseStyle: ZikoUseStyle,
|
|
3336
3310
|
useFavIcon: useFavIcon$1,
|
|
3337
3311
|
useHead: useHead$1,
|
|
3338
3312
|
useMediaQuery: useMediaQuery,
|
|
3339
3313
|
useMeta: useMeta$1,
|
|
3340
|
-
useRoot: useRoot,
|
|
3341
|
-
useRootValue: useRootValue,
|
|
3342
3314
|
useStyle: useStyle,
|
|
3343
3315
|
useSuccesifKeys: useSuccesifKeys,
|
|
3344
3316
|
useTitle: useTitle$1
|
|
@@ -8070,6 +8042,29 @@ const App={
|
|
|
8070
8042
|
// ...Params
|
|
8071
8043
|
};
|
|
8072
8044
|
|
|
8045
|
+
function useState(initialValue) {
|
|
8046
|
+
let value = initialValue;
|
|
8047
|
+
const subscribers = new Set();
|
|
8048
|
+
|
|
8049
|
+
function getValue() {
|
|
8050
|
+
return {
|
|
8051
|
+
value,
|
|
8052
|
+
isStateGetter: () => true,
|
|
8053
|
+
_subscribe: (fn) => subscribers.add(fn),
|
|
8054
|
+
};
|
|
8055
|
+
}
|
|
8056
|
+
|
|
8057
|
+
function setValue(newValue) {
|
|
8058
|
+
if (typeof newValue === "function") newValue = newValue(value);
|
|
8059
|
+
if (newValue !== value) {
|
|
8060
|
+
value = newValue;
|
|
8061
|
+
subscribers.forEach(fn => fn(value));
|
|
8062
|
+
}
|
|
8063
|
+
}
|
|
8064
|
+
|
|
8065
|
+
return [getValue, setValue];
|
|
8066
|
+
}
|
|
8067
|
+
|
|
8073
8068
|
class ZikoUseChannel{
|
|
8074
8069
|
constructor(name = ""){
|
|
8075
8070
|
this.channel = new BroadcastChannel(name);
|
|
@@ -8119,6 +8114,123 @@ class ZikoUseChannel{
|
|
|
8119
8114
|
}
|
|
8120
8115
|
const useChannel = name => new ZikoUseChannel(name);
|
|
8121
8116
|
|
|
8117
|
+
class ZikoUseThreed {
|
|
8118
|
+
#workerContent;
|
|
8119
|
+
constructor() {
|
|
8120
|
+
this.#workerContent = (
|
|
8121
|
+
function (msg) {
|
|
8122
|
+
try {
|
|
8123
|
+
const func = new Function("return " + msg.data.fun)();
|
|
8124
|
+
let result = func();
|
|
8125
|
+
postMessage({ result });
|
|
8126
|
+
} catch (error) {
|
|
8127
|
+
postMessage({ error: error.message });
|
|
8128
|
+
} finally {
|
|
8129
|
+
if (msg.data.close) self.close();
|
|
8130
|
+
}
|
|
8131
|
+
}
|
|
8132
|
+
).toString();
|
|
8133
|
+
this.blob = new Blob(["this.onmessage = " + this.#workerContent], { type: "text/javascript" });
|
|
8134
|
+
this.worker = new Worker(window.URL.createObjectURL(this.blob));
|
|
8135
|
+
}
|
|
8136
|
+
call(func, callback, close = true) {
|
|
8137
|
+
this.worker.postMessage({
|
|
8138
|
+
fun: func.toString(),
|
|
8139
|
+
close
|
|
8140
|
+
});
|
|
8141
|
+
this.worker.onmessage = function (e) {
|
|
8142
|
+
if (e.data.error) {
|
|
8143
|
+
console.error(e.data.error);
|
|
8144
|
+
} else {
|
|
8145
|
+
callback(e.data.result);
|
|
8146
|
+
}
|
|
8147
|
+
};
|
|
8148
|
+
return this;
|
|
8149
|
+
}
|
|
8150
|
+
}
|
|
8151
|
+
|
|
8152
|
+
const useThread = (func, callback , close) => {
|
|
8153
|
+
const T = new ZikoUseThreed();
|
|
8154
|
+
if (func) {
|
|
8155
|
+
T.call(func, callback , close);
|
|
8156
|
+
}
|
|
8157
|
+
return T;
|
|
8158
|
+
};
|
|
8159
|
+
|
|
8160
|
+
class ZikoUseRoot {
|
|
8161
|
+
constructor(PropsMap, {namespace = 'Ziko', register, ValidateCssProps = false} = {}){
|
|
8162
|
+
this.currentPropsMap = PropsMap;
|
|
8163
|
+
this.namespace = namespace;
|
|
8164
|
+
this.ValidateCssProps = ValidateCssProps;
|
|
8165
|
+
// this.pairs = {};
|
|
8166
|
+
// this.#maintain()
|
|
8167
|
+
this.use(PropsMap);
|
|
8168
|
+
}
|
|
8169
|
+
use(PropsMap){
|
|
8170
|
+
if(this.ValidateCssProps) ValidateCssProps(PropsMap);
|
|
8171
|
+
this.currentPropsMap = PropsMap;
|
|
8172
|
+
this.#maintain();
|
|
8173
|
+
return this;
|
|
8174
|
+
}
|
|
8175
|
+
#maintain(){
|
|
8176
|
+
const root = globalThis?.document?.documentElement?.style;
|
|
8177
|
+
for(let prop in this.currentPropsMap){
|
|
8178
|
+
const cssProp = this.namespace ? `--${this.namespace}-${prop}` : `--${prop}`;
|
|
8179
|
+
root.setProperty(
|
|
8180
|
+
cssProp,
|
|
8181
|
+
this.currentPropsMap[prop]
|
|
8182
|
+
);
|
|
8183
|
+
console.log({cssProp});
|
|
8184
|
+
// Object.assign(this.pairs, {
|
|
8185
|
+
// [prop] : `var(--${this.namespace}-${prop})`
|
|
8186
|
+
// })
|
|
8187
|
+
Object.defineProperty(this, prop, {
|
|
8188
|
+
value: `var(${cssProp})`,
|
|
8189
|
+
writable: true,
|
|
8190
|
+
configurable: true,
|
|
8191
|
+
enumerable: false
|
|
8192
|
+
});
|
|
8193
|
+
}
|
|
8194
|
+
}
|
|
8195
|
+
}
|
|
8196
|
+
|
|
8197
|
+
function ValidateCssProps(PropsMap){
|
|
8198
|
+
const validProps = new Set(Object.keys(document.documentElement.style));
|
|
8199
|
+
for (let key in PropsMap) {
|
|
8200
|
+
if (!validProps.has(key)) {
|
|
8201
|
+
throw new Error(`Invalid CSS property: "${key}"`);
|
|
8202
|
+
}
|
|
8203
|
+
}
|
|
8204
|
+
}
|
|
8205
|
+
|
|
8206
|
+
const useRoot = (PropsMap, {namespace, register, ValidateCssProps} = {}) => new ZikoUseRoot(PropsMap, {namespace, register, ValidateCssProps});
|
|
8207
|
+
|
|
8208
|
+
// Usage
|
|
8209
|
+
|
|
8210
|
+
/*
|
|
8211
|
+
const Styles = {
|
|
8212
|
+
S1 : {
|
|
8213
|
+
background : 'white',
|
|
8214
|
+
color : 'darkblue'
|
|
8215
|
+
border : '2px darkblue solid"'
|
|
8216
|
+
},
|
|
8217
|
+
S2 : {
|
|
8218
|
+
background : 'darkblue',
|
|
8219
|
+
color : 'white'
|
|
8220
|
+
border : '2px green solid"'
|
|
8221
|
+
}
|
|
8222
|
+
}
|
|
8223
|
+
const {use, border, background, color} = useRoot(Style.S1)
|
|
8224
|
+
|
|
8225
|
+
tags.p("Test useRoot ").style({
|
|
8226
|
+
border,
|
|
8227
|
+
color,
|
|
8228
|
+
background,
|
|
8229
|
+
padding : '10px'
|
|
8230
|
+
})
|
|
8231
|
+
|
|
8232
|
+
*/
|
|
8233
|
+
|
|
8122
8234
|
// To do : remove old items
|
|
8123
8235
|
class ZikoUseStorage{
|
|
8124
8236
|
constructor(storage, globalKey, initialValue){
|
|
@@ -8188,49 +8300,6 @@ class ZikoUseStorage{
|
|
|
8188
8300
|
const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
|
|
8189
8301
|
const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
|
|
8190
8302
|
|
|
8191
|
-
class ZikoUseThreed {
|
|
8192
|
-
#workerContent;
|
|
8193
|
-
constructor() {
|
|
8194
|
-
this.#workerContent = (
|
|
8195
|
-
function (msg) {
|
|
8196
|
-
try {
|
|
8197
|
-
const func = new Function("return " + msg.data.fun)();
|
|
8198
|
-
let result = func();
|
|
8199
|
-
postMessage({ result });
|
|
8200
|
-
} catch (error) {
|
|
8201
|
-
postMessage({ error: error.message });
|
|
8202
|
-
} finally {
|
|
8203
|
-
if (msg.data.close) self.close();
|
|
8204
|
-
}
|
|
8205
|
-
}
|
|
8206
|
-
).toString();
|
|
8207
|
-
this.blob = new Blob(["this.onmessage = " + this.#workerContent], { type: "text/javascript" });
|
|
8208
|
-
this.worker = new Worker(window.URL.createObjectURL(this.blob));
|
|
8209
|
-
}
|
|
8210
|
-
call(func, callback, close = true) {
|
|
8211
|
-
this.worker.postMessage({
|
|
8212
|
-
fun: func.toString(),
|
|
8213
|
-
close
|
|
8214
|
-
});
|
|
8215
|
-
this.worker.onmessage = function (e) {
|
|
8216
|
-
if (e.data.error) {
|
|
8217
|
-
console.error(e.data.error);
|
|
8218
|
-
} else {
|
|
8219
|
-
callback(e.data.result);
|
|
8220
|
-
}
|
|
8221
|
-
};
|
|
8222
|
-
return this;
|
|
8223
|
-
}
|
|
8224
|
-
}
|
|
8225
|
-
|
|
8226
|
-
const useThread = (func, callback , close) => {
|
|
8227
|
-
const T = new ZikoUseThreed();
|
|
8228
|
-
if (func) {
|
|
8229
|
-
T.call(func, callback , close);
|
|
8230
|
-
}
|
|
8231
|
-
return T;
|
|
8232
|
-
};
|
|
8233
|
-
|
|
8234
8303
|
[
|
|
8235
8304
|
App,
|
|
8236
8305
|
Math$1,
|
|
@@ -8578,8 +8647,8 @@ exports.useLocaleStorage = useLocaleStorage;
|
|
|
8578
8647
|
exports.useMediaQuery = useMediaQuery;
|
|
8579
8648
|
exports.useMeta = useMeta$1;
|
|
8580
8649
|
exports.useRoot = useRoot;
|
|
8581
|
-
exports.useRootValue = useRootValue;
|
|
8582
8650
|
exports.useSessionStorage = useSessionStorage;
|
|
8651
|
+
exports.useState = useState;
|
|
8583
8652
|
exports.useStyle = useStyle;
|
|
8584
8653
|
exports.useSuccesifKeys = useSuccesifKeys;
|
|
8585
8654
|
exports.useSwipeEvent = useSwipeEvent;
|
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 : Fri Aug 15 2025 09:48: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
|
|
@@ -1294,17 +1294,25 @@
|
|
|
1294
1294
|
}
|
|
1295
1295
|
for (let i = 0; i < ele.length; i++) {
|
|
1296
1296
|
if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
|
|
1297
|
-
if (
|
|
1298
|
-
typeof globalThis?.Node === "function" &&
|
|
1299
|
-
ele[i] instanceof globalThis?.Node
|
|
1300
|
-
)
|
|
1301
|
-
ele[i] = new this.constructor(ele[i]);
|
|
1297
|
+
if (typeof globalThis?.Node === "function" && ele[i] instanceof globalThis?.Node) ele[i] = new this.constructor(ele[i]);
|
|
1302
1298
|
if (ele[i]?.isZikoUIElement) {
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
}
|
|
1299
|
+
ele[i].cache.parent = this;
|
|
1300
|
+
this.element[adder](ele[i].element);
|
|
1301
|
+
ele[i].target = this.element;
|
|
1302
|
+
this.items[pusher](ele[i]);
|
|
1303
|
+
}
|
|
1304
|
+
// Fix Items Latter
|
|
1305
|
+
if( ele[i] instanceof Function){
|
|
1306
|
+
const getter = ele[i]();
|
|
1307
|
+
if (getter.isStateGetter) {
|
|
1308
|
+
const textNode = document?.createTextNode(getter.value);
|
|
1309
|
+
this.element.appendChild(textNode);
|
|
1310
|
+
getter._subscribe(
|
|
1311
|
+
(newValue) => (textNode.textContent = newValue),
|
|
1312
|
+
);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
else if (ele[i] instanceof Object) {
|
|
1308
1316
|
if (ele[i]?.style) this.style(ele[i]?.style);
|
|
1309
1317
|
if (ele[i]?.attr) {
|
|
1310
1318
|
Object.entries(ele[i].attr).forEach((n) =>
|
|
@@ -3295,52 +3303,16 @@
|
|
|
3295
3303
|
|
|
3296
3304
|
const useMediaQuery = (mediaQueryRules,fallback) => new ZikoUseMediaQuery(mediaQueryRules,fallback);
|
|
3297
3305
|
|
|
3298
|
-
class ZikoUseRoot{
|
|
3299
|
-
constructor(props){
|
|
3300
|
-
this.props={};
|
|
3301
|
-
props && this.set(props);
|
|
3302
|
-
}
|
|
3303
|
-
get(prop){
|
|
3304
|
-
return this.props[prop]
|
|
3305
|
-
}
|
|
3306
|
-
// getStaticValue(){
|
|
3307
|
-
// return document.documentElement.style.getPropertyValue("--primary-col")
|
|
3308
|
-
// }
|
|
3309
|
-
set(props){
|
|
3310
|
-
Object.entries(props).forEach(([key,value])=>this.#setOneProp(key, value));
|
|
3311
|
-
return this;
|
|
3312
|
-
}
|
|
3313
|
-
#setOneProp(prop, value){
|
|
3314
|
-
const CssProp = `--${Str.camel2hyphencase(prop)}`;
|
|
3315
|
-
document.documentElement.style.setProperty(CssProp,value);
|
|
3316
|
-
Object.assign(this.props, {[prop]: `var(${CssProp})`});
|
|
3317
|
-
Object.assign(this, {[prop] : `var(${CssProp})`});
|
|
3318
|
-
}
|
|
3319
|
-
}
|
|
3320
|
-
|
|
3321
|
-
const useRootValue=CssVar=>{
|
|
3322
|
-
if(!CssVar.startsWith("--")) CssVar = `--${Str.camel2hyphencase(CssVar)}`;
|
|
3323
|
-
return `var(${CssVar})`
|
|
3324
|
-
};
|
|
3325
|
-
// const useRootStaticValue=CssVar=>{
|
|
3326
|
-
// if(!CssVar.startsWith("--")) CssVar = `--${Str.camel2hyphencase(CssVar)}`
|
|
3327
|
-
// return globalThis.document.documentElement.style.getPropertyValue(CssVar)
|
|
3328
|
-
// }
|
|
3329
|
-
const useRoot=(props)=>new ZikoUseRoot(props);
|
|
3330
|
-
|
|
3331
3306
|
// export * from "./window"
|
|
3332
3307
|
|
|
3333
3308
|
var Hooks = /*#__PURE__*/Object.freeze({
|
|
3334
3309
|
__proto__: null,
|
|
3335
3310
|
ZikoHead: ZikoHead$1,
|
|
3336
|
-
ZikoUseRoot: ZikoUseRoot,
|
|
3337
3311
|
ZikoUseStyle: ZikoUseStyle,
|
|
3338
3312
|
useFavIcon: useFavIcon$1,
|
|
3339
3313
|
useHead: useHead$1,
|
|
3340
3314
|
useMediaQuery: useMediaQuery,
|
|
3341
3315
|
useMeta: useMeta$1,
|
|
3342
|
-
useRoot: useRoot,
|
|
3343
|
-
useRootValue: useRootValue,
|
|
3344
3316
|
useStyle: useStyle,
|
|
3345
3317
|
useSuccesifKeys: useSuccesifKeys,
|
|
3346
3318
|
useTitle: useTitle$1
|
|
@@ -8072,6 +8044,29 @@
|
|
|
8072
8044
|
// ...Params
|
|
8073
8045
|
};
|
|
8074
8046
|
|
|
8047
|
+
function useState(initialValue) {
|
|
8048
|
+
let value = initialValue;
|
|
8049
|
+
const subscribers = new Set();
|
|
8050
|
+
|
|
8051
|
+
function getValue() {
|
|
8052
|
+
return {
|
|
8053
|
+
value,
|
|
8054
|
+
isStateGetter: () => true,
|
|
8055
|
+
_subscribe: (fn) => subscribers.add(fn),
|
|
8056
|
+
};
|
|
8057
|
+
}
|
|
8058
|
+
|
|
8059
|
+
function setValue(newValue) {
|
|
8060
|
+
if (typeof newValue === "function") newValue = newValue(value);
|
|
8061
|
+
if (newValue !== value) {
|
|
8062
|
+
value = newValue;
|
|
8063
|
+
subscribers.forEach(fn => fn(value));
|
|
8064
|
+
}
|
|
8065
|
+
}
|
|
8066
|
+
|
|
8067
|
+
return [getValue, setValue];
|
|
8068
|
+
}
|
|
8069
|
+
|
|
8075
8070
|
class ZikoUseChannel{
|
|
8076
8071
|
constructor(name = ""){
|
|
8077
8072
|
this.channel = new BroadcastChannel(name);
|
|
@@ -8121,6 +8116,123 @@
|
|
|
8121
8116
|
}
|
|
8122
8117
|
const useChannel = name => new ZikoUseChannel(name);
|
|
8123
8118
|
|
|
8119
|
+
class ZikoUseThreed {
|
|
8120
|
+
#workerContent;
|
|
8121
|
+
constructor() {
|
|
8122
|
+
this.#workerContent = (
|
|
8123
|
+
function (msg) {
|
|
8124
|
+
try {
|
|
8125
|
+
const func = new Function("return " + msg.data.fun)();
|
|
8126
|
+
let result = func();
|
|
8127
|
+
postMessage({ result });
|
|
8128
|
+
} catch (error) {
|
|
8129
|
+
postMessage({ error: error.message });
|
|
8130
|
+
} finally {
|
|
8131
|
+
if (msg.data.close) self.close();
|
|
8132
|
+
}
|
|
8133
|
+
}
|
|
8134
|
+
).toString();
|
|
8135
|
+
this.blob = new Blob(["this.onmessage = " + this.#workerContent], { type: "text/javascript" });
|
|
8136
|
+
this.worker = new Worker(window.URL.createObjectURL(this.blob));
|
|
8137
|
+
}
|
|
8138
|
+
call(func, callback, close = true) {
|
|
8139
|
+
this.worker.postMessage({
|
|
8140
|
+
fun: func.toString(),
|
|
8141
|
+
close
|
|
8142
|
+
});
|
|
8143
|
+
this.worker.onmessage = function (e) {
|
|
8144
|
+
if (e.data.error) {
|
|
8145
|
+
console.error(e.data.error);
|
|
8146
|
+
} else {
|
|
8147
|
+
callback(e.data.result);
|
|
8148
|
+
}
|
|
8149
|
+
};
|
|
8150
|
+
return this;
|
|
8151
|
+
}
|
|
8152
|
+
}
|
|
8153
|
+
|
|
8154
|
+
const useThread = (func, callback , close) => {
|
|
8155
|
+
const T = new ZikoUseThreed();
|
|
8156
|
+
if (func) {
|
|
8157
|
+
T.call(func, callback , close);
|
|
8158
|
+
}
|
|
8159
|
+
return T;
|
|
8160
|
+
};
|
|
8161
|
+
|
|
8162
|
+
class ZikoUseRoot {
|
|
8163
|
+
constructor(PropsMap, {namespace = 'Ziko', register, ValidateCssProps = false} = {}){
|
|
8164
|
+
this.currentPropsMap = PropsMap;
|
|
8165
|
+
this.namespace = namespace;
|
|
8166
|
+
this.ValidateCssProps = ValidateCssProps;
|
|
8167
|
+
// this.pairs = {};
|
|
8168
|
+
// this.#maintain()
|
|
8169
|
+
this.use(PropsMap);
|
|
8170
|
+
}
|
|
8171
|
+
use(PropsMap){
|
|
8172
|
+
if(this.ValidateCssProps) ValidateCssProps(PropsMap);
|
|
8173
|
+
this.currentPropsMap = PropsMap;
|
|
8174
|
+
this.#maintain();
|
|
8175
|
+
return this;
|
|
8176
|
+
}
|
|
8177
|
+
#maintain(){
|
|
8178
|
+
const root = globalThis?.document?.documentElement?.style;
|
|
8179
|
+
for(let prop in this.currentPropsMap){
|
|
8180
|
+
const cssProp = this.namespace ? `--${this.namespace}-${prop}` : `--${prop}`;
|
|
8181
|
+
root.setProperty(
|
|
8182
|
+
cssProp,
|
|
8183
|
+
this.currentPropsMap[prop]
|
|
8184
|
+
);
|
|
8185
|
+
console.log({cssProp});
|
|
8186
|
+
// Object.assign(this.pairs, {
|
|
8187
|
+
// [prop] : `var(--${this.namespace}-${prop})`
|
|
8188
|
+
// })
|
|
8189
|
+
Object.defineProperty(this, prop, {
|
|
8190
|
+
value: `var(${cssProp})`,
|
|
8191
|
+
writable: true,
|
|
8192
|
+
configurable: true,
|
|
8193
|
+
enumerable: false
|
|
8194
|
+
});
|
|
8195
|
+
}
|
|
8196
|
+
}
|
|
8197
|
+
}
|
|
8198
|
+
|
|
8199
|
+
function ValidateCssProps(PropsMap){
|
|
8200
|
+
const validProps = new Set(Object.keys(document.documentElement.style));
|
|
8201
|
+
for (let key in PropsMap) {
|
|
8202
|
+
if (!validProps.has(key)) {
|
|
8203
|
+
throw new Error(`Invalid CSS property: "${key}"`);
|
|
8204
|
+
}
|
|
8205
|
+
}
|
|
8206
|
+
}
|
|
8207
|
+
|
|
8208
|
+
const useRoot = (PropsMap, {namespace, register, ValidateCssProps} = {}) => new ZikoUseRoot(PropsMap, {namespace, register, ValidateCssProps});
|
|
8209
|
+
|
|
8210
|
+
// Usage
|
|
8211
|
+
|
|
8212
|
+
/*
|
|
8213
|
+
const Styles = {
|
|
8214
|
+
S1 : {
|
|
8215
|
+
background : 'white',
|
|
8216
|
+
color : 'darkblue'
|
|
8217
|
+
border : '2px darkblue solid"'
|
|
8218
|
+
},
|
|
8219
|
+
S2 : {
|
|
8220
|
+
background : 'darkblue',
|
|
8221
|
+
color : 'white'
|
|
8222
|
+
border : '2px green solid"'
|
|
8223
|
+
}
|
|
8224
|
+
}
|
|
8225
|
+
const {use, border, background, color} = useRoot(Style.S1)
|
|
8226
|
+
|
|
8227
|
+
tags.p("Test useRoot ").style({
|
|
8228
|
+
border,
|
|
8229
|
+
color,
|
|
8230
|
+
background,
|
|
8231
|
+
padding : '10px'
|
|
8232
|
+
})
|
|
8233
|
+
|
|
8234
|
+
*/
|
|
8235
|
+
|
|
8124
8236
|
// To do : remove old items
|
|
8125
8237
|
class ZikoUseStorage{
|
|
8126
8238
|
constructor(storage, globalKey, initialValue){
|
|
@@ -8190,49 +8302,6 @@
|
|
|
8190
8302
|
const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
|
|
8191
8303
|
const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
|
|
8192
8304
|
|
|
8193
|
-
class ZikoUseThreed {
|
|
8194
|
-
#workerContent;
|
|
8195
|
-
constructor() {
|
|
8196
|
-
this.#workerContent = (
|
|
8197
|
-
function (msg) {
|
|
8198
|
-
try {
|
|
8199
|
-
const func = new Function("return " + msg.data.fun)();
|
|
8200
|
-
let result = func();
|
|
8201
|
-
postMessage({ result });
|
|
8202
|
-
} catch (error) {
|
|
8203
|
-
postMessage({ error: error.message });
|
|
8204
|
-
} finally {
|
|
8205
|
-
if (msg.data.close) self.close();
|
|
8206
|
-
}
|
|
8207
|
-
}
|
|
8208
|
-
).toString();
|
|
8209
|
-
this.blob = new Blob(["this.onmessage = " + this.#workerContent], { type: "text/javascript" });
|
|
8210
|
-
this.worker = new Worker(window.URL.createObjectURL(this.blob));
|
|
8211
|
-
}
|
|
8212
|
-
call(func, callback, close = true) {
|
|
8213
|
-
this.worker.postMessage({
|
|
8214
|
-
fun: func.toString(),
|
|
8215
|
-
close
|
|
8216
|
-
});
|
|
8217
|
-
this.worker.onmessage = function (e) {
|
|
8218
|
-
if (e.data.error) {
|
|
8219
|
-
console.error(e.data.error);
|
|
8220
|
-
} else {
|
|
8221
|
-
callback(e.data.result);
|
|
8222
|
-
}
|
|
8223
|
-
};
|
|
8224
|
-
return this;
|
|
8225
|
-
}
|
|
8226
|
-
}
|
|
8227
|
-
|
|
8228
|
-
const useThread = (func, callback , close) => {
|
|
8229
|
-
const T = new ZikoUseThreed();
|
|
8230
|
-
if (func) {
|
|
8231
|
-
T.call(func, callback , close);
|
|
8232
|
-
}
|
|
8233
|
-
return T;
|
|
8234
|
-
};
|
|
8235
|
-
|
|
8236
8305
|
[
|
|
8237
8306
|
App,
|
|
8238
8307
|
Math$1,
|
|
@@ -8580,8 +8649,8 @@
|
|
|
8580
8649
|
exports.useMediaQuery = useMediaQuery;
|
|
8581
8650
|
exports.useMeta = useMeta$1;
|
|
8582
8651
|
exports.useRoot = useRoot;
|
|
8583
|
-
exports.useRootValue = useRootValue;
|
|
8584
8652
|
exports.useSessionStorage = useSessionStorage;
|
|
8653
|
+
exports.useState = useState;
|
|
8585
8654
|
exports.useStyle = useStyle;
|
|
8586
8655
|
exports.useSuccesifKeys = useSuccesifKeys;
|
|
8587
8656
|
exports.useSwipeEvent = useSwipeEvent;
|