I'm working on a simple visual editor using SVG and Snap.SVG library.
It has a bunch of complex shapes as templates, each shape is a <g> element that contains paths.
The editor lets the user transform shapes by moving, scaling and rotating them.
This is done by applying the transforms as a matrix on the main <g> element of each shape.
The math is mainly done by the Snap.SVG library.
The transforms must by applied in a specific order for things to look right. The user might do any of the transforms in any order they like. So each user interaction with the shape is an update to the transform matrix of that shape.
When the user moves, rotates, scales, rotates again and scales again, what is the best way to update the transform matrix on the shape and keep the transforms in correct order?
Currently, all transforms are done in the order of: translate => rotate => scale. In this case, updating the rotation angle after the scale has already been applied to the matrix would break the shape. Because the matrix is already calculated with the scale taken into account. It would become translate => rotate => scale => rotate and the last rotation would get stretched by the scale transform.
I'm trying to avoid storing any extra data about transforms (e.g in data- attributes) and also avoid using transform strings, such as transform="translate(x, y) rotate(a, x, y) scale(x, y)" as it would be too complicated to parse it.