{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "field-currency",
  "type": "registry:component",
  "title": "Currency Field",
  "description": "A money input where digits fill from the right like a register, each new digit rolling in, formatted live for the locale and currency. It shows a converted estimate, quick add chips and a balance limit that shakes when crossed.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "forms",
    "currency",
    "money",
    "amount",
    "intl",
    "payments",
    "input"
  ],
  "docs": "https://hyperblur.dev/effects/field-currency",
  "files": [
    {
      "path": "registry/hyperblur/field-currency.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/field-currency.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface FieldCurrencyProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  label?: string;\n  value?: number;\n  defaultValue?: number;\n  onChange?: (amount: number, currency: string) => void;\n  currency?: string;\n  defaultCurrency?: string;\n  currencies?: string[];\n  onCurrencyChange?: (currency: string) => void;\n  locale?: string;\n  max?: number;\n  maxLabel?: string;\n  rates?: Record<string, number>;\n  convertTo?: string;\n  quickAmounts?: number[];\n  accent?: string;\n  disabled?: boolean;\n}\n\nconst css = `\n.hb-xg10 {\n  --hb-xg10-c: #2f7bff;\n  box-sizing: border-box;\n  width: 100%;\n  font-family: inherit;\n  color: #ededed;\n}\n.hb-xg10 *, .hb-xg10 *::before, .hb-xg10 *::after { box-sizing: border-box; }\n.hb-xg10[data-disabled=\"true\"] { opacity: 0.5; pointer-events: none; }\n.hb-xg10-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 7px; font-size: 12.5px; font-weight: 500; color: #a1a1a1; }\n.hb-xg10-bal { font-size: 11.5px; font-weight: 400; color: #6f6f6f; font-variant-numeric: tabular-nums; }\n.hb-xg10-box {\n  position: relative;\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  height: 62px;\n  padding: 0 8px 0 16px;\n  border: 1px solid #262626;\n  border-radius: 14px;\n  background: linear-gradient(180deg, #161616, #0f0f0f);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.045), 0 1px 2px rgba(0, 0, 0, 0.5);\n  cursor: text;\n  transition: border-color 0.2s ease, box-shadow 0.25s ease;\n}\n.hb-xg10-box:hover { border-color: #333; }\n.hb-xg10-box:focus-within {\n  border-color: var(--hb-xg10-c);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.045), 0 0 0 4px color-mix(in srgb, var(--hb-xg10-c) 16%, transparent);\n}\n.hb-xg10[data-over=\"true\"] .hb-xg10-box { border-color: #f2555a; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.045), 0 0 0 4px rgba(242, 85, 90, 0.14); animation: hb-xg10-shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97); }\n.hb-xg10-amt {\n  position: relative;\n  display: flex;\n  align-items: baseline;\n  flex: 1;\n  min-width: 0;\n  overflow: hidden;\n  font-family: var(--font-grotesk), var(--font-sans), sans-serif;\n  font-size: 30px;\n  font-weight: 500;\n  letter-spacing: -0.02em;\n  line-height: 1.15;\n  font-variant-numeric: tabular-nums;\n  white-space: nowrap;\n}\n.hb-xg10-ch { display: inline-block; animation: hb-xg10-roll 0.32s cubic-bezier(0.22, 1, 0.36, 1); }\n.hb-xg10-ch[data-kind=\"currency\"] { margin-right: 2px; font-size: 0.72em; color: #8f8f8f; animation: none; align-self: flex-start; margin-top: 0.18em; }\n.hb-xg10-ch[data-kind=\"group\"], .hb-xg10-ch[data-kind=\"decimal\"] { color: #6f6f6f; animation: none; }\n.hb-xg10-ch[data-kind=\"fraction\"] { font-size: 0.72em; color: #a1a1a1; }\n.hb-xg10[data-zero=\"true\"] .hb-xg10-ch:not([data-kind=\"currency\"]) { color: #4a4a4a; }\n.hb-xg10-caret { display: inline-block; width: 2px; height: 0.9em; margin-left: 3px; align-self: center; border-radius: 1px; background: var(--hb-xg10-c); opacity: 0; }\n.hb-xg10-box:focus-within .hb-xg10-caret { opacity: 1; animation: hb-xg10-blink 1.1s steps(2, jump-none) infinite; }\n.hb-xg10-in { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; opacity: 0; cursor: text; font-size: 16px; }\n.hb-xg10-cur { position: relative; flex: none; }\n.hb-xg10-sel {\n  height: 34px;\n  margin: 0;\n  padding: 0 26px 0 10px;\n  border: 1px solid #2a2a2a;\n  border-radius: 999px;\n  background: linear-gradient(180deg, #1f1f1f, #161616);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);\n  color: #ededed;\n  font: inherit;\n  font-size: 12.5px;\n  font-weight: 600;\n  letter-spacing: 0.02em;\n  appearance: none;\n  -webkit-appearance: none;\n  cursor: pointer;\n}\n.hb-xg10-sel:focus-visible { outline: 2px solid var(--hb-xg10-c); outline-offset: 2px; }\n.hb-xg10-sel option { background: #161616; color: #ededed; }\n.hb-xg10-cur svg { position: absolute; right: 10px; top: 50%; width: 10px; height: 10px; margin-top: -5px; color: #8f8f8f; pointer-events: none; }\n.hb-xg10-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 9px; }\n.hb-xg10-chips { display: flex; gap: 5px; }\n.hb-xg10-chip {\n  height: 26px;\n  margin: 0;\n  padding: 0 10px;\n  border: 1px solid #262626;\n  border-radius: 999px;\n  background: #121212;\n  color: #a1a1a1;\n  font: inherit;\n  font-size: 11.5px;\n  font-weight: 500;\n  font-variant-numeric: tabular-nums;\n  cursor: pointer;\n  transition: border-color 0.2s ease, color 0.2s ease, transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-xg10-chip:hover { border-color: #3a3a3a; color: #ededed; }\n.hb-xg10-chip:active { transform: scale(0.93); }\n.hb-xg10-chip:focus-visible { outline: 2px solid var(--hb-xg10-c); outline-offset: 2px; }\n.hb-xg10-conv { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: #6f6f6f; font-variant-numeric: tabular-nums; }\n.hb-xg10[data-over=\"true\"] .hb-xg10-conv { color: #ff7a7a; }\n@keyframes hb-xg10-roll { from { opacity: 0; transform: translateY(55%); filter: blur(2px); } }\n@keyframes hb-xg10-blink { 50% { opacity: 0; } }\n@keyframes hb-xg10-shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xg10 * { transition: none !important; animation: none !important; }\n  .hb-xg10[data-over=\"true\"] .hb-xg10-box { animation: none; }\n}\n`;\n\nconst defaultRates: Record<string, number> = { USD: 1, EUR: 0.92, GBP: 0.79, BRL: 5.42, JPY: 151.3, CAD: 1.37, AUD: 1.52, CHF: 0.88 };\n\nfunction digitsOf(currency: string, locale: string) {\n  try {\n    return new Intl.NumberFormat(locale, { style: \"currency\", currency }).resolvedOptions().maximumFractionDigits ?? 2;\n  } catch {\n    return 2;\n  }\n}\n\nfunction fmt(amount: number, currency: string, locale: string) {\n  try {\n    return new Intl.NumberFormat(locale, { style: \"currency\", currency }).format(amount);\n  } catch {\n    return `${currency} ${amount.toFixed(2)}`;\n  }\n}\n\nfunction partsOf(amount: number, currency: string, locale: string) {\n  try {\n    return new Intl.NumberFormat(locale, { style: \"currency\", currency }).formatToParts(amount);\n  } catch {\n    return [{ type: \"integer\", value: amount.toFixed(0) }] as Intl.NumberFormatPart[];\n  }\n}\n\nexport function FieldCurrency({\n  label = \"Amount\",\n  value,\n  defaultValue = 0,\n  onChange,\n  currency,\n  defaultCurrency = \"USD\",\n  currencies = [\"USD\", \"EUR\", \"GBP\", \"BRL\", \"JPY\", \"CAD\"],\n  onCurrencyChange,\n  locale = \"en-US\",\n  max,\n  maxLabel = \"Available\",\n  rates = defaultRates,\n  convertTo = \"EUR\",\n  quickAmounts = [10, 50, 100],\n  accent = \"#2f7bff\",\n  disabled = false,\n  className = \"\",\n  style,\n  ...rest\n}: FieldCurrencyProps) {\n  const id = React.useId();\n  const [innerCur, setInnerCur] = React.useState(defaultCurrency);\n  const cur = currency ?? innerCur;\n  const frac = digitsOf(cur, locale);\n  const scale = Math.pow(10, frac);\n  const controlled = value !== undefined;\n  const [innerMinor, setInnerMinor] = React.useState(Math.round(defaultValue * scale));\n  const minor = controlled ? Math.round(value * scale) : innerMinor;\n  const amount = minor / scale;\n  const over = max !== undefined && amount > max;\n\n  function setMinor(n: number) {\n    const clamped = Math.max(0, Math.min(n, 99999999999));\n    if (!controlled) setInnerMinor(clamped);\n    onChange?.(clamped / scale, cur);\n  }\n\n  function onKey(e: React.KeyboardEvent<HTMLInputElement>) {\n    if (e.metaKey || e.ctrlKey || e.altKey) return;\n    if (/^\\d$/.test(e.key)) {\n      e.preventDefault();\n      if (String(minor).length >= 11) return;\n      setMinor(minor * 10 + Number(e.key));\n    } else if (e.key === \"Backspace\") {\n      e.preventDefault();\n      setMinor(Math.floor(minor / 10));\n    } else if (e.key === \"Delete\" || e.key === \"Escape\") {\n      e.preventDefault();\n      setMinor(0);\n    } else if (e.key === \"ArrowUp\" || e.key === \"ArrowDown\") {\n      e.preventDefault();\n      const stepMinor = (e.shiftKey ? 10 : 1) * scale;\n      setMinor(minor + (e.key === \"ArrowUp\" ? stepMinor : -stepMinor));\n    }\n  }\n\n  function onPaste(e: React.ClipboardEvent<HTMLInputElement>) {\n    e.preventDefault();\n    const raw = e.clipboardData.getData(\"text\").replace(/[^\\d.,]/g, \"\");\n    if (!raw) return;\n    const lastSep = Math.max(raw.lastIndexOf(\".\"), raw.lastIndexOf(\",\"));\n    const hasFrac = lastSep >= 0 && raw.length - lastSep - 1 <= frac && raw.length - lastSep - 1 > 0;\n    const whole = (hasFrac ? raw.slice(0, lastSep) : raw).replace(/[.,]/g, \"\");\n    const part = hasFrac ? raw.slice(lastSep + 1).padEnd(frac, \"0\") : \"\".padEnd(frac, \"0\");\n    setMinor(Number(`${whole || \"0\"}${part}`));\n  }\n\n  function changeCurrency(next: string) {\n    if (currency === undefined) setInnerCur(next);\n    onCurrencyChange?.(next);\n    const nf = digitsOf(next, locale);\n    const nextMinor = Math.round(amount * Math.pow(10, nf));\n    if (!controlled) setInnerMinor(nextMinor);\n    onChange?.(nextMinor / Math.pow(10, nf), next);\n  }\n\n  const parts = partsOf(amount, cur, locale);\n  const chars: { ch: string; kind: string; key: string }[] = [];\n  let digitPos = 0;\n  for (let p = parts.length - 1; p >= 0; p--) {\n    const part = parts[p];\n    for (let i = part.value.length - 1; i >= 0; i--) {\n      const ch = part.value[i];\n      const isDigit = /\\d/.test(ch);\n      if (part.type === \"literal\" && /\\s/.test(ch)) continue;\n      chars.unshift({ ch, kind: part.type, key: isDigit ? `d${digitPos}-${ch}` : `${part.type}${digitPos}-${i}` });\n      if (isDigit) digitPos++;\n    }\n  }\n\n  const target = cur === convertTo ? \"USD\" : convertTo;\n  const rateFrom = rates[cur];\n  const rateTo = rates[target];\n  const converted = rateFrom && rateTo ? (amount / rateFrom) * rateTo : null;\n  const vars = { \"--hb-xg10-c\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <div className={`hb-xg10 ${className}`} style={vars} data-over={over} data-zero={minor === 0} data-disabled={disabled} {...rest}>\n      <style href=\"hb-field-currency\" precedence=\"default\">{css}</style>\n      <div className=\"hb-xg10-top\">\n        <label htmlFor={`${id}-in`}>{label}</label>\n        {max !== undefined && (\n          <span className=\"hb-xg10-bal\">\n            {maxLabel} {fmt(max, cur, locale)}\n          </span>\n        )}\n      </div>\n      <div className=\"hb-xg10-box\">\n        <div className=\"hb-xg10-amt\" aria-hidden=\"true\">\n          {chars.map((c) => (\n            <span key={c.key} className=\"hb-xg10-ch\" data-kind={c.kind}>\n              {c.ch}\n            </span>\n          ))}\n          <span className=\"hb-xg10-caret\" />\n        </div>\n        <input\n          id={`${id}-in`}\n          className=\"hb-xg10-in\"\n          inputMode=\"decimal\"\n          autoComplete=\"transaction-amount\"\n          value={fmt(amount, cur, locale)}\n          onChange={(e) => {\n            const d = e.target.value.replace(/\\D/g, \"\").slice(0, 11);\n            setMinor(Number(d || \"0\"));\n          }}\n          onKeyDown={onKey}\n          onPaste={onPaste}\n          disabled={disabled}\n          aria-invalid={over}\n          aria-describedby={`${id}-conv`}\n        />\n        <span className=\"hb-xg10-cur\">\n          <select className=\"hb-xg10-sel\" aria-label=\"Currency\" value={cur} onChange={(e) => changeCurrency(e.target.value)} disabled={disabled}>\n            {currencies.map((c) => (\n              <option key={c} value={c}>\n                {c}\n              </option>\n            ))}\n          </select>\n          <svg viewBox=\"0 0 10 10\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" aria-hidden=\"true\">\n            <path d=\"M2.5 4l2.5 2.5L7.5 4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n          </svg>\n        </span>\n      </div>\n      <div className=\"hb-xg10-foot\">\n        <div className=\"hb-xg10-chips\">\n          {quickAmounts.map((q) => (\n            <button key={q} type=\"button\" className=\"hb-xg10-chip\" onClick={() => setMinor(minor + Math.round(q * scale))} disabled={disabled}>\n              +{fmt(q, cur, locale).replace(/\\.00$|,00$/, \"\")}\n            </button>\n          ))}\n          {max !== undefined && (\n            <button type=\"button\" className=\"hb-xg10-chip\" onClick={() => setMinor(Math.round(max * scale))} disabled={disabled}>\n              Max\n            </button>\n          )}\n        </div>\n        <span className=\"hb-xg10-conv\" id={`${id}-conv`} aria-live=\"polite\">\n          {over ? `Over by ${fmt(amount - (max ?? 0), cur, locale)}` : converted !== null && amount > 0 ? `≈ ${fmt(converted, target, locale)}` : \"Digits fill from the right\"}\n        </span>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}