ziko 1.9.0 → 2.0.0-alpha.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 +304 -2868
- package/dist/ziko.js +1322 -5315
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +1242 -5057
- package/package.json +70 -97
- package/src/__ziko__/__config__.js +3 -3
- package/src/__ziko__/__state__.js +0 -1
- package/src/{dom/components → components}/Fragment/index.js +1 -1
- package/src/{dom/components/wrappers → components}/HTMLWrapper/index.js +3 -7
- package/src/{dom/components/wrappers → components}/SVGWrapper/index.js +3 -15
- package/src/{dom/components → components}/Suspense/index.js +1 -1
- package/src/{dom/components → components}/Swap/index.js +2 -2
- package/src/{dom/components → components}/Switch/index.js +1 -2
- package/src/components/View/index.js +11 -0
- package/src/{dom/components → components}/index.js +2 -3
- package/src/dom/{constructors/UIElement.js → UIElement/index.js} +6 -6
- package/src/dom/index.js +2 -6
- package/src/dom/{utils → internal-utils}/call_with_optional_props.js +1 -1
- package/src/dom/{utils/is_ui_item.js → internal-utils/checkers.js} +1 -0
- package/src/dom/internal-utils/is_ui_item.js +10 -0
- package/src/dom/tags/index.js +3 -3
- package/src/events/custom-events-registry/view.js +1 -1
- package/src/hooks/index.d.ts +0 -8
- package/src/hooks/index.js +1 -12
- package/src/hooks/use-derived.js +18 -14
- package/src/hooks/use-effect.js +7 -15
- package/src/hooks/use-reactive.d.ts +1 -1
- package/src/hooks/use-reactive.js +1 -1
- package/src/hooks/use-state.js +1 -7
- package/src/index.js +2 -6
- package/src/{helpers → internal-utils}/checkers/index.js +1 -1
- package/src/math/index.d.ts +4 -4
- package/src/math/index.js +7 -10
- package/src/math/{functions/mapfun → mapfun}/index.js +1 -1
- package/src/math/{functions/utils → utils}/index.d.ts +1 -1
- package/src/math/utils/index.js +42 -103
- package/src/{dom/constructors/UIElementCore.d.ts → mini-dom/UIElement/index.d.ts} +1 -1
- package/src/{dom/constructors/UIElementCore.js → mini-dom/UIElement/index.js} +5 -14
- package/src/{dom/constructors/UINode.js → mini-dom/UINode/index.js} +1 -3
- package/src/{dom/constructors → mini-dom}/mixins/attrs.js +6 -6
- package/src/{dom/constructors → mini-dom}/mixins/dom.js +2 -16
- package/src/mini-dom/mixins/lifecycle.js +32 -0
- package/src/{dom/constructors → mini-dom}/mixins/style.js +1 -1
- package/src/mini-dom/parse_props.js +26 -0
- package/src/{dom → mini-dom}/text/index.js +4 -4
- package/src/router/file-based-router/index.js +63 -14
- package/src/router/index.d.ts +1 -1
- package/src/router/index.js +1 -1
- package/src/router/{utils → internal-utils}/dynamic-routes-parser.js +45 -11
- package/src/router/internal-utils/get-root.js +24 -0
- package/src/router/internal-utils/index.d.ts +5 -0
- package/src/router/internal-utils/normalize-path.js +32 -0
- package/src/router/internal-utils/routes-grouper.js +49 -0
- package/src/router/{utils → internal-utils}/routes-matcher.js +32 -9
- package/src/{hooks/use-query-params.js → router/useQueryParams/index.js} +0 -1
- package/src/time/{clocks/clock.js → clock/index.js} +1 -1
- package/src/time/{clocks/clock.d.ts → clock/index.ts} +1 -1
- package/src/time/debounce/index.d.ts +4 -0
- package/src/time/debounce/index.js +4 -0
- package/src/time/index.d.ts +7 -5
- package/src/time/index.js +7 -8
- package/src/time/sleep/index.d.ts +1 -0
- package/src/time/sleep/index.js +1 -0
- package/src/time/throttle/index.d.ts +4 -0
- package/src/time/throttle/index.js +9 -0
- package/src/time/{clocks/tick.js → tick/index.js} +2 -7
- package/src/time/{delay → timeout}/index.d.ts +0 -2
- package/src/time/{delay → timeout}/index.js +0 -1
- package/src/app/globals.js +0 -76
- package/src/app/index.js +0 -18
- package/src/app/params.js +0 -37
- package/src/app/routes.js +0 -57
- package/src/app/spa-file-based-routing.js +0 -74
- package/src/app/spa.js +0 -55
- package/src/app/ziko-app.js +0 -39
- package/src/data/api/fetchdom.js +0 -30
- package/src/data/api/index.js +0 -4
- package/src/data/api/preload.js +0 -11
- package/src/data/converter/__(To Be Moved)adoc.js +0 -130
- package/src/data/converter/__(To Be Moved)markdown.js +0 -95
- package/src/data/converter/array.js +0 -43
- package/src/data/converter/canvas.js +0 -25
- package/src/data/converter/css.js +0 -37
- package/src/data/converter/csv.js +0 -35
- package/src/data/converter/idea.txt +0 -10
- package/src/data/converter/index.js +0 -33
- package/src/data/converter/json.js +0 -80
- package/src/data/converter/object.js +0 -74
- package/src/data/converter/svg.js +0 -11
- package/src/data/datatypes/color.js +0 -11
- package/src/data/decorators.js +0 -0
- package/src/data/index.js +0 -17
- package/src/data/parser/index.d.ts +0 -41
- package/src/data/parser/index.js +0 -28
- package/src/data/string-dep/index.js +0 -1
- package/src/data/string-dep/patterns.js +0 -12
- package/src/data/string-dep/string.js +0 -170
- package/src/dom/components/Flex/index.js +0 -89
- package/src/dom/components/Flex/utils/index.js +0 -20
- package/src/dom/components/View/index.js +0 -9
- package/src/dom/components/graphics/Canvas/index.js +0 -175
- package/src/dom/components/graphics/Svg/index.js +0 -69
- package/src/dom/components/graphics/index.js +0 -2
- package/src/dom/components/wrappers/index.js +0 -2
- package/src/dom/constructors/mixins/lifecycle.js +0 -54
- package/src/dom/grid/index.js +0 -33
- package/src/dom/mini/UIElement.js +0 -10
- package/src/dom/utils/checkers.js +0 -1
- package/src/dom/utils/getters.js +0 -0
- package/src/hooks/use-favicon.d.ts +0 -41
- package/src/hooks/use-favicon.js +0 -59
- package/src/hooks/use-ipc.d.ts +0 -12
- package/src/hooks/use-ipc.js +0 -83
- package/src/hooks/use-media-query.d.ts +0 -24
- package/src/hooks/use-media-query.js +0 -59
- package/src/hooks/use-root.d.ts +0 -15
- package/src/hooks/use-root.js +0 -73
- package/src/hooks/use-storage.d.ts +0 -47
- package/src/hooks/use-storage.js +0 -118
- package/src/hooks/use-thread.d.ts +0 -33
- package/src/hooks/use-thread.js +0 -55
- package/src/hooks/use-title.d.ts +0 -37
- package/src/hooks/use-title.js +0 -43
- package/src/lite.js +0 -2
- package/src/math/--discret/Set/index.js +0 -2
- package/src/math/--discret/Set/power-set.js +0 -15
- package/src/math/--discret/Set/sub-set.js +0 -10
- package/src/math/--discret/index.js +0 -12
- package/src/math/complex/helpers/constructor.js +0 -38
- package/src/math/complex/helpers/index.js +0 -1
- package/src/math/complex/index.d.ts +0 -231
- package/src/math/complex/index.js +0 -193
- package/src/math/functions/conversions/index.d.ts +0 -101
- package/src/math/functions/conversions/index.js +0 -61
- package/src/math/functions/helper.js +0 -81
- package/src/math/functions/index.d.ts +0 -147
- package/src/math/functions/index.js +0 -43
- package/src/math/functions/logic/index.d.ts +0 -53
- package/src/math/functions/logic/index.js +0 -54
- package/src/math/functions/proxy.js +0 -58
- package/src/math/functions/signal/index.d.ts +0 -146
- package/src/math/functions/signal/index.js +0 -104
- package/src/math/functions/stats/index.js +0 -61
- package/src/math/functions/ufunc/index.d.ts +0 -96
- package/src/math/functions/ufunc/index.js +0 -372
- package/src/math/functions/utils/index.js +0 -47
- package/src/math/matrix/AbstractMatrix.js +0 -0
- package/src/math/matrix/helpers/constructor.js +0 -31
- package/src/math/matrix/helpers/det.js +0 -36
- package/src/math/matrix/helpers/index.js +0 -5
- package/src/math/matrix/helpers/inverse.js +0 -52
- package/src/math/matrix/helpers/maintain.js +0 -13
- package/src/math/matrix/helpers/stack.js +0 -24
- package/src/math/matrix/index.js +0 -557
- package/src/math/random/index.d.ts +0 -162
- package/src/math/random/index.js +0 -125
- package/src/math/signal/functions.js +0 -84
- package/src/math/signal/index.js +0 -1
- package/src/math/stats/accum/index.d.ts +0 -43
- package/src/math/stats/accum/index.js +0 -39
- package/src/math/stats/average/index.d.ts +0 -123
- package/src/math/stats/average/index.js +0 -75
- package/src/math/stats/index.d.ts +0 -5
- package/src/math/stats/index.js +0 -14
- package/src/math/stats/percentile/index.d.ts +0 -66
- package/src/math/stats/percentile/index.js +0 -18
- package/src/math/stats/rolling/index.d.ts +0 -47
- package/src/math/stats/rolling/index.js +0 -34
- package/src/math/stats/variability/index.d.ts +0 -93
- package/src/math/stats/variability/index.js +0 -37
- package/src/math/utils/arithmetic.js +0 -137
- package/src/math/utils/checkers.js +0 -29
- package/src/math/utils/comparaison.js +0 -1
- package/src/math/utils/conversions.js +0 -19
- package/src/math/utils/discret.js +0 -51
- package/src/math/utils/mapfun.js +0 -42
- package/src/no-module.js +0 -32
- package/src/provider/index.js +0 -7
- package/src/router/utils/get-root.js +0 -16
- package/src/router/utils/index.d.ts +0 -5
- package/src/router/utils/normalize-path.js +0 -21
- package/src/router/utils/routes-grouper.js +0 -22
- package/src/time/animation/index.d.ts +0 -189
- package/src/time/animation/index.js +0 -94
- package/src/time/clocks/index.d.ts +0 -3
- package/src/time/clocks/index.js +0 -3
- package/src/time/converters/index.js +0 -1
- package/src/time/decorators/index.d.ts +0 -9
- package/src/time/decorators/index.js +0 -17
- package/src/time/ease/index.d.ts +0 -103
- package/src/time/ease/index.js +0 -118
- package/src/time/loop/index.d.ts +0 -50
- package/src/time/loop/index.js +0 -103
- package/src/time/utils/index.js +0 -17
- package/src/time/utils/performance.js +0 -16
- package/src/time/utils/ui.js +0 -26
- /package/src/{dom/components → components}/For/index.js +0 -0
- /package/src/{dom/components → components}/Fragment/index.d.ts +0 -0
- /package/src/{dom/components → components}/Swap/index.d.ts +0 -0
- /package/src/{dom/components → components}/index.d.ts +0 -0
- /package/src/dom/{utils → internal-utils}/index.js +0 -0
- /package/src/dom/{utils → internal-utils}/parse_props.js +0 -0
- /package/src/{helpers → internal-utils}/index.js +0 -0
- /package/src/{helpers → internal-utils}/register/index.js +0 -0
- /package/src/{helpers → internal-utils}/register/register-to-class.js +0 -0
- /package/src/{helpers → internal-utils}/register/register-to-instance.js +0 -0
- /package/src/{symbols → internal-utils/symbols}/index.d.ts +0 -0
- /package/src/{symbols → internal-utils/symbols}/index.js +0 -0
- /package/src/math/{functions/arithmetic → arithmetic}/index.d.ts +0 -0
- /package/src/math/{functions/arithmetic → arithmetic}/index.js +0 -0
- /package/src/math/{const.js → const/index.js} +0 -0
- /package/src/math/{functions/mapfun → mapfun}/index.d.ts +0 -0
- /package/src/math/{functions/mapfun → mapfun}/index.d.ts.txt +0 -0
- /package/src/math/{functions/utils → utils}/mapfun.d.ts.txt +0 -0
- /package/src/{dom/constructors/UINode.d.ts → mini-dom/UINode/index.d.ts} +0 -0
- /package/src/{dom/constructors → mini-dom}/mixins/index.js +0 -0
- /package/src/{dom/constructors → mini-dom}/mixins/indexing.js +0 -0
- /package/src/router/{utils → internal-utils}/dynamic-routes-parser.d.ts +0 -0
- /package/src/router/{utils → internal-utils}/get-root.d.ts +0 -0
- /package/src/router/{utils → internal-utils}/index.js +0 -0
- /package/src/router/{utils → internal-utils}/normalize-path.d.ts +0 -0
- /package/src/router/{utils → internal-utils}/renderer.js +0 -0
- /package/src/router/{utils → internal-utils}/routes-grouper.d.ts +0 -0
- /package/src/router/{utils → internal-utils}/routes-matcher.d.ts +0 -0
- /package/src/{hooks/use-query-params.d.ts → router/useQueryParams/index.d.ts} +0 -0
- /package/src/{data/string → string}/checkers/index.d.ts +0 -0
- /package/src/{data/string → string}/checkers/index.js +0 -0
- /package/src/{data/string → string}/converters/index.d.ts +0 -0
- /package/src/{data/string → string}/converters/index.js +0 -0
- /package/src/{data/string → string}/index.d.ts +0 -0
- /package/src/{data/string → string}/index.js +0 -0
- /package/src/time/{clocks/scheduler.js → schedular/index.js} +0 -0
- /package/src/time/{clocks/scheduler.d.ts → schedular/index.ts} +0 -0
- /package/src/time/{clocks/tick.d.ts → tick/index.ts} +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export function is_dynamic(path) {
|
|
2
|
+
const DynamicPattern = /(:\w+|\[\[\.\.\.\w+\]\]|\[\.\.\.\w+\]|\[\w+\]\+?)/;
|
|
3
|
+
return DynamicPattern.test(path);
|
|
4
|
+
}
|
|
5
|
+
export function sort_routes(routeKeys) {
|
|
6
|
+
return [...routeKeys].sort((a, b) => {
|
|
7
|
+
const aIsOptionalCatchAll = a.includes('[[...');
|
|
8
|
+
const bIsOptionalCatchAll = b.includes('[[...');
|
|
9
|
+
|
|
10
|
+
const aIsCatchAll = a.includes('[...') && !aIsOptionalCatchAll;
|
|
11
|
+
const bIsCatchAll = b.includes('[...') && !bIsOptionalCatchAll;
|
|
12
|
+
|
|
13
|
+
const aIsDynamic = is_dynamic(a);
|
|
14
|
+
const bIsDynamic = is_dynamic(b);
|
|
15
|
+
|
|
16
|
+
// 1. Optional catch-alls [[...slug]] ALWAYS go last
|
|
17
|
+
if (aIsOptionalCatchAll && !bIsOptionalCatchAll) return 1;
|
|
18
|
+
if (!aIsOptionalCatchAll && bIsOptionalCatchAll) return -1;
|
|
19
|
+
|
|
20
|
+
// 2. Catch-alls [...slug] go right before optional catch-alls
|
|
21
|
+
if (aIsCatchAll && !bIsCatchAll) return 1;
|
|
22
|
+
if (!aIsCatchAll && bIsCatchAll) return -1;
|
|
23
|
+
|
|
24
|
+
// 3. Static routes go before standard dynamic routes ([id])
|
|
25
|
+
if (!aIsDynamic && bIsDynamic) return -1;
|
|
26
|
+
if (aIsDynamic && !bIsDynamic) return 1;
|
|
27
|
+
|
|
28
|
+
// 4. Deeper/longer routes take precedence over shorter ones
|
|
29
|
+
return b.length - a.length;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function routes_grouper(routeMap) {
|
|
33
|
+
const grouped = {
|
|
34
|
+
static: {},
|
|
35
|
+
dynamic: {},
|
|
36
|
+
};
|
|
37
|
+
for (const [path, value] of Object.entries(routeMap)) {
|
|
38
|
+
if (is_dynamic(path)) {
|
|
39
|
+
const segments = path.split("/").filter(Boolean);
|
|
40
|
+
const optionalIndex = segments.findIndex(seg => seg.endsWith("]+"));
|
|
41
|
+
const hasInvalidOptional =
|
|
42
|
+
optionalIndex !== -1 && optionalIndex !== segments.length - 1;
|
|
43
|
+
if (hasInvalidOptional) throw new Error(`Invalid optional param position in route: "${path}" — optional parameters can only appear at the end.`);
|
|
44
|
+
grouped.dynamic[path] = value;
|
|
45
|
+
}
|
|
46
|
+
else grouped.static[path] = value;
|
|
47
|
+
}
|
|
48
|
+
return grouped;
|
|
49
|
+
}
|
|
@@ -2,18 +2,33 @@ export function routes_matcher(mask, route) {
|
|
|
2
2
|
const maskSegments = mask.split("/").filter(Boolean);
|
|
3
3
|
const routeSegments = route.split("/").filter(Boolean);
|
|
4
4
|
let i = 0, j = 0;
|
|
5
|
+
|
|
5
6
|
while (i < maskSegments.length && j < routeSegments.length) {
|
|
6
7
|
const maskSegment = maskSegments[i];
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
// Optional Catch-all [[...slug]]
|
|
10
|
+
if (maskSegment.startsWith("[[...") && maskSegment.endsWith("]]")) {
|
|
11
|
+
const remainingMaskSegments = maskSegments.length - i - 1;
|
|
12
|
+
if (remainingMaskSegments === 0) return true;
|
|
13
|
+
let requiredSegments = 0;
|
|
14
|
+
for (let k = i + 1; k < maskSegments.length; k++) {
|
|
15
|
+
if (!maskSegments[k].endsWith("]+")) requiredSegments++;
|
|
16
|
+
}
|
|
17
|
+
const remainingRouteSegments = routeSegments.length - j;
|
|
18
|
+
const segmentsToConsume = remainingRouteSegments - requiredSegments;
|
|
19
|
+
if (segmentsToConsume < 0) return false;
|
|
20
|
+
j += segmentsToConsume;
|
|
21
|
+
i++;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Required Catch-all [...slug]
|
|
8
26
|
if (maskSegment.startsWith("[...") && maskSegment.endsWith("]")) {
|
|
9
27
|
const remainingMaskSegments = maskSegments.length - i - 1;
|
|
10
28
|
if (remainingMaskSegments === 0) return true;
|
|
11
|
-
// Calculate minimum required route segments for remaining mask
|
|
12
29
|
let requiredSegments = 0;
|
|
13
30
|
for (let k = i + 1; k < maskSegments.length; k++) {
|
|
14
|
-
if (!maskSegments[k].endsWith("]+"))
|
|
15
|
-
requiredSegments++;
|
|
16
|
-
}
|
|
31
|
+
if (!maskSegments[k].endsWith("]+")) requiredSegments++;
|
|
17
32
|
}
|
|
18
33
|
const remainingRouteSegments = routeSegments.length - j;
|
|
19
34
|
if (remainingRouteSegments < requiredSegments) return false;
|
|
@@ -23,32 +38,40 @@ export function routes_matcher(mask, route) {
|
|
|
23
38
|
i++;
|
|
24
39
|
continue;
|
|
25
40
|
}
|
|
41
|
+
|
|
26
42
|
if (maskSegment.startsWith("[") && maskSegment.endsWith("]+")) {
|
|
27
|
-
if (
|
|
43
|
+
if (routeSegments[j]) j++;
|
|
28
44
|
i++;
|
|
29
45
|
continue;
|
|
30
46
|
}
|
|
47
|
+
|
|
31
48
|
if (maskSegment.startsWith("[") && maskSegment.endsWith("]")) {
|
|
32
49
|
i++;
|
|
33
50
|
j++;
|
|
34
51
|
continue;
|
|
35
52
|
}
|
|
36
|
-
|
|
53
|
+
|
|
54
|
+
if (maskSegment !== routeSegments[j]) return false;
|
|
37
55
|
i++;
|
|
38
56
|
j++;
|
|
39
57
|
}
|
|
58
|
+
|
|
40
59
|
while (i < maskSegments.length) {
|
|
41
60
|
const seg = maskSegments[i];
|
|
61
|
+
// [[...slug]] and [param]+ can match empty segments at the end
|
|
62
|
+
if (seg.startsWith("[[...") && seg.endsWith("]]")) {
|
|
63
|
+
i++;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
42
66
|
if (seg.endsWith("]+")) {
|
|
43
67
|
i++;
|
|
44
68
|
continue;
|
|
45
69
|
}
|
|
46
70
|
return false;
|
|
47
71
|
}
|
|
72
|
+
|
|
48
73
|
return i === maskSegments.length && j === routeSegments.length;
|
|
49
74
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
75
|
// // DEMO
|
|
53
76
|
// console.log("=== EXISTING TESTS ===");
|
|
54
77
|
// console.log(routes_matcher("/user/[id]+", "/user")); // true
|
package/src/time/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export type * from './
|
|
2
|
-
export type * from './
|
|
3
|
-
export type * from './
|
|
4
|
-
export type * from './
|
|
5
|
-
export type * from './
|
|
1
|
+
export type * from './clock/index.d.ts';
|
|
2
|
+
export type * from './debounce/index.d.ts';
|
|
3
|
+
export type * from './schedular/index.d.ts';
|
|
4
|
+
export type * from './sleep/index.d.ts';
|
|
5
|
+
export type * from './throttle/index.d.ts';
|
|
6
|
+
export type * from './tick/index.d.ts';
|
|
7
|
+
export type * from './timeout/index.d.ts';
|
package/src/time/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './utils/index.js';
|
|
1
|
+
export * from './clock/index.js';
|
|
2
|
+
export * from './debounce/index.js';
|
|
3
|
+
export * from './schedular/index.js';
|
|
4
|
+
export * from './sleep/index.js';
|
|
5
|
+
export * from './throttle/index.js';
|
|
6
|
+
export * from './tick/index.js';
|
|
7
|
+
export * from './timeout/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sleep: (ms: number) => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const sleep= ms => new Promise(res => setTimeout(res, ms));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Tick {
|
|
1
|
+
export class Tick {
|
|
2
2
|
constructor(fn, ms, count = Infinity, start) {
|
|
3
3
|
this.ms = ms;
|
|
4
4
|
this.fn = fn;
|
|
@@ -40,9 +40,4 @@ class Tick {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// Helper factory
|
|
43
|
-
const tick = (fn, ms, count = Infinity, start = true) => new Tick(fn, ms, count, start);
|
|
44
|
-
|
|
45
|
-
export {
|
|
46
|
-
Tick,
|
|
47
|
-
tick
|
|
48
|
-
};
|
|
43
|
+
export const tick = (fn, ms, count = Infinity, start = true) => new Tick(fn, ms, count, start);
|
package/src/app/globals.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { defineParamsGetter } from './params.js'
|
|
2
|
-
const __UI__={
|
|
3
|
-
__all__(){
|
|
4
|
-
return Object.values(this)
|
|
5
|
-
.filter(Array.isArray)
|
|
6
|
-
.flat();
|
|
7
|
-
},
|
|
8
|
-
querySelectorAll(){
|
|
9
|
-
return this.__all__().filter(n=>n)
|
|
10
|
-
},
|
|
11
|
-
getElementByIndex(index){
|
|
12
|
-
return this.__all__().find(n=>n.ui_index===index);
|
|
13
|
-
},
|
|
14
|
-
getElementById(id){
|
|
15
|
-
return null;
|
|
16
|
-
},
|
|
17
|
-
getElementsByClass(){
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
getElementsByTagName(){
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const __HYDRATION__ = {
|
|
25
|
-
map : new Map(),
|
|
26
|
-
index : 0,
|
|
27
|
-
increment : function(){
|
|
28
|
-
return this.index ++
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const __HYDRATION_MAP__ = new Map()
|
|
32
|
-
const __Config__={
|
|
33
|
-
default:{
|
|
34
|
-
target:null,
|
|
35
|
-
render:true,
|
|
36
|
-
math:{
|
|
37
|
-
mode:"deg"
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
setDefault:function(pairs){
|
|
41
|
-
const keys=Object.keys(pairs);
|
|
42
|
-
const values=Object.values(pairs);
|
|
43
|
-
for(let i=0; i<keys.length; i++) this.default[keys[i]]=values[i];
|
|
44
|
-
},
|
|
45
|
-
init:()=>{
|
|
46
|
-
// document.documentElement.setAttribute("data-engine","zikojs")
|
|
47
|
-
},
|
|
48
|
-
renderingMode :"spa",
|
|
49
|
-
isSSC : false,
|
|
50
|
-
}
|
|
51
|
-
const __CACHE__ = {
|
|
52
|
-
ui_index : 0,
|
|
53
|
-
get_ui_index:function(){
|
|
54
|
-
return this.ui_index ++
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if ( !globalThis?.__Ziko__ ){
|
|
58
|
-
globalThis.__Ziko__ = {
|
|
59
|
-
// ...Ziko,
|
|
60
|
-
__UI__,
|
|
61
|
-
__HYDRATION__,
|
|
62
|
-
__HYDRATION_MAP__,
|
|
63
|
-
__Config__,
|
|
64
|
-
__CACHE__,
|
|
65
|
-
// ExtractAll,
|
|
66
|
-
// RemoveAll
|
|
67
|
-
};
|
|
68
|
-
defineParamsGetter(__Ziko__)
|
|
69
|
-
}
|
|
70
|
-
export {
|
|
71
|
-
__UI__,
|
|
72
|
-
__HYDRATION_MAP__,
|
|
73
|
-
__Config__,
|
|
74
|
-
__CACHE__,
|
|
75
|
-
__HYDRATION__
|
|
76
|
-
}
|
package/src/app/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export * from "./ziko-app.js";
|
|
2
|
-
export * from "./spa.js"
|
|
3
|
-
export * from "./params.js"
|
|
4
|
-
// export * from "./globals.js"
|
|
5
|
-
export * from "./spa-file-based-routing.js"
|
|
6
|
-
|
|
7
|
-
import * as __App__ from "./ziko-app.js"
|
|
8
|
-
import * as Spa from "./spa.js"
|
|
9
|
-
// import * as Global from "./globals.js"
|
|
10
|
-
// import * as Params from "./params"
|
|
11
|
-
|
|
12
|
-
const App = {
|
|
13
|
-
...__App__,
|
|
14
|
-
...Spa,
|
|
15
|
-
// ...Global,
|
|
16
|
-
// ...Params
|
|
17
|
-
}
|
|
18
|
-
export default App
|
package/src/app/params.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
function parseQueryParams(queryString) {
|
|
2
|
-
return Object.fromEntries(
|
|
3
|
-
new URLSearchParams(location.search)
|
|
4
|
-
);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function defineParamsGetter(target ){
|
|
8
|
-
Object.defineProperties(target, {
|
|
9
|
-
'QueryParams': {
|
|
10
|
-
get: function() {
|
|
11
|
-
return parseQueryParams(globalThis.location.search.substring(1));
|
|
12
|
-
},
|
|
13
|
-
configurable: false,
|
|
14
|
-
enumerable: true
|
|
15
|
-
},
|
|
16
|
-
'HashParams': {
|
|
17
|
-
get: function() {
|
|
18
|
-
const hash = globalThis.location.hash.substring(1);
|
|
19
|
-
return hash.split("#");
|
|
20
|
-
},
|
|
21
|
-
configurable: false,
|
|
22
|
-
enumerable: true
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/*
|
|
29
|
-
|
|
30
|
-
/users?name=ziko&age=26
|
|
31
|
-
/users#name=ziko
|
|
32
|
-
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
export{
|
|
36
|
-
defineParamsGetter
|
|
37
|
-
}
|
package/src/app/routes.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
function routesMatcher(mask, route) {
|
|
2
|
-
const maskSegments = mask.split('/');
|
|
3
|
-
const routeSegments = route.split('/');
|
|
4
|
-
if (maskSegments.length !== routeSegments.length) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
for (let i = 0; i < maskSegments.length; i++) {
|
|
8
|
-
const maskSegment = maskSegments[i];
|
|
9
|
-
const routeSegment = routeSegments[i];
|
|
10
|
-
if (maskSegment.startsWith(':')) {
|
|
11
|
-
continue;
|
|
12
|
-
} else if (maskSegment !== routeSegment) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
function dynamicRoutesParser(mask, route) {
|
|
19
|
-
const maskSegments = mask.split('/');
|
|
20
|
-
const routeSegments = route.split('/');
|
|
21
|
-
const params = {};
|
|
22
|
-
if (maskSegments.length !== routeSegments.length) {
|
|
23
|
-
return params;
|
|
24
|
-
}
|
|
25
|
-
for (let i = 0; i < maskSegments.length; i++) {
|
|
26
|
-
const maskSegment = maskSegments[i];
|
|
27
|
-
const routeSegment = routeSegments[i];
|
|
28
|
-
if (maskSegment.startsWith(':')) {
|
|
29
|
-
const paramName = maskSegment.slice(1);
|
|
30
|
-
params[paramName] = routeSegment;
|
|
31
|
-
} else if (maskSegment !== routeSegment) {
|
|
32
|
-
return {};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return params;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function isDynamic(path) {
|
|
39
|
-
const DynamicPattern = /:\w+/;
|
|
40
|
-
return DynamicPattern.test(path);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// // Example usage:
|
|
44
|
-
// const mask = "/:id/id/:lang/lang";
|
|
45
|
-
// const route = "/id/5/lang/fr";
|
|
46
|
-
// console.log(DynamicRouteMatcher(mask, route)); // Should return true
|
|
47
|
-
|
|
48
|
-
export {
|
|
49
|
-
routesMatcher,
|
|
50
|
-
dynamicRoutesParser,
|
|
51
|
-
isDynamic
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// // Example usage:
|
|
55
|
-
// const mask = "app/lang/:lang/id/:id";
|
|
56
|
-
// const route = "app/lang/en/id/7";
|
|
57
|
-
// console.log(dynamicRoutesParser(mask, route)); // Should return { lang: "en", id: "7" }
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { SPA } from "./spa.js";
|
|
2
|
-
import { tags } from "../dom/index.js";
|
|
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
|
-
const pairs = {}
|
|
8
|
-
for(let i=0; i<routes.length; i++){
|
|
9
|
-
const module = await pages[routes[i]]()
|
|
10
|
-
const component = await module.default
|
|
11
|
-
Object.assign(pairs,{[customPath(routes[i], root)]:component})
|
|
12
|
-
}
|
|
13
|
-
return SPA({
|
|
14
|
-
target : document.body,
|
|
15
|
-
routes : {
|
|
16
|
-
"/" : ()=>{},
|
|
17
|
-
...pairs
|
|
18
|
-
},
|
|
19
|
-
wrapper : tags.section()
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
function customPath(inputPath, root = './src/pages', extensions = ['js', 'ts']) {
|
|
23
|
-
if(root.at(-1)==="/") root = root.slice(0, -1)
|
|
24
|
-
const normalizedPath = inputPath.replace(/\\/g, '/').replace(/\[(\w+)\]/g, '$1/:$1');
|
|
25
|
-
const parts = normalizedPath.split('/');
|
|
26
|
-
const rootParts = root.split('/');
|
|
27
|
-
const rootIndex = parts.indexOf(rootParts.at(-1));
|
|
28
|
-
if (rootIndex !== -1) {
|
|
29
|
-
const subsequentParts = parts.slice(rootIndex + 1);
|
|
30
|
-
const lastPart = parts.at(-1);
|
|
31
|
-
const isIndexFile = lastPart === 'index.js' || lastPart === 'index.ts';
|
|
32
|
-
// console.log({extensions, subsequentParts, lastPart, isIndexFile, rootParts, rootIndex, parts})
|
|
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
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { text } from "../dom/index.js";
|
|
2
|
-
import { dynamicRoutesParser,routesMatcher,isDynamic } from "./routes.js";
|
|
3
|
-
import { ZikoApp } from "./ziko-app.js";
|
|
4
|
-
class ZikoSPA extends ZikoApp{
|
|
5
|
-
constructor({head, wrapper, target, routes}){
|
|
6
|
-
super({head, wrapper, target})
|
|
7
|
-
this.routes=new Map([
|
|
8
|
-
["404",text("Error 404")],
|
|
9
|
-
...Object.entries(routes)
|
|
10
|
-
]);
|
|
11
|
-
this.clear();
|
|
12
|
-
globalThis.onpopstate = this.mount(location.pathname);
|
|
13
|
-
}
|
|
14
|
-
clear(){
|
|
15
|
-
[...this.routes].forEach(n=>{
|
|
16
|
-
!isDynamic(n[0]) && n[1]?.isUIElement && n[1].unmount()
|
|
17
|
-
})
|
|
18
|
-
// this.wrapper.clear();
|
|
19
|
-
return this;
|
|
20
|
-
}
|
|
21
|
-
mount(path){
|
|
22
|
-
const [mask, callback] = [...this.routes].find(route=>routesMatcher(route[0],path));
|
|
23
|
-
let element ;
|
|
24
|
-
if(isDynamic(mask)){
|
|
25
|
-
const params = dynamicRoutesParser(mask, path)
|
|
26
|
-
element = callback.call(this,params)
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
callback?.isUIElement && callback.mount(this.wrapper);
|
|
30
|
-
if(typeof callback === "function") element = callback();
|
|
31
|
-
}
|
|
32
|
-
if(element?.isUIElement) element.mount(this.wrapper);
|
|
33
|
-
// if(element?.isZikoApp) element.mount(this.wrapper);
|
|
34
|
-
if(element instanceof Promise){
|
|
35
|
-
element.then(e=>e.mount(this.wrapper))
|
|
36
|
-
}
|
|
37
|
-
globalThis.history.pushState({}, "", path);
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const SPA=({head, wrapper, target, routes})=>new ZikoSPA({head, wrapper, target, routes});
|
|
42
|
-
|
|
43
|
-
export {
|
|
44
|
-
ZikoSPA,
|
|
45
|
-
SPA
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/*
|
|
50
|
-
// Static
|
|
51
|
-
S.get("/url",wrapper)
|
|
52
|
-
// Dynamique
|
|
53
|
-
s.get("/url/name/:name/id/:id",(path,name,id)=>handler())
|
|
54
|
-
// regEx
|
|
55
|
-
*/
|
package/src/app/ziko-app.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// import { ZikoHead , useHead} from "../reactivity/hooks/head/index.js";
|
|
2
|
-
class ZikoApp {
|
|
3
|
-
constructor({head = null, wrapper = null, target = null}){
|
|
4
|
-
this.head = head;
|
|
5
|
-
this.wrapper = wrapper;
|
|
6
|
-
this.target = target;
|
|
7
|
-
this.init()
|
|
8
|
-
}
|
|
9
|
-
get isZikoApp(){
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
init(){
|
|
13
|
-
this.head && this.setHead(this.head);
|
|
14
|
-
this.wrapper && this.setWrapper(this.wrapper);
|
|
15
|
-
this.target && this.setTarget(this.target);
|
|
16
|
-
if(this.wrapper && this.target)this.wrapper.mount(this.target);
|
|
17
|
-
}
|
|
18
|
-
setTarget(target){
|
|
19
|
-
if(target instanceof HTMLElement) this.target = target;
|
|
20
|
-
else if (typeof target === "string") this.target = globalThis?.document?.querySelector(target);
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
setWrapper(wrapper){
|
|
24
|
-
if(wrapper?.isUIElement) this.wrapper = wrapper;
|
|
25
|
-
else if(typeof wrapper === "function") this.wrapper = wrapper();
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
// setHead(head){
|
|
29
|
-
// if(head instanceof ZikoHead) this.head = head;
|
|
30
|
-
// else this.head = useHead(head);
|
|
31
|
-
// return this;
|
|
32
|
-
// }
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
const App = ({head, wrapper, target}) => new ZikoApp({head, wrapper, target})
|
|
36
|
-
export{
|
|
37
|
-
ZikoApp,
|
|
38
|
-
App
|
|
39
|
-
}
|
package/src/data/api/fetchdom.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// import { preload } from "./preload";
|
|
2
|
-
|
|
3
|
-
// async function fetchdom(url='https://github.com/zakarialaoui10') {
|
|
4
|
-
// try {
|
|
5
|
-
// const response = await fetch(url);
|
|
6
|
-
// if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
|
7
|
-
// const html = await response.text();
|
|
8
|
-
// const dom = new DOMParser().parseFromString(html, 'text/html');
|
|
9
|
-
// return dom.documentElement;
|
|
10
|
-
// } catch (err) {
|
|
11
|
-
// console.error('Failed to fetch DOM:', err);
|
|
12
|
-
// throw err;
|
|
13
|
-
// }
|
|
14
|
-
// }
|
|
15
|
-
|
|
16
|
-
// function fetchdomSync(url='https://github.com/zakarialaoui10') {
|
|
17
|
-
// try {
|
|
18
|
-
// const data = preload(url);
|
|
19
|
-
// const dom = new DOMParser().parseFromString(data, 'text/html');
|
|
20
|
-
// return dom.documentElement;
|
|
21
|
-
// } catch (err) {
|
|
22
|
-
// console.error('Failed to fetch DOM synchronously:', err);
|
|
23
|
-
// throw err;
|
|
24
|
-
// }
|
|
25
|
-
// }
|
|
26
|
-
|
|
27
|
-
// export {
|
|
28
|
-
// fetchdom,
|
|
29
|
-
// fetchdomSync
|
|
30
|
-
// };
|
package/src/data/api/index.js
DELETED
package/src/data/api/preload.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const preload=(url)=>{
|
|
2
|
-
const xhr = new XMLHttpRequest();
|
|
3
|
-
xhr.open("GET", url, false);
|
|
4
|
-
xhr.send();
|
|
5
|
-
if (xhr.status === 200) {
|
|
6
|
-
return xhr.responseText;
|
|
7
|
-
} else {
|
|
8
|
-
throw new Error(`Failed to fetch data from ${url}. Status: ${xhr.status}`);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export {preload}
|