(value: string): string | null Checks if a value contains a possibly invalid calc expression.
value
- The formatted CSS value
stringreturns
string | null Warning message if suspicious, null otherwise
CSS-literal syntax parser, validator, and interpreter.
Enables writing utility classes using actual CSS syntax:
- display:flex → .display\:flex { display: flex; }
- hover:opacity:80% → .hover\:opacity\:80\%:hover { opacity: 80%; }
- md:dark:hover:before:opacity:80% → nested CSS with media query, ancestor, state, pseudo-element
@see {@link https://github.com/fuzdev/fuz_css} for documentation
24 declarations
(value: string): string | null Checks if a value contains a possibly invalid calc expression.
value- The formatted CSS value
stringstring | null Warning message if suspicious, null otherwise
CssLiteralOutput Information needed to generate CSS output for a CSS-literal class.
declarationCSS declaration (property: value;)
stringselectorFull CSS selector including pseudo-classes/elements
stringmedia_wrapperMedia query wrapper if any
string | nullancestor_wrapperAncestor wrapper if any
string | nullCssLiteralParseResult Result of parsing a CSS-literal class name.
Uses a discriminated union (Result type) because parsing a single class is binary: it either succeeds or fails entirely. This differs from which uses embedded diagnostics because file extraction can partially succeed (some classes extracted, others have errors).
Uses | null for diagnostics to avoid allocating empty arrays.
Callers should use a guard pattern: if (result.diagnostics) { ... }
(segments: string[], class_name: string): ModifierExtractionResult Extracts and validates modifiers from the beginning of a segments array. Modifiers are consumed from the front until a non-modifier segment is found.
Used by both CSS-literal parsing and modified class interpretation.
segments- Array of colon-separated segments
string[]class_name- Original class name for error messages
stringModifierExtractionResult ModifierExtractionResult with modifiers and remaining segments, or error
(class_name: string): string[] Extracts colon-separated segments from a class name, handling parentheses. Parenthesized content (like function arguments) is kept intact.
class_namestringstring[] ExtractedModifiers Extracted modifiers from a class name. Used by both CSS-literal parsing and modified class interpretation.
mediaMedia modifier (breakpoint or feature query)
ModifierDefinition | nullancestorAncestor modifier (dark/light)
ModifierDefinition | nullstatesState modifiers in alphabetical order (can have multiple)
Array<ModifierDefinition>pseudo_elementPseudo-element modifier (before, after, etc.)
ModifierDefinition | null(value: string): string Formats a CSS-literal value for CSS output.
- Replaces ~ with space
- Ensures space before !important
value- Raw value from class name
stringstring Formatted CSS value
(output: CssLiteralOutput): string Generates simple CSS for a CSS-literal class (without grouping). Used by the interpreter for basic output.
output- The CSS-literal output info
string CSS string for this class
(parsed: ParsedCssLiteral): string Generates the CSS declaration for a parsed CSS-literal class.
parsedstring (escaped_class_name: string, parsed: ParsedCssLiteral): string Generates the CSS selector for a parsed CSS-literal class. Includes state pseudo-classes and pseudo-element in the selector.
escaped_class_namestringparsedstring (modifiers: ExtractedModifiers): boolean Checks if extracted modifiers contain any modifier. Useful for tooling that needs to detect modified classes.
modifiersboolean (parsed: ParsedCssLiteral): boolean Checks if a parsed CSS literal has any modifiers.
parsedboolean (class_name: string, escaped_class_name: string, css_properties: Set<string> | null): InterpretCssLiteralResult Interprets a CSS-literal class and returns CSS generation info.
Callers should first check is_possible_css_literal() to filter non-CSS-literal classes.
class_name- The class name to interpret
stringescaped_class_name- The CSS-escaped version of the class name
stringcss_properties- Set of valid CSS properties from load_css_properties().
Pass null to skip property validation.
Set<string> | nullInterpretCssLiteralResult Result with output and warnings on success, or error on failure
InterpretCssLiteralResult Result of interpreting a CSS-literal class.
Uses | null for warnings to avoid allocating empty arrays.
Callers should use a guard pattern: if (result.warnings) { ... }
(class_name: string): boolean Checks if a class name could be a CSS-literal class. Quick check before attempting full parse.
class_name- The class name to check
stringboolean True if it could be CSS-literal syntax
(property: string, properties: Set<string> | null): boolean Checks if a property name is a valid CSS property. Custom properties (--*) always return true.
property- The CSS property name to validate
stringproperties- Set of valid CSS properties from load_css_properties().
Pass null to skip validation.
Set<string> | nullboolean True if valid CSS property or custom property
LiteralResolutionResult Result of attempting to resolve a CSS literal for composition.
(): Promise<Set<string>> Loads CSS properties from
Promise<Set<string>> ModifierExtractionResult Result of extracting modifiers from segments.
(class_name: string, css_properties: Set<string> | null): CssLiteralParseResult Parses a CSS-literal class name into its components.
class_name- The class name to parse
stringcss_properties- Set of valid CSS properties from load_css_properties().
Pass null to skip property validation.
Set<string> | nullCssLiteralParseResult CssLiteralParseResult with parsed data or error
ParsedCssLiteral Parsed CSS-literal class with all components extracted.
class_nameOriginal class name
stringmediaMedia modifier (breakpoint or feature query)
ModifierDefinition | nullancestorAncestor modifier (dark/light)
ModifierDefinition | nullstatesState modifiers in alphabetical order (can have multiple)
Array<ModifierDefinition>pseudo_elementPseudo-element modifier (before, after, etc.)
ModifierDefinition | nullpropertyCSS property name
stringvalueCSS value (with ~ replaced by spaces)
string(typo: string, properties: Set<string> | null): string | null Suggests a correct property name for a typo using Levenshtein distance.
typo- The mistyped property name
stringproperties- Set of valid CSS properties from load_css_properties().
Pass null to skip suggestions.
Set<string> | nullstring | null The suggested property or null if no close match (Levenshtein distance > 2)
(typo: string): string | null Suggests a correct modifier name for a typo using Levenshtein distance.
typo- The mistyped modifier name
stringstring | null The suggested modifier or null if no close match (Levenshtein distance > 2)
(class_name: string, css_properties: Set<string> | null, context_class_name: string): LiteralResolutionResult Attempts to resolve a class name as an unmodified CSS literal for composition.
Used by resolve_composes to support literals in composes arrays.
Returns the declaration if successful, null if not a literal, or an error
if it's a literal with issues (modifiers, invalid property, etc.).
class_name- The class name to try resolving
stringcss_properties- Set of valid CSS properties, or null to skip validation
Set<string> | nullcontext_class_name- The class being defined (for error messages)
stringLiteralResolutionResult Resolution result with declaration, or error, or null if not a literal