@vesk/runtime 0.0.1
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/README.md +23 -0
- package/dist/action.d.ts +43 -0
- package/dist/action.d.ts.map +1 -0
- package/dist/action.js +84 -0
- package/dist/bindings.d.ts +4 -0
- package/dist/bindings.d.ts.map +1 -0
- package/dist/bindings.js +137 -0
- package/dist/context.d.ts +15 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +34 -0
- package/dist/experiment.d.ts +17 -0
- package/dist/experiment.d.ts.map +1 -0
- package/dist/experiment.js +71 -0
- package/dist/form.d.ts +36 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +278 -0
- package/dist/hmr-client.d.ts +1 -0
- package/dist/hmr-client.d.ts.map +1 -0
- package/dist/hmr-client.js +273 -0
- package/dist/hydrate.d.ts +34 -0
- package/dist/hydrate.d.ts.map +1 -0
- package/dist/hydrate.js +248 -0
- package/dist/image.d.ts +19 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/image.js +51 -0
- package/dist/index-client.d.ts +16 -0
- package/dist/index-client.d.ts.map +1 -0
- package/dist/index-client.js +15 -0
- package/dist/index-server.d.ts +15 -0
- package/dist/index-server.d.ts.map +1 -0
- package/dist/index-server.js +14 -0
- package/dist/isr.d.ts +27 -0
- package/dist/isr.d.ts.map +1 -0
- package/dist/isr.js +143 -0
- package/dist/md.d.ts +17 -0
- package/dist/md.d.ts.map +1 -0
- package/dist/md.js +507 -0
- package/dist/package.json +23 -0
- package/dist/portal.d.ts +8 -0
- package/dist/portal.d.ts.map +1 -0
- package/dist/portal.js +20 -0
- package/dist/reconcile.d.ts +3 -0
- package/dist/reconcile.d.ts.map +1 -0
- package/dist/reconcile.js +66 -0
- package/dist/request.d.ts +188 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +624 -0
- package/dist/resource.d.ts +47 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +502 -0
- package/dist/ripple-blocks.d.ts +18 -0
- package/dist/ripple-blocks.d.ts.map +1 -0
- package/dist/ripple-blocks.js +184 -0
- package/dist/ripple-constants.d.ts +42 -0
- package/dist/ripple-constants.d.ts.map +1 -0
- package/dist/ripple-constants.js +41 -0
- package/dist/ripple-runtime.d.ts +125 -0
- package/dist/ripple-runtime.d.ts.map +1 -0
- package/dist/ripple-runtime.js +891 -0
- package/dist/ripple-utils.d.ts +12 -0
- package/dist/ripple-utils.d.ts.map +1 -0
- package/dist/ripple-utils.js +10 -0
- package/dist/router-components.d.ts +83 -0
- package/dist/router-components.d.ts.map +1 -0
- package/dist/router-components.js +320 -0
- package/dist/router-match.d.ts +40 -0
- package/dist/router-match.d.ts.map +1 -0
- package/dist/router-match.js +158 -0
- package/dist/router.d.ts +56 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +1330 -0
- package/dist/seo.d.ts +94 -0
- package/dist/seo.d.ts.map +1 -0
- package/dist/seo.js +138 -0
- package/dist/suspense.d.ts +1 -0
- package/dist/suspense.d.ts.map +1 -0
- package/dist/suspense.js +14 -0
- package/dist/track.d.ts +20 -0
- package/dist/track.d.ts.map +1 -0
- package/dist/track.js +124 -0
- package/package.json +55 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function is_ripple_object(v: unknown): v is {
|
|
2
|
+
f: number;
|
|
3
|
+
};
|
|
4
|
+
export declare const define_property: <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T;
|
|
5
|
+
export declare const get_descriptor: (o: any, p: PropertyKey) => PropertyDescriptor | undefined;
|
|
6
|
+
export declare const is_array: (arg: any) => arg is any[];
|
|
7
|
+
export declare const object_keys: {
|
|
8
|
+
(o: object): string[];
|
|
9
|
+
(o: {}): string[];
|
|
10
|
+
};
|
|
11
|
+
export declare function get_own_property_symbols(obj: Record<string | symbol, unknown>): symbol[];
|
|
12
|
+
//# sourceMappingURL=ripple-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ripple-utils.d.ts","sourceRoot":"","sources":["../src/ripple-utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI;IAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAE/D;AAED,eAAO,MAAM,eAAe,gFAAwB,CAAC;AACrD,eAAO,MAAM,cAAc,4DAAkC,CAAC;AAC9D,eAAO,MAAM,QAAQ,4BAAgB,CAAC;AACtC,eAAO,MAAM,WAAW;;;CAAc,CAAC;AACvC,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,CAExF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function is_ripple_object(v) {
|
|
2
|
+
return typeof v === 'object' && v !== null && typeof v.f === 'number';
|
|
3
|
+
}
|
|
4
|
+
export const define_property = Object.defineProperty;
|
|
5
|
+
export const get_descriptor = Object.getOwnPropertyDescriptor;
|
|
6
|
+
export const is_array = Array.isArray;
|
|
7
|
+
export const object_keys = Object.keys;
|
|
8
|
+
export function get_own_property_symbols(obj) {
|
|
9
|
+
return Object.getOwnPropertySymbols(obj);
|
|
10
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createHydrateWalker } from '@vesk/runtime/src/hydrate';
|
|
2
|
+
interface Router {
|
|
3
|
+
start(): Router;
|
|
4
|
+
navigate(path: string, opts?: {
|
|
5
|
+
replace?: boolean;
|
|
6
|
+
}): void;
|
|
7
|
+
prefetch(path: string): void;
|
|
8
|
+
readonly currentPath: string;
|
|
9
|
+
_outletPlaceholders?: HTMLElement[];
|
|
10
|
+
_currentSegments?: {
|
|
11
|
+
rendered: Node;
|
|
12
|
+
}[] | null;
|
|
13
|
+
_depth?: number;
|
|
14
|
+
[k: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
export declare class Redirect extends Error {
|
|
17
|
+
url: string;
|
|
18
|
+
status: number;
|
|
19
|
+
name: 'Redirect';
|
|
20
|
+
constructor(url: string, status?: number);
|
|
21
|
+
}
|
|
22
|
+
export declare function redirect(url: string, status?: number): never;
|
|
23
|
+
export declare function permanentRedirect(url: string): never;
|
|
24
|
+
export declare class NotFoundError extends Error {
|
|
25
|
+
name: 'NotFoundError';
|
|
26
|
+
constructor(msg?: string);
|
|
27
|
+
}
|
|
28
|
+
export declare function notFound(): never;
|
|
29
|
+
export declare const RouterCtx: import("@vesk/runtime/src/context").Context<Router | null>;
|
|
30
|
+
export declare let __isHydrating: boolean;
|
|
31
|
+
export declare function setIsHydrating(v: boolean): void;
|
|
32
|
+
export declare const _state: {
|
|
33
|
+
path: import("@vesk/runtime/src/ripple-runtime").Derived | import("@vesk/runtime/src/ripple-runtime").Tracked;
|
|
34
|
+
params: import("@vesk/runtime/src/ripple-runtime").Derived | import("@vesk/runtime/src/ripple-runtime").Tracked;
|
|
35
|
+
search: import("@vesk/runtime/src/ripple-runtime").Derived | import("@vesk/runtime/src/ripple-runtime").Tracked;
|
|
36
|
+
};
|
|
37
|
+
export declare const _scrollPositions: Map<string, number>;
|
|
38
|
+
export declare let _isPopStateNavigation: boolean;
|
|
39
|
+
export declare function setIsPopStateNavigation(v: boolean): void;
|
|
40
|
+
export declare function setCurrentRouter(r: Router | null): void;
|
|
41
|
+
export declare function getCurrentRouter(): Router | null;
|
|
42
|
+
export declare function findLoadingComponent(chain: Record<string, unknown>[]): Function | null;
|
|
43
|
+
export declare function findErrorComponent(chain: Record<string, unknown>[]): Function | null;
|
|
44
|
+
export declare function findNotFoundComponent(chain: Record<string, unknown>[]): Function | null;
|
|
45
|
+
export declare function showLoadingInContainer(container: HTMLElement, loadingFn: Function, params: Record<string, string>): void;
|
|
46
|
+
export declare function handleScroll(pathname: string, isReplace?: boolean): void;
|
|
47
|
+
export declare function applyHead(headHtml: string): void;
|
|
48
|
+
interface OutletProps {
|
|
49
|
+
children?: unknown;
|
|
50
|
+
}
|
|
51
|
+
export declare function Outlet(props?: OutletProps): Node;
|
|
52
|
+
interface LinkProps {
|
|
53
|
+
href: string;
|
|
54
|
+
children?: unknown;
|
|
55
|
+
class?: string;
|
|
56
|
+
style?: string;
|
|
57
|
+
target?: string;
|
|
58
|
+
rel?: string;
|
|
59
|
+
[k: string]: unknown;
|
|
60
|
+
}
|
|
61
|
+
type HydrateWalker = ReturnType<typeof createHydrateWalker>;
|
|
62
|
+
export declare function Link(props: LinkProps, registry?: Map<string, unknown>, hydrate?: HydrateWalker): Node | string;
|
|
63
|
+
interface NavLinkProps extends LinkProps {
|
|
64
|
+
activeClass?: string;
|
|
65
|
+
ariaCurrent?: boolean | string;
|
|
66
|
+
}
|
|
67
|
+
export declare function NavLink(props: NavLinkProps, registry?: Map<string, unknown>, hydrate?: HydrateWalker): Node | string;
|
|
68
|
+
export declare function useNavigate(): (path: string, opts?: {
|
|
69
|
+
replace?: boolean;
|
|
70
|
+
}) => void;
|
|
71
|
+
export declare function useParams(): Record<string, string>;
|
|
72
|
+
export declare function usePathname(): string;
|
|
73
|
+
export declare function useSearchParams(): [URLSearchParams, (next: Record<string, string> | string) => void];
|
|
74
|
+
export declare function useRouter(): {
|
|
75
|
+
push: (href: string) => void;
|
|
76
|
+
replace: (href: string) => void;
|
|
77
|
+
back: () => void;
|
|
78
|
+
forward: () => void;
|
|
79
|
+
refresh: () => void;
|
|
80
|
+
prefetch: (href: string) => void;
|
|
81
|
+
};
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=router-components.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-components.d.ts","sourceRoot":"","sources":["../src/router-components.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,UAAU,MAAM;IACf,KAAK,IAAI,MAAM,CAAC;IAChB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAA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EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,CAAC,EAAE,aAAa,GACrB,IAAI,GAAG,MAAM,CAoEf;AAED,UAAU,YAAa,SAAQ,SAAS;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CAC/B;AAED,wBAAgB,OAAO,CACtB,KAAK,EAAE,YAAY,EACnB,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,CAAC,EAAE,aAAa,GACrB,IAAI,GAAG,MAAM,CAuCf;AAED,wBAAgB,WAAW,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,KAAK,IAAI,CAUlF;AAED,wBAAgB,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAElD;AAED,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,eAAe,IAAI,CAAC,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,KAAK,IAAI,CAAC,CAWpG;AAED,wBAAgB,SAAS,IAAI;IAC5B,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,CAUA"}
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { track, get } from '@vesk/runtime/src/ripple-runtime';
|
|
2
|
+
import { createContext } from '@vesk/runtime/src/context';
|
|
3
|
+
import { createHydrateWalker } from '@vesk/runtime/src/hydrate';
|
|
4
|
+
export class Redirect extends Error {
|
|
5
|
+
url;
|
|
6
|
+
status;
|
|
7
|
+
constructor(url, status = 302) {
|
|
8
|
+
super(`Redirect to ${url}`);
|
|
9
|
+
this.url = url;
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.name = 'Redirect';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function redirect(url, status = 302) {
|
|
15
|
+
throw new Redirect(url, status);
|
|
16
|
+
}
|
|
17
|
+
export function permanentRedirect(url) {
|
|
18
|
+
throw new Redirect(url, 308);
|
|
19
|
+
}
|
|
20
|
+
export class NotFoundError extends Error {
|
|
21
|
+
constructor(msg = 'Not Found') {
|
|
22
|
+
super(msg);
|
|
23
|
+
this.name = 'NotFoundError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function notFound() {
|
|
27
|
+
throw new NotFoundError();
|
|
28
|
+
}
|
|
29
|
+
export const RouterCtx = createContext(null);
|
|
30
|
+
let _currentRouter = null;
|
|
31
|
+
let _outletId = 0;
|
|
32
|
+
export let __isHydrating = false;
|
|
33
|
+
export function setIsHydrating(v) {
|
|
34
|
+
__isHydrating = v;
|
|
35
|
+
}
|
|
36
|
+
export const _state = {
|
|
37
|
+
path: track('/'),
|
|
38
|
+
params: track({}),
|
|
39
|
+
search: track(''),
|
|
40
|
+
};
|
|
41
|
+
export const _scrollPositions = new Map();
|
|
42
|
+
export let _isPopStateNavigation = false;
|
|
43
|
+
export function setIsPopStateNavigation(v) {
|
|
44
|
+
_isPopStateNavigation = v;
|
|
45
|
+
}
|
|
46
|
+
export function setCurrentRouter(r) {
|
|
47
|
+
_currentRouter = r;
|
|
48
|
+
}
|
|
49
|
+
export function getCurrentRouter() {
|
|
50
|
+
return _currentRouter;
|
|
51
|
+
}
|
|
52
|
+
export function findLoadingComponent(chain) {
|
|
53
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
54
|
+
if (chain[i].loading)
|
|
55
|
+
return chain[i].loading;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
export function findErrorComponent(chain) {
|
|
60
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
61
|
+
if (chain[i].error)
|
|
62
|
+
return chain[i].error;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
export function findNotFoundComponent(chain) {
|
|
67
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
68
|
+
if (chain[i].notFound)
|
|
69
|
+
return chain[i].notFound;
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
export function showLoadingInContainer(container, loadingFn, params) {
|
|
74
|
+
const tempRoot = document.createDocumentFragment();
|
|
75
|
+
const walker = createHydrateWalker(tempRoot, []);
|
|
76
|
+
const loadingContent = loadingFn({ params }, new Map(), walker);
|
|
77
|
+
container.replaceChildren();
|
|
78
|
+
if (loadingContent && typeof loadingContent === 'object' && loadingContent.nodeType) {
|
|
79
|
+
container.appendChild(loadingContent);
|
|
80
|
+
}
|
|
81
|
+
else if (typeof loadingContent === 'string') {
|
|
82
|
+
container.innerHTML = loadingContent;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export function handleScroll(pathname, isReplace) {
|
|
86
|
+
if (typeof window === 'undefined' || typeof window.scrollTo !== 'function')
|
|
87
|
+
return;
|
|
88
|
+
if (_isPopStateNavigation) {
|
|
89
|
+
setIsPopStateNavigation(false);
|
|
90
|
+
const savedY = _scrollPositions.get(pathname);
|
|
91
|
+
requestAnimationFrame(() => {
|
|
92
|
+
window.scrollTo(0, savedY !== undefined ? savedY : 0);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else if (!isReplace) {
|
|
96
|
+
requestAnimationFrame(() => window.scrollTo(0, 0));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const HEAD_MARKER = 'data-vesk-head';
|
|
100
|
+
export function applyHead(headHtml) {
|
|
101
|
+
if (typeof document === 'undefined' || !headHtml)
|
|
102
|
+
return;
|
|
103
|
+
const head = document.head;
|
|
104
|
+
if (!head)
|
|
105
|
+
return;
|
|
106
|
+
for (const el of Array.from(head.querySelectorAll('[' + HEAD_MARKER + ']'))) {
|
|
107
|
+
el.remove();
|
|
108
|
+
}
|
|
109
|
+
const titleMatch = headHtml.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
|
|
110
|
+
if (titleMatch) {
|
|
111
|
+
const existing = head.querySelector('title');
|
|
112
|
+
if (existing)
|
|
113
|
+
existing.textContent = titleMatch[1];
|
|
114
|
+
else {
|
|
115
|
+
const t = document.createElement('title');
|
|
116
|
+
t.textContent = titleMatch[1];
|
|
117
|
+
head.appendChild(t);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
for (const m of headHtml.matchAll(/<meta\b([^>]*)>/gi)) {
|
|
121
|
+
const meta = document.createElement('meta');
|
|
122
|
+
const raw = m[1] || '';
|
|
123
|
+
for (const attrMatch of raw.matchAll(/([a-zA-Z0-9\-:]+)\s*=\s*("([^"]*)"|'([^']*)')/g)) {
|
|
124
|
+
const name = attrMatch[1];
|
|
125
|
+
const value = attrMatch[3] ?? attrMatch[4] ?? '';
|
|
126
|
+
if (name.toLowerCase() === 'charset')
|
|
127
|
+
continue;
|
|
128
|
+
meta.setAttribute(name, value);
|
|
129
|
+
}
|
|
130
|
+
if (!meta.hasAttributes())
|
|
131
|
+
continue;
|
|
132
|
+
meta.setAttribute(HEAD_MARKER, '');
|
|
133
|
+
head.appendChild(meta);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export function Outlet(props) {
|
|
137
|
+
const router = RouterCtx.get();
|
|
138
|
+
if (!router)
|
|
139
|
+
return document.createComment('outlet');
|
|
140
|
+
const div = document.createElement('div');
|
|
141
|
+
div.setAttribute('data-vesk-outlet', String(_outletId++));
|
|
142
|
+
div.style.display = 'contents';
|
|
143
|
+
if (router._outletPlaceholders) {
|
|
144
|
+
router._outletPlaceholders.push(div);
|
|
145
|
+
}
|
|
146
|
+
const seg = router._currentSegments && router._currentSegments[router._depth || 0];
|
|
147
|
+
if (seg && seg.rendered) {
|
|
148
|
+
div.appendChild(seg.rendered);
|
|
149
|
+
}
|
|
150
|
+
return div;
|
|
151
|
+
}
|
|
152
|
+
export function Link(props, registry, hydrate) {
|
|
153
|
+
const href = props.href || '#';
|
|
154
|
+
if (hydrate && hydrate.nextElement) {
|
|
155
|
+
let a = hydrate.nextElement('a');
|
|
156
|
+
if (a && !a.parentNode && hydrate.root) {
|
|
157
|
+
const existing = hydrate.root.querySelector('a');
|
|
158
|
+
if (existing)
|
|
159
|
+
a = existing;
|
|
160
|
+
}
|
|
161
|
+
if (props.children != null) {
|
|
162
|
+
if (typeof props.children === 'string' || typeof props.children === 'number') {
|
|
163
|
+
a.textContent = String(props.children);
|
|
164
|
+
}
|
|
165
|
+
else if (props.children.textContent) {
|
|
166
|
+
a.textContent = props.children.textContent;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
a.addEventListener('click', (e) => {
|
|
170
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0)
|
|
171
|
+
return;
|
|
172
|
+
if (props.target === '_blank')
|
|
173
|
+
return;
|
|
174
|
+
e.preventDefault();
|
|
175
|
+
e.stopPropagation();
|
|
176
|
+
const nav = useNavigate();
|
|
177
|
+
nav(href);
|
|
178
|
+
});
|
|
179
|
+
return document.createDocumentFragment();
|
|
180
|
+
}
|
|
181
|
+
const attrs = [
|
|
182
|
+
`href="${href.replace(/"/g, '"')}"`,
|
|
183
|
+
props.class ? `class="${String(props.class).replace(/"/g, '"')}"` : '',
|
|
184
|
+
props.style ? `style="${String(props.style).replace(/"/g, '"')}"` : '',
|
|
185
|
+
props.target ? `target="${String(props.target).replace(/"/g, '"')}"` : '',
|
|
186
|
+
props.rel ? `rel="${String(props.rel).replace(/"/g, '"')}"` : '',
|
|
187
|
+
].filter(Boolean).join(' ');
|
|
188
|
+
let childStr = '';
|
|
189
|
+
if (props.children != null) {
|
|
190
|
+
childStr = typeof props.children === 'string' ? props.children
|
|
191
|
+
: typeof props.children === 'number' ? String(props.children)
|
|
192
|
+
: '';
|
|
193
|
+
}
|
|
194
|
+
if (typeof document === 'undefined') {
|
|
195
|
+
return `<a ${attrs}>${childStr}</a>`;
|
|
196
|
+
}
|
|
197
|
+
const a = document.createElement('a');
|
|
198
|
+
a.href = href;
|
|
199
|
+
if (props.class)
|
|
200
|
+
a.className = props.class;
|
|
201
|
+
if (props.style)
|
|
202
|
+
a.setAttribute('style', props.style);
|
|
203
|
+
if (props.target)
|
|
204
|
+
a.target = props.target;
|
|
205
|
+
if (props.rel)
|
|
206
|
+
a.rel = props.rel;
|
|
207
|
+
if (childStr) {
|
|
208
|
+
a.textContent = childStr;
|
|
209
|
+
}
|
|
210
|
+
else if (props.children != null) {
|
|
211
|
+
if (props.children.nodeType) {
|
|
212
|
+
a.appendChild(props.children);
|
|
213
|
+
}
|
|
214
|
+
else if (Array.isArray(props.children)) {
|
|
215
|
+
for (const c of props.children) {
|
|
216
|
+
if (c && c.nodeType)
|
|
217
|
+
a.appendChild(c);
|
|
218
|
+
else if (c != null)
|
|
219
|
+
a.appendChild(document.createTextNode(String(c)));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
a.addEventListener('click', (e) => {
|
|
224
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0)
|
|
225
|
+
return;
|
|
226
|
+
if (props.target === '_blank')
|
|
227
|
+
return;
|
|
228
|
+
e.preventDefault();
|
|
229
|
+
e.stopPropagation();
|
|
230
|
+
const nav = useNavigate();
|
|
231
|
+
nav(href);
|
|
232
|
+
});
|
|
233
|
+
return a;
|
|
234
|
+
}
|
|
235
|
+
export function NavLink(props, registry, hydrate) {
|
|
236
|
+
if (typeof document === 'undefined') {
|
|
237
|
+
return Link(props, registry, hydrate);
|
|
238
|
+
}
|
|
239
|
+
if (__isHydrating) {
|
|
240
|
+
const a = document.querySelector(`a[href="${props.href}"]`);
|
|
241
|
+
if (a) {
|
|
242
|
+
if (props.children != null) {
|
|
243
|
+
if (typeof props.children === 'string' || typeof props.children === 'number') {
|
|
244
|
+
a.textContent = String(props.children);
|
|
245
|
+
}
|
|
246
|
+
else if (props.children.textContent) {
|
|
247
|
+
a.textContent = props.children.textContent;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
a.addEventListener('click', (e) => {
|
|
251
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0)
|
|
252
|
+
return;
|
|
253
|
+
if (props.target === '_blank')
|
|
254
|
+
return;
|
|
255
|
+
e.preventDefault();
|
|
256
|
+
e.stopPropagation();
|
|
257
|
+
const nav = useNavigate();
|
|
258
|
+
nav(props.href);
|
|
259
|
+
});
|
|
260
|
+
const path = usePathname();
|
|
261
|
+
const isActive = props.href === path || (props.href !== '/' && path.startsWith(props.href) && (path.length === props.href.length || path[props.href.length] === '/' || path[props.href.length] === '?'));
|
|
262
|
+
if (isActive) {
|
|
263
|
+
a.classList.add(props.activeClass || 'active');
|
|
264
|
+
if (props.ariaCurrent !== false)
|
|
265
|
+
a.setAttribute('aria-current', 'page');
|
|
266
|
+
}
|
|
267
|
+
return document.createDocumentFragment();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const a = Link(props, registry, hydrate);
|
|
271
|
+
const path = usePathname();
|
|
272
|
+
const isActive = props.href === path || (props.href !== '/' && path.startsWith(props.href) && (path.length === props.href.length || path[props.href.length] === '/' || path[props.href.length] === '?'));
|
|
273
|
+
if (isActive) {
|
|
274
|
+
a.classList.add(props.activeClass || 'active');
|
|
275
|
+
if (props.ariaCurrent !== false)
|
|
276
|
+
a.setAttribute('aria-current', 'page');
|
|
277
|
+
}
|
|
278
|
+
return a;
|
|
279
|
+
}
|
|
280
|
+
export function useNavigate() {
|
|
281
|
+
const router = RouterCtx.get() || _currentRouter;
|
|
282
|
+
return (path, opts = {}) => {
|
|
283
|
+
if (router && router.navigate) {
|
|
284
|
+
router.navigate(path, opts);
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
window.history.pushState({}, '', path);
|
|
288
|
+
_state.path.value = path;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
export function useParams() {
|
|
293
|
+
return get(_state.params);
|
|
294
|
+
}
|
|
295
|
+
export function usePathname() {
|
|
296
|
+
return get(_state.path);
|
|
297
|
+
}
|
|
298
|
+
export function useSearchParams() {
|
|
299
|
+
const s = get(_state.search);
|
|
300
|
+
const sp = new URLSearchParams(s || '');
|
|
301
|
+
const setter = (next) => {
|
|
302
|
+
const q = typeof next === 'string' ? next : new URLSearchParams(next).toString();
|
|
303
|
+
_state.search.value = q;
|
|
304
|
+
const nav = useNavigate();
|
|
305
|
+
const path = get(_state.path);
|
|
306
|
+
nav(path + (q ? '?' + q : ''), { replace: true });
|
|
307
|
+
};
|
|
308
|
+
return [sp, setter];
|
|
309
|
+
}
|
|
310
|
+
export function useRouter() {
|
|
311
|
+
const router = RouterCtx.get() || _currentRouter;
|
|
312
|
+
return {
|
|
313
|
+
push: (href) => router?.navigate?.(href),
|
|
314
|
+
replace: (href) => router?.navigate?.(href, { replace: true }),
|
|
315
|
+
back: () => window.history.back(),
|
|
316
|
+
forward: () => window.history.forward(),
|
|
317
|
+
refresh: () => router?.navigate?.(window.location.pathname, { replace: true }),
|
|
318
|
+
prefetch: (href) => router?.prefetch?.(href),
|
|
319
|
+
};
|
|
320
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface RouteNode {
|
|
2
|
+
path: string;
|
|
3
|
+
fullPath?: string;
|
|
4
|
+
isGroup?: boolean;
|
|
5
|
+
isDynamic?: boolean;
|
|
6
|
+
isCatchAll?: boolean;
|
|
7
|
+
page?: Function | null;
|
|
8
|
+
layout?: Function | null;
|
|
9
|
+
loading?: Function | null;
|
|
10
|
+
error?: Function | null;
|
|
11
|
+
notFound?: Function | null;
|
|
12
|
+
children?: RouteNode[];
|
|
13
|
+
segmentCount?: number;
|
|
14
|
+
_matchChain?: RouteNode[];
|
|
15
|
+
loader?: Function;
|
|
16
|
+
props?: Record<string, unknown>;
|
|
17
|
+
_head?: string;
|
|
18
|
+
[k: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface RouteMatch {
|
|
21
|
+
matchChain: RouteNode[];
|
|
22
|
+
params: Record<string, string>;
|
|
23
|
+
pathname?: string;
|
|
24
|
+
}
|
|
25
|
+
interface CompiledRoute {
|
|
26
|
+
regex: RegExp;
|
|
27
|
+
paramNames: string[];
|
|
28
|
+
}
|
|
29
|
+
export declare function compileRoutePattern(fullPath: string): CompiledRoute;
|
|
30
|
+
export declare function collectLayouts(nodes: RouteNode[], pathParts: string[]): {
|
|
31
|
+
layout: Function;
|
|
32
|
+
node: RouteNode;
|
|
33
|
+
}[];
|
|
34
|
+
export declare function matchRouteNode(node: RouteNode, pathParts: string[]): boolean;
|
|
35
|
+
export declare function extractParams(node: RouteNode, pathParts: string[]): Record<string, string>;
|
|
36
|
+
export declare function flattenLayoutChain(tree: RouteNode[], pathParts: string[], result?: RouteNode[]): RouteNode[];
|
|
37
|
+
export declare function matchRoute(tree: RouteNode[], pathname: string): RouteMatch | null;
|
|
38
|
+
export declare function buildTreeFromMap(routes: Record<string, Function>, _options?: Record<string, unknown>): RouteNode[];
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=router-match.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-match.d.ts","sourceRoot":"","sources":["../src/router-match.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAA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,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAc1F;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,MAAM,GAAE,SAAS,EAAO,GAAG,SAAS,EAAE,CAoChH;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAuBjF;AAED,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,EAChC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,SAAS,EAAE,CAwBb"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
export function compileRoutePattern(fullPath) {
|
|
2
|
+
const paramNames = [];
|
|
3
|
+
const parts = fullPath.split('/').filter(Boolean);
|
|
4
|
+
let regexStr = '^';
|
|
5
|
+
for (const part of parts) {
|
|
6
|
+
if (part.startsWith(':')) {
|
|
7
|
+
const name = part.slice(1);
|
|
8
|
+
paramNames.push(name);
|
|
9
|
+
regexStr += '/([^/]+)';
|
|
10
|
+
}
|
|
11
|
+
else if (part === '*') {
|
|
12
|
+
regexStr += '(?:/(.*))?';
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
regexStr += '/' + part.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
regexStr += '$';
|
|
19
|
+
return { regex: new RegExp(regexStr), paramNames };
|
|
20
|
+
}
|
|
21
|
+
export function collectLayouts(nodes, pathParts) {
|
|
22
|
+
const layouts = [];
|
|
23
|
+
for (const node of nodes) {
|
|
24
|
+
if (node.isGroup) {
|
|
25
|
+
const childLayouts = collectLayouts(node.children || [], pathParts);
|
|
26
|
+
layouts.push(...childLayouts);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (node.layout) {
|
|
30
|
+
layouts.push({ layout: node.layout, node });
|
|
31
|
+
}
|
|
32
|
+
const len = pathParts.length;
|
|
33
|
+
const matched = matchRouteNode(node, pathParts);
|
|
34
|
+
if (matched) {
|
|
35
|
+
const remaining = pathParts.slice(node.segmentCount != null ? node.segmentCount : 1);
|
|
36
|
+
if (remaining.length > 0 && (node.children || []).length > 0) {
|
|
37
|
+
const childLayouts = collectLayouts(node.children || [], remaining);
|
|
38
|
+
layouts.push(...childLayouts);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return layouts;
|
|
43
|
+
}
|
|
44
|
+
export function matchRouteNode(node, pathParts) {
|
|
45
|
+
if (node.isGroup)
|
|
46
|
+
return false;
|
|
47
|
+
if (pathParts.length === 0)
|
|
48
|
+
return node.fullPath === '/';
|
|
49
|
+
const part = pathParts[0];
|
|
50
|
+
if (node.isCatchAll)
|
|
51
|
+
return true;
|
|
52
|
+
if (node.isDynamic)
|
|
53
|
+
return true;
|
|
54
|
+
return node.path === part;
|
|
55
|
+
}
|
|
56
|
+
export function extractParams(node, pathParts) {
|
|
57
|
+
const params = {};
|
|
58
|
+
let idx = 0;
|
|
59
|
+
for (const n of node._matchChain || []) {
|
|
60
|
+
if (n.isDynamic && pathParts[idx]) {
|
|
61
|
+
const name = n.path.slice(1);
|
|
62
|
+
params[name] = decodeURIComponent(pathParts[idx]);
|
|
63
|
+
}
|
|
64
|
+
else if (n.isCatchAll) {
|
|
65
|
+
const name = n.path.slice(1);
|
|
66
|
+
params[name] = pathParts.slice(idx).map(decodeURIComponent).join('/');
|
|
67
|
+
}
|
|
68
|
+
if (!n.isGroup)
|
|
69
|
+
idx++;
|
|
70
|
+
}
|
|
71
|
+
return params;
|
|
72
|
+
}
|
|
73
|
+
export function flattenLayoutChain(tree, pathParts, result = []) {
|
|
74
|
+
for (let i = 0; i < tree.length; i++) {
|
|
75
|
+
const node = tree[i];
|
|
76
|
+
if (node.isGroup) {
|
|
77
|
+
flattenLayoutChain(node.children || [], pathParts, result);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const part = pathParts[0];
|
|
81
|
+
const segCount = node.segmentCount != null ? node.segmentCount : 1;
|
|
82
|
+
let matched = false;
|
|
83
|
+
if (node.fullPath === '/') {
|
|
84
|
+
matched = true;
|
|
85
|
+
}
|
|
86
|
+
else if (node.isCatchAll) {
|
|
87
|
+
matched = true;
|
|
88
|
+
}
|
|
89
|
+
else if (node.isDynamic) {
|
|
90
|
+
matched = part !== undefined;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
matched = node.path === part;
|
|
94
|
+
}
|
|
95
|
+
if (matched) {
|
|
96
|
+
const consumeCount = node.isCatchAll ? pathParts.length : segCount;
|
|
97
|
+
const remaining = pathParts.slice(consumeCount);
|
|
98
|
+
const isLeaf = remaining.length === 0 || remaining.every(p => p === '');
|
|
99
|
+
result.push(node);
|
|
100
|
+
if (isLeaf) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
else if ((node.children || []).length > 0) {
|
|
104
|
+
flattenLayoutChain(node.children || [], remaining, result);
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
export function matchRoute(tree, pathname) {
|
|
112
|
+
const pathParts = pathname.split('/').filter(Boolean);
|
|
113
|
+
const matchChain = flattenLayoutChain(tree, pathParts);
|
|
114
|
+
if (matchChain.length === 0)
|
|
115
|
+
return null;
|
|
116
|
+
const params = {};
|
|
117
|
+
let partIdx = 0;
|
|
118
|
+
for (const node of matchChain) {
|
|
119
|
+
const segCount = node.segmentCount != null ? node.segmentCount : 1;
|
|
120
|
+
if (node.isDynamic && !node.isCatchAll) {
|
|
121
|
+
const name = node.path.startsWith(':') ? node.path.slice(1) : node.path;
|
|
122
|
+
if (partIdx < pathParts.length) {
|
|
123
|
+
params[name] = decodeURIComponent(pathParts[partIdx]);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (node.isCatchAll) {
|
|
127
|
+
const name = node.path.startsWith(':') ? node.path.slice(1) : node.path;
|
|
128
|
+
params[name] = pathParts.slice(partIdx).map(decodeURIComponent).join('/');
|
|
129
|
+
}
|
|
130
|
+
partIdx += segCount;
|
|
131
|
+
}
|
|
132
|
+
return { matchChain, params };
|
|
133
|
+
}
|
|
134
|
+
export function buildTreeFromMap(routes, _options) {
|
|
135
|
+
const root = [];
|
|
136
|
+
for (const [pattern, loader] of Object.entries(routes)) {
|
|
137
|
+
const parts = pattern.split('/').filter(Boolean);
|
|
138
|
+
const isDynamic = parts.some(p => p.startsWith(':'));
|
|
139
|
+
const isCatchAll = parts.some(p => p.startsWith('...'));
|
|
140
|
+
const node = {
|
|
141
|
+
path: parts[parts.length - 1] || '',
|
|
142
|
+
fullPath: pattern,
|
|
143
|
+
isGroup: false,
|
|
144
|
+
isDynamic,
|
|
145
|
+
isCatchAll,
|
|
146
|
+
page: loader,
|
|
147
|
+
layout: null,
|
|
148
|
+
loading: null,
|
|
149
|
+
error: null,
|
|
150
|
+
notFound: null,
|
|
151
|
+
children: [],
|
|
152
|
+
segmentCount: parts.length || 1,
|
|
153
|
+
loader,
|
|
154
|
+
};
|
|
155
|
+
root.push(node);
|
|
156
|
+
}
|
|
157
|
+
return root;
|
|
158
|
+
}
|