{"version":3,"file":"useTheme.mjs","names":[],"sources":["../../../../../../../../src/lib/theming/hooks/useTheme.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport type { Theme } from \"../types\";\nimport { themeHtmlAttribute } from \"../lib/keys\";\nimport { getTheme } from \"../lib/getTheme\";\n\nexport const useTheme = (): Theme => {\n  const initialTheme = getTheme();\n  const [theme, setTheme] = useState<Theme>(initialTheme);\n\n  useEffect(() => {\n    const mutationObserver = new MutationObserver((changes) => {\n      for (const change of changes) {\n        if (\n          change.type === \"attributes\" &&\n          change.attributeName === themeHtmlAttribute\n        ) {\n          setTheme(getTheme());\n        }\n      }\n    });\n\n    mutationObserver.observe(document.documentElement, {\n      attributes: true,\n      attributeFilter: [themeHtmlAttribute],\n    });\n\n    return () => {\n      mutationObserver.disconnect();\n    };\n  }, [setTheme]);\n\n  return theme;\n};\n"],"mappings":";;;;;;AAKA,IAAa,iBAAwB;CACnC,MAAM,eAAe,SAAS;CAC9B,MAAM,CAAC,OAAO,YAAY,SAAgB,YAAY;CAEtD,gBAAgB;EACd,MAAM,mBAAmB,IAAI,kBAAkB,YAAY;GACzD,KAAK,MAAM,UAAU,SACnB,IACE,OAAO,SAAS,gBAChB,OAAO,kBAAA,cAEP,SAAS,SAAS,CAAC;EAGzB,CAAC;EAED,iBAAiB,QAAQ,SAAS,iBAAiB;GACjD,YAAY;GACZ,iBAAiB,CAAC,kBAAkB;EACtC,CAAC;EAED,aAAa;GACX,iBAAiB,WAAW;EAC9B;CACF,GAAG,CAAC,QAAQ,CAAC;CAEb,OAAO;AACT"}