-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(insertables): add component thumbnails
GitOrigin-RevId: 441098d6f266eeee9ab54f152a9820fe613bd0b8
- Loading branch information
1 parent
e94a946
commit c675ba5
Showing
16 changed files
with
210 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { reduceImageSize } from "@/wab/client/image/transform"; | ||
|
||
describe("reduceImageSize", () => { | ||
it("should reduce the width to fit within the maxWidth while maintaining aspect ratio", () => { | ||
const result = reduceImageSize(2000, 1000, 1000, 1000); | ||
expect(result).toEqual({ width: 1000, height: 500 }); | ||
}); | ||
|
||
it("should reduce the height to fit within the maxHeight while maintaining aspect ratio", () => { | ||
const result = reduceImageSize(1000, 2000, 1000, 1000); | ||
expect(result).toEqual({ width: 500, height: 1000 }); | ||
}); | ||
|
||
it("should reduce both width and height to fit within maxWidth and maxHeight while maintaining aspect ratio", () => { | ||
const result = reduceImageSize(4000, 2000, 1000, 500); | ||
expect(result).toEqual({ width: 1000, height: 500 }); | ||
}); | ||
|
||
it("should not change the size if it is within the maxWidth and maxHeight", () => { | ||
const result = reduceImageSize(800, 600, 1000, 1000); | ||
expect(result).toEqual({ width: 800, height: 600 }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Reduces the dimensions of an image to fit within the specified maximum width and height, | ||
* while maintaining the original aspect ratio. | ||
* | ||
* @param width - The original width of the image. | ||
* @param height - The original height of the image. | ||
* @param maxWidth - The maximum allowed width for the image. | ||
* @param maxHeight - The maximum allowed height for the image. | ||
* @returns An object containing the new width and height of the image. | ||
*/ | ||
export function reduceImageSize( | ||
width: number, | ||
height: number, | ||
maxWidth: number, | ||
maxHeight: number | ||
) { | ||
const aspectRatio = width / height; | ||
if (width > maxWidth) { | ||
width = maxWidth; | ||
height = width / aspectRatio; | ||
} | ||
if (height > maxHeight) { | ||
height = maxHeight; | ||
width = height * aspectRatio; | ||
} | ||
return { width, height }; | ||
} |
Oops, something went wrong.