magnetar/fe_calckey/frontend/client/src/directives/panel.ts

34 lines
988 B
TypeScript
Raw Normal View History

2023-07-07 19:22:30 +00:00
import { Directive } from "vue";
export default {
mounted(src, binding, vn) {
const getBgColor = (el: HTMLElement) => {
const style = window.getComputedStyle(el);
if (
style.backgroundColor &&
!["rgba(0, 0, 0, 0)", "rgba(0,0,0,0)", "transparent"].includes(
style.backgroundColor
)
) {
return style.backgroundColor;
} else {
return el.parentElement
? getBgColor(el.parentElement)
: "transparent";
}
};
2023-07-07 19:22:30 +00:00
const parentBg = getBgColor(src.parentElement);
2023-07-07 19:22:30 +00:00
const myBg = getComputedStyle(
document.documentElement
).getPropertyValue("--panel");
2023-07-07 19:22:30 +00:00
if (parentBg === myBg) {
src.style.backgroundColor = "var(--bg)";
} else {
src.style.backgroundColor = "var(--panel)";
}
},
2023-07-07 19:22:30 +00:00
} as Directive;