igniteui-react-core
Version:
Ignite UI React Core.
511 lines (510 loc) • 19.4 kB
JavaScript
/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE: you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { Base, Boolean_$type, typeCast, String_$type, fromEnum, markType } from "./type";
import { Color } from "./Color";
import { Random } from "./Random";
import { Tuple$2 } from "./Tuple$2";
import { Brush } from "./Brush";
import { LinearGradientBrush } from "./LinearGradientBrush";
import { MathUtil } from "./MathUtil";
import { Dictionary$2 } from "./Dictionary$2";
import { truncate, intDivide } from "./number";
/**
* @hidden
*/
export let ColorUtil = /*@__PURE__*/ (() => {
class ColorUtil extends Base {
static aa(a) {
return Color.u(a, ColorUtil.j.next2(0, 255), ColorUtil.j.next2(0, 255), ColorUtil.j.next2(0, 255));
}
static ab(a) {
let b = ColorUtil.b(a);
return ColorUtil.s(b[0], ColorUtil.j.next2(0, 359), b[2], b[3]);
}
static ad(a) {
let b = 0.299 * a.o + 0.587 * a.n + 0.114 * a.m;
let c = Color.u(a.l, truncate(b), truncate(b), truncate(b));
return c;
}
static p(a) {
let b = Color.u(0, 0, 0, 0);
if (a == null) {
return new Tuple$2(Boolean_$type, Color.$, true, b);
}
if (typeCast(LinearGradientBrush.$, a) !== null) {
if (a.gradientStops == null || a.gradientStops.length < 1) {
return new Tuple$2(Boolean_$type, Color.$, false, b);
}
b = a.gradientStops[0].color;
}
else {
b = a.color;
}
return new Tuple$2(Boolean_$type, Color.$, true, b);
}
static x(a, interpolation_, maximum_, b) {
let min_ = a;
switch (b) {
case 1:
{
let c = ColorUtil.b(a);
let d = ColorUtil.b(maximum_);
let e = c[1] >= 0 ? c[1] : d[1];
let f = d[1] >= 0 ? d[1] : c[1];
if (e >= 0 && f >= 0 && Math.abs(f - e) > 180) {
if (f > e) {
e += 360;
}
else {
f += 360;
}
}
interpolation_ = Math.max(0, Math.min(1, interpolation_));
return ColorUtil.s(c[0] + interpolation_ * (d[0] - c[0]), e + interpolation_ * (f - e), c[2] + interpolation_ * (d[2] - c[2]), c[3] + interpolation_ * (d[3] - c[3]));
}
case 0: return Color.u((min_._a + interpolation_ * (maximum_._a - min_._a)), (min_._r + interpolation_ * (maximum_._r - min_._r)), (min_._g + interpolation_ * (maximum_._g - min_._g)), (min_._b + interpolation_ * (maximum_._b - min_._b)));
}
return a;
}
static v(a, b, c) {
let d = a[1] >= 0 ? a[1] : c[1];
let e = c[1] >= 0 ? c[1] : a[1];
if (d >= 0 && e >= 0 && Math.abs(e - d) > 180) {
if (e > d) {
d += 360;
}
else {
e += 360;
}
}
b = Math.max(0, Math.min(1, b));
return ColorUtil.s(a[0] + b * (c[0] - a[0]), d + b * (e - d), a[2] + b * (c[2] - a[2]), a[3] + b * (c[3] - a[3]));
}
static y(a, b) {
let c = ColorUtil.a(a);
if (b < 0) {
return ColorUtil.r(c[0], c[1], c[2], c[3] * (1 - MathUtil.d(-b, 0, 1)));
}
else {
return ColorUtil.r(c[0], c[1], c[2], c[3] + MathUtil.d(b, 0, 1) * (1 - c[3]));
}
}
static z(a, b) {
let c = ColorUtil.a(a);
if (b < 0) {
return ColorUtil.r(c[0], c[1], c[2] * (1 - MathUtil.d(-b, 0, 1)), c[3]);
}
else {
return ColorUtil.r(c[0], c[1], MathUtil.d(c[2] + MathUtil.d(b, 0, 1) * (1 - c[2]), 0, 1), c[3]);
}
}
static c(a) {
let b = a.o / 255;
let c = a.n / 255;
let d = a.m / 255;
let e = b < 0.03928 ? b / 12.92 : Math.pow(((b + 0.055) / 1.055), 2.4);
let f = c < 0.03928 ? c / 12.92 : Math.pow(((c + 0.055) / 1.055), 2.4);
let g = d < 0.03928 ? d / 12.92 : Math.pow(((d + 0.055) / 1.055), 2.4);
return [e, f, g];
}
static g(a) {
let b = ColorUtil.c(a);
let c = b[0];
let d = b[1];
let e = b[2];
return 0.2126 * c + 0.7152 * d + 0.0722 * e;
}
static ac(a, b) {
let c = a.l / 255;
let d = a.o;
let e = a.n;
let f = a.m;
let g = b.o;
let h = b.n;
let i = b.m;
let j = (1 - c) * g + c * d;
let k = (1 - c) * h + c * e;
let l = (1 - c) * i + c * f;
return Color.u(255, truncate(Math.round(j)), truncate(Math.round(k)), truncate(Math.round(l)));
}
static a(a) {
let b = new Array(4);
let c = a.o / 255;
let d = a.n / 255;
let e = a.m / 255;
let f = Math.min(Math.min(c, d), e);
let g = Math.max(Math.max(c, d), e);
let h = g - f;
b[0] = a.l / 255;
b[3] = (g + f) / 2;
if (h == 0) {
b[1] = -1;
b[2] = 0;
}
else {
b[1] = ColorUtil.h(g, h, c, d, e);
b[2] = b[3] < 0.5 ? h / (g + f) : h / (2 - g - f);
}
return b;
}
static b(a) {
let b = a.l / 255;
let c = a.o / 255;
let d = a.n / 255;
let e = a.m / 255;
let f = Math.min(c, Math.min(d, e));
let g = Math.max(c, Math.max(d, e));
let h = g - f;
let i = new Array(4);
i[0] = b;
i[3] = g;
if (h == 0) {
i[1] = -1;
i[2] = 0;
}
else {
i[1] = ColorUtil.h(g, h, c, d, e);
i[2] = h / g;
}
return i;
}
static r(a, b, c, d) {
let e;
let f;
let g;
if (c == 0) {
e = d;
f = d;
g = d;
}
else {
let h = d < 0.5 ? d * (1 + c) : d + c - (d * c);
let i = 2 * d - h;
let j = b / 360;
e = ColorUtil.f(i, h, j + 1 / 3);
f = ColorUtil.f(i, h, j);
g = ColorUtil.f(i, h, j - 1 / 3);
}
return Color.u(truncate((a * 255)), truncate((e * 255)), truncate((f * 255)), truncate((g * 255)));
}
static s(a, b, c, d) {
let e;
let f;
let g;
while (b >= 360) {
b -= 360;
}
if (c == 0) {
e = d;
f = d;
g = d;
}
else {
b /= 60;
let h = Math.floor(b);
let i = b - h;
let j = d * (1 - c);
let k = d * (1 - c * i);
let l = d * (1 - c * (1 - i));
switch (truncate(h)) {
case 0:
e = d;
f = l;
g = j;
break;
case 1:
e = k;
f = d;
g = j;
break;
case 2:
e = j;
f = d;
g = l;
break;
case 3:
e = j;
f = k;
g = d;
break;
case 4:
e = l;
f = j;
g = d;
break;
default:
e = d;
f = j;
g = k;
break;
}
}
return Color.u(truncate((a * 255)), truncate((e * 255)), truncate((f * 255)), truncate((g * 255)));
}
static h(a, b, c, d, e) {
let f = c == a ? (d - e) / b : d == a ? 2 + (e - c) / b : 4 + (c - d) / b;
f *= 60;
if (f < 0) {
f += 360;
}
return f;
}
static f(a, b, c) {
c = c < 0 ? c + 1 : c > 1 ? c - 1 : c;
if (c < 1 / 6) {
return a + ((b - a) * 6 * c);
}
if (c < 1 / 2) {
return b;
}
if (c < 2 / 3) {
return a + ((b - a) * 6 * (2 / 3 - c));
}
return a;
}
static i(a) {
let b = a.l / 255;
let c = truncate((a.o * b));
let d = truncate((a.n * b));
let e = truncate((a.m * b));
return a.l << 24 | c << 16 | d << 8 | e;
}
static w(a) {
return a.color;
}
static k(a, b) {
if (ColorUtil.e == null) {
ColorUtil.e = new Dictionary$2(String_$type, String_$type, 0);
for (let c of fromEnum(ColorUtil.d.keys)) {
let d = ColorUtil.d.item(c);
ColorUtil.e.item(d, c);
}
}
let e = ColorUtil.m(a);
if (ColorUtil.e.containsKey(e.toLowerCase())) {
return ColorUtil.e.item(e.toLowerCase());
}
if (b) {
e = ColorUtil.o(a);
}
return e;
}
static o(a) {
return "rgba(" + a.o + ", " + a.n + ", " + a.m + ", " + (a.l / 255) + ")";
}
static m(a) {
if (a.l == 255) {
return "#" + ColorUtil.l(a.o) + ColorUtil.l(a.n) + ColorUtil.l(a.m);
}
else {
return "#" + ColorUtil.l(a.l) + ColorUtil.l(a.o) + ColorUtil.l(a.n) + ColorUtil.l(a.m);
}
}
static l(a) {
let b = intDivide(a, 16);
let c = a % 16;
return ColorUtil.n(b) + ColorUtil.n(c);
}
static n(a) {
switch (a) {
case 0: return "0";
case 1: return "1";
case 2: return "2";
case 3: return "3";
case 4: return "4";
case 5: return "5";
case 6: return "6";
case 7: return "7";
case 8: return "8";
case 9: return "9";
case 10: return "a";
case 11: return "b";
case 12: return "c";
case 13: return "d";
case 14: return "e";
case 15: return "f";
}
return "0";
}
static u(a) {
let b = new Color();
b.colorString = a;
return b;
}
static t(a) {
let b = ((() => {
let $ret = new Color();
$ret.l = 255;
return $ret;
})());
b = ColorUtil.u(a._fill);
return b;
}
static q(a) {
let b = null;
let c = a.colorString;
b = ((() => {
let $ret = new Brush();
$ret.fill = c;
return $ret;
})());
return b;
}
}
ColorUtil.$t = /*@__PURE__*/ markType(ColorUtil, 'ColorUtil');
ColorUtil.j = /*@__PURE__*/ new Random(0);
ColorUtil.e = null;
ColorUtil.d = /*@__PURE__*/ ((() => {
let $ret = new Dictionary$2(String_$type, String_$type, 0);
$ret.addItem("transparent", "#000000");
$ret.addItem("aliceblue", "#f0f8ff");
$ret.addItem("antiquewhite", "#faebd7");
$ret.addItem("aqua", "#00ffff");
$ret.addItem("aquamarine", "#7fffd4");
$ret.addItem("azure", "#f0ffff");
$ret.addItem("beige", "#f5f5dc");
$ret.addItem("bisque", "#ffe4c4");
$ret.addItem("black", "#000000");
$ret.addItem("blanchedalmond", "#ffebcd");
$ret.addItem("blue", "#0000ff");
$ret.addItem("blueviolet", "#8a2be2");
$ret.addItem("brown", "#a52a2a");
$ret.addItem("burlywood", "#deb887");
$ret.addItem("cadetblue", "#5f9ea0");
$ret.addItem("chartreuse", "#7fff00");
$ret.addItem("chocolate", "#d2691e");
$ret.addItem("coral", "#ff7f50");
$ret.addItem("cornflowerblue", "#6495ed");
$ret.addItem("cornsilk", "#fff8dc");
$ret.addItem("crimson", "#dc143c");
$ret.addItem("cyan", "#00ffff");
$ret.addItem("darkblue", "#00008b");
$ret.addItem("darkcyan", "#008b8b");
$ret.addItem("darkgoldenrod", "#b8860b");
$ret.addItem("darkgray", "#a9a9a9");
$ret.addItem("darkgreen", "#006400");
$ret.addItem("darkkhaki", "#bdb76b");
$ret.addItem("darkmagenta", "#8b008b");
$ret.addItem("darkolivegreen", "#556b2f");
$ret.addItem("darkorange", "#ff8c00");
$ret.addItem("darkorchid", "#9932cc");
$ret.addItem("darkred", "#8b0000");
$ret.addItem("darksalmon", "#e9967a");
$ret.addItem("darkseagreen", "#8fbc8f");
$ret.addItem("darkslateblue", "#483d8b");
$ret.addItem("darkslategray", "#2f4f4f");
$ret.addItem("darkturquoise", "#00ced1");
$ret.addItem("darkviolet", "#9400d3");
$ret.addItem("deeppink", "#ff1493");
$ret.addItem("deepskyblue", "#00bfff");
$ret.addItem("dimgray", "#696969");
$ret.addItem("dodgerblue", "#1e90ff");
$ret.addItem("feldspar", "#d19275");
$ret.addItem("firebrick", "#b22222");
$ret.addItem("floralwhite", "#fffaf0");
$ret.addItem("forestgreen", "#228b22");
$ret.addItem("fuchsia", "#ff00ff");
$ret.addItem("gainsboro", "#dcdcdc");
$ret.addItem("ghostwhite", "#f8f8ff");
$ret.addItem("gold", "#ffd700");
$ret.addItem("goldenrod", "#daa520");
$ret.addItem("gray", "#808080");
$ret.addItem("green", "#008000");
$ret.addItem("greenyellow", "#adff2f");
$ret.addItem("honeydew", "#f0fff0");
$ret.addItem("hotpink", "#ff69b4");
$ret.addItem("indianred", "#cd5c5c");
$ret.addItem("indigo", "#4b0082");
$ret.addItem("ivory", "#fffff0");
$ret.addItem("khaki", "#f0e68c");
$ret.addItem("lavender", "#e6e6fa");
$ret.addItem("lavenderblush", "#fff0f5");
$ret.addItem("lawngreen", "#7cfc00");
$ret.addItem("lemonchiffon", "#fffacd");
$ret.addItem("lightblue", "#add8e6");
$ret.addItem("lightcoral", "#f08080");
$ret.addItem("lightcyan", "#e0ffff");
$ret.addItem("lightgoldenrodyellow", "#fafad2");
$ret.addItem("lightgray", "#d3d3d3");
$ret.addItem("lightgreen", "#90ee90");
$ret.addItem("lightpink", "#ffb6c1");
$ret.addItem("lightsalmon", "#ffa07a");
$ret.addItem("lightseagreen", "#20b2aa");
$ret.addItem("lightskyblue", "#87cefa");
$ret.addItem("lightslateblue", "#8470ff");
$ret.addItem("lightslategray", "#778899");
$ret.addItem("lightsteelblue", "#b0c4de");
$ret.addItem("lightyellow", "#ffffe0");
$ret.addItem("lime", "#00ff00");
$ret.addItem("limegreen", "#32cd32");
$ret.addItem("linen", "#faf0e6");
$ret.addItem("magenta", "#ff00ff");
$ret.addItem("maroon", "#800000");
$ret.addItem("mediumaquamarine", "#66cdaa");
$ret.addItem("mediumblue", "#0000cd");
$ret.addItem("mediumorchid", "#ba55d3");
$ret.addItem("mediumpurple", "#9370d8");
$ret.addItem("mediumseagreen", "#3cb371");
$ret.addItem("mediumslateblue", "#7b68ee");
$ret.addItem("mediumspringgreen", "#00fa9a");
$ret.addItem("mediumturquoise", "#48d1cc");
$ret.addItem("mediumvioletred", "#c71585");
$ret.addItem("midnightblue", "#191970");
$ret.addItem("mintcream", "#f5fffa");
$ret.addItem("mistyrose", "#ffe4e1");
$ret.addItem("moccasin", "#ffe4b5");
$ret.addItem("navajowhite", "#ffdead");
$ret.addItem("navy", "#000080");
$ret.addItem("oldlace", "#fdf5e6");
$ret.addItem("olive", "#808000");
$ret.addItem("olivedrab", "#6b8e23");
$ret.addItem("orange", "#ffa500");
$ret.addItem("orangered", "#ff4500");
$ret.addItem("orchid", "#da70d6");
$ret.addItem("palegoldenrod", "#eee8aa");
$ret.addItem("palegreen", "#98fb98");
$ret.addItem("paleturquoise", "#afeeee");
$ret.addItem("palevioletred", "#d87093");
$ret.addItem("papayawhip", "#ffefd5");
$ret.addItem("peachpuff", "#ffdab9");
$ret.addItem("peru", "#cd853f");
$ret.addItem("pink", "#ffc0cb");
$ret.addItem("plum", "#dda0dd");
$ret.addItem("powderblue", "#b0e0e6");
$ret.addItem("purple", "#800080");
$ret.addItem("red", "#ff0000");
$ret.addItem("rosybrown", "#bc8f8f");
$ret.addItem("royalblue", "#4169e1");
$ret.addItem("saddlebrown", "#8b4513");
$ret.addItem("salmon", "#fa8072");
$ret.addItem("sandybrown", "#f4a460");
$ret.addItem("seagreen", "#2e8b57");
$ret.addItem("seashell", "#fff5ee");
$ret.addItem("sienna", "#a0522d");
$ret.addItem("silver", "#c0c0c0");
$ret.addItem("skyblue", "#87ceeb");
$ret.addItem("slateblue", "#6a5acd");
$ret.addItem("slategray", "#708090");
$ret.addItem("snow", "#fffafa");
$ret.addItem("springgreen", "#00ff7f");
$ret.addItem("steelblue", "#4682b4");
$ret.addItem("tan", "#d2b48c");
$ret.addItem("teal", "#008080");
$ret.addItem("thistle", "#d8bfd8");
$ret.addItem("tomato", "#ff6347");
$ret.addItem("turquoise", "#40e0d0");
$ret.addItem("violet", "#ee82ee");
$ret.addItem("violetred", "#d02090");
$ret.addItem("wheat", "#f5deb3");
$ret.addItem("white", "#ffffff");
$ret.addItem("whitesmoke", "#f5f5f5");
$ret.addItem("yellow", "#ffff00");
$ret.addItem("yellowgreen", "#9acd32");
return $ret;
})());
return ColorUtil;
})();