/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { Directionality } from '@angular/cdk/bidi'; import { getRtlScrollAxisType, supportsScrollBehavior, } from '@angular/cdk/platform'; import { Directive, ElementRef, NgZone, Optional } from '@angular/core'; import { fromEvent, Observable, Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { ScrollDispatcher } from './scroll-dispatcher'; import * as i0 from "@angular/core"; import * as i1 from "./scroll-dispatcher"; import * as i2 from "@angular/cdk/bidi"; /** * Sends an event when the directive's element is scrolled. Registers itself with the * ScrollDispatcher service to include itself as part of its collection of scrolling events that it * can be listened to through the service. */ export class CdkScrollable { constructor(elementRef, scrollDispatcher, ngZone, dir) { this.elementRef = elementRef; this.scrollDispatcher = scrollDispatcher; this.ngZone = ngZone; this.dir = dir; this._destroyed = new Subject(); this._elementScrolled = new Observable((observer) => this.ngZone.runOutsideAngular(() => fromEvent(this.elementRef.nativeElement, 'scroll') .pipe(takeUntil(this._destroyed)) .subscribe(observer))); } ngOnInit() { this.scrollDispatcher.register(this); } ngOnDestroy() { this.scrollDispatcher.deregister(this); this._destroyed.next(); this._destroyed.complete(); } /** Returns observable that emits when a scroll event is fired on the host element. */ elementScrolled() { return this._elementScrolled; } /** Gets the ElementRef for the viewport. */ getElementRef() { return this.elementRef; } /** * Scrolls to the specified offsets. This is a normalized version of the browser's native scrollTo * method, since browsers are not consistent about what scrollLeft means in RTL. For this method * left and right always refer to the left and right side of the scrolling container irrespective * of the layout direction. start and end refer to left and right in an LTR context and vice-versa * in an RTL context. * @param options specified the offsets to scroll to. */ scrollTo(options) { const el = this.elementRef.nativeElement; const isRtl = this.dir && this.dir.value == 'rtl'; // Rewrite start & end offsets as right or left offsets. if (options.left == null) { options.left = isRtl ? options.end : options.start; } if (options.right == null) { options.right = isRtl ? options.start : options.end; } // Rewrite the bottom offset as a top offset. if (options.bottom != null) { options.top = el.scrollHeight - el.clientHeight - options.bottom; } // Rewrite the right offset as a left offset. if (isRtl && getRtlScrollAxisType() != 0 /* RtlScrollAxisType.NORMAL */) { if (options.left != null) { options.right = el.scrollWidth - el.clientWidth - options.left; } if (getRtlScrollAxisType() == 2 /* RtlScrollAxisType.INVERTED */) { options.left = options.right; } else if (getRtlScrollAxisType() == 1 /* RtlScrollAxisType.NEGATED */) { options.left = options.right ? -options.right : options.right; } } else { if (options.right != null) { options.left = el.scrollWidth - el.clientWidth - options.right; } } this._applyScrollToOptions(options); } _applyScrollToOptions(options) { const el = this.elementRef.nativeElement; if (supportsScrollBehavior()) { el.scrollTo(options); } else { if (options.top != null) { el.scrollTop = options.top; } if (options.left != null) { el.scrollLeft = options.left; } } } /** * Measures the scroll offset relative to the specified edge of the viewport. This method can be * used instead of directly checking scrollLeft or scrollTop, since browsers are not consistent * about what scrollLeft means in RTL. The values returned by this method are normalized such that * left and right always refer to the left and right side of the scrolling container irrespective * of the layout direction. start and end refer to left and right in an LTR context and vice-versa * in an RTL context. * @param from The edge to measure from. */ measureScrollOffset(from) { const LEFT = 'left'; const RIGHT = 'right'; const el = this.elementRef.nativeElement; if (from == 'top') { return el.scrollTop; } if (from == 'bottom') { return el.scrollHeight - el.clientHeight - el.scrollTop; } // Rewrite start & end as left or right offsets. const isRtl = this.dir && this.dir.value == 'rtl'; if (from == 'start') { from = isRtl ? RIGHT : LEFT; } else if (from == 'end') { from = isRtl ? LEFT : RIGHT; } if (isRtl && getRtlScrollAxisType() == 2 /* RtlScrollAxisType.INVERTED */) { // For INVERTED, scrollLeft is (scrollWidth - clientWidth) when scrolled all the way left and // 0 when scrolled all the way right. if (from == LEFT) { return el.scrollWidth - el.clientWidth - el.scrollLeft; } else { return el.scrollLeft; } } else if (isRtl && getRtlScrollAxisType() == 1 /* RtlScrollAxisType.NEGATED */) { // For NEGATED, scrollLeft is -(scrollWidth - clientWidth) when scrolled all the way left and // 0 when scrolled all the way right. if (from == LEFT) { return el.scrollLeft + el.scrollWidth - el.clientWidth; } else { return -el.scrollLeft; } } else { // For NORMAL, as well as non-RTL contexts, scrollLeft is 0 when scrolled all the way left and // (scrollWidth - clientWidth) when scrolled all the way right. if (from == LEFT) { return el.scrollLeft; } else { return el.scrollWidth - el.clientWidth - el.scrollLeft; } } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkScrollable, deps: [{ token: i0.ElementRef }, { token: i1.ScrollDispatcher }, { token: i0.NgZone }, { token: i2.Directionality, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.1", type: CdkScrollable, isStandalone: true, selector: "[cdk-scrollable], [cdkScrollable]", ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkScrollable, decorators: [{ type: Directive, args: [{ selector: '[cdk-scrollable], [cdkScrollable]', standalone: true, }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.ScrollDispatcher }, { type: i0.NgZone }, { type: i2.Directionality, decorators: [{ type: Optional }] }]; } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2Nyb2xsYWJsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvc2Nyb2xsaW5nL3Njcm9sbGFibGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUFDLGNBQWMsRUFBQyxNQUFNLG1CQUFtQixDQUFDO0FBQ2pELE9BQU8sRUFDTCxvQkFBb0IsRUFFcEIsc0JBQXNCLEdBQ3ZCLE1BQU0sdUJBQXVCLENBQUM7QUFDL0IsT0FBTyxFQUFDLFNBQVMsRUFBRSxVQUFVLEVBQUUsTUFBTSxFQUFxQixRQUFRLEVBQUMsTUFBT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