{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fx-particles",
  "type": "registry:component",
  "title": "Particles",
  "description": "A decorative field of drifting motes",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-components.json",
    "https://gpuixui.sudokw.com/gpuix-motion.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/fx/src/particles.tsx",
      "target": "@ui/gpuixui/fx/particles.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { EventPayload, MotionProps, Props } from \"@gpuix/react\";\nimport {\n  mergeStyles,\n  resolveStyle,\n  type StateStyle,\n} from \"@gpuix/react/floating\";\nimport type { MotionLevel } from \"../motion/timing.js\";\nimport { cn } from \"../tw/index.js\";\nimport * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\nimport { useState } from \"react\";\nimport {\n  measuredBox,\n  fadeOnly,\n  useMotionPreference,\n  useSurfaceTiming,\n  recipeStyle,\n  useTheme,\n  countOf,\n  durationOf,\n  seedOf,\n  sizeRangeOf,\n} from \"../components/authoring.js\";\nimport {\n  particleCount,\n  particleCountCap,\n  particleDriftCap,\n  particleDriftFloor,\n  particleDriftMs,\n  particleField,\n  particleMaxSize,\n  particleMinSize,\n  particleTravel,\n  type ParticleDirection,\n  type ParticleSpec,\n} from \"./particles/logic.js\";\n\nexport interface ParticlesState {\n  readonly count: number;\n  readonly reducedMotion: boolean;\n  readonly width: number;\n  readonly height: number;\n}\n\nexport interface ParticlesProps extends Omit<Props, \"children\" | \"style\"> {\n  readonly count?: number;\n\n  readonly seed?: number;\n\n  readonly minSize?: number;\n\n  readonly maxSize?: number;\n\n  readonly color?: string;\n\n  readonly driftMs?: number;\n\n  readonly level?: MotionLevel;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<ParticlesState>;\n}\n\ninterface MoteProps {\n  readonly spec: ParticleSpec;\n  readonly ink: string;\n  readonly radius: number;\n  readonly still: boolean;\n}\n\nconst Mote = ({ spec, ink, radius, still }: MoteProps) => {\n  const [direction, setDirection] = useState<ParticleDirection>(1);\n  const travel = particleTravel(spec, direction);\n  const motion: MotionProps = {\n    initial: { left: spec.x, top: spec.y },\n    animate: { left: travel.left, top: travel.top },\n    transition: { duration: spec.durationMs / 1000, ease: \"easeInOut\" },\n  };\n\n  return (\n    <div\n      testId={`particle-${spec.key}`}\n      {...(still\n        ? {}\n        : {\n            motion,\n            onMotionComplete: () =>\n              setDirection((current) => (current === 1 ? -1 : 1)),\n          })}\n      style={{\n        position: \"absolute\",\n        left: spec.x,\n        top: spec.y,\n        width: spec.size,\n        height: spec.size,\n        borderRadius: radius,\n        backgroundColor: ink,\n        opacity: spec.opacity,\n\n        pointerEvents: \"none\" as const,\n      }}\n    />\n  );\n};\n\nexport const Particles = ({\n  count,\n  seed,\n  minSize,\n  maxSize,\n  color,\n  driftMs,\n  level = \"slow\",\n  className,\n  style,\n  ...rest\n}: ParticlesProps) => {\n  const theme = useTheme();\n  const preference = useMotionPreference();\n  const timing = useSurfaceTiming(level);\n  const fieldCount = countOf(\n    Option.fromNullishOr(count),\n    particleCount,\n    particleCountCap,\n  );\n  const sizes = sizeRangeOf(\n    Option.fromNullishOr(minSize),\n    Option.fromNullishOr(maxSize),\n    particleMinSize,\n    particleMaxSize,\n  );\n  const layoutSeed = seedOf(Option.fromNullishOr(seed));\n  const drift = durationOf(\n    Option.fromNullishOr(driftMs),\n    particleDriftMs,\n    particleDriftFloor,\n    particleDriftCap,\n  );\n  const ink = color ?? theme.colors.primary;\n  const still = preference === \"reduced\";\n\n  const [box, setBox] = useState<\n    Option.Option<{\n      readonly width: number;\n      readonly height: number;\n    }>\n  >(Option.none());\n\n  const noteBox = (event: EventPayload): void => {\n    Option.match(measuredBox(event), {\n      onNone: () => undefined,\n      onSome: (next) =>\n        setBox((held) =>\n          Option.match(held, {\n            onNone: () => Option.some(next),\n            onSome: (current) =>\n              current.width === next.width && current.height === next.height\n                ? held\n                : Option.some(next),\n          }),\n        ),\n    });\n  };\n\n  const specs: ReadonlyArray<ParticleSpec> = Option.match(box, {\n    onNone: () => [],\n    onSome: (measured) =>\n      particleField({\n        width: measured.width,\n        height: measured.height,\n        count: fieldCount,\n        seed: layoutSeed,\n        minSize: sizes.min,\n        maxSize: sizes.max,\n        driftMs: drift,\n      }),\n  });\n\n  const state: ParticlesState = {\n    count: Arr.length(specs),\n    reducedMotion: still,\n    width: Option.match(box, {\n      onNone: () => 0,\n      onSome: (measured) => measured.width,\n    }),\n    height: Option.match(box, {\n      onNone: () => 0,\n      onSome: (measured) => measured.height,\n    }),\n  };\n\n  return (\n    <div\n      {...rest}\n      onLayout={noteBox}\n      motion={{ ...fadeOnly, transition: timing.enter }}\n      style={mergeStyles(\n        mergeStyles(recipeStyle(cn(className), theme), {\n          position: \"relative\",\n          overflow: \"hidden\",\n\n          pointerEvents: \"none\",\n        }),\n        resolveStyle(style, state),\n      )}\n    >\n      {Arr.map(specs, (spec) => (\n        <Mote\n          key={spec.key}\n          spec={spec}\n          ink={ink}\n          radius={theme.radius.full}\n          still={still}\n        />\n      ))}\n    </div>\n  );\n};\n\nexport const particlesMeta = {\n  name: \"Particles\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"partial\",\n  limitations: [\n    \"a mote drifts by tweening left/top inside a clipped box: the runtime has no transform (upstream issue #102) and no 2D canvas, so it never translates or scales a layer\",\n    \"the field measures its own box, so the caller must bound it; before the first layout it paints nothing\",\n    \"the runtime tweens a target once, so a float is a ping-pong driven by onMotionComplete; a hidden field keeps running until it is unmounted or count is 0\",\n    \"the field publishes no accessibility node and takes no pointer input: name the content it sits behind, never the field\",\n    \"a size change re-draws the field from the same seed, which restarts every leg (a tween cannot be resumed at an arbitrary progress)\",\n  ],\n  docs: \"docs/particles.mdx\",\n  example: \"examples/particles.example.tsx\",\n  testFile: \"src/behaviour/particles.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/fx/src/particles/logic.ts",
      "target": "@ui/gpuixui/fx/particles/logic.ts",
      "type": "registry:lib",
      "content": "import * as Arr from \"effect/Array\";\nimport { paintable, seededUnit, tenth } from \"../../components/authoring.js\";\n\nexport const particleCount = 24;\n\nexport const particleCountCap = 120;\n\nexport const particleMinSize = 2;\nexport const particleMaxSize = 5;\n\nexport const particleDriftMs = 14_000;\n\nexport const particleDriftFloor = 320;\n\nexport const particleDriftCap = 120_000;\n\nconst durationFloorShare = 0.75;\nconst durationCeilingShare = 1.25;\n\nconst driftShare = 0.08;\nconst driftFloor = 2;\nconst driftCeiling = 40;\n\nconst opacityFloor = 0.2;\nconst opacityCeiling = 0.55;\n\nexport interface ParticleSpec {\n  readonly key: string;\n\n  readonly x: number;\n  readonly y: number;\n  readonly size: number;\n\n  readonly driftX: number;\n  readonly driftY: number;\n\n  readonly durationMs: number;\n\n  readonly opacity: number;\n}\n\nexport interface ParticleFieldInput {\n  readonly width: number;\n  readonly height: number;\n  readonly count: number;\n  readonly seed: number;\n  readonly minSize: number;\n  readonly maxSize: number;\n  readonly driftMs: number;\n}\n\nexport type ParticleDirection = 1 | -1;\n\nexport interface ParticleTravel {\n  readonly left: number;\n  readonly top: number;\n}\n\nexport const particleAmplitude = (width: number, height: number): number => {\n  const shorter = Math.min(width, height);\n  if (!paintable(shorter)) return driftFloor;\n  return Math.min(Math.max(shorter * driftShare, driftFloor), driftCeiling);\n};\n\nexport const particleField = (\n  input: ParticleFieldInput,\n): ReadonlyArray<ParticleSpec> => {\n  if (!paintable(input.width) || !paintable(input.height)) return [];\n  const count = Math.min(\n    Math.max(Math.round(input.count), 0),\n    particleCountCap,\n  );\n  if (count === 0) return [];\n  const amplitude = particleAmplitude(input.width, input.height);\n  const maxSize = Math.max(input.maxSize, input.minSize);\n\n  const originX = Math.min(maxSize + amplitude, input.width / 2);\n  const originY = Math.min(maxSize + amplitude, input.height / 2);\n  const spanX = Math.max(input.width - originX * 2, 0);\n  const spanY = Math.max(input.height - originY * 2, 0);\n\n  return Arr.makeBy(count, (index) => {\n    const angle = seededUnit(input.seed, index, 3) * Math.PI * 2;\n    const size = Math.round(\n      input.minSize +\n        seededUnit(input.seed, index, 2) * (maxSize - input.minSize),\n    );\n    return {\n      key: String(index),\n      x: tenth(originX + seededUnit(input.seed, index, 0) * spanX),\n      y: tenth(originY + seededUnit(input.seed, index, 1) * spanY),\n      size: Math.max(size, 1),\n      driftX: tenth(Math.cos(angle) * amplitude),\n      driftY: tenth(Math.sin(angle) * amplitude),\n      durationMs: Math.round(\n        input.driftMs *\n          (durationFloorShare +\n            seededUnit(input.seed, index, 4) *\n              (durationCeilingShare - durationFloorShare)),\n      ),\n      opacity: tenth(\n        opacityFloor +\n          seededUnit(input.seed, index, 5) * (opacityCeiling - opacityFloor),\n      ),\n    };\n  });\n};\n\nexport const particleTravel = (\n  spec: ParticleSpec,\n  direction: ParticleDirection,\n): ParticleTravel =>\n  direction === 1\n    ? { left: tenth(spec.x + spec.driftX), top: tenth(spec.y + spec.driftY) }\n    : { left: spec.x, top: spec.y };\n"
    }
  ],
  "docs": "[Particles](https://gpuixui.sudokw.com/effects/particles) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/effects/particles",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}