/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import type { AttrMatchOptions, CompiledSelector, ElementSelectorBuilder } from './types.js'; /** * @internal * * A predicate that may write into the per-invocation `captures` map. Returns * `true` if the rule matches; `false` otherwise. */ export type Predicate = (node: Node, captures: Record) => boolean; /** @internal */ export type SelectorKind = 'element' | 'text' | 'comment'; /** @internal The runtime shape of a {@link CompiledSelector}. */ export interface SelectorImpl { readonly kind: SelectorKind; /** * Uppercased tag names this selector is restricted to. Empty for wildcard * element selectors and for text / comment selectors (dispatched by * `kind`). */ readonly tags: ReadonlySet; /** Composed predicate run against a candidate node. */ readonly predicate: Predicate; } /** @internal */ export declare function getSelectorImpl(sel: CompiledSelector): SelectorImpl; /** * @internal * * Build a selector value from a tag set and a predicate list. Used by the * combinator API and the CSS parser. */ export declare function buildSelector(tags: ReadonlySet, predicates: readonly Predicate[]): ElementSelectorBuilder; /** @internal */ export declare function buildClassAllPredicate(classes: readonly string[]): Predicate; /** @internal */ export declare function buildClassAnyPredicate(classes: readonly string[]): Predicate; /** @internal */ export declare function buildAttrPredicate(name: string, value: unknown, options?: AttrMatchOptions): Predicate; /** * Match any {@link HTMLElement}. * * @internal Use `sel.any()`. */ export declare function selAny(): ElementSelectorBuilder; /** * Match DOM {@link Comment} nodes. * * @internal Use `sel.comment()`. */ export declare function selComment(): CompiledSelector; /** * Match by tag name(s). With one literal tag the element type is narrowed * (e.g. `'a' → HTMLAnchorElement`); with multiple, it is the union of * their `HTMLElementTagNameMap` entries. * * @internal Use `sel.tag()`. */ export declare function selTag(...tags: Tags): ElementSelectorBuilder; /** * Match DOM {@link Text} nodes. * * @internal Use `sel.text()`. */ export declare function selText(): CompiledSelector; /** * Combinator API for building {@link CompiledSelector}s. The public * `sel` is augmented from this in `./index.ts` (where the CSS parser is * available without a circular import); consumers outside `@lexical/html` * should always import the public `sel` from the package root. * * Every method builds a selector and returns it; none of them touch anything * outside their arguments, which is what the marker declares. The build * annotates module-scope calls to them so an unused rule can be dropped. * * @internal * @lexical-pure-namespace */ export declare const selBase: { /** Match any {@link HTMLElement}. */ readonly any: typeof selAny; /** Match DOM {@link Comment} nodes. */ readonly comment: typeof selComment; /** * Match by tag name(s). With one literal tag the element type is narrowed * (e.g. `'a' → HTMLAnchorElement`); with multiple, it is the union of * their `HTMLElementTagNameMap` entries. */ readonly tag: typeof selTag; /** Match DOM {@link Text} nodes. */ readonly text: typeof selText; }; /** * Cross-frame-safe replacement for `node instanceof HTMLXxxElement`. Returns * true when `node` is an HTMLElement whose `nodeName` equals `tag` (compared * case-insensitively). * * @experimental */ export declare function isElementOfTag(node: Node, tag: T): node is HTMLElementTagNameMap[T];