{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "composer-loader",
  "type": "registry:block",
  "title": "Composer Loader",
  "description": "Loading state that wraps a chat composer — an iridescent light band orbiting the rim with a soft inward bloom, fading in while the agent works.",
  "dependencies": [],
  "registryDependencies": [
    "cx",
    "globals",
    "template-copy"
  ],
  "files": [
    {
      "path": "components/application/composer-loader/composer-loader.tsx",
      "content": "\"use client\";\n\nimport { useTemplateCopy } from \"@/components/foundations/template-copy/template-copy\";\n\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport { cx } from \"@/utils/cx\";\n\n/**\n * Composer Loader — a loading state that wraps a chat composer while the agent\n * works: an iridescent light band orbiting the pill's rim with a soft bloom\n * bleeding inward.\n *\n * The band is dash segments on an SVG stroke of the pill shape\n * (pathLength-normalized, so it travels at constant speed and bends around\n * the end caps), drawn at three scales — crisp line, tight glow, wide bloom —\n * with the sharp line leading and every soft layer's head pulled back behind\n * the tip.\n *\n * The component paints the pill surface itself and layers the light above\n * it, so the wrapped composer must not paint its own background:\n *\n *   <ComposerLoader active={isWaitingForReply}>\n *     <Composer className=\"bg-transparent shadow-none\" />\n *   </ComposerLoader>\n *\n * `active` fades the whole effect in and out (450ms), so toggling it on\n * send / reply reads as the composer lighting up rather than snapping.\n */\n\nexport interface ComposerLoaderProps {\n  children: ReactNode;\n  /** Show the light. Fades in/out — flip it while awaiting a response. */\n  active?: boolean;\n  /** Four gradient colors, spread across the pill left → right. */\n  colors?: [string, string, string, string];\n  /** Seconds per full lap. */\n  speed?: number;\n  /** Overall light opacity. */\n  intensity?: number;\n  /** How far the bloom bleeds inward from the rim, px. */\n  bloom?: number;\n  /** Bloom layer opacity. */\n  bloomStrength?: number;\n  /** How much of the perimeter the band occupies, degrees (of 360). */\n  arc?: number;\n  /** Reverse the travel direction. */\n  reverse?: boolean;\n  /** Corner radius, px. Defaults to a full pill. */\n  radius?: number;\n  /** Width of the crisp line, px; the tight glow scales with it. */\n  line?: number;\n  /** Draw the wide bloom alone, no line or tight glow: a soft wash for a beam to lead. */\n  bloomOnly?: boolean;\n  /** Paint the pill surface behind the light (on by default). */\n  surface?: boolean;\n  /**\n   * Fade the band's two ends instead of cutting them, 0–1: the fraction of\n   * the band's length that ramps. Each layer is stacked as shorter, centred\n   * copies at a fraction of its opacity; the blur melts the steps together.\n   */\n  taper?: number;\n  /** How the light composites over what's beneath, e.g. `screen` to read as light on a surface. */\n  blend?: CSSProperties[\"mixBlendMode\"];\n  /**\n   * Moves the band forward along the lap, as a fraction of the perimeter\n   * (0–1). Lets two loaders on one pill line up: a short beam with\n   * `offset` equal to the difference of the two arcs (as fractions) leads\n   * a wider glow tip to tip.\n   */\n  offset?: number;\n  className?: string;\n}\n\nconst DEFAULT_COLORS: [string, string, string, string] = [\n  \"#5eead4\",\n  \"#46baec\",\n  \"#e633a4\",\n  \"#00faa7\",\n];\n\nfunction hexTriplet(hex: string) {\n  return [\n    parseInt(hex.slice(1, 3), 16),\n    parseInt(hex.slice(3, 5), 16),\n    parseInt(hex.slice(5, 7), 16),\n  ];\n}\n\nexport function ComposerLoader({\n  children,\n  active = true,\n  colors = DEFAULT_COLORS,\n  speed = 4.5,\n  intensity = 0.7,\n  bloom = 16,\n  bloomStrength = 0.3,\n  arc = 120,\n  reverse = false,\n  radius,\n  line = 2.5,\n  bloomOnly = false,\n  surface = true,\n  taper = 0,\n  blend,\n  offset = 0,\n  className,\n}: ComposerLoaderProps) {\n  const localize = useTemplateCopy();\n  const gradientId = `bui-cl-${useId().replace(/[^a-zA-Z0-9]/g, \"\")}`;\n  const clipRef = useRef<HTMLSpanElement>(null);\n  const [box, setBox] = useState({ w: 640, h: 52 });\n\n  useEffect(() => {\n    const el = clipRef.current;\n    if (!el) return;\n    const observer = new ResizeObserver(() =>\n      setBox({ w: Math.max(1, el.clientWidth), h: Math.max(1, el.clientHeight) }),\n    );\n    observer.observe(el);\n    return () => observer.disconnect();\n  }, []);\n\n  const [c0, c1, c2, c3] = colors;\n  // Gradient center: pure blend of the middle colors, so the band never\n  // washes out to white.\n  const mid = `rgb(${hexTriplet(c1)\n    .map((v, i) => Math.round((v + hexTriplet(c2)[i]) / 2))\n    .join(\",\")})`;\n\n  const band = (arc / 360) * 100;\n  const rx = radius ?? box.h / 2;\n  const cornerRadius = radius ?? 9999;\n  const direction = reverse ? \"reverse\" : \"normal\";\n\n  // Path units per px, for pulling each soft layer's head behind the tip.\n  // Rounded-rect perimeter: straight runs plus the four corner arcs (for the\n  // default pill, rx = h/2 and this reduces to 2(w−h) + πh).\n  const cornerR = Math.min(rx, box.w / 2, box.h / 2);\n  const perimeter = Math.max(1, 2 * (box.w + box.h) - 8 * cornerR + 2 * Math.PI * cornerR);\n  const pxUnits = (px: number) => (px * 100) / perimeter;\n  // A layer's delay is its phase: the larger the phase, the further BACK\n  // along the lap the band sits (a negative delay is a head start). So\n  // moving a band forward, `offset` included, means subtracting.\n  const dashPhase = (len: number, backPx: number) =>\n    (reverse ? pxUnits(backPx) : len - band + pxUnits(backPx)) - offset * 100;\n\n  // Tapering stacks each layer as shorter, centred copies: the ramp at each\n  // end is a staircase with one step per copy, so it takes many copies and\n  // a little blur on the crisp line for the steps to melt into a gradient.\n  const TAPER_STEPS = 14;\n  const CRISP_BLUR = taper > 0 ? Math.max(0.5, line * 0.8) : 0.5;\n  const stroke = (width: number, blur: number, opacity: number, dashLen: number, backPx: number) => {\n    const copies = taper > 0 ? TAPER_STEPS : 1;\n    return Array.from({ length: copies }, (_, index) => {\n      // Copy 0 is the full band; each next one is shorter and moved forward\n      // by half the difference, so all of them share one midpoint and the\n      // ends thin out step by step.\n      const len = dashLen * (1 - (taper * index) / copies);\n      const phase = dashPhase(dashLen, backPx) - (dashLen - len) / 2;\n      return (\n        <rect\n          key={index}\n          x={0}\n          y={0}\n          width={box.w}\n          height={box.h}\n          rx={rx}\n          pathLength={100}\n          fill=\"none\"\n          stroke={`url(#${gradientId})`}\n          strokeWidth={width}\n          strokeLinecap=\"round\"\n          strokeDasharray={`${len} ${100 - len}`}\n          className=\"bui-composer-loader-rect\"\n          // SVG-native blur, not CSS filter: WebKit (iOS Safari and every iPhone\n          // browser) ignores CSS filters on individual SVG elements, which\n          // rendered the whole light razor-sharp on phones.\n          filter={blur > 0 ? `url(#${gradientId}-b${String(blur).replace(\".\", \"_\")})` : undefined}\n          style={{\n            opacity: opacity / copies,\n            animation: `bui-composer-loader-dash ${speed}s linear ${(phase * speed) / 100}s infinite ${direction}`,\n          }}\n        />\n      );\n    });\n  };\n\n  /** One feGaussianBlur per blur radius the layers use. The region is\n   *  widened well past the stroke so the blur never clips at the filter\n   *  bounds. */\n  const blurFilter = (radius: number) => (\n    <filter\n      key={radius}\n      id={`${gradientId}-b${String(radius).replace(\".\", \"_\")}`}\n      x=\"-50%\"\n      y=\"-50%\"\n      width=\"200%\"\n      height=\"200%\"\n    >\n      <feGaussianBlur stdDeviation={radius} />\n    </filter>\n  );\n\n  return localize((\n    <div className={cx(\"relative\", className)}>\n      {surface && (\n        <span\n          aria-hidden\n          className=\"absolute inset-0 bg-background-primary-default shadow-xs\"\n          style={{ borderRadius: cornerRadius }}\n        />\n      )}\n\n      <span\n        ref={clipRef}\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 overflow-hidden\"\n        style={{\n          borderRadius: cornerRadius,\n          opacity: active ? 1 : 0,\n          transition: \"opacity 450ms ease\",\n          mixBlendMode: blend,\n        }}\n      >\n        <svg\n          width=\"100%\"\n          height=\"100%\"\n          viewBox={`0 0 ${box.w} ${box.h}`}\n          preserveAspectRatio=\"none\"\n          style={{ opacity: intensity }}\n        >\n          <defs>\n            <linearGradient id={gradientId} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\">\n              <stop offset=\"0%\" stopColor={c0} />\n              <stop offset=\"30%\" stopColor={c1} />\n              <stop offset=\"50%\" stopColor={mid} />\n              <stop offset=\"70%\" stopColor={c2} />\n              <stop offset=\"100%\" stopColor={c3} />\n            </linearGradient>\n            {[14, 6, CRISP_BLUR].map(blurFilter)}\n          </defs>\n          {/* wide bloom bleeding inward (outer half clipped by the pill) */}\n          {bloom > 0 && stroke(bloom * 2, 14, bloomStrength, band * 0.9, bloom + 16)}\n          {/* tight glow */}\n          {!bloomOnly && stroke(line * 3.2, 6, 0.8, band * 0.95, 10)}\n          {/* crisp refraction line, tip leading */}\n          {!bloomOnly && stroke(line, CRISP_BLUR, 1, band, 0)}\n        </svg>\n      </span>\n\n      <div className=\"relative\">{children}</div>\n    </div>\n  ));\n}\n",
      "type": "registry:component",
      "target": "components/application/composer-loader/composer-loader.tsx"
    }
  ],
  "meta": {
    "docsUrl": "https://www.boardui.com/components/composer-loader",
    "example": "\"use client\";\n\nimport { ComposerLoader } from \"@/components/application/composer-loader/composer-loader\";\n\nexport function Example() {\n  return (\n    <ComposerLoader active>\n      {/* The wrapped composer must not paint its own surface — the light\n          layers between the pill background and the content. */}\n      <Composer className=\"bg-transparent shadow-none\" />\n    </ComposerLoader>\n  );\n}",
    "snippets": [
      {
        "label": "conversation",
        "code": "const [waiting, setWaiting] = useState(false);\n\nasync function send(message: string) {\n  setWaiting(true);           // light fades in, AgentThinking appears\n  await complete(message);\n  setWaiting(false);          // reply landed — everything fades out\n}\n\n{waiting && <AgentThinking variant=\"infinity\" />}\n<ComposerLoader active={waiting}>\n  <Composer className=\"bg-transparent shadow-none\" />\n</ComposerLoader>"
      },
      {
        "label": "options",
        "code": "{/* Everything ships tuned; override per surface as needed */}\n<ComposerLoader\n  colors={[\"#5eead4\", \"#46baec\", \"#e633a4\", \"#00faa7\"]}\n  speed={4.5}        // seconds per lap\n  arc={120}          // how much of the rim the band occupies\n  intensity={0.7}\n  bloom={16}         // how far the light bleeds inward, px\n  bloomStrength={0.3}\n  reverse={false}\n  radius={26}        // omit for a full pill\n>\n  ...\n</ComposerLoader>"
      }
    ]
  }
}
