@useavalon/avalon 0.1.54 → 0.1.56
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.
package/dist/src/client/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{executeCustomDirective as e,hasClientDirective as t}from"./custom-directives.js";import{loadIntegrationModule as n}from"virtual:avalon/integration-loader";document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,
|
|
1
|
+
import{executeCustomDirective as e,hasClientDirective as t}from"./custom-directives.js";import{loadIntegrationModule as n,preLitHydration as r,loadHMRAdapter as i}from"virtual:avalon/integration-loader";document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,a):a();function a(){let n=document.querySelectorAll(`[data-framework]`);n.length!==0&&n.forEach(n=>{try{let r=n.dataset.framework,i=n.dataset.condition||`on:client`;if(n.dataset.renderStrategy===`ssr-only`||!o(n,i))return;i===`on:client`?f(n,r):i===`on:visible`?s(n,r):i===`on:interaction`?c(n,r):i===`on:idle`?l(n,r):i.startsWith(`media:`)?u(n,r,i.slice(6)):n.dataset.customDirective||t(i)?e(n,i,()=>{f(n,r)})||(console.warn(`[avalon] Unknown hydration condition: "${i}". Hydrating immediately.`),f(n,r)):f(n,r)}catch(e){console.error(`Error processing island:`,e),p(n,n.dataset.framework||`unknown`,n.dataset.src||`unknown`,e)}})}function o(e,t){if(!t||t===`on:client`)return!0;if(t.startsWith(`media:`)){let e=t.slice(6);try{return globalThis.matchMedia(e).matches}catch(t){return console.error(`Invalid media query:`,e,t),!0}}return t===`on:visible`||t===`on:interaction`||t===`on:idle`||console.warn(`Unknown hydration condition:`,t),!0}function s(e,t){try{let n=new IntersectionObserver(r=>{r[0].isIntersecting&&(f(e,t),n.disconnect())},{rootMargin:`50px`,threshold:0});n.observe(e)}catch(n){console.error(`Failed to setup intersection observer:`,n),f(e,t)}}function c(e,t){let n=[`click`,`touchstart`,`mouseenter`,`focusin`],r=!1,i=()=>{r||(r=!0,n.forEach(t=>{e.removeEventListener(t,i)}),f(e,t))};try{n.forEach(t=>{e.addEventListener(t,i,{once:!0,passive:!0})})}catch(n){console.error(`Failed to setup interaction observer:`,n),f(e,t)}}function l(e,t){try{`requestIdleCallback`in globalThis?globalThis.requestIdleCallback(()=>{f(e,t)},{timeout:5e3}):document.readyState===`complete`?setTimeout(()=>{f(e,t)},200):globalThis.addEventListener(`load`,()=>{setTimeout(()=>{f(e,t)},200)},{once:!0})}catch(n){console.error(`Failed to setup idle callback:`,n),f(e,t)}}function u(e,t,n){try{let r=globalThis.matchMedia(n);if(r.matches){f(e,t);return}let i=n=>{n.matches&&(f(e,t),r.removeEventListener(`change`,i))};r.addEventListener(`change`,i)}catch(r){console.error(`Failed to setup media query:`,n,r),f(e,t)}}function d(e,t){let n=e.default;if(!n){let t=Object.keys(e).filter(e=>e!==`default`);for(let r of t){let t=e[r];if(typeof t==`function`&&t.prototype){n=t;break}}n||=e}if(!n)throw Error(`Component ${t} has no default export`);return n}async function f(e,t){if(e.dataset.hydrated)return;let i=e.dataset.src,a=e.dataset.props;if(!i){console.warn(`Island missing data-src attribute`);return}try{let o=a?JSON.parse(a):{};t===`lit`&&await r();let s=d(await import(i),i);try{let r=await n(t);if(!r.hydrate||typeof r.hydrate!=`function`)throw Error(`Integration ${t} does not export a hydrate function`);await r.hydrate(e,s,o),e.dataset.hydrated=`true`}catch(n){import.meta.env?.DEV&&console.error(`Integration hydration failed for ${t}: ${i}`,n),e.dataset.hydrationStatus=`failed`,e.dataset.hydrationError=n.message,e.dispatchEvent(new CustomEvent(`hydration-error`,{detail:{framework:t,src:i,error:n.message,timestamp:Date.now(),hydrationType:`integration-level`},bubbles:!0}))}}catch(n){console.error(`❌ Critical error hydrating ${t} island ${i}:`,n),p(e,t,i,n)}}function p(e,t,n,r){console.error(`Hydration error for ${t} island:`,{src:n,error:r.message,stack:r.stack}),e.dataset.hydrationStatus=`failed`,e.dataset.renderStrategy=`ssr-only`,e.classList.add(`hydration-failed`),e.dispatchEvent(new CustomEvent(`hydration-error`,{detail:{framework:t,src:n,error:r.message,timestamp:Date.now()},bubbles:!0})),h()&&m(e,t,n,r)}function m(e,t,n,r){let i=document.createElement(`div`);i.className=`hydration-error-indicator`,i.style.cssText=`
|
|
2
2
|
position: absolute;
|
|
3
3
|
top: 0;
|
|
4
4
|
right: 0;
|
|
@@ -11,7 +11,7 @@ import{executeCustomDirective as e,hasClientDirective as t}from"./custom-directi
|
|
|
11
11
|
z-index: 9999;
|
|
12
12
|
cursor: pointer;
|
|
13
13
|
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
|
|
14
|
-
`,i.textContent=`❌ ${t}`,i.title=`Hydration failed: ${n}\n${r.message}\nClick for details`,i.addEventListener(`click`,()=>{alert(`Hydration Error\n\nFramework: ${t}\nComponent: ${n}\n\nError: ${r.message}\n\nStack:\n${r.stack}`)}),globalThis.getComputedStyle(e).position===`static`&&(e.style.position=`relative`),e.appendChild(i)}function
|
|
14
|
+
`,i.textContent=`❌ ${t}`,i.title=`Hydration failed: ${n}\n${r.message}\nClick for details`,i.addEventListener(`click`,()=>{alert(`Hydration Error\n\nFramework: ${t}\nComponent: ${n}\n\nError: ${r.message}\n\nStack:\n${r.stack}`)}),globalThis.getComputedStyle(e).position===`static`&&(e.style.position=`relative`),e.appendChild(i)}function h(){return import.meta.env?.DEV||import.meta.env?.MODE===`development`||globalThis.location?.hostname===`localhost`||globalThis.location?.hostname===`127.0.0.1`}function g(e){let t=e.dataset.framework,n=e.dataset.src;if(!n)return null;let r={framework:t,src:n,props:e.dataset.props,scrollPosition:{x:globalThis.scrollX,y:globalThis.scrollY},focusedElement:document.activeElement?.id||null};try{t===`vue`&&e.__vue__?r.vueData=structuredClone(e.__vue__.$data||{}):t===`svelte`&&e.__svelte__?r.svelteState=e.__svelte__:t===`lit`&&e.tagName?.includes(`-`)&&(e.querySelector(`[data-lit-element]`)||e)._$litElement$&&(r.litProperties={})}catch(e){console.warn(`Failed to preserve island state:`,e)}return r}function _(e,t){if(t)try{if(t.scrollPosition&&globalThis.scrollTo(t.scrollPosition.x,t.scrollPosition.y),t.focusedElement){let e=document.getElementById(t.focusedElement);e&&e.focus()}e.dataset.framework===`vue`&&t.vueData&&e.__vue__&&Object.assign(e.__vue__.$data,t.vueData)}catch(e){console.warn(`Failed to restore island state:`,e)}}async function v(e,t,i,a){let o=e.dataset.props,s=o?JSON.parse(o):{};t===`lit`&&await r();let c=d(await import(i),a),l=await n(t);if(!l.hydrate||typeof l.hydrate!=`function`)throw Error(`Integration ${t} does not export a hydrate function`);l.hydrate(e,c,s),e.dataset.hydrated=`true`}function y(e,t,n,r){let i=e.querySelector(`.hmr-error-indicator`);i&&i.remove();let a=document.createElement(`div`);a.className=`hmr-error-indicator`,a.style.cssText=`
|
|
15
15
|
position: absolute;
|
|
16
16
|
top: 0;
|
|
17
17
|
left: 0;
|
|
@@ -36,4 +36,4 @@ import{executeCustomDirective as e,hasClientDirective as t}from"./custom-directi
|
|
|
36
36
|
cursor: pointer;
|
|
37
37
|
font-size: 14px;
|
|
38
38
|
line-height: 1;
|
|
39
|
-
`,c.onclick=()=>a.remove(),a.appendChild(o),a.appendChild(s),a.appendChild(c),globalThis.getComputedStyle(e).position===`static`&&(e.style.position=`relative`),e.insertBefore(a,e.firstChild)}import.meta.hot&&(import.meta.hot.accept(),import(`./hmr-coordinator.js`).then(async({initializeHMR:e,getHMRCoordinator:t})=>{e();let n=t(),r=new Set;document.querySelectorAll(`[data-framework]`).forEach(e=>{let t=e.dataset.framework;t&&r.add(t)});
|
|
39
|
+
`,c.onclick=()=>a.remove(),a.appendChild(o),a.appendChild(s),a.appendChild(c),globalThis.getComputedStyle(e).position===`static`&&(e.style.position=`relative`),e.insertBefore(a,e.firstChild)}import.meta.hot&&(import.meta.hot.accept(),import(`./hmr-coordinator.js`).then(async({initializeHMR:e,getHMRCoordinator:t})=>{e();let n=t(),r=new Set;document.querySelectorAll(`[data-framework]`).forEach(e=>{let t=e.dataset.framework;t&&r.add(t)});for(let e of r)try{let t=await i(e);t&&n.registerAdapter(e,t)}catch(t){console.warn(`[HMR] Failed to load adapter for ${e}:`,t)}}).catch(e=>{console.error(`[HMR] Failed to initialize:`,e)}),x());async function b(e,t,n,r){try{let{showHMRErrorOverlay:e}=await import(`./hmr-error-overlay.js`);e({framework:t,src:n,error:r,filePath:n})}catch{y(e,t,n,r)}}function x(){if(!import.meta.hot)return;let e=new Map;async function t(e){let t=e.replaceAll(`\\`,`/`),r=document.querySelectorAll(`[data-src*="${t}"], [data-src$="${t}"]`);if(r.length===0){let e=document.querySelectorAll(`[data-src]`);for(let r of e){let e=r.dataset.src;e&&(e.includes(t)||t.includes(e.replace(/^\//,``)))&&await n(r)}return}for(let e of r)await n(e)}async function n(t){let n=t.dataset.framework,r=t.dataset.src;if(!(!r||!n))try{let i=g(t);e.set(r,i),delete t.dataset.hydrated,delete t.dataset.hydrationStatus;let a=t.querySelector(`.hydration-error-indicator`);a&&a.remove();let o=Date.now();await v(t,n,r.includes(`?`)?`${r}&t=${o}`:`${r}?t=${o}`,r);let s=e.get(r);s&&(_(t,s),e.delete(r)),t.dispatchEvent(new CustomEvent(`hmr-update`,{detail:{framework:n,src:r,timestamp:Date.now(),success:!0},bubbles:!0}))}catch(e){console.error(`[HMR] Failed for ${n} island ${r}:`,e),t.dispatchEvent(new CustomEvent(`hmr-error`,{detail:{framework:n,src:r,error:e.message,timestamp:Date.now()},bubbles:!0})),h()&&b(t,n,r,e)}}import.meta.hot.on(`vite:beforeUpdate`,e=>{for(let n of e.updates||[]){let e=n.path||n.acceptedPath;e&&(e.includes(`/islands/`)||e.includes(`\\islands\\`))&&t(e)}}),import.meta.hot.on(`vite:beforeFullReload`,()=>{let e=document.querySelectorAll(`[data-hydrated="true"]`),t={};for(let n of e){let e=n.dataset.src;e&&(t[e]=g(n))}try{sessionStorage.setItem(`__avalon_hmr_states__`,JSON.stringify(t))}catch{}});try{let e=sessionStorage.getItem(`__avalon_hmr_states__`);if(e){let t=JSON.parse(e);sessionStorage.removeItem(`__avalon_hmr_states__`),setTimeout(()=>{for(let[e,n]of Object.entries(t)){let t=document.querySelector(`[data-src="${e}"]`);t&&n&&_(t,n)}},100)}}catch{}}
|
|
@@ -277,7 +277,7 @@ export declare function resolvePresetName(preset: string): string;
|
|
|
277
277
|
/**
|
|
278
278
|
* Default Nitro configuration values
|
|
279
279
|
*/
|
|
280
|
-
export declare const DEFAULT_NITRO_CONFIG: Required<Pick<AvalonNitroConfig, "preset" | "serverDir" | "streaming">>;
|
|
280
|
+
export declare const DEFAULT_NITRO_CONFIG: Required<Pick<AvalonNitroConfig, "preset" | "serverDir" | "streaming" | "compressPublicAssets">>;
|
|
281
281
|
/**
|
|
282
282
|
* Creates a Nitro configuration from Avalon plugin config and Nitro-specific options
|
|
283
283
|
*
|
package/dist/src/nitro/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const DEFAULT_STATIC_ASSETS_CONFIG={publicDir:`public`,buildDir:`dist`,compression:!0,cacheControl:`public, max-age=31536000, immutable`,mutableCacheControl:`public, max-age=0, must-revalidate`,headers:{}};export const VALID_V3_PRESETS=[`node_server`,`node_middleware`,`vercel`,`cloudflare_module`,`cloudflare_pages`,`deno_deploy`,`deno_server`,`netlify`,`netlify_functions`,`netlify_edge`,`aws_lambda`,`azure_swa`,`firebase_functions`,`render_com`,`static`,`browser`];export function resolvePresetName(e){if(VALID_V3_PRESETS.includes(e))return e;throw Error(`Unknown Nitro preset: "${e}". Valid presets: ${VALID_V3_PRESETS.join(`, `)}`)}export const DEFAULT_NITRO_CONFIG={preset:`node_server`,serverDir:`server`,streaming:!0};export function createNitroConfig(t,i){let a=t.pagesDir??i.pagesDir,o=i.layoutsDir,s={streaming:t.streaming??DEFAULT_NITRO_CONFIG.streaming,pagesDir:a,layoutsDir:o};if(t.runtimeConfig&&`nitro`in t.runtimeConfig)throw Error(`The "nitro" key in runtimeConfig is reserved by Nitro v3 and cannot be used.`);let c={avalon:s,...t.runtimeConfig},l={...DEFAULT_STATIC_ASSETS_CONFIG,...t.staticAssets},u=mergeRouteRules(createDefaultStaticAssetRouteRules(l),t.routeRules??{}),d=[{dir:l.publicDir??DEFAULT_STATIC_ASSETS_CONFIG.publicDir,baseURL:`/`,maxAge:0}],f=t.renderer===!1?!1:t.renderer?{...t.renderer}:void 0;return{preset:resolvePresetName(process.env.NITRO_PRESET??t.preset??DEFAULT_NITRO_CONFIG.preset),serverDir:t.serverDir??DEFAULT_NITRO_CONFIG.serverDir,routeRules:u,runtimeConfig:c,publicRuntimeConfig:t.publicRuntimeConfig,renderer:f,compatibilityDate:t.compatibilityDate,traceDeps:t.traceDeps,rolldownConfig:t.rolldownConfig,serverEntry:t.serverEntry,compressPublicAssets:t.compressPublicAssets,publicAssets:d,staticAssets:l,prerender:t.prerender}}export function createDefaultStaticAssetRouteRules(t){let n=t.cacheControl??DEFAULT_STATIC_ASSETS_CONFIG.cacheControl,r=t.mutableCacheControl??DEFAULT_STATIC_ASSETS_CONFIG.mutableCacheControl;return{"/assets/**":{headers:{"Cache-Control":n,...t.headers}},"/islands/**":{headers:{"Cache-Control":n,...t.headers}},"/chunks/**":{headers:{"Cache-Control":n,...t.headers}},"/_nuxt/**":{headers:{"Cache-Control":n,...t.headers}},"/**/*.woff":{headers:{"Cache-Control":n,...t.headers}},"/**/*.woff2":{headers:{"Cache-Control":n,...t.headers}},"/**/*.html":{headers:{"Cache-Control":r,...t.headers}},"/favicon.ico":{headers:{"Cache-Control":`public, max-age=86400`,...t.headers}},"/**/*.css":{headers:{"Cache-Control":r,...t.headers}}}}export function isValidPreset(e){return VALID_V3_PRESETS.includes(e)}export function mergeRouteRules(e,t){let n={...e};for(let[e,r]of Object.entries(t))n[e]?n[e]={...n[e],...r,headers:{...n[e].headers,...r.headers}}:n[e]=r;return n}
|
|
1
|
+
export const DEFAULT_STATIC_ASSETS_CONFIG={publicDir:`public`,buildDir:`dist`,compression:!0,cacheControl:`public, max-age=31536000, immutable`,mutableCacheControl:`public, max-age=0, must-revalidate`,headers:{}};export const VALID_V3_PRESETS=[`node_server`,`node_middleware`,`vercel`,`cloudflare_module`,`cloudflare_pages`,`deno_deploy`,`deno_server`,`netlify`,`netlify_functions`,`netlify_edge`,`aws_lambda`,`azure_swa`,`firebase_functions`,`render_com`,`static`,`browser`];export function resolvePresetName(e){if(VALID_V3_PRESETS.includes(e))return e;throw Error(`Unknown Nitro preset: "${e}". Valid presets: ${VALID_V3_PRESETS.join(`, `)}`)}export const DEFAULT_NITRO_CONFIG={preset:`node_server`,serverDir:`server`,streaming:!0,compressPublicAssets:!0};export function createNitroConfig(t,i){let a=t.pagesDir??i.pagesDir,o=i.layoutsDir,s={streaming:t.streaming??DEFAULT_NITRO_CONFIG.streaming,pagesDir:a,layoutsDir:o};if(t.runtimeConfig&&`nitro`in t.runtimeConfig)throw Error(`The "nitro" key in runtimeConfig is reserved by Nitro v3 and cannot be used.`);let c={avalon:s,...t.runtimeConfig},l={...DEFAULT_STATIC_ASSETS_CONFIG,...t.staticAssets},u=mergeRouteRules(createDefaultStaticAssetRouteRules(l),t.routeRules??{}),d=[{dir:l.publicDir??DEFAULT_STATIC_ASSETS_CONFIG.publicDir,baseURL:`/`,maxAge:0}],f=t.renderer===!1?!1:t.renderer?{...t.renderer}:void 0;return{preset:resolvePresetName(process.env.NITRO_PRESET??t.preset??DEFAULT_NITRO_CONFIG.preset),serverDir:t.serverDir??DEFAULT_NITRO_CONFIG.serverDir,routeRules:u,runtimeConfig:c,publicRuntimeConfig:t.publicRuntimeConfig,renderer:f,compatibilityDate:t.compatibilityDate,traceDeps:t.traceDeps,rolldownConfig:t.rolldownConfig,serverEntry:t.serverEntry,compressPublicAssets:t.compressPublicAssets??DEFAULT_NITRO_CONFIG.compressPublicAssets,publicAssets:d,staticAssets:l,prerender:t.prerender}}export function createDefaultStaticAssetRouteRules(t){let n=t.cacheControl??DEFAULT_STATIC_ASSETS_CONFIG.cacheControl,r=t.mutableCacheControl??DEFAULT_STATIC_ASSETS_CONFIG.mutableCacheControl;return{"/assets/**":{headers:{"Cache-Control":n,...t.headers}},"/islands/**":{headers:{"Cache-Control":n,...t.headers}},"/chunks/**":{headers:{"Cache-Control":n,...t.headers}},"/_nuxt/**":{headers:{"Cache-Control":n,...t.headers}},"/**/*.woff":{headers:{"Cache-Control":n,...t.headers}},"/**/*.woff2":{headers:{"Cache-Control":n,...t.headers}},"/**/*.html":{headers:{"Cache-Control":r,...t.headers}},"/favicon.ico":{headers:{"Cache-Control":`public, max-age=86400`,...t.headers}},"/**/*.css":{headers:{"Cache-Control":r,...t.headers}}}}export function isValidPreset(e){return VALID_V3_PRESETS.includes(e)}export function mergeRouteRules(e,t){let n={...e};for(let[e,r]of Object.entries(t))n[e]?n[e]={...n[e],...r,headers:{...n[e].headers,...r.headers}}:n[e]=r;return n}
|
|
@@ -57,4 +57,6 @@ declare module "virtual:avalon/client-entry" {
|
|
|
57
57
|
|
|
58
58
|
declare module "virtual:avalon/integration-loader" {
|
|
59
59
|
export function loadIntegrationModule(framework: string): Promise<unknown>;
|
|
60
|
+
export function preLitHydration(): Promise<void>;
|
|
61
|
+
export function loadHMRAdapter(framework: string): Promise<unknown>;
|
|
60
62
|
}
|
|
@@ -7,11 +7,11 @@ export default { loadPage, routes: [] };
|
|
|
7
7
|
`}}function P(){return`export const islandManifest = { islands: {}, clientEntry: "", css: [] };
|
|
8
8
|
export default islandManifest;
|
|
9
9
|
`}function F(e,t){let n={avalon:{streaming:t.streaming??!0,pagesDir:e.pagesDir,layoutsDir:e.layoutsDir,isDev:e.isDev},...t.runtimeConfig};return`export const runtimeConfig = ${JSON.stringify(n,null,2)};\nexport function useRuntimeConfig() { return runtimeConfig; }\nexport default runtimeConfig;\n`}export function generateConfigModule(e,t){let n={streaming:t.streaming??!0,pagesDir:e.pagesDir,layoutsDir:e.layoutsDir,isDev:e.isDev,...t.runtimeConfig};return`const config = ${JSON.stringify(n,null,2)};\nexport function useAvalonConfig() { return config; }\nexport default config;\n`}async function I(e){let{getAllLayoutDirs:t}=await import(`./module-discovery.js`),{relative:n,resolve:r}=await import(`node:path`),{stat:a}=await import(`node:fs/promises`),o=process.cwd(),s=await t(e.layoutsDir,e.modules,o),c=[],l=0,u=r(o,e.layoutsDir);for(let{dir:t,prefix:r}of s){let s=i(t,`_layout.tsx`);try{if(!(await a(s)).isFile())continue}catch{continue}let d=n(o,s).replaceAll(`\\`,`/`),f=d.startsWith(`/`)?d:`/`+d,p=t.startsWith(u),m=p&&!e.modules?`RootLayout`:`Layout_${l}`;c.push({prefix:r,importPath:f,varName:m,isShared:p}),l++}let d=c.filter(e=>e.isShared),f=c.filter(e=>!e.isShared),p=c.map(e=>`import ${e.varName} from '${e.importPath}';`),m=f.sort((e,t)=>t.prefix.length-e.prefix.length).map(e=>{let t=e.prefix===`/`;return` { prefix: ${JSON.stringify(e.prefix)}, Layout: ${e.varName}, skipRoot: ${t} }`}),h=d.length>0?d[0].varName:`null`;return[`// Auto-generated by Avalon — do not edit`,`import { h } from 'preact';`,`import preactRenderToString from 'preact-render-to-string';`,`import { getUniversalCSSForHead } from '@useavalon/avalon/islands/universal-css-collector';`,`import { getUniversalHeadForInjection } from '@useavalon/avalon/islands/universal-head-collector';`,...p,``,`const RootLayoutComponent = ${h};`,``,`const moduleLayouts = [`,m.join(`,
|
|
10
|
-
`),`];`,``,`function getLayoutsForPath(pathname) {`,` for (const entry of moduleLayouts) {`,` if (entry.prefix === '/' ? pathname === '/' : pathname.startsWith(entry.prefix)) {`,` return entry;`,` }`,` }`,` return null;`,`}`,``,`function injectUniversalAssets(html) {`,` const universalCSS = getUniversalCSSForHead(true);`,` if (universalCSS && html.includes('</head>')) {`,` html = html.replace('</head>', universalCSS + '\\n</head>');`,` }`,` const universalHead = getUniversalHeadForInjection(true);`,` if (universalHead && html.includes('</head>')) {`,` html = html.replace('</head>', universalHead + '\\n</head>');`,` }`,` return html;`,`}`,``,`export async function wrapWithLayouts(pageHtml, pageModule, context, injectAssets) {`,` const pathname = context.url.pathname;`,` const frontmatter = {`,` ...(pageModule.frontmatter || {}),`,` ...(pageModule.metadata || {}),`,` currentPath: pathname,`,` };`,` const pageLayoutConfig = pageModule.layoutConfig;`,` const skipAll = pageLayoutConfig?.skipLayouts?.includes('_layout');`,``,` const layoutEntry = getLayoutsForPath(pathname);`,` const routeInfo = { path: pathname, params: context.params, query: context.url.searchParams };`,` let html;`,``,` if (!layoutEntry || skipAll) {`,` const title = String(frontmatter.title || 'Avalon');`,`
|
|
10
|
+
`),`];`,``,`function getLayoutsForPath(pathname) {`,` for (const entry of moduleLayouts) {`,` if (entry.prefix === '/' ? pathname === '/' : pathname.startsWith(entry.prefix)) {`,` return entry;`,` }`,` }`,` return null;`,`}`,``,`function injectUniversalAssets(html) {`,` const universalCSS = getUniversalCSSForHead(true);`,` if (universalCSS && html.includes('</head>')) {`,` html = html.replace('</head>', universalCSS + '\\n</head>');`,` }`,` const universalHead = getUniversalHeadForInjection(true);`,` if (universalHead && html.includes('</head>')) {`,` html = html.replace('</head>', universalHead + '\\n</head>');`,` }`,` return html;`,`}`,``,`export async function wrapWithLayouts(pageHtml, pageModule, context, injectAssets) {`,` const pathname = context.url.pathname;`,` const frontmatter = {`,` ...(pageModule.frontmatter || {}),`,` ...(pageModule.metadata || {}),`,` currentPath: pathname,`,` };`,` const pageLayoutConfig = pageModule.layoutConfig;`,` const skipAll = pageLayoutConfig?.skipLayouts?.includes('_layout');`,``,` const layoutEntry = getLayoutsForPath(pathname);`,` const routeInfo = { path: pathname, params: context.params, query: context.url.searchParams };`,` let html;`,``,` if (!layoutEntry || skipAll) {`,` if (RootLayoutComponent && !skipAll) {`,` const rootProps = {`,` children: h('div', { id: 'app', dangerouslySetInnerHTML: { __html: pageHtml } }),`,` frontmatter,`,` data: {},`,` route: routeInfo,`,` };`,` const rootResult = RootLayoutComponent(rootProps);`,` const resolvedRoot = rootResult instanceof Promise ? await rootResult : rootResult;`,` html = '<!DOCTYPE html>\\n' + preactRenderToString(resolvedRoot);`,` } else {`,` const title = String(frontmatter.title || 'Avalon');`,` html = [`,` '<!DOCTYPE html>',`,` '<html lang="en">',`,` '<head>',`,` '<meta charset="utf-8">',`,` '<meta name="viewport" content="width=device-width, initial-scale=1">',`,` '<title>' + title + '</title>',`,` '</head>',`,` '<body>',`,` '<div id="app">' + pageHtml + '</div>',`,` '</body>',`,` '</html>',`,` ].join('\\n');`,` }`,` } else {`,` const layoutProps = {`,` children: h('div', { dangerouslySetInnerHTML: { __html: pageHtml } }),`,` frontmatter,`,` data: {},`,` route: routeInfo,`,` };`,` const layoutResult = layoutEntry.Layout(layoutProps);`,` const resolvedLayout = layoutResult instanceof Promise ? await layoutResult : layoutResult;`,` let wrappedHtml = preactRenderToString(resolvedLayout);`,``,` if (!layoutEntry.skipRoot && RootLayoutComponent) {`,` const rootProps = {`,` children: h('div', { dangerouslySetInnerHTML: { __html: wrappedHtml } }),`,` frontmatter,`,` data: {},`,` route: routeInfo,`,` };`,` const rootResult = RootLayoutComponent(rootProps);`,` const resolvedRoot = rootResult instanceof Promise ? await rootResult : rootResult;`,` wrappedHtml = preactRenderToString(resolvedRoot);`,` }`,``,` html = '<!DOCTYPE html>\\n' + wrappedHtml;`,` }`,``,` if (injectAssets) {`,` html = injectAssets(html);`,` }`,` return injectUniversalAssets(html);`,`}`,``,`export default { wrapWithLayouts };`,``].join(`
|
|
11
11
|
`)}function L(e){let t=e.clientEntry??`app/entry-client`;return[`// Auto-generated by Avalon — do not edit`,`// @ts-ignore — virtual import resolved by Nitro's Vite assets plugin at build time`,`import clientAssets from '${t.startsWith(`/`)?t:`/`+t}?assets=client';`,``,`function buildAssetTags() {`,` const cssLinks = (clientAssets?.css ?? [])`,` .map(attr => '<link rel="stylesheet" href="' + attr.href + '">')`,` .join('\\n');`,` const jsPreloads = (clientAssets?.js ?? [])`,` .map(attr => '<link rel="modulepreload" href="' + attr.href + '">')`,` .join('\\n');`,` const entryScript = clientAssets?.entry`,` ? '<script type="module" src="' + clientAssets.entry + '"><\/script>'`,` : '';`,` return { cssLinks, jsPreloads, entryScript };`,`}`,``,`export function injectAssets(html) {`,` const { cssLinks, jsPreloads, entryScript } = buildAssetTags();`,` if (html.includes('</head>')) {`,` html = html.replace('</head>', cssLinks + '\\n' + jsPreloads + '\\n</head>');`,` }`,` if (html.includes('</body>')) {`,` html = html.replace('</body>', entryScript + '\\n</body>');`,` }`,` return html;`,`}`,``,`export { clientAssets };`,`export default { injectAssets, clientAssets };`,``].join(`
|
|
12
12
|
`)}function R(e){let t=Array.isArray(e.integrations)?e.integrations:[],n=[],r=[];for(let e of t){let t=`${e}Integration`;n.push(`import { ${t} } from '@useavalon/${e}';`),r.push(`registry.register(${t});`)}return[`// Auto-generated by Avalon — do not edit`,`import { createNitroRenderer } from '@useavalon/avalon/nitro/renderer';`,`import { registerBuiltinDirectives } from '@useavalon/avalon';`,`import { registry } from '@useavalon/avalon/islands/integration-registry';`,`import avalonConfig from 'virtual:avalon/config';`,`import { loadPage } from 'virtual:avalon/page-loader';`,`import { wrapWithLayouts } from 'virtual:avalon/layouts';`,`import { injectAssets } from 'virtual:avalon/assets';`,...n,``,`// Pre-register framework integrations for SSR`,...r,``,`// Register built-in custom hydration directives (on:delay, on:scroll, etc.)`,`registerBuiltinDirectives();`,``,`export default createNitroRenderer({`,` avalonConfig,`,` isDev: avalonConfig.isDev,`,` resolvePageRoute: async (pathname) => {`,` const mod = loadPage(pathname);`,` if (!mod || !('default' in mod)) return null;`,` return { filePath: '[virtual:' + pathname + ']', pattern: pathname, params: {} };`,` },`,` loadPageModule: async (filePath) => {`,` const match = filePath.match(/^\\[virtual:(.+)\\]$/);`,` const pathname = match ? match[1] : filePath;`,` const mod = loadPage(pathname);`,` if (mod) return mod;`,` return { default: () => null, metadata: { title: 'Avalon' } };`,` },`,` wrapWithLayouts: (pageHtml, pageModule, context) =>`,` wrapWithLayouts(pageHtml, pageModule, context, injectAssets),`,`});`,``].join(`
|
|
13
13
|
`)}async function z(e,t){let{getAllLayoutDirs:n}=await import(`./module-discovery.js`),{readdir:r}=await import(`node:fs/promises`),{relative:i,join:a}=await import(`node:path`),o=process.cwd(),s=await n(e.layoutsDir,e.modules,o),c=[];for(let{dir:e}of s)try{let t=await r(e,{withFileTypes:!0});for(let n of t){if(!n.isFile()||!n.name.endsWith(`.css`))continue;let t=i(o,a(e,n.name)).replaceAll(`\\`,`/`),r=t.startsWith(`/`)?t:`/`+t;c.push(r)}}catch{}let l=[`// Auto-generated by Avalon — do not edit`,`// Island hydration runtime`,`import '@useavalon/avalon/client/main';`,``],u=t.globalCSS??[];for(let e of u){let t=e.startsWith(`/`)?e:`/`+e;l.push(`// Global CSS`),l.push(`import '${t}';`)}if(u.length>0&&l.push(``),c.length>0){l.push(`// Layout CSS (auto-discovered)`);for(let e of c)l.push(`import '${e}';`)}return l.push(``),l.join(`
|
|
14
|
-
`)}function B(e){let t=(e.integrations??[]).map(e=>typeof e==`string`?e:e.name),n={preact:`@useavalon/preact/client`,react:`@useavalon/preact/client`,vue:`@useavalon/vue/client`,svelte:`@useavalon/svelte/client`,solid:`@useavalon/solid/client`,lit:`@useavalon/lit/client`,qwik:`@useavalon/qwik/client`},r=[`// Auto-generated by Avalon — only includes configured integrations
|
|
14
|
+
`)}function B(e){let t=(e.integrations??[]).map(e=>typeof e==`string`?e:e.name),n={preact:`@useavalon/preact/client`,react:`@useavalon/preact/client`,vue:`@useavalon/vue/client`,svelte:`@useavalon/svelte/client`,solid:`@useavalon/solid/client`,lit:`@useavalon/lit/client`,qwik:`@useavalon/qwik/client`},r={preact:`@useavalon/preact/client/hmr`,react:`@useavalon/react/client/hmr`,vue:`@useavalon/vue/client/hmr`,svelte:`@useavalon/svelte/client/hmr`,solid:`@useavalon/solid/client/hmr`,lit:`@useavalon/lit/client/hmr`,qwik:`@useavalon/qwik/client/hmr`},i=t.includes(`lit`),a=[`// Auto-generated by Avalon — only includes configured integrations`,``,`// --- loadIntegrationModule ---`,`export async function loadIntegrationModule(framework) {`,` switch (framework) {`];for(let e of t){let t=n[e];t&&(e===`react`?a.push(` case "react":`):e===`preact`?(a.push(` case "preact":`),a.push(` return import("${t}");`)):(a.push(` case "${e}":`),a.push(` return import("${t}");`)))}t.includes(`react`)&&!t.includes(`preact`)&&a.push(` return import("${n.react}");`),a.push(` default:`),a.push(" throw new Error(`Unknown or unconfigured framework: ${framework}`);"),a.push(` }`),a.push(`}`),a.push(``),a.push(`// --- Lit hydration pre-load (only if Lit is configured) ---`),i?(a.push(`export async function preLitHydration() {`),a.push(` await import("@useavalon/lit/client");`),a.push(`}`)):a.push(`export async function preLitHydration() {}`),a.push(``),a.push(`// --- HMR adapter loader ---`),a.push(`export async function loadHMRAdapter(framework) {`),a.push(` switch (framework) {`);for(let e of t){let t=r[e];t&&(a.push(` case "${e}":`),a.push(` return import("${t}").then(m => m.${e}Adapter);`))}return a.push(` default: return null;`),a.push(` }`),a.push(`}`),a.join(`
|
|
15
15
|
`)}export function getViteDevServer(){return globalThis.__viteDevServer}export function getAvalonConfig(){return globalThis.__avalonConfig}export function isDevelopmentMode(){return globalThis.__avalonConfig?.isDev??!0}const V=`<!--AVALON_STREAM_BOUNDARY-->`;let H=null,U=null;async function W(e,t,n,r){if(!n.modules)return!1;let i=t.split(`?`)[0],a=await Y(i,n,e);if(!a)return!1;try{let t=await e.ssrLoadModule(a),n=t.default;if(!n)return!1;let o=t.layoutConfig,l=await _(e,a),u=await J(i,e),d=[];for(let t of u){let n=await e.ssrLoadModule(t);d.push({file:t,module:n})}for(let t of u){let n=await _(e,t);l.push(...n)}if(d.length===0)return!1;let{render:f}=await e.ssrLoadModule(`preact-render-to-string`),{h:p}=await e.ssrLoadModule(`preact`),m=o?.skipLayouts||[],h=d.filter(({file:e})=>{let t=e.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``;return!m.includes(t)}),g=t.frontmatter,v=t.metadata,y={children:null,frontmatter:{...g,...v,currentPath:i},params:{},url:i},b=[],x=[];for(let e of h){let t=e.module.default;if(!(!t||typeof t!=`function`))try{let n=t({...y,children:p(`div`,null,`test`)}),r=f(n instanceof Promise?await n:n);r.trim().startsWith(`<html`)||r.includes(`<!DOCTYPE`)?b.push(e):x.push(e)}catch{x.push(e)}}if(b.length===0)return!1;let{module:S}=b[b.length-1],C=S.default;if(!C||typeof C!=`function`)return!1;let w;try{let e=C({...y,children:p(`div`,{dangerouslySetInnerHTML:{__html:V}})});w=f(e instanceof Promise?await e:e)}catch{return!1}let T=w.indexOf(V);if(T===-1)return!1;let E=w.slice(0,T),D=w.slice(T+29),O=E;if(l.length>0){let e=`<style data-avalon-ssr-css>${l.join(`
|
|
16
16
|
`)}</style>`;O=E.includes(`</head>`)?E.replace(`</head>`,`${e}\n</head>`):E+e}O.trim().toLowerCase().startsWith(`<!doctype`)||(O=`<!DOCTYPE html>
|
|
17
17
|
`+O);let k=s(!0);k&&O.includes(`</head>`)&&(O=O.replace(`</head>`,`${k}\n</head>`));let A=c(!0);A&&O.includes(`</head>`)&&(O=O.replace(`</head>`,`${A}\n</head>`)),r.statusCode=200,r.setHeader(`Content-Type`,`text/html; charset=utf-8`),r.setHeader(`Transfer-Encoding`,`chunked`),r.setHeader(`X-Avalon-Streaming`,`1`),r.flushHeaders(),r.write(O);let j;try{let e=typeof n==`function`?n():n;j=f(e instanceof Promise?await e:e)}catch(e){console.error(`[SSR Streaming] Error rendering page component:`,e),j=`<div>Error rendering page</div>`}if(j.trim().startsWith(`<!DOCTYPE html>`)||j.trim().startsWith(`<html`))return r.end(j),!0;let M=j;for(let{module:e}of x){let t=e.default;if(!(!t||typeof t!=`function`))try{let e=t({...y,children:p(`div`,{dangerouslySetInnerHTML:{__html:M}})});M=f(e instanceof Promise?await e:e)}catch(e){console.error(`[SSR Streaming] Error rendering wrapper layout:`,e)}}let N=M+D;if(!N.includes(`/src/client/main.js`)&&!N.includes(`/@vite/client`)){let e=N.lastIndexOf(`</body>`);e!==-1&&(N=N.slice(0,e)+`
|