@embedpdf/plugin-print 1.0.19 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","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":["createRoot"],"mappings":";;;;;AAGO,MAAM,iBAAiB,MAAM,UAAuB,YAAY,EAAE;AAClE,MAAM,qBAAqB,MAAM,cAA2B,YAAY,EAAE;;;;;;ACFjF,MAAI,IAAI;AACR,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,WAAkB,aAAG,EAAE;AACvB,WAAmB,cAAG,EAAE;AAAA,EAC1B,OAAO;AACL,QAAI,IAAI,EAAE;AACV,wBAAqB,SAAS,GAAG,GAAG;AAClC,QAAE,wBAAwB;AAC1B,UAAI;AACF,eAAO,EAAE,WAAW,GAAG,CAAC;AAAA,MAC9B,UAAc;AACR,UAAE,wBAAwB;AAAA,MAChC;AAAA,IACG;AACD,WAAA,cAAsB,SAAS,GAAG,GAAG,GAAG;AACtC,QAAE,wBAAwB;AAC1B,UAAI;AACF,eAAO,EAAE,YAAY,GAAG,GAAG,CAAC;AAAA,MAClC,UAAc;AACR,UAAE,wBAAwB;AAAA,MAChC;AAAA,IACG;AAAA,EACH;;;;AClBA,MAAM,8BAAc,QAAsB;AAE1B,SAAA,OAAO,OAAyB,WAAiC;AAC/E,MAAI,CAAC,UAAW;AAEhB,MAAI,UAAU,MAAM;AAEZ,UAAA,OAAO,QAAQ,IAAI,SAAS;AAClC,QAAI,MAAM;AACR,WAAK,QAAQ;AACb,cAAQ,OAAO,SAAS;AAAA,IAAA;AAAA,EAC1B,OACK;AAED,QAAA,OAAO,QAAQ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M,EAAE,cAAc,UAAU,SAAS,YAAY,mBAAmB,gBAAgB;AAEjF,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","x_google_ignoreList":[1]}
1
+ {"version":3,"file":"index.js","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":["BasePrintPackage"],"mappings":";;;;;;;;;;;;AAEA,MAAI,IAAI;AACR,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,WAAkB,aAAG,EAAE;AACvB,WAAmB,cAAG,EAAE;AAAA,EAC1B,OAAO;AACL,QAAI,IAAI,EAAE;AACV,wBAAqB,SAAS,GAAG,GAAG;AAClC,QAAE,wBAAwB;AAC1B,UAAI;AACF,eAAO,EAAE,WAAW,GAAG,CAAC;AAAA,MAC9B,UAAc;AACR,UAAE,wBAAwB;AAAA,MAChC;AAAA,IACG;AACD,WAAA,cAAsB,SAAS,GAAG,GAAG,GAAG;AACtC,QAAE,wBAAwB;AAC1B,UAAI;AACF,eAAO,EAAE,YAAY,GAAG,GAAG,CAAC;AAAA,MAClC,UAAc;AACR,UAAE,wBAAwB;AAAA,MAChC;AAAA,IACG;AAAA,EACH;;;;ACrBO,MAAM,iBAAiB,MAAM,UAAuB,YAAY,EAAE;AAClE,MAAM,qBAAqB,M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AAW,UAAU,EACrB,MAAM;","x_google_ignoreList":[0]}
@@ -1,15 +1 @@
1
- import { ReactNode } from '../../preact/adapter.ts';
2
- import { PrintOptions, PrintProgress, ParsedPageRange } from '../../lib/types';
3
- interface PrintContextValue {
4
- parsePageRange: (rangeString: string) => ParsedPageRange;
5
- executePrint: (options: PrintOptions) => Promise<void>;
6
- progress: PrintProgress | null;
7
- isReady: boolean;
8
- isPrinting: boolean;
9
- }
10
- interface PrintProviderProps {
11
- children: ReactNode;
12
- }
13
- export declare function PrintProvider({ children }: PrintProviderProps): import("preact").JSX.Element;
14
- export declare function usePrintContext(): PrintContextValue;
15
- export {};
1
+ export declare function PrintFrame(): import("preact").JSX.Element;
@@ -1,2 +1 @@
1
1
  export * from './use-print';
2
- export * from './use-print-action';
@@ -1,2 +1,4 @@
1
1
  export * from './hooks';
2
2
  export * from './components';
3
+ export * from '../lib/index.ts';
4
+ export declare const PrintPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../lib/index.ts').PrintPlugin, import('../lib/index.ts').PrintPluginConfig, unknown, import('@embedpdf/core').Action>>;
@@ -1,15 +1 @@
1
- import { ReactNode } from '../../react/adapter.ts';
2
- import { PrintOptions, PrintProgress, ParsedPageRange } from '../../lib/types';
3
- interface PrintContextValue {
4
- parsePageRange: (rangeString: string) => ParsedPageRange;
5
- executePrint: (options: PrintOptions) => Promise<void>;
6
- progress: PrintProgress | null;
7
- isReady: boolean;
8
- isPrinting: boolean;
9
- }
10
- interface PrintProviderProps {
11
- children: ReactNode;
12
- }
13
- export declare function PrintProvider({ children }: PrintProviderProps): import("react/jsx-runtime").JSX.Element;
14
- export declare function usePrintContext(): PrintContextValue;
15
- export {};
1
+ export declare function PrintFrame(): import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1 @@
1
1
  export * from './use-print';
2
- export * from './use-print-action';
@@ -1,2 +1,4 @@
1
1
  export * from './hooks';
2
2
  export * from './components';
3
+ export * from '../lib/index.ts';
4
+ export declare const PrintPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../lib/index.ts').PrintPlugin, import('../lib/index.ts').PrintPluginConfig, unknown, import('@embedpdf/core').Action>>;
@@ -0,0 +1 @@
1
+ export { default as PrintFrame } from './print.vue';
@@ -0,0 +1,2 @@
1
+ declare const _default: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
2
+ export default _default;
@@ -0,0 +1 @@
1
+ export * from './use-print';
@@ -0,0 +1,3 @@
1
+ import { PrintPlugin } from '../../lib/index.ts';
2
+ export declare const usePrintPlugin: () => import('@embedpdf/core/vue').PluginState<PrintPlugin>;
3
+ export declare const usePrintCapability: () => import('@embedpdf/core/vue').CapabilityState<Readonly<import('../../lib/index.ts').PrintCapability>>;
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/vue"),t=require("@embedpdf/plugin-print"),r=require("vue"),n=require("@embedpdf/core"),l=()=>e.usePlugin(t.PrintPlugin.id),i=()=>e.useCapability(t.PrintPlugin.id),o=r.defineComponent({__name:"print",setup(e){const t=r.ref(null),n=r.ref(null),{provides:o}=i(),{plugin:u}=l();let a;return r.onMounted((()=>{o.value&&u.value&&(a=u.value.onPrintRequest((({buffer:e,task:r})=>{const l=t.value;if(!l)return;n.value&&(URL.revokeObjectURL(n.value),n.value=null);const i=URL.createObjectURL(new Blob([e],{type:"application/pdf"}));n.value=i,l.onload=()=>{var t,n;l.src===i&&(r.progress({stage:"iframe-ready",message:"Ready to print"}),null==(t=l.contentWindow)||t.focus(),null==(n=l.contentWindow)||n.print(),r.progress({stage:"printing",message:"Print dialog opened"}),r.resolve(e))},l.src=i})))})),r.onUnmounted((()=>{null==a||a(),n.value&&URL.revokeObjectURL(n.value)})),(e,n)=>(r.openBlock(),r.createElementBlock("iframe",{ref_key:"iframeRef",ref:t,title:"Print Document",src:"about:blank",style:{position:"absolute",display:"none"}},null,512))}}),u=n.createPluginPackage(t.PrintPluginPackage).addUtility(o).build();exports.PrintFrame=o,exports.PrintPluginPackage=u,exports.usePrintCapability=i,exports.usePrintPlugin=l,Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-print.ts","../../src/vue/components/print.vue","../../src/vue/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { PrintPlugin } from '@embedpdf/plugin-print';\n\nexport const usePrintPlugin = () => usePlugin<PrintPlugin>(PrintPlugin.id);\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n","<template>\n <iframe\n ref=\"iframeRef\"\n title=\"Print Document\"\n src=\"about:blank\"\n :style=\"{ position: 'absolute', display: 'none' }\"\n />\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted } from 'vue';\nimport { usePrintCapability, usePrintPlugin } from '../hooks';\n\nconst iframeRef = ref<HTMLIFrameElement | null>(null);\nconst urlRef = ref<string | null>(null);\n\nconst { provides: printCapability } = usePrintCapability();\nconst { plugin: printPlugin } = usePrintPlugin();\n\nlet unsubscribe: (() => void) | undefined;\n\nonMounted(() => {\n if (!printCapability.value || !printPlugin.value) return;\n\n unsubscribe = printPlugin.value.onPrintRequest(({ buffer, task }) => {\n const iframe = iframeRef.value;\n if (!iframe) return;\n\n if (urlRef.value) {\n URL.revokeObjectURL(urlRef.value);\n urlRef.value = null;\n }\n\n const url = URL.createObjectURL(new Blob([buffer], { type: 'application/pdf' }));\n urlRef.value = 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\nonUnmounted(() => {\n unsubscribe?.();\n if (urlRef.value) {\n URL.revokeObjectURL(urlRef.value);\n }\n});\n</script>\n","export * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-print';\n\nimport { createPluginPackage } from '@embedpdf/core';\nimport { PrintPluginPackage as BasePrintPackage } from '@embedpdf/plugin-print';\nimport { PrintFrame } from './components';\n\n/**\n * Build a Vue-flavoured package by adding the Vue PrintFrame utility.\n * Keeps heavy logic inside the plugin; framework layer just wires the component.\n */\nexport const PrintPluginPackage = createPluginPackage(BasePrintPackage)\n .addUtility(PrintFrame)\n .build();\n"],"names":["usePrintPlugin","usePlugin","PrintPlugin","id","usePrintCapability","useCapability","iframeRef","ref","urlRef","provides","printCapability","plugin","printPlugin","unsubscribe","onMounted","value","onPrintRequest","buffer","task","iframe","URL","revokeObjectURL","url","createObjectURL","Blob","type","onload","src","progress","stage","message","_a","contentWindow","focus","_b","print","resolve","onUnmounted","_createElementBlock","createElementBlock","title","style","position","display","PrintPluginPackage","createPluginPackage","BasePrintPackage","addUtility","PrintFrame","build"],"mappings":"uMAGaA,EAAiB,IAAMC,YAAuBC,EAAAA,YAAYC,IAC1DC,EAAqB,IAAMC,gBAA2BH,EAAAA,YAAYC,iDCSzE,MAAAG,EAAYC,MAA8B,MAC1CC,EAASD,MAAmB,OAE1BE,SAAUC,GAAoBN,KAC9BO,OAAQC,GAAgBZ,IAE5B,IAAAa,SAEJC,EAAAA,WAAU,KACHJ,EAAgBK,OAAUH,EAAYG,QAE3CF,EAAcD,EAAYG,MAAMC,gBAAe,EAAGC,SAAQC,WACxD,MAAMC,EAASb,EAAUS,MACzB,IAAKI,EAAQ,OAETX,EAAOO,QACLK,IAAAC,gBAAgBb,EAAOO,OAC3BP,EAAOO,MAAQ,MAGjB,MAAMO,EAAMF,IAAIG,gBAAgB,IAAIC,KAAK,CAACP,GAAS,CAAEQ,KAAM,qBAC3DjB,EAAOO,MAAQO,EAEfH,EAAOO,OAAS,aACVP,EAAOQ,MAAQL,IACjBJ,EAAKU,SAAS,CAAEC,MAAO,eAAgBC,QAAS,mBAChD,OAAAC,EAAAZ,EAAOa,gBAAeD,EAAAE,QACtB,OAAAC,EAAAf,EAAOa,gBAAeE,EAAAC,QACtBjB,EAAKU,SAAS,CAAEC,MAAO,WAAYC,QAAS,wBAC5CZ,EAAKkB,QAAQnB,GAAM,EAIvBE,EAAOQ,IAAML,CAAA,IACd,IAGHe,EAAAA,aAAY,KACI,MAAAxB,GAAAA,IACVL,EAAOO,OACLK,IAAAC,gBAAgBb,EAAOO,MAAK,0BApDlCuB,EAAAC,mBAKE,SAAA,SAJI,YAAJhC,IAAID,EACJkC,MAAM,iBACNb,IAAI,cACHc,MAAO,CAAyCC,SAAA,WAAAC,QAAA,uBCOxCC,EAAqBC,EAAoBA,oBAAAC,EAAgBF,oBACnEG,WAAWC,GACXC"}
@@ -0,0 +1,8 @@
1
+ export * from './hooks';
2
+ export * from './components';
3
+ export * from '../lib/index.ts';
4
+ /**
5
+ * Build a Vue-flavoured package by adding the Vue PrintFrame utility.
6
+ * Keeps heavy logic inside the plugin; framework layer just wires the component.
7
+ */
8
+ export declare const PrintPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../lib/index.ts').PrintPlugin, import('../lib/index.ts').PrintPluginConfig, unknown, import('@embedpdf/core').Action>>;
@@ -0,0 +1,64 @@
1
+ import { useCapability, usePlugin } from "@embedpdf/core/vue";
2
+ import { PrintPlugin, PrintPluginPackage as PrintPluginPackage$1 } from "@embedpdf/plugin-print";
3
+ export * from "@embedpdf/plugin-print";
4
+ import { defineComponent, ref, onMounted, onUnmounted, createElementBlock, openBlock } from "vue";
5
+ import { createPluginPackage } from "@embedpdf/core";
6
+ const usePrintPlugin = () => usePlugin(PrintPlugin.id);
7
+ const usePrintCapability = () => useCapability(PrintPlugin.id);
8
+ const _sfc_main = /* @__PURE__ */ defineComponent({
9
+ __name: "print",
10
+ setup(__props) {
11
+ const iframeRef = ref(null);
12
+ const urlRef = ref(null);
13
+ const { provides: printCapability } = usePrintCapability();
14
+ const { plugin: printPlugin } = usePrintPlugin();
15
+ let unsubscribe;
16
+ onMounted(() => {
17
+ if (!printCapability.value || !printPlugin.value) return;
18
+ unsubscribe = printPlugin.value.onPrintRequest(({ buffer, task }) => {
19
+ const iframe = iframeRef.value;
20
+ if (!iframe) return;
21
+ if (urlRef.value) {
22
+ URL.revokeObjectURL(urlRef.value);
23
+ urlRef.value = null;
24
+ }
25
+ const url = URL.createObjectURL(new Blob([buffer], { type: "application/pdf" }));
26
+ urlRef.value = url;
27
+ iframe.onload = () => {
28
+ var _a, _b;
29
+ if (iframe.src === url) {
30
+ task.progress({ stage: "iframe-ready", message: "Ready to print" });
31
+ (_a = iframe.contentWindow) == null ? void 0 : _a.focus();
32
+ (_b = iframe.contentWindow) == null ? void 0 : _b.print();
33
+ task.progress({ stage: "printing", message: "Print dialog opened" });
34
+ task.resolve(buffer);
35
+ }
36
+ };
37
+ iframe.src = url;
38
+ });
39
+ });
40
+ onUnmounted(() => {
41
+ unsubscribe == null ? void 0 : unsubscribe();
42
+ if (urlRef.value) {
43
+ URL.revokeObjectURL(urlRef.value);
44
+ }
45
+ });
46
+ return (_ctx, _cache) => {
47
+ return openBlock(), createElementBlock("iframe", {
48
+ ref_key: "iframeRef",
49
+ ref: iframeRef,
50
+ title: "Print Document",
51
+ src: "about:blank",
52
+ style: { position: "absolute", display: "none" }
53
+ }, null, 512);
54
+ };
55
+ }
56
+ });
57
+ const PrintPluginPackage = createPluginPackage(PrintPluginPackage$1).addUtility(_sfc_main).build();
58
+ export {
59
+ _sfc_main as PrintFrame,
60
+ PrintPluginPackage,
61
+ usePrintCapability,
62
+ usePrintPlugin
63
+ };
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-print.ts","../../src/vue/components/print.vue","../../src/vue/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { PrintPlugin } from '@embedpdf/plugin-print';\n\nexport const usePrintPlugin = () => usePlugin<PrintPlugin>(PrintPlugin.id);\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n","<template>\n <iframe\n ref=\"iframeRef\"\n title=\"Print Document\"\n src=\"about:blank\"\n :style=\"{ position: 'absolute', display: 'none' }\"\n />\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted } from 'vue';\nimport { usePrintCapability, usePrintPlugin } from '../hooks';\n\nconst iframeRef = ref<HTMLIFrameElement | null>(null);\nconst urlRef = ref<string | null>(null);\n\nconst { provides: printCapability } = usePrintCapability();\nconst { plugin: printPlugin } = usePrintPlugin();\n\nlet unsubscribe: (() => void) | undefined;\n\nonMounted(() => {\n if (!printCapability.value || !printPlugin.value) return;\n\n unsubscribe = printPlugin.value.onPrintRequest(({ buffer, task }) => {\n const iframe = iframeRef.value;\n if (!iframe) return;\n\n if (urlRef.value) {\n URL.revokeObjectURL(urlRef.value);\n urlRef.value = null;\n }\n\n const url = URL.createObjectURL(new Blob([buffer], { type: 'application/pdf' }));\n urlRef.value = 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\nonUnmounted(() => {\n unsubscribe?.();\n if (urlRef.value) {\n URL.revokeObjectURL(urlRef.value);\n }\n});\n</script>\n","export * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-print';\n\nimport { createPluginPackage } from '@embedpdf/core';\nimport { PrintPluginPackage as BasePrintPackage } from '@embedpdf/plugin-print';\nimport { PrintFrame } from './components';\n\n/**\n * Build a Vue-flavoured package by adding the Vue PrintFrame utility.\n * Keeps heavy logic inside the plugin; framework layer just wires the component.\n */\nexport const PrintPluginPackage = createPluginPackage(BasePrintPackage)\n .addUtility(PrintFrame)\n .build();\n"],"names":["_createElementBlock","BasePrintPackage","PrintFrame"],"mappings":";;;;;AAGO,MAAM,iBAAiB,MAAM,UAAuB,YAAY,EAAE;AAClE,MAAM,qBAAqB,MAAM,cAA2B,YAAY,EAAE;;;;ACS3E,UAAA,YAAY,IAA8B,IAAI;AAC9C,UAAA,SAAS,IAAmB,IAAI;AAEtC,UAAM,EAAE,UAAU,gBAAgB,IAAI,mBAAmB;AACzD,UAAM,EAAE,QAAQ,YAAY,IAAI,eAAe;AAE3C,QAAA;AAEJ,cAAU,MAAM;AACd,UAAI,CAAC,gBAAgB,SAAS,CAAC,YAAY,MAAO;AAElD,oBAAc,YAAY,MAAM,eAAe,CAAC,EAAE,QAAQ,WAAW;AACnE,cAAM,SAAS,UAAU;AACzB,YAAI,CAAC,OAAQ;AAEb,YAAI,OAAO,OAAO;AACZ,cAAA,gBAAgB,OAAO,KAAK;AAChC,iBAAO,QAAQ;AAAA,QAAA;AAGjB,cAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,MAAM,kBAAkB,CAAC,CAAC;AAC/E,eAAO,QAAQ;AAEf,eAAO,SAAS,MAAM;;AAChB,cAAA,OAAO,QAAQ,KAAK;AACtB,iBAAK,SAAS,EAAE,OAAO,gBAAgB,SAAS,kBAAkB;AAClE,yBAAO,kBAAP,mBAAsB;AACtB,yBAAO,kBAAP,mBAAsB;AACtB,iBAAK,SAAS,EAAE,OAAO,YAAY,SAAS,uBAAuB;AACnE,iBAAK,QAAQ,MAAM;AAAA,UAAA;AAAA,QAEvB;AAEA,eAAO,MAAM;AAAA,MAAA,CACd;AAAA,IAAA,CACF;AAED,gBAAY,MAAM;AACF;AACd,UAAI,OAAO,OAAO;AACZ,YAAA,gBAAgB,OAAO,KAAK;AAAA,MAAA;AAAA,IAClC,CACD;;0BAtDCA,mBAKE,UAAA;AAAA,iBAJI;AAAA,QAAJ,KAAI;AAAA,QACJ,OAAM;AAAA,QACN,KAAI;AAAA,QACH,OAAO,EAAyC,UAAA,YAAA,SAAA,OAAA;AAAA,MAAA;;;;ACO9C,MAAM,qBAAqB,oBAAoBC,oBAAgB,EACnE,WAAWC,SAAU,EACrB,MAAM;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-print",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -20,24 +20,30 @@
20
20
  "types": "./dist/react/index.d.ts",
21
21
  "import": "./dist/react/index.js",
22
22
  "require": "./dist/react/index.cjs"
23
+ },
24
+ "./vue": {
25
+ "types": "./dist/vue/index.d.ts",
26
+ "import": "./dist/vue/index.js",
27
+ "require": "./dist/vue/index.cjs"
23
28
  }
24
29
  },
25
30
  "dependencies": {
26
- "@embedpdf/models": "1.0.19"
31
+ "@embedpdf/models": "1.0.21"
27
32
  },
28
33
  "devDependencies": {
29
34
  "@types/react": "^18.2.0",
30
35
  "@types/react-dom": "^18.2.0",
31
36
  "typescript": "^5.0.0",
32
- "@embedpdf/build": "1.0.0",
33
- "@embedpdf/plugin-render": "1.0.19"
37
+ "@embedpdf/plugin-render": "1.0.21",
38
+ "@embedpdf/build": "1.0.0"
34
39
  },
35
40
  "peerDependencies": {
36
41
  "react": ">=18.0.0",
37
42
  "react-dom": ">=18.0.0",
38
43
  "preact": "^10.26.4",
39
- "@embedpdf/core": "1.0.19",
40
- "@embedpdf/plugin-render": "1.0.19"
44
+ "vue": ">=3.2.0",
45
+ "@embedpdf/plugin-render": "1.0.21",
46
+ "@embedpdf/core": "1.0.21"
41
47
  },
42
48
  "files": [
43
49
  "dist",
@@ -59,7 +65,8 @@
59
65
  "build:base": "vite build --mode base",
60
66
  "build:react": "vite build --mode react",
61
67
  "build:preact": "vite build --mode preact",
62
- "build": "pnpm run clean && concurrently -c auto -n base,react,preact \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\"",
68
+ "build:vue": "vite build --mode vue",
69
+ "build": "pnpm run clean && concurrently -c auto -n base,react,preact,vue \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\" \"vite build --mode vue\"",
63
70
  "clean": "rimraf dist",
64
71
  "lint": "eslint src --color",
65
72
  "lint:fix": "eslint src --color --fix"
@@ -1,8 +0,0 @@
1
- import { PrintOptions } from '../../lib/index.ts';
2
- export declare const usePrintAction: () => {
3
- executePrint: (options: PrintOptions) => Promise<void>;
4
- progress: import('../../lib/index.ts').PrintProgress | null;
5
- isReady: boolean;
6
- isPrinting: boolean;
7
- parsePageRange: (rangeString: string) => import('../../lib/index.ts').ParsedPageRange;
8
- };
@@ -1,8 +0,0 @@
1
- import { PrintOptions } from '../../lib/index.ts';
2
- export declare const usePrintAction: () => {
3
- executePrint: (options: PrintOptions) => Promise<void>;
4
- progress: import('../../lib/index.ts').PrintProgress | null;
5
- isReady: boolean;
6
- isPrinting: boolean;
7
- parsePageRange: (rangeString: string) => import('../../lib/index.ts').ParsedPageRange;
8
- };