Skip to content

🎥 Make videos programmatically with React

`@remotion/web-renderer`: Fix bad interpretation of transforms

JonnyBurgerc1756e6d1e59
diff --git a/packages/web-renderer/src/drawing/calculate-transforms.ts b/packages/web-renderer/src/drawing/calculate-transforms.ts
index 1afaf986b3..b7e18374fe 100644
--- a/packages/web-renderer/src/drawing/calculate-transforms.ts
+++ b/packages/web-renderer/src/drawing/calculate-transforms.ts
@@ -1,3 +1,4 @@
+import {hasAnyTransformCssValue, hasTransformCssValue} from './has-transform';
import {parseTransformOrigin} from './parse-transform-origin';
type Transform = {
@@ -49,14 +50,10 @@ export const calculateTransforms = (element: HTMLElement | SVGElement) => {
elementComputedStyle = computedStyle;
}
- if (
- (computedStyle.transform && computedStyle.transform !== 'none') ||
- parent === element
- ) {
- const toParse =
- computedStyle.transform === 'none' || computedStyle.transform === ''
- ? undefined
- : computedStyle.transform;
+ if (hasAnyTransformCssValue(computedStyle) || parent === element) {
+ const toParse = !hasTransformCssValue(computedStyle)
+ ? computedStyle.transform
+ : undefined;
const matrix = new DOMMatrix(toParse);
const {transform, scale, rotate} = parent.style;
diff --git a/packages/web-renderer/src/drawing/has-transform.ts b/packages/web-renderer/src/drawing/has-transform.ts
new file mode 100644
index 0000000000..fbdadbb982
--- /dev/null
+++ b/packages/web-renderer/src/drawing/has-transform.ts
@@ -0,0 +1,19 @@
+export const hasTransformCssValue = (style: CSSStyleDeclaration) => {
+ return style.transform !== 'none' && style.transform !== '';
+};
+
+export const hasRotateCssValue = (style: CSSStyleDeclaration) => {
+ return style.rotate !== 'none' && style.rotate !== '';
+};
+
+export const hasScaleCssValue = (style: CSSStyleDeclaration) => {
+ return style.scale !== 'none' && style.scale !== '';
+};
+
+export const hasAnyTransformCssValue = (style: CSSStyleDeclaration) => {
+ return (
+ hasTransformCssValue(style) ||
+ hasRotateCssValue(style) ||
+ hasScaleCssValue(style)
+ );
+};