color.cjs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name in all)
  7. __defProp(target, name, { get: all[name], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. // node_modules/color/index.js
  19. var index_exports = {};
  20. __export(index_exports, {
  21. default: () => index_default
  22. });
  23. module.exports = __toCommonJS(index_exports);
  24. // node_modules/color-name/index.js
  25. var colors = {
  26. aliceblue: [240, 248, 255],
  27. antiquewhite: [250, 235, 215],
  28. aqua: [0, 255, 255],
  29. aquamarine: [127, 255, 212],
  30. azure: [240, 255, 255],
  31. beige: [245, 245, 220],
  32. bisque: [255, 228, 196],
  33. black: [0, 0, 0],
  34. blanchedalmond: [255, 235, 205],
  35. blue: [0, 0, 255],
  36. blueviolet: [138, 43, 226],
  37. brown: [165, 42, 42],
  38. burlywood: [222, 184, 135],
  39. cadetblue: [95, 158, 160],
  40. chartreuse: [127, 255, 0],
  41. chocolate: [210, 105, 30],
  42. coral: [255, 127, 80],
  43. cornflowerblue: [100, 149, 237],
  44. cornsilk: [255, 248, 220],
  45. crimson: [220, 20, 60],
  46. cyan: [0, 255, 255],
  47. darkblue: [0, 0, 139],
  48. darkcyan: [0, 139, 139],
  49. darkgoldenrod: [184, 134, 11],
  50. darkgray: [169, 169, 169],
  51. darkgreen: [0, 100, 0],
  52. darkgrey: [169, 169, 169],
  53. darkkhaki: [189, 183, 107],
  54. darkmagenta: [139, 0, 139],
  55. darkolivegreen: [85, 107, 47],
  56. darkorange: [255, 140, 0],
  57. darkorchid: [153, 50, 204],
  58. darkred: [139, 0, 0],
  59. darksalmon: [233, 150, 122],
  60. darkseagreen: [143, 188, 143],
  61. darkslateblue: [72, 61, 139],
  62. darkslategray: [47, 79, 79],
  63. darkslategrey: [47, 79, 79],
  64. darkturquoise: [0, 206, 209],
  65. darkviolet: [148, 0, 211],
  66. deeppink: [255, 20, 147],
  67. deepskyblue: [0, 191, 255],
  68. dimgray: [105, 105, 105],
  69. dimgrey: [105, 105, 105],
  70. dodgerblue: [30, 144, 255],
  71. firebrick: [178, 34, 34],
  72. floralwhite: [255, 250, 240],
  73. forestgreen: [34, 139, 34],
  74. fuchsia: [255, 0, 255],
  75. gainsboro: [220, 220, 220],
  76. ghostwhite: [248, 248, 255],
  77. gold: [255, 215, 0],
  78. goldenrod: [218, 165, 32],
  79. gray: [128, 128, 128],
  80. green: [0, 128, 0],
  81. greenyellow: [173, 255, 47],
  82. grey: [128, 128, 128],
  83. honeydew: [240, 255, 240],
  84. hotpink: [255, 105, 180],
  85. indianred: [205, 92, 92],
  86. indigo: [75, 0, 130],
  87. ivory: [255, 255, 240],
  88. khaki: [240, 230, 140],
  89. lavender: [230, 230, 250],
  90. lavenderblush: [255, 240, 245],
  91. lawngreen: [124, 252, 0],
  92. lemonchiffon: [255, 250, 205],
  93. lightblue: [173, 216, 230],
  94. lightcoral: [240, 128, 128],
  95. lightcyan: [224, 255, 255],
  96. lightgoldenrodyellow: [250, 250, 210],
  97. lightgray: [211, 211, 211],
  98. lightgreen: [144, 238, 144],
  99. lightgrey: [211, 211, 211],
  100. lightpink: [255, 182, 193],
  101. lightsalmon: [255, 160, 122],
  102. lightseagreen: [32, 178, 170],
  103. lightskyblue: [135, 206, 250],
  104. lightslategray: [119, 136, 153],
  105. lightslategrey: [119, 136, 153],
  106. lightsteelblue: [176, 196, 222],
  107. lightyellow: [255, 255, 224],
  108. lime: [0, 255, 0],
  109. limegreen: [50, 205, 50],
  110. linen: [250, 240, 230],
  111. magenta: [255, 0, 255],
  112. maroon: [128, 0, 0],
  113. mediumaquamarine: [102, 205, 170],
  114. mediumblue: [0, 0, 205],
  115. mediumorchid: [186, 85, 211],
  116. mediumpurple: [147, 112, 219],
  117. mediumseagreen: [60, 179, 113],
  118. mediumslateblue: [123, 104, 238],
  119. mediumspringgreen: [0, 250, 154],
  120. mediumturquoise: [72, 209, 204],
  121. mediumvioletred: [199, 21, 133],
  122. midnightblue: [25, 25, 112],
  123. mintcream: [245, 255, 250],
  124. mistyrose: [255, 228, 225],
  125. moccasin: [255, 228, 181],
  126. navajowhite: [255, 222, 173],
  127. navy: [0, 0, 128],
  128. oldlace: [253, 245, 230],
  129. olive: [128, 128, 0],
  130. olivedrab: [107, 142, 35],
  131. orange: [255, 165, 0],
  132. orangered: [255, 69, 0],
  133. orchid: [218, 112, 214],
  134. palegoldenrod: [238, 232, 170],
  135. palegreen: [152, 251, 152],
  136. paleturquoise: [175, 238, 238],
  137. palevioletred: [219, 112, 147],
  138. papayawhip: [255, 239, 213],
  139. peachpuff: [255, 218, 185],
  140. peru: [205, 133, 63],
  141. pink: [255, 192, 203],
  142. plum: [221, 160, 221],
  143. powderblue: [176, 224, 230],
  144. purple: [128, 0, 128],
  145. rebeccapurple: [102, 51, 153],
  146. red: [255, 0, 0],
  147. rosybrown: [188, 143, 143],
  148. royalblue: [65, 105, 225],
  149. saddlebrown: [139, 69, 19],
  150. salmon: [250, 128, 114],
  151. sandybrown: [244, 164, 96],
  152. seagreen: [46, 139, 87],
  153. seashell: [255, 245, 238],
  154. sienna: [160, 82, 45],
  155. silver: [192, 192, 192],
  156. skyblue: [135, 206, 235],
  157. slateblue: [106, 90, 205],
  158. slategray: [112, 128, 144],
  159. slategrey: [112, 128, 144],
  160. snow: [255, 250, 250],
  161. springgreen: [0, 255, 127],
  162. steelblue: [70, 130, 180],
  163. tan: [210, 180, 140],
  164. teal: [0, 128, 128],
  165. thistle: [216, 191, 216],
  166. tomato: [255, 99, 71],
  167. turquoise: [64, 224, 208],
  168. violet: [238, 130, 238],
  169. wheat: [245, 222, 179],
  170. white: [255, 255, 255],
  171. whitesmoke: [245, 245, 245],
  172. yellow: [255, 255, 0],
  173. yellowgreen: [154, 205, 50]
  174. };
  175. for (const key in colors) Object.freeze(colors[key]);
  176. var color_name_default = Object.freeze(colors);
  177. // node_modules/color-string/index.js
  178. var reverseNames = /* @__PURE__ */ Object.create(null);
  179. for (const name in color_name_default) {
  180. if (Object.hasOwn(color_name_default, name)) {
  181. reverseNames[color_name_default[name]] = name;
  182. }
  183. }
  184. var cs = {
  185. to: {},
  186. get: {}
  187. };
  188. cs.get = function(string) {
  189. const prefix = string.slice(0, 3).toLowerCase();
  190. let value;
  191. let model;
  192. switch (prefix) {
  193. case "hsl": {
  194. value = cs.get.hsl(string);
  195. model = "hsl";
  196. break;
  197. }
  198. case "hwb": {
  199. value = cs.get.hwb(string);
  200. model = "hwb";
  201. break;
  202. }
  203. default: {
  204. value = cs.get.rgb(string);
  205. model = "rgb";
  206. break;
  207. }
  208. }
  209. if (!value) {
  210. return null;
  211. }
  212. return { model, value };
  213. };
  214. cs.get.rgb = function(string) {
  215. if (!string) {
  216. return null;
  217. }
  218. const abbr = /^#([a-f\d]{3,4})$/i;
  219. const hex = /^#([a-f\d]{6})([a-f\d]{2})?$/i;
  220. const rgba = /^rgba?\(\s*([+-]?(?:\d*\.)?\d+(?:e\d+)?)(?=[\s,])\s*(?:,\s*)?([+-]?(?:\d*\.)?\d+(?:e\d+)?)(?=[\s,])\s*(?:,\s*)?([+-]?(?:\d*\.)?\d+(?:e\d+)?)\s*(?:[\s,|/]\s*([+-]?(?:\d*\.)?\d+(?:e\d+)?)(%?)\s*)?\)$/i;
  221. const per = /^rgba?\(\s*([+-]?[\d.]+)%\s*,?\s*([+-]?[\d.]+)%\s*,?\s*([+-]?[\d.]+)%\s*(?:[\s,|/]\s*([+-]?[\d.]+)(%?)\s*)?\)$/i;
  222. const keyword = /^(\w+)$/;
  223. let rgb = [0, 0, 0, 1];
  224. let match;
  225. let i;
  226. let hexAlpha;
  227. if (match = string.match(hex)) {
  228. hexAlpha = match[2];
  229. match = match[1];
  230. for (i = 0; i < 3; i++) {
  231. const i2 = i * 2;
  232. rgb[i] = Number.parseInt(match.slice(i2, i2 + 2), 16);
  233. }
  234. if (hexAlpha) {
  235. rgb[3] = Number.parseInt(hexAlpha, 16) / 255;
  236. }
  237. } else if (match = string.match(abbr)) {
  238. match = match[1];
  239. hexAlpha = match[3];
  240. for (i = 0; i < 3; i++) {
  241. rgb[i] = Number.parseInt(match[i] + match[i], 16);
  242. }
  243. if (hexAlpha) {
  244. rgb[3] = Number.parseInt(hexAlpha + hexAlpha, 16) / 255;
  245. }
  246. } else if (match = string.match(rgba)) {
  247. for (i = 0; i < 3; i++) {
  248. rgb[i] = Number.parseFloat(match[i + 1]);
  249. }
  250. if (match[4]) {
  251. rgb[3] = match[5] ? Number.parseFloat(match[4]) * 0.01 : Number.parseFloat(match[4]);
  252. }
  253. } else if (match = string.match(per)) {
  254. for (i = 0; i < 3; i++) {
  255. rgb[i] = Math.round(Number.parseFloat(match[i + 1]) * 2.55);
  256. }
  257. if (match[4]) {
  258. rgb[3] = match[5] ? Number.parseFloat(match[4]) * 0.01 : Number.parseFloat(match[4]);
  259. }
  260. } else if (match = string.toLowerCase().match(keyword)) {
  261. if (match[1] === "transparent") {
  262. return [0, 0, 0, 0];
  263. }
  264. if (!Object.hasOwn(color_name_default, match[1])) {
  265. return null;
  266. }
  267. rgb = color_name_default[match[1]].slice();
  268. rgb[3] = 1;
  269. return rgb;
  270. } else {
  271. return null;
  272. }
  273. for (i = 0; i < 3; i++) {
  274. rgb[i] = clamp(rgb[i], 0, 255);
  275. }
  276. rgb[3] = clamp(rgb[3], 0, 1);
  277. return rgb;
  278. };
  279. cs.get.hsl = function(string) {
  280. if (!string) {
  281. return null;
  282. }
  283. const hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d.]+)%\s*,?\s*([+-]?[\d.]+)%\s*(?:[,|/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:e[+-]?\d+)?)\s*)?\)$/i;
  284. const match = string.match(hsl);
  285. if (match) {
  286. const alpha = Number.parseFloat(match[4]);
  287. const h = (Number.parseFloat(match[1]) % 360 + 360) % 360;
  288. const s = clamp(Number.parseFloat(match[2]), 0, 100);
  289. const l = clamp(Number.parseFloat(match[3]), 0, 100);
  290. const a = clamp(Number.isNaN(alpha) ? 1 : alpha, 0, 1);
  291. return [h, s, l, a];
  292. }
  293. return null;
  294. };
  295. cs.get.hwb = function(string) {
  296. if (!string) {
  297. return null;
  298. }
  299. const hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*[\s,]\s*([+-]?[\d.]+)%\s*[\s,]\s*([+-]?[\d.]+)%\s*(?:[\s,]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:e[+-]?\d+)?)\s*)?\)$/i;
  300. const match = string.match(hwb);
  301. if (match) {
  302. const alpha = Number.parseFloat(match[4]);
  303. const h = (Number.parseFloat(match[1]) % 360 + 360) % 360;
  304. const w = clamp(Number.parseFloat(match[2]), 0, 100);
  305. const b = clamp(Number.parseFloat(match[3]), 0, 100);
  306. const a = clamp(Number.isNaN(alpha) ? 1 : alpha, 0, 1);
  307. return [h, w, b, a];
  308. }
  309. return null;
  310. };
  311. cs.to.hex = function(...rgba) {
  312. return "#" + hexDouble(rgba[0]) + hexDouble(rgba[1]) + hexDouble(rgba[2]) + (rgba[3] < 1 ? hexDouble(Math.round(rgba[3] * 255)) : "");
  313. };
  314. cs.to.rgb = function(...rgba) {
  315. return rgba.length < 4 || rgba[3] === 1 ? "rgb(" + Math.round(rgba[0]) + ", " + Math.round(rgba[1]) + ", " + Math.round(rgba[2]) + ")" : "rgba(" + Math.round(rgba[0]) + ", " + Math.round(rgba[1]) + ", " + Math.round(rgba[2]) + ", " + rgba[3] + ")";
  316. };
  317. cs.to.rgb.percent = function(...rgba) {
  318. const r = Math.round(rgba[0] / 255 * 100);
  319. const g = Math.round(rgba[1] / 255 * 100);
  320. const b = Math.round(rgba[2] / 255 * 100);
  321. return rgba.length < 4 || rgba[3] === 1 ? "rgb(" + r + "%, " + g + "%, " + b + "%)" : "rgba(" + r + "%, " + g + "%, " + b + "%, " + rgba[3] + ")";
  322. };
  323. cs.to.hsl = function(...hsla) {
  324. return hsla.length < 4 || hsla[3] === 1 ? "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)" : "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, " + hsla[3] + ")";
  325. };
  326. cs.to.hwb = function(...hwba) {
  327. let a = "";
  328. if (hwba.length >= 4 && hwba[3] !== 1) {
  329. a = ", " + hwba[3];
  330. }
  331. return "hwb(" + hwba[0] + ", " + hwba[1] + "%, " + hwba[2] + "%" + a + ")";
  332. };
  333. cs.to.keyword = function(...rgb) {
  334. return reverseNames[rgb.slice(0, 3)];
  335. };
  336. function clamp(number_, min, max) {
  337. return Math.min(Math.max(min, number_), max);
  338. }
  339. function hexDouble(number_) {
  340. const string_ = Math.round(number_).toString(16).toUpperCase();
  341. return string_.length < 2 ? "0" + string_ : string_;
  342. }
  343. var color_string_default = cs;
  344. // node_modules/color-convert/conversions.js
  345. var reverseKeywords = {};
  346. for (const key of Object.keys(color_name_default)) {
  347. reverseKeywords[color_name_default[key]] = key;
  348. }
  349. var convert = {
  350. rgb: { channels: 3, labels: "rgb" },
  351. hsl: { channels: 3, labels: "hsl" },
  352. hsv: { channels: 3, labels: "hsv" },
  353. hwb: { channels: 3, labels: "hwb" },
  354. cmyk: { channels: 4, labels: "cmyk" },
  355. xyz: { channels: 3, labels: "xyz" },
  356. lab: { channels: 3, labels: "lab" },
  357. oklab: { channels: 3, labels: ["okl", "oka", "okb"] },
  358. lch: { channels: 3, labels: "lch" },
  359. oklch: { channels: 3, labels: ["okl", "okc", "okh"] },
  360. hex: { channels: 1, labels: ["hex"] },
  361. keyword: { channels: 1, labels: ["keyword"] },
  362. ansi16: { channels: 1, labels: ["ansi16"] },
  363. ansi256: { channels: 1, labels: ["ansi256"] },
  364. hcg: { channels: 3, labels: ["h", "c", "g"] },
  365. apple: { channels: 3, labels: ["r16", "g16", "b16"] },
  366. gray: { channels: 1, labels: ["gray"] }
  367. };
  368. var conversions_default = convert;
  369. var LAB_FT = (6 / 29) ** 3;
  370. function srgbNonlinearTransform(c) {
  371. const cc = c > 31308e-7 ? 1.055 * c ** (1 / 2.4) - 0.055 : c * 12.92;
  372. return Math.min(Math.max(0, cc), 1);
  373. }
  374. function srgbNonlinearTransformInv(c) {
  375. return c > 0.04045 ? ((c + 0.055) / 1.055) ** 2.4 : c / 12.92;
  376. }
  377. for (const model of Object.keys(convert)) {
  378. if (!("channels" in convert[model])) {
  379. throw new Error("missing channels property: " + model);
  380. }
  381. if (!("labels" in convert[model])) {
  382. throw new Error("missing channel labels property: " + model);
  383. }
  384. if (convert[model].labels.length !== convert[model].channels) {
  385. throw new Error("channel and label counts mismatch: " + model);
  386. }
  387. const { channels, labels } = convert[model];
  388. delete convert[model].channels;
  389. delete convert[model].labels;
  390. Object.defineProperty(convert[model], "channels", { value: channels });
  391. Object.defineProperty(convert[model], "labels", { value: labels });
  392. }
  393. convert.rgb.hsl = function(rgb) {
  394. const r = rgb[0] / 255;
  395. const g = rgb[1] / 255;
  396. const b = rgb[2] / 255;
  397. const min = Math.min(r, g, b);
  398. const max = Math.max(r, g, b);
  399. const delta = max - min;
  400. let h;
  401. let s;
  402. switch (max) {
  403. case min: {
  404. h = 0;
  405. break;
  406. }
  407. case r: {
  408. h = (g - b) / delta;
  409. break;
  410. }
  411. case g: {
  412. h = 2 + (b - r) / delta;
  413. break;
  414. }
  415. case b: {
  416. h = 4 + (r - g) / delta;
  417. break;
  418. }
  419. }
  420. h = Math.min(h * 60, 360);
  421. if (h < 0) {
  422. h += 360;
  423. }
  424. const l = (min + max) / 2;
  425. if (max === min) {
  426. s = 0;
  427. } else if (l <= 0.5) {
  428. s = delta / (max + min);
  429. } else {
  430. s = delta / (2 - max - min);
  431. }
  432. return [h, s * 100, l * 100];
  433. };
  434. convert.rgb.hsv = function(rgb) {
  435. let rdif;
  436. let gdif;
  437. let bdif;
  438. let h;
  439. let s;
  440. const r = rgb[0] / 255;
  441. const g = rgb[1] / 255;
  442. const b = rgb[2] / 255;
  443. const v = Math.max(r, g, b);
  444. const diff = v - Math.min(r, g, b);
  445. const diffc = function(c) {
  446. return (v - c) / 6 / diff + 1 / 2;
  447. };
  448. if (diff === 0) {
  449. h = 0;
  450. s = 0;
  451. } else {
  452. s = diff / v;
  453. rdif = diffc(r);
  454. gdif = diffc(g);
  455. bdif = diffc(b);
  456. switch (v) {
  457. case r: {
  458. h = bdif - gdif;
  459. break;
  460. }
  461. case g: {
  462. h = 1 / 3 + rdif - bdif;
  463. break;
  464. }
  465. case b: {
  466. h = 2 / 3 + gdif - rdif;
  467. break;
  468. }
  469. }
  470. if (h < 0) {
  471. h += 1;
  472. } else if (h > 1) {
  473. h -= 1;
  474. }
  475. }
  476. return [
  477. h * 360,
  478. s * 100,
  479. v * 100
  480. ];
  481. };
  482. convert.rgb.hwb = function(rgb) {
  483. const r = rgb[0];
  484. const g = rgb[1];
  485. let b = rgb[2];
  486. const h = convert.rgb.hsl(rgb)[0];
  487. const w = 1 / 255 * Math.min(r, Math.min(g, b));
  488. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  489. return [h, w * 100, b * 100];
  490. };
  491. convert.rgb.oklab = function(rgb) {
  492. const r = srgbNonlinearTransformInv(rgb[0] / 255);
  493. const g = srgbNonlinearTransformInv(rgb[1] / 255);
  494. const b = srgbNonlinearTransformInv(rgb[2] / 255);
  495. const lp = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
  496. const mp = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
  497. const sp = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
  498. const l = 0.2104542553 * lp + 0.793617785 * mp - 0.0040720468 * sp;
  499. const aa = 1.9779984951 * lp - 2.428592205 * mp + 0.4505937099 * sp;
  500. const bb = 0.0259040371 * lp + 0.7827717662 * mp - 0.808675766 * sp;
  501. return [l * 100, aa * 100, bb * 100];
  502. };
  503. convert.rgb.cmyk = function(rgb) {
  504. const r = rgb[0] / 255;
  505. const g = rgb[1] / 255;
  506. const b = rgb[2] / 255;
  507. const k = Math.min(1 - r, 1 - g, 1 - b);
  508. const c = (1 - r - k) / (1 - k) || 0;
  509. const m = (1 - g - k) / (1 - k) || 0;
  510. const y = (1 - b - k) / (1 - k) || 0;
  511. return [c * 100, m * 100, y * 100, k * 100];
  512. };
  513. function comparativeDistance(x, y) {
  514. return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
  515. }
  516. convert.rgb.keyword = function(rgb) {
  517. const reversed = reverseKeywords[rgb];
  518. if (reversed) {
  519. return reversed;
  520. }
  521. let currentClosestDistance = Number.POSITIVE_INFINITY;
  522. let currentClosestKeyword;
  523. for (const keyword of Object.keys(color_name_default)) {
  524. const value = color_name_default[keyword];
  525. const distance = comparativeDistance(rgb, value);
  526. if (distance < currentClosestDistance) {
  527. currentClosestDistance = distance;
  528. currentClosestKeyword = keyword;
  529. }
  530. }
  531. return currentClosestKeyword;
  532. };
  533. convert.keyword.rgb = function(keyword) {
  534. return [...color_name_default[keyword]];
  535. };
  536. convert.rgb.xyz = function(rgb) {
  537. const r = srgbNonlinearTransformInv(rgb[0] / 255);
  538. const g = srgbNonlinearTransformInv(rgb[1] / 255);
  539. const b = srgbNonlinearTransformInv(rgb[2] / 255);
  540. const x = r * 0.4124564 + g * 0.3575761 + b * 0.1804375;
  541. const y = r * 0.2126729 + g * 0.7151522 + b * 0.072175;
  542. const z = r * 0.0193339 + g * 0.119192 + b * 0.9503041;
  543. return [x * 100, y * 100, z * 100];
  544. };
  545. convert.rgb.lab = function(rgb) {
  546. const xyz = convert.rgb.xyz(rgb);
  547. let x = xyz[0];
  548. let y = xyz[1];
  549. let z = xyz[2];
  550. x /= 95.047;
  551. y /= 100;
  552. z /= 108.883;
  553. x = x > LAB_FT ? x ** (1 / 3) : 7.787 * x + 16 / 116;
  554. y = y > LAB_FT ? y ** (1 / 3) : 7.787 * y + 16 / 116;
  555. z = z > LAB_FT ? z ** (1 / 3) : 7.787 * z + 16 / 116;
  556. const l = 116 * y - 16;
  557. const a = 500 * (x - y);
  558. const b = 200 * (y - z);
  559. return [l, a, b];
  560. };
  561. convert.hsl.rgb = function(hsl) {
  562. const h = hsl[0] / 360;
  563. const s = hsl[1] / 100;
  564. const l = hsl[2] / 100;
  565. let t3;
  566. let value;
  567. if (s === 0) {
  568. value = l * 255;
  569. return [value, value, value];
  570. }
  571. const t2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
  572. const t1 = 2 * l - t2;
  573. const rgb = [0, 0, 0];
  574. for (let i = 0; i < 3; i++) {
  575. t3 = h + 1 / 3 * -(i - 1);
  576. if (t3 < 0) {
  577. t3++;
  578. }
  579. if (t3 > 1) {
  580. t3--;
  581. }
  582. if (6 * t3 < 1) {
  583. value = t1 + (t2 - t1) * 6 * t3;
  584. } else if (2 * t3 < 1) {
  585. value = t2;
  586. } else if (3 * t3 < 2) {
  587. value = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  588. } else {
  589. value = t1;
  590. }
  591. rgb[i] = value * 255;
  592. }
  593. return rgb;
  594. };
  595. convert.hsl.hsv = function(hsl) {
  596. const h = hsl[0];
  597. let s = hsl[1] / 100;
  598. let l = hsl[2] / 100;
  599. let smin = s;
  600. const lmin = Math.max(l, 0.01);
  601. l *= 2;
  602. s *= l <= 1 ? l : 2 - l;
  603. smin *= lmin <= 1 ? lmin : 2 - lmin;
  604. const v = (l + s) / 2;
  605. const sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  606. return [h, sv * 100, v * 100];
  607. };
  608. convert.hsv.rgb = function(hsv) {
  609. const h = hsv[0] / 60;
  610. const s = hsv[1] / 100;
  611. let v = hsv[2] / 100;
  612. const hi = Math.floor(h) % 6;
  613. const f = h - Math.floor(h);
  614. const p = 255 * v * (1 - s);
  615. const q = 255 * v * (1 - s * f);
  616. const t = 255 * v * (1 - s * (1 - f));
  617. v *= 255;
  618. switch (hi) {
  619. case 0: {
  620. return [v, t, p];
  621. }
  622. case 1: {
  623. return [q, v, p];
  624. }
  625. case 2: {
  626. return [p, v, t];
  627. }
  628. case 3: {
  629. return [p, q, v];
  630. }
  631. case 4: {
  632. return [t, p, v];
  633. }
  634. case 5: {
  635. return [v, p, q];
  636. }
  637. }
  638. };
  639. convert.hsv.hsl = function(hsv) {
  640. const h = hsv[0];
  641. const s = hsv[1] / 100;
  642. const v = hsv[2] / 100;
  643. const vmin = Math.max(v, 0.01);
  644. let sl;
  645. let l;
  646. l = (2 - s) * v;
  647. const lmin = (2 - s) * vmin;
  648. sl = s * vmin;
  649. sl /= lmin <= 1 ? lmin : 2 - lmin;
  650. sl = sl || 0;
  651. l /= 2;
  652. return [h, sl * 100, l * 100];
  653. };
  654. convert.hwb.rgb = function(hwb) {
  655. const h = hwb[0] / 360;
  656. let wh = hwb[1] / 100;
  657. let bl = hwb[2] / 100;
  658. const ratio = wh + bl;
  659. let f;
  660. if (ratio > 1) {
  661. wh /= ratio;
  662. bl /= ratio;
  663. }
  664. const i = Math.floor(6 * h);
  665. const v = 1 - bl;
  666. f = 6 * h - i;
  667. if ((i & 1) !== 0) {
  668. f = 1 - f;
  669. }
  670. const n = wh + f * (v - wh);
  671. let r;
  672. let g;
  673. let b;
  674. switch (i) {
  675. default:
  676. case 6:
  677. case 0: {
  678. r = v;
  679. g = n;
  680. b = wh;
  681. break;
  682. }
  683. case 1: {
  684. r = n;
  685. g = v;
  686. b = wh;
  687. break;
  688. }
  689. case 2: {
  690. r = wh;
  691. g = v;
  692. b = n;
  693. break;
  694. }
  695. case 3: {
  696. r = wh;
  697. g = n;
  698. b = v;
  699. break;
  700. }
  701. case 4: {
  702. r = n;
  703. g = wh;
  704. b = v;
  705. break;
  706. }
  707. case 5: {
  708. r = v;
  709. g = wh;
  710. b = n;
  711. break;
  712. }
  713. }
  714. return [r * 255, g * 255, b * 255];
  715. };
  716. convert.cmyk.rgb = function(cmyk) {
  717. const c = cmyk[0] / 100;
  718. const m = cmyk[1] / 100;
  719. const y = cmyk[2] / 100;
  720. const k = cmyk[3] / 100;
  721. const r = 1 - Math.min(1, c * (1 - k) + k);
  722. const g = 1 - Math.min(1, m * (1 - k) + k);
  723. const b = 1 - Math.min(1, y * (1 - k) + k);
  724. return [r * 255, g * 255, b * 255];
  725. };
  726. convert.xyz.rgb = function(xyz) {
  727. const x = xyz[0] / 100;
  728. const y = xyz[1] / 100;
  729. const z = xyz[2] / 100;
  730. let r;
  731. let g;
  732. let b;
  733. r = x * 3.2404542 + y * -1.5371385 + z * -0.4985314;
  734. g = x * -0.969266 + y * 1.8760108 + z * 0.041556;
  735. b = x * 0.0556434 + y * -0.2040259 + z * 1.0572252;
  736. r = srgbNonlinearTransform(r);
  737. g = srgbNonlinearTransform(g);
  738. b = srgbNonlinearTransform(b);
  739. return [r * 255, g * 255, b * 255];
  740. };
  741. convert.xyz.lab = function(xyz) {
  742. let x = xyz[0];
  743. let y = xyz[1];
  744. let z = xyz[2];
  745. x /= 95.047;
  746. y /= 100;
  747. z /= 108.883;
  748. x = x > LAB_FT ? x ** (1 / 3) : 7.787 * x + 16 / 116;
  749. y = y > LAB_FT ? y ** (1 / 3) : 7.787 * y + 16 / 116;
  750. z = z > LAB_FT ? z ** (1 / 3) : 7.787 * z + 16 / 116;
  751. const l = 116 * y - 16;
  752. const a = 500 * (x - y);
  753. const b = 200 * (y - z);
  754. return [l, a, b];
  755. };
  756. convert.xyz.oklab = function(xyz) {
  757. const x = xyz[0] / 100;
  758. const y = xyz[1] / 100;
  759. const z = xyz[2] / 100;
  760. const lp = Math.cbrt(0.8189330101 * x + 0.3618667424 * y - 0.1288597137 * z);
  761. const mp = Math.cbrt(0.0329845436 * x + 0.9293118715 * y + 0.0361456387 * z);
  762. const sp = Math.cbrt(0.0482003018 * x + 0.2643662691 * y + 0.633851707 * z);
  763. const l = 0.2104542553 * lp + 0.793617785 * mp - 0.0040720468 * sp;
  764. const a = 1.9779984951 * lp - 2.428592205 * mp + 0.4505937099 * sp;
  765. const b = 0.0259040371 * lp + 0.7827717662 * mp - 0.808675766 * sp;
  766. return [l * 100, a * 100, b * 100];
  767. };
  768. convert.oklab.oklch = function(oklab) {
  769. return convert.lab.lch(oklab);
  770. };
  771. convert.oklab.xyz = function(oklab) {
  772. const ll = oklab[0] / 100;
  773. const a = oklab[1] / 100;
  774. const b = oklab[2] / 100;
  775. const l = (0.999999998 * ll + 0.396337792 * a + 0.215803758 * b) ** 3;
  776. const m = (1.000000008 * ll - 0.105561342 * a - 0.063854175 * b) ** 3;
  777. const s = (1.000000055 * ll - 0.089484182 * a - 1.291485538 * b) ** 3;
  778. const x = 1.227013851 * l - 0.55779998 * m + 0.281256149 * s;
  779. const y = -0.040580178 * l + 1.11225687 * m - 0.071676679 * s;
  780. const z = -0.076381285 * l - 0.421481978 * m + 1.58616322 * s;
  781. return [x * 100, y * 100, z * 100];
  782. };
  783. convert.oklab.rgb = function(oklab) {
  784. const ll = oklab[0] / 100;
  785. const aa = oklab[1] / 100;
  786. const bb = oklab[2] / 100;
  787. const l = (ll + 0.3963377774 * aa + 0.2158037573 * bb) ** 3;
  788. const m = (ll - 0.1055613458 * aa - 0.0638541728 * bb) ** 3;
  789. const s = (ll - 0.0894841775 * aa - 1.291485548 * bb) ** 3;
  790. const r = srgbNonlinearTransform(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s);
  791. const g = srgbNonlinearTransform(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s);
  792. const b = srgbNonlinearTransform(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s);
  793. return [r * 255, g * 255, b * 255];
  794. };
  795. convert.oklch.oklab = function(oklch) {
  796. return convert.lch.lab(oklch);
  797. };
  798. convert.lab.xyz = function(lab) {
  799. const l = lab[0];
  800. const a = lab[1];
  801. const b = lab[2];
  802. let x;
  803. let y;
  804. let z;
  805. y = (l + 16) / 116;
  806. x = a / 500 + y;
  807. z = y - b / 200;
  808. const y2 = y ** 3;
  809. const x2 = x ** 3;
  810. const z2 = z ** 3;
  811. y = y2 > LAB_FT ? y2 : (y - 16 / 116) / 7.787;
  812. x = x2 > LAB_FT ? x2 : (x - 16 / 116) / 7.787;
  813. z = z2 > LAB_FT ? z2 : (z - 16 / 116) / 7.787;
  814. x *= 95.047;
  815. y *= 100;
  816. z *= 108.883;
  817. return [x, y, z];
  818. };
  819. convert.lab.lch = function(lab) {
  820. const l = lab[0];
  821. const a = lab[1];
  822. const b = lab[2];
  823. let h;
  824. const hr = Math.atan2(b, a);
  825. h = hr * 360 / 2 / Math.PI;
  826. if (h < 0) {
  827. h += 360;
  828. }
  829. const c = Math.sqrt(a * a + b * b);
  830. return [l, c, h];
  831. };
  832. convert.lch.lab = function(lch) {
  833. const l = lch[0];
  834. const c = lch[1];
  835. const h = lch[2];
  836. const hr = h / 360 * 2 * Math.PI;
  837. const a = c * Math.cos(hr);
  838. const b = c * Math.sin(hr);
  839. return [l, a, b];
  840. };
  841. convert.rgb.ansi16 = function(args, saturation = null) {
  842. const [r, g, b] = args;
  843. let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation;
  844. value = Math.round(value / 50);
  845. if (value === 0) {
  846. return 30;
  847. }
  848. let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  849. if (value === 2) {
  850. ansi += 60;
  851. }
  852. return ansi;
  853. };
  854. convert.hsv.ansi16 = function(args) {
  855. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  856. };
  857. convert.rgb.ansi256 = function(args) {
  858. const r = args[0];
  859. const g = args[1];
  860. const b = args[2];
  861. if (r >> 4 === g >> 4 && g >> 4 === b >> 4) {
  862. if (r < 8) {
  863. return 16;
  864. }
  865. if (r > 248) {
  866. return 231;
  867. }
  868. return Math.round((r - 8) / 247 * 24) + 232;
  869. }
  870. const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  871. return ansi;
  872. };
  873. convert.ansi16.rgb = function(args) {
  874. args = args[0];
  875. let color = args % 10;
  876. if (color === 0 || color === 7) {
  877. if (args > 50) {
  878. color += 3.5;
  879. }
  880. color = color / 10.5 * 255;
  881. return [color, color, color];
  882. }
  883. const mult = (Math.trunc(args > 50) + 1) * 0.5;
  884. const r = (color & 1) * mult * 255;
  885. const g = (color >> 1 & 1) * mult * 255;
  886. const b = (color >> 2 & 1) * mult * 255;
  887. return [r, g, b];
  888. };
  889. convert.ansi256.rgb = function(args) {
  890. args = args[0];
  891. if (args >= 232) {
  892. const c = (args - 232) * 10 + 8;
  893. return [c, c, c];
  894. }
  895. args -= 16;
  896. let rem;
  897. const r = Math.floor(args / 36) / 5 * 255;
  898. const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  899. const b = rem % 6 / 5 * 255;
  900. return [r, g, b];
  901. };
  902. convert.rgb.hex = function(args) {
  903. const integer = ((Math.round(args[0]) & 255) << 16) + ((Math.round(args[1]) & 255) << 8) + (Math.round(args[2]) & 255);
  904. const string = integer.toString(16).toUpperCase();
  905. return "000000".slice(string.length) + string;
  906. };
  907. convert.hex.rgb = function(args) {
  908. const match = args.toString(16).match(/[a-f\d]{6}|[a-f\d]{3}/i);
  909. if (!match) {
  910. return [0, 0, 0];
  911. }
  912. let colorString = match[0];
  913. if (match[0].length === 3) {
  914. colorString = [...colorString].map((char) => char + char).join("");
  915. }
  916. const integer = Number.parseInt(colorString, 16);
  917. const r = integer >> 16 & 255;
  918. const g = integer >> 8 & 255;
  919. const b = integer & 255;
  920. return [r, g, b];
  921. };
  922. convert.rgb.hcg = function(rgb) {
  923. const r = rgb[0] / 255;
  924. const g = rgb[1] / 255;
  925. const b = rgb[2] / 255;
  926. const max = Math.max(Math.max(r, g), b);
  927. const min = Math.min(Math.min(r, g), b);
  928. const chroma = max - min;
  929. let hue;
  930. const grayscale = chroma < 1 ? min / (1 - chroma) : 0;
  931. if (chroma <= 0) {
  932. hue = 0;
  933. } else if (max === r) {
  934. hue = (g - b) / chroma % 6;
  935. } else if (max === g) {
  936. hue = 2 + (b - r) / chroma;
  937. } else {
  938. hue = 4 + (r - g) / chroma;
  939. }
  940. hue /= 6;
  941. hue %= 1;
  942. return [hue * 360, chroma * 100, grayscale * 100];
  943. };
  944. convert.hsl.hcg = function(hsl) {
  945. const s = hsl[1] / 100;
  946. const l = hsl[2] / 100;
  947. const c = l < 0.5 ? 2 * s * l : 2 * s * (1 - l);
  948. let f = 0;
  949. if (c < 1) {
  950. f = (l - 0.5 * c) / (1 - c);
  951. }
  952. return [hsl[0], c * 100, f * 100];
  953. };
  954. convert.hsv.hcg = function(hsv) {
  955. const s = hsv[1] / 100;
  956. const v = hsv[2] / 100;
  957. const c = s * v;
  958. let f = 0;
  959. if (c < 1) {
  960. f = (v - c) / (1 - c);
  961. }
  962. return [hsv[0], c * 100, f * 100];
  963. };
  964. convert.hcg.rgb = function(hcg) {
  965. const h = hcg[0] / 360;
  966. const c = hcg[1] / 100;
  967. const g = hcg[2] / 100;
  968. if (c === 0) {
  969. return [g * 255, g * 255, g * 255];
  970. }
  971. const pure = [0, 0, 0];
  972. const hi = h % 1 * 6;
  973. const v = hi % 1;
  974. const w = 1 - v;
  975. let mg = 0;
  976. switch (Math.floor(hi)) {
  977. case 0: {
  978. pure[0] = 1;
  979. pure[1] = v;
  980. pure[2] = 0;
  981. break;
  982. }
  983. case 1: {
  984. pure[0] = w;
  985. pure[1] = 1;
  986. pure[2] = 0;
  987. break;
  988. }
  989. case 2: {
  990. pure[0] = 0;
  991. pure[1] = 1;
  992. pure[2] = v;
  993. break;
  994. }
  995. case 3: {
  996. pure[0] = 0;
  997. pure[1] = w;
  998. pure[2] = 1;
  999. break;
  1000. }
  1001. case 4: {
  1002. pure[0] = v;
  1003. pure[1] = 0;
  1004. pure[2] = 1;
  1005. break;
  1006. }
  1007. default: {
  1008. pure[0] = 1;
  1009. pure[1] = 0;
  1010. pure[2] = w;
  1011. }
  1012. }
  1013. mg = (1 - c) * g;
  1014. return [
  1015. (c * pure[0] + mg) * 255,
  1016. (c * pure[1] + mg) * 255,
  1017. (c * pure[2] + mg) * 255
  1018. ];
  1019. };
  1020. convert.hcg.hsv = function(hcg) {
  1021. const c = hcg[1] / 100;
  1022. const g = hcg[2] / 100;
  1023. const v = c + g * (1 - c);
  1024. let f = 0;
  1025. if (v > 0) {
  1026. f = c / v;
  1027. }
  1028. return [hcg[0], f * 100, v * 100];
  1029. };
  1030. convert.hcg.hsl = function(hcg) {
  1031. const c = hcg[1] / 100;
  1032. const g = hcg[2] / 100;
  1033. const l = g * (1 - c) + 0.5 * c;
  1034. let s = 0;
  1035. if (l > 0 && l < 0.5) {
  1036. s = c / (2 * l);
  1037. } else if (l >= 0.5 && l < 1) {
  1038. s = c / (2 * (1 - l));
  1039. }
  1040. return [hcg[0], s * 100, l * 100];
  1041. };
  1042. convert.hcg.hwb = function(hcg) {
  1043. const c = hcg[1] / 100;
  1044. const g = hcg[2] / 100;
  1045. const v = c + g * (1 - c);
  1046. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  1047. };
  1048. convert.hwb.hcg = function(hwb) {
  1049. const w = hwb[1] / 100;
  1050. const b = hwb[2] / 100;
  1051. const v = 1 - b;
  1052. const c = v - w;
  1053. let g = 0;
  1054. if (c < 1) {
  1055. g = (v - c) / (1 - c);
  1056. }
  1057. return [hwb[0], c * 100, g * 100];
  1058. };
  1059. convert.apple.rgb = function(apple) {
  1060. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  1061. };
  1062. convert.rgb.apple = function(rgb) {
  1063. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  1064. };
  1065. convert.gray.rgb = function(args) {
  1066. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  1067. };
  1068. convert.gray.hsl = function(args) {
  1069. return [0, 0, args[0]];
  1070. };
  1071. convert.gray.hsv = convert.gray.hsl;
  1072. convert.gray.hwb = function(gray) {
  1073. return [0, 100, gray[0]];
  1074. };
  1075. convert.gray.cmyk = function(gray) {
  1076. return [0, 0, 0, gray[0]];
  1077. };
  1078. convert.gray.lab = function(gray) {
  1079. return [gray[0], 0, 0];
  1080. };
  1081. convert.gray.hex = function(gray) {
  1082. const value = Math.round(gray[0] / 100 * 255) & 255;
  1083. const integer = (value << 16) + (value << 8) + value;
  1084. const string = integer.toString(16).toUpperCase();
  1085. return "000000".slice(string.length) + string;
  1086. };
  1087. convert.rgb.gray = function(rgb) {
  1088. const value = (rgb[0] + rgb[1] + rgb[2]) / 3;
  1089. return [value / 255 * 100];
  1090. };
  1091. // node_modules/color-convert/route.js
  1092. function buildGraph() {
  1093. const graph = {};
  1094. const models2 = Object.keys(conversions_default);
  1095. for (let { length } = models2, i = 0; i < length; i++) {
  1096. graph[models2[i]] = {
  1097. // http://jsperf.com/1-vs-infinity
  1098. // micro-opt, but this is simple.
  1099. distance: -1,
  1100. parent: null
  1101. };
  1102. }
  1103. return graph;
  1104. }
  1105. function deriveBFS(fromModel) {
  1106. const graph = buildGraph();
  1107. const queue = [fromModel];
  1108. graph[fromModel].distance = 0;
  1109. while (queue.length > 0) {
  1110. const current = queue.pop();
  1111. const adjacents = Object.keys(conversions_default[current]);
  1112. for (let { length } = adjacents, i = 0; i < length; i++) {
  1113. const adjacent = adjacents[i];
  1114. const node = graph[adjacent];
  1115. if (node.distance === -1) {
  1116. node.distance = graph[current].distance + 1;
  1117. node.parent = current;
  1118. queue.unshift(adjacent);
  1119. }
  1120. }
  1121. }
  1122. return graph;
  1123. }
  1124. function link(from, to) {
  1125. return function(args) {
  1126. return to(from(args));
  1127. };
  1128. }
  1129. function wrapConversion(toModel, graph) {
  1130. const path = [graph[toModel].parent, toModel];
  1131. let fn = conversions_default[graph[toModel].parent][toModel];
  1132. let cur = graph[toModel].parent;
  1133. while (graph[cur].parent) {
  1134. path.unshift(graph[cur].parent);
  1135. fn = link(conversions_default[graph[cur].parent][cur], fn);
  1136. cur = graph[cur].parent;
  1137. }
  1138. fn.conversion = path;
  1139. return fn;
  1140. }
  1141. function route(fromModel) {
  1142. const graph = deriveBFS(fromModel);
  1143. const conversion = {};
  1144. const models2 = Object.keys(graph);
  1145. for (let { length } = models2, i = 0; i < length; i++) {
  1146. const toModel = models2[i];
  1147. const node = graph[toModel];
  1148. if (node.parent === null) {
  1149. continue;
  1150. }
  1151. conversion[toModel] = wrapConversion(toModel, graph);
  1152. }
  1153. return conversion;
  1154. }
  1155. var route_default = route;
  1156. // node_modules/color-convert/index.js
  1157. var convert2 = {};
  1158. var models = Object.keys(conversions_default);
  1159. function wrapRaw(fn) {
  1160. const wrappedFn = function(...args) {
  1161. const arg0 = args[0];
  1162. if (arg0 === void 0 || arg0 === null) {
  1163. return arg0;
  1164. }
  1165. if (arg0.length > 1) {
  1166. args = arg0;
  1167. }
  1168. return fn(args);
  1169. };
  1170. if ("conversion" in fn) {
  1171. wrappedFn.conversion = fn.conversion;
  1172. }
  1173. return wrappedFn;
  1174. }
  1175. function wrapRounded(fn) {
  1176. const wrappedFn = function(...args) {
  1177. const arg0 = args[0];
  1178. if (arg0 === void 0 || arg0 === null) {
  1179. return arg0;
  1180. }
  1181. if (arg0.length > 1) {
  1182. args = arg0;
  1183. }
  1184. const result = fn(args);
  1185. if (typeof result === "object") {
  1186. for (let { length } = result, i = 0; i < length; i++) {
  1187. result[i] = Math.round(result[i]);
  1188. }
  1189. }
  1190. return result;
  1191. };
  1192. if ("conversion" in fn) {
  1193. wrappedFn.conversion = fn.conversion;
  1194. }
  1195. return wrappedFn;
  1196. }
  1197. for (const fromModel of models) {
  1198. convert2[fromModel] = {};
  1199. Object.defineProperty(convert2[fromModel], "channels", { value: conversions_default[fromModel].channels });
  1200. Object.defineProperty(convert2[fromModel], "labels", { value: conversions_default[fromModel].labels });
  1201. const routes = route_default(fromModel);
  1202. const routeModels = Object.keys(routes);
  1203. for (const toModel of routeModels) {
  1204. const fn = routes[toModel];
  1205. convert2[fromModel][toModel] = wrapRounded(fn);
  1206. convert2[fromModel][toModel].raw = wrapRaw(fn);
  1207. }
  1208. }
  1209. var color_convert_default = convert2;
  1210. // node_modules/color/index.js
  1211. var skippedModels = [
  1212. // To be honest, I don't really feel like keyword belongs in color convert, but eh.
  1213. "keyword",
  1214. // Gray conflicts with some method names, and has its own method defined.
  1215. "gray",
  1216. // Shouldn't really be in color-convert either...
  1217. "hex"
  1218. ];
  1219. var hashedModelKeys = {};
  1220. for (const model of Object.keys(color_convert_default)) {
  1221. hashedModelKeys[[...color_convert_default[model].labels].sort().join("")] = model;
  1222. }
  1223. var limiters = {};
  1224. function Color(object, model) {
  1225. if (!(this instanceof Color)) {
  1226. return new Color(object, model);
  1227. }
  1228. if (model && model in skippedModels) {
  1229. model = null;
  1230. }
  1231. if (model && !(model in color_convert_default)) {
  1232. throw new Error("Unknown model: " + model);
  1233. }
  1234. let i;
  1235. let channels;
  1236. if (object == null) {
  1237. this.model = "rgb";
  1238. this.color = [0, 0, 0];
  1239. this.valpha = 1;
  1240. } else if (object instanceof Color) {
  1241. this.model = object.model;
  1242. this.color = [...object.color];
  1243. this.valpha = object.valpha;
  1244. } else if (typeof object === "string") {
  1245. const result = color_string_default.get(object);
  1246. if (result === null) {
  1247. throw new Error("Unable to parse color from string: " + object);
  1248. }
  1249. this.model = result.model;
  1250. channels = color_convert_default[this.model].channels;
  1251. this.color = result.value.slice(0, channels);
  1252. this.valpha = typeof result.value[channels] === "number" ? result.value[channels] : 1;
  1253. } else if (object.length > 0) {
  1254. this.model = model || "rgb";
  1255. channels = color_convert_default[this.model].channels;
  1256. const newArray = Array.prototype.slice.call(object, 0, channels);
  1257. this.color = zeroArray(newArray, channels);
  1258. this.valpha = typeof object[channels] === "number" ? object[channels] : 1;
  1259. } else if (typeof object === "number") {
  1260. this.model = "rgb";
  1261. this.color = [
  1262. object >> 16 & 255,
  1263. object >> 8 & 255,
  1264. object & 255
  1265. ];
  1266. this.valpha = 1;
  1267. } else {
  1268. this.valpha = 1;
  1269. const keys = Object.keys(object);
  1270. if ("alpha" in object) {
  1271. keys.splice(keys.indexOf("alpha"), 1);
  1272. this.valpha = typeof object.alpha === "number" ? object.alpha : 0;
  1273. }
  1274. const hashedKeys = keys.sort().join("");
  1275. if (!(hashedKeys in hashedModelKeys)) {
  1276. throw new Error("Unable to parse color from object: " + JSON.stringify(object));
  1277. }
  1278. this.model = hashedModelKeys[hashedKeys];
  1279. const { labels } = color_convert_default[this.model];
  1280. const color = [];
  1281. for (i = 0; i < labels.length; i++) {
  1282. color.push(object[labels[i]]);
  1283. }
  1284. this.color = zeroArray(color);
  1285. }
  1286. if (limiters[this.model]) {
  1287. channels = color_convert_default[this.model].channels;
  1288. for (i = 0; i < channels; i++) {
  1289. const limit = limiters[this.model][i];
  1290. if (limit) {
  1291. this.color[i] = limit(this.color[i]);
  1292. }
  1293. }
  1294. }
  1295. this.valpha = Math.max(0, Math.min(1, this.valpha));
  1296. if (Object.freeze) {
  1297. Object.freeze(this);
  1298. }
  1299. }
  1300. Color.prototype = {
  1301. toString() {
  1302. return this.string();
  1303. },
  1304. toJSON() {
  1305. return this[this.model]();
  1306. },
  1307. string(places) {
  1308. let self = this.model in color_string_default.to ? this : this.rgb();
  1309. self = self.round(typeof places === "number" ? places : 1);
  1310. const arguments_ = self.valpha === 1 ? self.color : [...self.color, this.valpha];
  1311. return color_string_default.to[self.model](...arguments_);
  1312. },
  1313. percentString(places) {
  1314. const self = this.rgb().round(typeof places === "number" ? places : 1);
  1315. const arguments_ = self.valpha === 1 ? self.color : [...self.color, this.valpha];
  1316. return color_string_default.to.rgb.percent(...arguments_);
  1317. },
  1318. array() {
  1319. return this.valpha === 1 ? [...this.color] : [...this.color, this.valpha];
  1320. },
  1321. object() {
  1322. const result = {};
  1323. const { channels } = color_convert_default[this.model];
  1324. const { labels } = color_convert_default[this.model];
  1325. for (let i = 0; i < channels; i++) {
  1326. result[labels[i]] = this.color[i];
  1327. }
  1328. if (this.valpha !== 1) {
  1329. result.alpha = this.valpha;
  1330. }
  1331. return result;
  1332. },
  1333. unitArray() {
  1334. const rgb = this.rgb().color;
  1335. rgb[0] /= 255;
  1336. rgb[1] /= 255;
  1337. rgb[2] /= 255;
  1338. if (this.valpha !== 1) {
  1339. rgb.push(this.valpha);
  1340. }
  1341. return rgb;
  1342. },
  1343. unitObject() {
  1344. const rgb = this.rgb().object();
  1345. rgb.r /= 255;
  1346. rgb.g /= 255;
  1347. rgb.b /= 255;
  1348. if (this.valpha !== 1) {
  1349. rgb.alpha = this.valpha;
  1350. }
  1351. return rgb;
  1352. },
  1353. round(places) {
  1354. places = Math.max(places || 0, 0);
  1355. return new Color([...this.color.map(roundToPlace(places)), this.valpha], this.model);
  1356. },
  1357. alpha(value) {
  1358. if (value !== void 0) {
  1359. return new Color([...this.color, Math.max(0, Math.min(1, value))], this.model);
  1360. }
  1361. return this.valpha;
  1362. },
  1363. // Rgb
  1364. red: getset("rgb", 0, maxfn(255)),
  1365. green: getset("rgb", 1, maxfn(255)),
  1366. blue: getset("rgb", 2, maxfn(255)),
  1367. hue: getset(["hsl", "hsv", "hsl", "hwb", "hcg"], 0, (value) => (value % 360 + 360) % 360),
  1368. saturationl: getset("hsl", 1, maxfn(100)),
  1369. lightness: getset("hsl", 2, maxfn(100)),
  1370. saturationv: getset("hsv", 1, maxfn(100)),
  1371. value: getset("hsv", 2, maxfn(100)),
  1372. chroma: getset("hcg", 1, maxfn(100)),
  1373. gray: getset("hcg", 2, maxfn(100)),
  1374. white: getset("hwb", 1, maxfn(100)),
  1375. wblack: getset("hwb", 2, maxfn(100)),
  1376. cyan: getset("cmyk", 0, maxfn(100)),
  1377. magenta: getset("cmyk", 1, maxfn(100)),
  1378. yellow: getset("cmyk", 2, maxfn(100)),
  1379. black: getset("cmyk", 3, maxfn(100)),
  1380. x: getset("xyz", 0, maxfn(95.047)),
  1381. y: getset("xyz", 1, maxfn(100)),
  1382. z: getset("xyz", 2, maxfn(108.833)),
  1383. l: getset("lab", 0, maxfn(100)),
  1384. a: getset("lab", 1),
  1385. b: getset("lab", 2),
  1386. keyword(value) {
  1387. if (value !== void 0) {
  1388. return new Color(value);
  1389. }
  1390. return color_convert_default[this.model].keyword(this.color);
  1391. },
  1392. hex(value) {
  1393. if (value !== void 0) {
  1394. return new Color(value);
  1395. }
  1396. return color_string_default.to.hex(...this.rgb().round().color);
  1397. },
  1398. hexa(value) {
  1399. if (value !== void 0) {
  1400. return new Color(value);
  1401. }
  1402. const rgbArray = this.rgb().round().color;
  1403. let alphaHex = Math.round(this.valpha * 255).toString(16).toUpperCase();
  1404. if (alphaHex.length === 1) {
  1405. alphaHex = "0" + alphaHex;
  1406. }
  1407. return color_string_default.to.hex(...rgbArray) + alphaHex;
  1408. },
  1409. rgbNumber() {
  1410. const rgb = this.rgb().color;
  1411. return (rgb[0] & 255) << 16 | (rgb[1] & 255) << 8 | rgb[2] & 255;
  1412. },
  1413. luminosity() {
  1414. const rgb = this.rgb().color;
  1415. const lum = [];
  1416. for (const [i, element] of rgb.entries()) {
  1417. const chan = element / 255;
  1418. lum[i] = chan <= 0.04045 ? chan / 12.92 : ((chan + 0.055) / 1.055) ** 2.4;
  1419. }
  1420. return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
  1421. },
  1422. contrast(color2) {
  1423. const lum1 = this.luminosity();
  1424. const lum2 = color2.luminosity();
  1425. if (lum1 > lum2) {
  1426. return (lum1 + 0.05) / (lum2 + 0.05);
  1427. }
  1428. return (lum2 + 0.05) / (lum1 + 0.05);
  1429. },
  1430. level(color2) {
  1431. const contrastRatio = this.contrast(color2);
  1432. if (contrastRatio >= 7) {
  1433. return "AAA";
  1434. }
  1435. return contrastRatio >= 4.5 ? "AA" : "";
  1436. },
  1437. isDark() {
  1438. const rgb = this.rgb().color;
  1439. const yiq = (rgb[0] * 2126 + rgb[1] * 7152 + rgb[2] * 722) / 1e4;
  1440. return yiq < 128;
  1441. },
  1442. isLight() {
  1443. return !this.isDark();
  1444. },
  1445. negate() {
  1446. const rgb = this.rgb();
  1447. for (let i = 0; i < 3; i++) {
  1448. rgb.color[i] = 255 - rgb.color[i];
  1449. }
  1450. return rgb;
  1451. },
  1452. lighten(ratio) {
  1453. const hsl = this.hsl();
  1454. hsl.color[2] += hsl.color[2] * ratio;
  1455. return hsl;
  1456. },
  1457. darken(ratio) {
  1458. const hsl = this.hsl();
  1459. hsl.color[2] -= hsl.color[2] * ratio;
  1460. return hsl;
  1461. },
  1462. saturate(ratio) {
  1463. const hsl = this.hsl();
  1464. hsl.color[1] += hsl.color[1] * ratio;
  1465. return hsl;
  1466. },
  1467. desaturate(ratio) {
  1468. const hsl = this.hsl();
  1469. hsl.color[1] -= hsl.color[1] * ratio;
  1470. return hsl;
  1471. },
  1472. whiten(ratio) {
  1473. const hwb = this.hwb();
  1474. hwb.color[1] += hwb.color[1] * ratio;
  1475. return hwb;
  1476. },
  1477. blacken(ratio) {
  1478. const hwb = this.hwb();
  1479. hwb.color[2] += hwb.color[2] * ratio;
  1480. return hwb;
  1481. },
  1482. grayscale() {
  1483. const rgb = this.rgb().color;
  1484. const value = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
  1485. return Color.rgb(value, value, value);
  1486. },
  1487. fade(ratio) {
  1488. return this.alpha(this.valpha - this.valpha * ratio);
  1489. },
  1490. opaquer(ratio) {
  1491. return this.alpha(this.valpha + this.valpha * ratio);
  1492. },
  1493. rotate(degrees) {
  1494. const hsl = this.hsl();
  1495. let hue = hsl.color[0];
  1496. hue = (hue + degrees) % 360;
  1497. hue = hue < 0 ? 360 + hue : hue;
  1498. hsl.color[0] = hue;
  1499. return hsl;
  1500. },
  1501. mix(mixinColor, weight) {
  1502. if (!mixinColor || !mixinColor.rgb) {
  1503. throw new Error('Argument to "mix" was not a Color instance, but rather an instance of ' + typeof mixinColor);
  1504. }
  1505. const color1 = mixinColor.rgb();
  1506. const color2 = this.rgb();
  1507. const p = weight === void 0 ? 0.5 : weight;
  1508. const w = 2 * p - 1;
  1509. const a = color1.alpha() - color2.alpha();
  1510. const w1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2;
  1511. const w2 = 1 - w1;
  1512. return Color.rgb(
  1513. w1 * color1.red() + w2 * color2.red(),
  1514. w1 * color1.green() + w2 * color2.green(),
  1515. w1 * color1.blue() + w2 * color2.blue(),
  1516. color1.alpha() * p + color2.alpha() * (1 - p)
  1517. );
  1518. }
  1519. };
  1520. for (const model of Object.keys(color_convert_default)) {
  1521. if (skippedModels.includes(model)) {
  1522. continue;
  1523. }
  1524. const { channels } = color_convert_default[model];
  1525. Color.prototype[model] = function(...arguments_) {
  1526. if (this.model === model) {
  1527. return new Color(this);
  1528. }
  1529. if (arguments_.length > 0) {
  1530. return new Color(arguments_, model);
  1531. }
  1532. return new Color([...assertArray(color_convert_default[this.model][model].raw(this.color)), this.valpha], model);
  1533. };
  1534. Color[model] = function(...arguments_) {
  1535. let color = arguments_[0];
  1536. if (typeof color === "number") {
  1537. color = zeroArray(arguments_, channels);
  1538. }
  1539. return new Color(color, model);
  1540. };
  1541. }
  1542. function roundTo(number, places) {
  1543. return Number(number.toFixed(places));
  1544. }
  1545. function roundToPlace(places) {
  1546. return function(number) {
  1547. return roundTo(number, places);
  1548. };
  1549. }
  1550. function getset(model, channel, modifier) {
  1551. model = Array.isArray(model) ? model : [model];
  1552. for (const m of model) {
  1553. (limiters[m] ||= [])[channel] = modifier;
  1554. }
  1555. model = model[0];
  1556. return function(value) {
  1557. let result;
  1558. if (value !== void 0) {
  1559. if (modifier) {
  1560. value = modifier(value);
  1561. }
  1562. result = this[model]();
  1563. result.color[channel] = value;
  1564. return result;
  1565. }
  1566. result = this[model]().color[channel];
  1567. if (modifier) {
  1568. result = modifier(result);
  1569. }
  1570. return result;
  1571. };
  1572. }
  1573. function maxfn(max) {
  1574. return function(v) {
  1575. return Math.max(0, Math.min(max, v));
  1576. };
  1577. }
  1578. function assertArray(value) {
  1579. return Array.isArray(value) ? value : [value];
  1580. }
  1581. function zeroArray(array, length) {
  1582. for (let i = 0; i < length; i++) {
  1583. if (typeof array[i] !== "number") {
  1584. array[i] = 0;
  1585. }
  1586. }
  1587. return array;
  1588. }
  1589. var index_default = Color;