{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "filings",
  "type": "registry:ui",
  "title": "Filings",
  "description": "An iron-filing field: a grid of short segments aligning to a slow magnetic-dipole field when idle and bending toward the cursor, brightening from silver to white. Original OGL fragment shader, one draw call, offscreen-paused and reduced-motion-safe; the field idles on its own when untouched.",
  "dependencies": [
    "ogl"
  ],
  "registryDependencies": [
    "https://crucibleui.com/r/ogl-canvas.json",
    "https://crucibleui.com/r/use-visibility-pause.json",
    "https://crucibleui.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/default/backgrounds/filings/filings.tsx",
      "type": "registry:ui",
      "target": "components/crucible/filings.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { OglCanvas } from \"@/lib/ogl-canvas\";\n\nexport interface FilingsProps {\n  /**\n   * Two tones: `[cool, warm]`. `cool` is the resting silver of aligned\n   * filings; `warm` is the brighter white they glow near the cursor.\n   * Any hex string.\n   */\n  colors?: [string, string];\n  /** Grid density (square cells stacked across the container height), clamped 8–40. Default 22. */\n  density?: number;\n  /** Idle-field animation speed multiplier. 1 = default. Default 1. */\n  speed?: number;\n  /** Stroke brightness / glow. 1 = default. Default 1. */\n  intensity?: number;\n  /** Freeze the animation, holding the current frame. */\n  paused?: boolean;\n  /**\n   * Idle autoplay: after ~1.5s with no pointer present, a seeded ghost drifts\n   * slowly across the field and bends the filings, so thumbnails and heroes\n   * never look still; a real pointer takes over instantly. Never runs under\n   * reduced motion. Default true.\n   */\n  idle?: boolean;\n  /** Extra classes for the wrapper. Positioned `absolute inset-0 -z-10`. */\n  className?: string;\n}\n\nconst DEFAULT_COLORS: [string, string] = [\n  \"#a1a1aa\", // silver — resting\n  \"#fafafa\", // white — alignment glow\n];\n\n/** Hex → [r,g,b] in 0–1. Accepts #rgb / #rrggbb. */\nfunction hexToRgb(hex: string): [number, number, number] {\n  let h = hex.replace(\"#\", \"\").trim();\n  if (h.length === 3) {\n    h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];\n  }\n  const int = parseInt(h, 16);\n  if (Number.isNaN(int) || h.length !== 6) return [0.63, 0.63, 0.67];\n  return [((int >> 16) & 255) / 255, ((int >> 8) & 255) / 255, (int & 255) / 255];\n}\n\n/**\n * Original iron-filings fragment shader. The plane is tiled into a grid; each\n * cell draws one short line segment (an SDF capsule) whose orientation tracks a\n * slowly-rotating magnetic-dipole field when idle and bends radially toward the\n * pointer near it. Alignment strength doubles as brightness — cells near the\n * cursor glow from resting silver to bright white, with a radial\n * magnetization wave rippling out from the pointer. One draw call, no\n * derivatives. GLSL ES 1.00.\n */\nconst FRAGMENT = /* glsl */ `\nprecision highp float;\n\nvarying vec2 vUv;\n\nuniform float uTime;\nuniform vec2 uResolution;\nuniform vec2 uPointer;\nuniform float uPointerActive;\n\nuniform vec3 uColorCool; // resting silver\nuniform vec3 uColorWarm; // alignment-glow white\nuniform float uDensity;\nuniform float uSpeed;\nuniform float uIntensity;\n\n// Distance from p to the segment a—b.\nfloat segDist(vec2 p, vec2 a, vec2 b) {\n  vec2 pa = p - a;\n  vec2 ba = b - a;\n  float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);\n  return length(pa - ba * h);\n}\n\n// Ideal magnetic-dipole field at p from a dipole at pos with moment m.\n// Direction (~1/r^3 magnitude, unused here) gives the field-line tangent.\nvec2 dipoleField(vec2 p, vec2 pos, vec2 m) {\n  vec2 r = p - pos;\n  float d2 = dot(r, r) + 0.0009;\n  float d = sqrt(d2);\n  vec2 rh = r / d;\n  return (3.0 * dot(m, rh) * rh - m) / (d2 * d);\n}\n\nvoid main() {\n  vec2 uv = vUv;\n  float aspect = uResolution.x / max(uResolution.y, 1.0);\n  float t = uTime * uSpeed;\n  vec2 asp = vec2(aspect, 1.0);\n\n  float dens = clamp(uDensity, 8.0, 40.0);\n\n  // Aspect-corrected grid space (one grid unit is square on screen).\n  vec2 q = uv * asp;\n  vec2 gp = q * dens;\n  vec2 cid = floor(gp);\n  vec2 f = fract(gp) - 0.5;            // local coords within the cell\n  vec2 cCenter = (cid + 0.5) / dens;   // cell center in q-space\n\n  // Slowly-rotating, gently-drifting dipole for the idle field pattern.\n  float a = t * 0.15;\n  vec2 m = vec2(cos(a), sin(a));\n  vec2 dpos = vec2(0.5 * aspect, 0.5) + 0.12 * vec2(cos(t * 0.10), sin(t * 0.13));\n  vec2 fieldDir = normalize(dipoleField(cCenter, dpos, m));\n\n  // Pointer influence, aspect-corrected.\n  vec2 pw = uPointer * asp;\n  vec2 toP = pw - cCenter;\n  float pd = length(toP);\n  // Released when the pointer leaves, so the idle frame is the pure dipole field.\n  float cursorInf = exp(-pd * pd * 5.0) * uPointerActive;\n  vec2 cDir = toP / (pd + 1e-4);\n\n  // Blend idle field with the radial cursor pull.\n  vec2 dir = normalize(mix(fieldDir, cDir, cursorInf));\n\n  // One short segment centered in the cell, oriented along dir.\n  float hl = 0.34;\n  vec2 e = dir * hl;\n  float dist = segDist(f, -e, e);\n  float th = 0.075;\n  float seg = smoothstep(th, th * 0.35, dist);\n\n  // Alignment/brightness: a magnetization wave rides out from the pointer.\n  float wave = 0.6 + 0.4 * sin(pd * 12.0 - t * 2.5);\n  float warmth = clamp(cursorInf * wave, 0.0, 1.0);\n\n  vec3 stroke = mix(uColorCool, uColorWarm, warmth);\n\n  // Near-black plate with a faint cool lift toward the bottom.\n  vec3 col = mix(vec3(0.018, 0.016, 0.030), uColorCool * 0.05, pow(1.0 - uv.y, 1.6));\n\n  col += stroke * seg * uIntensity;\n  // Soft glow halo pooling under the cursor.\n  col += uColorWarm * cursorInf * cursorInf * 0.06;\n\n  // Film-grain dithering to defeat banding.\n  float grain = fract(sin(dot(gl_FragCoord.xy, vec2(12.9898, 78.233)) + fract(t) * 43.0) * 43758.5453) - 0.5;\n  col += grain * (1.6 / 255.0);\n\n  gl_FragColor = vec4(max(col, 0.0), 1.0);\n}\n`;\n\n/**\n * Filings — an iron-filing field. A grid of short line segments aligns to a\n * slowly-rotating magnetic-dipole field when idle and bends toward the cursor\n * like filings around a magnet, brightening from resting silver to white\n * where the field is strongest. Built on the `ogl-canvas` harness: one draw\n * call, offscreen-paused, reduced-motion-safe. Drop it inside any `relative`\n * container; it fills and sits behind content.\n */\nexport function Filings({\n  colors = DEFAULT_COLORS,\n  density = 22,\n  speed = 1,\n  intensity = 1,\n  paused = false,\n  idle = true,\n  className,\n}: FilingsProps) {\n  const uniforms = React.useMemo(\n    () => ({\n      uColorCool: { value: hexToRgb(colors[0]) },\n      uColorWarm: { value: hexToRgb(colors[1]) },\n      uDensity: { value: density },\n      uSpeed: { value: speed },\n      uIntensity: { value: intensity },\n    }),\n    [colors, density, speed, intensity]\n  );\n\n  return (\n    <OglCanvas\n      aria-hidden\n      data-crucible=\"filings\"\n      className={cn(\"absolute inset-0 -z-10\", className)}\n      fragment={FRAGMENT}\n      uniforms={uniforms}\n      paused={paused}\n      ghost={idle}\n      reducedMotionTime={3}\n    />\n  );\n}\n"
    }
  ]
}