import { PickSpecifyDesignToken, SpecifyDesignTokenTypeName, SpecifyModeAndValueLevelAliasSignature } from '../../../definitions/index.js'; import { TokenState } from '../TokenState.js'; import { ResolvableModeLevelAlias, ResolvableTopLevelAlias, ResolvableValueLevelAlias, UnresolvableModeLevelAlias, UnresolvableTopLevelAlias, UnresolvableValueLevelAlias } from './aliasing.js'; /** * An InnerValue is a wrapper around the primitive value of a token that allows for * mapping over the different possible cases of the inner mode value, being value * level aliases or primitive values. */ export declare class InnerValue, TypeOverride extends SpecifyDesignTokenTypeName = SpecifyDesignTokenTypeName> { #private; tokenState: TokenState; constructor(value: T, tokenState: TokenState); private _matchIsUnresolvableValueLevelAlias; private _matchIsResolvableValueLevelAlias; get isUnresolvableValueLevelAlias(): boolean; get isResolvableValueLevelAlias(): boolean; /** * Allows TypeScript to infer the type of the Value Level Alias. * @param type */ ofType(type: TO): InnerValue, RawValueSignature, TO>; /** * Resolve the Value Level Alias to a raw value - returns Unresolvable aliases otherwise. */ resolveDeepValue(): InnerValue, InitialRawType, TypeOverride>; /** * Map over the Unresolvable Value Level Alias case. * @param fn */ mapUnresolvableValueLevelAlias(fn: (unresolvableAliasRef: Extract) => U): InnerValue | U, InitialRawType, TypeOverride>; /** * Map over the Resolvable Value Level Alias case. * @param fn */ mapResolvableValueLevelAlias(fn: (resolvableAliasRef: ResolvableValueLevelAlias) => U): InnerValue | U, InitialRawType, TypeOverride>; /** * Map over the raw value case. * Important: this method should be called first to avoid re-mapping * the mapUnresolvableValueLevelAlias and/or mapResolvableValueLevelAlias * returned values. * @param fn */ mapPrimitiveValue(fn: (value: Exclude) => U): InnerValue> | U, InitialRawType, TypeOverride>; /** * Extract the mapped value. */ unwrap(): T; /** * Optimistically extract the mapped primitive value. */ unwrapValue(): Exclude; } type SwapAliasSignature = T extends SpecifyModeAndValueLevelAliasSignature ? ResolvableValueLevelAlias | UnresolvableValueLevelAlias : T extends { [k: PropertyKey]: unknown; } ? { [k in keyof T]: InnerValue>; } : T extends Array ? Array>> : T; export type RawValueSignature = SwapAliasSignature['$value'], SpecifyModeAndValueLevelAliasSignature>>; export type TopLevelValueSignature = { [mode: string]: ResolvableModeLevelAlias | UnresolvableModeLevelAlias | RawValueSignature | R; }; /** * A TopLevelValue is a wrapper around a token value that allows for * mapping over the different possible modes and cases of a locally defined token value. */ export declare class TopLevelValue = TopLevelValueSignature> { #private; readonly tokenState: TokenState; constructor(value: TopLevelValueSignature, tokenState: TokenState); private _matchIsUnresolvableModeLevelAlias; private _matchIsResolvableModeLevelAlias; private _matchIsRawValue; /** * Test whether the token value has a mode. * @param mode */ hasMode(mode: string): boolean; /** * Filter the token value to only the given mode. * This method is primarily a performance optimization * to avoid iterating on all modes when only one is needed. * @param mode */ focusOnMode(mode: string): this; /** * Extract the mapped value for a given mode. * @param mode */ pickMode(mode: string): T[number]; /** * Map over token value modes. * @param f */ mapModes(f: (mode: string) => U): TopLevelValue; /** * Deeply resolve the token value to a raw value - returns Unresolvable aliases otherwise. */ resolveDeepValue(): TopLevelValue>; }>; /** * Map over the Unresolvable Mode Level Alias case. * @param fn */ mapUnresolvableModeLevelAlias(fn: (unresolvableAliasRef: Extract, mode: string) => U): TopLevelValue; }>; /** * Map over the Resolvable Mode Level Alias case. * @param fn */ mapResolvableModeLevelAlias(fn: (resolvableAliasRef: Extract>, mode: string) => U): TopLevelValue>; }>; /** * Map over the raw value case. * Important: this method should be called first to avoid re-mapping * the mapUnresolvableModeLevelAlias and/or mapResolvableModeLevelAlias * returned values. * @param fn */ mapRawValue(fn: (rawValue: Exclude>, mode: string) => U): TopLevelValue>; }>; /** * Map over the raw value case and pass the tokenState as well. * This method is useful after calling `resolveDeepValue` because the modes might point to a different tokenState * than the original. Note that the mode as well will be the one of the resolvedToken. * Important: this method should be called first to avoid re-mapping * the mapUnresolvableModeLevelAlias and/or mapResolvableModeLevelAlias * returned values. * @param fn */ mapRawValueWithTokenState(fn: (rawValue: Exclude>, mode: string, tokenState: TokenState) => U): TopLevelValue>; }>; /** * Reduce the token value to an arbitrary output type. * @param f * @param initial */ reduce(f: (acc: G, mode: string, value: T[number]) => G, initial: G): G; /** * Extract the mapped value. */ unwrap(): T; /** * Optimistically extract the mapped value */ unwrapValue(): { [Key in keyof T]: Exclude | UnresolvableModeLevelAlias>; }; } /** * A StatefulValueResult is a wrapper around a token value that allows for * mapping over the different possible cases of a token value. */ export declare class StatefulValueResult | UnresolvableTopLevelAlias | TopLevelValue> { #private; readonly tokenState: TokenState; constructor(value: T, tokenState: TokenState); private _matchIsUnresolvableTopLevelAlias; private _matchIsResolvableTopLevelAlias; private _matchIsTopLevelValue; get isUnresolvableTopLevelAlias(): boolean; get isResolvableTopLevelAlias(): boolean; get isTopLevelValue(): boolean; /** * Deeply resolve the token value to a raw value - returns Unresolvable aliases otherwise. */ resolveDeepValue(): StatefulValueResult>>; /** * Map over the Unresolvable Top Level Alias case. * @param fn */ mapUnresolvableTopLevelAlias(fn: (topLevelAliasRef: Extract) => U): StatefulValueResult>; /** * Map over the Resolvable Top Level Alias case. * @param fn */ mapResolvableTopLevelAlias(fn: (topLevelAliasRef: Extract>) => U): StatefulValueResult>>; /** * Map over the locally defined value of the token wrapped in TopLevelValue. * @param fn */ mapTopLevelValue(fn: (topLevelValue: TopLevelValue) => U): StatefulValueResult>>; /** * Extract the mapped value */ unwrap(): T; /** * Optimistically extract the mapped value at the mode level */ unwrapValue(): Exclude | UnresolvableTopLevelAlias>; } export {};