variable_graph.ts

Variable dependency graph for bundled CSS generation.

Builds a dependency graph from style variables to enable transitive resolution of CSS custom properties. When a variable is needed, all variables it depends on are also included.

Declarations
#

11 declarations

view source

build_variable_graph
#

variable_graph.ts view source

(variables: { name: string; light?: string | undefined; dark?: string | undefined; summary?: string | undefined; }[], content_hash: string): VariableDependencyGraph

Builds a dependency graph from an array of style variables.

variables

array of StyleVariable objects

type { name: string; light?: string | undefined; dark?: string | undefined; summary?: string | undefined; }[]

content_hash

hash of the source for cache invalidation

type string

returns

VariableDependencyGraph

build_variable_graph_from_options
#

variable_graph.ts view source

(variables: VariablesOption): VariableDependencyGraph

Builds a variable dependency graph from a variables option. Handles all option forms: undefined (defaults), null (disabled), array, or callback.

variables

the variables option from generator config

returns

VariableDependencyGraph

VariableDependencyGraph built from the resolved variables

find_similar_variable
#

variable_graph.ts view source

(graph: VariableDependencyGraph, name: string): string | null

Finds the most similar variable in the graph to the given name. Returns null if no variable exceeds the similarity threshold.

graph

the variable dependency graph

name

the variable name to find similar matches for

type string

returns

string | null

the most similar variable name, or null if none are similar enough

generate_theme_css
#

variable_graph.ts view source

(graph: VariableDependencyGraph, resolved_variables: Set<string>, specificity?: number): { light_css: string; dark_css: string; }

Generates theme CSS for the resolved variables.

graph

the variable dependency graph

resolved_variables

set of variable names to include

type Set<string>

specificity

number of times to repeat the selector (default 1)

type number
default 1

returns

{ light_css: string; dark_css: string; }

object with light_css and dark_css strings

get_all_variable_names
#

has_variable
#

variable_graph.ts view source

(graph: VariableDependencyGraph, name: string): boolean

Checks if a variable exists in the graph.

graph

the variable dependency graph

name

variable name to check (without -- prefix)

type string

returns

boolean

true if the variable exists in the graph

resolve_variables_option
#

variable_graph.ts view source

(variables: VariablesOption): { name: string; light?: string | undefined; dark?: string | undefined; summary?: string | undefined; }[]

Resolves a variables option to a concrete array of style variables.

variables

the variables option (undefined, null, array, or callback)

returns

{ name: string; light?: string | undefined; dark?: string | undefined; summary?: string | undefined; }[]

resolved array of style variables, or empty array if null

resolve_variables_transitive
#

variable_graph.ts view source

(graph: VariableDependencyGraph, initial_variables: Iterable<string>): ResolveVariablesResult

Resolves variables transitively using DFS with cycle detection. When a variable is requested, all variables it depends on are included. Both light and dark dependencies are always resolved together.

graph

the variable dependency graph

initial_variables

initial set of variable names to resolve

type Iterable<string>

returns

ResolveVariablesResult

ResolveVariablesResult with all transitive dependencies

ResolveVariablesResult
#

variable_graph.ts view source

ResolveVariablesResult

Result from transitive variable resolution.

variables

All resolved variable names

type Set<string>

warnings

Warning messages for cycles

type Array<string>

missing

Variable names that were requested but not found in the graph

type Set<string>

StyleVariableInfo
#

variable_graph.ts view source

StyleVariableInfo

Information about a single style variable and its dependencies.

name

Variable name (without -- prefix)

type string

light_deps

Variables referenced in the light value

type Set<string>

dark_deps

Variables referenced in the dark value

type Set<string>

light_css

The CSS value for light mode, or undefined if not defined

type string | undefined

dark_css

The CSS value for dark mode, or undefined if not defined

type string | undefined

VariableDependencyGraph
#

variable_graph.ts view source

VariableDependencyGraph

Dependency graph for style variables.

variables

Map from variable name to its info

type Map<string, StyleVariableInfo>

content_hash

Content hash for cache invalidation

type string

Depends on
#

Imported by
#