@progress/kendo-react-inputs
Version:
React Inputs offer a customizable interface for users to enter and pick different information. KendoReact Input package
64 lines (63 loc) • 2.2 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
import * as d from "react";
import { svgPath as p, bezierCommand as f, controlPoint as A, line as b } from "./utils/svg-calc.mjs";
import { getContrastFromTwoRGBAs as S, getRGBA as h, getColorFromHSV as T } from "./utils/color-parser.mjs";
const C = 4.5, g = 7, m = 16;
class w extends d.Component {
renderSvgCurveLine() {
const t = this.props.metrics, v = (o, i, r, e, s) => {
const a = (r + e) / 2, l = Object.assign({}, this.props.hsva, {
s: i / t.width,
v: 1 - a / t.height
}), n = S(
h(T(l)),
h(this.props.backgroundColor || "")
);
return r + 0.5 > e ? n < o + 1 && n > o - 1 ? a : null : s(n, o) ? v(o, i, r, e - (e - r) / 2, s) : v(o, i, r + (e - r) / 2, e, s);
}, c = (o, i, r = !1) => {
const e = [];
for (let s = 0; s <= t.width; s += t.width / i) {
const a = v(
o,
s,
0,
t.height,
r ? (l, n) => l < n : (l, n) => l > n
);
a !== null && e.push([s, a]);
}
return e;
}, u = f(A(b));
return p(c(C, m), u) + p(c(C, m, !0), u) + p(c(g, m), u) + p(c(g, m, !0), u);
}
shouldComponentUpdate(t) {
return !(t.hsva.h === this.props.hsva.h && t.hsva.a === this.props.hsva.a && this.props.backgroundColor === t.backgroundColor && t.metrics === this.props.metrics);
}
render() {
return /* @__PURE__ */ d.createElement(
"svg",
{
xmlns: "http://www.w3.org/2000/svg",
className: "k-color-contrast-svg",
dangerouslySetInnerHTML: { __html: this.renderSvgCurveLine() },
style: {
position: "absolute",
overflow: "visible",
pointerEvents: "none",
left: 0,
top: 0,
zIndex: 3
}
}
);
}
}
export {
w as ColorContrastSvg
};