import { DOM } from './DOM' ; import { EVT } from './EVT' ; import { store } from './Store' ; class Log { constructor ( ) { window . addEventListener ( EVT . events . destroy , ( ) => { if ( store . states . allowWork ) { this . clear ( ) ; } } ) ; } private logArea = document . createElement ( 'div' ) ; private id = 'logWrap' ; private refresh = document . createElement ( 'span' ) ; private colors = [ '#00ca19' , '#d27e00' , '#f00' ] ; private checkElement ( ) { let test = document . getElementById ( this . id ) ; if ( test === null ) { this . logArea . id = this . id ; DOM . insertToHead ( this . logArea ) ; } } public clear ( ) { this . logArea . innerHTML = '' ; } private add ( str , level , br , keepShow ) { let span = document . createElement ( 'span' ) ; if ( ! keepShow ) { span = this . refresh ; } span . innerHTML = str ; if ( level > - 1 ) { span . style . color = this . colors [ level ] ; } while ( br > 0 ) { span . appendChild ( document . createElement ( 'br' ) ) ; br -- ; } this . logArea . appendChild ( span ) ; } public log ( str , br = 1 , keepShow = true ) { this . checkElement ( ) ; this . add ( str , - 1 , br , keepShow ) ; } public success ( str , br = 1 , keepShow = true ) { this . checkElement ( ) ; this . add ( str , 0 , br , keepShow ) ; } public warning ( str , br = 1 , keepShow = true ) { this . add ( str , 1 , br , keepShow ) ; } public error ( str , br = 1 , keepShow = true ) { this . add ( str , 2 , br , keepShow ) ; } } const log = new Log ( ) ; export { log } ;