Skip to content

Commit

Permalink
fixed "document is not defined" issue when building via vite-ssg
Browse files Browse the repository at this point in the history
  • Loading branch information
kolirt committed Dec 20, 2023
1 parent a105ae4 commit 5729286
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 18 additions & 14 deletions lib/utils/getScrollbarWidth.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
export function getScrollbarWidth(): number {
// Creating invisible container
const outer = document.createElement('div')
outer.style.visibility = 'hidden'
outer.style.overflow = 'scroll' // forcing scrollbar to appear
// outer.style.msOverflowStyle = 'scrollbar' // needed for WinJS apps
document.body.appendChild(outer)
try {
// Creating invisible container
const outer = document.createElement('div')
outer.style.visibility = 'hidden'
outer.style.overflow = 'scroll' // forcing scrollbar to appear
// outer.style.msOverflowStyle = 'scrollbar' // needed for WinJS apps
document.body.appendChild(outer)

// Creating inner element and placing it in the container
const inner = document.createElement('div')
outer.appendChild(inner)
// Creating inner element and placing it in the container
const inner = document.createElement('div')
outer.appendChild(inner)

// Calculating difference between container's full width and the child width
const scrollbarWidth = outer.offsetWidth - inner.offsetWidth
// Calculating difference between container's full width and the child width
const scrollbarWidth = outer.offsetWidth - inner.offsetWidth

// Removing temporary elements from the DOM
outer.parentNode?.removeChild(outer)
// Removing temporary elements from the DOM
outer.parentNode?.removeChild(outer)

return scrollbarWidth
return scrollbarWidth
} catch (e) {
return 0
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kolirt/vue-modal",
"version": "0.0.15",
"version": "0.0.16",
"description": "Simple Vue3 modal package",
"author": "kolirt",
"license": "MIT",
Expand Down

0 comments on commit 5729286

Please sign in to comment.