I have also been looking for a solution to this problem. »document« has an additional property theme:
document.theme.onUpdated.addListener((theme) => {
console.log(theme);
const themeElemList = document.querySelectorAll("sp-theme");
themeElemList.forEach((elem) => {
elem.setAttribute("color", theme);
});
});
Must test it in more detail but so far it seems to work.