refactor(frontend): getBgColorを共通化 (#14782)
* refactor: getBgColor関数の切り出し + fix types (taiyme#291) * move thing * revert unnecesary changes --------- Co-authored-by: taiy <53635909+taiyme@users.noreply.github.com>
This commit is contained in:
18
packages/frontend/src/scripts/get-bg-color.ts
Normal file
18
packages/frontend/src/scripts/get-bg-color.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import tinycolor from 'tinycolor2';
|
||||
|
||||
export const getBgColor = (elem?: Element | null | undefined): string | null => {
|
||||
if (elem == null) return null;
|
||||
|
||||
const { backgroundColor: bg } = window.getComputedStyle(elem);
|
||||
|
||||
if (bg && tinycolor(bg).getAlpha() !== 0) {
|
||||
return bg;
|
||||
}
|
||||
|
||||
return getBgColor(elem.parentElement);
|
||||
};
|
Reference in New Issue
Block a user