vorma 0.0.0-pre.0 → 0.82.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/LICENSE +28 -0
- package/README.md +48 -0
- package/internal/framework/_typescript/client/index.ts +64 -0
- package/internal/framework/_typescript/client/src/asset_manager.ts +67 -0
- package/internal/framework/_typescript/client/src/client.ts +1201 -0
- package/internal/framework/_typescript/client/src/client_loaders.ts +249 -0
- package/internal/framework/_typescript/client/src/component_loader.ts +105 -0
- package/internal/framework/_typescript/client/src/error_boundary.ts +7 -0
- package/internal/framework/_typescript/client/src/events.ts +54 -0
- package/internal/framework/_typescript/client/src/global_loading_indicator/global_loading_indicator.ts +125 -0
- package/internal/framework/_typescript/client/src/hard_reload.ts +1 -0
- package/internal/framework/_typescript/client/src/head_elements/head_elements.ts +193 -0
- package/internal/framework/_typescript/client/src/history/history.ts +118 -0
- package/internal/framework/_typescript/client/src/history/npm_history_types.ts +83 -0
- package/internal/framework/_typescript/client/src/hmr/hmr.ts +71 -0
- package/internal/framework/_typescript/client/src/init_client.ts +134 -0
- package/internal/framework/_typescript/client/src/links.ts +218 -0
- package/internal/framework/_typescript/client/src/redirects/redirects.ts +203 -0
- package/internal/framework/_typescript/client/src/rendering.ts +135 -0
- package/internal/framework/_typescript/client/src/resolve_public_href.ts +15 -0
- package/internal/framework/_typescript/client/src/scroll_state_manager.ts +100 -0
- package/internal/framework/_typescript/client/src/static_route_defs/route_def_helpers.ts +22 -0
- package/internal/framework/_typescript/client/src/ui_lib_impl_helpers/link_components.ts +131 -0
- package/internal/framework/_typescript/client/src/ui_lib_impl_helpers/route_components.ts +56 -0
- package/internal/framework/_typescript/client/src/ui_lib_impl_helpers/typed_navigate.ts +58 -0
- package/internal/framework/_typescript/client/src/utils/errors.ts +10 -0
- package/internal/framework/_typescript/client/src/utils/logging.ts +7 -0
- package/internal/framework/_typescript/client/src/vorma_app_helpers/vorma_app_helpers.ts +290 -0
- package/internal/framework/_typescript/client/src/vorma_ctx/vorma_ctx.ts +128 -0
- package/internal/framework/_typescript/client/src/window_focus_revalidation/window_focus_revalidation.ts +32 -0
- package/internal/framework/_typescript/client/tsconfig.json +3 -0
- package/internal/framework/_typescript/create/main.ts +378 -0
- package/internal/framework/_typescript/create/package.json +33 -0
- package/internal/framework/_typescript/create/pnpm-lock.yaml +70 -0
- package/internal/framework/_typescript/create/tsconfig.json +3 -0
- package/internal/framework/_typescript/preact/index.tsx +10 -0
- package/internal/framework/_typescript/preact/src/helpers.ts +113 -0
- package/internal/framework/_typescript/preact/src/link.tsx +107 -0
- package/internal/framework/_typescript/preact/src/preact.tsx +191 -0
- package/internal/framework/_typescript/preact/tsconfig.json +7 -0
- package/internal/framework/_typescript/react/index.tsx +10 -0
- package/internal/framework/_typescript/react/src/helpers.ts +118 -0
- package/internal/framework/_typescript/react/src/link.tsx +115 -0
- package/internal/framework/_typescript/react/src/react.tsx +299 -0
- package/internal/framework/_typescript/react/tsconfig.json +6 -0
- package/internal/framework/_typescript/solid/index.tsx +10 -0
- package/internal/framework/_typescript/solid/src/helpers.ts +114 -0
- package/internal/framework/_typescript/solid/src/link.tsx +104 -0
- package/internal/framework/_typescript/solid/src/solid.tsx +204 -0
- package/internal/framework/_typescript/solid/tsconfig.json +7 -0
- package/internal/framework/_typescript/vite/tsconfig.json +3 -0
- package/internal/framework/_typescript/vite/vite.ts +93 -0
- package/internal/site/frontend/assets/vorma-banner.webp +0 -0
- package/kit/_typescript/converters/converters.ts +152 -0
- package/kit/_typescript/cookies/cookies.ts +18 -0
- package/kit/_typescript/csrf/csrf.ts +10 -0
- package/kit/_typescript/debounce/debounce.ts +17 -0
- package/kit/_typescript/fmt/fmt.ts +3 -0
- package/kit/_typescript/json/deep_equals.ts +54 -0
- package/kit/_typescript/json/json.ts +3 -0
- package/kit/_typescript/json/search_param_serializer.ts +49 -0
- package/kit/_typescript/json/stringify_stable.ts +43 -0
- package/kit/_typescript/listeners/listeners.ts +16 -0
- package/kit/_typescript/matcher/find_best_match.ts +205 -0
- package/kit/_typescript/matcher/find_nested_matches.ts +357 -0
- package/kit/_typescript/matcher/parse_segments.ts +30 -0
- package/kit/_typescript/matcher/register.ts +271 -0
- package/kit/_typescript/theme/theme.ts +166 -0
- package/kit/_typescript/tsconfig.json +3 -0
- package/kit/_typescript/url/url.ts +132 -0
- package/npm_dist/internal/framework/_typescript/client/index.d.ts +17 -0
- package/npm_dist/internal/framework/_typescript/client/index.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/index.js +2489 -0
- package/npm_dist/internal/framework/_typescript/client/index.js.map +7 -0
- package/npm_dist/internal/framework/_typescript/client/src/asset_manager.d.ts +6 -0
- package/npm_dist/internal/framework/_typescript/client/src/asset_manager.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/client.d.ts +119 -0
- package/npm_dist/internal/framework/_typescript/client/src/client.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/client_loaders.d.ts +18 -0
- package/npm_dist/internal/framework/_typescript/client/src/client_loaders.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/component_loader.d.ts +10 -0
- package/npm_dist/internal/framework/_typescript/client/src/component_loader.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/error_boundary.d.ts +3 -0
- package/npm_dist/internal/framework/_typescript/client/src/error_boundary.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/events.d.ts +26 -0
- package/npm_dist/internal/framework/_typescript/client/src/events.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/global_loading_indicator/global_loading_indicator.d.ts +12 -0
- package/npm_dist/internal/framework/_typescript/client/src/global_loading_indicator/global_loading_indicator.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/hard_reload.d.ts +2 -0
- package/npm_dist/internal/framework/_typescript/client/src/hard_reload.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/head_elements/head_elements.d.ts +7 -0
- package/npm_dist/internal/framework/_typescript/client/src/head_elements/head_elements.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/history/history.d.ts +14 -0
- package/npm_dist/internal/framework/_typescript/client/src/history/history.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/history/npm_history_types.d.ts +84 -0
- package/npm_dist/internal/framework/_typescript/client/src/history/npm_history_types.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/hmr/hmr.d.ts +3 -0
- package/npm_dist/internal/framework/_typescript/client/src/hmr/hmr.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/init_client.d.ts +9 -0
- package/npm_dist/internal/framework/_typescript/client/src/init_client.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/links.d.ts +33 -0
- package/npm_dist/internal/framework/_typescript/client/src/links.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/redirects/redirects.d.ts +26 -0
- package/npm_dist/internal/framework/_typescript/client/src/redirects/redirects.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/rendering.d.ts +18 -0
- package/npm_dist/internal/framework/_typescript/client/src/rendering.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/resolve_public_href.d.ts +2 -0
- package/npm_dist/internal/framework/_typescript/client/src/resolve_public_href.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/scroll_state_manager.d.ts +22 -0
- package/npm_dist/internal/framework/_typescript/client/src/scroll_state_manager.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/static_route_defs/route_def_helpers.d.ts +12 -0
- package/npm_dist/internal/framework/_typescript/client/src/static_route_defs/route_def_helpers.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/ui_lib_impl_helpers/link_components.d.ts +28 -0
- package/npm_dist/internal/framework/_typescript/client/src/ui_lib_impl_helpers/link_components.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/ui_lib_impl_helpers/route_components.d.ts +18 -0
- package/npm_dist/internal/framework/_typescript/client/src/ui_lib_impl_helpers/route_components.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/ui_lib_impl_helpers/typed_navigate.d.ts +11 -0
- package/npm_dist/internal/framework/_typescript/client/src/ui_lib_impl_helpers/typed_navigate.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/utils/errors.d.ts +3 -0
- package/npm_dist/internal/framework/_typescript/client/src/utils/errors.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/utils/logging.d.ts +3 -0
- package/npm_dist/internal/framework/_typescript/client/src/utils/logging.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/vorma_app_helpers/vorma_app_helpers.d.ts +119 -0
- package/npm_dist/internal/framework/_typescript/client/src/vorma_app_helpers/vorma_app_helpers.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/vorma_ctx/vorma_ctx.d.ts +88 -0
- package/npm_dist/internal/framework/_typescript/client/src/vorma_ctx/vorma_ctx.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/client/src/window_focus_revalidation/window_focus_revalidation.d.ts +10 -0
- package/npm_dist/internal/framework/_typescript/client/src/window_focus_revalidation/window_focus_revalidation.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/create/main.d.ts +3 -0
- package/npm_dist/internal/framework/_typescript/create/main.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/preact/index.d.ts +4 -0
- package/npm_dist/internal/framework/_typescript/preact/index.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/preact/index.js +283 -0
- package/npm_dist/internal/framework/_typescript/preact/index.js.map +7 -0
- package/npm_dist/internal/framework/_typescript/preact/src/helpers.d.ts +21 -0
- package/npm_dist/internal/framework/_typescript/preact/src/helpers.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/preact/src/link.d.ts +11 -0
- package/npm_dist/internal/framework/_typescript/preact/src/link.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/preact/src/preact.d.ts +21 -0
- package/npm_dist/internal/framework/_typescript/preact/src/preact.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/react/index.d.ts +4 -0
- package/npm_dist/internal/framework/_typescript/react/index.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/react/index.js +370 -0
- package/npm_dist/internal/framework/_typescript/react/index.js.map +7 -0
- package/npm_dist/internal/framework/_typescript/react/src/helpers.d.ts +21 -0
- package/npm_dist/internal/framework/_typescript/react/src/helpers.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/react/src/link.d.ts +11 -0
- package/npm_dist/internal/framework/_typescript/react/src/link.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/react/src/react.d.ts +20 -0
- package/npm_dist/internal/framework/_typescript/react/src/react.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/solid/index.d.ts +4 -0
- package/npm_dist/internal/framework/_typescript/solid/index.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/solid/index.js +314 -0
- package/npm_dist/internal/framework/_typescript/solid/index.js.map +7 -0
- package/npm_dist/internal/framework/_typescript/solid/src/helpers.d.ts +22 -0
- package/npm_dist/internal/framework/_typescript/solid/src/helpers.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/solid/src/link.d.ts +11 -0
- package/npm_dist/internal/framework/_typescript/solid/src/link.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/solid/src/solid.d.ts +22 -0
- package/npm_dist/internal/framework/_typescript/solid/src/solid.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/vite/vite.d.ts +11 -0
- package/npm_dist/internal/framework/_typescript/vite/vite.d.ts.map +1 -0
- package/npm_dist/internal/framework/_typescript/vite/vite.js +82 -0
- package/npm_dist/internal/framework/_typescript/vite/vite.js.map +7 -0
- package/npm_dist/kit/_typescript/chunk-YBAPNBS2.js +202 -0
- package/npm_dist/kit/_typescript/chunk-YBAPNBS2.js.map +7 -0
- package/npm_dist/kit/_typescript/converters/converters.d.ts +26 -0
- package/npm_dist/kit/_typescript/converters/converters.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/converters/converters.js +99 -0
- package/npm_dist/kit/_typescript/converters/converters.js.map +7 -0
- package/npm_dist/kit/_typescript/cookies/cookies.d.ts +13 -0
- package/npm_dist/kit/_typescript/cookies/cookies.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/cookies/cookies.js +13 -0
- package/npm_dist/kit/_typescript/cookies/cookies.js.map +7 -0
- package/npm_dist/kit/_typescript/csrf/csrf.d.ts +5 -0
- package/npm_dist/kit/_typescript/csrf/csrf.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/csrf/csrf.js +11 -0
- package/npm_dist/kit/_typescript/csrf/csrf.js.map +7 -0
- package/npm_dist/kit/_typescript/debounce/debounce.d.ts +4 -0
- package/npm_dist/kit/_typescript/debounce/debounce.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/debounce/debounce.js +16 -0
- package/npm_dist/kit/_typescript/debounce/debounce.js.map +7 -0
- package/npm_dist/kit/_typescript/fmt/fmt.d.ts +2 -0
- package/npm_dist/kit/_typescript/fmt/fmt.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/fmt/fmt.js +8 -0
- package/npm_dist/kit/_typescript/fmt/fmt.js.map +7 -0
- package/npm_dist/kit/_typescript/json/deep_equals.d.ts +7 -0
- package/npm_dist/kit/_typescript/json/deep_equals.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/json/json.d.ts +4 -0
- package/npm_dist/kit/_typescript/json/json.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/json/json.js +110 -0
- package/npm_dist/kit/_typescript/json/json.js.map +7 -0
- package/npm_dist/kit/_typescript/json/search_param_serializer.d.ts +2 -0
- package/npm_dist/kit/_typescript/json/search_param_serializer.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/json/stringify_stable.d.ts +7 -0
- package/npm_dist/kit/_typescript/json/stringify_stable.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/listeners/listeners.d.ts +2 -0
- package/npm_dist/kit/_typescript/listeners/listeners.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/listeners/listeners.js +20 -0
- package/npm_dist/kit/_typescript/listeners/listeners.js.map +7 -0
- package/npm_dist/kit/_typescript/matcher/find_best_match.d.ts +10 -0
- package/npm_dist/kit/_typescript/matcher/find_best_match.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/matcher/find_best_match.js +146 -0
- package/npm_dist/kit/_typescript/matcher/find_best_match.js.map +7 -0
- package/npm_dist/kit/_typescript/matcher/find_nested_matches.d.ts +14 -0
- package/npm_dist/kit/_typescript/matcher/find_nested_matches.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/matcher/find_nested_matches.js +248 -0
- package/npm_dist/kit/_typescript/matcher/find_nested_matches.js.map +7 -0
- package/npm_dist/kit/_typescript/matcher/parse_segments.d.ts +2 -0
- package/npm_dist/kit/_typescript/matcher/parse_segments.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/matcher/register.d.ts +54 -0
- package/npm_dist/kit/_typescript/matcher/register.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/matcher/register.js +21 -0
- package/npm_dist/kit/_typescript/matcher/register.js.map +7 -0
- package/npm_dist/kit/_typescript/theme/theme.d.ts +23 -0
- package/npm_dist/kit/_typescript/theme/theme.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/theme/theme.js +122 -0
- package/npm_dist/kit/_typescript/theme/theme.js.map +7 -0
- package/npm_dist/kit/_typescript/url/url.d.ts +30 -0
- package/npm_dist/kit/_typescript/url/url.d.ts.map +1 -0
- package/npm_dist/kit/_typescript/url/url.js +100 -0
- package/npm_dist/kit/_typescript/url/url.js.map +7 -0
- package/package.json +135 -3
- package/tsconfig.base.json +17 -0
- package/index.js +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { debounce } from "vorma/kit/debounce";
|
|
2
|
+
|
|
3
|
+
export function addOnWindowFocusListener(callback: () => void): () => void {
|
|
4
|
+
const debouncedCallback = debounce(callback, 30);
|
|
5
|
+
const ifVisibleCallback = () => {
|
|
6
|
+
if (document.visibilityState === "visible") {
|
|
7
|
+
debouncedCallback();
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
window.addEventListener("focus", debouncedCallback);
|
|
11
|
+
window.addEventListener("visibilitychange", ifVisibleCallback);
|
|
12
|
+
return () => {
|
|
13
|
+
window.removeEventListener("focus", debouncedCallback);
|
|
14
|
+
window.removeEventListener("visibilitychange", ifVisibleCallback);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { parseSegments } from "./parse_segments.ts";
|
|
2
|
+
import {
|
|
3
|
+
NODE_DYNAMIC,
|
|
4
|
+
NODE_SPLAT,
|
|
5
|
+
SCORE_DYNAMIC,
|
|
6
|
+
SCORE_STATIC_MATCH,
|
|
7
|
+
SEG_TYPES,
|
|
8
|
+
type Params,
|
|
9
|
+
type PatternRegistry,
|
|
10
|
+
type RegisteredPattern,
|
|
11
|
+
type SegmentNode,
|
|
12
|
+
} from "./register.ts";
|
|
13
|
+
|
|
14
|
+
type BestMatch = {
|
|
15
|
+
registeredPattern: RegisteredPattern;
|
|
16
|
+
params: Params;
|
|
17
|
+
splatValues: string[];
|
|
18
|
+
score: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type DfsBestState = {
|
|
22
|
+
best: BestMatch | null;
|
|
23
|
+
bestScore: number;
|
|
24
|
+
foundMatch: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function dfsBest(
|
|
28
|
+
registry: PatternRegistry,
|
|
29
|
+
node: SegmentNode,
|
|
30
|
+
segments: string[],
|
|
31
|
+
depth: number,
|
|
32
|
+
score: number,
|
|
33
|
+
state: DfsBestState,
|
|
34
|
+
checkTrailingSlash: boolean,
|
|
35
|
+
): void {
|
|
36
|
+
const atNormalEnd = checkTrailingSlash && depth === segments.length - 1;
|
|
37
|
+
|
|
38
|
+
if (node.pattern.length > 0) {
|
|
39
|
+
const rp = registry.dynamicPatterns.get(node.pattern);
|
|
40
|
+
if (rp) {
|
|
41
|
+
if (
|
|
42
|
+
depth === segments.length ||
|
|
43
|
+
node.nodeType === NODE_SPLAT ||
|
|
44
|
+
atNormalEnd
|
|
45
|
+
) {
|
|
46
|
+
if (!state.foundMatch || score > state.bestScore) {
|
|
47
|
+
state.best = {
|
|
48
|
+
registeredPattern: rp,
|
|
49
|
+
params: {},
|
|
50
|
+
splatValues: [],
|
|
51
|
+
score,
|
|
52
|
+
};
|
|
53
|
+
state.bestScore = score;
|
|
54
|
+
state.foundMatch = true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (depth >= segments.length) return;
|
|
61
|
+
|
|
62
|
+
if (node.children !== null) {
|
|
63
|
+
const child = node.children.get(segments[depth]!);
|
|
64
|
+
if (child) {
|
|
65
|
+
dfsBest(
|
|
66
|
+
registry,
|
|
67
|
+
child,
|
|
68
|
+
segments,
|
|
69
|
+
depth + 1,
|
|
70
|
+
score + SCORE_STATIC_MATCH,
|
|
71
|
+
state,
|
|
72
|
+
checkTrailingSlash,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
if (
|
|
76
|
+
state.foundMatch &&
|
|
77
|
+
depth + 1 === segments.length &&
|
|
78
|
+
child.pattern !== ""
|
|
79
|
+
) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for (const child of node.dynChildren) {
|
|
86
|
+
switch (child.nodeType) {
|
|
87
|
+
case NODE_DYNAMIC:
|
|
88
|
+
if (segments[depth] !== "") {
|
|
89
|
+
dfsBest(
|
|
90
|
+
registry,
|
|
91
|
+
child,
|
|
92
|
+
segments,
|
|
93
|
+
depth + 1,
|
|
94
|
+
score + SCORE_DYNAMIC,
|
|
95
|
+
state,
|
|
96
|
+
checkTrailingSlash,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
|
|
101
|
+
case NODE_SPLAT:
|
|
102
|
+
if (child.pattern.length > 0) {
|
|
103
|
+
const rp = registry.dynamicPatterns.get(child.pattern);
|
|
104
|
+
if (rp && !state.foundMatch) {
|
|
105
|
+
state.best = {
|
|
106
|
+
registeredPattern: rp,
|
|
107
|
+
params: {},
|
|
108
|
+
splatValues: [],
|
|
109
|
+
score: 0,
|
|
110
|
+
};
|
|
111
|
+
state.foundMatch = true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function findBestMatch(
|
|
120
|
+
registry: PatternRegistry,
|
|
121
|
+
realPath: string,
|
|
122
|
+
): BestMatch | null {
|
|
123
|
+
// Check static patterns first
|
|
124
|
+
const rr = registry.staticPatterns.get(realPath);
|
|
125
|
+
if (rr) {
|
|
126
|
+
return {
|
|
127
|
+
registeredPattern: rr,
|
|
128
|
+
params: {},
|
|
129
|
+
splatValues: [],
|
|
130
|
+
score: 0,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const segments = parseSegments(realPath);
|
|
135
|
+
const hasTrailingSlash =
|
|
136
|
+
realPath.length > 0 && realPath[realPath.length - 1] === "/";
|
|
137
|
+
|
|
138
|
+
// Check static pattern without trailing slash
|
|
139
|
+
if (hasTrailingSlash) {
|
|
140
|
+
const pathWithoutTrailingSlash = realPath.substring(
|
|
141
|
+
0,
|
|
142
|
+
realPath.length - 1,
|
|
143
|
+
);
|
|
144
|
+
const rrWithoutSlash = registry.staticPatterns.get(
|
|
145
|
+
pathWithoutTrailingSlash,
|
|
146
|
+
);
|
|
147
|
+
if (rrWithoutSlash) {
|
|
148
|
+
return {
|
|
149
|
+
registeredPattern: rrWithoutSlash,
|
|
150
|
+
params: {},
|
|
151
|
+
splatValues: [],
|
|
152
|
+
score: 0,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Search for dynamic patterns
|
|
158
|
+
const state: DfsBestState = {
|
|
159
|
+
best: null,
|
|
160
|
+
bestScore: 0,
|
|
161
|
+
foundMatch: false,
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
dfsBest(
|
|
165
|
+
registry,
|
|
166
|
+
registry.rootNode,
|
|
167
|
+
segments,
|
|
168
|
+
0,
|
|
169
|
+
0,
|
|
170
|
+
state,
|
|
171
|
+
hasTrailingSlash,
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
if (!state.foundMatch || !state.best) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Populate params
|
|
179
|
+
if (state.best.registeredPattern.numberOfDynamicParamSegs > 0) {
|
|
180
|
+
const params: Params = {};
|
|
181
|
+
for (
|
|
182
|
+
let i = 0;
|
|
183
|
+
i < state.best.registeredPattern.normalizedSegments.length;
|
|
184
|
+
i++
|
|
185
|
+
) {
|
|
186
|
+
const seg = state.best.registeredPattern.normalizedSegments[i]!;
|
|
187
|
+
if (seg.segType === SEG_TYPES.dynamic) {
|
|
188
|
+
params[seg.normalizedVal.substring(1)] = segments[i]!;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
state.best.params = params;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Populate splat values
|
|
195
|
+
if (
|
|
196
|
+
state.best.registeredPattern.normalizedPattern === "/*" ||
|
|
197
|
+
state.best.registeredPattern.lastSegIsNonRootSplat
|
|
198
|
+
) {
|
|
199
|
+
state.best.splatValues = segments.slice(
|
|
200
|
+
state.best.registeredPattern.normalizedSegments.length - 1,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return state.best;
|
|
205
|
+
}
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { parseSegments } from "./parse_segments.ts";
|
|
2
|
+
import type {
|
|
3
|
+
Params,
|
|
4
|
+
PatternRegistry,
|
|
5
|
+
RegisteredPattern,
|
|
6
|
+
SegmentNode,
|
|
7
|
+
} from "./register.ts";
|
|
8
|
+
import { NODE_DYNAMIC, NODE_SPLAT, SEG_TYPES } from "./register.ts";
|
|
9
|
+
|
|
10
|
+
export type Match = {
|
|
11
|
+
registeredPattern: RegisteredPattern;
|
|
12
|
+
params: Params;
|
|
13
|
+
splatValues: string[];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type FindNestedMatchesResult = {
|
|
17
|
+
params: Params;
|
|
18
|
+
splatValues: string[];
|
|
19
|
+
matches: Match[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function stripTrailingSlash(pattern: string): string {
|
|
23
|
+
return pattern.length > 0 && pattern[pattern.length - 1] === "/"
|
|
24
|
+
? pattern.substring(0, pattern.length - 1)
|
|
25
|
+
: pattern;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function dfsNestedMatches(
|
|
29
|
+
registry: PatternRegistry,
|
|
30
|
+
node: SegmentNode,
|
|
31
|
+
segments: string[],
|
|
32
|
+
depth: number,
|
|
33
|
+
params: Params,
|
|
34
|
+
matches: Map<string, Match>,
|
|
35
|
+
): void {
|
|
36
|
+
if (node.pattern.length > 0) {
|
|
37
|
+
const rp = registry.dynamicPatterns.get(node.pattern);
|
|
38
|
+
if (rp && node.pattern !== "/*") {
|
|
39
|
+
const paramsCopy = { ...params };
|
|
40
|
+
let splatValues: string[] = [];
|
|
41
|
+
|
|
42
|
+
if (node.nodeType === NODE_SPLAT && depth < segments.length) {
|
|
43
|
+
splatValues = segments.slice(depth);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
matches.set(node.pattern, {
|
|
47
|
+
registeredPattern: rp,
|
|
48
|
+
params: paramsCopy,
|
|
49
|
+
splatValues,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if (depth === segments.length) {
|
|
53
|
+
const indexPattern = node.pattern + "/";
|
|
54
|
+
const rpIndex = registry.dynamicPatterns.get(indexPattern);
|
|
55
|
+
if (rpIndex) {
|
|
56
|
+
matches.set(indexPattern, {
|
|
57
|
+
registeredPattern: rpIndex,
|
|
58
|
+
params: paramsCopy,
|
|
59
|
+
splatValues: [],
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (depth >= segments.length) return;
|
|
67
|
+
|
|
68
|
+
const seg = segments[depth]!;
|
|
69
|
+
|
|
70
|
+
if (node.children !== null) {
|
|
71
|
+
const child = node.children.get(seg);
|
|
72
|
+
if (child) {
|
|
73
|
+
dfsNestedMatches(
|
|
74
|
+
registry,
|
|
75
|
+
child,
|
|
76
|
+
segments,
|
|
77
|
+
depth + 1,
|
|
78
|
+
params,
|
|
79
|
+
matches,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
for (const child of node.dynChildren) {
|
|
85
|
+
switch (child.nodeType) {
|
|
86
|
+
case NODE_DYNAMIC: {
|
|
87
|
+
const oldVal = params[child.paramName];
|
|
88
|
+
const hadVal = oldVal !== undefined;
|
|
89
|
+
params[child.paramName] = seg;
|
|
90
|
+
|
|
91
|
+
dfsNestedMatches(
|
|
92
|
+
registry,
|
|
93
|
+
child,
|
|
94
|
+
segments,
|
|
95
|
+
depth + 1,
|
|
96
|
+
params,
|
|
97
|
+
matches,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if (hadVal) {
|
|
101
|
+
params[child.paramName] = oldVal!;
|
|
102
|
+
} else {
|
|
103
|
+
delete params[child.paramName];
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case NODE_SPLAT:
|
|
108
|
+
dfsNestedMatches(
|
|
109
|
+
registry,
|
|
110
|
+
child,
|
|
111
|
+
segments,
|
|
112
|
+
depth,
|
|
113
|
+
params,
|
|
114
|
+
matches,
|
|
115
|
+
);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function flattenAndSortMatches(
|
|
122
|
+
matches: Map<string, Match>,
|
|
123
|
+
realPath: string,
|
|
124
|
+
realSegmentLen: number,
|
|
125
|
+
): FindNestedMatchesResult | null {
|
|
126
|
+
const results: Match[] = Array.from(matches.values());
|
|
127
|
+
|
|
128
|
+
results.sort((i, j) => {
|
|
129
|
+
if (i.registeredPattern.lastSegIsIndex) return 1;
|
|
130
|
+
if (j.registeredPattern.lastSegIsIndex) return -1;
|
|
131
|
+
return (
|
|
132
|
+
i.registeredPattern.normalizedSegments.length -
|
|
133
|
+
j.registeredPattern.normalizedSegments.length
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
if (results.length === 0) return null;
|
|
138
|
+
|
|
139
|
+
const isNotSlashRoute = realPath !== "" && realPath !== "/";
|
|
140
|
+
if (
|
|
141
|
+
isNotSlashRoute &&
|
|
142
|
+
results.length === 1 &&
|
|
143
|
+
results[0]!.registeredPattern.normalizedPattern === ""
|
|
144
|
+
) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const lastMatch = results[results.length - 1]!;
|
|
149
|
+
|
|
150
|
+
if (
|
|
151
|
+
!lastMatch.registeredPattern.lastSegIsNonRootSplat &&
|
|
152
|
+
lastMatch.registeredPattern.normalizedPattern !== "/*"
|
|
153
|
+
) {
|
|
154
|
+
const patternSegmentsLen =
|
|
155
|
+
lastMatch.registeredPattern.normalizedSegments.length;
|
|
156
|
+
|
|
157
|
+
if (patternSegmentsLen < realSegmentLen) return null;
|
|
158
|
+
|
|
159
|
+
if (
|
|
160
|
+
patternSegmentsLen === realSegmentLen &&
|
|
161
|
+
lastMatch.registeredPattern.numberOfDynamicParamSegs > 0 &&
|
|
162
|
+
Object.keys(lastMatch.params).length === 0
|
|
163
|
+
) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
params: lastMatch.params,
|
|
170
|
+
splatValues: lastMatch.splatValues,
|
|
171
|
+
matches: results,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function findNestedMatches(
|
|
176
|
+
registry: PatternRegistry,
|
|
177
|
+
realPath: string,
|
|
178
|
+
): FindNestedMatchesResult | null {
|
|
179
|
+
realPath = stripTrailingSlash(realPath);
|
|
180
|
+
|
|
181
|
+
const realSegments = parseSegments(realPath);
|
|
182
|
+
const matches: Map<string, Match> = new Map();
|
|
183
|
+
|
|
184
|
+
// Check for empty pattern
|
|
185
|
+
const emptyRR = registry.staticPatterns.get("");
|
|
186
|
+
if (emptyRR) {
|
|
187
|
+
matches.set(emptyRR.normalizedPattern, {
|
|
188
|
+
registeredPattern: emptyRR,
|
|
189
|
+
params: {},
|
|
190
|
+
splatValues: [],
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const realSegmentsLen = realSegments.length;
|
|
195
|
+
|
|
196
|
+
// Handle root path
|
|
197
|
+
if (realPath === "") {
|
|
198
|
+
const rr = registry.staticPatterns.get("/");
|
|
199
|
+
if (rr) {
|
|
200
|
+
matches.set(rr.normalizedPattern, {
|
|
201
|
+
registeredPattern: rr,
|
|
202
|
+
params: {},
|
|
203
|
+
splatValues: [],
|
|
204
|
+
});
|
|
205
|
+
} else {
|
|
206
|
+
const catchAllRR = registry.dynamicPatterns.get("/*");
|
|
207
|
+
if (catchAllRR) {
|
|
208
|
+
matches.set("/*", {
|
|
209
|
+
registeredPattern: catchAllRR,
|
|
210
|
+
params: {},
|
|
211
|
+
splatValues: [],
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return flattenAndSortMatches(matches, realPath, realSegmentsLen);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Check static patterns progressively
|
|
219
|
+
let pb = "";
|
|
220
|
+
let foundFullStatic = false;
|
|
221
|
+
|
|
222
|
+
for (let i = 0; i < realSegments.length; i++) {
|
|
223
|
+
pb += "/" + realSegments[i];
|
|
224
|
+
const rr = registry.staticPatterns.get(pb);
|
|
225
|
+
if (rr) {
|
|
226
|
+
matches.set(rr.normalizedPattern, {
|
|
227
|
+
registeredPattern: rr,
|
|
228
|
+
params: {},
|
|
229
|
+
splatValues: [],
|
|
230
|
+
});
|
|
231
|
+
if (i === realSegmentsLen - 1) foundFullStatic = true;
|
|
232
|
+
}
|
|
233
|
+
if (i === realSegmentsLen - 1) {
|
|
234
|
+
pb += "/";
|
|
235
|
+
const rrWithSlash = registry.staticPatterns.get(pb);
|
|
236
|
+
if (rrWithSlash) {
|
|
237
|
+
matches.set(rrWithSlash.normalizedPattern, {
|
|
238
|
+
registeredPattern: rrWithSlash,
|
|
239
|
+
params: {},
|
|
240
|
+
splatValues: [],
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Check dynamic patterns if no full static match
|
|
247
|
+
if (!foundFullStatic) {
|
|
248
|
+
const rr = registry.dynamicPatterns.get("/*");
|
|
249
|
+
if (rr) {
|
|
250
|
+
matches.set("/*", {
|
|
251
|
+
registeredPattern: rr,
|
|
252
|
+
params: {},
|
|
253
|
+
splatValues: realSegments,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const params: Params = {};
|
|
258
|
+
dfsNestedMatches(
|
|
259
|
+
registry,
|
|
260
|
+
registry.rootNode,
|
|
261
|
+
realSegments,
|
|
262
|
+
0,
|
|
263
|
+
params,
|
|
264
|
+
matches,
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Clean up catch-all pattern if necessary
|
|
269
|
+
const hasEmptyRR = emptyRR !== undefined;
|
|
270
|
+
if (matches.has("/*")) {
|
|
271
|
+
if (hasEmptyRR) {
|
|
272
|
+
if (matches.size > 2) matches.delete("/*");
|
|
273
|
+
} else if (matches.size > 1) {
|
|
274
|
+
matches.delete("/*");
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (matches.size < 2) {
|
|
279
|
+
return flattenAndSortMatches(matches, realPath, realSegmentsLen);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Find longest segment matches
|
|
283
|
+
let longestSegmentLen = 0;
|
|
284
|
+
const longestSegmentMatches: Map<string, Match> = new Map();
|
|
285
|
+
|
|
286
|
+
for (const match of matches.values()) {
|
|
287
|
+
if (
|
|
288
|
+
match.registeredPattern.normalizedSegments.length >
|
|
289
|
+
longestSegmentLen
|
|
290
|
+
) {
|
|
291
|
+
longestSegmentLen =
|
|
292
|
+
match.registeredPattern.normalizedSegments.length;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
for (const match of matches.values()) {
|
|
297
|
+
if (
|
|
298
|
+
match.registeredPattern.normalizedSegments.length ===
|
|
299
|
+
longestSegmentLen
|
|
300
|
+
) {
|
|
301
|
+
longestSegmentMatches.set(
|
|
302
|
+
match.registeredPattern.lastSegType,
|
|
303
|
+
match,
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Remove shorter matches
|
|
309
|
+
for (const [pattern, match] of matches) {
|
|
310
|
+
if (
|
|
311
|
+
match.registeredPattern.normalizedSegments.length <
|
|
312
|
+
longestSegmentLen
|
|
313
|
+
) {
|
|
314
|
+
if (
|
|
315
|
+
match.registeredPattern.lastSegIsNonRootSplat ||
|
|
316
|
+
match.registeredPattern.lastSegIsIndex
|
|
317
|
+
) {
|
|
318
|
+
matches.delete(pattern);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (matches.size < 2) {
|
|
324
|
+
return flattenAndSortMatches(matches, realPath, realSegmentsLen);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Handle conflicts between longest matches
|
|
328
|
+
if (longestSegmentMatches.size > 1) {
|
|
329
|
+
const indexMatch = longestSegmentMatches.get(SEG_TYPES.index);
|
|
330
|
+
if (indexMatch) {
|
|
331
|
+
matches.delete(indexMatch.registeredPattern.normalizedPattern);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const dynamicExists = longestSegmentMatches.has(SEG_TYPES.dynamic);
|
|
335
|
+
const splatExists = longestSegmentMatches.has(SEG_TYPES.splat);
|
|
336
|
+
|
|
337
|
+
if (
|
|
338
|
+
realSegmentsLen === longestSegmentLen &&
|
|
339
|
+
dynamicExists &&
|
|
340
|
+
splatExists
|
|
341
|
+
) {
|
|
342
|
+
const splatMatch = longestSegmentMatches.get(SEG_TYPES.splat)!;
|
|
343
|
+
matches.delete(splatMatch.registeredPattern.normalizedPattern);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (
|
|
347
|
+
realSegmentsLen > longestSegmentLen &&
|
|
348
|
+
splatExists &&
|
|
349
|
+
dynamicExists
|
|
350
|
+
) {
|
|
351
|
+
const dynamicMatch = longestSegmentMatches.get(SEG_TYPES.dynamic)!;
|
|
352
|
+
matches.delete(dynamicMatch.registeredPattern.normalizedPattern);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return flattenAndSortMatches(matches, realPath, realSegmentsLen);
|
|
357
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function parseSegments(path: string): string[] {
|
|
2
|
+
if (path === "" || path === "/") {
|
|
3
|
+
return path === "/" ? [""] : [];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const startIdx = path.startsWith("/") ? 1 : 0;
|
|
7
|
+
const segments: string[] = [];
|
|
8
|
+
let start = startIdx;
|
|
9
|
+
|
|
10
|
+
for (let i = startIdx; i < path.length; i++) {
|
|
11
|
+
if (path[i] === "/") {
|
|
12
|
+
if (i > start) {
|
|
13
|
+
segments.push(path.substring(start, i));
|
|
14
|
+
}
|
|
15
|
+
start = i + 1;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Add the last segment if it exists
|
|
20
|
+
if (start < path.length) {
|
|
21
|
+
segments.push(path.substring(start));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Add empty segment for trailing slash
|
|
25
|
+
if (path.endsWith("/")) {
|
|
26
|
+
segments.push("");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return segments;
|
|
30
|
+
}
|