import { WebRenderer } from 'storybook/internal/types';
/**
* Astro component references can't be JSON-serialized, so when a story passes an
* Astro component as a prop or as slot content, the client replaces it with this
* plain marker before sending the render request. The server reconstructs it: a
* marker used as a prop is resolved back to the real component factory (the
* parent template renders it via ``); a marker used as slot content is
* rendered to an HTML string (the Astro Container only accepts string slots).
*
* Only the `moduleId` needs to cross the boundary — the server loads the
* component from it exactly like it loads the top-level story component.
*
* Scope: a marker carries a bare component reference, not per-instance props or
* slots. Passing a "configured" child (with its own props/slots) or a non-Astro
* framework component as a slot/prop is not supported yet.
*/
declare const ASTRO_COMPONENT_MARKER = "__astroComponent";
type AstroComponentMarker = {
[ASTRO_COMPONENT_MARKER]: true;
moduleId: string;
};
/**
* A value is a marker only when both keys are present and well-typed, so a
* legitimate plain-object arg can't be mistaken for one.
*/
declare function isAstroComponentMarker(value: unknown): value is AstroComponentMarker;
/**
* Detects an Astro component factory — the callable produced by importing a
* `.astro` file. On the client this is the stub from `vitePluginAstroComponentMarker`
* (which sets `isAstroComponentFactory` and `moduleId`); on the server (and in the
* Vitest/portable path) it's the real Astro factory, which also sets the flag.
*/
declare function isAstroComponentFactory(value: unknown): boolean;
/**
* Recursively replaces Astro component factories in an args/slots value with
* serializable {@link AstroComponentMarker}s so the value can cross the JSON
* render boundary. Walks arrays and nested objects. A factory missing its
* `moduleId` can't be rendered server-side, so it's dropped with an error.
*/
declare function serializeAstroComponentMarkers(value: unknown, depth?: number): unknown;
/** Slot content: an HTML string, a serialized component reference, or a list of either. */
type SlotValue = string | AstroComponentMarker | Array;
/**
* Mirrors the shape that the Astro language server gives to `.astro` imports:
* a callable factory function with an optional `isAstroComponentFactory` marker.
* Keeping this structurally compatible ensures that assigning an imported Astro
* component to `component:` is clean under strict TypeScript / ESLint rules.
*/
type AstroComponentFactory = {
(result: unknown, props: unknown, slots: unknown): unknown | Promise;
isAstroComponentFactory?: boolean;
moduleId?: string | undefined;
};
/**
* Storybook renderer type for Astro components.
*
* Astro components are server-side rendered, so storyResult can be an Astro component
* factory (routed to SSR), a string (HTML), or an HTMLElement (DOM node).
*/
interface AstroRenderer extends WebRenderer {
component: AstroComponentFactory | string | HTMLElement | ((...args: unknown[]) => unknown);
storyResult: AstroComponentFactory | string | HTMLElement;
}
type RenderComponentInput = {
component: string;
args: Record;
slots: Record;
story?: {
id: string;
title?: string;
name?: string;
};
};
type RenderResponseMessage = {
type: 'astro:render:response';
data: {
id: string;
html: string;
};
};
type RenderRequestMessage = {
type: 'astro:render:request';
data: RenderComponentInput & {
id: string;
};
};
type Message = RenderRequestMessage | RenderResponseMessage;
type RenderPromise = {
resolve: (value: RenderResponseMessage['data']) => void;
reject: (reason?: unknown) => void;
timeoutId: NodeJS.Timeout;
};
declare global {
interface Window {
preact?: {
h: (type: string | ((props: Record) => unknown), props: Record | null, ...children: unknown[]) => unknown;
render: (element: unknown, container: HTMLElement) => void;
};
Alpine?: {
start: () => void;
_isStarted?: boolean;
};
}
}
export { ASTRO_COMPONENT_MARKER, type AstroComponentFactory, type AstroComponentMarker, type AstroRenderer, type Message, type RenderComponentInput, type RenderPromise, type RenderRequestMessage, type RenderResponseMessage, type SlotValue, isAstroComponentFactory, isAstroComponentMarker, serializeAstroComponentMarkers };