Theming
Light and dark mode support in Visor — automatic system preference detection and manual theme toggle.
Overview
Visor ships light and dark themes out of the box via @loworbitstudio/visor-core. Both themes are CSS-only — no JavaScript required for the default behavior.
The system works at two levels:
- Automatic —
prefers-color-scheme: darkis respected by default. Users with dark system preferences get dark mode immediately. - Manual toggle — Apply a class or data attribute to override the system preference.
Quick Start
Import the full token bundle in your app's root CSS file:
@import '@loworbitstudio/visor-core';That's it. The bundle includes:
- All primitive tokens (colors, spacing, typography)
- All semantic tokens
- Light theme applied to
:root - Dark theme applied via
@media (prefers-color-scheme: dark)and manual selectors
Using Stock Themes
Four stock themes ship with @loworbitstudio/visor-core as CSS subpath exports. Import the one you want and apply its class to your root element:
@import '@loworbitstudio/visor-core';
@import '@loworbitstudio/visor-core/themes/blackout';<body class="blackout-theme">
<!-- your app -->
</body>Available themes:
| Import | Class |
|---|---|
@loworbitstudio/visor-core/themes/blackout | .blackout-theme |
@loworbitstudio/visor-core/themes/modern-minimal | .modern-minimal-theme |
@loworbitstudio/visor-core/themes/neutral | .neutral-theme |
@loworbitstudio/visor-core/themes/paper | .paper-theme |
@loworbitstudio/visor-core/themes/space | .space-theme |
Each stock theme is class-scoped — it only activates within elements that carry the theme class. Import the base @loworbitstudio/visor-core first; the stock theme import adds color, typography, and spacing overrides on top.
Paper is Low Orbit's shared theme: "Paper" in light, "Paper at night" in dark, set in Satoshi. It has no success, warning or info colour; coral is for alerts only. Beside the Visor tokens it ships theme data under --paper-*:
- Desk scale (desktop density):
--paper-desk-title(900 34/38),--paper-desk-title-2(900 22/27),--paper-desk-row(600 15/20),--paper-desk-body(500 14/20),--paper-desk-sub(400 13/18),--paper-desk-label(700 11/16, uppercase with--paper-track-label),--paper-control-h(36px) and--paper-radius-sheet(28px). Use them withfont: var(--paper-desk-title). Corners map chip 10, field 14, card 20 and tile 24 to--radius-smthrough--radius-xl. - Project hues: twelve OKLCH angles (75 to 339, 24° apart, none in the coral range), each as
--paper-hue-<angle>-fill,-fill-strong,-inkand-solid, with values per mode.
Automatic Dark Mode
No setup required. When a user's OS is set to dark mode, prefers-color-scheme: dark applies the dark token values automatically.
The dark theme activates on :root unless the consumer has explicitly forced light mode:
/* Applied automatically when system prefers dark */
@media (prefers-color-scheme: dark) {
:root:not(.light):not(.theme-light):not([data-theme="light"]) {
--text-primary: var(--color-gray-50);
--surface-page: var(--color-gray-950);
/* ...all adaptive tokens switch to dark values */
}
}Single-Mode Brands (color-scheme)
Some brands only ship one mode. A theme can declare this in its .visor.yaml with the color-scheme field, and the engine generates mode-correct CSS:
name: Animal
color-scheme: dark-only # dark-only | light-only | adaptive (default)
colors:
primary: "#e8b64c"| Value | Generated output |
|---|---|
adaptive (default) | Light palette on :root, dark behind @media (prefers-color-scheme: dark) + manual toggles. |
dark-only | Dark palette pinned directly on the host selector, plus color-scheme: dark. No prefers-color-scheme media query and no light blocks. |
light-only | Light palette pinned on the host, plus color-scheme: light. No dark blocks. |
For a single-mode brand the palette is unconditional — there is nothing to toggle — so the .dark / .light selectors and the prefers-color-scheme fallback are omitted entirely. The emitted color-scheme property also tells the browser to render native UI chrome (form controls, scrollbars) in the matching mode.
This makes the "light-at-:root, dark-behind-prefers" shape ungeneratable for a dark-only brand — the failure mode where a dark brand briefly (or permanently, on a light OS) renders as a white app.
Form-Control Edges (edges)
One line turns off the resting edge of every form control — Input, Textarea, Select, Checkbox, Switch, TagInput, Chip, FileUpload, EmptyState and the edged Button faces — dashed edges included:
# my-theme.visor.yaml
edges: off # on (default) | offedges: off emits --control-edge-width: 0. Nothing moves when it flips, because the edge is an inset outline, not a border. Focus and invalid stay visible, and an unchecked checkbox takes a fill so it still reads as a box. To scope it to one part of an app, set --control-edge-width: 0 on any ancestor. The full token set is in Component Tokens → control.
Hairlines (hairlines)
One line turns off every hairline — the soft separators, dividers and rings coloured by --hairline and --hairline-strong (table row rules, the tab rail, dialog footer rules, popover and doc-frame borders, and more):
# my-theme.visor.yaml
hairlines: off # on (default) | offhairlines: off emits --hairline-width: 0. It is independent of edges: neither switch touches the other's tokens, and focus and invalid states are untouched. To scope it to one part of an app, set --hairline-width: 0 on any ancestor. The full token set is in Component Tokens → hairline.
Corner Shape (corners)
One line draws every rounded corner as a squircle, the smooth superellipse corner, instead of a circular arc:
# my-theme.visor.yaml
corners: squircle # round (default) | squirclecorners: squircle emits --corner-shape: squircle and, in the lowest layer (visor-base), binds corner-shape: var(--corner-shape) to every element. Each border-radius keeps its value; only the curve changes. To keep part of an app round (a circular avatar, a pill), set --corner-shape: round on it or on any ancestor, or write corner-shape: round in its own class, which beats the base layer. With corners absent or round, the theme emits nothing.
Safari Fallback
Safari has no corner-shape yet, on macOS or iOS, and every iPhone browser is Safari underneath. Without help it draws a squircle theme round. A squircle theme also ships a fallback for it, used only where @supports not (corner-shape: squircle) holds and only inside a squircle scope, so Chromium keeps the native corner and the fallback switches itself off once Safari ships the property.
The fallback draws the curve on the components that need it: Button, Dialog, SegmentedControl and ToggleGroup (track, sliding pill and segments), Meter, Badge and Chip. Each sets --squircle-r to its radius clamped to half its height and draws two shared values from the theme:
--squircle-radius, a circle at 0.54 of the squircle's radius: the largest circle that still holds the whole squircle.--squircle-clip, aclip-path: shape()that trims only what that circle draws outside the squircle, and keeps everything outside the box.--squircle-ring, the band between the squircle and the same squircle inset by--squircle-edge. Button, Chip, SegmentedControl and ToggleGroup redraw their edge on a pseudo-element clipped to it, so the edge follows the squircle exactly.
So the fill and those edges are the squircle, and focus rings and shadows stay whole: they are drawn round the smaller circle, never clipped. To draw your own element as a squircle in Safari, give it the same three lines inside the same gates:
@supports not (corner-shape: squircle) {
@container style(--corner-shape: squircle) {
.tile {
--squircle-r: min(var(--radius-xl), 50px); /* the radius, at most half the height */
border-radius: var(--squircle-radius, var(--squircle-r));
clip-path: var(--squircle-clip, none);
}
}
}Its limits:
- Inputs, cards and tabs stay round in Safari. Their focus halo or shadow hugs the box, and Safari cannot shape a shadow to a clip (
filter: drop-shadow()runs beforeclip-path), so a squircle would show a hairline of page between it and the shadow. Round is what Safari draws today; a seam is not acceptable. - Focus rings and shadows on the other components follow the smaller circle, within 1.6% of the radius of the squircle. Give your own element a shadow that hugs it and it has the same seam, so leave it round.
--squircle-rmust already be clamped: a radius past half the box's height draws a broken clip. Components clamp against their height token; a box with no known height needs one.- In Safari,
--corner-shape: roundkeeps an element round when it is set on an ancestor, not on the element itself. - Only the listed components draw it. Any other rounded element stays round in Safari until it opts in.
- A browser with neither
corner-shapenor style queries skips the fallback and draws round.
Testing the Fallback
Newer Playwright WebKit builds (1.64 and up) draw corner-shape natively, unlike shipping Safari, so a test that relies on WebKit lacking it quietly stops testing the fallback. forceSquircleFallback(css) from @loworbitstudio/visor-theme-engine is a test-only hook: it lifts every @supports not (corner-shape: squircle) gate and turns the native corner off, so Chromium or any WebKit draws what Safari draws. Production CSS never contains it. In a Playwright spec, rewrite the app's stylesheets as they load:
import { forceSquircleFallback } from "@loworbitstudio/visor-theme-engine"
await page.route("**/*.css", async (route) => {
const response = await route.fetch()
await route.fulfill({ response, body: forceSquircleFallback(await response.text()) })
})A test that checks the real, unforced gate should first assert CSS.supports("corner-shape", "squircle") is false and fail with "this WebKit draws corner-shape natively; the fallback is not being tested" when it is not.
Motion Values (motion)
The motion block sets the theme's curves and durations. Every key is optional:
# my-theme.visor.yaml
motion:
duration-fast: 100ms # --motion-duration-100
duration-normal: 200ms # --motion-duration-200
duration-slow: 500ms # --motion-duration-500
easing: "cubic-bezier(0.83, 0, 0.17, 1)" # --motion-easing-ease-in-out (the default curve)
easing-out: "cubic-bezier(0.22, 1, 0.36, 1)" # --motion-easing-ease-out (the enter curve)
# Opt-in role durations: each emits only when set.
duration-enter: 800ms # --motion-duration-enter
duration-exit: 380ms # --motion-duration-exit
duration-page: 1200ms # --motion-duration-page
duration-stagger: 75ms # --motion-duration-stagger
duration-enter-delay: 120ms # --motion-duration-enter-delayeasing-out defaults to cubic-bezier(0, 0, 0.2, 1), and the semantic --motion-easing-enter reads it. The five role durations have no default: a theme that leaves them out emits none of them, so read them with a fallback, for example var(--motion-duration-exit, var(--motion-duration-normal)). Durations are whole milliseconds (1200ms, not 1.2s). The Visual Explorer's Motion section shows every value and the corner shape as the active theme resolves them.
Manual Theme Toggle
To override the system preference, apply one of the following to your <html> element (or any root container):
| Selector | Effect |
|---|---|
.dark | Force dark mode |
.theme-dark | Force dark mode (legacy alias) |
[data-theme="dark"] | Force dark mode |
.light | Force light mode (override dark system preference) |
.theme-light | Force light mode (legacy alias) |
[data-theme="light"] | Force light mode |
HTML Attribute Example
<!-- Force dark mode regardless of system preference -->
<html data-theme="dark">
<!-- Force light mode regardless of system preference -->
<html data-theme="light">
<!-- Let the system preference decide (default) -->
<html>Class Example
<html class="dark">
<!-- dark mode active -->
</html>JavaScript Theme Toggle
The @loworbitstudio/visor-core package exports utilities for toggling themes programmatically:
import { applyTheme, getSystemTheme } from '@loworbitstudio/visor-core';
// Apply a theme
applyTheme('dark'); // adds .dark to <html>
applyTheme('light'); // adds .light to <html>
// Read the system preference
const systemTheme = getSystemTheme(); // 'light' | 'dark'You can also pass a custom element as the second argument:
const container = document.getElementById('app');
applyTheme('dark', container);Persisting User Preference
Combine applyTheme with localStorage to persist the user's choice:
import { applyTheme, getSystemTheme, type Theme } from '@loworbitstudio/visor-core';
function initTheme() {
const stored = localStorage.getItem('theme') as Theme | null;
const theme = stored ?? getSystemTheme();
applyTheme(theme);
}
function toggleTheme() {
const current = document.documentElement.classList.contains('dark') ? 'dark' : 'light';
const next: Theme = current === 'dark' ? 'light' : 'dark';
applyTheme(next);
localStorage.setItem('theme', next);
}React Hook Example
import { useState, useEffect } from 'react';
import { applyTheme, getSystemTheme, type Theme } from '@loworbitstudio/visor-core';
function useTheme() {
const [theme, setTheme] = useState<Theme>(() => {
if (typeof window === 'undefined') return 'light';
return (localStorage.getItem('theme') as Theme) ?? getSystemTheme();
});
useEffect(() => {
applyTheme(theme);
localStorage.setItem('theme', theme);
}, [theme]);
return { theme, setTheme };
}
// Usage
function ThemeToggle() {
const { theme, setTheme } = useTheme();
return (
<button onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
{theme === 'dark' ? 'Switch to Light' : 'Switch to Dark'}
</button>
);
}Granular CSS Imports
Instead of the full bundle, you can import individual CSS files:
/* Primitive tokens only */
@import '@loworbitstudio/visor-core/primitives';
/* Semantic tokens only */
@import '@loworbitstudio/visor-core/semantic';
/* Light theme adaptive tokens */
@import '@loworbitstudio/visor-core/themes/light';
/* Dark theme adaptive tokens (manual selectors + media query) */
@import '@loworbitstudio/visor-core/themes/dark';
/* Element baseline — form-control font inheritance, box-sizing, UA
margin/appearance normalisation. Opt-in: skip it if you already ship
Tailwind preflight or your own reset. */
@import '@loworbitstudio/visor-core/reset';This is useful when you want to compose the token layers manually or when your build system handles CSS concatenation.
Token Architecture
All components in Visor reference CSS custom properties — never hardcoded values. This means every component automatically responds to theme changes with zero extra code.
/* A component referencing adaptive tokens */
.card {
background: var(--surface-card); /* white in light, gray-900 in dark */
color: var(--text-primary); /* gray-900 in light, gray-50 in dark */
border: 1px solid var(--border-default); /* gray-200 in light, gray-700 in dark */
}The 3-tier token architecture:
Primitives Semantic Adaptive
--color-gray-50 --text-primary switches light ↔ dark
--color-gray-900 --surface-card based on theme class
--color-blue-500 --border-default or prefers-color-schemeConsumers can override any tier. Overriding a primitive cascades to all semantic and adaptive tokens that reference it.
Brand Workbench
A cluster of brand surfaces — Brand assets, Logo Guidelines, Strategy, Pillars, and Verbal — that resolve live against the active theme inside the Visual Explorer.
Creating Themes
How to create a Visor theme — the theme contract, 5-section template, standard vs creative themes, and the space theme as a reference implementation.