{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "loader-file-morph",
  "type": "registry:component",
  "title": "Loader File Morph",
  "description": "A single shape morphs between a document, an image frame, an audio disc and a code hexagon, with the inner glyph crossfading at each step. Built for exports and format conversions.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "loaders",
    "loader",
    "morph",
    "export",
    "convert",
    "files",
    "svg"
  ],
  "docs": "https://hyperblur.dev/effects/loader-file-morph",
  "files": [
    {
      "path": "registry/hyperblur/loader-file-morph.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/loader-file-morph.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface LoaderFileMorphProps extends React.HTMLAttributes<HTMLSpanElement> {\n  size?: number;\n  color?: string;\n  accent?: string;\n  speed?: number;\n  labels?: [string, string, string, string];\n  label?: string;\n}\n\ntype Pt = [number, number];\n\nconst N = 64;\n\nfunction samplePolygon(vertices: Pt[]): Pt[] {\n  const closed = [...vertices, vertices[0]];\n  const lengths: number[] = [];\n  let total = 0;\n  for (let i = 0; i < vertices.length; i++) {\n    const [x1, y1] = closed[i];\n    const [x2, y2] = closed[i + 1];\n    const l = Math.hypot(x2 - x1, y2 - y1);\n    lengths.push(l);\n    total += l;\n  }\n  const out: Pt[] = [];\n  for (let k = 0; k < N; k++) {\n    let d = (k / N) * total;\n    let i = 0;\n    while (d > lengths[i] && i < lengths.length - 1) {\n      d -= lengths[i];\n      i++;\n    }\n    const f = lengths[i] ? d / lengths[i] : 0;\n    const [x1, y1] = closed[i];\n    const [x2, y2] = closed[i + 1];\n    out.push([x1 + (x2 - x1) * f, y1 + (y2 - y1) * f]);\n  }\n  return out;\n}\n\nfunction sampleCircle(cx: number, cy: number, r: number): Pt[] {\n  const out: Pt[] = [];\n  for (let k = 0; k < N; k++) {\n    const a = (-135 + (k / N) * 360) * (Math.PI / 180);\n    out.push([cx + Math.cos(a) * r, cy + Math.sin(a) * r]);\n  }\n  return out;\n}\n\nconst shapes: Pt[][] = [\n  samplePolygon([\n    [29, 13],\n    [58, 13],\n    [72, 27],\n    [72, 87],\n    [29, 87],\n  ]),\n  samplePolygon([\n    [14, 25],\n    [86, 25],\n    [86, 75],\n    [14, 75],\n  ]),\n  sampleCircle(50, 50, 35),\n  samplePolygon([\n    [31, 19],\n    [69, 19],\n    [87, 50],\n    [69, 81],\n    [31, 81],\n    [13, 50],\n  ]),\n];\n\nfunction toPath(points: Pt[]) {\n  return `M${points.map(([x, y]) => `${x.toFixed(2)} ${y.toFixed(2)}`).join(\"L\")}Z`;\n}\n\nfunction easeInOut(t: number) {\n  return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;\n}\n\nconst css = `\n.hb-vk2 {\n  display: inline-flex;\n  flex-direction: column;\n  align-items: center;\n  gap: 0.7em;\n  box-sizing: border-box;\n  font-family: inherit;\n  color: #ededed;\n  vertical-align: middle;\n}\n.hb-vk2 *, .hb-vk2 *::before, .hb-vk2 *::after { box-sizing: border-box; }\n.hb-vk2-stage {\n  position: relative;\n  width: var(--hb-vk2-s);\n  height: var(--hb-vk2-s);\n  flex: none;\n}\n.hb-vk2-stage::after {\n  content: \"\";\n  position: absolute;\n  left: 18%;\n  right: 18%;\n  bottom: -2%;\n  height: 8%;\n  border-radius: 50%;\n  background: radial-gradient(closest-side, color-mix(in srgb, var(--hb-vk2-c) 45%, transparent), transparent);\n  filter: blur(2px);\n}\n.hb-vk2-svg { display: block; width: 100%; height: 100%; overflow: visible; }\n.hb-vk2-shape { filter: drop-shadow(0 6px 14px color-mix(in srgb, var(--hb-vk2-c) 40%, transparent)); }\n.hb-vk2-glyph { fill: none; stroke: rgba(255,255,255,0.92); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }\n.hb-vk2-steps { display: inline-flex; gap: 5px; }\n.hb-vk2-step {\n  width: 5px;\n  height: 5px;\n  border-radius: 999px;\n  background: #2a2a2a;\n  transition: width 420ms cubic-bezier(0.22, 1, 0.36, 1), background-color 420ms ease;\n}\n.hb-vk2-step[data-on=\"true\"] { width: 16px; background: var(--hb-vk2-a); }\n.hb-vk2-l {\n  font-size: 12px;\n  line-height: 1.3;\n  color: #a1a1a1;\n  white-space: nowrap;\n  font-variant-numeric: tabular-nums;\n}\n.hb-vk2-l b { color: #ededed; font-weight: 500; }\n.hb-vk2-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n`;\n\nexport function LoaderFileMorph({\n  size = 72,\n  color = \"#2f7bff\",\n  accent = \"#7fb3ff\",\n  speed = 1.6,\n  labels = [\"Document\", \"Image\", \"Audio\", \"Code\"],\n  label,\n  className = \"\",\n  style,\n  ...rest\n}: LoaderFileMorphProps) {\n  const gid = React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const [t, setT] = React.useState(0);\n  const period = Math.max(0.6, speed) * 1000;\n\n  React.useEffect(() => {\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    let raf = 0;\n    let t0 = 0;\n    function tick(now: number) {\n      if (!t0) t0 = now;\n      setT((now - t0) / period);\n      raf = requestAnimationFrame(tick);\n    }\n    raf = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(raf);\n  }, [period]);\n\n  const seg = Math.floor(t) % 4;\n  const next = (seg + 1) % 4;\n  const local = t - Math.floor(t);\n  const k = easeInOut(Math.min(1, Math.max(0, (local - 0.6) / 0.4)));\n  const a = shapes[seg];\n  const b = shapes[next];\n  const points: Pt[] = a.map(([x, y], i) => [x + (b[i][0] - x) * k, y + (b[i][1] - y) * k]);\n  const squash = 1 - 0.07 * Math.sin(Math.PI * k);\n  const tilt = 8 * Math.sin(Math.PI * k) * (seg % 2 ? -1 : 1);\n  const glyph = (i: number) => (i === seg ? Math.max(0, 1 - k * 2.2) : i === next ? Math.max(0, (k - 0.55) * 2.2) : 0);\n  const active = k > 0.5 ? next : seg;\n\n  const vars = {\n    \"--hb-vk2-s\": `${size}px`,\n    \"--hb-vk2-c\": color,\n    \"--hb-vk2-a\": accent,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-loader-file-morph\" precedence=\"default\">{css}</style>\n      <span role=\"status\" className={`hb-vk2 ${className}`} style={vars} {...rest}>\n        <span className=\"hb-vk2-stage\" aria-hidden=\"true\">\n          <svg className=\"hb-vk2-svg\" viewBox=\"0 0 100 100\">\n            <defs>\n              <linearGradient id={`${gid}f`} x1=\"0\" y1=\"0\" x2=\"0.6\" y2=\"1\">\n                <stop offset=\"0%\" stopColor={accent} />\n                <stop offset=\"100%\" stopColor={color} />\n              </linearGradient>\n              <linearGradient id={`${gid}h`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n                <stop offset=\"0%\" stopColor=\"#ffffff\" stopOpacity=\"0.55\" />\n                <stop offset=\"45%\" stopColor=\"#ffffff\" stopOpacity=\"0\" />\n              </linearGradient>\n            </defs>\n            <g transform={`translate(50 50) rotate(${tilt.toFixed(2)}) scale(${(2 - squash).toFixed(3)} ${squash.toFixed(3)}) translate(-50 -50)`}>\n              <path className=\"hb-vk2-shape\" d={toPath(points)} fill={`url(#${gid}f)`} strokeLinejoin=\"round\" />\n              <path d={toPath(points)} fill=\"none\" stroke={`url(#${gid}h)`} strokeWidth=\"1.4\" />\n              <g className=\"hb-vk2-glyph\" opacity={glyph(0).toFixed(3)}>\n                <path d=\"M38 40h20M38 51h24M38 62h16\" />\n              </g>\n              <g className=\"hb-vk2-glyph\" opacity={glyph(1).toFixed(3)}>\n                <circle cx=\"66\" cy=\"39\" r=\"4.5\" />\n                <path d=\"M24 66l15-15 11 10 7-6 15 11\" />\n              </g>\n              <g className=\"hb-vk2-glyph\" opacity={glyph(2).toFixed(3)}>\n                <path d=\"M34 46v8M42 39v22M50 33v34M58 41v18M66 47v6\" />\n              </g>\n              <g className=\"hb-vk2-glyph\" opacity={glyph(3).toFixed(3)}>\n                <path d=\"M39 40l-10 10 10 10M61 40l10 10-10 10M54 36l-8 28\" />\n              </g>\n            </g>\n          </svg>\n        </span>\n        <span className=\"hb-vk2-steps\" aria-hidden=\"true\">\n          {labels.map((l, i) => (\n            <span key={l + i} className=\"hb-vk2-step\" data-on={i === active} />\n          ))}\n        </span>\n        {label ? (\n          <span className=\"hb-vk2-l\" aria-hidden=\"true\">\n            {label} <b>{labels[active]}</b>\n          </span>\n        ) : null}\n        <span className=\"hb-vk2-sr\">{label ?? \"Converting\"}</span>\n      </span>\n    </>\n  );\n}\n"
    }
  ]
}