UNPKG

@terrazzo/token-tools

Version:
403 lines (401 loc) 14.2 kB
import { ObjectNode } from "@humanwhocodes/momoa"; //#region src/types.d.ts interface TokenCore<E extends {} = Record<string, unknown>> { $description?: string; $deprecated?: string | boolean; $extensions?: E; } type Token = BooleanToken | BorderToken | ColorToken | CubicBezierToken | DimensionToken | DurationToken | FontFamilyToken | FontWeightToken | GradientToken | LinkToken | NumberToken | ShadowToken | StringToken | TransitionToken | TypographyToken | StrokeStyleToken; type TokensSet = Record<string, Token>; type AliasValue = string; interface AliasToken extends TokenCore { $type?: never; $value: AliasValue; } /** * 8.? Boolean (beta) */ interface BooleanToken extends TokenCore { $type: 'boolean'; $value: BooleanValue | AliasValue; } type BooleanValue = boolean; /** * 9.3 Border */ interface BorderToken extends TokenCore { $type: 'border'; $value: BorderValue | AliasValue; } interface BorderValue { color: ColorValue | AliasValue; width: DimensionValue | AliasValue; style: StrokeStyleValue | AliasValue; } /** * 8.1 Color */ interface ColorToken extends TokenCore { $type: 'color'; $value: ColorValue | AliasValue; } type ColorValue = string | { colorSpace: ColorSpace; channels?: [number, number, number]; components: [number, number, number]; alpha?: number; hex?: string; }; interface CubicBezierToken extends TokenCore { $type: 'cubicBezier'; $value: CubicBezierValue | AliasValue; } type CubicBezierValue = [number, number, number, number]; /** * 8.2 Dimension */ interface DimensionToken extends TokenCore { $type: 'dimension'; $value: DimensionValue | AliasValue; } interface DimensionValue { value: number; unit: 'px' | 'em' | 'rem'; } /** * 8.5 Duration */ interface DurationToken extends TokenCore { $type: 'duration'; $value: DurationValue | AliasValue; } interface DurationValue { value: number; unit: 'ms' | 's'; } /** * 9.6 Gradient */ interface GradientToken extends TokenCore { $type: 'gradient'; $value: GradientValue | AliasValue; } type GradientValue = GradientStop[]; interface GradientStop { color: ColorValue | AliasValue; position: NumberValue | AliasValue; } /** * 8.3 Font Family */ interface FontFamilyToken extends TokenCore { $type: 'fontFamily'; $value: FontFamilyValue | AliasValue; } type FontFamilyValue = string | string[]; /** * 8.4 Font Weight */ interface FontWeightToken extends TokenCore { $type: 'fontWeight'; $value: FontWeightValue | AliasValue; } type FontWeightValue = 'thin' | 'hairline' | 'extra-light' | 'ultra-light' | 'light' | 'normal' | 'regular' | 'book' | 'medium' | 'semi-bold' | 'demi-bold' | 'bold' | 'extra-bold' | 'ultra-bold' | 'black' | 'heavy' | 'extra-black' | 'ultra-black' | number; /** * 8.? Link (beta) */ interface LinkToken extends TokenCore { $type: 'link'; $value: LinkValue | AliasValue; } type LinkValue = string; /** * 8.7 Number */ interface NumberToken extends TokenCore { $type: 'number'; $value: NumberValue | AliasValue; } type NumberValue = number; /** * 8.? String (beta) */ interface StringToken extends TokenCore { $type: 'string'; $value: StringValue | AliasValue; } type StringValue = string; /** * 9.2 Stroke Style */ interface StrokeStyleToken extends TokenCore { $type: 'strokeStyle'; $value: StrokeStyleValue | AliasValue; } type StrokeStyleValue = 'solid' | 'dashed' | 'dotted' | 'double' | 'groove' | 'ridge' | 'outset' | 'inset' | StrokeStyleValueExpanded; interface StrokeStyleValueExpanded { dashArray: (DimensionValue | AliasValue)[]; lineCap: 'round' | 'butt' | 'square'; } /** * 9.5 Shadow */ interface ShadowToken extends TokenCore { $type: 'shadow'; $value: ShadowValue | ShadowValue[] | AliasValue; } interface ShadowValue { color: ColorValue | AliasValue; offsetX: DimensionValue | AliasValue; offsetY: DimensionValue | AliasValue; blur?: DimensionValue | AliasValue; spread?: DimensionValue | AliasValue; inset?: boolean; } /** * 9.4 Transition */ interface TransitionToken extends TokenCore { $type: 'transition'; $value: TransitionValue | AliasValue; } interface TransitionValue { duration: DurationValue | AliasValue; delay: DurationValue | AliasValue; timingFunction: CubicBezierValue | AliasValue; } /** * 9.7 Typography */ interface TypographyToken extends TokenCore { $type: 'typography'; $value: TypographyValue | AliasValue; } interface TypographyValue { fontFamily?: FontFamilyValue | AliasValue; fontSize?: DimensionValue | AliasValue; fontStyle?: string; fontVariant?: string; fontVariantAlternatives?: string; fontVariantCaps?: string; fontVariantEastAsian?: string; fontVariantEmoji?: string; fontVariantLigatures?: string; fontVariantNumeric?: string; fontVariantPosition?: string; fontVariationSettings?: string; fontWeight?: FontWeightValue | AliasValue; letterSpacing?: DimensionValue | AliasValue; lineHeight?: DimensionValue | NumberValue | AliasValue; textDecoration?: string; textTransform?: string; [key: string]: unknown; } interface GroupCore { $description?: string; $type?: Token['$type']; $extensions?: Record<string, unknown>; } type Group = GroupCore | { [key: string]: GroupOrToken | GroupCore; }; type GroupOrToken = Group | Token; /** Modes only have a subset of information from the root token, that is allowed to diverge (e.g. id will never differ, so don’t bother storing it on mode). */ type TokenMode<T extends TokenNormalized> = Pick<T, '$value' | 'aliasOf' | 'aliasChain' | 'partialAliasOf' | 'source'> & { originalValue: T['originalValue']['$value']; }; type ModeMap<T extends TokenNormalized> = { '.': TokenMode<T>; [mode: string]: TokenMode<T> | undefined; }; interface TokenNormalizedCore<$type extends Token['$type']> { $type: $type; $description?: string; $extensions?: Record<string, unknown>; $deprecated?: string | boolean; id: string; source: { loc?: string; node: ObjectNode; }; /** The **final** aliased ID */ aliasOf?: string; /** The entire alias chain, starting from the source token. The last item will match `.aliasOf`. */ aliasChain?: string[]; /** If this token is aliased in other tokens. */ aliasedBy?: string[]; group: { $description?: string; $extensions?: Record<string, unknown>; $type?: $type; id: string; /** IDs of all tokens contained in this group */ tokens: string[]; }; } type TokenNormalized = BooleanTokenNormalized | BorderTokenNormalized | ColorTokenNormalized | CubicBezierTokenNormalized | DimensionTokenNormalized | DurationTokenNormalized | FontFamilyTokenNormalized | FontWeightTokenNormalized | GradientTokenNormalized | LinkTokenNormalized | NumberTokenNormalized | ShadowTokenNormalized | StringTokenNormalized | StrokeStyleTokenNormalized | TransitionTokenNormalized | TypographyTokenNormalized; type TokenNormalizedSet = Record<string, TokenNormalized>; interface BooleanTokenNormalized extends TokenNormalizedCore<'boolean'> { $value: BooleanValue; partialAliasOf?: never; mode: ModeMap<BooleanTokenNormalized>; originalValue: BooleanToken | AliasToken; } interface BorderTokenNormalized extends TokenNormalizedCore<'border'> { $value: BorderValueNormalized; partialAliasOf?: Partial<Record<keyof BorderValueNormalized, string>>; mode: ModeMap<BorderTokenNormalized>; originalValue: BorderToken | AliasToken; } interface BorderValueNormalized { color: ColorValueNormalized; width: DimensionValue; style: StrokeStyleValueExpanded; } interface ColorTokenNormalized extends TokenNormalizedCore<'color'> { $value: ColorValueNormalized; mode: ModeMap<ColorTokenNormalized>; partialAliasOf?: never; originalValue: ColorToken | AliasToken; } interface ColorValueNormalized { /** * Colorspace * @default "srgb" * @see https://www.w3.org/TR/css-color-4/#predefined */ colorSpace: ColorSpace; channels?: [number, number, number]; /** Color components. Will be normalized to 1 unless the colorspace prevents it (e.g. XYZ, LAB) */ components: [number, number, number]; /** Alpha channel, normalized from 0 – 1 */ alpha: number; /** Hex fallback (for sRGB) */ hex?: string; } type ColorSpace = 'a98-rgb' | 'display-p3' | 'hsl' | 'hwb' | 'lab' | 'lab-d65' | 'lch' | 'okhsv' | 'oklab' | 'oklch' | 'prophoto-rgb' | 'rec2020' | 'srgb-linear' | 'srgb' | 'xyz' | 'xyz-d50' | 'xyz-d65'; interface CubicBezierTokenNormalized extends TokenNormalizedCore<'cubicBezier'> { $value: CubicBezierValue; partialAliasOf?: [string | undefined, string | undefined, string | undefined, string | undefined]; mode: ModeMap<CubicBezierTokenNormalized>; originalValue: CubicBezierToken | AliasToken; } interface DimensionTokenNormalized extends TokenNormalizedCore<'dimension'> { $value: DimensionValue; partialAliasOf?: never; mode: ModeMap<DimensionTokenNormalized>; originalValue: DimensionToken | AliasToken; } interface DurationTokenNormalized extends TokenNormalizedCore<'duration'> { $value: DurationValue; partialAliasOf?: never; mode: ModeMap<DurationTokenNormalized>; originalValue: DurationToken | AliasToken; } interface FontFamilyTokenNormalized extends TokenNormalizedCore<'fontFamily'> { $value: FontFamilyValueNormalized; aliasOf?: string; partialAliasOf?: never; mode: ModeMap<FontFamilyTokenNormalized>; originalValue: FontFamilyToken | AliasToken; } type FontFamilyValueNormalized = string[]; interface FontWeightTokenNormalized extends TokenNormalizedCore<'fontWeight'> { $type: 'fontWeight'; $value: FontWeightValueNormalized; aliasOf?: string; partialAliasOf?: never; mode: ModeMap<FontWeightTokenNormalized>; originalValue: FontWeightToken | AliasToken; } type FontWeightValueNormalized = number; interface GradientTokenNormalized extends TokenNormalizedCore<'gradient'> { $value: GradientValueNormalized; partialAliasOf?: Partial<Record<keyof GradientStopNormalized, string>>[]; mode: ModeMap<GradientTokenNormalized>; originalValue: GradientTokenNormalized | AliasToken; } type GradientValueNormalized = GradientStopNormalized[]; interface GradientStopNormalized { color: ColorValueNormalized; position: number; } interface LinkTokenNormalized extends TokenNormalizedCore<'link'> { $value: LinkValue; partialAliasOf?: never; mode: ModeMap<LinkTokenNormalized>; originalValue: LinkToken | AliasToken; } interface NumberTokenNormalized extends TokenNormalizedCore<'number'> { $value: NumberValue; partialAliasOf?: never; mode: ModeMap<NumberTokenNormalized>; originalValue: NumberToken | AliasToken; } interface ShadowTokenNormalized extends TokenNormalizedCore<'shadow'> { $value: ShadowValueNormalized[]; partialAliasOf?: Partial<Record<keyof ShadowValueNormalized, string>>[]; mode: ModeMap<ShadowTokenNormalized>; originalValue: ShadowToken | AliasToken; } interface ShadowValueNormalized { color: ColorValueNormalized; offsetX: DimensionValue; offsetY: DimensionValue; blur: DimensionValue; spread: DimensionValue; inset: boolean; } interface StringTokenNormalized extends TokenNormalizedCore<'string'> { $value: StringValue; partialAliasOf?: never; mode: ModeMap<StringTokenNormalized>; originalValue: StringTokenNormalized | AliasToken; } interface StrokeStyleTokenNormalized extends TokenNormalizedCore<'strokeStyle'> { $value: StrokeStyleValueExpanded; partialAliasOf?: never; mode: ModeMap<StrokeStyleTokenNormalized>; originalValue: StrokeStyleToken | AliasToken; } interface TransitionTokenNormalized extends TokenNormalizedCore<'transition'> { $value: TransitionValueNormalized; partialAliasOf?: Partial<Record<keyof TransitionValueNormalized, string>>; mode: ModeMap<TransitionTokenNormalized>; originalValue: TransitionToken | AliasToken; } interface TransitionValueNormalized { duration: DurationValue; delay: DurationValue; timingFunction: CubicBezierValue; } interface TypographyTokenNormalized extends TokenNormalizedCore<'typography'> { $value: TypographyValueNormalized; partialAliasOf?: Record<string, string>; mode: ModeMap<TypographyTokenNormalized>; originalValue: TypographyToken | AliasToken; } interface TypographyValueNormalized { fontFamily?: FontFamilyValue; fontSize?: DimensionValue; fontStyle?: string; fontVariant?: string; fontVariantAlternatives?: string; fontVariantCaps?: string; fontVariantEastAsian?: string; fontVariantEmoji?: string; fontVariantLigatures?: string; fontVariantNumeric?: string; fontVariantPosition?: string; fontVariationSettings?: string; fontWeight?: FontWeightValue; letterSpacing?: DimensionValue; lineHeight?: DimensionValue | NumberValue; textDecoration?: string; textTransform?: string; [key: string]: unknown; } //# sourceMappingURL=types.d.ts.map //#endregion export { AliasToken, AliasValue, BooleanToken, BooleanTokenNormalized, BooleanValue, BorderToken, BorderTokenNormalized, BorderValue, BorderValueNormalized, ColorSpace, ColorToken, ColorTokenNormalized, ColorValue, ColorValueNormalized, CubicBezierToken, CubicBezierTokenNormalized, CubicBezierValue, DimensionToken, DimensionTokenNormalized, DimensionValue, DurationToken, DurationTokenNormalized, DurationValue, FontFamilyToken, FontFamilyTokenNormalized, FontFamilyValue, FontFamilyValueNormalized, FontWeightToken, FontWeightTokenNormalized, FontWeightValue, FontWeightValueNormalized, GradientStop, GradientStopNormalized, GradientToken, GradientTokenNormalized, GradientValue, GradientValueNormalized, Group, GroupCore, GroupOrToken, LinkToken, LinkTokenNormalized, LinkValue, ModeMap, NumberToken, NumberTokenNormalized, NumberValue, ShadowToken, ShadowTokenNormalized, ShadowValue, ShadowValueNormalized, StringToken, StringTokenNormalized, StringValue, StrokeStyleToken, StrokeStyleTokenNormalized, StrokeStyleValue, StrokeStyleValueExpanded, Token, TokenCore, TokenMode, TokenNormalized, TokenNormalizedCore, TokenNormalizedSet, TokensSet, TransitionToken, TransitionTokenNormalized, TransitionValue, TransitionValueNormalized, TypographyToken, TypographyTokenNormalized, TypographyValue, TypographyValueNormalized }; //# sourceMappingURL=types-BOWDcBsq.d.ts.map