How to resize a rectangle in square aspect ratio?

I’m currently working on image annotations in which I’m looking for a possibility that the rectangle could be resized in a square aspect ratio.

In my attachment below, an editable rectangle worked perfectly but in my case but what I do want is an editable square that can be resized in a square aspect ratio because the square shape used to annotate the object in the image matters the most in my requirement.

Here is the shape drawing source code in plotlyjs and I would like to customize it according to the needs mentioned above. I really appreciate any help.