@remotion/shapes 3.3.37 → 3.3.39

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" })] }));
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");
@@ -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.39",
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": "5a07260074fe3a6db2cdba0001503c665951414d"
48
48
  }