@embedpdf/plugin-attachment 1.4.1 → 2.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@embedpdf/core"),e=require("@embedpdf/models"),n=class extends t.BasePlugin{constructor(t,e){super(t,e)}async initialize(t){}buildCapability(){return{getAttachments:this.getAttachments.bind(this),downloadAttachment:this.downloadAttachment.bind(this)}}downloadAttachment(t){const n=this.coreState.core.document;return n?this.engine.readAttachmentContent(n,t):e.PdfTaskHelper.reject({code:e.PdfErrorCode.NotFound,message:"Document not found"})}getAttachments(){const t=this.coreState.core.document;return t?this.engine.getAttachments(t):e.PdfTaskHelper.reject({code:e.PdfErrorCode.NotFound,message:"Document not found"})}};n.id="attachment";let o=n;const a="attachment",r={id:a,name:"Attachment Plugin",version:"1.0.0",provides:["attachment"],requires:[],optional:[],defaultConfig:{enabled:!0}},s={manifest:r,create:t=>new o(a,t),reducer:()=>{},initialState:{}};exports.ATTACHMENT_PLUGIN_ID=a,exports.AttachmentPlugin=o,exports.AttachmentPluginPackage=s,exports.manifest=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@embedpdf/core"),e=require("@embedpdf/models"),n=class extends t.BasePlugin{constructor(t,e){super(t,e)}async initialize(t){}buildCapability(){return{getAttachments:()=>this.getAttachments(),downloadAttachment:t=>this.downloadAttachment(t),forDocument:t=>this.createAttachmentScope(t)}}createAttachmentScope(t){return{getAttachments:()=>this.getAttachments(t),downloadAttachment:e=>this.downloadAttachment(e,t)}}downloadAttachment(t,n){const o=n??this.getActiveDocumentId(),c=this.coreState.core.documents[o];return(null==c?void 0:c.document)?this.engine.readAttachmentContent(c.document,t):e.PdfTaskHelper.reject({code:e.PdfErrorCode.NotFound,message:`Document ${o} not found`})}getAttachments(t){const n=t??this.getActiveDocumentId(),o=this.coreState.core.documents[n];return(null==o?void 0:o.document)?this.engine.getAttachments(o.document):e.PdfTaskHelper.reject({code:e.PdfErrorCode.NotFound,message:`Document ${n} not found`})}};n.id="attachment";let o=n;const c="attachment",a={id:c,name:"Attachment Plugin",version:"1.0.0",provides:["attachment"],requires:[],optional:[],defaultConfig:{enabled:!0}},r={manifest:a,create:t=>new o(c,t),reducer:()=>{},initialState:{}};exports.ATTACHMENT_PLUGIN_ID=c,exports.AttachmentPlugin=o,exports.AttachmentPluginPackage=r,exports.manifest=a;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/lib/attachment-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePlugin, createEmitter, PluginRegistry } from '@embedpdf/core';\n\nimport { AttachmentCapability, AttachmentPluginConfig } from './types';\nimport {\n PdfAttachmentObject,\n PdfErrorCode,\n PdfErrorReason,\n PdfTaskHelper,\n Task,\n} from '@embedpdf/models';\n\nexport class AttachmentPlugin extends BasePlugin<AttachmentPluginConfig, AttachmentCapability> {\n static readonly id = 'attachment' as const;\n\n constructor(id: string, registry: PluginRegistry) {\n super(id, registry);\n }\n\n async initialize(_: AttachmentPluginConfig): Promise<void> {}\n\n protected buildCapability(): AttachmentCapability {\n return {\n getAttachments: this.getAttachments.bind(this),\n downloadAttachment: this.downloadAttachment.bind(this),\n };\n }\n\n private downloadAttachment(attachment: PdfAttachmentObject): Task<ArrayBuffer, PdfErrorReason> {\n const doc = this.coreState.core.document;\n\n if (!doc) {\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n }\n\n return this.engine.readAttachmentContent(doc, attachment);\n }\n\n private getAttachments(): Task<PdfAttachmentObject[], PdfErrorReason> {\n const doc = this.coreState.core.document;\n\n if (!doc) {\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n }\n\n return this.engine.getAttachments(doc);\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { AttachmentPluginConfig } from './types';\n\nexport const ATTACHMENT_PLUGIN_ID = 'attachment';\n\nexport const manifest: PluginManifest<AttachmentPluginConfig> = {\n id: ATTACHMENT_PLUGIN_ID,\n name: 'Attachment Plugin',\n version: '1.0.0',\n provides: ['attachment'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { AttachmentPlugin } from './attachment-plugin';\nimport { manifest, ATTACHMENT_PLUGIN_ID } from './manifest';\nimport { AttachmentPluginConfig } from './types';\n\nexport const AttachmentPluginPackage: PluginPackage<AttachmentPlugin, AttachmentPluginConfig> = {\n manifest,\n create: (registry) => new AttachmentPlugin(ATTACHMENT_PLUGIN_ID, registry),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './attachment-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["_AttachmentPlugin","BasePlugin","constructor","id","registry","super","initialize","_","buildCapability","getAttachments","this","bind","downloadAttachment","attachment","doc","coreState","core","document","engine","readAttachmentContent","PdfTaskHelper","reject","code","PdfErrorCode","NotFound","message","AttachmentPlugin","ATTACHMENT_PLUGIN_ID","manifest","name","version","provides","requires","optional","defaultConfig","enabled","AttachmentPluginPackage","create","reducer","initialState"],"mappings":"gJAWaA,EAAN,cAA+BC,EAAAA,WAGpC,WAAAC,CAAYC,EAAYC,GACtBC,MAAMF,EAAIC,EAAQ,CAGpB,gBAAME,CAAWC,GAA0C,CAEjD,eAAAC,GACD,MAAA,CACLC,eAAgBC,KAAKD,eAAeE,KAAKD,MACzCE,mBAAoBF,KAAKE,mBAAmBD,KAAKD,MACnD,CAGM,kBAAAE,CAAmBC,GACnB,MAAAC,EAAMJ,KAAKK,UAAUC,KAAKC,SAEhC,OAAKH,EAIEJ,KAAKQ,OAAOC,sBAAsBL,EAAKD,GAHrCO,EAAAA,cAAcC,OAAO,CAAEC,KAAMC,eAAaC,SAAUC,QAAS,sBAGd,CAGlD,cAAAhB,GACA,MAAAK,EAAMJ,KAAKK,UAAUC,KAAKC,SAEhC,OAAKH,EAIEJ,KAAKQ,OAAOT,eAAeK,GAHzBM,EAAAA,cAAcC,OAAO,CAAEC,KAAMC,eAAaC,SAAUC,QAAS,sBAGjC,GAhCvCzB,EAAgBG,GAAK,aADhB,IAAMuB,EAAN1B,ECRA,MAAM2B,EAAuB,aAEvBC,EAAmD,CAC9DzB,GAAIwB,EACJE,KAAM,oBACNC,QAAS,QACTC,SAAU,CAAC,cACXC,SAAU,GACVC,SAAU,GACVC,cAAe,CACbC,SAAS,ICPAC,EAAmF,CAC9FR,WACAS,OAASjC,GAAa,IAAIsB,EAAiBC,EAAsBvB,GACjEkC,QAAS,OACTC,aAAc,CAAA"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/lib/attachment-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePlugin, PluginRegistry } from '@embedpdf/core';\n\nimport { AttachmentCapability, AttachmentPluginConfig, AttachmentScope } from './types';\nimport {\n PdfAttachmentObject,\n PdfErrorCode,\n PdfErrorReason,\n PdfTaskHelper,\n Task,\n} from '@embedpdf/models';\n\nexport class AttachmentPlugin extends BasePlugin<AttachmentPluginConfig, AttachmentCapability> {\n static readonly id = 'attachment' as const;\n\n constructor(id: string, registry: PluginRegistry) {\n super(id, registry);\n }\n\n async initialize(_: AttachmentPluginConfig): Promise<void> {}\n\n // ─────────────────────────────────────────────────────────\n // Capability\n // ─────────────────────────────────────────────────────────\n\n protected buildCapability(): AttachmentCapability {\n return {\n // Active document operations\n getAttachments: () => this.getAttachments(),\n downloadAttachment: (attachment) => this.downloadAttachment(attachment),\n\n // Document-scoped operations\n forDocument: (documentId: string) => this.createAttachmentScope(documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Scoping\n // ─────────────────────────────────────────────────────────\n\n private createAttachmentScope(documentId: string): AttachmentScope {\n return {\n getAttachments: () => this.getAttachments(documentId),\n downloadAttachment: (attachment) => this.downloadAttachment(attachment, documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Core Operations\n // ─────────────────────────────────────────────────────────\n\n private downloadAttachment(\n attachment: PdfAttachmentObject,\n documentId?: string,\n ): 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.NotFound,\n message: `Document ${id} not found`,\n });\n }\n\n return this.engine.readAttachmentContent(coreDoc.document, attachment);\n }\n\n private getAttachments(documentId?: string): Task<PdfAttachmentObject[], 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.NotFound,\n message: `Document ${id} not found`,\n });\n }\n\n return this.engine.getAttachments(coreDoc.document);\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { AttachmentPluginConfig } from './types';\n\nexport const ATTACHMENT_PLUGIN_ID = 'attachment';\n\nexport const manifest: PluginManifest<AttachmentPluginConfig> = {\n id: ATTACHMENT_PLUGIN_ID,\n name: 'Attachment Plugin',\n version: '1.0.0',\n provides: ['attachment'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { AttachmentPlugin } from './attachment-plugin';\nimport { manifest, ATTACHMENT_PLUGIN_ID } from './manifest';\nimport { AttachmentPluginConfig } from './types';\n\nexport const AttachmentPluginPackage: PluginPackage<AttachmentPlugin, AttachmentPluginConfig> = {\n manifest,\n create: (registry) => new AttachmentPlugin(ATTACHMENT_PLUGIN_ID, registry),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './attachment-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["_AttachmentPlugin","BasePlugin","constructor","id","registry","super","initialize","_","buildCapability","getAttachments","this","downloadAttachment","attachment","forDocument","documentId","createAttachmentScope","getActiveDocumentId","coreDoc","coreState","core","documents","document","engine","readAttachmentContent","PdfTaskHelper","reject","code","PdfErrorCode","NotFound","message","AttachmentPlugin","ATTACHMENT_PLUGIN_ID","manifest","name","version","provides","requires","optional","defaultConfig","enabled","AttachmentPluginPackage","create","reducer","initialState"],"mappings":"gJAWaA,EAAN,cAA+BC,EAAAA,WAGpC,WAAAC,CAAYC,EAAYC,GACtBC,MAAMF,EAAIC,EACZ,CAEA,gBAAME,CAAWC,GAA2C,CAMlD,eAAAC,GACR,MAAO,CAELC,eAAgB,IAAMC,KAAKD,iBAC3BE,mBAAqBC,GAAeF,KAAKC,mBAAmBC,GAG5DC,YAAcC,GAAuBJ,KAAKK,sBAAsBD,GAEpE,CAMQ,qBAAAC,CAAsBD,GAC5B,MAAO,CACLL,eAAgB,IAAMC,KAAKD,eAAeK,GAC1CH,mBAAqBC,GAAeF,KAAKC,mBAAmBC,EAAYE,GAE5E,CAMQ,kBAAAH,CACNC,EACAE,GAEA,MAAMX,EAAKW,GAAcJ,KAAKM,sBACxBC,EAAUP,KAAKQ,UAAUC,KAAKC,UAAUjB,GAE9C,aAAKc,WAASI,UAOPX,KAAKY,OAAOC,sBAAsBN,EAAQI,SAAUT,GANlDY,EAAAA,cAAcC,OAAO,CAC1BC,KAAMC,EAAAA,aAAaC,SACnBC,QAAS,YAAY1B,eAK3B,CAEQ,cAAAM,CAAeK,GACrB,MAAMX,EAAKW,GAAcJ,KAAKM,sBACxBC,EAAUP,KAAKQ,UAAUC,KAAKC,UAAUjB,GAE9C,aAAKc,WAASI,UAOPX,KAAKY,OAAOb,eAAeQ,EAAQI,UANjCG,EAAAA,cAAcC,OAAO,CAC1BC,KAAMC,EAAAA,aAAaC,SACnBC,QAAS,YAAY1B,eAK3B,GAnEAH,EAAgBG,GAAK,aADhB,IAAM2B,EAAN9B,ECRA,MAAM+B,EAAuB,aAEvBC,EAAmD,CAC9D7B,GAAI4B,EACJE,KAAM,oBACNC,QAAS,QACTC,SAAU,CAAC,cACXC,SAAU,GACVC,SAAU,GACVC,cAAe,CACbC,SAAS,ICPAC,EAAmF,CAC9FR,WACAS,OAASrC,GAAa,IAAI0B,EAAiBC,EAAsB3B,GACjEsC,QAAS,OACTC,aAAc,CAAA"}
package/dist/index.js CHANGED
@@ -6,25 +6,51 @@ const _AttachmentPlugin = class _AttachmentPlugin extends BasePlugin {
6
6
  }
7
7
  async initialize(_) {
8
8
  }
9
+ // ─────────────────────────────────────────────────────────
10
+ // Capability
11
+ // ─────────────────────────────────────────────────────────
9
12
  buildCapability() {
10
13
  return {
11
- getAttachments: this.getAttachments.bind(this),
12
- downloadAttachment: this.downloadAttachment.bind(this)
14
+ // Active document operations
15
+ getAttachments: () => this.getAttachments(),
16
+ downloadAttachment: (attachment) => this.downloadAttachment(attachment),
17
+ // Document-scoped operations
18
+ forDocument: (documentId) => this.createAttachmentScope(documentId)
13
19
  };
14
20
  }
15
- downloadAttachment(attachment) {
16
- const doc = this.coreState.core.document;
17
- if (!doc) {
18
- return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: "Document not found" });
21
+ // ─────────────────────────────────────────────────────────
22
+ // Document Scoping
23
+ // ─────────────────────────────────────────────────────────
24
+ createAttachmentScope(documentId) {
25
+ return {
26
+ getAttachments: () => this.getAttachments(documentId),
27
+ downloadAttachment: (attachment) => this.downloadAttachment(attachment, documentId)
28
+ };
29
+ }
30
+ // ─────────────────────────────────────────────────────────
31
+ // Core Operations
32
+ // ─────────────────────────────────────────────────────────
33
+ downloadAttachment(attachment, documentId) {
34
+ const id = documentId ?? this.getActiveDocumentId();
35
+ const coreDoc = this.coreState.core.documents[id];
36
+ if (!(coreDoc == null ? void 0 : coreDoc.document)) {
37
+ return PdfTaskHelper.reject({
38
+ code: PdfErrorCode.NotFound,
39
+ message: `Document ${id} not found`
40
+ });
19
41
  }
20
- return this.engine.readAttachmentContent(doc, attachment);
42
+ return this.engine.readAttachmentContent(coreDoc.document, attachment);
21
43
  }
22
- getAttachments() {
23
- const doc = this.coreState.core.document;
24
- if (!doc) {
25
- return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: "Document not found" });
44
+ getAttachments(documentId) {
45
+ const id = documentId ?? this.getActiveDocumentId();
46
+ const coreDoc = this.coreState.core.documents[id];
47
+ if (!(coreDoc == null ? void 0 : coreDoc.document)) {
48
+ return PdfTaskHelper.reject({
49
+ code: PdfErrorCode.NotFound,
50
+ message: `Document ${id} not found`
51
+ });
26
52
  }
27
- return this.engine.getAttachments(doc);
53
+ return this.engine.getAttachments(coreDoc.document);
28
54
  }
29
55
  };
30
56
  _AttachmentPlugin.id = "attachment";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/lib/attachment-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePlugin, createEmitter, PluginRegistry } from '@embedpdf/core';\n\nimport { AttachmentCapability, AttachmentPluginConfig } from './types';\nimport {\n PdfAttachmentObject,\n PdfErrorCode,\n PdfErrorReason,\n PdfTaskHelper,\n Task,\n} from '@embedpdf/models';\n\nexport class AttachmentPlugin extends BasePlugin<AttachmentPluginConfig, AttachmentCapability> {\n static readonly id = 'attachment' as const;\n\n constructor(id: string, registry: PluginRegistry) {\n super(id, registry);\n }\n\n async initialize(_: AttachmentPluginConfig): Promise<void> {}\n\n protected buildCapability(): AttachmentCapability {\n return {\n getAttachments: this.getAttachments.bind(this),\n downloadAttachment: this.downloadAttachment.bind(this),\n };\n }\n\n private downloadAttachment(attachment: PdfAttachmentObject): Task<ArrayBuffer, PdfErrorReason> {\n const doc = this.coreState.core.document;\n\n if (!doc) {\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n }\n\n return this.engine.readAttachmentContent(doc, attachment);\n }\n\n private getAttachments(): Task<PdfAttachmentObject[], PdfErrorReason> {\n const doc = this.coreState.core.document;\n\n if (!doc) {\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n }\n\n return this.engine.getAttachments(doc);\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { AttachmentPluginConfig } from './types';\n\nexport const ATTACHMENT_PLUGIN_ID = 'attachment';\n\nexport const manifest: PluginManifest<AttachmentPluginConfig> = {\n id: ATTACHMENT_PLUGIN_ID,\n name: 'Attachment Plugin',\n version: '1.0.0',\n provides: ['attachment'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { AttachmentPlugin } from './attachment-plugin';\nimport { manifest, ATTACHMENT_PLUGIN_ID } from './manifest';\nimport { AttachmentPluginConfig } from './types';\n\nexport const AttachmentPluginPackage: PluginPackage<AttachmentPlugin, AttachmentPluginConfig> = {\n manifest,\n create: (registry) => new AttachmentPlugin(ATTACHMENT_PLUGIN_ID, registry),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './attachment-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":[],"mappings":";;AAWO,MAAM,oBAAN,MAAM,0BAAyB,WAAyD;AAAA,EAG7F,YAAY,IAAY,UAA0B;AAChD,UAAM,IAAI,QAAQ;AAAA,EAAA;AAAA,EAGpB,MAAM,WAAW,GAA0C;AAAA,EAAA;AAAA,EAEjD,kBAAwC;AACzC,WAAA;AAAA,MACL,gBAAgB,KAAK,eAAe,KAAK,IAAI;AAAA,MAC7C,oBAAoB,KAAK,mBAAmB,KAAK,IAAI;AAAA,IACvD;AAAA,EAAA;AAAA,EAGM,mBAAmB,YAAoE;AACvF,UAAA,MAAM,KAAK,UAAU,KAAK;AAEhC,QAAI,CAAC,KAAK;AACD,aAAA,cAAc,OAAO,EAAE,MAAM,aAAa,UAAU,SAAS,sBAAsB;AAAA,IAAA;AAG5F,WAAO,KAAK,OAAO,sBAAsB,KAAK,UAAU;AAAA,EAAA;AAAA,EAGlD,iBAA8D;AAC9D,UAAA,MAAM,KAAK,UAAU,KAAK;AAEhC,QAAI,CAAC,KAAK;AACD,aAAA,cAAc,OAAO,EAAE,MAAM,aAAa,UAAU,SAAS,sBAAsB;AAAA,IAAA;AAGrF,WAAA,KAAK,OAAO,eAAe,GAAG;AAAA,EAAA;AAEzC;AAlCE,kBAAgB,KAAK;AADhB,IAAM,mBAAN;ACRA,MAAM,uBAAuB;AAE7B,MAAM,WAAmD;AAAA,EAC9D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,YAAY;AAAA,EACvB,UAAU,CAAC;AAAA,EACX,UAAU,CAAC;AAAA,EACX,eAAe;AAAA,IACb,SAAS;AAAA,EAAA;AAEb;ACTO,MAAM,0BAAmF;AAAA,EAC9F;AAAA,EACA,QAAQ,CAAC,aAAa,IAAI,iBAAiB,sBAAsB,QAAQ;AAAA,EACzE,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAA;AAChB;"}
1
+ {"version":3,"file":"index.js","sources":["../src/lib/attachment-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePlugin, PluginRegistry } from '@embedpdf/core';\n\nimport { AttachmentCapability, AttachmentPluginConfig, AttachmentScope } from './types';\nimport {\n PdfAttachmentObject,\n PdfErrorCode,\n PdfErrorReason,\n PdfTaskHelper,\n Task,\n} from '@embedpdf/models';\n\nexport class AttachmentPlugin extends BasePlugin<AttachmentPluginConfig, AttachmentCapability> {\n static readonly id = 'attachment' as const;\n\n constructor(id: string, registry: PluginRegistry) {\n super(id, registry);\n }\n\n async initialize(_: AttachmentPluginConfig): Promise<void> {}\n\n // ─────────────────────────────────────────────────────────\n // Capability\n // ─────────────────────────────────────────────────────────\n\n protected buildCapability(): AttachmentCapability {\n return {\n // Active document operations\n getAttachments: () => this.getAttachments(),\n downloadAttachment: (attachment) => this.downloadAttachment(attachment),\n\n // Document-scoped operations\n forDocument: (documentId: string) => this.createAttachmentScope(documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Scoping\n // ─────────────────────────────────────────────────────────\n\n private createAttachmentScope(documentId: string): AttachmentScope {\n return {\n getAttachments: () => this.getAttachments(documentId),\n downloadAttachment: (attachment) => this.downloadAttachment(attachment, documentId),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Core Operations\n // ─────────────────────────────────────────────────────────\n\n private downloadAttachment(\n attachment: PdfAttachmentObject,\n documentId?: string,\n ): 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.NotFound,\n message: `Document ${id} not found`,\n });\n }\n\n return this.engine.readAttachmentContent(coreDoc.document, attachment);\n }\n\n private getAttachments(documentId?: string): Task<PdfAttachmentObject[], 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.NotFound,\n message: `Document ${id} not found`,\n });\n }\n\n return this.engine.getAttachments(coreDoc.document);\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { AttachmentPluginConfig } from './types';\n\nexport const ATTACHMENT_PLUGIN_ID = 'attachment';\n\nexport const manifest: PluginManifest<AttachmentPluginConfig> = {\n id: ATTACHMENT_PLUGIN_ID,\n name: 'Attachment Plugin',\n version: '1.0.0',\n provides: ['attachment'],\n requires: [],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { AttachmentPlugin } from './attachment-plugin';\nimport { manifest, ATTACHMENT_PLUGIN_ID } from './manifest';\nimport { AttachmentPluginConfig } from './types';\n\nexport const AttachmentPluginPackage: PluginPackage<AttachmentPlugin, AttachmentPluginConfig> = {\n manifest,\n create: (registry) => new AttachmentPlugin(ATTACHMENT_PLUGIN_ID, registry),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './attachment-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":[],"mappings":";;AAWO,MAAM,oBAAN,MAAM,0BAAyB,WAAyD;AAAA,EAG7F,YAAY,IAAY,UAA0B;AAChD,UAAM,IAAI,QAAQ;AAAA,EACpB;AAAA,EAEA,MAAM,WAAW,GAA0C;AAAA,EAAC;AAAA;AAAA;AAAA;AAAA,EAMlD,kBAAwC;AAChD,WAAO;AAAA;AAAA,MAEL,gBAAgB,MAAM,KAAK,eAAA;AAAA,MAC3B,oBAAoB,CAAC,eAAe,KAAK,mBAAmB,UAAU;AAAA;AAAA,MAGtE,aAAa,CAAC,eAAuB,KAAK,sBAAsB,UAAU;AAAA,IAAA;AAAA,EAE9E;AAAA;AAAA;AAAA;AAAA,EAMQ,sBAAsB,YAAqC;AACjE,WAAO;AAAA,MACL,gBAAgB,MAAM,KAAK,eAAe,UAAU;AAAA,MACpD,oBAAoB,CAAC,eAAe,KAAK,mBAAmB,YAAY,UAAU;AAAA,IAAA;AAAA,EAEtF;AAAA;AAAA;AAAA;AAAA,EAMQ,mBACN,YACA,YACmC;AACnC,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,sBAAsB,QAAQ,UAAU,UAAU;AAAA,EACvE;AAAA,EAEQ,eAAe,YAAkE;AACvF,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,eAAe,QAAQ,QAAQ;AAAA,EACpD;AACF;AApEE,kBAAgB,KAAK;AADhB,IAAM,mBAAN;ACRA,MAAM,uBAAuB;AAE7B,MAAM,WAAmD;AAAA,EAC9D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,YAAY;AAAA,EACvB,UAAU,CAAA;AAAA,EACV,UAAU,CAAA;AAAA,EACV,eAAe;AAAA,IACb,SAAS;AAAA,EAAA;AAEb;ACTO,MAAM,0BAAmF;AAAA,EAC9F;AAAA,EACA,QAAQ,CAAC,aAAa,IAAI,iBAAiB,sBAAsB,QAAQ;AAAA,EACzE,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAA;AAChB;"}
@@ -5,6 +5,7 @@ export declare class AttachmentPlugin extends BasePlugin<AttachmentPluginConfig,
5
5
  constructor(id: string, registry: PluginRegistry);
6
6
  initialize(_: AttachmentPluginConfig): Promise<void>;
7
7
  protected buildCapability(): AttachmentCapability;
8
+ private createAttachmentScope;
8
9
  private downloadAttachment;
9
10
  private getAttachments;
10
11
  }
@@ -2,7 +2,12 @@ import { BasePluginConfig } from '@embedpdf/core';
2
2
  import { PdfAttachmentObject, PdfErrorReason, Task } from '@embedpdf/models';
3
3
  export interface AttachmentPluginConfig extends BasePluginConfig {
4
4
  }
5
+ export interface AttachmentScope {
6
+ getAttachments(): Task<PdfAttachmentObject[], PdfErrorReason>;
7
+ downloadAttachment(attachment: PdfAttachmentObject): Task<ArrayBuffer, PdfErrorReason>;
8
+ }
5
9
  export interface AttachmentCapability {
6
10
  getAttachments: () => Task<PdfAttachmentObject[], PdfErrorReason>;
7
11
  downloadAttachment: (attachment: PdfAttachmentObject) => Task<ArrayBuffer, PdfErrorReason>;
12
+ forDocument(documentId: string): AttachmentScope;
8
13
  }
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-attachment");exports.useAttachmentCapability=()=>e.useCapability(t.AttachmentPlugin.id),exports.useAttachmentPlugin=()=>e.usePlugin(t.AttachmentPlugin.id),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/preact"),t=require("@embedpdf/plugin-attachment");exports.useAttachmentCapability=()=>e.useCapability(t.AttachmentPlugin.id),exports.useAttachmentPlugin=()=>e.usePlugin(t.AttachmentPlugin.id),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,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-attachment");exports.useAttachmentCapability=()=>e.useCapability(t.AttachmentPlugin.id),exports.useAttachmentPlugin=()=>e.usePlugin(t.AttachmentPlugin.id),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/react"),t=require("@embedpdf/plugin-attachment");exports.useAttachmentCapability=()=>e.useCapability(t.AttachmentPlugin.id),exports.useAttachmentPlugin=()=>e.usePlugin(t.AttachmentPlugin.id),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
@@ -0,0 +1 @@
1
+ export * from './use-attachment';
@@ -0,0 +1,11 @@
1
+ import { AttachmentPlugin } from '../../lib/index.ts';
2
+ export declare const useAttachmentPlugin: () => {
3
+ plugin: AttachmentPlugin | null;
4
+ isLoading: boolean;
5
+ ready: Promise<void>;
6
+ };
7
+ export declare const useAttachmentCapability: () => {
8
+ provides: Readonly<import('../../lib/index.ts').AttachmentCapability> | null;
9
+ isLoading: boolean;
10
+ ready: Promise<void>;
11
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/svelte"),t=require("@embedpdf/plugin-attachment");exports.useAttachmentCapability=()=>e.useCapability(t.AttachmentPlugin.id),exports.useAttachmentPlugin=()=>e.usePlugin(t.AttachmentPlugin.id);
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-attachment.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { AttachmentPlugin } from '@embedpdf/plugin-attachment';\n\nexport const useAttachmentPlugin = () => usePlugin<AttachmentPlugin>(AttachmentPlugin.id);\nexport const useAttachmentCapability = () => useCapability<AttachmentPlugin>(AttachmentPlugin.id);\n"],"names":["useCapability","AttachmentPlugin","id","usePlugin"],"mappings":"kMAIuC,IAAMA,gBAAgCC,EAAAA,iBAAiBC,gCAD3D,IAAMC,YAA4BF,EAAAA,iBAAiBC"}
@@ -0,0 +1 @@
1
+ export * from './hooks';
@@ -0,0 +1,9 @@
1
+ import { usePlugin, useCapability } from "@embedpdf/core/svelte";
2
+ import { AttachmentPlugin } from "@embedpdf/plugin-attachment";
3
+ const useAttachmentPlugin = () => usePlugin(AttachmentPlugin.id);
4
+ const useAttachmentCapability = () => useCapability(AttachmentPlugin.id);
5
+ export {
6
+ useAttachmentCapability,
7
+ useAttachmentPlugin
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-attachment.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { AttachmentPlugin } from '@embedpdf/plugin-attachment';\n\nexport const useAttachmentPlugin = () => usePlugin<AttachmentPlugin>(AttachmentPlugin.id);\nexport const useAttachmentCapability = () => useCapability<AttachmentPlugin>(AttachmentPlugin.id);\n"],"names":[],"mappings":";;AAGO,MAAM,sBAAsB,MAAM,UAA4B,iBAAiB,EAAE;AACjF,MAAM,0BAA0B,MAAM,cAAgC,iBAAiB,EAAE;"}
@@ -0,0 +1 @@
1
+ export * from './use-attachment';
@@ -0,0 +1,3 @@
1
+ import { AttachmentPlugin } from '../../lib/index.ts';
2
+ export declare const useAttachmentPlugin: () => import('@embedpdf/core/vue').PluginState<AttachmentPlugin>;
3
+ export declare const useAttachmentCapability: () => import('@embedpdf/core/vue').CapabilityState<Readonly<import('../../lib/index.ts').AttachmentCapability>>;
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/vue"),t=require("@embedpdf/plugin-attachment");exports.useAttachmentCapability=()=>e.useCapability(t.AttachmentPlugin.id),exports.useAttachmentPlugin=()=>e.usePlugin(t.AttachmentPlugin.id),Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-attachment.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { AttachmentPlugin } from '@embedpdf/plugin-attachment';\n\nexport const useAttachmentPlugin = () => usePlugin<AttachmentPlugin>(AttachmentPlugin.id);\nexport const useAttachmentCapability = () => useCapability<AttachmentPlugin>(AttachmentPlugin.id);\n"],"names":["useCapability","AttachmentPlugin","id","usePlugin"],"mappings":"+LAIuC,IAAMA,gBAAgCC,EAAAA,iBAAiBC,gCAD3D,IAAMC,YAA4BF,EAAAA,iBAAiBC"}
@@ -0,0 +1,2 @@
1
+ export * from './hooks';
2
+ export * from '../lib/index.ts';
@@ -0,0 +1,10 @@
1
+ import { usePlugin, useCapability } from "@embedpdf/core/vue";
2
+ import { AttachmentPlugin } from "@embedpdf/plugin-attachment";
3
+ export * from "@embedpdf/plugin-attachment";
4
+ const useAttachmentPlugin = () => usePlugin(AttachmentPlugin.id);
5
+ const useAttachmentCapability = () => useCapability(AttachmentPlugin.id);
6
+ export {
7
+ useAttachmentCapability,
8
+ useAttachmentPlugin
9
+ };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-attachment.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { AttachmentPlugin } from '@embedpdf/plugin-attachment';\n\nexport const useAttachmentPlugin = () => usePlugin<AttachmentPlugin>(AttachmentPlugin.id);\nexport const useAttachmentCapability = () => useCapability<AttachmentPlugin>(AttachmentPlugin.id);\n"],"names":[],"mappings":";;;AAGO,MAAM,sBAAsB,MAAM,UAA4B,iBAAiB,EAAE;AACjF,MAAM,0BAA0B,MAAM,cAAgC,iBAAiB,EAAE;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-attachment",
3
- "version": "1.4.1",
3
+ "version": "2.0.0-next.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",
@@ -21,22 +21,34 @@
21
21
  "types": "./dist/react/index.d.ts",
22
22
  "import": "./dist/react/index.js",
23
23
  "require": "./dist/react/index.cjs"
24
+ },
25
+ "./vue": {
26
+ "types": "./dist/vue/index.d.ts",
27
+ "import": "./dist/vue/index.js",
28
+ "require": "./dist/vue/index.cjs"
29
+ },
30
+ "./svelte": {
31
+ "types": "./dist/svelte/index.d.ts",
32
+ "import": "./dist/svelte/index.js",
33
+ "require": "./dist/svelte/index.cjs"
24
34
  }
25
35
  },
26
36
  "dependencies": {
27
- "@embedpdf/models": "1.4.1"
37
+ "@embedpdf/models": "2.0.0-next.0"
28
38
  },
29
39
  "devDependencies": {
30
40
  "@types/react": "^18.2.0",
31
41
  "typescript": "^5.0.0",
32
- "@embedpdf/core": "1.4.1",
33
- "@embedpdf/build": "1.1.0"
42
+ "@embedpdf/build": "1.1.0",
43
+ "@embedpdf/core": "2.0.0-next.0"
34
44
  },
35
45
  "peerDependencies": {
36
46
  "react": ">=16.8.0",
37
47
  "react-dom": ">=16.8.0",
38
48
  "preact": "^10.26.4",
39
- "@embedpdf/core": "1.4.1"
49
+ "vue": ">=3.2.0",
50
+ "svelte": ">=5 <6",
51
+ "@embedpdf/core": "2.0.0-next.0"
40
52
  },
41
53
  "files": [
42
54
  "dist",
@@ -58,7 +70,9 @@
58
70
  "build:base": "vite build --mode base",
59
71
  "build:react": "vite build --mode react",
60
72
  "build:preact": "vite build --mode preact",
61
- "build": "pnpm run clean && concurrently -c auto -n base,react,preact \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\"",
73
+ "build:vue": "vite build --mode vue",
74
+ "build:svelte": "vite build --mode svelte",
75
+ "build": "pnpm run clean && concurrently -c auto -n base,react,preact,vue,svelte \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\" \"vite build --mode vue\" \"vite build --mode svelte\"",
62
76
  "clean": "rimraf dist",
63
77
  "lint": "eslint src --color",
64
78
  "lint:fix": "eslint src --color --fix"