@ni/nimble-components 20.17.7 → 20.18.1

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 (88) hide show
  1. package/dist/all-components-bundle.js +599 -163
  2. package/dist/all-components-bundle.js.map +1 -1
  3. package/dist/all-components-bundle.min.js +1151 -1107
  4. package/dist/all-components-bundle.min.js.map +1 -1
  5. package/dist/esm/all-components.d.ts +2 -0
  6. package/dist/esm/all-components.js +2 -0
  7. package/dist/esm/all-components.js.map +1 -1
  8. package/dist/esm/rich-text/base/index.js +2 -4
  9. package/dist/esm/rich-text/base/index.js.map +1 -1
  10. package/dist/esm/table/index.js +2 -4
  11. package/dist/esm/table/index.js.map +1 -1
  12. package/dist/esm/table-column/number-text/cell-view/index.js +1 -2
  13. package/dist/esm/table-column/number-text/cell-view/index.js.map +1 -1
  14. package/dist/esm/table-column/number-text/group-header-view/index.js +1 -2
  15. package/dist/esm/table-column/number-text/group-header-view/index.js.map +1 -1
  16. package/dist/esm/table-column/number-text/index.d.ts +11 -2
  17. package/dist/esm/table-column/number-text/index.js +61 -14
  18. package/dist/esm/table-column/number-text/index.js.map +1 -1
  19. package/dist/esm/table-column/number-text/models/table-column-number-text-validator.d.ts +2 -1
  20. package/dist/esm/table-column/number-text/models/table-column-number-text-validator.js +6 -1
  21. package/dist/esm/table-column/number-text/models/table-column-number-text-validator.js.map +1 -1
  22. package/dist/esm/table-column/number-text/template.d.ts +2 -0
  23. package/dist/esm/table-column/number-text/template.js +14 -0
  24. package/dist/esm/table-column/number-text/template.js.map +1 -0
  25. package/dist/esm/unit/base/template.d.ts +1 -0
  26. package/dist/esm/unit/base/template.js +3 -0
  27. package/dist/esm/unit/base/template.js.map +1 -0
  28. package/dist/esm/unit/base/unit.d.ts +9 -0
  29. package/dist/esm/unit/base/unit.js +12 -0
  30. package/dist/esm/unit/base/unit.js.map +1 -0
  31. package/dist/esm/unit/byte/index.d.ts +19 -0
  32. package/dist/esm/unit/byte/index.js +36 -0
  33. package/dist/esm/unit/byte/index.js.map +1 -0
  34. package/dist/esm/unit/volt/index.d.ts +13 -0
  35. package/dist/esm/unit/volt/index.js +20 -0
  36. package/dist/esm/unit/volt/index.js.map +1 -0
  37. package/dist/esm/utilities/unit-format/decimal-unit-format.d.ts +22 -0
  38. package/dist/esm/utilities/unit-format/decimal-unit-format.js +51 -0
  39. package/dist/esm/utilities/unit-format/decimal-unit-format.js.map +1 -0
  40. package/dist/esm/utilities/unit-format/default-unit-format.d.ts +21 -0
  41. package/dist/esm/utilities/unit-format/default-unit-format.js +102 -0
  42. package/dist/esm/utilities/unit-format/default-unit-format.js.map +1 -0
  43. package/dist/esm/utilities/unit-format/scaled-unit/scaled-unit.d.ts +16 -0
  44. package/dist/esm/utilities/unit-format/scaled-unit/scaled-unit.js +13 -0
  45. package/dist/esm/utilities/unit-format/scaled-unit/scaled-unit.js.map +1 -0
  46. package/dist/esm/utilities/unit-format/scaled-unit-format/intl-number-format-scaled-unit-format.d.ts +11 -0
  47. package/dist/esm/utilities/unit-format/scaled-unit-format/intl-number-format-scaled-unit-format.js +21 -0
  48. package/dist/esm/utilities/unit-format/scaled-unit-format/intl-number-format-scaled-unit-format.js.map +1 -0
  49. package/dist/esm/utilities/unit-format/scaled-unit-format/manually-translated-scaled-unit-format.d.ts +43 -0
  50. package/dist/esm/utilities/unit-format/scaled-unit-format/manually-translated-scaled-unit-format.js +62 -0
  51. package/dist/esm/utilities/unit-format/scaled-unit-format/manually-translated-scaled-unit-format.js.map +1 -0
  52. package/dist/esm/utilities/unit-format/scaled-unit-format/scaled-unit-format.d.ts +10 -0
  53. package/dist/esm/utilities/unit-format/scaled-unit-format/scaled-unit-format.js +10 -0
  54. package/dist/esm/utilities/unit-format/scaled-unit-format/scaled-unit-format.js.map +1 -0
  55. package/dist/esm/utilities/unit-format/unit-format.d.ts +16 -0
  56. package/dist/esm/utilities/unit-format/unit-format.js +21 -0
  57. package/dist/esm/utilities/unit-format/unit-format.js.map +1 -0
  58. package/dist/esm/utilities/unit-format/unit-scale/byte-1024-unit-scale.d.ts +9 -0
  59. package/dist/esm/utilities/unit-format/unit-scale/byte-1024-unit-scale.js +31 -0
  60. package/dist/esm/utilities/unit-format/unit-scale/byte-1024-unit-scale.js.map +1 -0
  61. package/dist/esm/utilities/unit-format/unit-scale/byte-unit-scale.d.ts +9 -0
  62. package/dist/esm/utilities/unit-format/unit-scale/byte-unit-scale.js +25 -0
  63. package/dist/esm/utilities/unit-format/unit-scale/byte-unit-scale.js.map +1 -0
  64. package/dist/esm/utilities/unit-format/unit-scale/passthrough-unit-scale.d.ts +9 -0
  65. package/dist/esm/utilities/unit-format/unit-scale/passthrough-unit-scale.js +15 -0
  66. package/dist/esm/utilities/unit-format/unit-scale/passthrough-unit-scale.js.map +1 -0
  67. package/dist/esm/utilities/unit-format/unit-scale/unit-scale.d.ts +15 -0
  68. package/dist/esm/utilities/unit-format/unit-scale/unit-scale.js +49 -0
  69. package/dist/esm/utilities/unit-format/unit-scale/unit-scale.js.map +1 -0
  70. package/dist/esm/utilities/unit-format/unit-scale/utilities/metrix-prefixes.d.ts +1 -0
  71. package/dist/esm/utilities/unit-format/unit-scale/utilities/metrix-prefixes.js +17 -0
  72. package/dist/esm/utilities/unit-format/unit-scale/utilities/metrix-prefixes.js.map +1 -0
  73. package/dist/esm/utilities/unit-format/unit-scale/volt-unit-scale.d.ts +9 -0
  74. package/dist/esm/utilities/unit-format/unit-scale/volt-unit-scale.js +24 -0
  75. package/dist/esm/utilities/unit-format/unit-scale/volt-unit-scale.js.map +1 -0
  76. package/dist/esm/utilities/wait-until-custom-elements-defined-async.d.ts +1 -0
  77. package/dist/esm/utilities/wait-until-custom-elements-defined-async.js +7 -0
  78. package/dist/esm/utilities/wait-until-custom-elements-defined-async.js.map +1 -0
  79. package/package.json +1 -1
  80. package/dist/esm/table-column/number-text/models/decimal-formatter.d.ts +0 -11
  81. package/dist/esm/table-column/number-text/models/decimal-formatter.js +0 -27
  82. package/dist/esm/table-column/number-text/models/decimal-formatter.js.map +0 -1
  83. package/dist/esm/table-column/number-text/models/default-formatter.d.ts +0 -15
  84. package/dist/esm/table-column/number-text/models/default-formatter.js +0 -55
  85. package/dist/esm/table-column/number-text/models/default-formatter.js.map +0 -1
  86. package/dist/esm/table-column/number-text/models/number-formatter.d.ts +0 -11
  87. package/dist/esm/table-column/number-text/models/number-formatter.js +0 -21
  88. package/dist/esm/table-column/number-text/models/number-formatter.js.map +0 -1
@@ -0,0 +1,13 @@
1
+ import { Unit } from '../base/unit';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ 'nimble-unit-volt': UnitVolt;
5
+ }
6
+ }
7
+ /**
8
+ * Element representing units for volts
9
+ */
10
+ export declare class UnitVolt extends Unit {
11
+ constructor();
12
+ }
13
+ export declare const unitVoltTag = "nimble-unit-volt";
@@ -0,0 +1,20 @@
1
+ import { DesignSystem } from '@microsoft/fast-foundation';
2
+ import { template } from '../base/template';
3
+ import { Unit } from '../base/unit';
4
+ import { voltUnitScale } from '../../utilities/unit-format/unit-scale/volt-unit-scale';
5
+ /**
6
+ * Element representing units for volts
7
+ */
8
+ export class UnitVolt extends Unit {
9
+ constructor() {
10
+ super();
11
+ this.resolvedUnitScale = voltUnitScale;
12
+ }
13
+ }
14
+ const nimbleUnitVolt = UnitVolt.compose({
15
+ baseName: 'unit-volt',
16
+ template
17
+ });
18
+ DesignSystem.getOrCreate().withPrefix('nimble').register(nimbleUnitVolt());
19
+ export const unitVoltTag = 'nimble-unit-volt';
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit/volt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,wDAAwD,CAAC;AAQvF;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,IAAI;IAC9B;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,iBAAiB,GAAG,aAAa,CAAC;IAC3C,CAAC;CACJ;AAED,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC;IACpC,QAAQ,EAAE,WAAW;IACrB,QAAQ;CACX,CAAC,CAAC;AAEH,YAAY,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC;AAC3E,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { UnitFormat, UnitFormatOptions } from './unit-format';
2
+ import type { UnitScale } from './unit-scale/unit-scale';
3
+ interface DecimalUnitFormatOptions extends UnitFormatOptions {
4
+ minimumFractionDigits?: number;
5
+ maximumFractionDigits?: number;
6
+ unitScale?: UnitScale;
7
+ }
8
+ /**
9
+ * Format for decimal numbers with units.
10
+ */
11
+ export declare class DecimalUnitFormat extends UnitFormat<DecimalUnitFormatOptions> {
12
+ private readonly unitScale;
13
+ private readonly minimumFractionDigits;
14
+ private readonly maximumFractionDigits;
15
+ private readonly scaledUnitFormatters;
16
+ private readonly tenPowDecimalDigits;
17
+ constructor(locale: string, { minimumFractionDigits, maximumFractionDigits, unitScale }?: DecimalUnitFormatOptions);
18
+ resolvedOptions(): Required<DecimalUnitFormatOptions>;
19
+ protected tryFormat(number: number): string;
20
+ private willRoundToZero;
21
+ }
22
+ export {};
@@ -0,0 +1,51 @@
1
+ import { UnitFormat } from './unit-format';
2
+ import { passthroughUnitScale } from './unit-scale/passthrough-unit-scale';
3
+ /**
4
+ * Format for decimal numbers with units.
5
+ */
6
+ export class DecimalUnitFormat extends UnitFormat {
7
+ constructor(locale, { minimumFractionDigits = 0, maximumFractionDigits = Math.max(3, minimumFractionDigits), unitScale = passthroughUnitScale } = {
8
+ minimumFractionDigits: 0,
9
+ maximumFractionDigits: 3,
10
+ unitScale: passthroughUnitScale
11
+ }) {
12
+ super();
13
+ this.scaledUnitFormatters = new Map();
14
+ const intlNumberFormatOptions = {
15
+ maximumFractionDigits,
16
+ minimumFractionDigits,
17
+ useGrouping: true
18
+ };
19
+ for (const scaledUnit of unitScale.supportedScaledUnits) {
20
+ this.scaledUnitFormatters.set(scaledUnit.scaleFactor, scaledUnit.scaledUnitFormatFactory({
21
+ locale,
22
+ intlNumberFormatOptions
23
+ }));
24
+ }
25
+ this.tenPowDecimalDigits = 10 ** maximumFractionDigits;
26
+ this.unitScale = unitScale;
27
+ this.minimumFractionDigits = minimumFractionDigits;
28
+ this.maximumFractionDigits = maximumFractionDigits;
29
+ }
30
+ resolvedOptions() {
31
+ return {
32
+ unitScale: this.unitScale,
33
+ maximumFractionDigits: this.maximumFractionDigits,
34
+ minimumFractionDigits: this.minimumFractionDigits
35
+ };
36
+ }
37
+ tryFormat(number) {
38
+ const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(number);
39
+ const numberNormalized = this.willRoundToZero(scaledValue)
40
+ ? 0
41
+ : scaledValue;
42
+ const scaledUnitFormatter = this.scaledUnitFormatters.get(scaledUnit.scaleFactor);
43
+ return scaledUnitFormatter.format(numberNormalized);
44
+ }
45
+ willRoundToZero(number) {
46
+ // Multiply the value by 10 raised to maximumFractionDigits so that Math.round can be used to emulate rounding to
47
+ // maximumFractionDigits decimal places. If that rounded value is 0, then the value will be rendered with only 0s.
48
+ return Math.round(number * this.tenPowDecimalDigits) === 0;
49
+ }
50
+ }
51
+ //# sourceMappingURL=decimal-unit-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decimal-unit-format.js","sourceRoot":"","sources":["../../../../src/utilities/unit-format/decimal-unit-format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,eAAe,CAAC;AAG9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCA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CAAC;YACtD,CAAC,CAAC,CAAC;YACH,CAAC,CAAC,WAAW,CAAC;QAClB,MAAM,mBAAmB,GAAG,IAAI,CAAC,oBAAoB,CAAC,GAAG,CACrD,UAAU,CAAC,WAAW,CACxB,CAAC;QACH,OAAO,mBAAmB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IACxD,CAAC;IAEO,eAAe,CAAC,MAAc;QAClC,iHAAiH;QACjH,kHAAkH;QAClH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC/D,CAAC;CACJ"}
@@ -0,0 +1,21 @@
1
+ import { UnitFormat, UnitFormatOptions } from './unit-format';
2
+ /**
3
+ * Format for numbers with units to show in a tabular form.
4
+ * Large and tiny numbers are shown exponentially and the rest as decimal.
5
+ */
6
+ export declare class DefaultUnitFormat extends UnitFormat {
7
+ private static readonly maximumDigits;
8
+ private static readonly exponentialLowerBound;
9
+ private static readonly exponentialUpperBound;
10
+ private readonly unitScale;
11
+ private readonly defaultIntlNumberFormatOptions;
12
+ private readonly defaultScaledUnitFormatters;
13
+ private readonly leadingZeroIntlNumberFormatOptions;
14
+ private readonly leadingZeroScaledUnitFormatters;
15
+ private readonly exponentialIntlNumberFormatOptions;
16
+ private readonly exponentialScaledUnitFormatter;
17
+ constructor(locale: string, { unitScale }?: UnitFormatOptions);
18
+ resolvedOptions(): Required<UnitFormatOptions>;
19
+ protected tryFormat(number: number): string;
20
+ private resolveNumberStyle;
21
+ }
@@ -0,0 +1,102 @@
1
+ import { UnitFormat } from './unit-format';
2
+ import { passthroughUnitScale } from './unit-scale/passthrough-unit-scale';
3
+ /**
4
+ * Format for numbers with units to show in a tabular form.
5
+ * Large and tiny numbers are shown exponentially and the rest as decimal.
6
+ */
7
+ export class DefaultUnitFormat extends UnitFormat {
8
+ constructor(locale, { unitScale = passthroughUnitScale } = {
9
+ unitScale: passthroughUnitScale
10
+ }) {
11
+ super();
12
+ // Format options to use by default. It renders the number with a maximum of 6 signficant digits.
13
+ this.defaultIntlNumberFormatOptions = {
14
+ maximumSignificantDigits: DefaultUnitFormat.maximumDigits,
15
+ useGrouping: true
16
+ };
17
+ this.defaultScaledUnitFormatters = new Map();
18
+ // Format options to use for numbers that have leading zeros. It limits the number of rendered
19
+ // digits using 'maximumFractionDigits', which will result in less than 6 significant digits
20
+ // in order to render no more than 6 total digits.
21
+ this.leadingZeroIntlNumberFormatOptions = {
22
+ maximumFractionDigits: DefaultUnitFormat.maximumDigits - 1,
23
+ useGrouping: true
24
+ };
25
+ this.leadingZeroScaledUnitFormatters = new Map();
26
+ // Format options for numbers that should be displayed in exponential notation. This should be used
27
+ // for numbers with magintudes over 'exponentialUpperBound' or under 'exponentialLowerBound'.
28
+ this.exponentialIntlNumberFormatOptions = {
29
+ maximumSignificantDigits: DefaultUnitFormat.maximumDigits,
30
+ notation: 'scientific'
31
+ };
32
+ for (const unit of unitScale.supportedScaledUnits) {
33
+ this.defaultScaledUnitFormatters.set(unit.scaleFactor, unit.scaledUnitFormatFactory({
34
+ locale,
35
+ intlNumberFormatOptions: this.defaultIntlNumberFormatOptions
36
+ }));
37
+ this.leadingZeroScaledUnitFormatters.set(unit.scaleFactor, unit.scaledUnitFormatFactory({
38
+ locale,
39
+ intlNumberFormatOptions: this.leadingZeroIntlNumberFormatOptions
40
+ }));
41
+ }
42
+ this.exponentialScaledUnitFormatter = unitScale.baseScaledUnit.scaledUnitFormatFactory({
43
+ locale,
44
+ intlNumberFormatOptions: this.exponentialIntlNumberFormatOptions
45
+ });
46
+ this.unitScale = unitScale;
47
+ }
48
+ resolvedOptions() {
49
+ return {
50
+ unitScale: this.unitScale
51
+ };
52
+ }
53
+ tryFormat(number) {
54
+ // Normalize +0 / -0 --> +0
55
+ const numberNormalized = number === 0 ? 0 : number;
56
+ const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(numberNormalized);
57
+ const numberStyle = this.resolveNumberStyle(scaledValue);
58
+ switch (numberStyle) {
59
+ case 'default': {
60
+ const scaledUnitFormatter = this.defaultScaledUnitFormatters.get(scaledUnit.scaleFactor);
61
+ return scaledUnitFormatter.format(scaledValue);
62
+ }
63
+ case 'leadingZero': {
64
+ const scaledUnitFormatter = this.leadingZeroScaledUnitFormatters.get(scaledUnit.scaleFactor);
65
+ return scaledUnitFormatter.format(scaledValue);
66
+ }
67
+ case 'exponential': {
68
+ const scaledUnitFormatter = this.exponentialScaledUnitFormatter;
69
+ return scaledUnitFormatter.format(numberNormalized);
70
+ }
71
+ default:
72
+ throw new Error('Unexpected number format style');
73
+ }
74
+ }
75
+ resolveNumberStyle(number) {
76
+ if (number === 0) {
77
+ return 'default';
78
+ }
79
+ const absoluteValue = Math.abs(number);
80
+ if (absoluteValue >= DefaultUnitFormat.exponentialUpperBound
81
+ || absoluteValue < DefaultUnitFormat.exponentialLowerBound) {
82
+ return 'exponential';
83
+ }
84
+ // Ideally, we could set 'roundingPriority: "lessPrecision"' with a formatter that has both 'maximumSignificantDigits' and
85
+ // 'maximumFractionDigits' configured instead of having two different formatters that we conditionally choose between. However,
86
+ // 'roundingPrioirty' is not supported yet in all browsers.
87
+ if (absoluteValue < 1) {
88
+ return 'leadingZero';
89
+ }
90
+ return 'default';
91
+ }
92
+ }
93
+ // The maximum number of digits that should be rendered for any given value.
94
+ DefaultUnitFormat.maximumDigits = 6;
95
+ // Use exponential notation for numbers that will be rendered with 3 leading 0s or more.
96
+ // Because a maximum of 6 digits are rendered, showing more than 3 leading 0s is not ideal
97
+ // because then at least half of the displayed digits will be leading 0s.
98
+ DefaultUnitFormat.exponentialLowerBound = 0.000995;
99
+ // Use exponential formatting for numbers whose magnitude cannot otherwise be displayed
100
+ // with 6 digits or less.
101
+ DefaultUnitFormat.exponentialUpperBound = 999999.5;
102
+ //# sourceMappingURL=default-unit-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-unit-format.js","sourceRoot":"","sources":["../../../../src/utilities/unit-format/default-unit-format.ts"],"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AAE;YACd,OAAO,SAAS,CAAC;SACpB;QAED,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACvC,IACI,aAAa,IAAI,iBAAiB,CAAC,qBAAqB;eACrD,aAAa,GAAG,iBAAiB,CAAC,qBAAqB,EAC5D;YACE,OAAO,aAAa,CAAC;SACxB;QACD,0HAA0H;QAC1H,+HAA+H;QAC/H,2DAA2D;QAC3D,IAAI,aAAa,GAAG,CAAC,EAAE;YACnB,OAAO,aAAa,CAAC;SACxB;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;;AApID,4EAA4E;AACpD,+BAAa,GAAG,CAAC,CAAC;AAE1C,wFAAwF;AACxF,0FAA0F;AAC1F,yEAAyE;AACjD,uCAAqB,GAAG,QAAQ,CAAC;AAEzD,uFAAuF;AACvF,yBAAyB;AACD,uCAAqB,GAAG,QAAQ,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { ScaledUnitFormat } from '../scaled-unit-format/scaled-unit-format';
2
+ export interface ScaledUnitFormatFactoryOptions {
3
+ readonly locale: string;
4
+ readonly intlNumberFormatOptions?: Intl.NumberFormatOptions;
5
+ }
6
+ declare type ScaledUnitFormatFactory = (scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions) => ScaledUnitFormat;
7
+ /**
8
+ * A unit that represents a scaled version of a base unit.
9
+ */
10
+ export declare class ScaledUnit {
11
+ readonly scaleFactor: number;
12
+ readonly scaledUnitFormatFactory: ScaledUnitFormatFactory;
13
+ constructor(scaleFactor: number, scaledUnitFormatFactory: ScaledUnitFormatFactory);
14
+ isBase(): boolean;
15
+ }
16
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A unit that represents a scaled version of a base unit.
3
+ */
4
+ export class ScaledUnit {
5
+ constructor(scaleFactor, scaledUnitFormatFactory) {
6
+ this.scaleFactor = scaleFactor;
7
+ this.scaledUnitFormatFactory = scaledUnitFormatFactory;
8
+ }
9
+ isBase() {
10
+ return this.scaleFactor === 1;
11
+ }
12
+ }
13
+ //# sourceMappingURL=scaled-unit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scaled-unit.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/scaled-unit/scaled-unit.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB,YACoB,WAAmB,EACnB,uBAAgD;QADhD,gBAAW,GAAX,WAAW,CAAQ;QACnB,4BAAuB,GAAvB,uBAAuB,CAAyB;IACjE,CAAC;IAEG,MAAM;QACT,OAAO,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC;IAClC,CAAC;CACJ"}
@@ -0,0 +1,11 @@
1
+ import type { ScaledUnitFormatFactoryOptions } from '../scaled-unit/scaled-unit';
2
+ import { ScaledUnitFormat } from './scaled-unit-format';
3
+ /**
4
+ * A formatter for units that can be formatted/translated by Intl.NumberFormat
5
+ */
6
+ export declare class IntlNumberFormatScaledUnitFormat extends ScaledUnitFormat {
7
+ private readonly formatter;
8
+ protected constructor(scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions, unitSpecificIntlNumberFormatOptions: Intl.NumberFormatOptions);
9
+ static createFactory(unitSpecificIntlNumberFormatOptions: Intl.NumberFormatOptions): (scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions) => IntlNumberFormatScaledUnitFormat;
10
+ format(value: number): string;
11
+ }
@@ -0,0 +1,21 @@
1
+ import { ScaledUnitFormat } from './scaled-unit-format';
2
+ /**
3
+ * A formatter for units that can be formatted/translated by Intl.NumberFormat
4
+ */
5
+ export class IntlNumberFormatScaledUnitFormat extends ScaledUnitFormat {
6
+ constructor(scaledUnitFormatFactoryOptions, unitSpecificIntlNumberFormatOptions) {
7
+ super(scaledUnitFormatFactoryOptions);
8
+ this.formatter = new Intl.NumberFormat(this.locale, {
9
+ ...unitSpecificIntlNumberFormatOptions,
10
+ // Application configured options override unit specific options
11
+ ...this.intlNumberFormatOptions
12
+ });
13
+ }
14
+ static createFactory(unitSpecificIntlNumberFormatOptions) {
15
+ return (scaledUnitFormatFactoryOptions) => new IntlNumberFormatScaledUnitFormat(scaledUnitFormatFactoryOptions, unitSpecificIntlNumberFormatOptions);
16
+ }
17
+ format(value) {
18
+ return this.formatter.format(value);
19
+ }
20
+ }
21
+ //# sourceMappingURL=intl-number-format-scaled-unit-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intl-number-format-scaled-unit-format.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/scaled-unit-format/intl-number-format-scaled-unit-format.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD;;GAEG;AACH,MAAM,OAAO,gCAAiC,SAAQ,gBAAgB;IAGlE,YACI,8BAA8D,EAC9D,mCAA6D;QAE7D,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE;YAChD,GAAG,mCAAmC;YACtC,gEAAgE;YAChE,GAAG,IAAI,CAAC,uBAAuB;SAClC,CAAC,CAAC;IACP,CAAC;IAEM,MAAM,CAAC,aAAa,CACvB,mCAA6D;QAE7D,OAAO,CACH,8BAA8D,EAC9B,EAAE,CAAC,IAAI,gCAAgC,CACvE,8BAA8B,EAC9B,mCAAmC,CACtC,CAAC;IACN,CAAC;IAEM,MAAM,CAAC,KAAa;QACvB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;CACJ"}
@@ -0,0 +1,43 @@
1
+ import type { ScaledUnitFormatFactoryOptions } from '../scaled-unit/scaled-unit';
2
+ import { ScaledUnitFormat } from './scaled-unit-format';
3
+ /**
4
+ * Representations of a unit in a particular language
5
+ */
6
+ export declare class UnitTranslation {
7
+ readonly singular: string;
8
+ readonly plural: string;
9
+ readonly symbol: string;
10
+ constructor(singular: string, plural: string, symbol: string);
11
+ }
12
+ /**
13
+ * A map of locales of string format "[lang]" or "[lang]-[region]", for example "en" and / or "en-us", to UnitTranslation objects
14
+ */
15
+ export declare type UnitTranslations = ReadonlyMap<string, UnitTranslation>;
16
+ export interface ManuallyTranslatedScaledUnitFormatOptions {
17
+ /**
18
+ * Translations for the unit by locale string.
19
+ * The locale strings must be of the form [lang] or [lang]-[region], for example "en" and / or "en-us".
20
+ * Other subtags besides lang and region are not supported.
21
+ * Translations for "en" must be provided.
22
+ */
23
+ readonly unitTranslations: UnitTranslations;
24
+ /**
25
+ * String for prefix of this scaled unit, for example "k" (for kilo-).
26
+ * Assumed the same across languages.
27
+ * Base unit must use "", i.e. empty string, as the scaled prefix text.
28
+ */
29
+ readonly scaledPrefixText: string;
30
+ }
31
+ /**
32
+ * A formatter for units that are not supported by Intl.NumberFormat
33
+ */
34
+ export declare class ManuallyTranslatedScaledUnitFormat extends ScaledUnitFormat {
35
+ private readonly pluralRules;
36
+ private readonly formatter;
37
+ private readonly unitTranslation;
38
+ private readonly scaledPrefixText;
39
+ protected constructor(scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions, { unitTranslations, scaledPrefixText }: ManuallyTranslatedScaledUnitFormatOptions);
40
+ static createFactory(manuallyTranslatedScaledUnitFormatOptions: ManuallyTranslatedScaledUnitFormatOptions): (scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions) => ManuallyTranslatedScaledUnitFormat;
41
+ format(value: number): string;
42
+ private getTranslationToUse;
43
+ }
@@ -0,0 +1,62 @@
1
+ import { ScaledUnitFormat } from './scaled-unit-format';
2
+ /**
3
+ * Representations of a unit in a particular language
4
+ */
5
+ export class UnitTranslation {
6
+ constructor(singular, plural, symbol) {
7
+ this.singular = singular;
8
+ this.plural = plural;
9
+ this.symbol = symbol;
10
+ }
11
+ }
12
+ /**
13
+ * A formatter for units that are not supported by Intl.NumberFormat
14
+ */
15
+ export class ManuallyTranslatedScaledUnitFormat extends ScaledUnitFormat {
16
+ constructor(scaledUnitFormatFactoryOptions, { unitTranslations, scaledPrefixText }) {
17
+ super(scaledUnitFormatFactoryOptions);
18
+ if (!unitTranslations.get('en')) {
19
+ throw new Error('English translations must exist with locale string "en"');
20
+ }
21
+ this.pluralRules = new Intl.PluralRules(this.locale);
22
+ this.formatter = new Intl.NumberFormat(this.locale, this.intlNumberFormatOptions);
23
+ this.unitTranslation = this.getTranslationToUse(unitTranslations, this.locale);
24
+ this.scaledPrefixText = scaledPrefixText;
25
+ }
26
+ static createFactory(manuallyTranslatedScaledUnitFormatOptions) {
27
+ return (scaledUnitFormatFactoryOptions) => new ManuallyTranslatedScaledUnitFormat(scaledUnitFormatFactoryOptions, manuallyTranslatedScaledUnitFormatOptions);
28
+ }
29
+ format(value) {
30
+ const formatted = this.formatter.format(value);
31
+ // For non-base units (which are a scaled prefix text of empty string)
32
+ if (this.scaledPrefixText !== '') {
33
+ return `${formatted} ${this.scaledPrefixText}${this.unitTranslation.symbol}`;
34
+ }
35
+ // Some languages have more than two forms (singular/plural) of cardinal
36
+ // numbers, but we are treating anything other than the 'one' form as plural.
37
+ // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules#description
38
+ //
39
+ // Because PluralRules.select() takes a number (not a string), it cannot differentiate
40
+ // between 1 and 1.0. When NumberFormat is configured to format with a set number
41
+ // of fractional digits, those fractional digits can have an effect on the pluralization
42
+ // of the unit. E.g. in English, it formats "1 byte" vs "1.0 bytes". Thus there is
43
+ // sometimes an inconsistency between unit pluralization for the same number, based
44
+ // on whether it's supported by NumberFormat, or manually translated.
45
+ const unitLabel = this.pluralRules.select(value) === 'one'
46
+ ? this.unitTranslation.singular
47
+ : this.unitTranslation.plural;
48
+ return `${formatted} ${unitLabel}`;
49
+ }
50
+ getTranslationToUse(unitTranslations, locale) {
51
+ const localeObject = new Intl.Locale(locale ?? 'en');
52
+ const language = localeObject.language;
53
+ const region = localeObject.region;
54
+ const regionSpecificMatchedTranslations = region
55
+ ? unitTranslations.get(`${language}-${region}`)
56
+ : undefined;
57
+ return (regionSpecificMatchedTranslations
58
+ ?? unitTranslations.get(language)
59
+ ?? unitTranslations.get('en'));
60
+ }
61
+ }
62
+ //# sourceMappingURL=manually-translated-scaled-unit-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manually-translated-scaled-unit-format.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/scaled-unit-format/manually-translated-scaled-unit-format.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD;;GAEG;AACH,MAAM,OAAO,eAAe;IACxB,YACoB,QAAgB,EAChB,MAAc,EACd,MAAc;QAFd,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAQ;IAC/B,CAAC;CACP;AAqBD;;GAEG;AACH,MAAM,OAAO,kCAAmC,SAAQ,gBAAgB;IAMpE,YACI,8BAA8D,EAC9D,EACI,gBAAgB,EAChB,gBAAgB,EACwB;QAE5C,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACtC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC7B,MAAM,IAAI,KAAK,CACX,yDAAyD,CAC5D,CAAC;SACL;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrD,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAClC,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,uBAAuB,CAC/B,CAAC;QACF,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,mBAAmB,CAC3C,gBAAgB,EAChB,IAAI,CAAC,MAAM,CACd,CAAC;QACF,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC7C,CAAC;IAEM,MAAM,CAAC,aAAa,CACvB,yCAAoF;QAEpF,OAAO,C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AG,CAAC,IAAI,CAAE,CACjC,CAAC;IACN,CAAC;CACJ"}
@@ -0,0 +1,10 @@
1
+ import type { ScaledUnitFormatFactoryOptions } from '../scaled-unit/scaled-unit';
2
+ /**
3
+ * A class that knows how to format a numeric value as a string that includes units.
4
+ */
5
+ export declare abstract class ScaledUnitFormat {
6
+ protected readonly locale: string;
7
+ protected readonly intlNumberFormatOptions?: Intl.NumberFormatOptions;
8
+ protected constructor(scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions);
9
+ abstract format(value: number): string;
10
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A class that knows how to format a numeric value as a string that includes units.
3
+ */
4
+ export class ScaledUnitFormat {
5
+ constructor(scaledUnitFormatFactoryOptions) {
6
+ this.locale = scaledUnitFormatFactoryOptions.locale;
7
+ this.intlNumberFormatOptions = scaledUnitFormatFactoryOptions.intlNumberFormatOptions;
8
+ }
9
+ }
10
+ //# sourceMappingURL=scaled-unit-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scaled-unit-format.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/scaled-unit-format/scaled-unit-format.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAgB,gBAAgB;IAIlC,YACI,8BAA8D;QAE9D,IAAI,CAAC,MAAM,GAAG,8BAA8B,CAAC,MAAM,CAAC;QACpD,IAAI,CAAC,uBAAuB,GAAG,8BAA8B,CAAC,uBAAuB,CAAC;IAC1F,CAAC;CAGJ"}
@@ -0,0 +1,16 @@
1
+ import type { UnitScale } from './unit-scale/unit-scale';
2
+ export interface UnitFormatOptions {
3
+ unitScale?: UnitScale;
4
+ }
5
+ /**
6
+ * The base class for unit formats.
7
+ */
8
+ export declare abstract class UnitFormat<Options extends UnitFormatOptions = UnitFormatOptions> {
9
+ /**
10
+ * Formats a number value to a string.
11
+ * For nullish values or values that result in an exception being thrown, empty string is returned
12
+ */
13
+ format(value: number | undefined | null): string;
14
+ abstract resolvedOptions(): Required<Options>;
15
+ protected abstract tryFormat(number: number): string;
16
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The base class for unit formats.
3
+ */
4
+ export class UnitFormat {
5
+ /**
6
+ * Formats a number value to a string.
7
+ * For nullish values or values that result in an exception being thrown, empty string is returned
8
+ */
9
+ format(value) {
10
+ if (typeof value !== 'number') {
11
+ return '';
12
+ }
13
+ try {
14
+ return this.tryFormat(value);
15
+ }
16
+ catch {
17
+ return '';
18
+ }
19
+ }
20
+ }
21
+ //# sourceMappingURL=unit-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unit-format.js","sourceRoot":"","sources":["../../../../src/utilities/unit-format/unit-format.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,OAAgB,UAAU;IAG5B;;;OAGG;IACI,MAAM,CAAC,KAAgC;QAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC3B,OAAO,EAAE,CAAC;SACb;QAED,IAAI;YACA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SAChC;QAAC,MAAM;YACJ,OAAO,EAAE,CAAC;SACb;IACL,CAAC;CAKJ"}
@@ -0,0 +1,9 @@
1
+ import { UnitScale } from './unit-scale';
2
+ /**
3
+ * Byte units (1024-based)
4
+ */
5
+ declare class Byte1024UnitScale extends UnitScale {
6
+ constructor();
7
+ }
8
+ export declare const byte1024UnitScale: Byte1024UnitScale;
9
+ export {};
@@ -0,0 +1,31 @@
1
+ import { ScaledUnit } from '../scaled-unit/scaled-unit';
2
+ import { UnitScale } from './unit-scale';
3
+ import { ManuallyTranslatedScaledUnitFormat, UnitTranslation } from '../scaled-unit-format/manually-translated-scaled-unit-format';
4
+ const unitTranslations = new Map([
5
+ ['en', new UnitTranslation('byte', 'bytes', 'B')],
6
+ ['fr', new UnitTranslation('octet', 'octets', 'o')],
7
+ ['de', new UnitTranslation('Byte', 'Byte', 'B')],
8
+ ['ja', new UnitTranslation('バイト', 'バイト', 'B')],
9
+ ['zh', new UnitTranslation('字节', '字节', 'B')]
10
+ ]);
11
+ const byte1024Prefixes = [
12
+ [1024 ** 0, ''],
13
+ [1024 ** 1, 'Ki'],
14
+ [1024 ** 2, 'Mi'],
15
+ [1024 ** 3, 'Gi'],
16
+ [1024 ** 4, 'Ti'],
17
+ [1024 ** 5, 'Pi']
18
+ ];
19
+ /**
20
+ * Byte units (1024-based)
21
+ */
22
+ class Byte1024UnitScale extends UnitScale {
23
+ constructor() {
24
+ super(byte1024Prefixes.map(([scaleFactor, scaledPrefixText]) => new ScaledUnit(scaleFactor, ManuallyTranslatedScaledUnitFormat.createFactory({
25
+ unitTranslations,
26
+ scaledPrefixText
27
+ }))));
28
+ }
29
+ }
30
+ export const byte1024UnitScale = new Byte1024UnitScale();
31
+ //# sourceMappingURL=byte-1024-unit-scale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"byte-1024-unit-scale.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/unit-scale/byte-1024-unit-scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACH,kCAAkC,EAElC,eAAe,EAClB,MAAM,8DAA8D,CAAC;AAEtE,MAAM,gBAAgB,GAAqB,IAAI,GAAG,CAAC;IAC/C,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACjD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IACnD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAChD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;CAC/C,CAAC,CAAC;AAEH,MAAM,gBAAgB,GAAG;IACrB,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;IACf,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;IACjB,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;IACjB,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;IACjB,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;IACjB,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;CACX,CAAC;AAEX;;GAEG;AACH,MAAM,iBAAkB,SAAQ,SAAS;IACrC;QACI,KAAK,CACD,gBAAgB,CAAC,GAAG,CAChB,CAAC,CAAC,WAAW,EAAE,gBAAgB,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAC/C,WAAW,EACX,kCAAkC,CAAC,aAAa,CAAC;YAC7C,gBAAgB;YAChB,gBAAgB;SACnB,CAAC,CACL,CACJ,CACJ,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { UnitScale } from './unit-scale';
2
+ /**
3
+ * Byte units (1000-based)
4
+ */
5
+ declare class ByteUnitScale extends UnitScale {
6
+ constructor();
7
+ }
8
+ export declare const byteUnitScale: ByteUnitScale;
9
+ export {};
@@ -0,0 +1,25 @@
1
+ import { IntlNumberFormatScaledUnitFormat } from '../scaled-unit-format/intl-number-format-scaled-unit-format';
2
+ import { ScaledUnit } from '../scaled-unit/scaled-unit';
3
+ import { UnitScale } from './unit-scale';
4
+ const byteUnitScaleOptions = [
5
+ [1000 ** 0, 'byte', 'long'],
6
+ [1000 ** 1, 'kilobyte', 'short'],
7
+ [1000 ** 2, 'megabyte', 'short'],
8
+ [1000 ** 3, 'gigabyte', 'short'],
9
+ [1000 ** 4, 'terabyte', 'short'],
10
+ [1000 ** 5, 'petabyte', 'short']
11
+ ];
12
+ /**
13
+ * Byte units (1000-based)
14
+ */
15
+ class ByteUnitScale extends UnitScale {
16
+ constructor() {
17
+ super(byteUnitScaleOptions.map(([scaleFactor, unit, unitDisplay]) => new ScaledUnit(scaleFactor, IntlNumberFormatScaledUnitFormat.createFactory({
18
+ style: 'unit',
19
+ unit,
20
+ unitDisplay
21
+ }))));
22
+ }
23
+ }
24
+ export const byteUnitScale = new ByteUnitScale();
25
+ //# sourceMappingURL=byte-unit-scale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"byte-unit-scale.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/unit-scale/byte-unit-scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,6DAA6D,CAAC;AAC/G,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,oBAAoB,GAAG;IACzB,CAAC,IAAI,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC;IAC3B,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;IAChC,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;IAChC,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;IAChC,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;IAChC,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEX;;GAEG;AACH,MAAM,aAAc,SAAQ,SAAS;IACjC;QACI,KAAK,CACD,oBAAoB,CAAC,GAAG,CACpB,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAChD,WAAW,EACX,gCAAgC,CAAC,aAAa,CAAC;YAC3C,KAAK,EAAE,MAAM;YACb,IAAI;YACJ,WAAW;SACd,CAAC,CACL,CACJ,CACJ,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { UnitScale } from './unit-scale';
2
+ /**
3
+ * Unit scale that is used to passthrough a number without applying scaling or units
4
+ */
5
+ declare class PassthroughUnitScale extends UnitScale {
6
+ constructor();
7
+ }
8
+ export declare const passthroughUnitScale: PassthroughUnitScale;
9
+ export {};
@@ -0,0 +1,15 @@
1
+ import { IntlNumberFormatScaledUnitFormat } from '../scaled-unit-format/intl-number-format-scaled-unit-format';
2
+ import { ScaledUnit } from '../scaled-unit/scaled-unit';
3
+ import { UnitScale } from './unit-scale';
4
+ /**
5
+ * Unit scale that is used to passthrough a number without applying scaling or units
6
+ */
7
+ class PassthroughUnitScale extends UnitScale {
8
+ constructor() {
9
+ super([
10
+ new ScaledUnit(10 ** 0, IntlNumberFormatScaledUnitFormat.createFactory({}))
11
+ ]);
12
+ }
13
+ }
14
+ export const passthroughUnitScale = new PassthroughUnitScale();
15
+ //# sourceMappingURL=passthrough-unit-scale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passthrough-unit-scale.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/unit-scale/passthrough-unit-scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,6DAA6D,CAAC;AAC/G,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;GAEG;AACH,MAAM,oBAAqB,SAAQ,SAAS;IACxC;QACI,KAAK,CAAC;YACF,IAAI,UAAU,CACV,EAAE,IAAI,CAAC,EACP,gCAAgC,CAAC,aAAa,CAAC,EAAE,CAAC,CACrD;SACJ,CAAC,CAAC;IACP,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC"}