{
  "$schema": "../../schema.json",
  "id": "squash-drop",
  "type": "component",
  "title": "Squash drop",
  "summary": "A squashes, launches up stretched; B falls in, squashes on impact, wobbles; its content follows through.",
  "tags": [
    "component",
    "playful",
    "physics",
    "ui"
  ],
  "version": "1.0.0",
  "license": "MIT",
  "export": "squashDrop",
  "signature": "squashDrop(a, b, p, { duration, height })",
  "params": [
    {
      "name": "duration",
      "type": "number",
      "default": 1.1,
      "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": "height",
      "type": "number",
      "default": 1.3,
      "description": "launch height in heights",
      "min": 0.5,
      "max": 3,
      "step": 0.05,
      "group": "main"
    }
  ],
  "install": {
    "kind": "code"
  },
  "files": [
    {
      "path": "moves/squash-drop.js",
      "content": "import { ease, progress } from 'paper-motion';\nimport { dims, items, show, layer, hide, resetAll } from 'paper-motion/kit';\n\n/** A squashes, then launches up stretched; B falls in stretched, squashes on impact and wobbles to rest while its content follows through. */\nexport function squashDrop(a, b, p, { duration = 1.1, height = 1.3 } = {}) {\n  const slot = a.parentElement, [w, h] = dims(a);\n  if (p <= 0 || p >= 1) { hide(slot, 'sdL', 'sdR'); resetAll(a, b, ...items(b)); show(a, b, p); return; }\n  const sq = ease.outQuad(progress(p, 0, 0.13)) * (1 - progress(p, 0.13, 0.2)), up = ease.inCubic(progress(p, 0.12, 0.38));\n  a.style.transformOrigin = '50% 100%';\n  a.style.transform = `translateY(${-h * height * up}px) scale(${1 + 0.05 * sq - 0.07 * up}, ${1 - 0.09 * sq + 0.16 * up})`;\n  a.style.opacity = p < 0.38 ? 1 : 0;\n  const HIT = 0.58, fall = ease.inCubic(progress(p, 0.3, HIT)), dt = Math.max(0, (p - HIT) * duration), end = 1 - progress(p, 0.9, 1);\n  const wob = p > HIT ? Math.exp(-dt * 7) * Math.cos(dt * 24) * end : 0, st = p < HIT ? 0.14 * fall : 0;\n  b.style.transformOrigin = '50% 100%';\n  b.style.transform = `translateY(${-h * height * (1 - fall)}px) scale(${1 - 0.06 * st + 0.09 * wob}, ${1 + st - 0.13 * wob})`;\n  b.style.opacity = p > 0.3 ? 1 : 0;\n  items(b).forEach((c, i) => { const y = p < HIT ? -24 * fall : -24 * Math.exp(-dt * 8) * Math.cos(dt * 20 + i * 0.4) * end; c.style.transform = `translateY(${y}px)`; });\n  const l = progress(p, HIT, HIT + 0.22), on = l > 0 && l < 1 ? 'block' : 'none', len = 120 * (1 - l) + 12, reach = 150 * ease.outCubic(l);\n  layer(slot, 'sdL', `display:${on};left:${-reach - len}px;top:${h - 2}px;width:${len}px;height:3px;background:#fff;opacity:${1 - l};z-index:4`);\n  layer(slot, 'sdR', `display:${on};left:${w + reach}px;top:${h - 2}px;width:${len}px;height:3px;background:#fff;opacity:${1 - l};z-index:4`);\n}\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.0"
  },
  "usage": "import { squashDrop } from './moves/squash-drop.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) => squashDrop(cardA, cardB, progress(t, 2.0, 3.1), { duration: 1.1 }));",
  "notes": [
    "A squashes, then launches up stretched; B falls in stretched, squashes on impact and wobbles to rest while its content follows through.",
    "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/squash-drop.webm",
    "poster": "previews/squash-drop.jpg"
  },
  "mood": [
    "playful",
    "warm",
    "bold"
  ],
  "energy": 5,
  "role": "swap",
  "when": [
    "cartoon physics suit the brand",
    "fun, snappy swaps"
  ]
}