| 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
| 2 | const warning = (s: string) => { |
| 3 | // Todo remove debug code |
| 4 | // eslint-disable-next-line no-console |
| 5 | console.error('Log function was called before initialization', s); |
| 6 | }; |
| 7 | |
| 8 | export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'; |
| 9 | |
| 10 | export const LEVELS: Record<LogLevel, number> = { |
| 11 | trace: 0, |
| 12 | debug: 1, |
| 13 | info: 2, |
| 14 | warn: 3, |
| 15 | error: 4, |
| 16 | fatal: 5, |
| 17 | }; |
| 18 | |
| 19 | export const log: Record<keyof typeof LEVELS, typeof console.log> = { |
| 20 | trace: warning, |
| 21 | debug: warning, |
| 22 | info: warning, |
| 23 | warn: warning, |
| 24 | error: warning, |
| 25 | fatal: warning, |
| 26 | }; |
| 27 | |
| 28 | export let setLogLevel: (level: keyof typeof LEVELS | number) => void; |
| 29 | export let getConfig: () => object; |
| 30 | export let sanitizeText: (str: string) => string; |
| 31 | export let commonDb: () => object; |
| 32 | export let setupGraphViewbox: ( |
| 33 | graph: any, |
| 34 | svgElem: any, |
| 35 | padding: any, |
| 36 | useMaxWidth: boolean |
| 37 | ) => void; |
| 38 | |
| 39 | export const injectUtils = ( |
| 40 | _log: Record<keyof typeof LEVELS, typeof console.log>, |
| 41 | _setLogLevel: any, |
| 42 | _getConfig: any, |
| 43 | _sanitizeText: any, |
| 44 | _setupGraphViewbox: any, |
| 45 | _commonDb: any |
| 46 | ) => { |
| 47 | _log.info('Mermaid utils injected'); |
| 48 | log.trace = _log.trace; |
| 49 | log.debug = _log.debug; |
| 50 | log.info = _log.info; |
| 51 | log.warn = _log.warn; |
| 52 | log.error = _log.error; |
| 53 | log.fatal = _log.fatal; |
| 54 | setLogLevel = _setLogLevel; |
| 55 | getConfig = _getConfig; |
| 56 | sanitizeText = _sanitizeText; |
| 57 | setupGraphViewbox = _setupGraphViewbox; |
| 58 | commonDb = _commonDb; |
| 59 | }; |
| 60 | |