@embedpdf/plugin-print 1.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.
- package/LICENSE +21 -0
- package/dist/index.cjs +299 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +78 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +267 -0
- package/dist/index.js.map +1 -0
- package/dist/preact/index.cjs +223 -0
- package/dist/preact/index.cjs.map +1 -0
- package/dist/preact/index.d.cts +76 -0
- package/dist/preact/index.d.ts +76 -0
- package/dist/preact/index.js +192 -0
- package/dist/preact/index.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/preact/index.ts
|
|
21
|
+
var preact_exports = {};
|
|
22
|
+
__export(preact_exports, {
|
|
23
|
+
PrintProvider: () => PrintProvider,
|
|
24
|
+
usePrint: () => usePrint,
|
|
25
|
+
usePrintAction: () => usePrintAction,
|
|
26
|
+
usePrintCapability: () => usePrintCapability,
|
|
27
|
+
usePrintContext: () => usePrintContext
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(preact_exports);
|
|
30
|
+
|
|
31
|
+
// src/preact/hooks/use-print.ts
|
|
32
|
+
var import_preact = require("@embedpdf/core/preact");
|
|
33
|
+
var import_plugin_print = require("@embedpdf/plugin-print");
|
|
34
|
+
var usePrint = () => (0, import_preact.usePlugin)(import_plugin_print.PrintPlugin.id);
|
|
35
|
+
var usePrintCapability = () => (0, import_preact.useCapability)(import_plugin_print.PrintPlugin.id);
|
|
36
|
+
|
|
37
|
+
// src/preact/components/print.tsx
|
|
38
|
+
var import_preact2 = require("preact");
|
|
39
|
+
var import_hooks = require("preact/hooks");
|
|
40
|
+
var import_jsx_runtime = require("preact/jsx-runtime");
|
|
41
|
+
var PrintContext = (0, import_preact2.createContext)(null);
|
|
42
|
+
var PrintPage = ({ pageResult }) => {
|
|
43
|
+
const [imageUrl, setImageUrl] = (0, import_hooks.useState)("");
|
|
44
|
+
(0, import_hooks.useEffect)(() => {
|
|
45
|
+
const url = URL.createObjectURL(pageResult.blob);
|
|
46
|
+
setImageUrl(url);
|
|
47
|
+
return () => {
|
|
48
|
+
URL.revokeObjectURL(url);
|
|
49
|
+
};
|
|
50
|
+
}, [pageResult.blob]);
|
|
51
|
+
const handleLoad = () => {
|
|
52
|
+
if (imageUrl) {
|
|
53
|
+
URL.revokeObjectURL(imageUrl);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
57
|
+
"div",
|
|
58
|
+
{
|
|
59
|
+
style: {
|
|
60
|
+
pageBreakAfter: "always",
|
|
61
|
+
width: "210mm",
|
|
62
|
+
minHeight: "297mm",
|
|
63
|
+
margin: "0 auto",
|
|
64
|
+
background: "white",
|
|
65
|
+
position: "relative"
|
|
66
|
+
},
|
|
67
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
68
|
+
"img",
|
|
69
|
+
{
|
|
70
|
+
src: imageUrl,
|
|
71
|
+
onLoad: handleLoad,
|
|
72
|
+
alt: `Page ${pageResult.pageIndex + 1}`,
|
|
73
|
+
style: {
|
|
74
|
+
width: "100%",
|
|
75
|
+
height: "auto",
|
|
76
|
+
display: "block",
|
|
77
|
+
objectFit: "contain"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
var PrintLayout = ({ pages }) => {
|
|
85
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
86
|
+
"div",
|
|
87
|
+
{
|
|
88
|
+
style: {
|
|
89
|
+
fontFamily: "Arial, sans-serif",
|
|
90
|
+
fontSize: "12px",
|
|
91
|
+
lineHeight: "1.4",
|
|
92
|
+
color: "#000",
|
|
93
|
+
backgroundColor: "#fff"
|
|
94
|
+
},
|
|
95
|
+
children: [
|
|
96
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: `
|
|
97
|
+
@media print {
|
|
98
|
+
body { margin: 0; padding: 0; }
|
|
99
|
+
}
|
|
100
|
+
` }),
|
|
101
|
+
pages.map((pageResult) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PrintPage, { pageResult }) }, pageResult.pageIndex))
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
function PrintProvider({ children }) {
|
|
107
|
+
const { provides: printCapability } = usePrintCapability();
|
|
108
|
+
const iframeRef = (0, import_hooks.useRef)(null);
|
|
109
|
+
const [progress, setProgress] = (0, import_hooks.useState)(null);
|
|
110
|
+
const [isReady, setIsReady] = (0, import_hooks.useState)(false);
|
|
111
|
+
const [isPrinting, setIsPrinting] = (0, import_hooks.useState)(false);
|
|
112
|
+
const [pages, setPages] = (0, import_hooks.useState)([]);
|
|
113
|
+
const executePrint = async (options) => {
|
|
114
|
+
if (!printCapability) {
|
|
115
|
+
throw new Error("Print capability not available");
|
|
116
|
+
}
|
|
117
|
+
if (!iframeRef.current?.contentWindow) {
|
|
118
|
+
throw new Error("Print iframe not ready");
|
|
119
|
+
}
|
|
120
|
+
setIsPrinting(true);
|
|
121
|
+
setProgress(null);
|
|
122
|
+
setPages([]);
|
|
123
|
+
setIsReady(false);
|
|
124
|
+
try {
|
|
125
|
+
const collectedPages = [];
|
|
126
|
+
await printCapability.preparePrint(
|
|
127
|
+
options,
|
|
128
|
+
// Progress callback
|
|
129
|
+
(progressUpdate) => {
|
|
130
|
+
setProgress(progressUpdate);
|
|
131
|
+
},
|
|
132
|
+
// Page ready callback
|
|
133
|
+
(pageResult) => {
|
|
134
|
+
collectedPages.push(pageResult);
|
|
135
|
+
setPages([...collectedPages]);
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
139
|
+
const printWindow = iframeRef.current.contentWindow;
|
|
140
|
+
printWindow.focus();
|
|
141
|
+
printWindow.print();
|
|
142
|
+
setProgress({
|
|
143
|
+
current: progress?.total || 0,
|
|
144
|
+
total: progress?.total || 0,
|
|
145
|
+
status: "complete",
|
|
146
|
+
message: "Print dialog opened"
|
|
147
|
+
});
|
|
148
|
+
} catch (error) {
|
|
149
|
+
setProgress({
|
|
150
|
+
current: 0,
|
|
151
|
+
total: 0,
|
|
152
|
+
status: "error",
|
|
153
|
+
message: `Print failed: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
154
|
+
});
|
|
155
|
+
throw error;
|
|
156
|
+
} finally {
|
|
157
|
+
setIsPrinting(false);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
(0, import_hooks.useEffect)(() => {
|
|
161
|
+
const iframe = iframeRef.current;
|
|
162
|
+
const mountNode = iframe?.contentWindow?.document?.body;
|
|
163
|
+
if (mountNode && pages.length > 0) {
|
|
164
|
+
(0, import_preact2.render)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PrintLayout, { pages }), mountNode);
|
|
165
|
+
setIsReady(true);
|
|
166
|
+
return () => {
|
|
167
|
+
if (mountNode) {
|
|
168
|
+
(0, import_preact2.render)(null, mountNode);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}, [pages]);
|
|
173
|
+
const contextValue = {
|
|
174
|
+
parsePageRange: printCapability?.parsePageRange || (() => ({ pages: [], isValid: false })),
|
|
175
|
+
executePrint,
|
|
176
|
+
progress,
|
|
177
|
+
isReady,
|
|
178
|
+
isPrinting
|
|
179
|
+
};
|
|
180
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(PrintContext.Provider, { value: contextValue, children: [
|
|
181
|
+
children,
|
|
182
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
183
|
+
"iframe",
|
|
184
|
+
{
|
|
185
|
+
ref: iframeRef,
|
|
186
|
+
style: {
|
|
187
|
+
display: "none",
|
|
188
|
+
width: "210mm",
|
|
189
|
+
height: "297mm"
|
|
190
|
+
},
|
|
191
|
+
title: "Print Preview"
|
|
192
|
+
}
|
|
193
|
+
)
|
|
194
|
+
] });
|
|
195
|
+
}
|
|
196
|
+
function usePrintContext() {
|
|
197
|
+
const context = (0, import_hooks.useContext)(PrintContext);
|
|
198
|
+
if (!context) {
|
|
199
|
+
throw new Error("usePrintContext must be used within a PrintProvider");
|
|
200
|
+
}
|
|
201
|
+
return context;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/preact/hooks/use-print-action.ts
|
|
205
|
+
var usePrintAction = () => {
|
|
206
|
+
const { executePrint, progress, isReady, isPrinting, parsePageRange } = usePrintContext();
|
|
207
|
+
return {
|
|
208
|
+
executePrint,
|
|
209
|
+
progress,
|
|
210
|
+
isReady,
|
|
211
|
+
isPrinting,
|
|
212
|
+
parsePageRange
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
216
|
+
0 && (module.exports = {
|
|
217
|
+
PrintProvider,
|
|
218
|
+
usePrint,
|
|
219
|
+
usePrintAction,
|
|
220
|
+
usePrintCapability,
|
|
221
|
+
usePrintContext
|
|
222
|
+
});
|
|
223
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/preact/index.ts","../../src/preact/hooks/use-print.ts","../../src/preact/components/print.tsx","../../src/preact/hooks/use-print-action.ts"],"sourcesContent":["export * from './hooks';\nexport * from './components';\n","import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { PrintPlugin } from '@embedpdf/plugin-print';\n\nexport const usePrint = () => usePlugin<PrintPlugin>(PrintPlugin.id);\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n","/** @jsxImportSource preact */\nimport { createContext, render } from 'preact';\nimport { useContext, useRef, useEffect, useState } from 'preact/hooks';\nimport { ComponentChildren } from 'preact';\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: ComponentChildren;\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyC;AACzC,0BAA4B;AAErB,IAAM,WAAW,UAAM,yBAAuB,gCAAY,EAAE;AAC5D,IAAM,qBAAqB,UAAM,6BAA2B,gCAAY,EAAE;;;ACHjF,IAAAA,iBAAsC;AACtC,mBAAwD;AAoDlD;AAvCN,IAAM,mBAAe,8BAAwC,IAAI;AAUjE,IA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A,IACrB;AAAA,EACF;AAGA,8BAAU,MAAM;AACd,UAAM,SAAS,UAAU;AACzB,UAAM,YAAY,QAAQ,eAAe,UAAU;AAEnD,QAAI,aAAa,MAAM,SAAS,GAAG;AACjC,iCAAO,4CAAC,eAAY,OAAc,GAAI,SAAS;AAC/C,iBAAW,IAAI;AAEf,aAAO,MAAM;AACX,YAAI,WAAW;AACb,qCAAO,MAAM,SAAS;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,KAAK,CAAC;AAEV,QAAM,eAAkC;AAAA,IACtC,gBAAgB,iBAAiB,mBAAmB,OAAO,EAAE,OAAO,CAAC,GAAG,SAAS,MAAM;AAAA,IACvF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SACE,6CAAC,aAAa,UAAb,EAAsB,OAAO,cAC3B;AAAA;AAAA,IACD;AAAA,MAAC;AAAA;AAAA,QACC,KAAK;AAAA,QACL,OAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO;AAAA,UACP,QAAQ;AAAA,QACV;AAAA,QACA,OAAM;AAAA;AAAA,IACR;AAAA,KACF;AAEJ;AAEO,SAAS,kBAAqC;AACnD,QAAM,cAAU,yBAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACA,SAAO;AACT;;;AChNO,IAAM,iBAAiB,MAAM;AAClC,QAAM,EAAE,cAAc,UAAU,SAAS,YAAY,eAAe,IAAI,gBAAgB;AAExF,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["import_preact"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as _embedpdf_plugin_print from '@embedpdf/plugin-print';
|
|
2
|
+
import { PrintPlugin } from '@embedpdf/plugin-print';
|
|
3
|
+
import * as preact from 'preact';
|
|
4
|
+
import { ComponentChildren } from 'preact';
|
|
5
|
+
|
|
6
|
+
declare const usePrint: () => {
|
|
7
|
+
plugin: PrintPlugin | null;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
ready: Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
declare const usePrintCapability: () => {
|
|
12
|
+
provides: Readonly<_embedpdf_plugin_print.PrintCapability> | null;
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
ready: Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
declare enum PrintQuality {
|
|
18
|
+
Normal = "normal",
|
|
19
|
+
High = "high"
|
|
20
|
+
}
|
|
21
|
+
declare enum PageRangeType {
|
|
22
|
+
Current = "current",
|
|
23
|
+
All = "all",
|
|
24
|
+
Custom = "custom"
|
|
25
|
+
}
|
|
26
|
+
interface PageRangeCurrent {
|
|
27
|
+
type: PageRangeType.Current;
|
|
28
|
+
currentPage: number;
|
|
29
|
+
}
|
|
30
|
+
interface PageRangeAll {
|
|
31
|
+
type: PageRangeType.All;
|
|
32
|
+
}
|
|
33
|
+
interface PageRangeCustom {
|
|
34
|
+
type: PageRangeType.Custom;
|
|
35
|
+
pages: number[];
|
|
36
|
+
}
|
|
37
|
+
type PageRange = PageRangeCurrent | PageRangeAll | PageRangeCustom;
|
|
38
|
+
interface PrintOptions {
|
|
39
|
+
pageRange: PageRange;
|
|
40
|
+
includeAnnotations: boolean;
|
|
41
|
+
quality: PrintQuality;
|
|
42
|
+
}
|
|
43
|
+
interface PrintProgress {
|
|
44
|
+
current: number;
|
|
45
|
+
total: number;
|
|
46
|
+
status: 'preparing' | 'rendering' | 'complete' | 'error';
|
|
47
|
+
message?: string;
|
|
48
|
+
}
|
|
49
|
+
interface ParsedPageRange {
|
|
50
|
+
pages: number[];
|
|
51
|
+
isValid: boolean;
|
|
52
|
+
error?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
declare const usePrintAction: () => {
|
|
56
|
+
executePrint: (options: PrintOptions) => Promise<void>;
|
|
57
|
+
progress: PrintProgress | null;
|
|
58
|
+
isReady: boolean;
|
|
59
|
+
isPrinting: boolean;
|
|
60
|
+
parsePageRange: (rangeString: string) => ParsedPageRange;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
interface PrintContextValue {
|
|
64
|
+
parsePageRange: (rangeString: string) => ParsedPageRange;
|
|
65
|
+
executePrint: (options: PrintOptions) => Promise<void>;
|
|
66
|
+
progress: PrintProgress | null;
|
|
67
|
+
isReady: boolean;
|
|
68
|
+
isPrinting: boolean;
|
|
69
|
+
}
|
|
70
|
+
interface PrintProviderProps {
|
|
71
|
+
children: ComponentChildren;
|
|
72
|
+
}
|
|
73
|
+
declare function PrintProvider({ children }: PrintProviderProps): preact.JSX.Element;
|
|
74
|
+
declare function usePrintContext(): PrintContextValue;
|
|
75
|
+
|
|
76
|
+
export { PrintProvider, usePrint, usePrintAction, usePrintCapability, usePrintContext };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as _embedpdf_plugin_print from '@embedpdf/plugin-print';
|
|
2
|
+
import { PrintPlugin } from '@embedpdf/plugin-print';
|
|
3
|
+
import * as preact from 'preact';
|
|
4
|
+
import { ComponentChildren } from 'preact';
|
|
5
|
+
|
|
6
|
+
declare const usePrint: () => {
|
|
7
|
+
plugin: PrintPlugin | null;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
ready: Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
declare const usePrintCapability: () => {
|
|
12
|
+
provides: Readonly<_embedpdf_plugin_print.PrintCapability> | null;
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
ready: Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
declare enum PrintQuality {
|
|
18
|
+
Normal = "normal",
|
|
19
|
+
High = "high"
|
|
20
|
+
}
|
|
21
|
+
declare enum PageRangeType {
|
|
22
|
+
Current = "current",
|
|
23
|
+
All = "all",
|
|
24
|
+
Custom = "custom"
|
|
25
|
+
}
|
|
26
|
+
interface PageRangeCurrent {
|
|
27
|
+
type: PageRangeType.Current;
|
|
28
|
+
currentPage: number;
|
|
29
|
+
}
|
|
30
|
+
interface PageRangeAll {
|
|
31
|
+
type: PageRangeType.All;
|
|
32
|
+
}
|
|
33
|
+
interface PageRangeCustom {
|
|
34
|
+
type: PageRangeType.Custom;
|
|
35
|
+
pages: number[];
|
|
36
|
+
}
|
|
37
|
+
type PageRange = PageRangeCurrent | PageRangeAll | PageRangeCustom;
|
|
38
|
+
interface PrintOptions {
|
|
39
|
+
pageRange: PageRange;
|
|
40
|
+
includeAnnotations: boolean;
|
|
41
|
+
quality: PrintQuality;
|
|
42
|
+
}
|
|
43
|
+
interface PrintProgress {
|
|
44
|
+
current: number;
|
|
45
|
+
total: number;
|
|
46
|
+
status: 'preparing' | 'rendering' | 'complete' | 'error';
|
|
47
|
+
message?: string;
|
|
48
|
+
}
|
|
49
|
+
interface ParsedPageRange {
|
|
50
|
+
pages: number[];
|
|
51
|
+
isValid: boolean;
|
|
52
|
+
error?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
declare const usePrintAction: () => {
|
|
56
|
+
executePrint: (options: PrintOptions) => Promise<void>;
|
|
57
|
+
progress: PrintProgress | null;
|
|
58
|
+
isReady: boolean;
|
|
59
|
+
isPrinting: boolean;
|
|
60
|
+
parsePageRange: (rangeString: string) => ParsedPageRange;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
interface PrintContextValue {
|
|
64
|
+
parsePageRange: (rangeString: string) => ParsedPageRange;
|
|
65
|
+
executePrint: (options: PrintOptions) => Promise<void>;
|
|
66
|
+
progress: PrintProgress | null;
|
|
67
|
+
isReady: boolean;
|
|
68
|
+
isPrinting: boolean;
|
|
69
|
+
}
|
|
70
|
+
interface PrintProviderProps {
|
|
71
|
+
children: ComponentChildren;
|
|
72
|
+
}
|
|
73
|
+
declare function PrintProvider({ children }: PrintProviderProps): preact.JSX.Element;
|
|
74
|
+
declare function usePrintContext(): PrintContextValue;
|
|
75
|
+
|
|
76
|
+
export { PrintProvider, usePrint, usePrintAction, usePrintCapability, usePrintContext };
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// src/preact/hooks/use-print.ts
|
|
2
|
+
import { useCapability, usePlugin } from "@embedpdf/core/preact";
|
|
3
|
+
import { PrintPlugin } from "@embedpdf/plugin-print";
|
|
4
|
+
var usePrint = () => usePlugin(PrintPlugin.id);
|
|
5
|
+
var usePrintCapability = () => useCapability(PrintPlugin.id);
|
|
6
|
+
|
|
7
|
+
// src/preact/components/print.tsx
|
|
8
|
+
import { createContext, render } from "preact";
|
|
9
|
+
import { useContext, useRef, useEffect, useState } from "preact/hooks";
|
|
10
|
+
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
11
|
+
var PrintContext = createContext(null);
|
|
12
|
+
var PrintPage = ({ pageResult }) => {
|
|
13
|
+
const [imageUrl, setImageUrl] = useState("");
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const url = URL.createObjectURL(pageResult.blob);
|
|
16
|
+
setImageUrl(url);
|
|
17
|
+
return () => {
|
|
18
|
+
URL.revokeObjectURL(url);
|
|
19
|
+
};
|
|
20
|
+
}, [pageResult.blob]);
|
|
21
|
+
const handleLoad = () => {
|
|
22
|
+
if (imageUrl) {
|
|
23
|
+
URL.revokeObjectURL(imageUrl);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return /* @__PURE__ */ jsx(
|
|
27
|
+
"div",
|
|
28
|
+
{
|
|
29
|
+
style: {
|
|
30
|
+
pageBreakAfter: "always",
|
|
31
|
+
width: "210mm",
|
|
32
|
+
minHeight: "297mm",
|
|
33
|
+
margin: "0 auto",
|
|
34
|
+
background: "white",
|
|
35
|
+
position: "relative"
|
|
36
|
+
},
|
|
37
|
+
children: /* @__PURE__ */ jsx(
|
|
38
|
+
"img",
|
|
39
|
+
{
|
|
40
|
+
src: imageUrl,
|
|
41
|
+
onLoad: handleLoad,
|
|
42
|
+
alt: `Page ${pageResult.pageIndex + 1}`,
|
|
43
|
+
style: {
|
|
44
|
+
width: "100%",
|
|
45
|
+
height: "auto",
|
|
46
|
+
display: "block",
|
|
47
|
+
objectFit: "contain"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
var PrintLayout = ({ pages }) => {
|
|
55
|
+
return /* @__PURE__ */ jsxs(
|
|
56
|
+
"div",
|
|
57
|
+
{
|
|
58
|
+
style: {
|
|
59
|
+
fontFamily: "Arial, sans-serif",
|
|
60
|
+
fontSize: "12px",
|
|
61
|
+
lineHeight: "1.4",
|
|
62
|
+
color: "#000",
|
|
63
|
+
backgroundColor: "#fff"
|
|
64
|
+
},
|
|
65
|
+
children: [
|
|
66
|
+
/* @__PURE__ */ jsx("style", { children: `
|
|
67
|
+
@media print {
|
|
68
|
+
body { margin: 0; padding: 0; }
|
|
69
|
+
}
|
|
70
|
+
` }),
|
|
71
|
+
pages.map((pageResult) => /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(PrintPage, { pageResult }) }, pageResult.pageIndex))
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
function PrintProvider({ children }) {
|
|
77
|
+
const { provides: printCapability } = usePrintCapability();
|
|
78
|
+
const iframeRef = useRef(null);
|
|
79
|
+
const [progress, setProgress] = useState(null);
|
|
80
|
+
const [isReady, setIsReady] = useState(false);
|
|
81
|
+
const [isPrinting, setIsPrinting] = useState(false);
|
|
82
|
+
const [pages, setPages] = useState([]);
|
|
83
|
+
const executePrint = async (options) => {
|
|
84
|
+
if (!printCapability) {
|
|
85
|
+
throw new Error("Print capability not available");
|
|
86
|
+
}
|
|
87
|
+
if (!iframeRef.current?.contentWindow) {
|
|
88
|
+
throw new Error("Print iframe not ready");
|
|
89
|
+
}
|
|
90
|
+
setIsPrinting(true);
|
|
91
|
+
setProgress(null);
|
|
92
|
+
setPages([]);
|
|
93
|
+
setIsReady(false);
|
|
94
|
+
try {
|
|
95
|
+
const collectedPages = [];
|
|
96
|
+
await printCapability.preparePrint(
|
|
97
|
+
options,
|
|
98
|
+
// Progress callback
|
|
99
|
+
(progressUpdate) => {
|
|
100
|
+
setProgress(progressUpdate);
|
|
101
|
+
},
|
|
102
|
+
// Page ready callback
|
|
103
|
+
(pageResult) => {
|
|
104
|
+
collectedPages.push(pageResult);
|
|
105
|
+
setPages([...collectedPages]);
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
109
|
+
const printWindow = iframeRef.current.contentWindow;
|
|
110
|
+
printWindow.focus();
|
|
111
|
+
printWindow.print();
|
|
112
|
+
setProgress({
|
|
113
|
+
current: progress?.total || 0,
|
|
114
|
+
total: progress?.total || 0,
|
|
115
|
+
status: "complete",
|
|
116
|
+
message: "Print dialog opened"
|
|
117
|
+
});
|
|
118
|
+
} catch (error) {
|
|
119
|
+
setProgress({
|
|
120
|
+
current: 0,
|
|
121
|
+
total: 0,
|
|
122
|
+
status: "error",
|
|
123
|
+
message: `Print failed: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
124
|
+
});
|
|
125
|
+
throw error;
|
|
126
|
+
} finally {
|
|
127
|
+
setIsPrinting(false);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
const iframe = iframeRef.current;
|
|
132
|
+
const mountNode = iframe?.contentWindow?.document?.body;
|
|
133
|
+
if (mountNode && pages.length > 0) {
|
|
134
|
+
render(/* @__PURE__ */ jsx(PrintLayout, { pages }), mountNode);
|
|
135
|
+
setIsReady(true);
|
|
136
|
+
return () => {
|
|
137
|
+
if (mountNode) {
|
|
138
|
+
render(null, mountNode);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}, [pages]);
|
|
143
|
+
const contextValue = {
|
|
144
|
+
parsePageRange: printCapability?.parsePageRange || (() => ({ pages: [], isValid: false })),
|
|
145
|
+
executePrint,
|
|
146
|
+
progress,
|
|
147
|
+
isReady,
|
|
148
|
+
isPrinting
|
|
149
|
+
};
|
|
150
|
+
return /* @__PURE__ */ jsxs(PrintContext.Provider, { value: contextValue, children: [
|
|
151
|
+
children,
|
|
152
|
+
/* @__PURE__ */ jsx(
|
|
153
|
+
"iframe",
|
|
154
|
+
{
|
|
155
|
+
ref: iframeRef,
|
|
156
|
+
style: {
|
|
157
|
+
display: "none",
|
|
158
|
+
width: "210mm",
|
|
159
|
+
height: "297mm"
|
|
160
|
+
},
|
|
161
|
+
title: "Print Preview"
|
|
162
|
+
}
|
|
163
|
+
)
|
|
164
|
+
] });
|
|
165
|
+
}
|
|
166
|
+
function usePrintContext() {
|
|
167
|
+
const context = useContext(PrintContext);
|
|
168
|
+
if (!context) {
|
|
169
|
+
throw new Error("usePrintContext must be used within a PrintProvider");
|
|
170
|
+
}
|
|
171
|
+
return context;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/preact/hooks/use-print-action.ts
|
|
175
|
+
var usePrintAction = () => {
|
|
176
|
+
const { executePrint, progress, isReady, isPrinting, parsePageRange } = usePrintContext();
|
|
177
|
+
return {
|
|
178
|
+
executePrint,
|
|
179
|
+
progress,
|
|
180
|
+
isReady,
|
|
181
|
+
isPrinting,
|
|
182
|
+
parsePageRange
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
export {
|
|
186
|
+
PrintProvider,
|
|
187
|
+
usePrint,
|
|
188
|
+
usePrintAction,
|
|
189
|
+
usePrintCapability,
|
|
190
|
+
usePrintContext
|
|
191
|
+
};
|
|
192
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/preact/hooks/use-print.ts","../../src/preact/components/print.tsx","../../src/preact/hooks/use-print-action.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { PrintPlugin } from '@embedpdf/plugin-print';\n\nexport const usePrint = () => usePlugin<PrintPlugin>(PrintPlugin.id);\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n","/** @jsxImportSource preact */\nimport { createContext, render } from 'preact';\nimport { useContext, useRef, useEffect, useState } from 'preact/hooks';\nimport { ComponentChildren } from 'preact';\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: ComponentChildren;\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"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,mBAAmB;AAErB,IAAM,WAAW,MAAM,UAAuB,YAAY,EAAE;AAC5D,IAAM,qBAAqB,MAAM,cAA2B,YAAY,EAAE;;;ACHjF,SAAS,eAAe,cAAc;AACtC,SAAS,YAAY,QAAQ,WAAW,gBAAgB;AAoDlD,cAqBF,YArBE;AAvCN,IAAM,eAAe,cAAwC,IAAI;AAUjE,IAAM,YAAY,CAAC,EAAE,WAAW,MAAsB;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,EACF,GAAG,CAAC,WAAW,IAAI,CAAC;AAEpB,QAAM,aAAa,MAAM;AACvB,QAAI,UAAU;AACZ,UAAI,gBAAgB,QAAQ;AAAA,IAC9B;AAAA,EACF;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL,gBAAgB;AAAA,QAChB,OAAO;AAAA,QACP,WAAW;AAAA,QACX,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ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AsB,OAAO,cAC3B;AAAA;AAAA,IACD;AAAA,MAAC;AAAA;AAAA,QACC,KAAK;AAAA,QACL,OAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO;AAAA,UACP,QAAQ;AAAA,QACV;AAAA,QACA,OAAM;AAAA;AAAA,IACR;AAAA,KACF;AAEJ;AAEO,SAAS,kBAAqC;AACnD,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACA,SAAO;AACT;;;AChNO,IAAM,iBAAiB,MAAM;AAClC,QAAM,EAAE,cAAc,UAAU,SAAS,YAAY,eAAe,IAAI,gBAAgB;AAExF,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@embedpdf/plugin-print",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
"./preact": {
|
|
15
|
+
"types": "./dist/preact/index.d.ts",
|
|
16
|
+
"import": "./dist/preact/index.js",
|
|
17
|
+
"require": "./dist/preact/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/react": "^18.2.0",
|
|
23
|
+
"tsup": "^8.0.0",
|
|
24
|
+
"typescript": "^5.0.0",
|
|
25
|
+
"@embedpdf/models": "1.0.0",
|
|
26
|
+
"@embedpdf/plugin-render": "1.0.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": ">=16.8.0",
|
|
30
|
+
"react-dom": ">=16.8.0",
|
|
31
|
+
"preact": "^10.26.4",
|
|
32
|
+
"@embedpdf/core": "1.0.0"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/embedpdf/embed-pdf-viewer",
|
|
41
|
+
"directory": "packages/plugin-print"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://www.embedpdf.com/docs",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/embedpdf/embed-pdf-viewer/issues"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "PROJECT_CWD=$(pwd) pnpm -w p:build",
|
|
52
|
+
"build:watch": "PROJECT_CWD=$(pwd) pnpm -w p:build:watch",
|
|
53
|
+
"clean": "PROJECT_CWD=$(pwd) pnpm -w p:clean",
|
|
54
|
+
"lint": "PROJECT_CWD=$(pwd) pnpm -w p:lint",
|
|
55
|
+
"lint:fix": "PROJECT_CWD=$(pwd) pnpm -w p:lint:fix",
|
|
56
|
+
"typecheck": "PROJECT_CWD=$(pwd) pnpm -w p:typecheck"
|
|
57
|
+
}
|
|
58
|
+
}
|