Skip to content

🎥 Make videos programmatically with React

add support for negative number with units

ChetanKarwa912763b139da
diff --git a/packages/animation-utils/src/transformation-helpers/interpolate-styles/utils.ts b/packages/animation-utils/src/transformation-helpers/interpolate-styles/utils.ts
index 651bfdccb7..d211dd916a 100644
--- a/packages/animation-utils/src/transformation-helpers/interpolate-styles/utils.ts
+++ b/packages/animation-utils/src/transformation-helpers/interpolate-styles/utils.ts
@@ -143,16 +143,16 @@ const classifyParts = (parts: string[]) => {
return {function: {name: functionName, values: functionValues}};
}
- // Check for a number possibly followed by a unit
- const numberUnitMatch = part.match(/^(\d+(?:\.\d+)?)([a-zA-Z%]*)$/);
+ // Check for a number possibly followed by a unit like '10px' or '10' or '-10px'
+ const numberUnitMatch = part.match(/^(-?\d+(?:\.\d+)?)([a-zA-Z%]*)$/);
if (numberUnitMatch) {
const number = parseFloat(numberUnitMatch[1]);
const unit = numberUnitMatch[2];
return unit ? {number, unit} : {number};
}
- // Check for a number without a unit
- const numberMatch = part.match(/^(\d+(?:\.\d+)?)$/);
+ // Check for a number without a unit like '10' or '-10
+ const numberMatch = part.match(/^(-?\d+(?:\.\d+)?)$/);
if (numberMatch) {
const number = parseFloat(numberMatch[1]);
return {number};