MCPcopy Index your code
hub / github.com/darkreader/darkreader / putRootVars

Method putRootVars

src/inject/dynamic-theme/variables.ts:588–620  ·  view source on GitHub ↗
(styleElement: HTMLStyleElement, theme: Theme)

Source from the content-addressed store, hash-verified

586 }
587
588 putRootVars(styleElement: HTMLStyleElement, theme: Theme): void {
589 const declarations = new Map<string, string>();
590 iterateCSSDeclarations(document.documentElement.style, (property, value) => {
591 if (isVariable(property)) {
592 if (this.isVarType(property, VAR_TYPE_BG_COLOR)) {
593 declarations.set(wrapBgColorVariableName(property), tryModifyBgColor(value, theme));
594 }
595 if (this.isVarType(property, VAR_TYPE_TEXT_COLOR)) {
596 declarations.set(wrapTextColorVariableName(property), tryModifyTextColor(value, theme));
597 }
598 if (this.isVarType(property, VAR_TYPE_BORDER_COLOR)) {
599 declarations.set(wrapBorderColorVariableName(property), tryModifyBorderColor(value, theme));
600 }
601 this.subscribeForVarTypeChange(property, this.onRootVariableDefined);
602 }
603 });
604 const cssLines: string[] = [];
605 cssLines.push(':root {');
606 for (const [property, value] of declarations) {
607 cssLines.push(` ${property}: ${value};`);
608 }
609 cssLines.push('}');
610 const cssText = cssLines.join('\n');
611 const sheet = styleElement.sheet;
612 if (sheet) {
613 if (sheet.cssRules.length > 0) {
614 sheet.deleteRule(0);
615 }
616 sheet.insertRule(cssText);
617 } else {
618 styleElement.textContent = cssText;
619 }
620 }
621}
622
623export const variablesStore = new VariablesStore();

Callers 2

watchForUpdatesFunction · 0.80

Calls 13

isVarTypeMethod · 0.95
iterateCSSDeclarationsFunction · 0.90
isVariableFunction · 0.85
wrapBgColorVariableNameFunction · 0.85
tryModifyBgColorFunction · 0.85
tryModifyTextColorFunction · 0.85
tryModifyBorderColorFunction · 0.85
deleteRuleMethod · 0.80
insertRuleMethod · 0.80

Tested by

no test coverage detected