@embedpdf/plugin-print 2.1.1 → 2.2.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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
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",i={id:r,name:"Print Plugin",version:"1.0.0",provides:["print"],requires:[],optional:[],defaultConfig:{}},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;
|
|
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:{}},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();if(!this.checkPermission(i,t.PdfPermissionFlag.Print))return this.logger.debug("PrintPlugin","Print",`Cannot print: document ${i} lacks Print permission`),t.PdfTaskHelper.reject({code:t.PdfErrorCode.Security,message:"Document lacks Print permission"});const 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
|
package/dist/index.cjs.map
CHANGED
|
@@ -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};\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","_PrintPlugin","BasePlugin","constructor","registry","_config","super","this","printReady$","createEmitter","buildCapability","print","options","forDocument","documentId","createPrintScope","getActiveDocumentId","printOptions","task","Task","progress","stage","
|
|
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};\n","import { BasePlugin, createEmitter, Listener, PluginRegistry, Unsubscribe } from '@embedpdf/core';\nimport {\n PdfErrorCode,\n PdfErrorReason,\n PdfPermissionFlag,\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\n // Prevent printing without permission\n if (!this.checkPermission(id, PdfPermissionFlag.Print)) {\n this.logger.debug(\n 'PrintPlugin',\n 'Print',\n `Cannot print: document ${id} lacks Print permission`,\n );\n return PdfTaskHelper.reject({\n code: PdfErrorCode.Security,\n message: 'Document lacks Print permission',\n });\n }\n\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","_PrintPlugin","BasePlugin","constructor","registry","_config","super","this","printReady$","createEmitter","buildCapability","print","options","forDocument","documentId","createPrintScope","getActiveDocumentId","checkPermission","PdfPermissionFlag","Print","logger","debug","PdfTaskHelper","reject","code","PdfErrorCode","Security","message","printOptions","task","Task","progress","stage","preparePrintDocument","wait","buffer","emit","error","fail","coreDoc","coreState","core","documents","document","engine","DocNotOpen","onPrintRequest","listener","on","initialize","_","info","destroy","clear","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,CAAA,GCMJC,EAAN,cAA0BC,EAAAA,WAK/B,WAAAC,CAAYT,EAAYU,EAA0BC,GAChDC,MAAMZ,EAAIU,GAHZG,KAAiBC,YAAcC,iBAI/B,CAMU,eAAAC,GACR,MAAO,CAELC,MAAQC,GAA8BL,KAAKI,MAAMC,GAGjDC,YAAcC,GAAuBP,KAAKQ,iBAAiBD,GAE/D,CAMQ,gBAAAC,CAAiBD,GACvB,MAAO,CACLH,MAAQC,GAA8BL,KAAKI,MAAMC,EAASE,GAE9D,CAMQ,KAAAH,CACNC,EACAE,GAEA,MAAMpB,EAAKoB,GAAcP,KAAKS,sBAG9B,IAAKT,KAAKU,gBAAgBvB,EAAIwB,EAAAA,kBAAkBC,OAM9C,OALAZ,KAAKa,OAAOC,MACV,cACA,QACA,0BAA0B3B,4BAErB4B,EAAAA,cAAcC,OAAO,CAC1BC,KAAMC,EAAAA,aAAaC,SACnBC,QAAS,oCAIb,MAAMC,EAAehB,GAAW,CAAA,EAC1BiB,EAAO,IAAIC,OAEjBD,EAAKE,SAAS,CAAEC,MAAO,YAAaL,QAAS,0BAiB7C,OAfgBpB,KAAK0B,qBAAqBL,EAAclC,GAChDwC,KACLC,IACCN,EAAKE,SAAS,CAAEC,MAAO,iBAAkBL,QAAS,mCAElDpB,KAAKC,YAAY4B,KAAK,CACpBtB,WAAYpB,EACZkB,QAASgB,EACTO,SACAN,UAGHQ,GAAUR,EAAKS,KAAKD,IAGhBR,CACT,CAEQ,oBAAAI,CACNrB,EACAE,GAEA,MAAMyB,EAAUhC,KAAKiC,UAAUC,KAAKC,UAAU5B,GAE9C,aAAKyB,WAASI,UAOPpC,KAAKqC,OAAOX,qBAAqBM,EAAQI,SAAU/B,GANjDU,EAAAA,cAAcC,OAAO,CAC1BC,KAAMC,EAAAA,aAAaoB,WACnBlB,QAAS,YAAYb,eAK3B,CAMO,cAAAgC,CAAeC,GACpB,OAAOxC,KAAKC,YAAYwC,GAAGD,EAC7B,CAMA,gBAAME,CAAWC,GACf3C,KAAKa,OAAO+B,KAAK,cAAe,aAAc,2BAChD,CAEA,aAAMC,GACJ7C,KAAKC,YAAY6C,cACX/C,MAAM8C,SACd,GAjHAnD,EAAgBP,GAAK,QADhB,IAAM4D,EAANrD,ECbA,MAAMsD,EAAoE,CAC/E9D,WACA+D,OAAQ,CAACpD,EAAUqD,IAAW,IAAIH,EAAY9D,EAAiBY,EAAUqD,GACzEC,QAAS,OACTC,aAAc,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BasePlugin, createEmitter } from "@embedpdf/core";
|
|
2
|
-
import {
|
|
2
|
+
import { PdfPermissionFlag, PdfTaskHelper, PdfErrorCode, Task } from "@embedpdf/models";
|
|
3
3
|
const PRINT_PLUGIN_ID = "print";
|
|
4
4
|
const manifest = {
|
|
5
5
|
id: PRINT_PLUGIN_ID,
|
|
@@ -39,6 +39,17 @@ const _PrintPlugin = class _PrintPlugin extends BasePlugin {
|
|
|
39
39
|
// ─────────────────────────────────────────────────────────
|
|
40
40
|
print(options, documentId) {
|
|
41
41
|
const id = documentId ?? this.getActiveDocumentId();
|
|
42
|
+
if (!this.checkPermission(id, PdfPermissionFlag.Print)) {
|
|
43
|
+
this.logger.debug(
|
|
44
|
+
"PrintPlugin",
|
|
45
|
+
"Print",
|
|
46
|
+
`Cannot print: document ${id} lacks Print permission`
|
|
47
|
+
);
|
|
48
|
+
return PdfTaskHelper.reject({
|
|
49
|
+
code: PdfErrorCode.Security,
|
|
50
|
+
message: "Document lacks Print permission"
|
|
51
|
+
});
|
|
52
|
+
}
|
|
42
53
|
const printOptions = options ?? {};
|
|
43
54
|
const task = new Task();
|
|
44
55
|
task.progress({ stage: "preparing", message: "Preparing document..." });
|
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};\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":[],"mappings":";;AAGO,MAAM,kBAAkB;AAExB,MAAM,WAA8C;AAAA,EACzD,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,OAAO;AAAA,EAClB,UAAU,CAAA;AAAA,EACV,UAAU,CAAA;AAAA,EACV,eAAe,CAAA;AACjB;
|
|
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};\n","import { BasePlugin, createEmitter, Listener, PluginRegistry, Unsubscribe } from '@embedpdf/core';\nimport {\n PdfErrorCode,\n PdfErrorReason,\n PdfPermissionFlag,\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\n // Prevent printing without permission\n if (!this.checkPermission(id, PdfPermissionFlag.Print)) {\n this.logger.debug(\n 'PrintPlugin',\n 'Print',\n `Cannot print: document ${id} lacks Print permission`,\n );\n return PdfTaskHelper.reject({\n code: PdfErrorCode.Security,\n message: 'Document lacks Print permission',\n });\n }\n\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":[],"mappings":";;AAGO,MAAM,kBAAkB;AAExB,MAAM,WAA8C;AAAA,EACzD,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,OAAO;AAAA,EAClB,UAAU,CAAA;AAAA,EACV,UAAU,CAAA;AAAA,EACV,eAAe,CAAA;AACjB;ACKO,MAAM,eAAN,MAAM,qBAAoB,WAA+C;AAAA,EAK9E,YAAY,IAAY,UAA0B,SAA4B;AAC5E,UAAM,IAAI,QAAQ;AAHpB,SAAiB,cAAc,cAAA;AAAA,EAI/B;AAAA;AAAA;AAAA;AAAA,EAMU,kBAAmC;AAC3C,WAAO;AAAA;AAAA,MAEL,OAAO,CAAC,YAA8B,KAAK,MAAM,OAAO;AAAA;AAAA,MAGxD,aAAa,CAAC,eAAuB,KAAK,iBAAiB,UAAU;AAAA,IAAA;AAAA,EAEzE;AAAA;AAAA;AAAA;AAAA,EAMQ,iBAAiB,YAAgC;AACvD,WAAO;AAAA,MACL,OAAO,CAAC,YAA8B,KAAK,MAAM,SAAS,UAAU;AAAA,IAAA;AAAA,EAExE;AAAA;AAAA;AAAA;AAAA,EAMQ,MACN,SACA,YACkD;AAClD,UAAM,KAAK,cAAc,KAAK,oBAAA;AAG9B,QAAI,CAAC,KAAK,gBAAgB,IAAI,kBAAkB,KAAK,GAAG;AACtD,WAAK,OAAO;AAAA,QACV;AAAA,QACA;AAAA,QACA,0BAA0B,EAAE;AAAA,MAAA;AAE9B,aAAO,cAAc,OAAO;AAAA,QAC1B,MAAM,aAAa;AAAA,QACnB,SAAS;AAAA,MAAA,CACV;AAAA,IACH;AAEA,UAAM,eAAe,WAAW,CAAA;AAChC,UAAM,OAAO,IAAI,KAAA;AAEjB,SAAK,SAAS,EAAE,OAAO,aAAa,SAAS,yBAAyB;AAEtE,UAAM,UAAU,KAAK,qBAAqB,cAAc,EAAE;AAC1D,YAAQ;AAAA,MACN,CAAC,WAAW;AACV,aAAK,SAAS,EAAE,OAAO,kBAAkB,SAAS,kCAAkC;AAEpF,aAAK,YAAY,KAAK;AAAA,UACpB,YAAY;AAAA,UACZ,SAAS;AAAA,UACT;AAAA,UACA;AAAA,QAAA,CACD;AAAA,MACH;AAAA,MACA,CAAC,UAAU,KAAK,KAAK,KAAK;AAAA,IAAA;AAG5B,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;AAlHE,aAAgB,KAAK;AADhB,IAAM,cAAN;ACbA,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;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-print",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.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": "2.
|
|
37
|
+
"@embedpdf/models": "2.2.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
43
|
"@embedpdf/build": "1.1.0",
|
|
44
|
-
"@embedpdf/core": "2.
|
|
44
|
+
"@embedpdf/core": "2.2.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": "2.
|
|
52
|
+
"@embedpdf/core": "2.2.0"
|
|
53
53
|
},
|
|
54
54
|
"files": [
|
|
55
55
|
"dist",
|