@embedpdf/plugin-export 1.5.0 → 2.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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"),o=class extends e.BasePlugin{constructor(t,o,s){super(t,o),this.downloadRequest$=e.createEmitter(),this.config=s}async initialize(e){}buildCapability(){return{saveAsCopy:this.saveAsCopy.bind(this),download:this.download.bind(this)}}onRequest(e){return this.downloadRequest$.on(e)}download(){this.downloadRequest$.emit("download")}saveAsCopyAndGetBufferAndName(){const e=new t.Task,o=this.coreState.core.document;return o?(this.saveAsCopy().wait((t=>{e.resolve({buffer:t,name:o.name??this.config.defaultFileName})}),e.fail),e):t.PdfTaskHelper.reject({code:t.PdfErrorCode.DocNotOpen,message:"Document not found"})}saveAsCopy(){const e=this.coreState.core.document;return e?this.engine.saveAsCopy(e):t.PdfTaskHelper.reject({code:t.PdfErrorCode.DocNotOpen,message:"Document not found"})}};o.id="export";let s=o;const n="export",r={id:n,name:"Export Plugin",version:"1.0.0",provides:["export"],requires:[],optional:[],defaultConfig:{enabled:!0,defaultFileName:"document.pdf"}},i={manifest:r,create:(e,t)=>new s(n,e,t),reducer:()=>{},initialState:{}};exports.EXPORT_PLUGIN_ID=n,exports.ExportPlugin=s,exports.ExportPluginPackage=i,exports.manifest=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/models"),o=class extends e.BasePlugin{constructor(t,o,s){super(t,o),this.downloadRequest$=e.createEmitter(),this.config=s}buildCapability(){return{saveAsCopy:()=>this.saveAsCopy(),download:()=>this.download(),forDocument:e=>this.createExportScope(e)}}createExportScope(e){return{saveAsCopy:()=>this.saveAsCopy(e),download:()=>this.download(e)}}download(e){const t=e??this.getActiveDocumentId();this.downloadRequest$.emit({documentId:t})}saveAsCopy(e){const o=e??this.getActiveDocumentId(),s=this.coreState.core.documents[o];return(null==s?void 0:s.document)?this.engine.saveAsCopy(s.document):t.PdfTaskHelper.reject({code:t.PdfErrorCode.DocNotOpen,message:`Document ${o} not found`})}saveAsCopyAndGetBufferAndName(e){const o=new t.Task,s=this.coreState.core.documents[e];return(null==s?void 0:s.document)?(this.saveAsCopy(e).wait(e=>{o.resolve({buffer:e,name:s.name??this.config.defaultFileName})},e=>o.fail(e)),o):t.PdfTaskHelper.reject({code:t.PdfErrorCode.DocNotOpen,message:`Document ${e} not found`})}onRequest(e){return this.downloadRequest$.on(e)}async initialize(e){this.logger.info("ExportPlugin","Initialize","Export plugin initialized")}async destroy(){this.downloadRequest$.clear(),await super.destroy()}};o.id="export";let s=o;const n="export",r={id:n,name:"Export Plugin",version:"1.0.0",provides:["export"],requires:[],optional:[],defaultConfig:{enabled:!0,defaultFileName:"document.pdf"}},i={manifest:r,create:(e,t)=>new s(n,e,t),reducer:()=>{},initialState:{}};exports.EXPORT_PLUGIN_ID=n,exports.ExportPlugin=s,exports.ExportPluginPackage=i,exports.manifest=r;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/lib/export-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePlugin, createEmitter, Listener, PluginRegistry, Unsubscribe } from '@embedpdf/core';\nimport { PdfErrorCode, PdfErrorReason, PdfTaskHelper, Task } from '@embedpdf/models';\n\nimport { BufferAndName, ExportCapability, ExportPluginConfig } from './types';\n\nexport class ExportPlugin extends BasePlugin<ExportPluginConfig, ExportCapability> {\n static readonly id = 'export' as const;\n\n private readonly downloadRequest$ = createEmitter<'download'>();\n private readonly config: ExportPluginConfig;\n\n constructor(id: string, registry: PluginRegistry, config: ExportPluginConfig) {\n super(id, registry);\n\n this.config = config;\n }\n\n async initialize(_: ExportPluginConfig): Promise<void> {}\n\n protected buildCapability(): ExportCapability {\n return {\n saveAsCopy: this.saveAsCopy.bind(this),\n download: this.download.bind(this),\n };\n }\n\n public onRequest(event: Listener<'download'>): Unsubscribe {\n return this.downloadRequest$.on(event);\n }\n\n private download(): void {\n this.downloadRequest$.emit('download');\n }\n\n public saveAsCopyAndGetBufferAndName(): Task<BufferAndName, PdfErrorReason> {\n const task = new Task<BufferAndName, PdfErrorReason>();\n const document = this.coreState.core.document;\n if (!document)\n return PdfTaskHelper.reject({\n code: PdfErrorCode.DocNotOpen,\n message: 'Document not found',\n });\n\n this.saveAsCopy().wait((result) => {\n task.resolve({\n buffer: result,\n name: document.name ?? this.config.defaultFileName,\n });\n }, task.fail);\n\n return task;\n }\n\n private saveAsCopy(): 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 return this.engine.saveAsCopy(document);\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { ExportPluginConfig } from './types';\n\nexport const EXPORT_PLUGIN_ID = 'export';\n\nexport const manifest: PluginManifest<ExportPluginConfig> = {\n id: EXPORT_PLUGIN_ID,\n name: 'Export Plugin',\n version: '1.0.0',\n provides: ['export'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n defaultFileName: 'document.pdf',\n },\n};\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { ExportPlugin } from './export-plugin';\nimport { manifest, EXPORT_PLUGIN_ID } from './manifest';\nimport { ExportPluginConfig } from './types';\n\nexport const ExportPluginPackage: PluginPackage<ExportPlugin, ExportPluginConfig> = {\n manifest,\n create: (registry, config) => new ExportPlugin(EXPORT_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './export-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["_ExportPlugin","BasePlugin","constructor","id","registry","config","super","this","downloadRequest$","createEmitter","initialize","_","buildCapability","saveAsCopy","bind","download","onRequest","event","on","emit","saveAsCopyAndGetBufferAndName","task","Task","document","coreState","core","wait","result","resolve","buffer","name","defaultFileName","fail","PdfTaskHelper","reject","code","PdfErrorCode","DocNotOpen","message","engine","ExportPlugin","EXPORT_PLUGIN_ID","manifest","version","provides","requires","optional","defaultConfig","enabled","ExportPluginPackage","create","reducer","initialState"],"mappings":"gJAKaA,EAAN,cAA2BC,EAAAA,WAMhC,WAAAC,CAAYC,EAAYC,EAA0BC,GAChDC,MAAMH,EAAIC,GAJKG,KAAAC,iBAAmBC,kBAMlCF,KAAKF,OAASA,CAAA,CAGhB,gBAAMK,CAAWC,GAAsC,CAE7C,eAAAC,GACD,MAAA,CACLC,WAAYN,KAAKM,WAAWC,KAAKP,MACjCQ,SAAUR,KAAKQ,SAASD,KAAKP,MAC/B,CAGK,SAAAS,CAAUC,GACR,OAAAV,KAAKC,iBAAiBU,GAAGD,EAAK,CAG/B,QAAAF,GACDR,KAAAC,iBAAiBW,KAAK,WAAU,CAGhC,6BAAAC,GACC,MAAAC,EAAO,IAAIC,OACXC,EAAWhB,KAAKiB,UAAUC,KAAKF,SACrC,OAAKA,GAMLhB,KAAKM,aAAaa,MAAMC,IACtBN,EAAKO,QAAQ,CACXC,OAAQF,EACRG,KAAMP,EAASO,MAAQvB,KAAKF,OAAO0B,iBACpC,GACAV,EAAKW,MAEDX,GAZEY,EAAAA,cAAcC,OAAO,CAC1BC,KAAMC,EAAaA,aAAAC,WACnBC,QAAS,sBAUN,CAGD,UAAAzB,GACA,MAAAU,EAAWhB,KAAKiB,UAAUC,KAAKF,SAErC,OAAKA,EAMEhB,KAAKgC,OAAO1B,WAAWU,GALrBU,EAAAA,cAAcC,OAAO,CAC1BC,KAAMC,EAAaA,aAAAC,WACnBC,QAAS,sBAGyB,GAxDxCtC,EAAgBG,GAAK,SADhB,IAAMqC,EAANxC,ECFA,MAAMyC,EAAmB,SAEnBC,EAA+C,CAC1DvC,GAAIsC,EACJX,KAAM,gBACNa,QAAS,QACTC,SAAU,CAAC,UACXC,SAAU,GACVC,SAAU,GACVC,cAAe,CACbC,SAAS,EACTjB,gBAAiB,iBCRRkB,EAAuE,CAClFP,WACAQ,OAAQ,CAAC9C,EAAUC,IAAW,IAAImC,EAAaC,EAAkBrC,EAAUC,GAC3E8C,QAAS,OACTC,aAAc,CAAA"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/lib/export-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePlugin, createEmitter, Listener, PluginRegistry } from '@embedpdf/core';\nimport { PdfErrorCode, PdfErrorReason, PdfTaskHelper, Task } from '@embedpdf/models';\n\nimport {\n BufferAndName,\n ExportCapability,\n ExportPluginConfig,\n ExportScope,\n DownloadRequestEvent,\n} from './types';\n\nexport class ExportPlugin extends BasePlugin<ExportPluginConfig, ExportCapability> {\n static readonly id = 'export' as const;\n\n private readonly downloadRequest$ = createEmitter<DownloadRequestEvent>();\n private readonly config: ExportPluginConfig;\n\n constructor(id: string, registry: PluginRegistry, config: ExportPluginConfig) {\n super(id, registry);\n this.config = config;\n }\n\n // ─────────────────────────────────────────────────────────\n // Capability\n // ─────────────────────────────────────────────────────────\n\n protected buildCapability(): ExportCapability {\n return {\n // Active document operations\n saveAsCopy: () => this.saveAsCopy(),\n download: () => this.download(),\n\n // Document-scoped operations\n forDocument: (documentId: string) => this.createExportScope(documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Scoping\n // ─────────────────────────────────────────────────────────\n\n private createExportScope(documentId: string): ExportScope {\n return {\n saveAsCopy: () => this.saveAsCopy(documentId),\n download: () => this.download(documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Core Operations\n // ─────────────────────────────────────────────────────────\n\n private download(documentId?: string): void {\n const id = documentId ?? this.getActiveDocumentId();\n this.downloadRequest$.emit({ documentId: id });\n }\n\n private saveAsCopy(documentId?: string): Task<ArrayBuffer, PdfErrorReason> {\n const id = documentId ?? this.getActiveDocumentId();\n const coreDoc = this.coreState.core.documents[id];\n\n if (!coreDoc?.document) {\n return PdfTaskHelper.reject({\n code: PdfErrorCode.DocNotOpen,\n message: `Document ${id} not found`,\n });\n }\n\n return this.engine.saveAsCopy(coreDoc.document);\n }\n\n public saveAsCopyAndGetBufferAndName(documentId: string): Task<BufferAndName, PdfErrorReason> {\n const task = new Task<BufferAndName, 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 this.saveAsCopy(documentId).wait(\n (result) => {\n task.resolve({\n buffer: result,\n name: coreDoc.name ?? this.config.defaultFileName,\n });\n },\n (error) => task.fail(error),\n );\n\n return task;\n }\n\n // ─────────────────────────────────────────────────────────\n // Event Listeners\n // ─────────────────────────────────────────────────────────\n\n public onRequest(listener: Listener<DownloadRequestEvent>) {\n return this.downloadRequest$.on(listener);\n }\n\n // ─────────────────────────────────────────────────────────\n // Lifecycle\n // ─────────────────────────────────────────────────────────\n\n async initialize(_: ExportPluginConfig): Promise<void> {\n this.logger.info('ExportPlugin', 'Initialize', 'Export plugin initialized');\n }\n\n async destroy(): Promise<void> {\n this.downloadRequest$.clear();\n await super.destroy();\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { ExportPluginConfig } from './types';\n\nexport const EXPORT_PLUGIN_ID = 'export';\n\nexport const manifest: PluginManifest<ExportPluginConfig> = {\n id: EXPORT_PLUGIN_ID,\n name: 'Export Plugin',\n version: '1.0.0',\n provides: ['export'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n defaultFileName: 'document.pdf',\n },\n};\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { ExportPlugin } from './export-plugin';\nimport { manifest, EXPORT_PLUGIN_ID } from './manifest';\nimport { ExportPluginConfig } from './types';\n\nexport const ExportPluginPackage: PluginPackage<ExportPlugin, ExportPluginConfig> = {\n manifest,\n create: (registry, config) => new ExportPlugin(EXPORT_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './export-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["_ExportPlugin","BasePlugin","constructor","id","registry","config","super","this","downloadRequest$","createEmitter","buildCapability","saveAsCopy","download","forDocument","documentId","createExportScope","getActiveDocumentId","emit","coreDoc","coreState","core","documents","document","engine","PdfTaskHelper","reject","code","PdfErrorCode","DocNotOpen","message","saveAsCopyAndGetBufferAndName","task","Task","wait","result","resolve","buffer","name","defaultFileName","error","fail","onRequest","listener","on","initialize","_","logger","info","destroy","clear","ExportPlugin","EXPORT_PLUGIN_ID","manifest","version","provides","requires","optional","defaultConfig","enabled","ExportPluginPackage","create","reducer","initialState"],"mappings":"gJAWaA,EAAN,cAA2BC,EAAAA,WAMhC,WAAAC,CAAYC,EAAYC,EAA0BC,GAChDC,MAAMH,EAAIC,GAJZG,KAAiBC,iBAAmBC,kBAKlCF,KAAKF,OAASA,CAChB,CAMU,eAAAK,GACR,MAAO,CAELC,WAAY,IAAMJ,KAAKI,aACvBC,SAAU,IAAML,KAAKK,WAGrBC,YAAcC,GAAuBP,KAAKQ,kBAAkBD,GAEhE,CAMQ,iBAAAC,CAAkBD,GACxB,MAAO,CACLH,WAAY,IAAMJ,KAAKI,WAAWG,GAClCF,SAAU,IAAML,KAAKK,SAASE,GAElC,CAMQ,QAAAF,CAASE,GACf,MAAMX,EAAKW,GAAcP,KAAKS,sBAC9BT,KAAKC,iBAAiBS,KAAK,CAAEH,WAAYX,GAC3C,CAEQ,UAAAQ,CAAWG,GACjB,MAAMX,EAAKW,GAAcP,KAAKS,sBACxBE,EAAUX,KAAKY,UAAUC,KAAKC,UAAUlB,GAE9C,aAAKe,WAASI,UAOPf,KAAKgB,OAAOZ,WAAWO,EAAQI,UAN7BE,EAAAA,cAAcC,OAAO,CAC1BC,KAAMC,EAAAA,aAAaC,WACnBC,QAAS,YAAY1B,eAK3B,CAEO,6BAAA2B,CAA8BhB,GACnC,MAAMiB,EAAO,IAAIC,OACXd,EAAUX,KAAKY,UAAUC,KAAKC,UAAUP,GAE9C,aAAKI,WAASI,WAOdf,KAAKI,WAAWG,GAAYmB,KACzBC,IACCH,EAAKI,QAAQ,CACXC,OAAQF,EACRG,KAAMnB,EAAQmB,MAAQ9B,KAAKF,OAAOiC,mBAGrCC,GAAUR,EAAKS,KAAKD,IAGhBR,GAhBEP,EAAAA,cAAcC,OAAO,CAC1BC,KAAMC,EAAAA,aAAaC,WACnBC,QAAS,YAAYf,eAe3B,CAMO,SAAA2B,CAAUC,GACf,OAAOnC,KAAKC,iBAAiBmC,GAAGD,EAClC,CAMA,gBAAME,CAAWC,GACftC,KAAKuC,OAAOC,KAAK,eAAgB,aAAc,4BACjD,CAEA,aAAMC,GACJzC,KAAKC,iBAAiByC,cAChB3C,MAAM0C,SACd,GAtGAhD,EAAgBG,GAAK,SADhB,IAAM+C,EAANlD,ECRA,MAAMmD,EAAmB,SAEnBC,EAA+C,CAC1DjD,GAAIgD,EACJd,KAAM,gBACNgB,QAAS,QACTC,SAAU,CAAC,UACXC,SAAU,GACVC,SAAU,GACVC,cAAe,CACbC,SAAS,EACTpB,gBAAiB,iBCRRqB,EAAuE,CAClFP,WACAQ,OAAQ,CAACxD,EAAUC,IAAW,IAAI6C,EAAaC,EAAkB/C,EAAUC,GAC3EwD,QAAS,OACTC,aAAc,CAAA"}
package/dist/index.js CHANGED
@@ -1,49 +1,85 @@
1
1
  import { BasePlugin, createEmitter } from "@embedpdf/core";
2
- import { Task, PdfTaskHelper, PdfErrorCode } from "@embedpdf/models";
2
+ import { PdfTaskHelper, PdfErrorCode, Task } from "@embedpdf/models";
3
3
  const _ExportPlugin = class _ExportPlugin extends BasePlugin {
4
4
  constructor(id, registry, config) {
5
5
  super(id, registry);
6
6
  this.downloadRequest$ = createEmitter();
7
7
  this.config = config;
8
8
  }
9
- async initialize(_) {
10
- }
9
+ // ─────────────────────────────────────────────────────────
10
+ // Capability
11
+ // ─────────────────────────────────────────────────────────
11
12
  buildCapability() {
12
13
  return {
13
- saveAsCopy: this.saveAsCopy.bind(this),
14
- download: this.download.bind(this)
14
+ // Active document operations
15
+ saveAsCopy: () => this.saveAsCopy(),
16
+ download: () => this.download(),
17
+ // Document-scoped operations
18
+ forDocument: (documentId) => this.createExportScope(documentId)
15
19
  };
16
20
  }
17
- onRequest(event) {
18
- return this.downloadRequest$.on(event);
21
+ // ─────────────────────────────────────────────────────────
22
+ // Document Scoping
23
+ // ─────────────────────────────────────────────────────────
24
+ createExportScope(documentId) {
25
+ return {
26
+ saveAsCopy: () => this.saveAsCopy(documentId),
27
+ download: () => this.download(documentId)
28
+ };
19
29
  }
20
- download() {
21
- this.downloadRequest$.emit("download");
30
+ // ─────────────────────────────────────────────────────────
31
+ // Core Operations
32
+ // ─────────────────────────────────────────────────────────
33
+ download(documentId) {
34
+ const id = documentId ?? this.getActiveDocumentId();
35
+ this.downloadRequest$.emit({ documentId: id });
22
36
  }
23
- saveAsCopyAndGetBufferAndName() {
24
- const task = new Task();
25
- const document = this.coreState.core.document;
26
- if (!document)
37
+ saveAsCopy(documentId) {
38
+ const id = documentId ?? this.getActiveDocumentId();
39
+ const coreDoc = this.coreState.core.documents[id];
40
+ if (!(coreDoc == null ? void 0 : coreDoc.document)) {
27
41
  return PdfTaskHelper.reject({
28
42
  code: PdfErrorCode.DocNotOpen,
29
- message: "Document not found"
30
- });
31
- this.saveAsCopy().wait((result) => {
32
- task.resolve({
33
- buffer: result,
34
- name: document.name ?? this.config.defaultFileName
43
+ message: `Document ${id} not found`
35
44
  });
36
- }, task.fail);
37
- return task;
45
+ }
46
+ return this.engine.saveAsCopy(coreDoc.document);
38
47
  }
39
- saveAsCopy() {
40
- const document = this.coreState.core.document;
41
- if (!document)
48
+ saveAsCopyAndGetBufferAndName(documentId) {
49
+ const task = new Task();
50
+ const coreDoc = this.coreState.core.documents[documentId];
51
+ if (!(coreDoc == null ? void 0 : coreDoc.document)) {
42
52
  return PdfTaskHelper.reject({
43
53
  code: PdfErrorCode.DocNotOpen,
44
- message: "Document not found"
54
+ message: `Document ${documentId} not found`
45
55
  });
46
- return this.engine.saveAsCopy(document);
56
+ }
57
+ this.saveAsCopy(documentId).wait(
58
+ (result) => {
59
+ task.resolve({
60
+ buffer: result,
61
+ name: coreDoc.name ?? this.config.defaultFileName
62
+ });
63
+ },
64
+ (error) => task.fail(error)
65
+ );
66
+ return task;
67
+ }
68
+ // ─────────────────────────────────────────────────────────
69
+ // Event Listeners
70
+ // ─────────────────────────────────────────────────────────
71
+ onRequest(listener) {
72
+ return this.downloadRequest$.on(listener);
73
+ }
74
+ // ─────────────────────────────────────────────────────────
75
+ // Lifecycle
76
+ // ─────────────────────────────────────────────────────────
77
+ async initialize(_) {
78
+ this.logger.info("ExportPlugin", "Initialize", "Export plugin initialized");
79
+ }
80
+ async destroy() {
81
+ this.downloadRequest$.clear();
82
+ await super.destroy();
47
83
  }
48
84
  };
49
85
  _ExportPlugin.id = "export";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/lib/export-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePlugin, createEmitter, Listener, PluginRegistry, Unsubscribe } from '@embedpdf/core';\nimport { PdfErrorCode, PdfErrorReason, PdfTaskHelper, Task } from '@embedpdf/models';\n\nimport { BufferAndName, ExportCapability, ExportPluginConfig } from './types';\n\nexport class ExportPlugin extends BasePlugin<ExportPluginConfig, ExportCapability> {\n static readonly id = 'export' as const;\n\n private readonly downloadRequest$ = createEmitter<'download'>();\n private readonly config: ExportPluginConfig;\n\n constructor(id: string, registry: PluginRegistry, config: ExportPluginConfig) {\n super(id, registry);\n\n this.config = config;\n }\n\n async initialize(_: ExportPluginConfig): Promise<void> {}\n\n protected buildCapability(): ExportCapability {\n return {\n saveAsCopy: this.saveAsCopy.bind(this),\n download: this.download.bind(this),\n };\n }\n\n public onRequest(event: Listener<'download'>): Unsubscribe {\n return this.downloadRequest$.on(event);\n }\n\n private download(): void {\n this.downloadRequest$.emit('download');\n }\n\n public saveAsCopyAndGetBufferAndName(): Task<BufferAndName, PdfErrorReason> {\n const task = new Task<BufferAndName, PdfErrorReason>();\n const document = this.coreState.core.document;\n if (!document)\n return PdfTaskHelper.reject({\n code: PdfErrorCode.DocNotOpen,\n message: 'Document not found',\n });\n\n this.saveAsCopy().wait((result) => {\n task.resolve({\n buffer: result,\n name: document.name ?? this.config.defaultFileName,\n });\n }, task.fail);\n\n return task;\n }\n\n private saveAsCopy(): 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 return this.engine.saveAsCopy(document);\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { ExportPluginConfig } from './types';\n\nexport const EXPORT_PLUGIN_ID = 'export';\n\nexport const manifest: PluginManifest<ExportPluginConfig> = {\n id: EXPORT_PLUGIN_ID,\n name: 'Export Plugin',\n version: '1.0.0',\n provides: ['export'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n defaultFileName: 'document.pdf',\n },\n};\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { ExportPlugin } from './export-plugin';\nimport { manifest, EXPORT_PLUGIN_ID } from './manifest';\nimport { ExportPluginConfig } from './types';\n\nexport const ExportPluginPackage: PluginPackage<ExportPlugin, ExportPluginConfig> = {\n manifest,\n create: (registry, config) => new ExportPlugin(EXPORT_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './export-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":[],"mappings":";;AAKO,MAAM,gBAAN,MAAM,sBAAqB,WAAiD;AAAA,EAMjF,YAAY,IAAY,UAA0B,QAA4B;AAC5E,UAAM,IAAI,QAAQ;AAJpB,SAAiB,mBAAmB,cAA0B;AAM5D,SAAK,SAAS;AAAA,EAAA;AAAA,EAGhB,MAAM,WAAW,GAAsC;AAAA,EAAA;AAAA,EAE7C,kBAAoC;AACrC,WAAA;AAAA,MACL,YAAY,KAAK,WAAW,KAAK,IAAI;AAAA,MACrC,UAAU,KAAK,SAAS,KAAK,IAAI;AAAA,IACnC;AAAA,EAAA;AAAA,EAGK,UAAU,OAA0C;AAClD,WAAA,KAAK,iBAAiB,GAAG,KAAK;AAAA,EAAA;AAAA,EAG/B,WAAiB;AAClB,SAAA,iBAAiB,KAAK,UAAU;AAAA,EAAA;AAAA,EAGhC,gCAAqE;AACpE,UAAA,OAAO,IAAI,KAAoC;AAC/C,UAAA,WAAW,KAAK,UAAU,KAAK;AACrC,QAAI,CAAC;AACH,aAAO,cAAc,OAAO;AAAA,QAC1B,MAAM,aAAa;AAAA,QACnB,SAAS;AAAA,MAAA,CACV;AAEH,SAAK,WAAW,EAAE,KAAK,CAAC,WAAW;AACjC,WAAK,QAAQ;AAAA,QACX,QAAQ;AAAA,QACR,MAAM,SAAS,QAAQ,KAAK,OAAO;AAAA,MAAA,CACpC;AAAA,IAAA,GACA,KAAK,IAAI;AAEL,WAAA;AAAA,EAAA;AAAA,EAGD,aAAgD;AAChD,UAAA,WAAW,KAAK,UAAU,KAAK;AAErC,QAAI,CAAC;AACH,aAAO,cAAc,OAAO;AAAA,QAC1B,MAAM,aAAa;AAAA,QACnB,SAAS;AAAA,MAAA,CACV;AAEI,WAAA,KAAK,OAAO,WAAW,QAAQ;AAAA,EAAA;AAE1C;AA1DE,cAAgB,KAAK;AADhB,IAAM,eAAN;ACFA,MAAM,mBAAmB;AAEzB,MAAM,WAA+C;AAAA,EAC1D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,QAAQ;AAAA,EACnB,UAAU,CAAC;AAAA,EACX,UAAU,CAAC;AAAA,EACX,eAAe;AAAA,IACb,SAAS;AAAA,IACT,iBAAiB;AAAA,EAAA;AAErB;ACVO,MAAM,sBAAuE;AAAA,EAClF;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EACjF,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAA;AAChB;"}
1
+ {"version":3,"file":"index.js","sources":["../src/lib/export-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePlugin, createEmitter, Listener, PluginRegistry } from '@embedpdf/core';\nimport { PdfErrorCode, PdfErrorReason, PdfTaskHelper, Task } from '@embedpdf/models';\n\nimport {\n BufferAndName,\n ExportCapability,\n ExportPluginConfig,\n ExportScope,\n DownloadRequestEvent,\n} from './types';\n\nexport class ExportPlugin extends BasePlugin<ExportPluginConfig, ExportCapability> {\n static readonly id = 'export' as const;\n\n private readonly downloadRequest$ = createEmitter<DownloadRequestEvent>();\n private readonly config: ExportPluginConfig;\n\n constructor(id: string, registry: PluginRegistry, config: ExportPluginConfig) {\n super(id, registry);\n this.config = config;\n }\n\n // ─────────────────────────────────────────────────────────\n // Capability\n // ─────────────────────────────────────────────────────────\n\n protected buildCapability(): ExportCapability {\n return {\n // Active document operations\n saveAsCopy: () => this.saveAsCopy(),\n download: () => this.download(),\n\n // Document-scoped operations\n forDocument: (documentId: string) => this.createExportScope(documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Scoping\n // ─────────────────────────────────────────────────────────\n\n private createExportScope(documentId: string): ExportScope {\n return {\n saveAsCopy: () => this.saveAsCopy(documentId),\n download: () => this.download(documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Core Operations\n // ─────────────────────────────────────────────────────────\n\n private download(documentId?: string): void {\n const id = documentId ?? this.getActiveDocumentId();\n this.downloadRequest$.emit({ documentId: id });\n }\n\n private saveAsCopy(documentId?: string): Task<ArrayBuffer, PdfErrorReason> {\n const id = documentId ?? this.getActiveDocumentId();\n const coreDoc = this.coreState.core.documents[id];\n\n if (!coreDoc?.document) {\n return PdfTaskHelper.reject({\n code: PdfErrorCode.DocNotOpen,\n message: `Document ${id} not found`,\n });\n }\n\n return this.engine.saveAsCopy(coreDoc.document);\n }\n\n public saveAsCopyAndGetBufferAndName(documentId: string): Task<BufferAndName, PdfErrorReason> {\n const task = new Task<BufferAndName, 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 this.saveAsCopy(documentId).wait(\n (result) => {\n task.resolve({\n buffer: result,\n name: coreDoc.name ?? this.config.defaultFileName,\n });\n },\n (error) => task.fail(error),\n );\n\n return task;\n }\n\n // ─────────────────────────────────────────────────────────\n // Event Listeners\n // ─────────────────────────────────────────────────────────\n\n public onRequest(listener: Listener<DownloadRequestEvent>) {\n return this.downloadRequest$.on(listener);\n }\n\n // ─────────────────────────────────────────────────────────\n // Lifecycle\n // ─────────────────────────────────────────────────────────\n\n async initialize(_: ExportPluginConfig): Promise<void> {\n this.logger.info('ExportPlugin', 'Initialize', 'Export plugin initialized');\n }\n\n async destroy(): Promise<void> {\n this.downloadRequest$.clear();\n await super.destroy();\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { ExportPluginConfig } from './types';\n\nexport const EXPORT_PLUGIN_ID = 'export';\n\nexport const manifest: PluginManifest<ExportPluginConfig> = {\n id: EXPORT_PLUGIN_ID,\n name: 'Export Plugin',\n version: '1.0.0',\n provides: ['export'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n defaultFileName: 'document.pdf',\n },\n};\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { ExportPlugin } from './export-plugin';\nimport { manifest, EXPORT_PLUGIN_ID } from './manifest';\nimport { ExportPluginConfig } from './types';\n\nexport const ExportPluginPackage: PluginPackage<ExportPlugin, ExportPluginConfig> = {\n manifest,\n create: (registry, config) => new ExportPlugin(EXPORT_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './export-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":[],"mappings":";;AAWO,MAAM,gBAAN,MAAM,sBAAqB,WAAiD;AAAA,EAMjF,YAAY,IAAY,UAA0B,QAA4B;AAC5E,UAAM,IAAI,QAAQ;AAJpB,SAAiB,mBAAmB,cAAA;AAKlC,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAMU,kBAAoC;AAC5C,WAAO;AAAA;AAAA,MAEL,YAAY,MAAM,KAAK,WAAA;AAAA,MACvB,UAAU,MAAM,KAAK,SAAA;AAAA;AAAA,MAGrB,aAAa,CAAC,eAAuB,KAAK,kBAAkB,UAAU;AAAA,IAAA;AAAA,EAE1E;AAAA;AAAA;AAAA;AAAA,EAMQ,kBAAkB,YAAiC;AACzD,WAAO;AAAA,MACL,YAAY,MAAM,KAAK,WAAW,UAAU;AAAA,MAC5C,UAAU,MAAM,KAAK,SAAS,UAAU;AAAA,IAAA;AAAA,EAE5C;AAAA;AAAA;AAAA;AAAA,EAMQ,SAAS,YAA2B;AAC1C,UAAM,KAAK,cAAc,KAAK,oBAAA;AAC9B,SAAK,iBAAiB,KAAK,EAAE,YAAY,IAAI;AAAA,EAC/C;AAAA,EAEQ,WAAW,YAAwD;AACzE,UAAM,KAAK,cAAc,KAAK,oBAAA;AAC9B,UAAM,UAAU,KAAK,UAAU,KAAK,UAAU,EAAE;AAEhD,QAAI,EAAC,mCAAS,WAAU;AACtB,aAAO,cAAc,OAAO;AAAA,QAC1B,MAAM,aAAa;AAAA,QACnB,SAAS,YAAY,EAAE;AAAA,MAAA,CACxB;AAAA,IACH;AAEA,WAAO,KAAK,OAAO,WAAW,QAAQ,QAAQ;AAAA,EAChD;AAAA,EAEO,8BAA8B,YAAyD;AAC5F,UAAM,OAAO,IAAI,KAAA;AACjB,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,SAAK,WAAW,UAAU,EAAE;AAAA,MAC1B,CAAC,WAAW;AACV,aAAK,QAAQ;AAAA,UACX,QAAQ;AAAA,UACR,MAAM,QAAQ,QAAQ,KAAK,OAAO;AAAA,QAAA,CACnC;AAAA,MACH;AAAA,MACA,CAAC,UAAU,KAAK,KAAK,KAAK;AAAA,IAAA;AAG5B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAMO,UAAU,UAA0C;AACzD,WAAO,KAAK,iBAAiB,GAAG,QAAQ;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAW,GAAsC;AACrD,SAAK,OAAO,KAAK,gBAAgB,cAAc,2BAA2B;AAAA,EAC5E;AAAA,EAEA,MAAM,UAAyB;AAC7B,SAAK,iBAAiB,MAAA;AACtB,UAAM,MAAM,QAAA;AAAA,EACd;AACF;AAvGE,cAAgB,KAAK;AADhB,IAAM,eAAN;ACRA,MAAM,mBAAmB;AAEzB,MAAM,WAA+C;AAAA,EAC1D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,QAAQ;AAAA,EACnB,UAAU,CAAA;AAAA,EACV,UAAU,CAAA;AAAA,EACV,eAAe;AAAA,IACb,SAAS;AAAA,IACT,iBAAiB;AAAA,EAAA;AAErB;ACVO,MAAM,sBAAuE;AAAA,EAClF;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EACjF,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAA;AAChB;"}
@@ -1,15 +1,17 @@
1
- import { BasePlugin, Listener, PluginRegistry, Unsubscribe } from '@embedpdf/core';
1
+ import { BasePlugin, Listener, PluginRegistry } from '@embedpdf/core';
2
2
  import { PdfErrorReason, Task } from '@embedpdf/models';
3
- import { BufferAndName, ExportCapability, ExportPluginConfig } from './types';
3
+ import { BufferAndName, ExportCapability, ExportPluginConfig, DownloadRequestEvent } from './types';
4
4
  export declare class ExportPlugin extends BasePlugin<ExportPluginConfig, ExportCapability> {
5
5
  static readonly id: "export";
6
6
  private readonly downloadRequest$;
7
7
  private readonly config;
8
8
  constructor(id: string, registry: PluginRegistry, config: ExportPluginConfig);
9
- initialize(_: ExportPluginConfig): Promise<void>;
10
9
  protected buildCapability(): ExportCapability;
11
- onRequest(event: Listener<'download'>): Unsubscribe;
10
+ private createExportScope;
12
11
  private download;
13
- saveAsCopyAndGetBufferAndName(): Task<BufferAndName, PdfErrorReason>;
14
12
  private saveAsCopy;
13
+ saveAsCopyAndGetBufferAndName(documentId: string): Task<BufferAndName, PdfErrorReason>;
14
+ onRequest(listener: Listener<DownloadRequestEvent>): import('@embedpdf/core').Unsubscribe;
15
+ initialize(_: ExportPluginConfig): Promise<void>;
16
+ destroy(): Promise<void>;
15
17
  }
@@ -7,7 +7,17 @@ export interface BufferAndName {
7
7
  buffer: ArrayBuffer;
8
8
  name: string;
9
9
  }
10
+ export interface DownloadRequestEvent {
11
+ documentId: string;
12
+ }
13
+ export interface ExportScope {
14
+ saveAsCopy: () => Task<ArrayBuffer, PdfErrorReason>;
15
+ download: () => void;
16
+ }
10
17
  export interface ExportCapability {
11
18
  saveAsCopy: () => Task<ArrayBuffer, PdfErrorReason>;
12
19
  download: () => void;
20
+ forDocument(documentId: string): ExportScope;
21
+ }
22
+ export interface ExportState {
13
23
  }
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),r=require("@embedpdf/plugin-export"),t=require("preact/jsx-runtime"),o=require("@embedpdf/models"),i=require("preact/hooks"),n=require("@embedpdf/core/preact"),u=()=>n.usePlugin(r.ExportPlugin.id),a=()=>n.useCapability(r.ExportPlugin.id);function p(e){const{provides:r}=a(),{plugin:n}=u(),p=i.useRef(null);return i.useEffect((()=>{if(!r)return;if(!n)return;return n.onRequest((r=>{if("download"===r){const r=p.current;if(!r)return;n.saveAsCopyAndGetBufferAndName().wait((({buffer:t,name:o})=>{const i=URL.createObjectURL(new Blob([t]));r.href=i,r.download=e.fileName??o,r.click(),URL.revokeObjectURL(i)}),o.ignore)}}))}),[r,n]),t.jsx("a",{style:{display:"none"},ref:p})}const s=e.createPluginPackage(r.ExportPluginPackage).addUtility(p).build();exports.Download=p,exports.ExportPluginPackage=s,exports.useExportCapability=a,exports.useExportPlugin=u,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-export"),t=require("preact/jsx-runtime"),o=require("@embedpdf/models"),n=require("preact/hooks"),u=require("@embedpdf/core/preact"),i=()=>u.usePlugin(r.ExportPlugin.id),p=()=>u.useCapability(r.ExportPlugin.id);function s(){const{plugin:e}=i(),r=n.useRef(null);return n.useEffect(()=>{if(!e)return;return e.onRequest(t=>{const n=r.current;if(!n)return;e.saveAsCopyAndGetBufferAndName(t.documentId).wait(({buffer:e,name:r})=>{const t=URL.createObjectURL(new Blob([e]));n.href=t,n.download=r,n.click(),URL.revokeObjectURL(t)},o.ignore)})},[e]),t.jsx("a",{style:{display:"none"},ref:r})}const l=e.createPluginPackage(r.ExportPluginPackage).addUtility(s).build();exports.Download=s,exports.ExportPluginPackage=l,exports.useExport=e=>{const{provides:r}=p();return{provides:(null==r?void 0:r.forDocument(e))??null}},exports.useExportCapability=p,exports.useExportPlugin=i,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-export.ts","../../src/shared/component/download.tsx","../../src/shared/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n","import { ignore } from '@embedpdf/models';\nimport { useEffect, useRef } from '@framework';\n\nimport { useExportCapability, useExportPlugin } from '../hooks';\n\nexport interface DownloadProps {\n fileName?: string;\n}\n\nexport function Download(props: DownloadProps) {\n const { provides: exportCapability } = useExportCapability();\n const { plugin: exportPlugin } = useExportPlugin();\n const ref = useRef<HTMLAnchorElement>(null);\n\n useEffect(() => {\n if (!exportCapability) return;\n if (!exportPlugin) return;\n\n const unsub = exportPlugin.onRequest((action) => {\n if (action === 'download') {\n const el = ref.current;\n if (!el) return;\n\n const task = exportPlugin.saveAsCopyAndGetBufferAndName();\n task.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = props.fileName ?? name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n }\n });\n\n return unsub;\n }, [exportCapability, exportPlugin]);\n\n return <a style={{ display: 'none' }} ref={ref} />;\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './component';\n\nexport * from './hooks';\nexport * from './component';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["useExportPlugin","usePlugin","ExportPlugin","id","useExportCapability","useCapability","Download","props","provides","exportCapability","plugin","exportPlugin","ref","useRef","useEffect","onRequest","action","el","current","saveAsCopyAndGetBufferAndName","wait","buffer","name","url","URL","createObjectURL","Blob","href","download","fileName","click","revokeObjectURL","ignore","style","display","ExportPluginPackage","createPluginPackage","BaseExportPackage","addUtility","build"],"mappings":"kRAGaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,ICK3E,SAASG,EAASC,GACvB,MAAQC,SAAUC,GAAqBL,KAC/BM,OAAQC,GAAiBX,IAC3BY,EAAMC,SAA0B,aAEtCC,EAAAA,WAAU,KACR,IAAKL,EAAkB,OACvB,IAAKE,EAAc,OAkBZ,OAhBOA,EAAaI,WAAWC,IACpC,GAAe,aAAXA,EAAuB,CACzB,MAAMC,EAAKL,EAAIM,QACf,IAAKD,EAAI,OAEIN,EAAaQ,gCACrBC,MAAK,EAAGC,SAAQC,WACb,MAAAC,EAAMC,IAAIC,gBAAgB,IAAIC,KAAK,CAACL,KAC1CJ,EAAGU,KAAOJ,EACPN,EAAAW,SAAWrB,EAAMsB,UAAYP,EAChCL,EAAGa,QACHN,IAAIO,gBAAgBR,EAAG,GACtBS,SAAM,IAIN,GACN,CAACvB,EAAkBE,UAEd,IAAE,CAAAsB,MAAO,CAAEC,QAAS,QAAUtB,OACxC,CC5BO,MAAMuB,EAAsBC,EAAoBA,oBAAAC,EAAiBF,qBACrEG,WAAWhC,GACXiC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-export.ts","../../src/shared/component/download.tsx","../../src/shared/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n\n/**\n * Hook for export capability for a specific document\n * @param documentId Document ID\n */\nexport const useExport = (documentId: string) => {\n const { provides } = useExportCapability();\n\n return {\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n","import { ignore } from '@embedpdf/models';\nimport { useEffect, useRef } from '@framework';\n\nimport { useExportPlugin } from '../hooks';\n\nexport function Download() {\n const { plugin: exportPlugin } = useExportPlugin();\n const ref = useRef<HTMLAnchorElement>(null);\n\n useEffect(() => {\n if (!exportPlugin) return;\n\n const unsub = exportPlugin.onRequest((event) => {\n const el = ref.current;\n if (!el) return;\n\n const task = exportPlugin.saveAsCopyAndGetBufferAndName(event.documentId);\n task.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n });\n\n return unsub;\n }, [exportPlugin]);\n\n return <a style={{ display: 'none' }} ref={ref} />;\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './component';\n\nexport * from './hooks';\nexport * from './component';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["useExportPlugin","usePlugin","ExportPlugin","id","useExportCapability","useCapability","Download","plugin","exportPlugin","ref","useRef","useEffect","onRequest","event","el","current","saveAsCopyAndGetBufferAndName","documentId","wait","buffer","name","url","URL","createObjectURL","Blob","href","download","click","revokeObjectURL","ignore","style","display","ExportPluginPackage","createPluginPackage","BaseExportPackage","addUtility","build","provides","forDocument"],"mappings":"kRAGaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,ICC3E,SAASG,IACd,MAAQC,OAAQC,GAAiBR,IAC3BS,EAAMC,EAAAA,OAA0B,MAsBtC,OApBAC,EAAAA,UAAU,KACR,IAAKH,EAAc,OAgBnB,OAdcA,EAAaI,UAAWC,IACpC,MAAMC,EAAKL,EAAIM,QACf,IAAKD,EAAI,OAEIN,EAAaQ,8BAA8BH,EAAMI,YACzDC,KAAK,EAAGC,SAAQC,WACnB,MAAMC,EAAMC,IAAIC,gBAAgB,IAAIC,KAAK,CAACL,KAC1CL,EAAGW,KAAOJ,EACVP,EAAGY,SAAWN,EACdN,EAAGa,QACHL,IAAIM,gBAAgBP,IACnBQ,EAAAA,WAIJ,CAACrB,UAEI,IAAA,CAAEsB,MAAO,CAAEC,QAAS,QAAUtB,OACxC,CCpBO,MAAMuB,EAAsBC,EAAAA,oBAAoBC,EAAAA,qBACpDC,WAAW7B,GACX8B,2EFFuBnB,IACxB,MAAMoB,SAAEA,GAAajC,IAErB,MAAO,CACLiC,UAAU,MAAAA,OAAA,EAAAA,EAAUC,YAAYrB,KAAe"}
@@ -4,38 +4,41 @@ export * from "@embedpdf/plugin-export";
4
4
  import { jsx } from "preact/jsx-runtime";
5
5
  import { ignore } from "@embedpdf/models";
6
6
  import { useRef, useEffect } from "preact/hooks";
7
- import { useCapability, usePlugin } from "@embedpdf/core/preact";
7
+ import { usePlugin, useCapability } from "@embedpdf/core/preact";
8
8
  const useExportPlugin = () => usePlugin(ExportPlugin.id);
9
9
  const useExportCapability = () => useCapability(ExportPlugin.id);
10
- function Download(props) {
11
- const { provides: exportCapability } = useExportCapability();
10
+ const useExport = (documentId) => {
11
+ const { provides } = useExportCapability();
12
+ return {
13
+ provides: (provides == null ? void 0 : provides.forDocument(documentId)) ?? null
14
+ };
15
+ };
16
+ function Download() {
12
17
  const { plugin: exportPlugin } = useExportPlugin();
13
18
  const ref = useRef(null);
14
19
  useEffect(() => {
15
- if (!exportCapability) return;
16
20
  if (!exportPlugin) return;
17
- const unsub = exportPlugin.onRequest((action) => {
18
- if (action === "download") {
19
- const el = ref.current;
20
- if (!el) return;
21
- const task = exportPlugin.saveAsCopyAndGetBufferAndName();
22
- task.wait(({ buffer, name }) => {
23
- const url = URL.createObjectURL(new Blob([buffer]));
24
- el.href = url;
25
- el.download = props.fileName ?? name;
26
- el.click();
27
- URL.revokeObjectURL(url);
28
- }, ignore);
29
- }
21
+ const unsub = exportPlugin.onRequest((event) => {
22
+ const el = ref.current;
23
+ if (!el) return;
24
+ const task = exportPlugin.saveAsCopyAndGetBufferAndName(event.documentId);
25
+ task.wait(({ buffer, name }) => {
26
+ const url = URL.createObjectURL(new Blob([buffer]));
27
+ el.href = url;
28
+ el.download = name;
29
+ el.click();
30
+ URL.revokeObjectURL(url);
31
+ }, ignore);
30
32
  });
31
33
  return unsub;
32
- }, [exportCapability, exportPlugin]);
34
+ }, [exportPlugin]);
33
35
  return /* @__PURE__ */ jsx("a", { style: { display: "none" }, ref });
34
36
  }
35
37
  const ExportPluginPackage = createPluginPackage(ExportPluginPackage$1).addUtility(Download).build();
36
38
  export {
37
39
  Download,
38
40
  ExportPluginPackage,
41
+ useExport,
39
42
  useExportCapability,
40
43
  useExportPlugin
41
44
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-export.ts","../../src/shared/component/download.tsx","../../src/shared/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n","import { ignore } from '@embedpdf/models';\nimport { useEffect, useRef } from '@framework';\n\nimport { useExportCapability, useExportPlugin } from '../hooks';\n\nexport interface DownloadProps {\n fileName?: string;\n}\n\nexport function Download(props: DownloadProps) {\n const { provides: exportCapability } = useExportCapability();\n const { plugin: exportPlugin } = useExportPlugin();\n const ref = useRef<HTMLAnchorElement>(null);\n\n useEffect(() => {\n if (!exportCapability) return;\n if (!exportPlugin) return;\n\n const unsub = exportPlugin.onRequest((action) => {\n if (action === 'download') {\n const el = ref.current;\n if (!el) return;\n\n const task = exportPlugin.saveAsCopyAndGetBufferAndName();\n task.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = props.fileName ?? name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n }\n });\n\n return unsub;\n }, [exportCapability, exportPlugin]);\n\n return <a style={{ display: 'none' }} ref={ref} />;\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './component';\n\nexport * from './hooks';\nexport * from './component';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["BaseExportPackage"],"mappings":";;;;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;ACK7E,SAAS,SAAS,OAAsB;AAC7C,QAAM,EAAE,UAAU,iBAAiB,IAAI,oBAAoB;AAC3D,QAAM,EAAE,QAAQ,aAAa,IAAI,gBAAgB;AAC3C,QAAA,MAAM,OAA0B,IAAI;AAE1C,YAAU,MAAM;AACd,QAAI,CAAC,iBAAkB;AACvB,QAAI,CAAC,aAAc;AAEnB,UAAM,QAAQ,aAAa,UAAU,CAAC,WAAW;AAC/C,UAAI,WAAW,YAAY;AACzB,cAAM,KAAK,IAAI;AACf,YAAI,CAAC,GAAI;AAEH,cAAA,OAAO,aAAa,8BAA8B;AACxD,aAAK,KAAK,CAAC,EAAE,QAAQ,WAAW;AACxB,gBAAA,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAClD,aAAG,OAAO;AACP,aAAA,WAAW,MAAM,YAAY;AAChC,aAAG,MAAM;AACT,cAAI,gBAAgB,GAAG;AAAA,WACtB,MAAM;AAAA,MAAA;AAAA,IACX,CACD;AAEM,WAAA;AAAA,EAAA,GACN,CAAC,kBAAkB,YAAY,CAAC;AAEnC,6BAAQ,KAAE,EAAA,OAAO,EAAE,SAAS,OAAA,GAAU,KAAU;AAClD;AC5BO,MAAM,sBAAsB,oBAAoBA,qBAAiB,EACrE,WAAW,QAAQ,EACnB,MAAM;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-export.ts","../../src/shared/component/download.tsx","../../src/shared/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n\n/**\n * Hook for export capability for a specific document\n * @param documentId Document ID\n */\nexport const useExport = (documentId: string) => {\n const { provides } = useExportCapability();\n\n return {\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n","import { ignore } from '@embedpdf/models';\nimport { useEffect, useRef } from '@framework';\n\nimport { useExportPlugin } from '../hooks';\n\nexport function Download() {\n const { plugin: exportPlugin } = useExportPlugin();\n const ref = useRef<HTMLAnchorElement>(null);\n\n useEffect(() => {\n if (!exportPlugin) return;\n\n const unsub = exportPlugin.onRequest((event) => {\n const el = ref.current;\n if (!el) return;\n\n const task = exportPlugin.saveAsCopyAndGetBufferAndName(event.documentId);\n task.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n });\n\n return unsub;\n }, [exportPlugin]);\n\n return <a style={{ display: 'none' }} ref={ref} />;\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './component';\n\nexport * from './hooks';\nexport * from './component';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["BaseExportPackage"],"mappings":";;;;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAM7E,MAAM,YAAY,CAAC,eAAuB;AAC/C,QAAM,EAAE,SAAA,IAAa,oBAAA;AAErB,SAAO;AAAA,IACL,WAAU,qCAAU,YAAY,gBAAe;AAAA,EAAA;AAEnD;ACXO,SAAS,WAAW;AACzB,QAAM,EAAE,QAAQ,aAAA,IAAiB,gBAAA;AACjC,QAAM,MAAM,OAA0B,IAAI;AAE1C,YAAU,MAAM;AACd,QAAI,CAAC,aAAc;AAEnB,UAAM,QAAQ,aAAa,UAAU,CAAC,UAAU;AAC9C,YAAM,KAAK,IAAI;AACf,UAAI,CAAC,GAAI;AAET,YAAM,OAAO,aAAa,8BAA8B,MAAM,UAAU;AACxE,WAAK,KAAK,CAAC,EAAE,QAAQ,WAAW;AAC9B,cAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAClD,WAAG,OAAO;AACV,WAAG,WAAW;AACd,WAAG,MAAA;AACH,YAAI,gBAAgB,GAAG;AAAA,MACzB,GAAG,MAAM;AAAA,IACX,CAAC;AAED,WAAO;AAAA,EACT,GAAG,CAAC,YAAY,CAAC;AAEjB,6BAAQ,KAAA,EAAE,OAAO,EAAE,SAAS,OAAA,GAAU,KAAU;AAClD;ACpBO,MAAM,sBAAsB,oBAAoBA,qBAAiB,EACrE,WAAW,QAAQ,EACnB,MAAA;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),r=require("@embedpdf/plugin-export"),t=require("react/jsx-runtime"),o=require("@embedpdf/models"),i=require("react"),n=require("@embedpdf/core/react"),u=()=>n.usePlugin(r.ExportPlugin.id),a=()=>n.useCapability(r.ExportPlugin.id);function l(e){const{provides:r}=a(),{plugin:n}=u(),l=i.useRef(null);return i.useEffect((()=>{if(!r)return;if(!n)return;return n.onRequest((r=>{if("download"===r){const r=l.current;if(!r)return;n.saveAsCopyAndGetBufferAndName().wait((({buffer:t,name:o})=>{const i=URL.createObjectURL(new Blob([t]));r.href=i,r.download=e.fileName??o,r.click(),URL.revokeObjectURL(i)}),o.ignore)}}))}),[r,n]),t.jsx("a",{style:{display:"none"},ref:l})}const s=e.createPluginPackage(r.ExportPluginPackage).addUtility(l).build();exports.Download=l,exports.ExportPluginPackage=s,exports.useExportCapability=a,exports.useExportPlugin=u,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-export"),t=require("react/jsx-runtime"),o=require("@embedpdf/models"),n=require("react"),u=require("@embedpdf/core/react"),i=()=>u.usePlugin(r.ExportPlugin.id),s=()=>u.useCapability(r.ExportPlugin.id);function l(){const{plugin:e}=i(),r=n.useRef(null);return n.useEffect(()=>{if(!e)return;return e.onRequest(t=>{const n=r.current;if(!n)return;e.saveAsCopyAndGetBufferAndName(t.documentId).wait(({buffer:e,name:r})=>{const t=URL.createObjectURL(new Blob([e]));n.href=t,n.download=r,n.click(),URL.revokeObjectURL(t)},o.ignore)})},[e]),t.jsx("a",{style:{display:"none"},ref:r})}const p=e.createPluginPackage(r.ExportPluginPackage).addUtility(l).build();exports.Download=l,exports.ExportPluginPackage=p,exports.useExport=e=>{const{provides:r}=s();return{provides:(null==r?void 0:r.forDocument(e))??null}},exports.useExportCapability=s,exports.useExportPlugin=i,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-export.ts","../../src/shared/component/download.tsx","../../src/shared/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n","import { ignore } from '@embedpdf/models';\nimport { useEffect, useRef } from '@framework';\n\nimport { useExportCapability, useExportPlugin } from '../hooks';\n\nexport interface DownloadProps {\n fileName?: string;\n}\n\nexport function Download(props: DownloadProps) {\n const { provides: exportCapability } = useExportCapability();\n const { plugin: exportPlugin } = useExportPlugin();\n const ref = useRef<HTMLAnchorElement>(null);\n\n useEffect(() => {\n if (!exportCapability) return;\n if (!exportPlugin) return;\n\n const unsub = exportPlugin.onRequest((action) => {\n if (action === 'download') {\n const el = ref.current;\n if (!el) return;\n\n const task = exportPlugin.saveAsCopyAndGetBufferAndName();\n task.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = props.fileName ?? name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n }\n });\n\n return unsub;\n }, [exportCapability, exportPlugin]);\n\n return <a style={{ display: 'none' }} ref={ref} />;\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './component';\n\nexport * from './hooks';\nexport * from './component';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["useExportPlugin","usePlugin","ExportPlugin","id","useExportCapability","useCapability","Download","props","provides","exportCapability","plugin","exportPlugin","ref","useRef","useEffect","onRequest","action","el","current","saveAsCopyAndGetBufferAndName","wait","buffer","name","url","URL","createObjectURL","Blob","href","download","fileName","click","revokeObjectURL","ignore","style","display","ExportPluginPackage","createPluginPackage","BaseExportPackage","addUtility","build"],"mappings":"yQAGaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,ICK3E,SAASG,EAASC,GACvB,MAAQC,SAAUC,GAAqBL,KAC/BM,OAAQC,GAAiBX,IAC3BY,EAAMC,SAA0B,aAEtCC,EAAAA,WAAU,KACR,IAAKL,EAAkB,OACvB,IAAKE,EAAc,OAkBZ,OAhBOA,EAAaI,WAAWC,IACpC,GAAe,aAAXA,EAAuB,CACzB,MAAMC,EAAKL,EAAIM,QACf,IAAKD,EAAI,OAEIN,EAAaQ,gCACrBC,MAAK,EAAGC,SAAQC,WACb,MAAAC,EAAMC,IAAIC,gBAAgB,IAAIC,KAAK,CAACL,KAC1CJ,EAAGU,KAAOJ,EACPN,EAAAW,SAAWrB,EAAMsB,UAAYP,EAChCL,EAAGa,QACHN,IAAIO,gBAAgBR,EAAG,GACtBS,SAAM,IAIN,GACN,CAACvB,EAAkBE,UAEd,IAAE,CAAAsB,MAAO,CAAEC,QAAS,QAAUtB,OACxC,CC5BO,MAAMuB,EAAsBC,EAAoBA,oBAAAC,EAAiBF,qBACrEG,WAAWhC,GACXiC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-export.ts","../../src/shared/component/download.tsx","../../src/shared/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n\n/**\n * Hook for export capability for a specific document\n * @param documentId Document ID\n */\nexport const useExport = (documentId: string) => {\n const { provides } = useExportCapability();\n\n return {\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n","import { ignore } from '@embedpdf/models';\nimport { useEffect, useRef } from '@framework';\n\nimport { useExportPlugin } from '../hooks';\n\nexport function Download() {\n const { plugin: exportPlugin } = useExportPlugin();\n const ref = useRef<HTMLAnchorElement>(null);\n\n useEffect(() => {\n if (!exportPlugin) return;\n\n const unsub = exportPlugin.onRequest((event) => {\n const el = ref.current;\n if (!el) return;\n\n const task = exportPlugin.saveAsCopyAndGetBufferAndName(event.documentId);\n task.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n });\n\n return unsub;\n }, [exportPlugin]);\n\n return <a style={{ display: 'none' }} ref={ref} />;\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './component';\n\nexport * from './hooks';\nexport * from './component';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["useExportPlugin","usePlugin","ExportPlugin","id","useExportCapability","useCapability","Download","plugin","exportPlugin","ref","useRef","useEffect","onRequest","event","el","current","saveAsCopyAndGetBufferAndName","documentId","wait","buffer","name","url","URL","createObjectURL","Blob","href","download","click","revokeObjectURL","ignore","style","display","ExportPluginPackage","createPluginPackage","BaseExportPackage","addUtility","build","provides","forDocument"],"mappings":"yQAGaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,ICC3E,SAASG,IACd,MAAQC,OAAQC,GAAiBR,IAC3BS,EAAMC,EAAAA,OAA0B,MAsBtC,OApBAC,EAAAA,UAAU,KACR,IAAKH,EAAc,OAgBnB,OAdcA,EAAaI,UAAWC,IACpC,MAAMC,EAAKL,EAAIM,QACf,IAAKD,EAAI,OAEIN,EAAaQ,8BAA8BH,EAAMI,YACzDC,KAAK,EAAGC,SAAQC,WACnB,MAAMC,EAAMC,IAAIC,gBAAgB,IAAIC,KAAK,CAACL,KAC1CL,EAAGW,KAAOJ,EACVP,EAAGY,SAAWN,EACdN,EAAGa,QACHL,IAAIM,gBAAgBP,IACnBQ,EAAAA,WAIJ,CAACrB,UAEI,IAAA,CAAEsB,MAAO,CAAEC,QAAS,QAAUtB,OACxC,CCpBO,MAAMuB,EAAsBC,EAAAA,oBAAoBC,EAAAA,qBACpDC,WAAW7B,GACX8B,2EFFuBnB,IACxB,MAAMoB,SAAEA,GAAajC,IAErB,MAAO,CACLiC,UAAU,MAAAA,OAAA,EAAAA,EAAUC,YAAYrB,KAAe"}
@@ -4,38 +4,41 @@ export * from "@embedpdf/plugin-export";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  import { ignore } from "@embedpdf/models";
6
6
  import { useRef, useEffect } from "react";
7
- import { useCapability, usePlugin } from "@embedpdf/core/react";
7
+ import { usePlugin, useCapability } from "@embedpdf/core/react";
8
8
  const useExportPlugin = () => usePlugin(ExportPlugin.id);
9
9
  const useExportCapability = () => useCapability(ExportPlugin.id);
10
- function Download(props) {
11
- const { provides: exportCapability } = useExportCapability();
10
+ const useExport = (documentId) => {
11
+ const { provides } = useExportCapability();
12
+ return {
13
+ provides: (provides == null ? void 0 : provides.forDocument(documentId)) ?? null
14
+ };
15
+ };
16
+ function Download() {
12
17
  const { plugin: exportPlugin } = useExportPlugin();
13
18
  const ref = useRef(null);
14
19
  useEffect(() => {
15
- if (!exportCapability) return;
16
20
  if (!exportPlugin) return;
17
- const unsub = exportPlugin.onRequest((action) => {
18
- if (action === "download") {
19
- const el = ref.current;
20
- if (!el) return;
21
- const task = exportPlugin.saveAsCopyAndGetBufferAndName();
22
- task.wait(({ buffer, name }) => {
23
- const url = URL.createObjectURL(new Blob([buffer]));
24
- el.href = url;
25
- el.download = props.fileName ?? name;
26
- el.click();
27
- URL.revokeObjectURL(url);
28
- }, ignore);
29
- }
21
+ const unsub = exportPlugin.onRequest((event) => {
22
+ const el = ref.current;
23
+ if (!el) return;
24
+ const task = exportPlugin.saveAsCopyAndGetBufferAndName(event.documentId);
25
+ task.wait(({ buffer, name }) => {
26
+ const url = URL.createObjectURL(new Blob([buffer]));
27
+ el.href = url;
28
+ el.download = name;
29
+ el.click();
30
+ URL.revokeObjectURL(url);
31
+ }, ignore);
30
32
  });
31
33
  return unsub;
32
- }, [exportCapability, exportPlugin]);
34
+ }, [exportPlugin]);
33
35
  return /* @__PURE__ */ jsx("a", { style: { display: "none" }, ref });
34
36
  }
35
37
  const ExportPluginPackage = createPluginPackage(ExportPluginPackage$1).addUtility(Download).build();
36
38
  export {
37
39
  Download,
38
40
  ExportPluginPackage,
41
+ useExport,
39
42
  useExportCapability,
40
43
  useExportPlugin
41
44
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-export.ts","../../src/shared/component/download.tsx","../../src/shared/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n","import { ignore } from '@embedpdf/models';\nimport { useEffect, useRef } from '@framework';\n\nimport { useExportCapability, useExportPlugin } from '../hooks';\n\nexport interface DownloadProps {\n fileName?: string;\n}\n\nexport function Download(props: DownloadProps) {\n const { provides: exportCapability } = useExportCapability();\n const { plugin: exportPlugin } = useExportPlugin();\n const ref = useRef<HTMLAnchorElement>(null);\n\n useEffect(() => {\n if (!exportCapability) return;\n if (!exportPlugin) return;\n\n const unsub = exportPlugin.onRequest((action) => {\n if (action === 'download') {\n const el = ref.current;\n if (!el) return;\n\n const task = exportPlugin.saveAsCopyAndGetBufferAndName();\n task.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = props.fileName ?? name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n }\n });\n\n return unsub;\n }, [exportCapability, exportPlugin]);\n\n return <a style={{ display: 'none' }} ref={ref} />;\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './component';\n\nexport * from './hooks';\nexport * from './component';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["BaseExportPackage"],"mappings":";;;;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;ACK7E,SAAS,SAAS,OAAsB;AAC7C,QAAM,EAAE,UAAU,iBAAiB,IAAI,oBAAoB;AAC3D,QAAM,EAAE,QAAQ,aAAa,IAAI,gBAAgB;AAC3C,QAAA,MAAM,OAA0B,IAAI;AAE1C,YAAU,MAAM;AACd,QAAI,CAAC,iBAAkB;AACvB,QAAI,CAAC,aAAc;AAEnB,UAAM,QAAQ,aAAa,UAAU,CAAC,WAAW;AAC/C,UAAI,WAAW,YAAY;AACzB,cAAM,KAAK,IAAI;AACf,YAAI,CAAC,GAAI;AAEH,cAAA,OAAO,aAAa,8BAA8B;AACxD,aAAK,KAAK,CAAC,EAAE,QAAQ,WAAW;AACxB,gBAAA,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAClD,aAAG,OAAO;AACP,aAAA,WAAW,MAAM,YAAY;AAChC,aAAG,MAAM;AACT,cAAI,gBAAgB,GAAG;AAAA,WACtB,MAAM;AAAA,MAAA;AAAA,IACX,CACD;AAEM,WAAA;AAAA,EAAA,GACN,CAAC,kBAAkB,YAAY,CAAC;AAEnC,6BAAQ,KAAE,EAAA,OAAO,EAAE,SAAS,OAAA,GAAU,KAAU;AAClD;AC5BO,MAAM,sBAAsB,oBAAoBA,qBAAiB,EACrE,WAAW,QAAQ,EACnB,MAAM;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-export.ts","../../src/shared/component/download.tsx","../../src/shared/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n\n/**\n * Hook for export capability for a specific document\n * @param documentId Document ID\n */\nexport const useExport = (documentId: string) => {\n const { provides } = useExportCapability();\n\n return {\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n","import { ignore } from '@embedpdf/models';\nimport { useEffect, useRef } from '@framework';\n\nimport { useExportPlugin } from '../hooks';\n\nexport function Download() {\n const { plugin: exportPlugin } = useExportPlugin();\n const ref = useRef<HTMLAnchorElement>(null);\n\n useEffect(() => {\n if (!exportPlugin) return;\n\n const unsub = exportPlugin.onRequest((event) => {\n const el = ref.current;\n if (!el) return;\n\n const task = exportPlugin.saveAsCopyAndGetBufferAndName(event.documentId);\n task.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n });\n\n return unsub;\n }, [exportPlugin]);\n\n return <a style={{ display: 'none' }} ref={ref} />;\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './component';\n\nexport * from './hooks';\nexport * from './component';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["BaseExportPackage"],"mappings":";;;;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAM7E,MAAM,YAAY,CAAC,eAAuB;AAC/C,QAAM,EAAE,SAAA,IAAa,oBAAA;AAErB,SAAO;AAAA,IACL,WAAU,qCAAU,YAAY,gBAAe;AAAA,EAAA;AAEnD;ACXO,SAAS,WAAW;AACzB,QAAM,EAAE,QAAQ,aAAA,IAAiB,gBAAA;AACjC,QAAM,MAAM,OAA0B,IAAI;AAE1C,YAAU,MAAM;AACd,QAAI,CAAC,aAAc;AAEnB,UAAM,QAAQ,aAAa,UAAU,CAAC,UAAU;AAC9C,YAAM,KAAK,IAAI;AACf,UAAI,CAAC,GAAI;AAET,YAAM,OAAO,aAAa,8BAA8B,MAAM,UAAU;AACxE,WAAK,KAAK,CAAC,EAAE,QAAQ,WAAW;AAC9B,cAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAClD,WAAG,OAAO;AACV,WAAG,WAAW;AACd,WAAG,MAAA;AACH,YAAI,gBAAgB,GAAG;AAAA,MACzB,GAAG,MAAM;AAAA,IACX,CAAC;AAED,WAAO;AAAA,EACT,GAAG,CAAC,YAAY,CAAC;AAEjB,6BAAQ,KAAA,EAAE,OAAO,EAAE,SAAS,OAAA,GAAU,KAAU;AAClD;ACpBO,MAAM,sBAAsB,oBAAoBA,qBAAiB,EACrE,WAAW,QAAQ,EACnB,MAAA;"}
@@ -1,4 +1 @@
1
- export interface DownloadProps {
2
- fileName?: string;
3
- }
4
- export declare function Download(props: DownloadProps): import("react/jsx-runtime").JSX.Element;
1
+ export declare function Download(): import("react/jsx-runtime").JSX.Element;
@@ -9,3 +9,10 @@ export declare const useExportCapability: () => {
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
11
  };
12
+ /**
13
+ * Hook for export capability for a specific document
14
+ * @param documentId Document ID
15
+ */
16
+ export declare const useExport: (documentId: string) => {
17
+ provides: import('../../index.ts').ExportScope | null;
18
+ };
@@ -1,4 +1 @@
1
- export interface DownloadProps {
2
- fileName?: string;
3
- }
4
- export declare function Download(props: DownloadProps): import("preact").JSX.Element;
1
+ export declare function Download(): import("preact").JSX.Element;
@@ -9,3 +9,10 @@ export declare const useExportCapability: () => {
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
11
  };
12
+ /**
13
+ * Hook for export capability for a specific document
14
+ * @param documentId Document ID
15
+ */
16
+ export declare const useExport: (documentId: string) => {
17
+ provides: import('../../lib/index.ts').ExportScope | null;
18
+ };
@@ -1,4 +1 @@
1
- export interface DownloadProps {
2
- fileName?: string;
3
- }
4
- export declare function Download(props: DownloadProps): import("react/jsx-runtime").JSX.Element;
1
+ export declare function Download(): import("react/jsx-runtime").JSX.Element;
@@ -9,3 +9,10 @@ export declare const useExportCapability: () => {
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
11
  };
12
+ /**
13
+ * Hook for export capability for a specific document
14
+ * @param documentId Document ID
15
+ */
16
+ export declare const useExport: (documentId: string) => {
17
+ provides: import('../../lib/index.ts').ExportScope | null;
18
+ };
@@ -1,4 +1,4 @@
1
- import { ExportPlugin } from '../../lib/index.ts';
1
+ import { ExportPlugin, ExportScope } from '../../lib/index.ts';
2
2
  export declare const useExportPlugin: () => {
3
3
  plugin: ExportPlugin | null;
4
4
  isLoading: boolean;
@@ -9,3 +9,12 @@ export declare const useExportCapability: () => {
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
11
  };
12
+ interface UseExportReturn {
13
+ provides: ExportScope | null;
14
+ }
15
+ /**
16
+ * Hook for export capability for a specific document
17
+ * @param getDocumentId Function that returns the document ID
18
+ */
19
+ export declare const useExport: (getDocumentId: () => string | null) => UseExportReturn;
20
+ export {};
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-export");require("svelte/internal/disclose-version");const r=require("svelte/internal/client"),o=require("@embedpdf/models"),n=require("@embedpdf/core/svelte");function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}const l=i(r),u=()=>n.usePlugin(t.ExportPlugin.id),a=()=>n.useCapability(t.ExportPlugin.id);var s=l.from_html('<a style="display: none" href="/" aria-label="Download link"></a>');function c(e,t){l.push(t,!0);const r=a(),n=u();let i;l.user_effect((()=>{if(!r.provides)return;if(!n.plugin)return;return n.plugin.onRequest((e=>{var t;if("download"===e){const e=i;if(!e)return;const r=null==(t=n.plugin)?void 0:t.saveAsCopyAndGetBufferAndName();null==r||r.wait((({buffer:t,name:r})=>{const o=URL.createObjectURL(new Blob([t]));e.href=o,e.download=r,e.click(),URL.revokeObjectURL(o)}),o.ignore)}}))}));var c=s();l.bind_this(c,(e=>i=e),(()=>i)),l.append(e,c),l.pop()}const p=e.createPluginPackage(t.ExportPluginPackage).addUtility(c).build();exports.Download=c,exports.ExportPluginPackage=p,exports.useExportCapability=a,exports.useExportPlugin=u,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-export");require("svelte/internal/disclose-version");const r=require("svelte/internal/client"),o=require("@embedpdf/models"),n=require("@embedpdf/core/svelte");function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}const l=i(r),u=()=>n.usePlugin(t.ExportPlugin.id),s=()=>n.useCapability(t.ExportPlugin.id);var a=l.from_html('<a style="display: none" href="/" aria-label="Download link"></a>');function p(e,t){l.push(t,!0);const r=s(),n=u();let i;l.user_effect(()=>{if(!r.provides)return;if(!n.plugin)return;return n.plugin.onRequest(e=>{var t;const r=i;if(!r)return;const l=null==(t=n.plugin)?void 0:t.saveAsCopyAndGetBufferAndName(e.documentId);null==l||l.wait(({buffer:e,name:t})=>{const o=URL.createObjectURL(new Blob([e]));r.href=o,r.download=t,r.click(),URL.revokeObjectURL(o)},o.ignore)})});var p=a();l.bind_this(p,e=>i=e,()=>i),l.append(e,p),l.pop()}const c=e.createPluginPackage(t.ExportPluginPackage).addUtility(p).build();exports.Download=p,exports.ExportPluginPackage=c,exports.useExport=e=>{const t=s(),r=l.derived(e),o=l.derived(()=>t.provides&&l.get(r)?t.provides.forDocument(l.get(r)):null);return{get provides(){return l.get(o)}}},exports.useExportCapability=s,exports.useExportPlugin=u,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/svelte/hooks/use-export.svelte.ts","../../src/svelte/components/Download.svelte","../../src/svelte/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n","<script lang=\"ts\">\n import { ignore } from '@embedpdf/models';\n import { useExportCapability, useExportPlugin } from '../hooks';\n\n const exportCapability = useExportCapability();\n const exportPlugin = useExportPlugin();\n\n let anchorElement: HTMLAnchorElement | undefined;\n\n $effect(() => {\n if (!exportCapability.provides) return;\n if (!exportPlugin.plugin) return;\n\n const unsub = exportPlugin.plugin.onRequest((action) => {\n if (action === 'download') {\n const el = anchorElement;\n if (!el) return;\n\n const task = exportPlugin.plugin?.saveAsCopyAndGetBufferAndName();\n task?.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n }\n });\n\n return unsub;\n });\n</script>\n\n<a style=\"display: none\" bind:this={anchorElement} href=\"/\" aria-label=\"Download link\"></a>\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './components';\n\nexport * from './hooks';\nexport * from './components';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["useExportPlugin","usePlugin","ExportPlugin","id","useExportCapability","useCapability","exportCapability","exportPlugin","anchorElement","$","user_effect","provides","plugin","onRequest","action","el","task","_a","saveAsCopyAndGetBufferAndName","wait","buffer","name","url","URL","createObjectURL","Blob","href","download","click","revokeObjectURL","ignore","bind_this","a","$$value","ExportPluginPackage","createPluginPackage","BaseExportPackage","addUtility","Download","build"],"mappings":"skBAGaA,EAAwB,IAAAC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAA4B,IAAAC,gBAA4BH,EAAAA,aAAaC,wHCA1E,MAAAG,EAAmBF,IACnBG,EAAeP,IAEjB,IAAAQ,EAEJC,EAAAC,aAAc,KACP,IAAAJ,EAAiBK,SAAQ,OACzB,IAAAJ,EAAaK,OAAM,OAkBjB,OAhBOL,EAAaK,OAAOC,WAAWC,aAC5B,aAAXA,EAAuB,CACnB,MAAAC,EAAKP,MACNO,EAAE,OAED,MAAAC,EAAO,OAAAC,EAAaV,EAAAK,aAAQ,EAAAK,EAAAC,gCAC5B,MAAAF,GAAAA,EAAAG,QAAQC,SAAQC,WACd,MAAAC,EAAMC,IAAIC,gBAAoB,IAAAC,MAAML,KAC1CL,EAAGW,KAAOJ,EACVP,EAAGY,SAAWN,EACdN,EAAGa,QACHL,IAAIM,gBAAgBP,EAAG,GACtBQ,EAAAA,OACL,IAGK,cAIyBrB,EAAAsB,UAAAC,GAAAC,GAAAzB,UAAAA,yBAFpC,CCrBO,MAAM0B,EAAsBC,EAAoBA,oBAAAC,EAAiBF,qBACrEG,WAAWC,GACXC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-export.svelte.ts","../../src/svelte/components/Download.svelte","../../src/svelte/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { ExportPlugin, ExportScope } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseExportReturn {\n provides: ExportScope | null;\n}\n\n/**\n * Hook for export capability for a specific document\n * @param getDocumentId Function that returns the document ID\n */\nexport const useExport = (getDocumentId: () => string | null): UseExportReturn => {\n const capability = useExportCapability();\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 { ignore } from '@embedpdf/models';\n import { useExportCapability, useExportPlugin } from '../hooks';\n\n const exportCapability = useExportCapability();\n const exportPlugin = useExportPlugin();\n\n let anchorElement: HTMLAnchorElement | undefined;\n\n $effect(() => {\n if (!exportCapability.provides) return;\n if (!exportPlugin.plugin) return;\n\n const unsub = exportPlugin.plugin.onRequest((event) => {\n const el = anchorElement;\n if (!el) return;\n\n const task = exportPlugin.plugin?.saveAsCopyAndGetBufferAndName(event.documentId);\n task?.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n });\n\n return unsub;\n });\n</script>\n\n<a style=\"display: none\" bind:this={anchorElement} href=\"/\" aria-label=\"Download link\"></a>\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './components';\n\nexport * from './hooks';\nexport * from './components';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["useExportPlugin","usePlugin","ExportPlugin","id","useExportCapability","useCapability","exportCapability","exportPlugin","anchorElement","$","user_effect","provides","plugin","onRequest","event","el","task","_a","saveAsCopyAndGetBufferAndName","documentId","wait","buffer","name","url","URL","createObjectURL","Blob","href","download","click","revokeObjectURL","ignore","bind_this","a","$$value","ExportPluginPackage","createPluginPackage","BaseExportPackage","addUtility","Download","build","getDocumentId","capability","scopedProvides","derived","forDocument"],"mappings":"skBAGaA,EAAA,IAAwBC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAA,IAA4BC,gBAA4BH,EAAAA,aAAaC,wHCA1E,MAAAG,EAAmBF,IACnBG,EAAeP,QAEjBQ,EAEJC,EAAAC,YAAO,KACA,IAAAJ,EAAiBK,SAAQ,OACzB,IAAAJ,EAAaK,OAAM,cAEVL,EAAaK,OAAOC,UAAWC,UACrC,MAAAC,EAAKP,MACNO,EAAE,aAEDC,EAAO,OAAAC,EAAAV,EAAaK,aAAb,EAAAK,EAAqBC,8BAA8BJ,EAAMK,YACtE,MAAAH,GAAAA,EAAMI,OAAQC,SAAQC,WACd,MAAAC,EAAMC,IAAIC,gBAAe,IAAKC,MAAML,KAC1CN,EAAGY,KAAOJ,EACVR,EAAGa,SAAWN,EACdP,EAAGc,QACHL,IAAIM,gBAAgBP,IACnBQ,EAAAA,sBAO2BtB,EAAAuB,UAAAC,EAAAC,GAAA1B,QAAAA,wBAFpC,CCnBO,MAAM2B,EAAsBC,EAAAA,oBAAoBC,EAAAA,qBACpDC,WAAWC,GACXC,2EFGuBC,IAClB,MAAAC,EAAatC,IAGbe,YAAsBsB,GAGtBE,EAAAlC,EAAAmC,QAAA,IACJF,EAAW/B,gBAAYQ,GAAauB,EAAW/B,SAASkC,kBAAY1B,IAAc,aAI9E,YAAAR,gBACKgC,EACT"}
@@ -7,6 +7,16 @@ import { ignore } from "@embedpdf/models";
7
7
  import { useCapability, usePlugin } from "@embedpdf/core/svelte";
8
8
  const useExportPlugin = () => usePlugin(ExportPlugin.id);
9
9
  const useExportCapability = () => useCapability(ExportPlugin.id);
10
+ const useExport = (getDocumentId) => {
11
+ const capability = useExportCapability();
12
+ const documentId = $.derived(getDocumentId);
13
+ const scopedProvides = $.derived(() => capability.provides && $.get(documentId) ? capability.provides.forDocument($.get(documentId)) : null);
14
+ return {
15
+ get provides() {
16
+ return $.get(scopedProvides);
17
+ }
18
+ };
19
+ };
10
20
  var root = $.from_html(`<a style="display: none" href="/" aria-label="Download link"></a>`);
11
21
  function Download($$anchor, $$props) {
12
22
  $.push($$props, true);
@@ -16,23 +26,21 @@ function Download($$anchor, $$props) {
16
26
  $.user_effect(() => {
17
27
  if (!exportCapability.provides) return;
18
28
  if (!exportPlugin.plugin) return;
19
- const unsub = exportPlugin.plugin.onRequest((action) => {
29
+ const unsub = exportPlugin.plugin.onRequest((event) => {
20
30
  var _a;
21
- if (action === "download") {
22
- const el = anchorElement;
23
- if (!el) return;
24
- const task = (_a = exportPlugin.plugin) == null ? void 0 : _a.saveAsCopyAndGetBufferAndName();
25
- task == null ? void 0 : task.wait(
26
- ({ buffer, name }) => {
27
- const url = URL.createObjectURL(new Blob([buffer]));
28
- el.href = url;
29
- el.download = name;
30
- el.click();
31
- URL.revokeObjectURL(url);
32
- },
33
- ignore
34
- );
35
- }
31
+ const el = anchorElement;
32
+ if (!el) return;
33
+ const task = (_a = exportPlugin.plugin) == null ? void 0 : _a.saveAsCopyAndGetBufferAndName(event.documentId);
34
+ task == null ? void 0 : task.wait(
35
+ ({ buffer, name }) => {
36
+ const url = URL.createObjectURL(new Blob([buffer]));
37
+ el.href = url;
38
+ el.download = name;
39
+ el.click();
40
+ URL.revokeObjectURL(url);
41
+ },
42
+ ignore
43
+ );
36
44
  });
37
45
  return unsub;
38
46
  });
@@ -45,6 +53,7 @@ const ExportPluginPackage = createPluginPackage(ExportPluginPackage$1).addUtilit
45
53
  export {
46
54
  Download,
47
55
  ExportPluginPackage,
56
+ useExport,
48
57
  useExportCapability,
49
58
  useExportPlugin
50
59
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-export.svelte.ts","../../src/svelte/components/Download.svelte","../../src/svelte/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n","<script lang=\"ts\">\n import { ignore } from '@embedpdf/models';\n import { useExportCapability, useExportPlugin } from '../hooks';\n\n const exportCapability = useExportCapability();\n const exportPlugin = useExportPlugin();\n\n let anchorElement: HTMLAnchorElement | undefined;\n\n $effect(() => {\n if (!exportCapability.provides) return;\n if (!exportPlugin.plugin) return;\n\n const unsub = exportPlugin.plugin.onRequest((action) => {\n if (action === 'download') {\n const el = anchorElement;\n if (!el) return;\n\n const task = exportPlugin.plugin?.saveAsCopyAndGetBufferAndName();\n task?.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n }\n });\n\n return unsub;\n });\n</script>\n\n<a style=\"display: none\" bind:this={anchorElement} href=\"/\" aria-label=\"Download link\"></a>\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './components';\n\nexport * from './hooks';\nexport * from './components';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["BaseExportPackage"],"mappings":";;;;;;;AAGa,MAAA,kBAAwB,MAAA,UAAwB,aAAa,EAAE;AAC/D,MAAA,sBAA4B,MAAA,cAA4B,aAAa,EAAE;;qCCJpF;;AAIQ,QAAA,mBAAmB,oBAAmB;AACtC,QAAA,eAAe,gBAAe;MAEhC;AAEJ,IAAA,YAAc,MAAA;AACP,QAAA,CAAA,iBAAiB,SAAQ;AACzB,QAAA,CAAA,aAAa,OAAM;UAElB,QAAQ,aAAa,OAAO,UAAS,CAAE,WAAW;;UAClD,WAAW,YAAY;AACnB,cAAA,KAAK;aACN,GAAE;AAED,cAAA,QAAO,kBAAa,WAAb,mBAAqB;AAClC,qCAAM;AAAA,aAAQ,QAAQ,WAAW;AACzB,kBAAA,MAAM,IAAI,gBAAoB,IAAA,MAAM,MAAM,CAAA,CAAA;AAChD,eAAG,OAAO;AACV,eAAG,WAAW;AACd,eAAG,MAAK;AACR,gBAAI,gBAAgB,GAAG;AAAA,UACxB;AAAA,UAAE;AAAA;AAAA,MACL;AAAA,KACD;WAEM;AAAA,GACR;;AAGiC,IAAA,UAAA,GAAA,CAAA,YAAA,+BAAA,aAAa;;;AAFjD;ACrBO,MAAM,sBAAsB,oBAAoBA,qBAAiB,EACrE,WAAW,QAAQ,EACnB,MAAM;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-export.svelte.ts","../../src/svelte/components/Download.svelte","../../src/svelte/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { ExportPlugin, ExportScope } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseExportReturn {\n provides: ExportScope | null;\n}\n\n/**\n * Hook for export capability for a specific document\n * @param getDocumentId Function that returns the document ID\n */\nexport const useExport = (getDocumentId: () => string | null): UseExportReturn => {\n const capability = useExportCapability();\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 { ignore } from '@embedpdf/models';\n import { useExportCapability, useExportPlugin } from '../hooks';\n\n const exportCapability = useExportCapability();\n const exportPlugin = useExportPlugin();\n\n let anchorElement: HTMLAnchorElement | undefined;\n\n $effect(() => {\n if (!exportCapability.provides) return;\n if (!exportPlugin.plugin) return;\n\n const unsub = exportPlugin.plugin.onRequest((event) => {\n const el = anchorElement;\n if (!el) return;\n\n const task = exportPlugin.plugin?.saveAsCopyAndGetBufferAndName(event.documentId);\n task?.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n });\n\n return unsub;\n });\n</script>\n\n<a style=\"display: none\" bind:this={anchorElement} href=\"/\" aria-label=\"Download link\"></a>\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './components';\n\nexport * from './hooks';\nexport * from './components';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["BaseExportPackage"],"mappings":";;;;;;;AAGa,MAAA,kBAAA,MAAwB,UAAwB,aAAa,EAAE;AAC/D,MAAA,sBAAA,MAA4B,cAA4B,aAAa,EAAE;MAWvE,YAAA,CAAa,kBAAwD;AAC1E,QAAA,aAAa,oBAAA;AAGb,QAAA,uBAAsB,aAAA;AAGtB,QAAA,iBAAA,EAAA,QAAA,MACJ,WAAW,kBAAY,UAAA,IAAa,WAAW,SAAS,kBAAY,UAAU,CAAA,IAAI,IAAA;;IAI9E,IAAA,WAAW;mBACN,cAAA;AAAA,IACT;AAAA;AAEJ;;qCC/BA;;AAIQ,QAAA,mBAAmB,oBAAmB;AACtC,QAAA,eAAe,gBAAe;MAEhC;AAEJ,IAAA,YAAO,MAAO;AACP,QAAA,CAAA,iBAAiB,SAAQ;AACzB,QAAA,CAAA,aAAa,OAAM;UAElB,QAAQ,aAAa,OAAO,UAAS,CAAE,UAAU;;AAC/C,YAAA,KAAK;WACN,GAAE;YAED,QAAO,kBAAa,WAAb,mBAAqB,8BAA8B,MAAM;AACtE,mCAAM;AAAA,WAAQ,QAAQ,WAAW;AACzB,gBAAA,MAAM,IAAI,gBAAe,IAAK,MAAM,MAAM,CAAA,CAAA;AAChD,aAAG,OAAO;AACV,aAAG,WAAW;AACd,aAAG,MAAK;AACR,cAAI,gBAAgB,GAAG;AAAA,QACzB;AAAA,QAAG;AAAA;AAAA,IACL,CAAC;WAEM;AAAA,EACT,CAAC;;AAGiC,IAAA,UAAA,GAAA,CAAA,YAAA,+BAAA,aAAa;;;AAFjD;ACnBO,MAAM,sBAAsB,oBAAoBA,qBAAiB,EACrE,WAAW,QAAQ,EACnB,MAAA;"}
@@ -1,5 +1,3 @@
1
- export interface DownloadProps {
2
- fileName?: string;
3
- }
4
- declare const _default: import('vue').DefineComponent<DownloadProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<DownloadProps> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, 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;
5
3
  export default _default;
@@ -1,3 +1,11 @@
1
+ import { MaybeRefOrGetter } from 'vue';
1
2
  import { ExportPlugin } from '../../lib/index.ts';
2
3
  export declare const useExportPlugin: () => import('@embedpdf/core/vue').PluginState<ExportPlugin>;
3
4
  export declare const useExportCapability: () => import('@embedpdf/core/vue').CapabilityState<Readonly<import('../../lib/index.ts').ExportCapability>>;
5
+ /**
6
+ * Hook for export capability for a specific document
7
+ * @param documentId Document ID (can be ref, computed, getter, or plain value)
8
+ */
9
+ export declare const useExport: (documentId: MaybeRefOrGetter<string>) => {
10
+ provides: import('vue').ComputedRef<import('../../lib/index.ts').ExportScope | null>;
11
+ };
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),o=require("@embedpdf/plugin-export"),r=require("vue"),t=require("@embedpdf/models"),n=require("@embedpdf/core/vue"),l=()=>n.usePlugin(o.ExportPlugin.id),u=()=>n.useCapability(o.ExportPlugin.id),a=r.defineComponent({__name:"download",props:{fileName:{}},setup(e){const o=e,{provides:n}=u(),{plugin:a}=l(),i=r.ref(null);let p=null;return r.onMounted((()=>{const e=n.value,r=a.value;e&&r&&(p=r.onRequest((e=>{if("download"===e){const e=i.value;if(!e)return;r.saveAsCopyAndGetBufferAndName().wait((({buffer:r,name:t})=>{const n=URL.createObjectURL(new Blob([r]));e.href=n,e.download=o.fileName??t,e.click(),URL.revokeObjectURL(n)}),t.ignore)}})))})),r.onUnmounted((()=>{p&&p()})),(e,o)=>(r.openBlock(),r.createElementBlock("a",{ref_key:"anchorRef",ref:i,style:{display:"none"}},null,512))}}),i=e.createPluginPackage(o.ExportPluginPackage).addUtility(a).build();exports.Download=a,exports.ExportPluginPackage=i,exports.useExportCapability=u,exports.useExportPlugin=l,Object.keys(o).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>o[e]})}));
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),o=require("@embedpdf/plugin-export"),r=require("vue"),t=require("@embedpdf/models"),n=require("@embedpdf/core/vue"),u=()=>n.usePlugin(o.ExportPlugin.id),l=()=>n.useCapability(o.ExportPlugin.id),a=r.defineComponent({__name:"download",setup(e){const{provides:o}=l(),{plugin:n}=u(),a=r.ref(null);let p=null;return r.onMounted(()=>{const e=o.value,r=n.value;e&&r&&(p=r.onRequest(e=>{const o=a.value;if(!o)return;r.saveAsCopyAndGetBufferAndName(e.documentId).wait(({buffer:e,name:r})=>{const t=URL.createObjectURL(new Blob([e]));o.href=t,o.download=r,o.click(),URL.revokeObjectURL(t)},t.ignore)}))}),r.onUnmounted(()=>{p&&p()}),(e,o)=>(r.openBlock(),r.createElementBlock("a",{ref_key:"anchorRef",ref:a,style:{display:"none"}},null,512))}}),p=e.createPluginPackage(o.ExportPluginPackage).addUtility(a).build();exports.Download=a,exports.ExportPluginPackage=p,exports.useExport=e=>{const{provides:o}=l();return{provides:r.computed(()=>{var t;return(null==(t=o.value)?void 0:t.forDocument(r.toValue(e)))??null})}},exports.useExportCapability=l,exports.useExportPlugin=u,Object.keys(o).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>o[e]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-export.ts","../../src/vue/components/download.vue","../../src/vue/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n","<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted } from 'vue';\nimport { ignore } from '@embedpdf/models';\nimport { Unsubscribe } from '@embedpdf/core';\n\nimport { useExportCapability, useExportPlugin } from '../hooks';\n\nexport interface DownloadProps {\n fileName?: string;\n}\n\nconst props = defineProps<DownloadProps>();\n\nconst { provides: exportCapabilityRef } = useExportCapability();\nconst { plugin: exportPluginRef } = useExportPlugin();\nconst anchorRef = ref<HTMLAnchorElement | null>(null);\n\nlet unsubscribe: Unsubscribe | null = null;\n\nonMounted(() => {\n const exportCapability = exportCapabilityRef.value;\n const exportPlugin = exportPluginRef.value;\n\n if (!exportCapability || !exportPlugin) return;\n\n unsubscribe = exportPlugin.onRequest((action) => {\n if (action === 'download') {\n const el = anchorRef.value;\n if (!el) return;\n\n const task = exportPlugin.saveAsCopyAndGetBufferAndName();\n task.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = props.fileName ?? name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n }\n });\n});\n\nonUnmounted(() => {\n if (unsubscribe) {\n unsubscribe();\n }\n});\n</script>\n\n<template>\n <a ref=\"anchorRef\" style=\"display: none\" />\n</template>\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './components';\n\nexport * from './hooks';\nexport * from './components';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["useExportPlugin","usePlugin","ExportPlugin","id","useExportCapability","useCapability","props","__props","provides","exportCapabilityRef","plugin","exportPluginRef","anchorRef","ref","unsubscribe","onMounted","exportCapability","value","exportPlugin","onRequest","action","el","saveAsCopyAndGetBufferAndName","wait","buffer","name","url","URL","createObjectURL","Blob","href","download","fileName","click","revokeObjectURL","ignore","onUnmounted","_createElementBlock","createElementBlock","style","display","ExportPluginPackage","createPluginPackage","BaseExportPackage","addUtility","Download","build"],"mappings":"sOAGaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,wECOlF,MAAMG,EAAQC,GAENC,SAAUC,GAAwBL,KAClCM,OAAQC,GAAoBX,IAC9BY,EAAYC,MAA8B,MAEhD,IAAIC,EAAkC,YAEtCC,EAAAA,WAAU,KACR,MAAMC,EAAmBP,EAAoBQ,MACvCC,EAAeP,EAAgBM,MAEhCD,GAAqBE,IAEZJ,EAAAI,EAAaC,WAAWC,IACpC,GAAe,aAAXA,EAAuB,CACzB,MAAMC,EAAKT,EAAUK,MACrB,IAAKI,EAAI,OAEIH,EAAaI,gCACrBC,MAAK,EAAGC,SAAQC,WACb,MAAAC,EAAMC,IAAIC,gBAAgB,IAAIC,KAAK,CAACL,KAC1CH,EAAGS,KAAOJ,EACPL,EAAAU,SAAWzB,EAAM0B,UAAYP,EAChCJ,EAAGY,QACHN,IAAIO,gBAAgBR,EAAG,GACtBS,SAAM,KAEZ,IAGHC,EAAAA,aAAY,KACNtB,GACUA,GAAA,0BAMduB,EAAAC,mBAA2C,IAAA,SAApC,YAAJzB,IAAID,EAAY2B,MAAA,CAAqBC,QAAA,uBCxC7BC,EAAsBC,EAAoBA,oBAAAC,EAAiBF,qBACrEG,WAAWC,GACXC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-export.ts","../../src/vue/components/download.vue","../../src/vue/index.ts"],"sourcesContent":["import { computed, MaybeRefOrGetter, toValue } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n\n/**\n * Hook for export capability for a specific document\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport const useExport = (documentId: MaybeRefOrGetter<string>) => {\n const { provides } = useExportCapability();\n\n return {\n provides: computed(() => provides.value?.forDocument(toValue(documentId)) ?? null),\n };\n};\n","<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted } from 'vue';\nimport { ignore } from '@embedpdf/models';\nimport { Unsubscribe } from '@embedpdf/core';\n\nimport { useExportCapability, useExportPlugin } from '../hooks';\n\nconst { provides: exportCapabilityRef } = useExportCapability();\nconst { plugin: exportPluginRef } = useExportPlugin();\nconst anchorRef = ref<HTMLAnchorElement | null>(null);\n\nlet unsubscribe: Unsubscribe | null = null;\n\nonMounted(() => {\n const exportCapability = exportCapabilityRef.value;\n const exportPlugin = exportPluginRef.value;\n\n if (!exportCapability || !exportPlugin) return;\n\n unsubscribe = exportPlugin.onRequest((event) => {\n const el = anchorRef.value;\n if (!el) return;\n\n const task = exportPlugin.saveAsCopyAndGetBufferAndName(event.documentId);\n task.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n });\n});\n\nonUnmounted(() => {\n if (unsubscribe) {\n unsubscribe();\n }\n});\n</script>\n\n<template>\n <a ref=\"anchorRef\" style=\"display: none\" />\n</template>\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './components';\n\nexport * from './hooks';\nexport * from './components';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["useExportPlugin","usePlugin","ExportPlugin","id","useExportCapability","useCapability","provides","exportCapabilityRef","plugin","exportPluginRef","anchorRef","ref","unsubscribe","onMounted","exportCapability","value","exportPlugin","onRequest","event","el","saveAsCopyAndGetBufferAndName","documentId","wait","buffer","name","url","URL","createObjectURL","Blob","href","download","click","revokeObjectURL","ignore","onUnmounted","_createElementBlock","style","display","ExportPluginPackage","createPluginPackage","BaseExportPackage","addUtility","Download","build","computed","_a","forDocument","toValue"],"mappings":"sOAIaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,oDCElF,MAAQG,SAAUC,GAAwBH,KAClCI,OAAQC,GAAoBT,IAC9BU,EAAYC,EAAAA,IAA8B,MAEhD,IAAIC,EAAkC,YAEtCC,EAAAA,UAAU,KACR,MAAMC,EAAmBP,EAAoBQ,MACvCC,EAAeP,EAAgBM,MAEhCD,GAAqBE,IAE1BJ,EAAcI,EAAaC,UAAWC,IACpC,MAAMC,EAAKT,EAAUK,MACrB,IAAKI,EAAI,OAEIH,EAAaI,8BAA8BF,EAAMG,YACzDC,KAAK,EAAGC,SAAQC,WACnB,MAAMC,EAAMC,IAAIC,gBAAgB,IAAIC,KAAK,CAACL,KAC1CJ,EAAGU,KAAOJ,EACVN,EAAGW,SAAWN,EACdL,EAAGY,QACHL,IAAIM,gBAAgBP,IACnBQ,EAAAA,aAIPC,EAAAA,YAAY,KACNtB,GACFA,4BAMFuB,EAAAA,mBAA2C,IAAA,SAApC,YAAJxB,IAAID,EAAY0B,MAAA,CAAAC,QAAA,uBChCRC,EAAsBC,EAAAA,oBAAoBC,EAAAA,qBACpDC,WAAWC,GACXC,2EFDuBtB,IACxB,MAAMf,SAAEA,GAAaF,IAErB,MAAO,CACLE,SAAUsC,EAAAA,SAAS,WAAM,OAAA,OAAAC,EAAAvC,EAASS,YAAT,EAAA8B,EAAgBC,YAAYC,EAAAA,QAAQ1B,MAAgB"}
package/dist/vue/index.js CHANGED
@@ -1,18 +1,23 @@
1
1
  import { createPluginPackage } from "@embedpdf/core";
2
2
  import { ExportPlugin, ExportPluginPackage as ExportPluginPackage$1 } from "@embedpdf/plugin-export";
3
3
  export * from "@embedpdf/plugin-export";
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 { ignore } from "@embedpdf/models";
6
6
  import { useCapability, usePlugin } from "@embedpdf/core/vue";
7
7
  const useExportPlugin = () => usePlugin(ExportPlugin.id);
8
8
  const useExportCapability = () => useCapability(ExportPlugin.id);
9
+ const useExport = (documentId) => {
10
+ const { provides } = useExportCapability();
11
+ return {
12
+ provides: computed(() => {
13
+ var _a;
14
+ return ((_a = provides.value) == null ? void 0 : _a.forDocument(toValue(documentId))) ?? null;
15
+ })
16
+ };
17
+ };
9
18
  const _sfc_main = /* @__PURE__ */ defineComponent({
10
19
  __name: "download",
11
- props: {
12
- fileName: {}
13
- },
14
20
  setup(__props) {
15
- const props = __props;
16
21
  const { provides: exportCapabilityRef } = useExportCapability();
17
22
  const { plugin: exportPluginRef } = useExportPlugin();
18
23
  const anchorRef = ref(null);
@@ -21,19 +26,17 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
21
26
  const exportCapability = exportCapabilityRef.value;
22
27
  const exportPlugin = exportPluginRef.value;
23
28
  if (!exportCapability || !exportPlugin) return;
24
- unsubscribe = exportPlugin.onRequest((action) => {
25
- if (action === "download") {
26
- const el = anchorRef.value;
27
- if (!el) return;
28
- const task = exportPlugin.saveAsCopyAndGetBufferAndName();
29
- task.wait(({ buffer, name }) => {
30
- const url = URL.createObjectURL(new Blob([buffer]));
31
- el.href = url;
32
- el.download = props.fileName ?? name;
33
- el.click();
34
- URL.revokeObjectURL(url);
35
- }, ignore);
36
- }
29
+ unsubscribe = exportPlugin.onRequest((event) => {
30
+ const el = anchorRef.value;
31
+ if (!el) return;
32
+ const task = exportPlugin.saveAsCopyAndGetBufferAndName(event.documentId);
33
+ task.wait(({ buffer, name }) => {
34
+ const url = URL.createObjectURL(new Blob([buffer]));
35
+ el.href = url;
36
+ el.download = name;
37
+ el.click();
38
+ URL.revokeObjectURL(url);
39
+ }, ignore);
37
40
  });
38
41
  });
39
42
  onUnmounted(() => {
@@ -54,6 +57,7 @@ const ExportPluginPackage = createPluginPackage(ExportPluginPackage$1).addUtilit
54
57
  export {
55
58
  _sfc_main as Download,
56
59
  ExportPluginPackage,
60
+ useExport,
57
61
  useExportCapability,
58
62
  useExportPlugin
59
63
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-export.ts","../../src/vue/components/download.vue","../../src/vue/index.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n","<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted } from 'vue';\nimport { ignore } from '@embedpdf/models';\nimport { Unsubscribe } from '@embedpdf/core';\n\nimport { useExportCapability, useExportPlugin } from '../hooks';\n\nexport interface DownloadProps {\n fileName?: string;\n}\n\nconst props = defineProps<DownloadProps>();\n\nconst { provides: exportCapabilityRef } = useExportCapability();\nconst { plugin: exportPluginRef } = useExportPlugin();\nconst anchorRef = ref<HTMLAnchorElement | null>(null);\n\nlet unsubscribe: Unsubscribe | null = null;\n\nonMounted(() => {\n const exportCapability = exportCapabilityRef.value;\n const exportPlugin = exportPluginRef.value;\n\n if (!exportCapability || !exportPlugin) return;\n\n unsubscribe = exportPlugin.onRequest((action) => {\n if (action === 'download') {\n const el = anchorRef.value;\n if (!el) return;\n\n const task = exportPlugin.saveAsCopyAndGetBufferAndName();\n task.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = props.fileName ?? name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n }\n });\n});\n\nonUnmounted(() => {\n if (unsubscribe) {\n unsubscribe();\n }\n});\n</script>\n\n<template>\n <a ref=\"anchorRef\" style=\"display: none\" />\n</template>\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './components';\n\nexport * from './hooks';\nexport * from './components';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["_createElementBlock","BaseExportPackage","Download"],"mappings":";;;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;;;;;;;ACOpF,UAAM,QAAQ;AAEd,UAAM,EAAE,UAAU,oBAAoB,IAAI,oBAAoB;AAC9D,UAAM,EAAE,QAAQ,gBAAgB,IAAI,gBAAgB;AAC9C,UAAA,YAAY,IAA8B,IAAI;AAEpD,QAAI,cAAkC;AAEtC,cAAU,MAAM;AACd,YAAM,mBAAmB,oBAAoB;AAC7C,YAAM,eAAe,gBAAgB;AAEjC,UAAA,CAAC,oBAAoB,CAAC,aAAc;AAE1B,oBAAA,aAAa,UAAU,CAAC,WAAW;AAC/C,YAAI,WAAW,YAAY;AACzB,gBAAM,KAAK,UAAU;AACrB,cAAI,CAAC,GAAI;AAEH,gBAAA,OAAO,aAAa,8BAA8B;AACxD,eAAK,KAAK,CAAC,EAAE,QAAQ,WAAW;AACxB,kBAAA,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAClD,eAAG,OAAO;AACP,eAAA,WAAW,MAAM,YAAY;AAChC,eAAG,MAAM;AACT,gBAAI,gBAAgB,GAAG;AAAA,aACtB,MAAM;AAAA,QAAA;AAAA,MACX,CACD;AAAA,IAAA,CACF;AAED,gBAAY,MAAM;AAChB,UAAI,aAAa;AACH,oBAAA;AAAA,MAAA;AAAA,IACd,CACD;;0BAICA,mBAA2C,KAAA;AAAA,iBAApC;AAAA,QAAJ,KAAI;AAAA,QAAY,OAAA,EAAqB,WAAA,OAAA;AAAA,MAAA;;;;ACxCnC,MAAM,sBAAsB,oBAAoBC,qBAAiB,EACrE,WAAWC,SAAQ,EACnB,MAAM;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-export.ts","../../src/vue/components/download.vue","../../src/vue/index.ts"],"sourcesContent":["import { computed, MaybeRefOrGetter, toValue } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { ExportPlugin } from '@embedpdf/plugin-export';\n\nexport const useExportPlugin = () => usePlugin<ExportPlugin>(ExportPlugin.id);\nexport const useExportCapability = () => useCapability<ExportPlugin>(ExportPlugin.id);\n\n/**\n * Hook for export capability for a specific document\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport const useExport = (documentId: MaybeRefOrGetter<string>) => {\n const { provides } = useExportCapability();\n\n return {\n provides: computed(() => provides.value?.forDocument(toValue(documentId)) ?? null),\n };\n};\n","<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted } from 'vue';\nimport { ignore } from '@embedpdf/models';\nimport { Unsubscribe } from '@embedpdf/core';\n\nimport { useExportCapability, useExportPlugin } from '../hooks';\n\nconst { provides: exportCapabilityRef } = useExportCapability();\nconst { plugin: exportPluginRef } = useExportPlugin();\nconst anchorRef = ref<HTMLAnchorElement | null>(null);\n\nlet unsubscribe: Unsubscribe | null = null;\n\nonMounted(() => {\n const exportCapability = exportCapabilityRef.value;\n const exportPlugin = exportPluginRef.value;\n\n if (!exportCapability || !exportPlugin) return;\n\n unsubscribe = exportPlugin.onRequest((event) => {\n const el = anchorRef.value;\n if (!el) return;\n\n const task = exportPlugin.saveAsCopyAndGetBufferAndName(event.documentId);\n task.wait(({ buffer, name }) => {\n const url = URL.createObjectURL(new Blob([buffer]));\n el.href = url;\n el.download = name;\n el.click();\n URL.revokeObjectURL(url);\n }, ignore);\n });\n});\n\nonUnmounted(() => {\n if (unsubscribe) {\n unsubscribe();\n }\n});\n</script>\n\n<template>\n <a ref=\"anchorRef\" style=\"display: none\" />\n</template>\n","import { createPluginPackage } from '@embedpdf/core';\nimport { ExportPluginPackage as BaseExportPackage } from '@embedpdf/plugin-export';\n\nimport { Download } from './components';\n\nexport * from './hooks';\nexport * from './components';\n\nexport * from '@embedpdf/plugin-export';\n\nexport const ExportPluginPackage = createPluginPackage(BaseExportPackage)\n .addUtility(Download)\n .build();\n"],"names":["_createElementBlock","BaseExportPackage","Download"],"mappings":";;;;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAM7E,MAAM,YAAY,CAAC,eAAyC;AACjE,QAAM,EAAE,SAAA,IAAa,oBAAA;AAErB,SAAO;AAAA,IACL,UAAU,SAAS,MAAA;;AAAM,6BAAS,UAAT,mBAAgB,YAAY,QAAQ,UAAU,OAAM;AAAA,KAAI;AAAA,EAAA;AAErF;;;;ACVA,UAAM,EAAE,UAAU,oBAAA,IAAwB,oBAAA;AAC1C,UAAM,EAAE,QAAQ,gBAAA,IAAoB,gBAAA;AACpC,UAAM,YAAY,IAA8B,IAAI;AAEpD,QAAI,cAAkC;AAEtC,cAAU,MAAM;AACd,YAAM,mBAAmB,oBAAoB;AAC7C,YAAM,eAAe,gBAAgB;AAErC,UAAI,CAAC,oBAAoB,CAAC,aAAc;AAExC,oBAAc,aAAa,UAAU,CAAC,UAAU;AAC9C,cAAM,KAAK,UAAU;AACrB,YAAI,CAAC,GAAI;AAET,cAAM,OAAO,aAAa,8BAA8B,MAAM,UAAU;AACxE,aAAK,KAAK,CAAC,EAAE,QAAQ,WAAW;AAC9B,gBAAM,MAAM,IAAI,gBAAgB,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAClD,aAAG,OAAO;AACV,aAAG,WAAW;AACd,aAAG,MAAA;AACH,cAAI,gBAAgB,GAAG;AAAA,QACzB,GAAG,MAAM;AAAA,MACX,CAAC;AAAA,IACH,CAAC;AAED,gBAAY,MAAM;AAChB,UAAI,aAAa;AACf,oBAAA;AAAA,MACF;AAAA,IACF,CAAC;;0BAICA,mBAA2C,KAAA;AAAA,iBAApC;AAAA,QAAJ,KAAI;AAAA,QAAY,OAAA,EAAA,WAAA,OAAA;AAAA,MAAA;;;;AChCd,MAAM,sBAAsB,oBAAoBC,qBAAiB,EACrE,WAAWC,SAAQ,EACnB,MAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-export",
3
- "version": "1.5.0",
3
+ "version": "2.0.0-next.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",
@@ -34,12 +34,12 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@embedpdf/models": "1.5.0"
37
+ "@embedpdf/models": "2.0.0-next.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/react": "^18.2.0",
41
41
  "typescript": "^5.0.0",
42
- "@embedpdf/core": "1.5.0",
42
+ "@embedpdf/core": "2.0.0-next.1",
43
43
  "@embedpdf/build": "1.1.0"
44
44
  },
45
45
  "peerDependencies": {
@@ -48,7 +48,7 @@
48
48
  "preact": "^10.26.4",
49
49
  "vue": ">=3.2.0",
50
50
  "svelte": ">=5 <6",
51
- "@embedpdf/core": "1.5.0"
51
+ "@embedpdf/core": "2.0.0-next.1"
52
52
  },
53
53
  "files": [
54
54
  "dist",