ziko 0.0.15 → 0.0.17
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 +111 -17
- package/dist/ziko.js +116 -18
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +109 -19
- package/package.json +2 -2
- package/src/app/index.js +3 -2
- package/src/app/params.js +5 -5
- package/src/app/spa-file-based-routing.js +74 -0
- package/src/app/spa.js +1 -2
- package/src/app/ziko-app.js +2 -2
- package/src/index.js +2 -1
- package/src/ui/elements/primitives/misc/index.js +1 -0
- package/src/ui/elements/primitives/misc/xml-wrapper.js +37 -0
- package/src/ui/index.js +10 -1
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 : Sun Oct 13 2024 19:56:33 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
|
|
@@ -3877,7 +3877,7 @@ class ZikoHead{
|
|
|
3877
3877
|
}
|
|
3878
3878
|
}
|
|
3879
3879
|
|
|
3880
|
-
const useHead
|
|
3880
|
+
const useHead=({ title, lang, icon, meta, noscript })=>new ZikoHead({ title, lang, icon, meta, noscript });
|
|
3881
3881
|
|
|
3882
3882
|
const LightThemes={
|
|
3883
3883
|
cozyCottonCandy: {
|
|
@@ -5794,7 +5794,7 @@ const Hooks={
|
|
|
5794
5794
|
useTitle,
|
|
5795
5795
|
useFavIcon,
|
|
5796
5796
|
useMeta,
|
|
5797
|
-
useHead
|
|
5797
|
+
useHead,
|
|
5798
5798
|
useThrottle,
|
|
5799
5799
|
useDebounce,
|
|
5800
5800
|
useLocaleStorage,
|
|
@@ -7058,6 +7058,35 @@ class ZikoUIInputDateTime extends ZikoUIInput {
|
|
|
7058
7058
|
}
|
|
7059
7059
|
const inputDateTime = () => new ZikoUIInputDateTime();
|
|
7060
7060
|
|
|
7061
|
+
class ZikoUIXMLWrapper extends ZikoUIElement$1{
|
|
7062
|
+
constructor(XMLContent, type){
|
|
7063
|
+
super("div", "");
|
|
7064
|
+
this.element.append(type==="svg"?svg2dom(XMLContent):html2dom(XMLContent));
|
|
7065
|
+
}
|
|
7066
|
+
}
|
|
7067
|
+
function html2dom(htmlString) {
|
|
7068
|
+
const parser = new DOMParser();
|
|
7069
|
+
const doc = parser.parseFromString(`<div>${htmlString}</div>`, 'text/html');
|
|
7070
|
+
return doc.body.firstChild;
|
|
7071
|
+
}
|
|
7072
|
+
function svg2dom(svgString) {
|
|
7073
|
+
const parser = new DOMParser();
|
|
7074
|
+
const doc = parser.parseFromString(svgString, 'image/svg+xml');
|
|
7075
|
+
return doc.documentElement; // SVG elements are usually at the root
|
|
7076
|
+
}
|
|
7077
|
+
class ZikoUIHTMLWrapper extends ZikoUIXMLWrapper{
|
|
7078
|
+
constructor(HTMLContent){
|
|
7079
|
+
super(HTMLContent, "html");
|
|
7080
|
+
}
|
|
7081
|
+
}
|
|
7082
|
+
class ZikoUISVGWrapper extends ZikoUIXMLWrapper{
|
|
7083
|
+
constructor(SVGContent){
|
|
7084
|
+
super(SVGContent, "svg");
|
|
7085
|
+
}
|
|
7086
|
+
}
|
|
7087
|
+
const HTMLWrapper = (HTMLContent) => new ZikoUIHTMLWrapper(HTMLContent);
|
|
7088
|
+
const SVGWrapper = (SVGContent) => new ZikoUIHTMLWrapper(SVGContent);
|
|
7089
|
+
|
|
7061
7090
|
class ZikoUIHtmlTag extends ZikoUIContainerElement {
|
|
7062
7091
|
constructor(element) {
|
|
7063
7092
|
super(element,"html");
|
|
@@ -7146,10 +7175,15 @@ class ZikoUIBr extends ZikoUIElement$1 {
|
|
|
7146
7175
|
|
|
7147
7176
|
var Misc = /*#__PURE__*/Object.freeze({
|
|
7148
7177
|
__proto__: null,
|
|
7178
|
+
HTMLWrapper: HTMLWrapper,
|
|
7179
|
+
SVGWrapper: SVGWrapper,
|
|
7149
7180
|
ZikoUIBr: ZikoUIBr,
|
|
7181
|
+
ZikoUIHTMLWrapper: ZikoUIHTMLWrapper,
|
|
7150
7182
|
ZikoUIHr: ZikoUIHr,
|
|
7151
7183
|
ZikoUIHtmlTag: ZikoUIHtmlTag,
|
|
7152
7184
|
ZikoUILink: ZikoUILink,
|
|
7185
|
+
ZikoUISVGWrapper: ZikoUISVGWrapper,
|
|
7186
|
+
ZikoUIXMLWrapper: ZikoUIXMLWrapper,
|
|
7153
7187
|
br: br,
|
|
7154
7188
|
brs: brs,
|
|
7155
7189
|
btn: btn,
|
|
@@ -9509,7 +9543,9 @@ const UI$1 = {
|
|
|
9509
9543
|
...Table,
|
|
9510
9544
|
...Semantic,
|
|
9511
9545
|
...Misc,
|
|
9512
|
-
...Derived
|
|
9546
|
+
...Derived,
|
|
9547
|
+
ZikoUIElement: ZikoUIElement$1,
|
|
9548
|
+
ZikoUIContainerElement
|
|
9513
9549
|
};
|
|
9514
9550
|
|
|
9515
9551
|
const svg2str=svg=>(new XMLSerializer()).serializeToString(svg);
|
|
@@ -13273,7 +13309,7 @@ class ZikoApp {
|
|
|
13273
13309
|
this.head && this.setHead(this.head);
|
|
13274
13310
|
this.wrapper && this.setWrapper(this.wrapper);
|
|
13275
13311
|
this.target && this.setTarget(this.target);
|
|
13276
|
-
this.wrapper.render(this.target);
|
|
13312
|
+
if(this.wrapper && this.target)this.wrapper.render(this.target);
|
|
13277
13313
|
}
|
|
13278
13314
|
setTarget(target){
|
|
13279
13315
|
if(target instanceof HTMLElement) this.target = target;
|
|
@@ -13416,8 +13452,6 @@ function isDynamic(path) {
|
|
|
13416
13452
|
class ZikoSPA extends ZikoApp{
|
|
13417
13453
|
constructor({head, wrapper, target, routes}){
|
|
13418
13454
|
super({head, wrapper, target});
|
|
13419
|
-
// this.wrapper=wrapper;
|
|
13420
|
-
console.log(target);
|
|
13421
13455
|
this.routes=new Map([
|
|
13422
13456
|
["404",text$1("Error 404")],
|
|
13423
13457
|
...Object.entries(routes)
|
|
@@ -13444,6 +13478,7 @@ class ZikoSPA extends ZikoApp{
|
|
|
13444
13478
|
if(typeof callback === "function") element = callback();
|
|
13445
13479
|
}
|
|
13446
13480
|
if(element?.isZikoUIElement) element.render(this.wrapper);
|
|
13481
|
+
// if(element?.isZikoApp) element.render(this.wrapper);
|
|
13447
13482
|
if(element instanceof Promise){
|
|
13448
13483
|
element.then(e=>e.render(this.wrapper));
|
|
13449
13484
|
}
|
|
@@ -13468,7 +13503,7 @@ var Spa = /*#__PURE__*/Object.freeze({
|
|
|
13468
13503
|
ZikoSPA: ZikoSPA
|
|
13469
13504
|
});
|
|
13470
13505
|
|
|
13471
|
-
function
|
|
13506
|
+
function parseQueryParams(queryString) {
|
|
13472
13507
|
const params = {};
|
|
13473
13508
|
queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
|
|
13474
13509
|
const [key, value] = match.split('=');
|
|
@@ -13477,19 +13512,19 @@ function parseParams(queryString) {
|
|
|
13477
13512
|
return params;
|
|
13478
13513
|
}
|
|
13479
13514
|
|
|
13480
|
-
function defineParamsGetter(target
|
|
13515
|
+
function defineParamsGetter(target ){
|
|
13481
13516
|
Object.defineProperties(target, {
|
|
13482
13517
|
'QueryParams': {
|
|
13483
13518
|
get: function() {
|
|
13484
|
-
return
|
|
13519
|
+
return parseQueryParams(globalThis.location.search.substring(1));
|
|
13485
13520
|
},
|
|
13486
13521
|
configurable: false,
|
|
13487
13522
|
enumerable: true
|
|
13488
13523
|
},
|
|
13489
13524
|
'HashParams': {
|
|
13490
13525
|
get: function() {
|
|
13491
|
-
const hash =
|
|
13492
|
-
return
|
|
13526
|
+
const hash = globalThis.location.hash.substring(1);
|
|
13527
|
+
return hash.split("#");
|
|
13493
13528
|
},
|
|
13494
13529
|
configurable: false,
|
|
13495
13530
|
enumerable: true
|
|
@@ -13497,11 +13532,6 @@ function defineParamsGetter(target = globalThis){
|
|
|
13497
13532
|
});
|
|
13498
13533
|
}
|
|
13499
13534
|
|
|
13500
|
-
var Params = /*#__PURE__*/Object.freeze({
|
|
13501
|
-
__proto__: null,
|
|
13502
|
-
defineParamsGetter: defineParamsGetter
|
|
13503
|
-
});
|
|
13504
|
-
|
|
13505
13535
|
const __UI__={};
|
|
13506
13536
|
const __Config__={
|
|
13507
13537
|
default:{
|
|
@@ -13525,12 +13555,71 @@ var Global = /*#__PURE__*/Object.freeze({
|
|
|
13525
13555
|
__UI__: __UI__
|
|
13526
13556
|
});
|
|
13527
13557
|
|
|
13558
|
+
// import.meta.glob('./src/pages/**/*.js')
|
|
13559
|
+
async function FileBasedRouting(pages /* use import.meta.glob */){
|
|
13560
|
+
const routes = Object.keys(pages);
|
|
13561
|
+
const root = findCommonPath(routes);
|
|
13562
|
+
// console.log({root})
|
|
13563
|
+
const pairs = {};
|
|
13564
|
+
for(let i=0; i<routes.length; i++){
|
|
13565
|
+
const module = await pages[routes[i]]();
|
|
13566
|
+
const component = await module.default;
|
|
13567
|
+
Object.assign(pairs,{[customPath(routes[i], root)]:component});
|
|
13568
|
+
}
|
|
13569
|
+
return SPA({
|
|
13570
|
+
target : document.body,
|
|
13571
|
+
routes : {
|
|
13572
|
+
"/" : ()=>{},
|
|
13573
|
+
...pairs
|
|
13574
|
+
},
|
|
13575
|
+
wrapper : Section()
|
|
13576
|
+
})
|
|
13577
|
+
}
|
|
13578
|
+
function customPath(inputPath, root = './src/pages', extensions = ['js', 'ts']) {
|
|
13579
|
+
if(root.at(-1)==="/") root = root.slice(0, -1);
|
|
13580
|
+
const normalizedPath = inputPath.replace(/\\/g, '/').replace(/\[(\w+)\]/g, '$1/:$1');
|
|
13581
|
+
const parts = normalizedPath.split('/');
|
|
13582
|
+
const rootParts = root.split('/');
|
|
13583
|
+
const rootIndex = parts.indexOf(rootParts[rootParts.length - 1]);
|
|
13584
|
+
if (rootIndex !== -1) {
|
|
13585
|
+
const subsequentParts = parts.slice(rootIndex + 1);
|
|
13586
|
+
const lastPart = subsequentParts[subsequentParts.length - 1];
|
|
13587
|
+
const isIndexFile = lastPart === 'index.js' || lastPart === 'index.ts';
|
|
13588
|
+
const hasValidExtension = extensions.some(ext => lastPart === `.${ext}` || lastPart.endsWith(`.${ext}`));
|
|
13589
|
+
if (isIndexFile) {
|
|
13590
|
+
return '/' + (subsequentParts.length > 1 ? subsequentParts.slice(0, -1).join('/') : '');
|
|
13591
|
+
}
|
|
13592
|
+
if (hasValidExtension) {
|
|
13593
|
+
return '/' + subsequentParts.join('/').replace(/\.(js|ts)$/, '');
|
|
13594
|
+
}
|
|
13595
|
+
}
|
|
13596
|
+
return '';
|
|
13597
|
+
}
|
|
13598
|
+
function findCommonPath(paths) {
|
|
13599
|
+
if (paths.length === 0) return '';
|
|
13600
|
+
const splitPaths = paths.map(path => path.split('/'));
|
|
13601
|
+
const minLength = Math.min(...splitPaths.map(parts => parts.length));
|
|
13602
|
+
let commonParts = [];
|
|
13603
|
+
for (let i = 0; i < minLength; i++) {
|
|
13604
|
+
const part = splitPaths[0][i];
|
|
13605
|
+
if (splitPaths.every(parts => parts[i] === part || parts[i].startsWith('['))) {
|
|
13606
|
+
commonParts.push(part);
|
|
13607
|
+
} else {
|
|
13608
|
+
break;
|
|
13609
|
+
}
|
|
13610
|
+
}
|
|
13611
|
+
const commonPath = commonParts.join('/') + (commonParts.length ? '/' : '');
|
|
13612
|
+
return commonPath;
|
|
13613
|
+
}
|
|
13614
|
+
|
|
13615
|
+
// import * as Params from "./params"
|
|
13616
|
+
|
|
13528
13617
|
const App={
|
|
13529
13618
|
...__App__,
|
|
13530
13619
|
...JsonStyleSheet,
|
|
13531
13620
|
...Spa,
|
|
13532
13621
|
...Global,
|
|
13533
|
-
...Params
|
|
13622
|
+
// ...Params
|
|
13534
13623
|
};
|
|
13535
13624
|
|
|
13536
13625
|
[
|
|
@@ -13566,6 +13655,7 @@ if ( globalThis.__Ziko__ ) {
|
|
|
13566
13655
|
ExtractAll,
|
|
13567
13656
|
RemoveAll
|
|
13568
13657
|
};
|
|
13658
|
+
defineParamsGetter(__Ziko__);
|
|
13569
13659
|
}
|
|
13570
13660
|
// globalThis.__Ziko__={
|
|
13571
13661
|
// ...Ziko,
|
|
@@ -13595,4 +13685,4 @@ function RemoveAll(){
|
|
|
13595
13685
|
Data.RemoveAll();
|
|
13596
13686
|
}
|
|
13597
13687
|
|
|
13598
|
-
export { Accordion, App$1 as App, Article, Aside, Base, Breadcrumbs, Canvas, Carousel, CodeCell, CodeNote, Collapsible, Combinaison, Complex, E, EPSILON, Ease, Flex$1 as Flex, Footer, Form, Grid$1 as Grid, Header, LinearSystem, Logic$1 as Logic, Main, Matrix, Modal, Nav, PI, Permutation, Random, SPA, Section, Signal, Slider, Splitter, Str, Svg, Table$1 as Table, Tabs, Utils$1 as Utils, ZikoApp, ZikoJsonStyleSheet, ZikoMutationObserver, ZikoSPA, ZikoUIAbbrText, ZikoUIAccordion, ZikoUIArticle, ZikoUIAside, ZikoUIAudio, ZikoUIBlockQuote, ZikoUIBr, ZikoUIBreadcrumbs, ZikoUICanvas, ZikoUICodeNote, ZikoUICodeText, ZikoUIDefintion, ZikoUIFigure, ZikoUIFlex$1 as ZikoUIFlex, ZikoUIFooter, ZikoUIForm, ZikoUIGrid, ZikoUIHeader, ZikoUIHeading, ZikoUIHorizontalSlider, ZikoUIHorizontalSplitter, ZikoUIHr, ZikoUIHtmlTag, ZikoUIImage, ZikoUIInput, ZikoUIInputCheckbox, ZikoUIInputColor, ZikoUIInputDatalist$1 as ZikoUIInputDatalist, ZikoUIInputDate, ZikoUIInputDateTime, ZikoUIInputEmail, ZikoUIInputImage, ZikoUIInputNumber, ZikoUIInputOption, ZikoUIInputPassword, ZikoUIInputRadio, ZikoUIInputSearch, ZikoUIInputSlider$1 as ZikoUIInputSlider, ZikoUIInputTime, ZikoUILabel, ZikoUILink, ZikoUIMain, ZikoUIMenu3d, ZikoUIModal, ZikoUINav, ZikoUIParagraphe, ZikoUIQuote, ZikoUISection, ZikoUISelect, ZikoUISubText, ZikoUISupText, ZikoUISvg, ZikoUIText, ZikoUITextArea, ZikoUIVerticalSlider, ZikoUIVerticalSplitter, ZikoUIVideo, __Config__, __UI__, abbrText, abs, accum, acos, acosh, acot, add, adoc2html, arange, arr2str, asin, asinh, atan, atan2, atanh, audio, bessel, beta, blockQuote, br, brs, btn, canvasArc, canvasCircle, canvasLine, canvasPoints, canvasRect, cartesianProduct, ceil, checkbox, choleskyDecomposition, clamp, codeText, combinaison, complex, cos, cosh, cot, coth, count, countWords, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, dangerAlert, datalist, Ziko as default, defineParamsGetter, deg2rad, dfnText, div, e, fact, figure, floor, gamma, geomspace, h1, h2, h3, h4, h5, h6, hSlider, hSplitter, hr, hrs, html, hypot, image, inRange, infoAlert, input, inputCamera, inputColor, inputDate, inputDateTime, inputEmail, inputImage, inputNumber, inputPassword, inputTime, isApproximatlyEqual, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, jsonStyleSheet, lerp, li, link, linspace, ln, logspace, luDecomposition, map, mapfun$1 as mapfun, markdown2html, matrix, matrix2, matrix3, matrix4, max, menu3d, min, modulo, mul, norm, nums, obj2str, ol, ones, p, pgcd, pow, powerSet, ppcm, preload, prod, qrDecomposition, quote, rad2deg, radio, removeExtraSpace, round, search, sec, select, sig, sign, sin, sinc, sinh, slider, sqrt, sqrtn, str, sub, subSet, subText, successAlert, sum, supText, svg2ascii, svg2img, svg2imgUrl, svg2str, svgCircle, svgEllipse, svgGrid, svgGroupe, svgImage, svgLine, svgLink, svgObject, svgPath, svgPolyLine, svgPolygon, svgRect, svgText, tan, tanh, text$1 as text, textarea, timeTaken, time_memory_Taken, ul, useAnimation, useBattery, useBluetooth, useChannel, useClickEvent, useClipboardEvent, useCustomEvent, useDebounce, useDragEvent, useDropEvent, useEventEmitter, useFavIcon, useFocusEvent, useFps, useGeolocation, useHashEvent, useInputEvent, useKeyEvent, useLocaleStorage, useMediaQuery, useMouseEvent, usePointerEvent, useSessionStorage, useStyle, useSuccesifKeys, useSwipeEvent, useTheme, useThread, useThrottle, useTimeLoop, useTitle, useWheelEvent, vSlider, vSplitter, video, wait, waitForUIElm, waitForUIElmSync, warningAlert, watch, watchAttr, watchChildren, watchIntersection, watchScreen, watchSize, zeros };
|
|
13688
|
+
export { Accordion, App$1 as App, Article, Aside, Base, Breadcrumbs, Canvas, Carousel, CodeCell, CodeNote, Collapsible, Combinaison, Complex, E, EPSILON, Ease, FileBasedRouting, Flex$1 as Flex, Footer, Form, Grid$1 as Grid, HTMLWrapper, Header, LinearSystem, Logic$1 as Logic, Main, Matrix, Modal, Nav, PI, Permutation, Random, SPA, SVGWrapper, Section, Signal, Slider, Splitter, Str, Svg, Table$1 as Table, Tabs, Utils$1 as Utils, ZikoApp, ZikoJsonStyleSheet, ZikoMutationObserver, ZikoSPA, ZikoUIAbbrText, ZikoUIAccordion, ZikoUIArticle, ZikoUIAside, ZikoUIAudio, ZikoUIBlockQuote, ZikoUIBr, ZikoUIBreadcrumbs, ZikoUICanvas, ZikoUICodeNote, ZikoUICodeText, ZikoUIContainerElement, ZikoUIDefintion, ZikoUIElement$1 as ZikoUIElement, ZikoUIFigure, ZikoUIFlex$1 as ZikoUIFlex, ZikoUIFooter, ZikoUIForm, ZikoUIGrid, ZikoUIHTMLWrapper, ZikoUIHeader, ZikoUIHeading, ZikoUIHorizontalSlider, ZikoUIHorizontalSplitter, ZikoUIHr, ZikoUIHtmlTag, ZikoUIImage, ZikoUIInput, ZikoUIInputCheckbox, ZikoUIInputColor, ZikoUIInputDatalist$1 as ZikoUIInputDatalist, ZikoUIInputDate, ZikoUIInputDateTime, ZikoUIInputEmail, ZikoUIInputImage, ZikoUIInputNumber, ZikoUIInputOption, ZikoUIInputPassword, ZikoUIInputRadio, ZikoUIInputSearch, ZikoUIInputSlider$1 as ZikoUIInputSlider, ZikoUIInputTime, ZikoUILabel, ZikoUILink, ZikoUIMain, ZikoUIMenu3d, ZikoUIModal, ZikoUINav, ZikoUIParagraphe, ZikoUIQuote, ZikoUISVGWrapper, ZikoUISection, ZikoUISelect, ZikoUISubText, ZikoUISupText, ZikoUISvg, ZikoUIText, ZikoUITextArea, ZikoUIVerticalSlider, ZikoUIVerticalSplitter, ZikoUIVideo, ZikoUIXMLWrapper, __Config__, __UI__, abbrText, abs, accum, acos, acosh, acot, add, adoc2html, arange, arr2str, asin, asinh, atan, atan2, atanh, audio, bessel, beta, blockQuote, br, brs, btn, canvasArc, canvasCircle, canvasLine, canvasPoints, canvasRect, cartesianProduct, ceil, checkbox, choleskyDecomposition, clamp, codeText, combinaison, complex, cos, cosh, cot, coth, count, countWords, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, dangerAlert, datalist, Ziko as default, defineParamsGetter, deg2rad, dfnText, div, e, fact, figure, floor, gamma, geomspace, h1, h2, h3, h4, h5, h6, hSlider, hSplitter, hr, hrs, html, hypot, image, inRange, infoAlert, input, inputCamera, inputColor, inputDate, inputDateTime, inputEmail, inputImage, inputNumber, inputPassword, inputTime, isApproximatlyEqual, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, jsonStyleSheet, lerp, li, link, linspace, ln, logspace, luDecomposition, map, mapfun$1 as mapfun, markdown2html, matrix, matrix2, matrix3, matrix4, max, menu3d, min, modulo, mul, norm, nums, obj2str, ol, ones, p, pgcd, pow, powerSet, ppcm, preload, prod, qrDecomposition, quote, rad2deg, radio, removeExtraSpace, round, search, sec, select, sig, sign, sin, sinc, sinh, slider, sqrt, sqrtn, str, sub, subSet, subText, successAlert, sum, supText, svg2ascii, svg2img, svg2imgUrl, svg2str, svgCircle, svgEllipse, svgGrid, svgGroupe, svgImage, svgLine, svgLink, svgObject, svgPath, svgPolyLine, svgPolygon, svgRect, svgText, tan, tanh, text$1 as text, textarea, timeTaken, time_memory_Taken, ul, useAnimation, useBattery, useBluetooth, useChannel, useClickEvent, useClipboardEvent, useCustomEvent, useDebounce, useDragEvent, useDropEvent, useEventEmitter, useFavIcon, useFocusEvent, useFps, useGeolocation, useHashEvent, useInputEvent, useKeyEvent, useLocaleStorage, useMediaQuery, useMouseEvent, usePointerEvent, useSessionStorage, useStyle, useSuccesifKeys, useSwipeEvent, useTheme, useThread, useThrottle, useTimeLoop, useTitle, useWheelEvent, vSlider, vSplitter, video, wait, waitForUIElm, waitForUIElmSync, warningAlert, watch, watchAttr, watchChildren, watchIntersection, watchScreen, watchSize, zeros };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ziko",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "a versatile JavaScript library offering a rich set of UI components, advanced mathematical utilities,Reactivity,animations,client side routing and graphics capabilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Zikojs",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
|
-
"import": "./
|
|
28
|
+
"import": "./src/index.js",
|
|
29
29
|
"require": "./dist/ziko.cjs"
|
|
30
30
|
},
|
|
31
31
|
"./type": {
|
package/src/app/index.js
CHANGED
|
@@ -3,18 +3,19 @@ export * from "./json-style-sheet";
|
|
|
3
3
|
export * from "./spa"
|
|
4
4
|
export * from "./params"
|
|
5
5
|
export * from "./globals"
|
|
6
|
+
export * from "./spa-file-based-routing"
|
|
6
7
|
|
|
7
8
|
import * as __App__ from "./ziko-app"
|
|
8
9
|
import * as JsonStyleSheet from "./json-style-sheet"
|
|
9
10
|
import * as Spa from "./spa"
|
|
10
11
|
import * as Global from "./globals"
|
|
11
|
-
import * as Params from "./params"
|
|
12
|
+
// import * as Params from "./params"
|
|
12
13
|
|
|
13
14
|
const App={
|
|
14
15
|
...__App__,
|
|
15
16
|
...JsonStyleSheet,
|
|
16
17
|
...Spa,
|
|
17
18
|
...Global,
|
|
18
|
-
...Params
|
|
19
|
+
// ...Params
|
|
19
20
|
}
|
|
20
21
|
export default App
|
package/src/app/params.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function parseQueryParams(queryString) {
|
|
2
2
|
const params = {};
|
|
3
3
|
queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
|
|
4
4
|
const [key, value] = match.split('=');
|
|
@@ -7,19 +7,19 @@ function parseParams(queryString) {
|
|
|
7
7
|
return params;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
function defineParamsGetter(target
|
|
10
|
+
function defineParamsGetter(target ){
|
|
11
11
|
Object.defineProperties(target, {
|
|
12
12
|
'QueryParams': {
|
|
13
13
|
get: function() {
|
|
14
|
-
return
|
|
14
|
+
return parseQueryParams(globalThis.location.search.substring(1));
|
|
15
15
|
},
|
|
16
16
|
configurable: false,
|
|
17
17
|
enumerable: true
|
|
18
18
|
},
|
|
19
19
|
'HashParams': {
|
|
20
20
|
get: function() {
|
|
21
|
-
const hash =
|
|
22
|
-
return
|
|
21
|
+
const hash = globalThis.location.hash.substring(1);
|
|
22
|
+
return hash.split("#");
|
|
23
23
|
},
|
|
24
24
|
configurable: false,
|
|
25
25
|
enumerable: true
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { SPA } from "./spa";
|
|
2
|
+
import { Section } from "../ui";
|
|
3
|
+
// import.meta.glob('./src/pages/**/*.js')
|
|
4
|
+
async function FileBasedRouting(pages /* use import.meta.glob */){
|
|
5
|
+
const routes = Object.keys(pages)
|
|
6
|
+
const root = findCommonPath(routes)
|
|
7
|
+
// console.log({root})
|
|
8
|
+
const pairs = {}
|
|
9
|
+
for(let i=0; i<routes.length; i++){
|
|
10
|
+
const module = await pages[routes[i]]()
|
|
11
|
+
const component = await module.default
|
|
12
|
+
Object.assign(pairs,{[customPath(routes[i], root)]:component})
|
|
13
|
+
}
|
|
14
|
+
return SPA({
|
|
15
|
+
target : document.body,
|
|
16
|
+
routes : {
|
|
17
|
+
"/" : ()=>{},
|
|
18
|
+
...pairs
|
|
19
|
+
},
|
|
20
|
+
wrapper : Section()
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
function customPath(inputPath, root = './src/pages', extensions = ['js', 'ts']) {
|
|
24
|
+
if(root.at(-1)==="/") root = root.slice(0, -1)
|
|
25
|
+
const normalizedPath = inputPath.replace(/\\/g, '/').replace(/\[(\w+)\]/g, '$1/:$1');
|
|
26
|
+
const parts = normalizedPath.split('/');
|
|
27
|
+
const rootParts = root.split('/');
|
|
28
|
+
const rootIndex = parts.indexOf(rootParts[rootParts.length - 1]);
|
|
29
|
+
if (rootIndex !== -1) {
|
|
30
|
+
const subsequentParts = parts.slice(rootIndex + 1);
|
|
31
|
+
const lastPart = subsequentParts[subsequentParts.length - 1];
|
|
32
|
+
const isIndexFile = lastPart === 'index.js' || lastPart === 'index.ts';
|
|
33
|
+
const hasValidExtension = extensions.some(ext => lastPart === `.${ext}` || lastPart.endsWith(`.${ext}`));
|
|
34
|
+
if (isIndexFile) {
|
|
35
|
+
return '/' + (subsequentParts.length > 1 ? subsequentParts.slice(0, -1).join('/') : '');
|
|
36
|
+
}
|
|
37
|
+
if (hasValidExtension) {
|
|
38
|
+
return '/' + subsequentParts.join('/').replace(/\.(js|ts)$/, '');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
function findCommonPath(paths) {
|
|
44
|
+
if (paths.length === 0) return '';
|
|
45
|
+
const splitPaths = paths.map(path => path.split('/'));
|
|
46
|
+
const minLength = Math.min(...splitPaths.map(parts => parts.length));
|
|
47
|
+
let commonParts = [];
|
|
48
|
+
for (let i = 0; i < minLength; i++) {
|
|
49
|
+
const part = splitPaths[0][i];
|
|
50
|
+
if (splitPaths.every(parts => parts[i] === part || parts[i].startsWith('['))) {
|
|
51
|
+
commonParts.push(part);
|
|
52
|
+
} else {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const commonPath = commonParts.join('/') + (commonParts.length ? '/' : '');
|
|
57
|
+
return commonPath;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// // Example usage
|
|
61
|
+
// const inputPaths = [
|
|
62
|
+
// './src/pages/[blog]/[lang]/index.js',
|
|
63
|
+
// './src/pages/[blog]/index.js',
|
|
64
|
+
// './src/pages/about.js',
|
|
65
|
+
// './src/pages/articles/[data]/[color]/index.js',
|
|
66
|
+
// './src/pages/articles/a1.js',
|
|
67
|
+
// './src/pages/index.js',
|
|
68
|
+
// './src/pages/me.js'
|
|
69
|
+
// ];
|
|
70
|
+
|
|
71
|
+
// console.log(findCommonPath(inputPaths)); // Output: './src/pages/'
|
|
72
|
+
export{
|
|
73
|
+
FileBasedRouting,
|
|
74
|
+
}
|
package/src/app/spa.js
CHANGED
|
@@ -4,8 +4,6 @@ import { ZikoApp } from "./ziko-app";
|
|
|
4
4
|
class ZikoSPA extends ZikoApp{
|
|
5
5
|
constructor({head, wrapper, target, routes}){
|
|
6
6
|
super({head, wrapper, target})
|
|
7
|
-
// this.wrapper=wrapper;
|
|
8
|
-
console.log(target)
|
|
9
7
|
this.routes=new Map([
|
|
10
8
|
["404",text("Error 404")],
|
|
11
9
|
...Object.entries(routes)
|
|
@@ -32,6 +30,7 @@ class ZikoSPA extends ZikoApp{
|
|
|
32
30
|
if(typeof callback === "function") element = callback();
|
|
33
31
|
}
|
|
34
32
|
if(element?.isZikoUIElement) element.render(this.wrapper);
|
|
33
|
+
// if(element?.isZikoApp) element.render(this.wrapper);
|
|
35
34
|
if(element instanceof Promise){
|
|
36
35
|
element.then(e=>e.render(this.wrapper))
|
|
37
36
|
}
|
package/src/app/ziko-app.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ZikoHead } from "../reactivity/hooks/Head";
|
|
1
|
+
import { ZikoHead , useHead} from "../reactivity/hooks/Head";
|
|
2
2
|
class ZikoApp {
|
|
3
3
|
constructor({head = null, wrapper = null, target = null}){
|
|
4
4
|
this.head = head;
|
|
@@ -13,7 +13,7 @@ class ZikoApp {
|
|
|
13
13
|
this.head && this.setHead(this.head);
|
|
14
14
|
this.wrapper && this.setWrapper(this.wrapper);
|
|
15
15
|
this.target && this.setTarget(this.target);
|
|
16
|
-
this.wrapper.render(this.target);
|
|
16
|
+
if(this.wrapper && this.target)this.wrapper.render(this.target);
|
|
17
17
|
}
|
|
18
18
|
setTarget(target){
|
|
19
19
|
if(target instanceof HTMLElement) this.target = target;
|
package/src/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import Time from "./time";
|
|
|
5
5
|
import Data from "./data";
|
|
6
6
|
import Reactivity from "./reactivity";
|
|
7
7
|
import Graphics from "./graphics";
|
|
8
|
-
import App,{__UI__, __Config__} from "./app";
|
|
8
|
+
import App,{__UI__, __Config__, defineParamsGetter} from "./app";
|
|
9
9
|
|
|
10
10
|
export * from "./math";
|
|
11
11
|
export * from "./ui";
|
|
@@ -48,6 +48,7 @@ if ( globalThis.__Ziko__ ) {
|
|
|
48
48
|
ExtractAll,
|
|
49
49
|
RemoveAll
|
|
50
50
|
};
|
|
51
|
+
defineParamsGetter(__Ziko__)
|
|
51
52
|
}
|
|
52
53
|
// globalThis.__Ziko__={
|
|
53
54
|
// ...Ziko,
|
|
@@ -85,6 +85,7 @@ class ZikoUIBr extends ZikoUIElement {
|
|
|
85
85
|
const link=(href,...UIElement)=>new ZikoUILink(href).append(...UIElement);
|
|
86
86
|
const html=(tag,...UIElement)=>new ZikoUIHtmlTag(tag).append(...UIElement);
|
|
87
87
|
const btn = (value) => new ZikoUIBtn(value);
|
|
88
|
+
export * from "./xml-wrapper.js"
|
|
88
89
|
export{
|
|
89
90
|
html,
|
|
90
91
|
btn,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import ZikoUIElement from "../ZikoUIElement";
|
|
2
|
+
class ZikoUIXMLWrapper extends ZikoUIElement{
|
|
3
|
+
constructor(XMLContent, type){
|
|
4
|
+
super("div", "")
|
|
5
|
+
this.element.append(type==="svg"?svg2dom(XMLContent):html2dom(XMLContent))
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function html2dom(htmlString) {
|
|
9
|
+
const parser = new DOMParser();
|
|
10
|
+
const doc = parser.parseFromString(`<div>${htmlString}</div>`, 'text/html');
|
|
11
|
+
return doc.body.firstChild;
|
|
12
|
+
}
|
|
13
|
+
function svg2dom(svgString) {
|
|
14
|
+
const parser = new DOMParser();
|
|
15
|
+
const doc = parser.parseFromString(svgString, 'image/svg+xml');
|
|
16
|
+
return doc.documentElement; // SVG elements are usually at the root
|
|
17
|
+
}
|
|
18
|
+
class ZikoUIHTMLWrapper extends ZikoUIXMLWrapper{
|
|
19
|
+
constructor(HTMLContent){
|
|
20
|
+
super(HTMLContent, "html")
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class ZikoUISVGWrapper extends ZikoUIXMLWrapper{
|
|
24
|
+
constructor(SVGContent){
|
|
25
|
+
super(SVGContent, "svg")
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const HTMLWrapper = (HTMLContent) => new ZikoUIHTMLWrapper(HTMLContent);
|
|
29
|
+
const SVGWrapper = (SVGContent) => new ZikoUIHTMLWrapper(SVGContent);
|
|
30
|
+
|
|
31
|
+
export{
|
|
32
|
+
ZikoUIXMLWrapper,
|
|
33
|
+
ZikoUIHTMLWrapper,
|
|
34
|
+
ZikoUISVGWrapper,
|
|
35
|
+
HTMLWrapper,
|
|
36
|
+
SVGWrapper
|
|
37
|
+
}
|
package/src/ui/index.js
CHANGED
|
@@ -16,6 +16,13 @@ import * as Semantic from "./elements/primitives/semantic";
|
|
|
16
16
|
import * as Misc from "./elements/primitives/misc";
|
|
17
17
|
import * as Derived from "./elements/derived";
|
|
18
18
|
|
|
19
|
+
import ZikoUIElement from "./elements/primitives/ZikoUIElement";
|
|
20
|
+
import ZikoUIContainerElement from "./elements/primitives/ZikoUIContainerElement";
|
|
21
|
+
|
|
22
|
+
export{
|
|
23
|
+
ZikoUIContainerElement,
|
|
24
|
+
ZikoUIElement
|
|
25
|
+
}
|
|
19
26
|
const UI = {
|
|
20
27
|
...Text,
|
|
21
28
|
...List,
|
|
@@ -24,6 +31,8 @@ const UI = {
|
|
|
24
31
|
...Table,
|
|
25
32
|
...Semantic,
|
|
26
33
|
...Misc,
|
|
27
|
-
...Derived
|
|
34
|
+
...Derived,
|
|
35
|
+
ZikoUIElement,
|
|
36
|
+
ZikoUIContainerElement
|
|
28
37
|
}
|
|
29
38
|
export default UI;
|