/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import type { CSSType } from './VarTypes'; import type { CSSProperties } from './StyleXCSSTypes'; // Using an opaque type to declare ClassNames generated by stylex. declare const StyleXClassNameTag: unique symbol; export type StyleXClassNameFor = string & { _opaque: typeof StyleXClassNameTag; _key: K; _value: V; }; declare const StyleXVarTag: unique symbol; declare class _StyleXVar { private _opaque: typeof StyleXVarTag; private _value: Val; } export type StyleXVar = _StyleXVar & string; export type StyleXClassNameForValue = StyleXClassNameFor; export type StyleXClassNameForKey = StyleXClassNameFor; export type StyleXClassName = StyleXClassNameFor; // Type for arbitrarily nested Array. export type StyleXArray = T | ReadonlyArray>; type PseudoClassStr = `:${string}`; type AtRuleStr = `@${string}`; type CondStr = PseudoClassStr | AtRuleStr; type CSSPropertiesWithExtras = Partial< Readonly< CSSProperties & { '::after': CSSProperties; '::backdrop': CSSProperties; '::before': CSSProperties; '::cue': CSSProperties; '::cue-region': CSSProperties; '::first-letter': CSSProperties; '::first-line': CSSProperties; '::file-selector-button': CSSProperties; '::grammar-error': CSSProperties; '::marker': CSSProperties; // This is a pattern and not a static key so it cannot be typed correctly. // [key: `::part(${string})` | `::slotted(${string})`]: CSSProperties; '::placeholder': CSSProperties; '::selection': CSSProperties; // This is a pattern and not a static key so it cannot be typed correctly. // '::slotted()': CSSProperties; '::spelling-error': CSSProperties; '::target-text': CSSProperties; '::-webkit-scrollbar'?: CSSProperties; '::-webkit-scrollbar-button'?: CSSProperties; '::-webkit-scrollbar-thumb'?: CSSProperties; '::-webkit-scrollbar-track'?: CSSProperties; '::-webkit-scrollbar-track-piece'?: CSSProperties; '::-webkit-scrollbar-corner'?: CSSProperties; '::-webkit-resizer'?: CSSProperties; // webkit styles used for Search in Safari '::-webkit-search-decoration'?: CSSProperties; '::-webkit-search-cancel-button'?: CSSProperties; '::-webkit-search-results-button'?: CSSProperties; '::-webkit-search-results-decoration'?: CSSProperties; // For input ranges in Chromium '::-webkit-slider-thumb'?: CSSProperties; '::-webkit-slider-runnable-track'?: CSSProperties; // For input ranges in Firefox '::-moz-range-thumb'?: CSSProperties; '::-moz-range-track'?: CSSProperties; '::-moz-range-progress'?: CSSProperties; } > >; export type NestedCSSPropTypes = Partial< Readonly<{ [Key in keyof CSSPropertiesWithExtras]: StyleXClassNameFor< Key, CSSPropertiesWithExtras[Key] >; }> >; type NotUndefined = {} | null; type UserAuthoredStyles = | CSSPropertiesWithExtras | { [key: string]: NotUndefined }; export type StyleXSingleStyle = false | (null | undefined | NestedCSSPropTypes); // NOTE: `XStyle` has been deprecated in favor of `StaticStyles` and `StyleXStyles`. export type Keyframes = Readonly<{ [name: string]: CSSProperties }>; export type PositionTry = Readonly<{ // Anchor Positioning Properties positionAnchor?: CSSProperties['positionAnchor']; positionArea?: CSSProperties['positionArea']; // inset Properties top?: CSSProperties['top']; right?: CSSProperties['right']; bottom?: CSSProperties['bottom']; left?: CSSProperties['left']; inset?: CSSProperties['inset']; insetBlock?: CSSProperties['insetBlock']; insetBlockEnd?: CSSProperties['insetBlockEnd']; insetBlockStart?: CSSProperties['insetBlockStart']; insetInline?: CSSProperties['insetInline']; insetInlineEnd?: CSSProperties['insetInlineEnd']; insetInlineStart?: CSSProperties['insetInlineStart']; // margin Properties margin?: CSSProperties['margin']; marginBlock?: CSSProperties['marginBlock']; marginBlockEnd?: CSSProperties['marginBlockEnd']; marginBlockStart?: CSSProperties['marginBlockStart']; marginInline?: CSSProperties['marginInline']; marginInlineEnd?: CSSProperties['marginInlineEnd']; marginInlineStart?: CSSProperties['marginInlineStart']; marginTop?: CSSProperties['marginTop']; marginBottom?: CSSProperties['marginBottom']; marginLeft?: CSSProperties['marginLeft']; marginRight?: CSSProperties['marginRight']; // size properties width?: CSSProperties['width']; height?: CSSProperties['height']; minWidth?: CSSProperties['minWidth']; minHeight?: CSSProperties['minHeight']; maxWidth?: CSSProperties['maxWidth']; maxHeight?: CSSProperties['maxHeight']; blockSize?: CSSProperties['blockSize']; inlineSize?: CSSProperties['inlineSize']; minBlockSize?: CSSProperties['minBlockSize']; minInlineSize?: CSSProperties['minInlineSize']; maxBlockSize?: CSSProperties['maxBlockSize']; maxInlineSize?: CSSProperties['maxInlineSize']; // self alignment properties alignSelf?: CSSProperties['alignSelf']; justifySelf?: CSSProperties['justifySelf']; placeSelf?: CSSProperties['placeSelf']; }>; export type ViewTransitionClass = Readonly<{ group?: CSSProperties; imagePair?: CSSProperties; old?: CSSProperties; new?: CSSProperties; }>; export type LegacyThemeStyles = Readonly<{ [constantName: string]: string }>; type ComplexStyleValueType = T extends StyleXVar ? U extends CSSType ? V : U : T extends string | number | null | symbol ? T : T extends ReadonlyArray ? ComplexStyleValueType : T extends Readonly<{ default: infer A; [cond: CondStr]: infer B }> ? ComplexStyleValueType | ComplexStyleValueType : T; export type MapNamespace = Readonly<{ [Key in keyof CSS]: StyleXClassNameFor>; }>; export type MapNamespaces< S extends { [key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles); }, > = Readonly<{ [Key in keyof S]: S[Key] extends (...args: infer Args) => infer Obj ? (...args: Args) => Readonly<[MapNamespace, InlineStyles]> : MapNamespace; }>; export type StyleX$Create = < const S extends { [key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles); }, >( styles: S, ) => MapNamespaces; export type CompiledStyles = | Readonly<{ [key: string]: StyleXClassName | null | void | never; }> | Readonly<{ theme: StyleXClassName; }>; declare const StyleXInlineStylesTag: unique symbol; export type InlineStyles = { _opaque: typeof StyleXInlineStylesTag; }; type _GenStylePropType = Readonly<{ [Key in keyof CSS]: StyleXClassNameFor>; }> & Partial<{ [Key in Exclude]: never; }>; type GenStylePropType = Readonly< _GenStylePropType >; // Replace `XStyle` with this. export type StaticStyles< CSS extends UserAuthoredStyles = CSSPropertiesWithExtras, > = StyleXArray>; export type StaticStylesWithout = StaticStyles< Omit >; export type StyleXStyles< CSS extends UserAuthoredStyles = CSSPropertiesWithExtras, > = StyleXArray< | null | undefined | false | GenStylePropType | Readonly<[GenStylePropType, InlineStyles]> >; export type StyleXStylesWithout = StyleXStyles< Omit >; declare const StyleXVarGroupTag: unique symbol; export type VarGroup< Tokens extends { [key: string]: any }, ID extends symbol = symbol, > = Readonly<{ [Key in keyof Tokens]: StyleXVar; }> & Readonly<{ __opaqueId: ID; __tokens: Tokens; }> & typeof StyleXVarGroupTag; export type TokensFromVarGroup> = T['__tokens']; export type IDFromVarGroup> = T['__opaqueId']; type TTokens = Readonly<{ [key: string]: | NestedVarObject | StyleXVar | CSSType; }>; type UnwrapVars = T extends StyleXVar ? U : T; export type FlattenTokens = Readonly<{ [Key in keyof T]: T[Key] extends { [key: string]: infer X } ? UnwrapVars : UnwrapVars; }>; type NestedVarObject = | T | Readonly<{ default: NestedVarObject; [key: AtRuleStr]: NestedVarObject; }>; export type StyleX$DefineConsts = < DefaultTokens extends { [key: string]: number | string; }, >( tokens: DefaultTokens, ) => DefaultTokens; export type StyleX$DefineVars = < DefaultTokens extends TTokens, ID extends symbol = symbol, >( tokens: DefaultTokens, ) => VarGroup, ID>; declare class ThemeKey> extends String { private varGroup: VG; } export type Theme, Tag extends symbol = symbol> = Tag & Readonly<{ theme: StyleXClassNameFor, IDFromVarGroup>; }>; type OverridesForTokenType = { [Key in keyof Config]?: NestedVarObject; }; export type StyleX$CreateTheme = < TVars extends VarGroup<{}>, ThemeID extends symbol = symbol, >( baseTokens: TVars, overrides: OverridesForTokenType>, ) => Theme; declare const StyleXMarkerTag: unique symbol; export type StyleX$DefineMarker = () => MapNamespace<{ readonly marker: typeof StyleXMarkerTag; }>; export type StyleX$When = { ancestor: < const Pseudo extends `:${string}` | `[${string}]`, MarkerSymbol extends symbol = symbol, >( _pseudo?: Pseudo, _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>, // @ts-expect-error - Trying to use a symbol in a string is not normally allowed ) => `:where-ancestor(${Pseudo}, ${MarkerSymbol})`; descendant: < const Pseudo extends `:${string}` | `[${string}]`, MarkerSymbol extends symbol = symbol, >( _pseudo?: Pseudo, _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>, // @ts-expect-error - Trying to use a symbol in a string is not normally allowed ) => `:where-descendant(${Pseudo}, ${MarkerSymbol})`; siblingBefore: < const Pseudo extends `:${string}` | `[${string}]`, MarkerSymbol extends symbol = symbol, >( _pseudo?: Pseudo, _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>, // @ts-expect-error - Trying to use a symbol in a string is not normally allowed ) => `:where-sibling-before(${Pseudo}, ${MarkerSymbol})`; siblingAfter: < const Pseudo extends `:${string}` | `[${string}]`, MarkerSymbol extends symbol = symbol, >( _pseudo?: Pseudo, _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>, // @ts-expect-error - Trying to use a symbol in a string is not normally allowed ) => `:where-sibling-after(${Pseudo}, ${MarkerSymbol})`; anySibling: < const Pseudo extends `:${string}` | `[${string}]`, MarkerSymbol extends symbol = symbol, >( _pseudo?: Pseudo, _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>, // @ts-expect-error - Trying to use a symbol in a string is not normally allowed ) => `:where-any-sibling(${Pseudo}, ${MarkerSymbol})`; }; export interface Register {} export type StyleX$Env = Register extends { env: infer TEnv } ? TEnv : Readonly<{ [key: string]: unknown }>;