UNPKG

@technobuddha/library

Version:
34 lines (33 loc) 1.42 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.measureWindow = exports.measure = exports.getScrollbarSize = void 0; function getScrollbarSize() { var node = document.createElement('div'); node.setAttribute('style', 'width: 100px; height: 100px; position: absolute; top: -1000000px; overflow: scroll;'); document.body.appendChild(node); var scrollbarWidth = node.offsetWidth - node.clientWidth; var scrollbarHeight = node.offsetHeight - node.clientHeight; document.body.removeChild(node); return { scrollbarWidth: scrollbarWidth, scrollbarHeight: scrollbarHeight }; } exports.getScrollbarSize = getScrollbarSize; function measure(element) { return __assign({ width: element.offsetWidth, height: element.offsetHeight }, getScrollbarSize()); } exports.measure = measure; function measureWindow() { return __assign({ width: window.innerWidth, height: window.innerHeight }, getScrollbarSize()); } exports.measureWindow = measureWindow; exports.default = measure;