{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-export.ts","../../src/shared/component/download.tsx","../../src/shared/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n\n/**\n * Hook for export capability for a specific document\n * @param documentId Document ID\n */\nexport const useExport = (documentId: string) => {\n  const { provides } = useExportCapability();\n\n  return {\n    provides: provides?.forDocument(documentId) ?? null,\n  };\n};\n","import { ignore } from '@embedpdf/models';\nimport { useEffect, useRef } from '@framework';\n\nimport { useExportPlugin } from '../hooks';\n\nexport function Download() {\n  const { plugin: exportPlugin } = useExportPlugin();\n  const ref = useRef<HTMLAnchorElement>(null);\n\n  useEffect(() => {\n    if (!exportPlugin) return;\n\n    const unsub = exportPlugin.onRequest((event) => {\n      const el = ref.current;\n      if (!el) return;\n\n      const task = exportPlugin.saveAsCopyAndGetBufferAndName(event.documentId);\n      task.wait(({ buffer, name }) => {\n        const url = URL.createObjectURL(new Blob([buffer]));\n        el.href = url;\n        el.download = name;\n        el.click();\n        URL.revokeObjectURL(url);\n      }, ignore);\n    });\n\n    return unsub;\n  }, [exportPlugin]);\n\n  return <a style={{ display: 'none' }} ref={ref} />;\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './component';\n\nexport * from './hooks';\nexport * from './component';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n  .addUtility(Download)\n  .build();\n"],"names":["useExportPlugin","usePlugin","ExportPlugin","id","useExportCapability","useCapability","Download","plugin","exportPlugin","ref","useRef","useEffect","onRequest","event","el","current","saveAsCopyAndGetBufferAndName","documentId","wait","buffer","name","url","URL","createObjectURL","Blob","href","download","click","revokeObjectURL","ignore","style","display","ExportPluginPackage","createPluginPackage","BaseExportPackage","addUtility","build","provides","forDocument"],"mappings":"kRAGaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,ICC3E,SAASG,IACd,MAAQC,OAAQC,GAAiBR,IAC3BS,EAAMC,EAAAA,OAA0B,MAsBtC,OApBAC,EAAAA,UAAU,KACR,IAAKH,EAAc,OAgBnB,OAdcA,EAAaI,UAAWC,IACpC,MAAMC,EAAKL,EAAIM,QACf,IAAKD,EAAI,OAEIN,EAAaQ,8BAA8BH,EAAMI,YACzDC,KAAK,EAAGC,SAAQC,WACnB,MAAMC,EAAMC,IAAIC,gBAAgB,IAAIC,KAAK,CAACL,KAC1CL,EAAGW,KAAOJ,EACVP,EAAGY,SAAWN,EACdN,EAAGa,QACHL,IAAIM,gBAAgBP,IACnBQ,EAAAA,WAIJ,CAACrB,UAEI,IAAA,CAAEsB,MAAO,CAAEC,QAAS,QAAUtB,OACxC,CCpBO,MAAMuB,EAAsBC,EAAAA,oBAAoBC,EAAAA,qBACpDC,WAAW7B,GACX8B,2EFFuBnB,IACxB,MAAMoB,SAAEA,GAAajC,IAErB,MAAO,CACLiC,UAAU,MAAAA,OAAA,EAAAA,EAAUC,YAAYrB,KAAe"}