@embedpdf/plugin-print 1.0.20 → 1.0.21

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.
@@ -1,189 +1,62 @@
1
- import { usePlugin, useCapability } from "@embedpdf/core/preact";
2
- import { PrintPlugin } from "@embedpdf/plugin-print";
3
- import { jsx, jsxs } from "preact/jsx-runtime";
4
- import { createContext, render } from "preact";
5
- import { useRef, useState, useEffect, useContext } from "preact/hooks";
1
+ import { createPluginPackage } from "@embedpdf/core";
2
+ import { PrintPlugin, PrintPluginPackage as PrintPluginPackage$1 } from "@embedpdf/plugin-print";
3
+ export * from "@embedpdf/plugin-print";
4
+ import { jsx } from "preact/jsx-runtime";
5
+ import "preact";
6
+ import { useRef, useEffect } from "preact/hooks";
7
+ import { useCapability, usePlugin } from "@embedpdf/core/preact";
6
8
  const usePrintPlugin = () => usePlugin(PrintPlugin.id);
7
9
  const usePrintCapability = () => useCapability(PrintPlugin.id);
8
- const PrintContext = createContext(null);
9
- const PrintPage = ({ pageResult }) => {
10
- const [imageUrl, setImageUrl] = useState("");
10
+ function PrintFrame() {
11
+ const { provides: printCapability } = usePrintCapability();
12
+ const { plugin: printPlugin } = usePrintPlugin();
13
+ const iframeRef = useRef(null);
14
+ const urlRef = useRef(null);
11
15
  useEffect(() => {
12
- const url = URL.createObjectURL(pageResult.blob);
13
- setImageUrl(url);
16
+ if (!printCapability || !printPlugin) return;
17
+ const unsubscribe = printPlugin.onPrintRequest(({ buffer, task }) => {
18
+ const iframe = iframeRef.current;
19
+ if (!iframe) return;
20
+ if (urlRef.current) {
21
+ URL.revokeObjectURL(urlRef.current);
22
+ urlRef.current = null;
23
+ }
24
+ const url = URL.createObjectURL(new Blob([buffer], { type: "application/pdf" }));
25
+ urlRef.current = url;
26
+ iframe.onload = () => {
27
+ var _a, _b;
28
+ if (iframe.src === url) {
29
+ task.progress({ stage: "iframe-ready", message: "Ready to print" });
30
+ (_a = iframe.contentWindow) == null ? void 0 : _a.focus();
31
+ (_b = iframe.contentWindow) == null ? void 0 : _b.print();
32
+ task.progress({ stage: "printing", message: "Print dialog opened" });
33
+ task.resolve(buffer);
34
+ }
35
+ };
36
+ iframe.src = url;
37
+ });
14
38
  return () => {
15
- URL.revokeObjectURL(url);
39
+ unsubscribe();
40
+ if (urlRef.current) {
41
+ URL.revokeObjectURL(urlRef.current);
42
+ }
16
43
  };
17
- }, [pageResult.blob]);
18
- const handleLoad = () => {
19
- if (imageUrl) {
20
- URL.revokeObjectURL(imageUrl);
21
- }
22
- };
44
+ }, [printCapability, printPlugin]);
23
45
  return /* @__PURE__ */ jsx(
24
- "div",
46
+ "iframe",
25
47
  {
26
- style: {
27
- pageBreakAfter: "always",
28
- width: "210mm",
29
- minHeight: "297mm",
30
- margin: "0 auto",
31
- background: "white",
32
- position: "relative"
33
- },
34
- children: /* @__PURE__ */ jsx(
35
- "img",
36
- {
37
- src: imageUrl,
38
- onLoad: handleLoad,
39
- alt: `Page ${pageResult.pageIndex + 1}`,
40
- style: {
41
- width: "100%",
42
- height: "auto",
43
- display: "block",
44
- objectFit: "contain"
45
- }
46
- }
47
- )
48
+ ref: iframeRef,
49
+ style: { position: "absolute", display: "none" },
50
+ title: "Print Document",
51
+ src: "about:blank"
48
52
  }
49
53
  );
50
- };
51
- const PrintLayout = ({ pages }) => {
52
- return /* @__PURE__ */ jsxs(
53
- "div",
54
- {
55
- style: {
56
- fontFamily: "Arial, sans-serif",
57
- fontSize: "12px",
58
- lineHeight: "1.4",
59
- color: "#000",
60
- backgroundColor: "#fff"
61
- },
62
- children: [
63
- /* @__PURE__ */ jsx("style", { children: `
64
- @media print {
65
- body { margin: 0; padding: 0; }
66
- }
67
- ` }),
68
- pages.map((pageResult) => /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(PrintPage, { pageResult }) }, pageResult.pageIndex))
69
- ]
70
- }
71
- );
72
- };
73
- function PrintProvider({ children }) {
74
- const { provides: printCapability } = usePrintCapability();
75
- const iframeRef = useRef(null);
76
- const [progress, setProgress] = useState(null);
77
- const [isReady, setIsReady] = useState(false);
78
- const [isPrinting, setIsPrinting] = useState(false);
79
- const [pages, setPages] = useState([]);
80
- const executePrint = async (options) => {
81
- var _a;
82
- if (!printCapability) {
83
- throw new Error("Print capability not available");
84
- }
85
- if (!((_a = iframeRef.current) == null ? void 0 : _a.contentWindow)) {
86
- throw new Error("Print iframe not ready");
87
- }
88
- setIsPrinting(true);
89
- setProgress(null);
90
- setPages([]);
91
- setIsReady(false);
92
- try {
93
- const collectedPages = [];
94
- await printCapability.preparePrint(
95
- options,
96
- // Progress callback
97
- (progressUpdate) => {
98
- setProgress(progressUpdate);
99
- },
100
- // Page ready callback
101
- (pageResult) => {
102
- collectedPages.push(pageResult);
103
- setPages([...collectedPages]);
104
- }
105
- );
106
- await new Promise((resolve) => setTimeout(resolve, 500));
107
- const printWindow = iframeRef.current.contentWindow;
108
- printWindow.focus();
109
- printWindow.print();
110
- setProgress({
111
- current: (progress == null ? void 0 : progress.total) || 0,
112
- total: (progress == null ? void 0 : progress.total) || 0,
113
- status: "complete",
114
- message: "Print dialog opened"
115
- });
116
- } catch (error) {
117
- setProgress({
118
- current: 0,
119
- total: 0,
120
- status: "error",
121
- message: `Print failed: ${error instanceof Error ? error.message : "Unknown error"}`
122
- });
123
- throw error;
124
- } finally {
125
- setIsPrinting(false);
126
- }
127
- };
128
- useEffect(() => {
129
- var _a, _b;
130
- const iframe = iframeRef.current;
131
- const mountNode = (_b = (_a = iframe == null ? void 0 : iframe.contentWindow) == null ? void 0 : _a.document) == null ? void 0 : _b.body;
132
- if (mountNode && pages.length > 0) {
133
- render(/* @__PURE__ */ jsx(PrintLayout, { pages }), mountNode);
134
- setIsReady(true);
135
- return () => {
136
- if (mountNode) {
137
- render(null, mountNode);
138
- }
139
- };
140
- }
141
- }, [pages]);
142
- const contextValue = {
143
- parsePageRange: (printCapability == null ? void 0 : printCapability.parsePageRange) || (() => ({ pages: [], isValid: false })),
144
- executePrint,
145
- progress,
146
- isReady,
147
- isPrinting
148
- };
149
- return /* @__PURE__ */ jsxs(PrintContext.Provider, { value: contextValue, children: [
150
- children,
151
- /* @__PURE__ */ jsx(
152
- "iframe",
153
- {
154
- ref: iframeRef,
155
- style: {
156
- display: "none",
157
- width: "210mm",
158
- height: "297mm"
159
- },
160
- title: "Print Preview"
161
- }
162
- )
163
- ] });
164
- }
165
- function usePrintContext() {
166
- const context = useContext(PrintContext);
167
- if (!context) {
168
- throw new Error("usePrintContext must be used within a PrintProvider");
169
- }
170
- return context;
171
54
  }
172
- const usePrintAction = () => {
173
- const { executePrint, progress, isReady, isPrinting, parsePageRange } = usePrintContext();
174
- return {
175
- executePrint,
176
- progress,
177
- isReady,
178
- isPrinting,
179
- parsePageRange
180
- };
181
- };
55
+ const PrintPluginPackage = createPluginPackage(PrintPluginPackage$1).addUtility(PrintFrame).build();
182
56
  export {
183
- PrintProvider,
184
- usePrintAction,
57
+ PrintFrame,
58
+ PrintPluginPackage,
185
59
  usePrintCapability,
186
- usePrintContext,
187
60
  usePrintPlugin
188
61
  };
189
62
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-print.ts","../../src/shared/components/print.tsx","../../src/shared/hooks/use-print-action.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { PrintPlugin } from '@embedpdf/plugin-print';\n\nexport const usePrintPlugin = () => usePlugin<PrintPlugin>(PrintPlugin.id);\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n","import {\n createContext,\n render,\n useContext,\n useRef,\n useEffect,\n useState,\n ReactNode,\n} from '@framework';\nimport { usePrintCapability } from '../hooks/use-print';\nimport { PrintOptions, PrintProgress, PrintPageResult, ParsedPageRange } from '../../lib/types';\n\ninterface PrintContextValue {\n parsePageRange: (rangeString: string) => ParsedPageRange;\n executePrint: (options: PrintOptions) => Promise<void>;\n progress: PrintProgress | null;\n isReady: boolean;\n isPrinting: boolean;\n}\n\nconst PrintContext = createContext<PrintContextValue | null>(null);\n\ninterface PrintProviderProps {\n children: ReactNode;\n}\n\ninterface PrintPageProps {\n pageResult: PrintPageResult;\n}\n\nconst PrintPage = ({ pageResult }: PrintPageProps) => {\n const [imageUrl, setImageUrl] = useState<string>('');\n\n useEffect(() => {\n const url = URL.createObjectURL(pageResult.blob);\n setImageUrl(url);\n\n return () => {\n URL.revokeObjectURL(url);\n };\n }, [pageResult.blob]);\n\n const handleLoad = () => {\n if (imageUrl) {\n URL.revokeObjectURL(imageUrl);\n }\n };\n\n return (\n <div\n style={{\n pageBreakAfter: 'always',\n width: '210mm',\n minHeight: '297mm',\n margin: '0 auto',\n background: 'white',\n position: 'relative',\n }}\n >\n <img\n src={imageUrl}\n onLoad={handleLoad}\n alt={`Page ${pageResult.pageIndex + 1}`}\n style={{\n width: '100%',\n height: 'auto',\n display: 'block',\n objectFit: 'contain',\n }}\n />\n </div>\n );\n};\n\ninterface PrintLayoutProps {\n pages: PrintPageResult[];\n}\n\nconst PrintLayout = ({ pages }: PrintLayoutProps) => {\n return (\n <div\n style={{\n fontFamily: 'Arial, sans-serif',\n fontSize: '12px',\n lineHeight: '1.4',\n color: '#000',\n backgroundColor: '#fff',\n }}\n >\n <style>{`\n @media print {\n body { margin: 0; padding: 0; }\n }\n `}</style>\n {pages.map((pageResult) => (\n <div key={pageResult.pageIndex}>\n <PrintPage pageResult={pageResult} />\n </div>\n ))}\n </div>\n );\n};\n\nexport function PrintProvider({ children }: PrintProviderProps) {\n const { provides: printCapability } = usePrintCapability();\n const iframeRef = useRef<HTMLIFrameElement>(null);\n const [progress, setProgress] = useState<PrintProgress | null>(null);\n const [isReady, setIsReady] = useState(false);\n const [isPrinting, setIsPrinting] = useState(false);\n const [pages, setPages] = useState<PrintPageResult[]>([]);\n\n const executePrint = async (options: PrintOptions): Promise<void> => {\n if (!printCapability) {\n throw new Error('Print capability not available');\n }\n\n if (!iframeRef.current?.contentWindow) {\n throw new Error('Print iframe not ready');\n }\n\n setIsPrinting(true);\n setProgress(null);\n setPages([]);\n setIsReady(false);\n\n try {\n const collectedPages: PrintPageResult[] = [];\n\n // Prepare print with progress tracking\n await printCapability.preparePrint(\n options,\n // Progress callback\n (progressUpdate: PrintProgress) => {\n setProgress(progressUpdate);\n },\n // Page ready callback\n (pageResult: PrintPageResult) => {\n collectedPages.push(pageResult);\n setPages([...collectedPages]); // Update pages as they come in\n },\n );\n\n // Wait a bit for all content to load\n await new Promise((resolve) => setTimeout(resolve, 500));\n\n // Execute print\n const printWindow = iframeRef.current.contentWindow!;\n printWindow.focus();\n printWindow.print();\n\n setProgress({\n current: progress?.total || 0,\n total: progress?.total || 0,\n status: 'complete',\n message: 'Print dialog opened',\n });\n } catch (error) {\n setProgress({\n current: 0,\n total: 0,\n status: 'error',\n message: `Print failed: ${error instanceof Error ? error.message : 'Unknown error'}`,\n });\n throw error;\n } finally {\n setIsPrinting(false);\n }\n };\n\n // Render the print layout into the iframe when pages change\n useEffect(() => {\n const iframe = iframeRef.current;\n const mountNode = iframe?.contentWindow?.document?.body;\n\n if (mountNode && pages.length > 0) {\n render(<PrintLayout pages={pages} />, mountNode);\n setIsReady(true);\n\n return () => {\n if (mountNode) {\n render(null, mountNode);\n }\n };\n }\n }, [pages]);\n\n const contextValue: PrintContextValue = {\n parsePageRange: printCapability?.parsePageRange || (() => ({ pages: [], isValid: false })),\n executePrint,\n progress,\n isReady,\n isPrinting,\n };\n\n return (\n <PrintContext.Provider value={contextValue}>\n {children}\n <iframe\n ref={iframeRef}\n style={{\n display: 'none',\n width: '210mm',\n height: '297mm',\n }}\n title=\"Print Preview\"\n />\n </PrintContext.Provider>\n );\n}\n\nexport function usePrintContext(): PrintContextValue {\n const context = useContext(PrintContext);\n if (!context) {\n throw new Error('usePrintContext must be used within a PrintProvider');\n }\n return context;\n}\n","import { PrintOptions } from '@embedpdf/plugin-print';\nimport { usePrintContext } from '../components';\n\nexport const usePrintAction = () => {\n const { executePrint, progress, isReady, isPrinting, parsePageRange } = usePrintContext();\n\n return {\n executePrint,\n progress,\n isReady,\n isPrinting,\n parsePageRange,\n };\n};\n"],"names":[],"mappings":";;;;;AAGO,MAAM,iBAAiB,MAAM,UAAuB,YAAY,EAAE;AAClE,MAAM,qBAAqB,MAAM,cAA2B,YAAY,EAAE;ACgBjF,MAAM,eAAe,cAAwC,IAAI;AAUjE,MAAM,YAAY,CAAC,EAAE,iBAAiC;AACpD,QAAM,CAAC,UAAU,WAAW,IAAI,SAAiB,EAAE;AAEnD,YAAU,MAAM;AACd,UAAM,MAAM,IAAI,gBAAgB,WAAW,IAAI;AAC/C,gBAAY,GAAG;AAEf,WAAO,MAAM;AACX,UAAI,gBAAgB,GAAG;AAAA,IACzB;AAAA,EAAA,GACC,CAAC,WAAW,IAAI,CAAC;AAEpB,QAAM,aAAa,MAAM;AACvB,QAAI,UAAU;AACZ,UAAI,gBAAgB,QAAQ;AAAA,IAAA;AAAA,EAEhC;AAGE,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,gBAAgB;AAAA,QAChB,OAAO;AAAA,QACP,WAAW;AAAA,QACX,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,UAAU;AAAA,MACZ;AAAA,MAEA,UAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,KAAK;AAAA,UACL,QAAQ;AAAA,UACR,KAAK,QAAQ,WAAW,YAAY,CAAC;AAAA,UACrC,OAAO;AAAA,YACL,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,SAAS;AAAA,YACT,WAAW;AAAA,UAAA;AAAA,QACb;AAAA,MAAA;AAAA,IACF;AAAA,EACF;AAEJ;AAMA,MAAM,cAAc,CAAC,EAAE,YAA8B;AAEjD,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,YAAY;AAAA,QACZ,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,OAAO;AAAA,QACP,iBAA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;AAAA,EAAA;AAEhE,SAAA;AACT;ACrNO,MAAM,iBAAiB,MAAM;AAClC,QAAM,EAAE,cAAc,UAAU,SAAS,YAAY,mBAAmB,gBAAgB;AAEjF,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-print.ts","../../src/shared/components/print.tsx","../../src/shared/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { PrintPlugin } from '@embedpdf/plugin-print';\n\nexport const usePrintPlugin = () => usePlugin<PrintPlugin>(PrintPlugin.id);\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n","import { useEffect, useRef } from '@framework';\nimport { usePrintCapability, usePrintPlugin } from '../hooks';\n\nexport function PrintFrame() {\n const { provides: printCapability } = usePrintCapability();\n const { plugin: printPlugin } = usePrintPlugin();\n const iframeRef = useRef<HTMLIFrameElement | null>(null);\n const urlRef = useRef<string | null>(null);\n\n useEffect(() => {\n if (!printCapability || !printPlugin) return;\n\n const unsubscribe = printPlugin.onPrintRequest(({ buffer, task }) => {\n const iframe = iframeRef.current;\n if (!iframe) return;\n\n // cleanup old URL\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n\n const url = URL.createObjectURL(new Blob([buffer], { type: 'application/pdf' }));\n urlRef.current = url;\n\n iframe.onload = () => {\n if (iframe.src === url) {\n task.progress({ stage: 'iframe-ready', message: 'Ready to print' });\n iframe.contentWindow?.focus();\n iframe.contentWindow?.print();\n task.progress({ stage: 'printing', message: 'Print dialog opened' });\n task.resolve(buffer);\n }\n };\n\n iframe.src = url;\n });\n\n return () => {\n unsubscribe();\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n }\n };\n }, [printCapability, printPlugin]);\n\n return (\n <iframe\n ref={iframeRef}\n style={{ position: 'absolute', display: 'none' }}\n title=\"Print Document\"\n src=\"about:blank\"\n />\n );\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { PrintPluginPackage as BasePrintPackage } from '@embedpdf/plugin-print';\n\nimport { PrintFrame } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-print';\n\nexport const PrintPluginPackage = createPluginPackage(BasePrintPackage)\n .addUtility(PrintFrame)\n .build();\n"],"names":["BasePrintPackage"],"mappings":";;;;;;;AAGO,MAAM,iBAAiB,MAAM,UAAuB,YAAY,EAAE;AAClE,MAAM,qBAAqB,MAAM,cAA2B,YAAY,EAAE;ACD1E,SAAS,aAAa;AAC3B,QAAM,EAAE,UAAU,gBAAgB,IAAI,mBAAmB;AACzD,QAAM,EAAE,QAAQ,YAAY,IAAI,eAAe;AACzC,QAAA,YAAY,OAAiC,IAAI;AACjD,QAAA,SAAS,OAAsB,IAAI;AAEzC,YAAU,MAAM;AACV,QAAA,CAAC,mBAAmB,CAAC,YAAa;AAEtC,UAAM,cAAc,YAAY,eAAe,CAAC,EAAE,QAAQ,WAAW;AACnE,YAAM,SAAS,UAAU;AACzB,UAAI,CAAC,OAAQ;AAGb,UAAI,OAAO,SAAS;AACd,YAAA,gBAAgB,OAAO,OAAO;AAClC,eAAO,UAAU;AAAA,MAAA;AAGnB,YAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,MAAM,kBAAkB,CAAC,CAAC;AAC/E,aAAO,UAAU;AAEjB,aAAO,SAAS,MAAM;;AAChB,YAAA,OAAO,QAAQ,KAAK;AACtB,eAAK,SAAS,EAAE,OAAO,gBAAgB,SAAS,kBAAkB;AAClE,uBAAO,kBAAP,mBAAsB;AACtB,uBAAO,kBAAP,mBAAsB;AACtB,eAAK,SAAS,EAAE,OAAO,YAAY,SAAS,uBAAuB;AACnE,eAAK,QAAQ,MAAM;AAAA,QAAA;AAAA,MAEvB;AAEA,aAAO,MAAM;AAAA,IAAA,CACd;AAED,WAAO,MAAM;AACC,kBAAA;AACZ,UAAI,OAAO,SAAS;AACd,YAAA,gBAAgB,OAAO,OAAO;AAAA,MAAA;AAAA,IAEtC;AAAA,EAAA,GACC,CAAC,iBAAiB,WAAW,CAAC;AAG/B,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAK;AAAA,MACL,OAAO,EAAE,UAAU,YAAY,SAAS,OAAO;AAAA,MAC/C,OAAM;AAAA,MACN,KAAI;AAAA,IAAA;AAAA,EACN;AAEJ;AC7CO,MAAM,qBAAqB,oBAAoBA,oBAAgB,EACnE,WAAW,UAAU,EACrB,MAAM;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-print"),n=require("react/jsx-runtime"),r=require("react-dom"),i=require("react"),o=()=>e.useCapability(t.PrintPlugin.id);var a,s={};var l=function(){if(a)return s;a=1;var e=r;if("production"===process.env.NODE_ENV)s.createRoot=e.createRoot,s.hydrateRoot=e.hydrateRoot;else{var t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;s.createRoot=function(n,r){t.usingClientEntryPoint=!0;try{return e.createRoot(n,r)}finally{t.usingClientEntryPoint=!1}},s.hydrateRoot=function(n,r,i){t.usingClientEntryPoint=!0;try{return e.hydrateRoot(n,r,i)}finally{t.usingClientEntryPoint=!1}}}return s}();const u=new WeakMap;function c(e,t){if(t)if(null===e){const e=u.get(t);e&&(e.unmount(),u.delete(t))}else{let n=u.get(t);n||(n=l.createRoot(t),u.set(t,n)),n.render(e)}}const d=i.createContext(null),g=({pageResult:e})=>{const[t,r]=i.useState("");i.useEffect((()=>{const t=URL.createObjectURL(e.blob);return r(t),()=>{URL.revokeObjectURL(t)}}),[e.blob]);return n.jsx("div",{style:{pageBreakAfter:"always",width:"210mm",minHeight:"297mm",margin:"0 auto",background:"white",position:"relative"},children:n.jsx("img",{src:t,onLoad:()=>{t&&URL.revokeObjectURL(t)},alt:`Page ${e.pageIndex+1}`,style:{width:"100%",height:"auto",display:"block",objectFit:"contain"}})})},p=({pages:e})=>n.jsxs("div",{style:{fontFamily:"Arial, sans-serif",fontSize:"12px",lineHeight:"1.4",color:"#000",backgroundColor:"#fff"},children:[n.jsx("style",{children:"\n @media print {\n body { margin: 0; padding: 0; }\n }\n "}),e.map((e=>n.jsx("div",{children:n.jsx(g,{pageResult:e})},e.pageIndex)))]});function P(){const e=i.useContext(d);if(!e)throw new Error("usePrintContext must be used within a PrintProvider");return e}exports.PrintProvider=function({children:e}){const{provides:t}=o(),r=i.useRef(null),[a,s]=i.useState(null),[l,u]=i.useState(!1),[g,P]=i.useState(!1),[f,y]=i.useState([]);i.useEffect((()=>{var e,t;const i=r.current,o=null==(t=null==(e=null==i?void 0:i.contentWindow)?void 0:e.document)?void 0:t.body;if(o&&f.length>0)return c(n.jsx(p,{pages:f}),o),u(!0),()=>{o&&c(null,o)}}),[f]);const m={parsePageRange:(null==t?void 0:t.parsePageRange)||(()=>({pages:[],isValid:!1})),executePrint:async e=>{var n;if(!t)throw new Error("Print capability not available");if(!(null==(n=r.current)?void 0:n.contentWindow))throw new Error("Print iframe not ready");P(!0),s(null),y([]),u(!1);try{const n=[];await t.preparePrint(e,(e=>{s(e)}),(e=>{n.push(e),y([...n])})),await new Promise((e=>setTimeout(e,500)));const i=r.current.contentWindow;i.focus(),i.print(),s({current:(null==a?void 0:a.total)||0,total:(null==a?void 0:a.total)||0,status:"complete",message:"Print dialog opened"})}catch(i){throw s({current:0,total:0,status:"error",message:`Print failed: ${i instanceof Error?i.message:"Unknown error"}`}),i}finally{P(!1)}},progress:a,isReady:l,isPrinting:g};return n.jsxs(d.Provider,{value:m,children:[e,n.jsx("iframe",{ref:r,style:{display:"none",width:"210mm",height:"297mm"},title:"Print Preview"})]})},exports.usePrintAction=()=>{const{executePrint:e,progress:t,isReady:n,isPrinting:r,parsePageRange:i}=P();return{executePrint:e,progress:t,isReady:n,isPrinting:r,parsePageRange:i}},exports.usePrintCapability=o,exports.usePrintContext=P,exports.usePrintPlugin=()=>e.usePlugin(t.PrintPlugin.id);
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-print"),r=require("react/jsx-runtime"),n=require("react-dom"),i=require("react"),o=require("@embedpdf/core/react");var u,a={};!function(){if(u)return a;u=1;var e=n;if("production"===process.env.NODE_ENV)a.createRoot=e.createRoot,a.hydrateRoot=e.hydrateRoot;else{var t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;a.createRoot=function(r,n){t.usingClientEntryPoint=!0;try{return e.createRoot(r,n)}finally{t.usingClientEntryPoint=!1}},a.hydrateRoot=function(r,n,i){t.usingClientEntryPoint=!0;try{return e.hydrateRoot(r,n,i)}finally{t.usingClientEntryPoint=!1}}}}();const s=()=>o.usePlugin(t.PrintPlugin.id),c=()=>o.useCapability(t.PrintPlugin.id);function l(){const{provides:e}=c(),{plugin:t}=s(),n=i.useRef(null),o=i.useRef(null);return i.useEffect((()=>{if(!e||!t)return;const r=t.onPrintRequest((({buffer:e,task:t})=>{const r=n.current;if(!r)return;o.current&&(URL.revokeObjectURL(o.current),o.current=null);const i=URL.createObjectURL(new Blob([e],{type:"application/pdf"}));o.current=i,r.onload=()=>{var n,o;r.src===i&&(t.progress({stage:"iframe-ready",message:"Ready to print"}),null==(n=r.contentWindow)||n.focus(),null==(o=r.contentWindow)||o.print(),t.progress({stage:"printing",message:"Print dialog opened"}),t.resolve(e))},r.src=i}));return()=>{r(),o.current&&URL.revokeObjectURL(o.current)}}),[e,t]),r.jsx("iframe",{ref:n,style:{position:"absolute",display:"none"},title:"Print Document",src:"about:blank"})}const p=e.createPluginPackage(t.PrintPluginPackage).addUtility(l).build();exports.PrintFrame=l,exports.PrintPluginPackage=p,exports.usePrintCapability=c,exports.usePrintPlugin=s,Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-print.ts","../../../../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/client.js","../../src/react/adapter.ts","../../src/shared/components/print.tsx","../../src/shared/hooks/use-print-action.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { PrintPlugin } from '@embedpdf/plugin-print';\n\nexport const usePrintPlugin = () => usePlugin<PrintPlugin>(PrintPlugin.id);\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n","'use strict';\n\nvar m = require('react-dom');\nif (process.env.NODE_ENV === 'production') {\n exports.createRoot = m.createRoot;\n exports.hydrateRoot = m.hydrateRoot;\n} else {\n var i = m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;\n exports.createRoot = function(c, o) {\n i.usingClientEntryPoint = true;\n try {\n return m.createRoot(c, o);\n } finally {\n i.usingClientEntryPoint = false;\n }\n };\n exports.hydrateRoot = function(c, h, o) {\n i.usingClientEntryPoint = true;\n try {\n return m.hydrateRoot(c, h, o);\n } finally {\n i.usingClientEntryPoint = false;\n }\n };\n}\n","import { ReactNode } from 'react';\nimport { createRoot } from 'react-dom/client';\n\nexport { Fragment, useEffect, useRef, useState, createContext, useContext, ReactNode } from 'react';\nexport type { CSSProperties, HTMLAttributes } from 'react';\n\nconst rootMap = new WeakMap<Element, any>();\n\nexport function render(vnode: ReactNode | null, container: Element | null): void {\n if (!container) return;\n\n if (vnode === null) {\n // Unmounting\n const root = rootMap.get(container);\n if (root) {\n root.unmount();\n rootMap.delete(container);\n }\n } else {\n // Mounting/updating\n let root = rootMap.get(container);\n if (!root) {\n root = createRoot(container);\n rootMap.set(container, root);\n }\n root.render(vnode);\n }\n}\n","import {\n createContext,\n render,\n useContext,\n useRef,\n useEffect,\n useState,\n ReactNode,\n} from '@framework';\nimport { usePrintCapability } from '../hooks/use-print';\nimport { PrintOptions, PrintProgress, PrintPageResult, ParsedPageRange } from '../../lib/types';\n\ninterface PrintContextValue {\n parsePageRange: (rangeString: string) => ParsedPageRange;\n executePrint: (options: PrintOptions) => Promise<void>;\n progress: PrintProgress | null;\n isReady: boolean;\n isPrinting: boolean;\n}\n\nconst PrintContext = createContext<PrintContextValue | null>(null);\n\ninterface PrintProviderProps {\n children: ReactNode;\n}\n\ninterface PrintPageProps {\n pageResult: PrintPageResult;\n}\n\nconst PrintPage = ({ pageResult }: PrintPageProps) => {\n const [imageUrl, setImageUrl] = useState<string>('');\n\n useEffect(() => {\n const url = URL.createObjectURL(pageResult.blob);\n setImageUrl(url);\n\n return () => {\n URL.revokeObjectURL(url);\n };\n }, [pageResult.blob]);\n\n const handleLoad = () => {\n if (imageUrl) {\n URL.revokeObjectURL(imageUrl);\n }\n };\n\n return (\n <div\n style={{\n pageBreakAfter: 'always',\n width: '210mm',\n minHeight: '297mm',\n margin: '0 auto',\n background: 'white',\n position: 'relative',\n }}\n >\n <img\n src={imageUrl}\n onLoad={handleLoad}\n alt={`Page ${pageResult.pageIndex + 1}`}\n style={{\n width: '100%',\n height: 'auto',\n display: 'block',\n objectFit: 'contain',\n }}\n />\n </div>\n );\n};\n\ninterface PrintLayoutProps {\n pages: PrintPageResult[];\n}\n\nconst PrintLayout = ({ pages }: PrintLayoutProps) => {\n return (\n <div\n style={{\n fontFamily: 'Arial, sans-serif',\n fontSize: '12px',\n lineHeight: '1.4',\n color: '#000',\n backgroundColor: '#fff',\n }}\n >\n <style>{`\n @media print {\n body { margin: 0; padding: 0; }\n }\n `}</style>\n {pages.map((pageResult) => (\n <div key={pageResult.pageIndex}>\n <PrintPage pageResult={pageResult} />\n </div>\n ))}\n </div>\n );\n};\n\nexport function PrintProvider({ children }: PrintProviderProps) {\n const { provides: printCapability } = usePrintCapability();\n const iframeRef = useRef<HTMLIFrameElement>(null);\n const [progress, setProgress] = useState<PrintProgress | null>(null);\n const [isReady, setIsReady] = useState(false);\n const [isPrinting, setIsPrinting] = useState(false);\n const [pages, setPages] = useState<PrintPageResult[]>([]);\n\n const executePrint = async (options: PrintOptions): Promise<void> => {\n if (!printCapability) {\n throw new Error('Print capability not available');\n }\n\n if (!iframeRef.current?.contentWindow) {\n throw new Error('Print iframe not ready');\n }\n\n setIsPrinting(true);\n setProgress(null);\n setPages([]);\n setIsReady(false);\n\n try {\n const collectedPages: PrintPageResult[] = [];\n\n // Prepare print with progress tracking\n await printCapability.preparePrint(\n options,\n // Progress callback\n (progressUpdate: PrintProgress) => {\n setProgress(progressUpdate);\n },\n // Page ready callback\n (pageResult: PrintPageResult) => {\n collectedPages.push(pageResult);\n setPages([...collectedPages]); // Update pages as they come in\n },\n );\n\n // Wait a bit for all content to load\n await new Promise((resolve) => setTimeout(resolve, 500));\n\n // Execute print\n const printWindow = iframeRef.current.contentWindow!;\n printWindow.focus();\n printWindow.print();\n\n setProgress({\n current: progress?.total || 0,\n total: progress?.total || 0,\n status: 'complete',\n message: 'Print dialog opened',\n });\n } catch (error) {\n setProgress({\n current: 0,\n total: 0,\n status: 'error',\n message: `Print failed: ${error instanceof Error ? error.message : 'Unknown error'}`,\n });\n throw error;\n } finally {\n setIsPrinting(false);\n }\n };\n\n // Render the print layout into the iframe when pages change\n useEffect(() => {\n const iframe = iframeRef.current;\n const mountNode = iframe?.contentWindow?.document?.body;\n\n if (mountNode && pages.length > 0) {\n render(<PrintLayout pages={pages} />, mountNode);\n setIsReady(true);\n\n return () => {\n if (mountNode) {\n render(null, mountNode);\n }\n };\n }\n }, [pages]);\n\n const contextValue: PrintContextValue = {\n parsePageRange: printCapability?.parsePageRange || (() => ({ pages: [], isValid: false })),\n executePrint,\n progress,\n isReady,\n isPrinting,\n };\n\n return (\n <PrintContext.Provider value={contextValue}>\n {children}\n <iframe\n ref={iframeRef}\n style={{\n display: 'none',\n width: '210mm',\n height: '297mm',\n }}\n title=\"Print Preview\"\n />\n </PrintContext.Provider>\n );\n}\n\nexport function usePrintContext(): PrintContextValue {\n const context = useContext(PrintContext);\n if (!context) {\n throw new Error('usePrintContext must be used within a PrintProvider');\n }\n return context;\n}\n","import { PrintOptions } from '@embedpdf/plugin-print';\nimport { usePrintContext } from '../components';\n\nexport const usePrintAction = () => {\n const { executePrint, progress, isReady, isPrinting, parsePageRange } = usePrintContext();\n\n return {\n executePrint,\n progress,\n isReady,\n isPrinting,\n parsePageRange,\n };\n};\n"],"names":["usePrintCapability","useCapability","PrintPlugin","id","m","require$$0","process","env","NODE_ENV","client","createRoot","hydrateRoot","i","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","c","o","usingClientEntryPoint","h","rootMap","WeakMap","render","vnode","container","root","get","unmount","delete","set","PrintContext","createContext","PrintPage","pageResult","imageUrl","setImageUrl","useState","useEffect","url","URL","createObjectURL","blob","revokeObjectURL","jsxRuntime","jsx","style","pageBreakAfter","width","minHeight","margin","background","position","children","src","onLoad","alt","pageIndex","height","display","objectFit","PrintLayout","pages","jsxs","fontFamily","fontSize","lineHeight","color","backgroundColor","map","usePrintContext","context","useContext","Error","provides","printCapability","iframeRef","useRef","progress","setProgress","isReady","setIsReady","isPrinting","setIsPrinting","setPages","iframe","current","mountNode","_b","_a","contentWindow","document","body","length","contextValue","parsePageRange","isValid","executePrint","async","options","collectedPages","preparePrint","progressUpdate","push","Promise","resolve","setTimeout","printWindow","focus","print","total","status","message","error","Provider","value","ref","title","usePlugin"],"mappings":"qOAIaA,EAAqB,IAAMC,gBAA2BC,EAAAA,YAAYC,kDCF/E,IAAIC,EAAIC,EACJ,GAAyB,eAAzBC,QAAQC,IAAIC,SACdC,EAAkBC,WAAGN,EAAEM,WACvBD,EAAmBE,YAAGP,EAAEO,gBACnB,CACL,IAAIC,EAAIR,EAAES,gEACW,SAASC,EAAGC,GAC/BH,EAAEI,uBAAwB,EACtB,IACK,OAAAZ,EAAEM,WAAWI,EAAGC,E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AAYC,WAAWD,EAAS,OAG7C,MAAAE,EAAc/B,EAAUU,QAAQI,cACtCiB,EAAYC,QACZD,EAAYE,QAEA9B,EAAA,CACVO,eAASR,WAAUgC,QAAS,EAC5BA,aAAOhC,WAAUgC,QAAS,EAC1BC,OAAQ,WACRC,QAAS,8BAEJC,GAOD,MANMlC,EAAA,CACVO,QAAS,EACTwB,MAAO,EACPC,OAAQ,QACRC,QAAS,iBAAiBC,aAAiBxC,MAAQwC,EAAMD,QAAU,oBAE/DC,CAAA,CACN,QACA9B,GAAc,EAAK,GAwBrBL,WACAE,UACAE,cAGF,SACGnB,KAAAhC,EAAamF,SAAb,CAAsBC,MAAOrB,EAC3BzC,SAAA,CAAAA,EACDT,EAAAC,IAAC,SAAA,CACCuE,IAAKxC,EACL9B,MAAO,CACLa,QAAS,OACTX,MAAO,QACPU,OAAQ,SAEV2D,MAAM,oBAId,yBC7M8B,KAC5B,MAAMpB,aAAEA,EAAcnB,SAAAA,EAAAE,QAAUA,aAASE,EAAYa,eAAAA,GAAmBzB,IAEjE,MAAA,CACL2B,eACAnB,WACAE,UACAE,aACAa,iBACF,gFJT4B,IAAMuB,YAAuBjH,EAAAA,YAAYC","x_google_ignoreList":[1]}
1
+ {"version":3,"file":"index.cjs","sources":["../../../../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/client.js","../../src/shared/hooks/use-print.ts","../../src/shared/components/print.tsx","../../src/shared/index.ts"],"sourcesContent":["'use strict';\n\nvar m = require('react-dom');\nif (process.env.NODE_ENV === 'production') {\n exports.createRoot = m.createRoot;\n exports.hydrateRoot = m.hydrateRoot;\n} else {\n var i = m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;\n exports.createRoot = function(c, o) {\n i.usingClientEntryPoint = true;\n try {\n return m.createRoot(c, o);\n } finally {\n i.usingClientEntryPoint = false;\n }\n };\n exports.hydrateRoot = function(c, h, o) {\n i.usingClientEntryPoint = true;\n try {\n return m.hydrateRoot(c, h, o);\n } finally {\n i.usingClientEntryPoint = false;\n }\n };\n}\n","import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { PrintPlugin } from '@embedpdf/plugin-print';\n\nexport const usePrintPlugin = () => usePlugin<PrintPlugin>(PrintPlugin.id);\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n","import { useEffect, useRef } from '@framework';\nimport { usePrintCapability, usePrintPlugin } from '../hooks';\n\nexport function PrintFrame() {\n const { provides: printCapability } = usePrintCapability();\n const { plugin: printPlugin } = usePrintPlugin();\n const iframeRef = useRef<HTMLIFrameElement | null>(null);\n const urlRef = useRef<string | null>(null);\n\n useEffect(() => {\n if (!printCapability || !printPlugin) return;\n\n const unsubscribe = printPlugin.onPrintRequest(({ buffer, task }) => {\n const iframe = iframeRef.current;\n if (!iframe) return;\n\n // cleanup old URL\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n\n const url = URL.createObjectURL(new Blob([buffer], { type: 'application/pdf' }));\n urlRef.current = url;\n\n iframe.onload = () => {\n if (iframe.src === url) {\n task.progress({ stage: 'iframe-ready', message: 'Ready to print' });\n iframe.contentWindow?.focus();\n iframe.contentWindow?.print();\n task.progress({ stage: 'printing', message: 'Print dialog opened' });\n task.resolve(buffer);\n }\n };\n\n iframe.src = url;\n });\n\n return () => {\n unsubscribe();\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n }\n };\n }, [printCapability, printPlugin]);\n\n return (\n <iframe\n ref={iframeRef}\n style={{ position: 'absolute', display: 'none' }}\n title=\"Print Document\"\n src=\"about:blank\"\n />\n );\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { PrintPluginPackage as BasePrintPackage } from '@embedpdf/plugin-print';\n\nimport { PrintFrame } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-print';\n\nexport const PrintPluginPackage = createPluginPackage(BasePrintPackage)\n .addUtility(PrintFrame)\n .build();\n"],"names":["m","require$$0","process","env","NODE_ENV","client","createRoot","hydrateRoot","i","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","c","o","usingClientEntryPoint","h","usePrintPlugin","usePlugin","PrintPlugin","id","usePrintCapability","useCapability","PrintFrame","provides","printCapability","plugin","printPlugin","iframeRef","useRef","urlRef","useEffect","unsubscribe","onPrintRequest","buffer","task","iframe","current","URL","revokeObjectURL","url","createObjectURL","Blob","type","onload","src","progress","stage","message","_a","contentWindow","focus","_b","print","resolve","jsxRuntime","jsx","ref","style","position","display","title","PrintPluginPackage","createPluginPackage","BasePrintPackage","addUtility","build"],"mappings":"0SAEA,IAAIA,EAAIC,EACJ,GAAyB,eAAzBC,QAAQC,IAAIC,SACdC,EAAkBC,WAAGN,EAAEM,WACvBD,EAAmBE,YAAGP,EAAEO,gBACnB,CACL,IAAIC,EAAIR,EAAES,gEACW,SAASC,EAAGC,GAC/BH,EAAEI,uBAAwB,EACtB,IACK,OAAAZ,EAAEM,WAAWI,EAAGC,EAC7B,CAAc,QACRH,EAAEI,uBAAwB,CAChC,CACG,EACDP,EAAAE,YAAsB,SAASG,EAAGG,EAAGF,GACnCH,EAAEI,uBAAwB,EACtB,IACF,OAAOZ,EAAEO,YAAYG,EAAGG,EAAGF,EACjC,CAAc,QACRH,EAAEI,uBAAwB,CAChC,CACG,CACH,KCrBO,MAAME,EAAiB,IAAMC,YAAuBC,EAAAA,YAAYC,IAC1DC,EAAqB,IAAMC,gBAA2BH,EAAAA,YAAYC,ICDxE,SAASG,IACd,MAAQC,SAAUC,GAAoBJ,KAC9BK,OAAQC,GAAgBV,IAC1BW,EAAYC,SAAiC,MAC7CC,EAASD,SAAsB,MAwCnC,OAtCFE,EAAAA,WAAU,KACJ,IAACN,IAAoBE,EAAa,OAEtC,MAAMK,EAAcL,EAAYM,gBAAe,EAAGC,SAAQC,WACxD,MAAMC,EAASR,EAAUS,QACzB,IAAKD,EAAQ,OAGTN,EAAOO,UACLC,IAAAC,gBAAgBT,EAAOO,SAC3BP,EAAOO,QAAU,MAGnB,MAAMG,EAAMF,IAAIG,gBAAgB,IAAIC,KAAK,CAACR,GAAS,CAAES,KAAM,qBAC3Db,EAAOO,QAAUG,EAEjBJ,EAAOQ,OAAS,aACVR,EAAOS,MAAQL,IACjBL,EAAKW,SAAS,CAAEC,MAAO,eAAgBC,QAAS,mBAChD,OAAAC,EAAAb,EAAOc,gBAAeD,EAAAE,QACtB,OAAAC,EAAAhB,EAAOc,gBAAeE,EAAAC,QACtBlB,EAAKW,SAAS,CAAEC,MAAO,WAAYC,QAAS,wBAC5Cb,EAAKmB,QAAQpB,GAAM,EAIvBE,EAAOS,IAAML,CAAA,IAGf,MAAO,KACOR,IACRF,EAAOO,SACLC,IAAAC,gBAAgBT,EAAOO,QAAO,CAEtC,GACC,CAACZ,EAAiBE,IAGnB4B,EAAAC,IAAC,SAAA,CACCC,IAAK7B,EACL8B,MAAO,CAAEC,SAAU,WAAYC,QAAS,QACxCC,MAAM,iBACNhB,IAAI,eAGV,CC7CO,MAAMiB,EAAqBC,EAAoBA,oBAAAC,EAAgBF,oBACnEG,WAAW1C,GACX2C","x_google_ignoreList":[0]}
@@ -1,10 +1,10 @@
1
- import { usePlugin, useCapability } from "@embedpdf/core/react";
2
- import { PrintPlugin } from "@embedpdf/plugin-print";
3
- import { jsxs, jsx } from "react/jsx-runtime";
1
+ import { createPluginPackage } from "@embedpdf/core";
2
+ import { PrintPlugin, PrintPluginPackage as PrintPluginPackage$1 } from "@embedpdf/plugin-print";
3
+ export * from "@embedpdf/plugin-print";
4
+ import { jsx } from "react/jsx-runtime";
4
5
  import require$$0 from "react-dom";
5
- import { createContext, useRef, useState, useEffect, useContext } from "react";
6
- const usePrintPlugin = () => usePlugin(PrintPlugin.id);
7
- const usePrintCapability = () => useCapability(PrintPlugin.id);
6
+ import { useRef, useEffect } from "react";
7
+ import { useCapability, usePlugin } from "@embedpdf/core/react";
8
8
  var client = {};
9
9
  var hasRequiredClient;
10
10
  function requireClient() {
@@ -35,204 +35,59 @@ function requireClient() {
35
35
  }
36
36
  return client;
37
37
  }
38
- var clientExports = requireClient();
39
- const rootMap = /* @__PURE__ */ new WeakMap();
40
- function render(vnode, container) {
41
- if (!container) return;
42
- if (vnode === null) {
43
- const root = rootMap.get(container);
44
- if (root) {
45
- root.unmount();
46
- rootMap.delete(container);
47
- }
48
- } else {
49
- let root = rootMap.get(container);
50
- if (!root) {
51
- root = clientExports.createRoot(container);
52
- rootMap.set(container, root);
53
- }
54
- root.render(vnode);
55
- }
56
- }
57
- const PrintContext = createContext(null);
58
- const PrintPage = ({ pageResult }) => {
59
- const [imageUrl, setImageUrl] = useState("");
38
+ requireClient();
39
+ const usePrintPlugin = () => usePlugin(PrintPlugin.id);
40
+ const usePrintCapability = () => useCapability(PrintPlugin.id);
41
+ function PrintFrame() {
42
+ const { provides: printCapability } = usePrintCapability();
43
+ const { plugin: printPlugin } = usePrintPlugin();
44
+ const iframeRef = useRef(null);
45
+ const urlRef = useRef(null);
60
46
  useEffect(() => {
61
- const url = URL.createObjectURL(pageResult.blob);
62
- setImageUrl(url);
47
+ if (!printCapability || !printPlugin) return;
48
+ const unsubscribe = printPlugin.onPrintRequest(({ buffer, task }) => {
49
+ const iframe = iframeRef.current;
50
+ if (!iframe) return;
51
+ if (urlRef.current) {
52
+ URL.revokeObjectURL(urlRef.current);
53
+ urlRef.current = null;
54
+ }
55
+ const url = URL.createObjectURL(new Blob([buffer], { type: "application/pdf" }));
56
+ urlRef.current = url;
57
+ iframe.onload = () => {
58
+ var _a, _b;
59
+ if (iframe.src === url) {
60
+ task.progress({ stage: "iframe-ready", message: "Ready to print" });
61
+ (_a = iframe.contentWindow) == null ? void 0 : _a.focus();
62
+ (_b = iframe.contentWindow) == null ? void 0 : _b.print();
63
+ task.progress({ stage: "printing", message: "Print dialog opened" });
64
+ task.resolve(buffer);
65
+ }
66
+ };
67
+ iframe.src = url;
68
+ });
63
69
  return () => {
64
- URL.revokeObjectURL(url);
70
+ unsubscribe();
71
+ if (urlRef.current) {
72
+ URL.revokeObjectURL(urlRef.current);
73
+ }
65
74
  };
66
- }, [pageResult.blob]);
67
- const handleLoad = () => {
68
- if (imageUrl) {
69
- URL.revokeObjectURL(imageUrl);
70
- }
71
- };
75
+ }, [printCapability, printPlugin]);
72
76
  return /* @__PURE__ */ jsx(
73
- "div",
77
+ "iframe",
74
78
  {
75
- style: {
76
- pageBreakAfter: "always",
77
- width: "210mm",
78
- minHeight: "297mm",
79
- margin: "0 auto",
80
- background: "white",
81
- position: "relative"
82
- },
83
- children: /* @__PURE__ */ jsx(
84
- "img",
85
- {
86
- src: imageUrl,
87
- onLoad: handleLoad,
88
- alt: `Page ${pageResult.pageIndex + 1}`,
89
- style: {
90
- width: "100%",
91
- height: "auto",
92
- display: "block",
93
- objectFit: "contain"
94
- }
95
- }
96
- )
79
+ ref: iframeRef,
80
+ style: { position: "absolute", display: "none" },
81
+ title: "Print Document",
82
+ src: "about:blank"
97
83
  }
98
84
  );
99
- };
100
- const PrintLayout = ({ pages }) => {
101
- return /* @__PURE__ */ jsxs(
102
- "div",
103
- {
104
- style: {
105
- fontFamily: "Arial, sans-serif",
106
- fontSize: "12px",
107
- lineHeight: "1.4",
108
- color: "#000",
109
- backgroundColor: "#fff"
110
- },
111
- children: [
112
- /* @__PURE__ */ jsx("style", { children: `
113
- @media print {
114
- body { margin: 0; padding: 0; }
115
- }
116
- ` }),
117
- pages.map((pageResult) => /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(PrintPage, { pageResult }) }, pageResult.pageIndex))
118
- ]
119
- }
120
- );
121
- };
122
- function PrintProvider({ children }) {
123
- const { provides: printCapability } = usePrintCapability();
124
- const iframeRef = useRef(null);
125
- const [progress, setProgress] = useState(null);
126
- const [isReady, setIsReady] = useState(false);
127
- const [isPrinting, setIsPrinting] = useState(false);
128
- const [pages, setPages] = useState([]);
129
- const executePrint = async (options) => {
130
- var _a;
131
- if (!printCapability) {
132
- throw new Error("Print capability not available");
133
- }
134
- if (!((_a = iframeRef.current) == null ? void 0 : _a.contentWindow)) {
135
- throw new Error("Print iframe not ready");
136
- }
137
- setIsPrinting(true);
138
- setProgress(null);
139
- setPages([]);
140
- setIsReady(false);
141
- try {
142
- const collectedPages = [];
143
- await printCapability.preparePrint(
144
- options,
145
- // Progress callback
146
- (progressUpdate) => {
147
- setProgress(progressUpdate);
148
- },
149
- // Page ready callback
150
- (pageResult) => {
151
- collectedPages.push(pageResult);
152
- setPages([...collectedPages]);
153
- }
154
- );
155
- await new Promise((resolve) => setTimeout(resolve, 500));
156
- const printWindow = iframeRef.current.contentWindow;
157
- printWindow.focus();
158
- printWindow.print();
159
- setProgress({
160
- current: (progress == null ? void 0 : progress.total) || 0,
161
- total: (progress == null ? void 0 : progress.total) || 0,
162
- status: "complete",
163
- message: "Print dialog opened"
164
- });
165
- } catch (error) {
166
- setProgress({
167
- current: 0,
168
- total: 0,
169
- status: "error",
170
- message: `Print failed: ${error instanceof Error ? error.message : "Unknown error"}`
171
- });
172
- throw error;
173
- } finally {
174
- setIsPrinting(false);
175
- }
176
- };
177
- useEffect(() => {
178
- var _a, _b;
179
- const iframe = iframeRef.current;
180
- const mountNode = (_b = (_a = iframe == null ? void 0 : iframe.contentWindow) == null ? void 0 : _a.document) == null ? void 0 : _b.body;
181
- if (mountNode && pages.length > 0) {
182
- render(/* @__PURE__ */ jsx(PrintLayout, { pages }), mountNode);
183
- setIsReady(true);
184
- return () => {
185
- if (mountNode) {
186
- render(null, mountNode);
187
- }
188
- };
189
- }
190
- }, [pages]);
191
- const contextValue = {
192
- parsePageRange: (printCapability == null ? void 0 : printCapability.parsePageRange) || (() => ({ pages: [], isValid: false })),
193
- executePrint,
194
- progress,
195
- isReady,
196
- isPrinting
197
- };
198
- return /* @__PURE__ */ jsxs(PrintContext.Provider, { value: contextValue, children: [
199
- children,
200
- /* @__PURE__ */ jsx(
201
- "iframe",
202
- {
203
- ref: iframeRef,
204
- style: {
205
- display: "none",
206
- width: "210mm",
207
- height: "297mm"
208
- },
209
- title: "Print Preview"
210
- }
211
- )
212
- ] });
213
- }
214
- function usePrintContext() {
215
- const context = useContext(PrintContext);
216
- if (!context) {
217
- throw new Error("usePrintContext must be used within a PrintProvider");
218
- }
219
- return context;
220
85
  }
221
- const usePrintAction = () => {
222
- const { executePrint, progress, isReady, isPrinting, parsePageRange } = usePrintContext();
223
- return {
224
- executePrint,
225
- progress,
226
- isReady,
227
- isPrinting,
228
- parsePageRange
229
- };
230
- };
86
+ const PrintPluginPackage = createPluginPackage(PrintPluginPackage$1).addUtility(PrintFrame).build();
231
87
  export {
232
- PrintProvider,
233
- usePrintAction,
88
+ PrintFrame,
89
+ PrintPluginPackage,
234
90
  usePrintCapability,
235
- usePrintContext,
236
91
  usePrintPlugin
237
92
  };
238
93
  //# sourceMappingURL=index.js.map