Skip to content

🎥 Make videos programmatically with React

nice

JonnyBurger04b7c2d1cfc7
diff --git a/packages/convert/app/components/MediaPlayer.tsx b/packages/convert/app/components/MediaPlayer.tsx
index 97e308fe2e..1fbf268a3c 100644
--- a/packages/convert/app/components/MediaPlayer.tsx
+++ b/packages/convert/app/components/MediaPlayer.tsx
@@ -104,8 +104,8 @@ export function VideoPlayer({
>
<div
className={cn(
- 'border-2',
- crop ? null : 'rounded-md',
+ crop ? 'border-0' : 'border-2',
+ 'rounded-md',
crop ? 'border-transparent' : 'border-black',
'overflow-hidden',
)}
diff --git a/packages/convert/app/components/Page.tsx b/packages/convert/app/components/Page.tsx
index eb0e18cd7a..a1041ae83b 100644
--- a/packages/convert/app/components/Page.tsx
+++ b/packages/convert/app/components/Page.tsx
@@ -1,12 +1,15 @@
import clsx from 'clsx';
import React from 'react';
+export const pageRef = React.createRef<HTMLDivElement>();
+
export const Page: React.FC<{
readonly children: React.ReactNode;
readonly className?: string;
}> = ({children, className}) => {
return (
<div
+ ref={pageRef}
className={clsx(
'overflow-y-auto w-full bg-slate-50 min-h-screen',
className,
diff --git a/packages/convert/app/components/crop-ui/Backdrop.tsx b/packages/convert/app/components/crop-ui/Backdrop.tsx
index e713c85e95..424b1d9f67 100644
--- a/packages/convert/app/components/crop-ui/Backdrop.tsx
+++ b/packages/convert/app/components/crop-ui/Backdrop.tsx
@@ -79,7 +79,10 @@ export const CropBackdrop: React.FC<{
];
const d2 = serializeInstructions(path2);
return (
- <svg viewBox={`0 0 ${dimensions.width} ${dimensions.height}`}>
+ <svg
+ viewBox={`0 0 ${dimensions.width} ${dimensions.height}`}
+ className="rounded-md"
+ >
<path d={d1} fill="black" strokeWidth={10} opacity={0.5} />
<path d={d2} fill="black" strokeWidth={10} opacity={0.5} />
</svg>
diff --git a/packages/convert/app/components/crop-ui/DragHandle.tsx b/packages/convert/app/components/crop-ui/DragHandle.tsx
index 085211efed..95f47ba76f 100644
--- a/packages/convert/app/components/crop-ui/DragHandle.tsx
+++ b/packages/convert/app/components/crop-ui/DragHandle.tsx
@@ -5,6 +5,7 @@ import {
forceSpecificCursor,
stopForcingSpecificCursor,
} from './force-specific-cursor';
+import {preventBodyScroll} from './prevent-body-scroll';
const clamp = (val: number, min: number, max: number) => {
return Math.min(Math.max(val, min), max);
@@ -39,6 +40,8 @@ export const DragHandle: React.FC<{
forceSpecificCursor('move');
setMarkAsDragging(true);
+ const restoreBody = preventBodyScroll();
+
const boxOffset = divRef.current?.getBoundingClientRect()!;
const factor = boxOffset.width / dimensions.width;
@@ -87,6 +90,7 @@ export const DragHandle: React.FC<{
stopForcingSpecificCursor();
setMarkAsDragging(false);
+ restoreBody();
window.removeEventListener('pointermove', onPointerMove);
window.removeEventListener('pointerup', onPointerUp);
@@ -108,6 +112,7 @@ export const DragHandle: React.FC<{
return (
<div
style={style}
+ className="touch-none"
onPointerDown={onPointerDown}
// No visible styling - invisible hit area
/>
diff --git a/packages/convert/app/components/crop-ui/EdgeHandle.tsx b/packages/convert/app/components/crop-ui/EdgeHandle.tsx
index 03dfa65e56..be277adef9 100644
--- a/packages/convert/app/components/crop-ui/EdgeHandle.tsx
+++ b/packages/convert/app/components/crop-ui/EdgeHandle.tsx
@@ -5,6 +5,7 @@ import {
forceSpecificCursor,
stopForcingSpecificCursor,
} from './force-specific-cursor';
+import {preventBodyScroll} from './prevent-body-scroll';
type EdgePosition = 'top' | 'right' | 'bottom' | 'left';
@@ -108,6 +109,9 @@ export const EdgeHandle: React.FC<{
forceSpecificCursor(getCursor(position));
setMarkAsDragging(true);
+ // Prevent body scrolling
+ const restoreBody = preventBodyScroll();
+
const move = (evt: PointerEvent) => {
evt.preventDefault();
evt.stopPropagation();
@@ -182,6 +186,9 @@ export const EdgeHandle: React.FC<{
stopForcingSpecificCursor();
setMarkAsDragging(false);
+ // Restore body scroll
+ restoreBody();
+
window.removeEventListener('pointermove', onPointerMove);
window.removeEventListener('pointerup', onPointerUp);
};
@@ -200,10 +207,6 @@ export const EdgeHandle: React.FC<{
);
return (
- <div
- style={style}
- onPointerDown={onPointerDown}
- // No visible styling - invisible hit area
- />
+ <div style={style} className="touch-none" onPointerDown={onPointerDown} />
);
};
diff --git a/packages/convert/app/components/crop-ui/ResizeHandle.tsx b/packages/convert/app/components/crop-ui/ResizeHandle.tsx
index 53033f97e5..b0d6e29d0f 100644
--- a/packages/convert/app/components/crop-ui/ResizeHandle.tsx
+++ b/packages/convert/app/components/crop-ui/ResizeHandle.tsx
@@ -5,6 +5,7 @@ import {
forceSpecificCursor,
stopForcingSpecificCursor,
} from './force-specific-cursor';
+import {preventBodyScroll} from './prevent-body-scroll';
const baseStyle: React.CSSProperties = {
width: 12,
@@ -111,14 +112,16 @@ export const ResizeHandle: React.FC<{
const onPointerDown = useCallback(
(e: React.PointerEvent) => {
- e.preventDefault();
- e.stopPropagation();
if (e.button !== 0) {
return;
}
+ e.preventDefault();
+ e.stopPropagation();
+
forceSpecificCursor(getCursor(position));
setMarkAsDragging(true);
+ const restoreBody = preventBodyScroll();
const move = (evt: PointerEvent) => {
evt.preventDefault();
@@ -210,6 +213,7 @@ export const ResizeHandle: React.FC<{
stopForcingSpecificCursor();
setMarkAsDragging(false);
+ restoreBody();
window.removeEventListener('pointermove', onPointerMove);
window.removeEventListener('pointerup', onPointerUp);
@@ -230,7 +234,7 @@ export const ResizeHandle: React.FC<{
return (
<div
- className="w-4 h-4 bg-white absolute rounded-full border-2 border-black"
+ className="w-4 h-4 select-none touch-none bg-white absolute rounded-full border-2 border-black"
style={style}
onPointerDown={onPointerDown}
/>
diff --git a/packages/convert/app/components/crop-ui/VerticalPositionIndicator.tsx b/packages/convert/app/components/crop-ui/VerticalPositionIndicator.tsx
index 7cb457dcfe..bc8e3d56a0 100644
--- a/packages/convert/app/components/crop-ui/VerticalPositionIndicator.tsx
+++ b/packages/convert/app/components/crop-ui/VerticalPositionIndicator.tsx
@@ -8,7 +8,7 @@ export const VerticalPositionIndicator: React.FC<{
}> = ({xPosition, width, isDragging}) => {
return (
<div
- className="absolute font-brand text-sm text-gray-500 transition-opacity"
+ className="absolute hidden lg:block font-brand text-sm text-gray-500 transition-opacity"
style={{
left: `${(xPosition / width) * 100}%`,
top: -25,
@@ -31,7 +31,7 @@ export const HorizontalPositionIndicator: React.FC<{
}> = ({yPosition, height, isDragging}) => {
return (
<div
- className="absolute font-brand text-sm text-gray-500 pr-2 transition-opacity"
+ className="absolute hidden lg:block font-brand text-sm text-gray-500 pr-2 transition-opacity"
style={{
top: `${(yPosition / height) * 100}%`,
left: -INDICATOR_HEIGHT,
diff --git a/packages/convert/app/components/crop-ui/prevent-body-scroll.ts b/packages/convert/app/components/crop-ui/prevent-body-scroll.ts
new file mode 100644
index 0000000000..1cc3984c4c
--- /dev/null
+++ b/packages/convert/app/components/crop-ui/prevent-body-scroll.ts
@@ -0,0 +1,17 @@
+import {pageRef} from '../Page';
+
+export function preventBodyScroll() {
+ const {overflow} = document.body.style;
+ if (!pageRef.current) {
+ throw new Error('Page ref not found');
+ }
+
+ const pageElement = pageRef.current;
+
+ document.body.style.overflow = 'hidden';
+ pageElement.style.overflow = 'hidden';
+ return () => {
+ document.body.style.overflow = overflow;
+ pageElement.style.overflow = overflow;
+ };
+}