Skip to content
Open
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
22 changes: 20 additions & 2 deletions src/core/core.animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ import {resolve} from '../helpers/helpers.options.js';
import {color as helpersColor} from '../helpers/helpers.color.js';

const transparent = 'transparent';

/**
* Strip CSS comments from a color string.
* Handles /* ... */ style comments that some users put in rgba() for documentation.
* @param {string} value
* @returns {string}
*/
function stripCssComments(value) {
if (typeof value !== 'string') {
return value;
}
// Remove /* ... */ comments from the string
return value.replace(/\/\*[\s\S]*?\*\//g, '');
}

const interpolators = {
boolean(from, to, factor) {
return factor > 0.5 ? to : from;
Expand All @@ -13,8 +28,11 @@ const interpolators = {
* @param {number} factor
*/
color(from, to, factor) {
const c0 = helpersColor(from || transparent);
const c1 = c0.valid && helpersColor(to || transparent);
// Strip CSS comments from color strings to ensure proper parsing
const cleanFrom = stripCssComments(from);
const cleanTo = stripCssComments(to);
const c0 = helpersColor(cleanFrom || transparent);
const c1 = c0.valid && helpersColor(cleanTo || transparent);
return c1 && c1.valid
? c1.mix(c0, factor).hexString()
: to;
Expand Down