LiveStyle.UsageManifest (LiveStyle v0.14.0)
View SourceTracks which LiveStyle classes are actually used in code.
This module provides a data structure for tracking class usage at compile time, enabling tree-shaking of unused styles (StyleX-style optimization).
Usage Tracking
When css/1 macros expand, they record which classes are referenced.
This allows the CSS generator to emit only styles that are actually used.
Data Structure
Usage is stored as a MapSet of {module, class_name} tuples where:
moduleis the defining module (e.g.,MyApp.Button)class_nameis the atom name (e.g.,:primary)
Example
usage = UsageManifest.empty()
usage = UsageManifest.record_usage(usage, MyApp.Button, :primary)
UsageManifest.used?(usage, MyApp.Button, :primary) #=> true
Summary
Functions
Returns an empty usage manifest.
Checks if a class is used by its manifest key.
Marks all classes from a manifest as used.
Merges two usage manifests.
Records that a class is used.
Returns the number of recorded usages.
Converts usage manifest to a list of {module, class_name} tuples.
Checks if a class is used.
Types
Functions
@spec empty() :: t()
Returns an empty usage manifest.
Checks if a class is used by its manifest key.
Manifest keys have the format "Elixir.Module.class_name".
Parameters
usage- The usage manifestkey- The manifest key (e.g., "Elixir.MyApp.Button.primary")
Returns
true if the class has been recorded as used, false otherwise.
Marks all classes from a manifest as used.
This is useful for testing where you want to verify CSS output
without needing to explicitly call css/1 for each class.
Similar to StyleX's treeshakeCompensation option.
Parameters
usage- The current usage manifestmanifest- The LiveStyle manifest containing class definitions
Returns
Updated usage manifest with all classes marked as used.
Merges two usage manifests.
Parameters
usage1- First usage manifestusage2- Second usage manifest
Returns
A new usage manifest containing all entries from both.
Records that a class is used.
Parameters
usage- The current usage manifestmodule- The module defining the classclass_name- The atom name of the class
Returns
Updated usage manifest with the class recorded.
@spec size(t()) :: non_neg_integer()
Returns the number of recorded usages.
Converts usage manifest to a list of {module, class_name} tuples.
Checks if a class is used.
Parameters
usage- The usage manifestmodule- The module defining the classclass_name- The atom name of the class
Returns
true if the class has been recorded as used, false otherwise.