1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import * as env from './environment.js'
|
8 | import * as common from './logging.common.js'
|
9 |
|
10 | export { BOLD, UNBOLD, BLUE, GREY, GREEN, RED, PURPLE, ORANGE, UNCOLOR } from './logging.common.js'
|
11 |
|
12 | const _nodeStyleMap = {
|
13 | [common.BOLD]: '\u001b[1m',
|
14 | [common.UNBOLD]: '\u001b[2m',
|
15 | [common.BLUE]: '\x1b[34m',
|
16 | [common.GREEN]: '\x1b[32m',
|
17 | [common.GREY]: '\u001b[37m',
|
18 | [common.RED]: '\x1b[31m',
|
19 | [common.PURPLE]: '\x1b[35m',
|
20 | [common.ORANGE]: '\x1b[38;5;208m',
|
21 | [common.UNCOLOR]: '\x1b[0m'
|
22 | }
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | const computeNodeLoggingArgs = (args) => {
|
30 | if (args.length === 1 && args[0]?.constructor === Function) {
|
31 | args = ( (args)[0]())
|
32 | }
|
33 | const strBuilder = []
|
34 | const logArgs = []
|
35 |
|
36 | let i = 0
|
37 | for (; i < args.length; i++) {
|
38 | const arg = args[i]
|
39 |
|
40 | const style = _nodeStyleMap[arg]
|
41 | if (style !== undefined) {
|
42 | strBuilder.push(style)
|
43 | } else {
|
44 | if (arg === undefined) {
|
45 | break
|
46 | } else if (arg.constructor === String || arg.constructor === Number) {
|
47 | strBuilder.push(arg)
|
48 | } else {
|
49 | break
|
50 | }
|
51 | }
|
52 | }
|
53 | if (i > 0) {
|
54 |
|
55 | strBuilder.push('\x1b[0m')
|
56 | logArgs.push(strBuilder.join(''))
|
57 | }
|
58 |
|
59 | for (; i < args.length; i++) {
|
60 | const arg = args[i]
|
61 | if (!(arg instanceof Symbol)) {
|
62 | logArgs.push(arg)
|
63 | }
|
64 | }
|
65 | return logArgs
|
66 | }
|
67 |
|
68 |
|
69 |
|
70 | const computeLoggingArgs = env.supportsColor
|
71 | ? computeNodeLoggingArgs
|
72 | : common.computeNoColorLoggingArgs
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | export const print = (...args) => {
|
79 | console.log(...computeLoggingArgs(args))
|
80 | }
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | export const warn = (...args) => {
|
87 | console.warn(...computeLoggingArgs(args))
|
88 | }
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | export const printError = (err) => {
|
96 | console.error(err)
|
97 | }
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | export const printImg = (_url, _height) => {
|
106 |
|
107 | }
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | export const printImgBase64 = (base64, height) =>
|
116 | printImg(`data:image/gif;base64,${base64}`, height)
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | export const group = (...args) => {
|
123 | console.group(...computeLoggingArgs(args))
|
124 | }
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | export const groupCollapsed = (...args) => {
|
131 | console.groupCollapsed(...computeLoggingArgs(args))
|
132 | }
|
133 |
|
134 |
|
135 | export const groupEnd = () => {
|
136 | console.groupEnd()
|
137 | }
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | export const printDom = (_createNode) => {}
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | export const printCanvas = (canvas, height) =>
|
151 | printImg(canvas.toDataURL(), height)
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | export const createVConsole = (_dom) => {}
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | export const createModuleLogger = (moduleName) => common.createModuleLogger(print, moduleName)
|