@skyux/core 5.9.5 → 5.10.0
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-testing.umd.js +30 -0
- package/bundles/skyux-core.umd.js +764 -739
- package/documentation.json +149 -146
- package/esm2015/lib/modules/adapter-service/adapter.service.js +10 -6
- package/esm2015/lib/modules/adapter-service/adapter.service.js.map +1 -1
- package/esm2015/lib/modules/affix/affix.service.js +6 -2
- package/esm2015/lib/modules/affix/affix.service.js.map +1 -1
- 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 +42 -29
- package/esm2015/lib/modules/resize-observer/resize-observer-media-query.service.js.map +1 -1
- package/esm2015/lib/modules/resize-observer/resize-observer.service.js +16 -10
- package/esm2015/lib/modules/resize-observer/resize-observer.service.js.map +1 -1
- package/esm2015/lib/modules/scrollable-host/scrollable-host.service.js +28 -25
- package/esm2015/lib/modules/scrollable-host/scrollable-host.service.js.map +1 -1
- package/esm2015/testing/core-testing.module.js +29 -0
- package/esm2015/testing/core-testing.module.js.map +1 -0
- package/esm2015/testing/mock-media-query.service.js +2 -0
- package/esm2015/testing/mock-media-query.service.js.map +1 -1
- package/esm2015/testing/mock-ui-config.service.js.map +1 -1
- package/esm2015/testing/public-api.js +1 -0
- package/esm2015/testing/public-api.js.map +1 -1
- package/fesm2015/skyux-core-testing.js +28 -2
- package/fesm2015/skyux-core-testing.js.map +1 -1
- package/fesm2015/skyux-core.js +103 -77
- package/fesm2015/skyux-core.js.map +1 -1
- package/lib/modules/adapter-service/adapter.service.d.ts +1 -1
- package/lib/modules/affix/affix.service.d.ts +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 +2 -5
- package/lib/modules/resize-observer/resize-observer.service.d.ts +1 -2
- package/lib/modules/scrollable-host/scrollable-host.service.d.ts +7 -4
- package/package.json +2 -2
- package/testing/core-testing.module.d.ts +6 -0
- package/testing/mock-ui-config.service.d.ts +2 -1
- package/testing/public-api.d.ts +1 -0
@@ -1,3 +1,5 @@
|
|
1
|
+
var _SkyCoreAdapterService_renderer;
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
1
3
|
import { Injectable, RendererFactory2, } from '@angular/core';
|
2
4
|
import { SkyMediaBreakpoints } from '../media-query/media-breakpoints';
|
3
5
|
import * as i0 from "@angular/core";
|
@@ -17,7 +19,8 @@ const SKY_TABBABLE_SELECTOR = [
|
|
17
19
|
export class SkyCoreAdapterService {
|
18
20
|
constructor(rendererFactory) {
|
19
21
|
this.rendererFactory = rendererFactory;
|
20
|
-
|
22
|
+
_SkyCoreAdapterService_renderer.set(this, void 0);
|
23
|
+
__classPrivateFieldSet(this, _SkyCoreAdapterService_renderer, this.rendererFactory.createRenderer(undefined, null), "f");
|
21
24
|
}
|
22
25
|
/**
|
23
26
|
* Set the responsive container CSS class for a given element.
|
@@ -28,10 +31,10 @@ export class SkyCoreAdapterService {
|
|
28
31
|
*/
|
29
32
|
setResponsiveContainerClass(elementRef, breakpoint) {
|
30
33
|
const nativeEl = elementRef.nativeElement;
|
31
|
-
this.
|
32
|
-
this.
|
33
|
-
this.
|
34
|
-
this.
|
34
|
+
__classPrivateFieldGet(this, _SkyCoreAdapterService_renderer, "f").removeClass(nativeEl, 'sky-responsive-container-xs');
|
35
|
+
__classPrivateFieldGet(this, _SkyCoreAdapterService_renderer, "f").removeClass(nativeEl, 'sky-responsive-container-sm');
|
36
|
+
__classPrivateFieldGet(this, _SkyCoreAdapterService_renderer, "f").removeClass(nativeEl, 'sky-responsive-container-md');
|
37
|
+
__classPrivateFieldGet(this, _SkyCoreAdapterService_renderer, "f").removeClass(nativeEl, 'sky-responsive-container-lg');
|
35
38
|
let newClass;
|
36
39
|
switch (breakpoint) {
|
37
40
|
case SkyMediaBreakpoints.xs: {
|
@@ -51,7 +54,7 @@ export class SkyCoreAdapterService {
|
|
51
54
|
break;
|
52
55
|
}
|
53
56
|
}
|
54
|
-
this.
|
57
|
+
__classPrivateFieldGet(this, _SkyCoreAdapterService_renderer, "f").addClass(nativeEl, newClass);
|
55
58
|
}
|
56
59
|
/**
|
57
60
|
* This method temporarily enables/disables pointer events.
|
@@ -215,6 +218,7 @@ export class SkyCoreAdapterService {
|
|
215
218
|
return hasBounds;
|
216
219
|
}
|
217
220
|
}
|
221
|
+
_SkyCoreAdapterService_renderer = new WeakMap();
|
218
222
|
SkyCoreAdapterService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyCoreAdapterService, deps: [{ token: i0.RendererFactory2 }], target: i0.ɵɵFactoryTarget.Injectable });
|
219
223
|
SkyCoreAdapterService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyCoreAdapterService, providedIn: 'root' });
|
220
224
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyCoreAdapterService, decorators: [{
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"adapter.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/adapter-service/adapter.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAEV,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;;AAIvE,MAAM,qBAAqB,GAAG;IAC5B,SAAS;IACT,YAAY;IACZ,uBAAuB;IACvB,wBAAwB;IACxB,wBAAwB;IACxB,0BAA0B;IAC1B,QAAQ;IACR,QAAQ;IACR,OAAO;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YAChB,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,SAAS,CAAC,OAAoB;QACpC,MAAM,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAC/C,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,KAAK,MAAM,IAAI,KAAK,CAAC,UAAU,KAAK,QAAQ,CAAC;QAC3E,IAAI,QAAQ,EAAE;YACZ,OAAO,KAAK,CAAC;SACd;QAED,MAAM,SAAS,GAAG,CAAC,CAAC,CAClB,OAAO,CAAC,WAAW;YACnB,OAAO,CAAC,YAAY;YACpB,OAAO,CAAC,cAAc,EAAE,CAAC,MAAM,CAChC,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;;mHA7PU,qBAAqB;uHAArB,qBAAqB,cAFpB,MAAM;4FAEP,qBAAqB;kBAHjC,UAAU;mBAAC;oBACV,UAAU,EAAE,MAAM;iBACnB","sourcesContent":["import {\n ElementRef,\n Injectable,\n Renderer2,\n RendererFactory2,\n} from '@angular/core';\n\nimport { SkyMediaBreakpoints } from '../media-query/media-breakpoints';\n\nimport { SkyFocusableChildrenOptions } from './focusable-children-options';\n\nconst SKY_TABBABLE_SELECTOR = [\n 'a[href]',\n 'area[href]',\n 'input:not([disabled])',\n 'button:not([disabled])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n 'iframe',\n 'object',\n 'embed',\n '*[contenteditable=true]:not([disabled])',\n '*[tabindex]:not([disabled])',\n].join(', ');\n\n@Injectable({\n providedIn: 'root',\n})\nexport class SkyCoreAdapterService {\n private renderer: Renderer2;\n\n constructor(private rendererFactory: RendererFactory2) {\n this.renderer = this.rendererFactory.createRenderer(undefined, undefined);\n }\n\n /**\n * Set the responsive container CSS class for a given element.\n *\n * @param elementRef - The element that will recieve the new CSS class.\n * @param breakpoint - The SkyMediaBreakpoint will determine which class\n * gets set. For example a SkyMediaBreakpoint of `xs` will set a CSS class of `sky-responsive-container-xs`.\n */\n public setResponsiveContainerClass(\n elementRef: ElementRef,\n breakpoint: SkyMediaBreakpoints\n ): void {\n const nativeEl: HTMLElement = elementRef.nativeElement;\n\n this.renderer.removeClass(nativeEl, 'sky-responsive-container-xs');\n this.renderer.removeClass(nativeEl, 'sky-responsive-container-sm');\n this.renderer.removeClass(nativeEl, 'sky-responsive-container-md');\n this.renderer.removeClass(nativeEl, 'sky-responsive-container-lg');\n\n let newClass: string;\n\n switch (breakpoint) {\n case SkyMediaBreakpoints.xs: {\n newClass = 'sky-responsive-container-xs';\n break;\n }\n case SkyMediaBreakpoints.sm: {\n newClass = 'sky-responsive-container-sm';\n break;\n }\n case SkyMediaBreakpoints.md: {\n newClass = 'sky-responsive-container-md';\n break;\n }\n default: {\n newClass = 'sky-responsive-container-lg';\n break;\n }\n }\n\n this.renderer.addClass(nativeEl, newClass);\n }\n\n /**\n * This method temporarily enables/disables pointer events.\n * This is helpful to prevent iFrames from interfering with drag events.\n *\n * @param enable - Set to `true` to enable pointer events. Set to `false` to disable.\n */\n public toggleIframePointerEvents(enable: boolean): void {\n const iframes = document.querySelectorAll('iframe');\n for (let i = 0; i < iframes.length; i++) {\n // Setting to empty string will allow iframe to fall back to its prior CSS assignment.\n iframes[i].style.pointerEvents = enable ? '' : 'none';\n }\n }\n\n /**\n * Focuses on the first element found with an `autofocus` attribute inside the supplied `elementRef`.\n *\n * @param elementRef - The element to search within.\n * @return Returns `true` if a child element with autofocus is found.\n */\n public applyAutoFocus(elementRef: ElementRef): boolean {\n if (!elementRef) {\n return false;\n }\n\n const elementWithAutoFocus =\n elementRef.nativeElement.querySelector('[autofocus]');\n\n // Child was found with the autofocus property. Set focus and return true.\n if (elementWithAutoFocus) {\n elementWithAutoFocus.focus();\n return true;\n }\n\n // No children were found with autofocus property. Return false.\n return false;\n }\n\n /**\n * Sets focus on the first focusable child of the `elementRef` parameter.\n * If no focusable children are found, and `focusOnContainerIfNoChildrenFound` is `true`,\n * focus will be set on the container element.\n *\n * @param elementRef - The element to search within.\n * @param containerSelector - A CSS selector indicating the container that should\n * recieve focus if no focusable children are found.\n * @param focusOnContainerIfNoChildrenFound - It set to `true`, the container will\n * recieve focus if no focusable children are found.\n */\n public getFocusableChildrenAndApplyFocus(\n elementRef: ElementRef,\n containerSelector: string,\n focusOnContainerIfNoChildrenFound: boolean = false\n ): void {\n const containerElement =\n elementRef.nativeElement.querySelector(containerSelector);\n\n if (containerElement) {\n const focusableChildren = this.getFocusableChildren(containerElement);\n\n // Focus first focusable child if available. Otherwise, set focus on container.\n if (\n !this.focusFirstElement(focusableChildren) &&\n focusOnContainerIfNoChildrenFound\n ) {\n containerElement.focus();\n }\n }\n }\n\n /**\n * Returns an array of all focusable children of provided `element`.\n *\n * @param element - The HTMLElement to search within.\n * @param options - Options for getting focusable children.\n */\n public getFocusableChildren(\n element: HTMLElement,\n options?: SkyFocusableChildrenOptions\n ): HTMLElement[] {\n if (!element) {\n return [];\n }\n\n let elements = Array.prototype.slice.call(\n element.querySelectorAll(SKY_TABBABLE_SELECTOR)\n );\n\n // Unless ignoreTabIndex = true, filter out elements with tabindex = -1.\n if (!options || !options.ignoreTabIndex) {\n elements = elements.filter((el: HTMLElement) => {\n return el.tabIndex !== -1;\n });\n }\n\n // Unless ignoreVisibility = true, filter out elements that are not visible.\n if (!options || !options.ignoreVisibility) {\n elements = elements.filter((el: HTMLElement) => {\n return this.isVisible(el);\n });\n }\n\n return elements;\n }\n\n /**\n * Returns the clientWidth of the provided elementRef.\n * @param elementRef - The element to calculate width from.\n */\n public getWidth(elementRef: ElementRef): number {\n return elementRef.nativeElement.clientWidth;\n }\n\n /**\n * Checks if an event target has a higher z-index than a given element.\n * @param target The event target element.\n * @param element The element to test against. A z-index must be explicitly set for this element.\n */\n public isTargetAboveElement(\n target: EventTarget,\n element: HTMLElement\n ): boolean {\n const zIndex: string = getComputedStyle(element).zIndex;\n\n let el: HTMLElement = target as HTMLElement;\n\n while (el) {\n // Getting the computed style only works for elements that exist in the DOM.\n // In certain scenarios, an element is removed after a click event; by the time the event\n // bubbles up to other elements, however, the element has been removed and the computed style returns empty.\n // In this case, we'll need to check the z-index directly, via the style property.\n const targetZIndex: string =\n getComputedStyle(el).zIndex || el.style.zIndex;\n if (\n targetZIndex !== '' &&\n targetZIndex !== 'auto' &&\n +targetZIndex > +zIndex\n ) {\n return true;\n }\n\n el = el.parentElement as HTMLElement;\n }\n\n return false;\n }\n\n /**\n * Remove inline height styles from the provided elements.\n * @param elementRef - The element to search within.\n * @param selector - The CSS selector to use when finding elements for removing height.\n */\n public resetHeight(elementRef: ElementRef, selector: string): void {\n const children = elementRef.nativeElement.querySelectorAll(selector);\n /* istanbul ignore else */\n if (children.length > 0) {\n for (let i = 0; i < children.length; i++) {\n // Setting style attributes with Web API requires null instead of undefined.\n // tslint:disable-next-line: no-null-keyword\n children[i].style.height = null;\n }\n }\n }\n\n /**\n * Sets all element heights to match the height of the tallest element.\n * @param elementRef - The element to search within.\n * @param selector - The CSS selector to use when finding elements for syncing height.\n */\n public syncMaxHeight(elementRef: ElementRef, selector: string): void {\n const children = elementRef.nativeElement.querySelectorAll(selector);\n /* istanbul ignore else */\n if (children.length > 0) {\n let maxHeight = 0;\n for (let i = 0; i < children.length; i++) {\n maxHeight = Math.max(maxHeight, children[i].offsetHeight);\n }\n for (let i = 0; i < children.length; i++) {\n children[i].style.height = maxHeight + 'px';\n }\n }\n }\n\n private focusFirstElement(list: Array<HTMLElement>): boolean {\n if (list.length > 0) {\n list[0].focus();\n return true;\n }\n return false;\n }\n\n private isVisible(element: HTMLElement): boolean {\n const style = window.getComputedStyle(element);\n const isHidden = style.display === 'none' || style.visibility === 'hidden';\n if (isHidden) {\n return false;\n }\n\n const hasBounds = !!(\n element.offsetWidth ||\n element.offsetHeight ||\n element.getClientRects().length\n );\n return hasBounds;\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"adapter.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/adapter-service/adapter.service.ts"],"names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AE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACxC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;aAC7C;SACF;IACH,CAAC;IAEO,iBAAiB,CAAC,IAAwB;QAChD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACnB,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,SAAS,CAAC,OAAoB;QACpC,MAAM,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAC/C,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,KAAK,MAAM,IAAI,KAAK,CAAC,UAAU,KAAK,QAAQ,CAAC;QAC3E,IAAI,QAAQ,EAAE;YACZ,OAAO,KAAK,CAAC;SACd;QAED,MAAM,SAAS,GAAG,CAAC,CAAC,CAClB,OAAO,CAAC,WAAW;YACnB,OAAO,CAAC,YAAY;YACpB,OAAO,CAAC,cAAc,EAAE,CAAC,MAAM,CAChC,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;;;mHA5PU,qBAAqB;uHAArB,qBAAqB,cAFpB,MAAM;4FAEP,qBAAqB;kBAHjC,UAAU;mBAAC;oBACV,UAAU,EAAE,MAAM;iBACnB","sourcesContent":["import {\n ElementRef,\n Injectable,\n Renderer2,\n RendererFactory2,\n} from '@angular/core';\n\nimport { SkyMediaBreakpoints } from '../media-query/media-breakpoints';\n\nimport { SkyFocusableChildrenOptions } from './focusable-children-options';\n\nconst SKY_TABBABLE_SELECTOR = [\n 'a[href]',\n 'area[href]',\n 'input:not([disabled])',\n 'button:not([disabled])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n 'iframe',\n 'object',\n 'embed',\n '*[contenteditable=true]:not([disabled])',\n '*[tabindex]:not([disabled])',\n].join(', ');\n\n@Injectable({\n providedIn: 'root',\n})\nexport class SkyCoreAdapterService {\n #renderer: Renderer2;\n\n constructor(private rendererFactory: RendererFactory2) {\n this.#renderer = this.rendererFactory.createRenderer(undefined, null);\n }\n\n /**\n * Set the responsive container CSS class for a given element.\n *\n * @param elementRef - The element that will recieve the new CSS class.\n * @param breakpoint - The SkyMediaBreakpoint will determine which class\n * gets set. For example a SkyMediaBreakpoint of `xs` will set a CSS class of `sky-responsive-container-xs`.\n */\n public setResponsiveContainerClass(\n elementRef: ElementRef,\n breakpoint: SkyMediaBreakpoints\n ): void {\n const nativeEl = elementRef.nativeElement;\n\n this.#renderer.removeClass(nativeEl, 'sky-responsive-container-xs');\n this.#renderer.removeClass(nativeEl, 'sky-responsive-container-sm');\n this.#renderer.removeClass(nativeEl, 'sky-responsive-container-md');\n this.#renderer.removeClass(nativeEl, 'sky-responsive-container-lg');\n\n let newClass: string;\n\n switch (breakpoint) {\n case SkyMediaBreakpoints.xs: {\n newClass = 'sky-responsive-container-xs';\n break;\n }\n case SkyMediaBreakpoints.sm: {\n newClass = 'sky-responsive-container-sm';\n break;\n }\n case SkyMediaBreakpoints.md: {\n newClass = 'sky-responsive-container-md';\n break;\n }\n default: {\n newClass = 'sky-responsive-container-lg';\n break;\n }\n }\n\n this.#renderer.addClass(nativeEl, newClass);\n }\n\n /**\n * This method temporarily enables/disables pointer events.\n * This is helpful to prevent iFrames from interfering with drag events.\n *\n * @param enable - Set to `true` to enable pointer events. Set to `false` to disable.\n */\n public toggleIframePointerEvents(enable: boolean): void {\n const iframes = document.querySelectorAll('iframe');\n for (let i = 0; i < iframes.length; i++) {\n // Setting to empty string will allow iframe to fall back to its prior CSS assignment.\n iframes[i].style.pointerEvents = enable ? '' : 'none';\n }\n }\n\n /**\n * Focuses on the first element found with an `autofocus` attribute inside the supplied `elementRef`.\n *\n * @param elementRef - The element to search within.\n * @return Returns `true` if a child element with autofocus is found.\n */\n public applyAutoFocus(elementRef: ElementRef): boolean {\n if (!elementRef) {\n return false;\n }\n\n const elementWithAutoFocus =\n elementRef.nativeElement.querySelector('[autofocus]');\n\n // Child was found with the autofocus property. Set focus and return true.\n if (elementWithAutoFocus) {\n elementWithAutoFocus.focus();\n return true;\n }\n\n // No children were found with autofocus property. Return false.\n return false;\n }\n\n /**\n * Sets focus on the first focusable child of the `elementRef` parameter.\n * If no focusable children are found, and `focusOnContainerIfNoChildrenFound` is `true`,\n * focus will be set on the container element.\n *\n * @param elementRef - The element to search within.\n * @param containerSelector - A CSS selector indicating the container that should\n * recieve focus if no focusable children are found.\n * @param focusOnContainerIfNoChildrenFound - It set to `true`, the container will\n * recieve focus if no focusable children are found.\n */\n public getFocusableChildrenAndApplyFocus(\n elementRef: ElementRef,\n containerSelector: string,\n focusOnContainerIfNoChildrenFound: boolean = false\n ): void {\n const containerElement =\n elementRef.nativeElement.querySelector(containerSelector);\n\n if (containerElement) {\n const focusableChildren = this.getFocusableChildren(containerElement);\n\n // Focus first focusable child if available. Otherwise, set focus on container.\n if (\n !this.focusFirstElement(focusableChildren) &&\n focusOnContainerIfNoChildrenFound\n ) {\n containerElement.focus();\n }\n }\n }\n\n /**\n * Returns an array of all focusable children of provided `element`.\n *\n * @param element - The HTMLElement to search within.\n * @param options - Options for getting focusable children.\n */\n public getFocusableChildren(\n element: HTMLElement,\n options?: SkyFocusableChildrenOptions\n ): HTMLElement[] {\n if (!element) {\n return [];\n }\n\n let elements = Array.prototype.slice.call(\n element.querySelectorAll(SKY_TABBABLE_SELECTOR)\n );\n\n // Unless ignoreTabIndex = true, filter out elements with tabindex = -1.\n if (!options || !options.ignoreTabIndex) {\n elements = elements.filter((el: HTMLElement) => {\n return el.tabIndex !== -1;\n });\n }\n\n // Unless ignoreVisibility = true, filter out elements that are not visible.\n if (!options || !options.ignoreVisibility) {\n elements = elements.filter((el: HTMLElement) => {\n return this.isVisible(el);\n });\n }\n\n return elements;\n }\n\n /**\n * Returns the clientWidth of the provided elementRef.\n * @param elementRef - The element to calculate width from.\n */\n public getWidth(elementRef: ElementRef): number {\n return elementRef.nativeElement.clientWidth;\n }\n\n /**\n * Checks if an event target has a higher z-index than a given element.\n * @param target The event target element.\n * @param element The element to test against. A z-index must be explicitly set for this element.\n */\n public isTargetAboveElement(\n target: EventTarget,\n element: HTMLElement\n ): boolean {\n const zIndex = getComputedStyle(element).zIndex;\n\n let el = target as HTMLElement;\n\n while (el) {\n // Getting the computed style only works for elements that exist in the DOM.\n // In certain scenarios, an element is removed after a click event; by the time the event\n // bubbles up to other elements, however, the element has been removed and the computed style returns empty.\n // In this case, we'll need to check the z-index directly, via the style property.\n const targetZIndex = getComputedStyle(el).zIndex || el.style.zIndex;\n if (\n targetZIndex !== '' &&\n targetZIndex !== 'auto' &&\n +targetZIndex > +zIndex\n ) {\n return true;\n }\n\n el = el.parentElement as HTMLElement;\n }\n\n return false;\n }\n\n /**\n * Remove inline height styles from the provided elements.\n * @param elementRef - The element to search within.\n * @param selector - The CSS selector to use when finding elements for removing height.\n */\n public resetHeight(elementRef: ElementRef, selector: string): void {\n const children = elementRef.nativeElement.querySelectorAll(selector);\n /* istanbul ignore else */\n if (children.length > 0) {\n for (let i = 0; i < children.length; i++) {\n // Setting style attributes with Web API requires null instead of undefined.\n // tslint:disable-next-line: no-null-keyword\n children[i].style.height = null;\n }\n }\n }\n\n /**\n * Sets all element heights to match the height of the tallest element.\n * @param elementRef - The element to search within.\n * @param selector - The CSS selector to use when finding elements for syncing height.\n */\n public syncMaxHeight(elementRef: ElementRef, selector: string): void {\n const children = elementRef.nativeElement.querySelectorAll(selector);\n /* istanbul ignore else */\n if (children.length > 0) {\n let maxHeight = 0;\n for (let i = 0; i < children.length; i++) {\n maxHeight = Math.max(maxHeight, children[i].offsetHeight);\n }\n for (let i = 0; i < children.length; i++) {\n children[i].style.height = maxHeight + 'px';\n }\n }\n }\n\n private focusFirstElement(list: Array<HTMLElement>): boolean {\n if (list.length > 0) {\n list[0].focus();\n return true;\n }\n return false;\n }\n\n private isVisible(element: HTMLElement): boolean {\n const style = window.getComputedStyle(element);\n const isHidden = style.display === 'none' || style.visibility === 'hidden';\n if (isHidden) {\n return false;\n }\n\n const hasBounds = !!(\n element.offsetWidth ||\n element.offsetHeight ||\n element.getClientRects().length\n );\n return hasBounds;\n }\n}\n"]}
|
@@ -1,18 +1,22 @@
|
|
1
|
+
var _SkyAffixService_renderer;
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
1
3
|
import { Injectable, RendererFactory2, } from '@angular/core';
|
2
4
|
import { SkyAffixer } from './affixer';
|
3
5
|
import * as i0 from "@angular/core";
|
4
6
|
export class SkyAffixService {
|
5
7
|
constructor(rendererFactory) {
|
6
|
-
|
8
|
+
_SkyAffixService_renderer.set(this, void 0);
|
9
|
+
__classPrivateFieldSet(this, _SkyAffixService_renderer, rendererFactory.createRenderer(undefined, null), "f");
|
7
10
|
}
|
8
11
|
/**
|
9
12
|
* Creates an instance of [[SkyAffixer]].
|
10
13
|
* @param affixed The element to be affixed.
|
11
14
|
*/
|
12
15
|
createAffixer(affixed) {
|
13
|
-
return new SkyAffixer(affixed.nativeElement, this
|
16
|
+
return new SkyAffixer(affixed.nativeElement, __classPrivateFieldGet(this, _SkyAffixService_renderer, "f"));
|
14
17
|
}
|
15
18
|
}
|
19
|
+
_SkyAffixService_renderer = new WeakMap();
|
16
20
|
SkyAffixService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyAffixService, deps: [{ token: i0.RendererFactory2 }], target: i0.ɵɵFactoryTarget.Injectable });
|
17
21
|
SkyAffixService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyAffixService, providedIn: 'root' });
|
18
22
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyAffixService, decorators: [{
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"affix.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/affix/affix.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAEV,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;;AAKvC,MAAM,OAAO,eAAe;IAG1B,YAAY,eAAiC;
|
1
|
+
{"version":3,"file":"affix.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/affix/affix.service.ts"],"names":[],"mappings":";;AAAA,OAAO,EAEL,UAAU,EAEV,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;;AAKvC,MAAM,OAAO,eAAe;IAG1B,YAAY,eAAiC;QAF7C,4CAAqB;QAGnB,uBAAA,IAAI,6BAAa,eAAe,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,MAAA,CAAC;IACnE,CAAC;IAED;;;OAGG;IACI,aAAa,CAAC,OAAmB;QACtC,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,aAAa,EAAE,uBAAA,IAAI,iCAAU,CAAC,CAAC;IAC/D,CAAC;;;6GAbU,eAAe;iHAAf,eAAe,cAFd,MAAM;4FAEP,eAAe;kBAH3B,UAAU;mBAAC;oBACV,UAAU,EAAE,MAAM;iBACnB","sourcesContent":["import {\n ElementRef,\n Injectable,\n Renderer2,\n RendererFactory2,\n} from '@angular/core';\n\nimport { SkyAffixer } from './affixer';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class SkyAffixService {\n #renderer: Renderer2;\n\n constructor(rendererFactory: RendererFactory2) {\n this.#renderer = rendererFactory.createRenderer(undefined, null);\n }\n\n /**\n * Creates an instance of [[SkyAffixer]].\n * @param affixed The element to be affixed.\n */\n public createAffixer(affixed: ElementRef): SkyAffixer {\n return new SkyAffixer(affixed.nativeElement, this.#renderer);\n }\n}\n"]}
|
@@ -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;A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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":["../../../../../../../../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,EA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,CAAC,EAAE,CAAC;IACnD,CAAC;IAED;;;;;;OAMG;IACK,oBAAoB,CAAC,KAAa;QACxC,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3C,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;QACzC,MAAM,MAAM,GACV,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAEpE,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,SAAS,CAAC,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 * 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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C,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;QACnD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACnD,CAAC;IAED;;;;;;OAMG;IACK,oBAAoB,CAAC,KAAa;QACxC,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3C,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;QACzC,MAAM,MAAM,GACV,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAEpE,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,SAAS,CAAC,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"]}
|
@@ -1,3 +1,5 @@
|
|
1
|
+
var _SkyResizeObserverMediaQueryService_breakpoints, _SkyResizeObserverMediaQueryService_currentBreakpointObservable, _SkyResizeObserverMediaQueryService_stopListening, _SkyResizeObserverMediaQueryService_target;
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
1
3
|
import { Injectable } from '@angular/core';
|
2
4
|
import { ReplaySubject, Subject } from 'rxjs';
|
3
5
|
import { takeUntil } from 'rxjs/operators';
|
@@ -11,9 +13,9 @@ import * as i1 from "./resize-observer.service";
|
|
11
13
|
export class SkyResizeObserverMediaQueryService {
|
12
14
|
constructor(resizeObserverService) {
|
13
15
|
this.resizeObserverService = resizeObserverService;
|
14
|
-
this
|
16
|
+
_SkyResizeObserverMediaQueryService_breakpoints.set(this, [
|
15
17
|
{
|
16
|
-
check: (width) => width <= 767,
|
18
|
+
check: (width) => width > 0 && width <= 767,
|
17
19
|
name: SkyMediaBreakpoints.xs,
|
18
20
|
},
|
19
21
|
{
|
@@ -28,11 +30,12 @@ export class SkyResizeObserverMediaQueryService {
|
|
28
30
|
check: (width) => width > 1199,
|
29
31
|
name: SkyMediaBreakpoints.lg,
|
30
32
|
},
|
31
|
-
];
|
32
|
-
this
|
33
|
-
this
|
34
|
-
|
35
|
-
|
33
|
+
]);
|
34
|
+
_SkyResizeObserverMediaQueryService_currentBreakpointObservable.set(this, new ReplaySubject(1));
|
35
|
+
_SkyResizeObserverMediaQueryService_stopListening.set(this, new Subject());
|
36
|
+
_SkyResizeObserverMediaQueryService_target.set(this, void 0);
|
37
|
+
__classPrivateFieldGet(this, _SkyResizeObserverMediaQueryService_stopListening, "f").subscribe(() => {
|
38
|
+
__classPrivateFieldSet(this, _SkyResizeObserverMediaQueryService_target, undefined, "f");
|
36
39
|
this.updateBreakpoint(undefined);
|
37
40
|
});
|
38
41
|
}
|
@@ -43,10 +46,10 @@ export class SkyResizeObserverMediaQueryService {
|
|
43
46
|
return this._currentBreakpoint;
|
44
47
|
}
|
45
48
|
ngOnDestroy() {
|
46
|
-
this.
|
49
|
+
__classPrivateFieldGet(this, _SkyResizeObserverMediaQueryService_stopListening, "f").next();
|
47
50
|
this._currentBreakpoint = undefined;
|
48
|
-
this.
|
49
|
-
this.
|
51
|
+
__classPrivateFieldGet(this, _SkyResizeObserverMediaQueryService_stopListening, "f").complete();
|
52
|
+
__classPrivateFieldGet(this, _SkyResizeObserverMediaQueryService_currentBreakpointObservable, "f").complete();
|
50
53
|
}
|
51
54
|
/**
|
52
55
|
* @internal
|
@@ -59,25 +62,21 @@ export class SkyResizeObserverMediaQueryService {
|
|
59
62
|
* time. Any previous subscriptions will be unsubscribed when a new element is observed.
|
60
63
|
*/
|
61
64
|
observe(element) {
|
62
|
-
if (this
|
63
|
-
if (this
|
65
|
+
if (__classPrivateFieldGet(this, _SkyResizeObserverMediaQueryService_target, "f")) {
|
66
|
+
if (__classPrivateFieldGet(this, _SkyResizeObserverMediaQueryService_target, "f") === element) {
|
64
67
|
return this;
|
65
68
|
}
|
66
|
-
this.
|
69
|
+
__classPrivateFieldGet(this, _SkyResizeObserverMediaQueryService_stopListening, "f").next();
|
67
70
|
}
|
68
|
-
this
|
69
|
-
|
70
|
-
|
71
|
-
const breakpoint = this.checkBreakpoint(width);
|
72
|
-
this.updateBreakpoint(breakpoint);
|
73
|
-
}
|
74
|
-
this._resizeSubscription = this.resizeObserverService
|
71
|
+
__classPrivateFieldSet(this, _SkyResizeObserverMediaQueryService_target, element, "f");
|
72
|
+
this.checkWidth(element);
|
73
|
+
this.resizeObserverService
|
75
74
|
.observe(element)
|
76
|
-
.pipe(takeUntil(this
|
75
|
+
.pipe(takeUntil(__classPrivateFieldGet(this, _SkyResizeObserverMediaQueryService_stopListening, "f")))
|
77
76
|
.subscribe((value) => {
|
78
77
|
const breakpoint = this.checkBreakpoint(value.contentRect.width);
|
79
78
|
/* istanbul ignore else */
|
80
|
-
if (breakpoint !== this.
|
79
|
+
if (breakpoint !== this.current) {
|
81
80
|
this.updateBreakpoint(breakpoint);
|
82
81
|
}
|
83
82
|
});
|
@@ -87,25 +86,39 @@ export class SkyResizeObserverMediaQueryService {
|
|
87
86
|
* Stop watching the container element.
|
88
87
|
*/
|
89
88
|
unobserve() {
|
90
|
-
this.
|
89
|
+
__classPrivateFieldGet(this, _SkyResizeObserverMediaQueryService_stopListening, "f").next();
|
91
90
|
}
|
92
91
|
/**
|
93
92
|
* Subscribes to element size changes that cross breakpoints.
|
94
93
|
*/
|
95
94
|
subscribe(listener) {
|
96
|
-
return this
|
97
|
-
.pipe(takeUntil(this
|
98
|
-
.subscribe(
|
95
|
+
return __classPrivateFieldGet(this, _SkyResizeObserverMediaQueryService_currentBreakpointObservable, "f")
|
96
|
+
.pipe(takeUntil(__classPrivateFieldGet(this, _SkyResizeObserverMediaQueryService_stopListening, "f")))
|
97
|
+
.subscribe((value) => {
|
98
|
+
listener(value);
|
99
|
+
});
|
99
100
|
}
|
100
101
|
updateBreakpoint(breakpoint) {
|
101
102
|
this._currentBreakpoint = breakpoint;
|
102
|
-
this.
|
103
|
+
__classPrivateFieldGet(this, _SkyResizeObserverMediaQueryService_currentBreakpointObservable, "f").next(breakpoint);
|
103
104
|
}
|
104
105
|
checkBreakpoint(width) {
|
105
|
-
|
106
|
-
|
106
|
+
const breakpoint = __classPrivateFieldGet(this, _SkyResizeObserverMediaQueryService_breakpoints, "f").find((breakpoint) => breakpoint.check(width));
|
107
|
+
/* istanbul ignore else */
|
108
|
+
if (breakpoint) {
|
109
|
+
return breakpoint.name;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
checkWidth(element) {
|
113
|
+
const width = element.nativeElement.offsetWidth || 0;
|
114
|
+
const breakpoint = this.checkBreakpoint(width);
|
115
|
+
/* istanbul ignore else */
|
116
|
+
if (breakpoint !== this._currentBreakpoint) {
|
117
|
+
this.updateBreakpoint(breakpoint);
|
118
|
+
}
|
107
119
|
}
|
108
120
|
}
|
121
|
+
_SkyResizeObserverMediaQueryService_breakpoints = new WeakMap(), _SkyResizeObserverMediaQueryService_currentBreakpointObservable = new WeakMap(), _SkyResizeObserverMediaQueryService_stopListening = new WeakMap(), _SkyResizeObserverMediaQueryService_target = new WeakMap();
|
109
122
|
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
123
|
SkyResizeObserverMediaQueryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyResizeObserverMediaQueryService, providedIn: 'any' });
|
111
124
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyResizeObserverMediaQueryService, decorators: [{
|
@@ -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,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;IAwC7C,YAAoB,qBAA+C;QAA/C,0BAAqB,GAArB,qBAAqB,CAA0B;QAhCnE,0DAGM;YACJ;gBACE,KAAK,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,MAAM,UAAU,GAAG,uBAAA,IAAI,uDAAa,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CACvD,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CACxB,CAAC;QAEF,0BAA0B;QAC1B,IAAI,UAAU,EAAE;YACd,OAAO,UAAU,CAAC,IAAI,CAAC;SACxB;IACH,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;;;gIApIU,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 #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\n #currentBreakpointObservable = new ReplaySubject<\n SkyMediaBreakpoints | undefined\n >(1);\n\n private _currentBreakpoint: SkyMediaBreakpoints;\n\n #stopListening = new Subject<void>();\n\n #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\n this.#stopListening.next();\n }\n\n this.#target = element;\n\n this.checkWidth(element);\n\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.current) {\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 const breakpoint = this.#breakpoints.find((breakpoint) =>\n breakpoint.check(width)\n );\n\n /* istanbul ignore else */\n if (breakpoint) {\n return breakpoint.name;\n }\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"]}
|
@@ -1,3 +1,5 @@
|
|
1
|
+
var _SkyResizeObserverService_resizeObserver, _SkyResizeObserverService_tracking;
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
1
3
|
import { Injectable, NgZone } from '@angular/core';
|
2
4
|
import { Subject } from 'rxjs';
|
3
5
|
import { finalize } from 'rxjs/operators';
|
@@ -8,13 +10,14 @@ import * as i0 from "@angular/core";
|
|
8
10
|
export class SkyResizeObserverService {
|
9
11
|
constructor(zone) {
|
10
12
|
this.zone = zone;
|
11
|
-
this
|
12
|
-
this
|
13
|
+
_SkyResizeObserverService_resizeObserver.set(this, void 0);
|
14
|
+
_SkyResizeObserverService_tracking.set(this, []);
|
15
|
+
__classPrivateFieldSet(this, _SkyResizeObserverService_resizeObserver, new ResizeObserver((entries) => {
|
13
16
|
entries.forEach((entry) => this.callback(entry));
|
14
|
-
});
|
17
|
+
}), "f");
|
15
18
|
}
|
16
19
|
ngOnDestroy() {
|
17
|
-
this.
|
20
|
+
__classPrivateFieldGet(this, _SkyResizeObserverService_resizeObserver, "f").disconnect();
|
18
21
|
}
|
19
22
|
/**
|
20
23
|
* Create rxjs observable to get size changes for an element ref.
|
@@ -23,22 +26,22 @@ export class SkyResizeObserverService {
|
|
23
26
|
return this.observeAndTrack(element).subjectObservable;
|
24
27
|
}
|
25
28
|
observeAndTrack(element) {
|
26
|
-
const checkTracking = this.
|
29
|
+
const checkTracking = __classPrivateFieldGet(this, _SkyResizeObserverService_tracking, "f").findIndex((value) => {
|
27
30
|
return !value.subject.closed && value.element === element.nativeElement;
|
28
31
|
});
|
29
32
|
if (checkTracking === -1) {
|
30
|
-
this.
|
33
|
+
__classPrivateFieldGet(this, _SkyResizeObserverService_resizeObserver, "f").observe(element.nativeElement);
|
31
34
|
}
|
32
35
|
const subject = new Subject();
|
33
36
|
const subjectObservable = subject.pipe(finalize(() => {
|
34
37
|
// Are there any other tracking entries still watching this element?
|
35
|
-
const checkTracking = this.
|
38
|
+
const checkTracking = __classPrivateFieldGet(this, _SkyResizeObserverService_tracking, "f").findIndex((value) => {
|
36
39
|
return (value.subject !== subject &&
|
37
40
|
!value.subject.closed &&
|
38
41
|
value.element === element.nativeElement);
|
39
42
|
});
|
40
43
|
if (checkTracking === -1) {
|
41
|
-
this.
|
44
|
+
__classPrivateFieldGet(this, _SkyResizeObserverService_resizeObserver, "f").unobserve(element.nativeElement);
|
42
45
|
}
|
43
46
|
}));
|
44
47
|
const tracking = {
|
@@ -46,15 +49,17 @@ export class SkyResizeObserverService {
|
|
46
49
|
subject,
|
47
50
|
subjectObservable,
|
48
51
|
};
|
49
|
-
this.
|
52
|
+
__classPrivateFieldGet(this, _SkyResizeObserverService_tracking, "f").push(tracking);
|
50
53
|
return tracking;
|
51
54
|
}
|
52
55
|
callback(entry) {
|
53
|
-
this
|
56
|
+
__classPrivateFieldGet(this, _SkyResizeObserverService_tracking, "f")
|
54
57
|
.filter((value) => !(value.subject.closed || value.subject.isStopped))
|
55
58
|
.forEach((value) => {
|
56
59
|
/* istanbul ignore else */
|
57
60
|
if (value.element === entry.target) {
|
61
|
+
// Execute the callback within NgZone because Angular does not "monkey patch"
|
62
|
+
// ResizeObserver like it does for other features in the DOM.
|
58
63
|
this.zone.run(() => {
|
59
64
|
value.subject.next(entry);
|
60
65
|
});
|
@@ -62,6 +67,7 @@ export class SkyResizeObserverService {
|
|
62
67
|
});
|
63
68
|
}
|
64
69
|
}
|
70
|
+
_SkyResizeObserverService_resizeObserver = new WeakMap(), _SkyResizeObserverService_tracking = new WeakMap();
|
65
71
|
SkyResizeObserverService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyResizeObserverService, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
|
66
72
|
SkyResizeObserverService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyResizeObserverService, providedIn: 'any' });
|
67
73
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyResizeObserverService, decorators: [{
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"resize-observer.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/resize-observer/resize-observer.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,EAAa,MAAM,eAAe,CAAC;AAE1E,OAAO,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;;AAQ1C;;GAEG;AAIH,MAAM,OAAO,wBAAwB;
|
1
|
+
{"version":3,"file":"resize-observer.service.js","sourceRoot":"","sources":["../../../../../../../../libs/components/core/src/lib/modules/resize-observer/resize-observer.service.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,EAAa,MAAM,eAAe,CAAC;AAE1E,OAAO,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;;AAQ1C;;GAEG;AAIH,MAAM,OAAO,wBAAwB;IAKnC,YAAoB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAJhC,2DAAgC;QAEhC,6CAAsC,EAAE,EAAC;QAGvC,uBAAA,IAAI,4CAAmB,IAAI,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE;YACpD,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE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;YACf,OAAO,EAAE,OAAO,CAAC,aAAa;YAC9B,OAAO;YACP,iBAAiB;SAClB,CAAC;QAEF,uBAAA,IAAI,0CAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE9B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEO,QAAQ,CAAC,KAA0B;QACzC,uBAAA,IAAI,0CAAU;aACX,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;aACrE,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACjB,0BAA0B;YAC1B,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,MAAM,EAAE;gBAClC,6EAA6E;gBAC7E,6DAA6D;gBAC7D,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;oBACjB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC5B,CAAC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACP,CAAC;;;sHAzEU,wBAAwB;0HAAxB,wBAAwB,cAFvB,KAAK;4FAEN,wBAAwB;kBAHpC,UAAU;mBAAC;oBACV,UAAU,EAAE,KAAK;iBAClB","sourcesContent":["import { ElementRef, Injectable, NgZone, OnDestroy } from '@angular/core';\n\nimport { Observable, Subject } from 'rxjs';\nimport { finalize } from 'rxjs/operators';\n\ntype ResizeObserverTracking = {\n element: Element;\n subject: Subject<ResizeObserverEntry>;\n subjectObservable: Observable<ResizeObserverEntry>;\n};\n\n/**\n * Service to create rxjs observables for changes to the content box dimensions of elements.\n */\n@Injectable({\n providedIn: 'any',\n})\nexport class SkyResizeObserverService implements OnDestroy {\n #resizeObserver: ResizeObserver;\n\n #tracking: ResizeObserverTracking[] = [];\n\n constructor(private zone: NgZone) {\n this.#resizeObserver = new ResizeObserver((entries) => {\n entries.forEach((entry) => this.callback(entry));\n });\n }\n\n public ngOnDestroy(): void {\n this.#resizeObserver.disconnect();\n }\n\n /**\n * Create rxjs observable to get size changes for an element ref.\n */\n public observe(element: ElementRef): Observable<ResizeObserverEntry> {\n return this.observeAndTrack(element).subjectObservable;\n }\n\n private observeAndTrack(element: ElementRef): ResizeObserverTracking {\n const checkTracking = this.#tracking.findIndex((value) => {\n return !value.subject.closed && value.element === element.nativeElement;\n });\n\n if (checkTracking === -1) {\n this.#resizeObserver.observe(element.nativeElement);\n }\n\n const subject = new Subject<ResizeObserverEntry>();\n const subjectObservable = subject.pipe(\n finalize(() => {\n // Are there any other tracking entries still watching this element?\n const checkTracking = this.#tracking.findIndex((value) => {\n return (\n value.subject !== subject &&\n !value.subject.closed &&\n value.element === element.nativeElement\n );\n });\n\n if (checkTracking === -1) {\n this.#resizeObserver.unobserve(element.nativeElement);\n }\n })\n );\n\n const tracking = {\n element: element.nativeElement,\n subject,\n subjectObservable,\n };\n\n this.#tracking.push(tracking);\n\n return tracking;\n }\n\n private callback(entry: ResizeObserverEntry): void {\n this.#tracking\n .filter((value) => !(value.subject.closed || value.subject.isStopped))\n .forEach((value) => {\n /* istanbul ignore else */\n if (value.element === entry.target) {\n // Execute the callback within NgZone because Angular does not \"monkey patch\"\n // ResizeObserver like it does for other features in the DOM.\n this.zone.run(() => {\n value.subject.next(entry);\n });\n }\n });\n }\n}\n"]}
|