@angular/cdk 21.0.0-next.9 → 21.0.0-rc.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/_adev_assets/cdk_drag_drop.json +13 -12
- package/_adev_assets/cdk_testing.json +9 -9
- package/_adev_assets/cdk_testing_protractor.json +1 -1
- package/_adev_assets/cdk_testing_selenium_webdriver.json +1 -1
- package/_adev_assets/cdk_testing_testbed.json +1 -1
- package/fesm2022/_a11y-module-chunk.mjs +755 -869
- package/fesm2022/_a11y-module-chunk.mjs.map +1 -1
- package/fesm2022/_activedescendant-key-manager-chunk.mjs +8 -8
- package/fesm2022/_activedescendant-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_array-chunk.mjs +1 -1
- package/fesm2022/_array-chunk.mjs.map +1 -1
- package/fesm2022/_breakpoints-observer-chunk.mjs +149 -152
- package/fesm2022/_breakpoints-observer-chunk.mjs.map +1 -1
- package/fesm2022/_css-pixel-value-chunk.mjs +4 -5
- package/fesm2022/_css-pixel-value-chunk.mjs.map +1 -1
- package/fesm2022/_data-source-chunk.mjs +2 -8
- package/fesm2022/_data-source-chunk.mjs.map +1 -1
- package/fesm2022/_directionality-chunk.mjs +54 -54
- package/fesm2022/_directionality-chunk.mjs.map +1 -1
- package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs +25 -36
- package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs.map +1 -1
- package/fesm2022/_element-chunk.mjs +6 -17
- package/fesm2022/_element-chunk.mjs.map +1 -1
- package/fesm2022/_fake-event-detection-chunk.mjs +3 -17
- package/fesm2022/_fake-event-detection-chunk.mjs.map +1 -1
- package/fesm2022/_focus-key-manager-chunk.mjs +10 -14
- package/fesm2022/_focus-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_focus-monitor-chunk.mjs +376 -566
- package/fesm2022/_focus-monitor-chunk.mjs.map +1 -1
- package/fesm2022/_id-generator-chunk.mjs +36 -27
- package/fesm2022/_id-generator-chunk.mjs.map +1 -1
- package/fesm2022/_keycodes-chunk.mjs +9 -9
- package/fesm2022/_keycodes-chunk.mjs.map +1 -1
- package/fesm2022/_list-key-manager-chunk.mjs +248 -336
- package/fesm2022/_list-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_overlay-module-chunk.mjs +2534 -2948
- package/fesm2022/_overlay-module-chunk.mjs.map +1 -1
- package/fesm2022/_passive-listeners-chunk.mjs +10 -22
- package/fesm2022/_passive-listeners-chunk.mjs.map +1 -1
- package/fesm2022/_platform-chunk.mjs +42 -65
- package/fesm2022/_platform-chunk.mjs.map +1 -1
- package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs +78 -134
- package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs.map +1 -1
- package/fesm2022/_scrolling-chunk.mjs +44 -85
- package/fesm2022/_scrolling-chunk.mjs.map +1 -1
- package/fesm2022/_selection-model-chunk.mjs +138 -209
- package/fesm2022/_selection-model-chunk.mjs.map +1 -1
- package/fesm2022/_shadow-dom-chunk.mjs +21 -35
- package/fesm2022/_shadow-dom-chunk.mjs.map +1 -1
- package/fesm2022/_style-loader-chunk.mjs +50 -37
- package/fesm2022/_style-loader-chunk.mjs.map +1 -1
- package/fesm2022/_test-environment-chunk.mjs +2 -14
- package/fesm2022/_test-environment-chunk.mjs.map +1 -1
- package/fesm2022/_tree-key-manager-chunk.mjs +229 -308
- package/fesm2022/_tree-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_typeahead-chunk.mjs +52 -74
- package/fesm2022/_typeahead-chunk.mjs.map +1 -1
- package/fesm2022/_unique-selection-dispatcher-chunk.mjs +43 -40
- package/fesm2022/_unique-selection-dispatcher-chunk.mjs.map +1 -1
- package/fesm2022/a11y.mjs +351 -449
- package/fesm2022/a11y.mjs.map +1 -1
- package/fesm2022/accordion.mjs +254 -192
- package/fesm2022/accordion.mjs.map +1 -1
- package/fesm2022/bidi.mjs +121 -64
- package/fesm2022/bidi.mjs.map +1 -1
- package/fesm2022/cdk.mjs +1 -2
- package/fesm2022/cdk.mjs.map +1 -1
- package/fesm2022/clipboard.mjs +208 -186
- package/fesm2022/clipboard.mjs.map +1 -1
- package/fesm2022/coercion-private.mjs +4 -8
- package/fesm2022/coercion-private.mjs.map +1 -1
- package/fesm2022/coercion.mjs +11 -29
- package/fesm2022/coercion.mjs.map +1 -1
- package/fesm2022/dialog.mjs +660 -808
- package/fesm2022/dialog.mjs.map +1 -1
- package/fesm2022/drag-drop.mjs +3347 -4286
- package/fesm2022/drag-drop.mjs.map +1 -1
- package/fesm2022/keycodes.mjs +4 -8
- package/fesm2022/keycodes.mjs.map +1 -1
- package/fesm2022/layout.mjs +44 -26
- package/fesm2022/layout.mjs.map +1 -1
- package/fesm2022/listbox.mjs +841 -895
- package/fesm2022/listbox.mjs.map +1 -1
- package/fesm2022/menu.mjs +1942 -1858
- package/fesm2022/menu.mjs.map +1 -1
- package/fesm2022/observers-private.mjs +88 -106
- package/fesm2022/observers-private.mjs.map +1 -1
- package/fesm2022/observers.mjs +262 -184
- package/fesm2022/observers.mjs.map +1 -1
- package/fesm2022/overlay.mjs +72 -68
- package/fesm2022/overlay.mjs.map +1 -1
- package/fesm2022/platform.mjs +43 -54
- package/fesm2022/platform.mjs.map +1 -1
- package/fesm2022/portal.mjs +402 -560
- package/fesm2022/portal.mjs.map +1 -1
- package/fesm2022/private.mjs +38 -10
- package/fesm2022/private.mjs.map +1 -1
- package/fesm2022/scrolling.mjs +1323 -1400
- package/fesm2022/scrolling.mjs.map +1 -1
- package/fesm2022/stepper.mjs +758 -590
- package/fesm2022/stepper.mjs.map +1 -1
- package/fesm2022/table.mjs +2327 -2319
- package/fesm2022/table.mjs.map +1 -1
- package/fesm2022/testing-selenium-webdriver.mjs +252 -325
- package/fesm2022/testing-selenium-webdriver.mjs.map +1 -1
- package/fesm2022/testing-testbed.mjs +592 -709
- package/fesm2022/testing-testbed.mjs.map +1 -1
- package/fesm2022/testing.mjs +368 -889
- package/fesm2022/testing.mjs.map +1 -1
- package/fesm2022/text-field.mjs +459 -388
- package/fesm2022/text-field.mjs.map +1 -1
- package/fesm2022/tree.mjs +1483 -1731
- package/fesm2022/tree.mjs.map +1 -1
- package/overlay/_index.scss +28 -0
- package/overlay-prebuilt.css +1 -1
- package/package.json +1 -1
- package/schematics/ng-add/index.js +1 -1
- package/types/_overlay-module-chunk.d.ts +59 -7
- package/types/_portal-directives-chunk.d.ts +2 -18
- package/types/accordion.d.ts +3 -1
- package/types/dialog.d.ts +1 -1
- package/types/overlay.d.ts +6 -2
- package/types/portal.d.ts +1 -1
|
@@ -3,122 +3,104 @@ import { inject, NgZone, RendererFactory2, Injectable } from '@angular/core';
|
|
|
3
3
|
import { Subject, Observable } from 'rxjs';
|
|
4
4
|
import { filter, shareReplay, takeUntil } from 'rxjs/operators';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
const loopLimitExceededErrorHandler = (e) => {
|
|
12
|
-
if (e instanceof ErrorEvent && e.message === 'ResizeObserver loop limit exceeded') {
|
|
13
|
-
console.error(`${e.message}. This could indicate a performance issue with your app. See https://github.com/WICG/resize-observer/blob/master/explainer.md#error-handling`);
|
|
14
|
-
}
|
|
6
|
+
const loopLimitExceededErrorHandler = e => {
|
|
7
|
+
if (e instanceof ErrorEvent && e.message === 'ResizeObserver loop limit exceeded') {
|
|
8
|
+
console.error(`${e.message}. This could indicate a performance issue with your app. See https://github.com/WICG/resize-observer/blob/master/explainer.md#error-handling`);
|
|
9
|
+
}
|
|
15
10
|
};
|
|
16
|
-
/**
|
|
17
|
-
* A shared ResizeObserver to be used for a particular box type (content-box, border-box, or
|
|
18
|
-
* device-pixel-content-box)
|
|
19
|
-
*/
|
|
20
11
|
class SingleBoxSharedResizeObserver {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
constructor(
|
|
31
|
-
/** The box type to observe for resizes. */
|
|
32
|
-
_box) {
|
|
33
|
-
this._box = _box;
|
|
34
|
-
if (typeof ResizeObserver !== 'undefined') {
|
|
35
|
-
this._resizeObserver = new ResizeObserver(entries => this._resizeSubject.next(entries));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Gets a stream of resize events for the given element.
|
|
40
|
-
* @param target The element to observe.
|
|
41
|
-
* @return The stream of resize events for the element.
|
|
42
|
-
*/
|
|
43
|
-
observe(target) {
|
|
44
|
-
if (!this._elementObservables.has(target)) {
|
|
45
|
-
this._elementObservables.set(target, new Observable(observer => {
|
|
46
|
-
const subscription = this._resizeSubject.subscribe(observer);
|
|
47
|
-
this._resizeObserver?.observe(target, { box: this._box });
|
|
48
|
-
return () => {
|
|
49
|
-
this._resizeObserver?.unobserve(target);
|
|
50
|
-
subscription.unsubscribe();
|
|
51
|
-
this._elementObservables.delete(target);
|
|
52
|
-
};
|
|
53
|
-
}).pipe(filter(entries => entries.some(entry => entry.target === target)),
|
|
54
|
-
// Share a replay of the last event so that subsequent calls to observe the same element
|
|
55
|
-
// receive initial sizing info like the first one. Also enable ref counting so the
|
|
56
|
-
// element will be automatically unobserved when there are no more subscriptions.
|
|
57
|
-
shareReplay({ bufferSize: 1, refCount: true }), takeUntil(this._destroyed)));
|
|
58
|
-
}
|
|
59
|
-
return this._elementObservables.get(target);
|
|
12
|
+
_box;
|
|
13
|
+
_destroyed = new Subject();
|
|
14
|
+
_resizeSubject = new Subject();
|
|
15
|
+
_resizeObserver;
|
|
16
|
+
_elementObservables = new Map();
|
|
17
|
+
constructor(_box) {
|
|
18
|
+
this._box = _box;
|
|
19
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
20
|
+
this._resizeObserver = new ResizeObserver(entries => this._resizeSubject.next(entries));
|
|
60
21
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this._resizeSubject.
|
|
66
|
-
this.
|
|
22
|
+
}
|
|
23
|
+
observe(target) {
|
|
24
|
+
if (!this._elementObservables.has(target)) {
|
|
25
|
+
this._elementObservables.set(target, new Observable(observer => {
|
|
26
|
+
const subscription = this._resizeSubject.subscribe(observer);
|
|
27
|
+
this._resizeObserver?.observe(target, {
|
|
28
|
+
box: this._box
|
|
29
|
+
});
|
|
30
|
+
return () => {
|
|
31
|
+
this._resizeObserver?.unobserve(target);
|
|
32
|
+
subscription.unsubscribe();
|
|
33
|
+
this._elementObservables.delete(target);
|
|
34
|
+
};
|
|
35
|
+
}).pipe(filter(entries => entries.some(entry => entry.target === target)), shareReplay({
|
|
36
|
+
bufferSize: 1,
|
|
37
|
+
refCount: true
|
|
38
|
+
}), takeUntil(this._destroyed)));
|
|
67
39
|
}
|
|
40
|
+
return this._elementObservables.get(target);
|
|
41
|
+
}
|
|
42
|
+
destroy() {
|
|
43
|
+
this._destroyed.next();
|
|
44
|
+
this._destroyed.complete();
|
|
45
|
+
this._resizeSubject.complete();
|
|
46
|
+
this._elementObservables.clear();
|
|
47
|
+
}
|
|
68
48
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Allows observing resize events on multiple elements using a shared set of ResizeObserver.
|
|
71
|
-
* Sharing a ResizeObserver instance is recommended for better performance (see
|
|
72
|
-
* https://github.com/WICG/resize-observer/issues/59).
|
|
73
|
-
*
|
|
74
|
-
* Rather than share a single `ResizeObserver`, this class creates one `ResizeObserver` per type
|
|
75
|
-
* of observed box ('content-box', 'border-box', and 'device-pixel-content-box'). This avoids
|
|
76
|
-
* later calls to `observe` with a different box type from influencing the events dispatched to
|
|
77
|
-
* earlier calls.
|
|
78
|
-
*/
|
|
79
49
|
class SharedResizeObserver {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this._cleanupErrorListener = renderer.listen('window', 'error', loopLimitExceededErrorHandler);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
50
|
+
_cleanupErrorListener;
|
|
51
|
+
_observers = new Map();
|
|
52
|
+
_ngZone = inject(NgZone);
|
|
53
|
+
constructor() {
|
|
54
|
+
if (typeof ResizeObserver !== 'undefined' && (typeof ngDevMode === 'undefined' || ngDevMode)) {
|
|
55
|
+
this._ngZone.runOutsideAngular(() => {
|
|
56
|
+
const renderer = inject(RendererFactory2).createRenderer(null, null);
|
|
57
|
+
this._cleanupErrorListener = renderer.listen('window', 'error', loopLimitExceededErrorHandler);
|
|
58
|
+
});
|
|
92
59
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this._observers.clear();
|
|
98
|
-
this._cleanupErrorListener?.();
|
|
60
|
+
}
|
|
61
|
+
ngOnDestroy() {
|
|
62
|
+
for (const [, observer] of this._observers) {
|
|
63
|
+
observer.destroy();
|
|
99
64
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const box = options?.box || 'content-box';
|
|
108
|
-
if (!this._observers.has(box)) {
|
|
109
|
-
this._observers.set(box, new SingleBoxSharedResizeObserver(box));
|
|
110
|
-
}
|
|
111
|
-
return this._observers.get(box).observe(target);
|
|
65
|
+
this._observers.clear();
|
|
66
|
+
this._cleanupErrorListener?.();
|
|
67
|
+
}
|
|
68
|
+
observe(target, options) {
|
|
69
|
+
const box = options?.box || 'content-box';
|
|
70
|
+
if (!this._observers.has(box)) {
|
|
71
|
+
this._observers.set(box, new SingleBoxSharedResizeObserver(box));
|
|
112
72
|
}
|
|
113
|
-
|
|
114
|
-
|
|
73
|
+
return this._observers.get(box).observe(target);
|
|
74
|
+
}
|
|
75
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
76
|
+
minVersion: "12.0.0",
|
|
77
|
+
version: "20.2.0-next.2",
|
|
78
|
+
ngImport: i0,
|
|
79
|
+
type: SharedResizeObserver,
|
|
80
|
+
deps: [],
|
|
81
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
82
|
+
});
|
|
83
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
84
|
+
minVersion: "12.0.0",
|
|
85
|
+
version: "20.2.0-next.2",
|
|
86
|
+
ngImport: i0,
|
|
87
|
+
type: SharedResizeObserver,
|
|
88
|
+
providedIn: 'root'
|
|
89
|
+
});
|
|
115
90
|
}
|
|
116
|
-
i0.ɵɵngDeclareClassMetadata({
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
91
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
92
|
+
minVersion: "12.0.0",
|
|
93
|
+
version: "20.2.0-next.2",
|
|
94
|
+
ngImport: i0,
|
|
95
|
+
type: SharedResizeObserver,
|
|
96
|
+
decorators: [{
|
|
97
|
+
type: Injectable,
|
|
98
|
+
args: [{
|
|
99
|
+
providedIn: 'root'
|
|
100
|
+
}]
|
|
101
|
+
}],
|
|
102
|
+
ctorParameters: () => []
|
|
103
|
+
});
|
|
122
104
|
|
|
123
105
|
export { SharedResizeObserver };
|
|
124
106
|
//# sourceMappingURL=observers-private.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observers-private.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk/observers/private/shared-resize-observer.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\nimport {inject, Injectable, NgZone, OnDestroy, RendererFactory2} from '@angular/core';\nimport {Observable, Subject} from 'rxjs';\nimport {filter, shareReplay, takeUntil} from 'rxjs/operators';\n\n/**\n * Handler that logs \"ResizeObserver loop limit exceeded\" errors.\n * These errors are not shown in the Chrome console, so we log them to ensure developers are aware.\n * @param e The error\n */\nconst loopLimitExceededErrorHandler = (e: unknown) => {\n if (e instanceof ErrorEvent && e.message === 'ResizeObserver loop limit exceeded') {\n console.error(\n `${e.message}. This could indicate a performance issue with your app. See https://github.com/WICG/resize-observer/blob/master/explainer.md#error-handling`,\n );\n }\n};\n\n/**\n * A shared ResizeObserver to be used for a particular box type (content-box, border-box, or\n * device-pixel-content-box)\n */\nclass SingleBoxSharedResizeObserver {\n /** Stream that emits when the shared observer is destroyed. */\n private _destroyed = new Subject<void>();\n /** Stream of all events from the ResizeObserver. */\n private _resizeSubject = new Subject<ResizeObserverEntry[]>();\n /** ResizeObserver used to observe element resize events. */\n private _resizeObserver?: ResizeObserver;\n /** A map of elements to streams of their resize events. */\n private _elementObservables = new Map<Element, Observable<ResizeObserverEntry[]>>();\n\n constructor(\n /** The box type to observe for resizes. */\n private _box: ResizeObserverBoxOptions,\n ) {\n if (typeof ResizeObserver !== 'undefined') {\n this._resizeObserver = new ResizeObserver(entries => this._resizeSubject.next(entries));\n }\n }\n\n /**\n * Gets a stream of resize events for the given element.\n * @param target The element to observe.\n * @return The stream of resize events for the element.\n */\n observe(target: Element): Observable<ResizeObserverEntry[]> {\n if (!this._elementObservables.has(target)) {\n this._elementObservables.set(\n target,\n new Observable<ResizeObserverEntry[]>(observer => {\n const subscription = this._resizeSubject.subscribe(observer);\n this._resizeObserver?.observe(target, {box: this._box});\n return () => {\n this._resizeObserver?.unobserve(target);\n subscription.unsubscribe();\n this._elementObservables.delete(target);\n };\n }).pipe(\n filter(entries => entries.some(entry => entry.target === target)),\n // Share a replay of the last event so that subsequent calls to observe the same element\n // receive initial sizing info like the first one. Also enable ref counting so the\n // element will be automatically unobserved when there are no more subscriptions.\n shareReplay({bufferSize: 1, refCount: true}),\n takeUntil(this._destroyed),\n ),\n );\n }\n return this._elementObservables.get(target)!;\n }\n\n /** Destroys this instance. */\n destroy() {\n this._destroyed.next();\n this._destroyed.complete();\n this._resizeSubject.complete();\n this._elementObservables.clear();\n }\n}\n\n/**\n * Allows observing resize events on multiple elements using a shared set of ResizeObserver.\n * Sharing a ResizeObserver instance is recommended for better performance (see\n * https://github.com/WICG/resize-observer/issues/59).\n *\n * Rather than share a single `ResizeObserver`, this class creates one `ResizeObserver` per type\n * of observed box ('content-box', 'border-box', and 'device-pixel-content-box'). This avoids\n * later calls to `observe` with a different box type from influencing the events dispatched to\n * earlier calls.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class SharedResizeObserver implements OnDestroy {\n private _cleanupErrorListener: (() => void) | undefined;\n\n /** Map of box type to shared resize observer. */\n private _observers = new Map<ResizeObserverBoxOptions, SingleBoxSharedResizeObserver>();\n\n /** The Angular zone. */\n private _ngZone = inject(NgZone);\n\n constructor() {\n if (typeof ResizeObserver !== 'undefined' && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n this._ngZone.runOutsideAngular(() => {\n const renderer = inject(RendererFactory2).createRenderer(null, null);\n this._cleanupErrorListener = renderer.listen(\n 'window',\n 'error',\n loopLimitExceededErrorHandler,\n );\n });\n }\n }\n\n ngOnDestroy() {\n for (const [, observer] of this._observers) {\n observer.destroy();\n }\n this._observers.clear();\n this._cleanupErrorListener?.();\n }\n\n /**\n * Gets a stream of resize events for the given target element and box type.\n * @param target The element to observe for resizes.\n * @param options Options to pass to the `ResizeObserver`\n * @return The stream of resize events for the element.\n */\n observe(target: Element, options?: ResizeObserverOptions): Observable<ResizeObserverEntry[]> {\n const box = options?.box || 'content-box';\n if (!this._observers.has(box)) {\n this._observers.set(box, new SingleBoxSharedResizeObserver(box));\n }\n return this._observers.get(box)!.observe(target);\n }\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"observers-private.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk/observers/private/shared-resize-observer.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\nimport {inject, Injectable, NgZone, OnDestroy, RendererFactory2} from '@angular/core';\nimport {Observable, Subject} from 'rxjs';\nimport {filter, shareReplay, takeUntil} from 'rxjs/operators';\n\n/**\n * Handler that logs \"ResizeObserver loop limit exceeded\" errors.\n * These errors are not shown in the Chrome console, so we log them to ensure developers are aware.\n * @param e The error\n */\nconst loopLimitExceededErrorHandler = (e: unknown) => {\n if (e instanceof ErrorEvent && e.message === 'ResizeObserver loop limit exceeded') {\n console.error(\n `${e.message}. This could indicate a performance issue with your app. See https://github.com/WICG/resize-observer/blob/master/explainer.md#error-handling`,\n );\n }\n};\n\n/**\n * A shared ResizeObserver to be used for a particular box type (content-box, border-box, or\n * device-pixel-content-box)\n */\nclass SingleBoxSharedResizeObserver {\n /** Stream that emits when the shared observer is destroyed. */\n private _destroyed = new Subject<void>();\n /** Stream of all events from the ResizeObserver. */\n private _resizeSubject = new Subject<ResizeObserverEntry[]>();\n /** ResizeObserver used to observe element resize events. */\n private _resizeObserver?: ResizeObserver;\n /** A map of elements to streams of their resize events. */\n private _elementObservables = new Map<Element, Observable<ResizeObserverEntry[]>>();\n\n constructor(\n /** The box type to observe for resizes. */\n private _box: ResizeObserverBoxOptions,\n ) {\n if (typeof ResizeObserver !== 'undefined') {\n this._resizeObserver = new ResizeObserver(entries => this._resizeSubject.next(entries));\n }\n }\n\n /**\n * Gets a stream of resize events for the given element.\n * @param target The element to observe.\n * @return The stream of resize events for the element.\n */\n observe(target: Element): Observable<ResizeObserverEntry[]> {\n if (!this._elementObservables.has(target)) {\n this._elementObservables.set(\n target,\n new Observable<ResizeObserverEntry[]>(observer => {\n const subscription = this._resizeSubject.subscribe(observer);\n this._resizeObserver?.observe(target, {box: this._box});\n return () => {\n this._resizeObserver?.unobserve(target);\n subscription.unsubscribe();\n this._elementObservables.delete(target);\n };\n }).pipe(\n filter(entries => entries.some(entry => entry.target === target)),\n // Share a replay of the last event so that subsequent calls to observe the same element\n // receive initial sizing info like the first one. Also enable ref counting so the\n // element will be automatically unobserved when there are no more subscriptions.\n shareReplay({bufferSize: 1, refCount: true}),\n takeUntil(this._destroyed),\n ),\n );\n }\n return this._elementObservables.get(target)!;\n }\n\n /** Destroys this instance. */\n destroy() {\n this._destroyed.next();\n this._destroyed.complete();\n this._resizeSubject.complete();\n this._elementObservables.clear();\n }\n}\n\n/**\n * Allows observing resize events on multiple elements using a shared set of ResizeObserver.\n * Sharing a ResizeObserver instance is recommended for better performance (see\n * https://github.com/WICG/resize-observer/issues/59).\n *\n * Rather than share a single `ResizeObserver`, this class creates one `ResizeObserver` per type\n * of observed box ('content-box', 'border-box', and 'device-pixel-content-box'). This avoids\n * later calls to `observe` with a different box type from influencing the events dispatched to\n * earlier calls.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class SharedResizeObserver implements OnDestroy {\n private _cleanupErrorListener: (() => void) | undefined;\n\n /** Map of box type to shared resize observer. */\n private _observers = new Map<ResizeObserverBoxOptions, SingleBoxSharedResizeObserver>();\n\n /** The Angular zone. */\n private _ngZone = inject(NgZone);\n\n constructor() {\n if (typeof ResizeObserver !== 'undefined' && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n this._ngZone.runOutsideAngular(() => {\n const renderer = inject(RendererFactory2).createRenderer(null, null);\n this._cleanupErrorListener = renderer.listen(\n 'window',\n 'error',\n loopLimitExceededErrorHandler,\n );\n });\n }\n }\n\n ngOnDestroy() {\n for (const [, observer] of this._observers) {\n observer.destroy();\n }\n this._observers.clear();\n this._cleanupErrorListener?.();\n }\n\n /**\n * Gets a stream of resize events for the given target element and box type.\n * @param target The element to observe for resizes.\n * @param options Options to pass to the `ResizeObserver`\n * @return The stream of resize events for the element.\n */\n observe(target: Element, options?: ResizeObserverOptions): Observable<ResizeObserverEntry[]> {\n const box = options?.box || 'content-box';\n if (!this._observers.has(box)) {\n this._observers.set(box, new SingleBoxSharedResizeObserver(box));\n }\n return this._observers.get(box)!.observe(target);\n }\n}\n"],"names":["loopLimitExceededErrorHandler","e","_box","_resizeObserver","constructor","ResizeObserver","_resizeSubject","next","entries","_elementObservables","has","target","set","Observable","observer","subscription","unsubscribe","delete","filter","some","entry","bufferSize","refCount","takeUntil","_destroyed","get","_cleanupErrorListener","renderer","listen","ngOnDestroy","_observers","clear"],"mappings":";;;;;AAgBA,MAAAA,6BAAmC,GAAGC,CAAA,IAAC;;;;;AAwB3B,MAAA,6BAAA,CAAA;EAVFC,IAAA;;;EAQRC,eAAA;;AAEwCC,EAAAA,WAAAA,CAEtCF,IAAA,EAAA;IACE,IAAAA,CAAAA,IAAA,GAAAA,IAAA;AACF,IAAA,IAAA,OAAAG,cAAA,KAAA,WAAA,EAAA;2DACF,IAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,OAAA,CAAA,CAAA;AAEA;;;AAWQ,IAAA,IAAA,CAAA,IAAA,CAAAC,mBAAA,CAAAC,GAAA,CAAAC,MAAA,CAAA,EAAA;MAEE,IAAAF,CAAAA,mBAAA,CAAAG,GAAA,CAAAD,MAAA,EAAAE,IAAAA,UAAA,CAAAC,QAAA,IAAA;;;;;;;AAMsFC,UAAAA,YAAA,CAAAC,WAAA,EAAA;AACN,UAAA,IAAA,CAAAP,mBAAA,CAAAQ,MAAA,CAAAN,MAAA,CAAA;;AAOjF,OAAA,CAAA,CAAA,IAAA,CAAAO,MAAA,CAAAV,OAAwB,IAAAA,OAAA,CAAAW,IAAA,CAAAC,KAAW,IAAEA,KAAA,CAAAT,MAAA,KAAAA,MAAA,eAKxC,CAAA;QAAAU,UAAY,EAAA,CAAA;QAAAC,QAAM,EAAA;OAAAC,CAAAA,EAAAA,SAAA,MAAAC,UAAA,CAAA,CAAA,CAAA;;AAElB,IAAA,OAAA,IAAA,CAAAf,mBAAA,CAAAgB,GAAA,CAAAd,MAAA,CAAA;;AAKR,EAAA,OAAA,GAAA;;;;;;;;;;;EAuCIP,WAAA,GAAA;;;;AASC,QAAA,IAAA,CAAAsB,qBAAA,GAAAC,QAAA,CAAAC,MAAA,oBAAA5B,6BAAA,CAAA;AAED,OAAA,CAAA;AACI;;aAGJ6B,GAAA;SACF,MAAA,GAAAf,QAAA,CAAA,IAAA,IAAA,CAAAgB,UAAA,EAAA;;;QA5CA,CAAAA,UAAA,CAAAC,KAAA,EAAA;AACD,IAAA,IAAA,CAAAL,qBAAA,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|