Skip to content

🎥 Make videos programmatically with React

cooool

Jonny Burgerf66fa4abf567
diff --git a/packages/docs/src/components/DoMoreHero/fix-z.ts b/packages/docs/src/components/DoMoreHero/fix-z.ts
index e468b97f4a..2efdef06db 100644
--- a/packages/docs/src/components/DoMoreHero/fix-z.ts
+++ b/packages/docs/src/components/DoMoreHero/fix-z.ts
@@ -36,12 +36,6 @@ export const turnInto3D = (
cp1: [instruction.cp1x, instruction.cp1y, 0, 1],
cp2: [instruction.cp2x, instruction.cp2y, 0, 1],
});
- } else if (instruction.type === "Q") {
- newInstructions.push({
- type: "Q",
- cp: [instruction.cpx, instruction.cpy, 0, 1],
- point: [instruction.x, instruction.y, 0, 1],
- });
} else {
throw new Error("unknown");
}
diff --git a/packages/paths/src/get-bounding-box.ts b/packages/paths/src/get-bounding-box.ts
index b16b7eb925..b6f3e3ad92 100644
--- a/packages/paths/src/get-bounding-box.ts
+++ b/packages/paths/src/get-bounding-box.ts
@@ -175,31 +175,6 @@ export const getBoundingBoxFromInstructions = (
break;
}
- case 'Q': {
- const qxMinMax = minmaxQ([x, seg.cpx, seg.x]);
- if (minX > qxMinMax[0]) {
- minX = qxMinMax[0];
- }
-
- if (maxX < qxMinMax[1]) {
- maxX = qxMinMax[1];
- }
-
- const qyMinMax = minmaxQ([y, seg.cpy, seg.y]);
- if (minY > qyMinMax[0]) {
- minY = qyMinMax[0];
- }
-
- if (maxY < qyMinMax[1]) {
- maxY = qyMinMax[1];
- }
-
- x = seg.x;
- y = seg.y;
-
- break;
- }
-
case 'Z':
x = lastMoveX;
y = lastMoveY;
diff --git a/packages/paths/src/interpolate-path/convert-to-same-instruction-type.ts b/packages/paths/src/interpolate-path/convert-to-same-instruction-type.ts
index 5c59bfb6a7..c462e54c0b 100644
--- a/packages/paths/src/interpolate-path/convert-to-same-instruction-type.ts
+++ b/packages/paths/src/interpolate-path/convert-to-same-instruction-type.ts
@@ -2,7 +2,6 @@ import type {
CInstruction,
LInstruction,
Point,
- QInstruction,
ReducedInstruction,
} from '../helpers/types';
@@ -38,49 +37,9 @@ const convertToCCommand = (
};
}
- if (command.type === 'Q') {
- return {
- type: 'C',
- cp1x: command.cpx,
- cp1y: command.cpy,
- cp2x: command.cpx,
- cp2y: command.cpy,
- x: command.x,
- y: command.y,
- };
- }
-
throw new Error('all types should be handled');
};
-const convertToQCommand = (command: ReducedInstruction): QInstruction => {
- if (command.type === 'M' || command.type === 'Q' || command.type === 'Z') {
- throw new Error('unexpected');
- }
-
- if (command.type === 'C') {
- return {
- type: 'Q',
- cpx: command.cp1x,
- cpy: command.cp1y,
- x: command.x,
- y: command.y,
- };
- }
-
- if (command.type === 'L') {
- return {
- type: 'Q',
- cpx: command.x,
- cpy: command.y,
- x: command.x,
- y: command.y,
- };
- }
-
- throw new Error('unhandled');
-};
-
/**
* Converts command A to have the same type as command B.
*
@@ -122,10 +81,6 @@ export function convertToSameInstructionType(
return convertToLCommand(aCommand);
}
- if (bCommand.type === 'Q') {
- return convertToQCommand(aCommand);
- }
-
if (bCommand.type === 'Z') {
return {
type: 'Z',
diff --git a/packages/paths/src/interpolate-path/interpolate-instruction-of-same-kind.ts b/packages/paths/src/interpolate-path/interpolate-instruction-of-same-kind.ts
index 0d5dccae35..da877c1c37 100644
--- a/packages/paths/src/interpolate-path/interpolate-instruction-of-same-kind.ts
+++ b/packages/paths/src/interpolate-path/interpolate-instruction-of-same-kind.ts
@@ -2,7 +2,6 @@ import type {
CInstruction,
LInstruction,
MInstruction,
- QInstruction,
ReducedInstruction,
ZInstruction,
} from '../helpers/types';
@@ -35,20 +34,6 @@ const interpolateCInstructions = (
};
};
-const interpolateQInstructions = (
- t: number,
- first: QInstruction,
- second: QInstruction,
-): QInstruction => {
- return {
- type: 'Q',
- cpx: (1 - t) * first.cpx + t * second.cpx,
- cpy: (1 - t) * first.cpy + t * second.cpy,
- x: (1 - t) * first.x + t * second.x,
- y: (1 - t) * first.y + t * second.y,
- };
-};
-
const interpolateMInstructions = (
t: number,
first: MInstruction,
@@ -82,14 +67,6 @@ export const interpolateInstructionOfSameKind = (
return interpolateCInstructions(t, first, second);
}
- if (first.type === 'Q') {
- if (second.type !== 'Q') {
- throw new Error('mismatch');
- }
-
- return interpolateQInstructions(t, first, second);
- }
-
if (first.type === 'M') {
if (second.type !== 'M') {
throw new Error('mismatch');
diff --git a/packages/paths/src/interpolate-path/points-to-command.ts b/packages/paths/src/interpolate-path/points-to-command.ts
index a8e7988942..9eda679fd2 100644
--- a/packages/paths/src/interpolate-path/points-to-command.ts
+++ b/packages/paths/src/interpolate-path/points-to-command.ts
@@ -1,3 +1,4 @@
+import {convertQToCInstruction} from '../helpers/convert-q-to-c-instruction';
import type {ReducedInstruction} from '../helpers/types';
/**
@@ -32,13 +33,19 @@ export function pointsToInstruction(points: number[][]): ReducedInstruction {
const x1 = points[1][0];
const y1 = points[1][1];
- return {
- type: 'Q',
- cpx: x1,
- cpy: y1,
- x,
- y,
- };
+ return convertQToCInstruction(
+ {
+ type: 'Q',
+ cpx: x1,
+ cpy: y1,
+ x,
+ y,
+ },
+ {
+ x: points[0][0],
+ y: points[0][1],
+ },
+ );
}
return {
diff --git a/packages/paths/src/interpolate-path/split-segment.ts b/packages/paths/src/interpolate-path/split-segment.ts
index 90d248cd43..4312d69e19 100644
--- a/packages/paths/src/interpolate-path/split-segment.ts
+++ b/packages/paths/src/interpolate-path/split-segment.ts
@@ -22,11 +22,7 @@ export function splitSegmentInstructions(
let segments: ReducedInstruction[] = [];
// line, quadratic bezier, or cubic bezier
- if (
- commandEnd.type === 'L' ||
- commandEnd.type === 'Q' ||
- commandEnd.type === 'C'
- ) {
+ if (commandEnd.type === 'L' || commandEnd.type === 'C') {
if (commandStart.type !== 'Z') {
segments = segments.concat(
splitCurveInstructions(
diff --git a/packages/paths/src/warp-path/warp-helpers.ts b/packages/paths/src/warp-path/warp-helpers.ts
index 813a6f05c1..a0d93e5bb1 100644
--- a/packages/paths/src/warp-path/warp-helpers.ts
+++ b/packages/paths/src/warp-path/warp-helpers.ts
@@ -1,3 +1,4 @@
+import {convertQToCInstruction} from '../helpers/convert-q-to-c-instruction';
import type {ReducedInstruction} from '../helpers/types';
export type WarpPathFn = (point: {x: number; y: number}) => {
@@ -90,13 +91,19 @@ function createLineSegment(points: number[][]): ReducedInstruction {
};
case 3:
- return {
- type: 'Q',
- cpx: points[1][0],
- cpy: points[1][1],
- x: points[2][0],
- y: points[2][1],
- };
+ return convertQToCInstruction(
+ {
+ type: 'Q',
+ cpx: points[1][0],
+ cpy: points[1][1],
+ x: points[2][0],
+ y: points[2][1],
+ },
+ {
+ x: points[0][0],
+ y: points[0][1],
+ },
+ );
case 4:
return {
@@ -142,16 +149,7 @@ function warpInterpolate(
points.push([segment.x, segment.y]);
}
- if (segment.type === 'Q') {
- points.push([segment.cpx, segment.cpy]);
- points.push([segment.x, segment.y]);
- }
-
- if (
- segment.type === 'C' ||
- segment.type === 'Q' ||
- segment.type === 'L'
- ) {
+ if (segment.type === 'C' || segment.type === 'L') {
return interpolateUntil(points, threshold, deltaFunction).map(
(rawSegment) => createLineSegment(rawSegment),
);
@@ -202,23 +200,6 @@ export const warpTransform = (
];
}
- if (segment.type === 'Q') {
- const {x, y} = transformer({x: segment.x, y: segment.y});
- const {x: cpx, y: cpy} = transformer({
- x: segment.cpx,
- y: segment.cpy,
- });
- return [
- {
- type: 'Q',
- x,
- y,
- cpx,
- cpy,
- },
- ];
- }
-
if (segment.type === 'C') {
const {x, y} = transformer({x: segment.x, y: segment.y});
const {x: cp1x, y: cp1y} = transformer({