🎥 Make videos programmatically with React
generalize
Jonny Burgerc02b5c9dab50
diff --git a/packages/shapes/src/Ellipse.tsx b/packages/shapes/src/Ellipse.tsxindex 92e9cd51ce..6b734a0d74 100644--- a/packages/shapes/src/Ellipse.tsx+++ b/packages/shapes/src/Ellipse.tsx@@ -1,9 +1,9 @@-import React from 'react';+import type React from 'react';+import type {MakeEllipseOptions} from './make-ellipse';import {makeEllipse} from './make-ellipse';+import {renderSvg} from './render-svg';-export type EllipseProps = React.SVGProps<SVGPathElement> & {- rx: number;- ry: number;+export type EllipseProps = MakeEllipseOptions & {fill?: string;stroke?: string;strokeWidth?: number;@@ -18,24 +18,18 @@ export const Ellipse: React.FC<EllipseProps> = ({ry,style,}) => {- return (- <svg- width={rx * 2}- height={ry * 2}- viewBox={`0 0 ${rx * 2} ${ry * 2}`}- xmlns="http://www.w3.org/2000/svg"- style={style}- data-shape-type="ellipse"- >- <path- d={makeEllipse({- rx,- ry,- })}- fill={fill}- stroke={stroke}- strokeWidth={strokeWidth}- />- </svg>- );+ const path = makeEllipse({+ rx,+ ry,+ });++ return renderSvg({+ height: ry * 2,+ path,+ width: rx * 2,+ fill,+ style,+ strokeWidth,+ stroke,+ });};diff --git a/packages/shapes/src/circle.tsx b/packages/shapes/src/circle.tsxindex 4acb92e742..02442f2dc8 100644--- a/packages/shapes/src/circle.tsx+++ b/packages/shapes/src/circle.tsx@@ -1,9 +1,9 @@-import React from 'react';+import type React from 'react';+import type {MakeCircleProps} from './make-circle';import {makeCircle} from './make-circle';+import {renderSvg} from './render-svg';-export type CircleProps = React.SVGProps<SVGPathElement> & {- width: number;- height: number;+export type CircleProps = Omit<MakeCircleProps, 'cx' | 'cy'> & {fill?: string;stroke?: string;strokeWidth?: number;@@ -11,32 +11,25 @@ export type CircleProps = React.SVGProps<SVGPathElement> & {};export const Circle: React.FC<CircleProps> = ({- width,- height,fill,stroke,strokeWidth,style,+ radius,}) => {- return (- <svg- width={width}- height={height}- viewBox={`0 0 ${width} ${height}`}- xmlns="http://www.w3.org/2000/svg"- style={style}- data-shape-type="circle"- >- <path- d={makeCircle({- cx: 50,- cy: 50,- radius: 50,- })}- fill={fill}- stroke={stroke}- strokeWidth={strokeWidth}- />- </svg>- );+ const size = radius * 2;++ return renderSvg({+ path: makeCircle({+ cx: radius,+ cy: radius,+ radius,+ }),+ height: size,+ width: size,+ fill,+ stroke,+ strokeWidth,+ style,+ });};diff --git a/packages/shapes/src/make-circle.ts b/packages/shapes/src/make-circle.tsindex 3ce28b42d4..d57d61c596 100644--- a/packages/shapes/src/make-circle.ts+++ b/packages/shapes/src/make-circle.ts@@ -1,14 +1,10 @@export type MakeCircleProps = {- cx?: number | string;- cy?: number | string;- radius?: number | string;+ cx: number;+ cy: number;+ radius: number;};-export const makeCircle = ({- cx = 50,- cy = 50,- radius = 50,-}: MakeCircleProps) => {+export const makeCircle = ({cx, cy, radius}: MakeCircleProps) => {return `M ${cx} ${cy} m -${radius} 0 a ${radius} ${radius} 0 1 0 ${(radius as number) * 2} 0 ${radius} ${radius} 0 1 0 ${-radius * 2} 0`;diff --git a/packages/shapes/src/make-ellipse.ts b/packages/shapes/src/make-ellipse.tsindex 2c279e35cb..8567aeb9d3 100644--- a/packages/shapes/src/make-ellipse.ts+++ b/packages/shapes/src/make-ellipse.ts@@ -1,6 +1,6 @@export type MakeEllipseOptions = {- rx?: number | string;- ry?: number | string;+ rx: number;+ ry: number;};export const makeEllipse = ({rx = 50, ry = 50}: MakeEllipseOptions) => {diff --git a/packages/shapes/src/render-svg.tsx b/packages/shapes/src/render-svg.tsxindex 89665064bb..ecff7cdc18 100644--- a/packages/shapes/src/render-svg.tsx+++ b/packages/shapes/src/render-svg.tsx@@ -12,6 +12,8 @@ export const renderSvg = ({path: string;fill?: string;style?: React.CSSProperties;+ stroke?: string;+ strokeWidth?: number;}) => {return (<svg