ziko 0.45.1 → 0.45.3
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 +647 -696
- package/dist/ziko.js +98 -61
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +95 -62
- package/package.json +1 -1
- package/src/app/spa-file-based-routing.js +3 -2
- package/src/hooks/use-state.js +2 -2
- package/src/ui/__methods__/utils/index.js +1 -1
- package/src/ui/constructors/UIElement.js +6 -5
- package/src/ui/constructors/UIElementCore.js +10 -11
- package/src/ui/index.js +1 -1
- package/src/ui/logic/switch/index.js +28 -0
- package/src/ui/tags/index.js +9 -3
- package/src/ui/tags/tags-list.js +0 -1
- package/src/ui/wrappers/html/index.js +26 -0
- package/src/ui/wrappers/index.js +2 -0
- package/src/ui/wrappers/svg/index.js +46 -0
- package/src/ui/wrapper/index.js +0 -42
package/dist/ziko.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Wed Sep 03 2025 15:22:46 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
|
|
@@ -1198,22 +1198,21 @@ function __init__global__(){
|
|
|
1198
1198
|
|
|
1199
1199
|
__init__global__();
|
|
1200
1200
|
class UIElementCore extends UINode{
|
|
1201
|
-
constructor({
|
|
1202
|
-
element,
|
|
1203
|
-
name ='',
|
|
1204
|
-
type="html",
|
|
1205
|
-
render = __Ziko__.__Config__.default.render,
|
|
1206
|
-
isInteractive = false,
|
|
1207
|
-
}={}){
|
|
1201
|
+
constructor(){
|
|
1208
1202
|
super();
|
|
1209
|
-
this.init(element, name, type, render, isInteractive);
|
|
1210
1203
|
}
|
|
1211
1204
|
init(element, name, type, render, isInteractive = [true, false][Math.floor(2*Math.random())]){
|
|
1212
1205
|
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
1213
1206
|
if(typeof element === "string") {
|
|
1214
1207
|
switch(type){
|
|
1215
|
-
case "html" :
|
|
1216
|
-
|
|
1208
|
+
case "html" : {
|
|
1209
|
+
element = globalThis?.document?.createElement(element);
|
|
1210
|
+
console.log('1');
|
|
1211
|
+
} break;
|
|
1212
|
+
case "svg" : {
|
|
1213
|
+
element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
|
|
1214
|
+
console.log('2');
|
|
1215
|
+
} break;
|
|
1217
1216
|
default : throw Error("Not supported")
|
|
1218
1217
|
}
|
|
1219
1218
|
}
|
|
@@ -1267,7 +1266,7 @@ class UIElementCore extends UINode{
|
|
|
1267
1266
|
// &&
|
|
1268
1267
|
this.isInteractive()){
|
|
1269
1268
|
// this.setAttr("ziko-hydration-index", globalThis.__Ziko__.__HYDRATION__.index);
|
|
1270
|
-
this.element.setAttribute('ziko-hydration-index', globalThis.__Ziko__.__HYDRATION__.index)
|
|
1269
|
+
// this.element.setAttribute('ziko-hydration-index', globalThis.__Ziko__.__HYDRATION__.index)
|
|
1271
1270
|
globalThis.__Ziko__.__HYDRATION__.register(() => this);
|
|
1272
1271
|
}
|
|
1273
1272
|
globalThis.__Ziko__.__UI__.push(this);
|
|
@@ -1447,49 +1446,11 @@ function _register_to_class_(target, mixin) {
|
|
|
1447
1446
|
}
|
|
1448
1447
|
}
|
|
1449
1448
|
|
|
1450
|
-
function register_to_instance(target, ...mixins){
|
|
1451
|
-
console.log('register to instance');
|
|
1452
|
-
mixins.forEach(n => _register_to_instance_(target, n));
|
|
1453
|
-
}
|
|
1454
|
-
function _register_to_instance_(instance, mixin) {
|
|
1455
|
-
const descriptors = Object.getOwnPropertyDescriptors(mixin);
|
|
1456
|
-
for (const key of Reflect.ownKeys(descriptors)) {
|
|
1457
|
-
const desc = descriptors[key];
|
|
1458
|
-
if ('get' in desc || 'set' in desc) {
|
|
1459
|
-
Object.defineProperty(instance, key, {
|
|
1460
|
-
...desc,
|
|
1461
|
-
configurable: true // 🔑 make it replaceable
|
|
1462
|
-
});
|
|
1463
|
-
} else if (typeof desc.value === 'function') {
|
|
1464
|
-
Object.defineProperty(instance, key, {
|
|
1465
|
-
value: desc.value.bind(instance),
|
|
1466
|
-
writable: true, // 🔑 allow reassignment
|
|
1467
|
-
configurable: true, // 🔑 allow redefinition
|
|
1468
|
-
enumerable: false
|
|
1469
|
-
});
|
|
1470
|
-
} else {
|
|
1471
|
-
Object.defineProperty(instance, key, {
|
|
1472
|
-
value: desc.value,
|
|
1473
|
-
writable: true,
|
|
1474
|
-
configurable: true,
|
|
1475
|
-
enumerable: true
|
|
1476
|
-
});
|
|
1477
|
-
}
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
const register = (target, ...mixins) => {
|
|
1482
|
-
console.log(target);
|
|
1483
|
-
// return register_to_class(target, ...mixins)
|
|
1484
|
-
if(typeof target === 'function') register_to_class(target, ...mixins);
|
|
1485
|
-
else register_to_instance(target, ...mixins);
|
|
1486
|
-
};
|
|
1487
|
-
|
|
1488
1449
|
if(!globalThis.__Ziko__) __init__global__();
|
|
1489
1450
|
|
|
1490
1451
|
// HMR persistence
|
|
1491
|
-
if (import.meta.hot) {
|
|
1492
|
-
import.meta.hot.data.__Ziko__ = import.meta.hot.data
|
|
1452
|
+
if (import.meta.hot?.data) {
|
|
1453
|
+
import.meta.hot.data.__Ziko__ = import.meta.hot.data?.__Ziko__ || globalThis?.__Ziko__;
|
|
1493
1454
|
globalThis.__Ziko__ = import.meta.hot.data.__Ziko__;
|
|
1494
1455
|
// import.meta.hot.accept(n=>console.log(n));
|
|
1495
1456
|
// console.log(import.meta.hot.data.__Ziko__.__State__.store)
|
|
@@ -1612,7 +1573,7 @@ async function __addItem__(adder, pusher, ...ele) {
|
|
|
1612
1573
|
return this;
|
|
1613
1574
|
}
|
|
1614
1575
|
function _set_attrs_(name, value){
|
|
1615
|
-
if(this.element
|
|
1576
|
+
if(this.element instanceof globalThis?.SVGAElement) name = is_camelcase$1(name) ? camel2hyphencase$1(name) : name;
|
|
1616
1577
|
if(this?.attr[name] && this?.attr[name]===value) return;
|
|
1617
1578
|
if(isStateGetter(value)){
|
|
1618
1579
|
const getter = value();
|
|
@@ -3161,10 +3122,11 @@ class ZikoUseMediaQuery {
|
|
|
3161
3122
|
const useMediaQuery = (mediaQueryRules,fallback) => new ZikoUseMediaQuery(mediaQueryRules,fallback);
|
|
3162
3123
|
|
|
3163
3124
|
let UIElement$1 = class UIElement extends UIElementCore{
|
|
3164
|
-
constructor({element, name ='', type=
|
|
3165
|
-
super(
|
|
3166
|
-
console.log(
|
|
3167
|
-
|
|
3125
|
+
constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
|
|
3126
|
+
super();
|
|
3127
|
+
// console.log({type})
|
|
3128
|
+
// console.log(this)
|
|
3129
|
+
register_to_class(
|
|
3168
3130
|
this,
|
|
3169
3131
|
AttrsMethods,
|
|
3170
3132
|
DomMethods,
|
|
@@ -3419,7 +3381,6 @@ const HTMLTags = [
|
|
|
3419
3381
|
'sub',
|
|
3420
3382
|
'summary',
|
|
3421
3383
|
'sup',
|
|
3422
|
-
'svg',
|
|
3423
3384
|
'table',
|
|
3424
3385
|
'tbody',
|
|
3425
3386
|
'td',
|
|
@@ -3453,6 +3414,9 @@ const SVGTags = [
|
|
|
3453
3414
|
"desc", "title", "metadata", "foreignObject"
|
|
3454
3415
|
];
|
|
3455
3416
|
|
|
3417
|
+
// const h=(tag, attributes = {}, ...children)=> _h(tag, "html", attributes, ...children);
|
|
3418
|
+
// const s=(tag, attributes = {}, ...children)=> _h(tag, "svg", attributes, ...children);
|
|
3419
|
+
|
|
3456
3420
|
const tags = new Proxy({}, {
|
|
3457
3421
|
get(target, prop) {
|
|
3458
3422
|
if (typeof prop !== 'string') return undefined;
|
|
@@ -3460,16 +3424,22 @@ const tags = new Proxy({}, {
|
|
|
3460
3424
|
let type ;
|
|
3461
3425
|
if(HTMLTags.includes(tag)) type = 'html';
|
|
3462
3426
|
if(SVGTags.includes(tag)) type = 'svg';
|
|
3427
|
+
// console.log(type)
|
|
3463
3428
|
return (...args)=>{
|
|
3464
3429
|
// Fix undefined
|
|
3465
3430
|
// console.log(isStateGetter(args[0]))
|
|
3431
|
+
// console.log(!!args)
|
|
3432
|
+
if(args.length === 0) {
|
|
3433
|
+
// console.log('length 0')
|
|
3434
|
+
return new UIElement$1({element : tag, name : tag, type})
|
|
3435
|
+
}
|
|
3466
3436
|
if(
|
|
3467
3437
|
['string', 'number'].includes(typeof args[0])
|
|
3468
3438
|
|| args[0] instanceof UIElement$1
|
|
3469
3439
|
|| (typeof args[0] === 'function' && args[0]().isStateGetter())
|
|
3470
3440
|
) return new UIElement$1({element : tag, name : tag, type}).append(...args);
|
|
3471
3441
|
// console.log(args[0])
|
|
3472
|
-
return new UIElement$1({element : tag}).setAttr(args.shift()).append(...args)
|
|
3442
|
+
return new UIElement$1({element : tag, type}).setAttr(args.shift()).append(...args)
|
|
3473
3443
|
}
|
|
3474
3444
|
// if(SVGTags.includes(tag)) return (...args) => new UIElement(tag,"",{el_type : "svg"}).append(...args);
|
|
3475
3445
|
// return (...args)=>{
|
|
@@ -3621,6 +3591,68 @@ class ZikoUISuspense extends UIElement{
|
|
|
3621
3591
|
|
|
3622
3592
|
const Suspense = (fallback_ui, callback) => new ZikoUISuspense(fallback_ui, callback);
|
|
3623
3593
|
|
|
3594
|
+
class UIHTMLWrapper extends UIElement$1 {
|
|
3595
|
+
constructor(content){
|
|
3596
|
+
super({element : 'div', name : 'html_wrappper'});
|
|
3597
|
+
this.element.append(html2dom(content));
|
|
3598
|
+
this.style({
|
|
3599
|
+
display : 'contents'
|
|
3600
|
+
});
|
|
3601
|
+
}
|
|
3602
|
+
}
|
|
3603
|
+
|
|
3604
|
+
function html2dom(htmlString) {
|
|
3605
|
+
if(globalThis?.DOMParser){
|
|
3606
|
+
const parser = new DOMParser();
|
|
3607
|
+
const doc = parser.parseFromString(`<div>${htmlString}</div>`, 'text/html');
|
|
3608
|
+
doc.body.firstChild.style.display = "contents";
|
|
3609
|
+
return doc.body.firstChild;
|
|
3610
|
+
}
|
|
3611
|
+
}
|
|
3612
|
+
|
|
3613
|
+
const HTMLWrapper = (content) => new UIHTMLWrapper(content);
|
|
3614
|
+
|
|
3615
|
+
class UISVGWrapper extends UIElement$1 {
|
|
3616
|
+
constructor(content){
|
|
3617
|
+
super({element : 'div', name : 'html_wrappper'});
|
|
3618
|
+
this.element.append(svg2dom(content));
|
|
3619
|
+
this.style({
|
|
3620
|
+
display : 'contents'
|
|
3621
|
+
});
|
|
3622
|
+
}
|
|
3623
|
+
}
|
|
3624
|
+
|
|
3625
|
+
function svg2dom(svgString) {
|
|
3626
|
+
if (typeof DOMParser !== "undefined") {
|
|
3627
|
+
const parser = new DOMParser();
|
|
3628
|
+
const doc = parser.parseFromString(svgString.trim(), "image/svg+xml");
|
|
3629
|
+
const svg = doc.documentElement;
|
|
3630
|
+
|
|
3631
|
+
if (svg.nodeName === "parsererror") {
|
|
3632
|
+
throw new Error("Invalid SVG string");
|
|
3633
|
+
}
|
|
3634
|
+
if(svg.hasAttribute('xmlns')) return svg
|
|
3635
|
+
// TO Fix ...
|
|
3636
|
+
const {children, attributes} = svg;
|
|
3637
|
+
const element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
3638
|
+
for(let {name, value} of attributes){
|
|
3639
|
+
element.setAttribute(name, value);
|
|
3640
|
+
}
|
|
3641
|
+
element.append(...children);
|
|
3642
|
+
|
|
3643
|
+
globalThis.svg = svg;
|
|
3644
|
+
globalThis.children = children;
|
|
3645
|
+
globalThis.attributes = attributes;
|
|
3646
|
+
globalThis.element = element;
|
|
3647
|
+
return element;
|
|
3648
|
+
}
|
|
3649
|
+
throw new Error("DOMParser is not available in this environment");
|
|
3650
|
+
}
|
|
3651
|
+
|
|
3652
|
+
|
|
3653
|
+
|
|
3654
|
+
const SVGWrapper = (content) => new UISVGWrapper(content);
|
|
3655
|
+
|
|
3624
3656
|
function define_wc(name, UIElement, props = {}, { mode = 'open'} = {}) {
|
|
3625
3657
|
if (globalThis.customElements?.get(name)) {
|
|
3626
3658
|
console.warn(`Custom element "${name}" is already defined`);
|
|
@@ -5495,11 +5527,12 @@ function customPath(inputPath, root = './src/pages', extensions = ['js', 'ts'])
|
|
|
5495
5527
|
const normalizedPath = inputPath.replace(/\\/g, '/').replace(/\[(\w+)\]/g, '$1/:$1');
|
|
5496
5528
|
const parts = normalizedPath.split('/');
|
|
5497
5529
|
const rootParts = root.split('/');
|
|
5498
|
-
const rootIndex = parts.indexOf(rootParts
|
|
5530
|
+
const rootIndex = parts.indexOf(rootParts.at(-1));
|
|
5499
5531
|
if (rootIndex !== -1) {
|
|
5500
5532
|
const subsequentParts = parts.slice(rootIndex + 1);
|
|
5501
|
-
const lastPart =
|
|
5533
|
+
const lastPart = parts.at(-1);
|
|
5502
5534
|
const isIndexFile = lastPart === 'index.js' || lastPart === 'index.ts';
|
|
5535
|
+
// console.log({extensions, subsequentParts, lastPart, isIndexFile, rootParts, rootIndex, parts})
|
|
5503
5536
|
const hasValidExtension = extensions.some(ext => lastPart === `.${ext}` || lastPart.endsWith(`.${ext}`));
|
|
5504
5537
|
if (isIndexFile) {
|
|
5505
5538
|
return '/' + (subsequentParts.length > 1 ? subsequentParts.slice(0, -1).join('/') : '');
|
|
@@ -5859,4 +5892,4 @@ if(globalThis?.document){
|
|
|
5859
5892
|
document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
|
|
5860
5893
|
}
|
|
5861
5894
|
|
|
5862
|
-
export { App, Arc, Back, Base, Clock, Combinaison, Complex, Discret, E, EPSILON, Elastic, FileBasedRouting, Flex, InBack, InBounce, InCirc, InCubic, InElastic, InExpo, InOutBack, InOutBounce, InOutCirc, InOutCubic, InOutElastic, InOutExpo, InOutQuad, InOutQuart, InOutQuint, InOutSin, InQuad, InQuart, InQuint, InSin, Linear, Logic$1 as Logic, Matrix, OutBack, OutBounce, OutCirc, OutCubic, OutElastic, OutExpo, OutQuad, OutQuart, OutQuint, OutSin, PI$2 as PI, Permutation, Random, SPA, Scheduler, Step, Suspense, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UINode, Utils, ZikoApp, ZikoCustomEvent, ZikoEventClick, ZikoEventClipboard, ZikoEventCustom, ZikoEventDrag, ZikoEventFocus, ZikoEventInput, ZikoEventKey, ZikoEventMouse, ZikoEventPointer, ZikoEventSwipe, ZikoEventTouch, ZikoEventWheel, ZikoHead, ZikoMutationObserver, ZikoSPA, ZikoUIFlex, ZikoUISuspense, ZikoUIText, ZikoUseRoot, __ZikoEvent__, abs, accum, acos$1 as acos, acosh, acot, add, animation, arange, arr2str, asin, asinh, atan, atan2, atanh, bindCustomEvent, bindHashEvent, bindTouchEvent, bind_click_event, bind_clipboard_event, bind_drag_event, bind_focus_event, bind_key_event, bind_mouse_event, bind_pointer_event, bind_wheel_event, cartesianProduct, ceil, clamp, clock, combinaison, complex, cos$2 as cos, cosh$1 as cosh, cot, coth, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, define_wc, deg2rad, div, e, fact, floor, geomspace, getEvent, hypot, inRange, isApproximatlyEqual, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linspace, ln, logspace, loop, map$1 as map, mapfun$1 as mapfun, matrix, matrix2, matrix3, matrix4, max, min, modulo, mul, norm, nums, obj2str, ones, pgcd, pow$1 as pow, powerSet, ppcm, preload, prod, rad2deg, round, sec, sig, sign, sin$2 as sin, sinc, sinh$1 as sinh, sleep, sqrt$2 as sqrt, sqrtn, step_fps, sub, subSet, sum, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, useChannel, useCustomEvent, useDerived, useEventEmitter, useFavIcon, useHashEvent, useHead, useInputEvent, useLocaleStorage, useMediaQuery, useMeta, useReactive, useRoot, useSessionStorage, useState, useSuccesifKeys, useSwipeEvent, useThread, useTitle, wait, waitForUIElm, waitForUIElmSync, watch, watchAttr, watchChildren, watchIntersection, watchScreen, watchSize, zeros };
|
|
5895
|
+
export { App, Arc, Back, Base, Clock, Combinaison, Complex, Discret, E, EPSILON, Elastic, FileBasedRouting, Flex, HTMLWrapper, InBack, InBounce, InCirc, InCubic, InElastic, InExpo, InOutBack, InOutBounce, InOutCirc, InOutCubic, InOutElastic, InOutExpo, InOutQuad, InOutQuart, InOutQuint, InOutSin, InQuad, InQuart, InQuint, InSin, Linear, Logic$1 as Logic, Matrix, OutBack, OutBounce, OutCirc, OutCubic, OutElastic, OutExpo, OutQuad, OutQuart, OutQuint, OutSin, PI$2 as PI, Permutation, Random, SPA, SVGWrapper, Scheduler, Step, Suspense, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UIHTMLWrapper, UINode, UISVGWrapper, Utils, ZikoApp, ZikoCustomEvent, ZikoEventClick, ZikoEventClipboard, ZikoEventCustom, ZikoEventDrag, ZikoEventFocus, ZikoEventInput, ZikoEventKey, ZikoEventMouse, ZikoEventPointer, ZikoEventSwipe, ZikoEventTouch, ZikoEventWheel, ZikoHead, ZikoMutationObserver, ZikoSPA, ZikoUIFlex, ZikoUISuspense, ZikoUIText, ZikoUseRoot, __ZikoEvent__, abs, accum, acos$1 as acos, acosh, acot, add, animation, arange, arr2str, asin, asinh, atan, atan2, atanh, bindCustomEvent, bindHashEvent, bindTouchEvent, bind_click_event, bind_clipboard_event, bind_drag_event, bind_focus_event, bind_key_event, bind_mouse_event, bind_pointer_event, bind_wheel_event, cartesianProduct, ceil, clamp, clock, combinaison, complex, cos$2 as cos, cosh$1 as cosh, cot, coth, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, define_wc, deg2rad, div, e, fact, floor, geomspace, getEvent, hypot, inRange, isApproximatlyEqual, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linspace, ln, logspace, loop, map$1 as map, mapfun$1 as mapfun, matrix, matrix2, matrix3, matrix4, max, min, modulo, mul, norm, nums, obj2str, ones, pgcd, pow$1 as pow, powerSet, ppcm, preload, prod, rad2deg, round, sec, sig, sign, sin$2 as sin, sinc, sinh$1 as sinh, sleep, sqrt$2 as sqrt, sqrtn, step_fps, sub, subSet, sum, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, useChannel, useCustomEvent, useDerived, useEventEmitter, useFavIcon, useHashEvent, useHead, useInputEvent, useLocaleStorage, useMediaQuery, useMeta, useReactive, useRoot, useSessionStorage, useState, useSuccesifKeys, useSwipeEvent, useThread, useTitle, wait, waitForUIElm, waitForUIElmSync, watch, watchAttr, watchChildren, watchIntersection, watchScreen, watchSize, zeros };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ziko",
|
|
3
|
-
"version": "0.45.
|
|
3
|
+
"version": "0.45.3",
|
|
4
4
|
"description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"front-end",
|
|
@@ -24,11 +24,12 @@ function customPath(inputPath, root = './src/pages', extensions = ['js', 'ts'])
|
|
|
24
24
|
const normalizedPath = inputPath.replace(/\\/g, '/').replace(/\[(\w+)\]/g, '$1/:$1');
|
|
25
25
|
const parts = normalizedPath.split('/');
|
|
26
26
|
const rootParts = root.split('/');
|
|
27
|
-
const rootIndex = parts.indexOf(rootParts
|
|
27
|
+
const rootIndex = parts.indexOf(rootParts.at(-1));
|
|
28
28
|
if (rootIndex !== -1) {
|
|
29
29
|
const subsequentParts = parts.slice(rootIndex + 1);
|
|
30
|
-
const lastPart =
|
|
30
|
+
const lastPart = parts.at(-1);
|
|
31
31
|
const isIndexFile = lastPart === 'index.js' || lastPart === 'index.ts';
|
|
32
|
+
// console.log({extensions, subsequentParts, lastPart, isIndexFile, rootParts, rootIndex, parts})
|
|
32
33
|
const hasValidExtension = extensions.some(ext => lastPart === `.${ext}` || lastPart.endsWith(`.${ext}`));
|
|
33
34
|
if (isIndexFile) {
|
|
34
35
|
return '/' + (subsequentParts.length > 1 ? subsequentParts.slice(0, -1).join('/') : '');
|
package/src/hooks/use-state.js
CHANGED
|
@@ -2,8 +2,8 @@ import { __init__global__ } from "../__ziko__/index.js";
|
|
|
2
2
|
if(!globalThis.__Ziko__) __init__global__()
|
|
3
3
|
|
|
4
4
|
// HMR persistence
|
|
5
|
-
if (import.meta.hot) {
|
|
6
|
-
import.meta.hot.data.__Ziko__ = import.meta.hot.data
|
|
5
|
+
if (import.meta.hot?.data) {
|
|
6
|
+
import.meta.hot.data.__Ziko__ = import.meta.hot.data?.__Ziko__ || globalThis?.__Ziko__;
|
|
7
7
|
globalThis.__Ziko__ = import.meta.hot.data.__Ziko__;
|
|
8
8
|
// import.meta.hot.accept(n=>console.log(n));
|
|
9
9
|
// console.log(import.meta.hot.data.__Ziko__.__State__.store)
|
|
@@ -50,7 +50,7 @@ export async function __addItem__(adder, pusher, ...ele) {
|
|
|
50
50
|
return this;
|
|
51
51
|
}
|
|
52
52
|
export function _set_attrs_(name, value){
|
|
53
|
-
if(this.element
|
|
53
|
+
if(this.element instanceof globalThis?.SVGAElement) name = is_camelcase(name) ? camel2hyphencase(name) : name;
|
|
54
54
|
if(this?.attr[name] && this?.attr[name]===value) return;
|
|
55
55
|
if(isStateGetter(value)){
|
|
56
56
|
const getter = value()
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UIElementCore } from "./UIElementCore.js";
|
|
2
|
-
import {
|
|
2
|
+
import { register_to_class } from "../../__helpers__/register/register-to-class.js";
|
|
3
3
|
import {
|
|
4
4
|
AttrsMethods,
|
|
5
5
|
DomMethods,
|
|
@@ -16,10 +16,11 @@ import {
|
|
|
16
16
|
watchChildren
|
|
17
17
|
} from "../../reactivity/index.js"
|
|
18
18
|
class UIElement extends UIElementCore{
|
|
19
|
-
constructor({element, name ='', type=
|
|
20
|
-
super(
|
|
21
|
-
console.log(
|
|
22
|
-
|
|
19
|
+
constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
|
|
20
|
+
super()
|
|
21
|
+
// console.log({type})
|
|
22
|
+
// console.log(this)
|
|
23
|
+
register_to_class(
|
|
23
24
|
this,
|
|
24
25
|
AttrsMethods,
|
|
25
26
|
DomMethods,
|
|
@@ -2,22 +2,21 @@ import {UINode} from "./UINode.js";
|
|
|
2
2
|
import {__init__global__, UIStore} from '../../__ziko__/index.js';
|
|
3
3
|
__init__global__()
|
|
4
4
|
class UIElementCore extends UINode{
|
|
5
|
-
constructor({
|
|
6
|
-
element,
|
|
7
|
-
name ='',
|
|
8
|
-
type="html",
|
|
9
|
-
render = __Ziko__.__Config__.default.render,
|
|
10
|
-
isInteractive = false,
|
|
11
|
-
}={}){
|
|
5
|
+
constructor(){
|
|
12
6
|
super()
|
|
13
|
-
this.init(element, name, type, render, isInteractive)
|
|
14
7
|
}
|
|
15
8
|
init(element, name, type, render, isInteractive = [true, false][Math.floor(2*Math.random())]){
|
|
16
9
|
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
17
10
|
if(typeof element === "string") {
|
|
18
11
|
switch(type){
|
|
19
|
-
case "html" :
|
|
20
|
-
|
|
12
|
+
case "html" : {
|
|
13
|
+
element = globalThis?.document?.createElement(element);
|
|
14
|
+
console.log('1')
|
|
15
|
+
}; break;
|
|
16
|
+
case "svg" : {
|
|
17
|
+
element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
|
|
18
|
+
console.log('2')
|
|
19
|
+
}; break;
|
|
21
20
|
default : throw Error("Not supported")
|
|
22
21
|
}
|
|
23
22
|
}
|
|
@@ -71,7 +70,7 @@ class UIElementCore extends UINode{
|
|
|
71
70
|
// &&
|
|
72
71
|
this.isInteractive()){
|
|
73
72
|
// this.setAttr("ziko-hydration-index", globalThis.__Ziko__.__HYDRATION__.index);
|
|
74
|
-
this.element.setAttribute('ziko-hydration-index', globalThis.__Ziko__.__HYDRATION__.index)
|
|
73
|
+
// this.element.setAttribute('ziko-hydration-index', globalThis.__Ziko__.__HYDRATION__.index)
|
|
75
74
|
globalThis.__Ziko__.__HYDRATION__.register(() => this)
|
|
76
75
|
}
|
|
77
76
|
globalThis.__Ziko__.__UI__.push(this)
|
package/src/ui/index.js
CHANGED
|
@@ -5,6 +5,6 @@ export * from './text/index.js';
|
|
|
5
5
|
export * from './flex/index.js';
|
|
6
6
|
// export * from './grid/index.js';
|
|
7
7
|
export * from './suspense/index.js';
|
|
8
|
-
|
|
8
|
+
export * from './wrappers/index.js';
|
|
9
9
|
// export * from './graphics/index.js'
|
|
10
10
|
export * from './web-component/index.js'
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { UIElement } from "../../constructors/UIElement.js";
|
|
2
|
+
|
|
3
|
+
class UISwitch{
|
|
4
|
+
constructor(key, cases){
|
|
5
|
+
this.key = key;
|
|
6
|
+
this.cases = cases;
|
|
7
|
+
}
|
|
8
|
+
current_ui(){
|
|
9
|
+
const matched = Object.keys(this.cases).find(n => n == this.key) ?? 'default'
|
|
10
|
+
return this.cases[matched]()
|
|
11
|
+
}
|
|
12
|
+
updateKey(key){
|
|
13
|
+
this.key
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const Switch=({key, cases})=> new UISwitch(key, cases)
|
|
19
|
+
|
|
20
|
+
export{
|
|
21
|
+
UISwitch,
|
|
22
|
+
Switch
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// export const Switch=({key, cases}) => {
|
|
26
|
+
// const matched = Object.keys(cases).find(n => n == key) ?? 'default';
|
|
27
|
+
// return this.cases[matched]()
|
|
28
|
+
// }
|
package/src/ui/tags/index.js
CHANGED
|
@@ -9,8 +9,8 @@ const _h=(tag, type, attributes, ...children)=>{
|
|
|
9
9
|
children && element.append(...children);
|
|
10
10
|
return element;
|
|
11
11
|
}
|
|
12
|
-
const h=(tag, attributes = {}, ...children)=> _h(tag, "html", attributes, ...children);
|
|
13
|
-
const s=(tag, attributes = {}, ...children)=> _h(tag, "svg", attributes, ...children);
|
|
12
|
+
// const h=(tag, attributes = {}, ...children)=> _h(tag, "html", attributes, ...children);
|
|
13
|
+
// const s=(tag, attributes = {}, ...children)=> _h(tag, "svg", attributes, ...children);
|
|
14
14
|
|
|
15
15
|
const tags = new Proxy({}, {
|
|
16
16
|
get(target, prop) {
|
|
@@ -19,16 +19,22 @@ const tags = new Proxy({}, {
|
|
|
19
19
|
let type ;
|
|
20
20
|
if(HTMLTags.includes(tag)) type = 'html'
|
|
21
21
|
if(SVGTags.includes(tag)) type = 'svg'
|
|
22
|
+
// console.log(type)
|
|
22
23
|
return (...args)=>{
|
|
23
24
|
// Fix undefined
|
|
24
25
|
// console.log(isStateGetter(args[0]))
|
|
26
|
+
// console.log(!!args)
|
|
27
|
+
if(args.length === 0) {
|
|
28
|
+
// console.log('length 0')
|
|
29
|
+
return new UIElement({element : tag, name : tag, type})
|
|
30
|
+
}
|
|
25
31
|
if(
|
|
26
32
|
['string', 'number'].includes(typeof args[0])
|
|
27
33
|
|| args[0] instanceof UIElement
|
|
28
34
|
|| (typeof args[0] === 'function' && args[0]().isStateGetter())
|
|
29
35
|
) return new UIElement({element : tag, name : tag, type}).append(...args);
|
|
30
36
|
// console.log(args[0])
|
|
31
|
-
return new UIElement({element : tag}).setAttr(args.shift()).append(...args)
|
|
37
|
+
return new UIElement({element : tag, type}).setAttr(args.shift()).append(...args)
|
|
32
38
|
}
|
|
33
39
|
// if(SVGTags.includes(tag)) return (...args) => new UIElement(tag,"",{el_type : "svg"}).append(...args);
|
|
34
40
|
// return (...args)=>{
|
package/src/ui/tags/tags-list.js
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { UIElement } from "../../constructors/UIElement.js";
|
|
2
|
+
|
|
3
|
+
class UIHTMLWrapper extends UIElement {
|
|
4
|
+
constructor(content){
|
|
5
|
+
super({element : 'div', name : 'html_wrappper'})
|
|
6
|
+
this.element.append(html2dom(content))
|
|
7
|
+
this.style({
|
|
8
|
+
display : 'contents'
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function html2dom(htmlString) {
|
|
14
|
+
if(globalThis?.DOMParser){
|
|
15
|
+
const parser = new DOMParser();
|
|
16
|
+
const doc = parser.parseFromString(`<div>${htmlString}</div>`, 'text/html');
|
|
17
|
+
doc.body.firstChild.style.display = "contents"
|
|
18
|
+
return doc.body.firstChild;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const HTMLWrapper = (content) => new UIHTMLWrapper(content)
|
|
23
|
+
export{
|
|
24
|
+
UIHTMLWrapper,
|
|
25
|
+
HTMLWrapper
|
|
26
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { UIElement } from "../../constructors/UIElement.js";
|
|
2
|
+
|
|
3
|
+
class UISVGWrapper extends UIElement {
|
|
4
|
+
constructor(content){
|
|
5
|
+
super({element : 'div', name : 'html_wrappper'})
|
|
6
|
+
this.element.append(svg2dom(content));
|
|
7
|
+
this.style({
|
|
8
|
+
display : 'contents'
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function svg2dom(svgString) {
|
|
14
|
+
if (typeof DOMParser !== "undefined") {
|
|
15
|
+
const parser = new DOMParser();
|
|
16
|
+
const doc = parser.parseFromString(svgString.trim(), "image/svg+xml");
|
|
17
|
+
const svg = doc.documentElement;
|
|
18
|
+
|
|
19
|
+
if (svg.nodeName === "parsererror") {
|
|
20
|
+
throw new Error("Invalid SVG string");
|
|
21
|
+
}
|
|
22
|
+
if(svg.hasAttribute('xmlns')) return svg
|
|
23
|
+
// TO Fix ...
|
|
24
|
+
const {children, attributes} = svg;
|
|
25
|
+
const element = document.createElementNS("http://www.w3.org/2000/svg", "svg")
|
|
26
|
+
for(let {name, value} of attributes){
|
|
27
|
+
element.setAttribute(name, value)
|
|
28
|
+
}
|
|
29
|
+
element.append(...children)
|
|
30
|
+
|
|
31
|
+
globalThis.svg = svg
|
|
32
|
+
globalThis.children = children
|
|
33
|
+
globalThis.attributes = attributes
|
|
34
|
+
globalThis.element = element
|
|
35
|
+
return element;
|
|
36
|
+
}
|
|
37
|
+
throw new Error("DOMParser is not available in this environment");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const SVGWrapper = (content) => new UISVGWrapper(content)
|
|
43
|
+
export{
|
|
44
|
+
UISVGWrapper,
|
|
45
|
+
SVGWrapper
|
|
46
|
+
}
|
package/src/ui/wrapper/index.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {UIElement} from "../constructors/UIElement.js";
|
|
2
|
-
class ZikoUIXMLWrapper extends UIElement{
|
|
3
|
-
constructor(XMLContent, type){
|
|
4
|
-
super({element : "div", name : ""})
|
|
5
|
-
this.element.append(type==="svg"?svg2dom(XMLContent):html2dom(XMLContent))
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
function html2dom(htmlString) {
|
|
9
|
-
if(globalThis?.DOMParser){
|
|
10
|
-
const parser = new DOMParser();
|
|
11
|
-
const doc = parser.parseFromString(`<div>${htmlString}</div>`, 'text/html');
|
|
12
|
-
doc.body.firstChild.style.display = "contents"
|
|
13
|
-
return doc.body.firstChild;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function svg2dom(svgString) {
|
|
17
|
-
if(globalThis?.DOMParser){
|
|
18
|
-
const parser = new DOMParser();
|
|
19
|
-
const doc = parser.parseFromString(svgString.replace(/\s+/g, ' ').trim(), 'image/svg+xml');
|
|
20
|
-
return doc.documentElement; // SVG elements are usually at the root
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
class ZikoUIHTMLWrapper extends ZikoUIXMLWrapper{
|
|
24
|
-
constructor(HTMLContent){
|
|
25
|
-
super(HTMLContent, "html")
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
class ZikoUISVGWrapper extends ZikoUIXMLWrapper{
|
|
29
|
-
constructor(SVGContent){
|
|
30
|
-
super(SVGContent, "svg")
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const HTMLWrapper = (HTMLContent) => new ZikoUIHTMLWrapper(HTMLContent);
|
|
34
|
-
const SVGWrapper = (SVGContent) => new ZikoUISVGWrapper(SVGContent);
|
|
35
|
-
|
|
36
|
-
export{
|
|
37
|
-
ZikoUIXMLWrapper,
|
|
38
|
-
ZikoUIHTMLWrapper,
|
|
39
|
-
ZikoUISVGWrapper,
|
|
40
|
-
HTMLWrapper,
|
|
41
|
-
SVGWrapper
|
|
42
|
-
}
|