import{s as e}from"./chunk-Bj-mKKzh.js";import{n as t}from"./jsx-runtime-CiQ1k8xo.js";var n=e(t(),1),r=.5,i=null,a=new Set,o=null,s=null,c=null;function l(){for(let e of a)e()}function u(){let e=w();e!==i&&(i=e,l())}function d(e){if(e.rel!==`stylesheet`)return;if(e.sheet){queueMicrotask(()=>{u()});return}let t=()=>{u()};e.addEventListener(`load`,t,{once:!0}),e.addEventListener(`error`,t,{once:!0})}function f(e){if(e.type===`childList`){let t=!1;for(let n of Array.from(e.addedNodes))n instanceof HTMLLinkElement&&n.rel===`stylesheet`&&(d(n),t=!0);(e.removedNodes.length>0||!t)&&u();return}if(e.type===`attributes`){let t=e.target;if(t instanceof HTMLLinkElement&&t.rel===`stylesheet`&&(e.attributeName===`href`||e.attributeName===`media`||e.attributeName===`rel`)){d(t);return}u()}}function p(){if(typeof window>`u`||o||s)return;u(),o=new MutationObserver(e=>{for(let t of e)if(t.type===`attributes`){u();break}}),o.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`style`]});let e=document.head;e&&(s=new MutationObserver(e=>{for(let t of e)if(t.type===`childList`||t.type===`attributes`){f(t);break}}),s.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`href`,`media`,`rel`]})),typeof window<`u`&&typeof window.matchMedia==`function`&&(c=window.matchMedia(`(prefers-color-scheme: dark)`),c.addEventListener(`change`,u))}function m(){o?.disconnect(),s?.disconnect(),o=null,s=null,c?.removeEventListener(`change`,u),c=null}function h(e){return a.add(e),p(),()=>{a.delete(e),a.size===0&&m()}}function g(){return i}function _(){return(0,n.useSyncExternalStore)(h,g,g)}function v(e,t,n){let r=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4},i=r(e),a=r(t),o=r(n);return .2126*i+.7152*a+.0722*o}function y(e){let t=e.trim().toLowerCase();if(!t)return null;if(t.startsWith(`#`)){let e=t.slice(1),n=e=>e+e;return e.length===3||e.length===4?{r:parseInt(n(e[0]),16),g:parseInt(n(e[1]),16),b:parseInt(n(e[2]),16)}:e.length===6||e.length===8?{r:parseInt(e.slice(0,2),16),g:parseInt(e.slice(2,4),16),b:parseInt(e.slice(4,6),16)}:null}let n=t.match(/^rgba?\(([^)]+)\)$/);if(n){let e=n[1].split(/\s*,\s*/).map(e=>e.trim());if(e.length>=3){let t=b(e[0]),n=b(e[1]),r=b(e[2]);if(t!=null&&n!=null&&r!=null)return{r:t,g:n,b:r}}return null}let r=t.match(/^hsla?\(([^)]+)\)$/);if(r){let e=r[1].split(/\s*,\s*/).map(e=>e.trim());if(e.length>=3){let t=parseFloat(e[0]),n=x(e[1]),r=x(e[2]);if([t,n,r].every(e=>!Number.isNaN(e))){let{r:e,g:i,b:a}=S(t,n,r);return{r:e,g:i,b:a}}}return null}return null}function b(e){if(e.endsWith(`%`)){let t=parseFloat(e.slice(0,-1));return Number.isNaN(t)?null:Math.round(t/100*255)}let t=parseFloat(e);return Number.isNaN(t)?null:Math.max(0,Math.min(255,t))}function x(e){if(e.endsWith(`%`)){let t=parseFloat(e.slice(0,-1));return Number.isNaN(t)?0:t/100}let t=parseFloat(e);return Number.isNaN(t)?0:t/100}function S(e,t,n){let r=(1-Math.abs(2*n-1))*t,i=e%360/60,a=r*(1-Math.abs(i%2-1)),o=0,s=0,c=0;i>=0&&i<1?[o,s,c]=[r,a,0]:i>=1&&i<2?[o,s,c]=[a,r,0]:i>=2&&i<3?[o,s,c]=[0,r,a]:i>=3&&i<4?[o,s,c]=[0,a,r]:i>=4&&i<5?[o,s,c]=[a,0,r]:i>=5&&i<6&&([o,s,c]=[r,0,a]);let l=n-r/2;return{r:Math.round((o+l)*255),g:Math.round((s+l)*255),b:Math.round((c+l)*255)}}function C(){if(typeof window>`u`)return null;try{let e=document.createElement(`div`);e.style.display=`none`,e.style.backgroundColor=`var(--color-token-editor-background)`,document.body.appendChild(e);let t=getComputedStyle(e).backgroundColor||``;return e.remove(),t}catch{return null}}function w(){let e=C();if(!e)return null;let t=y(e);return t?v(t.r,t.g,t.b)<r:null}export{_ as t};
//# sourceMappingURL=use-is-dark-DM2fOM7F.js.map