(styleElement: HTMLStyleElement, theme: Theme)
| 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 | |
| 623 | export const variablesStore = new VariablesStore(); |
no test coverage detected