UNPKG

igniteui-react-core

Version:
569 lines (568 loc) 19.8 kB
/* 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, markType } from "./type"; import { Brush } from "./Brush"; import { Color } from "./Color"; import { LinearGradientBrush } from "./LinearGradientBrush"; import { GradientStop } from "./GradientStop"; import { ColorUtil } from "./ColorUtil"; import { Tuple$2 } from "./Tuple$2"; import { BrushCollection } from "./BrushCollection"; import { List$1 } from "./List$1"; import { CssGradientUtil } from "./CssGradientUtil"; import { truncate } from "./number"; import { stringJoin1 } from "./string"; /** * @hidden */ export let BrushUtil = /*@__PURE__*/ (() => { class BrushUtil extends Base { static d(a, b) { if (a == null && b == null) { return true; } else if ((a != null && b == null) || (a == null && b != null)) { return false; } if ((a._fill == null && b._fill != null) || (a._fill != null && b._fill == null)) { return false; } else if (a._fill == null && b._fill == null) { return a.color.equals(b.color) && a.isGradient == b.isGradient && a.isImageFill == b.isImageFill && a.isRadialGradient == b.isRadialGradient; } else { return Base.equalsStatic(a, b); } } static o(a, b) { if (a == null) { return a; } if (a.isGradient) { let c = a.clone(); for (let d = 0; d < c.gradientStops.length; d++) { let e = c.gradientStops[d]; e.color = ColorUtil.y(e.color, b); } return c; } else { let f = ColorUtil.y(a.color, b); return ((() => { let $ret = new Brush(); $ret.color = f; return $ret; })()); } } static q(a, b) { if (a == null) { return a; } if (a.isGradient) { let c = a.clone(); for (let d = 0; d < c.gradientStops.length; d++) { let e = c.gradientStops[d]; e.color = ColorUtil.z(e.color, b); } return c; } else { let f = ColorUtil.z(a.color, b); return ((() => { let $ret = new Brush(); $ret.color = f; return $ret; })()); } } static p(a, b) { if (a == null) { return a; } if (a.isGradient) { let c = a.clone(); for (let d = 0; d < c.gradientStops.length; d++) { let e = c.gradientStops[d]; e.color = BrushUtil.w(e.color, b); } return c; } else { let f = BrushUtil.w(a.color, b); return ((() => { let $ret = new Brush(); $ret.color = f; return $ret; })()); } } static w(a, b) { return Color.u(truncate(Math.round(255 * b)), a.o, a.n, a.m); } static g(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 v(a) { if (a == null) { return a; } if (typeCast(LinearGradientBrush.$, a) !== null) { let b = a.clone(); for (let c = 0; c < b.gradientStops.length; c++) { let d = b.gradientStops[c]; d.color = ColorUtil.ad(d.color); } return b; } else { let e = ((() => { let $ret = new Brush(); $ret.color = a.color; return $ret; })()); e.color = ColorUtil.ad(e.color); return e; } } static l(a, b, c) { let d = BrushUtil.g(a); let e = new Color(); if (!d.c) { return b; } else { e = d.d; } let f = new Color(); let g = new Color(); let h = BrushUtil.g(b); if (!h.c) { return b; } g = h.d; let i = BrushUtil.g(c); if (!i.c) { return b; } f = i.d; let j = ColorUtil.ac(e, f); let k = ColorUtil.g(j); let l = ColorUtil.g(f); let m = (Math.max(k, l) + 0.05) / (Math.min(k, l) + 0.05); j = ColorUtil.ac(e, g); k = ColorUtil.g(j); l = ColorUtil.g(g); let n = (Math.max(k, l) + 0.05) / (Math.min(k, l) + 0.05); if (n > m) { return b; } return c; } static k(a, b, c) { let d = new Color(); if (typeCast(LinearGradientBrush.$, a) !== null) { if (a.gradientStops == null || a.gradientStops.length < 1) { let e = new Brush(); e.color = b; return e; } d = a.gradientStops[0].color; } else { d = a.color; } let f = ColorUtil.ac(d, c); let g = ColorUtil.g(f); let h = ColorUtil.g(c); let i = (Math.max(g, h) + 0.05) / (Math.min(g, h) + 0.05); f = ColorUtil.ac(d, b); g = ColorUtil.g(f); h = ColorUtil.g(b); let j = (Math.max(g, h) + 0.05) / (Math.min(g, h) + 0.05); if (j > i) { return ((() => { let $ret = new Brush(); $ret.color = b; return $ret; })()); } return ((() => { let $ret = new Brush(); $ret.color = c; return $ret; })()); } static s(a, b) { if (a == null) { return a; } if (a.isGradient) { let c = a.clone(); for (let d = 0; d < c.gradientStops.length; d++) { let e = c.gradientStops[d]; e.color = Color.u(truncate(Math.round(e.color.l * b)), e.color.o, e.color.n, e.color.m); } return c; } else { let f = Color.u(truncate(Math.round(a.color.l * b)), a.color.o, a.color.n, a.color.m); return ((() => { let $ret = new Brush(); $ret.color = f; return $ret; })()); } } static n(a, b, c, d) { let e = new Brush(); if (a == null && c == null) { e._fill = "transparent"; return e; } let f = null, g = null; let h = null, i = null; if (a == null) { let j = c.isGradient ? ((() => { let $ret = new Color(); $ret.l = 0; $ret.o = 255; $ret.n = 255; $ret.m = 255; return $ret; })()) : ((() => { let $ret = new Color(); $ret.l = 0; $ret.o = c.color.o; $ret.n = c.color.n; $ret.m = c.color.m; return $ret; })()); f = ((() => { let $ret = new Brush(); $ret.color = j; return $ret; })()); } else { if (a.isGradient) { h = a; } else { f = a; } } if (c == null) { let k = a.isGradient ? ((() => { let $ret = new Color(); $ret.l = 0; $ret.o = 255; $ret.n = 255; $ret.m = 255; return $ret; })()) : ((() => { let $ret = new Color(); $ret.l = 0; $ret.o = a.color.o; $ret.n = a.color.n; $ret.m = a.color.m; return $ret; })()); g = ((() => { let $ret = new Brush(); $ret.color = k; return $ret; })()); } else { if (c.isGradient) { i = c; } else { g = c; } } if (f != null && g != null) { return BrushUtil.u(f, b, g, d); } if (f != null && i != null) { return BrushUtil.t(f, b, i, d); } if (h != null && g != null) { return BrushUtil.t(g, 1 - b, h, d); } if (h != null && i != null) { return BrushUtil.r(h, b, i, d); } return e; } static j(a, b, c, d) { let e = new Brush(); e.color = Color.u(a, b, c, d); return e; } static u(a, b, c, d) { let e = new Brush(); e.color = ColorUtil.x(a.color, b, c.color, d); return e; } static t(a, b, c, d) { let e = new LinearGradientBrush(); e.gradientStops = BrushUtil.c(a.color, b, c.gradientStops, d); if (c.useCustomDirection) { e.useCustomDirection = true; e.startX = c.startX; e.startY = c.startY; e.endX = c.endX; e.endY = c.endY; } return e; } static r(a, b, c, d) { let e = new LinearGradientBrush(); e.gradientStops = BrushUtil.b(a.gradientStops, b, c.gradientStops, d); if (a.useCustomDirection || c.useCustomDirection) { e.useCustomDirection = true; e.startX = a.startX + b * (c.startX - a.startX); e.startY = a.startY + b * (c.startY - a.startY); e.endX = (1 - b) * a.endX + b * c.endX; e.endY = (1 - b) * a.endY + b * c.endY; } return e; } static c(a, b, c, d) { let e = new Array(c.length); for (let f = 0; f < c.length; ++f) { e[f] = ((() => { let $ret = new GradientStop(); $ret.offset = c[f].offset; $ret.color = ColorUtil.x(a, b, c[f].color, d); return $ret; })()); } return e; } static b(a, b, c, d) { let e = Math.min(a.length, c.length); let f = Math.max(a.length, c.length); let g = new Array(f); let h = 0; for (; h < e; ++h) { g[h] = ((() => { let $ret = new GradientStop(); $ret.offset = (1 - b) * a[h].offset + b * c[h].offset; $ret.color = ColorUtil.x(a[h].color, b, c[h].color, d); return $ret; })()); } for (; h < a.length; ++h) { g[h] = ((() => { let $ret = new GradientStop(); $ret.offset = (1 - b) * a[h].offset + b * c[c.length - 1].offset; $ret.color = ColorUtil.x(a[h].color, b, c[c.length - 1].color, d); return $ret; })()); } for (; h < c.length; ++h) { g[h] = ((() => { let $ret = new GradientStop(); $ret.offset = (1 - b) * a[a.length - 1].offset + b * c[h].offset; $ret.color = ColorUtil.x(a[a.length - 1].color, b, c[h].color, d); return $ret; })()); } return g; } static a(a, b) { let c = new Array(2); b.addClass(a); let d = new Brush(); d._fill = b.getStyleProperty("background-color"); let e = new Brush(); e._fill = b.getStyleProperty("border-top-color"); b.removeClass(a); c[0] = d; c[1] = e; return c; } static h(palleteName_, container_, a, b, c = null) { a = new BrushCollection(); b = new BrushCollection(); let d; let e = new List$1(String_$type, 0); e.add("background-color"); e.add("border-top-color"); container_.startCSSQuery(); let f = container_.getCssDefaultValuesForClassCollection("ui-" + palleteName_ + "-palette-", e.toArray()); let g = f.length; if (g == 0) { if (c == null) { c = ["#B1BFC9", "#50a8be", "#798995", "#fc6754", "#4F606C", "#fec33c", "#374650", "#3c6399", "#162C3B", "#91af49"]; } for (let h = 0; h < c.length - 1; h += 2) { d = new Brush(); d._fill = c[h]; b.add(d); d = new Brush(); d._fill = c[h + 1]; a.add(d); } } for (let i = 0; i < g; i++) { let j = new Brush(); j._fill = f[i][0]; let k = new Brush(); k._fill = f[i][1]; a.add(j); b.add(k); } container_.endCSSQuery(); return { p2: a, p3: b }; } static i(a, b, c, container_, d, e, f = null) { d = new BrushCollection(); e = new BrushCollection(); if (f == null) { f = ["#B1BFC9", "#50a8be", "#798995", "#fc6754", "#4F606C", "#fec33c", "#374650", "#3c6399", "#162C3B", "#91af49"]; } container_.startCSSQuery(); let g = new List$1(String_$type, 0); g.add("background-image"); let h = container_.getCssDefaultValuesForClassCollection(a, g.toArray()); let i = h.length; let j = container_.getCssDefaultValuesForClassCollection(b, g.toArray()); let k = j.length; for (let l = 0; l < i; l++) { d.add(CssGradientUtil.brushFromGradientString(h[l][0])); } for (let m = 0; m < k; m++) { e.add(CssGradientUtil.brushFromGradientString(j[m][0])); } g.clear(); let n = 0; let o = 0; let p = Math.min(i, k); let q = null; if (i == 0) { g.add("background-color"); } if (k == 0) { g.add("border-top-color"); o = i == 0 ? 1 : 0; } if (g.count > 0) { q = container_.getCssDefaultValuesForClassCollection(c, g.toArray()); p = q.length; } if (i == 0) { if (p > 0) { for (let r = 0; r < p; r++) { let s = new Brush(); s._fill = q[r][n]; d.add(s); } } else { for (let t = 0; t < f.length - 1; t += 2) { let u = new Brush(); u = new Brush(); u._fill = f[t + 1]; d.add(u); } } } if (k == 0) { if (p > 0) { for (let v = 0; v < p; v++) { let w = new Brush(); w._fill = q[v][o]; e.add(w); } } else { for (let x = 0; x < f.length - 1; x += 2) { let y = new Brush(); y._fill = f[x]; e.add(y); } } } container_.endCSSQuery(); return { p4: d, p5: e }; } static m(a, b, c, container_, d) { let e = null; container_.startCSSQuery(); let f = container_.getCssDefaultPropertyValue(a, "background-image"); if (f != null) { e = CssGradientUtil.brushFromGradientString(f); } if (e == null) { e = new Brush(); let g = container_.getCssDefaultPropertyValue(b, c); e._fill = g != null ? g : d; } container_.endCSSQuery(); return e; } static f(a) { if (a == null) { return "null"; } if (a.isGradient) { let b = new List$1(String_$type, 0); let c = a.gradientStops; for (let d = 0; d < c.length; d++) { let e = c[d].color; b.add(ColorUtil.o(e)); } return stringJoin1(String_$type, " ", b); } else { return ColorUtil.o(a.color); } } static e(a) { if (a == null) { return "null"; } if (a.isGradient) { let b = new List$1(String_$type, 0); let c = a.gradientStops; for (let d = 0; d < c.length; d++) { let e = c[d].color; b.add(ColorUtil.m(e)); } return stringJoin1(String_$type, " ", b); } else { return ColorUtil.m(a.color); } } } BrushUtil.$t = /*@__PURE__*/ markType(BrushUtil, 'BrushUtil'); return BrushUtil; })();