@embedpdf/engines 1.0.26 → 1.1.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 (66) hide show
  1. package/dist/{engine-BH98VpS7.js → engine-Cm-940a0.js} +135 -12
  2. package/dist/engine-Cm-940a0.js.map +1 -0
  3. package/dist/engine-DVTbcCVE.cjs +2 -0
  4. package/dist/engine-DVTbcCVE.cjs.map +1 -0
  5. package/dist/index-BZKyCIIQ.cjs +2 -0
  6. package/dist/{index-CpWF5iWs.cjs.map → index-BZKyCIIQ.cjs.map} +1 -1
  7. package/dist/{index-DF0oRaJr.js → index-D9GgzViI.js} +6 -3
  8. package/dist/{index-DF0oRaJr.js.map → index-D9GgzViI.js.map} +1 -1
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.js +8 -4
  12. package/dist/index.js.map +1 -1
  13. package/dist/lib/pdfium/cache.d.ts +43 -5
  14. package/dist/lib/pdfium/engine.d.ts +11 -1
  15. package/dist/lib/pdfium/index.cjs +1 -1
  16. package/dist/lib/pdfium/index.js +2 -2
  17. package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
  18. package/dist/lib/pdfium/web/direct-engine.js +1 -1
  19. package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
  20. package/dist/lib/pdfium/web/worker-engine.js +1 -1
  21. package/dist/lib/webworker/engine.cjs +1 -1
  22. package/dist/lib/webworker/engine.cjs.map +1 -1
  23. package/dist/lib/webworker/engine.d.ts +6 -0
  24. package/dist/lib/webworker/engine.js +14 -1
  25. package/dist/lib/webworker/engine.js.map +1 -1
  26. package/dist/preact/adapter.d.ts +3 -1
  27. package/dist/preact/index.cjs +1 -1
  28. package/dist/preact/index.cjs.map +1 -1
  29. package/dist/preact/index.js +47 -7
  30. package/dist/preact/index.js.map +1 -1
  31. package/dist/react/adapter.d.ts +2 -1
  32. package/dist/react/index.cjs +1 -1
  33. package/dist/react/index.cjs.map +1 -1
  34. package/dist/react/index.js +46 -7
  35. package/dist/react/index.js.map +1 -1
  36. package/dist/shared-preact/components/index.d.ts +1 -0
  37. package/dist/shared-preact/components/pdf-engine-provider.d.ts +16 -0
  38. package/dist/shared-preact/context/index.d.ts +1 -0
  39. package/dist/shared-preact/context/pdf-engine-context.d.ts +7 -0
  40. package/dist/shared-preact/hooks/index.d.ts +1 -0
  41. package/dist/shared-preact/hooks/use-engine-context.d.ts +12 -0
  42. package/dist/shared-preact/index.d.ts +1 -0
  43. package/dist/shared-react/components/index.d.ts +1 -0
  44. package/dist/shared-react/components/pdf-engine-provider.d.ts +16 -0
  45. package/dist/shared-react/context/index.d.ts +1 -0
  46. package/dist/shared-react/context/pdf-engine-context.d.ts +7 -0
  47. package/dist/shared-react/hooks/index.d.ts +1 -0
  48. package/dist/shared-react/hooks/use-engine-context.d.ts +12 -0
  49. package/dist/shared-react/index.d.ts +1 -0
  50. package/dist/vue/components/index.d.ts +1 -0
  51. package/dist/vue/components/pdf-engine-provider.vue.d.ts +18 -0
  52. package/dist/vue/composables/index.d.ts +2 -0
  53. package/dist/vue/composables/use-engine-context.d.ts +12 -0
  54. package/dist/vue/context/pdf-engine-context.d.ts +8 -0
  55. package/dist/vue/index.cjs +1 -1
  56. package/dist/vue/index.cjs.map +1 -1
  57. package/dist/vue/index.d.ts +2 -1
  58. package/dist/vue/index.js +57 -7
  59. package/dist/vue/index.js.map +1 -1
  60. package/package.json +3 -3
  61. package/dist/engine-BH98VpS7.js.map +0 -1
  62. package/dist/engine-CudZwyui.cjs +0 -2
  63. package/dist/engine-CudZwyui.cjs.map +0 -1
  64. package/dist/index-CpWF5iWs.cjs +0 -2
  65. package/dist/vue/hooks/index.d.ts +0 -1
  66. /package/dist/vue/{hooks → composables}/use-pdfium-engine.d.ts +0 -0
@@ -1,5 +1,8 @@
1
- import { useState, useRef, useEffect } from "preact/hooks";
2
- const defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@1.0.26/dist/pdfium.wasm`;
1
+ import { useState, useRef, useEffect, useContext } from "preact/hooks";
2
+ import { createContext } from "preact";
3
+ import { ignore } from "@embedpdf/models";
4
+ import { jsx } from "preact/jsx-runtime";
5
+ const defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@1.1.0/dist/pdfium.wasm`;
3
6
  function usePdfiumEngine(config) {
4
7
  const { wasmUrl = defaultWasmUrl, worker = true, logger } = config ?? {};
5
8
  const [engine, setEngine] = useState(null);
@@ -13,8 +16,16 @@ function usePdfiumEngine(config) {
13
16
  const { createPdfiumEngine } = worker ? await import("@embedpdf/engines/pdfium-worker-engine") : await import("@embedpdf/engines/pdfium-direct-engine");
14
17
  const pdfEngine = await createPdfiumEngine(wasmUrl, logger);
15
18
  engineRef.current = pdfEngine;
16
- setEngine(pdfEngine);
17
- setLoading(false);
19
+ pdfEngine.initialize().wait(
20
+ () => {
21
+ setEngine(pdfEngine);
22
+ setLoading(false);
23
+ },
24
+ (e) => {
25
+ setError(new Error(e.reason.message));
26
+ setLoading(false);
27
+ }
28
+ );
18
29
  } catch (e) {
19
30
  if (!cancelled) {
20
31
  setError(e);
@@ -23,15 +34,44 @@ function usePdfiumEngine(config) {
23
34
  }
24
35
  })();
25
36
  return () => {
26
- var _a;
37
+ var _a, _b;
27
38
  cancelled = true;
28
- (_a = engineRef.current) == null ? void 0 : _a.destroy();
29
- engineRef.current = null;
39
+ (_b = (_a = engineRef.current) == null ? void 0 : _a.closeAllDocuments) == null ? void 0 : _b.call(_a).wait(() => {
40
+ var _a2, _b2;
41
+ (_b2 = (_a2 = engineRef.current) == null ? void 0 : _a2.destroy) == null ? void 0 : _b2.call(_a2);
42
+ engineRef.current = null;
43
+ }, ignore);
30
44
  };
31
45
  }, [wasmUrl, worker, logger]);
32
46
  return { engine, isLoading: loading, error };
33
47
  }
48
+ const PdfEngineContext = createContext(void 0);
49
+ function useEngineContext() {
50
+ const contextValue = useContext(PdfEngineContext);
51
+ if (contextValue === void 0) {
52
+ throw new Error("useEngineContext must be used within a PdfEngineProvider");
53
+ }
54
+ return contextValue;
55
+ }
56
+ function useEngine() {
57
+ const { engine, error } = useEngineContext();
58
+ if (error) {
59
+ throw error;
60
+ }
61
+ return engine;
62
+ }
63
+ function PdfEngineProvider({ children, engine, isLoading, error }) {
64
+ const contextValue = {
65
+ engine,
66
+ isLoading,
67
+ error
68
+ };
69
+ return /* @__PURE__ */ jsx(PdfEngineContext.Provider, { value: contextValue, children });
70
+ }
34
71
  export {
72
+ PdfEngineProvider,
73
+ useEngine,
74
+ useEngineContext,
35
75
  usePdfiumEngine
36
76
  };
37
77
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-pdfium-engine.ts"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { 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<{ destroy(): void } | 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 setEngine(pdfEngine);\n setLoading(false);\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?.destroy();\n engineRef.current = null;\n };\n }, [wasmUrl, worker, logger]);\n\n return { engine, isLoading: loading, error };\n}\n"],"names":[],"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,OAAmC,IAAI;AAEzD,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,SAAS;AACnB,mBAAW,KAAK;AAAA,eACT,GAAG;AACV,YAAI,CAAC,WAAW;AACd,mBAAS,CAAU;AACnB,qBAAW,KAAK;AAAA,QAAA;AAAA,MAClB;AAAA,IACF,GACC;AAEH,WAAO,MAAM;;AACC,kBAAA;AACZ,sBAAU,YAAV,mBAAmB;AACnB,gBAAU,UAAU;AAAA,IACtB;AAAA,EACC,GAAA,CAAC,SAAS,QAAQ,MAAM,CAAC;AAE5B,SAAO,EAAE,QAAQ,WAAW,SAAS,MAAM;AAC7C;"}
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 +1,2 @@
1
- export { useState, useEffect, useRef } from 'react';
1
+ export { useState, useEffect, useRef, useContext, createContext, ReactNode } from 'react';
2
+ export type { JSX } from 'react';
@@ -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"),t="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@1.0.26/dist/pdfium.wasm";exports.usePdfiumEngine=function(r){const{wasmUrl:n=t,worker:i=!0,logger:o}=r??{},[u,s]=e.useState(null),[c,a]=e.useState(!0),[p,d]=e.useState(null),l=e.useRef(null);return e.useEffect((()=>{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,o);l.current=t,s(t),a(!1)}catch(t){e||(d(t),a(!1))}})(),()=>{var t;e=!0,null==(t=l.current)||t.destroy(),l.current=null}}),[n,i,o]),{engine:u,isLoading:c,error:p}};
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.1.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"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { 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<{ destroy(): void } | 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 setEngine(pdfEngine);\n setLoading(false);\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?.destroy();\n engineRef.current = null;\n };\n }, [wasmUrl, worker, logger]);\n\n return { engine, isLoading: loading, error };\n}\n"],"names":["defaultWasmUrl","config","wasmUrl","worker","logger","engine","setEngine","useState","loading","setLoading","error","setError","engineRef","useRef","useEffect","cancelled","createPdfiumEngine","import","pdfEngine","current","e","_a","destroy","isLoading"],"mappings":"8PAGMA,EAAiB,gGAQhB,SAAyBC,GACxB,MAAAC,QAAEA,EAAUF,EAAgBG,OAAAA,GAAS,SAAMC,GAAWH,GAAU,CAAC,GAEhEI,EAAQC,GAAaC,EAAAA,SAA2B,OAChDC,EAASC,GAAcF,EAAAA,UAAS,IAChCG,EAAOC,GAAYJ,EAAAA,SAAuB,MAC3CK,EAAYC,SAAmC,MA8BrD,OA5BAC,EAAAA,WAAU,KACR,IAAIC,GAAY,EAoBhB,MAlBA,WACM,IACI,MAAAC,mBAAEA,GAAuBb,QACrBc,OAAO,gDACPA,OAAO,0CAEXC,QAAkBF,EAAmBd,EAASE,GACpDQ,EAAUO,QAAUD,EACpBZ,EAAUY,GACVT,GAAW,SACJW,GACFL,IACHJ,EAASS,GACTX,GAAW,GACb,CAED,EAhBH,GAkBO,WACOM,GAAA,EACZ,OAAAM,EAAAT,EAAUO,UAASE,EAAAC,UACnBV,EAAUO,QAAU,IAAA,CACtB,GACC,CAACjB,EAASC,EAAQC,IAEd,CAAEC,SAAQkB,UAAWf,EAASE,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,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,5 +1,7 @@
1
- import { useState, useRef, useEffect } from "react";
2
- const defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@1.0.26/dist/pdfium.wasm`;
1
+ import { useState, useRef, useEffect, createContext, useContext } from "react";
2
+ import { ignore } from "@embedpdf/models";
3
+ import { jsx } from "react/jsx-runtime";
4
+ const defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@1.1.0/dist/pdfium.wasm`;
3
5
  function usePdfiumEngine(config) {
4
6
  const { wasmUrl = defaultWasmUrl, worker = true, logger } = config ?? {};
5
7
  const [engine, setEngine] = useState(null);
@@ -13,8 +15,16 @@ function usePdfiumEngine(config) {
13
15
  const { createPdfiumEngine } = worker ? await import("@embedpdf/engines/pdfium-worker-engine") : await import("@embedpdf/engines/pdfium-direct-engine");
14
16
  const pdfEngine = await createPdfiumEngine(wasmUrl, logger);
15
17
  engineRef.current = pdfEngine;
16
- setEngine(pdfEngine);
17
- setLoading(false);
18
+ pdfEngine.initialize().wait(
19
+ () => {
20
+ setEngine(pdfEngine);
21
+ setLoading(false);
22
+ },
23
+ (e) => {
24
+ setError(new Error(e.reason.message));
25
+ setLoading(false);
26
+ }
27
+ );
18
28
  } catch (e) {
19
29
  if (!cancelled) {
20
30
  setError(e);
@@ -23,15 +33,44 @@ function usePdfiumEngine(config) {
23
33
  }
24
34
  })();
25
35
  return () => {
26
- var _a;
36
+ var _a, _b;
27
37
  cancelled = true;
28
- (_a = engineRef.current) == null ? void 0 : _a.destroy();
29
- engineRef.current = null;
38
+ (_b = (_a = engineRef.current) == null ? void 0 : _a.closeAllDocuments) == null ? void 0 : _b.call(_a).wait(() => {
39
+ var _a2, _b2;
40
+ (_b2 = (_a2 = engineRef.current) == null ? void 0 : _a2.destroy) == null ? void 0 : _b2.call(_a2);
41
+ engineRef.current = null;
42
+ }, ignore);
30
43
  };
31
44
  }, [wasmUrl, worker, logger]);
32
45
  return { engine, isLoading: loading, error };
33
46
  }
47
+ const PdfEngineContext = createContext(void 0);
48
+ function useEngineContext() {
49
+ const contextValue = useContext(PdfEngineContext);
50
+ if (contextValue === void 0) {
51
+ throw new Error("useEngineContext must be used within a PdfEngineProvider");
52
+ }
53
+ return contextValue;
54
+ }
55
+ function useEngine() {
56
+ const { engine, error } = useEngineContext();
57
+ if (error) {
58
+ throw error;
59
+ }
60
+ return engine;
61
+ }
62
+ function PdfEngineProvider({ children, engine, isLoading, error }) {
63
+ const contextValue = {
64
+ engine,
65
+ isLoading,
66
+ error
67
+ };
68
+ return /* @__PURE__ */ jsx(PdfEngineContext.Provider, { value: contextValue, children });
69
+ }
34
70
  export {
71
+ PdfEngineProvider,
72
+ useEngine,
73
+ useEngineContext,
35
74
  usePdfiumEngine
36
75
  };
37
76
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-pdfium-engine.ts"],"sourcesContent":["import { useEffect, useRef, useState } from '@framework';\nimport { 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<{ destroy(): void } | 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 setEngine(pdfEngine);\n setLoading(false);\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?.destroy();\n engineRef.current = null;\n };\n }, [wasmUrl, worker, logger]);\n\n return { engine, isLoading: loading, error };\n}\n"],"names":[],"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,OAAmC,IAAI;AAEzD,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,SAAS;AACnB,mBAAW,KAAK;AAAA,eACT,GAAG;AACV,YAAI,CAAC,WAAW;AACd,mBAAS,CAAU;AACnB,qBAAW,KAAK;AAAA,QAAA;AAAA,MAClB;AAAA,IACF,GACC;AAEH,WAAO,MAAM;;AACC,kBAAA;AACZ,sBAAU,YAAV,mBAAmB;AACnB,gBAAU,UAAU;AAAA,IACtB;AAAA,EACC,GAAA,CAAC,SAAS,QAAQ,MAAM,CAAC;AAE5B,SAAO,EAAE,QAAQ,WAAW,SAAS,MAAM;AAC7C;"}
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;"}
@@ -0,0 +1 @@
1
+ export * from './pdf-engine-provider';
@@ -0,0 +1,16 @@
1
+ import { ReactNode } from '../../preact/adapter.ts';
2
+ import { PdfEngine } from '@embedpdf/models';
3
+ export interface PdfEngineProviderProps {
4
+ children: ReactNode;
5
+ engine: PdfEngine | null;
6
+ isLoading: boolean;
7
+ error: Error | null;
8
+ }
9
+ /**
10
+ * Provider component that makes a PDF engine instance available
11
+ * to all child components via context.
12
+ *
13
+ * This provider is completely engine-agnostic - it accepts any engine
14
+ * and its loading state from the parent component.
15
+ */
16
+ export declare function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps): import("preact").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './pdf-engine-context';
@@ -0,0 +1,7 @@
1
+ import { PdfEngine } from '@embedpdf/models';
2
+ export interface PdfEngineContextState {
3
+ engine: PdfEngine | null;
4
+ isLoading: boolean;
5
+ error: Error | null;
6
+ }
7
+ export declare const PdfEngineContext: import('preact').Context<PdfEngineContextState | undefined>;
@@ -1 +1,2 @@
1
1
  export * from './use-pdfium-engine';
2
+ export * from './use-engine-context';
@@ -0,0 +1,12 @@
1
+ import { PdfEngineContextState } from '../context';
2
+ /**
3
+ * Hook to access the PDF engine from context.
4
+ * @returns The PDF engine context state
5
+ * @throws Error if used outside of PdfEngineProvider
6
+ */
7
+ export declare function useEngineContext(): PdfEngineContextState;
8
+ /**
9
+ * Hook to access the PDF engine, with a more convenient API.
10
+ * @returns The PDF engine or null if loading/error
11
+ */
12
+ export declare function useEngine(): import('@embedpdf/models').PdfEngine<Blob> | null;
@@ -1 +1,2 @@
1
1
  export * from './hooks';
2
+ export * from './components';
@@ -0,0 +1 @@
1
+ export * from './pdf-engine-provider';
@@ -0,0 +1,16 @@
1
+ import { ReactNode } from '../../react/adapter.ts';
2
+ import { PdfEngine } from '@embedpdf/models';
3
+ export interface PdfEngineProviderProps {
4
+ children: ReactNode;
5
+ engine: PdfEngine | null;
6
+ isLoading: boolean;
7
+ error: Error | null;
8
+ }
9
+ /**
10
+ * Provider component that makes a PDF engine instance available
11
+ * to all child components via context.
12
+ *
13
+ * This provider is completely engine-agnostic - it accepts any engine
14
+ * and its loading state from the parent component.
15
+ */
16
+ export declare function PdfEngineProvider({ children, engine, isLoading, error }: PdfEngineProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './pdf-engine-context';
@@ -0,0 +1,7 @@
1
+ import { PdfEngine } from '@embedpdf/models';
2
+ export interface PdfEngineContextState {
3
+ engine: PdfEngine | null;
4
+ isLoading: boolean;
5
+ error: Error | null;
6
+ }
7
+ export declare const PdfEngineContext: import('react').Context<PdfEngineContextState | undefined>;
@@ -1 +1,2 @@
1
1
  export * from './use-pdfium-engine';
2
+ export * from './use-engine-context';
@@ -0,0 +1,12 @@
1
+ import { PdfEngineContextState } from '../context';
2
+ /**
3
+ * Hook to access the PDF engine from context.
4
+ * @returns The PDF engine context state
5
+ * @throws Error if used outside of PdfEngineProvider
6
+ */
7
+ export declare function useEngineContext(): PdfEngineContextState;
8
+ /**
9
+ * Hook to access the PDF engine, with a more convenient API.
10
+ * @returns The PDF engine or null if loading/error
11
+ */
12
+ export declare function useEngine(): import('@embedpdf/models').PdfEngine<Blob> | null;
@@ -1 +1,2 @@
1
1
  export * from './hooks';
2
+ export * from './components';
@@ -0,0 +1 @@
1
+ export { default as PdfEngineProvider } from './pdf-engine-provider.vue';
@@ -0,0 +1,18 @@
1
+ import { PdfEngine } from '@embedpdf/models';
2
+ interface Props {
3
+ engine: PdfEngine | null;
4
+ isLoading: boolean;
5
+ error: Error | null;
6
+ }
7
+ declare var __VLS_1: {};
8
+ type __VLS_Slots = {} & {
9
+ default?: (props: typeof __VLS_1) => any;
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>;
13
+ export default _default;
14
+ type __VLS_WithSlots<T, S> = T & {
15
+ new (): {
16
+ $slots: S;
17
+ };
18
+ };
@@ -0,0 +1,2 @@
1
+ export * from './use-engine-context';
2
+ export * from './use-pdfium-engine';
@@ -0,0 +1,12 @@
1
+ import { PdfEngineContextState } from '../context/pdf-engine-context';
2
+ /**
3
+ * Composable to access the PDF engine from context.
4
+ * @returns The PDF engine context state
5
+ * @throws Error if used outside of PdfEngineProvider
6
+ */
7
+ export declare function useEngineContext(): PdfEngineContextState;
8
+ /**
9
+ * Composable to access the PDF engine, with a more convenient API.
10
+ * @returns The PDF engine or null if loading/error
11
+ */
12
+ export declare function useEngine(): import('vue').Ref<import('@embedpdf/models').PdfEngine<Blob> | null, import('@embedpdf/models').PdfEngine<Blob> | null>;
@@ -0,0 +1,8 @@
1
+ import { InjectionKey, Ref } from 'vue';
2
+ import { PdfEngine } from '@embedpdf/models';
3
+ export interface PdfEngineContextState {
4
+ engine: Ref<PdfEngine | null>;
5
+ isLoading: Ref<boolean>;
6
+ error: Ref<Error | null>;
7
+ }
8
+ export declare const pdfEngineKey: InjectionKey<PdfEngineContextState>;
@@ -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"),t="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@1.0.26/dist/pdfium.wasm";exports.usePdfiumEngine=function(n={}){const{wasmUrl:r=t,worker:o=!0,logger:i}=n,u=e.ref(null),a=e.ref(!0),l=e.ref(null);async function c(){try{const{createPdfiumEngine:e}=o?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine");u.value=await e(r,i),a.value=!1}catch(e){l.value=e,a.value=!1}}function d(){var e,t;null==(t=null==(e=u.value)?void 0:e.destroy)||t.call(e),u.value=null,a.value=!0,l.value=null}return e.onMounted(c),e.onBeforeUnmount(d),e.watch((()=>[r,o,i]),(()=>{d(),c()})),{engine:u,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@1.1.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/hooks/use-pdfium-engine.ts"],"sourcesContent":["import { ref, onMounted, onBeforeUnmount, watch, Ref } from 'vue';\nimport type { Logger, 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 engine.value = await createPdfiumEngine(wasmUrl, logger);\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?.destroy?.();\n engine.value = null;\n isLoading.value = true;\n error.value = null;\n }\n\n return { engine, isLoading, error };\n}\n"],"names":["defaultWasmUrl","props","wasmUrl","worker","logger","engine","ref","isLoading","error","async","loadEngine","createPdfiumEngine","import","value","e","destroyEngine","_b","_a","destroy","call","onMounted","onBeforeUnmount","vue","watch"],"mappings":"4PAGMA,EACJ,gGAkBc,SAAgBC,EAA8B,IAC5D,MAAMC,QAAEA,EAAUF,EAAAG,OAAgBA,GAAS,EAAAC,OAAMA,GAAWH,EAEtDI,EAASC,MAAsB,MAC/BC,EAAYD,OAAI,GAChBE,EAAQF,MAAkB,MAehCG,eAAeC,IACT,IACI,MAAAC,mBAAEA,GAAuBR,QACrBS,OAAO,gDACPA,OAAO,0CAEjBP,EAAOQ,YAAcF,EAAmBT,EAASE,GACjDG,EAAUM,OAAQ,QACXC,GACPN,EAAMK,MAAQC,EACdP,EAAUM,OAAQ,CAAA,CACpB,CAGF,SAASE,YACP,OAAOC,EAAP,OAAOC,EAAAZ,EAAAQ,gBAAOK,UAAdF,EAAAG,KAAAF,GACAZ,EAAOQ,MAAQ,KACfN,EAAUM,OAAQ,EAClBL,EAAMK,MAAQ,IAAA,CAGT,OAjCPO,EAAAA,UAAUV,GACVW,EAAAA,gBAAgBN,GAGhBO,EAAAC,OACE,IAAM,CAACrB,EAASC,EAAQC,KACxB,KACgBW,IACHL,GAAA,IAyBR,CAAEL,SAAQE,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","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 +1,2 @@
1
- export * from './hooks';
1
+ export * from './composables';
2
+ export * from './components';
package/dist/vue/index.js CHANGED
@@ -1,5 +1,21 @@
1
- import { ref, onMounted, onBeforeUnmount, watch } from "vue";
2
- const defaultWasmUrl = "https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@1.0.26/dist/pdfium.wasm";
1
+ import { inject, ref, onMounted, onBeforeUnmount, watch, defineComponent, toRefs, provide, renderSlot } from "vue";
2
+ import { ignore } from "@embedpdf/models";
3
+ const pdfEngineKey = Symbol("pdfEngineKey");
4
+ function useEngineContext() {
5
+ const contextValue = inject(pdfEngineKey);
6
+ if (!contextValue) {
7
+ throw new Error("useEngineContext must be used within a PdfEngineProvider");
8
+ }
9
+ return contextValue;
10
+ }
11
+ function useEngine() {
12
+ const { engine, error } = useEngineContext();
13
+ if (error.value) {
14
+ throw error.value;
15
+ }
16
+ return engine;
17
+ }
18
+ const defaultWasmUrl = "https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@1.1.0/dist/pdfium.wasm";
3
19
  function usePdfiumEngine(props = {}) {
4
20
  const { wasmUrl = defaultWasmUrl, worker = true, logger } = props;
5
21
  const engine = ref(null);
@@ -17,7 +33,17 @@ function usePdfiumEngine(props = {}) {
17
33
  async function loadEngine() {
18
34
  try {
19
35
  const { createPdfiumEngine } = worker ? await import("@embedpdf/engines/pdfium-worker-engine") : await import("@embedpdf/engines/pdfium-direct-engine");
20
- engine.value = await createPdfiumEngine(wasmUrl, logger);
36
+ const pdfEngine = await createPdfiumEngine(wasmUrl, logger);
37
+ pdfEngine.initialize().wait(
38
+ () => {
39
+ isLoading.value = false;
40
+ engine.value = pdfEngine;
41
+ },
42
+ (e) => {
43
+ error.value = new Error(e.reason.message);
44
+ isLoading.value = false;
45
+ }
46
+ );
21
47
  isLoading.value = false;
22
48
  } catch (e) {
23
49
  error.value = e;
@@ -26,14 +52,38 @@ function usePdfiumEngine(props = {}) {
26
52
  }
27
53
  function destroyEngine() {
28
54
  var _a, _b;
29
- (_b = (_a = engine.value) == null ? void 0 : _a.destroy) == null ? void 0 : _b.call(_a);
30
- engine.value = null;
31
- isLoading.value = true;
32
- error.value = null;
55
+ (_b = (_a = engine.value) == null ? void 0 : _a.closeAllDocuments) == null ? void 0 : _b.call(_a).wait(() => {
56
+ var _a2, _b2;
57
+ (_b2 = (_a2 = engine.value) == null ? void 0 : _a2.destroy) == null ? void 0 : _b2.call(_a2);
58
+ engine.value = null;
59
+ }, ignore);
33
60
  }
34
61
  return { engine, isLoading, error };
35
62
  }
63
+ const _sfc_main = /* @__PURE__ */ defineComponent({
64
+ __name: "pdf-engine-provider",
65
+ props: {
66
+ engine: {},
67
+ isLoading: { type: Boolean },
68
+ error: {}
69
+ },
70
+ setup(__props) {
71
+ const props = __props;
72
+ const { engine, isLoading, error } = toRefs(props);
73
+ provide(pdfEngineKey, {
74
+ engine,
75
+ isLoading,
76
+ error
77
+ });
78
+ return (_ctx, _cache) => {
79
+ return renderSlot(_ctx.$slots, "default");
80
+ };
81
+ }
82
+ });
36
83
  export {
84
+ _sfc_main as PdfEngineProvider,
85
+ useEngine,
86
+ useEngineContext,
37
87
  usePdfiumEngine
38
88
  };
39
89
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-pdfium-engine.ts"],"sourcesContent":["import { ref, onMounted, onBeforeUnmount, watch, Ref } from 'vue';\nimport type { Logger, 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 engine.value = await createPdfiumEngine(wasmUrl, logger);\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?.destroy?.();\n engine.value = null;\n isLoading.value = true;\n error.value = null;\n }\n\n return { engine, isLoading, error };\n}\n"],"names":[],"mappings":";AAGA,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,aAAO,QAAQ,MAAM,mBAAmB,SAAS,MAAM;AACvD,gBAAU,QAAQ;AAAA,aACX,GAAG;AACV,YAAM,QAAQ;AACd,gBAAU,QAAQ;AAAA,IAAA;AAAA,EACpB;AAGF,WAAS,gBAAgB;;AACvB,uBAAO,UAAP,mBAAc,YAAd;AACA,WAAO,QAAQ;AACf,cAAU,QAAQ;AAClB,UAAM,QAAQ;AAAA,EAAA;AAGT,SAAA,EAAE,QAAQ,WAAW,MAAM;AACpC;"}
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;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/engines",
3
- "version": "1.0.26",
3
+ "version": "1.1.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",
@@ -82,8 +82,8 @@
82
82
  "@embedpdf/build": "1.0.0"
83
83
  },
84
84
  "dependencies": {
85
- "@embedpdf/pdfium": "1.0.26",
86
- "@embedpdf/models": "1.0.26"
85
+ "@embedpdf/models": "1.1.0",
86
+ "@embedpdf/pdfium": "1.1.0"
87
87
  },
88
88
  "peerDependencies": {
89
89
  "react": ">=16.8.0",