import type { Context, FrameHandle } from './component.ts'; import type { ElementProps, RemixElement } from './jsx.ts'; import type { Scheduler } from './scheduler.ts'; import { TypedEventTarget } from './typed-event-target.ts'; type RebindNode = value extends (...args: infer fnArgs) => infer fnResult ? (...args: RebindTuple) => RebindNode : [value] extends [baseNode] ? [baseNode] extends [value] ? boundNode : value : value; type RebindTuple = { [index in keyof args]: RebindNode; }; export type MixinProps = Omit & { mix?: MixValue; }; export type MixinElement = ((handle: { update(): Promise; }, setup: unknown) => (props: MixinProps) => RemixElement) & { __rmxMixinElementType: string; }; export type MixinInsertEvent = Event & { node: node; parent: ParentNode; key?: string; }; export type MixinReclaimedEvent = Event & { node: node; parent: ParentNode; key?: string; }; export type MixinUpdateEvent = Event & { node: node; }; export type MixinBeforeRemoveEvent = Event & { persistNode(teardown: (signal: AbortSignal) => void | Promise): void; }; type MixinContext = Pick>, 'get'>; type MixinHandleEventMap = { beforeRemove: MixinBeforeRemoveEvent; reclaimed: MixinReclaimedEvent; remove: Event; insert: MixinInsertEvent; beforeUpdate: MixinUpdateEvent; commit: MixinUpdateEvent; }; /** * Runtime handle passed to mixin setup functions. * * Mixin render callbacks receive host props with `children` and `innerHTML` removed. * Returned mixin elements may patch host attributes and nested `mix`, but cannot replace * the host subtree. */ export type MixinHandle = TypedEventTarget> & { id: string; context: MixinContext; frame: FrameHandle; element: MixinElement; signal: AbortSignal; update(): Promise; queueTask(task: (node: node, signal: AbortSignal) => void): void; }; export declare function renderMixinElement(element: MixinElement, props?: MixinProps): RemixElement; type MixinRuntimeType = (handle: MixinHandle, type: string) => ((...args: [...args, currentProps: props]) => MixinReturn) | void; /** * Public mixin setup function signature. */ export type MixinType = (handle: MixinHandle, type: string) => ((...args: [...args, currentProps: props]) => MixinReturn) | void; /** * Serializable descriptor stored in the `mix` prop. */ export type MixinDescriptor = { type: MixinRuntimeType; args: args; readonly __node?: (node: node) => void; }; type PreviousMixDepth = [0, 0, 1, 2, 3, 4]; type FalsyMixValue = false | 0 | 0n | '' | null | undefined; type NullableMixValue = descriptor | FalsyMixValue; type NestedMixValue = depth extends 0 ? NullableMixValue | ReadonlyArray> : NullableMixValue | ReadonlyArray>; /** * Accepted authoring shape for the `mix` prop on host elements. */ export type MixInput = NestedMixValue>; /** * Accepted value shape for the `mix` prop. */ export type MixValue = MixinDescriptor | ReadonlyArray>; type MixinReturn = void | null | RemixElement | MixinElement | MixInput; type AnyMixinType = MixinRuntimeType; type AnyMixinRunner = (...args: [...unknown[], currentProps: ElementProps]) => MixinReturn; type AnyMixinHandle = MixinHandle; type RunnerEntry = { type: AnyMixinType; runner: AnyMixinRunner; scope: symbol; }; export type MixinRuntimeBinding = { node: Element; parent: ParentNode; key?: string; target: unknown; frame: FrameHandle; scheduler: Scheduler; enqueueUpdate(done: (signal: AbortSignal) => void): void; }; type ResolveMixedPropsInput = { hostType: string; frame: FrameHandle; scheduler: Scheduler; getContext?: MixinContext['get']; props: ElementProps; state?: MixinRuntimeState; }; type ResolveMixedPropsOutput = { props: ElementProps; state: MixinRuntimeState; }; export type MixinRuntimeState = { id: string; controller?: AbortController; aborted: boolean; handle?: AnyMixinHandle; runners: RunnerEntry[]; binding?: MixinRuntimeBinding; removePrepared?: boolean; pendingRemoval?: { signal: AbortSignal; cancel: (reason?: unknown) => void; done: Promise; }; }; /** * Creates a typed mixin factory that can be passed through the `mix` prop. * * @param type Mixin setup function. * @returns A function that captures mixin arguments and returns a descriptor. */ export declare function createMixin(type: MixinType): (...args: RebindTuple) => MixinDescriptor, props>; export declare function resolveMixedProps(input: ResolveMixedPropsInput): ResolveMixedPropsOutput; export declare function teardownMixins(state?: MixinRuntimeState): void; export declare function bindMixinRuntime(state: MixinRuntimeState | undefined, binding?: MixinRuntimeBinding, options?: { dispatchReclaimed?: boolean; }): void; export declare function prepareMixinRemoval(state?: MixinRuntimeState): Promise | undefined; export declare function cancelPendingMixinRemoval(state?: MixinRuntimeState, reason?: unknown): void; export declare function getMixinRuntimeSignal(state: MixinRuntimeState): AbortSignal; export declare function dispatchMixinBeforeUpdate(state?: MixinRuntimeState): void; export declare function dispatchMixinCommit(state?: MixinRuntimeState): void; export {};