import { D as InferArgsType, E as Thenable, O as InferReturnType, T as RpcReturnSchema, m as RpcFunctionAgentOptions, n as RpcArgsSchema } from "../types-BmDbfHCx.mjs"; import { Kt as EventEmitter, k as SharedState } from "../context--tVkJw3W.mjs"; //#region src/in-page-channel/types.d.ts /** * The shared contract of one in-page channel, declared once (usually in a * `shared/protocol.ts` both sides import) and passed to both endpoints as a * type parameter. Purely a type; the only runtime companion is the * channel-name constant declared next to it. */ interface InPageChannelProtocol { functions?: { /** Functions implemented by the page script. */ pageScript?: Record any>; /** Functions implemented by panels. */ panel?: Record any>; }; events?: { /** Events emitted by panels and received by the page script. */ pageScript?: Record void>; /** Events emitted by the page script and received by panels. */ panel?: Record void>; }; /** * Shared-state slots. The page script is the authority: it owns the * canonical value; panels are seeded on connect and converge through * syncId-deduplicated patches. */ sharedStates?: Record; } type SideFunctions = S extends Record any> ? S : Record; type SideDeclarations

= Kind extends keyof P ? Side extends keyof NonNullable ? SideFunctions[Side]>> : Record : Record; type PageScriptFunctions

= SideDeclarations; type PanelFunctions

= SideDeclarations; type SharedStates

= P['sharedStates'] extends Record ? P['sharedStates'] : Record; type FnArgs = F extends ((...args: infer A) => any) ? A : never; type FnReturn = F extends ((...args: any[]) => infer R) ? Awaited : never; type PageScriptEvents

= SideDeclarations; type PanelEvents

= SideDeclarations; /** * Converts a protocol function to its accepted endpoint handler. * * @internal */ type ProtocolHandler = F extends ((...args: any[]) => any) ? (...args: FnArgs) => Thenable> : never; /** * Types of an in-page channel function: `RpcFunctionType` minus the * server-only `static`: `event` is fire-and-forget (the only type valid for * fan-out), `action` performs, `query` requests data (the default). */ type InPageFunctionType = 'action' | 'event' | 'query'; interface InPageDefinitionBase { name: NAME; jsonSerializable?: boolean; } interface InPageFunctionDefinitionBase extends InPageDefinitionBase { /** Expose this function through DevFrame's browser-to-node agent bridge. */ agent?: RpcFunctionAgentOptions; } interface InPageEventFunctionDefinition extends InPageDefinitionBase { type: 'event'; handler?: HANDLER; } interface InPageQueryFunctionDefinition extends InPageFunctionDefinitionBase { type?: 'query'; handler: HANDLER; } interface InPageActionFunctionDefinition extends InPageFunctionDefinitionBase { type: 'action'; handler: HANDLER; } type InPageFunctionDefinitionForType = TYPE extends 'event' ? InPageEventFunctionDefinition : TYPE extends 'action' ? InPageActionFunctionDefinition : InPageQueryFunctionDefinition; type InPageFunctionDefinitionSchemas = [AS, RS] extends [undefined, undefined] ? { args?: AS; returns?: RS; } : { /** Standard Schema array validating (and typing) the arguments. */ args: AS; /** Standard Schema typing the resolved return value. */ returns: RS; }; type InPageFunctionDefinitionHandler = [AS, RS] extends [undefined, undefined] ? (...args: ARGS) => RETURN : (...args: InferArgsType) => Thenable>; /** * An in-page channel function definition: the `defineRpcFunction` authoring * shape (`name`, `type`, Standard-Schema `args`/`returns`, * `jsonSerializable`, `handler`) narrowed to the browser: there is no * `dump`/`snapshot`/`cacheable`. An optional `agent` exposes the function to * DevFrame's browser-to-node agent bridge. When `jsonSerializable` is `true`, * payloads are strictly validated at the receiving endpoint and misshapen * values reject the call with a descriptive `InPageChannelError` instead of * a cryptic `DataCloneError` in the port. Event definitions may omit their * handler when runtime listeners subscribe through `channel.on()`. */ type InPageFunctionDefinition = InPageFunctionDefinitionForType> & InPageFunctionDefinitionSchemas; /** * Function metadata with its handler constrained by a protocol function. * * @internal */ interface InPageDefinitionOptionBase { /** Optional Standard Schema array validating the arguments. */ args?: RpcArgsSchema; /** Optional Standard Schema validating the resolved return value. */ returns?: RpcReturnSchema; jsonSerializable?: boolean; } interface InPageFunctionOptionBase extends InPageDefinitionOptionBase { /** Expose this function through DevFrame's browser-to-node agent bridge. */ agent?: RpcFunctionAgentOptions; } interface InPageEventFunctionOption extends InPageDefinitionOptionBase { type?: 'event'; handler?: ProtocolHandler; } type InPageEventOption = [F] extends [never] ? never : InPageEventFunctionOption; interface InPageQueryFunctionOption extends InPageFunctionOptionBase { type?: 'query'; handler: ProtocolHandler; } interface InPageActionFunctionOption extends InPageFunctionOptionBase { type: 'action'; handler: ProtocolHandler; } type InPageFunctionOption = InPageQueryFunctionOption | InPageActionFunctionOption; /** * Functions implemented by {@link createPageScriptChannel}. * * @internal */ type CreatePageScriptChannelOptionsFunctions

= { [NAME in keyof PageScriptFunctions

& string]: InPageFunctionOption[NAME]>; }; /** * Functions implemented by {@link connectPanelChannel}. * * @internal */ type ConnectPanelChannelOptionsFunctions

= { [NAME in keyof PanelFunctions

& string]: InPageFunctionOption[NAME]>; }; /** * Connection lifecycle of a panel endpoint: `connecting` (handshake retry * loop running, outgoing traffic buffered) → `connected` → back to * `connecting` on port loss, or `closed` after `close()` (permanent). */ type InPageChannelStatus = 'connecting' | 'connected' | 'closed'; /** * Options shared by both in-page channel endpoints. * * @internal */ interface InPageChannelCommonOptions { /** * Channel name, namespaced with the devframe id by convention * (e.g. `devframes:plugin:a11y`). Both endpoints must use the same name. */ name: string; /** * Origins accepted during the handshake (and used as `targetOrigin` when * posting handshake messages). The in-page channel is same-origin by * definition, so this defaults to `[location.origin]`. */ allowedOrigins?: string[]; /** * Timeout for request/response calls, in milliseconds; `-1` disables. * Rejections are `InPageChannelError`s (code `timeout`) carrying the * endpoint status, so a hanging call explains itself. * @default 15000 */ callTimeoutMs?: number; /** * Liveness heartbeat guarding against silently dead ports. Defaults to a * 5s ping / 12s silence window; pass `false` to disable, on both * endpoints together. */ heartbeat?: { intervalMs?: number; timeoutMs?: number; } | false; /** * Applied to each outgoing argument and handler result before posting; * the place to unwrap framework reactivity (Vue `toRaw`, Solid `unwrap`) * into plain structured-cloneable values. */ serialize?: (value: unknown) => unknown; /** Applied to each incoming argument and call result. */ deserialize?: (value: unknown) => unknown; } /** Options for {@link createPageScriptChannel}. */ interface CreatePageScriptChannelOptions extends InPageChannelCommonOptions { /** Every page-script function declaration, with a required handler. */ functions: CreatePageScriptChannelOptionsFunctions; /** Optional metadata or handlers for incoming events. Listeners may instead subscribe through `channel.on()`. */ events?: { [NAME in keyof PageScriptEvents & string]?: InPageEventOption[NAME]>; }; /** * Window whose `message` events carry panel hellos. Defaults to the * global `window`; pass `false` to skip the handshake listener entirely * (bring-your-own ports via `addPanelPort` only). */ window?: Window | false; } /** Options for {@link connectPanelChannel}. */ interface ConnectPanelChannelOptions extends InPageChannelCommonOptions { /** Every panel function declaration, with a required handler. */ functions: ConnectPanelChannelOptionsFunctions; /** Optional metadata or handlers for incoming events. Listeners may instead subscribe through `channel.on()`. */ events?: { [NAME in keyof PanelEvents & string]?: InPageEventOption[NAME]>; }; /** * The panel's own window (listens for the handshake grant). Defaults to * the global `window`; pass `false` with `transport` to skip the handshake. */ window?: Window | false; /** * Windows the hello is posted to. Defaults to the panel's ancestor chain * plus those windows' openers, the places a page script can live. When * empty and no `transport` is given, the endpoint stays `connecting` and * warns once. */ targets?: Window[]; /** Pre-established port to the page script, bypassing the handshake. */ transport?: MessagePort; /** * Pin this panel to one page-script instance id. By default the panel * auto-pairs with the most recent page script that answers, almost * always "my own tab's page script". */ instanceId?: string; /** * Base interval between handshake hello retries, in milliseconds; each * retry backs off ×1.5 up to a 3s cap, forever (the page script may load * later than the panel). * @default 300 */ helloIntervalMs?: number; /** * Maximum `emit` payloads buffered while `connecting`, flushed on * connect; when full, the oldest is dropped with a console warning. * @default 64 */ eventBufferLimit?: number; } /** * The channel shared-state accessor, mirroring `rpc.sharedState`, with the * page script playing the server's role as rendezvous and authority. The * page script's first `get` of a key must provide `initialValue`; a panel's * `get` without one resolves once the authority's first replay arrives. */ interface InPageSharedStateHost

{ get: & string>(key: K, options?: { initialValue?: SharedStates

[K]; }) => Promise[K]>>; } /** Emitter events of a page-script endpoint. */ interface PageScriptChannelEvents

{ 'panel:connected': (panel: PanelPeer

) => void; 'panel:disconnected': (panel: PanelPeer

) => void; } /** One connected panel, as seen from the page script. */ interface PanelPeer

{ /** Unique id of the panel endpoint (stable across its lifetime, not reloads). */ readonly id: string; /** Call one panel's function and await the result. */ call: & string>(name: K, ...args: FnArgs[K]>) => Promise[K]>>; /** Disconnect this panel. */ close: () => void; } /** * The page-script endpoint of an in-page channel: answers panel handshakes, * holds one dedicated port per connected panel, fans events out to all of * them, and is the authority for the channel's shared states. */ interface PageScriptChannel

{ readonly name: string; /** * This page context's instance id (persisted per tab in sessionStorage), * carried in every handshake so panels can pin to one instance when the * same app is open in several tabs. */ readonly instanceId: string; /** Currently connected panels. */ readonly panels: readonly PanelPeer

[]; readonly events: Pick>, 'on' | 'once'>; /** Fan an event out to every connected panel. */ emit: & string>(name: K, ...args: FnArgs[K]>) => void; /** Subscribe to an event emitted by a panel. Returns an unsubscribe function. */ on: & string>(name: K, listener: (...args: FnArgs[K]>) => void) => () => void; /** Page-script-authoritative shared states, replayed to joining panels. */ readonly sharedState: InPageSharedStateHost

; /** Adopt a pre-established port as a panel peer (bring-your-own transport). */ addPanelPort: (port: MessagePort) => PanelPeer

; /** Tear the endpoint down: disconnect every panel, stop answering hellos. */ close: () => void; } /** Emitter events of a panel endpoint. */ interface PanelChannelEvents { 'status:updated': (status: InPageChannelStatus) => void; } /** * The panel endpoint of an in-page channel: finds the page script with a * retrying same-origin handshake, survives reloads on either side by * re-handshaking, and buffers outgoing traffic while `connecting`. */ interface PanelChannel

{ readonly name: string; readonly status: InPageChannelStatus; /** The paired page script's instance id, once connected. */ readonly pageScript: { instanceId: string; } | undefined; readonly events: Pick, 'on' | 'once'>; /** * Resolves once connected. With `timeoutMs`, rejects with an * `InPageChannelError` (code `timeout`) when no page script answered in * time; the hook for a "no page script found" fallback UI. */ whenConnected: (timeoutMs?: number) => Promise; /** * Call a page-script function and await the result. While `connecting` * the call is buffered and sent on connect; it rejects with code * `timeout` when `callTimeoutMs` elapses first. */ call: & string>(name: K, ...args: FnArgs[K]>) => Promise[K]>>; /** * Emit an event to the page script. While `connecting` the event is buffered * (up to `eventBufferLimit`) and flushed on connect. */ emit: & string>(name: K, ...args: FnArgs[K]>) => void; /** Subscribe to an event emitted by the page script. Returns an unsubscribe function. */ on: & string>(name: K, listener: (...args: FnArgs[K]>) => void) => () => void; /** Shared states mirrored from the page-script authority. */ readonly sharedState: InPageSharedStateHost

; /** Tear the endpoint down permanently. */ close: () => void; } //#endregion //#region src/in-page-channel/internal.d.ts /** Stable failure codes of the in-page channel. */ type InPageChannelErrorCode = 'timeout' | /** The endpoint was closed (or closed while calls were pending). */ 'closed' | /** A `jsonSerializable` payload contained a non-JSON value. */ 'not-serializable' | /** The port refused to clone a payload (`DataCloneError`). */ 'not-cloneable' | /** Standard-Schema validation of incoming arguments failed. */ 'invalid-args' | /** A shared-state key was first accessed without its initial value. */ 'state-uninitialized'; /** A coded in-page channel error; every failure mode carries a stable `code`. */ export declare class InPageChannelError extends Error { readonly code: InPageChannelErrorCode; name: string; constructor(code: InPageChannelErrorCode, message: string, options?: { cause?: unknown; }); } //#endregion //#region src/in-page-channel/page-script.d.ts /** * Create the page-script endpoint of an in-page channel. * * It listens for panel hellos on the host page's window and answers each * with a dedicated `MessageChannel` port (same-origin enforced both ways), * keeping one live peer per panel: dock iframe, popup, and Document-PiP * panels all handshake the same way, and a panel reload is simply a new * handshake. No server is involved at any point. */ export declare function createPageScriptChannel

(options: CreatePageScriptChannelOptions

): PageScriptChannel

; //#endregion //#region src/in-page-channel/panel.d.ts /** * Connect the panel endpoint of an in-page channel. * * The panel initiates: it posts a versioned hello to every window a * page script can live in (its ancestor chain and those windows' openers), * retrying with backoff until one answers with a dedicated port, so boot * order never matters, and a reload of either side is just a re-handshake * (`WindowProxy` references survive navigations). While `connecting`, * outgoing calls and events are buffered; when no page script exists at all * (e.g. the panel opened standalone), the endpoint stays `connecting` and * the UI can key a fallback state off `status` / `whenConnected()`. */ export declare function connectPanelChannel

(options: ConnectPanelChannelOptions

): PanelChannel

; //#endregion //#region src/in-page-channel/index.d.ts /** * Define one in-page channel function, the `defineRpcFunction` authoring * shape narrowed to the browser (see {@link InPageFunctionDefinition}). * Pure identity: it only types the definition. Functions live in * side-specific files and are passed to their endpoint via `functions`; the * shared protocol file carries only the contract type and the channel-name * constant. */ export declare function defineChannelFunction(definition: InPageFunctionDefinition): InPageFunctionDefinition; //#endregion export type { ConnectPanelChannelOptions, CreatePageScriptChannelOptions, InPageChannelErrorCode, InPageChannelProtocol, InPageChannelStatus, InPageFunctionDefinition, PageScriptChannel, PanelChannel, PanelPeer };