Toast stack
toast-stackNotifications arrive in a corner one after another and push the older ones back into a stack; the last carries the accent.
Install
$ npx paper-motion add toast-stackWrites a scene to pieces/, wired to your brand folder.
Tune it, then add it to your kit
Parameters
format
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>toast-stack</title>
<!--
Component · toast stack (5.2 s). Notifications arrive in a corner one after another: each new one slides up from
below on a spring and pushes the others back into a stack, smaller and dimmer, the oldest folding away. The last
one carries the accent. The camera sits close on the corner and leans with each arrival.
Toasts 0.7, 1.6, 2.5, 3.4 s · Hold to 5.2 s.
Vertical: a phone-shaped screen without sidebar, wider toasts, a gentler push-in; square: a squarer screen, larger toasts.
-->
<style>
#stage { overflow: hidden; }
.abs { position: absolute; box-sizing: border-box; }
#comp { position: absolute; box-sizing: border-box; overflow: hidden; }
.ui { position: absolute; inset: 0; display: grid; grid-template-columns: 18% 1fr; }
.side { display: flex; flex-direction: column; gap: 1.1em; padding: 2.2em 1.6em; }
.main { display: flex; flex-direction: column; gap: 1.4em; padding: 2.2em; }
i { display: block; height: 0.6em; border-radius: 999px; }
.toast { position: absolute; right: 2.2em; bottom: 2.2em; display: flex; align-items: center; gap: 1em; padding: 1.1em 1.4em; border-radius: 0.9em; transform-origin: 50% 100%; }
.dot { width: 1.6em; height: 1.6em; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex: none; font-size: 0.9em; }
</style>
</head>
<body>
<main id="stage">
<div id="bg" class="abs" style="inset:0"></div>
<div id="world"><div id="comp"><div class="ui" id="ui"></div></div></div>
</main>
<script type="module">
import { scene, progress, ease, spring } from 'paper-motion';
import { camera } from 'paper-motion/kit';
import { loadBrand } from 'paper-motion/brand';
const CONFIG = {
background: null,
toasts: [
['Render started', '720 frames · 1920 × 1080'],
['Brand applied', 'paper-motion'],
['Sound mixed', 'from /brand/sound.json'],
['launch.mp4 is ready', '24 s · 18 MB'],
],
format: [1920, 1080],
};
const B = await loadBrand();
const [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 5.2;
const s = scene({ width: W, height: H, fps: 30, duration: D, background: B.color('ground') });
const bgId = CONFIG.background ?? B.set.entries.find((e) => e.shader && !e.image)?.id;
if (bgId) B.shader(s, '#bg', bgId);
const $ = (id) => document.getElementById(id);
$('bg').style.opacity = 0.3;
const DIST = SHORT * 0.62, K = 1 + DIST / (SHORT * 1.7);
const cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });
const tall = H > W, square = W === H;
const comp = $('comp'), cw = (tall ? W * 0.9 : square ? W * 0.84 : W * 0.72) * K, ch = cw * (tall ? 1.5 : square ? 0.8 : 0.58), R = (B.tokens?.shape?.radius ?? 12) * (SHORT / 1080) * K;
const ground = B.color('ground'), muted = B.color('muted'), figure = B.color('figure'), accent = B.color('accent', '#E9E4D8');
const GREEN = '#8fbf8f';
const TW = tall ? 0.56 : square ? 0.345 : 0.3, FS = tall || square ? TW / 26 : 0.0115; // toast width and type size, as fractions of the screen width
Object.assign(comp.style, { width: `${cw}px`, height: `${ch}px`, borderRadius: `${R}px`, background: B.surface(0.2), border: `1.5px solid ${muted}55`, boxShadow: `0 ${SHORT * 0.04}px ${SHORT * 0.12}px rgba(0,0,0,0.5)`, fontSize: `${cw * FS}px`, fontFamily: B.font('text') });
const line = (w, c = muted, o = 0.45) => `<i style="width:${w}%;background:${c};opacity:${o}"></i>`;
const box = (h) => `<div style="height:${h}em;border-radius:0.8em;background:${ground};border:1px solid ${muted}33"></div>`;
if (tall) $('ui').style.gridTemplateColumns = '1fr';
$('ui').innerHTML = `<div class="side" style="background:${ground}${tall ? ';display:none' : ''}">${line(70, figure, 0.9)}${line(85)}${line(60)}${line(75)}</div><div class="main">${line(24, figure, 0.9)}${box(14)}${box(9)}${tall ? box(12) + box(10) : ''}</div>`;
const toasts = CONFIG.toasts.map(([a, b], i) => {
const last = i === CONFIG.toasts.length - 1, el = document.createElement('div'); el.className = 'toast';
Object.assign(el.style, { width: `${cw * TW}px`, background: last ? accent : '#242424', color: last ? ground : figure, border: `1px solid ${last ? 'transparent' : muted + '77'}`, boxShadow: `0 1.2em 3em rgba(0,0,0,0.55)` });
el.innerHTML = `<div class="dot" style="background:${last ? ground : GREEN};color:${last ? accent : ground}">✓</div><div><div style="font-weight:500;font-size:1.15em">${a}</div><div style="opacity:0.6;margin-top:0.25em">${b}</div></div>`;
comp.append(el); return el;
});
cam.place(comp, { x: 0, y: 0, z: 0 });
await document.fonts.ready;
const T = [0.7, 1.6, 2.5, 3.4];
const th = toasts[0].offsetHeight, gap = th * 0.42;
// the corner, in the comp's own pixels
const cx = cw - cw * FS * 2.2 - cw * TW / 2 - cw / 2, cy = ch - cw * FS * 2.2 - th * 0.8 - ch / 2;
const push = tall ? 0.68 : 0.95, turn = tall ? 0.2 : 1;
const oy = tall ? -H * 0.17 : square ? -H * 0.1 : 0; // in taller frames the toast sits low with the screen above it, not over an empty floor // in tall frames the toast fills the width: less push, less yaw
s.update((t) => {
// how many have arrived, continuously: each arrival is a spring
const arr = T.map((a) => (t >= a ? spring(t - a, { stiffness: 210, damping: 19 }) : 0));
const count = arr.reduce((x, y) => x + Math.min(1, y), 0);
toasts.forEach((el, i) => {
const age = count - 1 - i; // 0 = front, 1 = one behind, …
const inn = arr[i];
if (inn <= 0) { el.style.opacity = '0'; return; }
const lift = age <= 0 ? (1 - inn) * -th * 1.4 : age * gap; // the newest rises from below; the others step back
const sc = 1 - Math.max(0, age) * 0.06;
el.style.transform = `translateY(${-lift}px) scale(${sc})`;
el.style.opacity = String(Math.min(1, inn * 2) * Math.max(0, 1 - Math.max(0, age - 1.6) * 1.5));
for (const c of el.children) c.style.opacity = String(Math.max(0, 1 - Math.max(0, age) * 2.2)); // behind the front one only the card shows
el.style.zIndex = String(100 - i * 0 + i);
el.style.filter = age > 0.5 ? `brightness(${1 - 0.08 * age})` : 'none';
});
// the camera: close on the corner, leaning a little with each arrival
const arrive = progress(t, 0, 0.8, ease.outCubic), kick = T.reduce((k, a) => k + (t >= a ? Math.sin(Math.min(1, (t - a) / 0.5) * Math.PI) : 0), 0);
cam.at({ x: cx * arrive, y: (cy + oy) * arrive, z: DIST + SHORT * 0.25 * (1 - arrive) - SHORT * push * arrive - SHORT * 0.15 * progress(t, 0.8, D, ease.inOutSine) - SHORT * 0.012 * kick, yaw: (-10 * (1 - arrive) - 5 + 1.2 * kick) * turn, pitch: 4 * (1 - arrive) + 2, roll: 0 });
comp.style.opacity = String(progress(t, 0, 0.3));
});
T.forEach((a) => B.cue(s, 'text', a));
B.sound(s);
await s.start();
</script>
</body>
</html>
Defaults
Structure
Toast stack02 / 02
Hold
hold
0.0 / 5.2 s
01Toasts
02Hold
0 s5.2 s
- 010.7–4 sToaststoasts
- 024–5.2 sHoldhold
The script, sketched: the beats in order and their length, in the brand's colors and type. The clip above is the engine's render of the same recipe.
Notes
- Wired to the brand folder: needs brand/tokens.json (a palette and a font pair work) and, for the field, a shader-set entry.
- Recomposes for 16:9, 9:16 and 1:1: set
formatand the layout and camera follow.
Spec
- Id
- toast-stack
- Type
- Blocks
- Version
- 1.0.0
- Engine
- >=0.2.6
- License
- MIT