// @bun
var{defineProperty:J,getOwnPropertyNames:V,getOwnPropertyDescriptor:W}=Object,X=Object.prototype.hasOwnProperty;function Y(j){return this[j]}var H=(j)=>{var q=(Q??=new WeakMap).get(j),v;if(q)return q;if(q=J({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var w of V(j))if(!X.call(q,w))J(q,w,{get:Y.bind(j,w),enumerable:!(v=W(j,w))||v.enumerable})}return Q.set(j,q),q},Q;var Z=(j)=>j;function $(j,q){this[j]=Z.bind(null,q)}var I=(j,q)=>{for(var v in q)J(j,v,{get:q[v],enumerable:!0,configurable:!0,set:$.bind(q,v)})};var N=(j,q)=>()=>(j&&(q=j(j=0)),q);var P=import.meta.require;function U(j,q){if(q.theme===!1)return j;let v=typeof q.theme==="object"&&q.theme!==null?q.theme:{},w=v.default??"dark",M=v.storageKey??"theme",z=v.colors?.light??"#ffffff",B=v.colors?.dark??"#000000";if(w==="dark"){if(!/<html\b[^>]*\bclass=/.test(j))j=j.replace(/<html\b([^>]*)>/i,'<html$1 class="dark">');else if(!/<html\b[^>]*\bclass="[^"]*\bdark\b/.test(j))j=j.replace(/<html\b([^>]*\bclass=")([^"]*)(")/i,"<html$1$2 dark$3")}if(!j.includes("data-stx-theme-meta")&&/<head\b[^>]*>/i.test(j)){let x=['<meta name="color-scheme" content="dark light" data-stx-theme-meta="1">',`<meta name="theme-color" media="(prefers-color-scheme: light)" content="${z}" data-stx-theme-meta="1">`,`<meta name="theme-color" media="(prefers-color-scheme: dark)" content="${B}" data-stx-theme-meta="1">`].join(`
  `);j=j.replace(/<head\b([^>]*)>/i,`<head$1>
  ${x}`)}if(!j.includes("__stxThemeGuard")&&/<head\b[^>]*>/i.test(j)){let x=`<script data-stx-theme-guard="1">${D(w,M,z,B)};window.__stxThemeGuard=1;</script>`;j=j.replace(/<head\b([^>]*)>/i,`<head$1>
  ${x}`)}if(!j.includes("__stxThemeToggle")&&/<\/body>/i.test(j)){let x=`<script data-stx-theme-toggle="1">${F(M,z,B)};window.__stxThemeToggle=1;</script>`;j=j.replace(/<\/body>/i,`${x}
</body>`)}return j}var D=(j,q,v,w)=>`(function(){function read(){try{var k=${JSON.stringify(q)};var t=localStorage.getItem(k);return t===null?(${JSON.stringify(j)}==='dark'||(${JSON.stringify(j)}==='auto'&&window.matchMedia('(prefers-color-scheme: dark)').matches)):t==='dark'}catch(e){return ${JSON.stringify(j)}==='dark'}}function apply(){var isDark=read();var html=document.documentElement;html.classList[isDark?'add':'remove']('dark');var color=isDark?${JSON.stringify(w)}:${JSON.stringify(v)};if(!document.head)return;var tc=document.querySelector('meta[name="theme-color"]:not([media])');if(!tc){tc=document.createElement('meta');tc.setAttribute('name','theme-color');tc.setAttribute('data-stx-theme-meta','1')}tc.setAttribute('content',color);if(tc!==document.head.firstChild){document.head.insertBefore(tc,document.head.firstChild)}}apply();window.addEventListener('stx:navigate',apply);window.addEventListener('popstate',apply)})();`,F=(j,q,v)=>`document.addEventListener('click',function(e){var t=e.target&&e.target.closest&&e.target.closest('#theme-toggle');if(!t)return;var html=document.documentElement;var isDark=html.classList.toggle('dark');try{localStorage.setItem(${JSON.stringify(j)},isDark?'dark':'light')}catch(e){}var tc=document.querySelector('meta[name="theme-color"]:not([media])');if(tc)tc.setAttribute('content',isDark?${JSON.stringify(v)}:${JSON.stringify(q)})});`;export{U as injectThemeBootstrap};
