PhiaUiDesign.Canvas.Variables (phia_ui v0.1.17)

Copy Markdown View Source

Variable/token system for the PhiaUI Design canvas.

Variables are stored in the scene's ETS table under the :__variables__ key. Each variable has a name, value, type, and optional theme overrides.

Variable references in attrs use the "$name" syntax. The resolve/3 function replaces these references with concrete values based on the current theme.

Variable definition

%{
  value: "#3b82f6",
  type: :color,
  theme_overrides: %{dark: "#60a5fa"}
}

Summary

Functions

Delete a single variable.

Get all variables from the scene.

Check if a value is a variable reference ("$...").

Set a single variable.

Merge multiple variables at once.

Resolve a value that may be a variable reference.

Resolve all variable references in an attrs map.

Types

variable_def()

@type variable_def() :: %{
  value: term(),
  type: :color | :spacing | :number | :string,
  theme_overrides: %{optional(atom()) => term()}
}

Functions

delete(scene, name)

@spec delete(reference(), String.t()) :: :ok

Delete a single variable.

get_all(scene)

@spec get_all(reference()) :: %{required(String.t()) => variable_def()}

Get all variables from the scene.

is_variable_ref?(arg1)

@spec is_variable_ref?(term()) :: boolean()

Check if a value is a variable reference ("$...").

put(scene, name, definition)

@spec put(reference(), String.t(), variable_def()) :: :ok

Set a single variable.

put_all(scene, variables_map)

@spec put_all(reference(), %{required(String.t()) => variable_def()}) :: :ok

Merge multiple variables at once.

resolve(value, scene, theme)

@spec resolve(term(), reference(), atom()) :: term()

Resolve a value that may be a variable reference.

If the value is a string starting with "$", look it up in the scene's variables and return the concrete value (respecting theme overrides). Otherwise, return the value as-is.

resolve_attrs(attrs, scene, theme)

@spec resolve_attrs(map(), reference(), atom()) :: map()

Resolve all variable references in an attrs map.