// @bun
var __create = Object.create;
var __getProtoOf = Object.getPrototypeOf;
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __hasOwnProp = Object.prototype.hasOwnProperty;
function __accessProp(key) {
  return this[key];
}
var __toESMCache_node;
var __toESMCache_esm;
var __toESM = (mod, isNodeMode, target) => {
  var canCache = mod != null && typeof mod === "object";
  if (canCache) {
    var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
    var cached = cache.get(mod);
    if (cached)
      return cached;
  }
  target = mod != null ? __create(__getProtoOf(mod)) : {};
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
  for (let key of __getOwnPropNames(mod))
    if (!__hasOwnProp.call(to, key))
      __defProp(to, key, {
        get: __accessProp.bind(mod, key),
        enumerable: true
      });
  if (canCache)
    cache.set(mod, to);
  return to;
};
var __toCommonJS = (from) => {
  var entry = (__moduleCache ??= new WeakMap).get(from), desc;
  if (entry)
    return entry;
  entry = __defProp({}, "__esModule", { value: true });
  if (from && typeof from === "object" || typeof from === "function") {
    for (var key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(entry, key))
        __defProp(entry, key, {
          get: __accessProp.bind(from, key),
          enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
        });
  }
  __moduleCache.set(from, entry);
  return entry;
};
var __moduleCache;
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
var __returnValue = (v) => v;
function __exportSetter(name, newValue) {
  this[name] = __returnValue.bind(null, newValue);
}
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, {
      get: all[name],
      enumerable: true,
      configurable: true,
      set: __exportSetter.bind(all, name)
    });
};
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
    r = Reflect.decorate(decorators, target, key, desc);
  else
    for (var i = decorators.length - 1;i >= 0; i--)
      if (d = decorators[i])
        r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __legacyMetadataTS = (k, v) => {
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
    return Reflect.metadata(k, v);
};
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
var __require = import.meta.require;

// src/constants.ts
var ANGULAR_INIT_TIMEOUT_MS = 500, ANSI_ESCAPE_LENGTH = 3, ASCII_SPACE = 32, BASE_36_RADIX = 36, BUN_BUILD_WARNING_SUPPRESSION = "wildcard sideEffects are not supported yet", BODY_SLICE_LENGTH = 2000, BYTES_PER_KILOBYTE = 1024, CLI_ARGS_OFFSET = 3, CSS_ERROR_RESOLVE_DELAY_MS = 50, CSS_MAX_CHECK_ATTEMPTS = 10, CSS_MAX_PARSE_TIMEOUT_MS = 500, CSS_SHEET_READY_TIMEOUT_MS = 100, DEFAULT_CHUNK_SIZE = 16384, DEFAULT_DEBOUNCE_MS = 15, DEFAULT_PORT = 3000, DEV_SERVER_RESTART_DEBOUNCE_MS = 100, DOM_UPDATE_DELAY_MS = 50, FILE_PROTOCOL_PREFIX_LENGTH = 7, FOCUS_ID_PREFIX_LENGTH = 3, FOCUS_IDX_PREFIX_LENGTH = 4, FOCUS_NAME_PREFIX_LENGTH = 5, HMR_UPDATE_TIMEOUT_MS = 2000, HOOK_SIGNATURE_LENGTH = 12, EXCLUDE_LAST_OFFSET = -1, HOURS_IN_DAY = 24, HOURS_IN_HALF_DAY = 12, MAX_ERROR_LENGTH = 200, MAX_RECONNECT_ATTEMPTS = 60, MILLISECONDS_IN_A_SECOND = 1000, MINUTES_IN_AN_HOUR = 60, SECONDS_IN_A_MINUTE = 60, MILLISECONDS_IN_A_MINUTE, MILLISECONDS_IN_A_DAY, OVERLAY_FADE_DURATION_MS = 150, PING_INTERVAL_MS = 30000, RAF_BATCH_COUNT = 3, RANDOM_ID_END_INDEX = 11, REBUILD_BATCH_DELAY_MS = 10, REBUILD_RELOAD_DELAY_MS = 200, RECONNECT_INITIAL_DELAY_MS = 500, RECONNECT_POLL_INTERVAL_MS = 300, SIGINT_EXIT_CODE = 130, SIGTERM_EXIT_CODE = 143, SVELTE_CSS_LOAD_TIMEOUT_MS = 500, TIME_PRECISION = 2, TWO_THIRDS, UNFOUND_INDEX = -1, WEBSOCKET_NORMAL_CLOSURE = 1000;
var init_constants = __esm(() => {
  MILLISECONDS_IN_A_MINUTE = MILLISECONDS_IN_A_SECOND * SECONDS_IN_A_MINUTE;
  MILLISECONDS_IN_A_DAY = MILLISECONDS_IN_A_SECOND * SECONDS_IN_A_MINUTE * MINUTES_IN_AN_HOUR * HOURS_IN_DAY;
  TWO_THIRDS = 2 / 3;
});

// src/core/islandPageContext.ts
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) => {
  const manifestScript = `<script>window.__ABSOLUTE_MANIFEST__ = ${JSON.stringify(manifest)}</script>`;
  const islandStateScript = `<script>window.__ABS_ISLAND_STATE__ = ${JSON.stringify(globalThis.__ABS_ISLAND_STATE__ ?? {})}</script>`;
  const bootstrapPath = manifest[BOOTSTRAP_MANIFEST_KEY];
  const bootstrapScript = bootstrapPath ? `<script type="module" src="${bootstrapPath}"></script>` : "";
  return `${manifestScript}${islandStateScript}${bootstrapScript}`;
}, injectHeadMarkup = (html, markup) => {
  const closingHeadIndex = html.indexOf("</head>");
  if (closingHeadIndex >= 0) {
    return `${html.slice(0, closingHeadIndex)}${markup}${html.slice(closingHeadIndex)}`;
  }
  const openingBodyIndex = html.indexOf("<body");
  if (openingBodyIndex >= 0) {
    const bodyStart = html.indexOf(">", openingBodyIndex);
    if (bodyStart >= 0) {
      return `${html.slice(0, openingBodyIndex)}<head>${markup}</head>${html.slice(openingBodyIndex)}`;
    }
  }
  return `<!DOCTYPE html><html><head>${markup}</head><body>${html}</body></html>`;
}, streamChunkToString = (value, decoder) => typeof value === "string" ? value : decoder.decode(value, { stream: true }), pipeStreamWithHeadInjection = (stream, markup) => {
  const encoder = new TextEncoder;
  const decoder = new TextDecoder;
  const lookbehind = CLOSING_HEAD_TAG.length - 1;
  return new ReadableStream({
    async start(controller) {
      const reader = stream.getReader();
      let injected = false;
      let pending = "";
      try {
        for (;; ) {
          const { done, value } = await reader.read();
          if (done)
            break;
          if (!value)
            continue;
          pending += streamChunkToString(value, decoder);
          if (injected) {
            controller.enqueue(encoder.encode(pending));
            pending = "";
            continue;
          }
          const headIndex = pending.indexOf(CLOSING_HEAD_TAG);
          if (headIndex >= 0) {
            const next = `${pending.slice(0, headIndex)}${markup}${pending.slice(headIndex)}`;
            controller.enqueue(encoder.encode(next));
            pending = "";
            injected = true;
            continue;
          }
          if (pending.length > lookbehind) {
            const safeText = pending.slice(0, pending.length - lookbehind);
            controller.enqueue(encoder.encode(safeText));
            pending = pending.slice(-lookbehind);
          }
        }
        pending += decoder.decode();
        if (!injected) {
          pending = injectHeadMarkup(pending, markup);
        }
        if (pending.length > 0) {
          controller.enqueue(encoder.encode(pending));
        }
        controller.close();
      } catch (error) {
        controller.error(error);
      }
    }
  });
}, pipeStreamWithIslandMarkerDetection = (stream, markup) => {
  const encoder = new TextEncoder;
  const decoder = new TextDecoder;
  const lookbehind = Math.max(ISLAND_MARKER.length, 1024);
  return new ReadableStream({
    async start(controller) {
      const reader = stream.getReader();
      let injected = false;
      let pending = "";
      try {
        for (;; ) {
          const { done, value } = await reader.read();
          if (done)
            break;
          if (!value)
            continue;
          pending += streamChunkToString(value, decoder);
          if (injected) {
            controller.enqueue(encoder.encode(pending));
            pending = "";
            continue;
          }
          const markerIndex = pending.indexOf(ISLAND_MARKER);
          if (markerIndex >= 0) {
            const tagStart = pending.lastIndexOf("<", markerIndex);
            const injectAt = tagStart >= 0 ? tagStart : markerIndex;
            const next = `${pending.slice(0, injectAt)}${markup}${pending.slice(injectAt)}`;
            controller.enqueue(encoder.encode(next));
            pending = "";
            injected = true;
            continue;
          }
          if (pending.length > lookbehind) {
            const safeText = pending.slice(0, pending.length - lookbehind);
            controller.enqueue(encoder.encode(safeText));
            pending = pending.slice(-lookbehind);
          }
        }
        pending += decoder.decode();
        if (pending.length > 0) {
          controller.enqueue(encoder.encode(pending));
        }
        controller.close();
      } catch (error) {
        controller.error(error);
      }
    }
  });
}, htmlContainsIslands = (html) => html.includes(ISLAND_MARKER), injectIslandPageContext = (html, options) => {
  const manifest = globalThis.__absoluteManifest;
  const hasIslands = options?.hasIslands ?? htmlContainsIslands(html);
  if (!manifest || !hasIslands) {
    return html;
  }
  if (html.includes(MANIFEST_MARKER) || html.includes(ISLAND_STATE_MARKER)) {
    return html;
  }
  return injectHeadMarkup(html, buildIslandsHeadMarkup(manifest));
}, injectIslandPageContextStream = (stream, options) => {
  const manifest = globalThis.__absoluteManifest;
  if (!manifest)
    return stream;
  const markup = buildIslandsHeadMarkup(manifest);
  if (options?.hasIslands === true) {
    return pipeStreamWithHeadInjection(stream, markup);
  }
  if (options?.hasIslands === false) {
    return stream;
  }
  return pipeStreamWithIslandMarkerDetection(stream, markup);
}, setCurrentIslandManifest = (manifest) => {
  globalThis.__absoluteManifest = manifest;
};

// src/utils/ssrErrorPage.ts
var ssrErrorPage = (framework, error) => {
  const frameworkColors = {
    angular: "#dd0031",
    html: "#e34c26",
    htmx: "#1a365d",
    react: "#61dafb",
    svelte: "#ff3e00",
    vue: "#42b883"
  };
  const accent = frameworkColors[framework] ?? "#94a3b8";
  const label = framework.charAt(0).toUpperCase() + framework.slice(1);
  const message = error instanceof Error ? error.message : String(error);
  return `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SSR Error - AbsoluteJS</title>
<style>
*{margin:0;padding:0;box-sizing:border-box}
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}
.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}
.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)}
.brand{font-weight:700;font-size:20px;color:#fff;letter-spacing:-0.02em}
.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)}
.kind{color:#94a3b8;font-size:13px;font-weight:500}
.content{padding:24px}
.label{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:0.08em;color:#94a3b8;margin-bottom:8px}
.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}
.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}
</style>
</head>
<body>
<div class="card">
<div class="header">
<div style="display:flex;align-items:center;gap:12px">
<span class="brand">AbsoluteJS</span>
<span class="badge">${label}</span>
</div>
<span class="kind">Server Render Error</span>
</div>
<div class="content">
<div class="label">What went wrong</div>
<pre class="message">${message.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")}</pre>
<div class="hint">A component threw during server-side rendering. Check the terminal for the full stack trace.</div>
</div>
</div>
</body>
</html>`;
};

// src/utils/stringModifiers.ts
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) => {
  if (!str.includes("-") && !str.includes("_")) {
    return str.charAt(0).toUpperCase() + str.slice(1);
  }
  return normalizeSlug(str).split(/[-_]/).filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1).toLowerCase()).join("");
}, toScreamingSnake = (str) => str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toUpperCase();

// src/utils/resolveConvention.ts
import { basename } from "path";
var CONVENTIONS_KEY = "__absoluteConventions", isConventionsMap = (value) => Boolean(value) && typeof value === "object", getMap = () => {
  const value = Reflect.get(globalThis, CONVENTIONS_KEY);
  if (isConventionsMap(value))
    return value;
  const empty = {};
  return empty;
}, derivePageName = (pagePath) => {
  const base = basename(pagePath);
  const dotIndex = base.indexOf(".");
  const name = dotIndex > 0 ? base.slice(0, dotIndex) : base;
  return toPascal(name);
}, resolveErrorConventionPath = (framework, pageName) => {
  const conventions = getMap()[framework];
  if (!conventions)
    return;
  return conventions.pages?.[pageName]?.error ?? conventions.defaults?.error;
}, resolveNotFoundConventionPath = (framework) => getMap()[framework]?.defaults?.notFound, setConventions = (map) => {
  Reflect.set(globalThis, CONVENTIONS_KEY, map);
}, isDev = () => true, buildErrorProps = (error) => {
  const message = error instanceof Error ? error.message : String(error);
  const stack = isDev() && error instanceof Error ? error.stack : undefined;
  return { error: { message, stack } };
}, renderReactError = async (conventionPath, errorProps) => {
  const { createElement } = await import("react");
  const { renderToReadableStream } = await import("react-dom/server");
  const mod = await import(conventionPath);
  const [firstKey] = Object.keys(mod);
  const ErrorComponent = mod.default ?? (firstKey ? mod[firstKey] : undefined);
  const element = createElement(ErrorComponent, errorProps);
  const stream = await renderToReadableStream(element);
  return new Response(stream, {
    headers: { "Content-Type": "text/html" },
    status: 500
  });
}, renderSvelteError = async (conventionPath, errorProps) => {
  const { render } = await import("svelte/server");
  const mod = await import(conventionPath);
  const ErrorComponent = mod.default;
  const { head, body } = render(ErrorComponent, {
    props: errorProps
  });
  const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
  return new Response(html, {
    headers: { "Content-Type": "text/html" },
    status: 500
  });
}, unescapeVueStyles = (ssrBody) => {
  let styles = "";
  const body = ssrBody.replace(/<style>([\s\S]*?)<\/style>/g, (_, css) => {
    styles += `<style>${css.replace(/&quot;/g, '"').replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">")}</style>`;
    return "";
  });
  return { body, styles };
}, renderVueError = async (conventionPath, errorProps) => {
  const { createSSRApp, h } = await import("vue");
  const { renderToString } = await import("vue/server-renderer");
  const mod = await import(conventionPath);
  const ErrorComponent = mod.default;
  const app = createSSRApp({
    render: () => h(ErrorComponent, errorProps)
  });
  const rawBody = await renderToString(app);
  const { styles, body } = unescapeVueStyles(rawBody);
  const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
  return new Response(html, {
    headers: { "Content-Type": "text/html" },
    status: 500
  });
}, renderAngularError = async (conventionPath, errorProps) => {
  const mod = await import(conventionPath);
  const renderError = mod.default ?? mod.renderError;
  if (typeof renderError !== "function")
    return null;
  const html = renderError(errorProps);
  return new Response(html, {
    headers: { "Content-Type": "text/html" },
    status: 500
  });
}, logConventionRenderError = (framework, label, renderError) => {
  const message = renderError instanceof Error ? renderError.message : "";
  if (message.includes("Cannot find module") || message.includes("Cannot find package") || message.includes("not found in module")) {
    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}).`);
    return;
  }
  console.error(`[SSR] Failed to render ${framework} convention ${label} page:`, renderError);
}, ERROR_RENDERERS, renderConventionError = async (framework, pageName, error) => {
  const conventionPath = resolveErrorConventionPath(framework, pageName);
  if (!conventionPath)
    return null;
  const errorProps = buildErrorProps(error);
  const renderer = ERROR_RENDERERS[framework];
  if (!renderer)
    return null;
  try {
    return await renderer(conventionPath, errorProps);
  } catch (renderError) {
    logConventionRenderError(framework, "error", renderError);
  }
  return null;
}, renderReactNotFound = async (conventionPath) => {
  const { createElement } = await import("react");
  const { renderToReadableStream } = await import("react-dom/server");
  const mod = await import(conventionPath);
  const [nfKey] = Object.keys(mod);
  const NotFoundComponent = mod.default ?? (nfKey ? mod[nfKey] : undefined);
  const element = createElement(NotFoundComponent);
  const stream = await renderToReadableStream(element);
  return new Response(stream, {
    headers: { "Content-Type": "text/html" },
    status: 404
  });
}, renderSvelteNotFound = async (conventionPath) => {
  const { render } = await import("svelte/server");
  const mod = await import(conventionPath);
  const NotFoundComponent = mod.default;
  const { head, body } = render(NotFoundComponent);
  const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
  return new Response(html, {
    headers: { "Content-Type": "text/html" },
    status: 404
  });
}, renderVueNotFound = async (conventionPath) => {
  const { createSSRApp, h } = await import("vue");
  const { renderToString } = await import("vue/server-renderer");
  const mod = await import(conventionPath);
  const NotFoundComponent = mod.default;
  const app = createSSRApp({
    render: () => h(NotFoundComponent)
  });
  const rawBody = await renderToString(app);
  const { styles, body } = unescapeVueStyles(rawBody);
  const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
  return new Response(html, {
    headers: { "Content-Type": "text/html" },
    status: 404
  });
}, renderAngularNotFound = async (conventionPath) => {
  const mod = await import(conventionPath);
  const renderNotFound = mod.default ?? mod.renderNotFound;
  if (typeof renderNotFound !== "function")
    return null;
  const html = renderNotFound();
  return new Response(html, {
    headers: { "Content-Type": "text/html" },
    status: 404
  });
}, NOT_FOUND_RENDERERS, renderConventionNotFound = async (framework) => {
  const conventionPath = resolveNotFoundConventionPath(framework);
  if (!conventionPath)
    return null;
  const renderer = NOT_FOUND_RENDERERS[framework];
  if (!renderer)
    return null;
  try {
    return await renderer(conventionPath);
  } catch (renderError) {
    logConventionRenderError(framework, "not-found", renderError);
  }
  return null;
}, NOT_FOUND_PRIORITY, renderFirstNotFound = async () => {
  for (const framework of NOT_FOUND_PRIORITY) {
    if (!getMap()[framework]?.defaults?.notFound)
      continue;
    const response = await renderConventionNotFound(framework);
    if (response)
      return response;
  }
  return null;
};
var init_resolveConvention = __esm(() => {
  ERROR_RENDERERS = {
    angular: renderAngularError,
    react: renderReactError,
    svelte: renderSvelteError,
    vue: renderVueError
  };
  NOT_FOUND_RENDERERS = {
    angular: renderAngularNotFound,
    react: renderReactNotFound,
    svelte: renderSvelteNotFound,
    vue: renderVueNotFound
  };
  NOT_FOUND_PRIORITY = [
    "react",
    "svelte",
    "vue",
    "angular"
  ];
});

// src/vue/pageHandler.ts
import { readdir } from "fs/promises";
import { basename as basename2, dirname } from "path";
var ssrDirty = false, isRecord = (value) => typeof value === "object" && value !== null, isGenericVueComponent = (value) => typeof value === "function" || isRecord(value), readHasIslands = (value) => {
  if (!isRecord(value))
    return false;
  const hasIslands = value["__ABSOLUTE_PAGE_HAS_ISLANDS__"];
  return typeof hasIslands === "boolean" ? hasIslands : false;
}, readDefaultExport = (value) => isRecord(value) ? value.default : undefined, resolveCurrentGeneratedVueModulePath = async (pagePath) => {
  const pageDirectory = dirname(pagePath);
  const expectedPrefix = `${basename2(pagePath, ".js").split(".")[0]}.`;
  try {
    const pageEntries = await readdir(pageDirectory, {
      withFileTypes: true
    });
    const matchingEntry = pageEntries.find((entry) => entry.isFile() && entry.name.endsWith(".js") && (entry.name === `${expectedPrefix.slice(0, EXCLUDE_LAST_OFFSET)}.js` || entry.name.startsWith(expectedPrefix)));
    if (!matchingEntry) {
      return pagePath;
    }
    return `${pageDirectory}/${matchingEntry.name}`;
  } catch {
    return pagePath;
  }
}, buildDirtyResponse = (headTag, indexPath, maybeProps) => {
  const propsScript = `window.__INITIAL_PROPS__=${JSON.stringify(maybeProps ?? {})};`;
  const dirtyFlag = "window.__SSR_DIRTY__=true;";
  const html = `<!DOCTYPE html><html>${headTag}<body><div id="root"></div>` + `<script>${propsScript}${dirtyFlag}</script>` + `<script type="module" src="${indexPath}"></script>` + `</body></html>`;
  return new Response(html, {
    headers: { "Content-Type": "text/html" }
  });
}, handleVuePageRequest = async (_PageComponent, pagePath, indexPath, headTag = "<head></head>", ...props) => {
  const [maybeProps] = props;
  if (ssrDirty) {
    return buildDirtyResponse(headTag, indexPath, maybeProps);
  }
  try {
    const resolvePageComponent = async () => {
      const passedPageComponent = _PageComponent;
      if (isGenericVueComponent(passedPageComponent)) {
        return {
          component: passedPageComponent,
          hasIslands: readHasIslands(passedPageComponent)
        };
      }
      const generatedPagePath = await resolveCurrentGeneratedVueModulePath(pagePath);
      const importedPageModule = await import(generatedPagePath);
      const importedPageComponent = readDefaultExport(importedPageModule) ?? importedPageModule;
      if (!isGenericVueComponent(importedPageComponent)) {
        throw new Error(`Invalid Vue page module: ${generatedPagePath}`);
      }
      return {
        component: importedPageComponent,
        hasIslands: readHasIslands(importedPageModule)
      };
    };
    const resolvedPage = await resolvePageComponent();
    const { createSSRApp, h } = await import("vue");
    const { renderToWebStream } = await import("vue/server-renderer");
    const app = createSSRApp({
      render: () => h(resolvedPage.component, maybeProps ?? null)
    });
    const bodyStream = renderToWebStream(app);
    const head = `<!DOCTYPE html><html>${headTag}<body><div id="root">`;
    const tail = `</div><script>window.__INITIAL_PROPS__=${JSON.stringify(maybeProps ?? {})}</script><script type="module" src="${indexPath}"></script></body></html>`;
    const stream = new ReadableStream({
      start(controller) {
        controller.enqueue(head);
        const reader = bodyStream.getReader();
        const pumpLoop = () => {
          reader.read().then(({ done, value }) => done ? (controller.enqueue(tail), controller.close()) : (controller.enqueue(value), pumpLoop())).catch((err) => controller.error(err));
        };
        pumpLoop();
      }
    });
    const htmlStream = injectIslandPageContextStream(stream, {
      hasIslands: resolvedPage.hasIslands
    });
    return new Response(htmlStream, {
      headers: { "Content-Type": "text/html" }
    });
  } catch (error) {
    console.error("[SSR] Vue render error:", error);
    const pageName = derivePageName(pagePath);
    const conventionResponse = await renderConventionError("vue", pageName, error);
    if (conventionResponse)
      return conventionResponse;
    return new Response(ssrErrorPage("vue", error), {
      headers: { "Content-Type": "text/html" },
      status: 500
    });
  }
}, invalidateVueSsrCache = () => {
  ssrDirty = true;
};
var init_pageHandler = __esm(() => {
  init_constants();
  init_resolveConvention();
});

// src/vue/server.ts
init_pageHandler();
export {
  handleVuePageRequest
};

//# debugId=AE9618415E0420A764756E2164756E21
//# sourceMappingURL=server.js.map
