@mks2508/better-logger 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/bun.lock +333 -0
  2. package/dist/Logger.d.ts +704 -0
  3. package/dist/Logger.d.ts.map +1 -0
  4. package/dist/ScopedLogger.d.ts +310 -0
  5. package/dist/ScopedLogger.d.ts.map +1 -0
  6. package/dist/chunks/Logger-B7L-ujY4.js +3503 -0
  7. package/dist/chunks/Logger-B7L-ujY4.js.map +1 -0
  8. package/dist/chunks/Logger-DzU_c5sX.js +2 -0
  9. package/dist/chunks/Logger-DzU_c5sX.js.map +1 -0
  10. package/dist/chunks/RemoteLogHandler-CjWpWZGl.js +33 -0
  11. package/dist/chunks/RemoteLogHandler-CjWpWZGl.js.map +1 -0
  12. package/dist/chunks/RemoteLogHandler-ymkQ97xl.js +2 -0
  13. package/dist/chunks/RemoteLogHandler-ymkQ97xl.js.map +1 -0
  14. package/dist/chunks/ScopedLogger-BY3-E8Ov.js +2 -0
  15. package/dist/chunks/ScopedLogger-BY3-E8Ov.js.map +1 -0
  16. package/dist/chunks/ScopedLogger-D-RbiFZn.js +361 -0
  17. package/dist/chunks/ScopedLogger-D-RbiFZn.js.map +1 -0
  18. package/dist/chunks/environment-Ba5kShbx.js +4 -0
  19. package/dist/chunks/environment-Ba5kShbx.js.map +1 -0
  20. package/dist/chunks/environment-TI2ByCPT.js +1209 -0
  21. package/dist/chunks/environment-TI2ByCPT.js.map +1 -0
  22. package/dist/chunks/formatting-Blwy-f0W.js +2 -0
  23. package/dist/chunks/formatting-Blwy-f0W.js.map +1 -0
  24. package/dist/chunks/formatting-CuNUqGks.js +380 -0
  25. package/dist/chunks/formatting-CuNUqGks.js.map +1 -0
  26. package/dist/cli/CommandProcessor.d.ts +100 -0
  27. package/dist/cli/CommandProcessor.d.ts.map +1 -0
  28. package/dist/cli/commands/ConfigCommand.d.ts +14 -0
  29. package/dist/cli/commands/ConfigCommand.d.ts.map +1 -0
  30. package/dist/cli/commands/ExportCommand.d.ts +48 -0
  31. package/dist/cli/commands/ExportCommand.d.ts.map +1 -0
  32. package/dist/cli/commands/HistoryCommand.d.ts +47 -0
  33. package/dist/cli/commands/HistoryCommand.d.ts.map +1 -0
  34. package/dist/cli/commands/StatusCommand.d.ts +30 -0
  35. package/dist/cli/commands/StatusCommand.d.ts.map +1 -0
  36. package/dist/cli/commands/ThemeCommand.d.ts +30 -0
  37. package/dist/cli/commands/ThemeCommand.d.ts.map +1 -0
  38. package/dist/cli/help.d.ts +12 -0
  39. package/dist/cli/help.d.ts.map +1 -0
  40. package/dist/cli/index.d.ts +15 -0
  41. package/dist/cli/index.d.ts.map +1 -0
  42. package/dist/constants.d.ts +227 -0
  43. package/dist/constants.d.ts.map +1 -0
  44. package/dist/core.cjs +2 -0
  45. package/dist/core.cjs.map +1 -0
  46. package/dist/core.d.ts +127 -0
  47. package/dist/core.d.ts.map +1 -0
  48. package/dist/core.js +291 -0
  49. package/dist/core.js.map +1 -0
  50. package/dist/example.d.ts +18 -0
  51. package/dist/example.d.ts.map +1 -0
  52. package/dist/exports-module.d.ts +196 -0
  53. package/dist/exports-module.d.ts.map +1 -0
  54. package/dist/exports.cjs +2 -0
  55. package/dist/exports.cjs.map +1 -0
  56. package/dist/exports.js +238 -0
  57. package/dist/exports.js.map +1 -0
  58. package/dist/handlers/AnalyticsLogHandler.d.ts +8 -0
  59. package/dist/handlers/AnalyticsLogHandler.d.ts.map +1 -0
  60. package/dist/handlers/ExportLogHandler.d.ts +100 -0
  61. package/dist/handlers/ExportLogHandler.d.ts.map +1 -0
  62. package/dist/handlers/FileLogHandler.d.ts +33 -0
  63. package/dist/handlers/FileLogHandler.d.ts.map +1 -0
  64. package/dist/handlers/RemoteLogHandler.d.ts +11 -0
  65. package/dist/handlers/RemoteLogHandler.d.ts.map +1 -0
  66. package/dist/handlers/index.d.ts +8 -0
  67. package/dist/handlers/index.d.ts.map +1 -0
  68. package/dist/index.cjs +2 -0
  69. package/dist/index.cjs.map +1 -0
  70. package/dist/index.d.ts +124 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +247 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/main.d.ts +2 -0
  75. package/dist/main.d.ts.map +1 -0
  76. package/dist/styling/LogStyleBuilder.d.ts +146 -0
  77. package/dist/styling/LogStyleBuilder.d.ts.map +1 -0
  78. package/dist/styling/SemanticStyles.d.ts +178 -0
  79. package/dist/styling/SemanticStyles.d.ts.map +1 -0
  80. package/dist/styling/SmartPresets.d.ts +22 -0
  81. package/dist/styling/SmartPresets.d.ts.map +1 -0
  82. package/dist/styling/StyleBuilder.d.ts +140 -0
  83. package/dist/styling/StyleBuilder.d.ts.map +1 -0
  84. package/dist/styling/banners.d.ts +42 -0
  85. package/dist/styling/banners.d.ts.map +1 -0
  86. package/dist/styling/index.d.ts +10 -0
  87. package/dist/styling/index.d.ts.map +1 -0
  88. package/dist/styling/themes.d.ts +7 -0
  89. package/dist/styling/themes.d.ts.map +1 -0
  90. package/dist/styling-module.d.ts +178 -0
  91. package/dist/styling-module.d.ts.map +1 -0
  92. package/dist/styling.cjs +2 -0
  93. package/dist/styling.cjs.map +1 -0
  94. package/dist/styling.js +146 -0
  95. package/dist/styling.js.map +1 -0
  96. package/dist/terminal/terminal-renderer.d.ts +63 -0
  97. package/dist/terminal/terminal-renderer.d.ts.map +1 -0
  98. package/dist/types/core.d.ts +234 -0
  99. package/dist/types/core.d.ts.map +1 -0
  100. package/dist/types/handlers.d.ts +85 -0
  101. package/dist/types/handlers.d.ts.map +1 -0
  102. package/dist/types/index.d.ts +7 -0
  103. package/dist/types/index.d.ts.map +1 -0
  104. package/dist/utils/adapter.d.ts +48 -0
  105. package/dist/utils/adapter.d.ts.map +1 -0
  106. package/dist/utils/ansi-colors.d.ts +156 -0
  107. package/dist/utils/ansi-colors.d.ts.map +1 -0
  108. package/dist/utils/environment-detector.d.ts +35 -0
  109. package/dist/utils/environment-detector.d.ts.map +1 -0
  110. package/dist/utils/environment.d.ts +47 -0
  111. package/dist/utils/environment.d.ts.map +1 -0
  112. package/dist/utils/formatting.d.ts +58 -0
  113. package/dist/utils/formatting.d.ts.map +1 -0
  114. package/dist/utils/index.d.ts +8 -0
  115. package/dist/utils/index.d.ts.map +1 -0
  116. package/dist/utils/opentui-detection.d.ts +34 -0
  117. package/dist/utils/opentui-detection.d.ts.map +1 -0
  118. package/dist/utils/output.d.ts +46 -0
  119. package/dist/utils/output.d.ts.map +1 -0
  120. package/dist/utils/stackTrace.d.ts +6 -0
  121. package/dist/utils/stackTrace.d.ts.map +1 -0
  122. package/dist/utils/timestamps.d.ts +20 -0
  123. package/dist/utils/timestamps.d.ts.map +1 -0
  124. package/dist/vite.svg +1 -0
  125. package/package.json +1 -1
@@ -0,0 +1,1209 @@
1
+ function isMinifiedFile(filename) {
2
+ const minifiedPatterns = [
3
+ /\.min\.js$/,
4
+ /\.bundle\.js$/,
5
+ /\.chunk\.js$/,
6
+ /-[\w\d]{8,}\.js$/,
7
+ // Hash-based filenames
8
+ /Logger-[A-Za-z0-9]+\.js$/,
9
+ // Logger bundle files
10
+ /node_modules/,
11
+ /dist\//,
12
+ /build\//,
13
+ /\.mjs$/
14
+ ];
15
+ return minifiedPatterns.some((pattern) => pattern.test(filename));
16
+ }
17
+ function extractCleanFilename(fullPath) {
18
+ const filename = fullPath.split(/[/\\]/).pop() || fullPath;
19
+ return filename.replace(/\.min\.js$/, ".js").replace(/\.bundle\.js$/, ".js").replace(/\.chunk\.js$/, ".js").replace(/-[\w\d]{8,}\.js$/, ".js").replace(/Logger-[A-Za-z0-9]+\.js$/, "logger.ts");
20
+ }
21
+ function parseStackTrace() {
22
+ try {
23
+ const stack = new Error().stack;
24
+ if (!stack) {
25
+ return null;
26
+ }
27
+ const lines = stack.split("\n").filter((line) => line.trim());
28
+ for (let i = 1; i < lines.length; i++) {
29
+ const line = lines[i];
30
+ if (!line) {
31
+ continue;
32
+ }
33
+ if (line.includes("parseStackTrace") || line.includes("Logger.") || line.includes(".log(") || line.includes("createStyledOutput")) {
34
+ continue;
35
+ }
36
+ let match;
37
+ const chromeMatch = line.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);
38
+ if (chromeMatch) {
39
+ const filename = chromeMatch[2];
40
+ if (filename && isMinifiedFile(filename)) {
41
+ continue;
42
+ }
43
+ match = chromeMatch;
44
+ } else {
45
+ const firefoxMatch = line.match(/(.+?)@(.+?):(\d+):(\d+)$/);
46
+ if (firefoxMatch) {
47
+ const filename = firefoxMatch[2];
48
+ if (filename && isMinifiedFile(filename)) {
49
+ continue;
50
+ }
51
+ match = firefoxMatch;
52
+ } else {
53
+ const safariMatch = line.match(/(\S+)?@(.+?):(\d+):(\d+)$/);
54
+ if (safariMatch) {
55
+ const filename = safariMatch[2];
56
+ if (filename && isMinifiedFile(filename)) {
57
+ continue;
58
+ }
59
+ match = safariMatch;
60
+ }
61
+ }
62
+ }
63
+ if (!match) {
64
+ continue;
65
+ }
66
+ const [, functionName, file, lineStr, columnStr] = match;
67
+ if (!file) {
68
+ continue;
69
+ }
70
+ const cleanFileName = extractCleanFilename(file).split("?")[0];
71
+ if (!cleanFileName) {
72
+ continue;
73
+ }
74
+ const lineNum = lineStr ? parseInt(lineStr, 10) : 0;
75
+ const columnNum = columnStr ? parseInt(columnStr, 10) : 0;
76
+ const cleanFunction = functionName && functionName.trim() ? functionName.trim() : void 0;
77
+ return {
78
+ file: cleanFileName ? cleanFileName : "unknown",
79
+ line: lineNum,
80
+ column: columnNum,
81
+ function: cleanFunction
82
+ };
83
+ }
84
+ return null;
85
+ } catch {
86
+ return null;
87
+ }
88
+ }
89
+ const DEFAULT_CONFIG = {
90
+ verbosity: "info",
91
+ enableColors: true,
92
+ enableTimestamps: true,
93
+ enableStackTrace: true,
94
+ theme: "default",
95
+ bannerType: "simple",
96
+ bufferSize: 1e3,
97
+ autoDetectTheme: true,
98
+ outputFormat: "auto"
99
+ };
100
+ const LEVEL_STYLES = {
101
+ debug: {
102
+ emoji: "🔍",
103
+ label: "DEBUG",
104
+ background: "linear-gradient(90deg, #6c757d, #495057)",
105
+ color: "#ffffff",
106
+ border: "1px solid #6c757d",
107
+ shadow: "0 2px 4px rgba(108, 117, 125, 0.3)"
108
+ },
109
+ info: {
110
+ emoji: "ℹ️",
111
+ label: "INFO",
112
+ background: "linear-gradient(90deg, #007bff, #0056b3)",
113
+ color: "#ffffff",
114
+ border: "1px solid #007bff",
115
+ shadow: "0 2px 4px rgba(0, 123, 255, 0.3)"
116
+ },
117
+ warn: {
118
+ emoji: "⚠️",
119
+ label: "WARN",
120
+ background: "linear-gradient(90deg, #ffc107, #e0a800)",
121
+ color: "#000000",
122
+ border: "1px solid #ffc107",
123
+ shadow: "0 2px 4px rgba(255, 193, 7, 0.3)"
124
+ },
125
+ error: {
126
+ emoji: "❌",
127
+ label: "ERROR",
128
+ background: "linear-gradient(90deg, #dc3545, #c82333)",
129
+ color: "#ffffff",
130
+ border: "1px solid #dc3545",
131
+ shadow: "0 2px 4px rgba(220, 53, 69, 0.3)"
132
+ },
133
+ critical: {
134
+ emoji: "🚨",
135
+ label: "CRITICAL",
136
+ background: "linear-gradient(90deg, #8B0000, #FF0000)",
137
+ color: "#ffffff",
138
+ border: "2px solid #FF0000",
139
+ shadow: "0 4px 8px rgba(255, 0, 0, 0.4)"
140
+ },
141
+ success: {
142
+ emoji: "✅",
143
+ label: "SUCCESS",
144
+ background: "linear-gradient(90deg, #28a745, #1e7e34)",
145
+ color: "#ffffff",
146
+ border: "1px solid #28a745",
147
+ shadow: "0 2px 4px rgba(40, 167, 69, 0.3)"
148
+ }
149
+ };
150
+ const BUFFER_LIMITS = {
151
+ MIN_SIZE: 50,
152
+ DEFAULT_SIZE: 1e3,
153
+ MAX_SIZE: 1e4
154
+ };
155
+ const EXPORT_FORMATS = {
156
+ json: { extension: ".json", mimeType: "application/json" },
157
+ csv: { extension: ".csv", mimeType: "text/csv" },
158
+ markdown: { extension: ".md", mimeType: "text/markdown" },
159
+ plain: { extension: ".txt", mimeType: "text/plain" },
160
+ html: { extension: ".html", mimeType: "text/html" }
161
+ };
162
+ const TIME_UNITS = {
163
+ ms: 1,
164
+ s: 1e3,
165
+ m: 60 * 1e3,
166
+ h: 60 * 60 * 1e3,
167
+ d: 24 * 60 * 60 * 1e3
168
+ };
169
+ const ADAPTIVE_COLORS = {
170
+ timestamp: {
171
+ light: "#666666",
172
+ dark: "#a0a0a0"
173
+ },
174
+ messageText: {
175
+ light: "#2d3748",
176
+ dark: "#f7fafc"
177
+ },
178
+ prefix: {
179
+ light: "#2d3748",
180
+ dark: "#e2e8f0"
181
+ },
182
+ prefixBackground: {
183
+ light: "#2d3748",
184
+ dark: "#4a5568"
185
+ },
186
+ location: {
187
+ light: "#718096",
188
+ dark: "#a0aec0"
189
+ }
190
+ };
191
+ const BUILD_PRESETS = {
192
+ /**
193
+ * Configuración optimizada para Next.js builds
194
+ */
195
+ nextjs: {
196
+ verbosity: "info",
197
+ enableColors: true,
198
+ enableTimestamps: false,
199
+ enableStackTrace: false,
200
+ autoDetectTheme: false,
201
+ outputFormat: "build"
202
+ },
203
+ /**
204
+ * Configuración para Webpack builds
205
+ */
206
+ webpack: {
207
+ verbosity: "info",
208
+ enableColors: true,
209
+ enableTimestamps: true,
210
+ enableStackTrace: false,
211
+ autoDetectTheme: false,
212
+ outputFormat: "build"
213
+ },
214
+ /**
215
+ * Configuración para CI/CD environments
216
+ */
217
+ ci: {
218
+ verbosity: "info",
219
+ enableColors: false,
220
+ enableTimestamps: true,
221
+ enableStackTrace: true,
222
+ autoDetectTheme: false,
223
+ outputFormat: "ci"
224
+ },
225
+ /**
226
+ * Configuración para desarrollo terminal
227
+ */
228
+ terminal: {
229
+ verbosity: "debug",
230
+ enableColors: true,
231
+ enableTimestamps: true,
232
+ enableStackTrace: true,
233
+ autoDetectTheme: false,
234
+ outputFormat: "ansi"
235
+ }
236
+ };
237
+ const ENVIRONMENT_DETECTION = {
238
+ // Next.js detection
239
+ isNextJS: typeof process !== "undefined" && (process.env.NEXT_RUNTIME || process.env.NEXT_PUBLIC_VERCEL_ENV || process.argv && process.argv.some((arg) => arg.includes("next"))),
240
+ // Webpack detection
241
+ isWebpack: typeof process !== "undefined" && (process.env.WEBPACK_ENV || process.env.WEBPACK_BUILD || process.argv && process.argv.some((arg) => arg.includes("webpack"))),
242
+ // CI/CD detection
243
+ isCI: typeof process !== "undefined" && (process.env.CI || process.env.GITHUB_ACTIONS || process.env.JENKINS_URL || process.env.GITLAB_CI || process.env.TRAVIS || process.env.CIRCLECI),
244
+ // Build detection
245
+ isBuild: typeof process !== "undefined" && true,
246
+ // Terminal with ANSI support
247
+ isTerminal: typeof process !== "undefined" && (process.stdout?.isTTY === true && process.env.TERM !== "dumb")
248
+ };
249
+ function detectEnvironmentPreset() {
250
+ if (ENVIRONMENT_DETECTION.isCI) {
251
+ return "ci";
252
+ }
253
+ if (ENVIRONMENT_DETECTION.isNextJS) {
254
+ return "nextjs";
255
+ }
256
+ if (ENVIRONMENT_DETECTION.isWebpack) {
257
+ return "webpack";
258
+ }
259
+ if (ENVIRONMENT_DETECTION.isTerminal) {
260
+ return "terminal";
261
+ }
262
+ return "terminal";
263
+ }
264
+ function getOptimalConfig() {
265
+ const preset = detectEnvironmentPreset();
266
+ return {
267
+ ...DEFAULT_CONFIG,
268
+ ...BUILD_PRESETS[preset]
269
+ };
270
+ }
271
+ function formatTimestamp() {
272
+ try {
273
+ const now = /* @__PURE__ */ new Date();
274
+ return now.toISOString();
275
+ } catch {
276
+ return (/* @__PURE__ */ new Date()).toISOString();
277
+ }
278
+ }
279
+ function parseRelativeTime(timeStr) {
280
+ const match = timeStr.match(/^(\d+)(ms|s|m|h|d)$/);
281
+ if (!match) {
282
+ throw new Error(`Invalid time format: ${timeStr}. Use format like "2h", "30m", "1d"`);
283
+ }
284
+ const [, amount, unit] = match;
285
+ const multiplier = TIME_UNITS[unit];
286
+ return parseInt(amount || "0", 10) * multiplier;
287
+ }
288
+ function parseTimeInput(input) {
289
+ if (input instanceof Date) {
290
+ return input;
291
+ }
292
+ if (typeof input === "number") {
293
+ return new Date(Date.now() - input * TIME_UNITS.h);
294
+ }
295
+ if (typeof input === "string") {
296
+ const isoDate = new Date(input);
297
+ if (!isNaN(isoDate.getTime())) {
298
+ return isoDate;
299
+ }
300
+ try {
301
+ const ms = parseRelativeTime(input);
302
+ return new Date(Date.now() - ms);
303
+ } catch {
304
+ throw new Error(`Invalid time format: ${input}`);
305
+ }
306
+ }
307
+ throw new Error(`Unsupported time input type: ${typeof input}`);
308
+ }
309
+ function formatDisplayTime(date, format = "short") {
310
+ switch (format) {
311
+ case "time-only":
312
+ return date.toTimeString().slice(0, 8);
313
+ // HH:MM:SS
314
+ case "full":
315
+ return date.toISOString();
316
+ case "short":
317
+ default:
318
+ return date.toISOString().slice(11, 23);
319
+ }
320
+ }
321
+ class StyleBuilder {
322
+ styles = [];
323
+ constructor(baseStyle = "") {
324
+ if (baseStyle) this.styles.push(baseStyle);
325
+ }
326
+ /**
327
+ * Add background color or gradient
328
+ */
329
+ bg(background) {
330
+ this.styles.push(`background: ${background}`);
331
+ return this;
332
+ }
333
+ /**
334
+ * Add text color
335
+ */
336
+ color(color) {
337
+ this.styles.push(`color: ${color}`);
338
+ return this;
339
+ }
340
+ /**
341
+ * Add border styling
342
+ */
343
+ border(border) {
344
+ this.styles.push(`border: ${border}`);
345
+ return this;
346
+ }
347
+ /**
348
+ * Add box shadow
349
+ */
350
+ shadow(shadow) {
351
+ this.styles.push(`box-shadow: ${shadow}`);
352
+ return this;
353
+ }
354
+ /**
355
+ * Add padding
356
+ */
357
+ padding(padding) {
358
+ this.styles.push(`padding: ${padding}`);
359
+ return this;
360
+ }
361
+ /**
362
+ * Add margin
363
+ */
364
+ margin(margin) {
365
+ this.styles.push(`margin: ${margin}`);
366
+ return this;
367
+ }
368
+ /**
369
+ * Add border radius
370
+ */
371
+ rounded(radius = "4px") {
372
+ this.styles.push(`border-radius: ${radius}`);
373
+ return this;
374
+ }
375
+ /**
376
+ * Add font weight
377
+ */
378
+ bold() {
379
+ this.styles.push("font-weight: bold");
380
+ return this;
381
+ }
382
+ /**
383
+ * Add font styling
384
+ */
385
+ font(font) {
386
+ this.styles.push(`font-family: ${font}`);
387
+ return this;
388
+ }
389
+ /**
390
+ * Set monospace font family (alias for common monospace fonts)
391
+ */
392
+ mono() {
393
+ return this.font('Monaco, Consolas, "Courier New", monospace');
394
+ }
395
+ /**
396
+ * Set system font family (alias for system fonts)
397
+ */
398
+ system() {
399
+ return this.font('system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif');
400
+ }
401
+ /**
402
+ * Add font size
403
+ */
404
+ size(size) {
405
+ this.styles.push(`font-size: ${size}`);
406
+ return this;
407
+ }
408
+ /**
409
+ * Add line height
410
+ */
411
+ lineHeight(height) {
412
+ this.styles.push(`line-height: ${height}`);
413
+ return this;
414
+ }
415
+ /**
416
+ * Add text decoration
417
+ */
418
+ underline() {
419
+ this.styles.push("text-decoration: underline");
420
+ return this;
421
+ }
422
+ /**
423
+ * Add text transform
424
+ */
425
+ uppercase() {
426
+ this.styles.push("text-transform: uppercase");
427
+ return this;
428
+ }
429
+ /**
430
+ * Add opacity
431
+ */
432
+ opacity(value) {
433
+ this.styles.push(`opacity: ${value}`);
434
+ return this;
435
+ }
436
+ /**
437
+ * Add display property
438
+ */
439
+ display(value) {
440
+ this.styles.push(`display: ${value}`);
441
+ return this;
442
+ }
443
+ /**
444
+ * Add position property
445
+ */
446
+ position(value) {
447
+ this.styles.push(`position: ${value}`);
448
+ return this;
449
+ }
450
+ /**
451
+ * Add transform property
452
+ */
453
+ transform(value) {
454
+ this.styles.push(`transform: ${value}`);
455
+ return this;
456
+ }
457
+ /**
458
+ * Add animation property
459
+ */
460
+ animation(value) {
461
+ this.styles.push(`animation: ${value}`);
462
+ return this;
463
+ }
464
+ /**
465
+ * Add transition property
466
+ */
467
+ transition(value) {
468
+ this.styles.push(`transition: ${value}`);
469
+ return this;
470
+ }
471
+ /**
472
+ * Add cursor property
473
+ */
474
+ cursor(value) {
475
+ this.styles.push(`cursor: ${value}`);
476
+ return this;
477
+ }
478
+ /**
479
+ * Add any custom CSS property
480
+ */
481
+ custom(property, value) {
482
+ this.styles.push(`${property}: ${value}`);
483
+ return this;
484
+ }
485
+ /**
486
+ * Add any CSS property (alias for custom)
487
+ */
488
+ css(property, value) {
489
+ return this.custom(property, value);
490
+ }
491
+ /**
492
+ * Build the final CSS string
493
+ */
494
+ build() {
495
+ return this.styles.join("; ");
496
+ }
497
+ /**
498
+ * Clear all styles and start fresh
499
+ */
500
+ clear() {
501
+ this.styles = [];
502
+ return this;
503
+ }
504
+ /**
505
+ * Clone this StyleBuilder with the same styles
506
+ */
507
+ clone() {
508
+ const cloned = new StyleBuilder();
509
+ cloned.styles = [...this.styles];
510
+ return cloned;
511
+ }
512
+ /**
513
+ * Merge another StyleBuilder's styles into this one
514
+ */
515
+ merge(other) {
516
+ this.styles.push(...other.styles);
517
+ return this;
518
+ }
519
+ }
520
+ function createStyler() {
521
+ const builder = new StyleBuilder();
522
+ return new Proxy(builder, {
523
+ get(target, prop) {
524
+ if (prop in target) {
525
+ const method = target[prop];
526
+ if (typeof method === "function") {
527
+ return method.bind(target);
528
+ }
529
+ return method;
530
+ }
531
+ return void 0;
532
+ }
533
+ });
534
+ }
535
+ createStyler();
536
+ const StylePresets = {
537
+ success: () => new StyleBuilder().bg("linear-gradient(135deg, #00b894 0%, #00a085 100%)").color("#ffffff").padding("4px 8px").rounded("4px").bold(),
538
+ error: () => new StyleBuilder().bg("linear-gradient(135deg, #e84393 0%, #d63031 100%)").color("#ffffff").padding("4px 8px").rounded("4px").bold(),
539
+ warning: () => new StyleBuilder().bg("linear-gradient(135deg, #fdcb6e 0%, #e17055 100%)").color("#2d3436").padding("4px 8px").rounded("4px").bold(),
540
+ info: () => new StyleBuilder().bg("linear-gradient(135deg, #74b9ff 0%, #0984e3 100%)").color("#ffffff").padding("4px 8px").rounded("4px").bold(),
541
+ debug: () => new StyleBuilder().bg("linear-gradient(135deg, #667eea 0%, #764ba2 100%)").color("#ffffff").padding("4px 8px").rounded("4px").bold(),
542
+ muted: () => new StyleBuilder().color("#6c757d").font("Monaco, Consolas, monospace").size("12px"),
543
+ accent: () => new StyleBuilder().bg("#f8f9fa").color("#495057").padding("2px 6px").rounded("3px").border("1px solid #dee2e6"),
544
+ neon: () => new StyleBuilder().bg("linear-gradient(135deg, #0f3460 0%, #e94560 100%)").color("#00ffff").padding("4px 8px").rounded("4px").bold().shadow("0 0 10px rgba(0, 255, 255, 0.5)")
545
+ };
546
+ function getEnvironment() {
547
+ if (typeof globalThis !== "undefined" && globalThis.Deno) {
548
+ return "deno";
549
+ }
550
+ if (typeof window === "undefined" && typeof self !== "undefined" && typeof self.importScripts === "function") {
551
+ return "webworker";
552
+ }
553
+ if (typeof process !== "undefined" && process.versions && process.versions.node) {
554
+ if (isRunningInTerminal()) {
555
+ return "terminal";
556
+ }
557
+ return "server";
558
+ }
559
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
560
+ return "browser";
561
+ }
562
+ return "unknown";
563
+ }
564
+ function isRunningInTerminal() {
565
+ if (typeof process === "undefined") return false;
566
+ const isTTY = process.stdout && process.stdout.isTTY;
567
+ const hasTerminalEnv = process.env && (process.env.TERM || process.env.TERM_PROGRAM || process.env.SSH_TTY || process.env.TERM_SESSION_ID);
568
+ const terminalPrograms = [
569
+ "vscode",
570
+ "hyper",
571
+ "iterm",
572
+ "terminal",
573
+ "alacritty",
574
+ "kitty",
575
+ "gnome-terminal",
576
+ "konsole",
577
+ "xterm",
578
+ "tmux",
579
+ "screen"
580
+ ];
581
+ const isTerminalProgram = hasTerminalEnv && terminalPrograms.some(
582
+ (program) => process.env.TERM_PROGRAM?.toLowerCase().includes(program) || process.env.TERM?.toLowerCase().includes(program)
583
+ );
584
+ return Boolean(isTTY || hasTerminalEnv || isTerminalProgram);
585
+ }
586
+ function supportsANSI() {
587
+ const env = getEnvironment();
588
+ if (env === "browser") return false;
589
+ if (env === "terminal") return true;
590
+ if (env === "server") return checkServerANSISupport();
591
+ return false;
592
+ }
593
+ function checkServerANSISupport() {
594
+ if (typeof process === "undefined") return false;
595
+ const supportsANSI2 = process.env && (process.env.COLORTERM || process.env.FORCE_COLOR || process.env.TERM && process.env.TERM !== "dumb" || process.env.TERM_PROGRAM);
596
+ return Boolean(supportsANSI2);
597
+ }
598
+ function getColorCapability() {
599
+ const env = getEnvironment();
600
+ if (env === "browser") {
601
+ return "full";
602
+ }
603
+ if (!supportsANSI()) {
604
+ return "none";
605
+ }
606
+ if (typeof process !== "undefined" && process.env) {
607
+ const hasTrueColor = process.env.COLORTERM === "truecolor" || process.env.COLORTERM === "24bit";
608
+ const has256Colors = process.env.TERM && process.env.TERM.includes("256");
609
+ if (hasTrueColor || has256Colors) {
610
+ return "full";
611
+ }
612
+ }
613
+ return "basic";
614
+ }
615
+ class TerminalRenderer {
616
+ colorCapability;
617
+ constructor(colorCapability = "full") {
618
+ this.colorCapability = colorCapability;
619
+ }
620
+ /**
621
+ * Get ANSI color codes for basic colors
622
+ */
623
+ getColorCode(color, background = false) {
624
+ const colorCodes = {
625
+ "black": { normal: "30", bright: "90" },
626
+ "red": { normal: "31", bright: "91" },
627
+ "green": { normal: "32", bright: "92" },
628
+ "yellow": { normal: "33", bright: "93" },
629
+ "blue": { normal: "34", bright: "94" },
630
+ "magenta": { normal: "35", bright: "95" },
631
+ "cyan": { normal: "36", bright: "96" },
632
+ "white": { normal: "37", bright: "97" },
633
+ "gray": { normal: "90", bright: "37" },
634
+ "grey": { normal: "90", bright: "37" }
635
+ };
636
+ const codes = colorCodes[color.toLowerCase()] || { normal: "37" };
637
+ return `\x1B[${codes.normal}m`;
638
+ }
639
+ /**
640
+ * Get ANSI style codes
641
+ */
642
+ getStyleCode(styles) {
643
+ const styleCodes = {
644
+ "bold": "1",
645
+ "dim": "2",
646
+ "italic": "3",
647
+ "underline": "4",
648
+ "reset": "0"
649
+ };
650
+ const codes = styles.map((style) => styleCodes[style] || "0").join(";");
651
+ return codes ? `\x1B[${codes}m` : "";
652
+ }
653
+ /**
654
+ * Convert log styles to ANSI formatting
655
+ */
656
+ renderTerminal(level, message, timestamp, prefix, location, styles) {
657
+ const reset = "\x1B[0m";
658
+ const result = { text: "", reset };
659
+ if (styles) {
660
+ result.timestamp = this.styleTimestamp(timestamp, styles.timestamp);
661
+ result.level = this.styleLevel(level, styles.level);
662
+ result.prefix = this.stylePrefix(prefix, styles.prefix);
663
+ result.message = this.styleMessage(message, styles.message);
664
+ result.location = this.styleLocation(location, styles.location);
665
+ } else {
666
+ result.timestamp = this.styleTimestamp(timestamp);
667
+ result.level = this.styleLevel(level);
668
+ result.prefix = this.stylePrefix(prefix);
669
+ result.message = this.styleMessage(message);
670
+ result.location = this.styleLocation(location);
671
+ }
672
+ const parts = [];
673
+ if (result.timestamp) parts.push(result.timestamp);
674
+ if (result.level) parts.push(result.level);
675
+ if (result.prefix) parts.push(result.prefix);
676
+ if (result.message) parts.push(result.message);
677
+ if (result.location) parts.push(result.location);
678
+ result.text = parts.join(" ") + reset;
679
+ return result;
680
+ }
681
+ /**
682
+ * Style timestamp based on preset or defaults
683
+ */
684
+ styleTimestamp(timestamp, style) {
685
+ if (!timestamp || !style?.show) return "";
686
+ if (this.colorCapability === "none") {
687
+ return timestamp;
688
+ }
689
+ const dimStyle = this.getStyleCode(["dim"]);
690
+ return `${dimStyle}${timestamp}${"\x1B[0m"}`;
691
+ }
692
+ /**
693
+ * Style level with appropriate colors and formatting
694
+ */
695
+ styleLevel(level, style) {
696
+ if (!style?.show) return "";
697
+ const levelText = this.getLevelText(level);
698
+ const levelColors = {
699
+ "debug": "magenta",
700
+ "info": "blue",
701
+ "warn": "yellow",
702
+ "error": "red",
703
+ "critical": "red"
704
+ };
705
+ if (this.colorCapability === "none") {
706
+ return `[${levelText}]`;
707
+ }
708
+ const color = levelColors[level] || "white";
709
+ const colorCode = this.getColorCode(color);
710
+ const boldStyle = this.getStyleCode(["bold"]);
711
+ if (style?.style === "compact") {
712
+ return `${colorCode}[${levelText}]${"\x1B[0m"}`;
713
+ } else {
714
+ return `${colorCode}${boldStyle}[${levelText}]${"\x1B[0m"}`;
715
+ }
716
+ }
717
+ /**
718
+ * Style prefix based on preset - now as a badge
719
+ */
720
+ stylePrefix(prefix, style) {
721
+ if (!prefix || !style?.show) return "";
722
+ if (this.colorCapability === "none") {
723
+ return `[${prefix}]`;
724
+ }
725
+ const colorCode = this.getColorCode("cyan");
726
+ const bgBlack = "\x1B[40m";
727
+ return `${bgBlack}${colorCode}[${prefix.toUpperCase()}]${"\x1B[0m"}`;
728
+ }
729
+ /**
730
+ * Style message based on preset
731
+ */
732
+ styleMessage(message, style) {
733
+ if (!style?.show) return message;
734
+ return message;
735
+ }
736
+ /**
737
+ * Style location (file:line) information
738
+ */
739
+ styleLocation(location, style) {
740
+ if (!location || !style?.show) return "";
741
+ if (this.colorCapability === "none") {
742
+ return `(${location})`;
743
+ }
744
+ const dimStyle = this.getStyleCode(["dim"]);
745
+ if (style?.style === "clickable") {
746
+ const underlineStyle = this.getStyleCode(["dim", "underline"]);
747
+ return `${underlineStyle}(${location})${"\x1B[0m"}`;
748
+ }
749
+ return `${dimStyle}(${location})${"\x1B[0m"}`;
750
+ }
751
+ /**
752
+ * Get text representation of log level
753
+ */
754
+ getLevelText(level) {
755
+ const levelMap = {
756
+ "debug": "DEBUG",
757
+ "info": "INFO",
758
+ "warn": "WARN",
759
+ "error": "ERROR",
760
+ "critical": "CRITICAL"
761
+ };
762
+ return levelMap[level] || String(level).toUpperCase();
763
+ }
764
+ /**
765
+ * Create cyberpunk-style ANSI rendering
766
+ */
767
+ renderCyberpunk(level, message, timestamp, prefix, location) {
768
+ const reset = "\x1B[0m";
769
+ const levelColors = {
770
+ "debug": "\x1B[95m",
771
+ // Bright magenta
772
+ "info": "\x1B[94m",
773
+ // Bright blue
774
+ "warn": "\x1B[93m",
775
+ // Bright yellow
776
+ "error": "\x1B[91m",
777
+ // Bright red
778
+ "critical": "\x1B[91m\x1B[1m"
779
+ // Bright red + bold
780
+ };
781
+ const parts = [];
782
+ if (timestamp) {
783
+ parts.push(`\x1B[90m${timestamp}${reset}`);
784
+ }
785
+ const levelColor = levelColors[level] || "\x1B[97m";
786
+ const bgBlack = "\x1B[40m";
787
+ parts.push(`${bgBlack}${levelColor} ${this.getLevelText(level)} ${reset}`);
788
+ if (prefix) {
789
+ const bgBlack2 = "\x1B[40m";
790
+ parts.push(`${bgBlack2}\x1B[96m[${prefix.toUpperCase()}]${reset}`);
791
+ }
792
+ parts.push(message);
793
+ if (location) {
794
+ parts.push(`\x1B[90m(${location})${reset}`);
795
+ }
796
+ return {
797
+ text: parts.join(" "),
798
+ reset
799
+ };
800
+ }
801
+ /**
802
+ * Create minimal ANSI rendering
803
+ */
804
+ renderMinimal(level, message, timestamp, prefix) {
805
+ const reset = "\x1B[0m";
806
+ const levelColors = {
807
+ "debug": "\x1B[95m",
808
+ // Magenta
809
+ "info": "\x1B[94m",
810
+ // Blue
811
+ "warn": "\x1B[93m",
812
+ // Yellow
813
+ "error": "\x1B[91m",
814
+ // Red
815
+ "critical": "\x1B[91m\x1B[1m"
816
+ // Red + bold
817
+ };
818
+ const parts = [];
819
+ if (timestamp) {
820
+ parts.push(`\x1B[90m${timestamp}${reset}`);
821
+ }
822
+ const levelColor = levelColors[level] || "\x1B[97m";
823
+ parts.push(`${levelColor}${this.getLevelText(level)}:${reset}`);
824
+ if (prefix) {
825
+ parts.push(`\x1B[96m[${prefix.toUpperCase()}]${reset}`);
826
+ }
827
+ parts.push(message);
828
+ return {
829
+ text: parts.join(" "),
830
+ reset
831
+ };
832
+ }
833
+ /**
834
+ * Get chalk instance for log level (for compatibility with adapter)
835
+ */
836
+ getChalkForLevel(level) {
837
+ const levelColors = {
838
+ "debug": "magenta",
839
+ "info": "blue",
840
+ "warn": "yellow",
841
+ "error": "red",
842
+ "critical": "red"
843
+ };
844
+ return {
845
+ color: (text) => {
846
+ const color = levelColors[level] || "white";
847
+ const colorCode = this.getColorCode(color);
848
+ return `${colorCode}${text}${"\x1B[0m"}`;
849
+ },
850
+ bold: (text) => {
851
+ const boldStyle = this.getStyleCode(["bold"]);
852
+ return `${boldStyle}${text}${"\x1B[0m"}`;
853
+ },
854
+ dim: (text) => {
855
+ const dimStyle = this.getStyleCode(["dim"]);
856
+ return `${dimStyle}${text}${"\x1B[0m"}`;
857
+ },
858
+ bgGray: (text) => {
859
+ return `\x1B[100m${text}${"\x1B[0m"}`;
860
+ },
861
+ bgBlue: (text) => {
862
+ return `\x1B[104m${text}${"\x1B[0m"}`;
863
+ },
864
+ reset: (text) => text,
865
+ cyan: {
866
+ bold: (text) => {
867
+ const cyan = this.getColorCode("cyan");
868
+ const bold = this.getStyleCode(["bold"]);
869
+ return `${cyan}${bold}${text}${"\x1B[0m"}`;
870
+ },
871
+ dim: (text) => {
872
+ const cyan = this.getColorCode("cyan");
873
+ const dim = this.getStyleCode(["dim"]);
874
+ return `${cyan}${dim}${text}${"\x1B[0m"}`;
875
+ },
876
+ bg: (text) => {
877
+ const bgBlack = "\x1B[40m";
878
+ const cyan = this.getColorCode("cyan");
879
+ return `${bgBlack}${cyan}[${text.toUpperCase()}]${"\x1B[0m"}`;
880
+ }
881
+ }
882
+ };
883
+ }
884
+ }
885
+ class CSS2ANSIAdapter {
886
+ renderer;
887
+ constructor() {
888
+ const colorCapability = getColorCapability();
889
+ this.renderer = new TerminalRenderer(colorCapability);
890
+ }
891
+ /**
892
+ * Convert LogStyles to ANSIStyle for terminal rendering
893
+ */
894
+ adaptStyles(level, message, timestamp, prefix, location, styles, presetName) {
895
+ if (presetName) {
896
+ switch (presetName) {
897
+ case "cyberpunk":
898
+ return this.renderer.renderCyberpunk(level, message, timestamp, prefix, location);
899
+ case "minimal":
900
+ return this.renderer.renderMinimal(level, message, timestamp, prefix);
901
+ case "production":
902
+ return this.adaptProductionStyles(level, message, timestamp, prefix, location, styles);
903
+ case "debug":
904
+ return this.adaptDebugStyles(level, message, timestamp, prefix, location, styles);
905
+ case "glassmorphism":
906
+ return this.adaptGlassmorphismStyles(level, message, timestamp, prefix, location, styles);
907
+ }
908
+ }
909
+ return this.renderer.renderTerminal(level, message, timestamp, prefix, location, styles);
910
+ }
911
+ /**
912
+ * Adapt production preset for terminal
913
+ */
914
+ adaptProductionStyles(level, message, timestamp, prefix, location, styles) {
915
+ const reset = "\x1B[0m";
916
+ const levelChalk = this.renderer.getChalkForLevel(level);
917
+ const parts = [];
918
+ if (timestamp && styles?.timestamp?.show) {
919
+ parts.push(levelChalk.dim(timestamp));
920
+ }
921
+ if (styles?.level?.show) {
922
+ parts.push(levelChalk.color(`[${this.renderer["getLevelText"](level)}]`));
923
+ }
924
+ if (prefix && styles?.prefix?.show) {
925
+ parts.push(levelChalk.dim(`[${prefix}]`));
926
+ }
927
+ if (message && styles?.message?.show) {
928
+ parts.push(levelChalk.reset(message));
929
+ }
930
+ if (location && styles?.location?.show) {
931
+ parts.push(levelChalk.dim(`(${location})`));
932
+ }
933
+ return {
934
+ text: parts.join(" ") + reset,
935
+ reset
936
+ };
937
+ }
938
+ /**
939
+ * Adapt debug preset for terminal
940
+ */
941
+ adaptDebugStyles(level, message, timestamp, prefix, location, styles) {
942
+ const reset = "\x1B[0m";
943
+ const levelChalk = this.renderer.getChalkForLevel(level);
944
+ const parts = [];
945
+ if (timestamp && styles?.timestamp?.show) {
946
+ parts.push(levelChalk.dim(timestamp));
947
+ }
948
+ if (styles?.level?.show) {
949
+ if (styles?.level?.style === "compact") {
950
+ parts.push(levelChalk.color(`[${this.renderer["getLevelText"](level)}]`));
951
+ } else {
952
+ parts.push(levelChalk.bold(`[${this.renderer["getLevelText"](level)}]`));
953
+ }
954
+ }
955
+ if (prefix && styles?.prefix?.show) {
956
+ if (styles?.prefix?.style === "compact") {
957
+ parts.push(levelChalk.cyan.dim(`[${prefix}]`));
958
+ } else {
959
+ parts.push(levelChalk.cyan.bold(`[${prefix}]`));
960
+ }
961
+ }
962
+ if (message && styles?.message?.show) {
963
+ parts.push(levelChalk.reset(message));
964
+ }
965
+ if (location && styles?.location?.show) {
966
+ if (styles?.location?.style === "clickable") {
967
+ parts.push(levelChalk.dim(`${location} (clickable)`));
968
+ } else {
969
+ parts.push(levelChalk.dim(`(${location})`));
970
+ }
971
+ }
972
+ return {
973
+ text: parts.join(" ") + reset,
974
+ reset
975
+ };
976
+ }
977
+ /**
978
+ * Adapt glassmorphism preset for terminal
979
+ */
980
+ adaptGlassmorphismStyles(level, message, timestamp, prefix, location, styles) {
981
+ const reset = "\x1B[0m";
982
+ const levelChalk = this.renderer.getChalkForLevel(level);
983
+ const parts = [];
984
+ if (timestamp && styles?.timestamp?.show) {
985
+ parts.push(levelChalk.dim(timestamp));
986
+ }
987
+ if (styles?.level?.show) {
988
+ parts.push(levelChalk.bgGray(` ${this.renderer["getLevelText"](level)} `));
989
+ }
990
+ if (prefix && styles?.prefix?.show) {
991
+ parts.push(levelChalk.bgBlue(`[${prefix}]`));
992
+ }
993
+ if (message && styles?.message?.show) {
994
+ parts.push(levelChalk.reset(message));
995
+ }
996
+ if (location && styles?.location?.show) {
997
+ parts.push(levelChalk.dim(`(${location})`));
998
+ }
999
+ return {
1000
+ text: parts.join(" ") + reset,
1001
+ reset
1002
+ };
1003
+ }
1004
+ /**
1005
+ * Convert CSS color values to ANSI-friendly colors
1006
+ */
1007
+ adaptColor(cssColor) {
1008
+ if (cssColor.startsWith("#")) {
1009
+ return cssColor;
1010
+ }
1011
+ if (cssColor.startsWith("rgb(")) {
1012
+ return cssColor;
1013
+ }
1014
+ if (cssColor.includes("gradient")) {
1015
+ return this.extractColorFromGradient(cssColor);
1016
+ }
1017
+ return this.cssNameToANSI(cssColor);
1018
+ }
1019
+ /**
1020
+ * Extract primary color from CSS gradient
1021
+ */
1022
+ extractColorFromGradient(gradient) {
1023
+ const match = gradient.match(/#[0-9a-fA-F]{6}|rgb\([^)]+\)/);
1024
+ return match ? match[0] : "#ffffff";
1025
+ }
1026
+ /**
1027
+ * Convert CSS color names to ANSI-compatible names
1028
+ */
1029
+ cssNameToANSI(cssColor) {
1030
+ const colorMap = {
1031
+ "black": "black",
1032
+ "white": "white",
1033
+ "red": "red",
1034
+ "green": "green",
1035
+ "blue": "blue",
1036
+ "yellow": "yellow",
1037
+ "cyan": "cyan",
1038
+ "magenta": "magenta",
1039
+ "gray": "gray",
1040
+ "grey": "gray",
1041
+ "orange": "yellow",
1042
+ "purple": "magenta",
1043
+ "pink": "red",
1044
+ "brown": "yellow",
1045
+ "lightblue": "cyan",
1046
+ "lightgreen": "green",
1047
+ "lightgray": "gray",
1048
+ "lightgrey": "gray"
1049
+ };
1050
+ return colorMap[cssColor.toLowerCase()] || "white";
1051
+ }
1052
+ /**
1053
+ * Check if a style should be rendered in terminal
1054
+ */
1055
+ shouldRenderStyle(styleType, styles) {
1056
+ if (!styles) return true;
1057
+ const styleConfig = styles[styleType];
1058
+ return styleConfig?.show !== false;
1059
+ }
1060
+ /**
1061
+ * Get renderer instance for advanced usage
1062
+ */
1063
+ getRenderer() {
1064
+ return this.renderer;
1065
+ }
1066
+ }
1067
+ const css2ansiAdapter = new CSS2ANSIAdapter();
1068
+ function adaptToTerminal(level, message, timestamp, prefix, location, styles, presetName) {
1069
+ return css2ansiAdapter.adaptStyles(level, message, timestamp, prefix, location, styles, presetName);
1070
+ }
1071
+ function detectDevToolsTheme() {
1072
+ try {
1073
+ if (typeof window === "undefined" || !window.matchMedia) {
1074
+ return "light";
1075
+ }
1076
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
1077
+ return mediaQuery.matches ? "dark" : "light";
1078
+ } catch (error) {
1079
+ console.warn("Failed to detect DevTools theme:", error);
1080
+ return "light";
1081
+ }
1082
+ }
1083
+ function getAdaptiveColor(colors, theme) {
1084
+ const currentTheme = theme ?? detectDevToolsTheme();
1085
+ return colors[currentTheme];
1086
+ }
1087
+ function setupThemeChangeListener(callback) {
1088
+ try {
1089
+ if (typeof window === "undefined" || !window.matchMedia) {
1090
+ return null;
1091
+ }
1092
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
1093
+ const handler = (e) => {
1094
+ callback(e.matches ? "dark" : "light");
1095
+ };
1096
+ if (mediaQuery.addEventListener) {
1097
+ mediaQuery.addEventListener("change", handler);
1098
+ return () => mediaQuery.removeEventListener("change", handler);
1099
+ } else if (mediaQuery.addListener) {
1100
+ mediaQuery.addListener(handler);
1101
+ return () => mediaQuery.removeListener?.(handler);
1102
+ }
1103
+ return null;
1104
+ } catch (error) {
1105
+ console.warn("Failed to set up theme change listener:", error);
1106
+ return null;
1107
+ }
1108
+ }
1109
+ function createStyledOutput(level, levelStyles, prefix, message, stackInfo, autoDetectTheme = true, presetStyles, presetName) {
1110
+ const levelConfig = levelStyles[level];
1111
+ const timestamp = formatTimestamp();
1112
+ const environment = getEnvironment();
1113
+ if (environment !== "browser" && supportsANSI()) {
1114
+ return createTerminalOutput(level, message, timestamp, prefix, stackInfo, presetStyles, presetName);
1115
+ }
1116
+ const currentTheme = autoDetectTheme ? detectDevToolsTheme() : "light";
1117
+ const timestampStyle = new StyleBuilder().color(getAdaptiveColor(ADAPTIVE_COLORS.timestamp, currentTheme)).size("11px").font("Monaco, Consolas, monospace").build();
1118
+ const levelStyle = new StyleBuilder().bg(levelConfig.background).color(levelConfig.color).border(levelConfig.border).shadow(levelConfig.shadow).padding("2px 8px").rounded("4px").bold().font("Monaco, Consolas, monospace").size("12px").build();
1119
+ const prefixStyle = new StyleBuilder().bg(getAdaptiveColor(ADAPTIVE_COLORS.prefixBackground, currentTheme)).color(getAdaptiveColor(ADAPTIVE_COLORS.prefix, currentTheme)).padding("2px 6px").rounded("3px").bold().font("Monaco, Consolas, monospace").size("11px").build();
1120
+ const messageStyle = new StyleBuilder().color(getAdaptiveColor(ADAPTIVE_COLORS.messageText, currentTheme)).font("system-ui, -apple-system, sans-serif").size("14px").build();
1121
+ const locationStyle = new StyleBuilder().color(getAdaptiveColor(ADAPTIVE_COLORS.location, currentTheme)).size("11px").font("Monaco, Consolas, monospace").build();
1122
+ let format = `%c${timestamp.slice(11, 23)} %c${levelConfig.emoji} ${levelConfig.label}`;
1123
+ const styles = [timestampStyle, levelStyle];
1124
+ if (prefix) {
1125
+ format += ` %c${prefix}`;
1126
+ styles.push(prefixStyle);
1127
+ }
1128
+ format += ` %c${message}`;
1129
+ styles.push(messageStyle);
1130
+ if (stackInfo) {
1131
+ format += ` %c(${stackInfo.file}:${stackInfo.line}:${stackInfo.column})`;
1132
+ styles.push(locationStyle);
1133
+ }
1134
+ return [format, ...styles];
1135
+ }
1136
+ function generateLogId() {
1137
+ return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
1138
+ }
1139
+ function escapeHtml(text) {
1140
+ const div = document.createElement("div");
1141
+ div.textContent = text;
1142
+ return div.innerHTML;
1143
+ }
1144
+ function safeStringify(obj, _maxDepth = 3) {
1145
+ try {
1146
+ return JSON.stringify(obj, (_key, value) => {
1147
+ if (typeof value === "function") return "[Function]";
1148
+ if (value instanceof Error) return `[Error: ${value.message}]`;
1149
+ if (value instanceof Date) return value.toISOString();
1150
+ if (typeof value === "undefined") return "[undefined]";
1151
+ return value;
1152
+ }, 2);
1153
+ } catch (error) {
1154
+ return String(obj);
1155
+ }
1156
+ }
1157
+ function createTerminalOutput(level, message, timestamp, prefix, stackInfo, presetStyles, presetName) {
1158
+ const location = stackInfo ? `${stackInfo.file}:${stackInfo.line}:${stackInfo.column}` : void 0;
1159
+ const ansiStyle = adaptToTerminal(
1160
+ level,
1161
+ message,
1162
+ timestamp,
1163
+ prefix,
1164
+ location,
1165
+ presetStyles,
1166
+ presetName
1167
+ );
1168
+ return [ansiStyle.text];
1169
+ }
1170
+ const isNode = typeof process !== "undefined" && process.versions && process.versions.node;
1171
+ const isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
1172
+ function supportsCSSColors() {
1173
+ return isBrowser;
1174
+ }
1175
+ function supportsANSIColors() {
1176
+ if (isNode) {
1177
+ return process.stdout?.isTTY === true || process.env.FORCE_COLOR === "1" || process.env.FORCE_COLOR === "true";
1178
+ }
1179
+ return false;
1180
+ }
1181
+ export {
1182
+ ADAPTIVE_COLORS as A,
1183
+ BUILD_PRESETS as B,
1184
+ DEFAULT_CONFIG as D,
1185
+ ENVIRONMENT_DETECTION as E,
1186
+ LEVEL_STYLES as L,
1187
+ StylePresets as S,
1188
+ isBrowser as a,
1189
+ StyleBuilder as b,
1190
+ createStyledOutput as c,
1191
+ detectEnvironmentPreset as d,
1192
+ supportsANSIColors as e,
1193
+ formatTimestamp as f,
1194
+ getOptimalConfig as g,
1195
+ getAdaptiveColor as h,
1196
+ isNode as i,
1197
+ BUFFER_LIMITS as j,
1198
+ generateLogId as k,
1199
+ parseTimeInput as l,
1200
+ formatDisplayTime as m,
1201
+ safeStringify as n,
1202
+ escapeHtml as o,
1203
+ parseStackTrace as p,
1204
+ EXPORT_FORMATS as q,
1205
+ setupThemeChangeListener as r,
1206
+ supportsCSSColors as s,
1207
+ getEnvironment as t
1208
+ };
1209
+ //# sourceMappingURL=environment-TI2ByCPT.js.map