{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"card-input","type":"registry:component","title":"Card input","description":"Formats as you type, spots the card brand, and flips to show the CVC.","author":"Yash Bavadiya <https://xevrion.dev>","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"components/card-input.tsx","type":"registry:component","content":"\"use client\";\n\nimport { useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport { animate, motion, useMotionValue } from \"motion/react\";\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\nimport { cn } from \"@/lib/utils\";\n\ntype Brand = \"visa\" | \"mastercard\" | \"amex\" | \"discover\" | \"unknown\";\ntype Field = \"number\" | \"expiry\" | \"cvc\" | \"name\";\n\ntype BrandSpec = {\n  name: string;\n  test: RegExp;\n  // Valid lengths; the first is what the card face shows as placeholders.\n  lengths: number[];\n  gaps: number[];\n  cvc: number;\n};\n\nconst BRANDS: Record<Brand, BrandSpec> = {\n  visa: { name: \"Visa\", test: /^4/, lengths: [16, 13, 19], gaps: [4, 8, 12, 16], cvc: 3 },\n  mastercard: {\n    name: \"Mastercard\",\n    // The 2-series is only 2221 to 2720; 2200 to 2204 belongs to Mir.\n    test: /^(5[1-5]|222[1-9]|22[3-9]\\d|2[3-6]\\d{2}|27[01]\\d|2720)/,\n    lengths: [16],\n    gaps: [4, 8, 12],\n    cvc: 3,\n  },\n  // Amex groups 4-6-5 and puts a 4 digit code on the front.\n  amex: { name: \"American Express\", test: /^3[47]/, lengths: [15], gaps: [4, 10], cvc: 4 },\n  discover: {\n    name: \"Discover\",\n    test: /^(6011|65|64[4-9])/,\n    lengths: [16, 19],\n    gaps: [4, 8, 12, 16],\n    cvc: 3,\n  },\n  // An unrecognised prefix stops at 16, the length nearly every card has.\n  // Only a network known to issue longer numbers, like Visa or Discover,\n  // lets the field run on to 19, so a typo never spills past the card.\n  unknown: {\n    name: \"Card\",\n    test: /^/,\n    lengths: [16, 12, 13, 14, 15],\n    gaps: [4, 8, 12, 16],\n    cvc: 3,\n  },\n};\nconst ORDER: Brand[] = [\"visa\", \"mastercard\", \"amex\", \"discover\"];\n\nconst STROKE = {\n  fill: \"none\",\n  stroke: \"currentColor\",\n  strokeWidth: 1.5,\n  strokeLinecap: \"round\",\n  strokeLinejoin: \"round\",\n} as const;\n\nconst ICON_SWAP = { type: \"spring\", duration: 0.3, bounce: 0 } as const;\n// A half turn across the card's full width reads as a rush under ~400ms,\n// and nobody waits on it: the caret is already in the CVC field.\nconst FLIP = { type: \"spring\", visualDuration: 0.5, bounce: 0.15 } as const;\nconst RING = { type: \"spring\", duration: 0.3, bounce: 0 } as const;\n// Long enough to read, short enough that a second check isn't blocked.\nconst CONFIRM_FOR = 2000;\n\nfunction detect(digits: string): Brand {\n  return ORDER.find((b) => BRANDS[b].test.test(digits)) ?? \"unknown\";\n}\n\nfunction luhn(digits: string) {\n  let sum = 0;\n  for (let i = 0; i < digits.length; i++) {\n    let n = Number(digits[digits.length - 1 - i]);\n    if (i % 2) {\n      n *= 2;\n      if (n > 9) n -= 9;\n    }\n    sum += n;\n  }\n  return sum % 10 === 0;\n}\n\nfunction group(digits: string, gaps: number[]) {\n  let out = \"\";\n  for (let i = 0; i < digits.length; i++) {\n    if (gaps.includes(i)) out += \" \";\n    out += digits[i];\n  }\n  return out;\n}\n\nconst formatExpiry = (d: string) =>\n  d.length > 2 ? `${d.slice(0, 2)}/${d.slice(2)}` : d;\n\nfunction caretAfterDigits(value: string, count: number) {\n  if (count <= 0) return 0;\n  let seen = 0;\n  for (let i = 0; i < value.length; i++) {\n    if (/\\d/.test(value[i]) && ++seen === count) return i + 1;\n  }\n  return value.length;\n}\n\n// Reformats in place and puts the caret back after the same number of\n// digits it was after, so editing mid-number never throws it to the end.\n// Writing the DOM first means React sees an unchanged value and leaves the\n// caret alone.\nfunction reformat(\n  input: HTMLInputElement,\n  max: number,\n  format: (digits: string) => string,\n  pad?: (digits: string) => string,\n) {\n  const caret = input.selectionStart ?? input.value.length;\n  let before = input.value.slice(0, caret).replace(/\\D/g, \"\").length;\n  let digits = input.value.replace(/\\D/g, \"\").slice(0, max);\n  if (pad) {\n    const padded = pad(digits);\n    before += padded.length - digits.length;\n    digits = padded;\n  }\n  const value = format(digits);\n  input.value = value;\n  if (document.activeElement === input) {\n    const at = caretAfterDigits(value, Math.min(before, digits.length));\n    input.setSelectionRange(at, at);\n  }\n  return { digits, value };\n}\n\n// Backspace right after a space or slash would delete the separator, which\n// reformatting puts straight back, leaving the caret stuck. Step over it so\n// the digit before goes instead.\nfunction skipSeparator(e: React.KeyboardEvent<HTMLInputElement>) {\n  const el = e.currentTarget;\n  const at = el.selectionStart;\n  if (at === null || at !== el.selectionEnd) return;\n  if (e.key === \"Backspace\" && at > 0 && /\\D/.test(el.value[at - 1]))\n    el.setSelectionRange(at - 1, at - 1);\n  if (e.key === \"Delete\" && at < el.value.length && /\\D/.test(el.value[at]))\n    el.setSelectionRange(at + 1, at + 1);\n}\n\ntype Values = Record<Field, string>;\n\nfunction validate(field: Field, values: Values, brand: Brand, final: boolean) {\n  const spec = BRANDS[brand];\n  const value = values[field];\n  const digits = value.replace(/\\D/g, \"\");\n  // Tabbing past an empty field isn't a mistake; only a full check flags it.\n  if (!value.trim()) return final ? \"Required\" : null;\n  if (field === \"number\") {\n    if (!spec.lengths.includes(digits.length)) return \"Too short\";\n    if (!luhn(digits)) return \"Not a valid number\";\n  }\n  if (field === \"expiry\") {\n    if (digits.length < 4) return \"Use MM/YY\";\n    const month = Number(digits.slice(0, 2));\n    if (month < 1 || month > 12) return \"Invalid month\";\n    const now = new Date();\n    const year = 2000 + Number(digits.slice(2));\n    // Cards stay valid through the last day of their expiry month.\n    if (year < now.getFullYear() || (year === now.getFullYear() && month < now.getMonth() + 1))\n      return \"Card expired\";\n  }\n  if (field === \"cvc\" && digits.length < spec.cvc) return \"Too short\";\n  return null;\n}\n\nexport function CardInput({\n  onValid,\n  className,\n}: {\n  onValid?: (card: { brand: Brand; last4: string; expiry: string; name: string }) => void;\n  className?: string;\n}) {\n  const id = useId();\n  const reduceMotion = useReducedMotion();\n  const [values, setValues] = useState<Values>({ number: \"\", expiry: \"\", cvc: \"\", name: \"\" });\n  const [errors, setErrors] = useState<Partial<Record<Field, string>>>({});\n  const [focused, setFocused] = useState<Field | null>(null);\n  const [confirmed, setConfirmed] = useState(false);\n  const timer = useRef<ReturnType<typeof setTimeout>>(undefined);\n\n  useEffect(() => () => clearTimeout(timer.current), []);\n\n  const digits = values.number.replace(/\\D/g, \"\");\n  const brand = detect(digits);\n  const spec = BRANDS[brand];\n\n  const set = (field: Field, value: string) => {\n    setValues((v) => ({ ...v, [field]: value }));\n    // Typing is the fix, so the error goes at once rather than fading.\n    setErrors((e) => (e[field] ? { ...e, [field]: undefined } : e));\n    setConfirmed(false);\n  };\n\n  const blur = (field: Field) => {\n    setFocused((f) => (f === field ? null : f));\n    const error = validate(field, values, brand, false);\n    setErrors((e) => ({ ...e, [field]: error ?? undefined }));\n  };\n\n  const check = () => {\n    const fields: Field[] = [\"number\", \"expiry\", \"cvc\", \"name\"];\n    const next: Partial<Record<Field, string>> = {};\n    for (const f of fields) next[f] = validate(f, values, brand, true) ?? undefined;\n    setErrors(next);\n    const firstBad = fields.find((f) => next[f]);\n    if (firstBad) {\n      document.getElementById(`${id}-${firstBad}`)?.focus();\n      return;\n    }\n    setConfirmed(true);\n    onValid?.({ brand, last4: digits.slice(-4), expiry: values.expiry, name: values.name.trim() });\n    clearTimeout(timer.current);\n    timer.current = setTimeout(() => setConfirmed(false), CONFIRM_FOR);\n  };\n\n  const inputProps = (field: Field) => ({\n    id: `${id}-${field}`,\n    value: values[field],\n    \"aria-invalid\": Boolean(errors[field]),\n    \"aria-describedby\": errors[field] ? `${id}-${field}-error` : undefined,\n    onFocus: () => setFocused(field),\n    onBlur: () => blur(field),\n    className: cn(\n      \"h-11 w-full rounded-xl border bg-background px-3.5 text-[15px] text-foreground tabular-nums outline-hidden transition-[border-color] duration-150 ease-out placeholder:text-muted-foreground/70 focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-1\",\n      errors[field]\n        ? \"border-destructive focus-visible:outline-destructive\"\n        : \"border-border focus-visible:outline-foreground\",\n    ),\n  });\n\n  return (\n    <form\n      noValidate\n      aria-label=\"Card details\"\n      onSubmit={(e) => {\n        e.preventDefault();\n        check();\n      }}\n      className={cn(\"flex w-[min(400px,100%)] flex-col gap-5\", className)}\n    >\n      <CardPreview\n        values={values}\n        brand={brand}\n        focused={focused}\n        reduceMotion={Boolean(reduceMotion)}\n      />\n\n      <div className=\"flex flex-col gap-4\">\n        <FieldShell id={`${id}-number`} label=\"Card number\" error={errors.number}>\n          <div className=\"relative\">\n            <input\n              {...inputProps(\"number\")}\n              inputMode=\"numeric\"\n              autoComplete=\"cc-number\"\n              placeholder=\"1234 5678 9012 3456\"\n              className={cn(inputProps(\"number\").className, \"pr-16 font-mono\")}\n              onKeyDown={skipSeparator}\n              onChange={(e) => {\n                const raw = e.currentTarget.value.replace(/\\D/g, \"\");\n                const next = BRANDS[detect(raw)];\n                const { value, digits: d } = reformat(\n                  e.currentTarget,\n                  Math.max(...next.lengths),\n                  (x) => group(x, next.gaps),\n                );\n                set(\"number\", value);\n                // A shorter code is required once the brand changes away from Amex.\n                const cvcMax = BRANDS[detect(d)].cvc;\n                if (values.cvc.length > cvcMax) set(\"cvc\", values.cvc.slice(0, cvcMax));\n              }}\n            />\n            <span\n              className={cn(\n                \"pointer-events-none absolute top-1/2 right-3 -translate-y-1/2 transition-[color] duration-150 ease-out\",\n                brand === \"unknown\" ? \"text-muted-foreground\" : \"text-foreground\",\n              )}\n            >\n              <BrandMark brand={brand} reduceMotion={Boolean(reduceMotion)} />\n            </span>\n          </div>\n        </FieldShell>\n\n        <div className=\"grid grid-cols-2 gap-3\">\n          <FieldShell id={`${id}-expiry`} label=\"Expiry\" error={errors.expiry}>\n            <input\n              {...inputProps(\"expiry\")}\n              inputMode=\"numeric\"\n              autoComplete=\"cc-exp\"\n              placeholder=\"MM/YY\"\n              className={cn(inputProps(\"expiry\").className, \"font-mono\")}\n              onKeyDown={skipSeparator}\n              onChange={(e) => {\n                const { value } = reformat(e.currentTarget, 4, formatExpiry, (d) =>\n                  // A first digit of 2 to 9 can only be a single digit month.\n                  /^[2-9]/.test(d) ? `0${d}`.slice(0, 4) : d,\n                );\n                set(\"expiry\", value);\n              }}\n            />\n          </FieldShell>\n          <FieldShell id={`${id}-cvc`} label=\"CVC\" error={errors.cvc}>\n            <input\n              {...inputProps(\"cvc\")}\n              inputMode=\"numeric\"\n              autoComplete=\"cc-csc\"\n              placeholder={brand === \"amex\" ? \"1234\" : \"123\"}\n              className={cn(inputProps(\"cvc\").className, \"font-mono\")}\n              onChange={(e) => {\n                const { value } = reformat(e.currentTarget, spec.cvc, (d) => d);\n                set(\"cvc\", value);\n              }}\n            />\n          </FieldShell>\n        </div>\n\n        <FieldShell id={`${id}-name`} label=\"Name on card\" error={errors.name}>\n          <input\n            {...inputProps(\"name\")}\n            autoComplete=\"cc-name\"\n            autoCapitalize=\"words\"\n            spellCheck={false}\n            placeholder=\"Ada Lovelace\"\n            maxLength={40}\n            onChange={(e) => set(\"name\", e.currentTarget.value)}\n          />\n        </FieldShell>\n      </div>\n\n      <div className=\"flex flex-col gap-2.5\">\n        <button\n          type=\"submit\"\n          className=\"relative h-11 touch-manipulation rounded-xl bg-foreground text-[15px] font-medium text-background outline-hidden transition-[scale] duration-150 ease-out select-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-foreground active:scale-[0.96] motion-reduce:transition-none\"\n        >\n          {/* Both labels share one cell so the button never changes size. */}\n          <span className=\"grid\">\n            <ButtonLabel visible={!confirmed} reduceMotion={Boolean(reduceMotion)}>\n              Check details\n            </ButtonLabel>\n            <ButtonLabel\n              visible={confirmed}\n              reduceMotion={Boolean(reduceMotion)}\n              icon={<path d=\"m3.5 8.5 3 3 6-7\" />}\n            >\n              Details look valid\n            </ButtonLabel>\n          </span>\n        </button>\n        <p className=\"flex items-center justify-center gap-1.5 text-[13px] text-muted-foreground\">\n          <svg viewBox=\"0 0 16 16\" className=\"size-3.5 shrink-0\" {...STROKE} aria-hidden>\n            <rect x=\"3.25\" y=\"7\" width=\"9.5\" height=\"6.25\" rx=\"1.5\" />\n            <path d=\"M5.5 7V5a2.5 2.5 0 0 1 5 0v2\" />\n          </svg>\n          Demo only. Nothing is charged or sent anywhere.\n        </p>\n        <span className=\"sr-only\" aria-live=\"polite\">\n          {confirmed ? \"Card details look valid\" : \"\"}\n        </span>\n        <span className=\"sr-only\" aria-live=\"polite\">\n          {brand === \"unknown\" ? \"\" : `${spec.name} card`}\n        </span>\n      </div>\n    </form>\n  );\n}\n\nfunction FieldShell({\n  id,\n  label,\n  error,\n  children,\n}: {\n  id: string;\n  label: string;\n  error?: string;\n  children: React.ReactNode;\n}) {\n  return (\n    <div className=\"flex min-w-0 flex-col gap-2\">\n      {/* The error shares the label's row, so showing it never shifts the\n          fields below. */}\n      <div className=\"flex items-baseline justify-between gap-2\">\n        <label htmlFor={id} className=\"text-sm font-medium text-foreground select-none\">\n          {label}\n        </label>\n        {error && (\n          <span\n            key={error}\n            id={`${id}-error`}\n            className=\"truncate text-[13px] text-destructive transition-[opacity,filter,translate] duration-200 ease-[cubic-bezier(0.23,1,0.32,1)] starting:opacity-0 motion-safe:starting:translate-y-0.5 motion-safe:starting:blur-[4px]\"\n          >\n            {error}\n          </span>\n        )}\n      </div>\n      {children}\n    </div>\n  );\n}\n\nfunction CardPreview({\n  values,\n  brand,\n  focused,\n  reduceMotion,\n}: {\n  values: Values;\n  brand: Brand;\n  focused: Field | null;\n  reduceMotion: boolean;\n}) {\n  const spec = BRANDS[brand];\n  const digits = values.number.replace(/\\D/g, \"\");\n  const flipped = focused === \"cvc\";\n  const length = Math.max(spec.lengths[0], digits.length);\n  const slots = Array.from({ length }, (_, i) => digits[i] ?? \"•\");\n\n  // The focus ring is measured with offset* values, which ignore the flip's\n  // transform, and driven by motion values so moving it never re-renders.\n  const regions = useRef<Partial<Record<Field, HTMLElement | null>>>({});\n  const x = useMotionValue(0);\n  const y = useMotionValue(0);\n  const width = useMotionValue(0);\n  const height = useMotionValue(0);\n  const opacity = useMotionValue(0);\n\n  useLayoutEffect(() => {\n    const el = focused && focused !== \"cvc\" ? regions.current[focused] : null;\n    if (!el) {\n      const fade = animate(opacity, 0, { duration: 0.12, ease: \"easeOut\" });\n      return () => fade.stop();\n    }\n    // 8px and 6px of breathing room around the text it frames.\n    const target = [el.offsetLeft - 8, el.offsetTop - 6, el.offsetWidth + 16, el.offsetHeight + 12];\n    const box = [x, y, width, height];\n    // Coming from nowhere it appears in place; only a move between fields slides.\n    if (opacity.get() === 0 || reduceMotion) {\n      box.forEach((v, i) => v.jump(target[i]));\n      const fade = animate(opacity, 1, { duration: 0.2, ease: \"easeOut\" });\n      return () => fade.stop();\n    }\n    const runs = box.map((v, i) => animate(v, target[i], RING));\n    return () => runs.forEach((r) => r.stop());\n  }, [focused, reduceMotion, x, y, width, height, opacity]);\n\n  const face =\n    \"absolute inset-0 flex flex-col overflow-hidden rounded-2xl bg-foreground text-background shadow-raised backface-hidden\";\n\n  return (\n    <div aria-hidden className=\"relative aspect-[1.586] w-full [perspective:1200px] select-none\">\n      <motion.div\n        className=\"relative size-full transform-3d\"\n        initial={false}\n        animate={{ rotateY: flipped && !reduceMotion ? 180 : 0 }}\n        transition={FLIP}\n      >\n        <div\n          className={cn(\n            face,\n            \"justify-between p-6 transition-[opacity] duration-200 ease-out\",\n            reduceMotion && flipped && \"opacity-0\",\n          )}\n        >\n          <motion.span\n            className=\"pointer-events-none absolute top-0 left-0 rounded-lg border border-background/35\"\n            style={{ x, y, width, height, opacity }}\n          />\n          <div className=\"flex items-start justify-between\">\n            <Chip />\n            <BrandMark brand={brand} reduceMotion={reduceMotion} large />\n          </div>\n          <div\n            ref={(el) => {\n              regions.current.number = el;\n            }}\n            className=\"self-start font-mono text-[clamp(16px,5.2vw,21px)] tracking-wide whitespace-nowrap\"\n          >\n            {slots.map((c, i) => (\n              <span\n                // Keyed by content, so each new digit mounts and fades in\n                // through @starting-style with no JS.\n                key={`${i}-${c}`}\n                className={cn(\n                  \"inline-block transition-[opacity,translate,filter] duration-150 ease-out starting:opacity-0 motion-safe:starting:-translate-y-1 motion-safe:starting:blur-[2px]\",\n                  spec.gaps.includes(i) && \"ml-[0.6em]\",\n                  c === \"•\" && \"opacity-45\",\n                )}\n              >\n                {c}\n              </span>\n            ))}\n          </div>\n          <div className=\"flex items-end justify-between gap-6\">\n            <div\n              ref={(el) => {\n                regions.current.name = el;\n              }}\n              className=\"flex min-w-0 flex-1 flex-col gap-1\"\n            >\n              <span className=\"text-xs tracking-wide uppercase opacity-60\">Card holder</span>\n              <span className=\"truncate text-[15px] font-medium uppercase\">\n                {values.name.trim() || \"Your name\"}\n              </span>\n            </div>\n            <div\n              ref={(el) => {\n                regions.current.expiry = el;\n              }}\n              className=\"flex shrink-0 flex-col gap-1\"\n            >\n              <span className=\"text-xs tracking-wide uppercase opacity-60\">Expires</span>\n              <span className=\"font-mono text-[15px] font-medium\">\n                {values.expiry || \"MM/YY\"}\n              </span>\n            </div>\n          </div>\n        </div>\n\n        <div\n          className={cn(\n            face,\n            \"transition-[opacity] duration-200 ease-out\",\n            reduceMotion ? (flipped ? \"opacity-100\" : \"opacity-0\") : \"[transform:rotateY(180deg)]\",\n          )}\n        >\n          <div className=\"mt-6 h-11 bg-background/15\" />\n          <div className=\"flex items-center gap-3 px-6 pt-5\">\n            <div className=\"flex h-10 flex-1 items-center justify-end rounded-md bg-background px-3 font-mono text-[15px] text-foreground italic\">\n              {values.cvc || (brand === \"amex\" ? \"••••\" : \"•••\")}\n            </div>\n            <span className=\"text-xs tracking-wide uppercase opacity-60\">CVC</span>\n          </div>\n          <p className=\"mt-auto px-6 pb-5 text-xs opacity-60\">\n            Not a real card. Nothing you type leaves this page.\n          </p>\n        </div>\n      </motion.div>\n    </div>\n  );\n}\n\nfunction Chip() {\n  return (\n    <svg viewBox=\"0 0 44 32\" className=\"h-8 w-11\" fill=\"none\" aria-hidden>\n      <rect width=\"44\" height=\"32\" rx=\"6\" fill=\"currentColor\" opacity=\"0.22\" />\n      <path\n        d=\"M0 11h14m16 0h14M0 21h14m16 0h14M14 0v32M30 0v32M14 16h16\"\n        stroke=\"currentColor\"\n        strokeOpacity=\"0.3\"\n      />\n    </svg>\n  );\n}\n\n// Monochrome marks in currentColor, so they take the theme instead of\n// fighting it.\nfunction BrandMark({\n  brand,\n  reduceMotion,\n  large,\n}: {\n  brand: Brand;\n  reduceMotion: boolean;\n  large?: boolean;\n}) {\n  return (\n    <span className={cn(\"grid\", large ? \"h-8 w-12\" : \"h-6 w-9\")}>\n      {([\"unknown\", ...ORDER] as Brand[]).map((b) => (\n        <SwapIcon key={b} visible={b === brand} reduceMotion={reduceMotion}>\n          {MARKS[b]}\n        </SwapIcon>\n      ))}\n    </span>\n  );\n}\n\nconst MARKS: Record<Brand, React.ReactNode> = {\n  unknown: (\n    <g {...STROKE}>\n      <rect x=\"6.75\" y=\"4.75\" width=\"22.5\" height=\"14.5\" rx=\"2.5\" />\n      <path d=\"M6.75 9.25h22.5M10.5 15.5h4\" />\n    </g>\n  ),\n  visa: (\n    <text\n      x=\"18\"\n      y=\"16.5\"\n      textAnchor=\"middle\"\n      fontSize=\"12.5\"\n      fontWeight=\"800\"\n      fontStyle=\"italic\"\n      letterSpacing=\"-0.3\"\n      fill=\"currentColor\"\n    >\n      VISA\n    </text>\n  ),\n  mastercard: (\n    <g fill=\"currentColor\">\n      <circle cx=\"14\" cy=\"12\" r=\"7\" opacity=\"0.55\" />\n      <circle cx=\"22\" cy=\"12\" r=\"7\" opacity=\"0.9\" />\n    </g>\n  ),\n  amex: (\n    <g>\n      <rect x=\"3.75\" y=\"4.75\" width=\"28.5\" height=\"14.5\" rx=\"2.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n      <text x=\"18\" y=\"15.25\" textAnchor=\"middle\" fontSize=\"8\" fontWeight=\"800\" letterSpacing=\"0.4\" fill=\"currentColor\">\n        AMEX\n      </text>\n    </g>\n  ),\n  discover: (\n    <g fill=\"currentColor\">\n      <text x=\"15\" y=\"15\" textAnchor=\"middle\" fontSize=\"7.5\" fontWeight=\"700\" letterSpacing=\"0.2\">\n        DISC\n      </text>\n      <circle cx=\"28.5\" cy=\"12.25\" r=\"3.5\" />\n    </g>\n  ),\n};\n\nfunction SwapIcon({\n  visible,\n  reduceMotion,\n  children,\n}: {\n  visible: boolean;\n  reduceMotion: boolean;\n  children: React.ReactNode;\n}) {\n  const hidden = reduceMotion\n    ? { opacity: 0 }\n    : { scale: 0.25, opacity: 0, filter: \"blur(4px)\" };\n  return (\n    <motion.svg\n      viewBox=\"0 0 36 24\"\n      className=\"col-start-1 row-start-1 size-full\"\n      aria-hidden\n      initial={false}\n      animate={visible ? { scale: 1, opacity: 1, filter: \"blur(0px)\" } : hidden}\n      transition={ICON_SWAP}\n    >\n      {children}\n    </motion.svg>\n  );\n}\n\nfunction ButtonLabel({\n  visible,\n  reduceMotion,\n  icon,\n  children,\n}: {\n  visible: boolean;\n  reduceMotion: boolean;\n  icon?: React.ReactNode;\n  children: React.ReactNode;\n}) {\n  const hidden = reduceMotion ? { opacity: 0 } : { opacity: 0, filter: \"blur(4px)\" };\n  return (\n    <span\n      aria-hidden={!visible}\n      className=\"col-start-1 row-start-1 flex items-center justify-center gap-2\"\n    >\n      {icon && (\n        <motion.svg\n          viewBox=\"0 0 16 16\"\n          className=\"size-4 shrink-0\"\n          {...STROKE}\n          strokeWidth={2}\n          initial={false}\n          animate={\n            visible\n              ? { scale: 1, opacity: 1, filter: \"blur(0px)\" }\n              : reduceMotion\n                ? { opacity: 0 }\n                : { scale: 0.25, opacity: 0, filter: \"blur(4px)\" }\n          }\n          transition={ICON_SWAP}\n        >\n          {icon}\n        </motion.svg>\n      )}\n      <motion.span\n        initial={false}\n        animate={visible ? { opacity: 1, filter: \"blur(0px)\" } : hidden}\n        transition={ICON_SWAP}\n      >\n        {children}\n      </motion.span>\n    </span>\n  );\n}\n\nexport default function CardInputDemo() {\n  return <CardInput />;\n}\n"},{"path":"hooks/use-reduced-motion.ts","type":"registry:hook","target":"hooks/use-reduced-motion.ts","content":"\"use client\";\n\nimport { useSyncExternalStore } from \"react\";\n\n// Motion's useReducedMotion reads the media query on the very first client\n// render, but the server can't know it, so every component that renders\n// differently under reduced motion broke hydration for those users. This\n// reports false during hydration, matching the server HTML, then the real\n// preference straight after, and follows it if it changes.\nconst query = \"(prefers-reduced-motion: reduce)\";\n\nfunction subscribe(onChange: () => void) {\n  const media = window.matchMedia(query);\n  media.addEventListener(\"change\", onChange);\n  return () => media.removeEventListener(\"change\", onChange);\n}\n\nexport function useReducedMotion() {\n  return useSyncExternalStore(\n    subscribe,\n    () => window.matchMedia(query).matches,\n    () => false,\n  );\n}\n"}],"cssVars":{"light":{"shadow-raised":"0 0 0 1px oklch(0 0 0 / 0.06), 0 1px 2px oklch(0 0 0 / 0.06), 0 6px 16px -6px oklch(0 0 0 / 0.12)"},"dark":{"shadow-raised":"0 0 0 1px oklch(1 0 0 / 0.08), 0 1px 2px oklch(0 0 0 / 0.4), 0 6px 16px -6px oklch(0 0 0 / 0.6)"},"theme":{"shadow-raised":"var(--shadow-raised)"}},"categories":["inputs"],"docs":"From ui lab: https://lab.xevrion.dev/lab/card-input"}