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

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, {
@@ -4095,303 +4432,10 @@ var readSiblingCss = async (siblingJsPath) => {
4095
4432
  return "";
4096
4433
  }
4097
4434
  };
4098
- // src/utils/resolveConvention.ts
4099
- import { basename as basename2 } from "path";
4100
- var CONVENTIONS_KEY = "__absoluteConventions";
4101
- var isConventionsMap = (value) => Boolean(value) && typeof value === "object";
4102
- var getMap = () => {
4103
- const value = Reflect.get(globalThis, CONVENTIONS_KEY);
4104
- if (isConventionsMap(value))
4105
- return value;
4106
- const empty = {};
4107
- return empty;
4108
- };
4109
- var derivePageName = (pagePath) => {
4110
- const base = basename2(pagePath);
4111
- const dotIndex = base.indexOf(".");
4112
- const name = dotIndex > 0 ? base.slice(0, dotIndex) : base;
4113
- return toPascal(name);
4114
- };
4115
- var normalizeConventionPageName = (name) => toPascal(name).replace(/\d+$/, "");
4116
- var hasErrorConvention = (framework) => {
4117
- const conventions = getMap()[framework];
4118
- if (!conventions)
4119
- return false;
4120
- if (conventions.defaults?.error)
4121
- return true;
4122
- return Object.values(conventions.pages ?? {}).some((page) => Boolean(page.error));
4123
- };
4124
- var resolveErrorConventionPath = (framework, pageName) => {
4125
- const conventions = getMap()[framework];
4126
- if (!conventions)
4127
- return;
4128
- const exact = conventions.pages?.[pageName]?.error;
4129
- if (exact)
4130
- return exact;
4131
- const normalizedPageName = normalizeConventionPageName(pageName);
4132
- for (const [candidate, page] of Object.entries(conventions.pages ?? {})) {
4133
- if (normalizeConventionPageName(candidate) === normalizedPageName) {
4134
- return page.error ?? conventions.defaults?.error;
4135
- }
4136
- }
4137
- return conventions.defaults?.error;
4138
- };
4139
- var resolveNotFoundConventionPath = (framework) => getMap()[framework]?.defaults?.notFound;
4140
- var setConventions = (map) => {
4141
- Reflect.set(globalThis, CONVENTIONS_KEY, map);
4142
- };
4143
- var isDev = () => true;
4144
- var buildErrorProps = (error) => {
4145
- if (error instanceof Error) {
4146
- return {
4147
- name: error.name,
4148
- message: error.message,
4149
- ...isDev() && error.stack ? { stack: error.stack } : {}
4150
- };
4151
- }
4152
- return { message: String(error), name: "Error" };
4153
- };
4154
- var renderReactError = async (conventionPath, errorProps) => {
4155
- const { createElement } = await import("react");
4156
- const { renderToReadableStream } = await import("react-dom/server");
4157
- const mod = await import(conventionPath);
4158
- const ErrorComponent = mod.default;
4159
- if (typeof ErrorComponent !== "function")
4160
- return null;
4161
- const element = createElement(ErrorComponent, errorProps);
4162
- const stream = await renderToReadableStream(element);
4163
- return new Response(stream, {
4164
- headers: { "Content-Type": "text/html" },
4165
- status: 500
4166
- });
4167
- };
4168
- var renderSvelteError = async (conventionPath, errorProps) => {
4169
- const { render } = await import("svelte/server");
4170
- const mod = await import(conventionPath);
4171
- const ErrorComponent = mod.default;
4172
- if (!ErrorComponent)
4173
- return null;
4174
- const { head, body } = render(ErrorComponent, {
4175
- props: errorProps
4176
- });
4177
- const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
4178
- return new Response(html, {
4179
- headers: { "Content-Type": "text/html" },
4180
- status: 500
4181
- });
4182
- };
4183
- var unescapeVueStyles = (ssrBody) => {
4184
- let styles = "";
4185
- const body = ssrBody.replace(/<style>([\s\S]*?)<\/style>/g, (_, css) => {
4186
- styles += `<style>${css.replace(/&quot;/g, '"').replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">")}</style>`;
4187
- return "";
4188
- });
4189
- return { body, styles };
4190
- };
4191
- var renderVueError = async (conventionPath, errorProps) => {
4192
- const { createSSRApp, h } = await import("vue");
4193
- const { renderToString } = await import("vue/server-renderer");
4194
- const mod = await import(conventionPath);
4195
- const ErrorComponent = mod.default;
4196
- if (!ErrorComponent)
4197
- return null;
4198
- const app = createSSRApp({
4199
- render: () => h(ErrorComponent, errorProps)
4200
- });
4201
- const rawBody = await renderToString(app);
4202
- const { styles, body } = unescapeVueStyles(rawBody);
4203
- const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
4204
- return new Response(html, {
4205
- headers: { "Content-Type": "text/html" },
4206
- status: 500
4207
- });
4208
- };
4209
- var renderAngularError = async (conventionPath, errorProps) => {
4210
- const mod = await import(conventionPath);
4211
- const renderFn = mod.default;
4212
- if (typeof renderFn !== "function")
4213
- return null;
4214
- const html = renderFn(errorProps);
4215
- return new Response(html, {
4216
- headers: { "Content-Type": "text/html" },
4217
- status: 500
4218
- });
4219
- };
4220
- var escapeHtml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
4221
- 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) : "");
4222
- var renderHtmlError = async (conventionPath, errorProps) => {
4223
- const template = await Bun.file(conventionPath).text();
4224
- const html = replaceErrorTokens(template, errorProps);
4225
- return new Response(html, {
4226
- headers: { "Content-Type": "text/html" },
4227
- status: 500
4228
- });
4229
- };
4230
- var logConventionRenderError = (framework, label, renderError) => {
4231
- const message = renderError instanceof Error ? renderError.message : "";
4232
- if (message.includes("Cannot find module") || message.includes("Cannot find package") || message.includes("not found in module")) {
4233
- 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}).`);
4234
- return;
4235
- }
4236
- console.error(`[SSR] Failed to render ${framework} convention ${label} page:`, renderError);
4237
- };
4238
- var renderEmberError = async () => null;
4239
- var renderEmberNotFound = async () => null;
4240
- var ERROR_RENDERERS = {
4241
- angular: renderAngularError,
4242
- ember: renderEmberError,
4243
- html: renderHtmlError,
4244
- react: renderReactError,
4245
- svelte: renderSvelteError,
4246
- vue: renderVueError
4247
- };
4248
- var tryFrameworkErrorConvention = async (framework, pageName, errorProps, error) => {
4249
- let conventionPath = resolveErrorConventionPath(framework, pageName);
4250
- if (!conventionPath && error instanceof Error && error.stack) {
4251
- for (const match of error.stack.matchAll(/^\s*at\s+([A-Za-z_$][\w$]*)/gm)) {
4252
- const candidate = match[1];
4253
- if (!candidate)
4254
- continue;
4255
- conventionPath = resolveErrorConventionPath(framework, candidate);
4256
- if (conventionPath)
4257
- break;
4258
- }
4259
- }
4260
- if (!conventionPath)
4261
- return null;
4262
- const renderer = ERROR_RENDERERS[framework];
4263
- if (!renderer)
4264
- return null;
4265
- try {
4266
- return await renderer(conventionPath, errorProps);
4267
- } catch (renderError) {
4268
- logConventionRenderError(framework, "error", renderError);
4269
- }
4270
- return null;
4271
- };
4272
- var renderConventionError = async (framework, pageName, error) => {
4273
- const errorProps = buildErrorProps(error);
4274
- const frameworkResponse = await tryFrameworkErrorConvention(framework, pageName, errorProps, error);
4275
- if (frameworkResponse)
4276
- return frameworkResponse;
4277
- if (framework !== "html") {
4278
- const htmlResponse = await tryFrameworkErrorConvention("html", pageName, errorProps, error);
4279
- if (htmlResponse)
4280
- return htmlResponse;
4281
- }
4282
- return null;
4283
- };
4284
- var renderReactNotFound = async (conventionPath) => {
4285
- const { createElement } = await import("react");
4286
- const { renderToReadableStream } = await import("react-dom/server");
4287
- const mod = await import(conventionPath);
4288
- const NotFoundComponent = mod.default;
4289
- if (typeof NotFoundComponent !== "function")
4290
- return null;
4291
- const element = createElement(NotFoundComponent);
4292
- const stream = await renderToReadableStream(element);
4293
- return new Response(stream, {
4294
- headers: { "Content-Type": "text/html" },
4295
- status: 404
4296
- });
4297
- };
4298
- var renderSvelteNotFound = async (conventionPath) => {
4299
- const { render } = await import("svelte/server");
4300
- const mod = await import(conventionPath);
4301
- const NotFoundComponent = mod.default;
4302
- if (!NotFoundComponent)
4303
- return null;
4304
- const { head, body } = render(NotFoundComponent);
4305
- const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
4306
- return new Response(html, {
4307
- headers: { "Content-Type": "text/html" },
4308
- status: 404
4309
- });
4310
- };
4311
- var renderVueNotFound = async (conventionPath) => {
4312
- const { createSSRApp, h } = await import("vue");
4313
- const { renderToString } = await import("vue/server-renderer");
4314
- const mod = await import(conventionPath);
4315
- const NotFoundComponent = mod.default;
4316
- if (!NotFoundComponent)
4317
- return null;
4318
- const app = createSSRApp({
4319
- render: () => h(NotFoundComponent)
4320
- });
4321
- const rawBody = await renderToString(app);
4322
- const { styles, body } = unescapeVueStyles(rawBody);
4323
- const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
4324
- return new Response(html, {
4325
- headers: { "Content-Type": "text/html" },
4326
- status: 404
4327
- });
4328
- };
4329
- var renderAngularNotFound = async (conventionPath) => {
4330
- const mod = await import(conventionPath);
4331
- const renderFn = mod.default;
4332
- if (typeof renderFn !== "function")
4333
- return null;
4334
- const html = renderFn();
4335
- return new Response(html, {
4336
- headers: { "Content-Type": "text/html" },
4337
- status: 404
4338
- });
4339
- };
4340
- var renderHtmlNotFound = async (conventionPath) => {
4341
- const html = await Bun.file(conventionPath).text();
4342
- return new Response(html, {
4343
- headers: { "Content-Type": "text/html" },
4344
- status: 404
4345
- });
4346
- };
4347
- var NOT_FOUND_RENDERERS = {
4348
- angular: renderAngularNotFound,
4349
- ember: renderEmberNotFound,
4350
- html: renderHtmlNotFound,
4351
- react: renderReactNotFound,
4352
- svelte: renderSvelteNotFound,
4353
- vue: renderVueNotFound
4354
- };
4355
- var renderConventionNotFound = async (framework) => {
4356
- const conventionPath = resolveNotFoundConventionPath(framework);
4357
- if (!conventionPath)
4358
- return null;
4359
- const renderer = NOT_FOUND_RENDERERS[framework];
4360
- if (!renderer)
4361
- return null;
4362
- try {
4363
- return await renderer(conventionPath);
4364
- } catch (renderError) {
4365
- logConventionRenderError(framework, "not-found", renderError);
4366
- }
4367
- return null;
4368
- };
4369
- var NOT_FOUND_PRIORITY = [
4370
- "react",
4371
- "svelte",
4372
- "vue",
4373
- "angular",
4374
- "html"
4375
- ];
4376
- var renderFirstNotFound = async () => {
4377
- const renderNext = async (frameworks) => {
4378
- const [framework, ...remaining] = frameworks;
4379
- if (!framework) {
4380
- return null;
4381
- }
4382
- if (!getMap()[framework]?.defaults?.notFound) {
4383
- return renderNext(remaining);
4384
- }
4385
- const response = await renderConventionNotFound(framework);
4386
- if (response) {
4387
- return response;
4388
- }
4389
- return renderNext(remaining);
4390
- };
4391
- return renderNext(NOT_FOUND_PRIORITY);
4392
- };
4393
4435
 
4394
4436
  // src/svelte/pageHandler.ts
4437
+ init_spaRouteManifest();
4438
+ init_resolveConvention();
4395
4439
  var isRecord2 = (value) => typeof value === "object" && value !== null;
4396
4440
  var isGenericSvelteComponent = (value) => typeof value === "function" || isRecord2(value);
4397
4441
  var readHasIslands = (value) => {
@@ -4442,6 +4486,9 @@ var handleSveltePageRequest = async (input) => {
4442
4486
  url: requestPathname
4443
4487
  } : userProps;
4444
4488
  try {
4489
+ const spaNotFound = await renderSpaNotFound("svelte", derivePageName(resolvedPagePath), input.request);
4490
+ if (spaNotFound)
4491
+ return withPageCacheHeaders(spaNotFound, input.request);
4445
4492
  const handlerCallsite = resolvedOptions?.collectStreamingSlots === true ? undefined : getCurrentRouteRegistrationCallsite() ?? captureStreamingSlotWarningCallsite();
4446
4493
  const renderPageResponse = async () => {
4447
4494
  const resolvePageComponent = async () => {
@@ -4649,5 +4696,5 @@ export {
4649
4696
  createTypedIsland
4650
4697
  };
4651
4698
 
4652
- //# debugId=60861DEB9D7F3C6864756E2164756E21
4699
+ //# debugId=EC5C9E9600BCB3DE64756E2164756E21
4653
4700
  //# sourceMappingURL=index.js.map