import { l as InterpreterResult, L as LanguageError } from './interpreter-B7BcLEBz.cjs'; import { e as Config, I as ISymbolType, s as SymbolMetadata } from './types-BMYcHiSq.cjs'; /** * 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 { private nodes; addNode(node: N, dependencies?: N[] | Set): void; removeNode(node: N): void; getNodes(): Map>; 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; } /** * Reference path (token name delimited by `.`) */ type RefPath = string; type TokenInputMap = Map; type TokenDataMap$1 = Map; type ResolvedValueMap = Map; type TokenResult = InterpreterResult | Error; type TokenResultMap = Map; /** * 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; 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; }; }; type CreateTokenResult = TokenOperationResult & { created: boolean; }; type UpdateTokenResult = TokenOperationResult & { updated: boolean; }; type DeleteTokenResult = TokenOperationResult; type ResolveValueParams = { /** The raw token value expression to resolve (e.g. "{baseColors.red}", "16 * 2", "#ff0000") */ value: unknown; /** Token type used for validation (e.g. "color", "dimension"). Only used when `validate` is true. */ type?: string; /** When true, validate the resolved value against the token `type`. Defaults to false. */ validate?: boolean; }; type ResolveValueResult = { /** The resolved value (ISymbolType, string, Error, etc.) */ resolved: InterpreterResult; /** Resolution issues (parse errors, missing references, etc.) */ issues: ResolveIssue[]; }; type ProcessorResult = { graph: DependencyGraph; 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; subgraph: DependencyGraph; }; 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; /** * Resolve a single value expression against the existing warm cache. * No cloning, no graph rebuild, no re-parsing of other tokens. * Use this for lightweight preview resolution (e.g. live form input). * * **Important:** This method reads from the resolver's current cache and * shares its interpreter instance. It is intended for development-time * previews only. Callers that need isolation (e.g. speculative resolution * that must not observe or affect other operations) should clone the * `TokenResolver` first via `build()` on a copy of the token map. * * Must not be called concurrently with `updateToken`, `createToken`, * or `deleteToken` — those methods rebuild the internal resolver and * the shared interpreter state would conflict. */ resolveValue(params: ResolveValueParams): ResolveValueResult; } interface TokenBuilder { 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; interface BuildTokensOptions { builder?: TokenBuilder; 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 before calling this function. * Use processTokens/processTokenSets for automatic normalization of Records and Maps. */ declare function buildTokens>(tokens: TokenDataMap, options?: BuildTokensOptions): ProcessorOutput & { output: T; issues?: IssuesMap; }; type ProcessOptions = BuildTokensOptions; interface ProcessSetsOptions extends ProcessOptions { activeSets?: string[]; activeTheme?: string; } interface ProcessResult> extends ProcessorOutput { output: T; issues?: IssuesMap; } type ProcessFilesOptions = { path: string; outputPath?: string; schemas?: string[]; activeSets?: string[]; activeTheme?: string; builder?: TokenBuilder; 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 TokenData as f, type TokenDataMap as g, type TokenOperationResult as h, TokenResolver as i, type UpdateTokenResult as j, ValidationSeverity as k, buildTokens as l, type BuilderFormat as m, type ProcessSetsOptions as n, type ProcessOptions as o, type RefPath as p };