Overview
Shared Light / Dark / System preferences. Apps own their CSS palette and controls.
@absolutejs/themev0.1.0betaFrontend & UXSSR-safe light, dark and system theme preferences for AbsoluteJS applications.
bun add @absolutejs/themeShared Light / Dark / System preferences. Apps own their CSS palette and controls.
themeScript from @absolutejs/theme is a static inline bootstrap. Render it before visible content to restore the saved preference before paint; supply a CSP nonce/hash if your app requires one. It writes data-theme and color-scheme on the document root. Supply CSS media-query defaults for System when JavaScript is unavailable.
React: const { preference, resolved, setPreference } = useTheme() from @absolutejs/theme/react. Use preference for a three-option selector and resolved for canvas/material colors. Defaults to System, reacts to OS changes, syncs across tabs, tolerates unavailable storage, and cleans up listeners. No provider is required. The server snapshot is deterministic for hydration; browser resolution is available after hydration.
Other frameworks: createThemeStore(window) exposes subscribe, getSnapshot, and setPreference. Create one store per document and unsubscribe on teardown. Call subscribe to activate system/storage listeners. SSR can use the exported immutable serverTheme snapshot.
The preference is stored under absolutejs.theme for the current origin. There is no account or cross-device synchronization. Browser storage failures keep the preference in memory for the current page. Changing to System resumes OS tracking.
Outcomes
Shared Light / Dark / System preferences. Apps own their CSS palette and controls.
Hardening checklist
Follow in order
Supported entry points declared by this project’s package manifest. Internal dist paths are not part of the package contract.
Public package entry point declared in package.json.
Scripts declared by this project’s package manifest.
Search the declarations exported by the current package type files. Expand a symbol to inspect its source-backed signature.