321d2a87f8ab71b75f48b02271e3911bdcdff7c2cecfaf8678b926893e4884ce2d4fb63197d2cff63d083b5bb594bcb2daa8bd26c3bd04a9939a50b76d2680 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { ColorKeywords as s } from "./config/keywords.mjs";
  2. function i(r) {
  3. return typeof r != "string" ? !1 : (r = r.toLowerCase(), /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(r));
  4. }
  5. function C(r) {
  6. return typeof r != "string" ? !1 : (r = r.toLowerCase(), /^(rgb\(|RGB\()/.test(r));
  7. }
  8. function b(r) {
  9. return typeof r != "string" ? !1 : (r = r.toLowerCase(), /^(rgba|RGBA)/.test(r));
  10. }
  11. function l(r) {
  12. return /^(rgb|rgba|RGB|RGBA)/.test(r);
  13. }
  14. function p(r) {
  15. return s[r];
  16. }
  17. function g(r) {
  18. if (i(r) || l(r))
  19. return r;
  20. const t = p(r);
  21. if (!t)
  22. throw new Error(`Color: Invalid Input of ${r}`);
  23. return t;
  24. }
  25. function m(r) {
  26. r = r.replace("#", ""), r.length === 3 && (r = Array.from(r).map((e) => e + e).join(""));
  27. const t = r.split("");
  28. return new Array(3).fill(0).map((e, n) => parseInt(`0x${t[n * 2]}${t[n * 2 + 1]}`));
  29. }
  30. function R(r) {
  31. return r.replace(/rgb\(|rgba\(|\)/g, "").split(",").slice(0, 3).map((t) => parseInt(t));
  32. }
  33. function a(r) {
  34. const e = g(r).toLowerCase();
  35. return i(e) ? m(e) : R(e);
  36. }
  37. function c(r) {
  38. const t = g(r);
  39. return b(t) ? Number(
  40. t.toLowerCase().split(",").slice(-1)[0].replace(/[)|\s]/g, "")
  41. ) : 1;
  42. }
  43. function f(r) {
  44. const t = a(r);
  45. return t && [...t, c(r)];
  46. }
  47. function V(r, t) {
  48. const e = a(r);
  49. return typeof t == "number" ? `rgba(${e.join(",")},${t})` : `rgb(${e.join(",")})`;
  50. }
  51. function y(r) {
  52. if (i(r))
  53. return r;
  54. const t = a(r), e = (n) => Number(n).toString(16).padStart(2, "0");
  55. return `#${t.map(e).join("")}`;
  56. }
  57. function u(r) {
  58. if (!Array.isArray(r))
  59. throw new Error(`getColorFromRgbValue: ${r} is not an array`);
  60. const { length: t } = r;
  61. if (t !== 3 && t !== 4)
  62. throw new Error("getColorFromRgbValue: value length should be 3 or 4");
  63. return (t === 3 ? "rgb(" : "rgba(") + r.join(",") + ")";
  64. }
  65. function d(r, t = 0) {
  66. let e = f(r);
  67. return e = e.map((n, o) => o === 3 ? n : n - Math.ceil(2.55 * t)).map((n) => n < 0 ? 0 : n), u(e);
  68. }
  69. function h(r, t = 0) {
  70. let e = f(r);
  71. return e = e.map((n, o) => o === 3 ? n : n + Math.ceil(2.55 * t)).map((n) => n > 255 ? 255 : n), u(e);
  72. }
  73. function $(r, t = 100) {
  74. const e = a(r);
  75. return u([...e, t / 100]);
  76. }
  77. export {
  78. d as darken,
  79. $ as fade,
  80. u as getColorFromRgbValue,
  81. c as getOpacity,
  82. a as getRgbValue,
  83. f as getRgbaValue,
  84. i as isHex,
  85. C as isRgb,
  86. l as isRgbOrRgba,
  87. b as isRgba,
  88. h as lighten,
  89. y as toHex,
  90. V as toRgb
  91. };