@skyux/core 5.6.0 → 5.6.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.
@@ -1511,6 +1511,7 @@
1511
1511
  }
1512
1512
  /*istanbul ignore else */
1513
1513
  if (window.console) {
1514
+ // eslint-disable-next-line prefer-spread,prefer-rest-params
1514
1515
  window.console.warn.apply(window.console, arguments);
1515
1516
  }
1516
1517
  };
@@ -2211,6 +2212,7 @@
2211
2212
  this.storeShortenSymbol(output);
2212
2213
  var locale = options.locale || this.currentLocale;
2213
2214
  var digits;
2215
+ var isDecimal;
2214
2216
  // Checks the string entered for format. Using toLowerCase to ignore case.
2215
2217
  switch ((_a = options.format) === null || _a === void 0 ? void 0 : _a.toLowerCase()) {
2216
2218
  // In a case where a decimal value was not shortened and
@@ -2219,7 +2221,7 @@
2219
2221
  // Note: This will need to be reviewed if we support currencies with
2220
2222
  // three decimal digits.
2221
2223
  case 'currency':
2222
- var isDecimal = value % 1 !== 0;
2224
+ isDecimal = value % 1 !== 0;
2223
2225
  if (options.minDigits) {
2224
2226
  digits = "1." + options.minDigits + "-" + options.digits;
2225
2227
  }
@@ -2229,12 +2231,12 @@
2229
2231
  else {
2230
2232
  digits = "1.0-" + options.digits;
2231
2233
  }
2234
+ output = SkyNumberFormatUtility.formatNumber(locale, parseFloat(output), i1.SkyIntlNumberFormatStyle.Currency, digits, options.iso,
2232
2235
  // Angular 5+ needs a string for this parameter, but Angular 4 needs a boolean.
2233
2236
  // To support both versions we can supply 'symbol' which will evaluate truthy for Angular 4
2234
2237
  // and the appropriate string value for Angular 5+.
2235
2238
  // See: https://angular.io/api/common/CurrencyPipe#parameters
2236
- var symbolDisplay = 'symbol';
2237
- output = SkyNumberFormatUtility.formatNumber(locale, parseFloat(output), i1.SkyIntlNumberFormatStyle.Currency, digits, options.iso, symbolDisplay, options.currencySign);
2239
+ 'symbol', options.currencySign);
2238
2240
  break;
2239
2241
  // The following is a catch-all to ensure that if
2240
2242
  // anything but currency (or a future option) are entered,
@@ -3284,25 +3286,22 @@
3284
3286
  };
3285
3287
  SkyViewkeeper.prototype.shouldFixEl = function (boundaryInfo, verticalOffset) {
3286
3288
  var anchorTop;
3287
- var doFixEl;
3288
3289
  if (boundaryInfo.spacerEl) {
3289
3290
  anchorTop = getOffset(boundaryInfo.spacerEl, this.scrollableHost).top;
3290
3291
  }
3291
3292
  else {
3292
3293
  anchorTop = getOffset(this.el, this.scrollableHost).top;
3293
3294
  }
3294
- doFixEl =
3295
- boundaryInfo.scrollTop + verticalOffset + this.viewportMarginTop >
3296
- anchorTop;
3295
+ var doFixEl = boundaryInfo.scrollTop + verticalOffset + this.viewportMarginTop >
3296
+ anchorTop;
3297
3297
  return doFixEl;
3298
3298
  };
3299
3299
  SkyViewkeeper.prototype.getFixedStyles = function (boundaryInfo, verticalOffset) {
3300
- var elFixedTop;
3301
3300
  // If the element needs to be fixed, this will calculate its position. The position
3302
3301
  // will be 0 (fully visible) unless the user is scrolling the boundary out of view.
3303
3302
  // In that case, the element should begin to scroll out of view with the
3304
3303
  // rest of the boundary by setting its top position to a negative value.
3305
- elFixedTop = Math.min(boundaryInfo.boundaryBottom -
3304
+ var elFixedTop = Math.min(boundaryInfo.boundaryBottom -
3306
3305
  boundaryInfo.elHeight -
3307
3306
  boundaryInfo.scrollTop, verticalOffset);
3308
3307
  var elFixedWidth = boundaryInfo.boundaryEl.getBoundingClientRect().width;
@@ -7,6 +7,7 @@ export class SkyLogService {
7
7
  warn(message, ...optionalParams) {
8
8
  /*istanbul ignore else */
9
9
  if (window.console) {
10
+ // eslint-disable-next-line prefer-spread,prefer-rest-params
10
11
  window.console.warn.apply(window.console, arguments);
11
12
  }
12
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"log.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/log/log.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;;AAE3C;;GAEG;AAIH,MAAM,OAAO,aAAa;IACjB,IAAI,CAAC,OAAa,EAAE,GAAG,cAAqB;QACjD,yBAAyB;QACzB,IAAI,MAAM,CAAC,OAAO,EAAE;YAClB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;SACtD;IACH,CAAC;;2GANU,aAAa;+GAAb,aAAa,cAFZ,MAAM;4FAEP,aAAa;kBAHzB,UAAU;mBAAC;oBACV,UAAU,EAAE,MAAM;iBACnB","sourcesContent":["import { Injectable } from '@angular/core';\n\n/**\n * @deprecated The `SkyLogService` will be removed in the next major version of `@skyux/core`.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class SkyLogService {\n public warn(message?: any, ...optionalParams: any[]): void {\n /*istanbul ignore else */\n if (window.console) {\n window.console.warn.apply(window.console, arguments);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"log.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/log/log.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;;AAE3C;;GAEG;AAIH,MAAM,OAAO,aAAa;IACjB,IAAI,CAAC,OAAa,EAAE,GAAG,cAAqB;QACjD,yBAAyB;QACzB,IAAI,MAAM,CAAC,OAAO,EAAE;YAClB,4DAA4D;YAC5D,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;SACtD;IACH,CAAC;;2GAPU,aAAa;+GAAb,aAAa,cAFZ,MAAM;4FAEP,aAAa;kBAHzB,UAAU;mBAAC;oBACV,UAAU,EAAE,MAAM;iBACnB","sourcesContent":["import { Injectable } from '@angular/core';\n\n/**\n * @deprecated The `SkyLogService` will be removed in the next major version of `@skyux/core`.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class SkyLogService {\n public warn(message?: any, ...optionalParams: any[]): void {\n /*istanbul ignore else */\n if (window.console) {\n // eslint-disable-next-line prefer-spread,prefer-rest-params\n window.console.warn.apply(window.console, arguments);\n }\n }\n}\n"]}
@@ -59,6 +59,7 @@ export class SkyNumericService {
59
59
  this.storeShortenSymbol(output);
60
60
  const locale = options.locale || this.currentLocale;
61
61
  let digits;
62
+ let isDecimal;
62
63
  // Checks the string entered for format. Using toLowerCase to ignore case.
63
64
  switch ((_a = options.format) === null || _a === void 0 ? void 0 : _a.toLowerCase()) {
64
65
  // In a case where a decimal value was not shortened and
@@ -67,7 +68,7 @@ export class SkyNumericService {
67
68
  // Note: This will need to be reviewed if we support currencies with
68
69
  // three decimal digits.
69
70
  case 'currency':
70
- const isDecimal = value % 1 !== 0;
71
+ isDecimal = value % 1 !== 0;
71
72
  if (options.minDigits) {
72
73
  digits = `1.${options.minDigits}-${options.digits}`;
73
74
  }
@@ -77,12 +78,12 @@ export class SkyNumericService {
77
78
  else {
78
79
  digits = `1.0-${options.digits}`;
79
80
  }
81
+ output = SkyNumberFormatUtility.formatNumber(locale, parseFloat(output), SkyIntlNumberFormatStyle.Currency, digits, options.iso,
80
82
  // Angular 5+ needs a string for this parameter, but Angular 4 needs a boolean.
81
83
  // To support both versions we can supply 'symbol' which will evaluate truthy for Angular 4
82
84
  // and the appropriate string value for Angular 5+.
83
85
  // See: https://angular.io/api/common/CurrencyPipe#parameters
84
- const symbolDisplay = 'symbol';
85
- output = SkyNumberFormatUtility.formatNumber(locale, parseFloat(output), SkyIntlNumberFormatStyle.Currency, digits, options.iso, symbolDisplay, options.currencySign);
86
+ 'symbol', options.currencySign);
86
87
  break;
87
88
  // The following is a catch-all to ensure that if
88
89
  // anything but currency (or a future option) are entered,
@@ -1 +1 @@
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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yle, 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 // 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 const 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 // 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 const symbolDisplay: any = 'symbol';\n\n output = SkyNumberFormatUtility.formatNumber(\n locale,\n parseFloat(output),\n SkyIntlNumberFormatStyle.Currency,\n digits,\n options.iso,\n symbolDisplay,\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,IAAI,EAAE;YAClC,OAAO,EAAE,CAAC;SACX;QAED,MAAM,kBAAkB,GAAG,0BAA0B,CAAC;QAEtD,qFAAqF;QACrF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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 * 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"]}
@@ -160,25 +160,22 @@ export class SkyViewkeeper {
160
160
  }
161
161
  shouldFixEl(boundaryInfo, verticalOffset) {
162
162
  let anchorTop;
163
- let doFixEl;
164
163
  if (boundaryInfo.spacerEl) {
165
164
  anchorTop = getOffset(boundaryInfo.spacerEl, this.scrollableHost).top;
166
165
  }
167
166
  else {
168
167
  anchorTop = getOffset(this.el, this.scrollableHost).top;
169
168
  }
170
- doFixEl =
171
- boundaryInfo.scrollTop + verticalOffset + this.viewportMarginTop >
172
- anchorTop;
169
+ const doFixEl = boundaryInfo.scrollTop + verticalOffset + this.viewportMarginTop >
170
+ anchorTop;
173
171
  return doFixEl;
174
172
  }
175
173
  getFixedStyles(boundaryInfo, verticalOffset) {
176
- let elFixedTop;
177
174
  // If the element needs to be fixed, this will calculate its position. The position
178
175
  // will be 0 (fully visible) unless the user is scrolling the boundary out of view.
179
176
  // In that case, the element should begin to scroll out of view with the
180
177
  // rest of the boundary by setting its top position to a negative value.
181
- elFixedTop = Math.min(boundaryInfo.boundaryBottom -
178
+ const elFixedTop = Math.min(boundaryInfo.boundaryBottom -
182
179
  boundaryInfo.elHeight -
183
180
  boundaryInfo.scrollTop, verticalOffset);
184
181
  const elFixedWidth = boundaryInfo.boundaryEl.getBoundingClientRect().width;
@@ -1 +1 @@
1
- {"version":3,"file":"viewkeeper.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/viewkeeper/viewkeeper.ts"],"names":[],"mappings":"AAKA,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AACpD,MAAM,yBAAyB,GAAG,qBAAqB,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AC;QAClE,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC;QACvC,MAAM,cAAc,GAClB,WAAW,GAAG,UAAU,CAAC,qBAAqB,EAAE,CAAC,MAAM,CAAC;QAE1D,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc;YACpC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU;YAChC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,UAAU,CAAC;QACxC,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc;YACnC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,SAAS;YAC/B,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAC;QAEvC,MAAM,QAAQ,GAAG,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE9C,OAAO;YACL,cAAc;YACd,cAAc;YACd,UAAU;YACV,QAAQ;YACR,UAAU;YACV,SAAS;YACT,QAAQ;YACR,QAAQ;SACT,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { SkyViewkeeperBoundaryInfo } from './viewkeeper-boundary-info';\nimport { SkyViewkeeperFixedStyles } from './viewkeeper-fixed-styles';\nimport { SkyViewkeeperOffset } from './viewkeeper-offset';\nimport { SkyViewkeeperOptions } from './viewkeeper-options';\n\nconst CLS_VIEWKEEPER_FIXED = 'sky-viewkeeper-fixed';\nconst EVT_AFTER_VIEWKEEPER_SYNC = 'afterViewkeeperSync';\n\nlet styleEl: HTMLStyleElement;\nlet nextIdIndex: number;\n\nfunction ensureStyleEl(): void {\n if (!styleEl) {\n styleEl = document.createElement('style');\n\n const css = document.createTextNode(`\n.${CLS_VIEWKEEPER_FIXED} {\n position: fixed !important;\n z-index: 999;\n opacity: 0.95;\n overflow: hidden;\n}\n\n.sky-theme-modern .${CLS_VIEWKEEPER_FIXED} {\n box-shadow: 0px 1px 8px -1px rgba(0, 0, 0, 0.3);\n opacity: initial;\n}\n`);\n\n styleEl.appendChild(css);\n\n document.head.appendChild(styleEl);\n }\n}\n\nfunction nextId(): string {\n nextIdIndex = (nextIdIndex || 0) + 1;\n\n return 'viewkeeper-' + nextIdIndex;\n}\n\nfunction getOffset(\n el: HTMLElement,\n scrollableHost?: HTMLElement\n): SkyViewkeeperOffset {\n const rect = el.getBoundingClientRect();\n const parent = scrollableHost ? scrollableHost : document.documentElement;\n\n return {\n top: rect.top + parent.scrollTop,\n left: rect.left + parent.scrollLeft,\n };\n}\n\nfunction px(value: number | string): string {\n let pxValue = value ? value.toString() : '';\n\n if (typeof value === 'number') {\n pxValue = value + 'px';\n }\n\n return pxValue;\n}\n\nfunction setElPosition(\n el: HTMLElement,\n left: number | string,\n top: number | string,\n width: number | string,\n marginTop: number | string\n): void {\n el.style.top = px(top);\n el.style.left = px(left);\n el.style.marginTop = px(marginTop);\n\n /*istanbul ignore else*/\n /* sanity check */\n if (width !== null) {\n el.style.width = px(width);\n }\n}\n\nfunction getHeightWithMargin(el: HTMLElement): number {\n const computedStyle = getComputedStyle(el);\n\n return (\n el.offsetHeight +\n parseInt(computedStyle.marginTop, 10) +\n parseInt(computedStyle.marginBottom, 10)\n );\n}\n\nfunction createCustomEvent(name: any): CustomEvent<any> {\n const evt = document.createEvent('CustomEvent');\n\n evt.initCustomEvent(name, false, false, undefined);\n\n return evt;\n}\n\nexport class SkyViewkeeper {\n private setWidth: boolean;\n\n private id: string;\n\n private el: HTMLElement;\n\n private boundaryEl: HTMLElement;\n\n private verticalOffset: number;\n\n private verticalOffsetEl: HTMLElement;\n\n private set viewportMarginTop(margin: number) {\n this._viewportMarginTop = margin;\n }\n\n private get viewportMarginTop(): number {\n if (this.scrollableHost) {\n return 0;\n } else {\n return this._viewportMarginTop;\n }\n }\n\n private isDestroyed: boolean;\n\n private currentElFixedTop: number;\n\n private currentElFixedLeft: number;\n\n private currentElFixedWidth: number;\n\n private scrollableHost: HTMLElement;\n\n private syncElPositionHandler: () => void;\n\n private _viewportMarginTop: number;\n\n constructor(options: SkyViewkeeperOptions) {\n options = options || /* istanbul ignore next */ {};\n\n this.setWidth = options.setWidth;\n this.id = nextId();\n this.el = options.el;\n this.boundaryEl = options.boundaryEl;\n this.scrollableHost = options.scrollableHost;\n this.verticalOffset = options.verticalOffset || 0;\n this.verticalOffsetEl = options.verticalOffsetEl;\n this.viewportMarginTop = options.viewportMarginTop || 0;\n\n this.syncElPositionHandler = () => this.syncElPosition();\n\n if (this.verticalOffsetEl) {\n this.verticalOffsetEl.addEventListener(\n EVT_AFTER_VIEWKEEPER_SYNC,\n this.syncElPositionHandler\n );\n }\n\n window.addEventListener('scroll', this.syncElPositionHandler, true);\n window.addEventListener('resize', this.syncElPositionHandler);\n window.addEventListener('orientationchange', this.syncElPositionHandler);\n\n ensureStyleEl();\n\n this.syncElPosition();\n }\n\n public syncElPosition(): void {\n const verticalOffset = this.calculateVerticalOffset();\n\n // When the element isn't visible, its size can't be calculated, so don't attempt syncing position in this case.\n if (this.el.offsetWidth === 0 && this.el.offsetHeight === 0) {\n return;\n }\n\n const boundaryInfo = this.getBoundaryInfo();\n const fixedStyles = this.getFixedStyles(boundaryInfo, verticalOffset);\n\n const doFixEl = this.shouldFixEl(boundaryInfo, verticalOffset);\n\n if (this.needsUpdating(doFixEl, fixedStyles)) {\n if (doFixEl) {\n this.fixEl(boundaryInfo, fixedStyles);\n } else {\n this.unfixEl();\n }\n }\n\n const evt = createCustomEvent(EVT_AFTER_VIEWKEEPER_SYNC);\n\n this.el.dispatchEvent(evt);\n }\n\n public destroy(): void {\n if (!this.isDestroyed) {\n window.removeEventListener('scroll', this.syncElPositionHandler, true);\n window.removeEventListener('resize', this.syncElPositionHandler);\n window.removeEventListener(\n 'orientationchange',\n this.syncElPositionHandler\n );\n\n this.unfixEl();\n\n if (this.verticalOffsetEl) {\n this.verticalOffsetEl.removeEventListener(\n EVT_AFTER_VIEWKEEPER_SYNC,\n this.syncElPositionHandler\n );\n }\n\n this.el = this.boundaryEl = this.verticalOffsetEl = undefined;\n\n this.isDestroyed = true;\n }\n }\n\n private getSpacerId(): string {\n return this.id + '-spacer';\n }\n\n private unfixEl(): void {\n const spacerEl = document.getElementById(this.getSpacerId());\n\n if (spacerEl) {\n spacerEl.parentElement.removeChild(spacerEl);\n }\n\n this.el.classList.remove(CLS_VIEWKEEPER_FIXED);\n\n this.currentElFixedLeft =\n this.currentElFixedTop =\n this.currentElFixedWidth =\n undefined;\n\n let width: string;\n\n if (this.setWidth) {\n width = 'auto';\n }\n\n setElPosition(this.el, '', '', width, '');\n }\n\n private calculateVerticalOffset(): number {\n let offset = this.verticalOffset;\n\n if (this.verticalOffsetEl) {\n const verticalOffsetElTopStyle = this.verticalOffsetEl.style.top;\n const verticalOffsetElTop = parseInt(verticalOffsetElTopStyle, 10) || 0;\n\n offset += this.verticalOffsetEl.offsetHeight + verticalOffsetElTop;\n } else if (this.scrollableHost) {\n offset += this.scrollableHost.getBoundingClientRect().top;\n }\n\n return offset;\n }\n\n private shouldFixEl(\n boundaryInfo: SkyViewkeeperBoundaryInfo,\n verticalOffset: number\n ): boolean {\n let anchorTop: number;\n let doFixEl: boolean;\n\n if (boundaryInfo.spacerEl) {\n anchorTop = getOffset(boundaryInfo.spacerEl, this.scrollableHost).top;\n } else {\n anchorTop = getOffset(this.el, this.scrollableHost).top;\n }\n\n doFixEl =\n boundaryInfo.scrollTop + verticalOffset + this.viewportMarginTop >\n anchorTop;\n\n return doFixEl;\n }\n\n private getFixedStyles(\n boundaryInfo: SkyViewkeeperBoundaryInfo,\n verticalOffset: number\n ): SkyViewkeeperFixedStyles {\n let elFixedTop: number;\n\n // If the element needs to be fixed, this will calculate its position. The position\n // will be 0 (fully visible) unless the user is scrolling the boundary out of view.\n // In that case, the element should begin to scroll out of view with the\n // rest of the boundary by setting its top position to a negative value.\n elFixedTop = Math.min(\n boundaryInfo.boundaryBottom -\n boundaryInfo.elHeight -\n boundaryInfo.scrollTop,\n verticalOffset\n );\n\n const elFixedWidth = boundaryInfo.boundaryEl.getBoundingClientRect().width;\n const elFixedLeft =\n boundaryInfo.boundaryOffset.left - boundaryInfo.scrollLeft;\n\n return {\n elFixedLeft,\n elFixedTop,\n elFixedWidth,\n };\n }\n\n private needsUpdating(\n doFixEl: boolean,\n fixedStyles: SkyViewkeeperFixedStyles\n ): boolean {\n if (\n (doFixEl &&\n this.currentElFixedLeft === fixedStyles.elFixedLeft &&\n this.currentElFixedTop === fixedStyles.elFixedTop &&\n this.currentElFixedWidth === fixedStyles.elFixedWidth) ||\n (!doFixEl &&\n !(\n this.currentElFixedLeft !== undefined &&\n this.currentElFixedLeft !== null\n ))\n ) {\n // The element is either currently fixed and its position and width do not need\n // to change, or the element is not currently fixed and does not need to be fixed.\n // No changes are needed.\n return false;\n }\n\n return true;\n }\n\n private fixEl(\n boundaryInfo: SkyViewkeeperBoundaryInfo,\n fixedStyles: SkyViewkeeperFixedStyles\n ): void {\n const el = this.el;\n\n /* istanbul ignore else */\n /* sanity check */\n if (!boundaryInfo.spacerEl) {\n const spacerHeight = boundaryInfo.elHeight;\n\n const spacerEl = document.createElement('div');\n spacerEl.id = boundaryInfo.spacerId;\n spacerEl.style.height = px(spacerHeight);\n\n el.parentNode.insertBefore(spacerEl, el.nextSibling);\n }\n\n el.classList.add(CLS_VIEWKEEPER_FIXED);\n\n this.currentElFixedTop = fixedStyles.elFixedTop;\n this.currentElFixedLeft = fixedStyles.elFixedLeft;\n this.currentElFixedWidth = fixedStyles.elFixedWidth;\n\n let width: number;\n\n if (this.setWidth) {\n width = fixedStyles.elFixedWidth;\n }\n\n setElPosition(\n el,\n fixedStyles.elFixedLeft,\n fixedStyles.elFixedTop,\n width,\n this.viewportMarginTop\n );\n }\n\n private getBoundaryInfo(): SkyViewkeeperBoundaryInfo {\n const spacerId = this.getSpacerId();\n\n const spacerEl = document.getElementById(spacerId);\n\n const boundaryEl = this.boundaryEl;\n\n const boundaryOffset = getOffset(boundaryEl, this.scrollableHost);\n const boundaryTop = boundaryOffset.top;\n const boundaryBottom =\n boundaryTop + boundaryEl.getBoundingClientRect().height;\n\n const scrollLeft = this.scrollableHost\n ? this.scrollableHost.scrollLeft\n : document.documentElement.scrollLeft;\n const scrollTop = this.scrollableHost\n ? this.scrollableHost.scrollTop\n : document.documentElement.scrollTop;\n\n const elHeight = getHeightWithMargin(this.el);\n\n return {\n boundaryBottom,\n boundaryOffset,\n boundaryEl,\n elHeight,\n scrollLeft,\n scrollTop,\n spacerId,\n spacerEl,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"viewkeeper.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/viewkeeper/viewkeeper.ts"],"names":[],"mappings":"AAKA,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AACpD,MAAM,yBAAyB,GAAG,qBAAqB,CAAC;AAExD,IAAI,OAAyB,CAAC;AAC9B,IAAI,WAAmB,CAAC;AAExB,SAAS,aAAa;IACpB,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAE1C,MAAM,GAAG,GAAG,QAAQ,CAAC,cAAc,CAAC;GACrC,oBAAoB;;;;;;;qBAOF,oBAAoB;;;;CAIxC,CAAC,CAAC;QAEC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAEzB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;KACpC;AACH,CAAC;AAED,SAAS,MAAM;IACb,WAAW,GAAG,CAAC,WAAW,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IAErC,OAAO,aAAa,GAAG,WAAW,CAAC;AACrC,CAAC;AAED,SAAS,SAAS,CAChB,EAAe,EACf,cAA4B;IAE5B,MAAM,IAAI,GAAG,EAAE,CAAC,qBAAqB,EAAE,CAAC;IACxC,MAAM,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC;IAE1E,OAAO;QACL,GAAG,EAAE,IAAI,CAAC,GAAG,GA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AAY,CAAC;SAClC;QAED,aAAa,CACX,EAAE,EACF,WAAW,CAAC,WAAW,EACvB,WAAW,CAAC,UAAU,EACtB,KAAK,EACL,IAAI,CAAC,iBAAiB,CACvB,CAAC;IACJ,CAAC;IAEO,eAAe;QACrB,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAEpC,MAAM,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAEnD,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAEnC,MAAM,cAAc,GAAG,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAClE,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC;QACvC,MAAM,cAAc,GAClB,WAAW,GAAG,UAAU,CAAC,qBAAqB,EAAE,CAAC,MAAM,CAAC;QAE1D,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc;YACpC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU;YAChC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,UAAU,CAAC;QACxC,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc;YACnC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,SAAS;YAC/B,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAC;QAEvC,MAAM,QAAQ,GAAG,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE9C,OAAO;YACL,cAAc;YACd,cAAc;YACd,UAAU;YACV,QAAQ;YACR,UAAU;YACV,SAAS;YACT,QAAQ;YACR,QAAQ;SACT,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { SkyViewkeeperBoundaryInfo } from './viewkeeper-boundary-info';\nimport { SkyViewkeeperFixedStyles } from './viewkeeper-fixed-styles';\nimport { SkyViewkeeperOffset } from './viewkeeper-offset';\nimport { SkyViewkeeperOptions } from './viewkeeper-options';\n\nconst CLS_VIEWKEEPER_FIXED = 'sky-viewkeeper-fixed';\nconst EVT_AFTER_VIEWKEEPER_SYNC = 'afterViewkeeperSync';\n\nlet styleEl: HTMLStyleElement;\nlet nextIdIndex: number;\n\nfunction ensureStyleEl(): void {\n if (!styleEl) {\n styleEl = document.createElement('style');\n\n const css = document.createTextNode(`\n.${CLS_VIEWKEEPER_FIXED} {\n position: fixed !important;\n z-index: 999;\n opacity: 0.95;\n overflow: hidden;\n}\n\n.sky-theme-modern .${CLS_VIEWKEEPER_FIXED} {\n box-shadow: 0px 1px 8px -1px rgba(0, 0, 0, 0.3);\n opacity: initial;\n}\n`);\n\n styleEl.appendChild(css);\n\n document.head.appendChild(styleEl);\n }\n}\n\nfunction nextId(): string {\n nextIdIndex = (nextIdIndex || 0) + 1;\n\n return 'viewkeeper-' + nextIdIndex;\n}\n\nfunction getOffset(\n el: HTMLElement,\n scrollableHost?: HTMLElement\n): SkyViewkeeperOffset {\n const rect = el.getBoundingClientRect();\n const parent = scrollableHost ? scrollableHost : document.documentElement;\n\n return {\n top: rect.top + parent.scrollTop,\n left: rect.left + parent.scrollLeft,\n };\n}\n\nfunction px(value: number | string): string {\n let pxValue = value ? value.toString() : '';\n\n if (typeof value === 'number') {\n pxValue = value + 'px';\n }\n\n return pxValue;\n}\n\nfunction setElPosition(\n el: HTMLElement,\n left: number | string,\n top: number | string,\n width: number | string,\n marginTop: number | string\n): void {\n el.style.top = px(top);\n el.style.left = px(left);\n el.style.marginTop = px(marginTop);\n\n /*istanbul ignore else*/\n /* sanity check */\n if (width !== null) {\n el.style.width = px(width);\n }\n}\n\nfunction getHeightWithMargin(el: HTMLElement): number {\n const computedStyle = getComputedStyle(el);\n\n return (\n el.offsetHeight +\n parseInt(computedStyle.marginTop, 10) +\n parseInt(computedStyle.marginBottom, 10)\n );\n}\n\nfunction createCustomEvent(name: any): CustomEvent<any> {\n const evt = document.createEvent('CustomEvent');\n\n evt.initCustomEvent(name, false, false, undefined);\n\n return evt;\n}\n\nexport class SkyViewkeeper {\n private setWidth: boolean;\n\n private id: string;\n\n private el: HTMLElement;\n\n private boundaryEl: HTMLElement;\n\n private verticalOffset: number;\n\n private verticalOffsetEl: HTMLElement;\n\n private set viewportMarginTop(margin: number) {\n this._viewportMarginTop = margin;\n }\n\n private get viewportMarginTop(): number {\n if (this.scrollableHost) {\n return 0;\n } else {\n return this._viewportMarginTop;\n }\n }\n\n private isDestroyed: boolean;\n\n private currentElFixedTop: number;\n\n private currentElFixedLeft: number;\n\n private currentElFixedWidth: number;\n\n private scrollableHost: HTMLElement;\n\n private syncElPositionHandler: () => void;\n\n private _viewportMarginTop: number;\n\n constructor(options: SkyViewkeeperOptions) {\n options = options || /* istanbul ignore next */ {};\n\n this.setWidth = options.setWidth;\n this.id = nextId();\n this.el = options.el;\n this.boundaryEl = options.boundaryEl;\n this.scrollableHost = options.scrollableHost;\n this.verticalOffset = options.verticalOffset || 0;\n this.verticalOffsetEl = options.verticalOffsetEl;\n this.viewportMarginTop = options.viewportMarginTop || 0;\n\n this.syncElPositionHandler = () => this.syncElPosition();\n\n if (this.verticalOffsetEl) {\n this.verticalOffsetEl.addEventListener(\n EVT_AFTER_VIEWKEEPER_SYNC,\n this.syncElPositionHandler\n );\n }\n\n window.addEventListener('scroll', this.syncElPositionHandler, true);\n window.addEventListener('resize', this.syncElPositionHandler);\n window.addEventListener('orientationchange', this.syncElPositionHandler);\n\n ensureStyleEl();\n\n this.syncElPosition();\n }\n\n public syncElPosition(): void {\n const verticalOffset = this.calculateVerticalOffset();\n\n // When the element isn't visible, its size can't be calculated, so don't attempt syncing position in this case.\n if (this.el.offsetWidth === 0 && this.el.offsetHeight === 0) {\n return;\n }\n\n const boundaryInfo = this.getBoundaryInfo();\n const fixedStyles = this.getFixedStyles(boundaryInfo, verticalOffset);\n\n const doFixEl = this.shouldFixEl(boundaryInfo, verticalOffset);\n\n if (this.needsUpdating(doFixEl, fixedStyles)) {\n if (doFixEl) {\n this.fixEl(boundaryInfo, fixedStyles);\n } else {\n this.unfixEl();\n }\n }\n\n const evt = createCustomEvent(EVT_AFTER_VIEWKEEPER_SYNC);\n\n this.el.dispatchEvent(evt);\n }\n\n public destroy(): void {\n if (!this.isDestroyed) {\n window.removeEventListener('scroll', this.syncElPositionHandler, true);\n window.removeEventListener('resize', this.syncElPositionHandler);\n window.removeEventListener(\n 'orientationchange',\n this.syncElPositionHandler\n );\n\n this.unfixEl();\n\n if (this.verticalOffsetEl) {\n this.verticalOffsetEl.removeEventListener(\n EVT_AFTER_VIEWKEEPER_SYNC,\n this.syncElPositionHandler\n );\n }\n\n this.el = this.boundaryEl = this.verticalOffsetEl = undefined;\n\n this.isDestroyed = true;\n }\n }\n\n private getSpacerId(): string {\n return this.id + '-spacer';\n }\n\n private unfixEl(): void {\n const spacerEl = document.getElementById(this.getSpacerId());\n\n if (spacerEl) {\n spacerEl.parentElement.removeChild(spacerEl);\n }\n\n this.el.classList.remove(CLS_VIEWKEEPER_FIXED);\n\n this.currentElFixedLeft =\n this.currentElFixedTop =\n this.currentElFixedWidth =\n undefined;\n\n let width: string;\n\n if (this.setWidth) {\n width = 'auto';\n }\n\n setElPosition(this.el, '', '', width, '');\n }\n\n private calculateVerticalOffset(): number {\n let offset = this.verticalOffset;\n\n if (this.verticalOffsetEl) {\n const verticalOffsetElTopStyle = this.verticalOffsetEl.style.top;\n const verticalOffsetElTop = parseInt(verticalOffsetElTopStyle, 10) || 0;\n\n offset += this.verticalOffsetEl.offsetHeight + verticalOffsetElTop;\n } else if (this.scrollableHost) {\n offset += this.scrollableHost.getBoundingClientRect().top;\n }\n\n return offset;\n }\n\n private shouldFixEl(\n boundaryInfo: SkyViewkeeperBoundaryInfo,\n verticalOffset: number\n ): boolean {\n let anchorTop: number;\n\n if (boundaryInfo.spacerEl) {\n anchorTop = getOffset(boundaryInfo.spacerEl, this.scrollableHost).top;\n } else {\n anchorTop = getOffset(this.el, this.scrollableHost).top;\n }\n\n const doFixEl =\n boundaryInfo.scrollTop + verticalOffset + this.viewportMarginTop >\n anchorTop;\n\n return doFixEl;\n }\n\n private getFixedStyles(\n boundaryInfo: SkyViewkeeperBoundaryInfo,\n verticalOffset: number\n ): SkyViewkeeperFixedStyles {\n // If the element needs to be fixed, this will calculate its position. The position\n // will be 0 (fully visible) unless the user is scrolling the boundary out of view.\n // In that case, the element should begin to scroll out of view with the\n // rest of the boundary by setting its top position to a negative value.\n const elFixedTop = Math.min(\n boundaryInfo.boundaryBottom -\n boundaryInfo.elHeight -\n boundaryInfo.scrollTop,\n verticalOffset\n );\n\n const elFixedWidth = boundaryInfo.boundaryEl.getBoundingClientRect().width;\n const elFixedLeft =\n boundaryInfo.boundaryOffset.left - boundaryInfo.scrollLeft;\n\n return {\n elFixedLeft,\n elFixedTop,\n elFixedWidth,\n };\n }\n\n private needsUpdating(\n doFixEl: boolean,\n fixedStyles: SkyViewkeeperFixedStyles\n ): boolean {\n if (\n (doFixEl &&\n this.currentElFixedLeft === fixedStyles.elFixedLeft &&\n this.currentElFixedTop === fixedStyles.elFixedTop &&\n this.currentElFixedWidth === fixedStyles.elFixedWidth) ||\n (!doFixEl &&\n !(\n this.currentElFixedLeft !== undefined &&\n this.currentElFixedLeft !== null\n ))\n ) {\n // The element is either currently fixed and its position and width do not need\n // to change, or the element is not currently fixed and does not need to be fixed.\n // No changes are needed.\n return false;\n }\n\n return true;\n }\n\n private fixEl(\n boundaryInfo: SkyViewkeeperBoundaryInfo,\n fixedStyles: SkyViewkeeperFixedStyles\n ): void {\n const el = this.el;\n\n /* istanbul ignore else */\n /* sanity check */\n if (!boundaryInfo.spacerEl) {\n const spacerHeight = boundaryInfo.elHeight;\n\n const spacerEl = document.createElement('div');\n spacerEl.id = boundaryInfo.spacerId;\n spacerEl.style.height = px(spacerHeight);\n\n el.parentNode.insertBefore(spacerEl, el.nextSibling);\n }\n\n el.classList.add(CLS_VIEWKEEPER_FIXED);\n\n this.currentElFixedTop = fixedStyles.elFixedTop;\n this.currentElFixedLeft = fixedStyles.elFixedLeft;\n this.currentElFixedWidth = fixedStyles.elFixedWidth;\n\n let width: number;\n\n if (this.setWidth) {\n width = fixedStyles.elFixedWidth;\n }\n\n setElPosition(\n el,\n fixedStyles.elFixedLeft,\n fixedStyles.elFixedTop,\n width,\n this.viewportMarginTop\n );\n }\n\n private getBoundaryInfo(): SkyViewkeeperBoundaryInfo {\n const spacerId = this.getSpacerId();\n\n const spacerEl = document.getElementById(spacerId);\n\n const boundaryEl = this.boundaryEl;\n\n const boundaryOffset = getOffset(boundaryEl, this.scrollableHost);\n const boundaryTop = boundaryOffset.top;\n const boundaryBottom =\n boundaryTop + boundaryEl.getBoundingClientRect().height;\n\n const scrollLeft = this.scrollableHost\n ? this.scrollableHost.scrollLeft\n : document.documentElement.scrollLeft;\n const scrollTop = this.scrollableHost\n ? this.scrollableHost.scrollTop\n : document.documentElement.scrollTop;\n\n const elHeight = getHeightWithMargin(this.el);\n\n return {\n boundaryBottom,\n boundaryOffset,\n boundaryEl,\n elHeight,\n scrollLeft,\n scrollTop,\n spacerId,\n spacerEl,\n };\n }\n}\n"]}
@@ -1404,6 +1404,7 @@ class SkyLogService {
1404
1404
  warn(message, ...optionalParams) {
1405
1405
  /*istanbul ignore else */
1406
1406
  if (window.console) {
1407
+ // eslint-disable-next-line prefer-spread,prefer-rest-params
1407
1408
  window.console.warn.apply(window.console, arguments);
1408
1409
  }
1409
1410
  }
@@ -1761,6 +1762,7 @@ class SkyNumericService {
1761
1762
  this.storeShortenSymbol(output);
1762
1763
  const locale = options.locale || this.currentLocale;
1763
1764
  let digits;
1765
+ let isDecimal;
1764
1766
  // Checks the string entered for format. Using toLowerCase to ignore case.
1765
1767
  switch ((_a = options.format) === null || _a === void 0 ? void 0 : _a.toLowerCase()) {
1766
1768
  // In a case where a decimal value was not shortened and
@@ -1769,7 +1771,7 @@ class SkyNumericService {
1769
1771
  // Note: This will need to be reviewed if we support currencies with
1770
1772
  // three decimal digits.
1771
1773
  case 'currency':
1772
- const isDecimal = value % 1 !== 0;
1774
+ isDecimal = value % 1 !== 0;
1773
1775
  if (options.minDigits) {
1774
1776
  digits = `1.${options.minDigits}-${options.digits}`;
1775
1777
  }
@@ -1779,12 +1781,12 @@ class SkyNumericService {
1779
1781
  else {
1780
1782
  digits = `1.0-${options.digits}`;
1781
1783
  }
1784
+ output = SkyNumberFormatUtility.formatNumber(locale, parseFloat(output), SkyIntlNumberFormatStyle.Currency, digits, options.iso,
1782
1785
  // Angular 5+ needs a string for this parameter, but Angular 4 needs a boolean.
1783
1786
  // To support both versions we can supply 'symbol' which will evaluate truthy for Angular 4
1784
1787
  // and the appropriate string value for Angular 5+.
1785
1788
  // See: https://angular.io/api/common/CurrencyPipe#parameters
1786
- const symbolDisplay = 'symbol';
1787
- output = SkyNumberFormatUtility.formatNumber(locale, parseFloat(output), SkyIntlNumberFormatStyle.Currency, digits, options.iso, symbolDisplay, options.currencySign);
1789
+ 'symbol', options.currencySign);
1788
1790
  break;
1789
1791
  // The following is a catch-all to ensure that if
1790
1792
  // anything but currency (or a future option) are entered,
@@ -2776,25 +2778,22 @@ class SkyViewkeeper {
2776
2778
  }
2777
2779
  shouldFixEl(boundaryInfo, verticalOffset) {
2778
2780
  let anchorTop;
2779
- let doFixEl;
2780
2781
  if (boundaryInfo.spacerEl) {
2781
2782
  anchorTop = getOffset(boundaryInfo.spacerEl, this.scrollableHost).top;
2782
2783
  }
2783
2784
  else {
2784
2785
  anchorTop = getOffset(this.el, this.scrollableHost).top;
2785
2786
  }
2786
- doFixEl =
2787
- boundaryInfo.scrollTop + verticalOffset + this.viewportMarginTop >
2788
- anchorTop;
2787
+ const doFixEl = boundaryInfo.scrollTop + verticalOffset + this.viewportMarginTop >
2788
+ anchorTop;
2789
2789
  return doFixEl;
2790
2790
  }
2791
2791
  getFixedStyles(boundaryInfo, verticalOffset) {
2792
- let elFixedTop;
2793
2792
  // If the element needs to be fixed, this will calculate its position. The position
2794
2793
  // will be 0 (fully visible) unless the user is scrolling the boundary out of view.
2795
2794
  // In that case, the element should begin to scroll out of view with the
2796
2795
  // rest of the boundary by setting its top position to a negative value.
2797
- elFixedTop = Math.min(boundaryInfo.boundaryBottom -
2796
+ const elFixedTop = Math.min(boundaryInfo.boundaryBottom -
2798
2797
  boundaryInfo.elHeight -
2799
2798
  boundaryInfo.scrollTop, verticalOffset);
2800
2799
  const elFixedWidth = boundaryInfo.boundaryEl.getBoundingClientRect().width;