| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596 |
- var __defProp = Object.defineProperty;
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
- var __getOwnPropNames = Object.getOwnPropertyNames;
- var __hasOwnProp = Object.prototype.hasOwnProperty;
- var __export = (target, all) => {
- for (var name in all)
- __defProp(target, name, { get: all[name], enumerable: true });
- };
- var __copyProps = (to, from, except, desc) => {
- if (from && typeof from === "object" || typeof from === "function") {
- for (let key of __getOwnPropNames(from))
- if (!__hasOwnProp.call(to, key) && key !== except)
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
- }
- return to;
- };
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
- // node_modules/color/index.js
- var index_exports = {};
- __export(index_exports, {
- default: () => index_default
- });
- module.exports = __toCommonJS(index_exports);
- // node_modules/color-name/index.js
- var colors = {
- aliceblue: [240, 248, 255],
- antiquewhite: [250, 235, 215],
- aqua: [0, 255, 255],
- aquamarine: [127, 255, 212],
- azure: [240, 255, 255],
- beige: [245, 245, 220],
- bisque: [255, 228, 196],
- black: [0, 0, 0],
- blanchedalmond: [255, 235, 205],
- blue: [0, 0, 255],
- blueviolet: [138, 43, 226],
- brown: [165, 42, 42],
- burlywood: [222, 184, 135],
- cadetblue: [95, 158, 160],
- chartreuse: [127, 255, 0],
- chocolate: [210, 105, 30],
- coral: [255, 127, 80],
- cornflowerblue: [100, 149, 237],
- cornsilk: [255, 248, 220],
- crimson: [220, 20, 60],
- cyan: [0, 255, 255],
- darkblue: [0, 0, 139],
- darkcyan: [0, 139, 139],
- darkgoldenrod: [184, 134, 11],
- darkgray: [169, 169, 169],
- darkgreen: [0, 100, 0],
- darkgrey: [169, 169, 169],
- darkkhaki: [189, 183, 107],
- darkmagenta: [139, 0, 139],
- darkolivegreen: [85, 107, 47],
- darkorange: [255, 140, 0],
- darkorchid: [153, 50, 204],
- darkred: [139, 0, 0],
- darksalmon: [233, 150, 122],
- darkseagreen: [143, 188, 143],
- darkslateblue: [72, 61, 139],
- darkslategray: [47, 79, 79],
- darkslategrey: [47, 79, 79],
- darkturquoise: [0, 206, 209],
- darkviolet: [148, 0, 211],
- deeppink: [255, 20, 147],
- deepskyblue: [0, 191, 255],
- dimgray: [105, 105, 105],
- dimgrey: [105, 105, 105],
- dodgerblue: [30, 144, 255],
- firebrick: [178, 34, 34],
- floralwhite: [255, 250, 240],
- forestgreen: [34, 139, 34],
- fuchsia: [255, 0, 255],
- gainsboro: [220, 220, 220],
- ghostwhite: [248, 248, 255],
- gold: [255, 215, 0],
- goldenrod: [218, 165, 32],
- gray: [128, 128, 128],
- green: [0, 128, 0],
- greenyellow: [173, 255, 47],
- grey: [128, 128, 128],
- honeydew: [240, 255, 240],
- hotpink: [255, 105, 180],
- indianred: [205, 92, 92],
- indigo: [75, 0, 130],
- ivory: [255, 255, 240],
- khaki: [240, 230, 140],
- lavender: [230, 230, 250],
- lavenderblush: [255, 240, 245],
- lawngreen: [124, 252, 0],
- lemonchiffon: [255, 250, 205],
- lightblue: [173, 216, 230],
- lightcoral: [240, 128, 128],
- lightcyan: [224, 255, 255],
- lightgoldenrodyellow: [250, 250, 210],
- lightgray: [211, 211, 211],
- lightgreen: [144, 238, 144],
- lightgrey: [211, 211, 211],
- lightpink: [255, 182, 193],
- lightsalmon: [255, 160, 122],
- lightseagreen: [32, 178, 170],
- lightskyblue: [135, 206, 250],
- lightslategray: [119, 136, 153],
- lightslategrey: [119, 136, 153],
- lightsteelblue: [176, 196, 222],
- lightyellow: [255, 255, 224],
- lime: [0, 255, 0],
- limegreen: [50, 205, 50],
- linen: [250, 240, 230],
- magenta: [255, 0, 255],
- maroon: [128, 0, 0],
- mediumaquamarine: [102, 205, 170],
- mediumblue: [0, 0, 205],
- mediumorchid: [186, 85, 211],
- mediumpurple: [147, 112, 219],
- mediumseagreen: [60, 179, 113],
- mediumslateblue: [123, 104, 238],
- mediumspringgreen: [0, 250, 154],
- mediumturquoise: [72, 209, 204],
- mediumvioletred: [199, 21, 133],
- midnightblue: [25, 25, 112],
- mintcream: [245, 255, 250],
- mistyrose: [255, 228, 225],
- moccasin: [255, 228, 181],
- navajowhite: [255, 222, 173],
- navy: [0, 0, 128],
- oldlace: [253, 245, 230],
- olive: [128, 128, 0],
- olivedrab: [107, 142, 35],
- orange: [255, 165, 0],
- orangered: [255, 69, 0],
- orchid: [218, 112, 214],
- palegoldenrod: [238, 232, 170],
- palegreen: [152, 251, 152],
- paleturquoise: [175, 238, 238],
- palevioletred: [219, 112, 147],
- papayawhip: [255, 239, 213],
- peachpuff: [255, 218, 185],
- peru: [205, 133, 63],
- pink: [255, 192, 203],
- plum: [221, 160, 221],
- powderblue: [176, 224, 230],
- purple: [128, 0, 128],
- rebeccapurple: [102, 51, 153],
- red: [255, 0, 0],
- rosybrown: [188, 143, 143],
- royalblue: [65, 105, 225],
- saddlebrown: [139, 69, 19],
- salmon: [250, 128, 114],
- sandybrown: [244, 164, 96],
- seagreen: [46, 139, 87],
- seashell: [255, 245, 238],
- sienna: [160, 82, 45],
- silver: [192, 192, 192],
- skyblue: [135, 206, 235],
- slateblue: [106, 90, 205],
- slategray: [112, 128, 144],
- slategrey: [112, 128, 144],
- snow: [255, 250, 250],
- springgreen: [0, 255, 127],
- steelblue: [70, 130, 180],
- tan: [210, 180, 140],
- teal: [0, 128, 128],
- thistle: [216, 191, 216],
- tomato: [255, 99, 71],
- turquoise: [64, 224, 208],
- violet: [238, 130, 238],
- wheat: [245, 222, 179],
- white: [255, 255, 255],
- whitesmoke: [245, 245, 245],
- yellow: [255, 255, 0],
- yellowgreen: [154, 205, 50]
- };
- for (const key in colors) Object.freeze(colors[key]);
- var color_name_default = Object.freeze(colors);
- // node_modules/color-string/index.js
- var reverseNames = /* @__PURE__ */ Object.create(null);
- for (const name in color_name_default) {
- if (Object.hasOwn(color_name_default, name)) {
- reverseNames[color_name_default[name]] = name;
- }
- }
- var cs = {
- to: {},
- get: {}
- };
- cs.get = function(string) {
- const prefix = string.slice(0, 3).toLowerCase();
- let value;
- let model;
- switch (prefix) {
- case "hsl": {
- value = cs.get.hsl(string);
- model = "hsl";
- break;
- }
- case "hwb": {
- value = cs.get.hwb(string);
- model = "hwb";
- break;
- }
- default: {
- value = cs.get.rgb(string);
- model = "rgb";
- break;
- }
- }
- if (!value) {
- return null;
- }
- return { model, value };
- };
- cs.get.rgb = function(string) {
- if (!string) {
- return null;
- }
- const abbr = /^#([a-f\d]{3,4})$/i;
- const hex = /^#([a-f\d]{6})([a-f\d]{2})?$/i;
- 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;
- const per = /^rgba?\(\s*([+-]?[\d.]+)%\s*,?\s*([+-]?[\d.]+)%\s*,?\s*([+-]?[\d.]+)%\s*(?:[\s,|/]\s*([+-]?[\d.]+)(%?)\s*)?\)$/i;
- const keyword = /^(\w+)$/;
- let rgb = [0, 0, 0, 1];
- let match;
- let i;
- let hexAlpha;
- if (match = string.match(hex)) {
- hexAlpha = match[2];
- match = match[1];
- for (i = 0; i < 3; i++) {
- const i2 = i * 2;
- rgb[i] = Number.parseInt(match.slice(i2, i2 + 2), 16);
- }
- if (hexAlpha) {
- rgb[3] = Number.parseInt(hexAlpha, 16) / 255;
- }
- } else if (match = string.match(abbr)) {
- match = match[1];
- hexAlpha = match[3];
- for (i = 0; i < 3; i++) {
- rgb[i] = Number.parseInt(match[i] + match[i], 16);
- }
- if (hexAlpha) {
- rgb[3] = Number.parseInt(hexAlpha + hexAlpha, 16) / 255;
- }
- } else if (match = string.match(rgba)) {
- for (i = 0; i < 3; i++) {
- rgb[i] = Number.parseFloat(match[i + 1]);
- }
- if (match[4]) {
- rgb[3] = match[5] ? Number.parseFloat(match[4]) * 0.01 : Number.parseFloat(match[4]);
- }
- } else if (match = string.match(per)) {
- for (i = 0; i < 3; i++) {
- rgb[i] = Math.round(Number.parseFloat(match[i + 1]) * 2.55);
- }
- if (match[4]) {
- rgb[3] = match[5] ? Number.parseFloat(match[4]) * 0.01 : Number.parseFloat(match[4]);
- }
- } else if (match = string.toLowerCase().match(keyword)) {
- if (match[1] === "transparent") {
- return [0, 0, 0, 0];
- }
- if (!Object.hasOwn(color_name_default, match[1])) {
- return null;
- }
- rgb = color_name_default[match[1]].slice();
- rgb[3] = 1;
- return rgb;
- } else {
- return null;
- }
- for (i = 0; i < 3; i++) {
- rgb[i] = clamp(rgb[i], 0, 255);
- }
- rgb[3] = clamp(rgb[3], 0, 1);
- return rgb;
- };
- cs.get.hsl = function(string) {
- if (!string) {
- return null;
- }
- 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;
- const match = string.match(hsl);
- if (match) {
- const alpha = Number.parseFloat(match[4]);
- const h = (Number.parseFloat(match[1]) % 360 + 360) % 360;
- const s = clamp(Number.parseFloat(match[2]), 0, 100);
- const l = clamp(Number.parseFloat(match[3]), 0, 100);
- const a = clamp(Number.isNaN(alpha) ? 1 : alpha, 0, 1);
- return [h, s, l, a];
- }
- return null;
- };
- cs.get.hwb = function(string) {
- if (!string) {
- return null;
- }
- 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;
- const match = string.match(hwb);
- if (match) {
- const alpha = Number.parseFloat(match[4]);
- const h = (Number.parseFloat(match[1]) % 360 + 360) % 360;
- const w = clamp(Number.parseFloat(match[2]), 0, 100);
- const b = clamp(Number.parseFloat(match[3]), 0, 100);
- const a = clamp(Number.isNaN(alpha) ? 1 : alpha, 0, 1);
- return [h, w, b, a];
- }
- return null;
- };
- cs.to.hex = function(...rgba) {
- return "#" + hexDouble(rgba[0]) + hexDouble(rgba[1]) + hexDouble(rgba[2]) + (rgba[3] < 1 ? hexDouble(Math.round(rgba[3] * 255)) : "");
- };
- cs.to.rgb = function(...rgba) {
- 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] + ")";
- };
- cs.to.rgb.percent = function(...rgba) {
- const r = Math.round(rgba[0] / 255 * 100);
- const g = Math.round(rgba[1] / 255 * 100);
- const b = Math.round(rgba[2] / 255 * 100);
- return rgba.length < 4 || rgba[3] === 1 ? "rgb(" + r + "%, " + g + "%, " + b + "%)" : "rgba(" + r + "%, " + g + "%, " + b + "%, " + rgba[3] + ")";
- };
- cs.to.hsl = function(...hsla) {
- return hsla.length < 4 || hsla[3] === 1 ? "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)" : "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, " + hsla[3] + ")";
- };
- cs.to.hwb = function(...hwba) {
- let a = "";
- if (hwba.length >= 4 && hwba[3] !== 1) {
- a = ", " + hwba[3];
- }
- return "hwb(" + hwba[0] + ", " + hwba[1] + "%, " + hwba[2] + "%" + a + ")";
- };
- cs.to.keyword = function(...rgb) {
- return reverseNames[rgb.slice(0, 3)];
- };
- function clamp(number_, min, max) {
- return Math.min(Math.max(min, number_), max);
- }
- function hexDouble(number_) {
- const string_ = Math.round(number_).toString(16).toUpperCase();
- return string_.length < 2 ? "0" + string_ : string_;
- }
- var color_string_default = cs;
- // node_modules/color-convert/conversions.js
- var reverseKeywords = {};
- for (const key of Object.keys(color_name_default)) {
- reverseKeywords[color_name_default[key]] = key;
- }
- var convert = {
- rgb: { channels: 3, labels: "rgb" },
- hsl: { channels: 3, labels: "hsl" },
- hsv: { channels: 3, labels: "hsv" },
- hwb: { channels: 3, labels: "hwb" },
- cmyk: { channels: 4, labels: "cmyk" },
- xyz: { channels: 3, labels: "xyz" },
- lab: { channels: 3, labels: "lab" },
- oklab: { channels: 3, labels: ["okl", "oka", "okb"] },
- lch: { channels: 3, labels: "lch" },
- oklch: { channels: 3, labels: ["okl", "okc", "okh"] },
- hex: { channels: 1, labels: ["hex"] },
- keyword: { channels: 1, labels: ["keyword"] },
- ansi16: { channels: 1, labels: ["ansi16"] },
- ansi256: { channels: 1, labels: ["ansi256"] },
- hcg: { channels: 3, labels: ["h", "c", "g"] },
- apple: { channels: 3, labels: ["r16", "g16", "b16"] },
- gray: { channels: 1, labels: ["gray"] }
- };
- var conversions_default = convert;
- var LAB_FT = (6 / 29) ** 3;
- function srgbNonlinearTransform(c) {
- const cc = c > 31308e-7 ? 1.055 * c ** (1 / 2.4) - 0.055 : c * 12.92;
- return Math.min(Math.max(0, cc), 1);
- }
- function srgbNonlinearTransformInv(c) {
- return c > 0.04045 ? ((c + 0.055) / 1.055) ** 2.4 : c / 12.92;
- }
- for (const model of Object.keys(convert)) {
- if (!("channels" in convert[model])) {
- throw new Error("missing channels property: " + model);
- }
- if (!("labels" in convert[model])) {
- throw new Error("missing channel labels property: " + model);
- }
- if (convert[model].labels.length !== convert[model].channels) {
- throw new Error("channel and label counts mismatch: " + model);
- }
- const { channels, labels } = convert[model];
- delete convert[model].channels;
- delete convert[model].labels;
- Object.defineProperty(convert[model], "channels", { value: channels });
- Object.defineProperty(convert[model], "labels", { value: labels });
- }
- convert.rgb.hsl = function(rgb) {
- const r = rgb[0] / 255;
- const g = rgb[1] / 255;
- const b = rgb[2] / 255;
- const min = Math.min(r, g, b);
- const max = Math.max(r, g, b);
- const delta = max - min;
- let h;
- let s;
- switch (max) {
- case min: {
- h = 0;
- break;
- }
- case r: {
- h = (g - b) / delta;
- break;
- }
- case g: {
- h = 2 + (b - r) / delta;
- break;
- }
- case b: {
- h = 4 + (r - g) / delta;
- break;
- }
- }
- h = Math.min(h * 60, 360);
- if (h < 0) {
- h += 360;
- }
- const l = (min + max) / 2;
- if (max === min) {
- s = 0;
- } else if (l <= 0.5) {
- s = delta / (max + min);
- } else {
- s = delta / (2 - max - min);
- }
- return [h, s * 100, l * 100];
- };
- convert.rgb.hsv = function(rgb) {
- let rdif;
- let gdif;
- let bdif;
- let h;
- let s;
- const r = rgb[0] / 255;
- const g = rgb[1] / 255;
- const b = rgb[2] / 255;
- const v = Math.max(r, g, b);
- const diff = v - Math.min(r, g, b);
- const diffc = function(c) {
- return (v - c) / 6 / diff + 1 / 2;
- };
- if (diff === 0) {
- h = 0;
- s = 0;
- } else {
- s = diff / v;
- rdif = diffc(r);
- gdif = diffc(g);
- bdif = diffc(b);
- switch (v) {
- case r: {
- h = bdif - gdif;
- break;
- }
- case g: {
- h = 1 / 3 + rdif - bdif;
- break;
- }
- case b: {
- h = 2 / 3 + gdif - rdif;
- break;
- }
- }
- if (h < 0) {
- h += 1;
- } else if (h > 1) {
- h -= 1;
- }
- }
- return [
- h * 360,
- s * 100,
- v * 100
- ];
- };
- convert.rgb.hwb = function(rgb) {
- const r = rgb[0];
- const g = rgb[1];
- let b = rgb[2];
- const h = convert.rgb.hsl(rgb)[0];
- const w = 1 / 255 * Math.min(r, Math.min(g, b));
- b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
- return [h, w * 100, b * 100];
- };
- convert.rgb.oklab = function(rgb) {
- const r = srgbNonlinearTransformInv(rgb[0] / 255);
- const g = srgbNonlinearTransformInv(rgb[1] / 255);
- const b = srgbNonlinearTransformInv(rgb[2] / 255);
- const lp = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
- const mp = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
- const sp = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
- const l = 0.2104542553 * lp + 0.793617785 * mp - 0.0040720468 * sp;
- const aa = 1.9779984951 * lp - 2.428592205 * mp + 0.4505937099 * sp;
- const bb = 0.0259040371 * lp + 0.7827717662 * mp - 0.808675766 * sp;
- return [l * 100, aa * 100, bb * 100];
- };
- convert.rgb.cmyk = function(rgb) {
- const r = rgb[0] / 255;
- const g = rgb[1] / 255;
- const b = rgb[2] / 255;
- const k = Math.min(1 - r, 1 - g, 1 - b);
- const c = (1 - r - k) / (1 - k) || 0;
- const m = (1 - g - k) / (1 - k) || 0;
- const y = (1 - b - k) / (1 - k) || 0;
- return [c * 100, m * 100, y * 100, k * 100];
- };
- function comparativeDistance(x, y) {
- return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
- }
- convert.rgb.keyword = function(rgb) {
- const reversed = reverseKeywords[rgb];
- if (reversed) {
- return reversed;
- }
- let currentClosestDistance = Number.POSITIVE_INFINITY;
- let currentClosestKeyword;
- for (const keyword of Object.keys(color_name_default)) {
- const value = color_name_default[keyword];
- const distance = comparativeDistance(rgb, value);
- if (distance < currentClosestDistance) {
- currentClosestDistance = distance;
- currentClosestKeyword = keyword;
- }
- }
- return currentClosestKeyword;
- };
- convert.keyword.rgb = function(keyword) {
- return [...color_name_default[keyword]];
- };
- convert.rgb.xyz = function(rgb) {
- const r = srgbNonlinearTransformInv(rgb[0] / 255);
- const g = srgbNonlinearTransformInv(rgb[1] / 255);
- const b = srgbNonlinearTransformInv(rgb[2] / 255);
- const x = r * 0.4124564 + g * 0.3575761 + b * 0.1804375;
- const y = r * 0.2126729 + g * 0.7151522 + b * 0.072175;
- const z = r * 0.0193339 + g * 0.119192 + b * 0.9503041;
- return [x * 100, y * 100, z * 100];
- };
- convert.rgb.lab = function(rgb) {
- const xyz = convert.rgb.xyz(rgb);
- let x = xyz[0];
- let y = xyz[1];
- let z = xyz[2];
- x /= 95.047;
- y /= 100;
- z /= 108.883;
- x = x > LAB_FT ? x ** (1 / 3) : 7.787 * x + 16 / 116;
- y = y > LAB_FT ? y ** (1 / 3) : 7.787 * y + 16 / 116;
- z = z > LAB_FT ? z ** (1 / 3) : 7.787 * z + 16 / 116;
- const l = 116 * y - 16;
- const a = 500 * (x - y);
- const b = 200 * (y - z);
- return [l, a, b];
- };
- convert.hsl.rgb = function(hsl) {
- const h = hsl[0] / 360;
- const s = hsl[1] / 100;
- const l = hsl[2] / 100;
- let t3;
- let value;
- if (s === 0) {
- value = l * 255;
- return [value, value, value];
- }
- const t2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
- const t1 = 2 * l - t2;
- const rgb = [0, 0, 0];
- for (let i = 0; i < 3; i++) {
- t3 = h + 1 / 3 * -(i - 1);
- if (t3 < 0) {
- t3++;
- }
- if (t3 > 1) {
- t3--;
- }
- if (6 * t3 < 1) {
- value = t1 + (t2 - t1) * 6 * t3;
- } else if (2 * t3 < 1) {
- value = t2;
- } else if (3 * t3 < 2) {
- value = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
- } else {
- value = t1;
- }
- rgb[i] = value * 255;
- }
- return rgb;
- };
- convert.hsl.hsv = function(hsl) {
- const h = hsl[0];
- let s = hsl[1] / 100;
- let l = hsl[2] / 100;
- let smin = s;
- const lmin = Math.max(l, 0.01);
- l *= 2;
- s *= l <= 1 ? l : 2 - l;
- smin *= lmin <= 1 ? lmin : 2 - lmin;
- const v = (l + s) / 2;
- const sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
- return [h, sv * 100, v * 100];
- };
- convert.hsv.rgb = function(hsv) {
- const h = hsv[0] / 60;
- const s = hsv[1] / 100;
- let v = hsv[2] / 100;
- const hi = Math.floor(h) % 6;
- const f = h - Math.floor(h);
- const p = 255 * v * (1 - s);
- const q = 255 * v * (1 - s * f);
- const t = 255 * v * (1 - s * (1 - f));
- v *= 255;
- switch (hi) {
- case 0: {
- return [v, t, p];
- }
- case 1: {
- return [q, v, p];
- }
- case 2: {
- return [p, v, t];
- }
- case 3: {
- return [p, q, v];
- }
- case 4: {
- return [t, p, v];
- }
- case 5: {
- return [v, p, q];
- }
- }
- };
- convert.hsv.hsl = function(hsv) {
- const h = hsv[0];
- const s = hsv[1] / 100;
- const v = hsv[2] / 100;
- const vmin = Math.max(v, 0.01);
- let sl;
- let l;
- l = (2 - s) * v;
- const lmin = (2 - s) * vmin;
- sl = s * vmin;
- sl /= lmin <= 1 ? lmin : 2 - lmin;
- sl = sl || 0;
- l /= 2;
- return [h, sl * 100, l * 100];
- };
- convert.hwb.rgb = function(hwb) {
- const h = hwb[0] / 360;
- let wh = hwb[1] / 100;
- let bl = hwb[2] / 100;
- const ratio = wh + bl;
- let f;
- if (ratio > 1) {
- wh /= ratio;
- bl /= ratio;
- }
- const i = Math.floor(6 * h);
- const v = 1 - bl;
- f = 6 * h - i;
- if ((i & 1) !== 0) {
- f = 1 - f;
- }
- const n = wh + f * (v - wh);
- let r;
- let g;
- let b;
- switch (i) {
- default:
- case 6:
- case 0: {
- r = v;
- g = n;
- b = wh;
- break;
- }
- case 1: {
- r = n;
- g = v;
- b = wh;
- break;
- }
- case 2: {
- r = wh;
- g = v;
- b = n;
- break;
- }
- case 3: {
- r = wh;
- g = n;
- b = v;
- break;
- }
- case 4: {
- r = n;
- g = wh;
- b = v;
- break;
- }
- case 5: {
- r = v;
- g = wh;
- b = n;
- break;
- }
- }
- return [r * 255, g * 255, b * 255];
- };
- convert.cmyk.rgb = function(cmyk) {
- const c = cmyk[0] / 100;
- const m = cmyk[1] / 100;
- const y = cmyk[2] / 100;
- const k = cmyk[3] / 100;
- const r = 1 - Math.min(1, c * (1 - k) + k);
- const g = 1 - Math.min(1, m * (1 - k) + k);
- const b = 1 - Math.min(1, y * (1 - k) + k);
- return [r * 255, g * 255, b * 255];
- };
- convert.xyz.rgb = function(xyz) {
- const x = xyz[0] / 100;
- const y = xyz[1] / 100;
- const z = xyz[2] / 100;
- let r;
- let g;
- let b;
- r = x * 3.2404542 + y * -1.5371385 + z * -0.4985314;
- g = x * -0.969266 + y * 1.8760108 + z * 0.041556;
- b = x * 0.0556434 + y * -0.2040259 + z * 1.0572252;
- r = srgbNonlinearTransform(r);
- g = srgbNonlinearTransform(g);
- b = srgbNonlinearTransform(b);
- return [r * 255, g * 255, b * 255];
- };
- convert.xyz.lab = function(xyz) {
- let x = xyz[0];
- let y = xyz[1];
- let z = xyz[2];
- x /= 95.047;
- y /= 100;
- z /= 108.883;
- x = x > LAB_FT ? x ** (1 / 3) : 7.787 * x + 16 / 116;
- y = y > LAB_FT ? y ** (1 / 3) : 7.787 * y + 16 / 116;
- z = z > LAB_FT ? z ** (1 / 3) : 7.787 * z + 16 / 116;
- const l = 116 * y - 16;
- const a = 500 * (x - y);
- const b = 200 * (y - z);
- return [l, a, b];
- };
- convert.xyz.oklab = function(xyz) {
- const x = xyz[0] / 100;
- const y = xyz[1] / 100;
- const z = xyz[2] / 100;
- const lp = Math.cbrt(0.8189330101 * x + 0.3618667424 * y - 0.1288597137 * z);
- const mp = Math.cbrt(0.0329845436 * x + 0.9293118715 * y + 0.0361456387 * z);
- const sp = Math.cbrt(0.0482003018 * x + 0.2643662691 * y + 0.633851707 * z);
- const l = 0.2104542553 * lp + 0.793617785 * mp - 0.0040720468 * sp;
- const a = 1.9779984951 * lp - 2.428592205 * mp + 0.4505937099 * sp;
- const b = 0.0259040371 * lp + 0.7827717662 * mp - 0.808675766 * sp;
- return [l * 100, a * 100, b * 100];
- };
- convert.oklab.oklch = function(oklab) {
- return convert.lab.lch(oklab);
- };
- convert.oklab.xyz = function(oklab) {
- const ll = oklab[0] / 100;
- const a = oklab[1] / 100;
- const b = oklab[2] / 100;
- const l = (0.999999998 * ll + 0.396337792 * a + 0.215803758 * b) ** 3;
- const m = (1.000000008 * ll - 0.105561342 * a - 0.063854175 * b) ** 3;
- const s = (1.000000055 * ll - 0.089484182 * a - 1.291485538 * b) ** 3;
- const x = 1.227013851 * l - 0.55779998 * m + 0.281256149 * s;
- const y = -0.040580178 * l + 1.11225687 * m - 0.071676679 * s;
- const z = -0.076381285 * l - 0.421481978 * m + 1.58616322 * s;
- return [x * 100, y * 100, z * 100];
- };
- convert.oklab.rgb = function(oklab) {
- const ll = oklab[0] / 100;
- const aa = oklab[1] / 100;
- const bb = oklab[2] / 100;
- const l = (ll + 0.3963377774 * aa + 0.2158037573 * bb) ** 3;
- const m = (ll - 0.1055613458 * aa - 0.0638541728 * bb) ** 3;
- const s = (ll - 0.0894841775 * aa - 1.291485548 * bb) ** 3;
- const r = srgbNonlinearTransform(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s);
- const g = srgbNonlinearTransform(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s);
- const b = srgbNonlinearTransform(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s);
- return [r * 255, g * 255, b * 255];
- };
- convert.oklch.oklab = function(oklch) {
- return convert.lch.lab(oklch);
- };
- convert.lab.xyz = function(lab) {
- const l = lab[0];
- const a = lab[1];
- const b = lab[2];
- let x;
- let y;
- let z;
- y = (l + 16) / 116;
- x = a / 500 + y;
- z = y - b / 200;
- const y2 = y ** 3;
- const x2 = x ** 3;
- const z2 = z ** 3;
- y = y2 > LAB_FT ? y2 : (y - 16 / 116) / 7.787;
- x = x2 > LAB_FT ? x2 : (x - 16 / 116) / 7.787;
- z = z2 > LAB_FT ? z2 : (z - 16 / 116) / 7.787;
- x *= 95.047;
- y *= 100;
- z *= 108.883;
- return [x, y, z];
- };
- convert.lab.lch = function(lab) {
- const l = lab[0];
- const a = lab[1];
- const b = lab[2];
- let h;
- const hr = Math.atan2(b, a);
- h = hr * 360 / 2 / Math.PI;
- if (h < 0) {
- h += 360;
- }
- const c = Math.sqrt(a * a + b * b);
- return [l, c, h];
- };
- convert.lch.lab = function(lch) {
- const l = lch[0];
- const c = lch[1];
- const h = lch[2];
- const hr = h / 360 * 2 * Math.PI;
- const a = c * Math.cos(hr);
- const b = c * Math.sin(hr);
- return [l, a, b];
- };
- convert.rgb.ansi16 = function(args, saturation = null) {
- const [r, g, b] = args;
- let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation;
- value = Math.round(value / 50);
- if (value === 0) {
- return 30;
- }
- let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
- if (value === 2) {
- ansi += 60;
- }
- return ansi;
- };
- convert.hsv.ansi16 = function(args) {
- return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
- };
- convert.rgb.ansi256 = function(args) {
- const r = args[0];
- const g = args[1];
- const b = args[2];
- if (r >> 4 === g >> 4 && g >> 4 === b >> 4) {
- if (r < 8) {
- return 16;
- }
- if (r > 248) {
- return 231;
- }
- return Math.round((r - 8) / 247 * 24) + 232;
- }
- const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
- return ansi;
- };
- convert.ansi16.rgb = function(args) {
- args = args[0];
- let color = args % 10;
- if (color === 0 || color === 7) {
- if (args > 50) {
- color += 3.5;
- }
- color = color / 10.5 * 255;
- return [color, color, color];
- }
- const mult = (Math.trunc(args > 50) + 1) * 0.5;
- const r = (color & 1) * mult * 255;
- const g = (color >> 1 & 1) * mult * 255;
- const b = (color >> 2 & 1) * mult * 255;
- return [r, g, b];
- };
- convert.ansi256.rgb = function(args) {
- args = args[0];
- if (args >= 232) {
- const c = (args - 232) * 10 + 8;
- return [c, c, c];
- }
- args -= 16;
- let rem;
- const r = Math.floor(args / 36) / 5 * 255;
- const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
- const b = rem % 6 / 5 * 255;
- return [r, g, b];
- };
- convert.rgb.hex = function(args) {
- const integer = ((Math.round(args[0]) & 255) << 16) + ((Math.round(args[1]) & 255) << 8) + (Math.round(args[2]) & 255);
- const string = integer.toString(16).toUpperCase();
- return "000000".slice(string.length) + string;
- };
- convert.hex.rgb = function(args) {
- const match = args.toString(16).match(/[a-f\d]{6}|[a-f\d]{3}/i);
- if (!match) {
- return [0, 0, 0];
- }
- let colorString = match[0];
- if (match[0].length === 3) {
- colorString = [...colorString].map((char) => char + char).join("");
- }
- const integer = Number.parseInt(colorString, 16);
- const r = integer >> 16 & 255;
- const g = integer >> 8 & 255;
- const b = integer & 255;
- return [r, g, b];
- };
- convert.rgb.hcg = function(rgb) {
- const r = rgb[0] / 255;
- const g = rgb[1] / 255;
- const b = rgb[2] / 255;
- const max = Math.max(Math.max(r, g), b);
- const min = Math.min(Math.min(r, g), b);
- const chroma = max - min;
- let hue;
- const grayscale = chroma < 1 ? min / (1 - chroma) : 0;
- if (chroma <= 0) {
- hue = 0;
- } else if (max === r) {
- hue = (g - b) / chroma % 6;
- } else if (max === g) {
- hue = 2 + (b - r) / chroma;
- } else {
- hue = 4 + (r - g) / chroma;
- }
- hue /= 6;
- hue %= 1;
- return [hue * 360, chroma * 100, grayscale * 100];
- };
- convert.hsl.hcg = function(hsl) {
- const s = hsl[1] / 100;
- const l = hsl[2] / 100;
- const c = l < 0.5 ? 2 * s * l : 2 * s * (1 - l);
- let f = 0;
- if (c < 1) {
- f = (l - 0.5 * c) / (1 - c);
- }
- return [hsl[0], c * 100, f * 100];
- };
- convert.hsv.hcg = function(hsv) {
- const s = hsv[1] / 100;
- const v = hsv[2] / 100;
- const c = s * v;
- let f = 0;
- if (c < 1) {
- f = (v - c) / (1 - c);
- }
- return [hsv[0], c * 100, f * 100];
- };
- convert.hcg.rgb = function(hcg) {
- const h = hcg[0] / 360;
- const c = hcg[1] / 100;
- const g = hcg[2] / 100;
- if (c === 0) {
- return [g * 255, g * 255, g * 255];
- }
- const pure = [0, 0, 0];
- const hi = h % 1 * 6;
- const v = hi % 1;
- const w = 1 - v;
- let mg = 0;
- switch (Math.floor(hi)) {
- case 0: {
- pure[0] = 1;
- pure[1] = v;
- pure[2] = 0;
- break;
- }
- case 1: {
- pure[0] = w;
- pure[1] = 1;
- pure[2] = 0;
- break;
- }
- case 2: {
- pure[0] = 0;
- pure[1] = 1;
- pure[2] = v;
- break;
- }
- case 3: {
- pure[0] = 0;
- pure[1] = w;
- pure[2] = 1;
- break;
- }
- case 4: {
- pure[0] = v;
- pure[1] = 0;
- pure[2] = 1;
- break;
- }
- default: {
- pure[0] = 1;
- pure[1] = 0;
- pure[2] = w;
- }
- }
- mg = (1 - c) * g;
- return [
- (c * pure[0] + mg) * 255,
- (c * pure[1] + mg) * 255,
- (c * pure[2] + mg) * 255
- ];
- };
- convert.hcg.hsv = function(hcg) {
- const c = hcg[1] / 100;
- const g = hcg[2] / 100;
- const v = c + g * (1 - c);
- let f = 0;
- if (v > 0) {
- f = c / v;
- }
- return [hcg[0], f * 100, v * 100];
- };
- convert.hcg.hsl = function(hcg) {
- const c = hcg[1] / 100;
- const g = hcg[2] / 100;
- const l = g * (1 - c) + 0.5 * c;
- let s = 0;
- if (l > 0 && l < 0.5) {
- s = c / (2 * l);
- } else if (l >= 0.5 && l < 1) {
- s = c / (2 * (1 - l));
- }
- return [hcg[0], s * 100, l * 100];
- };
- convert.hcg.hwb = function(hcg) {
- const c = hcg[1] / 100;
- const g = hcg[2] / 100;
- const v = c + g * (1 - c);
- return [hcg[0], (v - c) * 100, (1 - v) * 100];
- };
- convert.hwb.hcg = function(hwb) {
- const w = hwb[1] / 100;
- const b = hwb[2] / 100;
- const v = 1 - b;
- const c = v - w;
- let g = 0;
- if (c < 1) {
- g = (v - c) / (1 - c);
- }
- return [hwb[0], c * 100, g * 100];
- };
- convert.apple.rgb = function(apple) {
- return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
- };
- convert.rgb.apple = function(rgb) {
- return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
- };
- convert.gray.rgb = function(args) {
- return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
- };
- convert.gray.hsl = function(args) {
- return [0, 0, args[0]];
- };
- convert.gray.hsv = convert.gray.hsl;
- convert.gray.hwb = function(gray) {
- return [0, 100, gray[0]];
- };
- convert.gray.cmyk = function(gray) {
- return [0, 0, 0, gray[0]];
- };
- convert.gray.lab = function(gray) {
- return [gray[0], 0, 0];
- };
- convert.gray.hex = function(gray) {
- const value = Math.round(gray[0] / 100 * 255) & 255;
- const integer = (value << 16) + (value << 8) + value;
- const string = integer.toString(16).toUpperCase();
- return "000000".slice(string.length) + string;
- };
- convert.rgb.gray = function(rgb) {
- const value = (rgb[0] + rgb[1] + rgb[2]) / 3;
- return [value / 255 * 100];
- };
- // node_modules/color-convert/route.js
- function buildGraph() {
- const graph = {};
- const models2 = Object.keys(conversions_default);
- for (let { length } = models2, i = 0; i < length; i++) {
- graph[models2[i]] = {
- // http://jsperf.com/1-vs-infinity
- // micro-opt, but this is simple.
- distance: -1,
- parent: null
- };
- }
- return graph;
- }
- function deriveBFS(fromModel) {
- const graph = buildGraph();
- const queue = [fromModel];
- graph[fromModel].distance = 0;
- while (queue.length > 0) {
- const current = queue.pop();
- const adjacents = Object.keys(conversions_default[current]);
- for (let { length } = adjacents, i = 0; i < length; i++) {
- const adjacent = adjacents[i];
- const node = graph[adjacent];
- if (node.distance === -1) {
- node.distance = graph[current].distance + 1;
- node.parent = current;
- queue.unshift(adjacent);
- }
- }
- }
- return graph;
- }
- function link(from, to) {
- return function(args) {
- return to(from(args));
- };
- }
- function wrapConversion(toModel, graph) {
- const path = [graph[toModel].parent, toModel];
- let fn = conversions_default[graph[toModel].parent][toModel];
- let cur = graph[toModel].parent;
- while (graph[cur].parent) {
- path.unshift(graph[cur].parent);
- fn = link(conversions_default[graph[cur].parent][cur], fn);
- cur = graph[cur].parent;
- }
- fn.conversion = path;
- return fn;
- }
- function route(fromModel) {
- const graph = deriveBFS(fromModel);
- const conversion = {};
- const models2 = Object.keys(graph);
- for (let { length } = models2, i = 0; i < length; i++) {
- const toModel = models2[i];
- const node = graph[toModel];
- if (node.parent === null) {
- continue;
- }
- conversion[toModel] = wrapConversion(toModel, graph);
- }
- return conversion;
- }
- var route_default = route;
- // node_modules/color-convert/index.js
- var convert2 = {};
- var models = Object.keys(conversions_default);
- function wrapRaw(fn) {
- const wrappedFn = function(...args) {
- const arg0 = args[0];
- if (arg0 === void 0 || arg0 === null) {
- return arg0;
- }
- if (arg0.length > 1) {
- args = arg0;
- }
- return fn(args);
- };
- if ("conversion" in fn) {
- wrappedFn.conversion = fn.conversion;
- }
- return wrappedFn;
- }
- function wrapRounded(fn) {
- const wrappedFn = function(...args) {
- const arg0 = args[0];
- if (arg0 === void 0 || arg0 === null) {
- return arg0;
- }
- if (arg0.length > 1) {
- args = arg0;
- }
- const result = fn(args);
- if (typeof result === "object") {
- for (let { length } = result, i = 0; i < length; i++) {
- result[i] = Math.round(result[i]);
- }
- }
- return result;
- };
- if ("conversion" in fn) {
- wrappedFn.conversion = fn.conversion;
- }
- return wrappedFn;
- }
- for (const fromModel of models) {
- convert2[fromModel] = {};
- Object.defineProperty(convert2[fromModel], "channels", { value: conversions_default[fromModel].channels });
- Object.defineProperty(convert2[fromModel], "labels", { value: conversions_default[fromModel].labels });
- const routes = route_default(fromModel);
- const routeModels = Object.keys(routes);
- for (const toModel of routeModels) {
- const fn = routes[toModel];
- convert2[fromModel][toModel] = wrapRounded(fn);
- convert2[fromModel][toModel].raw = wrapRaw(fn);
- }
- }
- var color_convert_default = convert2;
- // node_modules/color/index.js
- var skippedModels = [
- // To be honest, I don't really feel like keyword belongs in color convert, but eh.
- "keyword",
- // Gray conflicts with some method names, and has its own method defined.
- "gray",
- // Shouldn't really be in color-convert either...
- "hex"
- ];
- var hashedModelKeys = {};
- for (const model of Object.keys(color_convert_default)) {
- hashedModelKeys[[...color_convert_default[model].labels].sort().join("")] = model;
- }
- var limiters = {};
- function Color(object, model) {
- if (!(this instanceof Color)) {
- return new Color(object, model);
- }
- if (model && model in skippedModels) {
- model = null;
- }
- if (model && !(model in color_convert_default)) {
- throw new Error("Unknown model: " + model);
- }
- let i;
- let channels;
- if (object == null) {
- this.model = "rgb";
- this.color = [0, 0, 0];
- this.valpha = 1;
- } else if (object instanceof Color) {
- this.model = object.model;
- this.color = [...object.color];
- this.valpha = object.valpha;
- } else if (typeof object === "string") {
- const result = color_string_default.get(object);
- if (result === null) {
- throw new Error("Unable to parse color from string: " + object);
- }
- this.model = result.model;
- channels = color_convert_default[this.model].channels;
- this.color = result.value.slice(0, channels);
- this.valpha = typeof result.value[channels] === "number" ? result.value[channels] : 1;
- } else if (object.length > 0) {
- this.model = model || "rgb";
- channels = color_convert_default[this.model].channels;
- const newArray = Array.prototype.slice.call(object, 0, channels);
- this.color = zeroArray(newArray, channels);
- this.valpha = typeof object[channels] === "number" ? object[channels] : 1;
- } else if (typeof object === "number") {
- this.model = "rgb";
- this.color = [
- object >> 16 & 255,
- object >> 8 & 255,
- object & 255
- ];
- this.valpha = 1;
- } else {
- this.valpha = 1;
- const keys = Object.keys(object);
- if ("alpha" in object) {
- keys.splice(keys.indexOf("alpha"), 1);
- this.valpha = typeof object.alpha === "number" ? object.alpha : 0;
- }
- const hashedKeys = keys.sort().join("");
- if (!(hashedKeys in hashedModelKeys)) {
- throw new Error("Unable to parse color from object: " + JSON.stringify(object));
- }
- this.model = hashedModelKeys[hashedKeys];
- const { labels } = color_convert_default[this.model];
- const color = [];
- for (i = 0; i < labels.length; i++) {
- color.push(object[labels[i]]);
- }
- this.color = zeroArray(color);
- }
- if (limiters[this.model]) {
- channels = color_convert_default[this.model].channels;
- for (i = 0; i < channels; i++) {
- const limit = limiters[this.model][i];
- if (limit) {
- this.color[i] = limit(this.color[i]);
- }
- }
- }
- this.valpha = Math.max(0, Math.min(1, this.valpha));
- if (Object.freeze) {
- Object.freeze(this);
- }
- }
- Color.prototype = {
- toString() {
- return this.string();
- },
- toJSON() {
- return this[this.model]();
- },
- string(places) {
- let self = this.model in color_string_default.to ? this : this.rgb();
- self = self.round(typeof places === "number" ? places : 1);
- const arguments_ = self.valpha === 1 ? self.color : [...self.color, this.valpha];
- return color_string_default.to[self.model](...arguments_);
- },
- percentString(places) {
- const self = this.rgb().round(typeof places === "number" ? places : 1);
- const arguments_ = self.valpha === 1 ? self.color : [...self.color, this.valpha];
- return color_string_default.to.rgb.percent(...arguments_);
- },
- array() {
- return this.valpha === 1 ? [...this.color] : [...this.color, this.valpha];
- },
- object() {
- const result = {};
- const { channels } = color_convert_default[this.model];
- const { labels } = color_convert_default[this.model];
- for (let i = 0; i < channels; i++) {
- result[labels[i]] = this.color[i];
- }
- if (this.valpha !== 1) {
- result.alpha = this.valpha;
- }
- return result;
- },
- unitArray() {
- const rgb = this.rgb().color;
- rgb[0] /= 255;
- rgb[1] /= 255;
- rgb[2] /= 255;
- if (this.valpha !== 1) {
- rgb.push(this.valpha);
- }
- return rgb;
- },
- unitObject() {
- const rgb = this.rgb().object();
- rgb.r /= 255;
- rgb.g /= 255;
- rgb.b /= 255;
- if (this.valpha !== 1) {
- rgb.alpha = this.valpha;
- }
- return rgb;
- },
- round(places) {
- places = Math.max(places || 0, 0);
- return new Color([...this.color.map(roundToPlace(places)), this.valpha], this.model);
- },
- alpha(value) {
- if (value !== void 0) {
- return new Color([...this.color, Math.max(0, Math.min(1, value))], this.model);
- }
- return this.valpha;
- },
- // Rgb
- red: getset("rgb", 0, maxfn(255)),
- green: getset("rgb", 1, maxfn(255)),
- blue: getset("rgb", 2, maxfn(255)),
- hue: getset(["hsl", "hsv", "hsl", "hwb", "hcg"], 0, (value) => (value % 360 + 360) % 360),
- saturationl: getset("hsl", 1, maxfn(100)),
- lightness: getset("hsl", 2, maxfn(100)),
- saturationv: getset("hsv", 1, maxfn(100)),
- value: getset("hsv", 2, maxfn(100)),
- chroma: getset("hcg", 1, maxfn(100)),
- gray: getset("hcg", 2, maxfn(100)),
- white: getset("hwb", 1, maxfn(100)),
- wblack: getset("hwb", 2, maxfn(100)),
- cyan: getset("cmyk", 0, maxfn(100)),
- magenta: getset("cmyk", 1, maxfn(100)),
- yellow: getset("cmyk", 2, maxfn(100)),
- black: getset("cmyk", 3, maxfn(100)),
- x: getset("xyz", 0, maxfn(95.047)),
- y: getset("xyz", 1, maxfn(100)),
- z: getset("xyz", 2, maxfn(108.833)),
- l: getset("lab", 0, maxfn(100)),
- a: getset("lab", 1),
- b: getset("lab", 2),
- keyword(value) {
- if (value !== void 0) {
- return new Color(value);
- }
- return color_convert_default[this.model].keyword(this.color);
- },
- hex(value) {
- if (value !== void 0) {
- return new Color(value);
- }
- return color_string_default.to.hex(...this.rgb().round().color);
- },
- hexa(value) {
- if (value !== void 0) {
- return new Color(value);
- }
- const rgbArray = this.rgb().round().color;
- let alphaHex = Math.round(this.valpha * 255).toString(16).toUpperCase();
- if (alphaHex.length === 1) {
- alphaHex = "0" + alphaHex;
- }
- return color_string_default.to.hex(...rgbArray) + alphaHex;
- },
- rgbNumber() {
- const rgb = this.rgb().color;
- return (rgb[0] & 255) << 16 | (rgb[1] & 255) << 8 | rgb[2] & 255;
- },
- luminosity() {
- const rgb = this.rgb().color;
- const lum = [];
- for (const [i, element] of rgb.entries()) {
- const chan = element / 255;
- lum[i] = chan <= 0.04045 ? chan / 12.92 : ((chan + 0.055) / 1.055) ** 2.4;
- }
- return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
- },
- contrast(color2) {
- const lum1 = this.luminosity();
- const lum2 = color2.luminosity();
- if (lum1 > lum2) {
- return (lum1 + 0.05) / (lum2 + 0.05);
- }
- return (lum2 + 0.05) / (lum1 + 0.05);
- },
- level(color2) {
- const contrastRatio = this.contrast(color2);
- if (contrastRatio >= 7) {
- return "AAA";
- }
- return contrastRatio >= 4.5 ? "AA" : "";
- },
- isDark() {
- const rgb = this.rgb().color;
- const yiq = (rgb[0] * 2126 + rgb[1] * 7152 + rgb[2] * 722) / 1e4;
- return yiq < 128;
- },
- isLight() {
- return !this.isDark();
- },
- negate() {
- const rgb = this.rgb();
- for (let i = 0; i < 3; i++) {
- rgb.color[i] = 255 - rgb.color[i];
- }
- return rgb;
- },
- lighten(ratio) {
- const hsl = this.hsl();
- hsl.color[2] += hsl.color[2] * ratio;
- return hsl;
- },
- darken(ratio) {
- const hsl = this.hsl();
- hsl.color[2] -= hsl.color[2] * ratio;
- return hsl;
- },
- saturate(ratio) {
- const hsl = this.hsl();
- hsl.color[1] += hsl.color[1] * ratio;
- return hsl;
- },
- desaturate(ratio) {
- const hsl = this.hsl();
- hsl.color[1] -= hsl.color[1] * ratio;
- return hsl;
- },
- whiten(ratio) {
- const hwb = this.hwb();
- hwb.color[1] += hwb.color[1] * ratio;
- return hwb;
- },
- blacken(ratio) {
- const hwb = this.hwb();
- hwb.color[2] += hwb.color[2] * ratio;
- return hwb;
- },
- grayscale() {
- const rgb = this.rgb().color;
- const value = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
- return Color.rgb(value, value, value);
- },
- fade(ratio) {
- return this.alpha(this.valpha - this.valpha * ratio);
- },
- opaquer(ratio) {
- return this.alpha(this.valpha + this.valpha * ratio);
- },
- rotate(degrees) {
- const hsl = this.hsl();
- let hue = hsl.color[0];
- hue = (hue + degrees) % 360;
- hue = hue < 0 ? 360 + hue : hue;
- hsl.color[0] = hue;
- return hsl;
- },
- mix(mixinColor, weight) {
- if (!mixinColor || !mixinColor.rgb) {
- throw new Error('Argument to "mix" was not a Color instance, but rather an instance of ' + typeof mixinColor);
- }
- const color1 = mixinColor.rgb();
- const color2 = this.rgb();
- const p = weight === void 0 ? 0.5 : weight;
- const w = 2 * p - 1;
- const a = color1.alpha() - color2.alpha();
- const w1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2;
- const w2 = 1 - w1;
- return Color.rgb(
- w1 * color1.red() + w2 * color2.red(),
- w1 * color1.green() + w2 * color2.green(),
- w1 * color1.blue() + w2 * color2.blue(),
- color1.alpha() * p + color2.alpha() * (1 - p)
- );
- }
- };
- for (const model of Object.keys(color_convert_default)) {
- if (skippedModels.includes(model)) {
- continue;
- }
- const { channels } = color_convert_default[model];
- Color.prototype[model] = function(...arguments_) {
- if (this.model === model) {
- return new Color(this);
- }
- if (arguments_.length > 0) {
- return new Color(arguments_, model);
- }
- return new Color([...assertArray(color_convert_default[this.model][model].raw(this.color)), this.valpha], model);
- };
- Color[model] = function(...arguments_) {
- let color = arguments_[0];
- if (typeof color === "number") {
- color = zeroArray(arguments_, channels);
- }
- return new Color(color, model);
- };
- }
- function roundTo(number, places) {
- return Number(number.toFixed(places));
- }
- function roundToPlace(places) {
- return function(number) {
- return roundTo(number, places);
- };
- }
- function getset(model, channel, modifier) {
- model = Array.isArray(model) ? model : [model];
- for (const m of model) {
- (limiters[m] ||= [])[channel] = modifier;
- }
- model = model[0];
- return function(value) {
- let result;
- if (value !== void 0) {
- if (modifier) {
- value = modifier(value);
- }
- result = this[model]();
- result.color[channel] = value;
- return result;
- }
- result = this[model]().color[channel];
- if (modifier) {
- result = modifier(result);
- }
- return result;
- };
- }
- function maxfn(max) {
- return function(v) {
- return Math.max(0, Math.min(max, v));
- };
- }
- function assertArray(value) {
- return Array.isArray(value) ? value : [value];
- }
- function zeroArray(array, length) {
- for (let i = 0; i < length; i++) {
- if (typeof array[i] !== "number") {
- array[i] = 0;
- }
- }
- return array;
- }
- var index_default = Color;
|