UNPKG

@web3r/flowerkit

Version:

Tree-shakable JavaScript and TypeScript utility library for frontend/browser apps: DOM, events, arrays, objects, strings, date, JSON, and network helpers (ESM/CJS, SSR-friendly).

1 lines 1.54 kB
{"version":3,"file":"index.mjs","sources":[""],"sourcesContent":["import { getDocument } from \"ssr-window\";\r\n\r\nexport type TGetScrollbarWidthArgs = Parameters<typeof getScrollbarWidth>;\r\n\r\nexport type TGetScrollbarWidthReturn = ReturnType<typeof getScrollbarWidth>;\r\n\r\n/**\r\n * Computes the width of the browser's scrollbar in pixels.\r\n *\r\n * @returns {number} Scrollbar width in pixels\r\n * @example\r\n * const scrollbarWidth = getScrollbarWidth();\r\n * console.log(scrollbarWidth); // => number\r\n */\r\nexport const getScrollbarWidth = (): number => {\r\n const doc = getDocument();\r\n const outer = doc.createElement(\"div\");\r\n outer.style.visibility = \"hidden\";\r\n outer.style.overflow = \"scroll\";\r\n outer.style.msOverflowStyle = \"scrollbar\";\r\n doc.body.appendChild(outer);\r\n\r\n const inner = doc.createElement(\"div\");\r\n outer.appendChild(inner);\r\n\r\n const w = outer.offsetWidth - inner.offsetWidth;\r\n outer.parentNode?.removeChild(outer);\r\n return w;\r\n};\r\n"],"names":["getScrollbarWidth","doc","getDocument","outer","createElement","style","visibility","overflow","msOverflowStyle","body","appendChild","inner","w","offsetWidth","parentNode","removeChild"],"mappings":";;;;;;;;GAcO,MAAMA,kBAAoBA,KAC/B,MAAMC,IAAMC,cACZ,MAAMC,MAAQF,IAAIG,cAAc,OAChCD,MAAME,MAAMC,WAAa,SACzBH,MAAME,MAAME,SAAW,SACvBJ,MAAME,MAAMG,gBAAkB,YAC9BP,IAAIQ,KAAKC,YAAYP,OAErB,MAAMQ,MAAQV,IAAIG,cAAc,OAChCD,MAAMO,YAAYC,OAElB,MAAMC,EAAIT,MAAMU,YAAcF,MAAME,YACpCV,MAAMW,YAAYC,YAAYZ,OAC9B,OAAOS"}