// ---- Event system ---- export type Cancelable = { cancel: () => void; }; export type EventEmitterType = { on: (eventName: string, handler: (...args: any[]) => void) => Cancelable; once: (eventName: string, handler: (...args: any[]) => void) => Cancelable; trigger: (eventName: string, ...args: any[]) => void; off: (eventName: string, handler: (...args: any[]) => void) => void; destroy: () => void; }; // ---- Dimensions ---- export type CssDimensionsType = { width: string; height: string; }; // ---- Computed props ---- export type ComputedPropConfig
= {
/**
* Produce a computed prop value. Runs AFTER containerTemplate,
* so `state` reflects any mutations made by the container template.
* Return value is classified by `type`: 'function' → dispatch map, 'value' → data payload.
*/
factory: (context: {props: P; state: Record = {
uid: string;
frame: HTMLIFrameElement;
placeholder: HTMLElement | undefined;
doc: Document;
props: P;
event: EventEmitterType;
dimensions: CssDimensionsType;
state: Record = {
tag: string;
url: string;
dimensions?: CssDimensionsType;
autoResize?: {width?: boolean; height?: boolean; element?: string};
/**
* Build wrapper DOM around the iframe. Runs BEFORE computed prop factories,
* so it may mutate `state` (e.g., `state.__container = container`) for factories to read.
*/
containerTemplate?: (options: RenderOptions ) => HTMLElement | undefined;
prerenderTemplate?: (options: RenderOptions ) => HTMLElement | undefined;
validate?: (input: {props: P}) => void;
defaultProps?: (context: {event: EventEmitterType}) => Partial ;
/** Parent-side computed props — factories run at render time */
computedProps?: Record ) => (options?: any) => Promise {
render: (container?: string | HTMLElement) => Promise ) => Promise {
new (props: P): BridgeComponent ;
driver: (name: string, deps?: Record