{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "glass-core",
  "title": "Glass Core",
  "description": "A glass object for the centre of a hero, with no WebGL: a shaded knot on a small canvas, a CSS sphere or frosted panes. Respects reduced motion and reduced transparency.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://miseui.junsu4621.workers.dev/r/motion.json"
  ],
  "files": [
    {
      "path": "registry/miseui/ui/glass-core.tsx",
      "content": "import type * as React from \"react\"\nimport { useEffect, useRef, useSyncExternalStore } from \"react\"\nimport { animate, useMotionValue, useReducedMotion, useTransform, type MotionValue } from \"motion/react\"\nimport { SPRING_DEFAULT } from \"@/registry/miseui/lib/motion\"\nimport { KnotFace, OrbFace, PanesFace } from \"@/registry/miseui/ui/glass-core-faces\"\nimport { leanFrom } from \"@/registry/miseui/ui/glass-core-knot\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\n\ntype GlassCoreVariant = \"knot\" | \"orb\" | \"panes\"\ntype GlassCoreEffect = \"follow\" | \"drift\"\n\nconst FACE = { knot: KnotFace, orb: OrbFace, panes: PanesFace } as const\nconst REDUCED_TRANSPARENCY = \"(prefers-reduced-transparency: reduce)\"\nconst DRIFT_REACH = 0.6\nconst DRIFT_SECONDS = 9\n\nfunction subscribeTransparency(onChange: () => void) {\n  const query = window.matchMedia(REDUCED_TRANSPARENCY)\n  query.addEventListener(\"change\", onChange)\n  return () => query.removeEventListener(\"change\", onChange)\n}\n\nfunction useReducedTransparency() {\n  return useSyncExternalStore(subscribeTransparency, () => window.matchMedia(REDUCED_TRANSPARENCY).matches, () => false)\n}\n\nfunction usePointerLean(rootRef: React.RefObject<HTMLElement | null>, enabled: boolean) {\n  const leanX = useMotionValue(0)\n  const leanY = useMotionValue(0)\n  useEffect(() => {\n    if (!enabled) return\n    const onMove = (event: PointerEvent) => {\n      const rect = rootRef.current?.getBoundingClientRect()\n      if (!rect || event.pointerType === \"touch\") return\n      animate(leanX, leanFrom(event.clientX, rect.left, rect.width), SPRING_DEFAULT)\n      animate(leanY, leanFrom(event.clientY, rect.top, rect.height), SPRING_DEFAULT)\n    }\n    window.addEventListener(\"pointermove\", onMove, { passive: true })\n    return () => window.removeEventListener(\"pointermove\", onMove)\n  }, [enabled, leanX, leanY, rootRef])\n  return { leanX, leanY }\n}\n\n/** The CSS faces have no frame loop of their own, so a drift is a slow sway on one value, held while off screen. */\nfunction useCssDrift(rootRef: React.RefObject<HTMLElement | null>, enabled: boolean): MotionValue<number> {\n  const sway = useMotionValue(0)\n  useEffect(() => {\n    const root = rootRef.current\n    if (!enabled || !root) return\n    const controls = animate(sway, [-DRIFT_REACH, DRIFT_REACH], {\n      duration: DRIFT_SECONDS,\n      ease: \"easeInOut\",\n      repeat: Infinity,\n      repeatType: \"mirror\",\n    })\n    const view = typeof IntersectionObserver === \"undefined\" ? null : new IntersectionObserver(([entry]) => {\n      if (entry?.isIntersecting) controls.play()\n      else controls.pause()\n    })\n    view?.observe(root)\n    return () => {\n      view?.disconnect()\n      controls.stop()\n    }\n  }, [enabled, rootRef, sway])\n  return sway\n}\n\ntype GlassCoreProps = Omit<React.ComponentProps<\"div\">, \"role\"> & {\n  /** `knot` a shaded tube drawn on a canvas, `orb` a CSS glass sphere, `panes` frosted sheets in CSS 3D. */\n  variant?: GlassCoreVariant\n  /** `follow` leans toward the pointer; `drift` also turns slowly while on screen. Both stay still under reduced motion. */\n  effect?: GlassCoreEffect\n  /** Say what it stands for when it carries meaning. Without it the object is decoration and hidden from assistive tech. */\n  label?: string\n}\n\nfunction GlassCore({ variant = \"knot\", effect, label, className, children, ...props }: GlassCoreProps) {\n  const rootRef = useRef<HTMLDivElement>(null)\n  const reduceMotion = useReducedMotion() ?? false\n  const solid = useReducedTransparency()\n  const moving = !reduceMotion && effect !== undefined\n  const drift = moving && effect === \"drift\"\n  const { leanX, leanY } = usePointerLean(rootRef, moving)\n  const sway = useCssDrift(rootRef, drift && variant !== \"knot\")\n  const swayedX = useTransform([leanX, sway], ([lean = 0, offset = 0]) => (lean as number) + (offset as number))\n  const swayedY = useTransform([leanY, sway], ([lean = 0, offset = 0]) => (lean as number) - (offset as number) / 2)\n  const Face = FACE[variant]\n  return (\n    <div\n      ref={rootRef}\n      role={label ? \"img\" : undefined}\n      aria-label={label}\n      aria-hidden={label ? undefined : true}\n      data-slot=\"glass-core\"\n      data-variant={variant}\n      data-effect={effect}\n      data-solid={solid || undefined}\n      className={cn(\"relative isolate aspect-square w-full max-w-80 min-w-0\", className)}\n      {...props}\n    >\n      {/* Reduced transparency drops the light behind, since all it does is show through the glass. */}\n      {solid ? null : <div data-slot=\"glass-core-glow\" className=\"absolute inset-[22%] -z-10 rounded-full bg-mise opacity-50 blur-3xl\" />}\n      <Face leanX={swayedX} leanY={swayedY} drift={drift} solid={solid} />\n      {children ? <div className=\"absolute inset-0 z-10 grid place-items-center\">{children}</div> : null}\n    </div>\n  )\n}\n\nexport { GlassCore, type GlassCoreProps, type GlassCoreVariant, type GlassCoreEffect }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/glass-core-faces.tsx",
      "content": "import { useEffect, useRef } from \"react\"\nimport { motion, useMotionTemplate, useTransform, type MotionValue } from \"motion/react\"\nimport { startKnotPainter } from \"@/registry/miseui/ui/glass-core-painter\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\n\nexport interface GlassFaceProps {\n  leanX: MotionValue<number>\n  leanY: MotionValue<number>\n  drift: boolean\n  solid: boolean\n}\n\nexport function KnotFace({ leanX, leanY, drift, solid }: GlassFaceProps) {\n  const canvasRef = useRef<HTMLCanvasElement>(null)\n  useEffect(() => {\n    const canvas = canvasRef.current\n    if (!canvas) return\n    return startKnotPainter(canvas, { leanX, leanY, drift, solid })\n  }, [leanX, leanY, drift, solid])\n  return <canvas ref={canvasRef} data-slot=\"glass-core-canvas\" className=\"absolute inset-0 size-full\" />\n}\n\nconst HIGHLIGHT_REST = 32\nconst HIGHLIGHT_TRAVEL = 14\n\nconst ORB_SHADOW =\n  \"inset 0 0 0 1px rgb(255 255 255 / 0.18), inset 0 -24px 48px -16px color-mix(in oklab, var(--mise) 55%, transparent), 0 24px 48px -24px rgb(0 0 0 / 0.45)\"\n\nexport function OrbFace({ leanX, leanY }: GlassFaceProps) {\n  const lightX = useTransform(leanX, (value) => `${HIGHLIGHT_REST + value * HIGHLIGHT_TRAVEL}%`)\n  const lightY = useTransform(leanY, (value) => `${HIGHLIGHT_REST - 6 + value * HIGHLIGHT_TRAVEL}%`)\n  const bendX = useTransform(leanX, (value) => `${100 - HIGHLIGHT_REST + value * HIGHLIGHT_TRAVEL * -0.6}%`)\n  const bendY = useTransform(leanY, (value) => `${100 - HIGHLIGHT_REST + value * HIGHLIGHT_TRAVEL * -0.6}%`)\n  const glint = useMotionTemplate`radial-gradient(circle at ${lightX} ${lightY}, rgb(255 255 255 / 0.85), transparent 34%)`\n  const bend = useMotionTemplate`radial-gradient(circle at ${bendX} ${bendY}, color-mix(in oklab, var(--mise) 70%, transparent), transparent 56%)`\n  return (\n    <div\n      data-slot=\"glass-core-orb\"\n      className=\"absolute inset-[14%] overflow-hidden rounded-full border border-foreground/10 bg-background/20 backdrop-blur-md [@media(prefers-reduced-transparency:reduce)]:bg-muted [@media(prefers-reduced-transparency:reduce)]:backdrop-blur-none\"\n      style={{ boxShadow: ORB_SHADOW }}\n    >\n      <motion.div className=\"absolute inset-0\" style={{ backgroundImage: bend }} />\n      <motion.div className=\"absolute inset-0\" style={{ backgroundImage: glint }} />\n    </div>\n  )\n}\n\nconst PANE_TILT = 24\nconst PANE_TURN = -28\nconst PANE_LEAN = 14\nconst PANE_LAYERS: ReadonlyArray<{ z: number; className: string }> = [\n  { z: -48, className: \"bg-background/20\" },\n  { z: 0, className: \"bg-mise/20 [@media(prefers-reduced-transparency:reduce)]:bg-muted\" },\n  { z: 48, className: \"bg-background/30 [@media(prefers-reduced-transparency:reduce)]:bg-card\" },\n]\n\nexport function PanesFace({ leanX, leanY }: GlassFaceProps) {\n  const tilt = useTransform(leanY, (value) => PANE_TILT - value * PANE_LEAN)\n  const turn = useTransform(leanX, (value) => PANE_TURN + value * PANE_LEAN)\n  const transform = useMotionTemplate`rotateX(${tilt}deg) rotateY(${turn}deg)`\n  return (\n    <div className=\"absolute inset-0 perspective-[800px]\">\n      <motion.div className=\"absolute inset-0 transform-3d\" style={{ transform }}>\n        {PANE_LAYERS.map((pane) => (\n          <div\n            key={pane.z}\n            data-slot=\"glass-core-pane\"\n            className={cn(\n              \"absolute inset-[24%] rounded-2xl border border-foreground/15 shadow-[0_16px_32px_-20px_rgb(0_0_0/0.5)] backdrop-blur-sm [@media(prefers-reduced-transparency:reduce)]:backdrop-blur-none\",\n              pane.className,\n            )}\n            style={{ transform: `translateZ(${pane.z}px)` }}\n          />\n        ))}\n      </motion.div>\n    </div>\n  )\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/glass-core-knot.ts",
      "content": "export interface KnotPoint {\n  x: number\n  y: number\n  z: number\n}\n\nexport interface KnotBead {\n  x: number\n  y: number\n  /** -1 far, 1 near. */\n  depth: number\n  scale: number\n}\n\nconst WINDINGS = 2\nconst TWISTS = 3\n/** Half the canvas minus the tube and the glow around it. */\nexport const FILL_SHARE = 0.34\nconst CAMERA_DISTANCE = 4\nconst REST_TILT = 0.5\nconst REST_TURN = 0.4\nconst LEAN_TURN = 0.6\nconst LEAN_TILT = 0.4\nconst DRIFT_TURN_PER_S = 0.15\nconst DRIFT_TILT_RATE = 0.4\nconst DRIFT_TILT = 0.2\n\n/** A (2,3) torus knot scaled into a unit box. */\nexport function knotPoint(t: number): KnotPoint {\n  const ring = Math.cos(TWISTS * t) + 2\n  return { x: (ring * Math.cos(WINDINGS * t)) / 3, y: (ring * Math.sin(WINDINGS * t)) / 3, z: -Math.sin(TWISTS * t) / 3 }\n}\n\nexport function buildKnot(segments: number) {\n  return Array.from({ length: segments }, (_, step) => knotPoint((step / segments) * Math.PI * 2))\n}\n\nexport function rotatePoint({ x, y, z }: KnotPoint, tilt: number, turn: number): KnotPoint {\n  const turnedX = x * Math.cos(turn) + z * Math.sin(turn)\n  const turnedZ = -x * Math.sin(turn) + z * Math.cos(turn)\n  return {\n    x: turnedX,\n    y: y * Math.cos(tilt) - turnedZ * Math.sin(tilt),\n    z: y * Math.sin(tilt) + turnedZ * Math.cos(tilt),\n  }\n}\n\n/** Keeps the path order, because the raster reads each bead's neighbours for the direction of the tube. */\nexport function projectKnot(points: readonly KnotPoint[], tilt: number, turn: number, size: number): KnotBead[] {\n  const center = size / 2\n  const reach = size * FILL_SHARE * CAMERA_DISTANCE\n  return points.map((point) => {\n    const turned = rotatePoint(point, tilt, turn)\n    const scale = 1 / (1 - turned.z / CAMERA_DISTANCE)\n    return { x: center + (turned.x * reach * scale) / CAMERA_DISTANCE, y: center + (turned.y * reach * scale) / CAMERA_DISTANCE, depth: turned.z, scale }\n  })\n}\n\n/** Pointer position against the element's centre, -1 to 1. A pointer far outside still only leans it fully. */\nexport function leanFrom(pointer: number, start: number, length: number) {\n  if (length <= 0) return 0\n  return Math.max(-1, Math.min(1, ((pointer - start) / length) * 2 - 1))\n}\n\nexport function knotAngles(seconds: number, leanX: number, leanY: number) {\n  return {\n    tilt: REST_TILT + leanY * LEAN_TILT + Math.sin(seconds * DRIFT_TILT_RATE) * DRIFT_TILT,\n    turn: REST_TURN + leanX * LEAN_TURN + seconds * DRIFT_TURN_PER_S,\n  }\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/glass-core-painter.ts",
      "content": "import type { MotionValue } from \"motion/react\"\nimport { buildKnot, knotAngles, projectKnot } from \"@/registry/miseui/ui/glass-core-knot\"\nimport { rasterizeKnot, type KnotShade, type Rgb } from \"@/registry/miseui/ui/glass-core-raster\"\n\nconst BEAD_COUNT = 360\n/** Paint cost grows with the area. A smooth tube loses nothing when the browser scales it up the last step. */\nconst MAX_CANVAS_PX = 400\n\nconst MAX_PIXEL_RATIO = 2\n\n/** Canvas parses any CSS colour the theme uses, oklch included, so asking it is shorter than writing a parser. */\nfunction resolveColor(color: string, fallback: Rgb): Rgb {\n  const probe = document.createElement(\"canvas\")\n  probe.width = 1\n  probe.height = 1\n  const ctx = probe.getContext(\"2d\", { willReadFrequently: true })\n  if (!ctx) return fallback\n  ctx.fillStyle = color\n  ctx.fillRect(0, 0, 1, 1)\n  const [r = 0, g = 0, b = 0] = ctx.getImageData(0, 0, 1, 1).data\n  return [r, g, b]\n}\n\nfunction readColors(canvas: HTMLCanvasElement) {\n  const styles = getComputedStyle(canvas)\n  return { surface: styles.getPropertyValue(\"--background\").trim() || \"#ffffff\", accent: styles.getPropertyValue(\"--mise\").trim() || \"#888888\" }\n}\n\ninterface KnotLoopOptions {\n  leanX: MotionValue<number>\n  leanY: MotionValue<number>\n  drift: boolean\n  solid: boolean\n}\n\ntype KnotLean = Pick<KnotLoopOptions, \"leanX\" | \"leanY\">\n\n/** Everything that can make a painted knot stale: its size, the page theme, the pointer, and coming back into view. */\nfunction watchKnot(canvas: HTMLCanvasElement, { leanX, leanY }: KnotLean, schedule: () => void, setVisible: (visible: boolean) => void) {\n  const resize = new ResizeObserver(schedule)\n  resize.observe(canvas)\n  const theme = new MutationObserver(schedule)\n  theme.observe(document.documentElement, { attributes: true, attributeFilter: [\"class\", \"style\", \"data-theme\"] })\n  const view = typeof IntersectionObserver === \"undefined\" ? null : new IntersectionObserver(([entry]) => {\n    setVisible(entry?.isIntersecting ?? true)\n    schedule()\n  })\n  view?.observe(canvas)\n  const offX = leanX.on(\"change\", schedule)\n  const offY = leanY.on(\"change\", schedule)\n  document.addEventListener(\"visibilitychange\", schedule)\n  return () => {\n    resize.disconnect()\n    theme.disconnect()\n    view?.disconnect()\n    offX()\n    offY()\n    document.removeEventListener(\"visibilitychange\", schedule)\n  }\n}\n\n/**\n * Paints on demand and only runs a frame loop while drifting on screen, so a still knot costs nothing.\n * The theme is read per paint, and the observer on <html> repaints when the page changes theme or accent.\n */\nexport function startKnotPainter(canvas: HTMLCanvasElement, { leanX, leanY, drift, solid }: KnotLoopOptions) {\n  const ctx = canvas.getContext(\"2d\")\n  if (!ctx) return () => {}\n  const points = buildKnot(BEAD_COUNT)\n  let shade: KnotShade | null = null\n  let shadeKey = \"\"\n  let frame = 0\n  let visible = true\n  let startedAt: number | null = null\n\n  const paint = (time: number) => {\n    const size = canvas.clientWidth\n    const ratio = Math.min(window.devicePixelRatio || 1, MAX_PIXEL_RATIO)\n    const pixels = Math.min(Math.round(size * ratio), MAX_CANVAS_PX)\n    if (canvas.width !== pixels) canvas.width = pixels\n    if (canvas.height !== pixels) canvas.height = pixels\n    startedAt ??= time\n    const seconds = drift ? (time - startedAt) / 1000 : 0\n    const { tilt, turn } = knotAngles(seconds, leanX.get(), leanY.get())\n    const colors = readColors(canvas)\n    const key = `${colors.surface}|${colors.accent}`\n    if (!shade || key !== shadeKey) {\n      shade = { accent: resolveColor(colors.accent, [136, 136, 136]), surface: resolveColor(colors.surface, [255, 255, 255]), solid }\n      shadeKey = key\n    }\n    if (pixels <= 0) return\n    const image = ctx.createImageData(pixels, pixels)\n    rasterizeKnot(projectKnot(points, tilt, turn, pixels), pixels, shade, image.data)\n    ctx.putImageData(image, 0, 0)\n  }\n  const schedule = () => {\n    if (frame) return\n    frame = requestAnimationFrame((time) => {\n      frame = 0\n      paint(time)\n      if (drift && visible && !document.hidden) schedule()\n    })\n  }\n\n  const stopWatching = watchKnot(canvas, { leanX, leanY }, schedule, (next) => {\n    visible = next\n  })\n  schedule()\n\n  return () => {\n    cancelAnimationFrame(frame)\n    stopWatching()\n  }\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/glass-core-raster.ts",
      "content": "import { FILL_SHARE, type KnotBead } from \"@/registry/miseui/ui/glass-core-knot\"\n\nexport type Rgb = readonly [number, number, number]\n\nexport interface KnotShade {\n  accent: Rgb\n  surface: Rgb\n  solid: boolean\n}\n\nconst TUBE_SHARE = 0.11\nconst SLICE_REACH = 1.6\nconst FOLD_TURN = 0.7\nconst FOLD_STEP = 0.04\nconst FAR_FADE = 0.5\nconst FAR_FADE_SOLID = 0.25\nconst PALE_BODY = 0.2\nconst SHADOW = 0.3\nconst GLOW = 0.28\nconst SHEEN_POWER = 10\nconst SHEEN = 0.3\nconst GLINT_POWER = 60\nconst GLINT = 0.95\nconst GLASS_ALPHA = 0.86\nconst LIGHT = { x: -0.42, y: -0.6, z: 0.68 } as const\n\nconst mix = (from: number, to: number, amount: number) => from + (to - from) * amount\n\nfunction direction(beads: readonly KnotBead[], index: number) {\n  const before = beads[(index - 1 + beads.length) % beads.length] as KnotBead\n  const after = beads[(index + 1) % beads.length] as KnotBead\n  const dx = after.x - before.x\n  const dy = after.y - before.y\n  const length = Math.hypot(dx, dy) || 1\n  return { tx: dx / length, ty: dy / length, step: length / 2 }\n}\n\n/** A glass tube: pale where it faces you, light gathered on the side away from the source, one sharp glint. */\nfunction shadePixel(data: Uint8ClampedArray, offset: number, shade: KnotShade, nx: number, ny: number, nz: number, near: number, cover: number) {\n  const facing = nx * LIGHT.x + ny * LIGHT.y + nz * LIGHT.z\n  const fade = (1 - near) * (shade.solid ? FAR_FADE_SOLID : FAR_FADE)\n  const body = 1 - SHADOW * (1 - Math.max(facing, 0))\n  const pale = shade.solid ? 0 : PALE_BODY * nz\n  const reflected = Math.max(2 * facing * nz - LIGHT.z, 0)\n  const white = shade.solid ? 0 : Math.min(SHEEN * reflected ** SHEEN_POWER + GLINT * reflected ** GLINT_POWER * (0.4 + near * 0.6), 1)\n  const glow = shade.solid ? 0 : GLOW * Math.max(-facing, 0)\n  for (let channel = 0; channel < 3; channel += 1) {\n    const accent = shade.accent[channel] as number\n    const tint = mix(accent, shade.surface[channel] as number, fade)\n    data[offset + channel] = mix(mix(mix(tint, 255, pale) * body, accent, glow), 255, white)\n  }\n  data[offset + 3] = (shade.solid ? 1 : mix(1, GLASS_ALPHA, nz * nz)) * cover * 255\n}\n\ninterface Slice {\n  tx: number\n  ty: number\n  step: number\n  radius: number\n  /** The strand turns hard on screen here, so slices would fan apart with gaps between them. */\n  fold: boolean\n}\n\ninterface Claims {\n  depths: Float32Array\n  owners: Int32Array\n  across: Float32Array\n  along: Float32Array\n}\n\nfunction sliceAt(beads: readonly KnotBead[], index: number, size: number): Slice {\n  const bead = beads[index] as KnotBead\n  const before = beads[(index - 1 + beads.length) % beads.length] as KnotBead\n  const after = beads[(index + 1) % beads.length] as KnotBead\n  const radius = (size * TUBE_SHARE * bead.scale) / 2\n  const inLength = Math.hypot(bead.x - before.x, bead.y - before.y) || 1\n  const outLength = Math.hypot(after.x - bead.x, after.y - bead.y) || 1\n  const turn = ((bead.x - before.x) * (after.x - bead.x) + (bead.y - before.y) * (after.y - bead.y)) / (inLength * outLength)\n  const heading = direction(beads, index)\n  return { ...heading, radius, fold: turn < FOLD_TURN || heading.step < radius * FOLD_STEP }\n}\n\n/** Takes every pixel of this bead's slice that is nearer than what is there. A fold also takes a ball, which only wins where no slice reached. */\nfunction claimBead(claims: Claims, bead: KnotBead, index: number, { tx, ty, step, radius, fold }: Slice, size: number, world: number) {\n  const reach = Math.max(step * SLICE_REACH, 1)\n  const edge = radius + 0.5\n  // The box of this slice alone, not of the whole ball: most of the time saved is here.\n  const spanX = fold ? edge : Math.abs(tx) * reach + Math.abs(ty) * edge\n  const spanY = fold ? edge : Math.abs(ty) * reach + Math.abs(tx) * edge\n  const right = Math.min(Math.ceil(bead.x + spanX), size - 1)\n  const bottom = Math.min(Math.ceil(bead.y + spanY), size - 1)\n  for (let y = Math.max(Math.floor(bead.y - spanY), 0); y <= bottom; y += 1) {\n    for (let x = Math.max(Math.floor(bead.x - spanX), 0); x <= right; x += 1) {\n      const dx = x + 0.5 - bead.x\n      const dy = y + 0.5 - bead.y\n      const along = dx * tx + dy * ty\n      const across = dy * tx - dx * ty\n      const inSlice = Math.abs(along) <= reach && Math.abs(across) <= edge\n      if (!inSlice && !(fold && along * along + across * across <= edge * edge)) continue\n      const axial = inSlice ? 0 : along\n      const depth = bead.depth * world + Math.sqrt(Math.max(radius * radius - across * across - axial * axial, 0))\n      const pixel = y * size + x\n      if (depth <= (claims.depths[pixel] as number)) continue\n      claims.depths[pixel] = depth\n      claims.owners[pixel] = index\n      claims.across[pixel] = across\n      claims.along[pixel] = axial\n    }\n  }\n}\n\n/**\n * Paints the path as a tube into `data`, an RGBA buffer the caller owns and reuses, which is why this writes in place.\n * Each bead claims a thin slice across the tube, and a depth test per pixel settles every crossing without sorting.\n * A pixel is shaded once at the end, only by its distance from the centre line, so the shade cannot change along a\n * strand. Stamping shaded balls or strokes instead gave seams at the joints, or blobs where one ball ended up on top.\n */\nexport function rasterizeKnot(beads: readonly KnotBead[], size: number, shade: KnotShade, data: Uint8ClampedArray) {\n  data.fill(0)\n  const count = size * size\n  const claims: Claims = {\n    depths: new Float32Array(count).fill(-Infinity),\n    owners: new Int32Array(count).fill(-1),\n    across: new Float32Array(count),\n    along: new Float32Array(count),\n  }\n  const slices = beads.map((_, index) => sliceAt(beads, index, size))\n  beads.forEach((bead, index) => claimBead(claims, bead, index, slices[index] as Slice, size, size * FILL_SHARE))\n  for (let pixel = 0; pixel < count; pixel += 1) {\n    const owner = claims.owners[pixel] as number\n    if (owner < 0) continue\n    const bead = beads[owner] as KnotBead\n    const { tx, ty, radius } = slices[owner] as Slice\n    const across = claims.across[pixel] as number\n    const along = claims.along[pixel] as number\n    const nz = Math.sqrt(Math.max(radius * radius - across * across - along * along, 0)) / radius\n    const near = (Math.min(Math.max(bead.depth, -1), 1) + 1) / 2\n    const cover = Math.min(radius + 0.5 - Math.hypot(across, along), 1)\n    shadePixel(data, pixel * 4, shade, (tx * along - ty * across) / radius, (ty * along + tx * across) / radius, nz, near, cover)\n  }\n}\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "display"
  ],
  "type": "registry:ui"
}