🎥 Make videos programmatically with React
square -> rect
Jonny Burger3413b5836bb8
diff --git a/packages/docs/components/TableOfContents/shapes.tsx b/packages/docs/components/TableOfContents/shapes.tsxindex b0a14e0058..97e7d14789 100644--- a/packages/docs/components/TableOfContents/shapes.tsx+++ b/packages/docs/components/TableOfContents/shapes.tsx@@ -10,11 +10,11 @@ export const TableOfContents: React.FC = () => {<strong>makeCircle()</strong><div>Generate circle path</div></TOCItem>- <TOCItem link="/docs/shapes/make-square">- <strong>makeSquare()</strong>+ <TOCItem link="/docs/shapes/make-rect">+ <strong>makeRect()</strong><div>Generate circle path</div></TOCItem>- <TOCItem link="/docs/shapes/make-square">+ <TOCItem link="/docs/shapes/make-triangle"><strong>makeTriangle()</strong><div>Generate triangle path</div></TOCItem>@@ -22,9 +22,9 @@ export const TableOfContents: React.FC = () => {<strong>{`<Circle/>`}</strong><div>Generates Circle SVG</div></TOCItem>- <TOCItem link="/docs/shapes/square">- <strong>{`<Square/>`}</strong>- <div>Generates Square SVG</div>+ <TOCItem link="/docs/shapes/rect">+ <strong>{`<Rect/>`}</strong>+ <div>Generates a Rectangle SVG</div></TOCItem><TOCItem link="/docs/shapes/triangle"><strong>{`<Triangle/>`}</strong>diff --git a/packages/docs/docs/shapes/make-circle.md b/packages/docs/docs/shapes/make-circle.mdindex d13692606b..78f1c43e6f 100644--- a/packages/docs/docs/shapes/make-circle.md+++ b/packages/docs/docs/shapes/make-circle.md@@ -8,30 +8,28 @@ _Part of the [` @remotion/shapes`](/docs/shapes) package._Generates Circle SVG path-## Arguments### `options`+An object with the following arguments:- `cx`: `number` - The x axis coordinate of the center of the circle- `cy`: `number` - The y axis coordinate of the center of the circle- `radius`: `number` - The radius of the circle. A value lower or equal to zero disables rendering of the circle-Example Circle path generation```tsx twoslashimport { makeCircle } from "@remotion/shapes";-const circlePath = makeCircle({cx : 50, cy : 50, radius : 50});+const circlePath = makeCircle({ cx: 50, cy: 50, radius: 50 });console.log(circlePath); // M 50 50 m -50, 0 a 50,50 0 1,0 100,0 50,50 0 1,0 -100,0-```-## See also+- [makeTriangle()](/docs/shapes/make-triangle)-- [makeSquare()](/docs/shapes/make-square)+- [makeRect()](/docs/shapes/make-rect)- [`@remotion/shapes`](/docs/shapes)- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/shapes/src/make-triangle.ts)diff --git a/packages/docs/docs/shapes/make-square.md b/packages/docs/docs/shapes/make-square.mdindex 3d070ad22b..d4afe59807 100644--- a/packages/docs/docs/shapes/make-square.md+++ b/packages/docs/docs/shapes/make-square.md@@ -1,39 +1,46 @@----image: /generated/articles-docs-shapes-make-square.png-title: makeSquare()+title: makeRect()crumb: "@remotion/shapes"---_Part of the [` @remotion/shapes`](/docs/shapes) package._--Generates Square SVG path+Generates an SVG path for a rectangle## Arguments-### `options`+An object with the following entries:-An object with the following arguments:+### `x`-- `x`: `number` `defaults: 50`- The x axis coordinate to start drawing the square-- `y`: `number` `defaults: 50` - The y axis coordinate to start drawing the square-- `size`: `number` - The size of the square inside the path+_`number`, optional_+The x-axis coordinate to start drawing the rect. Defaults to `0`.-Example Square path generation+### `y`-```tsx twoslash-import { makeSquare } from "@remotion/shapes";-const square = makeSquare({x : 50, y : 50, size : 100});+_`number`, optional_-console.log(square); // M 50, 50 l 100, 0 l 0, 100 l -100, 0 Z+The y-axis coordinate to start drawing the rect. Defaults to `0`.-```+### `width`++The width of the rectangle++### `height`+The height of the rectangle++```tsx twoslash+import { makeRect } from "@remotion/shapes";+const rect = makeRect({ x: 50, y: 50, width: 100, height: 100 });++console.log(rect); // M 50 50 l 100 0 l 0 100 l -100 0 Z+```## See also- [makeTriangle()](/docs/shapes/make-triangle)- [makeCircle()](/docs/shapes/make-circle)- [`@remotion/shapes`](/docs/shapes)-- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/shapes/src/make-square.ts)+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/shapes/src/make-rect.ts)diff --git a/packages/docs/docs/shapes/make-triangle.md b/packages/docs/docs/shapes/make-triangle.mdindex e78a60dd30..9534b7869e 100644--- a/packages/docs/docs/shapes/make-triangle.md+++ b/packages/docs/docs/shapes/make-triangle.md@@ -6,7 +6,6 @@ crumb: "@remotion/shapes"_Part of the [` @remotion/shapes`](/docs/shapes) package._-Generates Triangle SVG path## Arguments@@ -15,24 +14,23 @@ Generates Triangle SVG pathAn object with the following arguments:-- `width`: `number` - The width of the triangle- `height`: `number` - The height of the triangle.-- `direction`: `string` - The identifier what kind of rectangle, possible values `left`, `right`, `top` and `bottom`-+- `direction`: `string` - The identifier what kind of rectangle, possible values `left`, `right`, `top` and `bottom`Example Triangle path generation```tsx twoslashimport { makeTriangle } from "@remotion/shapes";-const rightTriangle = makeTriangle({width : 100, height : 100, direction : 'right'});+const rightTriangle = makeTriangle({+ width: 100,+ height: 100,+ direction: "right",+});console.log(rightTriangle); // M 0,0 L 0,100 L 100,50 z-```--## CreditsSource code stems mostly from [triangle](https://stackblitz.com/edit/react-triangle-svg?file=index.js).@@ -40,6 +38,6 @@ Source code stems mostly from [triangle](https://stackblitz.com/edit/react-trian## See also- [makeCircle()](/docs/shapes/make-circle)-- [makeSquare()](/docs/shapes/make-square)+- [makeRect()](/docs/shapes/make-rect)- [`@remotion/shapes`](/docs/shapes)- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/shapes/src/make-triangle.ts)diff --git a/packages/docs/docs/shapes/square.md b/packages/docs/docs/shapes/square.mdindex 351f214604..bcdfa6adb0 100644--- a/packages/docs/docs/shapes/square.md+++ b/packages/docs/docs/shapes/square.md@@ -1,12 +1,11 @@----image: /generated/articles-docs-shapes-square.png-title: <Square />+title: <Rect />crumb: "@remotion/shapes"---_Part of the [` @remotion/shapes`](/docs/shapes) package._-Generate Square SVG component+Generate a rectangle using SVG## Props@@ -34,10 +33,9 @@ _`React.CSSProperties`, optional_CSS styles applied to `svg` element.-Example Square SVG+## Example```tsx twoslash-import { Square } from "@remotion/shapes";import { AbsoluteFill } from "remotion";export const MyComposition = () => {@@ -49,7 +47,7 @@ export const MyComposition = () => {alignItems: "center",}}>- <Square width={200} height={200} fill="red" />+ <Rect width={200} height={200} fill="red" /></AbsoluteFill>);};@@ -58,6 +56,6 @@ export const MyComposition = () => {## See also- [makeTriangle()](/docs/shapes/make-triangle)-- [makeSquare()](/docs/shapes/make-square)+- [makeRect()](/docs/shapes/make-rect)- [`@remotion/shapes`](/docs/shapes)-- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/shapes/src/square.tsx)+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/shapes/src/rect.tsx)diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex e00f2a561c..2f297e4c8a 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -295,9 +295,9 @@ module.exports = {},items: ["shapes/make-circle",- "shapes/make-square",+ "shapes/make-rect","shapes/make-triangle",- "shapes/square",+ "shapes/rect","shapes/triangle","shapes/circle",],diff --git a/packages/example/src/Shapes/SquareTest.tsx b/packages/example/src/Shapes/RectTest.tsxsimilarity index 61%rename from packages/example/src/Shapes/SquareTest.tsxrename to packages/example/src/Shapes/RectTest.tsxindex 05d6d5fa5f..6154ab7d23 100644--- a/packages/example/src/Shapes/SquareTest.tsx+++ b/packages/example/src/Shapes/RectTest.tsx@@ -1,8 +1,8 @@-import {Square} from '@remotion/shapes';+import {Rect} from '@remotion/shapes';import React from 'react';import {AbsoluteFill} from 'remotion';-const SquareTest: React.FC = () => {+const RectTest: React.FC = () => {return (<AbsoluteFillstyle={{@@ -12,9 +12,9 @@ const SquareTest: React.FC = () => {alignItems: 'center',}}>- <Square width={200} height={400} fill="red" />+ <Rect width={200} height={400} fill="red" /></AbsoluteFill>);};-export default SquareTest;+export default RectTest;diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsxindex 462b1e2ed1..1f5d4ce8c2 100644--- a/packages/example/src/Video.tsx+++ b/packages/example/src/Video.tsx@@ -18,6 +18,9 @@ import {OrbScene} from './Orb';import InfinityVideo from './ReallyLongVideo';import RemoteVideo from './RemoteVideo';import {Scripts} from './Scripts';+import CircleTest from './Shapes/CircleTest';+import RectTest from './Shapes/SquareTest';+import TriangleTest from './Shapes/TriangleTest';import {SkipZeroFrame} from './SkipZeroFrame';import {BaseSpring, SpringWithDuration} from './Spring/base-spring';import {SeriesTesting} from './StaggerTesting';@@ -29,9 +32,6 @@ import {VideoOnCanvas} from './VideoOnCanvas';import {Greenscreen} from './VideoOnCanvas/greenscreen';import {VideoSpeed} from './VideoSpeed';import {VideoTesting} from './VideoTesting';-import CircleTest from './Shapes/CircleTest';-import SquareTest from './Shapes/SquareTest';-import TriangleTest from './Shapes/TriangleTest';if (alias !== 'alias') {throw new Error('should support TS aliases');@@ -569,8 +569,8 @@ export const Index: React.FC = () => {durationInFrames={150}/><Composition- id="square-test"- component={SquareTest}+ id="rect-test"+ component={RectTest}width={1200}height={630}fps={30}diff --git a/packages/shapes/README.md b/packages/shapes/README.mdindex b5a3be4dcf..6f702e705f 100644--- a/packages/shapes/README.md+++ b/packages/shapes/README.md@@ -1,6 +1,6 @@## @remotion/paths-A package providing utility functions for creating shapes with SVG.+A package providing utility functions for creating shapes with SVG.- Functional style APIs- First class Typescript types@@ -11,11 +11,11 @@ No dependencies are needed, meaning this package can be used independently of Re## API-- [`makeSquare()`](https://remotion.dev/docs/shapes/make-squares)+- [`makeRect()`](https://remotion.dev/docs/shapes/make-rect)- [`makeCircle()`](https://remotion.dev/docs/shapes/make-circle)- [`makeTriangle()`](https://remotion.dev/docs/shapes/make-triangle)- [`<Circle />`](https://remotion.dev/docs/shapes/circle)-- [`<Square />`](https://remotion.dev/shapes/shapes/square)+- [`<Rect />`](https://remotion.dev/shapes/shapes/rect)- [`<Triangle />`](https://remotion.dev/shapes/shapes/triangle)## Licensediff --git a/packages/shapes/src/index.ts b/packages/shapes/src/index.tsindex b44e8efd79..12d47096a0 100644--- a/packages/shapes/src/index.ts+++ b/packages/shapes/src/index.ts@@ -1,6 +1,6 @@export {Circle} from './circle';-export {Square} from './square';-export {Triangle} from './triangle';export {makeCircle} from './make-circle';-export {makeSquare} from './make-square';+export {makeRect} from './make-rect';export {makeTriangle} from './make-triangle';+export {Rect} from './rect';+export {Triangle} from './triangle';diff --git a/packages/shapes/src/make-square.ts b/packages/shapes/src/make-rect.tssimilarity index 54%rename from packages/shapes/src/make-square.tsrename to packages/shapes/src/make-rect.tsindex 690580ef15..0446c53799 100644--- a/packages/shapes/src/make-square.ts+++ b/packages/shapes/src/make-rect.ts@@ -1,10 +1,10 @@-export type MakeSquareProps = {+export type MakeRectOptions = {x?: number;y?: number;width: number;height: number;};-export const makeSquare = ({x = 0, y = 0, width, height}: MakeSquareProps) => {+export const makeRect = ({x = 0, y = 0, width, height}: MakeRectOptions) => {return `M ${x} ${y} l ${width} 0 l 0 ${height} l ${-width} 0 Z`;};diff --git a/packages/shapes/src/square.tsx b/packages/shapes/src/rect.tsxsimilarity index 68%rename from packages/shapes/src/square.tsxrename to packages/shapes/src/rect.tsxindex bf0e91a2e9..2e89920f25 100644--- a/packages/shapes/src/square.tsx+++ b/packages/shapes/src/rect.tsx@@ -1,5 +1,5 @@import React from 'react';-import {makeSquare} from './make-square';+import {makeRect} from './make-rect';export type SquareProps = {width: number;@@ -8,7 +8,7 @@ export type SquareProps = {style?: React.CSSProperties;};-export const Square: React.FC<SquareProps> = ({width, height, fill, style}) => {+export const Rect: React.FC<SquareProps> = ({width, height, fill, style}) => {return (<svgwidth={width}@@ -16,10 +16,10 @@ export const Square: React.FC<SquareProps> = ({width, height, fill, style}) => {viewBox={`0 0 ${width} ${height}`}xmlns="http://www.w3.org/2000/svg"style={style}- data-shape-type="square"+ data-shape-type="rect"><path- d={makeSquare({+ d={makeRect({width,height,})}diff --git a/packages/shapes/src/test/make-rect.test.ts b/packages/shapes/src/test/make-rect.test.tsnew file mode 100644index 0000000000..069d200181--- /dev/null+++ b/packages/shapes/src/test/make-rect.test.ts@@ -0,0 +1,7 @@+import {expect, test} from 'vitest';+import {makeRect} from '../make-rect';++test('Should be able to make a rect path', () => {+ const rect = makeRect({x: 50, y: 50, width: 100, height: 100});+ expect(rect).toEqual('M 50 50 l 100 0 l 0 100 l -100 0 Z');+});diff --git a/packages/shapes/src/test/make-square.test.ts b/packages/shapes/src/test/make-square.test.tsdeleted file mode 100644index c2b8e0a41d..0000000000--- a/packages/shapes/src/test/make-square.test.ts+++ /dev/null@@ -1,7 +0,0 @@-import {expect, test} from 'vitest';-import {makeSquare} from '../make-square';--test('Should be able to make a square path', () => {- const square = makeSquare({x: 50, y: 50, width: 100, height: 100});- expect(square).toEqual('M 50 50 l 100 0 l 0 100 l -100 0 Z');-});diff --git a/packages/shapes/src/test/square.test.tsx b/packages/shapes/src/test/square.test.tsxindex 8661ef578a..b6da93ee94 100644--- a/packages/shapes/src/test/square.test.tsx+++ b/packages/shapes/src/test/square.test.tsx@@ -1,13 +1,13 @@import {expect, test} from 'vitest';-import {Square} from '../square';+import {Rect} from '../rect';import {render} from './test-utils';-test('Should be able to make a square svg', () => {- const {container} = render(<Square width={200} height={200} fill="red" />);+test('Should be able to make a rect svg', () => {+ const {container} = render(<Rect width={200} height={200} fill="red" />);// assert shape typeexpect(container.querySelector('svg')?.getAttribute('data-shape-type')- ).toEqual('square');+ ).toEqual('rect');// assert pathexpect(container.querySelector('path')?.getAttribute('d')).toEqual(