import * as tslib_1 from "tslib";
import { Injectable, NgZone } from '@angular/core';
import { fromEvent, merge } from 'rxjs';
import { auditTime } from 'rxjs/operators';
/** Time in ms to throttle the resize events by default. */
export var DEFAULT_RESIZE_TIME = 20;
/**
 * Simple utility for getting the bounds of the browser viewport.
 * @docs-private
 */
var ViewportRuler = /** @class */ (function () {
    function ViewportRuler(ngZone) {
        var _this = this;
        this._change = ngZone.runOutsideAngular(function () {
            return merge(fromEvent(window, 'resize'), fromEvent(window.document, 'scroll'));
        });
        this._invalidateCache = this.change().subscribe(function () { return _this._cacheViewportGeometry(); });
    }
    /** Caches the latest client rectangle of the document element. */
    ViewportRuler.prototype._cacheViewportGeometry = function () {
        this._documentRect = (document.documentElement || document.body).getBoundingClientRect();
    };
    ViewportRuler.prototype.ngOnDestroy = function () {
        this._invalidateCache.unsubscribe();
    };
    /**
     * Returns a stream that emits whenever the size of the viewport changes.
     * @param throttle Time in milliseconds to throttle the stream.
     * @return { Subscription }
     */
    ViewportRuler.prototype.change = function (throttleTime) {
        if (throttleTime === void 0) { throttleTime = DEFAULT_RESIZE_TIME; }
        return throttleTime > 0 ? this._change.pipe(auditTime(throttleTime)) : this._change;
    };
    ViewportRuler = tslib_1.__decorate([
        Injectable(),
        tslib_1.__metadata("design:paramtypes", [NgZone])
    ], ViewportRuler);
    return ViewportRuler;
}());
export { ViewportRuler };
//# sourceMappingURL=scroll-strategy.js.map