blob: 2bfd22f6b951622ee8678c7c9749002f863479e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import type { Directive } from 'vue';
import { getBgColor } from '@/utility/get-bg-color.js';
import { globalEvents } from '@/events.js';
const handlerMap = new WeakMap<HTMLElement, () => void>();
export const adaptiveBorderDirective = {
mounted(src) {
function calc() {
const parentBg = getBgColor(src.parentElement) ?? 'transparent';
const myBg = window.getComputedStyle(src).backgroundColor;
if (parentBg === myBg) {
src.style.borderColor = 'var(--MI_THEME-divider)';
} else {
src.style.borderColor = myBg;
}
}
handlerMap.set(src, calc);
calc();
globalEvents.on('themeChanged', calc);
},
unmounted(src) {
globalEvents.off('themeChanged', handlerMap.get(src));
},
} as Directive<HTMLElement>;
|