🎥 Make videos programmatically with React
return type and transform origin
Jonny Burger5ba259b1952a
diff --git a/packages/docs/components/shapes/shapes-info.tsx b/packages/docs/components/shapes/shapes-info.tsxindex ba665fb87d..d8cf6583ec 100644--- a/packages/docs/components/shapes/shapes-info.tsx+++ b/packages/docs/components/shapes/shapes-info.tsx@@ -14,7 +14,6 @@ type Param = {type ShapeComponent = {shape: string;- name: string;fn: (options: unknown) => unknown;params: Param[];};@@ -22,7 +21,6 @@ type ShapeComponent = {export const shapeComponents: ShapeComponent[] = [{shape: "Rect",- name: "<Rect>",fn: makeRect,params: [{@@ -39,7 +37,6 @@ export const shapeComponents: ShapeComponent[] = [},{shape: "Circle",- name: "<Circle>",fn: makeCircle,params: [{@@ -51,7 +48,6 @@ export const shapeComponents: ShapeComponent[] = [},{shape: "Ellipse",- name: "<Ellipse>",fn: makeEllipse,params: [{@@ -68,7 +64,6 @@ export const shapeComponents: ShapeComponent[] = [},{shape: "Triangle",- name: "<Triangle>",fn: makeTriangle,params: [{@@ -117,7 +112,10 @@ const globalParams: Param[] = [description: (<>CSS properties that will be applied to the <code>{"<path>"}</code> tag.- Default style: <code>{"overflow: 'visible'"}</code>+ Default style: <code>{"transform-box: 'fill-box'"}</code> and a+ dynamically calculated <code>{"transform-origin"}</code> which is the+ center of the shape, so that the shape rotates around its center by+ default.</>),},@@ -192,6 +190,56 @@ export const ShapeOptions: React.FC<{);};+export const MakeShapeReturnType: React.FC<{+ shape: string;+}> = ({ shape }) => {+ const shapeComponent = shapeComponents.find(+ (c) => c.shape.toLowerCase() === shape.toLowerCase()+ );++ return (+ <div>+ <h3>+ <code>path</code>+ </h3>+ <p>+ A string that is suitable as an argument for <code>d</code> in a{" "}+ <code>{"<path>"}</code> element.+ </p>+ <h3>+ <code>width</code>+ </h3>+ <p>+ The width of the {shapeComponent.shape.toLowerCase()}. Suitable for+ defining the <code>viewBox</code> of an <code>{"<svg>"}</code> tag.+ </p>+ <h3>+ <code>height</code>+ </h3>+ <p>+ The height of the {shapeComponent.shape.toLowerCase()}. Suitable for+ defining the <code>viewBox</code> of an <code>{"<svg>"}</code> tag.+ </p>+ <h3>+ <code>transformOrigin</code>+ </h3>+ <p>+ A string representing the point of origin if a shape should be rotated+ around itself.+ </p>+ <p>+ If you want to rotate the shape around its center, use the{" "}+ <code>transform-origin</code> CSS property and pass this value, and also+ add <code>transform-box: fill-box</code>. This is the default for{" "}+ <a href={`/docs/shapes/${shapeComponent.shape.toLowerCase()}`}>+ <code>{`<${shapeComponent.shape} />`}</code>+ </a>+ .+ </p>+ </div>+ );+};+export const MakeShapeSeeAlso: React.FC<{shape: string;}> = ({ shape }) => {diff --git a/packages/docs/docs/shapes/make-circle.md b/packages/docs/docs/shapes/make-circle.mdindex 47e20eb856..7e65e7dde6 100644--- a/packages/docs/docs/shapes/make-circle.md+++ b/packages/docs/docs/shapes/make-circle.md@@ -3,28 +3,33 @@ title: makeCircle()crumb: "@remotion/shapes"---+import {MakeShapeSeeAlso, ShapeOptions, MakeShapeReturnType} from "../../components/shapes/shapes-info"+_Part of the [`@remotion/shapes`](/docs/shapes) package._Generates a circle SVG path.-## Arguments--<ShapeOptions shape="circle"/>-## Example```tsx twoslash title="circle.ts"import { makeCircle } from "@remotion/shapes";-const { path, width, height } = makeCircle({ radius: 50 });+const { path, width, height, transformOrigin } = makeCircle({ radius: 50 });console.log(path); // M 0 0 m -50, 0 a 50,50 0 1,0 100,0 50,50 0 1,0 -100,0console.log(width); // 100console.log(height); // 100+console.log(transformOrigin); // '50 50'```-## See also+## Arguments++<ShapeOptions shape="circle"/>-import {MakeShapeSeeAlso, ShapeOptions} from "../../components/shapes/shapes-info"+## Return type++<MakeShapeReturnType shape="circle"/>++## See also<MakeShapeSeeAlso shape="circle"/>diff --git a/packages/docs/docs/shapes/make-ellipse.md b/packages/docs/docs/shapes/make-ellipse.mdindex 29716d4de7..6d0ea1f709 100644--- a/packages/docs/docs/shapes/make-ellipse.md+++ b/packages/docs/docs/shapes/make-ellipse.md@@ -18,7 +18,7 @@ Generates an ellipse SVG path.```tsx twoslash title="ellipse.ts"import { makeEllipse } from "@remotion/shapes";-const { path, width, height } = makeEllipse({+const { path, width, height, transformOrigin } = makeEllipse({rx: 100,ry: 50,});@@ -26,11 +26,16 @@ const { path, width, height } = makeEllipse({console.log(path); // M 100 0 a 100 100 0 1 0 1 0console.log(width); // 200console.log(height); // 100+console.log(transformOrigin); // '100 50'```-## Credits+## Arguments++<ShapeOptions shape="ellipse"/>++## Return type-Source code stems mostly from [triangle](https://stackblitz.com/edit/react-triangle-svg?file=index.js).+<MakeShapeReturnType shape="ellipse"/>## See alsodiff --git a/packages/docs/docs/shapes/make-rect.md b/packages/docs/docs/shapes/make-rect.mdindex 5ecf44c665..c6cd159cd0 100644--- a/packages/docs/docs/shapes/make-rect.md+++ b/packages/docs/docs/shapes/make-rect.md@@ -3,28 +3,36 @@ title: makeRect()crumb: "@remotion/shapes"----import {MakeShapeSeeAlso, ShapeOptions} from "../../components/shapes/shapes-info"+import {MakeShapeSeeAlso, ShapeOptions, MakeShapeReturnType} from "../../components/shapes/shapes-info"_Part of the [`@remotion/shapes`](/docs/shapes) package._Generates an SVG rectangle.-## Arguments--<ShapeOptions shape="rect"/>-## Example```tsx twoslash title="rect.ts"import { makeRect } from "@remotion/shapes";-const { path, width, height } = makeRect({ width: 100, height: 100 });+const { path, width, height, transformOrigin } = makeRect({+ width: 100,+ height: 100,+});console.log(path); // M 0 0 l 100 0 l 0 100 l -100 0 Zconsole.log(width); // 100console.log(height); // 100+console.log(transformOrigin); // '50 50'```+## Arguments++<ShapeOptions shape="rect"/>++## Return type++<MakeShapeReturnType shape="rect"/>+## See also<MakeShapeSeeAlso shape="rect"/>diff --git a/packages/docs/docs/shapes/make-triangle.md b/packages/docs/docs/shapes/make-triangle.mdindex 2430c3cfd7..f4a7c8a8e0 100644--- a/packages/docs/docs/shapes/make-triangle.md+++ b/packages/docs/docs/shapes/make-triangle.md@@ -3,16 +3,12 @@ title: makeTriangle()crumb: "@remotion/shapes"----import {MakeShapeSeeAlso, ShapeOptions} from "../../components/shapes/shapes-info"+import {MakeShapeSeeAlso, ShapeOptions, MakeShapeReturnType} from "../../components/shapes/shapes-info"_Part of the [`@remotion/shapes`](/docs/shapes) package._Generates a triangle SVG path.-## Arguments--<ShapeOptions shape="triangle"/>-## ExampleExample Triangle path generation@@ -20,7 +16,7 @@ Example Triangle path generation```tsx twoslash title="triangle.ts"import { makeTriangle } from "@remotion/shapes";-const { path, width, height } = makeTriangle({+const { path, width, height, transformOrigin } = makeTriangle({length: 100,direction: "right",});@@ -28,8 +24,17 @@ const { path, width, height } = makeTriangle({console.log(path); // M 0 0 L 0 100 L 86.60254037844386 50 zconsole.log(width); // 86.60254037844386console.log(height); // 100+console.log(transformOrigin); // '28.867513459481287 50'```+## Arguments++<ShapeOptions shape="triangle"/>++## Return type++<MakeShapeReturnType shape="rect"/>+## CreditsSource code partially taken from [this StackBlitz](https://stackblitz.com/edit/react-triangle-svg?file=index.js).