nothing-browser 0.0.4 → 0.0.6

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.
@@ -0,0 +1,902 @@
1
+ import { createRequire } from "node:module";
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
12
+ var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
20
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
21
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
22
+ for (let key of __getOwnPropNames(mod))
23
+ if (!__hasOwnProp.call(to, key))
24
+ __defProp(to, key, {
25
+ get: __accessProp.bind(mod, key),
26
+ enumerable: true
27
+ });
28
+ if (canCache)
29
+ cache.set(mod, to);
30
+ return to;
31
+ };
32
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
33
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
34
+
35
+ // node_modules/ernest-logger/colors/colors.js
36
+ var require_colors = __commonJS((exports, module) => {
37
+ var colors = {
38
+ black: "\x1B[30m",
39
+ red: "\x1B[31m",
40
+ green: "\x1B[32m",
41
+ yellow: "\x1B[33m",
42
+ blue: "\x1B[34m",
43
+ magenta: "\x1B[35m",
44
+ cyan: "\x1B[36m",
45
+ white: "\x1B[37m",
46
+ brightBlack: "\x1B[90m",
47
+ brightRed: "\x1B[91m",
48
+ brightGreen: "\x1B[92m",
49
+ brightYellow: "\x1B[93m",
50
+ brightBlue: "\x1B[94m",
51
+ brightMagenta: "\x1B[95m",
52
+ brightCyan: "\x1B[96m",
53
+ brightWhite: "\x1B[97m",
54
+ bgBlack: "\x1B[40m",
55
+ bgRed: "\x1B[41m",
56
+ bgGreen: "\x1B[42m",
57
+ bgYellow: "\x1B[43m",
58
+ bgBlue: "\x1B[44m",
59
+ bgMagenta: "\x1B[45m",
60
+ bgCyan: "\x1B[46m",
61
+ bgWhite: "\x1B[47m",
62
+ bgBrightBlack: "\x1B[100m",
63
+ bgBrightRed: "\x1B[101m",
64
+ bgBrightGreen: "\x1B[102m",
65
+ bgBrightYellow: "\x1B[103m",
66
+ bgBrightBlue: "\x1B[104m",
67
+ bgBrightMagenta: "\x1B[105m",
68
+ bgBrightCyan: "\x1B[106m",
69
+ bgBrightWhite: "\x1B[107m",
70
+ reset: "\x1B[0m",
71
+ bold: "\x1B[1m",
72
+ dim: "\x1B[2m",
73
+ italic: "\x1B[3m",
74
+ underline: "\x1B[4m",
75
+ blink: "\x1B[5m",
76
+ reverse: "\x1B[7m",
77
+ hidden: "\x1B[8m",
78
+ strikethrough: "\x1B[9m",
79
+ success: "\x1B[32m",
80
+ error: "\x1B[31m",
81
+ warning: "\x1B[33m",
82
+ info: "\x1B[34m",
83
+ debug: "\x1B[36m",
84
+ primary: "\x1B[94m",
85
+ secondary: "\x1B[90m",
86
+ danger: "\x1B[91m",
87
+ muted: "\x1B[2m"
88
+ };
89
+ colors.combine = (...codes) => {
90
+ return codes.map((code) => colors[code] || "").join("");
91
+ };
92
+ colors.wrap = (text, color) => {
93
+ return (colors[color] || "") + text + colors.reset;
94
+ };
95
+ colors.gradient = (text, colorSequence = ["cyan", "blue", "magenta"]) => {
96
+ const chars = text.split("");
97
+ const colorCount = colorSequence.length;
98
+ return chars.map((char, i) => {
99
+ const colorName = colorSequence[i % colorCount];
100
+ return colors[colorName] + char;
101
+ }).join("") + colors.reset;
102
+ };
103
+ colors.rainbow = (text) => {
104
+ const rainbowColors = ["red", "yellow", "green", "cyan", "blue", "magenta"];
105
+ return colors.gradient(text, rainbowColors);
106
+ };
107
+ module.exports = colors;
108
+ });
109
+
110
+ // node_modules/ernest-logger/emojis/emojis.js
111
+ var require_emojis = __commonJS((exports, module) => {
112
+ var emojis = {
113
+ trace: "\uD83D\uDD0D",
114
+ debug: "\uD83D\uDC1E",
115
+ info: "ℹ️",
116
+ success: "✅",
117
+ warn: "⚠️",
118
+ error: "❌",
119
+ fatal: "\uD83D\uDC80",
120
+ start: "▶️",
121
+ stop: "⏹️",
122
+ pause: "⏸️",
123
+ resume: "⏯️",
124
+ restart: "\uD83D\uDD04",
125
+ shutdown: "\uD83D\uDED1",
126
+ boot: "\uD83D\uDE80",
127
+ network: "\uD83C\uDF10",
128
+ api: "\uD83D\uDD0C",
129
+ request: "\uD83D\uDCE4",
130
+ response: "\uD83D\uDCE5",
131
+ webhook: "\uD83E\uDE9D",
132
+ socket: "\uD83D\uDD17",
133
+ upload: "⬆️",
134
+ download: "⬇️",
135
+ sync: "\uD83D\uDD04",
136
+ db: "\uD83D\uDCBE",
137
+ database: "\uD83D\uDDC4️",
138
+ cache: "\uD83D\uDCA8",
139
+ storage: "\uD83D\uDCE6",
140
+ backup: "\uD83D\uDCBF",
141
+ restore: "♻️",
142
+ query: "\uD83D\uDD0E",
143
+ migration: "\uD83D\uDD00",
144
+ security: "\uD83D\uDD12",
145
+ unlock: "\uD83D\uDD13",
146
+ auth: "\uD83D\uDD10",
147
+ key: "\uD83D\uDD11",
148
+ token: "\uD83C\uDFAB",
149
+ encrypt: "\uD83D\uDEE1️",
150
+ decrypt: "\uD83D\uDD13",
151
+ firewall: "\uD83E\uDDF1",
152
+ scan: "\uD83D\uDD2C",
153
+ file: "\uD83D\uDCC4",
154
+ folder: "\uD83D\uDCC1",
155
+ document: "\uD83D\uDCC3",
156
+ archive: "\uD83D\uDDDC️",
157
+ zip: "\uD83E\uDD10",
158
+ pdf: "\uD83D\uDCD5",
159
+ csv: "\uD83D\uDCCA",
160
+ json: "\uD83D\uDCCB",
161
+ xml: "\uD83D\uDCF0",
162
+ config: "⚙️",
163
+ cloud: "☁️",
164
+ server: "\uD83D\uDDA5️",
165
+ deploy: "\uD83D\uDE80",
166
+ build: "\uD83D\uDD28",
167
+ compile: "⚒️",
168
+ package: "\uD83D\uDCE6",
169
+ publish: "\uD83D\uDCE2",
170
+ release: "\uD83C\uDF89",
171
+ rollback: "⏮️",
172
+ test: "\uD83E\uDDEA",
173
+ unittest: "\uD83D\uDD2C",
174
+ integration: "\uD83D\uDD17",
175
+ coverage: "\uD83D\uDCCA",
176
+ benchmark: "⏱️",
177
+ performance: "⚡",
178
+ profiling: "\uD83D\uDCC8",
179
+ bugFix: "\uD83D\uDC1B",
180
+ feature: "✨",
181
+ refactor: "♻️",
182
+ cleanup: "\uD83E\uDDF9",
183
+ user: "\uD83D\uDC64",
184
+ users: "\uD83D\uDC65",
185
+ admin: "\uD83D\uDC51",
186
+ robot: "\uD83E\uDD16",
187
+ human: "\uD83D\uDC68‍\uD83D\uDC69‍\uD83D\uDC67‍\uD83D\uDC66",
188
+ team: "\uD83D\uDC68‍\uD83D\uDC69‍\uD83D\uDC67‍\uD83D\uDC66",
189
+ chat: "\uD83D\uDCAC",
190
+ message: "✉️",
191
+ notification: "\uD83D\uDD14",
192
+ alert: "\uD83D\uDEA8",
193
+ money: "\uD83D\uDCB0",
194
+ payment: "\uD83D\uDCB3",
195
+ invoice: "\uD83E\uDDFE",
196
+ chart: "\uD83D\uDCCA",
197
+ analytics: "\uD83D\uDCC8",
198
+ metrics: "\uD83D\uDCC9",
199
+ dashboard: "\uD83C\uDF9B️",
200
+ report: "\uD83D\uDCC4",
201
+ online: "\uD83D\uDFE2",
202
+ offline: "\uD83D\uDD34",
203
+ pending: "\uD83D\uDFE1",
204
+ processing: "⏳",
205
+ loading: "⌛",
206
+ complete: "✔️",
207
+ incomplete: "❌",
208
+ progress: "\uD83D\uDCCA",
209
+ idea: "\uD83D\uDCA1",
210
+ lightning: "⚡",
211
+ fire: "\uD83D\uDD25",
212
+ star: "⭐",
213
+ trophy: "\uD83C\uDFC6",
214
+ medal: "\uD83C\uDFC5",
215
+ gift: "\uD83C\uDF81",
216
+ celebrate: "\uD83C\uDF89",
217
+ party: "\uD83C\uDF8A",
218
+ rocket: "\uD83D\uDE80",
219
+ ship: "\uD83D\uDEA2",
220
+ airplane: "✈️",
221
+ train: "\uD83D\uDE86",
222
+ calendar: "\uD83D\uDCC5",
223
+ clock: "\uD83D\uDD50",
224
+ timer: "⏲️",
225
+ bell: "\uD83D\uDD14",
226
+ flag: "\uD83D\uDEA9",
227
+ bookmark: "\uD83D\uDD16",
228
+ tag: "\uD83C\uDFF7️",
229
+ pin: "\uD83D\uDCCC",
230
+ magnet: "\uD83E\uDDF2",
231
+ crystal: "\uD83D\uDD2E",
232
+ gem: "\uD83D\uDC8E",
233
+ target: "\uD83C\uDFAF",
234
+ dart: "\uD83C\uDFAF",
235
+ compass: "\uD83E\uDDED",
236
+ map: "\uD83D\uDDFA️",
237
+ globe: "\uD83C\uDF0D",
238
+ satellite: "\uD83D\uDEF0️",
239
+ telescope: "\uD83D\uDD2D",
240
+ microscope: "\uD83D\uDD2C",
241
+ magGlass: "\uD83D\uDD0D",
242
+ wrench: "\uD83D\uDD27",
243
+ hammer: "\uD83D\uDD28",
244
+ screwdriver: "\uD83E\uDE9B",
245
+ gear: "⚙️",
246
+ nut: "\uD83D\uDD29",
247
+ link: "\uD83D\uDD17",
248
+ chain: "⛓️",
249
+ bridge: "\uD83C\uDF09",
250
+ door: "\uD83D\uDEAA",
251
+ window: "\uD83E\uDE9F",
252
+ shield: "\uD83D\uDEE1️",
253
+ sword: "⚔️",
254
+ bomb: "\uD83D\uDCA3",
255
+ explosion: "\uD83D\uDCA5",
256
+ spark: "✨",
257
+ dizzy: "\uD83D\uDCAB",
258
+ wave: "\uD83C\uDF0A",
259
+ droplet: "\uD83D\uDCA7",
260
+ snowflake: "❄️",
261
+ sun: "☀️",
262
+ moon: "\uD83C\uDF19",
263
+ rainbow: "\uD83C\uDF08",
264
+ seedling: "\uD83C\uDF31",
265
+ tree: "\uD83C\uDF32",
266
+ leaf: "\uD83C\uDF43",
267
+ recycle: "♻️"
268
+ };
269
+ emojis.get = (name, fallback = "") => {
270
+ return emojis[name] || fallback;
271
+ };
272
+ emojis.has = (name) => {
273
+ return emojis.hasOwnProperty(name);
274
+ };
275
+ emojis.list = () => {
276
+ return Object.keys(emojis).filter((key) => typeof emojis[key] === "string" && !["get", "has", "list"].includes(key));
277
+ };
278
+ module.exports = emojis;
279
+ });
280
+
281
+ // node_modules/ernest-logger/utils/timestamp.js
282
+ var require_timestamp = __commonJS((exports, module) => {
283
+ var getTimestamp = () => {
284
+ const date = new Date;
285
+ const hours = String(date.getHours()).padStart(2, "0");
286
+ const minutes = String(date.getMinutes()).padStart(2, "0");
287
+ const seconds = String(date.getSeconds()).padStart(2, "0");
288
+ return `${hours}:${minutes}:${seconds}`;
289
+ };
290
+ var getTimestampWithMs = () => {
291
+ const date = new Date;
292
+ const hours = String(date.getHours()).padStart(2, "0");
293
+ const minutes = String(date.getMinutes()).padStart(2, "0");
294
+ const seconds = String(date.getSeconds()).padStart(2, "0");
295
+ const ms = String(date.getMilliseconds()).padStart(3, "0");
296
+ return `${hours}:${minutes}:${seconds}.${ms}`;
297
+ };
298
+ var getFullTimestamp = () => {
299
+ const date = new Date;
300
+ const year = date.getFullYear();
301
+ const month = String(date.getMonth() + 1).padStart(2, "0");
302
+ const day = String(date.getDate()).padStart(2, "0");
303
+ const hours = String(date.getHours()).padStart(2, "0");
304
+ const minutes = String(date.getMinutes()).padStart(2, "0");
305
+ const seconds = String(date.getSeconds()).padStart(2, "0");
306
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
307
+ };
308
+ var getISOTimestamp = () => {
309
+ return new Date().toISOString();
310
+ };
311
+ var getUnixTimestamp = () => {
312
+ return Math.floor(Date.now() / 1000);
313
+ };
314
+ var getRelativeTime = (date) => {
315
+ const now = Date.now();
316
+ const timestamp = date instanceof Date ? date.getTime() : date;
317
+ const diff = now - timestamp;
318
+ const seconds = Math.floor(diff / 1000);
319
+ const minutes = Math.floor(seconds / 60);
320
+ const hours = Math.floor(minutes / 60);
321
+ const days = Math.floor(hours / 24);
322
+ if (seconds < 60)
323
+ return `${seconds} second${seconds !== 1 ? "s" : ""} ago`;
324
+ if (minutes < 60)
325
+ return `${minutes} minute${minutes !== 1 ? "s" : ""} ago`;
326
+ if (hours < 24)
327
+ return `${hours} hour${hours !== 1 ? "s" : ""} ago`;
328
+ return `${days} day${days !== 1 ? "s" : ""} ago`;
329
+ };
330
+ var formatCustom = (format, date = new Date) => {
331
+ const tokens = {
332
+ YYYY: date.getFullYear(),
333
+ MM: String(date.getMonth() + 1).padStart(2, "0"),
334
+ DD: String(date.getDate()).padStart(2, "0"),
335
+ HH: String(date.getHours()).padStart(2, "0"),
336
+ mm: String(date.getMinutes()).padStart(2, "0"),
337
+ ss: String(date.getSeconds()).padStart(2, "0"),
338
+ SSS: String(date.getMilliseconds()).padStart(3, "0")
339
+ };
340
+ let result = format;
341
+ Object.entries(tokens).forEach(([token, value]) => {
342
+ result = result.replace(token, value);
343
+ });
344
+ return result;
345
+ };
346
+ module.exports = getTimestamp;
347
+ module.exports.getTimestamp = getTimestamp;
348
+ module.exports.getTimestampWithMs = getTimestampWithMs;
349
+ module.exports.getFullTimestamp = getFullTimestamp;
350
+ module.exports.getISOTimestamp = getISOTimestamp;
351
+ module.exports.getUnixTimestamp = getUnixTimestamp;
352
+ module.exports.getRelativeTime = getRelativeTime;
353
+ module.exports.formatCustom = formatCustom;
354
+ });
355
+
356
+ // node_modules/ernest-logger/utils/formatter.js
357
+ var require_formatter = __commonJS((exports, module) => {
358
+ var colors = require_colors();
359
+ var createBadge = (text, color) => {
360
+ const bg = "bg" + color.charAt(0).toUpperCase() + color.slice(1);
361
+ const bgColor = colors[bg] || colors.bgBlue;
362
+ const textColor = colors.white + colors.bold;
363
+ return bgColor + textColor + ` ${text} ` + colors.reset;
364
+ };
365
+ var createBox = (message, color, emoji = "") => {
366
+ const lines = message.split(`
367
+ `);
368
+ const maxLength = Math.max(...lines.map((line) => stripAnsi(line).length));
369
+ const topLeft = "╔";
370
+ const topRight = "╗";
371
+ const bottomLeft = "╚";
372
+ const bottomRight = "╝";
373
+ const horizontal = "═";
374
+ const vertical = "║";
375
+ const colorCode = colors[color] || colors.blue;
376
+ const horizontalLine = horizontal.repeat(maxLength + 4);
377
+ let box = colorCode + topLeft + horizontalLine + topRight + colors.reset + `
378
+ `;
379
+ if (emoji) {
380
+ const emojiPadding = " ".repeat(maxLength + 2 - emoji.length);
381
+ box += colorCode + vertical + colors.reset + ` ${emoji}${emojiPadding} ` + colorCode + vertical + colors.reset + `
382
+ `;
383
+ box += colorCode + vertical + horizontal.repeat(maxLength + 4) + vertical + colors.reset + `
384
+ `;
385
+ }
386
+ lines.forEach((line) => {
387
+ const stripped = stripAnsi(line);
388
+ const padding = " ".repeat(maxLength - stripped.length);
389
+ box += colorCode + vertical + colors.reset + ` ${line}${padding} ` + colorCode + vertical + colors.reset + `
390
+ `;
391
+ });
392
+ box += colorCode + bottomLeft + horizontalLine + bottomRight + colors.reset;
393
+ return box;
394
+ };
395
+ var createBanner = (text, char = "=") => {
396
+ const length = stripAnsi(text).length;
397
+ const line = char.repeat(length + 4);
398
+ return `${line}
399
+ ${text}
400
+ ${line}`;
401
+ };
402
+ var stripAnsi = (text) => {
403
+ return text.replace(/\x1b\[[0-9;]*m/g, "");
404
+ };
405
+ var truncate = (text, maxLength) => {
406
+ if (text.length <= maxLength)
407
+ return text;
408
+ return text.substring(0, maxLength - 3) + "...";
409
+ };
410
+ var center = (text, width) => {
411
+ const stripped = stripAnsi(text);
412
+ const padding = Math.max(0, width - stripped.length);
413
+ const leftPad = Math.floor(padding / 2);
414
+ const rightPad = padding - leftPad;
415
+ return " ".repeat(leftPad) + text + " ".repeat(rightPad);
416
+ };
417
+ var padRight = (text, width) => {
418
+ const stripped = stripAnsi(text);
419
+ const padding = Math.max(0, width - stripped.length);
420
+ return text + " ".repeat(padding);
421
+ };
422
+ var padLeft = (text, width) => {
423
+ const stripped = stripAnsi(text);
424
+ const padding = Math.max(0, width - stripped.length);
425
+ return " ".repeat(padding) + text;
426
+ };
427
+ var createProgressBar = (current, total, width = 20) => {
428
+ const percentage = Math.min(100, Math.max(0, current / total * 100));
429
+ const filled = Math.round(percentage / 100 * width);
430
+ const empty = width - filled;
431
+ const bar = colors.green + "█".repeat(filled) + colors.dim + "░".repeat(empty) + colors.reset;
432
+ const percent = `${percentage.toFixed(1)}%`;
433
+ return `${bar} ${percent}`;
434
+ };
435
+ var createSeparator = (length = 50, char = "-", color = "dim") => {
436
+ const colorCode = colors[color] || colors.dim;
437
+ return colorCode + char.repeat(length) + colors.reset;
438
+ };
439
+ var formatKeyValue = (key, value, keyWidth = 20) => {
440
+ const paddedKey = padRight(colors.cyan + key + colors.reset, keyWidth + 9);
441
+ return `${paddedKey}: ${colors.white}${value}${colors.reset}`;
442
+ };
443
+ var createList = (items, bullet = "•") => {
444
+ return items.map((item) => ` ${colors.dim}${bullet}${colors.reset} ${item}`).join(`
445
+ `);
446
+ };
447
+ var highlight = (text, bgColor = "bgYellow") => {
448
+ const bg = colors[bgColor] || colors.bgYellow;
449
+ return bg + colors.black + text + colors.reset;
450
+ };
451
+ module.exports = {
452
+ createBadge,
453
+ createBox,
454
+ createBanner,
455
+ stripAnsi,
456
+ truncate,
457
+ center,
458
+ padRight,
459
+ padLeft,
460
+ createProgressBar,
461
+ createSeparator,
462
+ formatKeyValue,
463
+ createList,
464
+ highlight
465
+ };
466
+ });
467
+
468
+ // node_modules/ernest-logger/index.js
469
+ var require_ernest_logger = __commonJS((exports, module) => {
470
+ var fs = __require("fs");
471
+ var path = __require("path");
472
+ var colors = require_colors();
473
+ var emojis = require_emojis();
474
+ var getTimestamp = require_timestamp();
475
+ var formatter = require_formatter();
476
+ var levelPriority = {
477
+ trace: 0,
478
+ debug: 1,
479
+ info: 2,
480
+ success: 3,
481
+ warn: 4,
482
+ error: 5,
483
+ fatal: 6
484
+ };
485
+ var globalConfig = {
486
+ time: true,
487
+ emoji: true,
488
+ level: "debug",
489
+ file: false,
490
+ filePath: path.join(process.cwd(), "ernest.log"),
491
+ colorize: true,
492
+ prefix: "",
493
+ maxFileSize: 5 * 1024 * 1024,
494
+ customLevels: {}
495
+ };
496
+ var rotateLogFile = (filePath, maxSize) => {
497
+ try {
498
+ const stats = fs.statSync(filePath);
499
+ if (stats.size > maxSize) {
500
+ const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
501
+ const rotatedPath = filePath.replace(".log", `-${timestamp}.log`);
502
+ fs.renameSync(filePath, rotatedPath);
503
+ }
504
+ } catch (err) {}
505
+ };
506
+ var createLogger = (options = {}) => {
507
+ const config = { ...globalConfig, ...options };
508
+ const formatMessage = (level, message, color) => {
509
+ if (levelPriority[level] < levelPriority[config.level])
510
+ return null;
511
+ let output = "";
512
+ if (config.time) {
513
+ const timestamp = getTimestamp();
514
+ output += config.colorize ? colors.dim + `[${timestamp}]` + colors.reset + " " : `[${timestamp}] `;
515
+ }
516
+ if (config.prefix) {
517
+ output += config.colorize ? colors.dim + config.prefix + colors.reset + " " : config.prefix + " ";
518
+ }
519
+ if (config.emoji && emojis[level]) {
520
+ output += `${emojis[level]} `;
521
+ }
522
+ const levelBadge = formatter.createBadge(level.toUpperCase(), color);
523
+ output += config.colorize ? levelBadge + " " : `[${level.toUpperCase()}] `;
524
+ output += config.colorize ? colors[color] + message + colors.reset : message;
525
+ return output;
526
+ };
527
+ const writeToFile = (message) => {
528
+ if (!config.file)
529
+ return;
530
+ try {
531
+ rotateLogFile(config.filePath, config.maxFileSize);
532
+ const plainMessage = message.replace(/\x1b\[[0-9;]*m/g, "");
533
+ fs.appendFileSync(config.filePath, plainMessage + `
534
+ `);
535
+ } catch (err) {
536
+ console.error("Failed to write to log file:", err.message);
537
+ }
538
+ };
539
+ const logMessage = (level, color, message) => {
540
+ const formatted = formatMessage(level, message, color);
541
+ if (!formatted)
542
+ return;
543
+ console.log(formatted);
544
+ writeToFile(formatted);
545
+ };
546
+ const logger = {
547
+ trace: (msg) => logMessage("trace", "dim", msg),
548
+ debug: (msg) => logMessage("debug", "cyan", msg),
549
+ info: (msg) => logMessage("info", "blue", msg),
550
+ success: (msg) => logMessage("success", "green", msg),
551
+ warn: (msg) => logMessage("warn", "yellow", msg),
552
+ error: (msg) => logMessage("error", "red", msg),
553
+ fatal: (msg) => logMessage("fatal", "brightRed", msg),
554
+ start: (msg) => logMessage("info", "brightGreen", `▶️ ${msg}`),
555
+ stop: (msg) => logMessage("info", "brightRed", `⏹️ ${msg}`),
556
+ network: (msg) => logMessage("info", "brightCyan", `\uD83C\uDF10 ${msg}`),
557
+ db: (msg) => logMessage("info", "brightMagenta", `\uD83D\uDCBE ${msg}`),
558
+ api: (msg) => logMessage("info", "brightBlue", `\uD83D\uDD0C ${msg}`),
559
+ security: (msg) => logMessage("warn", "brightYellow", `\uD83D\uDD12 ${msg}`),
560
+ bigLog: (message, options2 = {}) => {
561
+ const color = options2.color || "blue";
562
+ const emoji = options2.emoji || "\uD83D\uDCE3";
563
+ const boxed = formatter.createBox(message, color, emoji);
564
+ console.log(boxed);
565
+ if (config.file)
566
+ writeToFile(boxed);
567
+ },
568
+ table: (data) => {
569
+ console.table(data);
570
+ if (config.file) {
571
+ writeToFile(`
572
+ [TABLE DATA]
573
+ ` + JSON.stringify(data, null, 2));
574
+ }
575
+ },
576
+ group: (label) => console.group(label),
577
+ groupEnd: () => console.groupEnd(),
578
+ time: (label) => console.time(label),
579
+ timeEnd: (label) => console.timeEnd(label),
580
+ json: (obj, label = "") => {
581
+ const output = label ? `${label}:
582
+ ` : "";
583
+ const formatted = output + JSON.stringify(obj, null, 2);
584
+ console.log(config.colorize ? colors.cyan + formatted + colors.reset : formatted);
585
+ if (config.file)
586
+ writeToFile(formatted);
587
+ },
588
+ log: {
589
+ trace: {
590
+ dim: (msg) => logMessage("trace", "dim", msg),
591
+ white: (msg) => logMessage("trace", "white", msg)
592
+ },
593
+ debug: {
594
+ cyan: (msg) => logMessage("debug", "cyan", msg),
595
+ blue: (msg) => logMessage("debug", "blue", msg),
596
+ magenta: (msg) => logMessage("debug", "magenta", msg)
597
+ },
598
+ info: {
599
+ blue: (msg) => logMessage("info", "blue", msg),
600
+ cyan: (msg) => logMessage("info", "cyan", msg),
601
+ white: (msg) => logMessage("info", "white", msg)
602
+ },
603
+ success: {
604
+ green: (msg) => logMessage("success", "green", msg),
605
+ brightGreen: (msg) => logMessage("success", "brightGreen", msg)
606
+ },
607
+ warn: {
608
+ yellow: (msg) => logMessage("warn", "yellow", msg),
609
+ brightYellow: (msg) => logMessage("warn", "brightYellow", msg)
610
+ },
611
+ error: {
612
+ red: (msg) => logMessage("error", "red", msg),
613
+ brightRed: (msg) => logMessage("error", "brightRed", msg),
614
+ magenta: (msg) => logMessage("error", "magenta", msg)
615
+ },
616
+ fatal: {
617
+ brightRed: (msg) => logMessage("fatal", "brightRed", msg),
618
+ bgRed: (msg) => logMessage("fatal", "bgRed", msg)
619
+ }
620
+ },
621
+ configure: (newConfig) => {
622
+ Object.assign(config, newConfig);
623
+ return logger;
624
+ },
625
+ getConfig: () => ({ ...config }),
626
+ enableTime: () => {
627
+ config.time = true;
628
+ return logger;
629
+ },
630
+ disableTime: () => {
631
+ config.time = false;
632
+ return logger;
633
+ },
634
+ enableEmoji: () => {
635
+ config.emoji = true;
636
+ return logger;
637
+ },
638
+ disableEmoji: () => {
639
+ config.emoji = false;
640
+ return logger;
641
+ },
642
+ enableFile: () => {
643
+ config.file = true;
644
+ return logger;
645
+ },
646
+ disableFile: () => {
647
+ config.file = false;
648
+ return logger;
649
+ },
650
+ setLevel: (level) => {
651
+ config.level = level;
652
+ return logger;
653
+ }
654
+ };
655
+ if (config.customLevels && Object.keys(config.customLevels).length > 0) {
656
+ Object.entries(config.customLevels).forEach(([level, { color, emoji, priority }]) => {
657
+ if (emoji)
658
+ emojis[level] = emoji;
659
+ if (priority !== undefined)
660
+ levelPriority[level] = priority;
661
+ logger[level] = (msg) => logMessage(level, color, msg);
662
+ logger.log[level] = {
663
+ [color]: (msg) => logMessage(level, color, msg)
664
+ };
665
+ });
666
+ }
667
+ return logger;
668
+ };
669
+ var defaultLogger = createLogger();
670
+ module.exports = defaultLogger;
671
+ module.exports.createLogger = createLogger;
672
+ module.exports.setGlobalConfig = (config) => {
673
+ Object.assign(globalConfig, config);
674
+ };
675
+ });
676
+
677
+ // piggy/launch/spawn.ts
678
+ import { spawn as nodeSpawn } from "child_process";
679
+ import { execSync } from "child_process";
680
+ import { platform } from "os";
681
+
682
+ // piggy/launch/detect.ts
683
+ import { existsSync } from "fs";
684
+ import { join } from "path";
685
+
686
+ // piggy/logger/index.ts
687
+ var import_ernest_logger = __toESM(require_ernest_logger(), 1);
688
+ var logger = import_ernest_logger.createLogger({
689
+ time: true,
690
+ file: true,
691
+ filePath: "./piggy.log",
692
+ prefix: "[PIGGY]",
693
+ emoji: true,
694
+ level: "trace",
695
+ customLevels: {
696
+ info: {
697
+ color: "blue",
698
+ emoji: "ℹ️",
699
+ priority: 2
700
+ },
701
+ success: {
702
+ color: "green",
703
+ emoji: "✅",
704
+ priority: 2
705
+ },
706
+ error: {
707
+ color: "red",
708
+ emoji: "❌",
709
+ priority: 5
710
+ },
711
+ warn: {
712
+ color: "yellow",
713
+ emoji: "⚠️",
714
+ priority: 4
715
+ },
716
+ debug: {
717
+ color: "magenta",
718
+ emoji: "\uD83D\uDC1E",
719
+ priority: 1
720
+ },
721
+ network: {
722
+ color: "brightCyan",
723
+ emoji: "\uD83C\uDF10",
724
+ priority: 2
725
+ },
726
+ db: {
727
+ color: "brightMagenta",
728
+ emoji: "\uD83D\uDDC4️",
729
+ priority: 2
730
+ },
731
+ security: {
732
+ color: "brightRed",
733
+ emoji: "\uD83D\uDD12",
734
+ priority: 3
735
+ }
736
+ }
737
+ });
738
+ logger.info("logger initialized");
739
+ var logger_default = logger;
740
+
741
+ // piggy/launch/detect.ts
742
+ var BINARY_NAMES = {
743
+ headless: "nothing-browser-headless",
744
+ headful: "nothing-browser-headful"
745
+ };
746
+ function detectBinary(mode = "headless") {
747
+ const cwd = process.cwd();
748
+ const name = BINARY_NAMES[mode];
749
+ if (process.platform === "win32") {
750
+ const p2 = join(cwd, `${name}.exe`);
751
+ if (existsSync(p2)) {
752
+ logger_default.success(`Binary found (${mode}): ${p2}`);
753
+ return p2;
754
+ }
755
+ }
756
+ const p = join(cwd, name);
757
+ if (existsSync(p)) {
758
+ logger_default.success(`Binary found (${mode}): ${p}`);
759
+ return p;
760
+ }
761
+ logger_default.error(`❌ Binary not found in project root: ${name}`);
762
+ logger_default.error("");
763
+ logger_default.error("Download from:");
764
+ logger_default.error(" https://github.com/BunElysiaReact/nothing-browser/releases/");
765
+ logger_default.error("");
766
+ logger_default.error(`Place in: ${cwd}/${name}${process.platform === "win32" ? ".exe" : ""}`);
767
+ if (process.platform !== "win32") {
768
+ logger_default.error(`Then run: chmod +x ${name}`);
769
+ }
770
+ return null;
771
+ }
772
+
773
+ // piggy/launch/spawn.ts
774
+ var activeProcess = null;
775
+ var extraProcesses = [];
776
+ var isBun = typeof globalThis.Bun !== "undefined";
777
+ function killAllBrowsers() {
778
+ try {
779
+ logger_default.info("Cleaning up existing browser processes...");
780
+ if (platform() === "win32") {
781
+ execSync("taskkill /F /IM nothing-browser-headless.exe 2>nul || true", { stdio: "ignore" });
782
+ execSync("taskkill /F /IM nothing-browser-headful.exe 2>nul || true", { stdio: "ignore" });
783
+ execSync("taskkill /F /IM QtWebEngineProcess.exe 2>nul || true", { stdio: "ignore" });
784
+ } else {
785
+ execSync("pkill -f nothing-browser-headless 2>/dev/null || true", { stdio: "ignore" });
786
+ execSync("pkill -f nothing-browser-headful 2>/dev/null || true", { stdio: "ignore" });
787
+ execSync("pkill -f QtWebEngineProcess 2>/dev/null || true", { stdio: "ignore" });
788
+ execSync("rm -f /tmp/piggy", { stdio: "ignore" });
789
+ }
790
+ } catch {}
791
+ }
792
+ async function spawnBrowser(mode = "headless") {
793
+ killAllBrowsers();
794
+ await new Promise((resolve) => setTimeout(resolve, 500));
795
+ const binaryPath = detectBinary(mode);
796
+ if (!binaryPath) {
797
+ throw new Error(`Binary not found (${mode}). Cannot launch.`);
798
+ }
799
+ logger_default.info(`Spawning Nothing Browser (${mode}) from: ${binaryPath}`);
800
+ if (isBun) {
801
+ const Bun = globalThis.Bun;
802
+ activeProcess = Bun.spawn([binaryPath], {
803
+ stdio: ["ignore", "pipe", "pipe"],
804
+ env: process.env
805
+ });
806
+ if (activeProcess.stdout) {
807
+ const reader = activeProcess.stdout.getReader();
808
+ const read = async () => {
809
+ const { done, value } = await reader.read();
810
+ if (!done) {
811
+ logger_default.debug(`[Browser] ${new TextDecoder().decode(value)}`);
812
+ read();
813
+ }
814
+ };
815
+ read();
816
+ }
817
+ activeProcess.exited.then((code) => {
818
+ logger_default.warn(`Browser process exited with code: ${code}`);
819
+ activeProcess = null;
820
+ });
821
+ } else {
822
+ activeProcess = nodeSpawn(binaryPath, [], {
823
+ stdio: ["ignore", "pipe", "pipe"],
824
+ env: process.env
825
+ });
826
+ if (activeProcess.stdout) {
827
+ activeProcess.stdout.on("data", (data) => {
828
+ logger_default.debug(`[Browser] ${data.toString()}`);
829
+ });
830
+ }
831
+ if (activeProcess.stderr) {
832
+ activeProcess.stderr.on("data", (data) => {
833
+ logger_default.debug(`[Browser Error] ${data.toString()}`);
834
+ });
835
+ }
836
+ activeProcess.on("exit", (code) => {
837
+ logger_default.warn(`Browser process exited with code: ${code}`);
838
+ activeProcess = null;
839
+ });
840
+ }
841
+ await new Promise((resolve) => setTimeout(resolve, 2000));
842
+ if (activeProcess) {
843
+ logger_default.success(`Browser spawned and running (${mode})`);
844
+ } else {
845
+ logger_default.error("Browser started but exited immediately");
846
+ }
847
+ return binaryPath;
848
+ }
849
+ async function spawnBrowserOnSocket(socketName, mode = "headless") {
850
+ const binaryPath = detectBinary(mode);
851
+ if (!binaryPath) {
852
+ throw new Error(`Binary not found (${mode}). Cannot launch.`);
853
+ }
854
+ logger_default.info(`Spawning browser (${mode}) on socket: ${socketName}`);
855
+ if (isBun) {
856
+ const Bun = globalThis.Bun;
857
+ const proc = Bun.spawn([binaryPath], {
858
+ stdio: ["ignore", "pipe", "pipe"],
859
+ env: { ...process.env, PIGGY_SOCKET: socketName }
860
+ });
861
+ extraProcesses.push(proc);
862
+ proc.exited.then((code) => {
863
+ logger_default.warn(`Browser on socket ${socketName} exited with code: ${code}`);
864
+ });
865
+ } else {
866
+ const proc = nodeSpawn(binaryPath, [], {
867
+ stdio: ["ignore", "pipe", "pipe"],
868
+ env: { ...process.env, PIGGY_SOCKET: socketName }
869
+ });
870
+ extraProcesses.push(proc);
871
+ proc.on("exit", (code) => {
872
+ logger_default.warn(`Browser on socket ${socketName} exited with code: ${code}`);
873
+ });
874
+ }
875
+ await new Promise((resolve) => setTimeout(resolve, 1000));
876
+ logger_default.success(`Browser spawned (${mode}) on socket: ${socketName}`);
877
+ }
878
+ function killBrowser() {
879
+ if (activeProcess) {
880
+ logger_default.info("Killing browser process...");
881
+ if (isBun) {
882
+ activeProcess.kill();
883
+ } else {
884
+ activeProcess.kill("SIGTERM");
885
+ }
886
+ activeProcess = null;
887
+ }
888
+ for (const proc of extraProcesses) {
889
+ if (isBun) {
890
+ proc.kill();
891
+ } else {
892
+ proc.kill("SIGTERM");
893
+ }
894
+ }
895
+ extraProcesses.length = 0;
896
+ }
897
+ export {
898
+ spawnBrowserOnSocket,
899
+ spawnBrowser,
900
+ killBrowser,
901
+ killAllBrowsers
902
+ };