/** * 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 {DOMImportContextSymbol} from '../constants'; import type { AnyContextConfigPairOrUpdater, ContextConfig, ContextRecord, } from '../types'; import type {CompiledOverlayRules} from './defineOverlayRules'; import type {LexicalNode} from 'lexical'; /** * Phantom-typed branding so consumers cannot construct or mutate a * {@link CompiledSelector} directly; the only way to obtain one is via the * {@link sel} builder or {@link parseSelector}. The actual runtime shape is * an internal implementation detail (see `./sel`). * * @experimental */ export declare const NodeBrand: unique symbol; /** @experimental */ export declare const CaptureBrand: unique symbol; /** * An opaque, compiled selector used as the `match` field of a * {@link DOMImportRule}. The two phantom type parameters carry the matched * Node subtype (`N`) and a record of named regex captures (`C`) so the * importer body gets correctly-typed `ctx` and `node` arguments without * casts. * * @experimental */ export interface CompiledSelector< N extends Node = Node, C extends Record = Record, > { readonly [NodeBrand]?: N; readonly [CaptureBrand]?: C; } /** * The Node subtype matched by a selector (e.g. `HTMLAnchorElement` for * `sel.tag('a')`, `Text` for `sel.text()`). * * @experimental */ export type NodeOfSelector = S extends CompiledSelector> ? N : Node; /** * The named-capture map for a selector. * * @experimental */ export type CapturesOfSelector = S extends CompiledSelector ? C : Record; /** * Options bag for {@link ElementSelectorBuilder.attr} when the value is a * regex. Future options will be added here without breaking existing * call-sites. * * @experimental */ export interface AttrMatchOptions { /** * If provided, the {@link RegExpMatchArray} from the successful match is * stored on `ctx.captures[capture]` for the importer to consume — saving * a second regex execution. */ readonly capture?: K; } /** * Options bag for {@link ElementSelectorBuilder.styleAny} when the value is a * regex. See {@link AttrMatchOptions} for capture semantics. * * @experimental */ export interface StyleMatchOptions { readonly capture?: K; } /** * Fluent builder for an element selector. The two type parameters carry the * matched element type and the named-capture map; each call refines them. * * The builder itself implements {@link CompiledSelector} so it can be used * directly as the `match` field of a rule — no `.build()` call needed. * * @experimental */ export interface ElementSelectorBuilder< E extends HTMLElement, C extends Record = Record, > extends CompiledSelector { /** Require every listed class to be present on the element. */ classAll(...classes: readonly string[]): ElementSelectorBuilder; /** Require at least one of the listed classes to be present. */ classAny(...classes: readonly string[]): ElementSelectorBuilder; /** Require the attribute to be present (any value). */ attr(name: string, value: true): ElementSelectorBuilder; /** Require the attribute to equal the given string. */ attr(name: string, value: string): ElementSelectorBuilder; /** * Require the attribute to match the given regex. With * `{capture: 'name'}` the match result is exposed on * `ctx.captures.name`. */ attr( name: string, value: RegExp, options?: O, ): ElementSelectorBuilder< E, O extends {capture: infer K} ? C & Record : C >; /** Require the inline-style declaration to equal `value`. */ styleAny(prop: string, value: string): ElementSelectorBuilder; /** Require the inline-style declaration to match `value`. */ styleAny( prop: string, value: RegExp, options?: O, ): ElementSelectorBuilder< E, O extends {capture: infer K} ? C & Record : C >; } /** * Argument to {@link DOMImportContext.branch} / `$importChildren({context})` * — see {@link ContextConfigPair} / {@link ContextConfigUpdater}. * * @experimental */ export type ImportContextPairOrUpdater = AnyContextConfigPairOrUpdater< typeof DOMImportContextSymbol >; /** * A typed context-state key for the import pipeline. Create with * {@link createImportState}. * * @experimental */ export type ImportStateConfig = ContextConfig< typeof DOMImportContextSymbol, V >; /** * A mutable, document-order-shared store for the import pipeline. Lets a * rule visited early in the document write information that rules visited * later can read — e.g. parse `