@visulima/fmt 1.1.15 → 1.1.17

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.
package/dist/index.mjs CHANGED
@@ -1,659 +1 @@
1
- var __defProp$1 = Object.defineProperty;
2
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
3
- const colorKeywords = /* @__PURE__ */ new Map([
4
- ["aliceblue", "#f0f8ff"],
5
- ["antiquewhite", "#faebd7"],
6
- ["aqua", "#00ffff"],
7
- ["aquamarine", "#7fffd4"],
8
- ["azure", "#f0ffff"],
9
- ["beige", "#f5f5dc"],
10
- ["bisque", "#ffe4c4"],
11
- ["black", "#000000"],
12
- ["blanchedalmond", "#ffebcd"],
13
- ["blue", "#0000ff"],
14
- ["blueviolet", "#8a2be2"],
15
- ["brown", "#a52a2a"],
16
- ["burlywood", "#deb887"],
17
- ["cadetblue", "#5f9ea0"],
18
- ["chartreuse", "#7fff00"],
19
- ["chocolate", "#d2691e"],
20
- ["coral", "#ff7f50"],
21
- ["cornflowerblue", "#6495ed"],
22
- ["cornsilk", "#fff8dc"],
23
- ["crimson", "#dc143c"],
24
- ["cyan", "#00ffff"],
25
- ["darkblue", "#00008b"],
26
- ["darkcyan", "#008b8b"],
27
- ["darkgoldenrod", "#b8860b"],
28
- ["darkgray", "#a9a9a9"],
29
- ["darkgreen", "#006400"],
30
- ["darkgrey", "#a9a9a9"],
31
- ["darkkhaki", "#bdb76b"],
32
- ["darkmagenta", "#8b008b"],
33
- ["darkolivegreen", "#556b2f"],
34
- ["darkorange", "#ff8c00"],
35
- ["darkorchid", "#9932cc"],
36
- ["darkred", "#8b0000"],
37
- ["darksalmon", "#e9967a"],
38
- ["darkseagreen", "#8fbc8f"],
39
- ["darkslateblue", "#483d8b"],
40
- ["darkslategray", "#2f4f4f"],
41
- ["darkslategrey", "#2f4f4f"],
42
- ["darkturquoise", "#00ced1"],
43
- ["darkviolet", "#9400d3"],
44
- ["deeppink", "#ff1493"],
45
- ["deepskyblue", "#00bfff"],
46
- ["dimgray", "#696969"],
47
- ["dimgrey", "#696969"],
48
- ["dodgerblue", "#1e90ff"],
49
- ["firebrick", "#b22222"],
50
- ["floralwhite", "#fffaf0"],
51
- ["forestgreen", "#228b22"],
52
- ["fuchsia", "#ff00ff"],
53
- ["gainsboro", "#dcdcdc"],
54
- ["ghostwhite", "#f8f8ff"],
55
- ["gold", "#ffd700"],
56
- ["goldenrod", "#daa520"],
57
- ["gray", "#808080"],
58
- ["green", "#008000"],
59
- ["greenyellow", "#adff2f"],
60
- ["grey", "#808080"],
61
- ["honeydew", "#f0fff0"],
62
- ["hotpink", "#ff69b4"],
63
- ["indianred", "#cd5c5c"],
64
- ["indigo", "#4b0082"],
65
- ["ivory", "#fffff0"],
66
- ["khaki", "#f0e68c"],
67
- ["lavender", "#e6e6fa"],
68
- ["lavenderblush", "#fff0f5"],
69
- ["lawngreen", "#7cfc00"],
70
- ["lemonchiffon", "#fffacd"],
71
- ["lightblue", "#add8e6"],
72
- ["lightcoral", "#f08080"],
73
- ["lightcyan", "#e0ffff"],
74
- ["lightgoldenrodyellow", "#fafad2"],
75
- ["lightgray", "#d3d3d3"],
76
- ["lightgreen", "#90ee90"],
77
- ["lightgrey", "#d3d3d3"],
78
- ["lightpink", "#ffb6c1"],
79
- ["lightsalmon", "#ffa07a"],
80
- ["lightseagreen", "#20b2aa"],
81
- ["lightskyblue", "#87cefa"],
82
- ["lightslategray", "#778899"],
83
- ["lightslategrey", "#778899"],
84
- ["lightsteelblue", "#b0c4de"],
85
- ["lightyellow", "#ffffe0"],
86
- ["lime", "#00ff00"],
87
- ["limegreen", "#32cd32"],
88
- ["linen", "#faf0e6"],
89
- ["magenta", "#ff00ff"],
90
- ["maroon", "#800000"],
91
- ["mediumaquamarine", "#66cdaa"],
92
- ["mediumblue", "#0000cd"],
93
- ["mediumorchid", "#ba55d3"],
94
- ["mediumpurple", "#9370db"],
95
- ["mediumseagreen", "#3cb371"],
96
- ["mediumslateblue", "#7b68ee"],
97
- ["mediumspringgreen", "#00fa9a"],
98
- ["mediumturquoise", "#48d1cc"],
99
- ["mediumvioletred", "#c71585"],
100
- ["midnightblue", "#191970"],
101
- ["mintcream", "#f5fffa"],
102
- ["mistyrose", "#ffe4e1"],
103
- ["moccasin", "#ffe4b5"],
104
- ["navajowhite", "#ffdead"],
105
- ["navy", "#000080"],
106
- ["oldlace", "#fdf5e6"],
107
- ["olive", "#808000"],
108
- ["olivedrab", "#6b8e23"],
109
- ["orange", "#ffa500"],
110
- ["orangered", "#ff4500"],
111
- ["orchid", "#da70d6"],
112
- ["palegoldenrod", "#eee8aa"],
113
- ["palegreen", "#98fb98"],
114
- ["paleturquoise", "#afeeee"],
115
- ["palevioletred", "#db7093"],
116
- ["papayawhip", "#ffefd5"],
117
- ["peachpuff", "#ffdab9"],
118
- ["peru", "#cd853f"],
119
- ["pink", "#ffc0cb"],
120
- ["plum", "#dda0dd"],
121
- ["powderblue", "#b0e0e6"],
122
- ["purple", "#800080"],
123
- ["rebeccapurple", "#663399"],
124
- ["red", "#ff0000"],
125
- ["rosybrown", "#bc8f8f"],
126
- ["royalblue", "#4169e1"],
127
- ["saddlebrown", "#8b4513"],
128
- ["salmon", "#fa8072"],
129
- ["sandybrown", "#f4a460"],
130
- ["seagreen", "#2e8b57"],
131
- ["seashell", "#fff5ee"],
132
- ["sienna", "#a0522d"],
133
- ["silver", "#c0c0c0"],
134
- ["skyblue", "#87ceeb"],
135
- ["slateblue", "#6a5acd"],
136
- ["slategray", "#708090"],
137
- ["slategrey", "#708090"],
138
- ["snow", "#fffafa"],
139
- ["springgreen", "#00ff7f"],
140
- ["steelblue", "#4682b4"],
141
- ["tan", "#d2b48c"],
142
- ["teal", "#008080"],
143
- ["thistle", "#d8bfd8"],
144
- ["tomato", "#ff6347"],
145
- ["turquoise", "#40e0d0"],
146
- ["violet", "#ee82ee"],
147
- ["wheat", "#f5deb3"],
148
- ["white", "#ffffff"],
149
- ["whitesmoke", "#f5f5f5"],
150
- ["yellow", "#ffff00"],
151
- ["yellowgreen", "#9acd32"]
152
- ]);
153
- const HASH_PATTERN = /^#([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})?$/i;
154
- const SMALL_HASH_PATTERN = /^#([\dA-F])([\dA-F])([\dA-F])([\dA-F])?$/i;
155
- const RGB_PATTERN = (
156
- // eslint-disable-next-line security/detect-unsafe-regex,regexp/no-unused-capturing-group
157
- /^rgba?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/
158
- );
159
- const HSL_PATTERN = (
160
- // eslint-disable-next-line security/detect-unsafe-regex,regexp/no-unused-capturing-group
161
- /^hsla?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/
162
- );
163
- const getDefaultCss = /* @__PURE__ */ __name$1(() => {
164
- return {
165
- __proto__: null,
166
- backgroundColor: null,
167
- color: null,
168
- fontStyle: null,
169
- fontWeight: null,
170
- textDecorationColor: null,
171
- textDecorationLine: []
172
- };
173
- }, "getDefaultCss");
174
- const SPACE_PATTERN = /\s+/g;
175
- const parseCssColor = /* @__PURE__ */ __name$1((colorString) => {
176
- if (colorKeywords.has(colorString)) {
177
- colorString = colorKeywords.get(colorString);
178
- }
179
- const hashMatch = HASH_PATTERN.exec(colorString);
180
- if (hashMatch) {
181
- return [Number.parseInt(hashMatch[1], 16), Number.parseInt(hashMatch[2], 16), Number.parseInt(hashMatch[3], 16)];
182
- }
183
- const smallHashMatch = SMALL_HASH_PATTERN.exec(colorString);
184
- if (smallHashMatch) {
185
- return [
186
- Number.parseInt(`${smallHashMatch[1]}${smallHashMatch[1]}`, 16),
187
- Number.parseInt(`${smallHashMatch[2]}${smallHashMatch[2]}`, 16),
188
- Number.parseInt(`${smallHashMatch[3]}${smallHashMatch[3]}`, 16)
189
- ];
190
- }
191
- const rgbMatch = RGB_PATTERN.exec(colorString);
192
- if (rgbMatch) {
193
- return [
194
- Math.round(Math.max(0, Math.min(255, Number(rgbMatch[1])))),
195
- Math.round(Math.max(0, Math.min(255, Number(rgbMatch[2])))),
196
- Math.round(Math.max(0, Math.min(255, Number(rgbMatch[3]))))
197
- ];
198
- }
199
- const hslMatch = HSL_PATTERN.exec(colorString);
200
- if (hslMatch) {
201
- let h = Number(hslMatch[1]) % 360;
202
- if (h < 0) {
203
- h += 360;
204
- }
205
- const s = Math.max(0, Math.min(100, Number(hslMatch[2]))) / 100;
206
- const l = Math.max(0, Math.min(100, Number(hslMatch[3]))) / 100;
207
- const c = (1 - Math.abs(2 * l - 1)) * s;
208
- const x = c * (1 - Math.abs(h / 60 % 2 - 1));
209
- const m = l - c / 2;
210
- let r_;
211
- let g_;
212
- let b_;
213
- if (h < 60) {
214
- ({ 0: r_, 1: g_, 2: b_ } = [c, x, 0]);
215
- } else if (h < 120) {
216
- ({ 0: r_, 1: g_, 2: b_ } = [x, c, 0]);
217
- } else if (h < 180) {
218
- ({ 0: r_, 1: g_, 2: b_ } = [0, c, x]);
219
- } else if (h < 240) {
220
- ({ 0: r_, 1: g_, 2: b_ } = [0, x, c]);
221
- } else if (h < 300) {
222
- ({ 0: r_, 1: g_, 2: b_ } = [x, 0, c]);
223
- } else {
224
- ({ 0: r_, 1: g_, 2: b_ } = [c, 0, x]);
225
- }
226
- return [Math.round((r_ + m) * 255), Math.round((g_ + m) * 255), Math.round((b_ + m) * 255)];
227
- }
228
- return null;
229
- }, "parseCssColor");
230
- const colorEquals = /* @__PURE__ */ __name$1((color1, color2) => color1?.[0] === color2?.[0] && color1?.[1] === color2?.[1] && color1?.[2] === color2?.[2], "colorEquals");
231
- const parseCss = /* @__PURE__ */ __name$1((cssString) => {
232
- const css = getDefaultCss();
233
- const rawEntries = [];
234
- let inValue = false;
235
- let currentKey = null;
236
- let parenthesesDepth = 0;
237
- let currentPart = "";
238
- for (const c of cssString) {
239
- if (c === "(") {
240
- parenthesesDepth++;
241
- } else if (parenthesesDepth > 0) {
242
- if (c === ")") {
243
- parenthesesDepth--;
244
- }
245
- } else if (inValue) {
246
- if (c === ";") {
247
- const value = currentPart.trim();
248
- if (value !== "") {
249
- rawEntries.push([currentKey, value]);
250
- }
251
- currentKey = null;
252
- currentPart = "";
253
- inValue = false;
254
- continue;
255
- }
256
- } else if (c === ":") {
257
- currentKey = currentPart.trim();
258
- currentPart = "";
259
- inValue = true;
260
- continue;
261
- }
262
- currentPart += c;
263
- }
264
- if (inValue && parenthesesDepth === 0) {
265
- const value = currentPart.trim();
266
- if (value !== "") {
267
- rawEntries.push([currentKey, value]);
268
- }
269
- currentKey = null;
270
- currentPart = "";
271
- }
272
- for (const { 0: key, 1: value } of rawEntries) {
273
- switch (key) {
274
- case "background-color": {
275
- if (value != null) {
276
- css.backgroundColor = value;
277
- }
278
- break;
279
- }
280
- case "color": {
281
- if (value != null) {
282
- css.color = value;
283
- }
284
- break;
285
- }
286
- case "font-weight": {
287
- if (value === "bold") {
288
- css.fontWeight = value;
289
- }
290
- break;
291
- }
292
- case "font-style": {
293
- if (["italic", "oblique", "oblique 14deg"].includes(value)) {
294
- css.fontStyle = "italic";
295
- }
296
- break;
297
- }
298
- case "text-decoration-line": {
299
- css.textDecorationLine = [];
300
- const lineTypes = value.split(SPACE_PATTERN);
301
- for (const lineType of lineTypes) {
302
- if (["line-through", "overline", "underline"].includes(lineType)) {
303
- css.textDecorationLine.push(lineType);
304
- }
305
- }
306
- break;
307
- }
308
- case "text-decoration-color": {
309
- const color = parseCssColor(value);
310
- if (color != null) {
311
- css.textDecorationColor = color;
312
- }
313
- break;
314
- }
315
- case "text-decoration": {
316
- css.textDecorationColor = null;
317
- css.textDecorationLine = [];
318
- const arguments_ = value.split(SPACE_PATTERN);
319
- for (const argument of arguments_) {
320
- const maybeColor = parseCssColor(argument);
321
- if (maybeColor != null) {
322
- css.textDecorationColor = maybeColor;
323
- } else if (["line-through", "overline", "underline"].includes(argument)) {
324
- css.textDecorationLine.push(argument);
325
- }
326
- }
327
- break;
328
- }
329
- }
330
- }
331
- return css;
332
- }, "parseCss");
333
- const cssToAnsi = /* @__PURE__ */ __name$1((css, previousCss = null) => {
334
- previousCss = previousCss ?? getDefaultCss();
335
- let ansi = "";
336
- if (!colorEquals(css.backgroundColor, previousCss.backgroundColor)) {
337
- if (css.backgroundColor == null) {
338
- ansi += "\x1B[49m";
339
- } else
340
- switch (css.backgroundColor) {
341
- case "black": {
342
- ansi += "\x1B[40m";
343
- break;
344
- }
345
- case "red": {
346
- ansi += "\x1B[41m";
347
- break;
348
- }
349
- case "green": {
350
- ansi += "\x1B[42m";
351
- break;
352
- }
353
- case "yellow": {
354
- ansi += "\x1B[43m";
355
- break;
356
- }
357
- case "blue": {
358
- ansi += "\x1B[44m";
359
- break;
360
- }
361
- case "magenta": {
362
- ansi += "\x1B[45m";
363
- break;
364
- }
365
- case "cyan": {
366
- ansi += "\x1B[46m";
367
- break;
368
- }
369
- case "white": {
370
- ansi += "\x1B[47m";
371
- break;
372
- }
373
- default: {
374
- if (Array.isArray(css.backgroundColor)) {
375
- const { 0: r, 1: g, 2: b } = css.backgroundColor;
376
- ansi += `\x1B[48;2;${r};${g};${b}m`;
377
- } else {
378
- const parsed = parseCssColor(css.backgroundColor);
379
- if (parsed === null) {
380
- ansi += "\x1B[49m";
381
- } else {
382
- const { 0: r, 1: g, 2: b } = parsed;
383
- ansi += `\x1B[48;2;${r};${g};${b}m`;
384
- }
385
- }
386
- }
387
- }
388
- }
389
- if (!colorEquals(css.color, previousCss.color)) {
390
- if (css.color == null) {
391
- ansi += "\x1B[39m";
392
- } else
393
- switch (css.color) {
394
- case "black": {
395
- ansi += "\x1B[30m";
396
- break;
397
- }
398
- case "red": {
399
- ansi += "\x1B[31m";
400
- break;
401
- }
402
- case "green": {
403
- ansi += "\x1B[32m";
404
- break;
405
- }
406
- case "yellow": {
407
- ansi += "\x1B[33m";
408
- break;
409
- }
410
- case "blue": {
411
- ansi += "\x1B[34m";
412
- break;
413
- }
414
- case "magenta": {
415
- ansi += "\x1B[35m";
416
- break;
417
- }
418
- case "cyan": {
419
- ansi += "\x1B[36m";
420
- break;
421
- }
422
- case "white": {
423
- ansi += "\x1B[37m";
424
- break;
425
- }
426
- default: {
427
- if (Array.isArray(css.color)) {
428
- const { 0: r, 1: g, 2: b } = css.color;
429
- ansi += `\x1B[38;2;${r};${g};${b}m`;
430
- } else {
431
- const parsed = parseCssColor(css.color);
432
- if (parsed === null) {
433
- ansi += "\x1B[39m";
434
- } else {
435
- const { 0: r, 1: g, 2: b } = parsed;
436
- ansi += `\x1B[38;2;${r};${g};${b}m`;
437
- }
438
- }
439
- }
440
- }
441
- }
442
- if (css.fontWeight !== previousCss.fontWeight) {
443
- ansi += css.fontWeight === "bold" ? "\x1B[1m" : "\x1B[22m";
444
- }
445
- if (css.fontStyle !== previousCss.fontStyle) {
446
- ansi += css.fontStyle === "italic" ? "\x1B[3m" : "\x1B[23m";
447
- }
448
- if (!colorEquals(css.textDecorationColor, previousCss.textDecorationColor)) {
449
- if (css.textDecorationColor == null) {
450
- ansi += "\x1B[59m";
451
- } else {
452
- const { 0: r, 1: g, 2: b } = css.textDecorationColor;
453
- ansi += `\x1B[58;2;${r};${g};${b}m`;
454
- }
455
- }
456
- if (css.textDecorationLine.includes("line-through") !== previousCss.textDecorationLine.includes("line-through")) {
457
- ansi += css.textDecorationLine.includes("line-through") ? "\x1B[9m" : "\x1B[29m";
458
- }
459
- if (css.textDecorationLine.includes("overline") !== previousCss.textDecorationLine.includes("overline")) {
460
- ansi += css.textDecorationLine.includes("overline") ? "\x1B[53m" : "\x1B[55m";
461
- }
462
- if (css.textDecorationLine.includes("underline") !== previousCss.textDecorationLine.includes("underline")) {
463
- ansi += css.textDecorationLine.includes("underline") ? "\x1B[4m" : "\x1B[24m";
464
- }
465
- return ansi;
466
- }, "cssToAnsi");
467
-
468
- var __defProp = Object.defineProperty;
469
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
470
- const tryStringify = /* @__PURE__ */ __name((o) => {
471
- try {
472
- return JSON.stringify(o);
473
- } catch {
474
- return '"[Circular]"';
475
- }
476
- }, "tryStringify");
477
- const CHAR_PERCENT = "%".codePointAt(0);
478
- const CHAR_s = "s".codePointAt(0);
479
- const CHAR_d = "d".codePointAt(0);
480
- const CHAR_f = "f".codePointAt(0);
481
- const CHAR_i = "i".codePointAt(0);
482
- const CHAR_O = "O".codePointAt(0);
483
- const CHAR_o = "o".codePointAt(0);
484
- const CHAR_j = "j".codePointAt(0);
485
- const CHAR_c = "c".codePointAt(0);
486
- const format = /* @__PURE__ */ __name((fmt, arguments_ = [], options = {}) => {
487
- if (typeof fmt !== "string" && typeof fmt !== "object" || fmt === null) {
488
- throw new TypeError(`fmt must be a string or object, got ${fmt === null ? "null" : typeof fmt}`);
489
- }
490
- const stringify = options.stringify ?? tryStringify;
491
- const offset = 1;
492
- if (typeof fmt === "object") {
493
- const argumentsLength = arguments_.length + offset;
494
- if (argumentsLength === 1) {
495
- return "{}";
496
- }
497
- const objects = Array.from({ length: argumentsLength });
498
- objects[0] = stringify(fmt);
499
- for (let index = 1; index < argumentsLength; index++) {
500
- objects[index] = stringify(arguments_[index - offset]);
501
- }
502
- return objects.join(" ");
503
- }
504
- if (arguments_.length === 0) {
505
- return fmt;
506
- }
507
- let result = "";
508
- let a = 1 - offset;
509
- let lastPosition = -1;
510
- let usedStyle = false;
511
- let previousCss = null;
512
- for (let index = 0; index < fmt.length; ) {
513
- if (fmt.codePointAt(index) === CHAR_PERCENT && index + 1 < fmt.length) {
514
- lastPosition = lastPosition > -1 ? lastPosition : 0;
515
- const c = fmt.codePointAt(index + 1);
516
- if (c === void 0) {
517
- ++a;
518
- break;
519
- }
520
- switch (c) {
521
- case CHAR_d:
522
- case CHAR_f: {
523
- if (a >= arguments_.length || arguments_[a] == null) {
524
- break;
525
- }
526
- if (lastPosition < index) {
527
- result += fmt.slice(lastPosition, index);
528
- }
529
- result += Number(arguments_[a]).toString();
530
- lastPosition = index + 2;
531
- index++;
532
- break;
533
- }
534
- case CHAR_i: {
535
- if (a >= arguments_.length || arguments_[a] == null) {
536
- break;
537
- }
538
- if (lastPosition < index) {
539
- result += fmt.slice(lastPosition, index);
540
- }
541
- result += Math.floor(Number(arguments_[a])).toString();
542
- lastPosition = index + 2;
543
- index++;
544
- break;
545
- }
546
- case CHAR_O:
547
- case CHAR_o:
548
- case CHAR_j: {
549
- if (a >= arguments_.length || arguments_[a] === void 0) {
550
- break;
551
- }
552
- if (lastPosition < index) {
553
- result += fmt.slice(lastPosition, index);
554
- }
555
- const temporaryArgument = arguments_[a];
556
- const type = typeof temporaryArgument;
557
- if (type === "string") {
558
- result += `'${temporaryArgument}'`;
559
- lastPosition = index + 2;
560
- break;
561
- }
562
- if (type === "function") {
563
- result += temporaryArgument.name ? `[Function: ${temporaryArgument.name}]` : "[Function: <anonymous>]";
564
- lastPosition = index + 2;
565
- break;
566
- }
567
- result += stringify(temporaryArgument);
568
- lastPosition = index + 2;
569
- index++;
570
- break;
571
- }
572
- case CHAR_s: {
573
- if (a >= arguments_.length) {
574
- break;
575
- }
576
- if (lastPosition < index) {
577
- result += fmt.slice(lastPosition, index);
578
- }
579
- result += typeof arguments_[a] === "object" ? stringify(arguments_[a]) : String(arguments_[a]);
580
- lastPosition = index + 2;
581
- index++;
582
- break;
583
- }
584
- case CHAR_PERCENT: {
585
- if (lastPosition < index) {
586
- result += fmt.slice(lastPosition, index);
587
- }
588
- result += "%";
589
- lastPosition = index + 2;
590
- index++;
591
- a--;
592
- break;
593
- }
594
- case CHAR_c: {
595
- if (typeof window === "undefined") {
596
- const css = parseCss(arguments_[a]);
597
- if (lastPosition < index) {
598
- result += fmt.slice(lastPosition, index);
599
- }
600
- result += cssToAnsi(css, previousCss);
601
- if (result !== "") {
602
- usedStyle = true;
603
- previousCss = css;
604
- }
605
- }
606
- lastPosition = index + 2;
607
- index++;
608
- break;
609
- }
610
- default: {
611
- if (typeof options.formatters?.[c] === "function") {
612
- if (lastPosition < index) {
613
- result += fmt.slice(lastPosition, index);
614
- }
615
- result += options.formatters[c](arguments_[a]);
616
- lastPosition = index + 2;
617
- index++;
618
- }
619
- }
620
- }
621
- ++a;
622
- }
623
- ++index;
624
- }
625
- if (lastPosition === -1) {
626
- return fmt;
627
- }
628
- if (lastPosition < fmt.length) {
629
- result += fmt.slice(lastPosition);
630
- }
631
- if (usedStyle) {
632
- result += "\x1B[0m";
633
- }
634
- return result;
635
- }, "format");
636
- const build = /* @__PURE__ */ __name((options = {}) => {
637
- const formatters = {};
638
- if (typeof options.formatters === "object") {
639
- Object.entries(options.formatters).forEach(([key, formatterFunction]) => {
640
- if (key.length === 0) {
641
- throw new Error(`Formatter %${key} has no characters`);
642
- }
643
- if (key.length > 1) {
644
- throw new Error(`Formatter %${key} has more than one character`);
645
- }
646
- if (typeof formatterFunction !== "function") {
647
- throw new TypeError(`Formatter for %${key} is not a function`);
648
- }
649
- const c = key.codePointAt(0);
650
- if (c === void 0) {
651
- throw new Error(`${key}.codePointAt(0) failed to return a value, please report this issue`);
652
- }
653
- formatters[c] = formatterFunction;
654
- });
655
- }
656
- return (f, arguments_ = [], formatOptions = {}) => format(f, arguments_, { ...formatOptions, formatters });
657
- }, "build");
658
-
659
- export { build, format };
1
+ var $=Object.defineProperty;var h=(e,r)=>$(e,"name",{value:r,configurable:!0});var v=Object.defineProperty,m=h((e,r)=>v(e,"name",{value:r,configurable:!0}),"m$1");const y=new Map([["aliceblue","#f0f8ff"],["antiquewhite","#faebd7"],["aqua","#00ffff"],["aquamarine","#7fffd4"],["azure","#f0ffff"],["beige","#f5f5dc"],["bisque","#ffe4c4"],["black","#000000"],["blanchedalmond","#ffebcd"],["blue","#0000ff"],["blueviolet","#8a2be2"],["brown","#a52a2a"],["burlywood","#deb887"],["cadetblue","#5f9ea0"],["chartreuse","#7fff00"],["chocolate","#d2691e"],["coral","#ff7f50"],["cornflowerblue","#6495ed"],["cornsilk","#fff8dc"],["crimson","#dc143c"],["cyan","#00ffff"],["darkblue","#00008b"],["darkcyan","#008b8b"],["darkgoldenrod","#b8860b"],["darkgray","#a9a9a9"],["darkgreen","#006400"],["darkgrey","#a9a9a9"],["darkkhaki","#bdb76b"],["darkmagenta","#8b008b"],["darkolivegreen","#556b2f"],["darkorange","#ff8c00"],["darkorchid","#9932cc"],["darkred","#8b0000"],["darksalmon","#e9967a"],["darkseagreen","#8fbc8f"],["darkslateblue","#483d8b"],["darkslategray","#2f4f4f"],["darkslategrey","#2f4f4f"],["darkturquoise","#00ced1"],["darkviolet","#9400d3"],["deeppink","#ff1493"],["deepskyblue","#00bfff"],["dimgray","#696969"],["dimgrey","#696969"],["dodgerblue","#1e90ff"],["firebrick","#b22222"],["floralwhite","#fffaf0"],["forestgreen","#228b22"],["fuchsia","#ff00ff"],["gainsboro","#dcdcdc"],["ghostwhite","#f8f8ff"],["gold","#ffd700"],["goldenrod","#daa520"],["gray","#808080"],["green","#008000"],["greenyellow","#adff2f"],["grey","#808080"],["honeydew","#f0fff0"],["hotpink","#ff69b4"],["indianred","#cd5c5c"],["indigo","#4b0082"],["ivory","#fffff0"],["khaki","#f0e68c"],["lavender","#e6e6fa"],["lavenderblush","#fff0f5"],["lawngreen","#7cfc00"],["lemonchiffon","#fffacd"],["lightblue","#add8e6"],["lightcoral","#f08080"],["lightcyan","#e0ffff"],["lightgoldenrodyellow","#fafad2"],["lightgray","#d3d3d3"],["lightgreen","#90ee90"],["lightgrey","#d3d3d3"],["lightpink","#ffb6c1"],["lightsalmon","#ffa07a"],["lightseagreen","#20b2aa"],["lightskyblue","#87cefa"],["lightslategray","#778899"],["lightslategrey","#778899"],["lightsteelblue","#b0c4de"],["lightyellow","#ffffe0"],["lime","#00ff00"],["limegreen","#32cd32"],["linen","#faf0e6"],["magenta","#ff00ff"],["maroon","#800000"],["mediumaquamarine","#66cdaa"],["mediumblue","#0000cd"],["mediumorchid","#ba55d3"],["mediumpurple","#9370db"],["mediumseagreen","#3cb371"],["mediumslateblue","#7b68ee"],["mediumspringgreen","#00fa9a"],["mediumturquoise","#48d1cc"],["mediumvioletred","#c71585"],["midnightblue","#191970"],["mintcream","#f5fffa"],["mistyrose","#ffe4e1"],["moccasin","#ffe4b5"],["navajowhite","#ffdead"],["navy","#000080"],["oldlace","#fdf5e6"],["olive","#808000"],["olivedrab","#6b8e23"],["orange","#ffa500"],["orangered","#ff4500"],["orchid","#da70d6"],["palegoldenrod","#eee8aa"],["palegreen","#98fb98"],["paleturquoise","#afeeee"],["palevioletred","#db7093"],["papayawhip","#ffefd5"],["peachpuff","#ffdab9"],["peru","#cd853f"],["pink","#ffc0cb"],["plum","#dda0dd"],["powderblue","#b0e0e6"],["purple","#800080"],["rebeccapurple","#663399"],["red","#ff0000"],["rosybrown","#bc8f8f"],["royalblue","#4169e1"],["saddlebrown","#8b4513"],["salmon","#fa8072"],["sandybrown","#f4a460"],["seagreen","#2e8b57"],["seashell","#fff5ee"],["sienna","#a0522d"],["silver","#c0c0c0"],["skyblue","#87ceeb"],["slateblue","#6a5acd"],["slategray","#708090"],["slategrey","#708090"],["snow","#fffafa"],["springgreen","#00ff7f"],["steelblue","#4682b4"],["tan","#d2b48c"],["teal","#008080"],["thistle","#d8bfd8"],["tomato","#ff6347"],["turquoise","#40e0d0"],["violet","#ee82ee"],["wheat","#f5deb3"],["white","#ffffff"],["whitesmoke","#f5f5f5"],["yellow","#ffff00"],["yellowgreen","#9acd32"]]),A=/^#([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})?$/i,C=/^#([\dA-F])([\dA-F])([\dA-F])([\dA-F])?$/i,D=/^rgba?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/,M=/^hsla?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/,B=m(()=>({__proto__:null,backgroundColor:null,color:null,fontStyle:null,fontWeight:null,textDecorationColor:null,textDecorationLine:[]}),"getDefaultCss"),p=/\s+/g,g=m(e=>{y.has(e)&&(e=y.get(e));const r=A.exec(e);if(r)return[Number.parseInt(r[1],16),Number.parseInt(r[2],16),Number.parseInt(r[3],16)];const t=C.exec(e);if(t)return[Number.parseInt(`${t[1]}${t[1]}`,16),Number.parseInt(`${t[2]}${t[2]}`,16),Number.parseInt(`${t[3]}${t[3]}`,16)];const f=D.exec(e);if(f)return[Math.round(Math.max(0,Math.min(255,Number(f[1])))),Math.round(Math.max(0,Math.min(255,Number(f[2])))),Math.round(Math.max(0,Math.min(255,Number(f[3]))))];const i=M.exec(e);if(i){let a=Number(i[1])%360;a<0&&(a+=360);const l=Math.max(0,Math.min(100,Number(i[2])))/100,n=Math.max(0,Math.min(100,Number(i[3])))/100,c=(1-Math.abs(2*n-1))*l,u=c*(1-Math.abs(a/60%2-1)),o=n-c/2;let s,d,b;return a<60?{0:s,1:d,2:b}=[c,u,0]:a<120?{0:s,1:d,2:b}=[u,c,0]:a<180?{0:s,1:d,2:b}=[0,c,u]:a<240?{0:s,1:d,2:b}=[0,u,c]:a<300?{0:s,1:d,2:b}=[u,0,c]:{0:s,1:d,2:b}=[c,0,u],[Math.round((s+o)*255),Math.round((d+o)*255),Math.round((b+o)*255)]}return null},"parseCssColor"),k=m((e,r)=>e?.[0]===r?.[0]&&e?.[1]===r?.[1]&&e?.[2]===r?.[2],"colorEquals"),P=m(e=>{const r=B(),t=[];let f=!1,i=null,a=0,l="";for(const n of e){if(n==="(")a++;else if(a>0)n===")"&&a--;else if(f){if(n===";"){const c=l.trim();c!==""&&t.push([i,c]),i=null,l="",f=!1;continue}}else if(n===":"){i=l.trim(),l="",f=!0;continue}l+=n}if(f&&a===0){const n=l.trim();n!==""&&t.push([i,n]),i=null,l=""}for(const{0:n,1:c}of t)switch(n){case"background-color":{c!=null&&(r.backgroundColor=c);break}case"color":{c!=null&&(r.color=c);break}case"font-style":{["italic","oblique","oblique 14deg"].includes(c)&&(r.fontStyle="italic");break}case"font-weight":{c==="bold"&&(r.fontWeight=c);break}case"text-decoration":{r.textDecorationColor=null,r.textDecorationLine=[];const u=c.split(p);for(const o of u){const s=g(o);s!=null?r.textDecorationColor=s:["line-through","overline","underline"].includes(o)&&r.textDecorationLine.push(o)}break}case"text-decoration-color":{const u=g(c);u!=null&&(r.textDecorationColor=u);break}case"text-decoration-line":{r.textDecorationLine=[];const u=c.split(p);for(const o of u)["line-through","overline","underline"].includes(o)&&r.textDecorationLine.push(o);break}}return r},"parseCss"),N=m((e,r=null)=>{r=r??B();let t="";if(!k(e.backgroundColor,r.backgroundColor))if(e.backgroundColor==null)t+="\x1B[49m";else switch(e.backgroundColor){case"black":{t+="\x1B[40m";break}case"blue":{t+="\x1B[44m";break}case"cyan":{t+="\x1B[46m";break}case"green":{t+="\x1B[42m";break}case"magenta":{t+="\x1B[45m";break}case"red":{t+="\x1B[41m";break}case"white":{t+="\x1B[47m";break}case"yellow":{t+="\x1B[43m";break}default:if(Array.isArray(e.backgroundColor)){const{0:f,1:i,2:a}=e.backgroundColor;t+=`\x1B[48;2;${f};${i};${a}m`}else{const f=g(e.backgroundColor);if(f===null)t+="\x1B[49m";else{const{0:i,1:a,2:l}=f;t+=`\x1B[48;2;${i};${a};${l}m`}}}if(!k(e.color,r.color))if(e.color==null)t+="\x1B[39m";else switch(e.color){case"black":{t+="\x1B[30m";break}case"blue":{t+="\x1B[34m";break}case"cyan":{t+="\x1B[36m";break}case"green":{t+="\x1B[32m";break}case"magenta":{t+="\x1B[35m";break}case"red":{t+="\x1B[31m";break}case"white":{t+="\x1B[37m";break}case"yellow":{t+="\x1B[33m";break}default:if(Array.isArray(e.color)){const{0:f,1:i,2:a}=e.color;t+=`\x1B[38;2;${f};${i};${a}m`}else{const f=g(e.color);if(f===null)t+="\x1B[39m";else{const{0:i,1:a,2:l}=f;t+=`\x1B[38;2;${i};${a};${l}m`}}}if(e.fontWeight!==r.fontWeight&&(t+=e.fontWeight==="bold"?"\x1B[1m":"\x1B[22m"),e.fontStyle!==r.fontStyle&&(t+=e.fontStyle==="italic"?"\x1B[3m":"\x1B[23m"),!k(e.textDecorationColor,r.textDecorationColor))if(e.textDecorationColor==null)t+="\x1B[59m";else{const{0:f,1:i,2:a}=e.textDecorationColor;t+=`\x1B[58;2;${f};${i};${a}m`}return e.textDecorationLine.includes("line-through")!==r.textDecorationLine.includes("line-through")&&(t+=e.textDecorationLine.includes("line-through")?"\x1B[9m":"\x1B[29m"),e.textDecorationLine.includes("overline")!==r.textDecorationLine.includes("overline")&&(t+=e.textDecorationLine.includes("overline")?"\x1B[53m":"\x1B[55m"),e.textDecorationLine.includes("underline")!==r.textDecorationLine.includes("underline")&&(t+=e.textDecorationLine.includes("underline")?"\x1B[4m":"\x1B[24m"),t},"cssToAnsi");var F=Object.defineProperty,x=h((e,r)=>F(e,"name",{value:r,configurable:!0}),"y");const L=x(e=>{try{return JSON.stringify(e)}catch{return'"[Circular]"'}},"tryStringify"),w="%".codePointAt(0),j="s".codePointAt(0),q="d".codePointAt(0),S="f".codePointAt(0),E="i".codePointAt(0),I="O".codePointAt(0),O="o".codePointAt(0),T="j".codePointAt(0),W="c".codePointAt(0),_=x((e,r=[],t={})=>{if(typeof e!="string"&&typeof e!="object"||e===null)throw new TypeError(`fmt must be a string or object, got ${e===null?"null":typeof e}`);const f=t.stringify??L,i=1;if(typeof e=="object"){const o=r.length+i;if(o===1)return"{}";const s=Array.from({length:o});s[0]=f(e);for(let d=1;d<o;d++)s[d]=f(r[d-i]);return s.join(" ")}if(r.length===0)return e;let a="",l=1-i,n=-1,c=!1,u=null;for(let o=0;o<e.length;){if(e.codePointAt(o)===w&&o+1<e.length){n=n>-1?n:0;const s=e.codePointAt(o+1);if(s===void 0){++l;break}switch(s){case W:{if(globalThis.window===void 0){const d=P(r[l]);n<o&&(a+=e.slice(n,o)),a+=N(d,u),a!==""&&(c=!0,u=d)}n=o+2,o++;break}case q:case S:{if(l>=r.length||r[l]==null)break;n<o&&(a+=e.slice(n,o)),a+=Number(r[l]).toString(),n=o+2,o++;break}case E:{if(l>=r.length||r[l]==null)break;n<o&&(a+=e.slice(n,o)),a+=Math.floor(Number(r[l])).toString(),n=o+2,o++;break}case T:case I:case O:{if(l>=r.length||r[l]===void 0)break;n<o&&(a+=e.slice(n,o));const d=r[l],b=typeof d;if(b==="string"){a+=`'${d}'`,n=o+2;break}if(b==="function"){a+=d.name?`[Function: ${d.name}]`:"[Function: <anonymous>]",n=o+2;break}a+=f(d),n=o+2,o++;break}case w:{n<o&&(a+=e.slice(n,o)),a+="%",n=o+2,o++,l--;break}case j:{if(l>=r.length)break;n<o&&(a+=e.slice(n,o)),a+=typeof r[l]=="object"?f(r[l]):String(r[l]),n=o+2,o++;break}default:typeof t.formatters?.[s]=="function"&&(n<o&&(a+=e.slice(n,o)),a+=t.formatters[s](r[l]),n=o+2,o++)}++l}++o}return n===-1?e:(n<e.length&&(a+=e.slice(n)),c&&(a+="\x1B[0m"),a)},"format"),J=x((e={})=>{const r={};return typeof e.formatters=="object"&&Object.entries(e.formatters).forEach(([t,f])=>{if(t.length===0)throw new Error(`Formatter %${t} has no characters`);if(t.length>1)throw new Error(`Formatter %${t} has more than one character`);if(typeof f!="function")throw new TypeError(`Formatter for %${t} is not a function`);const i=t.codePointAt(0);if(i===void 0)throw new Error(`${t}.codePointAt(0) failed to return a value, please report this issue`);r[i]=f}),(t,f=[],i={})=>_(t,f,{...i,formatters:r})},"build");export{J as build,_ as format};