@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.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -149
- package/dist/index.js.map +1 -1
- package/dist/lib/print-plugin.d.ts +9 -11
- package/dist/lib/types.d.ts +19 -50
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +47 -174
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +49 -194
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/print.d.ts +1 -15
- package/dist/shared-preact/hooks/index.d.ts +0 -1
- package/dist/shared-preact/index.d.ts +2 -0
- package/dist/shared-react/components/print.d.ts +1 -15
- package/dist/shared-react/hooks/index.d.ts +0 -1
- package/dist/shared-react/index.d.ts +2 -0
- package/dist/vue/components/index.d.ts +1 -0
- package/dist/vue/components/print.vue.d.ts +2 -0
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-print.d.ts +3 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +8 -0
- package/dist/vue/index.js +64 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +14 -7
- package/dist/shared-preact/hooks/use-print-action.d.ts +0 -8
- package/dist/shared-react/hooks/use-print-action.d.ts +0 -8
package/dist/preact/index.js
CHANGED
|
@@ -1,189 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PrintPlugin } from "@embedpdf/plugin-print";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
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
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
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
|
-
|
|
13
|
-
|
|
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
|
-
|
|
39
|
+
unsubscribe();
|
|
40
|
+
if (urlRef.current) {
|
|
41
|
+
URL.revokeObjectURL(urlRef.current);
|
|
42
|
+
}
|
|
16
43
|
};
|
|
17
|
-
}, [
|
|
18
|
-
const handleLoad = () => {
|
|
19
|
-
if (imageUrl) {
|
|
20
|
-
URL.revokeObjectURL(imageUrl);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
44
|
+
}, [printCapability, printPlugin]);
|
|
23
45
|
return /* @__PURE__ */ jsx(
|
|
24
|
-
"
|
|
46
|
+
"iframe",
|
|
25
47
|
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
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
|
-
|
|
184
|
-
|
|
57
|
+
PrintFrame,
|
|
58
|
+
PrintPluginPackage,
|
|
185
59
|
usePrintCapability,
|
|
186
|
-
usePrintContext,
|
|
187
60
|
usePrintPlugin
|
|
188
61
|
};
|
|
189
62
|
//# sourceMappingURL=index.js.map
|
package/dist/preact/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-print.ts","../../src/shared/components/print.tsx","../../src/shared/
|
|
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;"}
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core
|
|
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
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -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":"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","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]}
|
package/dist/react/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PrintPlugin } from "@embedpdf/plugin-print";
|
|
3
|
-
|
|
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 {
|
|
6
|
-
|
|
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
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
|
|
70
|
+
unsubscribe();
|
|
71
|
+
if (urlRef.current) {
|
|
72
|
+
URL.revokeObjectURL(urlRef.current);
|
|
73
|
+
}
|
|
65
74
|
};
|
|
66
|
-
}, [
|
|
67
|
-
const handleLoad = () => {
|
|
68
|
-
if (imageUrl) {
|
|
69
|
-
URL.revokeObjectURL(imageUrl);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
75
|
+
}, [printCapability, printPlugin]);
|
|
72
76
|
return /* @__PURE__ */ jsx(
|
|
73
|
-
"
|
|
77
|
+
"iframe",
|
|
74
78
|
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
|
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
|
-
|
|
233
|
-
|
|
88
|
+
PrintFrame,
|
|
89
|
+
PrintPluginPackage,
|
|
234
90
|
usePrintCapability,
|
|
235
|
-
usePrintContext,
|
|
236
91
|
usePrintPlugin
|
|
237
92
|
};
|
|
238
93
|
//# sourceMappingURL=index.js.map
|