/** * 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. * * * * Utilities for flattening nested design token objects into dot-separated * flat keys, and unflattening them back. This is the core algorithm that * enables the unstable_defineVarsNested / unstable_defineConstsNested / * unstable_createThemeNested APIs. * * Architecture: * Nested input → flattenImpl() → existing flat transforms → unflattenObject() → nested output * * A single generic flattenImpl accepts isLeaf/transformLeaf callbacks, * enabling 4 flatten variants (vars, overrides, strings, consts) without * code duplication. */ import type { VarsConfigValue } from './stylex-vars-utils'; import { type CSSType } from './types'; export type NestedVarsValue = | string | CSSType | Readonly<{ readonly [$$Key$$: string]: NestedVarsValue }>; export type NestedStringValue = | string | Readonly<{ readonly [$$Key$$: string]: NestedStringValue }>; export type NestedConstsValue = | string | number | Readonly<{ readonly [$$Key$$: string]: NestedConstsValue }>; /** * Flattens a nested token object for unstable_defineVarsNested. * Stops at strings, CSSType values, and conditional @-rule objects (with `default` key). * * Example: * Input: { button: { bg: 'red', color: { default: 'blue', '@media ...': 'dark' } } } * Output: { 'button.bg': 'red', 'button.color': { default: 'blue', '@media ...': 'dark' } } */ export declare function flattenNestedVarsConfig( obj: Readonly<{ readonly [$$Key$$: string]: NestedVarsValue }>, prefix?: string, ): { [$$Key$$: string]: VarsConfigValue | CSSType }; /** * Flattens override values for unstable_createThemeNested. * Same leaf detection as vars, but CSSType values are unwrapped * (extracts .value) because createTheme expects plain VarsConfigValue. */ export declare function flattenNestedOverridesConfig( obj: Readonly<{ readonly [$$Key$$: string]: NestedVarsValue }>, prefix?: string, ): { [$$Key$$: string]: VarsConfigValue }; /** * Flattens the compiled themeVars object (from defineVarsNested output) * which only contains var(--hash) strings at the leaves. * Used by createThemeNested to flatten the first argument. */ export declare function flattenNestedStringConfig( obj: Readonly<{ readonly [$$Key$$: string]: NestedStringValue }>, prefix?: string, ): { [$$Key$$: string]: string }; /** * Flattens a nested token object for unstable_defineConstsNested. * Only strings and numbers are leaves — ALL objects are recursed into. * This means { default: '#00FF00', hovered: '#0000FF' } becomes two * separate flat keys, NOT a conditional value. * * Example: * Input: { button: { background: { default: '#00FF00', hovered: '#0000FF' } } } * Output: { 'button.background.default': '#00FF00', 'button.background.hovered': '#0000FF' } */ export declare function flattenNestedConstsConfig( obj: Readonly<{ readonly [$$Key$$: string]: NestedConstsValue }>, prefix?: string, ): { [$$Key$$: string]: string | number }; export type Unflattened = V | { [$$Key$$: string]: Unflattened }; export declare function unflattenObject(flatObj: { readonly [$$Key$$: string]: V; }): { [$$Key$$: string]: Unflattened };