ziko 1.6.1 → 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/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/dist/ziko.cjs
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
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
const { PI: PI$1, E } = Math;
|
|
14
14
|
const EPSILON=Number.EPSILON;
|
|
15
15
|
|
|
16
|
-
const is_primitive = value => typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
16
|
+
const is_primitive$1 = value => typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
17
17
|
|
|
18
18
|
const mapfun$1=(fun,...X)=>{
|
|
19
19
|
const Y=X.map(x=>{
|
|
20
|
-
if(is_primitive(x) || x?.__mapfun__) return fun(x)
|
|
20
|
+
if(is_primitive$1(x) || x?.__mapfun__) return fun(x)
|
|
21
21
|
if(x instanceof Array) return x.map(n=>mapfun$1(fun,n));
|
|
22
22
|
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
23
23
|
if(x instanceof Set) return new Set(mapfun$1(fun,...[...x]));
|
|
@@ -2229,12 +2229,39 @@ function __init__global__(){
|
|
|
2229
2229
|
}
|
|
2230
2230
|
}
|
|
2231
2231
|
|
|
2232
|
+
const parse_props = (props = {}) => {
|
|
2233
|
+
|
|
2234
|
+
const result = {
|
|
2235
|
+
methods: {},
|
|
2236
|
+
events: {},
|
|
2237
|
+
style: {},
|
|
2238
|
+
attrs: {}
|
|
2239
|
+
};
|
|
2240
|
+
|
|
2241
|
+
for (const [key, value] of Object.entries(props)) {
|
|
2242
|
+
if (key === "style") {
|
|
2243
|
+
result.style = value;
|
|
2244
|
+
}
|
|
2245
|
+
else if (key.startsWith("$")) {
|
|
2246
|
+
result.methods[key.slice(1)] = value;
|
|
2247
|
+
}
|
|
2248
|
+
else if (/^on[A-Z]/.test(key)) {
|
|
2249
|
+
result.events[key] = value;
|
|
2250
|
+
}
|
|
2251
|
+
else {
|
|
2252
|
+
result.attrs[key] = value;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
|
|
2256
|
+
return result;
|
|
2257
|
+
};
|
|
2258
|
+
|
|
2232
2259
|
__init__global__();
|
|
2233
2260
|
class UIElementCore extends UINode{
|
|
2234
2261
|
constructor(){
|
|
2235
2262
|
super();
|
|
2236
2263
|
}
|
|
2237
|
-
init(element, name, type, render){
|
|
2264
|
+
init({element, name, type, render, props = {}, items = []} = {}){
|
|
2238
2265
|
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
2239
2266
|
if(typeof element === "string") {
|
|
2240
2267
|
switch(type){
|
|
@@ -2282,9 +2309,26 @@ class UIElementCore extends UINode{
|
|
|
2282
2309
|
};
|
|
2283
2310
|
if(element) Object.assign(this.cache,{element});
|
|
2284
2311
|
this.items = new UIStore();
|
|
2285
|
-
globalThis.__Ziko__.__UI__[this.cache.name]
|
|
2312
|
+
globalThis.__Ziko__.__UI__[this.cache.name]
|
|
2313
|
+
? globalThis.__Ziko__.__UI__[this.cache.name]?.push(this)
|
|
2314
|
+
: globalThis.__Ziko__.__UI__[this.cache.name]=[this];
|
|
2286
2315
|
element && render && this?.render?.();
|
|
2287
2316
|
globalThis.__Ziko__.__UI__.push(this);
|
|
2317
|
+
|
|
2318
|
+
// console.log({props})
|
|
2319
|
+
const parsed_props = parse_props(props);
|
|
2320
|
+
|
|
2321
|
+
this.parsed_props = parsed_props;
|
|
2322
|
+
|
|
2323
|
+
this.style(parsed_props.style);
|
|
2324
|
+
this.setAttr(parsed_props.attrs);
|
|
2325
|
+
|
|
2326
|
+
const Events = Object.entries(parsed_props.events);
|
|
2327
|
+
|
|
2328
|
+
Events.forEach(([ev, callback]) => this[ev](callback.bind(this)));
|
|
2329
|
+
|
|
2330
|
+
|
|
2331
|
+
if(items.length > 0) this.append(...items);
|
|
2288
2332
|
}
|
|
2289
2333
|
get element(){
|
|
2290
2334
|
return this.cache.element;
|
|
@@ -2392,8 +2436,9 @@ var LifecycleMethods = /*#__PURE__*/Object.freeze({
|
|
|
2392
2436
|
|
|
2393
2437
|
// if (!globalThis.__Ziko__) __init__global__();
|
|
2394
2438
|
|
|
2439
|
+
const STATE_GETTER = Symbol.for("ziko.stateGetter");
|
|
2440
|
+
|
|
2395
2441
|
function useState(initialValue) {
|
|
2396
|
-
|
|
2397
2442
|
const state = {
|
|
2398
2443
|
value: initialValue,
|
|
2399
2444
|
subscribers: new Set(),
|
|
@@ -2403,7 +2448,6 @@ function useState(initialValue) {
|
|
|
2403
2448
|
function getValue() {
|
|
2404
2449
|
return {
|
|
2405
2450
|
value: state.value,
|
|
2406
|
-
isStateGetter: () => true,
|
|
2407
2451
|
_subscribe: (fn) => {
|
|
2408
2452
|
state.subscribers.add(fn);
|
|
2409
2453
|
return () => state.subscribers.delete(fn);
|
|
@@ -2411,6 +2455,8 @@ function useState(initialValue) {
|
|
|
2411
2455
|
};
|
|
2412
2456
|
}
|
|
2413
2457
|
|
|
2458
|
+
getValue[STATE_GETTER] = true;
|
|
2459
|
+
|
|
2414
2460
|
function setValue(newValue) {
|
|
2415
2461
|
if (state.paused) return;
|
|
2416
2462
|
|
|
@@ -2432,6 +2478,7 @@ function useState(initialValue) {
|
|
|
2432
2478
|
if (typeof newValue === "function") {
|
|
2433
2479
|
newValue = newValue(state.value);
|
|
2434
2480
|
}
|
|
2481
|
+
|
|
2435
2482
|
state.value = newValue;
|
|
2436
2483
|
state.subscribers.forEach((fn) => fn(state.value));
|
|
2437
2484
|
},
|
|
@@ -2441,9 +2488,7 @@ function useState(initialValue) {
|
|
|
2441
2488
|
return [getValue, setValue, controller];
|
|
2442
2489
|
}
|
|
2443
2490
|
|
|
2444
|
-
const isStateGetter = (arg) =>
|
|
2445
|
-
return typeof arg === "function" && arg?.()?.isStateGetter?.() === true;
|
|
2446
|
-
};
|
|
2491
|
+
const isStateGetter = (arg) => typeof arg === "function" && arg[STATE_GETTER] === true;
|
|
2447
2492
|
|
|
2448
2493
|
const camel2hyphencase = (text = '') => text.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
|
|
2449
2494
|
|
|
@@ -2594,8 +2639,8 @@ async function __addItem__(adder, pusher, ...ele) {
|
|
|
2594
2639
|
if (["number", "string"].includes(typeof ele[i])) ele[i] = text(ele[i]);
|
|
2595
2640
|
// Fix Items Latter
|
|
2596
2641
|
if (ele[i] instanceof Function) {
|
|
2597
|
-
|
|
2598
|
-
|
|
2642
|
+
if (isStateGetter(ele[i])) {
|
|
2643
|
+
const getter = ele[i]();
|
|
2599
2644
|
ele[i] = text(getter.value);
|
|
2600
2645
|
getter._subscribe(
|
|
2601
2646
|
(newValue) => (ele[i].element.textContent = newValue),
|
|
@@ -3085,7 +3130,7 @@ function register_swipe_event(
|
|
|
3085
3130
|
}
|
|
3086
3131
|
|
|
3087
3132
|
let UIElement$1 = class UIElement extends UIElementCore{
|
|
3088
|
-
constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
|
|
3133
|
+
constructor({element, name ='', type = 'html', render = __Ziko__.__Config__.default.render, props}={}){
|
|
3089
3134
|
super();
|
|
3090
3135
|
this.exp = {
|
|
3091
3136
|
events : {
|
|
@@ -3105,7 +3150,7 @@ let UIElement$1 = class UIElement extends UIElementCore{
|
|
|
3105
3150
|
ViewListeners,
|
|
3106
3151
|
);
|
|
3107
3152
|
|
|
3108
|
-
if(element)this.init(element, name, type, render);
|
|
3153
|
+
if(element) this.init({element, name, type, render, props});
|
|
3109
3154
|
}
|
|
3110
3155
|
on(event_name, callback, {details_setter, category = 'global', isCustom = false, preventDefault = false} = {}){
|
|
3111
3156
|
if(event_name instanceof Array) event_name.forEach(
|
|
@@ -3198,15 +3243,22 @@ let UIElement$1 = class UIElement extends UIElementCore{
|
|
|
3198
3243
|
|
|
3199
3244
|
};
|
|
3200
3245
|
|
|
3246
|
+
const is_primitive = (value) => typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
3247
|
+
|
|
3201
3248
|
const call_with_optional_props = (Component) => {
|
|
3202
3249
|
return (...args) => {
|
|
3203
3250
|
const first = args[0];
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3251
|
+
|
|
3252
|
+
const isChild = first?.isUIElement?.() || is_primitive(first);
|
|
3253
|
+
|
|
3254
|
+
if (isChild) {
|
|
3255
|
+
return new Component({}, ...args);
|
|
3256
|
+
}
|
|
3257
|
+
|
|
3258
|
+
return new Component(first, ...args.slice(1));
|
|
3208
3259
|
};
|
|
3209
|
-
};
|
|
3260
|
+
};
|
|
3261
|
+
|
|
3210
3262
|
function add_vendor_prefix(property) {
|
|
3211
3263
|
const propertyUC = property.slice(0, 1).toUpperCase() + property.slice(1);
|
|
3212
3264
|
const vendors = ['Webkit', 'Moz', 'O', 'ms'];
|
|
@@ -3259,9 +3311,9 @@ const CloneElement = (UIElement) => {
|
|
|
3259
3311
|
const cloneUI=UIElement=>{
|
|
3260
3312
|
return Object.assign(Object.create(Object.getPrototypeOf(UIElement)),UIElement)
|
|
3261
3313
|
};
|
|
3262
|
-
function isPrimitive(value) {
|
|
3263
|
-
|
|
3264
|
-
}
|
|
3314
|
+
// function isPrimitive(value) {
|
|
3315
|
+
// return typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
3316
|
+
// }
|
|
3265
3317
|
const waitElm=(UIElement)=>{
|
|
3266
3318
|
return new Promise(resolve => {
|
|
3267
3319
|
if (UIElement) {
|
|
@@ -3433,40 +3485,18 @@ const tags = new Proxy({}, {
|
|
|
3433
3485
|
if(HTMLTags.includes(tag)) type = 'html';
|
|
3434
3486
|
if(SVGTags.includes(tag)) type = 'svg';
|
|
3435
3487
|
if(MathMLTags.includes(tag)) type = 'mathml';
|
|
3436
|
-
return (...args)=>{
|
|
3437
|
-
// Fix undefined
|
|
3438
|
-
// console.log(isStateGetter(args[0]))
|
|
3439
|
-
// console.log(!!args)
|
|
3488
|
+
return (...args) => {
|
|
3440
3489
|
if(args.length === 0) {
|
|
3441
|
-
// console.log('length 0')
|
|
3442
3490
|
return new UIElement$1({element : tag, name : tag, type})
|
|
3443
3491
|
}
|
|
3444
3492
|
if(
|
|
3445
3493
|
['string', 'number'].includes(typeof args[0])
|
|
3446
3494
|
|| args[0] instanceof UIElement$1
|
|
3447
|
-
|| (
|
|
3495
|
+
|| isStateGetter(args[0])
|
|
3496
|
+
|| args[0] instanceof HTMLElement
|
|
3448
3497
|
) return new UIElement$1({element : tag, name : tag, type}).append(...args);
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
}
|
|
3452
|
-
// if(SVGTags.includes(tag)) return (...args) => new UIElement(tag,"",{el_type : "svg"}).append(...args);
|
|
3453
|
-
// return (...args)=>{
|
|
3454
|
-
// if(!(args[0] instanceof UIElement) && args[0] instanceof Object){
|
|
3455
|
-
// let attributes = args.shift()
|
|
3456
|
-
// return new UIElement(tag).setAttr(attributes).append(...args)
|
|
3457
|
-
// }
|
|
3458
|
-
// return new UIElement(tag).append(...args);
|
|
3459
|
-
// }
|
|
3460
|
-
// // switch(tag){
|
|
3461
|
-
// case "html" : globalThis?.document?.createElement("html")
|
|
3462
|
-
// case "head" :
|
|
3463
|
-
// case "style" :
|
|
3464
|
-
// case "link" :
|
|
3465
|
-
// case "meta" :
|
|
3466
|
-
// case "srcipt":
|
|
3467
|
-
// case "body" : return null; break;
|
|
3468
|
-
// default : return new UIElement(tag);
|
|
3469
|
-
// }
|
|
3498
|
+
return new UIElement$1({element : tag, type, props : args.shift()}).append(...args)
|
|
3499
|
+
}
|
|
3470
3500
|
}
|
|
3471
3501
|
});
|
|
3472
3502
|
|
|
@@ -3750,7 +3780,9 @@ class UISwap extends UIElement$1 {
|
|
|
3750
3780
|
};
|
|
3751
3781
|
|
|
3752
3782
|
this.append(...items);
|
|
3753
|
-
|
|
3783
|
+
requestAnimationFrame(() => {
|
|
3784
|
+
this.render();
|
|
3785
|
+
});
|
|
3754
3786
|
}
|
|
3755
3787
|
get activeItem(){
|
|
3756
3788
|
return this.items[this.states.activeIndex]
|
|
@@ -3758,7 +3790,7 @@ class UISwap extends UIElement$1 {
|
|
|
3758
3790
|
render() {
|
|
3759
3791
|
this.items.forEach((n, i) => {
|
|
3760
3792
|
|
|
3761
|
-
const initialDisplay = n.element
|
|
3793
|
+
const initialDisplay = getComputedStyle(n.element).display;
|
|
3762
3794
|
this.#DISPLAYS_MAP.set(n, initialDisplay);
|
|
3763
3795
|
|
|
3764
3796
|
if (i !== this.states.activeIndex) {
|
|
@@ -3766,6 +3798,9 @@ class UISwap extends UIElement$1 {
|
|
|
3766
3798
|
}
|
|
3767
3799
|
});
|
|
3768
3800
|
}
|
|
3801
|
+
get DS(){
|
|
3802
|
+
return this.#DISPLAYS_MAP
|
|
3803
|
+
}
|
|
3769
3804
|
next(n = 1) {
|
|
3770
3805
|
return this.activate(this.states.activeIndex + n);
|
|
3771
3806
|
}
|
|
@@ -4393,13 +4428,15 @@ const csv2object = (csv, delimiter = ",") => {
|
|
|
4393
4428
|
};
|
|
4394
4429
|
const csv2json = (csv, delimiter = ",") => JSON.stringify(csv2object(csv,delimiter));
|
|
4395
4430
|
const csv2sql=(csv, Table)=>{
|
|
4431
|
+
const sanitizeId = s => s.trim().replace(/[^a-zA-Z0-9_]/g, '');
|
|
4432
|
+
const escapeVal = s => "'" + s.trim().replace(/'/g, "''") + "'";
|
|
4396
4433
|
const lines = csv.trim().trimEnd().split('\n').filter(n=>n);
|
|
4397
|
-
const columns = lines[0].split(',');
|
|
4398
|
-
let sqlQuery =
|
|
4434
|
+
const columns = lines[0].split(',').map(sanitizeId);
|
|
4435
|
+
let sqlQuery = "INSERT INTO " + sanitizeId(Table) + " (" + columns.join(', ') + ") Values ";
|
|
4399
4436
|
let sqlValues = [];
|
|
4400
4437
|
for (let i = 1; i < lines.length; i++) {
|
|
4401
|
-
const values = lines[i].split(',');
|
|
4402
|
-
sqlValues.push(
|
|
4438
|
+
const values = lines[i].split(',').map(escapeVal);
|
|
4439
|
+
sqlValues.push("(" + values.join(', ') + ")");
|
|
4403
4440
|
}
|
|
4404
4441
|
return sqlQuery+sqlValues.join(",\n");
|
|
4405
4442
|
};
|
|
@@ -4516,6 +4553,35 @@ function trimKeys(obj) {
|
|
|
4516
4553
|
}, Array.isArray(obj) ? [] : {});
|
|
4517
4554
|
}
|
|
4518
4555
|
|
|
4556
|
+
function parseXML(xmlString) {
|
|
4557
|
+
const parser = new DOMParser();
|
|
4558
|
+
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
|
4559
|
+
const rootNode = xmlDoc.documentElement;
|
|
4560
|
+
const result = parseNode(rootNode);
|
|
4561
|
+
return result;
|
|
4562
|
+
}
|
|
4563
|
+
|
|
4564
|
+
function parseNode(node) {
|
|
4565
|
+
const obj = {
|
|
4566
|
+
type: node.nodeName,
|
|
4567
|
+
attributes: {},
|
|
4568
|
+
children: []
|
|
4569
|
+
};
|
|
4570
|
+
for (let i = 0; i < node.attributes.length; i++) {
|
|
4571
|
+
const attr = node.attributes[i];
|
|
4572
|
+
obj.attributes[attr.name] = attr.value;
|
|
4573
|
+
}
|
|
4574
|
+
for (let i = 0; i < node.childNodes.length; i++) {
|
|
4575
|
+
const child = node.childNodes[i];
|
|
4576
|
+
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
4577
|
+
obj.children.push(parseNode(child));
|
|
4578
|
+
} else if (child.nodeType === Node.TEXT_NODE) {
|
|
4579
|
+
obj.text = child.textContent.trim();
|
|
4580
|
+
}
|
|
4581
|
+
}
|
|
4582
|
+
return obj;
|
|
4583
|
+
}
|
|
4584
|
+
|
|
4519
4585
|
// import { ZikoHead , useHead} from "../reactivity/hooks/head/index.js";
|
|
4520
4586
|
class ZikoApp {
|
|
4521
4587
|
constructor({head = null, wrapper = null, target = null}){
|
|
@@ -5249,6 +5315,7 @@ exports.PI = PI$1;
|
|
|
5249
5315
|
exports.PtrListeners = PtrListeners;
|
|
5250
5316
|
exports.Random = Random;
|
|
5251
5317
|
exports.SPA = SPA;
|
|
5318
|
+
exports.STATE_GETTER = STATE_GETTER;
|
|
5252
5319
|
exports.SVGWrapper = SVGWrapper;
|
|
5253
5320
|
exports.Scheduler = Scheduler;
|
|
5254
5321
|
exports.Suspense = Suspense;
|
|
@@ -5353,8 +5420,8 @@ exports.in_quint = in_quint;
|
|
|
5353
5420
|
exports.in_sin = in_sin;
|
|
5354
5421
|
exports.interquartile_mean = interquartile_mean;
|
|
5355
5422
|
exports.iqr = iqr;
|
|
5356
|
-
exports.isPrimitive = isPrimitive;
|
|
5357
5423
|
exports.isStateGetter = isStateGetter;
|
|
5424
|
+
exports.is_primitive = is_primitive;
|
|
5358
5425
|
exports.json2arr = json2arr;
|
|
5359
5426
|
exports.json2css = json2css;
|
|
5360
5427
|
exports.json2csv = json2csv;
|
|
@@ -5399,6 +5466,8 @@ exports.out_quad = out_quad;
|
|
|
5399
5466
|
exports.out_quart = out_quart;
|
|
5400
5467
|
exports.out_quint = out_quint;
|
|
5401
5468
|
exports.out_sin = out_sin;
|
|
5469
|
+
exports.parseXML = parseXML;
|
|
5470
|
+
exports.parse_props = parse_props;
|
|
5402
5471
|
exports.percentile = percentile;
|
|
5403
5472
|
exports.pow = pow$1;
|
|
5404
5473
|
exports.power_mean = power_mean;
|