@visulima/colorize 1.4.29 → 2.0.0-alpha.10

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 (40) hide show
  1. package/CHANGELOG.md +169 -0
  2. package/LICENSE.md +1 -1
  3. package/README.md +32 -30
  4. package/dist/ansi-codes.d.mts +1 -1
  5. package/dist/colorize.browser.d.mts +1 -1
  6. package/dist/colorize.server.d.mts +1 -1
  7. package/dist/css-code.d.mts +1 -1
  8. package/dist/gradient.cjs +9 -7
  9. package/dist/gradient.mjs +9 -7
  10. package/dist/index.browser.d.mts +5 -5
  11. package/dist/index.browser.mjs +1 -1
  12. package/dist/index.server.cjs +24 -15
  13. package/dist/index.server.d.cts +2 -2
  14. package/dist/index.server.d.mts +5 -5
  15. package/dist/index.server.d.ts +2 -2
  16. package/dist/index.server.mjs +1 -1
  17. package/dist/packem_shared/{Colorize-Ca9CXTcj.mjs → Colorize-BQ-Wlgs0.js} +9 -13
  18. package/dist/packem_shared/{Colorize-BenP3bFn.mjs → Colorize-rJUN0RFg.js} +24 -15
  19. package/dist/packem_shared/{GradientBuilder-Ba4Teq6P.mjs → GradientBuilder-CkX4Imo9.mjs} +36 -40
  20. package/dist/packem_shared/{GradientBuilder-DjJK22kP.cjs → GradientBuilder-DRrwebdU.cjs} +36 -40
  21. package/dist/packem_shared/{colorize.server-BA3gZZXz.cjs → colorize.server-CwTmhs0e.cjs} +14 -9
  22. package/dist/packem_shared/{colorize.server-ry9FZNfG.mjs → colorize.server-YxoHIDUp.mjs} +14 -9
  23. package/dist/packem_shared/convertHexToRgb-51-edHxE.cjs +21 -0
  24. package/dist/packem_shared/convertHexToRgb-BZwJEiMZ.mjs +17 -0
  25. package/dist/template.cjs +15 -7
  26. package/dist/template.mjs +15 -7
  27. package/dist/types.d.cts +3 -3
  28. package/dist/types.d.mts +3 -3
  29. package/dist/types.d.ts +3 -3
  30. package/dist/util/clamp.d.cts +1 -1
  31. package/dist/util/clamp.d.mts +1 -1
  32. package/dist/util/clamp.d.ts +1 -1
  33. package/dist/util/convert-hex-to-rgb.d.cts +1 -15
  34. package/dist/util/convert-hex-to-rgb.d.mts +1 -15
  35. package/dist/util/convert-hex-to-rgb.d.ts +1 -15
  36. package/dist/utils.cjs +1 -1
  37. package/dist/utils.mjs +1 -1
  38. package/package.json +5 -5
  39. package/dist/packem_shared/convertHexToRgb-CWdAm2kE.mjs +0 -13
  40. package/dist/packem_shared/convertHexToRgb-DvkHBM3-.cjs +0 -17
@@ -8,18 +8,27 @@ function ansiRegex({ onlyFirst = false } = {}) {
8
8
  return new RegExp(pattern, onlyFirst ? void 0 : "g");
9
9
  }
10
10
 
11
- const clamp = (number_, min, max) => min > number_ ? min : Math.min(number_, max);
11
+ const clamp = (number_, min, max) => {
12
+ if (min > number_) {
13
+ return min;
14
+ }
15
+ return Math.min(number_, max);
16
+ };
12
17
 
18
+ const HEX_COLOR_REGEX = /([a-f\d]{3,6})/i;
13
19
  const convertHexToRgb = (hex) => {
14
- let [, color] = /([a-f\d]{3,6})/i.exec(hex) ?? [];
15
- const length_ = color ? color.length : 0;
16
- if (length_ === 3) {
17
- color = color[0] + color[0] + color[1] + color[1] + color[2] + color[2];
18
- } else if (length_ !== 6) {
20
+ let [, color] = HEX_COLOR_REGEX.exec(hex) ?? [];
21
+ const colorLength = color ? color.length : 0;
22
+ if (colorLength === 3) {
23
+ const c0 = color.charAt(0);
24
+ const c1 = color.charAt(1);
25
+ const c2 = color.charAt(2);
26
+ color = c0 + c0 + c1 + c1 + c2 + c2;
27
+ } else if (colorLength !== 6) {
19
28
  return [0, 0, 0];
20
29
  }
21
- const number_ = Number.parseInt(color, 16);
22
- return [number_ >> 16 & 255, number_ >> 8 & 255, number_ & 255];
30
+ const colorNumber = Number.parseInt(color, 16);
31
+ return [colorNumber >> 16 & 255, colorNumber >> 8 & 255, colorNumber & 255];
23
32
  };
24
33
 
25
34
  const rgbToAnsi256 = (r, g, b) => {
@@ -68,17 +77,17 @@ const bgOffset = 10;
68
77
  const supportedColor = isStdoutColorSupported();
69
78
  const mono = { close: "", open: "" };
70
79
  const esc = supportedColor > 0 ? (open, close) => {
71
- return { close: `\x1B[${close}m`, open: `\x1B[${open}m` };
80
+ return { close: `\x1B[${String(close)}m`, open: `\x1B[${String(open)}m` };
72
81
  } : () => mono;
73
82
  const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256(Number(r), Number(g), Number(b)));
74
83
  const createHexFunction = (function_) => (hex) => {
75
84
  const [r, g, b] = convertHexToRgb(hex);
76
85
  return function_(r, g, b);
77
86
  };
78
- let createAnsi256 = (code) => esc(`38;5;${code}`, closeCode);
79
- let createBgAnsi256 = (code) => esc(`48;5;${code}`, bgCloseCode);
80
- let createRgb = (r, g, b) => esc(`38;2;${r};${g};${b}`, closeCode);
81
- let createBgRgb = (r, g, b) => esc(`48;2;${r};${g};${b}`, bgCloseCode);
87
+ let createAnsi256 = (code) => esc(`38;5;${String(code)}`, closeCode);
88
+ let createBgAnsi256 = (code) => esc(`48;5;${String(code)}`, bgCloseCode);
89
+ let createRgb = (r, g, b) => esc(`38;2;${String(r)};${String(g)};${String(b)}`, closeCode);
90
+ let createBgRgb = (r, g, b) => esc(`48;2;${String(r)};${String(g)};${String(b)}`, bgCloseCode);
82
91
  if (supportedColor === 1) {
83
92
  createAnsi256 = (code) => esc(ansi256To16(Number(code)), closeCode);
84
93
  createBgAnsi256 = (code) => esc(ansi256To16(Number(code)) + bgOffset, bgCloseCode);
@@ -179,7 +188,7 @@ const wrapText = (strings, values, properties) => {
179
188
  if (!strings) {
180
189
  return "";
181
190
  }
182
- let string = strings.raw == void 0 ? `${strings}` : String.raw(strings, ...values);
191
+ let string = strings.raw === void 0 ? String(strings) : String.raw(strings, ...values);
183
192
  if (string.includes("\x1B")) {
184
193
  for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
185
194
  string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
@@ -201,7 +210,7 @@ const createStyle = ({ props }, { close, open }) => {
201
210
  return style;
202
211
  };
203
212
  const Colorize = function() {
204
- const self = (string_) => `${string_}`;
213
+ const self = (string_) => String(string_);
205
214
  self.strip = (value) => value.replaceAll(ansiRegex(), "");
206
215
  for (const name in baseColors) {
207
216
  styles[name] = {
@@ -1,4 +1,4 @@
1
- import { convertHexToRgb } from './convertHexToRgb-CWdAm2kE.mjs';
1
+ import { convertHexToRgb } from './convertHexToRgb-BZwJEiMZ.mjs';
2
2
 
3
3
  const colorNames = {
4
4
  aliceblue: [240, 248, 255],
@@ -161,23 +161,25 @@ const computeSubSteps = (stops, steps) => {
161
161
  throw new Error("Number of steps cannot be inferior to number of stops");
162
162
  }
163
163
  const substeps = [];
164
- for (let index = 1; index < l; index++) {
164
+ for (let index = 1; index < l; index += 1) {
165
165
  const step = (steps - 1) * (stops[index].position - stops[index - 1].position);
166
166
  substeps.push(Math.max(1, Math.round(step)));
167
167
  }
168
168
  let totalSubsteps = 1;
169
- for (let n = l - 1; n--; ) {
169
+ for (let n = l - 2; n >= 0; n -= 1) {
170
170
  totalSubsteps += substeps[n];
171
171
  }
172
172
  while (totalSubsteps !== steps) {
173
173
  if (totalSubsteps < steps) {
174
174
  const min = Math.min(...substeps);
175
- substeps[substeps.indexOf(min)]++;
176
- totalSubsteps++;
175
+ const minIndex = substeps.indexOf(min);
176
+ substeps[minIndex] = substeps[minIndex] + 1;
177
+ totalSubsteps += 1;
177
178
  } else {
178
179
  const max = Math.max(...substeps);
179
- substeps[substeps.indexOf(max)]--;
180
- totalSubsteps--;
180
+ const maxIndex = substeps.indexOf(max);
181
+ substeps[maxIndex] = substeps[maxIndex] - 1;
182
+ totalSubsteps -= 1;
181
183
  }
182
184
  }
183
185
  return substeps;
@@ -262,7 +264,7 @@ const HSV_MAX = { h: 360, s: 1, v: 1 };
262
264
  const calculateStepSize = (start, end, steps) => {
263
265
  const step = {};
264
266
  for (const k in start) {
265
- if (Object.prototype.hasOwnProperty.call(start, k)) {
267
+ if (Object.hasOwn(start, k)) {
266
268
  step[k] = steps === 0 ? 0 : (end[k] - start[k]) / steps;
267
269
  }
268
270
  }
@@ -271,21 +273,14 @@ const calculateStepSize = (start, end, steps) => {
271
273
  const interpolate = (step, start, index, max) => {
272
274
  const color = {};
273
275
  for (const k in start) {
274
- if (Object.prototype.hasOwnProperty.call(start, k)) {
275
- color[k] = step[k] * index + start[k];
276
- color[k] = color[k] < 0 ? (
277
- // eslint-disable-next-line security/detect-object-injection
278
- color[k] + max[k]
279
- ) : (
280
- // eslint-disable-next-line security/detect-object-injection
281
- max[k] === 1 ? (
282
- // eslint-disable-next-line security/detect-object-injection
283
- color[k]
284
- ) : (
285
- // eslint-disable-next-line security/detect-object-injection
286
- color[k] % max[k]
287
- )
288
- );
276
+ if (Object.hasOwn(start, k)) {
277
+ let value = step[k] * index + start[k];
278
+ if (value < 0) {
279
+ value += max[k];
280
+ } else if (max[k] !== 1) {
281
+ value %= max[k];
282
+ }
283
+ color[k] = value;
289
284
  }
290
285
  }
291
286
  return color;
@@ -295,7 +290,7 @@ const interpolateRgb = (stop1, stop2, steps) => {
295
290
  const end = { b: stop2.color[2], g: stop2.color[1], r: stop2.color[0] };
296
291
  const step = calculateStepSize(start, end, steps);
297
292
  const gradient = [{ ...start }];
298
- for (let index = 1; index < steps; index++) {
293
+ for (let index = 1; index < steps; index += 1) {
299
294
  const color = interpolate(step, start, index, RGBA_MAX);
300
295
  gradient.push({
301
296
  b: Math.floor(color.b),
@@ -335,7 +330,7 @@ const interpolateHsv = (stop1, stop2, steps, mode) => {
335
330
  diff = 360 - start.h + end.h;
336
331
  }
337
332
  step.h = (-1) ** (trigonometric ? 1 : 0) * Math.abs(diff) / steps;
338
- for (let index = 1; index < steps; index++) {
333
+ for (let index = 1; index < steps; index += 1) {
339
334
  const color = interpolate(step, start, index, HSV_MAX);
340
335
  gradient.push(hsvToRgb(color.h, color.s, color.v));
341
336
  }
@@ -357,7 +352,7 @@ class GradientBuilder {
357
352
  let p = -1;
358
353
  let lastColorLess = false;
359
354
  for (const [index, stop_] of stops.entries()) {
360
- let stop = {};
355
+ let stop;
361
356
  const hasPosition = stop_.position !== void 0;
362
357
  if (havingPositions !== hasPosition) {
363
358
  throw new Error("Cannot mix positioned and non-positioned color stops");
@@ -375,7 +370,7 @@ class GradientBuilder {
375
370
  color = stopInput.color;
376
371
  } else if (typeof stopInput.color === "string") {
377
372
  color = stopInput.color.includes("#") ? convertHexToRgb(stopInput.color) : colorNames[stopInput.color];
378
- } else if (stopInput.color.r !== void 0 && stopInput.color.g !== void 0 && stopInput.color.b) {
373
+ } else if (stopInput.color && "r" in stopInput.color && "g" in stopInput.color && "b" in stopInput.color) {
379
374
  color = [stopInput.color.r, stopInput.color.g, stopInput.color.b];
380
375
  }
381
376
  }
@@ -400,7 +395,7 @@ class GradientBuilder {
400
395
  color: stop_.includes("#") ? convertHexToRgb(stop_) : colorNames[stop_],
401
396
  position: index / (l - 1)
402
397
  };
403
- } else if (stop_.r !== void 0 && stop_.g !== void 0 && stop_.b !== void 0) {
398
+ } else if (stop_?.r !== void 0 && stop_?.g !== void 0 && stop_?.b !== void 0) {
404
399
  stop = {
405
400
  color: [stop_.r, stop_.g, stop_.b],
406
401
  position: index / (l - 1)
@@ -410,16 +405,18 @@ class GradientBuilder {
410
405
  }
411
406
  this.stops.push(stop);
412
407
  }
413
- if (this.stops[0].position !== 0) {
408
+ const firstStop = this.stops[0];
409
+ if (firstStop.position !== 0) {
414
410
  this.stops.unshift({
415
- color: this.stops[0].color,
411
+ color: firstStop.color,
416
412
  position: 0
417
413
  });
418
- l++;
414
+ l += 1;
419
415
  }
420
- if (this.stops[l - 1].position !== 1) {
416
+ const lastStop = this.stops[l - 1];
417
+ if (lastStop.position !== 1) {
421
418
  this.stops.push({
422
- color: this.stops[l - 1].color,
419
+ color: lastStop.color,
423
420
  position: 1
424
421
  });
425
422
  }
@@ -427,11 +424,10 @@ class GradientBuilder {
427
424
  reverse() {
428
425
  const stops = [];
429
426
  for (const stop of this.stops) {
430
- const stop_ = { ...stop };
431
- stop_.position = 1 - stop.position;
432
- stops.push(stop_);
427
+ const reversedStop = { ...stop, position: 1 - stop.position };
428
+ stops.push(reversedStop);
433
429
  }
434
- return new GradientBuilder(this.#colorize, stops.reverse());
430
+ return new GradientBuilder(this.#colorize, stops.toReversed());
435
431
  }
436
432
  loop() {
437
433
  const stops1 = [];
@@ -448,7 +444,7 @@ class GradientBuilder {
448
444
  position: 1 - (stop.position || 0) / 2
449
445
  });
450
446
  }
451
- return new GradientBuilder(this.#colorize, [...stops1, ...stops2.reverse()]);
447
+ return new GradientBuilder(this.#colorize, [...stops1, ...stops2.toReversed()]);
452
448
  }
453
449
  rgb(steps) {
454
450
  const subSteps = computeSubSteps(this.stops, steps);
@@ -459,7 +455,7 @@ class GradientBuilder {
459
455
  stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
460
456
  }
461
457
  });
462
- for (let index = 0, l = this.stops.length; index < l - 1; index++) {
458
+ for (let index = 0, l = this.stops.length; index < l - 1; index += 1) {
463
459
  const rgbs = interpolateRgb(this.stops[index], this.stops[index + 1], subSteps[index]);
464
460
  gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
465
461
  }
@@ -475,7 +471,7 @@ class GradientBuilder {
475
471
  stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
476
472
  }
477
473
  });
478
- for (let index = 0, l = this.stops.length; index < l - 1; index++) {
474
+ for (let index = 0, l = this.stops.length; index < l - 1; index += 1) {
479
475
  const rgbs = interpolateHsv(this.stops[index], this.stops[index + 1], subSteps[index], mode);
480
476
  gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
481
477
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
 
5
- const convertHexToRgb = require('./convertHexToRgb-DvkHBM3-.cjs');
5
+ const convertHexToRgb = require('./convertHexToRgb-51-edHxE.cjs');
6
6
 
7
7
  const colorNames = {
8
8
  aliceblue: [240, 248, 255],
@@ -165,23 +165,25 @@ const computeSubSteps = (stops, steps) => {
165
165
  throw new Error("Number of steps cannot be inferior to number of stops");
166
166
  }
167
167
  const substeps = [];
168
- for (let index = 1; index < l; index++) {
168
+ for (let index = 1; index < l; index += 1) {
169
169
  const step = (steps - 1) * (stops[index].position - stops[index - 1].position);
170
170
  substeps.push(Math.max(1, Math.round(step)));
171
171
  }
172
172
  let totalSubsteps = 1;
173
- for (let n = l - 1; n--; ) {
173
+ for (let n = l - 2; n >= 0; n -= 1) {
174
174
  totalSubsteps += substeps[n];
175
175
  }
176
176
  while (totalSubsteps !== steps) {
177
177
  if (totalSubsteps < steps) {
178
178
  const min = Math.min(...substeps);
179
- substeps[substeps.indexOf(min)]++;
180
- totalSubsteps++;
179
+ const minIndex = substeps.indexOf(min);
180
+ substeps[minIndex] = substeps[minIndex] + 1;
181
+ totalSubsteps += 1;
181
182
  } else {
182
183
  const max = Math.max(...substeps);
183
- substeps[substeps.indexOf(max)]--;
184
- totalSubsteps--;
184
+ const maxIndex = substeps.indexOf(max);
185
+ substeps[maxIndex] = substeps[maxIndex] - 1;
186
+ totalSubsteps -= 1;
185
187
  }
186
188
  }
187
189
  return substeps;
@@ -266,7 +268,7 @@ const HSV_MAX = { h: 360, s: 1, v: 1 };
266
268
  const calculateStepSize = (start, end, steps) => {
267
269
  const step = {};
268
270
  for (const k in start) {
269
- if (Object.prototype.hasOwnProperty.call(start, k)) {
271
+ if (Object.hasOwn(start, k)) {
270
272
  step[k] = steps === 0 ? 0 : (end[k] - start[k]) / steps;
271
273
  }
272
274
  }
@@ -275,21 +277,14 @@ const calculateStepSize = (start, end, steps) => {
275
277
  const interpolate = (step, start, index, max) => {
276
278
  const color = {};
277
279
  for (const k in start) {
278
- if (Object.prototype.hasOwnProperty.call(start, k)) {
279
- color[k] = step[k] * index + start[k];
280
- color[k] = color[k] < 0 ? (
281
- // eslint-disable-next-line security/detect-object-injection
282
- color[k] + max[k]
283
- ) : (
284
- // eslint-disable-next-line security/detect-object-injection
285
- max[k] === 1 ? (
286
- // eslint-disable-next-line security/detect-object-injection
287
- color[k]
288
- ) : (
289
- // eslint-disable-next-line security/detect-object-injection
290
- color[k] % max[k]
291
- )
292
- );
280
+ if (Object.hasOwn(start, k)) {
281
+ let value = step[k] * index + start[k];
282
+ if (value < 0) {
283
+ value += max[k];
284
+ } else if (max[k] !== 1) {
285
+ value %= max[k];
286
+ }
287
+ color[k] = value;
293
288
  }
294
289
  }
295
290
  return color;
@@ -299,7 +294,7 @@ const interpolateRgb = (stop1, stop2, steps) => {
299
294
  const end = { b: stop2.color[2], g: stop2.color[1], r: stop2.color[0] };
300
295
  const step = calculateStepSize(start, end, steps);
301
296
  const gradient = [{ ...start }];
302
- for (let index = 1; index < steps; index++) {
297
+ for (let index = 1; index < steps; index += 1) {
303
298
  const color = interpolate(step, start, index, RGBA_MAX);
304
299
  gradient.push({
305
300
  b: Math.floor(color.b),
@@ -339,7 +334,7 @@ const interpolateHsv = (stop1, stop2, steps, mode) => {
339
334
  diff = 360 - start.h + end.h;
340
335
  }
341
336
  step.h = (-1) ** (trigonometric ? 1 : 0) * Math.abs(diff) / steps;
342
- for (let index = 1; index < steps; index++) {
337
+ for (let index = 1; index < steps; index += 1) {
343
338
  const color = interpolate(step, start, index, HSV_MAX);
344
339
  gradient.push(hsvToRgb(color.h, color.s, color.v));
345
340
  }
@@ -361,7 +356,7 @@ class GradientBuilder {
361
356
  let p = -1;
362
357
  let lastColorLess = false;
363
358
  for (const [index, stop_] of stops.entries()) {
364
- let stop = {};
359
+ let stop;
365
360
  const hasPosition = stop_.position !== void 0;
366
361
  if (havingPositions !== hasPosition) {
367
362
  throw new Error("Cannot mix positioned and non-positioned color stops");
@@ -379,7 +374,7 @@ class GradientBuilder {
379
374
  color = stopInput.color;
380
375
  } else if (typeof stopInput.color === "string") {
381
376
  color = stopInput.color.includes("#") ? convertHexToRgb.convertHexToRgb(stopInput.color) : colorNames[stopInput.color];
382
- } else if (stopInput.color.r !== void 0 && stopInput.color.g !== void 0 && stopInput.color.b) {
377
+ } else if (stopInput.color && "r" in stopInput.color && "g" in stopInput.color && "b" in stopInput.color) {
383
378
  color = [stopInput.color.r, stopInput.color.g, stopInput.color.b];
384
379
  }
385
380
  }
@@ -404,7 +399,7 @@ class GradientBuilder {
404
399
  color: stop_.includes("#") ? convertHexToRgb.convertHexToRgb(stop_) : colorNames[stop_],
405
400
  position: index / (l - 1)
406
401
  };
407
- } else if (stop_.r !== void 0 && stop_.g !== void 0 && stop_.b !== void 0) {
402
+ } else if (stop_?.r !== void 0 && stop_?.g !== void 0 && stop_?.b !== void 0) {
408
403
  stop = {
409
404
  color: [stop_.r, stop_.g, stop_.b],
410
405
  position: index / (l - 1)
@@ -414,16 +409,18 @@ class GradientBuilder {
414
409
  }
415
410
  this.stops.push(stop);
416
411
  }
417
- if (this.stops[0].position !== 0) {
412
+ const firstStop = this.stops[0];
413
+ if (firstStop.position !== 0) {
418
414
  this.stops.unshift({
419
- color: this.stops[0].color,
415
+ color: firstStop.color,
420
416
  position: 0
421
417
  });
422
- l++;
418
+ l += 1;
423
419
  }
424
- if (this.stops[l - 1].position !== 1) {
420
+ const lastStop = this.stops[l - 1];
421
+ if (lastStop.position !== 1) {
425
422
  this.stops.push({
426
- color: this.stops[l - 1].color,
423
+ color: lastStop.color,
427
424
  position: 1
428
425
  });
429
426
  }
@@ -431,11 +428,10 @@ class GradientBuilder {
431
428
  reverse() {
432
429
  const stops = [];
433
430
  for (const stop of this.stops) {
434
- const stop_ = { ...stop };
435
- stop_.position = 1 - stop.position;
436
- stops.push(stop_);
431
+ const reversedStop = { ...stop, position: 1 - stop.position };
432
+ stops.push(reversedStop);
437
433
  }
438
- return new GradientBuilder(this.#colorize, stops.reverse());
434
+ return new GradientBuilder(this.#colorize, stops.toReversed());
439
435
  }
440
436
  loop() {
441
437
  const stops1 = [];
@@ -452,7 +448,7 @@ class GradientBuilder {
452
448
  position: 1 - (stop.position || 0) / 2
453
449
  });
454
450
  }
455
- return new GradientBuilder(this.#colorize, [...stops1, ...stops2.reverse()]);
451
+ return new GradientBuilder(this.#colorize, [...stops1, ...stops2.toReversed()]);
456
452
  }
457
453
  rgb(steps) {
458
454
  const subSteps = computeSubSteps(this.stops, steps);
@@ -463,7 +459,7 @@ class GradientBuilder {
463
459
  stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
464
460
  }
465
461
  });
466
- for (let index = 0, l = this.stops.length; index < l - 1; index++) {
462
+ for (let index = 0, l = this.stops.length; index < l - 1; index += 1) {
467
463
  const rgbs = interpolateRgb(this.stops[index], this.stops[index + 1], subSteps[index]);
468
464
  gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
469
465
  }
@@ -479,7 +475,7 @@ class GradientBuilder {
479
475
  stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
480
476
  }
481
477
  });
482
- for (let index = 0, l = this.stops.length; index < l - 1; index++) {
478
+ for (let index = 0, l = this.stops.length; index < l - 1; index += 1) {
483
479
  const rgbs = interpolateHsv(this.stops[index], this.stops[index + 1], subSteps[index], mode);
484
480
  gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
485
481
  }
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const isAnsiColorSupported = require('@visulima/is-ansi-color-supported');
4
- const convertHexToRgb = require('./convertHexToRgb-DvkHBM3-.cjs');
4
+ const convertHexToRgb = require('./convertHexToRgb-51-edHxE.cjs');
5
5
  const rgbToAnsi256 = require('./rgbToAnsi256-DL8eajTz.cjs');
6
6
 
7
7
  function ansiRegex({ onlyFirst = false } = {}) {
@@ -12,7 +12,12 @@ function ansiRegex({ onlyFirst = false } = {}) {
12
12
  return new RegExp(pattern, onlyFirst ? void 0 : "g");
13
13
  }
14
14
 
15
- const clamp = (number_, min, max) => min > number_ ? min : Math.min(number_, max);
15
+ const clamp = (number_, min, max) => {
16
+ if (min > number_) {
17
+ return min;
18
+ }
19
+ return Math.min(number_, max);
20
+ };
16
21
 
17
22
  const closeCode = 39;
18
23
  const bgCloseCode = 49;
@@ -20,17 +25,17 @@ const bgOffset = 10;
20
25
  const supportedColor = isAnsiColorSupported.isStdoutColorSupported();
21
26
  const mono = { close: "", open: "" };
22
27
  const esc = supportedColor > 0 ? (open, close) => {
23
- return { close: `\x1B[${close}m`, open: `\x1B[${open}m` };
28
+ return { close: `\x1B[${String(close)}m`, open: `\x1B[${String(open)}m` };
24
29
  } : () => mono;
25
30
  const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256.rgbToAnsi256(Number(r), Number(g), Number(b)));
26
31
  const createHexFunction = (function_) => (hex) => {
27
32
  const [r, g, b] = convertHexToRgb.convertHexToRgb(hex);
28
33
  return function_(r, g, b);
29
34
  };
30
- let createAnsi256 = (code) => esc(`38;5;${code}`, closeCode);
31
- let createBgAnsi256 = (code) => esc(`48;5;${code}`, bgCloseCode);
32
- let createRgb = (r, g, b) => esc(`38;2;${r};${g};${b}`, closeCode);
33
- let createBgRgb = (r, g, b) => esc(`48;2;${r};${g};${b}`, bgCloseCode);
35
+ let createAnsi256 = (code) => esc(`38;5;${String(code)}`, closeCode);
36
+ let createBgAnsi256 = (code) => esc(`48;5;${String(code)}`, bgCloseCode);
37
+ let createRgb = (r, g, b) => esc(`38;2;${String(r)};${String(g)};${String(b)}`, closeCode);
38
+ let createBgRgb = (r, g, b) => esc(`48;2;${String(r)};${String(g)};${String(b)}`, bgCloseCode);
34
39
  if (supportedColor === 1) {
35
40
  createAnsi256 = (code) => esc(rgbToAnsi256.ansi256To16(Number(code)), closeCode);
36
41
  createBgAnsi256 = (code) => esc(rgbToAnsi256.ansi256To16(Number(code)) + bgOffset, bgCloseCode);
@@ -131,7 +136,7 @@ const wrapText = (strings, values, properties) => {
131
136
  if (!strings) {
132
137
  return "";
133
138
  }
134
- let string = strings.raw == void 0 ? `${strings}` : String.raw(strings, ...values);
139
+ let string = strings.raw === void 0 ? String(strings) : String.raw(strings, ...values);
135
140
  if (string.includes("\x1B")) {
136
141
  for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
137
142
  string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
@@ -153,7 +158,7 @@ const createStyle = ({ props }, { close, open }) => {
153
158
  return style;
154
159
  };
155
160
  const Colorize = function() {
156
- const self = (string_) => `${string_}`;
161
+ const self = (string_) => String(string_);
157
162
  self.strip = (value) => value.replaceAll(ansiRegex(), "");
158
163
  for (const name in baseColors) {
159
164
  styles[name] = {
@@ -1,5 +1,5 @@
1
1
  import { isStdoutColorSupported } from '@visulima/is-ansi-color-supported';
2
- import { convertHexToRgb } from './convertHexToRgb-CWdAm2kE.mjs';
2
+ import { convertHexToRgb } from './convertHexToRgb-BZwJEiMZ.mjs';
3
3
  import { ansi256To16, rgbToAnsi16, rgbToAnsi256 } from './rgbToAnsi256-BdS0fomP.mjs';
4
4
 
5
5
  function ansiRegex({ onlyFirst = false } = {}) {
@@ -10,7 +10,12 @@ function ansiRegex({ onlyFirst = false } = {}) {
10
10
  return new RegExp(pattern, onlyFirst ? void 0 : "g");
11
11
  }
12
12
 
13
- const clamp = (number_, min, max) => min > number_ ? min : Math.min(number_, max);
13
+ const clamp = (number_, min, max) => {
14
+ if (min > number_) {
15
+ return min;
16
+ }
17
+ return Math.min(number_, max);
18
+ };
14
19
 
15
20
  const closeCode = 39;
16
21
  const bgCloseCode = 49;
@@ -18,17 +23,17 @@ const bgOffset = 10;
18
23
  const supportedColor = isStdoutColorSupported();
19
24
  const mono = { close: "", open: "" };
20
25
  const esc = supportedColor > 0 ? (open, close) => {
21
- return { close: `\x1B[${close}m`, open: `\x1B[${open}m` };
26
+ return { close: `\x1B[${String(close)}m`, open: `\x1B[${String(open)}m` };
22
27
  } : () => mono;
23
28
  const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256(Number(r), Number(g), Number(b)));
24
29
  const createHexFunction = (function_) => (hex) => {
25
30
  const [r, g, b] = convertHexToRgb(hex);
26
31
  return function_(r, g, b);
27
32
  };
28
- let createAnsi256 = (code) => esc(`38;5;${code}`, closeCode);
29
- let createBgAnsi256 = (code) => esc(`48;5;${code}`, bgCloseCode);
30
- let createRgb = (r, g, b) => esc(`38;2;${r};${g};${b}`, closeCode);
31
- let createBgRgb = (r, g, b) => esc(`48;2;${r};${g};${b}`, bgCloseCode);
33
+ let createAnsi256 = (code) => esc(`38;5;${String(code)}`, closeCode);
34
+ let createBgAnsi256 = (code) => esc(`48;5;${String(code)}`, bgCloseCode);
35
+ let createRgb = (r, g, b) => esc(`38;2;${String(r)};${String(g)};${String(b)}`, closeCode);
36
+ let createBgRgb = (r, g, b) => esc(`48;2;${String(r)};${String(g)};${String(b)}`, bgCloseCode);
32
37
  if (supportedColor === 1) {
33
38
  createAnsi256 = (code) => esc(ansi256To16(Number(code)), closeCode);
34
39
  createBgAnsi256 = (code) => esc(ansi256To16(Number(code)) + bgOffset, bgCloseCode);
@@ -129,7 +134,7 @@ const wrapText = (strings, values, properties) => {
129
134
  if (!strings) {
130
135
  return "";
131
136
  }
132
- let string = strings.raw == void 0 ? `${strings}` : String.raw(strings, ...values);
137
+ let string = strings.raw === void 0 ? String(strings) : String.raw(strings, ...values);
133
138
  if (string.includes("\x1B")) {
134
139
  for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
135
140
  string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
@@ -151,7 +156,7 @@ const createStyle = ({ props }, { close, open }) => {
151
156
  return style;
152
157
  };
153
158
  const Colorize = function() {
154
- const self = (string_) => `${string_}`;
159
+ const self = (string_) => String(string_);
155
160
  self.strip = (value) => value.replaceAll(ansiRegex(), "");
156
161
  for (const name in baseColors) {
157
162
  styles[name] = {
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ const HEX_COLOR_REGEX = /([a-f\d]{3,6})/i;
6
+ const convertHexToRgb = (hex) => {
7
+ let [, color] = HEX_COLOR_REGEX.exec(hex) ?? [];
8
+ const colorLength = color ? color.length : 0;
9
+ if (colorLength === 3) {
10
+ const c0 = color.charAt(0);
11
+ const c1 = color.charAt(1);
12
+ const c2 = color.charAt(2);
13
+ color = c0 + c0 + c1 + c1 + c2 + c2;
14
+ } else if (colorLength !== 6) {
15
+ return [0, 0, 0];
16
+ }
17
+ const colorNumber = Number.parseInt(color, 16);
18
+ return [colorNumber >> 16 & 255, colorNumber >> 8 & 255, colorNumber & 255];
19
+ };
20
+
21
+ exports.convertHexToRgb = convertHexToRgb;
@@ -0,0 +1,17 @@
1
+ const HEX_COLOR_REGEX = /([a-f\d]{3,6})/i;
2
+ const convertHexToRgb = (hex) => {
3
+ let [, color] = HEX_COLOR_REGEX.exec(hex) ?? [];
4
+ const colorLength = color ? color.length : 0;
5
+ if (colorLength === 3) {
6
+ const c0 = color.charAt(0);
7
+ const c1 = color.charAt(1);
8
+ const c2 = color.charAt(2);
9
+ color = c0 + c0 + c1 + c1 + c2 + c2;
10
+ } else if (colorLength !== 6) {
11
+ return [0, 0, 0];
12
+ }
13
+ const colorNumber = Number.parseInt(color, 16);
14
+ return [colorNumber >> 16 & 255, colorNumber >> 8 & 255, colorNumber & 255];
15
+ };
16
+
17
+ export { convertHexToRgb };