{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ring-tower",
  "title": "Ring Tower",
  "description": "A tower of tilted bands wrapped in your images. They crawl around, drag to spin, and neighbors counter-turn with the pointer.",
  "dependencies": [
    "three"
  ],
  "devDependencies": [
    "@types/three"
  ],
  "files": [
    {
      "path": "registry/ring-tower/ring-tower.tsx",
      "content": "\"use client\"\n\nimport { useEffect, useRef } from \"react\"\nimport { cn } from \"@/lib/utils\"\nimport {\n  CanvasTexture,\n  ClampToEdgeWrapping,\n  Color,\n  CylinderGeometry,\n  DoubleSide,\n  Group,\n  LinearFilter,\n  Mesh,\n  MeshBasicMaterial,\n  PerspectiveCamera,\n  Raycaster,\n  RepeatWrapping,\n  Scene,\n  SRGBColorSpace,\n  Vector2,\n  WebGLRenderer,\n  type Texture,\n} from \"three\"\n\nexport type RingTowerTheme = \"light\" | \"dark\" | \"auto\"\n\n/** One ring's own settings. Anything left out follows the tower. */\nexport type RingTowerRing = {\n  /** Images for this ring alone. Default: the tower's `images`. */\n  images?: string[]\n  /**\n   * Which way the ring leans, in degrees around the tower. Default `i * 90`,\n   * a quarter turn from the ring below, so the stack zig-zags.\n   */\n  rotation?: number\n  /** How far the ring leans, in degrees, -45 to 45. Default `14`. */\n  tilt?: number\n  /**\n   * Degrees per second the ring turns around the tower, -180 to 180, so its\n   * lean sweeps round. Default `0`.\n   */\n  spin?: number\n  /**\n   * Crawl speed for this ring, -4 to 4; negative crawls the other way.\n   * Default: the tower's `speed`.\n   */\n  speed?: number\n  /**\n   * Degrees the pointer turns this ring, -90 to 90; the sign picks the\n   * direction. Default: the tower's `parallax`, alternating direction.\n   */\n  parallax?: number\n}\n\nexport type RingTowerOptions = {\n  /**\n   * Image URLs drawn side by side around every band. Cross-origin images\n   * need CORS headers. Empty draws a plain grid band.\n   */\n  images?: string[]\n  /**\n   * Number of stacked rings, 1 to 5. Default `5`. Or one settings object per\n   * ring, from the bottom up, to set each ring's rotation, tilt, spin,\n   * speed, parallax or images; the array's length is the count.\n   */\n  rings?: number | RingTowerRing[]\n  /** How fast the images crawl around the bands. Default `1`, 0 to 4. */\n  speed?: number\n  /** Drag a band to spin the tower, with inertia. Default `true`. */\n  draggable?: boolean\n  /**\n   * How far, in degrees, the pointer turns each band. Neighbors turn the\n   * opposite way. Default `24`, 0 to 90. `0` keeps every band in step.\n   */\n  parallax?: number\n  /**\n   * How far the inside of the bands fades toward the page, 0 to 1: black in\n   * dark mode, white in light mode. Default `0.86`.\n   */\n  backface?: number\n  /** `\"auto\"` follows the page. Default `\"auto\"`. */\n  theme?: RingTowerTheme\n}\n\nexport type RingTowerInstance = {\n  setOptions: (options: Partial<RingTowerOptions>) => void\n  destroy: () => void\n}\n\nexport const DEFAULT_RINGS = 5\nexport const MAX_RINGS = 5\nexport const DEFAULT_SPEED = 1\nexport const DEFAULT_PARALLAX = 24\nexport const DEFAULT_BACKFACE = 0.86\nexport const DEFAULT_TILT = 14\nexport const DEFAULT_SPIN = 0\n\nconst RADIUS = 4\nconst BAND_HEIGHT = 2\nconst SPACING = 3.5\nconst SEGMENTS = 100\nconst STRIP_HEIGHT = 512\nconst CRAWL = 0.012\nconst START_ANGLE = 0.5\nconst DEG = Math.PI / 180\n/** Lean cycle per ring; signs alternate so neighbors counter-turn. */\nconst PARALLAX_FACTORS = [1, -0.75, 1.25, -0.9]\n\nfunction clamp(value: number, min: number, max: number) {\n  return Math.min(max, Math.max(min, value))\n}\n\nfunction numberOr(value: unknown, fallback: number, min: number, max: number) {\n  if (typeof value !== \"number\" || !Number.isFinite(value)) return fallback\n  return clamp(value, min, max)\n}\n\n/** Default rotation for ring `i`: a quarter turn from the one below. */\nexport function defaultRotation(i: number) {\n  return (i * 90) % 360\n}\n\n/** Default parallax for ring `i`: neighbors turn opposite ways. */\nexport function defaultParallax(i: number, parallax = DEFAULT_PARALLAX) {\n  return parallax * PARALLAX_FACTORS[i % PARALLAX_FACTORS.length]!\n}\n\n/** The ring count and each ring's own settings (empty where unset). */\nfunction ringsOf(value: RingTowerOptions[\"rings\"]): RingTowerRing[] {\n  if (Array.isArray(value) && value.length > 0) {\n    return value\n      .slice(0, MAX_RINGS)\n      .map((ring) => (ring && typeof ring === \"object\" ? ring : {}))\n  }\n  const count = Math.round(\n    numberOr(\n      Array.isArray(value) ? undefined : value,\n      DEFAULT_RINGS,\n      1,\n      MAX_RINGS\n    )\n  )\n  return Array.from({ length: count }, () => ({}))\n}\n\nfunction urlsOf(images: unknown): string[] {\n  if (!Array.isArray(images)) return []\n  return images.filter(\n    (url): url is string => typeof url === \"string\" && url.length > 0\n  )\n}\n\n/** Resolves shadcn / next-themes dark mode (`attribute=\"class\"` → `html.dark`). */\nexport function isDarkTheme(): boolean {\n  if (typeof document === \"undefined\") return false\n  const root = document.documentElement\n  if (root.classList.contains(\"dark\")) return true\n  if (root.classList.contains(\"light\")) return false\n  const dataTheme = root.getAttribute(\"data-theme\")\n  if (dataTheme === \"dark\") return true\n  if (dataTheme === \"light\") return false\n  return window.matchMedia(\"(prefers-color-scheme: dark)\").matches\n}\n\nexport function resolveDark(theme: RingTowerTheme): boolean {\n  if (theme === \"dark\") return true\n  if (theme === \"light\") return false\n  return isDarkTheme()\n}\n\nfunction loadImage(url: string) {\n  return new Promise<HTMLImageElement>((resolve, reject) => {\n    const img = new Image()\n    img.crossOrigin = \"anonymous\"\n    img.decoding = \"async\"\n    img.onload = () => resolve(img)\n    img.onerror = () => reject(new Error(`RingTower: failed to load ${url}`))\n    img.src = url\n  })\n}\n\ntype Strip = { canvas: HTMLCanvasElement; aspect: number }\n\n/** Draws the images side by side at one height on a white strip. */\nfunction stitch(images: HTMLImageElement[], maxSize: number): Strip | null {\n  const sizes = images.map((img) => {\n    const aspect = img.naturalWidth / Math.max(1, img.naturalHeight)\n    return { img, width: STRIP_HEIGHT * aspect }\n  })\n  const width = sizes.reduce((sum, s) => sum + s.width, 0)\n  if (width <= 0) return null\n\n  const canvas = document.createElement(\"canvas\")\n  const ctx = canvas.getContext(\"2d\")\n  if (!ctx) return null\n  const scale = Math.min(\n    Math.min(window.devicePixelRatio || 1, 2),\n    maxSize / width,\n    maxSize / STRIP_HEIGHT\n  )\n  canvas.width = Math.max(1, Math.floor(width * scale))\n  canvas.height = Math.max(1, Math.floor(STRIP_HEIGHT * scale))\n  ctx.scale(scale, scale)\n  ctx.fillStyle = \"#ffffff\"\n  ctx.fillRect(0, 0, width, STRIP_HEIGHT)\n  let x = 0\n  for (const s of sizes) {\n    ctx.drawImage(s.img, x, 0, s.width, STRIP_HEIGHT)\n    x += s.width\n  }\n  return { canvas, aspect: width / STRIP_HEIGHT }\n}\n\n/** Plain green grid band, used when no image loads. */\nfunction gridStrip(): Strip | null {\n  const canvas = document.createElement(\"canvas\")\n  canvas.width = 1024\n  canvas.height = 512\n  const ctx = canvas.getContext(\"2d\")\n  if (!ctx) return null\n  const fill = ctx.createLinearGradient(0, 0, 0, 512)\n  fill.addColorStop(0, \"#36C26A\")\n  fill.addColorStop(1, \"#22A653\")\n  ctx.fillStyle = fill\n  ctx.fillRect(0, 0, 1024, 512)\n  ctx.strokeStyle = \"rgba(255, 255, 255, 0.16)\"\n  ctx.lineWidth = 2\n  for (let i = 0; i <= 1024; i += 32) {\n    ctx.beginPath()\n    ctx.moveTo(i, 0)\n    ctx.lineTo(i, 512)\n    ctx.stroke()\n  }\n  for (let i = 0; i <= 512; i += 32) {\n    ctx.beginPath()\n    ctx.moveTo(0, i)\n    ctx.lineTo(1024, i)\n    ctx.stroke()\n  }\n  return { canvas, aspect: 2 }\n}\n\n/**\n * A tower of open, tilted cylinder bands wrapped in a strip of images, after\n * the vuemail.dev hero. Each band leans a quarter turn from the last, so the\n * stack zig-zags. The images crawl around the bands, dragging spins the\n * tower with inertia, and the pointer turns neighboring bands opposite ways.\n * The canvas is transparent; the parent paints the background, and the\n * inside of the bands fades toward black or white with the theme. Pauses\n * off-screen and in hidden tabs; holds still under `prefers-reduced-motion`.\n */\nexport function createRingTower(\n  root: HTMLElement,\n  initial: RingTowerOptions = {}\n): RingTowerInstance | null {\n  let options: RingTowerOptions = { draggable: true, ...initial }\n\n  let renderer: WebGLRenderer\n  try {\n    renderer = new WebGLRenderer({\n      alpha: true,\n      antialias: true,\n      powerPreference: \"high-performance\",\n    })\n  } catch {\n    return null\n  }\n  renderer.setPixelRatio(Math.min(Math.max(1, window.devicePixelRatio), 2))\n  renderer.outputColorSpace = SRGBColorSpace\n  renderer.setClearColor(0x000000, 0)\n  const canvas = renderer.domElement\n  canvas.style.display = \"block\"\n  canvas.style.touchAction = \"pan-y\"\n  root.appendChild(canvas)\n\n  const scene = new Scene()\n  const camera = new PerspectiveCamera(7, 1, 0.01, 1e5)\n  camera.position.set(0, 0, 70)\n  const tower = new Group()\n  tower.rotation.set(-0.2, START_ANGLE, 0.2)\n  scene.add(tower)\n\n  const geometry = new CylinderGeometry(\n    RADIUS,\n    RADIUS,\n    BAND_HEIGHT,\n    SEGMENTS,\n    1,\n    true\n  )\n  const backface = { value: DEFAULT_BACKFACE }\n  let dark = resolveDark(options.theme ?? \"auto\")\n  let darkMix = dark ? 1 : 0\n  const backColor = { value: new Color().setScalar(1 - darkMix) }\n\n  type Band = {\n    index: number\n    mesh: Mesh\n    material: MeshBasicMaterial\n    texture: Texture\n    tiles: number\n  }\n  let bands: Band[] = []\n  // One strip per distinct image list, shared by every ring that shows it.\n  // `base` is null while the images load.\n  type Entry = { base: CanvasTexture | null; tiles: number; token: number }\n  const strips = new Map<string, Entry>()\n  let rings = ringsOf(options.rings)\n  // Kept across rebuilds, so a strip arriving never snaps a ring back.\n  const crawls: number[] = []\n  const turns: number[] = []\n\n  const makeMaterial = (map: Texture) => {\n    const material = new MeshBasicMaterial({\n      map,\n      side: DoubleSide,\n      toneMapped: false,\n    })\n    material.onBeforeCompile = (shader) => {\n      shader.uniforms.uBackface = backface\n      shader.uniforms.uBackColor = backColor\n      shader.fragmentShader = shader.fragmentShader\n        .replace(\n          \"void main() {\",\n          \"uniform float uBackface;\\nuniform vec3 uBackColor;\\nvoid main() {\"\n        )\n        .replace(\n          \"#include <color_fragment>\",\n          `#include <color_fragment>\n          if (!gl_FrontFacing) {\n            diffuseColor.rgb = mix(diffuseColor.rgb, uBackColor, uBackface);\n          }`\n        )\n    }\n    material.customProgramCacheKey = () => \"ring-tower\"\n    return material\n  }\n\n  const clearBands = () => {\n    for (const band of bands) {\n      tower.remove(band.mesh)\n      band.material.dispose()\n      band.texture.dispose()\n    }\n    bands = []\n  }\n\n  // Whole tiles around the band keep the seam invisible; the strip is then\n  // cropped top and bottom to hold its proportions. Returns the tile count.\n  const fit = (texture: Texture, aspect: number) => {\n    const around = (2 * Math.PI * RADIUS) / BAND_HEIGHT\n    const whole = Math.floor(around / aspect)\n    if (whole >= 1) {\n      texture.repeat.set(whole, Math.min(1, (aspect * whole) / around))\n      texture.offset.y = (1 - texture.repeat.y) / 2\n      return whole\n    }\n    texture.repeat.set(around / aspect, 1)\n    texture.offset.y = 0\n    return around / aspect\n  }\n\n  const imagesFor = (ring: RingTowerRing) =>\n    urlsOf(ring.images).length ? urlsOf(ring.images) : urlsOf(options.images)\n  const keyFor = (ring: RingTowerRing) => imagesFor(ring).join(\"\\n\")\n\n  const buildBands = () => {\n    clearBands()\n    const middle = Math.ceil(rings.length / 2) - 1\n    rings.forEach((ring, i) => {\n      const entry = strips.get(keyFor(ring))\n      if (!entry?.base) return\n      // Clones share the image source, so each strip uploads once.\n      const texture = entry.base.clone()\n      const material = makeMaterial(texture)\n      const mesh = new Mesh(geometry, material)\n      mesh.position.set(0, (i - middle) * SPACING, 0)\n      tower.add(mesh)\n      bands.push({ index: i, mesh, material, texture, tiles: entry.tiles })\n    })\n    pose()\n  }\n\n  const setStrip = (key: string, next: Strip | null) => {\n    const entry = strips.get(key)\n    if (!entry || !next) return\n    const texture = new CanvasTexture(next.canvas)\n    texture.wrapS = RepeatWrapping\n    texture.wrapT = ClampToEdgeWrapping\n    texture.generateMipmaps = false\n    texture.minFilter = LinearFilter\n    texture.magFilter = LinearFilter\n    texture.colorSpace = SRGBColorSpace\n    texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy())\n    entry.tiles = fit(texture, next.aspect)\n    entry.base = texture\n    buildBands()\n    wake()\n  }\n\n  let loadToken = 0\n  let layoutKey = \"\"\n  // Loads any image list a ring now needs, drops the ones none show, and\n  // rebuilds the rings when their count or images change.\n  const loadImages = () => {\n    const needed = new Map(rings.map((ring) => [keyFor(ring), imagesFor(ring)]))\n    for (const [key, entry] of strips) {\n      if (needed.has(key)) continue\n      entry.base?.dispose()\n      strips.delete(key)\n    }\n    for (const [key, urls] of needed) {\n      if (strips.has(key)) continue\n      const token = ++loadToken\n      strips.set(key, { base: null, tiles: 1, token })\n      if (urls.length === 0) {\n        setStrip(key, gridStrip())\n        continue\n      }\n      void Promise.allSettled(urls.map(loadImage)).then((results) => {\n        if (destroyed || strips.get(key)?.token !== token) return\n        const loaded = results.flatMap((r) =>\n          r.status === \"fulfilled\" ? [r.value] : []\n        )\n        const next = loaded.length\n          ? stitch(loaded, renderer.capabilities.maxTextureSize)\n          : null\n        setStrip(key, next ?? gridStrip())\n      })\n    }\n    const nextLayout = rings.map(keyFor).join(\"\\0\")\n    if (nextLayout !== layoutKey) {\n      layoutKey = nextLayout\n      buildBands()\n    }\n  }\n\n  // Each ring's lean, heading and spin, read live so sliders need no rebuild.\n  const pose = () => {\n    for (const band of bands) {\n      const ring = rings[band.index] ?? {}\n      const rotation = numberOr(\n        ring.rotation,\n        defaultRotation(band.index),\n        -3600,\n        3600\n      )\n      const tilt = numberOr(ring.tilt, DEFAULT_TILT, -45, 45)\n      band.mesh.rotation.set(\n        0,\n        rotation * DEG + (turns[band.index] ?? 0),\n        tilt * DEG\n      )\n    }\n  }\n\n  const size = { width: 0, height: 0 }\n  const current = new Vector2()\n  /**\n   * Sizes the renderer to the root; true when the canvas changed. Setting\n   * the same size still clears the canvas, so it only sets a real change.\n   */\n  const resize = () => {\n    const { width, height } = root.getBoundingClientRect()\n    size.width = width\n    size.height = height\n    if (width <= 0 || height <= 0) return false\n    renderer.getSize(current)\n    if (current.x === width && current.y === height) return false\n    renderer.setSize(width, height)\n    camera.aspect = width / height\n    camera.updateProjectionMatrix()\n    wake()\n    return true\n  }\n\n  const mqReduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\")\n  let onScreen = true\n  let raf = 0\n  let destroyed = false\n  let lost = false\n  let last = 0\n  let angle = START_ANGLE\n  let velocity = 0\n  let dragging = false\n  let dragX = 0\n  let pointerX = 0\n  let pointerTarget = 0\n\n  const visible = () => onScreen && document.visibilityState !== \"hidden\"\n\n  function wake() {\n    if (raf || destroyed || lost) return\n    last = performance.now()\n    raf = requestAnimationFrame(tick)\n  }\n\n  const tick = (now: number) => {\n    raf = 0\n    if (lost) return\n    const dt = Math.min(0.05, Math.max(0, (now - last) / 1000))\n    last = now\n    if (!visible()) return\n    const still = mqReduce.matches\n\n    const towerSpeed = numberOr(options.speed, DEFAULT_SPEED, 0, 4)\n    const towerParallax = numberOr(options.parallax, DEFAULT_PARALLAX, 0, 90)\n    let spinning = false\n    if (!still) {\n      for (const band of bands) {\n        const ring = rings[band.index] ?? {}\n        const i = band.index\n        const speed = numberOr(ring.speed, towerSpeed, -4, 4)\n        // In texture units, so wrapping at 1 never shows a jump.\n        const crawl = (crawls[i] ?? 0) + dt * CRAWL * band.tiles * speed\n        crawls[i] = crawl - Math.floor(crawl)\n        const spin = numberOr(ring.spin, DEFAULT_SPIN, -180, 180)\n        if (spin !== 0) {\n          turns[i] = ((turns[i] ?? 0) + spin * DEG * dt) % (Math.PI * 2)\n          spinning = true\n        }\n      }\n    }\n    pose()\n    if (!dragging) {\n      if (still) velocity = 0\n      angle += velocity * dt\n      velocity *= Math.pow(0.95, dt * 60)\n      if (Math.abs(velocity) < 1e-4) velocity = 0\n    }\n    tower.rotation.y = angle\n\n    const ease = 1 - Math.exp(-dt * 4)\n    const target = still ? 0 : pointerTarget\n    pointerX += (target - pointerX) * ease\n    for (const band of bands) {\n      const ring = rings[band.index] ?? {}\n      const parallax = numberOr(\n        ring.parallax,\n        defaultParallax(band.index, towerParallax),\n        -90,\n        90\n      )\n      band.texture.offset.x =\n        (crawls[band.index] ?? 0) + (pointerX * parallax * band.tiles) / 360\n    }\n\n    darkMix += ((dark ? 1 : 0) - darkMix) * (1 - Math.exp(-dt * 6))\n    if (Math.abs((dark ? 1 : 0) - darkMix) < 1e-3) darkMix = dark ? 1 : 0\n    backColor.value.setScalar(1 - darkMix)\n\n    if (size.width > 0 && size.height > 0) renderer.render(scene, camera)\n\n    const moving =\n      (!still &&\n        (towerSpeed !== 0 || spinning || rings.some((r) => r.speed))) ||\n      dragging ||\n      velocity !== 0 ||\n      Math.abs(target - pointerX) > 1e-4 ||\n      darkMix !== (dark ? 1 : 0)\n    if (moving) raf = requestAnimationFrame(tick)\n  }\n\n  const raycaster = new Raycaster()\n  const ndc = new Vector2()\n  const hits = (e: PointerEvent) => {\n    const rect = canvas.getBoundingClientRect()\n    if (rect.width === 0 || rect.height === 0) return false\n    ndc.set(\n      ((e.clientX - rect.left) / rect.width) * 2 - 1,\n      -((e.clientY - rect.top) / rect.height) * 2 + 1\n    )\n    raycaster.setFromCamera(ndc, camera)\n    return raycaster.intersectObjects(tower.children, false).length > 0\n  }\n\n  const setCursor = (value: string) => {\n    if (canvas.style.cursor !== value) canvas.style.cursor = value\n  }\n\n  const onWindowMove = (e: PointerEvent) => {\n    const rect = root.getBoundingClientRect()\n    if (rect.width <= 0 || rect.height <= 0) return\n    const x = (e.clientX - rect.left) / rect.width\n    const y = (e.clientY - rect.top) / rect.height\n    const inside = x >= 0 && x <= 1 && y >= 0 && y <= 1\n    pointerTarget = inside ? clamp(x * 2 - 1, -1, 1) : 0\n    wake()\n  }\n  window.addEventListener(\"pointermove\", onWindowMove, { passive: true })\n\n  const onDown = (e: PointerEvent) => {\n    if (options.draggable === false || !hits(e)) return\n    dragging = true\n    dragX = e.clientX\n    velocity = 0\n    canvas.setPointerCapture(e.pointerId)\n    setCursor(\"grabbing\")\n    wake()\n  }\n  const onMove = (e: PointerEvent) => {\n    if (dragging) {\n      const delta =\n        ((e.clientX - dragX) / Math.max(1, size.width)) * Math.PI * 2\n      angle += delta\n      velocity = delta * 60\n      dragX = e.clientX\n      return\n    }\n    setCursor(options.draggable !== false && hits(e) ? \"grab\" : \"\")\n  }\n  const onUp = (e: PointerEvent) => {\n    if (!dragging) return\n    dragging = false\n    if (canvas.hasPointerCapture(e.pointerId)) {\n      canvas.releasePointerCapture(e.pointerId)\n    }\n    setCursor(hits(e) ? \"grab\" : \"\")\n    wake()\n  }\n  const onLeave = () => {\n    if (!dragging) setCursor(\"\")\n  }\n  canvas.addEventListener(\"pointerdown\", onDown)\n  canvas.addEventListener(\"pointermove\", onMove)\n  canvas.addEventListener(\"pointerup\", onUp)\n  canvas.addEventListener(\"pointercancel\", onUp)\n  canvas.addEventListener(\"pointerleave\", onLeave)\n\n  // Resizing cleared the canvas; draw the current pose now, or it shows\n  // blank for a frame.\n  const ro = new ResizeObserver(() => {\n    if (resize() && !destroyed && !lost) renderer.render(scene, camera)\n  })\n  ro.observe(root)\n  const io = new IntersectionObserver(([entry]) => {\n    onScreen = entry?.isIntersecting ?? true\n    wake()\n  })\n  io.observe(root)\n  const onVisibility = () => wake()\n  document.addEventListener(\"visibilitychange\", onVisibility)\n  const onReduce = () => wake()\n  mqReduce.addEventListener(\"change\", onReduce)\n\n  // three restores its own state; the loop just has to stop and resume.\n  const onLost = () => {\n    lost = true\n    cancelAnimationFrame(raf)\n    raf = 0\n  }\n  const onRestored = () => {\n    if (destroyed) return\n    lost = false\n    for (const { base } of strips.values()) if (base) base.needsUpdate = true\n    wake()\n  }\n  canvas.addEventListener(\"webglcontextlost\", onLost)\n  canvas.addEventListener(\"webglcontextrestored\", onRestored)\n\n  const syncTheme = () => {\n    const next = resolveDark(options.theme ?? \"auto\")\n    if (next === dark) return\n    dark = next\n    wake()\n  }\n  const mo = new MutationObserver(syncTheme)\n  mo.observe(document.documentElement, {\n    attributes: true,\n    attributeFilter: [\"class\", \"data-theme\", \"style\"],\n  })\n  const mqDark = window.matchMedia(\"(prefers-color-scheme: dark)\")\n  mqDark.addEventListener(\"change\", syncTheme)\n\n  const applyBackface = () => {\n    backface.value = numberOr(options.backface, DEFAULT_BACKFACE, 0, 1)\n  }\n\n  applyBackface()\n  resize()\n  loadImages()\n  wake()\n\n  return {\n    setOptions(next) {\n      options = { ...options, ...next }\n      rings = ringsOf(options.rings)\n      applyBackface()\n      if (options.draggable === false) {\n        dragging = false\n        setCursor(\"\")\n      }\n      loadImages()\n      syncTheme()\n      wake()\n    },\n    destroy() {\n      destroyed = true\n      cancelAnimationFrame(raf)\n      raf = 0\n      ro.disconnect()\n      io.disconnect()\n      mo.disconnect()\n      document.removeEventListener(\"visibilitychange\", onVisibility)\n      mqReduce.removeEventListener(\"change\", onReduce)\n      mqDark.removeEventListener(\"change\", syncTheme)\n      window.removeEventListener(\"pointermove\", onWindowMove)\n      canvas.removeEventListener(\"pointerdown\", onDown)\n      canvas.removeEventListener(\"pointermove\", onMove)\n      canvas.removeEventListener(\"pointerup\", onUp)\n      canvas.removeEventListener(\"pointercancel\", onUp)\n      canvas.removeEventListener(\"pointerleave\", onLeave)\n      canvas.removeEventListener(\"webglcontextlost\", onLost)\n      canvas.removeEventListener(\"webglcontextrestored\", onRestored)\n      clearBands()\n      for (const { base } of strips.values()) base?.dispose()\n      strips.clear()\n      geometry.dispose()\n      renderer.dispose()\n      renderer.forceContextLoss()\n      canvas.remove()\n    },\n  }\n}\n\nexport type RingTowerProps = RingTowerOptions & {\n  className?: string\n}\n\n/**\n * A tower of tilted bands wrapped in your images. The images crawl around\n * the bands, dragging spins the tower, and the pointer turns neighboring\n * bands opposite ways. Pass `rings` an array to set each ring's rotation,\n * tilt, spin, speed, parallax or images. Transparent; the parent paints the\n * background. Theme-aware.\n */\nexport function RingTower({\n  className,\n  images,\n  rings = DEFAULT_RINGS,\n  speed = DEFAULT_SPEED,\n  draggable = true,\n  parallax = DEFAULT_PARALLAX,\n  backface = DEFAULT_BACKFACE,\n  theme = \"auto\",\n}: RingTowerProps) {\n  const rootRef = useRef<HTMLDivElement>(null)\n  const instanceRef = useRef<RingTowerInstance | null>(null)\n\n  useEffect(() => {\n    const root = rootRef.current\n    if (!root) return\n    instanceRef.current = createRingTower(root, {\n      images,\n      rings,\n      speed,\n      draggable,\n      parallax,\n      backface,\n      theme,\n    })\n    return () => {\n      instanceRef.current?.destroy()\n      instanceRef.current = null\n    }\n    // Engine reads live options via setOptions; mount once.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [])\n\n  useEffect(() => {\n    instanceRef.current?.setOptions({\n      images,\n      rings,\n      speed,\n      draggable,\n      parallax,\n      backface,\n      theme,\n    })\n  }, [images, rings, speed, draggable, parallax, backface, theme])\n\n  return (\n    <div\n      ref={rootRef}\n      data-slot=\"ring-tower\"\n      aria-hidden\n      className={cn(\n        \"absolute inset-0 overflow-hidden rounded-[inherit] [mask-image:linear-gradient(#000,#000)]\",\n        className\n      )}\n    />\n  )\n}\n",
      "type": "registry:ui",
      "target": "components/ui/ring-tower.tsx"
    }
  ],
  "type": "registry:ui"
}