Algorithm for resize multi selected elements on the canvas

I have shapes with integer coordinates of width and height. They can be selected and stretched separately, I want to add the function of stretching a group of selected shapes. For example, as in the Figma editor or in VS Studio on a visual canvas, when we select a set of shapes and stretch them and they stretch proportionally with integer coordinates of width and height. Can you tell me how it works? For example, I have a list of 5 shapes with a width and height of 10px, indents from each other in 1px, I have selected them and pull them along the X axis in the positive direction by 8 pixels, which algorithm do I need to use? Here is an example of how it looks in VS when stretching buttons on the canvas.