import * as CSS from 'csstype'; /** * A CSS value that can be a standard value or a token reference (var() string). * * Values are emitted verbatim. TypeScript does **not** validate CSS syntax, so a typo in * `calc()`, `clamp()`, `min()`, `max()`, `url()`, etc. (for example a missing `)`) can produce * invalid CSS that breaks parsing for following rules. Use **`calc`** (tagged template) and * **`clamp`** from `typestyles` to keep function parentheses balanced, or small named helpers; * see the docs “TypeScript Tips” page. */ type CSSValue = string | number; /** * CSS properties with support for nested selectors and at-rules. * Extends csstype's Properties with nesting capabilities. * * For `@…` keys, **`container()`** / **`styles.container()`** infer a **literal** `@container …` template so * `[container({ minWidth: 400 })]` mixes with longhands without casting. For **dynamic** `@…` strings, spread * **`atRuleBlock` / `styles.atRuleBlock`**. Same idea for **`has` / `is` / `where`**: variadic literals narrow * to `&:…` keys; if the key is only known as `string`, spread a one-key object or use `atRuleBlock`. */ interface CSSProperties extends CSS.Properties { /** Nested selector (e.g., '&:hover', `has('.x')`, '& .child', '&::before', '&[data-variant]') */ [selector: `&${string}`]: CSSProperties; /** * Ancestor-prefixed selector where `&` is the styled element (e.g. `html[data-mode="dark"] &`, * `html:not([data-mode="light"]) &`). Runtime serialization replaces every `&` with the class selector. */ [selectorWithAncestor: `${string}&${string}`]: CSSProperties; /** Attribute selector (e.g., '[data-variant]', '[data-variant="primary"]', '[disabled]') */ [attribute: `[${string}]`]: CSSProperties; /** At-rule (e.g., '@media (max-width: 768px)', '@container', '@supports') */ [atRule: `@${string}`]: CSSProperties; } /** * Utility function map used by styles.withUtils(). * Each key becomes an extra style property that expands into CSSProperties. */ type BivariantCallback = { bivarianceHack(value: Arg): Ret; }['bivarianceHack']; type StyleUtils = Record>; type UtilityValue = U[K] extends (value: infer V) => CSSProperties ? V : never; /** * CSS properties augmented with user-defined utility keys. */ type CSSPropertiesWithUtils = CSS.Properties & { [K in keyof U]?: UtilityValue; } & { [selector: `&${string}`]: CSSPropertiesWithUtils; [selectorWithAncestor: `${string}&${string}`]: CSSPropertiesWithUtils; [attribute: `[${string}]`]: CSSPropertiesWithUtils; [atRule: `@${string}`]: CSSPropertiesWithUtils; }; /** * A map of style names to utility-aware CSS property definitions. */ type StyleDefinitionsWithUtils = Record>; /** * A map of variant names to their CSS property definitions. */ type StyleDefinitions = Record; /** * A token value can be a string/number or a nested object of token values. * Supports arbitrarily deep nesting for hierarchical token structures. */ type TokenValues = string | number | { [key: string]: TokenValues; }; /** * A flattened key-value pair for CSS custom property generation. */ type FlatTokenEntry = [key: string, value: string]; /** * Flattens a nested TokenValues object into an array of [key, value] pairs. * Deeply nested objects are flattened with keys joined by hyphens. * * @example * flattenTokens({ text: { primary: '#000' } }) * // => [['text-primary', '#000']] */ declare function flattenTokenEntries(obj: TokenValues, prefix?: string): FlatTokenEntry[]; /** * A typed token reference object. Property access returns var(--namespace-key). * Supports nested access: token.text.primary => var(--namespace-text-primary) */ type TokenRef = T extends string | number ? string : { readonly [K in keyof T]: T[K] extends TokenValues ? TokenRef : string; }; /** * Nested token values where any object level may omit keys (for mode layers that * only tweak a subtree of `base`). */ type DeepPartialTokenValues = string | number | { [key: string]: DeepPartialTokenValues | undefined; }; /** * Theme overrides: namespaces map to full or deeply partial token trees. * Aligns with `tokens.create` namespaces; mode `overrides` often only set a subset of keys. */ type ThemeOverrides = { [namespace: string]: DeepPartialTokenValues | undefined; }; /** * Keyframe stops: 'from', 'to', or percentage strings mapped to CSS properties. */ type KeyframeStops = Record; /** Match a media query (e.g. `(prefers-color-scheme: dark)`). */ type ThemeConditionMedia = { readonly type: 'media'; readonly query: string; }; /** Match an attribute on the themed element (`self`) or an ancestor (`ancestor`). */ type ThemeConditionAttr = { readonly type: 'attr'; readonly name: string; readonly value: string; readonly scope: 'self' | 'ancestor'; }; /** Match a class on the themed element (`self`) or an ancestor (`ancestor`). */ type ThemeConditionClass = { readonly type: 'class'; readonly name: string; readonly scope: 'self' | 'ancestor'; }; /** Raw selector escape hatch — the selector is used as an ancestor context for the theme class. */ type ThemeConditionSelector = { readonly type: 'selector'; readonly selector: string; }; /** All child conditions must hold. */ type ThemeConditionAnd = { readonly type: 'and'; readonly conditions: readonly ThemeCondition[]; }; /** Any child condition must hold (emits separate rules per branch). */ type ThemeConditionOr = { readonly type: 'or'; readonly conditions: readonly ThemeCondition[]; }; /** Negate a single-branch condition (see `tokens.when.not` JSDoc for limits). */ type ThemeConditionNot = { readonly type: 'not'; readonly condition: ThemeCondition; }; /** * A condition that determines **when** a set of token overrides applies. * Conditions compile to media queries, selector prefixes/suffixes, or combinations. */ type ThemeCondition = ThemeConditionMedia | ThemeConditionAttr | ThemeConditionClass | ThemeConditionSelector | ThemeConditionAnd | ThemeConditionOr | ThemeConditionNot; /** * A single mode layer within a theme surface. * Applies `overrides` when `when` is satisfied. */ type ThemeModeDefinition = { readonly id: string; readonly overrides: ThemeOverrides; readonly when: ThemeCondition; }; /** * Configuration for `tokens.createTheme()`. * Provide `modes` (manual) **or** `colorMode` (preset), not both. */ type ThemeConfig = { /** Base token overrides — emitted as `.theme-{name} { … }`. */ base?: ThemeOverrides; /** Manual mode layers with explicit conditions. Mutually exclusive with `colorMode`. */ modes?: ThemeModeDefinition[]; /** Preset mode layers from `tokens.colorMode.*`. Mutually exclusive with `modes`. */ colorMode?: ThemeModeDefinition[]; }; /** * The object returned by `tokens.createTheme()`. * * - `surface.className` — the generated class name (e.g. `"theme-acme"`) * - `surface.name` — the theme name (e.g. `"acme"`) * - `String(surface)` / template interpolation — coerces to `className` */ interface ThemeSurface { readonly className: string; readonly name: string; toString(): string; [Symbol.toPrimitive](hint: string): string; } /** * Styles for a single variant option (or slot variant block). * Union with a permissive record so **`[v.name]: value`** from {@link ComponentInternalVarRef} * (custom properties) infers as `{ [key: string]: … }` and still matches — that shape is not * assignable to {@link CSSProperties} alone, which would otherwise reject the dimensioned overload * and fall through to unrelated `component` overloads. **`Record`** also covers * objects that mix custom-property keys with nested selector blocks like `'&:hover'`. */ type VariantOptionStyle = CSSProperties | Record; /** * A map of variant dimensions to their options (each option is {@link VariantOptionStyle}). */ type VariantDefinitions = Record>; type SlotStyles = Partial>; type SlotVariantDefinitions = Record>>; type VariantDimensions = Record>; type VariantOptionKey = Extract; type VariantSelectionValue = OptionKey | (Extract extends never ? never : true) | (Extract extends never ? never : false); type CompoundSelectionValue = VariantSelectionValue | readonly VariantSelectionValue[]; type ComponentSelections = { [K in keyof V]?: VariantSelectionValue> | null | undefined; }; /** * A CSS custom property reference as a `var(--…)` value (tokens, `createVar()`, component internal vars). */ type CSSVarRef = `var(--${string})`; /** * Leaf shape for `ctx.vars({ … })` — mirrors typed tokens: `value` is the default (merged into `base`); * optional `syntax` / `inherits` register `@property` like typed design tokens. */ type ComponentVarDescriptor = { value: string | number; syntax?: string; inherits?: boolean; }; /** * Nested map of component internal vars (same nesting as `tokens.create` / theme token trees). */ type ComponentVarNode = string | number | ComponentVarDescriptor | { [key: string]: ComponentVarNode; }; type ComponentVarDefinitions = { [key: string]: ComponentVarNode; }; /** * Options for `ctx.var(id, options?)`. Set `value` to merge a default into `base` and as `@property` initial-value when `syntax` is set. */ type ComponentVarOptions = { value?: string | number; syntax?: string; inherits?: boolean; }; /** * Reference to a component-scoped custom property: `.name` for declaration keys and transitions, `.var` for values. */ type ComponentInternalVarRef = { readonly name: string; readonly var: CSSVarRef; }; /** * Context passed to `styles.component(namespace, (ctx) => { ... })` to declare internal custom properties. */ /** Proxy tree returned by `ctx.vars({ … })` — leaves are `{ name, var }`, nested objects are sub-trees. */ type ComponentVarRefTree = { [K in keyof T]: T[K] extends ComponentVarDescriptor | string | number ? ComponentInternalVarRef : ComponentVarRefTree; }; type ComponentConfigContext = { var: (id: string, options?: ComponentVarOptions) => ComponentInternalVarRef; vars: (definitions: T) => ComponentVarRefTree; }; /** * The full config object passed to styles.component() with dimensioned variants. */ type ComponentConfig = { base?: CSSProperties; variants?: V; compoundVariants?: Array<{ variants: { [K in keyof V]?: CompoundSelectionValue>; }; style: VariantOptionStyle; }>; defaultVariants?: ComponentSelections; }; /** * Config for flat variants: `{ base: {...}, elevated: {...}, compact: {...} }`. * Each key besides `base` is a boolean-style variant. * * **`variants`**, **`defaultVariants`**, **`compoundVariants`**, and **`slots`** are forbidden * on this shape so TypeScript does not pick the flat overload for CVA-style or slot configs. * Nested variant maps can otherwise satisfy {@link CSSProperties} too loosely (index signatures), * which produced wrong callable types for `styles.component(ns, (ctx) => ({ variants: … }), { layer })` * when cascade layers are enabled. */ type FlatComponentConfig = { base?: CSSProperties; variants?: never; defaultVariants?: never; compoundVariants?: never; slots?: never; } & Record; /** * Selection object for flat variants: `{ elevated: true, compact: true }`. */ type FlatComponentSelections = { [P in K]?: boolean | null | undefined; }; /** * All possible variant class string keys that can be destructured from a * dimensioned component. Includes 'base' plus all `{dimension}-{option}` keys * flattened from the variants config. */ type DimensionedVariantKeys = { [D in keyof V]: keyof V[D] extends string ? `${D & string}-${keyof V[D] & string}` : never; }[keyof V]; /** * The CVA-style return for dimensioned variants. * Callable as a function, destructurable as an object. */ type ComponentReturn = { /** Call with variant selections to get composed class string (base always included). */ (selections?: ComponentSelections): string; } & { /** The base class string. */ readonly base: string; } & { /** Individual variant class strings, keyed as `{dimension}-{option}`. */ readonly [K in DimensionedVariantKeys]: string; }; /** * The CVA-style return for flat variants. * Callable as a function, destructurable as an object. */ type FlatComponentReturn = { /** Call with variant selections to get composed class string (base always included). */ (selections?: FlatComponentSelections>): string; } & { /** The base class string. */ readonly base: string; } & { /** Individual variant class strings. */ readonly [P in Exclude]: string; }; type MultiSlotConfig = { slots: Slots; } & Partial>; type MultiSlotReturn = { (): Record; } & { readonly [K in Slots[number]]: string; }; type SlotComponentConfig> = { slots: Slots; base?: SlotStyles; variants?: V; compoundVariants?: Array<{ variants: { [K in keyof V]?: CompoundSelectionValue>; }; style: SlotStyles; }>; defaultVariants?: ComponentSelections; }; type SlotComponentFunction> = (selections?: ComponentSelections) => Record; /** * Config for `styles.component` may be a plain object or a function that receives {@link ComponentConfigContext}. */ type ComponentConfigInput = ComponentConfig | ((ctx: ComponentConfigContext) => ComponentConfig); type FlatComponentConfigInput = FlatComponentConfig | ((ctx: ComponentConfigContext) => FlatComponentConfig); type SlotComponentConfigInput> = SlotComponentConfig | ((ctx: ComponentConfigContext) => SlotComponentConfig); type MultiSlotConfigInput = MultiSlotConfig | ((ctx: ComponentConfigContext) => MultiSlotConfig); /** * Extract the variant prop types from a ComponentReturn or ComponentFunction. * * @example * ```ts * const button = styles.component('button', { * variants: { * intent: { primary: {...}, ghost: {...} }, * size: { sm: {...}, lg: {...} }, * }, * }); * * type ButtonProps = ComponentVariants; * // { intent?: 'primary' | 'ghost'; size?: 'sm' | 'lg' } * ``` */ type ComponentVariants = T extends (selections?: ComponentSelections) => unknown ? { [K in keyof V]?: keyof V[K]; } : never; /** * `src` value for {@link FontFaceProps}: a single CSS `src` fragment or multiple * fragments joined with commas (same as authoring `url(...), local(...)` by hand). */ type FontFaceSrc = string | readonly string[]; /** * Font face property declarations. * * Maps to standard `@font-face` descriptors. Values are emitted verbatim in CSS. */ type FontFaceProps = { src: FontFaceSrc; fontWeight?: string | number; fontStyle?: 'normal' | 'italic' | 'oblique' | string; fontDisplay?: 'auto' | 'block' | 'swap' | 'fallback' | 'optional'; fontStretch?: string; unicodeRange?: string; /** `size-adjust` — fallback tuning and font-size-adjust related metrics. */ sizeAdjust?: string; /** `ascent-override` */ ascentOverride?: string; /** `descent-override` */ descentOverride?: string; /** `line-gap-override` */ lineGapOverride?: string; }; /** * Return type of helpers in `typestyles/globals`, passed to `global.style(…)`. * * @example * ```ts * global.style(boxSizing()); * global.style(body({ margin: 0 }, { layer: 'components' })); * ``` */ type GlobalStyleTuple = readonly [selector: string, properties: CSSProperties] | readonly [selector: string, properties: CSSProperties, options: { layer?: string; }]; export { type ComponentSelections as A, type ComponentVarDefinitions as B, type CSSProperties as C, type ComponentVarDescriptor as D, type ComponentVarNode as E, type FlatComponentConfigInput as F, type GlobalStyleTuple as G, type ComponentVarOptions as H, type ComponentVarRefTree as I, type ComponentVariants as J, type DeepPartialTokenValues as K, type FlatComponentConfig as L, type MultiSlotConfigInput as M, type FlatComponentSelections as N, type FlatTokenEntry as O, type FontFaceSrc as P, type KeyframeStops as Q, type SlotComponentConfig as R, type SlotVariantDefinitions as S, type ThemeConditionMedia as T, type SlotStyles as U, type VariantDefinitions as V, type StyleDefinitions as W, type StyleDefinitionsWithUtils as X, type ThemeConditionNot as Y, type VariantOptionStyle as Z, flattenTokenEntries as _, type ThemeConditionAttr as a, type ThemeConditionClass as b, type ThemeConditionSelector as c, type ThemeCondition as d, type ThemeConditionAnd as e, type ThemeConditionOr as f, type ThemeOverrides as g, type ThemeModeDefinition as h, type ThemeSurface as i, type ThemeConfig as j, type TokenValues as k, type TokenRef as l, type ComponentConfigInput as m, type ComponentReturn as n, type FlatComponentReturn as o, type SlotComponentConfigInput as p, type SlotComponentFunction as q, type MultiSlotReturn as r, type StyleUtils as s, type CSSPropertiesWithUtils as t, type FontFaceProps as u, type CSSVarRef as v, type CSSValue as w, type ComponentConfig as x, type ComponentConfigContext as y, type ComponentInternalVarRef as z };