{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "meteors-background",
  "title": "Meteors Background",
  "description": "Short streaks crossing a section: thin meteors, faint rain, slow comets or a twinkling sky, placed from a seed and moved with transforms only.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/miseui/ui/meteors-background.tsx",
      "content": "import type * as React from \"react\"\nimport { useMemo, useRef } from \"react\"\nimport { LIGHT_TOKEN_CLASS, LOOP_CLASS, loopStyle, playStyle, useBackgroundPlayback } from \"@/registry/miseui/ui/background-loop\"\nimport { glintLayout, starLayout, streakLayout, type MeteorsVariant, type Streak } from \"@/registry/miseui/ui/meteors-background-layout\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\n\ntype MeteorsBackgroundEffect = \"flow\" | \"still\"\n\nconst FLY = \"rotate(var(--mise-a)) translateX(var(--mise-d))\"\nconst START = \"rotate(var(--mise-a)) translateX(0)\"\n\n/** The flight takes part of each period and the rest is empty sky: that gap is what keeps it from reading as a stream. */\nconst KEYFRAMES = [\n  `@keyframes mise-meteor-fly{0%{transform:${START};opacity:0}4%,30%{opacity:var(--mise-o)}40%,100%{transform:${FLY};opacity:0}}`,\n  `@keyframes mise-meteor-fall{0%{transform:${START};opacity:0}10%,80%{opacity:var(--mise-o)}100%{transform:${FLY};opacity:0}}`,\n  `@keyframes mise-meteor-comet{0%{transform:${START};opacity:0}6%,50%{opacity:var(--mise-o)}60%,100%{transform:${FLY};opacity:0}}`,\n  `@keyframes mise-meteor-glint{0%{transform:${START};opacity:0}1%,10%{opacity:var(--mise-o)}12%,100%{transform:${FLY};opacity:0}}`,\n  \"@keyframes mise-meteor-twinkle{0%,100%{opacity:calc(var(--mise-o)*.3)}50%{opacity:var(--mise-o)}}\",\n].join(\"\")\n\nconst FLIGHT = { meteors: \"mise-meteor-fly\", rain: \"mise-meteor-fall\", comets: \"mise-meteor-comet\" } as const\n\ninterface StreakProps {\n  streak: Streak\n  still: boolean\n  animation: string\n  head?: boolean\n  thick?: boolean\n}\n\nfunction StreakMark({ streak, still, animation, head = false, thick = false }: StreakProps) {\n  return (\n    <span\n      data-slot=\"meteors-background-streak\"\n      className={cn(\"absolute origin-left bg-linear-to-r from-transparent to-(--mise-light)\", thick ? \"h-0.5\" : \"h-px\", LOOP_CLASS)}\n      style={{\n        width: streak.length,\n        left: `${still ? streak.stillLeft : streak.left}%`,\n        top: `${still ? streak.stillTop : streak.top}%`,\n        ...({ \"--mise-a\": `${streak.angle}deg`, \"--mise-d\": `${streak.travel}px`, \"--mise-o\": streak.peak } as React.CSSProperties),\n        ...(still ? { transform: `rotate(${streak.angle}deg)`, opacity: streak.stillPeak } : loopStyle(animation, streak.seconds, streak.delay)),\n      }}\n    >\n      {head ? <span data-slot=\"meteors-background-head\" className=\"absolute top-1/2 right-0 size-1 translate-x-1/2 -translate-y-1/2 rounded-full bg-(--mise-light)\" /> : null}\n    </span>\n  )\n}\n\ninterface FaceProps {\n  seed: number\n  count?: number\n  still: boolean\n}\n\nfunction StreaksFace({ variant, seed, count, still }: FaceProps & { variant: Exclude<MeteorsVariant, \"stars\"> }) {\n  const streaks = useMemo(() => streakLayout(variant, seed, count), [variant, seed, count])\n  return streaks.map((streak, index) => (\n    <StreakMark key={index} streak={streak} still={still} animation={FLIGHT[variant]} head={variant === \"comets\"} thick={variant === \"comets\"} />\n  ))\n}\n\nfunction StarsFace({ seed, count, still }: FaceProps) {\n  const stars = useMemo(() => starLayout(seed, count), [seed, count])\n  const glint = useMemo(() => glintLayout(seed), [seed])\n  return (\n    <>\n      {stars.map((star, index) => (\n        <span\n          key={index}\n          data-slot=\"meteors-background-star\"\n          className={cn(\"absolute rounded-full bg-(--mise-light)\", LOOP_CLASS)}\n          style={{\n            left: `${star.left}%`,\n            top: `${star.top}%`,\n            width: star.size,\n            height: star.size,\n            ...({ \"--mise-o\": star.peak } as React.CSSProperties),\n            ...(still ? { opacity: star.peak * 0.7 } : loopStyle(\"mise-meteor-twinkle\", star.seconds, star.delay, \"ease-in-out\")),\n          }}\n        />\n      ))}\n      <StreakMark streak={glint} still={still} animation=\"mise-meteor-glint\" />\n    </>\n  )\n}\n\ntype MeteorsBackgroundProps = Omit<React.ComponentProps<\"div\">, \"ref\"> & {\n  /** `meteors` thin diagonals, `rain` vertical and faint, `comets` few and slow with long tails, `stars` still points with an occasional streak. */\n  variant?: MeteorsVariant\n  /** How many. Each variant has its own default and ceiling, so it never reads as a stream of errors. */\n  count?: number\n  /** `flow` moves while on screen. `still` draws one finished frame, the same one reduced motion gets. */\n  effect?: MeteorsBackgroundEffect\n  /** Holds the motion. Wire it to a control: motion past five seconds needs a way to stop it. */\n  paused?: boolean\n  /** Another seed gives another layout that is still the same on the server and the client. */\n  seed?: number\n}\n\nfunction MeteorsBackground({ variant = \"meteors\", count, effect = \"flow\", paused = false, seed = 1, className, children, ...props }: MeteorsBackgroundProps) {\n  const rootRef = useRef<HTMLDivElement>(null)\n  const { still, playing } = useBackgroundPlayback(rootRef, { paused, loops: effect === \"flow\" })\n  return (\n    <div\n      {...props}\n      ref={rootRef}\n      data-slot=\"meteors-background\"\n      data-variant={variant}\n      data-effect={effect}\n      data-playing={still ? undefined : String(playing)}\n      className={cn(\"relative isolate min-w-0 overflow-clip\", className)}\n    >\n      {still ? null : <style href=\"mise-meteors-background\" precedence=\"default\">{KEYFRAMES}</style>}\n      <div\n        aria-hidden=\"true\"\n        data-slot=\"meteors-background-layer\"\n        className={cn(\"pointer-events-none absolute inset-0 -z-10 overflow-clip rounded-[inherit]\", LIGHT_TOKEN_CLASS)}\n        style={playStyle(playing)}\n      >\n        {variant === \"stars\" ? <StarsFace seed={seed} count={count} still={still} /> : <StreaksFace variant={variant} seed={seed} count={count} still={still} />}\n      </div>\n      <div data-slot=\"meteors-background-content\" className=\"relative h-full\">\n        {children}\n      </div>\n    </div>\n  )\n}\n\nexport { MeteorsBackground, type MeteorsBackgroundProps, type MeteorsBackgroundEffect, type MeteorsVariant as MeteorsBackgroundVariant }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/meteors-background-layout.ts",
      "content": "import { between, seededRandom } from \"@/registry/miseui/ui/background-seed\"\n\nexport type MeteorsVariant = \"meteors\" | \"rain\" | \"comets\" | \"stars\"\n\nconst DEFAULT_COUNT: Record<MeteorsVariant, number> = { meteors: 8, rain: 26, comets: 3, stars: 36 }\n/** The ceilings keep the sky from reading as a fault, whatever the owner passes. */\nexport const MAX_COUNT: Record<MeteorsVariant, number> = { meteors: 20, rain: 48, comets: 6, stars: 96 }\n\nexport interface Streak {\n  /** Where it enters, in percent of the box. Can start past the edge. */\n  left: number\n  top: number\n  /** Where it sits in the frozen frame, always inside the box. */\n  stillLeft: number\n  stillTop: number\n  length: number\n  travel: number\n  angle: number\n  seconds: number\n  delay: number\n  peak: number\n  /** Opacity in the frozen frame. */\n  stillPeak: number\n}\n\nexport interface Star {\n  left: number\n  top: number\n  size: number\n  seconds: number\n  delay: number\n  peak: number\n}\n\nexport function meteorCount(variant: MeteorsVariant, count?: number) {\n  if (count === undefined || !Number.isFinite(count)) return DEFAULT_COUNT[variant]\n  return Math.min(MAX_COUNT[variant], Math.max(0, Math.round(count)))\n}\n\ninterface StreakRange {\n  left: readonly [number, number]\n  top: readonly [number, number]\n  length: readonly [number, number]\n  travel: readonly [number, number]\n  seconds: readonly [number, number]\n  peak: readonly [number, number]\n  angle: number\n}\n\n/** Diagonals enter along the top and, past 100%, down the right side, so the whole box gets crossed. */\nconst RANGE: Record<Exclude<MeteorsVariant, \"stars\">, StreakRange> = {\n  meteors: { left: [10, 150], top: [-14, -6], length: [56, 96], travel: [560, 760], seconds: [10, 18], peak: [0.55, 0.85], angle: 125 },\n  rain: { left: [1, 99], top: [-16, 40], length: [32, 72], travel: [560, 800], seconds: [3.4, 6], peak: [0.14, 0.3], angle: 90 },\n  comets: { left: [30, 160], top: [-30, -10], length: [160, 260], travel: [960, 1240], seconds: [20, 32], peak: [0.6, 0.8], angle: 140 },\n}\n\nconst GLINT: StreakRange = { left: [40, 130], top: [-12, -4], length: [64, 96], travel: [560, 640], seconds: [20, 28], peak: [0.6, 0.8], angle: 125 }\n\nfunction makeStreak(range: StreakRange, random: () => number): Streak {\n  const seconds = between(random, range.seconds[0], range.seconds[1])\n  const peak = between(random, range.peak[0], range.peak[1])\n  return {\n    left: between(random, range.left[0], range.left[1]),\n    top: between(random, range.top[0], range.top[1]),\n    stillLeft: between(random, 8, 88),\n    stillTop: between(random, 8, 84),\n    length: between(random, range.length[0], range.length[1]),\n    travel: between(random, range.travel[0], range.travel[1]),\n    angle: range.angle,\n    seconds,\n    delay: -between(random, 0, seconds),\n    peak,\n    stillPeak: peak * 0.8,\n  }\n}\n\nexport function streakLayout(variant: Exclude<MeteorsVariant, \"stars\">, seed: number, count?: number): readonly Streak[] {\n  const random = seededRandom(seed)\n  return Array.from({ length: meteorCount(variant, count) }, () => makeStreak(RANGE[variant], random))\n}\n\nexport function starLayout(seed: number, count?: number): readonly Star[] {\n  const random = seededRandom(seed)\n  return Array.from({ length: meteorCount(\"stars\", count) }, () => {\n    const seconds = between(random, 6, 14)\n    return {\n      left: between(random, 1, 99),\n      top: between(random, 1, 99),\n      size: between(random, 1, 2.5),\n      seconds,\n      delay: -between(random, 0, seconds),\n      peak: between(random, 0.3, 0.75),\n    }\n  })\n}\n\n/** The occasional streak over a still sky. One, so it stays an event. */\nexport function glintLayout(seed: number): Streak {\n  return makeStreak(GLINT, seededRandom(seed + 1))\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/background-loop.ts",
      "content": "import type * as React from \"react\"\nimport { useEffect, useState, useSyncExternalStore } from \"react\"\nimport { useReducedMotion } from \"motion/react\"\n\n/**\n * The accent as a light source, held in a lightness band per theme. A near-black accent would read as smoke on a light\n * page and a dark blue would pull muted text under 4.5:1 where a beam crosses it, so the band's floor is 0.6.\n * Older browsers keep plain --mise, which is only a stronger tint.\n */\nexport const LIGHT_TOKEN_CLASS = [\n  \"[--mise-light:var(--mise)]\",\n  \"supports-[color:oklch(from_red_l_c_h)]:[--mise-light:oklch(from_var(--mise)_clamp(0.6,l,0.76)_c_h)]\",\n  \"dark:supports-[color:oklch(from_red_l_c_h)]:[--mise-light:oklch(from_var(--mise)_clamp(0.62,l,0.82)_c_h)]\",\n].join(\" \")\n\n/** Before hydration the hook cannot know the preference yet. A paused animation holds its seeded frame. */\nexport const LOOP_CLASS = \"motion-reduce:[animation-play-state:paused]!\"\n\nconst subscribeToVisibility = (onChange: () => void) => {\n  document.addEventListener(\"visibilitychange\", onChange)\n  return () => document.removeEventListener(\"visibilitychange\", onChange)\n}\n\nfunction useTabVisible() {\n  return useSyncExternalStore(\n    subscribeToVisibility,\n    () => !document.hidden,\n    () => true,\n  )\n}\n\nfunction useOnScreen(rootRef: React.RefObject<HTMLElement | null>, watching: boolean) {\n  const [onScreen, setOnScreen] = useState(true)\n  useEffect(() => {\n    const root = rootRef.current\n    if (!watching || !root || typeof IntersectionObserver === \"undefined\") return\n    const view = new IntersectionObserver(([entry]) => setOnScreen(entry?.isIntersecting ?? true))\n    view.observe(root)\n    return () => view.disconnect()\n  }, [rootRef, watching])\n  return onScreen\n}\n\ninterface PlaybackOptions {\n  /** The owner's stop control. */\n  paused?: boolean\n  /** False when this look never moves, so nothing is watched at all. */\n  loops?: boolean\n}\n\n/** `still` draws one finished frame. `playing` is only true on screen, in a visible tab and not paused. */\nexport function useBackgroundPlayback(rootRef: React.RefObject<HTMLElement | null>, { paused = false, loops = true }: PlaybackOptions) {\n  const reduceMotion = useReducedMotion() ?? false\n  const moving = loops && !reduceMotion\n  const onScreen = useOnScreen(rootRef, moving)\n  const tabVisible = useTabVisible()\n  return { still: !moving, playing: moving && !paused && onScreen && tabVisible }\n}\n\n/** Longhands, because the shorthand would reset the play state each element reads from the layer. */\nexport function loopStyle(name: string, seconds: number, delay: number, timing = \"linear\", direction = \"normal\"): React.CSSProperties {\n  return {\n    animationName: name,\n    animationDuration: `${seconds}s`,\n    animationDelay: `${delay}s`,\n    animationTimingFunction: timing,\n    animationDirection: direction,\n    animationIterationCount: \"infinite\",\n    animationPlayState: \"var(--mise-bg-play)\",\n  }\n}\n\n/** Set once on the layer, so pausing writes one property however many elements are moving. */\nexport function playStyle(playing: boolean) {\n  return { \"--mise-bg-play\": playing ? \"running\" : \"paused\" } as React.CSSProperties\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/background-seed.ts",
      "content": "/** Mulberry32. Server and client walk the same numbers, so a seeded layout hydrates without a mismatch. */\nexport function seededRandom(seed: number) {\n  let state = seed >>> 0\n  return () => {\n    state = (state + 0x6d2b79f5) >>> 0\n    let mixed = state\n    mixed = Math.imul(mixed ^ (mixed >>> 15), mixed | 1)\n    mixed ^= mixed + Math.imul(mixed ^ (mixed >>> 7), mixed | 61)\n    return ((mixed ^ (mixed >>> 14)) >>> 0) / 4294967296\n  }\n}\n\n/** Two decimals: enough for a percent or a second, and short in the inline style. */\nexport function between(random: () => number, min: number, max: number) {\n  return Math.round((min + random() * (max - min)) * 100) / 100\n}\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "backgrounds"
  ],
  "type": "registry:ui"
}