{
  "$schema": "../../schema.json",
  "version": "1.0.0",
  "license": "MIT",
  "id": "drag-drop",
  "type": "block",
  "title": "Drag and drop",
  "summary": "A cursor lifts a card on a board, carries it tilted to another column, a slot opens, it drops on a spring and the counts update.",
  "tags": [
    "block",
    "ui",
    "kanban",
    "drag",
    "cursor"
  ],
  "params": [
    {
      "name": "background",
      "type": "string",
      "default": "",
      "description": "a background id from the registry; empty uses the brand's first",
      "group": "advanced",
      "control": "select"
    },
    {
      "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/drag-drop/scene.html",
      "content": "<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<title>drag-drop</title>\n<!--\n  Component · drag and drop (5.6 s). A cursor picks up a card on a board: the card lifts (bigger, tilted, a deep\n  shadow), travels across to another column leaning into the move, a slot opens for it as the cards there step down,\n  and it drops in on a spring while the column it left closes up. The camera rides along with the card, close.\n  Pick 1.0 s · Carry 1.2–2.9 s · Drop 3.0 s · Hold to 5.6 s.\n  Vertical and square: the board narrows to the frame and gets taller (larger type, same three columns); the camera pushes in closer.\n-->\n<style>\n  #stage { overflow: hidden; }\n  .abs { position: absolute; box-sizing: border-box; }\n  #board { position: absolute; box-sizing: border-box; }\n  .col { position: absolute; border-radius: 1em; }\n  .head { position: absolute; display: flex; align-items: center; gap: 0.6em; }\n  .card { position: absolute; left: 0; top: 0; border-radius: 0.8em; padding: 1em 1.1em; box-sizing: border-box; display: flex; flex-direction: column; gap: 0.6em; }\n  i { display: block; height: 0.55em; border-radius: 999px; }\n  #cursor { position: absolute; left: 0; top: 0; width: 0; height: 0; z-index: 50; }\n  #cursor svg { position: absolute; left: 0; top: 0; }\n  #slot { position: absolute; left: 0; top: 0; border-radius: 0.8em; }\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=\"board\"><div id=\"slot\"></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  columns: [['Draft', ['Launch film', 'Release teaser', 'Explainer']], ['Rendering', ['Social loop']], ['Done', ['README loop', 'End card']]],\n  move: [0, 1, 2, 1],                    // [from column, card, to column, at position]\n  format: [1920, 1080],\n};\n\nconst B = await loadBrand();\nconst [W, H] = CONFIG.format, SHORT = Math.min(W, H), D = 5.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.3;\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 tall = H > W, square = W === H;\nconst board = $('board'), bw = (tall ? W * 0.9 : square ? W * 0.84 : W * 0.74) * K, R = (B.tokens?.shape?.radius ?? 12) * (SHORT / 1080) * K;\nconst fs = bw * (tall ? 0.023 : square ? 0.015 : 0.0125), bh = tall || square ? fs * 41.7 : bw * 0.52;\nObject.assign(board.style, { width: `${bw}px`, height: `${bh}px`, borderRadius: `${R}px`, background: B.surface(0.16), border: `1.5px solid ${muted}44`, boxShadow: `0 ${SHORT * 0.04}px ${SHORT * 0.12}px rgba(0,0,0,0.5)`, fontSize: `${fs}px`, fontFamily: B.font('text'), color: figure });\n// layout by hand, so every card's position is a function of time\nconst pad = fs * 2.2, gapX = fs * 1.6, colW = (bw - pad * 2 - gapX * 2) / 3, top = pad + fs * 3.4, cardH = fs * 6.2, gapY = fs * 1.1;\nconst colX = (c) => pad + c * (colW + gapX);\nconst slotY = (i) => top + fs * 1.0 + i * (cardH + gapY);\nCONFIG.columns.forEach(([name, cards], c) => {\n  const col = document.createElement('div'); col.className = 'col';\n  Object.assign(col.style, { left: `${colX(c)}px`, top: `${pad}px`, width: `${colW}px`, height: `${bh - pad * 2}px`, background: `${ground}aa`, border: `1px solid ${muted}22` });\n  board.append(col);\n  const head = document.createElement('div'); head.className = 'head';\n  Object.assign(head.style, { left: `${colX(c) + fs * 1.1}px`, top: `${pad + fs * 1.1}px` });\n  head.innerHTML = `<span style=\"width:0.6em;height:0.6em;border-radius:50%;background:${[muted, accent, '#8fbf8f'][c]}\"></span><span style=\"font-weight:500\">${name}</span><span class=\"n\" data-c=\"${c}\" style=\"color:${muted}\">${cards.length}</span>`;\n  board.append(head);\n});\nconst cards = [];\nCONFIG.columns.forEach(([, list], c) => list.forEach((title, i) => {\n  const el = document.createElement('div'); el.className = 'card';\n  Object.assign(el.style, { width: `${colW - fs * 1.6}px`, height: `${cardH}px`, background: B.tokens?.mode === 'light' ? ground : '#1b1b1b', border: `1px solid ${muted}44` });   // cards sit a step off the board in either mode\n  el.innerHTML = `<div style=\"font-weight:500\">${title}</div><i style=\"width:70%;background:${muted};opacity:0.45\"></i><i style=\"width:45%;background:${muted};opacity:0.3\"></i>`;\n  board.append(el); cards.push({ el, c, i });\n}));\nconst slot = $('slot');\nObject.assign(slot.style, { width: `${colW - fs * 1.6}px`, height: `${cardH}px`, border: `1.5px dashed ${accent}88`, background: `${accent}10` });\nconst [fc, fi, tc, ti] = CONFIG.move;\nconst drag = cards.find((k) => k.c === fc && k.i === fi);\ndrag.el.style.zIndex = 20;\nconst cursor = document.createElement('div'); cursor.id = 'cursor'; const cs = fs * 2.4;\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>`;\nboard.append(cursor);\ncam.place(board, { x: 0, y: 0, z: 0 });\nawait document.fonts.ready;\n\nconst T = { reach: [0.3, 0.95], pick: 1.0, carry: [1.2, 2.9], drop: 3.0 };\nconst cx = (c) => colX(c) + fs * 0.8, from = [cx(fc), slotY(fi)], to = [cx(tc), slotY(ti)];\nconst grip = [colW * 0.55, cardH * 0.45];\ns.update((t) => {\n  const lift = t >= T.pick ? spring(t - T.pick, { stiffness: 260, damping: 16 }) : 0;\n  const p = progress(t, ...T.carry, ease.inOutCubic), dropped = t >= T.drop ? spring(t - T.drop, { stiffness: 300, damping: 15 }) : 0;\n  const up = lift * (1 - Math.min(1, dropped));\n  // the carried card: an arc across, leaning into the move (tilt follows its speed)\n  const speed = Math.sin(p * Math.PI) * (p > 0 && p < 1 ? 1 : 0);\n  const x = from[0] + (to[0] - from[0]) * p, y = from[1] + (to[1] - from[1]) * p - Math.sin(p * Math.PI) * cardH * 0.9 - up * cardH * 0.12;\n  drag.el.style.transform = `translate(${x}px, ${y}px) rotate(${up * 3 + speed * 5}deg) scale(${1 + 0.06 * up})`;\n  drag.el.style.boxShadow = `0 ${fs * (0.6 + 3 * up)}px ${fs * (1.5 + 5 * up)}px rgba(0,0,0,${0.3 + 0.35 * up})`;\n  drag.el.style.borderColor = up > 0.05 ? `${accent}88` : `${muted}44`;\n  // the others: the source column closes up after the pick, the target opens a slot before the drop\n  const close = progress(t, T.pick + 0.2, T.pick + 0.7, ease.inOutCubic), open = progress(t, T.carry[0] + 0.7, T.carry[1] - 0.1, ease.inOutCubic);\n  cards.forEach(({ el, c, i }) => {\n    if (el === drag.el) return;\n    let yy = slotY(i);\n    if (c === fc && i > fi) yy -= (cardH + gapY) * close;\n    if (c === tc && i >= ti) yy += (cardH + gapY) * open;\n    el.style.transform = `translate(${cx(c)}px, ${yy}px)`;\n  });\n  slot.style.transform = `translate(${to[0]}px, ${to[1]}px) scale(${0.96 + 0.04 * open})`;\n  slot.style.opacity = String(open * (1 - progress(t, T.drop, T.drop + 0.2)));\n  // the cursor: reaches the card, then travels gripped to it, lets go after the drop\n  const r = progress(t, ...T.reach, ease.inOutCubic), start = [bw * 0.5, bh * 1.05];\n  const g = [from[0] + grip[0], from[1] + grip[1]];\n  let px = start[0] + (g[0] - start[0]) * r, py = start[1] + (g[1] - start[1]) * r;\n  if (t >= T.pick) { px = x + grip[0]; py = y + grip[1]; }\n  if (t >= T.drop + 0.15) { const l = progress(t, T.drop + 0.15, T.drop + 0.9, ease.inOutCubic); px += bw * 0.06 * l; py += bh * 0.1 * l; }\n  cursor.style.transform = `translate(${px}px, ${py}px) scale(${up > 0.5 ? 0.9 : 1})`;\n  cursor.style.opacity = String(progress(t, 0.2, 0.4));\n  // the camera rides with the card, close, leaning the way it travels\n  const arrive = progress(t, 0, 0.8, ease.outCubic), follow = progress(t, 0.4, 1.2, ease.inOutCubic);\n  const fx = x + colW * 0.4 - bw / 2, fy = y + cardH * 0.5 - bh / 2;\n  cam.at({ x: fx * follow, y: fy * follow * 0.8, z: DIST + SHORT * 0.3 * (1 - arrive) - SHORT * (tall ? 1.12 : square ? 0.75 : 0.6) * follow, yaw: (-8 * (1 - arrive) + speed * 6) * (tall ? 0.5 : 1), pitch: 3 * (1 - arrive) + 2 * follow, roll: speed * 1.2 });\n  board.style.opacity = String(progress(t, 0, 0.3));\n  // the counts follow the card\n  board.querySelectorAll('.n').forEach((n) => { const c = +n.dataset.c, base = CONFIG.columns[c][1].length; n.textContent = String(base + (t >= T.pick + 0.3 && c === fc ? -1 : 0) + (t >= T.drop && c === tc ? 1 : 0)); n.style.color = (t >= T.drop && t < T.drop + 0.6 && c === tc) ? accent : muted; });\n});\nB.cue(s, 'text', T.pick); B.cue(s, 'transition', T.carry[0]); B.cue(s, 'land', T.drop);\nB.sound(s);\nawait s.start();\n</script>\n</body>\n</html>\n"
    },
    {
      "path": "pieces/drag-drop/brief.md",
      "content": "# Drag and drop\n\nBlock: drag-drop (5.6 s), from paper-motion.app. The look, fonts and sound come from `brand/`.\n\nA cursor lifts a card on a board, carries it tilted to another column, a slot opens, it drops on a spring and the counts update.\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.6 and 2.9 s; render.\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.6"
  },
  "usage": "npx paper-motion add drag-drop --name my-drag-drop\n# edit CONFIG in pieces/my-drag-drop/scene.html, then:\nnpx paper-motion render pieces/my-drag-drop/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": [
    "toast-stack",
    "magic-move"
  ],
  "preview": {
    "video": "previews/drag-drop.webm",
    "poster": "previews/drag-drop.jpg",
    "at": 3.6,
    "values": {}
  },
  "mood": [
    "playful"
  ],
  "duration": 5.6,
  "formats": [
    "16:9",
    "9:16",
    "1:1"
  ],
  "beats": [
    {
      "name": "Pick",
      "from": 1,
      "to": 1.6,
      "what": "pick"
    },
    {
      "name": "Carry",
      "from": 1.2,
      "to": 2.9,
      "what": "carry"
    },
    {
      "name": "Drop",
      "from": 3,
      "to": 3.6,
      "what": "drop"
    },
    {
      "name": "Hold",
      "from": 3.6,
      "to": 5.6,
      "what": "hold"
    }
  ],
  "when": [
    "boards, lists, anything you rearrange",
    "moving work from one state to another"
  ],
  "needs": [
    {
      "kind": "board",
      "fill": {
        "columns": "$columns",
        "move": "$move"
      }
    }
  ]
}