MCPcopy
hub / github.com/darkreader/darkreader / getDeclarations

Method getDeclarations

src/inject/dynamic-theme/variables.ts:150–217  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

148 const {varName, sourceValue, rule, ignoredImgSelectors, isCancelled} = options;
149
150 const getDeclarations = () => {
151 const declarations: ModifiedVarDeclaration[] = [];
152
153 const addModifiedValue = (
154 typeNum: number,
155 varNameWrapper: (name: string) => string,
156 colorModifier: (c: string, t: Theme) => string,
157 ) => {
158 if (!this.isVarType(varName, typeNum)) {
159 return;
160 }
161 const property = varNameWrapper(varName);
162 let modifiedValue: string;
163 if (isVarDependant(sourceValue)) {
164 if (isConstructedColorVar(sourceValue)) {
165 let value = insertVarValues(sourceValue, this.unstableVarValues);
166 if (!value) {
167 value = typeNum === VAR_TYPE_BG_COLOR ? '#ffffff' : '#000000';
168 }
169 modifiedValue = colorModifier(value, theme);
170 } else {
171 modifiedValue = replaceCSSVariablesNames(
172 sourceValue,
173 (v) => varNameWrapper(v),
174 (fallback) => colorModifier(fallback, theme),
175 );
176 }
177 } else {
178 modifiedValue = colorModifier(sourceValue, theme);
179 }
180 declarations.push({
181 property,
182 value: modifiedValue,
183 });
184 };
185
186 addModifiedValue(VAR_TYPE_BG_COLOR, wrapBgColorVariableName, tryModifyBgColor);
187 addModifiedValue(VAR_TYPE_TEXT_COLOR, wrapTextColorVariableName, tryModifyTextColor);
188 addModifiedValue(VAR_TYPE_BORDER_COLOR, wrapBorderColorVariableName, tryModifyBorderColor);
189 if (this.isVarType(varName, VAR_TYPE_BG_IMG)) {
190 const property = wrapBgImgVariableName(varName);
191 let modifiedValue: string | Promise<string | null> = sourceValue;
192 if (isVarDependant(sourceValue)) {
193 modifiedValue = replaceCSSVariablesNames(
194 sourceValue,
195 (v) => wrapBgColorVariableName(v),
196 (fallback) => tryModifyBgColor(fallback, theme),
197 );
198 }
199 const pushFilter = rule.selectorText ?
200 (type: FilterType) => this.setVarFilterType(varName, type) :
201 null;
202 const bgModifier = getBgImageModifier(
203 modifiedValue,
204 rule,
205 ignoredImgSelectors,
206 isCancelled,
207 pushFilter,

Callers

nothing calls this directly

Calls 8

isVarTypeMethod · 0.95
setVarFilterTypeMethod · 0.95
getBgImageModifierFunction · 0.90
wrapBgImgVariableNameFunction · 0.85
isVarDependantFunction · 0.85
replaceCSSVariablesNamesFunction · 0.85
wrapBgColorVariableNameFunction · 0.85
tryModifyBgColorFunction · 0.85

Tested by

no test coverage detected