Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

bg-wc

<bg-wc> draws an animated background behind any HTML content, choosing a WebGL, Canvas 2D or CSS 3D renderer to suit the preset (a named effect). It takes its colors from the Vanilla Breeze --color-* tokens, so it changes with the active theme.

At a glance

Package@profpowell/bg-wc, version 0.5.1
Elements<bg-wc>
Renders inShadow DOM. Your content stays in the light DOM and is slotted above the drawing.
Sourcegithub.com/ProfPowell/bg-wc
Documentationprofpowell.github.io/bg-wc
LicenceMIT
In Vanilla BreezeNot bundled. Load it yourself.

Install

From a CDN. The package has no stylesheet to load. Each preset is a separate file that the element fetches the first time it is used.

To use the data-background attributes instead of the element, load the binder. It imports the element for you.

Or with npm:

Demo

Each demo is a Vanilla Breeze page with one background filling the frame. None of them sets a color: the colors come from the theme tokens.

Mesh gradient, as an element

Mosaic, through data-background attributes

Confetti, using the status colors

Usage

Wrap content in the element. The content renders above the background, and the fallback slot holds a still image for when the animation cannot or should not run.

With the binder loaded, put data-background on an existing element. The binder inserts a <bg-wc> as that element's first child and positions it behind the content.

Some presets draw text. Pass it with text, using | to split lines.

Reference

Attributes

AttributeValuesDefaultPurpose
presetA preset namenoneWhich effect to draw. Without it the element shows only the fallback slot.
palettetheme, rainbow, monothemeColor strategy. Only some presets, such as particles and crawl, respond to values other than theme.
intensity0 to 10.5Strength of the effect. The meaning varies by preset.
speed0 to 51Time multiplier. 0 stops time.
density0 to 10.5Number of particles, tiles or similar detail.
seedInteger0Seed for the random layout, so the same seed gives the same arrangement.
pausedBooleanoffStops the animation and keeps the current frame.
pixel-ratioNumber, 0.25 to 8The device pixel ratio, capped at 2Canvas pixels per CSS pixel. Lower it to save work on large areas.
qualitylow, med, highmedDetail hint that some presets use, for example as a cap on particle count.
fitcover, contain, stretchcoverSizing hint passed to the preset.
motionauto, reduce, forceautoauto follows the reduced-motion setting of the operating system. reduce always shows a still. force always animates.
power-saveoffonBy default the animation stops when the device reports a battery below 20% that is not charging. off keeps it running.
modeDepends on the presetDepends on the presetA variant of the preset. mosaic accepts isometric, flat, sparse, stacked and blocks; dotwork accepts rings, spiral, double, whorl and waterholes; stipple accepts field, contour and vortex.
textStringPreset's own textText for the text presets, such as crawl, marquee, sinescroll, cascade, source, wordcloud and bootlog.
use-themeBooleanoffFor system7 only: take colors from the theme tokens instead of black on white.

Attribute binder

The binder watches the page, so elements added later are bound too. It accepts two spellings, data-background and the shorter data-bg. Use one spelling per element.

AttributeEffect
data-background="name"Sets preset on the inserted <bg-wc>.
data-background-xSets attribute x on the inserted element. Any name works, for example data-background-speed or data-background-mode.
data-background-color-xSets the custom property --bg-wc-color-x, for example data-background-color-1="hotpink".
data-background-skipStops the binder from touching this element.

The module also exports bindDataBackgrounds(root), which scans a subtree on demand, and stopWatching(), which stops the binder from reacting to later page changes.

Presets

Version 0.5.1 registers 199 presets in 22 groups. 129 draw with Canvas 2D, 60 with WebGL and 10 with CSS 3D transforms.

GroupPresets
Gradientribbons, flowlines, mesh-gradient, halcyon, waves, plasma, rainbow, shine, conic
Geometricmosaic, supergraphics, warp, topology, cells, kaleidoscope, doodles, scandi, truchet, delaunay, hilbert, moire
Texturedither, halftone, grain, paper-grain, stipple, terrazzo
Atmosphericnoise, lava, aurora, cumulus, moonrise, lightning, fog, caustics, tunnel, marble, nebula, summit
Pop artbenday, comic, deco, fan-deco, deco-spires, peacock, atomic, groove, psychedelia
Ornamentalgirih, mandala, op-art, dotwork, tapestry, celtic-knot, paisley, azulejo, mudcloth, gilded
Japaneseseigaiha, sumi-e, kintsugi, ukiyo-e, sakura, origami, zen-garden
Printrisograph, plotter, linocut, cyanotype, screenprint
Classicalchemy, bauhaus, cave, clockwork, damask, de-stijl, hieroglyph, illuminated, meander, morris, art-nouveau, constructivism, stained-glass, swiss
Artcolorfield, cutouts, drip, graffiti, mobile, watercolor, brushstroke, terrace, oil-sky
Kitschcrochet, disco, domino, neon-sign, pegboard, quilt
Sciencephyllotaxis, boids, helix, mycelium, reaction-diffusion, chladni, orbital, slime-mold
Techcircuit, blueprint, radar, gyroid, lidar, oscilloscope, spectrum, hologram, neon-city, swarm
Naturekomorebi, leaves, lily-pond, meadow, tide, migration, palms, reeds
Loungebarkcloth, breezeblock, lanai, tiki
Retroequalizer, vumeter, system7, glitch, vhs, synthwave, crt, gameboy, copperbars, metaballs, matrix, bliss, mystify
Vectorasteroids, wireframe, spirograph, incoming, trench, tempest, fireworks
Textsource, crawl, marquee, sinescroll, cascade, bootlog
Particlesstars, constellation, bubbles, snow, rain, fireflies, embers, confetti, network, particles, pulse, tetris, lanterns
Dimensionalfly-through, explode, carousel, gyroscope, monolith, shards, cube-wave, skyline, chamber, satellites
Dataledticker, nixie, splitflap, trades, dashboard, vectormap, transit-diagram, scatter, waveform, wordcloud
Musicliquid-light, bluenote, starburst, vinyl, prism, laser-show, scanimate, airbrush, video-feedback, stage-lights, chrome

Methods and properties

MemberPurpose
presetGets or sets the preset attribute.
pausedGets or sets the paused attribute as a boolean.
pause(), resume()Stop and restart the animation.
snapshot()Returns a promise for a PNG Blob of the current frame. Resolves to null for CSS 3D presets, which have no canvas.
readyA promise that settles once the preset has loaded and drawn its first frame, or has failed.
BgWc.presets()Static. Returns every preset as { name, renderer, group }.

Events

Events are dispatched on the element and do not bubble.

EventDetailWhen
bg-wc:ready{ preset, renderer }The preset loaded and drew its first frame.
bg-wc:preset-changed{ from, to }The preset attribute changed and the new preset is in place.
bg-wc:error{ phase, error }A preset failed to load, start or draw. phase is load, init or runtime. The element then shows the fallback slot until the preset changes.
bg-wc:visibility{ visible }The element entered or left the viewport.

CSS custom properties

PropertyPurpose
--bg-wc-color-1, --bg-wc-color-2, --bg-wc-color-3The three tints. They replace the primary, accent and info theme colors.
--bg-wc-color-bg, --bg-wc-color-fgBackdrop color, and the color of lines and text.
--bg-wc-intensity, --bg-wc-speed, --bg-wc-densitySame as the matching attribute. The property wins when both are set.
--bg-wc-pixel-ratioSame as pixel-ratio. The property wins when both are set.
--bg-wc-z-indexStacking order of the drawing inside the element. Default 0; slotted content sits at 1.

Two shadow parts can be styled from outside: ::part(canvas) for WebGL and Canvas 2D presets, and ::part(stage) for CSS 3D presets.

The bg-wc API reference has the full detail, and the gallery shows every preset running.

With Vanilla Breeze

Custom properties inherit into shadow DOM, so the element reads the tokens that a Vanilla Breeze theme sets on the page. No setup is needed. Token values written with light-dark() resolve against the element's own color scheme.

TokenDrivesPer-instance overrideBuilt-in default
--color-backgroundBackdrop of the element and of the drawing--bg-wc-color-bgtransparent
--color-primaryFirst tint--bg-wc-color-1#3b82f6
--color-accentSecond tint--bg-wc-color-2#ec4899
--color-infoThird tint--bg-wc-color-3#10b981
--color-textLines and text. The element looks for --color-foreground first; Vanilla Breeze does not define it, so --color-text is used.--bg-wc-color-fg#1a1a1a
--color-success, --color-warning, --color-errorExtra colors for presets that use the status palette, such as confettinone#22c55e, #f59e0b, #ef4444

For each color the element uses the first of these that has a value: the --bg-wc-* property, then the Vanilla Breeze token, then the built-in default. Set the property on one element to change that element only.

Vanilla Breeze has no data-background attribute of its own. The attribute only does something once the bg-wc binder is loaded.

Accessibility

↑