{
  "$schema": "../../schema.json",
  "id": "unfold",
  "type": "component",
  "title": "Unfold",
  "summary": "A's items leave, A folds into a glowing line, B unfolds out of the line with overshoot, items rise from it.",
  "tags": [
    "component",
    "reveal",
    "line",
    "ui"
  ],
  "version": "1.0.0",
  "license": "MIT",
  "export": "unfold",
  "signature": "unfold(a, b, p, { duration, radius })",
  "params": [
    {
      "name": "duration",
      "type": "number",
      "default": 1.2,
      "description": "length of the transition in seconds; springs use it to keep their feel",
      "min": 0.2,
      "max": 3,
      "step": 0.05,
      "group": "main"
    },
    {
      "name": "radius",
      "type": "number",
      "default": 14,
      "description": "corner radius in px",
      "min": 0,
      "max": 60,
      "step": 1,
      "group": "main"
    }
  ],
  "install": {
    "kind": "code"
  },
  "files": [
    {
      "path": "moves/unfold.js",
      "content": "import { ease, clamp, lerp, progress } from 'paper-motion';\nimport { dims, items, show, sp, settle, blur, layer, hide, resetAll } from 'paper-motion/kit';\n\n/** A's items leave, A folds into a glowing line, a glint runs along it, and B unfolds out of the line with overshoot as its items rise from it. */\nexport function unfold(a, b, p, { duration = 1.2, radius = 14 } = {}) {\n  const slot = a.parentElement, [w, h] = dims(a);\n  if (p <= 0 || p >= 1) { hide(slot, 'ufLine'); resetAll(a, b, ...items(a), ...items(b)); show(a, b, p); return; }\n  items(a).forEach((c, i) => { const l = progress(p, i * 0.03, i * 0.03 + 0.22); c.style.transform = `translateY(${-30 * ease.inCubic(l)}px)`; c.style.opacity = 1 - l; c.style.filter = blur(10 * l); });\n  const f = ease.inOutCubic(progress(p, 0.16, 0.42)), ins = (h / 2 - 1.5) * f;\n  a.style.clipPath = `inset(${ins}px 0 ${ins}px 0 round ${lerp(radius, 2, f)}px)`;\n  a.style.opacity = p < 0.44 ? 1 : 0;\n  const lp = progress(p, 0.36, 0.64), breathe = Math.sin(Math.PI * lp), g = ease.inOutCubic(lp) * 120 - 10;\n  layer(slot, 'ufLine', `display:${lp > 0 && lp < 1 ? 'block' : 'none'};left:${(w - w * (1 + 0.08 * breathe)) / 2}px;width:${w * (1 + 0.08 * breathe)}px;top:${h / 2 - 1.5}px;height:3px;z-index:4;border-radius:2px;`\n    + `background:linear-gradient(90deg,rgba(255,255,255,.35) ${g - 14}%,#fff ${g}%,rgba(255,255,255,.35) ${g + 14}%);box-shadow:0 0 ${18 * breathe}px rgba(255,255,255,${0.6 * breathe})`);\n  const u = settle(sp(p, 0.5, duration, { stiffness: 230, damping: 16 }), p), bi = Math.max(0, (h / 2 - 1.5) * (1 - u));\n  b.style.clipPath = `inset(${bi}px 0 ${bi}px 0 round ${lerp(2, radius, clamp(u))}px)`;\n  b.style.transform = `scaleY(${1 + Math.max(0, u - 1) * 0.6})`;\n  b.style.opacity = p > 0.5 ? 1 : 0;\n  items(b).forEach((c, i) => { const q = ease.outExpo(progress(p, 0.6 + i * 0.04, 0.88 + i * 0.03)); c.style.transform = `translateY(${40 * (1 - q)}px)`; c.style.opacity = q; c.style.filter = blur(8 * (1 - q)); });\n}\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.0"
  },
  "usage": "import { unfold } from './moves/unfold.js';\n\n// A and B (two states of a card) stacked in one positioned slot; 1.1 s from 2.0 s:\ns.update((t) => unfold(cardA, cardB, progress(t, 2.0, 3.1), { duration: 1.1 }));",
  "notes": [
    "A's items leave, A folds into a glowing line, a glint runs along it, and B unfolds out of the line with overshoot as its items rise from it.",
    "Stack A and B in one positioned slot (their parent); give the slot overflow:hidden to keep travel inside it.",
    "Pass the real duration in seconds and call it through p = 1: that is when it hides the layers it made.",
    "Render with --motion-blur 5."
  ],
  "preview": {
    "video": "previews/unfold.webm",
    "poster": "previews/unfold.jpg"
  },
  "mood": [
    "calm",
    "editorial",
    "luxury"
  ],
  "energy": 3,
  "role": "swap",
  "when": [
    "a reveal with weight and a pause",
    "a line becomes a panel"
  ]
}