# KptBackdrop (kpt-backdrop)
A decorative background layer for a section: the component wraps your content and paints an
animated canvas beneath it. You reach for it where a flat surface looks unfinished, and where
a video or a large image would cost bandwidth and refuse to follow the theme.
Projected content sits a layer above the canvas and behaves normally.
Import: `import { KptBackdrop } from '@konce-pt/angular';`
## Inputs (shared)
- `effect`: 'signal-grid' | 'wave' (default 'signal-grid') - the effect to draw
- `background`: string - the section background; empty takes `--kpt-color-surface`
- `speed`: number (default 1) - 1 is the calm pace of either effect, 0 freezes the picture
- `seed`: number (default 0) - the same value gives the same layout and the same sway
- `paused`: boolean - stops the animation, leaving the last frame
- `adaptive`: boolean - carries hardcoded colours onto the current theme's surface
## Inputs (signal-grid)
- `color`: string - the square colour, any CSS notation, tokens included; empty takes
`--kpt-color-primary`
- `anchor`: 'left' | 'right' (default 'right') - the edge the grid is densest at
- `cell`: number (default 5) - the square's side in px
- `gap`: number (default 11) - the space between squares in px
- `density`: number (default 0.8) - the share of lit cells at the anchor, 0-1
- `falloff`: number (default 1.4) - how fast the grid fades towards the far edge
## Inputs (wave)
- `colors`: string[] - the colour ramp the current slides along, closed into a loop; every
stop takes any CSS notation, `color`'s rules exactly
- `rotation`: number (default 12) - the angle the current crosses the frame at, in degrees
- `band`: number (default 0.34) - the band's width as a fraction of the frame's height
- `amplitude`: number (default 0.16) - how far the centre line sways
An input that does not belong to the current effect is simply not read.
## Methods
- `reseed()` - a fresh run of the effect at the same size and the same inputs
## Example
Build your app from the first prompt
Get started
## signal-grid
A fine grid of squares that quietly twinkle, dense at one edge and fading to empty at the other.
The gradient comes from **how many** squares are lit, not from opacity laid over an even grid -
that is why it reads as a signal rather than as a texture with a mask on top.
Each cell derives its own draws - whether it is lit, its twinkle phase and its rate - from its own
column and row, so the layout survives a resize instead of reshuffling. The rates are spread over
0.45-1.55, because at one shared rate the whole grid pulses in unison and the effect turns into
breathing. The grid deliberately runs past the area and the overflow is clipped: a grid that stops
before the edge looks cut off.
## wave
One soft current of light flowing across the frame, with hues sliding along it and no hard edge
anywhere. The centre line is a sum of harmonics at incommensurable frequencies, so the current
sways without a repeating pattern; brightness falls away from it on a Gaussian curve.
`rotation` turns the whole current: 0 runs it horizontally, 90 stands it on end. `band` sets how
wide it is, `amplitude` how much it sways - set `amplitude` to 0 and the shape stands still while
the colours keep flowing.
The ramp is closed into a loop, so the last colour returns to the first; a ramp with a seam would
show it in the middle of the frame. Colours are mixed on the polar form of OKLab, going round the
circle rather than across it: a straight mix of opposite hues crosses the achromatic axis and the
current goes grey exactly where it is brightest.
Without `colors` the ramp is `--kpt-color-primary` plus two hues derived from it by rotation.
The library's palette is neutral, so that default current is single-hued and muted - the hue
sliding only shows once you give it a real ramp.
Every stop is put to the browser, so `oklch()`, `color-mix()`, `rgb()` and named colours are read
the same as hex; alpha is dropped. A stop the browser refuses falls out of the ramp, and if every
one of them falls out the default ramp takes over rather than the section going blank - a dev
build says in the console which stops it dropped.
## What it costs
`wave` is computed in a buffer whose longer side is 160 px and scaled up: softness comes from the
browser's interpolation, so a few thousand pixels a frame cover a frame of any size. It is not
drawn at full canvas resolution.
## Where the maths lives
The grid layout, the density ramp, the twinkle, the current and the colour ramp - plus the
renderers for both effects - live in `@konce-pt/backdrop`, plain TypeScript with its own
`node --test` suite, shared by both ports. The component is the lifecycle around them.
## Rest
Drawing stops when there is nothing to watch: the section is off-screen (`IntersectionObserver`),
the tab is in the background, `paused` is set, `speed` is 0, or the system asks for reduced motion
(`prefers-reduced-motion`). What is left is a single static frame, not emptiness - the effect is
part of the composition, not decoration.
`speed` feeds the clock rather than the phase, so moving a speed slider accelerates the picture
instead of jumping it.
## Accessibility
The canvas carries `aria-hidden="true"` and `pointer-events: none` - it is decoration with no
content and nothing to hit. Content keeps its own roles and tab order. Under reduced motion the
animation does not start at all.
## Tokens
`--kpt-color-primary` (squares and the default ramp), `--kpt-color-surface` (background),
`--kpt-color-on-surface`. Overrides for a whole section without touching the inputs:
`--kpt-backdrop-color`, `--kpt-backdrop-surface`.
## Adaptive colours
A literal stays put by design, which is right for a brand colour and wrong for a section meant to
read in both themes. `adaptive` closes that gap: it carries `color`, `colors` and `background`
onto the surface of the current theme, keeping each one's distance from that surface. Black picked
for a white section comes out white on a near-black ground, and that white background comes out at
the surface's own lightness. Only lightness moves - hue and chroma stay, so a brand colour keeps
being that colour and only changes how light it is.
It touches literals only. An empty input takes a token, and a value reaching through `var()`
reaches a token too; both already follow the theme, and adapting them would turn them back again.
Values written for the light theme are the assumption - the library keeps light in `:root` and
dark as the override.
## Content on a custom background
The host paints `--kpt-color-surface` and lets content inherit `--kpt-color-on-surface`, which is
right until the section gets a `background` of its own - then that token describes the page around
it, not the ground the content actually sits on. A dark section in a light theme would come out
black on black.
So a section with its own background works out its own ink: the host sets `color` to match what it
paints, and announces the result as `data-tone` (`light` for a light background, `dark` for a dark
one). Text follows by inheritance; anything needing more than a text colour - buttons in the
section, say - can hang its own tokens off the attribute:
:where(kpt-backdrop[data-tone='light']) .hero { --kpt-button-filled-bg: #15181a; }
The tone is computed from the background the section really paints, so with `adaptive` on it
matches the adapted value, not the one written in the template. A section without its own
background announces nothing and content stays on `--kpt-color-on-surface`.
## Theme
Canvas does not expand `var()`, so the colour is read once and baked into the renderer - the
component therefore watches for anything that can restyle the tokens under it and reads them
again. `[data-theme="dark"]` is not tied to `:root`, so the watch covers `data-theme`, `class`
and `style` on every ancestor from the host up to ``, plus the `prefers-color-scheme` query
for an application that keeps its dark tokens in a media query. A runtime override of
`--kpt-color-primary` is picked up the same way as a theme switch. The renderer is rebuilt only
when the colour actually came out different, so an unrelated class landing on `` costs one
cheap read and nothing else.
Whether an explicit `color` or `colors` follows the theme is up to how it is written. A literal
stays put - `#5b8af2` is `#5b8af2` in either theme, which is what someone spelling out a brand
colour wants. An expression reaching for a token is resolved against the tree on every rebuild, so
it moves with the theme on its own:
`var(--kpt-color-primary)` works the same way. A name that resolves to nothing falls back to the
token for `color`, and drops out of the ramp for `colors`.
## Contrast
The palette is neutral, so `--kpt-color-primary` is near-black on a light surface and near-white
on a dark one - at the default density the picture is strong, and text laid over the dense half
loses its reading. Keep the copy on the side the grid fades towards (that is what `anchor` is
for), or drop `density`. `wave` is brightest along its centre line, so the same rule applies
through `rotation` and `band`. On a custom `background` give the colours a muted shade:
a full-strength colour behind text costs the reading, not the effect.