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…
An element that fills itself with a set number of empty cells and leaves every visual decision to your CSS. It has no theming of its own, so the cells take whatever Vanilla Breeze tokens you use in the rules you write.
Two grids colored only with Vanilla Breeze tokens: a ramp where each cell's color depends on its position, and a seeded random texture that is the same on every load.
Usage
The element creates the cells and nothing else. On its own it shows nothing: the cells are empty <i> elements with no size or color. This CSS makes the grid visible. The element sets --pg-cols and --pg-rows on itself for your rules to use.
The CSS functions sibling-index() and sibling-count() give a cell its position and the number of cells, but not every browser has them. Add shim="sibling" and the element writes the same numbers as custom properties: --i on each cell, counting from 1, and --n on the grid.
Wrap a grid in <seed-context> to give every cell random numbers. Each cell gets --rand-0 to --rand-7, each between 0 and 1, and --randi-0 to --randi-7, whole numbers from 0 to 99. The same seed produces the same numbers on every load.
Seeded random cells
<seed-contextseed="hello"><pattern-gridcells="8x8"></pattern-grid></seed-context><style>pattern-grid > i {background: hsl(calc(var(--rand-0) * 360deg) 70%50%); }</style>
Do not combine shim="sibling" with <seed-context> on the same grid. In version 0.3.0 the seed context replaces each cell's inline style, which removes --i.
To skip writing the layout rules, load the optional stylesheet. It makes the element a grid of square cells and reads four custom properties: --pg-gap, --pg-bg, --pg-cell-aspect and --pg-aspect.
Sets columns and rows together. When present, cols and rows are ignored.
cols
pattern-grid
1 to 256
1
Number of columns.
rows
pattern-grid
1 to 256
1
Number of rows.
cell
pattern-grid
Tag name
i
The element created for each cell. If the grid contains a <template> child, its content is cloned for each cell instead.
shim
pattern-grid
sibling
Off
Writes --i on each cell and --n on the grid, for browsers without sibling-index().
seed
pattern-grid
Any string
None
Accepted, but version 0.3.0 does nothing with it on this element. Put seed on <seed-context>.
seed
seed-context
Any string
Empty string
Starting value for the random numbers. The same seed gives the same result.
count
seed-context
1 to 32
8
How many --rand-N and --randi-N pairs each cell gets.
src
paint-worklet
URL
None
A CSS Paint Worklet module to register, so cells can use background: paint(name). A paint worklet is a script that draws an element's background.
If the grid already contains exactly columns times rows child elements, the element keeps them and creates nothing. Cells written by hand therefore work before the script loads.
Methods and properties
Member
Applies to
Purpose
cols, rows, cell
pattern-grid
Read or set the matching attributes.
total
pattern-grid
Read only. Columns times rows.
cellElements
pattern-grid
Read only. An array of the cells, in order.
render()
pattern-grid
Replaces all cells with new ones.
cellAt(index), cellAt(x, y)
pattern-grid
Returns one cell by position in the list, or by column and row, both counting from 0. Returns null if there is none.
seed, count
seed-context
Read or set the matching attributes.
reseed()
seed-context
Writes the random numbers again on every grid it has filled.
Events
All of these bubble.
Event
Detail
Fired when
pattern-grid:render
{ cols, rows, total }
The grid has created its cells.
seed-context:populated
{ target, count }
The seed context has written random numbers on a grid's cells.
paint-worklet:registered
{ src }
The worklet module loaded.
paint-worklet:error
{ src, error }
The module failed to load, or the browser has no Paint Worklet support.
CSS custom properties
Property
Set by
Purpose
--pg-cols, --pg-rows
The element, on itself
Number of columns and rows, for your layout rules.
--n
The element, with shim="sibling"
Total number of cells.
--i
The element, on each cell, with shim="sibling"
The cell's position, counting from 1.
--rand-N, --randi-N
seed-context, on each cell
Random numbers: 0 to 1, and whole numbers 0 to 99.
--pg-gap
You; read by the optional stylesheet
Gap between cells. Default 0.
--pg-bg
You; read by the optional stylesheet
Cell background. Default transparent.
--pg-cell-aspect
You; read by the optional stylesheet
Aspect ratio of each cell. Default 1.
--pg-aspect
You; read by the optional stylesheet
Aspect ratio of the whole grid. Default is columns divided by rows.
pattern-grid has no theming of its own. It reads no Vanilla Breeze token and has no fallback order, because it ships no colors, fonts or spacing. The cells are plain light DOM elements, so page CSS reaches them directly and Vanilla Breeze tokens work in it like anywhere else.
VB token
A use in a pattern
--color-primary, --color-accent
The colors a pattern is mixed from. They change with the theme.
--color-surface, --color-surface-sunken
The quiet end of a ramp, so cells fade into the page in light and dark mode.
--size-3xs, --size-2xs
Gap between cells.
--radius-s, --radius-m
Corner radius of cells or of the whole grid.
Style all grids with a rule on pattern-grid, and one grid with an id or other selector:
Cells styled with VB tokens
pattern-grid {display: grid;grid-template-columns: repeat(var(--pg-cols), 1fr);gap: var(--size-3xs);}pattern-grid > i {aspect-ratio: 1;border-radius: var(--radius-s);background: var(--color-surface-sunken);}/* One instance: a ramp from the surface color to the theme's primary color. Needs shim="sibling" on the element for --i and --n. */#ramp > i {background: color-mix( in oklch,var(--color-primary) calc(var(--i) / var(--n) * 100%),var(--color-surface) );}
Because the colors are tokens, the pattern changes when the theme or the light and dark mode changes, with no script.
Accessibility
The generated cells are empty and carry no role, label or keyboard behavior. A grid used as decoration should be hidden from assistive technology with aria-hidden="true".
If a pattern carries meaning, give that meaning in text next to it. Color in empty cells is not available to a screen reader.
The element adds no motion. Any animation comes from your CSS, so wrap it in a prefers-reduced-motion query.
<seed-context> fades cells in over 220 milliseconds when it fills them. Version 0.3.0 does not turn that fade off for reduced motion.