Skip to content

🎥 Make videos programmatically with React

feat: draft - task to create shapes package, documentation and example

Alex Fernandez7e62a131f34f
diff --git a/.npmrc b/.npmrc
index 1a992245cb..590d55f6db 100644
--- a/.npmrc
+++ b/.npmrc
@@ -5,3 +5,4 @@ public-hoist-pattern[]=@react-three/fiber
public-hoist-pattern[]=*eslint*
auto-install-peers=true
strict-peer-dependencies=false
+
diff --git a/packages/docs/components/TableOfContents/shapes.tsx b/packages/docs/components/TableOfContents/shapes.tsx
new file mode 100644
index 0000000000..6bf6a6d6ff
--- /dev/null
+++ b/packages/docs/components/TableOfContents/shapes.tsx
@@ -0,0 +1,36 @@
+import React from "react";
+import { Grid } from "./Grid";
+import { TOCItem } from "./TOCItem";
+
+export const TableOfContents: React.FC = () => {
+ return (
+ <div>
+ <Grid>
+ <TOCItem link="/docs/shapes/make-circle">
+ <strong>makeCircle()</strong>
+ <div>Generate circle path</div>
+ </TOCItem>
+ <TOCItem link="/docs/shapes/make-square">
+ <strong>makeSquare()</strong>
+ <div>Generate circle path</div>
+ </TOCItem>
+ <TOCItem link="/docs/shapes/make-square">
+ <strong>makeTriangle()</strong>
+ <div>Generate triangle path</div>
+ </TOCItem>
+ <TOCItem link="/docs/shapes/circle">
+ <strong>{`<Circle/>`}</strong>
+ <div>Circle</div>
+ </TOCItem>
+ <TOCItem link="/docs/shapes/square">
+ <strong>{`<Square/>`}</strong>
+ <div>Square</div>
+ </TOCItem>
+ <TOCItem link="/docs/shapes/triangle">
+ <strong>{`<Triangle/>`}</strong>
+ <div>Triangle</div>
+ </TOCItem>
+ </Grid>
+ </div>
+ );
+};
diff --git a/packages/docs/docs/shapes/circle.md b/packages/docs/docs/shapes/circle.md
new file mode 100644
index 0000000000..a772b51303
--- /dev/null
+++ b/packages/docs/docs/shapes/circle.md
@@ -0,0 +1,14 @@
+---
+image: /generated/articles-docs-paths-circle.png
+title: <Circle />
+crumb: "@remotion/shapes"
+---
+
+_Part of the [` @remotion/shapes`](/docs/shapes) package._
+
+
+
+## See also
+- [makeCircle()](/docs/paths/make-circle)
+- [`@remotion/shapes`](/docs/paths)
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/paths/src/make-triangle.tsx)
diff --git a/packages/docs/docs/shapes/index.md b/packages/docs/docs/shapes/index.md
new file mode 100644
index 0000000000..8ef6f0180b
--- /dev/null
+++ b/packages/docs/docs/shapes/index.md
@@ -0,0 +1,53 @@
+---
+image: /generated/articles-docs-shapes-index.png
+title: "@remotion/shapes"
+crumb: "SVG"
+---
+
+import {TableOfContents} from '../../components/TableOfContents/shapes';
+
+A package providing utility functions for generate SVG shapes.
+
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
+
+<Tabs
+defaultValue="npm"
+values={[
+{ label: 'npm', value: 'npm', },
+{ label: 'pnpm', value: 'pnpm', },
+{ label: 'yarn', value: 'yarn', },
+]
+}>
+<TabItem value="npm">
+
+```bash
+npm i @remotion/shapes
+```
+
+ </TabItem>
+
+ <TabItem value="pnpm">
+
+```bash
+pnpm i @remotion/shapes
+```
+
+ </TabItem>
+
+ <TabItem value="yarn">
+
+```bash
+yarn add @remotion/shapes
+```
+
+ </TabItem>
+</Tabs>
+
+## Functions
+
+<TableOfContents />
+
+## License
+
+MIT
diff --git a/packages/docs/docs/shapes/make-circle.md b/packages/docs/docs/shapes/make-circle.md
new file mode 100644
index 0000000000..258f5b370c
--- /dev/null
+++ b/packages/docs/docs/shapes/make-circle.md
@@ -0,0 +1,27 @@
+---
+image: /generated/articles-docs-paths-make-circle.png
+title: makeCircle()
+crumb: "@remotion/shapes"
+---
+
+_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
+
+
+
+## See also
+- [makeTriangle()](/docs/paths/make-triangle)
+- [makeSquare()](/docs/paths/make-square)
+- [`@remotion/shapes`](/docs/paths)
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/paths/src/make-triangle.tsx)
diff --git a/packages/docs/docs/shapes/make-square.md b/packages/docs/docs/shapes/make-square.md
new file mode 100644
index 0000000000..6c872ce18e
--- /dev/null
+++ b/packages/docs/docs/shapes/make-square.md
@@ -0,0 +1,29 @@
+---
+image: /generated/articles-docs-paths-make-square.png
+title: makeSquare()
+crumb: "@remotion/shapes"
+---
+
+_Part of the [` @remotion/shapes`](/docs/paths) package._
+
+
+Generates Square 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
+
+
+
+## See also
+
+- [makeTriangle()](/docs/paths/make-triangle)
+- [makeCircle()](/docs/paths/make-circle)
+- [`@remotion/shapes`](/docs/paths)
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/paths/src/make-square.tsx)
diff --git a/packages/docs/docs/shapes/make-triangle.md b/packages/docs/docs/shapes/make-triangle.md
new file mode 100644
index 0000000000..aefd06c1ed
--- /dev/null
+++ b/packages/docs/docs/shapes/make-triangle.md
@@ -0,0 +1,34 @@
+---
+image: /generated/articles-docs-paths-make-triangle.png
+title: makeTriangle()
+crumb: "@remotion/shapes"
+---
+
+_Part of the [` @remotion/shapes`](/docs/shapes) package._
+
+
+Generates Triangle SVG path
+
+## Arguments
+
+### `options`
+
+An object with the following arguments:
+
+- `audioData`: `AudioData` - information about the audio. Use [`getAudioData()`](/docs/get-audio-data) to fetch it.
+- `startTimeInSeconds`: `number` - trim the waveform to exclude all data before `startTimeInSeconds`.
+- `durationInSeconds`: `number` - trim the waveform to exclude all data after `startTimeInSeconds + durationInSeconds`.
+- `numberOfSamples`: `number` - how big you want the result array to be. The function will compress the waveform to fit in `numberOfSamples` data points.
+
+
+
+## Credits
+
+Source code stems mostly from [triangle](https://stackblitz.com/edit/react-triangle-svg?file=index.js).
+
+## See also
+
+- [makeCircle()](/docs/paths/make-circle)
+- [makeSquare()](/docs/paths/make-square)
+- [`@remotion/shapes`](/docs/paths)
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/paths/src/make-triangle.tsx)
diff --git a/packages/docs/docs/shapes/square.md b/packages/docs/docs/shapes/square.md
new file mode 100644
index 0000000000..00b997e320
--- /dev/null
+++ b/packages/docs/docs/shapes/square.md
@@ -0,0 +1,26 @@
+---
+image: /generated/articles-docs-shapes-square.png
+title: <Square />
+crumb: "@remotion/shapes"
+---
+
+_Part of the [` @remotion/shapes`](/docs/shapes) package._
+
+## Arguments
+
+### `options`
+
+An object with the following arguments:
+
+- `audioData`: `AudioData` - information about the audio. Use [`getAudioData()`](/docs/get-audio-data) to fetch it.
+- `startTimeInSeconds`: `number` - trim the waveform to exclude all data before `startTimeInSeconds`.
+- `durationInSeconds`: `number` - trim the waveform to exclude all data after `startTimeInSeconds + durationInSeconds`.
+- `numberOfSamples`: `number` - how big you want the result array to be. The function will compress the waveform to fit in `numberOfSamples` data points.
+
+
+
+## See also
+- [makeTriangle()](/docs/paths/make-triangle)
+- [makeSquare()](/docs/paths/make-square)
+- [`@remotion/shapes`](/docs/paths)
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/paths/src/make-triangle.tsx)
diff --git a/packages/docs/docs/shapes/triangle.md b/packages/docs/docs/shapes/triangle.md
new file mode 100644
index 0000000000..207eb80017
--- /dev/null
+++ b/packages/docs/docs/shapes/triangle.md
@@ -0,0 +1,25 @@
+---
+image: /generated/articles-docs-shapes-triangle.png
+title: <Triangle />
+crumb: "@remotion/shapes"
+---
+
+_Part of the [` @remotion/shapes`](/docs/shapes) package._
+
+
+## Arguments
+
+### `options`
+
+An object with the following arguments:
+
+- `audioData`: `AudioData` - information about the audio. Use [`getAudioData()`](/docs/get-audio-data) to fetch it.
+- `startTimeInSeconds`: `number` - trim the waveform to exclude all data before `startTimeInSeconds`.
+- `durationInSeconds`: `number` - trim the waveform to exclude all data after `startTimeInSeconds + durationInSeconds`.
+- `numberOfSamples`: `number` - how big you want the result array to be. The function will compress the waveform to fit in `numberOfSamples` data points.
+
+
+
+## See also
+- [makeTriangle()](/docs/paths/make-triangle)
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/paths/src/make-triangle.tsx)
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 522e97d0c6..e00f2a561c 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -286,6 +286,22 @@ module.exports = {
"google-fonts/get-info",
],
},
+ {
+ type: "category",
+ label: "@remotion/shapes",
+ link: {
+ type: "doc",
+ id: "shapes/index",
+ },
+ items: [
+ "shapes/make-circle",
+ "shapes/make-square",
+ "shapes/make-triangle",
+ "shapes/square",
+ "shapes/triangle",
+ "shapes/circle",
+ ],
+ },
],
mainSidebar: [
{
diff --git a/packages/example/package.json b/packages/example/package.json
index f6730b8089..b7b10b6b0f 100644
--- a/packages/example/package.json
+++ b/packages/example/package.json
@@ -39,6 +39,7 @@
"@remotion/media-utils": "3.3.31",
"@remotion/paths": "3.3.31",
"@remotion/renderer": "3.3.31",
+ "@remotion/shapes": "workspace:^3.3.31",
"@remotion/three": "3.3.31",
"@types/express": "^4.17.11",
"@types/node": "^16.7.5",
diff --git a/packages/example/src/Shapes/CircleTest.tsx b/packages/example/src/Shapes/CircleTest.tsx
new file mode 100644
index 0000000000..02fcc898b2
--- /dev/null
+++ b/packages/example/src/Shapes/CircleTest.tsx
@@ -0,0 +1,39 @@
+import {Circle} from '@remotion/shapes';
+import React from 'react';
+import {AbsoluteFill, spring, useCurrentFrame, useVideoConfig} from 'remotion';
+
+const CircleTest: React.FC = () => {
+ const {fps} = useVideoConfig();
+ const frame = useCurrentFrame();
+ const spr = spring({
+ fps,
+ frame,
+ config: {
+ damping: 200,
+ },
+ });
+
+ return (
+ <AbsoluteFill
+ style={{
+ display: 'flex',
+ justifyContent: 'center',
+ alignContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <Circle
+ width={100}
+ height={100}
+ cx={50}
+ cy={50}
+ radius={50}
+ fill="green"
+ stroke="green"
+ strokeWidth={1}
+ />
+ </AbsoluteFill>
+ );
+};
+
+export default CircleTest;
diff --git a/packages/example/src/Shapes/SquareTest.tsx b/packages/example/src/Shapes/SquareTest.tsx
new file mode 100644
index 0000000000..9b6ad76d9e
--- /dev/null
+++ b/packages/example/src/Shapes/SquareTest.tsx
@@ -0,0 +1,20 @@
+import {Square} from '@remotion/shapes';
+import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+const SquareTest: React.FC = () => {
+ return (
+ <AbsoluteFill
+ style={{
+ display: 'flex',
+ justifyContent: 'center',
+ alignContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <Square width={200} height={200} size={100} fill="red" />
+ </AbsoluteFill>
+ );
+};
+
+export default SquareTest;
diff --git a/packages/example/src/Shapes/TriangleTest.tsx b/packages/example/src/Shapes/TriangleTest.tsx
new file mode 100644
index 0000000000..4810fcef33
--- /dev/null
+++ b/packages/example/src/Shapes/TriangleTest.tsx
@@ -0,0 +1,61 @@
+import {Triangle} from '@remotion/shapes';
+import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+const TriangleTest: React.FC = () => {
+ return (
+ <AbsoluteFill
+ style={{
+ display: 'flex',
+ justifyContent: 'center',
+ alignContent: 'center',
+ alignItems: 'center',
+ flexDirection: 'row',
+ }}
+ >
+ <Triangle
+ style={{
+ margin: '10px',
+ }}
+ width={100}
+ height={100}
+ fill="red"
+ direction="left"
+ color="green"
+ />
+
+ <Triangle
+ style={{
+ margin: '10px',
+ }}
+ width={100}
+ height={100}
+ fill="red"
+ direction="right"
+ color="green"
+ />
+ <Triangle
+ style={{
+ margin: '10px',
+ }}
+ width={100}
+ height={100}
+ fill="red"
+ direction="top"
+ color="green"
+ />
+ <Triangle
+ style={{
+ margin: '10px',
+ }}
+ width={100}
+ height={100}
+ fill="red"
+ direction="bottom"
+ color="green"
+ />
+ </AbsoluteFill>
+ );
+};
+
+export default TriangleTest;
diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsx
index c60bbffa91..462b1e2ed1 100644
--- a/packages/example/src/Video.tsx
+++ b/packages/example/src/Video.tsx
@@ -29,6 +29,9 @@ 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');
@@ -555,6 +558,33 @@ export const Index: React.FC = () => {
durationInFrames={150}
/>
</Folder>
+
+ <Folder name="shapes">
+ <Composition
+ id="circle-test"
+ component={CircleTest}
+ width={1200}
+ height={630}
+ fps={30}
+ durationInFrames={150}
+ />
+ <Composition
+ id="square-test"
+ component={SquareTest}
+ width={1200}
+ height={630}
+ fps={30}
+ durationInFrames={150}
+ />
+ <Composition
+ id="triangle-test"
+ component={TriangleTest}
+ width={1200}
+ height={630}
+ fps={30}
+ durationInFrames={150}
+ />
+ </Folder>
</>
);
};
diff --git a/packages/shapes/.eslintrc b/packages/shapes/.eslintrc
new file mode 100644
index 0000000000..d1d3a75fcd
--- /dev/null
+++ b/packages/shapes/.eslintrc
@@ -0,0 +1,6 @@
+{
+ "extends": "@jonny",
+ "rules": {
+ "no-bitwise": "off"
+ }
+}
diff --git a/packages/shapes/.npmignore b/packages/shapes/.npmignore
new file mode 100644
index 0000000000..2489b53382
--- /dev/null
+++ b/packages/shapes/.npmignore
@@ -0,0 +1,7 @@
+dist/test/**
+src
+.eslintrc
+tsconfig.tsbuildinfo
+.prettierrc
+*.tgz
+.turbo
diff --git a/packages/shapes/.prettierrc.js b/packages/shapes/.prettierrc.js
new file mode 100644
index 0000000000..32eb24f3bf
--- /dev/null
+++ b/packages/shapes/.prettierrc.js
@@ -0,0 +1,14 @@
+module.exports = {
+ singleQuote: true,
+ bracketSpacing: false,
+ useTabs: true,
+ overrides: [
+ {
+ files: ['*.yml'],
+ options: {
+ singleQuote: false,
+ },
+ },
+ ],
+ plugins: [require.resolve('prettier-plugin-organize-imports')],
+};
diff --git a/packages/shapes/LICENSE.md b/packages/shapes/LICENSE.md
new file mode 100644
index 0000000000..57a1f00d2d
--- /dev/null
+++ b/packages/shapes/LICENSE.md
@@ -0,0 +1,7 @@
+Copyright (c) 2023 JonnyBurger
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/packages/shapes/README.md b/packages/shapes/README.md
new file mode 100644
index 0000000000..e8fffbe6a7
--- /dev/null
+++ b/packages/shapes/README.md
@@ -0,0 +1,25 @@
+## @remotion/paths
+
+A package providing utility functions for dealing with SVG paths. This package consists of code from [`svg-path-properties`](https://www.npmjs.com/package/svg-path-properties) and [`svg-path-reverse`](https://github.com/Pomax/svg-path-reverse#readme) with the following improvements:
+
+- Functional style APIs
+- First class Typescript types
+- Documentation with examples
+- ESM import style
+
+No dependencies are needed, meaning this package can be used independently of Remotion.
+
+## API
+
+- [`getLength()`](https://remotion.dev/docs/paths/get-length)
+- [`getParts()`](https://remotion.dev/docs/paths/get-parts)
+- [`getPointAtLength()`](https://remotion.dev/docs/paths/get-point-at-length)
+- [`getTangentAtLength()`](https://remotion.dev/docs/paths/get-tangent-at-length)
+- [`reversePath()`](https://remotion.dev/docs/paths/reverse-path)
+- [`normalizePath()`](https://remotion.dev/docs/paths/normalize-path)
+- [`interpolatePath()`](https://remotion.dev/docs/paths/interpolate-path)
+- [`evolvePath()`](https://remotion.dev/docs/paths/evolve-path)
+
+## License
+
+MIT
diff --git a/packages/shapes/package.json b/packages/shapes/package.json
new file mode 100644
index 0000000000..a562176a2f
--- /dev/null
+++ b/packages/shapes/package.json
@@ -0,0 +1,43 @@
+{
+ "name": "@remotion/shapes",
+ "version": "3.3.31",
+ "description": "Utility functions for SVG paths",
+ "main": "dist/index.js",
+ "sideEffects": false,
+ "scripts": {
+ "lint": "eslint src --ext ts,tsx",
+ "watch": "tsc -w",
+ "build": "tsc -d",
+ "test": "vitest --run"
+ },
+ "author": "Jonny Burger <[email protected]>",
+ "license": "MIT",
+ "repository": {
+ "url": "https://github.com/remotion-dev/remotion"
+ },
+ "bugs": {
+ "url": "https://github.com/remotion-dev/remotion/issues"
+ },
+ "devDependencies": {
+ "@jonny/eslint-config": "3.0.266",
+ "@types/node": "^16.7.5",
+ "@types/react": "18.0.26",
+ "eslint": "8.25.0",
+ "prettier": "^2.7.1",
+ "prettier-plugin-organize-imports": "^2.3.4",
+ "typescript": "^4.7.0",
+ "vitest": "0.24.3"
+ },
+ "keywords": [
+ "svg",
+ "path",
+ "utilities"
+ ],
+ "publishConfig": {
+ "access": "public"
+ },
+ "dependencies": {
+ "react": "^18.2.0",
+ "react-dom": "^18.2.0"
+ }
+}
diff --git a/packages/shapes/src/circle.tsx b/packages/shapes/src/circle.tsx
new file mode 100644
index 0000000000..9ada00a231
--- /dev/null
+++ b/packages/shapes/src/circle.tsx
@@ -0,0 +1,47 @@
+import React from 'react';
+import {makeCircle} from './make-circle';
+
+export type CircleProps = React.SVGProps<SVGPathElement> & {
+ width: number;
+ height: number;
+ cx: number;
+ cy: number;
+ radius?: number;
+ fill?: string;
+ stroke?: string;
+ strokeWidth?: number;
+ style?: React.CSSProperties;
+};
+
+export const Circle: React.FC<CircleProps> = ({
+ width,
+ height,
+ cx,
+ cy,
+ fill,
+ radius,
+ stroke,
+ strokeWidth,
+ style,
+}) => {
+ return (
+ <svg
+ width={width}
+ height={height}
+ viewBox={`0 0 ${width} ${height}`}
+ xmlns="http://www.w3.org/2000/svg"
+ style={style}
+ >
+ <path
+ d={makeCircle({
+ cx,
+ cy,
+ radius,
+ })}
+ fill={fill}
+ stroke={stroke}
+ strokeWidth={strokeWidth}
+ />
+ </svg>
+ );
+};
diff --git a/packages/shapes/src/index.ts b/packages/shapes/src/index.ts
new file mode 100644
index 0000000000..b44e8efd79
--- /dev/null
+++ b/packages/shapes/src/index.ts
@@ -0,0 +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 {makeTriangle} from './make-triangle';
diff --git a/packages/shapes/src/make-circle.tsx b/packages/shapes/src/make-circle.tsx
new file mode 100644
index 0000000000..49246a0372
--- /dev/null
+++ b/packages/shapes/src/make-circle.tsx
@@ -0,0 +1,15 @@
+export type MakeCircleProps = {
+ cx?: number | string;
+ cy?: number | string;
+ radius?: number | string;
+};
+
+export const makeCircle = ({
+ cx = 50,
+ cy = 50,
+ radius = 50,
+}: 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-square.ts b/packages/shapes/src/make-square.ts
new file mode 100644
index 0000000000..494464bb4e
--- /dev/null
+++ b/packages/shapes/src/make-square.ts
@@ -0,0 +1,9 @@
+export type MakeSquareProps = {
+ x?: number;
+ y?: number;
+ size: number;
+};
+
+export const makeSquare = ({x = 50, y = 50, size}: MakeSquareProps) => {
+ return `M ${x}, ${y} l ${size}, 0 l 0, ${size} l ${-size}, 0 Z`;
+};
diff --git a/packages/shapes/src/make-triangle.ts b/packages/shapes/src/make-triangle.ts
new file mode 100644
index 0000000000..2c467328f6
--- /dev/null
+++ b/packages/shapes/src/make-triangle.ts
@@ -0,0 +1,21 @@
+// Copied from https://stackblitz.com/edit/react-triangle-svg?file=index.js
+
+export type MakeTriangleProps = {
+ width: number;
+ height: number;
+ direction: 'right' | 'left' | 'top' | 'bottom';
+};
+
+export const makeTriangle = ({
+ width,
+ height,
+ direction = 'right',
+}: MakeTriangleProps) => {
+ const points = {
+ top: [`${width / 2},0`, 'L', `0,${height}`, 'L', `${width},${height}`],
+ right: [`0,0`, 'L', `0,${height}`, 'L', `${width},${height / 2}`],
+ bottom: [`0,0`, 'L', `${width},0`, 'L', `${width / 2},${height}`],
+ left: [`${width},0`, 'L', `${width},${height}`, 'L', `0,${height / 2}`],
+ };
+ return `M${points[direction].join(' ')}z`;
+};
diff --git a/packages/shapes/src/square.tsx b/packages/shapes/src/square.tsx
new file mode 100644
index 0000000000..04c26f5b08
--- /dev/null
+++ b/packages/shapes/src/square.tsx
@@ -0,0 +1,35 @@
+import React from 'react';
+import {makeSquare} from './make-square';
+
+export type SquareProps = {
+ width: number;
+ height: number;
+ size: number;
+ fill?: string;
+ style?: React.CSSProperties;
+};
+
+export const Square: React.FC<SquareProps> = ({
+ width,
+ height,
+ size,
+ fill,
+ style,
+}) => {
+ return (
+ <svg
+ width={width}
+ height={height}
+ viewBox={`0 0 ${width} ${height}`}
+ xmlns="http://www.w3.org/2000/svg"
+ style={style}
+ >
+ <path
+ d={makeSquare({
+ size: size,
+ })}
+ fill={fill}
+ />
+ </svg>
+ );
+};
diff --git a/packages/shapes/src/triangle.tsx b/packages/shapes/src/triangle.tsx
new file mode 100644
index 0000000000..2e5a423a5a
--- /dev/null
+++ b/packages/shapes/src/triangle.tsx
@@ -0,0 +1,38 @@
+import React from 'react';
+import {makeTriangle} from './make-triangle';
+
+export type TriangleProps = {
+ width: number;
+ height: number;
+ color: string;
+ fill?: string;
+ direction: 'right' | 'left' | 'top' | 'bottom';
+ style?: React.CSSProperties;
+};
+
+export const Triangle: React.FC<TriangleProps> = ({
+ width,
+ height,
+ fill,
+ direction,
+ style,
+}) => {
+ return (
+ <svg
+ width={width}
+ height={height}
+ viewBox={`0 0 ${width} ${height}`}
+ xmlns="http://www.w3.org/2000/svg"
+ style={style}
+ >
+ <path
+ d={makeTriangle({
+ width,
+ height,
+ direction,
+ })}
+ fill={fill}
+ />
+ </svg>
+ );
+};
diff --git a/packages/shapes/tsconfig.json b/packages/shapes/tsconfig.json
new file mode 100644
index 0000000000..25f29fc131
--- /dev/null
+++ b/packages/shapes/tsconfig.json
@@ -0,0 +1,14 @@
+{
+ "extends": "../tsconfig.settings.json",
+ "compilerOptions": {
+ "composite": true,
+ "rootDir": "src",
+ "outDir": "dist"
+ },
+ "include": ["src"],
+ "references": [
+ {
+ "path": "../core"
+ }
+ ]
+}