@eifi1/ui-kit 0.21.0 → 0.22.0

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 (278) hide show
  1. package/dist/chart.d.ts +10 -8
  2. package/dist/components/account-chips.d.ts +10 -3
  3. package/dist/components/account-chips.js +5 -2
  4. package/dist/components/account-chips.js.map +1 -1
  5. package/dist/components/account-settings.d.ts +33 -2
  6. package/dist/components/account-settings.js +43 -21
  7. package/dist/components/account-settings.js.map +1 -1
  8. package/dist/components/amount-input.d.ts +27 -8
  9. package/dist/components/amount-input.js +15 -28
  10. package/dist/components/amount-input.js.map +1 -1
  11. package/dist/components/autocomplete.d.ts +8 -0
  12. package/dist/components/autocomplete.js +9 -4
  13. package/dist/components/autocomplete.js.map +1 -1
  14. package/dist/components/button-group.d.ts +10 -8
  15. package/dist/components/calculator.d.ts +10 -8
  16. package/dist/components/checkbox-group.d.ts +104 -0
  17. package/dist/components/checkbox-group.js +111 -0
  18. package/dist/components/checkbox-group.js.map +1 -0
  19. package/dist/components/checkbox.d.ts +19 -0
  20. package/dist/components/checkbox.js +30 -7
  21. package/dist/components/checkbox.js.map +1 -1
  22. package/dist/components/chip.d.ts +18 -0
  23. package/dist/components/chip.js +47 -10
  24. package/dist/components/chip.js.map +1 -1
  25. package/dist/components/combobox.d.ts +13 -2
  26. package/dist/components/combobox.js +17 -8
  27. package/dist/components/combobox.js.map +1 -1
  28. package/dist/components/confirm-dialog.d.ts +66 -161
  29. package/dist/components/copy-button.d.ts +10 -8
  30. package/dist/components/country-select.d.ts +124 -0
  31. package/dist/components/country-select.js +237 -0
  32. package/dist/components/country-select.js.map +1 -0
  33. package/dist/components/currency-select.d.ts +17 -1
  34. package/dist/components/currency-select.js +56 -23
  35. package/dist/components/currency-select.js.map +1 -1
  36. package/dist/components/danger-confirm.d.ts +66 -166
  37. package/dist/components/danger-confirm.js +133 -49
  38. package/dist/components/danger-confirm.js.map +1 -1
  39. package/dist/components/data-table-cells.d.ts +1 -2
  40. package/dist/components/data-table-filter-popover.d.ts +1 -2
  41. package/dist/components/data-table-filters.d.ts +1 -2
  42. package/dist/components/data-table-labels.d.ts +4 -97
  43. package/dist/components/data-table-labels.js +9 -1
  44. package/dist/components/data-table-labels.js.map +1 -1
  45. package/dist/components/data-table-pagination.d.ts +3 -1
  46. package/dist/components/data-table.d.ts +1 -2
  47. package/dist/components/data-table.js +98 -3
  48. package/dist/components/data-table.js.map +1 -1
  49. package/dist/components/date-picker.d.ts +25 -5
  50. package/dist/components/date-picker.js +110 -59
  51. package/dist/components/date-picker.js.map +1 -1
  52. package/dist/components/entity-combobox.d.ts +8 -1
  53. package/dist/components/entity-combobox.js +9 -4
  54. package/dist/components/entity-combobox.js.map +1 -1
  55. package/dist/components/facing-pair.d.ts +10 -8
  56. package/dist/components/field-anatomy.d.ts +95 -0
  57. package/dist/components/field-anatomy.js +84 -0
  58. package/dist/components/field-anatomy.js.map +1 -0
  59. package/dist/components/field-parts.d.ts +114 -0
  60. package/dist/components/field-parts.js +72 -0
  61. package/dist/components/field-parts.js.map +1 -0
  62. package/dist/components/file-button.d.ts +10 -8
  63. package/dist/components/file-button.js +13 -3
  64. package/dist/components/file-button.js.map +1 -1
  65. package/dist/components/file-dropzone.d.ts +32 -9
  66. package/dist/components/file-dropzone.js +57 -34
  67. package/dist/components/file-dropzone.js.map +1 -1
  68. package/dist/components/form-actions.d.ts +10 -8
  69. package/dist/components/form-actions.js +61 -3
  70. package/dist/components/form-actions.js.map +1 -1
  71. package/dist/components/iban-input.d.ts +66 -0
  72. package/dist/components/iban-input.js +125 -0
  73. package/dist/components/iban-input.js.map +1 -0
  74. package/dist/components/icon-picker.d.ts +12 -2
  75. package/dist/components/icon-picker.js +9 -2
  76. package/dist/components/icon-picker.js.map +1 -1
  77. package/dist/components/inline-edit-field.d.ts +167 -0
  78. package/dist/components/inline-edit-field.js +293 -0
  79. package/dist/components/inline-edit-field.js.map +1 -0
  80. package/dist/components/language-select.d.ts +127 -0
  81. package/dist/components/language-select.js +18 -0
  82. package/dist/components/language-select.js.map +1 -0
  83. package/dist/components/line-items.d.ts +25 -3
  84. package/dist/components/line-items.js +55 -46
  85. package/dist/components/line-items.js.map +1 -1
  86. package/dist/components/list.d.ts +25 -0
  87. package/dist/components/list.js +16 -5
  88. package/dist/components/list.js.map +1 -1
  89. package/dist/components/money-field.d.ts +20 -8
  90. package/dist/components/money-field.js.map +1 -1
  91. package/dist/components/month-picker.d.ts +52 -4
  92. package/dist/components/month-picker.js +290 -86
  93. package/dist/components/month-picker.js.map +1 -1
  94. package/dist/components/multi-select.d.ts +8 -1
  95. package/dist/components/multi-select.js +9 -4
  96. package/dist/components/multi-select.js.map +1 -1
  97. package/dist/components/number-field.d.ts +25 -13
  98. package/dist/components/number-field.js +6 -20
  99. package/dist/components/number-field.js.map +1 -1
  100. package/dist/components/number-input.d.ts +70 -13
  101. package/dist/components/number-input.js +90 -38
  102. package/dist/components/number-input.js.map +1 -1
  103. package/dist/components/numpad-sheet.d.ts +10 -8
  104. package/dist/components/one-time-code-input.d.ts +100 -0
  105. package/dist/components/one-time-code-input.js +137 -0
  106. package/dist/components/one-time-code-input.js.map +1 -0
  107. package/dist/components/phone-input.d.ts +66 -0
  108. package/dist/components/phone-input.js +171 -0
  109. package/dist/components/phone-input.js.map +1 -0
  110. package/dist/components/series-chart.d.ts +10 -8
  111. package/dist/components/settings-fields.d.ts +10 -8
  112. package/dist/components/share-card.d.ts +8 -6
  113. package/dist/components/sign-chip.d.ts +66 -0
  114. package/dist/components/sign-chip.js +39 -0
  115. package/dist/components/sign-chip.js.map +1 -0
  116. package/dist/components/swatch-picker.d.ts +27 -2
  117. package/dist/components/swatch-picker.js +73 -31
  118. package/dist/components/swatch-picker.js.map +1 -1
  119. package/dist/components/switch.d.ts +19 -0
  120. package/dist/components/switch.js +24 -6
  121. package/dist/components/switch.js.map +1 -1
  122. package/dist/components/text-link.d.ts +10 -8
  123. package/dist/components/tile-radio.d.ts +68 -13
  124. package/dist/components/tile-radio.js +3 -3
  125. package/dist/components/tile-radio.js.map +1 -1
  126. package/dist/components/time-input.d.ts +15 -9
  127. package/dist/components/time-input.js.map +1 -1
  128. package/dist/components/toggle-group.d.ts +47 -1
  129. package/dist/components/toggle-group.js +110 -69
  130. package/dist/components/toggle-group.js.map +1 -1
  131. package/dist/components/ui.d.ts +10 -8
  132. package/dist/components/ui.js +280 -78
  133. package/dist/components/ui.js.map +1 -1
  134. package/dist/components/use-table-state.d.ts +1 -2
  135. package/dist/{data-table-3mi2R3so.d.ts → data-table-labels-B7OdnM0S.d.ts} +140 -3
  136. package/dist/data-table.d.ts +1 -2
  137. package/dist/data-table.js +2 -1
  138. package/dist/data-table.js.map +1 -1
  139. package/dist/feedback/feedback-attachment.d.ts +1 -1
  140. package/dist/feedback/feedback-attachment.js +210 -3
  141. package/dist/feedback/feedback-attachment.js.map +1 -1
  142. package/dist/feedback/feedback-dialog.d.ts +1 -1
  143. package/dist/feedback/feedback-dialog.js.map +1 -1
  144. package/dist/feedback/feedback-inbox.d.ts +1 -1
  145. package/dist/feedback/feedback-thread.d.ts +37 -3
  146. package/dist/feedback/feedback-thread.js +38 -9
  147. package/dist/feedback/feedback-thread.js.map +1 -1
  148. package/dist/{feedback-attachment-WFiXJ8We.d.ts → feedback-attachment-NhUm7Zga.d.ts} +70 -5
  149. package/dist/feedback.d.ts +2 -2
  150. package/dist/hooks/use-file-drop.d.ts +10 -8
  151. package/dist/i18n/defaults.d.ts +10 -8
  152. package/dist/i18n/defaults.js +17 -2
  153. package/dist/i18n/defaults.js.map +1 -1
  154. package/dist/i18n/german.d.ts +10 -8
  155. package/dist/i18n/german.js +50 -5
  156. package/dist/i18n/german.js.map +1 -1
  157. package/dist/i18n/kit-labels.d.ts +10 -8
  158. package/dist/i18n/kit-labels.js +8 -2
  159. package/dist/i18n/kit-labels.js.map +1 -1
  160. package/dist/i18n/languages.d.ts +10 -8
  161. package/dist/i18n/locales/de-CH.d.ts +10 -8
  162. package/dist/i18n/locales/en.d.ts +10 -8
  163. package/dist/i18n/locales/en.js +9 -0
  164. package/dist/i18n/locales/en.js.map +1 -1
  165. package/dist/i18n/locales/es.d.ts +10 -8
  166. package/dist/i18n/locales/es.js +48 -5
  167. package/dist/i18n/locales/es.js.map +1 -1
  168. package/dist/i18n/locales/fr.d.ts +10 -8
  169. package/dist/i18n/locales/fr.js +48 -5
  170. package/dist/i18n/locales/fr.js.map +1 -1
  171. package/dist/i18n/locales/hu.d.ts +10 -8
  172. package/dist/i18n/locales/hu.js +49 -5
  173. package/dist/i18n/locales/hu.js.map +1 -1
  174. package/dist/i18n/locales/it.d.ts +10 -8
  175. package/dist/i18n/locales/it.js +49 -5
  176. package/dist/i18n/locales/it.js.map +1 -1
  177. package/dist/i18n/locales/zh.d.ts +10 -8
  178. package/dist/i18n/locales/zh.js +48 -5
  179. package/dist/i18n/locales/zh.js.map +1 -1
  180. package/dist/i18n/review.d.ts +10 -8
  181. package/dist/i18n/review.js +8 -1
  182. package/dist/i18n/review.js.map +1 -1
  183. package/dist/index.d.ts +17 -10
  184. package/dist/index.js +57 -2
  185. package/dist/index.js.map +1 -1
  186. package/dist/{kit-labels-D1J2_jyD.d.ts → kit-labels-R8mIAc9N.d.ts} +811 -8
  187. package/dist/lib/countries.d.ts +43 -0
  188. package/dist/lib/countries.js +39 -0
  189. package/dist/lib/countries.js.map +1 -0
  190. package/dist/lib/decimal-marks.d.ts +46 -0
  191. package/dist/lib/decimal-marks.js +40 -0
  192. package/dist/lib/decimal-marks.js.map +1 -0
  193. package/dist/lib/iban.d.ts +98 -0
  194. package/dist/lib/iban.js +154 -0
  195. package/dist/lib/iban.js.map +1 -0
  196. package/dist/lib/isin.d.ts +30 -0
  197. package/dist/lib/isin.js +36 -0
  198. package/dist/lib/isin.js.map +1 -0
  199. package/dist/lib/phone.d.ts +69 -0
  200. package/dist/lib/phone.js +121 -0
  201. package/dist/lib/phone.js.map +1 -0
  202. package/dist/rhf/fields.d.ts +148 -11
  203. package/dist/rhf/fields.js +332 -3
  204. package/dist/rhf/fields.js.map +1 -1
  205. package/dist/rhf/form.d.ts +10 -8
  206. package/dist/rhf.d.ts +13 -9
  207. package/dist/rhf.js.map +1 -1
  208. package/dist/shell/app-shell.d.ts +10 -8
  209. package/dist/shell/top-bar-brand.d.ts +10 -8
  210. package/dist/shell.d.ts +10 -8
  211. package/dist/tour/tour.js +20 -24
  212. package/dist/tour/tour.js.map +1 -1
  213. package/dist/wizard/stepper-nav.d.ts +10 -8
  214. package/dist/wizard.d.ts +10 -8
  215. package/package.json +1 -1
  216. package/src/components/account-chips.tsx +17 -3
  217. package/src/components/account-settings.tsx +92 -26
  218. package/src/components/amount-input.tsx +49 -56
  219. package/src/components/autocomplete.tsx +133 -110
  220. package/src/components/checkbox-group.tsx +229 -0
  221. package/src/components/checkbox.tsx +72 -8
  222. package/src/components/chip.tsx +80 -10
  223. package/src/components/combobox.tsx +292 -253
  224. package/src/components/country-select.tsx +443 -0
  225. package/src/components/currency-select.tsx +109 -33
  226. package/src/components/danger-confirm.tsx +345 -77
  227. package/src/components/data-table-labels.ts +16 -1
  228. package/src/components/data-table.tsx +175 -6
  229. package/src/components/date-picker.tsx +173 -62
  230. package/src/components/entity-combobox.tsx +107 -87
  231. package/src/components/field-anatomy.tsx +190 -0
  232. package/src/components/field-parts.tsx +184 -0
  233. package/src/components/file-button.tsx +36 -3
  234. package/src/components/file-dropzone.tsx +106 -38
  235. package/src/components/form-actions.tsx +115 -2
  236. package/src/components/iban-input.tsx +231 -0
  237. package/src/components/icon-picker.tsx +26 -4
  238. package/src/components/inline-edit-field.tsx +533 -0
  239. package/src/components/language-select.tsx +78 -0
  240. package/src/components/line-items.tsx +35 -2
  241. package/src/components/list.tsx +55 -6
  242. package/src/components/money-field.tsx +10 -0
  243. package/src/components/month-picker.tsx +399 -63
  244. package/src/components/multi-select.tsx +80 -58
  245. package/src/components/number-field.tsx +28 -46
  246. package/src/components/number-input.tsx +210 -43
  247. package/src/components/one-time-code-input.tsx +288 -0
  248. package/src/components/phone-input.tsx +299 -0
  249. package/src/components/sign-chip.tsx +103 -0
  250. package/src/components/swatch-picker.tsx +118 -30
  251. package/src/components/switch.tsx +58 -7
  252. package/src/components/tile-radio.tsx +71 -16
  253. package/src/components/time-input.tsx +8 -1
  254. package/src/components/toggle-group.tsx +206 -73
  255. package/src/components/ui.tsx +472 -105
  256. package/src/data-table.ts +2 -1
  257. package/src/feedback/feedback-attachment.tsx +313 -9
  258. package/src/feedback/feedback-dialog.tsx +2 -0
  259. package/src/feedback/feedback-thread.tsx +66 -5
  260. package/src/i18n/defaults.ts +16 -1
  261. package/src/i18n/german.ts +47 -0
  262. package/src/i18n/kit-labels.tsx +78 -2
  263. package/src/i18n/locales/en.ts +10 -0
  264. package/src/i18n/locales/es.ts +46 -0
  265. package/src/i18n/locales/fr.ts +45 -0
  266. package/src/i18n/locales/hu.ts +46 -0
  267. package/src/i18n/locales/it.ts +47 -0
  268. package/src/i18n/locales/zh.ts +44 -0
  269. package/src/i18n/review.ts +7 -0
  270. package/src/index.ts +53 -3
  271. package/src/lib/countries.ts +91 -0
  272. package/src/lib/decimal-marks.ts +99 -0
  273. package/src/lib/iban.ts +171 -0
  274. package/src/lib/isin.ts +62 -0
  275. package/src/lib/phone.ts +211 -0
  276. package/src/rhf/fields.tsx +606 -9
  277. package/src/rhf.ts +2 -1
  278. package/src/tour/tour.tsx +66 -28
package/src/index.ts CHANGED
@@ -111,8 +111,25 @@ export * from "./components/disclosure";
111
111
  export * from "./components/dialog-frame";
112
112
  // Named, not `*`: danger-confirm also holds the password field and pending hook that
113
113
  // ReauthDialog shares with it, which are kit-internal.
114
- export { DangerConfirm, DEFAULT_DANGER_CONFIRM_LABELS, typedMatches } from "./components/danger-confirm";
115
- export type { DangerConfirmLabels, DangerConfirmProps, TypedMatch } from "./components/danger-confirm";
114
+ export {
115
+ DangerConfirm,
116
+ DEFAULT_DANGER_CONFIRM_LABELS,
117
+ typedMatches,
118
+ // 0.22.0: the typed-confirmation field on its own (keksdose K7) and the current-password
119
+ // field kastlan wants for sign-in and re-authentication (kastlan 1).
120
+ TypedConfirmField,
121
+ CurrentPasswordInput,
122
+ } from "./components/danger-confirm";
123
+ export type {
124
+ DangerConfirmLabels,
125
+ DangerConfirmProps,
126
+ TypedMatch,
127
+ DangerConsequence,
128
+ TypedConfirmFieldProps,
129
+ TypedConfirmFieldLabels,
130
+ CurrentPasswordInputProps,
131
+ CurrentPasswordInputLabels,
132
+ } from "./components/danger-confirm";
116
133
  // 0.18: re-authentication before a sensitive action (Kurvenschmiede 4).
117
134
  export { ReauthDialog, DEFAULT_REAUTH_DIALOG_LABELS } from "./components/reauth-dialog";
118
135
  export type { ReauthDialogProps, ReauthDialogLabels } from "./components/reauth-dialog";
@@ -259,8 +276,9 @@ export * from "./components/data-table-pagination";
259
276
  export { FilterPopover } from "./components/data-table-filter-popover";
260
277
  // data-table re-exports SortState internally; export the rest explicitly to
261
278
  // avoid a duplicate SortState star-export (it comes from data-table-sort).
262
- export { DataTable } from "./components/data-table";
279
+ export { DataTable, DEFAULT_DATA_TABLE_SORT_LABELS } from "./components/data-table";
263
280
  export type {
281
+ DataTableSortLabels,
264
282
  DataTableColumn,
265
283
  DataTableCellProps,
266
284
  DataTableHeadProps,
@@ -406,3 +424,35 @@ export type {
406
424
  // The legal pages' shell (0.19, H10): Imprint, Privacy Policy, Terms in every app.
407
425
  export { LegalLayout, LegalSection, LegalLinks, DEFAULT_LEGAL_LABELS } from "./components/legal";
408
426
  export type { LegalLabels, LegalLink, LegalLinksProps, LegalSectionProps, LegalLayoutProps } from "./components/legal";
427
+
428
+ // ── 0.22.0: the inputs round (kastlan's, keksdose's and Kurvenschmiede's audits) ──
429
+ export * from "./components/checkbox-group";
430
+ export * from "./components/one-time-code-input";
431
+ export * from "./components/language-select";
432
+ export * from "./components/tile-radio";
433
+ export * from "./components/inline-edit-field";
434
+ export * from "./components/sign-chip";
435
+ export * from "./components/country-select";
436
+ export { COUNTRY_CODES, countryName } from "./lib/countries";
437
+ export * from "./components/iban-input";
438
+ export {
439
+ IBAN_LENGTHS,
440
+ compactIban,
441
+ formatIban,
442
+ ibanCheckDigits,
443
+ ibanProblem,
444
+ isValidIban,
445
+ isQrIban,
446
+ } from "./lib/iban";
447
+ export type { IbanKind, IbanProblem } from "./lib/iban";
448
+ export { formatIsin, isinCheckDigit, isValidIsin } from "./lib/isin";
449
+ export * from "./components/phone-input";
450
+ export {
451
+ PHONE_DIAL_CODES,
452
+ PHONE_COUNTRIES,
453
+ parsePhone,
454
+ formatNationalPhone,
455
+ formatPhone,
456
+ isE164,
457
+ } from "./lib/phone";
458
+ export type { PhoneCountryCode, PhoneCountry, ParsedPhone } from "./lib/phone";
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Countries as ISO 3166-1 alpha-2 codes, named by the runtime — for {@link CountrySelect}
3
+ * and for an app that shows the code it stored ("CH") as a name somewhere else (a
4
+ * table cell, an address line).
5
+ *
6
+ * The kit ships CODES, not names. Every runtime the kit supports has
7
+ * `Intl.DisplayNames({ type: "region" })`, which names all of these in every locale
8
+ * the browser knows — so a table of 249 names per language would be a large file
9
+ * that is out of date the day a country is renamed (Türkiye, Czechia, Eswatini) and
10
+ * still covers fewer languages than the browser does. What is left to ship is the
11
+ * list of which codes ARE countries, and that is one string.
12
+ */
13
+
14
+ /**
15
+ * Every officially assigned ISO 3166-1 alpha-2 code — the 249 countries, territories
16
+ * and areas of the standard, upper-case, in code order.
17
+ *
18
+ * User-assigned codes are deliberately not in it: `XK` (Kosovo) is a widespread
19
+ * convention, not ISO, and whether to offer it is the app's decision. An app that
20
+ * wants it passes its own list to `CountrySelect`'s `countries` — the runtime names
21
+ * `XK` as well.
22
+ */
23
+ export const COUNTRY_CODES: readonly string[] = Object.freeze(
24
+ (
25
+ "AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ " +
26
+ "BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM " +
27
+ "DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS " +
28
+ "GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN " +
29
+ "KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ " +
30
+ "MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM " +
31
+ "PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV " +
32
+ "SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI " +
33
+ "VN VU WF WS YE YT ZA ZM ZW"
34
+ ).split(" "),
35
+ );
36
+
37
+ /** Two ASCII letters — the shape of an alpha-2 code, whatever the case. */
38
+ const ALPHA_2 = /^[A-Za-z]{2}$/;
39
+
40
+ /** `code` upper-cased when it has the shape of an alpha-2 code, else `undefined`. Does
41
+ * not check that ISO assigned it — see {@link COUNTRY_CODES} for why `XK` must pass. */
42
+ export function normalizeCountryCode(code: string | null | undefined): string | undefined {
43
+ return code && ALPHA_2.test(code) ? code.toUpperCase() : undefined;
44
+ }
45
+
46
+ // One `DisplayNames` per locale, built on first use. `null` records a locale the
47
+ // runtime refused (a malformed tag) or a runtime without the API, so neither is
48
+ // retried for every row of a 249-row list.
49
+ const namers = new Map<string, Intl.DisplayNames | null>();
50
+
51
+ function namer(locale: string): Intl.DisplayNames | null {
52
+ let n = namers.get(locale);
53
+ if (n === undefined) {
54
+ try {
55
+ n = new Intl.DisplayNames([locale], { type: "region", fallback: "code" });
56
+ } catch {
57
+ n = null;
58
+ }
59
+ namers.set(locale, n);
60
+ }
61
+ return n;
62
+ }
63
+
64
+ /**
65
+ * The name of the country `code` stands for, in `locale` — `countryName("CH", "de-CH")`
66
+ * is "Schweiz". Falls back to the upper-cased code itself when the runtime has no name
67
+ * for it, rejects the locale, or has no `Intl.DisplayNames`: a code is still the right
68
+ * answer, where an empty cell would not be.
69
+ *
70
+ * `locale` defaults to English rather than to the runtime's language, the rule the
71
+ * kit's currency names follow (`currencyName`): an app that never set a locale reads
72
+ * the kit's English everywhere else, and a country list in the browser's language
73
+ * beside English labels — or in the test runner's — is two languages on one form.
74
+ *
75
+ * The code is upper-cased first. `DisplayNames` is case-sensitive about it in some
76
+ * runtimes (Node answers "ch" with "ch"), and the codes reach this from forms,
77
+ * URLs and databases in either case.
78
+ */
79
+ export function countryName(code: string, locale: string = "en"): string {
80
+ const upper = code.toUpperCase();
81
+ const n = namer(locale);
82
+ if (n) {
83
+ try {
84
+ const name = n.of(upper);
85
+ if (name) return name;
86
+ } catch {
87
+ // Not a well-formed region subtag ("C1", "") — the code is all there is.
88
+ }
89
+ }
90
+ return upper;
91
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The locale's decimal mark and the reading of typed grouping marks, shared by the
3
+ * kit's numeric text fields: {@link AmountInput}, {@link NumberInput} and, through
4
+ * NumberInput, {@link NumberField} and {@link MoneyField}.
5
+ *
6
+ * Package-private — not re-exported from the barrel. It lives here rather than in
7
+ * `calc.ts` because that module is re-exported wholesale (`export * from
8
+ * "./lib/calc"`), and these are the fields' plumbing, not API.
9
+ *
10
+ * WHY ONE MODULE. AmountInput learned the locale's mark (kastlan 40) and the grouping
11
+ * parse (keksdose G1); NumberInput learned neither, so the same "1.234,56" a German
12
+ * user typed into a money field read as 1234.56 and, typed into the budget-goal field
13
+ * next to it, as 1.23456 (keksdose K5). Two private copies of the same rule are how
14
+ * that happened, so the rule now has one home.
15
+ */
16
+ import { sanitizeLive } from "./calc";
17
+
18
+ /**
19
+ * The locale's decimal mark, as far as a field can type it: "," or "." (kastlan 40).
20
+ * A mark outside those two (Arabic's "٫") is not one {@link sanitizeLive} lets
21
+ * through, so those locales keep the dot rather than get a field that eats the key it
22
+ * shows. `undefined` is the runtime's own locale, which is what `Intl` reads it as.
23
+ */
24
+ export function decimalMark(locale: string | undefined): "," | "." {
25
+ try {
26
+ const part = new Intl.NumberFormat(locale).formatToParts(1.5).find((p) => p.type === "decimal");
27
+ return part?.value === "," ? "," : ".";
28
+ } catch {
29
+ // An invalid tag throws a RangeError; a typo in a locale must not take the form down.
30
+ return ".";
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Which typed mark is the decimal one (keksdose G1). {@link sanitizeLive} folds every
36
+ * "," into ".", so on its own it read the German "1.234,56" as 1.23456 — and a money
37
+ * field's settle then made that 1.23, final. This decides per operand, from the
38
+ * typist's own text, before that fold:
39
+ *
40
+ * - both marks present: the one that is not the locale's is grouping, and goes;
41
+ * - in a "," locale, only "." present: grouping when it cannot be a decimal as a
42
+ * German reader writes it — twice ("1.234.567"), or in thousands shape ("1.234",
43
+ * "12.500") — otherwise a decimal ("1.5", typed by a dot-decimal habit);
44
+ * - in a "." locale, only "," present: grouping when it appears twice ("1,234,567");
45
+ * once it stays a decimal, because Swiss and German typists write "1,5" in a
46
+ * de-CH form (kastlan 40) and a unit price "1,789" is a decimal.
47
+ *
48
+ * Only a keystroke's text comes through here. A calculator result is dot-decimal
49
+ * already, and "1.234" from `100/81.03…` is never a thousand.
50
+ */
51
+ export function normalizeTypedMarks(raw: string, mark: "," | "."): string {
52
+ const other = mark === "," ? "." : ",";
53
+ return raw.replace(/[0-9.,]+/g, (operand) => {
54
+ const hasMark = operand.includes(mark);
55
+ const count = operand.split(other).length - 1;
56
+ if (count === 0) return operand;
57
+ const grouping = hasMark
58
+ ? true
59
+ : count > 1 || (mark === "," && /^\d{1,3}(\.\d{3})+$/.test(operand));
60
+ return grouping ? operand.split(other).join("") : operand;
61
+ });
62
+ }
63
+
64
+ /** What a keystroke's raw text reports: grouping read off, then the field's live
65
+ * sanitising (comma → dot, stray characters out, one decimal point per operand). */
66
+ export function readTyped(raw: string, mark: "," | "."): string {
67
+ return sanitizeLive(normalizeTypedMarks(raw, mark));
68
+ }
69
+
70
+ // Spacing a typist uses to group digits — a space, the no-break and narrow no-break
71
+ // spaces `Intl` itself writes for fr-CH ("1 234,5" with U+202F), and the Swiss
72
+ // apostrophes ("1'234.50"). The live sanitising drops them, so they never reach the
73
+ // value; the draft may still show them.
74
+ const GROUP_SPACING = /[\s'’\u00a0\u202f]/g;
75
+
76
+ /**
77
+ * Whether the field may keep SHOWING `raw` — the typist's own text — while it holds
78
+ * `canonical` (dot-decimal, as `onChange` reported it).
79
+ *
80
+ * Showing the typed text rather than re-spelling the value is what keeps the caret
81
+ * where the typist put it, and what keeps a grouping "." from being turned into a ","
82
+ * under their fingers — after which no rule could tell the two apart (keksdose G1).
83
+ * But only text that says the same as the value, and says it with nothing the field
84
+ * would have DROPPED: a letter, or a second decimal point in one operand ("1.2.3"),
85
+ * must not stay on screen while the value says "1.23" (Keksdose live #201 is the bug
86
+ * that showing it would bring back). Grouping marks and grouping spaces may stay.
87
+ */
88
+ export function showsTyped(raw: string, mark: "," | ".", canonical: string): boolean {
89
+ const read = normalizeTypedMarks(raw, mark).replace(GROUP_SPACING, "");
90
+ const sanitized = sanitizeLive(read);
91
+ // Nothing dropped: the read text is the sanitised one, but for which mark it uses.
92
+ return sanitized === read.replace(/,/g, ".") && sanitized === sanitizeLive(canonical);
93
+ }
94
+
95
+ /** A dot-decimal text spelt in `mark` — display only, one character for one, so a
96
+ * re-spelling never moves a caret. */
97
+ export function localizeMark(text: string, mark: "," | "."): string {
98
+ return mark === "," ? text.replace(/\./g, ",") : text;
99
+ }
@@ -0,0 +1,171 @@
1
+ /**
2
+ * IBAN helpers — ISO 13616 — for kastlan (supplier and customer bank details, the
3
+ * Swiss QR-bill) and keksdose (the accounts behind a household's transfers).
4
+ *
5
+ * Both apps validated an IBAN the same partial way: a regex for the shape, sometimes a
6
+ * mod-97, never the per-country length — so a Swiss IBAN with a digit missing passed
7
+ * as long as the shorter string happened to sum right, and "CH" followed by 22
8
+ * characters (a German length) was accepted as Swiss. And kastlan's QR-bill needs a
9
+ * second distinction neither had: a **QR-IBAN** (the institution id at positions 5–9 is
10
+ * 30000–31999) is the only account a QR-bill with a QR reference can be paid to, and it
11
+ * cannot receive an ordinary transfer — so a regular IBAN typed where a QR-IBAN is
12
+ * needed, or the other way round, is a payment that bounces weeks later.
13
+ *
14
+ * Everything here works on the **electronic format** (no spaces, upper case), which is
15
+ * what to store; {@link formatIban} is the paper format, which is what to show.
16
+ *
17
+ * Validation is the registry's two rules, nothing more: the length for the country and
18
+ * the mod-97 check digits. It does not check each country's BBAN layout (which places
19
+ * hold letters), nor whether the bank exists — a checksum catches a typo, not a closed
20
+ * account.
21
+ */
22
+
23
+ /**
24
+ * The IBAN length for each country in the SWIFT IBAN Registry (2025 edition) — the
25
+ * whole string, country code and check digits included.
26
+ *
27
+ * A country that is not in the table does not issue IBANs, so {@link isValidIban}
28
+ * refuses it ("XX" is a typo, not an exotic bank). Territories that use another
29
+ * country's code (Åland under FI, Guernsey under GB, the French overseas departments
30
+ * under FR) are covered by that code, as the registry lists them.
31
+ */
32
+ export const IBAN_LENGTHS: Readonly<Record<string, number>> = Object.freeze({
33
+ AD: 24, AE: 23, AL: 28, AT: 20, AZ: 28, BA: 20, BE: 16, BG: 22, BH: 22, BI: 27,
34
+ BR: 29, BY: 28, CH: 21, CR: 22, CY: 28, CZ: 24, DE: 22, DJ: 27, DK: 18, DO: 28,
35
+ EE: 20, EG: 29, ES: 24, FI: 18, FK: 18, FO: 18, FR: 27, GB: 22, GE: 22, GI: 23,
36
+ GL: 18, GR: 27, GT: 28, HN: 28, HR: 21, HU: 28, IE: 22, IL: 23, IQ: 23, IS: 26,
37
+ IT: 27, JO: 30, KW: 30, KZ: 20, LB: 28, LC: 32, LI: 21, LT: 20, LU: 20, LV: 21,
38
+ LY: 25, MC: 27, MD: 24, ME: 22, MK: 19, MN: 20, MR: 27, MT: 31, MU: 30, NI: 28,
39
+ NL: 18, NO: 15, OM: 23, PK: 24, PL: 28, PS: 29, PT: 25, QA: 29, RO: 24, RS: 22,
40
+ RU: 33, SA: 24, SC: 31, SD: 18, SE: 24, SI: 19, SK: 24, SM: 27, SO: 23, ST: 25,
41
+ SV: 28, TL: 23, TN: 24, TR: 26, UA: 29, VA: 22, VG: 24, XK: 20, YE: 30,
42
+ });
43
+
44
+ /**
45
+ * Which kind of IBAN a field accepts. `"any"`: every valid IBAN. `"qr"`: only a
46
+ * QR-IBAN (a QR-bill with a QR reference — kastlan's payment slips). `"plain"`: every
47
+ * valid IBAN EXCEPT a QR-IBAN (an account for ordinary transfers, which a QR-IBAN
48
+ * cannot receive).
49
+ */
50
+ export type IbanKind = "qr" | "plain" | "any";
51
+
52
+ /**
53
+ * Why a value is not the IBAN a field wants, most fundamental first:
54
+ *
55
+ * - `"format"` — it does not start with a two-letter country code and two digits;
56
+ * - `"country"` — the first two letters are not a country in {@link IBAN_LENGTHS};
57
+ * - `"length"` — the wrong number of characters for that country;
58
+ * - `"checksum"` — the mod-97 check digits do not match (a typo, a swapped pair);
59
+ * - `"qrRequired"` — a valid IBAN, but not a QR-IBAN where `kind="qr"` needs one;
60
+ * - `"qrNotAllowed"` — a valid QR-IBAN where `kind="plain"` refuses one.
61
+ */
62
+ export type IbanProblem = "format" | "country" | "length" | "checksum" | "qrRequired" | "qrNotAllowed";
63
+
64
+ /**
65
+ * The electronic format: every character that is not a letter or a digit dropped, the
66
+ * letters in upper case. Spaces, non-breaking spaces, hyphens and dots — what a paste
67
+ * from an invoice, a PDF or an e-banking screen carries — all go.
68
+ *
69
+ * A leading `"IBAN"` (the paper format's label: "IBAN CH56 …") is dropped too, but only
70
+ * in front of a country code and check digits, so typing the word does not make it
71
+ * vanish under the caret.
72
+ */
73
+ export function compactIban(value: string): string {
74
+ const compact = value.replace(/[^0-9A-Za-z]/g, "").toUpperCase();
75
+ return /^IBAN[A-Z]{2}\d{2}/.test(compact) ? compact.slice(4) : compact;
76
+ }
77
+
78
+ /**
79
+ * The paper format: {@link compactIban}, then groups of four separated by a single
80
+ * space ("CH09 0000 0000 0000 0000 1"). The last group is whatever is left over.
81
+ */
82
+ export function formatIban(value: string): string {
83
+ return compactIban(value).replace(/(.{4})(?=.)/g, "$1 ");
84
+ }
85
+
86
+ /** The remainder of a long digit string modulo 97, a few digits at a time so it never
87
+ * leaves the safe-integer range — ISO 7064 MOD 97-10 without a BigInt. */
88
+ function mod97(digits: string): number {
89
+ let rest = 0;
90
+ for (let i = 0; i < digits.length; i += 7) {
91
+ rest = Number(`${rest}${digits.slice(i, i + 7)}`) % 97;
92
+ }
93
+ return rest;
94
+ }
95
+
96
+ /** Letters to their two-digit numbers (A = 10 … Z = 35), digits as they are. */
97
+ function expandLetters(value: string): string {
98
+ return value.replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55));
99
+ }
100
+
101
+ /**
102
+ * The two check digits for a country code and a BBAN (the account part after them):
103
+ * `98 − ((BBAN + country + "00") mod 97)`, letters expanded A = 10 … Z = 35.
104
+ *
105
+ * What an app needs to BUILD an IBAN — a test fixture, a demo, a migration that
106
+ * assembles one from a clearing number and an account number — rather than to check
107
+ * one. Both arguments are compacted first.
108
+ */
109
+ export function ibanCheckDigits(country: string, bban: string): string {
110
+ const rearranged = `${compactIban(bban)}${compactIban(country)}00`;
111
+ const check = 98 - mod97(expandLetters(rearranged));
112
+ return String(check).padStart(2, "0");
113
+ }
114
+
115
+ /**
116
+ * The first thing wrong with `value` as an IBAN of `kind`, or `null` when it is one.
117
+ * The value is compacted first, so the paper format is accepted. An empty value is
118
+ * `"format"`: whether a field may be left empty is the form's rule, not the IBAN's.
119
+ */
120
+ export function ibanProblem(value: string, kind: IbanKind = "any"): IbanProblem | null {
121
+ const iban = compactIban(value);
122
+ if (!/^[A-Z]{2}\d{2}/.test(iban)) return "format";
123
+ const expected = IBAN_LENGTHS[iban.slice(0, 2)];
124
+ if (expected === undefined) return "country";
125
+ if (iban.length !== expected) return "length";
126
+ // 00, 01 and 99 are never computed (98 − r lies in 2…98), but 01 ≡ 98 mod 97 and
127
+ // would otherwise pass the remainder test below — ISO 7064 rules them out.
128
+ const check = iban.slice(2, 4);
129
+ if (check === "00" || check === "01" || check === "99") return "checksum";
130
+ if (mod97(expandLetters(`${iban.slice(4)}${iban.slice(0, 4)}`)) !== 1) return "checksum";
131
+ if (kind === "any") return null;
132
+ const qr = qrIid(iban);
133
+ if (kind === "qr" && !qr) return "qrRequired";
134
+ if (kind === "plain" && qr) return "qrNotAllowed";
135
+ return null;
136
+ }
137
+
138
+ /**
139
+ * Whether `value` is a valid IBAN: a registry country, that country's length, and
140
+ * matching mod-97 check digits. Spaces and lower case are fine (see
141
+ * {@link compactIban}); what to store is the compact form.
142
+ */
143
+ export function isValidIban(value: string): boolean {
144
+ return ibanProblem(value) === null;
145
+ }
146
+
147
+ /** A CH/LI IBAN whose institution id (positions 5–9) is in the QR range. Structure
148
+ * only — the caller has checked or will check the rest. */
149
+ function qrIid(iban: string): boolean {
150
+ const country = iban.slice(0, 2);
151
+ if (country !== "CH" && country !== "LI") return false;
152
+ const iid = iban.slice(4, 9);
153
+ if (!/^\d{5}$/.test(iid)) return false;
154
+ const n = Number(iid);
155
+ return n >= 30000 && n <= 31999;
156
+ }
157
+
158
+ /**
159
+ * Whether `value` is a valid **QR-IBAN**: a valid Swiss or Liechtenstein IBAN whose
160
+ * institution id — positions 5 to 9, the QR-IID — lies in 30000–31999 (SIX, Swiss
161
+ * Implementation Guidelines for the QR-bill).
162
+ *
163
+ * The distinction is not cosmetic (kastlan): a QR-bill with a QR reference can only be
164
+ * paid to a QR-IBAN, and a QR-IBAN can receive nothing else — so an app that prints
165
+ * payment slips needs one, and an app that stores an account for ordinary transfers
166
+ * must not take one.
167
+ */
168
+ export function isQrIban(value: string): boolean {
169
+ const iban = compactIban(value);
170
+ return ibanProblem(iban) === null && qrIid(iban);
171
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * ISIN helpers — ISO 6166 — for keksdose, whose securities holdings are keyed by ISIN
3
+ * and whose import and edit forms checked only the shape (two letters, ten
4
+ * characters): a mistyped ISIN saved happily and then matched no price feed.
5
+ *
6
+ * An ISIN is twelve characters: a two-letter prefix (the issuing country, or a
7
+ * supranational code such as `XS`), nine letters or digits (the national number) and
8
+ * one check digit. The check digit is the Luhn digit of the first eleven characters
9
+ * with every letter expanded to two digits (A = 10 … Z = 35) — which is all that is
10
+ * checked here. Whether the prefix is an assigned code, and whether the security
11
+ * exists, is a lookup, not a checksum.
12
+ */
13
+
14
+ /** Letters to their two-digit numbers (A = 10 … Z = 35), digits as they are. */
15
+ function expandLetters(value: string): string {
16
+ return value.replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55));
17
+ }
18
+
19
+ /** The Luhn sum of `digits` with the RIGHTMOST digit doubled first — the shape of the
20
+ * sum when a check digit is about to be appended. */
21
+ function luhnSum(digits: string, doubleRightmost: boolean): number {
22
+ let sum = 0;
23
+ let double = doubleRightmost;
24
+ for (let i = digits.length - 1; i >= 0; i--) {
25
+ let d = digits.charCodeAt(i) - 48;
26
+ if (double) {
27
+ d *= 2;
28
+ if (d > 9) d -= 9;
29
+ }
30
+ sum += d;
31
+ double = !double;
32
+ }
33
+ return sum;
34
+ }
35
+
36
+ /**
37
+ * The ISIN as it is printed: upper case, unbroken (ISO 6166 has no grouping), with
38
+ * the spaces and hyphens a paste from a broker's statement carries dropped.
39
+ */
40
+ export function formatIsin(value: string): string {
41
+ return value.replace(/[\s-]/g, "").toUpperCase();
42
+ }
43
+
44
+ /**
45
+ * The check digit for the first eleven characters of an ISIN (prefix and national
46
+ * number). For BUILDING one — a test fixture, a demo — rather than checking it.
47
+ */
48
+ export function isinCheckDigit(body: string): string {
49
+ const sum = luhnSum(expandLetters(formatIsin(body)), true);
50
+ return String((10 - (sum % 10)) % 10);
51
+ }
52
+
53
+ /**
54
+ * Whether `value` is a valid ISIN: two letters, nine letters or digits, one digit,
55
+ * and a matching Luhn check digit over the letter-expanded form. Spaces, hyphens and
56
+ * lower case are fine (see {@link formatIsin}).
57
+ */
58
+ export function isValidIsin(value: string): boolean {
59
+ const isin = formatIsin(value);
60
+ if (!/^[A-Z]{2}[A-Z0-9]{9}\d$/.test(isin)) return false;
61
+ return luhnSum(expandLetters(isin), false) % 10 === 0;
62
+ }