Files
tweakcn/utils/apply-style-to-element.ts
KrisLee1 b629ff8d5a fix: style value accumulation
Fix the issue of style value accumulation in root elements when switching themes.
2025-05-18 00:12:25 +05:30

18 lines
417 B
TypeScript

export function applyStyleToElement(
element: HTMLElement,
key: string,
value: string
) {
const currentStyle = element.getAttribute("style") || "";
// Remove the existing variable definitions with the same name
const cleanedStyle = currentStyle.replace(
new RegExp(`--${key}:\\s*[^;]+;?`, "g"),
""
).trim();
element.setAttribute(
"style",
`${cleanedStyle}--${key}: ${value};`
);
}