@progress/kendo-vue-inputs
Version:
66 lines (65 loc) • 2.28 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 { defineComponent as v, createVNode as C } from "vue";
import { bezierCommand as b, controlPoint as A, line as S } from "./utils/svg-calc.mjs";
import { getContrastFromTwoRGBAs as T, getRGBA as h, getColorFromHSV as $ } from "./utils/color-parser.mjs";
const p = 4.5, g = 7, f = 16, R = /* @__PURE__ */ v({
name: "KendoColorContrastSvg",
props: {
metrics: Object,
backgroundColor: String,
hsva: Object
},
render() {
const u = function(o, s) {
if (o.length === 0)
return "";
const r = o.reduce((e, t, n, i) => n === 0 ? (
// if first point
`M ${t[0]},${t[1]}`
) : (
// else
`${e} ${s(t, n, i)}`
), "");
return C("path", {
d: r,
fill: "none",
stroke: "white",
"stroke-width": "1"
}, null);
}, c = this.$props.metrics, m = (o, s, r, e, t) => {
const n = (r + e) / 2, i = Object.assign({}, this.$props.hsva, {
s: s / c.width,
v: 1 - n / c.height
}), l = T(h($(i)), h(this.$props.backgroundColor || ""));
return r + 0.5 > e ? l < o + 1 && l > o - 1 ? n : null : t(l, o) ? m(o, s, r, e - (e - r) / 2, t) : m(o, s, r + (e - r) / 2, e, t);
}, a = (o, s, r = !1) => {
const e = [];
for (let t = 0; t <= c.width; t += c.width / s) {
const n = m(o, t, 0, c.height, r ? (i, l) => i < l : (i, l) => i > l);
n !== null && e.push([t, n]);
}
return e;
}, d = b(A(S));
return C("svg", {
xmlns: "http://www.w3.org/2000/svg",
class: "k-color-contrast-svg",
style: {
position: "absolute",
overflow: "visible",
pointerEvents: "none",
left: 0,
top: 0,
zIndex: 3
}
}, [u.call(this, a(p, f), d), u.call(this, a(p, f, !0), d), u.call(this, a(g, f), d), u.call(this, a(g, f, !0), d)]);
}
});
export {
R as ColorContrastSvg
};