{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "background-10",
  "title": "Signal lines",
  "description": "Faint routes drawn from a seed behind a section about agents, where pulses of the hue travel along them like traffic.",
  "dependencies": [
    "not showing"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/background/background-10.tsx",
      "content": "'use client';\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nimport { DemoBand } from './_parts/demo-band';\nimport { DEFAULT_HUE } from './_parts/hue';\nimport { runWhileShowing } from './_parts/loops';\nimport { towards, type Point } from './_parts/math';\nimport { randomOf, seedOf } from './_parts/seeded';\nimport { useCells } from './_parts/use-cells';\n\nconst DEFAULT_CELL = 32;\n\nconst MIN_CELL = 16;\n\n/**\n * A corner is rounded over a quarter of a cell. A run or a jog is never shorter than a cell, so two\n * rounded corners never meet.\n */\nconst CORNER_SHARE = 0.25;\n\n/** A route runs this many cells to the right before it may jog, and up to five more. */\nconst MIN_RUN = 3;\n\nconst RUN_SPREAD = 5;\n\n/** A jog moves a route by one or two rows. */\nconst MAX_JOG = 2;\n\n/** Routes enter the box two rows apart. */\nconst LANE_GAP = 2;\n\nconst REVERSED_SHARE = 0.4;\n\n/** A line drawn through the middle of a pixel fills that pixel and no other. */\nconst HALF_PIXEL = 0.5;\n\nconst QUARTER_TURN_DEGREES = 90;\n\n/** The length of half a rounded corner, in radii: an eighth of a circle. */\nconst EIGHTH_TURN = Math.PI / 4;\n\n/** How far the middle of a rounded corner sits from the corner itself, in radii, along each leg. */\nconst ARC_INSET = 1 - Math.SQRT1_2;\n\nconst SPEED_PX = 90;\n\n/** One pulse for about this many pixels of route. */\nconst PULSE_GAP_PX = 520;\n\nconst FADE_IN = [{ opacity: 0 }, { opacity: 1 }];\n\nconst FADE_IN_MS = 500;\n\n/** A pulse is a short dash centred on its place, with a tail that fades behind it. */\nconst PULSE =\n  'absolute top-0 left-0 -mt-px -ml-2 h-0.5 w-4 rounded-full from-transparent to-current opacity-90';\n\nconst HEAD_RIGHT = 'bg-linear-to-r';\n\nconst HEAD_LEFT = 'bg-linear-to-l';\n\n/** A place on a route, the way a pulse faces there, and how much of the route lies before it. */\ntype Stop = Point & {\n  angle: number;\n  at: number;\n};\n\ntype Mark = Point & {\n  angle: number;\n  length: number;\n};\n\ntype Route = {\n  id: string;\n  path: string;\n  stops: Stop[];\n  length: number;\n  isReversed: boolean;\n  /** Where along the route its first pulse starts, from 0 to 1. */\n  phase: number;\n};\n\ntype Pulse = {\n  id: string;\n  route: Route;\n  phase: number;\n  /** Where the pulse sits before it runs, and under reduced motion. */\n  rest: string;\n};\n\n/** A route as it is being walked: its path so far, and where the walk stands. */\ntype Trace = {\n  parts: string[];\n  marks: Mark[];\n  length: number;\n  at: Point;\n  heading: Point;\n};\n\nfunction pixelOf(corner: Point, cell: number): Point {\n  const across = corner.x * cell;\n  const down = corner.y * cell;\n  return { x: across + HALF_PIXEL, y: down + HALF_PIXEL };\n}\n\n/** Routes only run along the grid, so a heading is one step along one axis. */\nfunction headingOf(from: Point, to: Point): Point {\n  const across = to.x - from.x;\n  const down = to.y - from.y;\n  return { x: Math.sign(across), y: Math.sign(down) };\n}\n\n/** A route never runs to the left: it faces right, down or up. */\nfunction angleOf(heading: Point) {\n  return heading.y * QUARTER_TURN_DEGREES;\n}\n\nfunction stepFrom(point: Point, heading: Point, distance: number): Point {\n  const across = heading.x * distance;\n  const down = heading.y * distance;\n  return { x: point.x + across, y: point.y + down };\n}\n\nfunction distanceBetween(from: Point, to: Point) {\n  const across = to.x - from.x;\n  const down = to.y - from.y;\n  return Math.hypot(across, down);\n}\n\n/** The flag an SVG arc takes: 1 when the turn is clockwise on screen. */\nfunction sweepOf(heading: Point, leaving: Point) {\n  const forward = heading.x * leaving.y;\n  const sideways = heading.y * leaving.x;\n  const isClockwise = forward > sideways;\n  return Number(isClockwise);\n}\n\nfunction advance(trace: Trace, point: Point, angle: number, travelled: number) {\n  trace.length += travelled;\n  trace.at = point;\n  trace.marks.push({ x: point.x, y: point.y, angle, length: trace.length });\n}\n\n/**\n * One rounded corner: a quarter of a circle between a point short of the corner and a point past\n * it. A pulse is told where the arc starts, where its middle is and where it ends, and turns as it\n * goes from one to the next, so it follows the arc closely on a straight glide.\n */\nfunction turn(trace: Trace, corner: Point, next: Point, radius: number) {\n  const { heading } = trace;\n  const leaving = headingOf(corner, next);\n  const inset = radius * ARC_INSET;\n  const halfArc = radius * EIGHTH_TURN;\n  const enter = stepFrom(corner, heading, -radius);\n  const exit = stepFrom(corner, leaving, radius);\n  const pulledBack = stepFrom(corner, heading, -inset);\n  const middle = stepFrom(pulledBack, leaving, inset);\n  const angleIn = angleOf(heading);\n  const angleOut = angleOf(leaving);\n  const angleSum = angleIn + angleOut;\n  const angleMiddle = angleSum / 2;\n  const straight = distanceBetween(trace.at, enter);\n  const sweep = sweepOf(heading, leaving);\n  const lineIn = `L${enter.x} ${enter.y}`;\n  const arcOut = `A${radius} ${radius} 0 0 ${sweep} ${exit.x} ${exit.y}`;\n  advance(trace, enter, angleIn, straight);\n  advance(trace, middle, angleMiddle, halfArc);\n  advance(trace, exit, angleOut, halfArc);\n  trace.parts.push(lineIn, arcOut);\n  trace.heading = leaving;\n}\n\nfunction stopOf(mark: Mark, total: number): Stop {\n  const at = mark.length / total;\n  return { x: mark.x, y: mark.y, angle: mark.angle, at };\n}\n\nfunction tracedOf(points: Point[], radius: number) {\n  const first = points[0];\n  const second = points[1];\n  const last = points.at(-1);\n  if (!first || !second || !last) {\n    return null;\n  }\n  const heading = headingOf(first, second);\n  const trace: Trace = {\n    parts: [`M${first.x} ${first.y}`],\n    marks: [],\n    length: 0,\n    at: first,\n    heading,\n  };\n  advance(trace, first, angleOf(heading), 0);\n  for (let index = 1; index < points.length - 1; index += 1) {\n    turn(trace, points[index], points[index + 1], radius);\n  }\n  const lastLeg = distanceBetween(trace.at, last);\n  advance(trace, last, angleOf(trace.heading), lastLeg);\n  trace.parts.push(`L${last.x} ${last.y}`);\n  return trace;\n}\n\n/** The row a jog ends on: the side asked for when there is room, the other side otherwise. */\nfunction jogOf(row: number, reach: number, isUp: boolean, rows: number) {\n  const lowest = Math.max(1, rows - 1);\n  const up = Math.max(1, row - reach);\n  const down = Math.min(lowest, row + reach);\n  const canGoUp = up !== row;\n  const canGoDown = down !== row;\n  if (isUp && canGoUp) {\n    return up;\n  }\n  if (canGoDown) {\n    return down;\n  }\n  return up;\n}\n\n/**\n * The corners of one route, in cells. It enters a cell before the left edge and leaves past the\n * right one. Every round draws the same three numbers, whatever the size of the box, so a wider\n * box shows more of the same route and never another one.\n */\nfunction cornersOf(\n  next: () => number,\n  firstRow: number,\n  columns: number,\n  rows: number\n) {\n  const lastColumn = columns + 1;\n  const corners: Point[] = [{ x: -1, y: firstRow }];\n  let column = -1;\n  let row = firstRow;\n  while (column < lastColumn) {\n    const runRoll = next() * RUN_SPREAD;\n    const jogRoll = next() * MAX_JOG;\n    const isUp = next() < 0.5;\n    const run = MIN_RUN + Math.floor(runRoll);\n    const reach = 1 + Math.floor(jogRoll);\n    column += run;\n    const target = jogOf(row, reach, isUp, rows);\n    const hasRoomLeft = column < lastColumn;\n    const isTurning = target !== row && hasRoomLeft;\n    if (isTurning) {\n      const bend = { x: column, y: row };\n      const landing = { x: column, y: target };\n      corners.push(bend, landing);\n      row = target;\n    }\n  }\n  corners.push({ x: column, y: row });\n  return corners;\n}\n\nfunction routeOf(\n  seed: number,\n  lane: number,\n  columns: number,\n  rows: number,\n  cell: number\n): Route | null {\n  const laneSeed = seedOf(seed, lane);\n  const next = randomOf(laneSeed);\n  const isReversed = next() < REVERSED_SHARE;\n  const phase = next();\n  const rowsDown = lane * LANE_GAP;\n  const firstRow = 1 + rowsDown;\n  const radius = cell * CORNER_SHARE;\n  const corners = cornersOf(next, firstRow, columns, rows);\n  const points = corners.map((corner) => pixelOf(corner, cell));\n  const trace = tracedOf(points, radius);\n  if (!trace) {\n    return null;\n  }\n  const total = trace.length;\n  return {\n    id: `route-${lane}`,\n    path: trace.parts.join(''),\n    stops: trace.marks.map((mark) => stopOf(mark, total)),\n    length: total,\n    isReversed,\n    phase,\n  };\n}\n\nfunction isRoute(route: Route | null): route is Route {\n  return route !== null;\n}\n\nfunction routesOf(seed: number, columns: number, rows: number, cell: number) {\n  const usable = Math.max(1, rows - 1);\n  const fitting = Math.floor(usable / LANE_GAP);\n  const lanes = Math.max(1, fitting);\n  const drawn = Array.from({ length: lanes }, (_, lane) =>\n    routeOf(seed, lane, columns, rows, cell)\n  );\n  return drawn.filter(isRoute);\n}\n\nfunction roundedOf(value: number) {\n  const scaled = Math.round(value * 100);\n  return scaled / 100;\n}\n\nfunction transformOf(place: Point & { angle: number }) {\n  const x = roundedOf(place.x);\n  const y = roundedOf(place.y);\n  const angle = roundedOf(place.angle);\n  return `translate(${x}px, ${y}px) rotate(${angle}deg)`;\n}\n\n/** Where a pulse is and how it faces once it has covered `phase` of its route. */\nfunction restOf(route: Route, phase: number) {\n  let before = route.stops[0];\n  for (const stop of route.stops) {\n    const isPast = stop.at > phase;\n    if (isPast && before) {\n      const span = stop.at - before.at;\n      const covered = phase - before.at;\n      const share = covered / span;\n      const x = towards(before.x, stop.x, share);\n      const y = towards(before.y, stop.y, share);\n      const angle = towards(before.angle, stop.angle, share);\n      return transformOf({ x, y, angle });\n    }\n    before = stop;\n  }\n  return 'none';\n}\n\nfunction pulsesOn(route: Route): Pulse[] {\n  const wanted = Math.round(route.length / PULSE_GAP_PX);\n  const count = Math.max(1, wanted);\n  return Array.from({ length: count }, (_, index) => {\n    const spread = index / count;\n    const shifted = route.phase + spread;\n    const phase = shifted % 1;\n    return {\n      id: `${route.id}-${index}`,\n      route,\n      phase,\n      rest: restOf(route, phase),\n    };\n  });\n}\n\nfunction keyframeOf(stop: Stop): Keyframe {\n  return { offset: stop.at, transform: transformOf(stop) };\n}\n\nfunction directionOf(isReversed: boolean): PlaybackDirection {\n  if (isReversed) {\n    return 'reverse';\n  }\n  return 'normal';\n}\n\nfunction headOf(isReversed: boolean) {\n  if (isReversed) {\n    return HEAD_LEFT;\n  }\n  return HEAD_RIGHT;\n}\n\n/** One pulse travels its whole route at a steady speed, by a transform alone, and starts over. */\nfunction travelOf(element: Element, pulse: Pulse) {\n  const { route } = pulse;\n  const seconds = route.length / SPEED_PX;\n  const duration = seconds * 1000;\n  const frames = route.stops.map(keyframeOf);\n  return element.animate(frames, {\n    duration,\n    iterations: Infinity,\n    iterationStart: pulse.phase,\n    direction: directionOf(route.isReversed),\n  });\n}\n\nfunction travelsOf(group: HTMLElement, pulses: Pulse[]) {\n  const elements = group.querySelectorAll('[data-pulse]');\n  const travels: Animation[] = [];\n  elements.forEach((element, index) => {\n    const pulse = pulses[index];\n    if (pulse) {\n      travels.push(travelOf(element, pulse));\n    }\n  });\n  return travels;\n}\n\ntype TracesProps = {\n  seed: number;\n  columns: number;\n  rows: number;\n  cell: number;\n};\n\n/** The routes and their pulses, for one seed. A new seed mounts a new one, which fades in. */\nfunction Traces({ seed, columns, rows, cell }: TracesProps) {\n  const groupRef = useRef<HTMLDivElement>(null);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const routes = useMemo(\n    () => routesOf(seed, columns, rows, cell),\n    [seed, columns, rows, cell]\n  );\n  const pulses = useMemo(() => routes.flatMap(pulsesOn), [routes]);\n  const columnsDrawn = columns + 2;\n  const rowsDrawn = rows + 1;\n  const width = columnsDrawn * cell;\n  const height = rowsDrawn * cell;\n\n  useEffect(() => {\n    const group = groupRef.current;\n    if (!group) {\n      return;\n    }\n    const fade = group.animate(FADE_IN, {\n      duration: FADE_IN_MS,\n      easing: 'ease-out',\n    });\n    return () => fade.cancel();\n  }, []);\n\n  useEffect(() => {\n    const group = groupRef.current;\n    if (!group || shouldReduceMotion) {\n      return;\n    }\n    const travels = travelsOf(group, pulses);\n    return runWhileShowing(group, travels);\n  }, [pulses, shouldReduceMotion]);\n\n  return (\n    <div ref={groupRef} className='absolute inset-0'>\n      <svg\n        aria-hidden='true'\n        width={width}\n        height={height}\n        fill='none'\n        stroke='currentColor'\n        strokeWidth={1}\n        className='text-border absolute top-0 left-0'\n      >\n        {routes.map((route) => (\n          <path key={route.id} d={route.path} />\n        ))}\n      </svg>\n      {pulses.map((pulse) => (\n        <span\n          key={pulse.id}\n          data-pulse=''\n          style={{ transform: pulse.rest }}\n          className={cn(PULSE, headOf(pulse.route.isReversed))}\n        />\n      ))}\n    </div>\n  );\n}\n\nexport type SignalLinesProps = {\n  className?: string;\n  /** Any colour token, such as `var(--primary)` or `var(--series-2)`. The pulses wear it. */\n  hue?: string;\n  /** The same seed always draws the same routes. */\n  seed?: number;\n  /** The side of a cell of the grid the routes follow, in pixels. */\n  size?: number;\n};\n\n/**\n * Faint routes with rounded corners, drawn from a seed in the border colour, and pulses of the hue\n * that travel along them. A pulse is moved by a transform alone, so nothing is repainted while it\n * travels. It fills its parent, which must be positioned. Under reduced motion the pulses rest on\n * their routes.\n */\nexport function SignalLines({\n  className,\n  hue = DEFAULT_HUE,\n  seed = 1,\n  size = DEFAULT_CELL,\n}: SignalLinesProps) {\n  const hostRef = useRef<HTMLDivElement>(null);\n  const cell = Math.max(MIN_CELL, size);\n  const { columns, rows } = useCells(hostRef, cell);\n  const hasCells = columns > 0 && rows > 0;\n\n  return (\n    <div\n      ref={hostRef}\n      aria-hidden='true'\n      style={{ color: hue }}\n      className={cn(\n        'pointer-events-none absolute inset-0 overflow-hidden transition-colors duration-500',\n        className\n      )}\n    >\n      {hasCells && (\n        <Traces\n          key={seed}\n          seed={seed}\n          columns={columns}\n          rows={rows}\n          cell={cell}\n        />\n      )}\n    </div>\n  );\n}\n\nexport default function Background10() {\n  const [seed, setSeed] = useState(1);\n\n  return (\n    <DemoBand\n      title='Signals that travel along quiet routes'\n      background={<SignalLines seed={seed} />}\n    >\n      <Button onClick={() => setSeed((current) => current + 1)}>\n        Draw new routes\n      </Button>\n    </DemoBand>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/background/background-10.tsx"
    },
    {
      "path": "registry/ndeko/components/background/_parts/demo-band.tsx",
      "content": "import { useId, type ReactNode, type Ref } from 'react';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\n\ntype BandAlign = 'center' | 'end';\n\nconst ALIGNMENTS: Record<BandAlign, string> = {\n  center: 'justify-center',\n  end: 'justify-end pb-10',\n};\n\ntype DemoBandProps = {\n  ref?: Ref<HTMLElement>;\n  title: string;\n  /** The background under test. It fills the band, behind the headline and the actions. */\n  background: ReactNode;\n  /** `end` sets the headline at the foot of the band and leaves its middle to the background. */\n  align?: BandAlign;\n  children: ReactNode;\n};\n\n/**\n * The band every background is shown in: the page colour, a headline in the foreground colour and\n * the actions laid straight over the background, to prove that text stays readable above it.\n */\nexport function DemoBand({\n  ref,\n  title,\n  background,\n  align = 'center',\n  children,\n}: DemoBandProps) {\n  const titleId = useId();\n\n  return (\n    <section\n      ref={ref}\n      aria-labelledby={titleId}\n      className={cn(\n        'bg-background @container relative isolate flex h-90 w-full flex-col items-center overflow-hidden rounded-xl',\n        ALIGNMENTS[align]\n      )}\n    >\n      {background}\n      <div className='relative flex max-w-lg flex-col items-center gap-5 px-6 text-center'>\n        <h3\n          id={titleId}\n          className='text-2xl font-semibold text-balance @lg:text-3xl'\n        >\n          {title}\n        </h3>\n        <div className='flex flex-wrap items-center justify-center gap-2'>\n          {children}\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/background/_parts/demo-band.tsx"
    },
    {
      "path": "registry/ndeko/components/background/_parts/hue.ts",
      "content": "'use client';\n\nimport { useState } from 'react';\n\n/** A background wears one hue: the brand unless it is told otherwise. */\nexport const DEFAULT_HUE = 'var(--primary)';\n\n/** The brand first, then the series hues that differ from it. */\nconst DEMO_HUES = [\n  DEFAULT_HUE,\n  'var(--series-2)',\n  'var(--series-3)',\n  'var(--series-4)',\n  'var(--series-5)',\n];\n\n/** The hue of a demo, and the step to the next one, to show a background in each hue it accepts. */\nexport function useHueCycle() {\n  const [index, setIndex] = useState(0);\n  const hue = DEMO_HUES[index] ?? DEFAULT_HUE;\n\n  function nextHue() {\n    setIndex((current) => {\n      const next = current + 1;\n      return next % DEMO_HUES.length;\n    });\n  }\n\n  return { hue, nextHue };\n}\n",
      "type": "registry:component",
      "target": "components/background/_parts/hue.ts"
    },
    {
      "path": "registry/ndeko/components/background/_parts/loops.ts",
      "content": "import { watchShowing } from './showing';\n\nfunction hold(animations: Animation[]) {\n  for (const animation of animations) {\n    animation.pause();\n  }\n}\n\nfunction resume(animations: Animation[]) {\n  for (const animation of animations) {\n    animation.play();\n  }\n}\n\nfunction cancel(animations: Animation[]) {\n  for (const animation of animations) {\n    animation.cancel();\n  }\n}\n\n/**\n * Lands every transition still running under `host` at its end value. A transition asks for frames\n * until it ends, on screen or not, and a host that stops showing must ask for none.\n */\nexport function landTransitions(host: Element) {\n  const animations = host.getAnimations({ subtree: true });\n  for (const animation of animations) {\n    const isTransition = animation instanceof CSSTransition;\n    if (isTransition) {\n      animation.finish();\n    }\n  }\n}\n\n/**\n * Endless animations that run only while their host shows. Off screen and in a hidden tab they are\n * paused: they keep their place and ask for no frame. They start paused, and `onShowing` is told\n * each time the host starts or stops showing. The function returned removes them.\n */\nexport function runWhileShowing(\n  host: Element,\n  animations: Animation[],\n  onShowing?: (isShowing: boolean) => void\n) {\n  hold(animations);\n  const stopWatching = watchShowing(host, (isShowing) => {\n    onShowing?.(isShowing);\n    if (isShowing) {\n      resume(animations);\n      return;\n    }\n    hold(animations);\n  });\n  return () => {\n    stopWatching();\n    cancel(animations);\n  };\n}\n",
      "type": "registry:component",
      "target": "components/background/_parts/loops.ts"
    },
    {
      "path": "registry/ndeko/components/background/_parts/math.ts",
      "content": "export type Point = {\n  x: number;\n  y: number;\n};\n\nexport function clamp(value: number, low: number, high: number) {\n  const raised = Math.max(low, value);\n  return Math.min(high, raised);\n}\n\n/** How much of the way left is covered in `seconds`: the same glide whatever the frame rate. */\nexport function shareOf(seconds: number, easeSeconds: number) {\n  const ratio = seconds / easeSeconds;\n  const decay = Math.exp(-ratio);\n  return 1 - decay;\n}\n\nexport function towards(from: number, to: number, share: number) {\n  const gap = to - from;\n  const step = gap * share;\n  return from + step;\n}\n\n/** From 0 at `low` to 1 at `high`, leaving and arriving without a corner. */\nexport function smoothstep(low: number, high: number, value: number) {\n  const span = high - low;\n  const offset = value - low;\n  const raw = offset / span;\n  const share = clamp(raw, 0, 1);\n  const doubled = 2 * share;\n  const curve = 3 - doubled;\n  const squared = share * share;\n  return squared * curve;\n}\n\n/** The damping that brings a spring of this stiffness to its target without passing it. */\nexport function dampingOf(stiffness: number) {\n  const root = Math.sqrt(stiffness);\n  return 2 * root;\n}\n\n/**\n * The speed of a spring one step later. The caller then moves the value by that speed over the\n * same step, so the value follows its target and settles on it.\n */\nexport function springSpeedOf(\n  gap: number,\n  speed: number,\n  stiffness: number,\n  damping: number,\n  seconds: number\n) {\n  const pull = gap * stiffness;\n  const drag = speed * damping;\n  const push = pull - drag;\n  const gain = push * seconds;\n  return speed + gain;\n}\n",
      "type": "registry:component",
      "target": "components/background/_parts/math.ts"
    },
    {
      "path": "registry/ndeko/components/background/_parts/seeded.ts",
      "content": "const STREAM_STEP = 0x6d2b79f5;\n\nconst UINT32_RANGE = 4294967296;\n\nconst FIRST_PRIME = 73856093;\n\nconst SECOND_PRIME = 19349663;\n\n/**\n * A stream of numbers from 0 to 1, the same for the same seed on the server and in the browser, so\n * a generated picture never changes between two renders.\n */\nexport function randomOf(seed: number) {\n  let state = seed >>> 0;\n\n  function next() {\n    const stepped = state + STREAM_STEP;\n    state = stepped >>> 0;\n    const shifted = state >>> 15;\n    const folded = state ^ shifted;\n    const odd = state | 1;\n    const first = Math.imul(folded, odd);\n    const reshifted = first >>> 7;\n    const refolded = first ^ reshifted;\n    const salted = first | 61;\n    const second = Math.imul(refolded, salted);\n    const summed = first + second;\n    const mixed = first ^ summed;\n    const lastShift = mixed >>> 14;\n    const settled = mixed ^ lastShift;\n    const positive = settled >>> 0;\n    return positive / UINT32_RANGE;\n  }\n\n  return next;\n}\n\n/** One seed out of two numbers, so each part of a picture draws from a stream of its own. */\nexport function seedOf(first: number, second: number) {\n  const firstHash = Math.imul(first, FIRST_PRIME);\n  const secondHash = Math.imul(second, SECOND_PRIME);\n  const mixed = firstHash ^ secondHash;\n  return mixed >>> 0;\n}\n",
      "type": "registry:component",
      "target": "components/background/_parts/seeded.ts"
    },
    {
      "path": "registry/ndeko/components/background/_parts/showing.ts",
      "content": "/**\n * A background sits behind content for as long as the page is open, so everything it runs hangs on\n * this answer: its box touches the screen and the tab is the one looked at. `onChange` is called\n * each time the answer changes, starting from \"not showing\". The function returned ends the watch.\n */\nexport function watchShowing(\n  element: Element,\n  onChange: (isShowing: boolean) => void\n) {\n  let isOnScreen = false;\n  let wasShowing = false;\n\n  function report() {\n    const isTabShown = document.visibilityState === 'visible';\n    const isShowing = isOnScreen && isTabShown;\n    if (isShowing === wasShowing) {\n      return;\n    }\n    wasShowing = isShowing;\n    onChange(isShowing);\n  }\n\n  function onCrossing(entries: IntersectionObserverEntry[]) {\n    const latest = entries.at(-1);\n    if (!latest) {\n      return;\n    }\n    isOnScreen = latest.isIntersecting;\n    report();\n  }\n\n  const observer = new IntersectionObserver(onCrossing);\n  observer.observe(element);\n  document.addEventListener('visibilitychange', report);\n\n  return () => {\n    observer.disconnect();\n    document.removeEventListener('visibilitychange', report);\n  };\n}\n",
      "type": "registry:component",
      "target": "components/background/_parts/showing.ts"
    },
    {
      "path": "registry/ndeko/components/background/_parts/use-cells.ts",
      "content": "'use client';\n\nimport { useEffect, useState, type RefObject } from 'react';\n\nexport type Cells = {\n  columns: number;\n  rows: number;\n};\n\nconst NO_CELLS: Cells = { columns: 0, rows: 0 };\n\nfunction cellsOf(element: HTMLElement, cell: number): Cells {\n  const side = Math.max(1, cell);\n  const across = element.clientWidth / side;\n  const down = element.clientHeight / side;\n  const columns = Math.ceil(across);\n  const rows = Math.ceil(down);\n  return { columns, rows };\n}\n\nfunction keptIfSame(current: Cells, next: Cells) {\n  const hasSameColumns = current.columns === next.columns;\n  const hasSameRows = current.rows === next.rows;\n  if (hasSameColumns && hasSameRows) {\n    return current;\n  }\n  return next;\n}\n\n/**\n * How many cells of `cell` pixels it takes to cover the element, counted again when its box\n * changes. Both counts are 0 until the box has been measured. The state only changes when a count\n * does, so a resize that stays inside the same cells renders nothing again.\n */\nexport function useCells<Target extends HTMLElement>(\n  ref: RefObject<Target | null>,\n  cell: number\n) {\n  const [cells, setCells] = useState(NO_CELLS);\n\n  useEffect(() => {\n    const element = ref.current;\n    if (!element) {\n      return;\n    }\n    const measured = element;\n\n    function count() {\n      const next = cellsOf(measured, cell);\n      setCells((current) => keptIfSame(current, next));\n    }\n\n    const observer = new ResizeObserver(count);\n    observer.observe(measured);\n    return () => observer.disconnect();\n  }, [ref, cell]);\n\n  return cells;\n}\n",
      "type": "registry:component",
      "target": "components/background/_parts/use-cells.ts"
    }
  ],
  "categories": [
    "components",
    "background"
  ],
  "type": "registry:component"
}