{
  "$schema": "../../schema.json",
  "id": "whip-pan",
  "type": "component",
  "title": "Whip pan",
  "summary": "A winds up, whips out tilted and smeared under a light streak; B whips in, overshoots, its content trails.",
  "tags": [
    "component",
    "energetic",
    "motion-blur",
    "ui"
  ],
  "version": "1.0.0",
  "license": "MIT",
  "export": "whipPan",
  "signature": "whipPan(a, b, p, { duration, dir, tilt, travel })",
  "params": [
    {
      "name": "duration",
      "type": "number",
      "default": 0.9,
      "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": "dir",
      "type": "enum",
      "default": "left",
      "description": "direction",
      "options": [
        "left",
        "right"
      ],
      "control": "segmented",
      "group": "main"
    },
    {
      "name": "tilt",
      "type": "number",
      "default": 7,
      "description": "tilt in degrees",
      "min": 0,
      "max": 30,
      "step": 0.5,
      "group": "main"
    },
    {
      "name": "travel",
      "type": "number",
      "default": 1.35,
      "description": "travel distance in widths",
      "min": 0.5,
      "max": 3,
      "step": 0.05,
      "group": "main"
    }
  ],
  "install": {
    "kind": "code"
  },
  "files": [
    {
      "path": "moves/whip-pan.js",
      "content": "import { ease, clamp, lerp, progress } from 'paper-motion';\nimport { dims, items, show, sp, settle, layer, hide, resetAll } from 'paper-motion/kit';\n\n/** A winds up, then whips out tilted and smeared; a light streak crosses at full speed; B whips in, overshoots and settles, its content trailing. */\nexport function whipPan(a, b, p, { duration = 0.9, dir = 'left', tilt = 7, travel = 1.35 } = {}) {\n  const slot = a.parentElement, [w] = dims(a), s = dir === 'left' ? -1 : 1;\n  if (p <= 0 || p >= 1) { hide(slot, 'wpStreak'); resetAll(a, b, ...items(a), ...items(b)); show(a, b, p); return; }\n  const wind = ease.outCubic(progress(p, 0, 0.18)) * (1 - ease.inCubic(progress(p, 0.18, 0.3)));\n  const out = ease.inExpo(progress(p, 0.16, 0.5));\n  a.style.transformOrigin = '50% 70%';\n  a.style.transform = `translateX(${-s * 40 * wind + s * w * travel * out}px) rotate(${-s * 1.6 * wind + s * tilt * out}deg) skewX(${-s * 12 * out}deg) scale(${1 - 0.03 * wind})`;\n  a.style.opacity = p < 0.5 ? 1 : 0;\n  const e = settle(sp(p, 0.42, duration, { stiffness: 250, damping: 19 }), p), r = 1 - e;\n  b.style.transformOrigin = '50% 70%';\n  b.style.transform = `translateX(${-s * w * travel * r}px) rotate(${-s * tilt * r}deg) skewX(${s * 12 * clamp(r) * clamp(r)}deg)`;\n  b.style.opacity = p > 0.42 ? 1 : 0;\n  items(b).forEach((c, i) => { const ci = settle(sp(p, 0.47 + i * 0.03, duration, { stiffness: 230, damping: 17 }), p); c.style.transform = `translateX(${-s * 110 * (1 - ci)}px)`; });\n  const st = progress(p, 0.28, 0.64), so = Math.sin(Math.PI * st), sw = w * 0.45;\n  layer(slot, 'wpStreak', `display:${so > 0.01 ? 'block' : 'none'};left:${lerp(s < 0 ? w : -sw, s < 0 ? -sw : w, ease.inOutCubic(st))}px;top:-15%;width:${sw}px;height:130%;z-index:5;opacity:${0.7 * so};`\n    + `background:linear-gradient(90deg,transparent,rgba(255,255,255,.85),transparent);transform:skewX(${-s * 18}deg);mix-blend-mode:screen;filter:blur(16px)`);\n}\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.0"
  },
  "usage": "import { whipPan } from './moves/whip-pan.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) => whipPan(cardA, cardB, progress(t, 2.0, 3.1), { duration: 1.1 }));",
  "notes": [
    "A winds up, then whips out tilted and smeared; a light streak crosses at full speed; B whips in, overshoots and settles, its content trailing.",
    "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/whip-pan.webm",
    "poster": "previews/whip-pan.jpg"
  },
  "mood": [
    "bold",
    "playful"
  ],
  "energy": 5,
  "role": "swap",
  "when": [
    "energetic UI or card swaps",
    "you want speed with a light streak"
  ]
}