@visulima/pail 4.0.0-alpha.3 → 4.0.0-alpha.5

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 (27) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/index.browser.js +1488 -2
  3. package/dist/index.server.js +2656 -12
  4. package/dist/interactive/index.js +1 -1
  5. package/dist/packem_shared/AbstractJsonReporter-DWRpTtGw.js +204 -0
  6. package/dist/packem_shared/{interactive-stream-hook-DG4BtN12.js → InteractiveStreamHook-ePIURL_U.js} +1 -9
  7. package/dist/packem_shared/{JsonReporter-VzgyLEYz.js → JsonReporter-BV5lMnJX.js} +1 -1
  8. package/dist/packem_shared/{PrettyReporter-DySIXBjQ.js → PrettyReporter-BYL3NrdA.js} +49 -4
  9. package/dist/packem_shared/{format-label-De49vNPd.js → PrettyReporter-DLQtmATi.js} +267 -2
  10. package/dist/packem_shared/Spinner-B9JUdsbY.js +2150 -0
  11. package/dist/packem_shared/abstract-pretty-reporter-DckLMlGF.js +2496 -0
  12. package/dist/packem_shared/constants-B1RjD_ps.js +99 -0
  13. package/dist/packem_shared/getBarChar-BWj1UrH3.js +404 -0
  14. package/dist/packem_shared/{index-BomQ3E6J.js → index-DnkF86LQ.js} +9 -1
  15. package/dist/processor/message-formatter-processor.js +648 -1
  16. package/dist/reporter/file/json-file-reporter.js +1 -1
  17. package/dist/reporter/http/abstract-http-reporter.js +1 -1
  18. package/dist/reporter/json/index.js +2 -2
  19. package/dist/reporter/pretty/index.browser.js +1 -1
  20. package/dist/reporter/pretty/index.js +1 -1
  21. package/dist/reporter/simple/simple-reporter.server.js +1 -6
  22. package/package.json +4 -4
  23. package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +0 -21
  24. package/dist/packem_shared/PrettyReporter-C2wVB7yu.js +0 -222
  25. package/dist/packem_shared/abstract-pretty-reporter-Di_sdm2r.js +0 -50
  26. package/dist/packem_shared/get-longest-label-C9PWeyKq.js +0 -9
  27. package/dist/packem_shared/pail.browser-u2CSR_af.js +0 -1427
@@ -0,0 +1,99 @@
1
+ const LOG_TYPES = {
2
+ alert: {
3
+ color: "red",
4
+ label: "alert",
5
+ logLevel: "alert"
6
+ },
7
+ await: {
8
+ color: "blue",
9
+ label: "awaiting",
10
+ logLevel: "informational"
11
+ },
12
+ complete: {
13
+ color: "cyan",
14
+ label: "complete",
15
+ logLevel: "informational"
16
+ },
17
+ critical: {
18
+ color: "redBright",
19
+ label: "critical",
20
+ logLevel: "critical"
21
+ },
22
+ debug: {
23
+ color: "gray",
24
+ label: "debug",
25
+ logLevel: "debug"
26
+ },
27
+ emergency: {
28
+ color: "redBright",
29
+ label: "emergency",
30
+ logLevel: "emergency"
31
+ },
32
+ error: {
33
+ color: "red",
34
+ label: "error",
35
+ logLevel: "error"
36
+ },
37
+ info: {
38
+ color: "blueBright",
39
+ label: "info",
40
+ logLevel: "informational"
41
+ },
42
+ log: {
43
+ label: "",
44
+ logLevel: "informational"
45
+ },
46
+ notice: {
47
+ color: "magentaBright",
48
+ label: "notice",
49
+ logLevel: "notice"
50
+ },
51
+ pending: {
52
+ color: "magenta",
53
+ label: "pending",
54
+ logLevel: "informational"
55
+ },
56
+ start: {
57
+ color: "greenBright",
58
+ label: "start",
59
+ logLevel: "informational"
60
+ },
61
+ stop: {
62
+ color: "red",
63
+ label: "stop",
64
+ logLevel: "informational"
65
+ },
66
+ success: {
67
+ color: "green",
68
+ label: "success",
69
+ logLevel: "informational"
70
+ },
71
+ trace: {
72
+ color: "cyanBright",
73
+ label: "trace",
74
+ logLevel: "trace"
75
+ },
76
+ wait: {
77
+ color: "blue",
78
+ label: "waiting",
79
+ logLevel: "informational"
80
+ },
81
+ warn: {
82
+ color: "yellow",
83
+ label: "warning",
84
+ logLevel: "warning"
85
+ },
86
+ warning: {
87
+ color: "yellow",
88
+ label: "warning",
89
+ logLevel: "warning"
90
+ },
91
+ watch: {
92
+ color: "yellowBright",
93
+ label: "watching",
94
+ logLevel: "informational"
95
+ }
96
+ };
97
+ const EMPTY_SYMBOL = /* @__PURE__ */ Symbol("EMPTY");
98
+
99
+ export { EMPTY_SYMBOL as E, LOG_TYPES as L };
@@ -0,0 +1,404 @@
1
+ const CHAR_GRADIENTS = {
2
+ default: ["█", "▓", "▒", "░"],
3
+ rect: ["▬", "▮", "▯", "▭"]
4
+ };
5
+ const BAR_REGEX = /\[([^[\]]*)\]/u;
6
+ const getBarChar = (char, style, complete = true) => {
7
+ if (char) {
8
+ return char;
9
+ }
10
+ switch (style) {
11
+ case "ascii": {
12
+ return complete ? "#" : "-";
13
+ }
14
+ case "filled": {
15
+ return complete ? "█" : " ";
16
+ }
17
+ case "rect": {
18
+ return complete ? "▬" : "▭";
19
+ }
20
+ case "shades_classic": {
21
+ return complete ? "█" : "░";
22
+ }
23
+ case "shades_grey": {
24
+ return complete ? "▓" : "░";
25
+ }
26
+ case "solid": {
27
+ return complete ? "█" : " ";
28
+ }
29
+ default: {
30
+ return complete ? "█" : "░";
31
+ }
32
+ }
33
+ };
34
+ const applyStyleToOptions = (options) => {
35
+ if (!options.style) {
36
+ return options;
37
+ }
38
+ const { style } = options;
39
+ const result = { ...options };
40
+ if (result.barCompleteChar === void 0) {
41
+ result.barCompleteChar = getBarChar(void 0, style, true);
42
+ }
43
+ if (result.barIncompleteChar === void 0) {
44
+ result.barIncompleteChar = getBarChar(void 0, style, false);
45
+ }
46
+ if (result.barGlue === void 0) {
47
+ result.barGlue = "";
48
+ }
49
+ return result;
50
+ };
51
+ class ProgressBar {
52
+ options;
53
+ current;
54
+ startTime;
55
+ interactiveManager;
56
+ isActive = false;
57
+ payload;
58
+ /**
59
+ * Creates a new progress bar instance.
60
+ * @param options Configuration options for the progress bar
61
+ * @param interactiveManager Optional interactive manager for rendering
62
+ * @param payload Optional initial payload data for format placeholders
63
+ */
64
+ constructor(options, interactiveManager, payload) {
65
+ const isCompleteArray = Array.isArray(options.barCompleteChar);
66
+ const isIncompleteArray = Array.isArray(options.barIncompleteChar);
67
+ const isGradientMode = isCompleteArray || isIncompleteArray;
68
+ const completeChar = isCompleteArray ? options.barCompleteChar : getBarChar(options.barCompleteChar, "shades_classic");
69
+ const incompleteChar = isIncompleteArray ? options.barIncompleteChar : getBarChar(options.barIncompleteChar, "shades_classic", false);
70
+ this.options = {
71
+ barCompleteChar: completeChar,
72
+ barIncompleteChar: incompleteChar,
73
+ current: 0,
74
+ fps: 10,
75
+ width: 40,
76
+ ...options
77
+ };
78
+ if (isGradientMode) {
79
+ if (!Array.isArray(this.options.barCompleteChar)) {
80
+ this.options.barCompleteChar = [this.options.barCompleteChar];
81
+ }
82
+ if (!Array.isArray(this.options.barIncompleteChar)) {
83
+ this.options.barIncompleteChar = [this.options.barIncompleteChar];
84
+ }
85
+ }
86
+ this.current = this.options.current ?? 0;
87
+ this.startTime = Date.now();
88
+ this.interactiveManager = interactiveManager;
89
+ this.payload = payload;
90
+ }
91
+ /**
92
+ * Updates the progress bar to a new value.
93
+ * @param current The current progress value
94
+ * @param payload Optional payload data to merge with existing data
95
+ */
96
+ update(current, payload) {
97
+ this.current = Math.min(current, this.options.total);
98
+ if (payload) {
99
+ this.payload = { ...this.payload, ...payload };
100
+ }
101
+ if (this.interactiveManager && this.isActive) {
102
+ const progressBar = this.render();
103
+ this.interactiveManager.update("stdout", [progressBar]);
104
+ }
105
+ }
106
+ /**
107
+ * Increments the progress bar by a specified step.
108
+ * @param step Amount to increment (default: 1)
109
+ * @param payload Optional payload data to merge with existing data
110
+ */
111
+ increment(step = 1, payload) {
112
+ this.update(this.current + step, payload);
113
+ }
114
+ /**
115
+ * Renders the progress bar as a formatted string.
116
+ * @returns Formatted progress bar string with all placeholders replaced
117
+ */
118
+ // eslint-disable-next-line sonarjs/cognitive-complexity
119
+ render() {
120
+ const total = this.options.total > 0 ? this.options.total : 1;
121
+ const width = Math.max(0, this.options.width ?? 40);
122
+ const percentage = Math.max(0, Math.min(100, Math.round(this.current / total * 100)));
123
+ const filled = Math.max(0, Math.min(width, Math.round(this.current / total * width)));
124
+ const empty = width - filled;
125
+ let bar;
126
+ if (Array.isArray(this.options.barCompleteChar) || Array.isArray(this.options.barIncompleteChar)) {
127
+ const completeChars = Array.isArray(this.options.barCompleteChar) ? this.options.barCompleteChar : void 0;
128
+ const incompleteChars = Array.isArray(this.options.barIncompleteChar) ? this.options.barIncompleteChar : void 0;
129
+ const completeChar = completeChars?.[completeChars.length - 1] ?? (typeof this.options.barCompleteChar === "string" ? this.options.barCompleteChar : "█");
130
+ const incompleteChar = incompleteChars?.[0] ?? (typeof this.options.barIncompleteChar === "string" ? this.options.barIncompleteChar : "░");
131
+ const completeLength = completeChars?.length ?? 1;
132
+ const progressRatio = this.current / total;
133
+ const totalSteps = width * completeLength;
134
+ const currentStep = Math.round(progressRatio * totalSteps);
135
+ const fractional = currentStep % completeLength;
136
+ let barContent = "";
137
+ for (let i = 0; i < width; i += 1) {
138
+ if (i < filled) {
139
+ const isGradientBoundary = i === filled - 1 && fractional > 0 && completeChars;
140
+ barContent += isGradientBoundary ? completeChars[Math.max(0, fractional - 1)] : completeChar;
141
+ } else {
142
+ barContent += incompleteChar;
143
+ }
144
+ }
145
+ bar = barContent;
146
+ } else {
147
+ const completeChar = typeof this.options.barCompleteChar === "string" ? this.options.barCompleteChar : "█";
148
+ const incompleteChar = typeof this.options.barIncompleteChar === "string" ? this.options.barIncompleteChar : "░";
149
+ bar = completeChar.repeat(filled) + incompleteChar.repeat(empty);
150
+ }
151
+ let format = this.options.format ?? "progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}";
152
+ if (this.payload) {
153
+ for (const [k, v] of Object.entries(this.payload)) {
154
+ format = format.replaceAll(`{${k}}`, String(v));
155
+ }
156
+ }
157
+ const eta = this.calculateETA();
158
+ return format.replaceAll("{bar}", bar).replaceAll("{percentage}", String(percentage)).replaceAll("{value}", String(this.current)).replaceAll("{total}", String(this.options.total)).replaceAll("{eta}", String(eta));
159
+ }
160
+ /**
161
+ * Starts the progress bar.
162
+ * @param total Optional total value to set
163
+ * @param startValue Optional starting value
164
+ * @param payload Optional initial payload data
165
+ */
166
+ start(total, startValue, payload) {
167
+ if (total !== void 0) {
168
+ this.options.total = total;
169
+ }
170
+ if (startValue !== void 0) {
171
+ this.current = startValue;
172
+ }
173
+ this.startTime = Date.now();
174
+ this.isActive = true;
175
+ if (this.interactiveManager) {
176
+ this.interactiveManager.hook();
177
+ this.update(this.current, payload);
178
+ }
179
+ }
180
+ /**
181
+ * Stops the progress bar and cleanup.
182
+ */
183
+ stop() {
184
+ this.isActive = false;
185
+ if (this.interactiveManager) {
186
+ this.interactiveManager.unhook(false);
187
+ }
188
+ }
189
+ calculateETA() {
190
+ if (this.current === 0) {
191
+ return 0;
192
+ }
193
+ const elapsed = (Date.now() - this.startTime) / 1e3;
194
+ if (elapsed < 0.1) {
195
+ return 0;
196
+ }
197
+ const rate = this.current / elapsed;
198
+ const remaining = this.options.total - this.current;
199
+ return Math.round(remaining / rate);
200
+ }
201
+ }
202
+ class MultiBarInstance extends ProgressBar {
203
+ multiBar;
204
+ constructor(multiBar, options, payload) {
205
+ super(options, void 0, payload);
206
+ this.multiBar = multiBar;
207
+ }
208
+ update(current, payload) {
209
+ super.update(current, payload);
210
+ this.multiBar.renderAll();
211
+ }
212
+ getBarState() {
213
+ const completeChar = Array.isArray(this.options.barCompleteChar) ? this.options.barCompleteChar[this.options.barCompleteChar.length - 1] : getBarChar(this.options.barCompleteChar, this.options.style ?? "shades_classic", true);
214
+ return {
215
+ char: completeChar ?? "█",
216
+ current: this.current,
217
+ total: this.options.total
218
+ };
219
+ }
220
+ }
221
+ class MultiProgressBar {
222
+ bars = /* @__PURE__ */ new Map();
223
+ options;
224
+ interactiveManager;
225
+ isActive = false;
226
+ nextBarId = 0;
227
+ composite = false;
228
+ barColors = /* @__PURE__ */ new Map();
229
+ /**
230
+ * Creates a new multi progress bar manager.
231
+ * @param options Configuration options for the progress bars
232
+ * @param interactiveManager Optional interactive manager for rendering
233
+ */
234
+ constructor(options = {}, interactiveManager) {
235
+ this.options = {
236
+ barCompleteChar: getBarChar(void 0, "shades_classic"),
237
+ barIncompleteChar: getBarChar(void 0, "shades_classic", false),
238
+ composite: false,
239
+ format: "progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}",
240
+ fps: 10,
241
+ ...options
242
+ };
243
+ this.composite = this.options.composite ?? false;
244
+ this.interactiveManager = interactiveManager;
245
+ }
246
+ /**
247
+ * Creates a new progress bar within this multi-bar manager.
248
+ * @param total Total value for the progress bar
249
+ * @param current Starting current value (default: 0)
250
+ * @param payload Optional initial payload data for format placeholders
251
+ * @returns The created progress bar instance
252
+ */
253
+ create(total, current = 0, payload) {
254
+ const barId = `bar_${this.nextBarId++}`;
255
+ const bar = new MultiBarInstance(
256
+ this,
257
+ {
258
+ barCompleteChar: this.options.barCompleteChar,
259
+ barIncompleteChar: this.options.barIncompleteChar,
260
+ current,
261
+ format: this.options.format,
262
+ fps: this.options.fps,
263
+ total,
264
+ width: 40
265
+ },
266
+ payload
267
+ );
268
+ this.bars.set(barId, bar);
269
+ if (!this.isActive && this.interactiveManager) {
270
+ this.interactiveManager.hook();
271
+ this.isActive = true;
272
+ this.renderAll();
273
+ }
274
+ return bar;
275
+ }
276
+ /**
277
+ * Removes a progress bar from the manager.
278
+ * @param bar The progress bar instance to remove
279
+ * @returns True if the bar was removed, false if not found
280
+ */
281
+ remove(bar) {
282
+ for (const [id, existingBar] of this.bars.entries()) {
283
+ if (existingBar === bar) {
284
+ this.bars.delete(id);
285
+ if (this.bars.size === 0) {
286
+ if (this.interactiveManager) {
287
+ this.interactiveManager.unhook(false);
288
+ }
289
+ this.isActive = false;
290
+ } else {
291
+ this.renderAll();
292
+ }
293
+ return true;
294
+ }
295
+ }
296
+ return false;
297
+ }
298
+ /**
299
+ * Renders all progress bars.
300
+ */
301
+ renderAll() {
302
+ if (!this.interactiveManager || !this.isActive) {
303
+ return;
304
+ }
305
+ const lines = [];
306
+ if (this.composite) {
307
+ const barsArray = [...this.bars.values()];
308
+ if (barsArray.length > 0) {
309
+ const compositeOutput = this.renderComposite(barsArray);
310
+ lines.push(compositeOutput);
311
+ }
312
+ } else {
313
+ for (const bar of this.bars.values()) {
314
+ lines.push(bar.render());
315
+ }
316
+ }
317
+ this.interactiveManager.update("stdout", lines);
318
+ }
319
+ /**
320
+ * Sets or removes a color function for a specific bar.
321
+ * @param bar The progress bar instance to color (must be from this MultiProgressBar)
322
+ * @param color Color function or undefined to remove color
323
+ */
324
+ setBarColor(bar, color) {
325
+ for (const instance of this.bars.values()) {
326
+ if (instance === bar) {
327
+ if (color) {
328
+ this.barColors.set(instance, color);
329
+ } else {
330
+ this.barColors.delete(instance);
331
+ }
332
+ break;
333
+ }
334
+ }
335
+ }
336
+ /**
337
+ * Stops all progress bars and cleanup.
338
+ */
339
+ // eslint-disable-next-line sonarjs/no-identical-functions
340
+ stop() {
341
+ this.isActive = false;
342
+ if (this.interactiveManager) {
343
+ this.interactiveManager.unhook(false);
344
+ }
345
+ }
346
+ renderComposite(bars) {
347
+ if (bars.length === 0) {
348
+ return "";
349
+ }
350
+ const firstBar = bars[0];
351
+ if (!firstBar) {
352
+ return "";
353
+ }
354
+ const output = firstBar.render();
355
+ const barMatch = output.match(BAR_REGEX);
356
+ if (!barMatch || !barMatch[1]) {
357
+ return output;
358
+ }
359
+ const width = barMatch[1].length;
360
+ const grid = Array.from({ length: width }, () => []);
361
+ bars.forEach((bar, index) => {
362
+ const state = bar.getBarState();
363
+ const filled = Math.round(state.current / state.total * width);
364
+ for (let i = 0; i < width; i += 1) {
365
+ if (i < filled) {
366
+ grid[i]?.push(index);
367
+ }
368
+ }
369
+ });
370
+ const composite = Array.from({ length: width }, (_, i) => this.getCompositeChar(bars, grid[i])).join("");
371
+ return output.replace(BAR_REGEX, `[${composite}]`);
372
+ }
373
+ getCompositeChar(bars, stack) {
374
+ if (!stack || stack.length === 0) {
375
+ const defaultBar = bars[0];
376
+ return defaultBar?.getBarState().char ?? "█";
377
+ }
378
+ const charGradient = CHAR_GRADIENTS[this.options.style === "rect" ? "rect" : "default"];
379
+ const char = charGradient?.[Math.min(stack.length - 1, charGradient.length - 1)] ?? "█";
380
+ let selectedBar;
381
+ let smallestPercent = 100;
382
+ for (const stackBarIndex of stack) {
383
+ const bar = bars[stackBarIndex];
384
+ if (!bar) {
385
+ continue;
386
+ }
387
+ const barState = bar.getBarState();
388
+ const barPercent = barState.current / barState.total * 100;
389
+ if (barPercent < smallestPercent || barPercent === smallestPercent && (selectedBar === void 0 || stackBarIndex > selectedBar)) {
390
+ smallestPercent = barPercent;
391
+ selectedBar = stackBarIndex;
392
+ }
393
+ }
394
+ const barIndex = selectedBar ?? stack[0];
395
+ const targetBar = bars[barIndex ?? 0];
396
+ if (!targetBar) {
397
+ return char;
398
+ }
399
+ const barColor = this.barColors.get(targetBar);
400
+ return barColor ? barColor(char) : char;
401
+ }
402
+ }
403
+
404
+ export { MultiBarInstance, MultiProgressBar, ProgressBar, applyStyleToOptions, getBarChar };
@@ -1,3 +1,11 @@
1
+ const getLongestLabel = (types) => {
2
+ const labels = Object.keys(types).map((x) => types[x].label ?? "");
3
+ if (labels.length === 0) {
4
+ return "";
5
+ }
6
+ return labels.reduce((x, y) => x.length > y.length ? x : y);
7
+ };
8
+
1
9
  const colorKeywords = /* @__PURE__ */ new Map([
2
10
  ["aliceblue", "#f0f8ff"],
3
11
  ["antiquewhite", "#faebd7"],
@@ -647,4 +655,4 @@ const build = (options = {}) => {
647
655
  return (f, arguments_ = [], formatOptions = {}) => format(f, arguments_, { ...formatOptions, formatters });
648
656
  };
649
657
 
650
- export { build as b, format as f };
658
+ export { build as b, format as f, getLongestLabel as g };