@absolutejs/absolute 0.19.0-beta.695 → 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 (39) 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 +2308 -2232
  5. package/dist/angular/index.js.map +14 -13
  6. package/dist/angular/server.js +2279 -2203
  7. package/dist/angular/server.js.map +14 -14
  8. package/dist/build.js +42796 -6393
  9. package/dist/build.js.map +8 -19
  10. package/dist/cli/index.js +1 -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 +42693 -5631
  16. package/dist/index.js.map +18 -23
  17. package/dist/react/components/index.js +24 -16
  18. package/dist/react/components/index.js.map +2 -2
  19. package/dist/react/index.js +922 -868
  20. package/dist/react/index.js.map +12 -12
  21. package/dist/react/server.js +903 -848
  22. package/dist/react/server.js.map +11 -11
  23. package/dist/src/build/compileTailwind.d.ts +3 -0
  24. package/dist/src/core/pageHandlers.d.ts +0 -2
  25. package/dist/src/core/ssrCache.d.ts +3 -0
  26. package/dist/svelte/index.js +963 -899
  27. package/dist/svelte/index.js.map +14 -13
  28. package/dist/svelte/server.js +777 -712
  29. package/dist/svelte/server.js.map +12 -12
  30. package/dist/types/build.d.ts +5 -4
  31. package/dist/types/index.d.ts +0 -1
  32. package/dist/types/island.d.ts +14 -11
  33. package/dist/vue/components/index.js +24 -16
  34. package/dist/vue/components/index.js.map +2 -2
  35. package/dist/vue/index.js +1040 -976
  36. package/dist/vue/index.js.map +12 -12
  37. package/dist/vue/server.js +908 -841
  38. package/dist/vue/server.js.map +11 -11
  39. package/package.json +16 -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";
@@ -988,332 +895,134 @@ var init_svelteServerModule = __esm(() => {
988
895
  });
989
896
  });
990
897
 
991
- // src/core/islandPageContext.ts
992
- 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) => {
993
- const manifestScript = `<script>window.__ABSOLUTE_MANIFEST__ = ${JSON.stringify(manifest)}</script>`;
994
- const islandStateScript = `<script>window.__ABS_ISLAND_STATE__ = ${JSON.stringify(globalThis.__ABS_ISLAND_STATE__ ?? {})}</script>`;
995
- const bootstrapPath = manifest[BOOTSTRAP_MANIFEST_KEY];
996
- const bootstrapScript = bootstrapPath ? `<script type="module" src="${bootstrapPath}"></script>` : "";
997
- return `${manifestScript}${islandStateScript}${bootstrapScript}`;
998
- }, injectHeadMarkup = (html, markup) => {
999
- const closingHeadIndex = html.indexOf("</head>");
1000
- if (closingHeadIndex >= 0) {
1001
- 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;
1002
910
  }
1003
- const openingBodyIndex = html.indexOf("<body");
1004
- if (openingBodyIndex >= 0) {
1005
- const bodyStart = html.indexOf(">", openingBodyIndex);
1006
- if (bodyStart >= 0) {
1007
- 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]);
1008
930
  }
1009
931
  }
1010
- return `<!DOCTYPE html><html><head>${markup}</head><body>${html}</body></html>`;
1011
- }, streamChunkToString = (value, decoder) => typeof value === "string" ? value : decoder.decode(value, { stream: true }), flushSafePendingText = (controller, encoder, pending, lookbehind) => {
1012
- if (pending.length <= lookbehind) {
1013
- return pending;
932
+ return;
933
+ }, captureRouteRegistrationCallsite = () => {
934
+ const { stack } = new Error;
935
+ if (!stack) {
936
+ return;
1014
937
  }
1015
- const safeText = pending.slice(0, pending.length - lookbehind);
1016
- controller.enqueue(encoder.encode(safeText));
1017
- return pending.slice(-lookbehind);
1018
- }, updateInjectedState = (consumed, injected, pending) => {
1019
- if (consumed.done) {
1020
- return { done: true, injected, pending };
938
+ return extractRouteRegistrationCallsite(stack);
939
+ }, wrapRouteHandlerWithCallsite = (handler, callsite) => {
940
+ if (typeof handler !== "function" || !callsite) {
941
+ return handler;
1021
942
  }
1022
- return {
1023
- done: false,
1024
- injected: consumed.injected,
1025
- pending: consumed.pending
943
+ const storage = ensureRouteCallsiteStorage();
944
+ return function wrappedRouteHandler(...args) {
945
+ return storage.run({ callsite }, () => Reflect.apply(handler, this, args));
1026
946
  };
1027
- }, readStreamChunk = async (reader) => {
1028
- const { done, value } = await reader.read();
1029
- if (done || !value) {
1030
- 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;
1031
951
  }
1032
- return { done, value };
1033
- }, pipeStreamWithHeadInjection = (stream, markup) => {
1034
- const encoder = new TextEncoder;
1035
- const decoder = new TextDecoder;
1036
- const lookbehind = CLOSING_HEAD_TAG.length - 1;
1037
- const processPending = (controller, pending, injected) => {
1038
- if (injected) {
1039
- controller.enqueue(encoder.encode(pending));
1040
- return { injected, pending: "" };
1041
- }
1042
- const headIndex = pending.indexOf(CLOSING_HEAD_TAG);
1043
- if (headIndex >= 0) {
1044
- const next = `${pending.slice(0, headIndex)}${markup}${pending.slice(headIndex)}`;
1045
- controller.enqueue(encoder.encode(next));
1046
- 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;
1047
957
  }
1048
- return {
1049
- injected,
1050
- 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
+ ]);
1051
965
  };
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;
1052
999
  };
1053
- const finishHeadInjectionStream = (controller, pending, injected) => {
1054
- let finalPending = pending + decoder.decode();
1055
- if (!injected) {
1056
- finalPending = injectHeadMarkup(finalPending, markup);
1000
+ const unwrapPendingPayload = (value) => isPatchedPendingEntry(value) ? value.payload : value;
1001
+ const canApplyImmediately = () => window.__ABS_SLOT_HYDRATION_PENDING__ !== true;
1002
+ const isAngularDeferPayload = (payload) => {
1003
+ if (!isObjectRecord4(payload))
1004
+ return false;
1005
+ return payload.kind === "angular-defer";
1006
+ };
1007
+ const isVueSuspensePayload = (payload) => {
1008
+ if (!isObjectRecord4(payload))
1009
+ return false;
1010
+ return payload.kind === "vue-suspense";
1011
+ };
1012
+ const resolveHtml = (payload) => {
1013
+ if (!isObjectRecord4(payload)) {
1014
+ return typeof payload === "string" ? payload : "";
1057
1015
  }
1058
- if (finalPending.length > 0) {
1059
- controller.enqueue(encoder.encode(finalPending));
1016
+ if (typeof payload.html === "string") {
1017
+ return payload.html;
1060
1018
  }
1061
- controller.close();
1019
+ return "";
1062
1020
  };
1063
- const consumeHeadChunk = async (controller, reader, pending, injected) => {
1064
- const { done, value } = await readStreamChunk(reader);
1065
- if (done || !value) {
1066
- return { done, injected, pending };
1067
- }
1068
- const processed = processPending(controller, pending + streamChunkToString(value, decoder), injected);
1069
- return {
1070
- done,
1071
- injected: processed.injected,
1072
- pending: processed.pending
1073
- };
1074
- };
1075
- const runHeadInjectionLoop = async (controller, reader) => {
1076
- const consumeNextHeadChunk = async (injected, pending) => {
1077
- const consumed = await consumeHeadChunk(controller, reader, pending, injected);
1078
- const nextState = updateInjectedState(consumed, injected, pending);
1079
- if (nextState.done) {
1080
- return { injected, pending };
1081
- }
1082
- return consumeNextHeadChunk(nextState.injected, nextState.pending);
1083
- };
1084
- return consumeNextHeadChunk(false, "");
1085
- };
1086
- return new ReadableStream({
1087
- async start(controller) {
1088
- const reader = stream.getReader();
1089
- try {
1090
- const { injected, pending } = await runHeadInjectionLoop(controller, reader);
1091
- finishHeadInjectionStream(controller, pending, injected);
1092
- } catch (error) {
1093
- controller.error(error);
1094
- }
1095
- }
1096
- });
1097
- }, pipeStreamWithIslandMarkerDetection = (stream, markup) => {
1098
- const encoder = new TextEncoder;
1099
- const decoder = new TextDecoder;
1100
- const lookbehind = Math.max(ISLAND_MARKER.length, BYTES_PER_KILOBYTE);
1101
- const processPending = (controller, pending, injected) => {
1102
- if (injected) {
1103
- controller.enqueue(encoder.encode(pending));
1104
- return { injected, pending: "" };
1105
- }
1106
- const markerIndex = pending.indexOf(ISLAND_MARKER);
1107
- if (markerIndex >= 0) {
1108
- const tagStart = pending.lastIndexOf("<", markerIndex);
1109
- const injectAt = tagStart >= 0 ? tagStart : markerIndex;
1110
- const next = `${pending.slice(0, injectAt)}${markup}${pending.slice(injectAt)}`;
1111
- controller.enqueue(encoder.encode(next));
1112
- return { injected: true, pending: "" };
1113
- }
1114
- return {
1115
- injected,
1116
- pending: flushSafePendingText(controller, encoder, pending, lookbehind)
1117
- };
1118
- };
1119
- const finishIslandMarkerStream = (controller, pending) => {
1120
- const finalPending = pending + decoder.decode();
1121
- if (finalPending.length > 0) {
1122
- controller.enqueue(encoder.encode(finalPending));
1123
- }
1124
- controller.close();
1125
- };
1126
- const consumeIslandChunk = async (controller, reader, pending, injected) => {
1127
- const { done, value } = await readStreamChunk(reader);
1128
- if (done || !value) {
1129
- return { done, injected, pending };
1130
- }
1131
- const processed = processPending(controller, pending + streamChunkToString(value, decoder), injected);
1132
- return {
1133
- done,
1134
- injected: processed.injected,
1135
- pending: processed.pending
1136
- };
1137
- };
1138
- const runIslandMarkerLoop = async (controller, reader) => {
1139
- const consumeNextIslandChunk = async (injected, pending) => {
1140
- const consumed = await consumeIslandChunk(controller, reader, pending, injected);
1141
- const nextState = updateInjectedState(consumed, injected, pending);
1142
- if (nextState.done) {
1143
- return { injected, pending };
1144
- }
1145
- return consumeNextIslandChunk(nextState.injected, nextState.pending);
1146
- };
1147
- return consumeNextIslandChunk(false, "");
1148
- };
1149
- return new ReadableStream({
1150
- async start(controller) {
1151
- const reader = stream.getReader();
1152
- try {
1153
- const { pending } = await runIslandMarkerLoop(controller, reader);
1154
- finishIslandMarkerStream(controller, pending);
1155
- } catch (error) {
1156
- controller.error(error);
1157
- }
1158
- }
1159
- });
1160
- }, htmlContainsIslands = (html) => html.includes(ISLAND_MARKER), injectIslandPageContext = (html, options) => {
1161
- const manifest = globalThis.__absoluteManifest;
1162
- const hasIslands = options?.hasIslands ?? htmlContainsIslands(html);
1163
- if (!manifest || !hasIslands) {
1164
- return html;
1165
- }
1166
- if (html.includes(MANIFEST_MARKER) || html.includes(ISLAND_STATE_MARKER)) {
1167
- return html;
1168
- }
1169
- return injectHeadMarkup(html, buildIslandsHeadMarkup(manifest));
1170
- }, injectIslandPageContextStream = (stream, options) => {
1171
- const manifest = globalThis.__absoluteManifest;
1172
- if (!manifest)
1173
- return stream;
1174
- const markup = buildIslandsHeadMarkup(manifest);
1175
- if (options?.hasIslands === true) {
1176
- return pipeStreamWithHeadInjection(stream, markup);
1177
- }
1178
- if (options?.hasIslands === false) {
1179
- return stream;
1180
- }
1181
- return pipeStreamWithIslandMarkerDetection(stream, markup);
1182
- }, setCurrentIslandManifest = (manifest) => {
1183
- globalThis.__absoluteManifest = manifest;
1184
- };
1185
- var init_islandPageContext = __esm(() => {
1186
- init_constants();
1187
- });
1188
-
1189
- // src/core/devRouteRegistrationCallsite.ts
1190
- var exports_devRouteRegistrationCallsite = {};
1191
- __export(exports_devRouteRegistrationCallsite, {
1192
- patchElysiaRouteRegistrationCallsites: () => patchElysiaRouteRegistrationCallsites,
1193
- getCurrentRouteRegistrationCallsite: () => getCurrentRouteRegistrationCallsite
1194
- });
1195
- import { AsyncLocalStorage } from "async_hooks";
1196
- import { Elysia } from "elysia";
1197
- 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 = () => {
1198
- const value = Reflect.get(globalThis, ROUTE_CALLSITE_STORAGE_KEY);
1199
- if (value === null || typeof value === "undefined") {
1200
- return;
1201
- }
1202
- return isAsyncLocalStorage2(value) ? value : undefined;
1203
- }, ensureRouteCallsiteStorage = () => {
1204
- const existing = getRouteCallsiteStorage();
1205
- if (existing) {
1206
- return existing;
1207
- }
1208
- const storage = new AsyncLocalStorage;
1209
- Reflect.set(globalThis, ROUTE_CALLSITE_STORAGE_KEY, storage);
1210
- return storage;
1211
- }, normalizeCallsitePath = (value) => value.replace(`${process.cwd()}/`, "").replace(process.cwd(), "").replace(/^\.\/+/, ""), extractRouteRegistrationCallsite = (stack) => {
1212
- const frames = stack.split(`
1213
- `).slice(1).map((line) => line.trim());
1214
- for (const frame of frames) {
1215
- if (frame.includes("/node_modules/") || frame.includes("/dist/") || frame.includes("/src/core/devRouteRegistrationCallsite.")) {
1216
- continue;
1217
- }
1218
- const locationMatch = frame.match(/\((\/[^)]+:\d+:\d+)\)$/) ?? frame.match(/at (\/[^ ]+:\d+:\d+)$/);
1219
- if (locationMatch?.[1]) {
1220
- return normalizeCallsitePath(locationMatch[1]);
1221
- }
1222
- }
1223
- return;
1224
- }, captureRouteRegistrationCallsite = () => {
1225
- const { stack } = new Error;
1226
- if (!stack) {
1227
- return;
1228
- }
1229
- return extractRouteRegistrationCallsite(stack);
1230
- }, wrapRouteHandlerWithCallsite = (handler, callsite) => {
1231
- if (typeof handler !== "function" || !callsite) {
1232
- return handler;
1233
- }
1234
- const storage = ensureRouteCallsiteStorage();
1235
- return function wrappedRouteHandler(...args) {
1236
- return storage.run({ callsite }, () => Reflect.apply(handler, this, args));
1237
- };
1238
- }, getCurrentRouteRegistrationCallsite = () => getRouteCallsiteStorage()?.getStore()?.callsite, patchElysiaRouteRegistrationCallsites = () => {
1239
- if (false) {}
1240
- if (Reflect.get(globalThis, ROUTE_CALLSITE_PATCHED_KEY) === true) {
1241
- return;
1242
- }
1243
- const prototype = Elysia.prototype;
1244
- for (const methodName of ROUTE_METHOD_NAMES) {
1245
- const originalMethod = prototype[methodName];
1246
- if (typeof originalMethod !== "function") {
1247
- continue;
1248
- }
1249
- prototype[methodName] = function patchedRouteMethod(path, handler, ...rest) {
1250
- const callsite = captureRouteRegistrationCallsite();
1251
- return Reflect.apply(originalMethod, this, [
1252
- path,
1253
- wrapRouteHandlerWithCallsite(handler, callsite),
1254
- ...rest
1255
- ]);
1256
- };
1257
- }
1258
- Reflect.set(globalThis, ROUTE_CALLSITE_PATCHED_KEY, true);
1259
- };
1260
- var init_devRouteRegistrationCallsite = __esm(() => {
1261
- ROUTE_CALLSITE_STORAGE_KEY = Symbol.for("absolutejs.devRouteRegistrationCallsiteStorage");
1262
- ROUTE_CALLSITE_PATCHED_KEY = Symbol.for("absolutejs.devRouteRegistrationCallsitePatched");
1263
- ROUTE_METHOD_NAMES = [
1264
- "all",
1265
- "delete",
1266
- "get",
1267
- "head",
1268
- "options",
1269
- "patch",
1270
- "post",
1271
- "put"
1272
- ];
1273
- });
1274
-
1275
- // src/client/streamSwap.ts
1276
- var streamSwapRuntime = () => {
1277
- const SLOT_PATCH_EVENT = "absolutejs:slot-patch";
1278
- if (window.__ABS_SLOT_RUNTIME__ === true)
1279
- return;
1280
- window.__ABS_SLOT_RUNTIME__ = true;
1281
- window.__ABS_SLOT_CONSUMERS__ = window.__ABS_SLOT_CONSUMERS__ ?? {};
1282
- window.__ABS_SLOT_PENDING__ = window.__ABS_SLOT_PENDING__ ?? {};
1283
- const consumers = window.__ABS_SLOT_CONSUMERS__;
1284
- const pending = window.__ABS_SLOT_PENDING__;
1285
- const isObjectRecord4 = (value) => Boolean(value) && typeof value === "object";
1286
- const isPatchedPendingEntry = (value) => {
1287
- if (!isObjectRecord4(value))
1288
- return false;
1289
- return value.domPatched === true && "payload" in value;
1290
- };
1291
- const unwrapPendingPayload = (value) => isPatchedPendingEntry(value) ? value.payload : value;
1292
- const canApplyImmediately = () => window.__ABS_SLOT_HYDRATION_PENDING__ !== true;
1293
- const isAngularDeferPayload = (payload) => {
1294
- if (!isObjectRecord4(payload))
1295
- return false;
1296
- return payload.kind === "angular-defer";
1297
- };
1298
- const isVueSuspensePayload = (payload) => {
1299
- if (!isObjectRecord4(payload))
1300
- return false;
1301
- return payload.kind === "vue-suspense";
1302
- };
1303
- const resolveHtml = (payload) => {
1304
- if (!isObjectRecord4(payload)) {
1305
- return typeof payload === "string" ? payload : "";
1306
- }
1307
- if (typeof payload.html === "string") {
1308
- return payload.html;
1309
- }
1310
- return "";
1311
- };
1312
- const apply = (id, pendingEntry) => {
1313
- const payload = unwrapPendingPayload(pendingEntry);
1314
- if (!canApplyImmediately()) {
1315
- pending[id] = payload;
1316
- return;
1021
+ const apply = (id, pendingEntry) => {
1022
+ const payload = unwrapPendingPayload(pendingEntry);
1023
+ if (!canApplyImmediately()) {
1024
+ pending[id] = payload;
1025
+ return;
1317
1026
  }
1318
1027
  const consumer = consumers[id];
1319
1028
  if (typeof consumer !== "function") {
@@ -1948,62 +1657,15 @@ var init_streamingSlots = __esm(() => {
1948
1657
  };
1949
1658
  });
1950
1659
 
1951
- // src/core/responseEnhancers.ts
1952
- var toResponse = async (responseLike) => responseLike, cloneHeaders = (response) => {
1953
- const headers = new Headers(response.headers);
1954
- return headers;
1955
- }, enhanceHtmlResponseWithStreamingSlots = (response, {
1956
- nonce,
1957
- onError,
1958
- runtimePlacement,
1959
- runtimePreludeScript,
1960
- streamingSlots = [],
1961
- policy
1962
- } = {}) => {
1963
- if (!response.body || streamingSlots.length === 0) {
1964
- return response;
1965
- }
1966
- const body = appendStreamingSlotPatchesToStream(response.body, streamingSlots, {
1967
- nonce,
1968
- onError,
1969
- policy,
1970
- runtimePlacement,
1971
- runtimePreludeScript
1972
- });
1973
- return new Response(body, {
1974
- headers: cloneHeaders(response),
1975
- status: response.status,
1976
- statusText: response.statusText
1977
- });
1978
- }, withStreamingSlots = async (responseLike, options = {}) => enhanceHtmlResponseWithStreamingSlots(await toResponse(responseLike), options), mergeStreamingSlots = (registered, explicit) => {
1979
- const merged = new Map;
1980
- for (const slot of registered)
1981
- merged.set(slot.id, slot);
1982
- for (const slot of explicit)
1983
- merged.set(slot.id, slot);
1984
- return [...merged.values()];
1985
- }, withRegisteredStreamingSlots = async (renderResponse, options = {}) => {
1986
- const { result, slots } = await runWithStreamingSlotRegistry(renderResponse);
1987
- const explicit = options.streamingSlots ?? [];
1988
- return withStreamingSlots(result, {
1989
- ...options,
1990
- streamingSlots: mergeStreamingSlots(slots, explicit)
1991
- });
1992
- };
1993
- var init_responseEnhancers = __esm(() => {
1994
- init_streamingSlots();
1995
- init_streamingSlotRegistry();
1996
- });
1997
-
1998
- // src/utils/getDurationString.ts
1999
- var getDurationString = (duration) => {
2000
- let durationString;
2001
- if (duration < MILLISECONDS_IN_A_SECOND) {
2002
- durationString = `${duration.toFixed(TIME_PRECISION)}ms`;
2003
- } else if (duration < MILLISECONDS_IN_A_MINUTE) {
2004
- durationString = `${(duration / MILLISECONDS_IN_A_SECOND).toFixed(TIME_PRECISION)}s`;
2005
- } else {
2006
- 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`;
2007
1669
  }
2008
1670
  return durationString;
2009
1671
  };
@@ -2137,117 +1799,14 @@ var init_logger = __esm(() => {
2137
1799
  };
2138
1800
  });
2139
1801
 
2140
- // src/core/streamingSlotWarningScope.ts
2141
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
2142
- 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 = () => {
2143
- const value = Reflect.get(globalThis, STREAMING_SLOT_WARNING_STORAGE_KEY2);
2144
- if (value === null || typeof value === "undefined") {
2145
- return;
2146
- }
2147
- return isAsyncLocalStorage3(value) ? value : undefined;
2148
- }, ensureWarningStorage = () => {
2149
- const existing = getWarningStorage();
2150
- if (existing) {
2151
- return existing;
2152
- }
2153
- const storage = new AsyncLocalStorage2;
2154
- Reflect.set(globalThis, STREAMING_SLOT_WARNING_STORAGE_KEY2, storage);
2155
- return storage;
2156
- }, normalizeCallsitePath2 = (value) => value.replace(`${process.cwd()}/`, "").replace(process.cwd(), "").replace(/^\.\/+/, ""), formatWarningCallsite = (callsite) => {
2157
- const match = callsite.match(/^(.*?)(:\d+:\d+)$/);
2158
- if (!match) {
2159
- return `\x1B[36m${callsite}\x1B[0m`;
2160
- }
2161
- return `\x1B[36m${match[1]}\x1B[33m${match[2]}\x1B[0m`;
2162
- }, extractCallsiteFromStack = (stack) => {
2163
- const frames = stack.split(`
2164
- `).slice(1).map((line) => line.trim());
2165
- for (const frame of frames) {
2166
- 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.")) {
2167
- continue;
2168
- }
2169
- const locationMatch = frame.match(/\((\/[^)]+:\d+:\d+)\)$/) ?? frame.match(/at (\/[^ ]+:\d+:\d+)$/);
2170
- if (locationMatch?.[1]) {
2171
- return normalizeCallsitePath2(locationMatch[1]);
2172
- }
2173
- }
2174
- return;
2175
- }, 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 = () => {
2176
- if (false) {}
2177
- const { stack } = new Error;
2178
- if (!stack) {
2179
- return;
2180
- }
2181
- return extractCallsiteFromStack(stack);
2182
- }, runWithStreamingSlotWarningScope = (task, metadata) => ensureWarningStorage().run({ handlerCallsite: metadata?.handlerCallsite, hasWarned: false }, task);
2183
- var init_streamingSlotWarningScope = __esm(() => {
2184
- init_logger();
2185
- init_streamingSlotRegistrar();
2186
- STREAMING_SLOT_WARNING_STORAGE_KEY2 = Symbol.for("absolutejs.streamingSlotWarningAsyncLocalStorage");
2187
- setStreamingSlotWarningController({
2188
- maybeWarn: (primitiveName) => {
2189
- const store = getWarningStorage()?.getStore();
2190
- if (!store || store.hasWarned) {
2191
- return;
2192
- }
2193
- store.hasWarned = true;
2194
- logWarn(buildMissingCollectorWarning(primitiveName, store.handlerCallsite));
2195
- }
2196
- });
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;
2197
1808
  });
2198
1809
 
2199
- // src/utils/ssrErrorPage.ts
2200
- var ssrErrorPage = (framework, error) => {
2201
- const frameworkColors2 = {
2202
- angular: "#dd0031",
2203
- html: "#e34c26",
2204
- htmx: "#1a365d",
2205
- react: "#61dafb",
2206
- svelte: "#ff3e00",
2207
- vue: "#42b883"
2208
- };
2209
- const accent = frameworkColors2[framework] ?? "#94a3b8";
2210
- const label = framework.charAt(0).toUpperCase() + framework.slice(1);
2211
- const message = error instanceof Error ? error.message : String(error);
2212
- return `<!DOCTYPE html>
2213
- <html>
2214
- <head>
2215
- <meta charset="utf-8">
2216
- <meta name="viewport" content="width=device-width, initial-scale=1">
2217
- <title>SSR Error - AbsoluteJS</title>
2218
- <style>
2219
- *{margin:0;padding:0;box-sizing:border-box}
2220
- 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}
2221
- .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}
2222
- .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)}
2223
- .brand{font-weight:700;font-size:20px;color:#fff;letter-spacing:-0.02em}
2224
- .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)}
2225
- .kind{color:#94a3b8;font-size:13px;font-weight:500}
2226
- .content{padding:24px}
2227
- .label{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:0.08em;color:#94a3b8;margin-bottom:8px}
2228
- .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}
2229
- .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}
2230
- </style>
2231
- </head>
2232
- <body>
2233
- <div class="card">
2234
- <div class="header">
2235
- <div style="display:flex;align-items:center;gap:12px">
2236
- <span class="brand">AbsoluteJS</span>
2237
- <span class="badge">${label}</span>
2238
- </div>
2239
- <span class="kind">Server Render Error</span>
2240
- </div>
2241
- <div class="content">
2242
- <div class="label">What went wrong</div>
2243
- <pre class="message">${message.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")}</pre>
2244
- <div class="hint">A component threw during server-side rendering. Check the terminal for the full stack trace.</div>
2245
- </div>
2246
- </div>
2247
- </body>
2248
- </html>`;
2249
- };
2250
-
2251
1810
  // src/utils/stringModifiers.ts
2252
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) => {
2253
1812
  if (!str.includes("-") && !str.includes("_")) {
@@ -2256,215 +1815,23 @@ var normalizeSlug = (str) => str.trim().replace(/\s+/g, "-").replace(/[^A-Za-z0-
2256
1815
  return normalizeSlug(str).split(/[-_]/).filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1).toLowerCase()).join("");
2257
1816
  }, toScreamingSnake = (str) => str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toUpperCase();
2258
1817
 
2259
- // src/utils/resolveConvention.ts
2260
- import { basename as basename2 } from "path";
2261
- var CONVENTIONS_KEY = "__absoluteConventions", isConventionsMap = (value) => Boolean(value) && typeof value === "object", getMap = () => {
2262
- const value = Reflect.get(globalThis, CONVENTIONS_KEY);
2263
- if (isConventionsMap(value))
2264
- return value;
2265
- const empty = {};
2266
- return empty;
2267
- }, derivePageName = (pagePath) => {
2268
- const base = basename2(pagePath);
2269
- const dotIndex = base.indexOf(".");
2270
- const name = dotIndex > 0 ? base.slice(0, dotIndex) : base;
2271
- return toPascal(name);
2272
- }, resolveErrorConventionPath = (framework, pageName) => {
2273
- const conventions = getMap()[framework];
2274
- if (!conventions)
2275
- return;
2276
- return conventions.pages?.[pageName]?.error ?? conventions.defaults?.error;
2277
- }, resolveNotFoundConventionPath = (framework) => getMap()[framework]?.defaults?.notFound, setConventions = (map) => {
2278
- Reflect.set(globalThis, CONVENTIONS_KEY, map);
2279
- }, isDev = () => true, buildErrorProps = (error) => {
2280
- const message = error instanceof Error ? error.message : String(error);
2281
- const stack = isDev() && error instanceof Error ? error.stack : undefined;
2282
- return { error: { message, stack } };
2283
- }, renderReactError = async (conventionPath, errorProps) => {
2284
- const { createElement } = await import("react");
2285
- const { renderToReadableStream } = await import("react-dom/server");
2286
- const mod = await import(conventionPath);
2287
- const [firstKey] = Object.keys(mod);
2288
- const ErrorComponent = mod.default ?? (firstKey ? mod[firstKey] : undefined);
2289
- const element = createElement(ErrorComponent, errorProps);
2290
- const stream = await renderToReadableStream(element);
2291
- return new Response(stream, {
2292
- headers: { "Content-Type": "text/html" },
2293
- status: 500
2294
- });
2295
- }, renderSvelteError = async (conventionPath, errorProps) => {
2296
- const { render } = await import("svelte/server");
2297
- const mod = await import(conventionPath);
2298
- const ErrorComponent = mod.default;
2299
- const { head, body } = render(ErrorComponent, {
2300
- props: errorProps
2301
- });
2302
- const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
2303
- return new Response(html, {
2304
- headers: { "Content-Type": "text/html" },
2305
- status: 500
2306
- });
2307
- }, unescapeVueStyles = (ssrBody) => {
2308
- let styles = "";
2309
- const body = ssrBody.replace(/<style>([\s\S]*?)<\/style>/g, (_, css) => {
2310
- styles += `<style>${css.replace(/&quot;/g, '"').replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">")}</style>`;
2311
- return "";
2312
- });
2313
- return { body, styles };
2314
- }, renderVueError = async (conventionPath, errorProps) => {
2315
- const { createSSRApp, h } = await import("vue");
2316
- const { renderToString } = await import("vue/server-renderer");
2317
- const mod = await import(conventionPath);
2318
- const ErrorComponent = mod.default;
2319
- const app = createSSRApp({
2320
- render: () => h(ErrorComponent, errorProps)
2321
- });
2322
- const rawBody = await renderToString(app);
2323
- const { styles, body } = unescapeVueStyles(rawBody);
2324
- const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
2325
- return new Response(html, {
2326
- headers: { "Content-Type": "text/html" },
2327
- status: 500
2328
- });
2329
- }, renderAngularError = async (conventionPath, errorProps) => {
2330
- const mod = await import(conventionPath);
2331
- const renderError = mod.default ?? mod.renderError;
2332
- if (typeof renderError !== "function")
2333
- return null;
2334
- const html = renderError(errorProps);
2335
- return new Response(html, {
2336
- headers: { "Content-Type": "text/html" },
2337
- status: 500
2338
- });
2339
- }, logConventionRenderError = (framework, label, renderError) => {
2340
- const message = renderError instanceof Error ? renderError.message : "";
2341
- if (message.includes("Cannot find module") || message.includes("Cannot find package") || message.includes("not found in module")) {
2342
- 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}).`);
2343
- return;
2344
- }
2345
- console.error(`[SSR] Failed to render ${framework} convention ${label} page:`, renderError);
2346
- }, ERROR_RENDERERS, renderConventionError = async (framework, pageName, error) => {
2347
- const conventionPath = resolveErrorConventionPath(framework, pageName);
2348
- if (!conventionPath)
2349
- return null;
2350
- const errorProps = buildErrorProps(error);
2351
- const renderer = ERROR_RENDERERS[framework];
2352
- if (!renderer)
2353
- return null;
2354
- try {
2355
- return await renderer(conventionPath, errorProps);
2356
- } catch (renderError) {
2357
- logConventionRenderError(framework, "error", renderError);
2358
- }
2359
- return null;
2360
- }, renderReactNotFound = async (conventionPath) => {
2361
- const { createElement } = await import("react");
2362
- const { renderToReadableStream } = await import("react-dom/server");
2363
- const mod = await import(conventionPath);
2364
- const [nfKey] = Object.keys(mod);
2365
- const NotFoundComponent = mod.default ?? (nfKey ? mod[nfKey] : undefined);
2366
- const element = createElement(NotFoundComponent);
2367
- const stream = await renderToReadableStream(element);
2368
- return new Response(stream, {
2369
- headers: { "Content-Type": "text/html" },
2370
- status: 404
2371
- });
2372
- }, renderSvelteNotFound = async (conventionPath) => {
2373
- const { render } = await import("svelte/server");
2374
- const mod = await import(conventionPath);
2375
- const NotFoundComponent = mod.default;
2376
- const { head, body } = render(NotFoundComponent);
2377
- const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
2378
- return new Response(html, {
2379
- headers: { "Content-Type": "text/html" },
2380
- status: 404
2381
- });
2382
- }, renderVueNotFound = async (conventionPath) => {
2383
- const { createSSRApp, h } = await import("vue");
2384
- const { renderToString } = await import("vue/server-renderer");
2385
- const mod = await import(conventionPath);
2386
- const NotFoundComponent = mod.default;
2387
- const app = createSSRApp({
2388
- render: () => h(NotFoundComponent)
2389
- });
2390
- const rawBody = await renderToString(app);
2391
- const { styles, body } = unescapeVueStyles(rawBody);
2392
- const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
2393
- return new Response(html, {
2394
- headers: { "Content-Type": "text/html" },
2395
- status: 404
2396
- });
2397
- }, renderAngularNotFound = async (conventionPath) => {
2398
- const mod = await import(conventionPath);
2399
- const renderNotFound = mod.default ?? mod.renderNotFound;
2400
- if (typeof renderNotFound !== "function")
2401
- return null;
2402
- const html = renderNotFound();
2403
- return new Response(html, {
2404
- headers: { "Content-Type": "text/html" },
2405
- status: 404
2406
- });
2407
- }, NOT_FOUND_RENDERERS, renderConventionNotFound = async (framework) => {
2408
- const conventionPath = resolveNotFoundConventionPath(framework);
2409
- if (!conventionPath)
2410
- return null;
2411
- const renderer = NOT_FOUND_RENDERERS[framework];
2412
- if (!renderer)
2413
- return null;
2414
- try {
2415
- return await renderer(conventionPath);
2416
- } catch (renderError) {
2417
- logConventionRenderError(framework, "not-found", renderError);
2418
- }
2419
- return null;
2420
- }, NOT_FOUND_PRIORITY, renderFirstNotFound = async () => {
2421
- for (const framework of NOT_FOUND_PRIORITY) {
2422
- if (!getMap()[framework]?.defaults?.notFound)
2423
- continue;
2424
- const response = await renderConventionNotFound(framework);
2425
- if (response)
2426
- return response;
2427
- }
2428
- return null;
2429
- };
2430
- var init_resolveConvention = __esm(() => {
2431
- ERROR_RENDERERS = {
2432
- angular: renderAngularError,
2433
- react: renderReactError,
2434
- svelte: renderSvelteError,
2435
- vue: renderVueError
2436
- };
2437
- NOT_FOUND_RENDERERS = {
2438
- angular: renderAngularNotFound,
2439
- react: renderReactNotFound,
2440
- svelte: renderSvelteNotFound,
2441
- vue: renderVueNotFound
2442
- };
2443
- NOT_FOUND_PRIORITY = [
2444
- "react",
2445
- "svelte",
2446
- "vue",
2447
- "angular"
2448
- ];
2449
- });
2450
-
2451
- // src/svelte/renderToReadableStream.ts
2452
- var exports_renderToReadableStream = {};
2453
- __export(exports_renderToReadableStream, {
2454
- renderToReadableStream: () => renderToReadableStream,
2455
- SVELTE_PAGE_ROOT_ID: () => SVELTE_PAGE_ROOT_ID
2456
- });
2457
- var SVELTE_PAGE_ROOT_ID = "__absolute_svelte_root__", renderToReadableStream = async (component, props, {
2458
- bootstrapScriptContent,
2459
- bootstrapScripts = [],
2460
- bootstrapModules = [],
2461
- nonce,
2462
- onError = console.error,
2463
- progressiveChunkSize = DEFAULT_CHUNK_SIZE,
2464
- signal,
2465
- headContent,
2466
- bodyContent
2467
- } = {}) => {
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
+ } = {}) => {
2468
1835
  try {
2469
1836
  const { render } = await import("svelte/server");
2470
1837
  const rendered = typeof props === "undefined" ? await render(component) : await render(component, { props });
@@ -2503,122 +1870,6 @@ var init_renderToReadableStream = __esm(() => {
2503
1870
  init_escapeScriptContent();
2504
1871
  });
2505
1872
 
2506
- // src/svelte/pageHandler.ts
2507
- var ssrDirty = false, isRecord2 = (value) => typeof value === "object" && value !== null, isGenericSvelteComponent = (value) => typeof value === "function" || isRecord2(value), readHasIslands = (value) => {
2508
- if (!isRecord2(value))
2509
- return false;
2510
- const hasIslands = value["__ABSOLUTE_PAGE_HAS_ISLANDS__"];
2511
- return typeof hasIslands === "boolean" ? hasIslands : false;
2512
- }, readDefaultExport = (value) => isRecord2(value) ? value.default : undefined, buildDirtyResponse = (indexPath, props) => {
2513
- const propsScript = `window.__ABS_SLOT_HYDRATION_PENDING__=true;window.__INITIAL_PROPS__=${JSON.stringify(props)};${indexPath ? `import(${JSON.stringify(indexPath)});` : ""}`;
2514
- const dirtyFlag = "window.__SSR_DIRTY__=true;";
2515
- const html = `<!DOCTYPE html><html><head></head><body><script>${propsScript}${dirtyFlag}</script></body></html>`;
2516
- return new Response(html, {
2517
- headers: { "Content-Type": "text/html" }
2518
- });
2519
- }, handleSveltePageRequest = async (PageComponentOrInput, pagePath, indexPath, props, options) => {
2520
- const {
2521
- PageComponent,
2522
- indexPath: resolvedIndexPath,
2523
- options: resolvedOptions,
2524
- pagePath: resolvedPagePath,
2525
- props: resolvedProps
2526
- } = typeof PageComponentOrInput === "object" && PageComponentOrInput !== null && "pagePath" in PageComponentOrInput && "indexPath" in PageComponentOrInput ? {
2527
- PageComponent: undefined,
2528
- indexPath: PageComponentOrInput.indexPath,
2529
- options: PageComponentOrInput,
2530
- pagePath: PageComponentOrInput.pagePath,
2531
- props: PageComponentOrInput.props
2532
- } : {
2533
- indexPath: indexPath ?? "",
2534
- options,
2535
- PageComponent: PageComponentOrInput,
2536
- pagePath: pagePath ?? "",
2537
- props
2538
- };
2539
- if (ssrDirty) {
2540
- return buildDirtyResponse(resolvedIndexPath, resolvedProps);
2541
- }
2542
- try {
2543
- const handlerCallsite = resolvedOptions?.collectStreamingSlots === true ? undefined : getCurrentRouteRegistrationCallsite() ?? captureStreamingSlotWarningCallsite();
2544
- const renderPageResponse = async () => {
2545
- const resolvePageComponent = async () => {
2546
- const passedPageComponent = PageComponent;
2547
- if (isGenericSvelteComponent(passedPageComponent)) {
2548
- return {
2549
- component: passedPageComponent,
2550
- hasIslands: readHasIslands(passedPageComponent)
2551
- };
2552
- }
2553
- const loadCompiledSourcePath = async (sourcePath) => {
2554
- const compiledModulePath = await compileSvelteServerModule(sourcePath);
2555
- const loadedModule = await import(compiledModulePath);
2556
- const loadedComponent = readDefaultExport(loadedModule) ?? loadedModule;
2557
- if (!isGenericSvelteComponent(loadedComponent)) {
2558
- throw new Error(`Invalid compiled Svelte page module: ${sourcePath}`);
2559
- }
2560
- return {
2561
- component: loadedComponent,
2562
- hasIslands: readHasIslands(loadedModule)
2563
- };
2564
- };
2565
- if (typeof passedPageComponent === "string" && passedPageComponent.endsWith(".svelte")) {
2566
- return loadCompiledSourcePath(passedPageComponent);
2567
- }
2568
- const importedPageModule = await import(resolvedPagePath);
2569
- const importedPageComponent = readDefaultExport(importedPageModule) ?? importedPageModule;
2570
- if (typeof importedPageComponent === "string" && importedPageComponent.endsWith(".svelte")) {
2571
- return loadCompiledSourcePath(importedPageComponent);
2572
- }
2573
- if (!isGenericSvelteComponent(importedPageComponent)) {
2574
- throw new Error(`Invalid Svelte page module: ${resolvedPagePath}`);
2575
- }
2576
- return {
2577
- component: importedPageComponent,
2578
- hasIslands: readHasIslands(importedPageModule)
2579
- };
2580
- };
2581
- const { renderToReadableStream: renderToReadableStream2 } = await Promise.resolve().then(() => (init_renderToReadableStream(), exports_renderToReadableStream));
2582
- const resolvedPage = await resolvePageComponent();
2583
- const stream = await renderToReadableStream2(resolvedPage.component, resolvedProps, {
2584
- bodyContent: resolvedOptions?.bodyContent,
2585
- bootstrapScriptContent: `window.__ABS_SLOT_HYDRATION_PENDING__=true;window.__INITIAL_PROPS__=${JSON.stringify(resolvedProps)};${resolvedIndexPath ? `import(${JSON.stringify(resolvedIndexPath)});` : ""}`,
2586
- headContent: resolvedOptions?.headContent
2587
- });
2588
- const htmlStream = injectIslandPageContextStream(stream, {
2589
- hasIslands: resolvedPage.hasIslands ? true : undefined
2590
- });
2591
- return new Response(htmlStream, {
2592
- headers: { "Content-Type": "text/html" }
2593
- });
2594
- };
2595
- return runWithStreamingSlotWarningScope(() => resolvedOptions?.collectStreamingSlots === true ? withRegisteredStreamingSlots(renderPageResponse, {
2596
- ...resolvedOptions,
2597
- runtimePlacement: resolvedOptions.runtimePlacement ?? "body"
2598
- }) : renderPageResponse(), { handlerCallsite });
2599
- } catch (error) {
2600
- console.error("[SSR] Svelte render error:", error);
2601
- const pageName = derivePageName(resolvedPagePath);
2602
- const conventionResponse = await renderConventionError("svelte", pageName, error);
2603
- if (conventionResponse)
2604
- return conventionResponse;
2605
- return new Response(ssrErrorPage("svelte", error), {
2606
- headers: { "Content-Type": "text/html" },
2607
- status: 500
2608
- });
2609
- }
2610
- }, invalidateSvelteSsrCache = () => {
2611
- ssrDirty = true;
2612
- };
2613
- var init_pageHandler = __esm(() => {
2614
- init_svelteServerModule();
2615
- init_islandPageContext();
2616
- init_devRouteRegistrationCallsite();
2617
- init_responseEnhancers();
2618
- init_streamingSlotWarningScope();
2619
- init_resolveConvention();
2620
- });
2621
-
2622
1873
  // src/angular/injectorPatch.ts
2623
1874
  import { existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync } from "fs";
2624
1875
  import { dirname as dirname3, join as join4, resolve as resolve4 } from "path";
@@ -3354,9 +2605,822 @@ var requireCurrentIslandRegistry = () => {
3354
2605
  globalThis.__absoluteIslandRegistry = registry;
3355
2606
  };
3356
2607
 
3357
- // src/svelte/index.ts
3358
- 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
+ };
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();
3359
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
+ };
3360
3424
  // src/svelte/createIsland.ts
3361
3425
  init_renderIslandMarkup();
3362
3426
  var createTypedIsland = (registry) => (props) => renderIslandMarkup(registry, props);
@@ -3498,5 +3562,5 @@ export {
3498
3562
  createTypedIsland
3499
3563
  };
3500
3564
 
3501
- //# debugId=02FEC5145382C1EB64756E2164756E21
3565
+ //# debugId=56FF273C4EAE5CAA64756E2164756E21
3502
3566
  //# sourceMappingURL=index.js.map