Website Structure

This commit is contained in:
supalerk-ar66 2026-01-13 10:46:40 +07:00
parent 62812f2090
commit 71f0676a62
22365 changed files with 4265753 additions and 791 deletions

View file

@ -0,0 +1,6 @@
import type { H3Event } from 'h3';
import type { NuxtPayload, NuxtSSRContext } from 'nuxt/app';
export declare function createSSRContext(event: H3Event): NuxtSSRContext;
export declare function setSSRError(ssrContext: NuxtSSRContext, error: NuxtPayload['error'] & {
url: string;
}): void;

View file

@ -0,0 +1,33 @@
import process from "node:process";
import { createHead } from "@unhead/vue/server";
import { sharedPrerenderCache } from "../cache.js";
import { useRuntimeConfig } from "#internal/nitro";
import unheadOptions from "#internal/unhead-options.mjs";
const PRERENDER_NO_SSR_ROUTES = /* @__PURE__ */ new Set(["/index.html", "/200.html", "/404.html"]);
export function createSSRContext(event) {
const ssrContext = {
url: event.path,
event,
runtimeConfig: useRuntimeConfig(event),
noSSR: !!process.env.NUXT_NO_SSR || event.context.nuxt?.noSSR || (import.meta.prerender ? PRERENDER_NO_SSR_ROUTES.has(event.path) : false),
head: createHead(unheadOptions),
error: false,
nuxt: void 0,
/* NuxtApp */
payload: {},
_payloadReducers: /* @__PURE__ */ Object.create(null),
modules: /* @__PURE__ */ new Set()
};
if (import.meta.prerender) {
if (process.env.NUXT_SHARED_DATA) {
ssrContext._sharedPrerenderCache = sharedPrerenderCache;
}
ssrContext.payload.prerenderedAt = Date.now();
}
return ssrContext;
}
export function setSSRError(ssrContext, error) {
ssrContext.error = true;
ssrContext.payload = { error };
ssrContext.url = error.url;
}

View file

@ -0,0 +1,22 @@
import type { NuxtSSRContext } from 'nuxt/app';
export declare const getSSRRenderer: () => Promise<{
rendererContext: import("vue-bundle-renderer/runtime").RendererContext;
renderToString(ssrContext: import("vue-bundle-renderer/runtime").SSRContext): Promise<{
html: string;
renderResourceHeaders: () => Record<string, string>;
renderResourceHints: () => string;
renderStyles: () => string;
renderScripts: () => string;
}>;
}>;
export declare function getRenderer(ssrContext: NuxtSSRContext): Promise<{
rendererContext: import("vue-bundle-renderer/runtime").RendererContext;
renderToString(ssrContext: import("vue-bundle-renderer/runtime").SSRContext): Promise<{
html: string;
renderResourceHeaders: () => Record<string, string>;
renderResourceHints: () => string;
renderStyles: () => string;
renderScripts: () => string;
}>;
}>;
export declare const getSSRStyles: () => Promise<Record<string, () => Promise<string[]>>>;

View file

@ -0,0 +1,85 @@
import process from "node:process";
import { createRenderer } from "vue-bundle-renderer/runtime";
import { renderToString as _renderToString } from "vue/server-renderer";
import { propsToString } from "@unhead/vue/server";
import { useRuntimeConfig } from "#internal/nitro";
import { appRootAttrs, appRootTag, appSpaLoaderAttrs, appSpaLoaderTag, spaLoadingTemplateOutside } from "#internal/nuxt.config.mjs";
import { buildAssetsURL } from "#internal/nuxt/paths";
const APP_ROOT_OPEN_TAG = `<${appRootTag}${propsToString(appRootAttrs)}>`;
const APP_ROOT_CLOSE_TAG = `</${appRootTag}>`;
const getServerEntry = () => import("#build/dist/server/server.mjs").then((r) => r.default || r);
const getClientManifest = () => import("#build/dist/server/client.manifest.mjs").then((r) => r.default || r).then((r) => typeof r === "function" ? r() : r);
const getPrecomputedDependencies = () => import("#build/dist/server/client.precomputed.mjs").then((r) => r.default || r).then((r) => typeof r === "function" ? r() : r);
export const getSSRRenderer = lazyCachedFunction(async () => {
const createSSRApp = await getServerEntry();
if (!createSSRApp) {
throw new Error("Server bundle is not available");
}
const precomputed = import.meta.dev ? void 0 : await getPrecomputedDependencies();
const renderer = createRenderer(createSSRApp, {
precomputed,
manifest: import.meta.dev ? await getClientManifest() : void 0,
renderToString,
buildAssetsURL
});
async function renderToString(input, context) {
const html = await _renderToString(input, context);
if (import.meta.dev && process.env.NUXT_VITE_NODE_OPTIONS) {
renderer.rendererContext.updateManifest(await getClientManifest());
}
return APP_ROOT_OPEN_TAG + html + APP_ROOT_CLOSE_TAG;
}
return renderer;
});
const getSPARenderer = lazyCachedFunction(async () => {
const precomputed = import.meta.dev ? void 0 : await getPrecomputedDependencies();
const spaTemplate = await import("#spa-template").then((r) => r.template).catch(() => "").then((r) => {
if (spaLoadingTemplateOutside) {
const APP_SPA_LOADER_OPEN_TAG = `<${appSpaLoaderTag}${propsToString(appSpaLoaderAttrs)}>`;
const APP_SPA_LOADER_CLOSE_TAG = `</${appSpaLoaderTag}>`;
const appTemplate = APP_ROOT_OPEN_TAG + APP_ROOT_CLOSE_TAG;
const loaderTemplate = r ? APP_SPA_LOADER_OPEN_TAG + r + APP_SPA_LOADER_CLOSE_TAG : "";
return appTemplate + loaderTemplate;
} else {
return APP_ROOT_OPEN_TAG + r + APP_ROOT_CLOSE_TAG;
}
});
const renderer = createRenderer(() => () => {
}, {
precomputed,
manifest: import.meta.dev ? await getClientManifest() : void 0,
renderToString: () => spaTemplate,
buildAssetsURL
});
const result = await renderer.renderToString({});
const renderToString = (ssrContext) => {
const config = useRuntimeConfig(ssrContext.event);
ssrContext.modules ||= /* @__PURE__ */ new Set();
ssrContext.payload.serverRendered = false;
ssrContext.config = {
public: config.public,
app: config.app
};
return Promise.resolve(result);
};
return {
rendererContext: renderer.rendererContext,
renderToString
};
});
function lazyCachedFunction(fn) {
let res = null;
return () => {
if (res === null) {
res = fn().catch((err) => {
res = null;
throw err;
});
}
return res;
};
}
export function getRenderer(ssrContext) {
return process.env.NUXT_NO_SSR || ssrContext.noSSR ? getSPARenderer() : getSSRRenderer();
}
export const getSSRStyles = lazyCachedFunction(() => import("#build/dist/server/styles.mjs").then((r) => r.default || r));

View file

@ -0,0 +1,2 @@
import type { Style } from '@unhead/vue/types';
export declare function renderInlineStyles(usedModules: Set<string> | string[]): Promise<Style[]>;

View file

@ -0,0 +1,13 @@
import { getSSRStyles } from "./build-files.js";
export async function renderInlineStyles(usedModules) {
const styleMap = await getSSRStyles();
const inlinedStyles = /* @__PURE__ */ new Set();
for (const mod of usedModules) {
if (mod in styleMap && styleMap[mod]) {
for (const style of await styleMap[mod]()) {
inlinedStyles.add(style);
}
}
}
return Array.from(inlinedStyles).map((style) => ({ innerHTML: style }));
}

View file

@ -0,0 +1,9 @@
import type { NuxtIslandResponse, NuxtSSRContext } from 'nuxt/app';
/**
* remove the root node from the html body
*/
export declare function getServerComponentHTML(body: string): string;
export declare function getSlotIslandResponse(ssrContext: NuxtSSRContext): NuxtIslandResponse['slots'];
export declare function getClientIslandResponse(ssrContext: NuxtSSRContext): NuxtIslandResponse['components'];
export declare function getComponentSlotTeleport(clientUid: string, teleports: Record<string, string>): Record<string, string>;
export declare function replaceIslandTeleports(ssrContext: NuxtSSRContext, html: string): string;

View file

@ -0,0 +1,82 @@
import { appRootTag } from "#internal/nuxt.config.mjs";
const ROOT_NODE_REGEX = new RegExp(`^<${appRootTag}[^>]*>([\\s\\S]*)<\\/${appRootTag}>$`);
export function getServerComponentHTML(body) {
const match = body.match(ROOT_NODE_REGEX);
return match?.[1] || body;
}
const SSR_SLOT_TELEPORT_MARKER = /^uid=([^;]*);slot=(.*)$/;
const SSR_CLIENT_TELEPORT_MARKER = /^uid=([^;]*);client=(.*)$/;
const SSR_CLIENT_SLOT_MARKER = /^island-slot=([^;]*);(.*)$/;
export function getSlotIslandResponse(ssrContext) {
if (!ssrContext.islandContext || !Object.keys(ssrContext.islandContext.slots).length) {
return void 0;
}
const response = {};
for (const [name, slot] of Object.entries(ssrContext.islandContext.slots)) {
response[name] = {
...slot,
fallback: ssrContext.teleports?.[`island-fallback=${name}`]
};
}
return response;
}
export function getClientIslandResponse(ssrContext) {
if (!ssrContext.islandContext || !Object.keys(ssrContext.islandContext.components).length) {
return void 0;
}
const response = {};
for (const [clientUid, component] of Object.entries(ssrContext.islandContext.components)) {
const html = ssrContext.teleports?.[clientUid]?.replaceAll("<!--teleport start anchor-->", "") || "";
response[clientUid] = {
...component,
html,
slots: getComponentSlotTeleport(clientUid, ssrContext.teleports ?? {})
};
}
return response;
}
export function getComponentSlotTeleport(clientUid, teleports) {
const entries = Object.entries(teleports);
const slots = {};
for (const [key, value] of entries) {
const match = key.match(SSR_CLIENT_SLOT_MARKER);
if (match) {
const [, id, slot] = match;
if (!slot || clientUid !== id) {
continue;
}
slots[slot] = value;
}
}
return slots;
}
export function replaceIslandTeleports(ssrContext, html) {
const { teleports, islandContext } = ssrContext;
if (islandContext || !teleports) {
return html;
}
for (const key in teleports) {
const matchClientComp = key.match(SSR_CLIENT_TELEPORT_MARKER);
if (matchClientComp) {
const [, uid, clientId] = matchClientComp;
if (!uid || !clientId) {
continue;
}
html = html.replace(new RegExp(` data-island-uid="${uid}" data-island-component="${clientId}"[^>]*>`), (full) => {
return full + teleports[key];
});
continue;
}
const matchSlot = key.match(SSR_SLOT_TELEPORT_MARKER);
if (matchSlot) {
const [, uid, slot] = matchSlot;
if (!uid || !slot) {
continue;
}
html = html.replace(new RegExp(` data-island-uid="${uid}" data-island-slot="${slot}"[^>]*>`), (full) => {
return full + teleports[key];
});
}
}
return html;
}

View file

@ -0,0 +1,37 @@
import type { Script } from '@unhead/vue';
import type { NuxtSSRContext } from 'nuxt/app';
export declare function renderPayloadResponse(ssrContext: NuxtSSRContext): {
body: string;
statusCode: number;
statusMessage: string;
headers: {
'content-type': string;
'x-powered-by': string;
};
};
export declare function renderPayloadJsonScript(opts: {
ssrContext: NuxtSSRContext;
data?: any;
src?: string;
}): Script[];
export declare function renderPayloadScript(opts: {
ssrContext: NuxtSSRContext;
data?: any;
src?: string;
}): Script[];
export declare function splitPayload(ssrContext: NuxtSSRContext): {
initial: {
prerenderedAt: number | undefined;
path?: string | undefined;
serverRendered?: boolean | undefined;
state?: Record<string, any> | undefined;
once?: Set<string> | undefined;
config?: Pick<import("nuxt/schema").RuntimeConfig, "public" | "app"> | undefined;
error?: (import("nuxt/app").NuxtError | import("nuxt/app/defaults").DefaultErrorValue) | undefined;
_errors?: Record<string, import("nuxt/app").NuxtError<unknown> | null> | undefined;
};
payload: {
data: Record<string, any> | undefined;
prerenderedAt: number | undefined;
};
};

View file

@ -0,0 +1,67 @@
import process from "node:process";
import { getResponseStatus, getResponseStatusText } from "h3";
import devalue from "@nuxt/devalue";
import { stringify, uneval } from "devalue";
import { appId, multiApp } from "#internal/nuxt.config.mjs";
export function renderPayloadResponse(ssrContext) {
return {
body: process.env.NUXT_JSON_PAYLOADS ? stringify(splitPayload(ssrContext).payload, ssrContext._payloadReducers) : `export default ${devalue(splitPayload(ssrContext).payload)}`,
statusCode: getResponseStatus(ssrContext.event),
statusMessage: getResponseStatusText(ssrContext.event),
headers: {
"content-type": process.env.NUXT_JSON_PAYLOADS ? "application/json;charset=utf-8" : "text/javascript;charset=utf-8",
"x-powered-by": "Nuxt"
}
};
}
export function renderPayloadJsonScript(opts) {
const contents = opts.data ? stringify(opts.data, opts.ssrContext._payloadReducers) : "";
const payload = {
"type": "application/json",
"innerHTML": contents,
"data-nuxt-data": appId,
"data-ssr": !(process.env.NUXT_NO_SSR || opts.ssrContext.noSSR)
};
if (!multiApp) {
payload.id = "__NUXT_DATA__";
}
if (opts.src) {
payload["data-src"] = opts.src;
}
const config = uneval(opts.ssrContext.config);
return [
payload,
{
innerHTML: multiApp ? `window.__NUXT__=window.__NUXT__||{};window.__NUXT__[${JSON.stringify(appId)}]={config:${config}}` : `window.__NUXT__={};window.__NUXT__.config=${config}`
}
];
}
export function renderPayloadScript(opts) {
opts.data.config = opts.ssrContext.config;
const _PAYLOAD_EXTRACTION = import.meta.prerender && process.env.NUXT_PAYLOAD_EXTRACTION && !opts.ssrContext.noSSR;
const nuxtData = devalue(opts.data);
if (_PAYLOAD_EXTRACTION) {
const singleAppPayload2 = `import p from "${opts.src}";window.__NUXT__={...p,...(${nuxtData})}`;
const multiAppPayload2 = `import p from "${opts.src}";window.__NUXT__=window.__NUXT__||{};window.__NUXT__[${JSON.stringify(appId)}]={...p,...(${nuxtData})}`;
return [
{
type: "module",
innerHTML: multiApp ? multiAppPayload2 : singleAppPayload2
}
];
}
const singleAppPayload = `window.__NUXT__=${nuxtData}`;
const multiAppPayload = `window.__NUXT__=window.__NUXT__||{};window.__NUXT__[${JSON.stringify(appId)}]=${nuxtData}`;
return [
{
innerHTML: multiApp ? multiAppPayload : singleAppPayload
}
];
}
export function splitPayload(ssrContext) {
const { data, prerenderedAt, ...initial } = ssrContext.payload;
return {
initial: { ...initial, prerenderedAt },
payload: { data, prerenderedAt }
};
}