@remotion/shapes 3.3.38 → 3.3.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
+ import type { Instruction } from '@remotion/paths/dist/helpers/types';
1
2
  import React from 'react';
2
- import type { Instruction } from '../utils/instructions';
3
3
  export declare type AllShapesProps = Omit<React.SVGProps<SVGPathElement>, 'width' | 'height' | 'd'> & {
4
4
  debug?: boolean;
5
5
  pathStyle?: React.CSSProperties;
@@ -22,7 +22,18 @@ const RenderSvg = ({ width, height, path, style, pathStyle, transformOrigin, deb
22
22
  const prevInstruction = index === 0
23
23
  ? instructions[instructions.length - 1]
24
24
  : instructions[index - 1];
25
- if (prevInstruction.type === 'z') {
25
+ if (prevInstruction.type === 'V' ||
26
+ prevInstruction.type === 'H' ||
27
+ prevInstruction.type === 'a' ||
28
+ prevInstruction.type === 'Z' ||
29
+ prevInstruction.type === 't' ||
30
+ prevInstruction.type === 'q' ||
31
+ prevInstruction.type === 'l' ||
32
+ prevInstruction.type === 'c' ||
33
+ prevInstruction.type === 'm' ||
34
+ prevInstruction.type === 'h' ||
35
+ prevInstruction.type === 's' ||
36
+ prevInstruction.type === 'v') {
26
37
  return null;
27
38
  }
28
39
  const prevX = prevInstruction.x;
@@ -0,0 +1,5 @@
1
+ export declare type ShapeInfo = {
2
+ path: string;
3
+ width: string;
4
+ height: string;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export declare type ShapeInfo = {
2
+ path: string;
3
+ width: number;
4
+ height: number;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
+ export { Instruction } from '@remotion/paths';
1
2
  export { Circle, CircleProps } from './components/circle';
2
3
  export { Ellipse, EllipseProps } from './components/ellipse';
3
4
  export { Pie, PieProps } from './components/pie';
4
5
  export { Rect, RectProps } from './components/rect';
5
6
  export { Star, StarProps } from './components/star';
6
7
  export { Triangle, TriangleProps } from './components/triangle';
7
- export { Instruction } from './utils/instructions';
8
8
  export { makeCircle, MakeCircleProps } from './utils/make-circle';
9
9
  export { makeEllipse, MakeEllipseOptions } from './utils/make-ellipse';
10
10
  export { makePie, MakePieProps } from './utils/make-pie';
@@ -1,6 +1,4 @@
1
1
  export declare type MakeCircleProps = {
2
- cx?: number | string;
3
- cy?: number | string;
4
- radius?: number | string;
2
+ radius: number;
5
3
  };
6
- export declare const makeCircle: ({ cx, cy, radius, }: MakeCircleProps) => string;
4
+ export declare const makeCircle: ({ radius }: MakeCircleProps) => string;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeCircle = void 0;
4
- const makeCircle = ({ cx = 50, cy = 50, radius = 50, }) => {
4
+ const makeCircle = ({ radius }) => {
5
+ const cx = radius;
6
+ const cy = radius;
5
7
  return `M ${cx} ${cy} m -${radius} 0 a ${radius} ${radius} 0 1 0 ${radius * 2} 0 ${radius} ${radius} 0 1 0 ${-radius * 2} 0`;
6
8
  };
7
9
  exports.makeCircle = makeCircle;
@@ -1,5 +1,5 @@
1
1
  export declare type MakeEllipseOptions = {
2
- rx?: number | string;
3
- ry?: number | string;
2
+ rx: number;
3
+ ry: number;
4
4
  };
5
5
  export declare const makeEllipse: ({ rx, ry }: MakeEllipseOptions) => string;
@@ -1,7 +1,5 @@
1
1
  export declare type MakeRectOptions = {
2
- x?: number;
3
- y?: number;
4
2
  width: number;
5
3
  height: number;
6
4
  };
7
- export declare const makeRect: ({ x, y, width, height }: MakeRectOptions) => string;
5
+ export declare const makeRect: ({ width, height }: MakeRectOptions) => string;
package/dist/make-rect.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeRect = void 0;
4
- const makeRect = ({ x = 0, y = 0, width, height }) => {
4
+ const makeRect = ({ width, height }) => {
5
+ const x = 0;
6
+ const y = 0;
5
7
  return `M ${x} ${y} l ${width} 0 l 0 ${height} l ${-width} 0 Z`;
6
8
  };
7
9
  exports.makeRect = makeRect;
@@ -1,4 +1,4 @@
1
- import type { Instruction } from './instructions';
1
+ import type { Instruction } from '@remotion/paths';
2
2
  export declare const joinPoints: (points: [
3
3
  number,
4
4
  number
@@ -27,17 +27,21 @@ const joinPoints = (points, { edgeRoundness, cornerRadius, roundCornerStrategy,
27
27
  ];
28
28
  if (i === 0) {
29
29
  if (edgeRoundness !== null) {
30
- return {
31
- type: 'M',
32
- x: middleOfLine[0],
33
- y: middleOfLine[1],
34
- };
30
+ return [
31
+ {
32
+ type: 'M',
33
+ x: middleOfLine[0],
34
+ y: middleOfLine[1],
35
+ },
36
+ ];
35
37
  }
36
- return {
37
- type: 'M',
38
- x,
39
- y,
40
- };
38
+ return [
39
+ {
40
+ type: 'M',
41
+ x,
42
+ y,
43
+ },
44
+ ];
41
45
  }
42
46
  const prevVector = [x - prevPoint[0], y - prevPoint[1]];
43
47
  const nextVector = [nextPoint[0] - x, nextPoint[1] - y];
@@ -46,11 +50,13 @@ const joinPoints = (points, { edgeRoundness, cornerRadius, roundCornerStrategy,
46
50
  }
47
51
  if (edgeRoundness === null) {
48
52
  if (cornerRadius === 0) {
49
- return {
50
- type: 'L',
51
- x,
52
- y,
53
- };
53
+ return [
54
+ {
55
+ type: 'L',
56
+ x,
57
+ y,
58
+ },
59
+ ];
54
60
  }
55
61
  const prevVectorMinusRadius = shortenVector(prevVector, cornerRadius);
56
62
  const prevVectorLenght = scaleVectorToLength(prevVector, cornerRadius);
@@ -71,8 +77,8 @@ const joinPoints = (points, { edgeRoundness, cornerRadius, roundCornerStrategy,
71
77
  rx: cornerRadius,
72
78
  ry: cornerRadius,
73
79
  xAxisRotation: 0,
74
- x: prevVectorLenght[0] + nextVectorMinusRadius[0],
75
- y: prevVectorLenght[1] + nextVectorMinusRadius[1],
80
+ dx: prevVectorLenght[0] + nextVectorMinusRadius[0],
81
+ dy: prevVectorLenght[1] + nextVectorMinusRadius[1],
76
82
  largeArcFlag: false,
77
83
  sweepFlag: true,
78
84
  }
@@ -95,15 +101,17 @@ const joinPoints = (points, { edgeRoundness, cornerRadius, roundCornerStrategy,
95
101
  middleOfLine[0] - nextVector[0] * edgeRoundness * 0.5,
96
102
  middleOfLine[1] - nextVector[1] * edgeRoundness * 0.5,
97
103
  ];
98
- return {
99
- type: 'C',
100
- cp1x: controlPoint1[0],
101
- cp1y: controlPoint1[1],
102
- cp2x: controlPoint2[0],
103
- cp2y: controlPoint2[1],
104
- x: middleOfLine[0],
105
- y: middleOfLine[1],
106
- };
104
+ return [
105
+ {
106
+ type: 'C',
107
+ cp1x: controlPoint1[0],
108
+ cp1y: controlPoint1[1],
109
+ cp2x: controlPoint2[0],
110
+ cp2y: controlPoint2[1],
111
+ x: middleOfLine[0],
112
+ y: middleOfLine[1],
113
+ },
114
+ ];
107
115
  })
108
116
  .flat(1);
109
117
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeCircle = void 0;
4
- const instructions_1 = require("./instructions");
4
+ const paths_1 = require("@remotion/paths");
5
5
  const makeCircle = ({ radius }) => {
6
6
  const instructions = [
7
7
  {
@@ -16,8 +16,8 @@ const makeCircle = ({ radius }) => {
16
16
  xAxisRotation: 0,
17
17
  largeArcFlag: true,
18
18
  sweepFlag: false,
19
- x: radius * 2,
20
- y: 0,
19
+ dx: radius * 2,
20
+ dy: 0,
21
21
  },
22
22
  {
23
23
  type: 'a',
@@ -26,14 +26,14 @@ const makeCircle = ({ radius }) => {
26
26
  xAxisRotation: 0,
27
27
  largeArcFlag: true,
28
28
  sweepFlag: false,
29
- x: -radius * 2,
30
- y: 0,
29
+ dx: -radius * 2,
30
+ dy: 0,
31
31
  },
32
32
  {
33
- type: 'z',
33
+ type: 'Z',
34
34
  },
35
35
  ];
36
- const path = (0, instructions_1.serializeInstructions)(instructions);
36
+ const path = (0, paths_1.serializeInstructions)(instructions);
37
37
  return {
38
38
  height: radius * 2,
39
39
  width: radius * 2,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeEllipse = void 0;
4
- const instructions_1 = require("./instructions");
4
+ const paths_1 = require("@remotion/paths");
5
5
  const makeEllipse = ({ rx, ry }) => {
6
6
  const instructions = [
7
7
  {
@@ -16,14 +16,14 @@ const makeEllipse = ({ rx, ry }) => {
16
16
  xAxisRotation: 0,
17
17
  largeArcFlag: true,
18
18
  sweepFlag: false,
19
- x: 1,
20
- y: 0,
19
+ dx: 1,
20
+ dy: 0,
21
21
  },
22
22
  {
23
- type: 'z',
23
+ type: 'Z',
24
24
  },
25
25
  ];
26
- const path = (0, instructions_1.serializeInstructions)(instructions);
26
+ const path = (0, paths_1.serializeInstructions)(instructions);
27
27
  return {
28
28
  width: rx * 2,
29
29
  height: ry * 2,
@@ -1,4 +1,4 @@
1
- import type { Instruction } from './instructions';
1
+ import type { Instruction } from '@remotion/paths';
2
2
  export declare type MakePieProps = {
3
3
  radius: number;
4
4
  progress: number;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makePie = void 0;
4
- const instructions_1 = require("./instructions");
4
+ const paths_1 = require("@remotion/paths");
5
5
  const getCoord = ({ counterClockwise, actualProgress, rotation, radius, coord, }) => {
6
6
  const factor = counterClockwise ? -1 : 1;
7
7
  const val = Math[coord === 'x' ? 'cos' : 'sin'](factor * actualProgress * Math.PI * 2 + Math.PI * 1.5 + rotation) *
@@ -94,11 +94,11 @@ const makePie = ({ progress, radius, closePath = true, counterClockwise = false,
94
94
  : null,
95
95
  closePath
96
96
  ? {
97
- type: 'z',
97
+ type: 'Z',
98
98
  }
99
99
  : null,
100
100
  ].filter(Boolean);
101
- const path = (0, instructions_1.serializeInstructions)(instructions);
101
+ const path = (0, paths_1.serializeInstructions)(instructions);
102
102
  return {
103
103
  height: radius * 2,
104
104
  width: radius * 2,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeRect = void 0;
4
- const instructions_1 = require("./instructions");
4
+ const paths_1 = require("@remotion/paths");
5
5
  const join_points_1 = require("./join-points");
6
6
  const makeRect = ({ width, height, edgeRoundness = null, cornerRadius = 0, }) => {
7
7
  const transformOrigin = [width / 2, height / 2];
@@ -14,10 +14,10 @@ const makeRect = ({ width, height, edgeRoundness = null, cornerRadius = 0, }) =>
14
14
  [0, 0],
15
15
  ], { edgeRoundness, cornerRadius, roundCornerStrategy: 'arc' }),
16
16
  {
17
- type: 'z',
17
+ type: 'Z',
18
18
  },
19
19
  ];
20
- const path = (0, instructions_1.serializeInstructions)(instructions);
20
+ const path = (0, paths_1.serializeInstructions)(instructions);
21
21
  return {
22
22
  width,
23
23
  height,
@@ -2,7 +2,7 @@
2
2
  // Copied from https://stackblitz.com/edit/svg-star-generator?file=index.js
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.makeStar = void 0;
5
- const instructions_1 = require("./instructions");
5
+ const paths_1 = require("@remotion/paths");
6
6
  const join_points_1 = require("./join-points");
7
7
  const star = ({ centerX, centerY, points, innerRadius, outerRadius, cornerRadius, edgeRoundness, }) => {
8
8
  const degreeIncrement = (Math.PI * 2) / (points * 2);
@@ -21,7 +21,7 @@ const star = ({ centerX, centerY, points, innerRadius, outerRadius, cornerRadius
21
21
  cornerRadius,
22
22
  roundCornerStrategy: cornerRadius > 0 ? 'bezier' : 'arc',
23
23
  }),
24
- { type: 'z' },
24
+ { type: 'Z' },
25
25
  ];
26
26
  };
27
27
  const makeStar = ({ points, innerRadius, outerRadius, cornerRadius = 0, edgeRoundness = null, }) => {
@@ -39,7 +39,7 @@ const makeStar = ({ points, innerRadius, outerRadius, cornerRadius = 0, edgeRoun
39
39
  edgeRoundness,
40
40
  });
41
41
  return {
42
- path: (0, instructions_1.serializeInstructions)(starPathInstructions),
42
+ path: (0, paths_1.serializeInstructions)(starPathInstructions),
43
43
  width,
44
44
  height,
45
45
  transformOrigin: `${centerX} ${centerY}`,
@@ -2,7 +2,7 @@
2
2
  // Copied from https://stackblitz.com/edit/react-triangle-svg?file=index.js
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.makeTriangle = void 0;
5
- const instructions_1 = require("./instructions");
5
+ const paths_1 = require("@remotion/paths");
6
6
  const join_points_1 = require("./join-points");
7
7
  const makeTriangle = ({ length, direction = 'right', edgeRoundness = null, cornerRadius = 0, }) => {
8
8
  const longerDimension = length;
@@ -52,10 +52,10 @@ const makeTriangle = ({ length, direction = 'right', edgeRoundness = null, corne
52
52
  roundCornerStrategy: 'bezier',
53
53
  }),
54
54
  {
55
- type: 'z',
55
+ type: 'Z',
56
56
  },
57
57
  ];
58
- const path = (0, instructions_1.serializeInstructions)(instructions);
58
+ const path = (0, paths_1.serializeInstructions)(instructions);
59
59
  return {
60
60
  path,
61
61
  instructions,
@@ -1,4 +1,4 @@
1
- import type { Instruction } from './instructions';
1
+ import type { Instruction } from '@remotion/paths';
2
2
  export declare type ShapeInfo = {
3
3
  path: string;
4
4
  width: number;
@@ -0,0 +1,10 @@
1
+ export declare type StarProps = {
2
+ centerX: number;
3
+ centerY: number;
4
+ points: number;
5
+ innerRadius: number;
6
+ outerRadius: number;
7
+ edgeRoundness: number | null;
8
+ cornerRadius: number;
9
+ };
10
+ export declare const star: ({ centerX, centerY, points, innerRadius, outerRadius, cornerRadius, edgeRoundness, }: StarProps) => string;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.star = void 0;
4
+ const instructions_1 = require("./instructions");
5
+ const join_points_1 = require("./join-points");
6
+ const polarToCartesian = ({ centerX, centerY, radius, angleInDegrees, }) => {
7
+ const angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0;
8
+ return {
9
+ x: centerX + radius * Math.cos(angleInRadians),
10
+ y: centerY + radius * Math.sin(angleInRadians),
11
+ };
12
+ };
13
+ const star = ({ centerX, centerY, points, innerRadius, outerRadius, cornerRadius, edgeRoundness, }) => {
14
+ const degreeIncrement = 360 / (points * 2);
15
+ const d = new Array(points * 2)
16
+ .fill('true')
17
+ .map((_p, i) => {
18
+ const radius = i % 2 === 0 ? outerRadius : innerRadius;
19
+ const degrees = degreeIncrement * i;
20
+ const point = polarToCartesian({
21
+ centerX,
22
+ centerY,
23
+ radius,
24
+ angleInDegrees: degrees,
25
+ });
26
+ return [point.x, point.y];
27
+ });
28
+ return (0, instructions_1.serializeInstructions)((0, join_points_1.joinPoints)([...d, d[0]], {
29
+ edgeRoundness,
30
+ cornerRadius,
31
+ roundCornerStrategy: 'arc',
32
+ }));
33
+ };
34
+ exports.star = star;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/shapes",
3
- "version": "3.3.38",
3
+ "version": "3.3.40",
4
4
  "description": "Utility functions and components for SVG shapes",
5
5
  "main": "dist/index.js",
6
6
  "sideEffects": false,
@@ -44,5 +44,8 @@
44
44
  "react": ">=16.8.0",
45
45
  "react-dom": ">=16.8.0"
46
46
  },
47
- "gitHead": "ac58695e452e58deb5c010f09bcc94d036930e6c"
47
+ "dependencies": {
48
+ "@remotion/paths": "3.3.40"
49
+ },
50
+ "gitHead": "be5f606a81761f7f8e1e191ebabd5f8d225d8c09"
48
51
  }
@@ -1,7 +0,0 @@
1
- export declare type MakeRectOptions = {
2
- x?: number;
3
- y?: number;
4
- width: number;
5
- height: number;
6
- };
7
- export declare const makeRect: ({ x, y, width, height }: MakeRectOptions) => string;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeRect = void 0;
4
- const makeRect = ({ x = 0, y = 0, width, height }) => {
5
- return `M ${x} ${y} l ${width} 0 l 0 ${height} l ${-width} 0 Z`;
6
- };
7
- exports.makeRect = makeRect;
package/dist/square.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- export declare type SquareProps = {
3
- width: number;
4
- height: number;
5
- fill?: string;
6
- style?: React.CSSProperties;
7
- };
8
- export declare const Square: React.FC<SquareProps>;
package/dist/square.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Square = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const make_square_1 = require("./make-square");
6
- const Square = ({ width, height, fill, style }) => {
7
- return ((0, jsx_runtime_1.jsx)("svg", { width: width, height: height, viewBox: `0 0 ${width} ${height}`, xmlns: "http://www.w3.org/2000/svg", style: style, "data-shape-type": "square", children: (0, jsx_runtime_1.jsx)("path", { d: (0, make_square_1.makeSquare)({
8
- width,
9
- height,
10
- }), fill: fill }) }));
11
- };
12
- exports.Square = Square;