{
  "$schema": "../../schema.json",
  "type": "recipe",
  "version": "1.0.0",
  "license": "MIT",
  "id": "before-after",
  "title": "Before / after",
  "summary": "Two states of the same thing in one panel: the old one muted, a wipe, the new one in the brand's colors, then the close, in 16 s.",
  "tags": [
    "recipe",
    "before",
    "after",
    "comparison",
    "wipe",
    "16:9",
    "1:1"
  ],
  "params": [
    {
      "name": "beforeTag",
      "type": "string",
      "default": "Before",
      "description": "label of the old state",
      "group": "main",
      "control": "text"
    },
    {
      "name": "beforeLine",
      "type": "string",
      "default": "Forty minutes, three tools, one guess.",
      "description": "the old state, in one line",
      "group": "main",
      "control": "text"
    },
    {
      "name": "beforeImage",
      "type": "string",
      "default": "",
      "description": "a picture of the old state (path)",
      "group": "advanced",
      "control": "text"
    },
    {
      "name": "afterTag",
      "type": "string",
      "default": "After",
      "description": "label of the new state",
      "group": "main",
      "control": "text"
    },
    {
      "name": "afterLine",
      "type": "string",
      "default": "One command. Every frame on purpose.",
      "description": "the new state, in one line",
      "group": "main",
      "control": "text"
    },
    {
      "name": "afterImage",
      "type": "string",
      "default": "",
      "description": "a picture of the new state (path)",
      "group": "advanced",
      "control": "text"
    },
    {
      "name": "action",
      "type": "string",
      "default": "your.site",
      "description": "the one action at the end",
      "group": "main",
      "control": "text"
    },
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "main",
      "control": "select"
    },
    {
      "name": "format",
      "type": "enum",
      "default": "1920x1080",
      "options": [
        "1920x1080",
        "1080x1920",
        "1080x1080"
      ],
      "description": "output size",
      "group": "main",
      "control": "segmented"
    }
  ],
  "install": {
    "kind": "scene"
  },
  "files": [
    {
      "path": "pieces/before-after/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>before-after</title>\n<!--\n  Recipe · before / after (16 s). Two states of the same thing, one wipe between them.\n  One idea: the panel is a slab standing in space. The camera meets the BEFORE from the side, flat and grey, almost\n  in profile; as a plane sweeps across the slab the camera swings around to face it, and the AFTER arrives with depth:\n  its label and its line float in front of the slab and parallax as the camera keeps turning slowly. The close is the\n  camera leaving past the edge of the slab toward the name.\n  Before 0–6 s · Wipe 6–7.5 s · After 7.5–13 s · Close 13–16 s.\n  Look, fonts, pace and sound come from /brand (serve from the project root). Edit CONFIG first: a real picture of each\n  state (`image`) beats any panel; without one, each state is a panel with its line.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  .place { display: flex; flex-direction: column; align-items: center; text-align: center; box-sizing: border-box; }\n  .state { position: absolute; inset: 0; overflow: hidden; }\n  .state img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }\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\">\n    <div id=\"panel\"></div>\n    <div id=\"tag-before\"></div><div id=\"line-before\"></div>\n    <div id=\"tag-after\"></div><div id=\"line-after\"></div>\n    <div id=\"p-close\" class=\"place\"><div id=\"mark\"></div><div id=\"action\"></div></div>\n  </div>\n</main>\n<script type=\"module\">\nimport { scene, progress, ease } from 'paper-motion';\nimport { wordRise, blurIn, wipe } 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 behind the after state, or null for the brand's first entry\n  before: { tag: 'Before', line: 'Forty minutes, three tools, one guess.', image: '' },\n  after: { tag: 'After', line: 'One command. Every frame on purpose.', image: '' },\n  action: 'your.site',\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 16;\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 = document.querySelector('#bg'); bg.style.opacity = 0.45;\ndocument.querySelector('#vig').style.background = 'radial-gradient(ellipse at 50% 55%, rgba(0,0,0,0) 30%, rgba(0,0,0,0.6) 100%)';\nconst $ = (id) => document.getElementById(id);\n\nconst DIST = SHORT * 0.7, K = 1 + DIST / (SHORT * 1.7), STEP = SHORT * 1.6;\nconst cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });\nconst mark = B.style($('mark'), 'display', { short: SHORT * K }), action = B.style($('action'), 'body', { short: SHORT * K, color: 'figure' });\nObject.assign(action.style, { fontFamily: B.font('mono'), fontSize: `${SHORT * K * 0.028}px`, letterSpacing: '0em', marginTop: `${SHORT * 0.03}px` });\nmark.textContent = B.name; action.textContent = CONFIG.action;\n$('p-close').style.width = `${W * 0.9}px`;\ncam.place($('p-close'), { x: STEP, yaw: -8 });\n\n// the slab: both states fill it; the wipe runs inside\nconst R = (B.tokens?.shape?.radius ?? 12) * (SHORT / 1080) * K;\nconst panel = $('panel'), pw = W * 0.6 * K, ph = pw * 0.56;\nObject.assign(panel.style, { width: `${pw}px`, height: `${ph}px`, borderRadius: `${R}px`, overflow: 'hidden', border: `1.5px solid ${B.color('muted')}55`, boxShadow: `0 ${SHORT * 0.04}px ${SHORT * 0.12}px rgba(0,0,0,0.5)` });\ncam.place(panel, { x: 0, y: 0, z: 0 });\nconst state = (cfg, after) => {\n  const el = document.createElement('div');\n  el.className = 'state';\n  el.style.background = after ? B.surface() : '#262626';\n  if (cfg.image) { const img = document.createElement('img'); img.src = cfg.image; if (!after) img.style.filter = 'grayscale(1) contrast(0.9) brightness(0.7)'; el.append(img); }\n  else if (after && bgId) { const f = document.createElement('div'); Object.assign(f.style, { position: 'absolute', inset: 0, opacity: 0.85 }); el.append(f); B.shader(s, f, bgId); }\n  else { el.style.background = 'linear-gradient(160deg, #2c2c2c, #1a1a1a)'; }\n  const band = document.createElement('div'); Object.assign(band.style, { position: 'absolute', left: 0, right: 0, bottom: 0, height: '55%', background: `linear-gradient(to top, ${after ? B.color('ground') : '#000000'}dd 0%, transparent 100%)` }); el.append(band);\n  panel.append(el);\n  return el;\n};\nconst before = state(CONFIG.before, false), after = state(CONFIG.after, true);\n// the words float in front of the slab: the before ones flat on it, the after ones a step closer (they parallax)\nconst tagOf = (id, cfg, after) => {\n  const tag = B.style($(id), 'caption', { short: SHORT * K, color: after ? 'ground' : 'figure' });\n  Object.assign(tag.style, { fontFamily: B.font('mono'), padding: `${SHORT * 0.007 * K}px ${SHORT * 0.014 * K}px`, borderRadius: `${R * 0.5}px`, background: after ? B.color('accent', '#E9E4D8') : '#ffffff22', color: after ? B.color('ground') : '#ddd', whiteSpace: 'nowrap' });\n  tag.textContent = cfg.tag;\n  cam.place(tag, { x: -pw / 2 + pw * 0.08 + tag.offsetWidth / 2, y: -ph / 2 + ph * 0.1, z: after ? SHORT * 0.12 : SHORT * 0.01 });\n  return tag;\n};\nconst lineOf = (id, cfg, after) => {\n  const line = B.style($(id), 'title', { short: SHORT * K, color: 'figure' });\n  Object.assign(line.style, { width: `${pw * 0.9}px`, textAlign: 'left', color: after ? B.color('figure') : '#cfcfcf', textShadow: '0 2px 24px rgba(0,0,0,0.6)' });\n  line.textContent = cfg.line;\n  cam.place(line, { x: 0, y: ph / 2 - ph * 0.2, z: after ? SHORT * 0.16 : SHORT * 0.01 });\n  return line;\n};\nawait document.fonts.ready;\nconst tagB = tagOf('tag-before', CONFIG.before, false), lineB = lineOf('line-before', CONFIG.before, false);\nconst tagA = tagOf('tag-after', CONFIG.after, true), lineA = lineOf('line-after', CONFIG.after, true);\nfor (const el of [mark]) { el.style.whiteSpace = 'nowrap'; const k = (W * 0.84) / el.scrollWidth; if (k < 1) el.style.fontSize = `${parseFloat(el.style.fontSize) * k}px`; }\n\n// the camera: in profile on the before, swinging to face the after as the plane crosses, then slowly on, then away\nconst T = { wipe: [6, 7.5], close: [12.8, 13.8] };\nconst path = [\n  [0, { x: -SHORT * 0.5, y: SHORT * 0.02, z: DIST * 1.05, yaw: -34, pitch: 3 }],\n  [1.0, { x: -SHORT * 0.42, yaw: -30 }, ease.outCubic],\n  [T.wipe[0] - 0.4, { x: -SHORT * 0.3, yaw: -24 }],\n  [T.wipe[1] + 0.3, { x: 0, y: 0, z: DIST, yaw: 0, pitch: 0 }, ease.inOutCubic],       // the swing: face on with the after\n  [T.close[0] - 0.4, { x: SHORT * 0.08, yaw: 7, pitch: -1, z: DIST * 0.96 }, ease.inOutSine],   // a slow turn the other way\n  [T.close[1] + 0.3, { x: STEP, y: 0, z: DIST, yaw: 0, pitch: 0 }, ease.inOutQuart],\n  [D, { x: STEP, z: DIST * 0.92 }, ease.inOutSine],\n];\nconst RESET = ['transform', 'opacity', 'filter', 'clipPath', 'zIndex'];\ns.update((t) => {\n  cam.travel(t, path);\n  cam.focus(DIST, SHORT * 1.1, 8);\n  bg.style.transform = `scale(${1.1 + 0.06 * progress(t, 0, D)}) translateX(${SHORT * 0.05 * progress(t, 0, D)}px)`;\n  // the plane crosses the slab; the before words leave with it, the after words arrive just behind it\n  RESET.forEach((k) => { before.style[k] = ''; after.style[k] = ''; });\n  before.style.zIndex = 1; after.style.zIndex = 2;\n  if (t < T.wipe[0]) { before.style.opacity = 1; after.style.opacity = 0; }\n  else if (t < T.wipe[1]) wipe(before, after, progress(t, ...T.wipe));\n  else { before.style.opacity = 0; after.style.opacity = 1; }\n  blurIn(tagB, t, { start: 0.6, duration: 0.6 }); wordRise(lineB, t, { start: 1.0, each: B.pace.stagger, duration: 0.8 });\n  const outB = progress(t, T.wipe[0], T.wipe[0] + 0.6, ease.inCubic);\n  if (outB > 0) { tagB.style.opacity = String(Math.min(Number(tagB.style.opacity || 1), 1 - outB)); lineB.style.opacity = String(Math.min(Number(lineB.style.opacity || 1), 1 - outB)); }\n  blurIn(tagA, t, { start: T.wipe[1] - 0.1, duration: 0.6 }); wordRise(lineA, t, { start: T.wipe[1] + 0.1, each: B.pace.stagger, duration: 0.8 });\n  wordRise(mark, t, { start: T.close[0] + 0.25, each: B.pace.stagger, duration: 0.9 });\n  blurIn(action, t, { start: T.close[1] + 0.5, duration: 0.8 });\n});\nB.cue(s, 'land', 1.0); B.cue(s, 'transition', T.wipe[0]); B.cue(s, 'land', T.wipe[1] + 0.1); B.cue(s, 'transition', T.close[0]); B.cue(s, 'land', T.close[1] + 0.3);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/before-after/brief.md",
      "content": "# Before / after\n\nRecipe: before-after (16 s), from paper-motion.app. The look, fonts, pace and sound come from `brand/`.\n\n## Before building\n- Agree the brief with the user: the two states in one line each (a real contrast, not a slogan), and a real\n  picture of each when there is one. The claim in the after line must be true (IDENTITY.md's Facts).\n- Edit `CONFIG`: `before` and `after` (tag, line, image), `action`, the background id, the format.\n- Swap the wipe for the transition the user picked (`npx paper-motion add <id>`).\n\n## Check and render\n- `npx paper-motion still pieces/before-after/scene.html --t 3,6.7,10,15` and compare the two states side by side.\n- `npx paper-motion render pieces/before-after/scene.html --motion-blur 5`\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.1"
  },
  "usage": "npx paper-motion add before-after --name my-piece\n# edit CONFIG in pieces/my-piece/scene.html, then:\nnpx paper-motion render pieces/my-piece/scene.html --motion-blur 5",
  "notes": [
    "Wired to the brand folder: needs brand/tokens.json (a palette and a font pair work: pamo add sage-night instrument) and, for the background, a shader-set entry (pamo add mesh-sage).",
    "A real picture of each state beats any panel; the before picture is shown desaturated.",
    "Uses these moves from the engine: wipe, word-rise, blur-in, crossfade."
  ],
  "related": [
    "wipe",
    "mask-reveal",
    "launch"
  ],
  "preview": {
    "video": "previews/before-after.webm",
    "poster": "previews/before-after.jpg",
    "at": 10.5,
    "values": {
      "beforeLine": "Forty minutes in a timeline, one guess.",
      "afterLine": "One board. You choose. It renders.",
      "action": "paper-motion.app"
    }
  },
  "mood": [
    "bold",
    "technical",
    "minimal"
  ],
  "duration": 16,
  "formats": [
    "16:9",
    "1:1",
    "9:16"
  ],
  "beats": [
    {
      "name": "Before",
      "from": 0,
      "to": 6,
      "what": "the old state: muted panel, its line"
    },
    {
      "name": "Wipe",
      "from": 6,
      "to": 7.5,
      "what": "the new state sweeps in"
    },
    {
      "name": "After",
      "from": 7.5,
      "to": 13,
      "what": "the brand's state, the accent, its line"
    },
    {
      "name": "Close",
      "from": 13,
      "to": 16,
      "what": "the wordmark and the action"
    }
  ],
  "when": [
    "the product replaces a worse way",
    "a redesign, a migration, a result"
  ]
}