ziko 0.0.15 → 0.0.16
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 +111 -17
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +106 -18
- package/package.json +1 -1
- 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/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 15:43:24 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,
|
|
@@ -13273,7 +13307,7 @@ class ZikoApp {
|
|
|
13273
13307
|
this.head && this.setHead(this.head);
|
|
13274
13308
|
this.wrapper && this.setWrapper(this.wrapper);
|
|
13275
13309
|
this.target && this.setTarget(this.target);
|
|
13276
|
-
this.wrapper.render(this.target);
|
|
13310
|
+
if(this.wrapper && this.target)this.wrapper.render(this.target);
|
|
13277
13311
|
}
|
|
13278
13312
|
setTarget(target){
|
|
13279
13313
|
if(target instanceof HTMLElement) this.target = target;
|
|
@@ -13416,8 +13450,6 @@ function isDynamic(path) {
|
|
|
13416
13450
|
class ZikoSPA extends ZikoApp{
|
|
13417
13451
|
constructor({head, wrapper, target, routes}){
|
|
13418
13452
|
super({head, wrapper, target});
|
|
13419
|
-
// this.wrapper=wrapper;
|
|
13420
|
-
console.log(target);
|
|
13421
13453
|
this.routes=new Map([
|
|
13422
13454
|
["404",text$1("Error 404")],
|
|
13423
13455
|
...Object.entries(routes)
|
|
@@ -13444,6 +13476,7 @@ class ZikoSPA extends ZikoApp{
|
|
|
13444
13476
|
if(typeof callback === "function") element = callback();
|
|
13445
13477
|
}
|
|
13446
13478
|
if(element?.isZikoUIElement) element.render(this.wrapper);
|
|
13479
|
+
// if(element?.isZikoApp) element.render(this.wrapper);
|
|
13447
13480
|
if(element instanceof Promise){
|
|
13448
13481
|
element.then(e=>e.render(this.wrapper));
|
|
13449
13482
|
}
|
|
@@ -13468,7 +13501,7 @@ var Spa = /*#__PURE__*/Object.freeze({
|
|
|
13468
13501
|
ZikoSPA: ZikoSPA
|
|
13469
13502
|
});
|
|
13470
13503
|
|
|
13471
|
-
function
|
|
13504
|
+
function parseQueryParams(queryString) {
|
|
13472
13505
|
const params = {};
|
|
13473
13506
|
queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
|
|
13474
13507
|
const [key, value] = match.split('=');
|
|
@@ -13477,19 +13510,19 @@ function parseParams(queryString) {
|
|
|
13477
13510
|
return params;
|
|
13478
13511
|
}
|
|
13479
13512
|
|
|
13480
|
-
function defineParamsGetter(target
|
|
13513
|
+
function defineParamsGetter(target ){
|
|
13481
13514
|
Object.defineProperties(target, {
|
|
13482
13515
|
'QueryParams': {
|
|
13483
13516
|
get: function() {
|
|
13484
|
-
return
|
|
13517
|
+
return parseQueryParams(globalThis.location.search.substring(1));
|
|
13485
13518
|
},
|
|
13486
13519
|
configurable: false,
|
|
13487
13520
|
enumerable: true
|
|
13488
13521
|
},
|
|
13489
13522
|
'HashParams': {
|
|
13490
13523
|
get: function() {
|
|
13491
|
-
const hash =
|
|
13492
|
-
return
|
|
13524
|
+
const hash = globalThis.location.hash.substring(1);
|
|
13525
|
+
return hash.split("#");
|
|
13493
13526
|
},
|
|
13494
13527
|
configurable: false,
|
|
13495
13528
|
enumerable: true
|
|
@@ -13497,11 +13530,6 @@ function defineParamsGetter(target = globalThis){
|
|
|
13497
13530
|
});
|
|
13498
13531
|
}
|
|
13499
13532
|
|
|
13500
|
-
var Params = /*#__PURE__*/Object.freeze({
|
|
13501
|
-
__proto__: null,
|
|
13502
|
-
defineParamsGetter: defineParamsGetter
|
|
13503
|
-
});
|
|
13504
|
-
|
|
13505
13533
|
const __UI__={};
|
|
13506
13534
|
const __Config__={
|
|
13507
13535
|
default:{
|
|
@@ -13525,12 +13553,71 @@ var Global = /*#__PURE__*/Object.freeze({
|
|
|
13525
13553
|
__UI__: __UI__
|
|
13526
13554
|
});
|
|
13527
13555
|
|
|
13556
|
+
// import.meta.glob('./src/pages/**/*.js')
|
|
13557
|
+
async function FileBasedRouting(pages /* use import.meta.glob */){
|
|
13558
|
+
const routes = Object.keys(pages);
|
|
13559
|
+
const root = findCommonPath(routes);
|
|
13560
|
+
// console.log({root})
|
|
13561
|
+
const pairs = {};
|
|
13562
|
+
for(let i=0; i<routes.length; i++){
|
|
13563
|
+
const module = await pages[routes[i]]();
|
|
13564
|
+
const component = await module.default;
|
|
13565
|
+
Object.assign(pairs,{[customPath(routes[i], root)]:component});
|
|
13566
|
+
}
|
|
13567
|
+
return SPA({
|
|
13568
|
+
target : document.body,
|
|
13569
|
+
routes : {
|
|
13570
|
+
"/" : ()=>{},
|
|
13571
|
+
...pairs
|
|
13572
|
+
},
|
|
13573
|
+
wrapper : Section()
|
|
13574
|
+
})
|
|
13575
|
+
}
|
|
13576
|
+
function customPath(inputPath, root = './src/pages', extensions = ['js', 'ts']) {
|
|
13577
|
+
if(root.at(-1)==="/") root = root.slice(0, -1);
|
|
13578
|
+
const normalizedPath = inputPath.replace(/\\/g, '/').replace(/\[(\w+)\]/g, '$1/:$1');
|
|
13579
|
+
const parts = normalizedPath.split('/');
|
|
13580
|
+
const rootParts = root.split('/');
|
|
13581
|
+
const rootIndex = parts.indexOf(rootParts[rootParts.length - 1]);
|
|
13582
|
+
if (rootIndex !== -1) {
|
|
13583
|
+
const subsequentParts = parts.slice(rootIndex + 1);
|
|
13584
|
+
const lastPart = subsequentParts[subsequentParts.length - 1];
|
|
13585
|
+
const isIndexFile = lastPart === 'index.js' || lastPart === 'index.ts';
|
|
13586
|
+
const hasValidExtension = extensions.some(ext => lastPart === `.${ext}` || lastPart.endsWith(`.${ext}`));
|
|
13587
|
+
if (isIndexFile) {
|
|
13588
|
+
return '/' + (subsequentParts.length > 1 ? subsequentParts.slice(0, -1).join('/') : '');
|
|
13589
|
+
}
|
|
13590
|
+
if (hasValidExtension) {
|
|
13591
|
+
return '/' + subsequentParts.join('/').replace(/\.(js|ts)$/, '');
|
|
13592
|
+
}
|
|
13593
|
+
}
|
|
13594
|
+
return '';
|
|
13595
|
+
}
|
|
13596
|
+
function findCommonPath(paths) {
|
|
13597
|
+
if (paths.length === 0) return '';
|
|
13598
|
+
const splitPaths = paths.map(path => path.split('/'));
|
|
13599
|
+
const minLength = Math.min(...splitPaths.map(parts => parts.length));
|
|
13600
|
+
let commonParts = [];
|
|
13601
|
+
for (let i = 0; i < minLength; i++) {
|
|
13602
|
+
const part = splitPaths[0][i];
|
|
13603
|
+
if (splitPaths.every(parts => parts[i] === part || parts[i].startsWith('['))) {
|
|
13604
|
+
commonParts.push(part);
|
|
13605
|
+
} else {
|
|
13606
|
+
break;
|
|
13607
|
+
}
|
|
13608
|
+
}
|
|
13609
|
+
const commonPath = commonParts.join('/') + (commonParts.length ? '/' : '');
|
|
13610
|
+
return commonPath;
|
|
13611
|
+
}
|
|
13612
|
+
|
|
13613
|
+
// import * as Params from "./params"
|
|
13614
|
+
|
|
13528
13615
|
const App={
|
|
13529
13616
|
...__App__,
|
|
13530
13617
|
...JsonStyleSheet,
|
|
13531
13618
|
...Spa,
|
|
13532
13619
|
...Global,
|
|
13533
|
-
...Params
|
|
13620
|
+
// ...Params
|
|
13534
13621
|
};
|
|
13535
13622
|
|
|
13536
13623
|
[
|
|
@@ -13566,6 +13653,7 @@ if ( globalThis.__Ziko__ ) {
|
|
|
13566
13653
|
ExtractAll,
|
|
13567
13654
|
RemoveAll
|
|
13568
13655
|
};
|
|
13656
|
+
defineParamsGetter(__Ziko__);
|
|
13569
13657
|
}
|
|
13570
13658
|
// globalThis.__Ziko__={
|
|
13571
13659
|
// ...Ziko,
|
|
@@ -13595,4 +13683,4 @@ function RemoveAll(){
|
|
|
13595
13683
|
Data.RemoveAll();
|
|
13596
13684
|
}
|
|
13597
13685
|
|
|
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 };
|
|
13686
|
+
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, ZikoUIDefintion, 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.16",
|
|
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",
|
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
|
+
}
|