@embedpdf/engines 1.4.1 → 2.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/{engine-N_GwaBxA.js → engine-B-RaFU77.js} +98 -28
  2. package/dist/engine-B-RaFU77.js.map +1 -0
  3. package/dist/engine-CXnLqg_9.cjs +2 -0
  4. package/dist/engine-CXnLqg_9.cjs.map +1 -0
  5. package/dist/{index-DXUtjXMC.js → index-D92r9YXl.js} +3 -3
  6. package/dist/{index-DXUtjXMC.js.map → index-D92r9YXl.js.map} +1 -1
  7. package/dist/index-GEOxMZwR.cjs +2 -0
  8. package/dist/{index-CgsjfX9e.cjs.map → index-GEOxMZwR.cjs.map} +1 -1
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.js +3 -2
  11. package/dist/lib/converters/index.cjs.map +1 -1
  12. package/dist/lib/converters/index.js.map +1 -1
  13. package/dist/lib/pdfium/cache.d.ts +5 -2
  14. package/dist/lib/pdfium/engine.d.ts +1 -1
  15. package/dist/lib/pdfium/helper.d.ts +11 -0
  16. package/dist/lib/pdfium/index.cjs +1 -1
  17. package/dist/lib/pdfium/index.js +3 -2
  18. package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
  19. package/dist/lib/pdfium/web/direct-engine.cjs.map +1 -1
  20. package/dist/lib/pdfium/web/direct-engine.js +1 -1
  21. package/dist/lib/pdfium/web/direct-engine.js.map +1 -1
  22. package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
  23. package/dist/lib/pdfium/web/worker-engine.js +1 -1
  24. package/dist/lib/webworker/engine.cjs +1 -1
  25. package/dist/lib/webworker/engine.cjs.map +1 -1
  26. package/dist/lib/webworker/engine.js +1 -1
  27. package/dist/lib/webworker/engine.js.map +1 -1
  28. package/dist/preact/index.cjs +1 -1
  29. package/dist/preact/index.cjs.map +1 -1
  30. package/dist/preact/index.js +1 -1
  31. package/dist/preact/index.js.map +1 -1
  32. package/dist/react/index.cjs +1 -1
  33. package/dist/react/index.cjs.map +1 -1
  34. package/dist/react/index.js +1 -1
  35. package/dist/react/index.js.map +1 -1
  36. package/dist/svelte/index.cjs +1 -1
  37. package/dist/svelte/index.cjs.map +1 -1
  38. package/dist/svelte/index.js.map +1 -1
  39. package/dist/vue/components/pdf-engine-provider.vue.d.ts +3 -2
  40. package/dist/vue/index.cjs +1 -1
  41. package/dist/vue/index.cjs.map +1 -1
  42. package/dist/vue/index.js +1 -1
  43. package/dist/vue/index.js.map +1 -1
  44. package/package.json +3 -3
  45. package/dist/engine-N_GwaBxA.js.map +0 -1
  46. package/dist/engine-Z4iXwySK.cjs +0 -2
  47. package/dist/engine-Z4iXwySK.cjs.map +0 -1
  48. package/dist/index-CgsjfX9e.cjs +0 -2
@@ -1,2 +1,2 @@
1
- "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),r=require("@embedpdf/models"),t=require("react/jsx-runtime"),n="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@1.4.1/dist/pdfium.wasm";const i=e.createContext(void 0);function o(){const r=e.useContext(i);if(void 0===r)throw new Error("useEngineContext must be used within a PdfEngineProvider");return r}exports.PdfEngineProvider=function({children:e,engine:r,isLoading:n,error:o}){const s={engine:r,isLoading:n,error:o};return t.jsx(i.Provider,{value:s,children:e})},exports.useEngine=function(){const{engine:e,error:r}=o();if(r)throw r;return e},exports.useEngineContext=o,exports.usePdfiumEngine=function(t){const{wasmUrl:i=n,worker:o=!0,logger:s}=t??{},[u,c]=e.useState(null),[d,a]=e.useState(!0),[l,g]=e.useState(null),p=e.useRef(null);return e.useEffect((()=>{let e=!1;return(async()=>{try{const{createPdfiumEngine:e}=o?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),r=await e(i,s);p.current=r,r.initialize().wait((()=>{c(r),a(!1)}),(e=>{g(new Error(e.reason.message)),a(!1)}))}catch(r){e||(g(r),a(!1))}})(),()=>{var t,n;e=!0,null==(n=null==(t=p.current)?void 0:t.closeAllDocuments)||n.call(t).wait((()=>{var e,r;null==(r=null==(e=p.current)?void 0:e.destroy)||r.call(e),p.current=null}),r.ignore)}}),[i,o,s]),{engine:u,isLoading:d,error:l}};
1
+ "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),r=require("@embedpdf/models"),t=require("react/jsx-runtime"),n="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.0-next.0/dist/pdfium.wasm";const i=e.createContext(void 0);function o(){const r=e.useContext(i);if(void 0===r)throw new Error("useEngineContext must be used within a PdfEngineProvider");return r}exports.PdfEngineProvider=function({children:e,engine:r,isLoading:n,error:o}){const s={engine:r,isLoading:n,error:o};return t.jsx(i.Provider,{value:s,children:e})},exports.useEngine=function(){const{engine:e,error:r}=o();if(r)throw r;return e},exports.useEngineContext=o,exports.usePdfiumEngine=function(t){const{wasmUrl:i=n,worker:o=!0,logger:s}=t??{},[u,c]=e.useState(null),[d,a]=e.useState(!0),[l,g]=e.useState(null),p=e.useRef(null);return e.useEffect(()=>{let e=!1;return(async()=>{try{const{createPdfiumEngine:e}=o?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),r=await e(i,s);p.current=r,r.initialize().wait(()=>{c(r),a(!1)},e=>{g(new Error(e.reason.message)),a(!1)})}catch(r){e||(g(r),a(!1))}})(),()=>{var t,n;e=!0,null==(n=null==(t=p.current)?void 0:t.closeAllDocuments)||n.call(t).wait(()=>{var e,r;null==(r=null==(e=p.current)?void 0:e.destroy)||r.call(e),p.current=null},r.ignore)}},[i,o,s]),{engine:u,isLoading:d,error:l}};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-pdfium-engine.ts","../../src/shared/context/pdf-engine-context.ts","../../src/shared/hooks/use-engine-context.ts","../../src/shared/components/pdf-engine-provider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { ignore, Logger, PdfEngine } from '@embedpdf/models';\n\nconst defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm`;\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger } = config ?? {};\n\n const [engine, setEngine] = useState<PdfEngine | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const engineRef = useRef<PdfEngine | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, logger);\n engineRef.current = pdfEngine;\n pdfEngine.initialize().wait(\n () => {\n setEngine(pdfEngine);\n setLoading(false);\n },\n (e) => {\n setError(new Error(e.reason.message));\n setLoading(false);\n },\n );\n } catch (e) {\n if (!cancelled) {\n setError(e as Error);\n setLoading(false);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef.current?.closeAllDocuments?.().wait(() => {\n engineRef.current?.destroy?.();\n engineRef.current = null;\n }, ignore);\n };\n }, [wasmUrl, worker, logger]);\n\n return { engine, isLoading: loading, error };\n}\n","import { createContext } from '@framework';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport const PdfEngineContext = createContext<PdfEngineContextState | undefined>(undefined);\n","import { useContext } from '@framework';\nimport { PdfEngineContext, PdfEngineContextState } from '../context';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = useContext(PdfEngineContext);\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ReactNode } from '@framework';\nimport { PdfEngineContext } from '../context';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineProviderProps {\n children: ReactNode;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/**\n * Provider component that makes a PDF engine instance available\n * to all child components via context.\n *\n * This provider is completely engine-agnostic - it accepts any engine\n * and its loading state from the parent component.\n */\nexport function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps) {\n const contextValue = {\n engine,\n isLoading,\n error,\n };\n\n return <PdfEngineContext.Provider value={contextValue}>{children}</PdfEngineContext.Provider>;\n}\n"],"names":["defaultWasmUrl","PdfEngineContext","createContext","useEngineContext","contextValue","useContext","Error","children","engine","isLoading","error","Provider","value","config","wasmUrl","worker","logger","setEngine","useState","loading","setLoading","setError","engineRef","useRef","useEffect","cancelled","createPdfiumEngine","import","pdfEngine","current","initialize","wait","e","reason","message","_b","_a","closeAllDocuments","call","destroy","ignore"],"mappings":"2TAGMA,EAAiB,uECMV,MAAAC,EAAmBC,qBAAiD,GCD1E,SAASC,IACR,MAAAC,EAAeC,aAAWJ,GAEhC,QAAqB,IAAjBG,EACI,MAAA,IAAIE,MAAM,4DAGX,OAAAF,CACT,2BCEO,UAA2BG,SAAEA,EAAAC,OAAUA,EAAQC,UAAAA,EAAAC,MAAWA,IAC/D,MAAMN,EAAe,CACnBI,SACAC,YACAC,sBAGMT,EAAiBU,SAAjB,CAA0BC,MAAOR,EAAeG,YAC1D,oBDJO,WACL,MAAMC,OAAEA,EAAAE,MAAQA,GAAUP,IAE1B,GAAIO,EACI,MAAAA,EAGD,OAAAF,CACT,qDFnBO,SAAyBK,GACxB,MAAAC,QAAEA,EAAUd,EAAgBe,OAAAA,GAAS,SAAMC,GAAWH,GAAU,CAAC,GAEhEL,EAAQS,GAAaC,EAAAA,SAA2B,OAChDC,EAASC,GAAcF,EAAAA,UAAS,IAChCR,EAAOW,GAAYH,EAAAA,SAAuB,MAC3CI,EAAYC,SAAyB,MAwC3C,OAtCAC,EAAAA,WAAU,KACR,IAAIC,GAAY,EA4BhB,MA1BA,WACM,IACI,MAAAC,mBAAEA,GAAuBX,QACrBY,OAAO,gDACPA,OAAO,0CAEXC,QAAkBF,EAAmBZ,EAASE,GACpDM,EAAUO,QAAUD,EACpBA,EAAUE,aAAaC,MACrB,KACEd,EAAUW,GACVR,GAAW,EAAK,IAEjBY,IACCX,EAAS,IAAIf,MAAM0B,EAAEC,OAAOC,UAC5Bd,GAAW,EAAK,UAGbY,GACFP,IACHJ,EAASW,GACTZ,GAAW,GACb,CAED,EAxBH,GA0BO,aACOK,GAAA,EACZ,OAAAU,EAAA,OAAAC,EAAAd,EAAUO,cAAV,EAAAO,EAAmBC,oBAAnBF,EAAAG,KAAAF,GAAyCL,MAAK,aAC5C,OAAAI,EAAA,OAAAC,EAAAd,EAAUO,gBAAVO,EAAmBG,UAAnBJ,EAAAG,KAAAF,GACAd,EAAUO,QAAU,IAAA,GACnBW,UACL,GACC,CAAC1B,EAASC,EAAQC,IAEd,CAAER,SAAQC,UAAWU,EAAST,QACvC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-pdfium-engine.ts","../../src/shared/context/pdf-engine-context.ts","../../src/shared/hooks/use-engine-context.ts","../../src/shared/components/pdf-engine-provider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { ignore, Logger, PdfEngine } from '@embedpdf/models';\n\nconst defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm`;\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger } = config ?? {};\n\n const [engine, setEngine] = useState<PdfEngine | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const engineRef = useRef<PdfEngine | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, logger);\n engineRef.current = pdfEngine;\n pdfEngine.initialize().wait(\n () => {\n setEngine(pdfEngine);\n setLoading(false);\n },\n (e) => {\n setError(new Error(e.reason.message));\n setLoading(false);\n },\n );\n } catch (e) {\n if (!cancelled) {\n setError(e as Error);\n setLoading(false);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef.current?.closeAllDocuments?.().wait(() => {\n engineRef.current?.destroy?.();\n engineRef.current = null;\n }, ignore);\n };\n }, [wasmUrl, worker, logger]);\n\n return { engine, isLoading: loading, error };\n}\n","import { createContext } from '@framework';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport const PdfEngineContext = createContext<PdfEngineContextState | undefined>(undefined);\n","import { useContext } from '@framework';\nimport { PdfEngineContext, PdfEngineContextState } from '../context';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = useContext(PdfEngineContext);\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ReactNode } from '@framework';\nimport { PdfEngineContext } from '../context';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineProviderProps {\n children: ReactNode;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/**\n * Provider component that makes a PDF engine instance available\n * to all child components via context.\n *\n * This provider is completely engine-agnostic - it accepts any engine\n * and its loading state from the parent component.\n */\nexport function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps) {\n const contextValue = {\n engine,\n isLoading,\n error,\n };\n\n return <PdfEngineContext.Provider value={contextValue}>{children}</PdfEngineContext.Provider>;\n}\n"],"names":["defaultWasmUrl","PdfEngineContext","createContext","useEngineContext","contextValue","useContext","Error","children","engine","isLoading","error","Provider","value","config","wasmUrl","worker","logger","setEngine","useState","loading","setLoading","setError","engineRef","useRef","useEffect","cancelled","createPdfiumEngine","import","pdfEngine","current","initialize","wait","e","reason","message","_b","_a","closeAllDocuments","call","destroy","ignore"],"mappings":"2TAGMA,EAAiB,8ECMhB,MAAMC,EAAmBC,EAAAA,mBAAiD,GCD1E,SAASC,IACd,MAAMC,EAAeC,EAAAA,WAAWJ,GAEhC,QAAqB,IAAjBG,EACF,MAAM,IAAIE,MAAM,4DAGlB,OAAOF,CACT,2BCEO,UAA2BG,SAAEA,EAAAC,OAAUA,EAAAC,UAAQA,EAAAC,MAAWA,IAC/D,MAAMN,EAAe,CACnBI,SACAC,YACAC,SAGF,aAAQT,EAAiBU,SAAjB,CAA0BC,MAAOR,EAAeG,YAC1D,oBDJO,WACL,MAAMC,OAAEA,EAAAE,MAAQA,GAAUP,IAE1B,GAAIO,EACF,MAAMA,EAGR,OAAOF,CACT,qDFnBO,SAAyBK,GAC9B,MAAMC,QAAEA,EAAUd,EAAAe,OAAgBA,GAAS,SAAMC,GAAWH,GAAU,CAAA,GAE/DL,EAAQS,GAAaC,EAAAA,SAA2B,OAChDC,EAASC,GAAcF,EAAAA,UAAS,IAChCR,EAAOW,GAAYH,EAAAA,SAAuB,MAC3CI,EAAYC,EAAAA,OAAyB,MAwC3C,OAtCAC,EAAAA,UAAU,KACR,IAAIC,GAAY,EA4BhB,MA1BA,WACE,IACE,MAAMC,mBAAEA,GAAuBX,QACrBY,OAAO,gDACPA,OAAO,0CAEXC,QAAkBF,EAAmBZ,EAASE,GACpDM,EAAUO,QAAUD,EACpBA,EAAUE,aAAaC,KACrB,KACEd,EAAUW,GACVR,GAAW,IAEZY,IACCX,EAAS,IAAIf,MAAM0B,EAAEC,OAAOC,UAC5Bd,GAAW,IAGjB,OAASY,GACFP,IACHJ,EAASW,GACTZ,GAAW,GAEf,CACF,EAxBA,GA0BO,aACLK,GAAY,EACZ,OAAAU,EAAA,OAAAC,EAAAd,EAAUO,cAAV,EAAAO,EAAmBC,oBAAnBF,EAAAG,KAAAF,GAAyCL,KAAK,aAC5C,OAAAI,EAAA,OAAAC,EAAAd,EAAUO,gBAAVO,EAAmBG,UAAnBJ,EAAAG,KAAAF,GACAd,EAAUO,QAAU,MACnBW,EAAAA,UAEJ,CAAC1B,EAASC,EAAQC,IAEd,CAAER,SAAQC,UAAWU,EAAST,QACvC"}
@@ -1,7 +1,7 @@
1
1
  import { useState, useRef, useEffect, createContext, useContext } from "react";
2
2
  import { ignore } from "@embedpdf/models";
3
3
  import { jsx } from "react/jsx-runtime";
4
- const defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@1.4.1/dist/pdfium.wasm`;
4
+ const defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.0-next.0/dist/pdfium.wasm`;
5
5
  function usePdfiumEngine(config) {
6
6
  const { wasmUrl = defaultWasmUrl, worker = true, logger } = config ?? {};
7
7
  const [engine, setEngine] = useState(null);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-pdfium-engine.ts","../../src/shared/context/pdf-engine-context.ts","../../src/shared/hooks/use-engine-context.ts","../../src/shared/components/pdf-engine-provider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { ignore, Logger, PdfEngine } from '@embedpdf/models';\n\nconst defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm`;\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger } = config ?? {};\n\n const [engine, setEngine] = useState<PdfEngine | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const engineRef = useRef<PdfEngine | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, logger);\n engineRef.current = pdfEngine;\n pdfEngine.initialize().wait(\n () => {\n setEngine(pdfEngine);\n setLoading(false);\n },\n (e) => {\n setError(new Error(e.reason.message));\n setLoading(false);\n },\n );\n } catch (e) {\n if (!cancelled) {\n setError(e as Error);\n setLoading(false);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef.current?.closeAllDocuments?.().wait(() => {\n engineRef.current?.destroy?.();\n engineRef.current = null;\n }, ignore);\n };\n }, [wasmUrl, worker, logger]);\n\n return { engine, isLoading: loading, error };\n}\n","import { createContext } from '@framework';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport const PdfEngineContext = createContext<PdfEngineContextState | undefined>(undefined);\n","import { useContext } from '@framework';\nimport { PdfEngineContext, PdfEngineContextState } from '../context';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = useContext(PdfEngineContext);\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ReactNode } from '@framework';\nimport { PdfEngineContext } from '../context';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineProviderProps {\n children: ReactNode;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/**\n * Provider component that makes a PDF engine instance available\n * to all child components via context.\n *\n * This provider is completely engine-agnostic - it accepts any engine\n * and its loading state from the parent component.\n */\nexport function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps) {\n const contextValue = {\n engine,\n isLoading,\n error,\n };\n\n return <PdfEngineContext.Provider value={contextValue}>{children}</PdfEngineContext.Provider>;\n}\n"],"names":["_b","_a"],"mappings":";;;AAGA,MAAM,iBAAiB;AAQhB,SAAS,gBAAgB,QAA+B;AACvD,QAAA,EAAE,UAAU,gBAAgB,SAAS,MAAM,OAAO,IAAI,UAAU,CAAC;AAEvE,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA2B,IAAI;AAC3D,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI;AAC3C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAuB,IAAI;AAC/C,QAAA,YAAY,OAAyB,IAAI;AAE/C,YAAU,MAAM;AACd,QAAI,YAAY;AAEhB,KAAC,YAAY;AACP,UAAA;AACI,cAAA,EAAE,mBAAmB,IAAI,SAC3B,MAAM,OAAO,wCAAwC,IACrD,MAAM,OAAO,wCAAwC;AAEzD,cAAM,YAAY,MAAM,mBAAmB,SAAS,MAAM;AAC1D,kBAAU,UAAU;AACpB,kBAAU,aAAa;AAAA,UACrB,MAAM;AACJ,sBAAU,SAAS;AACnB,uBAAW,KAAK;AAAA,UAClB;AAAA,UACA,CAAC,MAAM;AACL,qBAAS,IAAI,MAAM,EAAE,OAAO,OAAO,CAAC;AACpC,uBAAW,KAAK;AAAA,UAAA;AAAA,QAEpB;AAAA,eACO,GAAG;AACV,YAAI,CAAC,WAAW;AACd,mBAAS,CAAU;AACnB,qBAAW,KAAK;AAAA,QAAA;AAAA,MAClB;AAAA,IACF,GACC;AAEH,WAAO,MAAM;;AACC,kBAAA;AACZ,4BAAU,YAAV,mBAAmB,sBAAnB,4BAAyC,KAAK,MAAM;;AAClD,SAAAA,OAAAC,MAAA,UAAU,YAAV,gBAAAA,IAAmB,YAAnB,gBAAAD,IAAA,KAAAC;AACA,kBAAU,UAAU;AAAA,SACnB;AAAA,IACL;AAAA,EACC,GAAA,CAAC,SAAS,QAAQ,MAAM,CAAC;AAE5B,SAAO,EAAE,QAAQ,WAAW,SAAS,MAAM;AAC7C;ACjDa,MAAA,mBAAmB,cAAiD,MAAS;ACDnF,SAAS,mBAA0C;AAClD,QAAA,eAAe,WAAW,gBAAgB;AAEhD,MAAI,iBAAiB,QAAW;AACxB,UAAA,IAAI,MAAM,0DAA0D;AAAA,EAAA;AAGrE,SAAA;AACT;AAMO,SAAS,YAAY;AAC1B,QAAM,EAAE,QAAQ,MAAM,IAAI,iBAAiB;AAE3C,MAAI,OAAO;AACH,UAAA;AAAA,EAAA;AAGD,SAAA;AACT;ACZO,SAAS,kBAAkB,EAAE,UAAU,QAAQ,WAAW,SAAiC;AAChG,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,6BAAQ,iBAAiB,UAAjB,EAA0B,OAAO,cAAe,UAAS;AACnE;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-pdfium-engine.ts","../../src/shared/context/pdf-engine-context.ts","../../src/shared/hooks/use-engine-context.ts","../../src/shared/components/pdf-engine-provider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { ignore, Logger, PdfEngine } from '@embedpdf/models';\n\nconst defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm`;\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger } = config ?? {};\n\n const [engine, setEngine] = useState<PdfEngine | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const engineRef = useRef<PdfEngine | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, logger);\n engineRef.current = pdfEngine;\n pdfEngine.initialize().wait(\n () => {\n setEngine(pdfEngine);\n setLoading(false);\n },\n (e) => {\n setError(new Error(e.reason.message));\n setLoading(false);\n },\n );\n } catch (e) {\n if (!cancelled) {\n setError(e as Error);\n setLoading(false);\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef.current?.closeAllDocuments?.().wait(() => {\n engineRef.current?.destroy?.();\n engineRef.current = null;\n }, ignore);\n };\n }, [wasmUrl, worker, logger]);\n\n return { engine, isLoading: loading, error };\n}\n","import { createContext } from '@framework';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nexport const PdfEngineContext = createContext<PdfEngineContextState | undefined>(undefined);\n","import { useContext } from '@framework';\nimport { PdfEngineContext, PdfEngineContextState } from '../context';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = useContext(PdfEngineContext);\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ReactNode } from '@framework';\nimport { PdfEngineContext } from '../context';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineProviderProps {\n children: ReactNode;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n/**\n * Provider component that makes a PDF engine instance available\n * to all child components via context.\n *\n * This provider is completely engine-agnostic - it accepts any engine\n * and its loading state from the parent component.\n */\nexport function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps) {\n const contextValue = {\n engine,\n isLoading,\n error,\n };\n\n return <PdfEngineContext.Provider value={contextValue}>{children}</PdfEngineContext.Provider>;\n}\n"],"names":["_b","_a"],"mappings":";;;AAGA,MAAM,iBAAiB;AAQhB,SAAS,gBAAgB,QAA+B;AAC7D,QAAM,EAAE,UAAU,gBAAgB,SAAS,MAAM,OAAA,IAAW,UAAU,CAAA;AAEtE,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA2B,IAAI;AAC3D,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI;AAC3C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAuB,IAAI;AACrD,QAAM,YAAY,OAAyB,IAAI;AAE/C,YAAU,MAAM;AACd,QAAI,YAAY;AAEhB,KAAC,YAAY;AACX,UAAI;AACF,cAAM,EAAE,mBAAA,IAAuB,SAC3B,MAAM,OAAO,wCAAwC,IACrD,MAAM,OAAO,wCAAwC;AAEzD,cAAM,YAAY,MAAM,mBAAmB,SAAS,MAAM;AAC1D,kBAAU,UAAU;AACpB,kBAAU,aAAa;AAAA,UACrB,MAAM;AACJ,sBAAU,SAAS;AACnB,uBAAW,KAAK;AAAA,UAClB;AAAA,UACA,CAAC,MAAM;AACL,qBAAS,IAAI,MAAM,EAAE,OAAO,OAAO,CAAC;AACpC,uBAAW,KAAK;AAAA,UAClB;AAAA,QAAA;AAAA,MAEJ,SAAS,GAAG;AACV,YAAI,CAAC,WAAW;AACd,mBAAS,CAAU;AACnB,qBAAW,KAAK;AAAA,QAClB;AAAA,MACF;AAAA,IACF,GAAA;AAEA,WAAO,MAAM;;AACX,kBAAY;AACZ,4BAAU,YAAV,mBAAmB,sBAAnB,4BAAyC,KAAK,MAAM;;AAClD,SAAAA,OAAAC,MAAA,UAAU,YAAV,gBAAAA,IAAmB,YAAnB,gBAAAD,IAAA,KAAAC;AACA,kBAAU,UAAU;AAAA,MACtB,GAAG;AAAA,IACL;AAAA,EACF,GAAG,CAAC,SAAS,QAAQ,MAAM,CAAC;AAE5B,SAAO,EAAE,QAAQ,WAAW,SAAS,MAAA;AACvC;ACjDO,MAAM,mBAAmB,cAAiD,MAAS;ACDnF,SAAS,mBAA0C;AACxD,QAAM,eAAe,WAAW,gBAAgB;AAEhD,MAAI,iBAAiB,QAAW;AAC9B,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC5E;AAEA,SAAO;AACT;AAMO,SAAS,YAAY;AAC1B,QAAM,EAAE,QAAQ,MAAA,IAAU,iBAAA;AAE1B,MAAI,OAAO;AACT,UAAM;AAAA,EACR;AAEA,SAAO;AACT;ACZO,SAAS,kBAAkB,EAAE,UAAU,QAAQ,WAAW,SAAiC;AAChG,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGF,6BAAQ,iBAAiB,UAAjB,EAA0B,OAAO,cAAe,UAAS;AACnE;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),n=require("svelte"),t=require("@embedpdf/models"),r=require("@embedpdf/engines");function i(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const t in e)if("default"!==t){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>e[t]})}return n.default=e,Object.freeze(n)}require("svelte/internal/disclose-version");const o=i(e),s=Symbol("pdfEngineContext");function u(){const e=n.getContext(s);if(void 0===e)throw new Error("getPdfEngineContext must be used within a PdfEngineProvider");return e}exports.PdfEngineProvider=function(e,t){o.push(t,!0),o.user_effect((()=>{var e;e={engine:t.engine,isLoading:t.isLoading,error:t.error},n.setContext(s,e)}));var r=o.comment(),i=o.first_child(r);o.snippet(i,(()=>t.children)),o.append(e,r),o.pop()},exports.useEngine=function(){const{engine:e,error:n}=u();if(n)throw n;return e},exports.useEngineContext=function(){const e=u();if(void 0===e)throw new Error("useEngineContext must be used within a PdfEngineProvider");return e},exports.usePdfiumEngine=function(e){const{wasmUrl:n=r.DEFAULT_PDFIUM_WASM_URL,worker:i=!0,logger:s}=e??{},u=o.proxy({engine:null,isLoading:!0,error:null});let l=o.state(null);return"undefined"!=typeof window&&o.user_effect((()=>{let e=!1;return(async()=>{try{const{createPdfiumEngine:e}=i?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),t=await e(n,s);o.set(l,t,!0),t.initialize().wait((()=>{u.engine=t,u.isLoading=!1}),(e=>{u.error=new Error(e.reason.message),u.isLoading=!1}))}catch(t){e||(u.error=t,u.isLoading=!1)}})(),()=>{var n,r;e=!0,null==(r=null==(n=o.get(l))?void 0:n.closeAllDocuments)||r.call(n).wait((()=>{var e,n;null==(n=null==(e=o.get(l))?void 0:e.destroy)||n.call(e),o.set(l,null)}),t.ignore)}})),u};
1
+ "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),n=require("svelte"),t=require("@embedpdf/models"),r=require("@embedpdf/engines");function i(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const t in e)if("default"!==t){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>e[t]})}return n.default=e,Object.freeze(n)}require("svelte/internal/disclose-version");const o=i(e),s=Symbol("pdfEngineContext");function u(){const e=n.getContext(s);if(void 0===e)throw new Error("getPdfEngineContext must be used within a PdfEngineProvider");return e}exports.PdfEngineProvider=function(e,t){o.push(t,!0),o.user_effect(()=>{var e;e={engine:t.engine,isLoading:t.isLoading,error:t.error},n.setContext(s,e)});var r=o.comment(),i=o.first_child(r);o.snippet(i,()=>t.children),o.append(e,r),o.pop()},exports.useEngine=function(){const{engine:e,error:n}=u();if(n)throw n;return e},exports.useEngineContext=function(){const e=u();if(void 0===e)throw new Error("useEngineContext must be used within a PdfEngineProvider");return e},exports.usePdfiumEngine=function(e){const{wasmUrl:n=r.DEFAULT_PDFIUM_WASM_URL,worker:i=!0,logger:s}=e??{},u=o.proxy({engine:null,isLoading:!0,error:null});let l=o.state(null);return"undefined"!=typeof window&&o.user_effect(()=>{let e=!1;return(async()=>{try{const{createPdfiumEngine:e}=i?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),t=await e(n,s);o.set(l,t,!0),t.initialize().wait(()=>{u.engine=t,u.isLoading=!1},e=>{u.error=new Error(e.reason.message),u.isLoading=!1})}catch(t){e||(u.error=t,u.isLoading=!1)}})(),()=>{var n,r;e=!0,null==(r=null==(n=o.get(l))?void 0:n.closeAllDocuments)||r.call(n).wait(()=>{var e,n;null==(n=null==(e=o.get(l))?void 0:e.destroy)||n.call(e),o.set(l,null)},t.ignore)}}),u};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/svelte/context/pdf-engine-context.svelte.ts","../../src/svelte/components/PdfEngineProvider.svelte","../../src/svelte/hooks/use-engine-context.ts","../../src/svelte/hooks/use-pdfium-engine.svelte.ts"],"sourcesContent":["import { getContext, setContext } from 'svelte';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n\nconst PDF_ENGINE_CONTEXT_KEY = Symbol('pdfEngineContext');\n\n/**\n * Set the PDF engine context (used by PdfEngineProvider)\n */\nexport function setPdfEngineContext(value: PdfEngineContextState) {\n setContext(PDF_ENGINE_CONTEXT_KEY, value);\n}\n\n/**\n * Get the PDF engine context\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function getPdfEngineContext(): PdfEngineContextState {\n const context = getContext<PdfEngineContextState | undefined>(PDF_ENGINE_CONTEXT_KEY);\n \n if (context === undefined) {\n throw new Error('getPdfEngineContext must be used within a PdfEngineProvider');\n }\n \n return context;\n}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import type { PdfEngine } from '@embedpdf/models';\n import { setPdfEngineContext } from '../context';\n\n interface Props {\n children: Snippet;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n }\n\n let { children, engine, isLoading, error }: Props = $props();\n\n // Update context reactively whenever props change\n $effect(() => {\n setPdfEngineContext({\n engine,\n isLoading,\n error,\n });\n });\n</script>\n\n{@render children()}\n","import { getPdfEngineContext, type PdfEngineContextState } from '../context/pdf-engine-context.svelte';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = getPdfEngineContext();\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = getPdfEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n\n","import { ignore, Logger, PdfEngine } from '@embedpdf/models';\nimport { DEFAULT_PDFIUM_WASM_URL } from '@embedpdf/engines';\n\nexport interface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = DEFAULT_PDFIUM_WASM_URL, worker = true, logger } = config ?? {};\n\n // Create a reactive state object\n const state = $state({\n engine: null as PdfEngine | null,\n isLoading: true,\n error: null as Error | null,\n });\n\n let engineRef = $state<PdfEngine | null>(null);\n\n const isBrowser = typeof window !== 'undefined';\n\n if (isBrowser) {\n $effect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, logger);\n engineRef = pdfEngine;\n\n pdfEngine.initialize().wait(\n () => {\n state.engine = pdfEngine;\n state.isLoading = false;\n },\n (e) => {\n state.error = new Error(e.reason.message);\n state.isLoading = false;\n },\n );\n } catch (e) {\n if (!cancelled) {\n state.error = e as Error;\n state.isLoading = false;\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef?.closeAllDocuments?.().wait(() => {\n engineRef?.destroy?.();\n engineRef = null;\n }, ignore);\n };\n });\n }\n\n // Return the reactive state object directly\n return state;\n}\n"],"names":["PDF_ENGINE_CONTEXT_KEY","Symbol","getPdfEngineContext","context","getContext","Error","$","user_effect","value","engine","$$props","isLoading","error","svelte","setContext","contextValue","config","wasmUrl","DEFAULT_PDFIUM_WASM_URL","worker","logger","state","engineRef","window","cancelled","createPdfiumEngine","pdfEngine","$__namespace","set","initialize","wait","e","reason","message","closeAllDocuments","_b","call","_a","get","destroy","ignore"],"mappings":"oqBAUMA,EAAyBC,OAAO,oBAatB,SAAAC,IACR,MAAAC,EAAUC,aAA8CJ,eAE1DG,EACQ,MAAA,IAAAE,MAAM,+DAGX,OAAAF,CACT,sDChBEG,EAAAC,aAAc,SDAoBC,ICCb,CACjBC,OAAMC,EAAAD,OACNE,UAASD,EAAAC,UACTC,MAAKF,EAAAE,ODHTC,EAAAC,WAAWd,EAAwBQ,8FCMrC,oBCDO,WACL,MAAMC,OAAEA,EAAAG,MAAQA,GAAUV,IAE1B,GAAIU,EACI,MAAAA,EAGD,OAAAH,CACT,2BAtBO,WACL,MAAMM,EAAeb,IAErB,QAAqB,IAAjBa,EACI,MAAA,IAAIV,MAAM,4DAGX,OAAAU,CACT,mCCNgCC,iBACtBC,EAAUC,iCAAyBC,GAAS,EAAMC,OAAAA,GAAWJ,MAG/DK,WACJZ,OAAQ,KACRE,WAAW,EACXC,MAAO,OAGL,IAAAU,UAAqC,MA8ClC,MA5C6B,oBAAXC,QAGvBjB,EAAAC,kBACM,IAAAiB,GAAY,mBAGV,IACM,MAAAC,mBAAAA,GAAuBN,eACd,uDACA,0CAEXO,QAAkBD,EAAmBR,EAASG,GACxCO,EAAAC,IAAAN,EAAAI,GAAA,GAEZA,EAAUG,aAAaC,WAEnBT,EAAMZ,OAASiB,EACfL,EAAMV,WAAY,CAAA,IAEnBoB,IACCV,EAAMT,MAAY,IAAAP,MAAM0B,EAAEC,OAAOC,SACjCZ,EAAMV,WAAY,CAAA,UAGfoB,GACFP,IACHH,EAAMT,MAAQmB,EACdV,EAAMV,WAAY,GAGrB,kBAGWa,GAAA,0BACDF,aAAAY,oBAAsBC,EAAAC,KAAAC,GAAAP,mBAC/BxB,OAAAA,EAAAA,OAAAA,EAAAA,EAAAgC,IAAAhB,SAAAhB,EAAAA,EAAWiC,UAAXjC,EAAAA,KAAAA,GACYqB,EAAAC,IAAAN,EAAA,KAAA,GACXkB,EAAAA,OAAAA,CACL,IAKGnB,CACT"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/svelte/context/pdf-engine-context.svelte.ts","../../src/svelte/components/PdfEngineProvider.svelte","../../src/svelte/hooks/use-engine-context.ts","../../src/svelte/hooks/use-pdfium-engine.svelte.ts"],"sourcesContent":["import { getContext, setContext } from 'svelte';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nconst PDF_ENGINE_CONTEXT_KEY = Symbol('pdfEngineContext');\n\n/**\n * Set the PDF engine context (used by PdfEngineProvider)\n */\nexport function setPdfEngineContext(value: PdfEngineContextState) {\n setContext(PDF_ENGINE_CONTEXT_KEY, value);\n}\n\n/**\n * Get the PDF engine context\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function getPdfEngineContext(): PdfEngineContextState {\n const context = getContext<PdfEngineContextState | undefined>(PDF_ENGINE_CONTEXT_KEY);\n\n if (context === undefined) {\n throw new Error('getPdfEngineContext must be used within a PdfEngineProvider');\n }\n\n return context;\n}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import type { PdfEngine } from '@embedpdf/models';\n import { setPdfEngineContext } from '../context';\n\n interface Props {\n children: Snippet;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n }\n\n let { children, engine, isLoading, error }: Props = $props();\n\n // Update context reactively whenever props change\n $effect(() => {\n setPdfEngineContext({\n engine,\n isLoading,\n error,\n });\n });\n</script>\n\n{@render children()}\n","import {\n getPdfEngineContext,\n type PdfEngineContextState,\n} from '../context/pdf-engine-context.svelte';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = getPdfEngineContext();\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = getPdfEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ignore, Logger, PdfEngine } from '@embedpdf/models';\nimport { DEFAULT_PDFIUM_WASM_URL } from '@embedpdf/engines';\n\nexport interface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = DEFAULT_PDFIUM_WASM_URL, worker = true, logger } = config ?? {};\n\n // Create a reactive state object\n const state = $state({\n engine: null as PdfEngine | null,\n isLoading: true,\n error: null as Error | null,\n });\n\n let engineRef = $state<PdfEngine | null>(null);\n\n const isBrowser = typeof window !== 'undefined';\n\n if (isBrowser) {\n $effect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, logger);\n engineRef = pdfEngine;\n\n pdfEngine.initialize().wait(\n () => {\n state.engine = pdfEngine;\n state.isLoading = false;\n },\n (e) => {\n state.error = new Error(e.reason.message);\n state.isLoading = false;\n },\n );\n } catch (e) {\n if (!cancelled) {\n state.error = e as Error;\n state.isLoading = false;\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef?.closeAllDocuments?.().wait(() => {\n engineRef?.destroy?.();\n engineRef = null;\n }, ignore);\n };\n });\n }\n\n // Return the reactive state object directly\n return state;\n}\n"],"names":["PDF_ENGINE_CONTEXT_KEY","Symbol","getPdfEngineContext","context","getContext","Error","$","user_effect","value","engine","$$props","isLoading","error","setContext","contextValue","config","wasmUrl","DEFAULT_PDFIUM_WASM_URL","worker","logger","state","engineRef","window","cancelled","createPdfiumEngine","pdfEngine","set","initialize","wait","e","reason","message","closeAllDocuments","get","destroy","ignore"],"mappings":"oqBASMA,EAAyBC,OAAO,oBAatB,SAAAC,UACRC,EAAUC,EAAAA,WAA8CJ,eAE1DG,EACQ,MAAA,IAAAE,MAAM,sEAGXF,CACT,sDCfEG,EAAAC,YAAO,SDD2BC,ICEb,CACjBC,OAAMC,EAAAD,OACNE,UAASD,EAAAC,UACTC,MAAKF,EAAAE,ODJTC,EAAAA,WAAWb,EAAwBQ,2FCOrC,oBCEO,WACL,MAAMC,OAAEA,EAAAG,MAAQA,GAAUV,IAE1B,GAAIU,EACF,MAAMA,EAGR,OAAOH,CACT,2BAtBO,WACL,MAAMK,EAAeZ,IAErB,QAAqB,IAAjBY,EACF,MAAM,IAAIT,MAAM,4DAGlB,OAAOS,CACT,mCCTgCC,iBACtBC,EAAUC,iCAAyBC,GAAS,EAAAC,OAAMA,GAAWJ,MAG/DK,WACJX,OAAQ,KACRE,WAAW,EACXC,MAAO,OAGL,IAAAS,UAAqC,YAEL,oBAAXC,QAGvBhB,EAAAC,iBACM,IAAAgB,GAAY,uBAIJ,MAAAC,mBAAAA,GAAuBN,eACd,uDACA,0CAEXO,QAAkBD,EAAmBR,EAASG,GACpDb,EAAAoB,IAAAL,EAAYI,GAAA,GAEZA,EAAUE,aAAaC,UAEnBR,EAAMX,OAASgB,EACfL,EAAMT,WAAY,GAEnBkB,IACCT,EAAMR,MAAA,IAAYP,MAAMwB,EAAEC,OAAOC,SACjCX,EAAMT,WAAY,GAGxB,OAASkB,GACFN,IACHH,EAAMR,MAAQiB,EACdT,EAAMT,WAAY,EAEtB,CACF,kBAGEY,GAAY,0BACZF,aAAWW,8BAAsBJ,kBAC/BtB,OAAAA,EAAAA,OAAAA,EAAAA,EAAA2B,IAAAZ,SAAAf,EAAAA,EAAW4B,UAAX5B,EAAAA,KAAAA,GACAA,EAAAoB,IAAAL,EAAY,OACXc,EAAAA,WAMFf,CACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/svelte/context/pdf-engine-context.svelte.ts","../../src/svelte/hooks/use-engine-context.ts","../../src/svelte/hooks/use-pdfium-engine.svelte.ts","../../src/svelte/components/PdfEngineProvider.svelte"],"sourcesContent":["import { getContext, setContext } from 'svelte';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n\nconst PDF_ENGINE_CONTEXT_KEY = Symbol('pdfEngineContext');\n\n/**\n * Set the PDF engine context (used by PdfEngineProvider)\n */\nexport function setPdfEngineContext(value: PdfEngineContextState) {\n setContext(PDF_ENGINE_CONTEXT_KEY, value);\n}\n\n/**\n * Get the PDF engine context\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function getPdfEngineContext(): PdfEngineContextState {\n const context = getContext<PdfEngineContextState | undefined>(PDF_ENGINE_CONTEXT_KEY);\n \n if (context === undefined) {\n throw new Error('getPdfEngineContext must be used within a PdfEngineProvider');\n }\n \n return context;\n}\n","import { getPdfEngineContext, type PdfEngineContextState } from '../context/pdf-engine-context.svelte';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = getPdfEngineContext();\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = getPdfEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n\n","import { ignore, Logger, PdfEngine } from '@embedpdf/models';\nimport { DEFAULT_PDFIUM_WASM_URL } from '@embedpdf/engines';\n\nexport interface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = DEFAULT_PDFIUM_WASM_URL, worker = true, logger } = config ?? {};\n\n // Create a reactive state object\n const state = $state({\n engine: null as PdfEngine | null,\n isLoading: true,\n error: null as Error | null,\n });\n\n let engineRef = $state<PdfEngine | null>(null);\n\n const isBrowser = typeof window !== 'undefined';\n\n if (isBrowser) {\n $effect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, logger);\n engineRef = pdfEngine;\n\n pdfEngine.initialize().wait(\n () => {\n state.engine = pdfEngine;\n state.isLoading = false;\n },\n (e) => {\n state.error = new Error(e.reason.message);\n state.isLoading = false;\n },\n );\n } catch (e) {\n if (!cancelled) {\n state.error = e as Error;\n state.isLoading = false;\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef?.closeAllDocuments?.().wait(() => {\n engineRef?.destroy?.();\n engineRef = null;\n }, ignore);\n };\n });\n }\n\n // Return the reactive state object directly\n return state;\n}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import type { PdfEngine } from '@embedpdf/models';\n import { setPdfEngineContext } from '../context';\n\n interface Props {\n children: Snippet;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n }\n\n let { children, engine, isLoading, error }: Props = $props();\n\n // Update context reactively whenever props change\n $effect(() => {\n setPdfEngineContext({\n engine,\n isLoading,\n error,\n });\n });\n</script>\n\n{@render children()}\n"],"names":["_b","_a"],"mappings":";;;;;MAUM,yBAAyB,OAAO,kBAAkB;SAKxC,oBAAoB,OAA8B;AAChE,aAAW,wBAAwB,KAAK;AAC1C;AAMgB,SAAA,sBAA6C;QACrD,UAAU,WAA8C,sBAAsB;MAEhF,oBAAuB;AACf,UAAA,IAAA,MAAM,6DAA6D;AAAA;SAGxE;AACT;ACxBO,SAAS,mBAA0C;AACxD,QAAM,eAAe,oBAAoB;AAEzC,MAAI,iBAAiB,QAAW;AACxB,UAAA,IAAI,MAAM,0DAA0D;AAAA,EAAA;AAGrE,SAAA;AACT;AAMO,SAAS,YAAY;AAC1B,QAAM,EAAE,QAAQ,MAAM,IAAI,oBAAoB;AAE9C,MAAI,OAAO;AACH,UAAA;AAAA,EAAA;AAGD,SAAA;AACT;SCpBgB,gBAAgB,QAA+B;UACrD,UAAU,yBAAyB,SAAS,MAAM,OAAO,IAAI;QAG/D,kBACJ,QAAQ,MACR,WAAW,MACX,OAAO,MAAA;AAGL,MAAA,oBAAqC,IAAI;QAEvC,YAAA,OAAmB,WAAW;AAEhC,MAAA,WAAW;AACb,MAAA,kBAAc;AACR,UAAA,YAAY;mBAEH;YACP;AACM,gBAAA,EAAA,mBAAmB,IAAI,sBACd,wCAAwC,iBACxC,wCAAwC;AAEnD,gBAAA,YAAkB,MAAA,mBAAmB,SAAS,MAAM;AAC9C,YAAA,IAAA,WAAA,WAAA,IAAA;AAEZ,oBAAU,aAAa;AAAA,kBACf;AACJ,oBAAM,SAAS;AACf,oBAAM,YAAY;AAAA,YACpB;AAAA,YACC,CAAA,MAAM;AACL,oBAAM,QAAY,IAAA,MAAM,EAAE,OAAO,OAAO;AACxC,oBAAM,YAAY;AAAA;;iBAGf,GAAG;AACL,cAAA,CAAA,WAAW;AACd,kBAAM,QAAQ;AACd,kBAAM,YAAY;AAAA;;SAGrB;mBAEU;;AACC,oBAAA;0BACD,SAAA,yBAAA,kDAAsB;AAAA,gBAAW;;AAC1C,aAAAA,OAAAC,MAAA,EAAA,IAAA,SAAA,MAAA,gBAAAA,IAAW,YAAX,gBAAAD,IAAA,KAAAC;AACY,cAAA,IAAA,WAAA,IAAA;AAAA;UACX;AAAA;AAAA,MACL;AAAA,KACD;AAAA;SAII;AACT;8CClEA;;AAeE,IAAA,YAAc,MAAA;AACZ,wBAAmB;AAAA,MACjB,QAAM,QAAA;AAAA,MACN,WAAS,QAAA;AAAA,MACT,OAAK,QAAA;AAAA;GAER;;;;;;AACH;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/svelte/context/pdf-engine-context.svelte.ts","../../src/svelte/hooks/use-engine-context.ts","../../src/svelte/hooks/use-pdfium-engine.svelte.ts","../../src/svelte/components/PdfEngineProvider.svelte"],"sourcesContent":["import { getContext, setContext } from 'svelte';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nconst PDF_ENGINE_CONTEXT_KEY = Symbol('pdfEngineContext');\n\n/**\n * Set the PDF engine context (used by PdfEngineProvider)\n */\nexport function setPdfEngineContext(value: PdfEngineContextState) {\n setContext(PDF_ENGINE_CONTEXT_KEY, value);\n}\n\n/**\n * Get the PDF engine context\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function getPdfEngineContext(): PdfEngineContextState {\n const context = getContext<PdfEngineContextState | undefined>(PDF_ENGINE_CONTEXT_KEY);\n\n if (context === undefined) {\n throw new Error('getPdfEngineContext must be used within a PdfEngineProvider');\n }\n\n return context;\n}\n","import {\n getPdfEngineContext,\n type PdfEngineContextState,\n} from '../context/pdf-engine-context.svelte';\n\n/**\n * Hook to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = getPdfEngineContext();\n\n if (contextValue === undefined) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Hook to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = getPdfEngineContext();\n\n if (error) {\n throw error;\n }\n\n return engine;\n}\n","import { ignore, Logger, PdfEngine } from '@embedpdf/models';\nimport { DEFAULT_PDFIUM_WASM_URL } from '@embedpdf/engines';\n\nexport interface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = DEFAULT_PDFIUM_WASM_URL, worker = true, logger } = config ?? {};\n\n // Create a reactive state object\n const state = $state({\n engine: null as PdfEngine | null,\n isLoading: true,\n error: null as Error | null,\n });\n\n let engineRef = $state<PdfEngine | null>(null);\n\n const isBrowser = typeof window !== 'undefined';\n\n if (isBrowser) {\n $effect(() => {\n let cancelled = false;\n\n (async () => {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, logger);\n engineRef = pdfEngine;\n\n pdfEngine.initialize().wait(\n () => {\n state.engine = pdfEngine;\n state.isLoading = false;\n },\n (e) => {\n state.error = new Error(e.reason.message);\n state.isLoading = false;\n },\n );\n } catch (e) {\n if (!cancelled) {\n state.error = e as Error;\n state.isLoading = false;\n }\n }\n })();\n\n return () => {\n cancelled = true;\n engineRef?.closeAllDocuments?.().wait(() => {\n engineRef?.destroy?.();\n engineRef = null;\n }, ignore);\n };\n });\n }\n\n // Return the reactive state object directly\n return state;\n}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import type { PdfEngine } from '@embedpdf/models';\n import { setPdfEngineContext } from '../context';\n\n interface Props {\n children: Snippet;\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n }\n\n let { children, engine, isLoading, error }: Props = $props();\n\n // Update context reactively whenever props change\n $effect(() => {\n setPdfEngineContext({\n engine,\n isLoading,\n error,\n });\n });\n</script>\n\n{@render children()}\n"],"names":["_b","_a"],"mappings":";;;;;MASM,yBAAyB,OAAO,kBAAkB;SAKxC,oBAAoB,OAA8B;AAChE,aAAW,wBAAwB,KAAK;AAC1C;AAMgB,SAAA,sBAA6C;QACrD,UAAU,WAA8C,sBAAsB;MAEhF,oBAAuB;AACf,UAAA,IAAA,MAAM,6DAA6D;AAAA,EAC/E;SAEO;AACT;ACpBO,SAAS,mBAA0C;AACxD,QAAM,eAAe,oBAAA;AAErB,MAAI,iBAAiB,QAAW;AAC9B,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC5E;AAEA,SAAO;AACT;AAMO,SAAS,YAAY;AAC1B,QAAM,EAAE,QAAQ,MAAA,IAAU,oBAAA;AAE1B,MAAI,OAAO;AACT,UAAM;AAAA,EACR;AAEA,SAAO;AACT;SCvBgB,gBAAgB,QAA+B;UACrD,UAAU,yBAAyB,SAAS,MAAM,OAAA,IAAW;QAG/D,kBACJ,QAAQ,MACR,WAAW,MACX,OAAO,MAAA;AAGL,MAAA,oBAAqC,IAAI;QAEvC,YAAA,OAAmB,WAAW;AAEhC,MAAA,WAAW;AACb,MAAA,kBAAc;AACR,UAAA,YAAY;mBAEH;YACP;AACM,gBAAA,EAAA,mBAAA,IAAuB,sBACd,wCAAwC,iBACxC,wCAAwC;AAEnD,gBAAA,YAAA,MAAkB,mBAAmB,SAAS,MAAM;AAC1D,YAAA,IAAA,WAAY,WAAA,IAAA;AAEZ,oBAAU,aAAa;AAAA,kBACf;AACJ,oBAAM,SAAS;AACf,oBAAM,YAAY;AAAA,YACpB;AAAA,YACC,CAAA,MAAM;AACL,oBAAM,QAAA,IAAY,MAAM,EAAE,OAAO,OAAO;AACxC,oBAAM,YAAY;AAAA,YACpB;AAAA;QAEJ,SAAS,GAAG;AACL,cAAA,CAAA,WAAW;AACd,kBAAM,QAAQ;AACd,kBAAM,YAAY;AAAA,UACpB;AAAA,QACF;AAAA,MACF,GAAA;mBAEa;;AACX,oBAAY;0BACZ,SAAA,yBAAW,kDAAsB;AAAA,gBAAW;;AAC1C,aAAAA,OAAAC,MAAA,EAAA,IAAA,SAAA,MAAA,gBAAAA,IAAW,YAAX,gBAAAD,IAAA,KAAAC;AACA,cAAA,IAAA,WAAY,IAAA;AAAA,UACd;AAAA,UAAG;AAAA;AAAA,MACL;AAAA,IACF,CAAC;AAAA,EACH;SAGO;AACT;8CClEA;;AAeE,IAAA,YAAO,MAAO;AACZ,wBAAmB;AAAA,MACjB,QAAM,QAAA;AAAA,MACN,WAAS,QAAA;AAAA,MACT,OAAK,QAAA;AAAA;EAET,CAAC;;;;;;AACH;"}
@@ -8,8 +8,9 @@ declare var __VLS_1: {};
8
8
  type __VLS_Slots = {} & {
9
9
  default?: (props: typeof __VLS_1) => any;
10
10
  };
11
- declare const __VLS_component: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
12
- declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
11
+ declare const __VLS_base: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
12
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
13
+ declare const _default: typeof __VLS_export;
13
14
  export default _default;
14
15
  type __VLS_WithSlots<T, S> = T & {
15
16
  new (): {
@@ -1,2 +1,2 @@
1
- "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("@embedpdf/models"),r=Symbol("pdfEngineKey");function t(){const n=e.inject(r);if(!n)throw new Error("useEngineContext must be used within a PdfEngineProvider");return n}const o="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@1.4.1/dist/pdfium.wasm";const i=e.defineComponent({__name:"pdf-engine-provider",props:{engine:{},isLoading:{type:Boolean},error:{}},setup(n){const t=n,{engine:o,isLoading:i,error:u}=e.toRefs(t);return e.provide(r,{engine:o,isLoading:i,error:u}),(n,r)=>e.renderSlot(n.$slots,"default")}});exports.PdfEngineProvider=i,exports.useEngine=function(){const{engine:e,error:n}=t();if(n.value)throw n.value;return e},exports.useEngineContext=t,exports.usePdfiumEngine=function(r={}){const{wasmUrl:t=o,worker:i=!0,logger:u}=r,s=e.ref(null),a=e.ref(!0),l=e.ref(null);async function d(){try{const{createPdfiumEngine:e}=i?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),n=await e(t,u);n.initialize().wait((()=>{a.value=!1,s.value=n}),(e=>{l.value=new Error(e.reason.message),a.value=!1})),a.value=!1}catch(e){l.value=e,a.value=!1}}function c(){var e,r;null==(r=null==(e=s.value)?void 0:e.closeAllDocuments)||r.call(e).wait((()=>{var e,n;null==(n=null==(e=s.value)?void 0:e.destroy)||n.call(e),s.value=null}),n.ignore)}return e.onMounted(d),e.onBeforeUnmount(c),e.watch((()=>[t,i,u]),(()=>{c(),d()})),{engine:s,isLoading:a,error:l}};
1
+ "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("@embedpdf/models"),r=Symbol("pdfEngineKey");function t(){const n=e.inject(r);if(!n)throw new Error("useEngineContext must be used within a PdfEngineProvider");return n}const o="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.0-next.0/dist/pdfium.wasm";const i=e.defineComponent({__name:"pdf-engine-provider",props:{engine:{},isLoading:{type:Boolean},error:{}},setup(n){const t=n,{engine:o,isLoading:i,error:u}=e.toRefs(t);return e.provide(r,{engine:o,isLoading:i,error:u}),(n,r)=>e.renderSlot(n.$slots,"default")}});exports.PdfEngineProvider=i,exports.useEngine=function(){const{engine:e,error:n}=t();if(n.value)throw n.value;return e},exports.useEngineContext=t,exports.usePdfiumEngine=function(r={}){const{wasmUrl:t=o,worker:i=!0,logger:u}=r,s=e.ref(null),a=e.ref(!0),l=e.ref(null);async function d(){try{const{createPdfiumEngine:e}=i?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),n=await e(t,u);n.initialize().wait(()=>{a.value=!1,s.value=n},e=>{l.value=new Error(e.reason.message),a.value=!1}),a.value=!1}catch(e){l.value=e,a.value=!1}}function c(){var e,r;null==(r=null==(e=s.value)?void 0:e.closeAllDocuments)||r.call(e).wait(()=>{var e,n;null==(n=null==(e=s.value)?void 0:e.destroy)||n.call(e),s.value=null},n.ignore)}return e.onMounted(d),e.onBeforeUnmount(c),e.watch(()=>[t,i,u],()=>{c(),d()}),{engine:s,isLoading:a,error:l}};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"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';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: Ref<PdfEngine | null>;\n isLoading: Ref<boolean>;\n error: Ref<Error | null>;\n}\n\nexport const pdfEngineKey: InjectionKey<PdfEngineContextState> = Symbol('pdfEngineKey');\n","import { inject } from 'vue';\nimport { pdfEngineKey, PdfEngineContextState } from '../context/pdf-engine-context';\n\n/**\n * Composable to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = inject(pdfEngineKey);\n\n if (!contextValue) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Composable to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error.value) {\n throw error.value;\n }\n\n return engine;\n}\n","import { ref, onMounted, onBeforeUnmount, watch, Ref } from 'vue';\nimport { ignore, type Logger, type PdfEngine } from '@embedpdf/models';\n\nconst defaultWasmUrl =\n 'https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm';\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\ninterface UsePdfiumEngineResult {\n engine: Ref<PdfEngine | null>;\n isLoading: Ref<boolean>;\n error: Ref<Error | null>;\n}\n\n/**\n * Vue composable that loads a PdfiumEngine (worker or direct)\n * and keeps its lifetime tied to the component.\n */\nexport function usePdfiumEngine(props: UsePdfiumEngineProps = {}): UsePdfiumEngineResult {\n const { wasmUrl = defaultWasmUrl, worker = true, logger } = props;\n\n const engine = ref<PdfEngine | null>(null);\n const isLoading = ref(true);\n const error = ref<Error | null>(null);\n\n /* create / destroy tied to component lifecycle ----------------- */\n onMounted(loadEngine);\n onBeforeUnmount(destroyEngine);\n\n /* re‑load if reactive props change ----------------------------- */\n watch(\n () => [wasmUrl, worker, logger] as const,\n () => {\n destroyEngine();\n loadEngine();\n },\n );\n\n async function loadEngine() {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, logger);\n pdfEngine.initialize().wait(\n () => {\n isLoading.value = false;\n engine.value = pdfEngine;\n },\n (e) => {\n error.value = new Error(e.reason.message);\n isLoading.value = false;\n },\n );\n isLoading.value = false;\n } catch (e) {\n error.value = e as Error;\n isLoading.value = false;\n }\n }\n\n function destroyEngine() {\n engine.value?.closeAllDocuments?.().wait(() => {\n engine.value?.destroy?.();\n engine.value = null;\n }, ignore);\n }\n\n return { engine, isLoading, error };\n}\n","<script setup lang=\"ts\">\nimport { provide, toRefs } from 'vue';\nimport { pdfEngineKey } from '../context/pdf-engine-context';\nimport type { PdfEngine } from '@embedpdf/models';\n\ninterface Props {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nconst props = defineProps<Props>();\n\n// Convert props to refs and provide them\nconst { engine, isLoading, error } = toRefs(props);\n\nprovide(pdfEngineKey, {\n engine,\n isLoading,\n error,\n});\n</script>\n\n<template>\n <slot />\n</template>\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":"0RASaA,EAAoDC,OAAO,gBCDjE,SAASC,IACR,MAAAC,EAAeC,SAAOJ,GAE5B,IAAKG,EACG,MAAA,IAAIE,MAAM,4DAGX,OAAAF,CACT,CCbA,MAAMG,EACJ,4LCOF,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,gDACPA,OAAO,0CAEXC,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,EAAUO,OAAQ,QACXY,GACPlB,EAAMM,MAAQY,EACdnB,EAAUO,OAAQ,CAAA,CACpB,CAGF,SAASe,YACP,OAAAC,EAAA,OAAAC,EAAAzB,EAAOQ,YAAP,EAAAiB,EAAcC,oBAAdF,EAAAG,KAAAF,GAAoCN,MAAK,aACvC,OAAAK,EAAA,OAAAC,EAAAzB,EAAOQ,cAAPiB,EAAcG,UAAdJ,EAAAG,KAAAF,GACAzB,EAAOQ,MAAQ,IAAA,GACdqB,SAAM,CAGJ,OA3CPC,EAAAA,UAAUhB,GACViB,EAAAA,gBAAgBR,GAGhBS,EAAAC,OACE,IAAM,CAACxB,EAASC,EAAQC,KACxB,KACgBY,IACHT,GAAA,IAmCR,CAAEd,SAAQC,YAAWC,QAC9B"}
1
+ {"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';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: Ref<PdfEngine | null>;\n isLoading: Ref<boolean>;\n error: Ref<Error | null>;\n}\n\nexport const pdfEngineKey: InjectionKey<PdfEngineContextState> = Symbol('pdfEngineKey');\n","import { inject } from 'vue';\nimport { pdfEngineKey, PdfEngineContextState } from '../context/pdf-engine-context';\n\n/**\n * Composable to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = inject(pdfEngineKey);\n\n if (!contextValue) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Composable to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error.value) {\n throw error.value;\n }\n\n return engine;\n}\n","import { ref, onMounted, onBeforeUnmount, watch, Ref } from 'vue';\nimport { ignore, type Logger, type PdfEngine } from '@embedpdf/models';\n\nconst defaultWasmUrl =\n 'https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm';\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\ninterface UsePdfiumEngineResult {\n engine: Ref<PdfEngine | null>;\n isLoading: Ref<boolean>;\n error: Ref<Error | null>;\n}\n\n/**\n * Vue composable that loads a PdfiumEngine (worker or direct)\n * and keeps its lifetime tied to the component.\n */\nexport function usePdfiumEngine(props: UsePdfiumEngineProps = {}): UsePdfiumEngineResult {\n const { wasmUrl = defaultWasmUrl, worker = true, logger } = props;\n\n const engine = ref<PdfEngine | null>(null);\n const isLoading = ref(true);\n const error = ref<Error | null>(null);\n\n /* create / destroy tied to component lifecycle ----------------- */\n onMounted(loadEngine);\n onBeforeUnmount(destroyEngine);\n\n /* re‑load if reactive props change ----------------------------- */\n watch(\n () => [wasmUrl, worker, logger] as const,\n () => {\n destroyEngine();\n loadEngine();\n },\n );\n\n async function loadEngine() {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, logger);\n pdfEngine.initialize().wait(\n () => {\n isLoading.value = false;\n engine.value = pdfEngine;\n },\n (e) => {\n error.value = new Error(e.reason.message);\n isLoading.value = false;\n },\n );\n isLoading.value = false;\n } catch (e) {\n error.value = e as Error;\n isLoading.value = false;\n }\n }\n\n function destroyEngine() {\n engine.value?.closeAllDocuments?.().wait(() => {\n engine.value?.destroy?.();\n engine.value = null;\n }, ignore);\n }\n\n return { engine, isLoading, error };\n}\n","<script setup lang=\"ts\">\nimport { provide, toRefs } from 'vue';\nimport { pdfEngineKey } from '../context/pdf-engine-context';\nimport type { PdfEngine } from '@embedpdf/models';\n\ninterface Props {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nconst props = defineProps<Props>();\n\n// Convert props to refs and provide them\nconst { engine, isLoading, error } = toRefs(props);\n\nprovide(pdfEngineKey, {\n engine,\n isLoading,\n error,\n});\n</script>\n\n<template>\n <slot />\n</template>\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","watch"],"mappings":"0RASaA,EAAoDC,OAAO,gBCDjE,SAASC,IACd,MAAMC,EAAeC,EAAAA,OAAOJ,GAE5B,IAAKG,EACH,MAAM,IAAIE,MAAM,4DAGlB,OAAOF,CACT,CCbA,MAAMG,EACJ,mMCOF,MAAMC,EAAQC,GAGRC,OAAEA,EAAAC,UAAQA,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,MAGd,OAAOR,CACT,qDCRO,SAAyBF,EAA8B,IAC5D,MAAMW,QAAEA,EAAUZ,EAAAa,OAAgBA,GAAS,EAAAC,OAAMA,GAAWb,EAEtDE,EAASY,EAAAA,IAAsB,MAC/BX,EAAYW,EAAAA,KAAI,GAChBV,EAAQU,EAAAA,IAAkB,MAehCC,eAAeC,IACb,IACE,MAAMC,mBAAEA,GAAuBL,QACrBM,OAAO,gDACPA,OAAO,0CAEXC,QAAkBF,EAAmBN,EAASE,GACpDM,EAAUC,aAAaC,KACrB,KACElB,EAAUO,OAAQ,EAClBR,EAAOQ,MAAQS,GAEhBG,IACClB,EAAMM,MAAQ,IAAIZ,MAAMwB,EAAEC,OAAOC,SACjCrB,EAAUO,OAAQ,IAGtBP,EAAUO,OAAQ,CACpB,OAASY,GACPlB,EAAMM,MAAQY,EACdnB,EAAUO,OAAQ,CACpB,CACF,CAEA,SAASe,YACP,OAAAC,EAAA,OAAAC,EAAAzB,EAAOQ,YAAP,EAAAiB,EAAcC,oBAAdF,EAAAG,KAAAF,GAAoCN,KAAK,aACvC,OAAAK,EAAA,OAAAC,EAAAzB,EAAOQ,cAAPiB,EAAcG,UAAdJ,EAAAG,KAAAF,GACAzB,EAAOQ,MAAQ,MACdqB,EAAAA,OACL,CAEA,OA3CAC,EAAAA,UAAUhB,GACViB,EAAAA,gBAAgBR,GAGhBS,EAAAA,MACE,IAAM,CAACvB,EAASC,EAAQC,GACxB,KACEY,IACAT,MAmCG,CAAEd,SAAQC,YAAWC,QAC9B"}
package/dist/vue/index.js CHANGED
@@ -15,7 +15,7 @@ function useEngine() {
15
15
  }
16
16
  return engine;
17
17
  }
18
- const defaultWasmUrl = "https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@1.4.1/dist/pdfium.wasm";
18
+ const defaultWasmUrl = "https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.0-next.0/dist/pdfium.wasm";
19
19
  function usePdfiumEngine(props = {}) {
20
20
  const { wasmUrl = defaultWasmUrl, worker = true, logger } = props;
21
21
  const engine = ref(null);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","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';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: Ref<PdfEngine | null>;\n isLoading: Ref<boolean>;\n error: Ref<Error | null>;\n}\n\nexport const pdfEngineKey: InjectionKey<PdfEngineContextState> = Symbol('pdfEngineKey');\n","import { inject } from 'vue';\nimport { pdfEngineKey, PdfEngineContextState } from '../context/pdf-engine-context';\n\n/**\n * Composable to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = inject(pdfEngineKey);\n\n if (!contextValue) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Composable to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error.value) {\n throw error.value;\n }\n\n return engine;\n}\n","import { ref, onMounted, onBeforeUnmount, watch, Ref } from 'vue';\nimport { ignore, type Logger, type PdfEngine } from '@embedpdf/models';\n\nconst defaultWasmUrl =\n 'https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm';\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\ninterface UsePdfiumEngineResult {\n engine: Ref<PdfEngine | null>;\n isLoading: Ref<boolean>;\n error: Ref<Error | null>;\n}\n\n/**\n * Vue composable that loads a PdfiumEngine (worker or direct)\n * and keeps its lifetime tied to the component.\n */\nexport function usePdfiumEngine(props: UsePdfiumEngineProps = {}): UsePdfiumEngineResult {\n const { wasmUrl = defaultWasmUrl, worker = true, logger } = props;\n\n const engine = ref<PdfEngine | null>(null);\n const isLoading = ref(true);\n const error = ref<Error | null>(null);\n\n /* create / destroy tied to component lifecycle ----------------- */\n onMounted(loadEngine);\n onBeforeUnmount(destroyEngine);\n\n /* re‑load if reactive props change ----------------------------- */\n watch(\n () => [wasmUrl, worker, logger] as const,\n () => {\n destroyEngine();\n loadEngine();\n },\n );\n\n async function loadEngine() {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, logger);\n pdfEngine.initialize().wait(\n () => {\n isLoading.value = false;\n engine.value = pdfEngine;\n },\n (e) => {\n error.value = new Error(e.reason.message);\n isLoading.value = false;\n },\n );\n isLoading.value = false;\n } catch (e) {\n error.value = e as Error;\n isLoading.value = false;\n }\n }\n\n function destroyEngine() {\n engine.value?.closeAllDocuments?.().wait(() => {\n engine.value?.destroy?.();\n engine.value = null;\n }, ignore);\n }\n\n return { engine, isLoading, error };\n}\n","<script setup lang=\"ts\">\nimport { provide, toRefs } from 'vue';\nimport { pdfEngineKey } from '../context/pdf-engine-context';\nimport type { PdfEngine } from '@embedpdf/models';\n\ninterface Props {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nconst props = defineProps<Props>();\n\n// Convert props to refs and provide them\nconst { engine, isLoading, error } = toRefs(props);\n\nprovide(pdfEngineKey, {\n engine,\n isLoading,\n error,\n});\n</script>\n\n<template>\n <slot />\n</template>\n"],"names":["_b","_a","_renderSlot"],"mappings":";;AASa,MAAA,eAAoD,OAAO,cAAc;ACD/E,SAAS,mBAA0C;AAClD,QAAA,eAAe,OAAO,YAAY;AAExC,MAAI,CAAC,cAAc;AACX,UAAA,IAAI,MAAM,0DAA0D;AAAA,EAAA;AAGrE,SAAA;AACT;AAMO,SAAS,YAAY;AAC1B,QAAM,EAAE,QAAQ,MAAM,IAAI,iBAAiB;AAE3C,MAAI,MAAM,OAAO;AACf,UAAM,MAAM;AAAA,EAAA;AAGP,SAAA;AACT;AC3BA,MAAM,iBACJ;AAkBc,SAAA,gBAAgB,QAA8B,IAA2B;AACvF,QAAM,EAAE,UAAU,gBAAgB,SAAS,MAAM,WAAW;AAEtD,QAAA,SAAS,IAAsB,IAAI;AACnC,QAAA,YAAY,IAAI,IAAI;AACpB,QAAA,QAAQ,IAAkB,IAAI;AAGpC,YAAU,UAAU;AACpB,kBAAgB,aAAa;AAG7B;AAAA,IACE,MAAM,CAAC,SAAS,QAAQ,MAAM;AAAA,IAC9B,MAAM;AACU,oBAAA;AACH,iBAAA;AAAA,IAAA;AAAA,EAEf;AAEA,iBAAe,aAAa;AACtB,QAAA;AACI,YAAA,EAAE,mBAAmB,IAAI,SAC3B,MAAM,OAAO,wCAAwC,IACrD,MAAM,OAAO,wCAAwC;AAEzD,YAAM,YAAY,MAAM,mBAAmB,SAAS,MAAM;AAC1D,gBAAU,aAAa;AAAA,QACrB,MAAM;AACJ,oBAAU,QAAQ;AAClB,iBAAO,QAAQ;AAAA,QACjB;AAAA,QACA,CAAC,MAAM;AACL,gBAAM,QAAQ,IAAI,MAAM,EAAE,OAAO,OAAO;AACxC,oBAAU,QAAQ;AAAA,QAAA;AAAA,MAEtB;AACA,gBAAU,QAAQ;AAAA,aACX,GAAG;AACV,YAAM,QAAQ;AACd,gBAAU,QAAQ;AAAA,IAAA;AAAA,EACpB;AAGF,WAAS,gBAAgB;;AACvB,uBAAO,UAAP,mBAAc,sBAAd,4BAAoC,KAAK,MAAM;;AAC7C,OAAAA,OAAAC,MAAA,OAAO,UAAP,gBAAAA,IAAc,YAAd,gBAAAD,IAAA,KAAAC;AACA,aAAO,QAAQ;AAAA,OACd;AAAA,EAAM;AAGJ,SAAA,EAAE,QAAQ,WAAW,MAAM;AACpC;;;;;;;;;AC/DA,UAAM,QAAQ;AAGd,UAAM,EAAE,QAAQ,WAAW,MAAM,IAAI,OAAO,KAAK;AAEjD,YAAQ,cAAc;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;;AAIC,aAAAC,WAAQ,KAAA,QAAA,SAAA;AAAA;;;"}
1
+ {"version":3,"file":"index.js","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';\nimport type { PdfEngine } from '@embedpdf/models';\n\nexport interface PdfEngineContextState {\n engine: Ref<PdfEngine | null>;\n isLoading: Ref<boolean>;\n error: Ref<Error | null>;\n}\n\nexport const pdfEngineKey: InjectionKey<PdfEngineContextState> = Symbol('pdfEngineKey');\n","import { inject } from 'vue';\nimport { pdfEngineKey, PdfEngineContextState } from '../context/pdf-engine-context';\n\n/**\n * Composable to access the PDF engine from context.\n * @returns The PDF engine context state\n * @throws Error if used outside of PdfEngineProvider\n */\nexport function useEngineContext(): PdfEngineContextState {\n const contextValue = inject(pdfEngineKey);\n\n if (!contextValue) {\n throw new Error('useEngineContext must be used within a PdfEngineProvider');\n }\n\n return contextValue;\n}\n\n/**\n * Composable to access the PDF engine, with a more convenient API.\n * @returns The PDF engine or null if loading/error\n */\nexport function useEngine() {\n const { engine, error } = useEngineContext();\n\n if (error.value) {\n throw error.value;\n }\n\n return engine;\n}\n","import { ref, onMounted, onBeforeUnmount, watch, Ref } from 'vue';\nimport { ignore, type Logger, type PdfEngine } from '@embedpdf/models';\n\nconst defaultWasmUrl =\n 'https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@__PDFIUM_VERSION__/dist/pdfium.wasm';\n\ninterface UsePdfiumEngineProps {\n wasmUrl?: string;\n worker?: boolean;\n logger?: Logger;\n}\n\ninterface UsePdfiumEngineResult {\n engine: Ref<PdfEngine | null>;\n isLoading: Ref<boolean>;\n error: Ref<Error | null>;\n}\n\n/**\n * Vue composable that loads a PdfiumEngine (worker or direct)\n * and keeps its lifetime tied to the component.\n */\nexport function usePdfiumEngine(props: UsePdfiumEngineProps = {}): UsePdfiumEngineResult {\n const { wasmUrl = defaultWasmUrl, worker = true, logger } = props;\n\n const engine = ref<PdfEngine | null>(null);\n const isLoading = ref(true);\n const error = ref<Error | null>(null);\n\n /* create / destroy tied to component lifecycle ----------------- */\n onMounted(loadEngine);\n onBeforeUnmount(destroyEngine);\n\n /* re‑load if reactive props change ----------------------------- */\n watch(\n () => [wasmUrl, worker, logger] as const,\n () => {\n destroyEngine();\n loadEngine();\n },\n );\n\n async function loadEngine() {\n try {\n const { createPdfiumEngine } = worker\n ? await import('@embedpdf/engines/pdfium-worker-engine')\n : await import('@embedpdf/engines/pdfium-direct-engine');\n\n const pdfEngine = await createPdfiumEngine(wasmUrl, logger);\n pdfEngine.initialize().wait(\n () => {\n isLoading.value = false;\n engine.value = pdfEngine;\n },\n (e) => {\n error.value = new Error(e.reason.message);\n isLoading.value = false;\n },\n );\n isLoading.value = false;\n } catch (e) {\n error.value = e as Error;\n isLoading.value = false;\n }\n }\n\n function destroyEngine() {\n engine.value?.closeAllDocuments?.().wait(() => {\n engine.value?.destroy?.();\n engine.value = null;\n }, ignore);\n }\n\n return { engine, isLoading, error };\n}\n","<script setup lang=\"ts\">\nimport { provide, toRefs } from 'vue';\nimport { pdfEngineKey } from '../context/pdf-engine-context';\nimport type { PdfEngine } from '@embedpdf/models';\n\ninterface Props {\n engine: PdfEngine | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nconst props = defineProps<Props>();\n\n// Convert props to refs and provide them\nconst { engine, isLoading, error } = toRefs(props);\n\nprovide(pdfEngineKey, {\n engine,\n isLoading,\n error,\n});\n</script>\n\n<template>\n <slot />\n</template>\n"],"names":["_b","_a","_renderSlot"],"mappings":";;AASO,MAAM,eAAoD,OAAO,cAAc;ACD/E,SAAS,mBAA0C;AACxD,QAAM,eAAe,OAAO,YAAY;AAExC,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC5E;AAEA,SAAO;AACT;AAMO,SAAS,YAAY;AAC1B,QAAM,EAAE,QAAQ,MAAA,IAAU,iBAAA;AAE1B,MAAI,MAAM,OAAO;AACf,UAAM,MAAM;AAAA,EACd;AAEA,SAAO;AACT;AC3BA,MAAM,iBACJ;AAkBK,SAAS,gBAAgB,QAA8B,IAA2B;AACvF,QAAM,EAAE,UAAU,gBAAgB,SAAS,MAAM,WAAW;AAE5D,QAAM,SAAS,IAAsB,IAAI;AACzC,QAAM,YAAY,IAAI,IAAI;AAC1B,QAAM,QAAQ,IAAkB,IAAI;AAGpC,YAAU,UAAU;AACpB,kBAAgB,aAAa;AAG7B;AAAA,IACE,MAAM,CAAC,SAAS,QAAQ,MAAM;AAAA,IAC9B,MAAM;AACJ,oBAAA;AACA,iBAAA;AAAA,IACF;AAAA,EAAA;AAGF,iBAAe,aAAa;AAC1B,QAAI;AACF,YAAM,EAAE,mBAAA,IAAuB,SAC3B,MAAM,OAAO,wCAAwC,IACrD,MAAM,OAAO,wCAAwC;AAEzD,YAAM,YAAY,MAAM,mBAAmB,SAAS,MAAM;AAC1D,gBAAU,aAAa;AAAA,QACrB,MAAM;AACJ,oBAAU,QAAQ;AAClB,iBAAO,QAAQ;AAAA,QACjB;AAAA,QACA,CAAC,MAAM;AACL,gBAAM,QAAQ,IAAI,MAAM,EAAE,OAAO,OAAO;AACxC,oBAAU,QAAQ;AAAA,QACpB;AAAA,MAAA;AAEF,gBAAU,QAAQ;AAAA,IACpB,SAAS,GAAG;AACV,YAAM,QAAQ;AACd,gBAAU,QAAQ;AAAA,IACpB;AAAA,EACF;AAEA,WAAS,gBAAgB;;AACvB,uBAAO,UAAP,mBAAc,sBAAd,4BAAoC,KAAK,MAAM;;AAC7C,OAAAA,OAAAC,MAAA,OAAO,UAAP,gBAAAA,IAAc,YAAd,gBAAAD,IAAA,KAAAC;AACA,aAAO,QAAQ;AAAA,IACjB,GAAG;AAAA,EACL;AAEA,SAAO,EAAE,QAAQ,WAAW,MAAA;AAC9B;;;;;;;;;AC/DA,UAAM,QAAQ;AAGd,UAAM,EAAE,QAAQ,WAAW,MAAA,IAAU,OAAO,KAAK;AAEjD,YAAQ,cAAc;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;;aAICC,WAAQ,KAAA,QAAA,SAAA;AAAA;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/engines",
3
- "version": "1.4.1",
3
+ "version": "2.0.0-next.0",
4
4
  "description": "Pluggable runtime layer that abstracts over multiple PDF engines (PDF-ium, Web Workers, mocks, etc.) to provide a unified API for rendering, search, annotation, and other document-level operations in EmbedPDF.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -88,8 +88,8 @@
88
88
  "@embedpdf/build": "1.1.0"
89
89
  },
90
90
  "dependencies": {
91
- "@embedpdf/models": "1.4.1",
92
- "@embedpdf/pdfium": "1.4.1"
91
+ "@embedpdf/models": "2.0.0-next.0",
92
+ "@embedpdf/pdfium": "2.0.0-next.0"
93
93
  },
94
94
  "peerDependencies": {
95
95
  "preact": "^10.26.4",