{"version":3,"sources":["../../src/use-performance-observer/index.ts"],"sourcesContent":["import { useWebObserver } from '../use-web-observer'\nimport { isDev } from '../utils/basic'\n\nimport type { UseWebObserverOptions, UseWebObserverReturns } from '../use-web-observer'\n\nexport interface UsePerformanceObserverOptions\n  extends UseWebObserverOptions,\n    Omit<PerformanceObserverInit, 'entryTypes'> {\n  entryTypes: string[]\n}\n\nexport interface UsePerformanceObserverReturns extends UseWebObserverReturns<PerformanceObserver> {}\n\n/**\n * A React Hook that helps to use [PerformanceObserver API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver) with ease.\n */\nexport function usePerformanceObserver(\n  callback: PerformanceObserverCallback,\n  options: Omit<UsePerformanceObserverOptions, 'supported'>,\n): UsePerformanceObserverReturns {\n  const { immediate = true, ...observerOptions } = options\n\n  if (isDev) {\n    if (!options.entryTypes || !Array.isArray(options.entryTypes) || options.entryTypes.length === 0) {\n      throw new Error('usePerformanceObserver: entryTypes must be an array and not empty.')\n    }\n  }\n\n  return useWebObserver(\n    'PerformanceObserver',\n    undefined,\n    callback,\n    {\n      immediate,\n      supported() {\n        const isSupportedEntryTypesSupported = 'supportedEntryTypes' in PerformanceObserver\n\n        return options.entryTypes.every((e) => {\n          return isSupportedEntryTypesSupported && PerformanceObserver.supportedEntryTypes.includes(e)\n        })\n      },\n    },\n    undefined,\n    observerOptions,\n  )\n}\n"],"names":["usePerformanceObserver","callback","options","immediate","observerOptions","isDev","entryTypes","Array","isArray","length","Error","useWebObserver","undefined","supported","isSupportedEntryTypesSupported","PerformanceObserver","every","e","supportedEntryTypes","includes"],"mappings":";;;;+BAgBgBA;;;eAAAA;;;8BAhBe;qBACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAef,SAASA,uBACdC,QAAqC,EACrCC,OAAyD;IAEzD,yBAAiDA,QAAzCC,WAAAA,4CAAY,2BAASC,6CAAoBF;;;IAEjD,IAAIG,YAAK,EAAE;QACT,IAAI,CAACH,QAAQI,UAAU,IAAI,CAACC,MAAMC,OAAO,CAACN,QAAQI,UAAU,KAAKJ,QAAQI,UAAU,CAACG,MAAM,KAAK,GAAG;YAChG,MAAM,IAAIC,MAAM;QAClB;IACF;IAEA,OAAOC,IAAAA,8BAAc,EACnB,uBACAC,WACAX,UACA;QACEE,WAAAA;QACAU,WAAAA,SAAAA;YACE,IAAMC,iCAAiC,yBAAyBC;YAEhE,OAAOb,QAAQI,UAAU,CAACU,KAAK,CAAC,SAACC;gBAC/B,OAAOH,kCAAkCC,oBAAoBG,mBAAmB,CAACC,QAAQ,CAACF;YAC5F;QACF;IACF,GACAL,WACAR;AAEJ"}