@eifi1/ui-kit 0.51.6 → 0.51.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +5 -3
  2. package/dist/admin/admin-action-confirm.js +2 -4
  3. package/dist/admin/admin-action-confirm.js.map +1 -1
  4. package/dist/auth/complete-name-dialog.d.ts +3 -2
  5. package/dist/auth/complete-name-dialog.js +1 -4
  6. package/dist/auth/complete-name-dialog.js.map +1 -1
  7. package/dist/billing/cancel-request.d.ts +11 -2
  8. package/dist/billing/cancel-request.js +15 -3
  9. package/dist/billing/cancel-request.js.map +1 -1
  10. package/dist/billing/cancel-subscription.d.ts +2 -2
  11. package/dist/billing/cancel-subscription.js +2 -7
  12. package/dist/billing/cancel-subscription.js.map +1 -1
  13. package/dist/billing/plan-switch.d.ts +2 -2
  14. package/dist/billing/plan-switch.js +2 -4
  15. package/dist/billing/plan-switch.js.map +1 -1
  16. package/dist/components/amount-input.d.ts +9 -4
  17. package/dist/components/amount-input.js +2 -3
  18. package/dist/components/amount-input.js.map +1 -1
  19. package/dist/components/calculator.d.ts +21 -2
  20. package/dist/components/calculator.js +53 -14
  21. package/dist/components/calculator.js.map +1 -1
  22. package/dist/components/combobox-core.d.ts +8 -5
  23. package/dist/components/combobox-core.js +3 -4
  24. package/dist/components/combobox-core.js.map +1 -1
  25. package/dist/components/combobox.js +2 -2
  26. package/dist/components/combobox.js.map +1 -1
  27. package/dist/components/data-table-mobile.d.ts +24 -0
  28. package/dist/components/data-table-mobile.js +20 -1
  29. package/dist/components/data-table-mobile.js.map +1 -1
  30. package/dist/components/data-table.d.ts +13 -5
  31. package/dist/components/data-table.js +35 -9
  32. package/dist/components/data-table.js.map +1 -1
  33. package/dist/components/dialog-frame.d.ts +2 -1
  34. package/dist/components/dialog-frame.js.map +1 -1
  35. package/dist/components/entity-combobox.js +4 -2
  36. package/dist/components/entity-combobox.js.map +1 -1
  37. package/dist/components/inline-entity-combobox.js +4 -3
  38. package/dist/components/inline-entity-combobox.js.map +1 -1
  39. package/dist/components/list.js +1 -1
  40. package/dist/components/list.js.map +1 -1
  41. package/dist/components/modal.d.ts +24 -0
  42. package/dist/components/modal.js +9 -3
  43. package/dist/components/modal.js.map +1 -1
  44. package/dist/components/money-draft.js +7 -5
  45. package/dist/components/money-draft.js.map +1 -1
  46. package/dist/components/money-field.d.ts +2 -2
  47. package/dist/components/money-field.js.map +1 -1
  48. package/dist/components/multi-entity-combobox.js +2 -1
  49. package/dist/components/multi-entity-combobox.js.map +1 -1
  50. package/dist/components/number-field.d.ts +6 -4
  51. package/dist/components/number-field.js +3 -2
  52. package/dist/components/number-field.js.map +1 -1
  53. package/dist/components/number-input.d.ts +4 -1
  54. package/dist/components/number-input.js +3 -2
  55. package/dist/components/number-input.js.map +1 -1
  56. package/dist/components/numpad-sheet.js.map +1 -1
  57. package/dist/components/reauth-dialog.d.ts +4 -5
  58. package/dist/components/reauth-dialog.js +1 -4
  59. package/dist/components/reauth-dialog.js.map +1 -1
  60. package/dist/components/series-chart-axes.d.ts +7 -0
  61. package/dist/components/series-chart-axes.js +1 -0
  62. package/dist/components/series-chart-axes.js.map +1 -1
  63. package/dist/components/tabs.js +12 -10
  64. package/dist/components/tabs.js.map +1 -1
  65. package/dist/eslint/index.js +1 -1
  66. package/dist/hooks/use-dismiss.js.map +1 -1
  67. package/dist/hooks/use-overlay-history.d.ts +7 -1
  68. package/dist/hooks/use-overlay-history.js +16 -2
  69. package/dist/hooks/use-overlay-history.js.map +1 -1
  70. package/dist/lib/calc.d.ts +7 -1
  71. package/dist/lib/calc.js +3 -1
  72. package/dist/lib/calc.js.map +1 -1
  73. package/dist/lib/clipboard-minus.d.ts +2 -2
  74. package/dist/lib/clipboard-minus.js +1 -1
  75. package/dist/lib/clipboard-minus.js.map +1 -1
  76. package/dist/lib/decimal-marks.d.ts +7 -1
  77. package/dist/lib/decimal-marks.js +5 -2
  78. package/dist/lib/decimal-marks.js.map +1 -1
  79. package/dist/lib/format.d.ts +5 -3
  80. package/dist/lib/format.js +12 -0
  81. package/dist/lib/format.js.map +1 -1
  82. package/dist/lib/text-match.d.ts +9 -0
  83. package/dist/lib/text-match.js +4 -0
  84. package/dist/lib/text-match.js.map +1 -1
  85. package/dist/tour/tour.d.ts +3 -1
  86. package/dist/tour/tour.js +9 -3
  87. package/dist/tour/tour.js.map +1 -1
  88. package/dist/tour/use-tour-url-sync.js +2 -2
  89. package/dist/tour/use-tour-url-sync.js.map +1 -1
  90. package/package.json +3 -3
  91. package/src/admin/admin-action-confirm.tsx +4 -5
  92. package/src/auth/complete-name-dialog.tsx +5 -7
  93. package/src/billing/cancel-request.ts +28 -6
  94. package/src/billing/cancel-subscription.tsx +4 -11
  95. package/src/billing/plan-switch.tsx +5 -8
  96. package/src/components/amount-input.tsx +14 -7
  97. package/src/components/calculator.tsx +98 -17
  98. package/src/components/combobox-core.tsx +10 -7
  99. package/src/components/combobox.tsx +5 -6
  100. package/src/components/data-table-mobile.tsx +49 -1
  101. package/src/components/data-table.tsx +66 -11
  102. package/src/components/dialog-frame.tsx +2 -1
  103. package/src/components/entity-combobox.tsx +4 -1
  104. package/src/components/inline-entity-combobox.tsx +5 -3
  105. package/src/components/list.tsx +4 -1
  106. package/src/components/modal.tsx +39 -3
  107. package/src/components/money-draft.ts +16 -5
  108. package/src/components/money-field.tsx +2 -2
  109. package/src/components/multi-entity-combobox.tsx +1 -0
  110. package/src/components/number-field.tsx +14 -7
  111. package/src/components/number-input.tsx +9 -3
  112. package/src/components/numpad-sheet.tsx +4 -3
  113. package/src/components/reauth-dialog.tsx +6 -10
  114. package/src/components/series-chart-axes.ts +8 -0
  115. package/src/components/tabs.tsx +33 -17
  116. package/src/hooks/use-dismiss.ts +3 -2
  117. package/src/hooks/use-overlay-history.ts +38 -2
  118. package/src/lib/calc.ts +13 -2
  119. package/src/lib/clipboard-minus.ts +14 -4
  120. package/src/lib/decimal-marks.ts +12 -3
  121. package/src/lib/format.ts +30 -3
  122. package/src/lib/text-match.ts +12 -0
  123. package/src/tour/tour.tsx +21 -4
  124. package/src/tour/use-tour-url-sync.ts +7 -3
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/amount-input.tsx"],"sourcesContent":["import { useId, useMemo, useRef } from \"react\";\nimport { ChevronDown } from \"lucide-react\";\nimport type { ReactNode, Ref } from \"react\";\nimport { CurrencyOptionList, getCurrency } from \"./currency-option-list\";\nimport { useComboboxCore } from \"./combobox-core\";\nimport { FIELD_BASE, FIELD_DISPLAY, FIELD_INVALID, FLOATING_INPUT_CLASS, FloatingField } from \"./field-base\";\nimport { cn } from \"../lib/cn\";\nimport { currencyMinorDigits } from \"../lib/format\";\nimport { roundHalfAway } from \"../lib/round\";\nimport { CalculatorButton, type CalculatorButtonLabels } from \"./calculator\";\nimport { NumberPadSheet, type NumberPadSheetLabels } from \"./numpad-sheet\";\nimport {\n DEFAULT_COMMON_LABELS,\n DEFAULT_CURRENCY_LABELS,\n useKitLabels,\n useKitLocale,\n type CurrencyLabels,\n} from \"../i18n/kit-labels\";\nimport {\n commitExpression,\n evaluateExpression,\n formatResult,\n isBareAmount,\n looksLikeExpression,\n sanitizeLive,\n splitLeadingSign,\n} from \"../lib/calc\";\nimport {\n FieldCaption,\n LockedReason,\n mergeRefs,\n type DisabledReasonDisplay,\n type FieldHelpProps,\n type LockReason,\n} from \"./field-parts\";\nimport { useEndWidth, useNumericField } from \"./numeric-field\";\nimport type { CommitScope } from \"./write-lock\";\nimport { dataAttributes, type DataAttributes } from \"../lib/data-attributes\";\n\n/** {@link AmountInput}'s props — exported since 0.34 (refactor audit 2026-10, API-9): a\n * wrapper typed itself off `ComponentProps<typeof AmountInput>` until then. */\nexport interface AmountInputProps extends FieldHelpProps, DataAttributes {\n value: string;\n onChange: (value: string) => void;\n currency?: string;\n onCurrencyChange?: (code: string) => void;\n placeholder?: string;\n label?: ReactNode;\n disabled?: boolean;\n /** Required and unanswered — {@link FIELD_INVALID}. See {@link Input}'s `invalid`. */\n invalid?: boolean;\n /**\n * What is wrong with the amount, in the caller's own words — {@link Input}'s `error`\n * (keksdose K4: \"exceeds the outstanding balance\" was a loose `<p>` beside the field\n * that nothing pointed at). Rendered under the field, after a text `hint`; merged into\n * `aria-describedby` after the caller's ids and the hint's; implies `invalid`, so the\n * field paints as well as announces. `null`, `false` and `\"\"` are no message.\n * {@link MoneyField} takes it too.\n */\n error?: ReactNode;\n /**\n * Show the desktop calculator trigger (default `true`). `false` for an amount in an\n * ephemeral close-on-blur editor — a budget's assigned cell, a VAT cell (keksdose K6)\n * — where a click on the icon blurs the field and tears the editor down before the\n * popover can open. Typing a calculation (\"200+50\", then Enter) still evaluates, and\n * a phone keeps its numpad, exactly as {@link NumberInput}'s `calculator={false}`.\n */\n calculator?: boolean;\n /** The field's WRAPPER — width, a margin, a flex share. The `<input>` is\n * `inputClassName`'s. */\n className?: string;\n /**\n * Classes for the `<input>` itself — {@link NumberInput}'s and {@link Input}'s prop of\n * the same name, merged the same way: after everything the field sets for LOOKS — the\n * base classes, the plain end padding, the display shape's centring and the `tone`\n * colour — so it can restyle the figure (`text-end` for a money column whose decimal\n * points line up, `font-medium`, a tighter `py-1` or a symmetric `px-2` in a table\n * cell, `text-transparent` while a figure is being re-fetched), and before what the\n * field needs to WORK: the end padding the calculator and the currency chip reserve,\n * and the invalid border. Neither of those can be taken away by accident — a caller's\n * `px-2` keeps its start edge and the digits still stop short of the chip, and a\n * borderless cell's `border-transparent` still turns red when the value is wrong.\n *\n * keksdose G7: the invoice's VAT cell right-aligns its figure, and with only\n * `className` (the wrapper) it reached the element through `[&_input]:text-end` — a\n * descendant selector that depends on the field's inner markup, which the kit is free\n * to change, and that a reader of the call site has to decode. {@link MoneyField}\n * passes it through, and `RhfMoneyField` takes it too.\n *\n * keksdose 0.24: until then it sat BEFORE the plain end padding (`pe-3`) and the tone,\n * so the budget's assigned cell could not make its padding symmetric (`px-2` came out\n * `px-2 pe-3`) and the holdings price could not hide an outflow-toned figure while\n * re-fetching — both were back on `[&_input]:` selectors on the wrapper.\n */\n inputClassName?: string;\n id?: string;\n /** Names the field when it has no visible `label` (a table cell, the display shape). */\n \"aria-label\"?: string;\n /**\n * Set on the `<input>`, with `id` above. Declared so `Field`'s render-prop spread —\n * `{(ids) => <AmountInput {...ids} … />}` — is typed and reaches the input: the\n * hint and error are described, a required amount is announced as required, and\n * `aria-invalid` paints {@link FIELD_INVALID} the way `invalid` does.\n */\n \"aria-describedby\"?: string;\n \"aria-invalid\"?: boolean | \"true\" | \"false\";\n \"aria-required\"?: boolean | \"true\" | \"false\";\n /**\n * BCP 47 tag for this field — {@link NumberInput}'s `locale` (0.34, DUP-10): the decimal\n * mark the field SHOWS and reads typing in (\"1,5\" for fr-CH, \"1.5\" for de-CH, as `Intl`\n * decides), and the language of the currency picker's search. Default the\n * `<UiKitProvider locale>`, else the runtime's. `value` and `onChange` stay\n * dot-decimal.\n */\n locale?: string;\n /** {@link NumberInput}'s `hint`, the same rule: a {@link FieldHint} \"?\" rides the\n * label's own line, beside the label (not at the far end, where the calculator and\n * the currency chip live); plain TEXT (a string or a number) is a caption UNDER\n * the field, attached through `aria-describedby` after the caller's own. A phone's\n * `variant=\"display\"` has no visible label, so a FieldHint is dropped there; a\n * caption still shows.\n *\n * Since 0.34 a FieldHint is that caption at Large and on a touch screen, as on\n * NumberInput since 0.32 (`useInlineHint`, docs/text-size-harmonization.md §4: a fact\n * a finger cannot hover open is printed). A `HelpPopover` — help, not a fact (§10.23)\n * — stays on the label line at every size. */\n hint?: ReactNode;\n /** Every user-facing string this component and the two it composes own, so a\n * translating host can supply its own. Each key optional, and each a per-field\n * override of the kit-wide translation in `<UiKitProvider labels>`: `currency`\n * and `currencySearch` of its `currency` namespace, the rest of `calculator`.\n * `currency` names the picker chip, composed with the selected code through\n * `common.fieldValue`; the rest are pass-through. */\n labels?: {\n currency?: string;\n currencySearch?: string;\n /** Names the calculator TRIGGER this component renders. `calculator` below\n * names the controls inside the popover it opens. */\n calculatorTrigger?: string;\n pad?: NumberPadSheetLabels;\n calculator?: CalculatorButtonLabels;\n };\n /** Translated currency names for the chip's picker, keyed by ISO code. The same\n * sparse override `CurrencySelect` takes, and for the same reason: the names in\n * `CURRENCIES` are shipped data, so without this they are the one English word\n * left in a translated row. Not part of `labels` because it is keyed by DATA\n * rather than by a fixed set of slots, and an app passes the same map to both\n * pickers. */\n currencyNames?: Record<string, string>;\n /** Offer only these ISO codes in the chip's list, in this order — `CurrencySelect`'s\n * `options`, since the chip renders CurrencySelect's list (round 0.34 Wave 2, DUP-4).\n * Default every currency the kit knows. */\n currencyOptions?: string[];\n /** Focus the field on mount — on mobile this also opens the numpad sheet, so a\n * new-transaction form can jump straight to amount entry (feedback #70). */\n autoFocus?: boolean;\n /**\n * Tint the typed figure by what it will DO (Keksdose feedback #167).\n *\n * The direction is chosen with a toggle beside the field rather than typed, so\n * the digits alone say nothing about which way the money goes — on the one screen\n * where getting that backwards is the expensive mistake. Colour says it\n * continuously, and it costs no layout. It stays the MAIN indication (live #201\n * rework: *\"The main indication shall still be the color\"*); {@link negative}\n * renders the sign as a second, quieter signal in front of the figure.\n *\n * Never the ONLY signal: the toggle it mirrors is right there, labelled, so this\n * is reinforcement rather than the sole carrier of the meaning.\n */\n tone?: \"neutral\" | \"outflow\" | \"inflow\";\n /**\n * The SIGN of the figure, owned by the caller's direction control (Keksdose live\n * #201 rework: *\"Outflow should be negative and inflow positive … the sign shall\n * be displayed but not necessarily be typed in\"*).\n *\n * `value` stays the MAGNITUDE. The minus is glued on at render time and stripped\n * off again before anything is reported back, so the caller never sees its own\n * prefix echoed and no code path can end up applying it twice. That is the whole\n * cure: there is exactly ONE place the sign lives, and it is not the text.\n *\n * Because it is rendered rather than stored it cannot be deleted (the next render\n * puts it back), a select-all-and-retype keeps the direction, and the caret needs\n * no minding.\n *\n * Since 0.15.5 it is drawn on its own too, for a read-only or disabled signed figure\n * (an \"Items total\" of −5.18): no `onNegativeChange` needed just to show the minus.\n */\n negative?: boolean;\n /**\n * A sign the user TYPED, or a calculation that resolved to a signed number.\n *\n * SET, never flip. A \"-\" means *\"this is an outflow\"*, so typing it twice says the\n * same thing twice — which is exactly what the rework asks for (*\"Subtracting\n * values twice resulting in inflow -> outflow and back to inflow seems not\n * reasonable\"*). \"+\" says the other direction.\n *\n * Its presence is what ARMS the whole sign behaviour. A field with no direction\n * control — an account's starting balance, a loan payment, a holding's cost —\n * passes neither prop and keeps a text that is the whole truth, minus included.\n */\n onNegativeChange?: (negative: boolean) => void;\n /**\n * How the field presents itself ON A PHONE (Keksdose feedback #176).\n *\n * `\"field\"` (default) is the labelled, bordered input used everywhere else.\n *\n * `\"display\"` keeps every mechanic — the same `<input>`, the same numpad sheet,\n * the same currency picker, the same commit/blur contract — and only drops the\n * chrome: no border, no fill, no floating label, the figure set at display size.\n * On a form whose whole point is one number, a bordered `text-sm` box draws the\n * amount at the same weight as the memo beside it; this makes it the headline\n * instead. It stays fully editable — the underline and the caret are what say so.\n *\n * Phone-only by construction: it keys off the same breakpoint as the numpad, so\n * from `md` up the field is byte-for-byte the normal one and a desktop grid keeps\n * its column rhythm.\n */\n variant?: \"field\" | \"display\";\n /**\n * Where the figure sits in its row, for `variant=\"display\"` only (Keksdose\n * feedback #176 rework).\n *\n * `\"start\"` (default) keeps it flush left, in the reading column the fields\n * below it share — and it is what the entry forms use, because a figure that\n * starts at a known edge is legible at any width: when the value outgrows the\n * field, the digits that scroll out of sight are the trailing ones, not the\n * magnitude (Keksdose feedback #430 rework).\n *\n * `\"center\"` makes it a centred headline. It centres in the width that REMAINS\n * after the trailing currency control, not in the whole box: the control is\n * pinned to the right edge, so a plain `text-center` would centre the figure\n * under it and the last digits would sit behind the chip. This used to mirror\n * the control's reservation onto the left instead, which centred correctly but\n * spent twice the control's width on padding — fatal on a 375px screen, where\n * it left a 36px figure 16px to live in.\n */\n align?: \"start\" | \"center\";\n /**\n * Decimals the committed amount is rounded to (kastlan 0.12: \"12.345\" and a\n * calculator's \"100/3\" reached a `Numeric(10,2)` column unrounded and failed with a\n * 422). Default: the currency's minor unit, from `Intl` (CHF and EUR 2, JPY 0). With\n * no `currency`, nothing is rounded unless this is set. Rounding is half away from\n * zero (12.345 → 12.35, -12.345 → -12.35) and happens when the figure settles: on\n * blur, on Enter, and on every result the calculator writes back. Keystrokes are left\n * alone, so \"12.3\" can still become \"12.34\".\n *\n * ⚠️ **A unit price or a rate needs `digits`.** The default is right for an amount of\n * money and silently wrong for a price per unit: a fund's NAV of 123.4567 or fuel at\n * 1.789 €/l is stored as 123.46 / 1.79, and no test fails (keksdose G2, a\n * `Numeric(18,6)` holding price and a `Numeric(18,4)` unit price). Pass the column's\n * scale: `digits={4}`, `digits={6}`.\n *\n * **Set `digits` for any sub-currency scale** — not only a price: any field whose\n * column holds more decimals than the currency's minor unit. A split line stored at\n * the ledger's 4dp (`Numeric(18,4)`) and loaded as 12.3456 is SHOWN as 12.35, and\n * committed as 12.35 as soon as the user tabs through it (blur settles) — so the form\n * no longer equals what the server holds: the lines stop summing to the 4dp total,\n * and Save is held (keksdose live #240). With a `currency`, every commit rounds to that currency's\n * minor unit unless `digits` says otherwise: pass the column's scale (`digits={4}`).\n */\n digits?: number;\n /** The smallest amount the field settles on. A lower figure is raised to it when it\n * settles, like `digits`. Compared with the signed figure. */\n min?: number;\n /** The largest amount the field settles on (a deposit release capped at the\n * balance). A higher figure is lowered to it when it settles. */\n max?: number;\n /**\n * The SETTLED figure, dot-decimal, sign included — fired on blur, on Enter, on the\n * numpad's \"=\" and on every result the calculator writes back, never on a keystroke\n * (\"1200+\" is not a figure yet). `onChange` still reports every keystroke; this is\n * for a host that stores a number and must not see drafts (kastlan 52; see\n * {@link MoneyField}, which is built on it).\n */\n onCommit?: (value: string) => void;\n /**\n * Why the amount cannot be changed — {@link NumberInput}'s `disabledReason` (0.34,\n * round 0.34 C2), for an amount that SAVES itself: a budget row's assigned cell, a\n * price committed on blur. `disabled` takes the field out of the tab order, so the\n * reason never reached a keyboard.\n *\n * With a reason the field stays in the tab order and shows its figure, `readOnly` (the\n * settled grey FIELD_BASE gives a `[readonly]` field) and `aria-disabled`. Nothing\n * changes the amount: the calculator and the phone's numpad are not offered, the\n * currency chip is a read-out rather than a picker, and neither blur nor Enter\n * settles — so `onChange`, `onCommit`, `onNegativeChange` and `onCurrencyChange` are\n * never called. Enter is swallowed, so the field does not submit the form around it.\n * The reason is a line under the field at Large and on a touch screen, else in the kit\n * {@link Tooltip} (`disabledReasonDisplay`), and on the input's `aria-describedby`,\n * between the caption and the error. Wins over `disabled`. {@link MoneyField} and\n * `RhfMoneyField` take it too.\n */\n disabledReason?: ReactNode;\n /**\n * Where the reason shows — {@link Button}'s `disabledReasonDisplay`: by default a line\n * under the field at Large and on a touch screen, the tooltip otherwise (§4 \"No fact\n * only in a tooltip\"; DUP-3, refactor audit 2026-10).\n */\n disabledReasonDisplay?: DisabledReasonDisplay;\n /**\n * This amount COMMITS — {@link Button}'s `commit`, NumberInput's: under a locked\n * {@link WriteLockProvider} it is locked the `disabledReason` way with the lock's reason\n * (which wins over its own). An amount that only reaches the server through its form's\n * Save leaves this off and stays editable under the lock; the Save takes `commit`. No\n * provider, or an unlocked one: no effect.\n */\n commit?: CommitScope;\n /** The `<input>`. A React 19 ref prop since 0.34 (MOD-4, refactor audit 2026-10); it\n * was `forwardRef`. */\n ref?: Ref<HTMLInputElement>;\n}\n\n/**\n * A settled figure, rounded to `digits` (half away from zero) and clamped to\n * `min`/`max`. Only a plain number is touched. A half-typed draft or an expression\n * comes back as it was. Rounding is `lib/round.ts`'s, shared with `roundToCurrency`\n * (BUG-11: this copy blanked \"0.0000001\" and a 22-digit figure on blur).\n */\nfunction settleAmount(text: string, digits: number | undefined, min?: number, max?: number): string {\n const t = text.trim();\n if (!/^-?\\d*\\.?\\d*$/.test(t) || !/\\d/.test(t)) return text;\n let n = Number(t);\n if (!Number.isFinite(n)) return text;\n if (digits !== undefined) n = roundHalfAway(n, digits);\n if (min !== undefined && n < min) n = min;\n if (max !== undefined && n > max) n = max;\n const out = formatResult(n);\n // Unchanged figures keep their own spelling (\"12.50\" stays \"12.50\").\n return Number(out) === Number(t) ? text : out;\n}\n\n// The locale's decimal mark and the grouping parse (kastlan 40, keksdose G1) live in\n// `lib/decimal-marks.ts`, read through the engine NumberInput and this field share\n// (`numeric-field.ts`, DUP-10).\n\n// The consuming app's ONE money palette (`--money-expense` / `--money-income`),\n// not a bespoke rose/emerald pairing: a figure being typed has to wear the same\n// colour the same figure will wear once it is a row in the table behind the form\n// (Keksdose dev#434). The utilities are unlayered and theme-aware, so no `dark:`\n// variant is needed and they win over the field's own text colour regardless of\n// where `cn` puts them.\nconst TONE_CLASS: Record<\"neutral\" | \"outflow\" | \"inflow\", string> = {\n neutral: \"\",\n outflow: \"text-money-neg\",\n inflow: \"text-money-pos\",\n};\n\n// The shared chrome-less treatment at money size. `tabular-nums` so digits don't\n// reflow the figure as they are typed; FIELD_DISPLAY's own muted placeholder\n// colour is what keeps an EMPTY form from painting its zero in the direction tint\n// (`tone` is computed from 0, which reads as an inflow).\nconst DISPLAY_INPUT_CLASS = cn(FIELD_DISPLAY, \"text-4xl font-semibold leading-tight tracking-tight tabular-nums\");\n\n/**\n * Is `text` the ANSWER to `previous`, or something typed OVER it?\n *\n * \"The old text was a sum and the new one is bare\" cannot tell those apart, and both\n * gestures are ordinary: select-all-and-retype after a typo, or backspacing \"-20+\"\n * back down to a fresh figure. Read as an answer, they move the direction chip — so\n * an outflow of 7 quietly booked +7.00 (live #201 rework).\n *\n * The question that does separate them is arithmetic, not shape: evaluate what the\n * text replaced and see whether this IS that number. \"-12+30\" → \"18\" still is, so a\n * sum that comes out positive still takes the chip with it; \"-20+50\" → \"7\" is not,\n * and \"-20+\" evaluates to nothing at all.\n */\nfunction isResultOf(previous: string, text: string, settle: (text: string) => string): boolean {\n const n = evaluateExpression(previous);\n // Compared settled, since the field rounds what the calculator hands it.\n return n !== null && settle(formatResult(n)) === text.trim();\n}\n\nexport function AmountInput(props: AmountInputProps) {\n const {\n ref,\n value,\n onChange,\n currency,\n onCurrencyChange,\n placeholder,\n label,\n className,\n inputClassName,\n id,\n \"aria-label\": ariaLabel,\n \"aria-required\": ariaRequired,\n autoFocus,\n tone = \"neutral\",\n negative = false,\n onNegativeChange,\n align = \"start\",\n labels,\n currencyNames,\n currencyOptions,\n digits: digitsProp,\n min,\n max,\n onCommit,\n disabledReasonDisplay,\n } = props;\n const generatedId = useId();\n const fieldId = id ?? generatedId;\n // The sign is DISPLAYED, not stored (live #201 rework). `value` is the\n // magnitude; the minus is glued on here and taken off again in handleText, so\n // the two can never disagree and the caller can never double-apply it. Only in\n // front of a bare amount: an expression being typed (\"12-30\") owns its own\n // minus and has to survive keystroke-for-keystroke.\n const signOwned = onNegativeChange !== undefined;\n // The sign is DRAWN whenever `negative` says so, handler or not (keksdose live #366):\n // a read-only or disabled total (\"−5.18\") used to need a dummy `onNegativeChange`\n // just to show its minus. Without the handler there is nothing to toggle — a typed\n // minus simply stays in the text, as in any field without a direction control.\n const shown = negative && isBareAmount(value) ? `-${value}` : value;\n // What the user SEES is `shown` with the locale's decimal mark (kastlan 40: a\n // fr-CH user typed \"1,5\" and watched it turn into \"1.5\" under their fingers). Display only — `value`, `onChange`, the sign split and the settle all\n // stay dot-decimal, because that string is the contract: RhfMoneyField's\n // `parseAmount`, every app's `Number(value)` and the calculator's evaluator read\n // it. The way back is free: {@link sanitizeLive} already folds a typed \",\" into\n // \".\", so a comma typed, pasted or tapped on the numpad lands as a dot.\n //\n // One character for one character, and no digit grouping: the caret stays where\n // the typist put it, and \"1.000\" cannot be read back as a thousand in one locale\n // and as one in the other. de-CH and it-CH are \".\" — CLDR says so, and this\n // follows `Intl` rather than a guess about a country. The field's own `locale`,\n // else the provider's (0.34, DUP-10).\n const locale = useKitLocale(props.locale);\n // Decimals the figure settles to: `digits`, else the currency's minor unit.\n const digits = digitsProp ?? currencyMinorDigits(currency);\n const settle = (text: string) => settleAmount(text, digits, min, max);\n // The engine NumberInput shares (DUP-10): the lock (focusable, `readOnly`, nothing\n // changes or settles — see `disabledReason`), the hint — a FieldHint is its words at\n // Large and on touch, §4 — the error, the description's order, the typist's draft\n // in the locale's mark, the calculator and the numpad. On a phone the OS keyboard\n // is suppressed for the numpad sheet (feedback #334), and the display shape keys off\n // the SAME phone layout, so the two can never drift apart on the breakpoint.\n //\n // A value the HOST set (not one typed here) is shown at the currency's minor unit\n // while the field is not being edited: an FX estimate of 93.4213 showed four\n // decimals (keksdose live #356). Display only — `value` is the host's, untouched.\n const numeric = useNumericField(props, {\n settle,\n display: (focused) => (focused ? shown : settleAmount(shown, digits)),\n });\n const { lock, locked, off, isMobile, asDisplay, showCalc, showNumpad, setFocused, mark, draft, setDraft, derived } =\n numeric;\n const invalid = numeric.isInvalid;\n // A locked or disabled chip is a read-out: picking a currency is a change too.\n const editable = !!onCurrencyChange && !locked && !off;\n // Room for the trailing controls — the calculator and the currency chip — once\n // measured, as NumberInput reserves its own (keksdose live #367, DUP-10): their\n // width, the track's `end-1` inset in the boxed shape, and NumberInput's 4px gap.\n // Before that (the first paint, and wherever there is no layout) the classes below\n // stand in. showCalc is always false on a phone, so the display shape only has to\n // clear the chip, by its own width rather than the boxed shape's room (feedback #430\n // rework: on a 375px screen 16px decide between a readable figure and a clipped one).\n const hasEnd = showCalc || Boolean(currency);\n const [endRef, endWidth] = useEndWidth(hasEnd);\n const trailingRoom = asDisplay\n ? currency\n ? editable\n ? \"pe-16\"\n : \"pe-12\"\n : undefined\n : showCalc\n ? currency\n ? editable\n ? \"pe-24\"\n : \"pe-16\"\n : \"pe-10\"\n : currency\n ? editable\n ? \"pe-20\"\n : \"pe-14\"\n : undefined;\n const innerRef = useRef<HTMLInputElement>(null);\n const setRefs = useMemo(() => mergeRefs(innerRef, ref), [ref]);\n // While the typist is typing, the field shows THEIR text (\"1.234,5\" stays exactly\n // that), not the value re-spelt: re-spelling turned a grouping \".\" into a \",\" under\n // their fingers, after which no rule could tell the two apart (keksdose G1). The\n // draft only while it says what the field holds AND holds nothing the live\n // sanitising would drop — a letter, a second decimal point (see `showsTyped`); a\n // value set from outside, a calculator result or a commit shows the derived spelling.\n const display =\n draft === null\n ? derived\n : (numeric.typedFor(shown) ??\n // The caller owns the sign: the typed \"12\" is shown as the \"-12\" it is.\n (signOwned && negative && shown.startsWith(\"-\") && numeric.typedFor(shown.slice(1)) !== null\n ? `-${draft}`\n : derived));\n // Every route into the field — typing, the numpad sheet, the desktop\n // calculator, the blur/Enter commit — funnels through here, so the split is\n // written once and the four entry paths cannot drift.\n //\n // `previous` is the text this one REPLACES, and it is what says whether a bare\n // figure arriving here is an answer or a magnitude. For the three paths that\n // edit the field's own text that is simply what the field was showing; the\n // desktop calculator keeps its expression in a popover the field never sees,\n // so it passes it in (see `CalculatorButton`'s `onChange`).\n const handleText = (raw: string, previous: string = shown) => {\n const text = sanitizeLive(raw);\n if (!signOwned) {\n onChange(text);\n return;\n }\n const { sign, rest } = splitLeadingSign(text);\n if (sign) {\n // SET, not flip: re-reporting the same sign on every keystroke is a no-op.\n onNegativeChange(sign === \"-\");\n } else if (looksLikeExpression(previous) && isBareAmount(text) && isResultOf(previous, text, settle)) {\n // A calculation that just RESOLVED states its sign in both directions. The\n // figure it ran on is the SIGNED one the user could see — \"-12+30\" is +18 —\n // so a positive result has to move the chip too, or the field would answer\n // that sum with \"-18\" and contradict the arithmetic it just showed.\n //\n // Only when it really resolved, though: see {@link isResultOf}. A bare figure\n // arriving on top of an expression is far more often a replacement than an\n // answer, and reading it as an answer flips the direction of money.\n onNegativeChange(false);\n }\n onChange(sign ? rest : text);\n };\n const commit = () => {\n setDraft(null);\n const settled = settle(commitExpression(shown));\n handleText(settled);\n onCommit?.(settled);\n };\n const typed = (raw: string) => handleText(numeric.read(raw));\n // The currency list is CurrencySelect's (round 0.34 Wave 2, DUP-4) on the picker\n // family's core: the chip was a hand copy of it and had drifted (no wrap at Large, no\n // `options` subset, no check mark, no listbox id, no #308 width), and both were plain\n // buttons under a listbox promise. `filter: false`: the list filters its own rows.\n const core = useComboboxCore<string>({ filter: false, backCloses: true });\n // `chipRef`: the chip the currency list hangs off (Keksdose dev#548: portalled, so the\n // panel needs a real trigger rect rather than a relative parent). It is also where\n // Escape and a pick hand focus back (round 0.34 BUG-1): Safari does not focus a\n // clicked button, so \"whatever held focus\" is not the chip.\n const { open, setOpen, closeToTrigger, triggerRef: chipRef } = core;\n const listboxId = `${generatedId}-currencies`;\n // A lock arriving while the list is up closes it, as on CountrySelect — adjusted\n // while rendering, so no frame shows a list that can no longer be used.\n if (!editable && open) setOpen(false);\n\n // The currency chip's strings are the `currency` namespace — the same two\n // `CurrencySelect` resolves, under this component's older key names. The\n // calculator and the numpad resolve `calculator` themselves; `labels.calculator`\n // and `labels.pad` are handed straight through to them as overrides.\n // The two strings read out first, so the memo depends on them and not on the\n // caller's `labels` object (a new one every render) — what the React Compiler infers.\n const currencyLabel = labels?.currency;\n const currencySearchLabel = labels?.currencySearch;\n const currencyOverrides = useMemo(() => {\n const out: Partial<CurrencyLabels> = {};\n if (currencyLabel !== undefined) out.currency = currencyLabel;\n if (currencySearchLabel !== undefined) out.search = currencySearchLabel;\n return out;\n }, [currencyLabel, currencySearchLabel]);\n const currencyText = useKitLabels(\"currency\", DEFAULT_CURRENCY_LABELS, currencyOverrides);\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n\n const selected = getCurrency(currency);\n\n return (\n <div {...dataAttributes(props)} className={cn(\"w-full\", className)}>\n {/* Inner relative box holds the input + its absolutely-positioned\n trailing controls (calculator / currency), so those stay anchored to\n the INPUT even when the mobile math bar is rendered below (#334). It is\n the kit's FloatingField, which draws the label — floating, or sr-only in\n the display shape — and puts a FieldHint on the label's line, as it does\n for NumberInput. */}\n {/* Locked, the field sits in the reason's frame (LockedReason: the line, or the\n Tooltip), as NumberInput does; the root above keeps `className`, so nothing\n reflows. */}\n <LockedOrNot lock={lock} display={disabledReasonDisplay}>\n <FloatingField\n className=\"w-full\"\n htmlFor={fieldId}\n label={label}\n srOnlyLabel={asDisplay}\n hint={numeric.hint.labelHint}\n >\n <input\n ref={setRefs}\n id={fieldId}\n aria-label={ariaLabel}\n type=\"text\"\n // eslint-disable-next-line jsx-a11y/no-autofocus -- opt-in per call site (feedback #70)\n autoFocus={autoFocus}\n // On mobile suppress the OS keyboard so our numpad sheet owns entry; the\n // field keeps focus/caret. Desktop keeps the native decimal keypad.\n inputMode={isMobile ? \"none\" : \"decimal\"}\n autoComplete=\"off\"\n disabled={off}\n // Locked: focusable, `readOnly`, `aria-disabled` — see `disabledReason`.\n readOnly={locked || undefined}\n aria-disabled={locked || undefined}\n // The floating-label pattern needs a blank placeholder for its\n // peer-placeholder-shown trick. The display shape has no floating label,\n // so it spends the placeholder on what an empty borderless form actually\n // needs: a zero to aim at, at full size. The caller supplies it because\n // only the app knows the locale's decimal separator.\n placeholder={asDisplay ? (placeholder ?? \"0\") : label !== undefined ? \" \" : placeholder}\n value={display}\n onChange={(e) => {\n if (!locked) typed(e.target.value);\n }}\n onFocus={() => setFocused(true)}\n onBlur={() => {\n // Nothing settles under the lock — not even a draft typed before it arrived,\n // which stays in the field for when it lifts.\n if (!locked) commit();\n setFocused(false);\n }}\n onKeyDown={(e) => {\n if (e.key !== \"Enter\") return;\n // Locked: Enter submits no form and settles nothing.\n if (locked) e.preventDefault();\n else commit();\n }}\n className={cn(\n // With a label, use the floating-input padding (pt-4 pb-1) like every\n // other labelled field so the value sits BELOW the floated label rather\n // than vertically centred where it overlaps the resting label\n // (feedback #314). FLOATING_INPUT_CLASS already bundles the peer +\n // transparent-placeholder bits.\n asDisplay ? DISPLAY_INPUT_CLASS : label !== undefined ? FLOATING_INPUT_CLASS : FIELD_BASE,\n // The plain end padding, with nothing trailing: cosmetic, so the caller's\n // to change (keksdose 0.24 — a symmetric `px-2` in a budget cell).\n !trailingRoom && (asDisplay ? \"pe-0\" : \"pe-3\"),\n // Centred display shape: centre in what is LEFT of the currency chip.\n // `text-center` alone would centre the figure in the whole box, i.e.\n // partly underneath the chip; the padding below is what takes the chip\n // out of the centring, and nothing is added at the start because a\n // mirrored reservation would spend the width twice (see `align`).\n asDisplay && align === \"center\" && \"text-center\",\n // Over the base class's own text colour.\n TONE_CLASS[tone],\n // The caller's, over all of the above — base, plain padding, alignment and\n // tone — and under only what the field needs to work (see `inputClassName`).\n inputClassName,\n // Room for the trailing controls, after the caller's so a `px-2` cannot run\n // the digits under the chip (NumberInput's order, which reserves its unit\n // and calculator the same way).\n trailingRoom,\n invalid && FIELD_INVALID,\n locked && \"cursor-not-allowed\",\n )}\n // The classes above are the fallback; once measured the field reserves exactly\n // its trailing controls' width, inline so it wins over every class (see\n // `trailingRoom`).\n style={hasEnd && endWidth != null ? { paddingInlineEnd: endWidth + (asDisplay ? 4 : 8) } : undefined}\n aria-invalid={invalid || undefined}\n aria-describedby={numeric.describedBy}\n aria-required={ariaRequired}\n />\n {/* The label is FloatingField's, after these children (the floating trick\n reads the input through `peer-*`). The display shape drops it VISUALLY,\n not from the accessibility tree: a 36px tinted figure at the top of a\n transaction form is legibly the amount, but a screen reader still needs\n the name, and callers that pass `label` without `aria-label` would\n otherwise be left with none. */}\n {/* Trailing controls share one flex track so the calculator icon and the\n currency suffix/picker sit side by side without overlapping. */}\n {/* The display shape has no box to inset from, so the controls align to the\n figure's own end edge and its baseline strip (`bottom-1`, matching the\n input's pb-1) instead of floating inside a field. */}\n <div\n // Measured for the input's end padding (see `trailingRoom`).\n ref={endRef}\n className={cn(\n \"absolute flex items-center gap-0.5\",\n // Logical `end-*`: the chip and the calculator are the figure's trailing\n // controls, so a right-to-left form carries them on the left.\n asDisplay ? \"bottom-1 end-0\" : \"inset-y-1 end-1\",\n )}\n >\n {showCalc && (\n <CalculatorButton\n // The mark the field shows but not the typist's grouping: the evaluator\n // reads either mark, and \"1.234,5\" is two of them. The result comes back\n // dot-decimal.\n value={derived}\n onChange={(result, expression) => {\n setDraft(null);\n const settled = settle(result);\n handleText(settled, expression);\n onCommit?.(settled);\n }}\n className=\"px-1.5\"\n aria-label={labels?.calculatorTrigger}\n labels={labels?.calculator}\n />\n )}\n {currency && !editable && (\n <span\n aria-hidden\n className={cn(\n \"pointer-events-none px-1 font-medium text-muted\",\n // A text-xs chip next to a 36px figure reads as a stray footnote.\n asDisplay ? \"text-sm\" : \"text-xs\",\n )}\n >\n {currency}\n </span>\n )}\n {currency && editable && (\n <button\n ref={chipRef}\n type=\"button\"\n onClick={() => setOpen((v) => !v)}\n // A button that opens a listbox, and says so: the chip is a control inside\n // a text field, not a field of its own, so not a combobox.\n aria-haspopup=\"listbox\"\n aria-expanded={open}\n aria-controls={listboxId}\n aria-label={\n // \"Currency: EUR\" through `common.fieldValue`, not a template literal:\n // the colon-and-space is punctuation a translation has to own.\n selected ? common.fieldValue(currencyText.currency, selected.code) : currencyText.currency\n }\n className={cn(\n \"flex items-center gap-1 rounded px-2 py-1 font-medium text-secondary hover:bg-hover\",\n asDisplay ? \"text-sm\" : \"text-xs\",\n )}\n >\n {currency}\n <ChevronDown className=\"size-3\" />\n </button>\n )}\n </div>\n {editable && (\n <CurrencyOptionList\n core={core}\n listboxId={listboxId}\n value={currency}\n codes={currencyOptions}\n currencyNames={currencyNames}\n locale={locale}\n searchPlaceholder={currencyText.search}\n // The phone sheet's title: what the chip is for.\n sheetTitle={currencyText.currency}\n onChoose={(code) => {\n onCurrencyChange?.(code);\n closeToTrigger();\n }}\n />\n )}\n </FloatingField>\n </LockedOrNot>\n {/* Outside the relative box, as NumberInput's caption is: the trailing\n controls are `inset-y-1` in it and would stretch down over a second line. */}\n <FieldCaption parts={numeric.hint} />\n {/* The news after the standing advice, as Select orders them. The root is\n already a steady box, so the message coming and going remounts nothing. */}\n {numeric.errorEl}\n {showNumpad && (\n <NumberPadSheet\n // Localised like the field it mirrors. Keys are typing, read by the\n // locale's marks like the keyboard's; \"=\" is a result, dot-decimal.\n value={display}\n onChange={typed}\n onResult={(result) => {\n setDraft(null);\n const settled = settle(result);\n handleText(settled);\n onCommit?.(settled);\n }}\n onDone={() => innerRef.current?.blur()}\n label={label}\n labels={labels?.pad}\n decimalMark={mark}\n />\n )}\n </div>\n );\n}\n\n/** The field in its lock's {@link LockedReason} while locked, as it is otherwise. A\n * component rather than a ternary so the field's JSX is written once. `block w-full`:\n * the frame's box stands where the field's own did. */\nfunction LockedOrNot({\n lock,\n display,\n children,\n}: {\n lock: LockReason;\n display: DisabledReasonDisplay | undefined;\n children: ReactNode;\n}) {\n if (!lock.locked) return <>{children}</>;\n return (\n <LockedReason lock={lock} display={display} className=\"block w-full\">\n {children}\n </LockedReason>\n );\n}\n"],"mappings":";AAskBU,SAgNiB,UAhNjB,KA6HI,YA7HJ;AAtkBV,SAAS,OAAO,SAAS,cAAc;AACvC,SAAS,mBAAmB;AAE5B,SAAS,oBAAoB,mBAAmB;AAChD,SAAS,uBAAuB;AAChC,SAAS,YAAY,eAAe,eAAe,sBAAsB,qBAAqB;AAC9F,SAAS,UAAU;AACnB,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,wBAAqD;AAC9D,SAAS,sBAAiD;AAC1D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,aAAa,uBAAuB;AAE7C,SAAS,sBAA2C;AAyRpD,SAAS,aAAa,MAAc,QAA4B,KAAc,KAAsB;AAClG,QAAM,IAAI,KAAK,KAAK;AACpB,MAAI,CAAC,gBAAgB,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,EAAG,QAAO;AACtD,MAAI,IAAI,OAAO,CAAC;AAChB,MAAI,CAAC,OAAO,SAAS,CAAC,EAAG,QAAO;AAChC,MAAI,WAAW,OAAW,KAAI,cAAc,GAAG,MAAM;AACrD,MAAI,QAAQ,UAAa,IAAI,IAAK,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AAA,EACA;AAAA,EACA;AACF,GAIG;AACD,MAAI,CAAC,KAAK,OAAQ,QAAO,gCAAG,UAAS;AACrC,SACE,oBAAC,gBAAa,MAAY,SAAkB,WAAU,gBACnD,UACH;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/amount-input.tsx"],"sourcesContent":["import { useId, useMemo, useRef } from \"react\";\nimport { ChevronDown } from \"lucide-react\";\nimport type { ReactNode, Ref } from \"react\";\nimport { CurrencyOptionList, getCurrency } from \"./currency-option-list\";\nimport { useComboboxCore } from \"./combobox-core\";\nimport { FIELD_BASE, FIELD_DISPLAY, FIELD_INVALID, FLOATING_INPUT_CLASS, FloatingField } from \"./field-base\";\nimport { cn } from \"../lib/cn\";\nimport { currencyMinorDigits } from \"../lib/format\";\nimport { roundHalfAway } from \"../lib/round\";\nimport { CalculatorButton, type CalculatorButtonLabels } from \"./calculator\";\nimport { NumberPadSheet, type NumberPadSheetLabels } from \"./numpad-sheet\";\nimport {\n DEFAULT_COMMON_LABELS,\n DEFAULT_CURRENCY_LABELS,\n useKitLabels,\n useKitLocale,\n type CurrencyLabels,\n} from \"../i18n/kit-labels\";\nimport {\n commitExpression,\n evaluateExpression,\n formatResult,\n isBareAmount,\n looksLikeExpression,\n sanitizeLive,\n splitLeadingSign,\n} from \"../lib/calc\";\nimport {\n FieldCaption,\n LockedReason,\n mergeRefs,\n type DisabledReasonDisplay,\n type FieldHelpProps,\n type LockReason,\n} from \"./field-parts\";\nimport { useEndWidth, useNumericField } from \"./numeric-field\";\nimport type { CommitScope } from \"./write-lock\";\nimport { dataAttributes, type DataAttributes } from \"../lib/data-attributes\";\n\n/** {@link AmountInput}'s props — exported since 0.34 (refactor audit 2026-10, API-9): a\n * wrapper typed itself off `ComponentProps<typeof AmountInput>` until then. */\nexport interface AmountInputProps extends FieldHelpProps, DataAttributes {\n value: string;\n onChange: (value: string) => void;\n currency?: string;\n onCurrencyChange?: (code: string) => void;\n placeholder?: string;\n label?: ReactNode;\n disabled?: boolean;\n /** Required and unanswered — {@link FIELD_INVALID}. See {@link Input}'s `invalid`. */\n invalid?: boolean;\n /**\n * What is wrong with the amount, in the caller's own words — {@link Input}'s `error`\n * (keksdose K4: \"exceeds the outstanding balance\" was a loose `<p>` beside the field\n * that nothing pointed at). Rendered under the field, after a text `hint`; merged into\n * `aria-describedby` after the caller's ids and the hint's; implies `invalid`, so the\n * field paints as well as announces. `null`, `false` and `\"\"` are no message.\n * {@link MoneyField} takes it too.\n */\n error?: ReactNode;\n /**\n * Show the desktop calculator trigger (default `true`). `false` for an amount in an\n * ephemeral close-on-blur editor — a budget's assigned cell, a VAT cell (keksdose K6)\n * — where a click on the icon blurs the field and tears the editor down before the\n * popover can open. Typing a calculation (\"200+50\", then Enter) still evaluates, and\n * a phone keeps its numpad, exactly as {@link NumberInput}'s `calculator={false}`.\n */\n calculator?: boolean;\n /** The field's WRAPPER — width, a margin, a flex share. The `<input>` is\n * `inputClassName`'s. */\n className?: string;\n /**\n * Classes for the `<input>` itself — {@link NumberInput}'s and {@link Input}'s prop of\n * the same name, merged the same way: after everything the field sets for LOOKS — the\n * base classes, the plain end padding, the display shape's centring and the `tone`\n * colour — so it can restyle the figure (`text-end` for a money column whose decimal\n * points line up, `font-medium`, a tighter `py-1` or a symmetric `px-2` in a table\n * cell, `text-transparent` while a figure is being re-fetched), and before what the\n * field needs to WORK: the end padding the calculator and the currency chip reserve,\n * and the invalid border. Neither of those can be taken away by accident — a caller's\n * `px-2` keeps its start edge and the digits still stop short of the chip, and a\n * borderless cell's `border-transparent` still turns red when the value is wrong.\n *\n * keksdose G7: the invoice's VAT cell right-aligns its figure, and with only\n * `className` (the wrapper) it reached the element through `[&_input]:text-end` — a\n * descendant selector that depends on the field's inner markup, which the kit is free\n * to change, and that a reader of the call site has to decode. {@link MoneyField}\n * passes it through, and `RhfMoneyField` takes it too.\n *\n * keksdose 0.24: until then it sat BEFORE the plain end padding (`pe-3`) and the tone,\n * so the budget's assigned cell could not make its padding symmetric (`px-2` came out\n * `px-2 pe-3`) and the holdings price could not hide an outflow-toned figure while\n * re-fetching — both were back on `[&_input]:` selectors on the wrapper.\n */\n inputClassName?: string;\n id?: string;\n /** Names the field when it has no visible `label` (a table cell, the display shape). */\n \"aria-label\"?: string;\n /**\n * Set on the `<input>`, with `id` above. Declared so `Field`'s render-prop spread —\n * `{(ids) => <AmountInput {...ids} … />}` — is typed and reaches the input: the\n * hint and error are described, a required amount is announced as required, and\n * `aria-invalid` paints {@link FIELD_INVALID} the way `invalid` does.\n */\n \"aria-describedby\"?: string;\n \"aria-invalid\"?: boolean | \"true\" | \"false\";\n \"aria-required\"?: boolean | \"true\" | \"false\";\n /**\n * BCP 47 tag for this field — {@link NumberInput}'s `locale` (0.34, DUP-10): the decimal\n * mark the field SHOWS and reads typing in (\"1,5\" for fr-CH, \"1.5\" for de-CH, as `Intl`\n * decides), and the language of the currency picker's search. Default the\n * `<UiKitProvider locale>`, else the runtime's. `value` and `onChange` stay\n * dot-decimal.\n */\n locale?: string;\n /** {@link NumberInput}'s `hint`, the same rule: a {@link FieldHint} \"?\" rides the\n * label's own line, beside the label (not at the far end, where the calculator and\n * the currency chip live); plain TEXT (a string or a number) is a caption UNDER\n * the field, attached through `aria-describedby` after the caller's own. A phone's\n * `variant=\"display\"` has no visible label, so a FieldHint is dropped there; a\n * caption still shows.\n *\n * Since 0.34 a FieldHint is that caption at Large and on a touch screen, as on\n * NumberInput since 0.32 (`useInlineHint`, docs/text-size-harmonization.md §4: a fact\n * a finger cannot hover open is printed). A `HelpPopover` — help, not a fact (§10.23)\n * — stays on the label line at every size. */\n hint?: ReactNode;\n /** Every user-facing string this component and the two it composes own, so a\n * translating host can supply its own. Each key optional, and each a per-field\n * override of the kit-wide translation in `<UiKitProvider labels>`: `currency`\n * and `currencySearch` of its `currency` namespace, the rest of `calculator`.\n * `currency` names the picker chip, composed with the selected code through\n * `common.fieldValue`; the rest are pass-through. */\n labels?: {\n currency?: string;\n currencySearch?: string;\n /** Names the calculator TRIGGER this component renders. `calculator` below\n * names the controls inside the popover it opens. */\n calculatorTrigger?: string;\n pad?: NumberPadSheetLabels;\n calculator?: CalculatorButtonLabels;\n };\n /** Translated currency names for the chip's picker, keyed by ISO code. The same\n * sparse override `CurrencySelect` takes, and for the same reason: the names in\n * `CURRENCIES` are shipped data, so without this they are the one English word\n * left in a translated row. Not part of `labels` because it is keyed by DATA\n * rather than by a fixed set of slots, and an app passes the same map to both\n * pickers. */\n currencyNames?: Record<string, string>;\n /** Offer only these ISO codes in the chip's list, in this order — `CurrencySelect`'s\n * `options`, since the chip renders CurrencySelect's list (round 0.34 Wave 2, DUP-4).\n * Default every currency the kit knows. */\n currencyOptions?: string[];\n /** Focus the field on mount — on mobile this also opens the numpad sheet, so a\n * new-transaction form can jump straight to amount entry (feedback #70). */\n autoFocus?: boolean;\n /**\n * Tint the typed figure by what it will DO (Keksdose feedback #167).\n *\n * The direction is chosen with a toggle beside the field rather than typed, so\n * the digits alone say nothing about which way the money goes — on the one screen\n * where getting that backwards is the expensive mistake. Colour says it\n * continuously, and it costs no layout. It stays the MAIN indication (live #201\n * rework: *\"The main indication shall still be the color\"*); {@link negative}\n * renders the sign as a second, quieter signal in front of the figure.\n *\n * Never the ONLY signal: the toggle it mirrors is right there, labelled, so this\n * is reinforcement rather than the sole carrier of the meaning.\n */\n tone?: \"neutral\" | \"outflow\" | \"inflow\";\n /**\n * The SIGN of the figure, owned by the caller's direction control (Keksdose live\n * #201 rework: *\"Outflow should be negative and inflow positive … the sign shall\n * be displayed but not necessarily be typed in\"*).\n *\n * `value` stays the MAGNITUDE. The minus is glued on at render time and stripped\n * off again before anything is reported back, so the caller never sees its own\n * prefix echoed and no code path can end up applying it twice. That is the whole\n * cure: there is exactly ONE place the sign lives, and it is not the text.\n *\n * Because it is rendered rather than stored it cannot be deleted (the next render\n * puts it back), a select-all-and-retype keeps the direction, and the caret needs\n * no minding.\n *\n * Since 0.15.5 it is drawn on its own too, for a read-only or disabled signed figure\n * (an \"Items total\" of −5.18): no `onNegativeChange` needed just to show the minus.\n */\n negative?: boolean;\n /**\n * A sign the user TYPED, or a calculation that resolved to a signed number.\n *\n * SET, never flip. A \"-\" means *\"this is an outflow\"*, so typing it twice says the\n * same thing twice — which is exactly what the rework asks for (*\"Subtracting\n * values twice resulting in inflow -> outflow and back to inflow seems not\n * reasonable\"*). \"+\" says the other direction.\n *\n * Its presence is what ARMS the whole sign behaviour. A field with no direction\n * control — an account's starting balance, a loan payment, a holding's cost —\n * passes neither prop and keeps a text that is the whole truth, minus included.\n */\n onNegativeChange?: (negative: boolean) => void;\n /**\n * How the field presents itself ON A PHONE (Keksdose feedback #176).\n *\n * `\"field\"` (default) is the labelled, bordered input used everywhere else.\n *\n * `\"display\"` keeps every mechanic — the same `<input>`, the same numpad sheet,\n * the same currency picker, the same commit/blur contract — and only drops the\n * chrome: no border, no fill, no floating label, the figure set at display size.\n * On a form whose whole point is one number, a bordered `text-sm` box draws the\n * amount at the same weight as the memo beside it; this makes it the headline\n * instead. It stays fully editable — the underline and the caret are what say so.\n *\n * Phone-only by construction: it keys off the same breakpoint as the numpad, so\n * from `md` up the field is byte-for-byte the normal one and a desktop grid keeps\n * its column rhythm.\n */\n variant?: \"field\" | \"display\";\n /**\n * Where the figure sits in its row, for `variant=\"display\"` only (Keksdose\n * feedback #176 rework).\n *\n * `\"start\"` (default) keeps it flush left, in the reading column the fields\n * below it share — and it is what the entry forms use, because a figure that\n * starts at a known edge is legible at any width: when the value outgrows the\n * field, the digits that scroll out of sight are the trailing ones, not the\n * magnitude (Keksdose feedback #430 rework).\n *\n * `\"center\"` makes it a centred headline. It centres in the width that REMAINS\n * after the trailing currency control, not in the whole box: the control is\n * pinned to the right edge, so a plain `text-center` would centre the figure\n * under it and the last digits would sit behind the chip. This used to mirror\n * the control's reservation onto the left instead, which centred correctly but\n * spent twice the control's width on padding — fatal on a 375px screen, where\n * it left a 36px figure 16px to live in.\n */\n align?: \"start\" | \"center\";\n /**\n * Decimals the committed amount is rounded to (kastlan 0.12: \"12.345\" and a\n * calculator's \"100/3\" reached a `Numeric(10,2)` column unrounded and failed with a\n * 422). Default: the currency's minor unit, from `Intl` (CHF and EUR 2, JPY 0). With\n * no `currency`, nothing is rounded unless this is set. Rounding is half away from\n * zero (12.345 → 12.35, -12.345 → -12.35) and happens when the figure settles: on\n * blur, on Enter, and on every result the calculator writes back. Keystrokes are left\n * alone, so \"12.3\" can still become \"12.34\".\n *\n * ⚠️ **A unit price or a rate needs `digits`.** The default is right for an amount of\n * money and silently wrong for a price per unit: a fund's NAV of 123.4567 or fuel at\n * 1.789 €/l is stored as 123.46 / 1.79, and no test fails (keksdose G2, a\n * `Numeric(18,6)` holding price and a `Numeric(18,4)` unit price). Pass the column's\n * scale: `digits={4}`, `digits={6}`.\n *\n * **Set `digits` for any sub-currency scale** — not only a price: any field whose\n * column holds more decimals than the currency's minor unit. A split line stored at\n * the ledger's 4dp (`Numeric(18,4)`) and loaded as 12.3456 is SHOWN as 12.35, and\n * committed as 12.35 as soon as the user tabs through it (blur settles) — so the form\n * no longer equals what the server holds: the lines stop summing to the 4dp total,\n * and Save is held (keksdose live #240). With a `currency`, every commit rounds to that currency's\n * minor unit unless `digits` says otherwise: pass the column's scale (`digits={4}`).\n */\n digits?: number;\n /** The smallest amount the field settles on. A lower figure is raised to it when it\n * settles, like `digits`. Compared with the signed figure. */\n min?: number;\n /** The largest amount the field settles on (a deposit release capped at the\n * balance). A higher figure is lowered to it when it settles. */\n max?: number;\n /**\n * The SETTLED figure, dot-decimal, sign included — fired on blur, on Enter, on the\n * numpad's \"=\" and once per calculator session (its \"=\" or Enter in its display, or\n * the pad closing on a result not committed yet), never on a keystroke (\"1200+\" is\n * not a figure yet). `onChange` still reports every keystroke and every result the\n * calculator writes back; this is for a host that stores a number and must not see\n * drafts (kastlan 52; see {@link MoneyField}, which is built on it).\n *\n * Refactor audit 2026-10-30, INP-1: every calculator keystroke that resolved used to\n * commit, so \"100+50\" committed 105 on its way to 150 — keksdose saved both, and its\n * threshold field, `disabled` while it saves, lost the calculator to the first.\n */\n onCommit?: (value: string) => void;\n /**\n * Why the amount cannot be changed — {@link NumberInput}'s `disabledReason` (0.34,\n * round 0.34 C2), for an amount that SAVES itself: a budget row's assigned cell, a\n * price committed on blur. `disabled` takes the field out of the tab order, so the\n * reason never reached a keyboard.\n *\n * With a reason the field stays in the tab order and shows its figure, `readOnly` (the\n * settled grey FIELD_BASE gives a `[readonly]` field) and `aria-disabled`. Nothing\n * changes the amount: the calculator and the phone's numpad are not offered, the\n * currency chip is a read-out rather than a picker, and neither blur nor Enter\n * settles — so `onChange`, `onCommit`, `onNegativeChange` and `onCurrencyChange` are\n * never called. Enter is swallowed, so the field does not submit the form around it.\n * The reason is a line under the field at Large and on a touch screen, else in the kit\n * {@link Tooltip} (`disabledReasonDisplay`), and on the input's `aria-describedby`,\n * between the caption and the error. Wins over `disabled`. {@link MoneyField} and\n * `RhfMoneyField` take it too.\n */\n disabledReason?: ReactNode;\n /**\n * Where the reason shows — {@link Button}'s `disabledReasonDisplay`: by default a line\n * under the field at Large and on a touch screen, the tooltip otherwise (§4 \"No fact\n * only in a tooltip\"; DUP-3, refactor audit 2026-10).\n */\n disabledReasonDisplay?: DisabledReasonDisplay;\n /**\n * This amount COMMITS — {@link Button}'s `commit`, NumberInput's: under a locked\n * {@link WriteLockProvider} it is locked the `disabledReason` way with the lock's reason\n * (which wins over its own). An amount that only reaches the server through its form's\n * Save leaves this off and stays editable under the lock; the Save takes `commit`. No\n * provider, or an unlocked one: no effect.\n */\n commit?: CommitScope;\n /** The `<input>`. A React 19 ref prop since 0.34 (MOD-4, refactor audit 2026-10); it\n * was `forwardRef`. */\n ref?: Ref<HTMLInputElement>;\n}\n\n/**\n * A settled figure, rounded to `digits` (half away from zero) and clamped to\n * `min`/`max`. Only a plain number is touched. A half-typed draft or an expression\n * comes back as it was. Rounding is `lib/round.ts`'s, shared with `roundToCurrency`\n * (BUG-11: this copy blanked \"0.0000001\" and a 22-digit figure on blur).\n */\nfunction settleAmount(text: string, digits: number | undefined, min?: number, max?: number): string {\n const t = text.trim();\n if (!/^-?\\d*\\.?\\d*$/.test(t) || !/\\d/.test(t)) return text;\n let n = Number(t);\n if (!Number.isFinite(n)) return text;\n if (digits !== undefined) n = roundHalfAway(n, digits);\n if (min !== undefined && n < min) n = min;\n if (max !== undefined && n > max) n = max;\n const out = formatResult(n);\n // Unchanged figures keep their own spelling (\"12.50\" stays \"12.50\").\n return Number(out) === Number(t) ? text : out;\n}\n\n// The locale's decimal mark and the grouping parse (kastlan 40, keksdose G1) live in\n// `lib/decimal-marks.ts`, read through the engine NumberInput and this field share\n// (`numeric-field.ts`, DUP-10).\n\n// The consuming app's ONE money palette (`--money-expense` / `--money-income`),\n// not a bespoke rose/emerald pairing: a figure being typed has to wear the same\n// colour the same figure will wear once it is a row in the table behind the form\n// (Keksdose dev#434). The utilities are unlayered and theme-aware, so no `dark:`\n// variant is needed and they win over the field's own text colour regardless of\n// where `cn` puts them.\nconst TONE_CLASS: Record<\"neutral\" | \"outflow\" | \"inflow\", string> = {\n neutral: \"\",\n outflow: \"text-money-neg\",\n inflow: \"text-money-pos\",\n};\n\n// The shared chrome-less treatment at money size. `tabular-nums` so digits don't\n// reflow the figure as they are typed; FIELD_DISPLAY's own muted placeholder\n// colour is what keeps an EMPTY form from painting its zero in the direction tint\n// (`tone` is computed from 0, which reads as an inflow).\nconst DISPLAY_INPUT_CLASS = cn(FIELD_DISPLAY, \"text-4xl font-semibold leading-tight tracking-tight tabular-nums\");\n\n/**\n * Is `text` the ANSWER to `previous`, or something typed OVER it?\n *\n * \"The old text was a sum and the new one is bare\" cannot tell those apart, and both\n * gestures are ordinary: select-all-and-retype after a typo, or backspacing \"-20+\"\n * back down to a fresh figure. Read as an answer, they move the direction chip — so\n * an outflow of 7 quietly booked +7.00 (live #201 rework).\n *\n * The question that does separate them is arithmetic, not shape: evaluate what the\n * text replaced and see whether this IS that number. \"-12+30\" → \"18\" still is, so a\n * sum that comes out positive still takes the chip with it; \"-20+50\" → \"7\" is not,\n * and \"-20+\" evaluates to nothing at all.\n */\nfunction isResultOf(previous: string, text: string, settle: (text: string) => string): boolean {\n const n = evaluateExpression(previous);\n // Compared settled, since the field rounds what the calculator hands it.\n return n !== null && settle(formatResult(n)) === text.trim();\n}\n\nexport function AmountInput(props: AmountInputProps) {\n const {\n ref,\n value,\n onChange,\n currency,\n onCurrencyChange,\n placeholder,\n label,\n className,\n inputClassName,\n id,\n \"aria-label\": ariaLabel,\n \"aria-required\": ariaRequired,\n autoFocus,\n tone = \"neutral\",\n negative = false,\n onNegativeChange,\n align = \"start\",\n labels,\n currencyNames,\n currencyOptions,\n digits: digitsProp,\n min,\n max,\n onCommit,\n disabledReasonDisplay,\n } = props;\n const generatedId = useId();\n const fieldId = id ?? generatedId;\n // The sign is DISPLAYED, not stored (live #201 rework). `value` is the\n // magnitude; the minus is glued on here and taken off again in handleText, so\n // the two can never disagree and the caller can never double-apply it. Only in\n // front of a bare amount: an expression being typed (\"12-30\") owns its own\n // minus and has to survive keystroke-for-keystroke.\n const signOwned = onNegativeChange !== undefined;\n // The sign is DRAWN whenever `negative` says so, handler or not (keksdose live #366):\n // a read-only or disabled total (\"−5.18\") used to need a dummy `onNegativeChange`\n // just to show its minus. Without the handler there is nothing to toggle — a typed\n // minus simply stays in the text, as in any field without a direction control.\n const shown = negative && isBareAmount(value) ? `-${value}` : value;\n // What the user SEES is `shown` with the locale's decimal mark (kastlan 40: a\n // fr-CH user typed \"1,5\" and watched it turn into \"1.5\" under their fingers). Display only — `value`, `onChange`, the sign split and the settle all\n // stay dot-decimal, because that string is the contract: RhfMoneyField's\n // `parseAmount`, every app's `Number(value)` and the calculator's evaluator read\n // it. The way back is free: {@link sanitizeLive} already folds a typed \",\" into\n // \".\", so a comma typed, pasted or tapped on the numpad lands as a dot.\n //\n // One character for one character, and no digit grouping: the caret stays where\n // the typist put it, and \"1.000\" cannot be read back as a thousand in one locale\n // and as one in the other. de-CH and it-CH are \".\" — CLDR says so, and this\n // follows `Intl` rather than a guess about a country. The field's own `locale`,\n // else the provider's (0.34, DUP-10).\n const locale = useKitLocale(props.locale);\n // Decimals the figure settles to: `digits`, else the currency's minor unit.\n const digits = digitsProp ?? currencyMinorDigits(currency);\n const settle = (text: string) => settleAmount(text, digits, min, max);\n // The engine NumberInput shares (DUP-10): the lock (focusable, `readOnly`, nothing\n // changes or settles — see `disabledReason`), the hint — a FieldHint is its words at\n // Large and on touch, §4 — the error, the description's order, the typist's draft\n // in the locale's mark, the calculator and the numpad. On a phone the OS keyboard\n // is suppressed for the numpad sheet (feedback #334), and the display shape keys off\n // the SAME phone layout, so the two can never drift apart on the breakpoint.\n //\n // A value the HOST set (not one typed here) is shown at the currency's minor unit\n // while the field is not being edited: an FX estimate of 93.4213 showed four\n // decimals (keksdose live #356). Display only — `value` is the host's, untouched.\n const numeric = useNumericField(props, {\n settle,\n display: (focused) => (focused ? shown : settleAmount(shown, digits)),\n });\n const { lock, locked, off, isMobile, asDisplay, showCalc, showNumpad, setFocused, mark, draft, setDraft, derived } =\n numeric;\n const invalid = numeric.isInvalid;\n // A locked or disabled chip is a read-out: picking a currency is a change too.\n const editable = !!onCurrencyChange && !locked && !off;\n // Room for the trailing controls — the calculator and the currency chip — once\n // measured, as NumberInput reserves its own (keksdose live #367, DUP-10): their\n // width, the track's `end-1` inset in the boxed shape, and NumberInput's 4px gap.\n // Before that (the first paint, and wherever there is no layout) the classes below\n // stand in. showCalc is always false on a phone, so the display shape only has to\n // clear the chip, by its own width rather than the boxed shape's room (feedback #430\n // rework: on a 375px screen 16px decide between a readable figure and a clipped one).\n const hasEnd = showCalc || Boolean(currency);\n const [endRef, endWidth] = useEndWidth(hasEnd);\n const trailingRoom = asDisplay\n ? currency\n ? editable\n ? \"pe-16\"\n : \"pe-12\"\n : undefined\n : showCalc\n ? currency\n ? editable\n ? \"pe-24\"\n : \"pe-16\"\n : \"pe-10\"\n : currency\n ? editable\n ? \"pe-20\"\n : \"pe-14\"\n : undefined;\n const innerRef = useRef<HTMLInputElement>(null);\n const setRefs = useMemo(() => mergeRefs(innerRef, ref), [ref]);\n // While the typist is typing, the field shows THEIR text (\"1.234,5\" stays exactly\n // that), not the value re-spelt: re-spelling turned a grouping \".\" into a \",\" under\n // their fingers, after which no rule could tell the two apart (keksdose G1). The\n // draft only while it says what the field holds AND holds nothing the live\n // sanitising would drop — a letter, a second decimal point (see `showsTyped`); a\n // value set from outside, a calculator result or a commit shows the derived spelling.\n const display =\n draft === null\n ? derived\n : (numeric.typedFor(shown) ??\n // The caller owns the sign: the typed \"12\" is shown as the \"-12\" it is.\n (signOwned && negative && shown.startsWith(\"-\") && numeric.typedFor(shown.slice(1)) !== null\n ? `-${draft}`\n : derived));\n // Every route into the field — typing, the numpad sheet, the desktop\n // calculator, the blur/Enter commit — funnels through here, so the split is\n // written once and the four entry paths cannot drift.\n //\n // `previous` is the text this one REPLACES, and it is what says whether a bare\n // figure arriving here is an answer or a magnitude. For the three paths that\n // edit the field's own text that is simply what the field was showing; the\n // desktop calculator keeps its expression in a popover the field never sees,\n // so it passes it in (see `CalculatorButton`'s `onChange`).\n const handleText = (raw: string, previous: string = shown) => {\n const text = sanitizeLive(raw);\n if (!signOwned) {\n onChange(text);\n return;\n }\n const { sign, rest } = splitLeadingSign(text);\n if (sign) {\n // SET, not flip: re-reporting the same sign on every keystroke is a no-op.\n onNegativeChange(sign === \"-\");\n } else if (looksLikeExpression(previous) && isBareAmount(text) && isResultOf(previous, text, settle)) {\n // A calculation that just RESOLVED states its sign in both directions. The\n // figure it ran on is the SIGNED one the user could see — \"-12+30\" is +18 —\n // so a positive result has to move the chip too, or the field would answer\n // that sum with \"-18\" and contradict the arithmetic it just showed.\n //\n // Only when it really resolved, though: see {@link isResultOf}. A bare figure\n // arriving on top of an expression is far more often a replacement than an\n // answer, and reading it as an answer flips the direction of money.\n onNegativeChange(false);\n }\n onChange(sign ? rest : text);\n };\n const commit = () => {\n setDraft(null);\n const settled = settle(commitExpression(shown));\n handleText(settled);\n onCommit?.(settled);\n };\n const typed = (raw: string) => handleText(numeric.read(raw));\n // The currency list is CurrencySelect's (round 0.34 Wave 2, DUP-4) on the picker\n // family's core: the chip was a hand copy of it and had drifted (no wrap at Large, no\n // `options` subset, no check mark, no listbox id, no #308 width), and both were plain\n // buttons under a listbox promise. `filter: false`: the list filters its own rows.\n const core = useComboboxCore<string>({ filter: false, backCloses: true });\n // `chipRef`: the chip the currency list hangs off (Keksdose dev#548: portalled, so the\n // panel needs a real trigger rect rather than a relative parent). It is also where\n // Escape and a pick hand focus back (round 0.34 BUG-1): Safari does not focus a\n // clicked button, so \"whatever held focus\" is not the chip.\n const { open, setOpen, closeToTrigger, triggerRef: chipRef } = core;\n const listboxId = `${generatedId}-currencies`;\n // A lock arriving while the list is up closes it, as on CountrySelect — adjusted\n // while rendering, so no frame shows a list that can no longer be used.\n if (!editable && open) setOpen(false);\n\n // The currency chip's strings are the `currency` namespace — the same two\n // `CurrencySelect` resolves, under this component's older key names. The\n // calculator and the numpad resolve `calculator` themselves; `labels.calculator`\n // and `labels.pad` are handed straight through to them as overrides.\n // The two strings read out first, so the memo depends on them and not on the\n // caller's `labels` object (a new one every render) — what the React Compiler infers.\n const currencyLabel = labels?.currency;\n const currencySearchLabel = labels?.currencySearch;\n const currencyOverrides = useMemo(() => {\n const out: Partial<CurrencyLabels> = {};\n if (currencyLabel !== undefined) out.currency = currencyLabel;\n if (currencySearchLabel !== undefined) out.search = currencySearchLabel;\n return out;\n }, [currencyLabel, currencySearchLabel]);\n const currencyText = useKitLabels(\"currency\", DEFAULT_CURRENCY_LABELS, currencyOverrides);\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n\n const selected = getCurrency(currency);\n\n return (\n <div {...dataAttributes(props)} className={cn(\"w-full\", className)}>\n {/* Inner relative box holds the input + its absolutely-positioned\n trailing controls (calculator / currency), so those stay anchored to\n the INPUT even when the mobile math bar is rendered below (#334). It is\n the kit's FloatingField, which draws the label — floating, or sr-only in\n the display shape — and puts a FieldHint on the label's line, as it does\n for NumberInput. */}\n {/* Locked, the field sits in the reason's frame (LockedReason: the line, or the\n Tooltip), as NumberInput does; the root above keeps `className`, so nothing\n reflows. */}\n <LockedOrNot lock={lock} display={disabledReasonDisplay}>\n <FloatingField\n className=\"w-full\"\n htmlFor={fieldId}\n label={label}\n srOnlyLabel={asDisplay}\n hint={numeric.hint.labelHint}\n >\n <input\n ref={setRefs}\n id={fieldId}\n aria-label={ariaLabel}\n type=\"text\"\n // eslint-disable-next-line jsx-a11y/no-autofocus -- opt-in per call site (feedback #70)\n autoFocus={autoFocus}\n // On mobile suppress the OS keyboard so our numpad sheet owns entry; the\n // field keeps focus/caret. Desktop keeps the native decimal keypad.\n inputMode={isMobile ? \"none\" : \"decimal\"}\n autoComplete=\"off\"\n disabled={off}\n // Locked: focusable, `readOnly`, `aria-disabled` — see `disabledReason`.\n readOnly={locked || undefined}\n aria-disabled={locked || undefined}\n // The floating-label pattern needs a blank placeholder for its\n // peer-placeholder-shown trick. The display shape has no floating label,\n // so it spends the placeholder on what an empty borderless form actually\n // needs: a zero to aim at, at full size. The caller supplies it because\n // only the app knows the locale's decimal separator.\n placeholder={asDisplay ? (placeholder ?? \"0\") : label !== undefined ? \" \" : placeholder}\n value={display}\n onChange={(e) => {\n if (!locked) typed(e.target.value);\n }}\n onFocus={() => setFocused(true)}\n onBlur={() => {\n // Nothing settles under the lock — not even a draft typed before it arrived,\n // which stays in the field for when it lifts.\n if (!locked) commit();\n setFocused(false);\n }}\n onKeyDown={(e) => {\n if (e.key !== \"Enter\") return;\n // Locked: Enter submits no form and settles nothing.\n if (locked) e.preventDefault();\n else commit();\n }}\n className={cn(\n // With a label, use the floating-input padding (pt-4 pb-1) like every\n // other labelled field so the value sits BELOW the floated label rather\n // than vertically centred where it overlaps the resting label\n // (feedback #314). FLOATING_INPUT_CLASS already bundles the peer +\n // transparent-placeholder bits.\n asDisplay ? DISPLAY_INPUT_CLASS : label !== undefined ? FLOATING_INPUT_CLASS : FIELD_BASE,\n // The plain end padding, with nothing trailing: cosmetic, so the caller's\n // to change (keksdose 0.24 — a symmetric `px-2` in a budget cell).\n !trailingRoom && (asDisplay ? \"pe-0\" : \"pe-3\"),\n // Centred display shape: centre in what is LEFT of the currency chip.\n // `text-center` alone would centre the figure in the whole box, i.e.\n // partly underneath the chip; the padding below is what takes the chip\n // out of the centring, and nothing is added at the start because a\n // mirrored reservation would spend the width twice (see `align`).\n asDisplay && align === \"center\" && \"text-center\",\n // Over the base class's own text colour.\n TONE_CLASS[tone],\n // The caller's, over all of the above — base, plain padding, alignment and\n // tone — and under only what the field needs to work (see `inputClassName`).\n inputClassName,\n // Room for the trailing controls, after the caller's so a `px-2` cannot run\n // the digits under the chip (NumberInput's order, which reserves its unit\n // and calculator the same way).\n trailingRoom,\n invalid && FIELD_INVALID,\n locked && \"cursor-not-allowed\",\n )}\n // The classes above are the fallback; once measured the field reserves exactly\n // its trailing controls' width, inline so it wins over every class (see\n // `trailingRoom`).\n style={hasEnd && endWidth != null ? { paddingInlineEnd: endWidth + (asDisplay ? 4 : 8) } : undefined}\n aria-invalid={invalid || undefined}\n aria-describedby={numeric.describedBy}\n aria-required={ariaRequired}\n />\n {/* The label is FloatingField's, after these children (the floating trick\n reads the input through `peer-*`). The display shape drops it VISUALLY,\n not from the accessibility tree: a 36px tinted figure at the top of a\n transaction form is legibly the amount, but a screen reader still needs\n the name, and callers that pass `label` without `aria-label` would\n otherwise be left with none. */}\n {/* Trailing controls share one flex track so the calculator icon and the\n currency suffix/picker sit side by side without overlapping. */}\n {/* The display shape has no box to inset from, so the controls align to the\n figure's own end edge and its baseline strip (`bottom-1`, matching the\n input's pb-1) instead of floating inside a field. */}\n <div\n // Measured for the input's end padding (see `trailingRoom`).\n ref={endRef}\n className={cn(\n \"absolute flex items-center gap-0.5\",\n // Logical `end-*`: the chip and the calculator are the figure's trailing\n // controls, so a right-to-left form carries them on the left.\n asDisplay ? \"bottom-1 end-0\" : \"inset-y-1 end-1\",\n )}\n >\n {showCalc && (\n <CalculatorButton\n // The mark the field shows but not the typist's grouping: the evaluator\n // reads either mark, and \"1.234,5\" is two of them. The result comes back\n // dot-decimal.\n value={derived}\n // Live: every result, settled, so the field never shows more decimals than\n // it will keep. The commit is the session's one (INP-1): its \"=\", or the pad\n // closing on a newer result — not each figure on the way to the result.\n onChange={(result, expression) => {\n setDraft(null);\n handleText(settle(result), expression);\n }}\n onCommit={(result) => onCommit?.(settle(result))}\n className=\"px-1.5\"\n aria-label={labels?.calculatorTrigger}\n labels={labels?.calculator}\n />\n )}\n {currency && !editable && (\n <span\n aria-hidden\n className={cn(\n \"pointer-events-none px-1 font-medium text-muted\",\n // A text-xs chip next to a 36px figure reads as a stray footnote.\n asDisplay ? \"text-sm\" : \"text-xs\",\n )}\n >\n {currency}\n </span>\n )}\n {currency && editable && (\n <button\n ref={chipRef}\n type=\"button\"\n onClick={() => setOpen((v) => !v)}\n // A button that opens a listbox, and says so: the chip is a control inside\n // a text field, not a field of its own, so not a combobox.\n aria-haspopup=\"listbox\"\n aria-expanded={open}\n aria-controls={listboxId}\n aria-label={\n // \"Currency: EUR\" through `common.fieldValue`, not a template literal:\n // the colon-and-space is punctuation a translation has to own.\n selected ? common.fieldValue(currencyText.currency, selected.code) : currencyText.currency\n }\n className={cn(\n \"flex items-center gap-1 rounded px-2 py-1 font-medium text-secondary hover:bg-hover\",\n asDisplay ? \"text-sm\" : \"text-xs\",\n )}\n >\n {currency}\n <ChevronDown className=\"size-3\" />\n </button>\n )}\n </div>\n {editable && (\n <CurrencyOptionList\n core={core}\n listboxId={listboxId}\n value={currency}\n codes={currencyOptions}\n currencyNames={currencyNames}\n locale={locale}\n searchPlaceholder={currencyText.search}\n // The phone sheet's title: what the chip is for.\n sheetTitle={currencyText.currency}\n onChoose={(code) => {\n onCurrencyChange?.(code);\n closeToTrigger();\n }}\n />\n )}\n </FloatingField>\n </LockedOrNot>\n {/* Outside the relative box, as NumberInput's caption is: the trailing\n controls are `inset-y-1` in it and would stretch down over a second line. */}\n <FieldCaption parts={numeric.hint} />\n {/* The news after the standing advice, as Select orders them. The root is\n already a steady box, so the message coming and going remounts nothing. */}\n {numeric.errorEl}\n {showNumpad && (\n <NumberPadSheet\n // Localised like the field it mirrors. Keys are typing, read by the\n // locale's marks like the keyboard's; \"=\" is a result, dot-decimal.\n value={display}\n onChange={typed}\n onResult={(result) => {\n setDraft(null);\n const settled = settle(result);\n handleText(settled);\n onCommit?.(settled);\n }}\n onDone={() => innerRef.current?.blur()}\n label={label}\n labels={labels?.pad}\n decimalMark={mark}\n />\n )}\n </div>\n );\n}\n\n/** The field in its lock's {@link LockedReason} while locked, as it is otherwise. A\n * component rather than a ternary so the field's JSX is written once. `block w-full`:\n * the frame's box stands where the field's own did. */\nfunction LockedOrNot({\n lock,\n display,\n children,\n}: {\n lock: LockReason;\n display: DisabledReasonDisplay | undefined;\n children: ReactNode;\n}) {\n if (!lock.locked) return <>{children}</>;\n return (\n <LockedReason lock={lock} display={display} className=\"block w-full\">\n {children}\n </LockedReason>\n );\n}\n"],"mappings":";AA2kBU,SAkNiB,UAlNjB,KA+HI,YA/HJ;AA3kBV,SAAS,OAAO,SAAS,cAAc;AACvC,SAAS,mBAAmB;AAE5B,SAAS,oBAAoB,mBAAmB;AAChD,SAAS,uBAAuB;AAChC,SAAS,YAAY,eAAe,eAAe,sBAAsB,qBAAqB;AAC9F,SAAS,UAAU;AACnB,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,wBAAqD;AAC9D,SAAS,sBAAiD;AAC1D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,aAAa,uBAAuB;AAE7C,SAAS,sBAA2C;AA8R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A;AAAA,QAGC,OAAO;AAAA,QACP,UAAU;AAAA,QACV,UAAU,CAAC,WAAW;AACpB,mBAAS,IAAI;AACb,gBAAM,UAAU,OAAO,MAAM;AAC7B,qBAAW,OAAO;AAClB,qBAAW,OAAO;AAAA,QACpB;AAAA,QACA,QAAQ,MAAM,SAAS,SAAS,KAAK;AAAA,QACrC;AAAA,QACA,QAAQ,QAAQ;AAAA,QAChB,aAAa;AAAA;AAAA,IACf;AAAA,KAEJ;AAEJ;AAKA,SAAS,YAAY;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,MAAI,CAAC,KAAK,OAAQ,QAAO,gCAAG,UAAS;AACrC,SACE,oBAAC,gBAAa,MAAY,SAAkB,WAAU,gBACnD,UACH;AAEJ;","names":[]}
@@ -21,6 +21,24 @@ interface CalculatorButtonProps {
21
21
  * the one argument and ignore this.
22
22
  */
23
23
  onChange: (value: string, expression?: string) => void;
24
+ /**
25
+ * Called ONCE per calculator session, with the result the host should keep: on "="
26
+ * (the key, or Enter in the display), and when the panel closes — Escape, a press
27
+ * outside, the trigger — on a result `onChange` reported after the last commit. Never
28
+ * per keystroke: `onChange` is the live channel, this is the one to save on.
29
+ *
30
+ * Not called when the button goes away with its panel open (a lock or `disabled`
31
+ * arriving, the field unmounting): those say the value must not move, and the result
32
+ * stays where `onChange` put it.
33
+ *
34
+ * Refactor audit 2026-10-30, INP-1: the pad had no commit point of its own, and the
35
+ * two field engines guessed in opposite directions. NumberInput never committed a
36
+ * result, so Kurvenschmiede's dialogs saved the number from before the calculation;
37
+ * AmountInput committed every keystroke that resolved, so "100+50" saved 105 on its way
38
+ * to 150, and keksdose's threshold field, `disabled` while it saves, lost its pad to the
39
+ * first of them.
40
+ */
41
+ onCommit?: (value: string) => void;
24
42
  className?: string;
25
43
  /** The trigger's accessible name; wins over `calculator.open` from the provider. */
26
44
  "aria-label"?: string;
@@ -33,7 +51,8 @@ interface CalculatorButtonProps {
33
51
  * A calculator icon that opens a small keypad popover anchored to its host
34
52
  * field. Designed as a trailing-edge adornment: render it inside the field's
35
53
  * `relative` wrapper, positioned absolutely. The keypad seeds from the current
36
- * field value and writes evaluated results straight back through `onChange`.
54
+ * field value and writes evaluated results straight back through `onChange`, and
55
+ * commits the session once through `onCommit`.
37
56
  */
38
- export declare function CalculatorButton({ value, onChange, className, "aria-label": ariaLabel, labels: labelsProp, }: CalculatorButtonProps): import("react").JSX.Element;
57
+ export declare function CalculatorButton({ value, onChange, onCommit, className, "aria-label": ariaLabel, labels: labelsProp, }: CalculatorButtonProps): import("react").JSX.Element;
39
58
  export {};
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
- import { useEffect, useMemo, useRef, useState } from "react";
3
+ import { useEffect, useEffectEvent, useMemo, useRef, useState } from "react";
4
4
  import { Calculator as CalculatorIcon, Delete } from "lucide-react";
5
5
  import { Popover } from "./popover.js";
6
6
  import { cn } from "../lib/cn.js";
@@ -36,6 +36,7 @@ function seed(initial) {
36
36
  function CalculatorPanel({
37
37
  initial,
38
38
  onChange,
39
+ onEquals,
39
40
  labels
40
41
  }) {
41
42
  const [expr, setExpr] = useState(() => seed(initial));
@@ -60,6 +61,7 @@ function CalculatorPanel({
60
61
  const out = formatResult(result);
61
62
  setExpr(out);
62
63
  onChange(out, text);
64
+ onEquals();
63
65
  };
64
66
  return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
65
67
  /* @__PURE__ */ jsx(
@@ -138,9 +140,41 @@ function CalculatorPanel({
138
140
  ] })
139
141
  ] });
140
142
  }
143
+ function CalculatorTrigger({
144
+ open,
145
+ onToggle,
146
+ onClosed,
147
+ buttonRef,
148
+ label,
149
+ className
150
+ }) {
151
+ const closed = useEffectEvent(onClosed);
152
+ const wasOpen = useRef(open);
153
+ useEffect(() => {
154
+ if (wasOpen.current && !open) closed();
155
+ wasOpen.current = open;
156
+ }, [open]);
157
+ return /* @__PURE__ */ jsx(
158
+ "button",
159
+ {
160
+ ref: buttonRef,
161
+ type: "button",
162
+ tabIndex: -1,
163
+ onClick: onToggle,
164
+ "aria-label": label,
165
+ "aria-expanded": open,
166
+ className: cn(
167
+ "flex items-center justify-center text-placeholder transition-colors hover:text-secondary",
168
+ className
169
+ ),
170
+ children: /* @__PURE__ */ jsx(CalculatorIcon, { className: "size-4" })
171
+ }
172
+ );
173
+ }
141
174
  function CalculatorButton({
142
175
  value,
143
176
  onChange,
177
+ onCommit,
144
178
  className,
145
179
  "aria-label": ariaLabel,
146
180
  labels: labelsProp
@@ -150,28 +184,33 @@ function CalculatorButton({
150
184
  [ariaLabel, labelsProp]
151
185
  );
152
186
  const labels = useKitLabels("calculator", DEFAULT_CALCULATOR_LABELS, fromProps);
187
+ const unsettled = useRef(null);
188
+ const change = (next, expression) => {
189
+ unsettled.current = next;
190
+ onChange(next, expression);
191
+ };
192
+ const settle = () => {
193
+ const next = unsettled.current;
194
+ unsettled.current = null;
195
+ if (next !== null) onCommit?.(next);
196
+ };
153
197
  return /* @__PURE__ */ jsx(
154
198
  Popover,
155
199
  {
156
200
  width: "14rem",
157
201
  labels: { panel: labels.panel },
158
202
  trigger: ({ open, toggle, ref }) => /* @__PURE__ */ jsx(
159
- "button",
203
+ CalculatorTrigger,
160
204
  {
161
- ref,
162
- type: "button",
163
- tabIndex: -1,
164
- onClick: toggle,
165
- "aria-label": labels.open,
166
- "aria-expanded": open,
167
- className: cn(
168
- "flex items-center justify-center text-placeholder transition-colors hover:text-secondary",
169
- className
170
- ),
171
- children: /* @__PURE__ */ jsx(CalculatorIcon, { className: "size-4" })
205
+ open,
206
+ onToggle: toggle,
207
+ onClosed: settle,
208
+ buttonRef: ref,
209
+ label: labels.open,
210
+ className
172
211
  }
173
212
  ),
174
- children: () => /* @__PURE__ */ jsx(CalculatorPanel, { initial: value, onChange, labels })
213
+ children: () => /* @__PURE__ */ jsx(CalculatorPanel, { initial: value, onChange: change, onEquals: settle, labels })
175
214
  }
176
215
  );
177
216
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/calculator.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from \"react\";\nimport { Calculator as CalculatorIcon, Delete } from \"lucide-react\";\nimport { Popover } from \"./popover\";\nimport { cn } from \"../lib/cn\";\nimport { FIELD_TOUCH_TEXT } from \"./field-base\";\nimport { FOCUS_RING } from \"./focus-ring\";\nimport { evaluateExpression, formatResult, isBareAmount, splitLeadingSign } from \"../lib/calc\";\nimport { DEFAULT_CALCULATOR_LABELS, useKitLabels, type CalculatorLabels } from \"../i18n/kit-labels\";\n\n/** Screen-reader names for the calculator panel's own controls — any part of the\n * kit's `calculator` namespace. Once three optional keys of its own; widened, not\n * replaced, so every object that type-checked before still does. */\nexport type CalculatorButtonLabels = Partial<CalculatorLabels>;\n\ninterface CalculatorButtonProps {\n /** Current field text — seeds the keypad so the user can keep calculating\n * from what's already entered. */\n value: string;\n /**\n * Called with the evaluated result whenever the running expression resolves\n * to a number, so the host field tracks the keypad live.\n *\n * `expression` is the TEXT that result came out of — `\"-42+50\"` for an 8 — and\n * is omitted when there was no calculation (a cleared pad). A host that keeps\n * the sign of its figure OUTSIDE the text (see `AmountInput`'s `negative` /\n * `onNegativeChange`, where a direction toggle owns it) cannot otherwise tell\n * that 8 from a freshly typed one: the first is a sum that came out positive\n * and has to take the direction with it, the second is a magnitude that must\n * leave the direction alone. Hosts whose text carries its own sign can take\n * the one argument and ignore this.\n */\n onChange: (value: string, expression?: string) => void;\n className?: string;\n /** The trigger's accessible name; wins over `calculator.open` from the provider. */\n \"aria-label\"?: string;\n /** Screen-reader names for the panel's own controls. `aria-label` above already\n * covers the trigger; these three were hardcoded English inside the popover,\n * which a translating host had no way to reach. */\n labels?: CalculatorButtonLabels;\n}\n\n/** Keypad layout (4 columns). The final C/= row is rendered separately. `name` is\n * the key of the {@link CalculatorLabels} entry that names a non-digit key; a digit\n * is named by its own glyph. */\ntype Key = { kind: \"ins\"; label: string; ins: string; accent?: boolean; name?: KeyName } | { kind: \"back\" };\n\ntype KeyName = \"plus\" | \"minus\" | \"times\" | \"divide\" | \"decimal\";\n\nconst KEYS: Key[] = [\n { kind: \"ins\", label: \"7\", ins: \"7\" },\n { kind: \"ins\", label: \"8\", ins: \"8\" },\n { kind: \"ins\", label: \"9\", ins: \"9\" },\n { kind: \"ins\", label: \"÷\", ins: \"÷\", accent: true, name: \"divide\" },\n { kind: \"ins\", label: \"4\", ins: \"4\" },\n { kind: \"ins\", label: \"5\", ins: \"5\" },\n { kind: \"ins\", label: \"6\", ins: \"6\" },\n { kind: \"ins\", label: \"×\", ins: \"×\", accent: true, name: \"times\" },\n { kind: \"ins\", label: \"1\", ins: \"1\" },\n { kind: \"ins\", label: \"2\", ins: \"2\" },\n { kind: \"ins\", label: \"3\", ins: \"3\" },\n { kind: \"ins\", label: \"−\", ins: \"−\", accent: true, name: \"minus\" },\n { kind: \"ins\", label: \"0\", ins: \"0\" },\n { kind: \"ins\", label: \".\", ins: \".\", name: \"decimal\" },\n { kind: \"back\" },\n { kind: \"ins\", label: \"+\", ins: \"+\", accent: true, name: \"plus\" },\n];\n\n// The kit's one focus frame (text-size §5). Until 0.34 the keys rang in `ring-strong` on\n// `focus:`, so a pointer click left a grey ring on the key it pressed (DOC-7).\nconst KEY_BASE = `flex h-9 items-center justify-center rounded-md text-sm font-medium transition-colors ${FOCUS_RING}`;\n// Two key families, two fills: digits sit on the inset surface and darken on\n// hover, operators sit a step down on `--bg-active` and lift toward that surface —\n// the same split `NumberPadSheet` uses for this keypad on a phone. The tokens\n// flip with the theme, so neither needs a `dark:` twin.\n//\n// 0.33 (docs/colour-roles-harmonization.md §12.2, §12.9): the digits hover onto\n// `--bg-active`, 1.11–1.18:1 from the key — `--bg-hover` is mixed against the card and\n// sat only 1.04:1 from the well, which in light is the page. The operators rest on\n// `--bg-active` rather than `--border`: More contrast steps the border until it is a\n// 3:1 LINE, and as a fill under the label that left 2.2–2.7:1.\nconst KEY_DIGIT = \"bg-surface-2 text-primary hover:bg-active\";\nconst KEY_ACCENT = \"bg-active text-secondary hover:bg-surface-2\";\n\nfunction seed(initial: string): string {\n const t = initial.trim();\n return t === \"-\" ? \"\" : t;\n}\n\nfunction CalculatorPanel({\n initial,\n onChange,\n labels,\n}: {\n initial: string;\n onChange: (value: string, expression?: string) => void;\n labels: CalculatorLabels;\n}) {\n const [expr, setExpr] = useState(() => seed(initial));\n const inputRef = useRef<HTMLInputElement>(null);\n // What the pad SHOWS. Normally the expression it holds — but when the host owns\n // the sign of the figure, the magnitude it hands back is not the whole number:\n // type 50 into a pad opened on an outflow and the host answers \"-50\". Derived\n // rather than stored, so there is no echo to guard against and a host that\n // ignores `onChange` entirely (a static `value`) still sees its own keystrokes:\n // the pad only defers when the host's text is character-for-character its own\n // last number with a minus in front.\n const host = splitLeadingSign(initial.trim());\n const text = host.sign === \"-\" && isBareAmount(expr) && host.rest === expr.trim() ? initial.trim() : expr;\n const result = evaluateExpression(text);\n\n // Focus the display on open so the user can type or hit Enter immediately.\n useEffect(() => {\n inputRef.current?.focus();\n }, []);\n\n // Update the host field whenever the expression resolves to a number; an\n // incomplete expression (e.g. \"12+\") simply leaves the field untouched. The\n // expression rides along with the result — see `onChange` above.\n const apply = (next: string) => {\n setExpr(next);\n const n = evaluateExpression(next);\n if (n !== null) onChange(formatResult(n), next);\n };\n\n const clearAll = () => {\n setExpr(\"\");\n onChange(\"\");\n };\n\n const equals = () => {\n if (result === null) return;\n const out = formatResult(result);\n setExpr(out);\n onChange(out, text);\n };\n\n return (\n <div className=\"space-y-2\">\n <input\n ref={inputRef}\n aria-label={labels.calculation}\n value={text}\n inputMode=\"decimal\"\n onChange={(e) => apply(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\") {\n e.preventDefault();\n equals();\n }\n }}\n // Arithmetic reads left to right in every script, and a calculator display\n // is right-aligned in every script too — so both stay physical, pinned\n // with `dir=\"ltr\"` rather than mirrored in a right-to-left form.\n dir=\"ltr\"\n className={cn(\n \"block w-full rounded-md border border-subtle bg-surface px-2 py-1.5 text-right font-mono text-sm text-primary focus:border-strong focus:ring-strong\",\n FIELD_TOUCH_TEXT,\n )}\n />\n <div dir=\"ltr\" className=\"h-4 pr-1 text-right font-mono text-xs text-placeholder\">\n {result !== null && formatResult(result) !== text.trim() ? `= ${formatResult(result)}` : \"\"}\n </div>\n <div className=\"grid grid-cols-4 gap-1.5\">\n {KEYS.map((key, i) =>\n key.kind === \"back\" ? (\n <button\n key=\"back\"\n type=\"button\"\n aria-label={labels.backspace}\n onClick={() => apply(text.slice(0, -1))}\n className={cn(KEY_BASE, KEY_ACCENT)}\n >\n <Delete className=\"size-4\" />\n </button>\n ) : (\n <button\n key={`${key.ins}-${i}`}\n type=\"button\"\n aria-label={key.name ? labels[key.name] : undefined}\n onClick={() => apply(text + key.ins)}\n className={cn(KEY_BASE, key.accent ? KEY_ACCENT : KEY_DIGIT)}\n >\n {key.label}\n </button>\n ),\n )}\n <button\n type=\"button\"\n // \"C\" is a convention, not a name: read aloud it is the letter.\n aria-label={labels.clear}\n onClick={clearAll}\n className={cn(KEY_BASE, \"col-span-2\", KEY_ACCENT)}\n >\n C\n </button>\n <button\n type=\"button\"\n aria-label={labels.equals}\n onClick={equals}\n className={cn(\n KEY_BASE,\n // The one chip that inverts against the page. There is no hover token for\n // an inverted fill, so the hover is the chip mixed back toward the\n // surface — a step quieter in either theme, and still a colour, so\n // KEY_BASE's `transition-colors` carries it.\n \"col-span-2 bg-inverse text-inverse hover:bg-[color-mix(in_oklab,var(--bg-inverse)_88%,var(--bg-surface))]\",\n )}\n >\n =\n </button>\n </div>\n </div>\n );\n}\n\n/**\n * A calculator icon that opens a small keypad popover anchored to its host\n * field. Designed as a trailing-edge adornment: render it inside the field's\n * `relative` wrapper, positioned absolutely. The keypad seeds from the current\n * field value and writes evaluated results straight back through `onChange`.\n */\nexport function CalculatorButton({\n value,\n onChange,\n className,\n \"aria-label\": ariaLabel,\n labels: labelsProp,\n}: CalculatorButtonProps) {\n // prop > provider > English, with the name prop folded in as the `open` key it has\n // always been.\n const fromProps = useMemo(\n () => (ariaLabel === undefined ? labelsProp : { ...labelsProp, open: ariaLabel }),\n [ariaLabel, labelsProp],\n );\n const labels = useKitLabels(\"calculator\", DEFAULT_CALCULATOR_LABELS, fromProps);\n return (\n <Popover\n width=\"14rem\"\n labels={{ panel: labels.panel }}\n trigger={({ open, toggle, ref }) => (\n <button\n ref={ref}\n type=\"button\"\n tabIndex={-1}\n onClick={toggle}\n aria-label={labels.open}\n aria-expanded={open}\n className={cn(\n \"flex items-center justify-center text-placeholder transition-colors hover:text-secondary\",\n className,\n )}\n >\n <CalculatorIcon className=\"size-4\" />\n </button>\n )}\n >\n {() => <CalculatorPanel initial={value} onChange={onChange} labels={labels} />}\n </Popover>\n );\n}\n"],"mappings":";AA0IM,cAwBA,YAxBA;AA1IN,SAAS,WAAW,SAAS,QAAQ,gBAAgB;AACrD,SAAS,cAAc,gBAAgB,cAAc;AACrD,SAAS,eAAe;AACxB,SAAS,UAAU;AACnB,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB,cAAc,cAAc,wBAAwB;AACjF,SAAS,2BAA2B,oBAA2C;AAyC/E,MAAM,OAAc;AAAA,EAClB,EAAE,MAAM,OAAO,OAAO,KAAK,KAAK,IAAI;AAAA,EACpC,EAAE,MAAM,OAAO,OAAO,KAAK,KAAK,IAAI;AAAA,EACpC,EAAE,MAAM,OAAO,OAAO,KAAK,KAAK,IAAI;AAAA,EACpC,EAAE,MAAM,OAAO,OAAO,QAAK,KAAK,QAAK,QAAQ,MAAM,MAAM,SAAS;AAAA,EAClE,EAAE,MAAM,OAAO,OAAO,KAAK,KAAK,IAAI;AAAA,EACpC,EAAE,MAAM,OAAO,OAAO,KAAK,KAAK,IAAI;AAAA,EACpC,EAAE,MAAM,OAAO,OAAO,KAAK,KAAK,IAAI;AAAA,EACpC,EAAE,MAAM,OAAO,OAAO,QAAK,KAAK,QAAK,QAAQ,MAAM,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sources":["../../src/components/calculator.tsx"],"sourcesContent":["import { useEffect, useEffectEvent, useMemo, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\nimport { Calculator as CalculatorIcon, Delete } from \"lucide-react\";\nimport { Popover } from \"./popover\";\nimport { cn } from \"../lib/cn\";\nimport { FIELD_TOUCH_TEXT } from \"./field-base\";\nimport { FOCUS_RING } from \"./focus-ring\";\nimport { evaluateExpression, formatResult, isBareAmount, splitLeadingSign } from \"../lib/calc\";\nimport { DEFAULT_CALCULATOR_LABELS, useKitLabels, type CalculatorLabels } from \"../i18n/kit-labels\";\n\n/** Screen-reader names for the calculator panel's own controls — any part of the\n * kit's `calculator` namespace. Once three optional keys of its own; widened, not\n * replaced, so every object that type-checked before still does. */\nexport type CalculatorButtonLabels = Partial<CalculatorLabels>;\n\ninterface CalculatorButtonProps {\n /** Current field text — seeds the keypad so the user can keep calculating\n * from what's already entered. */\n value: string;\n /**\n * Called with the evaluated result whenever the running expression resolves\n * to a number, so the host field tracks the keypad live.\n *\n * `expression` is the TEXT that result came out of — `\"-42+50\"` for an 8 — and\n * is omitted when there was no calculation (a cleared pad). A host that keeps\n * the sign of its figure OUTSIDE the text (see `AmountInput`'s `negative` /\n * `onNegativeChange`, where a direction toggle owns it) cannot otherwise tell\n * that 8 from a freshly typed one: the first is a sum that came out positive\n * and has to take the direction with it, the second is a magnitude that must\n * leave the direction alone. Hosts whose text carries its own sign can take\n * the one argument and ignore this.\n */\n onChange: (value: string, expression?: string) => void;\n /**\n * Called ONCE per calculator session, with the result the host should keep: on \"=\"\n * (the key, or Enter in the display), and when the panel closes — Escape, a press\n * outside, the trigger — on a result `onChange` reported after the last commit. Never\n * per keystroke: `onChange` is the live channel, this is the one to save on.\n *\n * Not called when the button goes away with its panel open (a lock or `disabled`\n * arriving, the field unmounting): those say the value must not move, and the result\n * stays where `onChange` put it.\n *\n * Refactor audit 2026-10-30, INP-1: the pad had no commit point of its own, and the\n * two field engines guessed in opposite directions. NumberInput never committed a\n * result, so Kurvenschmiede's dialogs saved the number from before the calculation;\n * AmountInput committed every keystroke that resolved, so \"100+50\" saved 105 on its way\n * to 150, and keksdose's threshold field, `disabled` while it saves, lost its pad to the\n * first of them.\n */\n onCommit?: (value: string) => void;\n className?: string;\n /** The trigger's accessible name; wins over `calculator.open` from the provider. */\n \"aria-label\"?: string;\n /** Screen-reader names for the panel's own controls. `aria-label` above already\n * covers the trigger; these three were hardcoded English inside the popover,\n * which a translating host had no way to reach. */\n labels?: CalculatorButtonLabels;\n}\n\n/** Keypad layout (4 columns). The final C/= row is rendered separately. `name` is\n * the key of the {@link CalculatorLabels} entry that names a non-digit key; a digit\n * is named by its own glyph. */\ntype Key = { kind: \"ins\"; label: string; ins: string; accent?: boolean; name?: KeyName } | { kind: \"back\" };\n\ntype KeyName = \"plus\" | \"minus\" | \"times\" | \"divide\" | \"decimal\";\n\nconst KEYS: Key[] = [\n { kind: \"ins\", label: \"7\", ins: \"7\" },\n { kind: \"ins\", label: \"8\", ins: \"8\" },\n { kind: \"ins\", label: \"9\", ins: \"9\" },\n { kind: \"ins\", label: \"÷\", ins: \"÷\", accent: true, name: \"divide\" },\n { kind: \"ins\", label: \"4\", ins: \"4\" },\n { kind: \"ins\", label: \"5\", ins: \"5\" },\n { kind: \"ins\", label: \"6\", ins: \"6\" },\n { kind: \"ins\", label: \"×\", ins: \"×\", accent: true, name: \"times\" },\n { kind: \"ins\", label: \"1\", ins: \"1\" },\n { kind: \"ins\", label: \"2\", ins: \"2\" },\n { kind: \"ins\", label: \"3\", ins: \"3\" },\n { kind: \"ins\", label: \"−\", ins: \"−\", accent: true, name: \"minus\" },\n { kind: \"ins\", label: \"0\", ins: \"0\" },\n { kind: \"ins\", label: \".\", ins: \".\", name: \"decimal\" },\n { kind: \"back\" },\n { kind: \"ins\", label: \"+\", ins: \"+\", accent: true, name: \"plus\" },\n];\n\n// The kit's one focus frame (text-size §5). Until 0.34 the keys rang in `ring-strong` on\n// `focus:`, so a pointer click left a grey ring on the key it pressed (DOC-7).\nconst KEY_BASE = `flex h-9 items-center justify-center rounded-md text-sm font-medium transition-colors ${FOCUS_RING}`;\n// Two key families, two fills: digits sit on the inset surface and darken on\n// hover, operators sit a step down on `--bg-active` and lift toward that surface —\n// the same split `NumberPadSheet` uses for this keypad on a phone. The tokens\n// flip with the theme, so neither needs a `dark:` twin.\n//\n// 0.33 (docs/colour-roles-harmonization.md §12.2, §12.9): the digits hover onto\n// `--bg-active`, 1.11–1.18:1 from the key — `--bg-hover` is mixed against the card and\n// sat only 1.04:1 from the well, which in light is the page. The operators rest on\n// `--bg-active` rather than `--border`: More contrast steps the border until it is a\n// 3:1 LINE, and as a fill under the label that left 2.2–2.7:1.\nconst KEY_DIGIT = \"bg-surface-2 text-primary hover:bg-active\";\nconst KEY_ACCENT = \"bg-active text-secondary hover:bg-surface-2\";\n\nfunction seed(initial: string): string {\n const t = initial.trim();\n return t === \"-\" ? \"\" : t;\n}\n\nfunction CalculatorPanel({\n initial,\n onChange,\n onEquals,\n labels,\n}: {\n initial: string;\n onChange: (value: string, expression?: string) => void;\n /** \"=\" was pressed on a result: the session's commit point. */\n onEquals: () => void;\n labels: CalculatorLabels;\n}) {\n const [expr, setExpr] = useState(() => seed(initial));\n const inputRef = useRef<HTMLInputElement>(null);\n // What the pad SHOWS. Normally the expression it holds — but when the host owns\n // the sign of the figure, the magnitude it hands back is not the whole number:\n // type 50 into a pad opened on an outflow and the host answers \"-50\". Derived\n // rather than stored, so there is no echo to guard against and a host that\n // ignores `onChange` entirely (a static `value`) still sees its own keystrokes:\n // the pad only defers when the host's text is character-for-character its own\n // last number with a minus in front.\n const host = splitLeadingSign(initial.trim());\n const text = host.sign === \"-\" && isBareAmount(expr) && host.rest === expr.trim() ? initial.trim() : expr;\n const result = evaluateExpression(text);\n\n // Focus the display on open so the user can type or hit Enter immediately.\n useEffect(() => {\n inputRef.current?.focus();\n }, []);\n\n // Update the host field whenever the expression resolves to a number; an\n // incomplete expression (e.g. \"12+\") simply leaves the field untouched. The\n // expression rides along with the result — see `onChange` above.\n const apply = (next: string) => {\n setExpr(next);\n const n = evaluateExpression(next);\n if (n !== null) onChange(formatResult(n), next);\n };\n\n const clearAll = () => {\n setExpr(\"\");\n onChange(\"\");\n };\n\n const equals = () => {\n if (result === null) return;\n const out = formatResult(result);\n setExpr(out);\n onChange(out, text);\n onEquals();\n };\n\n return (\n <div className=\"space-y-2\">\n <input\n ref={inputRef}\n aria-label={labels.calculation}\n value={text}\n inputMode=\"decimal\"\n onChange={(e) => apply(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\") {\n e.preventDefault();\n equals();\n }\n }}\n // Arithmetic reads left to right in every script, and a calculator display\n // is right-aligned in every script too — so both stay physical, pinned\n // with `dir=\"ltr\"` rather than mirrored in a right-to-left form.\n dir=\"ltr\"\n className={cn(\n \"block w-full rounded-md border border-subtle bg-surface px-2 py-1.5 text-right font-mono text-sm text-primary focus:border-strong focus:ring-strong\",\n FIELD_TOUCH_TEXT,\n )}\n />\n <div dir=\"ltr\" className=\"h-4 pr-1 text-right font-mono text-xs text-placeholder\">\n {result !== null && formatResult(result) !== text.trim() ? `= ${formatResult(result)}` : \"\"}\n </div>\n <div className=\"grid grid-cols-4 gap-1.5\">\n {KEYS.map((key, i) =>\n key.kind === \"back\" ? (\n <button\n key=\"back\"\n type=\"button\"\n aria-label={labels.backspace}\n onClick={() => apply(text.slice(0, -1))}\n className={cn(KEY_BASE, KEY_ACCENT)}\n >\n <Delete className=\"size-4\" />\n </button>\n ) : (\n <button\n key={`${key.ins}-${i}`}\n type=\"button\"\n aria-label={key.name ? labels[key.name] : undefined}\n onClick={() => apply(text + key.ins)}\n className={cn(KEY_BASE, key.accent ? KEY_ACCENT : KEY_DIGIT)}\n >\n {key.label}\n </button>\n ),\n )}\n <button\n type=\"button\"\n // \"C\" is a convention, not a name: read aloud it is the letter.\n aria-label={labels.clear}\n onClick={clearAll}\n className={cn(KEY_BASE, \"col-span-2\", KEY_ACCENT)}\n >\n C\n </button>\n <button\n type=\"button\"\n aria-label={labels.equals}\n onClick={equals}\n className={cn(\n KEY_BASE,\n // The one chip that inverts against the page. There is no hover token for\n // an inverted fill, so the hover is the chip mixed back toward the\n // surface — a step quieter in either theme, and still a colour, so\n // KEY_BASE's `transition-colors` carries it.\n \"col-span-2 bg-inverse text-inverse hover:bg-[color-mix(in_oklab,var(--bg-inverse)_88%,var(--bg-surface))]\",\n )}\n >\n =\n </button>\n </div>\n </div>\n );\n}\n\n/**\n * The trigger, and the place a session ends. The render in which `open` turns false is\n * the panel closing, however it closed — Escape, a press outside, this button — and\n * that is when a result the pad left unsettled is committed. A component of its own\n * because `open` lives in Popover and reaches only the trigger.\n *\n * Not the panel's unmount: the panel also goes when a lock or `disabled` takes the\n * calculator away, and nothing may commit then. Those unmount this button with it, so no\n * render ever sees `open` turn false.\n */\nfunction CalculatorTrigger({\n open,\n onToggle,\n onClosed,\n buttonRef,\n label,\n className,\n}: {\n open: boolean;\n onToggle: () => void;\n onClosed: () => void;\n buttonRef: RefObject<HTMLButtonElement | null>;\n label: string;\n className?: string;\n}) {\n const closed = useEffectEvent(onClosed);\n const wasOpen = useRef(open);\n useEffect(() => {\n if (wasOpen.current && !open) closed();\n wasOpen.current = open;\n }, [open]);\n return (\n <button\n ref={buttonRef}\n type=\"button\"\n tabIndex={-1}\n onClick={onToggle}\n aria-label={label}\n aria-expanded={open}\n className={cn(\n \"flex items-center justify-center text-placeholder transition-colors hover:text-secondary\",\n className,\n )}\n >\n <CalculatorIcon className=\"size-4\" />\n </button>\n );\n}\n\n/**\n * A calculator icon that opens a small keypad popover anchored to its host\n * field. Designed as a trailing-edge adornment: render it inside the field's\n * `relative` wrapper, positioned absolutely. The keypad seeds from the current\n * field value and writes evaluated results straight back through `onChange`, and\n * commits the session once through `onCommit`.\n */\nexport function CalculatorButton({\n value,\n onChange,\n onCommit,\n className,\n \"aria-label\": ariaLabel,\n labels: labelsProp,\n}: CalculatorButtonProps) {\n // prop > provider > English, with the name prop folded in as the `open` key it has\n // always been.\n const fromProps = useMemo(\n () => (ariaLabel === undefined ? labelsProp : { ...labelsProp, open: ariaLabel }),\n [ariaLabel, labelsProp],\n );\n const labels = useKitLabels(\"calculator\", DEFAULT_CALCULATOR_LABELS, fromProps);\n // The last result `onChange` reported that no commit has covered yet — what closing\n // the panel commits. Written by the pad's handlers and read when it closes; never\n // rendered, so a ref.\n const unsettled = useRef<string | null>(null);\n const change = (next: string, expression?: string) => {\n unsettled.current = next;\n onChange(next, expression);\n };\n const settle = () => {\n const next = unsettled.current;\n unsettled.current = null;\n if (next !== null) onCommit?.(next);\n };\n return (\n <Popover\n width=\"14rem\"\n labels={{ panel: labels.panel }}\n trigger={({ open, toggle, ref }) => (\n <CalculatorTrigger\n open={open}\n onToggle={toggle}\n onClosed={settle}\n buttonRef={ref}\n label={labels.open}\n className={className}\n />\n )}\n >\n {() => <CalculatorPanel initial={value} onChange={change} onEquals={settle} labels={labels} />}\n </Popover>\n );\n}\n"],"mappings":";AAiKM,cAwBA,YAxBA;AAjKN,SAAS,WAAW,gBAAgB,SAAS,QAAQ,gBAAgB;AAErE,SAAS,cAAc,gBAAgB,cAAc;AACrD,SAAS,eAAe;AACxB,SAAS,UAAU;AACnB,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB,cAAc,cAAc,wBAAwB;AACjF,SAAS,2BAA2B,oBAA2C;AA2D/E,MAAM,OAAc;AAAA,EAClB,EAAE,MAAM,OAAO,OAAO,KAAK,KAAK,IAAI;AAAA,EACpC,EAAE,MAAM,OAAO,OAAO,KAAK,KAAK,IAAI;AAAA,EACpC,EAAE,MAAM,OAAO,OAAO,KAAK,KAAK,IAAI;AAAA,EACpC,EAAE,MAAM,OAAO,OAAO,QAAK,KAAK,QAAK,QAAQ,MAAM,MAAM,SAAS;AAAA,EAClE,EAAE,MAAM,OAAO,OAAO,KAAK,KAAK,IAAI;AAAA,EACpC,EAAE,MAAM,OAAO,OAAO,KAAK,K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A,EACd,QAAQ;AACV,GAA0B;AAGxB,QAAM,YAAY;AAAA,IAChB,MAAO,cAAc,SAAY,aAAa,EAAE,GAAG,YAAY,MAAM,UAAU;AAAA,IAC/E,CAAC,WAAW,UAAU;AAAA,EACxB;AACA,QAAM,SAAS,aAAa,cAAc,2BAA2B,SAAS;AAI9E,QAAM,YAAY,OAAsB,IAAI;AAC5C,QAAM,SAAS,CAAC,MAAc,eAAwB;AACpD,cAAU,UAAU;AACpB,aAAS,MAAM,UAAU;AAAA,EAC3B;AACA,QAAM,SAAS,MAAM;AACnB,UAAM,OAAO,UAAU;AACvB,cAAU,UAAU;AACpB,QAAI,SAAS,KAAM,YAAW,IAAI;AAAA,EACpC;AACA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAM;AAAA,MACN,QAAQ,EAAE,OAAO,OAAO,MAAM;AAAA,MAC9B,SAAS,CAAC,EAAE,MAAM,QAAQ,IAAI,MAC5B;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA,UAAU;AAAA,UACV,UAAU;AAAA,UACV,WAAW;AAAA,UACX,OAAO,OAAO;AAAA,UACd;AAAA;AAAA,MACF;AAAA,MAGD,gBAAM,oBAAC,mBAAgB,SAAS,OAAO,UAAU,QAAQ,UAAU,QAAQ,QAAgB;AAAA;AAAA,EAC9F;AAEJ;","names":[]}
@@ -71,16 +71,19 @@ export declare const DISABLED_ROW_CLASS = "cursor-not-allowed opacity-50 hover:b
71
71
  * Whether an entity picker offers its create row — one rule for
72
72
  * {@link EntityCombobox}, {@link MultiEntityCombobox} and {@link InlineEntityCombobox}.
73
73
  *
74
- * With a query: while the trimmed query names no option exactly (case-insensitive) —
75
- * an exact hit is a record the list is already showing, and a second way to "make" it
76
- * would mint a duplicate. With NO query: only when the caller named the row for that
74
+ * With a query: while the trimmed query names no option exactly — an exact hit is a
75
+ * record the list is already showing, and a second way to "make" it would mint a
76
+ * duplicate. "Exactly" as the list matches, folded by `locale` ({@link sameName}): with
77
+ * plain `toLowerCase`, "cafe" listed Café and offered "Create “cafe”" beside it (refactor
78
+ * audit 2026-10-30, DUP-5). With NO query: only when the caller named the row for that
77
79
  * case (`createEmptyLabel`) — a row reading `Create “”` says nothing, and the kit cannot
78
80
  * know the noun ("Create cash account") that would make it say something (keksdose G9).
79
81
  *
80
82
  * `names` is what the query is compared against: the loaded rows for a panel picker
81
- * (its async list is all it knows), every option for the inline one.
83
+ * (its async list is all it knows), every option for the inline one. `locale`: the
84
+ * provider's, which the list's match folds by; left out, the runtime's.
82
85
  */
83
- export declare function offersCreate(onCreate: unknown, query: string, names: readonly string[], createEmptyLabel: string | undefined): boolean;
86
+ export declare function offersCreate(onCreate: unknown, query: string, names: readonly string[], createEmptyLabel: string | undefined, locale?: string): boolean;
84
87
  /**
85
88
  * {@link EndHintRow}'s `hint` and `className` for a combobox-family field, keeping the
86
89
  * 0.22 rule (keksdose): a field that was passed `hint` at all — even `undefined` — keeps
@@ -15,7 +15,7 @@ import { anchoredInline, useAnchoredPanel, viewportSize } from "../hooks/use-anc
15
15
  import { pressInside, takeEscape, useDismissLayer, useOutsideClick } from "../hooks/use-dismiss.js";
16
16
  import { useOverlayHistory } from "../hooks/use-overlay-history.js";
17
17
  import { isImeEnter } from "../lib/ime.js";
18
- import { matchesSearch, searchWords } from "../lib/text-match.js";
18
+ import { matchesSearch, sameName, searchWords } from "../lib/text-match.js";
19
19
  import { DEFAULT_COMBOBOX_LABELS, useKitLabels, useKitLocale } from "../i18n/kit-labels.js";
20
20
  import { hasContent } from "../lib/presence.js";
21
21
  const isOptionEnabled = (o) => o !== void 0 && !o.disabled;
@@ -34,11 +34,10 @@ function settleEnabled(rows, i) {
34
34
  return before !== i ? before : -1;
35
35
  }
36
36
  const DISABLED_ROW_CLASS = "cursor-not-allowed opacity-50 hover:bg-transparent";
37
- function offersCreate(onCreate, query, names, createEmptyLabel) {
37
+ function offersCreate(onCreate, query, names, createEmptyLabel, locale) {
38
38
  if (!onCreate) return false;
39
39
  if (!query) return Boolean(createEmptyLabel);
40
- const q = query.toLowerCase();
41
- return !names.some((n) => n.toLowerCase() === q);
40
+ return !names.some((n) => sameName(n, query, locale));
42
41
  }
43
42
  function endHintRowProps(hintPassed, hasLabel, labelHint) {
44
43
  if (hasLabel) return { hint: void 0 };