@remotion/shapes 3.3.37 → 3.3.38

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 (69) hide show
  1. package/dist/components/pie.d.ts +5 -0
  2. package/dist/components/pie.js +10 -0
  3. package/dist/components/render-svg.js +3 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +5 -1
  6. package/dist/make-circle.d.ts +4 -2
  7. package/dist/make-circle.js +1 -3
  8. package/dist/make-ellipse.d.ts +2 -2
  9. package/dist/make-rect.d.ts +3 -1
  10. package/dist/make-rect.js +1 -3
  11. package/dist/make-square.d.ts +7 -0
  12. package/{package/dist/make-rect.js → dist/make-square.js} +1 -3
  13. package/{package/dist/rect.d.ts → dist/square.d.ts} +1 -1
  14. package/{package/dist/rect.js → dist/square.js} +5 -5
  15. package/dist/utils/instructions.d.ts +10 -3
  16. package/dist/utils/instructions.js +8 -4
  17. package/dist/utils/make-circle.js +4 -6
  18. package/dist/utils/make-ellipse.js +3 -0
  19. package/dist/utils/make-pie.d.ts +15 -0
  20. package/dist/utils/make-pie.js +110 -0
  21. package/dist/utils/make-rect.js +12 -7
  22. package/dist/utils/make-star.js +8 -5
  23. package/dist/utils/make-triangle.js +10 -5
  24. package/package.json +2 -2
  25. package/dist/components/return-type.d.ts +0 -5
  26. package/dist/components/return-type.js +0 -2
  27. package/dist/components/shape-info.d.ts +0 -5
  28. package/dist/components/shape-info.js +0 -2
  29. package/dist/utils/star.d.ts +0 -10
  30. package/dist/utils/star.js +0 -34
  31. package/package/dist/Ellipse.d.ts +0 -10
  32. package/package/dist/Ellipse.js +0 -12
  33. package/package/dist/circle.d.ts +0 -10
  34. package/package/dist/circle.js +0 -13
  35. package/package/dist/components/circle.d.ts +0 -5
  36. package/package/dist/components/circle.js +0 -10
  37. package/package/dist/components/ellipse.d.ts +0 -5
  38. package/package/dist/components/ellipse.js +0 -10
  39. package/package/dist/components/rect.d.ts +0 -5
  40. package/package/dist/components/rect.js +0 -10
  41. package/package/dist/components/render-svg.d.ts +0 -12
  42. package/package/dist/components/render-svg.js +0 -21
  43. package/package/dist/components/return-type.d.ts +0 -5
  44. package/package/dist/components/return-type.js +0 -2
  45. package/package/dist/components/shape-info.d.ts +0 -5
  46. package/package/dist/components/shape-info.js +0 -2
  47. package/package/dist/components/triangle.d.ts +0 -5
  48. package/package/dist/components/triangle.js +0 -10
  49. package/package/dist/index.d.ts +0 -8
  50. package/package/dist/index.js +0 -19
  51. package/package/dist/make-circle.d.ts +0 -4
  52. package/package/dist/make-circle.js +0 -9
  53. package/package/dist/make-ellipse.d.ts +0 -5
  54. package/package/dist/make-ellipse.js +0 -7
  55. package/package/dist/make-rect.d.ts +0 -5
  56. package/package/dist/make-triangle.d.ts +0 -6
  57. package/package/dist/make-triangle.js +0 -14
  58. package/package/dist/triangle.d.ts +0 -9
  59. package/package/dist/triangle.js +0 -13
  60. package/package/dist/utils/make-circle.d.ts +0 -5
  61. package/package/dist/utils/make-circle.js +0 -12
  62. package/package/dist/utils/make-ellipse.d.ts +0 -6
  63. package/package/dist/utils/make-ellipse.js +0 -12
  64. package/package/dist/utils/make-rect.d.ts +0 -6
  65. package/package/dist/utils/make-rect.js +0 -12
  66. package/package/dist/utils/make-triangle.d.ts +0 -6
  67. package/package/dist/utils/make-triangle.js +0 -57
  68. package/package/dist/utils/shape-info.d.ts +0 -6
  69. package/package/dist/utils/shape-info.js +0 -2
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import type { MakePieProps } from '../utils/make-pie';
3
+ import type { AllShapesProps } from './render-svg';
4
+ export declare type PieProps = MakePieProps & AllShapesProps;
5
+ export declare const Pie: React.FC<PieProps>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pie = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const make_pie_1 = require("../utils/make-pie");
6
+ const render_svg_1 = require("./render-svg");
7
+ const Pie = ({ radius, progress, closePath, counterClockwise, rotation, ...props }) => {
8
+ return ((0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_pie_1.makePie)({ radius, progress, closePath, counterClockwise, rotation }), ...props }));
9
+ };
10
+ exports.Pie = Pie;
@@ -22,6 +22,9 @@ 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') {
26
+ return null;
27
+ }
25
28
  const prevX = prevInstruction.x;
26
29
  const prevY = prevInstruction.y;
27
30
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("path", { d: `M ${prevX} ${prevY} ${i.cp1x} ${i.cp1y}`, strokeWidth: 2, stroke: "rgba(0, 0, 0, 0.4)" }), (0, jsx_runtime_1.jsx)("path", { d: `M ${i.x} ${i.y} ${i.cp2x} ${i.cp2y}`, strokeWidth: 2, stroke: "rgba(0, 0, 0, 0.4)" }), (0, jsx_runtime_1.jsx)("circle", { cx: i.cp1x, cy: i.cp1y, r: 3, fill: "white", strokeWidth: 2, stroke: "black" }), (0, jsx_runtime_1.jsx)("circle", { cx: i.cp2x, cy: i.cp2y, r: 3, strokeWidth: 2, fill: "white", stroke: "black" })] }));
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  export { Circle, CircleProps } from './components/circle';
2
2
  export { Ellipse, EllipseProps } from './components/ellipse';
3
+ export { Pie, PieProps } from './components/pie';
3
4
  export { Rect, RectProps } from './components/rect';
4
5
  export { Star, StarProps } from './components/star';
5
6
  export { Triangle, TriangleProps } from './components/triangle';
6
7
  export { Instruction } from './utils/instructions';
7
8
  export { makeCircle, MakeCircleProps } from './utils/make-circle';
8
9
  export { makeEllipse, MakeEllipseOptions } from './utils/make-ellipse';
10
+ export { makePie, MakePieProps } from './utils/make-pie';
9
11
  export { makeRect, MakeRectOptions } from './utils/make-rect';
10
12
  export { makeStar, MakeStarProps } from './utils/make-star';
11
13
  export { makeTriangle, MakeTriangleProps } from './utils/make-triangle';
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeTriangle = exports.makeStar = exports.makeRect = exports.makeEllipse = exports.makeCircle = exports.Triangle = exports.Star = exports.Rect = exports.Ellipse = exports.Circle = void 0;
3
+ exports.makeTriangle = exports.makeStar = exports.makeRect = exports.makePie = exports.makeEllipse = exports.makeCircle = exports.Triangle = exports.Star = exports.Rect = exports.Pie = exports.Ellipse = exports.Circle = void 0;
4
4
  var circle_1 = require("./components/circle");
5
5
  Object.defineProperty(exports, "Circle", { enumerable: true, get: function () { return circle_1.Circle; } });
6
6
  var ellipse_1 = require("./components/ellipse");
7
7
  Object.defineProperty(exports, "Ellipse", { enumerable: true, get: function () { return ellipse_1.Ellipse; } });
8
+ var pie_1 = require("./components/pie");
9
+ Object.defineProperty(exports, "Pie", { enumerable: true, get: function () { return pie_1.Pie; } });
8
10
  var rect_1 = require("./components/rect");
9
11
  Object.defineProperty(exports, "Rect", { enumerable: true, get: function () { return rect_1.Rect; } });
10
12
  var star_1 = require("./components/star");
@@ -15,6 +17,8 @@ var make_circle_1 = require("./utils/make-circle");
15
17
  Object.defineProperty(exports, "makeCircle", { enumerable: true, get: function () { return make_circle_1.makeCircle; } });
16
18
  var make_ellipse_1 = require("./utils/make-ellipse");
17
19
  Object.defineProperty(exports, "makeEllipse", { enumerable: true, get: function () { return make_ellipse_1.makeEllipse; } });
20
+ var make_pie_1 = require("./utils/make-pie");
21
+ Object.defineProperty(exports, "makePie", { enumerable: true, get: function () { return make_pie_1.makePie; } });
18
22
  var make_rect_1 = require("./utils/make-rect");
19
23
  Object.defineProperty(exports, "makeRect", { enumerable: true, get: function () { return make_rect_1.makeRect; } });
20
24
  var make_star_1 = require("./utils/make-star");
@@ -1,4 +1,6 @@
1
1
  export declare type MakeCircleProps = {
2
- radius: number;
2
+ cx?: number | string;
3
+ cy?: number | string;
4
+ radius?: number | string;
3
5
  };
4
- export declare const makeCircle: ({ radius }: MakeCircleProps) => string;
6
+ export declare const makeCircle: ({ cx, cy, radius, }: MakeCircleProps) => string;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeCircle = void 0;
4
- const makeCircle = ({ radius }) => {
5
- const cx = radius;
6
- const cy = radius;
4
+ const makeCircle = ({ cx = 50, cy = 50, radius = 50, }) => {
7
5
  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
6
  };
9
7
  exports.makeCircle = makeCircle;
@@ -1,5 +1,5 @@
1
1
  export declare type MakeEllipseOptions = {
2
- rx: number;
3
- ry: number;
2
+ rx?: number | string;
3
+ ry?: number | string;
4
4
  };
5
5
  export declare const makeEllipse: ({ rx, ry }: MakeEllipseOptions) => string;
@@ -1,5 +1,7 @@
1
1
  export declare type MakeRectOptions = {
2
+ x?: number;
3
+ y?: number;
2
4
  width: number;
3
5
  height: number;
4
6
  };
5
- export declare const makeRect: ({ width, height }: MakeRectOptions) => string;
7
+ export declare const makeRect: ({ x, y, width, height }: MakeRectOptions) => string;
package/dist/make-rect.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeRect = void 0;
4
- const makeRect = ({ width, height }) => {
5
- const x = 0;
6
- const y = 0;
4
+ const makeRect = ({ x = 0, y = 0, width, height }) => {
7
5
  return `M ${x} ${y} l ${width} 0 l 0 ${height} l ${-width} 0 Z`;
8
6
  };
9
7
  exports.makeRect = makeRect;
@@ -0,0 +1,7 @@
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,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeRect = void 0;
4
- const makeRect = ({ width, height }) => {
5
- const x = 0;
6
- const y = 0;
4
+ const makeRect = ({ x = 0, y = 0, width, height }) => {
7
5
  return `M ${x} ${y} l ${width} 0 l 0 ${height} l ${-width} 0 Z`;
8
6
  };
9
7
  exports.makeRect = makeRect;
@@ -5,4 +5,4 @@ export declare type SquareProps = {
5
5
  fill?: string;
6
6
  style?: React.CSSProperties;
7
7
  };
8
- export declare const Rect: React.FC<SquareProps>;
8
+ export declare const Square: React.FC<SquareProps>;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Rect = void 0;
3
+ exports.Square = void 0;
4
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)({
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
8
  width,
9
9
  height,
10
10
  }), fill: fill }) }));
11
11
  };
12
- exports.Rect = Rect;
12
+ exports.Square = Square;
@@ -15,11 +15,16 @@ export declare type Instruction = {
15
15
  x: number;
16
16
  y: number;
17
17
  } | {
18
- type: 'm';
18
+ type: 'a';
19
+ rx: number;
20
+ ry: number;
21
+ xAxisRotation: number;
22
+ largeArcFlag: boolean;
23
+ sweepFlag: boolean;
19
24
  x: number;
20
25
  y: number;
21
26
  } | {
22
- type: 'a';
27
+ type: 'A';
23
28
  rx: number;
24
29
  ry: number;
25
30
  xAxisRotation: number;
@@ -27,6 +32,8 @@ export declare type Instruction = {
27
32
  sweepFlag: boolean;
28
33
  x: number;
29
34
  y: number;
35
+ } | {
36
+ type: 'z';
30
37
  };
31
38
  export declare const serializeInstructions: (instructions: Instruction[]) => string;
32
- export declare const serializeInstruction: (instruction: Instruction) => string | undefined;
39
+ export declare const serializeInstruction: (instruction: Instruction) => string;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.serializeInstruction = exports.serializeInstructions = void 0;
4
4
  const serializeInstructions = (instructions) => {
5
- return instructions.map(exports.serializeInstruction).join(' ');
5
+ return instructions.map((i) => (0, exports.serializeInstruction)(i)).join(' ');
6
6
  };
7
7
  exports.serializeInstructions = serializeInstructions;
8
8
  const serializeInstruction = (instruction) => {
@@ -15,11 +15,15 @@ const serializeInstruction = (instruction) => {
15
15
  if (instruction.type === 'C') {
16
16
  return `C ${instruction.cp1x} ${instruction.cp1y} ${instruction.cp2x} ${instruction.cp2y} ${instruction.x} ${instruction.y}`;
17
17
  }
18
- if (instruction.type === 'm') {
19
- return `m ${instruction.x} ${instruction.y}`;
20
- }
21
18
  if (instruction.type === 'a') {
22
19
  return `a ${instruction.rx} ${instruction.ry} ${instruction.xAxisRotation} ${Number(instruction.largeArcFlag)} ${Number(instruction.sweepFlag ? 1 : 0)} ${instruction.x} ${instruction.y}`;
23
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');
24
28
  };
25
29
  exports.serializeInstruction = serializeInstruction;
@@ -6,14 +6,9 @@ const makeCircle = ({ radius }) => {
6
6
  const instructions = [
7
7
  {
8
8
  type: 'M',
9
- x: radius,
9
+ x: 0,
10
10
  y: radius,
11
11
  },
12
- {
13
- type: 'm',
14
- x: -radius,
15
- y: 0,
16
- },
17
12
  {
18
13
  type: 'a',
19
14
  rx: radius,
@@ -34,6 +29,9 @@ const makeCircle = ({ radius }) => {
34
29
  x: -radius * 2,
35
30
  y: 0,
36
31
  },
32
+ {
33
+ type: 'z',
34
+ },
37
35
  ];
38
36
  const path = (0, instructions_1.serializeInstructions)(instructions);
39
37
  return {
@@ -19,6 +19,9 @@ const makeEllipse = ({ rx, ry }) => {
19
19
  x: 1,
20
20
  y: 0,
21
21
  },
22
+ {
23
+ type: 'z',
24
+ },
22
25
  ];
23
26
  const path = (0, instructions_1.serializeInstructions)(instructions);
24
27
  return {
@@ -0,0 +1,15 @@
1
+ import type { Instruction } from './instructions';
2
+ export declare type MakePieProps = {
3
+ radius: number;
4
+ progress: number;
5
+ closePath?: boolean;
6
+ counterClockwise?: boolean;
7
+ rotation?: number;
8
+ };
9
+ export declare const makePie: ({ progress, radius, closePath, counterClockwise, rotation, }: MakePieProps) => {
10
+ height: number;
11
+ width: number;
12
+ path: string;
13
+ instructions: Instruction[];
14
+ transformOrigin: string;
15
+ };
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makePie = void 0;
4
+ const instructions_1 = require("./instructions");
5
+ const getCoord = ({ counterClockwise, actualProgress, rotation, radius, coord, }) => {
6
+ const factor = counterClockwise ? -1 : 1;
7
+ const val = Math[coord === 'x' ? 'cos' : 'sin'](factor * actualProgress * Math.PI * 2 + Math.PI * 1.5 + rotation) *
8
+ radius +
9
+ radius;
10
+ const rounded = Math.round(val * 100000) / 100000;
11
+ return rounded;
12
+ };
13
+ const makePie = ({ progress, radius, closePath = true, counterClockwise = false, rotation = 0, }) => {
14
+ const actualProgress = Math.min(Math.max(progress, 0), 1);
15
+ const endAngleX = getCoord({
16
+ actualProgress,
17
+ coord: 'x',
18
+ counterClockwise,
19
+ radius,
20
+ rotation,
21
+ });
22
+ const endAngleY = getCoord({
23
+ actualProgress,
24
+ coord: 'y',
25
+ counterClockwise,
26
+ radius,
27
+ rotation,
28
+ });
29
+ const start = {
30
+ x: getCoord({
31
+ actualProgress: 0,
32
+ coord: 'x',
33
+ counterClockwise,
34
+ radius,
35
+ rotation,
36
+ }),
37
+ y: getCoord({
38
+ actualProgress: 0,
39
+ coord: 'y',
40
+ counterClockwise,
41
+ radius,
42
+ rotation,
43
+ }),
44
+ };
45
+ const end = { x: endAngleX, y: endAngleY };
46
+ const instructions = [
47
+ {
48
+ type: 'M',
49
+ ...start,
50
+ },
51
+ {
52
+ type: 'A',
53
+ rx: radius,
54
+ ry: radius,
55
+ xAxisRotation: 0,
56
+ largeArcFlag: false,
57
+ sweepFlag: !counterClockwise,
58
+ x: actualProgress <= 0.5
59
+ ? endAngleX
60
+ : getCoord({
61
+ actualProgress: 0.5,
62
+ coord: 'x',
63
+ counterClockwise,
64
+ radius,
65
+ rotation,
66
+ }),
67
+ y: actualProgress <= 0.5
68
+ ? endAngleY
69
+ : getCoord({
70
+ actualProgress: 0.5,
71
+ coord: 'y',
72
+ counterClockwise,
73
+ radius,
74
+ rotation,
75
+ }),
76
+ },
77
+ actualProgress > 0.5
78
+ ? {
79
+ type: 'A',
80
+ rx: radius,
81
+ ry: radius,
82
+ xAxisRotation: 0,
83
+ largeArcFlag: false,
84
+ sweepFlag: !counterClockwise,
85
+ ...end,
86
+ }
87
+ : null,
88
+ actualProgress > 0 && actualProgress < 1 && closePath
89
+ ? {
90
+ type: 'L',
91
+ x: radius,
92
+ y: radius,
93
+ }
94
+ : null,
95
+ closePath
96
+ ? {
97
+ type: 'z',
98
+ }
99
+ : null,
100
+ ].filter(Boolean);
101
+ const path = (0, instructions_1.serializeInstructions)(instructions);
102
+ return {
103
+ height: radius * 2,
104
+ width: radius * 2,
105
+ path,
106
+ instructions,
107
+ transformOrigin: `${radius} ${radius}`,
108
+ };
109
+ };
110
+ exports.makePie = makePie;
@@ -5,13 +5,18 @@ const instructions_1 = require("./instructions");
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];
8
- const instructions = (0, join_points_1.joinPoints)([
9
- [0, 0],
10
- [width, 0],
11
- [width, height],
12
- [0, height],
13
- [0, 0],
14
- ], { edgeRoundness, cornerRadius, roundCornerStrategy: 'arc' });
8
+ const instructions = [
9
+ ...(0, join_points_1.joinPoints)([
10
+ [0, 0],
11
+ [width, 0],
12
+ [width, height],
13
+ [0, height],
14
+ [0, 0],
15
+ ], { edgeRoundness, cornerRadius, roundCornerStrategy: 'arc' }),
16
+ {
17
+ type: 'z',
18
+ },
19
+ ];
15
20
  const path = (0, instructions_1.serializeInstructions)(instructions);
16
21
  return {
17
22
  width,
@@ -15,11 +15,14 @@ const star = ({ centerX, centerY, points, innerRadius, outerRadius, cornerRadius
15
15
  };
16
16
  return [point.x, point.y];
17
17
  });
18
- return (0, join_points_1.joinPoints)([...d, d[0]], {
19
- edgeRoundness,
20
- cornerRadius,
21
- roundCornerStrategy: cornerRadius > 0 ? 'bezier' : 'arc',
22
- });
18
+ return [
19
+ ...(0, join_points_1.joinPoints)([...d, d[0]], {
20
+ edgeRoundness,
21
+ cornerRadius,
22
+ roundCornerStrategy: cornerRadius > 0 ? 'bezier' : 'arc',
23
+ }),
24
+ { type: 'z' },
25
+ ];
23
26
  };
24
27
  const makeStar = ({ points, innerRadius, outerRadius, cornerRadius = 0, edgeRoundness = null, }) => {
25
28
  const width = outerRadius * 2;
@@ -45,11 +45,16 @@ const makeTriangle = ({ length, direction = 'right', edgeRoundness = null, corne
45
45
  left: longerDimension / 2,
46
46
  right: longerDimension / 2,
47
47
  }[direction];
48
- const instructions = (0, join_points_1.joinPoints)(points[direction], {
49
- edgeRoundness,
50
- cornerRadius,
51
- roundCornerStrategy: 'bezier',
52
- });
48
+ const instructions = [
49
+ ...(0, join_points_1.joinPoints)(points[direction], {
50
+ edgeRoundness,
51
+ cornerRadius,
52
+ roundCornerStrategy: 'bezier',
53
+ }),
54
+ {
55
+ type: 'z',
56
+ },
57
+ ];
53
58
  const path = (0, instructions_1.serializeInstructions)(instructions);
54
59
  return {
55
60
  path,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/shapes",
3
- "version": "3.3.37",
3
+ "version": "3.3.38",
4
4
  "description": "Utility functions and components for SVG shapes",
5
5
  "main": "dist/index.js",
6
6
  "sideEffects": false,
@@ -44,5 +44,5 @@
44
44
  "react": ">=16.8.0",
45
45
  "react-dom": ">=16.8.0"
46
46
  },
47
- "gitHead": "ead6bdacc14a9953cae738159c49bf3daf09e9b0"
47
+ "gitHead": "ac58695e452e58deb5c010f09bcc94d036930e6c"
48
48
  }
@@ -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,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;
@@ -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>;
@@ -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;
@@ -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>;
@@ -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
- import React from 'react';
2
- import type { MakeCircleProps } from '../utils/make-circle';
3
- import type { AllShapesProps } from './render-svg';
4
- export declare type CircleProps = MakeCircleProps & AllShapesProps;
5
- export declare const Circle: React.FC<CircleProps>;
@@ -1,10 +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("../utils/make-circle");
6
- const render_svg_1 = require("./render-svg");
7
- const Circle = ({ radius, ...props }) => {
8
- return (0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_circle_1.makeCircle)({ radius }), ...props });
9
- };
10
- exports.Circle = Circle;
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- import type { MakeEllipseOptions } from '../utils/make-ellipse';
3
- import type { AllShapesProps } from './render-svg';
4
- export declare type EllipseProps = MakeEllipseOptions & AllShapesProps;
5
- export declare const Ellipse: React.FC<EllipseProps>;
@@ -1,10 +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("../utils/make-ellipse");
6
- const render_svg_1 = require("./render-svg");
7
- const Ellipse = ({ rx, ry, ...props }) => {
8
- return (0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_ellipse_1.makeEllipse)({ rx, ry }), ...props });
9
- };
10
- exports.Ellipse = Ellipse;
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- import type { MakeRectOptions } from '../utils/make-rect';
3
- import type { AllShapesProps } from './render-svg';
4
- export declare type RectProps = MakeRectOptions & AllShapesProps;
5
- export declare const Rect: React.FC<RectProps>;
@@ -1,10 +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("../utils/make-rect");
6
- const render_svg_1 = require("./render-svg");
7
- const Rect = ({ width, height, ...props }) => {
8
- return (0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_rect_1.makeRect)({ height, width }), ...props });
9
- };
10
- exports.Rect = Rect;
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- export declare type AllShapesProps = Omit<React.SVGProps<SVGPathElement>, 'width' | 'height' | 'd'> & {
3
- pathStyle?: React.CSSProperties;
4
- };
5
- export declare const RenderSvg: ({ width, height, path, style, pathStyle, transformOrigin, ...props }: {
6
- width: number;
7
- height: number;
8
- path: string;
9
- transformOrigin: string;
10
- } & Omit<React.SVGProps<SVGPathElement>, "width" | "height" | "d"> & {
11
- pathStyle?: React.CSSProperties | undefined;
12
- }) => JSX.Element;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RenderSvg = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("react");
6
- const RenderSvg = ({ width, height, path, style, pathStyle, transformOrigin, ...props }) => {
7
- const actualStyle = (0, react_1.useMemo)(() => {
8
- return {
9
- overflow: 'visible',
10
- ...(style !== null && style !== void 0 ? style : {}),
11
- };
12
- }, [style]);
13
- const actualPathStyle = (0, react_1.useMemo)(() => {
14
- return {
15
- transformBox: 'fill-box',
16
- ...(pathStyle !== null && pathStyle !== void 0 ? pathStyle : {}),
17
- };
18
- }, [pathStyle]);
19
- return ((0, jsx_runtime_1.jsx)("svg", { width: width, height: height, viewBox: `0 0 ${width} ${height}`, xmlns: "http://www.w3.org/2000/svg", style: actualStyle, children: (0, jsx_runtime_1.jsx)("path", { "transform-origin": transformOrigin, d: path, style: actualPathStyle, ...props }) }));
20
- };
21
- exports.RenderSvg = RenderSvg;
@@ -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,5 +0,0 @@
1
- import React from 'react';
2
- import type { MakeTriangleProps } from '../utils/make-triangle';
3
- import type { AllShapesProps } from './render-svg';
4
- export declare type TriangleProps = MakeTriangleProps & AllShapesProps;
5
- export declare const Triangle: React.FC<TriangleProps>;
@@ -1,10 +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("../utils/make-triangle");
6
- const render_svg_1 = require("./render-svg");
7
- const Triangle = ({ length, direction, ...props }) => {
8
- return (0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_triangle_1.makeTriangle)({ length, direction }), ...props });
9
- };
10
- exports.Triangle = Triangle;
@@ -1,8 +0,0 @@
1
- export { Circle, CircleProps } from './components/circle';
2
- export { Ellipse, EllipseProps } from './components/ellipse';
3
- export { Rect, RectProps } from './components/rect';
4
- export { Triangle, TriangleProps } from './components/triangle';
5
- export { makeCircle, MakeCircleProps } from './utils/make-circle';
6
- export { makeEllipse, MakeEllipseOptions } from './utils/make-ellipse';
7
- export { makeRect, MakeRectOptions } from './utils/make-rect';
8
- export { makeTriangle, MakeTriangleProps } from './utils/make-triangle';
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeTriangle = exports.makeRect = exports.makeEllipse = exports.makeCircle = exports.Triangle = exports.Rect = exports.Ellipse = exports.Circle = void 0;
4
- var circle_1 = require("./components/circle");
5
- Object.defineProperty(exports, "Circle", { enumerable: true, get: function () { return circle_1.Circle; } });
6
- var ellipse_1 = require("./components/ellipse");
7
- Object.defineProperty(exports, "Ellipse", { enumerable: true, get: function () { return ellipse_1.Ellipse; } });
8
- var rect_1 = require("./components/rect");
9
- Object.defineProperty(exports, "Rect", { enumerable: true, get: function () { return rect_1.Rect; } });
10
- var triangle_1 = require("./components/triangle");
11
- Object.defineProperty(exports, "Triangle", { enumerable: true, get: function () { return triangle_1.Triangle; } });
12
- var make_circle_1 = require("./utils/make-circle");
13
- Object.defineProperty(exports, "makeCircle", { enumerable: true, get: function () { return make_circle_1.makeCircle; } });
14
- var make_ellipse_1 = require("./utils/make-ellipse");
15
- Object.defineProperty(exports, "makeEllipse", { enumerable: true, get: function () { return make_ellipse_1.makeEllipse; } });
16
- var make_rect_1 = require("./utils/make-rect");
17
- Object.defineProperty(exports, "makeRect", { enumerable: true, get: function () { return make_rect_1.makeRect; } });
18
- var make_triangle_1 = require("./utils/make-triangle");
19
- Object.defineProperty(exports, "makeTriangle", { enumerable: true, get: function () { return make_triangle_1.makeTriangle; } });
@@ -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;
@@ -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;
@@ -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>;
@@ -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,5 +0,0 @@
1
- import type { ShapeInfo } from './shape-info';
2
- export declare type MakeCircleProps = {
3
- radius: number;
4
- };
5
- export declare const makeCircle: ({ radius }: MakeCircleProps) => ShapeInfo;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeCircle = void 0;
4
- const makeCircle = ({ radius }) => {
5
- return {
6
- height: radius * 2,
7
- width: radius * 2,
8
- path: `M ${radius} ${radius} m -${radius} 0 a ${radius} ${radius} 0 1 0 ${radius * 2} 0 ${radius} ${radius} 0 1 0 ${-radius * 2} 0`,
9
- transformOrigin: `${radius} ${radius}`,
10
- };
11
- };
12
- exports.makeCircle = makeCircle;
@@ -1,6 +0,0 @@
1
- import type { ShapeInfo } from './shape-info';
2
- export declare type MakeEllipseOptions = {
3
- rx: number;
4
- ry: number;
5
- };
6
- export declare const makeEllipse: ({ rx, ry }: MakeEllipseOptions) => ShapeInfo;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeEllipse = void 0;
4
- const makeEllipse = ({ rx, ry }) => {
5
- return {
6
- width: rx * 2,
7
- height: ry * 2,
8
- path: `M ${rx} ${0} a ${rx} ${ry} 0 1 0 1 0`,
9
- transformOrigin: `${rx} ${ry}`,
10
- };
11
- };
12
- exports.makeEllipse = makeEllipse;
@@ -1,6 +0,0 @@
1
- import type { ShapeInfo } from './shape-info';
2
- export declare type MakeRectOptions = {
3
- width: number;
4
- height: number;
5
- };
6
- export declare const makeRect: ({ width, height }: MakeRectOptions) => ShapeInfo;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeRect = void 0;
4
- const makeRect = ({ width, height }) => {
5
- return {
6
- width,
7
- height,
8
- path: `M 0 0 l ${width} 0 l 0 ${height} l ${-width} 0 Z`,
9
- transformOrigin: `${width / 2} ${height / 2}`,
10
- };
11
- };
12
- exports.makeRect = makeRect;
@@ -1,6 +0,0 @@
1
- import type { ShapeInfo } from './shape-info';
2
- export declare type MakeTriangleProps = {
3
- length: number;
4
- direction: 'right' | 'left' | 'top' | 'bottom';
5
- };
6
- export declare const makeTriangle: ({ length, direction, }: MakeTriangleProps) => ShapeInfo;
@@ -1,57 +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 = ({ length, direction = 'right', }) => {
6
- const longerDimension = length;
7
- const shorterSize = Math.sqrt(length ** 2 * 0.75); // Calculated on paper;
8
- const points = {
9
- top: [
10
- `${longerDimension / 2} 0`,
11
- 'L',
12
- `0 ${shorterSize}`,
13
- 'L',
14
- `${longerDimension} ${shorterSize}`,
15
- ],
16
- right: [
17
- `0 0`,
18
- 'L',
19
- `0 ${longerDimension}`,
20
- 'L',
21
- `${shorterSize} ${longerDimension / 2}`,
22
- ],
23
- bottom: [
24
- `0 0`,
25
- 'L',
26
- `${longerDimension} 0`,
27
- 'L',
28
- `${longerDimension / 2} ${shorterSize}`,
29
- ],
30
- left: [
31
- `${shorterSize} 0`,
32
- 'L',
33
- `${shorterSize} ${longerDimension}`,
34
- 'L',
35
- `0 ${longerDimension / 2}`,
36
- ],
37
- };
38
- const transformOriginX = {
39
- left: (shorterSize / 3) * 2,
40
- right: shorterSize / 3,
41
- top: longerDimension / 2,
42
- bottom: longerDimension / 2,
43
- }[direction];
44
- const transformOriginY = {
45
- top: (shorterSize / 3) * 2,
46
- bottom: shorterSize / 3,
47
- left: longerDimension / 2,
48
- right: longerDimension / 2,
49
- }[direction];
50
- return {
51
- path: `M ${points[direction].join(' ')} z`,
52
- width: direction === 'top' || direction === 'bottom' ? length : shorterSize,
53
- height: direction === 'top' || direction === 'bottom' ? shorterSize : length,
54
- transformOrigin: `${transformOriginX} ${transformOriginY}`,
55
- };
56
- };
57
- exports.makeTriangle = makeTriangle;
@@ -1,6 +0,0 @@
1
- export declare type ShapeInfo = {
2
- path: string;
3
- width: number;
4
- height: number;
5
- transformOrigin: string;
6
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });