Skip to content

🎥 Make videos programmatically with React

Update clamp-rect-to-parent-bounds.ts

Jonny Burger3a658503ac88
diff --git a/packages/web-renderer/src/drawing/clamp-rect-to-parent-bounds.ts b/packages/web-renderer/src/drawing/clamp-rect-to-parent-bounds.ts
index 55ccb97701..49c1a7a522 100644
--- a/packages/web-renderer/src/drawing/clamp-rect-to-parent-bounds.ts
+++ b/packages/web-renderer/src/drawing/clamp-rect-to-parent-bounds.ts
@@ -8,7 +8,15 @@ export const clampRectToParentBounds = ({
return new DOMRect(
Math.max(rect.left, parentRect.left),
Math.max(rect.top, parentRect.top),
- Math.min(rect.width, parentRect.width),
- Math.min(rect.height, parentRect.height),
+ Math.max(
+ 0,
+ Math.min(rect.right, parentRect.right) -
+ Math.max(rect.left, parentRect.left),
+ ),
+ Math.max(
+ 0,
+ Math.min(rect.bottom, parentRect.bottom) -
+ Math.max(rect.top, parentRect.top),
+ ),
);
};