Skip to content

Commit

Permalink
Merge pull request #1312 from capricorn86/1308-if-multiple-custom-pro…
Browse files Browse the repository at this point in the history
…perty-fallbacks-occur-getpropertyvalue-returns-an-empty-string

chore: [#1308] Fixes problem with last implementation for parsing CSS…
  • Loading branch information
capricorn86 authored Mar 14, 2024
2 parents 8786172 + d65c771 commit 8b2eb74
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import CSSMeasurementConverter from '../measurement-converter/CSSMeasurementConv
import MediaQueryList from '../../../match-media/MediaQueryList.js';
import WindowBrowserSettingsReader from '../../../window/WindowBrowserSettingsReader.js';

const CSS_VARIABLE_REGEXP = /var\( *(--[^), ]+)\)|var\( *(--[^), ]+), *([^), ]+)\)/g;
const CSS_VARIABLE_REGEXP = /var\( *(--[^), ]+)\)|var\( *(--[^), ]+), *([^), ]+)\)/;
const CSS_MEASUREMENT_REGEXP = /[0-9.]+(px|rem|em|vw|vh|%|vmin|vmax|cm|mm|in|pt|pc|Q)/g;

type IStyleAndElement = {
Expand Down Expand Up @@ -364,11 +364,10 @@ export default class CSSStyleDeclarationElementStyle {
* @returns CSS value.
*/
private parseCSSVariablesInValue(value: string, cssVariables: { [k: string]: string }): string {
const regexp = new RegExp(CSS_VARIABLE_REGEXP);
let newValue = value;
let match;

while ((match = regexp.exec(newValue)) !== null) {
while ((match = newValue.match(CSS_VARIABLE_REGEXP)) !== null) {
// Fallback value - E.g. var(--my-var, #FFFFFF)
if (match[2] !== undefined) {
newValue = newValue.replace(match[0], cssVariables[match[2]] || match[3]);
Expand Down

0 comments on commit 8b2eb74

Please sign in to comment.