The solution I came up with for this type of problem (it was only used internally) was just published as a public npm module, feel free to check it out, maybe it's useful to you: https://www.npmjs.com/package/@glowingblue-dev/shadow-css