{
  "$schema": "../../schema.json",
  "id": "flip-lift",
  "type": "component",
  "title": "Flip lift",
  "summary": "A lifts toward the camera, flips with a wobble and a sheen, lands as B with an echo; B's parts pop in.",
  "tags": [
    "component",
    "3d",
    "spring",
    "ui"
  ],
  "version": "1.0.0",
  "license": "MIT",
  "export": "flipLift",
  "signature": "flipLift(a, b, p, { duration, lift, perspective })",
  "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": "lift",
      "type": "number",
      "default": 150,
      "description": "lift toward the camera in px",
      "min": 0,
      "max": 400,
      "step": 5,
      "group": "main"
    },
    {
      "name": "perspective",
      "type": "number",
      "default": 1800,
      "description": "3D perspective in px",
      "min": 400,
      "max": 4000,
      "step": 50,
      "group": "main"
    }
  ],
  "install": {
    "kind": "code"
  },
  "files": [
    {
      "path": "moves/flip-lift.js",
      "content": "import { ease, clamp, progress } from 'paper-motion';\nimport { items, show, sp, settle, layer, hide, resetAll } from 'paper-motion/kit';\n\n/** A lifts toward the camera, flips with a wobble and a sheen across its face, and lands as B with an echo; B's parts pop in after. */\nexport function flipLift(a, b, p, { duration = 1.2, lift = 150, perspective = 1800 } = {}) {\n  const slot = a.parentElement;\n  if (p <= 0 || p >= 1) { hide(slot, 'flEcho'); hide(a, 'sheen'); hide(b, 'sheen'); resetAll(a, b, ...items(b)); a.style.backfaceVisibility = b.style.backfaceVisibility = ''; show(a, b, p); return; }\n  slot.style.perspective = `${perspective}px`;\n  const L = ease.outCubic(progress(p, 0, 0.22)) * (1 - ease.inOutCubic(progress(p, 0.6, 0.8)));\n  const ang = 180 * settle(sp(p, 0.14, duration, { stiffness: 110, damping: 11 }), p);\n  const dt = Math.max(0, (p - 0.8) * duration), imp = p > 0.8 ? Math.exp(-dt * 9) * Math.sin(dt * 30) * (1 - progress(p, 0.92, 1)) : 0;\n  const tf = (deg) => `translateZ(${lift * L}px) rotateX(${-8 * L}deg) rotateY(${deg}deg) scale(${1 - 0.035 * imp})`;\n  a.style.transform = tf(ang); b.style.transform = tf(ang - 180);\n  a.style.backfaceVisibility = 'hidden'; b.style.backfaceVisibility = 'hidden'; a.style.opacity = 1; b.style.opacity = 1;\n  const turn = Math.abs(Math.sin((ang * Math.PI) / 180));\n  for (const [el, off] of [[a, 0], [b, 180]]) {\n    const pos = 120 - ((ang - off + 180) / 360) * 140;\n    layer(el, 'sheen', `display:block;inset:0;z-index:9;border-radius:inherit;background:linear-gradient(105deg,transparent 38%,rgba(255,255,255,.28) 50%,transparent 62%);background-size:300% 100%;background-position:${pos}% 0;opacity:${0.25 + 0.75 * turn}`);\n  }\n  a.style.filter = `brightness(${1 - 0.45 * turn})`; b.style.filter = `brightness(${1 - 0.45 * turn})`;\n  const e = progress(p, 0.8, 1);\n  layer(slot, 'flEcho', `display:${e > 0 && e < 1 ? 'block' : 'none'};inset:0;z-index:0;border-radius:14px;border:1.5px solid rgba(255,255,255,${0.55 * (1 - e)});transform:scale(${1 + 0.14 * ease.outCubic(e)})`);\n  items(b).forEach((c, i) => { const q = settle(sp(p, 0.3 + i * 0.035, duration, { stiffness: 240, damping: 14 }), p); c.style.transform = `translateY(${26 * (1 - q)}px) scale(${0.92 + 0.08 * q})`; c.style.opacity = clamp(0.25 + q); });\n}\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.0"
  },
  "usage": "import { flipLift } from './moves/flip-lift.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) => flipLift(cardA, cardB, progress(t, 2.0, 3.1), { duration: 1.1 }));",
  "notes": [
    "A lifts toward the camera, flips with a wobble and a sheen across its face, and lands as B with an echo; B's parts pop in after.",
    "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/flip-lift.webm",
    "poster": "previews/flip-lift.jpg"
  },
  "mood": [
    "playful",
    "luxury"
  ],
  "energy": 4,
  "role": "swap",
  "when": [
    "a card turns over to show its other side",
    "physical, tactile products"
  ]
}