@reekon-tools/boldr-utils 1.9.5 → 1.9.6

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.
@@ -16,13 +16,34 @@ export interface CalculatorUnitInfo {
16
16
  mathUnit: string;
17
17
  /** Short display label, e.g. 'ft³'. */
18
18
  label: string;
19
+ /**
20
+ * Disambiguating suffix for the length units that share a `label`. Decimal
21
+ * and fractional inches are distinct display units but both read as 'in'
22
+ * (and both feet-inches units as 'ft-in'), so a picker listing a field's
23
+ * allowed units shows two identical-looking rows without this.
24
+ */
25
+ qualifier?: 'dec' | 'frac';
19
26
  }
20
27
  export declare const CALCULATOR_UNIT_INFO: Record<CalculatorUnit, CalculatorUnitInfo>;
21
28
  /** The math.js token for a dimension's canonical unit. '' for dimensionless. */
22
29
  export declare const canonicalMathUnit: (dimension: FieldDimension) => string;
23
30
  export declare const unitDimension: (unit: CalculatorUnit) => FieldDimension;
24
31
  export declare const unitsForDimension: (dimension: FieldDimension) => CalculatorUnit[];
25
- /** Short label for a unit ('ft³', 'in', '°'). */
32
+ /**
33
+ * A unit's token and its disambiguating qualifier as separate pieces. The
34
+ * compact unit chip is fixed-width, so it stacks the qualifier beneath the
35
+ * token instead of widening; everything else wants the joined form below.
36
+ * `qualifier` is null for every unit that isn't ambiguous.
37
+ */
38
+ export declare const calculatorUnitLabelParts: (unit: CalculatorUnit) => {
39
+ label: string;
40
+ qualifier: string | null;
41
+ };
42
+ /**
43
+ * Short label for a unit ('ft³', 'in frac', '°'). Note this is the label a
44
+ * user PICKS a unit by — `formatCanonical` keeps returning the bare token, so
45
+ * a rendered value stays "12 1/2 in", not "12 1/2 in frac".
46
+ */
26
47
  export declare const calculatorUnitLabel: (unit: CalculatorUnit) => string;
27
48
  /** Convert a display-unit numeric value to the dimension's canonical unit. */
28
49
  export declare const toCanonical: (value: number, unit: CalculatorUnit) => number;
@@ -7,22 +7,30 @@ const LENGTH_UNIT_INFO = {
7
7
  [Units.Millimeters]: { dimension: 'length', mathUnit: 'mm', label: 'mm' },
8
8
  [Units.Centimeters]: { dimension: 'length', mathUnit: 'cm', label: 'cm' },
9
9
  [Units.Meters]: { dimension: 'length', mathUnit: 'm', label: 'm' },
10
- [Units.Inches]: { dimension: 'length', mathUnit: 'in', label: 'in' },
10
+ [Units.Inches]: {
11
+ dimension: 'length',
12
+ mathUnit: 'in',
13
+ label: 'in',
14
+ qualifier: 'dec',
15
+ },
11
16
  [Units.FractionalInches]: {
12
17
  dimension: 'length',
13
18
  mathUnit: 'in',
14
19
  label: 'in',
20
+ qualifier: 'frac',
15
21
  },
16
22
  [Units.Feet]: { dimension: 'length', mathUnit: 'ft', label: 'ft' },
17
23
  [Units.FeetInchesDecimal]: {
18
24
  dimension: 'length',
19
25
  mathUnit: 'ft',
20
26
  label: 'ft-in',
27
+ qualifier: 'dec',
21
28
  },
22
29
  [Units.FeetInchesFractional]: {
23
30
  dimension: 'length',
24
31
  mathUnit: 'ft',
25
32
  label: 'ft-in',
33
+ qualifier: 'frac',
26
34
  },
27
35
  };
28
36
  export const CALCULATOR_UNIT_INFO = {
@@ -61,10 +69,30 @@ export const canonicalMathUnit = (dimension) => {
61
69
  };
62
70
  export const unitDimension = (unit) => CALCULATOR_UNIT_INFO[unit]?.dimension ?? 'none';
63
71
  export const unitsForDimension = (dimension) => Object.keys(CALCULATOR_UNIT_INFO).filter((u) => CALCULATOR_UNIT_INFO[u].dimension === dimension);
64
- /** Short label for a unit ('ft³', 'in', '°'). */
72
+ /**
73
+ * A unit's token and its disambiguating qualifier as separate pieces. The
74
+ * compact unit chip is fixed-width, so it stacks the qualifier beneath the
75
+ * token instead of widening; everything else wants the joined form below.
76
+ * `qualifier` is null for every unit that isn't ambiguous.
77
+ */
78
+ export const calculatorUnitLabelParts = (unit) => {
79
+ const info = CALCULATOR_UNIT_INFO[unit];
80
+ if (!info) {
81
+ return {
82
+ label: convertUnitsToReadableShort(unit) ?? String(unit),
83
+ qualifier: null,
84
+ };
85
+ }
86
+ return { label: info.label, qualifier: info.qualifier ?? null };
87
+ };
88
+ /**
89
+ * Short label for a unit ('ft³', 'in frac', '°'). Note this is the label a
90
+ * user PICKS a unit by — `formatCanonical` keeps returning the bare token, so
91
+ * a rendered value stays "12 1/2 in", not "12 1/2 in frac".
92
+ */
65
93
  export const calculatorUnitLabel = (unit) => {
66
- const lengthLabel = convertUnitsToReadableShort(unit);
67
- return CALCULATOR_UNIT_INFO[unit]?.label ?? lengthLabel ?? String(unit);
94
+ const { label, qualifier } = calculatorUnitLabelParts(unit);
95
+ return qualifier ? `${label} ${qualifier}` : label;
68
96
  };
69
97
  // All units here are pure scale factors relative to their canonical unit
70
98
  // (no affine offsets like °F), so conversion is a cached multiply.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reekon-tools/boldr-utils",
3
- "version": "1.9.5",
3
+ "version": "1.9.6",
4
4
  "description": "Shared utilities for formulas and measurement conversion used in Reekon apps",
5
5
  "author": "REEKON Tools",
6
6
  "license": "MIT",