{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cavemio-button",
  "title": "Button",
  "description": "The base action: variants, 24–40px sizes, a 3% press, and status (pending, success, error) shown through an icon slot and a morphing label.",
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/components/button.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { TextMorph } from \"./text-morph\";\nimport {\n  EASE_OUT,\n  INTERACTION_PRESS,\n  interactionIcon,\n} from \"./imported-ui-interaction-motion\";\n\nexport type ButtonVariant =\n  | \"primary\"\n  | \"brand\"\n  | \"secondary\"\n  | \"outline\"\n  | \"ghost\"\n  | \"destructive\"\n  | \"link\";\n\nexport type ButtonSize = \"xs\" | \"sm\" | \"md\" | \"lg\" | \"icon\";\nexport type ActionStatus = \"idle\" | \"pending\" | \"success\" | \"error\";\n\nexport interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n  ref?: React.Ref<HTMLButtonElement>;\n  variant?: ButtonVariant;\n  size?: ButtonSize;\n  loading?: boolean;\n  status?: ActionStatus;\n  /** Custom labels for each state when using status/async flows. */\n  statusLabels?: Partial<Record<ActionStatus, string>>;\n  /** Automatically reset back to idle after success/error (ms). Default 1800ms. */\n  resetAfter?: number;\n  onReset?: () => void;\n  icon?: React.ReactNode;\n  trailingIcon?: React.ReactNode;\n}\n\nconst FOCUS =\n  \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40 focus-visible:ring-offset-2 focus-visible:ring-offset-background\";\n\nconst variantStyles: Record<ButtonVariant, string> = {\n  primary: \"bg-primary text-primary-foreground hover:bg-primary/90\",\n  brand: \"bg-primary text-primary-foreground hover:bg-primary/90\",\n  secondary:\n    \"bg-card text-foreground shadow-[inset_0_0_0_1px_var(--border)] hover:bg-accent\",\n  outline:\n    \"bg-transparent text-foreground shadow-[inset_0_0_0_1px_var(--border)] hover:bg-accent\",\n  ghost:\n    \"bg-transparent text-muted-foreground hover:bg-accent hover:text-foreground\",\n  destructive:\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 hover:bg-red-500/15\",\n  link: \"bg-transparent text-primary underline-offset-4 hover:underline p-0 h-auto font-normal\",\n};\n\ninterface SizeConfig {\n  height: string;\n  padding: string;\n  fontSize: string;\n  iconSize: number;\n  iconGap: number;\n}\n\nconst sizeConfigs: Record<ButtonSize, SizeConfig> = {\n  xs: {\n    height: \"h-6\",\n    padding: \"px-2.5\",\n    fontSize: \"text-[12px]\",\n    iconSize: 12,\n    iconGap: 5,\n  },\n  sm: {\n    height: \"h-7\",\n    padding: \"px-3\",\n    fontSize: \"text-[12px]\",\n    iconSize: 13,\n    iconGap: 6,\n  },\n  md: {\n    height: \"h-9\",\n    padding: \"px-4\",\n    fontSize: \"text-[13px]\",\n    iconSize: 14,\n    iconGap: 7,\n  },\n  lg: {\n    height: \"h-10\",\n    padding: \"px-5\",\n    fontSize: \"text-[14px]\",\n    iconSize: 16,\n    iconGap: 8,\n  },\n  icon: {\n    height: \"size-9 p-0 justify-center items-center shrink-0\",\n    padding: \"p-0\",\n    fontSize: \"text-[13px]\",\n    iconSize: 15,\n    iconGap: 0,\n  },\n};\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\nfunction SelfDrawingCheck({\n  drawn,\n  reduced,\n  size,\n}: {\n  drawn: boolean;\n  reduced: boolean;\n  size: number;\n}) {\n  return (\n    <svg\n      width={size}\n      height={size}\n      viewBox=\"0 0 16 16\"\n      fill=\"none\"\n      className=\"shrink-0\"\n    >\n      <path\n        d=\"M3.5 8.5 6.5 11.5 12.5 4.5\"\n        stroke=\"currentColor\"\n        strokeWidth=\"2\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        pathLength={1}\n        strokeDasharray={1}\n        style={{\n          strokeDashoffset: drawn ? 0 : 1,\n          transition:\n            drawn && !reduced\n              ? `stroke-dashoffset 420ms ${EASE_OUT} 100ms`\n              : \"none\",\n        }}\n      />\n    </svg>\n  );\n}\n\nfunction StatusAlert({ size }: { size: number }) {\n  return (\n    <svg\n      width={size}\n      height={size}\n      viewBox=\"0 0 16 16\"\n      fill=\"none\"\n      className=\"shrink-0\"\n    >\n      <circle cx=\"8\" cy=\"8\" r=\"6.25\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n      <path\n        d=\"M8 4.75v3.75\"\n        stroke=\"currentColor\"\n        strokeWidth=\"1.75\"\n        strokeLinecap=\"round\"\n      />\n      <circle cx=\"8\" cy=\"11\" r=\"1\" fill=\"currentColor\" />\n    </svg>\n  );\n}\n\nconst DEFAULT_LABELS: Record<ActionStatus, string> = {\n  idle: \"Save\",\n  pending: \"Saving\",\n  success: \"Saved\",\n  error: \"Try again\",\n};\n\n/**\n * Button: high-craft tactile action primitive with rounded-full pill geometry,\n * StatusButton visual parity, self-drawing checkmark morphs, TextMorph label transitions,\n * and error shake physics.\n */\nexport function Button({\n  ref,\n  variant = \"primary\",\n  size = \"md\",\n  loading = false,\n  status,\n  statusLabels,\n  resetAfter = 1800,\n  onReset,\n  disabled = false,\n  icon,\n  trailingIcon,\n  className = \"\",\n  children,\n  onClick,\n  ...props\n}: ButtonProps) {\n  const innerRef = React.useRef<HTMLButtonElement | null>(null);\n  const reduced = useReducedMotion();\n\n  React.useImperativeHandle(ref, () => innerRef.current as HTMLButtonElement);\n\n  // Normalize status from explicit prop or loading boolean\n  const currentStatus: ActionStatus = status ?? (loading ? \"pending\" : \"idle\");\n  const isAsyncFlow = status !== undefined || loading;\n\n  // Resolve current text label\n  const idleLabel =\n    typeof children === \"string\" ? children : DEFAULT_LABELS.idle;\n  const labels: Record<ActionStatus, string> = {\n    idle: statusLabels?.idle ?? idleLabel,\n    pending: statusLabels?.pending ?? DEFAULT_LABELS.pending,\n    success: statusLabels?.success ?? DEFAULT_LABELS.success,\n    error: statusLabels?.error ?? DEFAULT_LABELS.error,\n  };\n  const activeLabel = labels[currentStatus];\n\n  // Auto-reset timer for success or error states\n  React.useEffect(() => {\n    if ((currentStatus !== \"success\" && currentStatus !== \"error\") || !onReset)\n      return;\n    const timer = window.setTimeout(onReset, resetAfter);\n    return () => window.clearTimeout(timer);\n  }, [currentStatus, onReset, resetAfter]);\n\n  // Error state horizontal shake\n  React.useEffect(() => {\n    if (currentStatus !== \"error\" || reduced) return;\n    innerRef.current?.animate(\n      [\n        { transform: \"none\" },\n        { transform: \"translateX(-4px)\" },\n        { transform: \"translateX(4px)\" },\n        { transform: \"translateX(-2px)\" },\n        { transform: \"none\" },\n      ],\n      { duration: 380, easing: \"ease-out\" },\n    );\n  }, [currentStatus, reduced]);\n\n  const cfg = sizeConfigs[size];\n  const isBusy = currentStatus === \"pending\";\n  const isInert = disabled || isBusy;\n\n  // Icon slot state: open if an icon was provided, or if in async status\n  const showLeadingSlot =\n    size !== \"icon\" &&\n    (Boolean(icon) || (isAsyncFlow && currentStatus !== \"idle\"));\n\n  const icons: Record<ActionStatus, React.ReactNode> = {\n    idle: icon,\n    pending: (\n      <span\n        style={{ width: cfg.iconSize, height: cfg.iconSize }}\n        className={`rounded-full border-[1.5px] border-current border-t-transparent motion-reduce:animate-none opacity-85 ${\n          currentStatus === \"pending\" ? \"animate-spin\" : \"\"\n        }`}\n      />\n    ),\n    success: (\n      <span\n        className={\n          variant === \"primary\"\n            ? \"text-primary-foreground\"\n            : \"text-emerald-600 dark:text-emerald-400\"\n        }\n      >\n        <SelfDrawingCheck\n          drawn={currentStatus === \"success\"}\n          reduced={reduced}\n          size={cfg.iconSize}\n        />\n      </span>\n    ),\n    error: (\n      <span className=\"text-red-600 dark:text-red-400\">\n        <StatusAlert size={cfg.iconSize} />\n      </span>\n    ),\n  };\n\n  const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {\n    if (isInert) {\n      e.preventDefault();\n      return;\n    }\n    onClick?.(e);\n  };\n\n  // Tone shifts for error states\n  const toneClass =\n    currentStatus === \"error\"\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      : variantStyles[variant];\n\n  return (\n    <>\n      <button\n        ref={innerRef}\n        type={props.type ?? \"button\"}\n        disabled={disabled}\n        aria-disabled={isInert ? true : undefined}\n        aria-busy={isBusy ? true : undefined}\n        onClick={handleClick}\n        className={`relative inline-flex items-center justify-center font-medium select-none whitespace-nowrap cursor-pointer rounded-full disabled:cursor-default disabled:opacity-45 ${variant === \"link\" ? \"transition-colors\" : INTERACTION_PRESS} ${FOCUS} ${\n          toneClass\n        } ${cfg.height} ${cfg.padding} ${cfg.fontSize} ${className}`}\n        {...props}\n      >\n        {/* Leading Icon / Status Slot with explicit width, height, and marginRight */}\n        {size !== \"icon\" && (\n          <span\n            aria-hidden=\"true\"\n            className=\"relative flex shrink-0 items-center justify-center overflow-hidden\"\n            style={{\n              width: showLeadingSlot ? cfg.iconSize : 0,\n              height: cfg.iconSize,\n              marginRight: showLeadingSlot ? cfg.iconGap : 0,\n              transition: reduced\n                ? \"none\"\n                : `width 360ms ${EASE_OUT}, margin-right 360ms ${EASE_OUT}`,\n            }}\n          >\n            {(Object.keys(icons) as ActionStatus[]).map((st) => (\n              <span\n                key={st}\n                className=\"absolute inset-0 flex items-center justify-center\"\n                style={interactionIcon(st === currentStatus, reduced)}\n              >\n                {icons[st]}\n              </span>\n            ))}\n          </span>\n        )}\n\n        {/* Icon-only mode: the same stacked layers, so the icon never hard-swaps. */}\n        {size === \"icon\" && (\n          <span\n            aria-hidden=\"true\"\n            className=\"relative shrink-0\"\n            style={{ width: cfg.iconSize, height: cfg.iconSize }}\n          >\n            {(Object.keys(icons) as ActionStatus[]).map((st) => (\n              <span\n                key={st}\n                className=\"absolute inset-0 flex items-center justify-center\"\n                style={interactionIcon(st === currentStatus, reduced)}\n              >\n                {st === \"idle\" ? (icon ?? children) : icons[st]}\n              </span>\n            ))}\n          </span>\n        )}\n\n        {/* Text Label: uses TextMorph for silky label transitions */}\n        {size !== \"icon\" && (\n          <span className=\"inline-flex items-center\">\n            {typeof children === \"string\" || isAsyncFlow ? (\n              <TextMorph>{activeLabel}</TextMorph>\n            ) : (\n              children\n            )}\n          </span>\n        )}\n\n        {/* Trailing Icon with guaranteed calibrated spacing */}\n        {trailingIcon && size !== \"icon\" && (\n          <span\n            aria-hidden=\"true\"\n            className=\"inline-flex shrink-0 items-center justify-center\"\n            style={{ marginLeft: cfg.iconGap }}\n          >\n            {trailingIcon}\n          </span>\n        )}\n      </button>\n\n      {/* Screen Reader live region outside button */}\n      {isAsyncFlow && (\n        <span role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n          {currentStatus === \"idle\" ? \"\" : activeLabel}\n        </span>\n      )}\n    </>\n  );\n}\n\nexport default Button;\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": "button",
      "exportName": "Button",
      "categories": [
        "buttons"
      ],
      "isNew": true,
      "usage": "import { Button } from \"@/components/button\";\n\n<Button variant=\"primary\" size=\"md\">Save changes</Button>\n<Button variant=\"secondary\" loading={isSaving}>Deploy</Button>",
      "accessibility": "- No external animation libraries: uses CSS transitions and native layout geometry.\n- Anchor triggers for Popovers and Dropdowns are guarded from press scaling to preserve positioning geometry.\n- Strict 1px thin line styling with zero drop shadows.",
      "previewNote": "Interactive local fixture. Data and async results are simulated in the preview; the caller supplies application services.",
      "documentation": {
        "props": [
          {
            "name": "variant",
            "type": "\"primary\" | \"secondary\" | \"outline\" | \"ghost\" | \"destructive\" | \"link\"",
            "description": "\"primary\" · Visual appearance of the button."
          },
          {
            "name": "size",
            "type": "\"xs\" | \"sm\" | \"md\" | \"lg\" | \"icon\"",
            "description": "\"md\" · Height and typographic scale."
          },
          {
            "name": "loading",
            "type": "boolean",
            "description": "false · Shows an in-place spinner while retaining keyboard focus."
          },
          {
            "name": "icon",
            "type": "ReactNode",
            "description": "– · Leading icon slot."
          },
          {
            "name": "trailingIcon",
            "type": "ReactNode",
            "description": "– · Trailing icon slot."
          },
          {
            "name": "disabled",
            "type": "boolean",
            "description": "false · Disables user interaction."
          }
        ],
        "useCases": [
          {
            "title": "Form submits",
            "description": "Primary actions with in-place loading state that retains keyboard focus."
          },
          {
            "title": "Toolbars & headers",
            "description": "Secondary and ghost buttons with thin line borders and adaptive press feel."
          },
          {
            "title": "Destructive dialogs",
            "description": "Clean destructive actions with clear visual distinction and no blurry glow."
          },
          {
            "title": "Icon triggers",
            "description": "Concentric square icon buttons with deeper tactile push feedback."
          }
        ],
        "features": [
          {
            "title": "Adaptive press scale",
            "description": "Small icon buttons push deeper (0.95), wide buttons push subtly (0.985), and floating anchor triggers never scale so popover bounds remain pixel-perfect."
          },
          {
            "title": "Smooth width morphing",
            "description": "When children or labels change, the button measures the new natural width and glides smoothly without jumping surrounding layout."
          },
          {
            "title": "In-place loading state",
            "description": "Loading morphs a centered spinner into place while keeping the button focusable (aria-disabled) so keyboard users never lose their place."
          },
          {
            "title": "thin line 1px precision",
            "description": "Pure 1px border tokens with zero fuzzy drop shadows and full dark mode compatibility."
          }
        ],
        "states": [
          {
            "title": "idle",
            "description": "Resting button: filled primary, or a 1px thin line for secondary and outline."
          },
          {
            "title": "pressed",
            "description": "Gives 3% and settles back in 200ms (none with reduced motion)."
          },
          {
            "title": "pending",
            "description": "The icon slot opens and a spinner blurs in; the label morphs; aria-busy, clicks swallowed, focus kept."
          },
          {
            "title": "success / error",
            "description": "A check draws itself, or an alert with a short shake; icon-only buttons swap their icon the same way."
          },
          {
            "title": "disabled",
            "description": "45% opacity and a default cursor."
          }
        ]
      }
    }
  },
  "type": "registry:component"
}