I’ve been working with Tone.Js recently and it’s been quite pleasant! Seems like it could handle this use case as well, fairly trivially. Worst part has been finding good royalty free sample sources for instruments.
https://github.com/sgossner/VCSL
There's also Tidal Cycles Drum Machines (and by the looks of things quite a few other tidal sample repos), but I'm not actually sure if this is public-domain
It's used in a side project I've had around for a while: https://random-music-generators.onrender.com/