Skip to content

🎥 Make videos programmatically with React

return viewbox, width and height in bounding box

Jonny Burger3a99578a15f5
diff --git a/packages/docs/docs/paths/get-bounding-box.md b/packages/docs/docs/paths/get-bounding-box.md
index 1f18af9a29..a34e7318a0 100644
--- a/packages/docs/docs/paths/get-bounding-box.md
+++ b/packages/docs/docs/paths/get-bounding-box.md
@@ -21,6 +21,18 @@ const boundingBox = getBoundingBox(
This function will throw if the SVG path is invalid.
+## Return type
+
+Includes the following properties:
+
+- `x1`: The leftmost x coordinate of the bounding box
+- `x2`: The rightmost x coordinate of the bounding box
+- `y1`: The topmost y coordinate of the bounding box
+- `y2`: The bottommost y coordinate of the bounding box
+- `width`: The width of the bounding box, _returned from v3.3.97_
+- `height`: The height of the bounding box, _returned from v3.3.97_
+- `viewBox`: The `viewBox` value that you can pass to an SVG, _returned from v3.3.97_
+
## `BoundingBox` type
In TypeScript, you can get the shape of the return value by importing the `BoundingBox` type:
diff --git a/packages/paths/src/get-bounding-box.ts b/packages/paths/src/get-bounding-box.ts
index 3a1d7b4f5c..de1d40e9cf 100644
--- a/packages/paths/src/get-bounding-box.ts
+++ b/packages/paths/src/get-bounding-box.ts
@@ -223,5 +223,13 @@ export const getBoundingBoxFromInstructions = (
}
}
- return {x1: minX, y1: minY, x2: maxX, y2: maxY};
+ return {
+ x1: minX,
+ y1: minY,
+ x2: maxX,
+ y2: maxY,
+ viewBox: `${minX} ${minY} ${maxX - minX} ${maxY - minY}`,
+ width: maxX - minX,
+ height: maxY - minY,
+ };
};
diff --git a/packages/paths/src/helpers/types.ts b/packages/paths/src/helpers/types.ts
index edef47b104..bef5e6a24c 100644
--- a/packages/paths/src/helpers/types.ts
+++ b/packages/paths/src/helpers/types.ts
@@ -24,7 +24,15 @@ export interface PointProperties {
tangentY: number;
}
-export type BoundingBox = {x1: number; y1: number; x2: number; y2: number};
+export type BoundingBox = {
+ x1: number;
+ y1: number;
+ x2: number;
+ y2: number;
+ viewBox: string;
+ width: number;
+ height: number;
+};
export type ReducedInstruction =
| {