@absolutejs/absolute 0.19.0-beta.1095 → 0.19.0-beta.1097

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.
@@ -2094,6 +2094,343 @@ var normalizeSlug = (str) => str.trim().replace(/\s+/g, "-").replace(/[^A-Za-z0-
2094
2094
  return normalizeSlug(str).split(/[-_]/).filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1).toLowerCase()).join("");
2095
2095
  };
2096
2096
 
2097
+ // src/utils/resolveConvention.ts
2098
+ import { basename as basename2 } from "path";
2099
+ var CONVENTIONS_KEY = "__absoluteConventions", isConventionsMap = (value) => Boolean(value) && typeof value === "object", getMap = () => {
2100
+ const value = Reflect.get(globalThis, CONVENTIONS_KEY);
2101
+ if (isConventionsMap(value))
2102
+ return value;
2103
+ const empty = {};
2104
+ return empty;
2105
+ }, derivePageName = (pagePath) => {
2106
+ const base = basename2(pagePath);
2107
+ const dotIndex = base.indexOf(".");
2108
+ const name = dotIndex > 0 ? base.slice(0, dotIndex) : base;
2109
+ return toPascal(name);
2110
+ }, normalizeConventionPageName = (name) => toPascal(name).replace(/\d+$/, ""), hasErrorConvention = (framework) => {
2111
+ const conventions = getMap()[framework];
2112
+ if (!conventions)
2113
+ return false;
2114
+ if (conventions.defaults?.error)
2115
+ return true;
2116
+ return Object.values(conventions.pages ?? {}).some((page) => Boolean(page.error));
2117
+ }, resolveErrorConventionPath = (framework, pageName) => {
2118
+ const conventions = getMap()[framework];
2119
+ if (!conventions)
2120
+ return;
2121
+ const exact = conventions.pages?.[pageName]?.error;
2122
+ if (exact)
2123
+ return exact;
2124
+ const normalizedPageName = normalizeConventionPageName(pageName);
2125
+ for (const [candidate, page] of Object.entries(conventions.pages ?? {})) {
2126
+ if (normalizeConventionPageName(candidate) === normalizedPageName) {
2127
+ return page.error ?? conventions.defaults?.error;
2128
+ }
2129
+ }
2130
+ return conventions.defaults?.error;
2131
+ }, resolveNotFoundConventionPath = (framework) => getMap()[framework]?.defaults?.notFound, setConventions = (map) => {
2132
+ Reflect.set(globalThis, CONVENTIONS_KEY, map);
2133
+ }, isDev = () => true, buildErrorProps = (error) => {
2134
+ if (error instanceof Error) {
2135
+ return {
2136
+ name: error.name,
2137
+ message: error.message,
2138
+ ...isDev() && error.stack ? { stack: error.stack } : {}
2139
+ };
2140
+ }
2141
+ return { message: String(error), name: "Error" };
2142
+ }, renderReactError = async (conventionPath, errorProps) => {
2143
+ const { createElement } = await import("react");
2144
+ const { renderToReadableStream } = await import("react-dom/server");
2145
+ const mod = await import(conventionPath);
2146
+ const ErrorComponent = mod.default;
2147
+ if (typeof ErrorComponent !== "function")
2148
+ return null;
2149
+ const element = createElement(ErrorComponent, errorProps);
2150
+ const stream = await renderToReadableStream(element);
2151
+ return new Response(stream, {
2152
+ headers: { "Content-Type": "text/html" },
2153
+ status: 500
2154
+ });
2155
+ }, renderSvelteError = async (conventionPath, errorProps) => {
2156
+ const { render } = await import("svelte/server");
2157
+ const mod = await import(conventionPath);
2158
+ const ErrorComponent = mod.default;
2159
+ if (!ErrorComponent)
2160
+ return null;
2161
+ const { head, body } = render(ErrorComponent, {
2162
+ props: errorProps
2163
+ });
2164
+ const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
2165
+ return new Response(html, {
2166
+ headers: { "Content-Type": "text/html" },
2167
+ status: 500
2168
+ });
2169
+ }, unescapeVueStyles = (ssrBody) => {
2170
+ let styles = "";
2171
+ const body = ssrBody.replace(/<style>([\s\S]*?)<\/style>/g, (_, css) => {
2172
+ styles += `<style>${css.replace(/&quot;/g, '"').replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">")}</style>`;
2173
+ return "";
2174
+ });
2175
+ return { body, styles };
2176
+ }, renderVueError = async (conventionPath, errorProps) => {
2177
+ const { createSSRApp, h } = await import("vue");
2178
+ const { renderToString } = await import("vue/server-renderer");
2179
+ const mod = await import(conventionPath);
2180
+ const ErrorComponent = mod.default;
2181
+ if (!ErrorComponent)
2182
+ return null;
2183
+ const app = createSSRApp({
2184
+ render: () => h(ErrorComponent, errorProps)
2185
+ });
2186
+ const rawBody = await renderToString(app);
2187
+ const { styles, body } = unescapeVueStyles(rawBody);
2188
+ const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
2189
+ return new Response(html, {
2190
+ headers: { "Content-Type": "text/html" },
2191
+ status: 500
2192
+ });
2193
+ }, renderAngularError = async (conventionPath, errorProps) => {
2194
+ const mod = await import(conventionPath);
2195
+ const renderFn = mod.default;
2196
+ if (typeof renderFn !== "function")
2197
+ return null;
2198
+ const html = renderFn(errorProps);
2199
+ return new Response(html, {
2200
+ headers: { "Content-Type": "text/html" },
2201
+ status: 500
2202
+ });
2203
+ }, escapeHtml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;"), replaceErrorTokens = (template, errorProps) => template.replace(/\{\{\s*name\s*\}\}/g, escapeHtml(errorProps.name)).replace(/\{\{\s*message\s*\}\}/g, escapeHtml(errorProps.message)).replace(/\{\{\s*stack\s*\}\}/g, errorProps.stack ? escapeHtml(errorProps.stack) : ""), renderHtmlError = async (conventionPath, errorProps) => {
2204
+ const template = await Bun.file(conventionPath).text();
2205
+ const html = replaceErrorTokens(template, errorProps);
2206
+ return new Response(html, {
2207
+ headers: { "Content-Type": "text/html" },
2208
+ status: 500
2209
+ });
2210
+ }, logConventionRenderError = (framework, label, renderError) => {
2211
+ const message = renderError instanceof Error ? renderError.message : "";
2212
+ if (message.includes("Cannot find module") || message.includes("Cannot find package") || message.includes("not found in module")) {
2213
+ console.error(`[SSR] Convention ${label} page for ${framework} failed: missing framework package. Ensure the ${framework} runtime is installed (e.g. bun add ${framework === "react" ? "react react-dom" : framework}).`);
2214
+ return;
2215
+ }
2216
+ console.error(`[SSR] Failed to render ${framework} convention ${label} page:`, renderError);
2217
+ }, renderEmberError = async () => null, renderEmberNotFound = async () => null, ERROR_RENDERERS, tryFrameworkErrorConvention = async (framework, pageName, errorProps, error) => {
2218
+ let conventionPath = resolveErrorConventionPath(framework, pageName);
2219
+ if (!conventionPath && error instanceof Error && error.stack) {
2220
+ for (const match of error.stack.matchAll(/^\s*at\s+([A-Za-z_$][\w$]*)/gm)) {
2221
+ const candidate = match[1];
2222
+ if (!candidate)
2223
+ continue;
2224
+ conventionPath = resolveErrorConventionPath(framework, candidate);
2225
+ if (conventionPath)
2226
+ break;
2227
+ }
2228
+ }
2229
+ if (!conventionPath)
2230
+ return null;
2231
+ const renderer = ERROR_RENDERERS[framework];
2232
+ if (!renderer)
2233
+ return null;
2234
+ try {
2235
+ return await renderer(conventionPath, errorProps);
2236
+ } catch (renderError) {
2237
+ logConventionRenderError(framework, "error", renderError);
2238
+ }
2239
+ return null;
2240
+ }, renderConventionError = async (framework, pageName, error) => {
2241
+ const errorProps = buildErrorProps(error);
2242
+ const frameworkResponse = await tryFrameworkErrorConvention(framework, pageName, errorProps, error);
2243
+ if (frameworkResponse)
2244
+ return frameworkResponse;
2245
+ if (framework !== "html") {
2246
+ const htmlResponse = await tryFrameworkErrorConvention("html", pageName, errorProps, error);
2247
+ if (htmlResponse)
2248
+ return htmlResponse;
2249
+ }
2250
+ return null;
2251
+ }, renderReactNotFound = async (conventionPath) => {
2252
+ const { createElement } = await import("react");
2253
+ const { renderToReadableStream } = await import("react-dom/server");
2254
+ const mod = await import(conventionPath);
2255
+ const NotFoundComponent = mod.default;
2256
+ if (typeof NotFoundComponent !== "function")
2257
+ return null;
2258
+ const element = createElement(NotFoundComponent);
2259
+ const stream = await renderToReadableStream(element);
2260
+ return new Response(stream, {
2261
+ headers: { "Content-Type": "text/html" },
2262
+ status: 404
2263
+ });
2264
+ }, renderSvelteNotFound = async (conventionPath) => {
2265
+ const { render } = await import("svelte/server");
2266
+ const mod = await import(conventionPath);
2267
+ const NotFoundComponent = mod.default;
2268
+ if (!NotFoundComponent)
2269
+ return null;
2270
+ const { head, body } = render(NotFoundComponent);
2271
+ const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
2272
+ return new Response(html, {
2273
+ headers: { "Content-Type": "text/html" },
2274
+ status: 404
2275
+ });
2276
+ }, renderVueNotFound = async (conventionPath) => {
2277
+ const { createSSRApp, h } = await import("vue");
2278
+ const { renderToString } = await import("vue/server-renderer");
2279
+ const mod = await import(conventionPath);
2280
+ const NotFoundComponent = mod.default;
2281
+ if (!NotFoundComponent)
2282
+ return null;
2283
+ const app = createSSRApp({
2284
+ render: () => h(NotFoundComponent)
2285
+ });
2286
+ const rawBody = await renderToString(app);
2287
+ const { styles, body } = unescapeVueStyles(rawBody);
2288
+ const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
2289
+ return new Response(html, {
2290
+ headers: { "Content-Type": "text/html" },
2291
+ status: 404
2292
+ });
2293
+ }, renderAngularNotFound = async (conventionPath) => {
2294
+ const mod = await import(conventionPath);
2295
+ const renderFn = mod.default;
2296
+ if (typeof renderFn !== "function")
2297
+ return null;
2298
+ const html = renderFn();
2299
+ return new Response(html, {
2300
+ headers: { "Content-Type": "text/html" },
2301
+ status: 404
2302
+ });
2303
+ }, renderHtmlNotFound = async (conventionPath) => {
2304
+ const html = await Bun.file(conventionPath).text();
2305
+ return new Response(html, {
2306
+ headers: { "Content-Type": "text/html" },
2307
+ status: 404
2308
+ });
2309
+ }, NOT_FOUND_RENDERERS, renderConventionNotFound = async (framework) => {
2310
+ const conventionPath = resolveNotFoundConventionPath(framework);
2311
+ if (!conventionPath)
2312
+ return null;
2313
+ const renderer = NOT_FOUND_RENDERERS[framework];
2314
+ if (!renderer)
2315
+ return null;
2316
+ try {
2317
+ return await renderer(conventionPath);
2318
+ } catch (renderError) {
2319
+ logConventionRenderError(framework, "not-found", renderError);
2320
+ }
2321
+ return null;
2322
+ }, NOT_FOUND_PRIORITY, renderFirstNotFound = async () => {
2323
+ const renderNext = async (frameworks) => {
2324
+ const [framework, ...remaining] = frameworks;
2325
+ if (!framework) {
2326
+ return null;
2327
+ }
2328
+ if (!getMap()[framework]?.defaults?.notFound) {
2329
+ return renderNext(remaining);
2330
+ }
2331
+ const response = await renderConventionNotFound(framework);
2332
+ if (response) {
2333
+ return response;
2334
+ }
2335
+ return renderNext(remaining);
2336
+ };
2337
+ return renderNext(NOT_FOUND_PRIORITY);
2338
+ };
2339
+ var init_resolveConvention = __esm(() => {
2340
+ ERROR_RENDERERS = {
2341
+ angular: renderAngularError,
2342
+ ember: renderEmberError,
2343
+ html: renderHtmlError,
2344
+ react: renderReactError,
2345
+ svelte: renderSvelteError,
2346
+ vue: renderVueError
2347
+ };
2348
+ NOT_FOUND_RENDERERS = {
2349
+ angular: renderAngularNotFound,
2350
+ ember: renderEmberNotFound,
2351
+ html: renderHtmlNotFound,
2352
+ react: renderReactNotFound,
2353
+ svelte: renderSvelteNotFound,
2354
+ vue: renderVueNotFound
2355
+ };
2356
+ NOT_FOUND_PRIORITY = [
2357
+ "react",
2358
+ "svelte",
2359
+ "vue",
2360
+ "angular",
2361
+ "html"
2362
+ ];
2363
+ });
2364
+
2365
+ // src/utils/spaRouteManifest.ts
2366
+ import { basename as basename3 } from "path";
2367
+ var SPA_ROUTES_KEY = "__absoluteSpaRoutes", setSpaRouteManifest = (hosts) => {
2368
+ Reflect.set(globalThis, SPA_ROUTES_KEY, hosts);
2369
+ }, getSpaRouteManifest = () => {
2370
+ const value = Reflect.get(globalThis, SPA_ROUTES_KEY);
2371
+ return Array.isArray(value) ? value : [];
2372
+ }, normalizePath = (path) => {
2373
+ const withLeadingSlash = path.startsWith("/") ? path : `/${path}`;
2374
+ const trimmed = withLeadingSlash.replace(/\/+$/, "");
2375
+ return trimmed || "/";
2376
+ }, fullRoutePath = (baseHref, routePath) => {
2377
+ const base = normalizePath(baseHref);
2378
+ const route = normalizePath(routePath);
2379
+ if (base !== "/" && (route === base || route.startsWith(`${base}/`))) {
2380
+ return route;
2381
+ }
2382
+ if (base === "/")
2383
+ return route;
2384
+ return normalizePath(`${base}/${route.replace(/^\/+/, "")}`);
2385
+ }, routePattern = (path) => {
2386
+ const segments = normalizePath(path).split("/").filter(Boolean);
2387
+ let expression = "^";
2388
+ for (const segment of segments) {
2389
+ if (segment === "*" || segment === "**") {
2390
+ expression += "(?:/.*)?";
2391
+ continue;
2392
+ }
2393
+ const parameter = /^:[A-Za-z_$][A-Za-z0-9_$]*(?:\((.*)\))?(\?)?$/.exec(segment);
2394
+ if (parameter) {
2395
+ const valuePattern = parameter[1] || "[^/]+";
2396
+ expression += parameter[2] ? `(?:/${valuePattern})?` : `/${valuePattern}`;
2397
+ continue;
2398
+ }
2399
+ expression += `/${segment.replace(/[.+?^${}()|[\]\\]/g, "\\$&")}`;
2400
+ }
2401
+ return new RegExp(`${expression || "^/"}/?$`);
2402
+ }, sourcePageName = (sourceFile) => basename3(sourceFile).replace(/\.[^.]+$/, "").toLowerCase(), isKnownSpaRoute = (framework, pageName, request) => {
2403
+ if (!request)
2404
+ return true;
2405
+ let pathname;
2406
+ try {
2407
+ pathname = normalizePath(new URL(request.url).pathname);
2408
+ } catch {
2409
+ return true;
2410
+ }
2411
+ const hosts = getSpaRouteManifest().filter((host) => {
2412
+ if (host.framework !== framework)
2413
+ return false;
2414
+ if (sourcePageName(host.sourceFile) !== pageName.toLowerCase())
2415
+ return false;
2416
+ const base = normalizePath(host.baseHref);
2417
+ return base === "/" || pathname === base || pathname.startsWith(`${base}/`);
2418
+ });
2419
+ if (hosts.length === 0)
2420
+ return true;
2421
+ return hosts.some((host) => host.routes.some((route) => routePattern(fullRoutePath(host.baseHref, route.path)).test(pathname)));
2422
+ }, renderSpaNotFound = async (framework, pageName, request) => {
2423
+ if (isKnownSpaRoute(framework, pageName, request))
2424
+ return null;
2425
+ return await renderFirstNotFound() ?? new Response("Not found", {
2426
+ headers: { "Content-Type": "text/plain" },
2427
+ status: 404
2428
+ });
2429
+ };
2430
+ var init_spaRouteManifest = __esm(() => {
2431
+ init_resolveConvention();
2432
+ });
2433
+
2097
2434
  // src/svelte/renderToReadableStream.ts
2098
2435
  var exports_renderToReadableStream = {};
2099
2436
  __export(exports_renderToReadableStream, {
@@ -2621,303 +2958,10 @@ var readSiblingCss = async (siblingJsPath) => {
2621
2958
  return "";
2622
2959
  }
2623
2960
  };
2624
- // src/utils/resolveConvention.ts
2625
- import { basename as basename2 } from "path";
2626
- var CONVENTIONS_KEY = "__absoluteConventions";
2627
- var isConventionsMap = (value) => Boolean(value) && typeof value === "object";
2628
- var getMap = () => {
2629
- const value = Reflect.get(globalThis, CONVENTIONS_KEY);
2630
- if (isConventionsMap(value))
2631
- return value;
2632
- const empty = {};
2633
- return empty;
2634
- };
2635
- var derivePageName = (pagePath) => {
2636
- const base = basename2(pagePath);
2637
- const dotIndex = base.indexOf(".");
2638
- const name = dotIndex > 0 ? base.slice(0, dotIndex) : base;
2639
- return toPascal(name);
2640
- };
2641
- var normalizeConventionPageName = (name) => toPascal(name).replace(/\d+$/, "");
2642
- var hasErrorConvention = (framework) => {
2643
- const conventions = getMap()[framework];
2644
- if (!conventions)
2645
- return false;
2646
- if (conventions.defaults?.error)
2647
- return true;
2648
- return Object.values(conventions.pages ?? {}).some((page) => Boolean(page.error));
2649
- };
2650
- var resolveErrorConventionPath = (framework, pageName) => {
2651
- const conventions = getMap()[framework];
2652
- if (!conventions)
2653
- return;
2654
- const exact = conventions.pages?.[pageName]?.error;
2655
- if (exact)
2656
- return exact;
2657
- const normalizedPageName = normalizeConventionPageName(pageName);
2658
- for (const [candidate, page] of Object.entries(conventions.pages ?? {})) {
2659
- if (normalizeConventionPageName(candidate) === normalizedPageName) {
2660
- return page.error ?? conventions.defaults?.error;
2661
- }
2662
- }
2663
- return conventions.defaults?.error;
2664
- };
2665
- var resolveNotFoundConventionPath = (framework) => getMap()[framework]?.defaults?.notFound;
2666
- var setConventions = (map) => {
2667
- Reflect.set(globalThis, CONVENTIONS_KEY, map);
2668
- };
2669
- var isDev = () => true;
2670
- var buildErrorProps = (error) => {
2671
- if (error instanceof Error) {
2672
- return {
2673
- name: error.name,
2674
- message: error.message,
2675
- ...isDev() && error.stack ? { stack: error.stack } : {}
2676
- };
2677
- }
2678
- return { message: String(error), name: "Error" };
2679
- };
2680
- var renderReactError = async (conventionPath, errorProps) => {
2681
- const { createElement } = await import("react");
2682
- const { renderToReadableStream } = await import("react-dom/server");
2683
- const mod = await import(conventionPath);
2684
- const ErrorComponent = mod.default;
2685
- if (typeof ErrorComponent !== "function")
2686
- return null;
2687
- const element = createElement(ErrorComponent, errorProps);
2688
- const stream = await renderToReadableStream(element);
2689
- return new Response(stream, {
2690
- headers: { "Content-Type": "text/html" },
2691
- status: 500
2692
- });
2693
- };
2694
- var renderSvelteError = async (conventionPath, errorProps) => {
2695
- const { render } = await import("svelte/server");
2696
- const mod = await import(conventionPath);
2697
- const ErrorComponent = mod.default;
2698
- if (!ErrorComponent)
2699
- return null;
2700
- const { head, body } = render(ErrorComponent, {
2701
- props: errorProps
2702
- });
2703
- const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
2704
- return new Response(html, {
2705
- headers: { "Content-Type": "text/html" },
2706
- status: 500
2707
- });
2708
- };
2709
- var unescapeVueStyles = (ssrBody) => {
2710
- let styles = "";
2711
- const body = ssrBody.replace(/<style>([\s\S]*?)<\/style>/g, (_, css) => {
2712
- styles += `<style>${css.replace(/&quot;/g, '"').replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">")}</style>`;
2713
- return "";
2714
- });
2715
- return { body, styles };
2716
- };
2717
- var renderVueError = async (conventionPath, errorProps) => {
2718
- const { createSSRApp, h } = await import("vue");
2719
- const { renderToString } = await import("vue/server-renderer");
2720
- const mod = await import(conventionPath);
2721
- const ErrorComponent = mod.default;
2722
- if (!ErrorComponent)
2723
- return null;
2724
- const app = createSSRApp({
2725
- render: () => h(ErrorComponent, errorProps)
2726
- });
2727
- const rawBody = await renderToString(app);
2728
- const { styles, body } = unescapeVueStyles(rawBody);
2729
- const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
2730
- return new Response(html, {
2731
- headers: { "Content-Type": "text/html" },
2732
- status: 500
2733
- });
2734
- };
2735
- var renderAngularError = async (conventionPath, errorProps) => {
2736
- const mod = await import(conventionPath);
2737
- const renderFn = mod.default;
2738
- if (typeof renderFn !== "function")
2739
- return null;
2740
- const html = renderFn(errorProps);
2741
- return new Response(html, {
2742
- headers: { "Content-Type": "text/html" },
2743
- status: 500
2744
- });
2745
- };
2746
- var escapeHtml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
2747
- var replaceErrorTokens = (template, errorProps) => template.replace(/\{\{\s*name\s*\}\}/g, escapeHtml(errorProps.name)).replace(/\{\{\s*message\s*\}\}/g, escapeHtml(errorProps.message)).replace(/\{\{\s*stack\s*\}\}/g, errorProps.stack ? escapeHtml(errorProps.stack) : "");
2748
- var renderHtmlError = async (conventionPath, errorProps) => {
2749
- const template = await Bun.file(conventionPath).text();
2750
- const html = replaceErrorTokens(template, errorProps);
2751
- return new Response(html, {
2752
- headers: { "Content-Type": "text/html" },
2753
- status: 500
2754
- });
2755
- };
2756
- var logConventionRenderError = (framework, label, renderError) => {
2757
- const message = renderError instanceof Error ? renderError.message : "";
2758
- if (message.includes("Cannot find module") || message.includes("Cannot find package") || message.includes("not found in module")) {
2759
- console.error(`[SSR] Convention ${label} page for ${framework} failed: missing framework package. Ensure the ${framework} runtime is installed (e.g. bun add ${framework === "react" ? "react react-dom" : framework}).`);
2760
- return;
2761
- }
2762
- console.error(`[SSR] Failed to render ${framework} convention ${label} page:`, renderError);
2763
- };
2764
- var renderEmberError = async () => null;
2765
- var renderEmberNotFound = async () => null;
2766
- var ERROR_RENDERERS = {
2767
- angular: renderAngularError,
2768
- ember: renderEmberError,
2769
- html: renderHtmlError,
2770
- react: renderReactError,
2771
- svelte: renderSvelteError,
2772
- vue: renderVueError
2773
- };
2774
- var tryFrameworkErrorConvention = async (framework, pageName, errorProps, error) => {
2775
- let conventionPath = resolveErrorConventionPath(framework, pageName);
2776
- if (!conventionPath && error instanceof Error && error.stack) {
2777
- for (const match of error.stack.matchAll(/^\s*at\s+([A-Za-z_$][\w$]*)/gm)) {
2778
- const candidate = match[1];
2779
- if (!candidate)
2780
- continue;
2781
- conventionPath = resolveErrorConventionPath(framework, candidate);
2782
- if (conventionPath)
2783
- break;
2784
- }
2785
- }
2786
- if (!conventionPath)
2787
- return null;
2788
- const renderer = ERROR_RENDERERS[framework];
2789
- if (!renderer)
2790
- return null;
2791
- try {
2792
- return await renderer(conventionPath, errorProps);
2793
- } catch (renderError) {
2794
- logConventionRenderError(framework, "error", renderError);
2795
- }
2796
- return null;
2797
- };
2798
- var renderConventionError = async (framework, pageName, error) => {
2799
- const errorProps = buildErrorProps(error);
2800
- const frameworkResponse = await tryFrameworkErrorConvention(framework, pageName, errorProps, error);
2801
- if (frameworkResponse)
2802
- return frameworkResponse;
2803
- if (framework !== "html") {
2804
- const htmlResponse = await tryFrameworkErrorConvention("html", pageName, errorProps, error);
2805
- if (htmlResponse)
2806
- return htmlResponse;
2807
- }
2808
- return null;
2809
- };
2810
- var renderReactNotFound = async (conventionPath) => {
2811
- const { createElement } = await import("react");
2812
- const { renderToReadableStream } = await import("react-dom/server");
2813
- const mod = await import(conventionPath);
2814
- const NotFoundComponent = mod.default;
2815
- if (typeof NotFoundComponent !== "function")
2816
- return null;
2817
- const element = createElement(NotFoundComponent);
2818
- const stream = await renderToReadableStream(element);
2819
- return new Response(stream, {
2820
- headers: { "Content-Type": "text/html" },
2821
- status: 404
2822
- });
2823
- };
2824
- var renderSvelteNotFound = async (conventionPath) => {
2825
- const { render } = await import("svelte/server");
2826
- const mod = await import(conventionPath);
2827
- const NotFoundComponent = mod.default;
2828
- if (!NotFoundComponent)
2829
- return null;
2830
- const { head, body } = render(NotFoundComponent);
2831
- const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
2832
- return new Response(html, {
2833
- headers: { "Content-Type": "text/html" },
2834
- status: 404
2835
- });
2836
- };
2837
- var renderVueNotFound = async (conventionPath) => {
2838
- const { createSSRApp, h } = await import("vue");
2839
- const { renderToString } = await import("vue/server-renderer");
2840
- const mod = await import(conventionPath);
2841
- const NotFoundComponent = mod.default;
2842
- if (!NotFoundComponent)
2843
- return null;
2844
- const app = createSSRApp({
2845
- render: () => h(NotFoundComponent)
2846
- });
2847
- const rawBody = await renderToString(app);
2848
- const { styles, body } = unescapeVueStyles(rawBody);
2849
- const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
2850
- return new Response(html, {
2851
- headers: { "Content-Type": "text/html" },
2852
- status: 404
2853
- });
2854
- };
2855
- var renderAngularNotFound = async (conventionPath) => {
2856
- const mod = await import(conventionPath);
2857
- const renderFn = mod.default;
2858
- if (typeof renderFn !== "function")
2859
- return null;
2860
- const html = renderFn();
2861
- return new Response(html, {
2862
- headers: { "Content-Type": "text/html" },
2863
- status: 404
2864
- });
2865
- };
2866
- var renderHtmlNotFound = async (conventionPath) => {
2867
- const html = await Bun.file(conventionPath).text();
2868
- return new Response(html, {
2869
- headers: { "Content-Type": "text/html" },
2870
- status: 404
2871
- });
2872
- };
2873
- var NOT_FOUND_RENDERERS = {
2874
- angular: renderAngularNotFound,
2875
- ember: renderEmberNotFound,
2876
- html: renderHtmlNotFound,
2877
- react: renderReactNotFound,
2878
- svelte: renderSvelteNotFound,
2879
- vue: renderVueNotFound
2880
- };
2881
- var renderConventionNotFound = async (framework) => {
2882
- const conventionPath = resolveNotFoundConventionPath(framework);
2883
- if (!conventionPath)
2884
- return null;
2885
- const renderer = NOT_FOUND_RENDERERS[framework];
2886
- if (!renderer)
2887
- return null;
2888
- try {
2889
- return await renderer(conventionPath);
2890
- } catch (renderError) {
2891
- logConventionRenderError(framework, "not-found", renderError);
2892
- }
2893
- return null;
2894
- };
2895
- var NOT_FOUND_PRIORITY = [
2896
- "react",
2897
- "svelte",
2898
- "vue",
2899
- "angular",
2900
- "html"
2901
- ];
2902
- var renderFirstNotFound = async () => {
2903
- const renderNext = async (frameworks) => {
2904
- const [framework, ...remaining] = frameworks;
2905
- if (!framework) {
2906
- return null;
2907
- }
2908
- if (!getMap()[framework]?.defaults?.notFound) {
2909
- return renderNext(remaining);
2910
- }
2911
- const response = await renderConventionNotFound(framework);
2912
- if (response) {
2913
- return response;
2914
- }
2915
- return renderNext(remaining);
2916
- };
2917
- return renderNext(NOT_FOUND_PRIORITY);
2918
- };
2919
2961
 
2920
2962
  // src/svelte/pageHandler.ts
2963
+ init_spaRouteManifest();
2964
+ init_resolveConvention();
2921
2965
  var isRecord2 = (value) => typeof value === "object" && value !== null;
2922
2966
  var isGenericSvelteComponent = (value) => typeof value === "function" || isRecord2(value);
2923
2967
  var readHasIslands = (value) => {
@@ -2968,6 +3012,9 @@ var handleSveltePageRequest = async (input) => {
2968
3012
  url: requestPathname
2969
3013
  } : userProps;
2970
3014
  try {
3015
+ const spaNotFound = await renderSpaNotFound("svelte", derivePageName(resolvedPagePath), input.request);
3016
+ if (spaNotFound)
3017
+ return withPageCacheHeaders(spaNotFound, input.request);
2971
3018
  const handlerCallsite = resolvedOptions?.collectStreamingSlots === true ? undefined : getCurrentRouteRegistrationCallsite() ?? captureStreamingSlotWarningCallsite();
2972
3019
  const renderPageResponse = async () => {
2973
3020
  const resolvePageComponent = async () => {
@@ -3038,5 +3085,5 @@ export {
3038
3085
  handleSveltePageRequest
3039
3086
  };
3040
3087
 
3041
- //# debugId=06117E627CB6A42764756E2164756E21
3088
+ //# debugId=1E11CE6C861E5B9464756E2164756E21
3042
3089
  //# sourceMappingURL=server.js.map