{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "form-fill",
  "type": "block",
  "title": "Form fill",
  "summary": "A cursor fills a form field by field, each check pops on, the button works and then opens into a new, black screen.",
  "tags": [
    "block",
    "ui",
    "form",
    "cursor",
    "typing",
    "onboarding"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "name": "title",
      "type": "string",
      "default": "New brand",
      "description": "title",
      "group": "main",
      "control": "text"
    },
    {
      "name": "button",
      "type": "string",
      "default": "Create brand",
      "description": "button",
      "group": "main",
      "control": "text"
    },
    {
      "name": "done",
      "type": "string",
      "default": "Created",
      "description": "done",
      "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/form-fill/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>form-fill</title>\n<!--\n  Component · form fill (6.5 s). A cursor fills a form: it clicks a field (the focus ring lights), the value types\n  itself, a check pops on; the next field; then the button presses, works and turns into done. The camera stays close\n  on whatever the cursor is doing and pulls back a step for the button.\n  Arrive 0–0.7 s · Field 1 1.25–2.25 s · Field 2 2.85–3.95 s · Submit 4.55 s · Done 5.35 s · Opens 5.8–6.6 s, from the button to a full black screen · Hold to 7.6 s.\n  Vertical and square: the card is narrowed to the frame width, the camera rides each field centred and turns less.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #card { position: absolute; box-sizing: border-box; display: flex; flex-direction: column; gap: 1.5em; padding: 2.6em; }\n  .f { display: flex; flex-direction: column; gap: 0.6em; }\n  .box { position: relative; height: 3.2em; border-radius: 0.7em; display: flex; align-items: center; padding: 0 1.1em; }\n  .ck { position: absolute; right: 1em; top: 50%; width: 1.5em; height: 1.5em; margin-top: -0.75em; border-radius: 50%; display: flex; align-items: center; justify-content: center; }\n  .caret { display: inline-block; width: 0.1em; height: 1.2em; margin-left: 0.05em; vertical-align: -0.2em; }\n  #btn { position: relative; height: 3.4em; border-radius: 0.7em; display: flex; align-items: center; justify-content: center; gap: 0.6em; margin-top: 0.6em; overflow: hidden; }\n  #cursor { position: absolute; left: 0; top: 0; width: 0; height: 0; z-index: 5; }\n  #cursor svg { position: absolute; left: 0; top: 0; }\n  .spin { width: 1.1em; height: 1.1em; border-radius: 50%; }\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=\"card\"></div></div>\n  <div id=\"wipe\" class=\"abs\"></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  title: 'New brand',\n  fields: [['Name', 'paper-motion'], ['Website', 'paper-motion.app']],\n  button: 'Create brand',\n  done: 'Created',\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 7.6;\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.35;\n\nconst DIST = SHORT * 0.62, K = 1 + DIST / (SHORT * 1.7);\nconst cam = camera($('stage'), $('world'), { perspective: SHORT * 1.7 });\nconst ground = B.color('ground'), muted = B.color('muted'), figure = B.color('figure'), accent = B.color('accent', '#E9E4D8');\nconst GREEN = '#8fbf8f';\nconst card = $('card'), cw = Math.min(SHORT * 0.95, W * 0.82) * K, narrow = W <= H, R = (B.tokens?.shape?.radius ?? 12) * (SHORT / 1080) * K;\nObject.assign(card.style, { width: `${cw}px`, borderRadius: `${R * 1.4}px`, background: B.surface(0.18), border: `1.5px solid ${muted}55`, boxShadow: `0 ${SHORT * 0.04}px ${SHORT * 0.12}px rgba(0,0,0,0.5)`, fontSize: `${cw * 0.03}px`, fontFamily: B.font('text'), color: figure });\ncard.innerHTML = `<div style=\"font:400 2em ${B.font('display')}\">${CONFIG.title}</div>` +\n  CONFIG.fields.map(([l]) => `<div class=\"f\"><div style=\"color:${muted};font-size:0.85em\">${l}</div><div class=\"box\" style=\"background:${ground};border:1.5px solid ${muted}44\"><span class=\"v\"></span><span class=\"caret\" style=\"background:${accent}\"></span><div class=\"ck\" style=\"background:${GREEN};color:${ground}\">✓</div></div></div>`).join('') +\n  `<div id=\"btn\" style=\"background:${accent};color:${ground};font-weight:500\"><span class=\"spin\" style=\"border:0.16em solid ${ground}44;border-top-color:${ground}\"></span><span class=\"lab\">${CONFIG.button}</span></div>`;\nconst cursor = document.createElement('div'); cursor.id = 'cursor'; const cs = cw * 0.045;\ncursor.innerHTML = `<svg width=\"${cs}\" height=\"${cs * 1.4}\" viewBox=\"0 0 20 28\"><path d=\"M2 2 L18 14 L10 15.5 L14.5 25 L11 26.5 L6.5 17 L2 22 Z\" fill=\"${figure}\" stroke=\"${ground}\" stroke-width=\"1.5\" stroke-linejoin=\"round\"/></svg>`;\ncard.append(cursor);\ncam.place(card, { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\n\nconst boxes = [...card.querySelectorAll('.box')], btn = $('btn');\nconst ch = card.offsetHeight;\nconst center = (el) => [el.offsetLeft + el.offsetWidth / 2, el.offsetTop + el.offsetHeight / 2];\nconst at = (el, fx = 0.72) => [el.offsetLeft + el.offsetWidth * fx, el.offsetTop + el.offsetHeight * 0.55];\n// the cursor's path: from below, to each field, to the button\nconst P = [[cw * 0.9, ch * 1.05], at(boxes[0]), at(boxes[1]), at(btn, 0.5)];\nconst T = { moves: [[0.6, 1.2], [2.3, 2.8], [4.0, 4.5]], clicks: [1.25, 2.85, 4.55], types: [[1.35, 2.2], [2.95, 3.9]], checks: [2.25, 3.95], done: 5.35 };\nconst camAt = (el, z) => { const [x, y] = center(el); return { x: x - cw / 2, y: y - ch / 2, z }; };\nconst near = DIST - SHORT * (narrow ? 0.64 : 0.88), mid = DIST - SHORT * 0.62;\n// on a field the camera rides along it as the value types; between fields it swings, leaning the other way each time\n// in narrow frames the field fills the width, so it is ridden centred and the turns are gentler (yaw slides the framing)\nconst along = (el, fx, z, { yaw, ...extra }) => ({ x: el.offsetLeft + el.offsetWidth * (narrow ? 0.46 + fx * 0.1 : fx) - cw / 2, y: el.offsetTop + el.offsetHeight / 2 - ch / 2, z, yaw: narrow ? yaw * 0.35 : yaw, ...extra });\nconst path = [\n  [0, { x: 0, y: 0, z: DIST + SHORT * 0.35, yaw: -14, pitch: 6, roll: -2 }],\n  [0.9, { x: 0, y: 0, z: DIST - SHORT * 0.1, yaw: -6, pitch: 2, roll: 0 }, ease.outCubic],\n  [1.4, along(boxes[0], 0.3, near, { yaw: -8, pitch: 1, roll: -1 }), ease.inOutCubic],\n  [2.3, along(boxes[0], 0.55, near, { yaw: -4, pitch: 0, roll: 0 }), ease.inOutSine],\n  [3.0, along(boxes[1], 0.3, near, { yaw: 8, pitch: -1, roll: 1.2 }), ease.inOutCubic],\n  [3.95, along(boxes[1], 0.6, near, { yaw: 4, pitch: 0, roll: 0 }), ease.inOutSine],\n  [4.6, { ...camAt(btn, mid), yaw: -3, pitch: -2, roll: 0 }, ease.inOutCubic],\n  [5.6, { ...camAt(btn, mid - SHORT * 0.08), yaw: -1, pitch: -1 }, ease.inOutSine],\n  [6.6, { ...camAt(btn, DIST - SHORT * 1.05), yaw: 0, pitch: 0 }, ease.inCubic],     // into the button as it opens\n  [D, { ...camAt(btn, DIST - SHORT * 1.1), yaw: 0, pitch: 0 }],\n];\nT.open = [5.9, 6.7];\nconst wipe = $('wipe'); wipe.style.zIndex = 10; wipe.style.pointerEvents = 'none';\n\ns.update((t) => {\n  cam.travel(t, path);\n  card.style.opacity = String(progress(t, 0, 0.35));\n  // the cursor: a curved hop between targets, a small press at each click\n  let seg = 0; while (seg < 2 && t >= T.moves[seg][1]) seg++;\n  const [m0, m1] = T.moves[seg], p = progress(t, m0, m1, ease.inOutCubic), a = P[seg], b = P[seg + 1];\n  const bend = Math.sin(p * Math.PI) * ch * 0.06;\n  const press = T.clicks.some((c) => t >= c && t < c + 0.18) ? 0.86 : 1;\n  cursor.style.transform = `translate(${a[0] + (b[0] - a[0]) * p}px, ${a[1] + (b[1] - a[1]) * p - bend}px) scale(${press})`;\n  cursor.style.opacity = String(progress(t, 0.4, 0.7));\n  // the fields: focus ring, typing, check\n  boxes.forEach((bx, i) => {\n    const focus = t >= T.clicks[i] && (i === 1 ? true : t < T.clicks[i + 1]);\n    const ring = t >= T.clicks[i] ? spring(t - T.clicks[i], { stiffness: 260, damping: 18 }) : 0;\n    bx.style.borderColor = focus ? accent : t >= T.checks[i] ? `${GREEN}88` : `${muted}44`;\n    bx.style.boxShadow = focus ? `0 0 0 ${0.25 * ring}em ${accent}33` : 'none';\n    const v = CONFIG.fields[i][1], n = Math.round(v.length * progress(t, ...T.types[i]));\n    bx.querySelector('.v').textContent = v.slice(0, n);\n    const caret = bx.querySelector('.caret');\n    caret.style.opacity = focus && (t < T.types[i][1] || Math.sin(t * 10) > 0) && !(i === 1 && t > T.clicks[2]) ? '1' : '0';\n    const c = t >= T.checks[i] ? spring(t - T.checks[i], { stiffness: 380, damping: 13 }) : 0;\n    bx.querySelector('.ck').style.transform = `scale(${c})`;\n    if (i === 1 && t > T.clicks[2]) { bx.style.borderColor = `${GREEN}88`; bx.style.boxShadow = 'none'; }\n  });\n  // the button: press, work, done\n  const hit = t >= T.clicks[2] ? spring(t - T.clicks[2], { stiffness: 320, damping: 12 }) : 1;\n  btn.style.transform = `scale(${t >= T.clicks[2] ? 1 - 0.05 * (1 - hit) : 1})`;\n  const working = t >= T.clicks[2] + 0.05 && t < T.done, done = progress(t, T.done, T.done + 0.35, ease.outCubic);\n  const spin = btn.querySelector('.spin'), lab = btn.querySelector('.lab');\n  spin.style.display = working ? '' : 'none'; spin.style.transform = `rotate(${t * 720}deg)`;\n  lab.textContent = t >= T.done ? `✓ ${CONFIG.done}` : working ? 'Creating…' : CONFIG.button;\n  btn.style.background = done ? GREEN : accent;\n  lab.style.transform = `translateY(${(1 - done) * (t >= T.done ? 0.6 : 0)}em)`;\n  // the new screen: grows out of the button to the whole frame, its colour going from the button's to black\n  const o = progress(t, ...T.open, ease.inOutCubic);\n  if (t >= T.open[0]) {\n    const sr = $('stage').getBoundingClientRect(), br = btn.getBoundingClientRect(), k = sr.width / W;\n    const L = (br.left - sr.left) / k, Tp = (br.top - sr.top) / k, Wd = br.width / k, Ht = br.height / k;\n    const r = parseFloat(getComputedStyle(btn).borderRadius) * (br.width / btn.offsetWidth) / k;\n    Object.assign(wipe.style, { left: `${L * (1 - o)}px`, top: `${Tp * (1 - o)}px`, width: `${Wd + (W - Wd) * o}px`, height: `${Ht + (H - Ht) * o}px`, borderRadius: `${r * (1 - o)}px`, opacity: String(progress(t, T.open[0], T.open[0] + 0.12)) });\n    const c = progress(t, T.open[0] + 0.05, T.open[0] + 0.5);\n    wipe.style.background = c >= 1 ? ground : `color-mix(in srgb, ${GREEN} ${Math.round((1 - c) * 100)}%, ${ground})`;\n    wipe.style.boxShadow = `0 0 ${SHORT * 0.08 * (1 - o)}px rgba(0,0,0,0.6)`;\n  } else wipe.style.opacity = '0';\n});\nT.clicks.forEach((c) => B.cue(s, 'text', c)); B.cue(s, 'land', T.done);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/form-fill/brief.md",
      "content": "# Form fill\n\nBlock: form-fill (7.6 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nA cursor fills a form field by field, each check pops on, the button works and then opens into a new, black screen.\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.7 and 2.25 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add form-fill --name my-form-fill\n# edit CONFIG in pieces/my-form-fill/scene.html, then:\nnpx paper-motion render pieces/my-form-fill/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": [
    "search-type",
    "toggle-flip"
  ],
  "preview": {
    "video": "previews/form-fill.webm",
    "poster": "previews/form-fill.jpg",
    "at": 5.6,
    "values": {}
  },
  "mood": [
    "minimal",
    "warm"
  ],
  "duration": 7.6,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Arrive",
      "from": 0,
      "to": 0.7,
      "what": "arrive"
    },
    {
      "name": "Field 1",
      "from": 1.25,
      "to": 2.25,
      "what": "field 1"
    },
    {
      "name": "Field 2",
      "from": 2.85,
      "to": 3.95,
      "what": "field 2"
    },
    {
      "name": "Submit",
      "from": 4.55,
      "to": 5.1499999999999995,
      "what": "submit"
    },
    {
      "name": "Done",
      "from": 5.35,
      "to": 5.949999999999999,
      "what": "done"
    },
    {
      "name": "Opens",
      "from": 5.8,
      "to": 6.6,
      "what": "opens"
    },
    {
      "name": "Hold",
      "from": 6.6,
      "to": 7.6,
      "what": "hold"
    }
  ],
  "when": [
    "sign-up or setup flows",
    "show how little it takes to start"
  ],
  "needs": [
    {
      "kind": "form",
      "fill": {
        "title": "$title",
        "fields": "$fields",
        "button": "$button",
        "done": "$done"
      }
    }
  ]
}