It took me quite a bit of time to figure out how to do this, I must confess. Maybe others try to implement a similar canvas. So feel free to use this code. If it saves you some time, it would be my pleasure.
bikebot/Compose-Canvas-Pan-Zoom
Example code for a Jetpack Compose canvas that can be panned and zoomed. The canvas shows a rectangle that can be selected
Kotlin