@10x-media/fields 0.1.0-beta.6 → 0.1.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +3 -1
  3. package/dist/exports/client.d.ts +4 -1
  4. package/dist/exports/client.js +4 -1
  5. package/dist/exports/measurement-utils.d.ts +9 -0
  6. package/dist/exports/measurement-utils.js +8 -0
  7. package/dist/exports/measurement.d.ts +11 -0
  8. package/dist/exports/measurement.js +10 -0
  9. package/dist/exports/rsc.d.ts +3 -1
  10. package/dist/exports/rsc.js +3 -1
  11. package/dist/fields/icon/client/icon-field.css +4 -2
  12. package/dist/fields/measurement/client/MeasurementCell.d.ts +18 -0
  13. package/dist/fields/measurement/client/MeasurementCell.js +47 -0
  14. package/dist/fields/measurement/client/MeasurementCell.js.map +1 -0
  15. package/dist/fields/measurement/client/MeasurementField.d.ts +11 -0
  16. package/dist/fields/measurement/client/MeasurementField.js +386 -0
  17. package/dist/fields/measurement/client/MeasurementField.js.map +1 -0
  18. package/dist/fields/measurement/client/MeasurementUnitsProvider.d.ts +24 -0
  19. package/dist/fields/measurement/client/MeasurementUnitsProvider.js +61 -0
  20. package/dist/fields/measurement/client/MeasurementUnitsProvider.js.map +1 -0
  21. package/dist/fields/measurement/client/editModel.js +115 -0
  22. package/dist/fields/measurement/client/editModel.js.map +1 -0
  23. package/dist/fields/measurement/client/measurementCell.css +4 -0
  24. package/dist/fields/measurement/client/measurementField.css +215 -0
  25. package/dist/fields/measurement/engine/convert.d.ts +8 -0
  26. package/dist/fields/measurement/engine/convert.js +21 -0
  27. package/dist/fields/measurement/engine/convert.js.map +1 -0
  28. package/dist/fields/measurement/engine/format.d.ts +37 -0
  29. package/dist/fields/measurement/engine/format.js +156 -0
  30. package/dist/fields/measurement/engine/format.js.map +1 -0
  31. package/dist/fields/measurement/engine/locale.d.ts +25 -0
  32. package/dist/fields/measurement/engine/locale.js +79 -0
  33. package/dist/fields/measurement/engine/locale.js.map +1 -0
  34. package/dist/fields/measurement/engine/precision.d.ts +34 -0
  35. package/dist/fields/measurement/engine/precision.js +63 -0
  36. package/dist/fields/measurement/engine/precision.js.map +1 -0
  37. package/dist/fields/measurement/engine/registry.d.ts +55 -0
  38. package/dist/fields/measurement/engine/registry.js +117 -0
  39. package/dist/fields/measurement/engine/registry.js.map +1 -0
  40. package/dist/fields/measurement/engine/units.d.ts +178 -0
  41. package/dist/fields/measurement/engine/units.js +198 -0
  42. package/dist/fields/measurement/engine/units.js.map +1 -0
  43. package/dist/fields/measurement/measurementField.d.ts +17 -0
  44. package/dist/fields/measurement/measurementField.js +139 -0
  45. package/dist/fields/measurement/measurementField.js.map +1 -0
  46. package/dist/fields/measurement/options.d.ts +76 -0
  47. package/dist/fields/measurement/options.js +9 -0
  48. package/dist/fields/measurement/options.js.map +1 -0
  49. package/dist/fields/measurement/presets.d.ts +117 -0
  50. package/dist/fields/measurement/presets.js +136 -0
  51. package/dist/fields/measurement/presets.js.map +1 -0
  52. package/dist/fields/measurement/server/MeasurementCellServer.d.ts +21 -0
  53. package/dist/fields/measurement/server/MeasurementCellServer.js +53 -0
  54. package/dist/fields/measurement/server/MeasurementCellServer.js.map +1 -0
  55. package/dist/fields/measurement/server/MeasurementFieldServer.d.ts +16 -0
  56. package/dist/fields/measurement/server/MeasurementFieldServer.js +45 -0
  57. package/dist/fields/measurement/server/MeasurementFieldServer.js.map +1 -0
  58. package/dist/fields/measurement/server/getUserUnits.js +39 -0
  59. package/dist/fields/measurement/server/getUserUnits.js.map +1 -0
  60. package/dist/fields/measurement/server/resolvePrecisionSafe.js +24 -0
  61. package/dist/fields/measurement/server/resolvePrecisionSafe.js.map +1 -0
  62. package/dist/fields/measurement/server/resolveRegistryDefault.js +26 -0
  63. package/dist/fields/measurement/server/resolveRegistryDefault.js.map +1 -0
  64. package/dist/index.d.ts +4 -3
  65. package/dist/index.js +16 -0
  66. package/dist/index.js.map +1 -1
  67. package/dist/translations/ar.js +4 -1
  68. package/dist/translations/ar.js.map +1 -1
  69. package/dist/translations/de.js +4 -1
  70. package/dist/translations/de.js.map +1 -1
  71. package/dist/translations/en.js +4 -1
  72. package/dist/translations/en.js.map +1 -1
  73. package/dist/translations/es.js +4 -1
  74. package/dist/translations/es.js.map +1 -1
  75. package/dist/translations/fr.js +4 -1
  76. package/dist/translations/fr.js.map +1 -1
  77. package/dist/translations/id.js +4 -1
  78. package/dist/translations/id.js.map +1 -1
  79. package/dist/translations/keys.d.ts +3 -0
  80. package/dist/translations/keys.js +4 -1
  81. package/dist/translations/keys.js.map +1 -1
  82. package/dist/translations/ko.js +4 -1
  83. package/dist/translations/ko.js.map +1 -1
  84. package/dist/translations/pt.js +4 -1
  85. package/dist/translations/pt.js.map +1 -1
  86. package/dist/translations/ru.js +4 -1
  87. package/dist/translations/ru.js.map +1 -1
  88. package/dist/translations/uk.js +4 -1
  89. package/dist/translations/uk.js.map +1 -1
  90. package/dist/translations/zh.js +4 -1
  91. package/dist/translations/zh.js.map +1 -1
  92. package/dist/types.d.ts +20 -1
  93. package/package.json +13 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editModel.js","names":[],"sources":["../../../../src/fields/measurement/client/editModel.ts"],"sourcesContent":["import { roundTo } from '../engine/convert'\nimport type { MeasurementEngine } from '../engine/registry'\nimport { COMPOUNDS, type MeasurementUnitId, STORAGE_FRACTION_DIGITS } from '../engine/units'\n\n/** Re-exported so MeasurementField/MeasurementCell keep one import site for the edit model. */\nexport { resolveDisplayUnit } from '../engine/locale'\n\nexport type MeasurementDrafts = { primary: string; minor: string }\n\n/** Which inputs the viewer has actually typed into since the last resync. */\nexport type DirtyDrafts = { primary: boolean; minor: boolean }\n\ntype UnitContext = {\n\t/** Bound over the field's custom units, so custom ids convert and format like built-ins. */\n\tengine: MeasurementEngine\n\tstorageUnit: MeasurementUnitId\n\tdisplayUnit: MeasurementUnitId\n\tprecision?: Partial<Record<MeasurementUnitId, number>>\n\t/**\n\t * Draft-repaint policy: 'faithful' (default) escalates fraction digits until the\n\t * draft round-trips to the stored value; 'display' renders straight at display\n\t * digits, so a stored value can print shorter than it is stored.\n\t */\n\tdraft?: 'display' | 'faithful'\n\t/** Fraction digits kept in the storage unit. Defaults to STORAGE_FRACTION_DIGITS. */\n\tstorageDigits?: number\n}\n\ntype CommitOptions = UnitContext & {\n\t/**\n\t * Entry-unit typing behavior: 'quantize' rounds a dirty part at its own display\n\t * digits, in the unit it was typed in, before converting; 'free' (default) keeps\n\t * the typed value exact.\n\t */\n\tentry?: 'quantize' | 'free'\n\t/** An untouched part never commits its displayed string; only a dirty one does. */\n\tdirty?: DirtyDrafts\n\t/** Current stored value, used to derive an untouched part's exact contribution. */\n\tstoredValue?: number | null\n\t/**\n\t * The compound drafts as painted on screen immediately before this edit (not the\n\t * post-keystroke `drafts`). A display-digit repaint can carry (182.5 cm storage\n\t * splits exactly to 5 ft 11.850394 in but paints as 6 ft 0 in), so when exactly\n\t * one part is dirty, the edited part's contribution is computed as a delta off\n\t * this baseline rather than a full replace, which would otherwise bake the\n\t * painted carry into storage.\n\t */\n\tpaintedDrafts?: MeasurementDrafts\n}\n\nconst numberToDraft = (value: number): string => String(value)\n\nconst parseDraft = (raw: string): number | null => {\n\tif (raw.trim() === '') return null\n\tconst parsed = Number(raw)\n\treturn Number.isFinite(parsed) ? parsed : null\n}\n\n// draftsFor/commitDrafts default to 'faithful'/'free'/ALL_DIRTY when a caller omits\n// them, i.e. the shape of 'exact' mode, not the engine's own 'readable' default: the\n// component always threads its resolved precision explicitly, so these bare defaults\n// exist only for a caller invoking editModel directly (tests, or an embedder outside\n// the component), and preserve the single behavior this module had before precision\n// modes existed.\nconst ALL_DIRTY: DirtyDrafts = { primary: true, minor: true }\n\nexport const commitDrafts = (drafts: MeasurementDrafts, opts: CommitOptions): number | null => {\n\tconst {\n\t\tdisplayUnit,\n\t\tdirty = ALL_DIRTY,\n\t\tengine,\n\t\tentry = 'free',\n\t\tpaintedDrafts,\n\t\tprecision,\n\t\tstorageDigits = STORAGE_FRACTION_DIGITS,\n\t\tstorageUnit,\n\t\tstoredValue = null,\n\t} = opts\n\n\tif (engine.isCompoundUnit(displayUnit)) {\n\t\tconst compound = COMPOUNDS[displayUnit]\n\t\tconst hasStored = typeof storedValue === 'number'\n\t\tconst dirtyCount = (dirty.primary ? 1 : 0) + (dirty.minor ? 1 : 0)\n\n\t\t// Delta path: exactly one part was touched and a painted baseline exists, so\n\t\t// the untouched part's contribution comes entirely from the exact stored\n\t\t// total (never its carried, display-precision draft), and the touched part\n\t\t// contributes only the change the viewer actually typed, in minor units.\n\t\tif (hasStored && dirtyCount === 1 && paintedDrafts) {\n\t\t\tconst exact = engine.decompose(storedValue as number, storageUnit, displayUnit, storageDigits)\n\t\t\tconst exactTotal = exact.major * compound.ratio + exact.minor\n\n\t\t\tif (dirty.primary) {\n\t\t\t\tlet typedMajor = parseDraft(drafts.primary)\n\t\t\t\tif (typedMajor === null) return null\n\t\t\t\tif (entry === 'quantize') {\n\t\t\t\t\ttypedMajor = roundTo(typedMajor, engine.precisionFor(compound.major, precision))\n\t\t\t\t}\n\t\t\t\tconst paintedMajor = parseDraft(paintedDrafts.primary) ?? exact.major\n\t\t\t\tconst newTotal = exactTotal + (typedMajor - paintedMajor) * compound.ratio\n\t\t\t\treturn roundTo(\n\t\t\t\t\tengine.compose({ major: 0, minor: newTotal }, displayUnit, storageUnit),\n\t\t\t\t\tstorageDigits\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tconst rawMinor = parseDraft(drafts.minor) ?? 0\n\t\t\tconst typedMinor =\n\t\t\t\tentry === 'quantize'\n\t\t\t\t\t? roundTo(rawMinor, engine.precisionFor(displayUnit, precision))\n\t\t\t\t\t: rawMinor\n\t\t\tconst paintedMinor = parseDraft(paintedDrafts.minor) ?? 0\n\t\t\tconst newTotal = exactTotal + (typedMinor - paintedMinor)\n\t\t\treturn roundTo(\n\t\t\t\tengine.compose({ major: 0, minor: newTotal }, displayUnit, storageUnit),\n\t\t\t\tstorageDigits\n\t\t\t)\n\t\t}\n\n\t\t// Both parts dirty (an explicit full replace) or no baseline to diff\n\t\t// against: compose the two parts directly, as before.\n\t\tconst stored = hasStored\n\t\t\t? engine.decompose(storedValue as number, storageUnit, displayUnit, storageDigits)\n\t\t\t: null\n\n\t\tlet major: number | null\n\t\tif (dirty.primary) {\n\t\t\tmajor = parseDraft(drafts.primary)\n\t\t\tif (major !== null && entry === 'quantize') {\n\t\t\t\tmajor = roundTo(major, engine.precisionFor(compound.major, precision))\n\t\t\t}\n\t\t} else {\n\t\t\tmajor = stored ? stored.major : parseDraft(drafts.primary)\n\t\t}\n\t\tif (major === null) return null\n\n\t\tlet minor: number\n\t\tif (dirty.minor) {\n\t\t\tconst rawMinor = parseDraft(drafts.minor) ?? 0\n\t\t\tconst maxMinor = compound.ratio - 0.001\n\t\t\t// Clamp the raw typed magnitude (bounds a literal 24) before quantizing:\n\t\t\t// a quantized value landing exactly on the ratio (11.96 -> 12) must be\n\t\t\t// free to carry into the major via compose, matching decompose's own\n\t\t\t// carry contract, so nothing clamps it back down afterward.\n\t\t\tconst clampedRaw = Math.sign(rawMinor) * Math.min(Math.abs(rawMinor), maxMinor)\n\t\t\tminor =\n\t\t\t\tentry === 'quantize'\n\t\t\t\t\t? roundTo(clampedRaw, engine.precisionFor(displayUnit, precision))\n\t\t\t\t\t: clampedRaw\n\t\t} else {\n\t\t\t// No stored value to derive an exact minor from (a brand new, never-saved\n\t\t\t// field): fall back to the painted baseline, matching major's own fallback,\n\t\t\t// never a bare 0 (a cleared-then-retyped major would otherwise commit with\n\t\t\t// its minor silently zeroed).\n\t\t\tminor = stored ? stored.minor : (parseDraft(paintedDrafts?.minor ?? '') ?? 0)\n\t\t}\n\n\t\treturn roundTo(engine.compose({ major, minor }, displayUnit, storageUnit), storageDigits)\n\t}\n\n\tif (!dirty.primary) return storedValue\n\tconst parsed = parseDraft(drafts.primary)\n\tif (parsed === null) return null\n\tconst value =\n\t\tentry === 'quantize' ? roundTo(parsed, engine.precisionFor(displayUnit, precision)) : parsed\n\treturn roundTo(engine.convert(value, displayUnit, storageUnit), storageDigits)\n}\n\n/**\n * Drafts for repainting from a stored value. 'faithful' (default) is the shortest\n * draft that commits back to the stored value: display precision first, then one\n * more fraction digit at a time up to storage precision, since a draft that\n * silently truncates the stored value would write the truncation back on the next\n * save. 'display' skips escalation and renders straight at display digits\n * (compound parts each at their own digits), trading faithfulness for a value that\n * always matches what the unit picker promises.\n */\nexport const draftsFor = (value: number | null, opts: UnitContext): MeasurementDrafts => {\n\tif (typeof value !== 'number' || Number.isNaN(value)) return { minor: '', primary: '' }\n\tconst {\n\t\tdisplayUnit,\n\t\tdraft = 'faithful',\n\t\tengine,\n\t\tprecision,\n\t\tstorageDigits = STORAGE_FRACTION_DIGITS,\n\t\tstorageUnit,\n\t} = opts\n\tconst draftAt = (digits: number): MeasurementDrafts => {\n\t\tif (engine.isCompoundUnit(displayUnit)) {\n\t\t\tconst parts = engine.decompose(value, storageUnit, displayUnit, digits)\n\t\t\treturn { minor: numberToDraft(parts.minor), primary: numberToDraft(parts.major) }\n\t\t}\n\t\tconst converted = roundTo(engine.convert(value, storageUnit, displayUnit), digits)\n\t\treturn { minor: '', primary: numberToDraft(converted) }\n\t}\n\n\tconst displayDigits = engine.precisionFor(displayUnit, precision)\n\tif (draft === 'display') return draftAt(displayDigits)\n\n\t// Digits past storage precision never survive a save, so that is where escalation stops.\n\tconst maxDigits = Math.max(displayDigits, storageDigits)\n\tconst target = roundTo(value, storageDigits)\n\t// A bare probe: never forward `opts` itself, so an entry/dirty/storedValue field\n\t// a future CommitOptions caller happens to carry can never poison this check.\n\tconst probeOpts: UnitContext = { displayUnit, engine, precision, storageDigits, storageUnit }\n\tfor (let digits = displayDigits; digits < maxDigits; digits++) {\n\t\tconst candidate = draftAt(digits)\n\t\tif (commitDrafts(candidate, probeOpts) === target) return candidate\n\t}\n\treturn draftAt(maxDigits)\n}\n"],"mappings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AAA,GACA,gBACG;CACJ,MAAM,WAAW,WAAsC;EACtD,IAAI,OAAO,eAAe,WAAW,GAAG;GACvC,MAAM,QAAQ,OAAO,UAAU,OAAO,aAAa,aAAa,MAAM;GACtE,OAAO;IAAE,OAAO,cAAc,MAAM,KAAK;IAAG,SAAS,cAAc,MAAM,KAAK;GAAE;EACjF;EAEA,OAAO;GAAE,OAAO;GAAI,SAAS,cADX,QAAQ,OAAO,QAAQ,OAAO,aAAa,WAAW,GAAG,MACxB,CAAC;EAAE;CACvD;CAEA,MAAM,gBAAgB,OAAO,aAAa,aAAa,SAAS;CAChE,IAAI,UAAU,WAAW,OAAO,QAAQ,aAAa;CAGrD,MAAM,YAAY,KAAK,IAAI,eAAe,aAAa;CACvD,MAAM,SAAS,QAAQ,OAAO,aAAa;CAG3C,MAAM,YAAyB;EAAE;EAAa;EAAQ;EAAW;EAAe;CAAY;CAC5F,KAAK,IAAI,SAAS,eAAe,SAAS,WAAW,UAAU;EAC9D,MAAM,YAAY,QAAQ,MAAM;EAChC,IAAI,aAAa,WAAW,SAAS,MAAM,QAAQ,OAAO;CAC3D;CACA,OAAO,QAAQ,SAAS;AACzB"}
@@ -0,0 +1,4 @@
1
+ .fields-measurement-cell {
2
+ white-space: nowrap;
3
+ font-variant-numeric: tabular-nums;
4
+ }
@@ -0,0 +1,215 @@
1
+ .fields-measurement {
2
+ position: relative;
3
+ }
4
+
5
+ /* Mirrors Payload's formInput mixin (packages/ui/src/scss/vars.scss) so the composite
6
+ container reads as one native text input; focus rides :focus-within.
7
+ Dimensions are static px on purpose: Payload compiles scss base() to literal px
8
+ (native inputs stay 40px tall at every breakpoint), while the runtime --base var
9
+ is rem-based and shrinks with the responsive html font-size. Deriving from
10
+ var(--base) made this container 3px shorter than native inputs at <=1024px. */
11
+ .fields-measurement__container {
12
+ display: flex;
13
+ align-items: center;
14
+ gap: 3px;
15
+ width: 100%;
16
+ height: 40px;
17
+ padding: 0 8px 0 6px;
18
+ border: 1px solid var(--theme-elevation-150);
19
+ border-radius: var(--style-radius-s);
20
+ background: var(--theme-input-bg);
21
+ color: var(--theme-elevation-800);
22
+ font-family: var(--font-body);
23
+ font-size: 1rem;
24
+ box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
25
+ transition-property: border, box-shadow, background-color;
26
+ transition-duration: 100ms, 100ms, 500ms;
27
+ transition-timing-function: cubic-bezier(0, 0.2, 0.2, 1);
28
+ }
29
+
30
+ .fields-measurement__container:hover {
31
+ border-color: var(--theme-elevation-250);
32
+ box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.2);
33
+ }
34
+
35
+ .fields-measurement__container:focus-within {
36
+ border-color: var(--theme-elevation-400);
37
+ outline: 0;
38
+ }
39
+
40
+ html[data-theme="light"] .fields-measurement.error .fields-measurement__container {
41
+ background-color: var(--theme-error-50);
42
+ border-color: var(--theme-error-500);
43
+ }
44
+
45
+ html[data-theme="dark"] .fields-measurement.error .fields-measurement__container {
46
+ background-color: var(--theme-error-100);
47
+ border-color: var(--theme-error-400);
48
+ }
49
+
50
+ html[data-theme="dark"] .fields-measurement.error .fields-measurement__container:hover {
51
+ border-color: var(--theme-error-500);
52
+ }
53
+
54
+ .fields-measurement.read-only .fields-measurement__container,
55
+ .fields-measurement.read-only .fields-measurement__container:hover {
56
+ border-color: var(--theme-elevation-150);
57
+ background: var(--theme-elevation-100);
58
+ color: var(--theme-elevation-400);
59
+ box-shadow: none;
60
+ }
61
+
62
+ /* Each value hugs its unit; the wider gap separates the pairs, so the row
63
+ reads "5 ft 11 in" rather than evenly scattered tokens */
64
+ .fields-measurement__compound {
65
+ display: flex;
66
+ flex: 1 1 auto;
67
+ min-width: 0;
68
+ align-items: center;
69
+ gap: 12px;
70
+ height: 100%;
71
+ }
72
+
73
+ .fields-measurement__part {
74
+ display: flex;
75
+ align-items: center;
76
+ gap: 3px;
77
+ height: 100%;
78
+ }
79
+
80
+ /* Width comes from an inline style tracking the draft's length, so every value
81
+ (scalar or compound part) hugs its digits instead of stretching the row */
82
+ .fields-measurement__input {
83
+ flex: 0 1 auto;
84
+ min-width: 2ch;
85
+ height: 100%;
86
+ padding: 0;
87
+ border: 0;
88
+ background: transparent;
89
+ color: inherit;
90
+ font-family: inherit;
91
+ font-size: inherit;
92
+ appearance: none;
93
+ -webkit-appearance: none;
94
+ -moz-appearance: textfield;
95
+ }
96
+
97
+ .fields-measurement__input::-webkit-outer-spin-button,
98
+ .fields-measurement__input::-webkit-inner-spin-button {
99
+ -webkit-appearance: none;
100
+ margin: 0;
101
+ }
102
+
103
+ .fields-measurement__input:focus {
104
+ outline: 0;
105
+ }
106
+
107
+ .fields-measurement__input::placeholder {
108
+ color: var(--theme-elevation-400);
109
+ }
110
+
111
+ /* margin-left auto pins the kebab to the row's right edge, away from the
112
+ value-unit phrase on the left */
113
+ .fields-measurement__popup {
114
+ margin-left: auto;
115
+ }
116
+
117
+ .fields-measurement__popup,
118
+ .fields-measurement__popup .popup__trigger-wrap {
119
+ display: flex;
120
+ flex-shrink: 0;
121
+ }
122
+
123
+ /* The trigger is a real button so it keeps native focus/keyboard semantics; the
124
+ kebab is aria-hidden and a sr-only span next to it carries the name */
125
+ .fields-measurement__unit-trigger {
126
+ display: inline-flex;
127
+ flex-shrink: 0;
128
+ align-items: center;
129
+ justify-content: center;
130
+ width: 24px;
131
+ height: 24px;
132
+ padding: 0;
133
+ border: 0;
134
+ border-radius: var(--style-radius-s);
135
+ background: transparent;
136
+ color: var(--theme-elevation-500);
137
+ cursor: pointer;
138
+ }
139
+
140
+ .fields-measurement__unit-trigger:hover {
141
+ background: var(--theme-elevation-100);
142
+ color: var(--theme-elevation-800);
143
+ }
144
+
145
+ .fields-measurement__unit-trigger:focus-visible {
146
+ outline: var(--accessibility-outline);
147
+ }
148
+
149
+ .fields-measurement__kebab {
150
+ flex-shrink: 0;
151
+ width: 4px;
152
+ height: 14px;
153
+ }
154
+
155
+ .fields-measurement__sr-only {
156
+ position: absolute;
157
+ width: 1px;
158
+ height: 1px;
159
+ margin: -1px;
160
+ padding: 0;
161
+ overflow: hidden;
162
+ clip: rect(0 0 0 0);
163
+ white-space: nowrap;
164
+ border-width: 0;
165
+ }
166
+
167
+ /* The unit is always a passive suffix hugging its value; interactivity lives
168
+ on the kebab at the row's right edge (absent when there is nothing to open) */
169
+ .fields-measurement__unit-static {
170
+ flex-shrink: 0;
171
+ color: var(--theme-elevation-500);
172
+ font-size: 0.85rem;
173
+ white-space: nowrap;
174
+ cursor: default;
175
+ }
176
+
177
+ .popup__scroll-container:has(> .fields-measurement__unit-panel) {
178
+ max-height: none;
179
+ }
180
+
181
+ .fields-measurement__unit-panel {
182
+ display: flex;
183
+ flex-direction: column;
184
+ gap: 2px;
185
+ min-width: 180px;
186
+ padding: 4px;
187
+ }
188
+
189
+ .fields-measurement__unit-option {
190
+ display: flex;
191
+ align-items: center;
192
+ justify-content: space-between;
193
+ gap: 12px;
194
+ padding: 6px 8px;
195
+ border: 0;
196
+ border-radius: var(--style-radius-s);
197
+ background: transparent;
198
+ color: var(--theme-elevation-800);
199
+ font-size: 1rem;
200
+ text-align: start;
201
+ cursor: pointer;
202
+ }
203
+
204
+ .fields-measurement__unit-option:hover {
205
+ background: var(--theme-elevation-100);
206
+ }
207
+
208
+ .fields-measurement__unit-option[aria-selected="true"] {
209
+ background: var(--theme-elevation-150);
210
+ }
211
+
212
+ .fields-measurement__unit-symbol {
213
+ color: var(--theme-elevation-800);
214
+ font-size: 0.75rem;
215
+ }
@@ -0,0 +1,8 @@
1
+ import { ScalarUnitId } from "./units.js";
2
+
3
+ //#region src/fields/measurement/engine/convert.d.ts
4
+ declare const roundTo: (value: number, digits: number) => number;
5
+ declare const convert: (value: number, from: ScalarUnitId, to: ScalarUnitId) => number;
6
+ //#endregion
7
+ export { convert, roundTo };
8
+ //# sourceMappingURL=convert.d.ts.map
@@ -0,0 +1,21 @@
1
+ import { UNITS } from "./units.js";
2
+ //#region src/fields/measurement/engine/convert.ts
3
+ const roundTo = (value, digits) => {
4
+ const p = 10 ** digits;
5
+ return Math.round((value + Number.EPSILON * Math.sign(value)) * p) / p;
6
+ };
7
+ /** Converts between two units of the same dimension via the dimension canonical, over any unit table. */
8
+ const convertUnit = (units, value, from, to) => {
9
+ if (from === to) return value;
10
+ const f = units[from];
11
+ const t = units[to];
12
+ if (!f) throw new Error(`Unknown unit "${from}"`);
13
+ if (!t) throw new Error(`Unknown unit "${to}"`);
14
+ if (f.dimension !== t.dimension) throw new Error(`Cannot convert ${from} (${f.dimension}) to ${to} (${t.dimension}): dimension mismatch`);
15
+ return (value * f.factor + (f.offset ?? 0) - (t.offset ?? 0)) / t.factor;
16
+ };
17
+ const convert = (value, from, to) => convertUnit(UNITS, value, from, to);
18
+ //#endregion
19
+ export { convert, convertUnit, roundTo };
20
+
21
+ //# sourceMappingURL=convert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert.js","names":[],"sources":["../../../../src/fields/measurement/engine/convert.ts"],"sourcesContent":["import { type ScalarUnitId, UNITS } from './units'\n\nexport const roundTo = (value: number, digits: number): number => {\n\tconst p = 10 ** digits\n\treturn Math.round((value + Number.EPSILON * Math.sign(value)) * p) / p\n}\n\n/** Minimal shape convert needs, so createEngine can pass a merged built-in + custom unit table. */\nexport type ConversionUnit = { dimension: string; factor: number; offset?: number }\n\n/** Converts between two units of the same dimension via the dimension canonical, over any unit table. */\n// biome-ignore lint/complexity/useMaxParams: shared conversion core keyed by a caller-supplied unit table\nexport const convertUnit = (\n\tunits: Record<string, ConversionUnit>,\n\tvalue: number,\n\tfrom: string,\n\tto: string\n): number => {\n\tif (from === to) return value\n\tconst f = units[from]\n\tconst t = units[to]\n\tif (!f) throw new Error(`Unknown unit \"${from}\"`)\n\tif (!t) throw new Error(`Unknown unit \"${to}\"`)\n\tif (f.dimension !== t.dimension) {\n\t\tthrow new Error(\n\t\t\t`Cannot convert ${from} (${f.dimension}) to ${to} (${t.dimension}): dimension mismatch`\n\t\t)\n\t}\n\tconst canonical = value * f.factor + (f.offset ?? 0)\n\treturn (canonical - (t.offset ?? 0)) / t.factor\n}\n\nexport const convert = (value: number, from: ScalarUnitId, to: ScalarUnitId): number =>\n\tconvertUnit(UNITS, value, from, to)\n"],"mappings":";;AAEA,MAAa,WAAW,OAAe,WAA2B;CACjE,MAAM,IAAI,MAAM;CAChB,OAAO,KAAK,OAAO,QAAQ,OAAO,UAAU,KAAK,KAAK,KAAK,KAAK,CAAC,IAAI;AACtE;;AAOA,MAAa,eACZ,OACA,OACA,MACA,OACY;CACZ,IAAI,SAAS,IAAI,OAAO;CACxB,MAAM,IAAI,MAAM;CAChB,MAAM,IAAI,MAAM;CAChB,IAAI,CAAC,GAAG,MAAM,IAAI,MAAM,iBAAiB,KAAK,EAAE;CAChD,IAAI,CAAC,GAAG,MAAM,IAAI,MAAM,iBAAiB,GAAG,EAAE;CAC9C,IAAI,EAAE,cAAc,EAAE,WACrB,MAAM,IAAI,MACT,kBAAkB,KAAK,IAAI,EAAE,UAAU,OAAO,GAAG,IAAI,EAAE,UAAU,sBAClE;CAGD,QADkB,QAAQ,EAAE,UAAU,EAAE,UAAU,MAC7B,EAAE,UAAU,MAAM,EAAE;AAC1C;AAEA,MAAa,WAAW,OAAe,MAAoB,OAC1D,YAAY,OAAO,OAAO,MAAM,EAAE"}
@@ -0,0 +1,37 @@
1
+ import { CompoundUnitId, ScalarUnitId, UnitId } from "./units.js";
2
+
3
+ //#region src/fields/measurement/engine/format.d.ts
4
+ type FormatMeasurementOptions = {
5
+ storageUnit: ScalarUnitId;
6
+ displayUnit: UnitId;
7
+ locale: string;
8
+ unitDisplay?: 'long' | 'narrow' | 'short';
9
+ precision?: Partial<Record<UnitId, number>>;
10
+ };
11
+ /**
12
+ * Splits a stored scalar into compound major/minor parts. The minor is rounded
13
+ * to its display precision BEFORE deriving the major so 5 ft 11.996 in carries
14
+ * to 6 ft 0 in rather than printing an impossible 5 ft 12 in.
15
+ */
16
+ declare const decompose: (value: number, from: ScalarUnitId, compound: CompoundUnitId, minorDigits?: number) => {
17
+ major: number;
18
+ minor: number;
19
+ };
20
+ declare const compose: (parts: {
21
+ major: number;
22
+ minor: number;
23
+ }, compound: CompoundUnitId, to: ScalarUnitId) => number;
24
+ /** A label that may vary by locale: an exact string, or a map resolved via resolveLocalizedLabel. */
25
+ type LocalizedLabel = string | Partial<Record<string, string>>;
26
+ /**
27
+ * Resolves a possibly-localized label: exact locale match, then the language prefix
28
+ * (de for de-AT), then the 'en' entry, then whichever value comes first, so a partial
29
+ * map never renders blank. A plain string passes through unchanged.
30
+ */
31
+ declare const resolveLocalizedLabel: (label: LocalizedLabel, locale: string) => string;
32
+ declare const formatMeasurement: (value: number, opts: FormatMeasurementOptions) => string;
33
+ /** Picker label for a unit. Both styles come from Intl so they localize for free. */
34
+ declare const unitLabel: (unit: UnitId, locale: string, style: "long" | "short") => string;
35
+ //#endregion
36
+ export { FormatMeasurementOptions, LocalizedLabel, compose, decompose, formatMeasurement, resolveLocalizedLabel, unitLabel };
37
+ //# sourceMappingURL=format.d.ts.map
@@ -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,MAA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;CACd,CAAC,EAAE,cAAc,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,OA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