{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "thread-lines",
  "type": "registry:ui",
  "title": "Thread Lines",
  "description": "Interlace's own backdrop: a loose bundle of threads running across a section, crossing and parting the way strands do in a weave, with a small glint of light travelling along each one. It is the brand mark (two strands, interlaced) at the scale of a page.",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "decorative",
    "effect"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/effects/thread-lines.tsx",
      "target": "components/ui/effects/thread-lines.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/thread-lines v1.0.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/thread-lines\n// What changed since: https://ds.interlace.tools/c/thread-lines#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — ThreadLines\n *\n * Interlace's own backdrop: a loose bundle of threads running across a\n * section, crossing and parting the way strands do in a weave, with a small\n * glint of light travelling along each one. It is the brand mark (two\n * strands, interlaced) at the scale of a page.\n *\n * ## How it is drawn\n *\n * The threads are generated, not hand-drawn: each is a smooth curve through\n * evenly spaced points whose heights come from a seeded random sequence, so\n * the same `seed` always draws the same bundle, on the server and in the\n * browser alike. Strokes alternate between the two strand tokens\n * (`--strand-a`, `--strand-b`) and keep a hairline width at any size\n * (`vector-effect: non-scaling-stroke`).\n *\n * ## Motion\n *\n * The glint is a short dash moved along each path with the Web Animations\n * API, so the component ships no keyframes. Each thread takes 6 to 11\n * seconds and they are offset so no two glints line up. The loop pauses out\n * of view. Under `prefers-reduced-motion: reduce` the threads are drawn and\n * nothing travels.\n *\n * | Rule | Concept                 | Where in this file                                   |\n * | ---- | ----------------------- | ---------------------------------------------------- |\n * | R4   | Extends native el       | `svg` props, minus children                           |\n * | R6   | data-slot per part      | thread-lines / -thread / -glint                       |\n * | R7   | cn + ...rest            | `cn(…, className)` + `{...props}`                     |\n * | R19  | Tokens only             | `--strand-a`, `--strand-b`                            |\n * | R23  | CLS=0                   | `absolute inset-0`, never in flow                     |\n * | R25  | Client component        | the glint needs `Element.animate`                     |\n */\n\nimport { cn } from '@/lib/utils';\nimport { useReducedMotion } from '@/hooks/use-reduced-motion';\n\nconst W = 1000;\nconst H = 400;\n\n/** Mulberry32: small, fast, and identical on every JS engine. */\nfunction seeded(seed: number) {\n  let a = seed >>> 0;\n  return () => {\n    a = (a + 0x6d2b79f5) >>> 0;\n    let t = a;\n    t = Math.imul(t ^ (t >>> 15), t | 1);\n    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n  };\n}\n\n/** A smooth path through points (Catmull-Rom converted to cubic Béziers). */\nfunction smoothPath(points: ReadonlyArray<readonly [number, number]>): string {\n  let d = `M${points[0]![0]} ${points[0]![1]}`;\n  for (let i = 0; i < points.length - 1; i++) {\n    const p0 = points[i - 1] ?? points[i]!;\n    const p1 = points[i]!;\n    const p2 = points[i + 1]!;\n    const p3 = points[i + 2] ?? p2;\n    const c1x = p1[0] + (p2[0] - p0[0]) / 6;\n    const c1y = p1[1] + (p2[1] - p0[1]) / 6;\n    const c2x = p2[0] - (p3[0] - p1[0]) / 6;\n    const c2y = p2[1] - (p3[1] - p1[1]) / 6;\n    d += ` C${c1x.toFixed(1)} ${c1y.toFixed(1)} ${c2x.toFixed(1)} ${c2y.toFixed(1)} ${p2[0]} ${p2[1].toFixed(1)}`;\n  }\n  return d;\n}\n\nexport function threadPaths(count: number, seed: number): string[] {\n  const rand = seeded(seed);\n  const steps = 6;\n  return Array.from({ length: count }, (_, i) => {\n    // Each thread has a home height; the curve wanders around it, so the\n    // bundle reads as parallel strands that cross, not as a scribble.\n    const home = H * (0.25 + (0.5 * (i + 0.5)) / count);\n    const points = Array.from({ length: steps + 1 }, (_, s) => {\n      const x = (W * s) / steps;\n      const y = home + (rand() - 0.5) * H * 0.45;\n      return [x, y] as const;\n    });\n    return smoothPath(points);\n  });\n}\n\nexport interface ThreadLinesProps\n  extends Omit<React.ComponentPropsWithoutRef<'svg'>, 'children' | 'aria-hidden'> {\n  /** Number of threads. @default 8 */\n  count?: number;\n  /** Same seed, same bundle. Change it to get a different weave. @default 7 */\n  seed?: number;\n  /** Thread opacity, 0 to 1. @default 0.35 */\n  opacity?: number;\n  /** Set false to keep the glints still even when motion is allowed. @default true */\n  animated?: boolean;\n}\n\nexport function ThreadLines({\n  count = 8,\n  seed = 7,\n  opacity = 0.35,\n  animated = true,\n  className,\n  ...props\n}: ThreadLinesProps) {\n  const ref = React.useRef<SVGSVGElement>(null);\n  const reduced = useReducedMotion();\n  const moving = animated && !reduced;\n  const paths = React.useMemo(() => threadPaths(Math.max(1, count), seed), [count, seed]);\n\n  React.useEffect(() => {\n    const svg = ref.current;\n    if (!svg || !moving) return;\n    const glints = Array.from(svg.querySelectorAll<SVGPathElement>('[data-slot=\"thread-lines-glint\"]'));\n    if (!glints.every((g) => typeof g.animate === 'function')) return;\n    const animations = glints.map((glint, i) =>\n      glint.animate([{ strokeDashoffset: 100 }, { strokeDashoffset: -12 }], {\n        duration: 6000 + ((i * 1700) % 5000),\n        delay: -((i * 2300) % 6000),\n        iterations: Infinity,\n        easing: 'linear',\n      }),\n    );\n    const io =\n      typeof IntersectionObserver === 'undefined'\n        ? null\n        : new IntersectionObserver(([entry]) => {\n            for (const a of animations) {\n              if (entry?.isIntersecting) a.play();\n              else a.pause();\n            }\n          });\n    io?.observe(svg);\n    return () => {\n      io?.disconnect();\n      for (const a of animations) a.cancel();\n    };\n  }, [moving, paths]);\n\n  return (\n    <svg\n      ref={ref}\n      data-slot=\"thread-lines\"\n      viewBox={`0 0 ${W} ${H}`}\n      preserveAspectRatio=\"none\"\n      fill=\"none\"\n      className={cn('pointer-events-none absolute inset-0 size-full', className)}\n      {...props}\n      aria-hidden\n      focusable=\"false\"\n    >\n      {paths.map((d, i) => {\n        const stroke = i % 2 === 0 ? 'var(--strand-a)' : 'var(--strand-b)';\n        return (\n          <g key={i}>\n            <path\n              data-slot=\"thread-lines-thread\"\n              d={d}\n              stroke={stroke}\n              strokeOpacity={opacity}\n              strokeWidth={1}\n              vectorEffect=\"non-scaling-stroke\"\n            />\n            {moving ? (\n              <path\n                data-slot=\"thread-lines-glint\"\n                d={d}\n                pathLength={100}\n                stroke={stroke}\n                strokeWidth={2}\n                strokeLinecap=\"round\"\n                strokeDasharray=\"6 106\"\n                strokeDashoffset={100}\n                vectorEffect=\"non-scaling-stroke\"\n              />\n            ) : null}\n          </g>\n        );\n      })}\n    </svg>\n  );\n}\n"
    }
  ],
  "meta": {
    "tier": "effect",
    "client": true,
    "minViewport": null,
    "loading": false,
    "version": "1.0.0",
    "since": null
  },
  "docs": "## @interlace/thread-lines\n\nInstalled to `components/ui/effects/thread-lines.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/effects/thread-lines';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/thread-lines\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
