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

pattern-grid

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.

At a glance

Package@profpowell/pattern-grid 0.3.0
Elements<pattern-grid>, plus two optional companions loaded from their own files: <seed-context> and <paint-worklet>
Renders inLight DOM
Sourcegithub.com/ProfPowell/pattern-grid
Documentationprofpowell.github.io/pattern-grid
LicenceMIT
In Vanilla BreezeNot bundled. Load it yourself.

Install

From a CDN. The script is all you need. The stylesheet is optional: it sets up the grid layout for you, as described under Usage.

The optional stylesheet and the two companion elements are separate files:

Or from npm:

Demo

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.

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.

Reference

Attributes

AttributeApplies toValuesDefaultPurpose
cellspattern-grid8x8 (columns by rows) or 64 (columns, one row)NoneSets columns and rows together. When present, cols and rows are ignored.
colspattern-grid1 to 2561Number of columns.
rowspattern-grid1 to 2561Number of rows.
cellpattern-gridTag nameiThe element created for each cell. If the grid contains a <template> child, its content is cloned for each cell instead.
shimpattern-gridsiblingOffWrites --i on each cell and --n on the grid, for browsers without sibling-index().
seedpattern-gridAny stringNoneAccepted, but version 0.3.0 does nothing with it on this element. Put seed on <seed-context>.
seedseed-contextAny stringEmpty stringStarting value for the random numbers. The same seed gives the same result.
countseed-context1 to 328How many --rand-N and --randi-N pairs each cell gets.
srcpaint-workletURLNoneA 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

MemberApplies toPurpose
cols, rows, cellpattern-gridRead or set the matching attributes.
totalpattern-gridRead only. Columns times rows.
cellElementspattern-gridRead only. An array of the cells, in order.
render()pattern-gridReplaces all cells with new ones.
cellAt(index), cellAt(x, y)pattern-gridReturns one cell by position in the list, or by column and row, both counting from 0. Returns null if there is none.
seed, countseed-contextRead or set the matching attributes.
reseed()seed-contextWrites the random numbers again on every grid it has filled.

Events

All of these bubble.

EventDetailFired 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

PropertySet byPurpose
--pg-cols, --pg-rowsThe element, on itselfNumber of columns and rows, for your layout rules.
--nThe element, with shim="sibling"Total number of cells.
--iThe element, on each cell, with shim="sibling"The cell's position, counting from 1.
--rand-N, --randi-Nseed-context, on each cellRandom numbers: 0 to 1, and whole numbers 0 to 99.
--pg-gapYou; read by the optional stylesheetGap between cells. Default 0.
--pg-bgYou; read by the optional stylesheetCell background. Default transparent.
--pg-cell-aspectYou; read by the optional stylesheetAspect ratio of each cell. Default 1.
--pg-aspectYou; read by the optional stylesheetAspect ratio of the whole grid. Default is columns divided by rows.

The pattern-grid documentation has the full detail, and its showcase has worked patterns.

With Vanilla Breeze

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 tokenA use in a pattern
--color-primary, --color-accentThe colors a pattern is mixed from. They change with the theme.
--color-surface, --color-surface-sunkenThe quiet end of a ramp, so cells fade into the page in light and dark mode.
--size-3xs, --size-2xsGap between cells.
--radius-s, --radius-mCorner 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:

Because the colors are tokens, the pattern changes when the theme or the light and dark mode changes, with no script.

Accessibility

↑