How to Make a Responsive Canvas with Konva
A canvas has a display size and a drawing size. A CSS resize changes only the display size. This change can stretch the rendered pixels.
For a responsive Konva scene, define a fixed virtual size. Then scale the stage from the available container width.
The scale formula is:
scale = containerWidth / virtualWidth
The displayed height is virtualHeight * scale. All node coordinates stay in
the virtual coordinate system.
Responsive React example
This example uses ResizeObserver. The observer responds when the container
changes size, not only when the browser window changes size.
Do not store scaled coordinates in application state. Store virtual coordinates. Konva applies the stage scale during rendering and pointer conversion.
For high pixel density, Konva uses the device pixel ratio by default. Do not
multiply the stage size by devicePixelRatio unless the application manages
the backing store itself.
For more stage-resize details, see the responsive sandbox demo.