ziko 1.6.0 → 1.7.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 +125 -56
- package/dist/ziko.js +125 -56
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +122 -56
- package/package.json +1 -1
- package/src/data/converter/csv.js +6 -4
- package/src/data/parser/index.d.ts +41 -0
- package/src/data/parser/index.js +28 -1
- package/src/data/string/checkers/index.d.ts +62 -0
- package/src/data/string/converters/index.d.ts +159 -0
- package/src/data/string/index.d.ts +2 -0
- package/src/data/string/index.js +2 -2
- package/src/dom/components/index.d.ts +2 -0
- package/src/dom/components/swap/index.js +7 -2
- package/src/dom/constructors/UIElement.js +2 -2
- package/src/dom/constructors/UIElementCore.js +20 -2
- package/src/dom/constructors/mixins/dom.js +3 -2
- package/src/dom/tags/index.js +12 -35
- package/src/dom/utils/call_with_optional_props.js +14 -0
- package/src/dom/utils/checkers.js +1 -0
- package/src/dom/utils/index.js +8 -13
- package/src/dom/utils/is_ui_item.js +10 -0
- package/src/dom/utils/parse_props.js +26 -0
- package/src/hooks/use-state.js +6 -5
- package/src/time/animation/index.d.ts +189 -0
- package/src/time/index.d.ts +2 -1
- package/src/data/parser/xml.js +0 -47
- /package/src/data/string/{checkers.js → checkers/index.js} +0 -0
- /package/src/data/string/{converters.js → converters/index.js} +0 -0
package/dist/ziko.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date : Fri
|
|
5
|
+
Date : Fri Aug 07 2026 20:07:58 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
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
const { PI: PI$1, E } = Math;
|
|
18
18
|
const EPSILON=Number.EPSILON;
|
|
19
19
|
|
|
20
|
-
const is_primitive = value => typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
20
|
+
const is_primitive$1 = value => typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
21
21
|
|
|
22
22
|
const mapfun$1=(fun,...X)=>{
|
|
23
23
|
const Y=X.map(x=>{
|
|
24
|
-
if(is_primitive(x) || x?.__mapfun__) return fun(x)
|
|
24
|
+
if(is_primitive$1(x) || x?.__mapfun__) return fun(x)
|
|
25
25
|
if(x instanceof Array) return x.map(n=>mapfun$1(fun,n));
|
|
26
26
|
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
27
27
|
if(x instanceof Set) return new Set(mapfun$1(fun,...[...x]));
|
|
@@ -2233,12 +2233,39 @@
|
|
|
2233
2233
|
}
|
|
2234
2234
|
}
|
|
2235
2235
|
|
|
2236
|
+
const parse_props = (props = {}) => {
|
|
2237
|
+
|
|
2238
|
+
const result = {
|
|
2239
|
+
methods: {},
|
|
2240
|
+
events: {},
|
|
2241
|
+
style: {},
|
|
2242
|
+
attrs: {}
|
|
2243
|
+
};
|
|
2244
|
+
|
|
2245
|
+
for (const [key, value] of Object.entries(props)) {
|
|
2246
|
+
if (key === "style") {
|
|
2247
|
+
result.style = value;
|
|
2248
|
+
}
|
|
2249
|
+
else if (key.startsWith("$")) {
|
|
2250
|
+
result.methods[key.slice(1)] = value;
|
|
2251
|
+
}
|
|
2252
|
+
else if (/^on[A-Z]/.test(key)) {
|
|
2253
|
+
result.events[key] = value;
|
|
2254
|
+
}
|
|
2255
|
+
else {
|
|
2256
|
+
result.attrs[key] = value;
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
return result;
|
|
2261
|
+
};
|
|
2262
|
+
|
|
2236
2263
|
__init__global__();
|
|
2237
2264
|
class UIElementCore extends UINode{
|
|
2238
2265
|
constructor(){
|
|
2239
2266
|
super();
|
|
2240
2267
|
}
|
|
2241
|
-
init(element, name, type, render){
|
|
2268
|
+
init({element, name, type, render, props = {}, items = []} = {}){
|
|
2242
2269
|
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
2243
2270
|
if(typeof element === "string") {
|
|
2244
2271
|
switch(type){
|
|
@@ -2286,9 +2313,26 @@
|
|
|
2286
2313
|
};
|
|
2287
2314
|
if(element) Object.assign(this.cache,{element});
|
|
2288
2315
|
this.items = new UIStore();
|
|
2289
|
-
globalThis.__Ziko__.__UI__[this.cache.name]
|
|
2316
|
+
globalThis.__Ziko__.__UI__[this.cache.name]
|
|
2317
|
+
? globalThis.__Ziko__.__UI__[this.cache.name]?.push(this)
|
|
2318
|
+
: globalThis.__Ziko__.__UI__[this.cache.name]=[this];
|
|
2290
2319
|
element && render && this?.render?.();
|
|
2291
2320
|
globalThis.__Ziko__.__UI__.push(this);
|
|
2321
|
+
|
|
2322
|
+
// console.log({props})
|
|
2323
|
+
const parsed_props = parse_props(props);
|
|
2324
|
+
|
|
2325
|
+
this.parsed_props = parsed_props;
|
|
2326
|
+
|
|
2327
|
+
this.style(parsed_props.style);
|
|
2328
|
+
this.setAttr(parsed_props.attrs);
|
|
2329
|
+
|
|
2330
|
+
const Events = Object.entries(parsed_props.events);
|
|
2331
|
+
|
|
2332
|
+
Events.forEach(([ev, callback]) => this[ev](callback.bind(this)));
|
|
2333
|
+
|
|
2334
|
+
|
|
2335
|
+
if(items.length > 0) this.append(...items);
|
|
2292
2336
|
}
|
|
2293
2337
|
get element(){
|
|
2294
2338
|
return this.cache.element;
|
|
@@ -2396,8 +2440,9 @@
|
|
|
2396
2440
|
|
|
2397
2441
|
// if (!globalThis.__Ziko__) __init__global__();
|
|
2398
2442
|
|
|
2443
|
+
const STATE_GETTER = Symbol.for("ziko.stateGetter");
|
|
2444
|
+
|
|
2399
2445
|
function useState(initialValue) {
|
|
2400
|
-
|
|
2401
2446
|
const state = {
|
|
2402
2447
|
value: initialValue,
|
|
2403
2448
|
subscribers: new Set(),
|
|
@@ -2407,7 +2452,6 @@
|
|
|
2407
2452
|
function getValue() {
|
|
2408
2453
|
return {
|
|
2409
2454
|
value: state.value,
|
|
2410
|
-
isStateGetter: () => true,
|
|
2411
2455
|
_subscribe: (fn) => {
|
|
2412
2456
|
state.subscribers.add(fn);
|
|
2413
2457
|
return () => state.subscribers.delete(fn);
|
|
@@ -2415,6 +2459,8 @@
|
|
|
2415
2459
|
};
|
|
2416
2460
|
}
|
|
2417
2461
|
|
|
2462
|
+
getValue[STATE_GETTER] = true;
|
|
2463
|
+
|
|
2418
2464
|
function setValue(newValue) {
|
|
2419
2465
|
if (state.paused) return;
|
|
2420
2466
|
|
|
@@ -2436,6 +2482,7 @@
|
|
|
2436
2482
|
if (typeof newValue === "function") {
|
|
2437
2483
|
newValue = newValue(state.value);
|
|
2438
2484
|
}
|
|
2485
|
+
|
|
2439
2486
|
state.value = newValue;
|
|
2440
2487
|
state.subscribers.forEach((fn) => fn(state.value));
|
|
2441
2488
|
},
|
|
@@ -2445,9 +2492,7 @@
|
|
|
2445
2492
|
return [getValue, setValue, controller];
|
|
2446
2493
|
}
|
|
2447
2494
|
|
|
2448
|
-
const isStateGetter = (arg) =>
|
|
2449
|
-
return typeof arg === "function" && arg?.()?.isStateGetter?.() === true;
|
|
2450
|
-
};
|
|
2495
|
+
const isStateGetter = (arg) => typeof arg === "function" && arg[STATE_GETTER] === true;
|
|
2451
2496
|
|
|
2452
2497
|
const camel2hyphencase = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
|
|
2453
2498
|
|
|
@@ -2598,8 +2643,8 @@
|
|
|
2598
2643
|
if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
|
|
2599
2644
|
// Fix Items Latter
|
|
2600
2645
|
if (ele[i] instanceof Function) {
|
|
2601
|
-
|
|
2602
|
-
|
|
2646
|
+
if (isStateGetter(ele[i])) {
|
|
2647
|
+
const getter = ele[i]();
|
|
2603
2648
|
ele[i] = text(getter.value);
|
|
2604
2649
|
getter._subscribe(
|
|
2605
2650
|
(newValue) => (ele[i].element.textContent = newValue),
|
|
@@ -3089,7 +3134,7 @@
|
|
|
3089
3134
|
}
|
|
3090
3135
|
|
|
3091
3136
|
let UIElement$1 = class UIElement extends UIElementCore{
|
|
3092
|
-
constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
|
|
3137
|
+
constructor({element, name ='', type = 'html', render = __Ziko__.__Config__.default.render, props}={}){
|
|
3093
3138
|
super();
|
|
3094
3139
|
this.exp = {
|
|
3095
3140
|
events : {
|
|
@@ -3109,7 +3154,7 @@
|
|
|
3109
3154
|
ViewListeners,
|
|
3110
3155
|
);
|
|
3111
3156
|
|
|
3112
|
-
if(element)this.init(element, name, type, render);
|
|
3157
|
+
if(element) this.init({element, name, type, render, props});
|
|
3113
3158
|
}
|
|
3114
3159
|
on(event_name, callback, {details_setter, category = 'global', isCustom = false, preventDefault = false} = {}){
|
|
3115
3160
|
if(event_name instanceof Array) event_name.forEach(
|
|
@@ -3202,15 +3247,22 @@
|
|
|
3202
3247
|
|
|
3203
3248
|
};
|
|
3204
3249
|
|
|
3250
|
+
const is_primitive = (value) => typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
3251
|
+
|
|
3205
3252
|
const call_with_optional_props = (Component) => {
|
|
3206
3253
|
return (...args) => {
|
|
3207
3254
|
const first = args[0];
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3255
|
+
|
|
3256
|
+
const isChild = first?.isUIElement?.() || is_primitive(first);
|
|
3257
|
+
|
|
3258
|
+
if (isChild) {
|
|
3259
|
+
return new Component({}, ...args);
|
|
3260
|
+
}
|
|
3261
|
+
|
|
3262
|
+
return new Component(first, ...args.slice(1));
|
|
3212
3263
|
};
|
|
3213
|
-
};
|
|
3264
|
+
};
|
|
3265
|
+
|
|
3214
3266
|
function add_vendor_prefix(property) {
|
|
3215
3267
|
const propertyUC = property.slice(0, 1).toUpperCase() + property.slice(1);
|
|
3216
3268
|
const vendors = ['Webkit', 'Moz', 'O', 'ms'];
|
|
@@ -3263,9 +3315,9 @@
|
|
|
3263
3315
|
const cloneUI=UIElement=>{
|
|
3264
3316
|
return Object.assign(Object.create(Object.getPrototypeOf(UIElement)),UIElement)
|
|
3265
3317
|
};
|
|
3266
|
-
function isPrimitive(value) {
|
|
3267
|
-
|
|
3268
|
-
}
|
|
3318
|
+
// function isPrimitive(value) {
|
|
3319
|
+
// return typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
3320
|
+
// }
|
|
3269
3321
|
const waitElm=(UIElement)=>{
|
|
3270
3322
|
return new Promise(resolve => {
|
|
3271
3323
|
if (UIElement) {
|
|
@@ -3437,40 +3489,18 @@
|
|
|
3437
3489
|
if(HTMLTags.includes(tag)) type = 'html';
|
|
3438
3490
|
if(SVGTags.includes(tag)) type = 'svg';
|
|
3439
3491
|
if(MathMLTags.includes(tag)) type = 'mathml';
|
|
3440
|
-
return (...args)=>{
|
|
3441
|
-
// Fix undefined
|
|
3442
|
-
// console.log(isStateGetter(args[0]))
|
|
3443
|
-
// console.log(!!args)
|
|
3492
|
+
return (...args) => {
|
|
3444
3493
|
if(args.length === 0) {
|
|
3445
|
-
// console.log('length 0')
|
|
3446
3494
|
return new UIElement$1({element : tag, name : tag, type})
|
|
3447
3495
|
}
|
|
3448
3496
|
if(
|
|
3449
3497
|
['string', 'number'].includes(typeof args[0])
|
|
3450
3498
|
|| args[0] instanceof UIElement$1
|
|
3451
|
-
|| (
|
|
3499
|
+
|| isStateGetter(args[0])
|
|
3500
|
+
|| args[0] instanceof HTMLElement
|
|
3452
3501
|
) return new UIElement$1({element : tag, name : tag, type}).append(...args);
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
}
|
|
3456
|
-
// if(SVGTags.includes(tag)) return (...args) => new UIElement(tag,"",{el_type : "svg"}).append(...args);
|
|
3457
|
-
// return (...args)=>{
|
|
3458
|
-
// if(!(args[0] instanceof UIElement) && args[0] instanceof Object){
|
|
3459
|
-
// let attributes = args.shift()
|
|
3460
|
-
// return new UIElement(tag).setAttr(attributes).append(...args)
|
|
3461
|
-
// }
|
|
3462
|
-
// return new UIElement(tag).append(...args);
|
|
3463
|
-
// }
|
|
3464
|
-
// // switch(tag){
|
|
3465
|
-
// case "html" : globalThis?.document?.createElement("html")
|
|
3466
|
-
// case "head" :
|
|
3467
|
-
// case "style" :
|
|
3468
|
-
// case "link" :
|
|
3469
|
-
// case "meta" :
|
|
3470
|
-
// case "srcipt":
|
|
3471
|
-
// case "body" : return null; break;
|
|
3472
|
-
// default : return new UIElement(tag);
|
|
3473
|
-
// }
|
|
3502
|
+
return new UIElement$1({element : tag, type, props : args.shift()}).append(...args)
|
|
3503
|
+
}
|
|
3474
3504
|
}
|
|
3475
3505
|
});
|
|
3476
3506
|
|
|
@@ -3754,7 +3784,9 @@
|
|
|
3754
3784
|
};
|
|
3755
3785
|
|
|
3756
3786
|
this.append(...items);
|
|
3757
|
-
|
|
3787
|
+
requestAnimationFrame(() => {
|
|
3788
|
+
this.render();
|
|
3789
|
+
});
|
|
3758
3790
|
}
|
|
3759
3791
|
get activeItem(){
|
|
3760
3792
|
return this.items[this.states.activeIndex]
|
|
@@ -3762,7 +3794,7 @@
|
|
|
3762
3794
|
render() {
|
|
3763
3795
|
this.items.forEach((n, i) => {
|
|
3764
3796
|
|
|
3765
|
-
const initialDisplay = n.element
|
|
3797
|
+
const initialDisplay = getComputedStyle(n.element).display;
|
|
3766
3798
|
this.#DISPLAYS_MAP.set(n, initialDisplay);
|
|
3767
3799
|
|
|
3768
3800
|
if (i !== this.states.activeIndex) {
|
|
@@ -3770,6 +3802,9 @@
|
|
|
3770
3802
|
}
|
|
3771
3803
|
});
|
|
3772
3804
|
}
|
|
3805
|
+
get DS(){
|
|
3806
|
+
return this.#DISPLAYS_MAP
|
|
3807
|
+
}
|
|
3773
3808
|
next(n = 1) {
|
|
3774
3809
|
return this.activate(this.states.activeIndex + n);
|
|
3775
3810
|
}
|
|
@@ -4397,13 +4432,15 @@
|
|
|
4397
4432
|
};
|
|
4398
4433
|
const csv2json = (csv, delimiter = ",") => JSON.stringify(csv2object(csv,delimiter));
|
|
4399
4434
|
const csv2sql=(csv, Table)=>{
|
|
4435
|
+
const sanitizeId = s => s.trim().replace(/[^a-zA-Z0-9_]/g, '');
|
|
4436
|
+
const escapeVal = s => "'" + s.trim().replace(/'/g, "''") + "'";
|
|
4400
4437
|
const lines = csv.trim().trimEnd().split('\n').filter(n=>n);
|
|
4401
|
-
const columns = lines[0].split(',');
|
|
4402
|
-
let sqlQuery =
|
|
4438
|
+
const columns = lines[0].split(',').map(sanitizeId);
|
|
4439
|
+
let sqlQuery = "INSERT INTO " + sanitizeId(Table) + " (" + columns.join(', ') + ") Values ";
|
|
4403
4440
|
let sqlValues = [];
|
|
4404
4441
|
for (let i = 1; i < lines.length; i++) {
|
|
4405
|
-
const values = lines[i].split(',');
|
|
4406
|
-
sqlValues.push(
|
|
4442
|
+
const values = lines[i].split(',').map(escapeVal);
|
|
4443
|
+
sqlValues.push("(" + values.join(', ') + ")");
|
|
4407
4444
|
}
|
|
4408
4445
|
return sqlQuery+sqlValues.join(",\n");
|
|
4409
4446
|
};
|
|
@@ -4520,6 +4557,35 @@
|
|
|
4520
4557
|
}, Array.isArray(obj) ? [] : {});
|
|
4521
4558
|
}
|
|
4522
4559
|
|
|
4560
|
+
function parseXML(xmlString) {
|
|
4561
|
+
const parser = new DOMParser();
|
|
4562
|
+
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
|
4563
|
+
const rootNode = xmlDoc.documentElement;
|
|
4564
|
+
const result = parseNode(rootNode);
|
|
4565
|
+
return result;
|
|
4566
|
+
}
|
|
4567
|
+
|
|
4568
|
+
function parseNode(node) {
|
|
4569
|
+
const obj = {
|
|
4570
|
+
type: node.nodeName,
|
|
4571
|
+
attributes: {},
|
|
4572
|
+
children: []
|
|
4573
|
+
};
|
|
4574
|
+
for (let i = 0; i < node.attributes.length; i++) {
|
|
4575
|
+
const attr = node.attributes[i];
|
|
4576
|
+
obj.attributes[attr.name] = attr.value;
|
|
4577
|
+
}
|
|
4578
|
+
for (let i = 0; i < node.childNodes.length; i++) {
|
|
4579
|
+
const child = node.childNodes[i];
|
|
4580
|
+
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
4581
|
+
obj.children.push(parseNode(child));
|
|
4582
|
+
} else if (child.nodeType === Node.TEXT_NODE) {
|
|
4583
|
+
obj.text = child.textContent.trim();
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4586
|
+
return obj;
|
|
4587
|
+
}
|
|
4588
|
+
|
|
4523
4589
|
// import { ZikoHead , useHead} from "../reactivity/hooks/head/index.js";
|
|
4524
4590
|
class ZikoApp {
|
|
4525
4591
|
constructor({head = null, wrapper = null, target = null}){
|
|
@@ -5253,6 +5319,7 @@
|
|
|
5253
5319
|
exports.PtrListeners = PtrListeners;
|
|
5254
5320
|
exports.Random = Random;
|
|
5255
5321
|
exports.SPA = SPA;
|
|
5322
|
+
exports.STATE_GETTER = STATE_GETTER;
|
|
5256
5323
|
exports.SVGWrapper = SVGWrapper;
|
|
5257
5324
|
exports.Scheduler = Scheduler;
|
|
5258
5325
|
exports.Suspense = Suspense;
|
|
@@ -5357,8 +5424,8 @@
|
|
|
5357
5424
|
exports.in_sin = in_sin;
|
|
5358
5425
|
exports.interquartile_mean = interquartile_mean;
|
|
5359
5426
|
exports.iqr = iqr;
|
|
5360
|
-
exports.isPrimitive = isPrimitive;
|
|
5361
5427
|
exports.isStateGetter = isStateGetter;
|
|
5428
|
+
exports.is_primitive = is_primitive;
|
|
5362
5429
|
exports.json2arr = json2arr;
|
|
5363
5430
|
exports.json2css = json2css;
|
|
5364
5431
|
exports.json2csv = json2csv;
|
|
@@ -5403,6 +5470,8 @@
|
|
|
5403
5470
|
exports.out_quart = out_quart;
|
|
5404
5471
|
exports.out_quint = out_quint;
|
|
5405
5472
|
exports.out_sin = out_sin;
|
|
5473
|
+
exports.parseXML = parseXML;
|
|
5474
|
+
exports.parse_props = parse_props;
|
|
5406
5475
|
exports.percentile = percentile;
|
|
5407
5476
|
exports.pow = pow$1;
|
|
5408
5477
|
exports.power_mean = power_mean;
|