@remotion/shapes 4.0.0-newpaths.40 → 4.1.0-alpha2

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.
Files changed (53) hide show
  1. package/dist/components/circle.d.ts +6 -1
  2. package/dist/components/circle.js +5 -0
  3. package/dist/components/ellipse.d.ts +7 -1
  4. package/dist/components/ellipse.js +6 -0
  5. package/dist/components/pie.d.ts +10 -1
  6. package/dist/components/pie.js +9 -0
  7. package/dist/components/rect.d.ts +9 -1
  8. package/dist/components/rect.js +8 -0
  9. package/dist/components/render-svg.d.ts +2 -2
  10. package/dist/components/render-svg.js +0 -1
  11. package/dist/components/star.d.ts +10 -1
  12. package/dist/components/star.js +9 -0
  13. package/dist/components/triangle.d.ts +9 -1
  14. package/dist/components/triangle.js +8 -0
  15. package/dist/utils/join-points.js +17 -7
  16. package/dist/utils/make-circle.d.ts +6 -1
  17. package/dist/utils/make-circle.js +6 -1
  18. package/dist/utils/make-ellipse.d.ts +7 -1
  19. package/dist/utils/make-ellipse.js +7 -1
  20. package/dist/utils/make-pie.d.ts +10 -1
  21. package/dist/utils/make-pie.js +10 -1
  22. package/dist/utils/make-rect.d.ts +9 -1
  23. package/dist/utils/make-rect.js +10 -2
  24. package/dist/utils/make-star.d.ts +2 -2
  25. package/dist/utils/make-star.js +10 -1
  26. package/dist/utils/make-triangle.d.ts +10 -2
  27. package/dist/utils/make-triangle.js +12 -1
  28. package/dist/utils/shape-info.d.ts +1 -1
  29. package/package.json +50 -50
  30. package/dist/Ellipse.d.ts +0 -10
  31. package/dist/Ellipse.js +0 -12
  32. package/dist/circle.d.ts +0 -10
  33. package/dist/circle.js +0 -13
  34. package/dist/components/return-type.d.ts +0 -5
  35. package/dist/components/return-type.js +0 -2
  36. package/dist/components/shape-info.d.ts +0 -5
  37. package/dist/components/shape-info.js +0 -2
  38. package/dist/make-circle.d.ts +0 -4
  39. package/dist/make-circle.js +0 -9
  40. package/dist/make-ellipse.d.ts +0 -5
  41. package/dist/make-ellipse.js +0 -7
  42. package/dist/make-rect.d.ts +0 -5
  43. package/dist/make-rect.js +0 -9
  44. package/dist/make-triangle.d.ts +0 -6
  45. package/dist/make-triangle.js +0 -14
  46. package/dist/rect.d.ts +0 -8
  47. package/dist/rect.js +0 -12
  48. package/dist/triangle.d.ts +0 -9
  49. package/dist/triangle.js +0 -13
  50. package/dist/utils/instructions.d.ts +0 -3
  51. package/dist/utils/instructions.js +0 -29
  52. package/dist/utils/star.d.ts +0 -10
  53. package/dist/utils/star.js +0 -34
@@ -1,5 +1,10 @@
1
1
  import React from 'react';
2
2
  import type { MakeCircleProps } from '../utils/make-circle';
3
3
  import type { AllShapesProps } from './render-svg';
4
- export declare type CircleProps = MakeCircleProps & AllShapesProps;
4
+ export type CircleProps = MakeCircleProps & AllShapesProps;
5
+ /**
6
+ * @description Renders an SVG element drawing a circle.
7
+ * @param {Number} radius The radius of the circle.
8
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/circle)
9
+ */
5
10
  export declare const Circle: React.FC<CircleProps>;
@@ -4,6 +4,11 @@ exports.Circle = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const make_circle_1 = require("../utils/make-circle");
6
6
  const render_svg_1 = require("./render-svg");
7
+ /**
8
+ * @description Renders an SVG element drawing a circle.
9
+ * @param {Number} radius The radius of the circle.
10
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/circle)
11
+ */
7
12
  const Circle = ({ radius, ...props }) => {
8
13
  return (0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_circle_1.makeCircle)({ radius }), ...props });
9
14
  };
@@ -1,5 +1,11 @@
1
1
  import React from 'react';
2
2
  import type { MakeEllipseOptions } from '../utils/make-ellipse';
3
3
  import type { AllShapesProps } from './render-svg';
4
- export declare type EllipseProps = MakeEllipseOptions & AllShapesProps;
4
+ export type EllipseProps = MakeEllipseOptions & AllShapesProps;
5
+ /**
6
+ * @description Renders an SVG element drawing an ellipse.
7
+ * @param {Number} rx The radius of the ellipse on the X axis.
8
+ * @param {Number} ry The radius of the ellipse on the Y axis.
9
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/ellipse)
10
+ */
5
11
  export declare const Ellipse: React.FC<EllipseProps>;
@@ -4,6 +4,12 @@ exports.Ellipse = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const make_ellipse_1 = require("../utils/make-ellipse");
6
6
  const render_svg_1 = require("./render-svg");
7
+ /**
8
+ * @description Renders an SVG element drawing an ellipse.
9
+ * @param {Number} rx The radius of the ellipse on the X axis.
10
+ * @param {Number} ry The radius of the ellipse on the Y axis.
11
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/ellipse)
12
+ */
7
13
  const Ellipse = ({ rx, ry, ...props }) => {
8
14
  return (0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_ellipse_1.makeEllipse)({ rx, ry }), ...props });
9
15
  };
@@ -1,5 +1,14 @@
1
1
  import React from 'react';
2
2
  import type { MakePieProps } from '../utils/make-pie';
3
3
  import type { AllShapesProps } from './render-svg';
4
- export declare type PieProps = MakePieProps & AllShapesProps;
4
+ export type PieProps = MakePieProps & AllShapesProps;
5
+ /**
6
+ * @description Renders an SVG element drawing a pie piece.
7
+ * @param {Number} radius The radius of the circle..
8
+ * @param {Number} progress The percentage of the circle that is filled. 0 means fully empty, 1 means fully filled.
9
+ * @param {Boolean} closePath If set to false, no path to the middle of the circle will be drawn, leading to an open arc. Default true.
10
+ * @param {Boolean} counterClockwise If set, the circle gets filled counterclockwise instead of clockwise. Default false.
11
+ * @param {Boolean} rotation Add rotation to the path. 0 means no rotation, Math.PI * 2 means 1 full clockwise rotation
12
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/pie)
13
+ */
5
14
  export declare const Pie: React.FC<PieProps>;
@@ -4,6 +4,15 @@ exports.Pie = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const make_pie_1 = require("../utils/make-pie");
6
6
  const render_svg_1 = require("./render-svg");
7
+ /**
8
+ * @description Renders an SVG element drawing a pie piece.
9
+ * @param {Number} radius The radius of the circle..
10
+ * @param {Number} progress The percentage of the circle that is filled. 0 means fully empty, 1 means fully filled.
11
+ * @param {Boolean} closePath If set to false, no path to the middle of the circle will be drawn, leading to an open arc. Default true.
12
+ * @param {Boolean} counterClockwise If set, the circle gets filled counterclockwise instead of clockwise. Default false.
13
+ * @param {Boolean} rotation Add rotation to the path. 0 means no rotation, Math.PI * 2 means 1 full clockwise rotation
14
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/pie)
15
+ */
7
16
  const Pie = ({ radius, progress, closePath, counterClockwise, rotation, ...props }) => {
8
17
  return ((0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_pie_1.makePie)({ radius, progress, closePath, counterClockwise, rotation }), ...props }));
9
18
  };
@@ -1,5 +1,13 @@
1
1
  import React from 'react';
2
2
  import type { MakeRectOptions } from '../utils/make-rect';
3
3
  import type { AllShapesProps } from './render-svg';
4
- export declare type RectProps = MakeRectOptions & AllShapesProps;
4
+ export type RectProps = MakeRectOptions & AllShapesProps;
5
+ /**
6
+ * @description Renders an SVG element containing a rectangle.
7
+ * @param {Number} width The width of the Rectangle
8
+ * @param {Number} height The height of the Rectangle
9
+ * @param {Number} cornerRadius Rounds the corner using an arc. Similar to CSS's border-radius. Cannot be used together with edgeRoundness.
10
+ * @param {null|Number} edgeRoundness Allows to modify the shape by rounding the edges using bezier curves. Default null.
11
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/rect)
12
+ */
5
13
  export declare const Rect: React.FC<RectProps>;
@@ -4,6 +4,14 @@ exports.Rect = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const make_rect_1 = require("../utils/make-rect");
6
6
  const render_svg_1 = require("./render-svg");
7
+ /**
8
+ * @description Renders an SVG element containing a rectangle.
9
+ * @param {Number} width The width of the Rectangle
10
+ * @param {Number} height The height of the Rectangle
11
+ * @param {Number} cornerRadius Rounds the corner using an arc. Similar to CSS's border-radius. Cannot be used together with edgeRoundness.
12
+ * @param {null|Number} edgeRoundness Allows to modify the shape by rounding the edges using bezier curves. Default null.
13
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/rect)
14
+ */
7
15
  const Rect = ({ width, edgeRoundness, height, cornerRadius, ...props }) => {
8
16
  return ((0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_rect_1.makeRect)({ height, width, edgeRoundness, cornerRadius }), ...props }));
9
17
  };
@@ -1,6 +1,6 @@
1
- import type { Instruction } from '@remotion/paths/dist/helpers/types';
1
+ import type { Instruction } from '@remotion/paths';
2
2
  import React from 'react';
3
- export declare type AllShapesProps = Omit<React.SVGProps<SVGPathElement>, 'width' | 'height' | 'd'> & {
3
+ export type AllShapesProps = Omit<React.SVGProps<SVGPathElement>, 'width' | 'height' | 'd'> & {
4
4
  debug?: boolean;
5
5
  pathStyle?: React.CSSProperties;
6
6
  };
@@ -25,7 +25,6 @@ const RenderSvg = ({ width, height, path, style, pathStyle, transformOrigin, deb
25
25
  if (prevInstruction.type === 'V' ||
26
26
  prevInstruction.type === 'H' ||
27
27
  prevInstruction.type === 'a' ||
28
- prevInstruction.type === 'z' ||
29
28
  prevInstruction.type === 'Z' ||
30
29
  prevInstruction.type === 't' ||
31
30
  prevInstruction.type === 'q' ||
@@ -1,5 +1,14 @@
1
1
  import React from 'react';
2
2
  import type { MakeStarProps } from '../utils/make-star';
3
3
  import type { AllShapesProps } from './render-svg';
4
- export declare type StarProps = MakeStarProps & Omit<AllShapesProps, 'points'>;
4
+ export type StarProps = MakeStarProps & Omit<AllShapesProps, 'points'>;
5
+ /**
6
+ * @description Renders an SVG element containing a star.
7
+ * @param {Number} innerRadius The inner radius of the star.
8
+ * @param {Number} outerRadius The outer radius of the star.
9
+ * @param {Number} points The amount of points of the star.
10
+ * @param {Number} cornerRadius Rounds the corner using an arc. Similar to CSS's border-radius. Cannot be used together with edgeRoundness.
11
+ * @param {null|Number} edgeRoundness Allows to modify the shape by rounding the edges using bezier curves. Default null.
12
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/star)
13
+ */
5
14
  export declare const Star: React.FC<StarProps>;
@@ -4,6 +4,15 @@ exports.Star = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const make_star_1 = require("../utils/make-star");
6
6
  const render_svg_1 = require("./render-svg");
7
+ /**
8
+ * @description Renders an SVG element containing a star.
9
+ * @param {Number} innerRadius The inner radius of the star.
10
+ * @param {Number} outerRadius The outer radius of the star.
11
+ * @param {Number} points The amount of points of the star.
12
+ * @param {Number} cornerRadius Rounds the corner using an arc. Similar to CSS's border-radius. Cannot be used together with edgeRoundness.
13
+ * @param {null|Number} edgeRoundness Allows to modify the shape by rounding the edges using bezier curves. Default null.
14
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/star)
15
+ */
7
16
  const Star = ({ innerRadius, outerRadius, points, cornerRadius, edgeRoundness, ...props }) => {
8
17
  return ((0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_star_1.makeStar)({
9
18
  innerRadius,
@@ -1,5 +1,13 @@
1
1
  import React from 'react';
2
2
  import type { MakeTriangleProps } from '../utils/make-triangle';
3
3
  import type { AllShapesProps } from './render-svg';
4
- export declare type TriangleProps = MakeTriangleProps & AllShapesProps;
4
+ export type TriangleProps = MakeTriangleProps & AllShapesProps;
5
+ /**
6
+ * @description Renders an SVG element containing a triangle with same length on all sides.
7
+ * @param {Number} length The length of one triangle side.
8
+ * @param {string} direction The direction of the triangle
9
+ * @param {null|Number} edgeRoundness Allows to modify the shape by rounding the edges using bezier curves. Default null.
10
+ * @param {Number} cornerRadius Rounds the corner using an arc. Similar to CSS's border-radius. Cannot be used together with edgeRoundness.
11
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/triangle)
12
+ */
5
13
  export declare const Triangle: React.FC<TriangleProps>;
@@ -4,6 +4,14 @@ exports.Triangle = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const make_triangle_1 = require("../utils/make-triangle");
6
6
  const render_svg_1 = require("./render-svg");
7
+ /**
8
+ * @description Renders an SVG element containing a triangle with same length on all sides.
9
+ * @param {Number} length The length of one triangle side.
10
+ * @param {string} direction The direction of the triangle
11
+ * @param {null|Number} edgeRoundness Allows to modify the shape by rounding the edges using bezier curves. Default null.
12
+ * @param {Number} cornerRadius Rounds the corner using an arc. Similar to CSS's border-radius. Cannot be used together with edgeRoundness.
13
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/triangle)
14
+ */
7
15
  const Triangle = ({ length, direction, edgeRoundness, cornerRadius, ...props }) => {
8
16
  return ((0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_triangle_1.makeTriangle)({ length, direction, edgeRoundness, cornerRadius }), ...props }));
9
17
  };
@@ -25,6 +25,8 @@ const joinPoints = (points, { edgeRoundness, cornerRadius, roundCornerStrategy,
25
25
  (x + prevPoint[0]) / 2,
26
26
  (y + prevPoint[1]) / 2,
27
27
  ];
28
+ const prevVector = [x - prevPoint[0], y - prevPoint[1]];
29
+ const nextVector = [nextPoint[0] - x, nextPoint[1] - y];
28
30
  if (i === 0) {
29
31
  if (edgeRoundness !== null) {
30
32
  return [
@@ -35,6 +37,16 @@ const joinPoints = (points, { edgeRoundness, cornerRadius, roundCornerStrategy,
35
37
  },
36
38
  ];
37
39
  }
40
+ if (cornerRadius !== 0) {
41
+ const computeRadius = shortenVector(nextVector, cornerRadius);
42
+ return [
43
+ {
44
+ type: 'M',
45
+ x: computeRadius[0] + x,
46
+ y: computeRadius[1] + y,
47
+ },
48
+ ];
49
+ }
38
50
  return [
39
51
  {
40
52
  type: 'M',
@@ -43,8 +55,6 @@ const joinPoints = (points, { edgeRoundness, cornerRadius, roundCornerStrategy,
43
55
  },
44
56
  ];
45
57
  }
46
- const prevVector = [x - prevPoint[0], y - prevPoint[1]];
47
- const nextVector = [nextPoint[0] - x, nextPoint[1] - y];
48
58
  if (cornerRadius && edgeRoundness !== null) {
49
59
  throw new Error(`"cornerRadius" and "edgeRoundness" cannot be specified at the same time.`);
50
60
  }
@@ -59,7 +69,7 @@ const joinPoints = (points, { edgeRoundness, cornerRadius, roundCornerStrategy,
59
69
  ];
60
70
  }
61
71
  const prevVectorMinusRadius = shortenVector(prevVector, cornerRadius);
62
- const prevVectorLenght = scaleVectorToLength(prevVector, cornerRadius);
72
+ const prevVectorLength = scaleVectorToLength(prevVector, cornerRadius);
63
73
  const nextVectorMinusRadius = scaleVectorToLength(nextVector, cornerRadius);
64
74
  const firstDraw = [
65
75
  prevPoint[0] + prevVectorMinusRadius[0],
@@ -77,15 +87,15 @@ const joinPoints = (points, { edgeRoundness, cornerRadius, roundCornerStrategy,
77
87
  rx: cornerRadius,
78
88
  ry: cornerRadius,
79
89
  xAxisRotation: 0,
80
- dx: prevVectorLenght[0] + nextVectorMinusRadius[0],
81
- dy: prevVectorLenght[1] + nextVectorMinusRadius[1],
90
+ dx: prevVectorLength[0] + nextVectorMinusRadius[0],
91
+ dy: prevVectorLength[1] + nextVectorMinusRadius[1],
82
92
  largeArcFlag: false,
83
93
  sweepFlag: true,
84
94
  }
85
95
  : {
86
96
  type: 'C',
87
- x: firstDraw[0] + prevVectorLenght[0] + nextVectorMinusRadius[0],
88
- y: firstDraw[1] + prevVectorLenght[1] + nextVectorMinusRadius[1],
97
+ x: firstDraw[0] + prevVectorLength[0] + nextVectorMinusRadius[0],
98
+ y: firstDraw[1] + prevVectorLength[1] + nextVectorMinusRadius[1],
89
99
  cp1x: x,
90
100
  cp1y: y,
91
101
  cp2x: x,
@@ -1,5 +1,10 @@
1
1
  import type { ShapeInfo } from './shape-info';
2
- export declare type MakeCircleProps = {
2
+ export type MakeCircleProps = {
3
3
  radius: number;
4
4
  };
5
+ /**
6
+ * @description Generates a circle SVG path.
7
+ * @param {Number} radius The radius of the circle.
8
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/make-circle)
9
+ */
5
10
  export declare const makeCircle: ({ radius }: MakeCircleProps) => ShapeInfo;
@@ -2,6 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeCircle = void 0;
4
4
  const paths_1 = require("@remotion/paths");
5
+ /**
6
+ * @description Generates a circle SVG path.
7
+ * @param {Number} radius The radius of the circle.
8
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/make-circle)
9
+ */
5
10
  const makeCircle = ({ radius }) => {
6
11
  const instructions = [
7
12
  {
@@ -30,7 +35,7 @@ const makeCircle = ({ radius }) => {
30
35
  dy: 0,
31
36
  },
32
37
  {
33
- type: 'z',
38
+ type: 'Z',
34
39
  },
35
40
  ];
36
41
  const path = (0, paths_1.serializeInstructions)(instructions);
@@ -1,6 +1,12 @@
1
1
  import type { ShapeInfo } from './shape-info';
2
- export declare type MakeEllipseOptions = {
2
+ export type MakeEllipseOptions = {
3
3
  rx: number;
4
4
  ry: number;
5
5
  };
6
+ /**
7
+ * @description Generates an ellipse SVG path.
8
+ * @param {Number} rx The radius of the ellipse on the X axis.
9
+ * @param {Number} ry The radius of the ellipse on the Y axis.
10
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/make-ellipse)
11
+ */
6
12
  export declare const makeEllipse: ({ rx, ry }: MakeEllipseOptions) => ShapeInfo;
@@ -2,6 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeEllipse = void 0;
4
4
  const paths_1 = require("@remotion/paths");
5
+ /**
6
+ * @description Generates an ellipse SVG path.
7
+ * @param {Number} rx The radius of the ellipse on the X axis.
8
+ * @param {Number} ry The radius of the ellipse on the Y axis.
9
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/make-ellipse)
10
+ */
5
11
  const makeEllipse = ({ rx, ry }) => {
6
12
  const instructions = [
7
13
  {
@@ -20,7 +26,7 @@ const makeEllipse = ({ rx, ry }) => {
20
26
  dy: 0,
21
27
  },
22
28
  {
23
- type: 'z',
29
+ type: 'Z',
24
30
  },
25
31
  ];
26
32
  const path = (0, paths_1.serializeInstructions)(instructions);
@@ -1,11 +1,20 @@
1
1
  import type { Instruction } from '@remotion/paths';
2
- export declare type MakePieProps = {
2
+ export type MakePieProps = {
3
3
  radius: number;
4
4
  progress: number;
5
5
  closePath?: boolean;
6
6
  counterClockwise?: boolean;
7
7
  rotation?: number;
8
8
  };
9
+ /**
10
+ * @description Generates a piece of pie SVG path.
11
+ * @param {Number} radius The radius of the circle..
12
+ * @param {Number} progress The percentage of the circle that is filled. 0 means fully empty, 1 means fully filled.
13
+ * @param {Boolean} closePath If set to false, no path to the middle of the circle will be drawn, leading to an open arc. Default true.
14
+ * @param {Boolean} counterClockwise If set, the circle gets filled counterclockwise instead of clockwise. Default false.
15
+ * @param {Boolean} rotation Add rotation to the path. 0 means no rotation, Math.PI * 2 means 1 full clockwise rotation
16
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/make-pie)
17
+ */
9
18
  export declare const makePie: ({ progress, radius, closePath, counterClockwise, rotation, }: MakePieProps) => {
10
19
  height: number;
11
20
  width: number;
@@ -10,6 +10,15 @@ const getCoord = ({ counterClockwise, actualProgress, rotation, radius, coord, }
10
10
  const rounded = Math.round(val * 100000) / 100000;
11
11
  return rounded;
12
12
  };
13
+ /**
14
+ * @description Generates a piece of pie SVG path.
15
+ * @param {Number} radius The radius of the circle..
16
+ * @param {Number} progress The percentage of the circle that is filled. 0 means fully empty, 1 means fully filled.
17
+ * @param {Boolean} closePath If set to false, no path to the middle of the circle will be drawn, leading to an open arc. Default true.
18
+ * @param {Boolean} counterClockwise If set, the circle gets filled counterclockwise instead of clockwise. Default false.
19
+ * @param {Boolean} rotation Add rotation to the path. 0 means no rotation, Math.PI * 2 means 1 full clockwise rotation
20
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/make-pie)
21
+ */
13
22
  const makePie = ({ progress, radius, closePath = true, counterClockwise = false, rotation = 0, }) => {
14
23
  const actualProgress = Math.min(Math.max(progress, 0), 1);
15
24
  const endAngleX = getCoord({
@@ -94,7 +103,7 @@ const makePie = ({ progress, radius, closePath = true, counterClockwise = false,
94
103
  : null,
95
104
  closePath
96
105
  ? {
97
- type: 'z',
106
+ type: 'Z',
98
107
  }
99
108
  : null,
100
109
  ].filter(Boolean);
@@ -1,8 +1,16 @@
1
1
  import type { ShapeInfo } from './shape-info';
2
- export declare type MakeRectOptions = {
2
+ export type MakeRectOptions = {
3
3
  width: number;
4
4
  height: number;
5
5
  edgeRoundness?: number | null;
6
6
  cornerRadius?: number;
7
7
  };
8
+ /**
9
+ * @description Generates an SVG rectangle.
10
+ * @param {Number} width The width of the rectangle.
11
+ * @param {Number} height The height of the rectangle
12
+ * @param {Number | null} edgeRoundness Allows to modify the shape by rounding the edges using bezier curves. Default null.
13
+ * @param {Number} cornerRadius * @param {Number} cornerRadius Rounds the corner using an arc. Similar to CSS's border-radius. Cannot be used together with edgeRoundness.
14
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/make-rect)
15
+ */
8
16
  export declare const makeRect: ({ width, height, edgeRoundness, cornerRadius, }: MakeRectOptions) => ShapeInfo;
@@ -3,18 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeRect = void 0;
4
4
  const paths_1 = require("@remotion/paths");
5
5
  const join_points_1 = require("./join-points");
6
+ /**
7
+ * @description Generates an SVG rectangle.
8
+ * @param {Number} width The width of the rectangle.
9
+ * @param {Number} height The height of the rectangle
10
+ * @param {Number | null} edgeRoundness Allows to modify the shape by rounding the edges using bezier curves. Default null.
11
+ * @param {Number} cornerRadius * @param {Number} cornerRadius Rounds the corner using an arc. Similar to CSS's border-radius. Cannot be used together with edgeRoundness.
12
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/make-rect)
13
+ */
6
14
  const makeRect = ({ width, height, edgeRoundness = null, cornerRadius = 0, }) => {
7
15
  const transformOrigin = [width / 2, height / 2];
8
16
  const instructions = [
9
17
  ...(0, join_points_1.joinPoints)([
10
- [0, 0],
18
+ [cornerRadius, 0],
11
19
  [width, 0],
12
20
  [width, height],
13
21
  [0, height],
14
22
  [0, 0],
15
23
  ], { edgeRoundness, cornerRadius, roundCornerStrategy: 'arc' }),
16
24
  {
17
- type: 'z',
25
+ type: 'Z',
18
26
  },
19
27
  ];
20
28
  const path = (0, paths_1.serializeInstructions)(instructions);
@@ -1,12 +1,12 @@
1
1
  import type { ShapeInfo } from './shape-info';
2
- export declare type MakeStarProps = {
2
+ export type MakeStarProps = {
3
3
  points: number;
4
4
  innerRadius: number;
5
5
  outerRadius: number;
6
6
  edgeRoundness?: number | null;
7
7
  cornerRadius?: number;
8
8
  };
9
- export declare type StarProps = {
9
+ export type StarProps = {
10
10
  centerX: number;
11
11
  centerY: number;
12
12
  points: number;
@@ -4,6 +4,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.makeStar = void 0;
5
5
  const paths_1 = require("@remotion/paths");
6
6
  const join_points_1 = require("./join-points");
7
+ /**
8
+ * @description Generates a star SVG path.
9
+ * @param {Number} innerRadius The inner radius of the star.
10
+ * @param {Number} outerRadius The outer radius of the star.
11
+ * @param {Number} points The amount of points of the star.
12
+ * @param {Number} cornerRadius Rounds the corner using an arc. Similar to CSS's border-radius. Cannot be used together with edgeRoundness.
13
+ * @param {null|Number} edgeRoundness Allows to modify the shape by rounding the edges using bezier curves. Default null.
14
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/make-star)
15
+ */
7
16
  const star = ({ centerX, centerY, points, innerRadius, outerRadius, cornerRadius, edgeRoundness, }) => {
8
17
  const degreeIncrement = (Math.PI * 2) / (points * 2);
9
18
  const d = new Array(points * 2).fill(true).map((_p, i) => {
@@ -21,7 +30,7 @@ const star = ({ centerX, centerY, points, innerRadius, outerRadius, cornerRadius
21
30
  cornerRadius,
22
31
  roundCornerStrategy: cornerRadius > 0 ? 'bezier' : 'arc',
23
32
  }),
24
- { type: 'z' },
33
+ { type: 'Z' },
25
34
  ];
26
35
  };
27
36
  const makeStar = ({ points, innerRadius, outerRadius, cornerRadius = 0, edgeRoundness = null, }) => {
@@ -1,10 +1,18 @@
1
1
  import type { ShapeInfo } from './shape-info';
2
- declare type Direction = 'right' | 'left' | 'up' | 'down';
3
- export declare type MakeTriangleProps = {
2
+ type Direction = 'right' | 'left' | 'up' | 'down';
3
+ export type MakeTriangleProps = {
4
4
  length: number;
5
5
  direction: Direction;
6
6
  edgeRoundness?: number | null;
7
7
  cornerRadius?: number;
8
8
  };
9
+ /**
10
+ * @description Generates an SVG path for a triangle with the same length on all sides.
11
+ * @param {Number} length The length of one triangle side.
12
+ * @param {string} direction The direction of the triangle
13
+ * @param {null|Number} edgeRoundness Allows to modify the shape by rounding the edges using bezier curves. Default null.
14
+ * @param {Number} cornerRadius Rounds the corner using an arc. Similar to CSS's border-radius. Cannot be used together with edgeRoundness.
15
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/make-triangle)
16
+ */
9
17
  export declare const makeTriangle: ({ length, direction, edgeRoundness, cornerRadius, }: MakeTriangleProps) => ShapeInfo;
10
18
  export {};
@@ -4,7 +4,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.makeTriangle = void 0;
5
5
  const paths_1 = require("@remotion/paths");
6
6
  const join_points_1 = require("./join-points");
7
+ /**
8
+ * @description Generates an SVG path for a triangle with the same length on all sides.
9
+ * @param {Number} length The length of one triangle side.
10
+ * @param {string} direction The direction of the triangle
11
+ * @param {null|Number} edgeRoundness Allows to modify the shape by rounding the edges using bezier curves. Default null.
12
+ * @param {Number} cornerRadius Rounds the corner using an arc. Similar to CSS's border-radius. Cannot be used together with edgeRoundness.
13
+ * @see [Documentation](https://www.remotion.dev/docs/shapes/make-triangle)
14
+ */
7
15
  const makeTriangle = ({ length, direction = 'right', edgeRoundness = null, cornerRadius = 0, }) => {
16
+ if (typeof length !== 'number') {
17
+ throw new Error(`"length" of a triangle must be a number, got ${JSON.stringify(length)}`);
18
+ }
8
19
  const longerDimension = length;
9
20
  const shorterSize = Math.sqrt(length ** 2 * 0.75); // Calculated on paper;
10
21
  const points = {
@@ -52,7 +63,7 @@ const makeTriangle = ({ length, direction = 'right', edgeRoundness = null, corne
52
63
  roundCornerStrategy: 'bezier',
53
64
  }),
54
65
  {
55
- type: 'z',
66
+ type: 'Z',
56
67
  },
57
68
  ];
58
69
  const path = (0, paths_1.serializeInstructions)(instructions);
@@ -1,5 +1,5 @@
1
1
  import type { Instruction } from '@remotion/paths';
2
- export declare type ShapeInfo = {
2
+ export type ShapeInfo = {
3
3
  path: string;
4
4
  width: number;
5
5
  height: number;
package/package.json CHANGED
@@ -1,51 +1,51 @@
1
1
  {
2
- "name": "@remotion/shapes",
3
- "version": "4.0.0-newpaths.40+09405cced",
4
- "description": "Utility functions and components for SVG shapes",
5
- "main": "dist/index.js",
6
- "sideEffects": false,
7
- "scripts": {
8
- "lint": "eslint src --ext ts,tsx",
9
- "watch": "tsc -w",
10
- "build": "tsc -d",
11
- "test": "vitest --run"
12
- },
13
- "author": "Alex Fernandez, Jonny Burger <jonny@remotion.dev>",
14
- "license": "MIT",
15
- "repository": {
16
- "url": "https://github.com/remotion-dev/remotion"
17
- },
18
- "bugs": {
19
- "url": "https://github.com/remotion-dev/remotion/issues"
20
- },
21
- "devDependencies": {
22
- "@jonny/eslint-config": "3.0.266",
23
- "@testing-library/react": "^13.4.0",
24
- "@types/node": "^16.7.5",
25
- "@types/react": "18.0.26",
26
- "@vitejs/plugin-react": "^2.0.0",
27
- "eslint": "8.25.0",
28
- "prettier": "^2.7.1",
29
- "prettier-plugin-organize-imports": "^2.3.4",
30
- "react": "18.0.0",
31
- "react-dom": "18.0.0",
32
- "typescript": "^4.7.0",
33
- "vitest": "0.24.3"
34
- },
35
- "keywords": [
36
- "svg",
37
- "path",
38
- "utilities"
39
- ],
40
- "publishConfig": {
41
- "access": "public"
42
- },
43
- "peerDependencies": {
44
- "react": ">=16.8.0",
45
- "react-dom": ">=16.8.0"
46
- },
47
- "dependencies": {
48
- "@remotion/paths": "4.0.0-newpaths.40+09405cced"
49
- },
50
- "gitHead": "09405cced148038402b72b568f349e0bc7bbb949"
51
- }
2
+ "name": "@remotion/shapes",
3
+ "version": "4.1.0-alpha2",
4
+ "description": "Utility functions and components for SVG shapes",
5
+ "main": "dist/index.js",
6
+ "sideEffects": false,
7
+ "author": "Alex Fernandez, Jonny Burger <jonny@remotion.dev>",
8
+ "license": "MIT",
9
+ "repository": {
10
+ "url": "https://github.com/remotion-dev/remotion"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/remotion-dev/remotion/issues"
14
+ },
15
+ "devDependencies": {
16
+ "@jonny/eslint-config": "3.0.266",
17
+ "@testing-library/react": "^13.4.0",
18
+ "@types/node": "18.14.6",
19
+ "@types/react": "18.0.26",
20
+ "@vitejs/plugin-react": "^2.0.0",
21
+ "eslint": "8.42.0",
22
+ "prettier": "^2.7.1",
23
+ "prettier-plugin-organize-imports": "^2.3.4",
24
+ "react": "18.0.0",
25
+ "react-dom": "18.0.0",
26
+ "typescript": "4.9.5",
27
+ "vitest": "0.31.1"
28
+ },
29
+ "keywords": [
30
+ "svg",
31
+ "path",
32
+ "utilities"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "peerDependencies": {
38
+ "react": ">=16.8.0",
39
+ "react-dom": ">=16.8.0"
40
+ },
41
+ "dependencies": {
42
+ "@remotion/paths": "4.1.0-alpha2"
43
+ },
44
+ "scripts": {
45
+ "formatting": "prettier src --check",
46
+ "lint": "eslint src --ext ts,tsx",
47
+ "watch": "tsc -w",
48
+ "build": "tsc -d",
49
+ "test": "vitest --run"
50
+ }
51
+ }
package/dist/Ellipse.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- export declare type EllipseProps = React.SVGProps<SVGPathElement> & {
3
- rx: number;
4
- ry: number;
5
- fill?: string;
6
- stroke?: string;
7
- strokeWidth?: number;
8
- style?: React.CSSProperties;
9
- };
10
- export declare const Ellipse: React.FC<EllipseProps>;
package/dist/Ellipse.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Ellipse = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const make_ellipse_1 = require("./make-ellipse");
6
- const Ellipse = ({ fill, stroke, strokeWidth, rx, ry, style, }) => {
7
- return ((0, jsx_runtime_1.jsx)("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", children: (0, jsx_runtime_1.jsx)("path", { d: (0, make_ellipse_1.makeEllipse)({
8
- rx,
9
- ry,
10
- }), fill: fill, stroke: stroke, strokeWidth: strokeWidth }) }));
11
- };
12
- exports.Ellipse = Ellipse;
package/dist/circle.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- export declare type CircleProps = React.SVGProps<SVGPathElement> & {
3
- width: number;
4
- height: number;
5
- fill?: string;
6
- stroke?: string;
7
- strokeWidth?: number;
8
- style?: React.CSSProperties;
9
- };
10
- export declare const Circle: React.FC<CircleProps>;
package/dist/circle.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Circle = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const make_circle_1 = require("./make-circle");
6
- const Circle = ({ width, height, fill, stroke, strokeWidth, 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": "circle", children: (0, jsx_runtime_1.jsx)("path", { d: (0, make_circle_1.makeCircle)({
8
- cx: 50,
9
- cy: 50,
10
- radius: 50,
11
- }), fill: fill, stroke: stroke, strokeWidth: strokeWidth }) }));
12
- };
13
- exports.Circle = Circle;
@@ -1,5 +0,0 @@
1
- export declare type ShapeInfo = {
2
- path: string;
3
- width: string;
4
- height: string;
5
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- export declare type ShapeInfo = {
2
- path: string;
3
- width: number;
4
- height: number;
5
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +0,0 @@
1
- export declare type MakeCircleProps = {
2
- radius: number;
3
- };
4
- export declare const makeCircle: ({ radius }: MakeCircleProps) => string;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeCircle = void 0;
4
- const makeCircle = ({ radius }) => {
5
- const cx = radius;
6
- const cy = radius;
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`;
8
- };
9
- exports.makeCircle = makeCircle;
@@ -1,5 +0,0 @@
1
- export declare type MakeEllipseOptions = {
2
- rx: number;
3
- ry: number;
4
- };
5
- export declare const makeEllipse: ({ rx, ry }: MakeEllipseOptions) => string;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeEllipse = void 0;
4
- const makeEllipse = ({ rx = 50, ry = 50 }) => {
5
- return `M ${rx} ${0} a ${rx} ${ry} 0 1 0 1 0`;
6
- };
7
- exports.makeEllipse = makeEllipse;
@@ -1,5 +0,0 @@
1
- export declare type MakeRectOptions = {
2
- width: number;
3
- height: number;
4
- };
5
- export declare const makeRect: ({ width, height }: MakeRectOptions) => string;
package/dist/make-rect.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeRect = void 0;
4
- const makeRect = ({ width, height }) => {
5
- const x = 0;
6
- const y = 0;
7
- return `M ${x} ${y} l ${width} 0 l 0 ${height} l ${-width} 0 Z`;
8
- };
9
- exports.makeRect = makeRect;
@@ -1,6 +0,0 @@
1
- export declare type MakeTriangleProps = {
2
- width: number;
3
- height: number;
4
- direction: 'right' | 'left' | 'top' | 'bottom';
5
- };
6
- export declare const makeTriangle: ({ width, height, direction, }: MakeTriangleProps) => string;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- // Copied from https://stackblitz.com/edit/react-triangle-svg?file=index.js
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.makeTriangle = void 0;
5
- const makeTriangle = ({ width, height, direction = 'right', }) => {
6
- const points = {
7
- top: [`${width / 2} 0`, 'L', `0 ${height}`, 'L', `${width} ${height}`],
8
- right: [`0 0`, 'L', `0 ${height}`, 'L', `${width} ${height / 2}`],
9
- bottom: [`0 0`, 'L', `${width} 0`, 'L', `${width / 2} ${height}`],
10
- left: [`${width} 0`, 'L', `${width} ${height}`, 'L', `0 ${height / 2}`],
11
- };
12
- return `M ${points[direction].join(' ')} z`;
13
- };
14
- exports.makeTriangle = makeTriangle;
package/dist/rect.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 Rect: React.FC<SquareProps>;
package/dist/rect.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Rect = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const make_rect_1 = require("./make-rect");
6
- const Rect = ({ 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": "rect", children: (0, jsx_runtime_1.jsx)("path", { d: (0, make_rect_1.makeRect)({
8
- width,
9
- height,
10
- }), fill: fill }) }));
11
- };
12
- exports.Rect = Rect;
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- export declare type TriangleProps = {
3
- width: number;
4
- height: number;
5
- fill?: string;
6
- direction: 'right' | 'left' | 'top' | 'bottom';
7
- style?: React.CSSProperties;
8
- };
9
- export declare const Triangle: React.FC<TriangleProps>;
package/dist/triangle.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Triangle = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const make_triangle_1 = require("./make-triangle");
6
- const Triangle = ({ width, height, fill, direction, 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": "triangle", children: (0, jsx_runtime_1.jsx)("path", { d: (0, make_triangle_1.makeTriangle)({
8
- width,
9
- height,
10
- direction,
11
- }), fill: fill }) }));
12
- };
13
- exports.Triangle = Triangle;
@@ -1,3 +0,0 @@
1
- import type { Instruction } from '@remotion/paths';
2
- export declare const serializeInstructions: (instructions: Instruction[]) => string;
3
- export declare const serializeInstruction: (instruction: Instruction) => string;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serializeInstruction = exports.serializeInstructions = void 0;
4
- const serializeInstructions = (instructions) => {
5
- return instructions.map((i) => (0, exports.serializeInstruction)(i)).join(' ');
6
- };
7
- exports.serializeInstructions = serializeInstructions;
8
- const serializeInstruction = (instruction) => {
9
- if (instruction.type === 'M') {
10
- return `M ${instruction.x} ${instruction.y}`;
11
- }
12
- if (instruction.type === 'L') {
13
- return `L ${instruction.x} ${instruction.y}`;
14
- }
15
- if (instruction.type === 'C') {
16
- return `C ${instruction.cp1x} ${instruction.cp1y} ${instruction.cp2x} ${instruction.cp2y} ${instruction.x} ${instruction.y}`;
17
- }
18
- if (instruction.type === 'a') {
19
- return `a ${instruction.rx} ${instruction.ry} ${instruction.xAxisRotation} ${Number(instruction.largeArcFlag)} ${Number(instruction.sweepFlag ? 1 : 0)} ${instruction.x} ${instruction.y}`;
20
- }
21
- if (instruction.type === 'A') {
22
- return `A ${instruction.rx} ${instruction.ry} ${instruction.xAxisRotation} ${Number(instruction.largeArcFlag)} ${Number(instruction.sweepFlag ? 1 : 0)} ${instruction.x} ${instruction.y}`;
23
- }
24
- if (instruction.type === 'z') {
25
- return 'z';
26
- }
27
- throw new Error('not implemented');
28
- };
29
- exports.serializeInstruction = serializeInstruction;
@@ -1,10 +0,0 @@
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;
@@ -1,34 +0,0 @@
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;