Resize HTML canvas with respect to inner content
I am currently making an esoteric language which requires a theoretically infinite canvas. Basically, it should be able to resize and fit the contents of the drawing in and outside it's existing boundaries.
The brown region indicates the original canvas boundaries. The black lines are the drawing, and the red boundary is what it should expand to.
When I tried searching about this, all I got was things relating to using the
<canvas> tag in a responsive layout.
How do I achieve this effect using the HTML