@visulima/colorize 1.4.23 → 1.4.25

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 (39) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/LICENSE.md +1 -1
  3. package/dist/gradient.cjs +3 -62
  4. package/dist/gradient.d.cts +2 -2
  5. package/dist/gradient.d.mts +2 -2
  6. package/dist/gradient.d.ts +2 -2
  7. package/dist/gradient.mjs +3 -56
  8. package/dist/index.browser.mjs +1 -63
  9. package/dist/index.server.cjs +2 -266
  10. package/dist/index.server.d.cts +72 -71
  11. package/dist/index.server.mjs +1 -63
  12. package/dist/packem_shared/Colorize-Bn8gI3ME.mjs +1 -0
  13. package/dist/packem_shared/Colorize-CfIXnDUD.mjs +2 -0
  14. package/dist/packem_shared/GradientBuilder-C2IS34v_.cjs +1 -0
  15. package/dist/packem_shared/GradientBuilder-I_j6wpvU.mjs +1 -0
  16. package/dist/packem_shared/ansi256To16--f09kvlF.cjs +1 -0
  17. package/dist/packem_shared/ansi256To16-YETEPW8R.mjs +1 -0
  18. package/dist/packem_shared/colorize.server-9hV-s1hY.mjs +2 -0
  19. package/dist/packem_shared/colorize.server-B0BWdm8_.cjs +2 -0
  20. package/dist/packem_shared/convertHexToRgb-BEnfEytq.cjs +1 -0
  21. package/dist/packem_shared/convertHexToRgb-DGcGUKnj.mjs +1 -0
  22. package/dist/template.cjs +2 -158
  23. package/dist/template.d.cts +10 -8
  24. package/dist/template.d.mts +1 -1
  25. package/dist/template.d.ts +10 -8
  26. package/dist/template.mjs +2 -152
  27. package/dist/utils.cjs +1 -13
  28. package/dist/utils.mjs +1 -2
  29. package/package.json +19 -19
  30. package/dist/packem_shared/Colorize-B2nGcFjg.mjs +0 -417
  31. package/dist/packem_shared/Colorize-BihiZiAf.mjs +0 -258
  32. package/dist/packem_shared/GradientBuilder-Cn2sQ1aK.cjs +0 -505
  33. package/dist/packem_shared/GradientBuilder-Dy53F9zB.mjs +0 -501
  34. package/dist/packem_shared/colorize.server-0LnwnixR.cjs +0 -205
  35. package/dist/packem_shared/colorize.server-DSyvWqmN.mjs +0 -203
  36. package/dist/packem_shared/convertHexToRgb-DDy3Eccg.cjs +0 -19
  37. package/dist/packem_shared/convertHexToRgb-DOIRmKxM.mjs +0 -15
  38. package/dist/packem_shared/rgbToAnsi256-Cakhu-n9.cjs +0 -50
  39. package/dist/packem_shared/rgbToAnsi256-DcQVMIqi.mjs +0 -44
@@ -1,501 +0,0 @@
1
- import { convertHexToRgb } from './convertHexToRgb-DOIRmKxM.mjs';
2
-
3
- const colorNames = {
4
- aliceblue: [240, 248, 255],
5
- antiquewhite: [250, 235, 215],
6
- aqua: [0, 255, 255],
7
- aquamarine: [127, 255, 212],
8
- azure: [240, 255, 255],
9
- beige: [245, 245, 220],
10
- bisque: [255, 228, 196],
11
- black: [0, 0, 0],
12
- blanchedalmond: [255, 235, 205],
13
- blue: [0, 0, 255],
14
- blueviolet: [138, 43, 226],
15
- brown: [165, 42, 42],
16
- burlywood: [222, 184, 135],
17
- cadetblue: [95, 158, 160],
18
- chartreuse: [127, 255, 0],
19
- chocolate: [210, 105, 30],
20
- coral: [255, 127, 80],
21
- cornflowerblue: [100, 149, 237],
22
- cornsilk: [255, 248, 220],
23
- crimson: [220, 20, 60],
24
- cyan: [0, 255, 255],
25
- darkblue: [0, 0, 139],
26
- darkcyan: [0, 139, 139],
27
- darkgoldenrod: [184, 134, 11],
28
- darkgray: [169, 169, 169],
29
- darkgreen: [0, 100, 0],
30
- darkgrey: [169, 169, 169],
31
- darkkhaki: [189, 183, 107],
32
- darkmagenta: [139, 0, 139],
33
- darkolivegreen: [85, 107, 47],
34
- darkorange: [255, 140, 0],
35
- darkorchid: [153, 50, 204],
36
- darkred: [139, 0, 0],
37
- darksalmon: [233, 150, 122],
38
- darkseagreen: [143, 188, 143],
39
- darkslateblue: [72, 61, 139],
40
- darkslategray: [47, 79, 79],
41
- darkslategrey: [47, 79, 79],
42
- darkturquoise: [0, 206, 209],
43
- darkviolet: [148, 0, 211],
44
- deeppink: [255, 20, 147],
45
- deepskyblue: [0, 191, 255],
46
- dimgray: [105, 105, 105],
47
- dimgrey: [105, 105, 105],
48
- dodgerblue: [30, 144, 255],
49
- firebrick: [178, 34, 34],
50
- floralwhite: [255, 250, 240],
51
- forestgreen: [34, 139, 34],
52
- fuchsia: [255, 0, 255],
53
- gainsboro: [220, 220, 220],
54
- ghostwhite: [248, 248, 255],
55
- gold: [255, 215, 0],
56
- goldenrod: [218, 165, 32],
57
- gray: [128, 128, 128],
58
- green: [0, 128, 0],
59
- greenyellow: [173, 255, 47],
60
- grey: [128, 128, 128],
61
- honeydew: [240, 255, 240],
62
- hotpink: [255, 105, 180],
63
- indianred: [205, 92, 92],
64
- indigo: [75, 0, 130],
65
- ivory: [255, 255, 240],
66
- khaki: [240, 230, 140],
67
- lavender: [230, 230, 250],
68
- lavenderblush: [255, 240, 245],
69
- lawngreen: [124, 252, 0],
70
- lemonchiffon: [255, 250, 205],
71
- lightblue: [173, 216, 230],
72
- lightcoral: [240, 128, 128],
73
- lightcyan: [224, 255, 255],
74
- lightgoldenrodyellow: [250, 250, 210],
75
- lightgray: [211, 211, 211],
76
- lightgreen: [144, 238, 144],
77
- lightgrey: [211, 211, 211],
78
- lightpink: [255, 182, 193],
79
- lightsalmon: [255, 160, 122],
80
- lightseagreen: [32, 178, 170],
81
- lightskyblue: [135, 206, 250],
82
- lightslategray: [119, 136, 153],
83
- lightslategrey: [119, 136, 153],
84
- lightsteelblue: [176, 196, 222],
85
- lightyellow: [255, 255, 224],
86
- lime: [0, 255, 0],
87
- limegreen: [50, 205, 50],
88
- linen: [250, 240, 230],
89
- magenta: [255, 0, 255],
90
- maroon: [128, 0, 0],
91
- mediumaquamarine: [102, 205, 170],
92
- mediumblue: [0, 0, 205],
93
- mediumorchid: [186, 85, 211],
94
- mediumpurple: [147, 112, 219],
95
- mediumseagreen: [60, 179, 113],
96
- mediumslateblue: [123, 104, 238],
97
- mediumspringgreen: [0, 250, 154],
98
- mediumturquoise: [72, 209, 204],
99
- mediumvioletred: [199, 21, 133],
100
- midnightblue: [25, 25, 112],
101
- mintcream: [245, 255, 250],
102
- mistyrose: [255, 228, 225],
103
- moccasin: [255, 228, 181],
104
- navajowhite: [255, 222, 173],
105
- navy: [0, 0, 128],
106
- oldlace: [253, 245, 230],
107
- olive: [128, 128, 0],
108
- olivedrab: [107, 142, 35],
109
- orange: [255, 165, 0],
110
- orangered: [255, 69, 0],
111
- orchid: [218, 112, 214],
112
- palegoldenrod: [238, 232, 170],
113
- palegreen: [152, 251, 152],
114
- paleturquoise: [175, 238, 238],
115
- palevioletred: [219, 112, 147],
116
- papayawhip: [255, 239, 213],
117
- peachpuff: [255, 218, 185],
118
- peru: [205, 133, 63],
119
- pink: [255, 192, 203],
120
- plum: [221, 160, 221],
121
- powderblue: [176, 224, 230],
122
- purple: [128, 0, 128],
123
- rebeccapurple: [102, 51, 153],
124
- red: [255, 0, 0],
125
- rosybrown: [188, 143, 143],
126
- royalblue: [65, 105, 225],
127
- saddlebrown: [139, 69, 19],
128
- salmon: [250, 128, 114],
129
- sandybrown: [244, 164, 96],
130
- seagreen: [46, 139, 87],
131
- seashell: [255, 245, 238],
132
- sienna: [160, 82, 45],
133
- silver: [192, 192, 192],
134
- skyblue: [135, 206, 235],
135
- slateblue: [106, 90, 205],
136
- slategray: [112, 128, 144],
137
- slategrey: [112, 128, 144],
138
- snow: [255, 250, 250],
139
- springgreen: [0, 255, 127],
140
- steelblue: [70, 130, 180],
141
- tan: [210, 180, 140],
142
- teal: [0, 128, 128],
143
- thistle: [216, 191, 216],
144
- tomato: [255, 99, 71],
145
- turquoise: [64, 224, 208],
146
- violet: [238, 130, 238],
147
- wheat: [245, 222, 179],
148
- white: [255, 255, 255],
149
- whitesmoke: [245, 245, 245],
150
- yellow: [255, 255, 0],
151
- yellowgreen: [154, 205, 50]
152
- };
153
-
154
- var __defProp$4 = Object.defineProperty;
155
- var __name$4 = (target, value) => __defProp$4(target, "name", { value, configurable: true });
156
- const computeSubSteps = /* @__PURE__ */ __name$4((stops, steps) => {
157
- const l = stops.length;
158
- steps = Number.parseInt(steps.toString(), 10);
159
- if (Number.isNaN(steps) || steps < 2) {
160
- throw new Error("Invalid number of steps (< 2)");
161
- }
162
- if (steps < l) {
163
- throw new Error("Number of steps cannot be inferior to number of stops");
164
- }
165
- const substeps = [];
166
- for (let index = 1; index < l; index++) {
167
- const step = (steps - 1) * (stops[index].position - stops[index - 1].position);
168
- substeps.push(Math.max(1, Math.round(step)));
169
- }
170
- let totalSubsteps = 1;
171
- for (let n = l - 1; n--; ) {
172
- totalSubsteps += substeps[n];
173
- }
174
- while (totalSubsteps !== steps) {
175
- if (totalSubsteps < steps) {
176
- const min = Math.min(...substeps);
177
- substeps[substeps.indexOf(min)]++;
178
- totalSubsteps++;
179
- } else {
180
- const max = Math.max(...substeps);
181
- substeps[substeps.indexOf(max)]--;
182
- totalSubsteps--;
183
- }
184
- }
185
- return substeps;
186
- }, "computeSubSteps");
187
-
188
- var __defProp$3 = Object.defineProperty;
189
- var __name$3 = (target, value) => __defProp$3(target, "name", { value, configurable: true });
190
- const hsvToRgb = /* @__PURE__ */ __name$3((h, s, v) => {
191
- let r = 0;
192
- let g = 0;
193
- let b = 0;
194
- const index = Math.floor(h / 60);
195
- const f = h / 60 - index;
196
- const p = v * (1 - s);
197
- const q = v * (1 - f * s);
198
- const t = v * (1 - (1 - f) * s);
199
- if (index % 6 === 0) {
200
- r = v;
201
- g = t;
202
- b = p;
203
- } else if (index % 6 === 1) {
204
- r = q;
205
- g = v;
206
- b = p;
207
- } else if (index % 6 === 2) {
208
- r = p;
209
- g = v;
210
- b = t;
211
- } else if (index % 6 === 3) {
212
- r = p;
213
- g = q;
214
- b = v;
215
- } else if (index % 6 === 4) {
216
- r = t;
217
- g = p;
218
- b = v;
219
- } else if (index % 6 === 5) {
220
- r = v;
221
- g = p;
222
- b = q;
223
- }
224
- return { b: Math.round(b * 255), g: Math.round(g * 255), r: Math.round(r * 255) };
225
- }, "hsvToRgb");
226
-
227
- var __defProp$2 = Object.defineProperty;
228
- var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
229
- const rgbToHsv = /* @__PURE__ */ __name$2(({ b, g, r }) => {
230
- let rdif;
231
- let gdif;
232
- let bdif;
233
- let h = 0;
234
- let s = 0;
235
- r /= 255;
236
- g /= 255;
237
- b /= 255;
238
- const v = Math.max(r, g, b);
239
- const diff = v - Math.min(r, g, b);
240
- const diffc = /* @__PURE__ */ __name$2((c) => (v - c) / 6 / diff + 1 / 2, "diffc");
241
- if (diff !== 0) {
242
- s = diff / v;
243
- rdif = diffc(r);
244
- gdif = diffc(g);
245
- bdif = diffc(b);
246
- if (v === r) {
247
- h = bdif - gdif;
248
- } else if (v === g) {
249
- h = 1 / 3 + rdif - bdif;
250
- } else if (v === b) {
251
- h = 2 / 3 + gdif - rdif;
252
- }
253
- if (h < 0) {
254
- h += 1;
255
- } else if (h > 1) {
256
- h -= 1;
257
- }
258
- }
259
- return {
260
- h: h * 360,
261
- s,
262
- v
263
- };
264
- }, "rgbToHsv");
265
-
266
- var __defProp$1 = Object.defineProperty;
267
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
268
- const RGBA_MAX = { b: 256, g: 256, r: 256 };
269
- const HSV_MAX = { h: 360, s: 1, v: 1 };
270
- const calculateStepSize = /* @__PURE__ */ __name$1((start, end, steps) => {
271
- const step = {};
272
- for (const k in start) {
273
- if (Object.prototype.hasOwnProperty.call(start, k)) {
274
- step[k] = steps === 0 ? 0 : (end[k] - start[k]) / steps;
275
- }
276
- }
277
- return step;
278
- }, "calculateStepSize");
279
- const interpolate = /* @__PURE__ */ __name$1((step, start, index, max) => {
280
- const color = {};
281
- for (const k in start) {
282
- if (Object.prototype.hasOwnProperty.call(start, k)) {
283
- color[k] = step[k] * index + start[k];
284
- color[k] = // eslint-disable-next-line security/detect-object-injection
285
- color[k] < 0 ? (
286
- // eslint-disable-next-line security/detect-object-injection
287
- color[k] + max[k]
288
- ) : (
289
- // eslint-disable-next-line security/detect-object-injection
290
- max[k] === 1 ? (
291
- // eslint-disable-next-line security/detect-object-injection
292
- color[k]
293
- ) : (
294
- // eslint-disable-next-line security/detect-object-injection
295
- color[k] % max[k]
296
- )
297
- );
298
- }
299
- }
300
- return color;
301
- }, "interpolate");
302
- const interpolateRgb = /* @__PURE__ */ __name$1((stop1, stop2, steps) => {
303
- const start = { b: stop1.color[2], g: stop1.color[1], r: stop1.color[0] };
304
- const end = { b: stop2.color[2], g: stop2.color[1], r: stop2.color[0] };
305
- const step = calculateStepSize(start, end, steps);
306
- const gradient = [{ ...start }];
307
- for (let index = 1; index < steps; index++) {
308
- const color = interpolate(step, start, index, RGBA_MAX);
309
- gradient.push({
310
- b: Math.floor(color.b),
311
- g: Math.floor(color.g),
312
- r: Math.floor(color.r)
313
- });
314
- }
315
- return gradient;
316
- }, "interpolateRgb");
317
- const interpolateHsv = /* @__PURE__ */ __name$1((stop1, stop2, steps, mode) => {
318
- const start = rgbToHsv({ b: stop1.color[2], g: stop1.color[1], r: stop1.color[0] });
319
- const end = rgbToHsv({ b: stop2.color[2], g: stop2.color[1], r: stop2.color[0] });
320
- if (start.s === 0 || end.s === 0) {
321
- return interpolateRgb(stop1, stop2, steps);
322
- }
323
- let trigonometric;
324
- if (typeof mode === "boolean") {
325
- trigonometric = mode;
326
- } else {
327
- const trigShortest = start.h < end.h && end.h - start.h < 180 || start.h > end.h && start.h - end.h > 180;
328
- trigonometric = mode === "long" && trigShortest || mode === "short" && !trigShortest;
329
- }
330
- const step = calculateStepSize(start, end, steps);
331
- const gradient = [
332
- {
333
- b: stop1.color[2],
334
- g: stop1.color[1],
335
- r: stop1.color[0]
336
- }
337
- ];
338
- let diff;
339
- if (start.h <= end.h && !trigonometric || start.h >= end.h && trigonometric) {
340
- diff = end.h - start.h;
341
- } else if (trigonometric) {
342
- diff = 360 - end.h + start.h;
343
- } else {
344
- diff = 360 - start.h + end.h;
345
- }
346
- step.h = (-1) ** (trigonometric ? 1 : 0) * Math.abs(diff) / steps;
347
- for (let index = 1; index < steps; index++) {
348
- const color = interpolate(step, start, index, HSV_MAX);
349
- gradient.push(hsvToRgb(color.h, color.s, color.v));
350
- }
351
- return gradient;
352
- }, "interpolateHsv");
353
-
354
- var __defProp = Object.defineProperty;
355
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
356
- class GradientBuilder {
357
- static {
358
- __name(this, "GradientBuilder");
359
- }
360
- #colorize;
361
- stops;
362
- // eslint-disable-next-line sonarjs/cognitive-complexity
363
- constructor(colorize, stops) {
364
- this.#colorize = colorize;
365
- this.stops = [];
366
- if (stops.length < 2) {
367
- throw new Error("Invalid number of stops (< 2)");
368
- }
369
- const havingPositions = stops[0].position !== void 0;
370
- let l = stops.length;
371
- let p = -1;
372
- let lastColorLess = false;
373
- for (const [index, stop_] of stops.entries()) {
374
- let stop = {};
375
- const hasPosition = stop_.position !== void 0;
376
- if (havingPositions !== hasPosition) {
377
- throw new Error("Cannot mix positioned and non-positioned color stops");
378
- }
379
- if (hasPosition) {
380
- const stopInput = stop_;
381
- const hasColor = stopInput.color !== void 0;
382
- if (!hasColor && (lastColorLess || index === 0 || index === l - 1)) {
383
- throw new Error("Cannot define two consecutive position-only stops");
384
- }
385
- lastColorLess = !hasColor;
386
- let color;
387
- if (hasColor) {
388
- if (Array.isArray(stopInput.color)) {
389
- color = stopInput.color;
390
- } else if (typeof stopInput.color === "string") {
391
- color = stopInput.color.includes("#") ? convertHexToRgb(stopInput.color) : colorNames[stopInput.color];
392
- } else if (stopInput.color.r !== void 0 && stopInput.color.g !== void 0 && stopInput.color.b) {
393
- color = [stopInput.color.r, stopInput.color.g, stopInput.color.b];
394
- }
395
- }
396
- stop = {
397
- color,
398
- colorLess: !hasColor,
399
- position: stopInput.position
400
- };
401
- if (stop.position < 0 || stop.position > 1) {
402
- throw new Error("Color stops positions must be between 0 and 1");
403
- } else if (stop.position < p) {
404
- throw new Error("Color stops positions are not ordered");
405
- }
406
- p = stop.position;
407
- } else if (Array.isArray(stop_)) {
408
- stop = {
409
- color: stop_,
410
- position: index / (l - 1)
411
- };
412
- } else if (typeof stop_ === "string") {
413
- stop = {
414
- color: stop_.includes("#") ? convertHexToRgb(stop_) : colorNames[stop_],
415
- position: index / (l - 1)
416
- };
417
- } else if (stop_.r !== void 0 && stop_.g !== void 0 && stop_.b !== void 0) {
418
- stop = {
419
- color: [stop_.r, stop_.g, stop_.b],
420
- position: index / (l - 1)
421
- };
422
- } else {
423
- throw new Error("Invalid color stop");
424
- }
425
- this.stops.push(stop);
426
- }
427
- if (this.stops[0].position !== 0) {
428
- this.stops.unshift({
429
- color: this.stops[0].color,
430
- position: 0
431
- });
432
- l++;
433
- }
434
- if (this.stops[l - 1].position !== 1) {
435
- this.stops.push({
436
- color: this.stops[l - 1].color,
437
- position: 1
438
- });
439
- }
440
- }
441
- reverse() {
442
- const stops = [];
443
- for (const stop of this.stops) {
444
- const stop_ = { ...stop };
445
- stop_.position = 1 - stop.position;
446
- stops.push(stop_);
447
- }
448
- return new GradientBuilder(this.#colorize, stops.reverse());
449
- }
450
- loop() {
451
- const stops1 = [];
452
- const stops2 = [];
453
- for (const stop of this.stops) {
454
- stops1.push({
455
- color: stop.color,
456
- position: (stop.position || 0) / 2
457
- });
458
- }
459
- for (const stop of this.stops.slice(0, -1)) {
460
- stops2.push({
461
- color: stop.color,
462
- position: 1 - (stop.position || 0) / 2
463
- });
464
- }
465
- return new GradientBuilder(this.#colorize, [...stops1, ...stops2.reverse()]);
466
- }
467
- rgb(steps) {
468
- const subSteps = computeSubSteps(this.stops, steps);
469
- const gradient = [];
470
- this.stops.forEach((stop, index) => {
471
- if (stop.colorLess) {
472
- const rgbs = interpolateRgb(this.stops[index - 1], this.stops[index + 1], 2);
473
- stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
474
- }
475
- });
476
- for (let index = 0, l = this.stops.length; index < l - 1; index++) {
477
- const rgbs = interpolateRgb(this.stops[index], this.stops[index + 1], subSteps[index]);
478
- gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
479
- }
480
- gradient.push(this.#colorize.rgb(...this.stops.at(-1).color));
481
- return gradient;
482
- }
483
- hsv(steps, mode = false) {
484
- const subSteps = computeSubSteps(this.stops, steps);
485
- const gradient = [];
486
- this.stops.forEach((stop, index) => {
487
- if (stop.colorLess) {
488
- const rgbs = interpolateHsv(this.stops[index - 1], this.stops[index + 1], 2, mode);
489
- stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
490
- }
491
- });
492
- for (let index = 0, l = this.stops.length; index < l - 1; index++) {
493
- const rgbs = interpolateHsv(this.stops[index], this.stops[index + 1], subSteps[index], mode);
494
- gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
495
- }
496
- gradient.push(this.#colorize.rgb(...this.stops.at(-1).color));
497
- return gradient;
498
- }
499
- }
500
-
501
- export { GradientBuilder };
@@ -1,205 +0,0 @@
1
- 'use strict';
2
-
3
- const isAnsiColorSupported = require('@visulima/is-ansi-color-supported');
4
- const convertHexToRgb = require('./convertHexToRgb-DDy3Eccg.cjs');
5
- const rgbToAnsi256 = require('./rgbToAnsi256-Cakhu-n9.cjs');
6
-
7
- var __defProp$4 = Object.defineProperty;
8
- var __name$4 = (target, value) => __defProp$4(target, "name", { value, configurable: true });
9
- function ansiRegex({ onlyFirst = false } = {}) {
10
- const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
11
- const pattern = [
12
- `[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`,
13
- "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"
14
- ].join("|");
15
- return new RegExp(pattern, onlyFirst ? void 0 : "g");
16
- }
17
- __name$4(ansiRegex, "ansiRegex");
18
-
19
- var __defProp$3 = Object.defineProperty;
20
- var __name$3 = (target, value) => __defProp$3(target, "name", { value, configurable: true });
21
- const clamp = /* @__PURE__ */ __name$3((number_, min, max) => min > number_ ? min : number_ > max ? max : number_, "clamp");
22
-
23
- var __defProp$2 = Object.defineProperty;
24
- var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
25
- const closeCode = 39;
26
- const bgCloseCode = 49;
27
- const bgOffset = 10;
28
- const supportedColor = isAnsiColorSupported.isStdoutColorSupported();
29
- const mono = { close: "", open: "" };
30
- const esc = supportedColor > 0 ? (open, close) => {
31
- return { close: "\x1B[" + close + "m", open: "\x1B[" + open + "m" };
32
- } : () => mono;
33
- const createRgbFunction = /* @__PURE__ */ __name$2((function_) => (r, g, b) => function_(rgbToAnsi256.rgbToAnsi256(Number(r), Number(g), Number(b))), "createRgbFunction");
34
- const createHexFunction = /* @__PURE__ */ __name$2((function_) => (hex) => {
35
- const [r, g, b] = convertHexToRgb.convertHexToRgb(hex);
36
- return function_(r, g, b);
37
- }, "createHexFunction");
38
- let createAnsi256 = /* @__PURE__ */ __name$2((code) => esc("38;5;" + code, closeCode), "createAnsi256");
39
- let createBgAnsi256 = /* @__PURE__ */ __name$2((code) => esc("48;5;" + code, bgCloseCode), "createBgAnsi256");
40
- let createRgb = /* @__PURE__ */ __name$2((r, g, b) => esc("38;2;" + r + ";" + g + ";" + b, closeCode), "createRgb");
41
- let createBgRgb = /* @__PURE__ */ __name$2((r, g, b) => esc("48;2;" + r + ";" + g + ";" + b, bgCloseCode), "createBgRgb");
42
- if (supportedColor === 1) {
43
- createAnsi256 = /* @__PURE__ */ __name$2((code) => esc(rgbToAnsi256.ansi256To16(Number(code)), closeCode), "createAnsi256");
44
- createBgAnsi256 = /* @__PURE__ */ __name$2((code) => esc(rgbToAnsi256.ansi256To16(Number(code)) + bgOffset, bgCloseCode), "createBgAnsi256");
45
- createRgb = /* @__PURE__ */ __name$2((r, g, b) => esc(rgbToAnsi256.rgbToAnsi16(Number(r), Number(g), Number(b)), closeCode), "createRgb");
46
- createBgRgb = /* @__PURE__ */ __name$2((r, g, b) => esc(rgbToAnsi256.rgbToAnsi16(Number(r), Number(g), Number(b)) + bgOffset, bgCloseCode), "createBgRgb");
47
- } else if (supportedColor === 2) {
48
- createRgb = createRgbFunction(createAnsi256);
49
- createBgRgb = createRgbFunction(createBgAnsi256);
50
- }
51
- const baseStyles = {
52
- // 21 isn't widely supported and 22 does the same thing
53
- bold: esc(1, 22),
54
- dim: esc(2, 22),
55
- hidden: esc(8, 28),
56
- inverse: esc(7, 27),
57
- italic: esc(3, 23),
58
- overline: esc(53, 55),
59
- reset: esc(0, 0),
60
- strike: esc(9, 29),
61
- // alias for strikethrough
62
- strikethrough: esc(9, 29),
63
- underline: esc(4, 24),
64
- visible: mono
65
- };
66
- const baseColors = {
67
- bgBlack: esc(40, bgCloseCode),
68
- bgBlackBright: esc(100, bgCloseCode),
69
- bgBlue: esc(44, bgCloseCode),
70
- bgBlueBright: esc(104, bgCloseCode),
71
- bgCyan: esc(46, bgCloseCode),
72
- bgCyanBright: esc(106, bgCloseCode),
73
- bgGray: esc(100, bgCloseCode),
74
- // US spelling alias for bgBlackBright
75
- bgGreen: esc(42, bgCloseCode),
76
- bgGreenBright: esc(102, bgCloseCode),
77
- bgGrey: esc(100, bgCloseCode),
78
- // UK spelling alias for bgBlackBright
79
- bgMagenta: esc(45, bgCloseCode),
80
- bgMagentaBright: esc(105, bgCloseCode),
81
- bgRed: esc(41, bgCloseCode),
82
- bgRedBright: esc(101, bgCloseCode),
83
- bgWhite: esc(47, bgCloseCode),
84
- bgWhiteBright: esc(107, bgCloseCode),
85
- bgYellow: esc(43, bgCloseCode),
86
- bgYellowBright: esc(103, bgCloseCode),
87
- black: esc(30, closeCode),
88
- blackBright: esc(90, closeCode),
89
- blue: esc(34, closeCode),
90
- blueBright: esc(94, closeCode),
91
- cyan: esc(36, closeCode),
92
- cyanBright: esc(96, closeCode),
93
- gray: esc(90, closeCode),
94
- // US spelling alias for blackBright
95
- green: esc(32, closeCode),
96
- greenBright: esc(92, closeCode),
97
- grey: esc(90, closeCode),
98
- // UK spelling alias for blackBright
99
- magenta: esc(35, closeCode),
100
- magentaBright: esc(95, closeCode),
101
- red: esc(31, closeCode),
102
- redBright: esc(91, closeCode),
103
- white: esc(37, closeCode),
104
- whiteBright: esc(97, closeCode),
105
- yellow: esc(33, closeCode),
106
- yellowBright: esc(93, closeCode)
107
- };
108
- const styleMethods = {
109
- bg: /* @__PURE__ */ __name$2((code) => createBgAnsi256(clamp(code, 0, 255)), "bg"),
110
- bgHex: createHexFunction(createBgRgb),
111
- bgRgb: /* @__PURE__ */ __name$2((r, g, b) => createBgRgb(clamp(r, 0, 255), clamp(g, 0, 255), clamp(b, 0, 255)), "bgRgb"),
112
- fg: /* @__PURE__ */ __name$2((code) => createAnsi256(clamp(code, 0, 255)), "fg"),
113
- hex: createHexFunction(createRgb),
114
- rgb: /* @__PURE__ */ __name$2((r, g, b) => createRgb(clamp(r, 0, 255), clamp(g, 0, 255), clamp(b, 0, 255)), "rgb")
115
- };
116
-
117
- var __defProp$1 = Object.defineProperty;
118
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
119
- const stringReplaceAll = /* @__PURE__ */ __name$1((string_, searchValue, replaceValue) => {
120
- if (searchValue === "") {
121
- return string_;
122
- }
123
- let pos = string_.indexOf(searchValue);
124
- if (pos < 0) {
125
- return string_;
126
- }
127
- const substringLength = searchValue.length;
128
- let lastPos = 0;
129
- let result = "";
130
- while (~pos) {
131
- result += string_.slice(lastPos, pos) + replaceValue;
132
- lastPos = pos + substringLength;
133
- pos = string_.indexOf(searchValue, lastPos);
134
- }
135
- return result + string_.slice(lastPos);
136
- }, "stringReplaceAll");
137
-
138
- var __defProp = Object.defineProperty;
139
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
140
- const styles = {};
141
- let stylePrototype = null;
142
- const wrapText = /* @__PURE__ */ __name((strings, values, properties) => {
143
- if (!strings) {
144
- return "";
145
- }
146
- let string = strings.raw == null ? strings + "" : String.raw(strings, ...values);
147
- if (string.includes("\x1B")) {
148
- for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
149
- string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
150
- }
151
- }
152
- if (string.includes("\n")) {
153
- string = string.replace(/(\r*\n)/g, properties.closeStack + "$1" + properties.openStack);
154
- }
155
- return properties.openStack + string + properties.closeStack;
156
- }, "wrapText");
157
- const createStyle = /* @__PURE__ */ __name(({ props }, { close, open }) => {
158
- const openStack = (props?.openStack ?? "") + open;
159
- const closeStack = close + (props?.closeStack ?? "");
160
- const style = /* @__PURE__ */ __name((strings, ...values) => wrapText(strings, values, style.props), "style");
161
- Object.setPrototypeOf(style, stylePrototype);
162
- style.props = { close, closeStack, open, openStack, props };
163
- style.open = openStack;
164
- style.close = closeStack;
165
- return style;
166
- }, "createStyle");
167
- const Colorize = /* @__PURE__ */ __name(function() {
168
- const self = /* @__PURE__ */ __name((string_) => string_ + "", "self");
169
- self.strip = (value) => value.replaceAll(ansiRegex(), "");
170
- for (const name in baseColors) {
171
- styles[name] = {
172
- get() {
173
- const style = createStyle(this, baseColors[name]);
174
- Object.defineProperty(this, name, { value: style });
175
- return style;
176
- }
177
- };
178
- }
179
- for (const name in baseStyles) {
180
- styles[name] = {
181
- get() {
182
- const style = createStyle(this, baseStyles[name]);
183
- Object.defineProperty(this, name, { value: style });
184
- return style;
185
- }
186
- };
187
- }
188
- stylePrototype = Object.defineProperties({}, styles);
189
- Object.setPrototypeOf(self, stylePrototype);
190
- return self;
191
- }, "Colorize");
192
- for (const name in styleMethods) {
193
- styles[name] = {
194
- get() {
195
- return (...arguments_) => (
196
- // @ts-expect-error: TODO: fix typing of `arguments_`
197
- createStyle(this, styleMethods[name](...arguments_))
198
- );
199
- }
200
- };
201
- }
202
- styles.ansi256 = styles.fg;
203
- styles.bgAnsi256 = styles.bg;
204
-
205
- exports.Colorize = Colorize;