Skip to content

🎥 Make videos programmatically with React

join points

Jonny Burger708f38d73183
diff --git a/packages/shapes/src/utils/join-points.ts b/packages/shapes/src/utils/join-points.ts
new file mode 100644
index 0000000000..360ea1cf40
--- /dev/null
+++ b/packages/shapes/src/utils/join-points.ts
@@ -0,0 +1,6 @@
+export const joinPoints = (points: [number, number][]) => {
+ const pointsString = points
+ .map(([x, y], i) => `${i === 0 ? 'M' : 'L'} ${x} ${y}`)
+ .join(' ');
+ return pointsString;
+};
diff --git a/packages/shapes/src/utils/make-rect.ts b/packages/shapes/src/utils/make-rect.ts
index 19efa127d3..fece66a9fb 100644
--- a/packages/shapes/src/utils/make-rect.ts
+++ b/packages/shapes/src/utils/make-rect.ts
@@ -1,3 +1,4 @@
+import {joinPoints} from './join-points';
import type {ShapeInfo} from './shape-info';
export type MakeRectOptions = {
@@ -6,10 +7,17 @@ export type MakeRectOptions = {
};
export const makeRect = ({width, height}: MakeRectOptions): ShapeInfo => {
+ const path = joinPoints([
+ [0, 0],
+ [width, 0],
+ [width, height],
+ [0, height],
+ ]);
+
return {
width,
height,
- path: `M 0 0 l ${width} 0 l 0 ${height} l ${-width} 0 Z`,
+ path,
transformOrigin: `${width / 2} ${height / 2}`,
};
};