vorzelajs 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.
Files changed (96) hide show
  1. package/README.md +188 -0
  2. package/bin/vorzelajs.mjs +2 -0
  3. package/dist/analytics.d.ts +132 -0
  4. package/dist/analytics.d.ts.map +1 -0
  5. package/dist/analytics.js +690 -0
  6. package/dist/cli/build.d.ts +2 -0
  7. package/dist/cli/build.d.ts.map +1 -0
  8. package/dist/cli/build.js +22 -0
  9. package/dist/cli/dev.d.ts +2 -0
  10. package/dist/cli/dev.d.ts.map +1 -0
  11. package/dist/cli/dev.js +93 -0
  12. package/dist/cli/index.d.ts +3 -0
  13. package/dist/cli/index.d.ts.map +1 -0
  14. package/dist/cli/index.js +29 -0
  15. package/dist/cli/serve.d.ts +2 -0
  16. package/dist/cli/serve.d.ts.map +1 -0
  17. package/dist/cli/serve.js +43 -0
  18. package/dist/cookie.d.ts +33 -0
  19. package/dist/cookie.d.ts.map +1 -0
  20. package/dist/cookie.js +198 -0
  21. package/dist/debug/error-stack.d.ts +14 -0
  22. package/dist/debug/error-stack.d.ts.map +1 -0
  23. package/dist/debug/error-stack.js +52 -0
  24. package/dist/internal/document.d.ts +12 -0
  25. package/dist/internal/document.d.ts.map +1 -0
  26. package/dist/internal/document.jsx +56 -0
  27. package/dist/internal/entry-client.d.ts +2 -0
  28. package/dist/internal/entry-client.d.ts.map +1 -0
  29. package/dist/internal/entry-client.jsx +8 -0
  30. package/dist/internal/entry-server.d.ts +14 -0
  31. package/dist/internal/entry-server.d.ts.map +1 -0
  32. package/dist/internal/entry-server.jsx +71 -0
  33. package/dist/runtime/create-route.d.ts +8 -0
  34. package/dist/runtime/create-route.d.ts.map +1 -0
  35. package/dist/runtime/create-route.js +18 -0
  36. package/dist/runtime/head.d.ts +10 -0
  37. package/dist/runtime/head.d.ts.map +1 -0
  38. package/dist/runtime/head.js +111 -0
  39. package/dist/runtime/index.d.ts +6 -0
  40. package/dist/runtime/index.d.ts.map +1 -0
  41. package/dist/runtime/index.jsx +4 -0
  42. package/dist/runtime/navigation.d.ts +36 -0
  43. package/dist/runtime/navigation.d.ts.map +1 -0
  44. package/dist/runtime/navigation.js +70 -0
  45. package/dist/runtime/path.d.ts +11 -0
  46. package/dist/runtime/path.d.ts.map +1 -0
  47. package/dist/runtime/path.js +80 -0
  48. package/dist/runtime/resolve.d.ts +11 -0
  49. package/dist/runtime/resolve.d.ts.map +1 -0
  50. package/dist/runtime/resolve.js +449 -0
  51. package/dist/runtime/runtime.d.ts +40 -0
  52. package/dist/runtime/runtime.d.ts.map +1 -0
  53. package/dist/runtime/runtime.jsx +779 -0
  54. package/dist/runtime/search.d.ts +23 -0
  55. package/dist/runtime/search.d.ts.map +1 -0
  56. package/dist/runtime/search.js +178 -0
  57. package/dist/runtime/server.d.ts +10 -0
  58. package/dist/runtime/server.d.ts.map +1 -0
  59. package/dist/runtime/server.js +5 -0
  60. package/dist/runtime/types.d.ts +248 -0
  61. package/dist/runtime/types.d.ts.map +1 -0
  62. package/dist/runtime/types.js +1 -0
  63. package/dist/seo.d.ts +16 -0
  64. package/dist/seo.d.ts.map +1 -0
  65. package/dist/seo.js +69 -0
  66. package/dist/server/index.d.ts +53 -0
  67. package/dist/server/index.d.ts.map +1 -0
  68. package/dist/server/index.js +268 -0
  69. package/dist/session.d.ts +23 -0
  70. package/dist/session.d.ts.map +1 -0
  71. package/dist/session.js +58 -0
  72. package/dist/vite/index.d.ts +13 -0
  73. package/dist/vite/index.d.ts.map +1 -0
  74. package/dist/vite/index.js +174 -0
  75. package/dist/vite/routes-plugin.d.ts +4 -0
  76. package/dist/vite/routes-plugin.d.ts.map +1 -0
  77. package/dist/vite/routes-plugin.js +345 -0
  78. package/dist/vite/server-only.d.ts +3 -0
  79. package/dist/vite/server-only.d.ts.map +1 -0
  80. package/dist/vite/server-only.js +342 -0
  81. package/package.json +76 -0
  82. package/templates/bare/README.md +22 -0
  83. package/templates/bare/src/components/counter-card.tsx +19 -0
  84. package/templates/bare/src/routes/__root.tsx +24 -0
  85. package/templates/bare/src/routes/index.tsx +36 -0
  86. package/templates/base/gitignore +4 -0
  87. package/templates/base/public/favicon.svg +5 -0
  88. package/templates/base/tsconfig.json +18 -0
  89. package/templates/modern/README.md +28 -0
  90. package/templates/modern/src/components/counter-card.tsx +19 -0
  91. package/templates/modern/src/routes/__root.tsx +42 -0
  92. package/templates/modern/src/routes/about.tsx +55 -0
  93. package/templates/modern/src/routes/index.tsx +51 -0
  94. package/templates/styling/css/styles.css +269 -0
  95. package/templates/styling/css-modules/styles.css +269 -0
  96. package/templates/styling/tailwind/styles.css +271 -0
@@ -0,0 +1,71 @@
1
+ import { renderToStream, renderToString } from 'solid-js/web';
2
+ import { Document } from './document';
3
+ import { renderResolvedMatches } from '../runtime';
4
+ import { getResolvedRouteStatus, resolveRoute, serializeRouteState, } from '../runtime/resolve';
5
+ // @ts-expect-error resolved by vorzelajs vite plugin
6
+ import { routeManifest } from 'virtual:vorzela/routes';
7
+ function createStreamingResponse(bodyFactory, status = 200) {
8
+ const encoder = new TextEncoder();
9
+ const body = new ReadableStream({
10
+ async start(controller) {
11
+ controller.enqueue(encoder.encode('<!DOCTYPE html>'));
12
+ const stream = bodyFactory();
13
+ try {
14
+ await stream.pipeTo(new WritableStream({
15
+ write(chunk) {
16
+ controller.enqueue(typeof chunk === 'string' ? encoder.encode(chunk) : chunk);
17
+ },
18
+ close() {
19
+ controller.close();
20
+ },
21
+ abort(reason) {
22
+ controller.error(reason);
23
+ },
24
+ }));
25
+ }
26
+ catch (error) {
27
+ controller.error(error);
28
+ }
29
+ },
30
+ });
31
+ return new Response(body, {
32
+ headers: {
33
+ 'Content-Type': 'text/html; charset=utf-8',
34
+ },
35
+ status,
36
+ });
37
+ }
38
+ export async function renderDocument({ request, assets, nonce, }) {
39
+ const url = new URL(request.url);
40
+ const state = await resolveRoute(`${url.pathname}${url.search}`, { request });
41
+ const bootstrap = serializeRouteState(state);
42
+ const status = getResolvedRouteStatus(state);
43
+ const response = createStreamingResponse(() => renderToStream(() => (<Document assets={assets} bootstrap={bootstrap} head={state.head} nonce={nonce}>
44
+ {renderResolvedMatches(state, { wrapHydrationBoundaries: true })}
45
+ </Document>)), status);
46
+ if (state.responseHeaders) {
47
+ for (const [key, value] of state.responseHeaders) {
48
+ response.headers.append(key, value);
49
+ }
50
+ }
51
+ return response;
52
+ }
53
+ export async function renderPayload({ path, request, }) {
54
+ const state = await resolveRoute(path, { request });
55
+ const html = renderToString(() => renderResolvedMatches(state, {
56
+ wrapHydrationBoundaries: true,
57
+ }));
58
+ return {
59
+ ...serializeRouteState(state),
60
+ html,
61
+ responseHeaders: state.responseHeaders,
62
+ status: getResolvedRouteStatus(state),
63
+ };
64
+ }
65
+ export async function getSitemapEntries() {
66
+ return routeManifest
67
+ .filter((entry) => entry.id !== '__root__' && entry.matchPath !== null && !entry.matchPath.includes('$'))
68
+ .map((entry) => ({
69
+ loc: entry.to,
70
+ }));
71
+ }
@@ -0,0 +1,8 @@
1
+ import type { FileRouteDefinition, FileRouteOptions, RootRouteDefinition, RootRouteOptions, RouteSearch } from './types';
2
+ type InferValidatedSearch<Options> = Options extends {
3
+ validateSearch: (...args: any[]) => infer Search;
4
+ } ? Search extends RouteSearch ? Search : RouteSearch : RouteSearch;
5
+ export declare function createRootRoute<LoaderData = unknown>(): <const Options extends RootRouteOptions<LoaderData, any>>(options: Options) => RootRouteDefinition<LoaderData, InferValidatedSearch<Options>>;
6
+ export declare function createFileRoute<const Path extends string>(path: Path): <LoaderData = unknown, const Options extends FileRouteOptions<Path, LoaderData, any> = FileRouteOptions<Path, LoaderData, RouteSearch>>(options: Options) => FileRouteDefinition<Path, LoaderData, InferValidatedSearch<Options>>;
7
+ export {};
8
+ //# sourceMappingURL=create-route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-route.d.ts","sourceRoot":"","sources":["../../src/runtime/create-route.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACZ,MAAM,SAAS,CAAA;AAEhB,KAAK,oBAAoB,CAAC,OAAO,IAAI,OAAO,SAAS;IACnD,cAAc,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,MAAM,CAAA;CACjD,GACG,MAAM,SAAS,WAAW,GACxB,MAAM,GACN,WAAW,GACb,WAAW,CAAA;AAEf,wBAAgB,eAAe,CAAC,UAAU,GAAG,OAAO,MAC1C,KAAK,CAAC,OAAO,SAAS,gBAAgB,CAAC,UAAU,EAAE,GAAG,CAAC,EAC7D,SAAS,OAAO,KACf,mBAAmB,CAAC,UAAU,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAMlE;AAED,wBAAgB,eAAe,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,IAAI,EAAE,IAAI,IAEjE,UAAU,GAAG,OAAO,EACpB,KAAK,CAAC,OAAO,SAAS,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,GAAG,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,EAE/G,SAAS,OAAO,KACf,mBAAmB,CAAC,IAAI,EAAE,UAAU,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAOxE"}
@@ -0,0 +1,18 @@
1
+ import { useSearch, useSetSearch } from './runtime';
2
+ export function createRootRoute() {
3
+ return (options) => ({
4
+ kind: 'root',
5
+ options,
6
+ useSearch: () => useSearch(),
7
+ useSetSearch: () => useSetSearch(),
8
+ });
9
+ }
10
+ export function createFileRoute(path) {
11
+ return (options) => ({
12
+ kind: 'file',
13
+ options,
14
+ path,
15
+ useSearch: () => useSearch(),
16
+ useSetSearch: () => useSetSearch(),
17
+ });
18
+ }
@@ -0,0 +1,10 @@
1
+ import type { HeadObject, LinkDescriptor, MetaDescriptor } from './types';
2
+ export declare function mergeHeads(heads: Array<HeadObject | undefined>): {
3
+ canonical: string | undefined;
4
+ jsonLd: Record<string, unknown>[] | undefined;
5
+ title: string | undefined;
6
+ meta: MetaDescriptor[];
7
+ links: LinkDescriptor[];
8
+ };
9
+ export declare function syncHead(head: HeadObject): void;
10
+ //# sourceMappingURL=head.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"head.d.ts","sourceRoot":"","sources":["../../src/runtime/head.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAiCzE,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,GAAG,SAAS,CAAC;;;;;;EA0C9D;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,UAAU,QA6CxC"}
@@ -0,0 +1,111 @@
1
+ const MANAGED_HEAD_SELECTOR = '[data-vrz-head]';
2
+ function applyMetaAttributes(element, meta) {
3
+ if (meta.charset)
4
+ element.setAttribute('charset', meta.charset);
5
+ if (meta.content)
6
+ element.setAttribute('content', meta.content);
7
+ if (meta.httpEquiv)
8
+ element.setAttribute('http-equiv', meta.httpEquiv);
9
+ if (meta.name)
10
+ element.setAttribute('name', meta.name);
11
+ if (meta.property)
12
+ element.setAttribute('property', meta.property);
13
+ }
14
+ function applyLinkAttributes(element, link) {
15
+ element.setAttribute('href', link.href);
16
+ element.setAttribute('rel', link.rel);
17
+ if (link.as)
18
+ element.setAttribute('as', link.as);
19
+ if (link.crossorigin)
20
+ element.setAttribute('crossorigin', link.crossorigin);
21
+ if (link.type)
22
+ element.setAttribute('type', link.type);
23
+ }
24
+ function metaKey(meta, index) {
25
+ if (meta.charset)
26
+ return 'charset';
27
+ if (meta.name)
28
+ return `name:${meta.name}`;
29
+ if (meta.property)
30
+ return `property:${meta.property}`;
31
+ if (meta.httpEquiv)
32
+ return `http-equiv:${meta.httpEquiv}`;
33
+ return `meta:${index}`;
34
+ }
35
+ function linkKey(link, index) {
36
+ return `${link.rel}:${link.href}:${link.as ?? ''}:${index}`;
37
+ }
38
+ export function mergeHeads(heads) {
39
+ const metaEntries = new Map();
40
+ const linkEntries = new Map();
41
+ let title;
42
+ let canonical;
43
+ const jsonLdItems = [];
44
+ heads.forEach((head) => {
45
+ if (!head)
46
+ return;
47
+ if (head.title) {
48
+ title = head.title;
49
+ }
50
+ if (head.canonical) {
51
+ canonical = head.canonical;
52
+ }
53
+ if (head.jsonLd) {
54
+ if (Array.isArray(head.jsonLd)) {
55
+ jsonLdItems.push(...head.jsonLd);
56
+ }
57
+ else {
58
+ jsonLdItems.push(head.jsonLd);
59
+ }
60
+ }
61
+ head.meta?.forEach((meta, index) => {
62
+ metaEntries.set(metaKey(meta, index), meta);
63
+ });
64
+ head.links?.forEach((link, index) => {
65
+ linkEntries.set(linkKey(link, index), link);
66
+ });
67
+ });
68
+ return {
69
+ canonical,
70
+ jsonLd: jsonLdItems.length > 0 ? jsonLdItems : undefined,
71
+ title,
72
+ meta: [...metaEntries.values()],
73
+ links: [...linkEntries.values()],
74
+ };
75
+ }
76
+ export function syncHead(head) {
77
+ if (typeof document === 'undefined')
78
+ return;
79
+ document.title = head.title ?? 'VorzelaJs';
80
+ document.head.querySelectorAll(MANAGED_HEAD_SELECTOR).forEach((element) => element.remove());
81
+ head.meta?.forEach((meta) => {
82
+ const element = document.createElement('meta');
83
+ element.setAttribute('data-vrz-head', '');
84
+ applyMetaAttributes(element, meta);
85
+ document.head.appendChild(element);
86
+ });
87
+ head.links?.forEach((link) => {
88
+ const element = document.createElement('link');
89
+ element.setAttribute('data-vrz-head', '');
90
+ applyLinkAttributes(element, link);
91
+ document.head.appendChild(element);
92
+ });
93
+ if (head.canonical) {
94
+ const link = document.createElement('link');
95
+ link.setAttribute('rel', 'canonical');
96
+ link.setAttribute('href', head.canonical);
97
+ link.setAttribute('data-vrz-head', '');
98
+ document.head.appendChild(link);
99
+ }
100
+ document.head.querySelectorAll('script[data-vrz-jsonld]').forEach((el) => el.remove());
101
+ if (head.jsonLd) {
102
+ const items = Array.isArray(head.jsonLd) ? head.jsonLd : [head.jsonLd];
103
+ for (const item of items) {
104
+ const script = document.createElement('script');
105
+ script.setAttribute('type', 'application/ld+json');
106
+ script.setAttribute('data-vrz-jsonld', '');
107
+ script.textContent = JSON.stringify(item);
108
+ document.head.appendChild(script);
109
+ }
110
+ }
111
+ }
@@ -0,0 +1,6 @@
1
+ export { createFileRoute, createRootRoute } from './create-route';
2
+ export { isNotFound, isRedirect, notFound, redirect, resolveRedirectTarget, withRedirectParam, } from './navigation';
3
+ export { createRouter, Link, Outlet, readBootstrapPayload, renderResolvedMatches, RouterProvider, useLoaderData, useNavigate, useParams, useRouter, useSearch, useSetSearch, } from './runtime';
4
+ export { filterSearch } from './search';
5
+ export type { BootstrapPayload, GeneratedRouteHydrationRecord, HeadObject, NavigateToOptions, NotFoundState, RenderAssets, ResolvedRouteHydration, RouteAfterLoadContext, RouteBeforeLoadContext, RouteComponentProps, RouteErrorContext, RouteErrorData, RouteErrorState, RouteHydrationMode, RouteLocation, RouteNavigationEnvelope, RouteParams, RoutePayloadEnvelope, RouterCreateOptions, RouteRedirectData, RouteRedirectEnvelope, RouteResponseStub, RouteSearch, RouteSearchInput, RouteSearchUpdater, SetSearchFunction, SetSearchOptions, SitemapEntry, } from './types';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,EACL,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,YAAY,EACZ,IAAI,EACJ,MAAM,EACN,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,WAAW,EACX,SAAS,EACT,SAAS,EACT,SAAS,EACT,YAAY,GACb,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,YAAY,EACV,gBAAgB,EAChB,6BAA6B,EAC7B,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,uBAAuB,EACvB,WAAW,EACX,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,GACb,MAAM,SAAS,CAAA"}
@@ -0,0 +1,4 @@
1
+ export { createFileRoute, createRootRoute } from './create-route';
2
+ export { isNotFound, isRedirect, notFound, redirect, resolveRedirectTarget, withRedirectParam, } from './navigation';
3
+ export { createRouter, Link, Outlet, readBootstrapPayload, renderResolvedMatches, RouterProvider, useLoaderData, useNavigate, useParams, useRouter, useSearch, useSetSearch, } from './runtime';
4
+ export { filterSearch } from './search';
@@ -0,0 +1,36 @@
1
+ declare const REDIRECT_SIGNAL: unique symbol;
2
+ declare const NOT_FOUND_SIGNAL: unique symbol;
3
+ export interface RedirectOptions {
4
+ replace?: boolean;
5
+ status?: 301 | 302 | 303 | 307 | 308;
6
+ to: string;
7
+ }
8
+ export interface RedirectTargetOptions {
9
+ defaultTo?: string;
10
+ disallowedPrefixes?: string[];
11
+ }
12
+ export interface RedirectParamOptions {
13
+ paramName?: string;
14
+ }
15
+ export declare class RedirectSignal extends Error {
16
+ readonly replace: boolean;
17
+ readonly status: 301 | 302 | 303 | 307 | 308;
18
+ readonly to: string;
19
+ readonly [REDIRECT_SIGNAL] = true;
20
+ constructor(options: RedirectOptions);
21
+ }
22
+ export interface NotFoundOptions {
23
+ message?: string;
24
+ }
25
+ export declare class NotFoundSignal extends Error {
26
+ readonly [NOT_FOUND_SIGNAL] = true;
27
+ constructor(options?: NotFoundOptions);
28
+ }
29
+ export declare function redirect(options: RedirectOptions): RedirectSignal;
30
+ export declare function withRedirectParam(to: string, redirectTo: string, options?: RedirectParamOptions): string;
31
+ export declare function resolveRedirectTarget(target: unknown, options?: RedirectTargetOptions): string;
32
+ export declare function isRedirect(value: unknown): value is RedirectSignal;
33
+ export declare function notFound(options?: NotFoundOptions): NotFoundSignal;
34
+ export declare function isNotFound(value: unknown): value is NotFoundSignal;
35
+ export {};
36
+ //# sourceMappingURL=navigation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../src/runtime/navigation.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,eAAe,eAAmC,CAAA;AACxD,QAAA,MAAM,gBAAgB,eAAoC,CAAA;AAI1D,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;IACpC,EAAE,EAAE,MAAM,CAAA;CACX;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;IAC5C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,CAAC,eAAe,CAAC,QAAO;gBAErB,OAAO,EAAE,eAAe;CAOrC;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,CAAC,gBAAgB,CAAC,QAAO;gBAEtB,OAAO,GAAE,eAAoB;CAI1C;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,kBAEhD;AAED,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,UAOnG;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAE,qBAA0B,UAkCzF;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAGlE;AAED,wBAAgB,QAAQ,CAAC,OAAO,GAAE,eAAoB,kBAErD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAGlE"}
@@ -0,0 +1,70 @@
1
+ import { normalizeHref, normalizePath } from './path';
2
+ const REDIRECT_SIGNAL = Symbol.for('vorzelajs.redirect');
3
+ const NOT_FOUND_SIGNAL = Symbol.for('vorzelajs.not-found');
4
+ const REDIRECT_TARGET_BASE_URL = 'http://vorzelajs.local';
5
+ export class RedirectSignal extends Error {
6
+ replace;
7
+ status;
8
+ to;
9
+ [REDIRECT_SIGNAL] = true;
10
+ constructor(options) {
11
+ super(`Redirect to ${options.to}`);
12
+ this.name = 'RedirectSignal';
13
+ this.replace = options.replace ?? true;
14
+ this.status = options.status ?? 302;
15
+ this.to = options.to;
16
+ }
17
+ }
18
+ export class NotFoundSignal extends Error {
19
+ [NOT_FOUND_SIGNAL] = true;
20
+ constructor(options = {}) {
21
+ super(options.message ?? 'Not Found');
22
+ this.name = 'NotFoundSignal';
23
+ }
24
+ }
25
+ export function redirect(options) {
26
+ return new RedirectSignal(options);
27
+ }
28
+ export function withRedirectParam(to, redirectTo, options = {}) {
29
+ const url = new URL(normalizeHref(to), REDIRECT_TARGET_BASE_URL);
30
+ const paramName = options.paramName ?? 'redirect';
31
+ url.searchParams.set(paramName, resolveRedirectTarget(redirectTo));
32
+ return `${normalizePath(url.pathname)}${url.search}`;
33
+ }
34
+ export function resolveRedirectTarget(target, options = {}) {
35
+ const fallback = normalizeHref(options.defaultTo ?? '/');
36
+ if (typeof target !== 'string' || target.trim() === '' || target.startsWith('//') || !target.startsWith('/')) {
37
+ return fallback;
38
+ }
39
+ let url;
40
+ try {
41
+ url = new URL(target, REDIRECT_TARGET_BASE_URL);
42
+ }
43
+ catch {
44
+ return fallback;
45
+ }
46
+ if (url.origin !== REDIRECT_TARGET_BASE_URL) {
47
+ return fallback;
48
+ }
49
+ const normalizedTarget = normalizeHref(`${url.pathname}${url.search}`);
50
+ for (const prefix of options.disallowedPrefixes ?? []) {
51
+ const normalizedPrefix = normalizePath(prefix);
52
+ if (normalizedTarget === normalizedPrefix
53
+ || normalizedTarget.startsWith(`${normalizedPrefix}/`)
54
+ || normalizedTarget.startsWith(`${normalizedPrefix}?`)) {
55
+ return fallback;
56
+ }
57
+ }
58
+ return normalizedTarget;
59
+ }
60
+ export function isRedirect(value) {
61
+ return value instanceof RedirectSignal
62
+ || (typeof value === 'object' && value !== null && REDIRECT_SIGNAL in value);
63
+ }
64
+ export function notFound(options = {}) {
65
+ return new NotFoundSignal(options);
66
+ }
67
+ export function isNotFound(value) {
68
+ return value instanceof NotFoundSignal
69
+ || (typeof value === 'object' && value !== null && NOT_FOUND_SIGNAL in value);
70
+ }
@@ -0,0 +1,11 @@
1
+ import type { GeneratedRouteRecord } from './types';
2
+ export declare function normalizePath(pathname: string): string;
3
+ export declare function normalizeSearch(search: string): string;
4
+ export declare function normalizeHref(value: string): string;
5
+ export declare function matchPathPattern(pattern: string, pathname: string): {
6
+ matched: boolean;
7
+ params: Record<string, string>;
8
+ score: number;
9
+ };
10
+ export declare function buildRouteBranch(manifest: readonly GeneratedRouteRecord[], leafId: string): GeneratedRouteRecord[];
11
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/runtime/path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAuBnD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,UAK7C;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,UAM7C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,UAG1C;AAOD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;;;;EA0CjE;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,SAAS,oBAAoB,EAAE,EAAE,MAAM,EAAE,MAAM,0BAYzF"}
@@ -0,0 +1,80 @@
1
+ function stripHash(value) {
2
+ return value.split('#', 1)[0] ?? '/';
3
+ }
4
+ function splitPathAndSearch(value) {
5
+ const withoutHash = stripHash(value);
6
+ const questionMarkIndex = withoutHash.indexOf('?');
7
+ if (questionMarkIndex === -1) {
8
+ return {
9
+ pathname: withoutHash,
10
+ search: '',
11
+ };
12
+ }
13
+ return {
14
+ pathname: withoutHash.slice(0, questionMarkIndex),
15
+ search: withoutHash.slice(questionMarkIndex),
16
+ };
17
+ }
18
+ export function normalizePath(pathname) {
19
+ const { pathname: rawPath } = splitPathAndSearch(pathname);
20
+ const prefixed = rawPath.startsWith('/') ? rawPath : `/${rawPath}`;
21
+ const trimmed = prefixed.replace(/\/+$/u, '');
22
+ return trimmed === '' ? '/' : trimmed;
23
+ }
24
+ export function normalizeSearch(search) {
25
+ if (!search || search === '?') {
26
+ return '';
27
+ }
28
+ return search.startsWith('?') ? search : `?${search}`;
29
+ }
30
+ export function normalizeHref(value) {
31
+ const { pathname, search } = splitPathAndSearch(value);
32
+ return `${normalizePath(pathname)}${normalizeSearch(search)}`;
33
+ }
34
+ function splitPath(pathname) {
35
+ const normalized = normalizePath(pathname);
36
+ return normalized === '/' ? [] : normalized.slice(1).split('/').filter(Boolean);
37
+ }
38
+ export function matchPathPattern(pattern, pathname) {
39
+ const patternSegments = splitPath(pattern);
40
+ const pathnameSegments = splitPath(pathname);
41
+ const params = {};
42
+ if (patternSegments.length === 0 && pathnameSegments.length === 0) {
43
+ return { matched: true, params, score: 1000 };
44
+ }
45
+ let score = 0;
46
+ for (let index = 0; index < patternSegments.length; index += 1) {
47
+ const patternSegment = patternSegments[index];
48
+ const pathnameSegment = pathnameSegments[index];
49
+ if (patternSegment === '$') {
50
+ score += 1;
51
+ return { matched: true, params, score };
52
+ }
53
+ if (pathnameSegment === undefined) {
54
+ return { matched: false, params: {}, score: 0 };
55
+ }
56
+ if (patternSegment.startsWith('$')) {
57
+ params[patternSegment.slice(1)] = decodeURIComponent(pathnameSegment);
58
+ score += 5;
59
+ continue;
60
+ }
61
+ if (patternSegment !== pathnameSegment) {
62
+ return { matched: false, params: {}, score: 0 };
63
+ }
64
+ score += 10;
65
+ }
66
+ if (patternSegments.length !== pathnameSegments.length) {
67
+ return { matched: false, params: {}, score: 0 };
68
+ }
69
+ return { matched: true, params, score };
70
+ }
71
+ export function buildRouteBranch(manifest, leafId) {
72
+ const routesById = new Map(manifest.map((entry) => [entry.id, entry]));
73
+ const branch = [];
74
+ let current = routesById.get(leafId);
75
+ while (current) {
76
+ branch.unshift(current);
77
+ current = current.parentId ? routesById.get(current.parentId) : undefined;
78
+ }
79
+ return branch;
80
+ }
@@ -0,0 +1,11 @@
1
+ import type { BootstrapPayload, ResolvedRouteState, RoutePayloadEnvelope, RouterContextValue } from './types';
2
+ export declare function resolveRoute(target: string, options?: {
3
+ context?: RouterContextValue;
4
+ request?: Request;
5
+ }): Promise<ResolvedRouteState>;
6
+ export declare function serializeRouteState(state: ResolvedRouteState): BootstrapPayload;
7
+ export declare function materializeBootstrapPayload(payload: BootstrapPayload): Promise<ResolvedRouteState>;
8
+ export declare function materializePayloadEnvelope(payload: RoutePayloadEnvelope): Promise<ResolvedRouteState>;
9
+ export declare function getResolvedRouteStatus(state: Pick<ResolvedRouteState, 'matches' | 'notFound' | 'routeError'>): number;
10
+ export declare function isNotFoundState(state: ResolvedRouteState): boolean;
11
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/runtime/resolve.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAEV,gBAAgB,EAMhB,kBAAkB,EAKlB,oBAAoB,EACpB,kBAAkB,EAInB,MAAM,SAAS,CAAA;AA0LhB,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,kBAAkB,CAAA;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;CACb,GACL,OAAO,CAAC,kBAAkB,CAAC,CAsR7B;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,GAAG,gBAAgB,CAgB/E;AAED,wBAAsB,2BAA2B,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAUxG;AAED,wBAAsB,0BAA0B,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAW3G;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,IAAI,CAAC,kBAAkB,EAAE,SAAS,GAAG,UAAU,GAAG,YAAY,CAAC,UAW5G;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,kBAAkB,WAOxD"}