@remotion/shapes 3.3.36 → 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.
@@ -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" })] }));
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import type { MakeStarProps } from '../utils/make-star';
3
+ import type { AllShapesProps } from './render-svg';
4
+ export declare type StarProps = MakeStarProps & Omit<AllShapesProps, 'points'>;
5
+ export declare const Star: React.FC<StarProps>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Star = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const make_star_1 = require("../utils/make-star");
6
+ const render_svg_1 = require("./render-svg");
7
+ const Star = ({ innerRadius, outerRadius, points, cornerRadius, edgeRoundness, ...props }) => {
8
+ return ((0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_star_1.makeStar)({
9
+ innerRadius,
10
+ outerRadius,
11
+ points,
12
+ cornerRadius,
13
+ edgeRoundness,
14
+ }), ...props }));
15
+ };
16
+ exports.Star = Star;
package/dist/index.d.ts CHANGED
@@ -1,9 +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';
5
+ export { Star, StarProps } from './components/star';
4
6
  export { Triangle, TriangleProps } from './components/triangle';
5
7
  export { Instruction } from './utils/instructions';
6
8
  export { makeCircle, MakeCircleProps } from './utils/make-circle';
7
9
  export { makeEllipse, MakeEllipseOptions } from './utils/make-ellipse';
10
+ export { makePie, MakePieProps } from './utils/make-pie';
8
11
  export { makeRect, MakeRectOptions } from './utils/make-rect';
12
+ export { makeStar, MakeStarProps } from './utils/make-star';
9
13
  export { makeTriangle, MakeTriangleProps } from './utils/make-triangle';
package/dist/index.js CHANGED
@@ -1,19 +1,27 @@
1
1
  "use strict";
2
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;
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; } });
12
+ var star_1 = require("./components/star");
13
+ Object.defineProperty(exports, "Star", { enumerable: true, get: function () { return star_1.Star; } });
10
14
  var triangle_1 = require("./components/triangle");
11
15
  Object.defineProperty(exports, "Triangle", { enumerable: true, get: function () { return triangle_1.Triangle; } });
12
16
  var make_circle_1 = require("./utils/make-circle");
13
17
  Object.defineProperty(exports, "makeCircle", { enumerable: true, get: function () { return make_circle_1.makeCircle; } });
14
18
  var make_ellipse_1 = require("./utils/make-ellipse");
15
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; } });
16
22
  var make_rect_1 = require("./utils/make-rect");
17
23
  Object.defineProperty(exports, "makeRect", { enumerable: true, get: function () { return make_rect_1.makeRect; } });
24
+ var make_star_1 = require("./utils/make-star");
25
+ Object.defineProperty(exports, "makeStar", { enumerable: true, get: function () { return make_star_1.makeStar; } });
18
26
  var make_triangle_1 = require("./utils/make-triangle");
19
27
  Object.defineProperty(exports, "makeTriangle", { enumerable: true, get: function () { return make_triangle_1.makeTriangle; } });
@@ -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,
@@ -0,0 +1,18 @@
1
+ import type { ShapeInfo } from './shape-info';
2
+ export declare type MakeStarProps = {
3
+ points: number;
4
+ innerRadius: number;
5
+ outerRadius: number;
6
+ edgeRoundness?: number | null;
7
+ cornerRadius?: number;
8
+ };
9
+ export declare type StarProps = {
10
+ centerX: number;
11
+ centerY: number;
12
+ points: number;
13
+ innerRadius: number;
14
+ outerRadius: number;
15
+ edgeRoundness: number | null;
16
+ cornerRadius: number;
17
+ };
18
+ export declare const makeStar: ({ points, innerRadius, outerRadius, cornerRadius, edgeRoundness, }: MakeStarProps) => ShapeInfo;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ // Copied from https://stackblitz.com/edit/svg-star-generator?file=index.js
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.makeStar = void 0;
5
+ const instructions_1 = require("./instructions");
6
+ const join_points_1 = require("./join-points");
7
+ const star = ({ centerX, centerY, points, innerRadius, outerRadius, cornerRadius, edgeRoundness, }) => {
8
+ const degreeIncrement = (Math.PI * 2) / (points * 2);
9
+ const d = new Array(points * 2).fill(true).map((_p, i) => {
10
+ const radius = i % 2 === 0 ? outerRadius : innerRadius;
11
+ const angle = degreeIncrement * i - Math.PI / 2;
12
+ const point = {
13
+ x: centerX + radius * Math.cos(angle),
14
+ y: centerY + radius * Math.sin(angle),
15
+ };
16
+ return [point.x, point.y];
17
+ });
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
+ ];
26
+ };
27
+ const makeStar = ({ points, innerRadius, outerRadius, cornerRadius = 0, edgeRoundness = null, }) => {
28
+ const width = outerRadius * 2;
29
+ const height = outerRadius * 2;
30
+ const centerX = width / 2;
31
+ const centerY = height / 2;
32
+ const starPathInstructions = star({
33
+ centerX,
34
+ centerY,
35
+ points,
36
+ innerRadius,
37
+ outerRadius,
38
+ cornerRadius,
39
+ edgeRoundness,
40
+ });
41
+ return {
42
+ path: (0, instructions_1.serializeInstructions)(starPathInstructions),
43
+ width,
44
+ height,
45
+ transformOrigin: `${centerX} ${centerY}`,
46
+ instructions: starPathInstructions,
47
+ };
48
+ };
49
+ exports.makeStar = makeStar;
@@ -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.36",
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": "623bf1e883e7b26b9d02458037c930ccbe8857e4"
47
+ "gitHead": "ac58695e452e58deb5c010f09bcc94d036930e6c"
48
48
  }