// @bun
var{defineProperty:Q,getOwnPropertyNames:W,getOwnPropertyDescriptor:X}=Object,Y=Object.prototype.hasOwnProperty;function Z(z){return this[z]}var F=(z)=>{var j=(U??=new WeakMap).get(z),J;if(j)return j;if(j=Q({},"__esModule",{value:!0}),z&&typeof z==="object"||typeof z==="function"){for(var G of W(z))if(!Y.call(j,G))Q(j,G,{get:Z.bind(z,G),enumerable:!(J=X(z,G))||J.enumerable})}return U.set(z,j),j},U;var _=(z)=>z;function $(z,j){this[z]=_.bind(null,j)}var R=(z,j)=>{for(var J in j)Q(z,J,{get:j[J],enumerable:!0,configurable:!0,set:$.bind(j,J)})};var T=(z,j)=>()=>(z&&(j=z(z=0)),j);var w=import.meta.require;function V(){return typeof window<"u"&&"EyeDropper"in window}function v(z={}){let{onPick:j,onAbort:J,onError:G}=z,K=V(),I=new Set,B={isSupported:K,isOpen:!1,sRGBHex:null,error:null},M=null;function L(){I.forEach((q)=>q(B))}async function O(){if(!K||!window.EyeDropper){let q=Error("EyeDropper API not supported");return B={...B,error:q},L(),G?.(q),null}M?.abort(),M=new AbortController,B={...B,isOpen:!0,error:null},L();try{let N=await new window.EyeDropper().open({signal:M.signal});return B={...B,isOpen:!1,sRGBHex:N.sRGBHex},L(),j?.(N.sRGBHex),N.sRGBHex}catch(q){if(B={...B,isOpen:!1},q.name==="AbortError")return J?.(),L(),null;return B={...B,error:q},L(),G?.(q),null}}return{get:()=>B,subscribe:(q)=>{return I.add(q),q(B),()=>{if(I.delete(q),I.size===0)M?.abort()}},open:O,isSupported:()=>K}}async function E(){if(!V()||!window.EyeDropper)return null;try{return(await new window.EyeDropper().open()).sRGBHex}catch{return null}}function A(z){let j=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(z);return j?{r:Number.parseInt(j[1],16),g:Number.parseInt(j[2],16),b:Number.parseInt(j[3],16)}:null}function C(z){let j=A(z);if(!j)return null;let J=j.r/255,G=j.g/255,K=j.b/255,I=Math.max(J,G,K),B=Math.min(J,G,K),M=(I+B)/2;if(I===B)return{h:0,s:0,l:Math.round(M*100)};let L=I-B,O=M>0.5?L/(2-I-B):L/(I+B),q=0;switch(I){case J:q=((G-K)/L+(G<K?6:0))/6;break;case G:q=((K-J)/L+2)/6;break;case K:q=((J-G)/L+4)/6;break}return{h:Math.round(q*360),s:Math.round(O*100),l:Math.round(M*100)}}function H(z={}){let{maxHistory:j=20,onPick:J}=z,G=v({onPick:J}),K=new Set,I=[];function B(){let q={current:G.get().sRGBHex,history:I};K.forEach((N)=>N(q))}G.subscribe((q)=>{if(q.sRGBHex&&!I.includes(q.sRGBHex))I=[q.sRGBHex,...I].slice(0,j),B()});async function M(){return G.open()}function L(){I=[],B()}function O(q){I=I.filter((N)=>N!==q),B()}return{get:()=>({current:G.get().sRGBHex,history:I}),subscribe:(q)=>{return K.add(q),q({current:G.get().sRGBHex,history:I}),()=>{K.delete(q)}},pick:M,clearHistory:L,removeFromHistory:O,isSupported:G.isSupported}}export{v as useEyeDropper,H as useColorHistory,E as pickColor,V as isEyeDropperSupported,A as hexToRgb,C as hexToHsl};
