import { CssList, type ListItem } from './list'; import type { Atrule, CssNode, Declaration, Rule } from './types'; export declare const walk: WalkFn; export declare const walkSkip: symbol; export declare const walkStop: symbol; export declare interface WalkContext { root: CssNode stylesheet: CssNode | null atrule: Atrule | null atrulePrelude: CssNode | null rule: Rule | null selector: CssNode | null block: CssNode | null declaration: Declaration | null function: CssNode | null } /** * Object-form visitor. The `T extends WalkVisit` generic is inferred from * the literal value of `visit`, so writing * * walk(ast, { visit: 'Rule', enter(node) { … } }) * * narrows `node` to `Rule`. Without `visit`, callbacks receive the full * `CssNode` union as `enter`/`leave` arguments. */ export declare interface WalkVisitorObject { visit?: T reverse?: boolean enter?: VisitorCallback : CssNode> leave?: VisitorCallback : CssNode> } /** * Walk every node of `root`, calling `visitor` (or visitor.enter / .leave). * Returns: * - undefined when traversal completes, * - the SKIP / STOP sentinel propagated from a visitor. * * `walk.skip` / `walk.stop` are exposed as static-symbol sentinels. */ export declare interface WalkFn { (root: CssNode, visitor: WalkVisitorFunction): symbol | undefined (root: CssNode, visitor: WalkVisitorObject): symbol | undefined skip: symbol stop: symbol } export type WalkVisit = CssNode['type']; // Narrow CssNode by its `type` discriminant — used to type the // `visit: 'Rule'` filter so consumer callbacks receive a `Rule`, not the // full union. export type CssNodeOfType = Extract; // eslint-disable-next-line pickier/no-unused-vars declare type VisitorCallback = (this: WalkContext, node: N, item: ListItem | null, list: CssList | null) => void | symbol; /** Plain-function visitor — runs against every node. */ export type WalkVisitorFunction = VisitorCallback; export type WalkVisitor = WalkVisitorFunction | WalkVisitorObject;