UNPKG

@a_ng_d/utils-ui-color-palette

Version:

Core utilities library for UI Color Palette - a color management plugin for design tools. This library provides the foundational color manipulation, contrast calculation, and palette generation features used in the plugin.

549 lines (548 loc) 23.2 kB
var A = Object.defineProperty; var R = (b, t, h) => t in b ? A(b, t, { enumerable: !0, configurable: !0, writable: !0, value: h }) : b[t] = h; var a = (b, t, h) => R(b, typeof t != "symbol" ? t + "" : t, h); import { c as n } from "./index-Beb8qoyd.js"; class s { constructor() { this.hex = "#000000", this.rgb_r = 0, this.rgb_g = 0, this.rgb_b = 0, this.xyz_x = 0, this.xyz_y = 0, this.xyz_z = 0, this.luv_l = 0, this.luv_u = 0, this.luv_v = 0, this.lch_l = 0, this.lch_c = 0, this.lch_h = 0, this.hsluv_h = 0, this.hsluv_s = 0, this.hsluv_l = 0, this.hpluv_h = 0, this.hpluv_p = 0, this.hpluv_l = 0, this.r0s = 0, this.r0i = 0, this.r1s = 0, this.r1i = 0, this.g0s = 0, this.g0i = 0, this.g1s = 0, this.g1i = 0, this.b0s = 0, this.b0i = 0, this.b1s = 0, this.b1i = 0; } static fromLinear(t) { return t <= 31308e-7 ? 12.92 * t : 1.055 * Math.pow(t, 1 / 2.4) - 0.055; } static toLinear(t) { return t > 0.04045 ? Math.pow((t + 0.055) / 1.055, 2.4) : t / 12.92; } static yToL(t) { return t <= s.epsilon ? t / s.refY * s.kappa : 116 * Math.pow(t / s.refY, 1 / 3) - 16; } static lToY(t) { return t <= 8 ? s.refY * t / s.kappa : s.refY * Math.pow((t + 16) / 116, 3); } static rgbChannelToHex(t) { const h = Math.round(t * 255), i = h % 16, e = (h - i) / 16 | 0; return s.hexChars.charAt(e) + s.hexChars.charAt(i); } static hexToRgbChannel(t, h) { const i = s.hexChars.indexOf(t.charAt(h)), e = s.hexChars.indexOf(t.charAt(h + 1)); return (i * 16 + e) / 255; } static distanceFromOriginAngle(t, h, i) { const e = h / (Math.sin(i) - t * Math.cos(i)); return e < 0 ? 1 / 0 : e; } static distanceFromOrigin(t, h) { return Math.abs(h) / Math.sqrt(Math.pow(t, 2) + 1); } static min6(t, h, i, e, r, o) { return Math.min(t, Math.min(h, Math.min(i, Math.min(e, Math.min(r, o))))); } rgbToHex() { this.hex = "#", this.hex += s.rgbChannelToHex(this.rgb_r), this.hex += s.rgbChannelToHex(this.rgb_g), this.hex += s.rgbChannelToHex(this.rgb_b); } hexToRgb() { this.hex = this.hex.toLowerCase(), this.rgb_r = s.hexToRgbChannel(this.hex, 1), this.rgb_g = s.hexToRgbChannel(this.hex, 3), this.rgb_b = s.hexToRgbChannel(this.hex, 5); } xyzToRgb() { this.rgb_r = s.fromLinear(s.m_r0 * this.xyz_x + s.m_r1 * this.xyz_y + s.m_r2 * this.xyz_z), this.rgb_g = s.fromLinear(s.m_g0 * this.xyz_x + s.m_g1 * this.xyz_y + s.m_g2 * this.xyz_z), this.rgb_b = s.fromLinear(s.m_b0 * this.xyz_x + s.m_b1 * this.xyz_y + s.m_b2 * this.xyz_z); } rgbToXyz() { const t = s.toLinear(this.rgb_r), h = s.toLinear(this.rgb_g), i = s.toLinear(this.rgb_b); this.xyz_x = 0.41239079926595 * t + 0.35758433938387 * h + 0.18048078840183 * i, this.xyz_y = 0.21263900587151 * t + 0.71516867876775 * h + 0.072192315360733 * i, this.xyz_z = 0.019330818715591 * t + 0.11919477979462 * h + 0.95053215224966 * i; } xyzToLuv() { const t = this.xyz_x + 15 * this.xyz_y + 3 * this.xyz_z; let h = 4 * this.xyz_x, i = 9 * this.xyz_y; t !== 0 ? (h /= t, i /= t) : (h = NaN, i = NaN), this.luv_l = s.yToL(this.xyz_y), this.luv_l === 0 ? (this.luv_u = 0, this.luv_v = 0) : (this.luv_u = 13 * this.luv_l * (h - s.refU), this.luv_v = 13 * this.luv_l * (i - s.refV)); } luvToXyz() { if (this.luv_l === 0) { this.xyz_x = 0, this.xyz_y = 0, this.xyz_z = 0; return; } const t = this.luv_u / (13 * this.luv_l) + s.refU, h = this.luv_v / (13 * this.luv_l) + s.refV; this.xyz_y = s.lToY(this.luv_l), this.xyz_x = 0 - 9 * this.xyz_y * t / ((t - 4) * h - t * h), this.xyz_z = (9 * this.xyz_y - 15 * h * this.xyz_y - h * this.xyz_x) / (3 * h); } luvToLch() { if (this.lch_l = this.luv_l, this.lch_c = Math.sqrt(this.luv_u * this.luv_u + this.luv_v * this.luv_v), this.lch_c < 1e-8) this.lch_h = 0; else { const t = Math.atan2(this.luv_v, this.luv_u); this.lch_h = t * 180 / Math.PI, this.lch_h < 0 && (this.lch_h = 360 + this.lch_h); } } lchToLuv() { const t = this.lch_h / 180 * Math.PI; this.luv_l = this.lch_l, this.luv_u = Math.cos(t) * this.lch_c, this.luv_v = Math.sin(t) * this.lch_c; } calculateBoundingLines(t) { const h = Math.pow(t + 16, 3) / 1560896, i = h > s.epsilon ? h : t / s.kappa, e = i * (284517 * s.m_r0 - 94839 * s.m_r2), r = i * (838422 * s.m_r2 + 769860 * s.m_r1 + 731718 * s.m_r0), o = i * (632260 * s.m_r2 - 126452 * s.m_r1), l = i * (284517 * s.m_g0 - 94839 * s.m_g2), u = i * (838422 * s.m_g2 + 769860 * s.m_g1 + 731718 * s.m_g0), d = i * (632260 * s.m_g2 - 126452 * s.m_g1), C = i * (284517 * s.m_b0 - 94839 * s.m_b2), M = i * (838422 * s.m_b2 + 769860 * s.m_b1 + 731718 * s.m_b0), m = i * (632260 * s.m_b2 - 126452 * s.m_b1); this.r0s = e / o, this.r0i = r * t / o, this.r1s = e / (o + 126452), this.r1i = (r - 769860) * t / (o + 126452), this.g0s = l / d, this.g0i = u * t / d, this.g1s = l / (d + 126452), this.g1i = (u - 769860) * t / (d + 126452), this.b0s = C / m, this.b0i = M * t / m, this.b1s = C / (m + 126452), this.b1i = (M - 769860) * t / (m + 126452); } calcMaxChromaHpluv() { const t = s.distanceFromOrigin(this.r0s, this.r0i), h = s.distanceFromOrigin(this.r1s, this.r1i), i = s.distanceFromOrigin(this.g0s, this.g0i), e = s.distanceFromOrigin(this.g1s, this.g1i), r = s.distanceFromOrigin(this.b0s, this.b0i), o = s.distanceFromOrigin(this.b1s, this.b1i); return s.min6(t, h, i, e, r, o); } calcMaxChromaHsluv(t) { const h = t / 360 * Math.PI * 2, i = s.distanceFromOriginAngle(this.r0s, this.r0i, h), e = s.distanceFromOriginAngle(this.r1s, this.r1i, h), r = s.distanceFromOriginAngle(this.g0s, this.g0i, h), o = s.distanceFromOriginAngle(this.g1s, this.g1i, h), l = s.distanceFromOriginAngle(this.b0s, this.b0i, h), u = s.distanceFromOriginAngle(this.b1s, this.b1i, h); return s.min6(i, e, r, o, l, u); } hsluvToLch() { if (this.hsluv_l > 99.9999999) this.lch_l = 100, this.lch_c = 0; else if (this.hsluv_l < 1e-8) this.lch_l = 0, this.lch_c = 0; else { this.lch_l = this.hsluv_l, this.calculateBoundingLines(this.hsluv_l); const t = this.calcMaxChromaHsluv(this.hsluv_h); this.lch_c = t / 100 * this.hsluv_s; } this.lch_h = this.hsluv_h; } lchToHsluv() { if (this.lch_l > 99.9999999) this.hsluv_s = 0, this.hsluv_l = 100; else if (this.lch_l < 1e-8) this.hsluv_s = 0, this.hsluv_l = 0; else { this.calculateBoundingLines(this.lch_l); const t = this.calcMaxChromaHsluv(this.lch_h); this.hsluv_s = this.lch_c / t * 100, this.hsluv_l = this.lch_l; } this.hsluv_h = this.lch_h; } hpluvToLch() { if (this.hpluv_l > 99.9999999) this.lch_l = 100, this.lch_c = 0; else if (this.hpluv_l < 1e-8) this.lch_l = 0, this.lch_c = 0; else { this.lch_l = this.hpluv_l, this.calculateBoundingLines(this.hpluv_l); const t = this.calcMaxChromaHpluv(); this.lch_c = t / 100 * this.hpluv_p; } this.lch_h = this.hpluv_h; } lchToHpluv() { if (this.lch_l > 99.9999999) this.hpluv_p = 0, this.hpluv_l = 100; else if (this.lch_l < 1e-8) this.hpluv_p = 0, this.hpluv_l = 0; else { this.calculateBoundingLines(this.lch_l); const t = this.calcMaxChromaHpluv(); this.hpluv_p = this.lch_c / t * 100, this.hpluv_l = this.lch_l; } this.hpluv_h = this.lch_h; } hsluvToRgb() { this.hsluvToLch(), this.lchToLuv(), this.luvToXyz(), this.xyzToRgb(); } hpluvToRgb() { this.hpluvToLch(), this.lchToLuv(), this.luvToXyz(), this.xyzToRgb(); } hsluvToHex() { this.hsluvToRgb(), this.rgbToHex(); } hpluvToHex() { this.hpluvToRgb(), this.rgbToHex(); } rgbToHsluv() { this.rgbToXyz(), this.xyzToLuv(), this.luvToLch(), this.lchToHpluv(), this.lchToHsluv(); } rgbToHpluv() { this.rgbToXyz(), this.xyzToLuv(), this.luvToLch(), this.lchToHpluv(), this.lchToHpluv(); } hexToHsluv() { this.hexToRgb(), this.rgbToHsluv(); } hexToHpluv() { this.hexToRgb(), this.rgbToHpluv(); } } s.hexChars = "0123456789abcdef"; s.refY = 1; s.refU = 0.19783000664283; s.refV = 0.46831999493879; s.kappa = 903.2962962; s.epsilon = 0.0088564516; s.m_r0 = 3.240969941904521; s.m_r1 = -1.537383177570093; s.m_r2 = -0.498610760293; s.m_g0 = -0.96924363628087; s.m_g1 = 1.87596750150772; s.m_g2 = 0.041555057407175; s.m_b0 = 0.055630079696993; s.m_b1 = -0.20397695888897; s.m_b2 = 1.056971514242878; const c = { PROTANOPIA: [ [0.567, 0.433, 0], [0.558, 0.442, 0], [0, 0.242, 0.758] ], PROTANOMALY: [ [0.817, 0.183, 0], [0.333, 0.667, 0], [0, 0.125, 0.875] ], DEUTERANOPIA: [ [0.625, 0.375, 0], [0.7, 0.3, 0], [0, 0.3, 0.7] ], DEUTERANOMALY: [ [0.8, 0.2, 0], [0.258, 0.742, 0], [0, 0.142, 0.858] ], TRITANOPIA: [ [0.95, 0.05, 0], [0, 0.433, 0.567], [0, 0.475, 0.525] ], TRITANOMALY: [ [0.967, 0.033, 0], [0, 0.733, 0.267], [0, 0.183, 0.817] ], ACHROMATOPSIA: [ [0.299, 0.587, 0.114], [0.299, 0.587, 0.114], [0.299, 0.587, 0.114] ], ACHROMATOMALY: [ [0.618, 0.32, 0.062], [0.163, 0.775, 0.062], [0.163, 0.32, 0.516] ] }, g = (b, t) => { const [h, i, e] = b, [r, o, l] = t; return [ Math.round(h * r[0] + i * r[1] + e * r[2]), Math.round(h * o[0] + i * o[1] + e * o[2]), Math.round(h * l[0] + i * l[1] + e * l[2]) ]; }, _ = (b, t, h) => { const i = b / 255, e = t / 255, r = h / 255, o = 1 - Math.max(i, e, r); return o === 1 ? [0, 0, 0, 1] : [ (1 - i - o) / (1 - o), (1 - e - o) / (1 - o), (1 - r - o) / (1 - o), o ]; }, x = (b, t, h, i) => [ Math.round(255 * (1 - b) * (1 - i)), Math.round(255 * (1 - t) * (1 - i)), Math.round(255 * (1 - h) * (1 - i)) ]; class O { constructor({ render: t = "HEX", sourceColor: h = [0, 0, 0], lightness: i = parseFloat((n(h).luminance() * 100).toFixed(1)), alpha: e = 1, hueShifting: r = 0, chromaShifting: o = 100, algorithmVersion: l = "v3", visionSimulationMode: u = "NONE" }) { a(this, "render"); a(this, "sourceColor"); a(this, "lightness"); a(this, "alpha"); a(this, "hueShifting"); a(this, "chromaShifting"); a(this, "algorithmVersion"); a(this, "visionSimulationMode"); a(this, "adjustHue", (t) => t + this.hueShifting < 0 ? t + this.hueShifting + 360 : t + this.hueShifting > 360 ? t + this.hueShifting - 360 : t + this.hueShifting); a(this, "adjustChroma", (t) => { if (this.algorithmVersion === "v1") return t; if (this.algorithmVersion === "v2") return Math.sin(this.lightness / 100 * Math.PI) * t; if (this.algorithmVersion === "v3") { const h = this.lightness / 100, i = Math.sin(h * Math.PI), e = Math.tanh(h * Math.PI), r = i * 0.5 + e * 0.5; return Math.pow(r, 0.5) * t; } return t; }); a(this, "setColor", () => this.render === "HEX" ? this.simulateColorBlindHex(this.sourceColor) : this.simulateColorBlindRgb(this.sourceColor)); a(this, "setColorWithAlpha", () => this.render === "HEX" ? n.rgb(...this.simulateColorBlindRgb(this.sourceColor), this.alpha).hex() : [...this.simulateColorBlindRgb(this.sourceColor), this.alpha]); a(this, "lch", () => { const t = n(this.sourceColor).lch(), h = n.lch( this.lightness, this.adjustChroma(t[1] * (this.chromaShifting / 100)), this.adjustHue(t[2]) ).rgb(); return this.render === "HEX" ? this.simulateColorBlindHex(h) : this.simulateColorBlindRgb(h); }); a(this, "lcha", () => { const t = n(this.sourceColor).lch(), h = n.lch( t[0], this.adjustChroma(t[1] * (this.chromaShifting / 100)), this.adjustHue(t[2]) ).rgb(); return this.render === "HEX" ? n.rgb(...this.simulateColorBlindRgb(h), this.alpha).hex() : [...this.simulateColorBlindRgb(h), this.alpha]; }); a(this, "oklch", () => { const t = n(this.sourceColor).oklch(), h = n.oklch( this.lightness / 100, this.adjustChroma(t[1] * (this.chromaShifting / 100)), this.adjustHue(t[2]) ).rgb(); return this.render === "HEX" ? this.simulateColorBlindHex(h) : this.simulateColorBlindRgb(h); }); a(this, "oklcha", () => { const t = n(this.sourceColor).oklch(), h = n.oklch( t[0], this.adjustChroma(t[1] * (this.chromaShifting / 100)), this.adjustHue(t[2]) ).rgb(); return this.render === "HEX" ? n.rgb(...this.simulateColorBlindRgb(h), this.alpha).hex() : [...this.simulateColorBlindRgb(h), this.alpha]; }); a(this, "lab", () => { const t = n(this.sourceColor).get("lab.a"), h = n(this.sourceColor).get("lab.b"), i = Math.sqrt(t ** 2 + h ** 2) * (this.chromaShifting / 100); let e = Math.atan(h / t) + this.hueShifting * (Math.PI / 180); (e > Math.PI || e < -Math.PI) && (e = Math.PI); let r = i * Math.cos(e), o = i * Math.sin(e); Math.sign(t) === -1 && Math.sign(h) === 1 && (r *= -1, o *= -1), Math.sign(t) === -1 && Math.sign(h) === -1 && (r *= -1, o *= -1); const l = n.lab( this.lightness, this.adjustChroma(r), this.adjustChroma(o) ).rgb(); return this.render === "HEX" ? this.simulateColorBlindHex(l) : this.simulateColorBlindRgb(l); }); a(this, "laba", () => { const t = n(this.sourceColor).get("lab.a"), h = n(this.sourceColor).get("lab.b"), i = n(this.sourceColor).get("lab.l"), e = Math.sqrt(t ** 2 + h ** 2) * (this.chromaShifting / 100); let r = Math.atan(h / t) + this.hueShifting * (Math.PI / 180); (r > Math.PI || r < -Math.PI) && (r = Math.PI); let o = e * Math.cos(r), l = e * Math.sin(r); Math.sign(t) === -1 && Math.sign(h) === 1 && (o *= -1, l *= -1), Math.sign(t) === -1 && Math.sign(h) === -1 && (o *= -1, l *= -1); const u = n.lab(i, this.adjustChroma(o), this.adjustChroma(l)).rgb(); return this.render === "HEX" ? n.rgb(...this.simulateColorBlindRgb(u), this.alpha).hex() : [...this.simulateColorBlindRgb(u), this.alpha]; }); a(this, "oklab", () => { const t = n(this.sourceColor).get("oklab.a"), h = n(this.sourceColor).get("oklab.b"), i = Math.sqrt(t ** 2 + h ** 2) * (this.chromaShifting / 100); let e = Math.atan(h / t) + this.hueShifting * (Math.PI / 180); (e > Math.PI || e < -Math.PI) && (e = Math.PI); let r = i * Math.cos(e), o = i * Math.sin(e); Math.sign(t) === -1 && Math.sign(h) === 1 && (r *= -1, o *= -1), Math.sign(t) === -1 && Math.sign(h) === -1 && (r *= -1, o *= -1), Number.isNaN(r) && (r = 0), Number.isNaN(o) && (o = 0); const l = n.oklab( this.lightness / 100, this.adjustChroma(r), this.adjustChroma(o) ).rgb(); return this.render === "HEX" ? this.simulateColorBlindHex(l) : this.simulateColorBlindRgb(l); }); a(this, "oklaba", () => { const t = n(this.sourceColor).get("oklab.a"), h = n(this.sourceColor).get("oklab.b"), i = n(this.sourceColor).get("oklab.l"), e = Math.sqrt(t ** 2 + h ** 2) * (this.chromaShifting / 100); let r = Math.atan(h / t) + this.hueShifting * (Math.PI / 180); (r > Math.PI || r < -Math.PI) && (r = Math.PI); let o = e * Math.cos(r), l = e * Math.sin(r); Math.sign(t) === -1 && Math.sign(h) === 1 && (o *= -1, l *= -1), Math.sign(t) === -1 && Math.sign(h) === -1 && (o *= -1, l *= -1), Number.isNaN(o) && (o = 0), Number.isNaN(l) && (l = 0); const u = n.oklab(i, this.adjustChroma(o), this.adjustChroma(l)).rgb(); return this.render === "HEX" ? n.rgb(...this.simulateColorBlindRgb(u), this.alpha).hex() : [...this.simulateColorBlindRgb(u), this.alpha]; }); a(this, "hsl", () => { const t = n(this.sourceColor).hsl(), h = n.hsl( this.adjustHue(t[0]), this.adjustChroma(t[1] * (this.chromaShifting / 100)), this.lightness / 100 ).rgb(); return this.render === "HEX" ? this.simulateColorBlindHex(h) : this.simulateColorBlindRgb(h); }); a(this, "hsla", () => { const t = n(this.sourceColor).hsl(), h = n.hsl( this.adjustHue(t[0]), this.adjustChroma(t[1] * (this.chromaShifting / 100)), t[2] ).rgb(); return this.render === "HEX" ? n.rgb(...this.simulateColorBlindRgb(h), this.alpha).hex() : [...this.simulateColorBlindRgb(h), this.alpha]; }); a(this, "hsluv", () => { const t = new s(); t.rgb_r = this.sourceColor[0] / 255, t.rgb_g = this.sourceColor[1] / 255, t.rgb_b = this.sourceColor[2] / 255, t.rgbToHsluv(), t.hsluv_l = this.lightness, t.hsluv_s = this.adjustChroma( t.hsluv_s * (this.chromaShifting / 100) ), t.hsluv_h = this.adjustHue(t.hsluv_h), Number.isNaN(t.hsluv_s) && (t.hsluv_s = 0), Number.isNaN(t.hsluv_h) && (t.hsluv_h = 0), t.hsluvToRgb(); const h = [ t.rgb_r * 255, t.rgb_g * 255, t.rgb_b * 255 ]; return this.render === "HEX" ? this.simulateColorBlindHex(h) : this.simulateColorBlindRgb(h); }); a(this, "hsluva", () => { const t = new s(); t.rgb_r = this.sourceColor[0] / 255, t.rgb_g = this.sourceColor[1] / 255, t.rgb_b = this.sourceColor[2] / 255, t.rgbToHsluv(), t.hsluv_s = this.adjustChroma( t.hsluv_s * (this.chromaShifting / 100) ), t.hsluv_h = this.adjustHue(t.hsluv_h), Number.isNaN(t.hsluv_s) && (t.hsluv_s = 0), Number.isNaN(t.hsluv_h) && (t.hsluv_h = 0), t.hsluvToRgb(); const h = [ t.rgb_r * 255, t.rgb_g * 255, t.rgb_b * 255 ]; return this.render === "HEX" ? n.rgb(...this.simulateColorBlindRgb(h), this.alpha).hex() : [...this.simulateColorBlindRgb(h), this.alpha]; }); a(this, "hsv", () => { const t = n(this.sourceColor).hsv(), h = n.hsv( this.adjustHue(Number.isNaN(t[0]) ? 0 : t[0]), this.adjustChroma(t[1] * (this.chromaShifting / 100)), this.lightness / 100 ).rgb(); return this.render === "HEX" ? this.simulateColorBlindHex(h) : this.simulateColorBlindRgb(h); }); a(this, "hsva", () => { const t = n(this.sourceColor).hsv(), h = n.hsv( this.adjustHue(Number.isNaN(t[0]) ? 0 : t[0]), this.adjustChroma(t[1] * (this.chromaShifting / 100)), t[2] ).rgb(); return this.render === "HEX" ? n.rgb(...this.simulateColorBlindRgb(h), this.alpha).hex() : [...this.simulateColorBlindRgb(h), this.alpha]; }); a(this, "cmyk", () => { const t = n(this.sourceColor).hsl(), [h, i, e] = n.hsl( this.adjustHue(Number.isNaN(t[0]) ? 0 : t[0]), t[1], t[2] ).rgb(), [r, o, l] = _(h, i, e), u = Math.min( 1, Math.max(0, this.adjustChroma(r * (this.chromaShifting / 100))) ), d = Math.min( 1, Math.max(0, this.adjustChroma(o * (this.chromaShifting / 100))) ), C = Math.min( 1, Math.max(0, this.adjustChroma(l * (this.chromaShifting / 100))) ), M = Math.min(1, Math.max(0, 1 - this.lightness / 100)), m = x(u, d, C, M); return this.render === "HEX" ? this.simulateColorBlindHex(m) : this.simulateColorBlindRgb(m); }); a(this, "cmyka", () => { const t = n(this.sourceColor).hsl(), [h, i, e] = n.hsl( this.adjustHue(Number.isNaN(t[0]) ? 0 : t[0]), t[1], t[2] ).rgb(), [r, o, l, u] = _(h, i, e), d = Math.min( 1, Math.max(0, this.adjustChroma(r * (this.chromaShifting / 100))) ), C = Math.min( 1, Math.max(0, this.adjustChroma(o * (this.chromaShifting / 100))) ), M = Math.min( 1, Math.max(0, this.adjustChroma(l * (this.chromaShifting / 100))) ), m = x(d, C, M, u); return this.render === "HEX" ? n.rgb(...this.simulateColorBlindRgb(m), this.alpha).hex() : [...this.simulateColorBlindRgb(m), this.alpha]; }); a(this, "getHsluv", () => { const t = new s(); return t.rgb_r = this.sourceColor[0] / 255, t.rgb_g = this.sourceColor[1] / 255, t.rgb_b = this.sourceColor[2] / 255, t.rgbToHsluv(), [t.hsluv_h, t.hsluv_s, t.hsluv_l]; }); a(this, "simulateColorBlindHex", (t) => { var e; const h = { NONE: () => n(t).hex(), PROTANOMALY: () => { const r = g( t, c.PROTANOMALY ); return n(r).hex(); }, PROTANOPIA: () => { const r = g( t, c.PROTANOPIA ); return n(r).hex(); }, DEUTERANOMALY: () => { const r = g( t, c.DEUTERANOMALY ); return n(r).hex(); }, DEUTERANOPIA: () => { const r = g( t, c.DEUTERANOPIA ); return n(r).hex(); }, TRITANOMALY: () => { const r = g( t, c.TRITANOMALY ); return n(r).hex(); }, TRITANOPIA: () => { const r = g( t, c.TRITANOPIA ); return n(r).hex(); }, ACHROMATOMALY: () => { const r = g( t, c.ACHROMATOMALY ); return n(r).hex(); }, ACHROMATOPSIA: () => { const r = g( t, c.ACHROMATOPSIA ); return n(r).hex(); } }, i = (e = h[this.visionSimulationMode]) == null ? void 0 : e.call(h); return i !== void 0 ? i : "#000000"; }); a(this, "simulateColorBlindRgb", (t) => { var e; const h = { NONE: () => n(t).rgb(), PROTANOMALY: () => g(t, c.PROTANOMALY), PROTANOPIA: () => g(t, c.PROTANOPIA), DEUTERANOMALY: () => g(t, c.DEUTERANOMALY), DEUTERANOPIA: () => g(t, c.DEUTERANOPIA), TRITANOMALY: () => g(t, c.TRITANOMALY), TRITANOPIA: () => g(t, c.TRITANOPIA), ACHROMATOMALY: () => g(t, c.ACHROMATOMALY), ACHROMATOPSIA: () => g(t, c.ACHROMATOPSIA) }, i = (e = h[this.visionSimulationMode]) == null ? void 0 : e.call(h); return i !== void 0 ? i : [0, 0, 0]; }); a(this, "mixColorsRgb", (t, h) => { const [i, e, r, o] = t, [l, u, d, C] = h; if (o === 1) return [i, e, r]; if (o === 0) return [l, u, d]; const M = o + C * (1 - o), m = Math.min( 255, Math.max(0, Math.round((i * o + l * C * (1 - o)) / M)) ), f = Math.min( 255, Math.max(0, Math.round((e * o + u * C * (1 - o)) / M)) ), T = Math.min( 255, Math.max(0, Math.round((r * o + d * C * (1 - o)) / M)) ); return this.simulateColorBlindRgb([m, f, T]); }); a(this, "mixColorsHex", (t, h) => { const i = /^#([0-9A-Fa-f]{3}){1,2}([0-9A-Fa-f]{2})?$/; if (!i.test(t)) return t; if (!i.test(h)) return h; const e = n(t).rgba(), r = n(h).rgba(), o = this.mixColorsRgb(e, r); return n(o).hex(); }); this.render = t, this.sourceColor = h, this.lightness = i, this.alpha = e, this.hueShifting = r, this.chromaShifting = o, this.algorithmVersion = l, this.visionSimulationMode = u; } } export { O as C, s as H }; //# sourceMappingURL=color-S7JZ1G0L.js.map