{"version":3,"file":"private.mjs","sources":["../../../../../../../src/cdk/observers/private/shared-resize-observer.ts","../../../../../../../src/cdk/observers/private/private_public_index.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.io/license\n */\nimport {inject, Injectable, NgZone, OnDestroy} 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 Error && 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();\n /** Stream of all events from the ResizeObserver. */\n private _resizeSubject = new Subject();\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>();\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 {\n if (!this._elementObservables.has(target)) {\n this._elementObservables.set(\n target,\n new Observable(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 /** Map of box type to shared resize observer. */\n private _observers = new Map();\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 window.addEventListener('error', loopLimitExceededErrorHandler);\n });\n }\n }\n\n ngOnDestroy() {\n for (const [, observer] of this._observers) {\n observer.destroy();\n }\n this._observers.clear();\n if (typeof ResizeObserver !== 'undefined' && (typeof ngDevMode === 'undefined' || ngDevMode)) {\n window.removeEventListener('error', loopLimitExceededErrorHandler);\n }\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 {\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","/**\n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