Animated Gif stitching?

Im trying to generate animated gifs just like the export gif animation feature in inspector but do it programatically. I have a function that generates an array of base64 PNGs from the scene and thats fine, but and id like to stitch these together into a animated gif. So really I just need the javascript stitching part of it. For some reason I cant find this in docs or related source. I dont see anything here:

the only thing I did find was this package and I dont know if this is what BJS uses?

Thanks everyone

The implementation is there:

We are using gif.js.optimized.


You guys are awsome thanks for being my eyes. So much to comb through. Thank you again.