{
  "$schema": "../../schema.json",
  "id": "dive-in",
  "type": "component",
  "title": "Dive in",
  "summary": "The camera dives into a detail of A; B opens inside it, a ring breaks outward, B's parts rise into focus.",
  "tags": [
    "component",
    "focus",
    "camera",
    "ui"
  ],
  "version": "1.0.0",
  "license": "MIT",
  "export": "diveIn",
  "signature": "diveIn(a, b, p, { duration, target, depth })",
  "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": "target",
      "type": "string",
      "default": "[data-par",
      "description": "CSS selector of the detail to dive into",
      "hidden": true
    },
    {
      "name": "depth",
      "type": "number",
      "default": 16,
      "description": "how deep the camera dives",
      "min": 2,
      "max": 30,
      "step": 0.5,
      "group": "main"
    }
  ],
  "install": {
    "kind": "code"
  },
  "files": [
    {
      "path": "moves/dive-in.js",
      "content": "import { ease, lerp, progress } from 'paper-motion';\nimport { dims, items, show, blur, rectIn, layer, hide, resetAll } from 'paper-motion/kit';\n\n/** The camera dives into a detail of A (`target`); B opens inside it as it fills the slot, a ring breaks outward, B's parts rise into focus. */\nexport function diveIn(a, b, p, { duration = 1.1, target = '[data-part=\"media\"]', depth = 16 } = {}) {\n  const slot = a.parentElement, t = a.querySelector(target) ?? a, R = rectIn(t, a), cx = R.x + R.w / 2, cy = R.y + R.h / 2;\n  if (p <= 0 || p >= 1) { hide(slot, 'diveRing'); resetAll(a, b, ...items(b)); show(a, b, p); return; }\n  const [w, h] = dims(a), full = Math.hypot(Math.max(cx, w - cx), Math.max(cy, h - cy));\n  const z = ease.inExpo(progress(p, 0.02, 0.5)), sa = 1 + (depth - 1) * z;\n  a.style.transformOrigin = `${cx}px ${cy}px`; a.style.transform = `scale(${sa})`;\n  a.style.filter = blur(10 * ease.inQuad(progress(p, 0.25, 0.5))); a.style.opacity = 1 - progress(p, 0.46, 0.56);\n  const rad = Math.max((Math.min(R.w, R.h) / 2) * 0.8 * sa, lerp(0, full * 1.05, ease.inOutCubic(progress(p, 0.42, 0.78))));\n  const bz = ease.outExpo(progress(p, 0.3, 1)), sb = 1.6 - 0.6 * bz;\n  b.style.transformOrigin = `${cx}px ${cy}px`; b.style.transform = `scale(${sb})`; b.style.filter = blur(12 * (1 - bz));\n  b.style.clipPath = rad >= full ? 'none' : `circle(${rad / sb}px at ${cx}px ${cy}px)`;\n  b.style.opacity = p > 0.1 ? 1 : 0; b.style.zIndex = 3; a.style.zIndex = 2;\n  items(b).forEach((c, i) => { const q = ease.outExpo(progress(p, 0.55 + i * 0.035, 0.85 + i * 0.035)); c.style.transform = `translateY(${40 * (1 - q)}px)`; c.style.opacity = q; c.style.filter = blur(8 * (1 - q)); });\n  const ring = progress(p, 0.4, 0.82), rr = rad + 60 * ease.outCubic(ring);\n  layer(slot, 'diveRing', `display:${ring > 0 && ring < 1 ? 'block' : 'none'};left:${cx - rr}px;top:${cy - rr}px;width:${2 * rr}px;height:${2 * rr}px;border-radius:50%;z-index:4;`\n    + `border:${2 + 6 * (1 - ring)}px solid rgba(255,255,255,${0.75 * (1 - ring)})`);\n}\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.0"
  },
  "usage": "import { diveIn } from './moves/dive-in.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) => diveIn(cardA, cardB, progress(t, 2.0, 3.1), { duration: 1.1 }));",
  "notes": [
    "The camera dives into a detail of A (`target`); B opens inside it as it fills the slot, a ring breaks outward, B's parts rise into focus.",
    "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.",
    "`target` is a selector inside A (default [data-part=\"media\"]); a round detail reads best."
  ],
  "preview": {
    "video": "previews/dive-in.webm",
    "poster": "previews/dive-in.jpg"
  },
  "mood": [
    "technical",
    "luxury"
  ],
  "energy": 4,
  "role": "camera",
  "when": [
    "going into a detail of a card or UI",
    "\"and now, inside\""
  ]
}