{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "circle-mark",
  "type": "block",
  "title": "Circle mark",
  "summary": "A hand-drawn ring closes around the number that matters on a screen; the rest dims, the marked card lifts and the camera leans in close.",
  "tags": [
    "block",
    "annotation",
    "highlight",
    "ui",
    "callout"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "name": "mark",
      "type": "number",
      "default": 1,
      "description": "which stat gets the ring",
      "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/circle-mark/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>circle-mark</title>\n<!--\n  Annotation · circle mark (4.5 s). A hand-drawn ring closes around the thing that matters on a screen: the stroke\n  overshoots its own start like a marker, the rest of the screen dims, the marked part lifts, and the camera leans in.\n  Arrive 0–0.9 s · Draw 1.0–1.7 s · Hold 1.7–4.5 s.\n  Vertical: a phone-width dashboard, no sidebar, a tall body; square: a squarer window. The lean stops where the ring fits.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #comp { position: absolute; overflow: hidden; box-sizing: border-box; }\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.6em; padding: 2.2em; }\n  .row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.4em; }\n  .card { border-radius: 0.8em; padding: 1.4em; display: flex; flex-direction: column; gap: 0.6em; }\n  i { display: block; height: 0.6em; border-radius: 999px; }\n  #dim { position: absolute; inset: 0; pointer-events: none; }\n  #ink { 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 class=\"ui\" id=\"ui\"></div><div id=\"dim\"></div><svg id=\"ink\"><path id=\"ring\"/></svg></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  stats: [['Renders', '1,284'], ['Avg. time', '2 min'], ['Brands', '36']],\n  mark: 1,                               // which stat gets the ring\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 4.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.6, 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.84 : W * 0.72) * K, ch = cw * (tall ? 1.5 : square ? 0.84 : 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');\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)` });\nconst ui = $('ui'); ui.style.fontSize = `${cw * (tall ? 0.021 : square ? 0.016 : 0.011)}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 card = (label, value, i) => `<div class=\"card\" data-i=\"${i}\" style=\"background:${ground};border:1px solid ${muted}33\"><div style=\"font:400 1.1em ${B.font('text')};color:${muted}\">${label}</div><div style=\"font:400 3.2em ${B.font('display')};color:${figure};line-height:1\">${value}</div>${line(40 + i * 12)}</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(24, figure, 0.9)}<div class=\"row\">${CONFIG.stats.map(([l, v], i) => card(l, v, i)).join('')}</div>\n<div class=\"card\" style=\"flex:1;background:${ground};border:1px solid ${muted}33\">${line(30, figure, 0.7)}${line(90)}${line(82)}${line(88)}${line(64)}${tall ? `<div style=\"height:2em\"></div>${line(26, figure, 0.7)}${line(86)}${line(92)}${line(70)}<div style=\"height:2em\"></div>${line(34, figure, 0.7)}${line(80)}${line(88)}${line(58)}` : ''}</div></div>`;\ncam.place(comp, { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\n\n// the ring: an ellipse drawn by hand around the marked card, a little wider than it, overshooting its start\nconst target = ui.querySelector(`.card[data-i=\"${CONFIG.mark}\"]`);\nconst cr = target.getBoundingClientRect(), pr = comp.getBoundingClientRect();\nconst sc = cw / pr.width;                                            // layout px per screen px (the camera scales the stage)\nconst cx = (cr.left - pr.left + cr.width / 2) * sc, cy = (cr.top - pr.top + cr.height / 2) * sc;\nconst rx = cr.width * sc * 0.56, ry = cr.height * sc * 0.8;\nconst pts = [], a0 = -2.3, turn = Math.PI * 2 + 0.55;\nfor (let k = 0; k <= 90; k++) {\n  const u = k / 90, a = a0 + turn * u;\n  const wob = 1 + 0.035 * Math.sin(a * 3 + 1.2) + 0.05 * u;          // uneven and spiralling a touch outward, like a hand\n  pts.push(`${(cx + Math.cos(a) * rx * wob).toFixed(1)},${(cy + Math.sin(a) * ry * wob - u * ry * 0.06).toFixed(1)}`);\n}\nconst ring = $('ring');\nring.setAttribute('d', `M${pts.join(' L')}`);\nObject.assign(ring.style, { fill: 'none', stroke: accent, strokeWidth: `${SHORT * 0.0075 * K}`, strokeLinecap: 'round', strokeLinejoin: 'round' });\nconst L = ring.getTotalLength(); ring.style.strokeDasharray = `${L}`;\nconst dim = $('dim');\ndim.style.background = 'rgba(0,0,0,0.55)';\nconst hole = `radial-gradient(ellipse ${rx * 1.15}px ${ry * 1.15}px at ${cx}px ${cy}px, transparent 70%, black 100%)`;\ndim.style.webkitMaskImage = dim.style.maskImage = hole;\nconst T = { draw: [1.0, 1.75] };\nconst tx = cx - cw / 2, ty = cy - ch / 2;\n// how close the lean goes: the original depth, unless the ring would no longer fit the frame\nconst fit = Math.min(W * 0.84 / (rx * 2.3), H * 0.8 / (ry * 2.3)), zEnd = Math.min(DIST - SHORT * 0.4, Math.max(DIST - SHORT * 0.95, SHORT * 1.7 / fit - SHORT * 1.7));\n\ns.update((t) => {\n  // arrive: from farther and turned, settling face-on; then a slow lean toward the mark as it is drawn\n  const arrive = progress(t, 0, 0.9, ease.outCubic), lean = progress(t, T.draw[0] - 0.1, T.draw[1] + 0.6, ease.inOutCubic);\n  cam.at({ x: tx * lean, y: ty * lean, z: DIST + SHORT * 0.35 * (1 - arrive) + (zEnd - DIST) * lean, yaw: -10 * (1 - arrive) + 2 * Math.sin(t * 0.6) * arrive, pitch: 4 * (1 - arrive) });\n  comp.style.opacity = String(progress(t, 0, 0.35));\n  // the stroke: fast in the middle, slowing as it closes past its start\n  const d = progress(t, ...T.draw, ease.inOutQuad);\n  ring.style.strokeDashoffset = `${L * (1 - d)}`;\n  ring.style.opacity = d > 0 ? '1' : '0';\n  dim.style.opacity = String(progress(t, T.draw[0] + 0.1, T.draw[1] + 0.2, ease.outCubic));\n  // the marked card lifts a step when the ring closes\n  const lift = t > T.draw[1] - 0.1 ? spring(t - (T.draw[1] - 0.1), { stiffness: 220, damping: 13 }) : 0;\n  target.style.transform = `translateY(${-lift * ch * 0.012}px) scale(${1 + lift * 0.035})`;\n  target.style.boxShadow = lift ? `0 ${ch * 0.02 * lift}px ${ch * 0.05}px rgba(0,0,0,${0.5 * lift})` : 'none';\n  target.style.borderColor = lift > 0.05 ? `${accent}66` : `${muted}33`;\n});\nB.cue(s, 'transition', 0); B.cue(s, 'text', T.draw[0]); B.cue(s, 'land', T.draw[1]);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/circle-mark/brief.md",
      "content": "# Circle mark\n\nBlock: circle-mark (4.5 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nA hand-drawn ring closes around the number that matters on a screen; the rest dims, the marked card lifts and the camera leans in close.\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.7 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add circle-mark --name my-circle-mark\n# edit CONFIG in pieces/my-circle-mark/scene.html, then:\nnpx paper-motion render pieces/my-circle-mark/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": [
    "callout-zoom",
    "pointer-label"
  ],
  "preview": {
    "video": "previews/circle-mark.webm",
    "poster": "previews/circle-mark.jpg",
    "at": 3.4,
    "values": {}
  },
  "mood": [
    "minimal",
    "technical"
  ],
  "duration": 4.5,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Arrive",
      "from": 0,
      "to": 0.9,
      "what": "arrive"
    },
    {
      "name": "Draw",
      "from": 1,
      "to": 1.7,
      "what": "draw"
    },
    {
      "name": "Hold",
      "from": 1.7,
      "to": 4.5,
      "what": "hold"
    }
  ],
  "when": [
    "point at one figure on a dashboard",
    "the proof moment of a product demo"
  ],
  "needs": [
    {
      "kind": "table",
      "fill": {
        "stats": "$rows",
        "mark": "$main"
      }
    }
  ]
}