var e=()=>String(globalThis?.location?.protocol||``)===`chrome-extension:`,t=`he_theme`,n=()=>{if(e())return`light`;try{let e=localStorage.getItem(t);return e===`dark`||e===`light`?e:`light`}catch{return`light`}},r=(t=n())=>e()?`light`:t===`dark`?`dark`:`light`,i=(i=n())=>{let a=e()?`light`:r(i);try{document.documentElement.setAttribute(`data-theme`,a)}catch{}try{document.documentElement.setAttribute(`data-theme-mode`,a)}catch{}try{e()&&localStorage.setItem(t,`light`)}catch{}return a},a=n=>{let r=e()?`light`:n;try{localStorage.setItem(t,r)}catch{}let a=i(r);try{window.dispatchEvent(new CustomEvent(`he-theme-change`,{detail:{mode:r,theme:a}}))}catch{}return{mode:r,theme:a}},o=e=>e===`light`?`dark`:`light`,s=r=>{if(e())return()=>{};let a=()=>r({mode:n(),theme:i(n())}),o=e=>{String(e?.key||``)===t&&a()},s=()=>a();try{window.addEventListener(`storage`,o)}catch{}try{window.addEventListener(`he-theme-change`,s)}catch{}return()=>{try{window.removeEventListener(`storage`,o)}catch{}try{window.removeEventListener(`he-theme-change`,s)}catch{}}};export{n as a,r as i,o as n,a as o,e as r,s,i as t};