{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "silk",
  "type": "registry:component",
  "title": "Silk",
  "description": "Layered sine waves filled with soft gradients that drift and breathe, like folded fabric.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "silk",
    "waves",
    "fabric",
    "gradient",
    "background",
    "canvas"
  ],
  "docs": "https://hyperblur.dev/effects/silk",
  "files": [
    {
      "path": "registry/hyperblur/silk.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/silk.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SilkProps extends React.HTMLAttributes<HTMLDivElement> {\n  color?: string;\n  secondary?: string;\n  layers?: number;\n  speed?: number;\n  amplitude?: number;\n  seed?: number;\n}\n\nconst css = `\n.hb-sk { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }\n.hb-sk-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }\n`;\n\ninterface Layer {\n  base: number;\n  amp: number;\n  f1: number;\n  f2: number;\n  s1: number;\n  s2: number;\n  p1: number;\n  p2: number;\n  drift: number;\n  breathe: number;\n  rgb: [number, number, number];\n  fill: CanvasGradient | null;\n  line: CanvasGradient | null;\n}\n\nfunction rnd(i: number, salt: number, seed: number) {\n  let x = (Math.imul(i + 1, 2654435761) + Math.imul(salt + 1, 40503) + Math.imul(seed | 0, 2246822519)) >>> 0;\n  x = Math.imul((x >>> 16) ^ x, 0x45d9f3b);\n  x = Math.imul((x >>> 16) ^ x, 0x45d9f3b);\n  x = ((x >>> 16) ^ x) >>> 0;\n  return x / 4294967296;\n}\n\nfunction parseColor(ctx: CanvasRenderingContext2D, value: string, fallback: string): [number, number, number] {\n  ctx.fillStyle = fallback;\n  ctx.fillStyle = value;\n  const s = String(ctx.fillStyle);\n  if (s[0] === \"#\") {\n    const n = parseInt(s.slice(1), 16);\n    return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n  }\n  const m = s.match(/[\\d.]+/g);\n  return m && m.length >= 3 ? [Math.round(+m[0]), Math.round(+m[1]), Math.round(+m[2])] : [47, 123, 255];\n}\n\nexport function Silk({\n  color = \"#2f7bff\",\n  secondary = \"#19c3f5\",\n  layers = 4,\n  speed = 1,\n  amplitude = 0.5,\n  seed = 1,\n  className = \"\",\n  style,\n  ...rest\n}: SilkProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n\n  React.useEffect(() => {\n    const wrap = wrapRef.current;\n    const canvas = canvasRef.current;\n    const ctx = canvas ? canvas.getContext(\"2d\") : null;\n    if (!wrap || !canvas || !ctx) return;\n\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const total = Math.max(1, Math.round(layers));\n    const amp = Math.min(1, Math.max(0, amplitude));\n    const c1 = parseColor(ctx, color, \"#2f7bff\");\n    const c2 = parseColor(ctx, secondary, \"#19c3f5\");\n    const TAU = Math.PI * 2;\n    const step = 8;\n\n    const table = new Float32Array(32);\n    for (let i = 0; i < 32; i++) table[i] = rnd(i, 99, seed) * 2 - 1;\n    const noise = (x: number) => {\n      const i = Math.floor(x);\n      const f = x - i;\n      const s = f * f * (3 - 2 * f);\n      return table[i & 31] * (1 - s) + table[(i + 1) & 31] * s;\n    };\n\n    const stack: Layer[] = Array.from({ length: total }, (_, i) => {\n      const u = total > 1 ? i / (total - 1) : 0.5;\n      return {\n        base: 0.3 + 0.5 * u + (rnd(i, 1, seed) - 0.5) * 0.06,\n        amp: 0.05 + 0.17 * amp,\n        f1: TAU * (0.6 + rnd(i, 2, seed) * 0.9),\n        f2: TAU * (1.4 + rnd(i, 3, seed) * 1.6),\n        s1: (0.2 + rnd(i, 4, seed) * 0.3) * (rnd(i, 5, seed) < 0.5 ? -1 : 1),\n        s2: 0.15 + rnd(i, 6, seed) * 0.3,\n        p1: rnd(i, 7, seed) * TAU,\n        p2: rnd(i, 8, seed) * TAU,\n        drift: i * 7.3 + rnd(i, 9, seed) * 10,\n        breathe: rnd(i, 10, seed) * TAU,\n        rgb: [\n          Math.round(c1[0] + (c2[0] - c1[0]) * u),\n          Math.round(c1[1] + (c2[1] - c1[1]) * u),\n          Math.round(c1[2] + (c2[2] - c1[2]) * u),\n        ],\n        fill: null,\n        line: null,\n      };\n    });\n\n    let w = 1;\n    let h = 1;\n    let dpr = 1;\n    let raf = 0;\n    let last = 0;\n    let time = 0;\n    let visible = true;\n    let sheen: CanvasGradient | null = null;\n\n    const build = () => {\n      const s = ctx.createLinearGradient(0, 0, w, 0);\n      s.addColorStop(0, \"rgba(255,255,255,0)\");\n      s.addColorStop(0.5, \"rgba(255,255,255,0.06)\");\n      s.addColorStop(1, \"rgba(255,255,255,0)\");\n      sheen = s;\n      for (const l of stack) {\n        const [r, g, b] = l.rgb;\n        const top = l.base * h - l.amp * h * 2.2;\n        const f = ctx.createLinearGradient(0, top, 0, h);\n        f.addColorStop(0, `rgba(${r},${g},${b},0.5)`);\n        f.addColorStop(0.35, `rgba(${r},${g},${b},0.16)`);\n        f.addColorStop(1, `rgba(${r},${g},${b},0)`);\n        l.fill = f;\n        const hi = [Math.round(r + (255 - r) * 0.5), Math.round(g + (255 - g) * 0.5), Math.round(b + (255 - b) * 0.5)];\n        const e = ctx.createLinearGradient(0, 0, w, 0);\n        e.addColorStop(0, `rgba(${hi[0]},${hi[1]},${hi[2]},0)`);\n        e.addColorStop(0.3, `rgba(${hi[0]},${hi[1]},${hi[2]},0.7)`);\n        e.addColorStop(0.7, `rgba(${hi[0]},${hi[1]},${hi[2]},0.7)`);\n        e.addColorStop(1, `rgba(${hi[0]},${hi[1]},${hi[2]},0)`);\n        l.line = e;\n      }\n    };\n\n    const draw = (t: number) => {\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      ctx.clearRect(0, 0, w, h);\n      ctx.globalCompositeOperation = \"lighter\";\n      ctx.lineWidth = 1.25;\n      ctx.lineJoin = \"round\";\n      const ts = t * speed;\n      for (const l of stack) {\n        const a = l.amp * h * (0.82 + 0.18 * Math.sin(ts * 0.4 + l.breathe));\n        const y0 = l.base * h;\n        ctx.beginPath();\n        for (let x = -step; x <= w + step; x += step) {\n          const u = x / w;\n          const n = noise(u * 2.2 + ts * 0.08 + l.drift);\n          const y =\n            y0 +\n            a * Math.sin(u * l.f1 + ts * l.s1 + l.p1 + n * 1.1) +\n            a * 0.5 * Math.sin(u * l.f2 - ts * l.s2 + l.p2 + n * 0.7);\n          if (x < 0) ctx.moveTo(x, y);\n          else ctx.lineTo(x, y);\n        }\n        if (l.line) ctx.strokeStyle = l.line;\n        ctx.globalAlpha = 0.55;\n        ctx.stroke();\n        ctx.lineTo(w + step, h + 2);\n        ctx.lineTo(-step, h + 2);\n        ctx.closePath();\n        ctx.globalAlpha = 1;\n        if (l.fill) ctx.fillStyle = l.fill;\n        ctx.fill();\n        if (sheen) {\n          ctx.fillStyle = sheen;\n          ctx.fill();\n        }\n      }\n      ctx.globalAlpha = 1;\n      ctx.globalCompositeOperation = \"source-over\";\n    };\n\n    const active = () => visible && !document.hidden && !reduce.matches;\n\n    const frame = (now: number) => {\n      raf = 0;\n      time += Math.min(0.05, (now - last) / 1000);\n      last = now;\n      draw(time);\n      if (active()) raf = requestAnimationFrame(frame);\n    };\n\n    const sync = () => {\n      if (active()) {\n        if (!raf) {\n          last = performance.now();\n          raf = requestAnimationFrame(frame);\n        }\n      } else {\n        cancelAnimationFrame(raf);\n        raf = 0;\n        draw(time);\n      }\n    };\n\n    const resize = () => {\n      w = Math.max(1, wrap.clientWidth);\n      h = Math.max(1, wrap.clientHeight);\n      dpr = Math.min(2, window.devicePixelRatio || 1);\n      canvas.width = Math.round(w * dpr);\n      canvas.height = Math.round(h * dpr);\n      build();\n      draw(time);\n    };\n\n    const ro = new ResizeObserver(resize);\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n      sync();\n    });\n\n    ro.observe(wrap);\n    io.observe(wrap);\n    document.addEventListener(\"visibilitychange\", sync);\n    reduce.addEventListener(\"change\", sync);\n    resize();\n    sync();\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", sync);\n      reduce.removeEventListener(\"change\", sync);\n    };\n  }, [color, secondary, layers, speed, amplitude, seed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-sk ${className}`} style={style} aria-hidden=\"true\" {...rest}>\n      <style href=\"hb-silk\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-sk-canvas\" />\n    </div>\n  );\n}\n"
    }
  ]
}