UNPKG

@progress/kendo-angular-grid

Version:

Kendo UI Grid for Angular - high performance data grid with paging, filtering, virtualization, CRUD, and more.

95 lines (94 loc) 4 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Injectable, NgZone, ChangeDetectorRef, EventEmitter } from '@angular/core'; import { fromEvent } from 'rxjs'; import { auditTime } from 'rxjs/operators'; import { isDocumentAvailable } from '@progress/kendo-angular-common'; import * as i0 from "@angular/core"; const canCreateElement = () => isDocumentAvailable() && document.createElement; let cachedScrollbarWidth = null; let cachedPixelRatio; let cachedRtlScrollLeft = null; function scrollbarWidth() { if (cachedScrollbarWidth === null && canCreateElement()) { cachedPixelRatio = window.devicePixelRatio || 1; const div = document.createElement("div"); div.style.cssText = "overflow:scroll;overflow-x:hidden;zoom:1;clear:both;display:block"; div.innerHTML = "&nbsp;"; document.body.appendChild(div); cachedScrollbarWidth = div.offsetWidth - div.scrollWidth; document.body.removeChild(div); } return cachedScrollbarWidth; } function rtlScrollLeft() { if (cachedRtlScrollLeft === null && canCreateElement()) { const outer = document.createElement('div'); outer.style.direction = 'rtl'; outer.style.display = 'block'; outer.style.clear = 'both'; outer.style.width = '100px'; outer.style.visibility = 'hidden'; outer.style.position = 'absolute'; outer.style.left = '-10000px'; outer.style.overflow = 'scroll'; outer.style.zoom = '1'; const inner = document.createElement('div'); inner.style.width = '200px'; inner.style.height = '1px'; outer.append(inner); document.body.appendChild(outer); const initial = outer.scrollLeft; outer.scrollLeft = -1; cachedRtlScrollLeft = outer.scrollLeft < 0 ? outer.scrollLeft : initial; document.body.removeChild(outer); } return cachedRtlScrollLeft; } /** * @hidden * move to kendo-common */ export class BrowserSupportService { zone; changeDetector; changes = new EventEmitter(); subscriptions; constructor(zone, changeDetector) { this.zone = zone; this.changeDetector = changeDetector; if (typeof window === 'undefined') { return; } this.zone.runOutsideAngular(() => { this.subscriptions = fromEvent(window, 'resize').pipe(auditTime(100)).subscribe(() => { if (cachedPixelRatio !== window.devicePixelRatio) { zone.run(() => { cachedScrollbarWidth = null; this.changes.emit(); this.changeDetector.markForCheck(); }); } }); }); } ngOnDestroy() { if (this.subscriptions) { this.subscriptions.unsubscribe(); this.subscriptions = null; } } get scrollbarWidth() { return scrollbarWidth(); } get rtlScrollLeft() { return rtlScrollLeft(); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BrowserSupportService, deps: [{ token: i0.NgZone }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BrowserSupportService }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BrowserSupportService, decorators: [{ type: Injectable }], ctorParameters: function () { return [{ type: i0.NgZone }, { type: i0.ChangeDetectorRef }]; } });