{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "callout-zoom",
  "type": "block",
  "title": "Callout zoom",
  "summary": "A ring pulses on a detail too small to read; a round lens grows out of it and shows it magnified, tied back by a thin line.",
  "tags": [
    "block",
    "annotation",
    "zoom",
    "magnify",
    "ui"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "name": "detail",
      "type": "number",
      "default": 2,
      "description": "which row the lens magnifies",
      "group": "main"
    },
    {
      "name": "zoom",
      "type": "number",
      "default": 2.8,
      "description": "how much the lens magnifies",
      "group": "main"
    },
    {
      "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/callout-zoom/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>callout-zoom</title>\n<!--\n  Annotation · callout zoom (5 s). A detail too small to read on screen: a ring pulses on it, then a round lens grows\n  out of that point, travels out past the edge of the screen and shows the detail magnified, tied back to its source\n  by a thin line. The camera drifts toward the lens.\n  Arrive 0–0.9 s · Pulse 1.0 s · Lens 1.3–2.2 s · Hold 2.2–5 s.\n  Vertical: a tall screen without sidebar, the lens drops into the space below the rows; square: a squarer screen.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #comp { position: absolute; box-sizing: border-box; }\n  #screen { position: absolute; inset: 0; overflow: hidden; }\n  .ui { position: absolute; left: 0; top: 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.2em; padding: 2.2em; }\n  .rows { border-radius: 0.8em; padding: 0.6em 1.4em; }\n  .r { display: flex; justify-content: space-between; align-items: center; padding: 0.9em 0; }\n  i { display: block; height: 0.6em; border-radius: 999px; }\n  #lens { position: absolute; overflow: hidden; border-radius: 50%; }\n  #lens .ui { transform-origin: 0 0; }\n  #tie, #dot { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }\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 id=\"screen\"><div class=\"ui\" id=\"ui\"></div></div><svg id=\"tie\"><line id=\"line\"/><circle id=\"ring\"/></svg><div id=\"lens\"></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  rows: [['Format', '1920 × 1080'], ['Frame rate', '30 fps'], ['Motion blur', '4 samples'], ['Sound', 'from /brand'], ['Output', 'mp4 · webm']],\n  detail: 2,                             // which row the lens magnifies\n  zoom: 2.8,                             // how much the lens magnifies\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);\ndocument.querySelector('#bg').style.opacity = 0.3;\nconst $ = (id) => 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 tall = H > W, square = W === H;\nconst comp = $('comp'), cw = (tall ? W * 0.86 : square ? W * 0.8 : W * 0.62) * K, ch = cw * (tall ? 1.3 : square ? 0.74 : 0.6), 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');\nObject.assign(comp.style, { width: `${cw}px`, height: `${ch}px` });\nObject.assign($('screen').style, { 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)` });\nconst ui = $('ui'); Object.assign(ui.style, { width: `${cw}px`, height: `${ch}px`, fontSize: `${cw * (tall ? 0.021 : square ? 0.0135 : 0.0095)}px` });\nif (tall) ui.style.gridTemplateColumns = '1fr';\nconst line = (w, c = muted, o = 0.45) => `<i style=\"width:${w}%;background:${c};opacity:${o}\"></i>`;\nconst row = ([k, v], i) => `<div class=\"r\" data-i=\"${i}\" style=\"${i ? `border-top:1px solid ${muted}22` : ''}\"><span style=\"font:400 1.15em ${B.font('text')};color:${muted}\">${k}</span><span style=\"font:500 1.15em ${B.font('mono')};color:${figure}\">${v}</span></div>`;\nui.innerHTML = `<div class=\"side\" style=\"background:${ground}${tall ? ';display:none' : ''}\">${line(70, figure, 0.9)}${line(85)}${line(60)}${line(75)}${line(50)}</div>\n<div class=\"main\">${line(22, figure, 0.9)}${line(48)}<div class=\"rows\" style=\"background:${ground};border:1px solid ${muted}33\">${CONFIG.rows.map(row).join('')}</div>${line(80)}${line(66)}${tall ? `<div style=\"height:3em\"></div>${line(30, figure, 0.7)}${line(88)}${line(74)}${line(92)}${line(60)}<div style=\"height:3em\"></div>${line(26, figure, 0.7)}${line(84)}${line(70)}` : ''}</div>`;\ncam.place(comp, { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\n\n// the source: the centre of the value in the chosen row, in the screen's own pixels\nconst src = ui.querySelector(`.r[data-i=\"${CONFIG.detail}\"] span:last-child`), pr = ui.getBoundingClientRect(), sr = src.getBoundingClientRect(), sc = cw / pr.width;\nconst sx = (sr.left - pr.left + sr.width * 0.5) * sc, sy = (sr.top - pr.top + sr.height / 2) * sc;\n// the lens: grows out of the source and settles up and out past the right edge of the screen\nconst r = tall ? cw * 0.23 : ch * (square ? 0.23 : 0.21), lx = sx - cw * (tall ? 0.24 : 0.3), ly = sy + ch * (tall ? 0.3 : 0.34), Z = CONFIG.zoom;\nconst lens = $('lens'), inner = ui.cloneNode(true); inner.removeAttribute('id'); lens.append(inner);\nObject.assign(lens.style, { background: B.surface(0.2), border: `${SHORT * 0.004 * K}px solid ${accent}`, boxShadow: `0 ${SHORT * 0.03}px ${SHORT * 0.09}px rgba(0,0,0,0.6)` });\nconst lineEl = $('line'), ring = $('ring');\nObject.assign(lineEl.style, { stroke: accent, strokeWidth: `${SHORT * 0.0025 * K}`, strokeLinecap: 'round' });\nObject.assign(ring.style, { fill: 'none', stroke: accent, strokeWidth: `${SHORT * 0.003 * K}` });\nring.setAttribute('cx', sx); ring.setAttribute('cy', sy);\nconst T = { pulse: 1.0, lens: [1.3, 2.2] };\n\ns.update((t) => {\n  const arrive = progress(t, 0, 0.9, ease.outCubic), drift = progress(t, T.lens[0], D, ease.inOutSine);\n  cam.at({ x: ((lx + sx) / 2 - cw / 2) * drift, y: ((ly + sy) / 2 - ch / 2) * drift, z: DIST + SHORT * 0.3 * (1 - arrive) - SHORT * 0.6 * drift, yaw: 8 * (1 - arrive) - 3 * drift, pitch: 3 * (1 - arrive) });\n  comp.style.opacity = String(progress(t, 0, 0.35));\n  // the pulse: a ring that tightens onto the source and stays as its anchor\n  const pin = t >= T.pulse ? spring(t - T.pulse, { stiffness: 260, damping: 16 }) : 0;\n  ring.setAttribute('r', String(Math.max(0, ch * (0.09 - 0.065 * pin))));\n  ring.style.opacity = String(progress(t, T.pulse, T.pulse + 0.15));\n  // the lens: out of the source on a spring, growing as it travels\n  const g = t >= T.lens[0] ? spring(t - T.lens[0], { stiffness: 140, damping: 15 }) : 0;\n  const cx = sx + (lx - sx) * g, cy = sy + (ly - sy) * g, rr = Math.max(0.01, r * Math.min(1.08, g));\n  Object.assign(lens.style, { left: `${cx - rr}px`, top: `${cy - rr}px`, width: `${rr * 2}px`, height: `${rr * 2}px`, opacity: String(Math.min(1, g * 4)) });\n  const z = 1 + (Z - 1) * Math.min(1, g);                                            // the magnification grows with the lens\n  inner.style.transform = `translate(${rr - sx * z}px, ${rr - sy * z}px) scale(${z})`;\n  // the tie: from the anchor ring to the lens edge\n  const dx = cx - sx, dy = cy - sy, len = Math.hypot(dx, dy) || 1, ar = ch * 0.025;\n  lineEl.setAttribute('x1', sx + dx / len * ar); lineEl.setAttribute('y1', sy + dy / len * ar);\n  lineEl.setAttribute('x2', cx - dx / len * rr); lineEl.setAttribute('y2', cy - dy / len * rr);\n  lineEl.style.opacity = String(progress(t, T.lens[0] + 0.15, T.lens[0] + 0.4) * (len > rr + ar ? 1 : 0));\n});\nB.cue(s, 'transition', 0); B.cue(s, 'text', T.pulse); B.cue(s, 'land', T.lens[0] + 0.4);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/callout-zoom/brief.md",
      "content": "# Callout zoom\n\nBlock: callout-zoom (5 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nA ring pulses on a detail too small to read; a round lens grows out of it and shows it magnified, tied back by a thin line.\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 0.9 and 1.6 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add callout-zoom --name my-callout-zoom\n# edit CONFIG in pieces/my-callout-zoom/scene.html, then:\nnpx paper-motion render pieces/my-callout-zoom/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": [
    "circle-mark",
    "focus-pull"
  ],
  "preview": {
    "video": "previews/callout-zoom.webm",
    "poster": "previews/callout-zoom.jpg",
    "at": 3.6,
    "values": {}
  },
  "mood": [
    "technical",
    "calm"
  ],
  "duration": 5,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Arrive",
      "from": 0,
      "to": 0.9,
      "what": "arrive"
    },
    {
      "name": "Pulse",
      "from": 1,
      "to": 1.6,
      "what": "pulse"
    },
    {
      "name": "Lens",
      "from": 1.3,
      "to": 2.2,
      "what": "lens"
    },
    {
      "name": "Hold",
      "from": 2.2,
      "to": 5,
      "what": "hold"
    }
  ],
  "when": [
    "a setting or value that is too small on screen",
    "show a detail without cutting away"
  ],
  "needs": [
    {
      "kind": "table",
      "fill": {
        "rows": "$rows",
        "detail": "$main"
      }
    }
  ]
}