Outlook_Addin_LLM/node_modules/@fluentui/react-utilities/lib-commonjs/hooks/useScrollbarWidth.js

38 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useScrollbarWidth", {
enumerable: true,
get: function() {
return useScrollbarWidth;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const cache = new WeakMap();
function useScrollbarWidth(options) {
const { targetDocument, force } = options;
return _react.useMemo(()=>{
if (!targetDocument) {
return 0;
}
if (!force && cache.has(targetDocument)) {
return cache.get(targetDocument);
}
const outer = targetDocument.createElement('div');
outer.style.visibility = 'hidden';
outer.style.overflow = 'scroll';
const inner = targetDocument.createElement('div');
outer.appendChild(inner);
targetDocument.body.appendChild(outer);
const scrollbarWidth = outer.offsetWidth - inner.offsetWidth;
outer.remove();
cache.set(targetDocument, scrollbarWidth);
return scrollbarWidth;
}, [
targetDocument,
force
]);
}