Skip to content

Commit

Permalink
feat: return results of browser helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
verekia committed Oct 17, 2024
1 parent 14f09d3 commit 49ce16c
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions packages/core/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,37 @@

export const enterFullscreen = () => {
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen()
} else if ((document.documentElement as any).mozRequestFullScreen) {
;(document.documentElement as any).mozRequestFullScreen()
} else if ((document.documentElement as any).webkitRequestFullscreen) {
;(document.documentElement as any).webkitRequestFullscreen()
} else if ((document.documentElement as any).msRequestFullscreen) {
;(document.documentElement as any).msRequestFullscreen()
return document.documentElement.requestFullscreen()
}

if ((document.documentElement as any).mozRequestFullScreen) {
return (document.documentElement as any).mozRequestFullScreen()
}

if ((document.documentElement as any).webkitRequestFullscreen) {
return (document.documentElement as any).webkitRequestFullscreen()
}

if ((document.documentElement as any).msRequestFullscreen) {
return (document.documentElement as any).msRequestFullscreen()
}
}

export const exitFullscreen = () => {
if (document.exitFullscreen) {
document.exitFullscreen()
} else if ((document as any).mozCancelFullScreen) {
;(document as any).mozCancelFullScreen()
} else if ((document as any).webkitExitFullscreen) {
;(document as any).webkitExitFullscreen()
} else if ((document as any).msExitFullscreen) {
;(document as any).msExitFullscreen()
return document.exitFullscreen()
}

if ((document as any).mozCancelFullScreen) {
return (document as any).mozCancelFullScreen()
}

if ((document as any).webkitExitFullscreen) {
return (document as any).webkitExitFullscreen()
}

if ((document as any).msExitFullscreen) {
return (document as any).msExitFullscreen()
}
}

Expand All @@ -39,13 +51,13 @@ export const lockOrientation = (type: OrientationLockType) => {
return
}
if ('lock' in screen.orientation) {
;(screen.orientation.lock as any)(type)
return (screen.orientation.lock as any)(type)
}
}

export const unlockOrientation = () => {
if ('unlock' in screen.orientation) {
screen.orientation.unlock()
return screen.orientation.unlock()
}
}

Expand All @@ -56,7 +68,7 @@ export const lockKeys = (keys: string[]) => {
'lock' in (navigator.keyboard as any) &&
(navigator.keyboard as any).lock
) {
;((navigator.keyboard as any).lock as any)(keys)
return ((navigator.keyboard as any).lock as any)(keys)
}
}

Expand All @@ -67,7 +79,7 @@ export const unlockKeys = () => {
'unlock' in (navigator.keyboard as any) &&
(navigator.keyboard as any).unlock
) {
;((navigator.keyboard as any).unlock as any)()
return ((navigator.keyboard as any).unlock as any)()
}
}

Expand Down

0 comments on commit 49ce16c

Please sign in to comment.