Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #37 from PsycleResearch/fix/global-is-not-defined
Browse files Browse the repository at this point in the history
fix: Global is not defined in Vite projects
  • Loading branch information
mbaumanndev authored Oct 13, 2022
2 parents 044e8c0 + 41d2642 commit 4815f2b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export function truncate(

export function getRandomId() {
const arr = new Uint32Array(1)
global.crypto.getRandomValues(arr)
crypto.getRandomValues(arr)
return arr[0].toString(36)
}

export function getRandomNumber(min: number, max: number) {
const arr = new Uint32Array(1)
global.crypto.getRandomValues(arr)
crypto.getRandomValues(arr)
const random = arr[0]
const range = max - min
return Math.floor((random / (0xffffffff + 1)) * range + min)
Expand Down
10 changes: 5 additions & 5 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ export function usePointerPosition() {
}

useAnimationFrame(() => {
if (!global.window) return
if (!window) return

global.window.addEventListener('pointerenter', updatePosition, false)
global.window.addEventListener('pointermove', updatePosition, false)
window.addEventListener('pointerenter', updatePosition, false)
window.addEventListener('pointermove', updatePosition, false)

return () => {
global.window.removeEventListener(
window.removeEventListener(
'pointermove',
updatePosition,
false,
)
global.window.removeEventListener(
window.removeEventListener(
'pointerenter',
updatePosition,
false,
Expand Down
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export const isTouchDevice =
global.window &&
('ontouchstart' in global.window || navigator.maxTouchPoints > 0)
window && ('ontouchstart' in window || navigator.maxTouchPoints > 0)

0 comments on commit 4815f2b

Please sign in to comment.