{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"silk-flowing-line-bundle-canvas-background","type":"registry:block","title":"Silk Flowing Line Bundle","description":"","dependencies":[],"files":[{"path":"components/we-inc/silk-flowing-line-bundle-canvas-background.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\n// A bundle of hairlines strung between two moving edge curves. The second control point is\n// interpolated the opposite way, so the bundle twists over itself like a fold of silk.\n// Change these: thread count, colours (rgb), opacity and how fast the cloth moves.\nconst THREADS = 90;\nconst SAND = \"214,190,150\";\nconst GLASS = \"143,186,180\";\nconst ALPHA = 0.32;\nconst SPEED = 1;\n\nexport default function SilkFlowingLineBundle() {\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!canvas || !ctx) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let w = 0;\n    let h = 0;\n    let raf = 0;\n    let onScreen = true;\n    const born = performance.now();\n    const cleanups: (() => void)[] = [];\n\n    const draw = (t: number) => {\n      ctx.clearRect(0, 0, w, h);\n      const s = t * SPEED;\n      const A = [\n        h * (0.42 + 0.06 * Math.sin(s * 0.21)),\n        w * (0.28 + 0.05 * Math.sin(s * 0.17)), h * (0.2 + 0.12 * Math.sin(s * 0.23 + 1)),\n        w * (0.62 + 0.05 * Math.sin(s * 0.19 + 2)), h * (0.32 + 0.12 * Math.sin(s * 0.25 + 2.2)),\n        h * (0.3 + 0.08 * Math.sin(s * 0.15 + 3)),\n      ];\n      const B = [\n        h * (1.02 + 0.05 * Math.sin(s * 0.18 + 2.4)),\n        w * (0.36 + 0.06 * Math.sin(s * 0.2 + 1.2)), h * (1.15 + 0.1 * Math.sin(s * 0.16 + 0.3)),\n        w * (0.7 + 0.05 * Math.sin(s * 0.22 + 4)), h * (1.15 + 0.1 * Math.sin(s * 0.27 + 0.5)),\n        h * (0.92 + 0.07 * Math.sin(s * 0.14 + 1)),\n      ];\n      const grad = ctx.createLinearGradient(0, 0, w, 0);\n      grad.addColorStop(0, \"rgba(\" + SAND + \",\" + ALPHA * 0.4 + \")\");\n      grad.addColorStop(0.35, \"rgba(\" + SAND + \",\" + ALPHA + \")\");\n      grad.addColorStop(0.7, \"rgba(\" + GLASS + \",\" + ALPHA + \")\");\n      grad.addColorStop(1, \"rgba(\" + GLASS + \",\" + ALPHA * 0.5 + \")\");\n      ctx.globalCompositeOperation = \"lighter\";\n      ctx.strokeStyle = grad;\n      ctx.lineWidth = 0.9;\n      for (let i = 0; i < THREADS; i++) {\n        const u = i / (THREADS - 1);\n        const v = 1 - u;\n        const wob = 0.02 * Math.sin(s * 0.5 + u * 9);\n        ctx.beginPath();\n        ctx.moveTo(-0.1 * w, A[0] + (B[0] - A[0]) * u);\n        ctx.bezierCurveTo(\n          A[1] + (B[1] - A[1]) * u, A[2] + (B[2] - A[2]) * u + wob * h,\n          A[3] + (B[3] - A[3]) * v, A[4] + (B[4] - A[4]) * v - wob * h,\n          1.1 * w, A[5] + (B[5] - A[5]) * u,\n        );\n        ctx.stroke();\n      }\n      ctx.globalCompositeOperation = \"source-over\";\n    };\n    const now = () => 22 + (performance.now() - born) / 1000;\n    const frame = () => {\n      raf = 0;\n      draw(now());\n      if (onScreen && !reduce) raf = requestAnimationFrame(frame);\n    };\n    const resize = () => {\n      const r = canvas.getBoundingClientRect();\n      const dpr = Math.min(window.devicePixelRatio || 1, 1.5);\n      w = r.width;\n      h = r.height;\n      canvas.width = Math.max(1, Math.round(w * dpr));\n      canvas.height = Math.max(1, Math.round(h * dpr));\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      draw(reduce ? 22 : now());\n    };\n    const ro = new ResizeObserver(resize);\n    ro.observe(canvas);\n    resize();\n    const io = new IntersectionObserver((entries) => {\n      onScreen = entries[0].isIntersecting;\n      if (onScreen && !reduce && !raf) raf = requestAnimationFrame(frame);\n    });\n    io.observe(canvas);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      cleanups.forEach((c) => c());\n    };\n  }, []);\n  return (\n    <section className=\"relative isolate min-h-[640px] overflow-hidden bg-[#13181b]\">\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 -z-10\">\n        <div className=\"absolute inset-0 [background:radial-gradient(90%_70%_at_60%_80%,#1f2a2d,transparent)]\" />\n        <canvas ref={canvasRef} aria-hidden=\"true\" className=\"absolute inset-0 h-full w-full\" />\n        <div className=\"absolute inset-0 [background:radial-gradient(50%_55%_at_22%_30%,rgba(19,24,27,.9),transparent)]\" />\n      </div>\n      <div className=\"mx-auto max-w-5xl px-6 pb-56 pt-20 sm:pt-28\">\n        <p className=\"text-sm font-medium uppercase tracking-[0.2em] text-[#d6be96]\">Marrow and Weft</p>\n        <h1 className=\"mt-4 max-w-xl text-4xl font-semibold leading-[1.08] tracking-tight text-[#f2ede4] sm:text-6xl\">Silk scarves woven and dyed by hand.</h1>\n        <p className=\"mt-5 max-w-lg text-lg leading-relaxed text-[#b8bfbd]\">Small batches from a two-loom studio, each piece numbered and finished with a rolled hem.</p>\n        <a href=\"#\" className=\"mt-8 inline-flex h-12 items-center rounded-full bg-[#d6be96] px-7 text-sm font-semibold text-[#13181b] transition hover:bg-[#e6d3b2] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#d6be96] focus-visible:ring-offset-2 focus-visible:ring-offset-[#13181b]\">See the autumn dye lot</a>\n      </div>\n    </section>\n  );\n}\n"}]}
