All files / Rindu/utils fullScreen.ts

11.53% Statements 3/26
0% Branches 0/27
0% Functions 0/3
13.04% Lines 3/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                        2x                 2x                           2x                        
declare global {
  interface Document {
    mozCancelFullScreen?: () => Promise<void>;
    msExitFullscreen?: () => Promise<void>;
    webkitExitFullscreen?: () => Promise<void>;
    mozFullScreenElement?: Element;
    msFullscreenElement?: Element;
    webkitFullscreenElement?: Element;
    webkitFullscreenEnabled?: boolean;
    mozFullScreenEnabled?: boolean;
    msFullscreenEnabled?: boolean;
  }
 
  interface HTMLElement {
    msRequestFullscreen?: () => Promise<void>;
    mozRequestFullScreen?: () => Promise<void>;
    webkitRequestFullscreen?: () => Promise<void>;
  }
}
 
export function isFullScreen(): boolean {
  return Boolean(
    document.fullscreenElement ||
      document.webkitFullscreenElement ||
      document.mozFullScreenElement ||
      document.msFullscreenElement
  );
}
 
export function requestFullScreen(el: HTMLElement): void {
  Iif (isFullScreen()) return;
  Iif (el === undefined) el = document.documentElement;
  if (document.fullscreenEnabled) {
    el.requestFullscreen();
  } else if (document.webkitFullscreenEnabled && el.webkitRequestFullscreen) {
    el.webkitRequestFullscreen();
  } else if (document.mozFullScreenEnabled && el.mozRequestFullScreen) {
    el.mozRequestFullScreen();
  } else Iif (document.msFullscreenEnabled && el.msRequestFullscreen) {
    el.msRequestFullscreen();
  }
}
 
export function exitFullScreen(): void {
  Iif (!isFullScreen()) return;
  if (document.exitFullscreen) {
    document.exitFullscreen();
  } else if (document.webkitExitFullscreen) {
    document.webkitExitFullscreen();
  } else if (document.mozCancelFullScreen) {
    document.mozCancelFullScreen();
  } else Iif (document.msExitFullscreen) {
    document.msExitFullscreen();
  }
}