{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "toast-stack",
  "type": "block",
  "title": "Toast stack",
  "summary": "Notifications arrive in a corner one after another and push the older ones back into a stack; the last carries the accent.",
  "tags": [
    "block",
    "ui",
    "notification",
    "toast",
    "progress"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "name": "format",
      "type": "enum",
      "default": "1920x1080",
      "options": [
        "1920x1080",
        "1080x1920",
        "1080x1080"
      ],
      "description": "output size; the layout recomposes for each",
      "group": "main",
      "control": "segmented"
    }
  ],
  "install": {
    "kind": "scene"
  },
  "files": [
    {
      "path": "pieces/toast-stack/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>toast-stack</title>\n<!--\n  Component · toast stack (5.2 s). Notifications arrive in a corner one after another: each new one slides up from\n  below on a spring and pushes the others back into a stack, smaller and dimmer, the oldest folding away. The last\n  one carries the accent. The camera sits close on the corner and leans with each arrival.\n  Toasts 0.7, 1.6, 2.5, 3.4 s · Hold to 5.2 s.\n  Vertical: a phone-shaped screen without sidebar, wider toasts, a gentler push-in; square: a squarer screen, larger toasts.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #comp { position: absolute; box-sizing: border-box; overflow: hidden; }\n  .ui { position: absolute; inset: 0; display: grid; grid-template-columns: 18% 1fr; }\n  .side { display: flex; flex-direction: column; gap: 1.1em; padding: 2.2em 1.6em; }\n  .main { display: flex; flex-direction: column; gap: 1.4em; padding: 2.2em; }\n  i { display: block; height: 0.6em; border-radius: 999px; }\n  .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%; }\n  .dot { width: 1.6em; height: 1.6em; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex: none; font-size: 0.9em; }\n</style>\n</head>\n<body>\n<main id=\"stage\">\n  <div id=\"bg\" class=\"abs\" style=\"inset:0\"></div>\n  <div id=\"world\"><div id=\"comp\"><div class=\"ui\" id=\"ui\"></div></div></div>\n</main>\n<script type=\"module\">\nimport { scene, progress, ease, spring } from 'paper-motion';\nimport { camera } from 'paper-motion/kit';\nimport { loadBrand } from 'paper-motion/brand';\n\nconst CONFIG = {\n  background: null,                      // a shader-set id, or null for the brand's first entry\n  toasts: [\n    ['Render started', '720 frames · 1920 × 1080'],\n    ['Brand applied', 'paper-motion'],\n    ['Sound mixed', 'from /brand/sound.json'],\n    ['launch.mp4 is ready', '24 s · 18 MB'],\n  ],\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 5.2;\nconst s = scene({ width: W, height: H, fps: 30, duration: D, background: B.color('ground') });\nconst bgId = CONFIG.background ?? B.set.entries.find((e) => e.shader && !e.image)?.id;\nif (bgId) B.shader(s, '#bg', bgId);\nconst $ = (id) => document.getElementById(id);\n$('bg').style.opacity = 0.3;\n\nconst DIST = SHORT * 0.62, K = 1 + DIST / (SHORT * 1.7);\nconst cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });\nconst tall = H > W, square = W === H;\nconst 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;\nconst ground = B.color('ground'), muted = B.color('muted'), figure = B.color('figure'), accent = B.color('accent', '#E9E4D8');\nconst GREEN = '#8fbf8f';\nconst 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\nObject.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') });\nconst line = (w, c = muted, o = 0.45) => `<i style=\"width:${w}%;background:${c};opacity:${o}\"></i>`;\nconst box = (h) => `<div style=\"height:${h}em;border-radius:0.8em;background:${ground};border:1px solid ${muted}33\"></div>`;\nif (tall) $('ui').style.gridTemplateColumns = '1fr';\n$('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>`;\nconst toasts = CONFIG.toasts.map(([a, b], i) => {\n  const last = i === CONFIG.toasts.length - 1, el = document.createElement('div'); el.className = 'toast';\n  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)` });\n  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>`;\n  comp.append(el); return el;\n});\ncam.place(comp, { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\n\nconst T = [0.7, 1.6, 2.5, 3.4];\nconst th = toasts[0].offsetHeight, gap = th * 0.42;\n// the corner, in the comp's own pixels\nconst cx = cw - cw * FS * 2.2 - cw * TW / 2 - cw / 2, cy = ch - cw * FS * 2.2 - th * 0.8 - ch / 2;\nconst push = tall ? 0.68 : 0.95, turn = tall ? 0.2 : 1;\nconst 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\ns.update((t) => {\n  // how many have arrived, continuously: each arrival is a spring\n  const arr = T.map((a) => (t >= a ? spring(t - a, { stiffness: 210, damping: 19 }) : 0));\n  const count = arr.reduce((x, y) => x + Math.min(1, y), 0);\n  toasts.forEach((el, i) => {\n    const age = count - 1 - i;                                     // 0 = front, 1 = one behind, …\n    const inn = arr[i];\n    if (inn <= 0) { el.style.opacity = '0'; return; }\n    const lift = age <= 0 ? (1 - inn) * -th * 1.4 : age * gap;     // the newest rises from below; the others step back\n    const sc = 1 - Math.max(0, age) * 0.06;\n    el.style.transform = `translateY(${-lift}px) scale(${sc})`;\n    el.style.opacity = String(Math.min(1, inn * 2) * Math.max(0, 1 - Math.max(0, age - 1.6) * 1.5));\n    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\n    el.style.zIndex = String(100 - i * 0 + i);\n    el.style.filter = age > 0.5 ? `brightness(${1 - 0.08 * age})` : 'none';\n  });\n  // the camera: close on the corner, leaning a little with each arrival\n  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);\n  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 });\n  comp.style.opacity = String(progress(t, 0, 0.3));\n});\nT.forEach((a) => B.cue(s, 'text', a));\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/toast-stack/brief.md",
      "content": "# Toast stack\n\nBlock: toast-stack (5.2 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nNotifications arrive in a corner one after another and push the older ones back into a stack; the last carries the accent.\n\nA block is one ready-made moment. Edit `CONFIG` (its words, numbers and format: 16:9, 9:16 or 1:1, the layout recomposes for each); check `npx paper-motion still` at 4 and 5.2 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add toast-stack --name my-toast-stack\n# edit CONFIG in pieces/my-toast-stack/scene.html, then:\nnpx paper-motion render pieces/my-toast-stack/scene.html --motion-blur 5",
  "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 `format` and the layout and camera follow."
  ],
  "related": [
    "terminal-run",
    "drag-drop"
  ],
  "preview": {
    "video": "previews/toast-stack.webm",
    "poster": "previews/toast-stack.jpg",
    "at": 4.6,
    "values": {}
  },
  "mood": [
    "playful",
    "minimal"
  ],
  "duration": 5.2,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Toasts",
      "from": 0.7,
      "to": 4,
      "what": "toasts"
    },
    {
      "name": "Hold",
      "from": 4,
      "to": 5.2,
      "what": "hold"
    }
  ],
  "when": [
    "a process that reports as it goes",
    "a run of quick wins"
  ],
  "needs": [
    {
      "kind": "events",
      "fill": {
        "toasts": "$items"
      }
    }
  ]
}