@10x-media/fields 0.1.0-beta.0 → 0.1.0-beta.10

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 (320) hide show
  1. package/CHANGELOG.md +173 -0
  2. package/README.md +8 -4
  3. package/dist/exports/client.d.ts +10 -1
  4. package/dist/exports/client.js +9 -1
  5. package/dist/exports/color-utils.d.ts +4 -2
  6. package/dist/exports/color-utils.js +3 -1
  7. package/dist/exports/color.d.ts +5 -2
  8. package/dist/exports/color.js +4 -1
  9. package/dist/exports/encrypted.d.ts +7 -4
  10. package/dist/exports/encrypted.js +6 -3
  11. package/dist/exports/icon-adapters/radix.d.ts +2 -2
  12. package/dist/exports/icon-adapters/radix.js +2 -2
  13. package/dist/exports/icon-react.d.ts +2 -2
  14. package/dist/exports/icon.d.ts +6 -2
  15. package/dist/exports/icon.js +6 -2
  16. package/dist/exports/measurement-utils.d.ts +9 -0
  17. package/dist/exports/measurement-utils.js +8 -0
  18. package/dist/exports/measurement.d.ts +11 -0
  19. package/dist/exports/measurement.js +10 -0
  20. package/dist/exports/phone-utils.d.ts +4 -0
  21. package/dist/exports/phone-utils.js +4 -0
  22. package/dist/exports/phone.d.ts +6 -0
  23. package/dist/exports/phone.js +3 -0
  24. package/dist/exports/rsc.d.ts +5 -1
  25. package/dist/exports/rsc.js +5 -1
  26. package/dist/exports/types.d.ts +3 -2
  27. package/dist/fields/color/client/ColorField.d.ts +2 -0
  28. package/dist/fields/color/client/ColorField.js +35 -288
  29. package/dist/fields/color/client/ColorField.js.map +1 -1
  30. package/dist/fields/color/client/ColorInput.d.ts +44 -0
  31. package/dist/fields/color/client/ColorInput.js +374 -0
  32. package/dist/fields/color/client/ColorInput.js.map +1 -0
  33. package/dist/fields/color/client/ColorPickerPanel.d.ts +3 -1
  34. package/dist/fields/color/client/ColorPickerPanel.js +31 -5
  35. package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
  36. package/dist/fields/color/client/colorField.css +30 -0
  37. package/dist/fields/color/colorField.d.ts +9 -2
  38. package/dist/fields/color/colorField.js +68 -15
  39. package/dist/fields/color/colorField.js.map +1 -1
  40. package/dist/fields/color/engine/index.d.ts +2 -1
  41. package/dist/fields/color/engine/scheme.d.ts +13 -0
  42. package/dist/fields/color/engine/scheme.js +12 -0
  43. package/dist/fields/color/engine/scheme.js.map +1 -0
  44. package/dist/fields/color/options.d.ts +5 -4
  45. package/dist/fields/color/options.js.map +1 -1
  46. package/dist/fields/color/paths.d.ts +1 -0
  47. package/dist/fields/color/paths.js +32 -0
  48. package/dist/fields/color/paths.js.map +1 -0
  49. package/dist/fields/color/presetChip.js +10 -9
  50. package/dist/fields/color/presetChip.js.map +1 -1
  51. package/dist/fields/color/presetReference.d.ts +13 -0
  52. package/dist/fields/color/presetReference.js +94 -0
  53. package/dist/fields/color/presetReference.js.map +1 -0
  54. package/dist/fields/color/presetsFromArray.d.ts +30 -0
  55. package/dist/fields/color/presetsFromArray.js +58 -0
  56. package/dist/fields/color/presetsFromArray.js.map +1 -0
  57. package/dist/fields/color/presetsFromDoc.js +1 -23
  58. package/dist/fields/color/presetsFromDoc.js.map +1 -1
  59. package/dist/fields/color/resolvePresets.d.ts +2 -2
  60. package/dist/fields/color/resolvePresets.js +38 -8
  61. package/dist/fields/color/resolvePresets.js.map +1 -1
  62. package/dist/fields/color/schemeValue.js +30 -0
  63. package/dist/fields/color/schemeValue.js.map +1 -0
  64. package/dist/fields/color/server/ColorCell.js +9 -3
  65. package/dist/fields/color/server/ColorCell.js.map +1 -1
  66. package/dist/fields/color/server/colorCell.css +5 -0
  67. package/dist/fields/color/valueIssue.js +23 -0
  68. package/dist/fields/color/valueIssue.js.map +1 -0
  69. package/dist/fields/encrypted/boot.js +2 -1
  70. package/dist/fields/encrypted/boot.js.map +1 -1
  71. package/dist/fields/encrypted/components/EncryptedInput.js +4 -1
  72. package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -1
  73. package/dist/fields/encrypted/components/EncryptedTextarea.js +6 -2
  74. package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -1
  75. package/dist/fields/encrypted/components/ProtectedCell.d.ts +15 -6
  76. package/dist/fields/encrypted/components/ProtectedCell.js +37 -8
  77. package/dist/fields/encrypted/components/ProtectedCell.js.map +1 -1
  78. package/dist/fields/encrypted/components/ProtectedField.css +134 -39
  79. package/dist/fields/encrypted/components/ProtectedField.d.ts +3 -0
  80. package/dist/fields/encrypted/components/ProtectedField.js +14 -0
  81. package/dist/fields/encrypted/components/ProtectedField.js.map +1 -1
  82. package/dist/fields/encrypted/components/WriteOnlyActions.js +65 -0
  83. package/dist/fields/encrypted/components/WriteOnlyActions.js.map +1 -0
  84. package/dist/fields/encrypted/components/WriteOnlyField.js +286 -0
  85. package/dist/fields/encrypted/components/WriteOnlyField.js.map +1 -0
  86. package/dist/fields/encrypted/components/writeOnlyIntent.js +69 -0
  87. package/dist/fields/encrypted/components/writeOnlyIntent.js.map +1 -0
  88. package/dist/fields/encrypted/crypto/wire.d.ts +10 -1
  89. package/dist/fields/encrypted/crypto/wire.js +1 -1
  90. package/dist/fields/encrypted/encryptedField.js +63 -6
  91. package/dist/fields/encrypted/encryptedField.js.map +1 -1
  92. package/dist/fields/encrypted/generateSecret.d.ts +10 -0
  93. package/dist/fields/encrypted/generateSecret.js +41 -0
  94. package/dist/fields/encrypted/generateSecret.js.map +1 -0
  95. package/dist/fields/encrypted/hint.js +67 -0
  96. package/dist/fields/encrypted/hint.js.map +1 -0
  97. package/dist/fields/encrypted/hooks.js +59 -31
  98. package/dist/fields/encrypted/hooks.js.map +1 -1
  99. package/dist/fields/encrypted/queryRewrite.d.ts +10 -2
  100. package/dist/fields/encrypted/queryRewrite.js +34 -8
  101. package/dist/fields/encrypted/queryRewrite.js.map +1 -1
  102. package/dist/fields/encrypted/rawRead.d.ts +24 -0
  103. package/dist/fields/encrypted/rawRead.js +40 -0
  104. package/dist/fields/encrypted/rawRead.js.map +1 -0
  105. package/dist/fields/encrypted/scan.js +21 -4
  106. package/dist/fields/encrypted/scan.js.map +1 -1
  107. package/dist/fields/encrypted/types.d.ts +67 -2
  108. package/dist/fields/encrypted/types.js +8 -1
  109. package/dist/fields/encrypted/types.js.map +1 -1
  110. package/dist/fields/encrypted/utils/decryptAllData.js +2 -2
  111. package/dist/fields/encrypted/utils/decryptAllData.js.map +1 -1
  112. package/dist/fields/encrypted/utils/decryptFieldValue.d.ts +30 -0
  113. package/dist/fields/encrypted/utils/decryptFieldValue.js +56 -0
  114. package/dist/fields/encrypted/utils/decryptFieldValue.js.map +1 -0
  115. package/dist/fields/encrypted/utils/readEncryptedField.d.ts +51 -0
  116. package/dist/fields/encrypted/utils/readEncryptedField.js +96 -0
  117. package/dist/fields/encrypted/utils/readEncryptedField.js.map +1 -0
  118. package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -1
  119. package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -1
  120. package/dist/fields/icon/adapters/radix/adapter.js +7 -0
  121. package/dist/fields/icon/adapters/radix/adapter.js.map +1 -1
  122. package/dist/fields/icon/adapters/radix/client.d.ts +3 -2
  123. package/dist/fields/icon/adapters/radix/client.js +3 -2
  124. package/dist/fields/icon/adapters/radix/client.js.map +1 -1
  125. package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -1
  126. package/dist/fields/icon/adapters/radix/generated/nodes.js +3625 -0
  127. package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -0
  128. package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -1
  129. package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
  130. package/dist/fields/icon/client/DrawerGlyph.js +34 -17
  131. package/dist/fields/icon/client/DrawerGlyph.js.map +1 -1
  132. package/dist/fields/icon/client/IconDrawerContent.js +9 -45
  133. package/dist/fields/icon/client/IconDrawerContent.js.map +1 -1
  134. package/dist/fields/icon/client/IconFieldClient.d.ts +7 -0
  135. package/dist/fields/icon/client/IconFieldClient.js +15 -7
  136. package/dist/fields/icon/client/IconFieldClient.js.map +1 -1
  137. package/dist/fields/icon/client/IconGridCell.js +67 -0
  138. package/dist/fields/icon/client/IconGridCell.js.map +1 -0
  139. package/dist/fields/icon/client/icon-field.css +12 -2
  140. package/dist/fields/icon/codegen/emit.js +5 -4
  141. package/dist/fields/icon/codegen/emit.js.map +1 -1
  142. package/dist/fields/icon/codegen/generate.js +32 -6
  143. package/dist/fields/icon/codegen/generate.js.map +1 -1
  144. package/dist/fields/icon/layers/coalesce.js +41 -0
  145. package/dist/fields/icon/layers/coalesce.js.map +1 -0
  146. package/dist/fields/icon/layers/manifestCache.d.ts +6 -0
  147. package/dist/fields/icon/layers/manifestCache.js +49 -0
  148. package/dist/fields/icon/layers/manifestCache.js.map +1 -0
  149. package/dist/fields/icon/layers/resolve.d.ts +20 -0
  150. package/dist/fields/icon/layers/resolve.js +63 -0
  151. package/dist/fields/icon/layers/resolve.js.map +1 -0
  152. package/dist/fields/icon/layers/upload.d.ts +52 -0
  153. package/dist/fields/icon/layers/upload.js +116 -0
  154. package/dist/fields/icon/layers/upload.js.map +1 -0
  155. package/dist/fields/icon/plugin.js +24 -0
  156. package/dist/fields/icon/plugin.js.map +1 -1
  157. package/dist/fields/icon/react/createIcon.d.ts +5 -0
  158. package/dist/fields/icon/react/createIcon.js +22 -4
  159. package/dist/fields/icon/react/createIcon.js.map +1 -1
  160. package/dist/fields/icon/react/createRscIcon.js +22 -1
  161. package/dist/fields/icon/react/createRscIcon.js.map +1 -1
  162. package/dist/fields/icon/react/resolveRendered.js +21 -0
  163. package/dist/fields/icon/react/resolveRendered.js.map +1 -0
  164. package/dist/fields/icon/react/types.d.ts +15 -1
  165. package/dist/fields/icon/rsc/IconCell.d.ts +2 -2
  166. package/dist/fields/icon/rsc/IconCell.js +12 -5
  167. package/dist/fields/icon/rsc/IconCell.js.map +1 -1
  168. package/dist/fields/icon/rsc/IconFieldServer.js +16 -2
  169. package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -1
  170. package/dist/fields/icon/rsc/IconLibrarySelectServer.js +1 -1
  171. package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -1
  172. package/dist/fields/icon/server/endpoint.d.ts +12 -0
  173. package/dist/fields/icon/server/endpoint.js +52 -0
  174. package/dist/fields/icon/server/endpoint.js.map +1 -0
  175. package/dist/fields/icon/server/manifestCache.js +9 -4
  176. package/dist/fields/icon/server/manifestCache.js.map +1 -1
  177. package/dist/fields/icon/server/resolveIconMeta.js +31 -0
  178. package/dist/fields/icon/server/resolveIconMeta.js.map +1 -0
  179. package/dist/fields/icon/server/validate.js +5 -2
  180. package/dist/fields/icon/server/validate.js.map +1 -1
  181. package/dist/fields/icon/shared/adapterComponents.d.ts +3 -2
  182. package/dist/fields/icon/shared/iconLabel.js +26 -0
  183. package/dist/fields/icon/shared/iconLabel.js.map +1 -0
  184. package/dist/fields/measurement/client/MeasurementCell.d.ts +18 -0
  185. package/dist/fields/measurement/client/MeasurementCell.js +47 -0
  186. package/dist/fields/measurement/client/MeasurementCell.js.map +1 -0
  187. package/dist/fields/measurement/client/MeasurementField.d.ts +13 -0
  188. package/dist/fields/measurement/client/MeasurementField.js +70 -0
  189. package/dist/fields/measurement/client/MeasurementField.js.map +1 -0
  190. package/dist/fields/measurement/client/MeasurementInput.d.ts +42 -0
  191. package/dist/fields/measurement/client/MeasurementInput.js +327 -0
  192. package/dist/fields/measurement/client/MeasurementInput.js.map +1 -0
  193. package/dist/fields/measurement/client/MeasurementUnitsProvider.d.ts +24 -0
  194. package/dist/fields/measurement/client/MeasurementUnitsProvider.js +61 -0
  195. package/dist/fields/measurement/client/MeasurementUnitsProvider.js.map +1 -0
  196. package/dist/fields/measurement/client/editModel.js +124 -0
  197. package/dist/fields/measurement/client/editModel.js.map +1 -0
  198. package/dist/fields/measurement/client/measurementCell.css +4 -0
  199. package/dist/fields/measurement/client/measurementField.css +215 -0
  200. package/dist/fields/measurement/client/useMeasurementModel.d.ts +19 -0
  201. package/dist/fields/measurement/client/useMeasurementModel.js +85 -0
  202. package/dist/fields/measurement/client/useMeasurementModel.js.map +1 -0
  203. package/dist/fields/measurement/engine/convert.d.ts +8 -0
  204. package/dist/fields/measurement/engine/convert.js +21 -0
  205. package/dist/fields/measurement/engine/convert.js.map +1 -0
  206. package/dist/fields/measurement/engine/format.d.ts +37 -0
  207. package/dist/fields/measurement/engine/format.js +156 -0
  208. package/dist/fields/measurement/engine/format.js.map +1 -0
  209. package/dist/fields/measurement/engine/locale.d.ts +25 -0
  210. package/dist/fields/measurement/engine/locale.js +79 -0
  211. package/dist/fields/measurement/engine/locale.js.map +1 -0
  212. package/dist/fields/measurement/engine/precision.d.ts +34 -0
  213. package/dist/fields/measurement/engine/precision.js +63 -0
  214. package/dist/fields/measurement/engine/precision.js.map +1 -0
  215. package/dist/fields/measurement/engine/registry.d.ts +55 -0
  216. package/dist/fields/measurement/engine/registry.js +117 -0
  217. package/dist/fields/measurement/engine/registry.js.map +1 -0
  218. package/dist/fields/measurement/engine/units.d.ts +178 -0
  219. package/dist/fields/measurement/engine/units.js +198 -0
  220. package/dist/fields/measurement/engine/units.js.map +1 -0
  221. package/dist/fields/measurement/measurementField.d.ts +17 -0
  222. package/dist/fields/measurement/measurementField.js +139 -0
  223. package/dist/fields/measurement/measurementField.js.map +1 -0
  224. package/dist/fields/measurement/options.d.ts +76 -0
  225. package/dist/fields/measurement/options.js +9 -0
  226. package/dist/fields/measurement/options.js.map +1 -0
  227. package/dist/fields/measurement/presets.d.ts +117 -0
  228. package/dist/fields/measurement/presets.js +136 -0
  229. package/dist/fields/measurement/presets.js.map +1 -0
  230. package/dist/fields/measurement/server/MeasurementCellServer.d.ts +21 -0
  231. package/dist/fields/measurement/server/MeasurementCellServer.js +53 -0
  232. package/dist/fields/measurement/server/MeasurementCellServer.js.map +1 -0
  233. package/dist/fields/measurement/server/MeasurementFieldServer.d.ts +16 -0
  234. package/dist/fields/measurement/server/MeasurementFieldServer.js +45 -0
  235. package/dist/fields/measurement/server/MeasurementFieldServer.js.map +1 -0
  236. package/dist/fields/measurement/server/getUserUnits.js +39 -0
  237. package/dist/fields/measurement/server/getUserUnits.js.map +1 -0
  238. package/dist/fields/measurement/server/resolvePrecisionSafe.js +24 -0
  239. package/dist/fields/measurement/server/resolvePrecisionSafe.js.map +1 -0
  240. package/dist/fields/measurement/server/resolveRegistryDefault.js +26 -0
  241. package/dist/fields/measurement/server/resolveRegistryDefault.js.map +1 -0
  242. package/dist/fields/phoneNumber/client/CountryFlag.d.ts +16 -0
  243. package/dist/fields/phoneNumber/client/CountryFlag.js +40 -0
  244. package/dist/fields/phoneNumber/client/CountryFlag.js.map +1 -0
  245. package/dist/fields/phoneNumber/client/CountryPicker.d.ts +21 -0
  246. package/dist/fields/phoneNumber/client/CountryPicker.js +255 -0
  247. package/dist/fields/phoneNumber/client/CountryPicker.js.map +1 -0
  248. package/dist/fields/phoneNumber/client/PhoneNumberField.d.ts +26 -0
  249. package/dist/fields/phoneNumber/client/PhoneNumberField.js +318 -0
  250. package/dist/fields/phoneNumber/client/PhoneNumberField.js.map +1 -0
  251. package/dist/fields/phoneNumber/client/editModel.js +86 -0
  252. package/dist/fields/phoneNumber/client/editModel.js.map +1 -0
  253. package/dist/fields/phoneNumber/client/phoneNumberField.css +305 -0
  254. package/dist/fields/phoneNumber/engine/countries.d.ts +36 -0
  255. package/dist/fields/phoneNumber/engine/countries.js +68 -0
  256. package/dist/fields/phoneNumber/engine/countries.js.map +1 -0
  257. package/dist/fields/phoneNumber/engine/draft.d.ts +13 -0
  258. package/dist/fields/phoneNumber/engine/draft.js +72 -0
  259. package/dist/fields/phoneNumber/engine/draft.js.map +1 -0
  260. package/dist/fields/phoneNumber/engine/metadata.d.ts +11 -0
  261. package/dist/fields/phoneNumber/engine/metadata.js +32 -0
  262. package/dist/fields/phoneNumber/engine/metadata.js.map +1 -0
  263. package/dist/fields/phoneNumber/engine/phone.d.ts +37 -0
  264. package/dist/fields/phoneNumber/engine/phone.js +59 -0
  265. package/dist/fields/phoneNumber/engine/phone.js.map +1 -0
  266. package/dist/fields/phoneNumber/options.d.ts +72 -0
  267. package/dist/fields/phoneNumber/options.js +37 -0
  268. package/dist/fields/phoneNumber/options.js.map +1 -0
  269. package/dist/fields/phoneNumber/phoneNumberField.d.ts +14 -0
  270. package/dist/fields/phoneNumber/phoneNumberField.js +167 -0
  271. package/dist/fields/phoneNumber/phoneNumberField.js.map +1 -0
  272. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.d.ts +19 -0
  273. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js +73 -0
  274. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js.map +1 -0
  275. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.d.ts +16 -0
  276. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js +57 -0
  277. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js.map +1 -0
  278. package/dist/fields/phoneNumber/server/flagsEndpoint.js +51 -0
  279. package/dist/fields/phoneNumber/server/flagsEndpoint.js.map +1 -0
  280. package/dist/fields/phoneNumber/server/readPhoneOptions.js +18 -0
  281. package/dist/fields/phoneNumber/server/readPhoneOptions.js.map +1 -0
  282. package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js +33 -0
  283. package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js.map +1 -0
  284. package/dist/index.d.ts +5 -3
  285. package/dist/index.js +35 -1
  286. package/dist/index.js.map +1 -1
  287. package/dist/translations/ar.js +62 -0
  288. package/dist/translations/ar.js.map +1 -0
  289. package/dist/translations/de.js +19 -1
  290. package/dist/translations/de.js.map +1 -1
  291. package/dist/translations/en.js +19 -1
  292. package/dist/translations/en.js.map +1 -1
  293. package/dist/translations/es.js +62 -0
  294. package/dist/translations/es.js.map +1 -0
  295. package/dist/translations/fr.js +62 -0
  296. package/dist/translations/fr.js.map +1 -0
  297. package/dist/translations/id.js +62 -0
  298. package/dist/translations/id.js.map +1 -0
  299. package/dist/translations/index.d.ts +10 -1
  300. package/dist/translations/index.js +19 -1
  301. package/dist/translations/index.js.map +1 -1
  302. package/dist/translations/keys.d.ts +19 -1
  303. package/dist/translations/keys.js +20 -2
  304. package/dist/translations/keys.js.map +1 -1
  305. package/dist/translations/ko.js +62 -0
  306. package/dist/translations/ko.js.map +1 -0
  307. package/dist/translations/pt.js +62 -0
  308. package/dist/translations/pt.js.map +1 -0
  309. package/dist/translations/ru.js +62 -0
  310. package/dist/translations/ru.js.map +1 -0
  311. package/dist/translations/uk.js +62 -0
  312. package/dist/translations/uk.js.map +1 -0
  313. package/dist/translations/zh.js +62 -0
  314. package/dist/translations/zh.js.map +1 -0
  315. package/dist/types.d.ts +165 -8
  316. package/dist/utils/resolveStaticLabel.js +13 -0
  317. package/dist/utils/resolveStaticLabel.js.map +1 -0
  318. package/package.json +31 -7
  319. package/dist/fields/icon/rsc/resolveStaticLabel.js +0 -16
  320. package/dist/fields/icon/rsc/resolveStaticLabel.js.map +0 -1
@@ -0,0 +1,156 @@
1
+ import { COMPOUNDS, UNITS, isCompoundUnit, precisionFor } from "./units.js";
2
+ import { convert, roundTo } from "./convert.js";
3
+ //#region src/fields/measurement/engine/format.ts
4
+ /**
5
+ * Splits a stored scalar into compound major/minor parts. The minor is rounded
6
+ * to its display precision BEFORE deriving the major so 5 ft 11.996 in carries
7
+ * to 6 ft 0 in rather than printing an impossible 5 ft 12 in.
8
+ */
9
+ const decompose = (value, from, compound, minorDigits) => {
10
+ const def = COMPOUNDS[compound];
11
+ const digits = minorDigits ?? precisionFor(compound);
12
+ const sign = value < 0 ? -1 : 1;
13
+ const totalMinor = roundTo(Math.abs(convert(value, from, def.minor)), digits);
14
+ const major = Math.floor(totalMinor / def.ratio);
15
+ const minor = roundTo(totalMinor - major * def.ratio, digits);
16
+ return {
17
+ major: sign * major + 0,
18
+ minor: sign * minor + 0
19
+ };
20
+ };
21
+ const compose = (parts, compound, to) => {
22
+ const def = COMPOUNDS[compound];
23
+ return convert(parts.major * def.ratio + parts.minor, def.minor, to);
24
+ };
25
+ /**
26
+ * Resolves a possibly-localized label: exact locale match, then the language prefix
27
+ * (de for de-AT), then the 'en' entry, then whichever value comes first, so a partial
28
+ * map never renders blank. A plain string passes through unchanged.
29
+ */
30
+ const resolveLocalizedLabel = (label, locale) => {
31
+ if (typeof label === "string") return label;
32
+ const exact = label[locale];
33
+ if (exact !== void 0) return exact;
34
+ const [prefix] = locale.split("-");
35
+ const byPrefix = prefix ? label[prefix] : void 0;
36
+ if (byPrefix !== void 0) return byPrefix;
37
+ if (label.en !== void 0) return label.en;
38
+ return Object.values(label)[0] ?? "";
39
+ };
40
+ /**
41
+ * Formatters are pure functions of locale + options, so every call site sharing a
42
+ * combination reuses one instance instead of paying Intl construction per call: list
43
+ * views can format hundreds of cells per render. Capped and cleared wholesale on
44
+ * overflow rather than tracking LRU order, since a repo's locale/unit/digit combinations
45
+ * are small and bounded in practice.
46
+ */
47
+ const MAX_FORMATTER_CACHE_SIZE = 200;
48
+ const numberFormatCache = /* @__PURE__ */ new Map();
49
+ const listFormatCache = /* @__PURE__ */ new Map();
50
+ const getNumberFormatter = (locale, options) => {
51
+ const key = `${locale}|${options.style ?? ""}|${options.unit ?? ""}|${options.unitDisplay ?? ""}|${options.maximumFractionDigits ?? ""}`;
52
+ const cached = numberFormatCache.get(key);
53
+ if (cached) return cached;
54
+ if (numberFormatCache.size >= MAX_FORMATTER_CACHE_SIZE) numberFormatCache.clear();
55
+ const formatter = new Intl.NumberFormat(locale, options);
56
+ numberFormatCache.set(key, formatter);
57
+ return formatter;
58
+ };
59
+ const getListFormatter = (locale, style) => {
60
+ const key = `${locale}|${style}`;
61
+ const cached = listFormatCache.get(key);
62
+ if (cached) return cached;
63
+ if (listFormatCache.size >= MAX_FORMATTER_CACHE_SIZE) listFormatCache.clear();
64
+ const formatter = new Intl.ListFormat(locale, {
65
+ style,
66
+ type: "unit"
67
+ });
68
+ listFormatCache.set(key, formatter);
69
+ return formatter;
70
+ };
71
+ const scalarFormatter = (unit, locale, digits, unitDisplay) => getNumberFormatter(locale, {
72
+ maximumFractionDigits: digits,
73
+ style: "unit",
74
+ unit: UNITS[unit].intlUnit,
75
+ unitDisplay
76
+ });
77
+ /** intlUnit null means the unit has no ECMA-402 identifier: fall back to plain decimal + shortLabel. */
78
+ const formatScalarValue = (value, opts) => {
79
+ const { digits, locale, unit, unitDisplay } = opts;
80
+ if (unit.intlUnit === null) {
81
+ const label = resolveLocalizedLabel(unit.shortLabel, locale);
82
+ return `${getNumberFormatter(locale, { maximumFractionDigits: digits }).format(value)} ${label}`;
83
+ }
84
+ return getNumberFormatter(locale, {
85
+ maximumFractionDigits: digits,
86
+ style: "unit",
87
+ unit: unit.intlUnit,
88
+ unitDisplay
89
+ }).format(value);
90
+ };
91
+ const joinParts = (parts, locale) => {
92
+ try {
93
+ return getListFormatter(locale, "narrow").format(parts);
94
+ } catch {
95
+ return parts.join(" ");
96
+ }
97
+ };
98
+ const formatMeasurement = (value, opts) => {
99
+ const { displayUnit, locale, precision, storageUnit, unitDisplay = "short" } = opts;
100
+ if (isCompoundUnit(displayUnit)) {
101
+ const def = COMPOUNDS[displayUnit];
102
+ const { major, minor } = decompose(value, storageUnit, displayUnit, precisionFor(displayUnit, precision));
103
+ return joinParts([scalarFormatter(def.major, locale, 0, unitDisplay).format(major), scalarFormatter(def.minor, locale, precisionFor(displayUnit, precision), unitDisplay).format(minor)], locale);
104
+ }
105
+ const digits = precisionFor(displayUnit, precision);
106
+ return formatScalarValue(roundTo(convert(value, storageUnit, displayUnit), digits), {
107
+ digits,
108
+ locale,
109
+ unit: UNITS[displayUnit],
110
+ unitDisplay
111
+ });
112
+ };
113
+ /** Fallback label when intlUnit is null or extraction fails: longLabel if given, else shortLabel. */
114
+ const staticLabelFor = (unit, locale) => resolveLocalizedLabel(unit.longLabel ?? unit.shortLabel, locale);
115
+ /** intlUnit null means the unit has no ECMA-402 identifier: fall back to the resolved label. */
116
+ const scalarLongLabelFor = (unit, locale) => {
117
+ if (unit.intlUnit === null) return staticLabelFor(unit, locale);
118
+ return getNumberFormatter(locale, {
119
+ style: "unit",
120
+ unit: unit.intlUnit,
121
+ unitDisplay: "long"
122
+ }).formatToParts(2).find((part) => part.type === "unit")?.value ?? staticLabelFor(unit, locale);
123
+ };
124
+ /**
125
+ * Same technique as scalarLongLabelFor but unitDisplay 'short': formatToParts(2) is only
126
+ * used for extraction, the unit part alone is the label, nothing else is stripped from it.
127
+ */
128
+ const scalarShortLabelFor = (unit, locale) => {
129
+ if (unit.intlUnit === null) return resolveLocalizedLabel(unit.shortLabel, locale);
130
+ return getNumberFormatter(locale, {
131
+ style: "unit",
132
+ unit: unit.intlUnit,
133
+ unitDisplay: "short"
134
+ }).formatToParts(2).find((part) => part.type === "unit")?.value ?? resolveLocalizedLabel(unit.shortLabel, locale);
135
+ };
136
+ const scalarLongLabel = (unit, locale) => scalarLongLabelFor(UNITS[unit], locale);
137
+ const scalarShortLabel = (unit, locale) => scalarShortLabelFor(UNITS[unit], locale);
138
+ /** Picker label for a unit. Both styles come from Intl so they localize for free. */
139
+ const unitLabel = (unit, locale, style) => {
140
+ if (isCompoundUnit(unit)) {
141
+ const def = COMPOUNDS[unit];
142
+ if (style === "short") return `${scalarShortLabel(def.major, locale)} ${scalarShortLabel(def.minor, locale)}`;
143
+ const major = scalarLongLabel(def.major, locale);
144
+ const minor = scalarLongLabel(def.minor, locale);
145
+ try {
146
+ return getListFormatter(locale, "long").format([major, minor]);
147
+ } catch {
148
+ return `${major} ${minor}`;
149
+ }
150
+ }
151
+ return style === "short" ? scalarShortLabel(unit, locale) : scalarLongLabel(unit, locale);
152
+ };
153
+ //#endregion
154
+ export { compose, decompose, formatMeasurement, formatScalarValue, resolveLocalizedLabel, scalarLongLabelFor, scalarShortLabelFor, unitLabel };
155
+
156
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","names":[],"sources":["../../../../src/fields/measurement/engine/format.ts"],"sourcesContent":["import { convert, roundTo } from './convert'\nimport {\n\tCOMPOUNDS,\n\ttype CompoundUnitId,\n\tisCompoundUnit,\n\tprecisionFor,\n\ttype ScalarUnitId,\n\tUNITS,\n\ttype UnitId,\n} from './units'\n\nexport type FormatMeasurementOptions = {\n\tstorageUnit: ScalarUnitId\n\tdisplayUnit: UnitId\n\tlocale: string\n\tunitDisplay?: 'long' | 'narrow' | 'short'\n\tprecision?: Partial<Record<UnitId, number>>\n}\n\n/**\n * Splits a stored scalar into compound major/minor parts. The minor is rounded\n * to its display precision BEFORE deriving the major so 5 ft 11.996 in carries\n * to 6 ft 0 in rather than printing an impossible 5 ft 12 in.\n */\n// biome-ignore lint/complexity/useMaxParams: designed interface for measurement decomposition\nexport const decompose = (\n\tvalue: number,\n\tfrom: ScalarUnitId,\n\tcompound: CompoundUnitId,\n\tminorDigits?: number\n): { major: number; minor: number } => {\n\tconst def = COMPOUNDS[compound]\n\tconst digits = minorDigits ?? precisionFor(compound)\n\tconst sign = value < 0 ? -1 : 1\n\tconst totalMinor = roundTo(Math.abs(convert(value, from, def.minor)), digits)\n\tconst major = Math.floor(totalMinor / def.ratio)\n\tconst minor = roundTo(totalMinor - major * def.ratio, digits)\n\treturn { major: sign * major + 0, minor: sign * minor + 0 }\n}\n\nexport const compose = (\n\tparts: { major: number; minor: number },\n\tcompound: CompoundUnitId,\n\tto: ScalarUnitId\n): number => {\n\tconst def = COMPOUNDS[compound]\n\treturn convert(parts.major * def.ratio + parts.minor, def.minor, to)\n}\n\n/** A label that may vary by locale: an exact string, or a map resolved via resolveLocalizedLabel. */\nexport type LocalizedLabel = string | Partial<Record<string, string>>\n\n/**\n * Resolves a possibly-localized label: exact locale match, then the language prefix\n * (de for de-AT), then the 'en' entry, then whichever value comes first, so a partial\n * map never renders blank. A plain string passes through unchanged.\n */\nexport const resolveLocalizedLabel = (label: LocalizedLabel, locale: string): string => {\n\tif (typeof label === 'string') return label\n\tconst exact = label[locale]\n\tif (exact !== undefined) return exact\n\tconst [prefix] = locale.split('-')\n\tconst byPrefix = prefix ? label[prefix] : undefined\n\tif (byPrefix !== undefined) return byPrefix\n\tif (label.en !== undefined) return label.en\n\treturn Object.values(label)[0] ?? ''\n}\n\n/**\n * Formatters are pure functions of locale + options, so every call site sharing a\n * combination reuses one instance instead of paying Intl construction per call: list\n * views can format hundreds of cells per render. Capped and cleared wholesale on\n * overflow rather than tracking LRU order, since a repo's locale/unit/digit combinations\n * are small and bounded in practice.\n */\nconst MAX_FORMATTER_CACHE_SIZE = 200\nconst numberFormatCache = new Map<string, Intl.NumberFormat>()\nconst listFormatCache = new Map<string, Intl.ListFormat>()\n\nconst getNumberFormatter = (\n\tlocale: string,\n\toptions: Intl.NumberFormatOptions\n): Intl.NumberFormat => {\n\tconst key = `${locale}|${options.style ?? ''}|${options.unit ?? ''}|${options.unitDisplay ?? ''}|${options.maximumFractionDigits ?? ''}`\n\tconst cached = numberFormatCache.get(key)\n\tif (cached) return cached\n\tif (numberFormatCache.size >= MAX_FORMATTER_CACHE_SIZE) numberFormatCache.clear()\n\tconst formatter = new Intl.NumberFormat(locale, options)\n\tnumberFormatCache.set(key, formatter)\n\treturn formatter\n}\n\nconst getListFormatter = (locale: string, style: 'long' | 'narrow'): Intl.ListFormat => {\n\tconst key = `${locale}|${style}`\n\tconst cached = listFormatCache.get(key)\n\tif (cached) return cached\n\tif (listFormatCache.size >= MAX_FORMATTER_CACHE_SIZE) listFormatCache.clear()\n\tconst formatter = new Intl.ListFormat(locale, { style, type: 'unit' })\n\tlistFormatCache.set(key, formatter)\n\treturn formatter\n}\n\n// biome-ignore lint/complexity/useMaxParams: Intl.NumberFormat options require locale and formatting parameters\nconst scalarFormatter = (\n\tunit: ScalarUnitId,\n\tlocale: string,\n\tdigits: number,\n\tunitDisplay: 'long' | 'narrow' | 'short'\n): Intl.NumberFormat =>\n\tgetNumberFormatter(locale, {\n\t\tmaximumFractionDigits: digits,\n\t\tstyle: 'unit',\n\t\tunit: UNITS[unit].intlUnit,\n\t\tunitDisplay,\n\t})\n\n/** Minimal shape formatting needs, so createEngine can format custom units alongside built-ins. */\nexport type FormattableUnit = {\n\tintlUnit: string | null\n\tshortLabel: LocalizedLabel\n\tlongLabel?: LocalizedLabel\n}\n\nexport type ScalarFormatOptions = {\n\tunit: FormattableUnit\n\tlocale: string\n\tdigits: number\n\tunitDisplay: 'long' | 'narrow' | 'short'\n}\n\n/** intlUnit null means the unit has no ECMA-402 identifier: fall back to plain decimal + shortLabel. */\nexport const formatScalarValue = (value: number, opts: ScalarFormatOptions): string => {\n\tconst { digits, locale, unit, unitDisplay } = opts\n\tif (unit.intlUnit === null) {\n\t\tconst label = resolveLocalizedLabel(unit.shortLabel, locale)\n\t\treturn `${getNumberFormatter(locale, { maximumFractionDigits: digits }).format(value)} ${label}`\n\t}\n\treturn getNumberFormatter(locale, {\n\t\tmaximumFractionDigits: digits,\n\t\tstyle: 'unit',\n\t\tunit: unit.intlUnit,\n\t\tunitDisplay,\n\t}).format(value)\n}\n\nconst joinParts = (parts: string[], locale: string): string => {\n\ttry {\n\t\treturn getListFormatter(locale, 'narrow').format(parts)\n\t} catch {\n\t\treturn parts.join(' ')\n\t}\n}\n\nexport const formatMeasurement = (value: number, opts: FormatMeasurementOptions): string => {\n\tconst { displayUnit, locale, precision, storageUnit, unitDisplay = 'short' } = opts\n\tif (isCompoundUnit(displayUnit)) {\n\t\tconst def = COMPOUNDS[displayUnit]\n\t\tconst { major, minor } = decompose(\n\t\t\tvalue,\n\t\t\tstorageUnit,\n\t\t\tdisplayUnit,\n\t\t\tprecisionFor(displayUnit, precision)\n\t\t)\n\t\tconst majorText = scalarFormatter(def.major, locale, 0, unitDisplay).format(major)\n\t\tconst minorText = scalarFormatter(\n\t\t\tdef.minor,\n\t\t\tlocale,\n\t\t\tprecisionFor(displayUnit, precision),\n\t\t\tunitDisplay\n\t\t).format(minor)\n\t\treturn joinParts([majorText, minorText], locale)\n\t}\n\tconst digits = precisionFor(displayUnit, precision)\n\treturn formatScalarValue(roundTo(convert(value, storageUnit, displayUnit), digits), {\n\t\tdigits,\n\t\tlocale,\n\t\tunit: UNITS[displayUnit],\n\t\tunitDisplay,\n\t})\n}\n\n/** Fallback label when intlUnit is null or extraction fails: longLabel if given, else shortLabel. */\nconst staticLabelFor = (unit: FormattableUnit, locale: string): string =>\n\tresolveLocalizedLabel(unit.longLabel ?? unit.shortLabel, locale)\n\n/** intlUnit null means the unit has no ECMA-402 identifier: fall back to the resolved label. */\nexport const scalarLongLabelFor = (unit: FormattableUnit, locale: string): string => {\n\tif (unit.intlUnit === null) return staticLabelFor(unit, locale)\n\tconst parts = getNumberFormatter(locale, {\n\t\tstyle: 'unit',\n\t\tunit: unit.intlUnit,\n\t\tunitDisplay: 'long',\n\t}).formatToParts(2)\n\tconst unitPart = parts.find((part) => part.type === 'unit')\n\treturn unitPart?.value ?? staticLabelFor(unit, locale)\n}\n\n/**\n * Same technique as scalarLongLabelFor but unitDisplay 'short': formatToParts(2) is only\n * used for extraction, the unit part alone is the label, nothing else is stripped from it.\n */\nexport const scalarShortLabelFor = (unit: FormattableUnit, locale: string): string => {\n\tif (unit.intlUnit === null) return resolveLocalizedLabel(unit.shortLabel, locale)\n\tconst parts = getNumberFormatter(locale, {\n\t\tstyle: 'unit',\n\t\tunit: unit.intlUnit,\n\t\tunitDisplay: 'short',\n\t}).formatToParts(2)\n\tconst unitPart = parts.find((part) => part.type === 'unit')\n\treturn unitPart?.value ?? resolveLocalizedLabel(unit.shortLabel, locale)\n}\n\nconst scalarLongLabel = (unit: ScalarUnitId, locale: string): string =>\n\tscalarLongLabelFor(UNITS[unit], locale)\n\nconst scalarShortLabel = (unit: ScalarUnitId, locale: string): string =>\n\tscalarShortLabelFor(UNITS[unit], locale)\n\n/** Picker label for a unit. Both styles come from Intl so they localize for free. */\nexport const unitLabel = (unit: UnitId, locale: string, style: 'long' | 'short'): string => {\n\tif (isCompoundUnit(unit)) {\n\t\tconst def = COMPOUNDS[unit]\n\t\tif (style === 'short')\n\t\t\treturn `${scalarShortLabel(def.major, locale)} ${scalarShortLabel(def.minor, locale)}`\n\t\tconst major = scalarLongLabel(def.major, locale)\n\t\tconst minor = scalarLongLabel(def.minor, locale)\n\t\ttry {\n\t\t\treturn getListFormatter(locale, 'long').format([major, minor])\n\t\t} catch {\n\t\t\treturn `${major} ${minor}`\n\t\t}\n\t}\n\treturn style === 'short' ? scalarShortLabel(unit, locale) : scalarLongLabel(unit, locale)\n}\n"],"mappings":";;;;;;;;AAyBA,MAAa,aACZ,OACA,MACA,UACA,gBACsC;CACtC,MAAM,MAAM,UAAU;CACtB,MAAM,SAAS,eAAe,aAAa,QAAQ;CACnD,MAAM,OAAO,QAAQ,IAAI,KAAK;CAC9B,MAAM,aAAa,QAAQ,KAAK,IAAI,QAAQ,OAAO,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM;CAC5E,MAAM,QAAQ,KAAK,MAAM,aAAa,IAAI,KAAK;CAC/C,MAAM,QAAQ,QAAQ,aAAa,QAAQ,IAAI,OAAO,MAAM;CAC5D,OAAO;EAAE,OAAO,OAAO,QAAQ;EAAG,OAAO,OAAO,QAAQ;CAAE;AAC3D;AAEA,MAAa,WACZ,OACA,UACA,OACY;CACZ,MAAM,MAAM,UAAU;CACtB,OAAO,QAAQ,MAAM,QAAQ,IAAI,QAAQ,MAAM,OAAO,IAAI,OAAO,EAAE;AACpE;;;;;;AAUA,MAAa,yBAAyB,OAAuB,WAA2B;CACvF,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,MAAM,QAAQ,MAAM;CACpB,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,CAAC,UAAU,OAAO,MAAM,GAAG;CACjC,MAAM,WAAW,SAAS,MAAM,UAAU,KAAA;CAC1C,IAAI,aAAa,KAAA,GAAW,OAAO;CACnC,IAAI,MAAM,OAAO,KAAA,GAAW,OAAO,MAAM;CACzC,OAAO,OAAO,OAAO,KAAK,EAAE,MAAM;AACnC;;;;;;;;AASA,MAAM,2BAA2B;AACjC,MAAM,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,CACI,EAAE,MAAM,SAAS,KAAK,SAAS,MACtC,GAAG,SAAS,sBAAsB,KAAK,YAAY,MAAM;AACxE;AAEA,MAAM,mBAAmB,MAAoB,WAC5C,mBAAmB,MAAM,OAAO,MAAM;AAEvC,MAAM,oBAAoB,MAAoB,WAC7C,oBAAoB,MAAM,OAAO,MAAM;;AAGxC,MAAa,aAAa,MAAc,QAAgB,UAAoC;CAC3F,IAAI,eAAe,IAAI,GAAG;EACzB,MAAM,MAAM,UAAU;EACtB,IAAI,UAAU,SACb,OAAO,GAAG,iBAAiB,IAAI,OAAO,MAAM,EAAE,GAAG,iBAAiB,IAAI,OAAO,MAAM;EACpF,MAAM,QAAQ,gBAAgB,IAAI,OAAO,MAAM;EAC/C,MAAM,QAAQ,gBAAgB,IAAI,OAAO,MAAM;EAC/C,IAAI;GACH,OAAO,iBAAiB,QAAQ,MAAM,EAAE,OAAO,CAAC,OAAO,KAAK,CAAC;EAC9D,QAAQ;GACP,OAAO,GAAG,MAAM,GAAG;EACpB;CACD;CACA,OAAO,UAAU,UAAU,iBAAiB,MAAM,MAAM,IAAI,gBAAgB,MAAM,MAAM;AACzF"}
@@ -0,0 +1,25 @@
1
+ import { CoreDimension, MeasurementUnitId, UnitId } from "./units.js";
2
+
3
+ //#region src/fields/measurement/engine/locale.d.ts
4
+ type MeasurementSystem = 'metric' | 'uk' | 'us';
5
+ /** Final fallback in the resolution chain: locale-system default per built-in dimension. */
6
+ declare const DIMENSION_LOCALE_DEFAULTS: Record<CoreDimension, Record<MeasurementSystem, UnitId>>;
7
+ declare const systemForLocale: (locale: string) => MeasurementSystem;
8
+ /**
9
+ * Display-unit resolution chain, in order: user preference, field fallback, plugin
10
+ * registry default, then the locale steps (field locale defaults, then the per-dimension
11
+ * table). First candidate the field actually offers wins; the field's first unit is the
12
+ * floor. Pure and admin-free so both the client field and measurement-utils can use it.
13
+ */
14
+ declare const resolveDisplayUnit: (args: {
15
+ dimension: string;
16
+ preferenceUnit?: MeasurementUnitId | null;
17
+ fallbackUnit?: MeasurementUnitId;
18
+ registryDefault?: MeasurementUnitId; /** Null until the browser locale is read post-hydration, which skips both locale steps. */
19
+ system?: MeasurementSystem | null;
20
+ localeDefaults?: Partial<Record<MeasurementSystem, MeasurementUnitId>>;
21
+ units: readonly MeasurementUnitId[];
22
+ }) => MeasurementUnitId;
23
+ //#endregion
24
+ export { DIMENSION_LOCALE_DEFAULTS, MeasurementSystem, resolveDisplayUnit, systemForLocale };
25
+ //# sourceMappingURL=locale.d.ts.map
@@ -0,0 +1,79 @@
1
+ //#region src/fields/measurement/engine/locale.ts
2
+ /** Final fallback in the resolution chain: locale-system default per built-in dimension. */
3
+ const DIMENSION_LOCALE_DEFAULTS = {
4
+ mass: {
5
+ metric: "kg",
6
+ uk: "lb",
7
+ us: "lb"
8
+ },
9
+ length: {
10
+ metric: "cm",
11
+ uk: "in",
12
+ us: "in"
13
+ },
14
+ volume: {
15
+ metric: "l",
16
+ uk: "l",
17
+ us: "fl-oz"
18
+ },
19
+ temperature: {
20
+ metric: "c",
21
+ uk: "c",
22
+ us: "f"
23
+ },
24
+ speed: {
25
+ metric: "km/h",
26
+ uk: "mph",
27
+ us: "mph"
28
+ }
29
+ };
30
+ /**
31
+ * CLDR supplemental measurementData, complete: world default metric, US system
32
+ * for US and Liberia, UK system for Great Britain and Myanmar. No shipped Intl
33
+ * API exposes this, so the five-entry table is vendored.
34
+ */
35
+ const US_REGIONS = new Set(["US", "LR"]);
36
+ const UK_REGIONS = new Set(["GB", "MM"]);
37
+ const systemForLocale = (locale) => {
38
+ let region;
39
+ try {
40
+ const parsed = new Intl.Locale(locale);
41
+ region = parsed.region ?? parsed.maximize().region;
42
+ } catch {
43
+ return "metric";
44
+ }
45
+ if (region && US_REGIONS.has(region)) return "us";
46
+ if (region && UK_REGIONS.has(region)) return "uk";
47
+ return "metric";
48
+ };
49
+ /** Widened for lookup by any field dimension, including custom dimensions the table has no entry for. */
50
+ const dimensionLocaleDefaults = DIMENSION_LOCALE_DEFAULTS;
51
+ /** Locale step of the resolution chain: field-declared defaults first, then the per-dimension table. */
52
+ const localeCandidatesFor = (args) => [args.localeDefaults?.[args.system], dimensionLocaleDefaults[args.dimension]?.[args.system]].filter((unit) => typeof unit === "string");
53
+ /**
54
+ * Display-unit resolution chain, in order: user preference, field fallback, plugin
55
+ * registry default, then the locale steps (field locale defaults, then the per-dimension
56
+ * table). First candidate the field actually offers wins; the field's first unit is the
57
+ * floor. Pure and admin-free so both the client field and measurement-utils can use it.
58
+ */
59
+ const resolveDisplayUnit = (args) => {
60
+ const localeCandidates = args.system ? localeCandidatesFor({
61
+ dimension: args.dimension,
62
+ localeDefaults: args.localeDefaults,
63
+ system: args.system
64
+ }) : [];
65
+ const candidates = [
66
+ args.preferenceUnit,
67
+ args.fallbackUnit,
68
+ args.registryDefault,
69
+ ...localeCandidates
70
+ ];
71
+ for (const candidate of candidates) if (candidate && args.units.includes(candidate)) return candidate;
72
+ const first = args.units[0];
73
+ if (!first) throw new Error("resolveDisplayUnit: empty units list");
74
+ return first;
75
+ };
76
+ //#endregion
77
+ export { DIMENSION_LOCALE_DEFAULTS, resolveDisplayUnit, systemForLocale };
78
+
79
+ //# sourceMappingURL=locale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.js","names":[],"sources":["../../../../src/fields/measurement/engine/locale.ts"],"sourcesContent":["import type { CoreDimension, MeasurementUnitId, UnitId } from './units'\n\nexport type MeasurementSystem = 'metric' | 'uk' | 'us'\n\n/** Final fallback in the resolution chain: locale-system default per built-in dimension. */\nexport const DIMENSION_LOCALE_DEFAULTS: Record<CoreDimension, Record<MeasurementSystem, UnitId>> = {\n\tmass: { metric: 'kg', uk: 'lb', us: 'lb' },\n\tlength: { metric: 'cm', uk: 'in', us: 'in' },\n\tvolume: { metric: 'l', uk: 'l', us: 'fl-oz' },\n\ttemperature: { metric: 'c', uk: 'c', us: 'f' },\n\tspeed: { metric: 'km/h', uk: 'mph', us: 'mph' },\n}\n\n/**\n * CLDR supplemental measurementData, complete: world default metric, US system\n * for US and Liberia, UK system for Great Britain and Myanmar. No shipped Intl\n * API exposes this, so the five-entry table is vendored.\n */\nconst US_REGIONS = new Set(['US', 'LR'])\nconst UK_REGIONS = new Set(['GB', 'MM'])\n\nexport const systemForLocale = (locale: string): MeasurementSystem => {\n\tlet region: string | undefined\n\ttry {\n\t\tconst parsed = new Intl.Locale(locale)\n\t\tregion = parsed.region ?? parsed.maximize().region\n\t} catch {\n\t\treturn 'metric'\n\t}\n\tif (region && US_REGIONS.has(region)) return 'us'\n\tif (region && UK_REGIONS.has(region)) return 'uk'\n\treturn 'metric'\n}\n\n/** Widened for lookup by any field dimension, including custom dimensions the table has no entry for. */\nconst dimensionLocaleDefaults: Partial<\n\tRecord<string, Record<MeasurementSystem, MeasurementUnitId>>\n> = DIMENSION_LOCALE_DEFAULTS\n\n/** Locale step of the resolution chain: field-declared defaults first, then the per-dimension table. */\nconst localeCandidatesFor = (args: {\n\tdimension: string\n\tsystem: MeasurementSystem\n\tlocaleDefaults?: Partial<Record<MeasurementSystem, MeasurementUnitId>>\n}): MeasurementUnitId[] =>\n\t[\n\t\targs.localeDefaults?.[args.system],\n\t\tdimensionLocaleDefaults[args.dimension]?.[args.system],\n\t].filter((unit): unit is MeasurementUnitId => typeof unit === 'string')\n\n/**\n * Display-unit resolution chain, in order: user preference, field fallback, plugin\n * registry default, then the locale steps (field locale defaults, then the per-dimension\n * table). First candidate the field actually offers wins; the field's first unit is the\n * floor. Pure and admin-free so both the client field and measurement-utils can use it.\n */\nexport const resolveDisplayUnit = (args: {\n\tdimension: string\n\tpreferenceUnit?: MeasurementUnitId | null\n\tfallbackUnit?: MeasurementUnitId\n\tregistryDefault?: MeasurementUnitId\n\t/** Null until the browser locale is read post-hydration, which skips both locale steps. */\n\tsystem?: MeasurementSystem | null\n\tlocaleDefaults?: Partial<Record<MeasurementSystem, MeasurementUnitId>>\n\tunits: readonly MeasurementUnitId[]\n}): MeasurementUnitId => {\n\tconst localeCandidates = args.system\n\t\t? localeCandidatesFor({\n\t\t\t\tdimension: args.dimension,\n\t\t\t\tlocaleDefaults: args.localeDefaults,\n\t\t\t\tsystem: args.system,\n\t\t\t})\n\t\t: []\n\tconst candidates = [\n\t\targs.preferenceUnit,\n\t\targs.fallbackUnit,\n\t\targs.registryDefault,\n\t\t...localeCandidates,\n\t]\n\tfor (const candidate of candidates) {\n\t\tif (candidate && args.units.includes(candidate)) return candidate\n\t}\n\tconst first = args.units[0]\n\tif (!first) throw new Error('resolveDisplayUnit: empty units list')\n\treturn first\n}\n"],"mappings":";;AAKA,MAAa,4BAAsF;CAClG,MAAM;EAAE,QAAQ;EAAM,IAAI;EAAM,IAAI;CAAK;CACzC,QAAQ;EAAE,QAAQ;EAAM,IAAI;EAAM,IAAI;CAAK;CAC3C,QAAQ;EAAE,QAAQ;EAAK,IAAI;EAAK,IAAI;CAAQ;CAC5C,aAAa;EAAE,QAAQ;EAAK,IAAI;EAAK,IAAI;CAAI;CAC7C,OAAO;EAAE,QAAQ;EAAQ,IAAI;EAAO,IAAI;CAAM;AAC/C;;;;;;AAOA,MAAM,aAAa,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC;AACvC,MAAM,aAAa,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC;AAEvC,MAAa,mBAAmB,WAAsC;CACrE,IAAI;CACJ,IAAI;EACH,MAAM,SAAS,IAAI,KAAK,OAAO,MAAM;EACrC,SAAS,OAAO,UAAU,OAAO,SAAS,EAAE;CAC7C,QAAQ;EACP,OAAO;CACR;CACA,IAAI,UAAU,WAAW,IAAI,MAAM,GAAG,OAAO;CAC7C,IAAI,UAAU,WAAW,IAAI,MAAM,GAAG,OAAO;CAC7C,OAAO;AACR;;AAGA,MAAM,0BAEF;;AAGJ,MAAM,uBAAuB,SAK5B,CACC,KAAK,iBAAiB,KAAK,SAC3B,wBAAwB,KAAK,aAAa,KAAK,OAChD,EAAE,QAAQ,SAAoC,OAAO,SAAS,QAAQ;;;;;;;AAQvE,MAAa,sBAAsB,SASV;CACxB,MAAM,mBAAmB,KAAK,SAC3B,oBAAoB;EACpB,WAAW,KAAK;EAChB,gBAAgB,KAAK;EACrB,QAAQ,KAAK;CACd,CAAC,IACA,CAAC;CACJ,MAAM,aAAa;EAClB,KAAK;EACL,KAAK;EACL,KAAK;EACL,GAAG;CACJ;CACA,KAAK,MAAM,aAAa,YACvB,IAAI,aAAa,KAAK,MAAM,SAAS,SAAS,GAAG,OAAO;CAEzD,MAAM,QAAQ,KAAK,MAAM;CACzB,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,sCAAsC;CAClE,OAAO;AACR"}
@@ -0,0 +1,34 @@
1
+ //#region src/fields/measurement/engine/precision.d.ts
2
+ type PrecisionMode = 'readable' | 'exact';
3
+ /**
4
+ * A precision layer as authored by a plugin or a field: every knob optional, so
5
+ * `resolvePrecision` can tell "not set" apart from an explicit choice while merging
6
+ * layers. `display` is unit-id keyed; a narrower per-dimension key union comes from
7
+ * the factory's option type, not from this engine-level shape.
8
+ */
9
+ type MeasurementPrecision = {
10
+ mode?: PrecisionMode; /** Fraction digits kept in the storage unit, applied to every write. */
11
+ storage?: number; /** Entry-unit typing behavior: 'quantize' rounds as you type, 'free' keeps exact input. */
12
+ entry?: 'quantize' | 'free'; /** Draft-repaint policy after a save/refresh. */
13
+ draft?: 'display' | 'faithful';
14
+ display?: Partial<Record<string, number>>;
15
+ };
16
+ /** A `MeasurementPrecision` with every knob but `display` filled in. */
17
+ type ResolvedPrecision = {
18
+ mode: PrecisionMode;
19
+ storage: number;
20
+ entry: 'quantize' | 'free';
21
+ draft: 'display' | 'faithful';
22
+ display?: Partial<Record<string, number>>;
23
+ };
24
+ /**
25
+ * Merges precision layers low-to-high priority: pass `[pluginDefault, fieldOption]`
26
+ * so a field's own choice always wins. A bare mode string expands to its preset
27
+ * (readable = quantize entry + display drafts, exact = free entry + faithful
28
+ * drafts); an explicit entry/draft/storage/display knob on any layer overrides
29
+ * whatever the final mode's preset would otherwise imply for that knob.
30
+ */
31
+ declare const resolvePrecision: (layers: Array<MeasurementPrecision | PrecisionMode | undefined>) => ResolvedPrecision;
32
+ //#endregion
33
+ export { MeasurementPrecision, PrecisionMode, ResolvedPrecision, resolvePrecision };
34
+ //# sourceMappingURL=precision.d.ts.map
@@ -0,0 +1,63 @@
1
+ import "./units.js";
2
+ //#region src/fields/measurement/engine/precision.ts
3
+ const MODE_PRESETS = {
4
+ readable: {
5
+ entry: "quantize",
6
+ draft: "display"
7
+ },
8
+ exact: {
9
+ entry: "free",
10
+ draft: "faithful"
11
+ }
12
+ };
13
+ const DEFAULT_MODE = "readable";
14
+ /**
15
+ * Merges precision layers low-to-high priority: pass `[pluginDefault, fieldOption]`
16
+ * so a field's own choice always wins. A bare mode string expands to its preset
17
+ * (readable = quantize entry + display drafts, exact = free entry + faithful
18
+ * drafts); an explicit entry/draft/storage/display knob on any layer overrides
19
+ * whatever the final mode's preset would otherwise imply for that knob.
20
+ */
21
+ const resolvePrecision = (layers) => {
22
+ let mode = DEFAULT_MODE;
23
+ let storage = 6;
24
+ let entry;
25
+ let draft;
26
+ let display;
27
+ for (const raw of layers) {
28
+ if (raw === void 0) continue;
29
+ const layer = typeof raw === "string" ? { mode: raw } : raw;
30
+ if (layer.mode !== void 0) mode = layer.mode;
31
+ if (layer.storage !== void 0) storage = layer.storage;
32
+ if (layer.entry !== void 0) entry = layer.entry;
33
+ if (layer.draft !== void 0) draft = layer.draft;
34
+ if (layer.display !== void 0) display = {
35
+ ...display,
36
+ ...layer.display
37
+ };
38
+ }
39
+ if (!Object.hasOwn(MODE_PRESETS, mode)) throw new Error(`resolvePrecision: mode "${mode}" must be "readable" or "exact"`);
40
+ if (!Number.isInteger(storage) || storage < 0 || storage > 12) throw new Error(`resolvePrecision: storage must be an integer between 0 and 12, got ${storage}`);
41
+ const preset = MODE_PRESETS[mode];
42
+ return {
43
+ mode,
44
+ storage,
45
+ entry: entry ?? preset.entry,
46
+ draft: draft ?? preset.draft,
47
+ ...display !== void 0 ? { display } : {}
48
+ };
49
+ };
50
+ /**
51
+ * Exact mode reads back at full storage fidelity instead of display digits, for
52
+ * both cells and bound messages, so the two always agree. An explicit per-unit
53
+ * override for the display unit itself still wins, since the caller asked for it
54
+ * by name; every other unit's override (if any) passes through untouched.
55
+ */
56
+ const exactModePrecisionOverride = (resolved, displayUnit) => resolved.mode === "exact" ? {
57
+ ...resolved.display,
58
+ [displayUnit]: resolved.display?.[displayUnit] ?? resolved.storage
59
+ } : resolved.display;
60
+ //#endregion
61
+ export { exactModePrecisionOverride, resolvePrecision };
62
+
63
+ //# sourceMappingURL=precision.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"precision.js","names":[],"sources":["../../../../src/fields/measurement/engine/precision.ts"],"sourcesContent":["import { STORAGE_FRACTION_DIGITS } from './units'\n\nexport type PrecisionMode = 'readable' | 'exact'\n\n/**\n * A precision layer as authored by a plugin or a field: every knob optional, so\n * `resolvePrecision` can tell \"not set\" apart from an explicit choice while merging\n * layers. `display` is unit-id keyed; a narrower per-dimension key union comes from\n * the factory's option type, not from this engine-level shape.\n */\nexport type MeasurementPrecision = {\n\tmode?: PrecisionMode\n\t/** Fraction digits kept in the storage unit, applied to every write. */\n\tstorage?: number\n\t/** Entry-unit typing behavior: 'quantize' rounds as you type, 'free' keeps exact input. */\n\tentry?: 'quantize' | 'free'\n\t/** Draft-repaint policy after a save/refresh. */\n\tdraft?: 'display' | 'faithful'\n\tdisplay?: Partial<Record<string, number>>\n}\n\n/** A `MeasurementPrecision` with every knob but `display` filled in. */\nexport type ResolvedPrecision = {\n\tmode: PrecisionMode\n\tstorage: number\n\tentry: 'quantize' | 'free'\n\tdraft: 'display' | 'faithful'\n\tdisplay?: Partial<Record<string, number>>\n}\n\nconst MODE_PRESETS: Record<PrecisionMode, Pick<ResolvedPrecision, 'draft' | 'entry'>> = {\n\treadable: { entry: 'quantize', draft: 'display' },\n\texact: { entry: 'free', draft: 'faithful' },\n}\n\nconst DEFAULT_MODE: PrecisionMode = 'readable'\n\n/**\n * Merges precision layers low-to-high priority: pass `[pluginDefault, fieldOption]`\n * so a field's own choice always wins. A bare mode string expands to its preset\n * (readable = quantize entry + display drafts, exact = free entry + faithful\n * drafts); an explicit entry/draft/storage/display knob on any layer overrides\n * whatever the final mode's preset would otherwise imply for that knob.\n */\nexport const resolvePrecision = (\n\tlayers: Array<MeasurementPrecision | PrecisionMode | undefined>\n): ResolvedPrecision => {\n\tlet mode: PrecisionMode = DEFAULT_MODE\n\tlet storage: number = STORAGE_FRACTION_DIGITS\n\tlet entry: ResolvedPrecision['entry'] | undefined\n\tlet draft: ResolvedPrecision['draft'] | undefined\n\tlet display: Partial<Record<string, number>> | undefined\n\n\tfor (const raw of layers) {\n\t\tif (raw === undefined) continue\n\t\tconst layer = typeof raw === 'string' ? { mode: raw } : raw\n\t\tif (layer.mode !== undefined) mode = layer.mode\n\t\tif (layer.storage !== undefined) storage = layer.storage\n\t\tif (layer.entry !== undefined) entry = layer.entry\n\t\tif (layer.draft !== undefined) draft = layer.draft\n\t\tif (layer.display !== undefined) display = { ...display, ...layer.display }\n\t}\n\n\tif (!Object.hasOwn(MODE_PRESETS, mode)) {\n\t\tthrow new Error(`resolvePrecision: mode \"${mode}\" must be \"readable\" or \"exact\"`)\n\t}\n\tif (!Number.isInteger(storage) || storage < 0 || storage > 12) {\n\t\tthrow new Error(`resolvePrecision: storage must be an integer between 0 and 12, got ${storage}`)\n\t}\n\n\tconst preset = MODE_PRESETS[mode]\n\treturn {\n\t\tmode,\n\t\tstorage,\n\t\tentry: entry ?? preset.entry,\n\t\tdraft: draft ?? preset.draft,\n\t\t...(display !== undefined ? { display } : {}),\n\t}\n}\n\n/**\n * Exact mode reads back at full storage fidelity instead of display digits, for\n * both cells and bound messages, so the two always agree. An explicit per-unit\n * override for the display unit itself still wins, since the caller asked for it\n * by name; every other unit's override (if any) passes through untouched.\n */\nexport const exactModePrecisionOverride = (\n\tresolved: ResolvedPrecision,\n\tdisplayUnit: string\n): Partial<Record<string, number>> | undefined =>\n\tresolved.mode === 'exact'\n\t\t? { ...resolved.display, [displayUnit]: resolved.display?.[displayUnit] ?? resolved.storage }\n\t\t: resolved.display\n"],"mappings":";;AA8BA,MAAM,eAAkF;CACvF,UAAU;EAAE,OAAO;EAAY,OAAO;CAAU;CAChD,OAAO;EAAE,OAAO;EAAQ,OAAO;CAAW;AAC3C;AAEA,MAAM,eAA8B;;;;;;;;AASpC,MAAa,oBACZ,WACuB;CACvB,IAAI,OAAsB;CAC1B,IAAI,UAAA;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CAEJ,KAAK,MAAM,OAAO,QAAQ;EACzB,IAAI,QAAQ,KAAA,GAAW;EACvB,MAAM,QAAQ,OAAO,QAAQ,WAAW,EAAE,MAAM,IAAI,IAAI;EACxD,IAAI,MAAM,SAAS,KAAA,GAAW,OAAO,MAAM;EAC3C,IAAI,MAAM,YAAY,KAAA,GAAW,UAAU,MAAM;EACjD,IAAI,MAAM,UAAU,KAAA,GAAW,QAAQ,MAAM;EAC7C,IAAI,MAAM,UAAU,KAAA,GAAW,QAAQ,MAAM;EAC7C,IAAI,MAAM,YAAY,KAAA,GAAW,UAAU;GAAE,GAAG;GAAS,GAAG,MAAM;EAAQ;CAC3E;CAEA,IAAI,CAAC,OAAO,OAAO,cAAc,IAAI,GACpC,MAAM,IAAI,MAAM,2BAA2B,KAAK,gCAAgC;CAEjF,IAAI,CAAC,OAAO,UAAU,OAAO,KAAK,UAAU,KAAK,UAAU,IAC1D,MAAM,IAAI,MAAM,sEAAsE,SAAS;CAGhG,MAAM,SAAS,aAAa;CAC5B,OAAO;EACN;EACA;EACA,OAAO,SAAS,OAAO;EACvB,OAAO,SAAS,OAAO;EACvB,GAAI,YAAY,KAAA,IAAY,EAAE,QAAQ,IAAI,CAAC;CAC5C;AACD;;;;;;;AAQA,MAAa,8BACZ,UACA,gBAEA,SAAS,SAAS,UACf;CAAE,GAAG,SAAS;EAAU,cAAc,SAAS,UAAU,gBAAgB,SAAS;AAAQ,IAC1F,SAAS"}
@@ -0,0 +1,55 @@
1
+ import { CompoundUnitId } from "./units.js";
2
+ import { LocalizedLabel } from "./format.js";
3
+
4
+ //#region src/fields/measurement/engine/registry.d.ts
5
+ type CustomUnitDef = {
6
+ dimension: string;
7
+ factor: number;
8
+ offset?: number; /** ECMA-402 unit identifier, or null when there is none: formatting falls back to plain decimal + shortLabel. */
9
+ intlUnit: string | null; /** A plain string applies to every locale; a map resolves exact locale, then language prefix, then 'en'. */
10
+ shortLabel: LocalizedLabel; /** Long-form label, same resolution as shortLabel. Defaults to shortLabel when omitted. */
11
+ longLabel?: LocalizedLabel; /** Display fraction digits for this unit. Defaults to 2 when omitted. */
12
+ precision?: number;
13
+ };
14
+ type CustomDimensionDef = {
15
+ /** Must name one of `custom.units` for this dimension, with factor 1 and no offset. */canonicalUnit: string;
16
+ };
17
+ type MeasurementCustomConfig = {
18
+ units?: Record<string, CustomUnitDef>;
19
+ dimensions?: Record<string, CustomDimensionDef>;
20
+ };
21
+ type EngineFormatMeasurementOptions = {
22
+ storageUnit: string;
23
+ displayUnit: string;
24
+ locale: string;
25
+ unitDisplay?: 'long' | 'narrow' | 'short';
26
+ precision?: Partial<Record<string, number>>;
27
+ };
28
+ /**
29
+ * Builds a measurement engine over the built-in units merged with a serializable custom
30
+ * config. Compound units (ft-in, st-lb) are always built-in: custom units are scalar-only,
31
+ * so decompose/compose run on the built-in table, bridged for a custom storage unit.
32
+ */
33
+ declare const createEngine: (custom?: MeasurementCustomConfig) => {
34
+ compose: (parts: {
35
+ major: number;
36
+ minor: number;
37
+ }, compound: CompoundUnitId, to: string) => number;
38
+ convert: (value: number, from: string, to: string) => number;
39
+ decompose: (value: number, from: string, compound: CompoundUnitId, minorDigits?: number) => {
40
+ major: number;
41
+ minor: number;
42
+ };
43
+ dimensionOf: (unit: string) => string;
44
+ formatMeasurement: (value: number, opts: EngineFormatMeasurementOptions) => string;
45
+ isCompoundUnit: (unit: string) => unit is CompoundUnitId;
46
+ isScalarUnit: (unit: string) => boolean;
47
+ precisionFor: (unit: string, overrides?: Partial<Record<string, number>>) => number;
48
+ unitLabel: (unit: string, locale: string, style: "long" | "short") => string;
49
+ unitsOfDimension: (dimension: string) => string[];
50
+ };
51
+ type MeasurementEngine = ReturnType<typeof createEngine>;
52
+ declare const defaultEngine: MeasurementEngine;
53
+ //#endregion
54
+ export { CustomDimensionDef, CustomUnitDef, EngineFormatMeasurementOptions, MeasurementCustomConfig, MeasurementEngine, createEngine, defaultEngine };
55
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1,117 @@
1
+ import { COMPOUNDS, COMPOUND_MINOR_PRECISION, DISPLAY_PRECISION, UNITS, isScalarUnit, unitsOfDimension } from "./units.js";
2
+ import { DIMENSION_LOCALE_DEFAULTS } from "./locale.js";
3
+ import { convertUnit, roundTo } from "./convert.js";
4
+ import { compose, decompose, formatMeasurement, formatScalarValue, scalarLongLabelFor, scalarShortLabelFor, unitLabel } from "./format.js";
5
+ //#region src/fields/measurement/engine/registry.ts
6
+ const CORE_DIMENSIONS = new Set(Object.keys(DIMENSION_LOCALE_DEFAULTS));
7
+ const ALLOWED_CUSTOM_CONFIG_KEYS = new Set(["units", "dimensions"]);
8
+ const isCompoundUnitId = (unit) => Object.hasOwn(COMPOUNDS, unit);
9
+ const mergeUnits = (custom) => {
10
+ if (custom !== void 0) {
11
+ for (const key of Object.keys(custom)) if (!ALLOWED_CUSTOM_CONFIG_KEYS.has(key)) throw new Error(`Custom config key "${key}" is not recognized; only "units" and "dimensions" are allowed`);
12
+ }
13
+ const customUnits = custom?.units ?? {};
14
+ const customDimensions = custom?.dimensions ?? {};
15
+ for (const dimensionId of Object.keys(customDimensions)) if (CORE_DIMENSIONS.has(dimensionId)) throw new Error(`Custom dimension "${dimensionId}" collides with a built-in dimension`);
16
+ const units = {};
17
+ for (const id of Object.keys(UNITS)) units[id] = {
18
+ ...UNITS[id],
19
+ precision: DISPLAY_PRECISION[id]
20
+ };
21
+ for (const [id, def] of Object.entries(customUnits)) {
22
+ if (Object.hasOwn(UNITS, id) || Object.hasOwn(COMPOUNDS, id)) throw new Error(`Custom unit "${id}" collides with a built-in unit id`);
23
+ if (Object.hasOwn(units, id)) throw new Error(`Custom unit "${id}" collides with another custom unit id`);
24
+ if (!CORE_DIMENSIONS.has(def.dimension) && !Object.hasOwn(customDimensions, def.dimension)) throw new Error(`Custom unit "${id}" references unknown dimension "${def.dimension}": declare it in custom.dimensions or use a built-in dimension`);
25
+ units[id] = {
26
+ dimension: def.dimension,
27
+ factor: def.factor,
28
+ offset: def.offset,
29
+ intlUnit: def.intlUnit,
30
+ shortLabel: def.shortLabel,
31
+ longLabel: def.longLabel,
32
+ precision: def.precision ?? 2
33
+ };
34
+ }
35
+ for (const [dimensionId, def] of Object.entries(customDimensions)) {
36
+ const canonical = units[def.canonicalUnit];
37
+ if (!canonical || canonical.dimension !== dimensionId) throw new Error(`Custom dimension "${dimensionId}" canonicalUnit "${def.canonicalUnit}" must be a custom unit declared for dimension "${dimensionId}"`);
38
+ if (canonical.factor !== 1 || typeof canonical.offset !== "undefined") throw new Error(`Custom dimension "${dimensionId}" canonicalUnit "${def.canonicalUnit}" must have factor 1 and no offset`);
39
+ }
40
+ return units;
41
+ };
42
+ /**
43
+ * Builds a measurement engine over the built-in units merged with a serializable custom
44
+ * config. Compound units (ft-in, st-lb) are always built-in: custom units are scalar-only,
45
+ * so decompose/compose run on the built-in table, bridged for a custom storage unit.
46
+ */
47
+ const createEngine = (custom) => {
48
+ const units = mergeUnits(custom);
49
+ const getUnit = (unit) => {
50
+ const def = units[unit];
51
+ if (!def) throw new Error(`Unknown unit "${unit}"`);
52
+ return def;
53
+ };
54
+ const convert = (value, from, to) => convertUnit(units, value, from, to);
55
+ const isScalarUnit$1 = (unit) => Object.hasOwn(units, unit);
56
+ const decompose$1 = (value, from, compound, minorDigits) => {
57
+ if (isScalarUnit(from)) return decompose(value, from, compound, minorDigits);
58
+ const bridge = COMPOUNDS[compound].major;
59
+ return decompose(convert(value, from, bridge), bridge, compound, minorDigits);
60
+ };
61
+ const compose$1 = (parts, compound, to) => {
62
+ if (isScalarUnit(to)) return compose(parts, compound, to);
63
+ const bridge = COMPOUNDS[compound].major;
64
+ return convert(compose(parts, compound, bridge), bridge, to);
65
+ };
66
+ const dimensionOf = (unit) => isCompoundUnitId(unit) ? UNITS[COMPOUNDS[unit].major].dimension : getUnit(unit).dimension;
67
+ const unitsOfDimension$1 = (dimension) => {
68
+ const customIds = Object.entries(custom?.units ?? {}).filter(([, def]) => def.dimension === dimension).map(([id]) => id);
69
+ return [...unitsOfDimension(dimension), ...customIds];
70
+ };
71
+ const precisionFor = (unit, overrides) => {
72
+ const override = overrides?.[unit];
73
+ if (typeof override === "number") return override;
74
+ return isCompoundUnitId(unit) ? COMPOUND_MINOR_PRECISION[unit] : getUnit(unit).precision;
75
+ };
76
+ const unitLabel$1 = (unit, locale, style) => {
77
+ if (isCompoundUnitId(unit)) return unitLabel(unit, locale, style);
78
+ const def = getUnit(unit);
79
+ return style === "short" ? scalarShortLabelFor(def, locale) : scalarLongLabelFor(def, locale);
80
+ };
81
+ const formatMeasurement$1 = (value, opts) => {
82
+ const { displayUnit, locale, precision, storageUnit, unitDisplay = "short" } = opts;
83
+ if (isCompoundUnitId(displayUnit)) {
84
+ const bridge = COMPOUNDS[displayUnit].major;
85
+ const builtInStorage = isScalarUnit(storageUnit);
86
+ return formatMeasurement(builtInStorage ? value : convert(value, storageUnit, bridge), {
87
+ ...opts,
88
+ storageUnit: builtInStorage ? storageUnit : bridge,
89
+ displayUnit
90
+ });
91
+ }
92
+ const digits = precisionFor(displayUnit, precision);
93
+ return formatScalarValue(roundTo(convert(value, storageUnit, displayUnit), digits), {
94
+ digits,
95
+ locale,
96
+ unit: getUnit(displayUnit),
97
+ unitDisplay
98
+ });
99
+ };
100
+ return {
101
+ compose: compose$1,
102
+ convert,
103
+ decompose: decompose$1,
104
+ dimensionOf,
105
+ formatMeasurement: formatMeasurement$1,
106
+ isCompoundUnit: isCompoundUnitId,
107
+ isScalarUnit: isScalarUnit$1,
108
+ precisionFor,
109
+ unitLabel: unitLabel$1,
110
+ unitsOfDimension: unitsOfDimension$1
111
+ };
112
+ };
113
+ const defaultEngine = createEngine();
114
+ //#endregion
115
+ export { createEngine, defaultEngine };
116
+
117
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","names":["isScalarUnit","decompose","isBuiltInScalarUnit","decomposeBuiltIn","compose","composeBuiltIn","unitsOfDimension","unitsOfDimensionBuiltIn","unitLabel","unitLabelBuiltIn","formatMeasurement","formatMeasurementBuiltIn"],"sources":["../../../../src/fields/measurement/engine/registry.ts"],"sourcesContent":["import { convertUnit, roundTo } from './convert'\nimport {\n\tcompose as composeBuiltIn,\n\tdecompose as decomposeBuiltIn,\n\ttype FormattableUnit,\n\tformatMeasurement as formatMeasurementBuiltIn,\n\tformatScalarValue,\n\ttype LocalizedLabel,\n\tscalarLongLabelFor,\n\tscalarShortLabelFor,\n\tunitLabel as unitLabelBuiltIn,\n} from './format'\nimport { DIMENSION_LOCALE_DEFAULTS } from './locale'\nimport {\n\tCOMPOUND_MINOR_PRECISION,\n\tCOMPOUNDS,\n\ttype CompoundUnitId,\n\tDISPLAY_PRECISION,\n\tisScalarUnit as isBuiltInScalarUnit,\n\ttype ScalarUnitId,\n\tUNITS,\n\tunitsOfDimension as unitsOfDimensionBuiltIn,\n} from './units'\n\nexport type CustomUnitDef = {\n\tdimension: string\n\tfactor: number\n\toffset?: number\n\t/** ECMA-402 unit identifier, or null when there is none: formatting falls back to plain decimal + shortLabel. */\n\tintlUnit: string | null\n\t/** A plain string applies to every locale; a map resolves exact locale, then language prefix, then 'en'. */\n\tshortLabel: LocalizedLabel\n\t/** Long-form label, same resolution as shortLabel. Defaults to shortLabel when omitted. */\n\tlongLabel?: LocalizedLabel\n\t/** Display fraction digits for this unit. Defaults to 2 when omitted. */\n\tprecision?: number\n}\n\nexport type CustomDimensionDef = {\n\t/** Must name one of `custom.units` for this dimension, with factor 1 and no offset. */\n\tcanonicalUnit: string\n}\n\nexport type MeasurementCustomConfig = {\n\tunits?: Record<string, CustomUnitDef>\n\tdimensions?: Record<string, CustomDimensionDef>\n}\n\nexport type EngineFormatMeasurementOptions = {\n\tstorageUnit: string\n\tdisplayUnit: string\n\tlocale: string\n\tunitDisplay?: 'long' | 'narrow' | 'short'\n\tprecision?: Partial<Record<string, number>>\n}\n\ntype MergedUnit = FormattableUnit & {\n\tdimension: string\n\tfactor: number\n\toffset?: number\n\tprecision: number\n}\n\nconst CORE_DIMENSIONS = new Set<string>(Object.keys(DIMENSION_LOCALE_DEFAULTS))\n\nconst ALLOWED_CUSTOM_CONFIG_KEYS = new Set<string>(['units', 'dimensions'])\n\nconst isCompoundUnitId = (unit: string): unit is CompoundUnitId => Object.hasOwn(COMPOUNDS, unit)\n\nconst mergeUnits = (custom?: MeasurementCustomConfig): Record<string, MergedUnit> => {\n\tif (custom !== undefined) {\n\t\tfor (const key of Object.keys(custom)) {\n\t\t\tif (!ALLOWED_CUSTOM_CONFIG_KEYS.has(key)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Custom config key \"${key}\" is not recognized; only \"units\" and \"dimensions\" are allowed`\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\tconst customUnits = custom?.units ?? {}\n\tconst customDimensions = custom?.dimensions ?? {}\n\n\tfor (const dimensionId of Object.keys(customDimensions)) {\n\t\tif (CORE_DIMENSIONS.has(dimensionId)) {\n\t\t\tthrow new Error(`Custom dimension \"${dimensionId}\" collides with a built-in dimension`)\n\t\t}\n\t}\n\n\tconst units: Record<string, MergedUnit> = {}\n\tfor (const id of Object.keys(UNITS) as ScalarUnitId[]) {\n\t\tunits[id] = { ...UNITS[id], precision: DISPLAY_PRECISION[id] }\n\t}\n\n\tfor (const [id, def] of Object.entries(customUnits)) {\n\t\tif (Object.hasOwn(UNITS, id) || Object.hasOwn(COMPOUNDS, id)) {\n\t\t\tthrow new Error(`Custom unit \"${id}\" collides with a built-in unit id`)\n\t\t}\n\t\t// Unreachable while customUnits is a plain object (keys are already unique), but\n\t\t// kept as a guard against a future custom-unit source that permits duplicates.\n\t\tif (Object.hasOwn(units, id)) {\n\t\t\tthrow new Error(`Custom unit \"${id}\" collides with another custom unit id`)\n\t\t}\n\t\tif (!CORE_DIMENSIONS.has(def.dimension) && !Object.hasOwn(customDimensions, def.dimension)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Custom unit \"${id}\" references unknown dimension \"${def.dimension}\": declare it in custom.dimensions or use a built-in dimension`\n\t\t\t)\n\t\t}\n\t\tunits[id] = {\n\t\t\tdimension: def.dimension,\n\t\t\tfactor: def.factor,\n\t\t\toffset: def.offset,\n\t\t\tintlUnit: def.intlUnit,\n\t\t\tshortLabel: def.shortLabel,\n\t\t\tlongLabel: def.longLabel,\n\t\t\tprecision: def.precision ?? 2,\n\t\t}\n\t}\n\n\tfor (const [dimensionId, def] of Object.entries(customDimensions)) {\n\t\tconst canonical = units[def.canonicalUnit]\n\t\tif (!canonical || canonical.dimension !== dimensionId) {\n\t\t\tthrow new Error(\n\t\t\t\t`Custom dimension \"${dimensionId}\" canonicalUnit \"${def.canonicalUnit}\" must be a custom unit declared for dimension \"${dimensionId}\"`\n\t\t\t)\n\t\t}\n\t\tif (canonical.factor !== 1 || typeof canonical.offset !== 'undefined') {\n\t\t\tthrow new Error(\n\t\t\t\t`Custom dimension \"${dimensionId}\" canonicalUnit \"${def.canonicalUnit}\" must have factor 1 and no offset`\n\t\t\t)\n\t\t}\n\t}\n\n\treturn units\n}\n\n/**\n * Builds a measurement engine over the built-in units merged with a serializable custom\n * config. Compound units (ft-in, st-lb) are always built-in: custom units are scalar-only,\n * so decompose/compose run on the built-in table, bridged for a custom storage unit.\n */\nexport const createEngine = (custom?: MeasurementCustomConfig) => {\n\tconst units = mergeUnits(custom)\n\n\tconst getUnit = (unit: string): MergedUnit => {\n\t\tconst def = units[unit]\n\t\tif (!def) throw new Error(`Unknown unit \"${unit}\"`)\n\t\treturn def\n\t}\n\n\tconst convert = (value: number, from: string, to: string): number =>\n\t\tconvertUnit(units, value, from, to)\n\n\tconst isScalarUnit = (unit: string): boolean => Object.hasOwn(units, unit)\n\n\t// Compound units are built-in and split on the built-in table, so a custom\n\t// storage unit is bridged through the compound's own major unit.\n\t// biome-ignore lint/complexity/useMaxParams: mirrors the built-in decompose signature\n\tconst decompose = (\n\t\tvalue: number,\n\t\tfrom: string,\n\t\tcompound: CompoundUnitId,\n\t\tminorDigits?: number\n\t): { major: number; minor: number } => {\n\t\tif (isBuiltInScalarUnit(from)) return decomposeBuiltIn(value, from, compound, minorDigits)\n\t\tconst bridge = COMPOUNDS[compound].major\n\t\treturn decomposeBuiltIn(convert(value, from, bridge), bridge, compound, minorDigits)\n\t}\n\n\tconst compose = (\n\t\tparts: { major: number; minor: number },\n\t\tcompound: CompoundUnitId,\n\t\tto: string\n\t): number => {\n\t\tif (isBuiltInScalarUnit(to)) return composeBuiltIn(parts, compound, to)\n\t\tconst bridge = COMPOUNDS[compound].major\n\t\treturn convert(composeBuiltIn(parts, compound, bridge), bridge, to)\n\t}\n\n\tconst dimensionOf = (unit: string): string =>\n\t\tisCompoundUnitId(unit) ? UNITS[COMPOUNDS[unit].major].dimension : getUnit(unit).dimension\n\n\tconst unitsOfDimension = (dimension: string): string[] => {\n\t\tconst customIds = Object.entries(custom?.units ?? {})\n\t\t\t.filter(([, def]) => def.dimension === dimension)\n\t\t\t.map(([id]) => id)\n\t\treturn [...unitsOfDimensionBuiltIn(dimension), ...customIds]\n\t}\n\n\tconst precisionFor = (unit: string, overrides?: Partial<Record<string, number>>): number => {\n\t\tconst override = overrides?.[unit]\n\t\tif (typeof override === 'number') return override\n\t\treturn isCompoundUnitId(unit) ? COMPOUND_MINOR_PRECISION[unit] : getUnit(unit).precision\n\t}\n\n\tconst unitLabel = (unit: string, locale: string, style: 'long' | 'short'): string => {\n\t\tif (isCompoundUnitId(unit)) return unitLabelBuiltIn(unit, locale, style)\n\t\tconst def = getUnit(unit)\n\t\treturn style === 'short' ? scalarShortLabelFor(def, locale) : scalarLongLabelFor(def, locale)\n\t}\n\n\tconst formatMeasurement = (value: number, opts: EngineFormatMeasurementOptions): string => {\n\t\tconst { displayUnit, locale, precision, storageUnit, unitDisplay = 'short' } = opts\n\t\tif (isCompoundUnitId(displayUnit)) {\n\t\t\tconst bridge = COMPOUNDS[displayUnit].major\n\t\t\tconst builtInStorage = isBuiltInScalarUnit(storageUnit)\n\t\t\treturn formatMeasurementBuiltIn(\n\t\t\t\tbuiltInStorage ? value : convert(value, storageUnit, bridge),\n\t\t\t\t{\n\t\t\t\t\t...opts,\n\t\t\t\t\tstorageUnit: builtInStorage ? storageUnit : bridge,\n\t\t\t\t\tdisplayUnit,\n\t\t\t\t}\n\t\t\t)\n\t\t}\n\t\tconst digits = precisionFor(displayUnit, precision)\n\t\treturn formatScalarValue(roundTo(convert(value, storageUnit, displayUnit), digits), {\n\t\t\tdigits,\n\t\t\tlocale,\n\t\t\tunit: getUnit(displayUnit),\n\t\t\tunitDisplay,\n\t\t})\n\t}\n\n\treturn {\n\t\tcompose,\n\t\tconvert,\n\t\tdecompose,\n\t\tdimensionOf,\n\t\tformatMeasurement,\n\t\tisCompoundUnit: isCompoundUnitId,\n\t\tisScalarUnit,\n\t\tprecisionFor,\n\t\tunitLabel,\n\t\tunitsOfDimension,\n\t}\n}\n\nexport type MeasurementEngine = ReturnType<typeof createEngine>\n\nexport const defaultEngine: MeasurementEngine = createEngine()\n"],"mappings":";;;;;AA+DA,MAAM,kBAAkB,IAAI,IAAY,OAAO,KAAK,yBAAyB,CAAC;AAE9E,MAAM,6BAA6B,IAAI,IAAY,CAAC,SAAS,YAAY,CAAC;AAE1E,MAAM,oBAAoB,SAAyC,OAAO,OAAO,WAAW,IAAI;AAEhG,MAAM,cAAc,WAAiE;CACpF,IAAI,WAAW,KAAA;OACT,MAAM,OAA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