@10x-media/fields 0.1.0-beta.1 → 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.
- package/CHANGELOG.md +120 -0
- package/README.md +7 -3
- package/dist/exports/client.d.ts +10 -1
- package/dist/exports/client.js +9 -1
- package/dist/exports/color-utils.d.ts +2 -1
- package/dist/exports/color-utils.js +2 -1
- package/dist/exports/color.d.ts +2 -1
- package/dist/exports/color.js +2 -1
- package/dist/exports/encrypted.d.ts +7 -4
- package/dist/exports/encrypted.js +6 -3
- package/dist/exports/measurement-utils.d.ts +9 -0
- package/dist/exports/measurement-utils.js +8 -0
- package/dist/exports/measurement.d.ts +11 -0
- package/dist/exports/measurement.js +10 -0
- package/dist/exports/phone-utils.d.ts +4 -0
- package/dist/exports/phone-utils.js +4 -0
- package/dist/exports/phone.d.ts +6 -0
- package/dist/exports/phone.js +3 -0
- package/dist/exports/rsc.d.ts +5 -1
- package/dist/exports/rsc.js +5 -1
- package/dist/exports/types.d.ts +3 -2
- package/dist/fields/color/client/ColorField.d.ts +2 -0
- package/dist/fields/color/client/ColorField.js +35 -293
- package/dist/fields/color/client/ColorField.js.map +1 -1
- package/dist/fields/color/client/ColorInput.d.ts +44 -0
- package/dist/fields/color/client/ColorInput.js +374 -0
- package/dist/fields/color/client/ColorInput.js.map +1 -0
- package/dist/fields/color/client/ColorPickerPanel.d.ts +3 -1
- package/dist/fields/color/client/ColorPickerPanel.js +29 -4
- package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
- package/dist/fields/color/client/colorField.css +30 -0
- package/dist/fields/color/colorField.js +36 -8
- package/dist/fields/color/colorField.js.map +1 -1
- package/dist/fields/color/presetChip.js +10 -9
- package/dist/fields/color/presetChip.js.map +1 -1
- package/dist/fields/color/presetReference.d.ts +13 -0
- package/dist/fields/color/presetReference.js +94 -0
- package/dist/fields/color/presetReference.js.map +1 -0
- package/dist/fields/color/server/ColorCell.js +7 -1
- package/dist/fields/color/server/ColorCell.js.map +1 -1
- package/dist/fields/color/server/colorCell.css +5 -0
- package/dist/fields/color/valueIssue.js +23 -0
- package/dist/fields/color/valueIssue.js.map +1 -0
- package/dist/fields/encrypted/boot.js +2 -1
- package/dist/fields/encrypted/boot.js.map +1 -1
- package/dist/fields/encrypted/components/EncryptedInput.js +4 -1
- package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -1
- package/dist/fields/encrypted/components/EncryptedTextarea.js +6 -2
- package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -1
- package/dist/fields/encrypted/components/ProtectedCell.d.ts +15 -6
- package/dist/fields/encrypted/components/ProtectedCell.js +37 -8
- package/dist/fields/encrypted/components/ProtectedCell.js.map +1 -1
- package/dist/fields/encrypted/components/ProtectedField.css +134 -39
- package/dist/fields/encrypted/components/ProtectedField.d.ts +3 -0
- package/dist/fields/encrypted/components/ProtectedField.js +14 -0
- package/dist/fields/encrypted/components/ProtectedField.js.map +1 -1
- package/dist/fields/encrypted/components/WriteOnlyActions.js +65 -0
- package/dist/fields/encrypted/components/WriteOnlyActions.js.map +1 -0
- package/dist/fields/encrypted/components/WriteOnlyField.js +286 -0
- package/dist/fields/encrypted/components/WriteOnlyField.js.map +1 -0
- package/dist/fields/encrypted/components/writeOnlyIntent.js +69 -0
- package/dist/fields/encrypted/components/writeOnlyIntent.js.map +1 -0
- package/dist/fields/encrypted/crypto/wire.d.ts +10 -1
- package/dist/fields/encrypted/crypto/wire.js +1 -1
- package/dist/fields/encrypted/encryptedField.js +63 -6
- package/dist/fields/encrypted/encryptedField.js.map +1 -1
- package/dist/fields/encrypted/generateSecret.d.ts +10 -0
- package/dist/fields/encrypted/generateSecret.js +41 -0
- package/dist/fields/encrypted/generateSecret.js.map +1 -0
- package/dist/fields/encrypted/hint.js +67 -0
- package/dist/fields/encrypted/hint.js.map +1 -0
- package/dist/fields/encrypted/hooks.js +59 -31
- package/dist/fields/encrypted/hooks.js.map +1 -1
- package/dist/fields/encrypted/queryRewrite.d.ts +10 -2
- package/dist/fields/encrypted/queryRewrite.js +34 -8
- package/dist/fields/encrypted/queryRewrite.js.map +1 -1
- package/dist/fields/encrypted/rawRead.d.ts +24 -0
- package/dist/fields/encrypted/rawRead.js +40 -0
- package/dist/fields/encrypted/rawRead.js.map +1 -0
- package/dist/fields/encrypted/scan.js +21 -4
- package/dist/fields/encrypted/scan.js.map +1 -1
- package/dist/fields/encrypted/types.d.ts +67 -2
- package/dist/fields/encrypted/types.js +8 -1
- package/dist/fields/encrypted/types.js.map +1 -1
- package/dist/fields/encrypted/utils/decryptAllData.js +2 -2
- package/dist/fields/encrypted/utils/decryptAllData.js.map +1 -1
- package/dist/fields/encrypted/utils/decryptFieldValue.d.ts +30 -0
- package/dist/fields/encrypted/utils/decryptFieldValue.js +56 -0
- package/dist/fields/encrypted/utils/decryptFieldValue.js.map +1 -0
- package/dist/fields/encrypted/utils/readEncryptedField.d.ts +51 -0
- package/dist/fields/encrypted/utils/readEncryptedField.js +96 -0
- package/dist/fields/encrypted/utils/readEncryptedField.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -1
- package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -1
- package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
- package/dist/fields/icon/client/icon-field.css +4 -2
- package/dist/fields/icon/codegen/emit.js +2 -2
- package/dist/fields/icon/codegen/emit.js.map +1 -1
- package/dist/fields/icon/rsc/IconFieldServer.js +1 -1
- package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -1
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js +1 -1
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -1
- package/dist/fields/icon/shared/iconLabel.js +1 -1
- package/dist/fields/icon/shared/iconLabel.js.map +1 -1
- package/dist/fields/measurement/client/MeasurementCell.d.ts +18 -0
- package/dist/fields/measurement/client/MeasurementCell.js +47 -0
- package/dist/fields/measurement/client/MeasurementCell.js.map +1 -0
- package/dist/fields/measurement/client/MeasurementField.d.ts +13 -0
- package/dist/fields/measurement/client/MeasurementField.js +70 -0
- package/dist/fields/measurement/client/MeasurementField.js.map +1 -0
- package/dist/fields/measurement/client/MeasurementInput.d.ts +42 -0
- package/dist/fields/measurement/client/MeasurementInput.js +327 -0
- package/dist/fields/measurement/client/MeasurementInput.js.map +1 -0
- package/dist/fields/measurement/client/MeasurementUnitsProvider.d.ts +24 -0
- package/dist/fields/measurement/client/MeasurementUnitsProvider.js +61 -0
- package/dist/fields/measurement/client/MeasurementUnitsProvider.js.map +1 -0
- package/dist/fields/measurement/client/editModel.js +124 -0
- package/dist/fields/measurement/client/editModel.js.map +1 -0
- package/dist/fields/measurement/client/measurementCell.css +4 -0
- package/dist/fields/measurement/client/measurementField.css +215 -0
- package/dist/fields/measurement/client/useMeasurementModel.d.ts +19 -0
- package/dist/fields/measurement/client/useMeasurementModel.js +85 -0
- package/dist/fields/measurement/client/useMeasurementModel.js.map +1 -0
- package/dist/fields/measurement/engine/convert.d.ts +8 -0
- package/dist/fields/measurement/engine/convert.js +21 -0
- package/dist/fields/measurement/engine/convert.js.map +1 -0
- package/dist/fields/measurement/engine/format.d.ts +37 -0
- package/dist/fields/measurement/engine/format.js +156 -0
- package/dist/fields/measurement/engine/format.js.map +1 -0
- package/dist/fields/measurement/engine/locale.d.ts +25 -0
- package/dist/fields/measurement/engine/locale.js +79 -0
- package/dist/fields/measurement/engine/locale.js.map +1 -0
- package/dist/fields/measurement/engine/precision.d.ts +34 -0
- package/dist/fields/measurement/engine/precision.js +63 -0
- package/dist/fields/measurement/engine/precision.js.map +1 -0
- package/dist/fields/measurement/engine/registry.d.ts +55 -0
- package/dist/fields/measurement/engine/registry.js +117 -0
- package/dist/fields/measurement/engine/registry.js.map +1 -0
- package/dist/fields/measurement/engine/units.d.ts +178 -0
- package/dist/fields/measurement/engine/units.js +198 -0
- package/dist/fields/measurement/engine/units.js.map +1 -0
- package/dist/fields/measurement/measurementField.d.ts +17 -0
- package/dist/fields/measurement/measurementField.js +139 -0
- package/dist/fields/measurement/measurementField.js.map +1 -0
- package/dist/fields/measurement/options.d.ts +76 -0
- package/dist/fields/measurement/options.js +9 -0
- package/dist/fields/measurement/options.js.map +1 -0
- package/dist/fields/measurement/presets.d.ts +117 -0
- package/dist/fields/measurement/presets.js +136 -0
- package/dist/fields/measurement/presets.js.map +1 -0
- package/dist/fields/measurement/server/MeasurementCellServer.d.ts +21 -0
- package/dist/fields/measurement/server/MeasurementCellServer.js +53 -0
- package/dist/fields/measurement/server/MeasurementCellServer.js.map +1 -0
- package/dist/fields/measurement/server/MeasurementFieldServer.d.ts +16 -0
- package/dist/fields/measurement/server/MeasurementFieldServer.js +45 -0
- package/dist/fields/measurement/server/MeasurementFieldServer.js.map +1 -0
- package/dist/fields/measurement/server/getUserUnits.js +39 -0
- package/dist/fields/measurement/server/getUserUnits.js.map +1 -0
- package/dist/fields/measurement/server/resolvePrecisionSafe.js +24 -0
- package/dist/fields/measurement/server/resolvePrecisionSafe.js.map +1 -0
- package/dist/fields/measurement/server/resolveRegistryDefault.js +26 -0
- package/dist/fields/measurement/server/resolveRegistryDefault.js.map +1 -0
- package/dist/fields/phoneNumber/client/CountryFlag.d.ts +16 -0
- package/dist/fields/phoneNumber/client/CountryFlag.js +40 -0
- package/dist/fields/phoneNumber/client/CountryFlag.js.map +1 -0
- package/dist/fields/phoneNumber/client/CountryPicker.d.ts +21 -0
- package/dist/fields/phoneNumber/client/CountryPicker.js +255 -0
- package/dist/fields/phoneNumber/client/CountryPicker.js.map +1 -0
- package/dist/fields/phoneNumber/client/PhoneNumberField.d.ts +26 -0
- package/dist/fields/phoneNumber/client/PhoneNumberField.js +318 -0
- package/dist/fields/phoneNumber/client/PhoneNumberField.js.map +1 -0
- package/dist/fields/phoneNumber/client/editModel.js +86 -0
- package/dist/fields/phoneNumber/client/editModel.js.map +1 -0
- package/dist/fields/phoneNumber/client/phoneNumberField.css +305 -0
- package/dist/fields/phoneNumber/engine/countries.d.ts +36 -0
- package/dist/fields/phoneNumber/engine/countries.js +68 -0
- package/dist/fields/phoneNumber/engine/countries.js.map +1 -0
- package/dist/fields/phoneNumber/engine/draft.d.ts +13 -0
- package/dist/fields/phoneNumber/engine/draft.js +72 -0
- package/dist/fields/phoneNumber/engine/draft.js.map +1 -0
- package/dist/fields/phoneNumber/engine/metadata.d.ts +11 -0
- package/dist/fields/phoneNumber/engine/metadata.js +32 -0
- package/dist/fields/phoneNumber/engine/metadata.js.map +1 -0
- package/dist/fields/phoneNumber/engine/phone.d.ts +37 -0
- package/dist/fields/phoneNumber/engine/phone.js +59 -0
- package/dist/fields/phoneNumber/engine/phone.js.map +1 -0
- package/dist/fields/phoneNumber/options.d.ts +72 -0
- package/dist/fields/phoneNumber/options.js +37 -0
- package/dist/fields/phoneNumber/options.js.map +1 -0
- package/dist/fields/phoneNumber/phoneNumberField.d.ts +14 -0
- package/dist/fields/phoneNumber/phoneNumberField.js +167 -0
- package/dist/fields/phoneNumber/phoneNumberField.js.map +1 -0
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.d.ts +19 -0
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js +73 -0
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js.map +1 -0
- package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.d.ts +16 -0
- package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js +57 -0
- package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js.map +1 -0
- package/dist/fields/phoneNumber/server/flagsEndpoint.js +51 -0
- package/dist/fields/phoneNumber/server/flagsEndpoint.js.map +1 -0
- package/dist/fields/phoneNumber/server/readPhoneOptions.js +18 -0
- package/dist/fields/phoneNumber/server/readPhoneOptions.js.map +1 -0
- package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js +33 -0
- package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +35 -1
- package/dist/index.js.map +1 -1
- package/dist/translations/ar.js +62 -0
- package/dist/translations/ar.js.map +1 -0
- package/dist/translations/de.js +19 -1
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +19 -1
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +62 -0
- package/dist/translations/es.js.map +1 -0
- package/dist/translations/fr.js +62 -0
- package/dist/translations/fr.js.map +1 -0
- package/dist/translations/id.js +62 -0
- package/dist/translations/id.js.map +1 -0
- package/dist/translations/index.d.ts +10 -1
- package/dist/translations/index.js +19 -1
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/keys.d.ts +19 -1
- package/dist/translations/keys.js +20 -2
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +62 -0
- package/dist/translations/ko.js.map +1 -0
- package/dist/translations/pt.js +62 -0
- package/dist/translations/pt.js.map +1 -0
- package/dist/translations/ru.js +62 -0
- package/dist/translations/ru.js.map +1 -0
- package/dist/translations/uk.js +62 -0
- package/dist/translations/uk.js.map +1 -0
- package/dist/translations/zh.js +62 -0
- package/dist/translations/zh.js.map +1 -0
- package/dist/types.d.ts +41 -1
- package/dist/utils/resolveStaticLabel.js +13 -0
- package/dist/utils/resolveStaticLabel.js.map +1 -0
- package/package.json +28 -6
- package/dist/fields/icon/shared/resolveStaticLabel.js +0 -16
- package/dist/fields/icon/shared/resolveStaticLabel.js.map +0 -1
|
@@ -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,19 @@
|
|
|
1
|
+
import { MeasurementPrecision, PrecisionMode } from "../engine/precision.js";
|
|
2
|
+
import { MeasurementUnitId } from "../engine/units.js";
|
|
3
|
+
import { MeasurementResolvedClientOptions } from "../options.js";
|
|
4
|
+
|
|
5
|
+
//#region src/fields/measurement/client/useMeasurementModel.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* What the standalone input needs to know about a measurement. Only `storageUnit` is
|
|
8
|
+
* required: `dimension`, `preferenceKey` and `units` default the way `measurementField`
|
|
9
|
+
* defaults them, and `precision` is merged the way the field merges its own layer.
|
|
10
|
+
*/
|
|
11
|
+
type MeasurementInputOptions = Omit<MeasurementResolvedClientOptions, 'dimension' | 'precision' | 'preferenceKey' | 'units'> & {
|
|
12
|
+
dimension?: string;
|
|
13
|
+
precision?: MeasurementPrecision | PrecisionMode;
|
|
14
|
+
preferenceKey?: string;
|
|
15
|
+
units?: readonly MeasurementUnitId[];
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { MeasurementInputOptions };
|
|
19
|
+
//# sourceMappingURL=useMeasurementModel.d.ts.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { exactModePrecisionOverride, resolvePrecision } from "../engine/precision.js";
|
|
3
|
+
import { useTranslation } from "../../../translations/useTranslation.js";
|
|
4
|
+
import { resolveDisplayUnit, systemForLocale } from "../engine/locale.js";
|
|
5
|
+
import { createEngine, defaultEngine } from "../engine/registry.js";
|
|
6
|
+
import { useMeasurementUnits } from "./MeasurementUnitsProvider.js";
|
|
7
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
8
|
+
//#region src/fields/measurement/client/useMeasurementModel.ts
|
|
9
|
+
/**
|
|
10
|
+
* Engine, display unit and precision for one measurement row. Options are compared by
|
|
11
|
+
* content, so a caller passing an inline object does not rebuild the engine and the
|
|
12
|
+
* draft options every render (which would resync drafts in a loop).
|
|
13
|
+
*/
|
|
14
|
+
const useMeasurementModel = (options) => {
|
|
15
|
+
const optionsKey = JSON.stringify(options);
|
|
16
|
+
const stable = useMemo(() => JSON.parse(optionsKey), [optionsKey]);
|
|
17
|
+
const { custom, fallbackUnit, initialUnit, localeDefaults, registryDefault, storageUnit } = stable;
|
|
18
|
+
const { i18n } = useTranslation();
|
|
19
|
+
const locale = i18n.language;
|
|
20
|
+
const engine = useMemo(() => custom ? createEngine(custom) : defaultEngine, [custom]);
|
|
21
|
+
const dimension = stable.dimension ?? engine.dimensionOf(storageUnit);
|
|
22
|
+
const preferenceKey = stable.preferenceKey ?? dimension;
|
|
23
|
+
const units = useMemo(() => stable.units ?? engine.unitsOfDimension(dimension), [
|
|
24
|
+
dimension,
|
|
25
|
+
engine,
|
|
26
|
+
stable.units
|
|
27
|
+
]);
|
|
28
|
+
const resolvedPrecision = useMemo(() => resolvePrecision([stable.precision]), [stable.precision]);
|
|
29
|
+
const context = useMeasurementUnits();
|
|
30
|
+
const [localUnit, setLocalUnit] = useState(initialUnit ?? null);
|
|
31
|
+
const [system, setSystem] = useState(null);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
setSystem(systemForLocale(navigator.language));
|
|
34
|
+
}, []);
|
|
35
|
+
const displayUnit = resolveDisplayUnit({
|
|
36
|
+
dimension,
|
|
37
|
+
fallbackUnit,
|
|
38
|
+
localeDefaults,
|
|
39
|
+
preferenceUnit: context ? context.units[preferenceKey] ?? (context.ready ? null : initialUnit ?? null) : localUnit,
|
|
40
|
+
registryDefault,
|
|
41
|
+
system,
|
|
42
|
+
units
|
|
43
|
+
});
|
|
44
|
+
const displayPrecision = useMemo(() => exactModePrecisionOverride(resolvedPrecision, displayUnit), [resolvedPrecision, displayUnit]);
|
|
45
|
+
return {
|
|
46
|
+
displayPrecision,
|
|
47
|
+
displayUnit,
|
|
48
|
+
engine,
|
|
49
|
+
fmtBound: useCallback((bound) => {
|
|
50
|
+
try {
|
|
51
|
+
return engine.formatMeasurement(bound, {
|
|
52
|
+
displayUnit,
|
|
53
|
+
locale: `${locale}-u-nu-latn`,
|
|
54
|
+
precision: displayPrecision,
|
|
55
|
+
storageUnit
|
|
56
|
+
});
|
|
57
|
+
} catch {
|
|
58
|
+
return engine.formatMeasurement(bound, {
|
|
59
|
+
displayUnit,
|
|
60
|
+
locale,
|
|
61
|
+
precision: displayPrecision,
|
|
62
|
+
storageUnit
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}, [
|
|
66
|
+
displayUnit,
|
|
67
|
+
engine,
|
|
68
|
+
locale,
|
|
69
|
+
displayPrecision,
|
|
70
|
+
storageUnit
|
|
71
|
+
]),
|
|
72
|
+
locale,
|
|
73
|
+
resolvedPrecision,
|
|
74
|
+
selectUnit: useCallback((unit) => {
|
|
75
|
+
if (context) context.setUnit(preferenceKey, unit);
|
|
76
|
+
else setLocalUnit(unit);
|
|
77
|
+
}, [context, preferenceKey]),
|
|
78
|
+
storageUnit,
|
|
79
|
+
units
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
//#endregion
|
|
83
|
+
export { useMeasurementModel };
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=useMeasurementModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMeasurementModel.js","names":[],"sources":["../../../../src/fields/measurement/client/useMeasurementModel.ts"],"sourcesContent":["'use client'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport { type MeasurementSystem, systemForLocale } from '../engine/locale'\nimport {\n\texactModePrecisionOverride,\n\ttype MeasurementPrecision,\n\ttype PrecisionMode,\n\tresolvePrecision,\n} from '../engine/precision'\nimport { createEngine, defaultEngine } from '../engine/registry'\nimport type { MeasurementUnitId } from '../engine/units'\nimport type { MeasurementResolvedClientOptions } from '../options'\nimport { resolveDisplayUnit } from './editModel'\nimport { useMeasurementUnits } from './MeasurementUnitsProvider'\n\n/**\n * What the standalone input needs to know about a measurement. Only `storageUnit` is\n * required: `dimension`, `preferenceKey` and `units` default the way `measurementField`\n * defaults them, and `precision` is merged the way the field merges its own layer.\n */\nexport type MeasurementInputOptions = Omit<\n\tMeasurementResolvedClientOptions,\n\t'dimension' | 'precision' | 'preferenceKey' | 'units'\n> & {\n\tdimension?: string\n\tprecision?: MeasurementPrecision | PrecisionMode\n\tpreferenceKey?: string\n\tunits?: readonly MeasurementUnitId[]\n}\n\n/**\n * Engine, display unit and precision for one measurement row. Options are compared by\n * content, so a caller passing an inline object does not rebuild the engine and the\n * draft options every render (which would resync drafts in a loop).\n */\nexport const useMeasurementModel = (options: MeasurementInputOptions) => {\n\tconst optionsKey = JSON.stringify(options)\n\tconst stable = useMemo<MeasurementInputOptions>(() => JSON.parse(optionsKey), [optionsKey])\n\tconst { custom, fallbackUnit, initialUnit, localeDefaults, registryDefault, storageUnit } = stable\n\tconst { i18n } = useTranslation()\n\tconst locale = i18n.language\n\n\t// Every conversion, label and precision lookup runs through this, so the\n\t// field's custom units behave exactly like the built-in ones.\n\tconst engine = useMemo(() => (custom ? createEngine(custom) : defaultEngine), [custom])\n\tconst dimension = stable.dimension ?? engine.dimensionOf(storageUnit)\n\tconst preferenceKey = stable.preferenceKey ?? dimension\n\tconst units = useMemo(\n\t\t() => stable.units ?? engine.unitsOfDimension(dimension),\n\t\t[dimension, engine, stable.units]\n\t)\n\tconst resolvedPrecision = useMemo(() => resolvePrecision([stable.precision]), [stable.precision])\n\n\tconst context = useMeasurementUnits()\n\t// Session-only fallback when the plugin (and so the provider) is absent\n\tconst [localUnit, setLocalUnit] = useState<MeasurementUnitId | null>(initialUnit ?? null)\n\t// navigator is read post-hydration only, or SSR markup would mismatch\n\tconst [system, setSystem] = useState<MeasurementSystem | null>(null)\n\tuseEffect(() => {\n\t\tsetSystem(systemForLocale(navigator.language))\n\t}, [])\n\n\tconst preferenceUnit = context\n\t\t? (context.units[preferenceKey] ?? (context.ready ? null : (initialUnit ?? null)))\n\t\t: localUnit\n\tconst displayUnit = resolveDisplayUnit({\n\t\tdimension,\n\t\tfallbackUnit,\n\t\tlocaleDefaults,\n\t\tpreferenceUnit,\n\t\tregistryDefault,\n\t\tsystem,\n\t\tunits,\n\t})\n\n\t// Bound messages sit next to a type=number input, which always renders Latin\n\t// digits; force the same numerals here so \"min 5\" and \"5\" agree in RTL/native-digit\n\t// locales (Arabic, Persian). The input itself stays native-digit for display. Exact\n\t// mode uses the same storage-digit override as the cell, so error text and cell\n\t// text always agree. Memoized: exact mode builds a fresh object every call, and an\n\t// unmemoized value here fed draftOpts -> the resync effect -> setDrafts in a loop\n\t// that never settled.\n\tconst displayPrecision = useMemo(\n\t\t() => exactModePrecisionOverride(resolvedPrecision, displayUnit),\n\t\t[resolvedPrecision, displayUnit]\n\t)\n\tconst fmtBound = useCallback(\n\t\t(bound: number) => {\n\t\t\ttry {\n\t\t\t\treturn engine.formatMeasurement(bound, {\n\t\t\t\t\tdisplayUnit,\n\t\t\t\t\tlocale: `${locale}-u-nu-latn`,\n\t\t\t\t\tprecision: displayPrecision,\n\t\t\t\t\tstorageUnit,\n\t\t\t\t})\n\t\t\t} catch {\n\t\t\t\treturn engine.formatMeasurement(bound, {\n\t\t\t\t\tdisplayUnit,\n\t\t\t\t\tlocale,\n\t\t\t\t\tprecision: displayPrecision,\n\t\t\t\t\tstorageUnit,\n\t\t\t\t})\n\t\t\t}\n\t\t},\n\t\t[displayUnit, engine, locale, displayPrecision, storageUnit]\n\t)\n\n\tconst selectUnit = useCallback(\n\t\t(unit: MeasurementUnitId) => {\n\t\t\tif (context) context.setUnit(preferenceKey, unit)\n\t\t\telse setLocalUnit(unit)\n\t\t},\n\t\t[context, preferenceKey]\n\t)\n\n\treturn {\n\t\tdisplayPrecision,\n\t\tdisplayUnit,\n\t\tengine,\n\t\tfmtBound,\n\t\tlocale,\n\t\tresolvedPrecision,\n\t\tselectUnit,\n\t\tstorageUnit,\n\t\tunits,\n\t}\n}\n\nexport type MeasurementModel = ReturnType<typeof useMeasurementModel>\n"],"mappings":";;;;;;;;;;;;;AAoCA,MAAa,uBAAuB,YAAqC;CACxE,MAAM,aAAa,KAAK,UAAU,OAAO;CACzC,MAAM,SAAS,cAAuC,KAAK,MAAM,UAAU,GAAG,CAAC,UAAU,CAAC;CAC1F,MAAM,EAAE,QAAQ,cAAc,aAAa,gBAAgB,iBAAiB,gBAAgB;CAC5F,MAAM,EAAE,SAAS,eAAe;CAChC,MAAM,SAAS,KAAK;CAIpB,MAAM,SAAS,cAAe,SAAS,aAAa,MAAM,IAAI,eAAgB,CAAC,MAAM,CAAC;CACtF,MAAM,YAAY,OAAO,aAAa,OAAO,YAAY,WAAW;CACpE,MAAM,gBAAgB,OAAO,iBAAiB;CAC9C,MAAM,QAAQ,cACP,OAAO,SAAS,OAAO,iBAAiB,SAAS,GACvD;EAAC;EAAW;EAAQ,OAAO;CAAK,CACjC;CACA,MAAM,oBAAoB,cAAc,iBAAiB,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,OAAO,SAAS,CAAC;CAEhG,MAAM,UAAU,oBAAoB;CAEpC,MAAM,CAAC,WAAW,gBAAgB,SAAmC,eAAe,IAAI;CAExF,MAAM,CAAC,QAAQ,aAAa,SAAmC,IAAI;CACnE,gBAAgB;EACf,UAAU,gBAAgB,UAAU,QAAQ,CAAC;CAC9C,GAAG,CAAC,CAAC;CAKL,MAAM,cAAc,mBAAmB;EACtC;EACA;EACA;EACA,gBAPsB,UACnB,QAAQ,MAAM,mBAAmB,QAAQ,QAAQ,OAAQ,eAAe,QACzE;EAMF;EACA;EACA;CACD,CAAC;CASD,MAAM,mBAAmB,cAClB,2BAA2B,mBAAmB,WAAW,GAC/D,CAAC,mBAAmB,WAAW,CAChC;CA8BA,OAAO;EACN;EACA;EACA;EACA,UAjCgB,aACf,UAAkB;GAClB,IAAI;IACH,OAAO,OAAO,kBAAkB,OAAO;KACtC;KACA,QAAQ,GAAG,OAAO;KAClB,WAAW;KACX;IACD,CAAC;GACF,QAAQ;IACP,OAAO,OAAO,kBAAkB,OAAO;KACtC;KACA;KACA,WAAW;KACX;IACD,CAAC;GACF;EACD,GACA;GAAC;GAAa;GAAQ;GAAQ;GAAkB;EAAW,CAepD;EACP;EACA;EACA,YAfkB,aACjB,SAA4B;GAC5B,IAAI,SAAS,QAAQ,QAAQ,eAAe,IAAI;QAC3C,aAAa,IAAI;EACvB,GACA,CAAC,SAAS,aAAa,CAUd;EACT;EACA;CACD;AACD"}
|
|
@@ -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,MAAM,2BAA2B;AACjC,MAAM,oCAAoB,IAAI,IAA+B;AAC7D,MAAM,kCAAkB,IAAI,IAA6B;AAEzD,MAAM,sBACL,QACA,YACuB;CACvB,MAAM,MAAM,GAAG,OAAO,GAAG,QAAQ,SAAS,GAAG,GAAG,QAAQ,QAAQ,GAAG,GAAG,QAAQ,eAAe,GAAG,GAAG,QAAQ,yBAAyB;CACpI,MAAM,SAAS,kBAAkB,IAAI,GAAG;CACxC,IAAI,QAAQ,OAAO;CACnB,IAAI,kBAAkB,QAAQ,0BAA0B,kBAAkB,MAAM;CAChF,MAAM,YAAY,IAAI,KAAK,aAAa,QAAQ,OAAO;CACvD,kBAAkB,IAAI,KAAK,SAAS;CACpC,OAAO;AACR;AAEA,MAAM,oBAAoB,QAAgB,UAA8C;CACvF,MAAM,MAAM,GAAG,OAAO,GAAG;CACzB,MAAM,SAAS,gBAAgB,IAAI,GAAG;CACtC,IAAI,QAAQ,OAAO;CACnB,IAAI,gBAAgB,QAAQ,0BAA0B,gBAAgB,MAAM;CAC5E,MAAM,YAAY,IAAI,KAAK,WAAW,QAAQ;EAAE;EAAO,MAAM;CAAO,CAAC;CACrE,gBAAgB,IAAI,KAAK,SAAS;CAClC,OAAO;AACR;AAGA,MAAM,mBACL,MACA,QACA,QACA,gBAEA,mBAAmB,QAAQ;CAC1B,uBAAuB;CACvB,OAAO;CACP,MAAM,MAAM,MAAM;CAClB;AACD,CAAC;;AAiBF,MAAa,qBAAqB,OAAe,SAAsC;CACtF,MAAM,EAAE,QAAQ,QAAQ,MAAM,gBAAgB;CAC9C,IAAI,KAAK,aAAa,MAAM;EAC3B,MAAM,QAAQ,sBAAsB,KAAK,YAAY,MAAM;EAC3D,OAAO,GAAG,mBAAmB,QAAQ,EAAE,uBAAuB,OAAO,CAAC,EAAE,OAAO,KAAK,EAAE,GAAG;CAC1F;CACA,OAAO,mBAAmB,QAAQ;EACjC,uBAAuB;EACvB,OAAO;EACP,MAAM,KAAK;EACX;CACD,CAAC,EAAE,OAAO,KAAK;AAChB;AAEA,MAAM,aAAa,OAAiB,WAA2B;CAC9D,IAAI;EACH,OAAO,iBAAiB,QAAQ,QAAQ,EAAE,OAAO,KAAK;CACvD,QAAQ;EACP,OAAO,MAAM,KAAK,GAAG;CACtB;AACD;AAEA,MAAa,qBAAqB,OAAe,SAA2C;CAC3F,MAAM,EAAE,aAAa,QAAQ,WAAW,aAAa,cAAc,YAAY;CAC/E,IAAI,eAAe,WAAW,GAAG;EAChC,MAAM,MAAM,UAAU;EACtB,MAAM,EAAE,OAAO,UAAU,UACxB,OACA,aACA,aACA,aAAa,aAAa,SAAS,CACpC;EAQA,OAAO,UAAU,CAPC,gBAAgB,IAAI,OAAO,QAAQ,GAAG,WAAW,EAAE,OAAO,KAOlD,GANR,gBACjB,IAAI,OACJ,QACA,aAAa,aAAa,SAAS,GACnC,WACD,EAAE,OAAO,KAC4B,CAAC,GAAG,MAAM;CAChD;CACA,MAAM,SAAS,aAAa,aAAa,SAAS;CAClD,OAAO,kBAAkB,QAAQ,QAAQ,OAAO,aAAa,WAAW,GAAG,MAAM,GAAG;EACnF;EACA;EACA,MAAM,MAAM;EACZ;CACD,CAAC;AACF;;AAGA,MAAM,kBAAkB,MAAuB,WAC9C,sBAAsB,KAAK,aAAa,KAAK,YAAY,MAAM;;AAGhE,MAAa,sBAAsB,MAAuB,WAA2B;CACpF,IAAI,KAAK,aAAa,MAAM,OAAO,eAAe,MAAM,MAAM;CAO9D,OANc,mBAAmB,QAAQ;EACxC,OAAO;EACP,MAAM,KAAK;EACX,aAAa;CACd,CAAC,EAAE,cAAc,CACI,EAAE,MAAM,SAAS,KAAK,SAAS,MACtC,GAAG,SAAS,eAAe,MAAM,MAAM;AACtD;;;;;AAMA,MAAa,uBAAuB,MAAuB,WAA2B;CACrF,IAAI,KAAK,aAAa,MAAM,OAAO,sBAAsB,KAAK,YAAY,MAAM;CAOhF,OANc,mBAAmB,QAAQ;EACxC,OAAO;EACP,MAAM,KAAK;EACX,aAAa;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
|