import { d as InterpreterResult, L as LanguageError } from './interpreter-C2GNrbRq.js';
import { a as Config, A as ASTNode, I as ISymbolType } from './types-CpUWRnTg.js';

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;
}

/**
 * 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 lint issue or a language error (lexer/parser/interpreter/processor).
 */
type ResolveIssue = LintIssue | 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;

declare enum LintSeverity {
    ERROR = "error",
    WARNING = "warning",
    INFO = "info"
}
/**
 * A lint issue found during token 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 LintIssue {
    code: string;
    severity: LintSeverity;
    message: string;
    tokenName: RefPath;
    path?: (string | number)[];
    line?: number;
    data?: Record<string, unknown>;
}
/**
 * Map of token names to their lint issues.
 */
type LintResult = Map<RefPath, LintIssue[]>;
/**
 * Context provided to lint rules during validation.
 *
 * @property tokenName - The token being validated
 * @property tokenType - Token type (e.g., "color", "opacity")
 * @property config - Interpreter configuration
 * @property allTokens - All tokens in the current set
 * @property resolvedTokens - Previously resolved tokens for cross-validation
 * @property ast - The AST of the token expression
 */
interface LintContext {
    tokenName: RefPath;
    tokenType?: string;
    config?: Config;
    allTokens: TokenDataMap$1;
    resolvedTokens?: ResolvedValueMap;
    ast?: ASTNode;
}
/**
 * A lint rule that validates token values.
 *
 * @property id - Unique identifier for this rule
 * @property severity - Default severity level for issues
 * @property tokenTypes - Optional filter: only run for specific token types
 * @property validate - Validate a token value and return any issues found
 */
interface LintRule {
    id: string;
    severity: LintSeverity;
    tokenTypes?: string[];
    validate(value: InterpreterResult, context: LintContext): LintIssue[];
}
/**
 * Linter configuration.
 *
 * @property rules - Rule overrides: false to disable, severity to override default
 */
interface LintConfig {
    rules?: Record<string, boolean | LintSeverity>;
}
/**
 * Function to create a lint issue.
 */
type CreateIssueFn = (issue: LintIssue) => LintIssue;

declare abstract class BaseLintRule implements LintRule {
    abstract id: string;
    abstract severity: LintSeverity;
    tokenTypes?: string[];
    abstract validate(value: InterpreterResult, context: LintContext): LintIssue[];
    protected createIssue: CreateIssueFn;
}

type TokenTypeValidator = (value: InterpreterResult, context: LintContext, createIssue: CreateIssueFn) => LintIssue | LintIssue[] | null | undefined;
type TokenTypeValidatorMap = Record<string, TokenTypeValidator>;
declare class TypeBasedRule extends BaseLintRule {
    id: string;
    severity: LintSeverity;
    private validators;
    private defaultValidator?;
    constructor(validators?: TokenTypeValidatorMap);
    forType(tokenType: string, validator: TokenTypeValidator): this;
    forDefault(validator: TokenTypeValidator): this;
    /**
     * Returns a copy of the internal validator map.
     * Useful for extending rules.
     */
    getValidators(): Map<string, TokenTypeValidator>;
    /**
     * Returns the default validator, if set.
     */
    getDefaultValidator(): TokenTypeValidator | undefined;
    validate(value: InterpreterResult, context: LintContext): LintIssue[];
}

declare class LintRunner {
    private rules;
    private config;
    constructor(config?: LintConfig);
    addRule(rule: LintRule): this;
    /**
     * Creates a new LintRunner that extends this one with additional/overridden validators.
     *
     * Merges TypeBasedRule validators from the current runner with the provided overrides.
     * Override validators replace existing ones for the same token type.
     * Non-TypeBasedRule rules are preserved in their original order relative to TypeBasedRules.
     *
     * @param overrides - Map of token types to validators to add or override
     * @returns A new LintRunner with merged validators
     *
     * @example
     * const cssRules = css.createLintRunner();
     * const penpotRules = cssRules.extend({
     *   "border-radius": all(css.borderRadius, customValidator),
     *   "stroke-width": penpot.strokeWidthValidator,
     * });
     */
    extend(overrides: TokenTypeValidatorMap): LintRunner;
    lintResult(options: {
        tokenName: RefPath;
        tokenType: string | undefined;
        result: InterpreterResult;
        allTokens: TokenDataMap$1;
        resolvedTokens?: ResolvedValueMap;
        config?: Config;
        ast?: ASTNode;
    }): LintIssue[];
    private isRuleEnabled;
    private applyOverrides;
}

/**
 * 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;
};

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?;
    private linter?;
    processTokens(tokens: TokenInputMap, callbacks?: ProcessorCallbacks, config?: Config, objectParsers?: ObjectParser[], linter?: LintRunner): 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[], linter?: LintRunner): 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[];
    linter?: LintRunner;
}
/**
 * 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, LintRunner as L, type ProcessFilesOptions as P, type ResolveIssue as R, type TokenBuilder as T, type UpdateTokenParams as U, type ProcessResult as a, buildTokens as b, type CreateTokenResult as c, type DeleteTokenResult as d, type ProcessorOutput as e, type ProcessorResult as f, type TokenDataMap as g, type TokenOperationResult as h, TokenResolver as i, type UpdateTokenResult as j, type TokenData as k, type TokenTypeValidator as l, type TokenTypeValidatorMap as m, LintSeverity as n, type LintIssue as o, BaseLintRule as p, type CreateIssueFn as q, type LintConfig as r, type LintContext as s, type LintResult as t, type LintRule as u, TypeBasedRule as v, type BuilderFormat as w, type ProcessSetsOptions as x, type ProcessOptions as y, type RefPath as z };
