{"version":3,"file":"index.cjs","sources":["../../src/vue/context/pdf-engine-context.ts","../../src/vue/composables/use-engine-context.ts","../../src/vue/composables/use-pdfium-engine.ts","../../src/vue/components/pdf-engine-provider.vue"],"sourcesContent":["import { InjectionKey, Ref } from 'vue';\r\nimport type { PdfEngine } from '@elhalawany/models';\r\n\r\nexport interface PdfEngineContextState {\r\n  engine: Ref<PdfEngine | null>;\r\n  isLoading: Ref<boolean>;\r\n  error: Ref<Error | null>;\r\n}\r\n\r\nexport const pdfEngineKey: InjectionKey<PdfEngineContextState> = Symbol('pdfEngineKey');\r\n","import { inject } from 'vue';\r\nimport { pdfEngineKey, PdfEngineContextState } from '../context/pdf-engine-context';\r\n\r\n/**\r\n * Composable to access the PDF engine from context.\r\n * @returns The PDF engine context state\r\n * @throws Error if used outside of PdfEngineProvider\r\n */\r\nexport function useEngineContext(): PdfEngineContextState {\r\n  const contextValue = inject(pdfEngineKey);\r\n\r\n  if (!contextValue) {\r\n    throw new Error('useEngineContext must be used within a PdfEngineProvider');\r\n  }\r\n\r\n  return contextValue;\r\n}\r\n\r\n/**\r\n * Composable to access the PDF engine, with a more convenient API.\r\n * @returns The PDF engine or null if loading/error\r\n */\r\nexport function useEngine() {\r\n  const { engine, error } = useEngineContext();\r\n\r\n  if (error.value) {\r\n    throw error.value;\r\n  }\r\n\r\n  return engine;\r\n}\r\n","import { ref, onMounted, onBeforeUnmount, watch, Ref } from 'vue';\r\nimport { ignore, type Logger, type PdfEngine } from '@elhalawany/models';\r\n\r\nconst defaultWasmUrl =\r\n  'https://cdn.jsdelivr.net/npm/@elhalawany/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm';\r\n\r\ninterface UsePdfiumEngineProps {\r\n  wasmUrl?: string;\r\n  worker?: boolean;\r\n  logger?: Logger;\r\n}\r\n\r\ninterface UsePdfiumEngineResult {\r\n  engine: Ref<PdfEngine | null>;\r\n  isLoading: Ref<boolean>;\r\n  error: Ref<Error | null>;\r\n}\r\n\r\n/**\r\n * Vue composable that loads a PdfiumEngine (worker or direct)\r\n * and keeps its lifetime tied to the component.\r\n */\r\nexport function usePdfiumEngine(props: UsePdfiumEngineProps = {}): UsePdfiumEngineResult {\r\n  const { wasmUrl = defaultWasmUrl, worker = true, logger } = props;\r\n\r\n  const engine = ref<PdfEngine | null>(null);\r\n  const isLoading = ref(true);\r\n  const error = ref<Error | null>(null);\r\n\r\n  /* create / destroy tied to component lifecycle ----------------- */\r\n  onMounted(loadEngine);\r\n  onBeforeUnmount(destroyEngine);\r\n\r\n  /* re‑load if reactive props change ----------------------------- */\r\n  watch(\r\n    () => [wasmUrl, worker, logger] as const,\r\n    () => {\r\n      destroyEngine();\r\n      loadEngine();\r\n    },\r\n  );\r\n\r\n  async function loadEngine() {\r\n    try {\r\n      const { createPdfiumEngine } = worker\r\n        ? await import('@elhalawany/engines/pdfium-worker-engine')\r\n        : await import('@elhalawany/engines/pdfium-direct-engine');\r\n\r\n      const pdfEngine = await createPdfiumEngine(wasmUrl, logger);\r\n      pdfEngine.initialize().wait(\r\n        () => {\r\n          isLoading.value = false;\r\n          engine.value = pdfEngine;\r\n        },\r\n        (e) => {\r\n          error.value = new Error(e.reason.message);\r\n          isLoading.value = false;\r\n        },\r\n      );\r\n      isLoading.value = false;\r\n    } catch (e) {\r\n      error.value = e as Error;\r\n      isLoading.value = false;\r\n    }\r\n  }\r\n\r\n  function destroyEngine() {\r\n    engine.value?.closeAllDocuments?.().wait(() => {\r\n      engine.value?.destroy?.();\r\n      engine.value = null;\r\n    }, ignore);\r\n  }\r\n\r\n  return { engine, isLoading, error };\r\n}\r\n","<script setup lang=\"ts\">\r\nimport { provide, toRefs } from 'vue';\r\nimport { pdfEngineKey } from '../context/pdf-engine-context';\r\nimport type { PdfEngine } from '@elhalawany/models';\r\n\r\ninterface Props {\r\n  engine: PdfEngine | null;\r\n  isLoading: boolean;\r\n  error: Error | null;\r\n}\r\n\r\nconst props = defineProps<Props>();\r\n\r\n// Convert props to refs and provide them\r\nconst { engine, isLoading, error } = toRefs(props);\r\n\r\nprovide(pdfEngineKey, {\r\n  engine,\r\n  isLoading,\r\n  error,\r\n});\r\n</script>\r\n\r\n<template>\r\n  <slot />\r\n</template>\r\n"],"names":["pdfEngineKey","Symbol","useEngineContext","contextValue","inject","Error","defaultWasmUrl","props","__props","engine","isLoading","error","toRefs","provide","_renderSlot","_ctx","$slots","value","wasmUrl","worker","logger","ref","async","loadEngine","createPdfiumEngine","import","pdfEngine","initialize","wait","e","reason","message","destroyEngine","_b","_a","closeAllDocuments","call","destroy","ignore","onMounted","onBeforeUnmount","vue","watch"],"mappings":"4RASaA,EAAoDC,OAAO,gBCDjE,SAASC,IACR,MAAAC,EAAeC,SAAOJ,GAE5B,IAAKG,EACG,MAAA,IAAIE,MAAM,4DAGX,OAAAF,CACT,CCbA,MAAMG,EACJ,8LCOF,MAAMC,EAAQC,GAGRC,OAAEA,EAAQC,UAAAA,EAAAC,MAAWA,GAAUC,EAAAA,OAAOL,UAE5CM,EAAAA,QAAQb,EAAc,CACpBS,SACAC,YACAC,iBAKAG,aAAQC,EAAAC,OAAA,4DFFH,WACL,MAAMP,OAAEA,EAAAE,MAAQA,GAAUT,IAE1B,GAAIS,EAAMM,MACR,MAAMN,EAAMM,MAGP,OAAAR,CACT,qDCRgB,SAAgBF,EAA8B,IAC5D,MAAMW,QAAEA,EAAUZ,EAAAa,OAAgBA,GAAS,EAAAC,OAAMA,GAAWb,EAEtDE,EAASY,MAAsB,MAC/BX,EAAYW,OAAI,GAChBV,EAAQU,MAAkB,MAehCC,eAAeC,IACT,IACI,MAAAC,mBAAEA,GAAuBL,QACrBM,OAAO,kDACPA,OAAO,4CAEXC,QAAkBF,EAAmBN,EAASE,GACpDM,EAAUC,aAAaC,MACrB,KACElB,EAAUO,OAAQ,EAClBR,EAAOQ,MAAQS,CAAA,IAEhBG,IACClB,EAAMM,MAAQ,IAAIZ,MAAMwB,EAAEC,OAAOC,SACjCrB,EAAUO,OAAQ,CAAA,IAGtBP,EAA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