import { KeepTrackApi , SatMath , SatObject , SettingsManager } from './keepTrackTypes' ; import { html } from './templateLiterals' ; declare global { interface Window { settingsManager : SettingsManager ; jQuery : unknown ; $ : unknown ; gremlins : any ; randomizer : any ; keepTrackApi : KeepTrackApi ; dataLayer : any ; _numeric : any ; satellite : SatMath ; M : any ; } } export const register = ( params ) => { if ( typeof keepTrackApi . callbacks [ params . method ] !== 'undefined' ) { keepTrackApi . callbacks [ params . method ] . push ( { name : params . cbName , cb : params . cb } ) ; } else { throw new Error ( `Invalid callback "${ params . method }"!` ) ; } } ; export const unregister = ( params ) => { if ( typeof keepTrackApi . callbacks [ params . method ] !== 'undefined' ) { for ( let i = 0 ; i < keepTrackApi . callbacks [ params . method ] . length ; i ++ ) { if ( keepTrackApi . callbacks [ params . method ] [ i ] . name == params . cbName ) { keepTrackApi . callbacks [ params . method ] . splice ( i , 1 ) ; return ; } } throw new Error ( `Callback "${ params . cbName } not found"!` ) ; } else { throw new Error ( `Invalid callback "${ params . method }"!` ) ; } } ; export const isThisJest = ( ) => typeof process !== 'undefined' ; export const keepTrackApi = { html : html , register : register , unregister : unregister , callbacks : { selectSatData : [ ] , updateSelectBox : [ ] , onCruncherReady : [ ] , onCruncherMessage : [ ] , uiManagerInit : [ ] , uiManagerOnReady : [ ] , bottomMenuClick : [ ] , hideSideMenus : [ ] , nightToggle : [ ] , orbitManagerInit : [ ] , adviceReady : [ ] , drawManagerLoadScene : [ ] , drawOptionalScenery : [ ] , updateLoop : [ ] , rmbMenuActions : [ ] , rightBtnMenuAdd : [ ] , updateDateTime : [ ] , uiManagerFinal : [ ] , loadCatalog : [ ] , resetSensor : [ ] , setSensor : [ ] , onDrawLoopComplete : [ ] , } , methods : { selectSatData : ( sat , satId ) => { keepTrackApi . callbacks . selectSatData . forEach ( ( cb ) => cb . cb ( sat , satId ) ) ; } , updateSelectBox : ( sat ) => { keepTrackApi . callbacks . updateSelectBox . forEach ( ( cb ) => cb . cb ( sat ) ) ; } , onCruncherReady : ( ) => { keepTrackApi . callbacks . onCruncherReady . forEach ( ( cb ) => cb . cb ( ) ) ; } , onCruncherMessage : ( ) => { keepTrackApi . callbacks . onCruncherMessage . forEach ( ( cb ) => cb . cb ( ) ) ; } , uiManagerInit : ( ) => { keepTrackApi . callbacks . uiManagerInit . forEach ( ( cb ) => cb . cb ( ) ) ; } , uiManagerOnReady : ( ) => { keepTrackApi . callbacks . uiManagerOnReady . forEach ( ( cb ) => cb . cb ( ) ) ; } , bottomMenuClick : ( iconName ) => { keepTrackApi . callbacks . bottomMenuClick . forEach ( ( cb ) => cb . cb ( iconName ) ) ; } , hideSideMenus : ( ) => { keepTrackApi . callbacks . hideSideMenus . forEach ( ( cb ) => cb . cb ( ) ) ; } , nightToggle : ( gl , nightTexture , texture ) => { keepTrackApi . callbacks . nightToggle . forEach ( ( cb ) => cb . cb ( gl , nightTexture , texture ) ) ; } , orbitManagerInit : ( ) => { keepTrackApi . callbacks . orbitManagerInit . forEach ( ( cb ) => cb . cb ( ) ) ; } , adviceReady : ( ) => { keepTrackApi . callbacks . adviceReady . forEach ( ( cb ) => cb . cb ( ) ) ; } , drawManagerLoadScene : ( ) => { keepTrackApi . callbacks . drawManagerLoadScene . forEach ( ( cb ) => cb . cb ( ) ) ; } , drawOptionalScenery : ( ) => { keepTrackApi . callbacks . drawOptionalScenery . forEach ( ( cb ) => cb . cb ( ) ) ; } , updateLoop : ( ) => { keepTrackApi . callbacks . updateLoop . forEach ( ( cb ) => cb . cb ( ) ) ; } , rmbMenuActions : ( menuName ) => { keepTrackApi . callbacks . rmbMenuActions . forEach ( ( cb ) => cb . cb ( menuName ) ) ; } , rightBtnMenuAdd : ( ) => { keepTrackApi . callbacks . rightBtnMenuAdd . forEach ( ( cb ) => cb . cb ( ) ) ; } , updateDateTime : ( date ) => { keepTrackApi . callbacks . updateDateTime . forEach ( ( cb ) => cb . cb ( date ) ) ; } , uiManagerFinal : ( ) => { keepTrackApi . callbacks . uiManagerFinal . forEach ( ( cb ) => cb . cb ( ) ) ; } , loadCatalog : async ( ) : Promise < SatObject [ ] > => keepTrackApi . callbacks . loadCatalog [ 0 ] . cb ( ) , resetSensor : ( ) => { keepTrackApi . callbacks . resetSensor . forEach ( ( cb ) => cb . cb ( ) ) ; } , setSensor : ( sensor , id ) => { keepTrackApi . callbacks . setSensor . forEach ( ( cb ) => cb . cb ( sensor , id ) ) ; } , onDrawLoopComplete : ( ) => { keepTrackApi . callbacks . onDrawLoopComplete . forEach ( ( cb ) => cb . cb ( ) ) ; } , } , programs : < any > { } , } ; if ( ! window . keepTrackApi ) window . keepTrackApi = keepTrackApi ;