Presets
Presets are ready-made backgrounds. Pick one by name and you get a complete style in a single line of code. This page documents the available presets, how to build on top of them and the color palette they use.
Overview
Create a preset with the Preset class and the name of the preset, then call toStyle() exactly as you would on a Builder.
import { Preset } from 'xeerpe'
const style = new Preset('sunrise').toStyle()Preset extends Builder: it is a builder that already contains the layers of the preset. Everything you can do with a Builder, you can also do with a preset.
xeerpe ships more than 200 presets, grouped in categories such as metals, gems, food, nature and space. Browse them all in Preset examples. This page uses sunrise and northern-lights to explain how presets work.
namerequiredstringThe name of the preset, such as 'gold', 'jungle' or 'northern-lights'. Names are kebab-case and case-sensitive. The full list is exported as presetNames.
TypeScript does not check the name, because the type is a plain string. An unknown name throws an error with the message Preset "<name>" not found as soon as the preset is created.
Presets take no other options. To change how a preset looks, see Customizing a preset.
Sunrise
A soft vertical gradient from warm peach at the top to pale sky blue at the bottom. It is a light background, so it pairs well with dark text.
new Preset('sunrise').toStyle()How sunrise is built
sunrise is a single linear gradient with four color stops.
new Builder()
.linearGradient({
colors: [
{ color: '#FFE5D9', position: '0%' },
{ color: '#FFCDB6', position: '35%' },
{ color: '#FFB7A3', position: '55%' },
{ color: '#BFD8F2', position: '100%' },
],
direction: 'to bottom',
})
.toStyle()Northern lights
A dark navy base covered by six overlapping blobs of green, teal and violet, like an aurora in the night sky. It includes a slow, five-second aurora animation that gently zooms the background in and out.
Note: the animation needs the xeerpe stylesheet. Without it the preset still renders, but it does not move. See Add the stylesheet.
new Preset('northern-lights').toStyle()How northern lights is built
northern-lights is a mesh gradient built with colors from the palette, plus an aurora animation.
import { Builder, colors } from 'xeerpe'
new Builder()
.meshGradient({
background: '#050914',
layers: [
{
position: '15% 15%',
from: colors.malachite,
to: 'transparent',
colorFromPosition: '0px',
colorToPosition: '55%',
},
{
position: '40% 8%',
from: colors.celadon,
to: 'transparent',
colorFromPosition: '0px',
colorToPosition: '55%',
},
{
position: '68% 18%',
from: colors.verdigris,
to: 'transparent',
colorFromPosition: '0px',
colorToPosition: '50%',
},
{
position: '85% 30%',
from: colors.malachite,
to: 'transparent',
colorFromPosition: '0px',
colorToPosition: '50%',
},
{
position: '45% 50%',
from: colors.amethyst,
to: 'transparent',
colorFromPosition: '0px',
colorToPosition: '45%',
},
{
position: '20% 65%',
from: colors.wisteria,
to: 'transparent',
colorFromPosition: '0px',
colorToPosition: '40%',
},
],
})
.aurora({ duration: '5s' })
.toStyle()Extending a preset
Because a preset is a builder, you can keep chaining after it. Effects, patterns, filters and animations all work, and they are drawn on top of the preset.
Examples
Film look
Grain and a warm vignette give the soft sunrise a photographic feel.
new Preset('sunrise')
.grain({ intensity: 1.5 })
.vignette({
color: '#7c2d12',
intensity: 0.2,
spread: 0.5,
})
.toStyle()Textured night
A light noise layer and a vignette add depth to the northern lights.
new Preset('northern-lights')
.noise({ opacity: 0.15 })
.vignette({
intensity: 0.5,
spread: 0.4,
})
.toStyle()Good to know
- Effects and patterns are always drawn above gradients, so they work on any preset.
- A gradient added after a preset is drawn below the preset's gradient, because the layers added first sit on top. On
sunrise, which is fully opaque, a second gradient would be hidden. - An animation added after a preset runs together with the preset's own animation. For example,
new Preset('northern-lights').float()runs bothauroraandfloat.
Customizing a preset
A preset cannot be configured: its colors, positions and timings are fixed, and you cannot register your own presets. To change one, rebuild it with a Builder and edit the values. The How it is built snippets above are the starting point.
Examples
Warm variation
The northern-lights structure with a warm palette, a different base color and a slower animation.
import { Builder, colors } from 'xeerpe'
new Builder()
.meshGradient({
background: '#140a1f',
layers: [
{
position: '15% 20%',
from: colors.coral,
to: 'transparent',
colorFromPosition: '0px',
colorToPosition: '55%',
},
{
position: '45% 8%',
from: colors.amber,
to: 'transparent',
colorFromPosition: '0px',
colorToPosition: '50%',
},
{
position: '82% 22%',
from: colors.mulberry,
to: 'transparent',
colorFromPosition: '0px',
colorToPosition: '55%',
},
{
position: '25% 72%',
from: colors.sakura,
to: 'transparent',
colorFromPosition: '0px',
colorToPosition: '45%',
},
{
position: '72% 78%',
from: colors.byzantium,
to: 'transparent',
colorFromPosition: '0px',
colorToPosition: '50%',
},
],
})
.aurora({ duration: '12s' })
.toStyle()To reuse your own recipe in several places, wrap the chain in a function that returns the style.
Colors
xeerpe also exports colors, the palette used by its presets: 100 named colors, each one a six-digit hex string. Use them anywhere a color is accepted.
import { Builder, colors } from 'xeerpe'
const style = new Builder()
.linearGradient({
from: colors.inkwell,
to: colors.obsidian,
})
.toStyle()inkwell#1a1a2eobsidian#16213evoid#0f0f1amidnightOil#1b1f3bpitch#222222carbon#2d2d2dgraphite#3d3d3dflint#555555stone#737373pewter#8e8e8eash#b4b4b0smoke#d0d0ccbone#e8e5dcchalk#f2f0easalt#faf9f6parchment#f5f0e8linen#eee8d5cream#fdf6e3absinthe#4a7c59forestFloor#2d5a27malachite#3a9e6dverdigris#5f9ea0celadon#ace1affern#4f7942chartreuse#b5cc18mantis#74c365viridian#40826dspruce#1e4d40prussian#003153lapis#1b4f8ccobalt#0047abcerulean#007ba7denim#1560bdglacier#80b9d3powder#b0d6e6steel#4682b4maya#73c2fbdelft#3640b8indigoInk#220066wisteria#9b7ec8aubergine#614051amethyst#9966ccmauve#e0b0ffbyzantium#702963mulberry#c54b8cplum#8e4585heliotrope#df73ffiris#5a4fcfcinnabar#e34234amaranth#e52b50carmine#960018rouge#ab4f62garnet#732e45crimson#dc143cvenetian#c80815blush#f4a0a0tomato#ff6347poppy#e35335amber#ffbf00saffron#f4c430ochre#cc7722goldenrod#daa520harvest#da8a2ecopper#b87333terra#c2713fsienna#882d17umber#635147rust#b7410ecoral#ff7f7fpeach#ffb38aapricot#fbceb1cantaloupe#f48054melon#fdbcb4spearmint#a1caa0sage#b2ac88taupe#b5a999khaki#c3b091dusk#8899a6slate#6d8b9ccadet#5f9ea0eucalyptus#5f8575clay#9c6b5amushroom#9e9388tealDeep#006d77aquamarine#2dc5a2seafoam#93e1d8jade#00a878turquoise#40e0d0niagara#06aed5tiffany#81d8d0pine#01796fmint#98ff98patina#4e8b78sakura#ffb7c5orchid#da70d6fandango#b53389cerise#de3163magenta#ff00ffteal#008080sapphire#0F52BATypes reference
class Preset extends Builder {
constructor(name: string)
}
type PresetConfig = (builder: Builder) => void
const presetCategories: {
classic: string[]
metals: string[]
gems: string[]
// ...and 11 more categories
}
type PresetCategory = keyof typeof presetCategories
const presetNames: string[]
const colors: {
inkwell: string
obsidian: string
void: string
// ...and 97 more named colors
}