{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fx-fireworks",
  "type": "registry:component",
  "title": "Fireworks",
  "description": "A decorative field of bursting sparks",
  "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/fireworks.tsx",
      "target": "@ui/gpuixui/fx/fireworks.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  countOf,\n  durationOf,\n  seedOf,\n  sizeRangeOf,\n  useTheme,\n} from \"../components/authoring.js\";\nimport {\n  fireworkBurstCap,\n  fireworkBurstFloor,\n  fireworkBurstMs,\n  fireworkBurstCapMs,\n  fireworkBursts,\n  fireworkField,\n  fireworkMaxSize,\n  fireworkMinSize,\n  fireworkSparks,\n  fireworkSparksCap,\n  sparkPhases,\n  sparkRest,\n  type FireworkSpark,\n} from \"./fireworks/logic.js\";\n\nexport interface FireworksState {\n  readonly count: number;\n  readonly reducedMotion: boolean;\n  readonly width: number;\n  readonly height: number;\n}\n\nexport interface FireworksProps extends Omit<Props, \"children\" | \"style\"> {\n  readonly bursts?: number;\n\n  readonly sparks?: number;\n\n  readonly seed?: number;\n\n  readonly minSize?: number;\n\n  readonly maxSize?: number;\n\n  readonly color?: string;\n\n  readonly burstMs?: number;\n\n  readonly level?: MotionLevel;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<FireworksState>;\n}\n\ninterface SparkProps {\n  readonly spec: FireworkSpark;\n  readonly ink: string;\n  readonly radius: number;\n  readonly still: boolean;\n}\n\nconst Spark = ({ spec, ink, radius, still }: SparkProps) => {\n  const [life, setLife] = useState({ lap: 0, fading: false });\n  const phases = sparkPhases(spec);\n  const rest = sparkRest(spec);\n  const phase = life.fading ? phases.fade : phases.fly;\n  const motion: MotionProps = {\n    initial: life.fading ? false : { left: spec.x, top: spec.y, opacity: 0 },\n    animate: { left: phase.left, top: phase.top, opacity: phase.opacity },\n    transition: {\n      duration: phase.durationMs / 1000,\n      delay: phase.delayMs / 1000,\n      ease: \"easeOut\",\n    },\n  };\n\n  return (\n    <div\n      key={life.lap}\n      testId={`spark-${spec.key}`}\n      {...(still\n        ? {}\n        : {\n            motion,\n            onMotionComplete: () =>\n              setLife((current) =>\n                current.fading\n                  ? { lap: current.lap + 1, fading: false }\n                  : { lap: current.lap, fading: true },\n              ),\n          })}\n      style={{\n        position: \"absolute\",\n        left: still ? rest.left : spec.x,\n        top: still ? rest.top : spec.y,\n        width: spec.size,\n        height: spec.size,\n        borderRadius: radius,\n        backgroundColor: ink,\n        opacity: still ? spec.peak : 0,\n\n        pointerEvents: \"none\",\n      }}\n    />\n  );\n};\n\nexport const Fireworks = ({\n  bursts,\n  sparks,\n  seed,\n  minSize,\n  maxSize,\n  color,\n  burstMs,\n  level = \"slow\",\n  className,\n  style,\n  ...rest\n}: FireworksProps) => {\n  const theme = useTheme();\n  const preference = useMotionPreference();\n  const timing = useSurfaceTiming(level);\n  const burstCount = countOf(\n    Option.fromNullishOr(bursts),\n    fireworkBursts,\n    fireworkBurstCap,\n  );\n  const sparkCount = countOf(\n    Option.fromNullishOr(sparks),\n    fireworkSparks,\n    fireworkSparksCap,\n  );\n  const sizes = sizeRangeOf(\n    Option.fromNullishOr(minSize),\n    Option.fromNullishOr(maxSize),\n    fireworkMinSize,\n    fireworkMaxSize,\n  );\n  const layoutSeed = seedOf(Option.fromNullishOr(seed));\n  const burst = durationOf(\n    Option.fromNullishOr(burstMs),\n    fireworkBurstMs,\n    fireworkBurstFloor,\n    fireworkBurstCapMs,\n  );\n  const ink = color ?? theme.colors.primary;\n  const still = preference === \"reduced\";\n\n  const [box, setBox] = useState<\n    Option.Option<{ readonly width: number; readonly height: number }>\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 measured = Option.getOrElse(box, () => ({ width: 0, height: 0 }));\n  const specs: ReadonlyArray<FireworkSpark> =\n    measured.width > 0 && measured.height > 0\n      ? fireworkField({\n          width: measured.width,\n          height: measured.height,\n          bursts: burstCount,\n          sparks: sparkCount,\n          seed: layoutSeed,\n          minSize: sizes.min,\n          maxSize: sizes.max,\n          burstMs: burst,\n        })\n      : [];\n\n  const state: FireworksState = {\n    count: Arr.length(specs),\n    reducedMotion: still,\n    width: measured.width,\n    height: measured.height,\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        <Spark\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 fireworksMeta = {\n  name: \"Fireworks\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"partial\",\n  limitations: [\n    \"a spark is a dot that travels a straight line: the runtime has no transform (upstream issue #102), no canvas and no blur, so a spark cannot stretch into a streak, trail behind itself or arc under gravity\",\n    \"a spark's life is two phases — fly brightening, then fade at the ring — because the runtime tweens one opacity target at a time\",\n    \"a fade completed by the tween re-keys the element into a fresh spark at the centre; the restart is invisible because the spark is at zero opacity both before the fly and after the fade\",\n    \"the field measures its own box, so the caller must bound it; before the first layout it paints nothing\",\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 sequence from the same seed, which restarts every burst (a tween cannot be resumed at an arbitrary progress)\",\n  ],\n  docs: \"docs/fireworks.mdx\",\n  example: \"examples/fireworks.example.tsx\",\n  testFile: \"src/behaviour/fireworks.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/fx/src/fireworks/logic.ts",
      "target": "@ui/gpuixui/fx/fireworks/logic.ts",
      "type": "registry:lib",
      "content": "import * as Arr from \"effect/Array\";\nimport { paintable, seededUnit, tenth } from \"../../components/authoring.js\";\n\nexport const fireworkBursts = 3;\n\nexport const fireworkBurstCap = 6;\n\nexport const fireworkSparks = 18;\n\nexport const fireworkSparksCap = 40;\n\nexport const fireworkMinSize = 2;\nexport const fireworkMaxSize = 4;\n\nexport const fireworkBurstMs = 1_400;\n\nexport const fireworkBurstFloor = 400;\n\nexport const fireworkBurstCapMs = 12_000;\n\nconst flyShare = 0.7;\n\nconst peakFloor = 0.5;\nconst peakCeiling = 0.95;\n\nconst ringFloorShare = 0.55;\nconst ringCeilingShare = 0.95;\n\nconst centreFloorShare = 0.25;\nconst centreCeilingShare = 0.75;\n\nconst burstStaggerShare = 0.4;\n\nconst sparkJitterShare = 0.08;\n\nexport interface FireworkSpark {\n  readonly key: string;\n\n  readonly burst: number;\n\n  readonly x: number;\n  readonly y: number;\n\n  readonly midLeft: number;\n  readonly midTop: number;\n  readonly toLeft: number;\n  readonly toTop: number;\n  readonly size: number;\n\n  readonly peak: number;\n\n  readonly durationMs: number;\n\n  readonly delayMs: number;\n}\n\nexport interface FireworkFieldInput {\n  readonly width: number;\n  readonly height: number;\n  readonly bursts: number;\n  readonly sparks: number;\n  readonly seed: number;\n  readonly minSize: number;\n  readonly maxSize: number;\n  readonly burstMs: number;\n}\n\nexport interface SparkPhase {\n  readonly left: number;\n  readonly top: number;\n  readonly opacity: number;\n\n  readonly durationMs: number;\n\n  readonly delayMs: number;\n}\n\nexport interface SparkPhases {\n  readonly fly: SparkPhase;\n  readonly fade: SparkPhase;\n}\n\nexport const fireworkField = (\n  input: FireworkFieldInput,\n): ReadonlyArray<FireworkSpark> => {\n  if (!paintable(input.width) || !paintable(input.height)) return [];\n  const bursts = Math.min(\n    Math.max(Math.round(input.bursts), 0),\n    fireworkBurstCap,\n  );\n  const sparks = Math.min(\n    Math.max(Math.round(input.sparks), 0),\n    fireworkSparksCap,\n  );\n  if (bursts === 0 || sparks === 0) return [];\n  const maxSize = Math.max(input.maxSize, input.minSize);\n  const step = (Math.PI * 2) / sparks;\n\n  return Arr.flatMap(\n    Arr.makeBy(bursts, (index) => index),\n    (burst) => {\n      const centreX = tenth(\n        input.width *\n          (centreFloorShare +\n            seededUnit(input.seed, burst, 0) *\n              (centreCeilingShare - centreFloorShare)),\n      );\n      const centreY = tenth(\n        input.height *\n          (centreFloorShare +\n            seededUnit(input.seed, burst, 1) *\n              (centreCeilingShare - centreFloorShare)),\n      );\n      const burstDelayMs = burst * input.burstMs * burstStaggerShare;\n\n      return Arr.makeBy(sparks, (index): FireworkSpark => {\n        const slot = burst * 64 + index;\n        const size = Math.round(\n          input.minSize +\n            seededUnit(input.seed, slot, 4) * (maxSize - input.minSize),\n        );\n        const angle =\n          step * index + (seededUnit(input.seed, slot, 2) - 0.5) * step * 0.6;\n\n        const room = Math.max(\n          Math.min(\n            centreX - size,\n            input.width - size - centreX,\n            centreY - size,\n            input.height - size - centreY,\n          ),\n          0,\n        );\n        const radius =\n          room *\n          (ringFloorShare +\n            seededUnit(input.seed, slot, 3) *\n              (ringCeilingShare - ringFloorShare));\n        const toLeft = tenth(centreX + Math.cos(angle) * radius);\n        const toTop = tenth(centreY + Math.sin(angle) * radius);\n        const durationMs = Math.round(\n          input.burstMs * (0.6 + seededUnit(input.seed, slot, 6) * 0.4),\n        );\n\n        return {\n          key: `${burst}-${index}`,\n          burst,\n          x: centreX,\n          y: centreY,\n          midLeft: tenth(centreX + (toLeft - centreX) * flyShare),\n          midTop: tenth(centreY + (toTop - centreY) * flyShare),\n          toLeft,\n          toTop,\n          size: Math.max(size, 1),\n          peak: tenth(\n            peakFloor +\n              seededUnit(input.seed, slot, 5) * (peakCeiling - peakFloor),\n          ),\n          durationMs,\n          delayMs: Math.round(\n            burstDelayMs +\n              seededUnit(input.seed, slot, 7) *\n                input.burstMs *\n                sparkJitterShare,\n          ),\n        };\n      });\n    },\n  );\n};\n\nexport const sparkPhases = (spec: FireworkSpark): SparkPhases => {\n  const flyMs = Math.round(spec.durationMs * flyShare);\n  return {\n    fly: {\n      left: spec.midLeft,\n      top: spec.midTop,\n      opacity: spec.peak,\n      durationMs: flyMs,\n      delayMs: spec.delayMs,\n    },\n    fade: {\n      left: spec.toLeft,\n      top: spec.toTop,\n      opacity: 0,\n      durationMs: Math.max(spec.durationMs - flyMs, 0),\n      delayMs: 0,\n    },\n  };\n};\n\nexport const sparkRest = (\n  spec: FireworkSpark,\n): { readonly left: number; readonly top: number } => ({\n  left: spec.midLeft,\n  top: spec.midTop,\n});\n"
    }
  ],
  "docs": "[Fireworks](https://gpuixui.sudokw.com/effects/fireworks) — 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/fireworks",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}