@progress/kendo-angular-common
Version:
Kendo UI for Angular - Utility Package
44 lines (43 loc) • 2.03 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { Injectable, EventEmitter } from '@angular/core';
import { isDocumentAvailable } from './is-document-available';
import * as i0 from "@angular/core";
const canCreateElement = () => isDocumentAvailable() && document.createElement;
const propName = '--kendo-scrollbar-width';
/**
* @hidden
*/
export const scrollbarWidth = () => {
let scrollbarWidth = 0;
if (canCreateElement()) {
const div = document.createElement('div');
div.style.cssText = 'overflow:scroll;overflow-x:hidden;zoom:1;clear:both;display:block';
div.innerHTML = ' ';
document.body.appendChild(div);
scrollbarWidth = div.offsetWidth - div.scrollWidth;
document.body.removeChild(div);
}
return scrollbarWidth;
};
/**
* @hidden
*/
export class ScrollbarWidthService {
changes = new EventEmitter();
constructor() {
if (typeof window !== 'undefined' && isDocumentAvailable()) {
document.body.style.setProperty(propName, `${scrollbarWidth()}px`);
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ScrollbarWidthService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ScrollbarWidthService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ScrollbarWidthService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root'
}]
}], ctorParameters: function () { return []; } });