@ni/nimble-components 21.6.7 → 21.6.8

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.
@@ -16301,7 +16301,7 @@
16301
16301
 
16302
16302
  /**
16303
16303
  * Do not edit directly
16304
- * Generated on Fri, 23 Feb 2024 22:40:01 GMT
16304
+ * Generated on Mon, 26 Feb 2024 22:10:53 GMT
16305
16305
  */
16306
16306
 
16307
16307
  const Information100DarkUi = "#a46eff";
@@ -68468,6 +68468,10 @@ img.ProseMirror-separator {
68468
68468
  }
68469
68469
  const passthroughUnitScale = new PassthroughUnitScale();
68470
68470
 
68471
+ // Workaround to avoid ts errors about signDisplay not accepting the value 'negative'.
68472
+ // It has been supported by browsers since 8/23, but TypeScript still hasn't
68473
+ // added it to the type definitions. See https://github.com/microsoft/TypeScript/issues/56269
68474
+ const signDisplay = 'negative';
68471
68475
  /**
68472
68476
  * Format for numbers with units to show in a tabular form.
68473
68477
  * Large and tiny numbers are shown exponentially and the rest as decimal.
@@ -68477,35 +68481,26 @@ img.ProseMirror-separator {
68477
68481
  unitScale: passthroughUnitScale
68478
68482
  }) {
68479
68483
  super();
68480
- // Format options to use by default. It renders the number with a maximum of 6 signficant digits.
68484
+ // Format options to use by default. It renders the number with a maximum of 6 signficant digits (including zero before decimal point).
68481
68485
  this.defaultIntlNumberFormatOptions = {
68482
68486
  maximumSignificantDigits: DefaultUnitFormat.maximumDigits,
68483
- useGrouping: true
68484
- };
68485
- this.defaultScaledUnitFormatters = new Map();
68486
- // Format options to use for numbers that have leading zeros. It limits the number of rendered
68487
- // digits using 'maximumFractionDigits', which will result in less than 6 significant digits
68488
- // in order to render no more than 6 total digits.
68489
- this.leadingZeroIntlNumberFormatOptions = {
68490
68487
  maximumFractionDigits: DefaultUnitFormat.maximumDigits - 1,
68491
- useGrouping: true
68488
+ roundingPriority: 'lessPrecision',
68489
+ signDisplay
68492
68490
  };
68493
- this.leadingZeroScaledUnitFormatters = new Map();
68491
+ this.defaultScaledUnitFormatters = new Map();
68494
68492
  // Format options for numbers that should be displayed in exponential notation. This should be used
68495
68493
  // for numbers with magintudes over 'exponentialUpperBound' or under 'exponentialLowerBound'.
68496
68494
  this.exponentialIntlNumberFormatOptions = {
68497
68495
  maximumSignificantDigits: DefaultUnitFormat.maximumDigits,
68498
- notation: 'scientific'
68496
+ notation: 'scientific',
68497
+ signDisplay
68499
68498
  };
68500
68499
  for (const unit of unitScale.supportedScaledUnits) {
68501
68500
  this.defaultScaledUnitFormatters.set(unit.scaleFactor, unit.scaledUnitFormatFactory({
68502
68501
  locale,
68503
68502
  intlNumberFormatOptions: this.defaultIntlNumberFormatOptions
68504
68503
  }));
68505
- this.leadingZeroScaledUnitFormatters.set(unit.scaleFactor, unit.scaledUnitFormatFactory({
68506
- locale,
68507
- intlNumberFormatOptions: this.leadingZeroIntlNumberFormatOptions
68508
- }));
68509
68504
  }
68510
68505
  this.exponentialScaledUnitFormatter = unitScale.baseScaledUnit.scaledUnitFormatFactory({
68511
68506
  locale,
@@ -68519,43 +68514,16 @@ img.ProseMirror-separator {
68519
68514
  };
68520
68515
  }
68521
68516
  tryFormat(number) {
68522
- // Normalize +0 / -0 --> +0
68523
- const numberNormalized = number === 0 ? 0 : number;
68524
- const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(numberNormalized);
68525
- const numberStyle = this.resolveNumberStyle(scaledValue);
68526
- switch (numberStyle) {
68527
- case 'default': {
68528
- const scaledUnitFormatter = this.defaultScaledUnitFormatters.get(scaledUnit.scaleFactor);
68529
- return scaledUnitFormatter.format(scaledValue);
68530
- }
68531
- case 'leadingZero': {
68532
- const scaledUnitFormatter = this.leadingZeroScaledUnitFormatters.get(scaledUnit.scaleFactor);
68533
- return scaledUnitFormatter.format(scaledValue);
68534
- }
68535
- case 'exponential': {
68536
- const scaledUnitFormatter = this.exponentialScaledUnitFormatter;
68537
- return scaledUnitFormatter.format(numberNormalized);
68538
- }
68539
- default:
68540
- throw new Error('Unexpected number format style');
68541
- }
68542
- }
68543
- resolveNumberStyle(number) {
68544
- if (number === 0) {
68545
- return 'default';
68546
- }
68547
- const absoluteValue = Math.abs(number);
68548
- if (absoluteValue >= DefaultUnitFormat.exponentialUpperBound
68549
- || absoluteValue < DefaultUnitFormat.exponentialLowerBound) {
68550
- return 'exponential';
68551
- }
68552
- // Ideally, we could set 'roundingPriority: "lessPrecision"' with a formatter that has both 'maximumSignificantDigits' and
68553
- // 'maximumFractionDigits' configured instead of having two different formatters that we conditionally choose between. However,
68554
- // 'roundingPrioirty' is not supported yet in all browsers.
68555
- if (absoluteValue < 1) {
68556
- return 'leadingZero';
68557
- }
68558
- return 'default';
68517
+ const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(number);
68518
+ const absoluteValue = Math.abs(scaledValue);
68519
+ const useExponential = absoluteValue !== 0
68520
+ && (absoluteValue >= DefaultUnitFormat.exponentialUpperBound
68521
+ || absoluteValue < DefaultUnitFormat.exponentialLowerBound);
68522
+ return useExponential
68523
+ ? this.exponentialScaledUnitFormatter.format(number)
68524
+ : this.defaultScaledUnitFormatters
68525
+ .get(scaledUnit.scaleFactor)
68526
+ .format(scaledValue);
68559
68527
  }
68560
68528
  }
68561
68529
  // The maximum number of digits that should be rendered for any given value.
@@ -68579,10 +68547,14 @@ img.ProseMirror-separator {
68579
68547
  }) {
68580
68548
  super();
68581
68549
  this.scaledUnitFormatters = new Map();
68550
+ // Workaround to avoid a ts error about signDisplay not accepting the value 'negative'.
68551
+ // It has been supported by browsers since 8/23, but TypeScript still hasn't
68552
+ // added it to the type definitions. See https://github.com/microsoft/TypeScript/issues/56269
68553
+ const signDisplay = 'negative';
68582
68554
  const intlNumberFormatOptions = {
68583
68555
  maximumFractionDigits,
68584
68556
  minimumFractionDigits,
68585
- useGrouping: true
68557
+ signDisplay
68586
68558
  };
68587
68559
  for (const scaledUnit of unitScale.supportedScaledUnits) {
68588
68560
  this.scaledUnitFormatters.set(scaledUnit.scaleFactor, scaledUnit.scaledUnitFormatFactory({
@@ -68590,7 +68562,6 @@ img.ProseMirror-separator {
68590
68562
  intlNumberFormatOptions
68591
68563
  }));
68592
68564
  }
68593
- this.tenPowDecimalDigits = 10 ** maximumFractionDigits;
68594
68565
  this.unitScale = unitScale;
68595
68566
  this.minimumFractionDigits = minimumFractionDigits;
68596
68567
  this.maximumFractionDigits = maximumFractionDigits;
@@ -68604,16 +68575,8 @@ img.ProseMirror-separator {
68604
68575
  }
68605
68576
  tryFormat(number) {
68606
68577
  const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(number);
68607
- const numberNormalized = this.willRoundToZero(scaledValue)
68608
- ? 0
68609
- : scaledValue;
68610
68578
  const scaledUnitFormatter = this.scaledUnitFormatters.get(scaledUnit.scaleFactor);
68611
- return scaledUnitFormatter.format(numberNormalized);
68612
- }
68613
- willRoundToZero(number) {
68614
- // Multiply the value by 10 raised to maximumFractionDigits so that Math.round can be used to emulate rounding to
68615
- // maximumFractionDigits decimal places. If that rounded value is 0, then the value will be rendered with only 0s.
68616
- return Math.round(number * this.tenPowDecimalDigits) === 0;
68579
+ return scaledUnitFormatter.format(scaledValue);
68617
68580
  }
68618
68581
  }
68619
68582