commit 9f1c82f4d38b9a2ddc38812d74c4019c930e8566 Author: Valentin Silytuin Date: Mon Jun 19 16:01:37 2023 +0400 v1.0.0 diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b0183a2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..4d6be20 --- /dev/null +++ b/.gitignore @@ -0,0 +1,103 @@ +# Настройки редакторов + +.idea +.vscode + +# Node.js + +node_modules + +# Yarn (https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored) + +**/.pnp.* +**/.yarn/* +!**/.yarn/patches +!**/.yarn/plugins +!**/.yarn/releases +!**/.yarn/sdks +!**/.yarn/versions + +# ESLint + +.eslintcache + +# Stylelint + +.stylelintcache + +# Composer + +vendor + +# https://github.com/github/gitignore/blob/master/Global/Linux.gitignore + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# https://github.com/github/gitignore/blob/master/Global/macOS.gitignore + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# https://github.com/github/gitignore/blob/master/Global/Windows.gitignore + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..6874d55 --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +.editorconfig +.prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..9bcd429 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "printWidth": 120, + "tabWidth": 4, + "singleQuote": true, + "bracketSpacing": false +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..a79b494 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# get-scrollbar-width + +```js +import getScrollbarWidth from '@advdominion/get-scrollbar-width'; + +console.log(getScrollbarWidth()); +``` diff --git a/index.js b/index.js new file mode 100644 index 0000000..0ebd844 --- /dev/null +++ b/index.js @@ -0,0 +1,17 @@ +export default () => { + if (document.body.clientHeight > window.innerHeight) { + const outer = document.createElement('div'); + outer.style.visibility = 'hidden'; + outer.style.width = '100px'; + document.body.append(outer); + const widthNoScroll = outer.offsetWidth; + outer.style.overflow = 'scroll'; + const inner = document.createElement('div'); + inner.style.width = '100%'; + outer.append(inner); + const widthWithScroll = inner.offsetWidth; + outer.remove(); + return widthNoScroll - widthWithScroll; + } + return 0; +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..48050a1 --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "@advdominion/get-scrollbar-width", + "version": "1.0.0", + "type": "module", + "main": "index.js", + "repository": { + "type": "git", + "url": "https://gitea.optiweb.ru/public/get-scrollbar-width.git" + }, + "license": "MIT" +}