declare global { interface Document { mozExitFullscreen : Document [ 'exitFullscreen' ] ; webkitExitFullscreen : Document [ 'exitFullscreen' ] ; msExitFullscreen : Document [ 'exitFullscreen' ] ; webkitIsFullScreen : Document [ 'fullscreen' ] ; mozFullScreen : Document [ 'fullscreen' ] ; msFullscreenElement : Document [ 'fullscreen' ] ; } interface HTMLElement { mozRequestFullScreen : Element [ 'requestFullscreen' ] ; webkitRequestFullscreen : Element [ 'requestFullscreen' ] ; msRequestFullscreen : Element [ 'requestFullscreen' ] ; } } export function inlineCss ( cssObj ) { let style = '' ; Object . keys ( cssObj ) . forEach ( ( key ) => { style += `${ key }: ${ cssObj [ key ] };` ; } ) ; return style ; } function padZero ( num , len = 2 ) { let str = String ( num ) ; const threshold = Math . pow ( 10 , len - 1 ) ; if ( num < threshold ) { while ( String ( threshold ) . length > str . length ) { str = '0' + num ; } } return str ; } const SECOND = 1000 ; const MINUTE = 60 * SECOND ; const HOUR = 60 * MINUTE ; export function formatTime ( ms ) { if ( ms <= 0 ) { return '00:00' ; } const hour = Math . floor ( ms / HOUR ) ; ms = ms % HOUR ; const minute = Math . floor ( ms / MINUTE ) ; ms = ms % MINUTE ; const second = Math . floor ( ms / SECOND ) ; if ( hour ) { return `${ padZero ( hour ) }:${ padZero ( minute ) }:${ padZero ( second ) }` ; } return `${ padZero ( minute ) }:${ padZero ( second ) }` ; } export function openFullscreen ( el ) { if ( el . requestFullscreen ) { return el . requestFullscreen ( ) ; } else if ( el . mozRequestFullScreen ) { return el . mozRequestFullScreen ( ) ; } else if ( el . webkitRequestFullscreen ) { return el . webkitRequestFullscreen ( ) ; } else if ( el . msRequestFullscreen ) { return el . msRequestFullscreen ( ) ; } } export function exitFullscreen ( ) { if ( document . exitFullscreen ) { return document . exitFullscreen ( ) ; } else if ( document . mozExitFullscreen ) { return document . mozExitFullscreen ( ) ; } else if ( document . webkitExitFullscreen ) { return document . webkitExitFullscreen ( ) ; } else if ( document . msExitFullscreen ) { return document . msExitFullscreen ( ) ; } } export function isFullscreen ( ) { return ( document . fullscreen || document . webkitIsFullScreen || document . mozFullScreen || document . msFullscreenElement ) ; } export function onFullscreenChange ( handler ) { document . addEventListener ( 'fullscreenchange' , handler ) ; document . addEventListener ( 'webkitfullscreenchange' , handler ) ; document . addEventListener ( 'mozfullscreenchange' , handler ) ; document . addEventListener ( 'MSFullscreenChange' , handler ) ; return ( ) => { document . removeEventListener ( 'fullscreenchange' , handler ) ; document . removeEventListener ( 'webkitfullscreenchange' , handler ) ; document . removeEventListener ( 'mozfullscreenchange' , handler ) ; document . removeEventListener ( 'MSFullscreenChange' , handler ) ; } ; } export function typeOf ( obj ) { const toString = Object . prototype . toString ; const map = { '[object Boolean]' : 'boolean' , '[object Number]' : 'number' , '[object String]' : 'string' , '[object Function]' : 'function' , '[object Array]' : 'array' , '[object Date]' : 'date' , '[object RegExp]' : 'regExp' , '[object Undefined]' : 'undefined' , '[object Null]' : 'null' , '[object Object]' : 'object' , } ; return map [ toString . call ( obj ) ] ; }