Theming
@peleda-app/tokens/theme turns a few options into every --pl-* variable for the light and dark schemes. The default theme is generated the same way and ships as @peleda-app/tokens/theme.css.
Try the options in the playground.
createTheme
import { createTheme } from '@peleda-app/tokens/theme'
const theme = createTheme({
accent: '#0f766e',
neutral: { hue: 190, chroma: 0.01 },
corners: 'smooth',
density: 'compact',
})
theme.options // the resolved ThemeOptions
theme.shared // fonts, radii, corners, spacing, scale
theme.light // colours and shadows for the light scheme
theme.dark // colours and shadows for the dark schemeEvery option is optional; resolveTheme fills the rest from defaultTheme.
| Option | Values | Default |
|---|---|---|
accent, danger, warning, success | any CSS colour, or { light, dark } | indigo #3046c5 / #7c8cff, red, amber, green |
neutral | null or { hue, chroma } | null, the reference grays |
radius | none, small, medium, large, pill | medium |
corners | squircle, smooth, round | squircle |
avatar | circle, rounded | circle |
density | compact, default, comfortable | default |
scale | 0.75 to 1.25, clamped | 1 |
sans | geist, inter, plex, atkinson, lexend, opendyslexic, system | geist |
mono | geist, plex, system | geist |
display | sans, serif, mono | sans |
contrast | standard, high | standard |
elevation | soft, flat | soft |
motion | system, reduced | system |
readability | standard, relaxed | standard |
Colour
The engine works in OKLCH through culori. A seed keeps its hue and chroma; only its lightness moves, and only as far as needed to reach the contrast target: 4.5:1 with contrast: 'standard', 7:1 with 'high'.
accent,danger,warningandsuccessreach the target againstsurface,bgandbg-subtleand against their own-fgcolour. In light,-fgis white; in dark it is the darkbg.accent-subtle-fgreaches the target againstaccent-subtle; the tonesoft-fgcolours reach it against theirsoftbackground.- A single seed string is lifted to at least 0.7 lightness in dark mode. A
{ light, dark }pair is used as given, and only fitted. neutral: nullkeeps the reference grays exactly. A tint keeps each gray's lightness and swaps in the hue and a chroma that tapers towards white and black.contrast: 'high'also darkens (or, in dark, lightens) the text and border grays.
Size and type
radiusmultiplies the radius steps:none0,small0.5,medium1,large1.4.pilluses 1.4 too, and sets--pl-radius-controland--pl-radius-fieldto9999pxwith round corners.densitysets--pl-space-unit: 0.225rem, 0.25rem or 0.28rem.scalesets--pl-root-size, the root font size as a percentage.readability: 'relaxed'raises the line height factor to 1.2 and adds 0.035em letter spacing and 0.12em word spacing.motion: 'reduced'sets every duration to0ms;applyThemealso setsdata-motion="reduced"on the root.
Corners and the radius fit
corners picks the curve of every rounded corner through the CSS corner-shape property: squircle is superellipse(2), smooth is superellipse(1.5) and round is a circular arc. A superellipse of the same radius cuts much less of the corner than a circle, so it would look sharper. The engine grows the radius to compensate.
For superellipse(k) the curve is |x|^n + |y|^n = 1 with n = 2^k. Its point on the diagonal sits at a depth of 1 - 2^(-1/n) of the radius, measured from the corner of the box. A circular arc (n = 2) has a depth of 1 - 2^(-1/2) ≈ 0.2929. The fit is the ratio of the two:
fit(k) = (1 - 2^(-1/2)) / (1 - 2^(-1/2^k))which is about 1.8409 for squircle, 1.3476 for smooth and exactly 1 for round. cornerFit(k) is exported for reuse.
The fit only applies where the browser understands corner-shape. tokens.css sets --pl-corner-supported: 1 inside @supports (corner-shape: superellipse(2)), and the theme writes
--pl-corner-fit: calc(1 + 0.8409 * var(--pl-corner-supported, 0));
--pl-radius-md: calc(0.5rem * var(--pl-corner-fit));so a browser without superellipses keeps the plain radius and a circular corner. Plain CSS that reads --pl-radius-* sets corner-shape: var(--pl-corner-shape) beside it; a third-party radius that should look the same divides by var(--pl-corner-fit, 1). Pills, avatars in circle mode and rounded-full stay round.
themeToCss
import { createTheme, themeToCss } from '@peleda-app/tokens/theme'
const css = themeToCss(createTheme({ accent: '#be185d' }))
const scoped = themeToCss(createTheme({ accent: '#be185d' }), {
selector: "[data-site='favicons']",
})With the default :root selector the output has three blocks: the shared and light variables, the dark variables inside @media (prefers-color-scheme: dark) for :root:not([data-theme='light']), and the dark variables again for :root[data-theme='dark']. With another selector the same blocks are scoped to it, and a fourth block restores the light scheme under an ancestor with data-theme='light'.
applyTheme and the colour scheme
import { applyTheme, setColorScheme } from '@peleda-app/tokens/theme'
const remove = applyTheme({ accent: '#0f766e', density: 'compact' })
setColorScheme('dark')
remove()applyTheme(input, options) writes themeToCss into a <style id="pl-theme"> in the document head, creating it once and replacing its text on later calls. options.id changes the element id, options.selector scopes the CSS and options.document targets another document. It returns a function that removes the style element.
Without a data-theme attribute the scheme follows the system. setColorScheme('light' | 'dark' | 'system', root) sets or removes data-theme on <html> or the given element; colorSchemes lists the three values.
Presets
presets holds ready-made inputs and preset(id) resolves one: default, iris, teal, rose, ember, graphite, sand, ocean, carbon and terminal.
import { applyTheme, presets } from '@peleda-app/tokens/theme'
const ocean = presets.find((p) => p.id === 'ocean')
if (ocean) applyTheme(ocean.theme)Identities
identities from @peleda-app/tokens/identities describe each public site: id, name, tagline, a theme input, a background motif (grid, dots, hairlines, contours, stamps or none), a glyph, the url and the GitHub repo. identity(id) returns one.
| id | Site | Theme |
|---|---|---|
skein | skein.peleda.dev | violet accent, violet-tinted neutrals |
pellet | pellet.peleda.dev | green accent pair, mono display |
sanctions | sanctions.peleda.dev | red accent, warm neutrals, serif display |
favicons | favicons.peleda.dev | pink accent, large radius |
status | status.peleda.dev | teal accent, compact density |
dev | peleda.dev | the default theme |
ui | ui.peleda.dev | indigo accent, cool neutrals |
<Site identity={identity('pellet')}> from the landing kit and defineDocsConfig({ identity }) from the docs kit turn an identity into scoped CSS.