{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "pointer-label",
  "type": "block",
  "title": "Pointer label",
  "summary": "A short line lands on the screen, a curved arrow draws from it to a control, and the control answers with a pulse.",
  "tags": [
    "block",
    "annotation",
    "arrow",
    "label",
    "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": "label",
      "type": "string",
      "default": "One click renders it all.",
      "description": "the line the arrow starts from",
      "group": "main",
      "control": "text"
    },
    {
      "name": "button",
      "type": "string",
      "default": "Render",
      "description": "the control the arrow points at",
      "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/pointer-label/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>pointer-label</title>\n<!--\n  Annotation · pointer label (5 s). A short line lands on the screen, then a curved arrow draws from it to the control\n  it talks about; the head snaps on, the control answers with a pulse, and the camera leans in on the pair.\n  Arrive 0–0.9 s · Label 1.0–1.6 s · Arrow 1.4–2.2 s · Answer 2.3 s · Hold to 5 s.\n  Vertical: a tall screen without sidebar, the label set on two lines under the button; 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; display: grid; grid-template-columns: 16% 1fr; }\n  .side { display: flex; flex-direction: column; gap: 1.1em; padding: 2.2em 1.6em; }\n  .main { position: relative; display: flex; flex-direction: column; gap: 1.4em; padding: 2em 2.2em; }\n  .bar { display: flex; align-items: center; gap: 1em; }\n  .btn { padding: 0.75em 1.5em; border-radius: 0.6em; font-size: 1.25em; white-space: nowrap; }\n  #preview { flex: 1; border-radius: 0.8em; position: relative; overflow: hidden; }\n  i { display: block; height: 0.6em; border-radius: 999px; }\n  #ink { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }\n  #label { position: absolute; white-space: nowrap; }\n  #halo { position: absolute; border-radius: 0.8em; 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><div id=\"halo\"></div><svg id=\"ink\"><path id=\"arc\"/><path id=\"head\"/></svg><div id=\"label\"></div></div></div>\n</main>\n<script type=\"module\">\nimport { scene, progress, ease, spring } from 'paper-motion';\nimport { wordRise } 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  label: 'One click renders it all.',    // the line the arrow starts from\n  button: 'Render',                      // the control the arrow points at\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.88 : square ? W * 0.84 : W * 0.7) * K, ch = cw * (tall ? 1.45 : square ? 0.8 : 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` });\nconst screen = $('screen');\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)`, fontSize: `${cw * (tall ? 0.024 : square ? 0.0145 : 0.0105)}px`, fontFamily: B.font('text') });\nconst line = (w, c = muted, o = 0.45) => `<i style=\"width:${w}%;background:${c};opacity:${o}\"></i>`;\nif (tall) screen.style.gridTemplateColumns = '1fr';\nscreen.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\"><div class=\"bar\">${line(18, figure, 0.9)}<div style=\"flex:1\"></div><div class=\"btn\" style=\"border:1px solid ${muted}55;color:${muted}\">Preview</div><div class=\"btn\" id=\"target\" style=\"background:${accent};color:${ground};font-weight:500\">${CONFIG.button}</div></div>\n<div id=\"preview\" style=\"background:${ground};border:1px solid ${muted}33\"><div id=\"pv\" style=\"position:absolute;inset:0;opacity:0.5\"></div></div></div>`;\nif (bgId) B.shader(s, $('pv'), bgId);\nconst label = B.style($('label'), 'display', { short: SHORT * K, color: 'figure' });\nlabel.textContent = CONFIG.label; label.style.fontSize = `${ch * 0.06}px`; label.style.textShadow = '0 2px 30px rgba(0,0,0,0.8)';\nif (tall) Object.assign(label.style, { fontSize: `${cw * 0.085}px`, whiteSpace: 'normal', width: `${cw * 0.6}px`, textAlign: 'right', lineHeight: '1.15' });\ncam.place(comp, { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\n\n// geometry in the screen's own pixels: the button, and a label placed below-left of it over the preview\nconst target = $('target'), pr = screen.getBoundingClientRect(), sc = cw / pr.width, br = target.getBoundingClientRect();\nconst bx = (br.left - pr.left) * sc, by = (br.top - pr.top) * sc, bw = br.width * sc, bh = br.height * sc;\nconst lw = label.offsetWidth, lh = label.offsetHeight;\nconst lx = cw * (tall ? 0.14 : square ? 0.3 : 0.38), ly = ch * (tall ? 0.3 : 0.5);\nObject.assign(label.style, { left: `${lx}px`, top: `${ly}px` });\n// the arc: from the end of the label, rising in a loose curve into the button's lower edge\nconst U = tall ? cw * 0.62 : ch;                                     // the arc's own unit: the height in wide frames, the width in tall\nconst p0 = [lx + lw + U * 0.02, ly + lh * 0.45], p3 = [bx + bw * 0.35, by + bh + U * 0.025];\nconst p1 = [p0[0] + U * 0.22, p0[1] + U * 0.02], p2 = [p3[0] - U * 0.02, p3[1] + U * 0.2];\nconst arc = $('arc'), head = $('head');\narc.setAttribute('d', `M${p0} C${p1} ${p2} ${p3}`);\nconst sw = SHORT * 0.005 * K;\nfor (const el of [arc, head]) Object.assign(el.style, { fill: 'none', stroke: accent, strokeWidth: `${sw}`, strokeLinecap: 'round', strokeLinejoin: 'round' });\nconst L = arc.getTotalLength(); arc.style.strokeDasharray = `${L}`;\n// the head: two short strokes along the arc's last tangent\nconst ang = Math.atan2(p3[1] - p2[1], p3[0] - p2[0]), hl = U * 0.035;\nconst wing = (d) => [p3[0] - Math.cos(ang + d) * hl, p3[1] - Math.sin(ang + d) * hl];\nhead.setAttribute('d', `M${wing(0.55)} L${p3} L${wing(-0.55)}`);\nconst HL = head.getTotalLength(); head.style.strokeDasharray = `${HL}`;\nconst halo = $('halo');\nObject.assign(halo.style, { left: `${bx}px`, top: `${by}px`, width: `${bw}px`, height: `${bh}px`, border: `${sw * 0.7}px solid ${accent}` });\nconst T = { label: 1.0, arc: [1.4, 2.2], hit: 2.3 };\nconst mx = (Math.min(lx, bx) + Math.max(lx + lw, bx + bw)) / 2 - cw / 2, my = (by + ly + lh) / 2 - ch / 2;\n\ns.update((t) => {\n  const arrive = progress(t, 0, 0.9, ease.outCubic), lean = progress(t, 0.9, 2.8, ease.inOutCubic);\n  cam.at({ x: mx * lean, y: my * lean, z: DIST + SHORT * 0.3 * (1 - arrive) - SHORT * (tall ? 0.38 : 0.55) * lean, yaw: -8 * (1 - arrive) + 3 * lean, pitch: 3 * (1 - arrive) - 1 * lean });\n  comp.style.opacity = String(progress(t, 0, 0.35));\n  wordRise(label, t, { start: T.label, each: B.pace.stagger, duration: 0.7 });\n  const a = progress(t, ...T.arc, ease.inOutCubic);\n  arc.style.strokeDashoffset = `${L * (1 - a)}`; arc.style.opacity = a > 0 ? '1' : '0';\n  const h = progress(t, T.arc[1] - 0.05, T.arc[1] + 0.15, ease.outCubic);\n  head.style.strokeDashoffset = `${HL * (1 - h)}`; head.style.opacity = h > 0 ? '1' : '0';\n  // the answer: the button presses and a halo rings out from it\n  const hit = t >= T.hit ? spring(t - T.hit, { stiffness: 300, damping: 12 }) : 0;\n  target.style.transform = `scale(${1 + (t >= T.hit ? 0.08 * (1 - hit) : 0)})`;\n  const ring = progress(t, T.hit, T.hit + 0.8, ease.outCubic);\n  halo.style.opacity = String(t >= T.hit ? 0.9 * (1 - ring) : 0);\n  halo.style.transform = `scale(${1 + ring * 0.5}, ${1 + ring * 1.1})`;\n});\nB.cue(s, 'transition', 0); B.cue(s, 'text', T.label); B.cue(s, 'land', T.hit);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/pointer-label/brief.md",
      "content": "# Pointer label\n\nBlock: pointer-label (5 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nA short line lands on the screen, a curved arrow draws from it to a control, and the control answers with a pulse.\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 pointer-label --name my-pointer-label\n# edit CONFIG in pieces/my-pointer-label/scene.html, then:\nnpx paper-motion render pieces/my-pointer-label/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",
    "cursor-guide"
  ],
  "preview": {
    "video": "previews/pointer-label.webm",
    "poster": "previews/pointer-label.jpg",
    "at": 3.2,
    "values": {}
  },
  "mood": [
    "warm",
    "minimal"
  ],
  "duration": 5,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Arrive",
      "from": 0,
      "to": 0.9,
      "what": "arrive"
    },
    {
      "name": "Label",
      "from": 1,
      "to": 1.6,
      "what": "label"
    },
    {
      "name": "Arrow",
      "from": 1.4,
      "to": 2.2,
      "what": "arrow"
    },
    {
      "name": "Answer",
      "from": 2.3,
      "to": 2.9,
      "what": "answer"
    },
    {
      "name": "Hold",
      "from": 2.9,
      "to": 5,
      "what": "hold"
    }
  ],
  "when": [
    "say what a button does",
    "one-click moments"
  ],
  "needs": [
    {
      "kind": "action",
      "fill": {
        "label": "$text",
        "button": "$button"
      }
    }
  ]
}