{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "orb",
  "type": "registry:component",
  "title": "Orb",
  "description": "A softly morphing sphere in the highlight colour, lit at its rim so it reads on light and dark grounds, leaning gently toward the pointer.",
  "categories": [
    "three"
  ],
  "dependencies": [
    "@react-three/fiber",
    "three"
  ],
  "devDependencies": [
    "@types/three"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/theme-color"
  ],
  "files": [
    {
      "path": "registry/three/orb.tsx",
      "type": "registry:component",
      "target": "components/three/orb.tsx",
      "content": "\"use client\";\n/**\n * @name orb\n * @category three\n * @description A softly morphing sphere in the highlight colour, lit at its rim so it reads on light and dark grounds, leaning gently toward the pointer.\n * @when A calm focal object for a hero or an empty state. Use it inside scene. For many small elements use particle-field; for a product or object of your own use model-stage.\n * @example\n * <Scene aspect={1} className=\"max-w-md\">\n *   <Orb />\n * </Scene>\n *\n * <Scene aspect={16 / 9}>\n *   <Orb color=\"--chart-2\" speed={0.6} distortion={0.5} detail={32} />\n * </Scene>\n */\n/* eslint-disable react-hooks/immutability -- three.js objects (uniforms, the canvas, scene nodes) are changed in place by design, in effects and frames, never during render */\nimport { useFrame, useThree } from \"@react-three/fiber\";\nimport { useEffect, useMemo, useRef } from \"react\";\nimport { Color, Vector2, type Mesh } from \"three\";\nimport { useThemeColors } from \"@/lib/theme-color\";\n\nexport type OrbProps = {\n  /** The CSS variable the orb takes its colour from. */\n  color?: string;\n  /** How fast the surface moves. 1 is a slow breath; 0 holds it still. */\n  speed?: number;\n  /** How far the surface is pushed in and out, as a share of the radius (0 to about 0.6). */\n  distortion?: number;\n  /** Subdivisions of the sphere. More is smoother and costs more; 8 to 48. */\n  detail?: number;\n  /** Radius in scene units. */\n  radius?: number;\n  /** Where it sits in the scene. */\n  position?: [number, number, number];\n};\n\nconst VERTEX = /* glsl */ `\nuniform float uTime;\nuniform float uDistortion;\nuniform vec2 uPointer;\nvarying vec3 vNormal;\nvarying vec3 vView;\n\nvec3 hash3(vec3 p) {\n  p = vec3(dot(p, vec3(127.1, 311.7, 74.7)), dot(p, vec3(269.5, 183.3, 246.1)), dot(p, vec3(113.5, 271.9, 124.6)));\n  return -1.0 + 2.0 * fract(sin(p) * 43758.5453123);\n}\n\n// Gradient noise, roughly -1 to 1.\nfloat noise(vec3 p) {\n  vec3 i = floor(p);\n  vec3 f = fract(p);\n  vec3 u = f * f * (3.0 - 2.0 * f);\n  return mix(\n    mix(\n      mix(dot(hash3(i), f), dot(hash3(i + vec3(1.0, 0.0, 0.0)), f - vec3(1.0, 0.0, 0.0)), u.x),\n      mix(dot(hash3(i + vec3(0.0, 1.0, 0.0)), f - vec3(0.0, 1.0, 0.0)), dot(hash3(i + vec3(1.0, 1.0, 0.0)), f - vec3(1.0, 1.0, 0.0)), u.x),\n      u.y\n    ),\n    mix(\n      mix(dot(hash3(i + vec3(0.0, 0.0, 1.0)), f - vec3(0.0, 0.0, 1.0)), dot(hash3(i + vec3(1.0, 0.0, 1.0)), f - vec3(1.0, 0.0, 1.0)), u.x),\n      mix(dot(hash3(i + vec3(0.0, 1.0, 1.0)), f - vec3(0.0, 1.0, 1.0)), dot(hash3(i + vec3(1.0, 1.0, 1.0)), f - vec3(1.0, 1.0, 1.0)), u.x),\n      u.y\n    ),\n    u.z\n  );\n}\n\n// A point on the unit sphere, pushed along its own direction.\nvec3 surface(vec3 direction, float radius) {\n  vec3 q = direction * 1.15 + vec3(uPointer * 0.35, 0.0) + vec3(0.0, 0.0, uTime * 0.25);\n  float n = noise(q) + 0.35 * noise(q * 2.3 + vec3(uTime * 0.2));\n  return direction * radius * (1.0 + n * uDistortion);\n}\n\nvoid main() {\n  float radius = length(position);\n  vec3 direction = position / radius;\n  // The normal of the moved surface comes from two neighbours on the sphere, moved the same way.\n  vec3 axis = abs(direction.y) > 0.99 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);\n  vec3 tangent = normalize(cross(axis, direction));\n  vec3 bitangent = cross(direction, tangent);\n  float eps = 0.02;\n  vec3 moved = surface(direction, radius);\n  vec3 a = surface(normalize(direction + tangent * eps), radius);\n  vec3 b = surface(normalize(direction + bitangent * eps), radius);\n  vec3 movedNormal = normalize(cross(a - moved, b - moved));\n  vec4 viewPosition = modelViewMatrix * vec4(moved, 1.0);\n  vNormal = normalize(normalMatrix * movedNormal);\n  vView = -viewPosition.xyz;\n  gl_Position = projectionMatrix * viewPosition;\n}\n`;\n\nconst FRAGMENT = /* glsl */ `\nuniform vec3 uColor;\nuniform vec3 uRim;\nvarying vec3 vNormal;\nvarying vec3 vView;\n\nvoid main() {\n  vec3 normal = normalize(vNormal);\n  vec3 view = normalize(vView);\n  float facing = clamp(dot(normal, view), 0.0, 1.0);\n  float fresnel = pow(1.0 - facing, 2.2);\n  // One soft light from the upper left gives the form; the rim takes the text colour, which is dark on a\n  // light ground and light on a dark one, so the edge always separates from the page.\n  float light = 0.88 + 0.12 * dot(normal, normalize(vec3(-0.4, 0.7, 0.6)));\n  vec3 color = mix(uColor * light, uRim, fresnel * 0.55);\n  gl_FragColor = vec4(color, 1.0);\n  #include <colorspace_fragment>\n}\n`;\n\nexport function Orb({ color = \"--highlight\", speed = 1, distortion = 0.3, detail = 24, radius = 1.6, position }: OrbProps) {\n  const mesh = useRef<Mesh>(null);\n  const time = useRef(0);\n  const canvas = useThree((state) => state.gl.domElement);\n  const invalidate = useThree((state) => state.invalidate);\n  const colors = useThemeColors([color, \"--foreground\"], canvas);\n  const fill = colors[color] ?? \"\";\n  const rim = colors[\"--foreground\"] ?? \"\";\n\n  // Uniform holders are plain objects: nothing here holds GPU memory. The geometry and the material are\n  // created declaratively below, so react-three-fiber disposes of them.\n  const uniforms = useMemo(\n    () => ({\n      uTime: { value: 0 },\n      uDistortion: { value: 0 },\n      uPointer: { value: new Vector2() },\n      uColor: { value: new Color() },\n      uRim: { value: new Color() },\n    }),\n    [],\n  );\n\n  useEffect(() => {\n    uniforms.uColor.value.set(fill);\n    uniforms.uRim.value.set(rim);\n    invalidate();\n  }, [uniforms, fill, rim, invalidate]);\n\n  useEffect(() => {\n    uniforms.uDistortion.value = distortion;\n    invalidate();\n  }, [uniforms, distortion, invalidate]);\n\n  useFrame((state, delta) => {\n    // A long gap (a hidden tab, a paused scene) must not jump the surface.\n    const dt = Math.min(delta, 0.1);\n    time.current += dt * speed;\n    uniforms.uTime.value = time.current;\n    const ease = 1 - Math.exp(-dt * 3);\n    const pointer = uniforms.uPointer.value;\n    pointer.x += (state.pointer.x - pointer.x) * ease;\n    pointer.y += (state.pointer.y - pointer.y) * ease;\n    const object = mesh.current;\n    if (object) {\n      object.rotation.y = pointer.x * 0.35;\n      object.rotation.x = -pointer.y * 0.25;\n    }\n  });\n\n  const segments = Math.max(1, Math.min(64, Math.round(detail)));\n\n  return (\n    <mesh ref={mesh} position={position}>\n      <icosahedronGeometry args={[radius, segments]} />\n      <shaderMaterial args={[{ uniforms, vertexShader: VERTEX, fragmentShader: FRAGMENT }]} />\n    </mesh>\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "three",
    "when": "A calm focal object for a hero or an empty state. Use it inside scene. For many small elements use particle-field; for a product or object of your own use model-stage.",
    "example": "<Scene aspect={1} className=\"max-w-md\">\n  <Orb />\n</Scene>\n\n<Scene aspect={16 / 9}>\n  <Orb color=\"--chart-2\" speed={0.6} distortion={0.5} detail={32} />\n</Scene>",
    "client": true
  }
}
