import { HostBackend } from "./backend.js"; import { NativeCommand, NativeNodeId } from "./native-protocol.js"; //#region src/native-command-backend.d.ts /** * An opaque native host node. The reconciler treats it as a handle; the backend * tracks structure (parent/children) on it to translate the {@link HostBackend} * tree operations into index-based {@link NativeCommand}s. */ interface NativeCommandNode { /** Stable id, shared with the host via the command stream. */ readonly id: NativeNodeId; /** `"element"` or `"text"`. */ kind: 'element' | 'text'; /** Element tag (empty for text nodes). */ tag: string; /** Text content (text nodes). */ text: string; /** Parent node, or `null` when detached / the root. */ parent: NativeCommandNode | null; /** Ordered child nodes. */ children: NativeCommandNode[]; } /** Options for {@link createNativeCommandBackend}. */ interface NativeCommandBackendOptions { /** Id of the host's pre-existing root container. Defaults to a per-instance id. */ rootId?: NativeNodeId; /** * Custom node-id generator. Must return **unique, finite** ids (a non-finite * number is rejected at the boundary). Defaults to a collision-free per-instance * factory; uniqueness of a custom factory is the caller's responsibility. */ idFactory?: () => NativeNodeId; /** Called synchronously for every emitted command. */ onCommand?: (command: NativeCommand) => void; /** Called by {@link NativeCommandBackend.flushCommands} with the flushed batch. */ onBatch?: (commands: readonly NativeCommand[]) => void; } /** A {@link HostBackend} that emits a {@link NativeCommand} stream. */ interface NativeCommandBackend extends HostBackend { /** Discriminator for backend kind. */ readonly kind: 'native-command'; /** Id of the host root container (the `parentId` of top-level inserts). */ readonly rootId: NativeNodeId; /** The root node to pass as the `container` to `render()`. */ readonly root: N; /** A readonly snapshot of all commands buffered since the last flush/clear. */ getCommands(): readonly NativeCommand[]; /** Return the buffered commands as a batch, fire `onBatch`, and clear the buffer. */ flushCommands(): readonly NativeCommand[]; /** Drop all buffered commands without firing `onBatch`. */ clearCommands(): void; /** * Invoke a registered event handler by id (what a host calls when a native * event fires). Returns `true` if a handler was found and called. */ dispatchEvent(handlerId: string, event?: unknown): boolean; } /** * Create a {@link NativeCommandBackend}. Render against it to capture the native * command stream: * * @example * const backend = createNativeCommandBackend() * const app = render(MyComponent, {}, backend, backend.root) * const commands = backend.flushCommands() // replay these on a native host */ declare function createNativeCommandBackend(options?: NativeCommandBackendOptions): NativeCommandBackend; //#endregion export { NativeCommandBackend, NativeCommandBackendOptions, NativeCommandNode, createNativeCommandBackend }; //# sourceMappingURL=native-command-backend.d.ts.map