@embedpdf/plugin-print 1.0.0 → 1.0.1
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/preact/index.cjs
CHANGED
|
@@ -21,17 +21,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var preact_exports = {};
|
|
22
22
|
__export(preact_exports, {
|
|
23
23
|
PrintProvider: () => PrintProvider,
|
|
24
|
-
usePrint: () => usePrint,
|
|
25
24
|
usePrintAction: () => usePrintAction,
|
|
26
25
|
usePrintCapability: () => usePrintCapability,
|
|
27
|
-
usePrintContext: () => usePrintContext
|
|
26
|
+
usePrintContext: () => usePrintContext,
|
|
27
|
+
usePrintPlugin: () => usePrintPlugin
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(preact_exports);
|
|
30
30
|
|
|
31
31
|
// src/preact/hooks/use-print.ts
|
|
32
32
|
var import_preact = require("@embedpdf/core/preact");
|
|
33
33
|
var import_plugin_print = require("@embedpdf/plugin-print");
|
|
34
|
-
var
|
|
34
|
+
var usePrintPlugin = () => (0, import_preact.usePlugin)(import_plugin_print.PrintPlugin.id);
|
|
35
35
|
var usePrintCapability = () => (0, import_preact.useCapability)(import_plugin_print.PrintPlugin.id);
|
|
36
36
|
|
|
37
37
|
// src/preact/components/print.tsx
|
|
@@ -215,9 +215,9 @@ var usePrintAction = () => {
|
|
|
215
215
|
// Annotate the CommonJS export names for ESM import in node:
|
|
216
216
|
0 && (module.exports = {
|
|
217
217
|
PrintProvider,
|
|
218
|
-
usePrint,
|
|
219
218
|
usePrintAction,
|
|
220
219
|
usePrintCapability,
|
|
221
|
-
usePrintContext
|
|
220
|
+
usePrintContext,
|
|
221
|
+
usePrintPlugin
|
|
222
222
|
});
|
|
223
223
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +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
|
|
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 usePrintPlugin = () => 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,iBAAiB,UAAM,yBAAuB,gCAAY,EAAE;AAClE,IAAM,qBAAqB,UAAM,6BAA2B,gCAAY,EAAE;;;ACHjF,IAAAA,iBAAsC;AACtC,mBAAwD;AAoDlD;AAvCN,IAAM,mBAAe,8BAAwC,IAAI;AAUjE,IAAM,YAAY,CAAC,EAAE,WAAW,MAAsB;AACpD,QAAM,CAAC,UAAU,WAAW,QAAI,uB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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"]}
|
package/dist/preact/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import { PrintPlugin } from '@embedpdf/plugin-print';
|
|
|
3
3
|
import * as preact from 'preact';
|
|
4
4
|
import { ComponentChildren } from 'preact';
|
|
5
5
|
|
|
6
|
-
declare const
|
|
6
|
+
declare const usePrintPlugin: () => {
|
|
7
7
|
plugin: PrintPlugin | null;
|
|
8
8
|
isLoading: boolean;
|
|
9
9
|
ready: Promise<void>;
|
|
@@ -73,4 +73,4 @@ interface PrintProviderProps {
|
|
|
73
73
|
declare function PrintProvider({ children }: PrintProviderProps): preact.JSX.Element;
|
|
74
74
|
declare function usePrintContext(): PrintContextValue;
|
|
75
75
|
|
|
76
|
-
export { PrintProvider,
|
|
76
|
+
export { PrintProvider, usePrintAction, usePrintCapability, usePrintContext, usePrintPlugin };
|
package/dist/preact/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { PrintPlugin } from '@embedpdf/plugin-print';
|
|
|
3
3
|
import * as preact from 'preact';
|
|
4
4
|
import { ComponentChildren } from 'preact';
|
|
5
5
|
|
|
6
|
-
declare const
|
|
6
|
+
declare const usePrintPlugin: () => {
|
|
7
7
|
plugin: PrintPlugin | null;
|
|
8
8
|
isLoading: boolean;
|
|
9
9
|
ready: Promise<void>;
|
|
@@ -73,4 +73,4 @@ interface PrintProviderProps {
|
|
|
73
73
|
declare function PrintProvider({ children }: PrintProviderProps): preact.JSX.Element;
|
|
74
74
|
declare function usePrintContext(): PrintContextValue;
|
|
75
75
|
|
|
76
|
-
export { PrintProvider,
|
|
76
|
+
export { PrintProvider, usePrintAction, usePrintCapability, usePrintContext, usePrintPlugin };
|
package/dist/preact/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/preact/hooks/use-print.ts
|
|
2
2
|
import { useCapability, usePlugin } from "@embedpdf/core/preact";
|
|
3
3
|
import { PrintPlugin } from "@embedpdf/plugin-print";
|
|
4
|
-
var
|
|
4
|
+
var usePrintPlugin = () => usePlugin(PrintPlugin.id);
|
|
5
5
|
var usePrintCapability = () => useCapability(PrintPlugin.id);
|
|
6
6
|
|
|
7
7
|
// src/preact/components/print.tsx
|
|
@@ -184,9 +184,9 @@ var usePrintAction = () => {
|
|
|
184
184
|
};
|
|
185
185
|
export {
|
|
186
186
|
PrintProvider,
|
|
187
|
-
usePrint,
|
|
188
187
|
usePrintAction,
|
|
189
188
|
usePrintCapability,
|
|
190
|
-
usePrintContext
|
|
189
|
+
usePrintContext,
|
|
190
|
+
usePrintPlugin
|
|
191
191
|
};
|
|
192
192
|
//# sourceMappingURL=index.js.map
|
package/dist/preact/index.js.map
CHANGED
|
@@ -1 +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
|
|
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 usePrintPlugin = () => 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,iBAAiB,MAAM,UAAuB,YAAY,EAAE;AAClE,IAAM,qBAAqB,MAAM,cAA2B,YAAY,EAAE;;;ACHjF,SAAS,eAAe,cAAc;AACtC,SAAS,YAAY,QAAQ,WAAW,gBAAgB;AAoDlD,cAqBF,YArBE;AAvCN,IAAM,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A,oBAAc,KAAK;AAAA,IACrB;AAAA,EACF;AAGA,YAAU,MAAM;AACd,UAAM,SAAS,UAAU;AACzB,UAAM,YAAY,QAAQ,eAAe,UAAU;AAEnD,QAAI,aAAa,MAAM,SAAS,GAAG;AACjC,aAAO,oBAAC,eAAY,OAAc,GAAI,SAAS;AAC/C,iBAAW,IAAI;AAEf,aAAO,MAAM;AACX,YAAI,WAAW;AACb,iBAAO,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,qBAAC,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,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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-print",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"@types/react": "^18.2.0",
|
|
23
23
|
"tsup": "^8.0.0",
|
|
24
24
|
"typescript": "^5.0.0",
|
|
25
|
-
"@embedpdf/models": "1.0.
|
|
26
|
-
"@embedpdf/plugin-render": "1.0.
|
|
25
|
+
"@embedpdf/models": "1.0.1",
|
|
26
|
+
"@embedpdf/plugin-render": "1.0.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": ">=16.8.0",
|
|
30
30
|
"react-dom": ">=16.8.0",
|
|
31
31
|
"preact": "^10.26.4",
|
|
32
|
-
"@embedpdf/core": "1.0.
|
|
32
|
+
"@embedpdf/core": "1.0.1"
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
35
|
"dist",
|