{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cavemio-split-button",
  "title": "Split button",
  "description": "Dual-action trigger: primary action on the left, trailing chevron on the right opening an aligned dropdown menu.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/components/split-button.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { ChevronDown } from \"lucide-react\";\nimport { TextMorph } from \"./text-morph\";\nimport {\n  INTERACTION_FOCUS,\n  interactionIcon,\n  useInteractionReducedMotion,\n} from \"./imported-ui-interaction-motion\";\n\nexport interface SplitMenuItem {\n  id: string;\n  label: string;\n  icon?: React.ReactNode;\n  onSelect: () => void;\n  destructive?: boolean;\n  disabled?: boolean;\n}\n\nexport interface SplitButtonProps {\n  label: string;\n  icon?: React.ReactNode;\n  onClick?: () => void;\n  menuItems: SplitMenuItem[];\n  variant?: \"primary\" | \"secondary\" | \"destructive\";\n  size?: \"sm\" | \"md\" | \"lg\";\n  disabled?: boolean;\n  loading?: boolean;\n  menuLabel?: string;\n  className?: string;\n}\n\n// Exact physics & timing from FilterBar\nconst EASE = \"cubic-bezier(0.16,1,0.3,1)\";\nconst UI = \"cubic-bezier(0.23,1,0.32,1)\";\nconst OPEN = 280;\nconst CLOSE = 200;\nconst ROW_H = 32;\n\ntype Phase = \"closed\" | \"opening\" | \"open\" | \"closing\";\ntype Box = { left: number; top: number; width: number; height: number };\n\nconst variantStyles = {\n  primary: {\n    container: \"bg-primary text-primary-foreground\",\n    action:\n      \"hover:bg-primary-foreground/10 active:bg-primary-foreground/15 text-primary-foreground\",\n    trigger:\n      \"hover:bg-primary-foreground/10 active:bg-primary-foreground/15 text-primary-foreground\",\n    divider: \"bg-primary-foreground/25\",\n  },\n  secondary: {\n    container: \"bg-card text-foreground shadow-[inset_0_0_0_1px_var(--border)]\",\n    action: \"hover:bg-accent active:bg-accent/80 text-foreground\",\n    trigger: \"hover:bg-accent active:bg-accent/80 text-foreground\",\n    divider: \"bg-border\",\n  },\n  destructive: {\n    container:\n      \"bg-red-500/10 text-red-600 shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--color-red-500)_30%,transparent)] dark:text-red-400\",\n    action:\n      \"hover:bg-red-500/15 active:bg-red-500/20 text-red-600 dark:text-red-400\",\n    trigger:\n      \"hover:bg-red-500/15 active:bg-red-500/20 text-red-600 dark:text-red-400\",\n    divider: \"bg-red-500/25\",\n  },\n};\n\nconst sizeStyles = {\n  sm: {\n    height: \"h-7 text-[12px] rounded-full\",\n    actionPad: \"pl-3 pr-2 gap-1.5\",\n    triggerPad: \"px-2\",\n    iconSize: 13,\n  },\n  md: {\n    height: \"h-9 text-[13px] rounded-full\",\n    actionPad: \"pl-4 pr-2.5 gap-2\",\n    triggerPad: \"px-2.5\",\n    iconSize: 14,\n  },\n  lg: {\n    height: \"h-10 text-[14px] rounded-full\",\n    actionPad: \"pl-5 pr-3 gap-2.5\",\n    triggerPad: \"px-3\",\n    iconSize: 16,\n  },\n};\n\nexport function SplitButton({\n  label,\n  icon,\n  onClick,\n  menuItems,\n  variant = \"primary\",\n  size = \"md\",\n  disabled = false,\n  loading = false,\n  menuLabel = \"More actions\",\n  className = \"\",\n}: SplitButtonProps) {\n  const reduced = useInteractionReducedMotion();\n  const [phase, setPhase] = React.useState<Phase>(\"closed\");\n  const [box, setBox] = React.useState<Box>({\n    left: 0,\n    top: 0,\n    width: 0,\n    height: 36,\n  });\n  const [wrapW, setWrapW] = React.useState(200);\n  const [panelH, setPanelH] = React.useState(0);\n  const [activeIndex, setActiveIndex] = React.useState(0);\n\n  const wrapRef = React.useRef<HTMLDivElement | null>(null);\n  const triggerRef = React.useRef<HTMLButtonElement | null>(null);\n  const panelRef = React.useRef<HTMLDivElement | null>(null);\n  const timer = React.useRef<number>(0);\n\n  const v = variantStyles[variant];\n  const s = sizeStyles[size];\n  const inert = disabled || loading;\n  const mounted = phase !== \"closed\";\n  const expanded = phase === \"open\";\n\n  // Open the morphing floating dropdown from the trigger pill\n  const openMenu = () => {\n    const wrap = wrapRef.current;\n    const trigger = triggerRef.current;\n    if (!wrap || !trigger) return;\n    window.clearTimeout(timer.current);\n    const a = trigger.getBoundingClientRect();\n    const w = wrap.getBoundingClientRect();\n    setBox({\n      left: a.left - w.left,\n      top: a.top - w.top,\n      width: a.width,\n      height: a.height,\n    });\n    setWrapW(w.width);\n    setActiveIndex(0);\n    setPhase(reduced ? \"open\" : \"opening\");\n  };\n\n  const closeMenu = React.useCallback(\n    (refocus = true) => {\n      window.clearTimeout(timer.current);\n      if (refocus) {\n        triggerRef.current?.focus({ preventScroll: true });\n      }\n      if (reduced) {\n        setPhase(\"closed\");\n        return;\n      }\n      setPhase(\"closing\");\n      timer.current = window.setTimeout(() => {\n        setPhase(\"closed\");\n      }, CLOSE);\n    },\n    [reduced],\n  );\n\n  // FilterBar double-rAF expansion\n  React.useEffect(() => {\n    if (phase !== \"opening\") return;\n    let inner = 0;\n    const outer = requestAnimationFrame(() => {\n      inner = requestAnimationFrame(() => setPhase(\"open\"));\n    });\n    return () => {\n      cancelAnimationFrame(outer);\n      cancelAnimationFrame(inner);\n    };\n  }, [phase]);\n\n  // Clean timer on unmount\n  React.useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  // Measure content height dynamically\n  React.useLayoutEffect(() => {\n    const panel = panelRef.current;\n    if (!panel) return;\n    const measure = () => setPanelH(panel.offsetHeight);\n    measure();\n    const observer = new ResizeObserver(measure);\n    observer.observe(panel);\n    return () => observer.disconnect();\n  }, [menuItems, mounted]);\n\n  // Close on outside pointer click\n  React.useEffect(() => {\n    if (!mounted || phase === \"closing\") return;\n    const onPointerDown = (e: PointerEvent) => {\n      if (!wrapRef.current?.contains(e.target as Node)) {\n        closeMenu(false);\n      }\n    };\n    document.addEventListener(\"pointerdown\", onPointerDown);\n    return () => document.removeEventListener(\"pointerdown\", onPointerDown);\n  }, [mounted, phase, closeMenu]);\n\n  // Keyboard navigation\n  const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    if (!mounted || phase === \"closing\") {\n      if (\n        e.key === \"ArrowDown\" &&\n        document.activeElement === triggerRef.current\n      ) {\n        e.preventDefault();\n        openMenu();\n      }\n      return;\n    }\n\n    if (e.key === \"Escape\") {\n      e.preventDefault();\n      closeMenu(true);\n    } else if (e.key === \"ArrowDown\") {\n      e.preventDefault();\n      setActiveIndex((prev) => (prev < menuItems.length - 1 ? prev + 1 : 0));\n    } else if (e.key === \"ArrowUp\") {\n      e.preventDefault();\n      setActiveIndex((prev) => (prev > 0 ? prev - 1 : menuItems.length - 1));\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      setActiveIndex(0);\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      setActiveIndex(menuItems.length - 1);\n    } else if (e.key === \"Enter\" || e.key === \" \") {\n      e.preventDefault();\n      const current = menuItems[activeIndex];\n      if (current && !current.disabled) {\n        closeMenu(true);\n        current.onSelect();\n      }\n    }\n  };\n\n  const handleActionClick = (e: React.MouseEvent<HTMLButtonElement>) => {\n    if (inert) {\n      e.preventDefault();\n      return;\n    }\n    onClick?.();\n  };\n\n  const toggleDropdown = (e: React.MouseEvent<HTMLButtonElement>) => {\n    e.stopPropagation();\n    if (inert) return;\n    if (mounted && phase !== \"closing\") {\n      closeMenu();\n    } else {\n      openMenu();\n    }\n  };\n\n  // Dimensions & alignment: matches FilterBar's floating panel geometry\n  const PANEL_W = 184;\n  const menuWidth = Math.min(PANEL_W, Math.max(160, wrapW));\n  const targetLeft = Math.max(0, box.left + box.width - menuWidth);\n  const targetTop = box.top + box.height + 6;\n\n  return (\n    <div\n      ref={wrapRef}\n      onKeyDown={handleKeyDown}\n      className={`relative isolate inline-flex select-none items-stretch transition-[scale] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] has-[button:active:not(:disabled)]:scale-[0.98] motion-reduce:transition-none motion-reduce:has-[button:active]:scale-100 ${s.height} ${v.container} ${\n        disabled ? \"opacity-45\" : \"\"\n      } ${className}`}\n    >\n      {/* Primary Action Button */}\n      <button\n        type=\"button\"\n        disabled={inert}\n        onClick={handleActionClick}\n        aria-busy={loading || undefined}\n        className={`relative inline-flex items-center justify-center whitespace-nowrap rounded-l-full font-medium transition-colors duration-200 cursor-pointer disabled:cursor-default ${s.actionPad} ${v.action} ${INTERACTION_FOCUS}`}\n      >\n        {/* The slot opens for an icon or the spinner; they trade places through a blur. */}\n        <span\n          aria-hidden=\"true\"\n          className=\"relative flex shrink-0 items-center justify-center\"\n          style={{\n            width: icon || loading ? s.iconSize : 0,\n            height: s.iconSize,\n            marginRight: icon || loading ? 6 : 0,\n            transition: reduced\n              ? \"none\"\n              : `width 380ms ${EASE}, margin-right 380ms ${EASE}`,\n          }}\n        >\n          <span\n            className=\"absolute inset-0 flex items-center justify-center\"\n            style={interactionIcon(!loading, reduced)}\n          >\n            {icon}\n          </span>\n          <span\n            className=\"absolute inset-0 flex items-center justify-center\"\n            style={interactionIcon(loading, reduced)}\n          >\n            <span\n              className={`size-3 rounded-full border-[1.5px] border-current border-t-transparent ${loading ? \"animate-spin\" : \"\"}`}\n            />\n          </span>\n        </span>\n        <TextMorph>{label}</TextMorph>\n      </button>\n\n      {/* Quiet thin line Divider */}\n      <span\n        aria-hidden=\"true\"\n        className={`w-px my-1.5 self-stretch ${v.divider}`}\n      />\n\n      {/* Dropdown Chevron Trigger Button */}\n      <button\n        ref={triggerRef}\n        type=\"button\"\n        disabled={inert}\n        onClick={toggleDropdown}\n        aria-label={menuLabel}\n        aria-haspopup=\"menu\"\n        aria-expanded={mounted && phase !== \"closing\"}\n        className={`relative inline-flex items-center justify-center rounded-r-full transition-colors duration-200 cursor-pointer disabled:cursor-default ${s.triggerPad} ${v.trigger} ${INTERACTION_FOCUS}`}\n      >\n        <ChevronDown\n          size={s.iconSize}\n          strokeWidth={1.75}\n          style={{\n            transform:\n              mounted && phase !== \"closing\" ? \"rotate(180deg)\" : \"none\",\n            transition: reduced ? \"none\" : `transform 300ms ${EASE}`,\n          }}\n        />\n      </button>\n\n      {/* Floating Panel: Morphs out from under the trigger pill with spring physics */}\n      {mounted && (\n        <div\n          role=\"menu\"\n          aria-label={menuLabel}\n          className=\"absolute z-50 overflow-hidden bg-popover text-popover-foreground\"\n          style={{\n            top: targetTop,\n            left: expanded ? targetLeft : box.left,\n            width: expanded ? menuWidth : box.width,\n            height: expanded ? panelH : box.height,\n            borderRadius: expanded ? 12 : box.height / 2,\n            opacity: expanded ? 1 : 0,\n            boxShadow: \"0 0 0 1px var(--border)\",\n            transition: reduced\n              ? \"none\"\n              : phase === \"closing\"\n                ? `width ${CLOSE}ms ${UI}, height ${CLOSE}ms ${UI}, left ${CLOSE}ms ${UI}, border-radius ${CLOSE}ms ${UI}, opacity ${CLOSE}ms ${UI}`\n                : `width ${OPEN}ms ${UI}, height ${OPEN}ms ${UI}, left ${OPEN}ms ${UI}, border-radius ${OPEN}ms ${UI}, opacity 160ms ${UI}`,\n          }}\n        >\n          <div\n            ref={panelRef}\n            inert={!expanded ? true : undefined}\n            className=\"relative p-1\"\n            style={{\n              width: menuWidth,\n              opacity: expanded ? 1 : 0,\n              transition: reduced\n                ? \"none\"\n                : expanded\n                  ? `opacity 180ms ${EASE} 60ms`\n                  : \"opacity 90ms ease-out\",\n            }}\n          >\n            {/* The Internal Highlight Glides Between Menu Rows */}\n            <span\n              aria-hidden=\"true\"\n              className=\"pointer-events-none absolute inset-x-1 top-1 h-8 rounded-[7px] bg-accent\"\n              style={{\n                transform: `translateY(${activeIndex * ROW_H}px)`,\n                opacity: activeIndex >= 0 && menuItems.length > 0 ? 1 : 0,\n                transition: reduced ? \"none\" : `transform 160ms ${UI}`,\n              }}\n            />\n\n            {/* Menu Items */}\n            {menuItems.map((item, index) => {\n              const isDestructive = item.destructive;\n              const isSelected = activeIndex === index;\n\n              return (\n                <button\n                  key={item.id}\n                  type=\"button\"\n                  role=\"menuitem\"\n                  data-menu-item=\"\"\n                  disabled={item.disabled}\n                  onPointerEnter={() => !item.disabled && setActiveIndex(index)}\n                  onClick={() => {\n                    closeMenu(false);\n                    item.onSelect();\n                  }}\n                  className={`relative z-10 flex h-8 w-full items-center gap-2 rounded-[7px] px-2.5 text-[13px] font-medium transition-colors cursor-pointer disabled:cursor-not-allowed disabled:opacity-40 select-none text-left ${\n                    isDestructive\n                      ? isSelected\n                        ? \"text-red-600 dark:text-red-400 font-semibold\"\n                        : \"text-red-500/90 dark:text-red-400/90\"\n                      : isSelected\n                        ? \"text-foreground font-semibold\"\n                        : \"text-muted-foreground\"\n                  } ${INTERACTION_FOCUS}`}\n                >\n                  {item.icon && (\n                    <span\n                      className={`inline-flex size-3.5 shrink-0 items-center justify-center ${\n                        isDestructive ? \"text-red-500\" : \"text-muted-foreground\"\n                      }`}\n                    >\n                      {item.icon}\n                    </span>\n                  )}\n                  <span className=\"truncate flex-1\">{item.label}</span>\n                </button>\n              );\n            })}\n          </div>\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport default SplitButton;\n",
      "type": "registry:component"
    },
    {
      "path": "registry/components/text-morph.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\n/* ─────────────────────────────────────────────────────────\n * TEXT MORPH: text that changes the way it should\n *\n *   shared   letters both texts share stay alive and slide to\n *            their new place (\"Save\" → \"Saving\" keeps \"Sav\")\n *   new      letters that weren't there rise in out of a blur,\n *            one after another\n *   gone     letters that leave lift away and blur out where\n *            they stood\n *   width    the box eases to its new width, so a button or\n *            pill holding it resizes with it\n *\n * Texts with little in common crossfade as a whole instead of\n * flinging single letters across. The real text is always\n * there for screen readers.\n * ───────────────────────────────────────────────────────── */\n\nexport interface TextMorphProps extends Omit<\n  React.HTMLAttributes<HTMLSpanElement>,\n  \"children\"\n> {\n  children: string;\n  /** Morph time in ms. */\n  duration?: number;\n  /** Where new letters come from: below (\"up\") or above (\"down\"). */\n  direction?: \"up\" | \"down\";\n  /** Ease the box's width too; turn off for text that wraps. */\n  animateWidth?: boolean;\n}\n\ntype Glyph = { key: number; char: string };\ntype Leaving = Glyph & { x: number; y: number };\n\nconst EASE = \"cubic-bezier(0.16,1,0.3,1)\";\n\nconst reducedQuery = \"(prefers-reduced-motion: reduce)\";\nconst subscribeReduced = (onChange: () => void) => {\n  const query = window.matchMedia(reducedQuery);\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n};\nconst useReducedMotion = () =>\n  React.useSyncExternalStore(\n    subscribeReduced,\n    () => window.matchMedia(reducedQuery).matches,\n    () => false,\n  );\n\n/** Keep the letters two texts share (longest common subsequence); everything else is new. */\nfunction morph(\n  previous: Glyph[],\n  text: string,\n  nextKey: () => number,\n): Glyph[] {\n  const a = previous.map((g) => g.char);\n  const b = Array.from(text);\n  const fresh = () => b.map((char) => ({ key: nextKey(), char }));\n  if (!a.length || !b.length) return fresh();\n\n  const dp = Array.from(\n    { length: a.length + 1 },\n    () => new Uint16Array(b.length + 1),\n  );\n  for (let i = a.length - 1; i >= 0; i--)\n    for (let j = b.length - 1; j >= 0; j--)\n      dp[i][j] =\n        a[i] === b[j]\n          ? dp[i + 1][j + 1] + 1\n          : Math.max(dp[i + 1][j], dp[i][j + 1]);\n\n  // Too little in common reads as two different words: crossfade them instead.\n  if (dp[0][0] < Math.min(a.length, b.length) * 0.5) return fresh();\n\n  const out: Glyph[] = [];\n  let i = 0;\n  let j = 0;\n  while (j < b.length) {\n    if (i < a.length && a[i] === b[j]) {\n      out.push(previous[i++]);\n      j++;\n    } else if (i < a.length && dp[i + 1][j] >= dp[i][j + 1]) i++;\n    else out.push({ key: nextKey(), char: b[j++] });\n  }\n  return out;\n}\n\nfunction LeavingGlyph({\n  glyph,\n  lift,\n  duration,\n  onDone,\n}: {\n  glyph: Leaving;\n  lift: number;\n  duration: number;\n  onDone: (key: number) => void;\n}) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  React.useLayoutEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const animation = el.animate(\n      [\n        { opacity: 1, filter: \"blur(0px)\", transform: \"none\" },\n        { opacity: 0, filter: \"blur(4px)\", transform: `translateY(${lift}em)` },\n      ],\n      { duration: duration * 0.6, easing: EASE, fill: \"forwards\" },\n    );\n    animation.onfinish = () => onDone(glyph.key);\n    return () => animation.cancel();\n  }, [glyph.key, lift, duration, onDone]);\n  return (\n    <span\n      ref={ref}\n      aria-hidden=\"true\"\n      className=\"pointer-events-none absolute whitespace-pre\"\n      style={{ left: glyph.x, top: glyph.y }}\n    >\n      {glyph.char}\n    </span>\n  );\n}\n\nexport function TextMorph({\n  children: text,\n  duration = 460,\n  direction = \"up\",\n  animateWidth = true,\n  className = \"\",\n  ...props\n}: TextMorphProps) {\n  const reduced = useReducedMotion();\n  const counter = React.useRef(text.length);\n  const nextKey = React.useCallback(() => ++counter.current, []);\n  const [glyphs, setGlyphs] = React.useState<Glyph[]>(() =>\n    Array.from(text).map((char, i) => ({ key: i + 1, char })),\n  );\n  const [leaving, setLeaving] = React.useState<Leaving[]>([]);\n  const rootRef = React.useRef<HTMLSpanElement>(null);\n  const els = React.useRef(new Map<number, HTMLSpanElement>());\n  const before = React.useRef<{\n    at: Map<number, { x: number; y: number }>;\n    width: number;\n  } | null>(null);\n  const rise = direction === \"up\" ? 0.35 : -0.35;\n\n  // A preference change must also finish an in-flight morph whose target text\n  // already matches the glyphs (including the empty label in a folded receipt).\n  React.useLayoutEffect(() => {\n    if (!reduced) return;\n    before.current = null;\n    const root = rootRef.current;\n    root\n      ?.getAnimations({ subtree: true })\n      .forEach((animation) => animation.cancel());\n    if (root) root.style.whiteSpace = \"\";\n    setLeaving((previous) => (previous.length ? [] : previous));\n  }, [reduced]);\n\n  // 1. The text changed: note where every letter stands, then work out which letters stay.\n  React.useLayoutEffect(() => {\n    if (text === glyphs.map((g) => g.char).join(\"\")) return;\n    const root = rootRef.current;\n    if (!root || reduced) {\n      setLeaving([]);\n      setGlyphs(Array.from(text).map((char) => ({ key: nextKey(), char })));\n      return;\n    }\n    const box = root.getBoundingClientRect();\n    const at = new Map<number, { x: number; y: number }>();\n    els.current.forEach((el, key) => {\n      const r = el.getBoundingClientRect();\n      at.set(key, { x: r.left - box.left, y: r.top - box.top });\n    });\n    before.current = { at, width: box.width };\n    const next = morph(glyphs, text, nextKey);\n    const kept = new Set(next.map((g) => g.key));\n    setLeaving((l) => [\n      ...l,\n      ...glyphs\n        .filter((g) => !kept.has(g.key))\n        .map((g) => ({ ...g, ...(at.get(g.key) ?? { x: 0, y: 0 }) })),\n    ]);\n    setGlyphs(next);\n  }, [text, reduced]);\n\n  // 2. The new letters are in place: glide the ones that stayed, raise the new ones, ease the width.\n  React.useLayoutEffect(() => {\n    const prev = before.current;\n    const root = rootRef.current;\n    if (!prev || !root) return;\n    before.current = null;\n    const box = root.getBoundingClientRect();\n    let order = 0;\n    for (const g of glyphs) {\n      const el = els.current.get(g.key);\n      if (!el) continue;\n      const from = prev.at.get(g.key);\n      if (from) {\n        const r = el.getBoundingClientRect();\n        const dx = from.x - (r.left - box.left);\n        const dy = from.y - (r.top - box.top);\n        if (Math.abs(dx) > 0.5 || Math.abs(dy) > 0.5)\n          el.animate(\n            [\n              { transform: `translate(${dx}px, ${dy}px)` },\n              { transform: \"none\" },\n            ],\n            { duration, easing: EASE },\n          );\n      } else {\n        el.animate(\n          [\n            {\n              opacity: 0,\n              filter: \"blur(4px)\",\n              transform: `translateY(${rise}em)`,\n            },\n            { opacity: 1, filter: \"blur(0px)\", transform: \"none\" },\n          ],\n          {\n            duration,\n            easing: EASE,\n            delay: Math.min(order++ * 16, 160),\n            fill: \"backwards\",\n          },\n        );\n      }\n    }\n    if (animateWidth && Math.abs(prev.width - box.width) > 0.5) {\n      // Hold the words on one line while the box is narrower than them, or \"No credits left\" would wrap mid-morph.\n      root.style.whiteSpace = \"nowrap\";\n      const resize = root.animate(\n        [{ width: `${prev.width}px` }, { width: `${box.width}px` }],\n        { duration, easing: EASE },\n      );\n      resize.onfinish = resize.oncancel = () => {\n        root.style.whiteSpace = \"\";\n      };\n    }\n  }, [glyphs, duration, rise, animateWidth]);\n\n  const done = React.useCallback(\n    (key: number) => setLeaving((l) => l.filter((g) => g.key !== key)),\n    [],\n  );\n\n  // Words stay unbroken; lines may only wrap at spaces.\n  const words: Glyph[][] = [];\n  for (const g of glyphs) {\n    if (\n      g.char === \" \" ||\n      !words.length ||\n      words[words.length - 1][0]?.char === \" \"\n    )\n      words.push([g]);\n    else words[words.length - 1].push(g);\n  }\n\n  return (\n    <span\n      ref={rootRef}\n      className={`relative inline-block ${className}`}\n      {...props}\n    >\n      <span className=\"sr-only\">{text}</span>\n      {words.map((word, w) => (\n        <span\n          key={w}\n          aria-hidden=\"true\"\n          className=\"inline-block whitespace-pre\"\n        >\n          {word.map((g) => (\n            <span\n              key={g.key}\n              ref={(el) => {\n                if (el) els.current.set(g.key, el);\n                else els.current.delete(g.key);\n              }}\n              className=\"inline-block\"\n            >\n              {g.char}\n            </span>\n          ))}\n        </span>\n      ))}\n      {leaving.map((g) => (\n        <LeavingGlyph\n          key={`out-${g.key}`}\n          glyph={g}\n          lift={-rise}\n          duration={duration}\n          onDone={done}\n        />\n      ))}\n    </span>\n  );\n}\n",
      "type": "registry:component"
    },
    {
      "path": "registry/components/imported-ui-interaction-motion.ts",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport const EASE_OUT = \"cubic-bezier(0.16, 1, 0.3, 1)\";\nexport const EASE_SETTLE = \"cubic-bezier(0.22, 1.18, 0.36, 1)\";\n/** Thrown things (indicators, thumbs): a slight overshoot on transform only. */\nexport const EASE_THROW = \"cubic-bezier(0.34, 1.36, 0.64, 1)\";\n/**\n * The press every button primitive shares: a 3% give that eases in and settles back.\n * Tailwind v4's scale-* writes the `scale` property, so `scale` has to be in the list\n * or the press snaps.\n */\nexport const INTERACTION_PRESS =\n  \"transition-[background-color,color,box-shadow,opacity,scale] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] active:scale-[0.97] motion-reduce:transition-none motion-reduce:active:scale-100\";\nexport const INTERACTION_FOCUS =\n  \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background\";\n\nconst query = \"(prefers-reduced-motion: reduce)\";\nconst subscribe = (notify: () => void) => {\n  const media = window.matchMedia(query);\n  media.addEventListener(\"change\", notify);\n  return () => media.removeEventListener(\"change\", notify);\n};\nexport const useInteractionReducedMotion = () =>\n  React.useSyncExternalStore(\n    subscribe,\n    () => window.matchMedia(query).matches,\n    () => false,\n  );\n\nexport function useInteractionActivity<T extends Element>() {\n  const ref = React.useRef<T>(null);\n  const [visible, setVisible] = React.useState(false);\n  const [hidden, setHidden] = React.useState(false);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const observer = new IntersectionObserver(([entry]) =>\n      setVisible(entry.isIntersecting),\n    );\n    observer.observe(el);\n    const visibility = () => setHidden(document.hidden);\n    visibility();\n    document.addEventListener(\"visibilitychange\", visibility);\n    return () => {\n      observer.disconnect();\n      document.removeEventListener(\"visibilitychange\", visibility);\n    };\n  }, []);\n  return { ref, active: visible && !hidden };\n}\n\nexport function interactionIcon(\n  on: boolean,\n  reduced: boolean,\n): React.CSSProperties {\n  return {\n    opacity: on ? 1 : 0,\n    transform: on ? \"none\" : \"scale(0.6)\",\n    filter: on ? \"blur(0px)\" : \"blur(3px)\",\n    transition: reduced\n      ? \"none\"\n      : `opacity 220ms ${EASE_OUT}, transform 380ms ${EASE_OUT}, filter 220ms ${EASE_OUT}`,\n  };\n}\n\n/** Sample recent movement rather than averaging a long drag and losing its release velocity. */\nexport type PointerSample = { x: number; time: number };\nexport function samplePointer(\n  samples: PointerSample[],\n  x: number,\n  time: number,\n) {\n  samples.push({ x, time });\n  while (samples.length > 2 && time - samples[0].time > 100) samples.shift();\n}\nexport function releaseVelocity(samples: PointerSample[], now: number) {\n  if (samples.length < 2 || now - samples[samples.length - 1].time > 100)\n    return 0;\n  const first = samples[0],\n    last = samples[samples.length - 1];\n  return (last.x - first.x) / Math.max(1, last.time - first.time);\n}\n\n/** Smooth Apple/rational rubber-band curve: continuous exponential-like resistance without linear kinks. */\nexport function rubberBand(\n  overshoot: number,\n  dimension = 320,\n  constant = 0.55,\n): number {\n  const d = dimension || 320;\n  const abs = Math.abs(overshoot);\n  return Math.sign(overshoot) * (1 - 1 / ((abs * constant) / d + 1)) * d;\n}\n\n/** Projects resting travel from release velocity (velocity in px/ms; time in seconds). */\nexport function projectInertia(\n  distance: number,\n  velocity: number,\n  time = 0.12,\n): number {\n  return distance + velocity * 1000 * time;\n}\n\n/** Smooths incoming release velocity toward a boundary so springs don't slam or clip into walls. */\nexport function softenVelocity(\n  velocity: number,\n  distanceToTarget: number,\n  factor = 10,\n): number {\n  const maxAllowed = Math.abs(distanceToTarget) * factor;\n  return Math.sign(velocity) * Math.min(Math.abs(velocity), maxAllowed);\n}\n\n/** A damped spring sampled by WAAPI: tuned for organic lightness with a hint of life (3% breath). */\nexport function springFrames(\n  from: number,\n  to: number,\n  velocity = 0,\n  duration = 480,\n  config: { omega?: number; damping?: number; steps?: number } = {},\n) {\n  const { omega = 16, damping = 0.74, steps = 36 } = config;\n  const damped = omega * Math.sqrt(Math.max(0.001, 1 - damping * damping));\n  const displacement = from - to;\n  const coefficient =\n    (velocity * 1000 + damping * omega * displacement) / damped;\n  return Array.from({ length: steps + 1 }, (_, i) => {\n    const t = (i / steps) * (duration / 1000);\n    const value =\n      to +\n      Math.exp(-damping * omega * t) *\n        (displacement * Math.cos(damped * t) +\n          coefficient * Math.sin(damped * t));\n    return { value: i === steps ? to : value, offset: i / steps };\n  });\n}\n",
      "type": "registry:component"
    }
  ],
  "css": {},
  "meta": {
    "cavemio": {
      "component": "split-button",
      "exportName": "SplitButton",
      "categories": [
        "buttons"
      ],
      "isNew": true,
      "usage": "import { SplitButton } from \"@/components/split-button\";\n\n<SplitButton\n  label=\"Save changes\"\n  onClick={() => save()}\n  menuItems={[\n    { id: \"save-draft\", label: \"Save as draft\", onSelect: () => saveDraft() },\n    { id: \"export\", label: \"Export backup\", onSelect: () => exportBackup() },\n  ]}\n/>",
      "accessibility": "- No external dropdown library dependency: lightweight self-contained menu logic with full keyboard handling.\n- Clicking outside or pressing Escape cleanly closes the menu.",
      "previewNote": "Interactive local fixture. Data and async results are simulated in the preview; the caller supplies application services.",
      "documentation": {
        "props": [
          {
            "name": "label",
            "type": "string",
            "description": "– · Text of the primary action."
          },
          {
            "name": "onClick",
            "type": "() => void",
            "description": "– · Called when the primary action button is clicked."
          },
          {
            "name": "menuItems",
            "type": "SplitMenuItem[]",
            "description": "– · List of secondary actions shown in the dropdown menu."
          },
          {
            "name": "variant",
            "type": "\"primary\" | \"secondary\" | \"destructive\"",
            "description": "\"primary\" · Color scheme and visual tone."
          },
          {
            "name": "size",
            "type": "\"sm\" | \"md\" | \"lg\"",
            "description": "\"md\" · Height and typography scale."
          },
          {
            "name": "loading",
            "type": "boolean",
            "description": "false · Shows a spinner inside the primary button."
          },
          {
            "name": "disabled",
            "type": "boolean",
            "description": "false · Disables both primary and dropdown actions."
          }
        ],
        "useCases": [
          {
            "title": "Publish & deploy",
            "description": "Primary \"Publish\" action with dropdown options for \"Schedule\" or \"Publish as draft\"."
          },
          {
            "title": "Save & export",
            "description": "\"Save\" main action paired with \"Export as PDF\" or \"Export as JSON\"."
          },
          {
            "title": "Git & release",
            "description": "\"Commit changes\" with \"Commit and push\" or \"Create PR\" secondary options."
          }
        ],
        "features": [
          {
            "title": "Dual-action trigger",
            "description": "Independent click handlers for the primary action and the secondary chevron trigger."
          },
          {
            "title": "Aligned floating menu",
            "description": "Floating menu opens directly below the button’s right edge with thin line borders and zero fuzzy shadows."
          },
          {
            "title": "180° chevron rotation",
            "description": "Chevron smoothly rotates with organic spring easing when opened."
          },
          {
            "title": "Keyboard accessible",
            "description": "Navigate open menu items with ArrowUp, ArrowDown, Home, End, and dismiss with Escape."
          }
        ],
        "states": [
          {
            "title": "idle",
            "description": "A two-part capsule with a thin line divider; pressing either half gives the whole capsule 2%."
          },
          {
            "title": "open",
            "description": "The menu grows out of the chevron, which turns over; a highlight glides between rows."
          },
          {
            "title": "loading",
            "description": "The icon blurs into a spinner and the label morphs (\"Publish\" → \"Publishing\"); clicks are swallowed."
          }
        ]
      }
    }
  },
  "type": "registry:component"
}