{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "stat-row",
  "type": "block",
  "title": "Stat row",
  "summary": "Three numbers count up in turn with rules drawing between them; the camera meets each as it counts, then pulls back to all three.",
  "tags": [
    "block",
    "data",
    "numbers",
    "metrics",
    "counter"
  ],
  "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/stat-row/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>stat-row</title>\n<!--\n  Data · stat row (5.6 s). Three numbers side by side, each counting up in turn with its label rising under it and a\n  thin rule drawing between them. The camera travels along the row close, meeting each number as it counts, then\n  pulls back to show all three at once.\n  Counts 0.5, 1.4, 2.3 s · Pull back 3.0–4.6 s · Hold to 5.6 s.\n  Vertical: the row becomes a column with horizontal rules, and the camera travels down it instead of across.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #row { position: absolute; display: flex; align-items: flex-start; }\n  .st { flex: 1; display: flex; flex-direction: column; align-items: flex-start; }\n  .rule { width: 1.5px; align-self: stretch; transform-origin: 50% 0; }\n  .num { line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap; }\n</style>\n</head>\n<body>\n<main id=\"stage\">\n  <div id=\"bg\" class=\"abs\" style=\"inset:0\"></div>\n  <div id=\"vig\" class=\"abs\" style=\"inset:0\"></div>\n  <div id=\"world\"><div id=\"row\"></div></div>\n</main>\n<script type=\"module\">\nimport { scene, progress, ease } from 'paper-motion';\nimport { blurIn } from 'paper-motion/moves';\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  stats: [[36, '', 'brands made'], [1284, '', 'videos rendered'], [2, ' min', 'from brief to mp4']],\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 5.6;\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.4;\n$('vig').style.background = 'radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0) 30%, rgba(0,0,0,0.65) 100%)';\n\nconst DIST = SHORT * 0.62, K = 1 + DIST / (SHORT * 1.7);\nconst cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });\nconst accent = B.color('accent', '#E9E4D8'), muted = B.color('muted');\nconst tall = H > W;\nconst rw = W * (tall ? 0.8 : 0.86) * K, row = $('row');\nObject.assign(row.style, { width: `${rw}px`, gap: `${rw * 0.04}px` });\nif (tall) { row.style.flexDirection = 'column'; row.style.alignItems = 'center'; }\nconst items = CONFIG.stats.map(([v, unit, label], i) => {\n  if (i) { const r = document.createElement('div'); r.className = 'rule'; r.style.background = `${muted}66`; row.append(r); }\n  const st = document.createElement('div'); st.className = 'st';\n  const num = B.style(document.createElement('div'), 'display', { short: SHORT * K, color: i === 1 ? 'figure' : 'figure' }); num.className = 'num'; num.style.fontSize = `${rw * (tall ? 0.22 : 0.085)}px`;\n  const lab = B.style(document.createElement('div'), 'body', { short: SHORT * K, color: 'muted' }); lab.textContent = label; Object.assign(lab.style, { fontSize: `${rw * (tall ? 0.04 : 0.017)}px`, marginTop: `${rw * 0.012}px`, fontFamily: B.font('mono') });\n  st.append(num, lab); row.append(st);\n  if (tall) st.style.alignItems = 'center';\n  return { st, num, lab, v, unit };\n});\nitems[1].num.style.color = accent;\ncam.place(row, { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\nconst rules = [...row.querySelectorAll('.rule')];\nif (tall) rules.forEach((r) => Object.assign(r.style, { width: '28%', height: '1.5px', alignSelf: 'center', transformOrigin: '50% 50%' }));\nconst fmt = (n) => n.toLocaleString('en-US');\n\nconst T = { counts: [0.5, 1.4, 2.3], back: [3.0, 4.6] };\nconst rh = row.offsetHeight;\nitems.forEach(({ num, v, unit }) => { num.innerHTML = `${fmt(v)}<span style=\"font-size:0.5em\">${unit}</span>`; });   // measure at full size\nconst rr = row.getBoundingClientRect(), k0 = rw / rr.width;\nconst rhFull = row.offsetHeight;\nconst centers = tall\n  ? items.map(({ num }) => num.offsetTop + num.offsetHeight * 0.7 - rhFull / 2)\n  : items.map(({ num }) => { const b = num.getBoundingClientRect(); return (b.left - rr.left + b.width / 2) * k0 - rw / 2; });\ns.update((t) => {\n  items.forEach(({ num, lab, v, unit, st }, i) => {\n    const a = T.counts[i], tq = Math.round(t * 30) / 30, p = progress(tq, a, a + 0.9, ease.outCubic);   // one value per frame: no blurred digits\n    num.innerHTML = `${fmt(Math.round(v * p))}<span style=\"font-size:0.5em;opacity:0.7\">${unit}</span>`;\n    num.style.opacity = String(progress(t, a - 0.2, a + 0.1));\n    num.style.transform = `translateY(${(1 - progress(t, a - 0.2, a + 0.4, ease.outCubic)) * 0.3}em)`;\n    blurIn(lab, t, { start: a + 0.3, duration: 0.6 });\n  });\n  rules.forEach((r, i) => { r.style.transform = `${tall ? 'scaleX' : 'scaleY'}(${progress(t, T.counts[i + 1] - 0.3, T.counts[i + 1] + 0.2, ease.inOutCubic)})`; });\n  // the camera: along the row, meeting each number as it counts, then back to see all three\n  let along = centers[0];\n  for (let i = 1; i < centers.length; i++) along += (centers[i] - centers[i - 1]) * progress(t, T.counts[i] - 0.75, T.counts[i] + 0.1, ease.inOutSine);\n  const back = progress(t, ...T.back, ease.inOutCubic), arrive = progress(t, 0, 0.7, ease.outCubic);\n  if (tall) return cam.at({ x: 0, y: along * (1 - back), z: DIST + SHORT * 0.25 * (1 - arrive) - SHORT * 0.75 * (1 - back) - SHORT * 0.5 * back, yaw: 0, pitch: -3 * (1 - back) + 1 * back, roll: 1.5 * (1 - back) });\n  cam.at({ x: along * (1 - back), y: rh * (0.05 + 0.3 * back), z: DIST + SHORT * 0.25 * (1 - arrive) - SHORT * 0.75 * (1 - back) + SHORT * (W === H ? 0.02 : 0.1) * back, yaw: -3 * (1 - back) + 1 * back, pitch: 2 * (1 - back), roll: 0 });\n});\nT.counts.forEach((a) => B.cue(s, 'text', a)); B.cue(s, 'land', T.back[1]);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/stat-row/brief.md",
      "content": "# Stat row\n\nBlock: stat-row (5.6 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nThree numbers count up in turn with rules drawing between them; the camera meets each as it counts, then pulls back to all three.\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 2.9 and 4.6 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add stat-row --name my-stat-row\n# edit CONFIG in pieces/my-stat-row/scene.html, then:\nnpx paper-motion render pieces/my-stat-row/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": [
    "donut-fill",
    "bar-grow"
  ],
  "preview": {
    "video": "previews/stat-row.webm",
    "poster": "previews/stat-row.jpg",
    "at": 5.3,
    "values": {}
  },
  "mood": [
    "bold",
    "calm"
  ],
  "duration": 5.6,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Counts",
      "from": 0.5,
      "to": 2.9,
      "what": "counts"
    },
    {
      "name": "Pull back",
      "from": 3,
      "to": 4.6,
      "what": "pull back"
    },
    {
      "name": "Hold",
      "from": 4.6,
      "to": 5.6,
      "what": "hold"
    }
  ],
  "when": [
    "the closing numbers of a launch",
    "three metrics at once"
  ],
  "needs": [
    {
      "kind": "figure",
      "count": 3,
      "where": {
        "numeric": true
      },
      "fill": {
        "stats": {
          "$each": [
            "$value",
            "$unit",
            "$label"
          ]
        }
      }
    }
  ]
}