import { d as InterpreterResult, L as LanguageError } from './interpreter-CgnLEVGZ.js';
import { a as Config, I as ISymbolType, y as SymbolMetadata } from './types-DSZPf9oj.js';

/**
 * ObjectParser allows custom transformation of structured values into interpreter symbols.
 * This is useful for parsing complex nested structures like { value: 1, unit: "rem" } into NumberWithUnitSymbol.
 *
 * @example
 * const numberWithUnitParser: ObjectParser = {
 *   predicate: (value) => isObject(value) && 'value' in value && 'unit' in value,
 *   toSymbol: ({ value, unit }, config) => new NumberWithUnitSymbol(value, unit, config)
 * }
 */
type ObjectParser = {
    /**
     * Check if this parser should handle the given value
     */
    predicate: (value: unknown) => boolean;
    /**
     * Convert the matched value to an interpreter symbol
     */
    toSymbol: (value: any, config?: Config) => ISymbolType;
};

declare class DependencyGraph<N = string> {
    private nodes;
    addNode(node: N, dependencies?: N[] | Set<N>): void;
    removeNode(node: N): void;
    getNodes(): Map<N, Set<N>>;
    entryNodes(): N[];
    private findCycle;
    topologicalSort(): N[];
}

/**
 * Structured token data containing value and optional type information
 */
interface TokenData {
    $value: unknown;
    $type?: string;
    /**
     * Optional metadata attached to the token.
     * This is passed through to the TokenSymbol and preserved during cloning.
     * Not accessible to the tokenscript language.
     */
    $metadata?: SymbolMetadata;
}

declare enum ValidationSeverity {
    ERROR = "error",
    WARNING = "warning",
    INFO = "info"
}
/**
 * A validation issue found during token type validation.
 *
 * @property code - Unique error code for this specific issue type
 * @property severity - Severity level (ERROR, WARNING, INFO)
 * @property message - Human-readable description of the issue
 * @property tokenName - The token where the issue was found
 * @property path - Path to the specific field within a structured token (e.g., ["fontSize"] or [0, "blur"] for arrays)
 * @property line - Optional line number in the source
 * @property data - Additional structured data for debugging
 */
interface ValidationIssue {
    code: string;
    severity: ValidationSeverity;
    message: string;
    tokenName: RefPath;
    path?: (string | number)[];
    line?: number;
    data?: Record<string, unknown>;
}

/**
 * Reference path (token name delimited by `.`)
 */
type RefPath = string;
type TokenInputMap = Map<RefPath, string | TokenData>;
type TokenDataMap$1 = Map<RefPath, TokenData>;
type ResolvedValueMap = Map<RefPath, InterpreterResult>;
type TokenResult = InterpreterResult | Error;
type TokenResultMap = Map<RefPath, TokenResult>;
/**
 * An issue found during token resolution.
 * Can be a validation issue or a language error (lexer/parser/interpreter/processor).
 */
type ResolveIssue = ValidationIssue | LanguageError;
type IssuesMap = Map<RefPath, ResolveIssue[]>;
type TokenOperationBase = {
    tokenPath: RefPath;
};
type CreateTokenParams = TokenOperationBase & {
    tokenData: TokenData;
};
type UpdateTokenParams = TokenOperationBase & {
    tokenData?: TokenData;
    tokenPathRenamed?: RefPath;
    updateReferences?: boolean;
};
type DeleteTokenParams = TokenOperationBase;
type TokenOperationResult = {
    tokens: ResolvedValueMap;
    resolved?: InterpreterResult;
    issues?: IssuesMap;
    dependants?: {
        graph: DependencyGraph<RefPath>;
    };
};
type CreateTokenResult = TokenOperationResult & {
    created: boolean;
};
type UpdateTokenResult = TokenOperationResult & {
    updated: boolean;
};
type DeleteTokenResult = TokenOperationResult;

type ProcessorResult = {
    graph: DependencyGraph<RefPath>;
    resolved: TokenResultMap;
    issues?: IssuesMap;
};
type ProcessorCallbacks = {
    onResolve?: (tokenName: RefPath, value: InterpreterResult) => void;
    onError?: (tokenName: RefPath, error: Error, originalValue: string | unknown, metadata?: {
        isSubField: boolean;
        parentToken?: string;
        fieldPath?: string;
    }) => void;
};
type ProcessorOutput = ProcessorResult & {
    tokens: ResolvedValueMap;
    resolver: TokenResolver;
    issues?: IssuesMap;
};
/**
 * TokenResolver - Resolves tokens with dependencies using prefix-aware resolution
 *
 * @example
 * const processor = new TokenResolver();
 * const tokens = new Map([
 *   ["a", { $value: "10" }],
 *   ["b", { $value: "{a} * 2" }],
 * ]);
 * const result = processor.build(tokens);
 */
declare class TokenResolver {
    private prefixResolver?;
    private tokens?;
    private config?;
    private objectParsers?;
    processTokens(tokens: TokenInputMap, callbacks?: ProcessorCallbacks, config?: Config, objectParsers?: ObjectParser[]): ProcessorResult;
    /**
     * Find all tokens affected by a change to the given token.
     *
     * Uses BFS traversal on the reverse dependency graph to identify
     * the changed token plus all tokens that transitively depend on it.
     *
     * @param tokenName - The token that changed
     * @returns Object containing affected tokens and a subgraph showing their relationships
     *
     * @example
     * const { resolver } = new TokenResolver().build(tokens);
     * const { tokens, subgraph } = resolver.getTokenDependencyGraph("color.primary");
     * console.log(tokens); // Set(['color.primary', 'button.background', ...])
     */
    getTokenDependencyGraph(tokenName: RefPath): {
        tokens: Set<RefPath>;
        subgraph: DependencyGraph<RefPath>;
    };
    build(tokens: TokenDataMap$1, config?: Config, objectParsers?: ObjectParser[]): ProcessorOutput;
    private ensureInitialized;
    private normalizeTokenPath;
    private createOutputCallbacks;
    private rebuildResolver;
    updateToken(params: UpdateTokenParams): UpdateTokenResult;
    createToken(params: CreateTokenParams): CreateTokenResult;
    deleteToken(params: DeleteTokenParams): DeleteTokenResult;
}

interface TokenBuilder<T = unknown> {
    onResolve(tokenName: string, value: InterpreterResult): void;
    onError(tokenName: string, error: Error, originalValue: string | unknown): void;
    getResult(): T;
    readonly name: string;
}
type BuilderFormat = "nested" | "flat" | "map";

type TokenDataMap = Map<string, TokenData>;
interface BuildTokensOptions<T> {
    builder?: TokenBuilder<T>;
    config?: Config;
    objectParsers?: ObjectParser[];
}
/**
 * Builds tokens from a normalized TokenDataMap.
 *
 * This is the core token processing function. For most use cases, call this directly
 * rather than using the higher-level processTokens/processTokenSets wrappers.
 *
 * @param tokens - Map of token names to TokenData. Must be pre-normalized to TokenData format.
 * @param options - Build options (all optional):
 *   - builder: Custom token builder (default: MapBuilder)
 *   - config: Interpreter config
 *   - objectParsers: Array of object parsers
 *   - linter: Lint runner
 * @returns ProcessorOutput with resolved tokens, output, and optional lint results.
 *
 * @remarks
 * Consumers must normalize input to Map<string, TokenData> before calling this function.
 * Use processTokens/processTokenSets for automatic normalization of Records and Maps.
 */
declare function buildTokens<T = Map<string, InterpreterResult>>(tokens: TokenDataMap, options?: BuildTokensOptions<T>): ProcessorOutput & {
    output: T;
    issues?: IssuesMap;
};

type ProcessOptions = BuildTokensOptions<any>;
interface ProcessSetsOptions extends ProcessOptions {
    activeSets?: string[];
    activeTheme?: string;
}
interface ProcessResult<T = Map<string, string | InterpreterResult>> extends ProcessorOutput {
    output: T;
    issues?: IssuesMap;
}
type ProcessFilesOptions<T = any> = {
    path: string;
    outputPath?: string;
    schemas?: string[];
    activeSets?: string[];
    activeTheme?: string;
    builder?: TokenBuilder<T>;
    objectParsers?: ObjectParser[];
};

export { type BuildTokensOptions as B, type CreateTokenParams as C, type DeleteTokenParams as D, type IssuesMap as I, type ProcessFilesOptions as P, type ResolveIssue as R, type TokenBuilder as T, type UpdateTokenParams as U, type ValidationIssue as V, type ProcessResult as a, type CreateTokenResult as b, type DeleteTokenResult as c, type ProcessorOutput as d, type ProcessorResult as e, type TokenDataMap as f, type TokenOperationResult as g, type UpdateTokenResult as h, buildTokens as i, TokenResolver as j, ValidationSeverity as k, type TokenData as l, type BuilderFormat as m, type ProcessSetsOptions as n, type ProcessOptions as o, type RefPath as p };
