{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "marker-highlight",
  "type": "block",
  "title": "Marker highlight",
  "summary": "A sentence lands word by word, then a tilted marker sweeps behind the key words, which turn dark exactly where it passes.",
  "tags": [
    "block",
    "text",
    "highlight",
    "marker",
    "emphasis"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "name": "before",
      "type": "string",
      "default": "Your agent directs",
      "description": "before",
      "group": "main",
      "control": "text"
    },
    {
      "name": "mark",
      "type": "string",
      "default": "every frame.",
      "description": "the words the marker sweeps",
      "group": "main",
      "control": "text"
    },
    {
      "name": "after",
      "type": "string",
      "default": "",
      "description": "after",
      "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/marker-highlight/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>marker-highlight</title>\n<!--\n  Text · marker highlight (4.8 s). A sentence lands word by word; then a marker sweeps behind the words that matter,\n  a little tilted and uneven like a real one, and those words turn dark as it passes under them. The camera drifts in\n  and settles on the marked words.\n  Vertical/square: the sentence wraps onto three lines and the final push goes in until the widest line fills the width with a margin.\n  Words 0.2–1.2 s · Sweep 1.6–2.3 s · Hold to 4.8 s.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #p { display: flex; justify-content: center; text-align: center; }\n  #line { line-height: 1.12; }\n  .w { display: inline-block; white-space: pre; }\n  .hit { position: relative; display: inline-block; white-space: nowrap; }\n  .mk { position: absolute; z-index: 0; }\n  .ink { position: relative; z-index: 1; }\n  .dark { position: absolute; left: 0; top: 0; z-index: 2; white-space: nowrap; }\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=\"line\"></div></div></div>\n</main>\n<script type=\"module\">\nimport { scene, progress, ease } 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  before: 'Your agent directs',\n  mark: 'every frame.',                  // the words the marker sweeps\n  after: '',\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 4.8;\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 $ = (id) => document.getElementById(id);\n$('bg').style.opacity = 0.4;\n$('vig').style.background = 'radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0) 30%, rgba(0,0,0,0.6) 100%)';\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'), ground = B.color('ground');\nconst line = B.style($('line'), 'display', { short: SHORT * K, color: 'figure' });\nconst wide = W > H;\nline.style.fontSize = `${SHORT * K * (H > W ? 0.1 : 0.13)}px`; line.style.maxWidth = `${W * (H > W ? 0.9 : 0.86)}px`;\nconst words = (txt) => txt.split(/(\\s+)/).filter(Boolean).map((w) => `<span class=\"w\">${w}</span>`).join('');\nline.innerHTML = `${words(CONFIG.before)} <span class=\"hit\"><span class=\"mk\"></span><span class=\"ink\">${words(CONFIG.mark)}</span><span class=\"dark\">${CONFIG.mark}</span></span>${CONFIG.after ? ' ' + words(CONFIG.after) : ''}`;\n$('p').style.width = `${W}px`;\nconst mk = line.querySelector('.mk'), dark = line.querySelector('.dark'), hit = line.querySelector('.hit');\n// the marker: an uneven band, slightly tilted, ends rough\nmk.style.background = accent;\ndark.style.color = ground;\ncam.place($('p'), { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\nconst ws = [...line.querySelectorAll('.ink .w, #line > .w')].filter((w) => w.textContent.trim());\nconst allW = [...line.querySelectorAll('.w')].filter((w) => w.textContent.trim());\n// where the marked words sit, to settle the camera on them\nconst pr = $('p').getBoundingClientRect(), hr = hit.getBoundingClientRect(), sc = W / pr.width;\nconst hx = (hr.left - pr.left + hr.width / 2) * sc - W / 2, hy = (hr.top - pr.top + hr.height / 2) * sc - $('p').offsetHeight / 2;\n// one shape for the marker and for the dark words: an uneven band, tilted, growing from its left end\nconst em = parseFloat(getComputedStyle(line).fontSize), hw = hit.offsetWidth, hh = hit.offsetHeight, PAD = em * 0.4;\nconst SHAPE = [[0.01, 0.14], [0.3, 0.06], [0.62, 0.1], [0.99, 0.03], [1, 0.88], [0.7, 0.95], [0.35, 0.9], [0, 0.97]];\nconst bx = -0.08 * em, by = 0.1 * em, bw = hw + 0.16 * em, bh = hh + 0.02 * em, th = -1.4 * Math.PI / 180;\nconst shape = (m) => SHAPE.map(([u, v]) => {\n  const dx = u * bw * m, dy = (v - 0.5) * bh;\n  return [bx + dx * Math.cos(th) - dy * Math.sin(th), by + bh / 2 + dx * Math.sin(th) + dy * Math.cos(th)];\n});\nObject.assign(mk.style, { left: `${-PAD}px`, top: `${-PAD}px`, width: `${hw + PAD * 2}px`, height: `${hh + PAD * 2}px` });\nObject.assign(dark.style, { width: `${hw}px`, height: `${hh}px` });\n\n// narrow frames: push in only as far as the widest line still fits with a margin\nconst P = SHORT * 1.7, lk = line.offsetWidth / line.getBoundingClientRect().width, rows = new Map();\nfor (const w of allW) { const b = w.getBoundingClientRect(), k = Math.round(b.top * lk / (em * 0.5)); const r = rows.get(k) ?? [Infinity, -Infinity]; rows.set(k, [Math.min(r[0], b.left), Math.max(r[1], b.right)]); }\nconst lw = Math.max(hw + 0.4 * em, ...[...rows.values()].map(([a, b]) => (b - a) * lk));\nconst pre = H > W ? SHORT * 0.22 : 0;   // vertical starts closer: the sentence is narrow\nconst zEnd = wide ? DIST - SHORT * 0.62 : P * lw / (W * 0.88) - P;\nconst T = { words: 0.2, each: 0.11, sweep: [1.6, 2.3] };\ns.update((t) => {\n  allW.forEach((w, i) => {\n    const a = T.words + i * T.each, p = progress(t, a, a + 0.6, ease.outCubic);\n    w.style.transform = `translateY(${(1 - p) * 0.5}em)`; w.style.opacity = String(p); w.style.filter = p < 1 ? `blur(${(1 - p) * 8}px)` : 'none';\n  });\n  const m = progress(t, ...T.sweep, ease.inOutCubic);\n  const pts = shape(Math.max(0.001, m));\n  mk.style.clipPath = `polygon(${pts.map(([x, y]) => `${(x + PAD).toFixed(2)}px ${(y + PAD).toFixed(2)}px`).join(', ')})`;\n  dark.style.clipPath = `polygon(${pts.map(([x, y]) => `${x.toFixed(2)}px ${y.toFixed(2)}px`).join(', ')})`;   // dark exactly where the marker is\n  dark.style.opacity = m > 0 ? '1' : '0'; mk.style.opacity = m > 0 ? '1' : '0';\n  // the camera: a slow drift in, then onto the marked words as the marker lands\n  const arrive = progress(t, 0, 1.2, ease.outCubic), land = progress(t, T.sweep[0], D, ease.inOutCubic);\n  cam.at({ x: hx * 0.85 * land, y: wide ? 0 : hy * 0.4 * land, z: DIST - pre + SHORT * 0.3 * (1 - arrive) - (DIST - pre - zEnd) * land, yaw: -6 * (1 - arrive) + 2 * land, pitch: 0, roll: -0.6 * land });\n  $('bg').style.transform = `scale(${1.08 + 0.08 * progress(t, 0, D)})`;\n});\nB.cue(s, 'text', T.words); B.cue(s, 'land', T.sweep[0] + 0.3);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/marker-highlight/brief.md",
      "content": "# Marker highlight\n\nBlock: marker-highlight (4.8 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nA sentence lands word by word, then a tilted marker sweeps behind the key words, which turn dark exactly where it passes.\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.2 and 2.3 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add marker-highlight --name my-marker-highlight\n# edit CONFIG in pieces/my-marker-highlight/scene.html, then:\nnpx paper-motion render pieces/my-marker-highlight/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": [
    "word-swap",
    "circle-mark"
  ],
  "preview": {
    "video": "previews/marker-highlight.webm",
    "poster": "previews/marker-highlight.jpg",
    "at": 4.5,
    "values": {}
  },
  "mood": [
    "warm",
    "bold"
  ],
  "duration": 4.8,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Words",
      "from": 0.2,
      "to": 1.2,
      "what": "words"
    },
    {
      "name": "Sweep",
      "from": 1.6,
      "to": 2.3,
      "what": "sweep"
    },
    {
      "name": "Hold",
      "from": 2.3,
      "to": 4.8,
      "what": "hold"
    }
  ],
  "when": [
    "the one phrase that matters",
    "a promise or tagline"
  ],
  "needs": [
    {
      "kind": "line",
      "has": [
        "mark"
      ],
      "fill": {
        "before": "$before",
        "mark": "$mark",
        "after": "$after"
      }
    }
  ]
}