Initial commit

This commit is contained in:
2025-03-07 19:22:02 +01:00
commit 4a98255d83
55743 changed files with 5280367 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
import * as React from 'react';
const cache = new WeakMap();
/**
* @returns The width in pixels of the scrollbar in the user agent
*/ export 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
]);
}