🎥 Make videos programmatically with React
shapes: end all statements in z
Jonny Burger53a681d27743
diff --git a/packages/shapes/src/test/circle.test.tsx b/packages/shapes/src/test/circle.test.tsxindex edc75cdb1a..46b4f7a1e5 100644--- a/packages/shapes/src/test/circle.test.tsx+++ b/packages/shapes/src/test/circle.test.tsx@@ -8,6 +8,6 @@ test('Should be able to make a circle svg', () => {);expect(container.querySelector('path')?.getAttribute('d')).toEqual(- 'M 100 100 m -100 0 a 100 100 0 1 0 200 0 a 100 100 0 1 0 -200 0'+ 'M 100 100 m -100 0 a 100 100 0 1 0 200 0 a 100 100 0 1 0 -200 0 z');});diff --git a/packages/shapes/src/test/ellipse.test.tsx b/packages/shapes/src/test/ellipse.test.tsxindex e501832310..ac9144c374 100644--- a/packages/shapes/src/test/ellipse.test.tsx+++ b/packages/shapes/src/test/ellipse.test.tsx@@ -8,6 +8,6 @@ test('Should be able to make a circle svg', () => {);expect(container.querySelector('path')?.getAttribute('d')).toEqual(- 'M 100 0 a 100 100 0 1 0 1 0'+ 'M 100 0 a 100 100 0 1 0 1 0 z');});diff --git a/packages/shapes/src/test/make-circle.test.ts b/packages/shapes/src/test/make-circle.test.tsindex c85f86ad36..357b29a843 100644--- a/packages/shapes/src/test/make-circle.test.ts+++ b/packages/shapes/src/test/make-circle.test.ts@@ -6,7 +6,7 @@ test('Should be able to make a circle path', () => {expect(circlePath).toEqual({height: 100,width: 100,- path: 'M 50 50 m -50 0 a 50 50 0 1 0 100 0 a 50 50 0 1 0 -100 0',+ path: 'M 50 50 m -50 0 a 50 50 0 1 0 100 0 a 50 50 0 1 0 -100 0 z',transformOrigin: '50 50',instructions: [{type: 'M', x: 50, y: 50},@@ -31,6 +31,9 @@ test('Should be able to make a circle path', () => {x: -100,y: 0,},+ {+ type: 'z',+ },],});});diff --git a/packages/shapes/src/test/make-ellipse.test.ts b/packages/shapes/src/test/make-ellipse.test.tsindex 155d756840..c265175c10 100644--- a/packages/shapes/src/test/make-ellipse.test.ts+++ b/packages/shapes/src/test/make-ellipse.test.ts@@ -4,7 +4,7 @@ import {makeEllipse} from '../utils/make-ellipse';test('Should be able to make a circle path', () => {const circlePath = makeEllipse({rx: 100, ry: 50});expect(circlePath).toEqual({- path: 'M 100 0 a 100 50 0 1 0 1 0',+ path: 'M 100 0 a 100 50 0 1 0 1 0 z',height: 100,width: 200,transformOrigin: '100 50',@@ -20,6 +20,9 @@ test('Should be able to make a circle path', () => {x: 1,y: 0,},+ {+ type: 'z',+ },],});});diff --git a/packages/shapes/src/test/make-rect.test.ts b/packages/shapes/src/test/make-rect.test.tsindex a109141976..cc61e710cd 100644--- a/packages/shapes/src/test/make-rect.test.ts+++ b/packages/shapes/src/test/make-rect.test.ts@@ -6,7 +6,7 @@ test('Should be able to make a rect path', () => {expect(rect).toEqual({height: 100,width: 100,- path: 'M 0 0 L 100 0 L 100 100 L 0 100 L 0 0',+ path: 'M 0 0 L 100 0 L 100 100 L 0 100 L 0 0 z',transformOrigin: '50 50',instructions: [{type: 'M', x: 0, y: 0},@@ -14,6 +14,7 @@ test('Should be able to make a rect path', () => {{type: 'L', x: 100, y: 100},{type: 'L', x: 0, y: 100},{type: 'L', x: 0, y: 0},+ {type: 'z'},],});});diff --git a/packages/shapes/src/test/make-star.test.ts b/packages/shapes/src/test/make-star.test.tsindex 660e7aa56e..26174f6ba4 100644--- a/packages/shapes/src/test/make-star.test.ts+++ b/packages/shapes/src/test/make-star.test.ts@@ -9,7 +9,7 @@ test('Should be able to make a triangle path', () => {});expect(starPath).toEqual({- path: 'M 200 0 L 288.167787843871 78.64745084375788 L 390.21130325903073 138.19660112501052 L 342.658477444273 246.3525491562421 L 317.55705045849464 361.8033988749895 L 200 350 L 82.4429495415054 361.8033988749895 L 57.34152255572698 246.35254915624213 L 9.788696740969272 138.19660112501055 L 111.83221215612902 78.6474508437579 L 200 0',+ path: 'M 200 0 L 288.167787843871 78.64745084375788 L 390.21130325903073 138.19660112501052 L 342.658477444273 246.3525491562421 L 317.55705045849464 361.8033988749895 L 200 350 L 82.4429495415054 361.8033988749895 L 57.34152255572698 246.35254915624213 L 9.788696740969272 138.19660112501055 L 111.83221215612902 78.6474508437579 L 200 0 z',width: 400,height: 400,transformOrigin: '200 200',@@ -25,6 +25,7 @@ test('Should be able to make a triangle path', () => {{type: 'L', x: 9.788696740969272, y: 138.19660112501055},{type: 'L', x: 111.83221215612902, y: 78.6474508437579},{type: 'L', x: 200, y: 0},+ {type: 'z'},],});});diff --git a/packages/shapes/src/test/make-triangle.test.ts b/packages/shapes/src/test/make-triangle.test.tsindex 618b6f146c..91ea06a2cf 100644--- a/packages/shapes/src/test/make-triangle.test.ts+++ b/packages/shapes/src/test/make-triangle.test.ts@@ -10,13 +10,14 @@ test('Should be able to make a triangle path', () => {expect(rightTriangle).toEqual({width: 86.60254037844386,height: 100,- path: 'M 0 0 L 0 100 L 86.60254037844386 50 L 0 0',+ path: 'M 0 0 L 0 100 L 86.60254037844386 50 L 0 0 z',transformOrigin: '28.867513459481287 50',instructions: [{type: 'M', x: 0, y: 0},{type: 'L', x: 0, y: 100},{type: 'L', x: 86.60254037844386, y: 50},{type: 'L', x: 0, y: 0},+ {type: 'z'},],});});diff --git a/packages/shapes/src/test/square.test.tsx b/packages/shapes/src/test/square.test.tsxindex 626278fc66..8e6ef3111d 100644--- a/packages/shapes/src/test/square.test.tsx+++ b/packages/shapes/src/test/square.test.tsx@@ -7,6 +7,6 @@ test('Should be able to make a rect svg', () => {// assert pathexpect(container.querySelector('path')?.getAttribute('d')).toEqual(- 'M 0 0 L 200 0 L 200 200 L 0 200 L 0 0'+ 'M 0 0 L 200 0 L 200 200 L 0 200 L 0 0 z');});diff --git a/packages/shapes/src/test/star.test.tsx b/packages/shapes/src/test/star.test.tsxindex 383bfc7cea..6c1166317e 100644--- a/packages/shapes/src/test/star.test.tsx+++ b/packages/shapes/src/test/star.test.tsx@@ -8,6 +8,6 @@ test('Should be able to make a star svg', () => {);expect(container.querySelector('path')?.getAttribute('d')).toEqual(- 'M 150 0 L 267.55705045849464 -11.803398874989483 L 292.658477444273 103.6474508437579 L 340.21130325903073 211.80339887498948 L 238.16778784387097 271.3525491562421 L 150 350 L 61.832212156129046 271.3525491562421 L -40.2113032590307 211.8033988749895 L 7.341522555726954 103.64745084375791 L 32.44294954150536 -11.803398874989455 L 150 0'+ 'M 150 0 L 267.55705045849464 -11.803398874989483 L 292.658477444273 103.6474508437579 L 340.21130325903073 211.80339887498948 L 238.16778784387097 271.3525491562421 L 150 350 L 61.832212156129046 271.3525491562421 L -40.2113032590307 211.8033988749895 L 7.341522555726954 103.64745084375791 L 32.44294954150536 -11.803398874989455 L 150 0 z');});diff --git a/packages/shapes/src/test/triangle.test.tsx b/packages/shapes/src/test/triangle.test.tsxindex 0937aa7f6a..f43dc40471 100644--- a/packages/shapes/src/test/triangle.test.tsx+++ b/packages/shapes/src/test/triangle.test.tsx@@ -9,6 +9,6 @@ test('Should be able to make a triangle svg', () => {// assert pathexpect(container.querySelector('path')?.getAttribute('d')).toEqual(- 'M 86.60254037844386 0 L 86.60254037844386 100 L 0 50 L 86.60254037844386 0'+ 'M 86.60254037844386 0 L 86.60254037844386 100 L 0 50 L 86.60254037844386 0 z');});diff --git a/packages/shapes/src/utils/instructions.ts b/packages/shapes/src/utils/instructions.tsindex 29ed12be59..f12863d602 100644--- a/packages/shapes/src/utils/instructions.ts+++ b/packages/shapes/src/utils/instructions.ts@@ -32,10 +32,13 @@ export type Instruction =sweepFlag: boolean;x: number;y: number;+ }+ | {+ type: 'z';};export const serializeInstructions = (instructions: Instruction[]) => {- return instructions.map(serializeInstruction).join(' ');+ return instructions.map((i) => serializeInstruction(i)).join(' ');};export const serializeInstruction = (instruction: Instruction) => {@@ -62,4 +65,10 @@ export const serializeInstruction = (instruction: Instruction) => {instruction.sweepFlag ? 1 : 0)} ${instruction.x} ${instruction.y}`;}++ if (instruction.type === 'z') {+ return 'z';+ }++ throw new Error('not implemented');};diff --git a/packages/shapes/src/utils/make-circle.ts b/packages/shapes/src/utils/make-circle.tsindex e38a668b95..a2293d7407 100644--- a/packages/shapes/src/utils/make-circle.ts+++ b/packages/shapes/src/utils/make-circle.ts@@ -38,6 +38,9 @@ export const makeCircle = ({radius}: MakeCircleProps): ShapeInfo => {x: -radius * 2,y: 0,},+ {+ type: 'z',+ },];const path = serializeInstructions(instructions);diff --git a/packages/shapes/src/utils/make-ellipse.ts b/packages/shapes/src/utils/make-ellipse.tsindex 5da4c98d31..46f501f4b0 100644--- a/packages/shapes/src/utils/make-ellipse.ts+++ b/packages/shapes/src/utils/make-ellipse.ts@@ -24,6 +24,9 @@ export const makeEllipse = ({rx, ry}: MakeEllipseOptions): ShapeInfo => {x: 1,y: 0,},+ {+ type: 'z',+ },];const path = serializeInstructions(instructions);diff --git a/packages/shapes/src/utils/make-rect.ts b/packages/shapes/src/utils/make-rect.tsindex 12b8247f8b..191b9d170b 100644--- a/packages/shapes/src/utils/make-rect.ts+++ b/packages/shapes/src/utils/make-rect.ts@@ -1,3 +1,4 @@+import type {Instruction} from './instructions';import {serializeInstructions} from './instructions';import {joinPoints} from './join-points';import type {ShapeInfo} from './shape-info';@@ -16,16 +17,21 @@ export const makeRect = ({cornerRadius = 0,}: MakeRectOptions): ShapeInfo => {const transformOrigin: [number, number] = [width / 2, height / 2];- const instructions = joinPoints(- [- [0, 0],- [width, 0],- [width, height],- [0, height],- [0, 0],- ],- {edgeRoundness, cornerRadius, roundCornerStrategy: 'arc'}- );+ const instructions: Instruction[] = [+ ...joinPoints(+ [+ [0, 0],+ [width, 0],+ [width, height],+ [0, height],+ [0, 0],+ ],+ {edgeRoundness, cornerRadius, roundCornerStrategy: 'arc'}+ ),+ {+ type: 'z',+ },+ ];const path = serializeInstructions(instructions);return {diff --git a/packages/shapes/src/utils/make-star.ts b/packages/shapes/src/utils/make-star.tsindex 0abb5961a1..17312d4c92 100644--- a/packages/shapes/src/utils/make-star.ts+++ b/packages/shapes/src/utils/make-star.ts@@ -44,11 +44,14 @@ const star = ({return [point.x, point.y];});- return joinPoints([...d, d[0]], {- edgeRoundness,- cornerRadius,- roundCornerStrategy: cornerRadius > 0 ? 'bezier' : 'arc',- });+ return [+ ...joinPoints([...d, d[0]], {+ edgeRoundness,+ cornerRadius,+ roundCornerStrategy: cornerRadius > 0 ? 'bezier' : 'arc',+ }),+ {type: 'z'},+ ];};export const makeStar = ({diff --git a/packages/shapes/src/utils/make-triangle.ts b/packages/shapes/src/utils/make-triangle.tsindex 3d9fee18ec..f6b8fde43c 100644--- a/packages/shapes/src/utils/make-triangle.ts+++ b/packages/shapes/src/utils/make-triangle.ts@@ -1,5 +1,6 @@// Copied from https://stackblitz.com/edit/react-triangle-svg?file=index.js+import type {Instruction} from './instructions';import {serializeInstructions} from './instructions';import {joinPoints} from './join-points';import type {ShapeInfo} from './shape-info';@@ -63,11 +64,16 @@ export const makeTriangle = ({right: longerDimension / 2,}[direction];- const instructions = joinPoints(points[direction], {- edgeRoundness,- cornerRadius,- roundCornerStrategy: 'bezier',- });+ const instructions: Instruction[] = [+ ...joinPoints(points[direction], {+ edgeRoundness,+ cornerRadius,+ roundCornerStrategy: 'bezier',+ }),+ {+ type: 'z',+ },+ ];const path = serializeInstructions(instructions);return {