Luxar Viewer API Documentation - v2026.9.22
    Preparing search index...

    ThemeManager singleton class

    Manages all themes and handles runtime theme switching by injecting CSS custom properties into the document root.

    Index
    instance: ThemeManager | null = null
    themes: Map<string, Theme> = ...

    Map of registered themes by ID

    currentTheme: Theme | null = null

    Currently active theme

    observers: Set<ThemeChangeHandler> = ...

    Theme change observers

    glassRefractionObserverCleanup: (() => void) | null = null

    Cleanup function for the glass refraction observer

    pendingRefractionRAF: number | null = null

    Handle for the requestAnimationFrame call that defers injectGlassRefractionLayers() until the next frame. Tracked so that a dispose() racing the deferred injection can cancel it — otherwise the rAF fires after teardown and re-injects DOM that nothing will clean up.

    • Dispose the current instance and clear the singleton slot.

      Call this on app shutdown (so the next getInstance() builds a fresh manager) or between tests (to isolate state). The instance reference is cleared; the next getInstance() will lazily construct a new one.

      Returns void

    • Dispose the theme manager and clean up all resources

      This method:

      • Clears all theme change observers
      • Clears all registered themes
      • Removes all CSS variables
      • Removes data-theme attribute

      After calling dispose(), the ThemeManager instance cannot be reused.

      Returns void

    • Register a theme for use

      Parameters

      • theme: Theme

        Theme to register

      Returns void

      Error if theme with same ID already exists

    • Set the active theme

      Parameters

      • themeId: string

        ID of theme to activate

      Returns void

      Error if theme not found

    • Build the flat --luxar-* -> CSS-value map for a theme.

      Numbers (font weights, line heights, opacity, z-index) are stringified here. Optional theme fields that resolve to undefined are kept in the map and skipped at write time, so variables only land in the DOM when the theme actually defines them.

      Parameters

      Returns Record<string, string | undefined>

    • Set CSS custom properties from theme.

      Iterates the flat variable map from themeToCSSVariables; entries with undefined values are skipped, preserving the existing behavior of not setting properties for unset optional theme fields.

      Parameters

      • root: HTMLElement

        Document root element

      • theme: Theme

        Theme to inject

      Returns void

    • Save current theme to localStorage

      Parameters

      • themeId: string

        Theme ID to save

      Returns void