/** * Open all realms. */ export function dangerouslyOpenRealms(): void; /** * Close all realms. */ export function dangerouslyCloseRealms(): void; /** * Open all realms and call a callback. * @template {(...args: any) => any} T The type of the callback. * @param {T} callback The callback to invoke. * @returns {ReturnType} The result of the callback. */ export function dangerouslyEnterRealms any>(callback: T): ReturnType; /** * Create and attach a realm for a node. * @param {HTMLElement & { [REALM_SYMBOL]?: Realm }} node The root node. * @returns The realm instance. */ export function attachRealm(node: HTMLElement & { [REALM_SYMBOL]?: Realm; }): Realm; /** * Get the realm instance for a node. * @param {Node & { [REALM_SYMBOL]?: Realm }} node The root node. * @param {boolean} editMode Whether to return a realm in edit mode. * @returns {Realm|null} The realm instance or null. */ export function getRealm(node: Node & { [REALM_SYMBOL]?: Realm; }, editMode?: boolean): Realm | null; /** * Get the parent realm instance for a node. * @param {Node & { [REALM_PARENT_SYMBOL]?: Realm }} node The child node. * @param {boolean} editMode Whether to return a realm in edit mode. * @returns The parent realm instance or null. */ export function getParentRealm(node: Node & { [REALM_PARENT_SYMBOL]?: Realm; }, editMode?: boolean): Realm | null; /** * The realm class. */ export class Realm { /** * Setup the realm. * @param {HTMLElement} node The root node of the realm. */ constructor(node: HTMLElement); /** * The root node of the realm. * @type {HTMLElement} * @protected */ protected _node: HTMLElement; /** * The owenr document of the realm. * @type {Document} * @protected */ protected _document: Document; /** * The proxy for the realm root to use for internal rendering. * @type {HTMLElement} * @protected */ protected _proxy: HTMLElement; /** * The child nodes of the realm. * @type {ChildNode[]} * @protected */ protected _childNodes: ChildNode[]; /** * The fragment used to temporary store nodes. * @type {DocumentFragment} * @protected */ protected _fragment: DocumentFragment; /** * The callbacks to call when the realm changes. * @type {Set} * @protected */ protected _callbacks: Set; /** * Whether the realm is open. * @type {boolean} * @protected */ protected _open: boolean; /** * The host node of the realm. */ get node(): HTMLElement; /** * The root node of the realm. */ get root(): HTMLElement; /** * The child nodes of the realm as a NodeList. */ get childNodes(): ChildNode[]; /** * Whether the realm is open. */ get open(): boolean; /** * Get the closest realm ancestor of a node. * @returns {Realm | null} A realm or null. */ get ownerRealm(): Realm | null; /** * Initialize the realm. */ initialize(): void; /** * Add a callback to call when the realm changes. * @param {RealmChangeCallback} callback The callback to invoke. */ observe(callback: RealmChangeCallback): void; /** * Remove a registered callback. * @param {RealmChangeCallback} callback The callback to remove. */ unobserve(callback: RealmChangeCallback): void; /** * Open the realm. * When using this method, you must call `dangerouslyClose` when you are done, * or things will get unstable. */ dangerouslyOpen(): void; /** * Close the realm. */ dangerouslyClose(): void; /** * Request an update of the realm. * @template {(...args: any) => any} T The type of the callback. * @param {T} callback The callback to invoke. * @returns {ReturnType} The result of the callback. */ requestUpdate any>(callback: T): ReturnType; /** * Notifiy a realm update * @param {MutationRecord[]} mutations The list of mutations that triggered the update. */ _notifyUpdate(mutations?: MutationRecord[]): void; /** * Get the previous sibling of a node in the realm. * @param {ChildNode | null} node The node to get the previous sibling of. * @returns The previous sibling of the node. */ getPreviousSibling(node: ChildNode | null): ChildNode | null; /** * Get the next sibling of a node in the realm. * @param {ChildNode | null} node The node to get the next sibling of. * @returns The next sibling of the node. */ getNextSibling(node: ChildNode | null): ChildNode | null; /** * Normalize nodes list. * @param {(Node | string)[]} nodes The nodes to normalize. * @param {ChildNode[]} [acc] The accumulator. * @returns The normalized nodes. */ _importNodes(nodes: (Node | string)[], acc?: ChildNode[] | undefined): ChildNode[]; /** * Internal method to append nodes to the realm. * @protected * @param {(Node | string)[]} nodes The nodes to append. * @returns The nodes that were appended. */ protected _append(nodes: (Node | string)[]): ChildNode[]; /** * Internal method to prepend nodes to the realm. * @protected * @param {(Node | string)[]} nodes The nodes to prepend. * @returns The nodes that were prepended. */ protected _prepend(nodes: (Node | string)[]): ChildNode[]; /** * Internal method to remove nodes to the realm. * @protected * @param {ChildNode[]} nodes The nodes to remove. * @returns The nodes that were removed. */ protected _remove(nodes: ChildNode[]): ChildNode[]; /** * Internal method to insert nodes to the realm. * @protected * @param {ChildNode} node The node before which new nodes are to be inserted. * @param {(Node | string)[]} nodes The nodes to insert. * @returns The nodes that were inserted. */ protected _insert(node: ChildNode, nodes: (Node | string)[]): ChildNode[]; /** * Append nodes to the realm. * @param {(ChildNode | string)[]} nodes The nodes to append. */ append(...nodes: (ChildNode | string)[]): void; /** * Prepend nodes to the realm. * @param {(Node | string)[]} nodes The nodes to prepend. */ prepend(...nodes: (Node | string)[]): void; /** * Remove nodes from the realm. * @param {ChildNode[]} nodes The nodes to remove. */ remove(...nodes: ChildNode[]): void; /** * Replaces a realm node with nodes, while replacing strings in nodes with equivalent Text nodes. * @param {ChildNode} node The node to replace. * @param {(Node | string)[]} nodes The nodes or strings to replace node with. Strings are replaced with equivalent Text nodes. */ replaceWith(node: ChildNode, ...nodes: (Node | string)[]): void; /** * Inserts nodes or contents in the realm before node. * @param {ChildNode | null} node The node before which new nodes are to be inserted. * @param {(Node | string)[]} nodes The nodes to be inserted. */ insertBefore(node: ChildNode | null, ...nodes: (Node | string)[]): void; /** * Filter child nodes by `slot` attribute name. * @param {string|null} name The name of the slot. `null` for unnamed slot. */ childNodesBySlot(name?: string | null): ChildNode[]; /** * Check if a realm is contained in this realm. * @param {Realm} realm The child realm. * @returns {boolean} Whether the realm is contained in this realm. */ contains(realm: Realm): boolean; } export type MutationRecord = { addedNodes: ChildNode[]; removedNodes: ChildNode[]; previousSibling: ChildNode | null; nextSibling: ChildNode | null; }; export type RealmChangeCallback = (mutations: MutationRecord[]) => void; /** * @typedef {{ addedNodes: ChildNode[]; removedNodes: ChildNode[]; previousSibling: ChildNode | null; nextSibling: ChildNode | null }} MutationRecord */ /** * @typedef {(mutations: MutationRecord[]) => void} RealmChangeCallback */ declare const REALM_SYMBOL: unique symbol; declare const REALM_PARENT_SYMBOL: unique symbol; export {};