@nuxt/nitro-server-nightly 0.0.0 → 4.2.0-29344151.f836eca0

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/LICENSE +21 -0
  2. package/README.md +117 -0
  3. package/dist/index.d.mts +85 -0
  4. package/dist/index.d.ts +85 -0
  5. package/dist/index.mjs +834 -0
  6. package/dist/runtime/handlers/error.d.ts +3 -0
  7. package/dist/runtime/handlers/error.js +63 -0
  8. package/dist/runtime/handlers/island.d.ts +4 -0
  9. package/dist/runtime/handlers/island.js +100 -0
  10. package/dist/runtime/handlers/renderer.d.ts +8 -0
  11. package/dist/runtime/handlers/renderer.js +237 -0
  12. package/dist/runtime/middleware/no-ssr.d.ts +2 -0
  13. package/dist/runtime/middleware/no-ssr.js +7 -0
  14. package/dist/runtime/plugins/dev-server-logs.d.ts +3 -0
  15. package/dist/runtime/plugins/dev-server-logs.js +82 -0
  16. package/dist/runtime/templates/error-500.d.ts +2 -0
  17. package/dist/runtime/templates/error-500.js +6 -0
  18. package/dist/runtime/utils/app-config.d.ts +2 -0
  19. package/dist/runtime/utils/app-config.js +25 -0
  20. package/dist/runtime/utils/cache-driver.d.ts +2 -0
  21. package/dist/runtime/utils/cache-driver.js +34 -0
  22. package/dist/runtime/utils/cache.d.ts +8 -0
  23. package/dist/runtime/utils/cache.js +18 -0
  24. package/dist/runtime/utils/config.d.ts +1 -0
  25. package/dist/runtime/utils/config.js +1 -0
  26. package/dist/runtime/utils/dev.d.ts +1 -0
  27. package/dist/runtime/utils/dev.js +328 -0
  28. package/dist/runtime/utils/error.d.ts +6 -0
  29. package/dist/runtime/utils/error.js +11 -0
  30. package/dist/runtime/utils/paths.d.ts +4 -0
  31. package/dist/runtime/utils/paths.js +16 -0
  32. package/dist/runtime/utils/renderer/app.d.ts +6 -0
  33. package/dist/runtime/utils/renderer/app.js +32 -0
  34. package/dist/runtime/utils/renderer/build-files.d.ts +22 -0
  35. package/dist/runtime/utils/renderer/build-files.js +84 -0
  36. package/dist/runtime/utils/renderer/inline-styles.d.ts +2 -0
  37. package/dist/runtime/utils/renderer/inline-styles.js +13 -0
  38. package/dist/runtime/utils/renderer/islands.d.ts +9 -0
  39. package/dist/runtime/utils/renderer/islands.js +82 -0
  40. package/dist/runtime/utils/renderer/payload.d.ts +37 -0
  41. package/dist/runtime/utils/renderer/payload.js +66 -0
  42. package/package.json +58 -2
  43. package/dist/.gitkeep +0 -0
@@ -0,0 +1,328 @@
1
+ const iframeStorageBridge = (nonce) => (
2
+ /* js */
3
+ `
4
+ (function() {
5
+ const memoryStore = {};
6
+
7
+ const NONCE = ${JSON.stringify(nonce)}
8
+
9
+ const mockStorage = {
10
+ getItem: function(key) {
11
+ return memoryStore[key] !== undefined ? memoryStore[key] : null;
12
+ },
13
+ setItem: function(key, value) {
14
+ memoryStore[key] = String(value);
15
+ window.parent.postMessage({
16
+ type: 'storage-set',
17
+ key: key,
18
+ value: String(value),
19
+ nonce: NONCE
20
+ }, '*');
21
+ },
22
+ removeItem: function(key) {
23
+ delete memoryStore[key];
24
+ window.parent.postMessage({
25
+ type: 'storage-remove',
26
+ key: key,
27
+ nonce: NONCE
28
+ }, '*');
29
+ },
30
+ clear: function() {
31
+ for (const key in memoryStore) {
32
+ delete memoryStore[key];
33
+ }
34
+ window.parent.postMessage({
35
+ type: 'storage-clear',
36
+ nonce: NONCE
37
+ }, '*');
38
+ },
39
+ key: function(index) {
40
+ const keys = Object.keys(memoryStore);
41
+ return keys[index] !== undefined ? keys[index] : null;
42
+ },
43
+ get length() {
44
+ return Object.keys(memoryStore).length;
45
+ }
46
+ };
47
+
48
+ try {
49
+ Object.defineProperty(window, 'localStorage', {
50
+ value: mockStorage,
51
+ writable: false,
52
+ configurable: true
53
+ });
54
+ } catch (e) {
55
+ window.localStorage = mockStorage;
56
+ }
57
+
58
+ window.addEventListener('message', function(event) {
59
+ if (event.data.type === 'storage-sync-data' && event.data.nonce === NONCE) {
60
+ const data = event.data.data;
61
+ for (const key in data) {
62
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
63
+ memoryStore[key] = data[key];
64
+ }
65
+ }
66
+ if (typeof window.initTheme === 'function') {
67
+ window.initTheme();
68
+ }
69
+ window.dispatchEvent(new Event('storage-ready'));
70
+ }
71
+ });
72
+
73
+ window.parent.postMessage({
74
+ type: 'storage-sync-request',
75
+ nonce: NONCE
76
+ }, '*');
77
+ })();
78
+ `
79
+ );
80
+ const parentStorageBridge = (nonce) => (
81
+ /* js */
82
+ `
83
+ (function() {
84
+ const host = document.querySelector('nuxt-error-overlay');
85
+ if (!host) return;
86
+
87
+ // Wait for shadow root to be attached
88
+ const checkShadow = setInterval(function() {
89
+ if (host.shadowRoot) {
90
+ clearInterval(checkShadow);
91
+ const iframe = host.shadowRoot.getElementById('frame');
92
+ if (!iframe) return;
93
+
94
+ const NONCE = ${JSON.stringify(nonce)}
95
+
96
+ window.addEventListener('message', function(event) {
97
+ if (!event.data || event.data.nonce !== NONCE) return;
98
+
99
+ const data = event.data;
100
+
101
+ if (data.type === 'storage-set') {
102
+ localStorage.setItem(data.key, data.value);
103
+ } else if (data.type === 'storage-remove') {
104
+ localStorage.removeItem(data.key);
105
+ } else if (data.type === 'storage-clear') {
106
+ localStorage.clear();
107
+ } else if (data.type === 'storage-sync-request') {
108
+ const allData = {};
109
+ for (let i = 0; i < localStorage.length; i++) {
110
+ const key = localStorage.key(i);
111
+ allData[key] = localStorage.getItem(key);
112
+ }
113
+ iframe.contentWindow.postMessage({
114
+ type: 'storage-sync-data',
115
+ data: allData,
116
+ nonce: NONCE
117
+ }, '*');
118
+ }
119
+ });
120
+ }
121
+ }, 10);
122
+ })();
123
+ `
124
+ );
125
+ const errorCSS = (
126
+ /* css */
127
+ `
128
+ :host {
129
+ --preview-width: 240px;
130
+ --preview-height: 180px;
131
+ --base-width: 1200px;
132
+ --base-height: 900px;
133
+ --z-base: 999999998;
134
+ all: initial;
135
+ display: contents;
136
+ }
137
+ .sr-only {
138
+ position: absolute;
139
+ width: 1px;
140
+ height: 1px;
141
+ padding: 0;
142
+ margin: -1px;
143
+ overflow: hidden;
144
+ clip: rect(0, 0, 0, 0);
145
+ white-space: nowrap;
146
+ border-width: 0;
147
+ }
148
+ #frame {
149
+ position: fixed;
150
+ left: 0;
151
+ top: 0;
152
+ width: 100vw;
153
+ height: 100vh;
154
+ z-index: var(--z-base);
155
+ }
156
+ #frame[inert] {
157
+ right: 5px;
158
+ bottom: 5px;
159
+ left: auto;
160
+ top: auto;
161
+ width: var(--base-width);
162
+ height: var(--base-height);
163
+ transform: scale(calc(240 / 1200));
164
+ transform-origin: bottom right;
165
+ overflow: hidden;
166
+ border-radius: calc(1200 * 8px / 240);
167
+ }
168
+ #preview {
169
+ position: fixed;
170
+ right: 5px;
171
+ bottom: 5px;
172
+ width: var(--preview-width);
173
+ height: var(--preview-height);
174
+ overflow: hidden;
175
+ border-radius: 8px;
176
+ pointer-events: none;
177
+ z-index: var(--z-base);
178
+ background: white;
179
+ display: none;
180
+ }
181
+ #frame:not([inert]) + #preview {
182
+ display: block;
183
+ }
184
+ #toggle {
185
+ position: fixed;
186
+ right: 5px;
187
+ bottom: 5px;
188
+ width: var(--preview-width);
189
+ height: var(--preview-height);
190
+ background: none;
191
+ border: 3px solid #00DC82;
192
+ border-radius: 8px;
193
+ cursor: pointer;
194
+ opacity: 0.8;
195
+ transition: opacity 0.2s, box-shadow 0.2s;
196
+ z-index: calc(var(--z-base) + 1);
197
+ }
198
+ #toggle:hover,
199
+ #toggle:focus {
200
+ opacity: 1;
201
+ box-shadow: 0 0 20px rgba(0, 220, 130, 0.6);
202
+ }
203
+ #toggle:focus-visible {
204
+ outline: 3px solid #00DC82;
205
+ outline-offset: 3px;
206
+ box-shadow: 0 0 24px rgba(0, 220, 130, 0.8);
207
+ }
208
+ @media (prefers-reduced-motion: reduce) {
209
+ #toggle {
210
+ transition: none;
211
+ }
212
+ }
213
+ `
214
+ );
215
+ function webComponentScript(base64HTML) {
216
+ return (
217
+ /* js */
218
+ `
219
+ (function() {
220
+ try {
221
+ const host = document.querySelector('nuxt-error-overlay');
222
+ if (!host) return;
223
+
224
+ const shadow = host.attachShadow({ mode: 'open' });
225
+
226
+ // Create elements
227
+ const style = document.createElement('style');
228
+ style.textContent = ${JSON.stringify(errorCSS)};
229
+
230
+ const iframe = document.createElement('iframe');
231
+ iframe.id = 'frame';
232
+ iframe.src = 'data:text/html;base64,${base64HTML}';
233
+ iframe.title = 'Detailed error stack trace';
234
+ iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
235
+
236
+ const preview = document.createElement('div');
237
+ preview.id = 'preview';
238
+
239
+ const button = document.createElement('button');
240
+ button.id = 'toggle';
241
+ button.setAttribute('aria-expanded', 'true');
242
+ button.setAttribute('type', 'button');
243
+ button.innerHTML = '<span class="sr-only">Toggle detailed error view</span>';
244
+
245
+ const liveRegion = document.createElement('div');
246
+ liveRegion.setAttribute('role', 'status');
247
+ liveRegion.setAttribute('aria-live', 'polite');
248
+ liveRegion.className = 'sr-only';
249
+
250
+ // Update preview snapshot
251
+ function updatePreview() {
252
+ try {
253
+ let previewIframe = preview.querySelector('iframe');
254
+ if (!previewIframe) {
255
+ previewIframe = document.createElement('iframe');
256
+ previewIframe.style.cssText = 'width: 1200px; height: 900px; transform: scale(0.2); transform-origin: top left; border: none;';
257
+ previewIframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
258
+ preview.appendChild(previewIframe);
259
+ }
260
+
261
+ const doctype = document.doctype ? '<!DOCTYPE ' + document.doctype.name + '>' : '';
262
+ const cleanedHTML = document.documentElement.outerHTML
263
+ .replace(/<nuxt-error-overlay[^>]*>.*?<\\/nuxt-error-overlay>/gs, '')
264
+ .replace(/<script[^>]*>.*?<\\/script>/gs, '');
265
+
266
+ const iframeDoc = previewIframe.contentDocument || previewIframe.contentWindow.document;
267
+ iframeDoc.open();
268
+ iframeDoc.write(doctype + cleanedHTML);
269
+ iframeDoc.close();
270
+ } catch (error) {
271
+ console.error('Failed to update preview:', error);
272
+ }
273
+ }
274
+
275
+ function toggleView() {
276
+ const isMinimized = iframe.hasAttribute('inert');
277
+
278
+ if (isMinimized) {
279
+ updatePreview();
280
+ iframe.removeAttribute('inert');
281
+ button.setAttribute('aria-expanded', 'true');
282
+ liveRegion.textContent = 'Showing detailed error view';
283
+ setTimeout(function() {
284
+ try { iframe.contentWindow.focus(); } catch {}
285
+ }, 100);
286
+ } else {
287
+ iframe.setAttribute('inert', '');
288
+ button.setAttribute('aria-expanded', 'false');
289
+ liveRegion.textContent = 'Showing error page';
290
+ button.focus();
291
+ }
292
+ }
293
+
294
+ button.onclick = toggleView;
295
+
296
+ document.addEventListener('keydown', function(e) {
297
+ if ((e.key === 'Escape' || e.key === 'Esc') && !iframe.hasAttribute('inert')) {
298
+ toggleView();
299
+ }
300
+ });
301
+
302
+ // Append to shadow DOM
303
+ shadow.appendChild(style);
304
+ shadow.appendChild(liveRegion);
305
+ shadow.appendChild(iframe);
306
+ shadow.appendChild(preview);
307
+ shadow.appendChild(button);
308
+
309
+ // Initialize preview
310
+ setTimeout(updatePreview, 100);
311
+
312
+ } catch (error) {
313
+ console.error('Failed to initialize Nuxt error overlay:', error);
314
+ }
315
+ })();
316
+ `
317
+ );
318
+ }
319
+ export function generateErrorOverlayHTML(html) {
320
+ const nonce = Array.from(crypto.getRandomValues(new Uint8Array(16)), (b) => b.toString(16).padStart(2, "0")).join("");
321
+ const errorPage = html.replace("<head>", `<head><script>${iframeStorageBridge(nonce)}<\/script>`);
322
+ const base64HTML = Buffer.from(errorPage, "utf8").toString("base64");
323
+ return `
324
+ <script>${parentStorageBridge(nonce)}<\/script>
325
+ <nuxt-error-overlay></nuxt-error-overlay>
326
+ <script>${webComponentScript(base64HTML)}<\/script>
327
+ `;
328
+ }
@@ -0,0 +1,6 @@
1
+ import type { H3Event } from 'h3';
2
+ /**
3
+ * Nitro internal functions extracted from https://github.com/nitrojs/nitro/blob/main/src/runtime/internal/utils.ts
4
+ */
5
+ export declare function isJsonRequest(event: H3Event): boolean;
6
+ export declare function hasReqHeader(event: H3Event, name: string, includes: string): boolean | "" | undefined;
@@ -0,0 +1,11 @@
1
+ import { getRequestHeader } from "h3";
2
+ export function isJsonRequest(event) {
3
+ if (hasReqHeader(event, "accept", "text/html")) {
4
+ return false;
5
+ }
6
+ return hasReqHeader(event, "accept", "application/json") || hasReqHeader(event, "user-agent", "curl/") || hasReqHeader(event, "user-agent", "httpie/") || hasReqHeader(event, "sec-fetch-mode", "cors") || event.path.startsWith("/api/") || event.path.endsWith(".json");
7
+ }
8
+ export function hasReqHeader(event, name, includes) {
9
+ const value = getRequestHeader(event, name);
10
+ return value && typeof value === "string" && value.toLowerCase().includes(includes);
11
+ }
@@ -0,0 +1,4 @@
1
+ export declare function baseURL(): string;
2
+ export declare function buildAssetsDir(): string;
3
+ export declare function buildAssetsURL(...path: string[]): string;
4
+ export declare function publicAssetsURL(...path: string[]): string;
@@ -0,0 +1,16 @@
1
+ import { joinRelativeURL } from "ufo";
2
+ import { useRuntimeConfig } from "nitropack/runtime";
3
+ export function baseURL() {
4
+ return useRuntimeConfig().app.baseURL;
5
+ }
6
+ export function buildAssetsDir() {
7
+ return useRuntimeConfig().app.buildAssetsDir;
8
+ }
9
+ export function buildAssetsURL(...path) {
10
+ return joinRelativeURL(publicAssetsURL(), buildAssetsDir(), ...path);
11
+ }
12
+ export function publicAssetsURL(...path) {
13
+ const app = useRuntimeConfig().app;
14
+ const publicBase = app.cdnURL || app.baseURL;
15
+ return path.length ? joinRelativeURL(publicBase, ...path) : publicBase;
16
+ }
@@ -0,0 +1,6 @@
1
+ import type { H3Event } from 'h3';
2
+ import type { NuxtPayload, NuxtSSRContext } from 'nuxt/app';
3
+ export declare function createSSRContext(event: H3Event): NuxtSSRContext;
4
+ export declare function setSSRError(ssrContext: NuxtSSRContext, error: NuxtPayload['error'] & {
5
+ url: string;
6
+ }): void;
@@ -0,0 +1,32 @@
1
+ import { useRuntimeConfig } from "nitropack/runtime";
2
+ import { createHead } from "@unhead/vue/server";
3
+ import { sharedPrerenderCache } from "../cache.js";
4
+ import unheadOptions from "#internal/unhead-options.mjs";
5
+ const PRERENDER_NO_SSR_ROUTES = /* @__PURE__ */ new Set(["/index.html", "/200.html", "/404.html"]);
6
+ export function createSSRContext(event) {
7
+ const ssrContext = {
8
+ url: event.path,
9
+ event,
10
+ runtimeConfig: useRuntimeConfig(event),
11
+ noSSR: !!process.env.NUXT_NO_SSR || event.context.nuxt?.noSSR || (import.meta.prerender ? PRERENDER_NO_SSR_ROUTES.has(event.path) : false),
12
+ head: createHead(unheadOptions),
13
+ error: false,
14
+ nuxt: void 0,
15
+ /* NuxtApp */
16
+ payload: {},
17
+ _payloadReducers: /* @__PURE__ */ Object.create(null),
18
+ modules: /* @__PURE__ */ new Set()
19
+ };
20
+ if (import.meta.prerender) {
21
+ if (process.env.NUXT_SHARED_DATA) {
22
+ ssrContext._sharedPrerenderCache = sharedPrerenderCache;
23
+ }
24
+ ssrContext.payload.prerenderedAt = Date.now();
25
+ }
26
+ return ssrContext;
27
+ }
28
+ export function setSSRError(ssrContext, error) {
29
+ ssrContext.error = true;
30
+ ssrContext.payload = { error };
31
+ ssrContext.url = error.url;
32
+ }
@@ -0,0 +1,22 @@
1
+ import type { NuxtSSRContext } from 'nuxt/app';
2
+ export declare const getSSRRenderer: () => Promise<{
3
+ rendererContext: import("vue-bundle-renderer/runtime").RendererContext;
4
+ renderToString(ssrContext: import("vue-bundle-renderer/runtime").SSRContext): Promise<{
5
+ html: string;
6
+ renderResourceHeaders: () => Record<string, string>;
7
+ renderResourceHints: () => string;
8
+ renderStyles: () => string;
9
+ renderScripts: () => string;
10
+ }>;
11
+ }>;
12
+ export declare function getRenderer(ssrContext: NuxtSSRContext): Promise<{
13
+ rendererContext: import("vue-bundle-renderer/runtime").RendererContext;
14
+ renderToString(ssrContext: import("vue-bundle-renderer/runtime").SSRContext): Promise<{
15
+ html: string;
16
+ renderResourceHeaders: () => Record<string, string>;
17
+ renderResourceHints: () => string;
18
+ renderStyles: () => string;
19
+ renderScripts: () => string;
20
+ }>;
21
+ }>;
22
+ export declare const getSSRStyles: () => Promise<Record<string, () => Promise<string[]>>>;
@@ -0,0 +1,84 @@
1
+ import { createRenderer } from "vue-bundle-renderer/runtime";
2
+ import { renderToString as _renderToString } from "vue/server-renderer";
3
+ import { propsToString } from "@unhead/vue/server";
4
+ import { useRuntimeConfig } from "nitropack/runtime";
5
+ import { appRootAttrs, appRootTag, appSpaLoaderAttrs, appSpaLoaderTag, spaLoadingTemplateOutside } from "#internal/nuxt.config.mjs";
6
+ import { buildAssetsURL } from "#internal/nuxt/paths";
7
+ const APP_ROOT_OPEN_TAG = `<${appRootTag}${propsToString(appRootAttrs)}>`;
8
+ const APP_ROOT_CLOSE_TAG = `</${appRootTag}>`;
9
+ const getServerEntry = () => import("#build/dist/server/server.mjs").then((r) => r.default || r);
10
+ const getClientManifest = () => import("#build/dist/server/client.manifest.mjs").then((r) => r.default || r).then((r) => typeof r === "function" ? r() : r);
11
+ const getPrecomputedDependencies = () => import("#build/dist/server/client.precomputed.mjs").then((r) => r.default || r).then((r) => typeof r === "function" ? r() : r);
12
+ export const getSSRRenderer = lazyCachedFunction(async () => {
13
+ const createSSRApp = await getServerEntry();
14
+ if (!createSSRApp) {
15
+ throw new Error("Server bundle is not available");
16
+ }
17
+ const precomputed = import.meta.dev ? void 0 : await getPrecomputedDependencies();
18
+ const renderer = createRenderer(createSSRApp, {
19
+ precomputed,
20
+ manifest: import.meta.dev ? await getClientManifest() : void 0,
21
+ renderToString,
22
+ buildAssetsURL
23
+ });
24
+ async function renderToString(input, context) {
25
+ const html = await _renderToString(input, context);
26
+ if (import.meta.dev && process.env.NUXT_VITE_NODE_OPTIONS) {
27
+ renderer.rendererContext.updateManifest(await getClientManifest());
28
+ }
29
+ return APP_ROOT_OPEN_TAG + html + APP_ROOT_CLOSE_TAG;
30
+ }
31
+ return renderer;
32
+ });
33
+ const getSPARenderer = lazyCachedFunction(async () => {
34
+ const precomputed = import.meta.dev ? void 0 : await getPrecomputedDependencies();
35
+ const spaTemplate = await import("#spa-template").then((r) => r.template).catch(() => "").then((r) => {
36
+ if (spaLoadingTemplateOutside) {
37
+ const APP_SPA_LOADER_OPEN_TAG = `<${appSpaLoaderTag}${propsToString(appSpaLoaderAttrs)}>`;
38
+ const APP_SPA_LOADER_CLOSE_TAG = `</${appSpaLoaderTag}>`;
39
+ const appTemplate = APP_ROOT_OPEN_TAG + APP_ROOT_CLOSE_TAG;
40
+ const loaderTemplate = r ? APP_SPA_LOADER_OPEN_TAG + r + APP_SPA_LOADER_CLOSE_TAG : "";
41
+ return appTemplate + loaderTemplate;
42
+ } else {
43
+ return APP_ROOT_OPEN_TAG + r + APP_ROOT_CLOSE_TAG;
44
+ }
45
+ });
46
+ const renderer = createRenderer(() => () => {
47
+ }, {
48
+ precomputed,
49
+ manifest: import.meta.dev ? await getClientManifest() : void 0,
50
+ renderToString: () => spaTemplate,
51
+ buildAssetsURL
52
+ });
53
+ const result = await renderer.renderToString({});
54
+ const renderToString = (ssrContext) => {
55
+ const config = useRuntimeConfig(ssrContext.event);
56
+ ssrContext.modules ||= /* @__PURE__ */ new Set();
57
+ ssrContext.payload.serverRendered = false;
58
+ ssrContext.config = {
59
+ public: config.public,
60
+ app: config.app
61
+ };
62
+ return Promise.resolve(result);
63
+ };
64
+ return {
65
+ rendererContext: renderer.rendererContext,
66
+ renderToString
67
+ };
68
+ });
69
+ function lazyCachedFunction(fn) {
70
+ let res = null;
71
+ return () => {
72
+ if (res === null) {
73
+ res = fn().catch((err) => {
74
+ res = null;
75
+ throw err;
76
+ });
77
+ }
78
+ return res;
79
+ };
80
+ }
81
+ export function getRenderer(ssrContext) {
82
+ return process.env.NUXT_NO_SSR || ssrContext.noSSR ? getSPARenderer() : getSSRRenderer();
83
+ }
84
+ export const getSSRStyles = lazyCachedFunction(() => import("#build/dist/server/styles.mjs").then((r) => r.default || r));
@@ -0,0 +1,2 @@
1
+ import type { Style } from '@unhead/vue/types';
2
+ export declare function renderInlineStyles(usedModules: Set<string> | string[]): Promise<Style[]>;
@@ -0,0 +1,13 @@
1
+ import { getSSRStyles } from "./build-files.js";
2
+ export async function renderInlineStyles(usedModules) {
3
+ const styleMap = await getSSRStyles();
4
+ const inlinedStyles = /* @__PURE__ */ new Set();
5
+ for (const mod of usedModules) {
6
+ if (mod in styleMap && styleMap[mod]) {
7
+ for (const style of await styleMap[mod]()) {
8
+ inlinedStyles.add(style);
9
+ }
10
+ }
11
+ }
12
+ return Array.from(inlinedStyles).map((style) => ({ innerHTML: style }));
13
+ }
@@ -0,0 +1,9 @@
1
+ import type { NuxtIslandResponse, NuxtSSRContext } from 'nuxt/app';
2
+ /**
3
+ * remove the root node from the html body
4
+ */
5
+ export declare function getServerComponentHTML(body: string): string;
6
+ export declare function getSlotIslandResponse(ssrContext: NuxtSSRContext): NuxtIslandResponse['slots'];
7
+ export declare function getClientIslandResponse(ssrContext: NuxtSSRContext): NuxtIslandResponse['components'];
8
+ export declare function getComponentSlotTeleport(clientUid: string, teleports: Record<string, string>): Record<string, string>;
9
+ export declare function replaceIslandTeleports(ssrContext: NuxtSSRContext, html: string): string;
@@ -0,0 +1,82 @@
1
+ import { appRootTag } from "#internal/nuxt.config.mjs";
2
+ const ROOT_NODE_REGEX = new RegExp(`^<${appRootTag}[^>]*>([\\s\\S]*)<\\/${appRootTag}>$`);
3
+ export function getServerComponentHTML(body) {
4
+ const match = body.match(ROOT_NODE_REGEX);
5
+ return match?.[1] || body;
6
+ }
7
+ const SSR_SLOT_TELEPORT_MARKER = /^uid=([^;]*);slot=(.*)$/;
8
+ const SSR_CLIENT_TELEPORT_MARKER = /^uid=([^;]*);client=(.*)$/;
9
+ const SSR_CLIENT_SLOT_MARKER = /^island-slot=([^;]*);(.*)$/;
10
+ export function getSlotIslandResponse(ssrContext) {
11
+ if (!ssrContext.islandContext || !Object.keys(ssrContext.islandContext.slots).length) {
12
+ return void 0;
13
+ }
14
+ const response = {};
15
+ for (const [name, slot] of Object.entries(ssrContext.islandContext.slots)) {
16
+ response[name] = {
17
+ ...slot,
18
+ fallback: ssrContext.teleports?.[`island-fallback=${name}`]
19
+ };
20
+ }
21
+ return response;
22
+ }
23
+ export function getClientIslandResponse(ssrContext) {
24
+ if (!ssrContext.islandContext || !Object.keys(ssrContext.islandContext.components).length) {
25
+ return void 0;
26
+ }
27
+ const response = {};
28
+ for (const [clientUid, component] of Object.entries(ssrContext.islandContext.components)) {
29
+ const html = ssrContext.teleports?.[clientUid]?.replaceAll("<!--teleport start anchor-->", "") || "";
30
+ response[clientUid] = {
31
+ ...component,
32
+ html,
33
+ slots: getComponentSlotTeleport(clientUid, ssrContext.teleports ?? {})
34
+ };
35
+ }
36
+ return response;
37
+ }
38
+ export function getComponentSlotTeleport(clientUid, teleports) {
39
+ const entries = Object.entries(teleports);
40
+ const slots = {};
41
+ for (const [key, value] of entries) {
42
+ const match = key.match(SSR_CLIENT_SLOT_MARKER);
43
+ if (match) {
44
+ const [, id, slot] = match;
45
+ if (!slot || clientUid !== id) {
46
+ continue;
47
+ }
48
+ slots[slot] = value;
49
+ }
50
+ }
51
+ return slots;
52
+ }
53
+ export function replaceIslandTeleports(ssrContext, html) {
54
+ const { teleports, islandContext } = ssrContext;
55
+ if (islandContext || !teleports) {
56
+ return html;
57
+ }
58
+ for (const key in teleports) {
59
+ const matchClientComp = key.match(SSR_CLIENT_TELEPORT_MARKER);
60
+ if (matchClientComp) {
61
+ const [, uid, clientId] = matchClientComp;
62
+ if (!uid || !clientId) {
63
+ continue;
64
+ }
65
+ html = html.replace(new RegExp(` data-island-uid="${uid}" data-island-component="${clientId}"[^>]*>`), (full) => {
66
+ return full + teleports[key];
67
+ });
68
+ continue;
69
+ }
70
+ const matchSlot = key.match(SSR_SLOT_TELEPORT_MARKER);
71
+ if (matchSlot) {
72
+ const [, uid, slot] = matchSlot;
73
+ if (!uid || !slot) {
74
+ continue;
75
+ }
76
+ html = html.replace(new RegExp(` data-island-uid="${uid}" data-island-slot="${slot}"[^>]*>`), (full) => {
77
+ return full + teleports[key];
78
+ });
79
+ }
80
+ }
81
+ return html;
82
+ }
@@ -0,0 +1,37 @@
1
+ import type { Script } from '@unhead/vue';
2
+ import type { NuxtSSRContext } from 'nuxt/app';
3
+ export declare function renderPayloadResponse(ssrContext: NuxtSSRContext): {
4
+ body: string;
5
+ statusCode: number;
6
+ statusMessage: string;
7
+ headers: {
8
+ 'content-type': string;
9
+ 'x-powered-by': string;
10
+ };
11
+ };
12
+ export declare function renderPayloadJsonScript(opts: {
13
+ ssrContext: NuxtSSRContext;
14
+ data?: any;
15
+ src?: string;
16
+ }): Script[];
17
+ export declare function renderPayloadScript(opts: {
18
+ ssrContext: NuxtSSRContext;
19
+ data?: any;
20
+ src?: string;
21
+ }): Script[];
22
+ export declare function splitPayload(ssrContext: NuxtSSRContext): {
23
+ initial: {
24
+ prerenderedAt: number | undefined;
25
+ path?: string | undefined;
26
+ serverRendered?: boolean | undefined;
27
+ state?: Record<string, any> | undefined;
28
+ once?: Set<string> | undefined;
29
+ config?: Pick<import("nuxt/schema").RuntimeConfig, "public" | "app"> | undefined;
30
+ error?: import("nuxt/app").NuxtError<unknown> | undefined;
31
+ _errors?: Record<string, import("nuxt/app").NuxtError<unknown> | undefined> | undefined;
32
+ };
33
+ payload: {
34
+ data: Record<string, any> | undefined;
35
+ prerenderedAt: number | undefined;
36
+ };
37
+ };