@absolutejs/absolute 0.19.0-beta.694 → 0.19.0-beta.696

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 (43) hide show
  1. package/README.md +1 -1
  2. package/dist/angular/browser.js +48 -40
  3. package/dist/angular/browser.js.map +4 -4
  4. package/dist/angular/index.js +3090 -2890
  5. package/dist/angular/index.js.map +15 -14
  6. package/dist/angular/server.js +3083 -2883
  7. package/dist/angular/server.js.map +15 -15
  8. package/dist/build.js +42942 -6408
  9. package/dist/build.js.map +9 -20
  10. package/dist/cli/index.js +2 -1
  11. package/dist/core/streamingSlotRegistrar.js +24 -16
  12. package/dist/core/streamingSlotRegistrar.js.map +2 -2
  13. package/dist/core/streamingSlotRegistry.js +42 -29
  14. package/dist/core/streamingSlotRegistry.js.map +2 -2
  15. package/dist/index.js +41443 -4405
  16. package/dist/index.js.map +28 -40
  17. package/dist/islands/index.js +135 -11
  18. package/dist/islands/index.js.map +3 -3
  19. package/dist/react/components/index.js +24 -16
  20. package/dist/react/components/index.js.map +2 -2
  21. package/dist/react/index.js +1056 -873
  22. package/dist/react/index.js.map +13 -13
  23. package/dist/react/server.js +903 -843
  24. package/dist/react/server.js.map +11 -11
  25. package/dist/src/build/compileTailwind.d.ts +3 -0
  26. package/dist/src/build/stylePreprocessor.d.ts +2 -1
  27. package/dist/src/core/build.d.ts +1 -1
  28. package/dist/src/core/pageHandlers.d.ts +0 -1
  29. package/dist/src/core/ssrCache.d.ts +3 -0
  30. package/dist/svelte/index.js +1104 -916
  31. package/dist/svelte/index.js.map +15 -14
  32. package/dist/svelte/server.js +891 -702
  33. package/dist/svelte/server.js.map +13 -13
  34. package/dist/types/build.d.ts +18 -4
  35. package/dist/types/index.d.ts +0 -1
  36. package/dist/types/island.d.ts +14 -11
  37. package/dist/vue/components/index.js +24 -16
  38. package/dist/vue/components/index.js.map +2 -2
  39. package/dist/vue/index.js +1144 -956
  40. package/dist/vue/index.js.map +13 -13
  41. package/dist/vue/server.js +908 -841
  42. package/dist/vue/server.js.map +11 -11
  43. package/package.json +20 -8
@@ -78,99 +78,6 @@ var __legacyMetadataTS = (k, v) => {
78
78
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
79
79
  var __require = import.meta.require;
80
80
 
81
- // src/core/streamingSlotRegistrar.ts
82
- var STREAMING_SLOT_REGISTRAR_KEY, STREAMING_SLOT_WARNING_STORAGE_KEY, STREAMING_SLOT_COLLECTION_STORAGE_KEY, getRegisteredStreamingSlotRegistrar = () => {
83
- const value = Reflect.get(globalThis, STREAMING_SLOT_REGISTRAR_KEY);
84
- if (typeof value === "function" || value === null) {
85
- return value;
86
- }
87
- return;
88
- }, isObjectRecord = (value) => Boolean(value) && typeof value === "object", isStreamingSlotWarningController = (value) => isObjectRecord(value) && ("maybeWarn" in value) && typeof value.maybeWarn === "function", isStreamingSlotCollectionController = (value) => isObjectRecord(value) && ("isCollecting" in value) && typeof value.isCollecting === "function", getWarningController = () => {
89
- const value = Reflect.get(globalThis, STREAMING_SLOT_WARNING_STORAGE_KEY);
90
- if (value === null || typeof value === "undefined")
91
- return;
92
- return isStreamingSlotWarningController(value) ? value : undefined;
93
- }, getCollectionController = () => {
94
- const value = Reflect.get(globalThis, STREAMING_SLOT_COLLECTION_STORAGE_KEY);
95
- if (value === null || typeof value === "undefined")
96
- return;
97
- return isStreamingSlotCollectionController(value) ? value : undefined;
98
- }, hasRegisteredStreamingSlotRegistrar = () => typeof getRegisteredStreamingSlotRegistrar() === "function", isStreamingSlotCollectionActive = () => getCollectionController()?.isCollecting() === true, registerStreamingSlot = (slot) => {
99
- getRegisteredStreamingSlotRegistrar()?.(slot);
100
- }, setStreamingSlotCollectionController = (controller) => {
101
- Reflect.set(globalThis, STREAMING_SLOT_COLLECTION_STORAGE_KEY, controller);
102
- }, setStreamingSlotRegistrar = (nextRegistrar) => {
103
- Reflect.set(globalThis, STREAMING_SLOT_REGISTRAR_KEY, nextRegistrar);
104
- }, setStreamingSlotWarningController = (controller) => {
105
- Reflect.set(globalThis, STREAMING_SLOT_WARNING_STORAGE_KEY, controller);
106
- }, warnMissingStreamingSlotCollector = (primitiveName) => {
107
- if (isStreamingSlotCollectionActive()) {
108
- return;
109
- }
110
- getWarningController()?.maybeWarn(primitiveName);
111
- };
112
- var init_streamingSlotRegistrar = __esm(() => {
113
- STREAMING_SLOT_REGISTRAR_KEY = Symbol.for("absolutejs.streamingSlotRegistrar");
114
- STREAMING_SLOT_WARNING_STORAGE_KEY = Symbol.for("absolutejs.streamingSlotWarningController");
115
- STREAMING_SLOT_COLLECTION_STORAGE_KEY = Symbol.for("absolutejs.streamingSlotCollectionController");
116
- });
117
-
118
- // src/core/streamingSlotRegistry.ts
119
- var STREAMING_SLOT_STORAGE_KEY, isObjectRecord2 = (value) => Boolean(value) && typeof value === "object", isAsyncLocalStorage = (value) => isObjectRecord2(value) && ("getStore" in value) && typeof value.getStore === "function" && ("run" in value) && typeof value.run === "function", getStorageGlobal = () => {
120
- const value = Reflect.get(globalThis, STREAMING_SLOT_STORAGE_KEY);
121
- if (value === null || typeof value === "undefined") {
122
- return value;
123
- }
124
- return isAsyncLocalStorage(value) ? value : undefined;
125
- }, isServerRuntime = () => typeof process !== "undefined" && typeof process.versions?.node === "string", ensureAsyncLocalStorage = async () => {
126
- const storage = getStorageGlobal();
127
- if (typeof storage !== "undefined") {
128
- return storage;
129
- }
130
- if (!isServerRuntime()) {
131
- Reflect.set(globalThis, STREAMING_SLOT_STORAGE_KEY, null);
132
- return getStorageGlobal();
133
- }
134
- const mod = await import("async_hooks");
135
- Reflect.set(globalThis, STREAMING_SLOT_STORAGE_KEY, new mod.AsyncLocalStorage);
136
- return getStorageGlobal();
137
- }, getActiveSlotStore = () => {
138
- const storage = getStorageGlobal();
139
- if (!storage)
140
- return;
141
- return storage.getStore();
142
- }, registerStreamingSlot2 = (slot) => {
143
- const store = getActiveSlotStore();
144
- if (!store)
145
- return;
146
- store.set(slot.id, slot);
147
- }, hasActiveStreamingSlotRegistry = () => getActiveSlotStore() !== undefined, runWithStreamingSlotRegistry = async (task) => {
148
- const storage = await ensureAsyncLocalStorage();
149
- if (!storage) {
150
- const slots = [];
151
- return {
152
- result: await task(),
153
- slots
154
- };
155
- }
156
- return storage.run(new Map, async () => {
157
- const result = await task();
158
- const store = storage.getStore();
159
- return {
160
- result,
161
- slots: store ? [...store.values()] : []
162
- };
163
- });
164
- };
165
- var init_streamingSlotRegistry = __esm(() => {
166
- init_streamingSlotRegistrar();
167
- STREAMING_SLOT_STORAGE_KEY = Symbol.for("absolutejs.streamingSlotAsyncLocalStorage");
168
- setStreamingSlotRegistrar(registerStreamingSlot2);
169
- setStreamingSlotCollectionController({
170
- isCollecting: () => getActiveSlotStore() !== undefined
171
- });
172
- });
173
-
174
81
  // src/build/resolvePackageImport.ts
175
82
  import { resolve, join } from "path";
176
83
  import { existsSync, readFileSync } from "fs";
@@ -359,12 +266,27 @@ var init_lowerAwaitSlotSyntax = __esm(() => {
359
266
  });
360
267
 
361
268
  // src/build/stylePreprocessor.ts
269
+ var exports_stylePreprocessor = {};
270
+ __export(exports_stylePreprocessor, {
271
+ stylePreprocessorPlugin: () => stylePreprocessorPlugin,
272
+ isStylePath: () => isStylePath,
273
+ isStyleModulePath: () => isStyleModulePath,
274
+ isPreprocessableStylePath: () => isPreprocessableStylePath,
275
+ getStyleBaseName: () => getStyleBaseName,
276
+ getCssOutputExtension: () => getCssOutputExtension,
277
+ createSvelteStylePreprocessor: () => createSvelteStylePreprocessor,
278
+ createStyleTransformConfig: () => createStyleTransformConfig,
279
+ createStylePreprocessorPlugin: () => createStylePreprocessorPlugin,
280
+ compileStyleSource: () => compileStyleSource,
281
+ compileStyleFileIfNeededSync: () => compileStyleFileIfNeededSync,
282
+ compileStyleFileIfNeeded: () => compileStyleFileIfNeeded
283
+ });
362
284
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
363
285
  import { readFile } from "fs/promises";
364
286
  import { createRequire } from "module";
365
287
  import { dirname, extname, isAbsolute, join as join2, relative, resolve as resolve2 } from "path";
366
288
  import { fileURLToPath } from "url";
367
- var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATTERN, importOptionalPeer, requireOptionalPeer, requireFromCwd, isPreprocessableStylePath = (filePath) => STYLE_EXTENSION_PATTERN.test(filePath), isStyleModulePath = (filePath) => STYLE_MODULE_EXTENSION_PATTERN.test(filePath), isStylePath = (filePath) => /\.(css|s[ac]ss|less|styl(?:us)?)$/i.test(filePath), getStyleBaseName = (filePath) => filePath.replace(/\.(css|s[ac]ss|less|styl(?:us)?)$/i, ""), getStyleLanguage = (filePathOrLanguage) => {
289
+ var CSS_EXTENSION_PATTERN, STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATTERN, importOptionalPeer, requireOptionalPeer, requireFromCwd, isPreprocessableStylePath = (filePath) => STYLE_EXTENSION_PATTERN.test(filePath), isStyleModulePath = (filePath) => STYLE_MODULE_EXTENSION_PATTERN.test(filePath), isStylePath = (filePath) => /\.(css|s[ac]ss|less|styl(?:us)?)$/i.test(filePath), getStyleBaseName = (filePath) => filePath.replace(/\.(css|s[ac]ss|less|styl(?:us)?)$/i, ""), getStyleLanguage = (filePathOrLanguage) => {
368
290
  const normalized = filePathOrLanguage.toLowerCase();
369
291
  if (normalized === "scss" || normalized.endsWith(".scss"))
370
292
  return "scss";
@@ -375,7 +297,13 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
375
297
  if (normalized === "styl" || normalized === "stylus" || normalized.endsWith(".styl") || normalized.endsWith(".stylus"))
376
298
  return "stylus";
377
299
  return null;
378
- }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), normalizeLoadPaths = (filePath, paths = []) => [
300
+ }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), requireOptionalPeerSync = (specifier) => {
301
+ try {
302
+ return requireFromCwd(specifier);
303
+ } catch {
304
+ return requireOptionalPeer(specifier);
305
+ }
306
+ }, normalizeLoadPaths = (filePath, paths = []) => [
379
307
  dirname(filePath),
380
308
  process.cwd(),
381
309
  ...paths.map((path) => resolve2(process.cwd(), path))
@@ -504,8 +432,72 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
504
432
  }, getSassOptions = (config, language) => ({
505
433
  ...config?.sass ?? {},
506
434
  ...language === "scss" ? config?.scss ?? {} : {}
507
- }), getLessOptions = (config) => config?.less ?? {}, getStylusOptions = (config) => config?.stylus ?? {}, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
508
- ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, config) => ({
435
+ }), getLessOptions = (config) => config?.less ?? {}, getStylusOptions = (config) => config?.stylus ?? {}, createStyleTransformConfig = (stylePreprocessors, postcss) => postcss === undefined ? stylePreprocessors : { ...stylePreprocessors ?? {}, postcss }, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
436
+ ${contents}` : contents, normalizePostcssModule = (mod) => {
437
+ if (mod && typeof mod === "object" && "default" in mod) {
438
+ return mod.default ?? mod;
439
+ }
440
+ return mod;
441
+ }, loadPostcssConfigFile = async (configPath) => {
442
+ const resolved = resolve2(process.cwd(), configPath);
443
+ const loaded = resolved.endsWith(".cjs") || resolved.endsWith(".cts") ? requireOptionalPeerSync(resolved) : await importOptionalPeer(`${new URL(`file://${resolved}`).href}?t=${Date.now()}`);
444
+ const config = normalizePostcssModule(loaded);
445
+ const value = typeof config === "function" ? await config({
446
+ cwd: process.cwd(),
447
+ env: "development"
448
+ }) : config;
449
+ return normalizePostcssModule(value) ?? {};
450
+ }, normalizePostcssPlugins = (plugins) => {
451
+ if (!plugins)
452
+ return [];
453
+ if (Array.isArray(plugins))
454
+ return plugins.filter(Boolean);
455
+ const resolved = [];
456
+ for (const [specifier, options] of Object.entries(plugins)) {
457
+ if (options === false)
458
+ continue;
459
+ const mod = normalizePostcssModule(requireOptionalPeerSync(specifier));
460
+ const plugin = typeof mod === "function" ? mod(options === true ? undefined : options) : mod;
461
+ if (plugin)
462
+ resolved.push(plugin);
463
+ }
464
+ return resolved;
465
+ }, resolvePostcssConfig = async (config) => {
466
+ const inlineConfig = config?.postcss;
467
+ if (!inlineConfig)
468
+ return null;
469
+ const fileConfig = inlineConfig.config ? await loadPostcssConfigFile(inlineConfig.config) : {};
470
+ const plugins = [
471
+ ...normalizePostcssPlugins(fileConfig.plugins),
472
+ ...normalizePostcssPlugins(inlineConfig.plugins)
473
+ ];
474
+ if (plugins.length === 0)
475
+ return null;
476
+ return {
477
+ options: {
478
+ ...fileConfig.options ?? {},
479
+ ...inlineConfig.options ?? {}
480
+ },
481
+ plugins
482
+ };
483
+ }, runPostcss = async (css, filePath, config) => {
484
+ const postcssConfig = await resolvePostcssConfig(config);
485
+ if (!postcssConfig)
486
+ return css;
487
+ let postcssModule;
488
+ try {
489
+ postcssModule = await importOptionalPeer("postcss");
490
+ } catch {
491
+ throw missingDependencyError("postcss", filePath);
492
+ }
493
+ const postcss = postcssModule.default ?? postcssModule;
494
+ const result = await postcss(postcssConfig.plugins).process(css, {
495
+ from: filePath,
496
+ map: false,
497
+ ...postcssConfig.options
498
+ });
499
+ return result.css;
500
+ }, createSassImporter = (entryFile, loadPaths, language, config) => ({
509
501
  canonicalize(specifier, options) {
510
502
  const fromDirectory = options.containingUrl ? dirname(fileURLToPath(options.containingUrl)) : dirname(entryFile);
511
503
  const resolved = resolveImportPath(specifier, fromDirectory, loadPaths, language, config);
@@ -584,7 +576,7 @@ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, c
584
576
  syntax: language === "sass" ? "indented" : "scss",
585
577
  url: new URL(`file://${filePath}`)
586
578
  });
587
- return result.css;
579
+ return runPostcss(result.css, filePath, config);
588
580
  }
589
581
  if (language === "less") {
590
582
  const options = getLessOptions(config);
@@ -609,15 +601,15 @@ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, c
609
601
  createLessFileManager(filePath, loadPaths, config)
610
602
  ]
611
603
  });
612
- return result.css;
604
+ return runPostcss(result.css, filePath, config);
613
605
  }
614
606
  if (language === "stylus") {
615
607
  const options = getStylusOptions(config);
616
608
  const loadPaths = normalizeLoadPaths(filePath, options.paths);
617
609
  const contents = withAdditionalData(preprocessLoadedStyle(rawContents, filePath, filePath, loadPaths, "stylus", config), options.additionalData);
618
- return renderStylus(contents, filePath, loadPaths, options);
610
+ return runPostcss(await renderStylus(contents, filePath, loadPaths, options), filePath, config);
619
611
  }
620
- return rawContents;
612
+ return runPostcss(rawContents, filePath, config);
621
613
  }, createStylePreprocessorPlugin = (config) => ({
622
614
  name: "absolute-style-preprocessor",
623
615
  setup(build) {
@@ -653,6 +645,10 @@ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, c
653
645
  loader: "css"
654
646
  };
655
647
  });
648
+ build.onLoad({ filter: CSS_EXTENSION_PATTERN }, async ({ path }) => ({
649
+ contents: await compileStyleSource(path, undefined, undefined, config),
650
+ loader: "css"
651
+ }));
656
652
  }
657
653
  }), stylePreprocessorPlugin, createSvelteStylePreprocessor = (config) => ({
658
654
  style: async ({
@@ -670,11 +666,46 @@ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, c
670
666
  }
671
667
  }), compileStyleFileIfNeeded = async (filePath, config) => {
672
668
  if (!isPreprocessableStylePath(filePath)) {
673
- return readFile(filePath, "utf-8");
669
+ return runPostcss(await readFile(filePath, "utf-8"), filePath, config);
674
670
  }
675
671
  return compileStyleSource(filePath, undefined, undefined, config);
676
- };
672
+ }, compileStyleFileIfNeededSync = (filePath, config) => {
673
+ const rawContents = readFileSync2(filePath, "utf-8");
674
+ const language = getStyleLanguage(filePath);
675
+ if (config?.postcss) {
676
+ throw new Error(`Unable to compile ${filePath}: PostCSS preprocessing is async-only.`);
677
+ }
678
+ if (language === "scss" || language === "sass") {
679
+ const options = getSassOptions(config, language);
680
+ const packageName = options.implementation ?? "sass";
681
+ let sass;
682
+ try {
683
+ sass = requireOptionalPeerSync(packageName);
684
+ } catch {
685
+ throw missingDependencyError(packageName, filePath);
686
+ }
687
+ const contents = withAdditionalData(rawContents, options.additionalData);
688
+ const loadPaths = normalizeLoadPaths(filePath, options.loadPaths);
689
+ return sass.compileString(contents, {
690
+ importers: [
691
+ createSassImporter(filePath, loadPaths, language, config)
692
+ ],
693
+ loadPaths,
694
+ style: "expanded",
695
+ syntax: language === "sass" ? "indented" : "scss",
696
+ url: new URL(`file://${filePath}`)
697
+ }).css;
698
+ }
699
+ if (language === "less") {
700
+ throw new Error(`Unable to compile ${filePath}: Less styleUrl preprocessing is async-only. Import the Less file from a bundled entrypoint or use SCSS/CSS for Angular styleUrl.`);
701
+ }
702
+ if (language === "stylus") {
703
+ throw new Error(`Unable to compile ${filePath}: Stylus styleUrl preprocessing is async-only. Import the Stylus file from a bundled entrypoint or use SCSS/CSS for Angular styleUrl.`);
704
+ }
705
+ return rawContents;
706
+ }, getCssOutputExtension = (filePath) => isPreprocessableStylePath(filePath) ? ".css" : extname(filePath);
677
707
  var init_stylePreprocessor = __esm(() => {
708
+ CSS_EXTENSION_PATTERN = /\.css$/i;
678
709
  STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less|styl(?:us)?)$/i;
679
710
  STYLE_MODULE_EXTENSION_PATTERN = /\.module\.(s[ac]ss|less|styl(?:us)?)$/i;
680
711
  STYLE_LANGUAGE_PATTERN = /^(s[ac]ss|less|styl(?:us)?)$/i;
@@ -864,305 +895,107 @@ var init_svelteServerModule = __esm(() => {
864
895
  });
865
896
  });
866
897
 
867
- // src/core/islandPageContext.ts
868
- var BOOTSTRAP_MANIFEST_KEY = "BootstrapClient", ISLAND_MARKER = 'data-island="true"', MANIFEST_MARKER = "__ABSOLUTE_MANIFEST__", ISLAND_STATE_MARKER = "__ABS_ISLAND_STATE__", CLOSING_HEAD_TAG = "</head>", buildIslandsHeadMarkup = (manifest) => {
869
- const manifestScript = `<script>window.__ABSOLUTE_MANIFEST__ = ${JSON.stringify(manifest)}</script>`;
870
- const islandStateScript = `<script>window.__ABS_ISLAND_STATE__ = ${JSON.stringify(globalThis.__ABS_ISLAND_STATE__ ?? {})}</script>`;
871
- const bootstrapPath = manifest[BOOTSTRAP_MANIFEST_KEY];
872
- const bootstrapScript = bootstrapPath ? `<script type="module" src="${bootstrapPath}"></script>` : "";
873
- return `${manifestScript}${islandStateScript}${bootstrapScript}`;
874
- }, injectHeadMarkup = (html, markup) => {
875
- const closingHeadIndex = html.indexOf("</head>");
876
- if (closingHeadIndex >= 0) {
877
- return `${html.slice(0, closingHeadIndex)}${markup}${html.slice(closingHeadIndex)}`;
898
+ // src/core/devRouteRegistrationCallsite.ts
899
+ var exports_devRouteRegistrationCallsite = {};
900
+ __export(exports_devRouteRegistrationCallsite, {
901
+ patchElysiaRouteRegistrationCallsites: () => patchElysiaRouteRegistrationCallsites,
902
+ getCurrentRouteRegistrationCallsite: () => getCurrentRouteRegistrationCallsite
903
+ });
904
+ import { AsyncLocalStorage } from "async_hooks";
905
+ import { Elysia } from "elysia";
906
+ var ROUTE_CALLSITE_STORAGE_KEY, ROUTE_CALLSITE_PATCHED_KEY, ROUTE_METHOD_NAMES, isObjectRecord3 = (value) => Boolean(value) && typeof value === "object", isAsyncLocalStorage2 = (value) => isObjectRecord3(value) && ("getStore" in value) && typeof value.getStore === "function" && ("run" in value) && typeof value.run === "function", getRouteCallsiteStorage = () => {
907
+ const value = Reflect.get(globalThis, ROUTE_CALLSITE_STORAGE_KEY);
908
+ if (value === null || typeof value === "undefined") {
909
+ return;
878
910
  }
879
- const openingBodyIndex = html.indexOf("<body");
880
- if (openingBodyIndex >= 0) {
881
- const bodyStart = html.indexOf(">", openingBodyIndex);
882
- if (bodyStart >= 0) {
883
- return `${html.slice(0, openingBodyIndex)}<head>${markup}</head>${html.slice(openingBodyIndex)}`;
911
+ return isAsyncLocalStorage2(value) ? value : undefined;
912
+ }, ensureRouteCallsiteStorage = () => {
913
+ const existing = getRouteCallsiteStorage();
914
+ if (existing) {
915
+ return existing;
916
+ }
917
+ const storage = new AsyncLocalStorage;
918
+ Reflect.set(globalThis, ROUTE_CALLSITE_STORAGE_KEY, storage);
919
+ return storage;
920
+ }, normalizeCallsitePath = (value) => value.replace(`${process.cwd()}/`, "").replace(process.cwd(), "").replace(/^\.\/+/, ""), extractRouteRegistrationCallsite = (stack) => {
921
+ const frames = stack.split(`
922
+ `).slice(1).map((line) => line.trim());
923
+ for (const frame of frames) {
924
+ if (frame.includes("/node_modules/") || frame.includes("/dist/") || frame.includes("/src/core/devRouteRegistrationCallsite.")) {
925
+ continue;
926
+ }
927
+ const locationMatch = frame.match(/\((\/[^)]+:\d+:\d+)\)$/) ?? frame.match(/at (\/[^ ]+:\d+:\d+)$/);
928
+ if (locationMatch?.[1]) {
929
+ return normalizeCallsitePath(locationMatch[1]);
884
930
  }
885
931
  }
886
- return `<!DOCTYPE html><html><head>${markup}</head><body>${html}</body></html>`;
887
- }, streamChunkToString = (value, decoder) => typeof value === "string" ? value : decoder.decode(value, { stream: true }), flushSafePendingText = (controller, encoder, pending, lookbehind) => {
888
- if (pending.length <= lookbehind) {
889
- return pending;
932
+ return;
933
+ }, captureRouteRegistrationCallsite = () => {
934
+ const { stack } = new Error;
935
+ if (!stack) {
936
+ return;
890
937
  }
891
- const safeText = pending.slice(0, pending.length - lookbehind);
892
- controller.enqueue(encoder.encode(safeText));
893
- return pending.slice(-lookbehind);
894
- }, updateInjectedState = (consumed, injected, pending) => {
895
- if (consumed.done) {
896
- return { done: true, injected, pending };
938
+ return extractRouteRegistrationCallsite(stack);
939
+ }, wrapRouteHandlerWithCallsite = (handler, callsite) => {
940
+ if (typeof handler !== "function" || !callsite) {
941
+ return handler;
897
942
  }
898
- return {
899
- done: false,
900
- injected: consumed.injected,
901
- pending: consumed.pending
943
+ const storage = ensureRouteCallsiteStorage();
944
+ return function wrappedRouteHandler(...args) {
945
+ return storage.run({ callsite }, () => Reflect.apply(handler, this, args));
902
946
  };
903
- }, readStreamChunk = async (reader) => {
904
- const { done, value } = await reader.read();
905
- if (done || !value) {
906
- return { done, value: undefined };
947
+ }, getCurrentRouteRegistrationCallsite = () => getRouteCallsiteStorage()?.getStore()?.callsite, patchElysiaRouteRegistrationCallsites = () => {
948
+ if (false) {}
949
+ if (Reflect.get(globalThis, ROUTE_CALLSITE_PATCHED_KEY) === true) {
950
+ return;
907
951
  }
908
- return { done, value };
909
- }, pipeStreamWithHeadInjection = (stream, markup) => {
910
- const encoder = new TextEncoder;
911
- const decoder = new TextDecoder;
912
- const lookbehind = CLOSING_HEAD_TAG.length - 1;
913
- const processPending = (controller, pending, injected) => {
914
- if (injected) {
915
- controller.enqueue(encoder.encode(pending));
916
- return { injected, pending: "" };
917
- }
918
- const headIndex = pending.indexOf(CLOSING_HEAD_TAG);
919
- if (headIndex >= 0) {
920
- const next = `${pending.slice(0, headIndex)}${markup}${pending.slice(headIndex)}`;
921
- controller.enqueue(encoder.encode(next));
922
- return { injected: true, pending: "" };
952
+ const prototype = Elysia.prototype;
953
+ for (const methodName of ROUTE_METHOD_NAMES) {
954
+ const originalMethod = prototype[methodName];
955
+ if (typeof originalMethod !== "function") {
956
+ continue;
923
957
  }
924
- return {
925
- injected,
926
- pending: flushSafePendingText(controller, encoder, pending, lookbehind)
958
+ prototype[methodName] = function patchedRouteMethod(path, handler, ...rest) {
959
+ const callsite = captureRouteRegistrationCallsite();
960
+ return Reflect.apply(originalMethod, this, [
961
+ path,
962
+ wrapRouteHandlerWithCallsite(handler, callsite),
963
+ ...rest
964
+ ]);
927
965
  };
928
- };
929
- const finishHeadInjectionStream = (controller, pending, injected) => {
930
- let finalPending = pending + decoder.decode();
931
- if (!injected) {
932
- finalPending = injectHeadMarkup(finalPending, markup);
933
- }
934
- if (finalPending.length > 0) {
935
- controller.enqueue(encoder.encode(finalPending));
936
- }
937
- controller.close();
938
- };
939
- const consumeHeadChunk = async (controller, reader, pending, injected) => {
940
- const { done, value } = await readStreamChunk(reader);
941
- if (done || !value) {
942
- return { done, injected, pending };
943
- }
944
- const processed = processPending(controller, pending + streamChunkToString(value, decoder), injected);
945
- return {
946
- done,
947
- injected: processed.injected,
948
- pending: processed.pending
949
- };
950
- };
951
- const runHeadInjectionLoop = async (controller, reader) => {
952
- const consumeNextHeadChunk = async (injected, pending) => {
953
- const consumed = await consumeHeadChunk(controller, reader, pending, injected);
954
- const nextState = updateInjectedState(consumed, injected, pending);
955
- if (nextState.done) {
956
- return { injected, pending };
957
- }
958
- return consumeNextHeadChunk(nextState.injected, nextState.pending);
959
- };
960
- return consumeNextHeadChunk(false, "");
961
- };
962
- return new ReadableStream({
963
- async start(controller) {
964
- const reader = stream.getReader();
965
- try {
966
- const { injected, pending } = await runHeadInjectionLoop(controller, reader);
967
- finishHeadInjectionStream(controller, pending, injected);
968
- } catch (error) {
969
- controller.error(error);
970
- }
971
- }
972
- });
973
- }, pipeStreamWithIslandMarkerDetection = (stream, markup) => {
974
- const encoder = new TextEncoder;
975
- const decoder = new TextDecoder;
976
- const lookbehind = Math.max(ISLAND_MARKER.length, BYTES_PER_KILOBYTE);
977
- const processPending = (controller, pending, injected) => {
978
- if (injected) {
979
- controller.enqueue(encoder.encode(pending));
980
- return { injected, pending: "" };
981
- }
982
- const markerIndex = pending.indexOf(ISLAND_MARKER);
983
- if (markerIndex >= 0) {
984
- const tagStart = pending.lastIndexOf("<", markerIndex);
985
- const injectAt = tagStart >= 0 ? tagStart : markerIndex;
986
- const next = `${pending.slice(0, injectAt)}${markup}${pending.slice(injectAt)}`;
987
- controller.enqueue(encoder.encode(next));
988
- return { injected: true, pending: "" };
989
- }
990
- return {
991
- injected,
992
- pending: flushSafePendingText(controller, encoder, pending, lookbehind)
993
- };
994
- };
995
- const finishIslandMarkerStream = (controller, pending) => {
996
- const finalPending = pending + decoder.decode();
997
- if (finalPending.length > 0) {
998
- controller.enqueue(encoder.encode(finalPending));
999
- }
1000
- controller.close();
1001
- };
1002
- const consumeIslandChunk = async (controller, reader, pending, injected) => {
1003
- const { done, value } = await readStreamChunk(reader);
1004
- if (done || !value) {
1005
- return { done, injected, pending };
1006
- }
1007
- const processed = processPending(controller, pending + streamChunkToString(value, decoder), injected);
1008
- return {
1009
- done,
1010
- injected: processed.injected,
1011
- pending: processed.pending
1012
- };
1013
- };
1014
- const runIslandMarkerLoop = async (controller, reader) => {
1015
- const consumeNextIslandChunk = async (injected, pending) => {
1016
- const consumed = await consumeIslandChunk(controller, reader, pending, injected);
1017
- const nextState = updateInjectedState(consumed, injected, pending);
1018
- if (nextState.done) {
1019
- return { injected, pending };
1020
- }
1021
- return consumeNextIslandChunk(nextState.injected, nextState.pending);
1022
- };
1023
- return consumeNextIslandChunk(false, "");
1024
- };
1025
- return new ReadableStream({
1026
- async start(controller) {
1027
- const reader = stream.getReader();
1028
- try {
1029
- const { pending } = await runIslandMarkerLoop(controller, reader);
1030
- finishIslandMarkerStream(controller, pending);
1031
- } catch (error) {
1032
- controller.error(error);
1033
- }
1034
- }
1035
- });
1036
- }, htmlContainsIslands = (html) => html.includes(ISLAND_MARKER), injectIslandPageContext = (html, options) => {
1037
- const manifest = globalThis.__absoluteManifest;
1038
- const hasIslands = options?.hasIslands ?? htmlContainsIslands(html);
1039
- if (!manifest || !hasIslands) {
1040
- return html;
1041
- }
1042
- if (html.includes(MANIFEST_MARKER) || html.includes(ISLAND_STATE_MARKER)) {
1043
- return html;
1044
- }
1045
- return injectHeadMarkup(html, buildIslandsHeadMarkup(manifest));
1046
- }, injectIslandPageContextStream = (stream, options) => {
1047
- const manifest = globalThis.__absoluteManifest;
1048
- if (!manifest)
1049
- return stream;
1050
- const markup = buildIslandsHeadMarkup(manifest);
1051
- if (options?.hasIslands === true) {
1052
- return pipeStreamWithHeadInjection(stream, markup);
1053
- }
1054
- if (options?.hasIslands === false) {
1055
- return stream;
1056
- }
1057
- return pipeStreamWithIslandMarkerDetection(stream, markup);
1058
- }, setCurrentIslandManifest = (manifest) => {
1059
- globalThis.__absoluteManifest = manifest;
1060
- };
1061
- var init_islandPageContext = __esm(() => {
1062
- init_constants();
1063
- });
1064
-
1065
- // src/core/devRouteRegistrationCallsite.ts
1066
- var exports_devRouteRegistrationCallsite = {};
1067
- __export(exports_devRouteRegistrationCallsite, {
1068
- patchElysiaRouteRegistrationCallsites: () => patchElysiaRouteRegistrationCallsites,
1069
- getCurrentRouteRegistrationCallsite: () => getCurrentRouteRegistrationCallsite
1070
- });
1071
- import { AsyncLocalStorage } from "async_hooks";
1072
- import { Elysia } from "elysia";
1073
- var ROUTE_CALLSITE_STORAGE_KEY, ROUTE_CALLSITE_PATCHED_KEY, ROUTE_METHOD_NAMES, isObjectRecord3 = (value) => Boolean(value) && typeof value === "object", isAsyncLocalStorage2 = (value) => isObjectRecord3(value) && ("getStore" in value) && typeof value.getStore === "function" && ("run" in value) && typeof value.run === "function", getRouteCallsiteStorage = () => {
1074
- const value = Reflect.get(globalThis, ROUTE_CALLSITE_STORAGE_KEY);
1075
- if (value === null || typeof value === "undefined") {
1076
- return;
1077
- }
1078
- return isAsyncLocalStorage2(value) ? value : undefined;
1079
- }, ensureRouteCallsiteStorage = () => {
1080
- const existing = getRouteCallsiteStorage();
1081
- if (existing) {
1082
- return existing;
1083
- }
1084
- const storage = new AsyncLocalStorage;
1085
- Reflect.set(globalThis, ROUTE_CALLSITE_STORAGE_KEY, storage);
1086
- return storage;
1087
- }, normalizeCallsitePath = (value) => value.replace(`${process.cwd()}/`, "").replace(process.cwd(), "").replace(/^\.\/+/, ""), extractRouteRegistrationCallsite = (stack) => {
1088
- const frames = stack.split(`
1089
- `).slice(1).map((line) => line.trim());
1090
- for (const frame of frames) {
1091
- if (frame.includes("/node_modules/") || frame.includes("/dist/") || frame.includes("/src/core/devRouteRegistrationCallsite.")) {
1092
- continue;
1093
- }
1094
- const locationMatch = frame.match(/\((\/[^)]+:\d+:\d+)\)$/) ?? frame.match(/at (\/[^ ]+:\d+:\d+)$/);
1095
- if (locationMatch?.[1]) {
1096
- return normalizeCallsitePath(locationMatch[1]);
1097
- }
1098
- }
1099
- return;
1100
- }, captureRouteRegistrationCallsite = () => {
1101
- const { stack } = new Error;
1102
- if (!stack) {
1103
- return;
1104
- }
1105
- return extractRouteRegistrationCallsite(stack);
1106
- }, wrapRouteHandlerWithCallsite = (handler, callsite) => {
1107
- if (typeof handler !== "function" || !callsite) {
1108
- return handler;
1109
- }
1110
- const storage = ensureRouteCallsiteStorage();
1111
- return function wrappedRouteHandler(...args) {
1112
- return storage.run({ callsite }, () => Reflect.apply(handler, this, args));
1113
- };
1114
- }, getCurrentRouteRegistrationCallsite = () => getRouteCallsiteStorage()?.getStore()?.callsite, patchElysiaRouteRegistrationCallsites = () => {
1115
- if (false) {}
1116
- if (Reflect.get(globalThis, ROUTE_CALLSITE_PATCHED_KEY) === true) {
1117
- return;
1118
- }
1119
- const prototype = Elysia.prototype;
1120
- for (const methodName of ROUTE_METHOD_NAMES) {
1121
- const originalMethod = prototype[methodName];
1122
- if (typeof originalMethod !== "function") {
1123
- continue;
1124
- }
1125
- prototype[methodName] = function patchedRouteMethod(path, handler, ...rest) {
1126
- const callsite = captureRouteRegistrationCallsite();
1127
- return Reflect.apply(originalMethod, this, [
1128
- path,
1129
- wrapRouteHandlerWithCallsite(handler, callsite),
1130
- ...rest
1131
- ]);
1132
- };
1133
- }
1134
- Reflect.set(globalThis, ROUTE_CALLSITE_PATCHED_KEY, true);
1135
- };
1136
- var init_devRouteRegistrationCallsite = __esm(() => {
1137
- ROUTE_CALLSITE_STORAGE_KEY = Symbol.for("absolutejs.devRouteRegistrationCallsiteStorage");
1138
- ROUTE_CALLSITE_PATCHED_KEY = Symbol.for("absolutejs.devRouteRegistrationCallsitePatched");
1139
- ROUTE_METHOD_NAMES = [
1140
- "all",
1141
- "delete",
1142
- "get",
1143
- "head",
1144
- "options",
1145
- "patch",
1146
- "post",
1147
- "put"
1148
- ];
1149
- });
1150
-
1151
- // src/client/streamSwap.ts
1152
- var streamSwapRuntime = () => {
1153
- const SLOT_PATCH_EVENT = "absolutejs:slot-patch";
1154
- if (window.__ABS_SLOT_RUNTIME__ === true)
1155
- return;
1156
- window.__ABS_SLOT_RUNTIME__ = true;
1157
- window.__ABS_SLOT_CONSUMERS__ = window.__ABS_SLOT_CONSUMERS__ ?? {};
1158
- window.__ABS_SLOT_PENDING__ = window.__ABS_SLOT_PENDING__ ?? {};
1159
- const consumers = window.__ABS_SLOT_CONSUMERS__;
1160
- const pending = window.__ABS_SLOT_PENDING__;
1161
- const isObjectRecord4 = (value) => Boolean(value) && typeof value === "object";
1162
- const isPatchedPendingEntry = (value) => {
1163
- if (!isObjectRecord4(value))
1164
- return false;
1165
- return value.domPatched === true && "payload" in value;
966
+ }
967
+ Reflect.set(globalThis, ROUTE_CALLSITE_PATCHED_KEY, true);
968
+ };
969
+ var init_devRouteRegistrationCallsite = __esm(() => {
970
+ ROUTE_CALLSITE_STORAGE_KEY = Symbol.for("absolutejs.devRouteRegistrationCallsiteStorage");
971
+ ROUTE_CALLSITE_PATCHED_KEY = Symbol.for("absolutejs.devRouteRegistrationCallsitePatched");
972
+ ROUTE_METHOD_NAMES = [
973
+ "all",
974
+ "delete",
975
+ "get",
976
+ "head",
977
+ "options",
978
+ "patch",
979
+ "post",
980
+ "put"
981
+ ];
982
+ });
983
+
984
+ // src/client/streamSwap.ts
985
+ var streamSwapRuntime = () => {
986
+ const SLOT_PATCH_EVENT = "absolutejs:slot-patch";
987
+ if (window.__ABS_SLOT_RUNTIME__ === true)
988
+ return;
989
+ window.__ABS_SLOT_RUNTIME__ = true;
990
+ window.__ABS_SLOT_CONSUMERS__ = window.__ABS_SLOT_CONSUMERS__ ?? {};
991
+ window.__ABS_SLOT_PENDING__ = window.__ABS_SLOT_PENDING__ ?? {};
992
+ const consumers = window.__ABS_SLOT_CONSUMERS__;
993
+ const pending = window.__ABS_SLOT_PENDING__;
994
+ const isObjectRecord4 = (value) => Boolean(value) && typeof value === "object";
995
+ const isPatchedPendingEntry = (value) => {
996
+ if (!isObjectRecord4(value))
997
+ return false;
998
+ return value.domPatched === true && "payload" in value;
1166
999
  };
1167
1000
  const unwrapPendingPayload = (value) => isPatchedPendingEntry(value) ? value.payload : value;
1168
1001
  const canApplyImmediately = () => window.__ABS_SLOT_HYDRATION_PENDING__ !== true;
@@ -1824,62 +1657,15 @@ var init_streamingSlots = __esm(() => {
1824
1657
  };
1825
1658
  });
1826
1659
 
1827
- // src/core/responseEnhancers.ts
1828
- var toResponse = async (responseLike) => responseLike, cloneHeaders = (response) => {
1829
- const headers = new Headers(response.headers);
1830
- return headers;
1831
- }, enhanceHtmlResponseWithStreamingSlots = (response, {
1832
- nonce,
1833
- onError,
1834
- runtimePlacement,
1835
- runtimePreludeScript,
1836
- streamingSlots = [],
1837
- policy
1838
- } = {}) => {
1839
- if (!response.body || streamingSlots.length === 0) {
1840
- return response;
1841
- }
1842
- const body = appendStreamingSlotPatchesToStream(response.body, streamingSlots, {
1843
- nonce,
1844
- onError,
1845
- policy,
1846
- runtimePlacement,
1847
- runtimePreludeScript
1848
- });
1849
- return new Response(body, {
1850
- headers: cloneHeaders(response),
1851
- status: response.status,
1852
- statusText: response.statusText
1853
- });
1854
- }, withStreamingSlots = async (responseLike, options = {}) => enhanceHtmlResponseWithStreamingSlots(await toResponse(responseLike), options), mergeStreamingSlots = (registered, explicit) => {
1855
- const merged = new Map;
1856
- for (const slot of registered)
1857
- merged.set(slot.id, slot);
1858
- for (const slot of explicit)
1859
- merged.set(slot.id, slot);
1860
- return [...merged.values()];
1861
- }, withRegisteredStreamingSlots = async (renderResponse, options = {}) => {
1862
- const { result, slots } = await runWithStreamingSlotRegistry(renderResponse);
1863
- const explicit = options.streamingSlots ?? [];
1864
- return withStreamingSlots(result, {
1865
- ...options,
1866
- streamingSlots: mergeStreamingSlots(slots, explicit)
1867
- });
1868
- };
1869
- var init_responseEnhancers = __esm(() => {
1870
- init_streamingSlots();
1871
- init_streamingSlotRegistry();
1872
- });
1873
-
1874
- // src/utils/getDurationString.ts
1875
- var getDurationString = (duration) => {
1876
- let durationString;
1877
- if (duration < MILLISECONDS_IN_A_SECOND) {
1878
- durationString = `${duration.toFixed(TIME_PRECISION)}ms`;
1879
- } else if (duration < MILLISECONDS_IN_A_MINUTE) {
1880
- durationString = `${(duration / MILLISECONDS_IN_A_SECOND).toFixed(TIME_PRECISION)}s`;
1881
- } else {
1882
- durationString = `${(duration / MILLISECONDS_IN_A_MINUTE).toFixed(TIME_PRECISION)}m`;
1660
+ // src/utils/getDurationString.ts
1661
+ var getDurationString = (duration) => {
1662
+ let durationString;
1663
+ if (duration < MILLISECONDS_IN_A_SECOND) {
1664
+ durationString = `${duration.toFixed(TIME_PRECISION)}ms`;
1665
+ } else if (duration < MILLISECONDS_IN_A_MINUTE) {
1666
+ durationString = `${(duration / MILLISECONDS_IN_A_SECOND).toFixed(TIME_PRECISION)}s`;
1667
+ } else {
1668
+ durationString = `${(duration / MILLISECONDS_IN_A_MINUTE).toFixed(TIME_PRECISION)}m`;
1883
1669
  }
1884
1670
  return durationString;
1885
1671
  };
@@ -2013,117 +1799,14 @@ var init_logger = __esm(() => {
2013
1799
  };
2014
1800
  });
2015
1801
 
2016
- // src/core/streamingSlotWarningScope.ts
2017
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
2018
- var STREAMING_SLOT_WARNING_STORAGE_KEY2, isObjectRecord4 = (value) => Boolean(value) && typeof value === "object", isAsyncLocalStorage3 = (value) => isObjectRecord4(value) && ("getStore" in value) && typeof value.getStore === "function" && ("run" in value) && typeof value.run === "function", getWarningStorage = () => {
2019
- const value = Reflect.get(globalThis, STREAMING_SLOT_WARNING_STORAGE_KEY2);
2020
- if (value === null || typeof value === "undefined") {
2021
- return;
2022
- }
2023
- return isAsyncLocalStorage3(value) ? value : undefined;
2024
- }, ensureWarningStorage = () => {
2025
- const existing = getWarningStorage();
2026
- if (existing) {
2027
- return existing;
2028
- }
2029
- const storage = new AsyncLocalStorage2;
2030
- Reflect.set(globalThis, STREAMING_SLOT_WARNING_STORAGE_KEY2, storage);
2031
- return storage;
2032
- }, normalizeCallsitePath2 = (value) => value.replace(`${process.cwd()}/`, "").replace(process.cwd(), "").replace(/^\.\/+/, ""), formatWarningCallsite = (callsite) => {
2033
- const match = callsite.match(/^(.*?)(:\d+:\d+)$/);
2034
- if (!match) {
2035
- return `\x1B[36m${callsite}\x1B[0m`;
2036
- }
2037
- return `\x1B[36m${match[1]}\x1B[33m${match[2]}\x1B[0m`;
2038
- }, extractCallsiteFromStack = (stack) => {
2039
- const frames = stack.split(`
2040
- `).slice(1).map((line) => line.trim());
2041
- for (const frame of frames) {
2042
- if (frame.includes("/node_modules/") || frame.includes("/dist/") || frame.includes("/src/react/pageHandler.") || frame.includes("/src/vue/pageHandler.") || frame.includes("/src/svelte/pageHandler.") || frame.includes("/src/angular/pageHandler.") || frame.includes("/src/core/streamingSlotWarningScope.")) {
2043
- continue;
2044
- }
2045
- const locationMatch = frame.match(/\((\/[^)]+:\d+:\d+)\)$/) ?? frame.match(/at (\/[^ ]+:\d+:\d+)$/);
2046
- if (locationMatch?.[1]) {
2047
- return normalizeCallsitePath2(locationMatch[1]);
2048
- }
2049
- }
2050
- return;
2051
- }, buildMissingCollectorWarning = (primitiveName, handlerCallsite) => `${primitiveName} rendered during SSR without streaming slot collection enabled. Add { collectStreamingSlots: true } to this page handler to enable out-of-order streaming for this route.${handlerCallsite ? ` Update ${formatWarningCallsite(handlerCallsite)}.` : ""}`, captureStreamingSlotWarningCallsite = () => {
2052
- if (false) {}
2053
- const { stack } = new Error;
2054
- if (!stack) {
2055
- return;
2056
- }
2057
- return extractCallsiteFromStack(stack);
2058
- }, runWithStreamingSlotWarningScope = (task, metadata) => ensureWarningStorage().run({ handlerCallsite: metadata?.handlerCallsite, hasWarned: false }, task);
2059
- var init_streamingSlotWarningScope = __esm(() => {
2060
- init_logger();
2061
- init_streamingSlotRegistrar();
2062
- STREAMING_SLOT_WARNING_STORAGE_KEY2 = Symbol.for("absolutejs.streamingSlotWarningAsyncLocalStorage");
2063
- setStreamingSlotWarningController({
2064
- maybeWarn: (primitiveName) => {
2065
- const store = getWarningStorage()?.getStore();
2066
- if (!store || store.hasWarned) {
2067
- return;
2068
- }
2069
- store.hasWarned = true;
2070
- logWarn(buildMissingCollectorWarning(primitiveName, store.handlerCallsite));
2071
- }
2072
- });
1802
+ // src/core/ssrCache.ts
1803
+ var dirtyFrameworks, markSsrCacheDirty = (framework) => {
1804
+ dirtyFrameworks.add(framework);
1805
+ }, isSsrCacheDirty = (framework) => dirtyFrameworks.has(framework);
1806
+ var init_ssrCache = __esm(() => {
1807
+ dirtyFrameworks = new Set;
2073
1808
  });
2074
1809
 
2075
- // src/utils/ssrErrorPage.ts
2076
- var ssrErrorPage = (framework, error) => {
2077
- const frameworkColors2 = {
2078
- angular: "#dd0031",
2079
- html: "#e34c26",
2080
- htmx: "#1a365d",
2081
- react: "#61dafb",
2082
- svelte: "#ff3e00",
2083
- vue: "#42b883"
2084
- };
2085
- const accent = frameworkColors2[framework] ?? "#94a3b8";
2086
- const label = framework.charAt(0).toUpperCase() + framework.slice(1);
2087
- const message = error instanceof Error ? error.message : String(error);
2088
- return `<!DOCTYPE html>
2089
- <html>
2090
- <head>
2091
- <meta charset="utf-8">
2092
- <meta name="viewport" content="width=device-width, initial-scale=1">
2093
- <title>SSR Error - AbsoluteJS</title>
2094
- <style>
2095
- *{margin:0;padding:0;box-sizing:border-box}
2096
- body{min-height:100vh;background:linear-gradient(135deg,rgba(15,23,42,0.98) 0%,rgba(30,41,59,0.98) 100%);color:#e2e8f0;font-family:"JetBrains Mono","Fira Code",ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;font-size:14px;line-height:1.6;display:flex;align-items:flex-start;justify-content:center;padding:32px}
2097
- .card{max-width:720px;width:100%;background:rgba(30,41,59,0.6);border:1px solid rgba(71,85,105,0.5);border-radius:16px;box-shadow:0 25px 50px -12px rgba(0,0,0,0.5),0 0 0 1px rgba(255,255,255,0.05);overflow:hidden}
2098
- .header{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:20px 24px;background:rgba(15,23,42,0.5);border-bottom:1px solid rgba(71,85,105,0.4)}
2099
- .brand{font-weight:700;font-size:20px;color:#fff;letter-spacing:-0.02em}
2100
- .badge{padding:5px 10px;border-radius:8px;font-size:12px;font-weight:600;background:${accent};color:#fff;opacity:0.95;box-shadow:0 2px 4px rgba(0,0,0,0.2)}
2101
- .kind{color:#94a3b8;font-size:13px;font-weight:500}
2102
- .content{padding:24px}
2103
- .label{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:0.08em;color:#94a3b8;margin-bottom:8px}
2104
- .message{margin:0;padding:16px 20px;background:rgba(239,68,68,0.12);border:1px solid rgba(239,68,68,0.25);border-radius:10px;overflow-x:auto;white-space:pre-wrap;word-break:break-word;color:#fca5a5;font-size:13px;line-height:1.5}
2105
- .hint{margin-top:20px;padding:12px 20px;background:rgba(71,85,105,0.3);border-radius:10px;border:1px solid rgba(71,85,105,0.4);color:#cbd5e1;font-size:13px}
2106
- </style>
2107
- </head>
2108
- <body>
2109
- <div class="card">
2110
- <div class="header">
2111
- <div style="display:flex;align-items:center;gap:12px">
2112
- <span class="brand">AbsoluteJS</span>
2113
- <span class="badge">${label}</span>
2114
- </div>
2115
- <span class="kind">Server Render Error</span>
2116
- </div>
2117
- <div class="content">
2118
- <div class="label">What went wrong</div>
2119
- <pre class="message">${message.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")}</pre>
2120
- <div class="hint">A component threw during server-side rendering. Check the terminal for the full stack trace.</div>
2121
- </div>
2122
- </div>
2123
- </body>
2124
- </html>`;
2125
- };
2126
-
2127
1810
  // src/utils/stringModifiers.ts
2128
1811
  var normalizeSlug = (str) => str.trim().replace(/\s+/g, "-").replace(/[^A-Za-z0-9\-_]+/g, "").replace(/[-_]{2,}/g, "-"), toKebab = (str) => normalizeSlug(str).replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), toPascal = (str) => {
2129
1812
  if (!str.includes("-") && !str.includes("_")) {
@@ -2132,246 +1815,54 @@ var normalizeSlug = (str) => str.trim().replace(/\s+/g, "-").replace(/[^A-Za-z0-
2132
1815
  return normalizeSlug(str).split(/[-_]/).filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1).toLowerCase()).join("");
2133
1816
  }, toScreamingSnake = (str) => str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toUpperCase();
2134
1817
 
2135
- // src/utils/resolveConvention.ts
2136
- import { basename as basename2 } from "path";
2137
- var CONVENTIONS_KEY = "__absoluteConventions", isConventionsMap = (value) => Boolean(value) && typeof value === "object", getMap = () => {
2138
- const value = Reflect.get(globalThis, CONVENTIONS_KEY);
2139
- if (isConventionsMap(value))
2140
- return value;
2141
- const empty = {};
2142
- return empty;
2143
- }, derivePageName = (pagePath) => {
2144
- const base = basename2(pagePath);
2145
- const dotIndex = base.indexOf(".");
2146
- const name = dotIndex > 0 ? base.slice(0, dotIndex) : base;
2147
- return toPascal(name);
2148
- }, resolveErrorConventionPath = (framework, pageName) => {
2149
- const conventions = getMap()[framework];
2150
- if (!conventions)
2151
- return;
2152
- return conventions.pages?.[pageName]?.error ?? conventions.defaults?.error;
2153
- }, resolveNotFoundConventionPath = (framework) => getMap()[framework]?.defaults?.notFound, setConventions = (map) => {
2154
- Reflect.set(globalThis, CONVENTIONS_KEY, map);
2155
- }, isDev = () => true, buildErrorProps = (error) => {
2156
- const message = error instanceof Error ? error.message : String(error);
2157
- const stack = isDev() && error instanceof Error ? error.stack : undefined;
2158
- return { error: { message, stack } };
2159
- }, renderReactError = async (conventionPath, errorProps) => {
2160
- const { createElement } = await import("react");
2161
- const { renderToReadableStream } = await import("react-dom/server");
2162
- const mod = await import(conventionPath);
2163
- const [firstKey] = Object.keys(mod);
2164
- const ErrorComponent = mod.default ?? (firstKey ? mod[firstKey] : undefined);
2165
- const element = createElement(ErrorComponent, errorProps);
2166
- const stream = await renderToReadableStream(element);
2167
- return new Response(stream, {
2168
- headers: { "Content-Type": "text/html" },
2169
- status: 500
2170
- });
2171
- }, renderSvelteError = async (conventionPath, errorProps) => {
2172
- const { render } = await import("svelte/server");
2173
- const mod = await import(conventionPath);
2174
- const ErrorComponent = mod.default;
2175
- const { head, body } = render(ErrorComponent, {
2176
- props: errorProps
2177
- });
2178
- const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
2179
- return new Response(html, {
2180
- headers: { "Content-Type": "text/html" },
2181
- status: 500
2182
- });
2183
- }, unescapeVueStyles = (ssrBody) => {
2184
- let styles = "";
2185
- const body = ssrBody.replace(/<style>([\s\S]*?)<\/style>/g, (_, css) => {
2186
- styles += `<style>${css.replace(/&quot;/g, '"').replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">")}</style>`;
2187
- return "";
2188
- });
2189
- return { body, styles };
2190
- }, renderVueError = async (conventionPath, errorProps) => {
2191
- const { createSSRApp, h } = await import("vue");
2192
- const { renderToString } = await import("vue/server-renderer");
2193
- const mod = await import(conventionPath);
2194
- const ErrorComponent = mod.default;
2195
- const app = createSSRApp({
2196
- render: () => h(ErrorComponent, errorProps)
2197
- });
2198
- const rawBody = await renderToString(app);
2199
- const { styles, body } = unescapeVueStyles(rawBody);
2200
- const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
2201
- return new Response(html, {
2202
- headers: { "Content-Type": "text/html" },
2203
- status: 500
2204
- });
2205
- }, renderAngularError = async (conventionPath, errorProps) => {
2206
- const mod = await import(conventionPath);
2207
- const renderError = mod.default ?? mod.renderError;
2208
- if (typeof renderError !== "function")
2209
- return null;
2210
- const html = renderError(errorProps);
2211
- return new Response(html, {
2212
- headers: { "Content-Type": "text/html" },
2213
- status: 500
2214
- });
2215
- }, logConventionRenderError = (framework, label, renderError) => {
2216
- const message = renderError instanceof Error ? renderError.message : "";
2217
- if (message.includes("Cannot find module") || message.includes("Cannot find package") || message.includes("not found in module")) {
2218
- 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}).`);
2219
- return;
2220
- }
2221
- console.error(`[SSR] Failed to render ${framework} convention ${label} page:`, renderError);
2222
- }, ERROR_RENDERERS, renderConventionError = async (framework, pageName, error) => {
2223
- const conventionPath = resolveErrorConventionPath(framework, pageName);
2224
- if (!conventionPath)
2225
- return null;
2226
- const errorProps = buildErrorProps(error);
2227
- const renderer = ERROR_RENDERERS[framework];
2228
- if (!renderer)
2229
- return null;
1818
+ // src/svelte/renderToReadableStream.ts
1819
+ var exports_renderToReadableStream = {};
1820
+ __export(exports_renderToReadableStream, {
1821
+ renderToReadableStream: () => renderToReadableStream,
1822
+ SVELTE_PAGE_ROOT_ID: () => SVELTE_PAGE_ROOT_ID
1823
+ });
1824
+ var SVELTE_PAGE_ROOT_ID = "__absolute_svelte_root__", renderToReadableStream = async (component, props, {
1825
+ bootstrapScriptContent,
1826
+ bootstrapScripts = [],
1827
+ bootstrapModules = [],
1828
+ nonce,
1829
+ onError = console.error,
1830
+ progressiveChunkSize = DEFAULT_CHUNK_SIZE,
1831
+ signal,
1832
+ headContent,
1833
+ bodyContent
1834
+ } = {}) => {
2230
1835
  try {
2231
- return await renderer(conventionPath, errorProps);
2232
- } catch (renderError) {
2233
- logConventionRenderError(framework, "error", renderError);
2234
- }
2235
- return null;
2236
- }, renderReactNotFound = async (conventionPath) => {
2237
- const { createElement } = await import("react");
2238
- const { renderToReadableStream } = await import("react-dom/server");
2239
- const mod = await import(conventionPath);
2240
- const [nfKey] = Object.keys(mod);
2241
- const NotFoundComponent = mod.default ?? (nfKey ? mod[nfKey] : undefined);
2242
- const element = createElement(NotFoundComponent);
2243
- const stream = await renderToReadableStream(element);
2244
- return new Response(stream, {
2245
- headers: { "Content-Type": "text/html" },
2246
- status: 404
2247
- });
2248
- }, renderSvelteNotFound = async (conventionPath) => {
2249
- const { render } = await import("svelte/server");
2250
- const mod = await import(conventionPath);
2251
- const NotFoundComponent = mod.default;
2252
- const { head, body } = render(NotFoundComponent);
2253
- const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
2254
- return new Response(html, {
2255
- headers: { "Content-Type": "text/html" },
2256
- status: 404
2257
- });
2258
- }, renderVueNotFound = async (conventionPath) => {
2259
- const { createSSRApp, h } = await import("vue");
2260
- const { renderToString } = await import("vue/server-renderer");
2261
- const mod = await import(conventionPath);
2262
- const NotFoundComponent = mod.default;
2263
- const app = createSSRApp({
2264
- render: () => h(NotFoundComponent)
2265
- });
2266
- const rawBody = await renderToString(app);
2267
- const { styles, body } = unescapeVueStyles(rawBody);
2268
- const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
2269
- return new Response(html, {
2270
- headers: { "Content-Type": "text/html" },
2271
- status: 404
2272
- });
2273
- }, renderAngularNotFound = async (conventionPath) => {
2274
- const mod = await import(conventionPath);
2275
- const renderNotFound = mod.default ?? mod.renderNotFound;
2276
- if (typeof renderNotFound !== "function")
2277
- return null;
2278
- const html = renderNotFound();
2279
- return new Response(html, {
2280
- headers: { "Content-Type": "text/html" },
2281
- status: 404
2282
- });
2283
- }, NOT_FOUND_RENDERERS, renderConventionNotFound = async (framework) => {
2284
- const conventionPath = resolveNotFoundConventionPath(framework);
2285
- if (!conventionPath)
2286
- return null;
2287
- const renderer = NOT_FOUND_RENDERERS[framework];
2288
- if (!renderer)
2289
- return null;
2290
- try {
2291
- return await renderer(conventionPath);
2292
- } catch (renderError) {
2293
- logConventionRenderError(framework, "not-found", renderError);
2294
- }
2295
- return null;
2296
- }, NOT_FOUND_PRIORITY, renderFirstNotFound = async () => {
2297
- for (const framework of NOT_FOUND_PRIORITY) {
2298
- if (!getMap()[framework]?.defaults?.notFound)
2299
- continue;
2300
- const response = await renderConventionNotFound(framework);
2301
- if (response)
2302
- return response;
2303
- }
2304
- return null;
2305
- };
2306
- var init_resolveConvention = __esm(() => {
2307
- ERROR_RENDERERS = {
2308
- angular: renderAngularError,
2309
- react: renderReactError,
2310
- svelte: renderSvelteError,
2311
- vue: renderVueError
2312
- };
2313
- NOT_FOUND_RENDERERS = {
2314
- angular: renderAngularNotFound,
2315
- react: renderReactNotFound,
2316
- svelte: renderSvelteNotFound,
2317
- vue: renderVueNotFound
2318
- };
2319
- NOT_FOUND_PRIORITY = [
2320
- "react",
2321
- "svelte",
2322
- "vue",
2323
- "angular"
2324
- ];
2325
- });
2326
-
2327
- // src/svelte/renderToReadableStream.ts
2328
- var exports_renderToReadableStream = {};
2329
- __export(exports_renderToReadableStream, {
2330
- renderToReadableStream: () => renderToReadableStream,
2331
- SVELTE_PAGE_ROOT_ID: () => SVELTE_PAGE_ROOT_ID
2332
- });
2333
- var SVELTE_PAGE_ROOT_ID = "__absolute_svelte_root__", renderToReadableStream = async (component, props, {
2334
- bootstrapScriptContent,
2335
- bootstrapScripts = [],
2336
- bootstrapModules = [],
2337
- nonce,
2338
- onError = console.error,
2339
- progressiveChunkSize = DEFAULT_CHUNK_SIZE,
2340
- signal,
2341
- headContent,
2342
- bodyContent
2343
- } = {}) => {
2344
- try {
2345
- const { render } = await import("svelte/server");
2346
- const rendered = typeof props === "undefined" ? await render(component) : await render(component, { props });
2347
- const { head, body } = rendered;
2348
- const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
2349
- const scripts = (bootstrapScriptContent ? `<script${nonceAttr}>${escapeScriptContent(bootstrapScriptContent)}</script>` : "") + bootstrapScripts.map((src) => `<script${nonceAttr} src="${src}"></script>`).join("") + bootstrapModules.map((src) => `<script${nonceAttr} type="module" src="${src}"></script>`).join("");
2350
- const encoder = new TextEncoder;
2351
- const full = encoder.encode(`<!DOCTYPE html><html lang="en"><head>${head}${headContent ?? ""}</head><body><div id="${SVELTE_PAGE_ROOT_ID}">${body}</div>${scripts}${bodyContent ?? ""}</body></html>`);
2352
- let offset = 0;
2353
- return new ReadableStream({
2354
- type: "bytes",
2355
- cancel(reason) {
2356
- onError?.(reason);
2357
- },
2358
- pull(controller) {
2359
- if (signal?.aborted) {
2360
- controller.close();
2361
- return;
2362
- }
2363
- if (offset >= full.length) {
2364
- controller.close();
2365
- return;
2366
- }
2367
- const end = Math.min(offset + progressiveChunkSize, full.length);
2368
- controller.enqueue(full.subarray(offset, end));
2369
- offset = end;
2370
- }
2371
- });
2372
- } catch (error) {
2373
- onError?.(error);
2374
- throw error;
1836
+ const { render } = await import("svelte/server");
1837
+ const rendered = typeof props === "undefined" ? await render(component) : await render(component, { props });
1838
+ const { head, body } = rendered;
1839
+ const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
1840
+ const scripts = (bootstrapScriptContent ? `<script${nonceAttr}>${escapeScriptContent(bootstrapScriptContent)}</script>` : "") + bootstrapScripts.map((src) => `<script${nonceAttr} src="${src}"></script>`).join("") + bootstrapModules.map((src) => `<script${nonceAttr} type="module" src="${src}"></script>`).join("");
1841
+ const encoder = new TextEncoder;
1842
+ const full = encoder.encode(`<!DOCTYPE html><html lang="en"><head>${head}${headContent ?? ""}</head><body><div id="${SVELTE_PAGE_ROOT_ID}">${body}</div>${scripts}${bodyContent ?? ""}</body></html>`);
1843
+ let offset = 0;
1844
+ return new ReadableStream({
1845
+ type: "bytes",
1846
+ cancel(reason) {
1847
+ onError?.(reason);
1848
+ },
1849
+ pull(controller) {
1850
+ if (signal?.aborted) {
1851
+ controller.close();
1852
+ return;
1853
+ }
1854
+ if (offset >= full.length) {
1855
+ controller.close();
1856
+ return;
1857
+ }
1858
+ const end = Math.min(offset + progressiveChunkSize, full.length);
1859
+ controller.enqueue(full.subarray(offset, end));
1860
+ offset = end;
1861
+ }
1862
+ });
1863
+ } catch (error) {
1864
+ onError?.(error);
1865
+ throw error;
2375
1866
  }
2376
1867
  };
2377
1868
  var init_renderToReadableStream = __esm(() => {
@@ -2379,122 +1870,6 @@ var init_renderToReadableStream = __esm(() => {
2379
1870
  init_escapeScriptContent();
2380
1871
  });
2381
1872
 
2382
- // src/svelte/pageHandler.ts
2383
- var ssrDirty = false, isRecord2 = (value) => typeof value === "object" && value !== null, isGenericSvelteComponent = (value) => typeof value === "function" || isRecord2(value), readHasIslands = (value) => {
2384
- if (!isRecord2(value))
2385
- return false;
2386
- const hasIslands = value["__ABSOLUTE_PAGE_HAS_ISLANDS__"];
2387
- return typeof hasIslands === "boolean" ? hasIslands : false;
2388
- }, readDefaultExport = (value) => isRecord2(value) ? value.default : undefined, buildDirtyResponse = (indexPath, props) => {
2389
- const propsScript = `window.__ABS_SLOT_HYDRATION_PENDING__=true;window.__INITIAL_PROPS__=${JSON.stringify(props)};${indexPath ? `import(${JSON.stringify(indexPath)});` : ""}`;
2390
- const dirtyFlag = "window.__SSR_DIRTY__=true;";
2391
- const html = `<!DOCTYPE html><html><head></head><body><script>${propsScript}${dirtyFlag}</script></body></html>`;
2392
- return new Response(html, {
2393
- headers: { "Content-Type": "text/html" }
2394
- });
2395
- }, handleSveltePageRequest = async (PageComponentOrInput, pagePath, indexPath, props, options) => {
2396
- const {
2397
- PageComponent,
2398
- indexPath: resolvedIndexPath,
2399
- options: resolvedOptions,
2400
- pagePath: resolvedPagePath,
2401
- props: resolvedProps
2402
- } = typeof PageComponentOrInput === "object" && PageComponentOrInput !== null && "pagePath" in PageComponentOrInput && "indexPath" in PageComponentOrInput ? {
2403
- PageComponent: undefined,
2404
- indexPath: PageComponentOrInput.indexPath,
2405
- options: PageComponentOrInput,
2406
- pagePath: PageComponentOrInput.pagePath,
2407
- props: PageComponentOrInput.props
2408
- } : {
2409
- indexPath: indexPath ?? "",
2410
- options,
2411
- PageComponent: PageComponentOrInput,
2412
- pagePath: pagePath ?? "",
2413
- props
2414
- };
2415
- if (ssrDirty) {
2416
- return buildDirtyResponse(resolvedIndexPath, resolvedProps);
2417
- }
2418
- try {
2419
- const handlerCallsite = resolvedOptions?.collectStreamingSlots === true ? undefined : getCurrentRouteRegistrationCallsite() ?? captureStreamingSlotWarningCallsite();
2420
- const renderPageResponse = async () => {
2421
- const resolvePageComponent = async () => {
2422
- const passedPageComponent = PageComponent;
2423
- if (isGenericSvelteComponent(passedPageComponent)) {
2424
- return {
2425
- component: passedPageComponent,
2426
- hasIslands: readHasIslands(passedPageComponent)
2427
- };
2428
- }
2429
- const loadCompiledSourcePath = async (sourcePath) => {
2430
- const compiledModulePath = await compileSvelteServerModule(sourcePath);
2431
- const loadedModule = await import(compiledModulePath);
2432
- const loadedComponent = readDefaultExport(loadedModule) ?? loadedModule;
2433
- if (!isGenericSvelteComponent(loadedComponent)) {
2434
- throw new Error(`Invalid compiled Svelte page module: ${sourcePath}`);
2435
- }
2436
- return {
2437
- component: loadedComponent,
2438
- hasIslands: readHasIslands(loadedModule)
2439
- };
2440
- };
2441
- if (typeof passedPageComponent === "string" && passedPageComponent.endsWith(".svelte")) {
2442
- return loadCompiledSourcePath(passedPageComponent);
2443
- }
2444
- const importedPageModule = await import(resolvedPagePath);
2445
- const importedPageComponent = readDefaultExport(importedPageModule) ?? importedPageModule;
2446
- if (typeof importedPageComponent === "string" && importedPageComponent.endsWith(".svelte")) {
2447
- return loadCompiledSourcePath(importedPageComponent);
2448
- }
2449
- if (!isGenericSvelteComponent(importedPageComponent)) {
2450
- throw new Error(`Invalid Svelte page module: ${resolvedPagePath}`);
2451
- }
2452
- return {
2453
- component: importedPageComponent,
2454
- hasIslands: readHasIslands(importedPageModule)
2455
- };
2456
- };
2457
- const { renderToReadableStream: renderToReadableStream2 } = await Promise.resolve().then(() => (init_renderToReadableStream(), exports_renderToReadableStream));
2458
- const resolvedPage = await resolvePageComponent();
2459
- const stream = await renderToReadableStream2(resolvedPage.component, resolvedProps, {
2460
- bodyContent: resolvedOptions?.bodyContent,
2461
- bootstrapScriptContent: `window.__ABS_SLOT_HYDRATION_PENDING__=true;window.__INITIAL_PROPS__=${JSON.stringify(resolvedProps)};${resolvedIndexPath ? `import(${JSON.stringify(resolvedIndexPath)});` : ""}`,
2462
- headContent: resolvedOptions?.headContent
2463
- });
2464
- const htmlStream = injectIslandPageContextStream(stream, {
2465
- hasIslands: resolvedPage.hasIslands ? true : undefined
2466
- });
2467
- return new Response(htmlStream, {
2468
- headers: { "Content-Type": "text/html" }
2469
- });
2470
- };
2471
- return runWithStreamingSlotWarningScope(() => resolvedOptions?.collectStreamingSlots === true ? withRegisteredStreamingSlots(renderPageResponse, {
2472
- ...resolvedOptions,
2473
- runtimePlacement: resolvedOptions.runtimePlacement ?? "body"
2474
- }) : renderPageResponse(), { handlerCallsite });
2475
- } catch (error) {
2476
- console.error("[SSR] Svelte render error:", error);
2477
- const pageName = derivePageName(resolvedPagePath);
2478
- const conventionResponse = await renderConventionError("svelte", pageName, error);
2479
- if (conventionResponse)
2480
- return conventionResponse;
2481
- return new Response(ssrErrorPage("svelte", error), {
2482
- headers: { "Content-Type": "text/html" },
2483
- status: 500
2484
- });
2485
- }
2486
- }, invalidateSvelteSsrCache = () => {
2487
- ssrDirty = true;
2488
- };
2489
- var init_pageHandler = __esm(() => {
2490
- init_svelteServerModule();
2491
- init_islandPageContext();
2492
- init_devRouteRegistrationCallsite();
2493
- init_responseEnhancers();
2494
- init_streamingSlotWarningScope();
2495
- init_resolveConvention();
2496
- });
2497
-
2498
1873
  // src/angular/injectorPatch.ts
2499
1874
  import { existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync } from "fs";
2500
1875
  import { dirname as dirname3, join as join4, resolve as resolve4 } from "path";
@@ -3230,9 +2605,822 @@ var requireCurrentIslandRegistry = () => {
3230
2605
  globalThis.__absoluteIslandRegistry = registry;
3231
2606
  };
3232
2607
 
3233
- // src/svelte/index.ts
3234
- init_pageHandler();
2608
+ // src/core/streamingSlotRegistrar.ts
2609
+ var STREAMING_SLOT_REGISTRAR_KEY = Symbol.for("absolutejs.streamingSlotRegistrar");
2610
+ var STREAMING_SLOT_WARNING_STORAGE_KEY = Symbol.for("absolutejs.streamingSlotWarningController");
2611
+ var STREAMING_SLOT_COLLECTION_STORAGE_KEY = Symbol.for("absolutejs.streamingSlotCollectionController");
2612
+ var getRegisteredStreamingSlotRegistrar = () => {
2613
+ const value = Reflect.get(globalThis, STREAMING_SLOT_REGISTRAR_KEY);
2614
+ if (typeof value === "function" || value === null) {
2615
+ return value;
2616
+ }
2617
+ return;
2618
+ };
2619
+ var isObjectRecord = (value) => Boolean(value) && typeof value === "object";
2620
+ var isStreamingSlotWarningController = (value) => isObjectRecord(value) && ("maybeWarn" in value) && typeof value.maybeWarn === "function";
2621
+ var isStreamingSlotCollectionController = (value) => isObjectRecord(value) && ("isCollecting" in value) && typeof value.isCollecting === "function";
2622
+ var getWarningController = () => {
2623
+ const value = Reflect.get(globalThis, STREAMING_SLOT_WARNING_STORAGE_KEY);
2624
+ if (value === null || typeof value === "undefined")
2625
+ return;
2626
+ return isStreamingSlotWarningController(value) ? value : undefined;
2627
+ };
2628
+ var getCollectionController = () => {
2629
+ const value = Reflect.get(globalThis, STREAMING_SLOT_COLLECTION_STORAGE_KEY);
2630
+ if (value === null || typeof value === "undefined")
2631
+ return;
2632
+ return isStreamingSlotCollectionController(value) ? value : undefined;
2633
+ };
2634
+ var hasRegisteredStreamingSlotRegistrar = () => typeof getRegisteredStreamingSlotRegistrar() === "function";
2635
+ var isStreamingSlotCollectionActive = () => getCollectionController()?.isCollecting() === true;
2636
+ var registerStreamingSlot = (slot) => {
2637
+ getRegisteredStreamingSlotRegistrar()?.(slot);
2638
+ };
2639
+ var setStreamingSlotCollectionController = (controller) => {
2640
+ Reflect.set(globalThis, STREAMING_SLOT_COLLECTION_STORAGE_KEY, controller);
2641
+ };
2642
+ var setStreamingSlotRegistrar = (nextRegistrar) => {
2643
+ Reflect.set(globalThis, STREAMING_SLOT_REGISTRAR_KEY, nextRegistrar);
2644
+ };
2645
+ var setStreamingSlotWarningController = (controller) => {
2646
+ Reflect.set(globalThis, STREAMING_SLOT_WARNING_STORAGE_KEY, controller);
2647
+ };
2648
+ var warnMissingStreamingSlotCollector = (primitiveName) => {
2649
+ if (isStreamingSlotCollectionActive()) {
2650
+ return;
2651
+ }
2652
+ getWarningController()?.maybeWarn(primitiveName);
2653
+ };
3235
2654
 
2655
+ // src/core/streamingSlotRegistry.ts
2656
+ var STREAMING_SLOT_STORAGE_KEY = Symbol.for("absolutejs.streamingSlotAsyncLocalStorage");
2657
+ var isObjectRecord2 = (value) => Boolean(value) && typeof value === "object";
2658
+ var isAsyncLocalStorage = (value) => isObjectRecord2(value) && ("getStore" in value) && typeof value.getStore === "function" && ("run" in value) && typeof value.run === "function";
2659
+ var getStorageGlobal = () => {
2660
+ const value = Reflect.get(globalThis, STREAMING_SLOT_STORAGE_KEY);
2661
+ if (value === null || typeof value === "undefined") {
2662
+ return value;
2663
+ }
2664
+ return isAsyncLocalStorage(value) ? value : undefined;
2665
+ };
2666
+ var isServerRuntime = () => typeof process !== "undefined" && typeof process.versions?.node === "string";
2667
+ var ensureAsyncLocalStorage = async () => {
2668
+ const storage = getStorageGlobal();
2669
+ if (typeof storage !== "undefined") {
2670
+ return storage;
2671
+ }
2672
+ if (!isServerRuntime()) {
2673
+ Reflect.set(globalThis, STREAMING_SLOT_STORAGE_KEY, null);
2674
+ return getStorageGlobal();
2675
+ }
2676
+ const mod = await import("async_hooks");
2677
+ Reflect.set(globalThis, STREAMING_SLOT_STORAGE_KEY, new mod.AsyncLocalStorage);
2678
+ return getStorageGlobal();
2679
+ };
2680
+ var getActiveSlotStore = () => {
2681
+ const storage = getStorageGlobal();
2682
+ if (!storage)
2683
+ return;
2684
+ return storage.getStore();
2685
+ };
2686
+ var registerStreamingSlot2 = (slot) => {
2687
+ const store = getActiveSlotStore();
2688
+ if (!store)
2689
+ return;
2690
+ store.set(slot.id, slot);
2691
+ };
2692
+ setStreamingSlotRegistrar(registerStreamingSlot2);
2693
+ setStreamingSlotCollectionController({
2694
+ isCollecting: () => getActiveSlotStore() !== undefined
2695
+ });
2696
+ var hasActiveStreamingSlotRegistry = () => getActiveSlotStore() !== undefined;
2697
+ var runWithStreamingSlotRegistry = async (task) => {
2698
+ const storage = await ensureAsyncLocalStorage();
2699
+ if (!storage) {
2700
+ const slots = [];
2701
+ return {
2702
+ result: await task(),
2703
+ slots
2704
+ };
2705
+ }
2706
+ return storage.run(new Map, async () => {
2707
+ const result = await task();
2708
+ const store = storage.getStore();
2709
+ return {
2710
+ result,
2711
+ slots: store ? [...store.values()] : []
2712
+ };
2713
+ });
2714
+ };
2715
+
2716
+ // src/svelte/pageHandler.ts
2717
+ init_svelteServerModule();
2718
+
2719
+ // src/core/islandPageContext.ts
2720
+ init_constants();
2721
+ var BOOTSTRAP_MANIFEST_KEY = "BootstrapClient";
2722
+ var ISLAND_MARKER = 'data-island="true"';
2723
+ var MANIFEST_MARKER = "__ABSOLUTE_MANIFEST__";
2724
+ var ISLAND_STATE_MARKER = "__ABS_ISLAND_STATE__";
2725
+ var CLOSING_HEAD_TAG = "</head>";
2726
+ var buildIslandsHeadMarkup = (manifest) => {
2727
+ const manifestScript = `<script>window.__ABSOLUTE_MANIFEST__ = ${JSON.stringify(manifest)}</script>`;
2728
+ const islandStateScript = `<script>window.__ABS_ISLAND_STATE__ = ${JSON.stringify(globalThis.__ABS_ISLAND_STATE__ ?? {})}</script>`;
2729
+ const bootstrapPath = manifest[BOOTSTRAP_MANIFEST_KEY];
2730
+ const bootstrapScript = bootstrapPath ? `<script type="module" src="${bootstrapPath}"></script>` : "";
2731
+ return `${manifestScript}${islandStateScript}${bootstrapScript}`;
2732
+ };
2733
+ var injectHeadMarkup = (html, markup) => {
2734
+ const closingHeadIndex = html.indexOf("</head>");
2735
+ if (closingHeadIndex >= 0) {
2736
+ return `${html.slice(0, closingHeadIndex)}${markup}${html.slice(closingHeadIndex)}`;
2737
+ }
2738
+ const openingBodyIndex = html.indexOf("<body");
2739
+ if (openingBodyIndex >= 0) {
2740
+ const bodyStart = html.indexOf(">", openingBodyIndex);
2741
+ if (bodyStart >= 0) {
2742
+ return `${html.slice(0, openingBodyIndex)}<head>${markup}</head>${html.slice(openingBodyIndex)}`;
2743
+ }
2744
+ }
2745
+ return `<!DOCTYPE html><html><head>${markup}</head><body>${html}</body></html>`;
2746
+ };
2747
+ var streamChunkToString = (value, decoder) => typeof value === "string" ? value : decoder.decode(value, { stream: true });
2748
+ var flushSafePendingText = (controller, encoder, pending, lookbehind) => {
2749
+ if (pending.length <= lookbehind) {
2750
+ return pending;
2751
+ }
2752
+ const safeText = pending.slice(0, pending.length - lookbehind);
2753
+ controller.enqueue(encoder.encode(safeText));
2754
+ return pending.slice(-lookbehind);
2755
+ };
2756
+ var updateInjectedState = (consumed, injected, pending) => {
2757
+ if (consumed.done) {
2758
+ return { done: true, injected, pending };
2759
+ }
2760
+ return {
2761
+ done: false,
2762
+ injected: consumed.injected,
2763
+ pending: consumed.pending
2764
+ };
2765
+ };
2766
+ var readStreamChunk = async (reader) => {
2767
+ const { done, value } = await reader.read();
2768
+ if (done || !value) {
2769
+ return { done, value: undefined };
2770
+ }
2771
+ return { done, value };
2772
+ };
2773
+ var pipeStreamWithHeadInjection = (stream, markup) => {
2774
+ const encoder = new TextEncoder;
2775
+ const decoder = new TextDecoder;
2776
+ const lookbehind = CLOSING_HEAD_TAG.length - 1;
2777
+ const processPending = (controller, pending, injected) => {
2778
+ if (injected) {
2779
+ controller.enqueue(encoder.encode(pending));
2780
+ return { injected, pending: "" };
2781
+ }
2782
+ const headIndex = pending.indexOf(CLOSING_HEAD_TAG);
2783
+ if (headIndex >= 0) {
2784
+ const next = `${pending.slice(0, headIndex)}${markup}${pending.slice(headIndex)}`;
2785
+ controller.enqueue(encoder.encode(next));
2786
+ return { injected: true, pending: "" };
2787
+ }
2788
+ return {
2789
+ injected,
2790
+ pending: flushSafePendingText(controller, encoder, pending, lookbehind)
2791
+ };
2792
+ };
2793
+ const finishHeadInjectionStream = (controller, pending, injected) => {
2794
+ let finalPending = pending + decoder.decode();
2795
+ if (!injected) {
2796
+ finalPending = injectHeadMarkup(finalPending, markup);
2797
+ }
2798
+ if (finalPending.length > 0) {
2799
+ controller.enqueue(encoder.encode(finalPending));
2800
+ }
2801
+ controller.close();
2802
+ };
2803
+ const consumeHeadChunk = async (controller, reader, pending, injected) => {
2804
+ const { done, value } = await readStreamChunk(reader);
2805
+ if (done || !value) {
2806
+ return { done, injected, pending };
2807
+ }
2808
+ const processed = processPending(controller, pending + streamChunkToString(value, decoder), injected);
2809
+ return {
2810
+ done,
2811
+ injected: processed.injected,
2812
+ pending: processed.pending
2813
+ };
2814
+ };
2815
+ const runHeadInjectionLoop = async (controller, reader) => {
2816
+ const consumeNextHeadChunk = async (injected, pending) => {
2817
+ const consumed = await consumeHeadChunk(controller, reader, pending, injected);
2818
+ const nextState = updateInjectedState(consumed, injected, pending);
2819
+ if (nextState.done) {
2820
+ return { injected, pending };
2821
+ }
2822
+ return consumeNextHeadChunk(nextState.injected, nextState.pending);
2823
+ };
2824
+ return consumeNextHeadChunk(false, "");
2825
+ };
2826
+ return new ReadableStream({
2827
+ async start(controller) {
2828
+ const reader = stream.getReader();
2829
+ try {
2830
+ const { injected, pending } = await runHeadInjectionLoop(controller, reader);
2831
+ finishHeadInjectionStream(controller, pending, injected);
2832
+ } catch (error) {
2833
+ controller.error(error);
2834
+ }
2835
+ }
2836
+ });
2837
+ };
2838
+ var pipeStreamWithIslandMarkerDetection = (stream, markup) => {
2839
+ const encoder = new TextEncoder;
2840
+ const decoder = new TextDecoder;
2841
+ const lookbehind = Math.max(ISLAND_MARKER.length, BYTES_PER_KILOBYTE);
2842
+ const processPending = (controller, pending, injected) => {
2843
+ if (injected) {
2844
+ controller.enqueue(encoder.encode(pending));
2845
+ return { injected, pending: "" };
2846
+ }
2847
+ const markerIndex = pending.indexOf(ISLAND_MARKER);
2848
+ if (markerIndex >= 0) {
2849
+ const tagStart = pending.lastIndexOf("<", markerIndex);
2850
+ const injectAt = tagStart >= 0 ? tagStart : markerIndex;
2851
+ const next = `${pending.slice(0, injectAt)}${markup}${pending.slice(injectAt)}`;
2852
+ controller.enqueue(encoder.encode(next));
2853
+ return { injected: true, pending: "" };
2854
+ }
2855
+ return {
2856
+ injected,
2857
+ pending: flushSafePendingText(controller, encoder, pending, lookbehind)
2858
+ };
2859
+ };
2860
+ const finishIslandMarkerStream = (controller, pending) => {
2861
+ const finalPending = pending + decoder.decode();
2862
+ if (finalPending.length > 0) {
2863
+ controller.enqueue(encoder.encode(finalPending));
2864
+ }
2865
+ controller.close();
2866
+ };
2867
+ const consumeIslandChunk = async (controller, reader, pending, injected) => {
2868
+ const { done, value } = await readStreamChunk(reader);
2869
+ if (done || !value) {
2870
+ return { done, injected, pending };
2871
+ }
2872
+ const processed = processPending(controller, pending + streamChunkToString(value, decoder), injected);
2873
+ return {
2874
+ done,
2875
+ injected: processed.injected,
2876
+ pending: processed.pending
2877
+ };
2878
+ };
2879
+ const runIslandMarkerLoop = async (controller, reader) => {
2880
+ const consumeNextIslandChunk = async (injected, pending) => {
2881
+ const consumed = await consumeIslandChunk(controller, reader, pending, injected);
2882
+ const nextState = updateInjectedState(consumed, injected, pending);
2883
+ if (nextState.done) {
2884
+ return { injected, pending };
2885
+ }
2886
+ return consumeNextIslandChunk(nextState.injected, nextState.pending);
2887
+ };
2888
+ return consumeNextIslandChunk(false, "");
2889
+ };
2890
+ return new ReadableStream({
2891
+ async start(controller) {
2892
+ const reader = stream.getReader();
2893
+ try {
2894
+ const { pending } = await runIslandMarkerLoop(controller, reader);
2895
+ finishIslandMarkerStream(controller, pending);
2896
+ } catch (error) {
2897
+ controller.error(error);
2898
+ }
2899
+ }
2900
+ });
2901
+ };
2902
+ var htmlContainsIslands = (html) => html.includes(ISLAND_MARKER);
2903
+ var injectIslandPageContext = (html, options) => {
2904
+ const manifest = globalThis.__absoluteManifest;
2905
+ const hasIslands = options?.hasIslands ?? htmlContainsIslands(html);
2906
+ if (!manifest || !hasIslands) {
2907
+ return html;
2908
+ }
2909
+ if (html.includes(MANIFEST_MARKER) || html.includes(ISLAND_STATE_MARKER)) {
2910
+ return html;
2911
+ }
2912
+ return injectHeadMarkup(html, buildIslandsHeadMarkup(manifest));
2913
+ };
2914
+ var injectIslandPageContextStream = (stream, options) => {
2915
+ const manifest = globalThis.__absoluteManifest;
2916
+ if (!manifest)
2917
+ return stream;
2918
+ const markup = buildIslandsHeadMarkup(manifest);
2919
+ if (options?.hasIslands === true) {
2920
+ return pipeStreamWithHeadInjection(stream, markup);
2921
+ }
2922
+ if (options?.hasIslands === false) {
2923
+ return stream;
2924
+ }
2925
+ return pipeStreamWithIslandMarkerDetection(stream, markup);
2926
+ };
2927
+ var setCurrentIslandManifest = (manifest) => {
2928
+ globalThis.__absoluteManifest = manifest;
2929
+ };
2930
+
2931
+ // src/svelte/pageHandler.ts
2932
+ init_devRouteRegistrationCallsite();
2933
+
2934
+ // src/core/responseEnhancers.ts
2935
+ init_streamingSlots();
2936
+ var toResponse = async (responseLike) => responseLike;
2937
+ var cloneHeaders = (response) => {
2938
+ const headers = new Headers(response.headers);
2939
+ return headers;
2940
+ };
2941
+ var enhanceHtmlResponseWithStreamingSlots = (response, {
2942
+ nonce,
2943
+ onError,
2944
+ runtimePlacement,
2945
+ runtimePreludeScript,
2946
+ streamingSlots = [],
2947
+ policy
2948
+ } = {}) => {
2949
+ if (!response.body || streamingSlots.length === 0) {
2950
+ return response;
2951
+ }
2952
+ const body = appendStreamingSlotPatchesToStream(response.body, streamingSlots, {
2953
+ nonce,
2954
+ onError,
2955
+ policy,
2956
+ runtimePlacement,
2957
+ runtimePreludeScript
2958
+ });
2959
+ return new Response(body, {
2960
+ headers: cloneHeaders(response),
2961
+ status: response.status,
2962
+ statusText: response.statusText
2963
+ });
2964
+ };
2965
+ var withStreamingSlots = async (responseLike, options = {}) => enhanceHtmlResponseWithStreamingSlots(await toResponse(responseLike), options);
2966
+ var mergeStreamingSlots = (registered, explicit) => {
2967
+ const merged = new Map;
2968
+ for (const slot of registered)
2969
+ merged.set(slot.id, slot);
2970
+ for (const slot of explicit)
2971
+ merged.set(slot.id, slot);
2972
+ return [...merged.values()];
2973
+ };
2974
+ var withRegisteredStreamingSlots = async (renderResponse, options = {}) => {
2975
+ const { result, slots } = await runWithStreamingSlotRegistry(renderResponse);
2976
+ const explicit = options.streamingSlots ?? [];
2977
+ return withStreamingSlots(result, {
2978
+ ...options,
2979
+ streamingSlots: mergeStreamingSlots(slots, explicit)
2980
+ });
2981
+ };
2982
+
2983
+ // src/core/streamingSlotWarningScope.ts
2984
+ init_logger();
2985
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
2986
+ var STREAMING_SLOT_WARNING_STORAGE_KEY2 = Symbol.for("absolutejs.streamingSlotWarningAsyncLocalStorage");
2987
+ var isObjectRecord4 = (value) => Boolean(value) && typeof value === "object";
2988
+ var isAsyncLocalStorage3 = (value) => isObjectRecord4(value) && ("getStore" in value) && typeof value.getStore === "function" && ("run" in value) && typeof value.run === "function";
2989
+ var getWarningStorage = () => {
2990
+ const value = Reflect.get(globalThis, STREAMING_SLOT_WARNING_STORAGE_KEY2);
2991
+ if (value === null || typeof value === "undefined") {
2992
+ return;
2993
+ }
2994
+ return isAsyncLocalStorage3(value) ? value : undefined;
2995
+ };
2996
+ var ensureWarningStorage = () => {
2997
+ const existing = getWarningStorage();
2998
+ if (existing) {
2999
+ return existing;
3000
+ }
3001
+ const storage = new AsyncLocalStorage2;
3002
+ Reflect.set(globalThis, STREAMING_SLOT_WARNING_STORAGE_KEY2, storage);
3003
+ return storage;
3004
+ };
3005
+ var normalizeCallsitePath2 = (value) => value.replace(`${process.cwd()}/`, "").replace(process.cwd(), "").replace(/^\.\/+/, "");
3006
+ var formatWarningCallsite = (callsite) => {
3007
+ const match = callsite.match(/^(.*?)(:\d+:\d+)$/);
3008
+ if (!match) {
3009
+ return `\x1B[36m${callsite}\x1B[0m`;
3010
+ }
3011
+ return `\x1B[36m${match[1]}\x1B[33m${match[2]}\x1B[0m`;
3012
+ };
3013
+ var extractCallsiteFromStack = (stack) => {
3014
+ const frames = stack.split(`
3015
+ `).slice(1).map((line) => line.trim());
3016
+ for (const frame of frames) {
3017
+ if (frame.includes("/node_modules/") || frame.includes("/dist/") || frame.includes("/src/react/pageHandler.") || frame.includes("/src/vue/pageHandler.") || frame.includes("/src/svelte/pageHandler.") || frame.includes("/src/angular/pageHandler.") || frame.includes("/src/core/streamingSlotWarningScope.")) {
3018
+ continue;
3019
+ }
3020
+ const locationMatch = frame.match(/\((\/[^)]+:\d+:\d+)\)$/) ?? frame.match(/at (\/[^ ]+:\d+:\d+)$/);
3021
+ if (locationMatch?.[1]) {
3022
+ return normalizeCallsitePath2(locationMatch[1]);
3023
+ }
3024
+ }
3025
+ return;
3026
+ };
3027
+ var buildMissingCollectorWarning = (primitiveName, handlerCallsite) => `${primitiveName} rendered during SSR without streaming slot collection enabled. Add { collectStreamingSlots: true } to this page handler to enable out-of-order streaming for this route.${handlerCallsite ? ` Update ${formatWarningCallsite(handlerCallsite)}.` : ""}`;
3028
+ setStreamingSlotWarningController({
3029
+ maybeWarn: (primitiveName) => {
3030
+ const store = getWarningStorage()?.getStore();
3031
+ if (!store || store.hasWarned) {
3032
+ return;
3033
+ }
3034
+ store.hasWarned = true;
3035
+ logWarn(buildMissingCollectorWarning(primitiveName, store.handlerCallsite));
3036
+ }
3037
+ });
3038
+ var captureStreamingSlotWarningCallsite = () => {
3039
+ if (false) {}
3040
+ const { stack } = new Error;
3041
+ if (!stack) {
3042
+ return;
3043
+ }
3044
+ return extractCallsiteFromStack(stack);
3045
+ };
3046
+ var runWithStreamingSlotWarningScope = (task, metadata) => ensureWarningStorage().run({ handlerCallsite: metadata?.handlerCallsite, hasWarned: false }, task);
3047
+
3048
+ // src/svelte/pageHandler.ts
3049
+ init_ssrCache();
3050
+
3051
+ // src/utils/ssrErrorPage.ts
3052
+ var ssrErrorPage = (framework, error) => {
3053
+ const frameworkColors2 = {
3054
+ angular: "#dd0031",
3055
+ html: "#e34c26",
3056
+ htmx: "#1a365d",
3057
+ react: "#61dafb",
3058
+ svelte: "#ff3e00",
3059
+ vue: "#42b883"
3060
+ };
3061
+ const accent = frameworkColors2[framework] ?? "#94a3b8";
3062
+ const label = framework.charAt(0).toUpperCase() + framework.slice(1);
3063
+ const message = error instanceof Error ? error.message : String(error);
3064
+ return `<!DOCTYPE html>
3065
+ <html>
3066
+ <head>
3067
+ <meta charset="utf-8">
3068
+ <meta name="viewport" content="width=device-width, initial-scale=1">
3069
+ <title>SSR Error - AbsoluteJS</title>
3070
+ <style>
3071
+ *{margin:0;padding:0;box-sizing:border-box}
3072
+ body{min-height:100vh;background:linear-gradient(135deg,rgba(15,23,42,0.98) 0%,rgba(30,41,59,0.98) 100%);color:#e2e8f0;font-family:"JetBrains Mono","Fira Code",ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;font-size:14px;line-height:1.6;display:flex;align-items:flex-start;justify-content:center;padding:32px}
3073
+ .card{max-width:720px;width:100%;background:rgba(30,41,59,0.6);border:1px solid rgba(71,85,105,0.5);border-radius:16px;box-shadow:0 25px 50px -12px rgba(0,0,0,0.5),0 0 0 1px rgba(255,255,255,0.05);overflow:hidden}
3074
+ .header{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:20px 24px;background:rgba(15,23,42,0.5);border-bottom:1px solid rgba(71,85,105,0.4)}
3075
+ .brand{font-weight:700;font-size:20px;color:#fff;letter-spacing:-0.02em}
3076
+ .badge{padding:5px 10px;border-radius:8px;font-size:12px;font-weight:600;background:${accent};color:#fff;opacity:0.95;box-shadow:0 2px 4px rgba(0,0,0,0.2)}
3077
+ .kind{color:#94a3b8;font-size:13px;font-weight:500}
3078
+ .content{padding:24px}
3079
+ .label{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:0.08em;color:#94a3b8;margin-bottom:8px}
3080
+ .message{margin:0;padding:16px 20px;background:rgba(239,68,68,0.12);border:1px solid rgba(239,68,68,0.25);border-radius:10px;overflow-x:auto;white-space:pre-wrap;word-break:break-word;color:#fca5a5;font-size:13px;line-height:1.5}
3081
+ .hint{margin-top:20px;padding:12px 20px;background:rgba(71,85,105,0.3);border-radius:10px;border:1px solid rgba(71,85,105,0.4);color:#cbd5e1;font-size:13px}
3082
+ </style>
3083
+ </head>
3084
+ <body>
3085
+ <div class="card">
3086
+ <div class="header">
3087
+ <div style="display:flex;align-items:center;gap:12px">
3088
+ <span class="brand">AbsoluteJS</span>
3089
+ <span class="badge">${label}</span>
3090
+ </div>
3091
+ <span class="kind">Server Render Error</span>
3092
+ </div>
3093
+ <div class="content">
3094
+ <div class="label">What went wrong</div>
3095
+ <pre class="message">${message.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")}</pre>
3096
+ <div class="hint">A component threw during server-side rendering. Check the terminal for the full stack trace.</div>
3097
+ </div>
3098
+ </div>
3099
+ </body>
3100
+ </html>`;
3101
+ };
3102
+
3103
+ // src/utils/resolveConvention.ts
3104
+ import { basename as basename2 } from "path";
3105
+ var CONVENTIONS_KEY = "__absoluteConventions";
3106
+ var isConventionsMap = (value) => Boolean(value) && typeof value === "object";
3107
+ var getMap = () => {
3108
+ const value = Reflect.get(globalThis, CONVENTIONS_KEY);
3109
+ if (isConventionsMap(value))
3110
+ return value;
3111
+ const empty = {};
3112
+ return empty;
3113
+ };
3114
+ var derivePageName = (pagePath) => {
3115
+ const base = basename2(pagePath);
3116
+ const dotIndex = base.indexOf(".");
3117
+ const name = dotIndex > 0 ? base.slice(0, dotIndex) : base;
3118
+ return toPascal(name);
3119
+ };
3120
+ var resolveErrorConventionPath = (framework, pageName) => {
3121
+ const conventions = getMap()[framework];
3122
+ if (!conventions)
3123
+ return;
3124
+ return conventions.pages?.[pageName]?.error ?? conventions.defaults?.error;
3125
+ };
3126
+ var resolveNotFoundConventionPath = (framework) => getMap()[framework]?.defaults?.notFound;
3127
+ var setConventions = (map) => {
3128
+ Reflect.set(globalThis, CONVENTIONS_KEY, map);
3129
+ };
3130
+ var isDev = () => true;
3131
+ var buildErrorProps = (error) => {
3132
+ const message = error instanceof Error ? error.message : String(error);
3133
+ const stack = isDev() && error instanceof Error ? error.stack : undefined;
3134
+ return { error: { message, stack } };
3135
+ };
3136
+ var renderReactError = async (conventionPath, errorProps) => {
3137
+ const { createElement } = await import("react");
3138
+ const { renderToReadableStream } = await import("react-dom/server");
3139
+ const mod = await import(conventionPath);
3140
+ const [firstKey] = Object.keys(mod);
3141
+ const ErrorComponent = mod.default ?? (firstKey ? mod[firstKey] : undefined);
3142
+ const element = createElement(ErrorComponent, errorProps);
3143
+ const stream = await renderToReadableStream(element);
3144
+ return new Response(stream, {
3145
+ headers: { "Content-Type": "text/html" },
3146
+ status: 500
3147
+ });
3148
+ };
3149
+ var renderSvelteError = async (conventionPath, errorProps) => {
3150
+ const { render } = await import("svelte/server");
3151
+ const mod = await import(conventionPath);
3152
+ const ErrorComponent = mod.default;
3153
+ const { head, body } = render(ErrorComponent, {
3154
+ props: errorProps
3155
+ });
3156
+ const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
3157
+ return new Response(html, {
3158
+ headers: { "Content-Type": "text/html" },
3159
+ status: 500
3160
+ });
3161
+ };
3162
+ var unescapeVueStyles = (ssrBody) => {
3163
+ let styles = "";
3164
+ const body = ssrBody.replace(/<style>([\s\S]*?)<\/style>/g, (_, css) => {
3165
+ styles += `<style>${css.replace(/&quot;/g, '"').replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">")}</style>`;
3166
+ return "";
3167
+ });
3168
+ return { body, styles };
3169
+ };
3170
+ var renderVueError = async (conventionPath, errorProps) => {
3171
+ const { createSSRApp, h } = await import("vue");
3172
+ const { renderToString } = await import("vue/server-renderer");
3173
+ const mod = await import(conventionPath);
3174
+ const ErrorComponent = mod.default;
3175
+ const app = createSSRApp({
3176
+ render: () => h(ErrorComponent, errorProps)
3177
+ });
3178
+ const rawBody = await renderToString(app);
3179
+ const { styles, body } = unescapeVueStyles(rawBody);
3180
+ const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
3181
+ return new Response(html, {
3182
+ headers: { "Content-Type": "text/html" },
3183
+ status: 500
3184
+ });
3185
+ };
3186
+ var renderAngularError = async (conventionPath, errorProps) => {
3187
+ const mod = await import(conventionPath);
3188
+ const renderError = mod.default ?? mod.renderError;
3189
+ if (typeof renderError !== "function")
3190
+ return null;
3191
+ const html = renderError(errorProps);
3192
+ return new Response(html, {
3193
+ headers: { "Content-Type": "text/html" },
3194
+ status: 500
3195
+ });
3196
+ };
3197
+ var logConventionRenderError = (framework, label, renderError) => {
3198
+ const message = renderError instanceof Error ? renderError.message : "";
3199
+ if (message.includes("Cannot find module") || message.includes("Cannot find package") || message.includes("not found in module")) {
3200
+ 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}).`);
3201
+ return;
3202
+ }
3203
+ console.error(`[SSR] Failed to render ${framework} convention ${label} page:`, renderError);
3204
+ };
3205
+ var ERROR_RENDERERS = {
3206
+ angular: renderAngularError,
3207
+ react: renderReactError,
3208
+ svelte: renderSvelteError,
3209
+ vue: renderVueError
3210
+ };
3211
+ var renderConventionError = async (framework, pageName, error) => {
3212
+ const conventionPath = resolveErrorConventionPath(framework, pageName);
3213
+ if (!conventionPath)
3214
+ return null;
3215
+ const errorProps = buildErrorProps(error);
3216
+ const renderer = ERROR_RENDERERS[framework];
3217
+ if (!renderer)
3218
+ return null;
3219
+ try {
3220
+ return await renderer(conventionPath, errorProps);
3221
+ } catch (renderError) {
3222
+ logConventionRenderError(framework, "error", renderError);
3223
+ }
3224
+ return null;
3225
+ };
3226
+ var renderReactNotFound = async (conventionPath) => {
3227
+ const { createElement } = await import("react");
3228
+ const { renderToReadableStream } = await import("react-dom/server");
3229
+ const mod = await import(conventionPath);
3230
+ const [nfKey] = Object.keys(mod);
3231
+ const NotFoundComponent = mod.default ?? (nfKey ? mod[nfKey] : undefined);
3232
+ const element = createElement(NotFoundComponent);
3233
+ const stream = await renderToReadableStream(element);
3234
+ return new Response(stream, {
3235
+ headers: { "Content-Type": "text/html" },
3236
+ status: 404
3237
+ });
3238
+ };
3239
+ var renderSvelteNotFound = async (conventionPath) => {
3240
+ const { render } = await import("svelte/server");
3241
+ const mod = await import(conventionPath);
3242
+ const NotFoundComponent = mod.default;
3243
+ const { head, body } = render(NotFoundComponent);
3244
+ const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
3245
+ return new Response(html, {
3246
+ headers: { "Content-Type": "text/html" },
3247
+ status: 404
3248
+ });
3249
+ };
3250
+ var renderVueNotFound = async (conventionPath) => {
3251
+ const { createSSRApp, h } = await import("vue");
3252
+ const { renderToString } = await import("vue/server-renderer");
3253
+ const mod = await import(conventionPath);
3254
+ const NotFoundComponent = mod.default;
3255
+ const app = createSSRApp({
3256
+ render: () => h(NotFoundComponent)
3257
+ });
3258
+ const rawBody = await renderToString(app);
3259
+ const { styles, body } = unescapeVueStyles(rawBody);
3260
+ const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
3261
+ return new Response(html, {
3262
+ headers: { "Content-Type": "text/html" },
3263
+ status: 404
3264
+ });
3265
+ };
3266
+ var renderAngularNotFound = async (conventionPath) => {
3267
+ const mod = await import(conventionPath);
3268
+ const renderNotFound = mod.default ?? mod.renderNotFound;
3269
+ if (typeof renderNotFound !== "function")
3270
+ return null;
3271
+ const html = renderNotFound();
3272
+ return new Response(html, {
3273
+ headers: { "Content-Type": "text/html" },
3274
+ status: 404
3275
+ });
3276
+ };
3277
+ var NOT_FOUND_RENDERERS = {
3278
+ angular: renderAngularNotFound,
3279
+ react: renderReactNotFound,
3280
+ svelte: renderSvelteNotFound,
3281
+ vue: renderVueNotFound
3282
+ };
3283
+ var renderConventionNotFound = async (framework) => {
3284
+ const conventionPath = resolveNotFoundConventionPath(framework);
3285
+ if (!conventionPath)
3286
+ return null;
3287
+ const renderer = NOT_FOUND_RENDERERS[framework];
3288
+ if (!renderer)
3289
+ return null;
3290
+ try {
3291
+ return await renderer(conventionPath);
3292
+ } catch (renderError) {
3293
+ logConventionRenderError(framework, "not-found", renderError);
3294
+ }
3295
+ return null;
3296
+ };
3297
+ var NOT_FOUND_PRIORITY = [
3298
+ "react",
3299
+ "svelte",
3300
+ "vue",
3301
+ "angular"
3302
+ ];
3303
+ var renderFirstNotFound = async () => {
3304
+ for (const framework of NOT_FOUND_PRIORITY) {
3305
+ if (!getMap()[framework]?.defaults?.notFound)
3306
+ continue;
3307
+ const response = await renderConventionNotFound(framework);
3308
+ if (response)
3309
+ return response;
3310
+ }
3311
+ return null;
3312
+ };
3313
+
3314
+ // src/svelte/pageHandler.ts
3315
+ var isRecord2 = (value) => typeof value === "object" && value !== null;
3316
+ var isGenericSvelteComponent = (value) => typeof value === "function" || isRecord2(value);
3317
+ var readHasIslands = (value) => {
3318
+ if (!isRecord2(value))
3319
+ return false;
3320
+ const hasIslands = value["__ABSOLUTE_PAGE_HAS_ISLANDS__"];
3321
+ return typeof hasIslands === "boolean" ? hasIslands : false;
3322
+ };
3323
+ var readDefaultExport = (value) => isRecord2(value) ? value.default : undefined;
3324
+ var buildDirtyResponse = (indexPath, props) => {
3325
+ const propsScript = `window.__ABS_SLOT_HYDRATION_PENDING__=true;window.__INITIAL_PROPS__=${JSON.stringify(props)};${indexPath ? `import(${JSON.stringify(indexPath)});` : ""}`;
3326
+ const dirtyFlag = "window.__SSR_DIRTY__=true;";
3327
+ const html = `<!DOCTYPE html><html><head></head><body><script>${propsScript}${dirtyFlag}</script></body></html>`;
3328
+ return new Response(html, {
3329
+ headers: { "Content-Type": "text/html" }
3330
+ });
3331
+ };
3332
+ var handleSveltePageRequest = async (PageComponentOrInput, pagePath, indexPath, props, options) => {
3333
+ const {
3334
+ PageComponent,
3335
+ indexPath: resolvedIndexPath,
3336
+ options: resolvedOptions,
3337
+ pagePath: resolvedPagePath,
3338
+ props: resolvedProps
3339
+ } = typeof PageComponentOrInput === "object" && PageComponentOrInput !== null && "pagePath" in PageComponentOrInput && "indexPath" in PageComponentOrInput ? {
3340
+ PageComponent: undefined,
3341
+ indexPath: PageComponentOrInput.indexPath,
3342
+ options: PageComponentOrInput,
3343
+ pagePath: PageComponentOrInput.pagePath,
3344
+ props: PageComponentOrInput.props
3345
+ } : {
3346
+ indexPath: indexPath ?? "",
3347
+ options,
3348
+ PageComponent: PageComponentOrInput,
3349
+ pagePath: pagePath ?? "",
3350
+ props
3351
+ };
3352
+ if (isSsrCacheDirty("svelte")) {
3353
+ return buildDirtyResponse(resolvedIndexPath, resolvedProps);
3354
+ }
3355
+ try {
3356
+ const handlerCallsite = resolvedOptions?.collectStreamingSlots === true ? undefined : getCurrentRouteRegistrationCallsite() ?? captureStreamingSlotWarningCallsite();
3357
+ const renderPageResponse = async () => {
3358
+ const resolvePageComponent = async () => {
3359
+ const passedPageComponent = PageComponent;
3360
+ if (isGenericSvelteComponent(passedPageComponent)) {
3361
+ return {
3362
+ component: passedPageComponent,
3363
+ hasIslands: readHasIslands(passedPageComponent)
3364
+ };
3365
+ }
3366
+ const loadCompiledSourcePath = async (sourcePath) => {
3367
+ const compiledModulePath = await compileSvelteServerModule(sourcePath);
3368
+ const loadedModule = await import(compiledModulePath);
3369
+ const loadedComponent = readDefaultExport(loadedModule) ?? loadedModule;
3370
+ if (!isGenericSvelteComponent(loadedComponent)) {
3371
+ throw new Error(`Invalid compiled Svelte page module: ${sourcePath}`);
3372
+ }
3373
+ return {
3374
+ component: loadedComponent,
3375
+ hasIslands: readHasIslands(loadedModule)
3376
+ };
3377
+ };
3378
+ if (typeof passedPageComponent === "string" && passedPageComponent.endsWith(".svelte")) {
3379
+ return loadCompiledSourcePath(passedPageComponent);
3380
+ }
3381
+ const importedPageModule = await import(resolvedPagePath);
3382
+ const importedPageComponent = readDefaultExport(importedPageModule) ?? importedPageModule;
3383
+ if (typeof importedPageComponent === "string" && importedPageComponent.endsWith(".svelte")) {
3384
+ return loadCompiledSourcePath(importedPageComponent);
3385
+ }
3386
+ if (!isGenericSvelteComponent(importedPageComponent)) {
3387
+ throw new Error(`Invalid Svelte page module: ${resolvedPagePath}`);
3388
+ }
3389
+ return {
3390
+ component: importedPageComponent,
3391
+ hasIslands: readHasIslands(importedPageModule)
3392
+ };
3393
+ };
3394
+ const { renderToReadableStream: renderToReadableStream2 } = await Promise.resolve().then(() => (init_renderToReadableStream(), exports_renderToReadableStream));
3395
+ const resolvedPage = await resolvePageComponent();
3396
+ const stream = await renderToReadableStream2(resolvedPage.component, resolvedProps, {
3397
+ bodyContent: resolvedOptions?.bodyContent,
3398
+ bootstrapScriptContent: `window.__ABS_SLOT_HYDRATION_PENDING__=true;window.__INITIAL_PROPS__=${JSON.stringify(resolvedProps)};${resolvedIndexPath ? `import(${JSON.stringify(resolvedIndexPath)});` : ""}`,
3399
+ headContent: resolvedOptions?.headContent
3400
+ });
3401
+ const htmlStream = injectIslandPageContextStream(stream, {
3402
+ hasIslands: resolvedPage.hasIslands ? true : undefined
3403
+ });
3404
+ return new Response(htmlStream, {
3405
+ headers: { "Content-Type": "text/html" }
3406
+ });
3407
+ };
3408
+ return runWithStreamingSlotWarningScope(() => resolvedOptions?.collectStreamingSlots === true ? withRegisteredStreamingSlots(renderPageResponse, {
3409
+ ...resolvedOptions,
3410
+ runtimePlacement: resolvedOptions.runtimePlacement ?? "body"
3411
+ }) : renderPageResponse(), { handlerCallsite });
3412
+ } catch (error) {
3413
+ console.error("[SSR] Svelte render error:", error);
3414
+ const pageName = derivePageName(resolvedPagePath);
3415
+ const conventionResponse = await renderConventionError("svelte", pageName, error);
3416
+ if (conventionResponse)
3417
+ return conventionResponse;
3418
+ return new Response(ssrErrorPage("svelte", error), {
3419
+ headers: { "Content-Type": "text/html" },
3420
+ status: 500
3421
+ });
3422
+ }
3423
+ };
3236
3424
  // src/svelte/createIsland.ts
3237
3425
  init_renderIslandMarkup();
3238
3426
  var createTypedIsland = (registry) => (props) => renderIslandMarkup(registry, props);
@@ -3374,5 +3562,5 @@ export {
3374
3562
  createTypedIsland
3375
3563
  };
3376
3564
 
3377
- //# debugId=436071CA69710DBB64756E2164756E21
3565
+ //# debugId=56FF273C4EAE5CAA64756E2164756E21
3378
3566
  //# sourceMappingURL=index.js.map