UNPKG

@progress/kendo-angular-treelist

Version:

Kendo UI TreeList for Angular - Display hierarchical data in an Angular tree grid view that supports sorting, filtering, paging, and much more.

86 lines (85 loc) 3.83 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 div = document.createElement("div"); div.style.cssText = "overflow:scroll;zoom:1;clear:both;display:block;width:100px;visibility:hidden;position:absolute;left:-10000px;direction:rtl;"; const innerDiv = document.createElement('div'); innerDiv.style.width = '200px'; innerDiv.style.height = '1px'; div.appendChild(innerDiv); document.body.appendChild(div); const initial = div.scrollLeft; div.scrollLeft = -1; cachedRtlScrollLeft = div.scrollLeft < 0 ? div.scrollLeft : initial; document.body.removeChild(div); } 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') { 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 }]; } });