{"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-export.ts","../../src/vue/components/download.vue","../../src/vue/index.ts"],"sourcesContent":["import { computed, MaybeRefOrGetter, toValue } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\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 (can be ref, computed, getter, or plain value)\n */\nexport const useExport = (documentId: MaybeRefOrGetter<string>) => {\n  const { provides } = useExportCapability();\n\n  return {\n    provides: computed(() => provides.value?.forDocument(toValue(documentId)) ?? null),\n  };\n};\n","<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted } from 'vue';\nimport { ignore } from '@embedpdf/models';\nimport { Unsubscribe } from '@embedpdf/core';\n\nimport { useExportCapability, useExportPlugin } from '../hooks';\n\nconst { provides: exportCapabilityRef } = useExportCapability();\nconst { plugin: exportPluginRef } = useExportPlugin();\nconst anchorRef = ref<HTMLAnchorElement | null>(null);\n\nlet unsubscribe: Unsubscribe | null = null;\n\nonMounted(() => {\n  const exportCapability = exportCapabilityRef.value;\n  const exportPlugin = exportPluginRef.value;\n\n  if (!exportCapability || !exportPlugin) return;\n\n  unsubscribe = exportPlugin.onRequest((event) => {\n    const el = anchorRef.value;\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\nonUnmounted(() => {\n  if (unsubscribe) {\n    unsubscribe();\n  }\n});\n</script>\n\n<template>\n  <a ref=\"anchorRef\" style=\"display: none\" />\n</template>\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","provides","exportCapabilityRef","plugin","exportPluginRef","anchorRef","ref","unsubscribe","onMounted","exportCapability","value","exportPlugin","onRequest","event","el","saveAsCopyAndGetBufferAndName","documentId","wait","buffer","name","url","URL","createObjectURL","Blob","href","download","click","revokeObjectURL","ignore","onUnmounted","_createElementBlock","style","display","ExportPluginPackage","createPluginPackage","BaseExportPackage","addUtility","Download","build","computed","_a","forDocument","toValue"],"mappings":"sOAIaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,oDCElF,MAAQG,SAAUC,GAAwBH,KAClCI,OAAQC,GAAoBT,IAC9BU,EAAYC,EAAAA,IAA8B,MAEhD,IAAIC,EAAkC,YAEtCC,EAAAA,UAAU,KACR,MAAMC,EAAmBP,EAAoBQ,MACvCC,EAAeP,EAAgBM,MAEhCD,GAAqBE,IAE1BJ,EAAcI,EAAaC,UAAWC,IACpC,MAAMC,EAAKT,EAAUK,MACrB,IAAKI,EAAI,OAEIH,EAAaI,8BAA8BF,EAAMG,YACzDC,KAAK,EAAGC,SAAQC,WACnB,MAAMC,EAAMC,IAAIC,gBAAgB,IAAIC,KAAK,CAACL,KAC1CJ,EAAGU,KAAOJ,EACVN,EAAGW,SAAWN,EACdL,EAAGY,QACHL,IAAIM,gBAAgBP,IACnBQ,EAAAA,aAIPC,EAAAA,YAAY,KACNtB,GACFA,4BAMFuB,EAAAA,mBAA2C,IAAA,SAApC,YAAJxB,IAAID,EAAY0B,MAAA,CAAAC,QAAA,uBChCRC,EAAsBC,EAAAA,oBAAoBC,EAAAA,qBACpDC,WAAWC,GACXC,2EFDuBtB,IACxB,MAAMf,SAAEA,GAAaF,IAErB,MAAO,CACLE,SAAUsC,EAAAA,SAAS,WAAM,OAAA,OAAAC,EAAAvC,EAASS,YAAT,EAAA8B,EAAgBC,YAAYC,EAAAA,QAAQ1B,MAAgB"}