function textColor(content, { theme, ...style }) {
theme = themes.get(theme);
function yiq(color) {
const { r, g, b } = d3.rgb(color);
return (r * 299 + g * 587 + b * 114) / 1000 / 255;
}
const {
background = theme.get(content) ?? content,
color = yiq(background) >= 0.6 ? "#111" : "white",
padding = "0 5px",
borderRadius = "4pxf",
fontWeight = 800,
...rest
} = Object.entries(style).reduce((obj, [k, v]) => {
obj[k] = theme.get(v) ?? v;
return obj;
}, {});
return htl.html`<span style=${{
background,
color,
padding,
borderRadius,
fontWeight,
...rest
}}>${content}</span>`;
}