@embedpdf/engines 2.0.0-next.3 → 2.0.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/README.md +15 -9
  2. package/dist/browser-C6QEa8uk.cjs +2 -0
  3. package/dist/browser-C6QEa8uk.cjs.map +1 -0
  4. package/dist/{browser-Cm3DA8l_.js → browser-awZxztMA.js} +28 -22
  5. package/dist/browser-awZxztMA.js.map +1 -0
  6. package/dist/{direct-engine-BZRK27cv.js → direct-engine-DuLFAbiv.js} +23 -21
  7. package/dist/direct-engine-DuLFAbiv.js.map +1 -0
  8. package/dist/direct-engine-JeNRkc7w.cjs +2 -0
  9. package/dist/direct-engine-JeNRkc7w.cjs.map +1 -0
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.js +65 -48
  13. package/dist/index.js.map +1 -1
  14. package/dist/lib/converters/browser.d.ts +15 -14
  15. package/dist/lib/converters/index.cjs +1 -1
  16. package/dist/lib/converters/index.cjs.map +1 -1
  17. package/dist/lib/converters/index.js +2 -2
  18. package/dist/lib/orchestrator/pdf-engine.d.ts +0 -1
  19. package/dist/lib/orchestrator/remote-executor.d.ts +0 -1
  20. package/dist/lib/pdfium/engine.d.ts +2 -9
  21. package/dist/lib/pdfium/index.cjs +1 -1
  22. package/dist/lib/pdfium/index.cjs.map +1 -1
  23. package/dist/lib/pdfium/index.d.ts +1 -0
  24. package/dist/lib/pdfium/index.js +6 -4
  25. package/dist/lib/pdfium/index.js.map +1 -1
  26. package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
  27. package/dist/lib/pdfium/web/direct-engine.js +3 -3
  28. package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
  29. package/dist/lib/pdfium/web/worker-engine.cjs.map +1 -1
  30. package/dist/lib/pdfium/web/worker-engine.js +4 -7
  31. package/dist/lib/pdfium/web/worker-engine.js.map +1 -1
  32. package/dist/lib/webworker/engine.cjs +1 -1
  33. package/dist/lib/webworker/engine.cjs.map +1 -1
  34. package/dist/lib/webworker/engine.d.ts +0 -6
  35. package/dist/lib/webworker/engine.js +0 -13
  36. package/dist/lib/webworker/engine.js.map +1 -1
  37. package/dist/{pdf-engine-yZzBqL_l.js → pdf-engine-BVNF_Yo9.js} +6 -14
  38. package/dist/pdf-engine-BVNF_Yo9.js.map +1 -0
  39. package/dist/pdf-engine-C3JeKij1.cjs +2 -0
  40. package/dist/pdf-engine-C3JeKij1.cjs.map +1 -0
  41. package/dist/preact/index.cjs +1 -1
  42. package/dist/preact/index.cjs.map +1 -1
  43. package/dist/preact/index.js +3 -11
  44. package/dist/preact/index.js.map +1 -1
  45. package/dist/react/index.cjs +1 -1
  46. package/dist/react/index.cjs.map +1 -1
  47. package/dist/react/index.js +3 -11
  48. package/dist/react/index.js.map +1 -1
  49. package/dist/svelte/index.cjs +1 -1
  50. package/dist/svelte/index.cjs.map +1 -1
  51. package/dist/svelte/index.js +2 -10
  52. package/dist/svelte/index.js.map +1 -1
  53. package/dist/vue/index.cjs +1 -1
  54. package/dist/vue/index.cjs.map +1 -1
  55. package/dist/vue/index.js +2 -11
  56. package/dist/vue/index.js.map +1 -1
  57. package/package.json +3 -3
  58. package/dist/browser-B5Y-F6il.cjs +0 -2
  59. package/dist/browser-B5Y-F6il.cjs.map +0 -1
  60. package/dist/browser-Cm3DA8l_.js.map +0 -1
  61. package/dist/direct-engine-BZRK27cv.js.map +0 -1
  62. package/dist/direct-engine-CZAhOupl.cjs +0 -2
  63. package/dist/direct-engine-CZAhOupl.cjs.map +0 -1
  64. package/dist/pdf-engine-CrarIjJ6.cjs +0 -2
  65. package/dist/pdf-engine-CrarIjJ6.cjs.map +0 -1
  66. package/dist/pdf-engine-yZzBqL_l.js.map +0 -1
@@ -2,7 +2,7 @@ import { useState, useRef, useEffect, useContext } from "preact/hooks";
2
2
  import { createContext } from "preact";
3
3
  import { ignore } from "@embedpdf/models";
4
4
  import { jsx } from "preact/jsx-runtime";
5
- const defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.0-next.3/dist/pdfium.wasm`;
5
+ const defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.0/dist/pdfium.wasm`;
6
6
  function usePdfiumEngine(config) {
7
7
  const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = config ?? {};
8
8
  const [engine, setEngine] = useState(null);
@@ -16,16 +16,8 @@ function usePdfiumEngine(config) {
16
16
  const { createPdfiumEngine } = worker ? await import("@embedpdf/engines/pdfium-worker-engine") : await import("@embedpdf/engines/pdfium-direct-engine");
17
17
  const pdfEngine = await createPdfiumEngine(wasmUrl, { logger, encoderPoolSize });
18
18
  engineRef.current = pdfEngine;
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
- );
19
+ setEngine(pdfEngine);
20
+ setLoading(false);
29
21
  } catch (e) {
30
22
  if (!cancelled) {
31
23
  setError(e);
@@ -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 encoderPoolSize?: number;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = 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, encoderPoolSize });\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;AAShB,SAAS,gBAAgB,QAA+B;AAC7D,QAAM,EAAE,UAAU,gBAAgB,SAAS,MAAM,QAAQ,oBAAoB,UAAU,CAAA;AAEvF,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,EAAE,QAAQ,iBAAiB;AAC/E,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;AClDO,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
+ {"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 encoderPoolSize?: number;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = 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, encoderPoolSize });\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?.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;AAShB,SAAS,gBAAgB,QAA+B;AAC7D,QAAM,EAAE,UAAU,gBAAgB,SAAS,MAAM,QAAQ,oBAAoB,UAAU,CAAA;AAEvF,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,EAAE,QAAQ,iBAAiB;AAC/E,kBAAU,UAAU;AACpB,kBAAU,SAAS;AACnB,mBAAW,KAAK;AAAA,MAClB,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;AC1CO,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("react"),r=require("@embedpdf/models"),t=require("react/jsx-runtime"),n="https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.0-next.3/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,encoderPoolSize:u}=t??{},[c,d]=e.useState(null),[l,a]=e.useState(!0),[g,p]=e.useState(null),f=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,{logger:s,encoderPoolSize:u});f.current=r,r.initialize().wait(()=>{d(r),a(!1)},e=>{p(new Error(e.reason.message)),a(!1)})}catch(r){e||(p(r),a(!1))}})(),()=>{var t,n;e=!0,null==(n=null==(t=f.current)?void 0:t.closeAllDocuments)||n.call(t).wait(()=>{var e,r;null==(r=null==(e=f.current)?void 0:e.destroy)||r.call(e),f.current=null},r.ignore)}},[i,o,s]),{engine:c,isLoading:l,error:g}};
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/dist/pdfium.wasm";const o=e.createContext(void 0);function i(){const r=e.useContext(o);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:i}){const u={engine:r,isLoading:n,error:i};return t.jsx(o.Provider,{value:u,children:e})},exports.useEngine=function(){const{engine:e,error:r}=i();if(r)throw r;return e},exports.useEngineContext=i,exports.usePdfiumEngine=function(t){const{wasmUrl:o=n,worker:i=!0,logger:u,encoderPoolSize:s}=t??{},[c,d]=e.useState(null),[l,a]=e.useState(!0),[g,p]=e.useState(null),f=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"),r=await e(o,{logger:u,encoderPoolSize:s});f.current=r,d(r),a(!1)}catch(r){e||(p(r),a(!1))}})(),()=>{var t,n;e=!0,null==(n=null==(t=f.current)?void 0:t.closeAllDocuments)||n.call(t).wait(()=>{var e,r;null==(r=null==(e=f.current)?void 0:e.destroy)||r.call(e),f.current=null},r.ignore)}},[o,i,u]),{engine:c,isLoading:l,error:g}};
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 encoderPoolSize?: number;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = 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, encoderPoolSize });\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","encoderPoolSize","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,qDFlBO,SAAyBK,GAC9B,MAAMC,QAAEA,EAAUd,EAAAe,OAAgBA,GAAS,SAAMC,EAAAC,gBAAQA,GAAoBJ,GAAU,CAAA,GAEhFL,EAAQU,GAAaC,EAAAA,SAA2B,OAChDC,EAASC,GAAcF,EAAAA,UAAS,IAChCT,EAAOY,GAAYH,EAAAA,SAAuB,MAC3CI,EAAYC,EAAAA,OAAyB,MAwC3C,OAtCAC,EAAAA,UAAU,KACR,IAAIC,GAAY,EA4BhB,MA1BA,WACE,IACE,MAAMC,mBAAEA,GAAuBZ,QACrBa,OAAO,gDACPA,OAAO,0CAEXC,QAAkBF,EAAmBb,EAAS,CAAEE,SAAQC,oBAC9DM,EAAUO,QAAUD,EACpBA,EAAUE,aAAaC,KACrB,KACEd,EAAUW,GACVR,GAAW,IAEZY,IACCX,EAAS,IAAIhB,MAAM2B,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,CAAC3B,EAASC,EAAQC,IAEd,CAAER,SAAQC,UAAWW,EAASV,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 encoderPoolSize?: number;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = 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, encoderPoolSize });\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?.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","encoderPoolSize","setEngine","useState","loading","setLoading","setError","engineRef","useRef","useEffect","cancelled","createPdfiumEngine","import","pdfEngine","current","e","_b","_a","closeAllDocuments","call","wait","destroy","ignore"],"mappings":"2TAGMA,EAAiB,uECMhB,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,qDFlBO,SAAyBK,GAC9B,MAAMC,QAAEA,EAAUd,EAAAe,OAAgBA,GAAS,SAAMC,EAAAC,gBAAQA,GAAoBJ,GAAU,CAAA,GAEhFL,EAAQU,GAAaC,EAAAA,SAA2B,OAChDC,EAASC,GAAcF,EAAAA,UAAS,IAChCT,EAAOY,GAAYH,EAAAA,SAAuB,MAC3CI,EAAYC,EAAAA,OAAyB,MAgC3C,OA9BAC,EAAAA,UAAU,KACR,IAAIC,GAAY,EAoBhB,MAlBA,WACE,IACE,MAAMC,mBAAEA,GAAuBZ,QACrBa,OAAO,gDACPA,OAAO,0CAEXC,QAAkBF,EAAmBb,EAAS,CAAEE,SAAQC,oBAC9DM,EAAUO,QAAUD,EACpBX,EAAUW,GACVR,GAAW,EACb,OAASU,GACFL,IACHJ,EAASS,GACTV,GAAW,GAEf,CACF,EAhBA,GAkBO,aACLK,GAAY,EACZ,OAAAM,EAAA,OAAAC,EAAAV,EAAUO,cAAV,EAAAG,EAAmBC,oBAAnBF,EAAAG,KAAAF,GAAyCG,KAAK,aAC5C,OAAAJ,EAAA,OAAAC,EAAAV,EAAUO,gBAAVG,EAAmBI,UAAnBL,EAAAG,KAAAF,GACAV,EAAUO,QAAU,MACnBQ,EAAAA,UAEJ,CAACxB,EAASC,EAAQC,IAEd,CAAER,SAAQC,UAAWW,EAASV,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@2.0.0-next.3/dist/pdfium.wasm`;
4
+ const defaultWasmUrl = `https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.0/dist/pdfium.wasm`;
5
5
  function usePdfiumEngine(config) {
6
6
  const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = config ?? {};
7
7
  const [engine, setEngine] = useState(null);
@@ -15,16 +15,8 @@ function usePdfiumEngine(config) {
15
15
  const { createPdfiumEngine } = worker ? await import("@embedpdf/engines/pdfium-worker-engine") : await import("@embedpdf/engines/pdfium-direct-engine");
16
16
  const pdfEngine = await createPdfiumEngine(wasmUrl, { logger, encoderPoolSize });
17
17
  engineRef.current = pdfEngine;
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
+ setEngine(pdfEngine);
19
+ setLoading(false);
28
20
  } catch (e) {
29
21
  if (!cancelled) {
30
22
  setError(e);
@@ -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 encoderPoolSize?: number;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = 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, encoderPoolSize });\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;AAShB,SAAS,gBAAgB,QAA+B;AAC7D,QAAM,EAAE,UAAU,gBAAgB,SAAS,MAAM,QAAQ,oBAAoB,UAAU,CAAA;AAEvF,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,EAAE,QAAQ,iBAAiB;AAC/E,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;AClDO,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
+ {"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 encoderPoolSize?: number;\n}\n\nexport function usePdfiumEngine(config?: UsePdfiumEngineProps) {\n const { wasmUrl = defaultWasmUrl, worker = true, logger, encoderPoolSize } = 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, encoderPoolSize });\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?.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;AAShB,SAAS,gBAAgB,QAA+B;AAC7D,QAAM,EAAE,UAAU,gBAAgB,SAAS,MAAM,QAAQ,oBAAoB,UAAU,CAAA;AAEvF,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,EAAE,QAAQ,iBAAiB;AAC/E,kBAAU,UAAU;AACpB,kBAAU,SAAS;AACnB,mBAAW,KAAK;AAAA,MAClB,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;AC1CO,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 l(){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}=l();if(n)throw n;return e},exports.useEngineContext=function(){const e=l();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??{},l=o.proxy({engine:null,isLoading:!0,error:null});let u=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,{logger:s});o.set(u,t,!0),t.initialize().wait(()=>{l.engine=t,l.isLoading=!1},e=>{l.error=new Error(e.reason.message),l.isLoading=!1})}catch(t){e||(l.error=t,l.isLoading=!1)}})(),()=>{var n,r;e=!0,null==(r=null==(n=o.get(u))?void 0:n.closeAllDocuments)||r.call(n).wait(()=>{var e,n;null==(n=null==(e=o.get(u))?void 0:e.destroy)||n.call(e),o.set(u,null)},t.ignore)}}),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("svelte/internal/client"),t=require("svelte"),n=require("@embedpdf/models"),r=require("@embedpdf/engines");function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}require("svelte/internal/disclose-version");const o=i(e),s=Symbol("pdfEngineContext");function u(){const e=t.getContext(s);if(void 0===e)throw new Error("getPdfEngineContext must be used within a PdfEngineProvider");return e}exports.PdfEngineProvider=function(e,n){o.push(n,!0),o.user_effect(()=>{var e;e={engine:n.engine,isLoading:n.isLoading,error:n.error},t.setContext(s,e)});var r=o.comment(),i=o.first_child(r);o.snippet(i,()=>n.children),o.append(e,r),o.pop()},exports.useEngine=function(){const{engine:e,error:t}=u();if(t)throw t;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:t=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"),n=await e(t,{logger:s});o.set(l,n,!0),u.engine=n,u.isLoading=!1}catch(n){e||(u.error=n,u.isLoading=!1)}})(),()=>{var t,r;e=!0,null==(r=null==(t=o.get(l))?void 0:t.closeAllDocuments)||r.call(t).wait(()=>{var e,t;null==(t=null==(e=o.get(l))?void 0:e.destroy)||t.call(e),o.set(l,null)},n.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\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,GAAWG,WACtDb,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
+ {"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 state.engine = pdfEngine;\n state.isLoading = false;\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","e","closeAllDocuments","wait","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,GAAWG,WACtDb,EAAAoB,IAAAL,EAAYI,GAAA,GACZL,EAAMX,OAASgB,EACfL,EAAMT,WAAY,CACpB,OAASgB,GACFJ,IACHH,EAAMR,MAAQe,EACdP,EAAMT,WAAY,EAEtB,CACF,kBAGEY,GAAY,0BACZF,aAAWO,8BAAsBC,kBAC/BvB,OAAAA,EAAAA,OAAAA,EAAAA,EAAAwB,IAAAT,SAAAf,EAAAA,EAAWyB,UAAXzB,EAAAA,KAAAA,GACAA,EAAAoB,IAAAL,EAAY,OACXW,EAAAA,WAMFZ,CACT"}
@@ -41,16 +41,8 @@ function usePdfiumEngine(config) {
41
41
  const { createPdfiumEngine } = worker ? await import("@embedpdf/engines/pdfium-worker-engine") : await import("@embedpdf/engines/pdfium-direct-engine");
42
42
  const pdfEngine = await createPdfiumEngine(wasmUrl, { logger });
43
43
  $.set(engineRef, pdfEngine, true);
44
- pdfEngine.initialize().wait(
45
- () => {
46
- state.engine = pdfEngine;
47
- state.isLoading = false;
48
- },
49
- (e) => {
50
- state.error = new Error(e.reason.message);
51
- state.isLoading = false;
52
- }
53
- );
44
+ state.engine = pdfEngine;
45
+ state.isLoading = false;
54
46
  } catch (e) {
55
47
  if (!cancelled) {
56
48
  state.error = e;
@@ -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\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,kBAAkB,mBAAmB,WAAW;AACtD,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;"}
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 state.engine = pdfEngine;\n state.isLoading = false;\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,kBAAkB,mBAAmB,WAAW;AACtD,YAAA,IAAA,WAAY,WAAA,IAAA;AACZ,gBAAM,SAAS;AACf,gBAAM,YAAY;AAAA,QACpB,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;8CCzDA;;AAeE,IAAA,YAAO,MAAO;AACZ,wBAAmB;AAAA,MACjB,QAAM,QAAA;AAAA,MACN,WAAS,QAAA;AAAA,MACT,OAAK,QAAA;AAAA;EAET,CAAC;;;;;;AACH;"}
@@ -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@2.0.0-next.3/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),l=e.ref(!0),a=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,{logger:u});n.initialize().wait(()=>{l.value=!1,s.value=n},e=>{a.value=new Error(e.reason.message),l.value=!1}),l.value=!1}catch(e){a.value=e,l.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:l,error:a}};
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/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),l=e.ref(!0),d=e.ref(null);async function a(){try{const{createPdfiumEngine:e}=i?await import("@embedpdf/engines/pdfium-worker-engine"):await import("@embedpdf/engines/pdfium-direct-engine"),n=await e(t,{logger:u});s.value=n,l.value=!1}catch(e){d.value=e,l.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(a),e.onBeforeUnmount(c),e.watch(()=>[t,i,u],()=>{c(),a()}),{engine:s,isLoading:l,error:d}};
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","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,EAAS,CAAEE,WACtDM,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"}
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 engine.value = pdfEngine;\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","e","destroyEngine","_b","_a","closeAllDocuments","call","wait","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,4LCOF,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,EAAS,CAAEE,WACtDX,EAAOQ,MAAQS,EACfhB,EAAUO,OAAQ,CACpB,OAASU,GACPhB,EAAMM,MAAQU,EACdjB,EAAUO,OAAQ,CACpB,CACF,CAEA,SAASW,YACP,OAAAC,EAAA,OAAAC,EAAArB,EAAOQ,YAAP,EAAAa,EAAcC,oBAAdF,EAAAG,KAAAF,GAAoCG,KAAK,aACvC,OAAAJ,EAAA,OAAAC,EAAArB,EAAOQ,cAAPa,EAAcI,UAAdL,EAAAG,KAAAF,GACArB,EAAOQ,MAAQ,MACdkB,EAAAA,OACL,CAEA,OAlCAC,EAAAA,UAAUb,GACVc,EAAAA,gBAAgBT,GAGhBU,EAAAA,MACE,IAAM,CAACpB,EAASC,EAAQC,GACxB,KACEQ,IACAL,MA0BG,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@2.0.0-next.3/dist/pdfium.wasm";
18
+ const defaultWasmUrl = "https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.0.0/dist/pdfium.wasm";
19
19
  function usePdfiumEngine(props = {}) {
20
20
  const { wasmUrl = defaultWasmUrl, worker = true, logger } = props;
21
21
  const engine = ref(null);
@@ -34,16 +34,7 @@ function usePdfiumEngine(props = {}) {
34
34
  try {
35
35
  const { createPdfiumEngine } = worker ? await import("@embedpdf/engines/pdfium-worker-engine") : await import("@embedpdf/engines/pdfium-direct-engine");
36
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
- );
37
+ engine.value = pdfEngine;
47
38
  isLoading.value = false;
48
39
  } catch (e) {
49
40
  error.value = e;
@@ -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":";;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,EAAE,QAAQ;AAC9D,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;;;"}
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 engine.value = pdfEngine;\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,EAAE,QAAQ;AAC9D,aAAO,QAAQ;AACf,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;;;;;;;;;ACtDA,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": "2.0.0-next.3",
3
+ "version": "2.0.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": "2.0.0-next.3",
92
- "@embedpdf/pdfium": "2.0.0-next.3"
91
+ "@embedpdf/pdfium": "2.0.0",
92
+ "@embedpdf/models": "2.0.0"
93
93
  },
94
94
  "peerDependencies": {
95
95
  "preact": "^10.26.4",
@@ -1,2 +0,0 @@
1
- "use strict";class e extends Error{constructor(e){super(e),this.name="OffscreenCanvasError"}}exports.OffscreenCanvasError=e,exports.browserImageDataToBlobConverter=(t,r="image/webp",a)=>{if("undefined"==typeof OffscreenCanvas)return Promise.reject(new e("OffscreenCanvas is not available in this environment. This converter is intended for browser use only. Falling back to WASM-based image encoding."));const n=t(),o=new ImageData(n.data,n.width,n.height),i=new OffscreenCanvas(o.width,o.height);return i.getContext("2d").putImageData(o,0,0),i.convertToBlob({type:r,quality:a})},exports.createHybridImageConverter=function(e,t){return async(r,a="image/webp",n)=>{const o=r();try{const t=new Uint8ClampedArray(o.data);return await e.encode({data:t,width:o.width,height:o.height},a,n)}catch(i){return console.warn("Worker pool encoding failed, falling back to WASM:",i),t({data:o.data,width:o.width,height:o.height},a,n)}}},exports.createWorkerPoolImageConverter=function(e){return(t,r="image/webp",a)=>{const n=t(),o=new Uint8ClampedArray(n.data);return e.encode({data:o,width:n.width,height:n.height},r,a)}};
2
- //# sourceMappingURL=browser-B5Y-F6il.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser-B5Y-F6il.cjs","sources":["../src/lib/converters/browser.ts"],"sourcesContent":["import type { ImageConversionTypes } from '@embedpdf/models';\nimport type { ImageDataConverter, LazyImageData } from './types';\nimport { ImageEncoderWorkerPool } from '../image-encoder';\n\n// ============================================================================\n// Error Classes\n// ============================================================================\n\nexport class OffscreenCanvasError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'OffscreenCanvasError';\n }\n}\n\n// ============================================================================\n// Browser Converters\n// ============================================================================\n\n/**\n * Browser-based image converter using OffscreenCanvas in the same thread\n * This is the simplest approach but blocks the thread during encoding\n */\nexport const browserImageDataToBlobConverter: ImageDataConverter<Blob> = (\n getImageData: LazyImageData,\n imageType: ImageConversionTypes = 'image/webp',\n quality?: number,\n): Promise<Blob> => {\n // Check if we're in a browser environment\n if (typeof OffscreenCanvas === 'undefined') {\n return Promise.reject(\n new OffscreenCanvasError(\n 'OffscreenCanvas is not available in this environment. ' +\n 'This converter is intended for browser use only. ' +\n 'Falling back to WASM-based image encoding.',\n ),\n );\n }\n\n const pdfImage = getImageData();\n const imageData = new ImageData(pdfImage.data, pdfImage.width, pdfImage.height);\n const off = new OffscreenCanvas(imageData.width, imageData.height);\n off.getContext('2d')!.putImageData(imageData, 0, 0);\n return off.convertToBlob({ type: imageType, quality });\n};\n\n/**\n * Create an image converter that uses a dedicated worker pool for encoding\n * This prevents blocking the main/PDFium worker thread\n *\n * @param workerPool - Instance of ImageEncoderWorkerPool\n * @returns ImageDataConverter function\n */\nexport function createWorkerPoolImageConverter(\n workerPool: ImageEncoderWorkerPool,\n): ImageDataConverter<Blob> {\n return (\n getImageData: LazyImageData,\n imageType: ImageConversionTypes = 'image/webp',\n quality?: number,\n ): Promise<Blob> => {\n const pdfImage = getImageData();\n\n // Copy the data since we'll transfer it to another worker\n const dataCopy = new Uint8ClampedArray(pdfImage.data);\n\n return workerPool.encode(\n {\n data: dataCopy,\n width: pdfImage.width,\n height: pdfImage.height,\n },\n imageType,\n quality,\n );\n };\n}\n\n/**\n * Hybrid converter: tries worker pool first, falls back to WASM encoding\n * This provides the best performance with graceful degradation\n *\n * @param workerPool - Instance of ImageEncoderWorkerPool\n * @param wasmFallback - WASM-based encoding function\n * @returns ImageDataConverter function\n */\nexport function createHybridImageConverter(\n workerPool: ImageEncoderWorkerPool,\n wasmFallback: (\n imageData: { data: Uint8ClampedArray; width: number; height: number },\n imageType: ImageConversionTypes,\n quality?: number,\n ) => Blob,\n): ImageDataConverter<Blob> {\n return async (\n getImageData: LazyImageData,\n imageType: ImageConversionTypes = 'image/webp',\n quality?: number,\n ): Promise<Blob> => {\n const pdfImage = getImageData();\n\n try {\n // Try worker pool encoding first\n const dataCopy = new Uint8ClampedArray(pdfImage.data);\n return await workerPool.encode(\n {\n data: dataCopy,\n width: pdfImage.width,\n height: pdfImage.height,\n },\n imageType,\n quality,\n );\n } catch (error) {\n // Fallback to WASM encoding\n console.warn('Worker pool encoding failed, falling back to WASM:', error);\n return wasmFallback(\n {\n data: pdfImage.data,\n width: pdfImage.width,\n height: pdfImage.height,\n },\n imageType,\n quality,\n );\n }\n };\n}\n"],"names":["OffscreenCanvasError","Error","constructor","message","super","this","name","getImageData","imageType","quality","OffscreenCanvas","Promise","reject","pdfImage","imageData","ImageData","data","width","height","off","getContext","putImageData","convertToBlob","type","workerPool","wasmFallback","async","dataCopy","Uint8ClampedArray","encode","error","console","warn"],"mappings":"aAQO,MAAMA,UAA6BC,MACxC,WAAAC,CAAYC,GACVC,MAAMD,GACNE,KAAKC,KAAO,sBACd,yEAWuE,CACvEC,EACAC,EAAkC,aAClCC,KAGA,GAA+B,oBAApBC,gBACT,OAAOC,QAAQC,OACb,IAAIZ,EACF,sJAON,MAAMa,EAAWN,IACXO,EAAY,IAAIC,UAAUF,EAASG,KAAMH,EAASI,MAAOJ,EAASK,QAClEC,EAAM,IAAIT,gBAAgBI,EAAUG,MAAOH,EAAUI,QAE3D,OADAC,EAAIC,WAAW,MAAOC,aAAaP,EAAW,EAAG,GAC1CK,EAAIG,cAAc,CAAEC,KAAMf,EAAWC,gDA2CvC,SACLe,EACAC,GAMA,OAAOC,MACLnB,EACAC,EAAkC,aAClCC,KAEA,MAAMI,EAAWN,IAEjB,IAEE,MAAMoB,EAAW,IAAIC,kBAAkBf,EAASG,MAChD,aAAaQ,EAAWK,OACtB,CACEb,KAAMW,EACNV,MAAOJ,EAASI,MAChBC,OAAQL,EAASK,QAEnBV,EACAC,EAEJ,OAASqB,GAGP,OADAC,QAAQC,KAAK,qDAAsDF,GAC5DL,EACL,CACET,KAAMH,EAASG,KACfC,MAAOJ,EAASI,MAChBC,OAAQL,EAASK,QAEnBV,EACAC,EAEJ,EAEJ,yCA1EO,SACLe,GAEA,MAAO,CACLjB,EACAC,EAAkC,aAClCC,KAEA,MAAMI,EAAWN,IAGXoB,EAAW,IAAIC,kBAAkBf,EAASG,MAEhD,OAAOQ,EAAWK,OAChB,CACEb,KAAMW,EACNV,MAAOJ,EAASI,MAChBC,OAAQL,EAASK,QAEnBV,EACAC,GAGN"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser-Cm3DA8l_.js","sources":["../src/lib/converters/browser.ts"],"sourcesContent":["import type { ImageConversionTypes } from '@embedpdf/models';\nimport type { ImageDataConverter, LazyImageData } from './types';\nimport { ImageEncoderWorkerPool } from '../image-encoder';\n\n// ============================================================================\n// Error Classes\n// ============================================================================\n\nexport class OffscreenCanvasError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'OffscreenCanvasError';\n }\n}\n\n// ============================================================================\n// Browser Converters\n// ============================================================================\n\n/**\n * Browser-based image converter using OffscreenCanvas in the same thread\n * This is the simplest approach but blocks the thread during encoding\n */\nexport const browserImageDataToBlobConverter: ImageDataConverter<Blob> = (\n getImageData: LazyImageData,\n imageType: ImageConversionTypes = 'image/webp',\n quality?: number,\n): Promise<Blob> => {\n // Check if we're in a browser environment\n if (typeof OffscreenCanvas === 'undefined') {\n return Promise.reject(\n new OffscreenCanvasError(\n 'OffscreenCanvas is not available in this environment. ' +\n 'This converter is intended for browser use only. ' +\n 'Falling back to WASM-based image encoding.',\n ),\n );\n }\n\n const pdfImage = getImageData();\n const imageData = new ImageData(pdfImage.data, pdfImage.width, pdfImage.height);\n const off = new OffscreenCanvas(imageData.width, imageData.height);\n off.getContext('2d')!.putImageData(imageData, 0, 0);\n return off.convertToBlob({ type: imageType, quality });\n};\n\n/**\n * Create an image converter that uses a dedicated worker pool for encoding\n * This prevents blocking the main/PDFium worker thread\n *\n * @param workerPool - Instance of ImageEncoderWorkerPool\n * @returns ImageDataConverter function\n */\nexport function createWorkerPoolImageConverter(\n workerPool: ImageEncoderWorkerPool,\n): ImageDataConverter<Blob> {\n return (\n getImageData: LazyImageData,\n imageType: ImageConversionTypes = 'image/webp',\n quality?: number,\n ): Promise<Blob> => {\n const pdfImage = getImageData();\n\n // Copy the data since we'll transfer it to another worker\n const dataCopy = new Uint8ClampedArray(pdfImage.data);\n\n return workerPool.encode(\n {\n data: dataCopy,\n width: pdfImage.width,\n height: pdfImage.height,\n },\n imageType,\n quality,\n );\n };\n}\n\n/**\n * Hybrid converter: tries worker pool first, falls back to WASM encoding\n * This provides the best performance with graceful degradation\n *\n * @param workerPool - Instance of ImageEncoderWorkerPool\n * @param wasmFallback - WASM-based encoding function\n * @returns ImageDataConverter function\n */\nexport function createHybridImageConverter(\n workerPool: ImageEncoderWorkerPool,\n wasmFallback: (\n imageData: { data: Uint8ClampedArray; width: number; height: number },\n imageType: ImageConversionTypes,\n quality?: number,\n ) => Blob,\n): ImageDataConverter<Blob> {\n return async (\n getImageData: LazyImageData,\n imageType: ImageConversionTypes = 'image/webp',\n quality?: number,\n ): Promise<Blob> => {\n const pdfImage = getImageData();\n\n try {\n // Try worker pool encoding first\n const dataCopy = new Uint8ClampedArray(pdfImage.data);\n return await workerPool.encode(\n {\n data: dataCopy,\n width: pdfImage.width,\n height: pdfImage.height,\n },\n imageType,\n quality,\n );\n } catch (error) {\n // Fallback to WASM encoding\n console.warn('Worker pool encoding failed, falling back to WASM:', error);\n return wasmFallback(\n {\n data: pdfImage.data,\n width: pdfImage.width,\n height: pdfImage.height,\n },\n imageType,\n quality,\n );\n }\n };\n}\n"],"names":[],"mappings":"AAQO,MAAM,6BAA6B,MAAM;AAAA,EAC9C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAUO,MAAM,kCAA4D,CACvE,cACA,YAAkC,cAClC,YACkB;AAElB,MAAI,OAAO,oBAAoB,aAAa;AAC1C,WAAO,QAAQ;AAAA,MACb,IAAI;AAAA,QACF;AAAA,MAAA;AAAA,IAGF;AAAA,EAEJ;AAEA,QAAM,WAAW,aAAA;AACjB,QAAM,YAAY,IAAI,UAAU,SAAS,MAAM,SAAS,OAAO,SAAS,MAAM;AAC9E,QAAM,MAAM,IAAI,gBAAgB,UAAU,OAAO,UAAU,MAAM;AACjE,MAAI,WAAW,IAAI,EAAG,aAAa,WAAW,GAAG,CAAC;AAClD,SAAO,IAAI,cAAc,EAAE,MAAM,WAAW,SAAS;AACvD;AASO,SAAS,+BACd,YAC0B;AAC1B,SAAO,CACL,cACA,YAAkC,cAClC,YACkB;AAClB,UAAM,WAAW,aAAA;AAGjB,UAAM,WAAW,IAAI,kBAAkB,SAAS,IAAI;AAEpD,WAAO,WAAW;AAAA,MAChB;AAAA,QACE,MAAM;AAAA,QACN,OAAO,SAAS;AAAA,QAChB,QAAQ,SAAS;AAAA,MAAA;AAAA,MAEnB;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AACF;AAUO,SAAS,2BACd,YACA,cAK0B;AAC1B,SAAO,OACL,cACA,YAAkC,cAClC,YACkB;AAClB,UAAM,WAAW,aAAA;AAEjB,QAAI;AAEF,YAAM,WAAW,IAAI,kBAAkB,SAAS,IAAI;AACpD,aAAO,MAAM,WAAW;AAAA,QACtB;AAAA,UACE,MAAM;AAAA,UACN,OAAO,SAAS;AAAA,UAChB,QAAQ,SAAS;AAAA,QAAA;AAAA,QAEnB;AAAA,QACA;AAAA,MAAA;AAAA,IAEJ,SAAS,OAAO;AAEd,cAAQ,KAAK,sDAAsD,KAAK;AACxE,aAAO;AAAA,QACL;AAAA,UACE,MAAM,SAAS;AAAA,UACf,OAAO,SAAS;AAAA,UAChB,QAAQ,SAAS;AAAA,QAAA;AAAA,QAEnB;AAAA,QACA;AAAA,MAAA;AAAA,IAEJ;AAAA,EACF;AACF;"}