{"version":3,"file":"use-eye-dropper.cjs","names":[],"sources":["../../src/use-eye-dropper/use-eye-dropper.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\n\nexport interface EyeDropperOpenOptions {\n  signal?: AbortSignal;\n}\n\nexport interface EyeDropperOpenReturnType {\n  sRGBHex: string;\n}\n\nexport interface UseEyeDropperReturnValue {\n  supported: boolean;\n  open: (options?: EyeDropperOpenOptions) => Promise<EyeDropperOpenReturnType | undefined>;\n}\n\nexport function useEyeDropper(): UseEyeDropperReturnValue {\n  const [supported, setSupported] = useState(false);\n\n  useIsomorphicEffect(() => {\n    setSupported(typeof window !== 'undefined' && !isOpera() && 'EyeDropper' in window);\n  }, []);\n\n  const open = useCallback(\n    (options: EyeDropperOpenOptions = {}): Promise<EyeDropperOpenReturnType | undefined> => {\n      if (supported) {\n        const eyeDropper = new (window as any).EyeDropper();\n        return eyeDropper.open(options);\n      }\n\n      return Promise.resolve(undefined);\n    },\n    [supported]\n  );\n\n  return { supported, open };\n}\n\nfunction isOpera() {\n  return navigator.userAgent.includes('OPR');\n}\n"],"mappings":";;;;AAgBA,SAAgB,gBAA0C;CACxD,MAAM,CAAC,WAAW,iBAAA,GAAA,MAAA,UAAyB,MAAM;AAEjD,+BAAA,0BAA0B;AACxB,eAAa,OAAO,WAAW,eAAe,CAAC,SAAS,IAAI,gBAAgB,OAAO;IAClF,EAAE,CAAC;AAcN,QAAO;EAAE;EAAW,OAAA,GAAA,MAAA,cAXjB,UAAiC,EAAE,KAAoD;AACtF,OAAI,UAEF,QADmB,IAAK,OAAe,YAAY,CACjC,KAAK,QAAQ;AAGjC,UAAO,QAAQ,QAAQ,KAAA,EAAU;KAEnC,CAAC,UAAU,CACZ;EAEyB;;AAG5B,SAAS,UAAU;AACjB,QAAO,UAAU,UAAU,SAAS,MAAM"}