@skyux/core 5.9.4 → 5.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/skyux-core.umd.js +18 -13
- package/documentation.json +137 -134
- package/esm2015/lib/modules/numeric/numeric.pipe.js +3 -4
- package/esm2015/lib/modules/numeric/numeric.pipe.js.map +1 -1
- package/esm2015/lib/modules/numeric/numeric.service.js +1 -1
- package/esm2015/lib/modules/numeric/numeric.service.js.map +1 -1
- package/esm2015/lib/modules/resize-observer/resize-observer-media-query.service.js +14 -8
- package/esm2015/lib/modules/resize-observer/resize-observer-media-query.service.js.map +1 -1
- package/fesm2015/skyux-core.js +18 -13
- package/fesm2015/skyux-core.js.map +1 -1
- package/lib/modules/numeric/numeric.pipe.d.ts +3 -4
- package/lib/modules/numeric/numeric.service.d.ts +1 -1
- package/lib/modules/resize-observer/resize-observer-media-query.service.d.ts +1 -1
- package/package.json +2 -2
@@ -12,10 +12,6 @@ import * as i2 from "./numeric.service";
|
|
12
12
|
* M for millions, B for billions, and T for trillions. The pipe also formats for currency.
|
13
13
|
* Be sure you have a space after the two curly brackets opening the pipe and
|
14
14
|
* a space before the two curly brackets closing the pipe or it will not work.
|
15
|
-
* Usage:
|
16
|
-
* ```
|
17
|
-
* {{ value | skyNumeric(config) }}
|
18
|
-
* ```
|
19
15
|
*/
|
20
16
|
export class SkyNumericPipe {
|
21
17
|
constructor(localeProvider, numericService, changeDetector) {
|
@@ -36,6 +32,9 @@ export class SkyNumericPipe {
|
|
36
32
|
this.ngUnsubscribe.next();
|
37
33
|
this.ngUnsubscribe.complete();
|
38
34
|
}
|
35
|
+
/**
|
36
|
+
* Formats a number based on the provided options.
|
37
|
+
*/
|
39
38
|
transform(value, config) {
|
40
39
|
var _a;
|
41
40
|
const newCacheKey = (config ? JSON.stringify(config, Object.keys(config).sort()) : '') +
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"numeric.pipe.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/numeric/numeric.pipe.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAEjB,IAAI,GAEL,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;;;;AAEtD
|
1
|
+
{"version":3,"file":"numeric.pipe.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/numeric/numeric.pipe.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAEjB,IAAI,GAEL,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;;;;AAEtD;;;;;GAKG;AAKH,MAAM,OAAO,cAAc;IASzB,YACU,cAAoC,EAC3B,cAAiC,EAC1C,cAAiC;QAFjC,mBAAc,GAAd,cAAc,CAAsB;QAC3B,mBAAc,GAAd,cAAc,CAAmB;QAC1C,mBAAc,GAAd,cAAc,CAAmB;QALnC,kBAAa,GAAG,IAAI,OAAO,EAAQ,CAAC;QAO1C,IAAI,CAAC,cAAc;aAChB,aAAa,EAAE;aACf,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;aACnC,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE;YACxB,IAAI,CAAC,cAAc,GAAG,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AAM,CAAC,MAAM,EAAE;YACvD,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC;SACnC;QAED,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAE/B,+CAA+C;QAC/C,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,mBAAmB,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,mCAAI,IAAI,CAAC,cAAc,CAAC;QACjE,IAAI,CAAC,QAAQ,GAAG,WAAW,CAAC;QAE5B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACvE,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;;4GA5EU,cAAc;0GAAd,cAAc;4FAAd,cAAc;kBAJ1B,IAAI;mBAAC;oBACJ,IAAI,EAAE,YAAY;oBAClB,IAAI,EAAE,KAAK;iBACZ","sourcesContent":["import {\n ChangeDetectorRef,\n OnDestroy,\n Pipe,\n PipeTransform,\n} from '@angular/core';\nimport { SkyAppLocaleProvider } from '@skyux/i18n';\n\nimport { Subject } from 'rxjs';\nimport { takeUntil } from 'rxjs/operators';\n\nimport { NumericOptions } from './numeric.options';\nimport { SkyNumericService } from './numeric.service';\n\n/**\n * Shortens numbers to rounded numbers and abbreviation characters such as K for thousands,\n * M for millions, B for billions, and T for trillions. The pipe also formats for currency.\n * Be sure you have a space after the two curly brackets opening the pipe and\n * a space before the two curly brackets closing the pipe or it will not work.\n */\n@Pipe({\n name: 'skyNumeric',\n pure: false,\n})\nexport class SkyNumericPipe implements PipeTransform, OnDestroy {\n private cacheKey: string;\n private formattedValue: string;\n private lastTransformLocale: string;\n private rawValue: number;\n private providerLocale: string;\n\n private ngUnsubscribe = new Subject<void>();\n\n constructor(\n private localeProvider: SkyAppLocaleProvider,\n private readonly numericService: SkyNumericService,\n private changeDetector: ChangeDetectorRef\n ) {\n this.localeProvider\n .getLocaleInfo()\n .pipe(takeUntil(this.ngUnsubscribe))\n .subscribe((localeInfo) => {\n this.providerLocale = localeInfo.locale;\n numericService.currentLocale = this.providerLocale;\n this.changeDetector.markForCheck();\n });\n }\n\n public ngOnDestroy(): void {\n this.ngUnsubscribe.next();\n this.ngUnsubscribe.complete();\n }\n\n /**\n * Formats a number based on the provided options.\n */\n public transform(value: number, config?: NumericOptions): string {\n const newCacheKey =\n (config ? JSON.stringify(config, Object.keys(config).sort()) : '') +\n `${value}_${config?.locale || this.providerLocale}`;\n\n /* If the value and locale are the same as the last transform then return the previous value\n instead of reformatting. */\n if (this.formattedValue && this.cacheKey === newCacheKey) {\n return this.formattedValue;\n }\n\n const options = new NumericOptions();\n\n // The default number of digits is `1`. When truncate is disabled, set digits\n // to `0` to avoid the unnecessary addition of `.0` at the end of the formatted number.\n if (config && config.truncate === false && config.digits === undefined) {\n options.digits = 0;\n }\n\n // If the minimum digits is less than the set maximum digits then throw an error\n if (\n config &&\n config.minDigits &&\n config.digits &&\n config.minDigits > config.digits\n ) {\n throw new Error(\n 'The `digits` property must be greater than or equal to the `minDigits` property'\n );\n\n // If there is a minimum digits given but not a maximum then default the maximum to the minimum\n } else if (config && config.minDigits && !config.digits) {\n options.digits = config.minDigits;\n }\n\n Object.assign(options, config);\n\n // Assign properties for proper result caching.\n this.rawValue = value;\n this.lastTransformLocale = config?.locale ?? this.providerLocale;\n this.cacheKey = newCacheKey;\n\n this.formattedValue = this.numericService.formatNumber(value, options);\n return this.formattedValue;\n }\n}\n"]}
|
@@ -24,7 +24,7 @@ export class SkyNumericService {
|
|
24
24
|
return this._locale || 'en-US';
|
25
25
|
}
|
26
26
|
/**
|
27
|
-
*
|
27
|
+
* Formats a number based on the provided options.
|
28
28
|
* @param value The number to format.
|
29
29
|
* @param options Format options.
|
30
30
|
*/
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"numeric.service.js","sourceRoot":"","sources":["../../../../../../../../lib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;kBAH7B,UAAU;mBAAC;oBACV,UAAU,EAAE,KAAK;iBAClB","sourcesContent":["import { Injectable } from '@angular/core';\nimport { SkyIntlNumberFormatStyle, SkyLibResourcesService } from '@skyux/i18n';\n\nimport { SkyNumberFormatUtility } from '../shared/number-format/number-format-utility';\n\nimport { SkyNumericSymbol } from './numeric-symbol';\nimport { NumericOptions } from './numeric.options';\n\n@Injectable({\n providedIn: 'any',\n})\nexport class SkyNumericService {\n /**\n * The browser's current locale.\n * @internal\n */\n public set currentLocale(value: string) {\n this._locale = value;\n }\n\n public get currentLocale(): string {\n return this._locale || 'en-US';\n }\n\n /**\n * @internal\n */\n public shortSymbol: string;\n\n private symbolIndex: SkyNumericSymbol[] = [\n { value: 1e12, label: this.getSymbol('skyux_numeric_trillions_symbol') },\n { value: 1e9, label: this.getSymbol('skyux_numeric_billions_symbol') },\n { value: 1e6, label: this.getSymbol('skyux_numeric_millions_symbol') },\n { value: 1e3, label: this.getSymbol('skyux_numeric_thousands_symbol') },\n ];\n\n private _locale: string;\n\n constructor(private resourcesService: SkyLibResourcesService) {}\n\n /**\n * Shortens with or without symbol (K/M/B/T) depending on value of number.\n * @param value The number to format.\n * @param options Format options.\n */\n public formatNumber(value: number, options: NumericOptions): string {\n /* tslint:disable-next-line:no-null-keyword */\n if (isNaN(value) || value === null) {\n return '';\n }\n\n const decimalPlaceRegExp = /\\.0+$|(\\.[0-9]*[1-9])0+$/;\n\n // Get the symbol for the number after rounding, since rounding could push the number\n // into a different symbol range.\n let roundedNumber = this.roundNumber(value, options.digits);\n const roundedNumberAbs = Math.abs(roundedNumber);\n\n let suffix = '';\n\n for (let i = 0; i < this.symbolIndex.length; i++) {\n let symbol = this.symbolIndex[i];\n\n if (\n options.truncate &&\n roundedNumberAbs >= options.truncateAfter &&\n roundedNumberAbs >= symbol.value\n ) {\n roundedNumber = this.roundNumber(value / symbol.value, options.digits);\n\n if (Math.abs(roundedNumber) === 1000 && i > 0) {\n // Rounding caused the number to cross into the range of the next symbol.\n symbol = this.symbolIndex[i - 1];\n roundedNumber /= 1000;\n }\n\n suffix = symbol.label;\n\n break;\n }\n }\n\n let output =\n roundedNumber.toString().replace(decimalPlaceRegExp, '$1') + suffix;\n\n this.storeShortenSymbol(output);\n\n const locale = options.locale || this.currentLocale;\n\n let digits: string;\n let isDecimal: boolean;\n\n // Checks the string entered for format. Using toLowerCase to ignore case.\n switch (options.format?.toLowerCase()) {\n // In a case where a decimal value was not shortened and\n // the digit input is 2 or higher, it forces 2 digits.\n // For example, this prevents a value like $15.50 from displaying as $15.5.\n // Note: This will need to be reviewed if we support currencies with\n // three decimal digits.\n case 'currency':\n isDecimal = value % 1 !== 0;\n\n if (options.minDigits) {\n digits = `1.${options.minDigits}-${options.digits}`;\n } else if (isDecimal && options.digits >= 2) {\n digits = `1.2-${options.digits}`;\n } else {\n digits = `1.0-${options.digits}`;\n }\n\n output = SkyNumberFormatUtility.formatNumber(\n locale,\n parseFloat(output),\n SkyIntlNumberFormatStyle.Currency,\n digits,\n options.iso,\n // Angular 5+ needs a string for this parameter, but Angular 4 needs a boolean.\n // To support both versions we can supply 'symbol' which will evaluate truthy for Angular 4\n // and the appropriate string value for Angular 5+.\n // See: https://angular.io/api/common/CurrencyPipe#parameters\n 'symbol' as any,\n options.currencySign\n );\n break;\n\n // The following is a catch-all to ensure that if\n // anything but currency (or a future option) are entered,\n // it will be treated like a number.\n default:\n // Ensures localization of the number to ensure comma and\n // decimal separator\n if (options.minDigits) {\n digits = `1.${options.minDigits}-${options.digits}`;\n } else if (options.truncate) {\n digits = `1.0-${options.digits}`;\n } else {\n digits = `1.${options.digits}-${options.digits}`;\n }\n\n output = SkyNumberFormatUtility.formatNumber(\n locale,\n parseFloat(output),\n SkyIntlNumberFormatStyle.Decimal,\n digits\n );\n break;\n }\n\n if (options.truncate) {\n output = this.replaceShortenSymbol(output);\n }\n\n return output;\n }\n\n /**\n * Rounds a given number\n *\n * JS's limitation - numbers bigger than Number.MIN_SAFE_INTEGER or Number.MAX_SAFE_INTEGER\n * are not guaranteed to be represented or rounded correctly\n * @param value - value to round\n * @param precision - what precision to round with, defaults to 0 decimal places\n */\n private roundNumber(value: number, precision: number = 0): number {\n if (precision < 0) {\n throw new Error('SkyInvalidArgument: precision must be >= 0');\n }\n\n /* tslint:disable-next-line:no-null-keyword */\n /* Sanity check - ignoring coverage but should not ignore if we make this method public */\n /* istanbul ignore next */\n if (isNaN(value) || value === null) {\n return 0;\n }\n\n const scaledValue: number = this.scaleNumberByPowerOfTen(\n value,\n precision,\n true\n );\n const scaledRoundedValue: number = Math.round(scaledValue);\n const unscaledRoundedValue: number = this.scaleNumberByPowerOfTen(\n scaledRoundedValue,\n precision,\n false\n );\n\n return unscaledRoundedValue;\n }\n\n /**\n * Scales a given number by a power of 10\n * @param value - value to scale\n * @param scalar - 10^scalar\n * @param scaleUp - whether to increase or decrease the value\n */\n private scaleNumberByPowerOfTen(\n value: number,\n scalar: number,\n scaleUp: boolean\n ): number {\n const valueStr: string = value.toString().toLowerCase();\n const isExponentFormat: boolean = valueStr.includes('e');\n\n if (isExponentFormat) {\n const [base, exp] = valueStr.split('e');\n const newExp = scaleUp ? Number(exp) + scalar : Number(exp) - scalar;\n return Number(`${base}e${newExp}`);\n } else {\n const e = scaleUp ? 'e' : 'e-';\n return Number(`${value}${e}${scalar}`);\n }\n }\n\n /**\n * Stores the symbol added from shortening to reapply later.\n * @param value The string to derive the shorten symbol from.\n */\n private storeShortenSymbol(value: string): void {\n const symbols: string[] = this.symbolIndex.map((s) => s.label);\n const regexp = new RegExp(symbols.join('|'), 'ig');\n const match = value.match(regexp);\n this.shortSymbol = match ? match.toString() : '';\n }\n\n /**\n * Must have previously called storeShortenSymbol to have something to replace.\n * Finds the last number in the formatted number, gets the index of the position\n * after that character and re-inserts the symbol.\n * Works regardless of currency symbol position.\n * @param value The string to modify.\n */\n private replaceShortenSymbol(value: string): string {\n const result = /(\\d)(?!.*\\d)/g.exec(value);\n const pos = result.index + result.length;\n const output =\n value.substring(0, pos) + this.shortSymbol + value.substring(pos);\n\n return output;\n }\n\n private getSymbol(key: string): string {\n // TODO: Need to implement the async `getString` method in a breaking change.\n return this.resourcesService.getStringForLocale({ locale: 'en_US' }, key);\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"numeric.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/numeric/numeric.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;;;AAQvF,MAAM,OAAO,iBAAiB;IA2B5B,YAAoB,gBAAwC;QAAxC,qBAAgB,GAAhB,gBAAgB,CAAwB;QATpD,gBAAW,GAAuB;YACxC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,gCAAgC,CAAC,EAAE;YACxE,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,+BAA+B,CAAC,EAAE;YACtE,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,+BAA+B,CAAC,EAAE;YACtE,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,gCAAgC,CAAC,EAAE;SACxE,CAAC;IAI6D,CAAC;IA1BhE;;;OAGG;IACH,IAAW,aAAa,CAAC,KAAa;QACpC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC;IACjC,CAAC;IAkBD;;;;OAIG;IACI,YAAY,CAAC,KAAa,EAAE,OAAuB;;QACxD,8CAA8C;QAC9C,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,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,GAAW;QAC3B,6EAA6E;QAC7E,OAAO,IAAI,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;IAC5E,CAAC;;+GAzOU,iBAAiB;mHAAjB,iBAAiB,cAFhB,KAAK;4FAEN,iBAAiB;kBAH7B,UAAU;mBAAC;oBACV,UAAU,EAAE,KAAK;iBAClB","sourcesContent":["import { Injectable } from '@angular/core';\nimport { SkyIntlNumberFormatStyle, SkyLibResourcesService } from '@skyux/i18n';\n\nimport { SkyNumberFormatUtility } from '../shared/number-format/number-format-utility';\n\nimport { SkyNumericSymbol } from './numeric-symbol';\nimport { NumericOptions } from './numeric.options';\n\n@Injectable({\n providedIn: 'any',\n})\nexport class SkyNumericService {\n /**\n * The browser's current locale.\n * @internal\n */\n public set currentLocale(value: string) {\n this._locale = value;\n }\n\n public get currentLocale(): string {\n return this._locale || 'en-US';\n }\n\n /**\n * @internal\n */\n public shortSymbol: string;\n\n private symbolIndex: SkyNumericSymbol[] = [\n { value: 1e12, label: this.getSymbol('skyux_numeric_trillions_symbol') },\n { value: 1e9, label: this.getSymbol('skyux_numeric_billions_symbol') },\n { value: 1e6, label: this.getSymbol('skyux_numeric_millions_symbol') },\n { value: 1e3, label: this.getSymbol('skyux_numeric_thousands_symbol') },\n ];\n\n private _locale: string;\n\n constructor(private resourcesService: SkyLibResourcesService) {}\n\n /**\n * Formats a number based on the provided options.\n * @param value The number to format.\n * @param options Format options.\n */\n public formatNumber(value: number, options: NumericOptions): string {\n /* tslint:disable-next-line:no-null-keyword */\n if (isNaN(value) || value === null) {\n return '';\n }\n\n const decimalPlaceRegExp = /\\.0+$|(\\.[0-9]*[1-9])0+$/;\n\n // Get the symbol for the number after rounding, since rounding could push the number\n // into a different symbol range.\n let roundedNumber = this.roundNumber(value, options.digits);\n const roundedNumberAbs = Math.abs(roundedNumber);\n\n let suffix = '';\n\n for (let i = 0; i < this.symbolIndex.length; i++) {\n let symbol = this.symbolIndex[i];\n\n if (\n options.truncate &&\n roundedNumberAbs >= options.truncateAfter &&\n roundedNumberAbs >= symbol.value\n ) {\n roundedNumber = this.roundNumber(value / symbol.value, options.digits);\n\n if (Math.abs(roundedNumber) === 1000 && i > 0) {\n // Rounding caused the number to cross into the range of the next symbol.\n symbol = this.symbolIndex[i - 1];\n roundedNumber /= 1000;\n }\n\n suffix = symbol.label;\n\n break;\n }\n }\n\n let output =\n roundedNumber.toString().replace(decimalPlaceRegExp, '$1') + suffix;\n\n this.storeShortenSymbol(output);\n\n const locale = options.locale || this.currentLocale;\n\n let digits: string;\n let isDecimal: boolean;\n\n // Checks the string entered for format. Using toLowerCase to ignore case.\n switch (options.format?.toLowerCase()) {\n // In a case where a decimal value was not shortened and\n // the digit input is 2 or higher, it forces 2 digits.\n // For example, this prevents a value like $15.50 from displaying as $15.5.\n // Note: This will need to be reviewed if we support currencies with\n // three decimal digits.\n case 'currency':\n isDecimal = value % 1 !== 0;\n\n if (options.minDigits) {\n digits = `1.${options.minDigits}-${options.digits}`;\n } else if (isDecimal && options.digits >= 2) {\n digits = `1.2-${options.digits}`;\n } else {\n digits = `1.0-${options.digits}`;\n }\n\n output = SkyNumberFormatUtility.formatNumber(\n locale,\n parseFloat(output),\n SkyIntlNumberFormatStyle.Currency,\n digits,\n options.iso,\n // Angular 5+ needs a string for this parameter, but Angular 4 needs a boolean.\n // To support both versions we can supply 'symbol' which will evaluate truthy for Angular 4\n // and the appropriate string value for Angular 5+.\n // See: https://angular.io/api/common/CurrencyPipe#parameters\n 'symbol' as any,\n options.currencySign\n );\n break;\n\n // The following is a catch-all to ensure that if\n // anything but currency (or a future option) are entered,\n // it will be treated like a number.\n default:\n // Ensures localization of the number to ensure comma and\n // decimal separator\n if (options.minDigits) {\n digits = `1.${options.minDigits}-${options.digits}`;\n } else if (options.truncate) {\n digits = `1.0-${options.digits}`;\n } else {\n digits = `1.${options.digits}-${options.digits}`;\n }\n\n output = SkyNumberFormatUtility.formatNumber(\n locale,\n parseFloat(output),\n SkyIntlNumberFormatStyle.Decimal,\n digits\n );\n break;\n }\n\n if (options.truncate) {\n output = this.replaceShortenSymbol(output);\n }\n\n return output;\n }\n\n /**\n * Rounds a given number\n *\n * JS's limitation - numbers bigger than Number.MIN_SAFE_INTEGER or Number.MAX_SAFE_INTEGER\n * are not guaranteed to be represented or rounded correctly\n * @param value - value to round\n * @param precision - what precision to round with, defaults to 0 decimal places\n */\n private roundNumber(value: number, precision: number = 0): number {\n if (precision < 0) {\n throw new Error('SkyInvalidArgument: precision must be >= 0');\n }\n\n /* tslint:disable-next-line:no-null-keyword */\n /* Sanity check - ignoring coverage but should not ignore if we make this method public */\n /* istanbul ignore next */\n if (isNaN(value) || value === null) {\n return 0;\n }\n\n const scaledValue: number = this.scaleNumberByPowerOfTen(\n value,\n precision,\n true\n );\n const scaledRoundedValue: number = Math.round(scaledValue);\n const unscaledRoundedValue: number = this.scaleNumberByPowerOfTen(\n scaledRoundedValue,\n precision,\n false\n );\n\n return unscaledRoundedValue;\n }\n\n /**\n * Scales a given number by a power of 10\n * @param value - value to scale\n * @param scalar - 10^scalar\n * @param scaleUp - whether to increase or decrease the value\n */\n private scaleNumberByPowerOfTen(\n value: number,\n scalar: number,\n scaleUp: boolean\n ): number {\n const valueStr: string = value.toString().toLowerCase();\n const isExponentFormat: boolean = valueStr.includes('e');\n\n if (isExponentFormat) {\n const [base, exp] = valueStr.split('e');\n const newExp = scaleUp ? Number(exp) + scalar : Number(exp) - scalar;\n return Number(`${base}e${newExp}`);\n } else {\n const e = scaleUp ? 'e' : 'e-';\n return Number(`${value}${e}${scalar}`);\n }\n }\n\n /**\n * Stores the symbol added from shortening to reapply later.\n * @param value The string to derive the shorten symbol from.\n */\n private storeShortenSymbol(value: string): void {\n const symbols: string[] = this.symbolIndex.map((s) => s.label);\n const regexp = new RegExp(symbols.join('|'), 'ig');\n const match = value.match(regexp);\n this.shortSymbol = match ? match.toString() : '';\n }\n\n /**\n * Must have previously called storeShortenSymbol to have something to replace.\n * Finds the last number in the formatted number, gets the index of the position\n * after that character and re-inserts the symbol.\n * Works regardless of currency symbol position.\n * @param value The string to modify.\n */\n private replaceShortenSymbol(value: string): string {\n const result = /(\\d)(?!.*\\d)/g.exec(value);\n const pos = result.index + result.length;\n const output =\n value.substring(0, pos) + this.shortSymbol + value.substring(pos);\n\n return output;\n }\n\n private getSymbol(key: string): string {\n // TODO: Need to implement the async `getString` method in a breaking change.\n return this.resourcesService.getStringForLocale({ locale: 'en_US' }, key);\n }\n}\n"]}
|
@@ -13,7 +13,7 @@ export class SkyResizeObserverMediaQueryService {
|
|
13
13
|
this.resizeObserverService = resizeObserverService;
|
14
14
|
this._breakpoints = [
|
15
15
|
{
|
16
|
-
check: (width) => width <= 767,
|
16
|
+
check: (width) => width > 0 && width <= 767,
|
17
17
|
name: SkyMediaBreakpoints.xs,
|
18
18
|
},
|
19
19
|
{
|
@@ -66,12 +66,8 @@ export class SkyResizeObserverMediaQueryService {
|
|
66
66
|
this._stopListening.next();
|
67
67
|
}
|
68
68
|
this._target = element;
|
69
|
-
|
70
|
-
|
71
|
-
const breakpoint = this.checkBreakpoint(width);
|
72
|
-
this.updateBreakpoint(breakpoint);
|
73
|
-
}
|
74
|
-
this._resizeSubscription = this.resizeObserverService
|
69
|
+
this.checkWidth(element);
|
70
|
+
this.resizeObserverService
|
75
71
|
.observe(element)
|
76
72
|
.pipe(takeUntil(this._stopListening))
|
77
73
|
.subscribe((value) => {
|
@@ -95,7 +91,9 @@ export class SkyResizeObserverMediaQueryService {
|
|
95
91
|
subscribe(listener) {
|
96
92
|
return this._currentBreakpointObservable
|
97
93
|
.pipe(takeUntil(this._stopListening))
|
98
|
-
.subscribe(
|
94
|
+
.subscribe((value) => {
|
95
|
+
listener(value);
|
96
|
+
});
|
99
97
|
}
|
100
98
|
updateBreakpoint(breakpoint) {
|
101
99
|
this._currentBreakpoint = breakpoint;
|
@@ -105,6 +103,14 @@ export class SkyResizeObserverMediaQueryService {
|
|
105
103
|
var _a;
|
106
104
|
return (_a = this._breakpoints.find((breakpoint) => breakpoint.check(width))) === null || _a === void 0 ? void 0 : _a.name;
|
107
105
|
}
|
106
|
+
checkWidth(element) {
|
107
|
+
const width = element.nativeElement.offsetWidth || 0;
|
108
|
+
const breakpoint = this.checkBreakpoint(width);
|
109
|
+
/* istanbul ignore else */
|
110
|
+
if (breakpoint !== this._currentBreakpoint) {
|
111
|
+
this.updateBreakpoint(breakpoint);
|
112
|
+
}
|
113
|
+
}
|
108
114
|
}
|
109
115
|
SkyResizeObserverMediaQueryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyResizeObserverMediaQueryService, deps: [{ token: i1.SkyResizeObserverService }], target: i0.ɵɵFactoryTarget.Injectable });
|
110
116
|
SkyResizeObserverMediaQueryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyResizeObserverMediaQueryService, providedIn: 'any' });
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"resize-observer-media-query.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/resize-observer/resize-observer-media-query.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAa,MAAM,eAAe,CAAC;AAElE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAgB,MAAM,MAAM,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAGvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;;;AAErE;;GAEG;AAIH,MAAM,OAAO,kCAAkC;
|
1
|
+
{"version":3,"file":"resize-observer-media-query.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/resize-observer/resize-observer-media-query.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU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B;aACrC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;aACpC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;YACnB,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,gBAAgB,CAAC,UAA+B;QACtD,IAAI,CAAC,kBAAkB,GAAG,UAAU,CAAC;QACrC,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACrD,CAAC;IAEO,eAAe,CAAC,KAAa;;QACnC,OAAO,MAAA,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,0CAClE,IAAI,CAAC;IACX,CAAC;IAEO,UAAU,CAAC,OAAmB;QACpC,MAAM,KAAK,GAAI,OAAO,CAAC,aAA6B,CAAC,WAAW,IAAI,CAAC,CAAC;QACtE,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC/C,0BAA0B;QAC1B,IAAI,UAAU,KAAK,IAAI,CAAC,kBAAkB,EAAE;YAC1C,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;SACnC;IACH,CAAC;;gIAtHU,kCAAkC;oIAAlC,kCAAkC,cAFjC,KAAK;4FAEN,kCAAkC;kBAH9C,UAAU;mBAAC;oBACV,UAAU,EAAE,KAAK;iBAClB","sourcesContent":["import { ElementRef, Injectable, OnDestroy } from '@angular/core';\n\nimport { ReplaySubject, Subject, Subscription } from 'rxjs';\nimport { takeUntil } from 'rxjs/operators';\n\nimport { SkyMediaBreakpoints } from '../media-query/media-breakpoints';\nimport { SkyMediaQueryListener } from '../media-query/media-query-listener';\n\nimport { SkyResizeObserverService } from './resize-observer.service';\n\n/**\n * Acts like `SkyMediaQueryService` for a container element, emitting the same responsive breakpoints.\n */\n@Injectable({\n providedIn: 'any',\n})\nexport class SkyResizeObserverMediaQueryService implements OnDestroy {\n /**\n * Returns the current breakpoint.\n */\n public get current(): SkyMediaBreakpoints | undefined {\n return this._currentBreakpoint;\n }\n\n private _breakpoints: {\n check: (width: number) => boolean;\n name: SkyMediaBreakpoints;\n }[] = [\n {\n check: (width: number) => width > 0 && width <= 767,\n name: SkyMediaBreakpoints.xs,\n },\n {\n check: (width: number) => width > 767 && width <= 991,\n name: SkyMediaBreakpoints.sm,\n },\n {\n check: (width: number) => width > 991 && width <= 1199,\n name: SkyMediaBreakpoints.md,\n },\n {\n check: (width: number) => width > 1199,\n name: SkyMediaBreakpoints.lg,\n },\n ];\n private _currentBreakpointObservable = new ReplaySubject<\n SkyMediaBreakpoints | undefined\n >(1);\n private _currentBreakpoint: SkyMediaBreakpoints;\n private _stopListening = new Subject<void>();\n private _target?: ElementRef;\n\n constructor(private resizeObserverService: SkyResizeObserverService) {\n this._stopListening.subscribe(() => {\n this._target = undefined;\n this.updateBreakpoint(undefined);\n });\n }\n\n public ngOnDestroy(): void {\n this._stopListening.next();\n this._currentBreakpoint = undefined;\n this._stopListening.complete();\n this._currentBreakpointObservable.complete();\n }\n\n /**\n * @internal\n */\n public destroy(): void {\n this.ngOnDestroy();\n }\n\n /**\n * Sets the container element to watch. The `SkyResizeObserverMediaQueryService` will only observe one element at a\n * time. Any previous subscriptions will be unsubscribed when a new element is observed.\n */\n public observe(element: ElementRef): SkyResizeObserverMediaQueryService {\n if (this._target) {\n if (this._target === element) {\n return this;\n }\n this._stopListening.next();\n }\n this._target = element;\n this.checkWidth(element);\n this.resizeObserverService\n .observe(element)\n .pipe(takeUntil(this._stopListening))\n .subscribe((value) => {\n const breakpoint = this.checkBreakpoint(value.contentRect.width);\n /* istanbul ignore else */\n if (breakpoint !== this._currentBreakpoint) {\n this.updateBreakpoint(breakpoint);\n }\n });\n return this;\n }\n\n /**\n * Stop watching the container element.\n */\n public unobserve(): void {\n this._stopListening.next();\n }\n\n /**\n * Subscribes to element size changes that cross breakpoints.\n */\n public subscribe(listener: SkyMediaQueryListener): Subscription {\n return this._currentBreakpointObservable\n .pipe(takeUntil(this._stopListening))\n .subscribe((value) => {\n listener(value);\n });\n }\n\n private updateBreakpoint(breakpoint: SkyMediaBreakpoints) {\n this._currentBreakpoint = breakpoint;\n this._currentBreakpointObservable.next(breakpoint);\n }\n\n private checkBreakpoint(width: number): SkyMediaBreakpoints | undefined {\n return this._breakpoints.find((breakpoint) => breakpoint.check(width))\n ?.name;\n }\n\n private checkWidth(element: ElementRef) {\n const width = (element.nativeElement as HTMLElement).offsetWidth || 0;\n const breakpoint = this.checkBreakpoint(width);\n /* istanbul ignore else */\n if (breakpoint !== this._currentBreakpoint) {\n this.updateBreakpoint(breakpoint);\n }\n }\n}\n"]}
|
package/fesm2015/skyux-core.js
CHANGED
@@ -1736,7 +1736,7 @@ class SkyNumericService {
|
|
1736
1736
|
return this._locale || 'en-US';
|
1737
1737
|
}
|
1738
1738
|
/**
|
1739
|
-
*
|
1739
|
+
* Formats a number based on the provided options.
|
1740
1740
|
* @param value The number to format.
|
1741
1741
|
* @param options Format options.
|
1742
1742
|
*/
|
@@ -1904,10 +1904,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImpo
|
|
1904
1904
|
* M for millions, B for billions, and T for trillions. The pipe also formats for currency.
|
1905
1905
|
* Be sure you have a space after the two curly brackets opening the pipe and
|
1906
1906
|
* a space before the two curly brackets closing the pipe or it will not work.
|
1907
|
-
* Usage:
|
1908
|
-
* ```
|
1909
|
-
* {{ value | skyNumeric(config) }}
|
1910
|
-
* ```
|
1911
1907
|
*/
|
1912
1908
|
class SkyNumericPipe {
|
1913
1909
|
constructor(localeProvider, numericService, changeDetector) {
|
@@ -1928,6 +1924,9 @@ class SkyNumericPipe {
|
|
1928
1924
|
this.ngUnsubscribe.next();
|
1929
1925
|
this.ngUnsubscribe.complete();
|
1930
1926
|
}
|
1927
|
+
/**
|
1928
|
+
* Formats a number based on the provided options.
|
1929
|
+
*/
|
1931
1930
|
transform(value, config) {
|
1932
1931
|
var _a;
|
1933
1932
|
const newCacheKey = (config ? JSON.stringify(config, Object.keys(config).sort()) : '') +
|
@@ -2494,7 +2493,7 @@ class SkyResizeObserverMediaQueryService {
|
|
2494
2493
|
this.resizeObserverService = resizeObserverService;
|
2495
2494
|
this._breakpoints = [
|
2496
2495
|
{
|
2497
|
-
check: (width) => width <= 767,
|
2496
|
+
check: (width) => width > 0 && width <= 767,
|
2498
2497
|
name: SkyMediaBreakpoints.xs,
|
2499
2498
|
},
|
2500
2499
|
{
|
@@ -2547,12 +2546,8 @@ class SkyResizeObserverMediaQueryService {
|
|
2547
2546
|
this._stopListening.next();
|
2548
2547
|
}
|
2549
2548
|
this._target = element;
|
2550
|
-
|
2551
|
-
|
2552
|
-
const breakpoint = this.checkBreakpoint(width);
|
2553
|
-
this.updateBreakpoint(breakpoint);
|
2554
|
-
}
|
2555
|
-
this._resizeSubscription = this.resizeObserverService
|
2549
|
+
this.checkWidth(element);
|
2550
|
+
this.resizeObserverService
|
2556
2551
|
.observe(element)
|
2557
2552
|
.pipe(takeUntil(this._stopListening))
|
2558
2553
|
.subscribe((value) => {
|
@@ -2576,7 +2571,9 @@ class SkyResizeObserverMediaQueryService {
|
|
2576
2571
|
subscribe(listener) {
|
2577
2572
|
return this._currentBreakpointObservable
|
2578
2573
|
.pipe(takeUntil(this._stopListening))
|
2579
|
-
.subscribe(
|
2574
|
+
.subscribe((value) => {
|
2575
|
+
listener(value);
|
2576
|
+
});
|
2580
2577
|
}
|
2581
2578
|
updateBreakpoint(breakpoint) {
|
2582
2579
|
this._currentBreakpoint = breakpoint;
|
@@ -2586,6 +2583,14 @@ class SkyResizeObserverMediaQueryService {
|
|
2586
2583
|
var _a;
|
2587
2584
|
return (_a = this._breakpoints.find((breakpoint) => breakpoint.check(width))) === null || _a === void 0 ? void 0 : _a.name;
|
2588
2585
|
}
|
2586
|
+
checkWidth(element) {
|
2587
|
+
const width = element.nativeElement.offsetWidth || 0;
|
2588
|
+
const breakpoint = this.checkBreakpoint(width);
|
2589
|
+
/* istanbul ignore else */
|
2590
|
+
if (breakpoint !== this._currentBreakpoint) {
|
2591
|
+
this.updateBreakpoint(breakpoint);
|
2592
|
+
}
|
2593
|
+
}
|
2589
2594
|
}
|
2590
2595
|
SkyResizeObserverMediaQueryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyResizeObserverMediaQueryService, deps: [{ token: SkyResizeObserverService }], target: i0.ɵɵFactoryTarget.Injectable });
|
2591
2596
|
SkyResizeObserverMediaQueryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyResizeObserverMediaQueryService, providedIn: 'any' });
|