UNPKG

@cairn214/fluent-editor

Version:

A rich text editor based on Quill 2.0, which extends rich modules and formats on the basis of Quill. It's powerful and out-of-the-box.

48 lines (47 loc) 1.83 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); let scrollBarWidth; function getScrollBarWidth({ target = document.body } = {}) { var _a; if (scrollBarWidth !== void 0) return scrollBarWidth; const outer = document.createElement("div"); outer.className = "scroll__wrap"; outer.style.visibility = "hidden"; outer.style.width = "100px"; outer.style.position = "absolute"; outer.style.top = "-9999px"; target.appendChild(outer); const widthNoScroll = outer.offsetWidth; outer.style.overflow = "scroll"; const inner = document.createElement("div"); inner.style.width = "100%"; outer.appendChild(inner); const widthWithScroll = inner.offsetWidth; (_a = outer.parentNode) == null ? void 0 : _a.removeChild(outer); scrollBarWidth = widthNoScroll - widthWithScroll; return scrollBarWidth; } function lockScroll({ target = document.body } = {}) { let scrollBarWidth2 = 0; let originWidth = "0"; const clockClass = "scroll--lock"; const cleanLock = () => { target && (target.style.width = originWidth); target.classList.remove(clockClass); }; const hasHiddenClass = target.classList.contains(clockClass); if (!hasHiddenClass) { originWidth = target.style.width; } scrollBarWidth2 = getScrollBarWidth({ target }); const hasOverflow = (target === document.body ? document.documentElement : target).clientHeight < target.scrollHeight; const overflowY = window.getComputedStyle(target).overflowY; if (scrollBarWidth2 > 0 && (hasOverflow || overflowY === "scroll") && !hasHiddenClass) { target.style.width = `calc(100% - ${scrollBarWidth2}px)`; } target.classList.add(clockClass); return cleanLock; } exports.getScrollBarWidth = getScrollBarWidth; exports.lockScroll = lockScroll; //# sourceMappingURL=scroll-lock.cjs.js.map