Class CssVariableResolver
- Namespace
- SharpVectors.Renderers.Wpf
- Assembly
- SharpVectors.Rendering.Wpf.dll
Resolves CSS custom property (variable) references with support for fallbacks, nested variables, and fallback chains.
public static class CssVariableResolver
- Inheritance
-
CssVariableResolver
- Inherited Members
Remarks
Specification: CSS Cascading Variables Module Level 1 (css-variables-1)
Purpose:
This resolver robustly handles CSS var() function calls that may be unresolved at render time. It supports fallback extraction, nested variables, fallback chains, and cycle detection.
Supported Patterns:
- Simple: "var(--my-color)" → empty (unresolved)
- With fallback: "var(--my-color, #FF0000)" → "#FF0000"
- Nested fallback: "var(--missing, var(--also-missing, #000))" → "#000" (recursive resolution)
- Multiple vars: "var(--a) var(--b, #111)" → processed independently
- Whitespace handling: "var( --name , fallback )" → normalized
Edge Cases Handled:
- Circular references: Tracked via depth limit and visited set to prevent infinite recursion
- Unresolved chains: Falls back to empty string if no terminal value found
- Malformed syntax: Treated as non-variable, returned unchanged
Methods
- ResolveVariables(string)
Resolves CSS variable references in a property value with support for fallbacks and nested variables.