Skip to content

Commit 98f4cd2

Browse files
authored
Merge pull request #2261 from IBMa/dev-2219
fix(engine): Issues related to `<elements>` made invisible with clip-path
2 parents 7b6c9d9 + cf785c1 commit 98f4cd2

File tree

9 files changed

+1232
-37
lines changed

9 files changed

+1232
-37
lines changed

accessibility-checker-engine/src/v4/util/CSSUtil.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ export class CSSUtil {
477477
* @return value in pixels
478478
*/
479479
public static convertValue2Pixels(unit, unitValue, elem) {
480-
if (unitValue == 0) return 0;
480+
if (unitValue === 0) return 0;
481+
if (!unit) unit = "px";
481482
const supportedUnits = {
482483
// absolute unit
483484
px: (value) => value,
@@ -511,7 +512,7 @@ export class CSSUtil {
511512
getComputedStyle(elem).getPropertyValue("font-size")
512513
),
513514
};
514-
515+
515516
if (unit in supportedUnits) return supportedUnits[unit](unitValue);
516517

517518
return null;
@@ -863,4 +864,25 @@ export class CSSUtil {
863864
return null;
864865
}
865866

867+
/**
868+
* return an array [value, Unit] from a value-unit combo string
869+
* @param valueUnitCombo, such as 20px, 2rem
870+
* @returns
871+
*/
872+
public static getValueUnitPair(valueUnitCombo) {
873+
if (!valueUnitCombo) return null;
874+
875+
if (Number.isInteger(valueUnitCombo)) return ["px", valueUnitCombo];
876+
877+
const value = parseInt(valueUnitCombo);
878+
if (isNaN(value)) return null;
879+
880+
valueUnitCombo = valueUnitCombo.trim().toLowerCase();
881+
let match = valueUnitCombo.trim().match(/([a-z]+)$/);
882+
let unit = 'px';
883+
if (match) unit = match[1];
884+
885+
return [unit, value];
886+
}
887+
866888
}

0 commit comments

Comments
 (0)