{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "caption-particle-burst",
  "title": "Caption Particle Burst",
  "description": "Spoken words emit seeded multicolored particles with outward motion, shrink, and fade.",
  "dependencies": [
    "@editframe/react"
  ],
  "files": [
    {
      "path": "registry/bases/editframe/components/caption-particle-burst/index.tsx",
      "content": "// Adapted from HyperFrames captions (https://github.com/heygen-com/hyperframes).\n// Copyright 2026 HeyGen, Inc., licensed under the Apache License, Version 2.0.\n// Modifications for framecn are licensed under the MIT License.\n\"use client\";\n\nimport { Timegroup, useTimingInfo } from \"@editframe/react\";\nimport { useMemo } from \"react\";\n\nexport interface CaptionWord {\n  text: string;\n  start: number;\n  end: number;\n}\n\nexport interface CaptionParticleBurstProps {\n  words?: CaptionWord[];\n  color?: string;\n  burstColor?: string;\n  fontSize?: number;\n  fontWeight?: number | string;\n  background?: string;\n  speed?: number;\n  fps?: number;\n  durationInFrames?: number;\n  width?: number;\n  height?: number;\n  className?: string;\n}\n\nconst DEFAULT_WORDS: CaptionWord[] = [\n  { end: 0.35, start: 0, text: \"Every\" },\n  { end: 0.65, start: 0.35, text: \"great\" },\n  { end: 1, start: 0.65, text: \"video\" },\n  { end: 1.45, start: 1.1, text: \"starts\" },\n  { end: 1.65, start: 1.45, text: \"with\" },\n  { end: 1.8, start: 1.65, text: \"a\" },\n  { end: 2.15, start: 1.8, text: \"single\" },\n  { end: 2.7, start: 2.15, text: \"frame.\" },\n  { end: 3.2, start: 3, text: \"No\" },\n  { end: 3.9, start: 3.2, text: \"timelines.\" },\n  { end: 4.2, start: 4, text: \"No\" },\n  { end: 4.5, start: 4.2, text: \"drag\" },\n  { end: 4.65, start: 4.5, text: \"and\" },\n  { end: 5.1, start: 4.65, text: \"drop.\" },\n  { end: 5.55, start: 5.3, text: \"Just\" },\n  { end: 6, start: 5.55, text: \"code.\" },\n];\n\nconst WORDS_PER_GROUP = 3;\n\nconst PARTICLE_COLORS = [\n  \"#FF6B35\",\n  \"#FF3C78\",\n  \"#9B5DE5\",\n  \"#00BBF9\",\n  \"#00F5D4\",\n  \"#ffffff\",\n  \"#F15BB5\",\n];\n\nconst particleValue = (seed: number) => {\n  const value = ((seed + 1) * 48_271) % 2_147_483_647;\n  return ((value * 48_271) % 2_147_483_647) / 2_147_483_647;\n};\n\nexport const CaptionParticleBurst = ({\n  words = DEFAULT_WORDS,\n  color = \"#ffffff\",\n  burstColor = \"#fbbf24\",\n  fontSize = 80,\n  fontWeight = 900,\n  background = \"#0a0a0a\",\n  speed = 1,\n  fps = 30,\n  durationInFrames = 180,\n  width = 1280,\n  height = 720,\n  className,\n}: CaptionParticleBurstProps) => {\n  const { ref, ownCurrentTimeMs } = useTimingInfo();\n  const safeSpeed = Math.max(0.01, speed);\n  const durationMs = (durationInFrames / fps) * 1000;\n  const time = (ownCurrentTimeMs / 1000) * safeSpeed;\n  const compositionEnd = (durationMs / 1000) * safeSpeed;\n  const padding = Math.min(80, Math.max(16, width * 0.06));\n  const groups = useMemo(() => {\n    const result: {\n      words: {\n        word: CaptionWord;\n        particles: { x: number; y: number; size: number }[];\n      }[];\n      start: number;\n      end: number;\n      characters: number;\n    }[] = [];\n    let current: {\n      word: CaptionWord;\n      particles: { x: number; y: number; size: number }[];\n    }[] = [];\n    const finish = () => {\n      if (!current.length) {\n        return;\n      }\n      result.push({\n        characters: current.reduce(\n          (count, { word }) => count + word.text.length + 1,\n          0\n        ),\n        end: (current.at(-1)?.word.end ?? 0) + 0.18,\n        start: current[0].word.start,\n        words: current,\n      });\n      current = [];\n    };\n    for (const [index, word] of words.entries()) {\n      const particles = Array.from({ length: 10 }, (_, pi) => {\n        const seed = index * 137 + pi * 17 + 99;\n        const angle = (pi / 10) * Math.PI * 2 + particleValue(seed) * 0.6;\n        const distance = 0.75 + particleValue(seed + 1) * 1.35;\n        return {\n          size: 0.045 + particleValue(seed + 2) * 0.075,\n          x: Math.cos(angle) * distance,\n          y: -Math.sin(angle) * distance * 0.65,\n        };\n      });\n      current.push({ particles, word });\n      const next = words[index + 1];\n      if (\n        current.length >= WORDS_PER_GROUP ||\n        /[.!?,;:][\"')\\]]?$/u.test(word.text) ||\n        !next ||\n        next.start - word.end >= 0.15 - 1e-6\n      ) {\n        finish();\n      }\n    }\n    finish();\n    for (const [index, group] of result.entries()) {\n      group.end = Math.min(group.end, result[index + 1]?.start ?? Infinity);\n    }\n    return result;\n  }, [words]);\n\n  return (\n    <Timegroup\n      ref={ref}\n      className={className}\n      duration={`${durationMs}ms`}\n      mode=\"fixed\"\n      style={{\n        background,\n        height,\n        overflow: \"hidden\",\n        position: \"relative\",\n        width,\n      }}\n    >\n      {groups.map((group, gi) => {\n        const end = Math.min(group.end, compositionEnd);\n        const visible = time >= group.start && time < end;\n        const fittedSize = Math.min(\n          fontSize,\n          height * 0.15,\n          (width - padding * 2) / Math.max(1, group.characters * 0.78)\n        );\n        const enter = Math.max(\n          0,\n          Math.min(\n            1,\n            (time - group.start) /\n              Math.min(0.18, Math.max(0.001, end - group.start) * 0.4)\n          )\n        );\n        return (\n          <div\n            key={gi}\n            data-caption-group={gi}\n            style={{\n              alignItems: \"baseline\",\n              bottom: height * 0.15,\n              boxSizing: \"border-box\",\n              display: \"flex\",\n              flexWrap: \"wrap\",\n              fontFamily: \"'Outfit', 'Arial Black', Arial, sans-serif\",\n              fontSize: fittedSize,\n              fontWeight,\n              gap: \"0.3em\",\n              justifyContent: \"center\",\n              left: 0,\n              letterSpacing: \"0.05em\",\n              lineHeight: 1.15,\n              opacity: visible ? 1 : 0,\n              overflow: \"visible\",\n              padding: `0 ${padding}px`,\n              position: \"absolute\",\n              right: 0,\n              textTransform: \"uppercase\",\n              transform: `scale(${0.92 + 0.08 * (1 - (1 - enter) ** 3)})`,\n            }}\n          >\n            {group.words.map(({ word, particles }, wi) => {\n              const active = time >= word.start && time < word.end;\n              const emphasis =\n                word.text.replaceAll(/[^\\p{L}\\p{N}]/gu, \"\").length >= 6;\n              const elapsed = time - word.start;\n              const burstDuration = Math.min(\n                0.55,\n                Math.max(0.001, end - word.start)\n              );\n              const pulse = active\n                ? Math.sin(\n                    Math.PI *\n                      Math.max(\n                        0,\n                        Math.min(\n                          1,\n                          elapsed /\n                            Math.min(\n                              0.16,\n                              Math.max(0.001, word.end - word.start)\n                            )\n                        )\n                      )\n                  )\n                : 0;\n              return (\n                <span\n                  key={wi}\n                  data-caption-word={word.text}\n                  style={{\n                    display: \"inline-block\",\n                    maxWidth: \"100%\",\n                    overflow: \"visible\",\n                    position: \"relative\",\n                  }}\n                >\n                  {particles.map((particle, pi) => {\n                    const progress =\n                      (elapsed / burstDuration - pi * 0.018) / (1 - pi * 0.018);\n                    const p = Math.max(0, Math.min(1, progress));\n                    const travel = 1 - (1 - p) ** 3;\n                    return (\n                      <span\n                        key={pi}\n                        aria-hidden\n                        data-caption-particle={pi}\n                        style={{\n                          background:\n                            pi % 3 === 0\n                              ? burstColor\n                              : PARTICLE_COLORS[pi % PARTICLE_COLORS.length],\n                          borderRadius: \"50%\",\n                          height: fittedSize * particle.size,\n                          left: \"50%\",\n                          opacity:\n                            visible && progress >= 0 && progress < 1\n                              ? (1 - p) ** 1.3\n                              : 0,\n                          pointerEvents: \"none\",\n                          position: \"absolute\",\n                          top: \"50%\",\n                          transform: `translate(-50%, -50%) translate(${particle.x * fittedSize * travel}px, ${particle.y * fittedSize * travel + fittedSize * 0.25 * p * p}px) scale(${1 - p * 0.65})`,\n                          width: fittedSize * particle.size,\n                          zIndex: 2,\n                        }}\n                      />\n                    );\n                  })}\n                  <span\n                    style={{\n                      color: emphasis && active ? burstColor : color,\n                      display: \"inline-block\",\n                      maxWidth: \"100%\",\n                      opacity: active ? 1 : 0.4,\n                      overflowWrap: \"anywhere\",\n                      transform: `scale(${1 + pulse * (emphasis ? 0.12 : 0.05)})`,\n                    }}\n                  >\n                    {word.text}\n                  </span>\n                </span>\n              );\n            })}\n          </div>\n        );\n      })}\n    </Timegroup>\n  );\n};\n",
      "type": "registry:component",
      "target": "components/framecn/caption-particle-burst.tsx"
    }
  ],
  "type": "registry:component"
}