Skip to content

🎥 Make videos programmatically with React

fix stuff

Jonny Burger55e06b3df9a1
diff --git a/packages/svg-3d-engine/package.json b/packages/svg-3d-engine/package.json
index c2dd60426e..73ba2ce9a6 100644
--- a/packages/svg-3d-engine/package.json
+++ b/packages/svg-3d-engine/package.json
@@ -3,7 +3,10 @@
"dependencies": {
"@remotion/paths": "workspace:*"
},
- "devDependencies": {},
+ "devDependencies": {
+ "@remotion/eslint-config-internal": "workspace:*",
+ "eslint": "9.14.0"
+ },
"main": "dist/cjs/index.js",
"types": "dist/cjs/index.d.ts",
"module": "dist/esm/index.mjs",
diff --git a/packages/svg-3d-engine/src/3d-svg.ts b/packages/svg-3d-engine/src/3d-svg.ts
index b7a538e0b3..0aa9bc893e 100644
--- a/packages/svg-3d-engine/src/3d-svg.ts
+++ b/packages/svg-3d-engine/src/3d-svg.ts
@@ -1,4 +1,4 @@
-import {Vector4D} from './matrix';
+import type {Vector4D} from './matrix';
export type ThreeDReducedInstruction =
| {
@@ -31,18 +31,23 @@ const serializeThreeDReducedInstruction = (
if (instruction.type === 'M') {
return `M ${instruction.point[0]} ${instruction.point[1]}`;
}
+
if (instruction.type === 'L') {
return `L ${instruction.point[0]} ${instruction.point[1]}`;
}
+
if (instruction.type === 'C') {
return `C ${instruction.cp1[0]} ${instruction.cp1[1]} ${instruction.cp2[0]} ${instruction.cp2[1]} ${instruction.point[0]} ${instruction.point[1]}`;
}
+
if (instruction.type === 'Q') {
return `Q ${instruction.cp[0]} ${instruction.cp[1]} ${instruction.point[0]} ${instruction.point[1]}`;
}
+
if (instruction.type === 'Z') {
return 'Z';
}
+
throw new Error('Unknown instruction type');
};
diff --git a/packages/svg-3d-engine/src/elements.ts b/packages/svg-3d-engine/src/elements.ts
index df27167227..95fd47111a 100644
--- a/packages/svg-3d-engine/src/elements.ts
+++ b/packages/svg-3d-engine/src/elements.ts
@@ -1,13 +1,8 @@
import {makeId} from './make-id';
-import {FaceType, transformFace} from './map-face';
-import {
- MatrixTransform4D,
- multiplyMatrix,
- translateX,
- translateY,
- translateZ,
- Vector4D,
-} from './matrix';
+import type {FaceType} from './map-face';
+import {transformFace} from './map-face';
+import type {MatrixTransform4D, Vector4D} from './matrix';
+import {multiplyMatrix, translateX, translateY, translateZ} from './matrix';
export type ThreeDElement = {
faces: FaceType[];
diff --git a/packages/svg-3d-engine/src/extrude-element.ts b/packages/svg-3d-engine/src/extrude-element.ts
index 935ce20a52..faf9d7c453 100644
--- a/packages/svg-3d-engine/src/extrude-element.ts
+++ b/packages/svg-3d-engine/src/extrude-element.ts
@@ -1,12 +1,61 @@
-import {Instruction, PathInternals, reduceInstructions} from '@remotion/paths';
-import {ThreeDReducedInstruction} from './3d-svg';
-import {makeElement, ThreeDElement} from './elements';
+import type {Instruction} from '@remotion/paths';
+import {PathInternals, reduceInstructions} from '@remotion/paths';
+import type {ThreeDReducedInstruction} from './3d-svg';
+import type {ThreeDElement} from './elements';
+import {makeElement} from './elements';
import {turnInto3D} from './fix-z';
-import {FaceType, transformFace, translateSvgInstruction} from './map-face';
-import {translateZ, Vector4D} from './matrix';
+import type {FaceType} from './map-face';
+import {transformFace, translateSvgInstruction} from './map-face';
+import type {Vector4D} from './matrix';
+import {translateZ} from './matrix';
import {subdivideInstructions} from './subdivide-instructions';
import {truthy} from './truthy';
+const inverseInstruction = (
+ instruction: ThreeDReducedInstruction,
+ comingFrom: Vector4D,
+): ThreeDReducedInstruction => {
+ if (instruction.type === 'M') {
+ return {
+ type: 'M',
+ point: comingFrom,
+ };
+ }
+
+ if (instruction.type === 'L') {
+ return {
+ type: 'L',
+ point: comingFrom,
+ };
+ }
+
+ if (instruction.type === 'C') {
+ return {
+ type: 'C',
+ point: comingFrom,
+ cp1: instruction.cp2,
+ cp2: instruction.cp1,
+ };
+ }
+
+ if (instruction.type === 'Q') {
+ return {
+ type: 'Q',
+ point: comingFrom,
+ cp: instruction.cp,
+ };
+ }
+
+ if (instruction.type === 'Z') {
+ return {
+ type: 'L',
+ point: comingFrom,
+ };
+ }
+
+ throw new Error('Unknown instruction type');
+};
+
export const extrudeElement = ({
depth,
sideColor,
@@ -125,43 +174,3 @@ export const extrudeElement = ({
description,
);
};
-
-const inverseInstruction = (
- instruction: ThreeDReducedInstruction,
- comingFrom: Vector4D,
-): ThreeDReducedInstruction => {
- if (instruction.type === 'M') {
- return {
- type: 'M',
- point: comingFrom,
- };
- }
- if (instruction.type === 'L') {
- return {
- type: 'L',
- point: comingFrom,
- };
- }
- if (instruction.type === 'C') {
- return {
- type: 'C',
- point: comingFrom,
- cp1: instruction.cp2,
- cp2: instruction.cp1,
- };
- }
- if (instruction.type === 'Q') {
- return {
- type: 'Q',
- point: comingFrom,
- cp: instruction.cp,
- };
- }
- if (instruction.type === 'Z') {
- return {
- type: 'L',
- point: comingFrom,
- };
- }
- throw new Error('Unknown instruction type');
-};
diff --git a/packages/svg-3d-engine/src/fix-z.ts b/packages/svg-3d-engine/src/fix-z.ts
index 6e5846c911..21c24a2d1e 100644
--- a/packages/svg-3d-engine/src/fix-z.ts
+++ b/packages/svg-3d-engine/src/fix-z.ts
@@ -1,6 +1,7 @@
-import {Instruction, reduceInstructions} from '@remotion/paths';
-import {ThreeDReducedInstruction} from './3d-svg';
-import {Vector4D} from './matrix';
+import type {Instruction} from '@remotion/paths';
+import {reduceInstructions} from '@remotion/paths';
+import type {ThreeDReducedInstruction} from './3d-svg';
+import type {Vector4D} from './matrix';
export const turnInto3D = (
instructions: Instruction[],
diff --git a/packages/svg-3d-engine/src/map-face.ts b/packages/svg-3d-engine/src/map-face.ts
index 9ec460cfcf..c142e59a55 100644
--- a/packages/svg-3d-engine/src/map-face.ts
+++ b/packages/svg-3d-engine/src/map-face.ts
@@ -1,13 +1,10 @@
import {parsePath} from '@remotion/paths';
-import {ThreeDReducedInstruction} from './3d-svg';
-import {ThreeDElement, transformElement} from './elements';
+import type {ThreeDReducedInstruction} from './3d-svg';
+import type {ThreeDElement} from './elements';
+import {transformElement} from './elements';
import {turnInto3D} from './fix-z';
-import {
- MatrixTransform4D,
- multiplyMatrix,
- multiplyMatrixAndSvgInstruction,
- Vector4D,
-} from './matrix';
+import type {MatrixTransform4D, Vector4D} from './matrix';
+import {multiplyMatrix, multiplyMatrixAndSvgInstruction} from './matrix';
export type FaceType = {
color: string;
@@ -36,6 +33,7 @@ export const translateSvgInstruction = (
],
};
}
+
if (instruction.type === 'L') {
return {
type: 'L',
@@ -47,6 +45,7 @@ export const translateSvgInstruction = (
],
};
}
+
if (instruction.type === 'C') {
return {
type: 'C',
@@ -70,6 +69,7 @@ export const translateSvgInstruction = (
],
};
}
+
if (instruction.type === 'Q') {
return {
type: 'Q',
@@ -87,6 +87,7 @@ export const translateSvgInstruction = (
],
};
}
+
if (instruction.type === 'Z') {
return {
type: 'Z',
@@ -98,6 +99,7 @@ export const translateSvgInstruction = (
],
};
}
+
throw new Error('Unknown instruction type: ' + JSON.stringify(instruction));
};
diff --git a/packages/svg-3d-engine/src/matrix.ts b/packages/svg-3d-engine/src/matrix.ts
index 17e846caa0..5ac8dadbe7 100644
--- a/packages/svg-3d-engine/src/matrix.ts
+++ b/packages/svg-3d-engine/src/matrix.ts
@@ -1,8 +1,5 @@
-import {ThreeDReducedInstruction} from './3d-svg';
-
-export const translated4d = function (vec: Vector) {
- return stride({v: vec, m: identity4(), width: 4, offset: 3, colStride: 0});
-};
+/* eslint-disable @typescript-eslint/no-use-before-define */
+import type {ThreeDReducedInstruction} from './3d-svg';
export const stride = function ({
v,
@@ -23,6 +20,7 @@ export const stride = function ({
((i * colStride + offset + width) % width) // Row
] = v[i];
}
+
return m;
};
@@ -33,6 +31,7 @@ export const identity4 = function (): MatrixTransform4D {
while (size--) {
m[size] = size % (n + 1) === 0 ? 1.0 : 0.0;
}
+
return m;
};
@@ -51,12 +50,14 @@ function multiplyMany(
if (listOfMatrices.length < 2) {
throw new Error('multiplication expected two or more matrices');
}
+
let result = mul(listOfMatrices[0], listOfMatrices[1], size);
let next = 2;
while (next < listOfMatrices.length) {
result = mul(result, listOfMatrices[next], size);
next++;
}
+
return result as MatrixTransform4D;
}
@@ -66,6 +67,7 @@ function mul(m1: number[], m2: number[], size: number): number[] {
`Undefined for matrices of different sizes. m1.length=${m1.length}, m2.length=${m2.length}`,
);
}
+
if (size * size !== m1.length) {
throw new Error(
`Undefined for non-square matrices. array size was ${size}`,
@@ -80,9 +82,11 @@ function mul(m1: number[], m2: number[], size: number): number[] {
for (let k = 0; k < size; k++) {
acc += m1[size * r + k] * m2[size * k + c];
}
+
result[r * size + c] = acc;
}
}
+
return result;
}
@@ -101,9 +105,15 @@ const rotated = function (axisVec: Vector, radians: number): MatrixTransform4D {
export const rotateX = (radians: number) => {
return rotated([1, 0, 0], radians);
};
+
export const rotateY = (radians: number) => {
return rotated([0, 1, 0], radians);
};
+
+export const translated4d = function (vec: Vector) {
+ return stride({v: vec, m: identity4(), width: 4, offset: 3, colStride: 0});
+};
+
export const rotateZ = (radians: number) => {
return rotated([0, 0, 1], radians);
};
@@ -178,12 +188,14 @@ const vectorLength = function (v: number[]) {
const lengthSquared = function (v: number[]) {
return dot(v, v);
};
+
export const dot = function (a: number[], b: number[]) {
if (a.length !== b.length) {
throw new Error(
`Cannot perform dot product on arrays of different length (${a.length} vs ${b.length})`,
);
}
+
return a
.map((v, i) => {
return v * b[i];
@@ -242,6 +254,7 @@ export function multiplyMatrixAndSvgInstruction(
point: multiplyMatrix(matrix, point.point),
};
}
+
if (point.type === 'Q') {
return {
type: 'Q',
@@ -249,24 +262,28 @@ export function multiplyMatrixAndSvgInstruction(
point: multiplyMatrix(matrix, point.point),
};
}
+
if (point.type === 'M') {
return {
type: 'M',
point: multiplyMatrix(matrix, point.point),
};
}
+
if (point.type === 'L') {
return {
type: 'L',
point: multiplyMatrix(matrix, point.point),
};
}
+
if (point.type === 'Z') {
return {
type: 'Z',
point: multiplyMatrix(matrix, point.point),
};
}
+
throw new Error('Unknown instruction type: ' + JSON.stringify(point));
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3a3512e057..cfc0b413fa 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2044,6 +2044,13 @@ importers:
'@remotion/paths':
specifier: workspace:*
version: link:../paths
+ devDependencies:
+ '@remotion/eslint-config-internal':
+ specifier: workspace:*
+ version: link:../eslint-config-internal
+ eslint:
+ specifier: 9.14.0
+ version: 9.14.0
packages/tailwind:
dependencies:
diff --git a/tsconfig.json b/tsconfig.json
index 16fbf9d610..f02677abca 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -13,7 +13,8 @@
"resolveJsonModule": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
- "skipLibCheck": true
+ "skipLibCheck": true,
+ "isolatedModules": true
},
"include": [],
"references": [