CSS parsing, printing, and AST traversal helpers.
The AST is produced by LightningCSS and represented as Elixir maps, lists,
strings, numbers, booleans, and nil. Use parse_ast/2 to parse CSS,
transform the returned AST with prewalk/2 or postwalk/2, and then use
print_ast/2 to serialize it back to CSS.
Summary
Functions
Bundle a CSS file and all its @import dependencies into a single stylesheet.
Like bundle/2 but raises on errors.
Collect values from map nodes that match fun.
Compile CSS using LightningCSS.
Like compile/2 but raises on errors.
Parse CSS into a LightningCSS-backed AST represented as Elixir maps and lists.
Like parse_ast/2 but raises on errors.
Depth-first post-order traversal, like Macro.postwalk/2.
Depth-first post-order traversal with accumulator, like Macro.postwalk/3.
Depth-first pre-order traversal, like Macro.prewalk/2.
Depth-first pre-order traversal with accumulator, like Macro.prewalk/3.
Print CSS from an AST returned by parse_ast/2.
Like print_ast/2 but raises on errors.
Traverse the AST in pre-order and call fun for every map node.
Types
Functions
@spec bundle( String.t(), keyword() ) :: {:ok, css_result()}
Bundle a CSS file and all its @import dependencies into a single stylesheet.
Reads the entry file and all imported files from disk, resolving @import
rules recursively. The result is a single merged stylesheet with all imports
inlined, wrapped in the appropriate @media, @supports, and @layer rules.
Options
:minify— minify the output (default:false):css_modules— enable CSS Modules scoping (default:false):targets— browser targets for autoprefixing
@spec bundle!( String.t(), keyword() ) :: css_result()
Like bundle/2 but raises on errors.
Collect values from map nodes that match fun.
fun should return {:keep, value} to include a value, or :skip to ignore
the node.
@spec compile( String.t(), keyword() ) :: {:ok, css_result()}
Compile CSS using LightningCSS.
Parses, autoprefixes, and optionally minifies CSS. Also handles Vue scoped CSS
transformation, v-bind() extraction, and CSS Modules.
Options
:minify— minify the output (default:false):scoped— apply Vue scoped CSS transformation (default:false):scope_id— scope ID for scoped CSS (e.g."data-v-abc123"):filename— filename for error reporting:css_modules— enable CSS Modules scoping (default:false):targets— browser targets for autoprefixing, map with optional:chrome,:firefox,:safarikeys as major version integers
Examples
iex> {:ok, result} = Vize.CSS.compile(".foo { color: red }")
iex> result.code =~ "color"
true
iex> result.errors
[]
@spec compile!( String.t(), keyword() ) :: css_result()
Like compile/2 but raises on errors.
@spec parse_ast( String.t(), keyword() ) :: {:ok, ast_result()}
Parse CSS into a LightningCSS-backed AST represented as Elixir maps and lists.
Options
:filename— filename for parser locations and error reporting:css_modules— enable CSS Modules parsing (default:false):custom_media— enable custom media parsing (default:false)
Examples
iex> {:ok, result} = Vize.CSS.parse_ast(".foo { background: url('./logo.svg') }")
iex> is_map(result.ast)
true
iex> result.errors
[]
@spec parse_ast!( String.t(), keyword() ) :: ast_result()
Like parse_ast/2 but raises on errors.
Depth-first post-order traversal, like Macro.postwalk/2.
The callback receives every map node after its children and must return the transformed node.
Depth-first post-order traversal with accumulator, like Macro.postwalk/3.
Depth-first pre-order traversal, like Macro.prewalk/2.
The callback receives every map node before its children and must return the node to continue traversing.
Depth-first pre-order traversal with accumulator, like Macro.prewalk/3.
@spec print_ast( map(), keyword() ) :: {:ok, css_result()}
Print CSS from an AST returned by parse_ast/2.
Options
:minify— minify the output (default:false):targets— browser targets for autoprefixing, map with optional:chrome,:firefox,:safarikeys as major version integers
Examples
iex> {:ok, parsed} = Vize.CSS.parse_ast(".foo { color: red }")
iex> {:ok, printed} = Vize.CSS.print_ast(parsed.ast)
iex> printed.code =~ "color"
true
@spec print_ast!( map(), keyword() ) :: css_result()
Like print_ast/2 but raises on errors.
Traverse the AST in pre-order and call fun for every map node.
Returns :ok. Use prewalk/2 or postwalk/2 when you need to transform
the AST.