{"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-export.svelte.ts","../../src/svelte/components/Download.svelte","../../src/svelte/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { ExportPlugin, ExportScope } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseExportReturn {\n  provides: ExportScope | null;\n}\n\n/**\n * Hook for export capability for a specific document\n * @param getDocumentId Function that returns the document ID\n */\nexport const useExport = (getDocumentId: () => string | null): UseExportReturn => {\n  const capability = useExportCapability();\n\n  // Reactive documentId\n  const documentId = $derived(getDocumentId());\n\n  // Scoped capability for current docId\n  const scopedProvides = $derived(\n    capability.provides && documentId ? capability.provides.forDocument(documentId) : null,\n  );\n\n  return {\n    get provides() {\n      return scopedProvides;\n    },\n  };\n};\n","<script lang=\"ts\">\n  import { ignore } from '@embedpdf/models';\n  import { useExportCapability, useExportPlugin } from '../hooks';\n\n  const exportCapability = useExportCapability();\n  const exportPlugin = useExportPlugin();\n\n  let anchorElement: HTMLAnchorElement | undefined;\n\n  $effect(() => {\n    if (!exportCapability.provides) return;\n    if (!exportPlugin.plugin) return;\n\n    const unsub = exportPlugin.plugin.onRequest((event) => {\n      const el = anchorElement;\n      if (!el) return;\n\n      const task = exportPlugin.plugin?.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  });\n</script>\n\n<a style=\"display: none\" bind:this={anchorElement} href=\"/\" aria-label=\"Download link\"></a>\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './components';\n\nexport * from './hooks';\nexport * from './components';\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","exportCapability","exportPlugin","anchorElement","$","user_effect","provides","plugin","onRequest","event","el","task","_a","saveAsCopyAndGetBufferAndName","documentId","wait","buffer","name","url","URL","createObjectURL","Blob","href","download","click","revokeObjectURL","ignore","a","root","$$value","ExportPluginPackage","createPluginPackage","BaseExportPackage","addUtility","Download","build","getDocumentId","capability","scopedProvides","derived","forDocument"],"mappings":"skBAGaA,EAAA,IAAwBC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAA,IAA4BC,gBAA4BH,EAAAA,aAAaC,wHCA1E,MAAAG,EAAmBF,IACnBG,EAAeP,QAEjBQ,EAEJC,EAAAC,YAAO,KACA,IAAAJ,EAAiBK,SAAQ,OACzB,IAAAJ,EAAaK,OAAM,cAEVL,EAAaK,OAAOC,UAAWC,UACrC,MAAAC,EAAKP,MACNO,EAAE,aAEDC,EAAO,OAAAC,EAAAV,EAAaK,aAAb,EAAAK,EAAqBC,8BAA8BJ,EAAMK,YACtE,MAAAH,GAAAA,EAAMI,OAAQC,SAAQC,WACd,MAAAC,EAAMC,IAAIC,gBAAe,IAAKC,MAAML,KAC1CN,EAAGY,KAAOJ,EACVR,EAAGa,SAAWN,EACdP,EAAGc,QACHL,IAAIM,gBAAgBP,IACnBQ,EAAAA,gBAORC,EAACC,gBAADD,EAACE,GAAkC1B,EAAa0B,EAAA,IAAb1B,cAAnCwB,UAFO,CCnBD,MAAMG,EAAsBC,EAAAA,oBAAoBC,EAAAA,qBACpDC,WAAWC,GACXC,2EFGuBC,IAClB,MAAAC,EAAatC,IAGbe,YAAsBsB,GAGtBE,EAAAlC,EAAAmC,QAAA,IACJF,EAAW/B,gBAAYQ,GAAauB,EAAW/B,SAASkC,kBAAY1B,IAAc,aAI9E,YAAAR,gBACKgC,EACT"}