{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "curtain-mixed",
  "type": "registry:component",
  "title": "Curtain Mixed",
  "description": "A mosaic of tiles that wipe away row by row, each row in the opposite direction of the one before, in a snaking order.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "transitions",
    "curtain",
    "tiles",
    "mosaic",
    "wipe",
    "reveal",
    "stagger"
  ],
  "docs": "https://hyperblur.dev/effects/curtain-mixed",
  "files": [
    {
      "path": "registry/hyperblur/curtain-mixed.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/curtain-mixed.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type CurtainMixedTrigger = \"mount\" | \"view\" | \"manual\";\n\nexport interface CurtainMixedProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\" | \"color\"> {\n  children?: React.ReactNode;\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  trigger?: CurtainMixedTrigger;\n  duration?: number;\n  color?: string;\n  accent?: string;\n  direction?: \"horizontal\" | \"vertical\";\n  rows?: number;\n  cols?: number;\n  stagger?: number;\n  replay?: string | number;\n  closeAfter?: number;\n  loop?: boolean;\n}\n\nconst css = `\n.hb-zy4 {\n  position: relative;\n  overflow: hidden;\n  isolation: isolate;\n  box-sizing: border-box;\n  font-family: inherit;\n}\n.hb-zy4 *, .hb-zy4 *::before, .hb-zy4 *::after { box-sizing: border-box; }\n.hb-zy4-c { position: relative; z-index: 0; height: 100%; }\n.hb-zy4-k {\n  position: absolute;\n  inset: 0;\n  z-index: 1;\n  display: grid;\n  grid-template-columns: repeat(var(--hb-zy4-x), minmax(0, 1fr));\n  grid-template-rows: repeat(var(--hb-zy4-y), minmax(0, 1fr));\n  pointer-events: none;\n}\n.hb-zy4[data-open=\"false\"] .hb-zy4-k { pointer-events: auto; }\n.hb-zy4-t {\n  margin: -0.5px;\n  background:\n    linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0) 55%),\n    var(--hb-zy4-f);\n  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.05);\n  clip-path: inset(0 0 0 0);\n  transition: clip-path var(--hb-zy4-d) cubic-bezier(0.83, 0, 0.17, 1);\n  transition-delay: calc(var(--hb-zy4-j) * var(--hb-zy4-s));\n}\n.hb-zy4[data-open=\"true\"] .hb-zy4-t { transition-delay: calc(var(--hb-zy4-i) * var(--hb-zy4-s)); }\n.hb-zy4[data-open=\"true\"] .hb-zy4-t[data-way=\"r\"] { clip-path: inset(0 0 0 100%); }\n.hb-zy4[data-open=\"true\"] .hb-zy4-t[data-way=\"l\"] { clip-path: inset(0 100% 0 0); }\n.hb-zy4[data-open=\"true\"] .hb-zy4-t[data-way=\"d\"] { clip-path: inset(100% 0 0 0); }\n.hb-zy4[data-open=\"true\"] .hb-zy4-t[data-way=\"u\"] { clip-path: inset(0 0 100% 0); }\n.hb-zy4[data-instant=\"true\"] .hb-zy4-t { transition: none !important; }\n.hb-zy4-s {\n  display: grid;\n  min-height: 220px;\n  place-content: center;\n  gap: 6px;\n  padding: 24px;\n  text-align: center;\n  color: #ededed;\n  background:\n    radial-gradient(circle at 20% 30%, rgba(255, 92, 138, 0.5), transparent 40%),\n    radial-gradient(circle at 80% 70%, rgba(47, 123, 255, 0.55), transparent 45%),\n    #0d0d12;\n}\n.hb-zy4-s small {\n  font-size: 11px;\n  letter-spacing: 0.16em;\n  text-transform: uppercase;\n  color: rgba(237, 237, 237, 0.6);\n}\n.hb-zy4-s strong { font-size: 26px; line-height: 1.1; font-weight: 600; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-zy4-t { transition: none !important; }\n}\n`;\n\nfunction useCurtain(\n  open: boolean | undefined,\n  defaultOpen: boolean,\n  onOpenChange: ((open: boolean) => void) | undefined,\n  trigger: CurtainMixedTrigger,\n  replay: string | number | undefined,\n  closeAfter: number | undefined,\n  loop: boolean,\n  total: number,\n) {\n  const ref = React.useRef<HTMLDivElement>(null);\n  const controlled = open !== undefined;\n  const [inner, setInner] = React.useState(defaultOpen);\n  const [instant, setInstant] = React.useState(false);\n  const isOpen = controlled ? open : inner;\n  const live = React.useRef({ controlled, onOpenChange, isOpen });\n  const opened = React.useRef(defaultOpen);\n  const prevReplay = React.useRef(replay);\n\n  React.useEffect(() => {\n    live.current = { controlled, onOpenChange, isOpen };\n    if (isOpen) opened.current = true;\n  });\n\n  const setOpen = React.useCallback((next: boolean) => {\n    if (live.current.isOpen === next) return;\n    live.current.isOpen = next;\n    if (!live.current.controlled) setInner(next);\n    live.current.onOpenChange?.(next);\n  }, []);\n\n  React.useEffect(() => {\n    if (trigger !== \"mount\") return;\n    let b = 0;\n    const a = requestAnimationFrame(() => {\n      b = requestAnimationFrame(() => setOpen(true));\n    });\n    return () => {\n      cancelAnimationFrame(a);\n      cancelAnimationFrame(b);\n    };\n  }, [trigger, setOpen]);\n\n  React.useEffect(() => {\n    if (trigger !== \"view\") return;\n    const el = ref.current;\n    if (!el || typeof IntersectionObserver === \"undefined\") return;\n    const io = new IntersectionObserver(\n      (entries) => {\n        if (!entries.some((e) => e.isIntersecting)) return;\n        setOpen(true);\n        io.disconnect();\n      },\n      { threshold: 0.3 },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, [trigger, setOpen]);\n\n  React.useEffect(() => {\n    if (prevReplay.current === replay) return;\n    prevReplay.current = replay;\n    let b = 0;\n    let c = 0;\n    const a = requestAnimationFrame(() => {\n      setInstant(true);\n      setOpen(false);\n      b = requestAnimationFrame(() => {\n        c = requestAnimationFrame(() => {\n          setInstant(false);\n          setOpen(true);\n        });\n      });\n    });\n    return () => {\n      cancelAnimationFrame(a);\n      cancelAnimationFrame(b);\n      cancelAnimationFrame(c);\n    };\n  }, [replay, setOpen]);\n\n  React.useEffect(() => {\n    if (instant) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    let t = 0;\n    if (isOpen && closeAfter !== undefined) {\n      t = window.setTimeout(() => setOpen(false), total + closeAfter);\n    } else if (!isOpen && loop && opened.current) {\n      t = window.setTimeout(() => setOpen(true), total + 800);\n    }\n    return () => window.clearTimeout(t);\n  }, [isOpen, instant, closeAfter, loop, total, setOpen]);\n\n  return { ref, isOpen, instant };\n}\n\nfunction mix(i: number) {\n  return (Math.imul(i + 1, 2654435761) >>> 0) ^ ((i + 7) * 40503);\n}\n\nexport function CurtainMixed({\n  children,\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  trigger = \"mount\",\n  duration = 650,\n  color = \"#141416\",\n  accent = \"#2f7bff\",\n  direction = \"horizontal\",\n  rows = 4,\n  cols = 6,\n  stagger = 45,\n  replay,\n  closeAfter,\n  loop = false,\n  className = \"\",\n  style,\n  ...rest\n}: CurtainMixedProps) {\n  const ny = Math.max(1, Math.min(16, Math.round(rows)));\n  const nx = Math.max(1, Math.min(16, Math.round(cols)));\n  const last = nx - 1 + ny - 1;\n  const total = duration + stagger * last;\n  const { ref, isOpen, instant } = useCurtain(\n    open,\n    defaultOpen,\n    onOpenChange,\n    trigger,\n    replay,\n    closeAfter,\n    loop,\n    total,\n  );\n\n  const tiles = Array.from({ length: nx * ny }, (_, n) => {\n    const r = Math.floor(n / nx);\n    const c = n % nx;\n    const h = mix(n) >>> 0;\n    const order =\n      direction === \"vertical\" ? c + (c % 2 === 0 ? r : ny - 1 - r) : r + (r % 2 === 0 ? c : nx - 1 - c);\n    const way =\n      direction === \"vertical\" ? (c % 2 === 0 ? \"d\" : \"u\") : r % 2 === 0 ? \"r\" : \"l\";\n    const fill =\n      h % 9 === 0\n        ? \"color-mix(in srgb, var(--hb-zy4-acc) 72%, var(--hb-zy4-col))\"\n        : `color-mix(in srgb, var(--hb-zy4-col) ${100 - (h % 6) * 2}%, #ffffff)`;\n    return { n, order, way, fill };\n  });\n\n  const vars = {\n    \"--hb-zy4-col\": color,\n    \"--hb-zy4-acc\": accent,\n    \"--hb-zy4-d\": `${duration}ms`,\n    \"--hb-zy4-s\": `${stagger}ms`,\n    \"--hb-zy4-x\": nx,\n    \"--hb-zy4-y\": ny,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-curtain-mixed\" precedence=\"default\">{css}</style>\n      <div\n        ref={ref}\n        className={`hb-zy4 ${className}`}\n        style={vars}\n        data-open={isOpen}\n        data-instant={instant}\n        {...rest}\n      >\n        <div className=\"hb-zy4-c\">\n          {children ?? (\n            <div className=\"hb-zy4-s\">\n              <small>Issue 12</small>\n              <strong>Color Field</strong>\n            </div>\n          )}\n        </div>\n        <div className=\"hb-zy4-k\" aria-hidden=\"true\">\n          {tiles.map((t) => (\n            <span\n              key={t.n}\n              className=\"hb-zy4-t\"\n              data-way={t.way}\n              style={\n                {\n                  \"--hb-zy4-i\": t.order,\n                  \"--hb-zy4-j\": last - t.order,\n                  \"--hb-zy4-f\": t.fill,\n                } as React.CSSProperties\n              }\n            />\n          ))}\n        </div>\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}