Hi there!
I've just types some javascript until it worked. (Honestly, it's some rubbish code there!). I mostly relied on the browser's Canvas Api.
The "layering" - if I can call it like that - is just drawing elements on the in-memeory canvas where I want them in the order I want them - no magic here.
The export is done with an old trick of assigning base64 encoded canvas (exportLink.href = canvas.toDataURL("image/png")) into the export anchor's href attribute on every change.
This technique has some limitations but for small files it works like a charm.
Let know if you have more questions, and good luck with your tool!