import { encryptString } from "../../../core/encryption.js"; import { renderChild } from "./any.js"; import { renderSlotToString } from "./slot.js"; const internalProps = /* @__PURE__ */ new Set([ "server:component-path", "server:component-export", "server:component-directive", "server:defer" ]); function containsServerDirective(props) { return "server:component-directive" in props; } function safeJsonStringify(obj) { return JSON.stringify(obj).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029").replace(//g, "\\u003e").replace(/\//g, "\\u002f"); } function renderServerIsland(result, _displayName, props, slots) { return { async render(destination) { const componentPath = props["server:component-path"]; const componentExport = props["server:component-export"]; const componentId = result.serverIslandNameMap.get(componentPath); if (!componentId) { throw new Error(`Could not find server component name`); } for (const key2 of Object.keys(props)) { if (internalProps.has(key2)) { delete props[key2]; } } destination.write(""); const renderedSlots = {}; for (const name in slots) { if (name !== "fallback") { const content = await renderSlotToString(result, slots[name]); renderedSlots[name] = content.toString(); } else { await renderChild(destination, slots.fallback(result)); } } const key = await result.key; const propsEncrypted = await encryptString(key, JSON.stringify(props)); const hostId = crypto.randomUUID(); const slash = result.base.endsWith("/") ? "" : "/"; const serverIslandUrl = `${result.base}${slash}_server-islands/${componentId}${result.trailingSlash === "always" ? "/" : ""}`; destination.write(``); } }; } export { containsServerDirective, renderServerIsland };