Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Prevent flipping percentages in CSS color functions #93

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/cssjanus.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,17 @@ function CSSJanus() {
* @return {string} Inverted property
*/
function calculateNewBackgroundPosition( match, pre, value ) {
var idx, len;
// Check if inside a known color function
var lowerPre = pre.toLowerCase();
if (/(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch|color|color-mix|linear-gradient)\(/.test(lowerPre)) {
// Do not flip if inside a color function
return pre + value;
}

if ( value.slice( -1 ) === '%' ) {
idx = value.indexOf( '.' );
var idx = value.indexOf( '.' );
if ( idx !== -1 ) {
// Two off, one for the "%" at the end, one for the dot itself
len = value.length - idx - 2;
var len = value.length - idx - 2;
value = 100 - parseFloat( value );
value = value.toFixed( len ) + '%';
} else {
Expand Down