@remotion/shapes 3.3.33 → 3.3.35

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/rect.js +2 -2
  2. package/dist/components/render-svg.d.ts +5 -1
  3. package/dist/components/render-svg.js +14 -2
  4. package/dist/components/triangle.js +2 -2
  5. package/dist/index.d.ts +1 -0
  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 +32 -0
  16. package/dist/utils/instructions.js +25 -0
  17. package/dist/utils/join-points.d.ts +9 -0
  18. package/dist/utils/join-points.js +110 -0
  19. package/dist/utils/make-circle.js +36 -1
  20. package/dist/utils/make-ellipse.js +21 -1
  21. package/dist/utils/make-rect.d.ts +3 -1
  22. package/dist/utils/make-rect.js +15 -3
  23. package/dist/utils/make-triangle.d.ts +6 -2
  24. package/dist/utils/make-triangle.js +35 -30
  25. package/dist/utils/shape-info.d.ts +2 -0
  26. package/package.json +2 -2
  27. package/dist/components/return-type.d.ts +0 -5
  28. package/dist/components/return-type.js +0 -2
  29. package/dist/components/shape-info.d.ts +0 -5
  30. package/dist/components/shape-info.js +0 -2
  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
@@ -4,7 +4,7 @@ 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
- const Rect = ({ width, height, ...props }) => {
8
- return (0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_rect_1.makeRect)({ height, width }), ...props });
7
+ const Rect = ({ width, edgeRoundness, height, cornerRadius, ...props }) => {
8
+ return ((0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_rect_1.makeRect)({ height, width, edgeRoundness, cornerRadius }), ...props }));
9
9
  };
10
10
  exports.Rect = Rect;
@@ -1,12 +1,16 @@
1
1
  import React from 'react';
2
+ import type { Instruction } from '../utils/instructions';
2
3
  export declare type AllShapesProps = Omit<React.SVGProps<SVGPathElement>, 'width' | 'height' | 'd'> & {
4
+ debug?: boolean;
3
5
  pathStyle?: React.CSSProperties;
4
6
  };
5
- export declare const RenderSvg: ({ width, height, path, style, pathStyle, transformOrigin, ...props }: {
7
+ export declare const RenderSvg: ({ width, height, path, style, pathStyle, transformOrigin, debug, instructions, ...props }: {
6
8
  width: number;
7
9
  height: number;
8
10
  path: string;
11
+ instructions: Instruction[];
9
12
  transformOrigin: string;
10
13
  } & Omit<React.SVGProps<SVGPathElement>, "width" | "height" | "d"> & {
14
+ debug?: boolean | undefined;
11
15
  pathStyle?: React.CSSProperties | undefined;
12
16
  }) => JSX.Element;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RenderSvg = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
- const RenderSvg = ({ width, height, path, style, pathStyle, transformOrigin, ...props }) => {
6
+ const RenderSvg = ({ width, height, path, style, pathStyle, transformOrigin, debug, instructions, ...props }) => {
7
7
  const actualStyle = (0, react_1.useMemo)(() => {
8
8
  return {
9
9
  overflow: 'visible',
@@ -16,6 +16,18 @@ const RenderSvg = ({ width, height, path, style, pathStyle, transformOrigin, ...
16
16
  ...(pathStyle !== null && pathStyle !== void 0 ? pathStyle : {}),
17
17
  };
18
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 }) }));
19
+ return ((0, jsx_runtime_1.jsxs)("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 }), debug
20
+ ? instructions.map((i, index) => {
21
+ if (i.type === 'C') {
22
+ const prevInstruction = index === 0
23
+ ? instructions[instructions.length - 1]
24
+ : instructions[index - 1];
25
+ const prevX = prevInstruction.x;
26
+ const prevY = prevInstruction.y;
27
+ 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" })] }));
28
+ }
29
+ return null;
30
+ })
31
+ : null] }));
20
32
  };
21
33
  exports.RenderSvg = RenderSvg;
@@ -4,7 +4,7 @@ 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
- const Triangle = ({ length, direction, ...props }) => {
8
- return (0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_triangle_1.makeTriangle)({ length, direction }), ...props });
7
+ const Triangle = ({ length, direction, edgeRoundness, cornerRadius, ...props }) => {
8
+ return ((0, jsx_runtime_1.jsx)(render_svg_1.RenderSvg, { ...(0, make_triangle_1.makeTriangle)({ length, direction, edgeRoundness, cornerRadius }), ...props }));
9
9
  };
10
10
  exports.Triangle = Triangle;
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export { Circle, CircleProps } from './components/circle';
2
2
  export { Ellipse, EllipseProps } from './components/ellipse';
3
3
  export { Rect, RectProps } from './components/rect';
4
4
  export { Triangle, TriangleProps } from './components/triangle';
5
+ export { Instruction } from './utils/instructions';
5
6
  export { makeCircle, MakeCircleProps } from './utils/make-circle';
6
7
  export { makeEllipse, MakeEllipseOptions } from './utils/make-ellipse';
7
8
  export { makeRect, MakeRectOptions } from './utils/make-rect';
@@ -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;
@@ -0,0 +1,32 @@
1
+ export declare type Instruction = {
2
+ type: 'M';
3
+ x: number;
4
+ y: number;
5
+ } | {
6
+ type: 'L';
7
+ x: number;
8
+ y: number;
9
+ } | {
10
+ type: 'C';
11
+ cp1x: number;
12
+ cp1y: number;
13
+ cp2x: number;
14
+ cp2y: number;
15
+ x: number;
16
+ y: number;
17
+ } | {
18
+ type: 'm';
19
+ x: number;
20
+ y: number;
21
+ } | {
22
+ type: 'a';
23
+ rx: number;
24
+ ry: number;
25
+ xAxisRotation: number;
26
+ largeArcFlag: boolean;
27
+ sweepFlag: boolean;
28
+ x: number;
29
+ y: number;
30
+ };
31
+ export declare const serializeInstructions: (instructions: Instruction[]) => string;
32
+ export declare const serializeInstruction: (instruction: Instruction) => string | undefined;
@@ -0,0 +1,25 @@
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(exports.serializeInstruction).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 === 'm') {
19
+ return `m ${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
+ };
25
+ exports.serializeInstruction = serializeInstruction;
@@ -0,0 +1,9 @@
1
+ import type { Instruction } from './instructions';
2
+ export declare const joinPoints: (points: [
3
+ number,
4
+ number
5
+ ][], { edgeRoundness, cornerRadius, roundCornerStrategy, }: {
6
+ edgeRoundness: number | null;
7
+ cornerRadius: number;
8
+ roundCornerStrategy: 'arc' | 'bezier';
9
+ }) => Instruction[];
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.joinPoints = void 0;
4
+ const shortenVector = (vector, radius) => {
5
+ const [x, y] = vector;
6
+ const currentLength = Math.sqrt(x * x + y * y);
7
+ const scalingFactor = (currentLength - radius) / currentLength;
8
+ return [x * scalingFactor, y * scalingFactor];
9
+ };
10
+ const scaleVectorToLength = (vector, length) => {
11
+ const [x, y] = vector;
12
+ const currentLength = Math.sqrt(x * x + y * y);
13
+ const scalingFactor = length / currentLength;
14
+ return [x * scalingFactor, y * scalingFactor];
15
+ };
16
+ const joinPoints = (points, { edgeRoundness, cornerRadius, roundCornerStrategy, }) => {
17
+ return points
18
+ .map(([x, y], i) => {
19
+ const prevPointIndex = i === 0 ? points.length - 2 : i - 1;
20
+ const prevPoint = points[prevPointIndex];
21
+ const nextPointIndex = i === points.length - 1 ? 1 : i + 1;
22
+ const nextPoint = points[nextPointIndex];
23
+ const middleOfLine = [(x + nextPoint[0]) / 2, (y + nextPoint[1]) / 2];
24
+ const prevPointMiddleOfLine = [
25
+ (x + prevPoint[0]) / 2,
26
+ (y + prevPoint[1]) / 2,
27
+ ];
28
+ if (i === 0) {
29
+ if (edgeRoundness !== null) {
30
+ return {
31
+ type: 'M',
32
+ x: middleOfLine[0],
33
+ y: middleOfLine[1],
34
+ };
35
+ }
36
+ return {
37
+ type: 'M',
38
+ x,
39
+ y,
40
+ };
41
+ }
42
+ const prevVector = [x - prevPoint[0], y - prevPoint[1]];
43
+ const nextVector = [nextPoint[0] - x, nextPoint[1] - y];
44
+ if (cornerRadius && edgeRoundness !== null) {
45
+ throw new Error(`"cornerRadius" and "edgeRoundness" cannot be specified at the same time.`);
46
+ }
47
+ if (edgeRoundness === null) {
48
+ if (cornerRadius === 0) {
49
+ return {
50
+ type: 'L',
51
+ x,
52
+ y,
53
+ };
54
+ }
55
+ const prevVectorMinusRadius = shortenVector(prevVector, cornerRadius);
56
+ const prevVectorLenght = scaleVectorToLength(prevVector, cornerRadius);
57
+ const nextVectorMinusRadius = scaleVectorToLength(nextVector, cornerRadius);
58
+ const firstDraw = [
59
+ prevPoint[0] + prevVectorMinusRadius[0],
60
+ prevPoint[1] + prevVectorMinusRadius[1],
61
+ ];
62
+ return [
63
+ {
64
+ type: 'L',
65
+ x: firstDraw[0],
66
+ y: firstDraw[1],
67
+ },
68
+ roundCornerStrategy === 'arc'
69
+ ? {
70
+ type: 'a',
71
+ rx: cornerRadius,
72
+ ry: cornerRadius,
73
+ xAxisRotation: 0,
74
+ x: prevVectorLenght[0] + nextVectorMinusRadius[0],
75
+ y: prevVectorLenght[1] + nextVectorMinusRadius[1],
76
+ largeArcFlag: false,
77
+ sweepFlag: true,
78
+ }
79
+ : {
80
+ type: 'C',
81
+ x: firstDraw[0] + prevVectorLenght[0] + nextVectorMinusRadius[0],
82
+ y: firstDraw[1] + prevVectorLenght[1] + nextVectorMinusRadius[1],
83
+ cp1x: x,
84
+ cp1y: y,
85
+ cp2x: x,
86
+ cp2y: y,
87
+ },
88
+ ];
89
+ }
90
+ const controlPoint1 = [
91
+ prevPointMiddleOfLine[0] + prevVector[0] * edgeRoundness * 0.5,
92
+ prevPointMiddleOfLine[1] + prevVector[1] * edgeRoundness * 0.5,
93
+ ];
94
+ const controlPoint2 = [
95
+ middleOfLine[0] - nextVector[0] * edgeRoundness * 0.5,
96
+ middleOfLine[1] - nextVector[1] * edgeRoundness * 0.5,
97
+ ];
98
+ return {
99
+ type: 'C',
100
+ cp1x: controlPoint1[0],
101
+ cp1y: controlPoint1[1],
102
+ cp2x: controlPoint2[0],
103
+ cp2y: controlPoint2[1],
104
+ x: middleOfLine[0],
105
+ y: middleOfLine[1],
106
+ };
107
+ })
108
+ .flat(1);
109
+ };
110
+ exports.joinPoints = joinPoints;
@@ -1,11 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeCircle = void 0;
4
+ const instructions_1 = require("./instructions");
4
5
  const makeCircle = ({ radius }) => {
6
+ const instructions = [
7
+ {
8
+ type: 'M',
9
+ x: radius,
10
+ y: radius,
11
+ },
12
+ {
13
+ type: 'm',
14
+ x: -radius,
15
+ y: 0,
16
+ },
17
+ {
18
+ type: 'a',
19
+ rx: radius,
20
+ ry: radius,
21
+ xAxisRotation: 0,
22
+ largeArcFlag: true,
23
+ sweepFlag: false,
24
+ x: radius * 2,
25
+ y: 0,
26
+ },
27
+ {
28
+ type: 'a',
29
+ rx: radius,
30
+ ry: radius,
31
+ xAxisRotation: 0,
32
+ largeArcFlag: true,
33
+ sweepFlag: false,
34
+ x: -radius * 2,
35
+ y: 0,
36
+ },
37
+ ];
38
+ const path = (0, instructions_1.serializeInstructions)(instructions);
5
39
  return {
6
40
  height: radius * 2,
7
41
  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`,
42
+ path,
43
+ instructions,
9
44
  transformOrigin: `${radius} ${radius}`,
10
45
  };
11
46
  };
@@ -1,11 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeEllipse = void 0;
4
+ const instructions_1 = require("./instructions");
4
5
  const makeEllipse = ({ rx, ry }) => {
6
+ const instructions = [
7
+ {
8
+ type: 'M',
9
+ x: rx,
10
+ y: 0,
11
+ },
12
+ {
13
+ type: 'a',
14
+ rx,
15
+ ry,
16
+ xAxisRotation: 0,
17
+ largeArcFlag: true,
18
+ sweepFlag: false,
19
+ x: 1,
20
+ y: 0,
21
+ },
22
+ ];
23
+ const path = (0, instructions_1.serializeInstructions)(instructions);
5
24
  return {
6
25
  width: rx * 2,
7
26
  height: ry * 2,
8
- path: `M ${rx} ${0} a ${rx} ${ry} 0 1 0 1 0`,
27
+ path,
28
+ instructions,
9
29
  transformOrigin: `${rx} ${ry}`,
10
30
  };
11
31
  };
@@ -2,5 +2,7 @@ import type { ShapeInfo } from './shape-info';
2
2
  export declare type MakeRectOptions = {
3
3
  width: number;
4
4
  height: number;
5
+ edgeRoundness?: number | null;
6
+ cornerRadius?: number;
5
7
  };
6
- export declare const makeRect: ({ width, height }: MakeRectOptions) => ShapeInfo;
8
+ export declare const makeRect: ({ width, height, edgeRoundness, cornerRadius, }: MakeRectOptions) => ShapeInfo;
@@ -1,12 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeRect = void 0;
4
- const makeRect = ({ width, height }) => {
4
+ const instructions_1 = require("./instructions");
5
+ const join_points_1 = require("./join-points");
6
+ const makeRect = ({ width, height, edgeRoundness = null, cornerRadius = 0, }) => {
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' });
15
+ const path = (0, instructions_1.serializeInstructions)(instructions);
5
16
  return {
6
17
  width,
7
18
  height,
8
- path: `M 0 0 l ${width} 0 l 0 ${height} l ${-width} 0 Z`,
9
- transformOrigin: `${width / 2} ${height / 2}`,
19
+ instructions,
20
+ path,
21
+ transformOrigin: transformOrigin.join(' '),
10
22
  };
11
23
  };
12
24
  exports.makeRect = makeRect;
@@ -1,6 +1,10 @@
1
1
  import type { ShapeInfo } from './shape-info';
2
+ declare type Direction = 'right' | 'left' | 'up' | 'down';
2
3
  export declare type MakeTriangleProps = {
3
4
  length: number;
4
- direction: 'right' | 'left' | 'top' | 'bottom';
5
+ direction: Direction;
6
+ edgeRoundness?: number | null;
7
+ cornerRadius?: number;
5
8
  };
6
- export declare const makeTriangle: ({ length, direction, }: MakeTriangleProps) => ShapeInfo;
9
+ export declare const makeTriangle: ({ length, direction, edgeRoundness, cornerRadius, }: MakeTriangleProps) => ShapeInfo;
10
+ export {};
@@ -2,55 +2,60 @@
2
2
  // Copied from https://stackblitz.com/edit/react-triangle-svg?file=index.js
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.makeTriangle = void 0;
5
- const makeTriangle = ({ length, direction = 'right', }) => {
5
+ const instructions_1 = require("./instructions");
6
+ const join_points_1 = require("./join-points");
7
+ const makeTriangle = ({ length, direction = 'right', edgeRoundness = null, cornerRadius = 0, }) => {
6
8
  const longerDimension = length;
7
9
  const shorterSize = Math.sqrt(length ** 2 * 0.75); // Calculated on paper;
8
10
  const points = {
9
- top: [
10
- `${longerDimension / 2} 0`,
11
- 'L',
12
- `0 ${shorterSize}`,
13
- 'L',
14
- `${longerDimension} ${shorterSize}`,
11
+ up: [
12
+ [longerDimension / 2, 0],
13
+ [0, shorterSize],
14
+ [longerDimension, shorterSize],
15
+ [longerDimension / 2, 0],
15
16
  ],
16
17
  right: [
17
- `0 0`,
18
- 'L',
19
- `0 ${longerDimension}`,
20
- 'L',
21
- `${shorterSize} ${longerDimension / 2}`,
18
+ [0, 0],
19
+ [0, longerDimension],
20
+ [shorterSize, longerDimension / 2],
21
+ [0, 0],
22
22
  ],
23
- bottom: [
24
- `0 0`,
25
- 'L',
26
- `${longerDimension} 0`,
27
- 'L',
28
- `${longerDimension / 2} ${shorterSize}`,
23
+ down: [
24
+ [0, 0],
25
+ [longerDimension, 0],
26
+ [longerDimension / 2, shorterSize],
27
+ [0, 0],
29
28
  ],
30
29
  left: [
31
- `${shorterSize} 0`,
32
- 'L',
33
- `${shorterSize} ${longerDimension}`,
34
- 'L',
35
- `0 ${longerDimension / 2}`,
30
+ [shorterSize, 0],
31
+ [shorterSize, longerDimension],
32
+ [0, longerDimension / 2],
33
+ [shorterSize, 0],
36
34
  ],
37
35
  };
38
36
  const transformOriginX = {
39
37
  left: (shorterSize / 3) * 2,
40
38
  right: shorterSize / 3,
41
- top: longerDimension / 2,
42
- bottom: longerDimension / 2,
39
+ up: longerDimension / 2,
40
+ down: longerDimension / 2,
43
41
  }[direction];
44
42
  const transformOriginY = {
45
- top: (shorterSize / 3) * 2,
46
- bottom: shorterSize / 3,
43
+ up: (shorterSize / 3) * 2,
44
+ down: shorterSize / 3,
47
45
  left: longerDimension / 2,
48
46
  right: longerDimension / 2,
49
47
  }[direction];
48
+ const instructions = (0, join_points_1.joinPoints)(points[direction], {
49
+ edgeRoundness,
50
+ cornerRadius,
51
+ roundCornerStrategy: 'bezier',
52
+ });
53
+ const path = (0, instructions_1.serializeInstructions)(instructions);
50
54
  return {
51
- path: `M ${points[direction].join(' ')} z`,
52
- width: direction === 'top' || direction === 'bottom' ? length : shorterSize,
53
- height: direction === 'top' || direction === 'bottom' ? shorterSize : length,
55
+ path,
56
+ instructions,
57
+ width: direction === 'up' || direction === 'down' ? length : shorterSize,
58
+ height: direction === 'up' || direction === 'down' ? shorterSize : length,
54
59
  transformOrigin: `${transformOriginX} ${transformOriginY}`,
55
60
  };
56
61
  };
@@ -1,6 +1,8 @@
1
+ import type { Instruction } from './instructions';
1
2
  export declare type ShapeInfo = {
2
3
  path: string;
3
4
  width: number;
4
5
  height: number;
5
6
  transformOrigin: string;
7
+ instructions: Instruction[];
6
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/shapes",
3
- "version": "3.3.33",
3
+ "version": "3.3.35",
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": "0356b9108673ac98c41990f192b101f7a6574ed0"
47
+ "gitHead": "92344ca937e4c51b8484f79528e3c38d598f7053"
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
- 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 });