class Opal::ThemeStore

Overview

Registry and preset repository for UI semantic themes. Includes 16 calibrated presets, JSON serialization/deserialization for custom user themes, reactive .on_change subscription hooks, and accessibility contrast auditing.

Defined in:

opal/style/theme_store.cr

Class Method Summary

Class Method Detail

def self.all : Array(Theme) #

Returns all registered themes.


[View source]
def self.clear_listeners : Nil #

Clears all change listeners


[View source]
def self.contrast_analysis(theme : Theme) : Hash(String, Float64) #

Calculates WCAG 2.1 contrast ratios for key UI color pairings in a theme.


[View source]
def self.current : Theme #

Returns the currently active global theme.


[View source]
def self.current=(theme : Theme | Symbol | String) : Theme #

Sets the currently active global theme and notifies subscribers.


[View source]
def self.export_json(theme : Theme) : String #

Exports a theme to a JSON string representation.


[View source]
def self.export_kv(theme : Theme) : String #

Exports a theme to a clean, human-readable key-value (.theme) string.


[View source]
def self.get(name : Symbol | String) : Theme #

Fetches a theme by name, falling back to catppuccin_mocha or default.


[View source]
def self.has?(name : Symbol | String) : Bool #

Checks if a theme exists by name.


[View source]
def self.import_json(json_str : String) : Theme #

Imports a theme from a JSON string representation.


[View source]
def self.import_kv(kv_str : String) : Theme #

Imports a theme from a key-value (.theme) string representation.


[View source]
def self.load_file(path : String) : Theme #

Loads a theme from either a JSON (.json) or key-value (.theme) file.


[View source]
def self.names : Array(String) #

Returns names of all registered themes.


[View source]
def self.on_change(&block : Theme -> Nil) : Nil #

Registers a listener callback invoked whenever the active theme changes.


[View source]
def self.register(theme : Theme) : Theme #

Registers a theme in the store.


[View source]
def self.save_file(theme : Theme, path : String) : Nil #

Saves a theme to a file on disk (auto-detects JSON or KV based on file extension).


[View source]