import { Inject, Injectable } from '@angular/core'; import { DOCUMENT } from '@angular/common'; import { BehaviorSubject, fromEvent, debounceTime, tap, distinctUntilChanged, map } from 'rxjs'; import * as i0 from "@angular/core"; import * as i1 from "../utils/scrollbar-manager"; import * as i2 from "@angular/cdk/platform"; export class NativeScrollbarSizeFactory { constructor(document, manager, platform) { this.document = document; this.manager = manager; this.platform = platform; this._scrollbarSize = new BehaviorSubject(this.getNativeScrollbarSize()); this.scrollbarSize = this._scrollbarSize.asObservable(); // Calculate native scrollbar size on window resize event, because the size changes if use zoomed in/out if (platform.isBrowser) { fromEvent(this.document.defaultView, 'resize', { passive: true }).pipe(debounceTime(this.manager.globalOptions.windowResizeDebounce), map(() => this.getNativeScrollbarSize()), distinctUntilChanged(), tap((size) => this._scrollbarSize.next(size))).subscribe(); } } /** * Get native scrollbar size */ getNativeScrollbarSize() { // Avoid executing browser code in server side rendering if (!this.platform.isBrowser) { return 0; } // Hide iOS browsers native scrollbar if (this.platform.IOS) { return 6; } const box = this.document.createElement('div'); box.className = 'ng-scrollbar-measure'; box.style.left = '0px'; box.style.overflow = 'scroll'; box.style.position = 'fixed'; box.style.top = '-9999px'; this.document.body.appendChild(box); const size = box.getBoundingClientRect().right; this.document.body.removeChild(box); return size; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.5", ngImport: i0, type: NativeScrollbarSizeFactory, deps: [{ token: DOCUMENT }, { token: i1.ScrollbarManager }, { token: i2.Platform }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.5", ngImport: i0, type: NativeScrollbarSizeFactory, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.5", ngImport: i0, type: NativeScrollbarSizeFactory, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: function () { return [{ type: Document, decorators: [{ type: Inject, args: [DOCUMENT] }] }, { type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