{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "stat-compare",
  "type": "block",
  "title": "Stat compare",
  "summary": "The old number is struck through and falls away soft; the new one arrives from deep in the scene and lands in the accent.",
  "tags": [
    "block",
    "data",
    "number",
    "before-after",
    "comparison"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "name": "label",
      "type": "string",
      "default": "per launch video",
      "description": "label",
      "group": "main",
      "control": "text"
    },
    {
      "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-compare/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>stat-compare</title>\n<!--\n  Data · stat compare (5 s). One number, then the number that replaces it. The old figure is struck through, tips\n  and falls out of frame, soft; the new one arrives from deep in the scene on a spring and lands in the accent, while\n  the line above it changes from how it was to how it is now. The camera answers the landing with a small push.\n  Vertical: each figure stacks its words (40 / min) and grows to fill the width; square: the figures fit the width.\n  Old 0.2–1.3 s · Strike 1.4–1.8 s · Fall 2.0–2.7 s · New 2.2–2.9 s · Hold to 5 s.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #p { display: flex; flex-direction: column; align-items: center; text-align: center; }\n  #cap { position: relative; }\n  #cap > div { white-space: nowrap; }\n  #cap .b { position: absolute; left: 50%; top: 0; transform: translateX(-50%); }\n  #nums { position: relative; }\n  #old, #new { white-space: nowrap; line-height: 1; }\n  #new { position: absolute; left: 50%; top: 0; }\n  #strike { position: absolute; left: -4%; right: -4%; top: 54%; transform-origin: 0 50%; }\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=\"p\"><div id=\"cap\"><div class=\"a\"></div><div class=\"b\"></div></div><div id=\"nums\"><div id=\"old\"><span id=\"oldt\"></span><div id=\"strike\"></div></div><div id=\"new\"></div></div><div id=\"label\"></div></div></div>\n</main>\n<script type=\"module\">\nimport { scene, progress, ease, spring } from 'paper-motion';\nimport { wordRise, 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  before: { caption: 'By hand', value: '40 min' },\n  after: { caption: 'With paper-motion', value: '2 min' },\n  label: 'per launch video',\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 5;\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 bg = $('bg'); bg.style.opacity = 0.45;\n$('vig').style.background = 'radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0) 30%, rgba(0,0,0,0.65) 100%)';\nfunction $(id) { return document.getElementById(id); }\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, big0 = SHORT * K * 0.3; let big = big0;\nconst oldT = B.style($('oldt'), 'display', { short: SHORT * K, color: 'figure' }), nw = B.style($('new'), 'display', { short: SHORT * K, color: 'figure' });\nfor (const el of [oldT, nw]) el.style.fontSize = `${big}px`;\noldT.textContent = CONFIG.before.value; nw.textContent = CONFIG.after.value; nw.style.color = accent;\nconst capA = B.style($('cap').children[0], 'body', { short: SHORT * K, color: 'muted' }), capB = B.style($('cap').children[1], 'body', { short: SHORT * K, color: 'figure' });\nfor (const el of [capA, capB]) Object.assign(el.style, { fontFamily: B.font('mono'), fontSize: `${SHORT * K * (tall ? 0.045 : 0.032)}px`, letterSpacing: '0.02em' });\ncapA.textContent = CONFIG.before.caption; capB.textContent = CONFIG.after.caption;\nconst label = B.style($('label'), 'title', { short: SHORT * K, color: 'muted' });\nlabel.textContent = CONFIG.label; label.style.fontSize = `${SHORT * K * (tall ? 0.075 : 0.05)}px`; label.style.marginTop = `${SHORT * (tall ? 0.04 : 0.02)}px`;\n$('cap').style.marginBottom = `${SHORT * (tall ? 0.05 : 0.03)}px`;\nconst strike = $('strike'); Object.assign(strike.style, { height: `${big * 0.035}px`, background: '#d0715f', borderRadius: '999px' });\n$('p').style.width = `${W}px`;\ncam.place($('p'), { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\n// the figures fit the frame at the closest push (a margin each side): only narrow frames shrink them\nconst closest = (SHORT * 1.7) / (SHORT * 1.7 + DIST - SHORT * 0.25);\nconst strikes = [strike];\nif (tall) {   // one word per line, and one strike per line\n  for (const el of [$('old'), nw]) Object.assign(el.style, { width: 'min-content', whiteSpace: 'normal' });\n  const s2 = strike.cloneNode(); $('old').append(s2); strikes.push(s2);\n  strike.style.top = '27%'; s2.style.top = '77%';\n}\nconst widest = Math.max($('old').offsetWidth, nw.offsetWidth);\nbig = Math.min(big0 * (tall ? 1.6 : 1), big0 * (W * 0.84 / closest) / widest);\nfor (const el of [oldT, nw]) el.style.fontSize = `${big}px`;\nstrikes.forEach((e) => { e.style.height = `${big * 0.035}px`; });\n\nconst T = { old: 0.2, strike: [1.4, 1.8], fall: [1.95, 2.45], nw: 2.4 };\nconst old = $('old');\ns.update((t) => {\n  wordRise(oldT, t, { start: T.old, each: B.pace.stagger, duration: 0.8 });\n  blurIn(capA, t, { start: T.old + 0.3, duration: 0.6 });\n  blurIn(label, t, { start: T.old + 0.5, duration: 0.7 });\n  strikes.forEach((e, i) => { e.style.transform = `scaleX(${progress(t, T.strike[0] + i * 0.12, T.strike[1] + i * 0.12, ease.inOutCubic)})`; });\n  // the old number tips and falls, going soft as it goes\n  const f = progress(t, ...T.fall, ease.inCubic);\n  old.style.transform = `translateY(${f * SHORT * 0.7}px) rotate(${f * 9}deg)`;\n  old.style.filter = f > 0.02 ? `blur(${f * 14}px)` : 'none';\n  old.style.opacity = String(Math.max(0, 1 - f * 1.8));\n  // the new one comes from deep in the scene: small, soft and far, landing full size with a spring\n  const n = t >= T.nw ? spring(t - T.nw, { stiffness: 120, damping: 12 }) : 0;\n  nw.style.transform = `translateX(-50%) scale(${0.18 + 0.82 * n})`;\n  nw.style.filter = n < 0.95 ? `blur(${(1 - Math.min(1, n)) * 18}px)` : 'none';\n  nw.style.opacity = String(Math.min(1, n * 2.5));\n  // the caption swaps as the numbers do\n  const c = progress(t, T.fall[0], T.nw + 0.3, ease.inOutCubic);\n  capA.style.opacity = String(Math.min(progress(t, T.old + 0.3, T.old + 0.9), 1 - Math.min(1, c * 2))); capA.style.transform = `translateY(${-c * 0.6}em)`;\n  capB.style.opacity = String(Math.max(0, c * 2 - 1)); capB.style.transform = `translateX(-50%) translateY(${(1 - c) * 0.6}em)`;\n  // the camera: a slow drift, then a small push that answers the landing\n  const arrive = progress(t, 0, 1.2, ease.outCubic), push = progress(t, T.nw + 0.2, D, ease.outCubic);\n  const kick = t >= T.nw + 0.3 ? Math.sin(Math.min(1, (t - T.nw - 0.3) / 0.35) * Math.PI) : 0;\n  cam.at({ x: SHORT * 0.02 * (1 - push), y: 0, z: DIST + SHORT * 0.25 * (1 - arrive) - SHORT * 0.22 * push - SHORT * 0.03 * kick, yaw: 5 * (1 - arrive) - 3 * push * 0.3, pitch: 0 });\n  bg.style.transform = `scale(${1.1 + 0.08 * progress(t, 0, D)})`;\n});\nB.cue(s, 'text', T.old); B.cue(s, 'transition', T.strike[0]); B.cue(s, 'land', T.nw + 0.3);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/stat-compare/brief.md",
      "content": "# Stat compare\n\nBlock: stat-compare (5 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nThe old number is struck through and falls away soft; the new one arrives from deep in the scene and lands in 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 1.3 and 1.8 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add stat-compare --name my-stat-compare\n# edit CONFIG in pieces/my-stat-compare/scene.html, then:\nnpx paper-motion render pieces/my-stat-compare/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": [
    "code-diff",
    "before-after"
  ],
  "preview": {
    "video": "previews/stat-compare.webm",
    "poster": "previews/stat-compare.jpg",
    "at": 4.6,
    "values": {}
  },
  "mood": [
    "bold"
  ],
  "duration": 5,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Old",
      "from": 0.2,
      "to": 1.3,
      "what": "old"
    },
    {
      "name": "Strike",
      "from": 1.4,
      "to": 1.8,
      "what": "strike"
    },
    {
      "name": "Fall",
      "from": 2,
      "to": 2.7,
      "what": "fall"
    },
    {
      "name": "New",
      "from": 2.2,
      "to": 2.9,
      "what": "new"
    },
    {
      "name": "Hold",
      "from": 2.9,
      "to": 5,
      "what": "hold"
    }
  ],
  "when": [
    "how much time or money it saves",
    "a before and after in one figure"
  ],
  "needs": [
    {
      "kind": "change",
      "fill": {
        "before": {
          "caption": "$fromLabel",
          "value": "$from"
        },
        "after": {
          "caption": "$toLabel",
          "value": "$to"
        },
        "label": "$label"
      }
    }
  ]
}