@embedpdf/plugin-print 1.4.1 → 2.0.0-next.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/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/models"),r="print",n={id:r,name:"Print Plugin",version:"1.0.0",provides:["print"],requires:[],optional:[],defaultConfig:{enabled:!0}},i=class extends e.BasePlugin{constructor(t,r,n){super(t,r),this.printReady$=e.createEmitter()}async initialize(e){}buildCapability(){return{print:this.print.bind(this)}}onPrintRequest(e){return this.printReady$.on(e)}print(e){const r=e??{},n=new t.Task;n.progress({stage:"preparing",message:"Preparing document..."});return this.preparePrintDocument(r).wait((e=>{n.progress({stage:"document-ready",message:"Document prepared successfully"}),this.printReady$.emit({options:r,buffer:e,task:n})}),n.fail),n}preparePrintDocument(e){const r=this.coreState.core.document;return r?this.engine.preparePrintDocument(r,e):t.PdfTaskHelper.reject({code:t.PdfErrorCode.DocNotOpen,message:"Document not found"})}};i.id="print";let s=i;const o={manifest:n,create:(e,t)=>new s(r,e,t),reducer:()=>{},initialState:{}};exports.PRINT_PLUGIN_ID=r,exports.PrintPlugin=s,exports.PrintPluginPackage=o,exports.manifest=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/models"),r="print",i={id:r,name:"Print Plugin",version:"1.0.0",provides:["print"],requires:[],optional:[],defaultConfig:{enabled:!0}},n=class extends e.BasePlugin{constructor(t,r,i){super(t,r),this.printReady$=e.createEmitter()}buildCapability(){return{print:e=>this.print(e),forDocument:e=>this.createPrintScope(e)}}createPrintScope(e){return{print:t=>this.print(t,e)}}print(e,r){const i=r??this.getActiveDocumentId(),n=e??{},s=new t.Task;s.progress({stage:"preparing",message:"Preparing document..."});return this.preparePrintDocument(n,i).wait(e=>{s.progress({stage:"document-ready",message:"Document prepared successfully"}),this.printReady$.emit({documentId:i,options:n,buffer:e,task:s})},e=>s.fail(e)),s}preparePrintDocument(e,r){const i=this.coreState.core.documents[r];return(null==i?void 0:i.document)?this.engine.preparePrintDocument(i.document,e):t.PdfTaskHelper.reject({code:t.PdfErrorCode.DocNotOpen,message:`Document ${r} not found`})}onPrintRequest(e){return this.printReady$.on(e)}async initialize(e){this.logger.info("PrintPlugin","Initialize","Print plugin initialized")}async destroy(){this.printReady$.clear(),await super.destroy()}};n.id="print";let s=n;const o={manifest:i,create:(e,t)=>new s(r,e,t),reducer:()=>{},initialState:{}};exports.PRINT_PLUGIN_ID=r,exports.PrintPlugin=s,exports.PrintPluginPackage=o,exports.manifest=i;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/lib/manifest.ts","../src/lib/print-plugin.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { PrintPluginConfig } from './types';\n\nexport const PRINT_PLUGIN_ID = 'print';\n\nexport const manifest: PluginManifest<PrintPluginConfig> = {\n id: PRINT_PLUGIN_ID,\n name: 'Print Plugin',\n version: '1.0.0',\n provides: ['print'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { BasePlugin, createEmitter, Listener, PluginRegistry, Unsubscribe } from '@embedpdf/core';\nimport {\n PdfErrorCode,\n PdfErrorReason,\n PdfPrintOptions,\n PdfTaskHelper,\n Task,\n} from '@embedpdf/models';\n\nimport { PrintCapability, PrintPluginConfig, PrintProgress, PrintReadyEvent } from './types';\n\nexport class PrintPlugin extends BasePlugin<PrintPluginConfig, PrintCapability> {\n static readonly id = 'print' as const;\n\n private readonly printReady$ = createEmitter<PrintReadyEvent>();\n\n constructor(id: string, registry: PluginRegistry, _config: PrintPluginConfig) {\n super(id, registry);\n }\n\n async initialize(_: PrintPluginConfig): Promise<void> {}\n\n protected buildCapability(): PrintCapability {\n return {\n print: this.print.bind(this),\n };\n }\n\n public onPrintRequest(listener: Listener<PrintReadyEvent>): Unsubscribe {\n return this.printReady$.on(listener);\n }\n\n private print(options?: PdfPrintOptions): Task<ArrayBuffer, PdfErrorReason, PrintProgress> {\n const printOptions = options ?? {};\n const task = new Task<ArrayBuffer, PdfErrorReason, PrintProgress>();\n task.progress({ stage: 'preparing', message: 'Preparing document...' });\n\n const prepare = this.preparePrintDocument(printOptions);\n prepare.wait((buffer) => {\n task.progress({ stage: 'document-ready', message: 'Document prepared successfully' });\n // Emit buffer + task for the framework layer to display & trigger print\n this.printReady$.emit({ options: printOptions, buffer, task });\n }, task.fail);\n\n return task;\n }\n\n public preparePrintDocument(options: PdfPrintOptions): Task<ArrayBuffer, PdfErrorReason> {\n const document = this.coreState.core.document;\n\n if (!document) {\n return PdfTaskHelper.reject({\n code: PdfErrorCode.DocNotOpen,\n message: 'Document not found',\n });\n }\n\n return this.engine.preparePrintDocument(document, options);\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, PRINT_PLUGIN_ID } from './manifest';\nimport { PrintPluginConfig } from './types';\nimport { PrintPlugin } from './print-plugin';\n\nexport const PrintPluginPackage: PluginPackage<PrintPlugin, PrintPluginConfig> = {\n manifest,\n create: (registry, config) => new PrintPlugin(PRINT_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './print-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["PRINT_PLUGIN_ID","manifest","id","name","version","provides","requires","optional","defaultConfig","enabled","_PrintPlugin","BasePlugin","constructor","registry","_config","super","this","printReady$","createEmitter","initialize","_","buildCapability","print","bind","onPrintRequest","listener","on","options","printOptions","task","Task","progress","stage","message","preparePrintDocument","wait","buffer","emit","fail","document","coreState","core","engine","PdfTaskHelper","reject","code","PdfErrorCode","DocNotOpen","PrintPlugin","PrintPluginPackage","create","config","reducer","initialState"],"mappings":"gJAGaA,EAAkB,QAElBC,EAA8C,CACzDC,GAAIF,EACJG,KAAM,eACNC,QAAS,QACTC,SAAU,CAAC,SACXC,SAAU,GACVC,SAAU,GACVC,cAAe,CACbC,SAAS,ICFAC,EAAN,cAA0BC,EAAAA,WAK/B,WAAAC,CAAYV,EAAYW,EAA0BC,GAChDC,MAAMb,EAAIW,GAHKG,KAAAC,YAAcC,iBAA+B,CAM9D,gBAAMC,CAAWC,GAAqC,CAE5C,eAAAC,GACD,MAAA,CACLC,MAAON,KAAKM,MAAMC,KAAKP,MACzB,CAGK,cAAAQ,CAAeC,GACb,OAAAT,KAAKC,YAAYS,GAAGD,EAAQ,CAG7B,KAAAH,CAAMK,GACN,MAAAC,EAAeD,GAAW,CAAC,EAC3BE,EAAO,IAAIC,OACjBD,EAAKE,SAAS,CAAEC,MAAO,YAAaC,QAAS,0BAStC,OAPSjB,KAAKkB,qBAAqBN,GAClCO,MAAMC,IACZP,EAAKE,SAAS,CAAEC,MAAO,iBAAkBC,QAAS,mCAElDjB,KAAKC,YAAYoB,KAAK,CAAEV,QAASC,EAAcQ,SAAQP,QAAM,GAC5DA,EAAKS,MAEDT,CAAA,CAGF,oBAAAK,CAAqBP,GACpB,MAAAY,EAAWvB,KAAKwB,UAAUC,KAAKF,SAErC,OAAKA,EAOEvB,KAAK0B,OAAOR,qBAAqBK,EAAUZ,GANzCgB,EAAAA,cAAcC,OAAO,CAC1BC,KAAMC,EAAaA,aAAAC,WACnBd,QAAS,sBAI4C,GA7C3DvB,EAAgBR,GAAK,QADhB,IAAM8C,EAANtC,ECNA,MAAMuC,EAAoE,CAC/EhD,WACAiD,OAAQ,CAACrC,EAAUsC,IAAW,IAAIH,EAAYhD,EAAiBa,EAAUsC,GACzEC,QAAS,OACTC,aAAc,CAAA"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/lib/manifest.ts","../src/lib/print-plugin.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { PrintPluginConfig } from './types';\n\nexport const PRINT_PLUGIN_ID = 'print';\n\nexport const manifest: PluginManifest<PrintPluginConfig> = {\n id: PRINT_PLUGIN_ID,\n name: 'Print Plugin',\n version: '1.0.0',\n provides: ['print'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { BasePlugin, createEmitter, Listener, PluginRegistry, Unsubscribe } from '@embedpdf/core';\nimport {\n PdfErrorCode,\n PdfErrorReason,\n PdfPrintOptions,\n PdfTaskHelper,\n Task,\n} from '@embedpdf/models';\n\nimport {\n PrintCapability,\n PrintPluginConfig,\n PrintProgress,\n PrintReadyEvent,\n PrintScope,\n} from './types';\n\nexport class PrintPlugin extends BasePlugin<PrintPluginConfig, PrintCapability> {\n static readonly id = 'print' as const;\n\n private readonly printReady$ = createEmitter<PrintReadyEvent>();\n\n constructor(id: string, registry: PluginRegistry, _config: PrintPluginConfig) {\n super(id, registry);\n }\n\n // ─────────────────────────────────────────────────────────\n // Capability\n // ─────────────────────────────────────────────────────────\n\n protected buildCapability(): PrintCapability {\n return {\n // Active document operations\n print: (options?: PdfPrintOptions) => this.print(options),\n\n // Document-scoped operations\n forDocument: (documentId: string) => this.createPrintScope(documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Scoping\n // ─────────────────────────────────────────────────────────\n\n private createPrintScope(documentId: string): PrintScope {\n return {\n print: (options?: PdfPrintOptions) => this.print(options, documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Core Operations\n // ─────────────────────────────────────────────────────────\n\n private print(\n options?: PdfPrintOptions,\n documentId?: string,\n ): Task<ArrayBuffer, PdfErrorReason, PrintProgress> {\n const id = documentId ?? this.getActiveDocumentId();\n const printOptions = options ?? {};\n const task = new Task<ArrayBuffer, PdfErrorReason, PrintProgress>();\n\n task.progress({ stage: 'preparing', message: 'Preparing document...' });\n\n const prepare = this.preparePrintDocument(printOptions, id);\n prepare.wait(\n (buffer) => {\n task.progress({ stage: 'document-ready', message: 'Document prepared successfully' });\n // Emit buffer + task for the framework layer to display & trigger print\n this.printReady$.emit({\n documentId: id,\n options: printOptions,\n buffer,\n task,\n });\n },\n (error) => task.fail(error),\n );\n\n return task;\n }\n\n private preparePrintDocument(\n options: PdfPrintOptions,\n documentId: string,\n ): Task<ArrayBuffer, PdfErrorReason> {\n const coreDoc = this.coreState.core.documents[documentId];\n\n if (!coreDoc?.document) {\n return PdfTaskHelper.reject({\n code: PdfErrorCode.DocNotOpen,\n message: `Document ${documentId} not found`,\n });\n }\n\n return this.engine.preparePrintDocument(coreDoc.document, options);\n }\n\n // ─────────────────────────────────────────────────────────\n // Event Listeners\n // ─────────────────────────────────────────────────────────\n\n public onPrintRequest(listener: Listener<PrintReadyEvent>): Unsubscribe {\n return this.printReady$.on(listener);\n }\n\n // ─────────────────────────────────────────────────────────\n // Lifecycle\n // ─────────────────────────────────────────────────────────\n\n async initialize(_: PrintPluginConfig): Promise<void> {\n this.logger.info('PrintPlugin', 'Initialize', 'Print plugin initialized');\n }\n\n async destroy(): Promise<void> {\n this.printReady$.clear();\n await super.destroy();\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, PRINT_PLUGIN_ID } from './manifest';\nimport { PrintPluginConfig } from './types';\nimport { PrintPlugin } from './print-plugin';\n\nexport const PrintPluginPackage: PluginPackage<PrintPlugin, PrintPluginConfig> = {\n manifest,\n create: (registry, config) => new PrintPlugin(PRINT_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './print-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["PRINT_PLUGIN_ID","manifest","id","name","version","provides","requires","optional","defaultConfig","enabled","_PrintPlugin","BasePlugin","constructor","registry","_config","super","this","printReady$","createEmitter","buildCapability","print","options","forDocument","documentId","createPrintScope","getActiveDocumentId","printOptions","task","Task","progress","stage","message","preparePrintDocument","wait","buffer","emit","error","fail","coreDoc","coreState","core","documents","document","engine","PdfTaskHelper","reject","code","PdfErrorCode","DocNotOpen","onPrintRequest","listener","on","initialize","_","logger","info","destroy","clear","PrintPlugin","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,2BAChD,CAEA,aAAMC,GACJxC,KAAKC,YAAYwC,cACX1C,MAAMyC,SACd,GAnGA9C,EAAgBR,GAAK,QADhB,IAAMwD,EAANhD,ECZA,MAAMiD,EAAoE,CAC/E1D,WACA2D,OAAQ,CAAC/C,EAAUgD,IAAW,IAAIH,EAAY1D,EAAiBa,EAAUgD,GACzEC,QAAS,OACTC,aAAc,CAAA"}
package/dist/index.js CHANGED
@@ -17,36 +17,73 @@ const _PrintPlugin = class _PrintPlugin extends BasePlugin {
17
17
  super(id, registry);
18
18
  this.printReady$ = createEmitter();
19
19
  }
20
- async initialize(_) {
21
- }
20
+ // ─────────────────────────────────────────────────────────
21
+ // Capability
22
+ // ─────────────────────────────────────────────────────────
22
23
  buildCapability() {
23
24
  return {
24
- print: this.print.bind(this)
25
+ // Active document operations
26
+ print: (options) => this.print(options),
27
+ // Document-scoped operations
28
+ forDocument: (documentId) => this.createPrintScope(documentId)
25
29
  };
26
30
  }
27
- onPrintRequest(listener) {
28
- return this.printReady$.on(listener);
31
+ // ─────────────────────────────────────────────────────────
32
+ // Document Scoping
33
+ // ─────────────────────────────────────────────────────────
34
+ createPrintScope(documentId) {
35
+ return {
36
+ print: (options) => this.print(options, documentId)
37
+ };
29
38
  }
30
- print(options) {
39
+ // ─────────────────────────────────────────────────────────
40
+ // Core Operations
41
+ // ─────────────────────────────────────────────────────────
42
+ print(options, documentId) {
43
+ const id = documentId ?? this.getActiveDocumentId();
31
44
  const printOptions = options ?? {};
32
45
  const task = new Task();
33
46
  task.progress({ stage: "preparing", message: "Preparing document..." });
34
- const prepare = this.preparePrintDocument(printOptions);
35
- prepare.wait((buffer) => {
36
- task.progress({ stage: "document-ready", message: "Document prepared successfully" });
37
- this.printReady$.emit({ options: printOptions, buffer, task });
38
- }, task.fail);
47
+ const prepare = this.preparePrintDocument(printOptions, id);
48
+ prepare.wait(
49
+ (buffer) => {
50
+ task.progress({ stage: "document-ready", message: "Document prepared successfully" });
51
+ this.printReady$.emit({
52
+ documentId: id,
53
+ options: printOptions,
54
+ buffer,
55
+ task
56
+ });
57
+ },
58
+ (error) => task.fail(error)
59
+ );
39
60
  return task;
40
61
  }
41
- preparePrintDocument(options) {
42
- const document = this.coreState.core.document;
43
- if (!document) {
62
+ preparePrintDocument(options, documentId) {
63
+ const coreDoc = this.coreState.core.documents[documentId];
64
+ if (!(coreDoc == null ? void 0 : coreDoc.document)) {
44
65
  return PdfTaskHelper.reject({
45
66
  code: PdfErrorCode.DocNotOpen,
46
- message: "Document not found"
67
+ message: `Document ${documentId} not found`
47
68
  });
48
69
  }
49
- return this.engine.preparePrintDocument(document, options);
70
+ return this.engine.preparePrintDocument(coreDoc.document, options);
71
+ }
72
+ // ─────────────────────────────────────────────────────────
73
+ // Event Listeners
74
+ // ─────────────────────────────────────────────────────────
75
+ onPrintRequest(listener) {
76
+ return this.printReady$.on(listener);
77
+ }
78
+ // ─────────────────────────────────────────────────────────
79
+ // Lifecycle
80
+ // ─────────────────────────────────────────────────────────
81
+ async initialize(_) {
82
+ this.logger.info("PrintPlugin", "Initialize", "Print plugin initialized");
83
+ }
84
+ async destroy() {
85
+ this.printReady$.clear();
86
+ await super.destroy();
50
87
  }
51
88
  };
52
89
  _PrintPlugin.id = "print";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/lib/manifest.ts","../src/lib/print-plugin.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { PrintPluginConfig } from './types';\n\nexport const PRINT_PLUGIN_ID = 'print';\n\nexport const manifest: PluginManifest<PrintPluginConfig> = {\n id: PRINT_PLUGIN_ID,\n name: 'Print Plugin',\n version: '1.0.0',\n provides: ['print'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { BasePlugin, createEmitter, Listener, PluginRegistry, Unsubscribe } from '@embedpdf/core';\nimport {\n PdfErrorCode,\n PdfErrorReason,\n PdfPrintOptions,\n PdfTaskHelper,\n Task,\n} from '@embedpdf/models';\n\nimport { PrintCapability, PrintPluginConfig, PrintProgress, PrintReadyEvent } from './types';\n\nexport class PrintPlugin extends BasePlugin<PrintPluginConfig, PrintCapability> {\n static readonly id = 'print' as const;\n\n private readonly printReady$ = createEmitter<PrintReadyEvent>();\n\n constructor(id: string, registry: PluginRegistry, _config: PrintPluginConfig) {\n super(id, registry);\n }\n\n async initialize(_: PrintPluginConfig): Promise<void> {}\n\n protected buildCapability(): PrintCapability {\n return {\n print: this.print.bind(this),\n };\n }\n\n public onPrintRequest(listener: Listener<PrintReadyEvent>): Unsubscribe {\n return this.printReady$.on(listener);\n }\n\n private print(options?: PdfPrintOptions): Task<ArrayBuffer, PdfErrorReason, PrintProgress> {\n const printOptions = options ?? {};\n const task = new Task<ArrayBuffer, PdfErrorReason, PrintProgress>();\n task.progress({ stage: 'preparing', message: 'Preparing document...' });\n\n const prepare = this.preparePrintDocument(printOptions);\n prepare.wait((buffer) => {\n task.progress({ stage: 'document-ready', message: 'Document prepared successfully' });\n // Emit buffer + task for the framework layer to display & trigger print\n this.printReady$.emit({ options: printOptions, buffer, task });\n }, task.fail);\n\n return task;\n }\n\n public preparePrintDocument(options: PdfPrintOptions): Task<ArrayBuffer, PdfErrorReason> {\n const document = this.coreState.core.document;\n\n if (!document) {\n return PdfTaskHelper.reject({\n code: PdfErrorCode.DocNotOpen,\n message: 'Document not found',\n });\n }\n\n return this.engine.preparePrintDocument(document, options);\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, PRINT_PLUGIN_ID } from './manifest';\nimport { PrintPluginConfig } from './types';\nimport { PrintPlugin } from './print-plugin';\n\nexport const PrintPluginPackage: PluginPackage<PrintPlugin, PrintPluginConfig> = {\n manifest,\n create: (registry, config) => new PrintPlugin(PRINT_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './print-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":[],"mappings":";;AAGO,MAAM,kBAAkB;AA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AM,qBAAoE;AAAA,EAC/E;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,YAAY,iBAAiB,UAAU,MAAM;AAAA,EAC/E,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAA;AAChB;"}
1
+ {"version":3,"file":"index.js","sources":["../src/lib/manifest.ts","../src/lib/print-plugin.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { PrintPluginConfig } from './types';\n\nexport const PRINT_PLUGIN_ID = 'print';\n\nexport const manifest: PluginManifest<PrintPluginConfig> = {\n id: PRINT_PLUGIN_ID,\n name: 'Print Plugin',\n version: '1.0.0',\n provides: ['print'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { BasePlugin, createEmitter, Listener, PluginRegistry, Unsubscribe } from '@embedpdf/core';\nimport {\n PdfErrorCode,\n PdfErrorReason,\n PdfPrintOptions,\n PdfTaskHelper,\n Task,\n} from '@embedpdf/models';\n\nimport {\n PrintCapability,\n PrintPluginConfig,\n PrintProgress,\n PrintReadyEvent,\n PrintScope,\n} from './types';\n\nexport class PrintPlugin extends BasePlugin<PrintPluginConfig, PrintCapability> {\n static readonly id = 'print' as const;\n\n private readonly printReady$ = createEmitter<PrintReadyEvent>();\n\n constructor(id: string, registry: PluginRegistry, _config: PrintPluginConfig) {\n super(id, registry);\n }\n\n // ─────────────────────────────────────────────────────────\n // Capability\n // ─────────────────────────────────────────────────────────\n\n protected buildCapability(): PrintCapability {\n return {\n // Active document operations\n print: (options?: PdfPrintOptions) => this.print(options),\n\n // Document-scoped operations\n forDocument: (documentId: string) => this.createPrintScope(documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Scoping\n // ─────────────────────────────────────────────────────────\n\n private createPrintScope(documentId: string): PrintScope {\n return {\n print: (options?: PdfPrintOptions) => this.print(options, documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Core Operations\n // ─────────────────────────────────────────────────────────\n\n private print(\n options?: PdfPrintOptions,\n documentId?: string,\n ): Task<ArrayBuffer, PdfErrorReason, PrintProgress> {\n const id = documentId ?? this.getActiveDocumentId();\n const printOptions = options ?? {};\n const task = new Task<ArrayBuffer, PdfErrorReason, PrintProgress>();\n\n task.progress({ stage: 'preparing', message: 'Preparing document...' });\n\n const prepare = this.preparePrintDocument(printOptions, id);\n prepare.wait(\n (buffer) => {\n task.progress({ stage: 'document-ready', message: 'Document prepared successfully' });\n // Emit buffer + task for the framework layer to display & trigger print\n this.printReady$.emit({\n documentId: id,\n options: printOptions,\n buffer,\n task,\n });\n },\n (error) => task.fail(error),\n );\n\n return task;\n }\n\n private preparePrintDocument(\n options: PdfPrintOptions,\n documentId: string,\n ): Task<ArrayBuffer, PdfErrorReason> {\n const coreDoc = this.coreState.core.documents[documentId];\n\n if (!coreDoc?.document) {\n return PdfTaskHelper.reject({\n code: PdfErrorCode.DocNotOpen,\n message: `Document ${documentId} not found`,\n });\n }\n\n return this.engine.preparePrintDocument(coreDoc.document, options);\n }\n\n // ─────────────────────────────────────────────────────────\n // Event Listeners\n // ─────────────────────────────────────────────────────────\n\n public onPrintRequest(listener: Listener<PrintReadyEvent>): Unsubscribe {\n return this.printReady$.on(listener);\n }\n\n // ─────────────────────────────────────────────────────────\n // Lifecycle\n // ─────────────────────────────────────────────────────────\n\n async initialize(_: PrintPluginConfig): Promise<void> {\n this.logger.info('PrintPlugin', 'Initialize', 'Print plugin initialized');\n }\n\n async destroy(): Promise<void> {\n this.printReady$.clear();\n await super.destroy();\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, PRINT_PLUGIN_ID } from './manifest';\nimport { PrintPluginConfig } from './types';\nimport { PrintPlugin } from './print-plugin';\n\nexport const PrintPluginPackage: PluginPackage<PrintPlugin, PrintPluginConfig> = {\n manifest,\n create: (registry, config) => new PrintPlugin(PRINT_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './print-plugin';\nexport * from './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WAAO;AAAA,EACT;AAAA,EAEQ,qBACN,SACA,YACmC;AACnC,UAAM,UAAU,KAAK,UAAU,KAAK,UAAU,UAAU;AAExD,QAAI,EAAC,mCAAS,WAAU;AACtB,aAAO,cAAc,OAAO;AAAA,QAC1B,MAAM,aAAa;AAAA,QACnB,SAAS,YAAY,UAAU;AAAA,MAAA,CAChC;AAAA,IACH;AAEA,WAAO,KAAK,OAAO,qBAAqB,QAAQ,UAAU,OAAO;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA,EAMO,eAAe,UAAkD;AACtE,WAAO,KAAK,YAAY,GAAG,QAAQ;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAW,GAAqC;AACpD,SAAK,OAAO,KAAK,eAAe,cAAc,0BAA0B;AAAA,EAC1E;AAAA,EAEA,MAAM,UAAyB;AAC7B,SAAK,YAAY,MAAA;AACjB,UAAM,MAAM,QAAA;AAAA,EACd;AACF;AApGE,aAAgB,KAAK;AADhB,IAAM,cAAN;ACZA,MAAM,qBAAoE;AAAA,EAC/E;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,YAAY,iBAAiB,UAAU,MAAM;AAAA,EAC/E,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAA;AAChB;"}
@@ -1,13 +1,14 @@
1
1
  import { BasePlugin, Listener, PluginRegistry, Unsubscribe } from '@embedpdf/core';
2
- import { PdfErrorReason, PdfPrintOptions, Task } from '@embedpdf/models';
3
2
  import { PrintCapability, PrintPluginConfig, PrintReadyEvent } from './types';
4
3
  export declare class PrintPlugin extends BasePlugin<PrintPluginConfig, PrintCapability> {
5
4
  static readonly id: "print";
6
5
  private readonly printReady$;
7
6
  constructor(id: string, registry: PluginRegistry, _config: PrintPluginConfig);
8
- initialize(_: PrintPluginConfig): Promise<void>;
9
7
  protected buildCapability(): PrintCapability;
10
- onPrintRequest(listener: Listener<PrintReadyEvent>): Unsubscribe;
8
+ private createPrintScope;
11
9
  private print;
12
- preparePrintDocument(options: PdfPrintOptions): Task<ArrayBuffer, PdfErrorReason>;
10
+ private preparePrintDocument;
11
+ onPrintRequest(listener: Listener<PrintReadyEvent>): Unsubscribe;
12
+ initialize(_: PrintPluginConfig): Promise<void>;
13
+ destroy(): Promise<void>;
13
14
  }
@@ -16,10 +16,17 @@ export type PrintProgress = {
16
16
  message: string;
17
17
  };
18
18
  export interface PrintReadyEvent {
19
+ documentId: string;
19
20
  options: PdfPrintOptions;
20
21
  buffer: ArrayBuffer;
21
22
  task: Task<ArrayBuffer, PdfErrorReason, PrintProgress>;
22
23
  }
24
+ export interface PrintScope {
25
+ print: (options?: PdfPrintOptions) => Task<ArrayBuffer, PdfErrorReason, PrintProgress>;
26
+ }
23
27
  export interface PrintCapability {
24
28
  print: (options?: PdfPrintOptions) => Task<ArrayBuffer, PdfErrorReason, PrintProgress>;
29
+ forDocument(documentId: string): PrintScope;
30
+ }
31
+ export interface PrintState {
25
32
  }
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),r=require("@embedpdf/plugin-print"),t=require("preact/jsx-runtime");require("preact");const n=require("preact/hooks"),i=require("@embedpdf/core/preact"),o=()=>i.usePlugin(r.PrintPlugin.id),u=()=>i.useCapability(r.PrintPlugin.id);function s(){const{provides:e}=u(),{plugin:r}=o(),i=n.useRef(null),s=n.useRef(null);return n.useEffect((()=>{if(!e||!r)return;const t=r.onPrintRequest((({buffer:e,task:r})=>{const t=i.current;if(!t)return;s.current&&(URL.revokeObjectURL(s.current),s.current=null);const n=URL.createObjectURL(new Blob([e],{type:"application/pdf"}));s.current=n,t.onload=()=>{var i,o;t.src===n&&(r.progress({stage:"iframe-ready",message:"Ready to print"}),null==(i=t.contentWindow)||i.focus(),null==(o=t.contentWindow)||o.print(),r.progress({stage:"printing",message:"Print dialog opened"}),r.resolve(e))},t.src=n}));return()=>{t(),s.current&&URL.revokeObjectURL(s.current)}}),[e,r]),t.jsx("iframe",{ref:i,style:{position:"absolute",display:"none"},title:"Print Document",src:"about:blank"})}const c=e.createPluginPackage(r.PrintPluginPackage).addUtility(s).build();exports.PrintFrame=s,exports.PrintPluginPackage=c,exports.usePrintCapability=u,exports.usePrintPlugin=o,Object.keys(r).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})}));
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),r=require("@embedpdf/plugin-print"),t=require("preact/jsx-runtime");require("preact");const n=require("preact/hooks"),i=require("@embedpdf/core/preact"),o=()=>i.usePlugin(r.PrintPlugin.id),u=()=>i.useCapability(r.PrintPlugin.id);function s(){const{provides:e}=u(),{plugin:r}=o(),i=n.useRef(null),s=n.useRef(null);return n.useEffect(()=>{if(!e||!r)return;const t=r.onPrintRequest(({buffer:e,task:r})=>{const t=i.current;if(!t)return;s.current&&(URL.revokeObjectURL(s.current),s.current=null);const n=URL.createObjectURL(new Blob([e],{type:"application/pdf"}));s.current=n,t.onload=()=>{var i,o;t.src===n&&(r.progress({stage:"iframe-ready",message:"Ready to print"}),null==(i=t.contentWindow)||i.focus(),null==(o=t.contentWindow)||o.print(),r.progress({stage:"printing",message:"Print dialog opened"}),r.resolve(e))},t.src=n});return()=>{t(),s.current&&URL.revokeObjectURL(s.current)}},[e,r]),t.jsx("iframe",{ref:i,style:{position:"absolute",display:"none"},title:"Print Document",src:"about:blank"})}const c=e.createPluginPackage(r.PrintPluginPackage).addUtility(s).build();exports.PrintFrame=s,exports.PrintPluginPackage=c,exports.usePrint=e=>{const{provides:r}=u();return{provides:(null==r?void 0:r.forDocument(e))??null}},exports.usePrintCapability=u,exports.usePrintPlugin=o,Object.keys(r).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","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":["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":"2QAGaA,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"}
1
+ {"version":3,"file":"index.cjs","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\n/**\n * Hook for print capability for a specific document\n * @param documentId Document ID\n */\nexport const usePrint = (documentId: string) => {\n const { provides } = usePrintCapability();\n\n return {\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\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":["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","jsx","ref","style","position","display","title","PrintPluginPackage","createPluginPackage","BasePrintPackage","addUtility","build","documentId","forDocument"],"mappings":"2QAGaA,EAAiB,IAAMC,YAAuBC,EAAAA,YAAYC,IAC1DC,EAAqB,IAAMC,gBAA2BH,EAAAA,YAAYC,ICDxE,SAASG,IACd,MAAQC,SAAUC,GAAoBJ,KAC9BK,OAAQC,GAAgBV,IAC1BW,EAAYC,EAAAA,OAAiC,MAC7CC,EAASD,EAAAA,OAAsB,MAuCrC,OArCAE,EAAAA,UAAU,KACR,IAAKN,IAAoBE,EAAa,OAEtC,MAAMK,EAAcL,EAAYM,eAAe,EAAGC,SAAQC,WACxD,MAAMC,EAASR,EAAUS,QACzB,IAAKD,EAAQ,OAGTN,EAAOO,UACTC,IAAIC,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,gBAAPD,EAAsBE,QACtB,OAAAC,EAAAhB,EAAOc,gBAAPE,EAAsBC,QACtBlB,EAAKW,SAAS,CAAEC,MAAO,WAAYC,QAAS,wBAC5Cb,EAAKmB,QAAQpB,KAIjBE,EAAOS,IAAML,IAGf,MAAO,KACLR,IACIF,EAAOO,SACTC,IAAIC,gBAAgBT,EAAOO,WAG9B,CAACZ,EAAiBE,IAGnB4B,EAAAA,IAAC,SAAA,CACCC,IAAK5B,EACL6B,MAAO,CAAEC,SAAU,WAAYC,QAAS,QACxCC,MAAM,iBACNf,IAAI,eAGV,CC7CO,MAAMgB,EAAqBC,EAAAA,oBAAoBC,EAAAA,oBACnDC,WAAWzC,GACX0C,2EFDsBC,IACvB,MAAM1C,SAAEA,GAAaH,IAErB,MAAO,CACLG,UAAU,MAAAA,OAAA,EAAAA,EAAU2C,YAAYD,KAAe"}
@@ -7,6 +7,12 @@ import { useRef, useEffect } from "preact/hooks";
7
7
  import { useCapability, usePlugin } from "@embedpdf/core/preact";
8
8
  const usePrintPlugin = () => usePlugin(PrintPlugin.id);
9
9
  const usePrintCapability = () => useCapability(PrintPlugin.id);
10
+ const usePrint = (documentId) => {
11
+ const { provides } = usePrintCapability();
12
+ return {
13
+ provides: (provides == null ? void 0 : provides.forDocument(documentId)) ?? null
14
+ };
15
+ };
10
16
  function PrintFrame() {
11
17
  const { provides: printCapability } = usePrintCapability();
12
18
  const { plugin: printPlugin } = usePrintPlugin();
@@ -56,6 +62,7 @@ const PrintPluginPackage = createPluginPackage(PrintPluginPackage$1).addUtility(
56
62
  export {
57
63
  PrintFrame,
58
64
  PrintPluginPackage,
65
+ usePrint,
59
66
  usePrintCapability,
60
67
  usePrintPlugin
61
68
  };
@@ -1 +1 @@
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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AAAA,IAAA;AAAA,EACN;AAEJ;AC7CO,MAAM,qBAAqB,oBAAoBA,oBAAgB,EACnE,WAAW,UAAU,EACrB,MAAM;"}
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\n/**\n * Hook for print capability for a specific document\n * @param documentId Document ID\n */\nexport const usePrint = (documentId: string) => {\n const { provides } = usePrintCapability();\n\n return {\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\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;AAM1E,MAAM,WAAW,CAAC,eAAuB;AAC9C,QAAM,EAAE,SAAA,IAAa,mBAAA;AAErB,SAAO;AAAA,IACL,WAAU,qCAAU,YAAY,gBAAe;AAAA,EAAA;AAEnD;ACbO,SAAS,aAAa;AAC3B,QAAM,EAAE,UAAU,gBAAA,IAAoB,mBAAA;AACtC,QAAM,EAAE,QAAQ,YAAA,IAAgB,eAAA;AAChC,QAAM,YAAY,OAAiC,IAAI;AACvD,QAAM,SAAS,OAAsB,IAAI;AAEzC,YAAU,MAAM;AACd,QAAI,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;AAClB,YAAI,gBAAgB,OAAO,OAAO;AAClC,eAAO,UAAU;AAAA,MACnB;AAEA,YAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,MAAM,kBAAA,CAAmB,CAAC;AAC/E,aAAO,UAAU;AAEjB,aAAO,SAAS,MAAM;;AACpB,YAAI,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,QACrB;AAAA,MACF;AAEA,aAAO,MAAM;AAAA,IACf,CAAC;AAED,WAAO,MAAM;AACX,kBAAA;AACA,UAAI,OAAO,SAAS;AAClB,YAAI,gBAAgB,OAAO,OAAO;AAAA,MACpC;AAAA,IACF;AAAA,EACF,GAAG,CAAC,iBAAiB,WAAW,CAAC;AAEjC,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAK;AAAA,MACL,OAAO,EAAE,UAAU,YAAY,SAAS,OAAA;AAAA,MACxC,OAAM;AAAA,MACN,KAAI;AAAA,IAAA;AAAA,EAAA;AAGV;AC7CO,MAAM,qBAAqB,oBAAoBA,oBAAgB,EACnE,WAAW,UAAU,EACrB,MAAA;"}
@@ -1,2 +1,2 @@
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]})}));
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"),o=require("react"),i=require("@embedpdf/core/react");var u,s={};!function(){if(u)return s;u=1;var e=n;if("production"===process.env.NODE_ENV)s.createRoot=e.createRoot,s.hydrateRoot=e.hydrateRoot;else{var t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;s.createRoot=function(r,n){t.usingClientEntryPoint=!0;try{return e.createRoot(r,n)}finally{t.usingClientEntryPoint=!1}},s.hydrateRoot=function(r,n,o){t.usingClientEntryPoint=!0;try{return e.hydrateRoot(r,n,o)}finally{t.usingClientEntryPoint=!1}}}}();const a=()=>i.usePlugin(t.PrintPlugin.id),c=()=>i.useCapability(t.PrintPlugin.id);function l(){const{provides:e}=c(),{plugin:t}=a(),n=o.useRef(null),i=o.useRef(null);return o.useEffect(()=>{if(!e||!t)return;const r=t.onPrintRequest(({buffer:e,task:t})=>{const r=n.current;if(!r)return;i.current&&(URL.revokeObjectURL(i.current),i.current=null);const o=URL.createObjectURL(new Blob([e],{type:"application/pdf"}));i.current=o,r.onload=()=>{var n,i;r.src===o&&(t.progress({stage:"iframe-ready",message:"Ready to print"}),null==(n=r.contentWindow)||n.focus(),null==(i=r.contentWindow)||i.print(),t.progress({stage:"printing",message:"Print dialog opened"}),t.resolve(e))},r.src=o});return()=>{r(),i.current&&URL.revokeObjectURL(i.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.usePrint=e=>{const{provides:t}=c();return{provides:(null==t?void 0:t.forDocument(e))??null}},exports.usePrintCapability=c,exports.usePrintPlugin=a,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/client.js","../../src/shared/hooks/use-print.ts","../../src/shared/components/print.tsx","../../src/shared/index.ts"],"sourcesContent":["'use strict';\n\nvar m = require('react-dom');\nif (process.env.NODE_ENV === 'production') {\n exports.createRoot = m.createRoot;\n exports.hydrateRoot = m.hydrateRoot;\n} else {\n var i = m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;\n exports.createRoot = function(c, o) {\n i.usingClientEntryPoint = true;\n try {\n return m.createRoot(c, o);\n } finally {\n i.usingClientEntryPoint = false;\n }\n };\n exports.hydrateRoot = function(c, h, o) {\n i.usingClientEntryPoint = true;\n try {\n return m.hydrateRoot(c, h, o);\n } finally {\n i.usingClientEntryPoint = false;\n }\n };\n}\n","import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { PrintPlugin } from '@embedpdf/plugin-print';\n\nexport const usePrintPlugin = () => usePlugin<PrintPlugin>(PrintPlugin.id);\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n","import { useEffect, useRef } from '@framework';\nimport { usePrintCapability, usePrintPlugin } from '../hooks';\n\nexport function PrintFrame() {\n const { provides: printCapability } = usePrintCapability();\n const { plugin: printPlugin } = usePrintPlugin();\n const iframeRef = useRef<HTMLIFrameElement | null>(null);\n const urlRef = useRef<string | null>(null);\n\n useEffect(() => {\n if (!printCapability || !printPlugin) return;\n\n const unsubscribe = printPlugin.onPrintRequest(({ buffer, task }) => {\n const iframe = iframeRef.current;\n if (!iframe) return;\n\n // cleanup old URL\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n\n const url = URL.createObjectURL(new Blob([buffer], { type: 'application/pdf' }));\n urlRef.current = url;\n\n iframe.onload = () => {\n if (iframe.src === url) {\n task.progress({ stage: 'iframe-ready', message: 'Ready to print' });\n iframe.contentWindow?.focus();\n iframe.contentWindow?.print();\n task.progress({ stage: 'printing', message: 'Print dialog opened' });\n task.resolve(buffer);\n }\n };\n\n iframe.src = url;\n });\n\n return () => {\n unsubscribe();\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n }\n };\n }, [printCapability, printPlugin]);\n\n return (\n <iframe\n ref={iframeRef}\n style={{ position: 'absolute', display: 'none' }}\n title=\"Print Document\"\n src=\"about:blank\"\n />\n );\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { PrintPluginPackage as BasePrintPackage } from '@embedpdf/plugin-print';\n\nimport { PrintFrame } from './components';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-print';\n\nexport const PrintPluginPackage = createPluginPackage(BasePrintPackage)\n .addUtility(PrintFrame)\n .build();\n"],"names":["m","require$$0","process","env","NODE_ENV","client","createRoot","hydrateRoot","i","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","c","o","usingClientEntryPoint","h","usePrintPlugin","usePlugin","PrintPlugin","id","usePrintCapability","useCapability","PrintFrame","provides","printCapability","plugin","printPlugin","iframeRef","useRef","urlRef","useEffect","unsubscribe","onPrintRequest","buffer","task","iframe","current","URL","revokeObjectURL","url","createObjectURL","Blob","type","onload","src","progress","stage","message","_a","contentWindow","focus","_b","print","resolve","jsxRuntime","jsx","ref","style","position","display","title","PrintPluginPackage","createPluginPackage","BasePrintPackage","addUtility","build"],"mappings":"0SAEA,IAAIA,EAAIC,EACJ,GAAyB,eAAzBC,QAAQC,IAAIC,SACdC,EAAkBC,WAAGN,EAAEM,WACvBD,EAAmBE,YAAGP,EAAEO,gBACnB,CACL,IAAIC,EAAIR,EAAES,gEACW,SAASC,EAAGC,GAC/BH,EAAEI,uBAAwB,EACtB,IACK,OAAAZ,EAAEM,WAAWI,EAAGC,EAC7B,CAAc,QACRH,EAAEI,uBAAwB,CAChC,CACG,EACDP,EAAAE,YAAsB,SAASG,EAAGG,EAAGF,GACnCH,EAAEI,uBAAwB,EACtB,IACF,OAAOZ,EAAEO,YAAYG,EAAGG,EAAGF,EACjC,CAAc,QACRH,EAAEI,uBAAwB,CAChC,CACG,CACH,KCrBO,MAAME,EAAiB,IAAMC,YAAuBC,EAAAA,YAAYC,IAC1DC,EAAqB,IAAMC,gBAA2BH,EAAAA,YAAYC,ICDxE,SAASG,IACd,MAAQC,SAAUC,GAAoBJ,KAC9BK,OAAQC,GAAgBV,IAC1BW,EAAYC,SAAiC,MAC7CC,EAASD,SAAsB,MAwCnC,OAtCFE,EAAAA,WAAU,KACJ,IAACN,IAAoBE,EAAa,OAEtC,MAAMK,EAAcL,EAAYM,gBAAe,EAAGC,SAAQC,WACxD,MAAMC,EAASR,EAAUS,QACzB,IAAKD,EAAQ,OAGTN,EAAOO,UACLC,IAAAC,gBAAgBT,EAAOO,SAC3BP,EAAOO,QAAU,MAGnB,MAAMG,EAAMF,IAAIG,gBAAgB,IAAIC,KAAK,CAACR,GAAS,CAAES,KAAM,qBAC3Db,EAAOO,QAAUG,EAEjBJ,EAAOQ,OAAS,aACVR,EAAOS,MAAQL,IACjBL,EAAKW,SAAS,CAAEC,MAAO,eAAgBC,QAAS,mBAChD,OAAAC,EAAAb,EAAOc,gBAAeD,EAAAE,QACtB,OAAAC,EAAAhB,EAAOc,gBAAeE,EAAAC,QACtBlB,EAAKW,SAAS,CAAEC,MAAO,WAAYC,QAAS,wBAC5Cb,EAAKmB,QAAQpB,GAAM,EAIvBE,EAAOS,IAAML,CAAA,IAGf,MAAO,KACOR,IACRF,EAAOO,SACLC,IAAAC,gBAAgBT,EAAOO,QAAO,CAEtC,GACC,CAACZ,EAAiBE,IAGnB4B,EAAAC,IAAC,SAAA,CACCC,IAAK7B,EACL8B,MAAO,CAAEC,SAAU,WAAYC,QAAS,QACxCC,MAAM,iBACNhB,IAAI,eAGV,CC7CO,MAAMiB,EAAqBC,EAAoBA,oBAAAC,EAAgBF,oBACnEG,WAAW1C,GACX2C","x_google_ignoreList":[0]}
1
+ {"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\n/**\n * Hook for print capability for a specific document\n * @param documentId Document ID\n */\nexport const usePrint = (documentId: string) => {\n const { provides } = usePrintCapability();\n\n return {\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\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","jsx","ref","style","position","display","title","PrintPluginPackage","createPluginPackage","BasePrintPackage","addUtility","build","documentId","forDocument"],"mappings":"0SAEA,IAAIA,EAAIC,EACR,GAA6B,eAAzBC,QAAQC,IAAIC,SACdC,EAAAC,WAAqBN,EAAEM,WACvBD,EAAAE,YAAsBP,EAAEO,gBACnB,CACL,IAAIC,EAAIR,EAAES,mDACVJ,aAAqB,SAASK,EAAGC,GAC/BH,EAAEI,uBAAwB,EAC1B,IACE,OAAOZ,EAAEM,WAAWI,EAAGC,EAC7B,CAAA,QACMH,EAAEI,uBAAwB,CAChC,CACA,EACEP,EAAAE,YAAsB,SAASG,EAAGG,EAAGF,GACnCH,EAAEI,uBAAwB,EAC1B,IACE,OAAOZ,EAAEO,YAAYG,EAAGG,EAAGF,EACjC,CAAA,QACMH,EAAEI,uBAAwB,CAChC,CACA,CACA,KCrBO,MAAME,EAAiB,IAAMC,YAAuBC,EAAAA,YAAYC,IAC1DC,EAAqB,IAAMC,gBAA2BH,EAAAA,YAAYC,ICDxE,SAASG,IACd,MAAQC,SAAUC,GAAoBJ,KAC9BK,OAAQC,GAAgBV,IAC1BW,EAAYC,EAAAA,OAAiC,MAC7CC,EAASD,EAAAA,OAAsB,MAuCrC,OArCAE,EAAAA,UAAU,KACR,IAAKN,IAAoBE,EAAa,OAEtC,MAAMK,EAAcL,EAAYM,eAAe,EAAGC,SAAQC,WACxD,MAAMC,EAASR,EAAUS,QACzB,IAAKD,EAAQ,OAGTN,EAAOO,UACTC,IAAIC,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,gBAAPD,EAAsBE,QACtB,OAAAC,EAAAhB,EAAOc,gBAAPE,EAAsBC,QACtBlB,EAAKW,SAAS,CAAEC,MAAO,WAAYC,QAAS,wBAC5Cb,EAAKmB,QAAQpB,KAIjBE,EAAOS,IAAML,IAGf,MAAO,KACLR,IACIF,EAAOO,SACTC,IAAIC,gBAAgBT,EAAOO,WAG9B,CAACZ,EAAiBE,IAGnB4B,EAAAA,IAAC,SAAA,CACCC,IAAK5B,EACL6B,MAAO,CAAEC,SAAU,WAAYC,QAAS,QACxCC,MAAM,iBACNf,IAAI,eAGV,CC7CO,MAAMgB,EAAqBC,EAAAA,oBAAoBC,EAAAA,oBACnDC,WAAWzC,GACX0C,2EFDsBC,IACvB,MAAM1C,SAAEA,GAAaH,IAErB,MAAO,CACLG,UAAU,MAAAA,OAAA,EAAAA,EAAU2C,YAAYD,KAAe","x_google_ignoreList":[0]}
@@ -38,6 +38,12 @@ function requireClient() {
38
38
  requireClient();
39
39
  const usePrintPlugin = () => usePlugin(PrintPlugin.id);
40
40
  const usePrintCapability = () => useCapability(PrintPlugin.id);
41
+ const usePrint = (documentId) => {
42
+ const { provides } = usePrintCapability();
43
+ return {
44
+ provides: (provides == null ? void 0 : provides.forDocument(documentId)) ?? null
45
+ };
46
+ };
41
47
  function PrintFrame() {
42
48
  const { provides: printCapability } = usePrintCapability();
43
49
  const { plugin: printPlugin } = usePrintPlugin();
@@ -87,6 +93,7 @@ const PrintPluginPackage = createPluginPackage(PrintPluginPackage$1).addUtility(
87
93
  export {
88
94
  PrintFrame,
89
95
  PrintPluginPackage,
96
+ usePrint,
90
97
  usePrintCapability,
91
98
  usePrintPlugin
92
99
  };
@@ -1 +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,MAAM,cAA2B,YAAY,EAAE;ACD1E,SAAS,aAAa;AAC3B,QAAM,EAAE,UAAU,gBAAgB,IAAI,mBAAmB;AACzD,QAAM,EAAE,QAAQ,YAAY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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\n/**\n * Hook for print capability for a specific document\n * @param documentId Document ID\n */\nexport const usePrint = (documentId: string) => {\n const { provides } = usePrintCapability();\n\n return {\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\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,WAAA,aAAqB,EAAE;AACvB,WAAA,cAAsB,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,UAAK;AACC,UAAE,wBAAwB;AAAA,MAChC;AAAA,IACA;AACE,WAAA,cAAsB,SAAS,GAAG,GAAG,GAAG;AACtC,QAAE,wBAAwB;AAC1B,UAAI;AACF,eAAO,EAAE,YAAY,GAAG,GAAG,CAAC;AAAA,MAClC,UAAK;AACC,UAAE,wBAAwB;AAAA,MAChC;AAAA,IACA;AAAA,EACA;;;;ACrBO,MAAM,iBAAiB,MAAM,UAAuB,YAAY,EAAE;AAClE,MAAM,qBAAqB,MAAM,cAA2B,YAAY,EAAE;AAM1E,MAAM,WAAW,CAAC,eAAuB;AAC9C,QAAM,EAAE,SAAA,IAAa,mBAAA;AAErB,SA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B,oBAAoBA,oBAAgB,EACnE,WAAW,UAAU,EACrB,MAAA;","x_google_ignoreList":[0]}
@@ -9,3 +9,10 @@ export declare const usePrintCapability: () => {
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
11
  };
12
+ /**
13
+ * Hook for print capability for a specific document
14
+ * @param documentId Document ID
15
+ */
16
+ export declare const usePrint: (documentId: string) => {
17
+ provides: import('../../index.ts').PrintScope | null;
18
+ };
@@ -9,3 +9,10 @@ export declare const usePrintCapability: () => {
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
11
  };
12
+ /**
13
+ * Hook for print capability for a specific document
14
+ * @param documentId Document ID
15
+ */
16
+ export declare const usePrint: (documentId: string) => {
17
+ provides: import('../../lib/index.ts').PrintScope | null;
18
+ };
@@ -9,3 +9,10 @@ export declare const usePrintCapability: () => {
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
11
  };
12
+ /**
13
+ * Hook for print capability for a specific document
14
+ * @param documentId Document ID
15
+ */
16
+ export declare const usePrint: (documentId: string) => {
17
+ provides: import('../../lib/index.ts').PrintScope | null;
18
+ };
@@ -1,4 +1,13 @@
1
- import { PrintPlugin } from '../../lib/index.ts';
1
+ import { PrintPlugin, PrintScope } from '../../lib/index.ts';
2
+ /**
3
+ * Hook to get the raw print plugin instance.
4
+ * Useful for accessing plugin-specific properties or methods not exposed in the capability.
5
+ */
6
+ export declare const usePrintPlugin: () => {
7
+ plugin: PrintPlugin | null;
8
+ isLoading: boolean;
9
+ ready: Promise<void>;
10
+ };
2
11
  /**
3
12
  * Hook to get the print plugin's capability API.
4
13
  * This provides methods for initiating print operations.
@@ -8,12 +17,12 @@ export declare const usePrintCapability: () => {
8
17
  isLoading: boolean;
9
18
  ready: Promise<void>;
10
19
  };
20
+ interface UsePrintReturn {
21
+ provides: PrintScope | null;
22
+ }
11
23
  /**
12
- * Hook to get the raw print plugin instance.
13
- * Useful for accessing plugin-specific properties or methods not exposed in the capability.
24
+ * Hook for print capability for a specific document
25
+ * @param getDocumentId Function that returns the document ID
14
26
  */
15
- export declare const usePrintPlugin: () => {
16
- plugin: PrintPlugin | null;
17
- isLoading: boolean;
18
- ready: Promise<void>;
19
- };
27
+ export declare const usePrint: (getDocumentId: () => string | null) => UsePrintReturn;
28
+ export {};
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),t=require("@embedpdf/core/svelte"),r=require("@embedpdf/plugin-print");require("svelte/internal/disclose-version");const n=require("@embedpdf/core");function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}const o=i(e),l=()=>t.useCapability(r.PrintPlugin.id),s=()=>t.usePlugin(r.PrintPlugin.id);var a=o.from_html('<iframe title="Print Document" src="about:blank" style="position: absolute; display: none;"></iframe>');function u(e,t){o.push(t,!0);const r=l(),n=s();let i=o.state(null),u=null;o.user_effect((()=>{if(!r.provides||!n.plugin)return;const e=n.plugin.onPrintRequest((({buffer:e,task:t})=>{const r=o.get(i);if(!r)return;u&&(URL.revokeObjectURL(u),u=null);const n=URL.createObjectURL(new Blob([e],{type:"application/pdf"}));u=n,r.onload=()=>{var i,o;r.src===n&&(t.progress({stage:"iframe-ready",message:"Ready to print"}),null==(i=r.contentWindow)||i.focus(),null==(o=r.contentWindow)||o.print(),t.progress({stage:"printing",message:"Print dialog opened"}),t.resolve(e))},r.src=n}));return()=>{e(),u&&(URL.revokeObjectURL(u),u=null)}}));var c=a();o.bind_this(c,(e=>o.set(i,e)),(()=>o.get(i))),o.append(e,c),o.pop()}const c=n.createPluginPackage(r.PrintPluginPackage).addUtility(u).build();exports.PrintFrame=u,exports.PrintPluginPackage=c,exports.usePrintCapability=l,exports.usePrintPlugin=s,Object.keys(r).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})}));
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),t=require("@embedpdf/core/svelte"),r=require("@embedpdf/plugin-print");require("svelte/internal/disclose-version");const n=require("@embedpdf/core");function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}const o=i(e),s=()=>t.usePlugin(r.PrintPlugin.id),l=()=>t.useCapability(r.PrintPlugin.id);var u=o.from_html('<iframe title="Print Document" src="about:blank" style="position: absolute; display: none;"></iframe>');function a(e,t){o.push(t,!0);const r=l(),n=s();let i=o.state(null),a=null;o.user_effect(()=>{if(!r.provides||!n.plugin)return;const e=n.plugin.onPrintRequest(({buffer:e,task:t})=>{const r=o.get(i);if(!r)return;a&&(URL.revokeObjectURL(a),a=null);const n=URL.createObjectURL(new Blob([e],{type:"application/pdf"}));a=n,r.onload=()=>{var i,o;r.src===n&&(t.progress({stage:"iframe-ready",message:"Ready to print"}),null==(i=r.contentWindow)||i.focus(),null==(o=r.contentWindow)||o.print(),t.progress({stage:"printing",message:"Print dialog opened"}),t.resolve(e))},r.src=n});return()=>{e(),a&&(URL.revokeObjectURL(a),a=null)}});var c=u();o.bind_this(c,e=>o.set(i,e),()=>o.get(i)),o.append(e,c),o.pop()}const c=n.createPluginPackage(r.PrintPluginPackage).addUtility(a).build();exports.PrintFrame=a,exports.PrintPluginPackage=c,exports.usePrint=e=>{const t=l(),r=o.derived(e),n=o.derived(()=>t.provides&&o.get(r)?t.provides.forDocument(o.get(r)):null);return{get provides(){return o.get(n)}}},exports.usePrintCapability=l,exports.usePrintPlugin=s,Object.keys(r).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-print.svelte.ts","../../src/svelte/components/print.svelte","../../src/svelte/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { PrintPlugin } from '@embedpdf/plugin-print';\n\n/**\n * Hook to get the print plugin's capability API.\n * This provides methods for initiating print operations.\n */\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n\n/**\n * Hook to get the raw print plugin instance.\n * Useful for accessing plugin-specific properties or methods not exposed in the capability.\n */\nexport const usePrintPlugin = () => usePlugin<PrintPlugin>(PrintPlugin.id);\n","<script lang=\"ts\">\n import { usePrintCapability, usePrintPlugin } from '../hooks';\n\n const printCapability = usePrintCapability();\n const printPlugin = usePrintPlugin();\n\n let iframeRef = $state<HTMLIFrameElement | null>(null);\n let urlRef: string | null = null;\n\n $effect(() => {\n if (!printCapability.provides || !printPlugin.plugin) return;\n\n const unsubscribe = printPlugin.plugin.onPrintRequest(({ buffer, task }) => {\n const iframe = iframeRef;\n if (!iframe) return;\n\n // cleanup old URL\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n\n const url = URL.createObjectURL(new Blob([buffer], { type: 'application/pdf' }));\n urlRef = 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) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n };\n });\n</script>\n\n<iframe\n bind:this={iframeRef}\n title=\"Print Document\"\n src=\"about:blank\"\n style=\"position: absolute; display: none;\"\n>\n</iframe>\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 Svelte-flavoured package by adding the Svelte 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":["usePrintCapability","useCapability","PrintPlugin","id","usePrintPlugin","usePlugin","printCapability","printPlugin","iframeRef","urlRef","$","user_effect","provides","plugin","unsubscribe","onPrintRequest","buffer","task","iframe","URL","revokeObjectURL","url","createObjectURL","Blob","type","onload","src","progress","stage","message","_a","contentWindow","focus","_b","print","resolve","bind_this","iframe_1","$$value","set","PrintPluginPackage","createPluginPackage","BasePrintPackage","addUtility","PrintFrame","build"],"mappings":"uiBAOaA,EAA2B,IAAAC,gBAA2BC,EAAAA,YAAYC,IAMlEC,EAAuB,IAAAC,YAAuBH,EAAAA,YAAYC,4JCV/D,MAAAG,EAAkBN,IAClBO,EAAcH,IAEhB,IAAAI,UAA6C,MAC7CC,EAAwB,KAE5BC,EAAAC,aAAc,KACP,IAAAL,EAAgBM,WAAaL,EAAYM,OAAM,OAE9C,MAAAC,EAAcP,EAAYM,OAAOE,gBAAkB,EAAAC,SAAQC,WACzD,MAAAC,QAASV,OACVU,EAAM,OAGPT,IACFU,IAAIC,gBAAgBX,GACXA,EAAA,YAGLY,EAAMF,IAAIG,gBAAe,IAAKC,KAAI,CAAEP,GAAM,CAAKQ,KAAM,qBAClDf,EAAAY,EAETH,EAAOO,OAAe,aAChBP,EAAOQ,MAAQL,IACjBJ,EAAKU,SAAW,CAAAC,MAAO,eAAgBC,QAAS,mBAChD,OAAAC,EAAAZ,EAAOa,gBAAeD,EAAAE,QACtB,OAAAC,EAAAf,EAAOa,gBAAeE,EAAAC,QACtBjB,EAAKU,SAAW,CAAAC,MAAO,WAAYC,QAAS,wBAC5CZ,EAAKkB,QAAQnB,GACf,EAGFE,EAAOQ,IAAML,CAAA,IAGF,MAAA,KACAP,IACPL,IACFU,IAAIC,gBAAgBX,GACXA,EAAA,KACX,CACD,cAKQC,EAAA0B,UAAAC,GAAAC,GAAA5B,EAAA6B,IAAA/B,iBAAAA,0BAHb,CClCO,MAAMgC,EAAqBC,EAAoBA,oBAAAC,EAAgBF,oBACnEG,WAAWC,GACXC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-print.svelte.ts","../../src/svelte/components/print.svelte","../../src/svelte/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { PrintPlugin, PrintScope } from '@embedpdf/plugin-print';\n\n/**\n * Hook to get the raw print plugin instance.\n * Useful for accessing plugin-specific properties or methods not exposed in the capability.\n */\nexport const usePrintPlugin = () => usePlugin<PrintPlugin>(PrintPlugin.id);\n\n/**\n * Hook to get the print plugin's capability API.\n * This provides methods for initiating print operations.\n */\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UsePrintReturn {\n provides: PrintScope | null;\n}\n\n/**\n * Hook for print capability for a specific document\n * @param getDocumentId Function that returns the document ID\n */\nexport const usePrint = (getDocumentId: () => string | null): UsePrintReturn => {\n const capability = usePrintCapability();\n\n // Reactive documentId\n const documentId = $derived(getDocumentId());\n\n // Scoped capability for current docId\n const scopedProvides = $derived(\n capability.provides && documentId ? capability.provides.forDocument(documentId) : null,\n );\n\n return {\n get provides() {\n return scopedProvides;\n },\n };\n};\n","<script lang=\"ts\">\n import { usePrintCapability, usePrintPlugin } from '../hooks';\n\n const printCapability = usePrintCapability();\n const printPlugin = usePrintPlugin();\n\n let iframeRef = $state<HTMLIFrameElement | null>(null);\n let urlRef: string | null = null;\n\n $effect(() => {\n if (!printCapability.provides || !printPlugin.plugin) return;\n\n const unsubscribe = printPlugin.plugin.onPrintRequest(({ buffer, task }) => {\n const iframe = iframeRef;\n if (!iframe) return;\n\n // cleanup old URL\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n\n const url = URL.createObjectURL(new Blob([buffer], { type: 'application/pdf' }));\n urlRef = 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) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n };\n });\n</script>\n\n<iframe\n bind:this={iframeRef}\n title=\"Print Document\"\n src=\"about:blank\"\n style=\"position: absolute; display: none;\"\n>\n</iframe>\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 Svelte-flavoured package by adding the Svelte 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","printCapability","printPlugin","iframeRef","urlRef","$","user_effect","provides","plugin","unsubscribe","onPrintRequest","buffer","task","iframe","URL","revokeObjectURL","url","createObjectURL","Blob","type","onload","src","progress","stage","message","_a","contentWindow","focus","_b","print","resolve","bind_this","iframe_1","$$value","set","PrintPluginPackage","createPluginPackage","BasePrintPackage","addUtility","PrintFrame","build","getDocumentId","capability","documentId","scopedProvides","derived","forDocument"],"mappings":"uiBAOaA,EAAA,IAAuBC,YAAuBC,EAAAA,YAAYC,IAM1DC,EAAA,IAA2BC,gBAA2BH,EAAAA,YAAYC,4JCVvE,MAAAG,EAAkBF,IAClBG,EAAcP,IAEhB,IAAAQ,UAA6C,MAC7CC,EAAwB,KAE5BC,EAAAC,YAAO,KACA,IAAAL,EAAgBM,WAAaL,EAAYM,OAAM,aAE9CC,EAAcP,EAAYM,OAAOE,eAAc,EAAIC,SAAQC,WACzD,MAAAC,QAASV,OACVU,EAAM,OAGPT,IACFU,IAAIC,gBAAgBX,GACpBA,EAAS,YAGLY,EAAMF,IAAIG,gBAAe,IAAKC,KAAI,CAAEP,GAAM,CAAKQ,KAAM,qBAC3Df,EAASY,EAETH,EAAOO,OAAM,aACPP,EAAOQ,MAAQL,IACjBJ,EAAKU,SAAQ,CAAGC,MAAO,eAAgBC,QAAS,mBAChD,OAAAC,EAAAZ,EAAOa,gBAAPD,EAAsBE,QACtB,OAAAC,EAAAf,EAAOa,gBAAPE,EAAsBC,QACtBjB,EAAKU,SAAQ,CAAGC,MAAO,WAAYC,QAAS,wBAC5CZ,EAAKkB,QAAQnB,KAIjBE,EAAOQ,IAAML,IAGF,MAAA,KACXP,IACIL,IACFU,IAAIC,gBAAgBX,GACpBA,EAAS,mBAOJC,EAAA0B,UAAAC,EAAAC,GAAA5B,EAAA6B,IAAA/B,eAAAA,yBAHb,CClCO,MAAMgC,EAAqBC,EAAAA,oBAAoBC,EAAAA,oBACnDC,WAAWC,GACXC,2EFUsBC,IACjB,MAAAC,EAAa3C,IAGb4C,YAAsBF,GAGtBG,EAAAvC,EAAAwC,QAAA,IACJH,EAAWnC,gBAAYoC,GAAaD,EAAWnC,SAASuC,kBAAYH,IAAc,aAI9E,YAAApC,gBACKqC,EACT"}
@@ -4,8 +4,18 @@ import { PrintPlugin, PrintPluginPackage as PrintPluginPackage$1 } from "@embedp
4
4
  export * from "@embedpdf/plugin-print";
5
5
  import "svelte/internal/disclose-version";
6
6
  import { createPluginPackage } from "@embedpdf/core";
7
- const usePrintCapability = () => useCapability(PrintPlugin.id);
8
7
  const usePrintPlugin = () => usePlugin(PrintPlugin.id);
8
+ const usePrintCapability = () => useCapability(PrintPlugin.id);
9
+ const usePrint = (getDocumentId) => {
10
+ const capability = usePrintCapability();
11
+ const documentId = $.derived(getDocumentId);
12
+ const scopedProvides = $.derived(() => capability.provides && $.get(documentId) ? capability.provides.forDocument($.get(documentId)) : null);
13
+ return {
14
+ get provides() {
15
+ return $.get(scopedProvides);
16
+ }
17
+ };
18
+ };
9
19
  var root = $.from_html(`<iframe title="Print Document" src="about:blank" style="position: absolute; display: none;"></iframe>`);
10
20
  function Print($$anchor, $$props) {
11
21
  $.push($$props, true);
@@ -53,6 +63,7 @@ const PrintPluginPackage = createPluginPackage(PrintPluginPackage$1).addUtility(
53
63
  export {
54
64
  Print as PrintFrame,
55
65
  PrintPluginPackage,
66
+ usePrint,
56
67
  usePrintCapability,
57
68
  usePrintPlugin
58
69
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-print.svelte.ts","../../src/svelte/components/print.svelte","../../src/svelte/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { PrintPlugin } from '@embedpdf/plugin-print';\n\n/**\n * Hook to get the print plugin's capability API.\n * This provides methods for initiating print operations.\n */\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n\n/**\n * Hook to get the raw print plugin instance.\n * Useful for accessing plugin-specific properties or methods not exposed in the capability.\n */\nexport const usePrintPlugin = () => usePlugin<PrintPlugin>(PrintPlugin.id);\n","<script lang=\"ts\">\n import { usePrintCapability, usePrintPlugin } from '../hooks';\n\n const printCapability = usePrintCapability();\n const printPlugin = usePrintPlugin();\n\n let iframeRef = $state<HTMLIFrameElement | null>(null);\n let urlRef: string | null = null;\n\n $effect(() => {\n if (!printCapability.provides || !printPlugin.plugin) return;\n\n const unsubscribe = printPlugin.plugin.onPrintRequest(({ buffer, task }) => {\n const iframe = iframeRef;\n if (!iframe) return;\n\n // cleanup old URL\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n\n const url = URL.createObjectURL(new Blob([buffer], { type: 'application/pdf' }));\n urlRef = 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) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n };\n });\n</script>\n\n<iframe\n bind:this={iframeRef}\n title=\"Print Document\"\n src=\"about:blank\"\n style=\"position: absolute; display: none;\"\n>\n</iframe>\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 Svelte-flavoured package by adding the Svelte 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":["BasePrintPackage","PrintFrame"],"mappings":";;;;;;AAOa,MAAA,qBAA2B,MAAA,cAA2B,YAAY,EAAE;AAMpE,MAAA,iBAAuB,MAAA,UAAuB,YAAY,EAAE;;kCCbzE;;AAGQ,QAAA,kBAAkB,mBAAkB;AACpC,QAAA,cAAc,eAAc;AAE9B,MAAA,oBAA6C,IAAI;AACjD,MAAA,SAAwB;AAE5B,IAAA,YAAc,MAAA;AACP,QAAA,CAAA,gBAAgB,YAAa,CAAA,YAAY,OAAM;UAE9C,cAAc,YAAY,OAAO,eAAkB,CAAA,EAAA,QAAQ,WAAW;AACpE,YAAA,eAAS,SAAS;WACnB,OAAM;AAGP,UAAA,QAAQ;AACV,YAAI,gBAAgB,MAAM;AAC1B,iBAAS;AAAA,MACX;YAEM,MAAM,IAAI,gBAAe,IAAK,KAAI,CAAE,MAAM,GAAA,EAAK,MAAM,kBAAiB,CAAA,CAAA;AAC5E,eAAS;AAET,aAAO,SAAe,MAAA;;AAChB,YAAA,OAAO,QAAQ,KAAK;AACtB,eAAK,SAAW,EAAA,OAAO,gBAAgB,SAAS,kBAAgB;AAChE,uBAAO,kBAAP,mBAAsB;AACtB,uBAAO,kBAAP,mBAAsB;AACtB,eAAK,SAAW,EAAA,OAAO,YAAY,SAAS,uBAAqB;AACjE,eAAK,QAAQ,MAAM;AAAA,QACrB;AAAA,MACD;AAED,aAAO,MAAM;AAAA,KACd;AAEY,WAAA,MAAA;AACX,kBAAW;AACP,UAAA,QAAQ;AACV,YAAI,gBAAgB,MAAM;AAC1B,iBAAS;AAAA,MACX;AAAA,IACD;AAAA,GACF;;AAIU,IAAA,UAAA,UAAA,CAAA,YAAA,EAAA,IAAA,iCAAA,SAAS,CAAA;;;AAHtB;AClCO,MAAM,qBAAqB,oBAAoBA,oBAAgB,EACnE,WAAWC,KAAU,EACrB,MAAM;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-print.svelte.ts","../../src/svelte/components/print.svelte","../../src/svelte/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { PrintPlugin, PrintScope } from '@embedpdf/plugin-print';\n\n/**\n * Hook to get the raw print plugin instance.\n * Useful for accessing plugin-specific properties or methods not exposed in the capability.\n */\nexport const usePrintPlugin = () => usePlugin<PrintPlugin>(PrintPlugin.id);\n\n/**\n * Hook to get the print plugin's capability API.\n * This provides methods for initiating print operations.\n */\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UsePrintReturn {\n provides: PrintScope | null;\n}\n\n/**\n * Hook for print capability for a specific document\n * @param getDocumentId Function that returns the document ID\n */\nexport const usePrint = (getDocumentId: () => string | null): UsePrintReturn => {\n const capability = usePrintCapability();\n\n // Reactive documentId\n const documentId = $derived(getDocumentId());\n\n // Scoped capability for current docId\n const scopedProvides = $derived(\n capability.provides && documentId ? capability.provides.forDocument(documentId) : null,\n );\n\n return {\n get provides() {\n return scopedProvides;\n },\n };\n};\n","<script lang=\"ts\">\n import { usePrintCapability, usePrintPlugin } from '../hooks';\n\n const printCapability = usePrintCapability();\n const printPlugin = usePrintPlugin();\n\n let iframeRef = $state<HTMLIFrameElement | null>(null);\n let urlRef: string | null = null;\n\n $effect(() => {\n if (!printCapability.provides || !printPlugin.plugin) return;\n\n const unsubscribe = printPlugin.plugin.onPrintRequest(({ buffer, task }) => {\n const iframe = iframeRef;\n if (!iframe) return;\n\n // cleanup old URL\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n\n const url = URL.createObjectURL(new Blob([buffer], { type: 'application/pdf' }));\n urlRef = 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) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n };\n });\n</script>\n\n<iframe\n bind:this={iframeRef}\n title=\"Print Document\"\n src=\"about:blank\"\n style=\"position: absolute; display: none;\"\n>\n</iframe>\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 Svelte-flavoured package by adding the Svelte 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":["BasePrintPackage","PrintFrame"],"mappings":";;;;;;AAOa,MAAA,iBAAA,MAAuB,UAAuB,YAAY,EAAE;AAM5D,MAAA,qBAAA,MA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AAM,qBAAqB,oBAAoBA,oBAAgB,EACnE,WAAWC,KAAU,EACrB,MAAA;"}
@@ -1,2 +1,3 @@
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>;
1
+ declare const __VLS_export: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
2
3
  export default _default;
@@ -1,3 +1,11 @@
1
1
  import { PrintPlugin } from '../../lib/index.ts';
2
+ import { MaybeRefOrGetter } from 'vue';
2
3
  export declare const usePrintPlugin: () => import('@embedpdf/core/vue').PluginState<PrintPlugin>;
3
4
  export declare const usePrintCapability: () => import('@embedpdf/core/vue').CapabilityState<Readonly<import('../../lib/index.ts').PrintCapability>>;
5
+ /**
6
+ * Hook for print capability for a specific document
7
+ * @param documentId Document ID (can be ref, computed, getter, or plain value)
8
+ */
9
+ export declare const usePrint: (documentId: MaybeRefOrGetter<string>) => {
10
+ provides: import('vue').ComputedRef<import('../../lib/index.ts').PrintScope | null>;
11
+ };
@@ -1,2 +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]})}));
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"),o=()=>e.usePlugin(t.PrintPlugin.id),l=()=>e.useCapability(t.PrintPlugin.id),u=r.defineComponent({__name:"print",setup(e){const t=r.ref(null),n=r.ref(null),{provides:u}=l(),{plugin:i}=o();let a;return r.onMounted(()=>{u.value&&i.value&&(a=i.value.onPrintRequest(({buffer:e,task:r})=>{const o=t.value;if(!o)return;n.value&&(URL.revokeObjectURL(n.value),n.value=null);const l=URL.createObjectURL(new Blob([e],{type:"application/pdf"}));n.value=l,o.onload=()=>{var t,n;o.src===l&&(r.progress({stage:"iframe-ready",message:"Ready to print"}),null==(t=o.contentWindow)||t.focus(),null==(n=o.contentWindow)||n.print(),r.progress({stage:"printing",message:"Print dialog opened"}),r.resolve(e))},o.src=l}))}),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))}}),i=n.createPluginPackage(t.PrintPluginPackage).addUtility(u).build();exports.PrintFrame=u,exports.PrintPluginPackage=i,exports.usePrint=e=>{const{provides:t}=l();return{provides:r.computed(()=>{var n;const o=r.toValue(e);return(null==(n=t.value)?void 0:n.forDocument(o))??null})}},exports.usePrintCapability=l,exports.usePrintPlugin=o,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/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"}
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';\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue';\n\nexport const usePrintPlugin = () => usePlugin<PrintPlugin>(PrintPlugin.id);\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n\n/**\n * Hook for print capability for a specific document\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport const usePrint = (documentId: MaybeRefOrGetter<string>) => {\n const { provides } = usePrintCapability();\n\n // Return a computed ref for the scoped capability\n const scopedProvides = computed(() => {\n const docId = toValue(documentId);\n return provides.value?.forDocument(docId) ?? null;\n });\n\n return {\n provides: scopedProvides,\n };\n};\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","title","style","position","display","PrintPluginPackage","createPluginPackage","BasePrintPackage","addUtility","PrintFrame","build","documentId","computed","docId","toValue","forDocument"],"mappings":"uMAIaA,EAAiB,IAAMC,YAAuBC,EAAAA,YAAYC,IAC1DC,EAAqB,IAAMC,gBAA2BH,EAAAA,YAAYC,iDCQ/E,MAAMG,EAAYC,EAAAA,IAA8B,MAC1CC,EAASD,EAAAA,IAAmB,OAE1BE,SAAUC,GAAoBN,KAC9BO,OAAQC,GAAgBZ,IAEhC,IAAIa,SAEJC,EAAAA,UAAU,KACHJ,EAAgBK,OAAUH,EAAYG,QAE3CF,EAAcD,EAAYG,MAAMC,eAAe,EAAGC,SAAQC,WACxD,MAAMC,EAASb,EAAUS,MACzB,IAAKI,EAAQ,OAETX,EAAOO,QACTK,IAAIC,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,gBAAPD,EAAsBE,QACtB,OAAAC,EAAAf,EAAOa,gBAAPE,EAAsBC,QACtBjB,EAAKU,SAAS,CAAEC,MAAO,WAAYC,QAAS,wBAC5CZ,EAAKkB,QAAQnB,KAIjBE,EAAOQ,IAAML,OAIjBe,EAAAA,YAAY,KACV,MAAAxB,GAAAA,IACIL,EAAOO,OACTK,IAAIC,gBAAgBb,EAAOO,+BApD7BuB,EAAAA,mBAKE,SAAA,SAJI,YAAJ/B,IAAID,EACJiC,MAAM,iBACNZ,IAAI,cACHa,MAAO,CAAAC,SAAA,WAAAC,QAAA,uBCOCC,EAAqBC,EAAAA,oBAAoBC,EAAAA,oBACnDC,WAAWC,GACXC,2EFHsBC,IACvB,MAAMxC,SAAEA,GAAaL,IAQrB,MAAO,CACLK,SANqByC,EAAAA,SAAS,WAC9B,MAAMC,EAAQC,EAAAA,QAAQH,GACtB,OAAO,OAAAlB,EAAAtB,EAASM,YAAT,EAAAgB,EAAgBsB,YAAYF,KAAU"}
package/dist/vue/index.js CHANGED
@@ -1,10 +1,21 @@
1
1
  import { useCapability, usePlugin } from "@embedpdf/core/vue";
2
2
  import { PrintPlugin, PrintPluginPackage as PrintPluginPackage$1 } from "@embedpdf/plugin-print";
3
3
  export * from "@embedpdf/plugin-print";
4
- import { defineComponent, ref, onMounted, onUnmounted, createElementBlock, openBlock } from "vue";
4
+ import { computed, toValue, defineComponent, ref, onMounted, onUnmounted, createElementBlock, openBlock } from "vue";
5
5
  import { createPluginPackage } from "@embedpdf/core";
6
6
  const usePrintPlugin = () => usePlugin(PrintPlugin.id);
7
7
  const usePrintCapability = () => useCapability(PrintPlugin.id);
8
+ const usePrint = (documentId) => {
9
+ const { provides } = usePrintCapability();
10
+ const scopedProvides = computed(() => {
11
+ var _a;
12
+ const docId = toValue(documentId);
13
+ return ((_a = provides.value) == null ? void 0 : _a.forDocument(docId)) ?? null;
14
+ });
15
+ return {
16
+ provides: scopedProvides
17
+ };
18
+ };
8
19
  const _sfc_main = /* @__PURE__ */ defineComponent({
9
20
  __name: "print",
10
21
  setup(__props) {
@@ -58,6 +69,7 @@ const PrintPluginPackage = createPluginPackage(PrintPluginPackage$1).addUtility(
58
69
  export {
59
70
  _sfc_main as PrintFrame,
60
71
  PrintPluginPackage,
72
+ usePrint,
61
73
  usePrintCapability,
62
74
  usePrintPlugin
63
75
  };
@@ -1 +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;"}
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';\nimport { computed, toValue, type MaybeRefOrGetter } from 'vue';\n\nexport const usePrintPlugin = () => usePlugin<PrintPlugin>(PrintPlugin.id);\nexport const usePrintCapability = () => useCapability<PrintPlugin>(PrintPlugin.id);\n\n/**\n * Hook for print capability for a specific document\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport const usePrint = (documentId: MaybeRefOrGetter<string>) => {\n const { provides } = usePrintCapability();\n\n // Return a computed ref for the scoped capability\n const scopedProvides = computed(() => {\n const docId = toValue(documentId);\n return provides.value?.forDocument(docId) ?? null;\n });\n\n return {\n provides: scopedProvides,\n };\n};\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":";;;;;AAIO,MAAM,iBAAiB,MAAM,UAAuB,YAAY,EAAE;AAClE,MAAM,qBAAqB,MAAM,cAA2B,YAAY,EAAE;AAM1E,MAAM,WAAW,CAAC,eAAyC;AAChE,QAAM,EAAE,SAAA,IAAa,mBAAA;AAGrB,QAAM,iBAAiB,SAAS,MAAM;;AACpC,UAAM,QAAQ,QAAQ,UAAU;AAChC,aAAO,cAAS,UAAT,mBAAgB,YAAY,WAAU;AAAA,EAC/C,CAAC;AAED,SAAO;AAAA,IACL,UAAU;AAAA,EAAA;AAEd;;;;ACVA,UAAM,YAAY,IAA8B,IAAI;AACpD,UAAM,SAAS,IAAmB,IAAI;AAEtC,UAAM,EAAE,UAAU,gBAAA,IAAoB,mBAAA;AACtC,UAAM,EAAE,QAAQ,YAAA,IAAgB,eAAA;AAEhC,QAAI;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;AAChB,cAAI,gBAAgB,OAAO,KAAK;AAChC,iBAAO,QAAQ;AAAA,QACjB;AAEA,cAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,MAAM,kBAAA,CAAmB,CAAC;AAC/E,eAAO,QAAQ;AAEf,eAAO,SAAS,MAAM;;AACpB,cAAI,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,UACrB;AAAA,QACF;AAEA,eAAO,MAAM;AAAA,MACf,CAAC;AAAA,IACH,CAAC;AAED,gBAAY,MAAM;AAChB;AACA,UAAI,OAAO,OAAO;AAChB,YAAI,gBAAgB,OAAO,KAAK;AAAA,MAClC;AAAA,IACF,CAAC;;0BAtDCA,mBAKE,UAAA;AAAA,iBAJI;AAAA,QAAJ,KAAI;AAAA,QACJ,OAAM;AAAA,QACN,KAAI;AAAA,QACH,OAAO,EAAA,UAAA,YAAA,SAAA,OAAA;AAAA,MAAA;;;;ACOL,MAAM,qBAAqB,oBAAoBC,oBAAgB,EACnE,WAAWC,SAAU,EACrB,MAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-print",
3
- "version": "1.4.1",
3
+ "version": "2.0.0-next.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",
@@ -34,14 +34,14 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@embedpdf/models": "1.4.1"
37
+ "@embedpdf/models": "2.0.0-next.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/react": "^18.2.0",
41
41
  "@types/react-dom": "^18.2.0",
42
42
  "typescript": "^5.0.0",
43
- "@embedpdf/core": "1.4.1",
44
- "@embedpdf/build": "1.1.0"
43
+ "@embedpdf/build": "1.1.0",
44
+ "@embedpdf/core": "2.0.0-next.0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": ">=18.0.0",
@@ -49,7 +49,7 @@
49
49
  "preact": "^10.26.4",
50
50
  "vue": ">=3.2.0",
51
51
  "svelte": ">=5 <6",
52
- "@embedpdf/core": "1.4.1"
52
+ "@embedpdf/core": "2.0.0-next.0"
53
53
  },
54
54
  "files": [
55
55
  "dist",