LiveStyle.Class (LiveStyle v0.13.0)

View Source

Style class definition and lookup for LiveStyle.

This is an internal module that handles the processing of class/2 declarations. You typically don't use this module directly - instead use LiveStyle with the class/2 macro.

Responsibilities

  • Defining static and dynamic style classes
  • Looking up class entries by module and name
  • Orchestrating declaration processing via specialized processors

Internal API Example

# Static class (called by class macro)
LiveStyle.Class.define(MyModule, :button, [display: "flex", padding: "8px"])

# Dynamic class
LiveStyle.Class.define_dynamic(MyModule, :opacity, [:opacity])

# Fetch
LiveStyle.Class.fetch!(MyModule, :button)
# => %{class_string: "x1234 x5678", atomic_classes: [...], ...}

Summary

Functions

Defines a static style class directly in a manifest (for batch operations).

Defines a dynamic style class directly in a manifest (for batch operations).

Defines a static style class.

Defines a dynamic style class.

Fetches a Class by reference.

Gets the Class reference value.

Functions

batch_define(manifest, module, name, declarations, opts \\ [])

@spec batch_define(LiveStyle.Manifest.t(), module(), atom(), keyword(), keyword()) ::
  LiveStyle.Manifest.t()

Defines a static style class directly in a manifest (for batch operations).

This is used by @before_compile to batch all class definitions in a single manifest update, reducing lock contention during compilation.

Returns the updated manifest.

batch_define_dynamic(manifest, module, name, all_props)

@spec batch_define_dynamic(LiveStyle.Manifest.t(), module(), atom(), [atom()]) ::
  LiveStyle.Manifest.t()

Defines a dynamic style class directly in a manifest (for batch operations).

This is used by @before_compile to batch all class definitions in a single manifest update, reducing lock contention during compilation.

Returns the updated manifest.

define(module, name, declarations, opts \\ [])

@spec define(module(), atom(), keyword(), keyword()) :: :ok

Defines a static style class.

Parameters

  • module - The module defining the class
  • name - The class name (atom)
  • declarations - Keyword list of CSS property declarations
  • opts - Options including :file and :line for validation warnings

Example

LiveStyle.Class.define(MyModule, :button, [display: "flex"])

define_dynamic(module, name, all_props)

@spec define_dynamic(module(), atom(), [atom()]) :: :ok

Defines a dynamic style class.

Dynamic classes use CSS variables that are set at runtime via inline styles.

Parameters

  • module - The module defining the class
  • name - The class name (atom)
  • all_props - List of all CSS properties in the class

Example

LiveStyle.Class.define_dynamic(MyModule, :opacity, [:opacity])

fetch!(name)

@spec fetch!(atom() | {module(), atom()}) :: term()

Fetches a Class by reference.

Returns the entry. Raises if not found.

ref(name)

@spec ref(atom() | {module(), atom()}) :: term()

Gets the Class reference value.